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