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/etherdevice.h>
20 #include <linux/pci.h>
21 #include <linux/sched.h>
22 #include <linux/firmware.h>
23 #include <net/mac80211.h>
26 #include "phy/phy_int.h"
31 #include "ucode_loader.h"
32 #include "mac80211_if.h"
34 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
36 #define LOCK(wl) spin_lock_bh(&(wl)->lock)
37 #define UNLOCK(wl) spin_unlock_bh(&(wl)->lock)
39 /* locking from inside brcms_isr */
40 #define ISR_LOCK(wl, flags)\
42 spin_lock(&(wl)->isr_lock);\
46 #define ISR_UNLOCK(wl, flags)\
48 spin_unlock(&(wl)->isr_lock);\
52 /* locking under LOCK() to synchronize with brcms_isr */
53 #define INT_LOCK(wl, flags) spin_lock_irqsave(&(wl)->isr_lock, flags)
54 #define INT_UNLOCK(wl, flags) spin_unlock_irqrestore(&(wl)->isr_lock, flags)
56 static void brcms_timer(unsigned long data);
57 static void _brcms_timer(struct brcms_timer *t);
60 static int ieee_hw_init(struct ieee80211_hw *hw);
61 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
63 static int wl_linux_watchdog(void *ctx);
65 /* Flags we support */
66 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
72 FIF_BCN_PRBRESP_PROMISC)
74 static int n_adapters_found;
76 static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev);
77 static void brcms_release_fw(struct brcms_info *wl);
79 /* local prototypes */
80 static void brcms_dpc(unsigned long data);
81 static irqreturn_t brcms_isr(int irq, void *dev_id);
83 static int __devinit brcms_pci_probe(struct pci_dev *pdev,
84 const struct pci_device_id *ent);
85 static void brcms_remove(struct pci_dev *pdev);
86 static void brcms_free(struct brcms_info *wl);
87 static void brcms_set_basic_rate(struct wl_rateset *rs, u16 rate, bool is_br);
89 MODULE_AUTHOR("Broadcom Corporation");
90 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
91 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
92 MODULE_LICENSE("Dual BSD/GPL");
94 /* recognized PCI IDs */
95 static DEFINE_PCI_DEVICE_TABLE(brcms_pci_id_table) = {
96 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
97 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
98 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
100 {PCI_VENDOR_ID_BROADCOM, 0x0576, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
104 MODULE_DEVICE_TABLE(pci, brcms_pci_id_table);
107 static int msglevel = 0xdeadbeef;
108 module_param(msglevel, int, 0);
109 static int phymsglevel = 0xdeadbeef;
110 module_param(phymsglevel, int, 0);
113 #define HW_TO_WL(hw) (hw->priv)
114 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
116 /* MAC80211 callback functions */
117 static int brcms_ops_start(struct ieee80211_hw *hw);
118 static void brcms_ops_stop(struct ieee80211_hw *hw);
119 static int brcms_ops_add_interface(struct ieee80211_hw *hw,
120 struct ieee80211_vif *vif);
121 static void brcms_ops_remove_interface(struct ieee80211_hw *hw,
122 struct ieee80211_vif *vif);
123 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed);
124 static void brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
125 struct ieee80211_vif *vif,
126 struct ieee80211_bss_conf *info,
128 static void brcms_ops_configure_filter(struct ieee80211_hw *hw,
129 unsigned int changed_flags,
130 unsigned int *total_flags, u64 multicast);
131 static int brcms_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
133 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw);
134 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw);
135 static void brcms_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
136 static int brcms_ops_get_stats(struct ieee80211_hw *hw,
137 struct ieee80211_low_level_stats *stats);
138 static void brcms_ops_sta_notify(struct ieee80211_hw *hw,
139 struct ieee80211_vif *vif,
140 enum sta_notify_cmd cmd,
141 struct ieee80211_sta *sta);
142 static int brcms_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
143 const struct ieee80211_tx_queue_params *params);
144 static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw);
145 static int brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
146 struct ieee80211_sta *sta);
147 static int brcms_ops_sta_remove(struct ieee80211_hw *hw,
148 struct ieee80211_vif *vif,
149 struct ieee80211_sta *sta);
150 static int brcms_ops_ampdu_action(struct ieee80211_hw *hw,
151 struct ieee80211_vif *vif,
152 enum ieee80211_ampdu_mlme_action action,
153 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
155 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw);
156 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop);
158 static void brcms_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
160 struct brcms_info *wl = hw->priv;
164 wiphy_err(wl->wiphy, "ops->tx called while down\n");
168 brcms_c_sendpkt_mac80211(wl->wlc, skb, hw);
173 static int brcms_ops_start(struct ieee80211_hw *hw)
175 struct brcms_info *wl = hw->priv;
178 struct ieee80211_channel *curchan = hw->conf.channel;
181 ieee80211_wake_queues(hw);
183 blocked = brcms_rfkill_set_hw_state(wl);
186 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
191 static void brcms_ops_stop(struct ieee80211_hw *hw)
193 ieee80211_stop_queues(hw);
197 brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
199 struct brcms_info *wl;
202 /* Just STA for now */
203 if (vif->type != NL80211_IFTYPE_AP &&
204 vif->type != NL80211_IFTYPE_MESH_POINT &&
205 vif->type != NL80211_IFTYPE_STATION &&
206 vif->type != NL80211_IFTYPE_WDS &&
207 vif->type != NL80211_IFTYPE_ADHOC) {
208 wiphy_err(hw->wiphy, "%s: Attempt to add type %d, only"
209 " STA for now\n", __func__, vif->type);
219 wiphy_err(hw->wiphy, "%s: brcms_up() returned %d\n", __func__,
226 brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
228 struct brcms_info *wl;
232 /* put driver in down state */
239 * precondition: perimeter lock has been acquired
242 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
243 enum nl80211_channel_type type)
245 struct brcms_info *wl = HW_TO_WL(hw);
249 case NL80211_CHAN_HT20:
250 case NL80211_CHAN_NO_HT:
251 err = brcms_c_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
253 case NL80211_CHAN_HT40MINUS:
254 case NL80211_CHAN_HT40PLUS:
256 "%s: Need to implement 40 Mhz Channels!\n", __func__);
266 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
268 struct ieee80211_conf *conf = &hw->conf;
269 struct brcms_info *wl = HW_TO_WL(hw);
272 struct wiphy *wiphy = hw->wiphy;
275 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
276 if (brcms_c_set_par(wl->wlc, IOV_BCN_LI_BCN,
277 conf->listen_interval) < 0) {
278 wiphy_err(wiphy, "%s: Error setting listen_interval\n",
283 brcms_c_get_par(wl->wlc, IOV_BCN_LI_BCN, &new_int);
285 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
286 wiphy_err(wiphy, "%s: change monitor mode: %s (implement)\n",
287 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
289 if (changed & IEEE80211_CONF_CHANGE_PS)
290 wiphy_err(wiphy, "%s: change power-save mode: %s (implement)\n",
291 __func__, conf->flags & IEEE80211_CONF_PS ?
294 if (changed & IEEE80211_CONF_CHANGE_POWER) {
295 if (brcms_c_set_par(wl->wlc, IOV_QTXPOWER,
296 conf->power_level * 4) < 0) {
297 wiphy_err(wiphy, "%s: Error setting power_level\n",
302 brcms_c_get_par(wl->wlc, IOV_QTXPOWER, &new_int);
303 if (new_int != (conf->power_level * 4))
304 wiphy_err(wiphy, "%s: Power level req != actual, %d %d"
305 "\n", __func__, conf->power_level * 4,
308 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
309 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
311 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
313 (wl->wlc, WLC_SET_SRL,
314 conf->short_frame_max_tx_count) < 0) {
315 wiphy_err(wiphy, "%s: Error setting srl\n", __func__);
319 if (brcms_c_set(wl->wlc, WLC_SET_LRL,
320 conf->long_frame_max_tx_count) < 0) {
321 wiphy_err(wiphy, "%s: Error setting lrl\n", __func__);
333 brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
334 struct ieee80211_vif *vif,
335 struct ieee80211_bss_conf *info, u32 changed)
337 struct brcms_info *wl = HW_TO_WL(hw);
338 struct wiphy *wiphy = hw->wiphy;
341 if (changed & BSS_CHANGED_ASSOC) {
342 /* association status changed (associated/disassociated)
343 * also implies a change in the AID.
345 wiphy_err(wiphy, "%s: %s: %sassociated\n", KBUILD_MODNAME,
346 __func__, info->assoc ? "" : "dis");
348 brcms_c_associate_upd(wl->wlc, info->assoc);
351 if (changed & BSS_CHANGED_ERP_SLOT) {
352 /* slot timing changed */
353 if (info->use_short_slot)
358 brcms_c_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;
367 brcms_c_protection_upd(wl->wlc, WLC_PROT_N_CFG,
368 mode & IEEE80211_HT_OP_MODE_PROTECTION);
369 brcms_c_protection_upd(wl->wlc, WLC_PROT_N_NONGF,
370 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
371 brcms_c_protection_upd(wl->wlc, WLC_PROT_N_OBSS,
372 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
375 if (changed & BSS_CHANGED_BASIC_RATES) {
376 struct ieee80211_supported_band *bi;
379 struct wl_rateset rs;
382 /* retrieve the current rates */
384 error = brcms_c_ioctl(wl->wlc, WLC_GET_CURR_RATESET,
385 &rs, sizeof(rs), NULL);
388 wiphy_err(wiphy, "%s: retrieve rateset failed: %d\n",
392 br_mask = info->basic_rates;
393 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
394 for (i = 0; i < bi->n_bitrates; i++) {
395 /* convert to internal rate value */
396 rate = (bi->bitrates[i].bitrate << 1) / 10;
398 /* set/clear basic rate flag */
399 brcms_set_basic_rate(&rs, rate, br_mask & 1);
403 /* update the rate set */
405 brcms_c_ioctl(wl->wlc, WLC_SET_RATESET, &rs, sizeof(rs), NULL);
408 if (changed & BSS_CHANGED_BEACON_INT) {
409 /* Beacon interval changed */
411 brcms_c_set(wl->wlc, WLC_SET_BCNPRD, info->beacon_int);
414 if (changed & BSS_CHANGED_BSSID) {
415 /* BSSID changed, for whatever reason (IBSS and managed mode) */
417 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
421 if (changed & BSS_CHANGED_BEACON) {
422 /* Beacon data changed, retrieve new beacon (beaconing modes) */
423 wiphy_err(wiphy, "%s: beacon changed\n", __func__);
425 if (changed & BSS_CHANGED_BEACON_ENABLED) {
426 /* Beaconing should be enabled/disabled (beaconing modes) */
427 wiphy_err(wiphy, "%s: Beacon enabled: %s\n", __func__,
428 info->enable_beacon ? "true" : "false");
430 if (changed & BSS_CHANGED_CQM) {
431 /* Connection quality monitor config changed */
432 wiphy_err(wiphy, "%s: cqm change: threshold %d, hys %d "
433 " (implement)\n", __func__, info->cqm_rssi_thold,
434 info->cqm_rssi_hyst);
436 if (changed & BSS_CHANGED_IBSS) {
437 /* IBSS join status changed */
438 wiphy_err(wiphy, "%s: IBSS joined: %s (implement)\n", __func__,
439 info->ibss_joined ? "true" : "false");
441 if (changed & BSS_CHANGED_ARP_FILTER) {
442 /* Hardware ARP filter address list or state changed */
443 wiphy_err(wiphy, "%s: arp filtering: enabled %s, count %d"
444 " (implement)\n", __func__, info->arp_filter_enabled ?
445 "true" : "false", info->arp_addr_cnt);
447 if (changed & BSS_CHANGED_QOS) {
449 * QoS for this association was enabled/disabled.
450 * Note that it is only ever disabled for station mode.
452 wiphy_err(wiphy, "%s: qos enabled: %s (implement)\n", __func__,
453 info->qos ? "true" : "false");
455 if (changed & BSS_CHANGED_IDLE) {
456 /* Idle changed for this BSS/interface */
457 wiphy_err(wiphy, "%s: BSS idle: %s (implement)\n", __func__,
458 info->idle ? "true" : "false");
464 brcms_ops_configure_filter(struct ieee80211_hw *hw,
465 unsigned int changed_flags,
466 unsigned int *total_flags, u64 multicast)
468 struct brcms_info *wl = hw->priv;
469 struct wiphy *wiphy = hw->wiphy;
471 changed_flags &= MAC_FILTERS;
472 *total_flags &= MAC_FILTERS;
473 if (changed_flags & FIF_PROMISC_IN_BSS)
474 wiphy_err(wiphy, "FIF_PROMISC_IN_BSS\n");
475 if (changed_flags & FIF_ALLMULTI)
476 wiphy_err(wiphy, "FIF_ALLMULTI\n");
477 if (changed_flags & FIF_FCSFAIL)
478 wiphy_err(wiphy, "FIF_FCSFAIL\n");
479 if (changed_flags & FIF_PLCPFAIL)
480 wiphy_err(wiphy, "FIF_PLCPFAIL\n");
481 if (changed_flags & FIF_CONTROL)
482 wiphy_err(wiphy, "FIF_CONTROL\n");
483 if (changed_flags & FIF_OTHER_BSS)
484 wiphy_err(wiphy, "FIF_OTHER_BSS\n");
485 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
487 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
488 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
489 brcms_c_mac_bcn_promisc_change(wl->wlc, 1);
491 brcms_c_mac_bcn_promisc_change(wl->wlc, 0);
492 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
500 brcms_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
505 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
507 struct brcms_info *wl = hw->priv;
509 brcms_c_scan_start(wl->wlc);
514 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
516 struct brcms_info *wl = hw->priv;
518 brcms_c_scan_stop(wl->wlc);
523 static void brcms_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
525 wiphy_err(hw->wiphy, "%s: Enter\n", __func__);
530 brcms_ops_get_stats(struct ieee80211_hw *hw,
531 struct ieee80211_low_level_stats *stats)
533 struct brcms_info *wl = hw->priv;
538 stats->dot11ACKFailureCount = 0;
539 stats->dot11RTSFailureCount = 0;
540 stats->dot11FCSErrorCount = 0;
541 stats->dot11RTSSuccessCount = 0;
547 brcms_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
548 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
552 wiphy_err(hw->wiphy, "%s: Unknown cmd = %d\n", __func__,
560 brcms_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
561 const struct ieee80211_tx_queue_params *params)
563 struct brcms_info *wl = hw->priv;
566 brcms_c_wme_setparams(wl->wlc, queue, params, true);
572 static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw)
574 wiphy_err(hw->wiphy, "%s: Enter\n", __func__);
579 brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
580 struct ieee80211_sta *sta)
585 struct brcms_info *wl = hw->priv;
588 scb = (struct scb *)sta->drv_priv;
589 memset(scb, 0, sizeof(struct scb));
590 for (i = 0; i < NUMPRIO; i++)
591 scb->seqctl[i] = 0xFFFF;
592 scb->seqctl_nonqos = 0xFFFF;
593 scb->magic = SCB_MAGIC;
595 wl->pub->global_scb = scb;
596 wl->pub->global_ampdu = &(scb->scb_ampdu);
597 wl->pub->global_ampdu->scb = scb;
598 wl->pub->global_ampdu->max_pdu = 16;
599 brcmu_pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
600 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
602 sta->ht_cap.ht_supported = true;
603 sta->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
604 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
605 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
606 IEEE80211_HT_CAP_SGI_20 |
607 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
609 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
614 brcms_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
615 struct ieee80211_sta *sta)
621 brcms_ops_ampdu_action(struct ieee80211_hw *hw,
622 struct ieee80211_vif *vif,
623 enum ieee80211_ampdu_mlme_action action,
624 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
627 struct scb *scb = (struct scb *)sta->drv_priv;
628 struct brcms_info *wl = hw->priv;
631 if (WARN_ON(scb->magic != SCB_MAGIC))
634 case IEEE80211_AMPDU_RX_START:
636 case IEEE80211_AMPDU_RX_STOP:
638 case IEEE80211_AMPDU_TX_START:
640 status = brcms_c_aggregatable(wl->wlc, tid);
643 wiphy_err(wl->wiphy, "START: tid %d is not agg\'able\n",
647 /* XXX: Use the starting sequence number provided ... */
649 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
652 case IEEE80211_AMPDU_TX_STOP:
654 brcms_c_ampdu_flush(wl->wlc, sta, tid);
656 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
658 case IEEE80211_AMPDU_TX_OPERATIONAL:
660 * BA window size from ADDBA response ('buf_size') defines how
661 * many outstanding MPDUs are allowed for the BA stream by
662 * recipient and traffic class.
665 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size);
667 /* Power save wakeup */
670 wiphy_err(wl->wiphy, "%s: Invalid command, ignoring\n",
677 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
679 struct brcms_info *wl = HW_TO_WL(hw);
683 blocked = brcms_c_check_radio_disabled(wl->wlc);
686 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
689 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
691 struct brcms_info *wl = HW_TO_WL(hw);
693 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
695 /* wait for packet queue and dma fifos to run empty */
697 brcms_c_wait_for_tx_completion(wl->wlc, drop);
701 static const struct ieee80211_ops brcms_ops = {
703 .start = brcms_ops_start,
704 .stop = brcms_ops_stop,
705 .add_interface = brcms_ops_add_interface,
706 .remove_interface = brcms_ops_remove_interface,
707 .config = brcms_ops_config,
708 .bss_info_changed = brcms_ops_bss_info_changed,
709 .configure_filter = brcms_ops_configure_filter,
710 .set_tim = brcms_ops_set_tim,
711 .sw_scan_start = brcms_ops_sw_scan_start,
712 .sw_scan_complete = brcms_ops_sw_scan_complete,
713 .set_tsf = brcms_ops_set_tsf,
714 .get_stats = brcms_ops_get_stats,
715 .sta_notify = brcms_ops_sta_notify,
716 .conf_tx = brcms_ops_conf_tx,
717 .get_tsf = brcms_ops_get_tsf,
718 .sta_add = brcms_ops_sta_add,
719 .sta_remove = brcms_ops_sta_remove,
720 .ampdu_action = brcms_ops_ampdu_action,
721 .rfkill_poll = brcms_ops_rfkill_poll,
722 .flush = brcms_ops_flush,
726 * is called in brcms_pci_probe() context, therefore no locking required.
728 static int brcms_set_hint(struct brcms_info *wl, char *abbrev)
730 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
734 * attach to the WL device.
736 * Attach to the WL device identified by vendor and device parameters.
737 * regs is a host accessible memory address pointing to WL device registers.
739 * brcms_attach is not defined as static because in the case where no bus
740 * is defined, wl_attach will never be called, and thus, gcc will issue
741 * a warning that this function is defined but not used if we declare
745 * is called in brcms_pci_probe() context, therefore no locking required.
747 static struct brcms_info *brcms_attach(u16 vendor, u16 device,
749 uint bustype, void *btparam, uint irq)
751 struct brcms_info *wl = NULL;
753 unsigned long base_addr;
754 struct ieee80211_hw *hw;
757 unit = n_adapters_found;
764 /* allocate private info */
765 hw = pci_get_drvdata(btparam); /* btparam == pdev */
768 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
770 wl->wiphy = hw->wiphy;
772 atomic_set(&wl->callbacks, 0);
774 /* setup the bottom half handler */
775 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
781 if (bustype == PCI_BUS || bustype == RPC_BUS) {
785 BCMMSG(wl->wiphy, "force to PCI\n");
787 wl->bcm_bustype = bustype;
789 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
790 if (wl->regsva == NULL) {
791 wiphy_err(wl->wiphy, "wl%d: ioremap() failed\n", unit);
794 spin_lock_init(&wl->lock);
795 spin_lock_init(&wl->isr_lock);
798 if (brcms_request_fw(wl, (struct pci_dev *)btparam) < 0) {
799 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
800 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
801 brcms_release_fw(wl);
802 brcms_remove((struct pci_dev *)btparam);
806 /* common load-time initialization */
807 wl->wlc = brcms_c_attach((void *)wl, vendor, device, unit, false,
808 wl->regsva, wl->bcm_bustype, btparam, &err);
809 brcms_release_fw(wl);
811 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
812 KBUILD_MODNAME, err);
815 wl->pub = brcms_c_pub(wl->wlc);
817 wl->pub->ieee_hw = hw;
819 if (brcms_c_set_par(wl->wlc, IOV_MPC, 0) < 0) {
820 wiphy_err(wl->wiphy, "wl%d: Error setting MPC variable to 0\n",
824 /* register our interrupt handler */
825 if (request_irq(irq, brcms_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
826 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
831 /* register module */
832 brcms_c_module_register(wl->pub, "linux", wl, wl_linux_watchdog, NULL);
834 if (ieee_hw_init(hw)) {
835 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
840 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
841 if (WARN_ON(!is_valid_ether_addr(perm)))
843 SET_IEEE80211_PERM_ADDR(hw, perm);
845 err = ieee80211_register_hw(hw);
847 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
848 "%d\n", __func__, err);
851 if (wl->pub->srom_ccode[0])
852 err = brcms_set_hint(wl, wl->pub->srom_ccode);
854 err = brcms_set_hint(wl, "US");
856 wiphy_err(wl->wiphy, "%s: regulatory_hint failed, status %d\n",
870 #define CHAN2GHZ(channel, freqency, chflags) { \
871 .band = IEEE80211_BAND_2GHZ, \
872 .center_freq = (freqency), \
873 .hw_value = (channel), \
875 .max_antenna_gain = 0, \
879 static struct ieee80211_channel brcms_2ghz_chantable[] = {
880 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
881 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
882 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
883 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
884 CHAN2GHZ(5, 2432, 0),
885 CHAN2GHZ(6, 2437, 0),
886 CHAN2GHZ(7, 2442, 0),
887 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
888 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
889 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
890 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
892 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
893 IEEE80211_CHAN_NO_HT40PLUS),
895 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
896 IEEE80211_CHAN_NO_HT40PLUS),
898 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
899 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
902 #define CHAN5GHZ(channel, chflags) { \
903 .band = IEEE80211_BAND_5GHZ, \
904 .center_freq = 5000 + 5*(channel), \
905 .hw_value = (channel), \
907 .max_antenna_gain = 0, \
911 static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
913 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
914 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
915 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
916 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
919 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
920 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
922 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
923 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
925 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
926 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
928 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
929 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
932 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
933 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
935 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
936 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
938 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
939 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
941 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
942 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
944 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
945 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
947 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
948 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
950 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
951 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
953 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
954 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
956 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
957 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
959 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
960 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
962 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
963 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
964 IEEE80211_CHAN_NO_HT40MINUS),
966 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
967 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
968 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
969 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
970 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
973 #define RATE(rate100m, _flags) { \
974 .bitrate = (rate100m), \
976 .hw_value = (rate100m / 5), \
979 static struct ieee80211_rate legacy_ratetable[] = {
981 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
982 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
983 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
994 static struct ieee80211_supported_band brcms_band_2GHz_nphy = {
995 .band = IEEE80211_BAND_2GHZ,
996 .channels = brcms_2ghz_chantable,
997 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
998 .bitrates = legacy_ratetable,
999 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
1001 /* from include/linux/ieee80211.h */
1002 .cap = IEEE80211_HT_CAP_GRN_FLD |
1003 IEEE80211_HT_CAP_SGI_20 |
1004 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
1005 .ht_supported = true,
1006 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
1007 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1009 /* placeholders for now */
1010 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1012 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1016 static struct ieee80211_supported_band brcms_band_5GHz_nphy = {
1017 .band = IEEE80211_BAND_5GHZ,
1018 .channels = brcms_5ghz_nphy_chantable,
1019 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
1020 .bitrates = legacy_ratetable + 4,
1021 .n_bitrates = ARRAY_SIZE(legacy_ratetable) - 4,
1023 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1024 .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 */
1025 .ht_supported = true,
1026 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
1027 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1029 /* placeholders for now */
1030 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1032 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1037 * is called in brcms_pci_probe() context, therefore no locking required.
1039 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1041 struct brcms_info *wl = HW_TO_WL(hw);
1047 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1048 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1050 if (brcms_c_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0)
1051 wiphy_err(hw->wiphy, "Phy list failed\n");
1053 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1054 if (phy_list[0] == 'c') {
1056 brcms_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1057 brcms_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1059 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &brcms_band_2GHz_nphy;
1064 /* Assume all bands use the same phy. True for 11n devices. */
1065 if (NBANDS_PUB(wl->pub) > 1) {
1067 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1068 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1069 &brcms_band_5GHz_nphy;
1078 * is called in brcms_pci_probe() context, therefore no locking required.
1080 static int ieee_hw_init(struct ieee80211_hw *hw)
1082 hw->flags = IEEE80211_HW_SIGNAL_DBM
1083 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1084 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1085 | IEEE80211_HW_AMPDU_AGGREGATION;
1087 hw->extra_tx_headroom = brcms_c_get_header_len();
1088 hw->queues = N_TX_QUEUES;
1089 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1090 * mac80211/status.c:ieee80211_tx_status() checks this value,
1091 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1092 * appears to always set 3 rates
1094 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1096 hw->channel_change_time = 7 * 1000; /* channel change time is dependent on chip and band */
1097 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1099 hw->rate_control_algorithm = "minstrel_ht";
1101 hw->sta_data_size = sizeof(struct scb);
1102 return ieee_hw_rate_init(hw);
1106 * determines if a device is a WL device, and if so, attaches it.
1108 * This function determines if a device pointed to by pdev is a WL device,
1109 * and if so, performs a brcms_attach() on it.
1111 * Perimeter lock is initialized in the course of this function.
1113 static int __devinit
1114 brcms_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1117 struct brcms_info *wl;
1118 struct ieee80211_hw *hw;
1121 dev_info(&pdev->dev, "bus %d slot %d func %d irq %d\n",
1122 pdev->bus->number, PCI_SLOT(pdev->devfn),
1123 PCI_FUNC(pdev->devfn), pdev->irq);
1125 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1126 ((pdev->device != 0x0576) &&
1127 ((pdev->device & 0xff00) != 0x4300) &&
1128 ((pdev->device & 0xff00) != 0x4700) &&
1129 ((pdev->device < 43000) || (pdev->device > 43999))))
1132 rc = pci_enable_device(pdev);
1134 pr_err("%s: Cannot enable device %d-%d_%d\n",
1135 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1136 PCI_FUNC(pdev->devfn));
1139 pci_set_master(pdev);
1141 pci_read_config_dword(pdev, 0x40, &val);
1142 if ((val & 0x0000ff00) != 0)
1143 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1145 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1147 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1151 SET_IEEE80211_DEV(hw, &pdev->dev);
1153 pci_set_drvdata(pdev, hw);
1155 memset(hw->priv, 0, sizeof(*wl));
1157 wl = brcms_attach(pdev->vendor, pdev->device,
1158 pci_resource_start(pdev, 0), PCI_BUS, pdev,
1162 pr_err("%s: %s: brcms_attach failed!\n", KBUILD_MODNAME,
1169 static int brcms_suspend(struct pci_dev *pdev, pm_message_t state)
1171 struct brcms_info *wl;
1172 struct ieee80211_hw *hw;
1174 hw = pci_get_drvdata(pdev);
1177 wiphy_err(wl->wiphy,
1178 "brcms_suspend: pci_get_drvdata failed\n");
1182 /* only need to flag hw is down for proper resume */
1184 wl->pub->hw_up = false;
1187 pci_save_state(pdev);
1188 pci_disable_device(pdev);
1189 return pci_set_power_state(pdev, PCI_D3hot);
1192 static int brcms_resume(struct pci_dev *pdev)
1194 struct brcms_info *wl;
1195 struct ieee80211_hw *hw;
1199 hw = pci_get_drvdata(pdev);
1202 wiphy_err(wl->wiphy,
1203 "wl: brcms_resume: pci_get_drvdata failed\n");
1207 err = pci_set_power_state(pdev, PCI_D0);
1211 pci_restore_state(pdev);
1213 err = pci_enable_device(pdev);
1217 pci_set_master(pdev);
1219 pci_read_config_dword(pdev, 0x40, &val);
1220 if ((val & 0x0000ff00) != 0)
1221 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1224 * done. driver will be put in up state
1225 * in brcms_ops_add_interface() call.
1231 * called from both kernel as from this kernel module.
1232 * precondition: perimeter lock is not acquired.
1234 static void brcms_remove(struct pci_dev *pdev)
1236 struct brcms_info *wl;
1237 struct ieee80211_hw *hw;
1240 hw = pci_get_drvdata(pdev);
1243 pr_err("wl: brcms_remove: pci_get_drvdata failed\n");
1248 status = brcms_c_chipmatch(pdev->vendor, pdev->device);
1251 wiphy_err(wl->wiphy, "wl: brcms_remove: chipmatch "
1256 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1257 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1258 ieee80211_unregister_hw(hw);
1263 pci_disable_device(pdev);
1267 pci_set_drvdata(pdev, NULL);
1268 ieee80211_free_hw(hw);
1271 static struct pci_driver brcms_pci_driver = {
1272 .name = KBUILD_MODNAME,
1273 .probe = brcms_pci_probe,
1274 .suspend = brcms_suspend,
1275 .resume = brcms_resume,
1276 .remove = __devexit_p(brcms_remove),
1277 .id_table = brcms_pci_id_table,
1281 * This is the main entry point for the WL driver.
1283 * This function determines if a device pointed to by pdev is a WL device,
1284 * and if so, performs a brcms_attach() on it.
1287 static int __init brcms_module_init(void)
1289 int error = -ENODEV;
1292 if (msglevel != 0xdeadbeef)
1293 brcm_msg_level = msglevel;
1294 if (phymsglevel != 0xdeadbeef)
1295 phyhal_msg_level = phymsglevel;
1298 error = pci_register_driver(&brcms_pci_driver);
1308 * This function unloads the WL driver from the system.
1310 * This function unconditionally unloads the WL driver module from the
1314 static void __exit brcms_module_exit(void)
1316 pci_unregister_driver(&brcms_pci_driver);
1320 module_init(brcms_module_init);
1321 module_exit(brcms_module_exit);
1324 * This function frees the WL per-device resources.
1326 * This function frees resources owned by the WL device pointed to
1327 * by the wl parameter.
1329 * precondition: can both be called locked and unlocked
1332 static void brcms_free(struct brcms_info *wl)
1334 struct brcms_timer *t, *next;
1336 /* free ucode data */
1338 brcms_ucode_data_free();
1340 free_irq(wl->irq, wl);
1343 tasklet_kill(&wl->tasklet);
1346 brcms_c_module_unregister(wl->pub, "linux", wl);
1349 /* free common resources */
1351 brcms_c_detach(wl->wlc);
1356 /* virtual interface deletion is deferred so we cannot spinwait */
1358 /* wait for all pending callbacks to complete */
1359 while (atomic_read(&wl->callbacks) > 0)
1363 for (t = wl->timers; t; t = next) {
1372 * unregister_netdev() calls get_stats() which may read chip registers
1373 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1375 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1376 wl->bcm_bustype != JTAG_BUS) {
1377 iounmap((void *)wl->regsva);
1382 /* flags the given rate in rateset as requested */
1383 static void brcms_set_basic_rate(struct wl_rateset *rs, u16 rate, bool is_br)
1387 for (i = 0; i < rs->count; i++) {
1388 if (rate != (rs->rates[i] & 0x7f))
1392 rs->rates[i] |= WLC_RATE_FLAG;
1394 rs->rates[i] &= WLC_RATE_MASK;
1400 * precondition: perimeter lock has been acquired
1402 void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1403 bool state, int prio)
1405 wiphy_err(wl->wiphy, "Shouldn't be here %s\n", __func__);
1409 * precondition: perimeter lock has been acquired
1411 void brcms_init(struct brcms_info *wl)
1413 BCMMSG(WL_TO_HW(wl)->wiphy, "wl%d\n", wl->pub->unit);
1416 brcms_c_init(wl->wlc);
1420 * precondition: perimeter lock has been acquired
1422 uint brcms_reset(struct brcms_info *wl)
1424 BCMMSG(WL_TO_HW(wl)->wiphy, "wl%d\n", wl->pub->unit);
1425 brcms_c_reset(wl->wlc);
1427 /* dpc will not be rescheduled */
1434 * These are interrupt on/off entry points. Disable interrupts
1435 * during interrupt state transition.
1437 void brcms_intrson(struct brcms_info *wl)
1439 unsigned long flags;
1441 INT_LOCK(wl, flags);
1442 brcms_c_intrson(wl->wlc);
1443 INT_UNLOCK(wl, flags);
1447 * precondition: perimeter lock has been acquired
1449 bool wl_alloc_dma_resources(struct brcms_info *wl, uint addrwidth)
1454 u32 brcms_intrsoff(struct brcms_info *wl)
1456 unsigned long flags;
1459 INT_LOCK(wl, flags);
1460 status = brcms_c_intrsoff(wl->wlc);
1461 INT_UNLOCK(wl, flags);
1465 void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1467 unsigned long flags;
1469 INT_LOCK(wl, flags);
1470 brcms_c_intrsrestore(wl->wlc, macintmask);
1471 INT_UNLOCK(wl, flags);
1475 * precondition: perimeter lock has been acquired
1477 int brcms_up(struct brcms_info *wl)
1484 error = brcms_c_up(wl->wlc);
1490 * precondition: perimeter lock has been acquired
1492 void brcms_down(struct brcms_info *wl)
1494 uint callbacks, ret_val = 0;
1496 /* call common down function */
1497 ret_val = brcms_c_down(wl->wlc);
1498 callbacks = atomic_read(&wl->callbacks) - ret_val;
1500 /* wait for down callbacks to complete */
1503 /* For HIGH_only driver, it's important to actually schedule other work,
1504 * not just spin wait since everything runs at schedule level
1506 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1511 static irqreturn_t brcms_isr(int irq, void *dev_id)
1513 struct brcms_info *wl;
1515 unsigned long flags;
1517 wl = (struct brcms_info *) dev_id;
1519 ISR_LOCK(wl, flags);
1521 /* call common first level interrupt handler */
1522 ours = brcms_c_isr(wl->wlc, &wantdpc);
1524 /* if more to do... */
1527 /* ...and call the second level interrupt handler */
1529 tasklet_schedule(&wl->tasklet);
1533 ISR_UNLOCK(wl, flags);
1535 return IRQ_RETVAL(ours);
1538 static void brcms_dpc(unsigned long data)
1540 struct brcms_info *wl;
1542 wl = (struct brcms_info *) data;
1546 /* call the common second level interrupt handler */
1549 unsigned long flags;
1551 INT_LOCK(wl, flags);
1552 brcms_c_intrsupd(wl->wlc);
1553 INT_UNLOCK(wl, flags);
1556 wl->resched = brcms_c_dpc(wl->wlc, true);
1559 /* brcms_c_dpc() may bring the driver down */
1563 /* re-schedule dpc */
1565 tasklet_schedule(&wl->tasklet);
1567 /* re-enable interrupts */
1576 * is called by the kernel from software irq context
1578 static void brcms_timer(unsigned long data)
1580 _brcms_timer((struct brcms_timer *) data);
1584 * precondition: perimeter lock is not acquired
1586 static void _brcms_timer(struct brcms_timer *t)
1592 t->timer.expires = jiffies + t->ms * HZ / 1000;
1593 atomic_inc(&t->wl->callbacks);
1594 add_timer(&t->timer);
1602 atomic_dec(&t->wl->callbacks);
1608 * Adds a timer to the list. Caller supplies a timer function.
1609 * Is called from wlc.
1611 * precondition: perimeter lock has been acquired
1613 struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1614 void (*fn) (void *arg),
1615 void *arg, const char *name)
1617 struct brcms_timer *t;
1619 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1621 wiphy_err(wl->wiphy, "wl%d: brcms_init_timer: out of memory\n",
1626 init_timer(&t->timer);
1627 t->timer.data = (unsigned long) t;
1628 t->timer.function = brcms_timer;
1632 t->next = wl->timers;
1636 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1638 strcpy(t->name, name);
1644 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1645 * as well as it's easier to make it periodic
1647 * precondition: perimeter lock has been acquired
1649 void brcms_add_timer(struct brcms_info *wl, struct brcms_timer *t, uint ms,
1654 wiphy_err(wl->wiphy, "%s: Already set. Name: %s, per %d\n",
1655 __func__, t->name, periodic);
1659 t->periodic = (bool) periodic;
1661 t->timer.expires = jiffies + ms * HZ / 1000;
1663 atomic_inc(&wl->callbacks);
1664 add_timer(&t->timer);
1668 * return true if timer successfully deleted, false if still pending
1670 * precondition: perimeter lock has been acquired
1672 bool brcms_del_timer(struct brcms_info *wl, struct brcms_timer *t)
1676 if (!del_timer(&t->timer)) {
1679 atomic_dec(&wl->callbacks);
1686 * precondition: perimeter lock has been acquired
1688 void brcms_free_timer(struct brcms_info *wl, struct brcms_timer *t)
1690 struct brcms_timer *tmp;
1692 /* delete the timer in case it is active */
1693 brcms_del_timer(wl, t);
1695 if (wl->timers == t) {
1696 wl->timers = wl->timers->next;
1707 if (tmp->next == t) {
1708 tmp->next = t->next;
1721 * runs in software irq context
1723 * precondition: perimeter lock is not acquired
1725 static int wl_linux_watchdog(void *ctx)
1730 struct firmware_hdr {
1736 char *brcms_firmwares[MAX_FW_IMAGES] = {
1742 * precondition: perimeter lock has been acquired
1744 int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1748 struct firmware_hdr *hdr;
1749 for (i = 0; i < wl->fw.fw_cnt; i++) {
1750 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1751 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1753 if (hdr->idx == idx) {
1754 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1755 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1756 if (*pbuf == NULL) {
1757 wiphy_err(wl->wiphy, "fail to alloc %d"
1758 " bytes\n", hdr->len);
1761 memcpy(*pbuf, pdata, hdr->len);
1766 wiphy_err(wl->wiphy, "ERROR: ucode buf tag:%d can not be found!\n",
1774 * Precondition: Since this function is called in brcms_pci_probe() context,
1775 * no locking is required.
1777 int brcms_ucode_init_uint(struct brcms_info *wl, u32 *data, u32 idx)
1781 struct firmware_hdr *hdr;
1782 for (i = 0; i < wl->fw.fw_cnt; i++) {
1783 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1784 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1786 if (hdr->idx == idx) {
1787 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1788 if (hdr->len != 4) {
1789 wiphy_err(wl->wiphy,
1790 "ERROR: fw hdr len\n");
1793 *data = *((u32 *) pdata);
1798 wiphy_err(wl->wiphy, "ERROR: ucode tag:%d can not be found!\n", idx);
1803 * Precondition: Since this function is called in brcms_pci_probe() context,
1804 * no locking is required.
1806 static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev)
1809 struct device *device = &pdev->dev;
1813 memset((void *)&wl->fw, 0, sizeof(struct brcms_firmware));
1814 for (i = 0; i < MAX_FW_IMAGES; i++) {
1815 if (brcms_firmwares[i] == NULL)
1817 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
1818 UCODE_LOADER_API_VER);
1819 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1821 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
1822 KBUILD_MODNAME, fw_name);
1825 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
1826 UCODE_LOADER_API_VER);
1827 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1829 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
1830 KBUILD_MODNAME, fw_name);
1833 wl->fw.hdr_num_entries[i] =
1834 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
1837 return brcms_ucode_data_init(wl);
1841 * precondition: can both be called locked and unlocked
1843 void brcms_ucode_free_buf(void *p)
1849 * Precondition: Since this function is called in brcms_pci_probe() context,
1850 * no locking is required.
1852 static void brcms_release_fw(struct brcms_info *wl)
1855 for (i = 0; i < MAX_FW_IMAGES; i++) {
1856 release_firmware(wl->fw.fw_bin[i]);
1857 release_firmware(wl->fw.fw_hdr[i]);
1863 * checks validity of all firmware images loaded from user space
1865 * Precondition: Since this function is called in brcms_pci_probe() context,
1866 * no locking is required.
1868 int brcms_check_firmwares(struct brcms_info *wl)
1873 const struct firmware *fw;
1874 const struct firmware *fw_hdr;
1875 struct firmware_hdr *ucode_hdr;
1876 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1877 fw = wl->fw.fw_bin[i];
1878 fw_hdr = wl->fw.fw_hdr[i];
1879 if (fw == NULL && fw_hdr == NULL) {
1881 } else if (fw == NULL || fw_hdr == NULL) {
1882 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1885 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1886 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1887 "size %zu/%zu\n", __func__, fw_hdr->size,
1888 sizeof(struct firmware_hdr));
1890 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1891 wiphy_err(wl->wiphy, "%s: out of bounds fw file size "
1892 "%zu\n", __func__, fw->size);
1895 /* check if ucode section overruns firmware image */
1896 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1897 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1898 !rc; entry++, ucode_hdr++) {
1899 if (ucode_hdr->offset + ucode_hdr->len >
1901 wiphy_err(wl->wiphy,
1902 "%s: conflicting bin/hdr\n",
1909 if (rc == 0 && wl->fw.fw_cnt != i) {
1910 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1918 * precondition: perimeter lock has been acquired
1920 bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1922 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1925 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1927 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1933 * precondition: perimeter lock has been acquired
1935 void brcms_msleep(struct brcms_info *wl, uint ms)