2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #define __UNDEF_NO_VERSION__
19 #include <linux/kernel.h>
20 #include <linux/etherdevice.h>
21 #include <linux/types.h>
22 #include <linux/pci_ids.h>
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/sched.h>
26 #include <linux/firmware.h>
27 #include <net/mac80211.h>
35 #include "phy/wlc_phy_int.h"
37 #include "wlc_types.h"
40 #include "wlc_channel.h"
44 #include "wl_export.h"
45 #include "ucode_loader.h"
46 #include "brcms_mac80211.h"
48 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
50 #define LOCK(wl) spin_lock_bh(&(wl)->lock)
51 #define UNLOCK(wl) spin_unlock_bh(&(wl)->lock)
53 /* locking from inside brcms_isr */
54 #define ISR_LOCK(wl, flags)\
56 spin_lock(&(wl)->isr_lock);\
60 #define ISR_UNLOCK(wl, flags)\
62 spin_unlock(&(wl)->isr_lock);\
66 /* locking under LOCK() to synchronize with brcms_isr */
67 #define INT_LOCK(wl, flags) spin_lock_irqsave(&(wl)->isr_lock, flags)
68 #define INT_UNLOCK(wl, flags) spin_unlock_irqrestore(&(wl)->isr_lock, flags)
70 static void brcms_timer(unsigned long data
);
71 static void _brcms_timer(struct brcms_timer
*t
);
74 static int ieee_hw_init(struct ieee80211_hw
*hw
);
75 static int ieee_hw_rate_init(struct ieee80211_hw
*hw
);
77 static int wl_linux_watchdog(void *ctx
);
79 /* Flags we support */
80 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
86 FIF_BCN_PRBRESP_PROMISC)
88 static int n_adapters_found
;
90 static int brcms_request_fw(struct brcms_info
*wl
, struct pci_dev
*pdev
);
91 static void brcms_release_fw(struct brcms_info
*wl
);
93 /* local prototypes */
94 static void brcms_dpc(unsigned long data
);
95 static irqreturn_t
brcms_isr(int irq
, void *dev_id
);
97 static int __devinit
brcms_pci_probe(struct pci_dev
*pdev
,
98 const struct pci_device_id
*ent
);
99 static void brcms_remove(struct pci_dev
*pdev
);
100 static void brcms_free(struct brcms_info
*wl
);
101 static void brcms_set_basic_rate(struct wl_rateset
*rs
, u16 rate
, bool is_br
);
103 MODULE_AUTHOR("Broadcom Corporation");
104 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
105 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
106 MODULE_LICENSE("Dual BSD/GPL");
108 /* recognized PCI IDs */
109 static DEFINE_PCI_DEVICE_TABLE(brcms_pci_id_table
) = {
110 {PCI_VENDOR_ID_BROADCOM
, 0x4357, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, /* 43225 2G */
111 {PCI_VENDOR_ID_BROADCOM
, 0x4353, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, /* 43224 DUAL */
112 {PCI_VENDOR_ID_BROADCOM
, 0x4727, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, /* 4313 DUAL */
114 {PCI_VENDOR_ID_BROADCOM
, 0x0576, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
118 MODULE_DEVICE_TABLE(pci
, brcms_pci_id_table
);
121 static int msglevel
= 0xdeadbeef;
122 module_param(msglevel
, int, 0);
123 static int phymsglevel
= 0xdeadbeef;
124 module_param(phymsglevel
, int, 0);
127 #define HW_TO_WL(hw) (hw->priv)
128 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
130 /* MAC80211 callback functions */
131 static int brcms_ops_start(struct ieee80211_hw
*hw
);
132 static void brcms_ops_stop(struct ieee80211_hw
*hw
);
133 static int brcms_ops_add_interface(struct ieee80211_hw
*hw
,
134 struct ieee80211_vif
*vif
);
135 static void brcms_ops_remove_interface(struct ieee80211_hw
*hw
,
136 struct ieee80211_vif
*vif
);
137 static int brcms_ops_config(struct ieee80211_hw
*hw
, u32 changed
);
138 static void brcms_ops_bss_info_changed(struct ieee80211_hw
*hw
,
139 struct ieee80211_vif
*vif
,
140 struct ieee80211_bss_conf
*info
,
142 static void brcms_ops_configure_filter(struct ieee80211_hw
*hw
,
143 unsigned int changed_flags
,
144 unsigned int *total_flags
, u64 multicast
);
145 static int brcms_ops_set_tim(struct ieee80211_hw
*hw
, struct ieee80211_sta
*sta
,
147 static void brcms_ops_sw_scan_start(struct ieee80211_hw
*hw
);
148 static void brcms_ops_sw_scan_complete(struct ieee80211_hw
*hw
);
149 static void brcms_ops_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
);
150 static int brcms_ops_get_stats(struct ieee80211_hw
*hw
,
151 struct ieee80211_low_level_stats
*stats
);
152 static void brcms_ops_sta_notify(struct ieee80211_hw
*hw
,
153 struct ieee80211_vif
*vif
,
154 enum sta_notify_cmd cmd
,
155 struct ieee80211_sta
*sta
);
156 static int brcms_ops_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
157 const struct ieee80211_tx_queue_params
*params
);
158 static u64
brcms_ops_get_tsf(struct ieee80211_hw
*hw
);
159 static int brcms_ops_sta_add(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
160 struct ieee80211_sta
*sta
);
161 static int brcms_ops_sta_remove(struct ieee80211_hw
*hw
,
162 struct ieee80211_vif
*vif
,
163 struct ieee80211_sta
*sta
);
164 static int brcms_ops_ampdu_action(struct ieee80211_hw
*hw
,
165 struct ieee80211_vif
*vif
,
166 enum ieee80211_ampdu_mlme_action action
,
167 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
169 static void brcms_ops_rfkill_poll(struct ieee80211_hw
*hw
);
170 static void brcms_ops_flush(struct ieee80211_hw
*hw
, bool drop
);
172 static void brcms_ops_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
174 struct brcms_info
*wl
= hw
->priv
;
178 wiphy_err(wl
->wiphy
, "ops->tx called while down\n");
182 wlc_sendpkt_mac80211(wl
->wlc
, skb
, hw
);
187 static int brcms_ops_start(struct ieee80211_hw
*hw
)
189 struct brcms_info
*wl
= hw
->priv
;
192 struct ieee80211_channel *curchan = hw->conf.channel;
195 ieee80211_wake_queues(hw
);
197 blocked
= brcms_rfkill_set_hw_state(wl
);
200 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
205 static void brcms_ops_stop(struct ieee80211_hw
*hw
)
207 ieee80211_stop_queues(hw
);
211 brcms_ops_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
213 struct brcms_info
*wl
;
216 /* Just STA for now */
217 if (vif
->type
!= NL80211_IFTYPE_AP
&&
218 vif
->type
!= NL80211_IFTYPE_MESH_POINT
&&
219 vif
->type
!= NL80211_IFTYPE_STATION
&&
220 vif
->type
!= NL80211_IFTYPE_WDS
&&
221 vif
->type
!= NL80211_IFTYPE_ADHOC
) {
222 wiphy_err(hw
->wiphy
, "%s: Attempt to add type %d, only"
223 " STA for now\n", __func__
, vif
->type
);
233 wiphy_err(hw
->wiphy
, "%s: brcms_up() returned %d\n", __func__
,
240 brcms_ops_remove_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
242 struct brcms_info
*wl
;
246 /* put driver in down state */
253 * precondition: perimeter lock has been acquired
256 ieee_set_channel(struct ieee80211_hw
*hw
, struct ieee80211_channel
*chan
,
257 enum nl80211_channel_type type
)
259 struct brcms_info
*wl
= HW_TO_WL(hw
);
263 case NL80211_CHAN_HT20
:
264 case NL80211_CHAN_NO_HT
:
265 err
= wlc_set(wl
->wlc
, WLC_SET_CHANNEL
, chan
->hw_value
);
267 case NL80211_CHAN_HT40MINUS
:
268 case NL80211_CHAN_HT40PLUS
:
270 "%s: Need to implement 40 Mhz Channels!\n", __func__
);
280 static int brcms_ops_config(struct ieee80211_hw
*hw
, u32 changed
)
282 struct ieee80211_conf
*conf
= &hw
->conf
;
283 struct brcms_info
*wl
= HW_TO_WL(hw
);
286 struct wiphy
*wiphy
= hw
->wiphy
;
289 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
290 if (wlc_set_par(wl
->wlc
, IOV_BCN_LI_BCN
, conf
->listen_interval
)
292 wiphy_err(wiphy
, "%s: Error setting listen_interval\n",
297 wlc_get_par(wl
->wlc
, IOV_BCN_LI_BCN
, &new_int
);
299 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
)
300 wiphy_err(wiphy
, "%s: change monitor mode: %s (implement)\n",
301 __func__
, conf
->flags
& IEEE80211_CONF_MONITOR
?
303 if (changed
& IEEE80211_CONF_CHANGE_PS
)
304 wiphy_err(wiphy
, "%s: change power-save mode: %s (implement)\n",
305 __func__
, conf
->flags
& IEEE80211_CONF_PS
?
308 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
309 if (wlc_set_par(wl
->wlc
, IOV_QTXPOWER
, conf
->power_level
* 4)
311 wiphy_err(wiphy
, "%s: Error setting power_level\n",
316 wlc_get_par(wl
->wlc
, IOV_QTXPOWER
, &new_int
);
317 if (new_int
!= (conf
->power_level
* 4))
318 wiphy_err(wiphy
, "%s: Power level req != actual, %d %d"
319 "\n", __func__
, conf
->power_level
* 4,
322 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
323 err
= ieee_set_channel(hw
, conf
->channel
, conf
->channel_type
);
325 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
327 (wl
->wlc
, WLC_SET_SRL
,
328 conf
->short_frame_max_tx_count
) < 0) {
329 wiphy_err(wiphy
, "%s: Error setting srl\n", __func__
);
333 if (wlc_set(wl
->wlc
, WLC_SET_LRL
, conf
->long_frame_max_tx_count
)
335 wiphy_err(wiphy
, "%s: Error setting lrl\n", __func__
);
347 brcms_ops_bss_info_changed(struct ieee80211_hw
*hw
,
348 struct ieee80211_vif
*vif
,
349 struct ieee80211_bss_conf
*info
, u32 changed
)
351 struct brcms_info
*wl
= HW_TO_WL(hw
);
352 struct wiphy
*wiphy
= hw
->wiphy
;
355 if (changed
& BSS_CHANGED_ASSOC
) {
356 /* association status changed (associated/disassociated)
357 * also implies a change in the AID.
359 wiphy_err(wiphy
, "%s: %s: %sassociated\n", KBUILD_MODNAME
,
360 __func__
, info
->assoc
? "" : "dis");
362 wlc_associate_upd(wl
->wlc
, info
->assoc
);
365 if (changed
& BSS_CHANGED_ERP_SLOT
) {
366 /* slot timing changed */
367 if (info
->use_short_slot
)
372 wlc_set(wl
->wlc
, WLC_SET_SHORTSLOT_OVERRIDE
, val
);
376 if (changed
& BSS_CHANGED_HT
) {
377 /* 802.11n parameters changed */
378 u16 mode
= info
->ht_operation_mode
;
381 wlc_protection_upd(wl
->wlc
, WLC_PROT_N_CFG
,
382 mode
& IEEE80211_HT_OP_MODE_PROTECTION
);
383 wlc_protection_upd(wl
->wlc
, WLC_PROT_N_NONGF
,
384 mode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
385 wlc_protection_upd(wl
->wlc
, WLC_PROT_N_OBSS
,
386 mode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
);
389 if (changed
& BSS_CHANGED_BASIC_RATES
) {
390 struct ieee80211_supported_band
*bi
;
393 struct wl_rateset rs
;
396 /* retrieve the current rates */
398 error
= wlc_ioctl(wl
->wlc
, WLC_GET_CURR_RATESET
,
399 &rs
, sizeof(rs
), NULL
);
402 wiphy_err(wiphy
, "%s: retrieve rateset failed: %d\n",
406 br_mask
= info
->basic_rates
;
407 bi
= hw
->wiphy
->bands
[wlc_get_curband(wl
->wlc
)];
408 for (i
= 0; i
< bi
->n_bitrates
; i
++) {
409 /* convert to internal rate value */
410 rate
= (bi
->bitrates
[i
].bitrate
<< 1) / 10;
412 /* set/clear basic rate flag */
413 brcms_set_basic_rate(&rs
, rate
, br_mask
& 1);
417 /* update the rate set */
419 wlc_ioctl(wl
->wlc
, WLC_SET_RATESET
, &rs
, sizeof(rs
), NULL
);
422 if (changed
& BSS_CHANGED_BEACON_INT
) {
423 /* Beacon interval changed */
425 wlc_set(wl
->wlc
, WLC_SET_BCNPRD
, info
->beacon_int
);
428 if (changed
& BSS_CHANGED_BSSID
) {
429 /* BSSID changed, for whatever reason (IBSS and managed mode) */
431 wlc_set_addrmatch(wl
->wlc
, RCM_BSSID_OFFSET
,
435 if (changed
& BSS_CHANGED_BEACON
) {
436 /* Beacon data changed, retrieve new beacon (beaconing modes) */
437 wiphy_err(wiphy
, "%s: beacon changed\n", __func__
);
439 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
440 /* Beaconing should be enabled/disabled (beaconing modes) */
441 wiphy_err(wiphy
, "%s: Beacon enabled: %s\n", __func__
,
442 info
->enable_beacon
? "true" : "false");
444 if (changed
& BSS_CHANGED_CQM
) {
445 /* Connection quality monitor config changed */
446 wiphy_err(wiphy
, "%s: cqm change: threshold %d, hys %d "
447 " (implement)\n", __func__
, info
->cqm_rssi_thold
,
448 info
->cqm_rssi_hyst
);
450 if (changed
& BSS_CHANGED_IBSS
) {
451 /* IBSS join status changed */
452 wiphy_err(wiphy
, "%s: IBSS joined: %s (implement)\n", __func__
,
453 info
->ibss_joined
? "true" : "false");
455 if (changed
& BSS_CHANGED_ARP_FILTER
) {
456 /* Hardware ARP filter address list or state changed */
457 wiphy_err(wiphy
, "%s: arp filtering: enabled %s, count %d"
458 " (implement)\n", __func__
, info
->arp_filter_enabled
?
459 "true" : "false", info
->arp_addr_cnt
);
461 if (changed
& BSS_CHANGED_QOS
) {
463 * QoS for this association was enabled/disabled.
464 * Note that it is only ever disabled for station mode.
466 wiphy_err(wiphy
, "%s: qos enabled: %s (implement)\n", __func__
,
467 info
->qos
? "true" : "false");
469 if (changed
& BSS_CHANGED_IDLE
) {
470 /* Idle changed for this BSS/interface */
471 wiphy_err(wiphy
, "%s: BSS idle: %s (implement)\n", __func__
,
472 info
->idle
? "true" : "false");
478 brcms_ops_configure_filter(struct ieee80211_hw
*hw
,
479 unsigned int changed_flags
,
480 unsigned int *total_flags
, u64 multicast
)
482 struct brcms_info
*wl
= hw
->priv
;
483 struct wiphy
*wiphy
= hw
->wiphy
;
485 changed_flags
&= MAC_FILTERS
;
486 *total_flags
&= MAC_FILTERS
;
487 if (changed_flags
& FIF_PROMISC_IN_BSS
)
488 wiphy_err(wiphy
, "FIF_PROMISC_IN_BSS\n");
489 if (changed_flags
& FIF_ALLMULTI
)
490 wiphy_err(wiphy
, "FIF_ALLMULTI\n");
491 if (changed_flags
& FIF_FCSFAIL
)
492 wiphy_err(wiphy
, "FIF_FCSFAIL\n");
493 if (changed_flags
& FIF_PLCPFAIL
)
494 wiphy_err(wiphy
, "FIF_PLCPFAIL\n");
495 if (changed_flags
& FIF_CONTROL
)
496 wiphy_err(wiphy
, "FIF_CONTROL\n");
497 if (changed_flags
& FIF_OTHER_BSS
)
498 wiphy_err(wiphy
, "FIF_OTHER_BSS\n");
499 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
501 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
) {
502 wl
->pub
->mac80211_state
|= MAC80211_PROMISC_BCNS
;
503 wlc_mac_bcn_promisc_change(wl
->wlc
, 1);
505 wlc_mac_bcn_promisc_change(wl
->wlc
, 0);
506 wl
->pub
->mac80211_state
&= ~MAC80211_PROMISC_BCNS
;
514 brcms_ops_set_tim(struct ieee80211_hw
*hw
, struct ieee80211_sta
*sta
, bool set
)
519 static void brcms_ops_sw_scan_start(struct ieee80211_hw
*hw
)
521 struct brcms_info
*wl
= hw
->priv
;
523 wlc_scan_start(wl
->wlc
);
528 static void brcms_ops_sw_scan_complete(struct ieee80211_hw
*hw
)
530 struct brcms_info
*wl
= hw
->priv
;
532 wlc_scan_stop(wl
->wlc
);
537 static void brcms_ops_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
539 wiphy_err(hw
->wiphy
, "%s: Enter\n", __func__
);
544 brcms_ops_get_stats(struct ieee80211_hw
*hw
,
545 struct ieee80211_low_level_stats
*stats
)
547 struct brcms_info
*wl
= hw
->priv
;
552 stats
->dot11ACKFailureCount
= 0;
553 stats
->dot11RTSFailureCount
= 0;
554 stats
->dot11FCSErrorCount
= 0;
555 stats
->dot11RTSSuccessCount
= 0;
561 brcms_ops_sta_notify(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
562 enum sta_notify_cmd cmd
, struct ieee80211_sta
*sta
)
566 wiphy_err(hw
->wiphy
, "%s: Unknown cmd = %d\n", __func__
,
574 brcms_ops_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
575 const struct ieee80211_tx_queue_params
*params
)
577 struct brcms_info
*wl
= hw
->priv
;
580 wlc_wme_setparams(wl
->wlc
, queue
, params
, true);
586 static u64
brcms_ops_get_tsf(struct ieee80211_hw
*hw
)
588 wiphy_err(hw
->wiphy
, "%s: Enter\n", __func__
);
593 brcms_ops_sta_add(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
594 struct ieee80211_sta
*sta
)
599 struct brcms_info
*wl
= hw
->priv
;
602 scb
= (struct scb
*)sta
->drv_priv
;
603 memset(scb
, 0, sizeof(struct scb
));
604 for (i
= 0; i
< NUMPRIO
; i
++)
605 scb
->seqctl
[i
] = 0xFFFF;
606 scb
->seqctl_nonqos
= 0xFFFF;
607 scb
->magic
= SCB_MAGIC
;
609 wl
->pub
->global_scb
= scb
;
610 wl
->pub
->global_ampdu
= &(scb
->scb_ampdu
);
611 wl
->pub
->global_ampdu
->scb
= scb
;
612 wl
->pub
->global_ampdu
->max_pdu
= 16;
613 bcm_pktq_init(&scb
->scb_ampdu
.txq
, AMPDU_MAX_SCB_TID
,
614 AMPDU_MAX_SCB_TID
* PKTQ_LEN_DEFAULT
);
616 sta
->ht_cap
.ht_supported
= true;
617 sta
->ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
618 sta
->ht_cap
.ampdu_density
= AMPDU_DEF_MPDU_DENSITY
;
619 sta
->ht_cap
.cap
= IEEE80211_HT_CAP_GRN_FLD
|
620 IEEE80211_HT_CAP_SGI_20
|
621 IEEE80211_HT_CAP_SGI_40
| IEEE80211_HT_CAP_40MHZ_INTOLERANT
;
623 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
628 brcms_ops_sta_remove(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
629 struct ieee80211_sta
*sta
)
635 brcms_ops_ampdu_action(struct ieee80211_hw
*hw
,
636 struct ieee80211_vif
*vif
,
637 enum ieee80211_ampdu_mlme_action action
,
638 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
641 struct scb
*scb
= (struct scb
*)sta
->drv_priv
;
642 struct brcms_info
*wl
= hw
->priv
;
645 if (WARN_ON(scb
->magic
!= SCB_MAGIC
))
648 case IEEE80211_AMPDU_RX_START
:
650 case IEEE80211_AMPDU_RX_STOP
:
652 case IEEE80211_AMPDU_TX_START
:
654 status
= wlc_aggregatable(wl
->wlc
, tid
);
657 wiphy_err(wl
->wiphy
, "START: tid %d is not agg\'able\n",
661 /* XXX: Use the starting sequence number provided ... */
663 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
666 case IEEE80211_AMPDU_TX_STOP
:
668 wlc_ampdu_flush(wl
->wlc
, sta
, tid
);
670 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
672 case IEEE80211_AMPDU_TX_OPERATIONAL
:
673 /* Not sure what to do here */
674 /* Power save wakeup */
677 wiphy_err(wl
->wiphy
, "%s: Invalid command, ignoring\n",
684 static void brcms_ops_rfkill_poll(struct ieee80211_hw
*hw
)
686 struct brcms_info
*wl
= HW_TO_WL(hw
);
690 blocked
= wlc_check_radio_disabled(wl
->wlc
);
693 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
696 static void brcms_ops_flush(struct ieee80211_hw
*hw
, bool drop
)
698 struct brcms_info
*wl
= HW_TO_WL(hw
);
700 no_printk("%s: drop = %s\n", __func__
, drop
? "true" : "false");
702 /* wait for packet queue and dma fifos to run empty */
704 wlc_wait_for_tx_completion(wl
->wlc
, drop
);
708 static const struct ieee80211_ops brcms_ops
= {
710 .start
= brcms_ops_start
,
711 .stop
= brcms_ops_stop
,
712 .add_interface
= brcms_ops_add_interface
,
713 .remove_interface
= brcms_ops_remove_interface
,
714 .config
= brcms_ops_config
,
715 .bss_info_changed
= brcms_ops_bss_info_changed
,
716 .configure_filter
= brcms_ops_configure_filter
,
717 .set_tim
= brcms_ops_set_tim
,
718 .sw_scan_start
= brcms_ops_sw_scan_start
,
719 .sw_scan_complete
= brcms_ops_sw_scan_complete
,
720 .set_tsf
= brcms_ops_set_tsf
,
721 .get_stats
= brcms_ops_get_stats
,
722 .sta_notify
= brcms_ops_sta_notify
,
723 .conf_tx
= brcms_ops_conf_tx
,
724 .get_tsf
= brcms_ops_get_tsf
,
725 .sta_add
= brcms_ops_sta_add
,
726 .sta_remove
= brcms_ops_sta_remove
,
727 .ampdu_action
= brcms_ops_ampdu_action
,
728 .rfkill_poll
= brcms_ops_rfkill_poll
,
729 .flush
= brcms_ops_flush
,
733 * is called in brcms_pci_probe() context, therefore no locking required.
735 static int brcms_set_hint(struct brcms_info
*wl
, char *abbrev
)
737 return regulatory_hint(wl
->pub
->ieee_hw
->wiphy
, abbrev
);
741 * attach to the WL device.
743 * Attach to the WL device identified by vendor and device parameters.
744 * regs is a host accessible memory address pointing to WL device registers.
746 * brcms_attach is not defined as static because in the case where no bus
747 * is defined, wl_attach will never be called, and thus, gcc will issue
748 * a warning that this function is defined but not used if we declare
752 * is called in brcms_pci_probe() context, therefore no locking required.
754 static struct brcms_info
*brcms_attach(u16 vendor
, u16 device
,
756 uint bustype
, void *btparam
, uint irq
)
758 struct brcms_info
*wl
= NULL
;
760 unsigned long base_addr
;
761 struct ieee80211_hw
*hw
;
764 unit
= n_adapters_found
;
771 /* allocate private info */
772 hw
= pci_get_drvdata(btparam
); /* btparam == pdev */
775 if (WARN_ON(hw
== NULL
) || WARN_ON(wl
== NULL
))
777 wl
->wiphy
= hw
->wiphy
;
779 atomic_set(&wl
->callbacks
, 0);
781 /* setup the bottom half handler */
782 tasklet_init(&wl
->tasklet
, brcms_dpc
, (unsigned long) wl
);
788 if (bustype
== PCI_BUS
|| bustype
== RPC_BUS
) {
792 BCMMSG(wl
->wiphy
, "force to PCI\n");
794 wl
->bcm_bustype
= bustype
;
796 wl
->regsva
= ioremap_nocache(base_addr
, PCI_BAR0_WINSZ
);
797 if (wl
->regsva
== NULL
) {
798 wiphy_err(wl
->wiphy
, "wl%d: ioremap() failed\n", unit
);
801 spin_lock_init(&wl
->lock
);
802 spin_lock_init(&wl
->isr_lock
);
805 if (brcms_request_fw(wl
, (struct pci_dev
*)btparam
) < 0) {
806 wiphy_err(wl
->wiphy
, "%s: Failed to find firmware usually in "
807 "%s\n", KBUILD_MODNAME
, "/lib/firmware/brcm");
808 brcms_release_fw(wl
);
809 brcms_remove((struct pci_dev
*)btparam
);
813 /* common load-time initialization */
814 wl
->wlc
= wlc_attach((void *)wl
, vendor
, device
, unit
, false,
815 wl
->regsva
, wl
->bcm_bustype
, btparam
, &err
);
816 brcms_release_fw(wl
);
818 wiphy_err(wl
->wiphy
, "%s: wlc_attach() failed with code %d\n",
819 KBUILD_MODNAME
, err
);
822 wl
->pub
= wlc_pub(wl
->wlc
);
824 wl
->pub
->ieee_hw
= hw
;
826 if (wlc_set_par(wl
->wlc
, IOV_MPC
, 0) < 0) {
827 wiphy_err(wl
->wiphy
, "wl%d: Error setting MPC variable to 0\n",
831 /* register our interrupt handler */
832 if (request_irq(irq
, brcms_isr
, IRQF_SHARED
, KBUILD_MODNAME
, wl
)) {
833 wiphy_err(wl
->wiphy
, "wl%d: request_irq() failed\n", unit
);
838 /* register module */
839 wlc_module_register(wl
->pub
, "linux", wl
, wl_linux_watchdog
, NULL
);
841 if (ieee_hw_init(hw
)) {
842 wiphy_err(wl
->wiphy
, "wl%d: %s: ieee_hw_init failed!\n", unit
,
847 memcpy(perm
, &wl
->pub
->cur_etheraddr
, ETH_ALEN
);
848 if (WARN_ON(!is_valid_ether_addr(perm
)))
850 SET_IEEE80211_PERM_ADDR(hw
, perm
);
852 err
= ieee80211_register_hw(hw
);
854 wiphy_err(wl
->wiphy
, "%s: ieee80211_register_hw failed, status"
855 "%d\n", __func__
, err
);
858 if (wl
->pub
->srom_ccode
[0])
859 err
= brcms_set_hint(wl
, wl
->pub
->srom_ccode
);
861 err
= brcms_set_hint(wl
, "US");
863 wiphy_err(wl
->wiphy
, "%s: regulatory_hint failed, status %d\n",
877 #define CHAN2GHZ(channel, freqency, chflags) { \
878 .band = IEEE80211_BAND_2GHZ, \
879 .center_freq = (freqency), \
880 .hw_value = (channel), \
882 .max_antenna_gain = 0, \
886 static struct ieee80211_channel brcms_2ghz_chantable
[] = {
887 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS
),
888 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS
),
889 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS
),
890 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS
),
891 CHAN2GHZ(5, 2432, 0),
892 CHAN2GHZ(6, 2437, 0),
893 CHAN2GHZ(7, 2442, 0),
894 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS
),
895 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS
),
896 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS
),
897 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS
),
899 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
900 IEEE80211_CHAN_NO_HT40PLUS
),
902 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
903 IEEE80211_CHAN_NO_HT40PLUS
),
905 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
906 IEEE80211_CHAN_NO_HT40PLUS
| IEEE80211_CHAN_NO_HT40MINUS
)
909 #define CHAN5GHZ(channel, chflags) { \
910 .band = IEEE80211_BAND_5GHZ, \
911 .center_freq = 5000 + 5*(channel), \
912 .hw_value = (channel), \
914 .max_antenna_gain = 0, \
918 static struct ieee80211_channel brcms_5ghz_nphy_chantable
[] = {
920 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS
),
921 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS
),
922 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS
),
923 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS
),
926 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
927 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
929 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
930 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
),
939 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
940 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
942 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
943 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
945 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
946 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
948 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
949 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
951 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
952 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
954 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
955 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
957 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
958 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
960 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
961 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
963 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
964 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
966 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
967 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
969 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
970 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
|
971 IEEE80211_CHAN_NO_HT40MINUS
),
973 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS
),
974 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS
),
975 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS
),
976 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS
),
977 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS
| IEEE80211_CHAN_NO_HT40MINUS
)
980 #define RATE(rate100m, _flags) { \
981 .bitrate = (rate100m), \
983 .hw_value = (rate100m / 5), \
986 static struct ieee80211_rate legacy_ratetable
[] = {
988 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE
),
989 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE
),
990 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE
),
1001 static struct ieee80211_supported_band brcms_band_2GHz_nphy
= {
1002 .band
= IEEE80211_BAND_2GHZ
,
1003 .channels
= brcms_2ghz_chantable
,
1004 .n_channels
= ARRAY_SIZE(brcms_2ghz_chantable
),
1005 .bitrates
= legacy_ratetable
,
1006 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
),
1008 /* from include/linux/ieee80211.h */
1009 .cap
= IEEE80211_HT_CAP_GRN_FLD
|
1010 IEEE80211_HT_CAP_SGI_20
|
1011 IEEE80211_HT_CAP_SGI_40
| IEEE80211_HT_CAP_40MHZ_INTOLERANT
,
1012 .ht_supported
= true,
1013 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
1014 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
1016 /* placeholders for now */
1017 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1019 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
1023 static struct ieee80211_supported_band brcms_band_5GHz_nphy
= {
1024 .band
= IEEE80211_BAND_5GHZ
,
1025 .channels
= brcms_5ghz_nphy_chantable
,
1026 .n_channels
= ARRAY_SIZE(brcms_5ghz_nphy_chantable
),
1027 .bitrates
= legacy_ratetable
+ 4,
1028 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
) - 4,
1030 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1031 .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 */
1032 .ht_supported
= true,
1033 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
1034 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
1036 /* placeholders for now */
1037 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1039 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
1044 * is called in brcms_pci_probe() context, therefore no locking required.
1046 static int ieee_hw_rate_init(struct ieee80211_hw
*hw
)
1048 struct brcms_info
*wl
= HW_TO_WL(hw
);
1054 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = NULL
;
1055 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = NULL
;
1057 if (wlc_get(wl
->wlc
, WLC_GET_PHYLIST
, (int *)&phy_list
) < 0) {
1058 wiphy_err(hw
->wiphy
, "Phy list failed\n");
1061 if (phy_list
[0] == 'n' || phy_list
[0] == 'c') {
1062 if (phy_list
[0] == 'c') {
1064 brcms_band_2GHz_nphy
.ht_cap
.mcs
.rx_mask
[1] = 0;
1065 brcms_band_2GHz_nphy
.ht_cap
.mcs
.rx_highest
= 72;
1067 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &brcms_band_2GHz_nphy
;
1072 /* Assume all bands use the same phy. True for 11n devices. */
1073 if (NBANDS_PUB(wl
->pub
) > 1) {
1075 if (phy_list
[0] == 'n' || phy_list
[0] == 'c') {
1076 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
1077 &brcms_band_5GHz_nphy
;
1086 * is called in brcms_pci_probe() context, therefore no locking required.
1088 static int ieee_hw_init(struct ieee80211_hw
*hw
)
1090 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
1091 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1092 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1093 | IEEE80211_HW_AMPDU_AGGREGATION
;
1095 hw
->extra_tx_headroom
= wlc_get_header_len();
1096 hw
->queues
= N_TX_QUEUES
;
1097 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1098 * mac80211/status.c:ieee80211_tx_status() checks this value,
1099 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1100 * appears to always set 3 rates
1102 hw
->max_rates
= 2; /* Primary rate and 1 fallback rate */
1104 hw
->channel_change_time
= 7 * 1000; /* channel change time is dependent on chip and band */
1105 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
1107 hw
->rate_control_algorithm
= "minstrel_ht";
1109 hw
->sta_data_size
= sizeof(struct scb
);
1110 return ieee_hw_rate_init(hw
);
1114 * determines if a device is a WL device, and if so, attaches it.
1116 * This function determines if a device pointed to by pdev is a WL device,
1117 * and if so, performs a brcms_attach() on it.
1119 * Perimeter lock is initialized in the course of this function.
1121 static int __devinit
1122 brcms_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1125 struct brcms_info
*wl
;
1126 struct ieee80211_hw
*hw
;
1129 dev_info(&pdev
->dev
, "bus %d slot %d func %d irq %d\n",
1130 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
),
1131 PCI_FUNC(pdev
->devfn
), pdev
->irq
);
1133 if ((pdev
->vendor
!= PCI_VENDOR_ID_BROADCOM
) ||
1134 ((pdev
->device
!= 0x0576) &&
1135 ((pdev
->device
& 0xff00) != 0x4300) &&
1136 ((pdev
->device
& 0xff00) != 0x4700) &&
1137 ((pdev
->device
< 43000) || (pdev
->device
> 43999))))
1140 rc
= pci_enable_device(pdev
);
1142 pr_err("%s: Cannot enable device %d-%d_%d\n",
1143 __func__
, pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
),
1144 PCI_FUNC(pdev
->devfn
));
1147 pci_set_master(pdev
);
1149 pci_read_config_dword(pdev
, 0x40, &val
);
1150 if ((val
& 0x0000ff00) != 0)
1151 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
1153 hw
= ieee80211_alloc_hw(sizeof(struct brcms_info
), &brcms_ops
);
1155 pr_err("%s: ieee80211_alloc_hw failed\n", __func__
);
1159 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1161 pci_set_drvdata(pdev
, hw
);
1163 memset(hw
->priv
, 0, sizeof(*wl
));
1165 wl
= brcms_attach(pdev
->vendor
, pdev
->device
,
1166 pci_resource_start(pdev
, 0), PCI_BUS
, pdev
,
1170 pr_err("%s: %s: brcms_attach failed!\n", KBUILD_MODNAME
,
1177 static int brcms_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1179 struct brcms_info
*wl
;
1180 struct ieee80211_hw
*hw
;
1182 hw
= pci_get_drvdata(pdev
);
1185 wiphy_err(wl
->wiphy
,
1186 "brcms_suspend: pci_get_drvdata failed\n");
1190 /* only need to flag hw is down for proper resume */
1192 wl
->pub
->hw_up
= false;
1195 pci_save_state(pdev
);
1196 pci_disable_device(pdev
);
1197 return pci_set_power_state(pdev
, PCI_D3hot
);
1200 static int brcms_resume(struct pci_dev
*pdev
)
1202 struct brcms_info
*wl
;
1203 struct ieee80211_hw
*hw
;
1207 hw
= pci_get_drvdata(pdev
);
1210 wiphy_err(wl
->wiphy
,
1211 "wl: brcms_resume: pci_get_drvdata failed\n");
1215 err
= pci_set_power_state(pdev
, PCI_D0
);
1219 pci_restore_state(pdev
);
1221 err
= pci_enable_device(pdev
);
1225 pci_set_master(pdev
);
1227 pci_read_config_dword(pdev
, 0x40, &val
);
1228 if ((val
& 0x0000ff00) != 0)
1229 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
1232 * done. driver will be put in up state
1233 * in brcms_ops_add_interface() call.
1239 * called from both kernel as from this kernel module.
1240 * precondition: perimeter lock is not acquired.
1242 static void brcms_remove(struct pci_dev
*pdev
)
1244 struct brcms_info
*wl
;
1245 struct ieee80211_hw
*hw
;
1248 hw
= pci_get_drvdata(pdev
);
1251 pr_err("wl: brcms_remove: pci_get_drvdata failed\n");
1256 status
= wlc_chipmatch(pdev
->vendor
, pdev
->device
);
1259 wiphy_err(wl
->wiphy
, "wl: brcms_remove: wlc_chipmatch "
1264 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, false);
1265 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
1266 ieee80211_unregister_hw(hw
);
1271 pci_disable_device(pdev
);
1275 pci_set_drvdata(pdev
, NULL
);
1276 ieee80211_free_hw(hw
);
1279 static struct pci_driver brcms_pci_driver
= {
1280 .name
= KBUILD_MODNAME
,
1281 .probe
= brcms_pci_probe
,
1282 .suspend
= brcms_suspend
,
1283 .resume
= brcms_resume
,
1284 .remove
= __devexit_p(brcms_remove
),
1285 .id_table
= brcms_pci_id_table
,
1289 * This is the main entry point for the WL driver.
1291 * This function determines if a device pointed to by pdev is a WL device,
1292 * and if so, performs a brcms_attach() on it.
1295 static int __init
brcms_module_init(void)
1297 int error
= -ENODEV
;
1300 if (msglevel
!= 0xdeadbeef)
1301 brcm_msg_level
= msglevel
;
1303 char *var
= getvar(NULL
, "wl_msglevel");
1305 unsigned long value
;
1307 (void)strict_strtoul(var
, 0, &value
);
1308 brcm_msg_level
= value
;
1311 if (phymsglevel
!= 0xdeadbeef)
1312 phyhal_msg_level
= phymsglevel
;
1314 char *var
= getvar(NULL
, "phy_msglevel");
1316 unsigned long value
;
1318 (void)strict_strtoul(var
, 0, &value
);
1319 phyhal_msg_level
= value
;
1324 error
= pci_register_driver(&brcms_pci_driver
);
1334 * This function unloads the WL driver from the system.
1336 * This function unconditionally unloads the WL driver module from the
1340 static void __exit
brcms_module_exit(void)
1342 pci_unregister_driver(&brcms_pci_driver
);
1346 module_init(brcms_module_init
);
1347 module_exit(brcms_module_exit
);
1350 * This function frees the WL per-device resources.
1352 * This function frees resources owned by the WL device pointed to
1353 * by the wl parameter.
1355 * precondition: can both be called locked and unlocked
1358 static void brcms_free(struct brcms_info
*wl
)
1360 struct brcms_timer
*t
, *next
;
1362 /* free ucode data */
1364 brcms_ucode_data_free();
1366 free_irq(wl
->irq
, wl
);
1369 tasklet_kill(&wl
->tasklet
);
1372 wlc_module_unregister(wl
->pub
, "linux", wl
);
1375 /* free common resources */
1377 wlc_detach(wl
->wlc
);
1382 /* virtual interface deletion is deferred so we cannot spinwait */
1384 /* wait for all pending callbacks to complete */
1385 while (atomic_read(&wl
->callbacks
) > 0)
1389 for (t
= wl
->timers
; t
; t
= next
) {
1398 * unregister_netdev() calls get_stats() which may read chip registers
1399 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1401 if (wl
->regsva
&& wl
->bcm_bustype
!= SDIO_BUS
&&
1402 wl
->bcm_bustype
!= JTAG_BUS
) {
1403 iounmap((void *)wl
->regsva
);
1408 /* flags the given rate in rateset as requested */
1409 static void brcms_set_basic_rate(struct wl_rateset
*rs
, u16 rate
, bool is_br
)
1413 for (i
= 0; i
< rs
->count
; i
++) {
1414 if (rate
!= (rs
->rates
[i
] & 0x7f))
1418 rs
->rates
[i
] |= WLC_RATE_FLAG
;
1420 rs
->rates
[i
] &= WLC_RATE_MASK
;
1426 * precondition: perimeter lock has been acquired
1428 void brcms_txflowcontrol(struct brcms_info
*wl
, struct brcms_if
*wlif
,
1429 bool state
, int prio
)
1431 wiphy_err(wl
->wiphy
, "Shouldn't be here %s\n", __func__
);
1435 * precondition: perimeter lock has been acquired
1437 void brcms_init(struct brcms_info
*wl
)
1439 BCMMSG(WL_TO_HW(wl
)->wiphy
, "wl%d\n", wl
->pub
->unit
);
1446 * precondition: perimeter lock has been acquired
1448 uint
brcms_reset(struct brcms_info
*wl
)
1450 BCMMSG(WL_TO_HW(wl
)->wiphy
, "wl%d\n", wl
->pub
->unit
);
1453 /* dpc will not be rescheduled */
1460 * These are interrupt on/off entry points. Disable interrupts
1461 * during interrupt state transition.
1463 void brcms_intrson(struct brcms_info
*wl
)
1465 unsigned long flags
;
1467 INT_LOCK(wl
, flags
);
1468 wlc_intrson(wl
->wlc
);
1469 INT_UNLOCK(wl
, flags
);
1473 * precondition: perimeter lock has been acquired
1475 bool wl_alloc_dma_resources(struct brcms_info
*wl
, uint addrwidth
)
1480 u32
brcms_intrsoff(struct brcms_info
*wl
)
1482 unsigned long flags
;
1485 INT_LOCK(wl
, flags
);
1486 status
= wlc_intrsoff(wl
->wlc
);
1487 INT_UNLOCK(wl
, flags
);
1491 void brcms_intrsrestore(struct brcms_info
*wl
, u32 macintmask
)
1493 unsigned long flags
;
1495 INT_LOCK(wl
, flags
);
1496 wlc_intrsrestore(wl
->wlc
, macintmask
);
1497 INT_UNLOCK(wl
, flags
);
1501 * precondition: perimeter lock has been acquired
1503 int brcms_up(struct brcms_info
*wl
)
1510 error
= wlc_up(wl
->wlc
);
1516 * precondition: perimeter lock has been acquired
1518 void brcms_down(struct brcms_info
*wl
)
1520 uint callbacks
, ret_val
= 0;
1522 /* call common down function */
1523 ret_val
= wlc_down(wl
->wlc
);
1524 callbacks
= atomic_read(&wl
->callbacks
) - ret_val
;
1526 /* wait for down callbacks to complete */
1529 /* For HIGH_only driver, it's important to actually schedule other work,
1530 * not just spin wait since everything runs at schedule level
1532 SPINWAIT((atomic_read(&wl
->callbacks
) > callbacks
), 100 * 1000);
1537 static irqreturn_t
brcms_isr(int irq
, void *dev_id
)
1539 struct brcms_info
*wl
;
1541 unsigned long flags
;
1543 wl
= (struct brcms_info
*) dev_id
;
1545 ISR_LOCK(wl
, flags
);
1547 /* call common first level interrupt handler */
1548 ours
= wlc_isr(wl
->wlc
, &wantdpc
);
1550 /* if more to do... */
1553 /* ...and call the second level interrupt handler */
1555 tasklet_schedule(&wl
->tasklet
);
1559 ISR_UNLOCK(wl
, flags
);
1561 return IRQ_RETVAL(ours
);
1564 static void brcms_dpc(unsigned long data
)
1566 struct brcms_info
*wl
;
1568 wl
= (struct brcms_info
*) data
;
1572 /* call the common second level interrupt handler */
1575 unsigned long flags
;
1577 INT_LOCK(wl
, flags
);
1578 wlc_intrsupd(wl
->wlc
);
1579 INT_UNLOCK(wl
, flags
);
1582 wl
->resched
= wlc_dpc(wl
->wlc
, true);
1585 /* wlc_dpc() may bring the driver down */
1589 /* re-schedule dpc */
1591 tasklet_schedule(&wl
->tasklet
);
1593 /* re-enable interrupts */
1602 * is called by the kernel from software irq context
1604 static void brcms_timer(unsigned long data
)
1606 _brcms_timer((struct brcms_timer
*) data
);
1610 * precondition: perimeter lock is not acquired
1612 static void _brcms_timer(struct brcms_timer
*t
)
1618 t
->timer
.expires
= jiffies
+ t
->ms
* HZ
/ 1000;
1619 atomic_inc(&t
->wl
->callbacks
);
1620 add_timer(&t
->timer
);
1628 atomic_dec(&t
->wl
->callbacks
);
1634 * Adds a timer to the list. Caller supplies a timer function.
1635 * Is called from wlc.
1637 * precondition: perimeter lock has been acquired
1639 struct brcms_timer
*brcms_init_timer(struct brcms_info
*wl
,
1640 void (*fn
) (void *arg
),
1641 void *arg
, const char *name
)
1643 struct brcms_timer
*t
;
1645 t
= kzalloc(sizeof(struct brcms_timer
), GFP_ATOMIC
);
1647 wiphy_err(wl
->wiphy
, "wl%d: brcms_init_timer: out of memory\n",
1652 init_timer(&t
->timer
);
1653 t
->timer
.data
= (unsigned long) t
;
1654 t
->timer
.function
= brcms_timer
;
1658 t
->next
= wl
->timers
;
1662 t
->name
= kmalloc(strlen(name
) + 1, GFP_ATOMIC
);
1664 strcpy(t
->name
, name
);
1670 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1671 * as well as it's easier to make it periodic
1673 * precondition: perimeter lock has been acquired
1675 void brcms_add_timer(struct brcms_info
*wl
, struct brcms_timer
*t
, uint ms
,
1680 wiphy_err(wl
->wiphy
, "%s: Already set. Name: %s, per %d\n",
1681 __func__
, t
->name
, periodic
);
1685 t
->periodic
= (bool) periodic
;
1687 t
->timer
.expires
= jiffies
+ ms
* HZ
/ 1000;
1689 atomic_inc(&wl
->callbacks
);
1690 add_timer(&t
->timer
);
1694 * return true if timer successfully deleted, false if still pending
1696 * precondition: perimeter lock has been acquired
1698 bool brcms_del_timer(struct brcms_info
*wl
, struct brcms_timer
*t
)
1702 if (!del_timer(&t
->timer
)) {
1705 atomic_dec(&wl
->callbacks
);
1712 * precondition: perimeter lock has been acquired
1714 void brcms_free_timer(struct brcms_info
*wl
, struct brcms_timer
*t
)
1716 struct brcms_timer
*tmp
;
1718 /* delete the timer in case it is active */
1719 brcms_del_timer(wl
, t
);
1721 if (wl
->timers
== t
) {
1722 wl
->timers
= wl
->timers
->next
;
1733 if (tmp
->next
== t
) {
1734 tmp
->next
= t
->next
;
1747 * runs in software irq context
1749 * precondition: perimeter lock is not acquired
1751 static int wl_linux_watchdog(void *ctx
)
1756 struct firmware_hdr
{
1762 char *brcms_firmwares
[MAX_FW_IMAGES
] = {
1768 * precondition: perimeter lock has been acquired
1770 int brcms_ucode_init_buf(struct brcms_info
*wl
, void **pbuf
, u32 idx
)
1774 struct firmware_hdr
*hdr
;
1775 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1776 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1777 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1779 if (hdr
->idx
== idx
) {
1780 pdata
= wl
->fw
.fw_bin
[i
]->data
+ hdr
->offset
;
1781 *pbuf
= kmalloc(hdr
->len
, GFP_ATOMIC
);
1782 if (*pbuf
== NULL
) {
1783 wiphy_err(wl
->wiphy
, "fail to alloc %d"
1784 " bytes\n", hdr
->len
);
1787 memcpy(*pbuf
, pdata
, hdr
->len
);
1792 wiphy_err(wl
->wiphy
, "ERROR: ucode buf tag:%d can not be found!\n",
1800 * Precondition: Since this function is called in brcms_pci_probe() context,
1801 * no locking is required.
1803 int brcms_ucode_init_uint(struct brcms_info
*wl
, u32
*data
, u32 idx
)
1807 struct firmware_hdr
*hdr
;
1808 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1809 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1810 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1812 if (hdr
->idx
== idx
) {
1813 pdata
= wl
->fw
.fw_bin
[i
]->data
+ hdr
->offset
;
1814 if (hdr
->len
!= 4) {
1815 wiphy_err(wl
->wiphy
,
1816 "ERROR: fw hdr len\n");
1819 *data
= *((u32
*) pdata
);
1824 wiphy_err(wl
->wiphy
, "ERROR: ucode tag:%d can not be found!\n", idx
);
1829 * Precondition: Since this function is called in brcms_pci_probe() context,
1830 * no locking is required.
1832 static int brcms_request_fw(struct brcms_info
*wl
, struct pci_dev
*pdev
)
1835 struct device
*device
= &pdev
->dev
;
1839 memset((void *)&wl
->fw
, 0, sizeof(struct brcms_firmware
));
1840 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
1841 if (brcms_firmwares
[i
] == NULL
)
1843 sprintf(fw_name
, "%s-%d.fw", brcms_firmwares
[i
],
1844 UCODE_LOADER_API_VER
);
1845 status
= request_firmware(&wl
->fw
.fw_bin
[i
], fw_name
, device
);
1847 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
1848 KBUILD_MODNAME
, fw_name
);
1851 sprintf(fw_name
, "%s_hdr-%d.fw", brcms_firmwares
[i
],
1852 UCODE_LOADER_API_VER
);
1853 status
= request_firmware(&wl
->fw
.fw_hdr
[i
], fw_name
, device
);
1855 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
1856 KBUILD_MODNAME
, fw_name
);
1859 wl
->fw
.hdr_num_entries
[i
] =
1860 wl
->fw
.fw_hdr
[i
]->size
/ (sizeof(struct firmware_hdr
));
1863 return brcms_ucode_data_init(wl
);
1867 * precondition: can both be called locked and unlocked
1869 void brcms_ucode_free_buf(void *p
)
1875 * Precondition: Since this function is called in brcms_pci_probe() context,
1876 * no locking is required.
1878 static void brcms_release_fw(struct brcms_info
*wl
)
1881 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
1882 release_firmware(wl
->fw
.fw_bin
[i
]);
1883 release_firmware(wl
->fw
.fw_hdr
[i
]);
1889 * checks validity of all firmware images loaded from user space
1891 * Precondition: Since this function is called in brcms_pci_probe() context,
1892 * no locking is required.
1894 int brcms_check_firmwares(struct brcms_info
*wl
)
1899 const struct firmware
*fw
;
1900 const struct firmware
*fw_hdr
;
1901 struct firmware_hdr
*ucode_hdr
;
1902 for (i
= 0; i
< MAX_FW_IMAGES
&& rc
== 0; i
++) {
1903 fw
= wl
->fw
.fw_bin
[i
];
1904 fw_hdr
= wl
->fw
.fw_hdr
[i
];
1905 if (fw
== NULL
&& fw_hdr
== NULL
) {
1907 } else if (fw
== NULL
|| fw_hdr
== NULL
) {
1908 wiphy_err(wl
->wiphy
, "%s: invalid bin/hdr fw\n",
1911 } else if (fw_hdr
->size
% sizeof(struct firmware_hdr
)) {
1912 wiphy_err(wl
->wiphy
, "%s: non integral fw hdr file "
1913 "size %zu/%zu\n", __func__
, fw_hdr
->size
,
1914 sizeof(struct firmware_hdr
));
1916 } else if (fw
->size
< MIN_FW_SIZE
|| fw
->size
> MAX_FW_SIZE
) {
1917 wiphy_err(wl
->wiphy
, "%s: out of bounds fw file size "
1918 "%zu\n", __func__
, fw
->size
);
1921 /* check if ucode section overruns firmware image */
1922 ucode_hdr
= (struct firmware_hdr
*)fw_hdr
->data
;
1923 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
] &&
1924 !rc
; entry
++, ucode_hdr
++) {
1925 if (ucode_hdr
->offset
+ ucode_hdr
->len
>
1927 wiphy_err(wl
->wiphy
,
1928 "%s: conflicting bin/hdr\n",
1935 if (rc
== 0 && wl
->fw
.fw_cnt
!= i
) {
1936 wiphy_err(wl
->wiphy
, "%s: invalid fw_cnt=%d\n", __func__
,
1944 * precondition: perimeter lock has been acquired
1946 bool brcms_rfkill_set_hw_state(struct brcms_info
*wl
)
1948 bool blocked
= wlc_check_radio_disabled(wl
->wlc
);
1951 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
1953 wiphy_rfkill_start_polling(wl
->pub
->ieee_hw
->wiphy
);
1959 * precondition: perimeter lock has been acquired
1961 void brcms_msleep(struct brcms_info
*wl
, uint ms
)