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_DEV_IF(dev) ((wl_if_t *)netdev_priv(dev))
139 #define WL_INFO(dev) ((wl_info_t *)(WL_DEV_IF(dev)->wl)) /* points to wl */
140 static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev);
141 static void wl_release_fw(wl_info_t *wl);
144 /* local prototypes */
145 static int wl_start(struct sk_buff *skb, wl_info_t *wl);
146 static int wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw,
147 struct sk_buff *skb);
148 static void wl_dpc(unsigned long data);
150 MODULE_AUTHOR("Broadcom Corporation");
151 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
152 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
153 MODULE_LICENSE("Dual BSD/GPL");
156 /* recognized PCI IDs */
157 static struct pci_device_id wl_id_table[] = {
158 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
159 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
160 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
164 MODULE_DEVICE_TABLE(pci, wl_id_table);
165 static void wl_remove(struct pci_dev *pdev);
166 #endif /* !BCMSDIO */
169 static uint sd_drivestrength = 6;
170 module_param(sd_drivestrength, uint, 0);
174 static int msglevel = 0xdeadbeef;
175 module_param(msglevel, int, 0);
176 #ifndef WLC_HIGH_ONLY
177 static int phymsglevel = 0xdeadbeef;
178 module_param(phymsglevel, int, 0);
179 #endif /* WLC_HIGH_ONLY */
183 module_param(oneonly, int, 0);
186 module_param(piomode, int, 0);
188 static int instance_base; /* Starting instance number */
189 module_param(instance_base, int, 0);
192 static char *macaddr;
193 module_param(macaddr, charp, S_IRUGO);
196 static int nompc = 1;
197 module_param(nompc, int, 0);
199 static char name[IFNAMSIZ] = "eth%d";
200 module_param_string(name, name, IFNAMSIZ, 0);
206 #define WL_MAGIC 0xdeadbeef
208 #define HW_TO_WL(hw) (hw->priv)
209 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
211 static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb);
213 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
215 static int wl_ops_start(struct ieee80211_hw *hw);
216 static void wl_ops_stop(struct ieee80211_hw *hw);
217 static int wl_ops_add_interface(struct ieee80211_hw *hw,
218 struct ieee80211_vif *vif);
219 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
220 struct ieee80211_vif *vif);
221 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
222 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
223 struct ieee80211_vif *vif,
224 struct ieee80211_bss_conf *info,
226 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
227 unsigned int changed_flags,
228 unsigned int *total_flags, u64 multicast);
229 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
231 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
232 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
233 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
234 static int wl_ops_get_stats(struct ieee80211_hw *hw,
235 struct ieee80211_low_level_stats *stats);
236 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
237 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
238 struct ieee80211_vif *vif,
239 enum sta_notify_cmd cmd,
240 struct ieee80211_sta *sta);
241 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
242 const struct ieee80211_tx_queue_params *params);
243 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
244 static int wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
245 struct ieee80211_sta *sta);
246 static int wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
247 struct ieee80211_sta *sta);
248 static int wl_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
249 enum ieee80211_ampdu_mlme_action action,
250 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
253 static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb)
256 wl_info_t *wl = hw->priv;
258 WL_ERROR(("ops->tx called while down\n"));
262 status = wl_start(skb, wl);
267 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
270 wl_info_t *wl = hw->priv;
273 WL_ERROR(("ops->tx called while down\n"));
277 status = wl_start(skb, wl);
282 #endif /* WLC_HIGH_ONLY */
284 static int wl_ops_start(struct ieee80211_hw *hw)
286 wl_info_t *wl = hw->priv;
287 /* struct ieee80211_channel *curchan = hw->conf.channel; */
288 WL_NONE(("%s : Initial channel: %d\n", __func__, curchan->hw_value));
291 ieee80211_wake_queues(hw);
297 static void wl_ops_stop(struct ieee80211_hw *hw)
299 wl_info_t *wl = hw->priv;
303 ieee80211_stop_queues(hw);
310 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
315 /* Just STA for now */
316 if (vif->type != NL80211_IFTYPE_AP &&
317 vif->type != NL80211_IFTYPE_MESH_POINT &&
318 vif->type != NL80211_IFTYPE_STATION &&
319 vif->type != NL80211_IFTYPE_WDS &&
320 vif->type != NL80211_IFTYPE_ADHOC) {
321 WL_ERROR(("%s: Attempt to add type %d, only STA for now\n",
322 __func__, vif->type));
332 WL_ERROR(("%s: wl_up() returned %d\n", __func__, err));
337 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
343 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
344 enum nl80211_channel_type type)
346 wl_info_t *wl = HW_TO_WL(hw);
350 case NL80211_CHAN_HT20:
351 case NL80211_CHAN_NO_HT:
353 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
356 case NL80211_CHAN_HT40MINUS:
357 case NL80211_CHAN_HT40PLUS:
358 WL_ERROR(("%s: Need to implement 40 Mhz Channels!\n",
368 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
370 struct ieee80211_conf *conf = &hw->conf;
371 wl_info_t *wl = HW_TO_WL(hw);
375 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
376 WL_NONE(("%s: Setting listen interval to %d\n",
377 __func__, conf->listen_interval));
379 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
380 WL_ERROR(("%s: Error setting listen_interval\n",
385 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
386 ASSERT(new_int == conf->listen_interval);
388 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
389 WL_NONE(("Need to set monitor mode\n"));
390 if (changed & IEEE80211_CONF_CHANGE_PS)
391 WL_NONE(("Need to set Power-save mode\n"));
393 if (changed & IEEE80211_CONF_CHANGE_POWER) {
394 WL_NONE(("%s: Setting tx power to %d dbm\n", __func__,
397 (wl->wlc, "qtxpower", conf->power_level * 4)) {
398 WL_ERROR(("%s: Error setting power_level\n", __func__));
402 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
403 if (new_int != (conf->power_level * 4))
404 WL_ERROR(("%s: Power level req != actual, %d %d\n",
405 __func__, conf->power_level * 4, new_int));
407 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
408 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
410 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
411 WL_NONE(("%s: srl %d, lrl %d\n", __func__,
412 conf->short_frame_max_tx_count,
413 conf->long_frame_max_tx_count));
415 (wl->wlc, WLC_SET_SRL,
416 conf->short_frame_max_tx_count) < 0) {
417 WL_ERROR(("%s: Error setting srl\n", __func__));
421 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
423 WL_ERROR(("%s: Error setting lrl\n", __func__));
434 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
435 struct ieee80211_vif *vif,
436 struct ieee80211_bss_conf *info, u32 changed)
438 wl_info_t *wl = HW_TO_WL(hw);
445 if (changed & BSS_CHANGED_ASSOC) {
446 WL_ERROR(("Associated:\t%s\n", info->assoc ? "True" : "False"));
447 /* association status changed (associated/disassociated)
448 * also implies a change in the AID.
451 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
452 WL_NONE(("Use_cts_prot:\t%s Implement me\n",
453 info->use_cts_prot ? "True" : "False"));
454 /* CTS protection changed */
456 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
457 WL_NONE(("Short preamble:\t%s Implement me\n",
458 info->use_short_preamble ? "True" : "False"));
459 /* preamble changed */
461 if (changed & BSS_CHANGED_ERP_SLOT) {
462 WL_NONE(("Changing short slot:\t%s\n",
463 info->use_short_slot ? "True" : "False"));
464 if (info->use_short_slot)
468 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
469 /* slot timing changed */
472 if (changed & BSS_CHANGED_HT) {
473 WL_NONE(("%s: HT mode - Implement me\n", __func__));
474 /* 802.11n parameters changed */
476 if (changed & BSS_CHANGED_BASIC_RATES) {
477 WL_NONE(("Need to change Basic Rates:\t0x%x! Implement me\n",
478 (uint32) info->basic_rates));
479 /* Basic rateset changed */
481 if (changed & BSS_CHANGED_BEACON_INT) {
482 WL_NONE(("Beacon Interval:\t%d Implement me\n",
484 /* Beacon interval changed */
486 if (changed & BSS_CHANGED_BSSID) {
487 /* char eabuf[ETHER_ADDR_STR_LEN]; */
488 WL_NONE(("new BSSID:\taid %d bss:%s\n",
490 bcm_ether_ntoa((struct ether_addr *)info->bssid,
492 /* BSSID changed, for whatever reason (IBSS and managed mode) */
493 /* FIXME: need to store bssid in bsscfg */
494 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
495 (struct ether_addr *)info->bssid);
497 if (changed & BSS_CHANGED_BEACON) {
498 WL_ERROR(("BSS_CHANGED_BEACON\n"));
499 /* Beacon data changed, retrieve new beacon (beaconing modes) */
501 if (changed & BSS_CHANGED_BEACON_ENABLED) {
502 WL_ERROR(("Beacon enabled:\t%s\n",
503 info->enable_beacon ? "True" : "False"));
504 /* Beaconing should be enabled/disabled (beaconing modes) */
513 wl_ops_configure_filter(struct ieee80211_hw *hw,
514 unsigned int changed_flags,
515 unsigned int *total_flags, u64 multicast)
517 #ifndef WLC_HIGH_ONLY
518 wl_info_t *wl = hw->priv;
521 changed_flags &= MAC_FILTERS;
522 *total_flags &= MAC_FILTERS;
523 if (changed_flags & FIF_PROMISC_IN_BSS)
524 WL_ERROR(("FIF_PROMISC_IN_BSS\n"));
525 if (changed_flags & FIF_ALLMULTI)
526 WL_ERROR(("FIF_ALLMULTI\n"));
527 if (changed_flags & FIF_FCSFAIL)
528 WL_ERROR(("FIF_FCSFAIL\n"));
529 if (changed_flags & FIF_PLCPFAIL)
530 WL_ERROR(("FIF_PLCPFAIL\n"));
531 if (changed_flags & FIF_CONTROL)
532 WL_ERROR(("FIF_CONTROL\n"));
533 if (changed_flags & FIF_OTHER_BSS)
534 WL_ERROR(("FIF_OTHER_BSS\n"));
535 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
536 WL_NONE(("FIF_BCN_PRBRESP_PROMISC\n"));
537 #ifndef WLC_HIGH_ONLY
539 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
540 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
541 wlc_mac_bcn_promisc_change(wl->wlc, 1);
543 wlc_mac_bcn_promisc_change(wl->wlc, 0);
544 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
553 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
555 WL_ERROR(("%s: Enter\n", __func__));
559 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
561 WL_NONE(("Scan Start\n"));
565 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
567 WL_NONE(("Scan Complete\n"));
571 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
573 WL_ERROR(("%s: Enter\n", __func__));
578 wl_ops_get_stats(struct ieee80211_hw *hw,
579 struct ieee80211_low_level_stats *stats)
581 WL_ERROR(("%s: Enter\n", __func__));
585 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
587 WL_ERROR(("%s: Enter\n", __func__));
592 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
593 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
595 WL_NONE(("%s: Enter\n", __func__));
598 WL_ERROR(("%s: Uknown cmd = %d\n", __func__, cmd));
605 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
606 const struct ieee80211_tx_queue_params *params)
608 wl_info_t *wl = hw->priv;
610 WL_NONE(("%s: Enter (WME config)\n", __func__));
611 WL_NONE(("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
612 params->txop, params->cw_min, params->cw_max, params->aifs));
615 wlc_wme_setparams(wl->wlc, queue, (void *)params, TRUE);
621 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
623 WL_ERROR(("%s: Enter\n", __func__));
628 wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
629 struct ieee80211_sta *sta)
634 wl_info_t *wl = hw->priv;
637 scb = (struct scb *)sta->drv_priv;
638 bzero(scb, sizeof(struct scb));
639 for (i = 0; i < NUMPRIO; i++)
640 scb->seqctl[i] = 0xFFFF;
641 scb->seqctl_nonqos = 0xFFFF;
642 scb->magic = SCB_MAGIC;
644 wl->pub->global_scb = scb;
645 wl->pub->global_ampdu = &(scb->scb_ampdu);
646 wl->pub->global_ampdu->scb = scb;
648 wl->pub->global_ampdu->max_pdu = AMPDU_NUM_MPDU;
650 wl->pub->global_ampdu->max_pdu = 16;
652 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
653 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
655 sta->ht_cap.ht_supported = TRUE;
657 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_16K;
659 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
661 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
662 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
663 IEEE80211_HT_CAP_SGI_20 |
664 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
666 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
671 wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
672 struct ieee80211_sta *sta)
674 WL_NONE(("%s: Enter\n", __func__));
679 wl_ampdu_action(struct ieee80211_hw *hw,
680 struct ieee80211_vif *vif,
681 enum ieee80211_ampdu_mlme_action action,
682 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
685 struct scb *scb = (struct scb *)sta->drv_priv;
687 wl_info_t *wl = hw->priv;
689 ASSERT(scb->magic == SCB_MAGIC);
691 case IEEE80211_AMPDU_RX_START:
692 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_START\n", __func__));
694 case IEEE80211_AMPDU_RX_STOP:
695 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__));
697 case IEEE80211_AMPDU_TX_START:
698 if (!wlc_aggregatable(wl->wlc, tid)) {
699 /* WL_ERROR(("START: tid %d is not agg' able, return FAILURE to stack\n", tid)); */
702 /* XXX: Use the starting sequence number provided ... */
704 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
707 case IEEE80211_AMPDU_TX_STOP:
708 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
710 case IEEE80211_AMPDU_TX_OPERATIONAL:
711 /* Not sure what to do here */
712 /* Power save wakeup */
713 WL_NONE(("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
717 WL_ERROR(("%s: Invalid command, ignoring\n", __func__));
723 static const struct ieee80211_ops wl_ops = {
729 .start = wl_ops_start,
731 .add_interface = wl_ops_add_interface,
732 .remove_interface = wl_ops_remove_interface,
733 .config = wl_ops_config,
734 .bss_info_changed = wl_ops_bss_info_changed,
735 .configure_filter = wl_ops_configure_filter,
736 .set_tim = wl_ops_set_tim,
737 .sw_scan_start = wl_ops_sw_scan_start,
738 .sw_scan_complete = wl_ops_sw_scan_complete,
739 .set_tsf = wl_ops_set_tsf,
740 .get_stats = wl_ops_get_stats,
741 .set_rts_threshold = wl_ops_set_rts_threshold,
742 .sta_notify = wl_ops_sta_notify,
743 .conf_tx = wl_ops_conf_tx,
744 .get_tsf = wl_ops_get_tsf,
745 .sta_add = wl_sta_add,
746 .sta_remove = wl_sta_remove,
747 .ampdu_action = wl_ampdu_action,
750 static int wl_set_hint(wl_info_t *wl, char *abbrev)
752 WL_ERROR(("%s: Sending country code %c%c to MAC80211\n", __func__,
753 abbrev[0], abbrev[1]));
754 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
758 * attach to the WL device.
760 * Attach to the WL device identified by vendor and device parameters.
761 * regs is a host accessible memory address pointing to WL device registers.
763 * wl_attach is not defined as static because in the case where no bus
764 * is defined, wl_attach will never be called, and thus, gcc will issue
765 * a warning that this function is defined but not used if we declare
768 static wl_info_t *wl_attach(uint16 vendor, uint16 device, unsigned long regs,
769 uint bustype, void *btparam, uint irq)
775 unsigned long base_addr;
776 struct ieee80211_hw *hw;
779 unit = wl_found + instance_base;
783 WL_ERROR(("wl%d: unit number overflow, exiting\n", unit));
787 if (oneonly && (unit != instance_base)) {
788 WL_ERROR(("wl%d: wl_attach: oneonly is set, exiting\n", unit));
792 /* Requires pkttag feature */
793 osh = osl_attach(btparam, bustype, TRUE);
797 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
799 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
803 bzero(hw->priv, sizeof(*wl));
806 /* allocate private info */
807 hw = pci_get_drvdata(btparam); /* btparam == pdev */
812 wl->magic = WL_MAGIC;
814 atomic_set(&wl->callbacks, 0);
816 /* setup the bottom half handler */
817 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
820 wl->rpc_th = bcm_rpc_tp_attach(osh, NULL);
821 if (wl->rpc_th == NULL) {
822 WL_ERROR(("wl%d: %s: bcm_rpc_tp_attach failed!\n", unit,
827 wl->rpc = bcm_rpc_attach(NULL, osh, wl->rpc_th);
828 if (wl->rpc == NULL) {
829 WL_ERROR(("wl%d: %s: bcm_rpc_attach failed!\n", unit,
834 /* init tx work queue for wl_start/send pkt; no need to destroy workitem */
835 INIT_WORK(&wl->txq_task.work, (work_func_t) wl_start_txqwork);
836 wl->txq_task.context = wl;
837 #endif /* WLC_HIGH_ONLY */
840 SET_IEEE80211_DEV(hw, sdiommc_dev);
845 if (bustype == PCI_BUS) {
846 /* piomode can be overwritten by command argument */
847 wl->piomode = piomode;
848 WL_TRACE(("PCI/%s\n", wl->piomode ? "PIO" : "DMA"));
849 } else if (bustype == RPC_BUS) {
853 WL_TRACE(("force to PCI\n"));
855 wl->bcm_bustype = bustype;
858 if (wl->bcm_bustype == RPC_BUS) {
859 wl->regsva = (void *)0;
863 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
864 if (wl->regsva == NULL) {
865 WL_ERROR(("wl%d: ioremap() failed\n", unit));
869 spin_lock_init(&wl->rpcq_lock);
870 spin_lock_init(&wl->txq_lock);
872 init_MUTEX(&wl->sem);
874 spin_lock_init(&wl->lock);
875 spin_lock_init(&wl->isr_lock);
878 #ifndef WLC_HIGH_ONLY
880 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
881 printf("%s: Failed to find firmware usually in %s\n",
882 KBUILD_MODNAME, "/lib/firmware/brcm");
884 wl_remove((struct pci_dev *)btparam);
889 /* common load-time initialization */
890 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
891 wl->regsva, wl->bcm_bustype, btparam, &err);
892 #ifndef WLC_HIGH_ONLY
896 printf("%s: %s wlc_attach() failed with code %d\n",
897 KBUILD_MODNAME, EPI_VERSION_STR, err);
900 wl->pub = wlc_pub(wl->wlc);
902 wl->pub->ieee_hw = hw;
903 ASSERT(wl->pub->ieee_hw);
904 ASSERT(wl->pub->ieee_hw->priv == wl);
907 REGOPSSET(osh, (osl_rreg_fn_t) wlc_reg_read,
908 (osl_wreg_fn_t) wlc_reg_write, wl->wlc);
909 wl->rpc_dispatch_ctx.rpc = wl->rpc;
910 wl->rpc_dispatch_ctx.wlc = wl->wlc;
911 bcm_rpc_rxcb_init(wl->rpc, wl, wl_rpc_dispatch_schedule, wl,
912 wl_rpc_down, NULL, NULL);
913 #endif /* WLC_HIGH_ONLY */
916 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
917 WL_ERROR(("wl%d: Error setting MPC variable to 0\n",
922 /* Set SDIO drive strength */
923 wlc_iovar_setint(wl->wlc, "sd_drivestrength", sd_drivestrength);
927 /* register our interrupt handler */
928 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
929 WL_ERROR(("wl%d: request_irq() failed\n", unit));
935 /* register module */
936 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
939 if (ieee_hw_init(hw)) {
940 WL_ERROR(("wl%d: %s: ieee_hw_init failed!\n", unit, __func__));
944 bcopy(&wl->pub->cur_etheraddr, perm, ETHER_ADDR_LEN);
945 ASSERT(is_valid_ether_addr(perm));
946 SET_IEEE80211_PERM_ADDR(hw, perm);
948 err = ieee80211_register_hw(hw);
950 WL_ERROR(("%s: ieee80211_register_hw failed, status %d\n",
954 if (wl->pub->srom_ccode[0])
955 err = wl_set_hint(wl, wl->pub->srom_ccode);
957 err = wl_set_hint(wl, "US");
959 WL_ERROR(("%s: regulatory_hint failed, status %d\n", __func__,
962 #ifndef WLC_HIGH_ONLY
963 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
964 EPI_VERSION_STR " (" PHY_VERSION_STR ")", unit));
966 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
967 EPI_VERSION_STR, unit));
971 printf(" (Compiled in " SRCBASE " at " __TIME__ " on " __DATE__ ")");
985 static void *wl_dbus_probe_cb(void *arg, const char *desc, uint32 bustype,
989 WL_ERROR(("%s:\n", __func__));
991 wl = wl_attach(BCM_DNGL_VID, BCM_DNGL_BDC_PID, (unsigned long) NULL, RPC_BUS,
994 WL_ERROR(("%s: wl_attach failed\n", __func__));
997 /* This is later passed to wl_dbus_disconnect_cb */
1001 static void wl_dbus_disconnect_cb(void *arg)
1003 wl_info_t *wl = arg;
1005 WL_ERROR(("%s:\n", __func__));
1008 #ifdef WLC_HIGH_ONLY
1009 if (wl->pub->ieee_hw) {
1010 ieee80211_unregister_hw(wl->pub->ieee_hw);
1011 WL_ERROR(("%s: Back from down\n", __func__));
1013 wlc_device_removed(wl->wlc);
1014 wlc_bmac_dngl_reboot(wl->rpc);
1015 bcm_rpc_down(wl->rpc);
1020 #ifdef WLC_HIGH_ONLY
1021 if (wl->pub->ieee_hw) {
1022 ieee80211_free_hw(wl->pub->ieee_hw);
1023 WL_ERROR(("%s: Back from ieee80211_free_hw\n",
1025 wl->pub->ieee_hw = NULL;
1031 #endif /* WLC_HIGH_ONLY */
1034 #define CHAN2GHZ(channel, freqency, chflags) { \
1035 .band = IEEE80211_BAND_2GHZ, \
1036 .center_freq = (freqency), \
1037 .hw_value = (channel), \
1039 .max_antenna_gain = 0, \
1043 static struct ieee80211_channel wl_2ghz_chantable[] = {
1044 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
1045 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
1046 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
1047 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
1048 CHAN2GHZ(5, 2432, 0),
1049 CHAN2GHZ(6, 2437, 0),
1050 CHAN2GHZ(7, 2442, 0),
1051 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
1052 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
1053 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
1054 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
1056 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1057 IEEE80211_CHAN_NO_HT40PLUS),
1059 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1060 IEEE80211_CHAN_NO_HT40PLUS),
1062 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
1063 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
1066 #define CHAN5GHZ(channel, chflags) { \
1067 .band = IEEE80211_BAND_5GHZ, \
1068 .center_freq = 5000 + 5*(channel), \
1069 .hw_value = (channel), \
1071 .max_antenna_gain = 0, \
1075 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
1077 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
1078 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
1079 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
1080 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
1083 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1084 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1086 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1087 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1089 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1090 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1092 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1093 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1096 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1097 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1099 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1100 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1102 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1103 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1105 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1106 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1108 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1109 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1111 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1112 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1114 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1115 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1117 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1118 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1120 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1121 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
1123 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1124 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
1126 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
1127 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
1128 IEEE80211_CHAN_NO_HT40MINUS),
1130 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
1131 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
1132 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
1133 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
1134 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
1137 #define RATE(rate100m, _flags) { \
1138 .bitrate = (rate100m), \
1139 .flags = (_flags), \
1140 .hw_value = (rate100m / 5), \
1143 static struct ieee80211_rate wl_legacy_ratetable[] = {
1145 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
1146 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
1147 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
1158 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
1159 .band = IEEE80211_BAND_2GHZ,
1160 .channels = wl_2ghz_chantable,
1161 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
1162 .bitrates = wl_legacy_ratetable,
1163 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
1165 /* from include/linux/ieee80211.h */
1166 .cap = IEEE80211_HT_CAP_GRN_FLD |
1167 IEEE80211_HT_CAP_SGI_20 |
1168 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
1169 #ifdef WLC_HIGH_ONLY
1170 .ht_supported = true,
1171 .ampdu_factor = AMPDU_RX_FACTOR_16K,
1173 .ht_supported = true,
1174 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1176 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1178 /* placeholders for now */
1179 #ifdef WLC_HIGH_ONLY
1181 * rx_mask[0] = 0xff by default
1182 * rx_mask[1] = 0xff if number of rx chain >=2
1183 * rx_mask[2] = 0xff if number of rx chain >=3
1184 * rx_mask[4] = 1 if 40Mhz is supported
1186 .rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0},
1187 .rx_highest = 72, /* max rate of single stream */
1189 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1192 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1196 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
1197 .band = IEEE80211_BAND_5GHZ,
1198 .channels = wl_5ghz_nphy_chantable,
1199 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
1200 .bitrates = wl_legacy_ratetable + 4,
1201 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1203 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1204 .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 */
1205 .ht_supported = true,
1206 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1207 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1209 /* placeholders for now */
1210 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1212 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1216 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1218 wl_info_t *wl = HW_TO_WL(hw);
1224 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1225 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1227 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1228 WL_ERROR(("Phy list failed\n"));
1230 WL_NONE(("%s: phylist = %c\n", __func__, phy_list[0]));
1232 #ifndef WLC_HIGH_ONLY
1233 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1234 if (phy_list[0] == 'c') {
1236 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1237 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1240 if (phy_list[0] == 's') {
1242 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1248 /* Assume all bands use the same phy. True for 11n devices. */
1249 if (NBANDS_PUB(wl->pub) > 1) {
1251 #ifndef WLC_HIGH_ONLY
1252 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1254 if (phy_list[0] == 's') {
1256 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1263 WL_NONE(("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g));
1268 static int ieee_hw_init(struct ieee80211_hw *hw)
1270 hw->flags = IEEE80211_HW_SIGNAL_DBM
1271 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1272 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1273 | IEEE80211_HW_AMPDU_AGGREGATION;
1275 hw->extra_tx_headroom = wlc_get_header_len();
1276 /* FIXME: should get this from wlc->machwcap */
1278 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1279 * mac80211/status.c:ieee80211_tx_status() checks this value,
1280 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1281 * appears to always set 3 rates
1283 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1285 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1286 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1288 hw->rate_control_algorithm = "minstrel_ht";
1290 hw->sta_data_size = sizeof(struct scb);
1291 return ieee_hw_rate_init(hw);
1296 * determines if a device is a WL device, and if so, attaches it.
1298 * This function determines if a device pointed to by pdev is a WL device,
1299 * and if so, performs a wl_attach() on it.
1303 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1307 struct ieee80211_hw *hw;
1312 WL_TRACE(("%s: bus %d slot %d func %d irq %d\n", __func__,
1313 pdev->bus->number, PCI_SLOT(pdev->devfn),
1314 PCI_FUNC(pdev->devfn), pdev->irq));
1316 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1317 (((pdev->device & 0xff00) != 0x4300) &&
1318 ((pdev->device & 0xff00) != 0x4700) &&
1319 ((pdev->device < 43000) || (pdev->device > 43999))))
1322 rc = pci_enable_device(pdev);
1324 WL_ERROR(("%s: Cannot enable device %d-%d_%d\n", __func__,
1325 pdev->bus->number, PCI_SLOT(pdev->devfn),
1326 PCI_FUNC(pdev->devfn)));
1329 pci_set_master(pdev);
1331 pci_read_config_dword(pdev, 0x40, &val);
1332 if ((val & 0x0000ff00) != 0)
1333 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1335 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
1337 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
1342 SET_IEEE80211_DEV(hw, &pdev->dev);
1344 pci_set_drvdata(pdev, hw);
1346 bzero(hw->priv, sizeof(*wl));
1348 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1349 PCI_BUS, pdev, pdev->irq);
1352 WL_ERROR(("%s: %s: wl_attach failed!\n",
1353 KBUILD_MODNAME, __func__));
1358 WL_ERROR(("%s: err_1: Major hoarkage\n", __func__));
1363 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1366 struct ieee80211_hw *hw;
1368 WL_TRACE(("wl: wl_suspend\n"));
1370 hw = pci_get_drvdata(pdev);
1373 WL_ERROR(("wl: wl_suspend: pci_get_drvdata failed\n"));
1379 wl->pub->hw_up = FALSE;
1381 pci_save_state(pdev, wl->pci_psstate);
1382 pci_disable_device(pdev);
1383 return pci_set_power_state(pdev, PCI_D3hot);
1386 static int wl_resume(struct pci_dev *pdev)
1389 struct ieee80211_hw *hw;
1393 WL_TRACE(("wl: wl_resume\n"));
1394 hw = pci_get_drvdata(pdev);
1397 WL_ERROR(("wl: wl_resume: pci_get_drvdata failed\n"));
1401 err = pci_set_power_state(pdev, PCI_D0);
1405 pci_restore_state(pdev, wl->pci_psstate);
1407 err = pci_enable_device(pdev);
1411 pci_set_master(pdev);
1413 pci_read_config_dword(pdev, 0x40, &val);
1414 if ((val & 0x0000ff00) != 0)
1415 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1423 #endif /* LINUXSTA_PS */
1425 static void wl_remove(struct pci_dev *pdev)
1428 struct ieee80211_hw *hw;
1430 hw = pci_get_drvdata(pdev);
1433 WL_ERROR(("wl: wl_remove: pci_get_drvdata failed\n"));
1436 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1437 WL_ERROR(("wl: wl_remove: wlc_chipmatch failed\n"));
1441 ieee80211_unregister_hw(hw);
1445 WL_NONE(("%s: Down\n", __func__));
1447 pci_disable_device(pdev);
1451 pci_set_drvdata(pdev, NULL);
1452 ieee80211_free_hw(hw);
1455 static struct pci_driver wl_pci_driver = {
1456 .name = "brcm80211",
1457 .probe = wl_pci_probe,
1459 .suspend = wl_suspend,
1460 .resume = wl_resume,
1461 #endif /* LINUXSTA_PS */
1462 .remove = __devexit_p(wl_remove),
1463 .id_table = wl_id_table,
1465 #endif /* !BCMSDIO */
1468 * This is the main entry point for the WL driver.
1470 * This function determines if a device pointed to by pdev is a WL device,
1471 * and if so, performs a wl_attach() on it.
1474 static int __init wl_module_init(void)
1476 int error = -ENODEV;
1479 if (msglevel != 0xdeadbeef)
1480 wl_msg_level = msglevel;
1482 char *var = getvar(NULL, "wl_msglevel");
1484 wl_msg_level = simple_strtoul(var, NULL, 0);
1486 #ifndef WLC_HIGH_ONLY
1488 extern uint32 phyhal_msg_level;
1490 if (phymsglevel != 0xdeadbeef)
1491 phyhal_msg_level = phymsglevel;
1493 char *var = getvar(NULL, "phy_msglevel");
1495 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1498 #endif /* WLC_HIGH_ONLY */
1502 error = pci_register_driver(&wl_pci_driver);
1506 #endif /* !BCMSDIO */
1508 #ifdef WLC_HIGH_ONLY
1509 /* BMAC_NOTE: define hardcode number, why NODEVICE is ok ? */
1511 dbus_register(BCM_DNGL_VID, 0, wl_dbus_probe_cb,
1512 wl_dbus_disconnect_cb, NULL, NULL, NULL);
1513 if (error == DBUS_ERR_NODEVICE) {
1516 #endif /* WLC_HIGH_ONLY */
1522 * This function unloads the WL driver from the system.
1524 * This function unconditionally unloads the WL driver module from the
1528 static void __exit wl_module_exit(void)
1531 pci_unregister_driver(&wl_pci_driver);
1532 #endif /* !BCMSDIO */
1534 #ifdef WLC_HIGH_ONLY
1536 #endif /* WLC_HIGH_ONLY */
1539 module_init(wl_module_init);
1540 module_exit(wl_module_exit);
1543 * This function frees the WL per-device resources.
1545 * This function frees resources owned by the WL device pointed to
1546 * by the wl parameter.
1549 void wl_free(wl_info_t *wl)
1551 wl_timer_t *t, *next;
1555 #ifndef WLC_HIGH_ONLY
1556 /* free ucode data */
1558 wl_ucode_data_free();
1560 free_irq(wl->irq, wl);
1564 tasklet_kill(&wl->tasklet);
1567 wlc_module_unregister(wl->pub, "linux", wl);
1570 /* free common resources */
1572 wlc_detach(wl->wlc);
1577 /* virtual interface deletion is deferred so we cannot spinwait */
1579 /* wait for all pending callbacks to complete */
1580 while (atomic_read(&wl->callbacks) > 0)
1584 for (t = wl->timers; t; t = next) {
1588 MFREE(wl->osh, t->name, strlen(t->name) + 1);
1590 MFREE(wl->osh, t, sizeof(wl_timer_t));
1596 * unregister_netdev() calls get_stats() which may read chip registers
1597 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1599 if (wl->regsva && BUSTYPE(wl->bcm_bustype) != SDIO_BUS &&
1600 BUSTYPE(wl->bcm_bustype) != JTAG_BUS) {
1601 iounmap((void *)wl->regsva);
1605 #ifdef WLC_HIGH_ONLY
1611 bcm_rpc_detach(wl->rpc);
1616 bcm_rpc_tp_detach(wl->rpc_th);
1619 #endif /* WLC_HIGH_ONLY */
1621 if (osl_malloced(osh)) {
1622 printf("**** Memory leak of bytes %d\n", osl_malloced(osh));
1623 ASSERT(0 && "Memory Leak");
1630 /* transmit a packet */
1631 static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
1636 return wl_start_int(wl, WL_TO_HW(wl), skb);
1638 #endif /* WLC_LOW */
1640 static int BCMFASTPATH
1641 wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1643 #ifdef WLC_HIGH_ONLY
1646 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1647 #ifdef WLC_HIGH_ONLY
1650 return NETDEV_TX_OK;
1653 void wl_txflowcontrol(wl_info_t *wl, struct wl_if *wlif, bool state, int prio)
1655 WL_ERROR(("Shouldn't be here %s\n", __func__));
1658 #if defined(WLC_HIGH_ONLY)
1659 /* Schedule a completion handler to run at safe time */
1661 wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *task),
1666 WL_TRACE(("wl%d: wl_schedule_task\n", wl->pub->unit));
1668 task = osl_malloc(wl->osh, sizeof(wl_task_t));
1670 WL_ERROR(("wl%d: wl_schedule_task: out of memory, malloced %d bytes\n", wl->pub->unit, osl_malloced(wl->osh)));
1674 INIT_WORK(&task->work, (work_func_t) fn);
1675 task->context = context;
1677 if (!schedule_work(&task->work)) {
1678 WL_ERROR(("wl%d: schedule_work() failed\n", wl->pub->unit));
1679 MFREE(wl->osh, task, sizeof(wl_task_t));
1683 atomic_inc(&wl->callbacks);
1687 #endif /* defined(WLC_HIGH_ONLY) */
1689 void wl_init(wl_info_t *wl)
1691 WL_TRACE(("wl%d: wl_init\n", wl->pub->unit));
1698 uint wl_reset(wl_info_t *wl)
1700 WL_TRACE(("wl%d: wl_reset\n", wl->pub->unit));
1704 /* dpc will not be rescheduled */
1711 * These are interrupt on/off entry points. Disable interrupts
1712 * during interrupt state transition.
1714 void BCMFASTPATH wl_intrson(wl_info_t *wl)
1716 #if defined(WLC_LOW)
1717 unsigned long flags;
1719 INT_LOCK(wl, flags);
1720 wlc_intrson(wl->wlc);
1721 INT_UNLOCK(wl, flags);
1722 #endif /* WLC_LOW */
1725 bool wl_alloc_dma_resources(wl_info_t *wl, uint addrwidth)
1730 uint32 BCMFASTPATH wl_intrsoff(wl_info_t *wl)
1732 #if defined(WLC_LOW)
1733 unsigned long flags;
1736 INT_LOCK(wl, flags);
1737 status = wlc_intrsoff(wl->wlc);
1738 INT_UNLOCK(wl, flags);
1742 #endif /* WLC_LOW */
1745 void wl_intrsrestore(wl_info_t *wl, uint32 macintmask)
1747 #if defined(WLC_LOW)
1748 unsigned long flags;
1750 INT_LOCK(wl, flags);
1751 wlc_intrsrestore(wl->wlc, macintmask);
1752 INT_UNLOCK(wl, flags);
1753 #endif /* WLC_LOW */
1756 int wl_up(wl_info_t *wl)
1763 error = wlc_up(wl->wlc);
1768 void wl_down(wl_info_t *wl)
1770 uint callbacks, ret_val = 0;
1772 /* call common down function */
1773 ret_val = wlc_down(wl->wlc);
1774 callbacks = atomic_read(&wl->callbacks) - ret_val;
1776 /* wait for down callbacks to complete */
1779 #ifndef WLC_HIGH_ONLY
1780 /* For HIGH_only driver, it's important to actually schedule other work,
1781 * not just spin wait since everything runs at schedule level
1783 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1784 #endif /* WLC_HIGH_ONLY */
1789 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1791 #if defined(WLC_LOW)
1794 unsigned long flags;
1796 wl = (wl_info_t *) dev_id;
1798 WL_ISRLOCK(wl, flags);
1800 /* call common first level interrupt handler */
1801 ours = wlc_isr(wl->wlc, &wantdpc);
1803 /* if more to do... */
1806 /* ...and call the second level interrupt handler */
1808 ASSERT(wl->resched == FALSE);
1809 tasklet_schedule(&wl->tasklet);
1813 WL_ISRUNLOCK(wl, flags);
1815 return IRQ_RETVAL(ours);
1817 return IRQ_RETVAL(0);
1818 #endif /* WLC_LOW */
1821 static void BCMFASTPATH wl_dpc(unsigned long data)
1826 wl = (wl_info_t *) data;
1830 /* call the common second level interrupt handler */
1833 unsigned long flags;
1835 INT_LOCK(wl, flags);
1836 wlc_intrsupd(wl->wlc);
1837 INT_UNLOCK(wl, flags);
1840 wl->resched = wlc_dpc(wl->wlc, TRUE);
1843 /* wlc_dpc() may bring the driver down */
1847 /* re-schedule dpc */
1849 tasklet_schedule(&wl->tasklet);
1851 /* re-enable interrupts */
1857 #endif /* WLC_LOW */
1860 static void wl_link_up(wl_info_t *wl, char *ifname)
1862 WL_ERROR(("wl%d: link up (%s)\n", wl->pub->unit, ifname));
1865 static void wl_link_down(wl_info_t *wl, char *ifname)
1867 WL_ERROR(("wl%d: link down (%s)\n", wl->pub->unit, ifname));
1870 void wl_event(wl_info_t *wl, char *ifname, wlc_event_t *e)
1873 switch (e->event.event_type) {
1875 case WLC_E_NDIS_LINK:
1876 if (e->event.flags & WLC_EVENT_MSG_LINK)
1877 wl_link_up(wl, ifname);
1879 wl_link_down(wl, ifname);
1886 static void wl_timer(unsigned long data)
1888 #ifndef WLC_HIGH_ONLY
1889 _wl_timer((wl_timer_t *) data);
1891 wl_timer_t *t = (wl_timer_t *) data;
1892 wl_schedule_task(t->wl, wl_timer_task, t);
1893 #endif /* WLC_HIGH_ONLY */
1896 static void _wl_timer(wl_timer_t *t)
1902 t->timer.expires = jiffies + t->ms * HZ / 1000;
1903 atomic_inc(&t->wl->callbacks);
1904 add_timer(&t->timer);
1912 atomic_dec(&t->wl->callbacks);
1917 wl_timer_t *wl_init_timer(wl_info_t *wl, void (*fn) (void *arg), void *arg,
1922 t = osl_malloc(wl->osh, sizeof(wl_timer_t));
1924 WL_ERROR(("wl%d: wl_init_timer: out of memory, malloced %d bytes\n", wl->pub->unit, osl_malloced(wl->osh)));
1928 bzero(t, sizeof(wl_timer_t));
1930 init_timer(&t->timer);
1931 t->timer.data = (unsigned long) t;
1932 t->timer.function = wl_timer;
1936 t->next = wl->timers;
1940 t->name = osl_malloc(wl->osh, strlen(name) + 1);
1942 strcpy(t->name, name);
1948 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1949 * as well as it's easier to make it periodic
1951 void wl_add_timer(wl_info_t *wl, wl_timer_t *t, uint ms, int periodic)
1955 WL_ERROR(("%s: Already set. Name: %s, per %d\n",
1956 __func__, t->name, periodic));
1962 t->periodic = (bool) periodic;
1964 t->timer.expires = jiffies + ms * HZ / 1000;
1966 atomic_inc(&wl->callbacks);
1967 add_timer(&t->timer);
1970 /* return TRUE if timer successfully deleted, FALSE if still pending */
1971 bool wl_del_timer(wl_info_t *wl, wl_timer_t *t)
1975 if (!del_timer(&t->timer)) {
1978 atomic_dec(&wl->callbacks);
1984 void wl_free_timer(wl_info_t *wl, wl_timer_t *t)
1988 /* delete the timer in case it is active */
1989 wl_del_timer(wl, t);
1991 if (wl->timers == t) {
1992 wl->timers = wl->timers->next;
1995 MFREE(wl->osh, t->name, strlen(t->name) + 1);
1997 MFREE(wl->osh, t, sizeof(wl_timer_t));
2004 if (tmp->next == t) {
2005 tmp->next = t->next;
2008 MFREE(wl->osh, t->name, strlen(t->name) + 1);
2010 MFREE(wl->osh, t, sizeof(wl_timer_t));
2018 static int wl_linux_watchdog(void *ctx)
2020 wl_info_t *wl = (wl_info_t *) ctx;
2021 struct net_device_stats *stats = NULL;
2025 ASSERT(wl->stats_id < 2);
2027 id = 1 - wl->stats_id;
2029 stats = &wl->stats_watchdog[id];
2030 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
2031 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
2032 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
2033 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
2034 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
2035 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
2036 stats->collisions = 0;
2038 stats->rx_length_errors = 0;
2039 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
2040 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
2041 stats->rx_frame_errors = 0;
2042 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
2043 stats->rx_missed_errors = 0;
2045 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
2060 #ifdef WLC_HIGH_ONLY
2061 static void wl_rpc_down(void *wlh)
2063 wl_info_t *wl = (wl_info_t *) (wlh);
2065 wlc_device_removed(wl->wlc);
2070 static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
2073 unsigned long flags;
2077 /* Lock the queue as tasklet could be running at this time */
2078 TXQ_LOCK(wl, flags);
2079 if (wl->txq_head == NULL)
2082 wl->txq_tail->prev = skb;
2086 if (wl->txq_dispatched == FALSE) {
2087 wl->txq_dispatched = TRUE;
2089 if (schedule_work(&wl->txq_task.work)) {
2090 atomic_inc(&wl->callbacks);
2092 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2097 TXQ_UNLOCK(wl, flags);
2103 static void wl_start_txqwork(struct wl_task *task)
2105 wl_info_t *wl = (wl_info_t *) task->context;
2106 struct sk_buff *skb;
2107 unsigned long flags;
2110 WL_TRACE(("wl%d: wl_start_txqwork\n", wl->pub->unit));
2112 /* First remove an entry then go for execution */
2113 TXQ_LOCK(wl, flags);
2114 while (wl->txq_head) {
2116 wl->txq_head = skb->prev;
2118 if (wl->txq_head == NULL)
2119 wl->txq_tail = NULL;
2120 TXQ_UNLOCK(wl, flags);
2122 /* it has WL_LOCK/WL_UNLOCK inside */
2123 wl_start_int(wl, WL_TO_HW(wl), skb);
2125 /* bounded our execution, reshedule ourself next */
2129 TXQ_LOCK(wl, flags);
2133 if (!schedule_work(&wl->txq_task.work)) {
2134 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2136 atomic_dec(&wl->callbacks);
2139 wl->txq_dispatched = FALSE;
2140 TXQ_UNLOCK(wl, flags);
2141 atomic_dec(&wl->callbacks);
2147 static void wl_txq_free(wl_info_t *wl)
2149 struct sk_buff *skb;
2151 if (wl->txq_head == NULL) {
2152 ASSERT(wl->txq_tail == NULL);
2156 while (wl->txq_head) {
2158 wl->txq_head = skb->prev;
2159 PKTFREE(wl->osh, skb, TRUE);
2162 wl->txq_tail = NULL;
2165 static void wl_rpcq_free(wl_info_t *wl)
2169 if (wl->rpcq_head == NULL) {
2170 ASSERT(wl->rpcq_tail == NULL);
2174 while (wl->rpcq_head) {
2175 buf = wl->rpcq_head;
2176 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2177 bcm_rpc_buf_free(wl->rpc_dispatch_ctx.rpc, buf);
2180 wl->rpcq_tail = NULL;
2183 static void wl_rpcq_dispatch(struct wl_task *task)
2185 wl_info_t *wl = (wl_info_t *) task->context;
2187 unsigned long flags;
2189 /* First remove an entry then go for execution */
2190 RPCQ_LOCK(wl, flags);
2191 while (wl->rpcq_head) {
2192 buf = wl->rpcq_head;
2193 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2195 if (wl->rpcq_head == NULL)
2196 wl->rpcq_tail = NULL;
2197 RPCQ_UNLOCK(wl, flags);
2200 wlc_rpc_high_dispatch(&wl->rpc_dispatch_ctx, buf);
2203 RPCQ_LOCK(wl, flags);
2206 wl->rpcq_dispatched = FALSE;
2208 RPCQ_UNLOCK(wl, flags);
2210 MFREE(wl->osh, task, sizeof(wl_task_t));
2211 atomic_dec(&wl->callbacks);
2214 static void wl_rpcq_add(wl_info_t *wl, rpc_buf_t *buf)
2216 unsigned long flags;
2218 bcm_rpc_buf_next_set(wl->rpc_th, buf, NULL);
2220 /* Lock the queue as tasklet could be running at this time */
2221 RPCQ_LOCK(wl, flags);
2222 if (wl->rpcq_head == NULL)
2223 wl->rpcq_head = buf;
2225 bcm_rpc_buf_next_set(wl->rpc_th, wl->rpcq_tail, buf);
2227 wl->rpcq_tail = buf;
2229 if (wl->rpcq_dispatched == FALSE) {
2230 wl->rpcq_dispatched = TRUE;
2231 wl_schedule_task(wl, wl_rpcq_dispatch, wl);
2234 RPCQ_UNLOCK(wl, flags);
2238 static const struct name_entry rpc_name_tbl[] = RPC_ID_TABLE;
2241 /* dongle-side rpc dispatch routine */
2242 static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf)
2245 wl_info_t *wl = (wl_info_t *) ctx;
2246 wlc_rpc_id_t rpc_id;
2249 bcm_xdr_buf_init(&b, bcm_rpc_buf_data(wl->rpc_th, buf),
2250 bcm_rpc_buf_len_get(wl->rpc_th, buf));
2252 err = bcm_xdr_unpack_uint32(&b, &rpc_id);
2254 WL_TRACE(("%s: Dispatch id %s\n", __func__,
2255 WLC_RPC_ID_LOOKUP(rpc_name_tbl, rpc_id)));
2257 /* Handle few emergency ones */
2260 wl_rpcq_add(wl, buf);
2265 static void wl_timer_task(wl_task_t *task)
2267 wl_timer_t *t = (wl_timer_t *) task->context;
2270 MFREE(t->wl->osh, task, sizeof(wl_task_t));
2272 /* This dec is for the task_schedule. The timer related
2273 * callback is decremented in _wl_timer
2275 atomic_dec(&t->wl->callbacks);
2277 #endif /* WLC_HIGH_ONLY */
2279 #ifndef WLC_HIGH_ONLY
2280 char *wl_firmwares[WL_MAX_FW] = {
2286 int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, uint32 idx)
2290 struct wl_fw_hdr *hdr;
2291 for (i = 0; i < wl->fw.fw_cnt; i++) {
2292 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
2293 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
2295 if (hdr->idx == idx) {
2296 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
2297 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
2298 if (*pbuf == NULL) {
2299 printf("fail to alloc %d bytes\n",
2302 bcopy(pdata, *pbuf, hdr->len);
2307 printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
2312 int wl_ucode_init_uint(wl_info_t *wl, uint32 *data, uint32 idx)
2316 struct wl_fw_hdr *hdr;
2317 for (i = 0; i < wl->fw.fw_cnt; i++) {
2318 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
2319 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
2321 if (hdr->idx == idx) {
2322 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
2323 ASSERT(hdr->len == 4);
2324 *data = *((uint32 *) pdata);
2329 printf("ERROR: ucode tag:%d can not be found!\n", idx);
2332 #endif /* WLC_LOW */
2334 static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev)
2337 struct device *device = &pdev->dev;
2341 bzero((void *)&wl->fw, sizeof(struct wl_firmware));
2342 for (i = 0; i < WL_MAX_FW; i++) {
2343 if (wl_firmwares[i] == NULL)
2345 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
2346 UCODE_LOADER_API_VER);
2347 WL_NONE(("request fw %s\n", fw_name));
2348 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
2350 printf("%s: fail to load firmware %s\n",
2351 KBUILD_MODNAME, fw_name);
2355 WL_NONE(("request fw %s\n", fw_name));
2356 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
2357 UCODE_LOADER_API_VER);
2358 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
2360 printf("%s: fail to load firmware %s\n",
2361 KBUILD_MODNAME, fw_name);
2365 wl->fw.hdr_num_entries[i] =
2366 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
2367 WL_NONE(("request fw %s find: %d entries\n", fw_name,
2368 wl->fw.hdr_num_entries[i]));
2371 wl_ucode_data_init(wl);
2376 void wl_ucode_free_buf(void *p)
2380 #endif /* WLC_LOW */
2382 static void wl_release_fw(wl_info_t *wl)
2385 for (i = 0; i < WL_MAX_FW; i++) {
2386 release_firmware(wl->fw.fw_bin[i]);
2387 release_firmware(wl->fw.fw_hdr[i]);
2390 #endif /* WLC_HIGH_ONLY */