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/kernel.h>
23 #include <linux/etherdevice.h>
24 #include <linux/string.h>
25 #include <linux/pci_ids.h>
26 #define WLC_MAXBSSCFG 1 /* single BSS configs */
29 #include <net/mac80211.h>
32 #include <phy_version.h>
38 #include <wlc_channel.h>
45 #include <wl_export.h>
48 #include "bcm_rpc_tp.h"
54 #include <wl_mac80211.h>
55 #include <linux/firmware.h>
58 #include <d11ucode_ext.h>
62 extern struct device *sdiommc_dev;
65 extern void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg,
67 bool wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw);
68 void wlc_mac_bcn_promisc_change(wlc_info_t *wlc, bool promisc);
69 void wlc_set_addrmatch(wlc_info_t *wlc, int match_reg_offset,
70 const struct ether_addr *addr);
72 static void wl_timer(unsigned long data);
73 static void _wl_timer(wl_timer_t *t);
76 #define RPCQ_LOCK(_wl, _flags) spin_lock_irqsave(&(_wl)->rpcq_lock, (_flags))
77 #define RPCQ_UNLOCK(_wl, _flags) spin_unlock_irqrestore(&(_wl)->rpcq_lock, (_flags))
78 #define TXQ_LOCK(_wl, _flags) spin_lock_irqsave(&(_wl)->txq_lock, (_flags))
79 #define TXQ_UNLOCK(_wl, _flags) spin_unlock_irqrestore(&(_wl)->txq_lock, (_flags))
80 static void wl_rpc_down(void *wlh);
81 static void wl_rpcq_free(wl_info_t *wl);
82 static void wl_rpcq_dispatch(struct wl_task *task);
83 static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf);
84 static void wl_start_txqwork(struct wl_task *task);
85 static void wl_txq_free(wl_info_t *wl);
86 static void wl_timer_task(wl_task_t *task);
87 static int wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *),
89 #endif /* WLC_HIGH_ONLY */
91 static int ieee_hw_init(struct ieee80211_hw *hw);
92 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
94 static int wl_linux_watchdog(void *ctx);
96 /* Flags we support */
97 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
103 FIF_BCN_PRBRESP_PROMISC)
107 struct ieee80211_tkip_data {
108 #define TKIP_KEY_LEN 32
109 u8 key[TKIP_KEY_LEN];
124 u32 dot11RSNAStatsTKIPReplays;
125 u32 dot11RSNAStatsTKIPICVErrors;
126 u32 dot11RSNAStatsTKIPLocalMICFailures;
130 struct crypto_tfm *tfm_arc4;
131 struct crypto_tfm *tfm_michael;
133 /* scratch buffers for virt_to_page() (crypto API) */
134 u8 rx_hdr[16], tx_hdr[16];
137 #ifndef WLC_HIGH_ONLY
138 #define WL_INFO(dev) ((wl_info_t *)(WL_DEV_IF(dev)->wl)) /* points to wl */
139 static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev);
140 static void wl_release_fw(wl_info_t *wl);
143 /* local prototypes */
144 static int wl_start(struct sk_buff *skb, wl_info_t *wl);
145 static int wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw,
146 struct sk_buff *skb);
147 static void wl_dpc(unsigned long data);
149 MODULE_AUTHOR("Broadcom Corporation");
150 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
151 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
152 MODULE_LICENSE("Dual BSD/GPL");
155 /* recognized PCI IDs */
156 static struct pci_device_id wl_id_table[] = {
157 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
158 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
159 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
163 MODULE_DEVICE_TABLE(pci, wl_id_table);
164 static void wl_remove(struct pci_dev *pdev);
165 #endif /* !BCMSDIO */
168 static uint sd_drivestrength = 6;
169 module_param(sd_drivestrength, uint, 0);
173 static int msglevel = 0xdeadbeef;
174 module_param(msglevel, int, 0);
175 #ifndef WLC_HIGH_ONLY
176 static int phymsglevel = 0xdeadbeef;
177 module_param(phymsglevel, int, 0);
178 #endif /* WLC_HIGH_ONLY */
182 module_param(oneonly, int, 0);
185 module_param(piomode, int, 0);
187 static int instance_base; /* Starting instance number */
188 module_param(instance_base, int, 0);
191 static char *macaddr;
192 module_param(macaddr, charp, S_IRUGO);
195 static int nompc = 1;
196 module_param(nompc, int, 0);
198 static char name[IFNAMSIZ] = "eth%d";
199 module_param_string(name, name, IFNAMSIZ, 0);
205 #define WL_MAGIC 0xdeadbeef
207 #define HW_TO_WL(hw) (hw->priv)
208 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
210 static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb);
212 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
214 static int wl_ops_start(struct ieee80211_hw *hw);
215 static void wl_ops_stop(struct ieee80211_hw *hw);
216 static int wl_ops_add_interface(struct ieee80211_hw *hw,
217 struct ieee80211_vif *vif);
218 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
219 struct ieee80211_vif *vif);
220 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
221 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
222 struct ieee80211_vif *vif,
223 struct ieee80211_bss_conf *info,
225 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
226 unsigned int changed_flags,
227 unsigned int *total_flags, u64 multicast);
228 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
230 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
231 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
232 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
233 static int wl_ops_get_stats(struct ieee80211_hw *hw,
234 struct ieee80211_low_level_stats *stats);
235 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
236 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
237 struct ieee80211_vif *vif,
238 enum sta_notify_cmd cmd,
239 struct ieee80211_sta *sta);
240 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
241 const struct ieee80211_tx_queue_params *params);
242 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
243 static int wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
244 struct ieee80211_sta *sta);
245 static int wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
246 struct ieee80211_sta *sta);
247 static int wl_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
248 enum ieee80211_ampdu_mlme_action action,
249 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
252 static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb)
255 wl_info_t *wl = hw->priv;
257 WL_ERROR(("ops->tx called while down\n"));
261 status = wl_start(skb, wl);
266 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
269 wl_info_t *wl = hw->priv;
272 WL_ERROR(("ops->tx called while down\n"));
276 status = wl_start(skb, wl);
281 #endif /* WLC_HIGH_ONLY */
283 static int wl_ops_start(struct ieee80211_hw *hw)
285 wl_info_t *wl = hw->priv;
286 /* struct ieee80211_channel *curchan = hw->conf.channel; */
287 WL_NONE(("%s : Initial channel: %d\n", __func__, curchan->hw_value));
290 ieee80211_wake_queues(hw);
296 static void wl_ops_stop(struct ieee80211_hw *hw)
298 wl_info_t *wl = hw->priv;
302 ieee80211_stop_queues(hw);
309 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
314 /* Just STA for now */
315 if (vif->type != NL80211_IFTYPE_AP &&
316 vif->type != NL80211_IFTYPE_MESH_POINT &&
317 vif->type != NL80211_IFTYPE_STATION &&
318 vif->type != NL80211_IFTYPE_WDS &&
319 vif->type != NL80211_IFTYPE_ADHOC) {
320 WL_ERROR(("%s: Attempt to add type %d, only STA for now\n",
321 __func__, vif->type));
331 WL_ERROR(("%s: wl_up() returned %d\n", __func__, err));
336 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
342 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
343 enum nl80211_channel_type type)
345 wl_info_t *wl = HW_TO_WL(hw);
349 case NL80211_CHAN_HT20:
350 case NL80211_CHAN_NO_HT:
352 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
355 case NL80211_CHAN_HT40MINUS:
356 case NL80211_CHAN_HT40PLUS:
357 WL_ERROR(("%s: Need to implement 40 Mhz Channels!\n",
367 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
369 struct ieee80211_conf *conf = &hw->conf;
370 wl_info_t *wl = HW_TO_WL(hw);
374 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
375 WL_NONE(("%s: Setting listen interval to %d\n",
376 __func__, conf->listen_interval));
378 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
379 WL_ERROR(("%s: Error setting listen_interval\n",
384 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
385 ASSERT(new_int == conf->listen_interval);
387 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
388 WL_NONE(("Need to set monitor mode\n"));
389 if (changed & IEEE80211_CONF_CHANGE_PS)
390 WL_NONE(("Need to set Power-save mode\n"));
392 if (changed & IEEE80211_CONF_CHANGE_POWER) {
393 WL_NONE(("%s: Setting tx power to %d dbm\n", __func__,
396 (wl->wlc, "qtxpower", conf->power_level * 4)) {
397 WL_ERROR(("%s: Error setting power_level\n", __func__));
401 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
402 if (new_int != (conf->power_level * 4))
403 WL_ERROR(("%s: Power level req != actual, %d %d\n",
404 __func__, conf->power_level * 4, new_int));
406 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
407 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
409 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
410 WL_NONE(("%s: srl %d, lrl %d\n", __func__,
411 conf->short_frame_max_tx_count,
412 conf->long_frame_max_tx_count));
414 (wl->wlc, WLC_SET_SRL,
415 conf->short_frame_max_tx_count) < 0) {
416 WL_ERROR(("%s: Error setting srl\n", __func__));
420 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
422 WL_ERROR(("%s: Error setting lrl\n", __func__));
433 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
434 struct ieee80211_vif *vif,
435 struct ieee80211_bss_conf *info, u32 changed)
437 wl_info_t *wl = HW_TO_WL(hw);
444 if (changed & BSS_CHANGED_ASSOC) {
445 WL_ERROR(("Associated:\t%s\n", info->assoc ? "True" : "False"));
446 /* association status changed (associated/disassociated)
447 * also implies a change in the AID.
450 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
451 WL_NONE(("Use_cts_prot:\t%s Implement me\n",
452 info->use_cts_prot ? "True" : "False"));
453 /* CTS protection changed */
455 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
456 WL_NONE(("Short preamble:\t%s Implement me\n",
457 info->use_short_preamble ? "True" : "False"));
458 /* preamble changed */
460 if (changed & BSS_CHANGED_ERP_SLOT) {
461 WL_NONE(("Changing short slot:\t%s\n",
462 info->use_short_slot ? "True" : "False"));
463 if (info->use_short_slot)
467 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
468 /* slot timing changed */
471 if (changed & BSS_CHANGED_HT) {
472 WL_NONE(("%s: HT mode - Implement me\n", __func__));
473 /* 802.11n parameters changed */
475 if (changed & BSS_CHANGED_BASIC_RATES) {
476 WL_NONE(("Need to change Basic Rates:\t0x%x! Implement me\n",
477 (uint32) info->basic_rates));
478 /* Basic rateset changed */
480 if (changed & BSS_CHANGED_BEACON_INT) {
481 WL_NONE(("Beacon Interval:\t%d Implement me\n",
483 /* Beacon interval changed */
485 if (changed & BSS_CHANGED_BSSID) {
486 /* char eabuf[ETHER_ADDR_STR_LEN]; */
487 WL_NONE(("new BSSID:\taid %d bss:%s\n",
489 bcm_ether_ntoa((struct ether_addr *)info->bssid,
491 /* BSSID changed, for whatever reason (IBSS and managed mode) */
492 /* FIXME: need to store bssid in bsscfg */
493 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
494 (struct ether_addr *)info->bssid);
496 if (changed & BSS_CHANGED_BEACON) {
497 WL_ERROR(("BSS_CHANGED_BEACON\n"));
498 /* Beacon data changed, retrieve new beacon (beaconing modes) */
500 if (changed & BSS_CHANGED_BEACON_ENABLED) {
501 WL_ERROR(("Beacon enabled:\t%s\n",
502 info->enable_beacon ? "True" : "False"));
503 /* Beaconing should be enabled/disabled (beaconing modes) */
512 wl_ops_configure_filter(struct ieee80211_hw *hw,
513 unsigned int changed_flags,
514 unsigned int *total_flags, u64 multicast)
516 #ifndef WLC_HIGH_ONLY
517 wl_info_t *wl = hw->priv;
520 changed_flags &= MAC_FILTERS;
521 *total_flags &= MAC_FILTERS;
522 if (changed_flags & FIF_PROMISC_IN_BSS)
523 WL_ERROR(("FIF_PROMISC_IN_BSS\n"));
524 if (changed_flags & FIF_ALLMULTI)
525 WL_ERROR(("FIF_ALLMULTI\n"));
526 if (changed_flags & FIF_FCSFAIL)
527 WL_ERROR(("FIF_FCSFAIL\n"));
528 if (changed_flags & FIF_PLCPFAIL)
529 WL_ERROR(("FIF_PLCPFAIL\n"));
530 if (changed_flags & FIF_CONTROL)
531 WL_ERROR(("FIF_CONTROL\n"));
532 if (changed_flags & FIF_OTHER_BSS)
533 WL_ERROR(("FIF_OTHER_BSS\n"));
534 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
535 WL_NONE(("FIF_BCN_PRBRESP_PROMISC\n"));
536 #ifndef WLC_HIGH_ONLY
538 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
539 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
540 wlc_mac_bcn_promisc_change(wl->wlc, 1);
542 wlc_mac_bcn_promisc_change(wl->wlc, 0);
543 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
552 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
554 WL_ERROR(("%s: Enter\n", __func__));
558 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
560 WL_NONE(("Scan Start\n"));
564 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
566 WL_NONE(("Scan Complete\n"));
570 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
572 WL_ERROR(("%s: Enter\n", __func__));
577 wl_ops_get_stats(struct ieee80211_hw *hw,
578 struct ieee80211_low_level_stats *stats)
580 WL_ERROR(("%s: Enter\n", __func__));
584 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
586 WL_ERROR(("%s: Enter\n", __func__));
591 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
592 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
594 WL_NONE(("%s: Enter\n", __func__));
597 WL_ERROR(("%s: Uknown cmd = %d\n", __func__, cmd));
604 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
605 const struct ieee80211_tx_queue_params *params)
607 wl_info_t *wl = hw->priv;
609 WL_NONE(("%s: Enter (WME config)\n", __func__));
610 WL_NONE(("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
611 params->txop, params->cw_min, params->cw_max, params->aifs));
614 wlc_wme_setparams(wl->wlc, queue, (void *)params, TRUE);
620 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
622 WL_ERROR(("%s: Enter\n", __func__));
627 wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
628 struct ieee80211_sta *sta)
633 wl_info_t *wl = hw->priv;
636 scb = (struct scb *)sta->drv_priv;
637 bzero(scb, sizeof(struct scb));
638 for (i = 0; i < NUMPRIO; i++)
639 scb->seqctl[i] = 0xFFFF;
640 scb->seqctl_nonqos = 0xFFFF;
641 scb->magic = SCB_MAGIC;
643 wl->pub->global_scb = scb;
644 wl->pub->global_ampdu = &(scb->scb_ampdu);
645 wl->pub->global_ampdu->scb = scb;
647 wl->pub->global_ampdu->max_pdu = AMPDU_NUM_MPDU;
649 wl->pub->global_ampdu->max_pdu = 16;
651 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
652 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
654 sta->ht_cap.ht_supported = TRUE;
656 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_16K;
658 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
660 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
661 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
662 IEEE80211_HT_CAP_SGI_20 |
663 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
665 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
670 wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
671 struct ieee80211_sta *sta)
673 WL_NONE(("%s: Enter\n", __func__));
678 wl_ampdu_action(struct ieee80211_hw *hw,
679 struct ieee80211_vif *vif,
680 enum ieee80211_ampdu_mlme_action action,
681 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
684 struct scb *scb = (struct scb *)sta->drv_priv;
686 wl_info_t *wl = hw->priv;
688 ASSERT(scb->magic == SCB_MAGIC);
690 case IEEE80211_AMPDU_RX_START:
691 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_START\n", __func__));
693 case IEEE80211_AMPDU_RX_STOP:
694 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__));
696 case IEEE80211_AMPDU_TX_START:
697 if (!wlc_aggregatable(wl->wlc, tid)) {
698 /* WL_ERROR(("START: tid %d is not agg' able, return FAILURE to stack\n", tid)); */
701 /* XXX: Use the starting sequence number provided ... */
703 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
706 case IEEE80211_AMPDU_TX_STOP:
707 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
709 case IEEE80211_AMPDU_TX_OPERATIONAL:
710 /* Not sure what to do here */
711 /* Power save wakeup */
712 WL_NONE(("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
716 WL_ERROR(("%s: Invalid command, ignoring\n", __func__));
722 static const struct ieee80211_ops wl_ops = {
728 .start = wl_ops_start,
730 .add_interface = wl_ops_add_interface,
731 .remove_interface = wl_ops_remove_interface,
732 .config = wl_ops_config,
733 .bss_info_changed = wl_ops_bss_info_changed,
734 .configure_filter = wl_ops_configure_filter,
735 .set_tim = wl_ops_set_tim,
736 .sw_scan_start = wl_ops_sw_scan_start,
737 .sw_scan_complete = wl_ops_sw_scan_complete,
738 .set_tsf = wl_ops_set_tsf,
739 .get_stats = wl_ops_get_stats,
740 .set_rts_threshold = wl_ops_set_rts_threshold,
741 .sta_notify = wl_ops_sta_notify,
742 .conf_tx = wl_ops_conf_tx,
743 .get_tsf = wl_ops_get_tsf,
744 .sta_add = wl_sta_add,
745 .sta_remove = wl_sta_remove,
746 .ampdu_action = wl_ampdu_action,
749 static int wl_set_hint(wl_info_t *wl, char *abbrev)
751 WL_ERROR(("%s: Sending country code %c%c to MAC80211\n", __func__,
752 abbrev[0], abbrev[1]));
753 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
757 * attach to the WL device.
759 * Attach to the WL device identified by vendor and device parameters.
760 * regs is a host accessible memory address pointing to WL device registers.
762 * wl_attach is not defined as static because in the case where no bus
763 * is defined, wl_attach will never be called, and thus, gcc will issue
764 * a warning that this function is defined but not used if we declare
767 static wl_info_t *wl_attach(uint16 vendor, uint16 device, unsigned long regs,
768 uint bustype, void *btparam, uint irq)
774 unsigned long base_addr;
775 struct ieee80211_hw *hw;
778 unit = wl_found + instance_base;
782 WL_ERROR(("wl%d: unit number overflow, exiting\n", unit));
786 if (oneonly && (unit != instance_base)) {
787 WL_ERROR(("wl%d: wl_attach: oneonly is set, exiting\n", unit));
791 /* Requires pkttag feature */
792 osh = osl_attach(btparam, bustype, TRUE);
796 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
798 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
802 bzero(hw->priv, sizeof(*wl));
805 /* allocate private info */
806 hw = pci_get_drvdata(btparam); /* btparam == pdev */
811 wl->magic = WL_MAGIC;
813 atomic_set(&wl->callbacks, 0);
815 /* setup the bottom half handler */
816 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
819 wl->rpc_th = bcm_rpc_tp_attach(osh, NULL);
820 if (wl->rpc_th == NULL) {
821 WL_ERROR(("wl%d: %s: bcm_rpc_tp_attach failed!\n", unit,
826 wl->rpc = bcm_rpc_attach(NULL, osh, wl->rpc_th);
827 if (wl->rpc == NULL) {
828 WL_ERROR(("wl%d: %s: bcm_rpc_attach failed!\n", unit,
833 /* init tx work queue for wl_start/send pkt; no need to destroy workitem */
834 INIT_WORK(&wl->txq_task.work, (work_func_t) wl_start_txqwork);
835 wl->txq_task.context = wl;
836 #endif /* WLC_HIGH_ONLY */
839 SET_IEEE80211_DEV(hw, sdiommc_dev);
844 if (bustype == PCI_BUS) {
845 /* piomode can be overwritten by command argument */
846 wl->piomode = piomode;
847 WL_TRACE(("PCI/%s\n", wl->piomode ? "PIO" : "DMA"));
848 } else if (bustype == RPC_BUS) {
852 WL_TRACE(("force to PCI\n"));
854 wl->bcm_bustype = bustype;
857 if (wl->bcm_bustype == RPC_BUS) {
858 wl->regsva = (void *)0;
862 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
863 if (wl->regsva == NULL) {
864 WL_ERROR(("wl%d: ioremap() failed\n", unit));
868 spin_lock_init(&wl->rpcq_lock);
869 spin_lock_init(&wl->txq_lock);
871 init_MUTEX(&wl->sem);
873 spin_lock_init(&wl->lock);
874 spin_lock_init(&wl->isr_lock);
877 #ifndef WLC_HIGH_ONLY
879 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
880 printf("%s: Failed to find firmware usually in %s\n",
881 KBUILD_MODNAME, "/lib/firmware/brcm");
883 wl_remove((struct pci_dev *)btparam);
888 /* common load-time initialization */
889 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
890 wl->regsva, wl->bcm_bustype, btparam, &err);
891 #ifndef WLC_HIGH_ONLY
895 printf("%s: %s wlc_attach() failed with code %d\n",
896 KBUILD_MODNAME, EPI_VERSION_STR, err);
899 wl->pub = wlc_pub(wl->wlc);
901 wl->pub->ieee_hw = hw;
902 ASSERT(wl->pub->ieee_hw);
903 ASSERT(wl->pub->ieee_hw->priv == wl);
906 REGOPSSET(osh, (osl_rreg_fn_t) wlc_reg_read,
907 (osl_wreg_fn_t) wlc_reg_write, wl->wlc);
908 wl->rpc_dispatch_ctx.rpc = wl->rpc;
909 wl->rpc_dispatch_ctx.wlc = wl->wlc;
910 bcm_rpc_rxcb_init(wl->rpc, wl, wl_rpc_dispatch_schedule, wl,
911 wl_rpc_down, NULL, NULL);
912 #endif /* WLC_HIGH_ONLY */
915 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
916 WL_ERROR(("wl%d: Error setting MPC variable to 0\n",
921 /* Set SDIO drive strength */
922 wlc_iovar_setint(wl->wlc, "sd_drivestrength", sd_drivestrength);
926 /* register our interrupt handler */
927 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
928 WL_ERROR(("wl%d: request_irq() failed\n", unit));
934 /* register module */
935 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
938 if (ieee_hw_init(hw)) {
939 WL_ERROR(("wl%d: %s: ieee_hw_init failed!\n", unit, __func__));
943 bcopy(&wl->pub->cur_etheraddr, perm, ETHER_ADDR_LEN);
944 ASSERT(is_valid_ether_addr(perm));
945 SET_IEEE80211_PERM_ADDR(hw, perm);
947 err = ieee80211_register_hw(hw);
949 WL_ERROR(("%s: ieee80211_register_hw failed, status %d\n",
953 if (wl->pub->srom_ccode[0])
954 err = wl_set_hint(wl, wl->pub->srom_ccode);
956 err = wl_set_hint(wl, "US");
958 WL_ERROR(("%s: regulatory_hint failed, status %d\n", __func__,
961 #ifndef WLC_HIGH_ONLY
962 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
963 EPI_VERSION_STR " (" PHY_VERSION_STR ")", unit));
965 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
966 EPI_VERSION_STR, unit));
970 printf(" (Compiled in " SRCBASE " at " __TIME__ " on " __DATE__ ")");
984 static void *wl_dbus_probe_cb(void *arg, const char *desc, uint32 bustype,
988 WL_ERROR(("%s:\n", __func__));
990 wl = wl_attach(BCM_DNGL_VID, BCM_DNGL_BDC_PID, (unsigned long) NULL, RPC_BUS,
993 WL_ERROR(("%s: wl_attach failed\n", __func__));
996 /* This is later passed to wl_dbus_disconnect_cb */
1000 static void wl_dbus_disconnect_cb(void *arg)
1002 wl_info_t *wl = arg;
1004 WL_ERROR(("%s:\n", __func__));
1007 #ifdef WLC_HIGH_ONLY
1008 if (wl->pub->ieee_hw) {
1009 ieee80211_unregister_hw(wl->pub->ieee_hw);
1010 WL_ERROR(("%s: Back from down\n", __func__));
1012 wlc_device_removed(wl->wlc);
1013 wlc_bmac_dngl_reboot(wl->rpc);
1014 bcm_rpc_down(wl->rpc);
1019 #ifdef WLC_HIGH_ONLY
1020 if (wl->pub->ieee_hw) {
1021 ieee80211_free_hw(wl->pub->ieee_hw);
1022 WL_ERROR(("%s: Back from ieee80211_free_hw\n",
1024 wl->pub->ieee_hw = NULL;
1030 #endif /* WLC_HIGH_ONLY */
1033 #define CHAN2GHZ(channel, freqency, chflags) { \
1034 .band = IEEE80211_BAND_2GHZ, \
1035 .center_freq = (freqency), \
1036 .hw_value = (channel), \
1038 .max_antenna_gain = 0, \
1042 static struct ieee80211_channel wl_2ghz_chantable[] = {
1043 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
1044 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
1045 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
1046 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
1047 CHAN2GHZ(5, 2432, 0),
1048 CHAN2GHZ(6, 2437, 0),
1049 CHAN2GHZ(7, 2442, 0),
1050 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
1051 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
1052 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
1053 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
1055 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1056 IEEE80211_CHAN_NO_HT40PLUS),
1058 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1059 IEEE80211_CHAN_NO_HT40PLUS),
1061 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1062 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
1065 #define CHAN5GHZ(channel, chflags) { \
1066 .band = IEEE80211_BAND_5GHZ, \
1067 .center_freq = 5000 + 5*(channel), \
1068 .hw_value = (channel), \
1070 .max_antenna_gain = 0, \
1074 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
1076 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
1077 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
1078 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
1079 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
1082 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1083 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1085 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1086 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1088 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1089 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1091 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1092 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1095 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1096 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1098 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1099 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1101 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1102 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1104 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1105 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1107 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1108 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1110 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1111 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1113 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1114 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1116 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1117 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1119 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1120 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1122 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1123 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1125 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1126 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
1127 IEEE80211_CHAN_NO_HT40MINUS),
1129 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
1130 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
1131 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
1132 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
1133 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
1136 #define RATE(rate100m, _flags) { \
1137 .bitrate = (rate100m), \
1138 .flags = (_flags), \
1139 .hw_value = (rate100m / 5), \
1142 static struct ieee80211_rate wl_legacy_ratetable[] = {
1144 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
1145 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
1146 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
1157 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
1158 .band = IEEE80211_BAND_2GHZ,
1159 .channels = wl_2ghz_chantable,
1160 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
1161 .bitrates = wl_legacy_ratetable,
1162 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
1164 /* from include/linux/ieee80211.h */
1165 .cap = IEEE80211_HT_CAP_GRN_FLD |
1166 IEEE80211_HT_CAP_SGI_20 |
1167 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
1168 #ifdef WLC_HIGH_ONLY
1169 .ht_supported = true,
1170 .ampdu_factor = AMPDU_RX_FACTOR_16K,
1172 .ht_supported = true,
1173 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1175 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1177 /* placeholders for now */
1178 #ifdef WLC_HIGH_ONLY
1180 * rx_mask[0] = 0xff by default
1181 * rx_mask[1] = 0xff if number of rx chain >=2
1182 * rx_mask[2] = 0xff if number of rx chain >=3
1183 * rx_mask[4] = 1 if 40Mhz is supported
1185 .rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0},
1186 .rx_highest = 72, /* max rate of single stream */
1188 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1191 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1195 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
1196 .band = IEEE80211_BAND_5GHZ,
1197 .channels = wl_5ghz_nphy_chantable,
1198 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
1199 .bitrates = wl_legacy_ratetable + 4,
1200 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1202 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1203 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT, /* No 40 mhz yet */
1204 .ht_supported = true,
1205 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1206 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1208 /* placeholders for now */
1209 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1211 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1215 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1217 wl_info_t *wl = HW_TO_WL(hw);
1223 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1224 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1226 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1227 WL_ERROR(("Phy list failed\n"));
1229 WL_NONE(("%s: phylist = %c\n", __func__, phy_list[0]));
1231 #ifndef WLC_HIGH_ONLY
1232 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1233 if (phy_list[0] == 'c') {
1235 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1236 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1239 if (phy_list[0] == 's') {
1241 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1247 /* Assume all bands use the same phy. True for 11n devices. */
1248 if (NBANDS_PUB(wl->pub) > 1) {
1250 #ifndef WLC_HIGH_ONLY
1251 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1253 if (phy_list[0] == 's') {
1255 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1262 WL_NONE(("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g));
1267 static int ieee_hw_init(struct ieee80211_hw *hw)
1269 hw->flags = IEEE80211_HW_SIGNAL_DBM
1270 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1271 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1272 | IEEE80211_HW_AMPDU_AGGREGATION;
1274 hw->extra_tx_headroom = wlc_get_header_len();
1275 /* FIXME: should get this from wlc->machwcap */
1277 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1278 * mac80211/status.c:ieee80211_tx_status() checks this value,
1279 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1280 * appears to always set 3 rates
1282 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1284 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1285 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1287 hw->rate_control_algorithm = "minstrel_ht";
1289 hw->sta_data_size = sizeof(struct scb);
1290 return ieee_hw_rate_init(hw);
1295 * determines if a device is a WL device, and if so, attaches it.
1297 * This function determines if a device pointed to by pdev is a WL device,
1298 * and if so, performs a wl_attach() on it.
1302 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1306 struct ieee80211_hw *hw;
1311 WL_TRACE(("%s: bus %d slot %d func %d irq %d\n", __func__,
1312 pdev->bus->number, PCI_SLOT(pdev->devfn),
1313 PCI_FUNC(pdev->devfn), pdev->irq));
1315 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1316 (((pdev->device & 0xff00) != 0x4300) &&
1317 ((pdev->device & 0xff00) != 0x4700) &&
1318 ((pdev->device < 43000) || (pdev->device > 43999))))
1321 rc = pci_enable_device(pdev);
1323 WL_ERROR(("%s: Cannot enable device %d-%d_%d\n", __func__,
1324 pdev->bus->number, PCI_SLOT(pdev->devfn),
1325 PCI_FUNC(pdev->devfn)));
1328 pci_set_master(pdev);
1330 pci_read_config_dword(pdev, 0x40, &val);
1331 if ((val & 0x0000ff00) != 0)
1332 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1334 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
1336 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
1341 SET_IEEE80211_DEV(hw, &pdev->dev);
1343 pci_set_drvdata(pdev, hw);
1345 bzero(hw->priv, sizeof(*wl));
1347 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1348 PCI_BUS, pdev, pdev->irq);
1351 WL_ERROR(("%s: %s: wl_attach failed!\n",
1352 KBUILD_MODNAME, __func__));
1357 WL_ERROR(("%s: err_1: Major hoarkage\n", __func__));
1362 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1365 struct ieee80211_hw *hw;
1367 WL_TRACE(("wl: wl_suspend\n"));
1369 hw = pci_get_drvdata(pdev);
1372 WL_ERROR(("wl: wl_suspend: pci_get_drvdata failed\n"));
1378 wl->pub->hw_up = FALSE;
1380 pci_save_state(pdev, wl->pci_psstate);
1381 pci_disable_device(pdev);
1382 return pci_set_power_state(pdev, PCI_D3hot);
1385 static int wl_resume(struct pci_dev *pdev)
1388 struct ieee80211_hw *hw;
1392 WL_TRACE(("wl: wl_resume\n"));
1393 hw = pci_get_drvdata(pdev);
1396 WL_ERROR(("wl: wl_resume: pci_get_drvdata failed\n"));
1400 err = pci_set_power_state(pdev, PCI_D0);
1404 pci_restore_state(pdev, wl->pci_psstate);
1406 err = pci_enable_device(pdev);
1410 pci_set_master(pdev);
1412 pci_read_config_dword(pdev, 0x40, &val);
1413 if ((val & 0x0000ff00) != 0)
1414 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1422 #endif /* LINUXSTA_PS */
1424 static void wl_remove(struct pci_dev *pdev)
1427 struct ieee80211_hw *hw;
1429 hw = pci_get_drvdata(pdev);
1432 WL_ERROR(("wl: wl_remove: pci_get_drvdata failed\n"));
1435 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1436 WL_ERROR(("wl: wl_remove: wlc_chipmatch failed\n"));
1440 ieee80211_unregister_hw(hw);
1444 WL_NONE(("%s: Down\n", __func__));
1446 pci_disable_device(pdev);
1450 pci_set_drvdata(pdev, NULL);
1451 ieee80211_free_hw(hw);
1454 static struct pci_driver wl_pci_driver = {
1455 .name = "brcm80211",
1456 .probe = wl_pci_probe,
1458 .suspend = wl_suspend,
1459 .resume = wl_resume,
1460 #endif /* LINUXSTA_PS */
1461 .remove = __devexit_p(wl_remove),
1462 .id_table = wl_id_table,
1464 #endif /* !BCMSDIO */
1467 * This is the main entry point for the WL driver.
1469 * This function determines if a device pointed to by pdev is a WL device,
1470 * and if so, performs a wl_attach() on it.
1473 static int __init wl_module_init(void)
1475 int error = -ENODEV;
1478 if (msglevel != 0xdeadbeef)
1479 wl_msg_level = msglevel;
1481 char *var = getvar(NULL, "wl_msglevel");
1483 wl_msg_level = simple_strtoul(var, NULL, 0);
1485 #ifndef WLC_HIGH_ONLY
1487 extern uint32 phyhal_msg_level;
1489 if (phymsglevel != 0xdeadbeef)
1490 phyhal_msg_level = phymsglevel;
1492 char *var = getvar(NULL, "phy_msglevel");
1494 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1497 #endif /* WLC_HIGH_ONLY */
1501 error = pci_register_driver(&wl_pci_driver);
1505 #endif /* !BCMSDIO */
1507 #ifdef WLC_HIGH_ONLY
1508 /* BMAC_NOTE: define hardcode number, why NODEVICE is ok ? */
1510 dbus_register(BCM_DNGL_VID, 0, wl_dbus_probe_cb,
1511 wl_dbus_disconnect_cb, NULL, NULL, NULL);
1512 if (error == DBUS_ERR_NODEVICE) {
1515 #endif /* WLC_HIGH_ONLY */
1521 * This function unloads the WL driver from the system.
1523 * This function unconditionally unloads the WL driver module from the
1527 static void __exit wl_module_exit(void)
1530 pci_unregister_driver(&wl_pci_driver);
1531 #endif /* !BCMSDIO */
1533 #ifdef WLC_HIGH_ONLY
1535 #endif /* WLC_HIGH_ONLY */
1538 module_init(wl_module_init);
1539 module_exit(wl_module_exit);
1542 * This function frees the WL per-device resources.
1544 * This function frees resources owned by the WL device pointed to
1545 * by the wl parameter.
1548 void wl_free(wl_info_t *wl)
1550 wl_timer_t *t, *next;
1554 #ifndef WLC_HIGH_ONLY
1555 /* free ucode data */
1557 wl_ucode_data_free();
1559 free_irq(wl->irq, wl);
1563 tasklet_kill(&wl->tasklet);
1566 wlc_module_unregister(wl->pub, "linux", wl);
1569 /* free common resources */
1571 wlc_detach(wl->wlc);
1576 /* virtual interface deletion is deferred so we cannot spinwait */
1578 /* wait for all pending callbacks to complete */
1579 while (atomic_read(&wl->callbacks) > 0)
1583 for (t = wl->timers; t; t = next) {
1587 MFREE(wl->osh, t->name, strlen(t->name) + 1);
1589 MFREE(wl->osh, t, sizeof(wl_timer_t));
1595 * unregister_netdev() calls get_stats() which may read chip registers
1596 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1598 if (wl->regsva && BUSTYPE(wl->bcm_bustype) != SDIO_BUS &&
1599 BUSTYPE(wl->bcm_bustype) != JTAG_BUS) {
1600 iounmap((void *)wl->regsva);
1604 #ifdef WLC_HIGH_ONLY
1610 bcm_rpc_detach(wl->rpc);
1615 bcm_rpc_tp_detach(wl->rpc_th);
1618 #endif /* WLC_HIGH_ONLY */
1620 if (osl_malloced(osh)) {
1621 printf("**** Memory leak of bytes %d\n", osl_malloced(osh));
1622 ASSERT(0 && "Memory Leak");
1629 /* transmit a packet */
1630 static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
1635 return wl_start_int(wl, WL_TO_HW(wl), skb);
1637 #endif /* WLC_LOW */
1639 static int BCMFASTPATH
1640 wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1642 #ifdef WLC_HIGH_ONLY
1645 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1646 #ifdef WLC_HIGH_ONLY
1649 return NETDEV_TX_OK;
1652 void wl_txflowcontrol(wl_info_t *wl, struct wl_if *wlif, bool state, int prio)
1654 WL_ERROR(("Shouldn't be here %s\n", __func__));
1657 #if defined(WLC_HIGH_ONLY)
1658 /* Schedule a completion handler to run at safe time */
1660 wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *task),
1665 WL_TRACE(("wl%d: wl_schedule_task\n", wl->pub->unit));
1667 task = osl_malloc(wl->osh, sizeof(wl_task_t));
1669 WL_ERROR(("wl%d: wl_schedule_task: out of memory, malloced %d bytes\n", wl->pub->unit, osl_malloced(wl->osh)));
1673 INIT_WORK(&task->work, (work_func_t) fn);
1674 task->context = context;
1676 if (!schedule_work(&task->work)) {
1677 WL_ERROR(("wl%d: schedule_work() failed\n", wl->pub->unit));
1678 MFREE(wl->osh, task, sizeof(wl_task_t));
1682 atomic_inc(&wl->callbacks);
1686 #endif /* defined(WLC_HIGH_ONLY) */
1688 void wl_init(wl_info_t *wl)
1690 WL_TRACE(("wl%d: wl_init\n", wl->pub->unit));
1697 uint wl_reset(wl_info_t *wl)
1699 WL_TRACE(("wl%d: wl_reset\n", wl->pub->unit));
1703 /* dpc will not be rescheduled */
1710 * These are interrupt on/off entry points. Disable interrupts
1711 * during interrupt state transition.
1713 void BCMFASTPATH wl_intrson(wl_info_t *wl)
1715 #if defined(WLC_LOW)
1716 unsigned long flags;
1718 INT_LOCK(wl, flags);
1719 wlc_intrson(wl->wlc);
1720 INT_UNLOCK(wl, flags);
1721 #endif /* WLC_LOW */
1724 bool wl_alloc_dma_resources(wl_info_t *wl, uint addrwidth)
1729 uint32 BCMFASTPATH wl_intrsoff(wl_info_t *wl)
1731 #if defined(WLC_LOW)
1732 unsigned long flags;
1735 INT_LOCK(wl, flags);
1736 status = wlc_intrsoff(wl->wlc);
1737 INT_UNLOCK(wl, flags);
1741 #endif /* WLC_LOW */
1744 void wl_intrsrestore(wl_info_t *wl, uint32 macintmask)
1746 #if defined(WLC_LOW)
1747 unsigned long flags;
1749 INT_LOCK(wl, flags);
1750 wlc_intrsrestore(wl->wlc, macintmask);
1751 INT_UNLOCK(wl, flags);
1752 #endif /* WLC_LOW */
1755 int wl_up(wl_info_t *wl)
1762 error = wlc_up(wl->wlc);
1767 void wl_down(wl_info_t *wl)
1769 uint callbacks, ret_val = 0;
1771 /* call common down function */
1772 ret_val = wlc_down(wl->wlc);
1773 callbacks = atomic_read(&wl->callbacks) - ret_val;
1775 /* wait for down callbacks to complete */
1778 #ifndef WLC_HIGH_ONLY
1779 /* For HIGH_only driver, it's important to actually schedule other work,
1780 * not just spin wait since everything runs at schedule level
1782 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1783 #endif /* WLC_HIGH_ONLY */
1788 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1790 #if defined(WLC_LOW)
1793 unsigned long flags;
1795 wl = (wl_info_t *) dev_id;
1797 WL_ISRLOCK(wl, flags);
1799 /* call common first level interrupt handler */
1800 ours = wlc_isr(wl->wlc, &wantdpc);
1802 /* if more to do... */
1805 /* ...and call the second level interrupt handler */
1807 ASSERT(wl->resched == FALSE);
1808 tasklet_schedule(&wl->tasklet);
1812 WL_ISRUNLOCK(wl, flags);
1814 return IRQ_RETVAL(ours);
1816 return IRQ_RETVAL(0);
1817 #endif /* WLC_LOW */
1820 static void BCMFASTPATH wl_dpc(unsigned long data)
1825 wl = (wl_info_t *) data;
1829 /* call the common second level interrupt handler */
1832 unsigned long flags;
1834 INT_LOCK(wl, flags);
1835 wlc_intrsupd(wl->wlc);
1836 INT_UNLOCK(wl, flags);
1839 wl->resched = wlc_dpc(wl->wlc, TRUE);
1842 /* wlc_dpc() may bring the driver down */
1846 /* re-schedule dpc */
1848 tasklet_schedule(&wl->tasklet);
1850 /* re-enable interrupts */
1856 #endif /* WLC_LOW */
1859 static void wl_link_up(wl_info_t *wl, char *ifname)
1861 WL_ERROR(("wl%d: link up (%s)\n", wl->pub->unit, ifname));
1864 static void wl_link_down(wl_info_t *wl, char *ifname)
1866 WL_ERROR(("wl%d: link down (%s)\n", wl->pub->unit, ifname));
1869 void wl_event(wl_info_t *wl, char *ifname, wlc_event_t *e)
1872 switch (e->event.event_type) {
1874 case WLC_E_NDIS_LINK:
1875 if (e->event.flags & WLC_EVENT_MSG_LINK)
1876 wl_link_up(wl, ifname);
1878 wl_link_down(wl, ifname);
1885 static void wl_timer(unsigned long data)
1887 #ifndef WLC_HIGH_ONLY
1888 _wl_timer((wl_timer_t *) data);
1890 wl_timer_t *t = (wl_timer_t *) data;
1891 wl_schedule_task(t->wl, wl_timer_task, t);
1892 #endif /* WLC_HIGH_ONLY */
1895 static void _wl_timer(wl_timer_t *t)
1901 t->timer.expires = jiffies + t->ms * HZ / 1000;
1902 atomic_inc(&t->wl->callbacks);
1903 add_timer(&t->timer);
1911 atomic_dec(&t->wl->callbacks);
1916 wl_timer_t *wl_init_timer(wl_info_t *wl, void (*fn) (void *arg), void *arg,
1921 t = osl_malloc(wl->osh, sizeof(wl_timer_t));
1923 WL_ERROR(("wl%d: wl_init_timer: out of memory, malloced %d bytes\n", wl->pub->unit, osl_malloced(wl->osh)));
1927 bzero(t, sizeof(wl_timer_t));
1929 init_timer(&t->timer);
1930 t->timer.data = (unsigned long) t;
1931 t->timer.function = wl_timer;
1935 t->next = wl->timers;
1939 t->name = osl_malloc(wl->osh, strlen(name) + 1);
1941 strcpy(t->name, name);
1947 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1948 * as well as it's easier to make it periodic
1950 void wl_add_timer(wl_info_t *wl, wl_timer_t *t, uint ms, int periodic)
1954 WL_ERROR(("%s: Already set. Name: %s, per %d\n",
1955 __func__, t->name, periodic));
1961 t->periodic = (bool) periodic;
1963 t->timer.expires = jiffies + ms * HZ / 1000;
1965 atomic_inc(&wl->callbacks);
1966 add_timer(&t->timer);
1969 /* return TRUE if timer successfully deleted, FALSE if still pending */
1970 bool wl_del_timer(wl_info_t *wl, wl_timer_t *t)
1974 if (!del_timer(&t->timer)) {
1977 atomic_dec(&wl->callbacks);
1983 void wl_free_timer(wl_info_t *wl, wl_timer_t *t)
1987 /* delete the timer in case it is active */
1988 wl_del_timer(wl, t);
1990 if (wl->timers == t) {
1991 wl->timers = wl->timers->next;
1994 MFREE(wl->osh, t->name, strlen(t->name) + 1);
1996 MFREE(wl->osh, t, sizeof(wl_timer_t));
2003 if (tmp->next == t) {
2004 tmp->next = t->next;
2007 MFREE(wl->osh, t->name, strlen(t->name) + 1);
2009 MFREE(wl->osh, t, sizeof(wl_timer_t));
2017 static int wl_linux_watchdog(void *ctx)
2019 wl_info_t *wl = (wl_info_t *) ctx;
2020 struct net_device_stats *stats = NULL;
2024 ASSERT(wl->stats_id < 2);
2026 id = 1 - wl->stats_id;
2028 stats = &wl->stats_watchdog[id];
2029 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
2030 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
2031 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
2032 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
2033 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
2034 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
2035 stats->collisions = 0;
2037 stats->rx_length_errors = 0;
2038 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
2039 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
2040 stats->rx_frame_errors = 0;
2041 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
2042 stats->rx_missed_errors = 0;
2044 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
2059 #ifdef WLC_HIGH_ONLY
2060 static void wl_rpc_down(void *wlh)
2062 wl_info_t *wl = (wl_info_t *) (wlh);
2064 wlc_device_removed(wl->wlc);
2069 static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
2072 unsigned long flags;
2076 /* Lock the queue as tasklet could be running at this time */
2077 TXQ_LOCK(wl, flags);
2078 if (wl->txq_head == NULL)
2081 wl->txq_tail->prev = skb;
2085 if (wl->txq_dispatched == FALSE) {
2086 wl->txq_dispatched = TRUE;
2088 if (schedule_work(&wl->txq_task.work)) {
2089 atomic_inc(&wl->callbacks);
2091 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2096 TXQ_UNLOCK(wl, flags);
2102 static void wl_start_txqwork(struct wl_task *task)
2104 wl_info_t *wl = (wl_info_t *) task->context;
2105 struct sk_buff *skb;
2106 unsigned long flags;
2109 WL_TRACE(("wl%d: wl_start_txqwork\n", wl->pub->unit));
2111 /* First remove an entry then go for execution */
2112 TXQ_LOCK(wl, flags);
2113 while (wl->txq_head) {
2115 wl->txq_head = skb->prev;
2117 if (wl->txq_head == NULL)
2118 wl->txq_tail = NULL;
2119 TXQ_UNLOCK(wl, flags);
2121 /* it has WL_LOCK/WL_UNLOCK inside */
2122 wl_start_int(wl, WL_TO_HW(wl), skb);
2124 /* bounded our execution, reshedule ourself next */
2128 TXQ_LOCK(wl, flags);
2132 if (!schedule_work(&wl->txq_task.work)) {
2133 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2135 atomic_dec(&wl->callbacks);
2138 wl->txq_dispatched = FALSE;
2139 TXQ_UNLOCK(wl, flags);
2140 atomic_dec(&wl->callbacks);
2146 static void wl_txq_free(wl_info_t *wl)
2148 struct sk_buff *skb;
2150 if (wl->txq_head == NULL) {
2151 ASSERT(wl->txq_tail == NULL);
2155 while (wl->txq_head) {
2157 wl->txq_head = skb->prev;
2158 PKTFREE(wl->osh, skb, TRUE);
2161 wl->txq_tail = NULL;
2164 static void wl_rpcq_free(wl_info_t *wl)
2168 if (wl->rpcq_head == NULL) {
2169 ASSERT(wl->rpcq_tail == NULL);
2173 while (wl->rpcq_head) {
2174 buf = wl->rpcq_head;
2175 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2176 bcm_rpc_buf_free(wl->rpc_dispatch_ctx.rpc, buf);
2179 wl->rpcq_tail = NULL;
2182 static void wl_rpcq_dispatch(struct wl_task *task)
2184 wl_info_t *wl = (wl_info_t *) task->context;
2186 unsigned long flags;
2188 /* First remove an entry then go for execution */
2189 RPCQ_LOCK(wl, flags);
2190 while (wl->rpcq_head) {
2191 buf = wl->rpcq_head;
2192 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2194 if (wl->rpcq_head == NULL)
2195 wl->rpcq_tail = NULL;
2196 RPCQ_UNLOCK(wl, flags);
2199 wlc_rpc_high_dispatch(&wl->rpc_dispatch_ctx, buf);
2202 RPCQ_LOCK(wl, flags);
2205 wl->rpcq_dispatched = FALSE;
2207 RPCQ_UNLOCK(wl, flags);
2209 MFREE(wl->osh, task, sizeof(wl_task_t));
2210 atomic_dec(&wl->callbacks);
2213 static void wl_rpcq_add(wl_info_t *wl, rpc_buf_t *buf)
2215 unsigned long flags;
2217 bcm_rpc_buf_next_set(wl->rpc_th, buf, NULL);
2219 /* Lock the queue as tasklet could be running at this time */
2220 RPCQ_LOCK(wl, flags);
2221 if (wl->rpcq_head == NULL)
2222 wl->rpcq_head = buf;
2224 bcm_rpc_buf_next_set(wl->rpc_th, wl->rpcq_tail, buf);
2226 wl->rpcq_tail = buf;
2228 if (wl->rpcq_dispatched == FALSE) {
2229 wl->rpcq_dispatched = TRUE;
2230 wl_schedule_task(wl, wl_rpcq_dispatch, wl);
2233 RPCQ_UNLOCK(wl, flags);
2237 static const struct name_entry rpc_name_tbl[] = RPC_ID_TABLE;
2240 /* dongle-side rpc dispatch routine */
2241 static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf)
2244 wl_info_t *wl = (wl_info_t *) ctx;
2245 wlc_rpc_id_t rpc_id;
2248 bcm_xdr_buf_init(&b, bcm_rpc_buf_data(wl->rpc_th, buf),
2249 bcm_rpc_buf_len_get(wl->rpc_th, buf));
2251 err = bcm_xdr_unpack_uint32(&b, &rpc_id);
2253 WL_TRACE(("%s: Dispatch id %s\n", __func__,
2254 WLC_RPC_ID_LOOKUP(rpc_name_tbl, rpc_id)));
2256 /* Handle few emergency ones */
2259 wl_rpcq_add(wl, buf);
2264 static void wl_timer_task(wl_task_t *task)
2266 wl_timer_t *t = (wl_timer_t *) task->context;
2269 MFREE(t->wl->osh, task, sizeof(wl_task_t));
2271 /* This dec is for the task_schedule. The timer related
2272 * callback is decremented in _wl_timer
2274 atomic_dec(&t->wl->callbacks);
2276 #endif /* WLC_HIGH_ONLY */
2278 #ifndef WLC_HIGH_ONLY
2279 char *wl_firmwares[WL_MAX_FW] = {
2285 int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, uint32 idx)
2289 struct wl_fw_hdr *hdr;
2290 for (i = 0; i < wl->fw.fw_cnt; i++) {
2291 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
2292 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
2294 if (hdr->idx == idx) {
2295 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
2296 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
2297 if (*pbuf == NULL) {
2298 printf("fail to alloc %d bytes\n",
2301 bcopy(pdata, *pbuf, hdr->len);
2306 printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
2311 int wl_ucode_init_uint(wl_info_t *wl, uint32 *data, uint32 idx)
2315 struct wl_fw_hdr *hdr;
2316 for (i = 0; i < wl->fw.fw_cnt; i++) {
2317 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
2318 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
2320 if (hdr->idx == idx) {
2321 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
2322 ASSERT(hdr->len == 4);
2323 *data = *((uint32 *) pdata);
2328 printf("ERROR: ucode tag:%d can not be found!\n", idx);
2331 #endif /* WLC_LOW */
2333 static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev)
2336 struct device *device = &pdev->dev;
2340 bzero((void *)&wl->fw, sizeof(struct wl_firmware));
2341 for (i = 0; i < WL_MAX_FW; i++) {
2342 if (wl_firmwares[i] == NULL)
2344 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
2345 UCODE_LOADER_API_VER);
2346 WL_NONE(("request fw %s\n", fw_name));
2347 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
2349 printf("%s: fail to load firmware %s\n",
2350 KBUILD_MODNAME, fw_name);
2354 WL_NONE(("request fw %s\n", fw_name));
2355 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
2356 UCODE_LOADER_API_VER);
2357 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
2359 printf("%s: fail to load firmware %s\n",
2360 KBUILD_MODNAME, fw_name);
2364 wl->fw.hdr_num_entries[i] =
2365 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
2366 WL_NONE(("request fw %s find: %d entries\n", fw_name,
2367 wl->fw.hdr_num_entries[i]));
2370 wl_ucode_data_init(wl);
2375 void wl_ucode_free_buf(void *p)
2379 #endif /* WLC_LOW */
2381 static void wl_release_fw(wl_info_t *wl)
2384 for (i = 0; i < WL_MAX_FW; i++) {
2385 release_firmware(wl->fw.fw_bin[i]);
2386 release_firmware(wl->fw.fw_hdr[i]);
2389 #endif /* WLC_HIGH_ONLY */