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);
174 ieee80211_wake_queues(hw);
176 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)
187 struct wl_info *wl = hw->priv;
190 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 * precondition: perimeter lock has been acquired
238 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
239 enum nl80211_channel_type type)
241 struct wl_info *wl = HW_TO_WL(hw);
245 case NL80211_CHAN_HT20:
246 case NL80211_CHAN_NO_HT:
247 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
249 case NL80211_CHAN_HT40MINUS:
250 case NL80211_CHAN_HT40PLUS:
251 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
261 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
263 struct ieee80211_conf *conf = &hw->conf;
264 struct wl_info *wl = HW_TO_WL(hw);
269 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
271 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
272 WL_ERROR("%s: Error setting listen_interval\n",
277 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
278 ASSERT(new_int == conf->listen_interval);
280 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
281 WL_ERROR("%s: change monitor mode: %s (implement)\n", __func__,
282 conf->flags & IEEE80211_CONF_MONITOR ?
284 if (changed & IEEE80211_CONF_CHANGE_PS)
285 WL_ERROR("%s: change power-save mode: %s (implement)\n",
286 __func__, conf->flags & IEEE80211_CONF_PS ?
289 if (changed & IEEE80211_CONF_CHANGE_POWER) {
291 (wl->wlc, "qtxpower", conf->power_level * 4)) {
292 WL_ERROR("%s: Error setting power_level\n", __func__);
296 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
297 if (new_int != (conf->power_level * 4))
298 WL_ERROR("%s: Power level req != actual, %d %d\n",
299 __func__, conf->power_level * 4, new_int);
301 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
302 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
304 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
306 (wl->wlc, WLC_SET_SRL,
307 conf->short_frame_max_tx_count) < 0) {
308 WL_ERROR("%s: Error setting srl\n", __func__);
312 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
314 WL_ERROR("%s: Error setting lrl\n", __func__);
326 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
327 struct ieee80211_vif *vif,
328 struct ieee80211_bss_conf *info, u32 changed)
330 struct wl_info *wl = HW_TO_WL(hw);
333 if (changed & BSS_CHANGED_ASSOC) {
334 /* association status changed (associated/disassociated)
335 * also implies a change in the AID.
337 WL_ERROR("%s: %s: %sassociated\n", KBUILD_MODNAME, __func__,
338 info->assoc ? "" : "dis");
339 wlc_associate_upd(wl->wlc, info->assoc);
341 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
342 /* CTS protection changed */
343 WL_ERROR("%s: use_cts_prot: %s (implement)\n", __func__,
344 info->use_cts_prot ? "true" : "false");
346 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
347 /* preamble changed */
348 WL_ERROR("%s: short preamble: %s (implement)\n", __func__,
349 info->use_short_preamble ? "true" : "false");
351 if (changed & BSS_CHANGED_ERP_SLOT) {
352 /* slot timing changed */
353 if (info->use_short_slot)
358 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
362 if (changed & BSS_CHANGED_HT) {
363 /* 802.11n parameters changed */
364 u16 mode = info->ht_operation_mode;
365 WL_NONE("%s: HT mode: 0x%04X\n", __func__, mode);
366 wlc_protection_upd(wl->wlc, WLC_PROT_N_CFG,
367 mode & IEEE80211_HT_OP_MODE_PROTECTION);
368 wlc_protection_upd(wl->wlc, WLC_PROT_N_NONGF,
369 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
370 wlc_protection_upd(wl->wlc, WLC_PROT_N_OBSS,
371 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
373 if (changed & BSS_CHANGED_BASIC_RATES) {
374 /* Basic rateset changed */
375 WL_ERROR("%s: Need to change Basic Rates: 0x%x (implement)\n",
376 __func__, (u32) info->basic_rates);
378 if (changed & BSS_CHANGED_BEACON_INT) {
379 /* Beacon interval changed */
380 WL_NONE("%s: Beacon Interval: %d\n",
381 __func__, info->beacon_int);
382 wlc_set(wl->wlc, WLC_SET_BCNPRD, info->beacon_int);
384 if (changed & BSS_CHANGED_BSSID) {
385 /* BSSID changed, for whatever reason (IBSS and managed mode) */
386 WL_NONE("%s: new BSSID: aid %d bss:%pM\n", __func__,
387 info->aid, info->bssid);
389 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
393 if (changed & BSS_CHANGED_BEACON) {
394 /* Beacon data changed, retrieve new beacon (beaconing modes) */
395 WL_ERROR("%s: beacon changed\n", __func__);
397 if (changed & BSS_CHANGED_BEACON_ENABLED) {
398 /* Beaconing should be enabled/disabled (beaconing modes) */
399 WL_ERROR("%s: Beacon enabled: %s\n", __func__,
400 info->enable_beacon ? "true" : "false");
402 if (changed & BSS_CHANGED_CQM) {
403 /* Connection quality monitor config changed */
404 WL_ERROR("%s: cqm change: threshold %d, hys %d (implement)\n",
405 __func__, info->cqm_rssi_thold, info->cqm_rssi_hyst);
407 if (changed & BSS_CHANGED_IBSS) {
408 /* IBSS join status changed */
409 WL_ERROR("%s: IBSS joined: %s (implement)\n", __func__,
410 info->ibss_joined ? "true" : "false");
412 if (changed & BSS_CHANGED_ARP_FILTER) {
413 /* Hardware ARP filter address list or state changed */
414 WL_ERROR("%s: arp filtering: enabled %s, count %d (implement)\n",
415 __func__, info->arp_filter_enabled ? "true" : "false",
418 if (changed & BSS_CHANGED_QOS) {
420 * QoS for this association was enabled/disabled.
421 * Note that it is only ever disabled for station mode.
423 WL_ERROR("%s: qos enabled: %s (implement)\n", __func__,
424 info->qos ? "true" : "false");
426 if (changed & BSS_CHANGED_IDLE) {
427 /* Idle changed for this BSS/interface */
428 WL_ERROR("%s: BSS idle: %s (implement)\n", __func__,
429 info->idle ? "true" : "false");
435 wl_ops_configure_filter(struct ieee80211_hw *hw,
436 unsigned int changed_flags,
437 unsigned int *total_flags, u64 multicast)
439 struct wl_info *wl = hw->priv;
441 changed_flags &= MAC_FILTERS;
442 *total_flags &= MAC_FILTERS;
443 if (changed_flags & FIF_PROMISC_IN_BSS)
444 WL_ERROR("FIF_PROMISC_IN_BSS\n");
445 if (changed_flags & FIF_ALLMULTI)
446 WL_ERROR("FIF_ALLMULTI\n");
447 if (changed_flags & FIF_FCSFAIL)
448 WL_ERROR("FIF_FCSFAIL\n");
449 if (changed_flags & FIF_PLCPFAIL)
450 WL_ERROR("FIF_PLCPFAIL\n");
451 if (changed_flags & FIF_CONTROL)
452 WL_ERROR("FIF_CONTROL\n");
453 if (changed_flags & FIF_OTHER_BSS)
454 WL_ERROR("FIF_OTHER_BSS\n");
455 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
456 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
458 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
459 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
460 wlc_mac_bcn_promisc_change(wl->wlc, 1);
462 wlc_mac_bcn_promisc_change(wl->wlc, 0);
463 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
471 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
473 WL_NONE("%s: Enter\n", __func__);
477 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
479 struct wl_info *wl = hw->priv;
480 WL_NONE("Scan Start\n");
482 wlc_scan_start(wl->wlc);
487 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
489 struct wl_info *wl = hw->priv;
490 WL_NONE("Scan Complete\n");
492 wlc_scan_stop(wl->wlc);
497 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
499 WL_ERROR("%s: Enter\n", __func__);
504 wl_ops_get_stats(struct ieee80211_hw *hw,
505 struct ieee80211_low_level_stats *stats)
507 struct wl_info *wl = hw->priv;
512 stats->dot11ACKFailureCount = cnt->txnoack;
513 stats->dot11RTSFailureCount = cnt->txnocts;
514 stats->dot11FCSErrorCount = cnt->rxcrc;
515 stats->dot11RTSSuccessCount = cnt->txrts;
520 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
522 struct wl_info *wl = hw->priv;
525 wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
531 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
532 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
534 WL_NONE("%s: Enter\n", __func__);
537 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
544 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
545 const struct ieee80211_tx_queue_params *params)
547 struct wl_info *wl = hw->priv;
549 WL_NONE("%s: Enter (WME config)\n", __func__);
550 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
551 params->txop, params->cw_min, params->cw_max, params->aifs);
554 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
560 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
562 WL_ERROR("%s: Enter\n", __func__);
567 wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
568 struct ieee80211_sta *sta)
573 struct wl_info *wl = hw->priv;
576 scb = (struct scb *)sta->drv_priv;
577 memset(scb, 0, sizeof(struct scb));
578 for (i = 0; i < NUMPRIO; i++)
579 scb->seqctl[i] = 0xFFFF;
580 scb->seqctl_nonqos = 0xFFFF;
581 scb->magic = SCB_MAGIC;
583 wl->pub->global_scb = scb;
584 wl->pub->global_ampdu = &(scb->scb_ampdu);
585 wl->pub->global_ampdu->scb = scb;
586 wl->pub->global_ampdu->max_pdu = 16;
587 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
588 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
590 sta->ht_cap.ht_supported = true;
591 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
592 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
593 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
594 IEEE80211_HT_CAP_SGI_20 |
595 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
597 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
602 wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
603 struct ieee80211_sta *sta)
605 WL_NONE("%s: Enter\n", __func__);
610 wl_ops_ampdu_action(struct ieee80211_hw *hw,
611 struct ieee80211_vif *vif,
612 enum ieee80211_ampdu_mlme_action action,
613 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
616 struct scb *scb = (struct scb *)sta->drv_priv;
618 struct wl_info *wl = hw->priv;
621 ASSERT(scb->magic == SCB_MAGIC);
623 case IEEE80211_AMPDU_RX_START:
624 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
626 case IEEE80211_AMPDU_RX_STOP:
627 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
629 case IEEE80211_AMPDU_TX_START:
631 status = wlc_aggregatable(wl->wlc, tid);
634 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
637 /* XXX: Use the starting sequence number provided ... */
639 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
642 case IEEE80211_AMPDU_TX_STOP:
643 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
645 case IEEE80211_AMPDU_TX_OPERATIONAL:
646 /* Not sure what to do here */
647 /* Power save wakeup */
648 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
652 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
658 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
660 struct wl_info *wl = HW_TO_WL(hw);
664 blocked = wlc_check_radio_disabled(wl->wlc);
667 WL_NONE("wl: rfkill_poll: %d\n", blocked);
668 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
671 static const struct ieee80211_ops wl_ops = {
673 .start = wl_ops_start,
675 .add_interface = wl_ops_add_interface,
676 .remove_interface = wl_ops_remove_interface,
677 .config = wl_ops_config,
678 .bss_info_changed = wl_ops_bss_info_changed,
679 .configure_filter = wl_ops_configure_filter,
680 .set_tim = wl_ops_set_tim,
681 .sw_scan_start = wl_ops_sw_scan_start,
682 .sw_scan_complete = wl_ops_sw_scan_complete,
683 .set_tsf = wl_ops_set_tsf,
684 .get_stats = wl_ops_get_stats,
685 .set_rts_threshold = wl_ops_set_rts_threshold,
686 .sta_notify = wl_ops_sta_notify,
687 .conf_tx = wl_ops_conf_tx,
688 .get_tsf = wl_ops_get_tsf,
689 .sta_add = wl_ops_sta_add,
690 .sta_remove = wl_ops_sta_remove,
691 .ampdu_action = wl_ops_ampdu_action,
692 .rfkill_poll = wl_ops_rfkill_poll,
696 * is called in wl_pci_probe() context, therefore no locking required.
698 static int wl_set_hint(struct wl_info *wl, char *abbrev)
700 WL_NONE("%s: Sending country code %c%c to MAC80211\n",
701 __func__, abbrev[0], abbrev[1]);
702 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
706 * attach to the WL device.
708 * Attach to the WL device identified by vendor and device parameters.
709 * regs is a host accessible memory address pointing to WL device registers.
711 * wl_attach is not defined as static because in the case where no bus
712 * is defined, wl_attach will never be called, and thus, gcc will issue
713 * a warning that this function is defined but not used if we declare
717 * is called in wl_pci_probe() context, therefore no locking required.
719 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
720 uint bustype, void *btparam, uint irq)
723 struct osl_info *osh;
726 unsigned long base_addr;
727 struct ieee80211_hw *hw;
734 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
738 osh = osl_attach(btparam, bustype);
741 /* allocate private info */
742 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, osh,
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 = AMPDU_RX_FACTOR_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 = AMPDU_RX_FACTOR_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 dependant 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.
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 wl_msg_level = simple_strtoul(var, NULL, 0);
1291 extern u32 phyhal_msg_level;
1293 if (phymsglevel != 0xdeadbeef)
1294 phyhal_msg_level = phymsglevel;
1296 char *var = getvar(NULL, "phy_msglevel");
1298 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1303 error = pci_register_driver(&wl_pci_driver);
1313 * This function unloads the WL driver from the system.
1315 * This function unconditionally unloads the WL driver module from the
1319 static void __exit wl_module_exit(void)
1321 pci_unregister_driver(&wl_pci_driver);
1325 module_init(wl_module_init);
1326 module_exit(wl_module_exit);
1329 * This function frees the WL per-device resources.
1331 * This function frees resources owned by the WL device pointed to
1332 * by the wl parameter.
1334 * precondition: can both be called locked and unlocked
1337 void wl_free(struct wl_info *wl)
1339 wl_timer_t *t, *next;
1340 struct osl_info *osh;
1343 /* free ucode data */
1345 wl_ucode_data_free();
1347 free_irq(wl->irq, wl);
1350 tasklet_kill(&wl->tasklet);
1353 wlc_module_unregister(wl->pub, "linux", wl);
1356 /* free common resources */
1358 wlc_detach(wl->wlc);
1363 /* virtual interface deletion is deferred so we cannot spinwait */
1365 /* wait for all pending callbacks to complete */
1366 while (atomic_read(&wl->callbacks) > 0)
1370 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);
1397 * precondition: perimeter lock has been acquired
1399 static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1404 return wl_start_int(wl, WL_TO_HW(wl), skb);
1407 static int BCMFASTPATH
1408 wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1410 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1411 return NETDEV_TX_OK;
1415 * precondition: perimeter lock has been acquired
1417 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1420 WL_ERROR("Shouldn't be here %s\n", __func__);
1424 * precondition: perimeter lock has been acquired
1426 void wl_init(struct wl_info *wl)
1428 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1436 * precondition: perimeter lock has been acquired
1438 uint wl_reset(struct wl_info *wl)
1440 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1444 /* dpc will not be rescheduled */
1451 * These are interrupt on/off entry points. Disable interrupts
1452 * during interrupt state transition.
1454 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1456 unsigned long flags;
1458 INT_LOCK(wl, flags);
1459 wlc_intrson(wl->wlc);
1460 INT_UNLOCK(wl, flags);
1464 * precondition: perimeter lock has been acquired
1466 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1471 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1473 unsigned long flags;
1476 INT_LOCK(wl, flags);
1477 status = wlc_intrsoff(wl->wlc);
1478 INT_UNLOCK(wl, flags);
1482 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1484 unsigned long flags;
1486 INT_LOCK(wl, flags);
1487 wlc_intrsrestore(wl->wlc, macintmask);
1488 INT_UNLOCK(wl, flags);
1492 * precondition: perimeter lock has been acquired
1494 int wl_up(struct wl_info *wl)
1501 error = wlc_up(wl->wlc);
1507 * precondition: perimeter lock has been acquired
1509 void wl_down(struct wl_info *wl)
1511 uint callbacks, ret_val = 0;
1513 /* call common down function */
1514 ret_val = wlc_down(wl->wlc);
1515 callbacks = atomic_read(&wl->callbacks) - ret_val;
1517 /* wait for down callbacks to complete */
1520 /* For HIGH_only driver, it's important to actually schedule other work,
1521 * not just spin wait since everything runs at schedule level
1523 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1528 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1532 unsigned long flags;
1534 wl = (struct wl_info *) dev_id;
1536 WL_ISRLOCK(wl, flags);
1538 /* call common first level interrupt handler */
1539 ours = wlc_isr(wl->wlc, &wantdpc);
1541 /* if more to do... */
1544 /* ...and call the second level interrupt handler */
1546 ASSERT(wl->resched == false);
1547 tasklet_schedule(&wl->tasklet);
1551 WL_ISRUNLOCK(wl, flags);
1553 return IRQ_RETVAL(ours);
1556 static void BCMFASTPATH wl_dpc(unsigned long data)
1560 wl = (struct wl_info *) data;
1564 /* call the common second level interrupt handler */
1567 unsigned long flags;
1569 INT_LOCK(wl, flags);
1570 wlc_intrsupd(wl->wlc);
1571 INT_UNLOCK(wl, flags);
1574 wl->resched = wlc_dpc(wl->wlc, true);
1577 /* wlc_dpc() may bring the driver down */
1581 /* re-schedule dpc */
1583 tasklet_schedule(&wl->tasklet);
1585 /* re-enable interrupts */
1594 * is called by the kernel from software irq context
1596 static void wl_timer(unsigned long data)
1598 _wl_timer((wl_timer_t *) data);
1602 * precondition: perimeter lock is not acquired
1604 static void _wl_timer(wl_timer_t *t)
1610 t->timer.expires = jiffies + t->ms * HZ / 1000;
1611 atomic_inc(&t->wl->callbacks);
1612 add_timer(&t->timer);
1620 atomic_dec(&t->wl->callbacks);
1626 * Adds a timer to the list. Caller supplies a timer function.
1627 * Is called from wlc.
1629 * precondition: perimeter lock has been acquired
1631 wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
1636 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
1638 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1642 memset(t, 0, sizeof(wl_timer_t));
1644 init_timer(&t->timer);
1645 t->timer.data = (unsigned long) t;
1646 t->timer.function = wl_timer;
1650 t->next = wl->timers;
1654 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1656 strcpy(t->name, name);
1662 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1663 * as well as it's easier to make it periodic
1665 * precondition: perimeter lock has been acquired
1667 void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
1671 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1672 __func__, t->name, periodic);
1678 t->periodic = (bool) periodic;
1680 t->timer.expires = jiffies + ms * HZ / 1000;
1682 atomic_inc(&wl->callbacks);
1683 add_timer(&t->timer);
1687 * return true if timer successfully deleted, false if still pending
1689 * precondition: perimeter lock has been acquired
1691 bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
1695 if (!del_timer(&t->timer)) {
1698 atomic_dec(&wl->callbacks);
1705 * precondition: perimeter lock has been acquired
1707 void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
1711 /* delete the timer in case it is active */
1712 wl_del_timer(wl, t);
1714 if (wl->timers == t) {
1715 wl->timers = wl->timers->next;
1727 if (tmp->next == t) {
1728 tmp->next = t->next;
1742 * runs in software irq context
1744 * precondition: perimeter lock is not acquired
1746 static int wl_linux_watchdog(void *ctx)
1748 struct wl_info *wl = (struct wl_info *) ctx;
1750 struct net_device_stats *stats = NULL;
1754 ASSERT(wl->stats_id < 2);
1756 cnt = wl->pub->_cnt;
1757 id = 1 - wl->stats_id;
1758 stats = &wl->stats_watchdog[id];
1759 stats->rx_packets = cnt->rxframe;
1760 stats->tx_packets = cnt->txframe;
1761 stats->rx_bytes = cnt->rxbyte;
1762 stats->tx_bytes = cnt->txbyte;
1763 stats->rx_errors = cnt->rxerror;
1764 stats->tx_errors = cnt->txerror;
1765 stats->collisions = 0;
1767 stats->rx_length_errors = 0;
1768 stats->rx_over_errors = cnt->rxoflo;
1769 stats->rx_crc_errors = cnt->rxcrc;
1770 stats->rx_frame_errors = 0;
1771 stats->rx_fifo_errors = cnt->rxoflo;
1772 stats->rx_missed_errors = 0;
1774 stats->tx_fifo_errors = cnt->txuflo;
1788 char *wl_firmwares[WL_MAX_FW] = {
1794 * precondition: perimeter lock has been acquired
1796 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1800 struct wl_fw_hdr *hdr;
1801 for (i = 0; i < wl->fw.fw_cnt; i++) {
1802 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1803 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1805 if (hdr->idx == idx) {
1806 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1807 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1808 if (*pbuf == NULL) {
1809 WL_ERROR("fail to alloc %d bytes\n",
1813 memcpy(*pbuf, pdata, hdr->len);
1818 WL_ERROR("ERROR: ucode buf tag:%d can not be found!\n", idx);
1821 return BCME_NOTFOUND;
1825 * Precondition: Since this function is called in wl_pci_probe() context,
1826 * no locking is required.
1828 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1832 struct wl_fw_hdr *hdr;
1833 for (i = 0; i < wl->fw.fw_cnt; i++) {
1834 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1835 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1837 if (hdr->idx == idx) {
1838 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1839 ASSERT(hdr->len == 4);
1840 *data = *((u32 *) pdata);
1845 WL_ERROR("ERROR: ucode tag:%d can not be found!\n", idx);
1850 * Precondition: Since this function is called in wl_pci_probe() context,
1851 * no locking is required.
1853 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1856 struct device *device = &pdev->dev;
1860 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1861 for (i = 0; i < WL_MAX_FW; i++) {
1862 if (wl_firmwares[i] == NULL)
1864 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1865 UCODE_LOADER_API_VER);
1866 WL_NONE("request fw %s\n", fw_name);
1867 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1869 WL_ERROR("%s: fail to load firmware %s\n",
1870 KBUILD_MODNAME, fw_name);
1873 WL_NONE("request fw %s\n", fw_name);
1874 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1875 UCODE_LOADER_API_VER);
1876 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1878 WL_ERROR("%s: fail to load firmware %s\n",
1879 KBUILD_MODNAME, fw_name);
1882 wl->fw.hdr_num_entries[i] =
1883 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1884 WL_NONE("request fw %s find: %d entries\n",
1885 fw_name, wl->fw.hdr_num_entries[i]);
1888 return wl_ucode_data_init(wl);
1892 * precondition: can both be called locked and unlocked
1894 void wl_ucode_free_buf(void *p)
1900 * Precondition: Since this function is called in wl_pci_probe() context,
1901 * no locking is required.
1903 static void wl_release_fw(struct wl_info *wl)
1906 for (i = 0; i < WL_MAX_FW; i++) {
1907 release_firmware(wl->fw.fw_bin[i]);
1908 release_firmware(wl->fw.fw_hdr[i]);
1914 * checks validity of all firmware images loaded from user space
1916 * Precondition: Since this function is called in wl_pci_probe() context,
1917 * no locking is required.
1919 int wl_check_firmwares(struct wl_info *wl)
1924 const struct firmware *fw;
1925 const struct firmware *fw_hdr;
1926 struct wl_fw_hdr *ucode_hdr;
1927 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1928 fw = wl->fw.fw_bin[i];
1929 fw_hdr = wl->fw.fw_hdr[i];
1930 if (fw == NULL && fw_hdr == NULL) {
1932 } else if (fw == NULL || fw_hdr == NULL) {
1933 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1935 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1936 WL_ERROR("%s: non integral fw hdr file size %zu/%zu\n",
1937 __func__, fw_hdr->size,
1938 sizeof(struct wl_fw_hdr));
1940 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1941 WL_ERROR("%s: out of bounds fw file size %zu\n",
1942 __func__, fw->size);
1945 /* check if ucode section overruns firmware image */
1946 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1947 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1948 !rc; entry++, ucode_hdr++) {
1949 if (ucode_hdr->offset + ucode_hdr->len >
1951 WL_ERROR("%s: conflicting bin/hdr\n",
1958 if (rc == 0 && wl->fw.fw_cnt != i) {
1959 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1966 * precondition: perimeter lock has been acquired
1968 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1970 bool blocked = wlc_check_radio_disabled(wl->wlc);
1972 WL_NONE("%s: update hw state: blocked=%s\n", __func__,
1973 blocked ? "true" : "false");
1975 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1977 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);