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