2 * Copyright (c) 2010 Broadcom Corporation
3 * Copyright (c) 2013 Hauke Mehrtens <hauke@hauke-m.de>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/pci_ids.h>
21 #include <linux/if_ether.h>
22 #include <net/cfg80211.h>
23 #include <net/mac80211.h>
24 #include <brcm_hw_ids.h>
26 #include <chipcommon.h>
29 #include "phy/phy_hal.h"
34 #include "mac80211_if.h"
35 #include "ucode_loader.h"
40 #include "brcms_trace_events.h"
42 /* watchdog timer, in unit of ms */
43 #define TIMER_INTERVAL_WATCHDOG 1000
44 /* radio monitor timer, in unit of ms */
45 #define TIMER_INTERVAL_RADIOCHK 800
47 /* beacon interval, in unit of 1024TU */
48 #define BEACON_INTERVAL_DEFAULT 100
50 /* n-mode support capability */
51 /* 2x2 includes both 1x1 & 2x2 devices
52 * reserved #define 2 for future when we want to separate 1x1 & 2x2 and
53 * control it independently
59 #define EDCF_ACI_MASK 0x60
60 #define EDCF_ACI_SHIFT 5
61 #define EDCF_ECWMIN_MASK 0x0f
62 #define EDCF_ECWMAX_SHIFT 4
63 #define EDCF_AIFSN_MASK 0x0f
64 #define EDCF_AIFSN_MAX 15
65 #define EDCF_ECWMAX_MASK 0xf0
67 #define EDCF_AC_BE_TXOP_STA 0x0000
68 #define EDCF_AC_BK_TXOP_STA 0x0000
69 #define EDCF_AC_VO_ACI_STA 0x62
70 #define EDCF_AC_VO_ECW_STA 0x32
71 #define EDCF_AC_VI_ACI_STA 0x42
72 #define EDCF_AC_VI_ECW_STA 0x43
73 #define EDCF_AC_BK_ECW_STA 0xA4
74 #define EDCF_AC_VI_TXOP_STA 0x005e
75 #define EDCF_AC_VO_TXOP_STA 0x002f
76 #define EDCF_AC_BE_ACI_STA 0x03
77 #define EDCF_AC_BE_ECW_STA 0xA4
78 #define EDCF_AC_BK_ACI_STA 0x27
79 #define EDCF_AC_VO_TXOP_AP 0x002f
81 #define EDCF_TXOP2USEC(txop) ((txop) << 5)
82 #define EDCF_ECW2CW(exp) ((1 << (exp)) - 1)
84 #define APHY_SYMBOL_TIME 4
85 #define APHY_PREAMBLE_TIME 16
86 #define APHY_SIGNAL_TIME 4
87 #define APHY_SIFS_TIME 16
88 #define APHY_SERVICE_NBITS 16
89 #define APHY_TAIL_NBITS 6
90 #define BPHY_SIFS_TIME 10
91 #define BPHY_PLCP_SHORT_TIME 96
93 #define PREN_PREAMBLE 24
94 #define PREN_MM_EXT 12
95 #define PREN_PREAMBLE_EXT 4
97 #define DOT11_MAC_HDR_LEN 24
98 #define DOT11_ACK_LEN 10
99 #define DOT11_BA_LEN 4
100 #define DOT11_OFDM_SIGNAL_EXTENSION 6
101 #define DOT11_MIN_FRAG_LEN 256
102 #define DOT11_RTS_LEN 16
103 #define DOT11_CTS_LEN 10
104 #define DOT11_BA_BITMAP_LEN 128
105 #define DOT11_MAXNUMFRAGS 16
106 #define DOT11_MAX_FRAG_LEN 2346
108 #define BPHY_PLCP_TIME 192
109 #define RIFS_11N_TIME 2
111 /* length of the BCN template area */
112 #define BCN_TMPL_LEN 512
114 /* brcms_bss_info flag bit values */
115 #define BRCMS_BSS_HT 0x0020 /* BSS is HT (MIMO) capable */
117 /* chip rx buffer offset */
118 #define BRCMS_HWRXOFF 38
120 /* rfdisable delay timer 500 ms, runs of ALP clock */
121 #define RFDISABLE_DEFAULT 10000000
123 #define BRCMS_TEMPSENSE_PERIOD 10 /* 10 second timeout */
125 /* synthpu_dly times in us */
126 #define SYNTHPU_DLY_APHY_US 3700
127 #define SYNTHPU_DLY_BPHY_US 1050
128 #define SYNTHPU_DLY_NPHY_US 2048
129 #define SYNTHPU_DLY_LPPHY_US 300
131 #define ANTCNT 10 /* vanilla M_MAX_ANTCNT val */
133 /* Per-AC retry limit register definitions; uses defs.h bitfield macros */
134 #define EDCF_SHORT_S 0
136 #define EDCF_LONG_S 8
137 #define EDCF_LFB_S 12
138 #define EDCF_SHORT_M BITFIELD_MASK(4)
139 #define EDCF_SFB_M BITFIELD_MASK(4)
140 #define EDCF_LONG_M BITFIELD_MASK(4)
141 #define EDCF_LFB_M BITFIELD_MASK(4)
143 #define RETRY_SHORT_DEF 7 /* Default Short retry Limit */
144 #define RETRY_SHORT_MAX 255 /* Maximum Short retry Limit */
145 #define RETRY_LONG_DEF 4 /* Default Long retry count */
146 #define RETRY_SHORT_FB 3 /* Short count for fb rate */
147 #define RETRY_LONG_FB 2 /* Long count for fb rate */
149 #define APHY_CWMIN 15
150 #define PHY_CWMAX 1023
152 #define EDCF_AIFSN_MIN 1
154 #define FRAGNUM_MASK 0xF
156 #define APHY_SLOT_TIME 9
157 #define BPHY_SLOT_TIME 20
159 #define WL_SPURAVOID_OFF 0
160 #define WL_SPURAVOID_ON1 1
161 #define WL_SPURAVOID_ON2 2
163 /* invalid core flags, use the saved coreflags */
164 #define BRCMS_USE_COREFLAGS 0xffffffff
166 /* values for PLCPHdr_override */
167 #define BRCMS_PLCP_AUTO -1
168 #define BRCMS_PLCP_SHORT 0
169 #define BRCMS_PLCP_LONG 1
171 /* values for g_protection_override and n_protection_override */
172 #define BRCMS_PROTECTION_AUTO -1
173 #define BRCMS_PROTECTION_OFF 0
174 #define BRCMS_PROTECTION_ON 1
175 #define BRCMS_PROTECTION_MMHDR_ONLY 2
176 #define BRCMS_PROTECTION_CTS_ONLY 3
178 /* values for g_protection_control and n_protection_control */
179 #define BRCMS_PROTECTION_CTL_OFF 0
180 #define BRCMS_PROTECTION_CTL_LOCAL 1
181 #define BRCMS_PROTECTION_CTL_OVERLAP 2
183 /* values for n_protection */
184 #define BRCMS_N_PROTECTION_OFF 0
185 #define BRCMS_N_PROTECTION_OPTIONAL 1
186 #define BRCMS_N_PROTECTION_20IN40 2
187 #define BRCMS_N_PROTECTION_MIXEDMODE 3
189 /* values for band specific 40MHz capabilities */
190 #define BRCMS_N_BW_20ALL 0
191 #define BRCMS_N_BW_40ALL 1
192 #define BRCMS_N_BW_20IN2G_40IN5G 2
194 /* bitflags for SGI support (sgi_rx iovar) */
195 #define BRCMS_N_SGI_20 0x01
196 #define BRCMS_N_SGI_40 0x02
198 /* defines used by the nrate iovar */
199 /* MSC in use,indicates b0-6 holds an mcs */
200 #define NRATE_MCS_INUSE 0x00000080
202 #define NRATE_RATE_MASK 0x0000007f
203 /* stf mode mask: siso, cdd, stbc, sdm */
204 #define NRATE_STF_MASK 0x0000ff00
206 #define NRATE_STF_SHIFT 8
207 /* bit indicate to override mcs only */
208 #define NRATE_OVERRIDE_MCS_ONLY 0x40000000
209 #define NRATE_SGI_MASK 0x00800000 /* sgi mode */
210 #define NRATE_SGI_SHIFT 23 /* sgi mode */
211 #define NRATE_LDPC_CODING 0x00400000 /* adv coding in use */
212 #define NRATE_LDPC_SHIFT 22 /* ldpc shift */
214 #define NRATE_STF_SISO 0 /* stf mode SISO */
215 #define NRATE_STF_CDD 1 /* stf mode CDD */
216 #define NRATE_STF_STBC 2 /* stf mode STBC */
217 #define NRATE_STF_SDM 3 /* stf mode SDM */
219 #define MAX_DMA_SEGS 4
221 /* # of entries in Tx FIFO */
223 /* Max # of entries in Rx FIFO based on 4kb page size */
226 /* Amount of headroom to leave in Tx FIFO */
227 #define TX_HEADROOM 4
229 /* try to keep this # rbufs posted to the chip */
230 #define NRXBUFPOST 32
232 /* max # frames to process in brcms_c_recv() */
234 /* max # tx status to process in wlc_txstatus() */
237 /* brcmu_format_flags() bit description structure */
238 struct brcms_c_bit_desc
{
244 * The following table lists the buffer memory allocated to xmt fifos in HW.
245 * the size is in units of 256bytes(one block), total size is HW dependent
246 * ucode has default fifo partition, sw can overwrite if necessary
248 * This is documented in twiki under the topic UcodeTxFifo. Please ensure
249 * the twiki is updated before making changes.
252 /* Starting corerev for the fifo size table */
253 #define XMTFIFOTBL_STARTREV 17
261 struct edcf_acparam
{
270 /* TX FIFO number to WME/802.1E Access Category */
271 static const u8 wme_fifo2ac
[] = {
280 /* ieee80211 Access Category to TX FIFO number */
281 static const u8 wme_ac2fifo
[] = {
288 static const u16 xmtfifo_sz
[][NFIFO
] = {
289 /* corerev 17: 5120, 49152, 49152, 5376, 4352, 1280 */
290 {20, 192, 192, 21, 17, 5},
295 /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */
296 {20, 192, 192, 21, 17, 5},
297 /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */
298 {9, 58, 22, 14, 14, 5},
299 /* corerev 22: 5120, 49152, 49152, 5376, 4352, 1280 */
300 {20, 192, 192, 21, 17, 5},
301 /* corerev 23: 5120, 49152, 49152, 5376, 4352, 1280 */
302 {20, 192, 192, 21, 17, 5},
303 /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */
304 {9, 58, 22, 14, 14, 5},
311 /* corerev 28: 2304, 14848, 5632, 3584, 3584, 1280 */
312 {9, 58, 22, 14, 14, 5},
316 static const char * const fifo_names
[] = {
317 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
319 static const char fifo_names
[6][1];
323 /* pointer to most recently allocated wl/wlc */
324 static struct brcms_c_info
*wlc_info_dbg
= (struct brcms_c_info
*) (NULL
);
327 /* Mapping of ieee80211 AC numbers to tx fifos */
328 static const u8 ac_to_fifo_mapping
[IEEE80211_NUM_ACS
] = {
329 [IEEE80211_AC_VO
] = TX_AC_VO_FIFO
,
330 [IEEE80211_AC_VI
] = TX_AC_VI_FIFO
,
331 [IEEE80211_AC_BE
] = TX_AC_BE_FIFO
,
332 [IEEE80211_AC_BK
] = TX_AC_BK_FIFO
,
335 /* Mapping of tx fifos to ieee80211 AC numbers */
336 static const u8 fifo_to_ac_mapping
[IEEE80211_NUM_ACS
] = {
337 [TX_AC_BK_FIFO
] = IEEE80211_AC_BK
,
338 [TX_AC_BE_FIFO
] = IEEE80211_AC_BE
,
339 [TX_AC_VI_FIFO
] = IEEE80211_AC_VI
,
340 [TX_AC_VO_FIFO
] = IEEE80211_AC_VO
,
343 static u8
brcms_ac_to_fifo(u8 ac
)
345 if (ac
>= ARRAY_SIZE(ac_to_fifo_mapping
))
346 return TX_AC_BE_FIFO
;
347 return ac_to_fifo_mapping
[ac
];
350 static u8
brcms_fifo_to_ac(u8 fifo
)
352 if (fifo
>= ARRAY_SIZE(fifo_to_ac_mapping
))
353 return IEEE80211_AC_BE
;
354 return fifo_to_ac_mapping
[fifo
];
357 /* Find basic rate for a given rate */
358 static u8
brcms_basic_rate(struct brcms_c_info
*wlc
, u32 rspec
)
360 if (is_mcs_rate(rspec
))
361 return wlc
->band
->basic_rate
[mcs_table
[rspec
& RSPEC_RATE_MASK
]
363 return wlc
->band
->basic_rate
[rspec
& RSPEC_RATE_MASK
];
366 static u16
frametype(u32 rspec
, u8 mimoframe
)
368 if (is_mcs_rate(rspec
))
370 return is_cck_rate(rspec
) ? FT_CCK
: FT_OFDM
;
373 /* currently the best mechanism for determining SIFS is the band in use */
374 static u16
get_sifs(struct brcms_band
*band
)
376 return band
->bandtype
== BRCM_BAND_5G
? APHY_SIFS_TIME
:
381 * Detect Card removed.
382 * Even checking an sbconfig register read will not false trigger when the core
383 * is in reset it breaks CF address mechanism. Accessing gphy phyversion will
384 * cause SB error if aphy is in reset on 4306B0-DB. Need a simple accessible
385 * reg with fixed 0/1 pattern (some platforms return all 0).
386 * If clocks are present, call the sb routine which will figure out if the
389 static bool brcms_deviceremoved(struct brcms_c_info
*wlc
)
394 return ai_deviceremoved(wlc
->hw
->sih
);
395 macctrl
= bcma_read32(wlc
->hw
->d11core
,
396 D11REGOFFS(maccontrol
));
397 return (macctrl
& (MCTL_PSM_JMP_0
| MCTL_IHR_EN
)) != MCTL_IHR_EN
;
400 /* sum the individual fifo tx pending packet counts */
401 static int brcms_txpktpendtot(struct brcms_c_info
*wlc
)
406 for (i
= 0; i
< ARRAY_SIZE(wlc
->hw
->di
); i
++)
408 pending
+= dma_txpending(wlc
->hw
->di
[i
]);
412 static bool brcms_is_mband_unlocked(struct brcms_c_info
*wlc
)
414 return wlc
->pub
->_nbands
> 1 && !wlc
->bandlocked
;
417 static int brcms_chspec_bw(u16 chanspec
)
419 if (CHSPEC_IS40(chanspec
))
421 if (CHSPEC_IS20(chanspec
))
427 static void brcms_c_bsscfg_mfree(struct brcms_bss_cfg
*cfg
)
432 kfree(cfg
->current_bss
);
436 static void brcms_c_detach_mfree(struct brcms_c_info
*wlc
)
441 brcms_c_bsscfg_mfree(wlc
->bsscfg
);
443 kfree(wlc
->modulecb
);
444 kfree(wlc
->default_bss
);
445 kfree(wlc
->protection
);
447 kfree(wlc
->bandstate
[0]);
449 kfree(wlc
->corestate
->macstat_snapshot
);
450 kfree(wlc
->corestate
);
452 kfree(wlc
->hw
->bandstate
[0]);
455 dev_kfree_skb_any(wlc
->beacon
);
457 dev_kfree_skb_any(wlc
->probe_resp
);
462 static struct brcms_bss_cfg
*brcms_c_bsscfg_malloc(uint unit
)
464 struct brcms_bss_cfg
*cfg
;
466 cfg
= kzalloc(sizeof(struct brcms_bss_cfg
), GFP_ATOMIC
);
470 cfg
->current_bss
= kzalloc(sizeof(struct brcms_bss_info
), GFP_ATOMIC
);
471 if (cfg
->current_bss
== NULL
)
477 brcms_c_bsscfg_mfree(cfg
);
481 static struct brcms_c_info
*
482 brcms_c_attach_malloc(uint unit
, uint
*err
, uint devid
)
484 struct brcms_c_info
*wlc
;
486 wlc
= kzalloc(sizeof(struct brcms_c_info
), GFP_ATOMIC
);
492 /* allocate struct brcms_c_pub state structure */
493 wlc
->pub
= kzalloc(sizeof(struct brcms_pub
), GFP_ATOMIC
);
494 if (wlc
->pub
== NULL
) {
500 /* allocate struct brcms_hardware state structure */
502 wlc
->hw
= kzalloc(sizeof(struct brcms_hardware
), GFP_ATOMIC
);
503 if (wlc
->hw
== NULL
) {
509 wlc
->hw
->bandstate
[0] =
510 kzalloc(sizeof(struct brcms_hw_band
) * MAXBANDS
, GFP_ATOMIC
);
511 if (wlc
->hw
->bandstate
[0] == NULL
) {
517 for (i
= 1; i
< MAXBANDS
; i
++)
518 wlc
->hw
->bandstate
[i
] = (struct brcms_hw_band
*)
519 ((unsigned long)wlc
->hw
->bandstate
[0] +
520 (sizeof(struct brcms_hw_band
) * i
));
524 kzalloc(sizeof(struct modulecb
) * BRCMS_MAXMODULES
, GFP_ATOMIC
);
525 if (wlc
->modulecb
== NULL
) {
530 wlc
->default_bss
= kzalloc(sizeof(struct brcms_bss_info
), GFP_ATOMIC
);
531 if (wlc
->default_bss
== NULL
) {
536 wlc
->bsscfg
= brcms_c_bsscfg_malloc(unit
);
537 if (wlc
->bsscfg
== NULL
) {
542 wlc
->protection
= kzalloc(sizeof(struct brcms_protection
),
544 if (wlc
->protection
== NULL
) {
549 wlc
->stf
= kzalloc(sizeof(struct brcms_stf
), GFP_ATOMIC
);
550 if (wlc
->stf
== NULL
) {
556 kzalloc(sizeof(struct brcms_band
)*MAXBANDS
, GFP_ATOMIC
);
557 if (wlc
->bandstate
[0] == NULL
) {
563 for (i
= 1; i
< MAXBANDS
; i
++)
564 wlc
->bandstate
[i
] = (struct brcms_band
*)
565 ((unsigned long)wlc
->bandstate
[0]
566 + (sizeof(struct brcms_band
)*i
));
569 wlc
->corestate
= kzalloc(sizeof(struct brcms_core
), GFP_ATOMIC
);
570 if (wlc
->corestate
== NULL
) {
575 wlc
->corestate
->macstat_snapshot
=
576 kzalloc(sizeof(struct macstat
), GFP_ATOMIC
);
577 if (wlc
->corestate
->macstat_snapshot
== NULL
) {
585 brcms_c_detach_mfree(wlc
);
590 * Update the slot timing for standard 11b/g (20us slots)
591 * or shortslot 11g (9us slots)
592 * The PSM needs to be suspended for this call.
594 static void brcms_b_update_slot_timing(struct brcms_hardware
*wlc_hw
,
597 struct bcma_device
*core
= wlc_hw
->d11core
;
600 /* 11g short slot: 11a timing */
601 bcma_write16(core
, D11REGOFFS(ifs_slot
), 0x0207);
602 brcms_b_write_shm(wlc_hw
, M_DOT11_SLOT
, APHY_SLOT_TIME
);
604 /* 11g long slot: 11b timing */
605 bcma_write16(core
, D11REGOFFS(ifs_slot
), 0x0212);
606 brcms_b_write_shm(wlc_hw
, M_DOT11_SLOT
, BPHY_SLOT_TIME
);
611 * calculate frame duration of a given rate and length, return
614 static uint
brcms_c_calc_frame_time(struct brcms_c_info
*wlc
, u32 ratespec
,
615 u8 preamble_type
, uint mac_len
)
617 uint nsyms
, dur
= 0, Ndps
, kNdps
;
618 uint rate
= rspec2rate(ratespec
);
621 brcms_err(wlc
->hw
->d11core
, "wl%d: WAR: using rate of 1 mbps\n",
626 if (is_mcs_rate(ratespec
)) {
627 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
628 int tot_streams
= mcs_2_txstreams(mcs
) + rspec_stc(ratespec
);
630 dur
= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
631 if (preamble_type
== BRCMS_MM_PREAMBLE
)
633 /* 1000Ndbps = kbps * 4 */
634 kNdps
= mcs_2_rate(mcs
, rspec_is40mhz(ratespec
),
635 rspec_issgi(ratespec
)) * 4;
637 if (rspec_stc(ratespec
) == 0)
639 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
640 APHY_TAIL_NBITS
) * 1000, kNdps
);
642 /* STBC needs to have even number of symbols */
645 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
646 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
648 dur
+= APHY_SYMBOL_TIME
* nsyms
;
649 if (wlc
->band
->bandtype
== BRCM_BAND_2G
)
650 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
651 } else if (is_ofdm_rate(rate
)) {
652 dur
= APHY_PREAMBLE_TIME
;
653 dur
+= APHY_SIGNAL_TIME
;
654 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
656 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
658 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+ APHY_TAIL_NBITS
),
660 dur
+= APHY_SYMBOL_TIME
* nsyms
;
661 if (wlc
->band
->bandtype
== BRCM_BAND_2G
)
662 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
665 * calc # bits * 2 so factor of 2 in rate (1/2 mbps)
668 mac_len
= mac_len
* 8 * 2;
669 /* calc ceiling of bits/rate = microseconds of air time */
670 dur
= (mac_len
+ rate
- 1) / rate
;
671 if (preamble_type
& BRCMS_SHORT_PREAMBLE
)
672 dur
+= BPHY_PLCP_SHORT_TIME
;
674 dur
+= BPHY_PLCP_TIME
;
679 static void brcms_c_write_inits(struct brcms_hardware
*wlc_hw
,
680 const struct d11init
*inits
)
682 struct bcma_device
*core
= wlc_hw
->d11core
;
688 brcms_dbg_info(wlc_hw
->d11core
, "wl%d\n", wlc_hw
->unit
);
690 for (i
= 0; inits
[i
].addr
!= cpu_to_le16(0xffff); i
++) {
691 size
= le16_to_cpu(inits
[i
].size
);
692 offset
= le16_to_cpu(inits
[i
].addr
);
693 value
= le32_to_cpu(inits
[i
].value
);
695 bcma_write16(core
, offset
, value
);
697 bcma_write32(core
, offset
, value
);
703 static void brcms_c_write_mhf(struct brcms_hardware
*wlc_hw
, u16
*mhfs
)
707 M_HOST_FLAGS1
, M_HOST_FLAGS2
, M_HOST_FLAGS3
, M_HOST_FLAGS4
,
711 for (idx
= 0; idx
< MHFMAX
; idx
++)
712 brcms_b_write_shm(wlc_hw
, addr
[idx
], mhfs
[idx
]);
715 static void brcms_c_ucode_bsinit(struct brcms_hardware
*wlc_hw
)
717 struct brcms_ucode
*ucode
= &wlc_hw
->wlc
->wl
->ucode
;
719 /* init microcode host flags */
720 brcms_c_write_mhf(wlc_hw
, wlc_hw
->band
->mhfs
);
722 /* do band-specific ucode IHR, SHM, and SCR inits */
723 if (D11REV_IS(wlc_hw
->corerev
, 17) || D11REV_IS(wlc_hw
->corerev
, 23)) {
724 if (BRCMS_ISNPHY(wlc_hw
->band
))
725 brcms_c_write_inits(wlc_hw
, ucode
->d11n0bsinitvals16
);
727 brcms_err(wlc_hw
->d11core
,
728 "%s: wl%d: unsupported phy in corerev %d\n",
729 __func__
, wlc_hw
->unit
,
732 if (D11REV_IS(wlc_hw
->corerev
, 24)) {
733 if (BRCMS_ISLCNPHY(wlc_hw
->band
))
734 brcms_c_write_inits(wlc_hw
,
735 ucode
->d11lcn0bsinitvals24
);
737 brcms_err(wlc_hw
->d11core
,
738 "%s: wl%d: unsupported phy in core rev %d\n",
739 __func__
, wlc_hw
->unit
,
742 brcms_err(wlc_hw
->d11core
,
743 "%s: wl%d: unsupported corerev %d\n",
744 __func__
, wlc_hw
->unit
, wlc_hw
->corerev
);
749 static void brcms_b_core_ioctl(struct brcms_hardware
*wlc_hw
, u32 m
, u32 v
)
751 struct bcma_device
*core
= wlc_hw
->d11core
;
752 u32 ioctl
= bcma_aread32(core
, BCMA_IOCTL
) & ~m
;
754 bcma_awrite32(core
, BCMA_IOCTL
, ioctl
| v
);
757 static void brcms_b_core_phy_clk(struct brcms_hardware
*wlc_hw
, bool clk
)
759 brcms_dbg_info(wlc_hw
->d11core
, "wl%d: clk %d\n", wlc_hw
->unit
, clk
);
761 wlc_hw
->phyclk
= clk
;
763 if (OFF
== clk
) { /* clear gmode bit, put phy into reset */
765 brcms_b_core_ioctl(wlc_hw
, (SICF_PRST
| SICF_FGC
| SICF_GMODE
),
766 (SICF_PRST
| SICF_FGC
));
768 brcms_b_core_ioctl(wlc_hw
, (SICF_PRST
| SICF_FGC
), SICF_PRST
);
771 } else { /* take phy out of reset */
773 brcms_b_core_ioctl(wlc_hw
, (SICF_PRST
| SICF_FGC
), SICF_FGC
);
775 brcms_b_core_ioctl(wlc_hw
, SICF_FGC
, 0);
781 /* low-level band switch utility routine */
782 static void brcms_c_setxband(struct brcms_hardware
*wlc_hw
, uint bandunit
)
784 brcms_dbg_mac80211(wlc_hw
->d11core
, "wl%d: bandunit %d\n", wlc_hw
->unit
,
787 wlc_hw
->band
= wlc_hw
->bandstate
[bandunit
];
791 * until we eliminate need for wlc->band refs in low level code
793 wlc_hw
->wlc
->band
= wlc_hw
->wlc
->bandstate
[bandunit
];
795 /* set gmode core flag */
796 if (wlc_hw
->sbclk
&& !wlc_hw
->noreset
) {
802 brcms_b_core_ioctl(wlc_hw
, SICF_GMODE
, gmode
);
806 /* switch to new band but leave it inactive */
807 static u32
brcms_c_setband_inact(struct brcms_c_info
*wlc
, uint bandunit
)
809 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
813 brcms_dbg_mac80211(wlc_hw
->d11core
, "wl%d\n", wlc_hw
->unit
);
814 macctrl
= bcma_read32(wlc_hw
->d11core
,
815 D11REGOFFS(maccontrol
));
816 WARN_ON((macctrl
& MCTL_EN_MAC
) != 0);
818 /* disable interrupts */
819 macintmask
= brcms_intrsoff(wlc
->wl
);
822 wlc_phy_switch_radio(wlc_hw
->band
->pi
, OFF
);
824 brcms_b_core_phy_clk(wlc_hw
, OFF
);
826 brcms_c_setxband(wlc_hw
, bandunit
);
831 /* process an individual struct tx_status */
833 brcms_c_dotxstatus(struct brcms_c_info
*wlc
, struct tx_status
*txs
)
835 struct sk_buff
*p
= NULL
;
837 struct dma_pub
*dma
= NULL
;
838 struct d11txh
*txh
= NULL
;
839 struct scb
*scb
= NULL
;
841 int tx_rts
, tx_frame_count
, tx_rts_count
;
842 uint totlen
, supr_status
;
844 struct ieee80211_hdr
*h
;
846 struct ieee80211_tx_info
*tx_info
;
847 struct ieee80211_tx_rate
*txrate
;
851 trace_brcms_txstatus(&wlc
->hw
->d11core
->dev
, txs
->framelen
,
852 txs
->frameid
, txs
->status
, txs
->lasttxtime
,
853 txs
->sequence
, txs
->phyerr
, txs
->ackphyrxsh
);
855 /* discard intermediate indications for ucode with one legitimate case:
856 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange,
857 * but the subsequent tx of DATA failed. so it will start rts/cts
858 * from the beginning (resetting the rts transmission count)
860 if (!(txs
->status
& TX_STATUS_AMPDU
)
861 && (txs
->status
& TX_STATUS_INTERMEDIATE
)) {
862 brcms_dbg_tx(wlc
->hw
->d11core
, "INTERMEDIATE but not AMPDU\n");
867 queue
= txs
->frameid
& TXFID_QUEUE_MASK
;
868 if (queue
>= NFIFO
) {
869 brcms_err(wlc
->hw
->d11core
, "queue %u >= NFIFO\n", queue
);
873 dma
= wlc
->hw
->di
[queue
];
875 p
= dma_getnexttxp(wlc
->hw
->di
[queue
], DMA_RANGE_TRANSMITTED
);
877 brcms_err(wlc
->hw
->d11core
, "dma_getnexttxp returned null!\n");
881 txh
= (struct d11txh
*) (p
->data
);
882 mcl
= le16_to_cpu(txh
->MacTxControlLow
);
885 brcms_dbg_tx(wlc
->hw
->d11core
, "phyerr 0x%x, rate 0x%x\n",
886 txs
->phyerr
, txh
->MainRates
);
888 if (txs
->frameid
!= le16_to_cpu(txh
->TxFrameID
)) {
889 brcms_err(wlc
->hw
->d11core
, "frameid != txh->TxFrameID\n");
892 tx_info
= IEEE80211_SKB_CB(p
);
893 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
895 if (tx_info
->rate_driver_data
[0])
898 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
899 brcms_c_ampdu_dotxstatus(wlc
->ampdu
, scb
, p
, txs
);
905 * brcms_c_ampdu_dotxstatus() will trace tx descriptors for AMPDU
906 * frames; this traces them for the rest.
908 trace_brcms_txdesc(&wlc
->hw
->d11core
->dev
, txh
, sizeof(*txh
));
910 supr_status
= txs
->status
& TX_STATUS_SUPR_MASK
;
911 if (supr_status
== TX_STATUS_SUPR_BADCH
) {
912 unsigned xfts
= le16_to_cpu(txh
->XtraFrameTypes
);
913 brcms_dbg_tx(wlc
->hw
->d11core
,
914 "Pkt tx suppressed, dest chan %u, current %d\n",
915 (xfts
>> XFTS_CHANNEL_SHIFT
) & 0xff,
916 CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
));
919 tx_rts
= le16_to_cpu(txh
->MacTxControlLow
) & TXC_SENDRTS
;
921 (txs
->status
& TX_STATUS_FRM_RTX_MASK
) >> TX_STATUS_FRM_RTX_SHIFT
;
923 (txs
->status
& TX_STATUS_RTS_RTX_MASK
) >> TX_STATUS_RTS_RTX_SHIFT
;
925 lastframe
= !ieee80211_has_morefrags(h
->frame_control
);
928 brcms_err(wlc
->hw
->d11core
, "Not last frame!\n");
931 * Set information to be consumed by Minstrel ht.
933 * The "fallback limit" is the number of tx attempts a given
934 * MPDU is sent at the "primary" rate. Tx attempts beyond that
935 * limit are sent at the "secondary" rate.
936 * A 'short frame' does not exceed RTS treshold.
938 u16 sfbl
, /* Short Frame Rate Fallback Limit */
939 lfbl
, /* Long Frame Rate Fallback Limit */
942 if (queue
< IEEE80211_NUM_ACS
) {
943 sfbl
= GFIELD(wlc
->wme_retries
[wme_fifo2ac
[queue
]],
945 lfbl
= GFIELD(wlc
->wme_retries
[wme_fifo2ac
[queue
]],
952 txrate
= tx_info
->status
.rates
;
953 if (txrate
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
)
958 ieee80211_tx_info_clear_status(tx_info
);
960 if ((tx_frame_count
> fbl
) && (txrate
[1].idx
>= 0)) {
962 * rate selection requested a fallback rate
965 txrate
[0].count
= fbl
;
966 txrate
[1].count
= tx_frame_count
- fbl
;
969 * rate selection did not request fallback rate, or
972 txrate
[0].count
= tx_frame_count
;
974 * rc80211_minstrel.c:minstrel_tx_status() expects
975 * unused rates to be marked with idx = -1
981 /* clear the rest of the rates */
982 for (i
= 2; i
< IEEE80211_TX_MAX_RATES
; i
++) {
987 if (txs
->status
& TX_STATUS_ACK_RCV
)
988 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
995 /* remove PLCP & Broadcom tx descriptor header */
996 skb_pull(p
, D11_PHY_HDR_LEN
);
997 skb_pull(p
, D11_TXH_LEN
);
998 ieee80211_tx_status_irqsafe(wlc
->pub
->ieee_hw
, p
);
1000 brcms_err(wlc
->hw
->d11core
,
1001 "%s: Not last frame => not calling tx_status\n",
1010 trace_brcms_txdesc(&wlc
->hw
->d11core
->dev
, txh
,
1012 brcmu_pkt_buf_free_skb(p
);
1015 if (dma
&& queue
< NFIFO
) {
1016 u16 ac_queue
= brcms_fifo_to_ac(queue
);
1017 if (dma
->txavail
> TX_HEADROOM
&& queue
< TX_BCMC_FIFO
&&
1018 ieee80211_queue_stopped(wlc
->pub
->ieee_hw
, ac_queue
))
1019 ieee80211_wake_queue(wlc
->pub
->ieee_hw
, ac_queue
);
1026 /* process tx completion events in BMAC
1027 * Return true if more tx status need to be processed. false otherwise.
1030 brcms_b_txstatus(struct brcms_hardware
*wlc_hw
, bool bound
, bool *fatal
)
1032 struct bcma_device
*core
;
1033 struct tx_status txstatus
, *txs
;
1037 * Param 'max_tx_num' indicates max. # tx status to process before
1040 uint max_tx_num
= bound
? TXSBND
: -1;
1043 core
= wlc_hw
->d11core
;
1046 while (n
< max_tx_num
) {
1047 s1
= bcma_read32(core
, D11REGOFFS(frmtxstatus
));
1048 if (s1
== 0xffffffff) {
1049 brcms_err(core
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
1054 /* only process when valid */
1058 s2
= bcma_read32(core
, D11REGOFFS(frmtxstatus2
));
1059 txs
->status
= s1
& TXS_STATUS_MASK
;
1060 txs
->frameid
= (s1
& TXS_FID_MASK
) >> TXS_FID_SHIFT
;
1061 txs
->sequence
= s2
& TXS_SEQ_MASK
;
1062 txs
->phyerr
= (s2
& TXS_PTX_MASK
) >> TXS_PTX_SHIFT
;
1063 txs
->lasttxtime
= 0;
1065 *fatal
= brcms_c_dotxstatus(wlc_hw
->wlc
, txs
);
1071 return n
>= max_tx_num
;
1074 static void brcms_c_tbtt(struct brcms_c_info
*wlc
)
1076 if (wlc
->bsscfg
->type
== BRCMS_TYPE_ADHOC
)
1078 * DirFrmQ is now valid...defer setting until end
1081 wlc
->qvalid
|= MCMD_DIRFRMQVAL
;
1084 /* set initial host flags value */
1086 brcms_c_mhfdef(struct brcms_c_info
*wlc
, u16
*mhfs
, u16 mhf2_init
)
1088 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
1090 memset(mhfs
, 0, MHFMAX
* sizeof(u16
));
1092 mhfs
[MHF2
] |= mhf2_init
;
1094 /* prohibit use of slowclock on multifunction boards */
1095 if (wlc_hw
->boardflags
& BFL_NOPLLDOWN
)
1096 mhfs
[MHF1
] |= MHF1_FORCEFASTCLK
;
1098 if (BRCMS_ISNPHY(wlc_hw
->band
) && NREV_LT(wlc_hw
->band
->phyrev
, 2)) {
1099 mhfs
[MHF2
] |= MHF2_NPHY40MHZ_WAR
;
1100 mhfs
[MHF1
] |= MHF1_IQSWAP_WAR
;
1105 dmareg(uint direction
, uint fifonum
)
1107 if (direction
== DMA_TX
)
1108 return offsetof(struct d11regs
, fifo64regs
[fifonum
].dmaxmt
);
1109 return offsetof(struct d11regs
, fifo64regs
[fifonum
].dmarcv
);
1112 static bool brcms_b_attach_dmapio(struct brcms_c_info
*wlc
, uint j
, bool wme
)
1117 * ucode host flag 2 needed for pio mode, independent of band and fifo
1120 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
1121 uint unit
= wlc_hw
->unit
;
1123 /* name and offsets for dma_attach */
1124 snprintf(name
, sizeof(name
), "wl%d", unit
);
1126 if (wlc_hw
->di
[0] == NULL
) { /* Init FIFOs */
1127 int dma_attach_err
= 0;
1131 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
1132 * RX: RX_FIFO (RX data packets)
1134 wlc_hw
->di
[0] = dma_attach(name
, wlc
,
1135 (wme
? dmareg(DMA_TX
, 0) : 0),
1137 (wme
? NTXD
: 0), NRXD
,
1138 RXBUFSZ
, -1, NRXBUFPOST
,
1140 dma_attach_err
|= (NULL
== wlc_hw
->di
[0]);
1144 * TX: TX_AC_BE_FIFO (TX AC Best-Effort data packets)
1145 * (legacy) TX_DATA_FIFO (TX data packets)
1148 wlc_hw
->di
[1] = dma_attach(name
, wlc
,
1149 dmareg(DMA_TX
, 1), 0,
1150 NTXD
, 0, 0, -1, 0, 0);
1151 dma_attach_err
|= (NULL
== wlc_hw
->di
[1]);
1155 * TX: TX_AC_VI_FIFO (TX AC Video data packets)
1158 wlc_hw
->di
[2] = dma_attach(name
, wlc
,
1159 dmareg(DMA_TX
, 2), 0,
1160 NTXD
, 0, 0, -1, 0, 0);
1161 dma_attach_err
|= (NULL
== wlc_hw
->di
[2]);
1164 * TX: TX_AC_VO_FIFO (TX AC Voice data packets)
1165 * (legacy) TX_CTL_FIFO (TX control & mgmt packets)
1167 wlc_hw
->di
[3] = dma_attach(name
, wlc
,
1171 dma_attach_err
|= (NULL
== wlc_hw
->di
[3]);
1172 /* Cleaner to leave this as if with AP defined */
1174 if (dma_attach_err
) {
1175 brcms_err(wlc_hw
->d11core
,
1176 "wl%d: wlc_attach: dma_attach failed\n",
1181 /* get pointer to dma engine tx flow control variable */
1182 for (i
= 0; i
< NFIFO
; i
++)
1184 wlc_hw
->txavail
[i
] =
1185 (uint
*) dma_getvar(wlc_hw
->di
[i
],
1189 /* initial ucode host flags */
1190 brcms_c_mhfdef(wlc
, wlc_hw
->band
->mhfs
, pio_mhf2
);
1195 static void brcms_b_detach_dmapio(struct brcms_hardware
*wlc_hw
)
1199 for (j
= 0; j
< NFIFO
; j
++) {
1200 if (wlc_hw
->di
[j
]) {
1201 dma_detach(wlc_hw
->di
[j
]);
1202 wlc_hw
->di
[j
] = NULL
;
1208 * Initialize brcms_c_info default values ...
1209 * may get overrides later in this function
1210 * BMAC_NOTES, move low out and resolve the dangling ones
1212 static void brcms_b_info_init(struct brcms_hardware
*wlc_hw
)
1214 struct brcms_c_info
*wlc
= wlc_hw
->wlc
;
1216 /* set default sw macintmask value */
1217 wlc
->defmacintmask
= DEF_MACINTMASK
;
1219 /* various 802.11g modes */
1220 wlc_hw
->shortslot
= false;
1222 wlc_hw
->SFBL
= RETRY_SHORT_FB
;
1223 wlc_hw
->LFBL
= RETRY_LONG_FB
;
1225 /* default mac retry limits */
1226 wlc_hw
->SRL
= RETRY_SHORT_DEF
;
1227 wlc_hw
->LRL
= RETRY_LONG_DEF
;
1228 wlc_hw
->chanspec
= ch20mhz_chspec(1);
1231 static void brcms_b_wait_for_wake(struct brcms_hardware
*wlc_hw
)
1233 /* delay before first read of ucode state */
1236 /* wait until ucode is no longer asleep */
1237 SPINWAIT((brcms_b_read_shm(wlc_hw
, M_UCODE_DBGST
) ==
1238 DBGST_ASLEEP
), wlc_hw
->wlc
->fastpwrup_dly
);
1241 /* control chip clock to save power, enable dynamic clock or force fast clock */
1242 static void brcms_b_clkctl_clk(struct brcms_hardware
*wlc_hw
, enum bcma_clkmode mode
)
1244 if (ai_get_cccaps(wlc_hw
->sih
) & CC_CAP_PMU
) {
1245 /* new chips with PMU, CCS_FORCEHT will distribute the HT clock
1246 * on backplane, but mac core will still run on ALP(not HT) when
1247 * it enters powersave mode, which means the FCA bit may not be
1248 * set. Should wakeup mac if driver wants it to run on HT.
1252 if (mode
== BCMA_CLKMODE_FAST
) {
1253 bcma_set32(wlc_hw
->d11core
,
1254 D11REGOFFS(clk_ctl_st
),
1260 ((bcma_read32(wlc_hw
->d11core
,
1261 D11REGOFFS(clk_ctl_st
)) &
1263 PMU_MAX_TRANSITION_DLY
);
1264 WARN_ON(!(bcma_read32(wlc_hw
->d11core
,
1265 D11REGOFFS(clk_ctl_st
)) &
1268 if ((ai_get_pmurev(wlc_hw
->sih
) == 0) &&
1269 (bcma_read32(wlc_hw
->d11core
,
1270 D11REGOFFS(clk_ctl_st
)) &
1271 (CCS_FORCEHT
| CCS_HTAREQ
)))
1273 ((bcma_read32(wlc_hw
->d11core
,
1274 offsetof(struct d11regs
,
1277 PMU_MAX_TRANSITION_DLY
);
1278 bcma_mask32(wlc_hw
->d11core
,
1279 D11REGOFFS(clk_ctl_st
),
1283 wlc_hw
->forcefastclk
= (mode
== BCMA_CLKMODE_FAST
);
1286 /* old chips w/o PMU, force HT through cc,
1287 * then use FCA to verify mac is running fast clock
1290 wlc_hw
->forcefastclk
= ai_clkctl_cc(wlc_hw
->sih
, mode
);
1292 /* check fast clock is available (if core is not in reset) */
1293 if (wlc_hw
->forcefastclk
&& wlc_hw
->clk
)
1294 WARN_ON(!(bcma_aread32(wlc_hw
->d11core
, BCMA_IOST
) &
1298 * keep the ucode wake bit on if forcefastclk is on since we
1299 * do not want ucode to put us back to slow clock when it dozes
1300 * for PM mode. Code below matches the wake override bit with
1301 * current forcefastclk state. Only setting bit in wake_override
1302 * instead of waking ucode immediately since old code had this
1303 * behavior. Older code set wlc->forcefastclk but only had the
1304 * wake happen if the wakup_ucode work (protected by an up
1305 * check) was executed just below.
1307 if (wlc_hw
->forcefastclk
)
1308 mboolset(wlc_hw
->wake_override
,
1309 BRCMS_WAKE_OVERRIDE_FORCEFAST
);
1311 mboolclr(wlc_hw
->wake_override
,
1312 BRCMS_WAKE_OVERRIDE_FORCEFAST
);
1316 /* set or clear ucode host flag bits
1317 * it has an optimization for no-change write
1318 * it only writes through shared memory when the core has clock;
1319 * pre-CLK changes should use wlc_write_mhf to get around the optimization
1322 * bands values are: BRCM_BAND_AUTO <--- Current band only
1323 * BRCM_BAND_5G <--- 5G band only
1324 * BRCM_BAND_2G <--- 2G band only
1325 * BRCM_BAND_ALL <--- All bands
1328 brcms_b_mhf(struct brcms_hardware
*wlc_hw
, u8 idx
, u16 mask
, u16 val
,
1332 u16 addr
[MHFMAX
] = {
1333 M_HOST_FLAGS1
, M_HOST_FLAGS2
, M_HOST_FLAGS3
, M_HOST_FLAGS4
,
1336 struct brcms_hw_band
*band
;
1338 if ((val
& ~mask
) || idx
>= MHFMAX
)
1339 return; /* error condition */
1342 /* Current band only or all bands,
1343 * then set the band to current band
1345 case BRCM_BAND_AUTO
:
1347 band
= wlc_hw
->band
;
1350 band
= wlc_hw
->bandstate
[BAND_5G_INDEX
];
1353 band
= wlc_hw
->bandstate
[BAND_2G_INDEX
];
1356 band
= NULL
; /* error condition */
1360 save
= band
->mhfs
[idx
];
1361 band
->mhfs
[idx
] = (band
->mhfs
[idx
] & ~mask
) | val
;
1363 /* optimization: only write through if changed, and
1364 * changed band is the current band
1366 if (wlc_hw
->clk
&& (band
->mhfs
[idx
] != save
)
1367 && (band
== wlc_hw
->band
))
1368 brcms_b_write_shm(wlc_hw
, addr
[idx
],
1369 (u16
) band
->mhfs
[idx
]);
1372 if (bands
== BRCM_BAND_ALL
) {
1373 wlc_hw
->bandstate
[0]->mhfs
[idx
] =
1374 (wlc_hw
->bandstate
[0]->mhfs
[idx
] & ~mask
) | val
;
1375 wlc_hw
->bandstate
[1]->mhfs
[idx
] =
1376 (wlc_hw
->bandstate
[1]->mhfs
[idx
] & ~mask
) | val
;
1380 /* set the maccontrol register to desired reset state and
1381 * initialize the sw cache of the register
1383 static void brcms_c_mctrl_reset(struct brcms_hardware
*wlc_hw
)
1385 /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */
1386 wlc_hw
->maccontrol
= 0;
1387 wlc_hw
->suspended_fifos
= 0;
1388 wlc_hw
->wake_override
= 0;
1389 wlc_hw
->mute_override
= 0;
1390 brcms_b_mctrl(wlc_hw
, ~0, MCTL_IHR_EN
| MCTL_WAKE
);
1394 * write the software state of maccontrol and
1395 * overrides to the maccontrol register
1397 static void brcms_c_mctrl_write(struct brcms_hardware
*wlc_hw
)
1399 u32 maccontrol
= wlc_hw
->maccontrol
;
1401 /* OR in the wake bit if overridden */
1402 if (wlc_hw
->wake_override
)
1403 maccontrol
|= MCTL_WAKE
;
1405 /* set AP and INFRA bits for mute if needed */
1406 if (wlc_hw
->mute_override
) {
1407 maccontrol
&= ~(MCTL_AP
);
1408 maccontrol
|= MCTL_INFRA
;
1411 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(maccontrol
),
1415 /* set or clear maccontrol bits */
1416 void brcms_b_mctrl(struct brcms_hardware
*wlc_hw
, u32 mask
, u32 val
)
1422 return; /* error condition */
1423 maccontrol
= wlc_hw
->maccontrol
;
1424 new_maccontrol
= (maccontrol
& ~mask
) | val
;
1426 /* if the new maccontrol value is the same as the old, nothing to do */
1427 if (new_maccontrol
== maccontrol
)
1430 /* something changed, cache the new value */
1431 wlc_hw
->maccontrol
= new_maccontrol
;
1433 /* write the new values with overrides applied */
1434 brcms_c_mctrl_write(wlc_hw
);
1437 void brcms_c_ucode_wake_override_set(struct brcms_hardware
*wlc_hw
,
1440 if (wlc_hw
->wake_override
|| (wlc_hw
->maccontrol
& MCTL_WAKE
)) {
1441 mboolset(wlc_hw
->wake_override
, override_bit
);
1445 mboolset(wlc_hw
->wake_override
, override_bit
);
1447 brcms_c_mctrl_write(wlc_hw
);
1448 brcms_b_wait_for_wake(wlc_hw
);
1451 void brcms_c_ucode_wake_override_clear(struct brcms_hardware
*wlc_hw
,
1454 mboolclr(wlc_hw
->wake_override
, override_bit
);
1456 if (wlc_hw
->wake_override
|| (wlc_hw
->maccontrol
& MCTL_WAKE
))
1459 brcms_c_mctrl_write(wlc_hw
);
1462 /* When driver needs ucode to stop beaconing, it has to make sure that
1463 * MCTL_AP is clear and MCTL_INFRA is set
1464 * Mode MCTL_AP MCTL_INFRA
1466 * STA 0 1 <--- This will ensure no beacons
1469 static void brcms_c_ucode_mute_override_set(struct brcms_hardware
*wlc_hw
)
1471 wlc_hw
->mute_override
= 1;
1473 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1474 * override, then there is no change to write
1476 if ((wlc_hw
->maccontrol
& (MCTL_AP
| MCTL_INFRA
)) == MCTL_INFRA
)
1479 brcms_c_mctrl_write(wlc_hw
);
1482 /* Clear the override on AP and INFRA bits */
1483 static void brcms_c_ucode_mute_override_clear(struct brcms_hardware
*wlc_hw
)
1485 if (wlc_hw
->mute_override
== 0)
1488 wlc_hw
->mute_override
= 0;
1490 /* if maccontrol already has AP == 0 and INFRA == 1 without this
1491 * override, then there is no change to write
1493 if ((wlc_hw
->maccontrol
& (MCTL_AP
| MCTL_INFRA
)) == MCTL_INFRA
)
1496 brcms_c_mctrl_write(wlc_hw
);
1500 * Write a MAC address to the given match reg offset in the RXE match engine.
1503 brcms_b_set_addrmatch(struct brcms_hardware
*wlc_hw
, int match_reg_offset
,
1506 struct bcma_device
*core
= wlc_hw
->d11core
;
1511 brcms_dbg_rx(core
, "wl%d: brcms_b_set_addrmatch\n", wlc_hw
->unit
);
1513 mac_l
= addr
[0] | (addr
[1] << 8);
1514 mac_m
= addr
[2] | (addr
[3] << 8);
1515 mac_h
= addr
[4] | (addr
[5] << 8);
1517 /* enter the MAC addr into the RXE match registers */
1518 bcma_write16(core
, D11REGOFFS(rcm_ctl
),
1519 RCM_INC_DATA
| match_reg_offset
);
1520 bcma_write16(core
, D11REGOFFS(rcm_mat_data
), mac_l
);
1521 bcma_write16(core
, D11REGOFFS(rcm_mat_data
), mac_m
);
1522 bcma_write16(core
, D11REGOFFS(rcm_mat_data
), mac_h
);
1526 brcms_b_write_template_ram(struct brcms_hardware
*wlc_hw
, int offset
, int len
,
1529 struct bcma_device
*core
= wlc_hw
->d11core
;
1534 brcms_dbg_info(core
, "wl%d\n", wlc_hw
->unit
);
1536 bcma_write32(core
, D11REGOFFS(tplatewrptr
), offset
);
1538 /* if MCTL_BIGEND bit set in mac control register,
1539 * the chip swaps data in fifo, as well as data in
1542 be_bit
= (bcma_read32(core
, D11REGOFFS(maccontrol
)) & MCTL_BIGEND
) != 0;
1545 memcpy(&word
, buf
, sizeof(u32
));
1548 word_be
= cpu_to_be32(word
);
1549 word
= *(u32
*)&word_be
;
1551 word_le
= cpu_to_le32(word
);
1552 word
= *(u32
*)&word_le
;
1555 bcma_write32(core
, D11REGOFFS(tplatewrdata
), word
);
1557 buf
= (u8
*) buf
+ sizeof(u32
);
1562 static void brcms_b_set_cwmin(struct brcms_hardware
*wlc_hw
, u16 newmin
)
1564 wlc_hw
->band
->CWmin
= newmin
;
1566 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(objaddr
),
1567 OBJADDR_SCR_SEL
| S_DOT11_CWMIN
);
1568 (void)bcma_read32(wlc_hw
->d11core
, D11REGOFFS(objaddr
));
1569 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(objdata
), newmin
);
1572 static void brcms_b_set_cwmax(struct brcms_hardware
*wlc_hw
, u16 newmax
)
1574 wlc_hw
->band
->CWmax
= newmax
;
1576 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(objaddr
),
1577 OBJADDR_SCR_SEL
| S_DOT11_CWMAX
);
1578 (void)bcma_read32(wlc_hw
->d11core
, D11REGOFFS(objaddr
));
1579 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(objdata
), newmax
);
1582 void brcms_b_bw_set(struct brcms_hardware
*wlc_hw
, u16 bw
)
1586 /* request FAST clock if not on */
1587 fastclk
= wlc_hw
->forcefastclk
;
1589 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_FAST
);
1591 wlc_phy_bw_state_set(wlc_hw
->band
->pi
, bw
);
1593 brcms_b_phy_reset(wlc_hw
);
1594 wlc_phy_init(wlc_hw
->band
->pi
, wlc_phy_chanspec_get(wlc_hw
->band
->pi
));
1596 /* restore the clk */
1598 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_DYNAMIC
);
1601 static void brcms_b_upd_synthpu(struct brcms_hardware
*wlc_hw
)
1604 struct brcms_c_info
*wlc
= wlc_hw
->wlc
;
1605 /* update SYNTHPU_DLY */
1607 if (BRCMS_ISLCNPHY(wlc
->band
))
1608 v
= SYNTHPU_DLY_LPPHY_US
;
1609 else if (BRCMS_ISNPHY(wlc
->band
) && (NREV_GE(wlc
->band
->phyrev
, 3)))
1610 v
= SYNTHPU_DLY_NPHY_US
;
1612 v
= SYNTHPU_DLY_BPHY_US
;
1614 brcms_b_write_shm(wlc_hw
, M_SYNTHPU_DLY
, v
);
1617 static void brcms_c_ucode_txant_set(struct brcms_hardware
*wlc_hw
)
1620 u16 phytxant
= wlc_hw
->bmac_phytxant
;
1621 u16 mask
= PHY_TXC_ANT_MASK
;
1623 /* set the Probe Response frame phy control word */
1624 phyctl
= brcms_b_read_shm(wlc_hw
, M_CTXPRS_BLK
+ C_CTX_PCTLWD_POS
);
1625 phyctl
= (phyctl
& ~mask
) | phytxant
;
1626 brcms_b_write_shm(wlc_hw
, M_CTXPRS_BLK
+ C_CTX_PCTLWD_POS
, phyctl
);
1628 /* set the Response (ACK/CTS) frame phy control word */
1629 phyctl
= brcms_b_read_shm(wlc_hw
, M_RSP_PCTLWD
);
1630 phyctl
= (phyctl
& ~mask
) | phytxant
;
1631 brcms_b_write_shm(wlc_hw
, M_RSP_PCTLWD
, phyctl
);
1634 static u16
brcms_b_ofdm_ratetable_offset(struct brcms_hardware
*wlc_hw
,
1639 struct plcp_signal_rate_lookup
{
1643 /* OFDM RATE sub-field of PLCP SIGNAL field, per 802.11 sec 17.3.4.1 */
1644 const struct plcp_signal_rate_lookup rate_lookup
[] = {
1645 {BRCM_RATE_6M
, 0xB},
1646 {BRCM_RATE_9M
, 0xF},
1647 {BRCM_RATE_12M
, 0xA},
1648 {BRCM_RATE_18M
, 0xE},
1649 {BRCM_RATE_24M
, 0x9},
1650 {BRCM_RATE_36M
, 0xD},
1651 {BRCM_RATE_48M
, 0x8},
1652 {BRCM_RATE_54M
, 0xC}
1655 for (i
= 0; i
< ARRAY_SIZE(rate_lookup
); i
++) {
1656 if (rate
== rate_lookup
[i
].rate
) {
1657 plcp_rate
= rate_lookup
[i
].signal_rate
;
1662 /* Find the SHM pointer to the rate table entry by looking in the
1665 return 2 * brcms_b_read_shm(wlc_hw
, M_RT_DIRMAP_A
+ (plcp_rate
* 2));
1668 static void brcms_upd_ofdm_pctl1_table(struct brcms_hardware
*wlc_hw
)
1672 BRCM_RATE_6M
, BRCM_RATE_9M
, BRCM_RATE_12M
, BRCM_RATE_18M
,
1673 BRCM_RATE_24M
, BRCM_RATE_36M
, BRCM_RATE_48M
, BRCM_RATE_54M
1679 if (!BRCMS_PHY_11N_CAP(wlc_hw
->band
))
1682 /* walk the phy rate table and update the entries */
1683 for (i
= 0; i
< ARRAY_SIZE(rates
); i
++) {
1686 entry_ptr
= brcms_b_ofdm_ratetable_offset(wlc_hw
, rate
);
1688 /* read the SHM Rate Table entry OFDM PCTL1 values */
1690 brcms_b_read_shm(wlc_hw
, entry_ptr
+ M_RT_OFDM_PCTL1_POS
);
1692 /* modify the value */
1693 pctl1
&= ~PHY_TXC1_MODE_MASK
;
1694 pctl1
|= (wlc_hw
->hw_stf_ss_opmode
<< PHY_TXC1_MODE_SHIFT
);
1696 /* Update the SHM Rate Table entry OFDM PCTL1 values */
1697 brcms_b_write_shm(wlc_hw
, entry_ptr
+ M_RT_OFDM_PCTL1_POS
,
1702 /* band-specific init */
1703 static void brcms_b_bsinit(struct brcms_c_info
*wlc
, u16 chanspec
)
1705 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
1707 brcms_dbg_mac80211(wlc_hw
->d11core
, "wl%d: bandunit %d\n", wlc_hw
->unit
,
1708 wlc_hw
->band
->bandunit
);
1710 brcms_c_ucode_bsinit(wlc_hw
);
1712 wlc_phy_init(wlc_hw
->band
->pi
, chanspec
);
1714 brcms_c_ucode_txant_set(wlc_hw
);
1717 * cwmin is band-specific, update hardware
1718 * with value for current band
1720 brcms_b_set_cwmin(wlc_hw
, wlc_hw
->band
->CWmin
);
1721 brcms_b_set_cwmax(wlc_hw
, wlc_hw
->band
->CWmax
);
1723 brcms_b_update_slot_timing(wlc_hw
,
1724 wlc_hw
->band
->bandtype
== BRCM_BAND_5G
?
1725 true : wlc_hw
->shortslot
);
1727 /* write phytype and phyvers */
1728 brcms_b_write_shm(wlc_hw
, M_PHYTYPE
, (u16
) wlc_hw
->band
->phytype
);
1729 brcms_b_write_shm(wlc_hw
, M_PHYVER
, (u16
) wlc_hw
->band
->phyrev
);
1732 * initialize the txphyctl1 rate table since
1733 * shmem is shared between bands
1735 brcms_upd_ofdm_pctl1_table(wlc_hw
);
1737 brcms_b_upd_synthpu(wlc_hw
);
1740 /* Perform a soft reset of the PHY PLL */
1741 void brcms_b_core_phypll_reset(struct brcms_hardware
*wlc_hw
)
1743 ai_cc_reg(wlc_hw
->sih
, offsetof(struct chipcregs
, chipcontrol_addr
),
1746 ai_cc_reg(wlc_hw
->sih
, offsetof(struct chipcregs
, chipcontrol_data
),
1749 ai_cc_reg(wlc_hw
->sih
, offsetof(struct chipcregs
, chipcontrol_data
),
1752 ai_cc_reg(wlc_hw
->sih
, offsetof(struct chipcregs
, chipcontrol_data
),
1757 /* light way to turn on phy clock without reset for NPHY only
1758 * refer to brcms_b_core_phy_clk for full version
1760 void brcms_b_phyclk_fgc(struct brcms_hardware
*wlc_hw
, bool clk
)
1762 /* support(necessary for NPHY and HYPHY) only */
1763 if (!BRCMS_ISNPHY(wlc_hw
->band
))
1767 brcms_b_core_ioctl(wlc_hw
, SICF_FGC
, SICF_FGC
);
1769 brcms_b_core_ioctl(wlc_hw
, SICF_FGC
, 0);
1773 void brcms_b_macphyclk_set(struct brcms_hardware
*wlc_hw
, bool clk
)
1776 brcms_b_core_ioctl(wlc_hw
, SICF_MPCLKE
, SICF_MPCLKE
);
1778 brcms_b_core_ioctl(wlc_hw
, SICF_MPCLKE
, 0);
1781 void brcms_b_phy_reset(struct brcms_hardware
*wlc_hw
)
1783 struct brcms_phy_pub
*pih
= wlc_hw
->band
->pi
;
1785 bool phy_in_reset
= false;
1787 brcms_dbg_info(wlc_hw
->d11core
, "wl%d: reset phy\n", wlc_hw
->unit
);
1792 phy_bw_clkbits
= wlc_phy_clk_bwbits(wlc_hw
->band
->pi
);
1794 /* Specific reset sequence required for NPHY rev 3 and 4 */
1795 if (BRCMS_ISNPHY(wlc_hw
->band
) && NREV_GE(wlc_hw
->band
->phyrev
, 3) &&
1796 NREV_LE(wlc_hw
->band
->phyrev
, 4)) {
1797 /* Set the PHY bandwidth */
1798 brcms_b_core_ioctl(wlc_hw
, SICF_BWMASK
, phy_bw_clkbits
);
1802 /* Perform a soft reset of the PHY PLL */
1803 brcms_b_core_phypll_reset(wlc_hw
);
1806 brcms_b_core_ioctl(wlc_hw
, (SICF_PRST
| SICF_PCLKE
),
1807 (SICF_PRST
| SICF_PCLKE
));
1808 phy_in_reset
= true;
1810 brcms_b_core_ioctl(wlc_hw
,
1811 (SICF_PRST
| SICF_PCLKE
| SICF_BWMASK
),
1812 (SICF_PRST
| SICF_PCLKE
| phy_bw_clkbits
));
1816 brcms_b_core_phy_clk(wlc_hw
, ON
);
1819 wlc_phy_anacore(pih
, ON
);
1822 /* switch to and initialize new band */
1823 static void brcms_b_setband(struct brcms_hardware
*wlc_hw
, uint bandunit
,
1825 struct brcms_c_info
*wlc
= wlc_hw
->wlc
;
1828 /* Enable the d11 core before accessing it */
1829 if (!bcma_core_is_enabled(wlc_hw
->d11core
)) {
1830 bcma_core_enable(wlc_hw
->d11core
, 0);
1831 brcms_c_mctrl_reset(wlc_hw
);
1834 macintmask
= brcms_c_setband_inact(wlc
, bandunit
);
1839 brcms_b_core_phy_clk(wlc_hw
, ON
);
1841 /* band-specific initializations */
1842 brcms_b_bsinit(wlc
, chanspec
);
1845 * If there are any pending software interrupt bits,
1846 * then replace these with a harmless nonzero value
1847 * so brcms_c_dpc() will re-enable interrupts when done.
1849 if (wlc
->macintstatus
)
1850 wlc
->macintstatus
= MI_DMAINT
;
1852 /* restore macintmask */
1853 brcms_intrsrestore(wlc
->wl
, macintmask
);
1855 /* ucode should still be suspended.. */
1856 WARN_ON((bcma_read32(wlc_hw
->d11core
, D11REGOFFS(maccontrol
)) &
1860 static bool brcms_c_isgoodchip(struct brcms_hardware
*wlc_hw
)
1863 /* reject unsupported corerev */
1864 if (!CONF_HAS(D11CONF
, wlc_hw
->corerev
)) {
1865 wiphy_err(wlc_hw
->wlc
->wiphy
, "unsupported core rev %d\n",
1873 /* Validate some board info parameters */
1874 static bool brcms_c_validboardtype(struct brcms_hardware
*wlc_hw
)
1876 uint boardrev
= wlc_hw
->boardrev
;
1878 /* 4 bits each for board type, major, minor, and tiny version */
1879 uint brt
= (boardrev
& 0xf000) >> 12;
1880 uint b0
= (boardrev
& 0xf00) >> 8;
1881 uint b1
= (boardrev
& 0xf0) >> 4;
1882 uint b2
= boardrev
& 0xf;
1884 /* voards from other vendors are always considered valid */
1885 if (ai_get_boardvendor(wlc_hw
->sih
) != PCI_VENDOR_ID_BROADCOM
)
1888 /* do some boardrev sanity checks when boardvendor is Broadcom */
1892 if (boardrev
<= 0xff)
1895 if ((brt
> 2) || (brt
== 0) || (b0
> 9) || (b0
== 0) || (b1
> 9)
1902 static void brcms_c_get_macaddr(struct brcms_hardware
*wlc_hw
, u8 etheraddr
[ETH_ALEN
])
1904 struct ssb_sprom
*sprom
= &wlc_hw
->d11core
->bus
->sprom
;
1906 /* If macaddr exists, use it (Sromrev4, CIS, ...). */
1907 if (!is_zero_ether_addr(sprom
->il0mac
)) {
1908 memcpy(etheraddr
, sprom
->il0mac
, ETH_ALEN
);
1912 if (wlc_hw
->_nbands
> 1)
1913 memcpy(etheraddr
, sprom
->et1mac
, ETH_ALEN
);
1915 memcpy(etheraddr
, sprom
->il0mac
, ETH_ALEN
);
1918 /* power both the pll and external oscillator on/off */
1919 static void brcms_b_xtal(struct brcms_hardware
*wlc_hw
, bool want
)
1921 brcms_dbg_info(wlc_hw
->d11core
, "wl%d: want %d\n", wlc_hw
->unit
, want
);
1924 * dont power down if plldown is false or
1925 * we must poll hw radio disable
1927 if (!want
&& wlc_hw
->pllreq
)
1930 wlc_hw
->sbclk
= want
;
1931 if (!wlc_hw
->sbclk
) {
1932 wlc_hw
->clk
= false;
1933 if (wlc_hw
->band
&& wlc_hw
->band
->pi
)
1934 wlc_phy_hw_clk_state_upd(wlc_hw
->band
->pi
, false);
1939 * Return true if radio is disabled, otherwise false.
1940 * hw radio disable signal is an external pin, users activate it asynchronously
1941 * this function could be called when driver is down and w/o clock
1942 * it operates on different registers depending on corerev and boardflag.
1944 static bool brcms_b_radio_read_hwdisabled(struct brcms_hardware
*wlc_hw
)
1949 xtal
= wlc_hw
->sbclk
;
1951 brcms_b_xtal(wlc_hw
, ON
);
1953 /* may need to take core out of reset first */
1957 * mac no longer enables phyclk automatically when driver
1958 * accesses phyreg throughput mac. This can be skipped since
1959 * only mac reg is accessed below
1961 if (D11REV_GE(wlc_hw
->corerev
, 18))
1962 flags
|= SICF_PCLKE
;
1965 * TODO: test suspend/resume
1967 * AI chip doesn't restore bar0win2 on
1968 * hibernation/resume, need sw fixup
1971 bcma_core_enable(wlc_hw
->d11core
, flags
);
1972 brcms_c_mctrl_reset(wlc_hw
);
1975 v
= ((bcma_read32(wlc_hw
->d11core
,
1976 D11REGOFFS(phydebug
)) & PDBG_RFD
) != 0);
1978 /* put core back into reset */
1980 bcma_core_disable(wlc_hw
->d11core
, 0);
1983 brcms_b_xtal(wlc_hw
, OFF
);
1988 static bool wlc_dma_rxreset(struct brcms_hardware
*wlc_hw
, uint fifo
)
1990 struct dma_pub
*di
= wlc_hw
->di
[fifo
];
1991 return dma_rxreset(di
);
1995 * ensure fask clock during reset
1997 * reset d11(out of reset)
1998 * reset phy(out of reset)
1999 * clear software macintstatus for fresh new start
2000 * one testing hack wlc_hw->noreset will bypass the d11/phy reset
2002 void brcms_b_corereset(struct brcms_hardware
*wlc_hw
, u32 flags
)
2007 if (flags
== BRCMS_USE_COREFLAGS
)
2008 flags
= (wlc_hw
->band
->pi
? wlc_hw
->band
->core_flags
: 0);
2010 brcms_dbg_info(wlc_hw
->d11core
, "wl%d: core reset\n", wlc_hw
->unit
);
2012 /* request FAST clock if not on */
2013 fastclk
= wlc_hw
->forcefastclk
;
2015 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_FAST
);
2017 /* reset the dma engines except first time thru */
2018 if (bcma_core_is_enabled(wlc_hw
->d11core
)) {
2019 for (i
= 0; i
< NFIFO
; i
++)
2020 if ((wlc_hw
->di
[i
]) && (!dma_txreset(wlc_hw
->di
[i
])))
2021 brcms_err(wlc_hw
->d11core
, "wl%d: %s: "
2022 "dma_txreset[%d]: cannot stop dma\n",
2023 wlc_hw
->unit
, __func__
, i
);
2025 if ((wlc_hw
->di
[RX_FIFO
])
2026 && (!wlc_dma_rxreset(wlc_hw
, RX_FIFO
)))
2027 brcms_err(wlc_hw
->d11core
, "wl%d: %s: dma_rxreset"
2028 "[%d]: cannot stop dma\n",
2029 wlc_hw
->unit
, __func__
, RX_FIFO
);
2031 /* if noreset, just stop the psm and return */
2032 if (wlc_hw
->noreset
) {
2033 wlc_hw
->wlc
->macintstatus
= 0; /* skip wl_dpc after down */
2034 brcms_b_mctrl(wlc_hw
, MCTL_PSM_RUN
| MCTL_EN_MAC
, 0);
2039 * mac no longer enables phyclk automatically when driver accesses
2040 * phyreg throughput mac, AND phy_reset is skipped at early stage when
2041 * band->pi is invalid. need to enable PHY CLK
2043 if (D11REV_GE(wlc_hw
->corerev
, 18))
2044 flags
|= SICF_PCLKE
;
2048 * In chips with PMU, the fastclk request goes through d11 core
2049 * reg 0x1e0, which is cleared by the core_reset. have to re-request it.
2051 * This adds some delay and we can optimize it by also requesting
2052 * fastclk through chipcommon during this period if necessary. But
2053 * that has to work coordinate with other driver like mips/arm since
2054 * they may touch chipcommon as well.
2056 wlc_hw
->clk
= false;
2057 bcma_core_enable(wlc_hw
->d11core
, flags
);
2059 if (wlc_hw
->band
&& wlc_hw
->band
->pi
)
2060 wlc_phy_hw_clk_state_upd(wlc_hw
->band
->pi
, true);
2062 brcms_c_mctrl_reset(wlc_hw
);
2064 if (ai_get_cccaps(wlc_hw
->sih
) & CC_CAP_PMU
)
2065 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_FAST
);
2067 brcms_b_phy_reset(wlc_hw
);
2069 /* turn on PHY_PLL */
2070 brcms_b_core_phypll_ctl(wlc_hw
, true);
2072 /* clear sw intstatus */
2073 wlc_hw
->wlc
->macintstatus
= 0;
2075 /* restore the clk setting */
2077 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_DYNAMIC
);
2080 /* txfifo sizes needs to be modified(increased) since the newer cores
2083 static void brcms_b_corerev_fifofixup(struct brcms_hardware
*wlc_hw
)
2085 struct bcma_device
*core
= wlc_hw
->d11core
;
2087 u16 txfifo_startblk
= TXFIFO_START_BLK
, txfifo_endblk
;
2088 u16 txfifo_def
, txfifo_def1
;
2091 /* tx fifos start at TXFIFO_START_BLK from the Base address */
2092 txfifo_startblk
= TXFIFO_START_BLK
;
2094 /* sequence of operations: reset fifo, set fifo size, reset fifo */
2095 for (fifo_nu
= 0; fifo_nu
< NFIFO
; fifo_nu
++) {
2097 txfifo_endblk
= txfifo_startblk
+ wlc_hw
->xmtfifo_sz
[fifo_nu
];
2098 txfifo_def
= (txfifo_startblk
& 0xff) |
2099 (((txfifo_endblk
- 1) & 0xff) << TXFIFO_FIFOTOP_SHIFT
);
2100 txfifo_def1
= ((txfifo_startblk
>> 8) & 0x1) |
2102 1) >> 8) & 0x1) << TXFIFO_FIFOTOP_SHIFT
);
2104 TXFIFOCMD_RESET_MASK
| (fifo_nu
<< TXFIFOCMD_FIFOSEL_SHIFT
);
2106 bcma_write16(core
, D11REGOFFS(xmtfifocmd
), txfifo_cmd
);
2107 bcma_write16(core
, D11REGOFFS(xmtfifodef
), txfifo_def
);
2108 bcma_write16(core
, D11REGOFFS(xmtfifodef1
), txfifo_def1
);
2110 bcma_write16(core
, D11REGOFFS(xmtfifocmd
), txfifo_cmd
);
2112 txfifo_startblk
+= wlc_hw
->xmtfifo_sz
[fifo_nu
];
2115 * need to propagate to shm location to be in sync since ucode/hw won't
2118 brcms_b_write_shm(wlc_hw
, M_FIFOSIZE0
,
2119 wlc_hw
->xmtfifo_sz
[TX_AC_BE_FIFO
]);
2120 brcms_b_write_shm(wlc_hw
, M_FIFOSIZE1
,
2121 wlc_hw
->xmtfifo_sz
[TX_AC_VI_FIFO
]);
2122 brcms_b_write_shm(wlc_hw
, M_FIFOSIZE2
,
2123 ((wlc_hw
->xmtfifo_sz
[TX_AC_VO_FIFO
] << 8) | wlc_hw
->
2124 xmtfifo_sz
[TX_AC_BK_FIFO
]));
2125 brcms_b_write_shm(wlc_hw
, M_FIFOSIZE3
,
2126 ((wlc_hw
->xmtfifo_sz
[TX_ATIM_FIFO
] << 8) | wlc_hw
->
2127 xmtfifo_sz
[TX_BCMC_FIFO
]));
2130 /* This function is used for changing the tsf frac register
2131 * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz
2132 * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz
2133 * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz
2134 * HTPHY Formula is 2^26/freq(MHz) e.g.
2135 * For spuron2 - 126MHz -> 2^26/126 = 532610.0
2136 * - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082
2137 * For spuron: 123MHz -> 2^26/123 = 545600.5
2138 * - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341
2139 * For spur off: 120MHz -> 2^26/120 = 559240.5
2140 * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889
2143 void brcms_b_switch_macfreq(struct brcms_hardware
*wlc_hw
, u8 spurmode
)
2145 struct bcma_device
*core
= wlc_hw
->d11core
;
2147 if ((ai_get_chip_id(wlc_hw
->sih
) == BCMA_CHIP_ID_BCM43224
) ||
2148 (ai_get_chip_id(wlc_hw
->sih
) == BCMA_CHIP_ID_BCM43225
)) {
2149 if (spurmode
== WL_SPURAVOID_ON2
) { /* 126Mhz */
2150 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_l
), 0x2082);
2151 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_h
), 0x8);
2152 } else if (spurmode
== WL_SPURAVOID_ON1
) { /* 123Mhz */
2153 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_l
), 0x5341);
2154 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_h
), 0x8);
2155 } else { /* 120Mhz */
2156 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_l
), 0x8889);
2157 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_h
), 0x8);
2159 } else if (BRCMS_ISLCNPHY(wlc_hw
->band
)) {
2160 if (spurmode
== WL_SPURAVOID_ON1
) { /* 82Mhz */
2161 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_l
), 0x7CE0);
2162 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_h
), 0xC);
2163 } else { /* 80Mhz */
2164 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_l
), 0xCCCD);
2165 bcma_write16(core
, D11REGOFFS(tsf_clk_frac_h
), 0xC);
2170 void brcms_c_start_station(struct brcms_c_info
*wlc
, u8
*addr
)
2172 memcpy(wlc
->pub
->cur_etheraddr
, addr
, sizeof(wlc
->pub
->cur_etheraddr
));
2173 wlc
->bsscfg
->type
= BRCMS_TYPE_STATION
;
2176 void brcms_c_start_ap(struct brcms_c_info
*wlc
, u8
*addr
, const u8
*bssid
,
2177 u8
*ssid
, size_t ssid_len
)
2179 brcms_c_set_ssid(wlc
, ssid
, ssid_len
);
2181 memcpy(wlc
->pub
->cur_etheraddr
, addr
, sizeof(wlc
->pub
->cur_etheraddr
));
2182 memcpy(wlc
->bsscfg
->BSSID
, bssid
, sizeof(wlc
->bsscfg
->BSSID
));
2183 wlc
->bsscfg
->type
= BRCMS_TYPE_AP
;
2185 brcms_b_mctrl(wlc
->hw
, MCTL_AP
| MCTL_INFRA
, MCTL_AP
| MCTL_INFRA
);
2188 void brcms_c_start_adhoc(struct brcms_c_info
*wlc
, u8
*addr
)
2190 memcpy(wlc
->pub
->cur_etheraddr
, addr
, sizeof(wlc
->pub
->cur_etheraddr
));
2191 wlc
->bsscfg
->type
= BRCMS_TYPE_ADHOC
;
2193 brcms_b_mctrl(wlc
->hw
, MCTL_AP
| MCTL_INFRA
, 0);
2196 /* Initialize GPIOs that are controlled by D11 core */
2197 static void brcms_c_gpio_init(struct brcms_c_info
*wlc
)
2199 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2202 /* use GPIO select 0 to get all gpio signals from the gpio out reg */
2203 brcms_b_mctrl(wlc_hw
, MCTL_GPOUT_SEL_MASK
, 0);
2206 * Common GPIO setup:
2207 * G0 = LED 0 = WLAN Activity
2208 * G1 = LED 1 = WLAN 2.4 GHz Radio State
2209 * G2 = LED 2 = WLAN 5 GHz Radio State
2210 * G4 = radio disable input (HI enabled, LO disabled)
2215 /* Allocate GPIOs for mimo antenna diversity feature */
2216 if (wlc_hw
->antsel_type
== ANTSEL_2x3
) {
2217 /* Enable antenna diversity, use 2x3 mode */
2218 brcms_b_mhf(wlc_hw
, MHF3
, MHF3_ANTSEL_EN
,
2219 MHF3_ANTSEL_EN
, BRCM_BAND_ALL
);
2220 brcms_b_mhf(wlc_hw
, MHF3
, MHF3_ANTSEL_MODE
,
2221 MHF3_ANTSEL_MODE
, BRCM_BAND_ALL
);
2223 /* init superswitch control */
2224 wlc_phy_antsel_init(wlc_hw
->band
->pi
, false);
2226 } else if (wlc_hw
->antsel_type
== ANTSEL_2x4
) {
2227 gm
|= gc
|= (BOARD_GPIO_12
| BOARD_GPIO_13
);
2229 * The board itself is powered by these GPIOs
2230 * (when not sending pattern) so set them high
2232 bcma_set16(wlc_hw
->d11core
, D11REGOFFS(psm_gpio_oe
),
2233 (BOARD_GPIO_12
| BOARD_GPIO_13
));
2234 bcma_set16(wlc_hw
->d11core
, D11REGOFFS(psm_gpio_out
),
2235 (BOARD_GPIO_12
| BOARD_GPIO_13
));
2237 /* Enable antenna diversity, use 2x4 mode */
2238 brcms_b_mhf(wlc_hw
, MHF3
, MHF3_ANTSEL_EN
,
2239 MHF3_ANTSEL_EN
, BRCM_BAND_ALL
);
2240 brcms_b_mhf(wlc_hw
, MHF3
, MHF3_ANTSEL_MODE
, 0,
2243 /* Configure the desired clock to be 4Mhz */
2244 brcms_b_write_shm(wlc_hw
, M_ANTSEL_CLKDIV
,
2245 ANTSEL_CLKDIV_4MHZ
);
2249 * gpio 9 controls the PA. ucode is responsible
2250 * for wiggling out and oe
2252 if (wlc_hw
->boardflags
& BFL_PACTRL
)
2253 gm
|= gc
|= BOARD_GPIO_PACTRL
;
2255 /* apply to gpiocontrol register */
2256 bcma_chipco_gpio_control(&wlc_hw
->d11core
->bus
->drv_cc
, gm
, gc
);
2259 static void brcms_ucode_write(struct brcms_hardware
*wlc_hw
,
2260 const __le32 ucode
[], const size_t nbytes
)
2262 struct bcma_device
*core
= wlc_hw
->d11core
;
2266 brcms_dbg_info(wlc_hw
->d11core
, "wl%d\n", wlc_hw
->unit
);
2268 count
= (nbytes
/ sizeof(u32
));
2270 bcma_write32(core
, D11REGOFFS(objaddr
),
2271 OBJADDR_AUTO_INC
| OBJADDR_UCM_SEL
);
2272 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2273 for (i
= 0; i
< count
; i
++)
2274 bcma_write32(core
, D11REGOFFS(objdata
), le32_to_cpu(ucode
[i
]));
2278 static void brcms_ucode_download(struct brcms_hardware
*wlc_hw
)
2280 struct brcms_c_info
*wlc
;
2281 struct brcms_ucode
*ucode
= &wlc_hw
->wlc
->wl
->ucode
;
2285 if (wlc_hw
->ucode_loaded
)
2288 if (D11REV_IS(wlc_hw
->corerev
, 17) || D11REV_IS(wlc_hw
->corerev
, 23)) {
2289 if (BRCMS_ISNPHY(wlc_hw
->band
)) {
2290 brcms_ucode_write(wlc_hw
, ucode
->bcm43xx_16_mimo
,
2291 ucode
->bcm43xx_16_mimosz
);
2292 wlc_hw
->ucode_loaded
= true;
2294 brcms_err(wlc_hw
->d11core
,
2295 "%s: wl%d: unsupported phy in corerev %d\n",
2296 __func__
, wlc_hw
->unit
, wlc_hw
->corerev
);
2297 } else if (D11REV_IS(wlc_hw
->corerev
, 24)) {
2298 if (BRCMS_ISLCNPHY(wlc_hw
->band
)) {
2299 brcms_ucode_write(wlc_hw
, ucode
->bcm43xx_24_lcn
,
2300 ucode
->bcm43xx_24_lcnsz
);
2301 wlc_hw
->ucode_loaded
= true;
2303 brcms_err(wlc_hw
->d11core
,
2304 "%s: wl%d: unsupported phy in corerev %d\n",
2305 __func__
, wlc_hw
->unit
, wlc_hw
->corerev
);
2310 void brcms_b_txant_set(struct brcms_hardware
*wlc_hw
, u16 phytxant
)
2312 /* update sw state */
2313 wlc_hw
->bmac_phytxant
= phytxant
;
2315 /* push to ucode if up */
2318 brcms_c_ucode_txant_set(wlc_hw
);
2322 u16
brcms_b_get_txant(struct brcms_hardware
*wlc_hw
)
2324 return (u16
) wlc_hw
->wlc
->stf
->txant
;
2327 void brcms_b_antsel_type_set(struct brcms_hardware
*wlc_hw
, u8 antsel_type
)
2329 wlc_hw
->antsel_type
= antsel_type
;
2331 /* Update the antsel type for phy module to use */
2332 wlc_phy_antsel_type_set(wlc_hw
->band
->pi
, antsel_type
);
2335 static void brcms_b_fifoerrors(struct brcms_hardware
*wlc_hw
)
2339 uint intstatus
, idx
;
2340 struct bcma_device
*core
= wlc_hw
->d11core
;
2342 unit
= wlc_hw
->unit
;
2344 for (idx
= 0; idx
< NFIFO
; idx
++) {
2345 /* read intstatus register and ignore any non-error bits */
2348 D11REGOFFS(intctrlregs
[idx
].intstatus
)) &
2353 brcms_dbg_int(core
, "wl%d: intstatus%d 0x%x\n",
2354 unit
, idx
, intstatus
);
2356 if (intstatus
& I_RO
) {
2357 brcms_err(core
, "wl%d: fifo %d: receive fifo "
2358 "overflow\n", unit
, idx
);
2362 if (intstatus
& I_PC
) {
2363 brcms_err(core
, "wl%d: fifo %d: descriptor error\n",
2368 if (intstatus
& I_PD
) {
2369 brcms_err(core
, "wl%d: fifo %d: data error\n", unit
,
2374 if (intstatus
& I_DE
) {
2375 brcms_err(core
, "wl%d: fifo %d: descriptor protocol "
2376 "error\n", unit
, idx
);
2380 if (intstatus
& I_RU
)
2381 brcms_err(core
, "wl%d: fifo %d: receive descriptor "
2382 "underflow\n", idx
, unit
);
2384 if (intstatus
& I_XU
) {
2385 brcms_err(core
, "wl%d: fifo %d: transmit fifo "
2386 "underflow\n", idx
, unit
);
2391 brcms_fatal_error(wlc_hw
->wlc
->wl
); /* big hammer */
2395 D11REGOFFS(intctrlregs
[idx
].intstatus
),
2400 void brcms_c_intrson(struct brcms_c_info
*wlc
)
2402 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2403 wlc
->macintmask
= wlc
->defmacintmask
;
2404 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(macintmask
), wlc
->macintmask
);
2407 u32
brcms_c_intrsoff(struct brcms_c_info
*wlc
)
2409 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2415 macintmask
= wlc
->macintmask
; /* isr can still happen */
2417 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(macintmask
), 0);
2418 (void)bcma_read32(wlc_hw
->d11core
, D11REGOFFS(macintmask
));
2419 udelay(1); /* ensure int line is no longer driven */
2420 wlc
->macintmask
= 0;
2422 /* return previous macintmask; resolve race between us and our isr */
2423 return wlc
->macintstatus
? 0 : macintmask
;
2426 void brcms_c_intrsrestore(struct brcms_c_info
*wlc
, u32 macintmask
)
2428 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2432 wlc
->macintmask
= macintmask
;
2433 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(macintmask
), wlc
->macintmask
);
2436 /* assumes that the d11 MAC is enabled */
2437 static void brcms_b_tx_fifo_suspend(struct brcms_hardware
*wlc_hw
,
2440 u8 fifo
= 1 << tx_fifo
;
2442 /* Two clients of this code, 11h Quiet period and scanning. */
2444 /* only suspend if not already suspended */
2445 if ((wlc_hw
->suspended_fifos
& fifo
) == fifo
)
2448 /* force the core awake only if not already */
2449 if (wlc_hw
->suspended_fifos
== 0)
2450 brcms_c_ucode_wake_override_set(wlc_hw
,
2451 BRCMS_WAKE_OVERRIDE_TXFIFO
);
2453 wlc_hw
->suspended_fifos
|= fifo
;
2455 if (wlc_hw
->di
[tx_fifo
]) {
2457 * Suspending AMPDU transmissions in the middle can cause
2458 * underflow which may result in mismatch between ucode and
2459 * driver so suspend the mac before suspending the FIFO
2461 if (BRCMS_PHY_11N_CAP(wlc_hw
->band
))
2462 brcms_c_suspend_mac_and_wait(wlc_hw
->wlc
);
2464 dma_txsuspend(wlc_hw
->di
[tx_fifo
]);
2466 if (BRCMS_PHY_11N_CAP(wlc_hw
->band
))
2467 brcms_c_enable_mac(wlc_hw
->wlc
);
2471 static void brcms_b_tx_fifo_resume(struct brcms_hardware
*wlc_hw
,
2474 /* BMAC_NOTE: BRCMS_TX_FIFO_ENAB is done in brcms_c_dpc() for DMA case
2475 * but need to be done here for PIO otherwise the watchdog will catch
2476 * the inconsistency and fire
2478 /* Two clients of this code, 11h Quiet period and scanning. */
2479 if (wlc_hw
->di
[tx_fifo
])
2480 dma_txresume(wlc_hw
->di
[tx_fifo
]);
2482 /* allow core to sleep again */
2483 if (wlc_hw
->suspended_fifos
== 0)
2486 wlc_hw
->suspended_fifos
&= ~(1 << tx_fifo
);
2487 if (wlc_hw
->suspended_fifos
== 0)
2488 brcms_c_ucode_wake_override_clear(wlc_hw
,
2489 BRCMS_WAKE_OVERRIDE_TXFIFO
);
2493 /* precondition: requires the mac core to be enabled */
2494 static void brcms_b_mute(struct brcms_hardware
*wlc_hw
, bool mute_tx
)
2496 static const u8 null_ether_addr
[ETH_ALEN
] = {0, 0, 0, 0, 0, 0};
2497 u8
*ethaddr
= wlc_hw
->wlc
->pub
->cur_etheraddr
;
2500 /* suspend tx fifos */
2501 brcms_b_tx_fifo_suspend(wlc_hw
, TX_DATA_FIFO
);
2502 brcms_b_tx_fifo_suspend(wlc_hw
, TX_CTL_FIFO
);
2503 brcms_b_tx_fifo_suspend(wlc_hw
, TX_AC_BK_FIFO
);
2504 brcms_b_tx_fifo_suspend(wlc_hw
, TX_AC_VI_FIFO
);
2506 /* zero the address match register so we do not send ACKs */
2507 brcms_b_set_addrmatch(wlc_hw
, RCM_MAC_OFFSET
, null_ether_addr
);
2509 /* resume tx fifos */
2510 brcms_b_tx_fifo_resume(wlc_hw
, TX_DATA_FIFO
);
2511 brcms_b_tx_fifo_resume(wlc_hw
, TX_CTL_FIFO
);
2512 brcms_b_tx_fifo_resume(wlc_hw
, TX_AC_BK_FIFO
);
2513 brcms_b_tx_fifo_resume(wlc_hw
, TX_AC_VI_FIFO
);
2515 /* Restore address */
2516 brcms_b_set_addrmatch(wlc_hw
, RCM_MAC_OFFSET
, ethaddr
);
2519 wlc_phy_mute_upd(wlc_hw
->band
->pi
, mute_tx
, 0);
2522 brcms_c_ucode_mute_override_set(wlc_hw
);
2524 brcms_c_ucode_mute_override_clear(wlc_hw
);
2528 brcms_c_mute(struct brcms_c_info
*wlc
, bool mute_tx
)
2530 brcms_b_mute(wlc
->hw
, mute_tx
);
2534 * Read and clear macintmask and macintstatus and intstatus registers.
2535 * This routine should be called with interrupts off
2537 * -1 if brcms_deviceremoved(wlc) evaluates to true;
2538 * 0 if the interrupt is not for us, or we are in some special cases;
2539 * device interrupt status bits otherwise.
2541 static inline u32
wlc_intstatus(struct brcms_c_info
*wlc
, bool in_isr
)
2543 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2544 struct bcma_device
*core
= wlc_hw
->d11core
;
2545 u32 macintstatus
, mask
;
2547 /* macintstatus includes a DMA interrupt summary bit */
2548 macintstatus
= bcma_read32(core
, D11REGOFFS(macintstatus
));
2549 mask
= in_isr
? wlc
->macintmask
: wlc
->defmacintmask
;
2551 trace_brcms_macintstatus(&core
->dev
, in_isr
, macintstatus
, mask
);
2553 /* detect cardbus removed, in power down(suspend) and in reset */
2554 if (brcms_deviceremoved(wlc
))
2557 /* brcms_deviceremoved() succeeds even when the core is still resetting,
2558 * handle that case here.
2560 if (macintstatus
== 0xffffffff)
2563 /* defer unsolicited interrupts */
2564 macintstatus
&= mask
;
2567 if (macintstatus
== 0)
2570 /* turn off the interrupts */
2571 bcma_write32(core
, D11REGOFFS(macintmask
), 0);
2572 (void)bcma_read32(core
, D11REGOFFS(macintmask
));
2573 wlc
->macintmask
= 0;
2575 /* clear device interrupts */
2576 bcma_write32(core
, D11REGOFFS(macintstatus
), macintstatus
);
2578 /* MI_DMAINT is indication of non-zero intstatus */
2579 if (macintstatus
& MI_DMAINT
)
2581 * only fifo interrupt enabled is I_RI in
2582 * RX_FIFO. If MI_DMAINT is set, assume it
2583 * is set and clear the interrupt.
2585 bcma_write32(core
, D11REGOFFS(intctrlregs
[RX_FIFO
].intstatus
),
2588 return macintstatus
;
2591 /* Update wlc->macintstatus and wlc->intstatus[]. */
2592 /* Return true if they are updated successfully. false otherwise */
2593 bool brcms_c_intrsupd(struct brcms_c_info
*wlc
)
2597 /* read and clear macintstatus and intstatus registers */
2598 macintstatus
= wlc_intstatus(wlc
, false);
2600 /* device is removed */
2601 if (macintstatus
== 0xffffffff)
2604 /* update interrupt status in software */
2605 wlc
->macintstatus
|= macintstatus
;
2611 * First-level interrupt processing.
2612 * Return true if this was our interrupt
2613 * and if further brcms_c_dpc() processing is required,
2616 bool brcms_c_isr(struct brcms_c_info
*wlc
)
2618 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2621 if (!wlc_hw
->up
|| !wlc
->macintmask
)
2624 /* read and clear macintstatus and intstatus registers */
2625 macintstatus
= wlc_intstatus(wlc
, true);
2627 if (macintstatus
== 0xffffffff) {
2628 brcms_err(wlc_hw
->d11core
,
2629 "DEVICEREMOVED detected in the ISR code path\n");
2633 /* it is not for us */
2634 if (macintstatus
== 0)
2637 /* save interrupt status bits */
2638 wlc
->macintstatus
= macintstatus
;
2644 void brcms_c_suspend_mac_and_wait(struct brcms_c_info
*wlc
)
2646 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2647 struct bcma_device
*core
= wlc_hw
->d11core
;
2650 brcms_dbg_mac80211(core
, "wl%d: bandunit %d\n", wlc_hw
->unit
,
2651 wlc_hw
->band
->bandunit
);
2654 * Track overlapping suspend requests
2656 wlc_hw
->mac_suspend_depth
++;
2657 if (wlc_hw
->mac_suspend_depth
> 1)
2660 /* force the core awake */
2661 brcms_c_ucode_wake_override_set(wlc_hw
, BRCMS_WAKE_OVERRIDE_MACSUSPEND
);
2663 mc
= bcma_read32(core
, D11REGOFFS(maccontrol
));
2665 if (mc
== 0xffffffff) {
2666 brcms_err(core
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
2668 brcms_down(wlc
->wl
);
2671 WARN_ON(mc
& MCTL_PSM_JMP_0
);
2672 WARN_ON(!(mc
& MCTL_PSM_RUN
));
2673 WARN_ON(!(mc
& MCTL_EN_MAC
));
2675 mi
= bcma_read32(core
, D11REGOFFS(macintstatus
));
2676 if (mi
== 0xffffffff) {
2677 brcms_err(core
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
2679 brcms_down(wlc
->wl
);
2682 WARN_ON(mi
& MI_MACSSPNDD
);
2684 brcms_b_mctrl(wlc_hw
, MCTL_EN_MAC
, 0);
2686 SPINWAIT(!(bcma_read32(core
, D11REGOFFS(macintstatus
)) & MI_MACSSPNDD
),
2687 BRCMS_MAX_MAC_SUSPEND
);
2689 if (!(bcma_read32(core
, D11REGOFFS(macintstatus
)) & MI_MACSSPNDD
)) {
2690 brcms_err(core
, "wl%d: wlc_suspend_mac_and_wait: waited %d uS"
2691 " and MI_MACSSPNDD is still not on.\n",
2692 wlc_hw
->unit
, BRCMS_MAX_MAC_SUSPEND
);
2693 brcms_err(core
, "wl%d: psmdebug 0x%08x, phydebug 0x%08x, "
2694 "psm_brc 0x%04x\n", wlc_hw
->unit
,
2695 bcma_read32(core
, D11REGOFFS(psmdebug
)),
2696 bcma_read32(core
, D11REGOFFS(phydebug
)),
2697 bcma_read16(core
, D11REGOFFS(psm_brc
)));
2700 mc
= bcma_read32(core
, D11REGOFFS(maccontrol
));
2701 if (mc
== 0xffffffff) {
2702 brcms_err(core
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
2704 brcms_down(wlc
->wl
);
2707 WARN_ON(mc
& MCTL_PSM_JMP_0
);
2708 WARN_ON(!(mc
& MCTL_PSM_RUN
));
2709 WARN_ON(mc
& MCTL_EN_MAC
);
2712 void brcms_c_enable_mac(struct brcms_c_info
*wlc
)
2714 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2715 struct bcma_device
*core
= wlc_hw
->d11core
;
2718 brcms_dbg_mac80211(core
, "wl%d: bandunit %d\n", wlc_hw
->unit
,
2719 wlc
->band
->bandunit
);
2722 * Track overlapping suspend requests
2724 wlc_hw
->mac_suspend_depth
--;
2725 if (wlc_hw
->mac_suspend_depth
> 0)
2728 mc
= bcma_read32(core
, D11REGOFFS(maccontrol
));
2729 WARN_ON(mc
& MCTL_PSM_JMP_0
);
2730 WARN_ON(mc
& MCTL_EN_MAC
);
2731 WARN_ON(!(mc
& MCTL_PSM_RUN
));
2733 brcms_b_mctrl(wlc_hw
, MCTL_EN_MAC
, MCTL_EN_MAC
);
2734 bcma_write32(core
, D11REGOFFS(macintstatus
), MI_MACSSPNDD
);
2736 mc
= bcma_read32(core
, D11REGOFFS(maccontrol
));
2737 WARN_ON(mc
& MCTL_PSM_JMP_0
);
2738 WARN_ON(!(mc
& MCTL_EN_MAC
));
2739 WARN_ON(!(mc
& MCTL_PSM_RUN
));
2741 mi
= bcma_read32(core
, D11REGOFFS(macintstatus
));
2742 WARN_ON(mi
& MI_MACSSPNDD
);
2744 brcms_c_ucode_wake_override_clear(wlc_hw
,
2745 BRCMS_WAKE_OVERRIDE_MACSUSPEND
);
2748 void brcms_b_band_stf_ss_set(struct brcms_hardware
*wlc_hw
, u8 stf_mode
)
2750 wlc_hw
->hw_stf_ss_opmode
= stf_mode
;
2753 brcms_upd_ofdm_pctl1_table(wlc_hw
);
2756 static bool brcms_b_validate_chip_access(struct brcms_hardware
*wlc_hw
)
2758 struct bcma_device
*core
= wlc_hw
->d11core
;
2760 struct wiphy
*wiphy
= wlc_hw
->wlc
->wiphy
;
2762 /* Validate dchip register access */
2764 bcma_write32(core
, D11REGOFFS(objaddr
), OBJADDR_SHM_SEL
| 0);
2765 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2766 w
= bcma_read32(core
, D11REGOFFS(objdata
));
2768 /* Can we write and read back a 32bit register? */
2769 bcma_write32(core
, D11REGOFFS(objaddr
), OBJADDR_SHM_SEL
| 0);
2770 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2771 bcma_write32(core
, D11REGOFFS(objdata
), (u32
) 0xaa5555aa);
2773 bcma_write32(core
, D11REGOFFS(objaddr
), OBJADDR_SHM_SEL
| 0);
2774 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2775 val
= bcma_read32(core
, D11REGOFFS(objdata
));
2776 if (val
!= (u32
) 0xaa5555aa) {
2777 wiphy_err(wiphy
, "wl%d: validate_chip_access: SHM = 0x%x, "
2778 "expected 0xaa5555aa\n", wlc_hw
->unit
, val
);
2782 bcma_write32(core
, D11REGOFFS(objaddr
), OBJADDR_SHM_SEL
| 0);
2783 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2784 bcma_write32(core
, D11REGOFFS(objdata
), (u32
) 0x55aaaa55);
2786 bcma_write32(core
, D11REGOFFS(objaddr
), OBJADDR_SHM_SEL
| 0);
2787 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2788 val
= bcma_read32(core
, D11REGOFFS(objdata
));
2789 if (val
!= (u32
) 0x55aaaa55) {
2790 wiphy_err(wiphy
, "wl%d: validate_chip_access: SHM = 0x%x, "
2791 "expected 0x55aaaa55\n", wlc_hw
->unit
, val
);
2795 bcma_write32(core
, D11REGOFFS(objaddr
), OBJADDR_SHM_SEL
| 0);
2796 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2797 bcma_write32(core
, D11REGOFFS(objdata
), w
);
2799 /* clear CFPStart */
2800 bcma_write32(core
, D11REGOFFS(tsf_cfpstart
), 0);
2802 w
= bcma_read32(core
, D11REGOFFS(maccontrol
));
2803 if ((w
!= (MCTL_IHR_EN
| MCTL_WAKE
)) &&
2804 (w
!= (MCTL_IHR_EN
| MCTL_GMODE
| MCTL_WAKE
))) {
2805 wiphy_err(wiphy
, "wl%d: validate_chip_access: maccontrol = "
2806 "0x%x, expected 0x%x or 0x%x\n", wlc_hw
->unit
, w
,
2807 (MCTL_IHR_EN
| MCTL_WAKE
),
2808 (MCTL_IHR_EN
| MCTL_GMODE
| MCTL_WAKE
));
2815 #define PHYPLL_WAIT_US 100000
2817 void brcms_b_core_phypll_ctl(struct brcms_hardware
*wlc_hw
, bool on
)
2819 struct bcma_device
*core
= wlc_hw
->d11core
;
2822 brcms_dbg_info(core
, "wl%d\n", wlc_hw
->unit
);
2827 if ((ai_get_chip_id(wlc_hw
->sih
) == BCMA_CHIP_ID_BCM4313
)) {
2828 bcma_set32(core
, D11REGOFFS(clk_ctl_st
),
2830 CCS_ERSRC_REQ_D11PLL
|
2831 CCS_ERSRC_REQ_PHYPLL
);
2832 SPINWAIT((bcma_read32(core
, D11REGOFFS(clk_ctl_st
)) &
2833 CCS_ERSRC_AVAIL_HT
) != CCS_ERSRC_AVAIL_HT
,
2836 tmp
= bcma_read32(core
, D11REGOFFS(clk_ctl_st
));
2837 if ((tmp
& CCS_ERSRC_AVAIL_HT
) != CCS_ERSRC_AVAIL_HT
)
2838 brcms_err(core
, "%s: turn on PHY PLL failed\n",
2841 bcma_set32(core
, D11REGOFFS(clk_ctl_st
),
2842 tmp
| CCS_ERSRC_REQ_D11PLL
|
2843 CCS_ERSRC_REQ_PHYPLL
);
2844 SPINWAIT((bcma_read32(core
, D11REGOFFS(clk_ctl_st
)) &
2845 (CCS_ERSRC_AVAIL_D11PLL
|
2846 CCS_ERSRC_AVAIL_PHYPLL
)) !=
2847 (CCS_ERSRC_AVAIL_D11PLL
|
2848 CCS_ERSRC_AVAIL_PHYPLL
), PHYPLL_WAIT_US
);
2850 tmp
= bcma_read32(core
, D11REGOFFS(clk_ctl_st
));
2852 (CCS_ERSRC_AVAIL_D11PLL
| CCS_ERSRC_AVAIL_PHYPLL
))
2854 (CCS_ERSRC_AVAIL_D11PLL
| CCS_ERSRC_AVAIL_PHYPLL
))
2855 brcms_err(core
, "%s: turn on PHY PLL failed\n",
2860 * Since the PLL may be shared, other cores can still
2861 * be requesting it; so we'll deassert the request but
2862 * not wait for status to comply.
2864 bcma_mask32(core
, D11REGOFFS(clk_ctl_st
),
2865 ~CCS_ERSRC_REQ_PHYPLL
);
2866 (void)bcma_read32(core
, D11REGOFFS(clk_ctl_st
));
2870 static void brcms_c_coredisable(struct brcms_hardware
*wlc_hw
)
2874 brcms_dbg_info(wlc_hw
->d11core
, "wl%d: disable core\n", wlc_hw
->unit
);
2876 dev_gone
= brcms_deviceremoved(wlc_hw
->wlc
);
2881 if (wlc_hw
->noreset
)
2885 wlc_phy_switch_radio(wlc_hw
->band
->pi
, OFF
);
2887 /* turn off analog core */
2888 wlc_phy_anacore(wlc_hw
->band
->pi
, OFF
);
2890 /* turn off PHYPLL to save power */
2891 brcms_b_core_phypll_ctl(wlc_hw
, false);
2893 wlc_hw
->clk
= false;
2894 bcma_core_disable(wlc_hw
->d11core
, 0);
2895 wlc_phy_hw_clk_state_upd(wlc_hw
->band
->pi
, false);
2898 static void brcms_c_flushqueues(struct brcms_c_info
*wlc
)
2900 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
2903 /* free any posted tx packets */
2904 for (i
= 0; i
< NFIFO
; i
++) {
2905 if (wlc_hw
->di
[i
]) {
2906 dma_txreclaim(wlc_hw
->di
[i
], DMA_RANGE_ALL
);
2907 if (i
< TX_BCMC_FIFO
)
2908 ieee80211_wake_queue(wlc
->pub
->ieee_hw
,
2909 brcms_fifo_to_ac(i
));
2913 /* free any posted rx packets */
2914 dma_rxreclaim(wlc_hw
->di
[RX_FIFO
]);
2918 brcms_b_read_objmem(struct brcms_hardware
*wlc_hw
, uint offset
, u32 sel
)
2920 struct bcma_device
*core
= wlc_hw
->d11core
;
2921 u16 objoff
= D11REGOFFS(objdata
);
2923 bcma_write32(core
, D11REGOFFS(objaddr
), sel
| (offset
>> 2));
2924 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2928 return bcma_read16(core
, objoff
);
2932 brcms_b_write_objmem(struct brcms_hardware
*wlc_hw
, uint offset
, u16 v
,
2935 struct bcma_device
*core
= wlc_hw
->d11core
;
2936 u16 objoff
= D11REGOFFS(objdata
);
2938 bcma_write32(core
, D11REGOFFS(objaddr
), sel
| (offset
>> 2));
2939 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
2943 bcma_wflush16(core
, objoff
, v
);
2947 * Read a single u16 from shared memory.
2948 * SHM 'offset' needs to be an even address
2950 u16
brcms_b_read_shm(struct brcms_hardware
*wlc_hw
, uint offset
)
2952 return brcms_b_read_objmem(wlc_hw
, offset
, OBJADDR_SHM_SEL
);
2956 * Write a single u16 to shared memory.
2957 * SHM 'offset' needs to be an even address
2959 void brcms_b_write_shm(struct brcms_hardware
*wlc_hw
, uint offset
, u16 v
)
2961 brcms_b_write_objmem(wlc_hw
, offset
, v
, OBJADDR_SHM_SEL
);
2965 * Copy a buffer to shared memory of specified type .
2966 * SHM 'offset' needs to be an even address and
2967 * Buffer length 'len' must be an even number of bytes
2968 * 'sel' selects the type of memory
2971 brcms_b_copyto_objmem(struct brcms_hardware
*wlc_hw
, uint offset
,
2972 const void *buf
, int len
, u32 sel
)
2975 const u8
*p
= (const u8
*)buf
;
2978 if (len
<= 0 || (offset
& 1) || (len
& 1))
2981 for (i
= 0; i
< len
; i
+= 2) {
2982 v
= p
[i
] | (p
[i
+ 1] << 8);
2983 brcms_b_write_objmem(wlc_hw
, offset
+ i
, v
, sel
);
2988 * Copy a piece of shared memory of specified type to a buffer .
2989 * SHM 'offset' needs to be an even address and
2990 * Buffer length 'len' must be an even number of bytes
2991 * 'sel' selects the type of memory
2994 brcms_b_copyfrom_objmem(struct brcms_hardware
*wlc_hw
, uint offset
, void *buf
,
3001 if (len
<= 0 || (offset
& 1) || (len
& 1))
3004 for (i
= 0; i
< len
; i
+= 2) {
3005 v
= brcms_b_read_objmem(wlc_hw
, offset
+ i
, sel
);
3007 p
[i
+ 1] = (v
>> 8) & 0xFF;
3011 /* Copy a buffer to shared memory.
3012 * SHM 'offset' needs to be an even address and
3013 * Buffer length 'len' must be an even number of bytes
3015 static void brcms_c_copyto_shm(struct brcms_c_info
*wlc
, uint offset
,
3016 const void *buf
, int len
)
3018 brcms_b_copyto_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
3021 static void brcms_b_retrylimit_upd(struct brcms_hardware
*wlc_hw
,
3027 /* write retry limit to SCR, shouldn't need to suspend */
3029 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(objaddr
),
3030 OBJADDR_SCR_SEL
| S_DOT11_SRC_LMT
);
3031 (void)bcma_read32(wlc_hw
->d11core
, D11REGOFFS(objaddr
));
3032 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(objdata
), wlc_hw
->SRL
);
3033 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(objaddr
),
3034 OBJADDR_SCR_SEL
| S_DOT11_LRC_LMT
);
3035 (void)bcma_read32(wlc_hw
->d11core
, D11REGOFFS(objaddr
));
3036 bcma_write32(wlc_hw
->d11core
, D11REGOFFS(objdata
), wlc_hw
->LRL
);
3040 static void brcms_b_pllreq(struct brcms_hardware
*wlc_hw
, bool set
, u32 req_bit
)
3043 if (mboolisset(wlc_hw
->pllreq
, req_bit
))
3046 mboolset(wlc_hw
->pllreq
, req_bit
);
3048 if (mboolisset(wlc_hw
->pllreq
, BRCMS_PLLREQ_FLIP
)) {
3050 brcms_b_xtal(wlc_hw
, ON
);
3053 if (!mboolisset(wlc_hw
->pllreq
, req_bit
))
3056 mboolclr(wlc_hw
->pllreq
, req_bit
);
3058 if (mboolisset(wlc_hw
->pllreq
, BRCMS_PLLREQ_FLIP
)) {
3060 brcms_b_xtal(wlc_hw
, OFF
);
3065 static void brcms_b_antsel_set(struct brcms_hardware
*wlc_hw
, u32 antsel_avail
)
3067 wlc_hw
->antsel_avail
= antsel_avail
;
3071 * conditions under which the PM bit should be set in outgoing frames
3072 * and STAY_AWAKE is meaningful
3074 static bool brcms_c_ps_allowed(struct brcms_c_info
*wlc
)
3076 /* not supporting PS so always return false for now */
3080 static void brcms_c_statsupd(struct brcms_c_info
*wlc
)
3083 struct macstat
*macstats
;
3090 /* if driver down, make no sense to update stats */
3094 macstats
= wlc
->core
->macstat_snapshot
;
3097 /* save last rx fifo 0 overflow count */
3098 rxf0ovfl
= macstats
->rxf0ovfl
;
3100 /* save last tx fifo underflow count */
3101 for (i
= 0; i
< NFIFO
; i
++)
3102 txfunfl
[i
] = macstats
->txfunfl
[i
];
3105 /* Read mac stats from contiguous shared memory */
3106 brcms_b_copyfrom_objmem(wlc
->hw
, M_UCODE_MACSTAT
, macstats
,
3107 sizeof(*macstats
), OBJADDR_SHM_SEL
);
3110 /* check for rx fifo 0 overflow */
3111 delta
= (u16
)(macstats
->rxf0ovfl
- rxf0ovfl
);
3113 brcms_err(wlc
->hw
->d11core
, "wl%d: %u rx fifo 0 overflows!\n",
3114 wlc
->pub
->unit
, delta
);
3116 /* check for tx fifo underflows */
3117 for (i
= 0; i
< NFIFO
; i
++) {
3118 delta
= macstats
->txfunfl
[i
] - txfunfl
[i
];
3120 brcms_err(wlc
->hw
->d11core
,
3121 "wl%d: %u tx fifo %d underflows!\n",
3122 wlc
->pub
->unit
, delta
, i
);
3126 /* merge counters from dma module */
3127 for (i
= 0; i
< NFIFO
; i
++) {
3129 dma_counterreset(wlc
->hw
->di
[i
]);
3133 static void brcms_b_reset(struct brcms_hardware
*wlc_hw
)
3135 /* reset the core */
3136 if (!brcms_deviceremoved(wlc_hw
->wlc
))
3137 brcms_b_corereset(wlc_hw
, BRCMS_USE_COREFLAGS
);
3139 /* purge the dma rings */
3140 brcms_c_flushqueues(wlc_hw
->wlc
);
3143 void brcms_c_reset(struct brcms_c_info
*wlc
)
3145 brcms_dbg_info(wlc
->hw
->d11core
, "wl%d\n", wlc
->pub
->unit
);
3147 /* slurp up hw mac counters before core reset */
3148 brcms_c_statsupd(wlc
);
3150 /* reset our snapshot of macstat counters */
3151 memset(wlc
->core
->macstat_snapshot
, 0, sizeof(struct macstat
));
3153 brcms_b_reset(wlc
->hw
);
3156 void brcms_c_init_scb(struct scb
*scb
)
3160 memset(scb
, 0, sizeof(struct scb
));
3161 scb
->flags
= SCB_WMECAP
| SCB_HTCAP
;
3162 for (i
= 0; i
< NUMPRIO
; i
++) {
3164 scb
->seqctl
[i
] = 0xFFFF;
3167 scb
->seqctl_nonqos
= 0xFFFF;
3168 scb
->magic
= SCB_MAGIC
;
3173 * download ucode/PCM
3174 * let ucode run to suspended
3175 * download ucode inits
3176 * config other core registers
3179 static void brcms_b_coreinit(struct brcms_c_info
*wlc
)
3181 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
3182 struct bcma_device
*core
= wlc_hw
->d11core
;
3186 bool fifosz_fixup
= false;
3189 struct brcms_ucode
*ucode
= &wlc_hw
->wlc
->wl
->ucode
;
3191 brcms_dbg_info(core
, "wl%d: core init\n", wlc_hw
->unit
);
3194 brcms_b_mctrl(wlc_hw
, ~0, (MCTL_IHR_EN
| MCTL_PSM_JMP_0
| MCTL_WAKE
));
3196 brcms_ucode_download(wlc_hw
);
3198 * FIFOSZ fixup. driver wants to controls the fifo allocation.
3200 fifosz_fixup
= true;
3202 /* let the PSM run to the suspended state, set mode to BSS STA */
3203 bcma_write32(core
, D11REGOFFS(macintstatus
), -1);
3204 brcms_b_mctrl(wlc_hw
, ~0,
3205 (MCTL_IHR_EN
| MCTL_INFRA
| MCTL_PSM_RUN
| MCTL_WAKE
));
3207 /* wait for ucode to self-suspend after auto-init */
3208 SPINWAIT(((bcma_read32(core
, D11REGOFFS(macintstatus
)) &
3209 MI_MACSSPNDD
) == 0), 1000 * 1000);
3210 if ((bcma_read32(core
, D11REGOFFS(macintstatus
)) & MI_MACSSPNDD
) == 0)
3211 brcms_err(core
, "wl%d: wlc_coreinit: ucode did not self-"
3212 "suspend!\n", wlc_hw
->unit
);
3214 brcms_c_gpio_init(wlc
);
3216 sflags
= bcma_aread32(core
, BCMA_IOST
);
3218 if (D11REV_IS(wlc_hw
->corerev
, 17) || D11REV_IS(wlc_hw
->corerev
, 23)) {
3219 if (BRCMS_ISNPHY(wlc_hw
->band
))
3220 brcms_c_write_inits(wlc_hw
, ucode
->d11n0initvals16
);
3222 brcms_err(core
, "%s: wl%d: unsupported phy in corerev"
3223 " %d\n", __func__
, wlc_hw
->unit
,
3225 } else if (D11REV_IS(wlc_hw
->corerev
, 24)) {
3226 if (BRCMS_ISLCNPHY(wlc_hw
->band
))
3227 brcms_c_write_inits(wlc_hw
, ucode
->d11lcn0initvals24
);
3229 brcms_err(core
, "%s: wl%d: unsupported phy in corerev"
3230 " %d\n", __func__
, wlc_hw
->unit
,
3233 brcms_err(core
, "%s: wl%d: unsupported corerev %d\n",
3234 __func__
, wlc_hw
->unit
, wlc_hw
->corerev
);
3237 /* For old ucode, txfifo sizes needs to be modified(increased) */
3239 brcms_b_corerev_fifofixup(wlc_hw
);
3241 /* check txfifo allocations match between ucode and driver */
3242 buf
[TX_AC_BE_FIFO
] = brcms_b_read_shm(wlc_hw
, M_FIFOSIZE0
);
3243 if (buf
[TX_AC_BE_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_AC_BE_FIFO
]) {
3247 buf
[TX_AC_VI_FIFO
] = brcms_b_read_shm(wlc_hw
, M_FIFOSIZE1
);
3248 if (buf
[TX_AC_VI_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_AC_VI_FIFO
]) {
3252 buf
[TX_AC_BK_FIFO
] = brcms_b_read_shm(wlc_hw
, M_FIFOSIZE2
);
3253 buf
[TX_AC_VO_FIFO
] = (buf
[TX_AC_BK_FIFO
] >> 8) & 0xff;
3254 buf
[TX_AC_BK_FIFO
] &= 0xff;
3255 if (buf
[TX_AC_BK_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_AC_BK_FIFO
]) {
3259 if (buf
[TX_AC_VO_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_AC_VO_FIFO
]) {
3263 buf
[TX_BCMC_FIFO
] = brcms_b_read_shm(wlc_hw
, M_FIFOSIZE3
);
3264 buf
[TX_ATIM_FIFO
] = (buf
[TX_BCMC_FIFO
] >> 8) & 0xff;
3265 buf
[TX_BCMC_FIFO
] &= 0xff;
3266 if (buf
[TX_BCMC_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_BCMC_FIFO
]) {
3270 if (buf
[TX_ATIM_FIFO
] != wlc_hw
->xmtfifo_sz
[TX_ATIM_FIFO
]) {
3275 brcms_err(core
, "wlc_coreinit: txfifo mismatch: ucode size %d"
3276 " driver size %d index %d\n", buf
[i
],
3277 wlc_hw
->xmtfifo_sz
[i
], i
);
3279 /* make sure we can still talk to the mac */
3280 WARN_ON(bcma_read32(core
, D11REGOFFS(maccontrol
)) == 0xffffffff);
3282 /* band-specific inits done by wlc_bsinit() */
3284 /* Set up frame burst size and antenna swap threshold init values */
3285 brcms_b_write_shm(wlc_hw
, M_MBURST_SIZE
, MAXTXFRAMEBURST
);
3286 brcms_b_write_shm(wlc_hw
, M_MAX_ANTCNT
, ANTCNT
);
3288 /* enable one rx interrupt per received frame */
3289 bcma_write32(core
, D11REGOFFS(intrcvlazy
[0]), (1 << IRL_FC_SHIFT
));
3291 /* set the station mode (BSS STA) */
3292 brcms_b_mctrl(wlc_hw
,
3293 (MCTL_INFRA
| MCTL_DISCARD_PMQ
| MCTL_AP
),
3294 (MCTL_INFRA
| MCTL_DISCARD_PMQ
));
3296 /* set up Beacon interval */
3297 bcnint_us
= 0x8000 << 10;
3298 bcma_write32(core
, D11REGOFFS(tsf_cfprep
),
3299 (bcnint_us
<< CFPREP_CBI_SHIFT
));
3300 bcma_write32(core
, D11REGOFFS(tsf_cfpstart
), bcnint_us
);
3301 bcma_write32(core
, D11REGOFFS(macintstatus
), MI_GP1
);
3303 /* write interrupt mask */
3304 bcma_write32(core
, D11REGOFFS(intctrlregs
[RX_FIFO
].intmask
),
3307 /* allow the MAC to control the PHY clock (dynamic on/off) */
3308 brcms_b_macphyclk_set(wlc_hw
, ON
);
3310 /* program dynamic clock control fast powerup delay register */
3311 wlc
->fastpwrup_dly
= ai_clkctl_fast_pwrup_delay(wlc_hw
->sih
);
3312 bcma_write16(core
, D11REGOFFS(scc_fastpwrup_dly
), wlc
->fastpwrup_dly
);
3314 /* tell the ucode the corerev */
3315 brcms_b_write_shm(wlc_hw
, M_MACHW_VER
, (u16
) wlc_hw
->corerev
);
3317 /* tell the ucode MAC capabilities */
3318 brcms_b_write_shm(wlc_hw
, M_MACHW_CAP_L
,
3319 (u16
) (wlc_hw
->machwcap
& 0xffff));
3320 brcms_b_write_shm(wlc_hw
, M_MACHW_CAP_H
,
3322 machwcap
>> 16) & 0xffff));
3324 /* write retry limits to SCR, this done after PSM init */
3325 bcma_write32(core
, D11REGOFFS(objaddr
),
3326 OBJADDR_SCR_SEL
| S_DOT11_SRC_LMT
);
3327 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
3328 bcma_write32(core
, D11REGOFFS(objdata
), wlc_hw
->SRL
);
3329 bcma_write32(core
, D11REGOFFS(objaddr
),
3330 OBJADDR_SCR_SEL
| S_DOT11_LRC_LMT
);
3331 (void)bcma_read32(core
, D11REGOFFS(objaddr
));
3332 bcma_write32(core
, D11REGOFFS(objdata
), wlc_hw
->LRL
);
3334 /* write rate fallback retry limits */
3335 brcms_b_write_shm(wlc_hw
, M_SFRMTXCNTFBRTHSD
, wlc_hw
->SFBL
);
3336 brcms_b_write_shm(wlc_hw
, M_LFRMTXCNTFBRTHSD
, wlc_hw
->LFBL
);
3338 bcma_mask16(core
, D11REGOFFS(ifs_ctl
), 0x0FFF);
3339 bcma_write16(core
, D11REGOFFS(ifs_aifsn
), EDCF_AIFSN_MIN
);
3341 /* init the tx dma engines */
3342 for (i
= 0; i
< NFIFO
; i
++) {
3344 dma_txinit(wlc_hw
->di
[i
]);
3347 /* init the rx dma engine(s) and post receive buffers */
3348 dma_rxinit(wlc_hw
->di
[RX_FIFO
]);
3349 dma_rxfill(wlc_hw
->di
[RX_FIFO
]);
3352 static void brcms_b_init(struct brcms_hardware
*wlc_hw
, u16 chanspec
)
3356 struct brcms_c_info
*wlc
= wlc_hw
->wlc
;
3358 /* request FAST clock if not on */
3359 fastclk
= wlc_hw
->forcefastclk
;
3361 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_FAST
);
3363 /* disable interrupts */
3364 macintmask
= brcms_intrsoff(wlc
->wl
);
3366 /* set up the specified band and chanspec */
3367 brcms_c_setxband(wlc_hw
, chspec_bandunit(chanspec
));
3368 wlc_phy_chanspec_radio_set(wlc_hw
->band
->pi
, chanspec
);
3370 /* do one-time phy inits and calibration */
3371 wlc_phy_cal_init(wlc_hw
->band
->pi
);
3373 /* core-specific initialization */
3374 brcms_b_coreinit(wlc
);
3376 /* band-specific inits */
3377 brcms_b_bsinit(wlc
, chanspec
);
3379 /* restore macintmask */
3380 brcms_intrsrestore(wlc
->wl
, macintmask
);
3382 /* seed wake_override with BRCMS_WAKE_OVERRIDE_MACSUSPEND since the mac
3383 * is suspended and brcms_c_enable_mac() will clear this override bit.
3385 mboolset(wlc_hw
->wake_override
, BRCMS_WAKE_OVERRIDE_MACSUSPEND
);
3388 * initialize mac_suspend_depth to 1 to match ucode
3389 * initial suspended state
3391 wlc_hw
->mac_suspend_depth
= 1;
3393 /* restore the clk */
3395 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_DYNAMIC
);
3398 static void brcms_c_set_phy_chanspec(struct brcms_c_info
*wlc
,
3401 /* Save our copy of the chanspec */
3402 wlc
->chanspec
= chanspec
;
3404 /* Set the chanspec and power limits for this locale */
3405 brcms_c_channel_set_chanspec(wlc
->cmi
, chanspec
, BRCMS_TXPWR_MAX
);
3407 if (wlc
->stf
->ss_algosel_auto
)
3408 brcms_c_stf_ss_algo_channel_get(wlc
, &wlc
->stf
->ss_algo_channel
,
3411 brcms_c_stf_ss_update(wlc
, wlc
->band
);
3415 brcms_default_rateset(struct brcms_c_info
*wlc
, struct brcms_c_rateset
*rs
)
3417 brcms_c_rateset_default(rs
, NULL
, wlc
->band
->phytype
,
3418 wlc
->band
->bandtype
, false, BRCMS_RATE_MASK_FULL
,
3419 (bool) (wlc
->pub
->_n_enab
& SUPPORT_11N
),
3420 brcms_chspec_bw(wlc
->default_bss
->chanspec
),
3421 wlc
->stf
->txstreams
);
3424 /* derive wlc->band->basic_rate[] table from 'rateset' */
3425 static void brcms_c_rate_lookup_init(struct brcms_c_info
*wlc
,
3426 struct brcms_c_rateset
*rateset
)
3432 u8
*br
= wlc
->band
->basic_rate
;
3435 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
3436 memset(br
, 0, BRCM_MAXRATE
+ 1);
3438 /* For each basic rate in the rates list, make an entry in the
3439 * best basic lookup.
3441 for (i
= 0; i
< rateset
->count
; i
++) {
3442 /* only make an entry for a basic rate */
3443 if (!(rateset
->rates
[i
] & BRCMS_RATE_FLAG
))
3446 /* mask off basic bit */
3447 rate
= (rateset
->rates
[i
] & BRCMS_RATE_MASK
);
3449 if (rate
> BRCM_MAXRATE
) {
3450 brcms_err(wlc
->hw
->d11core
, "brcms_c_rate_lookup_init: "
3451 "invalid rate 0x%X in rate set\n",
3459 /* The rate lookup table now has non-zero entries for each
3460 * basic rate, equal to the basic rate: br[basicN] = basicN
3462 * To look up the best basic rate corresponding to any
3463 * particular rate, code can use the basic_rate table
3466 * basic_rate = wlc->band->basic_rate[tx_rate]
3468 * Make sure there is a best basic rate entry for
3469 * every rate by walking up the table from low rates
3470 * to high, filling in holes in the lookup table
3473 for (i
= 0; i
< wlc
->band
->hw_rateset
.count
; i
++) {
3474 rate
= wlc
->band
->hw_rateset
.rates
[i
];
3476 if (br
[rate
] != 0) {
3477 /* This rate is a basic rate.
3478 * Keep track of the best basic rate so far by
3481 if (is_ofdm_rate(rate
))
3489 /* This rate is not a basic rate so figure out the
3490 * best basic rate less than this rate and fill in
3491 * the hole in the table
3494 br
[rate
] = is_ofdm_rate(rate
) ? ofdm_basic
: cck_basic
;
3499 if (is_ofdm_rate(rate
)) {
3501 * In 11g and 11a, the OFDM mandatory rates
3502 * are 6, 12, and 24 Mbps
3504 if (rate
>= BRCM_RATE_24M
)
3505 mandatory
= BRCM_RATE_24M
;
3506 else if (rate
>= BRCM_RATE_12M
)
3507 mandatory
= BRCM_RATE_12M
;
3509 mandatory
= BRCM_RATE_6M
;
3511 /* In 11b, all CCK rates are mandatory 1 - 11 Mbps */
3515 br
[rate
] = mandatory
;
3519 static void brcms_c_bandinit_ordered(struct brcms_c_info
*wlc
,
3522 struct brcms_c_rateset default_rateset
;
3524 uint i
, band_order
[2];
3527 * We might have been bandlocked during down and the chip
3528 * power-cycled (hibernate). Figure out the right band to park on
3530 if (wlc
->bandlocked
|| wlc
->pub
->_nbands
== 1) {
3531 /* updated in brcms_c_bandlock() */
3532 parkband
= wlc
->band
->bandunit
;
3533 band_order
[0] = band_order
[1] = parkband
;
3535 /* park on the band of the specified chanspec */
3536 parkband
= chspec_bandunit(chanspec
);
3538 /* order so that parkband initialize last */
3539 band_order
[0] = parkband
^ 1;
3540 band_order
[1] = parkband
;
3543 /* make each band operational, software state init */
3544 for (i
= 0; i
< wlc
->pub
->_nbands
; i
++) {
3545 uint j
= band_order
[i
];
3547 wlc
->band
= wlc
->bandstate
[j
];
3549 brcms_default_rateset(wlc
, &default_rateset
);
3551 /* fill in hw_rate */
3552 brcms_c_rateset_filter(&default_rateset
, &wlc
->band
->hw_rateset
,
3553 false, BRCMS_RATES_CCK_OFDM
, BRCMS_RATE_MASK
,
3554 (bool) (wlc
->pub
->_n_enab
& SUPPORT_11N
));
3556 /* init basic rate lookup */
3557 brcms_c_rate_lookup_init(wlc
, &default_rateset
);
3560 /* sync up phy/radio chanspec */
3561 brcms_c_set_phy_chanspec(wlc
, chanspec
);
3565 * Set or clear filtering related maccontrol bits based on
3566 * specified filter flags
3568 void brcms_c_mac_promisc(struct brcms_c_info
*wlc
, uint filter_flags
)
3570 u32 promisc_bits
= 0;
3572 wlc
->filter_flags
= filter_flags
;
3574 if (filter_flags
& FIF_OTHER_BSS
)
3575 promisc_bits
|= MCTL_PROMISC
;
3577 if (filter_flags
& FIF_BCN_PRBRESP_PROMISC
)
3578 promisc_bits
|= MCTL_BCNS_PROMISC
;
3580 if (filter_flags
& FIF_FCSFAIL
)
3581 promisc_bits
|= MCTL_KEEPBADFCS
;
3583 if (filter_flags
& (FIF_CONTROL
| FIF_PSPOLL
))
3584 promisc_bits
|= MCTL_KEEPCONTROL
;
3586 brcms_b_mctrl(wlc
->hw
,
3587 MCTL_PROMISC
| MCTL_BCNS_PROMISC
|
3588 MCTL_KEEPCONTROL
| MCTL_KEEPBADFCS
,
3593 * ucode, hwmac update
3594 * Channel dependent updates for ucode and hw
3596 static void brcms_c_ucode_mac_upd(struct brcms_c_info
*wlc
)
3598 /* enable or disable any active IBSSs depending on whether or not
3599 * we are on the home channel
3601 if (wlc
->home_chanspec
== wlc_phy_chanspec_get(wlc
->band
->pi
)) {
3602 if (wlc
->pub
->associated
) {
3604 * BMAC_NOTE: This is something that should be fixed
3605 * in ucode inits. I think that the ucode inits set
3606 * up the bcn templates and shm values with a bogus
3607 * beacon. This should not be done in the inits. If
3608 * ucode needs to set up a beacon for testing, the
3609 * test routines should write it down, not expect the
3610 * inits to populate a bogus beacon.
3612 if (BRCMS_PHY_11N_CAP(wlc
->band
))
3613 brcms_b_write_shm(wlc
->hw
,
3614 M_BCN_TXTSF_OFFSET
, 0);
3617 /* disable an active IBSS if we are not on the home channel */
3621 static void brcms_c_write_rate_shm(struct brcms_c_info
*wlc
, u8 rate
,
3625 u8 basic_phy_rate
, basic_index
;
3626 u16 dir_table
, basic_table
;
3629 /* Shared memory address for the table we are reading */
3630 dir_table
= is_ofdm_rate(basic_rate
) ? M_RT_DIRMAP_A
: M_RT_DIRMAP_B
;
3632 /* Shared memory address for the table we are writing */
3633 basic_table
= is_ofdm_rate(rate
) ? M_RT_BBRSMAP_A
: M_RT_BBRSMAP_B
;
3636 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
3637 * the index into the rate table.
3639 phy_rate
= rate_info
[rate
] & BRCMS_RATE_MASK
;
3640 basic_phy_rate
= rate_info
[basic_rate
] & BRCMS_RATE_MASK
;
3641 index
= phy_rate
& 0xf;
3642 basic_index
= basic_phy_rate
& 0xf;
3644 /* Find the SHM pointer to the ACK rate entry by looking in the
3647 basic_ptr
= brcms_b_read_shm(wlc
->hw
, (dir_table
+ basic_index
* 2));
3649 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
3650 * to the correct basic rate for the given incoming rate
3652 brcms_b_write_shm(wlc
->hw
, (basic_table
+ index
* 2), basic_ptr
);
3655 static const struct brcms_c_rateset
*
3656 brcms_c_rateset_get_hwrs(struct brcms_c_info
*wlc
)
3658 const struct brcms_c_rateset
*rs_dflt
;
3660 if (BRCMS_PHY_11N_CAP(wlc
->band
)) {
3661 if (wlc
->band
->bandtype
== BRCM_BAND_5G
)
3662 rs_dflt
= &ofdm_mimo_rates
;
3664 rs_dflt
= &cck_ofdm_mimo_rates
;
3665 } else if (wlc
->band
->gmode
)
3666 rs_dflt
= &cck_ofdm_rates
;
3668 rs_dflt
= &cck_rates
;
3673 static void brcms_c_set_ratetable(struct brcms_c_info
*wlc
)
3675 const struct brcms_c_rateset
*rs_dflt
;
3676 struct brcms_c_rateset rs
;
3677 u8 rate
, basic_rate
;
3680 rs_dflt
= brcms_c_rateset_get_hwrs(wlc
);
3682 brcms_c_rateset_copy(rs_dflt
, &rs
);
3683 brcms_c_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
3685 /* walk the phy rate table and update SHM basic rate lookup table */
3686 for (i
= 0; i
< rs
.count
; i
++) {
3687 rate
= rs
.rates
[i
] & BRCMS_RATE_MASK
;
3689 /* for a given rate brcms_basic_rate returns the rate at
3690 * which a response ACK/CTS should be sent.
3692 basic_rate
= brcms_basic_rate(wlc
, rate
);
3693 if (basic_rate
== 0)
3694 /* This should only happen if we are using a
3695 * restricted rateset.
3697 basic_rate
= rs
.rates
[0] & BRCMS_RATE_MASK
;
3699 brcms_c_write_rate_shm(wlc
, rate
, basic_rate
);
3703 /* band-specific init */
3704 static void brcms_c_bsinit(struct brcms_c_info
*wlc
)
3706 brcms_dbg_info(wlc
->hw
->d11core
, "wl%d: bandunit %d\n",
3707 wlc
->pub
->unit
, wlc
->band
->bandunit
);
3709 /* write ucode ACK/CTS rate table */
3710 brcms_c_set_ratetable(wlc
);
3712 /* update some band specific mac configuration */
3713 brcms_c_ucode_mac_upd(wlc
);
3715 /* init antenna selection */
3716 brcms_c_antsel_init(wlc
->asi
);
3720 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
3722 brcms_c_duty_cycle_set(struct brcms_c_info
*wlc
, int duty_cycle
, bool isOFDM
,
3725 int idle_busy_ratio_x_16
= 0;
3727 isOFDM
? M_TX_IDLE_BUSY_RATIO_X_16_OFDM
:
3728 M_TX_IDLE_BUSY_RATIO_X_16_CCK
;
3729 if (duty_cycle
> 100 || duty_cycle
< 0) {
3730 brcms_err(wlc
->hw
->d11core
,
3731 "wl%d: duty cycle value off limit\n",
3736 idle_busy_ratio_x_16
= (100 - duty_cycle
) * 16 / duty_cycle
;
3737 /* Only write to shared memory when wl is up */
3739 brcms_b_write_shm(wlc
->hw
, offset
, (u16
) idle_busy_ratio_x_16
);
3742 wlc
->tx_duty_cycle_ofdm
= (u16
) duty_cycle
;
3744 wlc
->tx_duty_cycle_cck
= (u16
) duty_cycle
;
3749 /* push sw hps and wake state through hardware */
3750 static void brcms_c_set_ps_ctrl(struct brcms_c_info
*wlc
)
3756 hps
= brcms_c_ps_allowed(wlc
);
3758 brcms_dbg_mac80211(wlc
->hw
->d11core
, "wl%d: hps %d\n", wlc
->pub
->unit
,
3761 v1
= bcma_read32(wlc
->hw
->d11core
, D11REGOFFS(maccontrol
));
3766 brcms_b_mctrl(wlc
->hw
, MCTL_WAKE
| MCTL_HPS
, v2
);
3768 awake_before
= ((v1
& MCTL_WAKE
) || ((v1
& MCTL_HPS
) == 0));
3771 brcms_b_wait_for_wake(wlc
->hw
);
3775 * Write this BSS config's MAC address to core.
3776 * Updates RXE match engine.
3778 static int brcms_c_set_mac(struct brcms_bss_cfg
*bsscfg
)
3781 struct brcms_c_info
*wlc
= bsscfg
->wlc
;
3783 /* enter the MAC addr into the RXE match registers */
3784 brcms_c_set_addrmatch(wlc
, RCM_MAC_OFFSET
, wlc
->pub
->cur_etheraddr
);
3786 brcms_c_ampdu_macaddr_upd(wlc
);
3791 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
3792 * Updates RXE match engine.
3794 static void brcms_c_set_bssid(struct brcms_bss_cfg
*bsscfg
)
3796 /* we need to update BSSID in RXE match registers */
3797 brcms_c_set_addrmatch(bsscfg
->wlc
, RCM_BSSID_OFFSET
, bsscfg
->BSSID
);
3800 void brcms_c_set_ssid(struct brcms_c_info
*wlc
, u8
*ssid
, size_t ssid_len
)
3802 u8 len
= min_t(u8
, sizeof(wlc
->bsscfg
->SSID
), ssid_len
);
3803 memset(wlc
->bsscfg
->SSID
, 0, sizeof(wlc
->bsscfg
->SSID
));
3805 memcpy(wlc
->bsscfg
->SSID
, ssid
, len
);
3806 wlc
->bsscfg
->SSID_len
= len
;
3809 static void brcms_b_set_shortslot(struct brcms_hardware
*wlc_hw
, bool shortslot
)
3811 wlc_hw
->shortslot
= shortslot
;
3813 if (wlc_hw
->band
->bandtype
== BRCM_BAND_2G
&& wlc_hw
->up
) {
3814 brcms_c_suspend_mac_and_wait(wlc_hw
->wlc
);
3815 brcms_b_update_slot_timing(wlc_hw
, shortslot
);
3816 brcms_c_enable_mac(wlc_hw
->wlc
);
3821 * Suspend the the MAC and update the slot timing
3822 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
3824 static void brcms_c_switch_shortslot(struct brcms_c_info
*wlc
, bool shortslot
)
3826 /* use the override if it is set */
3827 if (wlc
->shortslot_override
!= BRCMS_SHORTSLOT_AUTO
)
3828 shortslot
= (wlc
->shortslot_override
== BRCMS_SHORTSLOT_ON
);
3830 if (wlc
->shortslot
== shortslot
)
3833 wlc
->shortslot
= shortslot
;
3835 brcms_b_set_shortslot(wlc
->hw
, shortslot
);
3838 static void brcms_c_set_home_chanspec(struct brcms_c_info
*wlc
, u16 chanspec
)
3840 if (wlc
->home_chanspec
!= chanspec
) {
3841 wlc
->home_chanspec
= chanspec
;
3843 if (wlc
->pub
->associated
)
3844 wlc
->bsscfg
->current_bss
->chanspec
= chanspec
;
3849 brcms_b_set_chanspec(struct brcms_hardware
*wlc_hw
, u16 chanspec
,
3850 bool mute_tx
, struct txpwr_limits
*txpwr
)
3854 brcms_dbg_mac80211(wlc_hw
->d11core
, "wl%d: 0x%x\n", wlc_hw
->unit
,
3857 wlc_hw
->chanspec
= chanspec
;
3859 /* Switch bands if necessary */
3860 if (wlc_hw
->_nbands
> 1) {
3861 bandunit
= chspec_bandunit(chanspec
);
3862 if (wlc_hw
->band
->bandunit
!= bandunit
) {
3863 /* brcms_b_setband disables other bandunit,
3864 * use light band switch if not up yet
3867 wlc_phy_chanspec_radio_set(wlc_hw
->
3868 bandstate
[bandunit
]->
3870 brcms_b_setband(wlc_hw
, bandunit
, chanspec
);
3872 brcms_c_setxband(wlc_hw
, bandunit
);
3877 wlc_phy_initcal_enable(wlc_hw
->band
->pi
, !mute_tx
);
3881 wlc_phy_txpower_limit_set(wlc_hw
->band
->pi
, txpwr
,
3883 wlc_phy_chanspec_radio_set(wlc_hw
->band
->pi
, chanspec
);
3885 wlc_phy_chanspec_set(wlc_hw
->band
->pi
, chanspec
);
3886 wlc_phy_txpower_limit_set(wlc_hw
->band
->pi
, txpwr
, chanspec
);
3888 /* Update muting of the channel */
3889 brcms_b_mute(wlc_hw
, mute_tx
);
3893 /* switch to and initialize new band */
3894 static void brcms_c_setband(struct brcms_c_info
*wlc
,
3897 wlc
->band
= wlc
->bandstate
[bandunit
];
3902 /* wait for at least one beacon before entering sleeping state */
3903 brcms_c_set_ps_ctrl(wlc
);
3905 /* band-specific initializations */
3906 brcms_c_bsinit(wlc
);
3909 static void brcms_c_set_chanspec(struct brcms_c_info
*wlc
, u16 chanspec
)
3912 bool switchband
= false;
3913 u16 old_chanspec
= wlc
->chanspec
;
3915 if (!brcms_c_valid_chanspec_db(wlc
->cmi
, chanspec
)) {
3916 brcms_err(wlc
->hw
->d11core
, "wl%d: %s: Bad channel %d\n",
3917 wlc
->pub
->unit
, __func__
, CHSPEC_CHANNEL(chanspec
));
3921 /* Switch bands if necessary */
3922 if (wlc
->pub
->_nbands
> 1) {
3923 bandunit
= chspec_bandunit(chanspec
);
3924 if (wlc
->band
->bandunit
!= bandunit
|| wlc
->bandinit_pending
) {
3926 if (wlc
->bandlocked
) {
3927 brcms_err(wlc
->hw
->d11core
,
3928 "wl%d: %s: chspec %d band is locked!\n",
3929 wlc
->pub
->unit
, __func__
,
3930 CHSPEC_CHANNEL(chanspec
));
3934 * should the setband call come after the
3935 * brcms_b_chanspec() ? if the setband updates
3936 * (brcms_c_bsinit) use low level calls to inspect and
3937 * set state, the state inspected may be from the wrong
3938 * band, or the following brcms_b_set_chanspec() may
3941 brcms_c_setband(wlc
, bandunit
);
3945 /* sync up phy/radio chanspec */
3946 brcms_c_set_phy_chanspec(wlc
, chanspec
);
3948 /* init antenna selection */
3949 if (brcms_chspec_bw(old_chanspec
) != brcms_chspec_bw(chanspec
)) {
3950 brcms_c_antsel_init(wlc
->asi
);
3952 /* Fix the hardware rateset based on bw.
3953 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
3955 brcms_c_rateset_bw_mcs_filter(&wlc
->band
->hw_rateset
,
3956 wlc
->band
->mimo_cap_40
? brcms_chspec_bw(chanspec
) : 0);
3959 /* update some mac configuration since chanspec changed */
3960 brcms_c_ucode_mac_upd(wlc
);
3964 * This function changes the phytxctl for beacon based on current
3965 * beacon ratespec AND txant setting as per this table:
3966 * ratespec CCK ant = wlc->stf->txant
3969 void brcms_c_beacon_phytxctl_txant_upd(struct brcms_c_info
*wlc
,
3973 u16 phytxant
= wlc
->stf
->phytxant
;
3974 u16 mask
= PHY_TXC_ANT_MASK
;
3976 /* for non-siso rates or default setting, use the available chains */
3977 if (BRCMS_PHY_11N_CAP(wlc
->band
))
3978 phytxant
= brcms_c_stf_phytxchain_sel(wlc
, bcn_rspec
);
3980 phyctl
= brcms_b_read_shm(wlc
->hw
, M_BCN_PCTLWD
);
3981 phyctl
= (phyctl
& ~mask
) | phytxant
;
3982 brcms_b_write_shm(wlc
->hw
, M_BCN_PCTLWD
, phyctl
);
3986 * centralized protection config change function to simplify debugging, no
3987 * consistency checking this should be called only on changes to avoid overhead
3988 * in periodic function
3990 void brcms_c_protection_upd(struct brcms_c_info
*wlc
, uint idx
, int val
)
3993 * Cannot use brcms_dbg_* here because this function is called
3994 * before wlc is sufficiently initialized.
3996 BCMMSG(wlc
->wiphy
, "idx %d, val %d\n", idx
, val
);
3999 case BRCMS_PROT_G_SPEC
:
4000 wlc
->protection
->_g
= (bool) val
;
4002 case BRCMS_PROT_G_OVR
:
4003 wlc
->protection
->g_override
= (s8
) val
;
4005 case BRCMS_PROT_G_USER
:
4006 wlc
->protection
->gmode_user
= (u8
) val
;
4008 case BRCMS_PROT_OVERLAP
:
4009 wlc
->protection
->overlap
= (s8
) val
;
4011 case BRCMS_PROT_N_USER
:
4012 wlc
->protection
->nmode_user
= (s8
) val
;
4014 case BRCMS_PROT_N_CFG
:
4015 wlc
->protection
->n_cfg
= (s8
) val
;
4017 case BRCMS_PROT_N_CFG_OVR
:
4018 wlc
->protection
->n_cfg_override
= (s8
) val
;
4020 case BRCMS_PROT_N_NONGF
:
4021 wlc
->protection
->nongf
= (bool) val
;
4023 case BRCMS_PROT_N_NONGF_OVR
:
4024 wlc
->protection
->nongf_override
= (s8
) val
;
4026 case BRCMS_PROT_N_PAM_OVR
:
4027 wlc
->protection
->n_pam_override
= (s8
) val
;
4029 case BRCMS_PROT_N_OBSS
:
4030 wlc
->protection
->n_obss
= (bool) val
;
4039 static void brcms_c_ht_update_sgi_rx(struct brcms_c_info
*wlc
, int val
)
4042 brcms_c_update_beacon(wlc
);
4043 brcms_c_update_probe_resp(wlc
, true);
4047 static void brcms_c_ht_update_ldpc(struct brcms_c_info
*wlc
, s8 val
)
4049 wlc
->stf
->ldpc
= val
;
4052 brcms_c_update_beacon(wlc
);
4053 brcms_c_update_probe_resp(wlc
, true);
4054 wlc_phy_ldpc_override_set(wlc
->band
->pi
, (val
? true : false));
4058 void brcms_c_wme_setparams(struct brcms_c_info
*wlc
, u16 aci
,
4059 const struct ieee80211_tx_queue_params
*params
,
4063 struct shm_acparams acp_shm
;
4066 /* Only apply params if the core is out of reset and has clocks */
4068 brcms_err(wlc
->hw
->d11core
, "wl%d: %s : no-clock\n",
4069 wlc
->pub
->unit
, __func__
);
4073 memset(&acp_shm
, 0, sizeof(struct shm_acparams
));
4074 /* fill in shm ac params struct */
4075 acp_shm
.txop
= params
->txop
;
4076 /* convert from units of 32us to us for ucode */
4077 wlc
->edcf_txop
[aci
& 0x3] = acp_shm
.txop
=
4078 EDCF_TXOP2USEC(acp_shm
.txop
);
4079 acp_shm
.aifs
= (params
->aifs
& EDCF_AIFSN_MASK
);
4081 if (aci
== IEEE80211_AC_VI
&& acp_shm
.txop
== 0
4082 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
4085 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
4086 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
4087 brcms_err(wlc
->hw
->d11core
, "wl%d: edcf_setparams: bad "
4088 "aifs %d\n", wlc
->pub
->unit
, acp_shm
.aifs
);
4090 acp_shm
.cwmin
= params
->cw_min
;
4091 acp_shm
.cwmax
= params
->cw_max
;
4092 acp_shm
.cwcur
= acp_shm
.cwmin
;
4094 bcma_read16(wlc
->hw
->d11core
, D11REGOFFS(tsf_random
)) &
4096 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
4097 /* Indicate the new params to the ucode */
4098 acp_shm
.status
= brcms_b_read_shm(wlc
->hw
, (M_EDCF_QINFO
+
4101 M_EDCF_STATUS_OFF
));
4102 acp_shm
.status
|= WME_STATUS_NEWAC
;
4104 /* Fill in shm acparam table */
4105 shm_entry
= (u16
*) &acp_shm
;
4106 for (i
= 0; i
< (int)sizeof(struct shm_acparams
); i
+= 2)
4107 brcms_b_write_shm(wlc
->hw
,
4109 wme_ac2fifo
[aci
] * M_EDCF_QLEN
+ i
,
4114 brcms_c_suspend_mac_and_wait(wlc
);
4116 brcms_c_update_beacon(wlc
);
4117 brcms_c_update_probe_resp(wlc
, false);
4120 brcms_c_enable_mac(wlc
);
4123 static void brcms_c_edcf_setparams(struct brcms_c_info
*wlc
, bool suspend
)
4127 struct ieee80211_tx_queue_params txq_pars
;
4128 static const struct edcf_acparam default_edcf_acparams
[] = {
4129 {EDCF_AC_BE_ACI_STA
, EDCF_AC_BE_ECW_STA
, EDCF_AC_BE_TXOP_STA
},
4130 {EDCF_AC_BK_ACI_STA
, EDCF_AC_BK_ECW_STA
, EDCF_AC_BK_TXOP_STA
},
4131 {EDCF_AC_VI_ACI_STA
, EDCF_AC_VI_ECW_STA
, EDCF_AC_VI_TXOP_STA
},
4132 {EDCF_AC_VO_ACI_STA
, EDCF_AC_VO_ECW_STA
, EDCF_AC_VO_TXOP_STA
}
4133 }; /* ucode needs these parameters during its initialization */
4134 const struct edcf_acparam
*edcf_acp
= &default_edcf_acparams
[0];
4136 for (i_ac
= 0; i_ac
< IEEE80211_NUM_ACS
; i_ac
++, edcf_acp
++) {
4137 /* find out which ac this set of params applies to */
4138 aci
= (edcf_acp
->ACI
& EDCF_ACI_MASK
) >> EDCF_ACI_SHIFT
;
4140 /* fill in shm ac params struct */
4141 txq_pars
.txop
= edcf_acp
->TXOP
;
4142 txq_pars
.aifs
= edcf_acp
->ACI
;
4144 /* CWmin = 2^(ECWmin) - 1 */
4145 txq_pars
.cw_min
= EDCF_ECW2CW(edcf_acp
->ECW
& EDCF_ECWMIN_MASK
);
4146 /* CWmax = 2^(ECWmax) - 1 */
4147 txq_pars
.cw_max
= EDCF_ECW2CW((edcf_acp
->ECW
& EDCF_ECWMAX_MASK
)
4148 >> EDCF_ECWMAX_SHIFT
);
4149 brcms_c_wme_setparams(wlc
, aci
, &txq_pars
, suspend
);
4153 brcms_c_suspend_mac_and_wait(wlc
);
4154 brcms_c_enable_mac(wlc
);
4158 static void brcms_c_radio_monitor_start(struct brcms_c_info
*wlc
)
4160 /* Don't start the timer if HWRADIO feature is disabled */
4161 if (wlc
->radio_monitor
)
4164 wlc
->radio_monitor
= true;
4165 brcms_b_pllreq(wlc
->hw
, true, BRCMS_PLLREQ_RADIO_MON
);
4166 brcms_add_timer(wlc
->radio_timer
, TIMER_INTERVAL_RADIOCHK
, true);
4169 static bool brcms_c_radio_monitor_stop(struct brcms_c_info
*wlc
)
4171 if (!wlc
->radio_monitor
)
4174 wlc
->radio_monitor
= false;
4175 brcms_b_pllreq(wlc
->hw
, false, BRCMS_PLLREQ_RADIO_MON
);
4176 return brcms_del_timer(wlc
->radio_timer
);
4179 /* read hwdisable state and propagate to wlc flag */
4180 static void brcms_c_radio_hwdisable_upd(struct brcms_c_info
*wlc
)
4182 if (wlc
->pub
->hw_off
)
4185 if (brcms_b_radio_read_hwdisabled(wlc
->hw
))
4186 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
4188 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
4191 /* update hwradio status and return it */
4192 bool brcms_c_check_radio_disabled(struct brcms_c_info
*wlc
)
4194 brcms_c_radio_hwdisable_upd(wlc
);
4196 return mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
) ?
4200 /* periodical query hw radio button while driver is "down" */
4201 static void brcms_c_radio_timer(void *arg
)
4203 struct brcms_c_info
*wlc
= (struct brcms_c_info
*) arg
;
4205 if (brcms_deviceremoved(wlc
)) {
4206 brcms_err(wlc
->hw
->d11core
, "wl%d: %s: dead chip\n",
4207 wlc
->pub
->unit
, __func__
);
4208 brcms_down(wlc
->wl
);
4212 brcms_c_radio_hwdisable_upd(wlc
);
4215 /* common low-level watchdog code */
4216 static void brcms_b_watchdog(struct brcms_c_info
*wlc
)
4218 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
4223 /* increment second count */
4226 /* Check for FIFO error interrupts */
4227 brcms_b_fifoerrors(wlc_hw
);
4229 /* make sure RX dma has buffers */
4230 dma_rxfill(wlc
->hw
->di
[RX_FIFO
]);
4232 wlc_phy_watchdog(wlc_hw
->band
->pi
);
4235 /* common watchdog code */
4236 static void brcms_c_watchdog(struct brcms_c_info
*wlc
)
4238 brcms_dbg_info(wlc
->hw
->d11core
, "wl%d\n", wlc
->pub
->unit
);
4243 if (brcms_deviceremoved(wlc
)) {
4244 brcms_err(wlc
->hw
->d11core
, "wl%d: %s: dead chip\n",
4245 wlc
->pub
->unit
, __func__
);
4246 brcms_down(wlc
->wl
);
4250 /* increment second count */
4253 brcms_c_radio_hwdisable_upd(wlc
);
4254 /* if radio is disable, driver may be down, quit here */
4255 if (wlc
->pub
->radio_disabled
)
4258 brcms_b_watchdog(wlc
);
4261 * occasionally sample mac stat counters to
4262 * detect 16-bit counter wrap
4264 if ((wlc
->pub
->now
% SW_TIMER_MAC_STAT_UPD
) == 0)
4265 brcms_c_statsupd(wlc
);
4267 if (BRCMS_ISNPHY(wlc
->band
) &&
4268 ((wlc
->pub
->now
- wlc
->tempsense_lasttime
) >=
4269 BRCMS_TEMPSENSE_PERIOD
)) {
4270 wlc
->tempsense_lasttime
= wlc
->pub
->now
;
4271 brcms_c_tempsense_upd(wlc
);
4275 static void brcms_c_watchdog_by_timer(void *arg
)
4277 struct brcms_c_info
*wlc
= (struct brcms_c_info
*) arg
;
4279 brcms_c_watchdog(wlc
);
4282 static bool brcms_c_timers_init(struct brcms_c_info
*wlc
, int unit
)
4284 wlc
->wdtimer
= brcms_init_timer(wlc
->wl
, brcms_c_watchdog_by_timer
,
4286 if (!wlc
->wdtimer
) {
4287 wiphy_err(wlc
->wiphy
, "wl%d: wl_init_timer for wdtimer "
4292 wlc
->radio_timer
= brcms_init_timer(wlc
->wl
, brcms_c_radio_timer
,
4294 if (!wlc
->radio_timer
) {
4295 wiphy_err(wlc
->wiphy
, "wl%d: wl_init_timer for radio_timer "
4307 * Initialize brcms_c_info default values ...
4308 * may get overrides later in this function
4310 static void brcms_c_info_init(struct brcms_c_info
*wlc
, int unit
)
4314 /* Save our copy of the chanspec */
4315 wlc
->chanspec
= ch20mhz_chspec(1);
4317 /* various 802.11g modes */
4318 wlc
->shortslot
= false;
4319 wlc
->shortslot_override
= BRCMS_SHORTSLOT_AUTO
;
4321 brcms_c_protection_upd(wlc
, BRCMS_PROT_G_OVR
, BRCMS_PROTECTION_AUTO
);
4322 brcms_c_protection_upd(wlc
, BRCMS_PROT_G_SPEC
, false);
4324 brcms_c_protection_upd(wlc
, BRCMS_PROT_N_CFG_OVR
,
4325 BRCMS_PROTECTION_AUTO
);
4326 brcms_c_protection_upd(wlc
, BRCMS_PROT_N_CFG
, BRCMS_N_PROTECTION_OFF
);
4327 brcms_c_protection_upd(wlc
, BRCMS_PROT_N_NONGF_OVR
,
4328 BRCMS_PROTECTION_AUTO
);
4329 brcms_c_protection_upd(wlc
, BRCMS_PROT_N_NONGF
, false);
4330 brcms_c_protection_upd(wlc
, BRCMS_PROT_N_PAM_OVR
, AUTO
);
4332 brcms_c_protection_upd(wlc
, BRCMS_PROT_OVERLAP
,
4333 BRCMS_PROTECTION_CTL_OVERLAP
);
4335 /* 802.11g draft 4.0 NonERP elt advertisement */
4336 wlc
->include_legacy_erp
= true;
4338 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_DEF
;
4339 wlc
->stf
->txant
= ANT_TX_DEF
;
4341 wlc
->prb_resp_timeout
= BRCMS_PRB_RESP_TIMEOUT
;
4343 wlc
->usr_fragthresh
= DOT11_DEFAULT_FRAG_LEN
;
4344 for (i
= 0; i
< NFIFO
; i
++)
4345 wlc
->fragthresh
[i
] = DOT11_DEFAULT_FRAG_LEN
;
4346 wlc
->RTSThresh
= DOT11_DEFAULT_RTS_LEN
;
4348 /* default rate fallback retry limits */
4349 wlc
->SFBL
= RETRY_SHORT_FB
;
4350 wlc
->LFBL
= RETRY_LONG_FB
;
4352 /* default mac retry limits */
4353 wlc
->SRL
= RETRY_SHORT_DEF
;
4354 wlc
->LRL
= RETRY_LONG_DEF
;
4356 /* WME QoS mode is Auto by default */
4357 wlc
->pub
->_ampdu
= AMPDU_AGG_HOST
;
4360 static uint
brcms_c_attach_module(struct brcms_c_info
*wlc
)
4364 unit
= wlc
->pub
->unit
;
4366 wlc
->asi
= brcms_c_antsel_attach(wlc
);
4367 if (wlc
->asi
== NULL
) {
4368 wiphy_err(wlc
->wiphy
, "wl%d: attach: antsel_attach "
4374 wlc
->ampdu
= brcms_c_ampdu_attach(wlc
);
4375 if (wlc
->ampdu
== NULL
) {
4376 wiphy_err(wlc
->wiphy
, "wl%d: attach: ampdu_attach "
4382 if ((brcms_c_stf_attach(wlc
) != 0)) {
4383 wiphy_err(wlc
->wiphy
, "wl%d: attach: stf_attach "
4392 struct brcms_pub
*brcms_c_pub(struct brcms_c_info
*wlc
)
4398 * run backplane attach, init nvram
4400 * initialize software state for each core and band
4401 * put the whole chip in reset(driver down state), no clock
4403 static int brcms_b_attach(struct brcms_c_info
*wlc
, struct bcma_device
*core
,
4404 uint unit
, bool piomode
)
4406 struct brcms_hardware
*wlc_hw
;
4410 struct shared_phy_params sha_params
;
4411 struct wiphy
*wiphy
= wlc
->wiphy
;
4412 struct pci_dev
*pcidev
= core
->bus
->host_pci
;
4413 struct ssb_sprom
*sprom
= &core
->bus
->sprom
;
4415 if (core
->bus
->hosttype
== BCMA_HOSTTYPE_PCI
)
4416 brcms_dbg_info(core
, "wl%d: vendor 0x%x device 0x%x\n", unit
,
4420 brcms_dbg_info(core
, "wl%d: vendor 0x%x device 0x%x\n", unit
,
4421 core
->bus
->boardinfo
.vendor
,
4422 core
->bus
->boardinfo
.type
);
4428 wlc_hw
->unit
= unit
;
4429 wlc_hw
->band
= wlc_hw
->bandstate
[0];
4430 wlc_hw
->_piomode
= piomode
;
4432 /* populate struct brcms_hardware with default values */
4433 brcms_b_info_init(wlc_hw
);
4436 * Do the hardware portion of the attach. Also initialize software
4437 * state that depends on the particular hardware we are running.
4439 wlc_hw
->sih
= ai_attach(core
->bus
);
4440 if (wlc_hw
->sih
== NULL
) {
4441 wiphy_err(wiphy
, "wl%d: brcms_b_attach: si_attach failed\n",
4447 /* verify again the device is supported */
4448 if (!brcms_c_chipmatch(core
)) {
4449 wiphy_err(wiphy
, "wl%d: brcms_b_attach: Unsupported device\n",
4455 if (core
->bus
->hosttype
== BCMA_HOSTTYPE_PCI
) {
4456 wlc_hw
->vendorid
= pcidev
->vendor
;
4457 wlc_hw
->deviceid
= pcidev
->device
;
4459 wlc_hw
->vendorid
= core
->bus
->boardinfo
.vendor
;
4460 wlc_hw
->deviceid
= core
->bus
->boardinfo
.type
;
4463 wlc_hw
->d11core
= core
;
4464 wlc_hw
->corerev
= core
->id
.rev
;
4466 /* validate chip, chiprev and corerev */
4467 if (!brcms_c_isgoodchip(wlc_hw
)) {
4472 /* initialize power control registers */
4473 ai_clkctl_init(wlc_hw
->sih
);
4475 /* request fastclock and force fastclock for the rest of attach
4476 * bring the d11 core out of reset.
4477 * For PMU chips, the first wlc_clkctl_clk is no-op since core-clk
4478 * is still false; But it will be called again inside wlc_corereset,
4479 * after d11 is out of reset.
4481 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_FAST
);
4482 brcms_b_corereset(wlc_hw
, BRCMS_USE_COREFLAGS
);
4484 if (!brcms_b_validate_chip_access(wlc_hw
)) {
4485 wiphy_err(wiphy
, "wl%d: brcms_b_attach: validate_chip_access "
4491 /* get the board rev, used just below */
4492 j
= sprom
->board_rev
;
4493 /* promote srom boardrev of 0xFF to 1 */
4494 if (j
== BOARDREV_PROMOTABLE
)
4495 j
= BOARDREV_PROMOTED
;
4496 wlc_hw
->boardrev
= (u16
) j
;
4497 if (!brcms_c_validboardtype(wlc_hw
)) {
4498 wiphy_err(wiphy
, "wl%d: brcms_b_attach: Unsupported Broadcom "
4499 "board type (0x%x)" " or revision level (0x%x)\n",
4500 unit
, ai_get_boardtype(wlc_hw
->sih
),
4505 wlc_hw
->sromrev
= sprom
->revision
;
4506 wlc_hw
->boardflags
= sprom
->boardflags_lo
+ (sprom
->boardflags_hi
<< 16);
4507 wlc_hw
->boardflags2
= sprom
->boardflags2_lo
+ (sprom
->boardflags2_hi
<< 16);
4509 if (wlc_hw
->boardflags
& BFL_NOPLLDOWN
)
4510 brcms_b_pllreq(wlc_hw
, true, BRCMS_PLLREQ_SHARED
);
4512 /* check device id(srom, nvram etc.) to set bands */
4513 if (wlc_hw
->deviceid
== BCM43224_D11N_ID
||
4514 wlc_hw
->deviceid
== BCM43224_D11N_ID_VEN1
||
4515 wlc_hw
->deviceid
== BCM43224_CHIP_ID
)
4516 /* Dualband boards */
4517 wlc_hw
->_nbands
= 2;
4519 wlc_hw
->_nbands
= 1;
4521 if ((ai_get_chip_id(wlc_hw
->sih
) == BCMA_CHIP_ID_BCM43225
))
4522 wlc_hw
->_nbands
= 1;
4524 /* BMAC_NOTE: remove init of pub values when brcms_c_attach()
4525 * unconditionally does the init of these values
4527 wlc
->vendorid
= wlc_hw
->vendorid
;
4528 wlc
->deviceid
= wlc_hw
->deviceid
;
4529 wlc
->pub
->sih
= wlc_hw
->sih
;
4530 wlc
->pub
->corerev
= wlc_hw
->corerev
;
4531 wlc
->pub
->sromrev
= wlc_hw
->sromrev
;
4532 wlc
->pub
->boardrev
= wlc_hw
->boardrev
;
4533 wlc
->pub
->boardflags
= wlc_hw
->boardflags
;
4534 wlc
->pub
->boardflags2
= wlc_hw
->boardflags2
;
4535 wlc
->pub
->_nbands
= wlc_hw
->_nbands
;
4537 wlc_hw
->physhim
= wlc_phy_shim_attach(wlc_hw
, wlc
->wl
, wlc
);
4539 if (wlc_hw
->physhim
== NULL
) {
4540 wiphy_err(wiphy
, "wl%d: brcms_b_attach: wlc_phy_shim_attach "
4546 /* pass all the parameters to wlc_phy_shared_attach in one struct */
4547 sha_params
.sih
= wlc_hw
->sih
;
4548 sha_params
.physhim
= wlc_hw
->physhim
;
4549 sha_params
.unit
= unit
;
4550 sha_params
.corerev
= wlc_hw
->corerev
;
4551 sha_params
.vid
= wlc_hw
->vendorid
;
4552 sha_params
.did
= wlc_hw
->deviceid
;
4553 sha_params
.chip
= ai_get_chip_id(wlc_hw
->sih
);
4554 sha_params
.chiprev
= ai_get_chiprev(wlc_hw
->sih
);
4555 sha_params
.chippkg
= ai_get_chippkg(wlc_hw
->sih
);
4556 sha_params
.sromrev
= wlc_hw
->sromrev
;
4557 sha_params
.boardtype
= ai_get_boardtype(wlc_hw
->sih
);
4558 sha_params
.boardrev
= wlc_hw
->boardrev
;
4559 sha_params
.boardflags
= wlc_hw
->boardflags
;
4560 sha_params
.boardflags2
= wlc_hw
->boardflags2
;
4562 /* alloc and save pointer to shared phy state area */
4563 wlc_hw
->phy_sh
= wlc_phy_shared_attach(&sha_params
);
4564 if (!wlc_hw
->phy_sh
) {
4569 /* initialize software state for each core and band */
4570 for (j
= 0; j
< wlc_hw
->_nbands
; j
++) {
4572 * band0 is always 2.4Ghz
4573 * band1, if present, is 5Ghz
4576 brcms_c_setxband(wlc_hw
, j
);
4578 wlc_hw
->band
->bandunit
= j
;
4579 wlc_hw
->band
->bandtype
= j
? BRCM_BAND_5G
: BRCM_BAND_2G
;
4580 wlc
->band
->bandunit
= j
;
4581 wlc
->band
->bandtype
= j
? BRCM_BAND_5G
: BRCM_BAND_2G
;
4582 wlc
->core
->coreidx
= core
->core_index
;
4584 wlc_hw
->machwcap
= bcma_read32(core
, D11REGOFFS(machwcap
));
4585 wlc_hw
->machwcap_backup
= wlc_hw
->machwcap
;
4587 /* init tx fifo size */
4588 WARN_ON(wlc_hw
->corerev
< XMTFIFOTBL_STARTREV
||
4589 (wlc_hw
->corerev
- XMTFIFOTBL_STARTREV
) >
4590 ARRAY_SIZE(xmtfifo_sz
));
4591 wlc_hw
->xmtfifo_sz
=
4592 xmtfifo_sz
[(wlc_hw
->corerev
- XMTFIFOTBL_STARTREV
)];
4593 WARN_ON(!wlc_hw
->xmtfifo_sz
[0]);
4595 /* Get a phy for this band */
4597 wlc_phy_attach(wlc_hw
->phy_sh
, core
,
4598 wlc_hw
->band
->bandtype
,
4600 if (wlc_hw
->band
->pi
== NULL
) {
4601 wiphy_err(wiphy
, "wl%d: brcms_b_attach: wlc_phy_"
4602 "attach failed\n", unit
);
4607 wlc_phy_machwcap_set(wlc_hw
->band
->pi
, wlc_hw
->machwcap
);
4609 wlc_phy_get_phyversion(wlc_hw
->band
->pi
, &wlc_hw
->band
->phytype
,
4610 &wlc_hw
->band
->phyrev
,
4611 &wlc_hw
->band
->radioid
,
4612 &wlc_hw
->band
->radiorev
);
4613 wlc_hw
->band
->abgphy_encore
=
4614 wlc_phy_get_encore(wlc_hw
->band
->pi
);
4615 wlc
->band
->abgphy_encore
= wlc_phy_get_encore(wlc_hw
->band
->pi
);
4616 wlc_hw
->band
->core_flags
=
4617 wlc_phy_get_coreflags(wlc_hw
->band
->pi
);
4619 /* verify good phy_type & supported phy revision */
4620 if (BRCMS_ISNPHY(wlc_hw
->band
)) {
4621 if (NCONF_HAS(wlc_hw
->band
->phyrev
))
4625 } else if (BRCMS_ISLCNPHY(wlc_hw
->band
)) {
4626 if (LCNCONF_HAS(wlc_hw
->band
->phyrev
))
4632 wiphy_err(wiphy
, "wl%d: brcms_b_attach: unsupported "
4633 "phy type/rev (%d/%d)\n", unit
,
4634 wlc_hw
->band
->phytype
, wlc_hw
->band
->phyrev
);
4641 * BMAC_NOTE: wlc->band->pi should not be set below and should
4642 * be done in the high level attach. However we can not make
4643 * that change until all low level access is changed to
4644 * wlc_hw->band->pi. Instead do the wlc->band->pi init below,
4645 * keeping wlc_hw->band->pi as well for incremental update of
4646 * low level fns, and cut over low only init when all fns
4649 wlc
->band
->pi
= wlc_hw
->band
->pi
;
4650 wlc
->band
->phytype
= wlc_hw
->band
->phytype
;
4651 wlc
->band
->phyrev
= wlc_hw
->band
->phyrev
;
4652 wlc
->band
->radioid
= wlc_hw
->band
->radioid
;
4653 wlc
->band
->radiorev
= wlc_hw
->band
->radiorev
;
4654 brcms_dbg_info(core
, "wl%d: phy %u/%u radio %x/%u\n", unit
,
4655 wlc
->band
->phytype
, wlc
->band
->phyrev
,
4656 wlc
->band
->radioid
, wlc
->band
->radiorev
);
4657 /* default contention windows size limits */
4658 wlc_hw
->band
->CWmin
= APHY_CWMIN
;
4659 wlc_hw
->band
->CWmax
= PHY_CWMAX
;
4661 if (!brcms_b_attach_dmapio(wlc
, j
, wme
)) {
4667 /* disable core to match driver "down" state */
4668 brcms_c_coredisable(wlc_hw
);
4670 /* Match driver "down" state */
4671 bcma_host_pci_down(wlc_hw
->d11core
->bus
);
4673 /* turn off pll and xtal to match driver "down" state */
4674 brcms_b_xtal(wlc_hw
, OFF
);
4676 /* *******************************************************************
4677 * The hardware is in the DOWN state at this point. D11 core
4678 * or cores are in reset with clocks off, and the board PLLs
4679 * are off if possible.
4681 * Beyond this point, wlc->sbclk == false and chip registers
4682 * should not be touched.
4683 *********************************************************************
4686 /* init etheraddr state variables */
4687 brcms_c_get_macaddr(wlc_hw
, wlc_hw
->etheraddr
);
4689 if (is_broadcast_ether_addr(wlc_hw
->etheraddr
) ||
4690 is_zero_ether_addr(wlc_hw
->etheraddr
)) {
4691 wiphy_err(wiphy
, "wl%d: brcms_b_attach: bad macaddr\n",
4697 brcms_dbg_info(wlc_hw
->d11core
, "deviceid 0x%x nbands %d board 0x%x\n",
4698 wlc_hw
->deviceid
, wlc_hw
->_nbands
,
4699 ai_get_boardtype(wlc_hw
->sih
));
4704 wiphy_err(wiphy
, "wl%d: brcms_b_attach: failed with err %d\n", unit
,
4709 static bool brcms_c_attach_stf_ant_init(struct brcms_c_info
*wlc
)
4714 struct ssb_sprom
*sprom
= &wlc
->hw
->d11core
->bus
->sprom
;
4716 unit
= wlc
->pub
->unit
;
4717 bandtype
= wlc
->band
->bandtype
;
4719 /* get antennas available */
4720 if (bandtype
== BRCM_BAND_5G
)
4721 aa
= sprom
->ant_available_a
;
4723 aa
= sprom
->ant_available_bg
;
4725 if ((aa
< 1) || (aa
> 15)) {
4726 wiphy_err(wlc
->wiphy
, "wl%d: %s: Invalid antennas available in"
4727 " srom (0x%x), using 3\n", unit
, __func__
, aa
);
4731 /* reset the defaults if we have a single antenna */
4733 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_0
;
4734 wlc
->stf
->txant
= ANT_TX_FORCE_0
;
4735 } else if (aa
== 2) {
4736 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_1
;
4737 wlc
->stf
->txant
= ANT_TX_FORCE_1
;
4741 /* Compute Antenna Gain */
4742 if (bandtype
== BRCM_BAND_5G
)
4743 wlc
->band
->antgain
= sprom
->antenna_gain
.a1
;
4745 wlc
->band
->antgain
= sprom
->antenna_gain
.a0
;
4750 static void brcms_c_bss_default_init(struct brcms_c_info
*wlc
)
4753 struct brcms_band
*band
;
4754 struct brcms_bss_info
*bi
= wlc
->default_bss
;
4756 /* init default and target BSS with some sane initial values */
4757 memset(bi
, 0, sizeof(*bi
));
4758 bi
->beacon_period
= BEACON_INTERVAL_DEFAULT
;
4760 /* fill the default channel as the first valid channel
4761 * starting from the 2G channels
4763 chanspec
= ch20mhz_chspec(1);
4764 wlc
->home_chanspec
= bi
->chanspec
= chanspec
;
4766 /* find the band of our default channel */
4768 if (wlc
->pub
->_nbands
> 1 &&
4769 band
->bandunit
!= chspec_bandunit(chanspec
))
4770 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
4772 /* init bss rates to the band specific default rate set */
4773 brcms_c_rateset_default(&bi
->rateset
, NULL
, band
->phytype
,
4774 band
->bandtype
, false, BRCMS_RATE_MASK_FULL
,
4775 (bool) (wlc
->pub
->_n_enab
& SUPPORT_11N
),
4776 brcms_chspec_bw(chanspec
), wlc
->stf
->txstreams
);
4778 if (wlc
->pub
->_n_enab
& SUPPORT_11N
)
4779 bi
->flags
|= BRCMS_BSS_HT
;
4782 static void brcms_c_update_mimo_band_bwcap(struct brcms_c_info
*wlc
, u8 bwcap
)
4785 struct brcms_band
*band
;
4787 for (i
= 0; i
< wlc
->pub
->_nbands
; i
++) {
4788 band
= wlc
->bandstate
[i
];
4789 if (band
->bandtype
== BRCM_BAND_5G
) {
4790 if ((bwcap
== BRCMS_N_BW_40ALL
)
4791 || (bwcap
== BRCMS_N_BW_20IN2G_40IN5G
))
4792 band
->mimo_cap_40
= true;
4794 band
->mimo_cap_40
= false;
4796 if (bwcap
== BRCMS_N_BW_40ALL
)
4797 band
->mimo_cap_40
= true;
4799 band
->mimo_cap_40
= false;
4804 static void brcms_c_timers_deinit(struct brcms_c_info
*wlc
)
4806 /* free timer state */
4808 brcms_free_timer(wlc
->wdtimer
);
4809 wlc
->wdtimer
= NULL
;
4811 if (wlc
->radio_timer
) {
4812 brcms_free_timer(wlc
->radio_timer
);
4813 wlc
->radio_timer
= NULL
;
4817 static void brcms_c_detach_module(struct brcms_c_info
*wlc
)
4820 brcms_c_antsel_detach(wlc
->asi
);
4825 brcms_c_ampdu_detach(wlc
->ampdu
);
4829 brcms_c_stf_detach(wlc
);
4835 static void brcms_b_detach(struct brcms_c_info
*wlc
)
4838 struct brcms_hw_band
*band
;
4839 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
4841 brcms_b_detach_dmapio(wlc_hw
);
4843 band
= wlc_hw
->band
;
4844 for (i
= 0; i
< wlc_hw
->_nbands
; i
++) {
4846 /* Detach this band's phy */
4847 wlc_phy_detach(band
->pi
);
4850 band
= wlc_hw
->bandstate
[OTHERBANDUNIT(wlc
)];
4853 /* Free shared phy state */
4854 kfree(wlc_hw
->phy_sh
);
4856 wlc_phy_shim_detach(wlc_hw
->physhim
);
4859 ai_detach(wlc_hw
->sih
);
4865 * Return a count of the number of driver callbacks still pending.
4867 * General policy is that brcms_c_detach can only dealloc/free software states.
4868 * It can NOT touch hardware registers since the d11core may be in reset and
4869 * clock may not be available.
4870 * One exception is sb register access, which is possible if crystal is turned
4871 * on after "down" state, driver should avoid software timer with the exception
4874 uint
brcms_c_detach(struct brcms_c_info
*wlc
)
4881 brcms_b_detach(wlc
);
4883 /* delete software timers */
4885 if (!brcms_c_radio_monitor_stop(wlc
))
4888 brcms_c_channel_mgr_detach(wlc
->cmi
);
4890 brcms_c_timers_deinit(wlc
);
4892 brcms_c_detach_module(wlc
);
4894 brcms_c_detach_mfree(wlc
);
4898 /* update state that depends on the current value of "ap" */
4899 static void brcms_c_ap_upd(struct brcms_c_info
*wlc
)
4901 /* STA-BSS; short capable */
4902 wlc
->PLCPHdr_override
= BRCMS_PLCP_SHORT
;
4905 /* Initialize just the hardware when coming out of POR or S3/S5 system states */
4906 static void brcms_b_hw_up(struct brcms_hardware
*wlc_hw
)
4908 if (wlc_hw
->wlc
->pub
->hw_up
)
4911 brcms_dbg_info(wlc_hw
->d11core
, "wl%d\n", wlc_hw
->unit
);
4914 * Enable pll and xtal, initialize the power control registers,
4915 * and force fastclock for the remainder of brcms_c_up().
4917 brcms_b_xtal(wlc_hw
, ON
);
4918 ai_clkctl_init(wlc_hw
->sih
);
4919 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_FAST
);
4922 * TODO: test suspend/resume
4924 * AI chip doesn't restore bar0win2 on
4925 * hibernation/resume, need sw fixup
4929 * Inform phy that a POR reset has occurred so
4930 * it does a complete phy init
4932 wlc_phy_por_inform(wlc_hw
->band
->pi
);
4934 wlc_hw
->ucode_loaded
= false;
4935 wlc_hw
->wlc
->pub
->hw_up
= true;
4937 if ((wlc_hw
->boardflags
& BFL_FEM
)
4938 && (ai_get_chip_id(wlc_hw
->sih
) == BCMA_CHIP_ID_BCM4313
)) {
4940 (wlc_hw
->boardrev
>= 0x1250
4941 && (wlc_hw
->boardflags
& BFL_FEM_BT
)))
4942 ai_epa_4313war(wlc_hw
->sih
);
4946 static int brcms_b_up_prep(struct brcms_hardware
*wlc_hw
)
4948 brcms_dbg_info(wlc_hw
->d11core
, "wl%d\n", wlc_hw
->unit
);
4951 * Enable pll and xtal, initialize the power control registers,
4952 * and force fastclock for the remainder of brcms_c_up().
4954 brcms_b_xtal(wlc_hw
, ON
);
4955 ai_clkctl_init(wlc_hw
->sih
);
4956 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_FAST
);
4959 * Configure pci/pcmcia here instead of in brcms_c_attach()
4960 * to allow mfg hotswap: down, hotswap (chip power cycle), up.
4962 bcma_host_pci_irq_ctl(wlc_hw
->d11core
->bus
, wlc_hw
->d11core
,
4966 * Need to read the hwradio status here to cover the case where the
4967 * system is loaded with the hw radio disabled. We do not want to
4968 * bring the driver up in this case.
4970 if (brcms_b_radio_read_hwdisabled(wlc_hw
)) {
4971 /* put SB PCI in down state again */
4972 bcma_host_pci_down(wlc_hw
->d11core
->bus
);
4973 brcms_b_xtal(wlc_hw
, OFF
);
4977 bcma_host_pci_up(wlc_hw
->d11core
->bus
);
4979 /* reset the d11 core */
4980 brcms_b_corereset(wlc_hw
, BRCMS_USE_COREFLAGS
);
4985 static int brcms_b_up_finish(struct brcms_hardware
*wlc_hw
)
4988 wlc_phy_hw_state_upd(wlc_hw
->band
->pi
, true);
4990 /* FULLY enable dynamic power control and d11 core interrupt */
4991 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_DYNAMIC
);
4992 brcms_intrson(wlc_hw
->wlc
->wl
);
4997 * Write WME tunable parameters for retransmit/max rate
4998 * from wlc struct to ucode
5000 static void brcms_c_wme_retries_write(struct brcms_c_info
*wlc
)
5004 /* Need clock to do this */
5008 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
5009 brcms_b_write_shm(wlc
->hw
, M_AC_TXLMT_ADDR(ac
),
5010 wlc
->wme_retries
[ac
]);
5013 /* make interface operational */
5014 int brcms_c_up(struct brcms_c_info
*wlc
)
5016 struct ieee80211_channel
*ch
;
5018 brcms_dbg_info(wlc
->hw
->d11core
, "wl%d\n", wlc
->pub
->unit
);
5020 /* HW is turned off so don't try to access it */
5021 if (wlc
->pub
->hw_off
|| brcms_deviceremoved(wlc
))
5024 if (!wlc
->pub
->hw_up
) {
5025 brcms_b_hw_up(wlc
->hw
);
5026 wlc
->pub
->hw_up
= true;
5029 if ((wlc
->pub
->boardflags
& BFL_FEM
)
5030 && (ai_get_chip_id(wlc
->hw
->sih
) == BCMA_CHIP_ID_BCM4313
)) {
5031 if (wlc
->pub
->boardrev
>= 0x1250
5032 && (wlc
->pub
->boardflags
& BFL_FEM_BT
))
5033 brcms_b_mhf(wlc
->hw
, MHF5
, MHF5_4313_GPIOCTRL
,
5034 MHF5_4313_GPIOCTRL
, BRCM_BAND_ALL
);
5036 brcms_b_mhf(wlc
->hw
, MHF4
, MHF4_EXTPA_ENABLE
,
5037 MHF4_EXTPA_ENABLE
, BRCM_BAND_ALL
);
5041 * Need to read the hwradio status here to cover the case where the
5042 * system is loaded with the hw radio disabled. We do not want to bring
5043 * the driver up in this case. If radio is disabled, abort up, lower
5044 * power, start radio timer and return 0(for NDIS) don't call
5045 * radio_update to avoid looping brcms_c_up.
5047 * brcms_b_up_prep() returns either 0 or -BCME_RADIOOFF only
5049 if (!wlc
->pub
->radio_disabled
) {
5050 int status
= brcms_b_up_prep(wlc
->hw
);
5051 if (status
== -ENOMEDIUM
) {
5053 (wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
)) {
5054 struct brcms_bss_cfg
*bsscfg
= wlc
->bsscfg
;
5055 mboolset(wlc
->pub
->radio_disabled
,
5056 WL_RADIO_HW_DISABLE
);
5057 if (bsscfg
->type
== BRCMS_TYPE_STATION
||
5058 bsscfg
->type
== BRCMS_TYPE_ADHOC
)
5059 brcms_err(wlc
->hw
->d11core
,
5060 "wl%d: up: rfdisable -> "
5061 "bsscfg_disable()\n",
5067 if (wlc
->pub
->radio_disabled
) {
5068 brcms_c_radio_monitor_start(wlc
);
5072 /* brcms_b_up_prep has done brcms_c_corereset(). so clk is on, set it */
5075 brcms_c_radio_monitor_stop(wlc
);
5077 /* Set EDCF hostflags */
5078 brcms_b_mhf(wlc
->hw
, MHF1
, MHF1_EDCF
, MHF1_EDCF
, BRCM_BAND_ALL
);
5080 brcms_init(wlc
->wl
);
5081 wlc
->pub
->up
= true;
5083 if (wlc
->bandinit_pending
) {
5084 ch
= wlc
->pub
->ieee_hw
->conf
.chandef
.chan
;
5085 brcms_c_suspend_mac_and_wait(wlc
);
5086 brcms_c_set_chanspec(wlc
, ch20mhz_chspec(ch
->hw_value
));
5087 wlc
->bandinit_pending
= false;
5088 brcms_c_enable_mac(wlc
);
5091 brcms_b_up_finish(wlc
->hw
);
5093 /* Program the TX wme params with the current settings */
5094 brcms_c_wme_retries_write(wlc
);
5096 /* start one second watchdog timer */
5097 brcms_add_timer(wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
, true);
5098 wlc
->WDarmed
= true;
5100 /* ensure antenna config is up to date */
5101 brcms_c_stf_phy_txant_upd(wlc
);
5102 /* ensure LDPC config is in sync */
5103 brcms_c_ht_update_ldpc(wlc
, wlc
->stf
->ldpc
);
5108 static uint
brcms_c_down_del_timer(struct brcms_c_info
*wlc
)
5115 static int brcms_b_bmac_down_prep(struct brcms_hardware
*wlc_hw
)
5123 dev_gone
= brcms_deviceremoved(wlc_hw
->wlc
);
5125 /* disable interrupts */
5127 wlc_hw
->wlc
->macintmask
= 0;
5129 /* now disable interrupts */
5130 brcms_intrsoff(wlc_hw
->wlc
->wl
);
5132 /* ensure we're running on the pll clock again */
5133 brcms_b_clkctl_clk(wlc_hw
, BCMA_CLKMODE_FAST
);
5135 /* down phy at the last of this stage */
5136 callbacks
+= wlc_phy_down(wlc_hw
->band
->pi
);
5141 static int brcms_b_down_finish(struct brcms_hardware
*wlc_hw
)
5150 wlc_phy_hw_state_upd(wlc_hw
->band
->pi
, false);
5152 dev_gone
= brcms_deviceremoved(wlc_hw
->wlc
);
5155 wlc_hw
->sbclk
= false;
5156 wlc_hw
->clk
= false;
5157 wlc_phy_hw_clk_state_upd(wlc_hw
->band
->pi
, false);
5159 /* reclaim any posted packets */
5160 brcms_c_flushqueues(wlc_hw
->wlc
);
5163 /* Reset and disable the core */
5164 if (bcma_core_is_enabled(wlc_hw
->d11core
)) {
5165 if (bcma_read32(wlc_hw
->d11core
,
5166 D11REGOFFS(maccontrol
)) & MCTL_EN_MAC
)
5167 brcms_c_suspend_mac_and_wait(wlc_hw
->wlc
);
5168 callbacks
+= brcms_reset(wlc_hw
->wlc
->wl
);
5169 brcms_c_coredisable(wlc_hw
);
5172 /* turn off primary xtal and pll */
5173 if (!wlc_hw
->noreset
) {
5174 bcma_host_pci_down(wlc_hw
->d11core
->bus
);
5175 brcms_b_xtal(wlc_hw
, OFF
);
5183 * Mark the interface nonoperational, stop the software mechanisms,
5184 * disable the hardware, free any transient buffer state.
5185 * Return a count of the number of driver callbacks still pending.
5187 uint
brcms_c_down(struct brcms_c_info
*wlc
)
5192 bool dev_gone
= false;
5194 brcms_dbg_info(wlc
->hw
->d11core
, "wl%d\n", wlc
->pub
->unit
);
5196 /* check if we are already in the going down path */
5197 if (wlc
->going_down
) {
5198 brcms_err(wlc
->hw
->d11core
,
5199 "wl%d: %s: Driver going down so return\n",
5200 wlc
->pub
->unit
, __func__
);
5206 wlc
->going_down
= true;
5208 callbacks
+= brcms_b_bmac_down_prep(wlc
->hw
);
5210 dev_gone
= brcms_deviceremoved(wlc
);
5212 /* Call any registered down handlers */
5213 for (i
= 0; i
< BRCMS_MAXMODULES
; i
++) {
5214 if (wlc
->modulecb
[i
].down_fn
)
5216 wlc
->modulecb
[i
].down_fn(wlc
->modulecb
[i
].hdl
);
5219 /* cancel the watchdog timer */
5221 if (!brcms_del_timer(wlc
->wdtimer
))
5223 wlc
->WDarmed
= false;
5225 /* cancel all other timers */
5226 callbacks
+= brcms_c_down_del_timer(wlc
);
5228 wlc
->pub
->up
= false;
5230 wlc_phy_mute_upd(wlc
->band
->pi
, false, PHY_MUTE_ALL
);
5232 callbacks
+= brcms_b_down_finish(wlc
->hw
);
5234 /* brcms_b_down_finish has done brcms_c_coredisable(). so clk is off */
5237 wlc
->going_down
= false;
5241 /* Set the current gmode configuration */
5242 int brcms_c_set_gmode(struct brcms_c_info
*wlc
, u8 gmode
, bool config
)
5246 struct brcms_c_rateset rs
;
5247 /* Default to 54g Auto */
5248 /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
5249 s8 shortslot
= BRCMS_SHORTSLOT_AUTO
;
5250 bool shortslot_restrict
= false; /* Restrict association to stations
5251 * that support shortslot
5253 bool ofdm_basic
= false; /* Make 6, 12, and 24 basic rates */
5254 /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
5255 int preamble
= BRCMS_PLCP_LONG
;
5256 bool preamble_restrict
= false; /* Restrict association to stations
5257 * that support short preambles
5259 struct brcms_band
*band
;
5261 /* if N-support is enabled, allow Gmode set as long as requested
5262 * Gmode is not GMODE_LEGACY_B
5264 if ((wlc
->pub
->_n_enab
& SUPPORT_11N
) && gmode
== GMODE_LEGACY_B
)
5267 /* verify that we are dealing with 2G band and grab the band pointer */
5268 if (wlc
->band
->bandtype
== BRCM_BAND_2G
)
5270 else if ((wlc
->pub
->_nbands
> 1) &&
5271 (wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
== BRCM_BAND_2G
))
5272 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
5276 /* update configuration value */
5278 brcms_c_protection_upd(wlc
, BRCMS_PROT_G_USER
, gmode
);
5280 /* Clear rateset override */
5281 memset(&rs
, 0, sizeof(rs
));
5284 case GMODE_LEGACY_B
:
5285 shortslot
= BRCMS_SHORTSLOT_OFF
;
5286 brcms_c_rateset_copy(&gphy_legacy_rates
, &rs
);
5294 /* Accept defaults */
5299 preamble
= BRCMS_PLCP_SHORT
;
5300 preamble_restrict
= true;
5303 case GMODE_PERFORMANCE
:
5304 shortslot
= BRCMS_SHORTSLOT_ON
;
5305 shortslot_restrict
= true;
5307 preamble
= BRCMS_PLCP_SHORT
;
5308 preamble_restrict
= true;
5313 brcms_err(wlc
->hw
->d11core
, "wl%d: %s: invalid gmode %d\n",
5314 wlc
->pub
->unit
, __func__
, gmode
);
5318 band
->gmode
= gmode
;
5320 wlc
->shortslot_override
= shortslot
;
5322 /* Use the default 11g rateset */
5324 brcms_c_rateset_copy(&cck_ofdm_rates
, &rs
);
5327 for (i
= 0; i
< rs
.count
; i
++) {
5328 if (rs
.rates
[i
] == BRCM_RATE_6M
5329 || rs
.rates
[i
] == BRCM_RATE_12M
5330 || rs
.rates
[i
] == BRCM_RATE_24M
)
5331 rs
.rates
[i
] |= BRCMS_RATE_FLAG
;
5335 /* Set default bss rateset */
5336 wlc
->default_bss
->rateset
.count
= rs
.count
;
5337 memcpy(wlc
->default_bss
->rateset
.rates
, rs
.rates
,
5338 sizeof(wlc
->default_bss
->rateset
.rates
));
5343 int brcms_c_set_nmode(struct brcms_c_info
*wlc
)
5348 if (wlc
->stf
->txstreams
== WL_11N_3x3
)
5353 /* force GMODE_AUTO if NMODE is ON */
5354 brcms_c_set_gmode(wlc
, GMODE_AUTO
, true);
5355 if (nmode
== WL_11N_3x3
)
5356 wlc
->pub
->_n_enab
= SUPPORT_HT
;
5358 wlc
->pub
->_n_enab
= SUPPORT_11N
;
5359 wlc
->default_bss
->flags
|= BRCMS_BSS_HT
;
5360 /* add the mcs rates to the default and hw ratesets */
5361 brcms_c_rateset_mcs_build(&wlc
->default_bss
->rateset
,
5362 wlc
->stf
->txstreams
);
5363 for (i
= 0; i
< wlc
->pub
->_nbands
; i
++)
5364 memcpy(wlc
->bandstate
[i
]->hw_rateset
.mcs
,
5365 wlc
->default_bss
->rateset
.mcs
, MCSSET_LEN
);
5371 brcms_c_set_internal_rateset(struct brcms_c_info
*wlc
,
5372 struct brcms_c_rateset
*rs_arg
)
5374 struct brcms_c_rateset rs
, new;
5377 memcpy(&rs
, rs_arg
, sizeof(struct brcms_c_rateset
));
5379 /* check for bad count value */
5380 if ((rs
.count
== 0) || (rs
.count
> BRCMS_NUMRATES
))
5383 /* try the current band */
5384 bandunit
= wlc
->band
->bandunit
;
5385 memcpy(&new, &rs
, sizeof(struct brcms_c_rateset
));
5386 if (brcms_c_rate_hwrs_filter_sort_validate
5387 (&new, &wlc
->bandstate
[bandunit
]->hw_rateset
, true,
5388 wlc
->stf
->txstreams
))
5391 /* try the other band */
5392 if (brcms_is_mband_unlocked(wlc
)) {
5393 bandunit
= OTHERBANDUNIT(wlc
);
5394 memcpy(&new, &rs
, sizeof(struct brcms_c_rateset
));
5395 if (brcms_c_rate_hwrs_filter_sort_validate(&new,
5397 bandstate
[bandunit
]->
5399 wlc
->stf
->txstreams
))
5406 /* apply new rateset */
5407 memcpy(&wlc
->default_bss
->rateset
, &new,
5408 sizeof(struct brcms_c_rateset
));
5409 memcpy(&wlc
->bandstate
[bandunit
]->defrateset
, &new,
5410 sizeof(struct brcms_c_rateset
));
5414 static void brcms_c_ofdm_rateset_war(struct brcms_c_info
*wlc
)
5419 if (wlc
->pub
->associated
)
5420 r
= wlc
->bsscfg
->current_bss
->rateset
.rates
[0];
5422 r
= wlc
->default_bss
->rateset
.rates
[0];
5424 wlc_phy_ofdm_rateset_war(wlc
->band
->pi
, war
);
5427 int brcms_c_set_channel(struct brcms_c_info
*wlc
, u16 channel
)
5429 u16 chspec
= ch20mhz_chspec(channel
);
5431 if (channel
< 0 || channel
> MAXCHANNEL
)
5434 if (!brcms_c_valid_chanspec_db(wlc
->cmi
, chspec
))
5438 if (!wlc
->pub
->up
&& brcms_is_mband_unlocked(wlc
)) {
5439 if (wlc
->band
->bandunit
!= chspec_bandunit(chspec
))
5440 wlc
->bandinit_pending
= true;
5442 wlc
->bandinit_pending
= false;
5445 wlc
->default_bss
->chanspec
= chspec
;
5446 /* brcms_c_BSSinit() will sanitize the rateset before
5448 if (wlc
->pub
->up
&& (wlc_phy_chanspec_get(wlc
->band
->pi
) != chspec
)) {
5449 brcms_c_set_home_chanspec(wlc
, chspec
);
5450 brcms_c_suspend_mac_and_wait(wlc
);
5451 brcms_c_set_chanspec(wlc
, chspec
);
5452 brcms_c_enable_mac(wlc
);
5457 int brcms_c_set_rate_limit(struct brcms_c_info
*wlc
, u16 srl
, u16 lrl
)
5461 if (srl
< 1 || srl
> RETRY_SHORT_MAX
||
5462 lrl
< 1 || lrl
> RETRY_SHORT_MAX
)
5468 brcms_b_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
5470 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
5471 wlc
->wme_retries
[ac
] = SFIELD(wlc
->wme_retries
[ac
],
5472 EDCF_SHORT
, wlc
->SRL
);
5473 wlc
->wme_retries
[ac
] = SFIELD(wlc
->wme_retries
[ac
],
5474 EDCF_LONG
, wlc
->LRL
);
5476 brcms_c_wme_retries_write(wlc
);
5481 void brcms_c_get_current_rateset(struct brcms_c_info
*wlc
,
5482 struct brcm_rateset
*currs
)
5484 struct brcms_c_rateset
*rs
;
5486 if (wlc
->pub
->associated
)
5487 rs
= &wlc
->bsscfg
->current_bss
->rateset
;
5489 rs
= &wlc
->default_bss
->rateset
;
5491 /* Copy only legacy rateset section */
5492 currs
->count
= rs
->count
;
5493 memcpy(&currs
->rates
, &rs
->rates
, rs
->count
);
5496 int brcms_c_set_rateset(struct brcms_c_info
*wlc
, struct brcm_rateset
*rs
)
5498 struct brcms_c_rateset internal_rs
;
5501 if (rs
->count
> BRCMS_NUMRATES
)
5504 memset(&internal_rs
, 0, sizeof(internal_rs
));
5506 /* Copy only legacy rateset section */
5507 internal_rs
.count
= rs
->count
;
5508 memcpy(&internal_rs
.rates
, &rs
->rates
, internal_rs
.count
);
5510 /* merge rateset coming in with the current mcsset */
5511 if (wlc
->pub
->_n_enab
& SUPPORT_11N
) {
5512 struct brcms_bss_info
*mcsset_bss
;
5513 if (wlc
->pub
->associated
)
5514 mcsset_bss
= wlc
->bsscfg
->current_bss
;
5516 mcsset_bss
= wlc
->default_bss
;
5517 memcpy(internal_rs
.mcs
, &mcsset_bss
->rateset
.mcs
[0],
5521 bcmerror
= brcms_c_set_internal_rateset(wlc
, &internal_rs
);
5523 brcms_c_ofdm_rateset_war(wlc
);
5528 static void brcms_c_time_lock(struct brcms_c_info
*wlc
)
5530 bcma_set32(wlc
->hw
->d11core
, D11REGOFFS(maccontrol
), MCTL_TBTTHOLD
);
5531 /* Commit the write */
5532 bcma_read32(wlc
->hw
->d11core
, D11REGOFFS(maccontrol
));
5535 static void brcms_c_time_unlock(struct brcms_c_info
*wlc
)
5537 bcma_mask32(wlc
->hw
->d11core
, D11REGOFFS(maccontrol
), ~MCTL_TBTTHOLD
);
5538 /* Commit the write */
5539 bcma_read32(wlc
->hw
->d11core
, D11REGOFFS(maccontrol
));
5542 int brcms_c_set_beacon_period(struct brcms_c_info
*wlc
, u16 period
)
5549 wlc
->default_bss
->beacon_period
= period
;
5551 bcnint_us
= period
<< 10;
5552 brcms_c_time_lock(wlc
);
5553 bcma_write32(wlc
->hw
->d11core
, D11REGOFFS(tsf_cfprep
),
5554 (bcnint_us
<< CFPREP_CBI_SHIFT
));
5555 bcma_write32(wlc
->hw
->d11core
, D11REGOFFS(tsf_cfpstart
), bcnint_us
);
5556 brcms_c_time_unlock(wlc
);
5561 u16
brcms_c_get_phy_type(struct brcms_c_info
*wlc
, int phyidx
)
5563 return wlc
->band
->phytype
;
5566 void brcms_c_set_shortslot_override(struct brcms_c_info
*wlc
, s8 sslot_override
)
5568 wlc
->shortslot_override
= sslot_override
;
5571 * shortslot is an 11g feature, so no more work if we are
5572 * currently on the 5G band
5574 if (wlc
->band
->bandtype
== BRCM_BAND_5G
)
5577 if (wlc
->pub
->up
&& wlc
->pub
->associated
) {
5578 /* let watchdog or beacon processing update shortslot */
5579 } else if (wlc
->pub
->up
) {
5580 /* unassociated shortslot is off */
5581 brcms_c_switch_shortslot(wlc
, false);
5583 /* driver is down, so just update the brcms_c_info
5585 if (wlc
->shortslot_override
== BRCMS_SHORTSLOT_AUTO
)
5586 wlc
->shortslot
= false;
5589 (wlc
->shortslot_override
==
5590 BRCMS_SHORTSLOT_ON
);
5595 * register watchdog and down handlers.
5597 int brcms_c_module_register(struct brcms_pub
*pub
,
5598 const char *name
, struct brcms_info
*hdl
,
5599 int (*d_fn
)(void *handle
))
5601 struct brcms_c_info
*wlc
= (struct brcms_c_info
*) pub
->wlc
;
5604 /* find an empty entry and just add, no duplication check! */
5605 for (i
= 0; i
< BRCMS_MAXMODULES
; i
++) {
5606 if (wlc
->modulecb
[i
].name
[0] == '\0') {
5607 strncpy(wlc
->modulecb
[i
].name
, name
,
5608 sizeof(wlc
->modulecb
[i
].name
) - 1);
5609 wlc
->modulecb
[i
].hdl
= hdl
;
5610 wlc
->modulecb
[i
].down_fn
= d_fn
;
5618 /* unregister module callbacks */
5619 int brcms_c_module_unregister(struct brcms_pub
*pub
, const char *name
,
5620 struct brcms_info
*hdl
)
5622 struct brcms_c_info
*wlc
= (struct brcms_c_info
*) pub
->wlc
;
5628 for (i
= 0; i
< BRCMS_MAXMODULES
; i
++) {
5629 if (!strcmp(wlc
->modulecb
[i
].name
, name
) &&
5630 (wlc
->modulecb
[i
].hdl
== hdl
)) {
5631 memset(&wlc
->modulecb
[i
], 0, sizeof(wlc
->modulecb
[i
]));
5636 /* table not found! */
5640 static bool brcms_c_chipmatch_pci(struct bcma_device
*core
)
5642 struct pci_dev
*pcidev
= core
->bus
->host_pci
;
5643 u16 vendor
= pcidev
->vendor
;
5644 u16 device
= pcidev
->device
;
5646 if (vendor
!= PCI_VENDOR_ID_BROADCOM
) {
5647 pr_err("unknown vendor id %04x\n", vendor
);
5651 if (device
== BCM43224_D11N_ID_VEN1
|| device
== BCM43224_CHIP_ID
)
5653 if ((device
== BCM43224_D11N_ID
) || (device
== BCM43225_D11N2G_ID
))
5655 if (device
== BCM4313_D11N2G_ID
|| device
== BCM4313_CHIP_ID
)
5657 if ((device
== BCM43236_D11N_ID
) || (device
== BCM43236_D11N2G_ID
))
5660 pr_err("unknown device id %04x\n", device
);
5664 static bool brcms_c_chipmatch_soc(struct bcma_device
*core
)
5666 struct bcma_chipinfo
*chipinfo
= &core
->bus
->chipinfo
;
5668 if (chipinfo
->id
== BCMA_CHIP_ID_BCM4716
)
5671 pr_err("unknown chip id %04x\n", chipinfo
->id
);
5675 bool brcms_c_chipmatch(struct bcma_device
*core
)
5677 switch (core
->bus
->hosttype
) {
5678 case BCMA_HOSTTYPE_PCI
:
5679 return brcms_c_chipmatch_pci(core
);
5680 case BCMA_HOSTTYPE_SOC
:
5681 return brcms_c_chipmatch_soc(core
);
5683 pr_err("unknown host type: %i\n", core
->bus
->hosttype
);
5688 u16
brcms_b_rate_shm_offset(struct brcms_hardware
*wlc_hw
, u8 rate
)
5693 /* get the phy specific rate encoding for the PLCP SIGNAL field */
5694 if (is_ofdm_rate(rate
))
5695 table_ptr
= M_RT_DIRMAP_A
;
5697 table_ptr
= M_RT_DIRMAP_B
;
5699 /* for a given rate, the LS-nibble of the PLCP SIGNAL field is
5700 * the index into the rate table.
5702 phy_rate
= rate_info
[rate
] & BRCMS_RATE_MASK
;
5703 index
= phy_rate
& 0xf;
5705 /* Find the SHM pointer to the rate table entry by looking in the
5708 return 2 * brcms_b_read_shm(wlc_hw
, table_ptr
+ (index
* 2));
5712 * bcmc_fid_generate:
5713 * Generate frame ID for a BCMC packet. The frag field is not used
5714 * for MC frames so is used as part of the sequence number.
5717 bcmc_fid_generate(struct brcms_c_info
*wlc
, struct brcms_bss_cfg
*bsscfg
,
5722 frameid
= le16_to_cpu(txh
->TxFrameID
) & ~(TXFID_SEQ_MASK
|
5726 mc_fid_counter
++) << TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5733 brcms_c_calc_ack_time(struct brcms_c_info
*wlc
, u32 rspec
,
5739 * Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that
5740 * is less than or equal to the rate of the immediately previous
5743 rspec
= brcms_basic_rate(wlc
, rspec
);
5744 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
5746 brcms_c_calc_frame_time(wlc
, rspec
, preamble_type
,
5747 (DOT11_ACK_LEN
+ FCS_LEN
));
5752 brcms_c_calc_cts_time(struct brcms_c_info
*wlc
, u32 rspec
,
5755 return brcms_c_calc_ack_time(wlc
, rspec
, preamble_type
);
5759 brcms_c_calc_ba_time(struct brcms_c_info
*wlc
, u32 rspec
,
5763 * Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that
5764 * is less than or equal to the rate of the immediately previous
5767 rspec
= brcms_basic_rate(wlc
, rspec
);
5768 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
5769 return brcms_c_calc_frame_time(wlc
, rspec
, preamble_type
,
5770 (DOT11_BA_LEN
+ DOT11_BA_BITMAP_LEN
+
5774 /* brcms_c_compute_frame_dur()
5776 * Calculate the 802.11 MAC header DUR field for MPDU
5777 * DUR for a single frame = 1 SIFS + 1 ACK
5778 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5780 * rate MPDU rate in unit of 500kbps
5781 * next_frag_len next MPDU length in bytes
5782 * preamble_type use short/GF or long/MM PLCP header
5785 brcms_c_compute_frame_dur(struct brcms_c_info
*wlc
, u32 rate
,
5786 u8 preamble_type
, uint next_frag_len
)
5790 sifs
= get_sifs(wlc
->band
);
5793 dur
+= (u16
) brcms_c_calc_ack_time(wlc
, rate
, preamble_type
);
5795 if (next_frag_len
) {
5796 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5798 /* add another SIFS and the frag time */
5801 (u16
) brcms_c_calc_frame_time(wlc
, rate
, preamble_type
,
5807 /* The opposite of brcms_c_calc_frame_time */
5809 brcms_c_calc_frame_len(struct brcms_c_info
*wlc
, u32 ratespec
,
5810 u8 preamble_type
, uint dur
)
5812 uint nsyms
, mac_len
, Ndps
, kNdps
;
5813 uint rate
= rspec2rate(ratespec
);
5815 if (is_mcs_rate(ratespec
)) {
5816 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
5817 int tot_streams
= mcs_2_txstreams(mcs
) + rspec_stc(ratespec
);
5818 dur
-= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
5819 /* payload calculation matches that of regular ofdm */
5820 if (wlc
->band
->bandtype
== BRCM_BAND_2G
)
5821 dur
-= DOT11_OFDM_SIGNAL_EXTENSION
;
5822 /* kNdbps = kbps * 4 */
5823 kNdps
= mcs_2_rate(mcs
, rspec_is40mhz(ratespec
),
5824 rspec_issgi(ratespec
)) * 4;
5825 nsyms
= dur
/ APHY_SYMBOL_TIME
;
5828 ((APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
) * 1000)) / 8000;
5829 } else if (is_ofdm_rate(ratespec
)) {
5830 dur
-= APHY_PREAMBLE_TIME
;
5831 dur
-= APHY_SIGNAL_TIME
;
5832 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
5834 nsyms
= dur
/ APHY_SYMBOL_TIME
;
5837 (APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
)) / 8;
5839 if (preamble_type
& BRCMS_SHORT_PREAMBLE
)
5840 dur
-= BPHY_PLCP_SHORT_TIME
;
5842 dur
-= BPHY_PLCP_TIME
;
5843 mac_len
= dur
* rate
;
5844 /* divide out factor of 2 in rate (1/2 mbps) */
5845 mac_len
= mac_len
/ 8 / 2;
5851 * Return true if the specified rate is supported by the specified band.
5852 * BRCM_BAND_AUTO indicates the current band.
5854 static bool brcms_c_valid_rate(struct brcms_c_info
*wlc
, u32 rspec
, int band
,
5857 struct brcms_c_rateset
*hw_rateset
;
5860 if ((band
== BRCM_BAND_AUTO
) || (band
== wlc
->band
->bandtype
))
5861 hw_rateset
= &wlc
->band
->hw_rateset
;
5862 else if (wlc
->pub
->_nbands
> 1)
5863 hw_rateset
= &wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->hw_rateset
;
5865 /* other band specified and we are a single band device */
5868 /* check if this is a mimo rate */
5869 if (is_mcs_rate(rspec
)) {
5870 if ((rspec
& RSPEC_RATE_MASK
) >= MCS_TABLE_SIZE
)
5873 return isset(hw_rateset
->mcs
, (rspec
& RSPEC_RATE_MASK
));
5876 for (i
= 0; i
< hw_rateset
->count
; i
++)
5877 if (hw_rateset
->rates
[i
] == rspec2rate(rspec
))
5881 brcms_err(wlc
->hw
->d11core
, "wl%d: valid_rate: rate spec 0x%x "
5882 "not in hw_rateset\n", wlc
->pub
->unit
, rspec
);
5888 mac80211_wlc_set_nrate(struct brcms_c_info
*wlc
, struct brcms_band
*cur_band
,
5891 struct bcma_device
*core
= wlc
->hw
->d11core
;
5892 u8 stf
= (int_val
& NRATE_STF_MASK
) >> NRATE_STF_SHIFT
;
5893 u8 rate
= int_val
& NRATE_RATE_MASK
;
5895 bool ismcs
= ((int_val
& NRATE_MCS_INUSE
) == NRATE_MCS_INUSE
);
5896 bool issgi
= ((int_val
& NRATE_SGI_MASK
) >> NRATE_SGI_SHIFT
);
5897 bool override_mcs_only
= ((int_val
& NRATE_OVERRIDE_MCS_ONLY
)
5898 == NRATE_OVERRIDE_MCS_ONLY
);
5904 /* validate the combination of rate/mcs/stf is allowed */
5905 if ((wlc
->pub
->_n_enab
& SUPPORT_11N
) && ismcs
) {
5906 /* mcs only allowed when nmode */
5907 if (stf
> PHY_TXC1_MODE_SDM
) {
5908 brcms_err(core
, "wl%d: %s: Invalid stf\n",
5909 wlc
->pub
->unit
, __func__
);
5914 /* mcs 32 is a special case, DUP mode 40 only */
5916 if (!CHSPEC_IS40(wlc
->home_chanspec
) ||
5917 ((stf
!= PHY_TXC1_MODE_SISO
)
5918 && (stf
!= PHY_TXC1_MODE_CDD
))) {
5919 brcms_err(core
, "wl%d: %s: Invalid mcs 32\n",
5920 wlc
->pub
->unit
, __func__
);
5924 /* mcs > 7 must use stf SDM */
5925 } else if (rate
> HIGHEST_SINGLE_STREAM_MCS
) {
5926 /* mcs > 7 must use stf SDM */
5927 if (stf
!= PHY_TXC1_MODE_SDM
) {
5928 brcms_dbg_mac80211(core
, "wl%d: enabling "
5929 "SDM mode for mcs %d\n",
5930 wlc
->pub
->unit
, rate
);
5931 stf
= PHY_TXC1_MODE_SDM
;
5935 * MCS 0-7 may use SISO, CDD, and for
5938 if ((stf
> PHY_TXC1_MODE_STBC
) ||
5939 (!BRCMS_STBC_CAP_PHY(wlc
)
5940 && (stf
== PHY_TXC1_MODE_STBC
))) {
5941 brcms_err(core
, "wl%d: %s: Invalid STBC\n",
5942 wlc
->pub
->unit
, __func__
);
5947 } else if (is_ofdm_rate(rate
)) {
5948 if ((stf
!= PHY_TXC1_MODE_CDD
) && (stf
!= PHY_TXC1_MODE_SISO
)) {
5949 brcms_err(core
, "wl%d: %s: Invalid OFDM\n",
5950 wlc
->pub
->unit
, __func__
);
5954 } else if (is_cck_rate(rate
)) {
5955 if ((cur_band
->bandtype
!= BRCM_BAND_2G
)
5956 || (stf
!= PHY_TXC1_MODE_SISO
)) {
5957 brcms_err(core
, "wl%d: %s: Invalid CCK\n",
5958 wlc
->pub
->unit
, __func__
);
5963 brcms_err(core
, "wl%d: %s: Unknown rate type\n",
5964 wlc
->pub
->unit
, __func__
);
5968 /* make sure multiple antennae are available for non-siso rates */
5969 if ((stf
!= PHY_TXC1_MODE_SISO
) && (wlc
->stf
->txstreams
== 1)) {
5970 brcms_err(core
, "wl%d: %s: SISO antenna but !SISO "
5971 "request\n", wlc
->pub
->unit
, __func__
);
5978 rspec
|= RSPEC_MIMORATE
;
5979 /* For STBC populate the STC field of the ratespec */
5980 if (stf
== PHY_TXC1_MODE_STBC
) {
5982 stc
= 1; /* Nss for single stream is always 1 */
5983 rspec
|= (stc
<< RSPEC_STC_SHIFT
);
5987 rspec
|= (stf
<< RSPEC_STF_SHIFT
);
5989 if (override_mcs_only
)
5990 rspec
|= RSPEC_OVERRIDE_MCS_ONLY
;
5993 rspec
|= RSPEC_SHORT_GI
;
5996 && !brcms_c_valid_rate(wlc
, rspec
, cur_band
->bandtype
, true))
6005 * Compute PLCP, but only requires actual rate and length of pkt.
6006 * Rate is given in the driver standard multiple of 500 kbps.
6007 * le is set for 11 Mbps rate if necessary.
6008 * Broken out for PRQ.
6011 static void brcms_c_cck_plcp_set(struct brcms_c_info
*wlc
, int rate_500
,
6012 uint length
, u8
*plcp
)
6025 usec
= (length
<< 4) / 11;
6026 if ((length
<< 4) - (usec
* 11) > 0)
6030 usec
= (length
<< 3) / 11;
6031 if ((length
<< 3) - (usec
* 11) > 0) {
6033 if ((usec
* 11) - (length
<< 3) >= 8)
6034 le
= D11B_PLCP_SIGNAL_LE
;
6039 brcms_err(wlc
->hw
->d11core
,
6040 "brcms_c_cck_plcp_set: unsupported rate %d\n",
6042 rate_500
= BRCM_RATE_1M
;
6046 /* PLCP signal byte */
6047 plcp
[0] = rate_500
* 5; /* r (500kbps) * 5 == r (100kbps) */
6048 /* PLCP service byte */
6049 plcp
[1] = (u8
) (le
| D11B_PLCP_SIGNAL_LOCKED
);
6050 /* PLCP length u16, little endian */
6051 plcp
[2] = usec
& 0xff;
6052 plcp
[3] = (usec
>> 8) & 0xff;
6058 /* Rate: 802.11 rate code, length: PSDU length in octets */
6059 static void brcms_c_compute_mimo_plcp(u32 rspec
, uint length
, u8
*plcp
)
6061 u8 mcs
= (u8
) (rspec
& RSPEC_RATE_MASK
);
6063 if (rspec_is40mhz(rspec
) || (mcs
== 32))
6064 plcp
[0] |= MIMO_PLCP_40MHZ
;
6065 BRCMS_SET_MIMO_PLCP_LEN(plcp
, length
);
6066 plcp
[3] = rspec_mimoplcp3(rspec
); /* rspec already holds this byte */
6067 plcp
[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
6068 plcp
[4] = 0; /* number of extension spatial streams bit 0 & 1 */
6072 /* Rate: 802.11 rate code, length: PSDU length in octets */
6074 brcms_c_compute_ofdm_plcp(u32 rspec
, u32 length
, u8
*plcp
)
6078 int rate
= rspec2rate(rspec
);
6081 * encode rate per 802.11a-1999 sec 17.3.4.1, with lsb
6084 rate_signal
= rate_info
[rate
] & BRCMS_RATE_MASK
;
6085 memset(plcp
, 0, D11_PHY_HDR_LEN
);
6086 D11A_PHY_HDR_SRATE((struct ofdm_phy_hdr
*) plcp
, rate_signal
);
6088 tmp
= (length
& 0xfff) << 5;
6089 plcp
[2] |= (tmp
>> 16) & 0xff;
6090 plcp
[1] |= (tmp
>> 8) & 0xff;
6091 plcp
[0] |= tmp
& 0xff;
6094 /* Rate: 802.11 rate code, length: PSDU length in octets */
6095 static void brcms_c_compute_cck_plcp(struct brcms_c_info
*wlc
, u32 rspec
,
6096 uint length
, u8
*plcp
)
6098 int rate
= rspec2rate(rspec
);
6100 brcms_c_cck_plcp_set(wlc
, rate
, length
, plcp
);
6104 brcms_c_compute_plcp(struct brcms_c_info
*wlc
, u32 rspec
,
6105 uint length
, u8
*plcp
)
6107 if (is_mcs_rate(rspec
))
6108 brcms_c_compute_mimo_plcp(rspec
, length
, plcp
);
6109 else if (is_ofdm_rate(rspec
))
6110 brcms_c_compute_ofdm_plcp(rspec
, length
, plcp
);
6112 brcms_c_compute_cck_plcp(wlc
, rspec
, length
, plcp
);
6115 /* brcms_c_compute_rtscts_dur()
6117 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
6118 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
6119 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
6121 * cts cts-to-self or rts/cts
6122 * rts_rate rts or cts rate in unit of 500kbps
6123 * rate next MPDU rate in unit of 500kbps
6124 * frame_len next MPDU frame length in bytes
6127 brcms_c_compute_rtscts_dur(struct brcms_c_info
*wlc
, bool cts_only
,
6129 u32 frame_rate
, u8 rts_preamble_type
,
6130 u8 frame_preamble_type
, uint frame_len
, bool ba
)
6134 sifs
= get_sifs(wlc
->band
);
6140 (u16
) brcms_c_calc_cts_time(wlc
, rts_rate
,
6148 (u16
) brcms_c_calc_frame_time(wlc
, frame_rate
, frame_preamble_type
,
6152 (u16
) brcms_c_calc_ba_time(wlc
, frame_rate
,
6153 BRCMS_SHORT_PREAMBLE
);
6156 (u16
) brcms_c_calc_ack_time(wlc
, frame_rate
,
6157 frame_preamble_type
);
6161 static u16
brcms_c_phytxctl1_calc(struct brcms_c_info
*wlc
, u32 rspec
)
6166 if (BRCMS_ISLCNPHY(wlc
->band
)) {
6167 bw
= PHY_TXC1_BW_20MHZ
;
6169 bw
= rspec_get_bw(rspec
);
6170 /* 10Mhz is not supported yet */
6171 if (bw
< PHY_TXC1_BW_20MHZ
) {
6172 brcms_err(wlc
->hw
->d11core
, "phytxctl1_calc: bw %d is "
6173 "not supported yet, set to 20L\n", bw
);
6174 bw
= PHY_TXC1_BW_20MHZ
;
6178 if (is_mcs_rate(rspec
)) {
6179 uint mcs
= rspec
& RSPEC_RATE_MASK
;
6181 /* bw, stf, coding-type is part of rspec_phytxbyte2 returns */
6182 phyctl1
= rspec_phytxbyte2(rspec
);
6183 /* set the upper byte of phyctl1 */
6184 phyctl1
|= (mcs_table
[mcs
].tx_phy_ctl3
<< 8);
6185 } else if (is_cck_rate(rspec
) && !BRCMS_ISLCNPHY(wlc
->band
)
6186 && !BRCMS_ISSSLPNPHY(wlc
->band
)) {
6188 * In CCK mode LPPHY overloads OFDM Modulation bits with CCK
6189 * Data Rate. Eventually MIMOPHY would also be converted to
6192 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
6193 phyctl1
= (bw
| (rspec_stf(rspec
) << PHY_TXC1_MODE_SHIFT
));
6194 } else { /* legacy OFDM/CCK */
6196 /* get the phyctl byte from rate phycfg table */
6197 phycfg
= brcms_c_rate_legacy_phyctl(rspec2rate(rspec
));
6199 brcms_err(wlc
->hw
->d11core
, "phytxctl1_calc: wrong "
6200 "legacy OFDM/CCK rate\n");
6203 /* set the upper byte of phyctl1 */
6205 (bw
| (phycfg
<< 8) |
6206 (rspec_stf(rspec
) << PHY_TXC1_MODE_SHIFT
));
6212 * Add struct d11txh, struct cck_phy_hdr.
6214 * 'p' data must start with 802.11 MAC header
6215 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
6217 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
6221 brcms_c_d11hdrs_mac80211(struct brcms_c_info
*wlc
, struct ieee80211_hw
*hw
,
6222 struct sk_buff
*p
, struct scb
*scb
, uint frag
,
6223 uint nfrags
, uint queue
, uint next_frag_len
)
6225 struct ieee80211_hdr
*h
;
6227 u8
*plcp
, plcp_fallback
[D11_PHY_HDR_LEN
];
6228 int len
, phylen
, rts_phylen
;
6229 u16 mch
, phyctl
, xfts
, mainrates
;
6230 u16 seq
= 0, mcl
= 0, status
= 0, frameid
= 0;
6231 u32 rspec
[2] = { BRCM_RATE_1M
, BRCM_RATE_1M
};
6232 u32 rts_rspec
[2] = { BRCM_RATE_1M
, BRCM_RATE_1M
};
6233 bool use_rts
= false;
6234 bool use_cts
= false;
6235 bool use_rifs
= false;
6236 bool short_preamble
[2] = { false, false };
6237 u8 preamble_type
[2] = { BRCMS_LONG_PREAMBLE
, BRCMS_LONG_PREAMBLE
};
6238 u8 rts_preamble_type
[2] = { BRCMS_LONG_PREAMBLE
, BRCMS_LONG_PREAMBLE
};
6239 u8
*rts_plcp
, rts_plcp_fallback
[D11_PHY_HDR_LEN
];
6240 struct ieee80211_rts
*rts
= NULL
;
6243 bool hwtkmic
= false;
6244 u16 mimo_ctlchbw
= PHY_TXC1_BW_20MHZ
;
6245 #define ANTCFG_NONE 0xFF
6246 u8 antcfg
= ANTCFG_NONE
;
6247 u8 fbantcfg
= ANTCFG_NONE
;
6248 uint phyctl1_stf
= 0;
6250 struct ieee80211_tx_rate
*txrate
[2];
6252 struct ieee80211_tx_info
*tx_info
;
6255 u8 mimo_preamble_type
;
6257 /* locate 802.11 MAC header */
6258 h
= (struct ieee80211_hdr
*)(p
->data
);
6259 qos
= ieee80211_is_data_qos(h
->frame_control
);
6261 /* compute length of frame in bytes for use in PLCP computations */
6263 phylen
= len
+ FCS_LEN
;
6266 tx_info
= IEEE80211_SKB_CB(p
);
6269 plcp
= skb_push(p
, D11_PHY_HDR_LEN
);
6271 /* add Broadcom tx descriptor header */
6272 txh
= (struct d11txh
*) skb_push(p
, D11_TXH_LEN
);
6273 memset(txh
, 0, D11_TXH_LEN
);
6276 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
6277 /* non-AP STA should never use BCMC queue */
6278 if (queue
== TX_BCMC_FIFO
) {
6279 brcms_err(wlc
->hw
->d11core
,
6280 "wl%d: %s: ASSERT queue == TX_BCMC!\n",
6281 wlc
->pub
->unit
, __func__
);
6282 frameid
= bcmc_fid_generate(wlc
, NULL
, txh
);
6284 /* Increment the counter for first fragment */
6285 if (tx_info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
)
6286 scb
->seqnum
[p
->priority
]++;
6288 /* extract fragment number from frame first */
6289 seq
= le16_to_cpu(h
->seq_ctrl
) & FRAGNUM_MASK
;
6290 seq
|= (scb
->seqnum
[p
->priority
] << SEQNUM_SHIFT
);
6291 h
->seq_ctrl
= cpu_to_le16(seq
);
6293 frameid
= ((seq
<< TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
6294 (queue
& TXFID_QUEUE_MASK
);
6297 frameid
|= queue
& TXFID_QUEUE_MASK
;
6299 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
6300 if (ieee80211_is_beacon(h
->frame_control
))
6301 mcl
|= TXC_IGNOREPMQ
;
6303 txrate
[0] = tx_info
->control
.rates
;
6304 txrate
[1] = txrate
[0] + 1;
6307 * if rate control algorithm didn't give us a fallback
6308 * rate, use the primary rate
6310 if (txrate
[1]->idx
< 0)
6311 txrate
[1] = txrate
[0];
6313 for (k
= 0; k
< hw
->max_rates
; k
++) {
6314 is_mcs
= txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
? true : false;
6316 if ((txrate
[k
]->idx
>= 0)
6317 && (txrate
[k
]->idx
<
6318 hw
->wiphy
->bands
[tx_info
->band
]->n_bitrates
)) {
6320 hw
->wiphy
->bands
[tx_info
->band
]->
6321 bitrates
[txrate
[k
]->idx
].hw_value
;
6324 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
?
6327 rspec
[k
] = BRCM_RATE_1M
;
6330 rspec
[k
] = mac80211_wlc_set_nrate(wlc
, wlc
->band
,
6331 NRATE_MCS_INUSE
| txrate
[k
]->idx
);
6335 * Currently only support same setting for primay and
6336 * fallback rates. Unify flags for each rate into a
6337 * single value for the frame
6341 flags
& IEEE80211_TX_RC_USE_RTS_CTS
? true : false;
6344 flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
? true : false;
6349 * determine and validate primary rate
6350 * and fallback rates
6352 if (!rspec_active(rspec
[k
])) {
6353 rspec
[k
] = BRCM_RATE_1M
;
6355 if (!is_multicast_ether_addr(h
->addr1
)) {
6356 /* set tx antenna config */
6357 brcms_c_antsel_antcfg_get(wlc
->asi
, false,
6358 false, 0, 0, &antcfg
, &fbantcfg
);
6363 phyctl1_stf
= wlc
->stf
->ss_opmode
;
6365 if (wlc
->pub
->_n_enab
& SUPPORT_11N
) {
6366 for (k
= 0; k
< hw
->max_rates
; k
++) {
6368 * apply siso/cdd to single stream mcs's or ofdm
6369 * if rspec is auto selected
6371 if (((is_mcs_rate(rspec
[k
]) &&
6372 is_single_stream(rspec
[k
] & RSPEC_RATE_MASK
)) ||
6373 is_ofdm_rate(rspec
[k
]))
6374 && ((rspec
[k
] & RSPEC_OVERRIDE_MCS_ONLY
)
6375 || !(rspec
[k
] & RSPEC_OVERRIDE
))) {
6376 rspec
[k
] &= ~(RSPEC_STF_MASK
| RSPEC_STC_MASK
);
6378 /* For SISO MCS use STBC if possible */
6379 if (is_mcs_rate(rspec
[k
])
6380 && BRCMS_STF_SS_STBC_TX(wlc
, scb
)) {
6383 /* Nss for single stream is always 1 */
6385 rspec
[k
] |= (PHY_TXC1_MODE_STBC
<<
6387 (stc
<< RSPEC_STC_SHIFT
);
6390 (phyctl1_stf
<< RSPEC_STF_SHIFT
);
6394 * Is the phy configured to use 40MHZ frames? If
6395 * so then pick the desired txbw
6397 if (brcms_chspec_bw(wlc
->chanspec
) == BRCMS_40_MHZ
) {
6398 /* default txbw is 20in40 SB */
6399 mimo_ctlchbw
= mimo_txbw
=
6400 CHSPEC_SB_UPPER(wlc_phy_chanspec_get(
6402 ? PHY_TXC1_BW_20MHZ_UP
: PHY_TXC1_BW_20MHZ
;
6404 if (is_mcs_rate(rspec
[k
])) {
6405 /* mcs 32 must be 40b/w DUP */
6406 if ((rspec
[k
] & RSPEC_RATE_MASK
)
6409 PHY_TXC1_BW_40MHZ_DUP
;
6411 } else if (wlc
->mimo_40txbw
!= AUTO
)
6412 mimo_txbw
= wlc
->mimo_40txbw
;
6413 /* else check if dst is using 40 Mhz */
6414 else if (scb
->flags
& SCB_IS40
)
6415 mimo_txbw
= PHY_TXC1_BW_40MHZ
;
6416 } else if (is_ofdm_rate(rspec
[k
])) {
6417 if (wlc
->ofdm_40txbw
!= AUTO
)
6418 mimo_txbw
= wlc
->ofdm_40txbw
;
6419 } else if (wlc
->cck_40txbw
!= AUTO
) {
6420 mimo_txbw
= wlc
->cck_40txbw
;
6424 * mcs32 is 40 b/w only.
6425 * This is possible for probe packets on
6428 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32)
6430 rspec
[k
] = RSPEC_MIMORATE
;
6432 mimo_txbw
= PHY_TXC1_BW_20MHZ
;
6435 /* Set channel width */
6436 rspec
[k
] &= ~RSPEC_BW_MASK
;
6437 if ((k
== 0) || ((k
> 0) && is_mcs_rate(rspec
[k
])))
6438 rspec
[k
] |= (mimo_txbw
<< RSPEC_BW_SHIFT
);
6440 rspec
[k
] |= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
6442 /* Disable short GI, not supported yet */
6443 rspec
[k
] &= ~RSPEC_SHORT_GI
;
6445 mimo_preamble_type
= BRCMS_MM_PREAMBLE
;
6446 if (txrate
[k
]->flags
& IEEE80211_TX_RC_GREEN_FIELD
)
6447 mimo_preamble_type
= BRCMS_GF_PREAMBLE
;
6449 if ((txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
)
6450 && (!is_mcs_rate(rspec
[k
]))) {
6451 brcms_warn(wlc
->hw
->d11core
,
6452 "wl%d: %s: IEEE80211_TX_RC_MCS != is_mcs_rate(rspec)\n",
6453 wlc
->pub
->unit
, __func__
);
6456 if (is_mcs_rate(rspec
[k
])) {
6457 preamble_type
[k
] = mimo_preamble_type
;
6460 * if SGI is selected, then forced mm
6463 if ((rspec
[k
] & RSPEC_SHORT_GI
)
6464 && is_single_stream(rspec
[k
] &
6466 preamble_type
[k
] = BRCMS_MM_PREAMBLE
;
6469 /* should be better conditionalized */
6470 if (!is_mcs_rate(rspec
[0])
6471 && (tx_info
->control
.rates
[0].
6472 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
))
6473 preamble_type
[k
] = BRCMS_SHORT_PREAMBLE
;
6476 for (k
= 0; k
< hw
->max_rates
; k
++) {
6477 /* Set ctrlchbw as 20Mhz */
6478 rspec
[k
] &= ~RSPEC_BW_MASK
;
6479 rspec
[k
] |= (PHY_TXC1_BW_20MHZ
<< RSPEC_BW_SHIFT
);
6481 /* for nphy, stf of ofdm frames must follow policies */
6482 if (BRCMS_ISNPHY(wlc
->band
) && is_ofdm_rate(rspec
[k
])) {
6483 rspec
[k
] &= ~RSPEC_STF_MASK
;
6484 rspec
[k
] |= phyctl1_stf
<< RSPEC_STF_SHIFT
;
6489 /* Reset these for use with AMPDU's */
6490 txrate
[0]->count
= 0;
6491 txrate
[1]->count
= 0;
6493 /* (2) PROTECTION, may change rspec */
6494 if ((ieee80211_is_data(h
->frame_control
) ||
6495 ieee80211_is_mgmt(h
->frame_control
)) &&
6496 (phylen
> wlc
->RTSThresh
) && !is_multicast_ether_addr(h
->addr1
))
6499 /* (3) PLCP: determine PLCP header and MAC duration,
6500 * fill struct d11txh */
6501 brcms_c_compute_plcp(wlc
, rspec
[0], phylen
, plcp
);
6502 brcms_c_compute_plcp(wlc
, rspec
[1], phylen
, plcp_fallback
);
6503 memcpy(&txh
->FragPLCPFallback
,
6504 plcp_fallback
, sizeof(txh
->FragPLCPFallback
));
6506 /* Length field now put in CCK FBR CRC field */
6507 if (is_cck_rate(rspec
[1])) {
6508 txh
->FragPLCPFallback
[4] = phylen
& 0xff;
6509 txh
->FragPLCPFallback
[5] = (phylen
& 0xff00) >> 8;
6512 /* MIMO-RATE: need validation ?? */
6513 mainrates
= is_ofdm_rate(rspec
[0]) ?
6514 D11A_PHY_HDR_GRATE((struct ofdm_phy_hdr
*) plcp
) :
6517 /* DUR field for main rate */
6518 if (!ieee80211_is_pspoll(h
->frame_control
) &&
6519 !is_multicast_ether_addr(h
->addr1
) && !use_rifs
) {
6521 brcms_c_compute_frame_dur(wlc
, rspec
[0], preamble_type
[0],
6523 h
->duration_id
= cpu_to_le16(durid
);
6524 } else if (use_rifs
) {
6525 /* NAV protect to end of next max packet size */
6527 (u16
) brcms_c_calc_frame_time(wlc
, rspec
[0],
6529 DOT11_MAX_FRAG_LEN
);
6530 durid
+= RIFS_11N_TIME
;
6531 h
->duration_id
= cpu_to_le16(durid
);
6534 /* DUR field for fallback rate */
6535 if (ieee80211_is_pspoll(h
->frame_control
))
6536 txh
->FragDurFallback
= h
->duration_id
;
6537 else if (is_multicast_ether_addr(h
->addr1
) || use_rifs
)
6538 txh
->FragDurFallback
= 0;
6540 durid
= brcms_c_compute_frame_dur(wlc
, rspec
[1],
6541 preamble_type
[1], next_frag_len
);
6542 txh
->FragDurFallback
= cpu_to_le16(durid
);
6545 /* (4) MAC-HDR: MacTxControlLow */
6547 mcl
|= TXC_STARTMSDU
;
6549 if (!is_multicast_ether_addr(h
->addr1
))
6550 mcl
|= TXC_IMMEDACK
;
6552 if (wlc
->band
->bandtype
== BRCM_BAND_5G
)
6553 mcl
|= TXC_FREQBAND_5G
;
6555 if (CHSPEC_IS40(wlc_phy_chanspec_get(wlc
->band
->pi
)))
6558 /* set AMIC bit if using hardware TKIP MIC */
6562 txh
->MacTxControlLow
= cpu_to_le16(mcl
);
6564 /* MacTxControlHigh */
6567 /* Set fallback rate preamble type */
6568 if ((preamble_type
[1] == BRCMS_SHORT_PREAMBLE
) ||
6569 (preamble_type
[1] == BRCMS_GF_PREAMBLE
)) {
6570 if (rspec2rate(rspec
[1]) != BRCM_RATE_1M
)
6571 mch
|= TXC_PREAMBLE_DATA_FB_SHORT
;
6574 /* MacFrameControl */
6575 memcpy(&txh
->MacFrameControl
, &h
->frame_control
, sizeof(u16
));
6576 txh
->TxFesTimeNormal
= cpu_to_le16(0);
6578 txh
->TxFesTimeFallback
= cpu_to_le16(0);
6581 memcpy(&txh
->TxFrameRA
, &h
->addr1
, ETH_ALEN
);
6584 txh
->TxFrameID
= cpu_to_le16(frameid
);
6587 * TxStatus, Note the case of recreating the first frag of a suppressed
6588 * frame then we may need to reset the retry cnt's via the status reg
6590 txh
->TxStatus
= cpu_to_le16(status
);
6593 * extra fields for ucode AMPDU aggregation, the new fields are added to
6594 * the END of previous structure so that it's compatible in driver.
6596 txh
->MaxNMpdus
= cpu_to_le16(0);
6597 txh
->MaxABytes_MRT
= cpu_to_le16(0);
6598 txh
->MaxABytes_FBR
= cpu_to_le16(0);
6599 txh
->MinMBytes
= cpu_to_le16(0);
6601 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration,
6602 * furnish struct d11txh */
6603 /* RTS PLCP header and RTS frame */
6604 if (use_rts
|| use_cts
) {
6605 if (use_rts
&& use_cts
)
6608 for (k
= 0; k
< 2; k
++) {
6609 rts_rspec
[k
] = brcms_c_rspec_to_rts_rspec(wlc
, rspec
[k
],
6614 if (!is_ofdm_rate(rts_rspec
[0]) &&
6615 !((rspec2rate(rts_rspec
[0]) == BRCM_RATE_1M
) ||
6616 (wlc
->PLCPHdr_override
== BRCMS_PLCP_LONG
))) {
6617 rts_preamble_type
[0] = BRCMS_SHORT_PREAMBLE
;
6618 mch
|= TXC_PREAMBLE_RTS_MAIN_SHORT
;
6621 if (!is_ofdm_rate(rts_rspec
[1]) &&
6622 !((rspec2rate(rts_rspec
[1]) == BRCM_RATE_1M
) ||
6623 (wlc
->PLCPHdr_override
== BRCMS_PLCP_LONG
))) {
6624 rts_preamble_type
[1] = BRCMS_SHORT_PREAMBLE
;
6625 mch
|= TXC_PREAMBLE_RTS_FB_SHORT
;
6628 /* RTS/CTS additions to MacTxControlLow */
6630 txh
->MacTxControlLow
|= cpu_to_le16(TXC_SENDCTS
);
6632 txh
->MacTxControlLow
|= cpu_to_le16(TXC_SENDRTS
);
6633 txh
->MacTxControlLow
|= cpu_to_le16(TXC_LONGFRAME
);
6636 /* RTS PLCP header */
6637 rts_plcp
= txh
->RTSPhyHeader
;
6639 rts_phylen
= DOT11_CTS_LEN
+ FCS_LEN
;
6641 rts_phylen
= DOT11_RTS_LEN
+ FCS_LEN
;
6643 brcms_c_compute_plcp(wlc
, rts_rspec
[0], rts_phylen
, rts_plcp
);
6645 /* fallback rate version of RTS PLCP header */
6646 brcms_c_compute_plcp(wlc
, rts_rspec
[1], rts_phylen
,
6648 memcpy(&txh
->RTSPLCPFallback
, rts_plcp_fallback
,
6649 sizeof(txh
->RTSPLCPFallback
));
6651 /* RTS frame fields... */
6652 rts
= (struct ieee80211_rts
*)&txh
->rts_frame
;
6654 durid
= brcms_c_compute_rtscts_dur(wlc
, use_cts
, rts_rspec
[0],
6655 rspec
[0], rts_preamble_type
[0],
6656 preamble_type
[0], phylen
, false);
6657 rts
->duration
= cpu_to_le16(durid
);
6658 /* fallback rate version of RTS DUR field */
6659 durid
= brcms_c_compute_rtscts_dur(wlc
, use_cts
,
6660 rts_rspec
[1], rspec
[1],
6661 rts_preamble_type
[1],
6662 preamble_type
[1], phylen
, false);
6663 txh
->RTSDurFallback
= cpu_to_le16(durid
);
6666 rts
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
6667 IEEE80211_STYPE_CTS
);
6669 memcpy(&rts
->ra
, &h
->addr2
, ETH_ALEN
);
6671 rts
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
6672 IEEE80211_STYPE_RTS
);
6674 memcpy(&rts
->ra
, &h
->addr1
, 2 * ETH_ALEN
);
6678 * low 8 bits: main frag rate/mcs,
6679 * high 8 bits: rts/cts rate/mcs
6681 mainrates
|= (is_ofdm_rate(rts_rspec
[0]) ?
6683 (struct ofdm_phy_hdr
*) rts_plcp
) :
6686 memset(txh
->RTSPhyHeader
, 0, D11_PHY_HDR_LEN
);
6687 memset(&txh
->rts_frame
, 0, sizeof(struct ieee80211_rts
));
6688 memset(txh
->RTSPLCPFallback
, 0, sizeof(txh
->RTSPLCPFallback
));
6689 txh
->RTSDurFallback
= 0;
6692 #ifdef SUPPORT_40MHZ
6693 /* add null delimiter count */
6694 if ((tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) && is_mcs_rate(rspec
))
6695 txh
->RTSPLCPFallback
[AMPDU_FBR_NULL_DELIM
] =
6696 brcm_c_ampdu_null_delim_cnt(wlc
->ampdu
, scb
, rspec
, phylen
);
6701 * Now that RTS/RTS FB preamble types are updated, write
6704 txh
->MacTxControlHigh
= cpu_to_le16(mch
);
6707 * MainRates (both the rts and frag plcp rates have
6708 * been calculated now)
6710 txh
->MainRates
= cpu_to_le16(mainrates
);
6712 /* XtraFrameTypes */
6713 xfts
= frametype(rspec
[1], wlc
->mimoft
);
6714 xfts
|= (frametype(rts_rspec
[0], wlc
->mimoft
) << XFTS_RTS_FT_SHIFT
);
6715 xfts
|= (frametype(rts_rspec
[1], wlc
->mimoft
) << XFTS_FBRRTS_FT_SHIFT
);
6716 xfts
|= CHSPEC_CHANNEL(wlc_phy_chanspec_get(wlc
->band
->pi
)) <<
6718 txh
->XtraFrameTypes
= cpu_to_le16(xfts
);
6720 /* PhyTxControlWord */
6721 phyctl
= frametype(rspec
[0], wlc
->mimoft
);
6722 if ((preamble_type
[0] == BRCMS_SHORT_PREAMBLE
) ||
6723 (preamble_type
[0] == BRCMS_GF_PREAMBLE
)) {
6724 if (rspec2rate(rspec
[0]) != BRCM_RATE_1M
)
6725 phyctl
|= PHY_TXC_SHORT_HDR
;
6728 /* phytxant is properly bit shifted */
6729 phyctl
|= brcms_c_stf_d11hdrs_phyctl_txant(wlc
, rspec
[0]);
6730 txh
->PhyTxControlWord
= cpu_to_le16(phyctl
);
6732 /* PhyTxControlWord_1 */
6733 if (BRCMS_PHY_11N_CAP(wlc
->band
)) {
6736 phyctl1
= brcms_c_phytxctl1_calc(wlc
, rspec
[0]);
6737 txh
->PhyTxControlWord_1
= cpu_to_le16(phyctl1
);
6738 phyctl1
= brcms_c_phytxctl1_calc(wlc
, rspec
[1]);
6739 txh
->PhyTxControlWord_1_Fbr
= cpu_to_le16(phyctl1
);
6741 if (use_rts
|| use_cts
) {
6742 phyctl1
= brcms_c_phytxctl1_calc(wlc
, rts_rspec
[0]);
6743 txh
->PhyTxControlWord_1_Rts
= cpu_to_le16(phyctl1
);
6744 phyctl1
= brcms_c_phytxctl1_calc(wlc
, rts_rspec
[1]);
6745 txh
->PhyTxControlWord_1_FbrRts
= cpu_to_le16(phyctl1
);
6749 * For mcs frames, if mixedmode(overloaded with long preamble)
6750 * is going to be set, fill in non-zero MModeLen and/or
6751 * MModeFbrLen it will be unnecessary if they are separated
6753 if (is_mcs_rate(rspec
[0]) &&
6754 (preamble_type
[0] == BRCMS_MM_PREAMBLE
)) {
6756 brcms_c_calc_lsig_len(wlc
, rspec
[0], phylen
);
6757 txh
->MModeLen
= cpu_to_le16(mmodelen
);
6760 if (is_mcs_rate(rspec
[1]) &&
6761 (preamble_type
[1] == BRCMS_MM_PREAMBLE
)) {
6763 brcms_c_calc_lsig_len(wlc
, rspec
[1], phylen
);
6764 txh
->MModeFbrLen
= cpu_to_le16(mmodefbrlen
);
6768 ac
= skb_get_queue_mapping(p
);
6769 if ((scb
->flags
& SCB_WMECAP
) && qos
&& wlc
->edcf_txop
[ac
]) {
6770 uint frag_dur
, dur
, dur_fallback
;
6772 /* WME: Update TXOP threshold */
6773 if (!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) && frag
== 0) {
6775 brcms_c_calc_frame_time(wlc
, rspec
[0],
6776 preamble_type
[0], phylen
);
6779 /* 1 RTS or CTS-to-self frame */
6781 brcms_c_calc_cts_time(wlc
, rts_rspec
[0],
6782 rts_preamble_type
[0]);
6784 brcms_c_calc_cts_time(wlc
, rts_rspec
[1],
6785 rts_preamble_type
[1]);
6786 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6787 dur
+= le16_to_cpu(rts
->duration
);
6789 le16_to_cpu(txh
->RTSDurFallback
);
6790 } else if (use_rifs
) {
6794 /* frame + SIFS + ACK */
6797 brcms_c_compute_frame_dur(wlc
, rspec
[0],
6798 preamble_type
[0], 0);
6801 brcms_c_calc_frame_time(wlc
, rspec
[1],
6805 brcms_c_compute_frame_dur(wlc
, rspec
[1],
6806 preamble_type
[1], 0);
6808 /* NEED to set TxFesTimeNormal (hard) */
6809 txh
->TxFesTimeNormal
= cpu_to_le16((u16
) dur
);
6811 * NEED to set fallback rate version of
6812 * TxFesTimeNormal (hard)
6814 txh
->TxFesTimeFallback
=
6815 cpu_to_le16((u16
) dur_fallback
);
6818 * update txop byte threshold (txop minus intraframe
6821 if (wlc
->edcf_txop
[ac
] >= (dur
- frag_dur
)) {
6825 brcms_c_calc_frame_len(wlc
,
6826 rspec
[0], preamble_type
[0],
6827 (wlc
->edcf_txop
[ac
] -
6829 /* range bound the fragthreshold */
6830 if (newfragthresh
< DOT11_MIN_FRAG_LEN
)
6833 else if (newfragthresh
>
6834 wlc
->usr_fragthresh
)
6836 wlc
->usr_fragthresh
;
6837 /* update the fragthresh and do txc update */
6838 if (wlc
->fragthresh
[queue
] !=
6839 (u16
) newfragthresh
)
6840 wlc
->fragthresh
[queue
] =
6841 (u16
) newfragthresh
;
6843 brcms_warn(wlc
->hw
->d11core
,
6844 "wl%d: %s txop invalid for rate %d\n",
6845 wlc
->pub
->unit
, fifo_names
[queue
],
6846 rspec2rate(rspec
[0]));
6849 if (dur
> wlc
->edcf_txop
[ac
])
6850 brcms_warn(wlc
->hw
->d11core
,
6851 "wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6852 wlc
->pub
->unit
, __func__
,
6854 phylen
, wlc
->fragthresh
[queue
],
6855 dur
, wlc
->edcf_txop
[ac
]);
6862 static int brcms_c_tx(struct brcms_c_info
*wlc
, struct sk_buff
*skb
)
6864 struct dma_pub
*dma
;
6865 int fifo
, ret
= -ENOSPC
;
6867 u16 frameid
= INVALIDFID
;
6869 fifo
= brcms_ac_to_fifo(skb_get_queue_mapping(skb
));
6870 dma
= wlc
->hw
->di
[fifo
];
6871 txh
= (struct d11txh
*)(skb
->data
);
6873 if (dma
->txavail
== 0) {
6875 * We sometimes get a frame from mac80211 after stopping
6876 * the queues. This only ever seems to be a single frame
6877 * and is seems likely to be a race. TX_HEADROOM should
6878 * ensure that we have enough space to handle these stray
6879 * packets, so warn if there isn't. If we're out of space
6880 * in the tx ring and the tx queue isn't stopped then
6881 * we've really got a bug; warn loudly if that happens.
6883 brcms_warn(wlc
->hw
->d11core
,
6884 "Received frame for tx with no space in DMA ring\n");
6885 WARN_ON(!ieee80211_queue_stopped(wlc
->pub
->ieee_hw
,
6886 skb_get_queue_mapping(skb
)));
6890 /* When a BC/MC frame is being committed to the BCMC fifo
6891 * via DMA (NOT PIO), update ucode or BSS info as appropriate.
6893 if (fifo
== TX_BCMC_FIFO
)
6894 frameid
= le16_to_cpu(txh
->TxFrameID
);
6896 /* Commit BCMC sequence number in the SHM frame ID location */
6897 if (frameid
!= INVALIDFID
) {
6899 * To inform the ucode of the last mcast frame posted
6900 * so that it can clear moredata bit
6902 brcms_b_write_shm(wlc
->hw
, M_BCMC_FID
, frameid
);
6905 ret
= brcms_c_txfifo(wlc
, fifo
, skb
);
6907 * The only reason for brcms_c_txfifo to fail is because
6908 * there weren't any DMA descriptors, but we've already
6909 * checked for that. So if it does fail yell loudly.
6916 bool brcms_c_sendpkt_mac80211(struct brcms_c_info
*wlc
, struct sk_buff
*sdu
,
6917 struct ieee80211_hw
*hw
)
6920 struct scb
*scb
= &wlc
->pri_scb
;
6922 fifo
= brcms_ac_to_fifo(skb_get_queue_mapping(sdu
));
6923 brcms_c_d11hdrs_mac80211(wlc
, hw
, sdu
, scb
, 0, 1, fifo
, 0);
6924 if (!brcms_c_tx(wlc
, sdu
))
6927 /* packet discarded */
6928 dev_kfree_skb_any(sdu
);
6933 brcms_c_txfifo(struct brcms_c_info
*wlc
, uint fifo
, struct sk_buff
*p
)
6935 struct dma_pub
*dma
= wlc
->hw
->di
[fifo
];
6939 ret
= dma_txfast(wlc
, dma
, p
);
6941 wiphy_err(wlc
->wiphy
, "txfifo: fatal, toss frames !!!\n");
6944 * Stop queue if DMA ring is full. Reserve some free descriptors,
6945 * as we sometimes receive a frame from mac80211 after the queues
6948 queue
= skb_get_queue_mapping(p
);
6949 if (dma
->txavail
<= TX_HEADROOM
&& fifo
< TX_BCMC_FIFO
&&
6950 !ieee80211_queue_stopped(wlc
->pub
->ieee_hw
, queue
))
6951 ieee80211_stop_queue(wlc
->pub
->ieee_hw
, queue
);
6957 brcms_c_rspec_to_rts_rspec(struct brcms_c_info
*wlc
, u32 rspec
,
6958 bool use_rspec
, u16 mimo_ctlchbw
)
6963 /* use frame rate as rts rate */
6965 else if (wlc
->band
->gmode
&& wlc
->protection
->_g
&& !is_cck_rate(rspec
))
6966 /* Use 11Mbps as the g protection RTS target rate and fallback.
6967 * Use the brcms_basic_rate() lookup to find the best basic rate
6968 * under the target in case 11 Mbps is not Basic.
6969 * 6 and 9 Mbps are not usually selected by rate selection, but
6970 * even if the OFDM rate we are protecting is 6 or 9 Mbps, 11
6973 rts_rspec
= brcms_basic_rate(wlc
, BRCM_RATE_11M
);
6975 /* calculate RTS rate and fallback rate based on the frame rate
6976 * RTS must be sent at a basic rate since it is a
6977 * control frame, sec 9.6 of 802.11 spec
6979 rts_rspec
= brcms_basic_rate(wlc
, rspec
);
6981 if (BRCMS_PHY_11N_CAP(wlc
->band
)) {
6982 /* set rts txbw to correct side band */
6983 rts_rspec
&= ~RSPEC_BW_MASK
;
6986 * if rspec/rspec_fallback is 40MHz, then send RTS on both
6987 * 20MHz channel (DUP), otherwise send RTS on control channel
6989 if (rspec_is40mhz(rspec
) && !is_cck_rate(rts_rspec
))
6990 rts_rspec
|= (PHY_TXC1_BW_40MHZ_DUP
<< RSPEC_BW_SHIFT
);
6992 rts_rspec
|= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
6994 /* pick siso/cdd as default for ofdm */
6995 if (is_ofdm_rate(rts_rspec
)) {
6996 rts_rspec
&= ~RSPEC_STF_MASK
;
6997 rts_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
7003 /* Update beacon listen interval in shared memory */
7004 static void brcms_c_bcn_li_upd(struct brcms_c_info
*wlc
)
7006 /* wake up every DTIM is the default */
7007 if (wlc
->bcn_li_dtim
== 1)
7008 brcms_b_write_shm(wlc
->hw
, M_BCN_LI
, 0);
7010 brcms_b_write_shm(wlc
->hw
, M_BCN_LI
,
7011 (wlc
->bcn_li_dtim
<< 8) | wlc
->bcn_li_bcn
);
7015 brcms_b_read_tsf(struct brcms_hardware
*wlc_hw
, u32
*tsf_l_ptr
,
7018 struct bcma_device
*core
= wlc_hw
->d11core
;
7020 /* read the tsf timer low, then high to get an atomic read */
7021 *tsf_l_ptr
= bcma_read32(core
, D11REGOFFS(tsf_timerlow
));
7022 *tsf_h_ptr
= bcma_read32(core
, D11REGOFFS(tsf_timerhigh
));
7026 * recover 64bit TSF value from the 16bit TSF value in the rx header
7027 * given the assumption that the TSF passed in header is within 65ms
7028 * of the current tsf.
7031 * 3.......6.......8.......0.......2.......4.......6.......8......0
7032 * |<---------- tsf_h ----------->||<--- tsf_l -->||<-RxTSFTime ->|
7034 * The RxTSFTime are the lowest 16 bits and provided by the ucode. The
7035 * tsf_l is filled in by brcms_b_recv, which is done earlier in the
7036 * receive call sequence after rx interrupt. Only the higher 16 bits
7037 * are used. Finally, the tsf_h is read from the tsf register.
7039 static u64
brcms_c_recover_tsf64(struct brcms_c_info
*wlc
,
7040 struct d11rxhdr
*rxh
)
7043 u16 rx_tsf_0_15
, rx_tsf_16_31
;
7045 brcms_b_read_tsf(wlc
->hw
, &tsf_l
, &tsf_h
);
7047 rx_tsf_16_31
= (u16
)(tsf_l
>> 16);
7048 rx_tsf_0_15
= rxh
->RxTSFTime
;
7051 * a greater tsf time indicates the low 16 bits of
7052 * tsf_l wrapped, so decrement the high 16 bits.
7054 if ((u16
)tsf_l
< rx_tsf_0_15
) {
7056 if (rx_tsf_16_31
== 0xffff)
7060 return ((u64
)tsf_h
<< 32) | (((u32
)rx_tsf_16_31
<< 16) + rx_tsf_0_15
);
7064 prep_mac80211_status(struct brcms_c_info
*wlc
, struct d11rxhdr
*rxh
,
7066 struct ieee80211_rx_status
*rx_status
)
7070 unsigned char *plcp
;
7072 /* fill in TSF and flag its presence */
7073 rx_status
->mactime
= brcms_c_recover_tsf64(wlc
, rxh
);
7074 rx_status
->flag
|= RX_FLAG_MACTIME_START
;
7076 channel
= BRCMS_CHAN_CHANNEL(rxh
->RxChan
);
7079 channel
> 14 ? NL80211_BAND_5GHZ
: NL80211_BAND_2GHZ
;
7081 ieee80211_channel_to_frequency(channel
, rx_status
->band
);
7083 rx_status
->signal
= wlc_phy_rssi_compute(wlc
->hw
->band
->pi
, rxh
);
7087 rx_status
->antenna
=
7088 (rxh
->PhyRxStatus_0
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0;
7092 rspec
= brcms_c_compute_rspec(rxh
, plcp
);
7093 if (is_mcs_rate(rspec
)) {
7094 rx_status
->rate_idx
= rspec
& RSPEC_RATE_MASK
;
7095 rx_status
->encoding
= RX_ENC_HT
;
7096 if (rspec_is40mhz(rspec
))
7097 rx_status
->bw
= RATE_INFO_BW_40
;
7099 switch (rspec2rate(rspec
)) {
7101 rx_status
->rate_idx
= 0;
7104 rx_status
->rate_idx
= 1;
7107 rx_status
->rate_idx
= 2;
7110 rx_status
->rate_idx
= 3;
7113 rx_status
->rate_idx
= 4;
7116 rx_status
->rate_idx
= 5;
7119 rx_status
->rate_idx
= 6;
7122 rx_status
->rate_idx
= 7;
7125 rx_status
->rate_idx
= 8;
7128 rx_status
->rate_idx
= 9;
7131 rx_status
->rate_idx
= 10;
7134 rx_status
->rate_idx
= 11;
7137 brcms_err(wlc
->hw
->d11core
,
7138 "%s: Unknown rate\n", __func__
);
7142 * For 5GHz, we should decrease the index as it is
7143 * a subset of the 2.4G rates. See bitrates field
7144 * of brcms_band_5GHz_nphy (in mac80211_if.c).
7146 if (rx_status
->band
== NL80211_BAND_5GHZ
)
7147 rx_status
->rate_idx
-= BRCMS_LEGACY_5G_RATE_OFFSET
;
7149 /* Determine short preamble and rate_idx */
7150 if (is_cck_rate(rspec
)) {
7151 if (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
)
7152 rx_status
->enc_flags
|= RX_ENC_FLAG_SHORTPRE
;
7153 } else if (is_ofdm_rate(rspec
)) {
7154 rx_status
->enc_flags
|= RX_ENC_FLAG_SHORTPRE
;
7156 brcms_err(wlc
->hw
->d11core
, "%s: Unknown modulation\n",
7161 if (plcp3_issgi(plcp
[3]))
7162 rx_status
->enc_flags
|= RX_ENC_FLAG_SHORT_GI
;
7164 if (rxh
->RxStatus1
& RXS_DECERR
) {
7165 rx_status
->flag
|= RX_FLAG_FAILED_PLCP_CRC
;
7166 brcms_err(wlc
->hw
->d11core
, "%s: RX_FLAG_FAILED_PLCP_CRC\n",
7169 if (rxh
->RxStatus1
& RXS_FCSERR
) {
7170 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
7171 brcms_err(wlc
->hw
->d11core
, "%s: RX_FLAG_FAILED_FCS_CRC\n",
7177 brcms_c_recvctl(struct brcms_c_info
*wlc
, struct d11rxhdr
*rxh
,
7181 struct ieee80211_rx_status rx_status
;
7182 struct ieee80211_hdr
*hdr
;
7184 memset(&rx_status
, 0, sizeof(rx_status
));
7185 prep_mac80211_status(wlc
, rxh
, p
, &rx_status
);
7187 /* mac header+body length, exclude CRC and plcp header */
7188 len_mpdu
= p
->len
- D11_PHY_HDR_LEN
- FCS_LEN
;
7189 skb_pull(p
, D11_PHY_HDR_LEN
);
7190 __skb_trim(p
, len_mpdu
);
7192 /* unmute transmit */
7193 if (wlc
->hw
->suspended_fifos
) {
7194 hdr
= (struct ieee80211_hdr
*)p
->data
;
7195 if (ieee80211_is_beacon(hdr
->frame_control
))
7196 brcms_b_mute(wlc
->hw
, false);
7199 memcpy(IEEE80211_SKB_RXCB(p
), &rx_status
, sizeof(rx_status
));
7200 ieee80211_rx_irqsafe(wlc
->pub
->ieee_hw
, p
);
7203 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7204 * number of bytes goes in the length field
7206 * Formula given by HT PHY Spec v 1.13
7207 * len = 3(nsyms + nstream + 3) - 3
7210 brcms_c_calc_lsig_len(struct brcms_c_info
*wlc
, u32 ratespec
,
7213 uint nsyms
, len
= 0, kNdps
;
7215 if (is_mcs_rate(ratespec
)) {
7216 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7217 int tot_streams
= (mcs_2_txstreams(mcs
) + 1) +
7218 rspec_stc(ratespec
);
7221 * the payload duration calculation matches that
7224 /* 1000Ndbps = kbps * 4 */
7225 kNdps
= mcs_2_rate(mcs
, rspec_is40mhz(ratespec
),
7226 rspec_issgi(ratespec
)) * 4;
7228 if (rspec_stc(ratespec
) == 0)
7230 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7231 APHY_TAIL_NBITS
) * 1000, kNdps
);
7233 /* STBC needs to have even number of symbols */
7236 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7237 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7239 /* (+3) account for HT-SIG(2) and HT-STF(1) */
7240 nsyms
+= (tot_streams
+ 3);
7242 * 3 bytes/symbol @ legacy 6Mbps rate
7243 * (-3) excluding service bits and tail bits
7245 len
= (3 * nsyms
) - 3;
7252 brcms_c_mod_prb_rsp_rate_table(struct brcms_c_info
*wlc
, uint frame_len
)
7254 const struct brcms_c_rateset
*rs_dflt
;
7255 struct brcms_c_rateset rs
;
7258 u8 plcp
[D11_PHY_HDR_LEN
];
7262 sifs
= get_sifs(wlc
->band
);
7264 rs_dflt
= brcms_c_rateset_get_hwrs(wlc
);
7266 brcms_c_rateset_copy(rs_dflt
, &rs
);
7267 brcms_c_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7270 * walk the phy rate table and update MAC core SHM
7271 * basic rate table entries
7273 for (i
= 0; i
< rs
.count
; i
++) {
7274 rate
= rs
.rates
[i
] & BRCMS_RATE_MASK
;
7276 entry_ptr
= brcms_b_rate_shm_offset(wlc
->hw
, rate
);
7278 /* Calculate the Probe Response PLCP for the given rate */
7279 brcms_c_compute_plcp(wlc
, rate
, frame_len
, plcp
);
7282 * Calculate the duration of the Probe Response
7283 * frame plus SIFS for the MAC
7285 dur
= (u16
) brcms_c_calc_frame_time(wlc
, rate
,
7286 BRCMS_LONG_PREAMBLE
, frame_len
);
7289 /* Update the SHM Rate Table entry Probe Response values */
7290 brcms_b_write_shm(wlc
->hw
, entry_ptr
+ M_RT_PRS_PLCP_POS
,
7291 (u16
) (plcp
[0] + (plcp
[1] << 8)));
7292 brcms_b_write_shm(wlc
->hw
, entry_ptr
+ M_RT_PRS_PLCP_POS
+ 2,
7293 (u16
) (plcp
[2] + (plcp
[3] << 8)));
7294 brcms_b_write_shm(wlc
->hw
, entry_ptr
+ M_RT_PRS_DUR_POS
, dur
);
7298 int brcms_c_get_header_len(void)
7303 static void brcms_c_beacon_write(struct brcms_c_info
*wlc
,
7304 struct sk_buff
*beacon
, u16 tim_offset
,
7305 u16 dtim_period
, bool bcn0
, bool bcn1
)
7308 struct ieee80211_tx_info
*tx_info
;
7309 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
7310 struct ieee80211_hw
*ieee_hw
= brcms_c_pub(wlc
)->ieee_hw
;
7313 tx_info
= IEEE80211_SKB_CB(beacon
);
7315 len
= min_t(size_t, beacon
->len
, BCN_TMPL_LEN
);
7316 wlc
->bcn_rspec
= ieee80211_get_tx_rate(ieee_hw
, tx_info
)->hw_value
;
7318 brcms_c_compute_plcp(wlc
, wlc
->bcn_rspec
,
7319 len
+ FCS_LEN
- D11_PHY_HDR_LEN
, beacon
->data
);
7321 /* "Regular" and 16 MBSS but not for 4 MBSS */
7322 /* Update the phytxctl for the beacon based on the rspec */
7323 brcms_c_beacon_phytxctl_txant_upd(wlc
, wlc
->bcn_rspec
);
7326 /* write the probe response into the template region */
7327 brcms_b_write_template_ram(wlc_hw
, T_BCN0_TPL_BASE
,
7328 (len
+ 3) & ~3, beacon
->data
);
7330 /* write beacon length to SCR */
7331 brcms_b_write_shm(wlc_hw
, M_BCN0_FRM_BYTESZ
, (u16
) len
);
7334 /* write the probe response into the template region */
7335 brcms_b_write_template_ram(wlc_hw
, T_BCN1_TPL_BASE
,
7336 (len
+ 3) & ~3, beacon
->data
);
7338 /* write beacon length to SCR */
7339 brcms_b_write_shm(wlc_hw
, M_BCN1_FRM_BYTESZ
, (u16
) len
);
7342 if (tim_offset
!= 0) {
7343 brcms_b_write_shm(wlc_hw
, M_TIMBPOS_INBEACON
,
7344 tim_offset
+ D11B_PHY_HDR_LEN
);
7345 brcms_b_write_shm(wlc_hw
, M_DOT11_DTIMPERIOD
, dtim_period
);
7347 brcms_b_write_shm(wlc_hw
, M_TIMBPOS_INBEACON
,
7348 len
+ D11B_PHY_HDR_LEN
);
7349 brcms_b_write_shm(wlc_hw
, M_DOT11_DTIMPERIOD
, 0);
7353 static void brcms_c_update_beacon_hw(struct brcms_c_info
*wlc
,
7354 struct sk_buff
*beacon
, u16 tim_offset
,
7357 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
7358 struct bcma_device
*core
= wlc_hw
->d11core
;
7360 /* Hardware beaconing for this config */
7361 u32 both_valid
= MCMD_BCN0VLD
| MCMD_BCN1VLD
;
7363 /* Check if both templates are in use, if so sched. an interrupt
7364 * that will call back into this routine
7366 if ((bcma_read32(core
, D11REGOFFS(maccommand
)) & both_valid
) == both_valid
)
7367 /* clear any previous status */
7368 bcma_write32(core
, D11REGOFFS(macintstatus
), MI_BCNTPL
);
7370 if (wlc
->beacon_template_virgin
) {
7371 wlc
->beacon_template_virgin
= false;
7372 brcms_c_beacon_write(wlc
, beacon
, tim_offset
, dtim_period
, true,
7374 /* mark beacon0 valid */
7375 bcma_set32(core
, D11REGOFFS(maccommand
), MCMD_BCN0VLD
);
7379 /* Check that after scheduling the interrupt both of the
7380 * templates are still busy. if not clear the int. & remask
7382 if ((bcma_read32(core
, D11REGOFFS(maccommand
)) & both_valid
) == both_valid
) {
7383 wlc
->defmacintmask
|= MI_BCNTPL
;
7387 if (!(bcma_read32(core
, D11REGOFFS(maccommand
)) & MCMD_BCN0VLD
)) {
7388 brcms_c_beacon_write(wlc
, beacon
, tim_offset
, dtim_period
, true,
7390 /* mark beacon0 valid */
7391 bcma_set32(core
, D11REGOFFS(maccommand
), MCMD_BCN0VLD
);
7394 if (!(bcma_read32(core
, D11REGOFFS(maccommand
)) & MCMD_BCN1VLD
)) {
7395 brcms_c_beacon_write(wlc
, beacon
, tim_offset
, dtim_period
,
7397 /* mark beacon0 valid */
7398 bcma_set32(core
, D11REGOFFS(maccommand
), MCMD_BCN1VLD
);
7405 * Update all beacons for the system.
7407 void brcms_c_update_beacon(struct brcms_c_info
*wlc
)
7409 struct brcms_bss_cfg
*bsscfg
= wlc
->bsscfg
;
7411 if (wlc
->pub
->up
&& (bsscfg
->type
== BRCMS_TYPE_AP
||
7412 bsscfg
->type
== BRCMS_TYPE_ADHOC
)) {
7413 /* Clear the soft intmask */
7414 wlc
->defmacintmask
&= ~MI_BCNTPL
;
7417 brcms_c_update_beacon_hw(wlc
, wlc
->beacon
,
7418 wlc
->beacon_tim_offset
,
7419 wlc
->beacon_dtim_period
);
7423 void brcms_c_set_new_beacon(struct brcms_c_info
*wlc
, struct sk_buff
*beacon
,
7424 u16 tim_offset
, u16 dtim_period
)
7429 dev_kfree_skb_any(wlc
->beacon
);
7430 wlc
->beacon
= beacon
;
7433 skb_push(wlc
->beacon
, D11_PHY_HDR_LEN
);
7434 wlc
->beacon_tim_offset
= tim_offset
;
7435 wlc
->beacon_dtim_period
= dtim_period
;
7436 brcms_c_update_beacon(wlc
);
7439 void brcms_c_set_new_probe_resp(struct brcms_c_info
*wlc
,
7440 struct sk_buff
*probe_resp
)
7444 if (wlc
->probe_resp
)
7445 dev_kfree_skb_any(wlc
->probe_resp
);
7446 wlc
->probe_resp
= probe_resp
;
7449 skb_push(wlc
->probe_resp
, D11_PHY_HDR_LEN
);
7450 brcms_c_update_probe_resp(wlc
, false);
7453 void brcms_c_enable_probe_resp(struct brcms_c_info
*wlc
, bool enable
)
7456 * prevent ucode from sending probe responses by setting the timeout
7457 * to 1, it can not send it in that time frame.
7459 wlc
->prb_resp_timeout
= enable
? BRCMS_PRB_RESP_TIMEOUT
: 1;
7460 brcms_b_write_shm(wlc
->hw
, M_PRS_MAXTIME
, wlc
->prb_resp_timeout
);
7461 /* TODO: if (enable) => also deactivate receiving of probe request */
7464 /* Write ssid into shared memory */
7466 brcms_c_shm_ssid_upd(struct brcms_c_info
*wlc
, struct brcms_bss_cfg
*cfg
)
7468 u8
*ssidptr
= cfg
->SSID
;
7470 u8 ssidbuf
[IEEE80211_MAX_SSID_LEN
];
7472 /* padding the ssid with zero and copy it into shm */
7473 memset(ssidbuf
, 0, IEEE80211_MAX_SSID_LEN
);
7474 memcpy(ssidbuf
, ssidptr
, cfg
->SSID_len
);
7476 brcms_c_copyto_shm(wlc
, base
, ssidbuf
, IEEE80211_MAX_SSID_LEN
);
7477 brcms_b_write_shm(wlc
->hw
, M_SSIDLEN
, (u16
) cfg
->SSID_len
);
7481 brcms_c_bss_update_probe_resp(struct brcms_c_info
*wlc
,
7482 struct brcms_bss_cfg
*cfg
,
7483 struct sk_buff
*probe_resp
,
7488 len
= min_t(size_t, probe_resp
->len
, BCN_TMPL_LEN
);
7491 brcms_c_suspend_mac_and_wait(wlc
);
7493 /* write the probe response into the template region */
7494 brcms_b_write_template_ram(wlc
->hw
, T_PRS_TPL_BASE
,
7495 (len
+ 3) & ~3, probe_resp
->data
);
7497 /* write the length of the probe response frame (+PLCP/-FCS) */
7498 brcms_b_write_shm(wlc
->hw
, M_PRB_RESP_FRM_LEN
, (u16
) len
);
7500 /* write the SSID and SSID length */
7501 brcms_c_shm_ssid_upd(wlc
, cfg
);
7504 * Write PLCP headers and durations for probe response frames
7505 * at all rates. Use the actual frame length covered by the
7506 * PLCP header for the call to brcms_c_mod_prb_rsp_rate_table()
7507 * by subtracting the PLCP len and adding the FCS.
7509 brcms_c_mod_prb_rsp_rate_table(wlc
,
7510 (u16
)len
+ FCS_LEN
- D11_PHY_HDR_LEN
);
7513 brcms_c_enable_mac(wlc
);
7516 void brcms_c_update_probe_resp(struct brcms_c_info
*wlc
, bool suspend
)
7518 struct brcms_bss_cfg
*bsscfg
= wlc
->bsscfg
;
7520 /* update AP or IBSS probe responses */
7521 if (wlc
->pub
->up
&& (bsscfg
->type
== BRCMS_TYPE_AP
||
7522 bsscfg
->type
== BRCMS_TYPE_ADHOC
)) {
7523 if (!wlc
->probe_resp
)
7525 brcms_c_bss_update_probe_resp(wlc
, bsscfg
, wlc
->probe_resp
,
7530 int brcms_b_xmtfifo_sz_get(struct brcms_hardware
*wlc_hw
, uint fifo
,
7536 *blocks
= wlc_hw
->xmtfifo_sz
[fifo
];
7542 brcms_c_set_addrmatch(struct brcms_c_info
*wlc
, int match_reg_offset
,
7545 brcms_b_set_addrmatch(wlc
->hw
, match_reg_offset
, addr
);
7546 if (match_reg_offset
== RCM_BSSID_OFFSET
)
7547 memcpy(wlc
->bsscfg
->BSSID
, addr
, ETH_ALEN
);
7551 * Flag 'scan in progress' to withhold dynamic phy calibration
7553 void brcms_c_scan_start(struct brcms_c_info
*wlc
)
7555 wlc_phy_hold_upd(wlc
->band
->pi
, PHY_HOLD_FOR_SCAN
, true);
7558 void brcms_c_scan_stop(struct brcms_c_info
*wlc
)
7560 wlc_phy_hold_upd(wlc
->band
->pi
, PHY_HOLD_FOR_SCAN
, false);
7563 void brcms_c_associate_upd(struct brcms_c_info
*wlc
, bool state
)
7565 wlc
->pub
->associated
= state
;
7569 * When a remote STA/AP is removed by Mac80211, or when it can no longer accept
7570 * AMPDU traffic, packets pending in hardware have to be invalidated so that
7571 * when later on hardware releases them, they can be handled appropriately.
7573 void brcms_c_inval_dma_pkts(struct brcms_hardware
*hw
,
7574 struct ieee80211_sta
*sta
,
7575 void (*dma_callback_fn
))
7577 struct dma_pub
*dmah
;
7579 for (i
= 0; i
< NFIFO
; i
++) {
7582 dma_walk_packets(dmah
, dma_callback_fn
, sta
);
7586 int brcms_c_get_curband(struct brcms_c_info
*wlc
)
7588 return wlc
->band
->bandunit
;
7591 bool brcms_c_tx_flush_completed(struct brcms_c_info
*wlc
)
7595 /* Kick DMA to send any pending AMPDU */
7596 for (i
= 0; i
< ARRAY_SIZE(wlc
->hw
->di
); i
++)
7598 dma_kick_tx(wlc
->hw
->di
[i
]);
7600 return !brcms_txpktpendtot(wlc
);
7603 void brcms_c_set_beacon_listen_interval(struct brcms_c_info
*wlc
, u8 interval
)
7605 wlc
->bcn_li_bcn
= interval
;
7607 brcms_c_bcn_li_upd(wlc
);
7610 u64
brcms_c_tsf_get(struct brcms_c_info
*wlc
)
7615 brcms_b_read_tsf(wlc
->hw
, &tsf_l
, &tsf_h
);
7624 void brcms_c_tsf_set(struct brcms_c_info
*wlc
, u64 tsf
)
7628 brcms_c_time_lock(wlc
);
7631 tsf_h
= (tsf
>> 32);
7633 /* read the tsf timer low, then high to get an atomic read */
7634 bcma_write32(wlc
->hw
->d11core
, D11REGOFFS(tsf_timerlow
), tsf_l
);
7635 bcma_write32(wlc
->hw
->d11core
, D11REGOFFS(tsf_timerhigh
), tsf_h
);
7637 brcms_c_time_unlock(wlc
);
7640 int brcms_c_set_tx_power(struct brcms_c_info
*wlc
, int txpwr
)
7644 /* Remove override bit and clip to max qdbm value */
7645 qdbm
= min_t(uint
, txpwr
* BRCMS_TXPWR_DB_FACTOR
, 0xff);
7646 return wlc_phy_txpower_set(wlc
->band
->pi
, qdbm
, false);
7649 int brcms_c_get_tx_power(struct brcms_c_info
*wlc
)
7654 wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
, &override
);
7656 /* Return qdbm units */
7657 return (int)(qdbm
/ BRCMS_TXPWR_DB_FACTOR
);
7660 /* Process received frames */
7662 * Return true if more frames need to be processed. false otherwise.
7663 * Param 'bound' indicates max. # frames to process before break out.
7665 static void brcms_c_recv(struct brcms_c_info
*wlc
, struct sk_buff
*p
)
7667 struct d11rxhdr
*rxh
;
7668 struct ieee80211_hdr
*h
;
7672 /* frame starts with rxhdr */
7673 rxh
= (struct d11rxhdr
*) (p
->data
);
7675 /* strip off rxhdr */
7676 skb_pull(p
, BRCMS_HWRXOFF
);
7678 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7679 if (rxh
->RxStatus1
& RXS_PBPRES
) {
7681 brcms_err(wlc
->hw
->d11core
,
7682 "wl%d: recv: rcvd runt of len %d\n",
7683 wlc
->pub
->unit
, p
->len
);
7689 h
= (struct ieee80211_hdr
*)(p
->data
+ D11_PHY_HDR_LEN
);
7692 if (rxh
->RxStatus1
& RXS_FCSERR
) {
7693 if (!(wlc
->filter_flags
& FIF_FCSFAIL
))
7697 /* check received pkt has at least frame control field */
7698 if (len
< D11_PHY_HDR_LEN
+ sizeof(h
->frame_control
))
7701 /* not supporting A-MSDU */
7702 is_amsdu
= rxh
->RxStatus2
& RXS_AMSDU_MASK
;
7706 brcms_c_recvctl(wlc
, rxh
, p
);
7710 brcmu_pkt_buf_free_skb(p
);
7713 /* Process received frames */
7715 * Return true if more frames need to be processed. false otherwise.
7716 * Param 'bound' indicates max. # frames to process before break out.
7719 brcms_b_recv(struct brcms_hardware
*wlc_hw
, uint fifo
, bool bound
)
7722 struct sk_buff
*next
= NULL
;
7723 struct sk_buff_head recv_frames
;
7726 uint bound_limit
= bound
? RXBND
: -1;
7727 bool morepending
= false;
7729 skb_queue_head_init(&recv_frames
);
7731 /* gather received frames */
7733 /* !give others some time to run! */
7734 if (n
>= bound_limit
)
7737 morepending
= dma_rx(wlc_hw
->di
[fifo
], &recv_frames
);
7739 } while (morepending
);
7741 /* post more rbufs */
7742 dma_rxfill(wlc_hw
->di
[fifo
]);
7744 /* process each frame */
7745 skb_queue_walk_safe(&recv_frames
, p
, next
) {
7746 struct d11rxhdr_le
*rxh_le
;
7747 struct d11rxhdr
*rxh
;
7749 skb_unlink(p
, &recv_frames
);
7750 rxh_le
= (struct d11rxhdr_le
*)p
->data
;
7751 rxh
= (struct d11rxhdr
*)p
->data
;
7753 /* fixup rx header endianness */
7754 rxh
->RxFrameSize
= le16_to_cpu(rxh_le
->RxFrameSize
);
7755 rxh
->PhyRxStatus_0
= le16_to_cpu(rxh_le
->PhyRxStatus_0
);
7756 rxh
->PhyRxStatus_1
= le16_to_cpu(rxh_le
->PhyRxStatus_1
);
7757 rxh
->PhyRxStatus_2
= le16_to_cpu(rxh_le
->PhyRxStatus_2
);
7758 rxh
->PhyRxStatus_3
= le16_to_cpu(rxh_le
->PhyRxStatus_3
);
7759 rxh
->PhyRxStatus_4
= le16_to_cpu(rxh_le
->PhyRxStatus_4
);
7760 rxh
->PhyRxStatus_5
= le16_to_cpu(rxh_le
->PhyRxStatus_5
);
7761 rxh
->RxStatus1
= le16_to_cpu(rxh_le
->RxStatus1
);
7762 rxh
->RxStatus2
= le16_to_cpu(rxh_le
->RxStatus2
);
7763 rxh
->RxTSFTime
= le16_to_cpu(rxh_le
->RxTSFTime
);
7764 rxh
->RxChan
= le16_to_cpu(rxh_le
->RxChan
);
7766 brcms_c_recv(wlc_hw
->wlc
, p
);
7772 /* second-level interrupt processing
7773 * Return true if another dpc needs to be re-scheduled. false otherwise.
7774 * Param 'bounded' indicates if applicable loops should be bounded.
7776 bool brcms_c_dpc(struct brcms_c_info
*wlc
, bool bounded
)
7779 struct brcms_hardware
*wlc_hw
= wlc
->hw
;
7780 struct bcma_device
*core
= wlc_hw
->d11core
;
7782 if (brcms_deviceremoved(wlc
)) {
7783 brcms_err(core
, "wl%d: %s: dead chip\n", wlc_hw
->unit
,
7785 brcms_down(wlc
->wl
);
7789 /* grab and clear the saved software intstatus bits */
7790 macintstatus
= wlc
->macintstatus
;
7791 wlc
->macintstatus
= 0;
7793 brcms_dbg_int(core
, "wl%d: macintstatus 0x%x\n",
7794 wlc_hw
->unit
, macintstatus
);
7796 WARN_ON(macintstatus
& MI_PRQ
); /* PRQ Interrupt in non-MBSS */
7799 if (macintstatus
& MI_TFS
) {
7801 if (brcms_b_txstatus(wlc
->hw
, bounded
, &fatal
))
7802 wlc
->macintstatus
|= MI_TFS
;
7804 brcms_err(core
, "MI_TFS: fatal\n");
7809 if (macintstatus
& (MI_TBTT
| MI_DTIM_TBTT
))
7812 /* ATIM window end */
7813 if (macintstatus
& MI_ATIMWINEND
) {
7814 brcms_dbg_info(core
, "end of ATIM window\n");
7815 bcma_set32(core
, D11REGOFFS(maccommand
), wlc
->qvalid
);
7820 * received data or control frame, MI_DMAINT is
7821 * indication of RX_FIFO interrupt
7823 if (macintstatus
& MI_DMAINT
)
7824 if (brcms_b_recv(wlc_hw
, RX_FIFO
, bounded
))
7825 wlc
->macintstatus
|= MI_DMAINT
;
7827 /* noise sample collected */
7828 if (macintstatus
& MI_BG_NOISE
)
7829 wlc_phy_noise_sample_intr(wlc_hw
->band
->pi
);
7831 if (macintstatus
& MI_GP0
) {
7832 brcms_err(core
, "wl%d: PSM microcode watchdog fired at %d "
7833 "(seconds). Resetting.\n", wlc_hw
->unit
, wlc_hw
->now
);
7835 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
7836 __func__
, ai_get_chip_id(wlc_hw
->sih
),
7837 ai_get_chiprev(wlc_hw
->sih
));
7838 brcms_fatal_error(wlc_hw
->wlc
->wl
);
7841 /* gptimer timeout */
7842 if (macintstatus
& MI_TO
)
7843 bcma_write32(core
, D11REGOFFS(gptimer
), 0);
7845 if (macintstatus
& MI_RFDISABLE
) {
7846 brcms_dbg_info(core
, "wl%d: BMAC Detected a change on the"
7847 " RF Disable Input\n", wlc_hw
->unit
);
7848 brcms_rfkill_set_hw_state(wlc
->wl
);
7851 /* BCN template is available */
7852 if (macintstatus
& MI_BCNTPL
)
7853 brcms_c_update_beacon(wlc
);
7855 /* it isn't done and needs to be resched if macintstatus is non-zero */
7856 return wlc
->macintstatus
!= 0;
7859 brcms_fatal_error(wlc_hw
->wlc
->wl
);
7860 return wlc
->macintstatus
!= 0;
7863 void brcms_c_init(struct brcms_c_info
*wlc
, bool mute_tx
)
7865 struct bcma_device
*core
= wlc
->hw
->d11core
;
7866 struct ieee80211_channel
*ch
= wlc
->pub
->ieee_hw
->conf
.chandef
.chan
;
7869 brcms_dbg_info(core
, "wl%d\n", wlc
->pub
->unit
);
7871 chanspec
= ch20mhz_chspec(ch
->hw_value
);
7873 brcms_b_init(wlc
->hw
, chanspec
);
7875 /* update beacon listen interval */
7876 brcms_c_bcn_li_upd(wlc
);
7878 /* write ethernet address to core */
7879 brcms_c_set_mac(wlc
->bsscfg
);
7880 brcms_c_set_bssid(wlc
->bsscfg
);
7882 /* Update tsf_cfprep if associated and up */
7883 if (wlc
->pub
->associated
&& wlc
->pub
->up
) {
7886 /* get beacon period and convert to uS */
7887 bi
= wlc
->bsscfg
->current_bss
->beacon_period
<< 10;
7889 * update since init path would reset
7892 bcma_write32(core
, D11REGOFFS(tsf_cfprep
),
7893 bi
<< CFPREP_CBI_SHIFT
);
7895 /* Update maccontrol PM related bits */
7896 brcms_c_set_ps_ctrl(wlc
);
7899 brcms_c_bandinit_ordered(wlc
, chanspec
);
7901 /* init probe response timeout */
7902 brcms_b_write_shm(wlc
->hw
, M_PRS_MAXTIME
, wlc
->prb_resp_timeout
);
7904 /* init max burst txop (framebursting) */
7905 brcms_b_write_shm(wlc
->hw
, M_MBURST_TXOP
,
7907 _rifs
? (EDCF_AC_VO_TXOP_AP
<< 5) : MAXFRAMEBURST_TXOP
));
7909 /* initialize maximum allowed duty cycle */
7910 brcms_c_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_ofdm
, true, true);
7911 brcms_c_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_cck
, false, true);
7914 * Update some shared memory locations related to
7915 * max AMPDU size allowed to received
7917 brcms_c_ampdu_shm_upd(wlc
->ampdu
);
7919 /* band-specific inits */
7920 brcms_c_bsinit(wlc
);
7922 /* Enable EDCF mode (while the MAC is suspended) */
7923 bcma_set16(core
, D11REGOFFS(ifs_ctl
), IFS_USEEDCF
);
7924 brcms_c_edcf_setparams(wlc
, false);
7926 /* read the ucode version if we have not yet done so */
7927 if (wlc
->ucode_rev
== 0) {
7931 rev
= brcms_b_read_shm(wlc
->hw
, M_BOM_REV_MAJOR
);
7932 patch
= brcms_b_read_shm(wlc
->hw
, M_BOM_REV_MINOR
);
7933 wlc
->ucode_rev
= (rev
<< NBITS(u16
)) | patch
;
7934 snprintf(wlc
->wiphy
->fw_version
,
7935 sizeof(wlc
->wiphy
->fw_version
), "%u.%u", rev
, patch
);
7938 /* ..now really unleash hell (allow the MAC out of suspend) */
7939 brcms_c_enable_mac(wlc
);
7941 /* suspend the tx fifos and mute the phy for preism cac time */
7943 brcms_b_mute(wlc
->hw
, true);
7945 /* enable the RF Disable Delay timer */
7946 bcma_write32(core
, D11REGOFFS(rfdisabledly
), RFDISABLE_DEFAULT
);
7949 * Initialize WME parameters; if they haven't been set by some other
7950 * mechanism (IOVar, etc) then read them from the hardware.
7952 if (GFIELD(wlc
->wme_retries
[0], EDCF_SHORT
) == 0) {
7953 /* Uninitialized; read from HW */
7956 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
7957 wlc
->wme_retries
[ac
] =
7958 brcms_b_read_shm(wlc
->hw
, M_AC_TXLMT_ADDR(ac
));
7963 * The common driver entry routine. Error codes should be unique
7965 struct brcms_c_info
*
7966 brcms_c_attach(struct brcms_info
*wl
, struct bcma_device
*core
, uint unit
,
7967 bool piomode
, uint
*perr
)
7969 struct brcms_c_info
*wlc
;
7972 struct brcms_pub
*pub
;
7974 /* allocate struct brcms_c_info state and its substructures */
7975 wlc
= brcms_c_attach_malloc(unit
, &err
, 0);
7978 wlc
->wiphy
= wl
->wiphy
;
7985 wlc
->band
= wlc
->bandstate
[0];
7986 wlc
->core
= wlc
->corestate
;
7989 pub
->_piomode
= piomode
;
7990 wlc
->bandinit_pending
= false;
7991 wlc
->beacon_template_virgin
= true;
7993 /* populate struct brcms_c_info with default values */
7994 brcms_c_info_init(wlc
, unit
);
7996 /* update sta/ap related parameters */
7997 brcms_c_ap_upd(wlc
);
8000 * low level attach steps(all hw accesses go
8001 * inside, no more in rest of the attach)
8003 err
= brcms_b_attach(wlc
, core
, unit
, piomode
);
8007 brcms_c_protection_upd(wlc
, BRCMS_PROT_N_PAM_OVR
, OFF
);
8009 pub
->phy_11ncapable
= BRCMS_PHY_11N_CAP(wlc
->band
);
8011 /* disable allowed duty cycle */
8012 wlc
->tx_duty_cycle_ofdm
= 0;
8013 wlc
->tx_duty_cycle_cck
= 0;
8015 brcms_c_stf_phy_chain_calc(wlc
);
8017 /* txchain 1: txant 0, txchain 2: txant 1 */
8018 if (BRCMS_ISNPHY(wlc
->band
) && (wlc
->stf
->txstreams
== 1))
8019 wlc
->stf
->txant
= wlc
->stf
->hw_txchain
- 1;
8021 /* push to BMAC driver */
8022 wlc_phy_stf_chain_init(wlc
->band
->pi
, wlc
->stf
->hw_txchain
,
8023 wlc
->stf
->hw_rxchain
);
8025 /* pull up some info resulting from the low attach */
8026 for (i
= 0; i
< NFIFO
; i
++)
8027 wlc
->core
->txavail
[i
] = wlc
->hw
->txavail
[i
];
8029 memcpy(&wlc
->perm_etheraddr
, &wlc
->hw
->etheraddr
, ETH_ALEN
);
8030 memcpy(&pub
->cur_etheraddr
, &wlc
->hw
->etheraddr
, ETH_ALEN
);
8032 for (j
= 0; j
< wlc
->pub
->_nbands
; j
++) {
8033 wlc
->band
= wlc
->bandstate
[j
];
8035 if (!brcms_c_attach_stf_ant_init(wlc
)) {
8040 /* default contention windows size limits */
8041 wlc
->band
->CWmin
= APHY_CWMIN
;
8042 wlc
->band
->CWmax
= PHY_CWMAX
;
8044 /* init gmode value */
8045 if (wlc
->band
->bandtype
== BRCM_BAND_2G
) {
8046 wlc
->band
->gmode
= GMODE_AUTO
;
8047 brcms_c_protection_upd(wlc
, BRCMS_PROT_G_USER
,
8051 /* init _n_enab supported mode */
8052 if (BRCMS_PHY_11N_CAP(wlc
->band
)) {
8053 pub
->_n_enab
= SUPPORT_11N
;
8054 brcms_c_protection_upd(wlc
, BRCMS_PROT_N_USER
,
8056 SUPPORT_11N
) ? WL_11N_2x2
:
8060 /* init per-band default rateset, depend on band->gmode */
8061 brcms_default_rateset(wlc
, &wlc
->band
->defrateset
);
8063 /* fill in hw_rateset */
8064 brcms_c_rateset_filter(&wlc
->band
->defrateset
,
8065 &wlc
->band
->hw_rateset
, false,
8066 BRCMS_RATES_CCK_OFDM
, BRCMS_RATE_MASK
,
8067 (bool) (wlc
->pub
->_n_enab
& SUPPORT_11N
));
8071 * update antenna config due to
8072 * wlc->stf->txant/txchain/ant_rx_ovr change
8074 brcms_c_stf_phy_txant_upd(wlc
);
8076 /* attach each modules */
8077 err
= brcms_c_attach_module(wlc
);
8081 if (!brcms_c_timers_init(wlc
, unit
)) {
8082 wiphy_err(wl
->wiphy
, "wl%d: %s: init_timer failed\n", unit
,
8088 /* depend on rateset, gmode */
8089 wlc
->cmi
= brcms_c_channel_mgr_attach(wlc
);
8091 wiphy_err(wl
->wiphy
, "wl%d: %s: channel_mgr_attach failed"
8092 "\n", unit
, __func__
);
8097 /* init default when all parameters are ready, i.e. ->rateset */
8098 brcms_c_bss_default_init(wlc
);
8101 * Complete the wlc default state initializations..
8104 wlc
->bsscfg
->wlc
= wlc
;
8106 wlc
->mimoft
= FT_HT
;
8107 wlc
->mimo_40txbw
= AUTO
;
8108 wlc
->ofdm_40txbw
= AUTO
;
8109 wlc
->cck_40txbw
= AUTO
;
8110 brcms_c_update_mimo_band_bwcap(wlc
, BRCMS_N_BW_20IN2G_40IN5G
);
8112 /* Set default values of SGI */
8113 if (BRCMS_SGI_CAP_PHY(wlc
)) {
8114 brcms_c_ht_update_sgi_rx(wlc
, (BRCMS_N_SGI_20
|
8116 } else if (BRCMS_ISSSLPNPHY(wlc
->band
)) {
8117 brcms_c_ht_update_sgi_rx(wlc
, (BRCMS_N_SGI_20
|
8120 brcms_c_ht_update_sgi_rx(wlc
, 0);
8123 brcms_b_antsel_set(wlc
->hw
, wlc
->asi
->antsel_avail
);
8131 wiphy_err(wl
->wiphy
, "wl%d: %s: failed with err %d\n",
8132 unit
, __func__
, err
);
8134 brcms_c_detach(wlc
);