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