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__
19 #include <linux/kernel.h>
20 #include <linux/etherdevice.h>
21 #include <linux/types.h>
22 #include <linux/pci_ids.h>
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/sched.h>
26 #include <linux/firmware.h>
27 #include <net/mac80211.h>
29 #include <proto/802.11.h>
39 #include "phy/phy_version.h"
42 #include "phy/wlc_phy_hal.h"
43 #include "wlc_channel.h"
47 #include "wl_export.h"
49 #include "d11ucode_ext.h"
50 #include "wl_mac80211.h"
52 static void wl_timer(unsigned long data);
53 static void _wl_timer(struct wl_timer *t);
56 static int ieee_hw_init(struct ieee80211_hw *hw);
57 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
59 static int wl_linux_watchdog(void *ctx);
61 /* Flags we support */
62 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
68 FIF_BCN_PRBRESP_PROMISC)
72 #define WL_DEV_IF(dev) ((struct wl_if *)netdev_priv(dev))
73 #define WL_INFO(dev) ((struct wl_info *)(WL_DEV_IF(dev)->wl))
74 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev);
75 static void wl_release_fw(struct wl_info *wl);
77 /* local prototypes */
78 static int wl_start(struct sk_buff *skb, struct wl_info *wl);
79 static int wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw,
81 static void wl_dpc(unsigned long data);
82 static irqreturn_t wl_isr(int irq, void *dev_id);
84 static int __devinit wl_pci_probe(struct pci_dev *pdev,
85 const struct pci_device_id *ent);
86 static void wl_remove(struct pci_dev *pdev);
87 static void wl_free(struct wl_info *wl);
89 MODULE_AUTHOR("Broadcom Corporation");
90 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
91 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
92 MODULE_LICENSE("Dual BSD/GPL");
94 /* recognized PCI IDs */
95 static struct pci_device_id wl_id_table[] = {
96 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
97 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
98 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
102 MODULE_DEVICE_TABLE(pci, wl_id_table);
105 static int msglevel = 0xdeadbeef;
106 module_param(msglevel, int, 0);
107 static int phymsglevel = 0xdeadbeef;
108 module_param(phymsglevel, int, 0);
111 #define HW_TO_WL(hw) (hw->priv)
112 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
114 /* MAC80211 callback functions */
115 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
116 static int wl_ops_start(struct ieee80211_hw *hw);
117 static void wl_ops_stop(struct ieee80211_hw *hw);
118 static int wl_ops_add_interface(struct ieee80211_hw *hw,
119 struct ieee80211_vif *vif);
120 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
121 struct ieee80211_vif *vif);
122 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
123 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
124 struct ieee80211_vif *vif,
125 struct ieee80211_bss_conf *info,
127 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
128 unsigned int changed_flags,
129 unsigned int *total_flags, u64 multicast);
130 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
132 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
133 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
134 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
135 static int wl_ops_get_stats(struct ieee80211_hw *hw,
136 struct ieee80211_low_level_stats *stats);
137 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
138 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
139 struct ieee80211_vif *vif,
140 enum sta_notify_cmd cmd,
141 struct ieee80211_sta *sta);
142 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
143 const struct ieee80211_tx_queue_params *params);
144 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
145 static int wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
146 struct ieee80211_sta *sta);
147 static int wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
148 struct ieee80211_sta *sta);
149 static int wl_ops_ampdu_action(struct ieee80211_hw *hw,
150 struct ieee80211_vif *vif,
151 enum ieee80211_ampdu_mlme_action action,
152 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
153 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw);
155 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
158 struct wl_info *wl = hw->priv;
162 WL_ERROR("ops->tx called while down\n");
166 status = wl_start(skb, wl);
172 static int wl_ops_start(struct ieee80211_hw *hw)
174 struct wl_info *wl = hw->priv;
177 struct ieee80211_channel *curchan = hw->conf.channel;
178 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
181 ieee80211_wake_queues(hw);
183 blocked = wl_rfkill_set_hw_state(wl);
186 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
191 static void wl_ops_stop(struct ieee80211_hw *hw)
194 struct wl_info *wl = hw->priv;
197 ieee80211_stop_queues(hw);
201 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
206 /* Just STA for now */
207 if (vif->type != NL80211_IFTYPE_AP &&
208 vif->type != NL80211_IFTYPE_MESH_POINT &&
209 vif->type != NL80211_IFTYPE_STATION &&
210 vif->type != NL80211_IFTYPE_WDS &&
211 vif->type != NL80211_IFTYPE_ADHOC) {
212 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
213 __func__, vif->type);
223 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
229 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
235 /* put driver in down state */
242 * precondition: perimeter lock has been acquired
245 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
246 enum nl80211_channel_type type)
248 struct wl_info *wl = HW_TO_WL(hw);
252 case NL80211_CHAN_HT20:
253 case NL80211_CHAN_NO_HT:
254 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
256 case NL80211_CHAN_HT40MINUS:
257 case NL80211_CHAN_HT40PLUS:
258 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
268 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
270 struct ieee80211_conf *conf = &hw->conf;
271 struct wl_info *wl = HW_TO_WL(hw);
276 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
278 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
279 WL_ERROR("%s: Error setting listen_interval\n",
284 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
285 ASSERT(new_int == conf->listen_interval);
287 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
288 WL_ERROR("%s: change monitor mode: %s (implement)\n", __func__,
289 conf->flags & IEEE80211_CONF_MONITOR ?
291 if (changed & IEEE80211_CONF_CHANGE_PS)
292 WL_ERROR("%s: change power-save mode: %s (implement)\n",
293 __func__, conf->flags & IEEE80211_CONF_PS ?
296 if (changed & IEEE80211_CONF_CHANGE_POWER) {
298 (wl->wlc, "qtxpower", conf->power_level * 4)) {
299 WL_ERROR("%s: Error setting power_level\n", __func__);
303 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
304 if (new_int != (conf->power_level * 4))
305 WL_ERROR("%s: Power level req != actual, %d %d\n",
306 __func__, conf->power_level * 4, new_int);
308 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
309 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
311 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
313 (wl->wlc, WLC_SET_SRL,
314 conf->short_frame_max_tx_count) < 0) {
315 WL_ERROR("%s: Error setting srl\n", __func__);
319 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
321 WL_ERROR("%s: Error setting lrl\n", __func__);
333 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
334 struct ieee80211_vif *vif,
335 struct ieee80211_bss_conf *info, u32 changed)
337 struct wl_info *wl = HW_TO_WL(hw);
340 if (changed & BSS_CHANGED_ASSOC) {
341 /* association status changed (associated/disassociated)
342 * also implies a change in the AID.
344 WL_ERROR("%s: %s: %sassociated\n", KBUILD_MODNAME, __func__,
345 info->assoc ? "" : "dis");
346 wlc_associate_upd(wl->wlc, info->assoc);
348 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
349 /* CTS protection changed */
350 WL_ERROR("%s: use_cts_prot: %s (implement)\n", __func__,
351 info->use_cts_prot ? "true" : "false");
353 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
354 /* preamble changed */
355 WL_ERROR("%s: short preamble: %s (implement)\n", __func__,
356 info->use_short_preamble ? "true" : "false");
358 if (changed & BSS_CHANGED_ERP_SLOT) {
359 /* slot timing changed */
360 if (info->use_short_slot)
365 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
369 if (changed & BSS_CHANGED_HT) {
370 /* 802.11n parameters changed */
371 u16 mode = info->ht_operation_mode;
372 WL_NONE("%s: HT mode: 0x%04X\n", __func__, mode);
373 wlc_protection_upd(wl->wlc, WLC_PROT_N_CFG,
374 mode & IEEE80211_HT_OP_MODE_PROTECTION);
375 wlc_protection_upd(wl->wlc, WLC_PROT_N_NONGF,
376 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
377 wlc_protection_upd(wl->wlc, WLC_PROT_N_OBSS,
378 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
380 if (changed & BSS_CHANGED_BASIC_RATES) {
381 /* Basic rateset changed */
382 WL_ERROR("%s: Need to change Basic Rates: 0x%x (implement)\n",
383 __func__, (u32) info->basic_rates);
385 if (changed & BSS_CHANGED_BEACON_INT) {
386 /* Beacon interval changed */
387 WL_NONE("%s: Beacon Interval: %d\n",
388 __func__, info->beacon_int);
389 wlc_set(wl->wlc, WLC_SET_BCNPRD, info->beacon_int);
391 if (changed & BSS_CHANGED_BSSID) {
392 /* BSSID changed, for whatever reason (IBSS and managed mode) */
393 WL_NONE("%s: new BSSID: aid %d bss:%pM\n", __func__,
394 info->aid, info->bssid);
396 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
400 if (changed & BSS_CHANGED_BEACON) {
401 /* Beacon data changed, retrieve new beacon (beaconing modes) */
402 WL_ERROR("%s: beacon changed\n", __func__);
404 if (changed & BSS_CHANGED_BEACON_ENABLED) {
405 /* Beaconing should be enabled/disabled (beaconing modes) */
406 WL_ERROR("%s: Beacon enabled: %s\n", __func__,
407 info->enable_beacon ? "true" : "false");
409 if (changed & BSS_CHANGED_CQM) {
410 /* Connection quality monitor config changed */
411 WL_ERROR("%s: cqm change: threshold %d, hys %d (implement)\n",
412 __func__, info->cqm_rssi_thold, info->cqm_rssi_hyst);
414 if (changed & BSS_CHANGED_IBSS) {
415 /* IBSS join status changed */
416 WL_ERROR("%s: IBSS joined: %s (implement)\n", __func__,
417 info->ibss_joined ? "true" : "false");
419 if (changed & BSS_CHANGED_ARP_FILTER) {
420 /* Hardware ARP filter address list or state changed */
421 WL_ERROR("%s: arp filtering: enabled %s, count %d (implement)\n",
422 __func__, info->arp_filter_enabled ? "true" : "false",
425 if (changed & BSS_CHANGED_QOS) {
427 * QoS for this association was enabled/disabled.
428 * Note that it is only ever disabled for station mode.
430 WL_ERROR("%s: qos enabled: %s (implement)\n", __func__,
431 info->qos ? "true" : "false");
433 if (changed & BSS_CHANGED_IDLE) {
434 /* Idle changed for this BSS/interface */
435 WL_ERROR("%s: BSS idle: %s (implement)\n", __func__,
436 info->idle ? "true" : "false");
442 wl_ops_configure_filter(struct ieee80211_hw *hw,
443 unsigned int changed_flags,
444 unsigned int *total_flags, u64 multicast)
446 struct wl_info *wl = hw->priv;
448 changed_flags &= MAC_FILTERS;
449 *total_flags &= MAC_FILTERS;
450 if (changed_flags & FIF_PROMISC_IN_BSS)
451 WL_ERROR("FIF_PROMISC_IN_BSS\n");
452 if (changed_flags & FIF_ALLMULTI)
453 WL_ERROR("FIF_ALLMULTI\n");
454 if (changed_flags & FIF_FCSFAIL)
455 WL_ERROR("FIF_FCSFAIL\n");
456 if (changed_flags & FIF_PLCPFAIL)
457 WL_ERROR("FIF_PLCPFAIL\n");
458 if (changed_flags & FIF_CONTROL)
459 WL_ERROR("FIF_CONTROL\n");
460 if (changed_flags & FIF_OTHER_BSS)
461 WL_ERROR("FIF_OTHER_BSS\n");
462 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
463 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
465 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
466 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
467 wlc_mac_bcn_promisc_change(wl->wlc, 1);
469 wlc_mac_bcn_promisc_change(wl->wlc, 0);
470 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
478 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
480 WL_NONE("%s: Enter\n", __func__);
484 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
486 struct wl_info *wl = hw->priv;
487 WL_NONE("Scan Start\n");
489 wlc_scan_start(wl->wlc);
494 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
496 struct wl_info *wl = hw->priv;
497 WL_NONE("Scan Complete\n");
499 wlc_scan_stop(wl->wlc);
504 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
506 WL_ERROR("%s: Enter\n", __func__);
511 wl_ops_get_stats(struct ieee80211_hw *hw,
512 struct ieee80211_low_level_stats *stats)
514 struct wl_info *wl = hw->priv;
519 stats->dot11ACKFailureCount = cnt->txnoack;
520 stats->dot11RTSFailureCount = cnt->txnocts;
521 stats->dot11FCSErrorCount = cnt->rxcrc;
522 stats->dot11RTSSuccessCount = cnt->txrts;
527 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
529 struct wl_info *wl = hw->priv;
532 wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
538 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
539 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
541 WL_NONE("%s: Enter\n", __func__);
544 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
551 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
552 const struct ieee80211_tx_queue_params *params)
554 struct wl_info *wl = hw->priv;
556 WL_NONE("%s: Enter (WME config)\n", __func__);
557 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
558 params->txop, params->cw_min, params->cw_max, params->aifs);
561 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
567 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
569 WL_ERROR("%s: Enter\n", __func__);
574 wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
575 struct ieee80211_sta *sta)
580 struct wl_info *wl = hw->priv;
583 scb = (struct scb *)sta->drv_priv;
584 memset(scb, 0, sizeof(struct scb));
585 for (i = 0; i < NUMPRIO; i++)
586 scb->seqctl[i] = 0xFFFF;
587 scb->seqctl_nonqos = 0xFFFF;
588 scb->magic = SCB_MAGIC;
590 wl->pub->global_scb = scb;
591 wl->pub->global_ampdu = &(scb->scb_ampdu);
592 wl->pub->global_ampdu->scb = scb;
593 wl->pub->global_ampdu->max_pdu = 16;
594 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
595 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
597 sta->ht_cap.ht_supported = true;
598 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
599 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
600 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
601 IEEE80211_HT_CAP_SGI_20 |
602 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
604 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
609 wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
610 struct ieee80211_sta *sta)
612 WL_NONE("%s: Enter\n", __func__);
617 wl_ops_ampdu_action(struct ieee80211_hw *hw,
618 struct ieee80211_vif *vif,
619 enum ieee80211_ampdu_mlme_action action,
620 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
623 struct scb *scb = (struct scb *)sta->drv_priv;
625 struct wl_info *wl = hw->priv;
628 ASSERT(scb->magic == SCB_MAGIC);
630 case IEEE80211_AMPDU_RX_START:
631 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
633 case IEEE80211_AMPDU_RX_STOP:
634 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
636 case IEEE80211_AMPDU_TX_START:
638 status = wlc_aggregatable(wl->wlc, tid);
641 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
644 /* XXX: Use the starting sequence number provided ... */
646 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
649 case IEEE80211_AMPDU_TX_STOP:
650 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
652 case IEEE80211_AMPDU_TX_OPERATIONAL:
653 /* Not sure what to do here */
654 /* Power save wakeup */
655 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
659 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
665 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
667 struct wl_info *wl = HW_TO_WL(hw);
671 blocked = wlc_check_radio_disabled(wl->wlc);
674 WL_NONE("wl: rfkill_poll: %d\n", blocked);
675 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
678 static const struct ieee80211_ops wl_ops = {
680 .start = wl_ops_start,
682 .add_interface = wl_ops_add_interface,
683 .remove_interface = wl_ops_remove_interface,
684 .config = wl_ops_config,
685 .bss_info_changed = wl_ops_bss_info_changed,
686 .configure_filter = wl_ops_configure_filter,
687 .set_tim = wl_ops_set_tim,
688 .sw_scan_start = wl_ops_sw_scan_start,
689 .sw_scan_complete = wl_ops_sw_scan_complete,
690 .set_tsf = wl_ops_set_tsf,
691 .get_stats = wl_ops_get_stats,
692 .set_rts_threshold = wl_ops_set_rts_threshold,
693 .sta_notify = wl_ops_sta_notify,
694 .conf_tx = wl_ops_conf_tx,
695 .get_tsf = wl_ops_get_tsf,
696 .sta_add = wl_ops_sta_add,
697 .sta_remove = wl_ops_sta_remove,
698 .ampdu_action = wl_ops_ampdu_action,
699 .rfkill_poll = wl_ops_rfkill_poll,
703 * is called in wl_pci_probe() context, therefore no locking required.
705 static int wl_set_hint(struct wl_info *wl, char *abbrev)
707 WL_NONE("%s: Sending country code %c%c to MAC80211\n",
708 __func__, abbrev[0], abbrev[1]);
709 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
713 * attach to the WL device.
715 * Attach to the WL device identified by vendor and device parameters.
716 * regs is a host accessible memory address pointing to WL device registers.
718 * wl_attach is not defined as static because in the case where no bus
719 * is defined, wl_attach will never be called, and thus, gcc will issue
720 * a warning that this function is defined but not used if we declare
724 * is called in wl_pci_probe() context, therefore no locking required.
726 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
727 uint bustype, void *btparam, uint irq)
730 struct osl_info *osh;
733 unsigned long base_addr;
734 struct ieee80211_hw *hw;
741 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
745 osh = osl_attach(btparam, bustype);
748 /* allocate private info */
749 hw = pci_get_drvdata(btparam); /* btparam == pdev */
754 atomic_set(&wl->callbacks, 0);
756 /* setup the bottom half handler */
757 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
763 if (bustype == PCI_BUS) {
765 } else if (bustype == RPC_BUS) {
769 WL_TRACE("force to PCI\n");
771 wl->bcm_bustype = bustype;
773 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
774 if (wl->regsva == NULL) {
775 WL_ERROR("wl%d: ioremap() failed\n", unit);
778 spin_lock_init(&wl->lock);
779 spin_lock_init(&wl->isr_lock);
782 if (wl_request_fw(wl, (struct pci_dev *)btparam) < 0) {
783 WL_ERROR("%s: Failed to find firmware usually in %s\n",
784 KBUILD_MODNAME, "/lib/firmware/brcm");
786 wl_remove((struct pci_dev *)btparam);
790 /* common load-time initialization */
791 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
792 wl->regsva, wl->bcm_bustype, btparam, &err);
795 WL_ERROR("%s: wlc_attach() failed with code %d\n",
796 KBUILD_MODNAME, err);
799 wl->pub = wlc_pub(wl->wlc);
801 wl->pub->ieee_hw = hw;
802 ASSERT(wl->pub->ieee_hw);
803 ASSERT(wl->pub->ieee_hw->priv == wl);
806 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
807 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
810 /* register our interrupt handler */
811 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
812 WL_ERROR("wl%d: request_irq() failed\n", unit);
817 /* register module */
818 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
821 if (ieee_hw_init(hw)) {
822 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
826 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
827 ASSERT(is_valid_ether_addr(perm));
828 SET_IEEE80211_PERM_ADDR(hw, perm);
830 err = ieee80211_register_hw(hw);
832 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
836 if (wl->pub->srom_ccode[0])
837 err = wl_set_hint(wl, wl->pub->srom_ccode);
839 err = wl_set_hint(wl, "US");
841 WL_ERROR("%s: regulatory_hint failed, status %d\n",
856 #define CHAN2GHZ(channel, freqency, chflags) { \
857 .band = IEEE80211_BAND_2GHZ, \
858 .center_freq = (freqency), \
859 .hw_value = (channel), \
861 .max_antenna_gain = 0, \
865 static struct ieee80211_channel wl_2ghz_chantable[] = {
866 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
867 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
868 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
869 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
870 CHAN2GHZ(5, 2432, 0),
871 CHAN2GHZ(6, 2437, 0),
872 CHAN2GHZ(7, 2442, 0),
873 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
874 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
875 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
876 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
878 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
879 IEEE80211_CHAN_NO_HT40PLUS),
881 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
882 IEEE80211_CHAN_NO_HT40PLUS),
884 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
885 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
888 #define CHAN5GHZ(channel, chflags) { \
889 .band = IEEE80211_BAND_5GHZ, \
890 .center_freq = 5000 + 5*(channel), \
891 .hw_value = (channel), \
893 .max_antenna_gain = 0, \
897 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
899 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
900 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
901 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
902 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
905 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
906 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
908 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
909 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
911 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
912 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
914 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
915 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
918 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
919 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
921 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
922 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
924 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
925 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
927 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
928 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
930 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
931 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
933 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
934 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
936 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
937 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
939 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
940 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
942 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
943 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
945 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
946 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
948 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
949 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
950 IEEE80211_CHAN_NO_HT40MINUS),
952 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
953 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
954 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
955 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
956 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
959 #define RATE(rate100m, _flags) { \
960 .bitrate = (rate100m), \
962 .hw_value = (rate100m / 5), \
965 static struct ieee80211_rate wl_legacy_ratetable[] = {
967 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
968 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
969 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
980 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
981 .band = IEEE80211_BAND_2GHZ,
982 .channels = wl_2ghz_chantable,
983 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
984 .bitrates = wl_legacy_ratetable,
985 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
987 /* from include/linux/ieee80211.h */
988 .cap = IEEE80211_HT_CAP_GRN_FLD |
989 IEEE80211_HT_CAP_SGI_20 |
990 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
991 .ht_supported = true,
992 .ampdu_factor = AMPDU_RX_FACTOR_64K,
993 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
995 /* placeholders for now */
996 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
998 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1002 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
1003 .band = IEEE80211_BAND_5GHZ,
1004 .channels = wl_5ghz_nphy_chantable,
1005 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
1006 .bitrates = wl_legacy_ratetable + 4,
1007 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1009 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1010 .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 */
1011 .ht_supported = true,
1012 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1013 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1015 /* placeholders for now */
1016 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1018 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1023 * is called in wl_pci_probe() context, therefore no locking required.
1025 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1027 struct wl_info *wl = HW_TO_WL(hw);
1033 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1034 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1036 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1037 WL_ERROR("Phy list failed\n");
1039 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
1041 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1042 if (phy_list[0] == 'c') {
1044 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1045 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1047 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1053 /* Assume all bands use the same phy. True for 11n devices. */
1054 if (NBANDS_PUB(wl->pub) > 1) {
1056 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1057 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1064 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
1070 * is called in wl_pci_probe() context, therefore no locking required.
1072 static int ieee_hw_init(struct ieee80211_hw *hw)
1074 hw->flags = IEEE80211_HW_SIGNAL_DBM
1075 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1076 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1077 | IEEE80211_HW_AMPDU_AGGREGATION;
1079 hw->extra_tx_headroom = wlc_get_header_len();
1080 /* FIXME: should get this from wlc->machwcap */
1082 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1083 * mac80211/status.c:ieee80211_tx_status() checks this value,
1084 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1085 * appears to always set 3 rates
1087 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1089 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1090 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1092 hw->rate_control_algorithm = "minstrel_ht";
1094 hw->sta_data_size = sizeof(struct scb);
1095 return ieee_hw_rate_init(hw);
1099 * determines if a device is a WL device, and if so, attaches it.
1101 * This function determines if a device pointed to by pdev is a WL device,
1102 * and if so, performs a wl_attach() on it.
1104 * Perimeter lock is initialized in the course of this function.
1106 static int __devinit
1107 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1111 struct ieee80211_hw *hw;
1116 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1117 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1118 PCI_FUNC(pdev->devfn), pdev->irq);
1120 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1121 (((pdev->device & 0xff00) != 0x4300) &&
1122 ((pdev->device & 0xff00) != 0x4700) &&
1123 ((pdev->device < 43000) || (pdev->device > 43999))))
1126 rc = pci_enable_device(pdev);
1128 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1129 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1130 PCI_FUNC(pdev->devfn));
1133 pci_set_master(pdev);
1135 pci_read_config_dword(pdev, 0x40, &val);
1136 if ((val & 0x0000ff00) != 0)
1137 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1139 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1141 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1146 SET_IEEE80211_DEV(hw, &pdev->dev);
1148 pci_set_drvdata(pdev, hw);
1150 memset(hw->priv, 0, sizeof(*wl));
1152 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1153 PCI_BUS, pdev, pdev->irq);
1156 WL_ERROR("%s: %s: wl_attach failed!\n",
1157 KBUILD_MODNAME, __func__);
1162 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1166 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1169 struct ieee80211_hw *hw;
1171 WL_TRACE("wl: wl_suspend\n");
1173 hw = pci_get_drvdata(pdev);
1176 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1180 /* only need to flag hw is down for proper resume */
1182 wl->pub->hw_up = false;
1185 pci_save_state(pdev);
1186 pci_disable_device(pdev);
1187 return pci_set_power_state(pdev, PCI_D3hot);
1190 static int wl_resume(struct pci_dev *pdev)
1193 struct ieee80211_hw *hw;
1197 WL_TRACE("wl: wl_resume\n");
1198 hw = pci_get_drvdata(pdev);
1201 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1205 err = pci_set_power_state(pdev, PCI_D0);
1209 pci_restore_state(pdev);
1211 err = pci_enable_device(pdev);
1215 pci_set_master(pdev);
1217 pci_read_config_dword(pdev, 0x40, &val);
1218 if ((val & 0x0000ff00) != 0)
1219 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1222 * done. driver will be put in up state
1223 * in wl_ops_add_interface() call.
1229 * called from both kernel as from wl_*()
1230 * precondition: perimeter lock is not acquired.
1232 static void wl_remove(struct pci_dev *pdev)
1235 struct ieee80211_hw *hw;
1238 hw = pci_get_drvdata(pdev);
1241 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1246 status = wlc_chipmatch(pdev->vendor, pdev->device);
1249 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1253 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1254 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1255 ieee80211_unregister_hw(hw);
1259 WL_NONE("%s: Down\n", __func__);
1261 pci_disable_device(pdev);
1265 pci_set_drvdata(pdev, NULL);
1266 ieee80211_free_hw(hw);
1269 static struct pci_driver wl_pci_driver = {
1270 .name = KBUILD_MODNAME,
1271 .probe = wl_pci_probe,
1272 .suspend = wl_suspend,
1273 .resume = wl_resume,
1274 .remove = __devexit_p(wl_remove),
1275 .id_table = wl_id_table,
1279 * This is the main entry point for the WL driver.
1281 * This function determines if a device pointed to by pdev is a WL device,
1282 * and if so, performs a wl_attach() on it.
1285 static int __init wl_module_init(void)
1287 int error = -ENODEV;
1290 if (msglevel != 0xdeadbeef)
1291 wl_msg_level = msglevel;
1293 char *var = getvar(NULL, "wl_msglevel");
1295 wl_msg_level = simple_strtoul(var, NULL, 0);
1298 extern u32 phyhal_msg_level;
1300 if (phymsglevel != 0xdeadbeef)
1301 phyhal_msg_level = phymsglevel;
1303 char *var = getvar(NULL, "phy_msglevel");
1305 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1310 error = pci_register_driver(&wl_pci_driver);
1320 * This function unloads the WL driver from the system.
1322 * This function unconditionally unloads the WL driver module from the
1326 static void __exit wl_module_exit(void)
1328 pci_unregister_driver(&wl_pci_driver);
1332 module_init(wl_module_init);
1333 module_exit(wl_module_exit);
1336 * This function frees the WL per-device resources.
1338 * This function frees resources owned by the WL device pointed to
1339 * by the wl parameter.
1341 * precondition: can both be called locked and unlocked
1344 static void wl_free(struct wl_info *wl)
1346 struct wl_timer *t, *next;
1347 struct osl_info *osh;
1350 /* free ucode data */
1352 wl_ucode_data_free();
1354 free_irq(wl->irq, wl);
1357 tasklet_kill(&wl->tasklet);
1360 wlc_module_unregister(wl->pub, "linux", wl);
1363 /* free common resources */
1365 wlc_detach(wl->wlc);
1370 /* virtual interface deletion is deferred so we cannot spinwait */
1372 /* wait for all pending callbacks to complete */
1373 while (atomic_read(&wl->callbacks) > 0)
1377 for (t = wl->timers; t; t = next) {
1389 * unregister_netdev() calls get_stats() which may read chip registers
1390 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1392 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1393 wl->bcm_bustype != JTAG_BUS) {
1394 iounmap((void *)wl->regsva);
1404 * precondition: perimeter lock has been acquired
1406 static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1411 return wl_start_int(wl, WL_TO_HW(wl), skb);
1414 static int BCMFASTPATH
1415 wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1417 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1418 return NETDEV_TX_OK;
1422 * precondition: perimeter lock has been acquired
1424 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1427 WL_ERROR("Shouldn't be here %s\n", __func__);
1431 * precondition: perimeter lock has been acquired
1433 void wl_init(struct wl_info *wl)
1435 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1443 * precondition: perimeter lock has been acquired
1445 uint wl_reset(struct wl_info *wl)
1447 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1451 /* dpc will not be rescheduled */
1458 * These are interrupt on/off entry points. Disable interrupts
1459 * during interrupt state transition.
1461 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1463 unsigned long flags;
1465 INT_LOCK(wl, flags);
1466 wlc_intrson(wl->wlc);
1467 INT_UNLOCK(wl, flags);
1471 * precondition: perimeter lock has been acquired
1473 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1478 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1480 unsigned long flags;
1483 INT_LOCK(wl, flags);
1484 status = wlc_intrsoff(wl->wlc);
1485 INT_UNLOCK(wl, flags);
1489 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1491 unsigned long flags;
1493 INT_LOCK(wl, flags);
1494 wlc_intrsrestore(wl->wlc, macintmask);
1495 INT_UNLOCK(wl, flags);
1499 * precondition: perimeter lock has been acquired
1501 int wl_up(struct wl_info *wl)
1508 error = wlc_up(wl->wlc);
1514 * precondition: perimeter lock has been acquired
1516 void wl_down(struct wl_info *wl)
1518 uint callbacks, ret_val = 0;
1520 /* call common down function */
1521 ret_val = wlc_down(wl->wlc);
1522 callbacks = atomic_read(&wl->callbacks) - ret_val;
1524 /* wait for down callbacks to complete */
1527 /* For HIGH_only driver, it's important to actually schedule other work,
1528 * not just spin wait since everything runs at schedule level
1530 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1535 static irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1539 unsigned long flags;
1541 wl = (struct wl_info *) dev_id;
1543 WL_ISRLOCK(wl, flags);
1545 /* call common first level interrupt handler */
1546 ours = wlc_isr(wl->wlc, &wantdpc);
1548 /* if more to do... */
1551 /* ...and call the second level interrupt handler */
1553 ASSERT(wl->resched == false);
1554 tasklet_schedule(&wl->tasklet);
1558 WL_ISRUNLOCK(wl, flags);
1560 return IRQ_RETVAL(ours);
1563 static void BCMFASTPATH wl_dpc(unsigned long data)
1567 wl = (struct wl_info *) data;
1571 /* call the common second level interrupt handler */
1574 unsigned long flags;
1576 INT_LOCK(wl, flags);
1577 wlc_intrsupd(wl->wlc);
1578 INT_UNLOCK(wl, flags);
1581 wl->resched = wlc_dpc(wl->wlc, true);
1584 /* wlc_dpc() may bring the driver down */
1588 /* re-schedule dpc */
1590 tasklet_schedule(&wl->tasklet);
1592 /* re-enable interrupts */
1601 * is called by the kernel from software irq context
1603 static void wl_timer(unsigned long data)
1605 _wl_timer((struct wl_timer *) data);
1609 * precondition: perimeter lock is not acquired
1611 static void _wl_timer(struct wl_timer *t)
1617 t->timer.expires = jiffies + t->ms * HZ / 1000;
1618 atomic_inc(&t->wl->callbacks);
1619 add_timer(&t->timer);
1627 atomic_dec(&t->wl->callbacks);
1633 * Adds a timer to the list. Caller supplies a timer function.
1634 * Is called from wlc.
1636 * precondition: perimeter lock has been acquired
1638 struct wl_timer *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg),
1639 void *arg, const char *name)
1643 t = kmalloc(sizeof(struct wl_timer), GFP_ATOMIC);
1645 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1649 memset(t, 0, sizeof(struct wl_timer));
1651 init_timer(&t->timer);
1652 t->timer.data = (unsigned long) t;
1653 t->timer.function = wl_timer;
1657 t->next = wl->timers;
1661 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1663 strcpy(t->name, name);
1669 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1670 * as well as it's easier to make it periodic
1672 * precondition: perimeter lock has been acquired
1674 void wl_add_timer(struct wl_info *wl, struct wl_timer *t, uint ms, int periodic)
1678 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1679 __func__, t->name, periodic);
1685 t->periodic = (bool) periodic;
1687 t->timer.expires = jiffies + ms * HZ / 1000;
1689 atomic_inc(&wl->callbacks);
1690 add_timer(&t->timer);
1694 * return true if timer successfully deleted, false if still pending
1696 * precondition: perimeter lock has been acquired
1698 bool wl_del_timer(struct wl_info *wl, struct wl_timer *t)
1702 if (!del_timer(&t->timer)) {
1705 atomic_dec(&wl->callbacks);
1712 * precondition: perimeter lock has been acquired
1714 void wl_free_timer(struct wl_info *wl, struct wl_timer *t)
1716 struct wl_timer *tmp;
1718 /* delete the timer in case it is active */
1719 wl_del_timer(wl, t);
1721 if (wl->timers == t) {
1722 wl->timers = wl->timers->next;
1734 if (tmp->next == t) {
1735 tmp->next = t->next;
1749 * runs in software irq context
1751 * precondition: perimeter lock is not acquired
1753 static int wl_linux_watchdog(void *ctx)
1755 struct wl_info *wl = (struct wl_info *) ctx;
1757 struct net_device_stats *stats = NULL;
1761 ASSERT(wl->stats_id < 2);
1763 cnt = wl->pub->_cnt;
1764 id = 1 - wl->stats_id;
1765 stats = &wl->stats_watchdog[id];
1766 stats->rx_packets = cnt->rxframe;
1767 stats->tx_packets = cnt->txframe;
1768 stats->rx_bytes = cnt->rxbyte;
1769 stats->tx_bytes = cnt->txbyte;
1770 stats->rx_errors = cnt->rxerror;
1771 stats->tx_errors = cnt->txerror;
1772 stats->collisions = 0;
1774 stats->rx_length_errors = 0;
1775 stats->rx_over_errors = cnt->rxoflo;
1776 stats->rx_crc_errors = cnt->rxcrc;
1777 stats->rx_frame_errors = 0;
1778 stats->rx_fifo_errors = cnt->rxoflo;
1779 stats->rx_missed_errors = 0;
1781 stats->tx_fifo_errors = cnt->txuflo;
1795 char *wl_firmwares[WL_MAX_FW] = {
1801 * precondition: perimeter lock has been acquired
1803 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1807 struct wl_fw_hdr *hdr;
1808 for (i = 0; i < wl->fw.fw_cnt; i++) {
1809 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1810 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1812 if (hdr->idx == idx) {
1813 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1814 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1815 if (*pbuf == NULL) {
1816 WL_ERROR("fail to alloc %d bytes\n",
1820 memcpy(*pbuf, pdata, hdr->len);
1825 WL_ERROR("ERROR: ucode buf tag:%d can not be found!\n", idx);
1828 return BCME_NOTFOUND;
1832 * Precondition: Since this function is called in wl_pci_probe() context,
1833 * no locking is required.
1835 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1839 struct wl_fw_hdr *hdr;
1840 for (i = 0; i < wl->fw.fw_cnt; i++) {
1841 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1842 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1844 if (hdr->idx == idx) {
1845 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1846 ASSERT(hdr->len == 4);
1847 *data = *((u32 *) pdata);
1852 WL_ERROR("ERROR: ucode tag:%d can not be found!\n", idx);
1857 * Precondition: Since this function is called in wl_pci_probe() context,
1858 * no locking is required.
1860 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1863 struct device *device = &pdev->dev;
1867 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1868 for (i = 0; i < WL_MAX_FW; i++) {
1869 if (wl_firmwares[i] == NULL)
1871 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1872 UCODE_LOADER_API_VER);
1873 WL_NONE("request fw %s\n", fw_name);
1874 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1876 WL_ERROR("%s: fail to load firmware %s\n",
1877 KBUILD_MODNAME, fw_name);
1880 WL_NONE("request fw %s\n", fw_name);
1881 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1882 UCODE_LOADER_API_VER);
1883 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1885 WL_ERROR("%s: fail to load firmware %s\n",
1886 KBUILD_MODNAME, fw_name);
1889 wl->fw.hdr_num_entries[i] =
1890 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1891 WL_NONE("request fw %s find: %d entries\n",
1892 fw_name, wl->fw.hdr_num_entries[i]);
1895 return wl_ucode_data_init(wl);
1899 * precondition: can both be called locked and unlocked
1901 void wl_ucode_free_buf(void *p)
1907 * Precondition: Since this function is called in wl_pci_probe() context,
1908 * no locking is required.
1910 static void wl_release_fw(struct wl_info *wl)
1913 for (i = 0; i < WL_MAX_FW; i++) {
1914 release_firmware(wl->fw.fw_bin[i]);
1915 release_firmware(wl->fw.fw_hdr[i]);
1921 * checks validity of all firmware images loaded from user space
1923 * Precondition: Since this function is called in wl_pci_probe() context,
1924 * no locking is required.
1926 int wl_check_firmwares(struct wl_info *wl)
1931 const struct firmware *fw;
1932 const struct firmware *fw_hdr;
1933 struct wl_fw_hdr *ucode_hdr;
1934 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1935 fw = wl->fw.fw_bin[i];
1936 fw_hdr = wl->fw.fw_hdr[i];
1937 if (fw == NULL && fw_hdr == NULL) {
1939 } else if (fw == NULL || fw_hdr == NULL) {
1940 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1942 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1943 WL_ERROR("%s: non integral fw hdr file size %zu/%zu\n",
1944 __func__, fw_hdr->size,
1945 sizeof(struct wl_fw_hdr));
1947 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1948 WL_ERROR("%s: out of bounds fw file size %zu\n",
1949 __func__, fw->size);
1952 /* check if ucode section overruns firmware image */
1953 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1954 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1955 !rc; entry++, ucode_hdr++) {
1956 if (ucode_hdr->offset + ucode_hdr->len >
1958 WL_ERROR("%s: conflicting bin/hdr\n",
1965 if (rc == 0 && wl->fw.fw_cnt != i) {
1966 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1973 * precondition: perimeter lock has been acquired
1975 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1977 bool blocked = wlc_check_radio_disabled(wl->wlc);
1979 WL_NONE("%s: update hw state: blocked=%s\n", __func__,
1980 blocked ? "true" : "false");
1982 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1984 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);