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>
37 #include "phy/wlc_phy_int.h"
39 #include "wlc_types.h"
41 #include "phy/phy_version.h"
43 #include "wlc_channel.h"
47 #include "wl_export.h"
49 #include "wl_mac80211.h"
51 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
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 void wl_dpc(unsigned long data);
80 static irqreturn_t wl_isr(int irq, void *dev_id);
82 static int __devinit wl_pci_probe(struct pci_dev *pdev,
83 const struct pci_device_id *ent);
84 static void wl_remove(struct pci_dev *pdev);
85 static void wl_free(struct wl_info *wl);
87 MODULE_AUTHOR("Broadcom Corporation");
88 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
89 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
90 MODULE_LICENSE("Dual BSD/GPL");
92 /* recognized PCI IDs */
93 static struct pci_device_id wl_id_table[] = {
94 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
95 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
96 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
100 MODULE_DEVICE_TABLE(pci, wl_id_table);
103 static int msglevel = 0xdeadbeef;
104 module_param(msglevel, int, 0);
105 static int phymsglevel = 0xdeadbeef;
106 module_param(phymsglevel, int, 0);
109 #define HW_TO_WL(hw) (hw->priv)
110 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
112 /* MAC80211 callback functions */
113 static int wl_ops_start(struct ieee80211_hw *hw);
114 static void wl_ops_stop(struct ieee80211_hw *hw);
115 static int wl_ops_add_interface(struct ieee80211_hw *hw,
116 struct ieee80211_vif *vif);
117 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
118 struct ieee80211_vif *vif);
119 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
120 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
121 struct ieee80211_vif *vif,
122 struct ieee80211_bss_conf *info,
124 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
125 unsigned int changed_flags,
126 unsigned int *total_flags, u64 multicast);
127 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
129 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
130 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
131 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
132 static int wl_ops_get_stats(struct ieee80211_hw *hw,
133 struct ieee80211_low_level_stats *stats);
134 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
135 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
136 struct ieee80211_vif *vif,
137 enum sta_notify_cmd cmd,
138 struct ieee80211_sta *sta);
139 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
140 const struct ieee80211_tx_queue_params *params);
141 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
142 static int wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
143 struct ieee80211_sta *sta);
144 static int wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
145 struct ieee80211_sta *sta);
146 static int wl_ops_ampdu_action(struct ieee80211_hw *hw,
147 struct ieee80211_vif *vif,
148 enum ieee80211_ampdu_mlme_action action,
149 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
151 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw);
153 static void wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
155 struct wl_info *wl = hw->priv;
159 WL_ERROR("ops->tx called while down\n");
163 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
168 static int wl_ops_start(struct ieee80211_hw *hw)
170 struct wl_info *wl = hw->priv;
173 struct ieee80211_channel *curchan = hw->conf.channel;
174 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
177 ieee80211_wake_queues(hw);
179 blocked = wl_rfkill_set_hw_state(wl);
182 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
187 static void wl_ops_stop(struct ieee80211_hw *hw)
190 struct wl_info *wl = hw->priv;
193 ieee80211_stop_queues(hw);
197 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
202 /* Just STA for now */
203 if (vif->type != NL80211_IFTYPE_AP &&
204 vif->type != NL80211_IFTYPE_MESH_POINT &&
205 vif->type != NL80211_IFTYPE_STATION &&
206 vif->type != NL80211_IFTYPE_WDS &&
207 vif->type != NL80211_IFTYPE_ADHOC) {
208 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
209 __func__, vif->type);
219 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
225 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
231 /* put driver in down state */
238 * precondition: perimeter lock has been acquired
241 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
242 enum nl80211_channel_type type)
244 struct wl_info *wl = HW_TO_WL(hw);
248 case NL80211_CHAN_HT20:
249 case NL80211_CHAN_NO_HT:
250 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
252 case NL80211_CHAN_HT40MINUS:
253 case NL80211_CHAN_HT40PLUS:
254 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
264 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
266 struct ieee80211_conf *conf = &hw->conf;
267 struct wl_info *wl = HW_TO_WL(hw);
272 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
274 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
275 WL_ERROR("%s: Error setting listen_interval\n",
280 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
281 ASSERT(new_int == conf->listen_interval);
283 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
284 WL_ERROR("%s: change monitor mode: %s (implement)\n", __func__,
285 conf->flags & IEEE80211_CONF_MONITOR ?
287 if (changed & IEEE80211_CONF_CHANGE_PS)
288 WL_ERROR("%s: change power-save mode: %s (implement)\n",
289 __func__, conf->flags & IEEE80211_CONF_PS ?
292 if (changed & IEEE80211_CONF_CHANGE_POWER) {
294 (wl->wlc, "qtxpower", conf->power_level * 4)) {
295 WL_ERROR("%s: Error setting power_level\n", __func__);
299 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
300 if (new_int != (conf->power_level * 4))
301 WL_ERROR("%s: Power level req != actual, %d %d\n",
302 __func__, conf->power_level * 4, new_int);
304 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
305 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
307 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
309 (wl->wlc, WLC_SET_SRL,
310 conf->short_frame_max_tx_count) < 0) {
311 WL_ERROR("%s: Error setting srl\n", __func__);
315 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
317 WL_ERROR("%s: Error setting lrl\n", __func__);
329 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
330 struct ieee80211_vif *vif,
331 struct ieee80211_bss_conf *info, u32 changed)
333 struct wl_info *wl = HW_TO_WL(hw);
336 if (changed & BSS_CHANGED_ASSOC) {
337 /* association status changed (associated/disassociated)
338 * also implies a change in the AID.
340 WL_ERROR("%s: %s: %sassociated\n", KBUILD_MODNAME, __func__,
341 info->assoc ? "" : "dis");
342 wlc_associate_upd(wl->wlc, info->assoc);
344 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
345 /* CTS protection changed */
346 WL_ERROR("%s: use_cts_prot: %s (implement)\n", __func__,
347 info->use_cts_prot ? "true" : "false");
349 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
350 /* preamble changed */
351 WL_ERROR("%s: short preamble: %s (implement)\n", __func__,
352 info->use_short_preamble ? "true" : "false");
354 if (changed & BSS_CHANGED_ERP_SLOT) {
355 /* slot timing changed */
356 if (info->use_short_slot)
361 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
365 if (changed & BSS_CHANGED_HT) {
366 /* 802.11n parameters changed */
367 u16 mode = info->ht_operation_mode;
368 WL_NONE("%s: HT mode: 0x%04X\n", __func__, mode);
369 wlc_protection_upd(wl->wlc, WLC_PROT_N_CFG,
370 mode & IEEE80211_HT_OP_MODE_PROTECTION);
371 wlc_protection_upd(wl->wlc, WLC_PROT_N_NONGF,
372 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
373 wlc_protection_upd(wl->wlc, WLC_PROT_N_OBSS,
374 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
376 if (changed & BSS_CHANGED_BASIC_RATES) {
377 /* Basic rateset changed */
378 WL_ERROR("%s: Need to change Basic Rates: 0x%x (implement)\n",
379 __func__, (u32) info->basic_rates);
381 if (changed & BSS_CHANGED_BEACON_INT) {
382 /* Beacon interval changed */
383 WL_NONE("%s: Beacon Interval: %d\n",
384 __func__, info->beacon_int);
385 wlc_set(wl->wlc, WLC_SET_BCNPRD, info->beacon_int);
387 if (changed & BSS_CHANGED_BSSID) {
388 /* BSSID changed, for whatever reason (IBSS and managed mode) */
389 WL_NONE("%s: new BSSID: aid %d bss:%pM\n", __func__,
390 info->aid, info->bssid);
392 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
396 if (changed & BSS_CHANGED_BEACON) {
397 /* Beacon data changed, retrieve new beacon (beaconing modes) */
398 WL_ERROR("%s: beacon changed\n", __func__);
400 if (changed & BSS_CHANGED_BEACON_ENABLED) {
401 /* Beaconing should be enabled/disabled (beaconing modes) */
402 WL_ERROR("%s: Beacon enabled: %s\n", __func__,
403 info->enable_beacon ? "true" : "false");
405 if (changed & BSS_CHANGED_CQM) {
406 /* Connection quality monitor config changed */
407 WL_ERROR("%s: cqm change: threshold %d, hys %d (implement)\n",
408 __func__, info->cqm_rssi_thold, info->cqm_rssi_hyst);
410 if (changed & BSS_CHANGED_IBSS) {
411 /* IBSS join status changed */
412 WL_ERROR("%s: IBSS joined: %s (implement)\n", __func__,
413 info->ibss_joined ? "true" : "false");
415 if (changed & BSS_CHANGED_ARP_FILTER) {
416 /* Hardware ARP filter address list or state changed */
417 WL_ERROR("%s: arp filtering: enabled %s, count %d (implement)\n",
418 __func__, info->arp_filter_enabled ? "true" : "false",
421 if (changed & BSS_CHANGED_QOS) {
423 * QoS for this association was enabled/disabled.
424 * Note that it is only ever disabled for station mode.
426 WL_ERROR("%s: qos enabled: %s (implement)\n", __func__,
427 info->qos ? "true" : "false");
429 if (changed & BSS_CHANGED_IDLE) {
430 /* Idle changed for this BSS/interface */
431 WL_ERROR("%s: BSS idle: %s (implement)\n", __func__,
432 info->idle ? "true" : "false");
438 wl_ops_configure_filter(struct ieee80211_hw *hw,
439 unsigned int changed_flags,
440 unsigned int *total_flags, u64 multicast)
442 struct wl_info *wl = hw->priv;
444 changed_flags &= MAC_FILTERS;
445 *total_flags &= MAC_FILTERS;
446 if (changed_flags & FIF_PROMISC_IN_BSS)
447 WL_ERROR("FIF_PROMISC_IN_BSS\n");
448 if (changed_flags & FIF_ALLMULTI)
449 WL_ERROR("FIF_ALLMULTI\n");
450 if (changed_flags & FIF_FCSFAIL)
451 WL_ERROR("FIF_FCSFAIL\n");
452 if (changed_flags & FIF_PLCPFAIL)
453 WL_ERROR("FIF_PLCPFAIL\n");
454 if (changed_flags & FIF_CONTROL)
455 WL_ERROR("FIF_CONTROL\n");
456 if (changed_flags & FIF_OTHER_BSS)
457 WL_ERROR("FIF_OTHER_BSS\n");
458 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
459 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
461 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
462 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
463 wlc_mac_bcn_promisc_change(wl->wlc, 1);
465 wlc_mac_bcn_promisc_change(wl->wlc, 0);
466 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
474 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
476 WL_NONE("%s: Enter\n", __func__);
480 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
482 struct wl_info *wl = hw->priv;
483 WL_NONE("Scan Start\n");
485 wlc_scan_start(wl->wlc);
490 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
492 struct wl_info *wl = hw->priv;
493 WL_NONE("Scan Complete\n");
495 wlc_scan_stop(wl->wlc);
500 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
502 WL_ERROR("%s: Enter\n", __func__);
507 wl_ops_get_stats(struct ieee80211_hw *hw,
508 struct ieee80211_low_level_stats *stats)
510 struct wl_info *wl = hw->priv;
515 stats->dot11ACKFailureCount = cnt->txnoack;
516 stats->dot11RTSFailureCount = cnt->txnocts;
517 stats->dot11FCSErrorCount = cnt->rxcrc;
518 stats->dot11RTSSuccessCount = cnt->txrts;
523 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
525 struct wl_info *wl = hw->priv;
528 wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
534 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
535 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
537 WL_NONE("%s: Enter\n", __func__);
540 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
547 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
548 const struct ieee80211_tx_queue_params *params)
550 struct wl_info *wl = hw->priv;
552 WL_NONE("%s: Enter (WME config)\n", __func__);
553 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
554 params->txop, params->cw_min, params->cw_max, params->aifs);
557 wlc_wme_setparams(wl->wlc, queue, params, true);
563 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
565 WL_ERROR("%s: Enter\n", __func__);
570 wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
571 struct ieee80211_sta *sta)
576 struct wl_info *wl = hw->priv;
579 scb = (struct scb *)sta->drv_priv;
580 memset(scb, 0, sizeof(struct scb));
581 for (i = 0; i < NUMPRIO; i++)
582 scb->seqctl[i] = 0xFFFF;
583 scb->seqctl_nonqos = 0xFFFF;
584 scb->magic = SCB_MAGIC;
586 wl->pub->global_scb = scb;
587 wl->pub->global_ampdu = &(scb->scb_ampdu);
588 wl->pub->global_ampdu->scb = scb;
589 wl->pub->global_ampdu->max_pdu = 16;
590 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
591 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
593 sta->ht_cap.ht_supported = true;
594 sta->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
595 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
596 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
597 IEEE80211_HT_CAP_SGI_20 |
598 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
600 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
605 wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
606 struct ieee80211_sta *sta)
608 WL_NONE("%s: Enter\n", __func__);
613 wl_ops_ampdu_action(struct ieee80211_hw *hw,
614 struct ieee80211_vif *vif,
615 enum ieee80211_ampdu_mlme_action action,
616 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
620 struct scb *scb = (struct scb *)sta->drv_priv;
622 struct wl_info *wl = hw->priv;
625 ASSERT(scb->magic == SCB_MAGIC);
627 case IEEE80211_AMPDU_RX_START:
628 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
630 case IEEE80211_AMPDU_RX_STOP:
631 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
633 case IEEE80211_AMPDU_TX_START:
635 status = wlc_aggregatable(wl->wlc, tid);
638 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
641 /* XXX: Use the starting sequence number provided ... */
643 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
646 case IEEE80211_AMPDU_TX_STOP:
648 wlc_ampdu_flush(wl->wlc, sta, tid);
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)
732 unsigned long base_addr;
733 struct ieee80211_hw *hw;
740 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
744 /* allocate private info */
745 hw = pci_get_drvdata(btparam); /* btparam == pdev */
749 atomic_set(&wl->callbacks, 0);
751 /* setup the bottom half handler */
752 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
758 if (bustype == PCI_BUS) {
760 } else if (bustype == RPC_BUS) {
764 WL_TRACE("force to PCI\n");
766 wl->bcm_bustype = bustype;
768 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
769 if (wl->regsva == NULL) {
770 WL_ERROR("wl%d: ioremap() failed\n", unit);
773 spin_lock_init(&wl->lock);
774 spin_lock_init(&wl->isr_lock);
777 if (wl_request_fw(wl, (struct pci_dev *)btparam) < 0) {
778 WL_ERROR("%s: Failed to find firmware usually in %s\n",
779 KBUILD_MODNAME, "/lib/firmware/brcm");
781 wl_remove((struct pci_dev *)btparam);
785 /* common load-time initialization */
786 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode,
787 wl->regsva, wl->bcm_bustype, btparam, &err);
790 WL_ERROR("%s: wlc_attach() failed with code %d\n",
791 KBUILD_MODNAME, err);
794 wl->pub = wlc_pub(wl->wlc);
796 wl->pub->ieee_hw = hw;
797 ASSERT(wl->pub->ieee_hw);
798 ASSERT(wl->pub->ieee_hw->priv == wl);
801 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
802 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
805 /* register our interrupt handler */
806 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
807 WL_ERROR("wl%d: request_irq() failed\n", unit);
812 /* register module */
813 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
816 if (ieee_hw_init(hw)) {
817 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
821 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
822 ASSERT(is_valid_ether_addr(perm));
823 SET_IEEE80211_PERM_ADDR(hw, perm);
825 err = ieee80211_register_hw(hw);
827 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
831 if (wl->pub->srom_ccode[0])
832 err = wl_set_hint(wl, wl->pub->srom_ccode);
834 err = wl_set_hint(wl, "US");
836 WL_ERROR("%s: regulatory_hint failed, status %d\n",
851 #define CHAN2GHZ(channel, freqency, chflags) { \
852 .band = IEEE80211_BAND_2GHZ, \
853 .center_freq = (freqency), \
854 .hw_value = (channel), \
856 .max_antenna_gain = 0, \
860 static struct ieee80211_channel wl_2ghz_chantable[] = {
861 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
862 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
863 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
864 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
865 CHAN2GHZ(5, 2432, 0),
866 CHAN2GHZ(6, 2437, 0),
867 CHAN2GHZ(7, 2442, 0),
868 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
869 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
870 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
871 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
873 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
874 IEEE80211_CHAN_NO_HT40PLUS),
876 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
877 IEEE80211_CHAN_NO_HT40PLUS),
879 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
880 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
883 #define CHAN5GHZ(channel, chflags) { \
884 .band = IEEE80211_BAND_5GHZ, \
885 .center_freq = 5000 + 5*(channel), \
886 .hw_value = (channel), \
888 .max_antenna_gain = 0, \
892 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
894 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
895 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
896 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
897 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
900 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
901 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
903 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
904 IEEE80211_CHAN_PASSIVE_SCAN | 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),
913 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
914 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
916 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
917 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_HT40PLUS |
945 IEEE80211_CHAN_NO_HT40MINUS),
947 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
948 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
949 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
950 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
951 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
954 #define RATE(rate100m, _flags) { \
955 .bitrate = (rate100m), \
957 .hw_value = (rate100m / 5), \
960 static struct ieee80211_rate wl_legacy_ratetable[] = {
962 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
963 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
964 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
975 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
976 .band = IEEE80211_BAND_2GHZ,
977 .channels = wl_2ghz_chantable,
978 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
979 .bitrates = wl_legacy_ratetable,
980 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
982 /* from include/linux/ieee80211.h */
983 .cap = IEEE80211_HT_CAP_GRN_FLD |
984 IEEE80211_HT_CAP_SGI_20 |
985 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
986 .ht_supported = true,
987 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
988 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
990 /* placeholders for now */
991 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
993 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
997 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
998 .band = IEEE80211_BAND_5GHZ,
999 .channels = wl_5ghz_nphy_chantable,
1000 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
1001 .bitrates = wl_legacy_ratetable + 4,
1002 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1004 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1005 .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 */
1006 .ht_supported = true,
1007 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
1008 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1010 /* placeholders for now */
1011 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1013 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1018 * is called in wl_pci_probe() context, therefore no locking required.
1020 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1022 struct wl_info *wl = HW_TO_WL(hw);
1028 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1029 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1031 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1032 WL_ERROR("Phy list failed\n");
1034 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
1036 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1037 if (phy_list[0] == 'c') {
1039 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1040 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1042 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1048 /* Assume all bands use the same phy. True for 11n devices. */
1049 if (NBANDS_PUB(wl->pub) > 1) {
1051 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1052 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1059 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
1065 * is called in wl_pci_probe() context, therefore no locking required.
1067 static int ieee_hw_init(struct ieee80211_hw *hw)
1069 hw->flags = IEEE80211_HW_SIGNAL_DBM
1070 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1071 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1072 | IEEE80211_HW_AMPDU_AGGREGATION;
1074 hw->extra_tx_headroom = wlc_get_header_len();
1075 hw->queues = N_TX_QUEUES;
1076 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1077 * mac80211/status.c:ieee80211_tx_status() checks this value,
1078 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1079 * appears to always set 3 rates
1081 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1083 hw->channel_change_time = 7 * 1000; /* channel change time is dependent on chip and band */
1084 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1086 hw->rate_control_algorithm = "minstrel_ht";
1088 hw->sta_data_size = sizeof(struct scb);
1089 return ieee_hw_rate_init(hw);
1093 * determines if a device is a WL device, and if so, attaches it.
1095 * This function determines if a device pointed to by pdev is a WL device,
1096 * and if so, performs a wl_attach() on it.
1098 * Perimeter lock is initialized in the course of this function.
1100 static int __devinit
1101 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1105 struct ieee80211_hw *hw;
1110 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1111 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1112 PCI_FUNC(pdev->devfn), pdev->irq);
1114 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1115 (((pdev->device & 0xff00) != 0x4300) &&
1116 ((pdev->device & 0xff00) != 0x4700) &&
1117 ((pdev->device < 43000) || (pdev->device > 43999))))
1120 rc = pci_enable_device(pdev);
1122 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1123 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1124 PCI_FUNC(pdev->devfn));
1127 pci_set_master(pdev);
1129 pci_read_config_dword(pdev, 0x40, &val);
1130 if ((val & 0x0000ff00) != 0)
1131 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1133 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1135 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1140 SET_IEEE80211_DEV(hw, &pdev->dev);
1142 pci_set_drvdata(pdev, hw);
1144 memset(hw->priv, 0, sizeof(*wl));
1146 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1147 PCI_BUS, pdev, pdev->irq);
1150 WL_ERROR("%s: %s: wl_attach failed!\n",
1151 KBUILD_MODNAME, __func__);
1156 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1160 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1163 struct ieee80211_hw *hw;
1165 WL_TRACE("wl: wl_suspend\n");
1167 hw = pci_get_drvdata(pdev);
1170 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1174 /* only need to flag hw is down for proper resume */
1176 wl->pub->hw_up = false;
1179 pci_save_state(pdev);
1180 pci_disable_device(pdev);
1181 return pci_set_power_state(pdev, PCI_D3hot);
1184 static int wl_resume(struct pci_dev *pdev)
1187 struct ieee80211_hw *hw;
1191 WL_TRACE("wl: wl_resume\n");
1192 hw = pci_get_drvdata(pdev);
1195 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1199 err = pci_set_power_state(pdev, PCI_D0);
1203 pci_restore_state(pdev);
1205 err = pci_enable_device(pdev);
1209 pci_set_master(pdev);
1211 pci_read_config_dword(pdev, 0x40, &val);
1212 if ((val & 0x0000ff00) != 0)
1213 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1216 * done. driver will be put in up state
1217 * in wl_ops_add_interface() call.
1223 * called from both kernel as from wl_*()
1224 * precondition: perimeter lock is not acquired.
1226 static void wl_remove(struct pci_dev *pdev)
1229 struct ieee80211_hw *hw;
1232 hw = pci_get_drvdata(pdev);
1235 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1240 status = wlc_chipmatch(pdev->vendor, pdev->device);
1243 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1247 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1248 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1249 ieee80211_unregister_hw(hw);
1253 WL_NONE("%s: Down\n", __func__);
1255 pci_disable_device(pdev);
1259 pci_set_drvdata(pdev, NULL);
1260 ieee80211_free_hw(hw);
1263 static struct pci_driver wl_pci_driver = {
1264 .name = KBUILD_MODNAME,
1265 .probe = wl_pci_probe,
1266 .suspend = wl_suspend,
1267 .resume = wl_resume,
1268 .remove = __devexit_p(wl_remove),
1269 .id_table = wl_id_table,
1273 * This is the main entry point for the WL driver.
1275 * This function determines if a device pointed to by pdev is a WL device,
1276 * and if so, performs a wl_attach() on it.
1279 static int __init wl_module_init(void)
1281 int error = -ENODEV;
1284 if (msglevel != 0xdeadbeef)
1285 wl_msg_level = msglevel;
1287 char *var = getvar(NULL, "wl_msglevel");
1289 unsigned long value;
1291 (void)strict_strtoul(var, 0, &value);
1292 wl_msg_level = value;
1295 if (phymsglevel != 0xdeadbeef)
1296 phyhal_msg_level = phymsglevel;
1298 char *var = getvar(NULL, "phy_msglevel");
1300 unsigned long value;
1302 (void)strict_strtoul(var, 0, &value);
1303 phyhal_msg_level = value;
1308 error = pci_register_driver(&wl_pci_driver);
1318 * This function unloads the WL driver from the system.
1320 * This function unconditionally unloads the WL driver module from the
1324 static void __exit wl_module_exit(void)
1326 pci_unregister_driver(&wl_pci_driver);
1330 module_init(wl_module_init);
1331 module_exit(wl_module_exit);
1334 * This function frees the WL per-device resources.
1336 * This function frees resources owned by the WL device pointed to
1337 * by the wl parameter.
1339 * precondition: can both be called locked and unlocked
1342 static void wl_free(struct wl_info *wl)
1344 struct wl_timer *t, *next;
1347 /* free ucode data */
1349 wl_ucode_data_free();
1351 free_irq(wl->irq, wl);
1354 tasklet_kill(&wl->tasklet);
1357 wlc_module_unregister(wl->pub, "linux", wl);
1360 /* free common resources */
1362 wlc_detach(wl->wlc);
1367 /* virtual interface deletion is deferred so we cannot spinwait */
1369 /* wait for all pending callbacks to complete */
1370 while (atomic_read(&wl->callbacks) > 0)
1374 for (t = wl->timers; t; t = next) {
1383 * unregister_netdev() calls get_stats() which may read chip registers
1384 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1386 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1387 wl->bcm_bustype != JTAG_BUS) {
1388 iounmap((void *)wl->regsva);
1394 * precondition: perimeter lock has been acquired
1396 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1399 WL_ERROR("Shouldn't be here %s\n", __func__);
1403 * precondition: perimeter lock has been acquired
1405 void wl_init(struct wl_info *wl)
1407 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1415 * precondition: perimeter lock has been acquired
1417 uint wl_reset(struct wl_info *wl)
1419 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1423 /* dpc will not be rescheduled */
1430 * These are interrupt on/off entry points. Disable interrupts
1431 * during interrupt state transition.
1433 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1435 unsigned long flags;
1437 INT_LOCK(wl, flags);
1438 wlc_intrson(wl->wlc);
1439 INT_UNLOCK(wl, flags);
1443 * precondition: perimeter lock has been acquired
1445 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1450 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1452 unsigned long flags;
1455 INT_LOCK(wl, flags);
1456 status = wlc_intrsoff(wl->wlc);
1457 INT_UNLOCK(wl, flags);
1461 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1463 unsigned long flags;
1465 INT_LOCK(wl, flags);
1466 wlc_intrsrestore(wl->wlc, macintmask);
1467 INT_UNLOCK(wl, flags);
1471 * precondition: perimeter lock has been acquired
1473 int wl_up(struct wl_info *wl)
1480 error = wlc_up(wl->wlc);
1486 * precondition: perimeter lock has been acquired
1488 void wl_down(struct wl_info *wl)
1490 uint callbacks, ret_val = 0;
1492 /* call common down function */
1493 ret_val = wlc_down(wl->wlc);
1494 callbacks = atomic_read(&wl->callbacks) - ret_val;
1496 /* wait for down callbacks to complete */
1499 /* For HIGH_only driver, it's important to actually schedule other work,
1500 * not just spin wait since everything runs at schedule level
1502 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1507 static irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1511 unsigned long flags;
1513 wl = (struct wl_info *) dev_id;
1515 WL_ISRLOCK(wl, flags);
1517 /* call common first level interrupt handler */
1518 ours = wlc_isr(wl->wlc, &wantdpc);
1520 /* if more to do... */
1523 /* ...and call the second level interrupt handler */
1525 ASSERT(wl->resched == false);
1526 tasklet_schedule(&wl->tasklet);
1530 WL_ISRUNLOCK(wl, flags);
1532 return IRQ_RETVAL(ours);
1535 static void BCMFASTPATH wl_dpc(unsigned long data)
1539 wl = (struct wl_info *) data;
1543 /* call the common second level interrupt handler */
1546 unsigned long flags;
1548 INT_LOCK(wl, flags);
1549 wlc_intrsupd(wl->wlc);
1550 INT_UNLOCK(wl, flags);
1553 wl->resched = wlc_dpc(wl->wlc, true);
1556 /* wlc_dpc() may bring the driver down */
1560 /* re-schedule dpc */
1562 tasklet_schedule(&wl->tasklet);
1564 /* re-enable interrupts */
1573 * is called by the kernel from software irq context
1575 static void wl_timer(unsigned long data)
1577 _wl_timer((struct wl_timer *) data);
1581 * precondition: perimeter lock is not acquired
1583 static void _wl_timer(struct wl_timer *t)
1589 t->timer.expires = jiffies + t->ms * HZ / 1000;
1590 atomic_inc(&t->wl->callbacks);
1591 add_timer(&t->timer);
1599 atomic_dec(&t->wl->callbacks);
1605 * Adds a timer to the list. Caller supplies a timer function.
1606 * Is called from wlc.
1608 * precondition: perimeter lock has been acquired
1610 struct wl_timer *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg),
1611 void *arg, const char *name)
1615 t = kzalloc(sizeof(struct wl_timer), GFP_ATOMIC);
1617 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1621 init_timer(&t->timer);
1622 t->timer.data = (unsigned long) t;
1623 t->timer.function = wl_timer;
1627 t->next = wl->timers;
1631 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1633 strcpy(t->name, name);
1639 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1640 * as well as it's easier to make it periodic
1642 * precondition: perimeter lock has been acquired
1644 void wl_add_timer(struct wl_info *wl, struct wl_timer *t, uint ms, int periodic)
1648 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1649 __func__, t->name, periodic);
1655 t->periodic = (bool) periodic;
1657 t->timer.expires = jiffies + ms * HZ / 1000;
1659 atomic_inc(&wl->callbacks);
1660 add_timer(&t->timer);
1664 * return true if timer successfully deleted, false if still pending
1666 * precondition: perimeter lock has been acquired
1668 bool wl_del_timer(struct wl_info *wl, struct wl_timer *t)
1672 if (!del_timer(&t->timer)) {
1675 atomic_dec(&wl->callbacks);
1682 * precondition: perimeter lock has been acquired
1684 void wl_free_timer(struct wl_info *wl, struct wl_timer *t)
1686 struct wl_timer *tmp;
1688 /* delete the timer in case it is active */
1689 wl_del_timer(wl, t);
1691 if (wl->timers == t) {
1692 wl->timers = wl->timers->next;
1703 if (tmp->next == t) {
1704 tmp->next = t->next;
1717 * runs in software irq context
1719 * precondition: perimeter lock is not acquired
1721 static int wl_linux_watchdog(void *ctx)
1723 struct wl_info *wl = (struct wl_info *) ctx;
1725 struct net_device_stats *stats = NULL;
1729 ASSERT(wl->stats_id < 2);
1731 cnt = wl->pub->_cnt;
1732 id = 1 - wl->stats_id;
1733 stats = &wl->stats_watchdog[id];
1734 stats->rx_packets = cnt->rxframe;
1735 stats->tx_packets = cnt->txframe;
1736 stats->rx_bytes = cnt->rxbyte;
1737 stats->tx_bytes = cnt->txbyte;
1738 stats->rx_errors = cnt->rxerror;
1739 stats->tx_errors = cnt->txerror;
1740 stats->collisions = 0;
1742 stats->rx_length_errors = 0;
1743 stats->rx_over_errors = cnt->rxoflo;
1744 stats->rx_crc_errors = cnt->rxcrc;
1745 stats->rx_frame_errors = 0;
1746 stats->rx_fifo_errors = cnt->rxoflo;
1747 stats->rx_missed_errors = 0;
1749 stats->tx_fifo_errors = cnt->txuflo;
1763 char *wl_firmwares[WL_MAX_FW] = {
1769 * precondition: perimeter lock has been acquired
1771 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1775 struct wl_fw_hdr *hdr;
1776 for (i = 0; i < wl->fw.fw_cnt; i++) {
1777 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1778 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1780 if (hdr->idx == idx) {
1781 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1782 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1783 if (*pbuf == NULL) {
1784 WL_ERROR("fail to alloc %d bytes\n",
1788 memcpy(*pbuf, pdata, hdr->len);
1793 WL_ERROR("ERROR: ucode buf tag:%d can not be found!\n", idx);
1796 return BCME_NOTFOUND;
1800 * Precondition: Since this function is called in wl_pci_probe() context,
1801 * no locking is required.
1803 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, 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 ASSERT(hdr->len == 4);
1815 *data = *((u32 *) pdata);
1820 WL_ERROR("ERROR: ucode tag:%d can not be found!\n", idx);
1825 * Precondition: Since this function is called in wl_pci_probe() context,
1826 * no locking is required.
1828 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1831 struct device *device = &pdev->dev;
1835 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1836 for (i = 0; i < WL_MAX_FW; i++) {
1837 if (wl_firmwares[i] == NULL)
1839 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1840 UCODE_LOADER_API_VER);
1841 WL_NONE("request fw %s\n", fw_name);
1842 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1844 WL_ERROR("%s: fail to load firmware %s\n",
1845 KBUILD_MODNAME, fw_name);
1848 WL_NONE("request fw %s\n", fw_name);
1849 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1850 UCODE_LOADER_API_VER);
1851 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1853 WL_ERROR("%s: fail to load firmware %s\n",
1854 KBUILD_MODNAME, fw_name);
1857 wl->fw.hdr_num_entries[i] =
1858 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1859 WL_NONE("request fw %s find: %d entries\n",
1860 fw_name, wl->fw.hdr_num_entries[i]);
1863 return wl_ucode_data_init(wl);
1867 * precondition: can both be called locked and unlocked
1869 void wl_ucode_free_buf(void *p)
1875 * Precondition: Since this function is called in wl_pci_probe() context,
1876 * no locking is required.
1878 static void wl_release_fw(struct wl_info *wl)
1881 for (i = 0; i < WL_MAX_FW; i++) {
1882 release_firmware(wl->fw.fw_bin[i]);
1883 release_firmware(wl->fw.fw_hdr[i]);
1889 * checks validity of all firmware images loaded from user space
1891 * Precondition: Since this function is called in wl_pci_probe() context,
1892 * no locking is required.
1894 int wl_check_firmwares(struct wl_info *wl)
1899 const struct firmware *fw;
1900 const struct firmware *fw_hdr;
1901 struct wl_fw_hdr *ucode_hdr;
1902 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1903 fw = wl->fw.fw_bin[i];
1904 fw_hdr = wl->fw.fw_hdr[i];
1905 if (fw == NULL && fw_hdr == NULL) {
1907 } else if (fw == NULL || fw_hdr == NULL) {
1908 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1910 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1911 WL_ERROR("%s: non integral fw hdr file size %zu/%zu\n",
1912 __func__, fw_hdr->size,
1913 sizeof(struct wl_fw_hdr));
1915 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1916 WL_ERROR("%s: out of bounds fw file size %zu\n",
1917 __func__, fw->size);
1920 /* check if ucode section overruns firmware image */
1921 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1922 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1923 !rc; entry++, ucode_hdr++) {
1924 if (ucode_hdr->offset + ucode_hdr->len >
1926 WL_ERROR("%s: conflicting bin/hdr\n",
1933 if (rc == 0 && wl->fw.fw_cnt != i) {
1934 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1941 * precondition: perimeter lock has been acquired
1943 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1945 bool blocked = wlc_check_radio_disabled(wl->wlc);
1947 WL_NONE("%s: update hw state: blocked=%s\n", __func__,
1948 blocked ? "true" : "false");
1950 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1952 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);