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/string.h>
22 #include <linux/pci_ids.h>
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/sched.h>
28 #define WLC_MAXBSSCFG 1 /* single BSS configs */
31 #include <net/mac80211.h>
32 #include <phy_version.h>
39 #include <wlc_channel.h>
43 #include <wl_export.h>
45 #include <wl_mac80211.h>
46 #include <linux/firmware.h>
48 #include <d11ucode_ext.h>
51 static void wl_timer(unsigned long data);
52 static void _wl_timer(wl_timer_t *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 int wl_start(struct sk_buff *skb, struct wl_info *wl);
78 static int wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw,
80 static void wl_dpc(unsigned long data);
82 MODULE_AUTHOR("Broadcom Corporation");
83 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
84 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
85 MODULE_LICENSE("Dual BSD/GPL");
87 /* recognized PCI IDs */
88 static struct pci_device_id wl_id_table[] = {
89 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
90 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
91 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
95 MODULE_DEVICE_TABLE(pci, wl_id_table);
96 static void wl_remove(struct pci_dev *pdev);
100 static int msglevel = 0xdeadbeef;
101 module_param(msglevel, int, 0);
102 static int phymsglevel = 0xdeadbeef;
103 module_param(phymsglevel, int, 0);
106 #define HW_TO_WL(hw) (hw->priv)
107 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
108 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
109 static int wl_ops_start(struct ieee80211_hw *hw);
110 static void wl_ops_stop(struct ieee80211_hw *hw);
111 static int wl_ops_add_interface(struct ieee80211_hw *hw,
112 struct ieee80211_vif *vif);
113 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
114 struct ieee80211_vif *vif);
115 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
116 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
117 struct ieee80211_vif *vif,
118 struct ieee80211_bss_conf *info,
120 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
121 unsigned int changed_flags,
122 unsigned int *total_flags, u64 multicast);
123 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
125 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
126 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
127 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
128 static int wl_ops_get_stats(struct ieee80211_hw *hw,
129 struct ieee80211_low_level_stats *stats);
130 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
131 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
132 struct ieee80211_vif *vif,
133 enum sta_notify_cmd cmd,
134 struct ieee80211_sta *sta);
135 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
136 const struct ieee80211_tx_queue_params *params);
137 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
138 static int wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
139 struct ieee80211_sta *sta);
140 static int wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
141 struct ieee80211_sta *sta);
142 static int wl_ops_ampdu_action(struct ieee80211_hw *hw,
143 struct ieee80211_vif *vif,
144 enum ieee80211_ampdu_mlme_action action,
145 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
146 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw);
148 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
151 struct wl_info *wl = hw->priv;
155 WL_ERROR("ops->tx called while down\n");
159 status = wl_start(skb, wl);
165 static int wl_ops_start(struct ieee80211_hw *hw)
167 struct wl_info *wl = hw->priv;
170 struct ieee80211_channel *curchan = hw->conf.channel;
171 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
175 ieee80211_wake_queues(hw);
177 blocked = wl_rfkill_set_hw_state(wl);
179 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
184 static void wl_ops_stop(struct ieee80211_hw *hw)
186 struct wl_info *wl = hw->priv;
189 ieee80211_stop_queues(hw);
194 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
199 /* Just STA for now */
200 if (vif->type != NL80211_IFTYPE_AP &&
201 vif->type != NL80211_IFTYPE_MESH_POINT &&
202 vif->type != NL80211_IFTYPE_STATION &&
203 vif->type != NL80211_IFTYPE_WDS &&
204 vif->type != NL80211_IFTYPE_ADHOC) {
205 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
206 __func__, vif->type);
216 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
222 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
228 /* put driver in down state */
235 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
236 enum nl80211_channel_type type)
238 struct wl_info *wl = HW_TO_WL(hw);
242 case NL80211_CHAN_HT20:
243 case NL80211_CHAN_NO_HT:
244 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
246 case NL80211_CHAN_HT40MINUS:
247 case NL80211_CHAN_HT40PLUS:
248 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
257 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
259 struct ieee80211_conf *conf = &hw->conf;
260 struct wl_info *wl = HW_TO_WL(hw);
265 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
267 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
268 WL_ERROR("%s: Error setting listen_interval\n",
273 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
274 ASSERT(new_int == conf->listen_interval);
276 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
277 WL_ERROR("%s: change monitor mode: %s (implement)\n", __func__,
278 conf->flags & IEEE80211_CONF_MONITOR ?
280 if (changed & IEEE80211_CONF_CHANGE_PS)
281 WL_ERROR("%s: change power-save mode: %s (implement)\n",
282 __func__, conf->flags & IEEE80211_CONF_PS ?
285 if (changed & IEEE80211_CONF_CHANGE_POWER) {
287 (wl->wlc, "qtxpower", conf->power_level * 4)) {
288 WL_ERROR("%s: Error setting power_level\n", __func__);
292 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
293 if (new_int != (conf->power_level * 4))
294 WL_ERROR("%s: Power level req != actual, %d %d\n",
295 __func__, conf->power_level * 4, new_int);
297 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
298 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
300 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
302 (wl->wlc, WLC_SET_SRL,
303 conf->short_frame_max_tx_count) < 0) {
304 WL_ERROR("%s: Error setting srl\n", __func__);
308 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
310 WL_ERROR("%s: Error setting lrl\n", __func__);
322 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
323 struct ieee80211_vif *vif,
324 struct ieee80211_bss_conf *info, u32 changed)
326 struct wl_info *wl = HW_TO_WL(hw);
329 if (changed & BSS_CHANGED_ASSOC) {
330 /* association status changed (associated/disassociated)
331 * also implies a change in the AID.
333 WL_ERROR("%s: %s: %sassociated\n", KBUILD_MODNAME, __func__,
334 info->assoc ? "" : "dis");
336 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
337 /* CTS protection changed */
338 WL_ERROR("%s: use_cts_prot: %s (implement)\n", __func__,
339 info->use_cts_prot ? "true" : "false");
341 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
342 /* preamble changed */
343 WL_ERROR("%s: short preamble: %s (implement)\n", __func__,
344 info->use_short_preamble ? "true" : "false");
346 if (changed & BSS_CHANGED_ERP_SLOT) {
347 /* slot timing changed */
348 if (info->use_short_slot)
352 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
355 if (changed & BSS_CHANGED_HT) {
356 /* 802.11n parameters changed */
357 u16 mode = info->ht_operation_mode;
358 WL_NONE("%s: HT mode: 0x%04X (implement)\n", __func__, mode);
360 if (changed & BSS_CHANGED_BASIC_RATES) {
361 /* Basic rateset changed */
362 WL_ERROR("%s: Need to change Basic Rates: 0x%x (implement)\n",
363 __func__, (u32) info->basic_rates);
365 if (changed & BSS_CHANGED_BEACON_INT) {
366 /* Beacon interval changed */
367 WL_NONE("%s: Beacon Interval: %d\n",
368 __func__, info->beacon_int);
370 if (changed & BSS_CHANGED_BSSID) {
371 /* BSSID changed, for whatever reason (IBSS and managed mode) */
372 WL_NONE("new BSSID:\taid %d bss:%pM\n",
373 info->aid, info->bssid);
374 /* FIXME: need to store bssid in bsscfg */
375 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
378 if (changed & BSS_CHANGED_BEACON) {
379 /* Beacon data changed, retrieve new beacon (beaconing modes) */
380 WL_ERROR("BSS_CHANGED_BEACON\n");
382 if (changed & BSS_CHANGED_BEACON_ENABLED) {
383 /* Beaconing should be enabled/disabled (beaconing modes) */
384 WL_ERROR("Beacon enabled: %s\n",
385 info->enable_beacon ? "true" : "false");
391 wl_ops_configure_filter(struct ieee80211_hw *hw,
392 unsigned int changed_flags,
393 unsigned int *total_flags, u64 multicast)
395 struct wl_info *wl = hw->priv;
397 changed_flags &= MAC_FILTERS;
398 *total_flags &= MAC_FILTERS;
399 if (changed_flags & FIF_PROMISC_IN_BSS)
400 WL_ERROR("FIF_PROMISC_IN_BSS\n");
401 if (changed_flags & FIF_ALLMULTI)
402 WL_ERROR("FIF_ALLMULTI\n");
403 if (changed_flags & FIF_FCSFAIL)
404 WL_ERROR("FIF_FCSFAIL\n");
405 if (changed_flags & FIF_PLCPFAIL)
406 WL_ERROR("FIF_PLCPFAIL\n");
407 if (changed_flags & FIF_CONTROL)
408 WL_ERROR("FIF_CONTROL\n");
409 if (changed_flags & FIF_OTHER_BSS)
410 WL_ERROR("FIF_OTHER_BSS\n");
411 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
412 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
414 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
415 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
416 wlc_mac_bcn_promisc_change(wl->wlc, 1);
418 wlc_mac_bcn_promisc_change(wl->wlc, 0);
419 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
427 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
429 WL_NONE("%s: Enter\n", __func__);
433 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
435 struct wl_info *wl = hw->priv;
436 WL_NONE("Scan Start\n");
438 wlc_scan_start(wl->wlc);
443 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
445 struct wl_info *wl = hw->priv;
446 WL_NONE("Scan Complete\n");
448 wlc_scan_stop(wl->wlc);
453 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
455 WL_ERROR("%s: Enter\n", __func__);
460 wl_ops_get_stats(struct ieee80211_hw *hw,
461 struct ieee80211_low_level_stats *stats)
463 WL_ERROR("%s: Enter\n", __func__);
467 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
469 struct wl_info *wl = hw->priv;
472 wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
478 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
479 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
481 WL_NONE("%s: Enter\n", __func__);
484 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
491 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
492 const struct ieee80211_tx_queue_params *params)
494 struct wl_info *wl = hw->priv;
496 WL_NONE("%s: Enter (WME config)\n", __func__);
497 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
498 params->txop, params->cw_min, params->cw_max, params->aifs);
501 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
507 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
509 WL_ERROR("%s: Enter\n", __func__);
514 wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
515 struct ieee80211_sta *sta)
520 struct wl_info *wl = hw->priv;
523 scb = (struct scb *)sta->drv_priv;
524 memset(scb, 0, sizeof(struct scb));
525 for (i = 0; i < NUMPRIO; i++)
526 scb->seqctl[i] = 0xFFFF;
527 scb->seqctl_nonqos = 0xFFFF;
528 scb->magic = SCB_MAGIC;
530 wl->pub->global_scb = scb;
531 wl->pub->global_ampdu = &(scb->scb_ampdu);
532 wl->pub->global_ampdu->scb = scb;
533 wl->pub->global_ampdu->max_pdu = 16;
534 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
535 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
537 sta->ht_cap.ht_supported = true;
538 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
539 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
540 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
541 IEEE80211_HT_CAP_SGI_20 |
542 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
544 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
549 wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
550 struct ieee80211_sta *sta)
552 WL_NONE("%s: Enter\n", __func__);
557 wl_ops_ampdu_action(struct ieee80211_hw *hw,
558 struct ieee80211_vif *vif,
559 enum ieee80211_ampdu_mlme_action action,
560 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
563 struct scb *scb = (struct scb *)sta->drv_priv;
565 struct wl_info *wl = hw->priv;
567 ASSERT(scb->magic == SCB_MAGIC);
569 case IEEE80211_AMPDU_RX_START:
570 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
572 case IEEE80211_AMPDU_RX_STOP:
573 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
575 case IEEE80211_AMPDU_TX_START:
576 if (!wlc_aggregatable(wl->wlc, tid)) {
577 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
580 /* XXX: Use the starting sequence number provided ... */
582 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
585 case IEEE80211_AMPDU_TX_STOP:
586 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
588 case IEEE80211_AMPDU_TX_OPERATIONAL:
589 /* Not sure what to do here */
590 /* Power save wakeup */
591 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
595 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
601 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
603 struct wl_info *wl = HW_TO_WL(hw);
607 blocked = wlc_check_radio_disabled(wl->wlc);
610 WL_NONE("wl: rfkill_poll: %d\n", blocked);
611 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
614 static const struct ieee80211_ops wl_ops = {
616 .start = wl_ops_start,
618 .add_interface = wl_ops_add_interface,
619 .remove_interface = wl_ops_remove_interface,
620 .config = wl_ops_config,
621 .bss_info_changed = wl_ops_bss_info_changed,
622 .configure_filter = wl_ops_configure_filter,
623 .set_tim = wl_ops_set_tim,
624 .sw_scan_start = wl_ops_sw_scan_start,
625 .sw_scan_complete = wl_ops_sw_scan_complete,
626 .set_tsf = wl_ops_set_tsf,
627 .get_stats = wl_ops_get_stats,
628 .set_rts_threshold = wl_ops_set_rts_threshold,
629 .sta_notify = wl_ops_sta_notify,
630 .conf_tx = wl_ops_conf_tx,
631 .get_tsf = wl_ops_get_tsf,
632 .sta_add = wl_ops_sta_add,
633 .sta_remove = wl_ops_sta_remove,
634 .ampdu_action = wl_ops_ampdu_action,
635 .rfkill_poll = wl_ops_rfkill_poll,
638 static int wl_set_hint(struct wl_info *wl, char *abbrev)
640 WL_NONE("%s: Sending country code %c%c to MAC80211\n",
641 __func__, abbrev[0], abbrev[1]);
642 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
646 * attach to the WL device.
648 * Attach to the WL device identified by vendor and device parameters.
649 * regs is a host accessible memory address pointing to WL device registers.
651 * wl_attach is not defined as static because in the case where no bus
652 * is defined, wl_attach will never be called, and thus, gcc will issue
653 * a warning that this function is defined but not used if we declare
656 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
657 uint bustype, void *btparam, uint irq)
660 struct osl_info *osh;
663 unsigned long base_addr;
664 struct ieee80211_hw *hw;
671 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
675 osh = osl_attach(btparam, bustype);
678 /* allocate private info */
679 hw = pci_get_drvdata(btparam); /* btparam == pdev */
684 atomic_set(&wl->callbacks, 0);
686 /* setup the bottom half handler */
687 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
693 if (bustype == PCI_BUS) {
695 } else if (bustype == RPC_BUS) {
699 WL_TRACE("force to PCI\n");
701 wl->bcm_bustype = bustype;
703 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
704 if (wl->regsva == NULL) {
705 WL_ERROR("wl%d: ioremap() failed\n", unit);
708 spin_lock_init(&wl->lock);
709 spin_lock_init(&wl->isr_lock);
712 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
713 printf("%s: Failed to find firmware usually in %s\n",
714 KBUILD_MODNAME, "/lib/firmware/brcm");
716 wl_remove((struct pci_dev *)btparam);
720 /* common load-time initialization */
721 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
722 wl->regsva, wl->bcm_bustype, btparam, &err);
725 printf("%s: wlc_attach() failed with code %d\n",
726 KBUILD_MODNAME, err);
729 wl->pub = wlc_pub(wl->wlc);
731 wl->pub->ieee_hw = hw;
732 ASSERT(wl->pub->ieee_hw);
733 ASSERT(wl->pub->ieee_hw->priv == wl);
736 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
737 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
740 /* register our interrupt handler */
741 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
742 WL_ERROR("wl%d: request_irq() failed\n", unit);
747 /* register module */
748 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
751 if (ieee_hw_init(hw)) {
752 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
756 bcopy(&wl->pub->cur_etheraddr, perm, ETH_ALEN);
757 ASSERT(is_valid_ether_addr(perm));
758 SET_IEEE80211_PERM_ADDR(hw, perm);
760 err = ieee80211_register_hw(hw);
762 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
766 if (wl->pub->srom_ccode[0])
767 err = wl_set_hint(wl, wl->pub->srom_ccode);
769 err = wl_set_hint(wl, "US");
771 WL_ERROR("%s: regulatory_hint failed, status %d\n",
786 #define CHAN2GHZ(channel, freqency, chflags) { \
787 .band = IEEE80211_BAND_2GHZ, \
788 .center_freq = (freqency), \
789 .hw_value = (channel), \
791 .max_antenna_gain = 0, \
795 static struct ieee80211_channel wl_2ghz_chantable[] = {
796 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
797 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
798 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
799 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
800 CHAN2GHZ(5, 2432, 0),
801 CHAN2GHZ(6, 2437, 0),
802 CHAN2GHZ(7, 2442, 0),
803 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
804 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
805 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
806 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
808 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
809 IEEE80211_CHAN_NO_HT40PLUS),
811 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
812 IEEE80211_CHAN_NO_HT40PLUS),
814 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
815 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
818 #define CHAN5GHZ(channel, chflags) { \
819 .band = IEEE80211_BAND_5GHZ, \
820 .center_freq = 5000 + 5*(channel), \
821 .hw_value = (channel), \
823 .max_antenna_gain = 0, \
827 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
829 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
830 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
831 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
832 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
835 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
836 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
838 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
839 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
841 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
842 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
844 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
845 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
848 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
849 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
851 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
852 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
854 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
855 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
857 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
858 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
860 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
861 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
863 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
864 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
866 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
867 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
869 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
870 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
872 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
873 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
875 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
876 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
878 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
879 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
880 IEEE80211_CHAN_NO_HT40MINUS),
882 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
883 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
884 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
885 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
886 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
889 #define RATE(rate100m, _flags) { \
890 .bitrate = (rate100m), \
892 .hw_value = (rate100m / 5), \
895 static struct ieee80211_rate wl_legacy_ratetable[] = {
897 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
898 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
899 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
910 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
911 .band = IEEE80211_BAND_2GHZ,
912 .channels = wl_2ghz_chantable,
913 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
914 .bitrates = wl_legacy_ratetable,
915 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
917 /* from include/linux/ieee80211.h */
918 .cap = IEEE80211_HT_CAP_GRN_FLD |
919 IEEE80211_HT_CAP_SGI_20 |
920 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
921 .ht_supported = true,
922 .ampdu_factor = AMPDU_RX_FACTOR_64K,
923 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
925 /* placeholders for now */
926 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
928 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
932 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
933 .band = IEEE80211_BAND_5GHZ,
934 .channels = wl_5ghz_nphy_chantable,
935 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
936 .bitrates = wl_legacy_ratetable + 4,
937 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
939 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
940 .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 */
941 .ht_supported = true,
942 .ampdu_factor = AMPDU_RX_FACTOR_64K,
943 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
945 /* placeholders for now */
946 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
948 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
952 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
954 struct wl_info *wl = HW_TO_WL(hw);
960 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
961 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
963 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
964 WL_ERROR("Phy list failed\n");
966 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
968 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
969 if (phy_list[0] == 'c') {
971 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
972 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
974 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
980 /* Assume all bands use the same phy. True for 11n devices. */
981 if (NBANDS_PUB(wl->pub) > 1) {
983 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
984 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
991 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
996 static int ieee_hw_init(struct ieee80211_hw *hw)
998 hw->flags = IEEE80211_HW_SIGNAL_DBM
999 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1000 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1001 | IEEE80211_HW_AMPDU_AGGREGATION;
1003 hw->extra_tx_headroom = wlc_get_header_len();
1004 /* FIXME: should get this from wlc->machwcap */
1006 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1007 * mac80211/status.c:ieee80211_tx_status() checks this value,
1008 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1009 * appears to always set 3 rates
1011 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1013 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1014 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1016 hw->rate_control_algorithm = "minstrel_ht";
1018 hw->sta_data_size = sizeof(struct scb);
1019 return ieee_hw_rate_init(hw);
1023 * determines if a device is a WL device, and if so, attaches it.
1025 * This function determines if a device pointed to by pdev is a WL device,
1026 * and if so, performs a wl_attach() on it.
1030 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1034 struct ieee80211_hw *hw;
1039 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1040 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1041 PCI_FUNC(pdev->devfn), pdev->irq);
1043 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1044 (((pdev->device & 0xff00) != 0x4300) &&
1045 ((pdev->device & 0xff00) != 0x4700) &&
1046 ((pdev->device < 43000) || (pdev->device > 43999))))
1049 rc = pci_enable_device(pdev);
1051 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1052 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1053 PCI_FUNC(pdev->devfn));
1056 pci_set_master(pdev);
1058 pci_read_config_dword(pdev, 0x40, &val);
1059 if ((val & 0x0000ff00) != 0)
1060 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1062 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1064 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1069 SET_IEEE80211_DEV(hw, &pdev->dev);
1071 pci_set_drvdata(pdev, hw);
1073 memset(hw->priv, 0, sizeof(*wl));
1075 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1076 PCI_BUS, pdev, pdev->irq);
1079 WL_ERROR("%s: %s: wl_attach failed!\n",
1080 KBUILD_MODNAME, __func__);
1085 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1089 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1092 struct ieee80211_hw *hw;
1094 WL_TRACE("wl: wl_suspend\n");
1096 hw = pci_get_drvdata(pdev);
1099 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1103 /* only need to flag hw is down for proper resume */
1105 wl->pub->hw_up = false;
1108 pci_save_state(pdev);
1109 pci_disable_device(pdev);
1110 return pci_set_power_state(pdev, PCI_D3hot);
1113 static int wl_resume(struct pci_dev *pdev)
1116 struct ieee80211_hw *hw;
1120 WL_TRACE("wl: wl_resume\n");
1121 hw = pci_get_drvdata(pdev);
1124 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1128 err = pci_set_power_state(pdev, PCI_D0);
1132 pci_restore_state(pdev);
1134 err = pci_enable_device(pdev);
1138 pci_set_master(pdev);
1140 pci_read_config_dword(pdev, 0x40, &val);
1141 if ((val & 0x0000ff00) != 0)
1142 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1145 * done. driver will be put in up state
1146 * in wl_ops_add_interface() call.
1151 static void wl_remove(struct pci_dev *pdev)
1154 struct ieee80211_hw *hw;
1156 hw = pci_get_drvdata(pdev);
1159 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1163 /* make sure rfkill is not using driver */
1164 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1165 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1167 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1168 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1172 ieee80211_unregister_hw(hw);
1176 WL_NONE("%s: Down\n", __func__);
1178 pci_disable_device(pdev);
1182 pci_set_drvdata(pdev, NULL);
1183 ieee80211_free_hw(hw);
1186 static struct pci_driver wl_pci_driver = {
1187 .name = KBUILD_MODNAME,
1188 .probe = wl_pci_probe,
1189 .suspend = wl_suspend,
1190 .resume = wl_resume,
1191 .remove = __devexit_p(wl_remove),
1192 .id_table = wl_id_table,
1196 * This is the main entry point for the WL driver.
1198 * This function determines if a device pointed to by pdev is a WL device,
1199 * and if so, performs a wl_attach() on it.
1202 static int __init wl_module_init(void)
1204 int error = -ENODEV;
1207 if (msglevel != 0xdeadbeef)
1208 wl_msg_level = msglevel;
1210 char *var = getvar(NULL, "wl_msglevel");
1212 wl_msg_level = simple_strtoul(var, NULL, 0);
1215 extern u32 phyhal_msg_level;
1217 if (phymsglevel != 0xdeadbeef)
1218 phyhal_msg_level = phymsglevel;
1220 char *var = getvar(NULL, "phy_msglevel");
1222 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1227 error = pci_register_driver(&wl_pci_driver);
1237 * This function unloads the WL driver from the system.
1239 * This function unconditionally unloads the WL driver module from the
1243 static void __exit wl_module_exit(void)
1245 pci_unregister_driver(&wl_pci_driver);
1249 module_init(wl_module_init);
1250 module_exit(wl_module_exit);
1253 * This function frees the WL per-device resources.
1255 * This function frees resources owned by the WL device pointed to
1256 * by the wl parameter.
1259 void wl_free(struct wl_info *wl)
1261 wl_timer_t *t, *next;
1262 struct osl_info *osh;
1265 /* free ucode data */
1267 wl_ucode_data_free();
1269 free_irq(wl->irq, wl);
1272 tasklet_kill(&wl->tasklet);
1275 wlc_module_unregister(wl->pub, "linux", wl);
1278 /* free common resources */
1280 wlc_detach(wl->wlc);
1285 /* virtual interface deletion is deferred so we cannot spinwait */
1287 /* wait for all pending callbacks to complete */
1288 while (atomic_read(&wl->callbacks) > 0)
1292 for (t = wl->timers; t; t = next) {
1304 * unregister_netdev() calls get_stats() which may read chip registers
1305 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1307 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1308 wl->bcm_bustype != JTAG_BUS) {
1309 iounmap((void *)wl->regsva);
1317 /* transmit a packet */
1318 static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1323 return wl_start_int(wl, WL_TO_HW(wl), skb);
1326 static int BCMFASTPATH
1327 wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1329 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1330 return NETDEV_TX_OK;
1333 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1336 WL_ERROR("Shouldn't be here %s\n", __func__);
1339 void wl_init(struct wl_info *wl)
1341 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1348 uint wl_reset(struct wl_info *wl)
1350 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1354 /* dpc will not be rescheduled */
1361 * These are interrupt on/off entry points. Disable interrupts
1362 * during interrupt state transition.
1364 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1366 unsigned long flags;
1368 INT_LOCK(wl, flags);
1369 wlc_intrson(wl->wlc);
1370 INT_UNLOCK(wl, flags);
1373 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1378 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1380 unsigned long flags;
1383 INT_LOCK(wl, flags);
1384 status = wlc_intrsoff(wl->wlc);
1385 INT_UNLOCK(wl, flags);
1389 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1391 unsigned long flags;
1393 INT_LOCK(wl, flags);
1394 wlc_intrsrestore(wl->wlc, macintmask);
1395 INT_UNLOCK(wl, flags);
1398 int wl_up(struct wl_info *wl)
1405 error = wlc_up(wl->wlc);
1410 void wl_down(struct wl_info *wl)
1412 uint callbacks, ret_val = 0;
1414 /* call common down function */
1415 ret_val = wlc_down(wl->wlc);
1416 callbacks = atomic_read(&wl->callbacks) - ret_val;
1418 /* wait for down callbacks to complete */
1421 /* For HIGH_only driver, it's important to actually schedule other work,
1422 * not just spin wait since everything runs at schedule level
1424 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1429 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1433 unsigned long flags;
1435 wl = (struct wl_info *) dev_id;
1437 WL_ISRLOCK(wl, flags);
1439 /* call common first level interrupt handler */
1440 ours = wlc_isr(wl->wlc, &wantdpc);
1442 /* if more to do... */
1445 /* ...and call the second level interrupt handler */
1447 ASSERT(wl->resched == false);
1448 tasklet_schedule(&wl->tasklet);
1452 WL_ISRUNLOCK(wl, flags);
1454 return IRQ_RETVAL(ours);
1457 static void BCMFASTPATH wl_dpc(unsigned long data)
1461 wl = (struct wl_info *) data;
1465 /* call the common second level interrupt handler */
1468 unsigned long flags;
1470 INT_LOCK(wl, flags);
1471 wlc_intrsupd(wl->wlc);
1472 INT_UNLOCK(wl, flags);
1475 wl->resched = wlc_dpc(wl->wlc, true);
1478 /* wlc_dpc() may bring the driver down */
1482 /* re-schedule dpc */
1484 tasklet_schedule(&wl->tasklet);
1486 /* re-enable interrupts */
1494 static void wl_link_up(struct wl_info *wl, char *ifname)
1496 WL_NONE("wl%d: link up (%s)\n", wl->pub->unit, ifname);
1499 static void wl_link_down(struct wl_info *wl, char *ifname)
1501 WL_NONE("wl%d: link down (%s)\n", wl->pub->unit, ifname);
1504 void wl_event(struct wl_info *wl, char *ifname, wlc_event_t *e)
1507 switch (e->event.event_type) {
1509 case WLC_E_NDIS_LINK:
1510 if (e->event.flags & WLC_EVENT_MSG_LINK)
1511 wl_link_up(wl, ifname);
1513 wl_link_down(wl, ifname);
1520 static void wl_timer(unsigned long data)
1522 _wl_timer((wl_timer_t *) data);
1525 static void _wl_timer(wl_timer_t *t)
1531 t->timer.expires = jiffies + t->ms * HZ / 1000;
1532 atomic_inc(&t->wl->callbacks);
1533 add_timer(&t->timer);
1541 atomic_dec(&t->wl->callbacks);
1546 wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
1551 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
1553 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1557 memset(t, 0, sizeof(wl_timer_t));
1559 init_timer(&t->timer);
1560 t->timer.data = (unsigned long) t;
1561 t->timer.function = wl_timer;
1565 t->next = wl->timers;
1569 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1571 strcpy(t->name, name);
1577 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1578 * as well as it's easier to make it periodic
1580 void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
1584 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1585 __func__, t->name, periodic);
1591 t->periodic = (bool) periodic;
1593 t->timer.expires = jiffies + ms * HZ / 1000;
1595 atomic_inc(&wl->callbacks);
1596 add_timer(&t->timer);
1599 /* return true if timer successfully deleted, false if still pending */
1600 bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
1604 if (!del_timer(&t->timer)) {
1607 atomic_dec(&wl->callbacks);
1613 void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
1617 /* delete the timer in case it is active */
1618 wl_del_timer(wl, t);
1620 if (wl->timers == t) {
1621 wl->timers = wl->timers->next;
1633 if (tmp->next == t) {
1634 tmp->next = t->next;
1647 static int wl_linux_watchdog(void *ctx)
1649 struct wl_info *wl = (struct wl_info *) ctx;
1650 struct net_device_stats *stats = NULL;
1654 ASSERT(wl->stats_id < 2);
1656 id = 1 - wl->stats_id;
1658 stats = &wl->stats_watchdog[id];
1659 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
1660 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
1661 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
1662 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
1663 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
1664 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
1665 stats->collisions = 0;
1667 stats->rx_length_errors = 0;
1668 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1669 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
1670 stats->rx_frame_errors = 0;
1671 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1672 stats->rx_missed_errors = 0;
1674 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
1689 char *wl_firmwares[WL_MAX_FW] = {
1694 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1698 struct wl_fw_hdr *hdr;
1699 for (i = 0; i < wl->fw.fw_cnt; i++) {
1700 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1701 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1703 if (hdr->idx == idx) {
1704 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1705 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1706 if (*pbuf == NULL) {
1707 printf("fail to alloc %d bytes\n",
1710 bcopy(pdata, *pbuf, hdr->len);
1715 printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
1720 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1724 struct wl_fw_hdr *hdr;
1725 for (i = 0; i < wl->fw.fw_cnt; i++) {
1726 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1727 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1729 if (hdr->idx == idx) {
1730 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1731 ASSERT(hdr->len == 4);
1732 *data = *((u32 *) pdata);
1737 printf("ERROR: ucode tag:%d can not be found!\n", idx);
1741 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1744 struct device *device = &pdev->dev;
1748 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1749 for (i = 0; i < WL_MAX_FW; i++) {
1750 if (wl_firmwares[i] == NULL)
1752 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1753 UCODE_LOADER_API_VER);
1754 WL_NONE("request fw %s\n", fw_name);
1755 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1757 printf("%s: fail to load firmware %s\n",
1758 KBUILD_MODNAME, fw_name);
1762 WL_NONE("request fw %s\n", fw_name);
1763 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1764 UCODE_LOADER_API_VER);
1765 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1767 printf("%s: fail to load firmware %s\n",
1768 KBUILD_MODNAME, fw_name);
1772 wl->fw.hdr_num_entries[i] =
1773 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1774 WL_NONE("request fw %s find: %d entries\n",
1775 fw_name, wl->fw.hdr_num_entries[i]);
1778 return wl_ucode_data_init(wl);
1781 void wl_ucode_free_buf(void *p)
1786 static void wl_release_fw(struct wl_info *wl)
1789 for (i = 0; i < WL_MAX_FW; i++) {
1790 release_firmware(wl->fw.fw_bin[i]);
1791 release_firmware(wl->fw.fw_hdr[i]);
1797 * checks validity of all firmware images loaded from user space
1799 int wl_check_firmwares(struct wl_info *wl)
1804 const struct firmware *fw;
1805 const struct firmware *fw_hdr;
1806 struct wl_fw_hdr *ucode_hdr;
1807 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1808 fw = wl->fw.fw_bin[i];
1809 fw_hdr = wl->fw.fw_hdr[i];
1810 if (fw == NULL && fw_hdr == NULL) {
1812 } else if (fw == NULL || fw_hdr == NULL) {
1813 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1815 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1816 WL_ERROR("%s: non integral fw hdr file size %d/%zu\n",
1817 __func__, fw_hdr->size,
1818 sizeof(struct wl_fw_hdr));
1820 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1821 WL_ERROR("%s: out of bounds fw file size %d\n",
1822 __func__, fw->size);
1825 /* check if ucode section overruns firmware image */
1826 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1827 for (entry = 0; entry < wl->fw.hdr_num_entries[i] && rc;
1828 entry++, ucode_hdr++) {
1829 if (ucode_hdr->offset + ucode_hdr->len >
1831 WL_ERROR("%s: conflicting bin/hdr\n",
1838 if (rc == 0 && wl->fw.fw_cnt != i) {
1839 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1845 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1847 bool blocked = wlc_check_radio_disabled(wl->wlc);
1849 WL_NONE("%s: update hw state: blocked=%s\n", __func__,
1850 blocked ? "true" : "false");
1851 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1853 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);