]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - drivers/staging/brcm80211/sys/wl_mac80211.c
staging: brcm80211: last nail into proto/ethernet.h
[mirror_ubuntu-kernels.git] / drivers / staging / brcm80211 / sys / wl_mac80211.c
CommitLineData
a9533e7e
HP
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
a9533e7e 19#include <linux/kernel.h>
a9533e7e 20#include <linux/etherdevice.h>
a9533e7e 21#include <linux/string.h>
a9533e7e 22#include <linux/pci_ids.h>
a1c16ed2 23#include <bcmdefs.h>
c6ac24e9
BR
24#include <linux/module.h>
25#include <linux/pci.h>
26#include <linux/sched.h>
a1c16ed2 27#include <osl.h>
a9533e7e
HP
28#define WLC_MAXBSSCFG 1 /* single BSS configs */
29
a9533e7e
HP
30#include <wlc_cfg.h>
31#include <net/mac80211.h>
a9533e7e 32#include <phy_version.h>
a9533e7e
HP
33#include <bcmutils.h>
34#include <pcicfg.h>
35#include <wlioctl.h>
36#include <wlc_key.h>
a52ba66c
BR
37#include <sbhndpio.h>
38#include <sbhnddma.h>
a9533e7e
HP
39#include <wlc_channel.h>
40#include <wlc_pub.h>
41#include <wlc_scb.h>
42#include <wl_dbg.h>
a9533e7e 43#include <wl_export.h>
a9533e7e
HP
44
45#include <wl_mac80211.h>
46#include <linux/firmware.h>
a9533e7e
HP
47#include <wl_ucode.h>
48#include <d11ucode_ext.h>
a9533e7e 49
a9533e7e 50
3deea904 51static void wl_timer(unsigned long data);
7cc4a4c0 52static void _wl_timer(wl_timer_t *t);
a9533e7e 53
a9533e7e
HP
54
55static int ieee_hw_init(struct ieee80211_hw *hw);
56static int ieee_hw_rate_init(struct ieee80211_hw *hw);
57
58static int wl_linux_watchdog(void *ctx);
59
60/* Flags we support */
61#define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
62 FIF_ALLMULTI | \
63 FIF_FCSFAIL | \
64 FIF_PLCPFAIL | \
65 FIF_CONTROL | \
66 FIF_OTHER_BSS | \
67 FIF_BCN_PRBRESP_PROMISC)
68
7e85c729 69static int wl_found;
a9533e7e
HP
70
71struct ieee80211_tkip_data {
72#define TKIP_KEY_LEN 32
73 u8 key[TKIP_KEY_LEN];
74 int key_set;
75
76 u32 tx_iv32;
77 u16 tx_iv16;
78 u16 tx_ttak[5];
79 int tx_phase1_done;
80
81 u32 rx_iv32;
82 u16 rx_iv16;
83 u16 rx_ttak[5];
84 int rx_phase1_done;
85 u32 rx_iv32_new;
86 u16 rx_iv16_new;
87
88 u32 dot11RSNAStatsTKIPReplays;
89 u32 dot11RSNAStatsTKIPICVErrors;
90 u32 dot11RSNAStatsTKIPLocalMICFailures;
91
92 int key_idx;
93
94 struct crypto_tfm *tfm_arc4;
95 struct crypto_tfm *tfm_michael;
96
97 /* scratch buffers for virt_to_page() (crypto API) */
98 u8 rx_hdr[16], tx_hdr[16];
99};
100
6cdeaef2 101#define WL_DEV_IF(dev) ((struct wl_if *)netdev_priv(dev))
2cb22a7a
RV
102#define WL_INFO(dev) ((struct wl_info *)(WL_DEV_IF(dev)->wl))
103static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev);
104static void wl_release_fw(struct wl_info *wl);
a9533e7e
HP
105
106/* local prototypes */
2cb22a7a
RV
107static int wl_start(struct sk_buff *skb, struct wl_info *wl);
108static int wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw,
a9533e7e 109 struct sk_buff *skb);
3deea904 110static void wl_dpc(unsigned long data);
a9533e7e
HP
111
112MODULE_AUTHOR("Broadcom Corporation");
113MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
114MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
115MODULE_LICENSE("Dual BSD/GPL");
116
a9533e7e
HP
117/* recognized PCI IDs */
118static struct pci_device_id wl_id_table[] = {
119 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
120 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
121 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
122 {0}
123};
124
125MODULE_DEVICE_TABLE(pci, wl_id_table);
6f0c5bcd 126static void wl_remove(struct pci_dev *pdev);
a9533e7e 127
a9533e7e
HP
128
129#ifdef BCMDBG
130static int msglevel = 0xdeadbeef;
131module_param(msglevel, int, 0);
a9533e7e
HP
132static int phymsglevel = 0xdeadbeef;
133module_param(phymsglevel, int, 0);
a9533e7e
HP
134#endif /* BCMDBG */
135
0d706ef4
JC
136#define HW_TO_WL(hw) (hw->priv)
137#define WL_TO_HW(wl) (wl->pub->ieee_hw)
a9533e7e 138static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
a9533e7e
HP
139static int wl_ops_start(struct ieee80211_hw *hw);
140static void wl_ops_stop(struct ieee80211_hw *hw);
141static int wl_ops_add_interface(struct ieee80211_hw *hw,
142 struct ieee80211_vif *vif);
143static void wl_ops_remove_interface(struct ieee80211_hw *hw,
144 struct ieee80211_vif *vif);
145static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
146static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
147 struct ieee80211_vif *vif,
148 struct ieee80211_bss_conf *info,
149 u32 changed);
150static void wl_ops_configure_filter(struct ieee80211_hw *hw,
151 unsigned int changed_flags,
152 unsigned int *total_flags, u64 multicast);
153static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
154 bool set);
155static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
156static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
157static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
158static int wl_ops_get_stats(struct ieee80211_hw *hw,
159 struct ieee80211_low_level_stats *stats);
160static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
161static void wl_ops_sta_notify(struct ieee80211_hw *hw,
162 struct ieee80211_vif *vif,
163 enum sta_notify_cmd cmd,
164 struct ieee80211_sta *sta);
165static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
166 const struct ieee80211_tx_queue_params *params);
167static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
168static int wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
169 struct ieee80211_sta *sta);
170static int wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
171 struct ieee80211_sta *sta);
172static int wl_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
173 enum ieee80211_ampdu_mlme_action action,
7cc4a4c0 174 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
a9533e7e 175
a9533e7e
HP
176static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
177{
178 int status;
2cb22a7a 179 struct wl_info *wl = hw->priv;
a9533e7e
HP
180 WL_LOCK(wl);
181 if (!wl->pub->up) {
f4528696 182 WL_ERROR("ops->tx called while down\n");
a9533e7e
HP
183 status = -ENETDOWN;
184 goto done;
185 }
186 status = wl_start(skb, wl);
187 done:
188 WL_UNLOCK(wl);
189 return status;
190}
a9533e7e
HP
191
192static int wl_ops_start(struct ieee80211_hw *hw)
193{
2cb22a7a 194 struct wl_info *wl = hw->priv;
f4528696
JP
195 /*
196 struct ieee80211_channel *curchan = hw->conf.channel;
197 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
198 */
a9533e7e
HP
199
200 WL_LOCK(wl);
201 ieee80211_wake_queues(hw);
202 WL_UNLOCK(wl);
203
204 return 0;
205}
206
207static void wl_ops_stop(struct ieee80211_hw *hw)
208{
2cb22a7a 209 struct wl_info *wl = hw->priv;
a9533e7e
HP
210 ASSERT(wl);
211 WL_LOCK(wl);
212 wl_down(wl);
213 ieee80211_stop_queues(hw);
214 WL_UNLOCK(wl);
215
216 return;
217}
218
219static int
220wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
221{
2cb22a7a 222 struct wl_info *wl;
a9533e7e
HP
223 int err;
224
225 /* Just STA for now */
226 if (vif->type != NL80211_IFTYPE_AP &&
227 vif->type != NL80211_IFTYPE_MESH_POINT &&
228 vif->type != NL80211_IFTYPE_STATION &&
229 vif->type != NL80211_IFTYPE_WDS &&
230 vif->type != NL80211_IFTYPE_ADHOC) {
f4528696
JP
231 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
232 __func__, vif->type);
a9533e7e
HP
233 return -EOPNOTSUPP;
234 }
235
236 wl = HW_TO_WL(hw);
237 WL_LOCK(wl);
238 err = wl_up(wl);
239 WL_UNLOCK(wl);
240
241 if (err != 0)
f4528696 242 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
a9533e7e
HP
243 return err;
244}
245
246static void
247wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
248{
249 return;
250}
251
252static int
253ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
254 enum nl80211_channel_type type)
255{
2cb22a7a 256 struct wl_info *wl = HW_TO_WL(hw);
a9533e7e
HP
257 int err = 0;
258
259 switch (type) {
260 case NL80211_CHAN_HT20:
261 case NL80211_CHAN_NO_HT:
262 WL_LOCK(wl);
263 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
264 WL_UNLOCK(wl);
265 break;
266 case NL80211_CHAN_HT40MINUS:
267 case NL80211_CHAN_HT40PLUS:
f4528696 268 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
a9533e7e
HP
269 break;
270 }
271
272 if (err)
273 return -EIO;
274 return err;
275}
276
277static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
278{
279 struct ieee80211_conf *conf = &hw->conf;
2cb22a7a 280 struct wl_info *wl = HW_TO_WL(hw);
a9533e7e
HP
281 int err = 0;
282 int new_int;
283
284 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
f4528696
JP
285 WL_NONE("%s: Setting listen interval to %d\n",
286 __func__, conf->listen_interval);
a9533e7e
HP
287 if (wlc_iovar_setint
288 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
f4528696
JP
289 WL_ERROR("%s: Error setting listen_interval\n",
290 __func__);
a9533e7e
HP
291 err = -EIO;
292 goto config_out;
293 }
294 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
295 ASSERT(new_int == conf->listen_interval);
296 }
297 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
f4528696 298 WL_NONE("Need to set monitor mode\n");
a9533e7e 299 if (changed & IEEE80211_CONF_CHANGE_PS)
f4528696 300 WL_NONE("Need to set Power-save mode\n");
a9533e7e
HP
301
302 if (changed & IEEE80211_CONF_CHANGE_POWER) {
f4528696
JP
303 WL_NONE("%s: Setting tx power to %d dbm\n",
304 __func__, conf->power_level);
a9533e7e
HP
305 if (wlc_iovar_setint
306 (wl->wlc, "qtxpower", conf->power_level * 4)) {
f4528696 307 WL_ERROR("%s: Error setting power_level\n", __func__);
a9533e7e
HP
308 err = -EIO;
309 goto config_out;
310 }
311 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
312 if (new_int != (conf->power_level * 4))
f4528696
JP
313 WL_ERROR("%s: Power level req != actual, %d %d\n",
314 __func__, conf->power_level * 4, new_int);
a9533e7e
HP
315 }
316 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
317 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
318 }
319 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
f4528696
JP
320 WL_NONE("%s: srl %d, lrl %d\n",
321 __func__,
322 conf->short_frame_max_tx_count,
323 conf->long_frame_max_tx_count);
a9533e7e
HP
324 if (wlc_set
325 (wl->wlc, WLC_SET_SRL,
326 conf->short_frame_max_tx_count) < 0) {
f4528696 327 WL_ERROR("%s: Error setting srl\n", __func__);
a9533e7e
HP
328 err = -EIO;
329 goto config_out;
330 }
331 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
332 < 0) {
f4528696 333 WL_ERROR("%s: Error setting lrl\n", __func__);
a9533e7e
HP
334 err = -EIO;
335 goto config_out;
336 }
337 }
338
339 config_out:
340 return err;
341}
342
343static void
344wl_ops_bss_info_changed(struct ieee80211_hw *hw,
345 struct ieee80211_vif *vif,
346 struct ieee80211_bss_conf *info, u32 changed)
347{
2cb22a7a 348 struct wl_info *wl = HW_TO_WL(hw);
a9533e7e
HP
349 int val;
350
a9533e7e
HP
351
352 if (changed & BSS_CHANGED_ASSOC) {
f4528696 353 WL_ERROR("Associated:\t%s\n", info->assoc ? "True" : "False");
a9533e7e
HP
354 /* association status changed (associated/disassociated)
355 * also implies a change in the AID.
356 */
357 }
358 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
f4528696
JP
359 WL_NONE("Use_cts_prot:\t%s Implement me\n",
360 info->use_cts_prot ? "True" : "False");
a9533e7e
HP
361 /* CTS protection changed */
362 }
363 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
f4528696
JP
364 WL_NONE("Short preamble:\t%s Implement me\n",
365 info->use_short_preamble ? "True" : "False");
a9533e7e
HP
366 /* preamble changed */
367 }
368 if (changed & BSS_CHANGED_ERP_SLOT) {
f4528696
JP
369 WL_NONE("Changing short slot:\t%s\n",
370 info->use_short_slot ? "True" : "False");
a9533e7e
HP
371 if (info->use_short_slot)
372 val = 1;
373 else
374 val = 0;
375 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
376 /* slot timing changed */
377 }
378
379 if (changed & BSS_CHANGED_HT) {
f4528696 380 WL_NONE("%s: HT mode - Implement me\n", __func__);
a9533e7e
HP
381 /* 802.11n parameters changed */
382 }
383 if (changed & BSS_CHANGED_BASIC_RATES) {
f4528696
JP
384 WL_NONE("Need to change Basic Rates:\t0x%x! Implement me\n",
385 (u32) info->basic_rates);
a9533e7e
HP
386 /* Basic rateset changed */
387 }
388 if (changed & BSS_CHANGED_BEACON_INT) {
f4528696
JP
389 WL_NONE("Beacon Interval:\t%d Implement me\n",
390 info->beacon_int);
a9533e7e
HP
391 /* Beacon interval changed */
392 }
393 if (changed & BSS_CHANGED_BSSID) {
f4528696
JP
394 WL_NONE("new BSSID:\taid %d bss:%pM\n",
395 info->aid, info->bssid);
a9533e7e
HP
396 /* BSSID changed, for whatever reason (IBSS and managed mode) */
397 /* FIXME: need to store bssid in bsscfg */
398 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
a44d4236 399 info->bssid);
a9533e7e
HP
400 }
401 if (changed & BSS_CHANGED_BEACON) {
f4528696 402 WL_ERROR("BSS_CHANGED_BEACON\n");
a9533e7e
HP
403 /* Beacon data changed, retrieve new beacon (beaconing modes) */
404 }
405 if (changed & BSS_CHANGED_BEACON_ENABLED) {
f4528696
JP
406 WL_ERROR("Beacon enabled:\t%s\n",
407 info->enable_beacon ? "True" : "False");
a9533e7e
HP
408 /* Beaconing should be enabled/disabled (beaconing modes) */
409 }
a9533e7e
HP
410 return;
411}
412
413static void
414wl_ops_configure_filter(struct ieee80211_hw *hw,
415 unsigned int changed_flags,
416 unsigned int *total_flags, u64 multicast)
417{
2cb22a7a 418 struct wl_info *wl = hw->priv;
a9533e7e
HP
419
420 changed_flags &= MAC_FILTERS;
421 *total_flags &= MAC_FILTERS;
422 if (changed_flags & FIF_PROMISC_IN_BSS)
f4528696 423 WL_ERROR("FIF_PROMISC_IN_BSS\n");
a9533e7e 424 if (changed_flags & FIF_ALLMULTI)
f4528696 425 WL_ERROR("FIF_ALLMULTI\n");
a9533e7e 426 if (changed_flags & FIF_FCSFAIL)
f4528696 427 WL_ERROR("FIF_FCSFAIL\n");
a9533e7e 428 if (changed_flags & FIF_PLCPFAIL)
f4528696 429 WL_ERROR("FIF_PLCPFAIL\n");
a9533e7e 430 if (changed_flags & FIF_CONTROL)
f4528696 431 WL_ERROR("FIF_CONTROL\n");
a9533e7e 432 if (changed_flags & FIF_OTHER_BSS)
f4528696 433 WL_ERROR("FIF_OTHER_BSS\n");
a9533e7e 434 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
f4528696 435 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
a9533e7e
HP
436 WL_LOCK(wl);
437 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
438 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
439 wlc_mac_bcn_promisc_change(wl->wlc, 1);
440 } else {
441 wlc_mac_bcn_promisc_change(wl->wlc, 0);
442 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
443 }
444 WL_UNLOCK(wl);
a9533e7e
HP
445 }
446 return;
447}
448
449static int
450wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
451{
f4528696 452 WL_ERROR("%s: Enter\n", __func__);
a9533e7e
HP
453 return 0;
454}
455
456static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
457{
f4528696 458 WL_NONE("Scan Start\n");
a9533e7e
HP
459 return;
460}
461
462static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
463{
f4528696 464 WL_NONE("Scan Complete\n");
a9533e7e
HP
465 return;
466}
467
468static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
469{
f4528696 470 WL_ERROR("%s: Enter\n", __func__);
a9533e7e
HP
471 return;
472}
473
474static int
475wl_ops_get_stats(struct ieee80211_hw *hw,
476 struct ieee80211_low_level_stats *stats)
477{
f4528696 478 WL_ERROR("%s: Enter\n", __func__);
a9533e7e
HP
479 return 0;
480}
481
482static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
483{
f4528696 484 WL_ERROR("%s: Enter\n", __func__);
a9533e7e
HP
485 return 0;
486}
487
488static void
489wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
490 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
491{
f4528696 492 WL_NONE("%s: Enter\n", __func__);
a9533e7e
HP
493 switch (cmd) {
494 default:
f4528696 495 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
a9533e7e
HP
496 break;
497 }
498 return;
499}
500
501static int
502wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
503 const struct ieee80211_tx_queue_params *params)
504{
2cb22a7a 505 struct wl_info *wl = hw->priv;
a9533e7e 506
f4528696
JP
507 WL_NONE("%s: Enter (WME config)\n", __func__);
508 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
509 params->txop, params->cw_min, params->cw_max, params->aifs);
a9533e7e
HP
510
511 WL_LOCK(wl);
0f0881b0 512 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
a9533e7e
HP
513 WL_UNLOCK(wl);
514
515 return 0;
516}
517
518static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
519{
f4528696 520 WL_ERROR("%s: Enter\n", __func__);
a9533e7e
HP
521 return 0;
522}
523
524static int
525wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
526 struct ieee80211_sta *sta)
527{
528 struct scb *scb;
529
530 int i;
2cb22a7a 531 struct wl_info *wl = hw->priv;
a9533e7e
HP
532
533 /* Init the scb */
534 scb = (struct scb *)sta->drv_priv;
9249ede9 535 memset(scb, 0, sizeof(struct scb));
a9533e7e
HP
536 for (i = 0; i < NUMPRIO; i++)
537 scb->seqctl[i] = 0xFFFF;
538 scb->seqctl_nonqos = 0xFFFF;
539 scb->magic = SCB_MAGIC;
540
541 wl->pub->global_scb = scb;
542 wl->pub->global_ampdu = &(scb->scb_ampdu);
543 wl->pub->global_ampdu->scb = scb;
a9533e7e 544 wl->pub->global_ampdu->max_pdu = 16;
a9533e7e
HP
545 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
546 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
547
0f0881b0 548 sta->ht_cap.ht_supported = true;
a9533e7e 549 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
a9533e7e
HP
550 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
551 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
552 IEEE80211_HT_CAP_SGI_20 |
553 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
554
555 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
556 return 0;
557}
558
559static int
560wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
561 struct ieee80211_sta *sta)
562{
f4528696 563 WL_NONE("%s: Enter\n", __func__);
a9533e7e
HP
564 return 0;
565}
566
567static int
568wl_ampdu_action(struct ieee80211_hw *hw,
569 struct ieee80211_vif *vif,
570 enum ieee80211_ampdu_mlme_action action,
7cc4a4c0 571 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
a9533e7e
HP
572{
573#if defined(BCMDBG)
574 struct scb *scb = (struct scb *)sta->drv_priv;
575#endif
2cb22a7a 576 struct wl_info *wl = hw->priv;
a9533e7e
HP
577
578 ASSERT(scb->magic == SCB_MAGIC);
579 switch (action) {
580 case IEEE80211_AMPDU_RX_START:
f4528696 581 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
a9533e7e
HP
582 break;
583 case IEEE80211_AMPDU_RX_STOP:
f4528696 584 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
a9533e7e
HP
585 break;
586 case IEEE80211_AMPDU_TX_START:
587 if (!wlc_aggregatable(wl->wlc, tid)) {
f4528696 588 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
a9533e7e
HP
589 return -1;
590 }
591 /* XXX: Use the starting sequence number provided ... */
592 *ssn = 0;
593 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
594 break;
595
596 case IEEE80211_AMPDU_TX_STOP:
597 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
598 break;
599 case IEEE80211_AMPDU_TX_OPERATIONAL:
600 /* Not sure what to do here */
601 /* Power save wakeup */
f4528696
JP
602 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
603 __func__);
a9533e7e
HP
604 break;
605 default:
f4528696 606 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
a9533e7e
HP
607 }
608
609 return 0;
610}
611
612static const struct ieee80211_ops wl_ops = {
a9533e7e 613 .tx = wl_ops_tx,
a9533e7e
HP
614 .start = wl_ops_start,
615 .stop = wl_ops_stop,
616 .add_interface = wl_ops_add_interface,
617 .remove_interface = wl_ops_remove_interface,
618 .config = wl_ops_config,
619 .bss_info_changed = wl_ops_bss_info_changed,
620 .configure_filter = wl_ops_configure_filter,
621 .set_tim = wl_ops_set_tim,
622 .sw_scan_start = wl_ops_sw_scan_start,
623 .sw_scan_complete = wl_ops_sw_scan_complete,
624 .set_tsf = wl_ops_set_tsf,
625 .get_stats = wl_ops_get_stats,
626 .set_rts_threshold = wl_ops_set_rts_threshold,
627 .sta_notify = wl_ops_sta_notify,
628 .conf_tx = wl_ops_conf_tx,
629 .get_tsf = wl_ops_get_tsf,
630 .sta_add = wl_sta_add,
631 .sta_remove = wl_sta_remove,
632 .ampdu_action = wl_ampdu_action,
633};
634
2cb22a7a 635static int wl_set_hint(struct wl_info *wl, char *abbrev)
a9533e7e 636{
f4528696
JP
637 WL_ERROR("%s: Sending country code %c%c to MAC80211\n",
638 __func__, abbrev[0], abbrev[1]);
90ea2296 639 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
a9533e7e
HP
640}
641
642/**
643 * attach to the WL device.
644 *
645 * Attach to the WL device identified by vendor and device parameters.
646 * regs is a host accessible memory address pointing to WL device registers.
647 *
648 * wl_attach is not defined as static because in the case where no bus
649 * is defined, wl_attach will never be called, and thus, gcc will issue
650 * a warning that this function is defined but not used if we declare
651 * it as static.
652 */
2cb22a7a 653static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
a9533e7e
HP
654 uint bustype, void *btparam, uint irq)
655{
2cb22a7a 656 struct wl_info *wl;
e69284f2 657 struct osl_info *osh;
a9533e7e
HP
658 int unit, err;
659
3deea904 660 unsigned long base_addr;
a9533e7e 661 struct ieee80211_hw *hw;
41feb5ed 662 u8 perm[ETH_ALEN];
a9533e7e 663
06fc8846 664 unit = wl_found;
a9533e7e
HP
665 err = 0;
666
667 if (unit < 0) {
f4528696 668 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
a9533e7e
HP
669 return NULL;
670 }
671
997dd24f 672 osh = osl_attach(btparam, bustype);
a9533e7e
HP
673 ASSERT(osh);
674
a9533e7e
HP
675 /* allocate private info */
676 hw = pci_get_drvdata(btparam); /* btparam == pdev */
677 wl = hw->priv;
a9533e7e
HP
678 ASSERT(wl);
679
a9533e7e
HP
680 wl->osh = osh;
681 atomic_set(&wl->callbacks, 0);
682
eb4764c3 683 /* setup the bottom half handler */
3deea904 684 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
eb4764c3 685
a9533e7e 686
a9533e7e
HP
687
688 base_addr = regs;
689
690 if (bustype == PCI_BUS) {
06fc8846 691 wl->piomode = false;
a9533e7e
HP
692 } else if (bustype == RPC_BUS) {
693 /* Do nothing */
694 } else {
695 bustype = PCI_BUS;
f4528696 696 WL_TRACE("force to PCI\n");
a9533e7e
HP
697 }
698 wl->bcm_bustype = bustype;
699
ca8c1e59
JC
700 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
701 if (wl->regsva == NULL) {
f4528696 702 WL_ERROR("wl%d: ioremap() failed\n", unit);
a9533e7e
HP
703 goto fail;
704 }
a9533e7e
HP
705 spin_lock_init(&wl->lock);
706 spin_lock_init(&wl->isr_lock);
a9533e7e 707
a9533e7e
HP
708 /* prepare ucode */
709 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
683b505b
BR
710 printf("%s: Failed to find firmware usually in %s\n",
711 KBUILD_MODNAME, "/lib/firmware/brcm");
712 wl_release_fw(wl);
713 wl_remove((struct pci_dev *)btparam);
714 goto fail1;
a9533e7e 715 }
a9533e7e
HP
716
717 /* common load-time initialization */
eb4764c3
BH
718 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
719 wl->regsva, wl->bcm_bustype, btparam, &err);
eb4764c3 720 wl_release_fw(wl);
eb4764c3 721 if (!wl->wlc) {
4766ae6c
BR
722 printf("%s: wlc_attach() failed with code %d\n",
723 KBUILD_MODNAME, err);
a9533e7e
HP
724 goto fail;
725 }
a9533e7e
HP
726 wl->pub = wlc_pub(wl->wlc);
727
728 wl->pub->ieee_hw = hw;
729 ASSERT(wl->pub->ieee_hw);
730 ASSERT(wl->pub->ieee_hw->priv == wl);
731
a9533e7e 732
06fc8846 733 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
f4528696 734 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
a9533e7e 735 }
a9533e7e 736
a9533e7e
HP
737 /* register our interrupt handler */
738 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
f4528696 739 WL_ERROR("wl%d: request_irq() failed\n", unit);
a9533e7e
HP
740 goto fail;
741 }
742 wl->irq = irq;
a9533e7e
HP
743
744 /* register module */
745 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
746 NULL);
747
748 if (ieee_hw_init(hw)) {
f4528696 749 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
a9533e7e
HP
750 goto fail;
751 }
752
b8d63078 753 bcopy(&wl->pub->cur_etheraddr, perm, ETH_ALEN);
a9533e7e
HP
754 ASSERT(is_valid_ether_addr(perm));
755 SET_IEEE80211_PERM_ADDR(hw, perm);
756
757 err = ieee80211_register_hw(hw);
758 if (err) {
f4528696
JP
759 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
760 __func__, err);
a9533e7e
HP
761 }
762
763 if (wl->pub->srom_ccode[0])
764 err = wl_set_hint(wl, wl->pub->srom_ccode);
765 else
766 err = wl_set_hint(wl, "US");
767 if (err) {
f4528696
JP
768 WL_ERROR("%s: regulatory_hint failed, status %d\n",
769 __func__, err);
a9533e7e 770 }
f4528696
JP
771 WL_ERROR("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver (" PHY_VERSION_STR ")",
772 unit);
a9533e7e
HP
773
774#ifdef BCMDBG
06fc8846 775 printf(" (Compiled at " __TIME__ " on " __DATE__ ")");
a9533e7e
HP
776#endif /* BCMDBG */
777 printf("\n");
778
a9533e7e
HP
779 wl_found++;
780 return wl;
781
782 fail:
783 wl_free(wl);
9e56568a 784fail1:
a9533e7e
HP
785 return NULL;
786}
787
a9533e7e 788
a9533e7e
HP
789
790#define CHAN2GHZ(channel, freqency, chflags) { \
791 .band = IEEE80211_BAND_2GHZ, \
792 .center_freq = (freqency), \
793 .hw_value = (channel), \
794 .flags = chflags, \
795 .max_antenna_gain = 0, \
796 .max_power = 19, \
797}
798
799static struct ieee80211_channel wl_2ghz_chantable[] = {
800 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
801 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
802 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
803 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
804 CHAN2GHZ(5, 2432, 0),
805 CHAN2GHZ(6, 2437, 0),
806 CHAN2GHZ(7, 2442, 0),
807 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
808 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
809 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
810 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
811 CHAN2GHZ(12, 2467,
812 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
813 IEEE80211_CHAN_NO_HT40PLUS),
814 CHAN2GHZ(13, 2472,
815 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
816 IEEE80211_CHAN_NO_HT40PLUS),
817 CHAN2GHZ(14, 2484,
818 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
819 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
820};
821
822#define CHAN5GHZ(channel, chflags) { \
823 .band = IEEE80211_BAND_5GHZ, \
824 .center_freq = 5000 + 5*(channel), \
825 .hw_value = (channel), \
826 .flags = chflags, \
827 .max_antenna_gain = 0, \
828 .max_power = 21, \
829}
830
831static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
832 /* UNII-1 */
833 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
834 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
835 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
836 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
837 /* UNII-2 */
838 CHAN5GHZ(52,
839 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
840 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
841 CHAN5GHZ(56,
842 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
843 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
844 CHAN5GHZ(60,
845 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
846 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
847 CHAN5GHZ(64,
848 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
849 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
850 /* MID */
851 CHAN5GHZ(100,
852 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
853 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
854 CHAN5GHZ(104,
855 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
856 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
857 CHAN5GHZ(108,
858 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
859 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
860 CHAN5GHZ(112,
861 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
862 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
863 CHAN5GHZ(116,
864 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
865 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
866 CHAN5GHZ(120,
867 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
868 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
869 CHAN5GHZ(124,
870 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
871 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
872 CHAN5GHZ(128,
873 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
874 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
875 CHAN5GHZ(132,
876 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
877 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
878 CHAN5GHZ(136,
879 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
880 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
881 CHAN5GHZ(140,
882 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
883 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
884 IEEE80211_CHAN_NO_HT40MINUS),
885 /* UNII-3 */
886 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
887 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
888 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
889 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
890 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
891};
892
893#define RATE(rate100m, _flags) { \
894 .bitrate = (rate100m), \
895 .flags = (_flags), \
896 .hw_value = (rate100m / 5), \
897}
898
899static struct ieee80211_rate wl_legacy_ratetable[] = {
900 RATE(10, 0),
901 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
902 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
903 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
904 RATE(60, 0),
905 RATE(90, 0),
906 RATE(120, 0),
907 RATE(180, 0),
908 RATE(240, 0),
909 RATE(360, 0),
910 RATE(480, 0),
911 RATE(540, 0),
912};
913
914static struct ieee80211_supported_band wl_band_2GHz_nphy = {
915 .band = IEEE80211_BAND_2GHZ,
916 .channels = wl_2ghz_chantable,
917 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
918 .bitrates = wl_legacy_ratetable,
919 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
920 .ht_cap = {
921 /* from include/linux/ieee80211.h */
922 .cap = IEEE80211_HT_CAP_GRN_FLD |
923 IEEE80211_HT_CAP_SGI_20 |
924 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
a9533e7e
HP
925 .ht_supported = true,
926 .ampdu_factor = AMPDU_RX_FACTOR_64K,
a9533e7e
HP
927 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
928 .mcs = {
929 /* placeholders for now */
a9533e7e
HP
930 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
931 .rx_highest = 500,
a9533e7e
HP
932 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
933 }
934};
935
936static struct ieee80211_supported_band wl_band_5GHz_nphy = {
937 .band = IEEE80211_BAND_5GHZ,
938 .channels = wl_5ghz_nphy_chantable,
939 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
940 .bitrates = wl_legacy_ratetable + 4,
941 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
942 .ht_cap = {
943 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
944 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT, /* No 40 mhz yet */
945 .ht_supported = true,
946 .ampdu_factor = AMPDU_RX_FACTOR_64K,
947 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
948 .mcs = {
949 /* placeholders for now */
950 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
951 .rx_highest = 500,
952 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
953 }
954};
955
956static int ieee_hw_rate_init(struct ieee80211_hw *hw)
957{
2cb22a7a 958 struct wl_info *wl = HW_TO_WL(hw);
a9533e7e
HP
959 int has_5g;
960 char phy_list[4];
961
962 has_5g = 0;
963
964 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
965 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
966
967 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
f4528696 968 WL_ERROR("Phy list failed\n");
a9533e7e 969 }
f4528696 970 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
a9533e7e 971
a9533e7e
HP
972 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
973 if (phy_list[0] == 'c') {
974 /* Single stream */
975 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
976 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
977 }
a9533e7e
HP
978 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
979 } else {
980 BUG();
90ea2296 981 return -1;
a9533e7e
HP
982 }
983
984 /* Assume all bands use the same phy. True for 11n devices. */
985 if (NBANDS_PUB(wl->pub) > 1) {
986 has_5g++;
a9533e7e 987 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
a9533e7e
HP
988 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
989 &wl_band_5GHz_nphy;
990 } else {
90ea2296 991 return -1;
a9533e7e
HP
992 }
993 }
994
f4528696 995 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
a9533e7e 996
90ea2296 997 return 0;
a9533e7e
HP
998}
999
1000static int ieee_hw_init(struct ieee80211_hw *hw)
1001{
1002 hw->flags = IEEE80211_HW_SIGNAL_DBM
1003 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1004 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1005 | IEEE80211_HW_AMPDU_AGGREGATION;
1006
1007 hw->extra_tx_headroom = wlc_get_header_len();
1008 /* FIXME: should get this from wlc->machwcap */
1009 hw->queues = 4;
1010 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1011 * mac80211/status.c:ieee80211_tx_status() checks this value,
1012 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1013 * appears to always set 3 rates
1014 */
1015 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1016
1017 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1018 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1019
1020 hw->rate_control_algorithm = "minstrel_ht";
1021
1022 hw->sta_data_size = sizeof(struct scb);
90ea2296 1023 return ieee_hw_rate_init(hw);
a9533e7e
HP
1024}
1025
a9533e7e
HP
1026/**
1027 * determines if a device is a WL device, and if so, attaches it.
1028 *
1029 * This function determines if a device pointed to by pdev is a WL device,
1030 * and if so, performs a wl_attach() on it.
1031 *
1032 */
1033int __devinit
1034wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1035{
1036 int rc;
2cb22a7a 1037 struct wl_info *wl;
a9533e7e 1038 struct ieee80211_hw *hw;
66cbd3ab 1039 u32 val;
a9533e7e
HP
1040
1041 ASSERT(pdev);
1042
f4528696
JP
1043 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1044 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1045 PCI_FUNC(pdev->devfn), pdev->irq);
a9533e7e
HP
1046
1047 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1048 (((pdev->device & 0xff00) != 0x4300) &&
1049 ((pdev->device & 0xff00) != 0x4700) &&
1050 ((pdev->device < 43000) || (pdev->device > 43999))))
90ea2296 1051 return -ENODEV;
a9533e7e
HP
1052
1053 rc = pci_enable_device(pdev);
1054 if (rc) {
f4528696
JP
1055 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1056 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1057 PCI_FUNC(pdev->devfn));
90ea2296 1058 return -ENODEV;
a9533e7e
HP
1059 }
1060 pci_set_master(pdev);
1061
1062 pci_read_config_dword(pdev, 0x40, &val);
1063 if ((val & 0x0000ff00) != 0)
1064 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1065
2cb22a7a 1066 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
a9533e7e 1067 if (!hw) {
f4528696 1068 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
a9533e7e
HP
1069 rc = -ENOMEM;
1070 goto err_1;
1071 }
1072
1073 SET_IEEE80211_DEV(hw, &pdev->dev);
1074
1075 pci_set_drvdata(pdev, hw);
1076
9249ede9 1077 memset(hw->priv, 0, sizeof(*wl));
a9533e7e
HP
1078
1079 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1080 PCI_BUS, pdev, pdev->irq);
1081
683b505b 1082 if (!wl) {
f4528696
JP
1083 WL_ERROR("%s: %s: wl_attach failed!\n",
1084 KBUILD_MODNAME, __func__);
683b505b
BR
1085 return -ENODEV;
1086 }
a9533e7e
HP
1087 return 0;
1088 err_1:
f4528696 1089 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
a9533e7e
HP
1090 return 0;
1091}
1092
1093#ifdef LINUXSTA_PS
878a6673 1094static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
a9533e7e 1095{
2cb22a7a 1096 struct wl_info *wl;
a9533e7e
HP
1097 struct ieee80211_hw *hw;
1098
f4528696 1099 WL_TRACE("wl: wl_suspend\n");
a9533e7e
HP
1100
1101 hw = pci_get_drvdata(pdev);
1102 wl = HW_TO_WL(hw);
1103 if (!wl) {
f4528696 1104 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
a9533e7e
HP
1105 return -ENODEV;
1106 }
1107
1108 WL_LOCK(wl);
1109 wl_down(wl);
0965ae88 1110 wl->pub->hw_up = false;
a9533e7e 1111 WL_UNLOCK(wl);
8ba9cfdb 1112 pci_save_state(pdev, wl->pci_psstate);
a9533e7e
HP
1113 pci_disable_device(pdev);
1114 return pci_set_power_state(pdev, PCI_D3hot);
1115}
1116
1117static int wl_resume(struct pci_dev *pdev)
1118{
2cb22a7a 1119 struct wl_info *wl;
a9533e7e
HP
1120 struct ieee80211_hw *hw;
1121 int err = 0;
66cbd3ab 1122 u32 val;
a9533e7e 1123
f4528696 1124 WL_TRACE("wl: wl_resume\n");
a9533e7e
HP
1125 hw = pci_get_drvdata(pdev);
1126 wl = HW_TO_WL(hw);
1127 if (!wl) {
f4528696 1128 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
a9533e7e
HP
1129 return -ENODEV;
1130 }
1131
1132 err = pci_set_power_state(pdev, PCI_D0);
1133 if (err)
1134 return err;
1135
8ba9cfdb 1136 pci_restore_state(pdev, wl->pci_psstate);
a9533e7e
HP
1137
1138 err = pci_enable_device(pdev);
1139 if (err)
1140 return err;
1141
1142 pci_set_master(pdev);
1143
1144 pci_read_config_dword(pdev, 0x40, &val);
1145 if ((val & 0x0000ff00) != 0)
1146 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1147
1148 WL_LOCK(wl);
1149 err = wl_up(wl);
1150 WL_UNLOCK(wl);
1151
90ea2296 1152 return err;
a9533e7e
HP
1153}
1154#endif /* LINUXSTA_PS */
1155
6f0c5bcd 1156static void wl_remove(struct pci_dev *pdev)
a9533e7e 1157{
2cb22a7a 1158 struct wl_info *wl;
a9533e7e
HP
1159 struct ieee80211_hw *hw;
1160
1161 hw = pci_get_drvdata(pdev);
1162 wl = HW_TO_WL(hw);
1163 if (!wl) {
f4528696 1164 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
a9533e7e
HP
1165 return;
1166 }
1167 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
f4528696 1168 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
a9533e7e
HP
1169 return;
1170 }
683b505b
BR
1171 if (wl->wlc) {
1172 ieee80211_unregister_hw(hw);
1173 WL_LOCK(wl);
1174 wl_down(wl);
1175 WL_UNLOCK(wl);
f4528696 1176 WL_NONE("%s: Down\n", __func__);
683b505b 1177 }
a9533e7e
HP
1178 pci_disable_device(pdev);
1179
1180 wl_free(wl);
1181
1182 pci_set_drvdata(pdev, NULL);
1183 ieee80211_free_hw(hw);
1184}
1185
1186static struct pci_driver wl_pci_driver = {
5fee2540
JC
1187 .name = "brcm80211",
1188 .probe = wl_pci_probe,
a9533e7e 1189#ifdef LINUXSTA_PS
5fee2540
JC
1190 .suspend = wl_suspend,
1191 .resume = wl_resume,
a9533e7e 1192#endif /* LINUXSTA_PS */
5fee2540
JC
1193 .remove = __devexit_p(wl_remove),
1194 .id_table = wl_id_table,
a9533e7e 1195};
a9533e7e
HP
1196
1197/**
1198 * This is the main entry point for the WL driver.
1199 *
1200 * This function determines if a device pointed to by pdev is a WL device,
1201 * and if so, performs a wl_attach() on it.
1202 *
1203 */
1204static int __init wl_module_init(void)
1205{
1206 int error = -ENODEV;
1207
1208#ifdef BCMDBG
1209 if (msglevel != 0xdeadbeef)
1210 wl_msg_level = msglevel;
1211 else {
1212 char *var = getvar(NULL, "wl_msglevel");
1213 if (var)
48c51a8c 1214 wl_msg_level = simple_strtoul(var, NULL, 0);
a9533e7e 1215 }
a9533e7e 1216 {
66cbd3ab 1217 extern u32 phyhal_msg_level;
a9533e7e
HP
1218
1219 if (phymsglevel != 0xdeadbeef)
1220 phyhal_msg_level = phymsglevel;
1221 else {
1222 char *var = getvar(NULL, "phy_msglevel");
1223 if (var)
48c51a8c 1224 phyhal_msg_level = simple_strtoul(var, NULL, 0);
a9533e7e
HP
1225 }
1226 }
a9533e7e
HP
1227#endif /* BCMDBG */
1228
8ba9cfdb 1229 error = pci_register_driver(&wl_pci_driver);
ca8c1e59 1230 if (!error)
90ea2296 1231 return 0;
a9533e7e 1232
a9533e7e 1233
a9533e7e 1234
90ea2296 1235 return error;
a9533e7e
HP
1236}
1237
1238/**
1239 * This function unloads the WL driver from the system.
1240 *
1241 * This function unconditionally unloads the WL driver module from the
1242 * system.
1243 *
1244 */
1245static void __exit wl_module_exit(void)
1246{
a9533e7e 1247 pci_unregister_driver(&wl_pci_driver);
a9533e7e 1248
a9533e7e
HP
1249}
1250
1251module_init(wl_module_init);
1252module_exit(wl_module_exit);
1253
1254/**
1255 * This function frees the WL per-device resources.
1256 *
1257 * This function frees resources owned by the WL device pointed to
1258 * by the wl parameter.
1259 *
1260 */
2cb22a7a 1261void wl_free(struct wl_info *wl)
a9533e7e
HP
1262{
1263 wl_timer_t *t, *next;
e69284f2 1264 struct osl_info *osh;
a9533e7e
HP
1265
1266 ASSERT(wl);
a9533e7e
HP
1267 /* free ucode data */
1268 if (wl->fw.fw_cnt)
1269 wl_ucode_data_free();
a9533e7e
HP
1270 if (wl->irq)
1271 free_irq(wl->irq, wl);
a9533e7e
HP
1272
1273 /* kill dpc */
1274 tasklet_kill(&wl->tasklet);
1275
1276 if (wl->pub) {
1277 wlc_module_unregister(wl->pub, "linux", wl);
1278 }
1279
1280 /* free common resources */
1281 if (wl->wlc) {
1282 wlc_detach(wl->wlc);
1283 wl->wlc = NULL;
1284 wl->pub = NULL;
1285 }
1286
1287 /* virtual interface deletion is deferred so we cannot spinwait */
1288
1289 /* wait for all pending callbacks to complete */
1290 while (atomic_read(&wl->callbacks) > 0)
1291 schedule();
1292
1293 /* free timers */
1294 for (t = wl->timers; t; t = next) {
1295 next = t->next;
1296#ifdef BCMDBG
1297 if (t->name)
182acb3c 1298 kfree(t->name);
a9533e7e 1299#endif
182acb3c 1300 kfree(t);
a9533e7e
HP
1301 }
1302
a9533e7e
HP
1303 osh = wl->osh;
1304
1305 /*
1306 * unregister_netdev() calls get_stats() which may read chip registers
1307 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1308 */
fa7a1db2
BR
1309 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1310 wl->bcm_bustype != JTAG_BUS) {
a9533e7e
HP
1311 iounmap((void *)wl->regsva);
1312 }
1313 wl->regsva = NULL;
1314
a9533e7e 1315
a9533e7e
HP
1316 osl_detach(osh);
1317}
1318
a9533e7e 1319/* transmit a packet */
2cb22a7a 1320static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
a9533e7e
HP
1321{
1322 if (!wl)
1323 return -ENETDOWN;
1324
1325 return wl_start_int(wl, WL_TO_HW(wl), skb);
1326}
a9533e7e
HP
1327
1328static int BCMFASTPATH
2cb22a7a 1329wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
a9533e7e 1330{
a9533e7e 1331 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
90ea2296 1332 return NETDEV_TX_OK;
a9533e7e
HP
1333}
1334
2cb22a7a
RV
1335void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1336 int prio)
a9533e7e 1337{
f4528696 1338 WL_ERROR("Shouldn't be here %s\n", __func__);
a9533e7e
HP
1339}
1340
2cb22a7a 1341void wl_init(struct wl_info *wl)
a9533e7e 1342{
f4528696 1343 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
a9533e7e
HP
1344
1345 wl_reset(wl);
1346
1347 wlc_init(wl->wlc);
1348}
1349
2cb22a7a 1350uint wl_reset(struct wl_info *wl)
a9533e7e 1351{
f4528696 1352 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
a9533e7e
HP
1353
1354 wlc_reset(wl->wlc);
1355
1356 /* dpc will not be rescheduled */
1357 wl->resched = 0;
1358
90ea2296 1359 return 0;
a9533e7e
HP
1360}
1361
1362/*
1363 * These are interrupt on/off entry points. Disable interrupts
1364 * during interrupt state transition.
1365 */
2cb22a7a 1366void BCMFASTPATH wl_intrson(struct wl_info *wl)
a9533e7e 1367{
a9533e7e
HP
1368 unsigned long flags;
1369
1370 INT_LOCK(wl, flags);
1371 wlc_intrson(wl->wlc);
1372 INT_UNLOCK(wl, flags);
a9533e7e
HP
1373}
1374
2cb22a7a 1375bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
a9533e7e 1376{
0f0881b0 1377 return true;
a9533e7e
HP
1378}
1379
2cb22a7a 1380u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
a9533e7e 1381{
a9533e7e 1382 unsigned long flags;
66cbd3ab 1383 u32 status;
a9533e7e
HP
1384
1385 INT_LOCK(wl, flags);
1386 status = wlc_intrsoff(wl->wlc);
1387 INT_UNLOCK(wl, flags);
1388 return status;
a9533e7e
HP
1389}
1390
2cb22a7a 1391void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
a9533e7e 1392{
a9533e7e
HP
1393 unsigned long flags;
1394
1395 INT_LOCK(wl, flags);
1396 wlc_intrsrestore(wl->wlc, macintmask);
1397 INT_UNLOCK(wl, flags);
a9533e7e
HP
1398}
1399
2cb22a7a 1400int wl_up(struct wl_info *wl)
a9533e7e
HP
1401{
1402 int error = 0;
1403
1404 if (wl->pub->up)
90ea2296 1405 return 0;
a9533e7e
HP
1406
1407 error = wlc_up(wl->wlc);
1408
90ea2296 1409 return error;
a9533e7e
HP
1410}
1411
2cb22a7a 1412void wl_down(struct wl_info *wl)
a9533e7e
HP
1413{
1414 uint callbacks, ret_val = 0;
1415
1416 /* call common down function */
1417 ret_val = wlc_down(wl->wlc);
1418 callbacks = atomic_read(&wl->callbacks) - ret_val;
1419
1420 /* wait for down callbacks to complete */
1421 WL_UNLOCK(wl);
1422
a9533e7e
HP
1423 /* For HIGH_only driver, it's important to actually schedule other work,
1424 * not just spin wait since everything runs at schedule level
1425 */
1426 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
a9533e7e
HP
1427
1428 WL_LOCK(wl);
1429}
1430
1431irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1432{
2cb22a7a 1433 struct wl_info *wl;
a9533e7e
HP
1434 bool ours, wantdpc;
1435 unsigned long flags;
1436
2cb22a7a 1437 wl = (struct wl_info *) dev_id;
a9533e7e
HP
1438
1439 WL_ISRLOCK(wl, flags);
1440
1441 /* call common first level interrupt handler */
ca8c1e59
JC
1442 ours = wlc_isr(wl->wlc, &wantdpc);
1443 if (ours) {
a9533e7e
HP
1444 /* if more to do... */
1445 if (wantdpc) {
1446
1447 /* ...and call the second level interrupt handler */
1448 /* schedule dpc */
0965ae88 1449 ASSERT(wl->resched == false);
a9533e7e
HP
1450 tasklet_schedule(&wl->tasklet);
1451 }
1452 }
1453
1454 WL_ISRUNLOCK(wl, flags);
1455
1456 return IRQ_RETVAL(ours);
a9533e7e
HP
1457}
1458
3deea904 1459static void BCMFASTPATH wl_dpc(unsigned long data)
a9533e7e 1460{
2cb22a7a 1461 struct wl_info *wl;
a9533e7e 1462
2cb22a7a 1463 wl = (struct wl_info *) data;
a9533e7e
HP
1464
1465 WL_LOCK(wl);
1466
1467 /* call the common second level interrupt handler */
1468 if (wl->pub->up) {
1469 if (wl->resched) {
1470 unsigned long flags;
1471
1472 INT_LOCK(wl, flags);
1473 wlc_intrsupd(wl->wlc);
1474 INT_UNLOCK(wl, flags);
1475 }
1476
0f0881b0 1477 wl->resched = wlc_dpc(wl->wlc, true);
a9533e7e
HP
1478 }
1479
1480 /* wlc_dpc() may bring the driver down */
1481 if (!wl->pub->up)
1482 goto done;
1483
1484 /* re-schedule dpc */
1485 if (wl->resched)
1486 tasklet_schedule(&wl->tasklet);
1487 else {
1488 /* re-enable interrupts */
1489 wl_intrson(wl);
1490 }
1491
1492 done:
1493 WL_UNLOCK(wl);
a9533e7e
HP
1494}
1495
2cb22a7a 1496static void wl_link_up(struct wl_info *wl, char *ifname)
a9533e7e 1497{
f4528696 1498 WL_ERROR("wl%d: link up (%s)\n", wl->pub->unit, ifname);
a9533e7e
HP
1499}
1500
2cb22a7a 1501static void wl_link_down(struct wl_info *wl, char *ifname)
a9533e7e 1502{
f4528696 1503 WL_ERROR("wl%d: link down (%s)\n", wl->pub->unit, ifname);
a9533e7e
HP
1504}
1505
2cb22a7a 1506void wl_event(struct wl_info *wl, char *ifname, wlc_event_t *e)
a9533e7e
HP
1507{
1508
1509 switch (e->event.event_type) {
1510 case WLC_E_LINK:
1511 case WLC_E_NDIS_LINK:
1512 if (e->event.flags & WLC_EVENT_MSG_LINK)
1513 wl_link_up(wl, ifname);
1514 else
1515 wl_link_down(wl, ifname);
1516 break;
1517 case WLC_E_RADIO:
1518 break;
1519 }
1520}
1521
3deea904 1522static void wl_timer(unsigned long data)
a9533e7e 1523{
a9533e7e 1524 _wl_timer((wl_timer_t *) data);
a9533e7e
HP
1525}
1526
7cc4a4c0 1527static void _wl_timer(wl_timer_t *t)
a9533e7e
HP
1528{
1529 WL_LOCK(t->wl);
1530
1531 if (t->set) {
1532 if (t->periodic) {
1533 t->timer.expires = jiffies + t->ms * HZ / 1000;
1534 atomic_inc(&t->wl->callbacks);
1535 add_timer(&t->timer);
0f0881b0 1536 t->set = true;
a9533e7e 1537 } else
0965ae88 1538 t->set = false;
a9533e7e
HP
1539
1540 t->fn(t->arg);
1541 }
1542
1543 atomic_dec(&t->wl->callbacks);
1544
1545 WL_UNLOCK(t->wl);
1546}
1547
2cb22a7a 1548wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
a9533e7e
HP
1549 const char *name)
1550{
1551 wl_timer_t *t;
1552
5fcc1fcb 1553 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
ca8c1e59 1554 if (!t) {
f4528696 1555 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
a9533e7e
HP
1556 return 0;
1557 }
1558
9249ede9 1559 memset(t, 0, sizeof(wl_timer_t));
a9533e7e
HP
1560
1561 init_timer(&t->timer);
3deea904 1562 t->timer.data = (unsigned long) t;
a9533e7e
HP
1563 t->timer.function = wl_timer;
1564 t->wl = wl;
1565 t->fn = fn;
1566 t->arg = arg;
1567 t->next = wl->timers;
1568 wl->timers = t;
1569
1570#ifdef BCMDBG
5fcc1fcb 1571 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
ca8c1e59 1572 if (t->name)
a9533e7e
HP
1573 strcpy(t->name, name);
1574#endif
1575
1576 return t;
1577}
1578
1579/* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1580 * as well as it's easier to make it periodic
1581 */
2cb22a7a 1582void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
a9533e7e
HP
1583{
1584#ifdef BCMDBG
1585 if (t->set) {
f4528696
JP
1586 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1587 __func__, t->name, periodic);
a9533e7e
HP
1588 }
1589#endif
1590 ASSERT(!t->set);
1591
1592 t->ms = ms;
1593 t->periodic = (bool) periodic;
0f0881b0 1594 t->set = true;
a9533e7e
HP
1595 t->timer.expires = jiffies + ms * HZ / 1000;
1596
1597 atomic_inc(&wl->callbacks);
1598 add_timer(&t->timer);
1599}
1600
0965ae88 1601/* return true if timer successfully deleted, false if still pending */
2cb22a7a 1602bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
a9533e7e
HP
1603{
1604 if (t->set) {
0965ae88 1605 t->set = false;
a9533e7e 1606 if (!del_timer(&t->timer)) {
0965ae88 1607 return false;
a9533e7e
HP
1608 }
1609 atomic_dec(&wl->callbacks);
1610 }
1611
0f0881b0 1612 return true;
a9533e7e
HP
1613}
1614
2cb22a7a 1615void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
a9533e7e
HP
1616{
1617 wl_timer_t *tmp;
1618
1619 /* delete the timer in case it is active */
1620 wl_del_timer(wl, t);
1621
1622 if (wl->timers == t) {
1623 wl->timers = wl->timers->next;
1624#ifdef BCMDBG
1625 if (t->name)
182acb3c 1626 kfree(t->name);
a9533e7e 1627#endif
182acb3c 1628 kfree(t);
a9533e7e
HP
1629 return;
1630
1631 }
1632
1633 tmp = wl->timers;
1634 while (tmp) {
1635 if (tmp->next == t) {
1636 tmp->next = t->next;
1637#ifdef BCMDBG
1638 if (t->name)
182acb3c 1639 kfree(t->name);
a9533e7e 1640#endif
182acb3c 1641 kfree(t);
a9533e7e
HP
1642 return;
1643 }
1644 tmp = tmp->next;
1645 }
1646
1647}
1648
1649static int wl_linux_watchdog(void *ctx)
1650{
2cb22a7a 1651 struct wl_info *wl = (struct wl_info *) ctx;
a9533e7e
HP
1652 struct net_device_stats *stats = NULL;
1653 uint id;
1654 /* refresh stats */
1655 if (wl->pub->up) {
1656 ASSERT(wl->stats_id < 2);
1657
1658 id = 1 - wl->stats_id;
1659
1660 stats = &wl->stats_watchdog[id];
1661 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
1662 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
1663 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
1664 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
1665 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
1666 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
1667 stats->collisions = 0;
1668
1669 stats->rx_length_errors = 0;
1670 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1671 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
1672 stats->rx_frame_errors = 0;
1673 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1674 stats->rx_missed_errors = 0;
1675
1676 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
1677
1678 wl->stats_id = id;
1679
1680 }
1681
1682 return 0;
1683}
1684
1685struct wl_fw_hdr {
66cbd3ab
GKH
1686 u32 offset;
1687 u32 len;
1688 u32 idx;
a9533e7e
HP
1689};
1690
a9533e7e
HP
1691char *wl_firmwares[WL_MAX_FW] = {
1692 "brcm/bcm43xx",
1693 NULL
1694};
1695
2cb22a7a 1696int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
a9533e7e
HP
1697{
1698 int i, entry;
41feb5ed 1699 const u8 *pdata;
a9533e7e
HP
1700 struct wl_fw_hdr *hdr;
1701 for (i = 0; i < wl->fw.fw_cnt; i++) {
1702 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1703 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1704 entry++, hdr++) {
1705 if (hdr->idx == idx) {
1706 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1707 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1708 if (*pbuf == NULL) {
1709 printf("fail to alloc %d bytes\n",
1710 hdr->len);
1711 }
1712 bcopy(pdata, *pbuf, hdr->len);
1713 return 0;
1714 }
1715 }
1716 }
1717 printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
1718 *pbuf = NULL;
1719 return -1;
1720}
1721
2cb22a7a 1722int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
a9533e7e
HP
1723{
1724 int i, entry;
41feb5ed 1725 const u8 *pdata;
a9533e7e
HP
1726 struct wl_fw_hdr *hdr;
1727 for (i = 0; i < wl->fw.fw_cnt; i++) {
1728 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1729 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1730 entry++, hdr++) {
1731 if (hdr->idx == idx) {
1732 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1733 ASSERT(hdr->len == 4);
66cbd3ab 1734 *data = *((u32 *) pdata);
a9533e7e
HP
1735 return 0;
1736 }
1737 }
1738 }
1739 printf("ERROR: ucode tag:%d can not be found!\n", idx);
1740 return -1;
1741}
a9533e7e 1742
2cb22a7a 1743static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
a9533e7e
HP
1744{
1745 int status;
1746 struct device *device = &pdev->dev;
1747 char fw_name[100];
1748 int i;
1749
9249ede9 1750 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
a9533e7e
HP
1751 for (i = 0; i < WL_MAX_FW; i++) {
1752 if (wl_firmwares[i] == NULL)
1753 break;
1754 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1755 UCODE_LOADER_API_VER);
f4528696 1756 WL_NONE("request fw %s\n", fw_name);
a9533e7e
HP
1757 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1758 if (status) {
683b505b
BR
1759 printf("%s: fail to load firmware %s\n",
1760 KBUILD_MODNAME, fw_name);
eb4764c3 1761 wl_release_fw(wl);
a9533e7e
HP
1762 return status;
1763 }
f4528696 1764 WL_NONE("request fw %s\n", fw_name);
a9533e7e
HP
1765 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1766 UCODE_LOADER_API_VER);
1767 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1768 if (status) {
683b505b
BR
1769 printf("%s: fail to load firmware %s\n",
1770 KBUILD_MODNAME, fw_name);
eb4764c3 1771 wl_release_fw(wl);
a9533e7e
HP
1772 return status;
1773 }
1774 wl->fw.hdr_num_entries[i] =
1775 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
f4528696
JP
1776 WL_NONE("request fw %s find: %d entries\n",
1777 fw_name, wl->fw.hdr_num_entries[i]);
a9533e7e
HP
1778 }
1779 wl->fw.fw_cnt = i;
3d44661a 1780 return wl_ucode_data_init(wl);
a9533e7e
HP
1781}
1782
a9533e7e
HP
1783void wl_ucode_free_buf(void *p)
1784{
1785 kfree(p);
1786}
a9533e7e 1787
2cb22a7a 1788static void wl_release_fw(struct wl_info *wl)
a9533e7e
HP
1789{
1790 int i;
eb4764c3 1791 for (i = 0; i < WL_MAX_FW; i++) {
a9533e7e
HP
1792 release_firmware(wl->fw.fw_bin[i]);
1793 release_firmware(wl->fw.fw_hdr[i]);
1794 }
1795}
3d44661a
RV
1796
1797
1798/*
1799 * checks validity of all firmware images loaded from user space
1800 */
1801int wl_check_firmwares(struct wl_info *wl)
1802{
1803 int i;
1804 int entry;
1805 int rc = 0;
1806 const struct firmware *fw;
1807 const struct firmware *fw_hdr;
1808 struct wl_fw_hdr *ucode_hdr;
1809 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1810 fw = wl->fw.fw_bin[i];
1811 fw_hdr = wl->fw.fw_hdr[i];
1812 if (fw == NULL && fw_hdr == NULL) {
1813 break;
1814 } else if (fw == NULL || fw_hdr == NULL) {
f4528696 1815 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
3d44661a
RV
1816 rc = -EBADF;
1817 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
f4528696
JP
1818 WL_ERROR("%s: non integral fw hdr file size %d/%zu\n",
1819 __func__, fw_hdr->size,
1820 sizeof(struct wl_fw_hdr));
3d44661a
RV
1821 rc = -EBADF;
1822 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
f4528696
JP
1823 WL_ERROR("%s: out of bounds fw file size %d\n",
1824 __func__, fw->size);
3d44661a
RV
1825 rc = -EBADF;
1826 } else {
1827 /* check if ucode section overruns firmware image */
1828 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1829 for (entry = 0; entry < wl->fw.hdr_num_entries[i] && rc;
1830 entry++, ucode_hdr++) {
1831 if (ucode_hdr->offset + ucode_hdr->len >
1832 fw->size) {
f4528696
JP
1833 WL_ERROR("%s: conflicting bin/hdr\n",
1834 __func__);
3d44661a
RV
1835 rc = -EBADF;
1836 }
1837 }
1838 }
1839 }
1840 if (rc == 0 && wl->fw.fw_cnt != i) {
f4528696 1841 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
3d44661a
RV
1842 rc = -EBADF;
1843 }
1844 return rc;
1845}
1846