blob: 85dbaf8ac997c99fe538ac0a9b7f7b2fd1611393 [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
Piotr Haber8e21df22012-11-28 21:44:08 +0100849 if (wl->pub) {
850 brcms_debugfs_detach(wl->pub);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200851 brcms_c_module_unregister(wl->pub, "linux", wl);
Piotr Haber8e21df22012-11-28 21:44:08 +0100852 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200853
854 /* free common resources */
855 if (wl->wlc) {
856 brcms_c_detach(wl->wlc);
857 wl->wlc = NULL;
858 wl->pub = NULL;
859 }
860
861 /* virtual interface deletion is deferred so we cannot spinwait */
862
863 /* wait for all pending callbacks to complete */
864 while (atomic_read(&wl->callbacks) > 0)
865 schedule();
866
867 /* free timers */
868 for (t = wl->timers; t; t = next) {
869 next = t->next;
Joe Perches8ae74652012-01-15 00:38:38 -0800870#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +0200871 kfree(t->name);
872#endif
873 kfree(t);
874 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200875}
876
877/*
Roland Vossen2646c462011-10-21 16:16:27 +0200878* called from both kernel as from this kernel module (error flow on attach)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200879* precondition: perimeter lock is not acquired.
880*/
Arend van Spriel2e7565602011-12-08 15:06:46 -0800881static void brcms_remove(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200882{
Arend van Spriel2e7565602011-12-08 15:06:46 -0800883 struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
Roland Vossen2646c462011-10-21 16:16:27 +0200884 struct brcms_info *wl = hw->priv;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200885
Arend van Spriel5b435de2011-10-05 13:19:03 +0200886 if (wl->wlc) {
887 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
888 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
889 ieee80211_unregister_hw(hw);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200890 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200891
892 brcms_free(wl);
893
Arend van Spriel2e7565602011-12-08 15:06:46 -0800894 bcma_set_drvdata(pdev, NULL);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200895 ieee80211_free_hw(hw);
896}
897
898static irqreturn_t brcms_isr(int irq, void *dev_id)
899{
900 struct brcms_info *wl;
Piotr Haber94d99022012-11-28 21:44:06 +0100901 irqreturn_t ret = IRQ_NONE;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200902
903 wl = (struct brcms_info *) dev_id;
904
905 spin_lock(&wl->isr_lock);
906
907 /* call common first level interrupt handler */
Piotr Haber94d99022012-11-28 21:44:06 +0100908 if (brcms_c_isr(wl->wlc)) {
909 /* schedule second level handler */
910 tasklet_schedule(&wl->tasklet);
911 ret = IRQ_HANDLED;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200912 }
913
914 spin_unlock(&wl->isr_lock);
915
Piotr Haber94d99022012-11-28 21:44:06 +0100916 return ret;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200917}
918
919/*
920 * is called in brcms_pci_probe() context, therefore no locking required.
921 */
922static int ieee_hw_rate_init(struct ieee80211_hw *hw)
923{
924 struct brcms_info *wl = hw->priv;
925 struct brcms_c_info *wlc = wl->wlc;
926 struct ieee80211_supported_band *band;
927 int has_5g = 0;
928 u16 phy_type;
929
930 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
931 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
932
933 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
934 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
935 band = &wlc->bandstate[BAND_2G_INDEX]->band;
936 *band = brcms_band_2GHz_nphy_template;
937 if (phy_type == PHY_TYPE_LCN) {
938 /* Single stream */
939 band->ht_cap.mcs.rx_mask[1] = 0;
Arend van Sprieldf4492f2011-10-12 20:51:15 +0200940 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200941 }
942 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
943 } else {
944 return -EPERM;
945 }
946
947 /* Assume all bands use the same phy. True for 11n devices. */
948 if (wl->pub->_nbands > 1) {
949 has_5g++;
950 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
951 band = &wlc->bandstate[BAND_5G_INDEX]->band;
952 *band = brcms_band_5GHz_nphy_template;
953 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
954 } else {
955 return -EPERM;
956 }
957 }
958 return 0;
959}
960
961/*
962 * is called in brcms_pci_probe() context, therefore no locking required.
963 */
964static int ieee_hw_init(struct ieee80211_hw *hw)
965{
966 hw->flags = IEEE80211_HW_SIGNAL_DBM
967 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
968 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
969 | IEEE80211_HW_AMPDU_AGGREGATION;
970
971 hw->extra_tx_headroom = brcms_c_get_header_len();
972 hw->queues = N_TX_QUEUES;
973 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
974
975 /* channel change time is dependent on chip and band */
976 hw->channel_change_time = 7 * 1000;
977 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
978
979 hw->rate_control_algorithm = "minstrel_ht";
980
981 hw->sta_data_size = 0;
982 return ieee_hw_rate_init(hw);
983}
984
985/**
986 * attach to the WL device.
987 *
988 * Attach to the WL device identified by vendor and device parameters.
989 * regs is a host accessible memory address pointing to WL device registers.
990 *
991 * brcms_attach is not defined as static because in the case where no bus
992 * is defined, wl_attach will never be called, and thus, gcc will issue
993 * a warning that this function is defined but not used if we declare
994 * it as static.
995 *
996 *
Arend van Spriel2e7565602011-12-08 15:06:46 -0800997 * is called in brcms_bcma_probe() context, therefore no locking required.
Arend van Spriel5b435de2011-10-05 13:19:03 +0200998 */
Arend van Spriel2e7565602011-12-08 15:06:46 -0800999static struct brcms_info *brcms_attach(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001000{
1001 struct brcms_info *wl = NULL;
1002 int unit, err;
1003 struct ieee80211_hw *hw;
1004 u8 perm[ETH_ALEN];
1005
1006 unit = n_adapters_found;
1007 err = 0;
1008
1009 if (unit < 0)
1010 return NULL;
1011
1012 /* allocate private info */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001013 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001014 if (hw != NULL)
1015 wl = hw->priv;
1016 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1017 return NULL;
1018 wl->wiphy = hw->wiphy;
1019
1020 atomic_set(&wl->callbacks, 0);
1021
1022 /* setup the bottom half handler */
1023 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1024
Arend van Spriel5b435de2011-10-05 13:19:03 +02001025 spin_lock_init(&wl->lock);
1026 spin_lock_init(&wl->isr_lock);
1027
1028 /* prepare ucode */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001029 if (brcms_request_fw(wl, pdev) < 0) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001030 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
1031 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
1032 brcms_release_fw(wl);
Arend van Spriel2e7565602011-12-08 15:06:46 -08001033 brcms_remove(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001034 return NULL;
1035 }
1036
1037 /* common load-time initialization */
Arend van Sprielb63337a2011-12-08 15:06:47 -08001038 wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001039 brcms_release_fw(wl);
1040 if (!wl->wlc) {
1041 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1042 KBUILD_MODNAME, err);
1043 goto fail;
1044 }
1045 wl->pub = brcms_c_pub(wl->wlc);
1046
1047 wl->pub->ieee_hw = hw;
1048
Arend van Spriel5b435de2011-10-05 13:19:03 +02001049 /* register our interrupt handler */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001050 if (request_irq(pdev->irq, brcms_isr,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001051 IRQF_SHARED, KBUILD_MODNAME, wl)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001052 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1053 goto fail;
1054 }
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001055 wl->irq = pdev->irq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001056
1057 /* register module */
1058 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1059
1060 if (ieee_hw_init(hw)) {
1061 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1062 __func__);
1063 goto fail;
1064 }
1065
Seth Forsheecf03c5d2012-06-16 07:47:52 -05001066 brcms_c_regd_init(wl->wlc);
1067
Arend van Spriel5b435de2011-10-05 13:19:03 +02001068 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1069 if (WARN_ON(!is_valid_ether_addr(perm)))
1070 goto fail;
1071 SET_IEEE80211_PERM_ADDR(hw, perm);
1072
1073 err = ieee80211_register_hw(hw);
1074 if (err)
1075 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1076 "%d\n", __func__, err);
1077
Arend van Sprield597ee72012-06-09 22:51:41 +02001078 if (wl->pub->srom_ccode[0] &&
1079 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1080 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001081
Piotr Haber8e21df22012-11-28 21:44:08 +01001082 brcms_debugfs_attach(wl->pub);
1083 brcms_debugfs_create_files(wl->pub);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001084 n_adapters_found++;
1085 return wl;
1086
1087fail:
1088 brcms_free(wl);
1089 return NULL;
1090}
1091
1092
1093
1094/**
1095 * determines if a device is a WL device, and if so, attaches it.
1096 *
1097 * This function determines if a device pointed to by pdev is a WL device,
1098 * and if so, performs a brcms_attach() on it.
1099 *
1100 * Perimeter lock is initialized in the course of this function.
1101 */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001102static int __devinit brcms_bcma_probe(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001103{
Arend van Spriel5b435de2011-10-05 13:19:03 +02001104 struct brcms_info *wl;
1105 struct ieee80211_hw *hw;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001106
Arend van Spriel2e7565602011-12-08 15:06:46 -08001107 dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
1108 pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001109 pdev->irq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001110
Arend van Spriel2e7565602011-12-08 15:06:46 -08001111 if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
1112 (pdev->id.id != BCMA_CORE_80211))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001113 return -ENODEV;
1114
Arend van Spriel5b435de2011-10-05 13:19:03 +02001115 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1116 if (!hw) {
1117 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1118 return -ENOMEM;
1119 }
1120
1121 SET_IEEE80211_DEV(hw, &pdev->dev);
1122
Arend van Spriel2e7565602011-12-08 15:06:46 -08001123 bcma_set_drvdata(pdev, hw);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001124
1125 memset(hw->priv, 0, sizeof(*wl));
1126
Arend van Spriel2e7565602011-12-08 15:06:46 -08001127 wl = brcms_attach(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001128 if (!wl) {
Joe Perches02f77192012-01-15 00:38:44 -08001129 pr_err("%s: brcms_attach failed!\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001130 return -ENODEV;
1131 }
1132 return 0;
1133}
1134
Linus Torvalds7d5869e2012-01-13 23:58:41 +01001135static int brcms_suspend(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001136{
1137 struct brcms_info *wl;
1138 struct ieee80211_hw *hw;
1139
Arend van Spriel2e7565602011-12-08 15:06:46 -08001140 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001141 wl = hw->priv;
1142 if (!wl) {
Arend van Spriel137dabe2012-02-09 21:08:59 +01001143 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
1144 __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001145 return -ENODEV;
1146 }
1147
1148 /* only need to flag hw is down for proper resume */
1149 spin_lock_bh(&wl->lock);
1150 wl->pub->hw_up = false;
1151 spin_unlock_bh(&wl->lock);
1152
Seth Forsheeb353dda2012-11-15 08:08:03 -06001153 brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001154
Arend van Spriel2e7565602011-12-08 15:06:46 -08001155 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001156}
1157
Arend van Spriel2e7565602011-12-08 15:06:46 -08001158static int brcms_resume(struct bcma_device *pdev)
1159{
Linus Torvalds7e9e7fa2012-01-13 23:58:42 +01001160 return 0;
Arend van Spriel2e7565602011-12-08 15:06:46 -08001161}
1162
1163static struct bcma_driver brcms_bcma_driver = {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001164 .name = KBUILD_MODNAME,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001165 .probe = brcms_bcma_probe,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001166 .suspend = brcms_suspend,
1167 .resume = brcms_resume,
1168 .remove = __devexit_p(brcms_remove),
Arend van Spriel2e7565602011-12-08 15:06:46 -08001169 .id_table = brcms_coreid_table,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001170};
1171
1172/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001173 * This is the main entry point for the brcmsmac driver.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001174 *
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001175 * This function is scheduled upon module initialization and
1176 * does the driver registration, which result in brcms_bcma_probe()
1177 * call resulting in the driver bringup.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001178 */
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001179static void brcms_driver_init(struct work_struct *work)
1180{
1181 int error;
1182
1183 error = bcma_driver_register(&brcms_bcma_driver);
1184 if (error)
1185 pr_err("%s: register returned %d\n", __func__, error);
1186}
1187
1188static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
1189
Arend van Spriel5b435de2011-10-05 13:19:03 +02001190static int __init brcms_module_init(void)
1191{
Piotr Haber8e21df22012-11-28 21:44:08 +01001192 brcms_debugfs_init();
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);
Piotr Haber8e21df22012-11-28 21:44:08 +01001210 brcms_debugfs_exit();
Arend van Spriel5b435de2011-10-05 13:19:03 +02001211}
1212
1213module_init(brcms_module_init);
1214module_exit(brcms_module_exit);
1215
1216/*
1217 * precondition: perimeter lock has been acquired
1218 */
1219void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1220 bool state, int prio)
1221{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001222 brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001223}
1224
1225/*
1226 * precondition: perimeter lock has been acquired
1227 */
1228void brcms_init(struct brcms_info *wl)
1229{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001230 brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
1231 wl->pub->unit);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001232 brcms_reset(wl);
Roland Vossendc460122011-10-21 16:16:28 +02001233 brcms_c_init(wl->wlc, wl->mute_tx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001234}
1235
1236/*
1237 * precondition: perimeter lock has been acquired
1238 */
1239uint brcms_reset(struct brcms_info *wl)
1240{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001241 brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001242 brcms_c_reset(wl->wlc);
1243
1244 /* dpc will not be rescheduled */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001245 wl->resched = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001246
Vladimir Zapolskiyea2d2182012-08-05 00:29:07 +03001247 /* inform publicly that interface is down */
1248 wl->pub->up = false;
1249
Arend van Spriel5b435de2011-10-05 13:19:03 +02001250 return 0;
1251}
1252
Roland Vossenc261bdf2011-10-18 14:03:04 +02001253void brcms_fatal_error(struct brcms_info *wl)
1254{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001255 brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
Roland Vossenc261bdf2011-10-18 14:03:04 +02001256 wl->wlc->pub->unit);
1257 brcms_reset(wl);
1258 ieee80211_restart_hw(wl->pub->ieee_hw);
1259}
1260
Arend van Spriel5b435de2011-10-05 13:19:03 +02001261/*
1262 * These are interrupt on/off entry points. Disable interrupts
1263 * during interrupt state transition.
1264 */
1265void brcms_intrson(struct brcms_info *wl)
1266{
1267 unsigned long flags;
1268
1269 spin_lock_irqsave(&wl->isr_lock, flags);
1270 brcms_c_intrson(wl->wlc);
1271 spin_unlock_irqrestore(&wl->isr_lock, flags);
1272}
1273
1274u32 brcms_intrsoff(struct brcms_info *wl)
1275{
1276 unsigned long flags;
1277 u32 status;
1278
1279 spin_lock_irqsave(&wl->isr_lock, flags);
1280 status = brcms_c_intrsoff(wl->wlc);
1281 spin_unlock_irqrestore(&wl->isr_lock, flags);
1282 return status;
1283}
1284
1285void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1286{
1287 unsigned long flags;
1288
1289 spin_lock_irqsave(&wl->isr_lock, flags);
1290 brcms_c_intrsrestore(wl->wlc, macintmask);
1291 spin_unlock_irqrestore(&wl->isr_lock, flags);
1292}
1293
1294/*
1295 * precondition: perimeter lock has been acquired
1296 */
1297int brcms_up(struct brcms_info *wl)
1298{
1299 int error = 0;
1300
1301 if (wl->pub->up)
1302 return 0;
1303
1304 error = brcms_c_up(wl->wlc);
1305
1306 return error;
1307}
1308
1309/*
1310 * precondition: perimeter lock has been acquired
1311 */
1312void brcms_down(struct brcms_info *wl)
1313{
1314 uint callbacks, ret_val = 0;
1315
1316 /* call common down function */
1317 ret_val = brcms_c_down(wl->wlc);
1318 callbacks = atomic_read(&wl->callbacks) - ret_val;
1319
1320 /* wait for down callbacks to complete */
1321 spin_unlock_bh(&wl->lock);
1322
1323 /* For HIGH_only driver, it's important to actually schedule other work,
1324 * not just spin wait since everything runs at schedule level
1325 */
1326 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1327
1328 spin_lock_bh(&wl->lock);
1329}
1330
1331/*
1332* precondition: perimeter lock is not acquired
1333 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001334static void _brcms_timer(struct work_struct *work)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001335{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001336 struct brcms_timer *t = container_of(work, struct brcms_timer,
1337 dly_wrk.work);
1338
Arend van Spriel5b435de2011-10-05 13:19:03 +02001339 spin_lock_bh(&t->wl->lock);
1340
1341 if (t->set) {
1342 if (t->periodic) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001343 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001344 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1345 &t->dly_wrk,
1346 msecs_to_jiffies(t->ms));
1347 } else {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001348 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001349 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001350
1351 t->fn(t->arg);
1352 }
1353
1354 atomic_dec(&t->wl->callbacks);
1355
1356 spin_unlock_bh(&t->wl->lock);
1357}
1358
1359/*
Arend van Spriel5b435de2011-10-05 13:19:03 +02001360 * Adds a timer to the list. Caller supplies a timer function.
1361 * Is called from wlc.
1362 *
1363 * precondition: perimeter lock has been acquired
1364 */
1365struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1366 void (*fn) (void *arg),
1367 void *arg, const char *name)
1368{
1369 struct brcms_timer *t;
1370
1371 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1372 if (!t)
1373 return NULL;
1374
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001375 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001376 t->wl = wl;
1377 t->fn = fn;
1378 t->arg = arg;
1379 t->next = wl->timers;
1380 wl->timers = t;
1381
Joe Perches8ae74652012-01-15 00:38:38 -08001382#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001383 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1384 if (t->name)
1385 strcpy(t->name, name);
1386#endif
1387
1388 return t;
1389}
1390
1391/*
1392 * adds only the kernel timer since it's going to be more accurate
1393 * as well as it's easier to make it periodic
1394 *
1395 * precondition: perimeter lock has been acquired
1396 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001397void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001398{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001399 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1400
Joe Perches8ae74652012-01-15 00:38:38 -08001401#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001402 if (t->set)
Seth Forsheeb353dda2012-11-15 08:08:03 -06001403 brcms_dbg_info(t->wl->wlc->hw->d11core,
1404 "%s: Already set. Name: %s, per %d\n",
1405 __func__, t->name, periodic);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001406#endif
1407 t->ms = ms;
1408 t->periodic = (bool) periodic;
1409 t->set = true;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001410
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001411 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001412
1413 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001414}
1415
1416/*
1417 * return true if timer successfully deleted, false if still pending
1418 *
1419 * precondition: perimeter lock has been acquired
1420 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001421bool brcms_del_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001422{
1423 if (t->set) {
1424 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001425 if (!cancel_delayed_work(&t->dly_wrk))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001426 return false;
1427
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001428 atomic_dec(&t->wl->callbacks);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001429 }
1430
1431 return true;
1432}
1433
1434/*
1435 * precondition: perimeter lock has been acquired
1436 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001437void brcms_free_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001438{
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001439 struct brcms_info *wl = t->wl;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001440 struct brcms_timer *tmp;
1441
1442 /* delete the timer in case it is active */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001443 brcms_del_timer(t);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001444
1445 if (wl->timers == t) {
1446 wl->timers = wl->timers->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001447#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001448 kfree(t->name);
1449#endif
1450 kfree(t);
1451 return;
1452
1453 }
1454
1455 tmp = wl->timers;
1456 while (tmp) {
1457 if (tmp->next == t) {
1458 tmp->next = t->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001459#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001460 kfree(t->name);
1461#endif
1462 kfree(t);
1463 return;
1464 }
1465 tmp = tmp->next;
1466 }
1467
1468}
1469
1470/*
1471 * precondition: perimeter lock has been acquired
1472 */
1473int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1474{
1475 int i, entry;
1476 const u8 *pdata;
1477 struct firmware_hdr *hdr;
1478 for (i = 0; i < wl->fw.fw_cnt; i++) {
1479 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1480 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1481 entry++, hdr++) {
1482 u32 len = le32_to_cpu(hdr->len);
1483 if (le32_to_cpu(hdr->idx) == idx) {
1484 pdata = wl->fw.fw_bin[i]->data +
1485 le32_to_cpu(hdr->offset);
Thomas Meyer1f1d52892011-11-17 23:43:40 +01001486 *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001487 if (*pbuf == NULL)
1488 goto fail;
1489
Arend van Spriel5b435de2011-10-05 13:19:03 +02001490 return 0;
1491 }
1492 }
1493 }
Seth Forsheeb353dda2012-11-15 08:08:03 -06001494 brcms_err(wl->wlc->hw->d11core,
1495 "ERROR: ucode buf tag:%d can not be found!\n", idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001496 *pbuf = NULL;
1497fail:
1498 return -ENODATA;
1499}
1500
1501/*
Arend van Spriel2e7565602011-12-08 15:06:46 -08001502 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001503 * no locking is required.
1504 */
1505int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1506{
1507 int i, entry;
1508 const u8 *pdata;
1509 struct firmware_hdr *hdr;
1510 for (i = 0; i < wl->fw.fw_cnt; i++) {
1511 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1512 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1513 entry++, hdr++) {
1514 if (le32_to_cpu(hdr->idx) == idx) {
1515 pdata = wl->fw.fw_bin[i]->data +
1516 le32_to_cpu(hdr->offset);
1517 if (le32_to_cpu(hdr->len) != 4) {
Seth Forsheeb353dda2012-11-15 08:08:03 -06001518 brcms_err(wl->wlc->hw->d11core,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001519 "ERROR: fw hdr len\n");
1520 return -ENOMSG;
1521 }
1522 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1523 return 0;
1524 }
1525 }
1526 }
Seth Forsheeb353dda2012-11-15 08:08:03 -06001527 brcms_err(wl->wlc->hw->d11core,
1528 "ERROR: ucode tag:%d can not be found!\n", idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001529 return -ENOMSG;
1530}
1531
1532/*
1533 * precondition: can both be called locked and unlocked
1534 */
1535void brcms_ucode_free_buf(void *p)
1536{
1537 kfree(p);
1538}
1539
1540/*
1541 * checks validity of all firmware images loaded from user space
1542 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001543 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001544 * no locking is required.
1545 */
1546int brcms_check_firmwares(struct brcms_info *wl)
1547{
1548 int i;
1549 int entry;
1550 int rc = 0;
1551 const struct firmware *fw;
1552 const struct firmware *fw_hdr;
1553 struct firmware_hdr *ucode_hdr;
1554 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1555 fw = wl->fw.fw_bin[i];
1556 fw_hdr = wl->fw.fw_hdr[i];
1557 if (fw == NULL && fw_hdr == NULL) {
1558 break;
1559 } else if (fw == NULL || fw_hdr == NULL) {
1560 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1561 __func__);
1562 rc = -EBADF;
1563 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1564 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1565 "size %zu/%zu\n", __func__, fw_hdr->size,
1566 sizeof(struct firmware_hdr));
1567 rc = -EBADF;
1568 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
Seth Forsheeb353dda2012-11-15 08:08:03 -06001569 wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
1570 __func__, fw->size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001571 rc = -EBADF;
1572 } else {
1573 /* check if ucode section overruns firmware image */
1574 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1575 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1576 !rc; entry++, ucode_hdr++) {
1577 if (le32_to_cpu(ucode_hdr->offset) +
1578 le32_to_cpu(ucode_hdr->len) >
1579 fw->size) {
1580 wiphy_err(wl->wiphy,
1581 "%s: conflicting bin/hdr\n",
1582 __func__);
1583 rc = -EBADF;
1584 }
1585 }
1586 }
1587 }
1588 if (rc == 0 && wl->fw.fw_cnt != i) {
1589 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1590 wl->fw.fw_cnt);
1591 rc = -EBADF;
1592 }
1593 return rc;
1594}
1595
1596/*
1597 * precondition: perimeter lock has been acquired
1598 */
1599bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1600{
1601 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1602
1603 spin_unlock_bh(&wl->lock);
1604 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1605 if (blocked)
1606 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1607 spin_lock_bh(&wl->lock);
1608 return blocked;
1609}
1610
1611/*
1612 * precondition: perimeter lock has been acquired
1613 */
1614void brcms_msleep(struct brcms_info *wl, uint ms)
1615{
1616 spin_unlock_bh(&wl->lock);
1617 msleep(ms);
1618 spin_lock_bh(&wl->lock);
1619}