]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - drivers/staging/brcm80211/sys/wl_mac80211.c
staging: brcm80211: Separate fullmac vs softmac defs in shared file
[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>
32#include <epivers.h>
33#ifndef WLC_HIGH_ONLY
34#include <phy_version.h>
35#endif
a9533e7e
HP
36#include <bcmutils.h>
37#include <pcicfg.h>
38#include <wlioctl.h>
39#include <wlc_key.h>
a52ba66c
BR
40#include <sbhndpio.h>
41#include <sbhnddma.h>
a9533e7e
HP
42#include <wlc_channel.h>
43#include <wlc_pub.h>
44#include <wlc_scb.h>
45#include <wl_dbg.h>
46#ifdef BCMSDIO
47#include <bcmsdh.h>
48#endif
49#include <wl_export.h>
50#ifdef WLC_HIGH_ONLY
51#include "dbus.h"
52#include "bcm_rpc_tp.h"
53#include "bcm_rpc.h"
54#include "bcm_xdr.h"
55#include "wlc_rpc.h"
56#endif
57
58#include <wl_mac80211.h>
59#include <linux/firmware.h>
60#ifndef WLC_HIGH_ONLY
61#include <wl_ucode.h>
62#include <d11ucode_ext.h>
63#endif
64
65#ifdef BCMSDIO
66extern struct device *sdiommc_dev;
67#endif
68
7cc4a4c0 69extern void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg,
a9533e7e 70 bool suspend);
7cc4a4c0
JC
71bool wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw);
72void wlc_mac_bcn_promisc_change(wlc_info_t *wlc, bool promisc);
73void wlc_set_addrmatch(wlc_info_t *wlc, int match_reg_offset,
a9533e7e
HP
74 const struct ether_addr *addr);
75
3deea904 76static void wl_timer(unsigned long data);
7cc4a4c0 77static void _wl_timer(wl_timer_t *t);
a9533e7e 78
a9533e7e
HP
79#ifdef WLC_HIGH_ONLY
80#define RPCQ_LOCK(_wl, _flags) spin_lock_irqsave(&(_wl)->rpcq_lock, (_flags))
81#define RPCQ_UNLOCK(_wl, _flags) spin_unlock_irqrestore(&(_wl)->rpcq_lock, (_flags))
82#define TXQ_LOCK(_wl, _flags) spin_lock_irqsave(&(_wl)->txq_lock, (_flags))
83#define TXQ_UNLOCK(_wl, _flags) spin_unlock_irqrestore(&(_wl)->txq_lock, (_flags))
84static void wl_rpc_down(void *wlh);
7cc4a4c0 85static void wl_rpcq_free(wl_info_t *wl);
a9533e7e
HP
86static void wl_rpcq_dispatch(struct wl_task *task);
87static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf);
88static void wl_start_txqwork(struct wl_task *task);
7cc4a4c0
JC
89static void wl_txq_free(wl_info_t *wl);
90static void wl_timer_task(wl_task_t *task);
91static int wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *),
a9533e7e
HP
92 void *context);
93#endif /* WLC_HIGH_ONLY */
94
95static int ieee_hw_init(struct ieee80211_hw *hw);
96static int ieee_hw_rate_init(struct ieee80211_hw *hw);
97
98static int wl_linux_watchdog(void *ctx);
99
100/* Flags we support */
101#define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
102 FIF_ALLMULTI | \
103 FIF_FCSFAIL | \
104 FIF_PLCPFAIL | \
105 FIF_CONTROL | \
106 FIF_OTHER_BSS | \
107 FIF_BCN_PRBRESP_PROMISC)
108
7e85c729 109static int wl_found;
a9533e7e
HP
110
111struct ieee80211_tkip_data {
112#define TKIP_KEY_LEN 32
113 u8 key[TKIP_KEY_LEN];
114 int key_set;
115
116 u32 tx_iv32;
117 u16 tx_iv16;
118 u16 tx_ttak[5];
119 int tx_phase1_done;
120
121 u32 rx_iv32;
122 u16 rx_iv16;
123 u16 rx_ttak[5];
124 int rx_phase1_done;
125 u32 rx_iv32_new;
126 u16 rx_iv16_new;
127
128 u32 dot11RSNAStatsTKIPReplays;
129 u32 dot11RSNAStatsTKIPICVErrors;
130 u32 dot11RSNAStatsTKIPLocalMICFailures;
131
132 int key_idx;
133
134 struct crypto_tfm *tfm_arc4;
135 struct crypto_tfm *tfm_michael;
136
137 /* scratch buffers for virt_to_page() (crypto API) */
138 u8 rx_hdr[16], tx_hdr[16];
139};
140
141#ifndef WLC_HIGH_ONLY
1a3bf747 142#define WL_DEV_IF(dev) ((wl_if_t *)netdev_priv(dev))
39dcff3f 143#define WL_INFO(dev) ((wl_info_t *)(WL_DEV_IF(dev)->wl)) /* points to wl */
7cc4a4c0
JC
144static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev);
145static void wl_release_fw(wl_info_t *wl);
a9533e7e
HP
146#endif
147
148/* local prototypes */
7cc4a4c0
JC
149static int wl_start(struct sk_buff *skb, wl_info_t *wl);
150static int wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw,
a9533e7e 151 struct sk_buff *skb);
3deea904 152static void wl_dpc(unsigned long data);
a9533e7e
HP
153
154MODULE_AUTHOR("Broadcom Corporation");
155MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
156MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
157MODULE_LICENSE("Dual BSD/GPL");
158
159#ifndef BCMSDIO
160/* recognized PCI IDs */
161static struct pci_device_id wl_id_table[] = {
162 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
163 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
164 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
165 {0}
166};
167
168MODULE_DEVICE_TABLE(pci, wl_id_table);
6f0c5bcd 169static void wl_remove(struct pci_dev *pdev);
a9533e7e
HP
170#endif /* !BCMSDIO */
171
172#ifdef BCMSDIO
173static uint sd_drivestrength = 6;
174module_param(sd_drivestrength, uint, 0);
175#endif
176
177#ifdef BCMDBG
178static int msglevel = 0xdeadbeef;
179module_param(msglevel, int, 0);
180#ifndef WLC_HIGH_ONLY
181static int phymsglevel = 0xdeadbeef;
182module_param(phymsglevel, int, 0);
183#endif /* WLC_HIGH_ONLY */
184#endif /* BCMDBG */
185
7e85c729 186static int oneonly;
a9533e7e
HP
187module_param(oneonly, int, 0);
188
7e85c729 189static int piomode;
a9533e7e
HP
190module_param(piomode, int, 0);
191
7e85c729 192static int instance_base; /* Starting instance number */
a9533e7e
HP
193module_param(instance_base, int, 0);
194
195#if defined(BCMDBG)
7e85c729 196static char *macaddr;
a9533e7e
HP
197module_param(macaddr, charp, S_IRUGO);
198#endif
199
200static int nompc = 1;
201module_param(nompc, int, 0);
202
203static char name[IFNAMSIZ] = "eth%d";
204module_param_string(name, name, IFNAMSIZ, 0);
205
206#ifndef SRCBASE
207#define SRCBASE "."
208#endif
209
210#define WL_MAGIC 0xdeadbeef
211
0d706ef4
JC
212#define HW_TO_WL(hw) (hw->priv)
213#define WL_TO_HW(wl) (wl->pub->ieee_hw)
a9533e7e
HP
214#ifdef WLC_HIGH_ONLY
215static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb);
216#else
217static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
218#endif
219static int wl_ops_start(struct ieee80211_hw *hw);
220static void wl_ops_stop(struct ieee80211_hw *hw);
221static int wl_ops_add_interface(struct ieee80211_hw *hw,
222 struct ieee80211_vif *vif);
223static void wl_ops_remove_interface(struct ieee80211_hw *hw,
224 struct ieee80211_vif *vif);
225static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
226static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
227 struct ieee80211_vif *vif,
228 struct ieee80211_bss_conf *info,
229 u32 changed);
230static void wl_ops_configure_filter(struct ieee80211_hw *hw,
231 unsigned int changed_flags,
232 unsigned int *total_flags, u64 multicast);
233static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
234 bool set);
235static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
236static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
237static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
238static int wl_ops_get_stats(struct ieee80211_hw *hw,
239 struct ieee80211_low_level_stats *stats);
240static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
241static void wl_ops_sta_notify(struct ieee80211_hw *hw,
242 struct ieee80211_vif *vif,
243 enum sta_notify_cmd cmd,
244 struct ieee80211_sta *sta);
245static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
246 const struct ieee80211_tx_queue_params *params);
247static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
248static int wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
249 struct ieee80211_sta *sta);
250static int wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
251 struct ieee80211_sta *sta);
252static int wl_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
253 enum ieee80211_ampdu_mlme_action action,
7cc4a4c0 254 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
a9533e7e
HP
255
256#ifdef WLC_HIGH_ONLY
257static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb)
258{
259 int status;
260 wl_info_t *wl = hw->priv;
261 if (!wl->pub->up) {
262 WL_ERROR(("ops->tx called while down\n"));
263 status = -ENETDOWN;
264 goto done;
265 }
266 status = wl_start(skb, wl);
267 done:
268 return status;
269}
270#else
271static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
272{
273 int status;
274 wl_info_t *wl = hw->priv;
275 WL_LOCK(wl);
276 if (!wl->pub->up) {
277 WL_ERROR(("ops->tx called while down\n"));
278 status = -ENETDOWN;
279 goto done;
280 }
281 status = wl_start(skb, wl);
282 done:
283 WL_UNLOCK(wl);
284 return status;
285}
286#endif /* WLC_HIGH_ONLY */
287
288static int wl_ops_start(struct ieee80211_hw *hw)
289{
290 wl_info_t *wl = hw->priv;
291 /* struct ieee80211_channel *curchan = hw->conf.channel; */
292 WL_NONE(("%s : Initial channel: %d\n", __func__, curchan->hw_value));
293
294 WL_LOCK(wl);
295 ieee80211_wake_queues(hw);
296 WL_UNLOCK(wl);
297
298 return 0;
299}
300
301static void wl_ops_stop(struct ieee80211_hw *hw)
302{
303 wl_info_t *wl = hw->priv;
304 ASSERT(wl);
305 WL_LOCK(wl);
306 wl_down(wl);
307 ieee80211_stop_queues(hw);
308 WL_UNLOCK(wl);
309
310 return;
311}
312
313static int
314wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
315{
316 wl_info_t *wl;
317 int err;
318
319 /* Just STA for now */
320 if (vif->type != NL80211_IFTYPE_AP &&
321 vif->type != NL80211_IFTYPE_MESH_POINT &&
322 vif->type != NL80211_IFTYPE_STATION &&
323 vif->type != NL80211_IFTYPE_WDS &&
324 vif->type != NL80211_IFTYPE_ADHOC) {
325 WL_ERROR(("%s: Attempt to add type %d, only STA for now\n",
326 __func__, vif->type));
327 return -EOPNOTSUPP;
328 }
329
330 wl = HW_TO_WL(hw);
331 WL_LOCK(wl);
332 err = wl_up(wl);
333 WL_UNLOCK(wl);
334
335 if (err != 0)
336 WL_ERROR(("%s: wl_up() returned %d\n", __func__, err));
337 return err;
338}
339
340static void
341wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
342{
343 return;
344}
345
346static int
347ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
348 enum nl80211_channel_type type)
349{
350 wl_info_t *wl = HW_TO_WL(hw);
351 int err = 0;
352
353 switch (type) {
354 case NL80211_CHAN_HT20:
355 case NL80211_CHAN_NO_HT:
356 WL_LOCK(wl);
357 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
358 WL_UNLOCK(wl);
359 break;
360 case NL80211_CHAN_HT40MINUS:
361 case NL80211_CHAN_HT40PLUS:
362 WL_ERROR(("%s: Need to implement 40 Mhz Channels!\n",
363 __func__));
364 break;
365 }
366
367 if (err)
368 return -EIO;
369 return err;
370}
371
372static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
373{
374 struct ieee80211_conf *conf = &hw->conf;
375 wl_info_t *wl = HW_TO_WL(hw);
376 int err = 0;
377 int new_int;
378
379 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
380 WL_NONE(("%s: Setting listen interval to %d\n",
381 __func__, conf->listen_interval));
382 if (wlc_iovar_setint
383 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
384 WL_ERROR(("%s: Error setting listen_interval\n",
385 __func__));
386 err = -EIO;
387 goto config_out;
388 }
389 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
390 ASSERT(new_int == conf->listen_interval);
391 }
392 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
393 WL_NONE(("Need to set monitor mode\n"));
394 if (changed & IEEE80211_CONF_CHANGE_PS)
395 WL_NONE(("Need to set Power-save mode\n"));
396
397 if (changed & IEEE80211_CONF_CHANGE_POWER) {
398 WL_NONE(("%s: Setting tx power to %d dbm\n", __func__,
399 conf->power_level));
400 if (wlc_iovar_setint
401 (wl->wlc, "qtxpower", conf->power_level * 4)) {
402 WL_ERROR(("%s: Error setting power_level\n", __func__));
403 err = -EIO;
404 goto config_out;
405 }
406 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
407 if (new_int != (conf->power_level * 4))
408 WL_ERROR(("%s: Power level req != actual, %d %d\n",
409 __func__, conf->power_level * 4, new_int));
410 }
411 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
412 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
413 }
414 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
415 WL_NONE(("%s: srl %d, lrl %d\n", __func__,
416 conf->short_frame_max_tx_count,
417 conf->long_frame_max_tx_count));
418 if (wlc_set
419 (wl->wlc, WLC_SET_SRL,
420 conf->short_frame_max_tx_count) < 0) {
421 WL_ERROR(("%s: Error setting srl\n", __func__));
422 err = -EIO;
423 goto config_out;
424 }
425 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
426 < 0) {
427 WL_ERROR(("%s: Error setting lrl\n", __func__));
428 err = -EIO;
429 goto config_out;
430 }
431 }
432
433 config_out:
434 return err;
435}
436
437static void
438wl_ops_bss_info_changed(struct ieee80211_hw *hw,
439 struct ieee80211_vif *vif,
440 struct ieee80211_bss_conf *info, u32 changed)
441{
442 wl_info_t *wl = HW_TO_WL(hw);
443 int val;
444
445#ifdef WLC_HIGH_ONLY
446 WL_LOCK(wl);
447#endif
448
449 if (changed & BSS_CHANGED_ASSOC) {
450 WL_ERROR(("Associated:\t%s\n", info->assoc ? "True" : "False"));
451 /* association status changed (associated/disassociated)
452 * also implies a change in the AID.
453 */
454 }
455 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
456 WL_NONE(("Use_cts_prot:\t%s Implement me\n",
457 info->use_cts_prot ? "True" : "False"));
458 /* CTS protection changed */
459 }
460 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
461 WL_NONE(("Short preamble:\t%s Implement me\n",
462 info->use_short_preamble ? "True" : "False"));
463 /* preamble changed */
464 }
465 if (changed & BSS_CHANGED_ERP_SLOT) {
466 WL_NONE(("Changing short slot:\t%s\n",
467 info->use_short_slot ? "True" : "False"));
468 if (info->use_short_slot)
469 val = 1;
470 else
471 val = 0;
472 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
473 /* slot timing changed */
474 }
475
476 if (changed & BSS_CHANGED_HT) {
477 WL_NONE(("%s: HT mode - Implement me\n", __func__));
478 /* 802.11n parameters changed */
479 }
480 if (changed & BSS_CHANGED_BASIC_RATES) {
481 WL_NONE(("Need to change Basic Rates:\t0x%x! Implement me\n",
66cbd3ab 482 (u32) info->basic_rates));
a9533e7e
HP
483 /* Basic rateset changed */
484 }
485 if (changed & BSS_CHANGED_BEACON_INT) {
486 WL_NONE(("Beacon Interval:\t%d Implement me\n",
487 info->beacon_int));
488 /* Beacon interval changed */
489 }
490 if (changed & BSS_CHANGED_BSSID) {
ba07d0cb
AS
491 WL_NONE(("new BSSID:\taid %d bss:%pM\n", info->aid,
492 info->bssid));
a9533e7e
HP
493 /* BSSID changed, for whatever reason (IBSS and managed mode) */
494 /* FIXME: need to store bssid in bsscfg */
495 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
496 (struct ether_addr *)info->bssid);
497 }
498 if (changed & BSS_CHANGED_BEACON) {
499 WL_ERROR(("BSS_CHANGED_BEACON\n"));
500 /* Beacon data changed, retrieve new beacon (beaconing modes) */
501 }
502 if (changed & BSS_CHANGED_BEACON_ENABLED) {
503 WL_ERROR(("Beacon enabled:\t%s\n",
504 info->enable_beacon ? "True" : "False"));
505 /* Beaconing should be enabled/disabled (beaconing modes) */
506 }
507#ifdef WLC_HIGH_ONLY
508 WL_UNLOCK(wl);
509#endif
510 return;
511}
512
513static void
514wl_ops_configure_filter(struct ieee80211_hw *hw,
515 unsigned int changed_flags,
516 unsigned int *total_flags, u64 multicast)
517{
518#ifndef WLC_HIGH_ONLY
519 wl_info_t *wl = hw->priv;
520#endif
521
522 changed_flags &= MAC_FILTERS;
523 *total_flags &= MAC_FILTERS;
524 if (changed_flags & FIF_PROMISC_IN_BSS)
525 WL_ERROR(("FIF_PROMISC_IN_BSS\n"));
526 if (changed_flags & FIF_ALLMULTI)
527 WL_ERROR(("FIF_ALLMULTI\n"));
528 if (changed_flags & FIF_FCSFAIL)
529 WL_ERROR(("FIF_FCSFAIL\n"));
530 if (changed_flags & FIF_PLCPFAIL)
531 WL_ERROR(("FIF_PLCPFAIL\n"));
532 if (changed_flags & FIF_CONTROL)
533 WL_ERROR(("FIF_CONTROL\n"));
534 if (changed_flags & FIF_OTHER_BSS)
535 WL_ERROR(("FIF_OTHER_BSS\n"));
536 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
537 WL_NONE(("FIF_BCN_PRBRESP_PROMISC\n"));
538#ifndef WLC_HIGH_ONLY
539 WL_LOCK(wl);
540 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
541 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
542 wlc_mac_bcn_promisc_change(wl->wlc, 1);
543 } else {
544 wlc_mac_bcn_promisc_change(wl->wlc, 0);
545 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
546 }
547 WL_UNLOCK(wl);
548#endif
549 }
550 return;
551}
552
553static int
554wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
555{
556 WL_ERROR(("%s: Enter\n", __func__));
557 return 0;
558}
559
560static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
561{
562 WL_NONE(("Scan Start\n"));
563 return;
564}
565
566static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
567{
568 WL_NONE(("Scan Complete\n"));
569 return;
570}
571
572static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
573{
574 WL_ERROR(("%s: Enter\n", __func__));
575 return;
576}
577
578static int
579wl_ops_get_stats(struct ieee80211_hw *hw,
580 struct ieee80211_low_level_stats *stats)
581{
582 WL_ERROR(("%s: Enter\n", __func__));
583 return 0;
584}
585
586static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
587{
588 WL_ERROR(("%s: Enter\n", __func__));
589 return 0;
590}
591
592static void
593wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
594 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
595{
596 WL_NONE(("%s: Enter\n", __func__));
597 switch (cmd) {
598 default:
599 WL_ERROR(("%s: Uknown cmd = %d\n", __func__, cmd));
600 break;
601 }
602 return;
603}
604
605static int
606wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
607 const struct ieee80211_tx_queue_params *params)
608{
609 wl_info_t *wl = hw->priv;
610
611 WL_NONE(("%s: Enter (WME config)\n", __func__));
612 WL_NONE(("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
613 params->txop, params->cw_min, params->cw_max, params->aifs));
614
615 WL_LOCK(wl);
0f0881b0 616 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
a9533e7e
HP
617 WL_UNLOCK(wl);
618
619 return 0;
620}
621
622static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
623{
624 WL_ERROR(("%s: Enter\n", __func__));
625 return 0;
626}
627
628static int
629wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
630 struct ieee80211_sta *sta)
631{
632 struct scb *scb;
633
634 int i;
635 wl_info_t *wl = hw->priv;
636
637 /* Init the scb */
638 scb = (struct scb *)sta->drv_priv;
639 bzero(scb, sizeof(struct scb));
640 for (i = 0; i < NUMPRIO; i++)
641 scb->seqctl[i] = 0xFFFF;
642 scb->seqctl_nonqos = 0xFFFF;
643 scb->magic = SCB_MAGIC;
644
645 wl->pub->global_scb = scb;
646 wl->pub->global_ampdu = &(scb->scb_ampdu);
647 wl->pub->global_ampdu->scb = scb;
648#ifdef WLC_HIGH_ONLY
649 wl->pub->global_ampdu->max_pdu = AMPDU_NUM_MPDU;
650#else
651 wl->pub->global_ampdu->max_pdu = 16;
652#endif
653 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
654 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
655
0f0881b0 656 sta->ht_cap.ht_supported = true;
a9533e7e
HP
657#ifdef WLC_HIGH_ONLY
658 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_16K;
659#else
660 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
661#endif
662 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
663 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
664 IEEE80211_HT_CAP_SGI_20 |
665 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
666
667 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
668 return 0;
669}
670
671static int
672wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
673 struct ieee80211_sta *sta)
674{
675 WL_NONE(("%s: Enter\n", __func__));
676 return 0;
677}
678
679static int
680wl_ampdu_action(struct ieee80211_hw *hw,
681 struct ieee80211_vif *vif,
682 enum ieee80211_ampdu_mlme_action action,
7cc4a4c0 683 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
a9533e7e
HP
684{
685#if defined(BCMDBG)
686 struct scb *scb = (struct scb *)sta->drv_priv;
687#endif
688 wl_info_t *wl = hw->priv;
689
690 ASSERT(scb->magic == SCB_MAGIC);
691 switch (action) {
692 case IEEE80211_AMPDU_RX_START:
693 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_START\n", __func__));
694 break;
695 case IEEE80211_AMPDU_RX_STOP:
696 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__));
697 break;
698 case IEEE80211_AMPDU_TX_START:
699 if (!wlc_aggregatable(wl->wlc, tid)) {
700 /* WL_ERROR(("START: tid %d is not agg' able, return FAILURE to stack\n", tid)); */
701 return -1;
702 }
703 /* XXX: Use the starting sequence number provided ... */
704 *ssn = 0;
705 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
706 break;
707
708 case IEEE80211_AMPDU_TX_STOP:
709 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
710 break;
711 case IEEE80211_AMPDU_TX_OPERATIONAL:
712 /* Not sure what to do here */
713 /* Power save wakeup */
714 WL_NONE(("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
715 __func__));
716 break;
717 default:
718 WL_ERROR(("%s: Invalid command, ignoring\n", __func__));
719 }
720
721 return 0;
722}
723
724static const struct ieee80211_ops wl_ops = {
725#ifdef WLC_HIGH_ONLY
726 .tx = wl_ops_tx_nl,
727#else
728 .tx = wl_ops_tx,
729#endif
730 .start = wl_ops_start,
731 .stop = wl_ops_stop,
732 .add_interface = wl_ops_add_interface,
733 .remove_interface = wl_ops_remove_interface,
734 .config = wl_ops_config,
735 .bss_info_changed = wl_ops_bss_info_changed,
736 .configure_filter = wl_ops_configure_filter,
737 .set_tim = wl_ops_set_tim,
738 .sw_scan_start = wl_ops_sw_scan_start,
739 .sw_scan_complete = wl_ops_sw_scan_complete,
740 .set_tsf = wl_ops_set_tsf,
741 .get_stats = wl_ops_get_stats,
742 .set_rts_threshold = wl_ops_set_rts_threshold,
743 .sta_notify = wl_ops_sta_notify,
744 .conf_tx = wl_ops_conf_tx,
745 .get_tsf = wl_ops_get_tsf,
746 .sta_add = wl_sta_add,
747 .sta_remove = wl_sta_remove,
748 .ampdu_action = wl_ampdu_action,
749};
750
7cc4a4c0 751static int wl_set_hint(wl_info_t *wl, char *abbrev)
a9533e7e
HP
752{
753 WL_ERROR(("%s: Sending country code %c%c to MAC80211\n", __func__,
754 abbrev[0], abbrev[1]));
90ea2296 755 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
a9533e7e
HP
756}
757
758/**
759 * attach to the WL device.
760 *
761 * Attach to the WL device identified by vendor and device parameters.
762 * regs is a host accessible memory address pointing to WL device registers.
763 *
764 * wl_attach is not defined as static because in the case where no bus
765 * is defined, wl_attach will never be called, and thus, gcc will issue
766 * a warning that this function is defined but not used if we declare
767 * it as static.
768 */
7d4df48e 769static wl_info_t *wl_attach(u16 vendor, u16 device, unsigned long regs,
a9533e7e
HP
770 uint bustype, void *btparam, uint irq)
771{
772 wl_info_t *wl;
773 osl_t *osh;
774 int unit, err;
775
3deea904 776 unsigned long base_addr;
a9533e7e 777 struct ieee80211_hw *hw;
41feb5ed 778 u8 perm[ETH_ALEN];
a9533e7e
HP
779
780 unit = wl_found + instance_base;
781 err = 0;
782
783 if (unit < 0) {
784 WL_ERROR(("wl%d: unit number overflow, exiting\n", unit));
785 return NULL;
786 }
787
788 if (oneonly && (unit != instance_base)) {
789 WL_ERROR(("wl%d: wl_attach: oneonly is set, exiting\n", unit));
790 return NULL;
791 }
792
793 /* Requires pkttag feature */
0f0881b0 794 osh = osl_attach(btparam, bustype, true);
a9533e7e
HP
795 ASSERT(osh);
796
797#ifdef WLC_HIGH_ONLY
798 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
799 if (!hw) {
800 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
801 ASSERT(0);
802 }
803
804 bzero(hw->priv, sizeof(*wl));
805 wl = hw->priv;
806#else
807 /* allocate private info */
808 hw = pci_get_drvdata(btparam); /* btparam == pdev */
809 wl = hw->priv;
810#endif
811 ASSERT(wl);
812
813 wl->magic = WL_MAGIC;
814 wl->osh = osh;
815 atomic_set(&wl->callbacks, 0);
816
eb4764c3 817 /* setup the bottom half handler */
3deea904 818 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
eb4764c3 819
a9533e7e
HP
820#ifdef WLC_HIGH_ONLY
821 wl->rpc_th = bcm_rpc_tp_attach(osh, NULL);
822 if (wl->rpc_th == NULL) {
823 WL_ERROR(("wl%d: %s: bcm_rpc_tp_attach failed!\n", unit,
824 __func__));
825 goto fail;
826 }
827
828 wl->rpc = bcm_rpc_attach(NULL, osh, wl->rpc_th);
829 if (wl->rpc == NULL) {
830 WL_ERROR(("wl%d: %s: bcm_rpc_attach failed!\n", unit,
831 __func__));
832 goto fail;
833 }
834
835 /* init tx work queue for wl_start/send pkt; no need to destroy workitem */
364eb72a 836 INIT_WORK(&wl->txq_task.work, (work_func_t) wl_start_txqwork);
a9533e7e
HP
837 wl->txq_task.context = wl;
838#endif /* WLC_HIGH_ONLY */
839
840#ifdef BCMSDIO
841 SET_IEEE80211_DEV(hw, sdiommc_dev);
842#endif
843
844 base_addr = regs;
845
846 if (bustype == PCI_BUS) {
847 /* piomode can be overwritten by command argument */
848 wl->piomode = piomode;
849 WL_TRACE(("PCI/%s\n", wl->piomode ? "PIO" : "DMA"));
850 } else if (bustype == RPC_BUS) {
851 /* Do nothing */
852 } else {
853 bustype = PCI_BUS;
854 WL_TRACE(("force to PCI\n"));
855 }
856 wl->bcm_bustype = bustype;
857
858#ifdef WLC_HIGH_ONLY
859 if (wl->bcm_bustype == RPC_BUS) {
860 wl->regsva = (void *)0;
861 btparam = wl->rpc;
862 } else
863#endif
ca8c1e59
JC
864 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
865 if (wl->regsva == NULL) {
a9533e7e
HP
866 WL_ERROR(("wl%d: ioremap() failed\n", unit));
867 goto fail;
868 }
869#ifdef WLC_HIGH_ONLY
870 spin_lock_init(&wl->rpcq_lock);
871 spin_lock_init(&wl->txq_lock);
872
45f4d024 873 sema_init(&wl->sem, 1);
a9533e7e
HP
874#else
875 spin_lock_init(&wl->lock);
876 spin_lock_init(&wl->isr_lock);
877#endif
878
879#ifndef WLC_HIGH_ONLY
880 /* prepare ucode */
881 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
683b505b
BR
882 printf("%s: Failed to find firmware usually in %s\n",
883 KBUILD_MODNAME, "/lib/firmware/brcm");
884 wl_release_fw(wl);
885 wl_remove((struct pci_dev *)btparam);
886 goto fail1;
a9533e7e
HP
887 }
888#endif
889
890 /* common load-time initialization */
eb4764c3
BH
891 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
892 wl->regsva, wl->bcm_bustype, btparam, &err);
893#ifndef WLC_HIGH_ONLY
894 wl_release_fw(wl);
895#endif
896 if (!wl->wlc) {
683b505b
BR
897 printf("%s: %s wlc_attach() failed with code %d\n",
898 KBUILD_MODNAME, EPI_VERSION_STR, err);
a9533e7e
HP
899 goto fail;
900 }
a9533e7e
HP
901 wl->pub = wlc_pub(wl->wlc);
902
903 wl->pub->ieee_hw = hw;
904 ASSERT(wl->pub->ieee_hw);
905 ASSERT(wl->pub->ieee_hw->priv == wl);
906
907#ifdef WLC_HIGH_ONLY
908 REGOPSSET(osh, (osl_rreg_fn_t) wlc_reg_read,
909 (osl_wreg_fn_t) wlc_reg_write, wl->wlc);
910 wl->rpc_dispatch_ctx.rpc = wl->rpc;
911 wl->rpc_dispatch_ctx.wlc = wl->wlc;
912 bcm_rpc_rxcb_init(wl->rpc, wl, wl_rpc_dispatch_schedule, wl,
913 wl_rpc_down, NULL, NULL);
914#endif /* WLC_HIGH_ONLY */
915
916 if (nompc) {
917 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
918 WL_ERROR(("wl%d: Error setting MPC variable to 0\n",
919 unit));
920 }
921 }
922#ifdef BCMSDIO
923 /* Set SDIO drive strength */
924 wlc_iovar_setint(wl->wlc, "sd_drivestrength", sd_drivestrength);
925#endif
926
a9533e7e
HP
927#ifdef WLC_LOW
928 /* register our interrupt handler */
929 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
930 WL_ERROR(("wl%d: request_irq() failed\n", unit));
931 goto fail;
932 }
933 wl->irq = irq;
934#endif /* WLC_LOW */
935
936 /* register module */
937 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
938 NULL);
939
940 if (ieee_hw_init(hw)) {
941 WL_ERROR(("wl%d: %s: ieee_hw_init failed!\n", unit, __func__));
942 goto fail;
943 }
944
945 bcopy(&wl->pub->cur_etheraddr, perm, ETHER_ADDR_LEN);
946 ASSERT(is_valid_ether_addr(perm));
947 SET_IEEE80211_PERM_ADDR(hw, perm);
948
949 err = ieee80211_register_hw(hw);
950 if (err) {
951 WL_ERROR(("%s: ieee80211_register_hw failed, status %d\n",
952 __func__, err));
953 }
954
955 if (wl->pub->srom_ccode[0])
956 err = wl_set_hint(wl, wl->pub->srom_ccode);
957 else
958 err = wl_set_hint(wl, "US");
959 if (err) {
960 WL_ERROR(("%s: regulatory_hint failed, status %d\n", __func__,
961 err));
962 }
963#ifndef WLC_HIGH_ONLY
964 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
965 EPI_VERSION_STR " (" PHY_VERSION_STR ")", unit));
966#else
967 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
968 EPI_VERSION_STR, unit));
969#endif
970
971#ifdef BCMDBG
972 printf(" (Compiled in " SRCBASE " at " __TIME__ " on " __DATE__ ")");
973#endif /* BCMDBG */
974 printf("\n");
975
a9533e7e
HP
976 wl_found++;
977 return wl;
978
979 fail:
980 wl_free(wl);
9e56568a 981fail1:
a9533e7e
HP
982 return NULL;
983}
984
a9533e7e 985#ifdef WLC_HIGH_ONLY
66cbd3ab
GKH
986static void *wl_dbus_probe_cb(void *arg, const char *desc, u32 bustype,
987 u32 hdrlen)
a9533e7e
HP
988{
989 wl_info_t *wl;
990 WL_ERROR(("%s:\n", __func__));
991
3deea904 992 wl = wl_attach(BCM_DNGL_VID, BCM_DNGL_BDC_PID, (unsigned long) NULL, RPC_BUS,
ca8c1e59
JC
993 NULL, 0);
994 if (!wl) {
a9533e7e
HP
995 WL_ERROR(("%s: wl_attach failed\n", __func__));
996 }
997
998 /* This is later passed to wl_dbus_disconnect_cb */
999 return wl;
1000}
1001
1002static void wl_dbus_disconnect_cb(void *arg)
1003{
1004 wl_info_t *wl = arg;
1005
1006 WL_ERROR(("%s:\n", __func__));
1007
1008 if (wl) {
1009#ifdef WLC_HIGH_ONLY
1010 if (wl->pub->ieee_hw) {
1011 ieee80211_unregister_hw(wl->pub->ieee_hw);
1012 WL_ERROR(("%s: Back from down\n", __func__));
1013 }
1014 wlc_device_removed(wl->wlc);
1015 wlc_bmac_dngl_reboot(wl->rpc);
1016 bcm_rpc_down(wl->rpc);
1017#endif
1018 WL_LOCK(wl);
1019 wl_down(wl);
1020 WL_UNLOCK(wl);
1021#ifdef WLC_HIGH_ONLY
1022 if (wl->pub->ieee_hw) {
1023 ieee80211_free_hw(wl->pub->ieee_hw);
1024 WL_ERROR(("%s: Back from ieee80211_free_hw\n",
1025 __func__));
1026 wl->pub->ieee_hw = NULL;
1027 }
1028#endif
1029 wl_free(wl);
1030 }
1031}
1032#endif /* WLC_HIGH_ONLY */
1033
a9533e7e
HP
1034
1035#define CHAN2GHZ(channel, freqency, chflags) { \
1036 .band = IEEE80211_BAND_2GHZ, \
1037 .center_freq = (freqency), \
1038 .hw_value = (channel), \
1039 .flags = chflags, \
1040 .max_antenna_gain = 0, \
1041 .max_power = 19, \
1042}
1043
1044static struct ieee80211_channel wl_2ghz_chantable[] = {
1045 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
1046 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
1047 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
1048 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
1049 CHAN2GHZ(5, 2432, 0),
1050 CHAN2GHZ(6, 2437, 0),
1051 CHAN2GHZ(7, 2442, 0),
1052 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
1053 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
1054 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
1055 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
1056 CHAN2GHZ(12, 2467,
1057 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1058 IEEE80211_CHAN_NO_HT40PLUS),
1059 CHAN2GHZ(13, 2472,
1060 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1061 IEEE80211_CHAN_NO_HT40PLUS),
1062 CHAN2GHZ(14, 2484,
1063 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1064 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
1065};
1066
1067#define CHAN5GHZ(channel, chflags) { \
1068 .band = IEEE80211_BAND_5GHZ, \
1069 .center_freq = 5000 + 5*(channel), \
1070 .hw_value = (channel), \
1071 .flags = chflags, \
1072 .max_antenna_gain = 0, \
1073 .max_power = 21, \
1074}
1075
1076static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
1077 /* UNII-1 */
1078 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
1079 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
1080 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
1081 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
1082 /* UNII-2 */
1083 CHAN5GHZ(52,
1084 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1085 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1086 CHAN5GHZ(56,
1087 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1088 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1089 CHAN5GHZ(60,
1090 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1091 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1092 CHAN5GHZ(64,
1093 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1094 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1095 /* MID */
1096 CHAN5GHZ(100,
1097 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1098 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1099 CHAN5GHZ(104,
1100 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1101 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1102 CHAN5GHZ(108,
1103 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1104 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1105 CHAN5GHZ(112,
1106 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1107 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1108 CHAN5GHZ(116,
1109 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1110 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1111 CHAN5GHZ(120,
1112 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1113 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1114 CHAN5GHZ(124,
1115 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1116 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1117 CHAN5GHZ(128,
1118 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1119 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1120 CHAN5GHZ(132,
1121 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1122 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1123 CHAN5GHZ(136,
1124 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1125 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1126 CHAN5GHZ(140,
1127 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1128 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
1129 IEEE80211_CHAN_NO_HT40MINUS),
1130 /* UNII-3 */
1131 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
1132 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
1133 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
1134 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
1135 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
1136};
1137
1138#define RATE(rate100m, _flags) { \
1139 .bitrate = (rate100m), \
1140 .flags = (_flags), \
1141 .hw_value = (rate100m / 5), \
1142}
1143
1144static struct ieee80211_rate wl_legacy_ratetable[] = {
1145 RATE(10, 0),
1146 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
1147 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
1148 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
1149 RATE(60, 0),
1150 RATE(90, 0),
1151 RATE(120, 0),
1152 RATE(180, 0),
1153 RATE(240, 0),
1154 RATE(360, 0),
1155 RATE(480, 0),
1156 RATE(540, 0),
1157};
1158
1159static struct ieee80211_supported_band wl_band_2GHz_nphy = {
1160 .band = IEEE80211_BAND_2GHZ,
1161 .channels = wl_2ghz_chantable,
1162 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
1163 .bitrates = wl_legacy_ratetable,
1164 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
1165 .ht_cap = {
1166 /* from include/linux/ieee80211.h */
1167 .cap = IEEE80211_HT_CAP_GRN_FLD |
1168 IEEE80211_HT_CAP_SGI_20 |
1169 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
1170#ifdef WLC_HIGH_ONLY
1171 .ht_supported = true,
1172 .ampdu_factor = AMPDU_RX_FACTOR_16K,
1173#else
1174 .ht_supported = true,
1175 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1176#endif
1177 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1178 .mcs = {
1179 /* placeholders for now */
1180#ifdef WLC_HIGH_ONLY
1181 /*
1182 * rx_mask[0] = 0xff by default
1183 * rx_mask[1] = 0xff if number of rx chain >=2
1184 * rx_mask[2] = 0xff if number of rx chain >=3
1185 * rx_mask[4] = 1 if 40Mhz is supported
1186 */
1187 .rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0},
1188 .rx_highest = 72, /* max rate of single stream */
1189#else
1190 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1191 .rx_highest = 500,
1192#endif
1193 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1194 }
1195};
1196
1197static struct ieee80211_supported_band wl_band_5GHz_nphy = {
1198 .band = IEEE80211_BAND_5GHZ,
1199 .channels = wl_5ghz_nphy_chantable,
1200 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
1201 .bitrates = wl_legacy_ratetable + 4,
1202 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1203 .ht_cap = {
1204 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1205 .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 */
1206 .ht_supported = true,
1207 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1208 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1209 .mcs = {
1210 /* placeholders for now */
1211 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1212 .rx_highest = 500,
1213 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1214 }
1215};
1216
1217static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1218{
1219 wl_info_t *wl = HW_TO_WL(hw);
1220 int has_5g;
1221 char phy_list[4];
1222
1223 has_5g = 0;
1224
1225 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1226 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1227
1228 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1229 WL_ERROR(("Phy list failed\n"));
1230 }
1231 WL_NONE(("%s: phylist = %c\n", __func__, phy_list[0]));
1232
1233#ifndef WLC_HIGH_ONLY
1234 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1235 if (phy_list[0] == 'c') {
1236 /* Single stream */
1237 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1238 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1239 }
1240#else
1241 if (phy_list[0] == 's') {
1242#endif
1243 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1244 } else {
1245 BUG();
90ea2296 1246 return -1;
a9533e7e
HP
1247 }
1248
1249 /* Assume all bands use the same phy. True for 11n devices. */
1250 if (NBANDS_PUB(wl->pub) > 1) {
1251 has_5g++;
1252#ifndef WLC_HIGH_ONLY
1253 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1254#else
1255 if (phy_list[0] == 's') {
1256#endif
1257 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1258 &wl_band_5GHz_nphy;
1259 } else {
90ea2296 1260 return -1;
a9533e7e
HP
1261 }
1262 }
1263
1264 WL_NONE(("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g));
1265
90ea2296 1266 return 0;
a9533e7e
HP
1267}
1268
1269static int ieee_hw_init(struct ieee80211_hw *hw)
1270{
1271 hw->flags = IEEE80211_HW_SIGNAL_DBM
1272 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1273 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1274 | IEEE80211_HW_AMPDU_AGGREGATION;
1275
1276 hw->extra_tx_headroom = wlc_get_header_len();
1277 /* FIXME: should get this from wlc->machwcap */
1278 hw->queues = 4;
1279 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1280 * mac80211/status.c:ieee80211_tx_status() checks this value,
1281 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1282 * appears to always set 3 rates
1283 */
1284 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1285
1286 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1287 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1288
1289 hw->rate_control_algorithm = "minstrel_ht";
1290
1291 hw->sta_data_size = sizeof(struct scb);
90ea2296 1292 return ieee_hw_rate_init(hw);
a9533e7e
HP
1293}
1294
1295#ifndef BCMSDIO
1296/**
1297 * determines if a device is a WL device, and if so, attaches it.
1298 *
1299 * This function determines if a device pointed to by pdev is a WL device,
1300 * and if so, performs a wl_attach() on it.
1301 *
1302 */
1303int __devinit
1304wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1305{
1306 int rc;
1307 wl_info_t *wl;
1308 struct ieee80211_hw *hw;
66cbd3ab 1309 u32 val;
a9533e7e
HP
1310
1311 ASSERT(pdev);
1312
1313 WL_TRACE(("%s: bus %d slot %d func %d irq %d\n", __func__,
1314 pdev->bus->number, PCI_SLOT(pdev->devfn),
1315 PCI_FUNC(pdev->devfn), pdev->irq));
1316
1317 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1318 (((pdev->device & 0xff00) != 0x4300) &&
1319 ((pdev->device & 0xff00) != 0x4700) &&
1320 ((pdev->device < 43000) || (pdev->device > 43999))))
90ea2296 1321 return -ENODEV;
a9533e7e
HP
1322
1323 rc = pci_enable_device(pdev);
1324 if (rc) {
1325 WL_ERROR(("%s: Cannot enable device %d-%d_%d\n", __func__,
1326 pdev->bus->number, PCI_SLOT(pdev->devfn),
1327 PCI_FUNC(pdev->devfn)));
90ea2296 1328 return -ENODEV;
a9533e7e
HP
1329 }
1330 pci_set_master(pdev);
1331
1332 pci_read_config_dword(pdev, 0x40, &val);
1333 if ((val & 0x0000ff00) != 0)
1334 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1335
1336 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
1337 if (!hw) {
1338 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
1339 rc = -ENOMEM;
1340 goto err_1;
1341 }
1342
1343 SET_IEEE80211_DEV(hw, &pdev->dev);
1344
1345 pci_set_drvdata(pdev, hw);
1346
1347 bzero(hw->priv, sizeof(*wl));
1348
1349 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1350 PCI_BUS, pdev, pdev->irq);
1351
683b505b
BR
1352 if (!wl) {
1353 WL_ERROR(("%s: %s: wl_attach failed!\n",
1354 KBUILD_MODNAME, __func__));
1355 return -ENODEV;
1356 }
a9533e7e
HP
1357 return 0;
1358 err_1:
1359 WL_ERROR(("%s: err_1: Major hoarkage\n", __func__));
1360 return 0;
1361}
1362
1363#ifdef LINUXSTA_PS
878a6673 1364static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
a9533e7e
HP
1365{
1366 wl_info_t *wl;
1367 struct ieee80211_hw *hw;
1368
1369 WL_TRACE(("wl: wl_suspend\n"));
1370
1371 hw = pci_get_drvdata(pdev);
1372 wl = HW_TO_WL(hw);
1373 if (!wl) {
1374 WL_ERROR(("wl: wl_suspend: pci_get_drvdata failed\n"));
1375 return -ENODEV;
1376 }
1377
1378 WL_LOCK(wl);
1379 wl_down(wl);
0965ae88 1380 wl->pub->hw_up = false;
a9533e7e 1381 WL_UNLOCK(wl);
8ba9cfdb 1382 pci_save_state(pdev, wl->pci_psstate);
a9533e7e
HP
1383 pci_disable_device(pdev);
1384 return pci_set_power_state(pdev, PCI_D3hot);
1385}
1386
1387static int wl_resume(struct pci_dev *pdev)
1388{
1389 wl_info_t *wl;
1390 struct ieee80211_hw *hw;
1391 int err = 0;
66cbd3ab 1392 u32 val;
a9533e7e
HP
1393
1394 WL_TRACE(("wl: wl_resume\n"));
1395 hw = pci_get_drvdata(pdev);
1396 wl = HW_TO_WL(hw);
1397 if (!wl) {
1398 WL_ERROR(("wl: wl_resume: pci_get_drvdata failed\n"));
1399 return -ENODEV;
1400 }
1401
1402 err = pci_set_power_state(pdev, PCI_D0);
1403 if (err)
1404 return err;
1405
8ba9cfdb 1406 pci_restore_state(pdev, wl->pci_psstate);
a9533e7e
HP
1407
1408 err = pci_enable_device(pdev);
1409 if (err)
1410 return err;
1411
1412 pci_set_master(pdev);
1413
1414 pci_read_config_dword(pdev, 0x40, &val);
1415 if ((val & 0x0000ff00) != 0)
1416 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1417
1418 WL_LOCK(wl);
1419 err = wl_up(wl);
1420 WL_UNLOCK(wl);
1421
90ea2296 1422 return err;
a9533e7e
HP
1423}
1424#endif /* LINUXSTA_PS */
1425
6f0c5bcd 1426static void wl_remove(struct pci_dev *pdev)
a9533e7e
HP
1427{
1428 wl_info_t *wl;
1429 struct ieee80211_hw *hw;
1430
1431 hw = pci_get_drvdata(pdev);
1432 wl = HW_TO_WL(hw);
1433 if (!wl) {
1434 WL_ERROR(("wl: wl_remove: pci_get_drvdata failed\n"));
1435 return;
1436 }
1437 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1438 WL_ERROR(("wl: wl_remove: wlc_chipmatch failed\n"));
1439 return;
1440 }
683b505b
BR
1441 if (wl->wlc) {
1442 ieee80211_unregister_hw(hw);
1443 WL_LOCK(wl);
1444 wl_down(wl);
1445 WL_UNLOCK(wl);
1446 WL_NONE(("%s: Down\n", __func__));
1447 }
a9533e7e
HP
1448 pci_disable_device(pdev);
1449
1450 wl_free(wl);
1451
1452 pci_set_drvdata(pdev, NULL);
1453 ieee80211_free_hw(hw);
1454}
1455
1456static struct pci_driver wl_pci_driver = {
5fee2540
JC
1457 .name = "brcm80211",
1458 .probe = wl_pci_probe,
a9533e7e 1459#ifdef LINUXSTA_PS
5fee2540
JC
1460 .suspend = wl_suspend,
1461 .resume = wl_resume,
a9533e7e 1462#endif /* LINUXSTA_PS */
5fee2540
JC
1463 .remove = __devexit_p(wl_remove),
1464 .id_table = wl_id_table,
a9533e7e
HP
1465};
1466#endif /* !BCMSDIO */
1467
1468/**
1469 * This is the main entry point for the WL driver.
1470 *
1471 * This function determines if a device pointed to by pdev is a WL device,
1472 * and if so, performs a wl_attach() on it.
1473 *
1474 */
1475static int __init wl_module_init(void)
1476{
1477 int error = -ENODEV;
1478
1479#ifdef BCMDBG
1480 if (msglevel != 0xdeadbeef)
1481 wl_msg_level = msglevel;
1482 else {
1483 char *var = getvar(NULL, "wl_msglevel");
1484 if (var)
48c51a8c 1485 wl_msg_level = simple_strtoul(var, NULL, 0);
a9533e7e
HP
1486 }
1487#ifndef WLC_HIGH_ONLY
1488 {
66cbd3ab 1489 extern u32 phyhal_msg_level;
a9533e7e
HP
1490
1491 if (phymsglevel != 0xdeadbeef)
1492 phyhal_msg_level = phymsglevel;
1493 else {
1494 char *var = getvar(NULL, "phy_msglevel");
1495 if (var)
48c51a8c 1496 phyhal_msg_level = simple_strtoul(var, NULL, 0);
a9533e7e
HP
1497 }
1498 }
1499#endif /* WLC_HIGH_ONLY */
1500#endif /* BCMDBG */
1501
1502#ifndef BCMSDIO
8ba9cfdb 1503 error = pci_register_driver(&wl_pci_driver);
ca8c1e59 1504 if (!error)
90ea2296 1505 return 0;
a9533e7e
HP
1506
1507#endif /* !BCMSDIO */
1508
1509#ifdef WLC_HIGH_ONLY
1510 /* BMAC_NOTE: define hardcode number, why NODEVICE is ok ? */
1511 error =
1512 dbus_register(BCM_DNGL_VID, 0, wl_dbus_probe_cb,
1513 wl_dbus_disconnect_cb, NULL, NULL, NULL);
1514 if (error == DBUS_ERR_NODEVICE) {
1515 error = DBUS_OK;
1516 }
1517#endif /* WLC_HIGH_ONLY */
1518
90ea2296 1519 return error;
a9533e7e
HP
1520}
1521
1522/**
1523 * This function unloads the WL driver from the system.
1524 *
1525 * This function unconditionally unloads the WL driver module from the
1526 * system.
1527 *
1528 */
1529static void __exit wl_module_exit(void)
1530{
1531#ifndef BCMSDIO
1532 pci_unregister_driver(&wl_pci_driver);
1533#endif /* !BCMSDIO */
1534
1535#ifdef WLC_HIGH_ONLY
1536 dbus_deregister();
1537#endif /* WLC_HIGH_ONLY */
1538}
1539
1540module_init(wl_module_init);
1541module_exit(wl_module_exit);
1542
1543/**
1544 * This function frees the WL per-device resources.
1545 *
1546 * This function frees resources owned by the WL device pointed to
1547 * by the wl parameter.
1548 *
1549 */
7cc4a4c0 1550void wl_free(wl_info_t *wl)
a9533e7e
HP
1551{
1552 wl_timer_t *t, *next;
1553 osl_t *osh;
1554
1555 ASSERT(wl);
1556#ifndef WLC_HIGH_ONLY
a9533e7e
HP
1557 /* free ucode data */
1558 if (wl->fw.fw_cnt)
1559 wl_ucode_data_free();
a9533e7e
HP
1560 if (wl->irq)
1561 free_irq(wl->irq, wl);
1562#endif
1563
1564 /* kill dpc */
1565 tasklet_kill(&wl->tasklet);
1566
1567 if (wl->pub) {
1568 wlc_module_unregister(wl->pub, "linux", wl);
1569 }
1570
1571 /* free common resources */
1572 if (wl->wlc) {
1573 wlc_detach(wl->wlc);
1574 wl->wlc = NULL;
1575 wl->pub = NULL;
1576 }
1577
1578 /* virtual interface deletion is deferred so we cannot spinwait */
1579
1580 /* wait for all pending callbacks to complete */
1581 while (atomic_read(&wl->callbacks) > 0)
1582 schedule();
1583
1584 /* free timers */
1585 for (t = wl->timers; t; t = next) {
1586 next = t->next;
1587#ifdef BCMDBG
1588 if (t->name)
182acb3c 1589 kfree(t->name);
a9533e7e 1590#endif
182acb3c 1591 kfree(t);
a9533e7e
HP
1592 }
1593
a9533e7e
HP
1594 osh = wl->osh;
1595
1596 /*
1597 * unregister_netdev() calls get_stats() which may read chip registers
1598 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1599 */
1600 if (wl->regsva && BUSTYPE(wl->bcm_bustype) != SDIO_BUS &&
1601 BUSTYPE(wl->bcm_bustype) != JTAG_BUS) {
1602 iounmap((void *)wl->regsva);
1603 }
1604 wl->regsva = NULL;
1605
1606#ifdef WLC_HIGH_ONLY
1607 wl_rpcq_free(wl);
1608
1609 wl_txq_free(wl);
1610
1611 if (wl->rpc) {
1612 bcm_rpc_detach(wl->rpc);
1613 wl->rpc = NULL;
1614 }
1615
1616 if (wl->rpc_th) {
1617 bcm_rpc_tp_detach(wl->rpc_th);
1618 wl->rpc_th = NULL;
1619 }
1620#endif /* WLC_HIGH_ONLY */
1621
a9533e7e
HP
1622 osl_detach(osh);
1623}
1624
1625#ifdef WLC_LOW
1626/* transmit a packet */
7cc4a4c0 1627static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
a9533e7e
HP
1628{
1629 if (!wl)
1630 return -ENETDOWN;
1631
1632 return wl_start_int(wl, WL_TO_HW(wl), skb);
1633}
1634#endif /* WLC_LOW */
1635
1636static int BCMFASTPATH
7cc4a4c0 1637wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
a9533e7e
HP
1638{
1639#ifdef WLC_HIGH_ONLY
1640 WL_LOCK(wl);
1641#endif
1642 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1643#ifdef WLC_HIGH_ONLY
1644 WL_UNLOCK(wl);
1645#endif
90ea2296 1646 return NETDEV_TX_OK;
a9533e7e
HP
1647}
1648
7cc4a4c0 1649void wl_txflowcontrol(wl_info_t *wl, struct wl_if *wlif, bool state, int prio)
a9533e7e
HP
1650{
1651 WL_ERROR(("Shouldn't be here %s\n", __func__));
1652}
1653
1654#if defined(WLC_HIGH_ONLY)
1655/* Schedule a completion handler to run at safe time */
1656static int
7cc4a4c0 1657wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *task),
a9533e7e
HP
1658 void *context)
1659{
1660 wl_task_t *task;
1661
1662 WL_TRACE(("wl%d: wl_schedule_task\n", wl->pub->unit));
1663
5fcc1fcb 1664 task = kmalloc(sizeof(wl_task_t), GFP_ATOMIC);
ca8c1e59 1665 if (!task) {
97e17d0e 1666 WL_ERROR(("wl%d: wl_schedule_task: out of memory\n", wl->pub->unit));
a9533e7e
HP
1667 return -ENOMEM;
1668 }
1669
364eb72a 1670 INIT_WORK(&task->work, (work_func_t) fn);
a9533e7e
HP
1671 task->context = context;
1672
1673 if (!schedule_work(&task->work)) {
1674 WL_ERROR(("wl%d: schedule_work() failed\n", wl->pub->unit));
182acb3c 1675 kfree(task);
a9533e7e
HP
1676 return -ENOMEM;
1677 }
1678
1679 atomic_inc(&wl->callbacks);
1680
1681 return 0;
1682}
1683#endif /* defined(WLC_HIGH_ONLY) */
1684
7cc4a4c0 1685void wl_init(wl_info_t *wl)
a9533e7e
HP
1686{
1687 WL_TRACE(("wl%d: wl_init\n", wl->pub->unit));
1688
1689 wl_reset(wl);
1690
1691 wlc_init(wl->wlc);
1692}
1693
7cc4a4c0 1694uint wl_reset(wl_info_t *wl)
a9533e7e
HP
1695{
1696 WL_TRACE(("wl%d: wl_reset\n", wl->pub->unit));
1697
1698 wlc_reset(wl->wlc);
1699
1700 /* dpc will not be rescheduled */
1701 wl->resched = 0;
1702
90ea2296 1703 return 0;
a9533e7e
HP
1704}
1705
1706/*
1707 * These are interrupt on/off entry points. Disable interrupts
1708 * during interrupt state transition.
1709 */
7cc4a4c0 1710void BCMFASTPATH wl_intrson(wl_info_t *wl)
a9533e7e
HP
1711{
1712#if defined(WLC_LOW)
1713 unsigned long flags;
1714
1715 INT_LOCK(wl, flags);
1716 wlc_intrson(wl->wlc);
1717 INT_UNLOCK(wl, flags);
1718#endif /* WLC_LOW */
1719}
1720
7cc4a4c0 1721bool wl_alloc_dma_resources(wl_info_t *wl, uint addrwidth)
a9533e7e 1722{
0f0881b0 1723 return true;
a9533e7e
HP
1724}
1725
66cbd3ab 1726u32 BCMFASTPATH wl_intrsoff(wl_info_t *wl)
a9533e7e
HP
1727{
1728#if defined(WLC_LOW)
1729 unsigned long flags;
66cbd3ab 1730 u32 status;
a9533e7e
HP
1731
1732 INT_LOCK(wl, flags);
1733 status = wlc_intrsoff(wl->wlc);
1734 INT_UNLOCK(wl, flags);
1735 return status;
1736#else
1737 return 0;
1738#endif /* WLC_LOW */
1739}
1740
66cbd3ab 1741void wl_intrsrestore(wl_info_t *wl, u32 macintmask)
a9533e7e
HP
1742{
1743#if defined(WLC_LOW)
1744 unsigned long flags;
1745
1746 INT_LOCK(wl, flags);
1747 wlc_intrsrestore(wl->wlc, macintmask);
1748 INT_UNLOCK(wl, flags);
1749#endif /* WLC_LOW */
1750}
1751
7cc4a4c0 1752int wl_up(wl_info_t *wl)
a9533e7e
HP
1753{
1754 int error = 0;
1755
1756 if (wl->pub->up)
90ea2296 1757 return 0;
a9533e7e
HP
1758
1759 error = wlc_up(wl->wlc);
1760
90ea2296 1761 return error;
a9533e7e
HP
1762}
1763
7cc4a4c0 1764void wl_down(wl_info_t *wl)
a9533e7e
HP
1765{
1766 uint callbacks, ret_val = 0;
1767
1768 /* call common down function */
1769 ret_val = wlc_down(wl->wlc);
1770 callbacks = atomic_read(&wl->callbacks) - ret_val;
1771
1772 /* wait for down callbacks to complete */
1773 WL_UNLOCK(wl);
1774
1775#ifndef WLC_HIGH_ONLY
1776 /* For HIGH_only driver, it's important to actually schedule other work,
1777 * not just spin wait since everything runs at schedule level
1778 */
1779 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1780#endif /* WLC_HIGH_ONLY */
1781
1782 WL_LOCK(wl);
1783}
1784
1785irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1786{
1787#if defined(WLC_LOW)
1788 wl_info_t *wl;
1789 bool ours, wantdpc;
1790 unsigned long flags;
1791
1792 wl = (wl_info_t *) dev_id;
1793
1794 WL_ISRLOCK(wl, flags);
1795
1796 /* call common first level interrupt handler */
ca8c1e59
JC
1797 ours = wlc_isr(wl->wlc, &wantdpc);
1798 if (ours) {
a9533e7e
HP
1799 /* if more to do... */
1800 if (wantdpc) {
1801
1802 /* ...and call the second level interrupt handler */
1803 /* schedule dpc */
0965ae88 1804 ASSERT(wl->resched == false);
a9533e7e
HP
1805 tasklet_schedule(&wl->tasklet);
1806 }
1807 }
1808
1809 WL_ISRUNLOCK(wl, flags);
1810
1811 return IRQ_RETVAL(ours);
1812#else
1813 return IRQ_RETVAL(0);
1814#endif /* WLC_LOW */
1815}
1816
3deea904 1817static void BCMFASTPATH wl_dpc(unsigned long data)
a9533e7e
HP
1818{
1819#ifdef WLC_LOW
1820 wl_info_t *wl;
1821
1822 wl = (wl_info_t *) data;
1823
1824 WL_LOCK(wl);
1825
1826 /* call the common second level interrupt handler */
1827 if (wl->pub->up) {
1828 if (wl->resched) {
1829 unsigned long flags;
1830
1831 INT_LOCK(wl, flags);
1832 wlc_intrsupd(wl->wlc);
1833 INT_UNLOCK(wl, flags);
1834 }
1835
0f0881b0 1836 wl->resched = wlc_dpc(wl->wlc, true);
a9533e7e
HP
1837 }
1838
1839 /* wlc_dpc() may bring the driver down */
1840 if (!wl->pub->up)
1841 goto done;
1842
1843 /* re-schedule dpc */
1844 if (wl->resched)
1845 tasklet_schedule(&wl->tasklet);
1846 else {
1847 /* re-enable interrupts */
1848 wl_intrson(wl);
1849 }
1850
1851 done:
1852 WL_UNLOCK(wl);
1853#endif /* WLC_LOW */
1854}
1855
7cc4a4c0 1856static void wl_link_up(wl_info_t *wl, char *ifname)
a9533e7e
HP
1857{
1858 WL_ERROR(("wl%d: link up (%s)\n", wl->pub->unit, ifname));
1859}
1860
7cc4a4c0 1861static void wl_link_down(wl_info_t *wl, char *ifname)
a9533e7e
HP
1862{
1863 WL_ERROR(("wl%d: link down (%s)\n", wl->pub->unit, ifname));
1864}
1865
7cc4a4c0 1866void wl_event(wl_info_t *wl, char *ifname, wlc_event_t *e)
a9533e7e
HP
1867{
1868
1869 switch (e->event.event_type) {
1870 case WLC_E_LINK:
1871 case WLC_E_NDIS_LINK:
1872 if (e->event.flags & WLC_EVENT_MSG_LINK)
1873 wl_link_up(wl, ifname);
1874 else
1875 wl_link_down(wl, ifname);
1876 break;
1877 case WLC_E_RADIO:
1878 break;
1879 }
1880}
1881
3deea904 1882static void wl_timer(unsigned long data)
a9533e7e
HP
1883{
1884#ifndef WLC_HIGH_ONLY
1885 _wl_timer((wl_timer_t *) data);
1886#else
1887 wl_timer_t *t = (wl_timer_t *) data;
1888 wl_schedule_task(t->wl, wl_timer_task, t);
1889#endif /* WLC_HIGH_ONLY */
1890}
1891
7cc4a4c0 1892static void _wl_timer(wl_timer_t *t)
a9533e7e
HP
1893{
1894 WL_LOCK(t->wl);
1895
1896 if (t->set) {
1897 if (t->periodic) {
1898 t->timer.expires = jiffies + t->ms * HZ / 1000;
1899 atomic_inc(&t->wl->callbacks);
1900 add_timer(&t->timer);
0f0881b0 1901 t->set = true;
a9533e7e 1902 } else
0965ae88 1903 t->set = false;
a9533e7e
HP
1904
1905 t->fn(t->arg);
1906 }
1907
1908 atomic_dec(&t->wl->callbacks);
1909
1910 WL_UNLOCK(t->wl);
1911}
1912
7cc4a4c0 1913wl_timer_t *wl_init_timer(wl_info_t *wl, void (*fn) (void *arg), void *arg,
a9533e7e
HP
1914 const char *name)
1915{
1916 wl_timer_t *t;
1917
5fcc1fcb 1918 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
ca8c1e59 1919 if (!t) {
97e17d0e 1920 WL_ERROR(("wl%d: wl_init_timer: out of memory\n", wl->pub->unit));
a9533e7e
HP
1921 return 0;
1922 }
1923
1924 bzero(t, sizeof(wl_timer_t));
1925
1926 init_timer(&t->timer);
3deea904 1927 t->timer.data = (unsigned long) t;
a9533e7e
HP
1928 t->timer.function = wl_timer;
1929 t->wl = wl;
1930 t->fn = fn;
1931 t->arg = arg;
1932 t->next = wl->timers;
1933 wl->timers = t;
1934
1935#ifdef BCMDBG
5fcc1fcb 1936 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
ca8c1e59 1937 if (t->name)
a9533e7e
HP
1938 strcpy(t->name, name);
1939#endif
1940
1941 return t;
1942}
1943
1944/* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1945 * as well as it's easier to make it periodic
1946 */
7cc4a4c0 1947void wl_add_timer(wl_info_t *wl, wl_timer_t *t, uint ms, int periodic)
a9533e7e
HP
1948{
1949#ifdef BCMDBG
1950 if (t->set) {
1951 WL_ERROR(("%s: Already set. Name: %s, per %d\n",
1952 __func__, t->name, periodic));
1953 }
1954#endif
1955 ASSERT(!t->set);
1956
1957 t->ms = ms;
1958 t->periodic = (bool) periodic;
0f0881b0 1959 t->set = true;
a9533e7e
HP
1960 t->timer.expires = jiffies + ms * HZ / 1000;
1961
1962 atomic_inc(&wl->callbacks);
1963 add_timer(&t->timer);
1964}
1965
0965ae88 1966/* return true if timer successfully deleted, false if still pending */
7cc4a4c0 1967bool wl_del_timer(wl_info_t *wl, wl_timer_t *t)
a9533e7e
HP
1968{
1969 if (t->set) {
0965ae88 1970 t->set = false;
a9533e7e 1971 if (!del_timer(&t->timer)) {
0965ae88 1972 return false;
a9533e7e
HP
1973 }
1974 atomic_dec(&wl->callbacks);
1975 }
1976
0f0881b0 1977 return true;
a9533e7e
HP
1978}
1979
7cc4a4c0 1980void wl_free_timer(wl_info_t *wl, wl_timer_t *t)
a9533e7e
HP
1981{
1982 wl_timer_t *tmp;
1983
1984 /* delete the timer in case it is active */
1985 wl_del_timer(wl, t);
1986
1987 if (wl->timers == t) {
1988 wl->timers = wl->timers->next;
1989#ifdef BCMDBG
1990 if (t->name)
182acb3c 1991 kfree(t->name);
a9533e7e 1992#endif
182acb3c 1993 kfree(t);
a9533e7e
HP
1994 return;
1995
1996 }
1997
1998 tmp = wl->timers;
1999 while (tmp) {
2000 if (tmp->next == t) {
2001 tmp->next = t->next;
2002#ifdef BCMDBG
2003 if (t->name)
182acb3c 2004 kfree(t->name);
a9533e7e 2005#endif
182acb3c 2006 kfree(t);
a9533e7e
HP
2007 return;
2008 }
2009 tmp = tmp->next;
2010 }
2011
2012}
2013
2014static int wl_linux_watchdog(void *ctx)
2015{
2016 wl_info_t *wl = (wl_info_t *) ctx;
2017 struct net_device_stats *stats = NULL;
2018 uint id;
2019 /* refresh stats */
2020 if (wl->pub->up) {
2021 ASSERT(wl->stats_id < 2);
2022
2023 id = 1 - wl->stats_id;
2024
2025 stats = &wl->stats_watchdog[id];
2026 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
2027 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
2028 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
2029 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
2030 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
2031 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
2032 stats->collisions = 0;
2033
2034 stats->rx_length_errors = 0;
2035 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
2036 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
2037 stats->rx_frame_errors = 0;
2038 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
2039 stats->rx_missed_errors = 0;
2040
2041 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
2042
2043 wl->stats_id = id;
2044
2045 }
2046
2047 return 0;
2048}
2049
2050struct wl_fw_hdr {
66cbd3ab
GKH
2051 u32 offset;
2052 u32 len;
2053 u32 idx;
a9533e7e
HP
2054};
2055
2056#ifdef WLC_HIGH_ONLY
2057static void wl_rpc_down(void *wlh)
2058{
2059 wl_info_t *wl = (wl_info_t *) (wlh);
2060
2061 wlc_device_removed(wl->wlc);
2062
2063 wl_rpcq_free(wl);
2064}
2065
7cc4a4c0 2066static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
a9533e7e
HP
2067{
2068
3deea904 2069 unsigned long flags;
a9533e7e
HP
2070
2071 skb->prev = NULL;
2072
2073 /* Lock the queue as tasklet could be running at this time */
2074 TXQ_LOCK(wl, flags);
2075 if (wl->txq_head == NULL)
2076 wl->txq_head = skb;
2077 else {
2078 wl->txq_tail->prev = skb;
2079 }
2080 wl->txq_tail = skb;
2081
0965ae88 2082 if (wl->txq_dispatched == false) {
0f0881b0 2083 wl->txq_dispatched = true;
a9533e7e
HP
2084
2085 if (schedule_work(&wl->txq_task.work)) {
2086 atomic_inc(&wl->callbacks);
2087 } else {
2088 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2089 wl->pub->unit));
2090 }
2091 }
2092
2093 TXQ_UNLOCK(wl, flags);
2094
90ea2296 2095 return 0;
a9533e7e
HP
2096
2097}
2098
2099static void wl_start_txqwork(struct wl_task *task)
2100{
2101 wl_info_t *wl = (wl_info_t *) task->context;
2102 struct sk_buff *skb;
3deea904 2103 unsigned long flags;
a9533e7e
HP
2104 uint count = 0;
2105
2106 WL_TRACE(("wl%d: wl_start_txqwork\n", wl->pub->unit));
2107
2108 /* First remove an entry then go for execution */
2109 TXQ_LOCK(wl, flags);
2110 while (wl->txq_head) {
2111 skb = wl->txq_head;
2112 wl->txq_head = skb->prev;
2113 skb->prev = NULL;
2114 if (wl->txq_head == NULL)
2115 wl->txq_tail = NULL;
2116 TXQ_UNLOCK(wl, flags);
2117
2118 /* it has WL_LOCK/WL_UNLOCK inside */
2119 wl_start_int(wl, WL_TO_HW(wl), skb);
2120
2121 /* bounded our execution, reshedule ourself next */
2122 if (++count >= 10)
2123 break;
2124
2125 TXQ_LOCK(wl, flags);
2126 }
2127
2128 if (count >= 10) {
2129 if (!schedule_work(&wl->txq_task.work)) {
2130 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2131 wl->pub->unit));
2132 atomic_dec(&wl->callbacks);
2133 }
2134 } else {
0965ae88 2135 wl->txq_dispatched = false;
a9533e7e
HP
2136 TXQ_UNLOCK(wl, flags);
2137 atomic_dec(&wl->callbacks);
2138 }
2139
2140 return;
2141}
2142
7cc4a4c0 2143static void wl_txq_free(wl_info_t *wl)
a9533e7e
HP
2144{
2145 struct sk_buff *skb;
2146
2147 if (wl->txq_head == NULL) {
2148 ASSERT(wl->txq_tail == NULL);
2149 return;
2150 }
2151
2152 while (wl->txq_head) {
2153 skb = wl->txq_head;
2154 wl->txq_head = skb->prev;
0f0881b0 2155 PKTFREE(wl->osh, skb, true);
a9533e7e
HP
2156 }
2157
2158 wl->txq_tail = NULL;
2159}
2160
7cc4a4c0 2161static void wl_rpcq_free(wl_info_t *wl)
a9533e7e
HP
2162{
2163 rpc_buf_t *buf;
2164
2165 if (wl->rpcq_head == NULL) {
2166 ASSERT(wl->rpcq_tail == NULL);
2167 return;
2168 }
2169
2170 while (wl->rpcq_head) {
2171 buf = wl->rpcq_head;
2172 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2173 bcm_rpc_buf_free(wl->rpc_dispatch_ctx.rpc, buf);
2174 }
2175
2176 wl->rpcq_tail = NULL;
2177}
2178
2179static void wl_rpcq_dispatch(struct wl_task *task)
2180{
2181 wl_info_t *wl = (wl_info_t *) task->context;
2182 rpc_buf_t *buf;
3deea904 2183 unsigned long flags;
a9533e7e
HP
2184
2185 /* First remove an entry then go for execution */
2186 RPCQ_LOCK(wl, flags);
2187 while (wl->rpcq_head) {
2188 buf = wl->rpcq_head;
2189 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2190
2191 if (wl->rpcq_head == NULL)
2192 wl->rpcq_tail = NULL;
2193 RPCQ_UNLOCK(wl, flags);
2194
2195 WL_LOCK(wl);
2196 wlc_rpc_high_dispatch(&wl->rpc_dispatch_ctx, buf);
2197 WL_UNLOCK(wl);
2198
2199 RPCQ_LOCK(wl, flags);
2200 }
2201
0965ae88 2202 wl->rpcq_dispatched = false;
a9533e7e
HP
2203
2204 RPCQ_UNLOCK(wl, flags);
2205
182acb3c 2206 kfree(task);
a9533e7e
HP
2207 atomic_dec(&wl->callbacks);
2208}
2209
7cc4a4c0 2210static void wl_rpcq_add(wl_info_t *wl, rpc_buf_t *buf)
a9533e7e 2211{
3deea904 2212 unsigned long flags;
a9533e7e
HP
2213
2214 bcm_rpc_buf_next_set(wl->rpc_th, buf, NULL);
2215
2216 /* Lock the queue as tasklet could be running at this time */
2217 RPCQ_LOCK(wl, flags);
2218 if (wl->rpcq_head == NULL)
2219 wl->rpcq_head = buf;
2220 else
2221 bcm_rpc_buf_next_set(wl->rpc_th, wl->rpcq_tail, buf);
2222
2223 wl->rpcq_tail = buf;
2224
0965ae88 2225 if (wl->rpcq_dispatched == false) {
0f0881b0 2226 wl->rpcq_dispatched = true;
a9533e7e
HP
2227 wl_schedule_task(wl, wl_rpcq_dispatch, wl);
2228 }
2229
2230 RPCQ_UNLOCK(wl, flags);
2231}
2232
2233#if defined(BCMDBG)
2234static const struct name_entry rpc_name_tbl[] = RPC_ID_TABLE;
2235#endif /* BCMDBG */
2236
2237/* dongle-side rpc dispatch routine */
2238static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf)
2239{
2240 bcm_xdr_buf_t b;
2241 wl_info_t *wl = (wl_info_t *) ctx;
2242 wlc_rpc_id_t rpc_id;
2243 int err;
2244
2245 bcm_xdr_buf_init(&b, bcm_rpc_buf_data(wl->rpc_th, buf),
2246 bcm_rpc_buf_len_get(wl->rpc_th, buf));
2247
66cbd3ab 2248 err = bcm_xdr_unpack_u32(&b, &rpc_id);
a9533e7e
HP
2249 ASSERT(!err);
2250 WL_TRACE(("%s: Dispatch id %s\n", __func__,
2251 WLC_RPC_ID_LOOKUP(rpc_name_tbl, rpc_id)));
2252
2253 /* Handle few emergency ones */
2254 switch (rpc_id) {
2255 default:
2256 wl_rpcq_add(wl, buf);
2257 break;
2258 }
2259}
2260
7cc4a4c0 2261static void wl_timer_task(wl_task_t *task)
a9533e7e
HP
2262{
2263 wl_timer_t *t = (wl_timer_t *) task->context;
2264
2265 _wl_timer(t);
182acb3c 2266 kfree(task);
a9533e7e
HP
2267
2268 /* This dec is for the task_schedule. The timer related
2269 * callback is decremented in _wl_timer
2270 */
2271 atomic_dec(&t->wl->callbacks);
2272}
2273#endif /* WLC_HIGH_ONLY */
2274
2275#ifndef WLC_HIGH_ONLY
2276char *wl_firmwares[WL_MAX_FW] = {
2277 "brcm/bcm43xx",
2278 NULL
2279};
2280
2281#ifdef WLC_LOW
66cbd3ab 2282int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, u32 idx)
a9533e7e
HP
2283{
2284 int i, entry;
41feb5ed 2285 const u8 *pdata;
a9533e7e
HP
2286 struct wl_fw_hdr *hdr;
2287 for (i = 0; i < wl->fw.fw_cnt; i++) {
2288 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
2289 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
2290 entry++, hdr++) {
2291 if (hdr->idx == idx) {
2292 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
2293 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
2294 if (*pbuf == NULL) {
2295 printf("fail to alloc %d bytes\n",
2296 hdr->len);
2297 }
2298 bcopy(pdata, *pbuf, hdr->len);
2299 return 0;
2300 }
2301 }
2302 }
2303 printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
2304 *pbuf = NULL;
2305 return -1;
2306}
2307
66cbd3ab 2308int wl_ucode_init_uint(wl_info_t *wl, u32 *data, u32 idx)
a9533e7e
HP
2309{
2310 int i, entry;
41feb5ed 2311 const u8 *pdata;
a9533e7e
HP
2312 struct wl_fw_hdr *hdr;
2313 for (i = 0; i < wl->fw.fw_cnt; i++) {
2314 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
2315 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
2316 entry++, hdr++) {
2317 if (hdr->idx == idx) {
2318 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
2319 ASSERT(hdr->len == 4);
66cbd3ab 2320 *data = *((u32 *) pdata);
a9533e7e
HP
2321 return 0;
2322 }
2323 }
2324 }
2325 printf("ERROR: ucode tag:%d can not be found!\n", idx);
2326 return -1;
2327}
2328#endif /* WLC_LOW */
2329
7cc4a4c0 2330static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev)
a9533e7e
HP
2331{
2332 int status;
2333 struct device *device = &pdev->dev;
2334 char fw_name[100];
2335 int i;
2336
2337 bzero((void *)&wl->fw, sizeof(struct wl_firmware));
2338 for (i = 0; i < WL_MAX_FW; i++) {
2339 if (wl_firmwares[i] == NULL)
2340 break;
2341 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
2342 UCODE_LOADER_API_VER);
2343 WL_NONE(("request fw %s\n", fw_name));
2344 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
2345 if (status) {
683b505b
BR
2346 printf("%s: fail to load firmware %s\n",
2347 KBUILD_MODNAME, fw_name);
eb4764c3 2348 wl_release_fw(wl);
a9533e7e
HP
2349 return status;
2350 }
2351 WL_NONE(("request fw %s\n", fw_name));
2352 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
2353 UCODE_LOADER_API_VER);
2354 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
2355 if (status) {
683b505b
BR
2356 printf("%s: fail to load firmware %s\n",
2357 KBUILD_MODNAME, fw_name);
eb4764c3 2358 wl_release_fw(wl);
a9533e7e
HP
2359 return status;
2360 }
2361 wl->fw.hdr_num_entries[i] =
2362 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
2363 WL_NONE(("request fw %s find: %d entries\n", fw_name,
2364 wl->fw.hdr_num_entries[i]));
2365 }
2366 wl->fw.fw_cnt = i;
2367 wl_ucode_data_init(wl);
2368 return 0;
2369}
2370
2371#ifdef WLC_LOW
2372void wl_ucode_free_buf(void *p)
2373{
2374 kfree(p);
2375}
2376#endif /* WLC_LOW */
2377
7cc4a4c0 2378static void wl_release_fw(wl_info_t *wl)
a9533e7e
HP
2379{
2380 int i;
eb4764c3 2381 for (i = 0; i < WL_MAX_FW; i++) {
a9533e7e
HP
2382 release_firmware(wl->fw.fw_bin[i]);
2383 release_firmware(wl->fw.fw_hdr[i]);
2384 }
2385}
2386#endif /* WLC_HIGH_ONLY */