blob: 3a6544710c8ab222cc126ef53d5f19143498cc9e [file] [log] [blame]
Arend van Spriel5b435de2011-10-05 13:19:03 +02001/*
2 * Copyright (c) 2010 Broadcom Corporation
Hauke Mehrtensaf44e252013-03-24 01:45:58 +01003 * Copyright (c) 2013 Hauke Mehrtens <hauke@hauke-m.de>
Arend van Spriel5b435de2011-10-05 13:19:03 +02004 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#define __UNDEF_NO_VERSION__
Joe Perches02f77192012-01-15 00:38:44 -080019#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Arend van Spriel5b435de2011-10-05 13:19:03 +020020
21#include <linux/etherdevice.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020022#include <linux/sched.h>
23#include <linux/firmware.h>
24#include <linux/interrupt.h>
Paul Gortmaker45296232011-08-30 17:50:46 -040025#include <linux/module.h>
Arend van Spriel2e7565602011-12-08 15:06:46 -080026#include <linux/bcma/bcma.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020027#include <net/mac80211.h>
28#include <defs.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020029#include "phy/phy_int.h"
30#include "d11.h"
31#include "channel.h"
32#include "scb.h"
33#include "pub.h"
34#include "ucode_loader.h"
35#include "mac80211_if.h"
36#include "main.h"
Seth Forsheeb353dda2012-11-15 08:08:03 -060037#include "debug.h"
Piotr Habercd864522013-03-03 12:45:20 +010038#include "led.h"
Arend van Spriel5b435de2011-10-05 13:19:03 +020039
40#define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
Arend van Spriel7b2385b2013-02-02 14:36:50 +010041#define BRCMS_FLUSH_TIMEOUT 500 /* msec */
Arend van Spriel5b435de2011-10-05 13:19:03 +020042
43/* Flags we support */
44#define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
45 FIF_ALLMULTI | \
46 FIF_FCSFAIL | \
Arend van Spriel5b435de2011-10-05 13:19:03 +020047 FIF_CONTROL | \
48 FIF_OTHER_BSS | \
Alwin Beukersbe667662011-11-22 17:21:43 -080049 FIF_BCN_PRBRESP_PROMISC | \
50 FIF_PSPOLL)
Arend van Spriel5b435de2011-10-05 13:19:03 +020051
52#define CHAN2GHZ(channel, freqency, chflags) { \
53 .band = IEEE80211_BAND_2GHZ, \
54 .center_freq = (freqency), \
55 .hw_value = (channel), \
56 .flags = chflags, \
57 .max_antenna_gain = 0, \
58 .max_power = 19, \
59}
60
61#define CHAN5GHZ(channel, chflags) { \
62 .band = IEEE80211_BAND_5GHZ, \
63 .center_freq = 5000 + 5*(channel), \
64 .hw_value = (channel), \
65 .flags = chflags, \
66 .max_antenna_gain = 0, \
67 .max_power = 21, \
68}
69
70#define RATE(rate100m, _flags) { \
71 .bitrate = (rate100m), \
72 .flags = (_flags), \
73 .hw_value = (rate100m / 5), \
74}
75
76struct firmware_hdr {
77 __le32 offset;
78 __le32 len;
79 __le32 idx;
80};
81
82static const char * const brcms_firmwares[MAX_FW_IMAGES] = {
83 "brcm/bcm43xx",
84 NULL
85};
86
87static int n_adapters_found;
88
89MODULE_AUTHOR("Broadcom Corporation");
90MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
91MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
92MODULE_LICENSE("Dual BSD/GPL");
Jeff Mahoneyfaa97bd4a2012-08-06 15:17:26 -040093/* This needs to be adjusted when brcms_firmwares changes */
94MODULE_FIRMWARE("brcm/bcm43xx-0.fw");
95MODULE_FIRMWARE("brcm/bcm43xx_hdr-0.fw");
Arend van Spriel5b435de2011-10-05 13:19:03 +020096
Arend van Spriel2e7565602011-12-08 15:06:46 -080097/* recognized BCMA Core IDs */
98static struct bcma_device_id brcms_coreid_table[] = {
Hauke Mehrtens6f80f012012-12-07 00:35:53 +010099 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 17, BCMA_ANY_CLASS),
Arend van Sprieleb032f02011-12-12 15:15:12 -0800100 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 23, BCMA_ANY_CLASS),
101 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 24, BCMA_ANY_CLASS),
Arend van Spriel2e7565602011-12-08 15:06:46 -0800102 BCMA_CORETABLE_END
103};
104MODULE_DEVICE_TABLE(bcma, brcms_coreid_table);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200105
Seth Forsheeb0341742012-11-15 08:08:01 -0600106#if defined(CONFIG_BRCMDBG)
107/*
108 * Module parameter for setting the debug message level. Available
109 * flags are specified by the BRCM_DL_* macros in
110 * drivers/net/wireless/brcm80211/include/defs.h.
111 */
112module_param_named(debug, brcm_msg_level, uint, S_IRUGO | S_IWUSR);
113#endif
Arend van Spriel5b435de2011-10-05 13:19:03 +0200114
115static struct ieee80211_channel brcms_2ghz_chantable[] = {
116 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
117 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
118 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
119 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
120 CHAN2GHZ(5, 2432, 0),
121 CHAN2GHZ(6, 2437, 0),
122 CHAN2GHZ(7, 2442, 0),
123 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
124 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
125 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
126 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
127 CHAN2GHZ(12, 2467,
128 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
129 IEEE80211_CHAN_NO_HT40PLUS),
130 CHAN2GHZ(13, 2472,
131 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
132 IEEE80211_CHAN_NO_HT40PLUS),
133 CHAN2GHZ(14, 2484,
134 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
Seth Forshee7f38e5b2012-08-01 15:58:43 -0500135 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS |
136 IEEE80211_CHAN_NO_OFDM)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200137};
138
139static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
140 /* UNII-1 */
141 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
142 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
143 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
144 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
145 /* UNII-2 */
146 CHAN5GHZ(52,
147 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
148 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
149 CHAN5GHZ(56,
150 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
151 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
152 CHAN5GHZ(60,
153 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
154 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
155 CHAN5GHZ(64,
156 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
157 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
158 /* MID */
159 CHAN5GHZ(100,
160 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
161 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
162 CHAN5GHZ(104,
163 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
164 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
165 CHAN5GHZ(108,
166 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
167 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
168 CHAN5GHZ(112,
169 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
170 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
171 CHAN5GHZ(116,
172 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
173 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
174 CHAN5GHZ(120,
175 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
176 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
177 CHAN5GHZ(124,
178 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
179 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
180 CHAN5GHZ(128,
181 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
182 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
183 CHAN5GHZ(132,
184 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
185 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
186 CHAN5GHZ(136,
187 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
188 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
189 CHAN5GHZ(140,
190 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
191 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
192 IEEE80211_CHAN_NO_HT40MINUS),
193 /* UNII-3 */
194 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
195 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
196 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
197 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
198 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
199};
200
201/*
202 * The rate table is used for both 2.4G and 5G rates. The
203 * latter being a subset as it does not support CCK rates.
204 */
205static struct ieee80211_rate legacy_ratetable[] = {
206 RATE(10, 0),
207 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
208 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
209 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
210 RATE(60, 0),
211 RATE(90, 0),
212 RATE(120, 0),
213 RATE(180, 0),
214 RATE(240, 0),
215 RATE(360, 0),
216 RATE(480, 0),
217 RATE(540, 0),
218};
219
220static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template = {
221 .band = IEEE80211_BAND_2GHZ,
222 .channels = brcms_2ghz_chantable,
223 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
224 .bitrates = legacy_ratetable,
225 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
226 .ht_cap = {
227 /* from include/linux/ieee80211.h */
228 .cap = IEEE80211_HT_CAP_GRN_FLD |
Arend van Spriel6b1a89a2011-10-18 14:02:59 +0200229 IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200230 .ht_supported = true,
231 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
232 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
233 .mcs = {
234 /* placeholders for now */
235 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
236 .rx_highest = cpu_to_le16(500),
237 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
238 }
239};
240
241static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template = {
242 .band = IEEE80211_BAND_5GHZ,
243 .channels = brcms_5ghz_nphy_chantable,
244 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
245 .bitrates = legacy_ratetable + BRCMS_LEGACY_5G_RATE_OFFSET,
246 .n_bitrates = ARRAY_SIZE(legacy_ratetable) -
247 BRCMS_LEGACY_5G_RATE_OFFSET,
248 .ht_cap = {
249 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
Arend van Spriel6b1a89a2011-10-18 14:02:59 +0200250 IEEE80211_HT_CAP_SGI_40,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200251 .ht_supported = true,
252 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
253 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
254 .mcs = {
255 /* placeholders for now */
256 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
257 .rx_highest = cpu_to_le16(500),
258 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
259 }
260};
261
262/* flags the given rate in rateset as requested */
263static void brcms_set_basic_rate(struct brcm_rateset *rs, u16 rate, bool is_br)
264{
265 u32 i;
266
267 for (i = 0; i < rs->count; i++) {
268 if (rate != (rs->rates[i] & 0x7f))
269 continue;
270
271 if (is_br)
272 rs->rates[i] |= BRCMS_RATE_FLAG;
273 else
274 rs->rates[i] &= BRCMS_RATE_MASK;
275 return;
276 }
277}
278
Arend van Spriel25b56322013-04-04 12:10:10 +0200279/**
280 * This function frees the WL per-device resources.
281 *
282 * This function frees resources owned by the WL device pointed to
283 * by the wl parameter.
284 *
285 * precondition: can both be called locked and unlocked
286 *
287 */
288static void brcms_free(struct brcms_info *wl)
289{
290 struct brcms_timer *t, *next;
291
292 /* free ucode data */
293 if (wl->fw.fw_cnt)
294 brcms_ucode_data_free(&wl->ucode);
295 if (wl->irq)
296 free_irq(wl->irq, wl);
297
298 /* kill dpc */
299 tasklet_kill(&wl->tasklet);
300
301 if (wl->pub) {
302 brcms_debugfs_detach(wl->pub);
303 brcms_c_module_unregister(wl->pub, "linux", wl);
304 }
305
306 /* free common resources */
307 if (wl->wlc) {
308 brcms_c_detach(wl->wlc);
309 wl->wlc = NULL;
310 wl->pub = NULL;
311 }
312
313 /* virtual interface deletion is deferred so we cannot spinwait */
314
315 /* wait for all pending callbacks to complete */
316 while (atomic_read(&wl->callbacks) > 0)
317 schedule();
318
319 /* free timers */
320 for (t = wl->timers; t; t = next) {
321 next = t->next;
322#ifdef DEBUG
323 kfree(t->name);
324#endif
325 kfree(t);
326 }
327}
328
329/*
330* called from both kernel as from this kernel module (error flow on attach)
331* precondition: perimeter lock is not acquired.
332*/
333static void brcms_remove(struct bcma_device *pdev)
334{
335 struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
336 struct brcms_info *wl = hw->priv;
337
338 if (wl->wlc) {
Piotr Haberd1497f22013-04-25 12:27:09 +0200339 brcms_led_unregister(wl);
Arend van Spriel25b56322013-04-04 12:10:10 +0200340 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
341 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
342 ieee80211_unregister_hw(hw);
343 }
344
345 brcms_free(wl);
346
347 bcma_set_drvdata(pdev, NULL);
348 ieee80211_free_hw(hw);
349}
350
351/*
352 * Precondition: Since this function is called in brcms_pci_probe() context,
353 * no locking is required.
354 */
355static void brcms_release_fw(struct brcms_info *wl)
356{
357 int i;
358 for (i = 0; i < MAX_FW_IMAGES; i++) {
359 release_firmware(wl->fw.fw_bin[i]);
360 release_firmware(wl->fw.fw_hdr[i]);
361 }
362}
363
364/*
365 * Precondition: Since this function is called in brcms_pci_probe() context,
366 * no locking is required.
367 */
368static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
369{
370 int status;
371 struct device *device = &pdev->dev;
372 char fw_name[100];
373 int i;
374
375 memset(&wl->fw, 0, sizeof(struct brcms_firmware));
376 for (i = 0; i < MAX_FW_IMAGES; i++) {
377 if (brcms_firmwares[i] == NULL)
378 break;
379 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
380 UCODE_LOADER_API_VER);
381 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
382 if (status) {
383 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
384 KBUILD_MODNAME, fw_name);
385 return status;
386 }
387 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
388 UCODE_LOADER_API_VER);
389 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
390 if (status) {
391 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
392 KBUILD_MODNAME, fw_name);
393 return status;
394 }
395 wl->fw.hdr_num_entries[i] =
396 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
397 }
398 wl->fw.fw_cnt = i;
399 status = brcms_ucode_data_init(wl, &wl->ucode);
400 brcms_release_fw(wl);
401 return status;
402}
403
Thomas Huehn36323f82012-07-23 21:33:42 +0200404static void brcms_ops_tx(struct ieee80211_hw *hw,
405 struct ieee80211_tx_control *control,
406 struct sk_buff *skb)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200407{
408 struct brcms_info *wl = hw->priv;
Thomas Huehn644e8c02012-07-10 14:01:37 +0200409 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200410
411 spin_lock_bh(&wl->lock);
412 if (!wl->pub->up) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600413 brcms_err(wl->wlc->hw->d11core, "ops->tx called while down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200414 kfree_skb(skb);
415 goto done;
416 }
Piotr Haberc4dea352012-11-28 21:44:05 +0100417 if (brcms_c_sendpkt_mac80211(wl->wlc, skb, hw))
418 tx_info->rate_driver_data[0] = control->sta;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200419 done:
420 spin_unlock_bh(&wl->lock);
421}
422
423static int brcms_ops_start(struct ieee80211_hw *hw)
424{
425 struct brcms_info *wl = hw->priv;
426 bool blocked;
Roland Vossen2646c462011-10-21 16:16:27 +0200427 int err;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200428
429 ieee80211_wake_queues(hw);
430 spin_lock_bh(&wl->lock);
431 blocked = brcms_rfkill_set_hw_state(wl);
432 spin_unlock_bh(&wl->lock);
433 if (!blocked)
434 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
435
Arend van Spriel25b56322013-04-04 12:10:10 +0200436 if (!wl->ucode.bcm43xx_bomminor) {
437 err = brcms_request_fw(wl, wl->wlc->hw->d11core);
438 if (err) {
439 brcms_remove(wl->wlc->hw->d11core);
440 return -ENOENT;
441 }
442 }
443
Roland Vossen2646c462011-10-21 16:16:27 +0200444 spin_lock_bh(&wl->lock);
Roland Vossendc460122011-10-21 16:16:28 +0200445 /* avoid acknowledging frames before a non-monitor device is added */
446 wl->mute_tx = true;
447
Roland Vossen2646c462011-10-21 16:16:27 +0200448 if (!wl->pub->up)
Piotr Haber82d8eba2012-09-19 22:21:15 +0200449 if (!blocked)
450 err = brcms_up(wl);
451 else
452 err = -ERFKILL;
Roland Vossen2646c462011-10-21 16:16:27 +0200453 else
454 err = -ENODEV;
455 spin_unlock_bh(&wl->lock);
456
457 if (err != 0)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600458 brcms_err(wl->wlc->hw->d11core, "%s: brcms_up() returned %d\n",
459 __func__, err);
Roland Vossen2646c462011-10-21 16:16:27 +0200460 return err;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200461}
462
463static void brcms_ops_stop(struct ieee80211_hw *hw)
464{
Roland Vossen2646c462011-10-21 16:16:27 +0200465 struct brcms_info *wl = hw->priv;
466 int status;
467
Arend van Spriel5b435de2011-10-05 13:19:03 +0200468 ieee80211_stop_queues(hw);
Roland Vossen2646c462011-10-21 16:16:27 +0200469
470 if (wl->wlc == NULL)
471 return;
472
473 spin_lock_bh(&wl->lock);
Hauke Mehrtenscacaa642012-06-30 15:16:19 +0200474 status = brcms_c_chipmatch(wl->wlc->hw->d11core);
Roland Vossen2646c462011-10-21 16:16:27 +0200475 spin_unlock_bh(&wl->lock);
476 if (!status) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600477 brcms_err(wl->wlc->hw->d11core,
Roland Vossen2646c462011-10-21 16:16:27 +0200478 "wl: brcms_ops_stop: chipmatch failed\n");
479 return;
480 }
481
482 /* put driver in down state */
483 spin_lock_bh(&wl->lock);
484 brcms_down(wl);
485 spin_unlock_bh(&wl->lock);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200486}
487
488static int
489brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
490{
Roland Vossendc460122011-10-21 16:16:28 +0200491 struct brcms_info *wl = hw->priv;
492
Hauke Mehrtensc55b3762013-03-24 01:46:03 +0100493 /* Just STA, AP and ADHOC for now */
Hauke Mehrtens492b71e2013-03-24 01:46:02 +0100494 if (vif->type != NL80211_IFTYPE_STATION &&
Hauke Mehrtensc55b3762013-03-24 01:46:03 +0100495 vif->type != NL80211_IFTYPE_AP &&
496 vif->type != NL80211_IFTYPE_ADHOC) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600497 brcms_err(wl->wlc->hw->d11core,
Hauke Mehrtensc55b3762013-03-24 01:46:03 +0100498 "%s: Attempt to add type %d, only STA, AP and AdHoc for now\n",
Seth Forsheeb353dda2012-11-15 08:08:03 -0600499 __func__, vif->type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200500 return -EOPNOTSUPP;
501 }
502
Arend van Spriel66578c02013-01-02 15:22:35 +0100503 spin_lock_bh(&wl->lock);
Roland Vossendc460122011-10-21 16:16:28 +0200504 wl->mute_tx = false;
505 brcms_c_mute(wl->wlc, false);
Hauke Mehrtens70268ce2013-03-24 01:45:50 +0100506 if (vif->type == NL80211_IFTYPE_STATION)
507 brcms_c_start_station(wl->wlc, vif->addr);
Hauke Mehrtens492b71e2013-03-24 01:46:02 +0100508 else if (vif->type == NL80211_IFTYPE_AP)
509 brcms_c_start_ap(wl->wlc, vif->addr, vif->bss_conf.bssid,
510 vif->bss_conf.ssid, vif->bss_conf.ssid_len);
Hauke Mehrtensc55b3762013-03-24 01:46:03 +0100511 else if (vif->type == NL80211_IFTYPE_ADHOC)
512 brcms_c_start_adhoc(wl->wlc, vif->addr);
Arend van Spriel66578c02013-01-02 15:22:35 +0100513 spin_unlock_bh(&wl->lock);
Roland Vossendc460122011-10-21 16:16:28 +0200514
Roland Vossen2646c462011-10-21 16:16:27 +0200515 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200516}
517
518static void
519brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
520{
Arend van Spriel5b435de2011-10-05 13:19:03 +0200521}
522
523static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
524{
525 struct ieee80211_conf *conf = &hw->conf;
526 struct brcms_info *wl = hw->priv;
Seth Forsheeb353dda2012-11-15 08:08:03 -0600527 struct bcma_device *core = wl->wlc->hw->d11core;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200528 int err = 0;
529 int new_int;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200530
531 spin_lock_bh(&wl->lock);
532 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
533 brcms_c_set_beacon_listen_interval(wl->wlc,
534 conf->listen_interval);
535 }
536 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600537 brcms_dbg_info(core, "%s: change monitor mode: %s\n",
538 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
539 "true" : "false");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200540 if (changed & IEEE80211_CONF_CHANGE_PS)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600541 brcms_err(core, "%s: change power-save mode: %s (implement)\n",
Arend van Spriel5b435de2011-10-05 13:19:03 +0200542 __func__, conf->flags & IEEE80211_CONF_PS ?
543 "true" : "false");
544
545 if (changed & IEEE80211_CONF_CHANGE_POWER) {
546 err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
547 if (err < 0) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600548 brcms_err(core, "%s: Error setting power_level\n",
Arend van Spriel5b435de2011-10-05 13:19:03 +0200549 __func__);
550 goto config_out;
551 }
552 new_int = brcms_c_get_tx_power(wl->wlc);
553 if (new_int != conf->power_level)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600554 brcms_err(core,
555 "%s: Power level req != actual, %d %d\n",
556 __func__, conf->power_level,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200557 new_int);
558 }
559 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100560 if (conf->chandef.width == NL80211_CHAN_WIDTH_20 ||
561 conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200562 err = brcms_c_set_channel(wl->wlc,
Karl Beldan675a0b02013-03-25 16:26:57 +0100563 conf->chandef.chan->hw_value);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200564 else
565 err = -ENOTSUPP;
566 }
567 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
568 err = brcms_c_set_rate_limit(wl->wlc,
569 conf->short_frame_max_tx_count,
570 conf->long_frame_max_tx_count);
571
572 config_out:
573 spin_unlock_bh(&wl->lock);
574 return err;
575}
576
577static void
578brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
579 struct ieee80211_vif *vif,
580 struct ieee80211_bss_conf *info, u32 changed)
581{
582 struct brcms_info *wl = hw->priv;
Seth Forsheeb353dda2012-11-15 08:08:03 -0600583 struct bcma_device *core = wl->wlc->hw->d11core;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200584
585 if (changed & BSS_CHANGED_ASSOC) {
586 /* association status changed (associated/disassociated)
587 * also implies a change in the AID.
588 */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600589 brcms_err(core, "%s: %s: %sassociated\n", KBUILD_MODNAME,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200590 __func__, info->assoc ? "" : "dis");
591 spin_lock_bh(&wl->lock);
592 brcms_c_associate_upd(wl->wlc, info->assoc);
593 spin_unlock_bh(&wl->lock);
594 }
595 if (changed & BSS_CHANGED_ERP_SLOT) {
596 s8 val;
597
598 /* slot timing changed */
599 if (info->use_short_slot)
600 val = 1;
601 else
602 val = 0;
603 spin_lock_bh(&wl->lock);
604 brcms_c_set_shortslot_override(wl->wlc, val);
605 spin_unlock_bh(&wl->lock);
606 }
607
608 if (changed & BSS_CHANGED_HT) {
609 /* 802.11n parameters changed */
610 u16 mode = info->ht_operation_mode;
611
612 spin_lock_bh(&wl->lock);
613 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
614 mode & IEEE80211_HT_OP_MODE_PROTECTION);
615 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
616 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
617 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
618 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
619 spin_unlock_bh(&wl->lock);
620 }
621 if (changed & BSS_CHANGED_BASIC_RATES) {
622 struct ieee80211_supported_band *bi;
623 u32 br_mask, i;
624 u16 rate;
625 struct brcm_rateset rs;
626 int error;
627
628 /* retrieve the current rates */
629 spin_lock_bh(&wl->lock);
630 brcms_c_get_current_rateset(wl->wlc, &rs);
631 spin_unlock_bh(&wl->lock);
632
633 br_mask = info->basic_rates;
634 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
635 for (i = 0; i < bi->n_bitrates; i++) {
636 /* convert to internal rate value */
637 rate = (bi->bitrates[i].bitrate << 1) / 10;
638
639 /* set/clear basic rate flag */
640 brcms_set_basic_rate(&rs, rate, br_mask & 1);
641 br_mask >>= 1;
642 }
643
644 /* update the rate set */
645 spin_lock_bh(&wl->lock);
646 error = brcms_c_set_rateset(wl->wlc, &rs);
647 spin_unlock_bh(&wl->lock);
648 if (error)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600649 brcms_err(core, "changing basic rates failed: %d\n",
Arend van Spriel5b435de2011-10-05 13:19:03 +0200650 error);
651 }
652 if (changed & BSS_CHANGED_BEACON_INT) {
653 /* Beacon interval changed */
654 spin_lock_bh(&wl->lock);
655 brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
656 spin_unlock_bh(&wl->lock);
657 }
658 if (changed & BSS_CHANGED_BSSID) {
659 /* BSSID changed, for whatever reason (IBSS and managed mode) */
660 spin_lock_bh(&wl->lock);
661 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
662 spin_unlock_bh(&wl->lock);
663 }
Hauke Mehrtensc031df32013-03-24 01:45:59 +0100664 if (changed & BSS_CHANGED_SSID) {
665 /* BSSID changed, for whatever reason (IBSS and managed mode) */
666 spin_lock_bh(&wl->lock);
667 brcms_c_set_ssid(wl->wlc, info->ssid, info->ssid_len);
668 spin_unlock_bh(&wl->lock);
669 }
Hauke Mehrtensaf44e252013-03-24 01:45:58 +0100670 if (changed & BSS_CHANGED_BEACON) {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200671 /* Beacon data changed, retrieve new beacon (beaconing modes) */
Hauke Mehrtensaf44e252013-03-24 01:45:58 +0100672 struct sk_buff *beacon;
673 u16 tim_offset = 0;
674
675 spin_lock_bh(&wl->lock);
676 beacon = ieee80211_beacon_get_tim(hw, vif, &tim_offset, NULL);
677 brcms_c_set_new_beacon(wl->wlc, beacon, tim_offset,
678 info->dtim_period);
679 spin_unlock_bh(&wl->lock);
680 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200681
Hauke Mehrtens5f1e59e2013-03-24 01:46:00 +0100682 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
683 struct sk_buff *probe_resp;
684
685 spin_lock_bh(&wl->lock);
686 probe_resp = ieee80211_proberesp_get(hw, vif);
687 brcms_c_set_new_probe_resp(wl->wlc, probe_resp);
688 spin_unlock_bh(&wl->lock);
689 }
690
Arend van Spriel5b435de2011-10-05 13:19:03 +0200691 if (changed & BSS_CHANGED_BEACON_ENABLED) {
692 /* Beaconing should be enabled/disabled (beaconing modes) */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600693 brcms_err(core, "%s: Beacon enabled: %s\n", __func__,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200694 info->enable_beacon ? "true" : "false");
Hauke Mehrtens04d2e422013-03-24 01:46:01 +0100695 if (info->enable_beacon &&
696 hw->wiphy->flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) {
697 brcms_c_enable_probe_resp(wl->wlc, true);
698 } else {
699 brcms_c_enable_probe_resp(wl->wlc, false);
700 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200701 }
702
703 if (changed & BSS_CHANGED_CQM) {
704 /* Connection quality monitor config changed */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600705 brcms_err(core, "%s: cqm change: threshold %d, hys %d "
Arend van Spriel5b435de2011-10-05 13:19:03 +0200706 " (implement)\n", __func__, info->cqm_rssi_thold,
707 info->cqm_rssi_hyst);
708 }
709
710 if (changed & BSS_CHANGED_IBSS) {
711 /* IBSS join status changed */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600712 brcms_err(core, "%s: IBSS joined: %s (implement)\n",
713 __func__, info->ibss_joined ? "true" : "false");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200714 }
715
716 if (changed & BSS_CHANGED_ARP_FILTER) {
717 /* Hardware ARP filter address list or state changed */
Johannes Berg0f19b412013-01-14 16:39:07 +0100718 brcms_err(core, "%s: arp filtering: %d addresses"
719 " (implement)\n", __func__, info->arp_addr_cnt);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200720 }
721
722 if (changed & BSS_CHANGED_QOS) {
723 /*
724 * QoS for this association was enabled/disabled.
725 * Note that it is only ever disabled for station mode.
726 */
Seth Forsheeb353dda2012-11-15 08:08:03 -0600727 brcms_err(core, "%s: qos enabled: %s (implement)\n",
728 __func__, info->qos ? "true" : "false");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200729 }
730 return;
731}
732
733static void
734brcms_ops_configure_filter(struct ieee80211_hw *hw,
735 unsigned int changed_flags,
736 unsigned int *total_flags, u64 multicast)
737{
738 struct brcms_info *wl = hw->priv;
Seth Forsheeb353dda2012-11-15 08:08:03 -0600739 struct bcma_device *core = wl->wlc->hw->d11core;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200740
741 changed_flags &= MAC_FILTERS;
742 *total_flags &= MAC_FILTERS;
Alwin Beukersbe667662011-11-22 17:21:43 -0800743
Arend van Spriel5b435de2011-10-05 13:19:03 +0200744 if (changed_flags & FIF_PROMISC_IN_BSS)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600745 brcms_dbg_info(core, "FIF_PROMISC_IN_BSS\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200746 if (changed_flags & FIF_ALLMULTI)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600747 brcms_dbg_info(core, "FIF_ALLMULTI\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200748 if (changed_flags & FIF_FCSFAIL)
Seth Forsheead667862012-11-21 09:24:31 -0600749 brcms_dbg_info(core, "FIF_FCSFAIL\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200750 if (changed_flags & FIF_CONTROL)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600751 brcms_dbg_info(core, "FIF_CONTROL\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200752 if (changed_flags & FIF_OTHER_BSS)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600753 brcms_dbg_info(core, "FIF_OTHER_BSS\n");
Alwin Beukersbe667662011-11-22 17:21:43 -0800754 if (changed_flags & FIF_PSPOLL)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600755 brcms_dbg_info(core, "FIF_PSPOLL\n");
Alwin Beukersbe667662011-11-22 17:21:43 -0800756 if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
Seth Forsheeb353dda2012-11-15 08:08:03 -0600757 brcms_dbg_info(core, "FIF_BCN_PRBRESP_PROMISC\n");
Alwin Beukersbe667662011-11-22 17:21:43 -0800758
759 spin_lock_bh(&wl->lock);
760 brcms_c_mac_promisc(wl->wlc, *total_flags);
761 spin_unlock_bh(&wl->lock);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200762 return;
763}
764
765static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
766{
767 struct brcms_info *wl = hw->priv;
768 spin_lock_bh(&wl->lock);
769 brcms_c_scan_start(wl->wlc);
770 spin_unlock_bh(&wl->lock);
771 return;
772}
773
774static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
775{
776 struct brcms_info *wl = hw->priv;
777 spin_lock_bh(&wl->lock);
778 brcms_c_scan_stop(wl->wlc);
779 spin_unlock_bh(&wl->lock);
780 return;
781}
782
783static int
784brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
785 const struct ieee80211_tx_queue_params *params)
786{
787 struct brcms_info *wl = hw->priv;
788
789 spin_lock_bh(&wl->lock);
790 brcms_c_wme_setparams(wl->wlc, queue, params, true);
791 spin_unlock_bh(&wl->lock);
792
793 return 0;
794}
795
796static int
797brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
798 struct ieee80211_sta *sta)
799{
800 struct brcms_info *wl = hw->priv;
801 struct scb *scb = &wl->wlc->pri_scb;
802
803 brcms_c_init_scb(scb);
804
805 wl->pub->global_ampdu = &(scb->scb_ampdu);
806 wl->pub->global_ampdu->scb = scb;
807 wl->pub->global_ampdu->max_pdu = 16;
808
Arend van Spriel5b435de2011-10-05 13:19:03 +0200809 /*
810 * minstrel_ht initiates addBA on our behalf by calling
811 * ieee80211_start_tx_ba_session()
812 */
813 return 0;
814}
815
816static int
817brcms_ops_ampdu_action(struct ieee80211_hw *hw,
818 struct ieee80211_vif *vif,
819 enum ieee80211_ampdu_mlme_action action,
820 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
821 u8 buf_size)
822{
823 struct brcms_info *wl = hw->priv;
824 struct scb *scb = &wl->wlc->pri_scb;
825 int status;
826
827 if (WARN_ON(scb->magic != SCB_MAGIC))
828 return -EIDRM;
829 switch (action) {
830 case IEEE80211_AMPDU_RX_START:
831 break;
832 case IEEE80211_AMPDU_RX_STOP:
833 break;
834 case IEEE80211_AMPDU_TX_START:
835 spin_lock_bh(&wl->lock);
836 status = brcms_c_aggregatable(wl->wlc, tid);
837 spin_unlock_bh(&wl->lock);
838 if (!status) {
Seth Forsheeb353dda2012-11-15 08:08:03 -0600839 brcms_err(wl->wlc->hw->d11core,
840 "START: tid %d is not agg\'able\n", tid);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200841 return -EINVAL;
842 }
843 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
844 break;
845
Johannes Berg18b559d2012-07-18 13:51:25 +0200846 case IEEE80211_AMPDU_TX_STOP_CONT:
847 case IEEE80211_AMPDU_TX_STOP_FLUSH:
848 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200849 spin_lock_bh(&wl->lock);
850 brcms_c_ampdu_flush(wl->wlc, sta, tid);
851 spin_unlock_bh(&wl->lock);
852 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
853 break;
854 case IEEE80211_AMPDU_TX_OPERATIONAL:
855 /*
856 * BA window size from ADDBA response ('buf_size') defines how
857 * many outstanding MPDUs are allowed for the BA stream by
858 * recipient and traffic class. 'ampdu_factor' gives maximum
859 * AMPDU size.
860 */
861 spin_lock_bh(&wl->lock);
862 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
863 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
864 sta->ht_cap.ampdu_factor)) - 1);
865 spin_unlock_bh(&wl->lock);
866 /* Power save wakeup */
867 break;
868 default:
Seth Forsheeb353dda2012-11-15 08:08:03 -0600869 brcms_err(wl->wlc->hw->d11core,
870 "%s: Invalid command, ignoring\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200871 }
872
873 return 0;
874}
875
876static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
877{
878 struct brcms_info *wl = hw->priv;
879 bool blocked;
880
881 spin_lock_bh(&wl->lock);
882 blocked = brcms_c_check_radio_disabled(wl->wlc);
883 spin_unlock_bh(&wl->lock);
884
885 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
886}
887
Arend van Spriel7b2385b2013-02-02 14:36:50 +0100888static bool brcms_tx_flush_completed(struct brcms_info *wl)
889{
890 bool result;
891
892 spin_lock_bh(&wl->lock);
893 result = brcms_c_tx_flush_completed(wl->wlc);
894 spin_unlock_bh(&wl->lock);
895 return result;
896}
897
Johannes Berg39ecc012013-02-13 12:11:00 +0100898static void brcms_ops_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200899{
900 struct brcms_info *wl = hw->priv;
Arend van Spriel7b2385b2013-02-02 14:36:50 +0100901 int ret;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200902
903 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
904
Arend van Spriel7b2385b2013-02-02 14:36:50 +0100905 ret = wait_event_timeout(wl->tx_flush_wq,
906 brcms_tx_flush_completed(wl),
907 msecs_to_jiffies(BRCMS_FLUSH_TIMEOUT));
908
909 brcms_dbg_mac80211(wl->wlc->hw->d11core,
910 "ret=%d\n", jiffies_to_msecs(ret));
Arend van Spriel5b435de2011-10-05 13:19:03 +0200911}
912
Hauke Mehrtens39b2d362013-03-24 01:45:49 +0100913static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
914{
915 struct brcms_info *wl = hw->priv;
916 u64 tsf;
917
918 spin_lock_bh(&wl->lock);
919 tsf = brcms_c_tsf_get(wl->wlc);
920 spin_unlock_bh(&wl->lock);
921
922 return tsf;
923}
924
925static void brcms_ops_set_tsf(struct ieee80211_hw *hw,
926 struct ieee80211_vif *vif, u64 tsf)
927{
928 struct brcms_info *wl = hw->priv;
929
930 spin_lock_bh(&wl->lock);
931 brcms_c_tsf_set(wl->wlc, tsf);
932 spin_unlock_bh(&wl->lock);
933}
934
Arend van Spriel5b435de2011-10-05 13:19:03 +0200935static const struct ieee80211_ops brcms_ops = {
936 .tx = brcms_ops_tx,
937 .start = brcms_ops_start,
938 .stop = brcms_ops_stop,
939 .add_interface = brcms_ops_add_interface,
940 .remove_interface = brcms_ops_remove_interface,
941 .config = brcms_ops_config,
942 .bss_info_changed = brcms_ops_bss_info_changed,
943 .configure_filter = brcms_ops_configure_filter,
944 .sw_scan_start = brcms_ops_sw_scan_start,
945 .sw_scan_complete = brcms_ops_sw_scan_complete,
946 .conf_tx = brcms_ops_conf_tx,
947 .sta_add = brcms_ops_sta_add,
948 .ampdu_action = brcms_ops_ampdu_action,
949 .rfkill_poll = brcms_ops_rfkill_poll,
950 .flush = brcms_ops_flush,
Hauke Mehrtens39b2d362013-03-24 01:45:49 +0100951 .get_tsf = brcms_ops_get_tsf,
952 .set_tsf = brcms_ops_set_tsf,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200953};
954
Arend van Spriel5b435de2011-10-05 13:19:03 +0200955void brcms_dpc(unsigned long data)
956{
957 struct brcms_info *wl;
958
959 wl = (struct brcms_info *) data;
960
961 spin_lock_bh(&wl->lock);
962
963 /* call the common second level interrupt handler */
964 if (wl->pub->up) {
965 if (wl->resched) {
966 unsigned long flags;
967
968 spin_lock_irqsave(&wl->isr_lock, flags);
969 brcms_c_intrsupd(wl->wlc);
970 spin_unlock_irqrestore(&wl->isr_lock, flags);
971 }
972
973 wl->resched = brcms_c_dpc(wl->wlc, true);
974 }
975
976 /* brcms_c_dpc() may bring the driver down */
977 if (!wl->pub->up)
978 goto done;
979
980 /* re-schedule dpc */
981 if (wl->resched)
982 tasklet_schedule(&wl->tasklet);
983 else
984 /* re-enable interrupts */
985 brcms_intrson(wl);
986
987 done:
988 spin_unlock_bh(&wl->lock);
Arend van Spriel7b2385b2013-02-02 14:36:50 +0100989 wake_up(&wl->tx_flush_wq);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200990}
991
Arend van Spriel5b435de2011-10-05 13:19:03 +0200992static irqreturn_t brcms_isr(int irq, void *dev_id)
993{
994 struct brcms_info *wl;
Piotr Haber94d99022012-11-28 21:44:06 +0100995 irqreturn_t ret = IRQ_NONE;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200996
997 wl = (struct brcms_info *) dev_id;
998
999 spin_lock(&wl->isr_lock);
1000
1001 /* call common first level interrupt handler */
Piotr Haber94d99022012-11-28 21:44:06 +01001002 if (brcms_c_isr(wl->wlc)) {
1003 /* schedule second level handler */
1004 tasklet_schedule(&wl->tasklet);
1005 ret = IRQ_HANDLED;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001006 }
1007
1008 spin_unlock(&wl->isr_lock);
1009
Piotr Haber94d99022012-11-28 21:44:06 +01001010 return ret;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001011}
1012
1013/*
1014 * is called in brcms_pci_probe() context, therefore no locking required.
1015 */
1016static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1017{
1018 struct brcms_info *wl = hw->priv;
1019 struct brcms_c_info *wlc = wl->wlc;
1020 struct ieee80211_supported_band *band;
1021 int has_5g = 0;
1022 u16 phy_type;
1023
1024 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1025 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1026
1027 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
1028 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
1029 band = &wlc->bandstate[BAND_2G_INDEX]->band;
1030 *band = brcms_band_2GHz_nphy_template;
1031 if (phy_type == PHY_TYPE_LCN) {
1032 /* Single stream */
1033 band->ht_cap.mcs.rx_mask[1] = 0;
Arend van Sprieldf4492f2011-10-12 20:51:15 +02001034 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001035 }
1036 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
1037 } else {
1038 return -EPERM;
1039 }
1040
1041 /* Assume all bands use the same phy. True for 11n devices. */
1042 if (wl->pub->_nbands > 1) {
1043 has_5g++;
1044 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
1045 band = &wlc->bandstate[BAND_5G_INDEX]->band;
1046 *band = brcms_band_5GHz_nphy_template;
1047 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
1048 } else {
1049 return -EPERM;
1050 }
1051 }
1052 return 0;
1053}
1054
1055/*
1056 * is called in brcms_pci_probe() context, therefore no locking required.
1057 */
1058static int ieee_hw_init(struct ieee80211_hw *hw)
1059{
1060 hw->flags = IEEE80211_HW_SIGNAL_DBM
1061 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1062 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1063 | IEEE80211_HW_AMPDU_AGGREGATION;
1064
1065 hw->extra_tx_headroom = brcms_c_get_header_len();
1066 hw->queues = N_TX_QUEUES;
1067 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1068
1069 /* channel change time is dependent on chip and band */
1070 hw->channel_change_time = 7 * 1000;
Hauke Mehrtens492b71e2013-03-24 01:46:02 +01001071 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Hauke Mehrtensc55b3762013-03-24 01:46:03 +01001072 BIT(NL80211_IFTYPE_AP) |
1073 BIT(NL80211_IFTYPE_ADHOC);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001074
Hauke Mehrtens04d2e422013-03-24 01:46:01 +01001075 /*
1076 * deactivate sending probe responses by ucude, because this will
1077 * cause problems when WPS is used.
1078 *
1079 * hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1080 */
Hauke Mehrtens5f1e59e2013-03-24 01:46:00 +01001081
Arend van Spriel5b435de2011-10-05 13:19:03 +02001082 hw->rate_control_algorithm = "minstrel_ht";
1083
1084 hw->sta_data_size = 0;
1085 return ieee_hw_rate_init(hw);
1086}
1087
1088/**
1089 * attach to the WL device.
1090 *
1091 * Attach to the WL device identified by vendor and device parameters.
1092 * regs is a host accessible memory address pointing to WL device registers.
1093 *
1094 * brcms_attach is not defined as static because in the case where no bus
1095 * is defined, wl_attach will never be called, and thus, gcc will issue
1096 * a warning that this function is defined but not used if we declare
1097 * it as static.
1098 *
1099 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001100 * is called in brcms_bcma_probe() context, therefore no locking required.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001101 */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001102static struct brcms_info *brcms_attach(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001103{
1104 struct brcms_info *wl = NULL;
1105 int unit, err;
1106 struct ieee80211_hw *hw;
1107 u8 perm[ETH_ALEN];
1108
1109 unit = n_adapters_found;
1110 err = 0;
1111
1112 if (unit < 0)
1113 return NULL;
1114
1115 /* allocate private info */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001116 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001117 if (hw != NULL)
1118 wl = hw->priv;
1119 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1120 return NULL;
1121 wl->wiphy = hw->wiphy;
1122
1123 atomic_set(&wl->callbacks, 0);
1124
Arend van Spriel7b2385b2013-02-02 14:36:50 +01001125 init_waitqueue_head(&wl->tx_flush_wq);
1126
Arend van Spriel5b435de2011-10-05 13:19:03 +02001127 /* setup the bottom half handler */
1128 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1129
Arend van Spriel5b435de2011-10-05 13:19:03 +02001130 spin_lock_init(&wl->lock);
1131 spin_lock_init(&wl->isr_lock);
1132
Arend van Spriel5b435de2011-10-05 13:19:03 +02001133 /* common load-time initialization */
Arend van Sprielb63337a2011-12-08 15:06:47 -08001134 wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001135 if (!wl->wlc) {
1136 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1137 KBUILD_MODNAME, err);
1138 goto fail;
1139 }
1140 wl->pub = brcms_c_pub(wl->wlc);
1141
1142 wl->pub->ieee_hw = hw;
1143
Arend van Spriel5b435de2011-10-05 13:19:03 +02001144 /* register our interrupt handler */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001145 if (request_irq(pdev->irq, brcms_isr,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001146 IRQF_SHARED, KBUILD_MODNAME, wl)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001147 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1148 goto fail;
1149 }
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001150 wl->irq = pdev->irq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001151
1152 /* register module */
1153 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1154
1155 if (ieee_hw_init(hw)) {
1156 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1157 __func__);
1158 goto fail;
1159 }
1160
Seth Forsheecf03c5d2012-06-16 07:47:52 -05001161 brcms_c_regd_init(wl->wlc);
1162
Arend van Spriel5b435de2011-10-05 13:19:03 +02001163 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1164 if (WARN_ON(!is_valid_ether_addr(perm)))
1165 goto fail;
1166 SET_IEEE80211_PERM_ADDR(hw, perm);
1167
1168 err = ieee80211_register_hw(hw);
1169 if (err)
1170 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1171 "%d\n", __func__, err);
1172
Arend van Sprield597ee72012-06-09 22:51:41 +02001173 if (wl->pub->srom_ccode[0] &&
1174 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1175 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001176
Piotr Haber8e21df22012-11-28 21:44:08 +01001177 brcms_debugfs_attach(wl->pub);
1178 brcms_debugfs_create_files(wl->pub);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001179 n_adapters_found++;
1180 return wl;
1181
1182fail:
1183 brcms_free(wl);
1184 return NULL;
1185}
1186
1187
1188
1189/**
1190 * determines if a device is a WL device, and if so, attaches it.
1191 *
1192 * This function determines if a device pointed to by pdev is a WL device,
1193 * and if so, performs a brcms_attach() on it.
1194 *
1195 * Perimeter lock is initialized in the course of this function.
1196 */
Bill Pembertonfcff0c02012-12-03 09:56:31 -05001197static int brcms_bcma_probe(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001198{
Arend van Spriel5b435de2011-10-05 13:19:03 +02001199 struct brcms_info *wl;
1200 struct ieee80211_hw *hw;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001201
Arend van Spriel2e7565602011-12-08 15:06:46 -08001202 dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
1203 pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001204 pdev->irq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001205
Arend van Spriel2e7565602011-12-08 15:06:46 -08001206 if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
1207 (pdev->id.id != BCMA_CORE_80211))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001208 return -ENODEV;
1209
Arend van Spriel5b435de2011-10-05 13:19:03 +02001210 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1211 if (!hw) {
1212 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1213 return -ENOMEM;
1214 }
1215
1216 SET_IEEE80211_DEV(hw, &pdev->dev);
1217
Arend van Spriel2e7565602011-12-08 15:06:46 -08001218 bcma_set_drvdata(pdev, hw);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001219
1220 memset(hw->priv, 0, sizeof(*wl));
1221
Arend van Spriel2e7565602011-12-08 15:06:46 -08001222 wl = brcms_attach(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001223 if (!wl) {
Joe Perches02f77192012-01-15 00:38:44 -08001224 pr_err("%s: brcms_attach failed!\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001225 return -ENODEV;
1226 }
Piotr Habercd864522013-03-03 12:45:20 +01001227 brcms_led_register(wl);
1228
Arend van Spriel5b435de2011-10-05 13:19:03 +02001229 return 0;
1230}
1231
Linus Torvalds7d5869e2012-01-13 23:58:41 +01001232static int brcms_suspend(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001233{
1234 struct brcms_info *wl;
1235 struct ieee80211_hw *hw;
1236
Arend van Spriel2e7565602011-12-08 15:06:46 -08001237 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001238 wl = hw->priv;
1239 if (!wl) {
Arend van Spriel137dabe2012-02-09 21:08:59 +01001240 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
1241 __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001242 return -ENODEV;
1243 }
1244
1245 /* only need to flag hw is down for proper resume */
1246 spin_lock_bh(&wl->lock);
1247 wl->pub->hw_up = false;
1248 spin_unlock_bh(&wl->lock);
1249
Seth Forsheeb353dda2012-11-15 08:08:03 -06001250 brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001251
Arend van Spriel2e7565602011-12-08 15:06:46 -08001252 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001253}
1254
Arend van Spriel2e7565602011-12-08 15:06:46 -08001255static int brcms_resume(struct bcma_device *pdev)
1256{
Linus Torvalds7e9e7fa2012-01-13 23:58:42 +01001257 return 0;
Arend van Spriel2e7565602011-12-08 15:06:46 -08001258}
1259
1260static struct bcma_driver brcms_bcma_driver = {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001261 .name = KBUILD_MODNAME,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001262 .probe = brcms_bcma_probe,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001263 .suspend = brcms_suspend,
1264 .resume = brcms_resume,
Bill Pembertonfcff0c02012-12-03 09:56:31 -05001265 .remove = brcms_remove,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001266 .id_table = brcms_coreid_table,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001267};
1268
1269/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001270 * This is the main entry point for the brcmsmac driver.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001271 *
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001272 * This function is scheduled upon module initialization and
1273 * does the driver registration, which result in brcms_bcma_probe()
1274 * call resulting in the driver bringup.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001275 */
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001276static void brcms_driver_init(struct work_struct *work)
1277{
1278 int error;
1279
1280 error = bcma_driver_register(&brcms_bcma_driver);
1281 if (error)
1282 pr_err("%s: register returned %d\n", __func__, error);
1283}
1284
1285static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
1286
Arend van Spriel5b435de2011-10-05 13:19:03 +02001287static int __init brcms_module_init(void)
1288{
Piotr Haber8e21df22012-11-28 21:44:08 +01001289 brcms_debugfs_init();
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001290 if (!schedule_work(&brcms_driver_work))
1291 return -EBUSY;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001292
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001293 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001294}
1295
1296/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001297 * This function unloads the brcmsmac driver from the system.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001298 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001299 * This function unconditionally unloads the brcmsmac driver module from the
Arend van Spriel5b435de2011-10-05 13:19:03 +02001300 * system.
1301 *
1302 */
1303static void __exit brcms_module_exit(void)
1304{
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001305 cancel_work_sync(&brcms_driver_work);
Arend van Spriel2e7565602011-12-08 15:06:46 -08001306 bcma_driver_unregister(&brcms_bcma_driver);
Piotr Haber8e21df22012-11-28 21:44:08 +01001307 brcms_debugfs_exit();
Arend van Spriel5b435de2011-10-05 13:19:03 +02001308}
1309
1310module_init(brcms_module_init);
1311module_exit(brcms_module_exit);
1312
1313/*
1314 * precondition: perimeter lock has been acquired
1315 */
1316void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1317 bool state, int prio)
1318{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001319 brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001320}
1321
1322/*
1323 * precondition: perimeter lock has been acquired
1324 */
1325void brcms_init(struct brcms_info *wl)
1326{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001327 brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
1328 wl->pub->unit);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001329 brcms_reset(wl);
Roland Vossendc460122011-10-21 16:16:28 +02001330 brcms_c_init(wl->wlc, wl->mute_tx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001331}
1332
1333/*
1334 * precondition: perimeter lock has been acquired
1335 */
1336uint brcms_reset(struct brcms_info *wl)
1337{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001338 brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001339 brcms_c_reset(wl->wlc);
1340
1341 /* dpc will not be rescheduled */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001342 wl->resched = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001343
Vladimir Zapolskiyea2d2182012-08-05 00:29:07 +03001344 /* inform publicly that interface is down */
1345 wl->pub->up = false;
1346
Arend van Spriel5b435de2011-10-05 13:19:03 +02001347 return 0;
1348}
1349
Roland Vossenc261bdf2011-10-18 14:03:04 +02001350void brcms_fatal_error(struct brcms_info *wl)
1351{
Seth Forsheeb353dda2012-11-15 08:08:03 -06001352 brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
Roland Vossenc261bdf2011-10-18 14:03:04 +02001353 wl->wlc->pub->unit);
1354 brcms_reset(wl);
1355 ieee80211_restart_hw(wl->pub->ieee_hw);
1356}
1357
Arend van Spriel5b435de2011-10-05 13:19:03 +02001358/*
1359 * These are interrupt on/off entry points. Disable interrupts
1360 * during interrupt state transition.
1361 */
1362void brcms_intrson(struct brcms_info *wl)
1363{
1364 unsigned long flags;
1365
1366 spin_lock_irqsave(&wl->isr_lock, flags);
1367 brcms_c_intrson(wl->wlc);
1368 spin_unlock_irqrestore(&wl->isr_lock, flags);
1369}
1370
1371u32 brcms_intrsoff(struct brcms_info *wl)
1372{
1373 unsigned long flags;
1374 u32 status;
1375
1376 spin_lock_irqsave(&wl->isr_lock, flags);
1377 status = brcms_c_intrsoff(wl->wlc);
1378 spin_unlock_irqrestore(&wl->isr_lock, flags);
1379 return status;
1380}
1381
1382void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1383{
1384 unsigned long flags;
1385
1386 spin_lock_irqsave(&wl->isr_lock, flags);
1387 brcms_c_intrsrestore(wl->wlc, macintmask);
1388 spin_unlock_irqrestore(&wl->isr_lock, flags);
1389}
1390
1391/*
1392 * precondition: perimeter lock has been acquired
1393 */
1394int brcms_up(struct brcms_info *wl)
1395{
1396 int error = 0;
1397
1398 if (wl->pub->up)
1399 return 0;
1400
1401 error = brcms_c_up(wl->wlc);
1402
1403 return error;
1404}
1405
1406/*
1407 * precondition: perimeter lock has been acquired
1408 */
1409void brcms_down(struct brcms_info *wl)
1410{
1411 uint callbacks, ret_val = 0;
1412
1413 /* call common down function */
1414 ret_val = brcms_c_down(wl->wlc);
1415 callbacks = atomic_read(&wl->callbacks) - ret_val;
1416
1417 /* wait for down callbacks to complete */
1418 spin_unlock_bh(&wl->lock);
1419
1420 /* For HIGH_only driver, it's important to actually schedule other work,
1421 * not just spin wait since everything runs at schedule level
1422 */
1423 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1424
1425 spin_lock_bh(&wl->lock);
1426}
1427
1428/*
1429* precondition: perimeter lock is not acquired
1430 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001431static void _brcms_timer(struct work_struct *work)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001432{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001433 struct brcms_timer *t = container_of(work, struct brcms_timer,
1434 dly_wrk.work);
1435
Arend van Spriel5b435de2011-10-05 13:19:03 +02001436 spin_lock_bh(&t->wl->lock);
1437
1438 if (t->set) {
1439 if (t->periodic) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001440 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001441 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1442 &t->dly_wrk,
1443 msecs_to_jiffies(t->ms));
1444 } else {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001445 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001446 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001447
1448 t->fn(t->arg);
1449 }
1450
1451 atomic_dec(&t->wl->callbacks);
1452
1453 spin_unlock_bh(&t->wl->lock);
1454}
1455
1456/*
Arend van Spriel5b435de2011-10-05 13:19:03 +02001457 * Adds a timer to the list. Caller supplies a timer function.
1458 * Is called from wlc.
1459 *
1460 * precondition: perimeter lock has been acquired
1461 */
1462struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1463 void (*fn) (void *arg),
1464 void *arg, const char *name)
1465{
1466 struct brcms_timer *t;
1467
1468 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1469 if (!t)
1470 return NULL;
1471
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001472 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001473 t->wl = wl;
1474 t->fn = fn;
1475 t->arg = arg;
1476 t->next = wl->timers;
1477 wl->timers = t;
1478
Joe Perches8ae74652012-01-15 00:38:38 -08001479#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001480 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1481 if (t->name)
1482 strcpy(t->name, name);
1483#endif
1484
1485 return t;
1486}
1487
1488/*
1489 * adds only the kernel timer since it's going to be more accurate
1490 * as well as it's easier to make it periodic
1491 *
1492 * precondition: perimeter lock has been acquired
1493 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001494void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001495{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001496 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1497
Joe Perches8ae74652012-01-15 00:38:38 -08001498#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001499 if (t->set)
Seth Forsheeb353dda2012-11-15 08:08:03 -06001500 brcms_dbg_info(t->wl->wlc->hw->d11core,
1501 "%s: Already set. Name: %s, per %d\n",
1502 __func__, t->name, periodic);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001503#endif
1504 t->ms = ms;
1505 t->periodic = (bool) periodic;
Piotr Haber01486c52013-01-02 15:22:34 +01001506 if (!t->set) {
1507 t->set = true;
1508 atomic_inc(&t->wl->callbacks);
1509 }
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001510
1511 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001512}
1513
1514/*
1515 * return true if timer successfully deleted, false if still pending
1516 *
1517 * precondition: perimeter lock has been acquired
1518 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001519bool brcms_del_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001520{
1521 if (t->set) {
1522 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001523 if (!cancel_delayed_work(&t->dly_wrk))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001524 return false;
1525
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001526 atomic_dec(&t->wl->callbacks);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001527 }
1528
1529 return true;
1530}
1531
1532/*
1533 * precondition: perimeter lock has been acquired
1534 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001535void brcms_free_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001536{
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001537 struct brcms_info *wl = t->wl;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001538 struct brcms_timer *tmp;
1539
1540 /* delete the timer in case it is active */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001541 brcms_del_timer(t);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001542
1543 if (wl->timers == t) {
1544 wl->timers = wl->timers->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001545#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001546 kfree(t->name);
1547#endif
1548 kfree(t);
1549 return;
1550
1551 }
1552
1553 tmp = wl->timers;
1554 while (tmp) {
1555 if (tmp->next == t) {
1556 tmp->next = t->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001557#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001558 kfree(t->name);
1559#endif
1560 kfree(t);
1561 return;
1562 }
1563 tmp = tmp->next;
1564 }
1565
1566}
1567
1568/*
1569 * precondition: perimeter lock has been acquired
1570 */
1571int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1572{
1573 int i, entry;
1574 const u8 *pdata;
1575 struct firmware_hdr *hdr;
1576 for (i = 0; i < wl->fw.fw_cnt; i++) {
1577 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1578 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1579 entry++, hdr++) {
1580 u32 len = le32_to_cpu(hdr->len);
1581 if (le32_to_cpu(hdr->idx) == idx) {
1582 pdata = wl->fw.fw_bin[i]->data +
1583 le32_to_cpu(hdr->offset);
Thomas Meyer1f1d52892011-11-17 23:43:40 +01001584 *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001585 if (*pbuf == NULL)
1586 goto fail;
1587
Arend van Spriel5b435de2011-10-05 13:19:03 +02001588 return 0;
1589 }
1590 }
1591 }
Seth Forsheeb353dda2012-11-15 08:08:03 -06001592 brcms_err(wl->wlc->hw->d11core,
1593 "ERROR: ucode buf tag:%d can not be found!\n", idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001594 *pbuf = NULL;
1595fail:
1596 return -ENODATA;
1597}
1598
1599/*
Arend van Spriel2e7565602011-12-08 15:06:46 -08001600 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001601 * no locking is required.
1602 */
1603int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1604{
1605 int i, entry;
1606 const u8 *pdata;
1607 struct firmware_hdr *hdr;
1608 for (i = 0; i < wl->fw.fw_cnt; i++) {
1609 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1610 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1611 entry++, hdr++) {
1612 if (le32_to_cpu(hdr->idx) == idx) {
1613 pdata = wl->fw.fw_bin[i]->data +
1614 le32_to_cpu(hdr->offset);
1615 if (le32_to_cpu(hdr->len) != 4) {
Seth Forsheeb353dda2012-11-15 08:08:03 -06001616 brcms_err(wl->wlc->hw->d11core,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001617 "ERROR: fw hdr len\n");
1618 return -ENOMSG;
1619 }
1620 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1621 return 0;
1622 }
1623 }
1624 }
Seth Forsheeb353dda2012-11-15 08:08:03 -06001625 brcms_err(wl->wlc->hw->d11core,
1626 "ERROR: ucode tag:%d can not be found!\n", idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001627 return -ENOMSG;
1628}
1629
1630/*
1631 * precondition: can both be called locked and unlocked
1632 */
1633void brcms_ucode_free_buf(void *p)
1634{
1635 kfree(p);
1636}
1637
1638/*
1639 * checks validity of all firmware images loaded from user space
1640 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001641 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001642 * no locking is required.
1643 */
1644int brcms_check_firmwares(struct brcms_info *wl)
1645{
1646 int i;
1647 int entry;
1648 int rc = 0;
1649 const struct firmware *fw;
1650 const struct firmware *fw_hdr;
1651 struct firmware_hdr *ucode_hdr;
1652 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1653 fw = wl->fw.fw_bin[i];
1654 fw_hdr = wl->fw.fw_hdr[i];
1655 if (fw == NULL && fw_hdr == NULL) {
1656 break;
1657 } else if (fw == NULL || fw_hdr == NULL) {
1658 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1659 __func__);
1660 rc = -EBADF;
1661 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1662 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1663 "size %zu/%zu\n", __func__, fw_hdr->size,
1664 sizeof(struct firmware_hdr));
1665 rc = -EBADF;
1666 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
Seth Forsheeb353dda2012-11-15 08:08:03 -06001667 wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
1668 __func__, fw->size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001669 rc = -EBADF;
1670 } else {
1671 /* check if ucode section overruns firmware image */
1672 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1673 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1674 !rc; entry++, ucode_hdr++) {
1675 if (le32_to_cpu(ucode_hdr->offset) +
1676 le32_to_cpu(ucode_hdr->len) >
1677 fw->size) {
1678 wiphy_err(wl->wiphy,
1679 "%s: conflicting bin/hdr\n",
1680 __func__);
1681 rc = -EBADF;
1682 }
1683 }
1684 }
1685 }
1686 if (rc == 0 && wl->fw.fw_cnt != i) {
1687 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1688 wl->fw.fw_cnt);
1689 rc = -EBADF;
1690 }
1691 return rc;
1692}
1693
1694/*
1695 * precondition: perimeter lock has been acquired
1696 */
1697bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1698{
1699 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1700
1701 spin_unlock_bh(&wl->lock);
1702 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1703 if (blocked)
1704 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1705 spin_lock_bh(&wl->lock);
1706 return blocked;
1707}