blob: 976720ccf17aad6a3a02f3cc558515363c9f0002 [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;
Piotr Haber94d99022012-11-28 21:44:06 +0100899 irqreturn_t ret = IRQ_NONE;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200900
901 wl = (struct brcms_info *) dev_id;
902
903 spin_lock(&wl->isr_lock);
904
905 /* call common first level interrupt handler */
Piotr Haber94d99022012-11-28 21:44:06 +0100906 if (brcms_c_isr(wl->wlc)) {
907 /* schedule second level handler */
908 tasklet_schedule(&wl->tasklet);
909 ret = IRQ_HANDLED;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200910 }
911
912 spin_unlock(&wl->isr_lock);
913
Piotr Haber94d99022012-11-28 21:44:06 +0100914 return ret;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200915}
916
917/*
918 * is called in brcms_pci_probe() context, therefore no locking required.
919 */
920static int ieee_hw_rate_init(struct ieee80211_hw *hw)
921{
922 struct brcms_info *wl = hw->priv;
923 struct brcms_c_info *wlc = wl->wlc;
924 struct ieee80211_supported_band *band;
925 int has_5g = 0;
926 u16 phy_type;
927
928 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
929 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
930
931 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
932 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
933 band = &wlc->bandstate[BAND_2G_INDEX]->band;
934 *band = brcms_band_2GHz_nphy_template;
935 if (phy_type == PHY_TYPE_LCN) {
936 /* Single stream */
937 band->ht_cap.mcs.rx_mask[1] = 0;
Arend van Sprieldf4492f2011-10-12 20:51:15 +0200938 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200939 }
940 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
941 } else {
942 return -EPERM;
943 }
944
945 /* Assume all bands use the same phy. True for 11n devices. */
946 if (wl->pub->_nbands > 1) {
947 has_5g++;
948 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
949 band = &wlc->bandstate[BAND_5G_INDEX]->band;
950 *band = brcms_band_5GHz_nphy_template;
951 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
952 } else {
953 return -EPERM;
954 }
955 }
956 return 0;
957}
958
959/*
960 * is called in brcms_pci_probe() context, therefore no locking required.
961 */
962static int ieee_hw_init(struct ieee80211_hw *hw)
963{
964 hw->flags = IEEE80211_HW_SIGNAL_DBM
965 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
966 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
967 | IEEE80211_HW_AMPDU_AGGREGATION;
968
969 hw->extra_tx_headroom = brcms_c_get_header_len();
970 hw->queues = N_TX_QUEUES;
971 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
972
973 /* channel change time is dependent on chip and band */
974 hw->channel_change_time = 7 * 1000;
975 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
976
977 hw->rate_control_algorithm = "minstrel_ht";
978
979 hw->sta_data_size = 0;
980 return ieee_hw_rate_init(hw);
981}
982
983/**
984 * attach to the WL device.
985 *
986 * Attach to the WL device identified by vendor and device parameters.
987 * regs is a host accessible memory address pointing to WL device registers.
988 *
989 * brcms_attach is not defined as static because in the case where no bus
990 * is defined, wl_attach will never be called, and thus, gcc will issue
991 * a warning that this function is defined but not used if we declare
992 * it as static.
993 *
994 *
Arend van Spriel2e7565602011-12-08 15:06:46 -0800995 * is called in brcms_bcma_probe() context, therefore no locking required.
Arend van Spriel5b435de2011-10-05 13:19:03 +0200996 */
Arend van Spriel2e7565602011-12-08 15:06:46 -0800997static struct brcms_info *brcms_attach(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200998{
999 struct brcms_info *wl = NULL;
1000 int unit, err;
1001 struct ieee80211_hw *hw;
1002 u8 perm[ETH_ALEN];
1003
1004 unit = n_adapters_found;
1005 err = 0;
1006
1007 if (unit < 0)
1008 return NULL;
1009
1010 /* allocate private info */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001011 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001012 if (hw != NULL)
1013 wl = hw->priv;
1014 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1015 return NULL;
1016 wl->wiphy = hw->wiphy;
1017
1018 atomic_set(&wl->callbacks, 0);
1019
1020 /* setup the bottom half handler */
1021 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1022
Arend van Spriel5b435de2011-10-05 13:19:03 +02001023 spin_lock_init(&wl->lock);
1024 spin_lock_init(&wl->isr_lock);
1025
1026 /* prepare ucode */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001027 if (brcms_request_fw(wl, pdev) < 0) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001028 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
1029 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
1030 brcms_release_fw(wl);
Arend van Spriel2e7565602011-12-08 15:06:46 -08001031 brcms_remove(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001032 return NULL;
1033 }
1034
1035 /* common load-time initialization */
Arend van Sprielb63337a2011-12-08 15:06:47 -08001036 wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001037 brcms_release_fw(wl);
1038 if (!wl->wlc) {
1039 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1040 KBUILD_MODNAME, err);
1041 goto fail;
1042 }
1043 wl->pub = brcms_c_pub(wl->wlc);
1044
1045 wl->pub->ieee_hw = hw;
1046
Arend van Spriel5b435de2011-10-05 13:19:03 +02001047 /* register our interrupt handler */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001048 if (request_irq(pdev->irq, brcms_isr,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001049 IRQF_SHARED, KBUILD_MODNAME, wl)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001050 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1051 goto fail;
1052 }
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001053 wl->irq = pdev->irq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001054
1055 /* register module */
1056 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1057
1058 if (ieee_hw_init(hw)) {
1059 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1060 __func__);
1061 goto fail;
1062 }
1063
Seth Forsheecf03c5d2012-06-16 07:47:52 -05001064 brcms_c_regd_init(wl->wlc);
1065
Arend van Spriel5b435de2011-10-05 13:19:03 +02001066 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1067 if (WARN_ON(!is_valid_ether_addr(perm)))
1068 goto fail;
1069 SET_IEEE80211_PERM_ADDR(hw, perm);
1070
1071 err = ieee80211_register_hw(hw);
1072 if (err)
1073 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1074 "%d\n", __func__, err);
1075
Arend van Sprield597ee72012-06-09 22:51:41 +02001076 if (wl->pub->srom_ccode[0] &&
1077 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1078 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001079
1080 n_adapters_found++;
1081 return wl;
1082
1083fail:
1084 brcms_free(wl);
1085 return NULL;
1086}
1087
1088
1089
1090/**
1091 * determines if a device is a WL device, and if so, attaches it.
1092 *
1093 * This function determines if a device pointed to by pdev is a WL device,
1094 * and if so, performs a brcms_attach() on it.
1095 *
1096 * Perimeter lock is initialized in the course of this function.
1097 */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001098static int __devinit brcms_bcma_probe(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001099{
Arend van Spriel5b435de2011-10-05 13:19:03 +02001100 struct brcms_info *wl;
1101 struct ieee80211_hw *hw;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001102
Arend van Spriel2e7565602011-12-08 15:06:46 -08001103 dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
1104 pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001105 pdev->irq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001106
Arend van Spriel2e7565602011-12-08 15:06:46 -08001107 if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
1108 (pdev->id.id != BCMA_CORE_80211))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001109 return -ENODEV;
1110
Arend van Spriel5b435de2011-10-05 13:19:03 +02001111 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1112 if (!hw) {
1113 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1114 return -ENOMEM;
1115 }
1116
1117 SET_IEEE80211_DEV(hw, &pdev->dev);
1118
Arend van Spriel2e7565602011-12-08 15:06:46 -08001119 bcma_set_drvdata(pdev, hw);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001120
1121 memset(hw->priv, 0, sizeof(*wl));
1122
Arend van Spriel2e7565602011-12-08 15:06:46 -08001123 wl = brcms_attach(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001124 if (!wl) {
Joe Perches02f77192012-01-15 00:38:44 -08001125 pr_err("%s: brcms_attach failed!\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001126 return -ENODEV;
1127 }
1128 return 0;
1129}
1130
Linus Torvalds7d5869e2012-01-13 23:58:41 +01001131static int brcms_suspend(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001132{
1133 struct brcms_info *wl;
1134 struct ieee80211_hw *hw;
1135
Arend van Spriel2e7565602011-12-08 15:06:46 -08001136 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001137 wl = hw->priv;
1138 if (!wl) {
Arend van Spriel137dabe2012-02-09 21:08:59 +01001139 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
1140 __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001141 return -ENODEV;
1142 }
1143
1144 /* only need to flag hw is down for proper resume */
1145 spin_lock_bh(&wl->lock);
1146 wl->pub->hw_up = false;
1147 spin_unlock_bh(&wl->lock);
1148
Seth Forsheeb353dda2012-11-15 08:08:03 -06001149 brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001150
Arend van Spriel2e7565602011-12-08 15:06:46 -08001151 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001152}
1153
Arend van Spriel2e7565602011-12-08 15:06:46 -08001154static int brcms_resume(struct bcma_device *pdev)
1155{
Linus Torvalds7e9e7fa2012-01-13 23:58:42 +01001156 return 0;
Arend van Spriel2e7565602011-12-08 15:06:46 -08001157}
1158
1159static struct bcma_driver brcms_bcma_driver = {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001160 .name = KBUILD_MODNAME,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001161 .probe = brcms_bcma_probe,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001162 .suspend = brcms_suspend,
1163 .resume = brcms_resume,
1164 .remove = __devexit_p(brcms_remove),
Arend van Spriel2e7565602011-12-08 15:06:46 -08001165 .id_table = brcms_coreid_table,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001166};
1167
1168/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001169 * This is the main entry point for the brcmsmac driver.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001170 *
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001171 * This function is scheduled upon module initialization and
1172 * does the driver registration, which result in brcms_bcma_probe()
1173 * call resulting in the driver bringup.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001174 */
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001175static void brcms_driver_init(struct work_struct *work)
1176{
1177 int error;
1178
1179 error = bcma_driver_register(&brcms_bcma_driver);
1180 if (error)
1181 pr_err("%s: register returned %d\n", __func__, error);
1182}
1183
1184static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
1185
Arend van Spriel5b435de2011-10-05 13:19:03 +02001186static int __init brcms_module_init(void)
1187{
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001188 if (!schedule_work(&brcms_driver_work))
1189 return -EBUSY;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001190
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001191 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001192}
1193
1194/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001195 * This function unloads the brcmsmac driver from the system.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001196 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001197 * This function unconditionally unloads the brcmsmac driver module from the
Arend van Spriel5b435de2011-10-05 13:19:03 +02001198 * system.
1199 *
1200 */
1201static void __exit brcms_module_exit(void)
1202{
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001203 cancel_work_sync(&brcms_driver_work);
Arend van Spriel2e7565602011-12-08 15:06:46 -08001204 bcma_driver_unregister(&brcms_bcma_driver);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001205}
1206
1207module_init(brcms_module_init);
1208module_exit(brcms_module_exit);
1209
1210/*
1211 * precondition: perimeter lock has been acquired
1212 */
1213void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1214 bool state, int prio)
1215{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001216 brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001217}
1218
1219/*
1220 * precondition: perimeter lock has been acquired
1221 */
1222void brcms_init(struct brcms_info *wl)
1223{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001224 brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
1225 wl->pub->unit);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001226 brcms_reset(wl);
Roland Vossendc460122011-10-21 16:16:28 +02001227 brcms_c_init(wl->wlc, wl->mute_tx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001228}
1229
1230/*
1231 * precondition: perimeter lock has been acquired
1232 */
1233uint brcms_reset(struct brcms_info *wl)
1234{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001235 brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001236 brcms_c_reset(wl->wlc);
1237
1238 /* dpc will not be rescheduled */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001239 wl->resched = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001240
Vladimir Zapolskiyea2d2182012-08-05 00:29:07 +03001241 /* inform publicly that interface is down */
1242 wl->pub->up = false;
1243
Arend van Spriel5b435de2011-10-05 13:19:03 +02001244 return 0;
1245}
1246
Roland Vossenc261bdf2011-10-18 14:03:04 +02001247void brcms_fatal_error(struct brcms_info *wl)
1248{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001249 brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
Roland Vossenc261bdf2011-10-18 14:03:04 +02001250 wl->wlc->pub->unit);
1251 brcms_reset(wl);
1252 ieee80211_restart_hw(wl->pub->ieee_hw);
1253}
1254
Arend van Spriel5b435de2011-10-05 13:19:03 +02001255/*
1256 * These are interrupt on/off entry points. Disable interrupts
1257 * during interrupt state transition.
1258 */
1259void brcms_intrson(struct brcms_info *wl)
1260{
1261 unsigned long flags;
1262
1263 spin_lock_irqsave(&wl->isr_lock, flags);
1264 brcms_c_intrson(wl->wlc);
1265 spin_unlock_irqrestore(&wl->isr_lock, flags);
1266}
1267
1268u32 brcms_intrsoff(struct brcms_info *wl)
1269{
1270 unsigned long flags;
1271 u32 status;
1272
1273 spin_lock_irqsave(&wl->isr_lock, flags);
1274 status = brcms_c_intrsoff(wl->wlc);
1275 spin_unlock_irqrestore(&wl->isr_lock, flags);
1276 return status;
1277}
1278
1279void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1280{
1281 unsigned long flags;
1282
1283 spin_lock_irqsave(&wl->isr_lock, flags);
1284 brcms_c_intrsrestore(wl->wlc, macintmask);
1285 spin_unlock_irqrestore(&wl->isr_lock, flags);
1286}
1287
1288/*
1289 * precondition: perimeter lock has been acquired
1290 */
1291int brcms_up(struct brcms_info *wl)
1292{
1293 int error = 0;
1294
1295 if (wl->pub->up)
1296 return 0;
1297
1298 error = brcms_c_up(wl->wlc);
1299
1300 return error;
1301}
1302
1303/*
1304 * precondition: perimeter lock has been acquired
1305 */
1306void brcms_down(struct brcms_info *wl)
1307{
1308 uint callbacks, ret_val = 0;
1309
1310 /* call common down function */
1311 ret_val = brcms_c_down(wl->wlc);
1312 callbacks = atomic_read(&wl->callbacks) - ret_val;
1313
1314 /* wait for down callbacks to complete */
1315 spin_unlock_bh(&wl->lock);
1316
1317 /* For HIGH_only driver, it's important to actually schedule other work,
1318 * not just spin wait since everything runs at schedule level
1319 */
1320 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1321
1322 spin_lock_bh(&wl->lock);
1323}
1324
1325/*
1326* precondition: perimeter lock is not acquired
1327 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001328static void _brcms_timer(struct work_struct *work)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001329{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001330 struct brcms_timer *t = container_of(work, struct brcms_timer,
1331 dly_wrk.work);
1332
Arend van Spriel5b435de2011-10-05 13:19:03 +02001333 spin_lock_bh(&t->wl->lock);
1334
1335 if (t->set) {
1336 if (t->periodic) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001337 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001338 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1339 &t->dly_wrk,
1340 msecs_to_jiffies(t->ms));
1341 } else {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001342 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001343 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001344
1345 t->fn(t->arg);
1346 }
1347
1348 atomic_dec(&t->wl->callbacks);
1349
1350 spin_unlock_bh(&t->wl->lock);
1351}
1352
1353/*
Arend van Spriel5b435de2011-10-05 13:19:03 +02001354 * Adds a timer to the list. Caller supplies a timer function.
1355 * Is called from wlc.
1356 *
1357 * precondition: perimeter lock has been acquired
1358 */
1359struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1360 void (*fn) (void *arg),
1361 void *arg, const char *name)
1362{
1363 struct brcms_timer *t;
1364
1365 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1366 if (!t)
1367 return NULL;
1368
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001369 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001370 t->wl = wl;
1371 t->fn = fn;
1372 t->arg = arg;
1373 t->next = wl->timers;
1374 wl->timers = t;
1375
Joe Perches8ae74652012-01-15 00:38:38 -08001376#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001377 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1378 if (t->name)
1379 strcpy(t->name, name);
1380#endif
1381
1382 return t;
1383}
1384
1385/*
1386 * adds only the kernel timer since it's going to be more accurate
1387 * as well as it's easier to make it periodic
1388 *
1389 * precondition: perimeter lock has been acquired
1390 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001391void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001392{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001393 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1394
Joe Perches8ae74652012-01-15 00:38:38 -08001395#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001396 if (t->set)
Seth Forsheeb353dda2012-11-15 08:08:03 -06001397 brcms_dbg_info(t->wl->wlc->hw->d11core,
1398 "%s: Already set. Name: %s, per %d\n",
1399 __func__, t->name, periodic);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001400#endif
1401 t->ms = ms;
1402 t->periodic = (bool) periodic;
1403 t->set = true;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001404
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001405 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001406
1407 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001408}
1409
1410/*
1411 * return true if timer successfully deleted, false if still pending
1412 *
1413 * precondition: perimeter lock has been acquired
1414 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001415bool brcms_del_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001416{
1417 if (t->set) {
1418 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001419 if (!cancel_delayed_work(&t->dly_wrk))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001420 return false;
1421
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001422 atomic_dec(&t->wl->callbacks);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001423 }
1424
1425 return true;
1426}
1427
1428/*
1429 * precondition: perimeter lock has been acquired
1430 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001431void brcms_free_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001432{
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001433 struct brcms_info *wl = t->wl;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001434 struct brcms_timer *tmp;
1435
1436 /* delete the timer in case it is active */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001437 brcms_del_timer(t);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001438
1439 if (wl->timers == t) {
1440 wl->timers = wl->timers->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001441#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001442 kfree(t->name);
1443#endif
1444 kfree(t);
1445 return;
1446
1447 }
1448
1449 tmp = wl->timers;
1450 while (tmp) {
1451 if (tmp->next == t) {
1452 tmp->next = t->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001453#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001454 kfree(t->name);
1455#endif
1456 kfree(t);
1457 return;
1458 }
1459 tmp = tmp->next;
1460 }
1461
1462}
1463
1464/*
1465 * precondition: perimeter lock has been acquired
1466 */
1467int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1468{
1469 int i, entry;
1470 const u8 *pdata;
1471 struct firmware_hdr *hdr;
1472 for (i = 0; i < wl->fw.fw_cnt; i++) {
1473 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1474 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1475 entry++, hdr++) {
1476 u32 len = le32_to_cpu(hdr->len);
1477 if (le32_to_cpu(hdr->idx) == idx) {
1478 pdata = wl->fw.fw_bin[i]->data +
1479 le32_to_cpu(hdr->offset);
Thomas Meyer1f1d52892011-11-17 23:43:40 +01001480 *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001481 if (*pbuf == NULL)
1482 goto fail;
1483
Arend van Spriel5b435de2011-10-05 13:19:03 +02001484 return 0;
1485 }
1486 }
1487 }
Seth Forsheeb353dda2012-11-15 08:08:03 -06001488 brcms_err(wl->wlc->hw->d11core,
1489 "ERROR: ucode buf tag:%d can not be found!\n", idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001490 *pbuf = NULL;
1491fail:
1492 return -ENODATA;
1493}
1494
1495/*
Arend van Spriel2e7565602011-12-08 15:06:46 -08001496 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001497 * no locking is required.
1498 */
1499int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1500{
1501 int i, entry;
1502 const u8 *pdata;
1503 struct firmware_hdr *hdr;
1504 for (i = 0; i < wl->fw.fw_cnt; i++) {
1505 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1506 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1507 entry++, hdr++) {
1508 if (le32_to_cpu(hdr->idx) == idx) {
1509 pdata = wl->fw.fw_bin[i]->data +
1510 le32_to_cpu(hdr->offset);
1511 if (le32_to_cpu(hdr->len) != 4) {
Seth Forsheeb353dda2012-11-15 08:08:03 -06001512 brcms_err(wl->wlc->hw->d11core,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001513 "ERROR: fw hdr len\n");
1514 return -ENOMSG;
1515 }
1516 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1517 return 0;
1518 }
1519 }
1520 }
Seth Forsheeb353dda2012-11-15 08:08:03 -06001521 brcms_err(wl->wlc->hw->d11core,
1522 "ERROR: ucode tag:%d can not be found!\n", idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001523 return -ENOMSG;
1524}
1525
1526/*
1527 * precondition: can both be called locked and unlocked
1528 */
1529void brcms_ucode_free_buf(void *p)
1530{
1531 kfree(p);
1532}
1533
1534/*
1535 * checks validity of all firmware images loaded from user space
1536 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001537 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001538 * no locking is required.
1539 */
1540int brcms_check_firmwares(struct brcms_info *wl)
1541{
1542 int i;
1543 int entry;
1544 int rc = 0;
1545 const struct firmware *fw;
1546 const struct firmware *fw_hdr;
1547 struct firmware_hdr *ucode_hdr;
1548 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1549 fw = wl->fw.fw_bin[i];
1550 fw_hdr = wl->fw.fw_hdr[i];
1551 if (fw == NULL && fw_hdr == NULL) {
1552 break;
1553 } else if (fw == NULL || fw_hdr == NULL) {
1554 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1555 __func__);
1556 rc = -EBADF;
1557 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1558 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1559 "size %zu/%zu\n", __func__, fw_hdr->size,
1560 sizeof(struct firmware_hdr));
1561 rc = -EBADF;
1562 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
Seth Forsheeb353dda2012-11-15 08:08:03 -06001563 wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
1564 __func__, fw->size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001565 rc = -EBADF;
1566 } else {
1567 /* check if ucode section overruns firmware image */
1568 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1569 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1570 !rc; entry++, ucode_hdr++) {
1571 if (le32_to_cpu(ucode_hdr->offset) +
1572 le32_to_cpu(ucode_hdr->len) >
1573 fw->size) {
1574 wiphy_err(wl->wiphy,
1575 "%s: conflicting bin/hdr\n",
1576 __func__);
1577 rc = -EBADF;
1578 }
1579 }
1580 }
1581 }
1582 if (rc == 0 && wl->fw.fw_cnt != i) {
1583 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1584 wl->fw.fw_cnt);
1585 rc = -EBADF;
1586 }
1587 return rc;
1588}
1589
1590/*
1591 * precondition: perimeter lock has been acquired
1592 */
1593bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1594{
1595 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1596
1597 spin_unlock_bh(&wl->lock);
1598 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1599 if (blocked)
1600 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1601 spin_lock_bh(&wl->lock);
1602 return blocked;
1603}
1604
1605/*
1606 * precondition: perimeter lock has been acquired
1607 */
1608void brcms_msleep(struct brcms_info *wl, uint ms)
1609{
1610 spin_unlock_bh(&wl->lock);
1611 msleep(ms);
1612 spin_lock_bh(&wl->lock);
1613}