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 static void wl_timer(unsigned long data);
52 static void _wl_timer(struct wl_timer *t);
55 static int ieee_hw_init(struct ieee80211_hw *hw);
56 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
58 static int wl_linux_watchdog(void *ctx);
60 /* Flags we support */
61 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
67 FIF_BCN_PRBRESP_PROMISC)
71 #define WL_DEV_IF(dev) ((struct wl_if *)netdev_priv(dev))
72 #define WL_INFO(dev) ((struct wl_info *)(WL_DEV_IF(dev)->wl))
73 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev);
74 static void wl_release_fw(struct wl_info *wl);
76 /* local prototypes */
77 static void wl_dpc(unsigned long data);
78 static irqreturn_t wl_isr(int irq, void *dev_id);
80 static int __devinit wl_pci_probe(struct pci_dev *pdev,
81 const struct pci_device_id *ent);
82 static void wl_remove(struct pci_dev *pdev);
83 static void wl_free(struct wl_info *wl);
85 MODULE_AUTHOR("Broadcom Corporation");
86 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
87 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
88 MODULE_LICENSE("Dual BSD/GPL");
90 /* recognized PCI IDs */
91 static struct pci_device_id wl_id_table[] = {
92 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
93 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
94 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
98 MODULE_DEVICE_TABLE(pci, wl_id_table);
101 static int msglevel = 0xdeadbeef;
102 module_param(msglevel, int, 0);
103 static int phymsglevel = 0xdeadbeef;
104 module_param(phymsglevel, int, 0);
107 #define HW_TO_WL(hw) (hw->priv)
108 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
110 /* MAC80211 callback functions */
111 static int wl_ops_start(struct ieee80211_hw *hw);
112 static void wl_ops_stop(struct ieee80211_hw *hw);
113 static int wl_ops_add_interface(struct ieee80211_hw *hw,
114 struct ieee80211_vif *vif);
115 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
116 struct ieee80211_vif *vif);
117 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
118 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
119 struct ieee80211_vif *vif,
120 struct ieee80211_bss_conf *info,
122 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
123 unsigned int changed_flags,
124 unsigned int *total_flags, u64 multicast);
125 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
127 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
128 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
129 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
130 static int wl_ops_get_stats(struct ieee80211_hw *hw,
131 struct ieee80211_low_level_stats *stats);
132 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
133 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
134 struct ieee80211_vif *vif,
135 enum sta_notify_cmd cmd,
136 struct ieee80211_sta *sta);
137 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
138 const struct ieee80211_tx_queue_params *params);
139 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
140 static int wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
141 struct ieee80211_sta *sta);
142 static int wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
143 struct ieee80211_sta *sta);
144 static int wl_ops_ampdu_action(struct ieee80211_hw *hw,
145 struct ieee80211_vif *vif,
146 enum ieee80211_ampdu_mlme_action action,
147 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
149 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw);
151 static void wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
153 struct wl_info *wl = hw->priv;
157 WL_ERROR("ops->tx called while down\n");
161 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
166 static int wl_ops_start(struct ieee80211_hw *hw)
168 struct wl_info *wl = hw->priv;
171 struct ieee80211_channel *curchan = hw->conf.channel;
172 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
175 ieee80211_wake_queues(hw);
177 blocked = wl_rfkill_set_hw_state(wl);
180 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
185 static void wl_ops_stop(struct ieee80211_hw *hw)
188 struct wl_info *wl = hw->priv;
191 ieee80211_stop_queues(hw);
195 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
200 /* Just STA for now */
201 if (vif->type != NL80211_IFTYPE_AP &&
202 vif->type != NL80211_IFTYPE_MESH_POINT &&
203 vif->type != NL80211_IFTYPE_STATION &&
204 vif->type != NL80211_IFTYPE_WDS &&
205 vif->type != NL80211_IFTYPE_ADHOC) {
206 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
207 __func__, vif->type);
217 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
223 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
229 /* put driver in down state */
236 * precondition: perimeter lock has been acquired
239 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
240 enum nl80211_channel_type type)
242 struct wl_info *wl = HW_TO_WL(hw);
246 case NL80211_CHAN_HT20:
247 case NL80211_CHAN_NO_HT:
248 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
250 case NL80211_CHAN_HT40MINUS:
251 case NL80211_CHAN_HT40PLUS:
252 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
262 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
264 struct ieee80211_conf *conf = &hw->conf;
265 struct wl_info *wl = HW_TO_WL(hw);
270 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
272 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
273 WL_ERROR("%s: Error setting listen_interval\n",
278 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
279 ASSERT(new_int == conf->listen_interval);
281 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
282 WL_ERROR("%s: change monitor mode: %s (implement)\n", __func__,
283 conf->flags & IEEE80211_CONF_MONITOR ?
285 if (changed & IEEE80211_CONF_CHANGE_PS)
286 WL_ERROR("%s: change power-save mode: %s (implement)\n",
287 __func__, conf->flags & IEEE80211_CONF_PS ?
290 if (changed & IEEE80211_CONF_CHANGE_POWER) {
292 (wl->wlc, "qtxpower", conf->power_level * 4)) {
293 WL_ERROR("%s: Error setting power_level\n", __func__);
297 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
298 if (new_int != (conf->power_level * 4))
299 WL_ERROR("%s: Power level req != actual, %d %d\n",
300 __func__, conf->power_level * 4, new_int);
302 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
303 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
305 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
307 (wl->wlc, WLC_SET_SRL,
308 conf->short_frame_max_tx_count) < 0) {
309 WL_ERROR("%s: Error setting srl\n", __func__);
313 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
315 WL_ERROR("%s: Error setting lrl\n", __func__);
327 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
328 struct ieee80211_vif *vif,
329 struct ieee80211_bss_conf *info, u32 changed)
331 struct wl_info *wl = HW_TO_WL(hw);
334 if (changed & BSS_CHANGED_ASSOC) {
335 /* association status changed (associated/disassociated)
336 * also implies a change in the AID.
338 WL_ERROR("%s: %s: %sassociated\n", KBUILD_MODNAME, __func__,
339 info->assoc ? "" : "dis");
340 wlc_associate_upd(wl->wlc, info->assoc);
342 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
343 /* CTS protection changed */
344 WL_ERROR("%s: use_cts_prot: %s (implement)\n", __func__,
345 info->use_cts_prot ? "true" : "false");
347 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
348 /* preamble changed */
349 WL_ERROR("%s: short preamble: %s (implement)\n", __func__,
350 info->use_short_preamble ? "true" : "false");
352 if (changed & BSS_CHANGED_ERP_SLOT) {
353 /* slot timing changed */
354 if (info->use_short_slot)
359 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
363 if (changed & BSS_CHANGED_HT) {
364 /* 802.11n parameters changed */
365 u16 mode = info->ht_operation_mode;
366 WL_NONE("%s: HT mode: 0x%04X\n", __func__, mode);
367 wlc_protection_upd(wl->wlc, WLC_PROT_N_CFG,
368 mode & IEEE80211_HT_OP_MODE_PROTECTION);
369 wlc_protection_upd(wl->wlc, WLC_PROT_N_NONGF,
370 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
371 wlc_protection_upd(wl->wlc, WLC_PROT_N_OBSS,
372 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
374 if (changed & BSS_CHANGED_BASIC_RATES) {
375 /* Basic rateset changed */
376 WL_ERROR("%s: Need to change Basic Rates: 0x%x (implement)\n",
377 __func__, (u32) info->basic_rates);
379 if (changed & BSS_CHANGED_BEACON_INT) {
380 /* Beacon interval changed */
381 WL_NONE("%s: Beacon Interval: %d\n",
382 __func__, info->beacon_int);
383 wlc_set(wl->wlc, WLC_SET_BCNPRD, info->beacon_int);
385 if (changed & BSS_CHANGED_BSSID) {
386 /* BSSID changed, for whatever reason (IBSS and managed mode) */
387 WL_NONE("%s: new BSSID: aid %d bss:%pM\n", __func__,
388 info->aid, info->bssid);
390 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
394 if (changed & BSS_CHANGED_BEACON) {
395 /* Beacon data changed, retrieve new beacon (beaconing modes) */
396 WL_ERROR("%s: beacon changed\n", __func__);
398 if (changed & BSS_CHANGED_BEACON_ENABLED) {
399 /* Beaconing should be enabled/disabled (beaconing modes) */
400 WL_ERROR("%s: Beacon enabled: %s\n", __func__,
401 info->enable_beacon ? "true" : "false");
403 if (changed & BSS_CHANGED_CQM) {
404 /* Connection quality monitor config changed */
405 WL_ERROR("%s: cqm change: threshold %d, hys %d (implement)\n",
406 __func__, info->cqm_rssi_thold, info->cqm_rssi_hyst);
408 if (changed & BSS_CHANGED_IBSS) {
409 /* IBSS join status changed */
410 WL_ERROR("%s: IBSS joined: %s (implement)\n", __func__,
411 info->ibss_joined ? "true" : "false");
413 if (changed & BSS_CHANGED_ARP_FILTER) {
414 /* Hardware ARP filter address list or state changed */
415 WL_ERROR("%s: arp filtering: enabled %s, count %d (implement)\n",
416 __func__, info->arp_filter_enabled ? "true" : "false",
419 if (changed & BSS_CHANGED_QOS) {
421 * QoS for this association was enabled/disabled.
422 * Note that it is only ever disabled for station mode.
424 WL_ERROR("%s: qos enabled: %s (implement)\n", __func__,
425 info->qos ? "true" : "false");
427 if (changed & BSS_CHANGED_IDLE) {
428 /* Idle changed for this BSS/interface */
429 WL_ERROR("%s: BSS idle: %s (implement)\n", __func__,
430 info->idle ? "true" : "false");
436 wl_ops_configure_filter(struct ieee80211_hw *hw,
437 unsigned int changed_flags,
438 unsigned int *total_flags, u64 multicast)
440 struct wl_info *wl = hw->priv;
442 changed_flags &= MAC_FILTERS;
443 *total_flags &= MAC_FILTERS;
444 if (changed_flags & FIF_PROMISC_IN_BSS)
445 WL_ERROR("FIF_PROMISC_IN_BSS\n");
446 if (changed_flags & FIF_ALLMULTI)
447 WL_ERROR("FIF_ALLMULTI\n");
448 if (changed_flags & FIF_FCSFAIL)
449 WL_ERROR("FIF_FCSFAIL\n");
450 if (changed_flags & FIF_PLCPFAIL)
451 WL_ERROR("FIF_PLCPFAIL\n");
452 if (changed_flags & FIF_CONTROL)
453 WL_ERROR("FIF_CONTROL\n");
454 if (changed_flags & FIF_OTHER_BSS)
455 WL_ERROR("FIF_OTHER_BSS\n");
456 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
457 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
459 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
460 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
461 wlc_mac_bcn_promisc_change(wl->wlc, 1);
463 wlc_mac_bcn_promisc_change(wl->wlc, 0);
464 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
472 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
474 WL_NONE("%s: Enter\n", __func__);
478 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
480 struct wl_info *wl = hw->priv;
481 WL_NONE("Scan Start\n");
483 wlc_scan_start(wl->wlc);
488 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
490 struct wl_info *wl = hw->priv;
491 WL_NONE("Scan Complete\n");
493 wlc_scan_stop(wl->wlc);
498 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
500 WL_ERROR("%s: Enter\n", __func__);
505 wl_ops_get_stats(struct ieee80211_hw *hw,
506 struct ieee80211_low_level_stats *stats)
508 struct wl_info *wl = hw->priv;
513 stats->dot11ACKFailureCount = cnt->txnoack;
514 stats->dot11RTSFailureCount = cnt->txnocts;
515 stats->dot11FCSErrorCount = cnt->rxcrc;
516 stats->dot11RTSSuccessCount = cnt->txrts;
521 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
523 struct wl_info *wl = hw->priv;
526 wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
532 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
533 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
535 WL_NONE("%s: Enter\n", __func__);
538 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
545 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
546 const struct ieee80211_tx_queue_params *params)
548 struct wl_info *wl = hw->priv;
550 WL_NONE("%s: Enter (WME config)\n", __func__);
551 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
552 params->txop, params->cw_min, params->cw_max, params->aifs);
555 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
561 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
563 WL_ERROR("%s: Enter\n", __func__);
568 wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
569 struct ieee80211_sta *sta)
574 struct wl_info *wl = hw->priv;
577 scb = (struct scb *)sta->drv_priv;
578 memset(scb, 0, sizeof(struct scb));
579 for (i = 0; i < NUMPRIO; i++)
580 scb->seqctl[i] = 0xFFFF;
581 scb->seqctl_nonqos = 0xFFFF;
582 scb->magic = SCB_MAGIC;
584 wl->pub->global_scb = scb;
585 wl->pub->global_ampdu = &(scb->scb_ampdu);
586 wl->pub->global_ampdu->scb = scb;
587 wl->pub->global_ampdu->max_pdu = 16;
588 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
589 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
591 sta->ht_cap.ht_supported = true;
592 sta->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
593 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
594 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
595 IEEE80211_HT_CAP_SGI_20 |
596 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
598 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
603 wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
604 struct ieee80211_sta *sta)
606 WL_NONE("%s: Enter\n", __func__);
611 wl_ops_ampdu_action(struct ieee80211_hw *hw,
612 struct ieee80211_vif *vif,
613 enum ieee80211_ampdu_mlme_action action,
614 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
618 struct scb *scb = (struct scb *)sta->drv_priv;
620 struct wl_info *wl = hw->priv;
623 ASSERT(scb->magic == SCB_MAGIC);
625 case IEEE80211_AMPDU_RX_START:
626 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
628 case IEEE80211_AMPDU_RX_STOP:
629 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
631 case IEEE80211_AMPDU_TX_START:
633 status = wlc_aggregatable(wl->wlc, tid);
636 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
639 /* XXX: Use the starting sequence number provided ... */
641 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
644 case IEEE80211_AMPDU_TX_STOP:
646 wlc_ampdu_flush(wl->wlc, sta, tid);
648 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
650 case IEEE80211_AMPDU_TX_OPERATIONAL:
651 /* Not sure what to do here */
652 /* Power save wakeup */
653 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
657 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
663 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
665 struct wl_info *wl = HW_TO_WL(hw);
669 blocked = wlc_check_radio_disabled(wl->wlc);
672 WL_NONE("wl: rfkill_poll: %d\n", blocked);
673 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
676 static const struct ieee80211_ops wl_ops = {
678 .start = wl_ops_start,
680 .add_interface = wl_ops_add_interface,
681 .remove_interface = wl_ops_remove_interface,
682 .config = wl_ops_config,
683 .bss_info_changed = wl_ops_bss_info_changed,
684 .configure_filter = wl_ops_configure_filter,
685 .set_tim = wl_ops_set_tim,
686 .sw_scan_start = wl_ops_sw_scan_start,
687 .sw_scan_complete = wl_ops_sw_scan_complete,
688 .set_tsf = wl_ops_set_tsf,
689 .get_stats = wl_ops_get_stats,
690 .set_rts_threshold = wl_ops_set_rts_threshold,
691 .sta_notify = wl_ops_sta_notify,
692 .conf_tx = wl_ops_conf_tx,
693 .get_tsf = wl_ops_get_tsf,
694 .sta_add = wl_ops_sta_add,
695 .sta_remove = wl_ops_sta_remove,
696 .ampdu_action = wl_ops_ampdu_action,
697 .rfkill_poll = wl_ops_rfkill_poll,
701 * is called in wl_pci_probe() context, therefore no locking required.
703 static int wl_set_hint(struct wl_info *wl, char *abbrev)
705 WL_NONE("%s: Sending country code %c%c to MAC80211\n",
706 __func__, abbrev[0], abbrev[1]);
707 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
711 * attach to the WL device.
713 * Attach to the WL device identified by vendor and device parameters.
714 * regs is a host accessible memory address pointing to WL device registers.
716 * wl_attach is not defined as static because in the case where no bus
717 * is defined, wl_attach will never be called, and thus, gcc will issue
718 * a warning that this function is defined but not used if we declare
722 * is called in wl_pci_probe() context, therefore no locking required.
724 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
725 uint bustype, void *btparam, uint irq)
730 unsigned long base_addr;
731 struct ieee80211_hw *hw;
738 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
742 /* allocate private info */
743 hw = pci_get_drvdata(btparam); /* btparam == pdev */
747 atomic_set(&wl->callbacks, 0);
749 /* setup the bottom half handler */
750 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
756 if (bustype == PCI_BUS) {
758 } else if (bustype == RPC_BUS) {
762 WL_TRACE("force to PCI\n");
764 wl->bcm_bustype = bustype;
766 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
767 if (wl->regsva == NULL) {
768 WL_ERROR("wl%d: ioremap() failed\n", unit);
771 spin_lock_init(&wl->lock);
772 spin_lock_init(&wl->isr_lock);
775 if (wl_request_fw(wl, (struct pci_dev *)btparam) < 0) {
776 WL_ERROR("%s: Failed to find firmware usually in %s\n",
777 KBUILD_MODNAME, "/lib/firmware/brcm");
779 wl_remove((struct pci_dev *)btparam);
783 /* common load-time initialization */
784 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode,
785 wl->regsva, wl->bcm_bustype, btparam, &err);
788 WL_ERROR("%s: wlc_attach() failed with code %d\n",
789 KBUILD_MODNAME, err);
792 wl->pub = wlc_pub(wl->wlc);
794 wl->pub->ieee_hw = hw;
795 ASSERT(wl->pub->ieee_hw);
796 ASSERT(wl->pub->ieee_hw->priv == wl);
799 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
800 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
803 /* register our interrupt handler */
804 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
805 WL_ERROR("wl%d: request_irq() failed\n", unit);
810 /* register module */
811 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
814 if (ieee_hw_init(hw)) {
815 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
819 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
820 ASSERT(is_valid_ether_addr(perm));
821 SET_IEEE80211_PERM_ADDR(hw, perm);
823 err = ieee80211_register_hw(hw);
825 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
829 if (wl->pub->srom_ccode[0])
830 err = wl_set_hint(wl, wl->pub->srom_ccode);
832 err = wl_set_hint(wl, "US");
834 WL_ERROR("%s: regulatory_hint failed, status %d\n",
849 #define CHAN2GHZ(channel, freqency, chflags) { \
850 .band = IEEE80211_BAND_2GHZ, \
851 .center_freq = (freqency), \
852 .hw_value = (channel), \
854 .max_antenna_gain = 0, \
858 static struct ieee80211_channel wl_2ghz_chantable[] = {
859 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
860 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
861 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
862 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
863 CHAN2GHZ(5, 2432, 0),
864 CHAN2GHZ(6, 2437, 0),
865 CHAN2GHZ(7, 2442, 0),
866 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
867 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
868 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
869 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
871 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
872 IEEE80211_CHAN_NO_HT40PLUS),
874 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
875 IEEE80211_CHAN_NO_HT40PLUS),
877 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
878 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
881 #define CHAN5GHZ(channel, chflags) { \
882 .band = IEEE80211_BAND_5GHZ, \
883 .center_freq = 5000 + 5*(channel), \
884 .hw_value = (channel), \
886 .max_antenna_gain = 0, \
890 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
892 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
893 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
894 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
895 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
898 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
899 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
901 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
902 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
904 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
905 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
907 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
908 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),
917 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
918 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
920 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
921 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
923 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
924 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
926 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
927 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
929 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
930 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
932 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
933 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
935 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
936 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
938 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
939 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
941 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
942 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
943 IEEE80211_CHAN_NO_HT40MINUS),
945 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
946 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
947 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
948 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
949 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
952 #define RATE(rate100m, _flags) { \
953 .bitrate = (rate100m), \
955 .hw_value = (rate100m / 5), \
958 static struct ieee80211_rate wl_legacy_ratetable[] = {
960 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
961 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
962 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
973 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
974 .band = IEEE80211_BAND_2GHZ,
975 .channels = wl_2ghz_chantable,
976 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
977 .bitrates = wl_legacy_ratetable,
978 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
980 /* from include/linux/ieee80211.h */
981 .cap = IEEE80211_HT_CAP_GRN_FLD |
982 IEEE80211_HT_CAP_SGI_20 |
983 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
984 .ht_supported = true,
985 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
986 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
988 /* placeholders for now */
989 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
991 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
995 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
996 .band = IEEE80211_BAND_5GHZ,
997 .channels = wl_5ghz_nphy_chantable,
998 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
999 .bitrates = wl_legacy_ratetable + 4,
1000 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1002 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1003 .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 */
1004 .ht_supported = true,
1005 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
1006 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1008 /* placeholders for now */
1009 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1011 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1016 * is called in wl_pci_probe() context, therefore no locking required.
1018 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1020 struct wl_info *wl = HW_TO_WL(hw);
1026 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1027 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1029 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1030 WL_ERROR("Phy list failed\n");
1032 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
1034 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1035 if (phy_list[0] == 'c') {
1037 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1038 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1040 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1046 /* Assume all bands use the same phy. True for 11n devices. */
1047 if (NBANDS_PUB(wl->pub) > 1) {
1049 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1050 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1057 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
1063 * is called in wl_pci_probe() context, therefore no locking required.
1065 static int ieee_hw_init(struct ieee80211_hw *hw)
1067 hw->flags = IEEE80211_HW_SIGNAL_DBM
1068 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1069 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1070 | IEEE80211_HW_AMPDU_AGGREGATION;
1072 hw->extra_tx_headroom = wlc_get_header_len();
1073 /* FIXME: should get this from wlc->machwcap */
1075 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1076 * mac80211/status.c:ieee80211_tx_status() checks this value,
1077 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1078 * appears to always set 3 rates
1080 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1082 hw->channel_change_time = 7 * 1000; /* channel change time is dependent on chip and band */
1083 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1085 hw->rate_control_algorithm = "minstrel_ht";
1087 hw->sta_data_size = sizeof(struct scb);
1088 return ieee_hw_rate_init(hw);
1092 * determines if a device is a WL device, and if so, attaches it.
1094 * This function determines if a device pointed to by pdev is a WL device,
1095 * and if so, performs a wl_attach() on it.
1097 * Perimeter lock is initialized in the course of this function.
1099 static int __devinit
1100 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1104 struct ieee80211_hw *hw;
1109 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1110 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1111 PCI_FUNC(pdev->devfn), pdev->irq);
1113 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1114 (((pdev->device & 0xff00) != 0x4300) &&
1115 ((pdev->device & 0xff00) != 0x4700) &&
1116 ((pdev->device < 43000) || (pdev->device > 43999))))
1119 rc = pci_enable_device(pdev);
1121 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1122 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1123 PCI_FUNC(pdev->devfn));
1126 pci_set_master(pdev);
1128 pci_read_config_dword(pdev, 0x40, &val);
1129 if ((val & 0x0000ff00) != 0)
1130 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1132 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1134 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1139 SET_IEEE80211_DEV(hw, &pdev->dev);
1141 pci_set_drvdata(pdev, hw);
1143 memset(hw->priv, 0, sizeof(*wl));
1145 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1146 PCI_BUS, pdev, pdev->irq);
1149 WL_ERROR("%s: %s: wl_attach failed!\n",
1150 KBUILD_MODNAME, __func__);
1155 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1159 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1162 struct ieee80211_hw *hw;
1164 WL_TRACE("wl: wl_suspend\n");
1166 hw = pci_get_drvdata(pdev);
1169 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1173 /* only need to flag hw is down for proper resume */
1175 wl->pub->hw_up = false;
1178 pci_save_state(pdev);
1179 pci_disable_device(pdev);
1180 return pci_set_power_state(pdev, PCI_D3hot);
1183 static int wl_resume(struct pci_dev *pdev)
1186 struct ieee80211_hw *hw;
1190 WL_TRACE("wl: wl_resume\n");
1191 hw = pci_get_drvdata(pdev);
1194 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1198 err = pci_set_power_state(pdev, PCI_D0);
1202 pci_restore_state(pdev);
1204 err = pci_enable_device(pdev);
1208 pci_set_master(pdev);
1210 pci_read_config_dword(pdev, 0x40, &val);
1211 if ((val & 0x0000ff00) != 0)
1212 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1215 * done. driver will be put in up state
1216 * in wl_ops_add_interface() call.
1222 * called from both kernel as from wl_*()
1223 * precondition: perimeter lock is not acquired.
1225 static void wl_remove(struct pci_dev *pdev)
1228 struct ieee80211_hw *hw;
1231 hw = pci_get_drvdata(pdev);
1234 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1239 status = wlc_chipmatch(pdev->vendor, pdev->device);
1242 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1246 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1247 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1248 ieee80211_unregister_hw(hw);
1252 WL_NONE("%s: Down\n", __func__);
1254 pci_disable_device(pdev);
1258 pci_set_drvdata(pdev, NULL);
1259 ieee80211_free_hw(hw);
1262 static struct pci_driver wl_pci_driver = {
1263 .name = KBUILD_MODNAME,
1264 .probe = wl_pci_probe,
1265 .suspend = wl_suspend,
1266 .resume = wl_resume,
1267 .remove = __devexit_p(wl_remove),
1268 .id_table = wl_id_table,
1272 * This is the main entry point for the WL driver.
1274 * This function determines if a device pointed to by pdev is a WL device,
1275 * and if so, performs a wl_attach() on it.
1278 static int __init wl_module_init(void)
1280 int error = -ENODEV;
1283 if (msglevel != 0xdeadbeef)
1284 wl_msg_level = msglevel;
1286 char *var = getvar(NULL, "wl_msglevel");
1288 unsigned long value;
1290 (void)strict_strtoul(var, 0, &value);
1291 wl_msg_level = value;
1294 if (phymsglevel != 0xdeadbeef)
1295 phyhal_msg_level = phymsglevel;
1297 char *var = getvar(NULL, "phy_msglevel");
1299 unsigned long value;
1301 (void)strict_strtoul(var, 0, &value);
1302 phyhal_msg_level = value;
1307 error = pci_register_driver(&wl_pci_driver);
1317 * This function unloads the WL driver from the system.
1319 * This function unconditionally unloads the WL driver module from the
1323 static void __exit wl_module_exit(void)
1325 pci_unregister_driver(&wl_pci_driver);
1329 module_init(wl_module_init);
1330 module_exit(wl_module_exit);
1333 * This function frees the WL per-device resources.
1335 * This function frees resources owned by the WL device pointed to
1336 * by the wl parameter.
1338 * precondition: can both be called locked and unlocked
1341 static void wl_free(struct wl_info *wl)
1343 struct wl_timer *t, *next;
1346 /* free ucode data */
1348 wl_ucode_data_free();
1350 free_irq(wl->irq, wl);
1353 tasklet_kill(&wl->tasklet);
1356 wlc_module_unregister(wl->pub, "linux", wl);
1359 /* free common resources */
1361 wlc_detach(wl->wlc);
1366 /* virtual interface deletion is deferred so we cannot spinwait */
1368 /* wait for all pending callbacks to complete */
1369 while (atomic_read(&wl->callbacks) > 0)
1373 for (t = wl->timers; t; t = next) {
1382 * unregister_netdev() calls get_stats() which may read chip registers
1383 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1385 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1386 wl->bcm_bustype != JTAG_BUS) {
1387 iounmap((void *)wl->regsva);
1393 * precondition: perimeter lock has been acquired
1395 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1398 WL_ERROR("Shouldn't be here %s\n", __func__);
1402 * precondition: perimeter lock has been acquired
1404 void wl_init(struct wl_info *wl)
1406 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1414 * precondition: perimeter lock has been acquired
1416 uint wl_reset(struct wl_info *wl)
1418 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1422 /* dpc will not be rescheduled */
1429 * These are interrupt on/off entry points. Disable interrupts
1430 * during interrupt state transition.
1432 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1434 unsigned long flags;
1436 INT_LOCK(wl, flags);
1437 wlc_intrson(wl->wlc);
1438 INT_UNLOCK(wl, flags);
1442 * precondition: perimeter lock has been acquired
1444 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1449 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1451 unsigned long flags;
1454 INT_LOCK(wl, flags);
1455 status = wlc_intrsoff(wl->wlc);
1456 INT_UNLOCK(wl, flags);
1460 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1462 unsigned long flags;
1464 INT_LOCK(wl, flags);
1465 wlc_intrsrestore(wl->wlc, macintmask);
1466 INT_UNLOCK(wl, flags);
1470 * precondition: perimeter lock has been acquired
1472 int wl_up(struct wl_info *wl)
1479 error = wlc_up(wl->wlc);
1485 * precondition: perimeter lock has been acquired
1487 void wl_down(struct wl_info *wl)
1489 uint callbacks, ret_val = 0;
1491 /* call common down function */
1492 ret_val = wlc_down(wl->wlc);
1493 callbacks = atomic_read(&wl->callbacks) - ret_val;
1495 /* wait for down callbacks to complete */
1498 /* For HIGH_only driver, it's important to actually schedule other work,
1499 * not just spin wait since everything runs at schedule level
1501 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1506 static irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1510 unsigned long flags;
1512 wl = (struct wl_info *) dev_id;
1514 WL_ISRLOCK(wl, flags);
1516 /* call common first level interrupt handler */
1517 ours = wlc_isr(wl->wlc, &wantdpc);
1519 /* if more to do... */
1522 /* ...and call the second level interrupt handler */
1524 ASSERT(wl->resched == false);
1525 tasklet_schedule(&wl->tasklet);
1529 WL_ISRUNLOCK(wl, flags);
1531 return IRQ_RETVAL(ours);
1534 static void BCMFASTPATH wl_dpc(unsigned long data)
1538 wl = (struct wl_info *) data;
1542 /* call the common second level interrupt handler */
1545 unsigned long flags;
1547 INT_LOCK(wl, flags);
1548 wlc_intrsupd(wl->wlc);
1549 INT_UNLOCK(wl, flags);
1552 wl->resched = wlc_dpc(wl->wlc, true);
1555 /* wlc_dpc() may bring the driver down */
1559 /* re-schedule dpc */
1561 tasklet_schedule(&wl->tasklet);
1563 /* re-enable interrupts */
1572 * is called by the kernel from software irq context
1574 static void wl_timer(unsigned long data)
1576 _wl_timer((struct wl_timer *) data);
1580 * precondition: perimeter lock is not acquired
1582 static void _wl_timer(struct wl_timer *t)
1588 t->timer.expires = jiffies + t->ms * HZ / 1000;
1589 atomic_inc(&t->wl->callbacks);
1590 add_timer(&t->timer);
1598 atomic_dec(&t->wl->callbacks);
1604 * Adds a timer to the list. Caller supplies a timer function.
1605 * Is called from wlc.
1607 * precondition: perimeter lock has been acquired
1609 struct wl_timer *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg),
1610 void *arg, const char *name)
1614 t = kzalloc(sizeof(struct wl_timer), GFP_ATOMIC);
1616 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1620 init_timer(&t->timer);
1621 t->timer.data = (unsigned long) t;
1622 t->timer.function = wl_timer;
1626 t->next = wl->timers;
1630 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1632 strcpy(t->name, name);
1638 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1639 * as well as it's easier to make it periodic
1641 * precondition: perimeter lock has been acquired
1643 void wl_add_timer(struct wl_info *wl, struct wl_timer *t, uint ms, int periodic)
1647 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1648 __func__, t->name, periodic);
1654 t->periodic = (bool) periodic;
1656 t->timer.expires = jiffies + ms * HZ / 1000;
1658 atomic_inc(&wl->callbacks);
1659 add_timer(&t->timer);
1663 * return true if timer successfully deleted, false if still pending
1665 * precondition: perimeter lock has been acquired
1667 bool wl_del_timer(struct wl_info *wl, struct wl_timer *t)
1671 if (!del_timer(&t->timer)) {
1674 atomic_dec(&wl->callbacks);
1681 * precondition: perimeter lock has been acquired
1683 void wl_free_timer(struct wl_info *wl, struct wl_timer *t)
1685 struct wl_timer *tmp;
1687 /* delete the timer in case it is active */
1688 wl_del_timer(wl, t);
1690 if (wl->timers == t) {
1691 wl->timers = wl->timers->next;
1702 if (tmp->next == t) {
1703 tmp->next = t->next;
1716 * runs in software irq context
1718 * precondition: perimeter lock is not acquired
1720 static int wl_linux_watchdog(void *ctx)
1722 struct wl_info *wl = (struct wl_info *) ctx;
1724 struct net_device_stats *stats = NULL;
1728 ASSERT(wl->stats_id < 2);
1730 cnt = wl->pub->_cnt;
1731 id = 1 - wl->stats_id;
1732 stats = &wl->stats_watchdog[id];
1733 stats->rx_packets = cnt->rxframe;
1734 stats->tx_packets = cnt->txframe;
1735 stats->rx_bytes = cnt->rxbyte;
1736 stats->tx_bytes = cnt->txbyte;
1737 stats->rx_errors = cnt->rxerror;
1738 stats->tx_errors = cnt->txerror;
1739 stats->collisions = 0;
1741 stats->rx_length_errors = 0;
1742 stats->rx_over_errors = cnt->rxoflo;
1743 stats->rx_crc_errors = cnt->rxcrc;
1744 stats->rx_frame_errors = 0;
1745 stats->rx_fifo_errors = cnt->rxoflo;
1746 stats->rx_missed_errors = 0;
1748 stats->tx_fifo_errors = cnt->txuflo;
1762 char *wl_firmwares[WL_MAX_FW] = {
1768 * precondition: perimeter lock has been acquired
1770 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1774 struct wl_fw_hdr *hdr;
1775 for (i = 0; i < wl->fw.fw_cnt; i++) {
1776 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1777 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1779 if (hdr->idx == idx) {
1780 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1781 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1782 if (*pbuf == NULL) {
1783 WL_ERROR("fail to alloc %d bytes\n",
1787 memcpy(*pbuf, pdata, hdr->len);
1792 WL_ERROR("ERROR: ucode buf tag:%d can not be found!\n", idx);
1795 return BCME_NOTFOUND;
1799 * Precondition: Since this function is called in wl_pci_probe() context,
1800 * no locking is required.
1802 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1806 struct wl_fw_hdr *hdr;
1807 for (i = 0; i < wl->fw.fw_cnt; i++) {
1808 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1809 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1811 if (hdr->idx == idx) {
1812 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1813 ASSERT(hdr->len == 4);
1814 *data = *((u32 *) pdata);
1819 WL_ERROR("ERROR: ucode tag:%d can not be found!\n", idx);
1824 * Precondition: Since this function is called in wl_pci_probe() context,
1825 * no locking is required.
1827 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1830 struct device *device = &pdev->dev;
1834 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1835 for (i = 0; i < WL_MAX_FW; i++) {
1836 if (wl_firmwares[i] == NULL)
1838 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1839 UCODE_LOADER_API_VER);
1840 WL_NONE("request fw %s\n", fw_name);
1841 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1843 WL_ERROR("%s: fail to load firmware %s\n",
1844 KBUILD_MODNAME, fw_name);
1847 WL_NONE("request fw %s\n", fw_name);
1848 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1849 UCODE_LOADER_API_VER);
1850 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1852 WL_ERROR("%s: fail to load firmware %s\n",
1853 KBUILD_MODNAME, fw_name);
1856 wl->fw.hdr_num_entries[i] =
1857 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1858 WL_NONE("request fw %s find: %d entries\n",
1859 fw_name, wl->fw.hdr_num_entries[i]);
1862 return wl_ucode_data_init(wl);
1866 * precondition: can both be called locked and unlocked
1868 void wl_ucode_free_buf(void *p)
1874 * Precondition: Since this function is called in wl_pci_probe() context,
1875 * no locking is required.
1877 static void wl_release_fw(struct wl_info *wl)
1880 for (i = 0; i < WL_MAX_FW; i++) {
1881 release_firmware(wl->fw.fw_bin[i]);
1882 release_firmware(wl->fw.fw_hdr[i]);
1888 * checks validity of all firmware images loaded from user space
1890 * Precondition: Since this function is called in wl_pci_probe() context,
1891 * no locking is required.
1893 int wl_check_firmwares(struct wl_info *wl)
1898 const struct firmware *fw;
1899 const struct firmware *fw_hdr;
1900 struct wl_fw_hdr *ucode_hdr;
1901 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1902 fw = wl->fw.fw_bin[i];
1903 fw_hdr = wl->fw.fw_hdr[i];
1904 if (fw == NULL && fw_hdr == NULL) {
1906 } else if (fw == NULL || fw_hdr == NULL) {
1907 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1909 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1910 WL_ERROR("%s: non integral fw hdr file size %zu/%zu\n",
1911 __func__, fw_hdr->size,
1912 sizeof(struct wl_fw_hdr));
1914 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1915 WL_ERROR("%s: out of bounds fw file size %zu\n",
1916 __func__, fw->size);
1919 /* check if ucode section overruns firmware image */
1920 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1921 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1922 !rc; entry++, ucode_hdr++) {
1923 if (ucode_hdr->offset + ucode_hdr->len >
1925 WL_ERROR("%s: conflicting bin/hdr\n",
1932 if (rc == 0 && wl->fw.fw_cnt != i) {
1933 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1940 * precondition: perimeter lock has been acquired
1942 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1944 bool blocked = wlc_check_radio_disabled(wl->wlc);
1946 WL_NONE("%s: update hw state: blocked=%s\n", __func__,
1947 blocked ? "true" : "false");
1949 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1951 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);