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>
38 #include "phy/wlc_phy_int.h"
40 #include "wlc_types.h"
42 #include "phy/phy_version.h"
44 #include "wlc_channel.h"
48 #include "wl_export.h"
50 #include "d11ucode_ext.h"
51 #include "wl_mac80211.h"
53 static void wl_timer(unsigned long data);
54 static void _wl_timer(struct wl_timer *t);
57 static int ieee_hw_init(struct ieee80211_hw *hw);
58 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
60 static int wl_linux_watchdog(void *ctx);
62 /* Flags we support */
63 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
69 FIF_BCN_PRBRESP_PROMISC)
73 #define WL_DEV_IF(dev) ((struct wl_if *)netdev_priv(dev))
74 #define WL_INFO(dev) ((struct wl_info *)(WL_DEV_IF(dev)->wl))
75 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev);
76 static void wl_release_fw(struct wl_info *wl);
78 /* local prototypes */
79 static int wl_start(struct sk_buff *skb, struct wl_info *wl);
80 static int wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw,
82 static void wl_dpc(unsigned long data);
83 static irqreturn_t wl_isr(int irq, void *dev_id);
85 static int __devinit wl_pci_probe(struct pci_dev *pdev,
86 const struct pci_device_id *ent);
87 static void wl_remove(struct pci_dev *pdev);
88 static void wl_free(struct wl_info *wl);
90 MODULE_AUTHOR("Broadcom Corporation");
91 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
92 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
93 MODULE_LICENSE("Dual BSD/GPL");
95 /* recognized PCI IDs */
96 static struct pci_device_id wl_id_table[] = {
97 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
98 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
99 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
103 MODULE_DEVICE_TABLE(pci, wl_id_table);
106 static int msglevel = 0xdeadbeef;
107 module_param(msglevel, int, 0);
108 static int phymsglevel = 0xdeadbeef;
109 module_param(phymsglevel, int, 0);
112 #define HW_TO_WL(hw) (hw->priv)
113 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
115 /* MAC80211 callback functions */
116 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
117 static int wl_ops_start(struct ieee80211_hw *hw);
118 static void wl_ops_stop(struct ieee80211_hw *hw);
119 static int wl_ops_add_interface(struct ieee80211_hw *hw,
120 struct ieee80211_vif *vif);
121 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
122 struct ieee80211_vif *vif);
123 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
124 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
125 struct ieee80211_vif *vif,
126 struct ieee80211_bss_conf *info,
128 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
129 unsigned int changed_flags,
130 unsigned int *total_flags, u64 multicast);
131 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
133 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
134 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
135 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
136 static int wl_ops_get_stats(struct ieee80211_hw *hw,
137 struct ieee80211_low_level_stats *stats);
138 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
139 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
140 struct ieee80211_vif *vif,
141 enum sta_notify_cmd cmd,
142 struct ieee80211_sta *sta);
143 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
144 const struct ieee80211_tx_queue_params *params);
145 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
146 static int wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
147 struct ieee80211_sta *sta);
148 static int wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
149 struct ieee80211_sta *sta);
150 static int wl_ops_ampdu_action(struct ieee80211_hw *hw,
151 struct ieee80211_vif *vif,
152 enum ieee80211_ampdu_mlme_action action,
153 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
154 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw);
156 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
159 struct wl_info *wl = hw->priv;
163 WL_ERROR("ops->tx called while down\n");
167 status = wl_start(skb, wl);
173 static int wl_ops_start(struct ieee80211_hw *hw)
175 struct wl_info *wl = hw->priv;
178 struct ieee80211_channel *curchan = hw->conf.channel;
179 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
182 ieee80211_wake_queues(hw);
184 blocked = wl_rfkill_set_hw_state(wl);
187 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
192 static void wl_ops_stop(struct ieee80211_hw *hw)
195 struct wl_info *wl = hw->priv;
198 ieee80211_stop_queues(hw);
202 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
207 /* Just STA for now */
208 if (vif->type != NL80211_IFTYPE_AP &&
209 vif->type != NL80211_IFTYPE_MESH_POINT &&
210 vif->type != NL80211_IFTYPE_STATION &&
211 vif->type != NL80211_IFTYPE_WDS &&
212 vif->type != NL80211_IFTYPE_ADHOC) {
213 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
214 __func__, vif->type);
224 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
230 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
236 /* put driver in down state */
243 * precondition: perimeter lock has been acquired
246 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
247 enum nl80211_channel_type type)
249 struct wl_info *wl = HW_TO_WL(hw);
253 case NL80211_CHAN_HT20:
254 case NL80211_CHAN_NO_HT:
255 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
257 case NL80211_CHAN_HT40MINUS:
258 case NL80211_CHAN_HT40PLUS:
259 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
269 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
271 struct ieee80211_conf *conf = &hw->conf;
272 struct wl_info *wl = HW_TO_WL(hw);
277 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
279 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
280 WL_ERROR("%s: Error setting listen_interval\n",
285 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
286 ASSERT(new_int == conf->listen_interval);
288 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
289 WL_ERROR("%s: change monitor mode: %s (implement)\n", __func__,
290 conf->flags & IEEE80211_CONF_MONITOR ?
292 if (changed & IEEE80211_CONF_CHANGE_PS)
293 WL_ERROR("%s: change power-save mode: %s (implement)\n",
294 __func__, conf->flags & IEEE80211_CONF_PS ?
297 if (changed & IEEE80211_CONF_CHANGE_POWER) {
299 (wl->wlc, "qtxpower", conf->power_level * 4)) {
300 WL_ERROR("%s: Error setting power_level\n", __func__);
304 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
305 if (new_int != (conf->power_level * 4))
306 WL_ERROR("%s: Power level req != actual, %d %d\n",
307 __func__, conf->power_level * 4, new_int);
309 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
310 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
312 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
314 (wl->wlc, WLC_SET_SRL,
315 conf->short_frame_max_tx_count) < 0) {
316 WL_ERROR("%s: Error setting srl\n", __func__);
320 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
322 WL_ERROR("%s: Error setting lrl\n", __func__);
334 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
335 struct ieee80211_vif *vif,
336 struct ieee80211_bss_conf *info, u32 changed)
338 struct wl_info *wl = HW_TO_WL(hw);
341 if (changed & BSS_CHANGED_ASSOC) {
342 /* association status changed (associated/disassociated)
343 * also implies a change in the AID.
345 WL_ERROR("%s: %s: %sassociated\n", KBUILD_MODNAME, __func__,
346 info->assoc ? "" : "dis");
347 wlc_associate_upd(wl->wlc, info->assoc);
349 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
350 /* CTS protection changed */
351 WL_ERROR("%s: use_cts_prot: %s (implement)\n", __func__,
352 info->use_cts_prot ? "true" : "false");
354 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
355 /* preamble changed */
356 WL_ERROR("%s: short preamble: %s (implement)\n", __func__,
357 info->use_short_preamble ? "true" : "false");
359 if (changed & BSS_CHANGED_ERP_SLOT) {
360 /* slot timing changed */
361 if (info->use_short_slot)
366 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
370 if (changed & BSS_CHANGED_HT) {
371 /* 802.11n parameters changed */
372 u16 mode = info->ht_operation_mode;
373 WL_NONE("%s: HT mode: 0x%04X\n", __func__, mode);
374 wlc_protection_upd(wl->wlc, WLC_PROT_N_CFG,
375 mode & IEEE80211_HT_OP_MODE_PROTECTION);
376 wlc_protection_upd(wl->wlc, WLC_PROT_N_NONGF,
377 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
378 wlc_protection_upd(wl->wlc, WLC_PROT_N_OBSS,
379 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
381 if (changed & BSS_CHANGED_BASIC_RATES) {
382 /* Basic rateset changed */
383 WL_ERROR("%s: Need to change Basic Rates: 0x%x (implement)\n",
384 __func__, (u32) info->basic_rates);
386 if (changed & BSS_CHANGED_BEACON_INT) {
387 /* Beacon interval changed */
388 WL_NONE("%s: Beacon Interval: %d\n",
389 __func__, info->beacon_int);
390 wlc_set(wl->wlc, WLC_SET_BCNPRD, info->beacon_int);
392 if (changed & BSS_CHANGED_BSSID) {
393 /* BSSID changed, for whatever reason (IBSS and managed mode) */
394 WL_NONE("%s: new BSSID: aid %d bss:%pM\n", __func__,
395 info->aid, info->bssid);
397 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
401 if (changed & BSS_CHANGED_BEACON) {
402 /* Beacon data changed, retrieve new beacon (beaconing modes) */
403 WL_ERROR("%s: beacon changed\n", __func__);
405 if (changed & BSS_CHANGED_BEACON_ENABLED) {
406 /* Beaconing should be enabled/disabled (beaconing modes) */
407 WL_ERROR("%s: Beacon enabled: %s\n", __func__,
408 info->enable_beacon ? "true" : "false");
410 if (changed & BSS_CHANGED_CQM) {
411 /* Connection quality monitor config changed */
412 WL_ERROR("%s: cqm change: threshold %d, hys %d (implement)\n",
413 __func__, info->cqm_rssi_thold, info->cqm_rssi_hyst);
415 if (changed & BSS_CHANGED_IBSS) {
416 /* IBSS join status changed */
417 WL_ERROR("%s: IBSS joined: %s (implement)\n", __func__,
418 info->ibss_joined ? "true" : "false");
420 if (changed & BSS_CHANGED_ARP_FILTER) {
421 /* Hardware ARP filter address list or state changed */
422 WL_ERROR("%s: arp filtering: enabled %s, count %d (implement)\n",
423 __func__, info->arp_filter_enabled ? "true" : "false",
426 if (changed & BSS_CHANGED_QOS) {
428 * QoS for this association was enabled/disabled.
429 * Note that it is only ever disabled for station mode.
431 WL_ERROR("%s: qos enabled: %s (implement)\n", __func__,
432 info->qos ? "true" : "false");
434 if (changed & BSS_CHANGED_IDLE) {
435 /* Idle changed for this BSS/interface */
436 WL_ERROR("%s: BSS idle: %s (implement)\n", __func__,
437 info->idle ? "true" : "false");
443 wl_ops_configure_filter(struct ieee80211_hw *hw,
444 unsigned int changed_flags,
445 unsigned int *total_flags, u64 multicast)
447 struct wl_info *wl = hw->priv;
449 changed_flags &= MAC_FILTERS;
450 *total_flags &= MAC_FILTERS;
451 if (changed_flags & FIF_PROMISC_IN_BSS)
452 WL_ERROR("FIF_PROMISC_IN_BSS\n");
453 if (changed_flags & FIF_ALLMULTI)
454 WL_ERROR("FIF_ALLMULTI\n");
455 if (changed_flags & FIF_FCSFAIL)
456 WL_ERROR("FIF_FCSFAIL\n");
457 if (changed_flags & FIF_PLCPFAIL)
458 WL_ERROR("FIF_PLCPFAIL\n");
459 if (changed_flags & FIF_CONTROL)
460 WL_ERROR("FIF_CONTROL\n");
461 if (changed_flags & FIF_OTHER_BSS)
462 WL_ERROR("FIF_OTHER_BSS\n");
463 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
464 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
466 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
467 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
468 wlc_mac_bcn_promisc_change(wl->wlc, 1);
470 wlc_mac_bcn_promisc_change(wl->wlc, 0);
471 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
479 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
481 WL_NONE("%s: Enter\n", __func__);
485 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
487 struct wl_info *wl = hw->priv;
488 WL_NONE("Scan Start\n");
490 wlc_scan_start(wl->wlc);
495 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
497 struct wl_info *wl = hw->priv;
498 WL_NONE("Scan Complete\n");
500 wlc_scan_stop(wl->wlc);
505 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
507 WL_ERROR("%s: Enter\n", __func__);
512 wl_ops_get_stats(struct ieee80211_hw *hw,
513 struct ieee80211_low_level_stats *stats)
515 struct wl_info *wl = hw->priv;
520 stats->dot11ACKFailureCount = cnt->txnoack;
521 stats->dot11RTSFailureCount = cnt->txnocts;
522 stats->dot11FCSErrorCount = cnt->rxcrc;
523 stats->dot11RTSSuccessCount = cnt->txrts;
528 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
530 struct wl_info *wl = hw->priv;
533 wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
539 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
540 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
542 WL_NONE("%s: Enter\n", __func__);
545 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
552 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
553 const struct ieee80211_tx_queue_params *params)
555 struct wl_info *wl = hw->priv;
557 WL_NONE("%s: Enter (WME config)\n", __func__);
558 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
559 params->txop, params->cw_min, params->cw_max, params->aifs);
562 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
568 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
570 WL_ERROR("%s: Enter\n", __func__);
575 wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
576 struct ieee80211_sta *sta)
581 struct wl_info *wl = hw->priv;
584 scb = (struct scb *)sta->drv_priv;
585 memset(scb, 0, sizeof(struct scb));
586 for (i = 0; i < NUMPRIO; i++)
587 scb->seqctl[i] = 0xFFFF;
588 scb->seqctl_nonqos = 0xFFFF;
589 scb->magic = SCB_MAGIC;
591 wl->pub->global_scb = scb;
592 wl->pub->global_ampdu = &(scb->scb_ampdu);
593 wl->pub->global_ampdu->scb = scb;
594 wl->pub->global_ampdu->max_pdu = 16;
595 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
596 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
598 sta->ht_cap.ht_supported = true;
599 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
600 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
601 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
602 IEEE80211_HT_CAP_SGI_20 |
603 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
605 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
610 wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
611 struct ieee80211_sta *sta)
613 WL_NONE("%s: Enter\n", __func__);
618 wl_ops_ampdu_action(struct ieee80211_hw *hw,
619 struct ieee80211_vif *vif,
620 enum ieee80211_ampdu_mlme_action action,
621 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
624 struct scb *scb = (struct scb *)sta->drv_priv;
626 struct wl_info *wl = hw->priv;
629 ASSERT(scb->magic == SCB_MAGIC);
631 case IEEE80211_AMPDU_RX_START:
632 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
634 case IEEE80211_AMPDU_RX_STOP:
635 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
637 case IEEE80211_AMPDU_TX_START:
639 status = wlc_aggregatable(wl->wlc, tid);
642 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
645 /* XXX: Use the starting sequence number provided ... */
647 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
650 case IEEE80211_AMPDU_TX_STOP:
651 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
653 case IEEE80211_AMPDU_TX_OPERATIONAL:
654 /* Not sure what to do here */
655 /* Power save wakeup */
656 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
660 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
666 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
668 struct wl_info *wl = HW_TO_WL(hw);
672 blocked = wlc_check_radio_disabled(wl->wlc);
675 WL_NONE("wl: rfkill_poll: %d\n", blocked);
676 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
679 static const struct ieee80211_ops wl_ops = {
681 .start = wl_ops_start,
683 .add_interface = wl_ops_add_interface,
684 .remove_interface = wl_ops_remove_interface,
685 .config = wl_ops_config,
686 .bss_info_changed = wl_ops_bss_info_changed,
687 .configure_filter = wl_ops_configure_filter,
688 .set_tim = wl_ops_set_tim,
689 .sw_scan_start = wl_ops_sw_scan_start,
690 .sw_scan_complete = wl_ops_sw_scan_complete,
691 .set_tsf = wl_ops_set_tsf,
692 .get_stats = wl_ops_get_stats,
693 .set_rts_threshold = wl_ops_set_rts_threshold,
694 .sta_notify = wl_ops_sta_notify,
695 .conf_tx = wl_ops_conf_tx,
696 .get_tsf = wl_ops_get_tsf,
697 .sta_add = wl_ops_sta_add,
698 .sta_remove = wl_ops_sta_remove,
699 .ampdu_action = wl_ops_ampdu_action,
700 .rfkill_poll = wl_ops_rfkill_poll,
704 * is called in wl_pci_probe() context, therefore no locking required.
706 static int wl_set_hint(struct wl_info *wl, char *abbrev)
708 WL_NONE("%s: Sending country code %c%c to MAC80211\n",
709 __func__, abbrev[0], abbrev[1]);
710 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
714 * attach to the WL device.
716 * Attach to the WL device identified by vendor and device parameters.
717 * regs is a host accessible memory address pointing to WL device registers.
719 * wl_attach is not defined as static because in the case where no bus
720 * is defined, wl_attach will never be called, and thus, gcc will issue
721 * a warning that this function is defined but not used if we declare
725 * is called in wl_pci_probe() context, therefore no locking required.
727 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
728 uint bustype, void *btparam, uint irq)
731 struct osl_info *osh;
734 unsigned long base_addr;
735 struct ieee80211_hw *hw;
742 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
746 osh = osl_attach(btparam, bustype);
749 /* allocate private info */
750 hw = pci_get_drvdata(btparam); /* btparam == pdev */
755 atomic_set(&wl->callbacks, 0);
757 /* setup the bottom half handler */
758 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
764 if (bustype == PCI_BUS) {
766 } else if (bustype == RPC_BUS) {
770 WL_TRACE("force to PCI\n");
772 wl->bcm_bustype = bustype;
774 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
775 if (wl->regsva == NULL) {
776 WL_ERROR("wl%d: ioremap() failed\n", unit);
779 spin_lock_init(&wl->lock);
780 spin_lock_init(&wl->isr_lock);
783 if (wl_request_fw(wl, (struct pci_dev *)btparam) < 0) {
784 WL_ERROR("%s: Failed to find firmware usually in %s\n",
785 KBUILD_MODNAME, "/lib/firmware/brcm");
787 wl_remove((struct pci_dev *)btparam);
791 /* common load-time initialization */
792 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
793 wl->regsva, wl->bcm_bustype, btparam, &err);
796 WL_ERROR("%s: wlc_attach() failed with code %d\n",
797 KBUILD_MODNAME, err);
800 wl->pub = wlc_pub(wl->wlc);
802 wl->pub->ieee_hw = hw;
803 ASSERT(wl->pub->ieee_hw);
804 ASSERT(wl->pub->ieee_hw->priv == wl);
807 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
808 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
811 /* register our interrupt handler */
812 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
813 WL_ERROR("wl%d: request_irq() failed\n", unit);
818 /* register module */
819 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
822 if (ieee_hw_init(hw)) {
823 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
827 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
828 ASSERT(is_valid_ether_addr(perm));
829 SET_IEEE80211_PERM_ADDR(hw, perm);
831 err = ieee80211_register_hw(hw);
833 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
837 if (wl->pub->srom_ccode[0])
838 err = wl_set_hint(wl, wl->pub->srom_ccode);
840 err = wl_set_hint(wl, "US");
842 WL_ERROR("%s: regulatory_hint failed, status %d\n",
857 #define CHAN2GHZ(channel, freqency, chflags) { \
858 .band = IEEE80211_BAND_2GHZ, \
859 .center_freq = (freqency), \
860 .hw_value = (channel), \
862 .max_antenna_gain = 0, \
866 static struct ieee80211_channel wl_2ghz_chantable[] = {
867 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
868 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
869 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
870 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
871 CHAN2GHZ(5, 2432, 0),
872 CHAN2GHZ(6, 2437, 0),
873 CHAN2GHZ(7, 2442, 0),
874 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
875 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
876 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
877 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
879 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
880 IEEE80211_CHAN_NO_HT40PLUS),
882 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
883 IEEE80211_CHAN_NO_HT40PLUS),
885 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
886 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
889 #define CHAN5GHZ(channel, chflags) { \
890 .band = IEEE80211_BAND_5GHZ, \
891 .center_freq = 5000 + 5*(channel), \
892 .hw_value = (channel), \
894 .max_antenna_gain = 0, \
898 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
900 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
901 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
902 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
903 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
906 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
907 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
909 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
910 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
912 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
913 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
915 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
916 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
919 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
920 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
922 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
923 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
925 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
926 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
928 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
929 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
931 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
932 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
934 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
935 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
937 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
938 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
940 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
941 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
943 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
944 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
946 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
947 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
949 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
950 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
951 IEEE80211_CHAN_NO_HT40MINUS),
953 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
954 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
955 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
956 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
957 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
960 #define RATE(rate100m, _flags) { \
961 .bitrate = (rate100m), \
963 .hw_value = (rate100m / 5), \
966 static struct ieee80211_rate wl_legacy_ratetable[] = {
968 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
969 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
970 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
981 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
982 .band = IEEE80211_BAND_2GHZ,
983 .channels = wl_2ghz_chantable,
984 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
985 .bitrates = wl_legacy_ratetable,
986 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
988 /* from include/linux/ieee80211.h */
989 .cap = IEEE80211_HT_CAP_GRN_FLD |
990 IEEE80211_HT_CAP_SGI_20 |
991 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
992 .ht_supported = true,
993 .ampdu_factor = AMPDU_RX_FACTOR_64K,
994 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
996 /* placeholders for now */
997 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
999 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1003 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
1004 .band = IEEE80211_BAND_5GHZ,
1005 .channels = wl_5ghz_nphy_chantable,
1006 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
1007 .bitrates = wl_legacy_ratetable + 4,
1008 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1010 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1011 .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 */
1012 .ht_supported = true,
1013 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1014 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1016 /* placeholders for now */
1017 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1019 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1024 * is called in wl_pci_probe() context, therefore no locking required.
1026 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1028 struct wl_info *wl = HW_TO_WL(hw);
1034 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1035 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1037 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1038 WL_ERROR("Phy list failed\n");
1040 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
1042 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1043 if (phy_list[0] == 'c') {
1045 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1046 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1048 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1054 /* Assume all bands use the same phy. True for 11n devices. */
1055 if (NBANDS_PUB(wl->pub) > 1) {
1057 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1058 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1065 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
1071 * is called in wl_pci_probe() context, therefore no locking required.
1073 static int ieee_hw_init(struct ieee80211_hw *hw)
1075 hw->flags = IEEE80211_HW_SIGNAL_DBM
1076 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1077 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1078 | IEEE80211_HW_AMPDU_AGGREGATION;
1080 hw->extra_tx_headroom = wlc_get_header_len();
1081 /* FIXME: should get this from wlc->machwcap */
1083 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1084 * mac80211/status.c:ieee80211_tx_status() checks this value,
1085 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1086 * appears to always set 3 rates
1088 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1090 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1091 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1093 hw->rate_control_algorithm = "minstrel_ht";
1095 hw->sta_data_size = sizeof(struct scb);
1096 return ieee_hw_rate_init(hw);
1100 * determines if a device is a WL device, and if so, attaches it.
1102 * This function determines if a device pointed to by pdev is a WL device,
1103 * and if so, performs a wl_attach() on it.
1105 * Perimeter lock is initialized in the course of this function.
1107 static int __devinit
1108 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1112 struct ieee80211_hw *hw;
1117 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1118 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1119 PCI_FUNC(pdev->devfn), pdev->irq);
1121 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1122 (((pdev->device & 0xff00) != 0x4300) &&
1123 ((pdev->device & 0xff00) != 0x4700) &&
1124 ((pdev->device < 43000) || (pdev->device > 43999))))
1127 rc = pci_enable_device(pdev);
1129 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1130 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1131 PCI_FUNC(pdev->devfn));
1134 pci_set_master(pdev);
1136 pci_read_config_dword(pdev, 0x40, &val);
1137 if ((val & 0x0000ff00) != 0)
1138 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1140 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1142 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1147 SET_IEEE80211_DEV(hw, &pdev->dev);
1149 pci_set_drvdata(pdev, hw);
1151 memset(hw->priv, 0, sizeof(*wl));
1153 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1154 PCI_BUS, pdev, pdev->irq);
1157 WL_ERROR("%s: %s: wl_attach failed!\n",
1158 KBUILD_MODNAME, __func__);
1163 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1167 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1170 struct ieee80211_hw *hw;
1172 WL_TRACE("wl: wl_suspend\n");
1174 hw = pci_get_drvdata(pdev);
1177 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1181 /* only need to flag hw is down for proper resume */
1183 wl->pub->hw_up = false;
1186 pci_save_state(pdev);
1187 pci_disable_device(pdev);
1188 return pci_set_power_state(pdev, PCI_D3hot);
1191 static int wl_resume(struct pci_dev *pdev)
1194 struct ieee80211_hw *hw;
1198 WL_TRACE("wl: wl_resume\n");
1199 hw = pci_get_drvdata(pdev);
1202 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1206 err = pci_set_power_state(pdev, PCI_D0);
1210 pci_restore_state(pdev);
1212 err = pci_enable_device(pdev);
1216 pci_set_master(pdev);
1218 pci_read_config_dword(pdev, 0x40, &val);
1219 if ((val & 0x0000ff00) != 0)
1220 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1223 * done. driver will be put in up state
1224 * in wl_ops_add_interface() call.
1230 * called from both kernel as from wl_*()
1231 * precondition: perimeter lock is not acquired.
1233 static void wl_remove(struct pci_dev *pdev)
1236 struct ieee80211_hw *hw;
1239 hw = pci_get_drvdata(pdev);
1242 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1247 status = wlc_chipmatch(pdev->vendor, pdev->device);
1250 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1254 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1255 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1256 ieee80211_unregister_hw(hw);
1260 WL_NONE("%s: Down\n", __func__);
1262 pci_disable_device(pdev);
1266 pci_set_drvdata(pdev, NULL);
1267 ieee80211_free_hw(hw);
1270 static struct pci_driver wl_pci_driver = {
1271 .name = KBUILD_MODNAME,
1272 .probe = wl_pci_probe,
1273 .suspend = wl_suspend,
1274 .resume = wl_resume,
1275 .remove = __devexit_p(wl_remove),
1276 .id_table = wl_id_table,
1280 * This is the main entry point for the WL driver.
1282 * This function determines if a device pointed to by pdev is a WL device,
1283 * and if so, performs a wl_attach() on it.
1286 static int __init wl_module_init(void)
1288 int error = -ENODEV;
1291 if (msglevel != 0xdeadbeef)
1292 wl_msg_level = msglevel;
1294 char *var = getvar(NULL, "wl_msglevel");
1296 wl_msg_level = simple_strtoul(var, NULL, 0);
1299 extern u32 phyhal_msg_level;
1301 if (phymsglevel != 0xdeadbeef)
1302 phyhal_msg_level = phymsglevel;
1304 char *var = getvar(NULL, "phy_msglevel");
1306 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1311 error = pci_register_driver(&wl_pci_driver);
1321 * This function unloads the WL driver from the system.
1323 * This function unconditionally unloads the WL driver module from the
1327 static void __exit wl_module_exit(void)
1329 pci_unregister_driver(&wl_pci_driver);
1333 module_init(wl_module_init);
1334 module_exit(wl_module_exit);
1337 * This function frees the WL per-device resources.
1339 * This function frees resources owned by the WL device pointed to
1340 * by the wl parameter.
1342 * precondition: can both be called locked and unlocked
1345 static void wl_free(struct wl_info *wl)
1347 struct wl_timer *t, *next;
1348 struct osl_info *osh;
1351 /* free ucode data */
1353 wl_ucode_data_free();
1355 free_irq(wl->irq, wl);
1358 tasklet_kill(&wl->tasklet);
1361 wlc_module_unregister(wl->pub, "linux", wl);
1364 /* free common resources */
1366 wlc_detach(wl->wlc);
1371 /* virtual interface deletion is deferred so we cannot spinwait */
1373 /* wait for all pending callbacks to complete */
1374 while (atomic_read(&wl->callbacks) > 0)
1378 for (t = wl->timers; t; t = next) {
1390 * unregister_netdev() calls get_stats() which may read chip registers
1391 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1393 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1394 wl->bcm_bustype != JTAG_BUS) {
1395 iounmap((void *)wl->regsva);
1405 * precondition: perimeter lock has been acquired
1407 static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1412 return wl_start_int(wl, WL_TO_HW(wl), skb);
1415 static int BCMFASTPATH
1416 wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1418 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1419 return NETDEV_TX_OK;
1423 * precondition: perimeter lock has been acquired
1425 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1428 WL_ERROR("Shouldn't be here %s\n", __func__);
1432 * precondition: perimeter lock has been acquired
1434 void wl_init(struct wl_info *wl)
1436 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1444 * precondition: perimeter lock has been acquired
1446 uint wl_reset(struct wl_info *wl)
1448 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1452 /* dpc will not be rescheduled */
1459 * These are interrupt on/off entry points. Disable interrupts
1460 * during interrupt state transition.
1462 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1464 unsigned long flags;
1466 INT_LOCK(wl, flags);
1467 wlc_intrson(wl->wlc);
1468 INT_UNLOCK(wl, flags);
1472 * precondition: perimeter lock has been acquired
1474 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1479 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1481 unsigned long flags;
1484 INT_LOCK(wl, flags);
1485 status = wlc_intrsoff(wl->wlc);
1486 INT_UNLOCK(wl, flags);
1490 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1492 unsigned long flags;
1494 INT_LOCK(wl, flags);
1495 wlc_intrsrestore(wl->wlc, macintmask);
1496 INT_UNLOCK(wl, flags);
1500 * precondition: perimeter lock has been acquired
1502 int wl_up(struct wl_info *wl)
1509 error = wlc_up(wl->wlc);
1515 * precondition: perimeter lock has been acquired
1517 void wl_down(struct wl_info *wl)
1519 uint callbacks, ret_val = 0;
1521 /* call common down function */
1522 ret_val = wlc_down(wl->wlc);
1523 callbacks = atomic_read(&wl->callbacks) - ret_val;
1525 /* wait for down callbacks to complete */
1528 /* For HIGH_only driver, it's important to actually schedule other work,
1529 * not just spin wait since everything runs at schedule level
1531 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1536 static irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1540 unsigned long flags;
1542 wl = (struct wl_info *) dev_id;
1544 WL_ISRLOCK(wl, flags);
1546 /* call common first level interrupt handler */
1547 ours = wlc_isr(wl->wlc, &wantdpc);
1549 /* if more to do... */
1552 /* ...and call the second level interrupt handler */
1554 ASSERT(wl->resched == false);
1555 tasklet_schedule(&wl->tasklet);
1559 WL_ISRUNLOCK(wl, flags);
1561 return IRQ_RETVAL(ours);
1564 static void BCMFASTPATH wl_dpc(unsigned long data)
1568 wl = (struct wl_info *) data;
1572 /* call the common second level interrupt handler */
1575 unsigned long flags;
1577 INT_LOCK(wl, flags);
1578 wlc_intrsupd(wl->wlc);
1579 INT_UNLOCK(wl, flags);
1582 wl->resched = wlc_dpc(wl->wlc, true);
1585 /* wlc_dpc() may bring the driver down */
1589 /* re-schedule dpc */
1591 tasklet_schedule(&wl->tasklet);
1593 /* re-enable interrupts */
1602 * is called by the kernel from software irq context
1604 static void wl_timer(unsigned long data)
1606 _wl_timer((struct wl_timer *) data);
1610 * precondition: perimeter lock is not acquired
1612 static void _wl_timer(struct wl_timer *t)
1618 t->timer.expires = jiffies + t->ms * HZ / 1000;
1619 atomic_inc(&t->wl->callbacks);
1620 add_timer(&t->timer);
1628 atomic_dec(&t->wl->callbacks);
1634 * Adds a timer to the list. Caller supplies a timer function.
1635 * Is called from wlc.
1637 * precondition: perimeter lock has been acquired
1639 struct wl_timer *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg),
1640 void *arg, const char *name)
1644 t = kmalloc(sizeof(struct wl_timer), GFP_ATOMIC);
1646 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1650 memset(t, 0, sizeof(struct wl_timer));
1652 init_timer(&t->timer);
1653 t->timer.data = (unsigned long) t;
1654 t->timer.function = wl_timer;
1658 t->next = wl->timers;
1662 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1664 strcpy(t->name, name);
1670 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1671 * as well as it's easier to make it periodic
1673 * precondition: perimeter lock has been acquired
1675 void wl_add_timer(struct wl_info *wl, struct wl_timer *t, uint ms, int periodic)
1679 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1680 __func__, t->name, periodic);
1686 t->periodic = (bool) periodic;
1688 t->timer.expires = jiffies + ms * HZ / 1000;
1690 atomic_inc(&wl->callbacks);
1691 add_timer(&t->timer);
1695 * return true if timer successfully deleted, false if still pending
1697 * precondition: perimeter lock has been acquired
1699 bool wl_del_timer(struct wl_info *wl, struct wl_timer *t)
1703 if (!del_timer(&t->timer)) {
1706 atomic_dec(&wl->callbacks);
1713 * precondition: perimeter lock has been acquired
1715 void wl_free_timer(struct wl_info *wl, struct wl_timer *t)
1717 struct wl_timer *tmp;
1719 /* delete the timer in case it is active */
1720 wl_del_timer(wl, t);
1722 if (wl->timers == t) {
1723 wl->timers = wl->timers->next;
1735 if (tmp->next == t) {
1736 tmp->next = t->next;
1750 * runs in software irq context
1752 * precondition: perimeter lock is not acquired
1754 static int wl_linux_watchdog(void *ctx)
1756 struct wl_info *wl = (struct wl_info *) ctx;
1758 struct net_device_stats *stats = NULL;
1762 ASSERT(wl->stats_id < 2);
1764 cnt = wl->pub->_cnt;
1765 id = 1 - wl->stats_id;
1766 stats = &wl->stats_watchdog[id];
1767 stats->rx_packets = cnt->rxframe;
1768 stats->tx_packets = cnt->txframe;
1769 stats->rx_bytes = cnt->rxbyte;
1770 stats->tx_bytes = cnt->txbyte;
1771 stats->rx_errors = cnt->rxerror;
1772 stats->tx_errors = cnt->txerror;
1773 stats->collisions = 0;
1775 stats->rx_length_errors = 0;
1776 stats->rx_over_errors = cnt->rxoflo;
1777 stats->rx_crc_errors = cnt->rxcrc;
1778 stats->rx_frame_errors = 0;
1779 stats->rx_fifo_errors = cnt->rxoflo;
1780 stats->rx_missed_errors = 0;
1782 stats->tx_fifo_errors = cnt->txuflo;
1796 char *wl_firmwares[WL_MAX_FW] = {
1802 * precondition: perimeter lock has been acquired
1804 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1808 struct wl_fw_hdr *hdr;
1809 for (i = 0; i < wl->fw.fw_cnt; i++) {
1810 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1811 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1813 if (hdr->idx == idx) {
1814 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1815 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1816 if (*pbuf == NULL) {
1817 WL_ERROR("fail to alloc %d bytes\n",
1821 memcpy(*pbuf, pdata, hdr->len);
1826 WL_ERROR("ERROR: ucode buf tag:%d can not be found!\n", idx);
1829 return BCME_NOTFOUND;
1833 * Precondition: Since this function is called in wl_pci_probe() context,
1834 * no locking is required.
1836 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1840 struct wl_fw_hdr *hdr;
1841 for (i = 0; i < wl->fw.fw_cnt; i++) {
1842 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1843 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1845 if (hdr->idx == idx) {
1846 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1847 ASSERT(hdr->len == 4);
1848 *data = *((u32 *) pdata);
1853 WL_ERROR("ERROR: ucode tag:%d can not be found!\n", idx);
1858 * Precondition: Since this function is called in wl_pci_probe() context,
1859 * no locking is required.
1861 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1864 struct device *device = &pdev->dev;
1868 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1869 for (i = 0; i < WL_MAX_FW; i++) {
1870 if (wl_firmwares[i] == NULL)
1872 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1873 UCODE_LOADER_API_VER);
1874 WL_NONE("request fw %s\n", fw_name);
1875 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1877 WL_ERROR("%s: fail to load firmware %s\n",
1878 KBUILD_MODNAME, fw_name);
1881 WL_NONE("request fw %s\n", fw_name);
1882 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1883 UCODE_LOADER_API_VER);
1884 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1886 WL_ERROR("%s: fail to load firmware %s\n",
1887 KBUILD_MODNAME, fw_name);
1890 wl->fw.hdr_num_entries[i] =
1891 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1892 WL_NONE("request fw %s find: %d entries\n",
1893 fw_name, wl->fw.hdr_num_entries[i]);
1896 return wl_ucode_data_init(wl);
1900 * precondition: can both be called locked and unlocked
1902 void wl_ucode_free_buf(void *p)
1908 * Precondition: Since this function is called in wl_pci_probe() context,
1909 * no locking is required.
1911 static void wl_release_fw(struct wl_info *wl)
1914 for (i = 0; i < WL_MAX_FW; i++) {
1915 release_firmware(wl->fw.fw_bin[i]);
1916 release_firmware(wl->fw.fw_hdr[i]);
1922 * checks validity of all firmware images loaded from user space
1924 * Precondition: Since this function is called in wl_pci_probe() context,
1925 * no locking is required.
1927 int wl_check_firmwares(struct wl_info *wl)
1932 const struct firmware *fw;
1933 const struct firmware *fw_hdr;
1934 struct wl_fw_hdr *ucode_hdr;
1935 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1936 fw = wl->fw.fw_bin[i];
1937 fw_hdr = wl->fw.fw_hdr[i];
1938 if (fw == NULL && fw_hdr == NULL) {
1940 } else if (fw == NULL || fw_hdr == NULL) {
1941 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1943 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1944 WL_ERROR("%s: non integral fw hdr file size %zu/%zu\n",
1945 __func__, fw_hdr->size,
1946 sizeof(struct wl_fw_hdr));
1948 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1949 WL_ERROR("%s: out of bounds fw file size %zu\n",
1950 __func__, fw->size);
1953 /* check if ucode section overruns firmware image */
1954 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1955 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1956 !rc; entry++, ucode_hdr++) {
1957 if (ucode_hdr->offset + ucode_hdr->len >
1959 WL_ERROR("%s: conflicting bin/hdr\n",
1966 if (rc == 0 && wl->fw.fw_cnt != i) {
1967 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1974 * precondition: perimeter lock has been acquired
1976 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1978 bool blocked = wlc_check_radio_disabled(wl->wlc);
1980 WL_NONE("%s: update hw state: blocked=%s\n", __func__,
1981 blocked ? "true" : "false");
1983 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1985 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);