blob: f917d621accac07a04f7d92ffd5cd32c28c3d7c9 [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"
Seth Forsheeb353dda2012-11-15 08:08:03 -060036#include "debug.h"
Arend van Spriel5b435de2011-10-05 13:19:03 +020037
38#define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
39
40/* Flags we support */
41#define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
42 FIF_ALLMULTI | \
43 FIF_FCSFAIL | \
Arend van Spriel5b435de2011-10-05 13:19:03 +020044 FIF_CONTROL | \
45 FIF_OTHER_BSS | \
Alwin Beukersbe667662011-11-22 17:21:43 -080046 FIF_BCN_PRBRESP_PROMISC | \
47 FIF_PSPOLL)
Arend van Spriel5b435de2011-10-05 13:19:03 +020048
49#define CHAN2GHZ(channel, freqency, chflags) { \
50 .band = IEEE80211_BAND_2GHZ, \
51 .center_freq = (freqency), \
52 .hw_value = (channel), \
53 .flags = chflags, \
54 .max_antenna_gain = 0, \
55 .max_power = 19, \
56}
57
58#define CHAN5GHZ(channel, chflags) { \
59 .band = IEEE80211_BAND_5GHZ, \
60 .center_freq = 5000 + 5*(channel), \
61 .hw_value = (channel), \
62 .flags = chflags, \
63 .max_antenna_gain = 0, \
64 .max_power = 21, \
65}
66
67#define RATE(rate100m, _flags) { \
68 .bitrate = (rate100m), \
69 .flags = (_flags), \
70 .hw_value = (rate100m / 5), \
71}
72
73struct firmware_hdr {
74 __le32 offset;
75 __le32 len;
76 __le32 idx;
77};
78
79static const char * const brcms_firmwares[MAX_FW_IMAGES] = {
80 "brcm/bcm43xx",
81 NULL
82};
83
84static int n_adapters_found;
85
86MODULE_AUTHOR("Broadcom Corporation");
87MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
88MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
89MODULE_LICENSE("Dual BSD/GPL");
Jeff Mahoneyfaa97bd4a2012-08-06 15:17:26 -040090/* This needs to be adjusted when brcms_firmwares changes */
91MODULE_FIRMWARE("brcm/bcm43xx-0.fw");
92MODULE_FIRMWARE("brcm/bcm43xx_hdr-0.fw");
Arend van Spriel5b435de2011-10-05 13:19:03 +020093
Arend van Spriel2e7565602011-12-08 15:06:46 -080094/* recognized BCMA Core IDs */
95static struct bcma_device_id brcms_coreid_table[] = {
Arend van Sprieleb032f02011-12-12 15:15:12 -080096 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 23, BCMA_ANY_CLASS),
97 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 24, BCMA_ANY_CLASS),
Arend van Spriel2e7565602011-12-08 15:06:46 -080098 BCMA_CORETABLE_END
99};
100MODULE_DEVICE_TABLE(bcma, brcms_coreid_table);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200101
Seth Forsheeb0341742012-11-15 08:08:01 -0600102#if defined(CONFIG_BRCMDBG)
103/*
104 * Module parameter for setting the debug message level. Available
105 * flags are specified by the BRCM_DL_* macros in
106 * drivers/net/wireless/brcm80211/include/defs.h.
107 */
108module_param_named(debug, brcm_msg_level, uint, S_IRUGO | S_IWUSR);
109#endif
Arend van Spriel5b435de2011-10-05 13:19:03 +0200110
111static struct ieee80211_channel brcms_2ghz_chantable[] = {
112 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
113 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
114 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
115 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
116 CHAN2GHZ(5, 2432, 0),
117 CHAN2GHZ(6, 2437, 0),
118 CHAN2GHZ(7, 2442, 0),
119 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
120 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
121 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
122 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
123 CHAN2GHZ(12, 2467,
124 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
125 IEEE80211_CHAN_NO_HT40PLUS),
126 CHAN2GHZ(13, 2472,
127 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
128 IEEE80211_CHAN_NO_HT40PLUS),
129 CHAN2GHZ(14, 2484,
130 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
Seth Forshee7f38e5b2012-08-01 15:58:43 -0500131 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS |
132 IEEE80211_CHAN_NO_OFDM)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200133};
134
135static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
136 /* UNII-1 */
137 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
138 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
139 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
140 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
141 /* UNII-2 */
142 CHAN5GHZ(52,
143 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
144 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
145 CHAN5GHZ(56,
146 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
147 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
148 CHAN5GHZ(60,
149 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
150 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
151 CHAN5GHZ(64,
152 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
153 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
154 /* MID */
155 CHAN5GHZ(100,
156 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
157 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
158 CHAN5GHZ(104,
159 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
160 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
161 CHAN5GHZ(108,
162 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
163 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
164 CHAN5GHZ(112,
165 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
166 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
167 CHAN5GHZ(116,
168 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
169 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
170 CHAN5GHZ(120,
171 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
172 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
173 CHAN5GHZ(124,
174 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
175 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
176 CHAN5GHZ(128,
177 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
178 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
179 CHAN5GHZ(132,
180 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
181 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
182 CHAN5GHZ(136,
183 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
184 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
185 CHAN5GHZ(140,
186 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
187 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
188 IEEE80211_CHAN_NO_HT40MINUS),
189 /* UNII-3 */
190 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
191 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
192 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
193 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
194 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
195};
196
197/*
198 * The rate table is used for both 2.4G and 5G rates. The
199 * latter being a subset as it does not support CCK rates.
200 */
201static struct ieee80211_rate legacy_ratetable[] = {
202 RATE(10, 0),
203 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
204 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
205 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
206 RATE(60, 0),
207 RATE(90, 0),
208 RATE(120, 0),
209 RATE(180, 0),
210 RATE(240, 0),
211 RATE(360, 0),
212 RATE(480, 0),
213 RATE(540, 0),
214};
215
216static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template = {
217 .band = IEEE80211_BAND_2GHZ,
218 .channels = brcms_2ghz_chantable,
219 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
220 .bitrates = legacy_ratetable,
221 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
222 .ht_cap = {
223 /* from include/linux/ieee80211.h */
224 .cap = IEEE80211_HT_CAP_GRN_FLD |
Arend van Spriel6b1a89a2011-10-18 14:02:59 +0200225 IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200226 .ht_supported = true,
227 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
228 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
229 .mcs = {
230 /* placeholders for now */
231 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
232 .rx_highest = cpu_to_le16(500),
233 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
234 }
235};
236
237static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template = {
238 .band = IEEE80211_BAND_5GHZ,
239 .channels = brcms_5ghz_nphy_chantable,
240 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
241 .bitrates = legacy_ratetable + BRCMS_LEGACY_5G_RATE_OFFSET,
242 .n_bitrates = ARRAY_SIZE(legacy_ratetable) -
243 BRCMS_LEGACY_5G_RATE_OFFSET,
244 .ht_cap = {
245 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
Arend van Spriel6b1a89a2011-10-18 14:02:59 +0200246 IEEE80211_HT_CAP_SGI_40,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200247 .ht_supported = true,
248 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
249 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
250 .mcs = {
251 /* placeholders for now */
252 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
253 .rx_highest = cpu_to_le16(500),
254 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
255 }
256};
257
258/* flags the given rate in rateset as requested */
259static void brcms_set_basic_rate(struct brcm_rateset *rs, u16 rate, bool is_br)
260{
261 u32 i;
262
263 for (i = 0; i < rs->count; i++) {
264 if (rate != (rs->rates[i] & 0x7f))
265 continue;
266
267 if (is_br)
268 rs->rates[i] |= BRCMS_RATE_FLAG;
269 else
270 rs->rates[i] &= BRCMS_RATE_MASK;
271 return;
272 }
273}
274
Thomas Huehn36323f82012-07-23 21:33:42 +0200275static void brcms_ops_tx(struct ieee80211_hw *hw,
276 struct ieee80211_tx_control *control,
277 struct sk_buff *skb)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200278{
279 struct brcms_info *wl = hw->priv;
Thomas Huehn644e8c02012-07-10 14:01:37 +0200280 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200281
282 spin_lock_bh(&wl->lock);
283 if (!wl->pub->up) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600284 brcms_err(wl->wlc->hw->d11core, "ops->tx called while down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200285 kfree_skb(skb);
286 goto done;
287 }
Piotr Haberc4dea352012-11-28 21:44:05 +0100288 if (brcms_c_sendpkt_mac80211(wl->wlc, skb, hw))
289 tx_info->rate_driver_data[0] = control->sta;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200290 done:
291 spin_unlock_bh(&wl->lock);
292}
293
294static int brcms_ops_start(struct ieee80211_hw *hw)
295{
296 struct brcms_info *wl = hw->priv;
297 bool blocked;
Roland Vossen2646c462011-10-21 16:16:27 +0200298 int err;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200299
300 ieee80211_wake_queues(hw);
301 spin_lock_bh(&wl->lock);
302 blocked = brcms_rfkill_set_hw_state(wl);
303 spin_unlock_bh(&wl->lock);
304 if (!blocked)
305 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
306
Roland Vossen2646c462011-10-21 16:16:27 +0200307 spin_lock_bh(&wl->lock);
Roland Vossendc460122011-10-21 16:16:28 +0200308 /* avoid acknowledging frames before a non-monitor device is added */
309 wl->mute_tx = true;
310
Roland Vossen2646c462011-10-21 16:16:27 +0200311 if (!wl->pub->up)
Piotr Haber82d8eba2012-09-19 22:21:15 +0200312 if (!blocked)
313 err = brcms_up(wl);
314 else
315 err = -ERFKILL;
Roland Vossen2646c462011-10-21 16:16:27 +0200316 else
317 err = -ENODEV;
318 spin_unlock_bh(&wl->lock);
319
320 if (err != 0)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600321 brcms_err(wl->wlc->hw->d11core, "%s: brcms_up() returned %d\n",
322 __func__, err);
Roland Vossen2646c462011-10-21 16:16:27 +0200323 return err;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200324}
325
326static void brcms_ops_stop(struct ieee80211_hw *hw)
327{
Roland Vossen2646c462011-10-21 16:16:27 +0200328 struct brcms_info *wl = hw->priv;
329 int status;
330
Arend van Spriel5b435de2011-10-05 13:19:03 +0200331 ieee80211_stop_queues(hw);
Roland Vossen2646c462011-10-21 16:16:27 +0200332
333 if (wl->wlc == NULL)
334 return;
335
336 spin_lock_bh(&wl->lock);
Hauke Mehrtenscacaa642012-06-30 15:16:19 +0200337 status = brcms_c_chipmatch(wl->wlc->hw->d11core);
Roland Vossen2646c462011-10-21 16:16:27 +0200338 spin_unlock_bh(&wl->lock);
339 if (!status) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600340 brcms_err(wl->wlc->hw->d11core,
Roland Vossen2646c462011-10-21 16:16:27 +0200341 "wl: brcms_ops_stop: chipmatch failed\n");
342 return;
343 }
344
345 /* put driver in down state */
346 spin_lock_bh(&wl->lock);
347 brcms_down(wl);
348 spin_unlock_bh(&wl->lock);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200349}
350
351static int
352brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
353{
Roland Vossendc460122011-10-21 16:16:28 +0200354 struct brcms_info *wl = hw->priv;
355
Arend van Spriel5b435de2011-10-05 13:19:03 +0200356 /* Just STA for now */
Roland Vossen15256622011-10-21 16:16:29 +0200357 if (vif->type != NL80211_IFTYPE_STATION) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600358 brcms_err(wl->wlc->hw->d11core,
359 "%s: Attempt to add type %d, only STA for now\n",
360 __func__, vif->type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200361 return -EOPNOTSUPP;
362 }
363
Roland Vossendc460122011-10-21 16:16:28 +0200364 wl->mute_tx = false;
365 brcms_c_mute(wl->wlc, false);
366
Roland Vossen2646c462011-10-21 16:16:27 +0200367 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200368}
369
370static void
371brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
372{
Arend van Spriel5b435de2011-10-05 13:19:03 +0200373}
374
375static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
376{
377 struct ieee80211_conf *conf = &hw->conf;
378 struct brcms_info *wl = hw->priv;
Seth Forsheeb353dda2012-11-15 08:08:03 -0600379 struct bcma_device *core = wl->wlc->hw->d11core;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200380 int err = 0;
381 int new_int;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200382
383 spin_lock_bh(&wl->lock);
384 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
385 brcms_c_set_beacon_listen_interval(wl->wlc,
386 conf->listen_interval);
387 }
388 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600389 brcms_dbg_info(core, "%s: change monitor mode: %s\n",
390 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
391 "true" : "false");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200392 if (changed & IEEE80211_CONF_CHANGE_PS)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600393 brcms_err(core, "%s: change power-save mode: %s (implement)\n",
Arend van Spriel5b435de2011-10-05 13:19:03 +0200394 __func__, conf->flags & IEEE80211_CONF_PS ?
395 "true" : "false");
396
397 if (changed & IEEE80211_CONF_CHANGE_POWER) {
398 err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
399 if (err < 0) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600400 brcms_err(core, "%s: Error setting power_level\n",
Arend van Spriel5b435de2011-10-05 13:19:03 +0200401 __func__);
402 goto config_out;
403 }
404 new_int = brcms_c_get_tx_power(wl->wlc);
405 if (new_int != conf->power_level)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600406 brcms_err(core,
407 "%s: Power level req != actual, %d %d\n",
408 __func__, conf->power_level,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200409 new_int);
410 }
411 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
412 if (conf->channel_type == NL80211_CHAN_HT20 ||
413 conf->channel_type == NL80211_CHAN_NO_HT)
414 err = brcms_c_set_channel(wl->wlc,
415 conf->channel->hw_value);
416 else
417 err = -ENOTSUPP;
418 }
419 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
420 err = brcms_c_set_rate_limit(wl->wlc,
421 conf->short_frame_max_tx_count,
422 conf->long_frame_max_tx_count);
423
424 config_out:
425 spin_unlock_bh(&wl->lock);
426 return err;
427}
428
429static void
430brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
431 struct ieee80211_vif *vif,
432 struct ieee80211_bss_conf *info, u32 changed)
433{
434 struct brcms_info *wl = hw->priv;
Seth Forsheeb353dda2012-11-15 08:08:03 -0600435 struct bcma_device *core = wl->wlc->hw->d11core;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200436
437 if (changed & BSS_CHANGED_ASSOC) {
438 /* association status changed (associated/disassociated)
439 * also implies a change in the AID.
440 */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600441 brcms_err(core, "%s: %s: %sassociated\n", KBUILD_MODNAME,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200442 __func__, info->assoc ? "" : "dis");
443 spin_lock_bh(&wl->lock);
444 brcms_c_associate_upd(wl->wlc, info->assoc);
445 spin_unlock_bh(&wl->lock);
446 }
447 if (changed & BSS_CHANGED_ERP_SLOT) {
448 s8 val;
449
450 /* slot timing changed */
451 if (info->use_short_slot)
452 val = 1;
453 else
454 val = 0;
455 spin_lock_bh(&wl->lock);
456 brcms_c_set_shortslot_override(wl->wlc, val);
457 spin_unlock_bh(&wl->lock);
458 }
459
460 if (changed & BSS_CHANGED_HT) {
461 /* 802.11n parameters changed */
462 u16 mode = info->ht_operation_mode;
463
464 spin_lock_bh(&wl->lock);
465 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
466 mode & IEEE80211_HT_OP_MODE_PROTECTION);
467 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
468 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
469 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
470 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
471 spin_unlock_bh(&wl->lock);
472 }
473 if (changed & BSS_CHANGED_BASIC_RATES) {
474 struct ieee80211_supported_band *bi;
475 u32 br_mask, i;
476 u16 rate;
477 struct brcm_rateset rs;
478 int error;
479
480 /* retrieve the current rates */
481 spin_lock_bh(&wl->lock);
482 brcms_c_get_current_rateset(wl->wlc, &rs);
483 spin_unlock_bh(&wl->lock);
484
485 br_mask = info->basic_rates;
486 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
487 for (i = 0; i < bi->n_bitrates; i++) {
488 /* convert to internal rate value */
489 rate = (bi->bitrates[i].bitrate << 1) / 10;
490
491 /* set/clear basic rate flag */
492 brcms_set_basic_rate(&rs, rate, br_mask & 1);
493 br_mask >>= 1;
494 }
495
496 /* update the rate set */
497 spin_lock_bh(&wl->lock);
498 error = brcms_c_set_rateset(wl->wlc, &rs);
499 spin_unlock_bh(&wl->lock);
500 if (error)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600501 brcms_err(core, "changing basic rates failed: %d\n",
Arend van Spriel5b435de2011-10-05 13:19:03 +0200502 error);
503 }
504 if (changed & BSS_CHANGED_BEACON_INT) {
505 /* Beacon interval changed */
506 spin_lock_bh(&wl->lock);
507 brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
508 spin_unlock_bh(&wl->lock);
509 }
510 if (changed & BSS_CHANGED_BSSID) {
511 /* BSSID changed, for whatever reason (IBSS and managed mode) */
512 spin_lock_bh(&wl->lock);
513 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
514 spin_unlock_bh(&wl->lock);
515 }
516 if (changed & BSS_CHANGED_BEACON)
517 /* Beacon data changed, retrieve new beacon (beaconing modes) */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600518 brcms_err(core, "%s: beacon changed\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200519
520 if (changed & BSS_CHANGED_BEACON_ENABLED) {
521 /* Beaconing should be enabled/disabled (beaconing modes) */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600522 brcms_err(core, "%s: Beacon enabled: %s\n", __func__,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200523 info->enable_beacon ? "true" : "false");
524 }
525
526 if (changed & BSS_CHANGED_CQM) {
527 /* Connection quality monitor config changed */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600528 brcms_err(core, "%s: cqm change: threshold %d, hys %d "
Arend van Spriel5b435de2011-10-05 13:19:03 +0200529 " (implement)\n", __func__, info->cqm_rssi_thold,
530 info->cqm_rssi_hyst);
531 }
532
533 if (changed & BSS_CHANGED_IBSS) {
534 /* IBSS join status changed */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600535 brcms_err(core, "%s: IBSS joined: %s (implement)\n",
536 __func__, info->ibss_joined ? "true" : "false");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200537 }
538
539 if (changed & BSS_CHANGED_ARP_FILTER) {
540 /* Hardware ARP filter address list or state changed */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600541 brcms_err(core, "%s: arp filtering: enabled %s, count %d"
Arend van Spriel5b435de2011-10-05 13:19:03 +0200542 " (implement)\n", __func__, info->arp_filter_enabled ?
543 "true" : "false", info->arp_addr_cnt);
544 }
545
546 if (changed & BSS_CHANGED_QOS) {
547 /*
548 * QoS for this association was enabled/disabled.
549 * Note that it is only ever disabled for station mode.
550 */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600551 brcms_err(core, "%s: qos enabled: %s (implement)\n",
552 __func__, info->qos ? "true" : "false");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200553 }
554 return;
555}
556
557static void
558brcms_ops_configure_filter(struct ieee80211_hw *hw,
559 unsigned int changed_flags,
560 unsigned int *total_flags, u64 multicast)
561{
562 struct brcms_info *wl = hw->priv;
Seth Forsheeb353dda2012-11-15 08:08:03 -0600563 struct bcma_device *core = wl->wlc->hw->d11core;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200564
565 changed_flags &= MAC_FILTERS;
566 *total_flags &= MAC_FILTERS;
Alwin Beukersbe667662011-11-22 17:21:43 -0800567
Arend van Spriel5b435de2011-10-05 13:19:03 +0200568 if (changed_flags & FIF_PROMISC_IN_BSS)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600569 brcms_dbg_info(core, "FIF_PROMISC_IN_BSS\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200570 if (changed_flags & FIF_ALLMULTI)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600571 brcms_dbg_info(core, "FIF_ALLMULTI\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200572 if (changed_flags & FIF_FCSFAIL)
Seth Forsheead667862012-11-21 09:24:31 -0600573 brcms_dbg_info(core, "FIF_FCSFAIL\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200574 if (changed_flags & FIF_CONTROL)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600575 brcms_dbg_info(core, "FIF_CONTROL\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200576 if (changed_flags & FIF_OTHER_BSS)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600577 brcms_dbg_info(core, "FIF_OTHER_BSS\n");
Alwin Beukersbe667662011-11-22 17:21:43 -0800578 if (changed_flags & FIF_PSPOLL)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600579 brcms_dbg_info(core, "FIF_PSPOLL\n");
Alwin Beukersbe667662011-11-22 17:21:43 -0800580 if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600581 brcms_dbg_info(core, "FIF_BCN_PRBRESP_PROMISC\n");
Alwin Beukersbe667662011-11-22 17:21:43 -0800582
583 spin_lock_bh(&wl->lock);
584 brcms_c_mac_promisc(wl->wlc, *total_flags);
585 spin_unlock_bh(&wl->lock);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200586 return;
587}
588
589static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
590{
591 struct brcms_info *wl = hw->priv;
592 spin_lock_bh(&wl->lock);
593 brcms_c_scan_start(wl->wlc);
594 spin_unlock_bh(&wl->lock);
595 return;
596}
597
598static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
599{
600 struct brcms_info *wl = hw->priv;
601 spin_lock_bh(&wl->lock);
602 brcms_c_scan_stop(wl->wlc);
603 spin_unlock_bh(&wl->lock);
604 return;
605}
606
607static int
608brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
609 const struct ieee80211_tx_queue_params *params)
610{
611 struct brcms_info *wl = hw->priv;
612
613 spin_lock_bh(&wl->lock);
614 brcms_c_wme_setparams(wl->wlc, queue, params, true);
615 spin_unlock_bh(&wl->lock);
616
617 return 0;
618}
619
620static int
621brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
622 struct ieee80211_sta *sta)
623{
624 struct brcms_info *wl = hw->priv;
625 struct scb *scb = &wl->wlc->pri_scb;
626
627 brcms_c_init_scb(scb);
628
629 wl->pub->global_ampdu = &(scb->scb_ampdu);
630 wl->pub->global_ampdu->scb = scb;
631 wl->pub->global_ampdu->max_pdu = 16;
632
Arend van Spriel5b435de2011-10-05 13:19:03 +0200633 /*
634 * minstrel_ht initiates addBA on our behalf by calling
635 * ieee80211_start_tx_ba_session()
636 */
637 return 0;
638}
639
640static int
641brcms_ops_ampdu_action(struct ieee80211_hw *hw,
642 struct ieee80211_vif *vif,
643 enum ieee80211_ampdu_mlme_action action,
644 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
645 u8 buf_size)
646{
647 struct brcms_info *wl = hw->priv;
648 struct scb *scb = &wl->wlc->pri_scb;
649 int status;
650
651 if (WARN_ON(scb->magic != SCB_MAGIC))
652 return -EIDRM;
653 switch (action) {
654 case IEEE80211_AMPDU_RX_START:
655 break;
656 case IEEE80211_AMPDU_RX_STOP:
657 break;
658 case IEEE80211_AMPDU_TX_START:
659 spin_lock_bh(&wl->lock);
660 status = brcms_c_aggregatable(wl->wlc, tid);
661 spin_unlock_bh(&wl->lock);
662 if (!status) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600663 brcms_err(wl->wlc->hw->d11core,
664 "START: tid %d is not agg\'able\n", tid);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200665 return -EINVAL;
666 }
667 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
668 break;
669
670 case IEEE80211_AMPDU_TX_STOP:
671 spin_lock_bh(&wl->lock);
672 brcms_c_ampdu_flush(wl->wlc, sta, tid);
673 spin_unlock_bh(&wl->lock);
674 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
675 break;
676 case IEEE80211_AMPDU_TX_OPERATIONAL:
677 /*
678 * BA window size from ADDBA response ('buf_size') defines how
679 * many outstanding MPDUs are allowed for the BA stream by
680 * recipient and traffic class. 'ampdu_factor' gives maximum
681 * AMPDU size.
682 */
683 spin_lock_bh(&wl->lock);
684 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
685 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
686 sta->ht_cap.ampdu_factor)) - 1);
687 spin_unlock_bh(&wl->lock);
688 /* Power save wakeup */
689 break;
690 default:
Seth Forsheeb353dda2012-11-15 08:08:03 -0600691 brcms_err(wl->wlc->hw->d11core,
692 "%s: Invalid command, ignoring\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200693 }
694
695 return 0;
696}
697
698static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
699{
700 struct brcms_info *wl = hw->priv;
701 bool blocked;
702
703 spin_lock_bh(&wl->lock);
704 blocked = brcms_c_check_radio_disabled(wl->wlc);
705 spin_unlock_bh(&wl->lock);
706
707 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
708}
709
710static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
711{
712 struct brcms_info *wl = hw->priv;
713
714 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
715
716 /* wait for packet queue and dma fifos to run empty */
717 spin_lock_bh(&wl->lock);
718 brcms_c_wait_for_tx_completion(wl->wlc, drop);
719 spin_unlock_bh(&wl->lock);
720}
721
722static const struct ieee80211_ops brcms_ops = {
723 .tx = brcms_ops_tx,
724 .start = brcms_ops_start,
725 .stop = brcms_ops_stop,
726 .add_interface = brcms_ops_add_interface,
727 .remove_interface = brcms_ops_remove_interface,
728 .config = brcms_ops_config,
729 .bss_info_changed = brcms_ops_bss_info_changed,
730 .configure_filter = brcms_ops_configure_filter,
731 .sw_scan_start = brcms_ops_sw_scan_start,
732 .sw_scan_complete = brcms_ops_sw_scan_complete,
733 .conf_tx = brcms_ops_conf_tx,
734 .sta_add = brcms_ops_sta_add,
735 .ampdu_action = brcms_ops_ampdu_action,
736 .rfkill_poll = brcms_ops_rfkill_poll,
737 .flush = brcms_ops_flush,
738};
739
Arend van Spriel5b435de2011-10-05 13:19:03 +0200740void brcms_dpc(unsigned long data)
741{
742 struct brcms_info *wl;
743
744 wl = (struct brcms_info *) data;
745
746 spin_lock_bh(&wl->lock);
747
748 /* call the common second level interrupt handler */
749 if (wl->pub->up) {
750 if (wl->resched) {
751 unsigned long flags;
752
753 spin_lock_irqsave(&wl->isr_lock, flags);
754 brcms_c_intrsupd(wl->wlc);
755 spin_unlock_irqrestore(&wl->isr_lock, flags);
756 }
757
758 wl->resched = brcms_c_dpc(wl->wlc, true);
759 }
760
761 /* brcms_c_dpc() may bring the driver down */
762 if (!wl->pub->up)
763 goto done;
764
765 /* re-schedule dpc */
766 if (wl->resched)
767 tasklet_schedule(&wl->tasklet);
768 else
769 /* re-enable interrupts */
770 brcms_intrson(wl);
771
772 done:
773 spin_unlock_bh(&wl->lock);
774}
775
776/*
777 * Precondition: Since this function is called in brcms_pci_probe() context,
778 * no locking is required.
779 */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +0200780static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200781{
782 int status;
783 struct device *device = &pdev->dev;
784 char fw_name[100];
785 int i;
786
787 memset(&wl->fw, 0, sizeof(struct brcms_firmware));
788 for (i = 0; i < MAX_FW_IMAGES; i++) {
789 if (brcms_firmwares[i] == NULL)
790 break;
791 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
792 UCODE_LOADER_API_VER);
793 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
794 if (status) {
795 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
796 KBUILD_MODNAME, fw_name);
797 return status;
798 }
799 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
800 UCODE_LOADER_API_VER);
801 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
802 if (status) {
803 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
804 KBUILD_MODNAME, fw_name);
805 return status;
806 }
807 wl->fw.hdr_num_entries[i] =
808 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
809 }
810 wl->fw.fw_cnt = i;
811 return brcms_ucode_data_init(wl, &wl->ucode);
812}
813
814/*
815 * Precondition: Since this function is called in brcms_pci_probe() context,
816 * no locking is required.
817 */
818static void brcms_release_fw(struct brcms_info *wl)
819{
820 int i;
821 for (i = 0; i < MAX_FW_IMAGES; i++) {
822 release_firmware(wl->fw.fw_bin[i]);
823 release_firmware(wl->fw.fw_hdr[i]);
824 }
825}
826
827/**
828 * This function frees the WL per-device resources.
829 *
830 * This function frees resources owned by the WL device pointed to
831 * by the wl parameter.
832 *
833 * precondition: can both be called locked and unlocked
834 *
835 */
836static void brcms_free(struct brcms_info *wl)
837{
838 struct brcms_timer *t, *next;
839
840 /* free ucode data */
841 if (wl->fw.fw_cnt)
842 brcms_ucode_data_free(&wl->ucode);
843 if (wl->irq)
844 free_irq(wl->irq, wl);
845
846 /* kill dpc */
847 tasklet_kill(&wl->tasklet);
848
849 if (wl->pub)
850 brcms_c_module_unregister(wl->pub, "linux", wl);
851
852 /* free common resources */
853 if (wl->wlc) {
854 brcms_c_detach(wl->wlc);
855 wl->wlc = NULL;
856 wl->pub = NULL;
857 }
858
859 /* virtual interface deletion is deferred so we cannot spinwait */
860
861 /* wait for all pending callbacks to complete */
862 while (atomic_read(&wl->callbacks) > 0)
863 schedule();
864
865 /* free timers */
866 for (t = wl->timers; t; t = next) {
867 next = t->next;
Joe Perches8ae74652012-01-15 00:38:38 -0800868#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +0200869 kfree(t->name);
870#endif
871 kfree(t);
872 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200873}
874
875/*
Roland Vossen2646c462011-10-21 16:16:27 +0200876* called from both kernel as from this kernel module (error flow on attach)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200877* precondition: perimeter lock is not acquired.
878*/
Arend van Spriel2e7565602011-12-08 15:06:46 -0800879static void brcms_remove(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200880{
Arend van Spriel2e7565602011-12-08 15:06:46 -0800881 struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
Roland Vossen2646c462011-10-21 16:16:27 +0200882 struct brcms_info *wl = hw->priv;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200883
Arend van Spriel5b435de2011-10-05 13:19:03 +0200884 if (wl->wlc) {
885 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
886 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
887 ieee80211_unregister_hw(hw);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200888 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200889
890 brcms_free(wl);
891
Arend van Spriel2e7565602011-12-08 15:06:46 -0800892 bcma_set_drvdata(pdev, NULL);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200893 ieee80211_free_hw(hw);
894}
895
896static irqreturn_t brcms_isr(int irq, void *dev_id)
897{
898 struct brcms_info *wl;
899 bool ours, wantdpc;
900
901 wl = (struct brcms_info *) dev_id;
902
903 spin_lock(&wl->isr_lock);
904
905 /* call common first level interrupt handler */
906 ours = brcms_c_isr(wl->wlc, &wantdpc);
907 if (ours) {
908 /* if more to do... */
909 if (wantdpc) {
910
911 /* ...and call the second level interrupt handler */
912 /* schedule dpc */
913 tasklet_schedule(&wl->tasklet);
914 }
915 }
916
917 spin_unlock(&wl->isr_lock);
918
919 return IRQ_RETVAL(ours);
920}
921
922/*
923 * is called in brcms_pci_probe() context, therefore no locking required.
924 */
925static int ieee_hw_rate_init(struct ieee80211_hw *hw)
926{
927 struct brcms_info *wl = hw->priv;
928 struct brcms_c_info *wlc = wl->wlc;
929 struct ieee80211_supported_band *band;
930 int has_5g = 0;
931 u16 phy_type;
932
933 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
934 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
935
936 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
937 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
938 band = &wlc->bandstate[BAND_2G_INDEX]->band;
939 *band = brcms_band_2GHz_nphy_template;
940 if (phy_type == PHY_TYPE_LCN) {
941 /* Single stream */
942 band->ht_cap.mcs.rx_mask[1] = 0;
Arend van Sprieldf4492f2011-10-12 20:51:15 +0200943 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200944 }
945 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
946 } else {
947 return -EPERM;
948 }
949
950 /* Assume all bands use the same phy. True for 11n devices. */
951 if (wl->pub->_nbands > 1) {
952 has_5g++;
953 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
954 band = &wlc->bandstate[BAND_5G_INDEX]->band;
955 *band = brcms_band_5GHz_nphy_template;
956 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
957 } else {
958 return -EPERM;
959 }
960 }
961 return 0;
962}
963
964/*
965 * is called in brcms_pci_probe() context, therefore no locking required.
966 */
967static int ieee_hw_init(struct ieee80211_hw *hw)
968{
969 hw->flags = IEEE80211_HW_SIGNAL_DBM
970 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
971 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
972 | IEEE80211_HW_AMPDU_AGGREGATION;
973
974 hw->extra_tx_headroom = brcms_c_get_header_len();
975 hw->queues = N_TX_QUEUES;
976 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
977
978 /* channel change time is dependent on chip and band */
979 hw->channel_change_time = 7 * 1000;
980 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
981
982 hw->rate_control_algorithm = "minstrel_ht";
983
984 hw->sta_data_size = 0;
985 return ieee_hw_rate_init(hw);
986}
987
988/**
989 * attach to the WL device.
990 *
991 * Attach to the WL device identified by vendor and device parameters.
992 * regs is a host accessible memory address pointing to WL device registers.
993 *
994 * brcms_attach is not defined as static because in the case where no bus
995 * is defined, wl_attach will never be called, and thus, gcc will issue
996 * a warning that this function is defined but not used if we declare
997 * it as static.
998 *
999 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001000 * is called in brcms_bcma_probe() context, therefore no locking required.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001001 */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001002static struct brcms_info *brcms_attach(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001003{
1004 struct brcms_info *wl = NULL;
1005 int unit, err;
1006 struct ieee80211_hw *hw;
1007 u8 perm[ETH_ALEN];
1008
1009 unit = n_adapters_found;
1010 err = 0;
1011
1012 if (unit < 0)
1013 return NULL;
1014
1015 /* allocate private info */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001016 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001017 if (hw != NULL)
1018 wl = hw->priv;
1019 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1020 return NULL;
1021 wl->wiphy = hw->wiphy;
1022
1023 atomic_set(&wl->callbacks, 0);
1024
1025 /* setup the bottom half handler */
1026 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1027
Arend van Spriel5b435de2011-10-05 13:19:03 +02001028 spin_lock_init(&wl->lock);
1029 spin_lock_init(&wl->isr_lock);
1030
1031 /* prepare ucode */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001032 if (brcms_request_fw(wl, pdev) < 0) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001033 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
1034 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
1035 brcms_release_fw(wl);
Arend van Spriel2e7565602011-12-08 15:06:46 -08001036 brcms_remove(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001037 return NULL;
1038 }
1039
1040 /* common load-time initialization */
Arend van Sprielb63337a2011-12-08 15:06:47 -08001041 wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001042 brcms_release_fw(wl);
1043 if (!wl->wlc) {
1044 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1045 KBUILD_MODNAME, err);
1046 goto fail;
1047 }
1048 wl->pub = brcms_c_pub(wl->wlc);
1049
1050 wl->pub->ieee_hw = hw;
1051
Arend van Spriel5b435de2011-10-05 13:19:03 +02001052 /* register our interrupt handler */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001053 if (request_irq(pdev->irq, brcms_isr,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001054 IRQF_SHARED, KBUILD_MODNAME, wl)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001055 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1056 goto fail;
1057 }
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001058 wl->irq = pdev->irq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001059
1060 /* register module */
1061 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1062
1063 if (ieee_hw_init(hw)) {
1064 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1065 __func__);
1066 goto fail;
1067 }
1068
Seth Forsheecf03c5d2012-06-16 07:47:52 -05001069 brcms_c_regd_init(wl->wlc);
1070
Arend van Spriel5b435de2011-10-05 13:19:03 +02001071 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1072 if (WARN_ON(!is_valid_ether_addr(perm)))
1073 goto fail;
1074 SET_IEEE80211_PERM_ADDR(hw, perm);
1075
1076 err = ieee80211_register_hw(hw);
1077 if (err)
1078 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1079 "%d\n", __func__, err);
1080
Arend van Sprield597ee72012-06-09 22:51:41 +02001081 if (wl->pub->srom_ccode[0] &&
1082 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1083 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001084
1085 n_adapters_found++;
1086 return wl;
1087
1088fail:
1089 brcms_free(wl);
1090 return NULL;
1091}
1092
1093
1094
1095/**
1096 * determines if a device is a WL device, and if so, attaches it.
1097 *
1098 * This function determines if a device pointed to by pdev is a WL device,
1099 * and if so, performs a brcms_attach() on it.
1100 *
1101 * Perimeter lock is initialized in the course of this function.
1102 */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001103static int __devinit brcms_bcma_probe(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001104{
Arend van Spriel5b435de2011-10-05 13:19:03 +02001105 struct brcms_info *wl;
1106 struct ieee80211_hw *hw;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001107
Arend van Spriel2e7565602011-12-08 15:06:46 -08001108 dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
1109 pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001110 pdev->irq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001111
Arend van Spriel2e7565602011-12-08 15:06:46 -08001112 if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
1113 (pdev->id.id != BCMA_CORE_80211))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001114 return -ENODEV;
1115
Arend van Spriel5b435de2011-10-05 13:19:03 +02001116 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1117 if (!hw) {
1118 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1119 return -ENOMEM;
1120 }
1121
1122 SET_IEEE80211_DEV(hw, &pdev->dev);
1123
Arend van Spriel2e7565602011-12-08 15:06:46 -08001124 bcma_set_drvdata(pdev, hw);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001125
1126 memset(hw->priv, 0, sizeof(*wl));
1127
Arend van Spriel2e7565602011-12-08 15:06:46 -08001128 wl = brcms_attach(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001129 if (!wl) {
Joe Perches02f77192012-01-15 00:38:44 -08001130 pr_err("%s: brcms_attach failed!\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001131 return -ENODEV;
1132 }
1133 return 0;
1134}
1135
Linus Torvalds7d5869e2012-01-13 23:58:41 +01001136static int brcms_suspend(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001137{
1138 struct brcms_info *wl;
1139 struct ieee80211_hw *hw;
1140
Arend van Spriel2e7565602011-12-08 15:06:46 -08001141 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001142 wl = hw->priv;
1143 if (!wl) {
Arend van Spriel137dabe2012-02-09 21:08:59 +01001144 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
1145 __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001146 return -ENODEV;
1147 }
1148
1149 /* only need to flag hw is down for proper resume */
1150 spin_lock_bh(&wl->lock);
1151 wl->pub->hw_up = false;
1152 spin_unlock_bh(&wl->lock);
1153
Seth Forsheeb353dda2012-11-15 08:08:03 -06001154 brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001155
Arend van Spriel2e7565602011-12-08 15:06:46 -08001156 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001157}
1158
Arend van Spriel2e7565602011-12-08 15:06:46 -08001159static int brcms_resume(struct bcma_device *pdev)
1160{
Linus Torvalds7e9e7fa2012-01-13 23:58:42 +01001161 return 0;
Arend van Spriel2e7565602011-12-08 15:06:46 -08001162}
1163
1164static struct bcma_driver brcms_bcma_driver = {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001165 .name = KBUILD_MODNAME,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001166 .probe = brcms_bcma_probe,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001167 .suspend = brcms_suspend,
1168 .resume = brcms_resume,
1169 .remove = __devexit_p(brcms_remove),
Arend van Spriel2e7565602011-12-08 15:06:46 -08001170 .id_table = brcms_coreid_table,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001171};
1172
1173/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001174 * This is the main entry point for the brcmsmac driver.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001175 *
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001176 * This function is scheduled upon module initialization and
1177 * does the driver registration, which result in brcms_bcma_probe()
1178 * call resulting in the driver bringup.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001179 */
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001180static void brcms_driver_init(struct work_struct *work)
1181{
1182 int error;
1183
1184 error = bcma_driver_register(&brcms_bcma_driver);
1185 if (error)
1186 pr_err("%s: register returned %d\n", __func__, error);
1187}
1188
1189static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
1190
Arend van Spriel5b435de2011-10-05 13:19:03 +02001191static int __init brcms_module_init(void)
1192{
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001193 if (!schedule_work(&brcms_driver_work))
1194 return -EBUSY;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001195
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001196 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001197}
1198
1199/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001200 * This function unloads the brcmsmac driver from the system.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001201 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001202 * This function unconditionally unloads the brcmsmac driver module from the
Arend van Spriel5b435de2011-10-05 13:19:03 +02001203 * system.
1204 *
1205 */
1206static void __exit brcms_module_exit(void)
1207{
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001208 cancel_work_sync(&brcms_driver_work);
Arend van Spriel2e7565602011-12-08 15:06:46 -08001209 bcma_driver_unregister(&brcms_bcma_driver);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001210}
1211
1212module_init(brcms_module_init);
1213module_exit(brcms_module_exit);
1214
1215/*
1216 * precondition: perimeter lock has been acquired
1217 */
1218void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1219 bool state, int prio)
1220{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001221 brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001222}
1223
1224/*
1225 * precondition: perimeter lock has been acquired
1226 */
1227void brcms_init(struct brcms_info *wl)
1228{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001229 brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
1230 wl->pub->unit);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001231 brcms_reset(wl);
Roland Vossendc460122011-10-21 16:16:28 +02001232 brcms_c_init(wl->wlc, wl->mute_tx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001233}
1234
1235/*
1236 * precondition: perimeter lock has been acquired
1237 */
1238uint brcms_reset(struct brcms_info *wl)
1239{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001240 brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001241 brcms_c_reset(wl->wlc);
1242
1243 /* dpc will not be rescheduled */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001244 wl->resched = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001245
Vladimir Zapolskiyea2d2182012-08-05 00:29:07 +03001246 /* inform publicly that interface is down */
1247 wl->pub->up = false;
1248
Arend van Spriel5b435de2011-10-05 13:19:03 +02001249 return 0;
1250}
1251
Roland Vossenc261bdf2011-10-18 14:03:04 +02001252void brcms_fatal_error(struct brcms_info *wl)
1253{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001254 brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
Roland Vossenc261bdf2011-10-18 14:03:04 +02001255 wl->wlc->pub->unit);
1256 brcms_reset(wl);
1257 ieee80211_restart_hw(wl->pub->ieee_hw);
1258}
1259
Arend van Spriel5b435de2011-10-05 13:19:03 +02001260/*
1261 * These are interrupt on/off entry points. Disable interrupts
1262 * during interrupt state transition.
1263 */
1264void brcms_intrson(struct brcms_info *wl)
1265{
1266 unsigned long flags;
1267
1268 spin_lock_irqsave(&wl->isr_lock, flags);
1269 brcms_c_intrson(wl->wlc);
1270 spin_unlock_irqrestore(&wl->isr_lock, flags);
1271}
1272
1273u32 brcms_intrsoff(struct brcms_info *wl)
1274{
1275 unsigned long flags;
1276 u32 status;
1277
1278 spin_lock_irqsave(&wl->isr_lock, flags);
1279 status = brcms_c_intrsoff(wl->wlc);
1280 spin_unlock_irqrestore(&wl->isr_lock, flags);
1281 return status;
1282}
1283
1284void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1285{
1286 unsigned long flags;
1287
1288 spin_lock_irqsave(&wl->isr_lock, flags);
1289 brcms_c_intrsrestore(wl->wlc, macintmask);
1290 spin_unlock_irqrestore(&wl->isr_lock, flags);
1291}
1292
1293/*
1294 * precondition: perimeter lock has been acquired
1295 */
1296int brcms_up(struct brcms_info *wl)
1297{
1298 int error = 0;
1299
1300 if (wl->pub->up)
1301 return 0;
1302
1303 error = brcms_c_up(wl->wlc);
1304
1305 return error;
1306}
1307
1308/*
1309 * precondition: perimeter lock has been acquired
1310 */
1311void brcms_down(struct brcms_info *wl)
1312{
1313 uint callbacks, ret_val = 0;
1314
1315 /* call common down function */
1316 ret_val = brcms_c_down(wl->wlc);
1317 callbacks = atomic_read(&wl->callbacks) - ret_val;
1318
1319 /* wait for down callbacks to complete */
1320 spin_unlock_bh(&wl->lock);
1321
1322 /* For HIGH_only driver, it's important to actually schedule other work,
1323 * not just spin wait since everything runs at schedule level
1324 */
1325 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1326
1327 spin_lock_bh(&wl->lock);
1328}
1329
1330/*
1331* precondition: perimeter lock is not acquired
1332 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001333static void _brcms_timer(struct work_struct *work)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001334{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001335 struct brcms_timer *t = container_of(work, struct brcms_timer,
1336 dly_wrk.work);
1337
Arend van Spriel5b435de2011-10-05 13:19:03 +02001338 spin_lock_bh(&t->wl->lock);
1339
1340 if (t->set) {
1341 if (t->periodic) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001342 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001343 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1344 &t->dly_wrk,
1345 msecs_to_jiffies(t->ms));
1346 } else {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001347 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001348 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001349
1350 t->fn(t->arg);
1351 }
1352
1353 atomic_dec(&t->wl->callbacks);
1354
1355 spin_unlock_bh(&t->wl->lock);
1356}
1357
1358/*
Arend van Spriel5b435de2011-10-05 13:19:03 +02001359 * Adds a timer to the list. Caller supplies a timer function.
1360 * Is called from wlc.
1361 *
1362 * precondition: perimeter lock has been acquired
1363 */
1364struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1365 void (*fn) (void *arg),
1366 void *arg, const char *name)
1367{
1368 struct brcms_timer *t;
1369
1370 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1371 if (!t)
1372 return NULL;
1373
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001374 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001375 t->wl = wl;
1376 t->fn = fn;
1377 t->arg = arg;
1378 t->next = wl->timers;
1379 wl->timers = t;
1380
Joe Perches8ae74652012-01-15 00:38:38 -08001381#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001382 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1383 if (t->name)
1384 strcpy(t->name, name);
1385#endif
1386
1387 return t;
1388}
1389
1390/*
1391 * adds only the kernel timer since it's going to be more accurate
1392 * as well as it's easier to make it periodic
1393 *
1394 * precondition: perimeter lock has been acquired
1395 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001396void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001397{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001398 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1399
Joe Perches8ae74652012-01-15 00:38:38 -08001400#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001401 if (t->set)
Seth Forsheeb353dda2012-11-15 08:08:03 -06001402 brcms_dbg_info(t->wl->wlc->hw->d11core,
1403 "%s: Already set. Name: %s, per %d\n",
1404 __func__, t->name, periodic);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001405#endif
1406 t->ms = ms;
1407 t->periodic = (bool) periodic;
1408 t->set = true;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001409
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001410 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001411
1412 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001413}
1414
1415/*
1416 * return true if timer successfully deleted, false if still pending
1417 *
1418 * precondition: perimeter lock has been acquired
1419 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001420bool brcms_del_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001421{
1422 if (t->set) {
1423 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001424 if (!cancel_delayed_work(&t->dly_wrk))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001425 return false;
1426
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001427 atomic_dec(&t->wl->callbacks);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001428 }
1429
1430 return true;
1431}
1432
1433/*
1434 * precondition: perimeter lock has been acquired
1435 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001436void brcms_free_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001437{
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001438 struct brcms_info *wl = t->wl;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001439 struct brcms_timer *tmp;
1440
1441 /* delete the timer in case it is active */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001442 brcms_del_timer(t);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001443
1444 if (wl->timers == t) {
1445 wl->timers = wl->timers->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001446#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001447 kfree(t->name);
1448#endif
1449 kfree(t);
1450 return;
1451
1452 }
1453
1454 tmp = wl->timers;
1455 while (tmp) {
1456 if (tmp->next == t) {
1457 tmp->next = t->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001458#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001459 kfree(t->name);
1460#endif
1461 kfree(t);
1462 return;
1463 }
1464 tmp = tmp->next;
1465 }
1466
1467}
1468
1469/*
1470 * precondition: perimeter lock has been acquired
1471 */
1472int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1473{
1474 int i, entry;
1475 const u8 *pdata;
1476 struct firmware_hdr *hdr;
1477 for (i = 0; i < wl->fw.fw_cnt; i++) {
1478 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1479 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1480 entry++, hdr++) {
1481 u32 len = le32_to_cpu(hdr->len);
1482 if (le32_to_cpu(hdr->idx) == idx) {
1483 pdata = wl->fw.fw_bin[i]->data +
1484 le32_to_cpu(hdr->offset);
Thomas Meyer1f1d52892011-11-17 23:43:40 +01001485 *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001486 if (*pbuf == NULL)
1487 goto fail;
1488
Arend van Spriel5b435de2011-10-05 13:19:03 +02001489 return 0;
1490 }
1491 }
1492 }
Seth Forsheeb353dda2012-11-15 08:08:03 -06001493 brcms_err(wl->wlc->hw->d11core,
1494 "ERROR: ucode buf tag:%d can not be found!\n", idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001495 *pbuf = NULL;
1496fail:
1497 return -ENODATA;
1498}
1499
1500/*
Arend van Spriel2e7565602011-12-08 15:06:46 -08001501 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001502 * no locking is required.
1503 */
1504int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1505{
1506 int i, entry;
1507 const u8 *pdata;
1508 struct firmware_hdr *hdr;
1509 for (i = 0; i < wl->fw.fw_cnt; i++) {
1510 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1511 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1512 entry++, hdr++) {
1513 if (le32_to_cpu(hdr->idx) == idx) {
1514 pdata = wl->fw.fw_bin[i]->data +
1515 le32_to_cpu(hdr->offset);
1516 if (le32_to_cpu(hdr->len) != 4) {
Seth Forsheeb353dda2012-11-15 08:08:03 -06001517 brcms_err(wl->wlc->hw->d11core,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001518 "ERROR: fw hdr len\n");
1519 return -ENOMSG;
1520 }
1521 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1522 return 0;
1523 }
1524 }
1525 }
Seth Forsheeb353dda2012-11-15 08:08:03 -06001526 brcms_err(wl->wlc->hw->d11core,
1527 "ERROR: ucode tag:%d can not be found!\n", idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001528 return -ENOMSG;
1529}
1530
1531/*
1532 * precondition: can both be called locked and unlocked
1533 */
1534void brcms_ucode_free_buf(void *p)
1535{
1536 kfree(p);
1537}
1538
1539/*
1540 * checks validity of all firmware images loaded from user space
1541 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001542 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001543 * no locking is required.
1544 */
1545int brcms_check_firmwares(struct brcms_info *wl)
1546{
1547 int i;
1548 int entry;
1549 int rc = 0;
1550 const struct firmware *fw;
1551 const struct firmware *fw_hdr;
1552 struct firmware_hdr *ucode_hdr;
1553 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1554 fw = wl->fw.fw_bin[i];
1555 fw_hdr = wl->fw.fw_hdr[i];
1556 if (fw == NULL && fw_hdr == NULL) {
1557 break;
1558 } else if (fw == NULL || fw_hdr == NULL) {
1559 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1560 __func__);
1561 rc = -EBADF;
1562 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1563 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1564 "size %zu/%zu\n", __func__, fw_hdr->size,
1565 sizeof(struct firmware_hdr));
1566 rc = -EBADF;
1567 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
Seth Forsheeb353dda2012-11-15 08:08:03 -06001568 wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
1569 __func__, fw->size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001570 rc = -EBADF;
1571 } else {
1572 /* check if ucode section overruns firmware image */
1573 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1574 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1575 !rc; entry++, ucode_hdr++) {
1576 if (le32_to_cpu(ucode_hdr->offset) +
1577 le32_to_cpu(ucode_hdr->len) >
1578 fw->size) {
1579 wiphy_err(wl->wiphy,
1580 "%s: conflicting bin/hdr\n",
1581 __func__);
1582 rc = -EBADF;
1583 }
1584 }
1585 }
1586 }
1587 if (rc == 0 && wl->fw.fw_cnt != i) {
1588 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1589 wl->fw.fw_cnt);
1590 rc = -EBADF;
1591 }
1592 return rc;
1593}
1594
1595/*
1596 * precondition: perimeter lock has been acquired
1597 */
1598bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1599{
1600 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1601
1602 spin_unlock_bh(&wl->lock);
1603 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1604 if (blocked)
1605 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1606 spin_lock_bh(&wl->lock);
1607 return blocked;
1608}
1609
1610/*
1611 * precondition: perimeter lock has been acquired
1612 */
1613void brcms_msleep(struct brcms_info *wl, uint ms)
1614{
1615 spin_unlock_bh(&wl->lock);
1616 msleep(ms);
1617 spin_lock_bh(&wl->lock);
1618}