2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #define __UNDEF_NO_VERSION__
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 */
38 #include <asm/system.h>
41 #include <asm/pgtable.h>
42 #include <asm/uaccess.h>
43 #include <asm/unaligned.h>
45 #include <net/mac80211.h>
48 #include <phy_version.h>
50 #include <bcmendian.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>
65 #include <wl_export.h>
68 #include "bcm_rpc_tp.h"
74 #include <wl_mac80211.h>
75 #include <linux/firmware.h>
78 #include <d11ucode_ext.h>
82 extern struct device *sdiommc_dev;
85 extern void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg,
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);
92 static void wl_timer(ulong data);
93 static void _wl_timer(wl_timer_t *t);
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);
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 *),
115 #endif /* WLC_HIGH_ONLY */
117 static int ieee_hw_init(struct ieee80211_hw *hw);
118 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
120 static int wl_linux_watchdog(void *ctx);
122 /* Flags we support */
123 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
129 FIF_BCN_PRBRESP_PROMISC)
133 struct ieee80211_tkip_data {
134 #define TKIP_KEY_LEN 32
135 u8 key[TKIP_KEY_LEN];
150 u32 dot11RSNAStatsTKIPReplays;
151 u32 dot11RSNAStatsTKIPICVErrors;
152 u32 dot11RSNAStatsTKIPLocalMICFailures;
156 struct crypto_tfm *tfm_arc4;
157 struct crypto_tfm *tfm_michael;
159 /* scratch buffers for virt_to_page() (crypto API) */
160 u8 rx_hdr[16], tx_hdr[16];
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);
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);
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");
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 */
189 MODULE_DEVICE_TABLE(pci, wl_id_table);
190 #endif /* !BCMSDIO */
193 static uint sd_drivestrength = 6;
194 module_param(sd_drivestrength, uint, 0);
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 */
207 module_param(oneonly, int, 0);
210 module_param(piomode, int, 0);
212 static int instance_base; /* Starting instance number */
213 module_param(instance_base, int, 0);
216 static char *macaddr;
217 module_param(macaddr, charp, S_IRUGO);
220 static int nompc = 1;
221 module_param(nompc, int, 0);
223 static char name[IFNAMSIZ] = "eth%d";
224 module_param_string(name, name, IFNAMSIZ, 0);
230 #define WL_MAGIC 0xdeadbeef
232 #define HW_TO_WL(hw) (hw->priv)
233 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
235 static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb);
237 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
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,
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,
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);
277 static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb)
280 wl_info_t *wl = hw->priv;
282 WL_ERROR(("ops->tx called while down\n"));
286 status = wl_start(skb, wl);
291 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
294 wl_info_t *wl = hw->priv;
297 WL_ERROR(("ops->tx called while down\n"));
301 status = wl_start(skb, wl);
306 #endif /* WLC_HIGH_ONLY */
308 static int wl_ops_start(struct ieee80211_hw *hw)
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));
315 ieee80211_wake_queues(hw);
321 static void wl_ops_stop(struct ieee80211_hw *hw)
323 wl_info_t *wl = hw->priv;
327 ieee80211_stop_queues(hw);
334 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
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));
356 WL_ERROR(("%s: wl_up() returned %d\n", __func__, err));
361 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
367 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
368 enum nl80211_channel_type type)
370 wl_info_t *wl = HW_TO_WL(hw);
374 case NL80211_CHAN_HT20:
375 case NL80211_CHAN_NO_HT:
377 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
380 case NL80211_CHAN_HT40MINUS:
381 case NL80211_CHAN_HT40PLUS:
382 WL_ERROR(("%s: Need to implement 40 Mhz Channels!\n",
392 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
394 struct ieee80211_conf *conf = &hw->conf;
395 wl_info_t *wl = HW_TO_WL(hw);
399 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
400 WL_NONE(("%s: Setting listen interval to %d\n",
401 __func__, conf->listen_interval));
403 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
404 WL_ERROR(("%s: Error setting listen_interval\n",
409 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
410 ASSERT(new_int == conf->listen_interval);
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"));
417 if (changed & IEEE80211_CONF_CHANGE_POWER) {
418 WL_NONE(("%s: Setting tx power to %d dbm\n", __func__,
421 (wl->wlc, "qtxpower", conf->power_level * 4)) {
422 WL_ERROR(("%s: Error setting power_level\n", __func__));
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));
431 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
432 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
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));
439 (wl->wlc, WLC_SET_SRL,
440 conf->short_frame_max_tx_count) < 0) {
441 WL_ERROR(("%s: Error setting srl\n", __func__));
445 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
447 WL_ERROR(("%s: Error setting lrl\n", __func__));
458 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
459 struct ieee80211_vif *vif,
460 struct ieee80211_bss_conf *info, u32 changed)
462 wl_info_t *wl = HW_TO_WL(hw);
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.
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 */
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 */
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)
492 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
493 /* slot timing changed */
496 if (changed & BSS_CHANGED_HT) {
497 WL_NONE(("%s: HT mode - Implement me\n", __func__));
498 /* 802.11n parameters changed */
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 */
505 if (changed & BSS_CHANGED_BEACON_INT) {
506 WL_NONE(("Beacon Interval:\t%d Implement me\n",
508 /* Beacon interval changed */
510 if (changed & BSS_CHANGED_BSSID) {
511 /* char eabuf[ETHER_ADDR_STR_LEN]; */
512 WL_NONE(("new BSSID:\taid %d bss:%s\n",
514 bcm_ether_ntoa((struct ether_addr *)info->bssid,
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);
521 if (changed & BSS_CHANGED_BEACON) {
522 WL_ERROR(("BSS_CHANGED_BEACON\n"));
523 /* Beacon data changed, retrieve new beacon (beaconing modes) */
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) */
537 wl_ops_configure_filter(struct ieee80211_hw *hw,
538 unsigned int changed_flags,
539 unsigned int *total_flags, u64 multicast)
541 #ifndef WLC_HIGH_ONLY
542 wl_info_t *wl = hw->priv;
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
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);
567 wlc_mac_bcn_promisc_change(wl->wlc, 0);
568 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
577 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
579 WL_ERROR(("%s: Enter\n", __func__));
583 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
585 WL_NONE(("Scan Start\n"));
589 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
591 WL_NONE(("Scan Complete\n"));
595 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
597 WL_ERROR(("%s: Enter\n", __func__));
602 wl_ops_get_stats(struct ieee80211_hw *hw,
603 struct ieee80211_low_level_stats *stats)
605 WL_ERROR(("%s: Enter\n", __func__));
609 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
611 WL_ERROR(("%s: Enter\n", __func__));
616 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
617 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
619 WL_NONE(("%s: Enter\n", __func__));
622 WL_ERROR(("%s: Uknown cmd = %d\n", __func__, cmd));
629 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
630 const struct ieee80211_tx_queue_params *params)
632 wl_info_t *wl = hw->priv;
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));
639 wlc_wme_setparams(wl->wlc, queue, (void *)params, TRUE);
645 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
647 WL_ERROR(("%s: Enter\n", __func__));
652 wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
653 struct ieee80211_sta *sta)
658 wl_info_t *wl = hw->priv;
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;
668 wl->pub->global_scb = scb;
669 wl->pub->global_ampdu = &(scb->scb_ampdu);
670 wl->pub->global_ampdu->scb = scb;
672 wl->pub->global_ampdu->max_pdu = AMPDU_NUM_MPDU;
674 wl->pub->global_ampdu->max_pdu = 16;
676 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
677 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
679 sta->ht_cap.ht_supported = TRUE;
681 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_16K;
683 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
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;
690 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
695 wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
696 struct ieee80211_sta *sta)
698 WL_NONE(("%s: Enter\n", __func__));
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)
709 struct scb *scb = (struct scb *)sta->drv_priv;
711 wl_info_t *wl = hw->priv;
713 ASSERT(scb->magic == SCB_MAGIC);
715 case IEEE80211_AMPDU_RX_START:
716 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_START\n", __func__));
718 case IEEE80211_AMPDU_RX_STOP:
719 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__));
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)); */
726 /* XXX: Use the starting sequence number provided ... */
728 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
731 case IEEE80211_AMPDU_TX_STOP:
732 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
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",
741 WL_ERROR(("%s: Invalid command, ignoring\n", __func__));
747 static const struct ieee80211_ops wl_ops = {
753 .start = wl_ops_start,
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,
774 static int wl_set_hint(wl_info_t *wl, char *abbrev)
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);
782 * attach to the WL device.
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.
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
792 static wl_info_t *wl_attach(uint16 vendor, uint16 device, ulong regs,
793 uint bustype, void *btparam, uint irq)
800 struct ieee80211_hw *hw;
801 uint8 perm[ETH_ALEN];
803 unit = wl_found + instance_base;
807 WL_ERROR(("wl%d: unit number overflow, exiting\n", unit));
811 if (oneonly && (unit != instance_base)) {
812 WL_ERROR(("wl%d: wl_attach: oneonly is set, exiting\n", unit));
816 /* Requires pkttag feature */
817 osh = osl_attach(btparam, bustype, TRUE);
821 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
823 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
827 bzero(hw->priv, sizeof(*wl));
830 /* allocate private info */
831 hw = pci_get_drvdata(btparam); /* btparam == pdev */
836 wl->magic = WL_MAGIC;
838 atomic_set(&wl->callbacks, 0);
840 /* setup the bottom half handler */
841 tasklet_init(&wl->tasklet, wl_dpc, (ulong) wl);
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,
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,
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 */
864 SET_IEEE80211_DEV(hw, sdiommc_dev);
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) {
877 WL_TRACE(("force to PCI\n"));
879 wl->bcm_bustype = bustype;
882 if (wl->bcm_bustype == RPC_BUS) {
883 wl->regsva = (void *)0;
887 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
888 if (wl->regsva == NULL) {
889 WL_ERROR(("wl%d: ioremap() failed\n", unit));
893 spin_lock_init(&wl->rpcq_lock);
894 spin_lock_init(&wl->txq_lock);
896 init_MUTEX(&wl->sem);
898 spin_lock_init(&wl->lock);
899 spin_lock_init(&wl->isr_lock);
902 #ifndef WLC_HIGH_ONLY
904 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
905 printf("%s: %s driver failed\n", KBUILD_MODNAME,
911 /* common load-time initialization */
912 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
913 wl->regsva, wl->bcm_bustype, btparam, &err);
914 #ifndef WLC_HIGH_ONLY
918 printf("%s: %s driver failed with code %d\n", KBUILD_MODNAME,
919 EPI_VERSION_STR, err);
922 wl->pub = wlc_pub(wl->wlc);
924 wl->pub->ieee_hw = hw;
925 ASSERT(wl->pub->ieee_hw);
926 ASSERT(wl->pub->ieee_hw->priv == wl);
929 REGOPSSET(osh, (osl_rreg_fn_t) wlc_reg_read,
930 (osl_wreg_fn_t) wlc_reg_write, wl->wlc);
931 wl->rpc_dispatch_ctx.rpc = wl->rpc;
932 wl->rpc_dispatch_ctx.wlc = wl->wlc;
933 bcm_rpc_rxcb_init(wl->rpc, wl, wl_rpc_dispatch_schedule, wl,
934 wl_rpc_down, NULL, NULL);
935 #endif /* WLC_HIGH_ONLY */
938 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
939 WL_ERROR(("wl%d: Error setting MPC variable to 0\n",
944 /* Set SDIO drive strength */
945 wlc_iovar_setint(wl->wlc, "sd_drivestrength", sd_drivestrength);
949 /* register our interrupt handler */
950 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
951 WL_ERROR(("wl%d: request_irq() failed\n", unit));
957 /* register module */
958 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
961 if (ieee_hw_init(hw)) {
962 WL_ERROR(("wl%d: %s: ieee_hw_init failed!\n", unit, __func__));
966 bcopy(&wl->pub->cur_etheraddr, perm, ETHER_ADDR_LEN);
967 ASSERT(is_valid_ether_addr(perm));
968 SET_IEEE80211_PERM_ADDR(hw, perm);
970 err = ieee80211_register_hw(hw);
972 WL_ERROR(("%s: ieee80211_register_hw failed, status %d\n",
976 if (wl->pub->srom_ccode[0])
977 err = wl_set_hint(wl, wl->pub->srom_ccode);
979 err = wl_set_hint(wl, "US");
981 WL_ERROR(("%s: regulatory_hint failed, status %d\n", __func__,
984 #ifndef WLC_HIGH_ONLY
985 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
986 EPI_VERSION_STR " (" PHY_VERSION_STR ")", unit));
988 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
989 EPI_VERSION_STR, unit));
993 printf(" (Compiled in " SRCBASE " at " __TIME__ " on " __DATE__ ")");
997 wl->proc_entry = create_proc_entry(PROC_ENTRY_NAME, 0644, NULL);
998 if (wl->proc_entry == NULL) {
999 WL_ERROR(("create_proc_entry failed *******\n"));
1002 wl->proc_entry->read_proc = wl_proc_read;
1003 wl->proc_entry->write_proc = wl_proc_write;
1004 wl->proc_entry->data = wl;
1005 /* wl->proc_entry->owner = THIS_MODULE; */
1007 wl->ioctlbuf = (char *)vmalloc(PAGE_SIZE);
1008 if (wl->ioctlbuf == NULL) {
1009 WL_ERROR(("%s: Vmalloc failed\n", __func__));
1011 wl->ioctlbuf_sz = PAGE_SIZE;
1012 memset(wl->ioctlbuf, 0, PAGE_SIZE);
1013 wl->ioctlbuf[0] = '!';
1024 #define PROC_MESSAGE "Broadcom driver debugger access only. Requires matching 'wl' app\n"
1026 /* OS Entry point when app attempts to read */
1028 wl_proc_read(char *buffer, char **start, off_t offset, int length, int *eof,
1031 wl_info_t *wl = (wl_info_t *) data;
1033 switch (wl->proc_state) {
1038 case WL_PROC_HAVE_IOC:
1039 /* Give the processed buffer back to userland */
1040 if (!wl->ioctl_in_progress) {
1041 WL_ERROR(("%s: No ioctl in progress nothing to read, 2\n", __func__));
1045 if (wl->ioc.len > wl->ioctlbuf_sz) {
1047 bcopy(wl->ioctlbuf, buffer + offset, wl->ioc.len);
1049 wl->ioctl_in_progress = 0;
1050 return wl->ioc.len + offset;
1052 case WL_PROC_HAVE_BUF:
1053 /* Give the processed IOC back to userland */
1054 if (!wl->ioctl_in_progress) {
1055 WL_ERROR(("%s: No ioctl in progress nothing to read, 1\n", __func__));
1058 if (length != sizeof(wl_ioctl_t)) {
1059 WL_ERROR(("%s: Reading ioc but len != sizeof(wl_ioctl_t)\n", __func__));
1062 bcopy(&wl->ioc, buffer + offset, length);
1064 return length + offset;
1067 WL_ERROR(("%s: Proc read out of sync. proc_state %d, ioctl_in_progress %d\n", __func__, wl->proc_state, wl->ioctl_in_progress));
1070 WL_ERROR(("%s: Invalid ioctl!!!\n", __func__));
1074 /* OS Entry point when app attempts to write */
1076 wl_proc_write(struct file *filp, const char __user *buff, unsigned long length,
1079 wl_info_t *wl = (wl_info_t *) data;
1082 switch (wl->proc_state) {
1085 if (wl->ioctl_in_progress) {
1086 WL_ERROR(("%s: ioctl still in progress\n", __func__));
1089 if (length != sizeof(wl_ioctl_t)) {
1090 WL_ERROR(("%s: Expecting ioctl sized buf\n", __func__));
1093 if (copy_from_user(&wl->ioc, buff, sizeof(wl_ioctl_t))) {
1094 WL_ERROR(("%s: copy from user failed\n", __func__));
1098 wl->ioctl_in_progress++;
1099 return sizeof(wl_ioctl_t);
1101 case WL_PROC_HAVE_IOC:
1102 if (!wl->ioctl_in_progress) {
1103 WL_ERROR(("%s: Ioctl not ready yet 1\n", __func__));
1106 if (wl->ioctlbuf_sz < length) {
1107 WL_ERROR(("%s: Buf write, ioctl buf %d not big enough too hold buffer %d\n", __func__, (int)sizeof(wl->ioctlbuf), (int)length));
1108 WL_ERROR(("Shortening input\n"));
1109 length = wl->ioctlbuf_sz;
1111 if (length != wl->ioc.len) {
1112 WL_ERROR(("%s: ioc.len %d != length param %d\n",
1113 __func__, wl->ioc.len, (int)length));
1116 if (copy_from_user(wl->ioctlbuf, buff, length)) {
1117 WL_ERROR(("%s: copy from user of %d bytes failed\n",
1118 __func__, (int)length));
1125 wlc_ioctl(wl->wlc, wl->ioc.cmd, wl->ioctlbuf, wl->ioc.len,
1134 case WL_PROC_HAVE_BUF:
1135 WL_ERROR(("%s: Illegal write. Rejecting.\n", __func__));
1138 WL_ERROR(("%s: Proc write out of sync. proc_state %d, ioctl_in_progress %d\n", __func__, wl->proc_state, wl->ioctl_in_progress));
1143 #ifdef WLC_HIGH_ONLY
1144 static void *wl_dbus_probe_cb(void *arg, const char *desc, uint32 bustype,
1148 WL_ERROR(("%s:\n", __func__));
1150 wl = wl_attach(BCM_DNGL_VID, BCM_DNGL_BDC_PID, (ulong) NULL, RPC_BUS,
1153 WL_ERROR(("%s: wl_attach failed\n", __func__));
1156 /* This is later passed to wl_dbus_disconnect_cb */
1160 static void wl_dbus_disconnect_cb(void *arg)
1162 wl_info_t *wl = arg;
1164 WL_ERROR(("%s:\n", __func__));
1167 #ifdef WLC_HIGH_ONLY
1168 if (wl->pub->ieee_hw) {
1169 ieee80211_unregister_hw(wl->pub->ieee_hw);
1170 WL_ERROR(("%s: Back from down\n", __func__));
1172 wlc_device_removed(wl->wlc);
1173 wlc_bmac_dngl_reboot(wl->rpc);
1174 bcm_rpc_down(wl->rpc);
1179 #ifdef WLC_HIGH_ONLY
1180 if (wl->pub->ieee_hw) {
1181 ieee80211_free_hw(wl->pub->ieee_hw);
1182 WL_ERROR(("%s: Back from ieee80211_free_hw\n",
1184 wl->pub->ieee_hw = NULL;
1190 #endif /* WLC_HIGH_ONLY */
1193 static void __devexit wl_remove(struct pci_dev *pdev);
1196 #define CHAN2GHZ(channel, freqency, chflags) { \
1197 .band = IEEE80211_BAND_2GHZ, \
1198 .center_freq = (freqency), \
1199 .hw_value = (channel), \
1201 .max_antenna_gain = 0, \
1205 static struct ieee80211_channel wl_2ghz_chantable[] = {
1206 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
1207 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
1208 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
1209 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
1210 CHAN2GHZ(5, 2432, 0),
1211 CHAN2GHZ(6, 2437, 0),
1212 CHAN2GHZ(7, 2442, 0),
1213 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
1214 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
1215 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
1216 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
1218 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1219 IEEE80211_CHAN_NO_HT40PLUS),
1221 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1222 IEEE80211_CHAN_NO_HT40PLUS),
1224 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1225 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
1228 #define CHAN5GHZ(channel, chflags) { \
1229 .band = IEEE80211_BAND_5GHZ, \
1230 .center_freq = 5000 + 5*(channel), \
1231 .hw_value = (channel), \
1233 .max_antenna_gain = 0, \
1237 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
1239 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
1240 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
1241 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
1242 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
1245 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1246 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1248 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1249 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1251 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1252 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1254 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1255 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1258 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1259 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1261 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1262 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1264 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1265 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1267 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1268 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1270 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1271 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1273 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1274 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1276 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1277 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1279 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1280 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1282 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1283 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1285 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1286 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1288 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1289 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
1290 IEEE80211_CHAN_NO_HT40MINUS),
1292 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
1293 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
1294 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
1295 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
1296 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
1299 #define RATE(rate100m, _flags) { \
1300 .bitrate = (rate100m), \
1301 .flags = (_flags), \
1302 .hw_value = (rate100m / 5), \
1305 static struct ieee80211_rate wl_legacy_ratetable[] = {
1307 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
1308 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
1309 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
1320 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
1321 .band = IEEE80211_BAND_2GHZ,
1322 .channels = wl_2ghz_chantable,
1323 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
1324 .bitrates = wl_legacy_ratetable,
1325 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
1327 /* from include/linux/ieee80211.h */
1328 .cap = IEEE80211_HT_CAP_GRN_FLD |
1329 IEEE80211_HT_CAP_SGI_20 |
1330 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
1331 #ifdef WLC_HIGH_ONLY
1332 .ht_supported = true,
1333 .ampdu_factor = AMPDU_RX_FACTOR_16K,
1335 .ht_supported = true,
1336 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1338 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1340 /* placeholders for now */
1341 #ifdef WLC_HIGH_ONLY
1343 * rx_mask[0] = 0xff by default
1344 * rx_mask[1] = 0xff if number of rx chain >=2
1345 * rx_mask[2] = 0xff if number of rx chain >=3
1346 * rx_mask[4] = 1 if 40Mhz is supported
1348 .rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0},
1349 .rx_highest = 72, /* max rate of single stream */
1351 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1354 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1358 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
1359 .band = IEEE80211_BAND_5GHZ,
1360 .channels = wl_5ghz_nphy_chantable,
1361 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
1362 .bitrates = wl_legacy_ratetable + 4,
1363 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1365 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1366 .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 */
1367 .ht_supported = true,
1368 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1369 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1371 /* placeholders for now */
1372 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1374 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1378 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1380 wl_info_t *wl = HW_TO_WL(hw);
1386 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1387 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1389 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1390 WL_ERROR(("Phy list failed\n"));
1392 WL_NONE(("%s: phylist = %c\n", __func__, phy_list[0]));
1394 #ifndef WLC_HIGH_ONLY
1395 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1396 if (phy_list[0] == 'c') {
1398 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1399 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1402 if (phy_list[0] == 's') {
1404 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1410 /* Assume all bands use the same phy. True for 11n devices. */
1411 if (NBANDS_PUB(wl->pub) > 1) {
1413 #ifndef WLC_HIGH_ONLY
1414 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1416 if (phy_list[0] == 's') {
1418 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1425 WL_NONE(("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g));
1430 static int ieee_hw_init(struct ieee80211_hw *hw)
1432 hw->flags = IEEE80211_HW_SIGNAL_DBM
1433 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1434 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1435 | IEEE80211_HW_AMPDU_AGGREGATION;
1437 hw->extra_tx_headroom = wlc_get_header_len();
1438 /* FIXME: should get this from wlc->machwcap */
1440 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1441 * mac80211/status.c:ieee80211_tx_status() checks this value,
1442 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1443 * appears to always set 3 rates
1445 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1447 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1448 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1450 hw->rate_control_algorithm = "minstrel_ht";
1452 hw->sta_data_size = sizeof(struct scb);
1453 return ieee_hw_rate_init(hw);
1458 * determines if a device is a WL device, and if so, attaches it.
1460 * This function determines if a device pointed to by pdev is a WL device,
1461 * and if so, performs a wl_attach() on it.
1465 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1469 struct ieee80211_hw *hw;
1474 WL_TRACE(("%s: bus %d slot %d func %d irq %d\n", __func__,
1475 pdev->bus->number, PCI_SLOT(pdev->devfn),
1476 PCI_FUNC(pdev->devfn), pdev->irq));
1478 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1479 (((pdev->device & 0xff00) != 0x4300) &&
1480 ((pdev->device & 0xff00) != 0x4700) &&
1481 ((pdev->device < 43000) || (pdev->device > 43999))))
1484 rc = pci_enable_device(pdev);
1486 WL_ERROR(("%s: Cannot enable device %d-%d_%d\n", __func__,
1487 pdev->bus->number, PCI_SLOT(pdev->devfn),
1488 PCI_FUNC(pdev->devfn)));
1491 pci_set_master(pdev);
1493 pci_read_config_dword(pdev, 0x40, &val);
1494 if ((val & 0x0000ff00) != 0)
1495 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1497 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
1499 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
1504 SET_IEEE80211_DEV(hw, &pdev->dev);
1506 pci_set_drvdata(pdev, hw);
1508 bzero(hw->priv, sizeof(*wl));
1510 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1511 PCI_BUS, pdev, pdev->irq);
1515 WL_ERROR(("%s: err_1: Major hoarkage\n", __func__));
1520 static int wl_suspend(struct pci_dev *pdev, DRV_SUSPEND_STATE_TYPE state)
1523 struct ieee80211_hw *hw;
1525 WL_TRACE(("wl: wl_suspend\n"));
1527 hw = pci_get_drvdata(pdev);
1530 WL_ERROR(("wl: wl_suspend: pci_get_drvdata failed\n"));
1536 wl->pub->hw_up = FALSE;
1538 PCI_SAVE_STATE(pdev, wl->pci_psstate);
1539 pci_disable_device(pdev);
1540 return pci_set_power_state(pdev, PCI_D3hot);
1543 static int wl_resume(struct pci_dev *pdev)
1546 struct ieee80211_hw *hw;
1550 WL_TRACE(("wl: wl_resume\n"));
1551 hw = pci_get_drvdata(pdev);
1554 WL_ERROR(("wl: wl_resume: pci_get_drvdata failed\n"));
1558 err = pci_set_power_state(pdev, PCI_D0);
1562 PCI_RESTORE_STATE(pdev, wl->pci_psstate);
1564 err = pci_enable_device(pdev);
1568 pci_set_master(pdev);
1570 pci_read_config_dword(pdev, 0x40, &val);
1571 if ((val & 0x0000ff00) != 0)
1572 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1580 #endif /* LINUXSTA_PS */
1582 static void __devexit wl_remove(struct pci_dev *pdev)
1585 struct ieee80211_hw *hw;
1587 hw = pci_get_drvdata(pdev);
1590 WL_ERROR(("wl: wl_remove: pci_get_drvdata failed\n"));
1593 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1594 WL_ERROR(("wl: wl_remove: wlc_chipmatch failed\n"));
1598 ieee80211_unregister_hw(hw);
1603 WL_NONE(("%s: Down\n", __func__));
1605 pci_disable_device(pdev);
1609 pci_set_drvdata(pdev, NULL);
1610 ieee80211_free_hw(hw);
1613 static struct pci_driver wl_pci_driver = {
1619 #endif /* LINUXSTA_PS */
1620 remove:__devexit_p(wl_remove),
1621 id_table:wl_id_table,
1623 #endif /* !BCMSDIO */
1626 * This is the main entry point for the WL driver.
1628 * This function determines if a device pointed to by pdev is a WL device,
1629 * and if so, performs a wl_attach() on it.
1632 static int __init wl_module_init(void)
1634 int error = -ENODEV;
1637 if (msglevel != 0xdeadbeef)
1638 wl_msg_level = msglevel;
1640 char *var = getvar(NULL, "wl_msglevel");
1642 wl_msg_level = bcm_strtoul(var, NULL, 0);
1644 #ifndef WLC_HIGH_ONLY
1646 extern uint32 phyhal_msg_level;
1648 if (phymsglevel != 0xdeadbeef)
1649 phyhal_msg_level = phymsglevel;
1651 char *var = getvar(NULL, "phy_msglevel");
1653 phyhal_msg_level = bcm_strtoul(var, NULL, 0);
1656 #endif /* WLC_HIGH_ONLY */
1660 error = pci_module_init(&wl_pci_driver);
1664 #endif /* !BCMSDIO */
1666 #ifdef WLC_HIGH_ONLY
1667 /* BMAC_NOTE: define hardcode number, why NODEVICE is ok ? */
1669 dbus_register(BCM_DNGL_VID, 0, wl_dbus_probe_cb,
1670 wl_dbus_disconnect_cb, NULL, NULL, NULL);
1671 if (error == DBUS_ERR_NODEVICE) {
1674 #endif /* WLC_HIGH_ONLY */
1680 * This function unloads the WL driver from the system.
1682 * This function unconditionally unloads the WL driver module from the
1686 static void __exit wl_module_exit(void)
1689 pci_unregister_driver(&wl_pci_driver);
1690 #endif /* !BCMSDIO */
1692 #ifdef WLC_HIGH_ONLY
1694 #endif /* WLC_HIGH_ONLY */
1697 module_init(wl_module_init);
1698 module_exit(wl_module_exit);
1701 * This function frees the WL per-device resources.
1703 * This function frees resources owned by the WL device pointed to
1704 * by the wl parameter.
1707 void wl_free(wl_info_t *wl)
1709 wl_timer_t *t, *next;
1713 #ifndef WLC_HIGH_ONLY
1714 /* free ucode data */
1716 wl_ucode_data_free();
1718 free_irq(wl->irq, wl);
1722 tasklet_kill(&wl->tasklet);
1725 wlc_module_unregister(wl->pub, "linux", wl);
1728 /* free common resources */
1730 wlc_detach(wl->wlc);
1735 /* virtual interface deletion is deferred so we cannot spinwait */
1737 /* wait for all pending callbacks to complete */
1738 while (atomic_read(&wl->callbacks) > 0)
1742 for (t = wl->timers; t; t = next) {
1746 MFREE(wl->osh, t->name, strlen(t->name) + 1);
1748 MFREE(wl->osh, t, sizeof(wl_timer_t));
1751 if (wl->ioctlbuf_sz) {
1752 remove_proc_entry(PROC_ENTRY_NAME, NULL);
1753 vfree(wl->ioctlbuf);
1754 wl->ioctlbuf_sz = 0;
1760 * unregister_netdev() calls get_stats() which may read chip registers
1761 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1763 if (wl->regsva && BUSTYPE(wl->bcm_bustype) != SDIO_BUS &&
1764 BUSTYPE(wl->bcm_bustype) != JTAG_BUS) {
1765 iounmap((void *)wl->regsva);
1769 #ifdef WLC_HIGH_ONLY
1775 bcm_rpc_detach(wl->rpc);
1780 bcm_rpc_tp_detach(wl->rpc_th);
1783 #endif /* WLC_HIGH_ONLY */
1785 if (osl_malloced(osh)) {
1786 printf("**** Memory leak of bytes %d\n", osl_malloced(osh));
1787 ASSERT(0 && "Memory Leak");
1794 /* transmit a packet */
1795 static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
1800 return wl_start_int(wl, WL_TO_HW(wl), skb);
1802 #endif /* WLC_LOW */
1804 static int BCMFASTPATH
1805 wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1807 #ifdef WLC_HIGH_ONLY
1810 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1811 #ifdef WLC_HIGH_ONLY
1814 return NETDEV_TX_OK;
1817 void wl_txflowcontrol(wl_info_t *wl, struct wl_if *wlif, bool state, int prio)
1819 WL_ERROR(("Shouldn't be here %s\n", __func__));
1822 #if defined(WLC_HIGH_ONLY)
1823 /* Schedule a completion handler to run at safe time */
1825 wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *task),
1830 WL_TRACE(("wl%d: wl_schedule_task\n", wl->pub->unit));
1832 task = osl_malloc(wl->osh, sizeof(wl_task_t));
1834 WL_ERROR(("wl%d: wl_schedule_task: out of memory, malloced %d bytes\n", wl->pub->unit, osl_malloced(wl->osh)));
1838 MY_INIT_WORK(&task->work, (work_func_t) fn);
1839 task->context = context;
1841 if (!schedule_work(&task->work)) {
1842 WL_ERROR(("wl%d: schedule_work() failed\n", wl->pub->unit));
1843 MFREE(wl->osh, task, sizeof(wl_task_t));
1847 atomic_inc(&wl->callbacks);
1851 #endif /* defined(WLC_HIGH_ONLY) */
1853 void wl_init(wl_info_t *wl)
1855 WL_TRACE(("wl%d: wl_init\n", wl->pub->unit));
1862 uint wl_reset(wl_info_t *wl)
1864 WL_TRACE(("wl%d: wl_reset\n", wl->pub->unit));
1868 /* dpc will not be rescheduled */
1875 * These are interrupt on/off entry points. Disable interrupts
1876 * during interrupt state transition.
1878 void BCMFASTPATH wl_intrson(wl_info_t *wl)
1880 #if defined(WLC_LOW)
1881 unsigned long flags;
1883 INT_LOCK(wl, flags);
1884 wlc_intrson(wl->wlc);
1885 INT_UNLOCK(wl, flags);
1886 #endif /* WLC_LOW */
1889 bool wl_alloc_dma_resources(wl_info_t *wl, uint addrwidth)
1894 uint32 BCMFASTPATH wl_intrsoff(wl_info_t *wl)
1896 #if defined(WLC_LOW)
1897 unsigned long flags;
1900 INT_LOCK(wl, flags);
1901 status = wlc_intrsoff(wl->wlc);
1902 INT_UNLOCK(wl, flags);
1906 #endif /* WLC_LOW */
1909 void wl_intrsrestore(wl_info_t *wl, uint32 macintmask)
1911 #if defined(WLC_LOW)
1912 unsigned long flags;
1914 INT_LOCK(wl, flags);
1915 wlc_intrsrestore(wl->wlc, macintmask);
1916 INT_UNLOCK(wl, flags);
1917 #endif /* WLC_LOW */
1920 int wl_up(wl_info_t *wl)
1927 error = wlc_up(wl->wlc);
1932 void wl_down(wl_info_t *wl)
1934 uint callbacks, ret_val = 0;
1936 /* call common down function */
1937 ret_val = wlc_down(wl->wlc);
1938 callbacks = atomic_read(&wl->callbacks) - ret_val;
1940 /* wait for down callbacks to complete */
1943 #ifndef WLC_HIGH_ONLY
1944 /* For HIGH_only driver, it's important to actually schedule other work,
1945 * not just spin wait since everything runs at schedule level
1947 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1948 #endif /* WLC_HIGH_ONLY */
1953 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1955 #if defined(WLC_LOW)
1958 unsigned long flags;
1960 wl = (wl_info_t *) dev_id;
1962 WL_ISRLOCK(wl, flags);
1964 /* call common first level interrupt handler */
1965 ours = wlc_isr(wl->wlc, &wantdpc);
1967 /* if more to do... */
1970 /* ...and call the second level interrupt handler */
1972 ASSERT(wl->resched == FALSE);
1973 tasklet_schedule(&wl->tasklet);
1977 WL_ISRUNLOCK(wl, flags);
1979 return IRQ_RETVAL(ours);
1981 return IRQ_RETVAL(0);
1982 #endif /* WLC_LOW */
1985 static void BCMFASTPATH wl_dpc(ulong data)
1990 wl = (wl_info_t *) data;
1994 /* call the common second level interrupt handler */
1997 unsigned long flags;
1999 INT_LOCK(wl, flags);
2000 wlc_intrsupd(wl->wlc);
2001 INT_UNLOCK(wl, flags);
2004 wl->resched = wlc_dpc(wl->wlc, TRUE);
2007 /* wlc_dpc() may bring the driver down */
2011 /* re-schedule dpc */
2013 tasklet_schedule(&wl->tasklet);
2015 /* re-enable interrupts */
2021 #endif /* WLC_LOW */
2024 static void wl_link_up(wl_info_t *wl, char *ifname)
2026 WL_ERROR(("wl%d: link up (%s)\n", wl->pub->unit, ifname));
2029 static void wl_link_down(wl_info_t *wl, char *ifname)
2031 WL_ERROR(("wl%d: link down (%s)\n", wl->pub->unit, ifname));
2034 void wl_event(wl_info_t *wl, char *ifname, wlc_event_t *e)
2037 switch (e->event.event_type) {
2039 case WLC_E_NDIS_LINK:
2040 if (e->event.flags & WLC_EVENT_MSG_LINK)
2041 wl_link_up(wl, ifname);
2043 wl_link_down(wl, ifname);
2050 static void wl_timer(ulong data)
2052 #ifndef WLC_HIGH_ONLY
2053 _wl_timer((wl_timer_t *) data);
2055 wl_timer_t *t = (wl_timer_t *) data;
2056 wl_schedule_task(t->wl, wl_timer_task, t);
2057 #endif /* WLC_HIGH_ONLY */
2060 static void _wl_timer(wl_timer_t *t)
2066 t->timer.expires = jiffies + t->ms * HZ / 1000;
2067 atomic_inc(&t->wl->callbacks);
2068 add_timer(&t->timer);
2076 atomic_dec(&t->wl->callbacks);
2081 wl_timer_t *wl_init_timer(wl_info_t *wl, void (*fn) (void *arg), void *arg,
2086 t = osl_malloc(wl->osh, sizeof(wl_timer_t));
2088 WL_ERROR(("wl%d: wl_init_timer: out of memory, malloced %d bytes\n", wl->pub->unit, osl_malloced(wl->osh)));
2092 bzero(t, sizeof(wl_timer_t));
2094 init_timer(&t->timer);
2095 t->timer.data = (ulong) t;
2096 t->timer.function = wl_timer;
2100 t->next = wl->timers;
2104 t->name = osl_malloc(wl->osh, strlen(name) + 1);
2106 strcpy(t->name, name);
2112 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
2113 * as well as it's easier to make it periodic
2115 void wl_add_timer(wl_info_t *wl, wl_timer_t *t, uint ms, int periodic)
2119 WL_ERROR(("%s: Already set. Name: %s, per %d\n",
2120 __func__, t->name, periodic));
2126 t->periodic = (bool) periodic;
2128 t->timer.expires = jiffies + ms * HZ / 1000;
2130 atomic_inc(&wl->callbacks);
2131 add_timer(&t->timer);
2134 /* return TRUE if timer successfully deleted, FALSE if still pending */
2135 bool wl_del_timer(wl_info_t *wl, wl_timer_t *t)
2139 if (!del_timer(&t->timer)) {
2142 atomic_dec(&wl->callbacks);
2148 void wl_free_timer(wl_info_t *wl, wl_timer_t *t)
2152 /* delete the timer in case it is active */
2153 wl_del_timer(wl, t);
2155 if (wl->timers == t) {
2156 wl->timers = wl->timers->next;
2159 MFREE(wl->osh, t->name, strlen(t->name) + 1);
2161 MFREE(wl->osh, t, sizeof(wl_timer_t));
2168 if (tmp->next == t) {
2169 tmp->next = t->next;
2172 MFREE(wl->osh, t->name, strlen(t->name) + 1);
2174 MFREE(wl->osh, t, sizeof(wl_timer_t));
2182 static int wl_linux_watchdog(void *ctx)
2184 wl_info_t *wl = (wl_info_t *) ctx;
2185 struct net_device_stats *stats = NULL;
2189 ASSERT(wl->stats_id < 2);
2191 id = 1 - wl->stats_id;
2193 stats = &wl->stats_watchdog[id];
2194 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
2195 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
2196 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
2197 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
2198 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
2199 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
2200 stats->collisions = 0;
2202 stats->rx_length_errors = 0;
2203 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
2204 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
2205 stats->rx_frame_errors = 0;
2206 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
2207 stats->rx_missed_errors = 0;
2209 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
2224 #ifdef WLC_HIGH_ONLY
2225 static void wl_rpc_down(void *wlh)
2227 wl_info_t *wl = (wl_info_t *) (wlh);
2229 wlc_device_removed(wl->wlc);
2234 static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
2241 /* Lock the queue as tasklet could be running at this time */
2242 TXQ_LOCK(wl, flags);
2243 if (wl->txq_head == NULL)
2246 wl->txq_tail->prev = skb;
2250 if (wl->txq_dispatched == FALSE) {
2251 wl->txq_dispatched = TRUE;
2253 if (schedule_work(&wl->txq_task.work)) {
2254 atomic_inc(&wl->callbacks);
2256 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2261 TXQ_UNLOCK(wl, flags);
2267 static void wl_start_txqwork(struct wl_task *task)
2269 wl_info_t *wl = (wl_info_t *) task->context;
2270 struct sk_buff *skb;
2274 WL_TRACE(("wl%d: wl_start_txqwork\n", wl->pub->unit));
2276 /* First remove an entry then go for execution */
2277 TXQ_LOCK(wl, flags);
2278 while (wl->txq_head) {
2280 wl->txq_head = skb->prev;
2282 if (wl->txq_head == NULL)
2283 wl->txq_tail = NULL;
2284 TXQ_UNLOCK(wl, flags);
2286 /* it has WL_LOCK/WL_UNLOCK inside */
2287 wl_start_int(wl, WL_TO_HW(wl), skb);
2289 /* bounded our execution, reshedule ourself next */
2293 TXQ_LOCK(wl, flags);
2297 if (!schedule_work(&wl->txq_task.work)) {
2298 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2300 atomic_dec(&wl->callbacks);
2303 wl->txq_dispatched = FALSE;
2304 TXQ_UNLOCK(wl, flags);
2305 atomic_dec(&wl->callbacks);
2311 static void wl_txq_free(wl_info_t *wl)
2313 struct sk_buff *skb;
2315 if (wl->txq_head == NULL) {
2316 ASSERT(wl->txq_tail == NULL);
2320 while (wl->txq_head) {
2322 wl->txq_head = skb->prev;
2323 PKTFREE(wl->osh, skb, TRUE);
2326 wl->txq_tail = NULL;
2329 static void wl_rpcq_free(wl_info_t *wl)
2333 if (wl->rpcq_head == NULL) {
2334 ASSERT(wl->rpcq_tail == NULL);
2338 while (wl->rpcq_head) {
2339 buf = wl->rpcq_head;
2340 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2341 bcm_rpc_buf_free(wl->rpc_dispatch_ctx.rpc, buf);
2344 wl->rpcq_tail = NULL;
2347 static void wl_rpcq_dispatch(struct wl_task *task)
2349 wl_info_t *wl = (wl_info_t *) task->context;
2353 /* First remove an entry then go for execution */
2354 RPCQ_LOCK(wl, flags);
2355 while (wl->rpcq_head) {
2356 buf = wl->rpcq_head;
2357 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2359 if (wl->rpcq_head == NULL)
2360 wl->rpcq_tail = NULL;
2361 RPCQ_UNLOCK(wl, flags);
2364 wlc_rpc_high_dispatch(&wl->rpc_dispatch_ctx, buf);
2367 RPCQ_LOCK(wl, flags);
2370 wl->rpcq_dispatched = FALSE;
2372 RPCQ_UNLOCK(wl, flags);
2374 MFREE(wl->osh, task, sizeof(wl_task_t));
2375 atomic_dec(&wl->callbacks);
2378 static void wl_rpcq_add(wl_info_t *wl, rpc_buf_t *buf)
2382 bcm_rpc_buf_next_set(wl->rpc_th, buf, NULL);
2384 /* Lock the queue as tasklet could be running at this time */
2385 RPCQ_LOCK(wl, flags);
2386 if (wl->rpcq_head == NULL)
2387 wl->rpcq_head = buf;
2389 bcm_rpc_buf_next_set(wl->rpc_th, wl->rpcq_tail, buf);
2391 wl->rpcq_tail = buf;
2393 if (wl->rpcq_dispatched == FALSE) {
2394 wl->rpcq_dispatched = TRUE;
2395 wl_schedule_task(wl, wl_rpcq_dispatch, wl);
2398 RPCQ_UNLOCK(wl, flags);
2402 static const struct name_entry rpc_name_tbl[] = RPC_ID_TABLE;
2405 /* dongle-side rpc dispatch routine */
2406 static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf)
2409 wl_info_t *wl = (wl_info_t *) ctx;
2410 wlc_rpc_id_t rpc_id;
2413 bcm_xdr_buf_init(&b, bcm_rpc_buf_data(wl->rpc_th, buf),
2414 bcm_rpc_buf_len_get(wl->rpc_th, buf));
2416 err = bcm_xdr_unpack_uint32(&b, &rpc_id);
2418 WL_TRACE(("%s: Dispatch id %s\n", __func__,
2419 WLC_RPC_ID_LOOKUP(rpc_name_tbl, rpc_id)));
2421 /* Handle few emergency ones */
2424 wl_rpcq_add(wl, buf);
2429 static void wl_timer_task(wl_task_t *task)
2431 wl_timer_t *t = (wl_timer_t *) task->context;
2434 MFREE(t->wl->osh, task, sizeof(wl_task_t));
2436 /* This dec is for the task_schedule. The timer related
2437 * callback is decremented in _wl_timer
2439 atomic_dec(&t->wl->callbacks);
2441 #endif /* WLC_HIGH_ONLY */
2443 #ifndef WLC_HIGH_ONLY
2444 char *wl_firmwares[WL_MAX_FW] = {
2450 int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, uint32 idx)
2454 struct wl_fw_hdr *hdr;
2455 for (i = 0; i < wl->fw.fw_cnt; i++) {
2456 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
2457 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
2459 if (hdr->idx == idx) {
2460 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
2461 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
2462 if (*pbuf == NULL) {
2463 printf("fail to alloc %d bytes\n",
2466 bcopy(pdata, *pbuf, hdr->len);
2471 printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
2476 int wl_ucode_init_uint(wl_info_t *wl, uint32 *data, uint32 idx)
2480 struct wl_fw_hdr *hdr;
2481 for (i = 0; i < wl->fw.fw_cnt; i++) {
2482 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
2483 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
2485 if (hdr->idx == idx) {
2486 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
2487 ASSERT(hdr->len == 4);
2488 *data = *((uint32 *) pdata);
2493 printf("ERROR: ucode tag:%d can not be found!\n", idx);
2496 #endif /* WLC_LOW */
2498 static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev)
2501 struct device *device = &pdev->dev;
2505 bzero((void *)&wl->fw, sizeof(struct wl_firmware));
2506 for (i = 0; i < WL_MAX_FW; i++) {
2507 if (wl_firmwares[i] == NULL)
2509 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
2510 UCODE_LOADER_API_VER);
2511 WL_NONE(("request fw %s\n", fw_name));
2512 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
2514 printf("fail to request firmware %s\n", fw_name);
2518 WL_NONE(("request fw %s\n", fw_name));
2519 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
2520 UCODE_LOADER_API_VER);
2521 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
2523 printf("fail to request firmware %s\n", fw_name);
2527 wl->fw.hdr_num_entries[i] =
2528 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
2529 WL_NONE(("request fw %s find: %d entries\n", fw_name,
2530 wl->fw.hdr_num_entries[i]));
2533 wl_ucode_data_init(wl);
2538 void wl_ucode_free_buf(void *p)
2542 #endif /* WLC_LOW */
2544 static void wl_release_fw(wl_info_t *wl)
2547 for (i = 0; i < WL_MAX_FW; i++) {
2548 release_firmware(wl->fw.fw_bin[i]);
2549 release_firmware(wl->fw.fw_hdr[i]);
2552 #endif /* WLC_HIGH_ONLY */