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