Commit | Line | Data |
---|---|---|
5b435de0 AS |
1 | /* |
2 | * Copyright (c) 2010 Broadcom Corporation | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | |
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
02f77195 JP |
17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
18 | ||
5b435de0 AS |
19 | #include <linux/pci_ids.h> |
20 | #include <linux/if_ether.h> | |
21 | #include <net/mac80211.h> | |
22 | #include <brcm_hw_ids.h> | |
23 | #include <aiutils.h> | |
24 | #include <chipcommon.h> | |
25 | #include "rate.h" | |
26 | #include "scb.h" | |
27 | #include "phy/phy_hal.h" | |
28 | #include "channel.h" | |
29 | #include "antsel.h" | |
30 | #include "stf.h" | |
31 | #include "ampdu.h" | |
32 | #include "mac80211_if.h" | |
33 | #include "ucode_loader.h" | |
34 | #include "main.h" | |
23038214 | 35 | #include "soc.h" |
5b435de0 AS |
36 | |
37 | /* | |
38 | * Indication for txflowcontrol that all priority bits in | |
39 | * TXQ_STOP_FOR_PRIOFC_MASK are to be considered. | |
40 | */ | |
73ffc2fc | 41 | #define ALLPRIO -1 |
5b435de0 AS |
42 | |
43 | /* watchdog timer, in unit of ms */ | |
73ffc2fc | 44 | #define TIMER_INTERVAL_WATCHDOG 1000 |
5b435de0 | 45 | /* radio monitor timer, in unit of ms */ |
73ffc2fc | 46 | #define TIMER_INTERVAL_RADIOCHK 800 |
5b435de0 | 47 | |
5b435de0 | 48 | /* beacon interval, in unit of 1024TU */ |
73ffc2fc | 49 | #define BEACON_INTERVAL_DEFAULT 100 |
5b435de0 AS |
50 | |
51 | /* n-mode support capability */ | |
52 | /* 2x2 includes both 1x1 & 2x2 devices | |
53 | * reserved #define 2 for future when we want to separate 1x1 & 2x2 and | |
54 | * control it independently | |
55 | */ | |
56 | #define WL_11N_2x2 1 | |
57 | #define WL_11N_3x3 3 | |
58 | #define WL_11N_4x4 4 | |
59 | ||
73ffc2fc AB |
60 | #define EDCF_ACI_MASK 0x60 |
61 | #define EDCF_ACI_SHIFT 5 | |
62 | #define EDCF_ECWMIN_MASK 0x0f | |
63 | #define EDCF_ECWMAX_SHIFT 4 | |
64 | #define EDCF_AIFSN_MASK 0x0f | |
65 | #define EDCF_AIFSN_MAX 15 | |
66 | #define EDCF_ECWMAX_MASK 0xf0 | |
67 | ||
68 | #define EDCF_AC_BE_TXOP_STA 0x0000 | |
69 | #define EDCF_AC_BK_TXOP_STA 0x0000 | |
70 | #define EDCF_AC_VO_ACI_STA 0x62 | |
71 | #define EDCF_AC_VO_ECW_STA 0x32 | |
72 | #define EDCF_AC_VI_ACI_STA 0x42 | |
73 | #define EDCF_AC_VI_ECW_STA 0x43 | |
74 | #define EDCF_AC_BK_ECW_STA 0xA4 | |
75 | #define EDCF_AC_VI_TXOP_STA 0x005e | |
76 | #define EDCF_AC_VO_TXOP_STA 0x002f | |
77 | #define EDCF_AC_BE_ACI_STA 0x03 | |
78 | #define EDCF_AC_BE_ECW_STA 0xA4 | |
79 | #define EDCF_AC_BK_ACI_STA 0x27 | |
80 | #define EDCF_AC_VO_TXOP_AP 0x002f | |
81 | ||
82 | #define EDCF_TXOP2USEC(txop) ((txop) << 5) | |
83 | #define EDCF_ECW2CW(exp) ((1 << (exp)) - 1) | |
84 | ||
85 | #define APHY_SYMBOL_TIME 4 | |
86 | #define APHY_PREAMBLE_TIME 16 | |
87 | #define APHY_SIGNAL_TIME 4 | |
88 | #define APHY_SIFS_TIME 16 | |
89 | #define APHY_SERVICE_NBITS 16 | |
90 | #define APHY_TAIL_NBITS 6 | |
91 | #define BPHY_SIFS_TIME 10 | |
92 | #define BPHY_PLCP_SHORT_TIME 96 | |
93 | ||
94 | #define PREN_PREAMBLE 24 | |
95 | #define PREN_MM_EXT 12 | |
96 | #define PREN_PREAMBLE_EXT 4 | |
5b435de0 AS |
97 | |
98 | #define DOT11_MAC_HDR_LEN 24 | |
73ffc2fc AB |
99 | #define DOT11_ACK_LEN 10 |
100 | #define DOT11_BA_LEN 4 | |
5b435de0 AS |
101 | #define DOT11_OFDM_SIGNAL_EXTENSION 6 |
102 | #define DOT11_MIN_FRAG_LEN 256 | |
73ffc2fc AB |
103 | #define DOT11_RTS_LEN 16 |
104 | #define DOT11_CTS_LEN 10 | |
5b435de0 AS |
105 | #define DOT11_BA_BITMAP_LEN 128 |
106 | #define DOT11_MIN_BEACON_PERIOD 1 | |
107 | #define DOT11_MAX_BEACON_PERIOD 0xFFFF | |
73ffc2fc | 108 | #define DOT11_MAXNUMFRAGS 16 |
5b435de0 AS |
109 | #define DOT11_MAX_FRAG_LEN 2346 |
110 | ||
73ffc2fc AB |
111 | #define BPHY_PLCP_TIME 192 |
112 | #define RIFS_11N_TIME 2 | |
5b435de0 | 113 | |
73ffc2fc AB |
114 | /* length of the BCN template area */ |
115 | #define BCN_TMPL_LEN 512 | |
5b435de0 AS |
116 | |
117 | /* brcms_bss_info flag bit values */ | |
73ffc2fc | 118 | #define BRCMS_BSS_HT 0x0020 /* BSS is HT (MIMO) capable */ |
5b435de0 | 119 | |
73ffc2fc AB |
120 | /* chip rx buffer offset */ |
121 | #define BRCMS_HWRXOFF 38 | |
5b435de0 AS |
122 | |
123 | /* rfdisable delay timer 500 ms, runs of ALP clock */ | |
73ffc2fc | 124 | #define RFDISABLE_DEFAULT 10000000 |
5b435de0 AS |
125 | |
126 | #define BRCMS_TEMPSENSE_PERIOD 10 /* 10 second timeout */ | |
127 | ||
128 | /* precedences numbers for wlc queues. These are twice as may levels as | |
129 | * 802.1D priorities. | |
130 | * Odd numbers are used for HI priority traffic at same precedence levels | |
131 | * These constants are used ONLY by wlc_prio2prec_map. Do not use them | |
132 | * elsewhere. | |
133 | */ | |
73ffc2fc AB |
134 | #define _BRCMS_PREC_NONE 0 /* None = - */ |
135 | #define _BRCMS_PREC_BK 2 /* BK - Background */ | |
136 | #define _BRCMS_PREC_BE 4 /* BE - Best-effort */ | |
137 | #define _BRCMS_PREC_EE 6 /* EE - Excellent-effort */ | |
138 | #define _BRCMS_PREC_CL 8 /* CL - Controlled Load */ | |
139 | #define _BRCMS_PREC_VI 10 /* Vi - Video */ | |
140 | #define _BRCMS_PREC_VO 12 /* Vo - Voice */ | |
141 | #define _BRCMS_PREC_NC 14 /* NC - Network Control */ | |
142 | ||
143 | /* synthpu_dly times in us */ | |
144 | #define SYNTHPU_DLY_APHY_US 3700 | |
145 | #define SYNTHPU_DLY_BPHY_US 1050 | |
146 | #define SYNTHPU_DLY_NPHY_US 2048 | |
147 | #define SYNTHPU_DLY_LPPHY_US 300 | |
148 | ||
149 | #define ANTCNT 10 /* vanilla M_MAX_ANTCNT val */ | |
5b435de0 AS |
150 | |
151 | /* Per-AC retry limit register definitions; uses defs.h bitfield macros */ | |
73ffc2fc AB |
152 | #define EDCF_SHORT_S 0 |
153 | #define EDCF_SFB_S 4 | |
154 | #define EDCF_LONG_S 8 | |
155 | #define EDCF_LFB_S 12 | |
156 | #define EDCF_SHORT_M BITFIELD_MASK(4) | |
157 | #define EDCF_SFB_M BITFIELD_MASK(4) | |
158 | #define EDCF_LONG_M BITFIELD_MASK(4) | |
159 | #define EDCF_LFB_M BITFIELD_MASK(4) | |
5b435de0 | 160 | |
73ffc2fc AB |
161 | #define RETRY_SHORT_DEF 7 /* Default Short retry Limit */ |
162 | #define RETRY_SHORT_MAX 255 /* Maximum Short retry Limit */ | |
163 | #define RETRY_LONG_DEF 4 /* Default Long retry count */ | |
164 | #define RETRY_SHORT_FB 3 /* Short count for fb rate */ | |
165 | #define RETRY_LONG_FB 2 /* Long count for fb rate */ | |
5b435de0 | 166 | |
73ffc2fc AB |
167 | #define APHY_CWMIN 15 |
168 | #define PHY_CWMAX 1023 | |
5b435de0 | 169 | |
73ffc2fc | 170 | #define EDCF_AIFSN_MIN 1 |
5b435de0 | 171 | |
73ffc2fc | 172 | #define FRAGNUM_MASK 0xF |
5b435de0 | 173 | |
73ffc2fc AB |
174 | #define APHY_SLOT_TIME 9 |
175 | #define BPHY_SLOT_TIME 20 | |
5b435de0 | 176 | |
73ffc2fc AB |
177 | #define WL_SPURAVOID_OFF 0 |
178 | #define WL_SPURAVOID_ON1 1 | |
179 | #define WL_SPURAVOID_ON2 2 | |
5b435de0 AS |
180 | |
181 | /* invalid core flags, use the saved coreflags */ | |
73ffc2fc | 182 | #define BRCMS_USE_COREFLAGS 0xffffffff |
5b435de0 AS |
183 | |
184 | /* values for PLCPHdr_override */ | |
73ffc2fc AB |
185 | #define BRCMS_PLCP_AUTO -1 |
186 | #define BRCMS_PLCP_SHORT 0 | |
187 | #define BRCMS_PLCP_LONG 1 | |
5b435de0 AS |
188 | |
189 | /* values for g_protection_override and n_protection_override */ | |
190 | #define BRCMS_PROTECTION_AUTO -1 | |
191 | #define BRCMS_PROTECTION_OFF 0 | |
192 | #define BRCMS_PROTECTION_ON 1 | |
193 | #define BRCMS_PROTECTION_MMHDR_ONLY 2 | |
73ffc2fc | 194 | #define BRCMS_PROTECTION_CTS_ONLY 3 |
5b435de0 AS |
195 | |
196 | /* values for g_protection_control and n_protection_control */ | |
73ffc2fc | 197 | #define BRCMS_PROTECTION_CTL_OFF 0 |
5b435de0 AS |
198 | #define BRCMS_PROTECTION_CTL_LOCAL 1 |
199 | #define BRCMS_PROTECTION_CTL_OVERLAP 2 | |
200 | ||
201 | /* values for n_protection */ | |
202 | #define BRCMS_N_PROTECTION_OFF 0 | |
203 | #define BRCMS_N_PROTECTION_OPTIONAL 1 | |
73ffc2fc | 204 | #define BRCMS_N_PROTECTION_20IN40 2 |
5b435de0 AS |
205 | #define BRCMS_N_PROTECTION_MIXEDMODE 3 |
206 | ||
207 | /* values for band specific 40MHz capabilities */ | |
73ffc2fc AB |
208 | #define BRCMS_N_BW_20ALL 0 |
209 | #define BRCMS_N_BW_40ALL 1 | |
210 | #define BRCMS_N_BW_20IN2G_40IN5G 2 | |
5b435de0 AS |
211 | |
212 | /* bitflags for SGI support (sgi_rx iovar) */ | |
213 | #define BRCMS_N_SGI_20 0x01 | |
214 | #define BRCMS_N_SGI_40 0x02 | |
215 | ||
216 | /* defines used by the nrate iovar */ | |
217 | /* MSC in use,indicates b0-6 holds an mcs */ | |
73ffc2fc | 218 | #define NRATE_MCS_INUSE 0x00000080 |
5b435de0 | 219 | /* rate/mcs value */ |
73ffc2fc | 220 | #define NRATE_RATE_MASK 0x0000007f |
5b435de0 | 221 | /* stf mode mask: siso, cdd, stbc, sdm */ |
73ffc2fc | 222 | #define NRATE_STF_MASK 0x0000ff00 |
5b435de0 | 223 | /* stf mode shift */ |
73ffc2fc | 224 | #define NRATE_STF_SHIFT 8 |
5b435de0 | 225 | /* bit indicate to override mcs only */ |
73ffc2fc AB |
226 | #define NRATE_OVERRIDE_MCS_ONLY 0x40000000 |
227 | #define NRATE_SGI_MASK 0x00800000 /* sgi mode */ | |
228 | #define NRATE_SGI_SHIFT 23 /* sgi mode */ | |
229 | #define NRATE_LDPC_CODING 0x00400000 /* adv coding in use */ | |
230 | #define NRATE_LDPC_SHIFT 22 /* ldpc shift */ | |
5b435de0 | 231 | |
73ffc2fc AB |
232 | #define NRATE_STF_SISO 0 /* stf mode SISO */ |
233 | #define NRATE_STF_CDD 1 /* stf mode CDD */ | |
234 | #define NRATE_STF_STBC 2 /* stf mode STBC */ | |
235 | #define NRATE_STF_SDM 3 /* stf mode SDM */ | |
5b435de0 | 236 | |
73ffc2fc | 237 | #define MAX_DMA_SEGS 4 |
5b435de0 AS |
238 | |
239 | /* Max # of entries in Tx FIFO based on 4kb page size */ | |
73ffc2fc | 240 | #define NTXD 256 |
5b435de0 | 241 | /* Max # of entries in Rx FIFO based on 4kb page size */ |
73ffc2fc | 242 | #define NRXD 256 |
5b435de0 AS |
243 | |
244 | /* try to keep this # rbufs posted to the chip */ | |
73ffc2fc | 245 | #define NRXBUFPOST 32 |
5b435de0 AS |
246 | |
247 | /* data msg txq hiwat mark */ | |
73ffc2fc | 248 | #define BRCMS_DATAHIWAT 50 |
5b435de0 | 249 | |
73ffc2fc AB |
250 | /* max # frames to process in brcms_c_recv() */ |
251 | #define RXBND 8 | |
252 | /* max # tx status to process in wlc_txstatus() */ | |
253 | #define TXSBND 8 | |
5b435de0 | 254 | |
44760651 AB |
255 | /* brcmu_format_flags() bit description structure */ |
256 | struct brcms_c_bit_desc { | |
257 | u32 bit; | |
258 | const char *name; | |
259 | }; | |
260 | ||
5b435de0 AS |
261 | /* |
262 | * The following table lists the buffer memory allocated to xmt fifos in HW. | |
263 | * the size is in units of 256bytes(one block), total size is HW dependent | |
264 | * ucode has default fifo partition, sw can overwrite if necessary | |
265 | * | |
266 | * This is documented in twiki under the topic UcodeTxFifo. Please ensure | |
267 | * the twiki is updated before making changes. | |
268 | */ | |
269 | ||
270 | /* Starting corerev for the fifo size table */ | |
271 | #define XMTFIFOTBL_STARTREV 20 | |
272 | ||
273 | struct d11init { | |
274 | __le16 addr; | |
275 | __le16 size; | |
276 | __le32 value; | |
277 | }; | |
278 | ||
5b435de0 AS |
279 | struct edcf_acparam { |
280 | u8 ACI; | |
281 | u8 ECW; | |
282 | u16 TXOP; | |
283 | } __packed; | |
284 | ||
285 | const u8 prio2fifo[NUMPRIO] = { | |
286 | TX_AC_BE_FIFO, /* 0 BE AC_BE Best Effort */ | |
287 | TX_AC_BK_FIFO, /* 1 BK AC_BK Background */ | |
288 | TX_AC_BK_FIFO, /* 2 -- AC_BK Background */ | |
289 | TX_AC_BE_FIFO, /* 3 EE AC_BE Best Effort */ | |
290 | TX_AC_VI_FIFO, /* 4 CL AC_VI Video */ | |
291 | TX_AC_VI_FIFO, /* 5 VI AC_VI Video */ | |
292 | TX_AC_VO_FIFO, /* 6 VO AC_VO Voice */ | |
293 | TX_AC_VO_FIFO /* 7 NC AC_VO Voice */ | |
294 | }; | |
295 | ||
296 | /* debug/trace */ | |
297 | uint brcm_msg_level = | |
8ae74654 | 298 | #if defined(DEBUG) |
5b435de0 AS |
299 | LOG_ERROR_VAL; |
300 | #else | |
301 | 0; | |
8ae74654 | 302 | #endif /* DEBUG */ |
5b435de0 AS |
303 | |
304 | /* TX FIFO number to WME/802.1E Access Category */ | |
b7eec423 AS |
305 | static const u8 wme_fifo2ac[] = { |
306 | IEEE80211_AC_BK, | |
307 | IEEE80211_AC_BE, | |
308 | IEEE80211_AC_VI, | |
309 | IEEE80211_AC_VO, | |
310 | IEEE80211_AC_BE, | |
311 | IEEE80211_AC_BE | |
312 | }; | |
5b435de0 | 313 | |
b7eec423 AS |
314 | /* ieee80211 Access Category to TX FIFO number */ |
315 | static const u8 wme_ac2fifo[] = { | |
316 | TX_AC_VO_FIFO, | |
317 | TX_AC_VI_FIFO, | |
318 | TX_AC_BE_FIFO, | |
319 | TX_AC_BK_FIFO | |
320 | }; | |
5b435de0 AS |
321 | |
322 | /* 802.1D Priority to precedence queue mapping */ | |
323 | const u8 wlc_prio2prec_map[] = { | |
324 | _BRCMS_PREC_BE, /* 0 BE - Best-effort */ | |
325 | _BRCMS_PREC_BK, /* 1 BK - Background */ | |
326 | _BRCMS_PREC_NONE, /* 2 None = - */ | |
327 | _BRCMS_PREC_EE, /* 3 EE - Excellent-effort */ | |
328 | _BRCMS_PREC_CL, /* 4 CL - Controlled Load */ | |
329 | _BRCMS_PREC_VI, /* 5 Vi - Video */ | |
330 | _BRCMS_PREC_VO, /* 6 Vo - Voice */ | |
331 | _BRCMS_PREC_NC, /* 7 NC - Network Control */ | |
332 | }; | |
333 | ||
334 | static const u16 xmtfifo_sz[][NFIFO] = { | |
335 | /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */ | |
336 | {20, 192, 192, 21, 17, 5}, | |
337 | /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */ | |
338 | {9, 58, 22, 14, 14, 5}, | |
339 | /* corerev 22: 5120, 49152, 49152, 5376, 4352, 1280 */ | |
340 | {20, 192, 192, 21, 17, 5}, | |
341 | /* corerev 23: 5120, 49152, 49152, 5376, 4352, 1280 */ | |
342 | {20, 192, 192, 21, 17, 5}, | |
343 | /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */ | |
344 | {9, 58, 22, 14, 14, 5}, | |
345 | }; | |
346 | ||
8ae74654 | 347 | #ifdef DEBUG |
5b435de0 AS |
348 | static const char * const fifo_names[] = { |
349 | "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" }; | |
350 | #else | |
351 | static const char fifo_names[6][0]; | |
352 | #endif | |
353 | ||
8ae74654 | 354 | #ifdef DEBUG |
5b435de0 AS |
355 | /* pointer to most recently allocated wl/wlc */ |
356 | static struct brcms_c_info *wlc_info_dbg = (struct brcms_c_info *) (NULL); | |
357 | #endif | |
358 | ||
73ffc2fc AB |
359 | /* Find basic rate for a given rate */ |
360 | static u8 brcms_basic_rate(struct brcms_c_info *wlc, u32 rspec) | |
361 | { | |
362 | if (is_mcs_rate(rspec)) | |
363 | return wlc->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK] | |
364 | .leg_ofdm]; | |
365 | return wlc->band->basic_rate[rspec & RSPEC_RATE_MASK]; | |
366 | } | |
367 | ||
368 | static u16 frametype(u32 rspec, u8 mimoframe) | |
369 | { | |
370 | if (is_mcs_rate(rspec)) | |
371 | return mimoframe; | |
372 | return is_cck_rate(rspec) ? FT_CCK : FT_OFDM; | |
373 | } | |
374 | ||
94bdc2a2 AB |
375 | /* currently the best mechanism for determining SIFS is the band in use */ |
376 | static u16 get_sifs(struct brcms_band *band) | |
377 | { | |
378 | return band->bandtype == BRCM_BAND_5G ? APHY_SIFS_TIME : | |
379 | BPHY_SIFS_TIME; | |
380 | } | |
381 | ||
382 | /* | |
383 | * Detect Card removed. | |
384 | * Even checking an sbconfig register read will not false trigger when the core | |
385 | * is in reset it breaks CF address mechanism. Accessing gphy phyversion will | |
386 | * cause SB error if aphy is in reset on 4306B0-DB. Need a simple accessible | |
387 | * reg with fixed 0/1 pattern (some platforms return all 0). | |
388 | * If clocks are present, call the sb routine which will figure out if the | |
389 | * device is removed. | |
390 | */ | |
391 | static bool brcms_deviceremoved(struct brcms_c_info *wlc) | |
392 | { | |
16d2812e AS |
393 | u32 macctrl; |
394 | ||
94bdc2a2 AB |
395 | if (!wlc->hw->clk) |
396 | return ai_deviceremoved(wlc->hw->sih); | |
16d2812e AS |
397 | macctrl = bcma_read32(wlc->hw->d11core, |
398 | D11REGOFFS(maccontrol)); | |
399 | return (macctrl & (MCTL_PSM_JMP_0 | MCTL_IHR_EN)) != MCTL_IHR_EN; | |
94bdc2a2 AB |
400 | } |
401 | ||
402 | /* sum the individual fifo tx pending packet counts */ | |
403 | static s16 brcms_txpktpendtot(struct brcms_c_info *wlc) | |
404 | { | |
405 | return wlc->core->txpktpend[0] + wlc->core->txpktpend[1] + | |
406 | wlc->core->txpktpend[2] + wlc->core->txpktpend[3]; | |
407 | } | |
408 | ||
409 | static bool brcms_is_mband_unlocked(struct brcms_c_info *wlc) | |
410 | { | |
411 | return wlc->pub->_nbands > 1 && !wlc->bandlocked; | |
412 | } | |
413 | ||
414 | static int brcms_chspec_bw(u16 chanspec) | |
415 | { | |
416 | if (CHSPEC_IS40(chanspec)) | |
417 | return BRCMS_40_MHZ; | |
418 | if (CHSPEC_IS20(chanspec)) | |
419 | return BRCMS_20_MHZ; | |
420 | ||
421 | return BRCMS_10_MHZ; | |
422 | } | |
423 | ||
5b435de0 AS |
424 | static void brcms_c_bsscfg_mfree(struct brcms_bss_cfg *cfg) |
425 | { | |
426 | if (cfg == NULL) | |
427 | return; | |
428 | ||
429 | kfree(cfg->current_bss); | |
430 | kfree(cfg); | |
431 | } | |
432 | ||
433 | static void brcms_c_detach_mfree(struct brcms_c_info *wlc) | |
434 | { | |
435 | if (wlc == NULL) | |
436 | return; | |
437 | ||
438 | brcms_c_bsscfg_mfree(wlc->bsscfg); | |
439 | kfree(wlc->pub); | |
440 | kfree(wlc->modulecb); | |
441 | kfree(wlc->default_bss); | |
442 | kfree(wlc->protection); | |
443 | kfree(wlc->stf); | |
444 | kfree(wlc->bandstate[0]); | |
445 | kfree(wlc->corestate->macstat_snapshot); | |
446 | kfree(wlc->corestate); | |
447 | kfree(wlc->hw->bandstate[0]); | |
448 | kfree(wlc->hw); | |
449 | ||
450 | /* free the wlc */ | |
451 | kfree(wlc); | |
452 | wlc = NULL; | |
453 | } | |
454 | ||
455 | static struct brcms_bss_cfg *brcms_c_bsscfg_malloc(uint unit) | |
456 | { | |
457 | struct brcms_bss_cfg *cfg; | |
458 | ||
459 | cfg = kzalloc(sizeof(struct brcms_bss_cfg), GFP_ATOMIC); | |
460 | if (cfg == NULL) | |
461 | goto fail; | |
462 | ||
463 | cfg->current_bss = kzalloc(sizeof(struct brcms_bss_info), GFP_ATOMIC); | |
464 | if (cfg->current_bss == NULL) | |
465 | goto fail; | |
466 | ||
467 | return cfg; | |
468 | ||
469 | fail: | |
470 | brcms_c_bsscfg_mfree(cfg); | |
471 | return NULL; | |
472 | } | |
473 | ||
474 | static struct brcms_c_info * | |
475 | brcms_c_attach_malloc(uint unit, uint *err, uint devid) | |
476 | { | |
477 | struct brcms_c_info *wlc; | |
478 | ||
479 | wlc = kzalloc(sizeof(struct brcms_c_info), GFP_ATOMIC); | |
480 | if (wlc == NULL) { | |
481 | *err = 1002; | |
482 | goto fail; | |
483 | } | |
484 | ||
485 | /* allocate struct brcms_c_pub state structure */ | |
486 | wlc->pub = kzalloc(sizeof(struct brcms_pub), GFP_ATOMIC); | |
487 | if (wlc->pub == NULL) { | |
488 | *err = 1003; | |
489 | goto fail; | |
490 | } | |
491 | wlc->pub->wlc = wlc; | |
492 | ||
493 | /* allocate struct brcms_hardware state structure */ | |
494 | ||
495 | wlc->hw = kzalloc(sizeof(struct brcms_hardware), GFP_ATOMIC); | |
496 | if (wlc->hw == NULL) { | |
497 | *err = 1005; | |
498 | goto fail; | |
499 | } | |
500 | wlc->hw->wlc = wlc; | |
501 | ||
502 | wlc->hw->bandstate[0] = | |
503 | kzalloc(sizeof(struct brcms_hw_band) * MAXBANDS, GFP_ATOMIC); | |
504 | if (wlc->hw->bandstate[0] == NULL) { | |
505 | *err = 1006; | |
506 | goto fail; | |
507 | } else { | |
508 | int i; | |
509 | ||
510 | for (i = 1; i < MAXBANDS; i++) | |
511 | wlc->hw->bandstate[i] = (struct brcms_hw_band *) | |
512 | ((unsigned long)wlc->hw->bandstate[0] + | |
513 | (sizeof(struct brcms_hw_band) * i)); | |
514 | } | |
515 | ||
516 | wlc->modulecb = | |
517 | kzalloc(sizeof(struct modulecb) * BRCMS_MAXMODULES, GFP_ATOMIC); | |
518 | if (wlc->modulecb == NULL) { | |
519 | *err = 1009; | |
520 | goto fail; | |
521 | } | |
522 | ||
523 | wlc->default_bss = kzalloc(sizeof(struct brcms_bss_info), GFP_ATOMIC); | |
524 | if (wlc->default_bss == NULL) { | |
525 | *err = 1010; | |
526 | goto fail; | |
527 | } | |
528 | ||
529 | wlc->bsscfg = brcms_c_bsscfg_malloc(unit); | |
530 | if (wlc->bsscfg == NULL) { | |
531 | *err = 1011; | |
532 | goto fail; | |
533 | } | |
534 | ||
535 | wlc->protection = kzalloc(sizeof(struct brcms_protection), | |
536 | GFP_ATOMIC); | |
537 | if (wlc->protection == NULL) { | |
538 | *err = 1016; | |
539 | goto fail; | |
540 | } | |
541 | ||
542 | wlc->stf = kzalloc(sizeof(struct brcms_stf), GFP_ATOMIC); | |
543 | if (wlc->stf == NULL) { | |
544 | *err = 1017; | |
545 | goto fail; | |
546 | } | |
547 | ||
548 | wlc->bandstate[0] = | |
549 | kzalloc(sizeof(struct brcms_band)*MAXBANDS, GFP_ATOMIC); | |
550 | if (wlc->bandstate[0] == NULL) { | |
551 | *err = 1025; | |
552 | goto fail; | |
553 | } else { | |
554 | int i; | |
555 | ||
556 | for (i = 1; i < MAXBANDS; i++) | |
557 | wlc->bandstate[i] = (struct brcms_band *) | |
558 | ((unsigned long)wlc->bandstate[0] | |
559 | + (sizeof(struct brcms_band)*i)); | |
560 | } | |
561 | ||
562 | wlc->corestate = kzalloc(sizeof(struct brcms_core), GFP_ATOMIC); | |
563 | if (wlc->corestate == NULL) { | |
564 | *err = 1026; | |
565 | goto fail; | |
566 | } | |
567 | ||
568 | wlc->corestate->macstat_snapshot = | |
569 | kzalloc(sizeof(struct macstat), GFP_ATOMIC); | |
570 | if (wlc->corestate->macstat_snapshot == NULL) { | |
571 | *err = 1027; | |
572 | goto fail; | |
573 | } | |
574 | ||
575 | return wlc; | |
576 | ||
577 | fail: | |
578 | brcms_c_detach_mfree(wlc); | |
579 | return NULL; | |
580 | } | |
581 | ||
582 | /* | |
583 | * Update the slot timing for standard 11b/g (20us slots) | |
584 | * or shortslot 11g (9us slots) | |
585 | * The PSM needs to be suspended for this call. | |
586 | */ | |
587 | static void brcms_b_update_slot_timing(struct brcms_hardware *wlc_hw, | |
588 | bool shortslot) | |
589 | { | |
16d2812e | 590 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
591 | |
592 | if (shortslot) { | |
593 | /* 11g short slot: 11a timing */ | |
16d2812e | 594 | bcma_write16(core, D11REGOFFS(ifs_slot), 0x0207); |
5b435de0 AS |
595 | brcms_b_write_shm(wlc_hw, M_DOT11_SLOT, APHY_SLOT_TIME); |
596 | } else { | |
597 | /* 11g long slot: 11b timing */ | |
16d2812e | 598 | bcma_write16(core, D11REGOFFS(ifs_slot), 0x0212); |
5b435de0 AS |
599 | brcms_b_write_shm(wlc_hw, M_DOT11_SLOT, BPHY_SLOT_TIME); |
600 | } | |
601 | } | |
602 | ||
94bdc2a2 AB |
603 | /* |
604 | * calculate frame duration of a given rate and length, return | |
605 | * time in usec unit | |
606 | */ | |
094b199b AS |
607 | static uint brcms_c_calc_frame_time(struct brcms_c_info *wlc, u32 ratespec, |
608 | u8 preamble_type, uint mac_len) | |
94bdc2a2 AB |
609 | { |
610 | uint nsyms, dur = 0, Ndps, kNdps; | |
611 | uint rate = rspec2rate(ratespec); | |
612 | ||
613 | if (rate == 0) { | |
614 | wiphy_err(wlc->wiphy, "wl%d: WAR: using rate of 1 mbps\n", | |
615 | wlc->pub->unit); | |
616 | rate = BRCM_RATE_1M; | |
617 | } | |
618 | ||
619 | BCMMSG(wlc->wiphy, "wl%d: rspec 0x%x, preamble_type %d, len%d\n", | |
620 | wlc->pub->unit, ratespec, preamble_type, mac_len); | |
621 | ||
622 | if (is_mcs_rate(ratespec)) { | |
623 | uint mcs = ratespec & RSPEC_RATE_MASK; | |
624 | int tot_streams = mcs_2_txstreams(mcs) + rspec_stc(ratespec); | |
625 | ||
626 | dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT); | |
627 | if (preamble_type == BRCMS_MM_PREAMBLE) | |
628 | dur += PREN_MM_EXT; | |
629 | /* 1000Ndbps = kbps * 4 */ | |
630 | kNdps = mcs_2_rate(mcs, rspec_is40mhz(ratespec), | |
631 | rspec_issgi(ratespec)) * 4; | |
632 | ||
633 | if (rspec_stc(ratespec) == 0) | |
634 | nsyms = | |
635 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + | |
636 | APHY_TAIL_NBITS) * 1000, kNdps); | |
637 | else | |
638 | /* STBC needs to have even number of symbols */ | |
639 | nsyms = | |
640 | 2 * | |
641 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + | |
642 | APHY_TAIL_NBITS) * 1000, 2 * kNdps); | |
643 | ||
644 | dur += APHY_SYMBOL_TIME * nsyms; | |
645 | if (wlc->band->bandtype == BRCM_BAND_2G) | |
646 | dur += DOT11_OFDM_SIGNAL_EXTENSION; | |
647 | } else if (is_ofdm_rate(rate)) { | |
648 | dur = APHY_PREAMBLE_TIME; | |
649 | dur += APHY_SIGNAL_TIME; | |
650 | /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */ | |
651 | Ndps = rate * 2; | |
652 | /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */ | |
653 | nsyms = | |
654 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS), | |
655 | Ndps); | |
656 | dur += APHY_SYMBOL_TIME * nsyms; | |
657 | if (wlc->band->bandtype == BRCM_BAND_2G) | |
658 | dur += DOT11_OFDM_SIGNAL_EXTENSION; | |
659 | } else { | |
660 | /* | |
661 | * calc # bits * 2 so factor of 2 in rate (1/2 mbps) | |
662 | * will divide out | |
663 | */ | |
664 | mac_len = mac_len * 8 * 2; | |
665 | /* calc ceiling of bits/rate = microseconds of air time */ | |
666 | dur = (mac_len + rate - 1) / rate; | |
667 | if (preamble_type & BRCMS_SHORT_PREAMBLE) | |
668 | dur += BPHY_PLCP_SHORT_TIME; | |
669 | else | |
670 | dur += BPHY_PLCP_TIME; | |
671 | } | |
672 | return dur; | |
673 | } | |
674 | ||
5b435de0 AS |
675 | static void brcms_c_write_inits(struct brcms_hardware *wlc_hw, |
676 | const struct d11init *inits) | |
677 | { | |
16d2812e | 678 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 | 679 | int i; |
16d2812e | 680 | uint offset; |
5b435de0 AS |
681 | u16 size; |
682 | u32 value; | |
683 | ||
684 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
685 | ||
5b435de0 AS |
686 | for (i = 0; inits[i].addr != cpu_to_le16(0xffff); i++) { |
687 | size = le16_to_cpu(inits[i].size); | |
16d2812e | 688 | offset = le16_to_cpu(inits[i].addr); |
5b435de0 AS |
689 | value = le32_to_cpu(inits[i].value); |
690 | if (size == 2) | |
16d2812e | 691 | bcma_write16(core, offset, value); |
5b435de0 | 692 | else if (size == 4) |
16d2812e | 693 | bcma_write32(core, offset, value); |
5b435de0 AS |
694 | else |
695 | break; | |
696 | } | |
697 | } | |
698 | ||
699 | static void brcms_c_write_mhf(struct brcms_hardware *wlc_hw, u16 *mhfs) | |
700 | { | |
701 | u8 idx; | |
702 | u16 addr[] = { | |
703 | M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4, | |
704 | M_HOST_FLAGS5 | |
705 | }; | |
706 | ||
707 | for (idx = 0; idx < MHFMAX; idx++) | |
708 | brcms_b_write_shm(wlc_hw, addr[idx], mhfs[idx]); | |
709 | } | |
710 | ||
711 | static void brcms_c_ucode_bsinit(struct brcms_hardware *wlc_hw) | |
712 | { | |
713 | struct wiphy *wiphy = wlc_hw->wlc->wiphy; | |
714 | struct brcms_ucode *ucode = &wlc_hw->wlc->wl->ucode; | |
715 | ||
716 | /* init microcode host flags */ | |
717 | brcms_c_write_mhf(wlc_hw, wlc_hw->band->mhfs); | |
718 | ||
719 | /* do band-specific ucode IHR, SHM, and SCR inits */ | |
720 | if (D11REV_IS(wlc_hw->corerev, 23)) { | |
721 | if (BRCMS_ISNPHY(wlc_hw->band)) | |
722 | brcms_c_write_inits(wlc_hw, ucode->d11n0bsinitvals16); | |
723 | else | |
724 | wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev" | |
725 | " %d\n", __func__, wlc_hw->unit, | |
726 | wlc_hw->corerev); | |
727 | } else { | |
728 | if (D11REV_IS(wlc_hw->corerev, 24)) { | |
729 | if (BRCMS_ISLCNPHY(wlc_hw->band)) | |
730 | brcms_c_write_inits(wlc_hw, | |
731 | ucode->d11lcn0bsinitvals24); | |
732 | else | |
733 | wiphy_err(wiphy, "%s: wl%d: unsupported phy in" | |
734 | " core rev %d\n", __func__, | |
735 | wlc_hw->unit, wlc_hw->corerev); | |
736 | } else { | |
737 | wiphy_err(wiphy, "%s: wl%d: unsupported corerev %d\n", | |
738 | __func__, wlc_hw->unit, wlc_hw->corerev); | |
739 | } | |
740 | } | |
741 | } | |
742 | ||
a8779e4a AS |
743 | static void brcms_b_core_ioctl(struct brcms_hardware *wlc_hw, u32 m, u32 v) |
744 | { | |
745 | struct bcma_device *core = wlc_hw->d11core; | |
746 | u32 ioctl = bcma_aread32(core, BCMA_IOCTL) & ~m; | |
747 | ||
748 | bcma_awrite32(core, BCMA_IOCTL, ioctl | v); | |
749 | } | |
750 | ||
5b435de0 AS |
751 | static void brcms_b_core_phy_clk(struct brcms_hardware *wlc_hw, bool clk) |
752 | { | |
753 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d: clk %d\n", wlc_hw->unit, clk); | |
754 | ||
755 | wlc_hw->phyclk = clk; | |
756 | ||
757 | if (OFF == clk) { /* clear gmode bit, put phy into reset */ | |
758 | ||
a8779e4a AS |
759 | brcms_b_core_ioctl(wlc_hw, (SICF_PRST | SICF_FGC | SICF_GMODE), |
760 | (SICF_PRST | SICF_FGC)); | |
5b435de0 | 761 | udelay(1); |
a8779e4a | 762 | brcms_b_core_ioctl(wlc_hw, (SICF_PRST | SICF_FGC), SICF_PRST); |
5b435de0 AS |
763 | udelay(1); |
764 | ||
765 | } else { /* take phy out of reset */ | |
766 | ||
a8779e4a | 767 | brcms_b_core_ioctl(wlc_hw, (SICF_PRST | SICF_FGC), SICF_FGC); |
5b435de0 | 768 | udelay(1); |
a8779e4a | 769 | brcms_b_core_ioctl(wlc_hw, SICF_FGC, 0); |
5b435de0 AS |
770 | udelay(1); |
771 | ||
772 | } | |
773 | } | |
774 | ||
94bdc2a2 AB |
775 | /* low-level band switch utility routine */ |
776 | static void brcms_c_setxband(struct brcms_hardware *wlc_hw, uint bandunit) | |
777 | { | |
778 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit, | |
779 | bandunit); | |
780 | ||
781 | wlc_hw->band = wlc_hw->bandstate[bandunit]; | |
782 | ||
783 | /* | |
784 | * BMAC_NOTE: | |
785 | * until we eliminate need for wlc->band refs in low level code | |
786 | */ | |
787 | wlc_hw->wlc->band = wlc_hw->wlc->bandstate[bandunit]; | |
788 | ||
789 | /* set gmode core flag */ | |
a8779e4a AS |
790 | if (wlc_hw->sbclk && !wlc_hw->noreset) { |
791 | u32 gmode = 0; | |
792 | ||
793 | if (bandunit == 0) | |
794 | gmode = SICF_GMODE; | |
795 | ||
796 | brcms_b_core_ioctl(wlc_hw, SICF_GMODE, gmode); | |
797 | } | |
94bdc2a2 AB |
798 | } |
799 | ||
5b435de0 AS |
800 | /* switch to new band but leave it inactive */ |
801 | static u32 brcms_c_setband_inact(struct brcms_c_info *wlc, uint bandunit) | |
802 | { | |
803 | struct brcms_hardware *wlc_hw = wlc->hw; | |
804 | u32 macintmask; | |
16d2812e | 805 | u32 macctrl; |
5b435de0 AS |
806 | |
807 | BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
16d2812e AS |
808 | macctrl = bcma_read32(wlc_hw->d11core, |
809 | D11REGOFFS(maccontrol)); | |
810 | WARN_ON((macctrl & MCTL_EN_MAC) != 0); | |
5b435de0 AS |
811 | |
812 | /* disable interrupts */ | |
813 | macintmask = brcms_intrsoff(wlc->wl); | |
814 | ||
815 | /* radio off */ | |
816 | wlc_phy_switch_radio(wlc_hw->band->pi, OFF); | |
817 | ||
818 | brcms_b_core_phy_clk(wlc_hw, OFF); | |
819 | ||
820 | brcms_c_setxband(wlc_hw, bandunit); | |
821 | ||
822 | return macintmask; | |
823 | } | |
824 | ||
94bdc2a2 | 825 | /* process an individual struct tx_status */ |
5b435de0 | 826 | static bool |
94bdc2a2 | 827 | brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs) |
5b435de0 AS |
828 | { |
829 | struct sk_buff *p; | |
94bdc2a2 AB |
830 | uint queue; |
831 | struct d11txh *txh; | |
832 | struct scb *scb = NULL; | |
833 | bool free_pdu; | |
834 | int tx_rts, tx_frame_count, tx_rts_count; | |
835 | uint totlen, supr_status; | |
836 | bool lastframe; | |
837 | struct ieee80211_hdr *h; | |
838 | u16 mcl; | |
839 | struct ieee80211_tx_info *tx_info; | |
840 | struct ieee80211_tx_rate *txrate; | |
841 | int i; | |
5b435de0 | 842 | |
94bdc2a2 AB |
843 | /* discard intermediate indications for ucode with one legitimate case: |
844 | * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, | |
845 | * but the subsequent tx of DATA failed. so it will start rts/cts | |
846 | * from the beginning (resetting the rts transmission count) | |
847 | */ | |
848 | if (!(txs->status & TX_STATUS_AMPDU) | |
849 | && (txs->status & TX_STATUS_INTERMEDIATE)) { | |
6ead629b | 850 | BCMMSG(wlc->wiphy, "INTERMEDIATE but not AMPDU\n"); |
94bdc2a2 AB |
851 | return false; |
852 | } | |
5b435de0 | 853 | |
94bdc2a2 AB |
854 | queue = txs->frameid & TXFID_QUEUE_MASK; |
855 | if (queue >= NFIFO) { | |
856 | p = NULL; | |
857 | goto fatal; | |
5b435de0 AS |
858 | } |
859 | ||
94bdc2a2 AB |
860 | p = dma_getnexttxp(wlc->hw->di[queue], DMA_RANGE_TRANSMITTED); |
861 | if (p == NULL) | |
862 | goto fatal; | |
5b435de0 AS |
863 | |
864 | txh = (struct d11txh *) (p->data); | |
865 | mcl = le16_to_cpu(txh->MacTxControlLow); | |
866 | ||
867 | if (txs->phyerr) { | |
868 | if (brcm_msg_level & LOG_ERROR_VAL) { | |
869 | wiphy_err(wlc->wiphy, "phyerr 0x%x, rate 0x%x\n", | |
870 | txs->phyerr, txh->MainRates); | |
871 | brcms_c_print_txdesc(txh); | |
872 | } | |
873 | brcms_c_print_txstatus(txs); | |
874 | } | |
875 | ||
876 | if (txs->frameid != le16_to_cpu(txh->TxFrameID)) | |
877 | goto fatal; | |
878 | tx_info = IEEE80211_SKB_CB(p); | |
879 | h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN); | |
880 | ||
881 | if (tx_info->control.sta) | |
882 | scb = &wlc->pri_scb; | |
883 | ||
884 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) { | |
885 | brcms_c_ampdu_dotxstatus(wlc->ampdu, scb, p, txs); | |
886 | return false; | |
887 | } | |
888 | ||
889 | supr_status = txs->status & TX_STATUS_SUPR_MASK; | |
890 | if (supr_status == TX_STATUS_SUPR_BADCH) | |
891 | BCMMSG(wlc->wiphy, | |
892 | "%s: Pkt tx suppressed, possibly channel %d\n", | |
893 | __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec)); | |
894 | ||
895 | tx_rts = le16_to_cpu(txh->MacTxControlLow) & TXC_SENDRTS; | |
896 | tx_frame_count = | |
897 | (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT; | |
898 | tx_rts_count = | |
899 | (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT; | |
900 | ||
901 | lastframe = !ieee80211_has_morefrags(h->frame_control); | |
902 | ||
903 | if (!lastframe) { | |
904 | wiphy_err(wlc->wiphy, "Not last frame!\n"); | |
905 | } else { | |
906 | /* | |
907 | * Set information to be consumed by Minstrel ht. | |
908 | * | |
909 | * The "fallback limit" is the number of tx attempts a given | |
910 | * MPDU is sent at the "primary" rate. Tx attempts beyond that | |
911 | * limit are sent at the "secondary" rate. | |
912 | * A 'short frame' does not exceed RTS treshold. | |
913 | */ | |
914 | u16 sfbl, /* Short Frame Rate Fallback Limit */ | |
915 | lfbl, /* Long Frame Rate Fallback Limit */ | |
916 | fbl; | |
917 | ||
b7eec423 | 918 | if (queue < IEEE80211_NUM_ACS) { |
5b435de0 AS |
919 | sfbl = GFIELD(wlc->wme_retries[wme_fifo2ac[queue]], |
920 | EDCF_SFB); | |
921 | lfbl = GFIELD(wlc->wme_retries[wme_fifo2ac[queue]], | |
922 | EDCF_LFB); | |
923 | } else { | |
924 | sfbl = wlc->SFBL; | |
925 | lfbl = wlc->LFBL; | |
926 | } | |
927 | ||
928 | txrate = tx_info->status.rates; | |
929 | if (txrate[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) | |
930 | fbl = lfbl; | |
931 | else | |
932 | fbl = sfbl; | |
933 | ||
934 | ieee80211_tx_info_clear_status(tx_info); | |
935 | ||
936 | if ((tx_frame_count > fbl) && (txrate[1].idx >= 0)) { | |
937 | /* | |
938 | * rate selection requested a fallback rate | |
939 | * and we used it | |
940 | */ | |
941 | txrate[0].count = fbl; | |
942 | txrate[1].count = tx_frame_count - fbl; | |
943 | } else { | |
944 | /* | |
945 | * rate selection did not request fallback rate, or | |
946 | * we didn't need it | |
947 | */ | |
948 | txrate[0].count = tx_frame_count; | |
949 | /* | |
950 | * rc80211_minstrel.c:minstrel_tx_status() expects | |
951 | * unused rates to be marked with idx = -1 | |
952 | */ | |
953 | txrate[1].idx = -1; | |
954 | txrate[1].count = 0; | |
955 | } | |
956 | ||
957 | /* clear the rest of the rates */ | |
958 | for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) { | |
959 | txrate[i].idx = -1; | |
960 | txrate[i].count = 0; | |
961 | } | |
962 | ||
963 | if (txs->status & TX_STATUS_ACK_RCV) | |
964 | tx_info->flags |= IEEE80211_TX_STAT_ACK; | |
965 | } | |
966 | ||
ad4d71f6 | 967 | totlen = p->len; |
5b435de0 AS |
968 | free_pdu = true; |
969 | ||
970 | brcms_c_txfifo_complete(wlc, queue, 1); | |
971 | ||
972 | if (lastframe) { | |
5b435de0 AS |
973 | /* remove PLCP & Broadcom tx descriptor header */ |
974 | skb_pull(p, D11_PHY_HDR_LEN); | |
975 | skb_pull(p, D11_TXH_LEN); | |
976 | ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p); | |
977 | } else { | |
978 | wiphy_err(wlc->wiphy, "%s: Not last frame => not calling " | |
979 | "tx_status\n", __func__); | |
980 | } | |
981 | ||
982 | return false; | |
983 | ||
984 | fatal: | |
985 | if (p) | |
986 | brcmu_pkt_buf_free_skb(p); | |
987 | ||
988 | return true; | |
989 | ||
990 | } | |
991 | ||
992 | /* process tx completion events in BMAC | |
993 | * Return true if more tx status need to be processed. false otherwise. | |
994 | */ | |
995 | static bool | |
996 | brcms_b_txstatus(struct brcms_hardware *wlc_hw, bool bound, bool *fatal) | |
997 | { | |
998 | bool morepending = false; | |
999 | struct brcms_c_info *wlc = wlc_hw->wlc; | |
16d2812e | 1000 | struct bcma_device *core; |
5b435de0 AS |
1001 | struct tx_status txstatus, *txs; |
1002 | u32 s1, s2; | |
1003 | uint n = 0; | |
1004 | /* | |
1005 | * Param 'max_tx_num' indicates max. # tx status to process before | |
1006 | * break out. | |
1007 | */ | |
1008 | uint max_tx_num = bound ? TXSBND : -1; | |
1009 | ||
1010 | BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
1011 | ||
1012 | txs = &txstatus; | |
16d2812e | 1013 | core = wlc_hw->d11core; |
5b435de0 | 1014 | *fatal = false; |
16d2812e | 1015 | s1 = bcma_read32(core, D11REGOFFS(frmtxstatus)); |
5b435de0 | 1016 | while (!(*fatal) |
16d2812e | 1017 | && (s1 & TXS_V)) { |
5b435de0 AS |
1018 | |
1019 | if (s1 == 0xffffffff) { | |
1020 | wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", | |
1021 | wlc_hw->unit, __func__); | |
1022 | return morepending; | |
1023 | } | |
16d2812e | 1024 | s2 = bcma_read32(core, D11REGOFFS(frmtxstatus2)); |
5b435de0 AS |
1025 | |
1026 | txs->status = s1 & TXS_STATUS_MASK; | |
1027 | txs->frameid = (s1 & TXS_FID_MASK) >> TXS_FID_SHIFT; | |
1028 | txs->sequence = s2 & TXS_SEQ_MASK; | |
1029 | txs->phyerr = (s2 & TXS_PTX_MASK) >> TXS_PTX_SHIFT; | |
1030 | txs->lasttxtime = 0; | |
1031 | ||
1032 | *fatal = brcms_c_dotxstatus(wlc_hw->wlc, txs); | |
1033 | ||
1034 | /* !give others some time to run! */ | |
1035 | if (++n >= max_tx_num) | |
1036 | break; | |
16d2812e | 1037 | s1 = bcma_read32(core, D11REGOFFS(frmtxstatus)); |
5b435de0 AS |
1038 | } |
1039 | ||
1040 | if (*fatal) | |
1041 | return 0; | |
1042 | ||
1043 | if (n >= max_tx_num) | |
1044 | morepending = true; | |
1045 | ||
1046 | if (!pktq_empty(&wlc->pkt_queue->q)) | |
1047 | brcms_c_send_q(wlc); | |
1048 | ||
1049 | return morepending; | |
1050 | } | |
1051 | ||
94bdc2a2 | 1052 | static void brcms_c_tbtt(struct brcms_c_info *wlc) |
5b435de0 | 1053 | { |
94bdc2a2 AB |
1054 | if (!wlc->bsscfg->BSS) |
1055 | /* | |
1056 | * DirFrmQ is now valid...defer setting until end | |
1057 | * of ATIM window | |
1058 | */ | |
1059 | wlc->qvalid |= MCMD_DIRFRMQVAL; | |
5b435de0 AS |
1060 | } |
1061 | ||
1062 | /* set initial host flags value */ | |
1063 | static void | |
1064 | brcms_c_mhfdef(struct brcms_c_info *wlc, u16 *mhfs, u16 mhf2_init) | |
1065 | { | |
1066 | struct brcms_hardware *wlc_hw = wlc->hw; | |
1067 | ||
1068 | memset(mhfs, 0, MHFMAX * sizeof(u16)); | |
1069 | ||
1070 | mhfs[MHF2] |= mhf2_init; | |
1071 | ||
1072 | /* prohibit use of slowclock on multifunction boards */ | |
1073 | if (wlc_hw->boardflags & BFL_NOPLLDOWN) | |
1074 | mhfs[MHF1] |= MHF1_FORCEFASTCLK; | |
1075 | ||
1076 | if (BRCMS_ISNPHY(wlc_hw->band) && NREV_LT(wlc_hw->band->phyrev, 2)) { | |
1077 | mhfs[MHF2] |= MHF2_NPHY40MHZ_WAR; | |
1078 | mhfs[MHF1] |= MHF1_IQSWAP_WAR; | |
1079 | } | |
1080 | } | |
1081 | ||
e81da650 AS |
1082 | static uint |
1083 | dmareg(uint direction, uint fifonum) | |
5b435de0 AS |
1084 | { |
1085 | if (direction == DMA_TX) | |
e81da650 AS |
1086 | return offsetof(struct d11regs, fifo64regs[fifonum].dmaxmt); |
1087 | return offsetof(struct d11regs, fifo64regs[fifonum].dmarcv); | |
5b435de0 AS |
1088 | } |
1089 | ||
1090 | static bool brcms_b_attach_dmapio(struct brcms_c_info *wlc, uint j, bool wme) | |
1091 | { | |
1092 | uint i; | |
1093 | char name[8]; | |
1094 | /* | |
1095 | * ucode host flag 2 needed for pio mode, independent of band and fifo | |
1096 | */ | |
1097 | u16 pio_mhf2 = 0; | |
1098 | struct brcms_hardware *wlc_hw = wlc->hw; | |
1099 | uint unit = wlc_hw->unit; | |
1100 | struct wiphy *wiphy = wlc->wiphy; | |
1101 | ||
1102 | /* name and offsets for dma_attach */ | |
1103 | snprintf(name, sizeof(name), "wl%d", unit); | |
1104 | ||
1105 | if (wlc_hw->di[0] == NULL) { /* Init FIFOs */ | |
1106 | int dma_attach_err = 0; | |
1107 | ||
1108 | /* | |
1109 | * FIFO 0 | |
1110 | * TX: TX_AC_BK_FIFO (TX AC Background data packets) | |
1111 | * RX: RX_FIFO (RX data packets) | |
1112 | */ | |
2e81b9b1 | 1113 | wlc_hw->di[0] = dma_attach(name, wlc_hw->sih, wlc_hw->d11core, |
e81da650 AS |
1114 | (wme ? dmareg(DMA_TX, 0) : 0), |
1115 | dmareg(DMA_RX, 0), | |
5b435de0 AS |
1116 | (wme ? NTXD : 0), NRXD, |
1117 | RXBUFSZ, -1, NRXBUFPOST, | |
1118 | BRCMS_HWRXOFF, &brcm_msg_level); | |
1119 | dma_attach_err |= (NULL == wlc_hw->di[0]); | |
1120 | ||
1121 | /* | |
1122 | * FIFO 1 | |
1123 | * TX: TX_AC_BE_FIFO (TX AC Best-Effort data packets) | |
1124 | * (legacy) TX_DATA_FIFO (TX data packets) | |
1125 | * RX: UNUSED | |
1126 | */ | |
2e81b9b1 | 1127 | wlc_hw->di[1] = dma_attach(name, wlc_hw->sih, wlc_hw->d11core, |
e81da650 | 1128 | dmareg(DMA_TX, 1), 0, |
5b435de0 AS |
1129 | NTXD, 0, 0, -1, 0, 0, |
1130 | &brcm_msg_level); | |
1131 | dma_attach_err |= (NULL == wlc_hw->di[1]); | |
1132 | ||
1133 | /* | |
1134 | * FIFO 2 | |
1135 | * TX: TX_AC_VI_FIFO (TX AC Video data packets) | |
1136 | * RX: UNUSED | |
1137 | */ | |
2e81b9b1 | 1138 | wlc_hw->di[2] = dma_attach(name, wlc_hw->sih, wlc_hw->d11core, |
e81da650 | 1139 | dmareg(DMA_TX, 2), 0, |
5b435de0 AS |
1140 | NTXD, 0, 0, -1, 0, 0, |
1141 | &brcm_msg_level); | |
1142 | dma_attach_err |= (NULL == wlc_hw->di[2]); | |
1143 | /* | |
1144 | * FIFO 3 | |
1145 | * TX: TX_AC_VO_FIFO (TX AC Voice data packets) | |
1146 | * (legacy) TX_CTL_FIFO (TX control & mgmt packets) | |
1147 | */ | |
2e81b9b1 | 1148 | wlc_hw->di[3] = dma_attach(name, wlc_hw->sih, wlc_hw->d11core, |
e81da650 AS |
1149 | dmareg(DMA_TX, 3), |
1150 | 0, NTXD, 0, 0, -1, | |
5b435de0 AS |
1151 | 0, 0, &brcm_msg_level); |
1152 | dma_attach_err |= (NULL == wlc_hw->di[3]); | |
1153 | /* Cleaner to leave this as if with AP defined */ | |
1154 | ||
1155 | if (dma_attach_err) { | |
1156 | wiphy_err(wiphy, "wl%d: wlc_attach: dma_attach failed" | |
1157 | "\n", unit); | |
1158 | return false; | |
1159 | } | |
1160 | ||
1161 | /* get pointer to dma engine tx flow control variable */ | |
1162 | for (i = 0; i < NFIFO; i++) | |
1163 | if (wlc_hw->di[i]) | |
1164 | wlc_hw->txavail[i] = | |
1165 | (uint *) dma_getvar(wlc_hw->di[i], | |
1166 | "&txavail"); | |
1167 | } | |
1168 | ||
1169 | /* initial ucode host flags */ | |
1170 | brcms_c_mhfdef(wlc, wlc_hw->band->mhfs, pio_mhf2); | |
1171 | ||
1172 | return true; | |
1173 | } | |
1174 | ||
1175 | static void brcms_b_detach_dmapio(struct brcms_hardware *wlc_hw) | |
1176 | { | |
1177 | uint j; | |
1178 | ||
1179 | for (j = 0; j < NFIFO; j++) { | |
1180 | if (wlc_hw->di[j]) { | |
1181 | dma_detach(wlc_hw->di[j]); | |
1182 | wlc_hw->di[j] = NULL; | |
1183 | } | |
1184 | } | |
1185 | } | |
1186 | ||
1187 | /* | |
1188 | * Initialize brcms_c_info default values ... | |
1189 | * may get overrides later in this function | |
1190 | * BMAC_NOTES, move low out and resolve the dangling ones | |
1191 | */ | |
1192 | static void brcms_b_info_init(struct brcms_hardware *wlc_hw) | |
1193 | { | |
1194 | struct brcms_c_info *wlc = wlc_hw->wlc; | |
1195 | ||
1196 | /* set default sw macintmask value */ | |
1197 | wlc->defmacintmask = DEF_MACINTMASK; | |
1198 | ||
1199 | /* various 802.11g modes */ | |
1200 | wlc_hw->shortslot = false; | |
1201 | ||
1202 | wlc_hw->SFBL = RETRY_SHORT_FB; | |
1203 | wlc_hw->LFBL = RETRY_LONG_FB; | |
1204 | ||
1205 | /* default mac retry limits */ | |
1206 | wlc_hw->SRL = RETRY_SHORT_DEF; | |
1207 | wlc_hw->LRL = RETRY_LONG_DEF; | |
1208 | wlc_hw->chanspec = ch20mhz_chspec(1); | |
1209 | } | |
1210 | ||
1211 | static void brcms_b_wait_for_wake(struct brcms_hardware *wlc_hw) | |
1212 | { | |
1213 | /* delay before first read of ucode state */ | |
1214 | udelay(40); | |
1215 | ||
1216 | /* wait until ucode is no longer asleep */ | |
1217 | SPINWAIT((brcms_b_read_shm(wlc_hw, M_UCODE_DBGST) == | |
1218 | DBGST_ASLEEP), wlc_hw->wlc->fastpwrup_dly); | |
1219 | } | |
1220 | ||
1221 | /* control chip clock to save power, enable dynamic clock or force fast clock */ | |
712e3c1f | 1222 | static void brcms_b_clkctl_clk(struct brcms_hardware *wlc_hw, enum bcma_clkmode mode) |
5b435de0 | 1223 | { |
b2ffec46 | 1224 | if (ai_get_cccaps(wlc_hw->sih) & CC_CAP_PMU) { |
5b435de0 AS |
1225 | /* new chips with PMU, CCS_FORCEHT will distribute the HT clock |
1226 | * on backplane, but mac core will still run on ALP(not HT) when | |
1227 | * it enters powersave mode, which means the FCA bit may not be | |
1228 | * set. Should wakeup mac if driver wants it to run on HT. | |
1229 | */ | |
1230 | ||
1231 | if (wlc_hw->clk) { | |
712e3c1f | 1232 | if (mode == BCMA_CLKMODE_FAST) { |
16d2812e AS |
1233 | bcma_set32(wlc_hw->d11core, |
1234 | D11REGOFFS(clk_ctl_st), | |
1235 | CCS_FORCEHT); | |
5b435de0 AS |
1236 | |
1237 | udelay(64); | |
1238 | ||
16d2812e AS |
1239 | SPINWAIT( |
1240 | ((bcma_read32(wlc_hw->d11core, | |
1241 | D11REGOFFS(clk_ctl_st)) & | |
1242 | CCS_HTAVAIL) == 0), | |
1243 | PMU_MAX_TRANSITION_DLY); | |
1244 | WARN_ON(!(bcma_read32(wlc_hw->d11core, | |
1245 | D11REGOFFS(clk_ctl_st)) & | |
1246 | CCS_HTAVAIL)); | |
5b435de0 | 1247 | } else { |
b2ffec46 | 1248 | if ((ai_get_pmurev(wlc_hw->sih) == 0) && |
16d2812e AS |
1249 | (bcma_read32(wlc_hw->d11core, |
1250 | D11REGOFFS(clk_ctl_st)) & | |
1251 | (CCS_FORCEHT | CCS_HTAREQ))) | |
1252 | SPINWAIT( | |
1253 | ((bcma_read32(wlc_hw->d11core, | |
1254 | offsetof(struct d11regs, | |
1255 | clk_ctl_st)) & | |
1256 | CCS_HTAVAIL) == 0), | |
1257 | PMU_MAX_TRANSITION_DLY); | |
1258 | bcma_mask32(wlc_hw->d11core, | |
1259 | D11REGOFFS(clk_ctl_st), | |
5b435de0 AS |
1260 | ~CCS_FORCEHT); |
1261 | } | |
1262 | } | |
712e3c1f | 1263 | wlc_hw->forcefastclk = (mode == BCMA_CLKMODE_FAST); |
5b435de0 AS |
1264 | } else { |
1265 | ||
1266 | /* old chips w/o PMU, force HT through cc, | |
1267 | * then use FCA to verify mac is running fast clock | |
1268 | */ | |
1269 | ||
1270 | wlc_hw->forcefastclk = ai_clkctl_cc(wlc_hw->sih, mode); | |
1271 | ||
1272 | /* check fast clock is available (if core is not in reset) */ | |
1273 | if (wlc_hw->forcefastclk && wlc_hw->clk) | |
a8779e4a | 1274 | WARN_ON(!(bcma_aread32(wlc_hw->d11core, BCMA_IOST) & |
5b435de0 AS |
1275 | SISF_FCLKA)); |
1276 | ||
1277 | /* | |
1278 | * keep the ucode wake bit on if forcefastclk is on since we | |
1279 | * do not want ucode to put us back to slow clock when it dozes | |
1280 | * for PM mode. Code below matches the wake override bit with | |
1281 | * current forcefastclk state. Only setting bit in wake_override | |
1282 | * instead of waking ucode immediately since old code had this | |
1283 | * behavior. Older code set wlc->forcefastclk but only had the | |
1284 | * wake happen if the wakup_ucode work (protected by an up | |
1285 | * check) was executed just below. | |
1286 | */ | |
1287 | if (wlc_hw->forcefastclk) | |
1288 | mboolset(wlc_hw->wake_override, | |
1289 | BRCMS_WAKE_OVERRIDE_FORCEFAST); | |
1290 | else | |
1291 | mboolclr(wlc_hw->wake_override, | |
1292 | BRCMS_WAKE_OVERRIDE_FORCEFAST); | |
1293 | } | |
1294 | } | |
1295 | ||
1296 | /* set or clear ucode host flag bits | |
1297 | * it has an optimization for no-change write | |
1298 | * it only writes through shared memory when the core has clock; | |
1299 | * pre-CLK changes should use wlc_write_mhf to get around the optimization | |
1300 | * | |
1301 | * | |
1302 | * bands values are: BRCM_BAND_AUTO <--- Current band only | |
1303 | * BRCM_BAND_5G <--- 5G band only | |
1304 | * BRCM_BAND_2G <--- 2G band only | |
1305 | * BRCM_BAND_ALL <--- All bands | |
1306 | */ | |
1307 | void | |
1308 | brcms_b_mhf(struct brcms_hardware *wlc_hw, u8 idx, u16 mask, u16 val, | |
1309 | int bands) | |
1310 | { | |
1311 | u16 save; | |
1312 | u16 addr[MHFMAX] = { | |
1313 | M_HOST_FLAGS1, M_HOST_FLAGS2, M_HOST_FLAGS3, M_HOST_FLAGS4, | |
1314 | M_HOST_FLAGS5 | |
1315 | }; | |
1316 | struct brcms_hw_band *band; | |
1317 | ||
1318 | if ((val & ~mask) || idx >= MHFMAX) | |
1319 | return; /* error condition */ | |
1320 | ||
1321 | switch (bands) { | |
1322 | /* Current band only or all bands, | |
1323 | * then set the band to current band | |
1324 | */ | |
1325 | case BRCM_BAND_AUTO: | |
1326 | case BRCM_BAND_ALL: | |
1327 | band = wlc_hw->band; | |
1328 | break; | |
1329 | case BRCM_BAND_5G: | |
1330 | band = wlc_hw->bandstate[BAND_5G_INDEX]; | |
1331 | break; | |
1332 | case BRCM_BAND_2G: | |
1333 | band = wlc_hw->bandstate[BAND_2G_INDEX]; | |
1334 | break; | |
1335 | default: | |
1336 | band = NULL; /* error condition */ | |
1337 | } | |
1338 | ||
1339 | if (band) { | |
1340 | save = band->mhfs[idx]; | |
1341 | band->mhfs[idx] = (band->mhfs[idx] & ~mask) | val; | |
1342 | ||
1343 | /* optimization: only write through if changed, and | |
1344 | * changed band is the current band | |
1345 | */ | |
1346 | if (wlc_hw->clk && (band->mhfs[idx] != save) | |
1347 | && (band == wlc_hw->band)) | |
1348 | brcms_b_write_shm(wlc_hw, addr[idx], | |
1349 | (u16) band->mhfs[idx]); | |
1350 | } | |
1351 | ||
1352 | if (bands == BRCM_BAND_ALL) { | |
1353 | wlc_hw->bandstate[0]->mhfs[idx] = | |
1354 | (wlc_hw->bandstate[0]->mhfs[idx] & ~mask) | val; | |
1355 | wlc_hw->bandstate[1]->mhfs[idx] = | |
1356 | (wlc_hw->bandstate[1]->mhfs[idx] & ~mask) | val; | |
1357 | } | |
1358 | } | |
1359 | ||
1360 | /* set the maccontrol register to desired reset state and | |
1361 | * initialize the sw cache of the register | |
1362 | */ | |
1363 | static void brcms_c_mctrl_reset(struct brcms_hardware *wlc_hw) | |
1364 | { | |
1365 | /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */ | |
1366 | wlc_hw->maccontrol = 0; | |
1367 | wlc_hw->suspended_fifos = 0; | |
1368 | wlc_hw->wake_override = 0; | |
1369 | wlc_hw->mute_override = 0; | |
1370 | brcms_b_mctrl(wlc_hw, ~0, MCTL_IHR_EN | MCTL_WAKE); | |
1371 | } | |
1372 | ||
1373 | /* | |
1374 | * write the software state of maccontrol and | |
1375 | * overrides to the maccontrol register | |
1376 | */ | |
1377 | static void brcms_c_mctrl_write(struct brcms_hardware *wlc_hw) | |
1378 | { | |
1379 | u32 maccontrol = wlc_hw->maccontrol; | |
1380 | ||
1381 | /* OR in the wake bit if overridden */ | |
1382 | if (wlc_hw->wake_override) | |
1383 | maccontrol |= MCTL_WAKE; | |
1384 | ||
1385 | /* set AP and INFRA bits for mute if needed */ | |
1386 | if (wlc_hw->mute_override) { | |
1387 | maccontrol &= ~(MCTL_AP); | |
1388 | maccontrol |= MCTL_INFRA; | |
1389 | } | |
1390 | ||
16d2812e AS |
1391 | bcma_write32(wlc_hw->d11core, D11REGOFFS(maccontrol), |
1392 | maccontrol); | |
5b435de0 AS |
1393 | } |
1394 | ||
1395 | /* set or clear maccontrol bits */ | |
1396 | void brcms_b_mctrl(struct brcms_hardware *wlc_hw, u32 mask, u32 val) | |
1397 | { | |
1398 | u32 maccontrol; | |
1399 | u32 new_maccontrol; | |
1400 | ||
1401 | if (val & ~mask) | |
1402 | return; /* error condition */ | |
1403 | maccontrol = wlc_hw->maccontrol; | |
1404 | new_maccontrol = (maccontrol & ~mask) | val; | |
1405 | ||
1406 | /* if the new maccontrol value is the same as the old, nothing to do */ | |
1407 | if (new_maccontrol == maccontrol) | |
1408 | return; | |
1409 | ||
1410 | /* something changed, cache the new value */ | |
1411 | wlc_hw->maccontrol = new_maccontrol; | |
1412 | ||
1413 | /* write the new values with overrides applied */ | |
1414 | brcms_c_mctrl_write(wlc_hw); | |
1415 | } | |
1416 | ||
1417 | void brcms_c_ucode_wake_override_set(struct brcms_hardware *wlc_hw, | |
1418 | u32 override_bit) | |
1419 | { | |
1420 | if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) { | |
1421 | mboolset(wlc_hw->wake_override, override_bit); | |
1422 | return; | |
1423 | } | |
1424 | ||
1425 | mboolset(wlc_hw->wake_override, override_bit); | |
1426 | ||
1427 | brcms_c_mctrl_write(wlc_hw); | |
1428 | brcms_b_wait_for_wake(wlc_hw); | |
1429 | } | |
1430 | ||
1431 | void brcms_c_ucode_wake_override_clear(struct brcms_hardware *wlc_hw, | |
1432 | u32 override_bit) | |
1433 | { | |
1434 | mboolclr(wlc_hw->wake_override, override_bit); | |
1435 | ||
1436 | if (wlc_hw->wake_override || (wlc_hw->maccontrol & MCTL_WAKE)) | |
1437 | return; | |
1438 | ||
1439 | brcms_c_mctrl_write(wlc_hw); | |
1440 | } | |
1441 | ||
1442 | /* When driver needs ucode to stop beaconing, it has to make sure that | |
1443 | * MCTL_AP is clear and MCTL_INFRA is set | |
1444 | * Mode MCTL_AP MCTL_INFRA | |
1445 | * AP 1 1 | |
1446 | * STA 0 1 <--- This will ensure no beacons | |
1447 | * IBSS 0 0 | |
1448 | */ | |
1449 | static void brcms_c_ucode_mute_override_set(struct brcms_hardware *wlc_hw) | |
1450 | { | |
1451 | wlc_hw->mute_override = 1; | |
1452 | ||
1453 | /* if maccontrol already has AP == 0 and INFRA == 1 without this | |
1454 | * override, then there is no change to write | |
1455 | */ | |
1456 | if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA) | |
1457 | return; | |
1458 | ||
1459 | brcms_c_mctrl_write(wlc_hw); | |
1460 | } | |
1461 | ||
1462 | /* Clear the override on AP and INFRA bits */ | |
1463 | static void brcms_c_ucode_mute_override_clear(struct brcms_hardware *wlc_hw) | |
1464 | { | |
1465 | if (wlc_hw->mute_override == 0) | |
1466 | return; | |
1467 | ||
1468 | wlc_hw->mute_override = 0; | |
1469 | ||
1470 | /* if maccontrol already has AP == 0 and INFRA == 1 without this | |
1471 | * override, then there is no change to write | |
1472 | */ | |
1473 | if ((wlc_hw->maccontrol & (MCTL_AP | MCTL_INFRA)) == MCTL_INFRA) | |
1474 | return; | |
1475 | ||
1476 | brcms_c_mctrl_write(wlc_hw); | |
1477 | } | |
1478 | ||
1479 | /* | |
1480 | * Write a MAC address to the given match reg offset in the RXE match engine. | |
1481 | */ | |
1482 | static void | |
1483 | brcms_b_set_addrmatch(struct brcms_hardware *wlc_hw, int match_reg_offset, | |
1484 | const u8 *addr) | |
1485 | { | |
16d2812e | 1486 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
1487 | u16 mac_l; |
1488 | u16 mac_m; | |
1489 | u16 mac_h; | |
1490 | ||
1491 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d: brcms_b_set_addrmatch\n", | |
1492 | wlc_hw->unit); | |
1493 | ||
5b435de0 AS |
1494 | mac_l = addr[0] | (addr[1] << 8); |
1495 | mac_m = addr[2] | (addr[3] << 8); | |
1496 | mac_h = addr[4] | (addr[5] << 8); | |
1497 | ||
1498 | /* enter the MAC addr into the RXE match registers */ | |
16d2812e AS |
1499 | bcma_write16(core, D11REGOFFS(rcm_ctl), |
1500 | RCM_INC_DATA | match_reg_offset); | |
1501 | bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_l); | |
1502 | bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_m); | |
1503 | bcma_write16(core, D11REGOFFS(rcm_mat_data), mac_h); | |
5b435de0 AS |
1504 | } |
1505 | ||
1506 | void | |
1507 | brcms_b_write_template_ram(struct brcms_hardware *wlc_hw, int offset, int len, | |
1508 | void *buf) | |
1509 | { | |
16d2812e | 1510 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
1511 | u32 word; |
1512 | __le32 word_le; | |
1513 | __be32 word_be; | |
1514 | bool be_bit; | |
1515 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
1516 | ||
16d2812e | 1517 | bcma_write32(core, D11REGOFFS(tplatewrptr), offset); |
5b435de0 AS |
1518 | |
1519 | /* if MCTL_BIGEND bit set in mac control register, | |
1520 | * the chip swaps data in fifo, as well as data in | |
1521 | * template ram | |
1522 | */ | |
16d2812e | 1523 | be_bit = (bcma_read32(core, D11REGOFFS(maccontrol)) & MCTL_BIGEND) != 0; |
5b435de0 AS |
1524 | |
1525 | while (len > 0) { | |
1526 | memcpy(&word, buf, sizeof(u32)); | |
1527 | ||
1528 | if (be_bit) { | |
1529 | word_be = cpu_to_be32(word); | |
1530 | word = *(u32 *)&word_be; | |
1531 | } else { | |
1532 | word_le = cpu_to_le32(word); | |
1533 | word = *(u32 *)&word_le; | |
1534 | } | |
1535 | ||
16d2812e | 1536 | bcma_write32(core, D11REGOFFS(tplatewrdata), word); |
5b435de0 AS |
1537 | |
1538 | buf = (u8 *) buf + sizeof(u32); | |
1539 | len -= sizeof(u32); | |
1540 | } | |
1541 | } | |
1542 | ||
1543 | static void brcms_b_set_cwmin(struct brcms_hardware *wlc_hw, u16 newmin) | |
1544 | { | |
1545 | wlc_hw->band->CWmin = newmin; | |
1546 | ||
16d2812e AS |
1547 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objaddr), |
1548 | OBJADDR_SCR_SEL | S_DOT11_CWMIN); | |
1549 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(objaddr)); | |
1550 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objdata), newmin); | |
5b435de0 AS |
1551 | } |
1552 | ||
1553 | static void brcms_b_set_cwmax(struct brcms_hardware *wlc_hw, u16 newmax) | |
1554 | { | |
1555 | wlc_hw->band->CWmax = newmax; | |
1556 | ||
16d2812e AS |
1557 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objaddr), |
1558 | OBJADDR_SCR_SEL | S_DOT11_CWMAX); | |
1559 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(objaddr)); | |
1560 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objdata), newmax); | |
5b435de0 AS |
1561 | } |
1562 | ||
1563 | void brcms_b_bw_set(struct brcms_hardware *wlc_hw, u16 bw) | |
1564 | { | |
1565 | bool fastclk; | |
1566 | ||
1567 | /* request FAST clock if not on */ | |
1568 | fastclk = wlc_hw->forcefastclk; | |
1569 | if (!fastclk) | |
712e3c1f | 1570 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
5b435de0 AS |
1571 | |
1572 | wlc_phy_bw_state_set(wlc_hw->band->pi, bw); | |
1573 | ||
1574 | brcms_b_phy_reset(wlc_hw); | |
1575 | wlc_phy_init(wlc_hw->band->pi, wlc_phy_chanspec_get(wlc_hw->band->pi)); | |
1576 | ||
1577 | /* restore the clk */ | |
1578 | if (!fastclk) | |
712e3c1f | 1579 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC); |
5b435de0 AS |
1580 | } |
1581 | ||
1582 | static void brcms_b_upd_synthpu(struct brcms_hardware *wlc_hw) | |
1583 | { | |
1584 | u16 v; | |
1585 | struct brcms_c_info *wlc = wlc_hw->wlc; | |
1586 | /* update SYNTHPU_DLY */ | |
1587 | ||
1588 | if (BRCMS_ISLCNPHY(wlc->band)) | |
1589 | v = SYNTHPU_DLY_LPPHY_US; | |
1590 | else if (BRCMS_ISNPHY(wlc->band) && (NREV_GE(wlc->band->phyrev, 3))) | |
1591 | v = SYNTHPU_DLY_NPHY_US; | |
1592 | else | |
1593 | v = SYNTHPU_DLY_BPHY_US; | |
1594 | ||
1595 | brcms_b_write_shm(wlc_hw, M_SYNTHPU_DLY, v); | |
1596 | } | |
1597 | ||
1598 | static void brcms_c_ucode_txant_set(struct brcms_hardware *wlc_hw) | |
1599 | { | |
1600 | u16 phyctl; | |
1601 | u16 phytxant = wlc_hw->bmac_phytxant; | |
1602 | u16 mask = PHY_TXC_ANT_MASK; | |
1603 | ||
1604 | /* set the Probe Response frame phy control word */ | |
1605 | phyctl = brcms_b_read_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS); | |
1606 | phyctl = (phyctl & ~mask) | phytxant; | |
1607 | brcms_b_write_shm(wlc_hw, M_CTXPRS_BLK + C_CTX_PCTLWD_POS, phyctl); | |
1608 | ||
1609 | /* set the Response (ACK/CTS) frame phy control word */ | |
1610 | phyctl = brcms_b_read_shm(wlc_hw, M_RSP_PCTLWD); | |
1611 | phyctl = (phyctl & ~mask) | phytxant; | |
1612 | brcms_b_write_shm(wlc_hw, M_RSP_PCTLWD, phyctl); | |
1613 | } | |
1614 | ||
1615 | static u16 brcms_b_ofdm_ratetable_offset(struct brcms_hardware *wlc_hw, | |
1616 | u8 rate) | |
1617 | { | |
1618 | uint i; | |
1619 | u8 plcp_rate = 0; | |
1620 | struct plcp_signal_rate_lookup { | |
1621 | u8 rate; | |
1622 | u8 signal_rate; | |
1623 | }; | |
1624 | /* OFDM RATE sub-field of PLCP SIGNAL field, per 802.11 sec 17.3.4.1 */ | |
1625 | const struct plcp_signal_rate_lookup rate_lookup[] = { | |
1626 | {BRCM_RATE_6M, 0xB}, | |
1627 | {BRCM_RATE_9M, 0xF}, | |
1628 | {BRCM_RATE_12M, 0xA}, | |
1629 | {BRCM_RATE_18M, 0xE}, | |
1630 | {BRCM_RATE_24M, 0x9}, | |
1631 | {BRCM_RATE_36M, 0xD}, | |
1632 | {BRCM_RATE_48M, 0x8}, | |
1633 | {BRCM_RATE_54M, 0xC} | |
1634 | }; | |
1635 | ||
1636 | for (i = 0; i < ARRAY_SIZE(rate_lookup); i++) { | |
1637 | if (rate == rate_lookup[i].rate) { | |
1638 | plcp_rate = rate_lookup[i].signal_rate; | |
1639 | break; | |
1640 | } | |
1641 | } | |
1642 | ||
1643 | /* Find the SHM pointer to the rate table entry by looking in the | |
1644 | * Direct-map Table | |
1645 | */ | |
1646 | return 2 * brcms_b_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2)); | |
1647 | } | |
1648 | ||
1649 | static void brcms_upd_ofdm_pctl1_table(struct brcms_hardware *wlc_hw) | |
1650 | { | |
1651 | u8 rate; | |
1652 | u8 rates[8] = { | |
1653 | BRCM_RATE_6M, BRCM_RATE_9M, BRCM_RATE_12M, BRCM_RATE_18M, | |
1654 | BRCM_RATE_24M, BRCM_RATE_36M, BRCM_RATE_48M, BRCM_RATE_54M | |
1655 | }; | |
1656 | u16 entry_ptr; | |
1657 | u16 pctl1; | |
1658 | uint i; | |
1659 | ||
1660 | if (!BRCMS_PHY_11N_CAP(wlc_hw->band)) | |
1661 | return; | |
1662 | ||
1663 | /* walk the phy rate table and update the entries */ | |
1664 | for (i = 0; i < ARRAY_SIZE(rates); i++) { | |
1665 | rate = rates[i]; | |
1666 | ||
1667 | entry_ptr = brcms_b_ofdm_ratetable_offset(wlc_hw, rate); | |
1668 | ||
1669 | /* read the SHM Rate Table entry OFDM PCTL1 values */ | |
1670 | pctl1 = | |
1671 | brcms_b_read_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS); | |
1672 | ||
1673 | /* modify the value */ | |
1674 | pctl1 &= ~PHY_TXC1_MODE_MASK; | |
1675 | pctl1 |= (wlc_hw->hw_stf_ss_opmode << PHY_TXC1_MODE_SHIFT); | |
1676 | ||
1677 | /* Update the SHM Rate Table entry OFDM PCTL1 values */ | |
1678 | brcms_b_write_shm(wlc_hw, entry_ptr + M_RT_OFDM_PCTL1_POS, | |
1679 | pctl1); | |
1680 | } | |
1681 | } | |
1682 | ||
1683 | /* band-specific init */ | |
1684 | static void brcms_b_bsinit(struct brcms_c_info *wlc, u16 chanspec) | |
1685 | { | |
1686 | struct brcms_hardware *wlc_hw = wlc->hw; | |
1687 | ||
1688 | BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit, | |
1689 | wlc_hw->band->bandunit); | |
1690 | ||
1691 | brcms_c_ucode_bsinit(wlc_hw); | |
1692 | ||
1693 | wlc_phy_init(wlc_hw->band->pi, chanspec); | |
1694 | ||
1695 | brcms_c_ucode_txant_set(wlc_hw); | |
1696 | ||
1697 | /* | |
1698 | * cwmin is band-specific, update hardware | |
1699 | * with value for current band | |
1700 | */ | |
1701 | brcms_b_set_cwmin(wlc_hw, wlc_hw->band->CWmin); | |
1702 | brcms_b_set_cwmax(wlc_hw, wlc_hw->band->CWmax); | |
1703 | ||
1704 | brcms_b_update_slot_timing(wlc_hw, | |
1705 | wlc_hw->band->bandtype == BRCM_BAND_5G ? | |
1706 | true : wlc_hw->shortslot); | |
1707 | ||
1708 | /* write phytype and phyvers */ | |
1709 | brcms_b_write_shm(wlc_hw, M_PHYTYPE, (u16) wlc_hw->band->phytype); | |
1710 | brcms_b_write_shm(wlc_hw, M_PHYVER, (u16) wlc_hw->band->phyrev); | |
1711 | ||
1712 | /* | |
1713 | * initialize the txphyctl1 rate table since | |
1714 | * shmem is shared between bands | |
1715 | */ | |
1716 | brcms_upd_ofdm_pctl1_table(wlc_hw); | |
1717 | ||
1718 | brcms_b_upd_synthpu(wlc_hw); | |
1719 | } | |
1720 | ||
1721 | /* Perform a soft reset of the PHY PLL */ | |
1722 | void brcms_b_core_phypll_reset(struct brcms_hardware *wlc_hw) | |
1723 | { | |
1724 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
1725 | ||
7d8e18e4 AS |
1726 | ai_cc_reg(wlc_hw->sih, offsetof(struct chipcregs, chipcontrol_addr), |
1727 | ~0, 0); | |
5b435de0 | 1728 | udelay(1); |
7d8e18e4 AS |
1729 | ai_cc_reg(wlc_hw->sih, offsetof(struct chipcregs, chipcontrol_data), |
1730 | 0x4, 0); | |
5b435de0 | 1731 | udelay(1); |
7d8e18e4 AS |
1732 | ai_cc_reg(wlc_hw->sih, offsetof(struct chipcregs, chipcontrol_data), |
1733 | 0x4, 4); | |
5b435de0 | 1734 | udelay(1); |
7d8e18e4 AS |
1735 | ai_cc_reg(wlc_hw->sih, offsetof(struct chipcregs, chipcontrol_data), |
1736 | 0x4, 0); | |
5b435de0 AS |
1737 | udelay(1); |
1738 | } | |
1739 | ||
1740 | /* light way to turn on phy clock without reset for NPHY only | |
1741 | * refer to brcms_b_core_phy_clk for full version | |
1742 | */ | |
1743 | void brcms_b_phyclk_fgc(struct brcms_hardware *wlc_hw, bool clk) | |
1744 | { | |
1745 | /* support(necessary for NPHY and HYPHY) only */ | |
1746 | if (!BRCMS_ISNPHY(wlc_hw->band)) | |
1747 | return; | |
1748 | ||
1749 | if (ON == clk) | |
a8779e4a | 1750 | brcms_b_core_ioctl(wlc_hw, SICF_FGC, SICF_FGC); |
5b435de0 | 1751 | else |
a8779e4a | 1752 | brcms_b_core_ioctl(wlc_hw, SICF_FGC, 0); |
5b435de0 AS |
1753 | |
1754 | } | |
1755 | ||
1756 | void brcms_b_macphyclk_set(struct brcms_hardware *wlc_hw, bool clk) | |
1757 | { | |
1758 | if (ON == clk) | |
a8779e4a | 1759 | brcms_b_core_ioctl(wlc_hw, SICF_MPCLKE, SICF_MPCLKE); |
5b435de0 | 1760 | else |
a8779e4a | 1761 | brcms_b_core_ioctl(wlc_hw, SICF_MPCLKE, 0); |
5b435de0 AS |
1762 | } |
1763 | ||
1764 | void brcms_b_phy_reset(struct brcms_hardware *wlc_hw) | |
1765 | { | |
1766 | struct brcms_phy_pub *pih = wlc_hw->band->pi; | |
1767 | u32 phy_bw_clkbits; | |
1768 | bool phy_in_reset = false; | |
1769 | ||
1770 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
1771 | ||
1772 | if (pih == NULL) | |
1773 | return; | |
1774 | ||
1775 | phy_bw_clkbits = wlc_phy_clk_bwbits(wlc_hw->band->pi); | |
1776 | ||
1777 | /* Specific reset sequence required for NPHY rev 3 and 4 */ | |
1778 | if (BRCMS_ISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3) && | |
1779 | NREV_LE(wlc_hw->band->phyrev, 4)) { | |
1780 | /* Set the PHY bandwidth */ | |
a8779e4a | 1781 | brcms_b_core_ioctl(wlc_hw, SICF_BWMASK, phy_bw_clkbits); |
5b435de0 AS |
1782 | |
1783 | udelay(1); | |
1784 | ||
1785 | /* Perform a soft reset of the PHY PLL */ | |
1786 | brcms_b_core_phypll_reset(wlc_hw); | |
1787 | ||
1788 | /* reset the PHY */ | |
a8779e4a AS |
1789 | brcms_b_core_ioctl(wlc_hw, (SICF_PRST | SICF_PCLKE), |
1790 | (SICF_PRST | SICF_PCLKE)); | |
5b435de0 AS |
1791 | phy_in_reset = true; |
1792 | } else { | |
a8779e4a AS |
1793 | brcms_b_core_ioctl(wlc_hw, |
1794 | (SICF_PRST | SICF_PCLKE | SICF_BWMASK), | |
1795 | (SICF_PRST | SICF_PCLKE | phy_bw_clkbits)); | |
5b435de0 AS |
1796 | } |
1797 | ||
1798 | udelay(2); | |
1799 | brcms_b_core_phy_clk(wlc_hw, ON); | |
1800 | ||
1801 | if (pih) | |
1802 | wlc_phy_anacore(pih, ON); | |
1803 | } | |
1804 | ||
1805 | /* switch to and initialize new band */ | |
1806 | static void brcms_b_setband(struct brcms_hardware *wlc_hw, uint bandunit, | |
1807 | u16 chanspec) { | |
1808 | struct brcms_c_info *wlc = wlc_hw->wlc; | |
1809 | u32 macintmask; | |
1810 | ||
1811 | /* Enable the d11 core before accessing it */ | |
a8779e4a AS |
1812 | if (!bcma_core_is_enabled(wlc_hw->d11core)) { |
1813 | bcma_core_enable(wlc_hw->d11core, 0); | |
5b435de0 AS |
1814 | brcms_c_mctrl_reset(wlc_hw); |
1815 | } | |
1816 | ||
1817 | macintmask = brcms_c_setband_inact(wlc, bandunit); | |
1818 | ||
1819 | if (!wlc_hw->up) | |
1820 | return; | |
1821 | ||
1822 | brcms_b_core_phy_clk(wlc_hw, ON); | |
1823 | ||
1824 | /* band-specific initializations */ | |
1825 | brcms_b_bsinit(wlc, chanspec); | |
1826 | ||
1827 | /* | |
1828 | * If there are any pending software interrupt bits, | |
1829 | * then replace these with a harmless nonzero value | |
1830 | * so brcms_c_dpc() will re-enable interrupts when done. | |
1831 | */ | |
1832 | if (wlc->macintstatus) | |
1833 | wlc->macintstatus = MI_DMAINT; | |
1834 | ||
1835 | /* restore macintmask */ | |
1836 | brcms_intrsrestore(wlc->wl, macintmask); | |
1837 | ||
1838 | /* ucode should still be suspended.. */ | |
16d2812e AS |
1839 | WARN_ON((bcma_read32(wlc_hw->d11core, D11REGOFFS(maccontrol)) & |
1840 | MCTL_EN_MAC) != 0); | |
5b435de0 AS |
1841 | } |
1842 | ||
5b435de0 AS |
1843 | static bool brcms_c_isgoodchip(struct brcms_hardware *wlc_hw) |
1844 | { | |
1845 | ||
1846 | /* reject unsupported corerev */ | |
1847 | if (!CONF_HAS(D11CONF, wlc_hw->corerev)) { | |
1848 | wiphy_err(wlc_hw->wlc->wiphy, "unsupported core rev %d\n", | |
1849 | wlc_hw->corerev); | |
1850 | return false; | |
1851 | } | |
1852 | ||
1853 | return true; | |
1854 | } | |
1855 | ||
1856 | /* Validate some board info parameters */ | |
1857 | static bool brcms_c_validboardtype(struct brcms_hardware *wlc_hw) | |
1858 | { | |
1859 | uint boardrev = wlc_hw->boardrev; | |
1860 | ||
1861 | /* 4 bits each for board type, major, minor, and tiny version */ | |
1862 | uint brt = (boardrev & 0xf000) >> 12; | |
1863 | uint b0 = (boardrev & 0xf00) >> 8; | |
1864 | uint b1 = (boardrev & 0xf0) >> 4; | |
1865 | uint b2 = boardrev & 0xf; | |
1866 | ||
1867 | /* voards from other vendors are always considered valid */ | |
b2ffec46 | 1868 | if (ai_get_boardvendor(wlc_hw->sih) != PCI_VENDOR_ID_BROADCOM) |
5b435de0 AS |
1869 | return true; |
1870 | ||
1871 | /* do some boardrev sanity checks when boardvendor is Broadcom */ | |
1872 | if (boardrev == 0) | |
1873 | return false; | |
1874 | ||
1875 | if (boardrev <= 0xff) | |
1876 | return true; | |
1877 | ||
1878 | if ((brt > 2) || (brt == 0) || (b0 > 9) || (b0 == 0) || (b1 > 9) | |
1879 | || (b2 > 9)) | |
1880 | return false; | |
1881 | ||
1882 | return true; | |
1883 | } | |
1884 | ||
898d3c3b | 1885 | static void brcms_c_get_macaddr(struct brcms_hardware *wlc_hw, u8 etheraddr[ETH_ALEN]) |
5b435de0 | 1886 | { |
898d3c3b | 1887 | struct ssb_sprom *sprom = &wlc_hw->d11core->bus->sprom; |
5b435de0 AS |
1888 | |
1889 | /* If macaddr exists, use it (Sromrev4, CIS, ...). */ | |
898d3c3b HM |
1890 | if (!is_zero_ether_addr(sprom->il0mac)) { |
1891 | memcpy(etheraddr, sprom->il0mac, 6); | |
1892 | return; | |
1893 | } | |
5b435de0 AS |
1894 | |
1895 | if (wlc_hw->_nbands > 1) | |
898d3c3b | 1896 | memcpy(etheraddr, sprom->et1mac, 6); |
5b435de0 | 1897 | else |
898d3c3b | 1898 | memcpy(etheraddr, sprom->il0mac, 6); |
5b435de0 AS |
1899 | } |
1900 | ||
1901 | /* power both the pll and external oscillator on/off */ | |
1902 | static void brcms_b_xtal(struct brcms_hardware *wlc_hw, bool want) | |
1903 | { | |
1904 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d: want %d\n", wlc_hw->unit, want); | |
1905 | ||
1906 | /* | |
1907 | * dont power down if plldown is false or | |
1908 | * we must poll hw radio disable | |
1909 | */ | |
1910 | if (!want && wlc_hw->pllreq) | |
1911 | return; | |
1912 | ||
5b435de0 AS |
1913 | wlc_hw->sbclk = want; |
1914 | if (!wlc_hw->sbclk) { | |
1915 | wlc_hw->clk = false; | |
1916 | if (wlc_hw->band && wlc_hw->band->pi) | |
1917 | wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false); | |
1918 | } | |
1919 | } | |
1920 | ||
1921 | /* | |
1922 | * Return true if radio is disabled, otherwise false. | |
1923 | * hw radio disable signal is an external pin, users activate it asynchronously | |
1924 | * this function could be called when driver is down and w/o clock | |
1925 | * it operates on different registers depending on corerev and boardflag. | |
1926 | */ | |
1927 | static bool brcms_b_radio_read_hwdisabled(struct brcms_hardware *wlc_hw) | |
1928 | { | |
1929 | bool v, clk, xtal; | |
a8779e4a | 1930 | u32 flags = 0; |
5b435de0 AS |
1931 | |
1932 | xtal = wlc_hw->sbclk; | |
1933 | if (!xtal) | |
1934 | brcms_b_xtal(wlc_hw, ON); | |
1935 | ||
1936 | /* may need to take core out of reset first */ | |
1937 | clk = wlc_hw->clk; | |
1938 | if (!clk) { | |
1939 | /* | |
1940 | * mac no longer enables phyclk automatically when driver | |
1941 | * accesses phyreg throughput mac. This can be skipped since | |
1942 | * only mac reg is accessed below | |
1943 | */ | |
1944 | flags |= SICF_PCLKE; | |
1945 | ||
1946 | /* | |
3b758a68 AS |
1947 | * TODO: test suspend/resume |
1948 | * | |
5b435de0 AS |
1949 | * AI chip doesn't restore bar0win2 on |
1950 | * hibernation/resume, need sw fixup | |
1951 | */ | |
16d2812e | 1952 | |
a8779e4a | 1953 | bcma_core_enable(wlc_hw->d11core, flags); |
5b435de0 AS |
1954 | brcms_c_mctrl_reset(wlc_hw); |
1955 | } | |
1956 | ||
16d2812e AS |
1957 | v = ((bcma_read32(wlc_hw->d11core, |
1958 | D11REGOFFS(phydebug)) & PDBG_RFD) != 0); | |
5b435de0 AS |
1959 | |
1960 | /* put core back into reset */ | |
1961 | if (!clk) | |
a8779e4a | 1962 | bcma_core_disable(wlc_hw->d11core, 0); |
5b435de0 AS |
1963 | |
1964 | if (!xtal) | |
1965 | brcms_b_xtal(wlc_hw, OFF); | |
1966 | ||
1967 | return v; | |
1968 | } | |
1969 | ||
1970 | static bool wlc_dma_rxreset(struct brcms_hardware *wlc_hw, uint fifo) | |
1971 | { | |
1972 | struct dma_pub *di = wlc_hw->di[fifo]; | |
1973 | return dma_rxreset(di); | |
1974 | } | |
1975 | ||
1976 | /* d11 core reset | |
1977 | * ensure fask clock during reset | |
1978 | * reset dma | |
1979 | * reset d11(out of reset) | |
1980 | * reset phy(out of reset) | |
1981 | * clear software macintstatus for fresh new start | |
1982 | * one testing hack wlc_hw->noreset will bypass the d11/phy reset | |
1983 | */ | |
1984 | void brcms_b_corereset(struct brcms_hardware *wlc_hw, u32 flags) | |
1985 | { | |
5b435de0 AS |
1986 | uint i; |
1987 | bool fastclk; | |
5b435de0 AS |
1988 | |
1989 | if (flags == BRCMS_USE_COREFLAGS) | |
1990 | flags = (wlc_hw->band->pi ? wlc_hw->band->core_flags : 0); | |
1991 | ||
1992 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
1993 | ||
5b435de0 AS |
1994 | /* request FAST clock if not on */ |
1995 | fastclk = wlc_hw->forcefastclk; | |
1996 | if (!fastclk) | |
712e3c1f | 1997 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
5b435de0 AS |
1998 | |
1999 | /* reset the dma engines except first time thru */ | |
a8779e4a | 2000 | if (bcma_core_is_enabled(wlc_hw->d11core)) { |
5b435de0 AS |
2001 | for (i = 0; i < NFIFO; i++) |
2002 | if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) | |
2003 | wiphy_err(wlc_hw->wlc->wiphy, "wl%d: %s: " | |
2004 | "dma_txreset[%d]: cannot stop dma\n", | |
2005 | wlc_hw->unit, __func__, i); | |
2006 | ||
2007 | if ((wlc_hw->di[RX_FIFO]) | |
2008 | && (!wlc_dma_rxreset(wlc_hw, RX_FIFO))) | |
2009 | wiphy_err(wlc_hw->wlc->wiphy, "wl%d: %s: dma_rxreset" | |
2010 | "[%d]: cannot stop dma\n", | |
2011 | wlc_hw->unit, __func__, RX_FIFO); | |
2012 | } | |
2013 | /* if noreset, just stop the psm and return */ | |
2014 | if (wlc_hw->noreset) { | |
2015 | wlc_hw->wlc->macintstatus = 0; /* skip wl_dpc after down */ | |
2016 | brcms_b_mctrl(wlc_hw, MCTL_PSM_RUN | MCTL_EN_MAC, 0); | |
2017 | return; | |
2018 | } | |
2019 | ||
2020 | /* | |
2021 | * mac no longer enables phyclk automatically when driver accesses | |
2022 | * phyreg throughput mac, AND phy_reset is skipped at early stage when | |
2023 | * band->pi is invalid. need to enable PHY CLK | |
2024 | */ | |
2025 | flags |= SICF_PCLKE; | |
2026 | ||
2027 | /* | |
2028 | * reset the core | |
2029 | * In chips with PMU, the fastclk request goes through d11 core | |
2030 | * reg 0x1e0, which is cleared by the core_reset. have to re-request it. | |
2031 | * | |
2032 | * This adds some delay and we can optimize it by also requesting | |
2033 | * fastclk through chipcommon during this period if necessary. But | |
2034 | * that has to work coordinate with other driver like mips/arm since | |
2035 | * they may touch chipcommon as well. | |
2036 | */ | |
2037 | wlc_hw->clk = false; | |
a8779e4a | 2038 | bcma_core_enable(wlc_hw->d11core, flags); |
5b435de0 AS |
2039 | wlc_hw->clk = true; |
2040 | if (wlc_hw->band && wlc_hw->band->pi) | |
2041 | wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, true); | |
2042 | ||
2043 | brcms_c_mctrl_reset(wlc_hw); | |
2044 | ||
b2ffec46 | 2045 | if (ai_get_cccaps(wlc_hw->sih) & CC_CAP_PMU) |
712e3c1f | 2046 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
5b435de0 AS |
2047 | |
2048 | brcms_b_phy_reset(wlc_hw); | |
2049 | ||
2050 | /* turn on PHY_PLL */ | |
2051 | brcms_b_core_phypll_ctl(wlc_hw, true); | |
2052 | ||
2053 | /* clear sw intstatus */ | |
2054 | wlc_hw->wlc->macintstatus = 0; | |
2055 | ||
2056 | /* restore the clk setting */ | |
2057 | if (!fastclk) | |
712e3c1f | 2058 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC); |
5b435de0 AS |
2059 | } |
2060 | ||
2061 | /* txfifo sizes needs to be modified(increased) since the newer cores | |
2062 | * have more memory. | |
2063 | */ | |
2064 | static void brcms_b_corerev_fifofixup(struct brcms_hardware *wlc_hw) | |
2065 | { | |
16d2812e | 2066 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
2067 | u16 fifo_nu; |
2068 | u16 txfifo_startblk = TXFIFO_START_BLK, txfifo_endblk; | |
2069 | u16 txfifo_def, txfifo_def1; | |
2070 | u16 txfifo_cmd; | |
2071 | ||
2072 | /* tx fifos start at TXFIFO_START_BLK from the Base address */ | |
2073 | txfifo_startblk = TXFIFO_START_BLK; | |
2074 | ||
2075 | /* sequence of operations: reset fifo, set fifo size, reset fifo */ | |
2076 | for (fifo_nu = 0; fifo_nu < NFIFO; fifo_nu++) { | |
2077 | ||
2078 | txfifo_endblk = txfifo_startblk + wlc_hw->xmtfifo_sz[fifo_nu]; | |
2079 | txfifo_def = (txfifo_startblk & 0xff) | | |
2080 | (((txfifo_endblk - 1) & 0xff) << TXFIFO_FIFOTOP_SHIFT); | |
2081 | txfifo_def1 = ((txfifo_startblk >> 8) & 0x1) | | |
2082 | ((((txfifo_endblk - | |
2083 | 1) >> 8) & 0x1) << TXFIFO_FIFOTOP_SHIFT); | |
2084 | txfifo_cmd = | |
2085 | TXFIFOCMD_RESET_MASK | (fifo_nu << TXFIFOCMD_FIFOSEL_SHIFT); | |
2086 | ||
16d2812e AS |
2087 | bcma_write16(core, D11REGOFFS(xmtfifocmd), txfifo_cmd); |
2088 | bcma_write16(core, D11REGOFFS(xmtfifodef), txfifo_def); | |
2089 | bcma_write16(core, D11REGOFFS(xmtfifodef1), txfifo_def1); | |
5b435de0 | 2090 | |
16d2812e | 2091 | bcma_write16(core, D11REGOFFS(xmtfifocmd), txfifo_cmd); |
5b435de0 AS |
2092 | |
2093 | txfifo_startblk += wlc_hw->xmtfifo_sz[fifo_nu]; | |
2094 | } | |
2095 | /* | |
2096 | * need to propagate to shm location to be in sync since ucode/hw won't | |
2097 | * do this | |
2098 | */ | |
2099 | brcms_b_write_shm(wlc_hw, M_FIFOSIZE0, | |
2100 | wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]); | |
2101 | brcms_b_write_shm(wlc_hw, M_FIFOSIZE1, | |
2102 | wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]); | |
2103 | brcms_b_write_shm(wlc_hw, M_FIFOSIZE2, | |
2104 | ((wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO] << 8) | wlc_hw-> | |
2105 | xmtfifo_sz[TX_AC_BK_FIFO])); | |
2106 | brcms_b_write_shm(wlc_hw, M_FIFOSIZE3, | |
2107 | ((wlc_hw->xmtfifo_sz[TX_ATIM_FIFO] << 8) | wlc_hw-> | |
2108 | xmtfifo_sz[TX_BCMC_FIFO])); | |
2109 | } | |
2110 | ||
2111 | /* This function is used for changing the tsf frac register | |
2112 | * If spur avoidance mode is off, the mac freq will be 80/120/160Mhz | |
2113 | * If spur avoidance mode is on1, the mac freq will be 82/123/164Mhz | |
2114 | * If spur avoidance mode is on2, the mac freq will be 84/126/168Mhz | |
2115 | * HTPHY Formula is 2^26/freq(MHz) e.g. | |
2116 | * For spuron2 - 126MHz -> 2^26/126 = 532610.0 | |
2117 | * - 532610 = 0x82082 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x2082 | |
2118 | * For spuron: 123MHz -> 2^26/123 = 545600.5 | |
2119 | * - 545601 = 0x85341 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x5341 | |
2120 | * For spur off: 120MHz -> 2^26/120 = 559240.5 | |
2121 | * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889 | |
2122 | */ | |
2123 | ||
2124 | void brcms_b_switch_macfreq(struct brcms_hardware *wlc_hw, u8 spurmode) | |
2125 | { | |
16d2812e | 2126 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 | 2127 | |
b2ffec46 AS |
2128 | if ((ai_get_chip_id(wlc_hw->sih) == BCM43224_CHIP_ID) || |
2129 | (ai_get_chip_id(wlc_hw->sih) == BCM43225_CHIP_ID)) { | |
5b435de0 | 2130 | if (spurmode == WL_SPURAVOID_ON2) { /* 126Mhz */ |
16d2812e AS |
2131 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x2082); |
2132 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0x8); | |
5b435de0 | 2133 | } else if (spurmode == WL_SPURAVOID_ON1) { /* 123Mhz */ |
16d2812e AS |
2134 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x5341); |
2135 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0x8); | |
5b435de0 | 2136 | } else { /* 120Mhz */ |
16d2812e AS |
2137 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x8889); |
2138 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0x8); | |
5b435de0 AS |
2139 | } |
2140 | } else if (BRCMS_ISLCNPHY(wlc_hw->band)) { | |
2141 | if (spurmode == WL_SPURAVOID_ON1) { /* 82Mhz */ | |
16d2812e AS |
2142 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x7CE0); |
2143 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0xC); | |
5b435de0 | 2144 | } else { /* 80Mhz */ |
16d2812e AS |
2145 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0xCCCD); |
2146 | bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0xC); | |
5b435de0 AS |
2147 | } |
2148 | } | |
2149 | } | |
2150 | ||
2151 | /* Initialize GPIOs that are controlled by D11 core */ | |
2152 | static void brcms_c_gpio_init(struct brcms_c_info *wlc) | |
2153 | { | |
2154 | struct brcms_hardware *wlc_hw = wlc->hw; | |
5b435de0 AS |
2155 | u32 gc, gm; |
2156 | ||
5b435de0 AS |
2157 | /* use GPIO select 0 to get all gpio signals from the gpio out reg */ |
2158 | brcms_b_mctrl(wlc_hw, MCTL_GPOUT_SEL_MASK, 0); | |
2159 | ||
2160 | /* | |
2161 | * Common GPIO setup: | |
2162 | * G0 = LED 0 = WLAN Activity | |
2163 | * G1 = LED 1 = WLAN 2.4 GHz Radio State | |
2164 | * G2 = LED 2 = WLAN 5 GHz Radio State | |
2165 | * G4 = radio disable input (HI enabled, LO disabled) | |
2166 | */ | |
2167 | ||
2168 | gc = gm = 0; | |
2169 | ||
2170 | /* Allocate GPIOs for mimo antenna diversity feature */ | |
2171 | if (wlc_hw->antsel_type == ANTSEL_2x3) { | |
2172 | /* Enable antenna diversity, use 2x3 mode */ | |
2173 | brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN, | |
2174 | MHF3_ANTSEL_EN, BRCM_BAND_ALL); | |
2175 | brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE, | |
2176 | MHF3_ANTSEL_MODE, BRCM_BAND_ALL); | |
2177 | ||
2178 | /* init superswitch control */ | |
2179 | wlc_phy_antsel_init(wlc_hw->band->pi, false); | |
2180 | ||
2181 | } else if (wlc_hw->antsel_type == ANTSEL_2x4) { | |
2182 | gm |= gc |= (BOARD_GPIO_12 | BOARD_GPIO_13); | |
2183 | /* | |
2184 | * The board itself is powered by these GPIOs | |
2185 | * (when not sending pattern) so set them high | |
2186 | */ | |
16d2812e AS |
2187 | bcma_set16(wlc_hw->d11core, D11REGOFFS(psm_gpio_oe), |
2188 | (BOARD_GPIO_12 | BOARD_GPIO_13)); | |
2189 | bcma_set16(wlc_hw->d11core, D11REGOFFS(psm_gpio_out), | |
2190 | (BOARD_GPIO_12 | BOARD_GPIO_13)); | |
5b435de0 AS |
2191 | |
2192 | /* Enable antenna diversity, use 2x4 mode */ | |
2193 | brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_EN, | |
2194 | MHF3_ANTSEL_EN, BRCM_BAND_ALL); | |
2195 | brcms_b_mhf(wlc_hw, MHF3, MHF3_ANTSEL_MODE, 0, | |
2196 | BRCM_BAND_ALL); | |
2197 | ||
2198 | /* Configure the desired clock to be 4Mhz */ | |
2199 | brcms_b_write_shm(wlc_hw, M_ANTSEL_CLKDIV, | |
2200 | ANTSEL_CLKDIV_4MHZ); | |
2201 | } | |
2202 | ||
2203 | /* | |
2204 | * gpio 9 controls the PA. ucode is responsible | |
2205 | * for wiggling out and oe | |
2206 | */ | |
2207 | if (wlc_hw->boardflags & BFL_PACTRL) | |
2208 | gm |= gc |= BOARD_GPIO_PACTRL; | |
2209 | ||
2210 | /* apply to gpiocontrol register */ | |
fa0b823b | 2211 | bcma_chipco_gpio_control(&wlc_hw->d11core->bus->drv_cc, gm, gc); |
5b435de0 AS |
2212 | } |
2213 | ||
2214 | static void brcms_ucode_write(struct brcms_hardware *wlc_hw, | |
2215 | const __le32 ucode[], const size_t nbytes) | |
2216 | { | |
16d2812e | 2217 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
2218 | uint i; |
2219 | uint count; | |
2220 | ||
2221 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
2222 | ||
2223 | count = (nbytes / sizeof(u32)); | |
2224 | ||
16d2812e AS |
2225 | bcma_write32(core, D11REGOFFS(objaddr), |
2226 | OBJADDR_AUTO_INC | OBJADDR_UCM_SEL); | |
2227 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
5b435de0 | 2228 | for (i = 0; i < count; i++) |
16d2812e | 2229 | bcma_write32(core, D11REGOFFS(objdata), le32_to_cpu(ucode[i])); |
5b435de0 AS |
2230 | |
2231 | } | |
2232 | ||
2233 | static void brcms_ucode_download(struct brcms_hardware *wlc_hw) | |
2234 | { | |
2235 | struct brcms_c_info *wlc; | |
2236 | struct brcms_ucode *ucode = &wlc_hw->wlc->wl->ucode; | |
2237 | ||
2238 | wlc = wlc_hw->wlc; | |
2239 | ||
2240 | if (wlc_hw->ucode_loaded) | |
2241 | return; | |
2242 | ||
2243 | if (D11REV_IS(wlc_hw->corerev, 23)) { | |
2244 | if (BRCMS_ISNPHY(wlc_hw->band)) { | |
2245 | brcms_ucode_write(wlc_hw, ucode->bcm43xx_16_mimo, | |
2246 | ucode->bcm43xx_16_mimosz); | |
2247 | wlc_hw->ucode_loaded = true; | |
2248 | } else | |
2249 | wiphy_err(wlc->wiphy, "%s: wl%d: unsupported phy in " | |
2250 | "corerev %d\n", | |
2251 | __func__, wlc_hw->unit, wlc_hw->corerev); | |
2252 | } else if (D11REV_IS(wlc_hw->corerev, 24)) { | |
2253 | if (BRCMS_ISLCNPHY(wlc_hw->band)) { | |
2254 | brcms_ucode_write(wlc_hw, ucode->bcm43xx_24_lcn, | |
2255 | ucode->bcm43xx_24_lcnsz); | |
2256 | wlc_hw->ucode_loaded = true; | |
2257 | } else { | |
2258 | wiphy_err(wlc->wiphy, "%s: wl%d: unsupported phy in " | |
2259 | "corerev %d\n", | |
2260 | __func__, wlc_hw->unit, wlc_hw->corerev); | |
2261 | } | |
2262 | } | |
2263 | } | |
2264 | ||
2265 | void brcms_b_txant_set(struct brcms_hardware *wlc_hw, u16 phytxant) | |
2266 | { | |
2267 | /* update sw state */ | |
2268 | wlc_hw->bmac_phytxant = phytxant; | |
2269 | ||
2270 | /* push to ucode if up */ | |
2271 | if (!wlc_hw->up) | |
2272 | return; | |
2273 | brcms_c_ucode_txant_set(wlc_hw); | |
2274 | ||
2275 | } | |
2276 | ||
2277 | u16 brcms_b_get_txant(struct brcms_hardware *wlc_hw) | |
2278 | { | |
2279 | return (u16) wlc_hw->wlc->stf->txant; | |
2280 | } | |
2281 | ||
2282 | void brcms_b_antsel_type_set(struct brcms_hardware *wlc_hw, u8 antsel_type) | |
2283 | { | |
2284 | wlc_hw->antsel_type = antsel_type; | |
2285 | ||
2286 | /* Update the antsel type for phy module to use */ | |
2287 | wlc_phy_antsel_type_set(wlc_hw->band->pi, antsel_type); | |
2288 | } | |
2289 | ||
2290 | static void brcms_b_fifoerrors(struct brcms_hardware *wlc_hw) | |
2291 | { | |
2292 | bool fatal = false; | |
2293 | uint unit; | |
2294 | uint intstatus, idx; | |
16d2812e | 2295 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
2296 | struct wiphy *wiphy = wlc_hw->wlc->wiphy; |
2297 | ||
2298 | unit = wlc_hw->unit; | |
2299 | ||
2300 | for (idx = 0; idx < NFIFO; idx++) { | |
2301 | /* read intstatus register and ignore any non-error bits */ | |
2302 | intstatus = | |
16d2812e AS |
2303 | bcma_read32(core, |
2304 | D11REGOFFS(intctrlregs[idx].intstatus)) & | |
2305 | I_ERRORS; | |
5b435de0 AS |
2306 | if (!intstatus) |
2307 | continue; | |
2308 | ||
2309 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d: intstatus%d 0x%x\n", | |
2310 | unit, idx, intstatus); | |
2311 | ||
2312 | if (intstatus & I_RO) { | |
2313 | wiphy_err(wiphy, "wl%d: fifo %d: receive fifo " | |
2314 | "overflow\n", unit, idx); | |
2315 | fatal = true; | |
2316 | } | |
2317 | ||
2318 | if (intstatus & I_PC) { | |
2319 | wiphy_err(wiphy, "wl%d: fifo %d: descriptor error\n", | |
2320 | unit, idx); | |
2321 | fatal = true; | |
2322 | } | |
2323 | ||
2324 | if (intstatus & I_PD) { | |
2325 | wiphy_err(wiphy, "wl%d: fifo %d: data error\n", unit, | |
2326 | idx); | |
2327 | fatal = true; | |
2328 | } | |
2329 | ||
2330 | if (intstatus & I_DE) { | |
2331 | wiphy_err(wiphy, "wl%d: fifo %d: descriptor protocol " | |
2332 | "error\n", unit, idx); | |
2333 | fatal = true; | |
2334 | } | |
2335 | ||
2336 | if (intstatus & I_RU) | |
2337 | wiphy_err(wiphy, "wl%d: fifo %d: receive descriptor " | |
2338 | "underflow\n", idx, unit); | |
2339 | ||
2340 | if (intstatus & I_XU) { | |
2341 | wiphy_err(wiphy, "wl%d: fifo %d: transmit fifo " | |
2342 | "underflow\n", idx, unit); | |
2343 | fatal = true; | |
2344 | } | |
2345 | ||
2346 | if (fatal) { | |
c261bdf8 | 2347 | brcms_fatal_error(wlc_hw->wlc->wl); /* big hammer */ |
5b435de0 AS |
2348 | break; |
2349 | } else | |
16d2812e AS |
2350 | bcma_write32(core, |
2351 | D11REGOFFS(intctrlregs[idx].intstatus), | |
2352 | intstatus); | |
5b435de0 AS |
2353 | } |
2354 | } | |
2355 | ||
2356 | void brcms_c_intrson(struct brcms_c_info *wlc) | |
2357 | { | |
2358 | struct brcms_hardware *wlc_hw = wlc->hw; | |
2359 | wlc->macintmask = wlc->defmacintmask; | |
16d2812e | 2360 | bcma_write32(wlc_hw->d11core, D11REGOFFS(macintmask), wlc->macintmask); |
5b435de0 AS |
2361 | } |
2362 | ||
5b435de0 AS |
2363 | u32 brcms_c_intrsoff(struct brcms_c_info *wlc) |
2364 | { | |
2365 | struct brcms_hardware *wlc_hw = wlc->hw; | |
2366 | u32 macintmask; | |
2367 | ||
2368 | if (!wlc_hw->clk) | |
2369 | return 0; | |
2370 | ||
2371 | macintmask = wlc->macintmask; /* isr can still happen */ | |
2372 | ||
16d2812e AS |
2373 | bcma_write32(wlc_hw->d11core, D11REGOFFS(macintmask), 0); |
2374 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(macintmask)); | |
5b435de0 AS |
2375 | udelay(1); /* ensure int line is no longer driven */ |
2376 | wlc->macintmask = 0; | |
2377 | ||
2378 | /* return previous macintmask; resolve race between us and our isr */ | |
2379 | return wlc->macintstatus ? 0 : macintmask; | |
2380 | } | |
2381 | ||
2382 | void brcms_c_intrsrestore(struct brcms_c_info *wlc, u32 macintmask) | |
2383 | { | |
2384 | struct brcms_hardware *wlc_hw = wlc->hw; | |
2385 | if (!wlc_hw->clk) | |
2386 | return; | |
2387 | ||
2388 | wlc->macintmask = macintmask; | |
16d2812e | 2389 | bcma_write32(wlc_hw->d11core, D11REGOFFS(macintmask), wlc->macintmask); |
5b435de0 AS |
2390 | } |
2391 | ||
dc460127 | 2392 | /* assumes that the d11 MAC is enabled */ |
5b435de0 AS |
2393 | static void brcms_b_tx_fifo_suspend(struct brcms_hardware *wlc_hw, |
2394 | uint tx_fifo) | |
2395 | { | |
2396 | u8 fifo = 1 << tx_fifo; | |
2397 | ||
2398 | /* Two clients of this code, 11h Quiet period and scanning. */ | |
2399 | ||
2400 | /* only suspend if not already suspended */ | |
2401 | if ((wlc_hw->suspended_fifos & fifo) == fifo) | |
2402 | return; | |
2403 | ||
2404 | /* force the core awake only if not already */ | |
2405 | if (wlc_hw->suspended_fifos == 0) | |
2406 | brcms_c_ucode_wake_override_set(wlc_hw, | |
2407 | BRCMS_WAKE_OVERRIDE_TXFIFO); | |
2408 | ||
2409 | wlc_hw->suspended_fifos |= fifo; | |
2410 | ||
2411 | if (wlc_hw->di[tx_fifo]) { | |
2412 | /* | |
2413 | * Suspending AMPDU transmissions in the middle can cause | |
2414 | * underflow which may result in mismatch between ucode and | |
2415 | * driver so suspend the mac before suspending the FIFO | |
2416 | */ | |
2417 | if (BRCMS_PHY_11N_CAP(wlc_hw->band)) | |
2418 | brcms_c_suspend_mac_and_wait(wlc_hw->wlc); | |
2419 | ||
2420 | dma_txsuspend(wlc_hw->di[tx_fifo]); | |
2421 | ||
2422 | if (BRCMS_PHY_11N_CAP(wlc_hw->band)) | |
2423 | brcms_c_enable_mac(wlc_hw->wlc); | |
2424 | } | |
2425 | } | |
2426 | ||
2427 | static void brcms_b_tx_fifo_resume(struct brcms_hardware *wlc_hw, | |
2428 | uint tx_fifo) | |
2429 | { | |
2430 | /* BMAC_NOTE: BRCMS_TX_FIFO_ENAB is done in brcms_c_dpc() for DMA case | |
2431 | * but need to be done here for PIO otherwise the watchdog will catch | |
2432 | * the inconsistency and fire | |
2433 | */ | |
2434 | /* Two clients of this code, 11h Quiet period and scanning. */ | |
2435 | if (wlc_hw->di[tx_fifo]) | |
2436 | dma_txresume(wlc_hw->di[tx_fifo]); | |
2437 | ||
2438 | /* allow core to sleep again */ | |
2439 | if (wlc_hw->suspended_fifos == 0) | |
2440 | return; | |
2441 | else { | |
2442 | wlc_hw->suspended_fifos &= ~(1 << tx_fifo); | |
2443 | if (wlc_hw->suspended_fifos == 0) | |
2444 | brcms_c_ucode_wake_override_clear(wlc_hw, | |
2445 | BRCMS_WAKE_OVERRIDE_TXFIFO); | |
2446 | } | |
2447 | } | |
2448 | ||
a8bc4917 | 2449 | /* precondition: requires the mac core to be enabled */ |
c6c44893 | 2450 | static void brcms_b_mute(struct brcms_hardware *wlc_hw, bool mute_tx) |
5b435de0 AS |
2451 | { |
2452 | static const u8 null_ether_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0}; | |
2453 | ||
c6c44893 | 2454 | if (mute_tx) { |
5b435de0 AS |
2455 | /* suspend tx fifos */ |
2456 | brcms_b_tx_fifo_suspend(wlc_hw, TX_DATA_FIFO); | |
2457 | brcms_b_tx_fifo_suspend(wlc_hw, TX_CTL_FIFO); | |
2458 | brcms_b_tx_fifo_suspend(wlc_hw, TX_AC_BK_FIFO); | |
2459 | brcms_b_tx_fifo_suspend(wlc_hw, TX_AC_VI_FIFO); | |
2460 | ||
2461 | /* zero the address match register so we do not send ACKs */ | |
2462 | brcms_b_set_addrmatch(wlc_hw, RCM_MAC_OFFSET, | |
2463 | null_ether_addr); | |
2464 | } else { | |
2465 | /* resume tx fifos */ | |
2466 | brcms_b_tx_fifo_resume(wlc_hw, TX_DATA_FIFO); | |
2467 | brcms_b_tx_fifo_resume(wlc_hw, TX_CTL_FIFO); | |
2468 | brcms_b_tx_fifo_resume(wlc_hw, TX_AC_BK_FIFO); | |
2469 | brcms_b_tx_fifo_resume(wlc_hw, TX_AC_VI_FIFO); | |
2470 | ||
2471 | /* Restore address */ | |
2472 | brcms_b_set_addrmatch(wlc_hw, RCM_MAC_OFFSET, | |
2473 | wlc_hw->etheraddr); | |
2474 | } | |
2475 | ||
c6c44893 | 2476 | wlc_phy_mute_upd(wlc_hw->band->pi, mute_tx, 0); |
5b435de0 | 2477 | |
c6c44893 | 2478 | if (mute_tx) |
5b435de0 AS |
2479 | brcms_c_ucode_mute_override_set(wlc_hw); |
2480 | else | |
2481 | brcms_c_ucode_mute_override_clear(wlc_hw); | |
2482 | } | |
2483 | ||
dc460127 RV |
2484 | void |
2485 | brcms_c_mute(struct brcms_c_info *wlc, bool mute_tx) | |
2486 | { | |
2487 | brcms_b_mute(wlc->hw, mute_tx); | |
2488 | } | |
2489 | ||
5b435de0 AS |
2490 | /* |
2491 | * Read and clear macintmask and macintstatus and intstatus registers. | |
2492 | * This routine should be called with interrupts off | |
2493 | * Return: | |
2494 | * -1 if brcms_deviceremoved(wlc) evaluates to true; | |
2495 | * 0 if the interrupt is not for us, or we are in some special cases; | |
2496 | * device interrupt status bits otherwise. | |
2497 | */ | |
2498 | static inline u32 wlc_intstatus(struct brcms_c_info *wlc, bool in_isr) | |
2499 | { | |
2500 | struct brcms_hardware *wlc_hw = wlc->hw; | |
16d2812e | 2501 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
2502 | u32 macintstatus; |
2503 | ||
2504 | /* macintstatus includes a DMA interrupt summary bit */ | |
16d2812e | 2505 | macintstatus = bcma_read32(core, D11REGOFFS(macintstatus)); |
5b435de0 AS |
2506 | |
2507 | BCMMSG(wlc->wiphy, "wl%d: macintstatus: 0x%x\n", wlc_hw->unit, | |
2508 | macintstatus); | |
2509 | ||
2510 | /* detect cardbus removed, in power down(suspend) and in reset */ | |
2511 | if (brcms_deviceremoved(wlc)) | |
2512 | return -1; | |
2513 | ||
2514 | /* brcms_deviceremoved() succeeds even when the core is still resetting, | |
2515 | * handle that case here. | |
2516 | */ | |
2517 | if (macintstatus == 0xffffffff) | |
2518 | return 0; | |
2519 | ||
2520 | /* defer unsolicited interrupts */ | |
2521 | macintstatus &= (in_isr ? wlc->macintmask : wlc->defmacintmask); | |
2522 | ||
2523 | /* if not for us */ | |
2524 | if (macintstatus == 0) | |
2525 | return 0; | |
2526 | ||
2527 | /* interrupts are already turned off for CFE build | |
2528 | * Caution: For CFE Turning off the interrupts again has some undesired | |
2529 | * consequences | |
2530 | */ | |
2531 | /* turn off the interrupts */ | |
16d2812e AS |
2532 | bcma_write32(core, D11REGOFFS(macintmask), 0); |
2533 | (void)bcma_read32(core, D11REGOFFS(macintmask)); | |
5b435de0 AS |
2534 | wlc->macintmask = 0; |
2535 | ||
2536 | /* clear device interrupts */ | |
16d2812e | 2537 | bcma_write32(core, D11REGOFFS(macintstatus), macintstatus); |
5b435de0 AS |
2538 | |
2539 | /* MI_DMAINT is indication of non-zero intstatus */ | |
2540 | if (macintstatus & MI_DMAINT) | |
2541 | /* | |
2542 | * only fifo interrupt enabled is I_RI in | |
2543 | * RX_FIFO. If MI_DMAINT is set, assume it | |
2544 | * is set and clear the interrupt. | |
2545 | */ | |
16d2812e AS |
2546 | bcma_write32(core, D11REGOFFS(intctrlregs[RX_FIFO].intstatus), |
2547 | DEF_RXINTMASK); | |
5b435de0 AS |
2548 | |
2549 | return macintstatus; | |
2550 | } | |
2551 | ||
2552 | /* Update wlc->macintstatus and wlc->intstatus[]. */ | |
2553 | /* Return true if they are updated successfully. false otherwise */ | |
2554 | bool brcms_c_intrsupd(struct brcms_c_info *wlc) | |
2555 | { | |
2556 | u32 macintstatus; | |
2557 | ||
2558 | /* read and clear macintstatus and intstatus registers */ | |
2559 | macintstatus = wlc_intstatus(wlc, false); | |
2560 | ||
2561 | /* device is removed */ | |
2562 | if (macintstatus == 0xffffffff) | |
2563 | return false; | |
2564 | ||
2565 | /* update interrupt status in software */ | |
2566 | wlc->macintstatus |= macintstatus; | |
2567 | ||
2568 | return true; | |
2569 | } | |
2570 | ||
2571 | /* | |
2572 | * First-level interrupt processing. | |
2573 | * Return true if this was our interrupt, false otherwise. | |
2574 | * *wantdpc will be set to true if further brcms_c_dpc() processing is required, | |
2575 | * false otherwise. | |
2576 | */ | |
2577 | bool brcms_c_isr(struct brcms_c_info *wlc, bool *wantdpc) | |
2578 | { | |
2579 | struct brcms_hardware *wlc_hw = wlc->hw; | |
2580 | u32 macintstatus; | |
2581 | ||
2582 | *wantdpc = false; | |
2583 | ||
2584 | if (!wlc_hw->up || !wlc->macintmask) | |
2585 | return false; | |
2586 | ||
2587 | /* read and clear macintstatus and intstatus registers */ | |
2588 | macintstatus = wlc_intstatus(wlc, true); | |
2589 | ||
2590 | if (macintstatus == 0xffffffff) | |
2591 | wiphy_err(wlc->wiphy, "DEVICEREMOVED detected in the ISR code" | |
2592 | " path\n"); | |
2593 | ||
2594 | /* it is not for us */ | |
2595 | if (macintstatus == 0) | |
2596 | return false; | |
2597 | ||
2598 | *wantdpc = true; | |
2599 | ||
2600 | /* save interrupt status bits */ | |
2601 | wlc->macintstatus = macintstatus; | |
2602 | ||
2603 | return true; | |
2604 | ||
2605 | } | |
2606 | ||
2607 | void brcms_c_suspend_mac_and_wait(struct brcms_c_info *wlc) | |
2608 | { | |
2609 | struct brcms_hardware *wlc_hw = wlc->hw; | |
16d2812e | 2610 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
2611 | u32 mc, mi; |
2612 | struct wiphy *wiphy = wlc->wiphy; | |
2613 | ||
2614 | BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit, | |
2615 | wlc_hw->band->bandunit); | |
2616 | ||
2617 | /* | |
2618 | * Track overlapping suspend requests | |
2619 | */ | |
2620 | wlc_hw->mac_suspend_depth++; | |
2621 | if (wlc_hw->mac_suspend_depth > 1) | |
2622 | return; | |
2623 | ||
2624 | /* force the core awake */ | |
2625 | brcms_c_ucode_wake_override_set(wlc_hw, BRCMS_WAKE_OVERRIDE_MACSUSPEND); | |
2626 | ||
16d2812e | 2627 | mc = bcma_read32(core, D11REGOFFS(maccontrol)); |
5b435de0 AS |
2628 | |
2629 | if (mc == 0xffffffff) { | |
2630 | wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit, | |
2631 | __func__); | |
2632 | brcms_down(wlc->wl); | |
2633 | return; | |
2634 | } | |
2635 | WARN_ON(mc & MCTL_PSM_JMP_0); | |
2636 | WARN_ON(!(mc & MCTL_PSM_RUN)); | |
2637 | WARN_ON(!(mc & MCTL_EN_MAC)); | |
2638 | ||
16d2812e | 2639 | mi = bcma_read32(core, D11REGOFFS(macintstatus)); |
5b435de0 AS |
2640 | if (mi == 0xffffffff) { |
2641 | wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit, | |
2642 | __func__); | |
2643 | brcms_down(wlc->wl); | |
2644 | return; | |
2645 | } | |
2646 | WARN_ON(mi & MI_MACSSPNDD); | |
2647 | ||
2648 | brcms_b_mctrl(wlc_hw, MCTL_EN_MAC, 0); | |
2649 | ||
16d2812e | 2650 | SPINWAIT(!(bcma_read32(core, D11REGOFFS(macintstatus)) & MI_MACSSPNDD), |
5b435de0 AS |
2651 | BRCMS_MAX_MAC_SUSPEND); |
2652 | ||
16d2812e | 2653 | if (!(bcma_read32(core, D11REGOFFS(macintstatus)) & MI_MACSSPNDD)) { |
5b435de0 AS |
2654 | wiphy_err(wiphy, "wl%d: wlc_suspend_mac_and_wait: waited %d uS" |
2655 | " and MI_MACSSPNDD is still not on.\n", | |
2656 | wlc_hw->unit, BRCMS_MAX_MAC_SUSPEND); | |
2657 | wiphy_err(wiphy, "wl%d: psmdebug 0x%08x, phydebug 0x%08x, " | |
2658 | "psm_brc 0x%04x\n", wlc_hw->unit, | |
16d2812e AS |
2659 | bcma_read32(core, D11REGOFFS(psmdebug)), |
2660 | bcma_read32(core, D11REGOFFS(phydebug)), | |
2661 | bcma_read16(core, D11REGOFFS(psm_brc))); | |
5b435de0 AS |
2662 | } |
2663 | ||
16d2812e | 2664 | mc = bcma_read32(core, D11REGOFFS(maccontrol)); |
5b435de0 AS |
2665 | if (mc == 0xffffffff) { |
2666 | wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit, | |
2667 | __func__); | |
2668 | brcms_down(wlc->wl); | |
2669 | return; | |
2670 | } | |
2671 | WARN_ON(mc & MCTL_PSM_JMP_0); | |
2672 | WARN_ON(!(mc & MCTL_PSM_RUN)); | |
2673 | WARN_ON(mc & MCTL_EN_MAC); | |
2674 | } | |
2675 | ||
2676 | void brcms_c_enable_mac(struct brcms_c_info *wlc) | |
2677 | { | |
2678 | struct brcms_hardware *wlc_hw = wlc->hw; | |
16d2812e | 2679 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
2680 | u32 mc, mi; |
2681 | ||
2682 | BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", wlc_hw->unit, | |
2683 | wlc->band->bandunit); | |
2684 | ||
2685 | /* | |
2686 | * Track overlapping suspend requests | |
2687 | */ | |
2688 | wlc_hw->mac_suspend_depth--; | |
2689 | if (wlc_hw->mac_suspend_depth > 0) | |
2690 | return; | |
2691 | ||
16d2812e | 2692 | mc = bcma_read32(core, D11REGOFFS(maccontrol)); |
5b435de0 AS |
2693 | WARN_ON(mc & MCTL_PSM_JMP_0); |
2694 | WARN_ON(mc & MCTL_EN_MAC); | |
2695 | WARN_ON(!(mc & MCTL_PSM_RUN)); | |
2696 | ||
2697 | brcms_b_mctrl(wlc_hw, MCTL_EN_MAC, MCTL_EN_MAC); | |
16d2812e | 2698 | bcma_write32(core, D11REGOFFS(macintstatus), MI_MACSSPNDD); |
5b435de0 | 2699 | |
16d2812e | 2700 | mc = bcma_read32(core, D11REGOFFS(maccontrol)); |
5b435de0 AS |
2701 | WARN_ON(mc & MCTL_PSM_JMP_0); |
2702 | WARN_ON(!(mc & MCTL_EN_MAC)); | |
2703 | WARN_ON(!(mc & MCTL_PSM_RUN)); | |
2704 | ||
16d2812e | 2705 | mi = bcma_read32(core, D11REGOFFS(macintstatus)); |
5b435de0 AS |
2706 | WARN_ON(mi & MI_MACSSPNDD); |
2707 | ||
2708 | brcms_c_ucode_wake_override_clear(wlc_hw, | |
2709 | BRCMS_WAKE_OVERRIDE_MACSUSPEND); | |
2710 | } | |
2711 | ||
2712 | void brcms_b_band_stf_ss_set(struct brcms_hardware *wlc_hw, u8 stf_mode) | |
2713 | { | |
2714 | wlc_hw->hw_stf_ss_opmode = stf_mode; | |
2715 | ||
2716 | if (wlc_hw->clk) | |
2717 | brcms_upd_ofdm_pctl1_table(wlc_hw); | |
2718 | } | |
2719 | ||
2720 | static bool brcms_b_validate_chip_access(struct brcms_hardware *wlc_hw) | |
2721 | { | |
16d2812e | 2722 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
2723 | u32 w, val; |
2724 | struct wiphy *wiphy = wlc_hw->wlc->wiphy; | |
2725 | ||
2726 | BCMMSG(wiphy, "wl%d\n", wlc_hw->unit); | |
2727 | ||
5b435de0 AS |
2728 | /* Validate dchip register access */ |
2729 | ||
16d2812e AS |
2730 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
2731 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
2732 | w = bcma_read32(core, D11REGOFFS(objdata)); | |
5b435de0 AS |
2733 | |
2734 | /* Can we write and read back a 32bit register? */ | |
16d2812e AS |
2735 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
2736 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
2737 | bcma_write32(core, D11REGOFFS(objdata), (u32) 0xaa5555aa); | |
5b435de0 | 2738 | |
16d2812e AS |
2739 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
2740 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
2741 | val = bcma_read32(core, D11REGOFFS(objdata)); | |
5b435de0 AS |
2742 | if (val != (u32) 0xaa5555aa) { |
2743 | wiphy_err(wiphy, "wl%d: validate_chip_access: SHM = 0x%x, " | |
2744 | "expected 0xaa5555aa\n", wlc_hw->unit, val); | |
2745 | return false; | |
2746 | } | |
2747 | ||
16d2812e AS |
2748 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
2749 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
2750 | bcma_write32(core, D11REGOFFS(objdata), (u32) 0x55aaaa55); | |
5b435de0 | 2751 | |
16d2812e AS |
2752 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
2753 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
2754 | val = bcma_read32(core, D11REGOFFS(objdata)); | |
5b435de0 AS |
2755 | if (val != (u32) 0x55aaaa55) { |
2756 | wiphy_err(wiphy, "wl%d: validate_chip_access: SHM = 0x%x, " | |
2757 | "expected 0x55aaaa55\n", wlc_hw->unit, val); | |
2758 | return false; | |
2759 | } | |
2760 | ||
16d2812e AS |
2761 | bcma_write32(core, D11REGOFFS(objaddr), OBJADDR_SHM_SEL | 0); |
2762 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
2763 | bcma_write32(core, D11REGOFFS(objdata), w); | |
5b435de0 AS |
2764 | |
2765 | /* clear CFPStart */ | |
16d2812e | 2766 | bcma_write32(core, D11REGOFFS(tsf_cfpstart), 0); |
5b435de0 | 2767 | |
16d2812e | 2768 | w = bcma_read32(core, D11REGOFFS(maccontrol)); |
5b435de0 AS |
2769 | if ((w != (MCTL_IHR_EN | MCTL_WAKE)) && |
2770 | (w != (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))) { | |
2771 | wiphy_err(wiphy, "wl%d: validate_chip_access: maccontrol = " | |
2772 | "0x%x, expected 0x%x or 0x%x\n", wlc_hw->unit, w, | |
2773 | (MCTL_IHR_EN | MCTL_WAKE), | |
2774 | (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE)); | |
2775 | return false; | |
2776 | } | |
2777 | ||
2778 | return true; | |
2779 | } | |
2780 | ||
2781 | #define PHYPLL_WAIT_US 100000 | |
2782 | ||
2783 | void brcms_b_core_phypll_ctl(struct brcms_hardware *wlc_hw, bool on) | |
2784 | { | |
16d2812e | 2785 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
2786 | u32 tmp; |
2787 | ||
2788 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
2789 | ||
2790 | tmp = 0; | |
5b435de0 AS |
2791 | |
2792 | if (on) { | |
b2ffec46 | 2793 | if ((ai_get_chip_id(wlc_hw->sih) == BCM4313_CHIP_ID)) { |
16d2812e AS |
2794 | bcma_set32(core, D11REGOFFS(clk_ctl_st), |
2795 | CCS_ERSRC_REQ_HT | | |
2796 | CCS_ERSRC_REQ_D11PLL | | |
2797 | CCS_ERSRC_REQ_PHYPLL); | |
2798 | SPINWAIT((bcma_read32(core, D11REGOFFS(clk_ctl_st)) & | |
2799 | CCS_ERSRC_AVAIL_HT) != CCS_ERSRC_AVAIL_HT, | |
5b435de0 AS |
2800 | PHYPLL_WAIT_US); |
2801 | ||
16d2812e AS |
2802 | tmp = bcma_read32(core, D11REGOFFS(clk_ctl_st)); |
2803 | if ((tmp & CCS_ERSRC_AVAIL_HT) != CCS_ERSRC_AVAIL_HT) | |
5b435de0 AS |
2804 | wiphy_err(wlc_hw->wlc->wiphy, "%s: turn on PHY" |
2805 | " PLL failed\n", __func__); | |
2806 | } else { | |
16d2812e AS |
2807 | bcma_set32(core, D11REGOFFS(clk_ctl_st), |
2808 | tmp | CCS_ERSRC_REQ_D11PLL | | |
2809 | CCS_ERSRC_REQ_PHYPLL); | |
2810 | SPINWAIT((bcma_read32(core, D11REGOFFS(clk_ctl_st)) & | |
5b435de0 AS |
2811 | (CCS_ERSRC_AVAIL_D11PLL | |
2812 | CCS_ERSRC_AVAIL_PHYPLL)) != | |
2813 | (CCS_ERSRC_AVAIL_D11PLL | | |
2814 | CCS_ERSRC_AVAIL_PHYPLL), PHYPLL_WAIT_US); | |
2815 | ||
16d2812e | 2816 | tmp = bcma_read32(core, D11REGOFFS(clk_ctl_st)); |
5b435de0 AS |
2817 | if ((tmp & |
2818 | (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) | |
2819 | != | |
2820 | (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) | |
2821 | wiphy_err(wlc_hw->wlc->wiphy, "%s: turn on " | |
2822 | "PHY PLL failed\n", __func__); | |
2823 | } | |
2824 | } else { | |
2825 | /* | |
2826 | * Since the PLL may be shared, other cores can still | |
2827 | * be requesting it; so we'll deassert the request but | |
2828 | * not wait for status to comply. | |
2829 | */ | |
16d2812e AS |
2830 | bcma_mask32(core, D11REGOFFS(clk_ctl_st), |
2831 | ~CCS_ERSRC_REQ_PHYPLL); | |
2832 | (void)bcma_read32(core, D11REGOFFS(clk_ctl_st)); | |
5b435de0 AS |
2833 | } |
2834 | } | |
2835 | ||
94bdc2a2 | 2836 | static void brcms_c_coredisable(struct brcms_hardware *wlc_hw) |
5b435de0 AS |
2837 | { |
2838 | bool dev_gone; | |
2839 | ||
2840 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
2841 | ||
2842 | dev_gone = brcms_deviceremoved(wlc_hw->wlc); | |
2843 | ||
2844 | if (dev_gone) | |
2845 | return; | |
2846 | ||
2847 | if (wlc_hw->noreset) | |
2848 | return; | |
2849 | ||
2850 | /* radio off */ | |
2851 | wlc_phy_switch_radio(wlc_hw->band->pi, OFF); | |
2852 | ||
2853 | /* turn off analog core */ | |
2854 | wlc_phy_anacore(wlc_hw->band->pi, OFF); | |
2855 | ||
2856 | /* turn off PHYPLL to save power */ | |
2857 | brcms_b_core_phypll_ctl(wlc_hw, false); | |
2858 | ||
2859 | wlc_hw->clk = false; | |
a8779e4a | 2860 | bcma_core_disable(wlc_hw->d11core, 0); |
5b435de0 AS |
2861 | wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false); |
2862 | } | |
2863 | ||
2864 | static void brcms_c_flushqueues(struct brcms_c_info *wlc) | |
2865 | { | |
2866 | struct brcms_hardware *wlc_hw = wlc->hw; | |
2867 | uint i; | |
2868 | ||
2869 | /* free any posted tx packets */ | |
2870 | for (i = 0; i < NFIFO; i++) | |
2871 | if (wlc_hw->di[i]) { | |
2872 | dma_txreclaim(wlc_hw->di[i], DMA_RANGE_ALL); | |
2873 | wlc->core->txpktpend[i] = 0; | |
2874 | BCMMSG(wlc->wiphy, "pktpend fifo %d clrd\n", i); | |
2875 | } | |
2876 | ||
2877 | /* free any posted rx packets */ | |
2878 | dma_rxreclaim(wlc_hw->di[RX_FIFO]); | |
2879 | } | |
2880 | ||
2881 | static u16 | |
2882 | brcms_b_read_objmem(struct brcms_hardware *wlc_hw, uint offset, u32 sel) | |
2883 | { | |
16d2812e AS |
2884 | struct bcma_device *core = wlc_hw->d11core; |
2885 | u16 objoff = D11REGOFFS(objdata); | |
5b435de0 | 2886 | |
16d2812e AS |
2887 | bcma_write32(core, D11REGOFFS(objaddr), sel | (offset >> 2)); |
2888 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
5b435de0 | 2889 | if (offset & 2) |
16d2812e | 2890 | objoff += 2; |
5b435de0 | 2891 | |
16d2812e | 2892 | return bcma_read16(core, objoff); |
5b435de0 AS |
2893 | } |
2894 | ||
2895 | static void | |
2896 | brcms_b_write_objmem(struct brcms_hardware *wlc_hw, uint offset, u16 v, | |
2897 | u32 sel) | |
2898 | { | |
16d2812e AS |
2899 | struct bcma_device *core = wlc_hw->d11core; |
2900 | u16 objoff = D11REGOFFS(objdata); | |
5b435de0 | 2901 | |
16d2812e AS |
2902 | bcma_write32(core, D11REGOFFS(objaddr), sel | (offset >> 2)); |
2903 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
5b435de0 | 2904 | if (offset & 2) |
16d2812e AS |
2905 | objoff += 2; |
2906 | ||
2907 | bcma_write16(core, objoff, v); | |
5b435de0 AS |
2908 | } |
2909 | ||
2910 | /* | |
2911 | * Read a single u16 from shared memory. | |
2912 | * SHM 'offset' needs to be an even address | |
2913 | */ | |
2914 | u16 brcms_b_read_shm(struct brcms_hardware *wlc_hw, uint offset) | |
2915 | { | |
2916 | return brcms_b_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL); | |
2917 | } | |
2918 | ||
2919 | /* | |
2920 | * Write a single u16 to shared memory. | |
2921 | * SHM 'offset' needs to be an even address | |
2922 | */ | |
2923 | void brcms_b_write_shm(struct brcms_hardware *wlc_hw, uint offset, u16 v) | |
2924 | { | |
2925 | brcms_b_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL); | |
2926 | } | |
2927 | ||
2928 | /* | |
2929 | * Copy a buffer to shared memory of specified type . | |
2930 | * SHM 'offset' needs to be an even address and | |
2931 | * Buffer length 'len' must be an even number of bytes | |
2932 | * 'sel' selects the type of memory | |
2933 | */ | |
2934 | void | |
2935 | brcms_b_copyto_objmem(struct brcms_hardware *wlc_hw, uint offset, | |
2936 | const void *buf, int len, u32 sel) | |
2937 | { | |
2938 | u16 v; | |
2939 | const u8 *p = (const u8 *)buf; | |
2940 | int i; | |
2941 | ||
2942 | if (len <= 0 || (offset & 1) || (len & 1)) | |
2943 | return; | |
2944 | ||
2945 | for (i = 0; i < len; i += 2) { | |
2946 | v = p[i] | (p[i + 1] << 8); | |
2947 | brcms_b_write_objmem(wlc_hw, offset + i, v, sel); | |
2948 | } | |
2949 | } | |
2950 | ||
2951 | /* | |
2952 | * Copy a piece of shared memory of specified type to a buffer . | |
2953 | * SHM 'offset' needs to be an even address and | |
2954 | * Buffer length 'len' must be an even number of bytes | |
2955 | * 'sel' selects the type of memory | |
2956 | */ | |
2957 | void | |
2958 | brcms_b_copyfrom_objmem(struct brcms_hardware *wlc_hw, uint offset, void *buf, | |
2959 | int len, u32 sel) | |
2960 | { | |
2961 | u16 v; | |
2962 | u8 *p = (u8 *) buf; | |
2963 | int i; | |
2964 | ||
2965 | if (len <= 0 || (offset & 1) || (len & 1)) | |
2966 | return; | |
2967 | ||
2968 | for (i = 0; i < len; i += 2) { | |
2969 | v = brcms_b_read_objmem(wlc_hw, offset + i, sel); | |
2970 | p[i] = v & 0xFF; | |
2971 | p[i + 1] = (v >> 8) & 0xFF; | |
2972 | } | |
2973 | } | |
2974 | ||
94bdc2a2 AB |
2975 | /* Copy a buffer to shared memory. |
2976 | * SHM 'offset' needs to be an even address and | |
2977 | * Buffer length 'len' must be an even number of bytes | |
2978 | */ | |
2979 | static void brcms_c_copyto_shm(struct brcms_c_info *wlc, uint offset, | |
2980 | const void *buf, int len) | |
2981 | { | |
2982 | brcms_b_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL); | |
2983 | } | |
2984 | ||
5b435de0 AS |
2985 | static void brcms_b_retrylimit_upd(struct brcms_hardware *wlc_hw, |
2986 | u16 SRL, u16 LRL) | |
2987 | { | |
2988 | wlc_hw->SRL = SRL; | |
2989 | wlc_hw->LRL = LRL; | |
2990 | ||
2991 | /* write retry limit to SCR, shouldn't need to suspend */ | |
2992 | if (wlc_hw->up) { | |
16d2812e AS |
2993 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objaddr), |
2994 | OBJADDR_SCR_SEL | S_DOT11_SRC_LMT); | |
2995 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(objaddr)); | |
2996 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objdata), wlc_hw->SRL); | |
2997 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objaddr), | |
2998 | OBJADDR_SCR_SEL | S_DOT11_LRC_LMT); | |
2999 | (void)bcma_read32(wlc_hw->d11core, D11REGOFFS(objaddr)); | |
3000 | bcma_write32(wlc_hw->d11core, D11REGOFFS(objdata), wlc_hw->LRL); | |
5b435de0 AS |
3001 | } |
3002 | } | |
3003 | ||
3004 | static void brcms_b_pllreq(struct brcms_hardware *wlc_hw, bool set, u32 req_bit) | |
3005 | { | |
3006 | if (set) { | |
3007 | if (mboolisset(wlc_hw->pllreq, req_bit)) | |
3008 | return; | |
3009 | ||
3010 | mboolset(wlc_hw->pllreq, req_bit); | |
3011 | ||
3012 | if (mboolisset(wlc_hw->pllreq, BRCMS_PLLREQ_FLIP)) { | |
3013 | if (!wlc_hw->sbclk) | |
3014 | brcms_b_xtal(wlc_hw, ON); | |
3015 | } | |
3016 | } else { | |
3017 | if (!mboolisset(wlc_hw->pllreq, req_bit)) | |
3018 | return; | |
3019 | ||
3020 | mboolclr(wlc_hw->pllreq, req_bit); | |
3021 | ||
3022 | if (mboolisset(wlc_hw->pllreq, BRCMS_PLLREQ_FLIP)) { | |
3023 | if (wlc_hw->sbclk) | |
3024 | brcms_b_xtal(wlc_hw, OFF); | |
3025 | } | |
3026 | } | |
3027 | } | |
3028 | ||
3029 | static void brcms_b_antsel_set(struct brcms_hardware *wlc_hw, u32 antsel_avail) | |
3030 | { | |
3031 | wlc_hw->antsel_avail = antsel_avail; | |
3032 | } | |
3033 | ||
3034 | /* | |
3035 | * conditions under which the PM bit should be set in outgoing frames | |
3036 | * and STAY_AWAKE is meaningful | |
3037 | */ | |
94bdc2a2 | 3038 | static bool brcms_c_ps_allowed(struct brcms_c_info *wlc) |
5b435de0 AS |
3039 | { |
3040 | struct brcms_bss_cfg *cfg = wlc->bsscfg; | |
3041 | ||
3042 | /* disallow PS when one of the following global conditions meets */ | |
3043 | if (!wlc->pub->associated) | |
3044 | return false; | |
3045 | ||
3046 | /* disallow PS when one of these meets when not scanning */ | |
be667669 | 3047 | if (wlc->filter_flags & FIF_PROMISC_IN_BSS) |
5b435de0 AS |
3048 | return false; |
3049 | ||
3050 | if (cfg->associated) { | |
3051 | /* | |
3052 | * disallow PS when one of the following | |
3053 | * bsscfg specific conditions meets | |
3054 | */ | |
3055 | if (!cfg->BSS) | |
3056 | return false; | |
3057 | ||
3058 | return false; | |
3059 | } | |
3060 | ||
3061 | return true; | |
3062 | } | |
3063 | ||
94bdc2a2 AB |
3064 | static void brcms_c_statsupd(struct brcms_c_info *wlc) |
3065 | { | |
3066 | int i; | |
3067 | struct macstat macstats; | |
8ae74654 | 3068 | #ifdef DEBUG |
94bdc2a2 AB |
3069 | u16 delta; |
3070 | u16 rxf0ovfl; | |
3071 | u16 txfunfl[NFIFO]; | |
8ae74654 | 3072 | #endif /* DEBUG */ |
94bdc2a2 AB |
3073 | |
3074 | /* if driver down, make no sense to update stats */ | |
3075 | if (!wlc->pub->up) | |
3076 | return; | |
3077 | ||
8ae74654 | 3078 | #ifdef DEBUG |
94bdc2a2 AB |
3079 | /* save last rx fifo 0 overflow count */ |
3080 | rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl; | |
3081 | ||
3082 | /* save last tx fifo underflow count */ | |
3083 | for (i = 0; i < NFIFO; i++) | |
3084 | txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i]; | |
8ae74654 | 3085 | #endif /* DEBUG */ |
94bdc2a2 AB |
3086 | |
3087 | /* Read mac stats from contiguous shared memory */ | |
3088 | brcms_b_copyfrom_objmem(wlc->hw, M_UCODE_MACSTAT, &macstats, | |
3089 | sizeof(struct macstat), OBJADDR_SHM_SEL); | |
3090 | ||
8ae74654 | 3091 | #ifdef DEBUG |
94bdc2a2 AB |
3092 | /* check for rx fifo 0 overflow */ |
3093 | delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl); | |
3094 | if (delta) | |
3095 | wiphy_err(wlc->wiphy, "wl%d: %u rx fifo 0 overflows!\n", | |
3096 | wlc->pub->unit, delta); | |
3097 | ||
3098 | /* check for tx fifo underflows */ | |
3099 | for (i = 0; i < NFIFO; i++) { | |
3100 | delta = | |
3101 | (u16) (wlc->core->macstat_snapshot->txfunfl[i] - | |
3102 | txfunfl[i]); | |
3103 | if (delta) | |
3104 | wiphy_err(wlc->wiphy, "wl%d: %u tx fifo %d underflows!" | |
3105 | "\n", wlc->pub->unit, delta, i); | |
3106 | } | |
8ae74654 | 3107 | #endif /* DEBUG */ |
94bdc2a2 AB |
3108 | |
3109 | /* merge counters from dma module */ | |
3110 | for (i = 0; i < NFIFO; i++) { | |
3111 | if (wlc->hw->di[i]) | |
3112 | dma_counterreset(wlc->hw->di[i]); | |
3113 | } | |
3114 | } | |
3115 | ||
5b435de0 AS |
3116 | static void brcms_b_reset(struct brcms_hardware *wlc_hw) |
3117 | { | |
3118 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
3119 | ||
3120 | /* reset the core */ | |
3121 | if (!brcms_deviceremoved(wlc_hw->wlc)) | |
3122 | brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS); | |
3123 | ||
3124 | /* purge the dma rings */ | |
3125 | brcms_c_flushqueues(wlc_hw->wlc); | |
3126 | } | |
3127 | ||
3128 | void brcms_c_reset(struct brcms_c_info *wlc) | |
3129 | { | |
3130 | BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit); | |
3131 | ||
3132 | /* slurp up hw mac counters before core reset */ | |
3133 | brcms_c_statsupd(wlc); | |
3134 | ||
3135 | /* reset our snapshot of macstat counters */ | |
3136 | memset((char *)wlc->core->macstat_snapshot, 0, | |
3137 | sizeof(struct macstat)); | |
3138 | ||
3139 | brcms_b_reset(wlc->hw); | |
3140 | } | |
3141 | ||
5b435de0 AS |
3142 | /* Return the channel the driver should initialize during brcms_c_init. |
3143 | * the channel may have to be changed from the currently configured channel | |
3144 | * if other configurations are in conflict (bandlocked, 11n mode disabled, | |
3145 | * invalid channel for current country, etc.) | |
3146 | */ | |
3147 | static u16 brcms_c_init_chanspec(struct brcms_c_info *wlc) | |
3148 | { | |
3149 | u16 chanspec = | |
3150 | 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE | | |
3151 | WL_CHANSPEC_BAND_2G; | |
3152 | ||
3153 | return chanspec; | |
3154 | } | |
3155 | ||
3156 | void brcms_c_init_scb(struct scb *scb) | |
3157 | { | |
3158 | int i; | |
3159 | ||
3160 | memset(scb, 0, sizeof(struct scb)); | |
3161 | scb->flags = SCB_WMECAP | SCB_HTCAP; | |
3162 | for (i = 0; i < NUMPRIO; i++) { | |
3163 | scb->seqnum[i] = 0; | |
3164 | scb->seqctl[i] = 0xFFFF; | |
3165 | } | |
3166 | ||
3167 | scb->seqctl_nonqos = 0xFFFF; | |
3168 | scb->magic = SCB_MAGIC; | |
3169 | } | |
3170 | ||
3171 | /* d11 core init | |
3172 | * reset PSM | |
3173 | * download ucode/PCM | |
3174 | * let ucode run to suspended | |
3175 | * download ucode inits | |
3176 | * config other core registers | |
3177 | * init dma | |
3178 | */ | |
3179 | static void brcms_b_coreinit(struct brcms_c_info *wlc) | |
3180 | { | |
3181 | struct brcms_hardware *wlc_hw = wlc->hw; | |
16d2812e | 3182 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 | 3183 | u32 sflags; |
16d2812e | 3184 | u32 bcnint_us; |
5b435de0 AS |
3185 | uint i = 0; |
3186 | bool fifosz_fixup = false; | |
3187 | int err = 0; | |
3188 | u16 buf[NFIFO]; | |
3189 | struct wiphy *wiphy = wlc->wiphy; | |
3190 | struct brcms_ucode *ucode = &wlc_hw->wlc->wl->ucode; | |
3191 | ||
5b435de0 AS |
3192 | BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit); |
3193 | ||
3194 | /* reset PSM */ | |
3195 | brcms_b_mctrl(wlc_hw, ~0, (MCTL_IHR_EN | MCTL_PSM_JMP_0 | MCTL_WAKE)); | |
3196 | ||
3197 | brcms_ucode_download(wlc_hw); | |
3198 | /* | |
3199 | * FIFOSZ fixup. driver wants to controls the fifo allocation. | |
3200 | */ | |
3201 | fifosz_fixup = true; | |
3202 | ||
3203 | /* let the PSM run to the suspended state, set mode to BSS STA */ | |
16d2812e | 3204 | bcma_write32(core, D11REGOFFS(macintstatus), -1); |
5b435de0 AS |
3205 | brcms_b_mctrl(wlc_hw, ~0, |
3206 | (MCTL_IHR_EN | MCTL_INFRA | MCTL_PSM_RUN | MCTL_WAKE)); | |
3207 | ||
3208 | /* wait for ucode to self-suspend after auto-init */ | |
16d2812e AS |
3209 | SPINWAIT(((bcma_read32(core, D11REGOFFS(macintstatus)) & |
3210 | MI_MACSSPNDD) == 0), 1000 * 1000); | |
3211 | if ((bcma_read32(core, D11REGOFFS(macintstatus)) & MI_MACSSPNDD) == 0) | |
5b435de0 AS |
3212 | wiphy_err(wiphy, "wl%d: wlc_coreinit: ucode did not self-" |
3213 | "suspend!\n", wlc_hw->unit); | |
3214 | ||
3215 | brcms_c_gpio_init(wlc); | |
3216 | ||
a8779e4a | 3217 | sflags = bcma_aread32(core, BCMA_IOST); |
5b435de0 AS |
3218 | |
3219 | if (D11REV_IS(wlc_hw->corerev, 23)) { | |
3220 | if (BRCMS_ISNPHY(wlc_hw->band)) | |
3221 | brcms_c_write_inits(wlc_hw, ucode->d11n0initvals16); | |
3222 | else | |
3223 | wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev" | |
3224 | " %d\n", __func__, wlc_hw->unit, | |
3225 | wlc_hw->corerev); | |
3226 | } else if (D11REV_IS(wlc_hw->corerev, 24)) { | |
3227 | if (BRCMS_ISLCNPHY(wlc_hw->band)) | |
3228 | brcms_c_write_inits(wlc_hw, ucode->d11lcn0initvals24); | |
3229 | else | |
3230 | wiphy_err(wiphy, "%s: wl%d: unsupported phy in corerev" | |
3231 | " %d\n", __func__, wlc_hw->unit, | |
3232 | wlc_hw->corerev); | |
3233 | } else { | |
3234 | wiphy_err(wiphy, "%s: wl%d: unsupported corerev %d\n", | |
3235 | __func__, wlc_hw->unit, wlc_hw->corerev); | |
3236 | } | |
3237 | ||
3238 | /* For old ucode, txfifo sizes needs to be modified(increased) */ | |
23677ce3 | 3239 | if (fifosz_fixup) |
5b435de0 AS |
3240 | brcms_b_corerev_fifofixup(wlc_hw); |
3241 | ||
3242 | /* check txfifo allocations match between ucode and driver */ | |
3243 | buf[TX_AC_BE_FIFO] = brcms_b_read_shm(wlc_hw, M_FIFOSIZE0); | |
3244 | if (buf[TX_AC_BE_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BE_FIFO]) { | |
3245 | i = TX_AC_BE_FIFO; | |
3246 | err = -1; | |
3247 | } | |
3248 | buf[TX_AC_VI_FIFO] = brcms_b_read_shm(wlc_hw, M_FIFOSIZE1); | |
3249 | if (buf[TX_AC_VI_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VI_FIFO]) { | |
3250 | i = TX_AC_VI_FIFO; | |
3251 | err = -1; | |
3252 | } | |
3253 | buf[TX_AC_BK_FIFO] = brcms_b_read_shm(wlc_hw, M_FIFOSIZE2); | |
3254 | buf[TX_AC_VO_FIFO] = (buf[TX_AC_BK_FIFO] >> 8) & 0xff; | |
3255 | buf[TX_AC_BK_FIFO] &= 0xff; | |
3256 | if (buf[TX_AC_BK_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_BK_FIFO]) { | |
3257 | i = TX_AC_BK_FIFO; | |
3258 | err = -1; | |
3259 | } | |
3260 | if (buf[TX_AC_VO_FIFO] != wlc_hw->xmtfifo_sz[TX_AC_VO_FIFO]) { | |
3261 | i = TX_AC_VO_FIFO; | |
3262 | err = -1; | |
3263 | } | |
3264 | buf[TX_BCMC_FIFO] = brcms_b_read_shm(wlc_hw, M_FIFOSIZE3); | |
3265 | buf[TX_ATIM_FIFO] = (buf[TX_BCMC_FIFO] >> 8) & 0xff; | |
3266 | buf[TX_BCMC_FIFO] &= 0xff; | |
3267 | if (buf[TX_BCMC_FIFO] != wlc_hw->xmtfifo_sz[TX_BCMC_FIFO]) { | |
3268 | i = TX_BCMC_FIFO; | |
3269 | err = -1; | |
3270 | } | |
3271 | if (buf[TX_ATIM_FIFO] != wlc_hw->xmtfifo_sz[TX_ATIM_FIFO]) { | |
3272 | i = TX_ATIM_FIFO; | |
3273 | err = -1; | |
3274 | } | |
3275 | if (err != 0) | |
3276 | wiphy_err(wiphy, "wlc_coreinit: txfifo mismatch: ucode size %d" | |
3277 | " driver size %d index %d\n", buf[i], | |
3278 | wlc_hw->xmtfifo_sz[i], i); | |
3279 | ||
3280 | /* make sure we can still talk to the mac */ | |
16d2812e | 3281 | WARN_ON(bcma_read32(core, D11REGOFFS(maccontrol)) == 0xffffffff); |
5b435de0 AS |
3282 | |
3283 | /* band-specific inits done by wlc_bsinit() */ | |
3284 | ||
3285 | /* Set up frame burst size and antenna swap threshold init values */ | |
3286 | brcms_b_write_shm(wlc_hw, M_MBURST_SIZE, MAXTXFRAMEBURST); | |
3287 | brcms_b_write_shm(wlc_hw, M_MAX_ANTCNT, ANTCNT); | |
3288 | ||
3289 | /* enable one rx interrupt per received frame */ | |
16d2812e | 3290 | bcma_write32(core, D11REGOFFS(intrcvlazy[0]), (1 << IRL_FC_SHIFT)); |
5b435de0 AS |
3291 | |
3292 | /* set the station mode (BSS STA) */ | |
3293 | brcms_b_mctrl(wlc_hw, | |
3294 | (MCTL_INFRA | MCTL_DISCARD_PMQ | MCTL_AP), | |
3295 | (MCTL_INFRA | MCTL_DISCARD_PMQ)); | |
3296 | ||
3297 | /* set up Beacon interval */ | |
3298 | bcnint_us = 0x8000 << 10; | |
16d2812e AS |
3299 | bcma_write32(core, D11REGOFFS(tsf_cfprep), |
3300 | (bcnint_us << CFPREP_CBI_SHIFT)); | |
3301 | bcma_write32(core, D11REGOFFS(tsf_cfpstart), bcnint_us); | |
3302 | bcma_write32(core, D11REGOFFS(macintstatus), MI_GP1); | |
5b435de0 AS |
3303 | |
3304 | /* write interrupt mask */ | |
16d2812e AS |
3305 | bcma_write32(core, D11REGOFFS(intctrlregs[RX_FIFO].intmask), |
3306 | DEF_RXINTMASK); | |
5b435de0 AS |
3307 | |
3308 | /* allow the MAC to control the PHY clock (dynamic on/off) */ | |
3309 | brcms_b_macphyclk_set(wlc_hw, ON); | |
3310 | ||
3311 | /* program dynamic clock control fast powerup delay register */ | |
3312 | wlc->fastpwrup_dly = ai_clkctl_fast_pwrup_delay(wlc_hw->sih); | |
16d2812e | 3313 | bcma_write16(core, D11REGOFFS(scc_fastpwrup_dly), wlc->fastpwrup_dly); |
5b435de0 AS |
3314 | |
3315 | /* tell the ucode the corerev */ | |
3316 | brcms_b_write_shm(wlc_hw, M_MACHW_VER, (u16) wlc_hw->corerev); | |
3317 | ||
3318 | /* tell the ucode MAC capabilities */ | |
3319 | brcms_b_write_shm(wlc_hw, M_MACHW_CAP_L, | |
3320 | (u16) (wlc_hw->machwcap & 0xffff)); | |
3321 | brcms_b_write_shm(wlc_hw, M_MACHW_CAP_H, | |
3322 | (u16) ((wlc_hw-> | |
3323 | machwcap >> 16) & 0xffff)); | |
3324 | ||
3325 | /* write retry limits to SCR, this done after PSM init */ | |
16d2812e AS |
3326 | bcma_write32(core, D11REGOFFS(objaddr), |
3327 | OBJADDR_SCR_SEL | S_DOT11_SRC_LMT); | |
3328 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
3329 | bcma_write32(core, D11REGOFFS(objdata), wlc_hw->SRL); | |
3330 | bcma_write32(core, D11REGOFFS(objaddr), | |
3331 | OBJADDR_SCR_SEL | S_DOT11_LRC_LMT); | |
3332 | (void)bcma_read32(core, D11REGOFFS(objaddr)); | |
3333 | bcma_write32(core, D11REGOFFS(objdata), wlc_hw->LRL); | |
5b435de0 AS |
3334 | |
3335 | /* write rate fallback retry limits */ | |
3336 | brcms_b_write_shm(wlc_hw, M_SFRMTXCNTFBRTHSD, wlc_hw->SFBL); | |
3337 | brcms_b_write_shm(wlc_hw, M_LFRMTXCNTFBRTHSD, wlc_hw->LFBL); | |
3338 | ||
16d2812e AS |
3339 | bcma_mask16(core, D11REGOFFS(ifs_ctl), 0x0FFF); |
3340 | bcma_write16(core, D11REGOFFS(ifs_aifsn), EDCF_AIFSN_MIN); | |
5b435de0 AS |
3341 | |
3342 | /* init the tx dma engines */ | |
3343 | for (i = 0; i < NFIFO; i++) { | |
3344 | if (wlc_hw->di[i]) | |
3345 | dma_txinit(wlc_hw->di[i]); | |
3346 | } | |
3347 | ||
3348 | /* init the rx dma engine(s) and post receive buffers */ | |
3349 | dma_rxinit(wlc_hw->di[RX_FIFO]); | |
3350 | dma_rxfill(wlc_hw->di[RX_FIFO]); | |
3351 | } | |
3352 | ||
3353 | void | |
a8bc4917 | 3354 | static brcms_b_init(struct brcms_hardware *wlc_hw, u16 chanspec) { |
5b435de0 AS |
3355 | u32 macintmask; |
3356 | bool fastclk; | |
3357 | struct brcms_c_info *wlc = wlc_hw->wlc; | |
3358 | ||
3359 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
3360 | ||
3361 | /* request FAST clock if not on */ | |
3362 | fastclk = wlc_hw->forcefastclk; | |
3363 | if (!fastclk) | |
712e3c1f | 3364 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
5b435de0 AS |
3365 | |
3366 | /* disable interrupts */ | |
3367 | macintmask = brcms_intrsoff(wlc->wl); | |
3368 | ||
3369 | /* set up the specified band and chanspec */ | |
3370 | brcms_c_setxband(wlc_hw, chspec_bandunit(chanspec)); | |
3371 | wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec); | |
3372 | ||
3373 | /* do one-time phy inits and calibration */ | |
3374 | wlc_phy_cal_init(wlc_hw->band->pi); | |
3375 | ||
3376 | /* core-specific initialization */ | |
3377 | brcms_b_coreinit(wlc); | |
3378 | ||
5b435de0 AS |
3379 | /* band-specific inits */ |
3380 | brcms_b_bsinit(wlc, chanspec); | |
3381 | ||
3382 | /* restore macintmask */ | |
3383 | brcms_intrsrestore(wlc->wl, macintmask); | |
3384 | ||
3385 | /* seed wake_override with BRCMS_WAKE_OVERRIDE_MACSUSPEND since the mac | |
3386 | * is suspended and brcms_c_enable_mac() will clear this override bit. | |
3387 | */ | |
3388 | mboolset(wlc_hw->wake_override, BRCMS_WAKE_OVERRIDE_MACSUSPEND); | |
3389 | ||
3390 | /* | |
3391 | * initialize mac_suspend_depth to 1 to match ucode | |
3392 | * initial suspended state | |
3393 | */ | |
3394 | wlc_hw->mac_suspend_depth = 1; | |
3395 | ||
3396 | /* restore the clk */ | |
3397 | if (!fastclk) | |
712e3c1f | 3398 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC); |
5b435de0 AS |
3399 | } |
3400 | ||
3401 | static void brcms_c_set_phy_chanspec(struct brcms_c_info *wlc, | |
3402 | u16 chanspec) | |
3403 | { | |
3404 | /* Save our copy of the chanspec */ | |
3405 | wlc->chanspec = chanspec; | |
3406 | ||
3407 | /* Set the chanspec and power limits for this locale */ | |
3408 | brcms_c_channel_set_chanspec(wlc->cmi, chanspec, BRCMS_TXPWR_MAX); | |
3409 | ||
3410 | if (wlc->stf->ss_algosel_auto) | |
3411 | brcms_c_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel, | |
3412 | chanspec); | |
3413 | ||
3414 | brcms_c_stf_ss_update(wlc, wlc->band); | |
5b435de0 AS |
3415 | } |
3416 | ||
94bdc2a2 AB |
3417 | static void |
3418 | brcms_default_rateset(struct brcms_c_info *wlc, struct brcms_c_rateset *rs) | |
3419 | { | |
3420 | brcms_c_rateset_default(rs, NULL, wlc->band->phytype, | |
3421 | wlc->band->bandtype, false, BRCMS_RATE_MASK_FULL, | |
3422 | (bool) (wlc->pub->_n_enab & SUPPORT_11N), | |
3423 | brcms_chspec_bw(wlc->default_bss->chanspec), | |
3424 | wlc->stf->txstreams); | |
3425 | } | |
3426 | ||
3427 | /* derive wlc->band->basic_rate[] table from 'rateset' */ | |
3428 | static void brcms_c_rate_lookup_init(struct brcms_c_info *wlc, | |
3429 | struct brcms_c_rateset *rateset) | |
3430 | { | |
3431 | u8 rate; | |
3432 | u8 mandatory; | |
3433 | u8 cck_basic = 0; | |
3434 | u8 ofdm_basic = 0; | |
3435 | u8 *br = wlc->band->basic_rate; | |
3436 | uint i; | |
3437 | ||
3438 | /* incoming rates are in 500kbps units as in 802.11 Supported Rates */ | |
3439 | memset(br, 0, BRCM_MAXRATE + 1); | |
3440 | ||
3441 | /* For each basic rate in the rates list, make an entry in the | |
3442 | * best basic lookup. | |
3443 | */ | |
3444 | for (i = 0; i < rateset->count; i++) { | |
3445 | /* only make an entry for a basic rate */ | |
3446 | if (!(rateset->rates[i] & BRCMS_RATE_FLAG)) | |
3447 | continue; | |
3448 | ||
3449 | /* mask off basic bit */ | |
3450 | rate = (rateset->rates[i] & BRCMS_RATE_MASK); | |
3451 | ||
3452 | if (rate > BRCM_MAXRATE) { | |
3453 | wiphy_err(wlc->wiphy, "brcms_c_rate_lookup_init: " | |
3454 | "invalid rate 0x%X in rate set\n", | |
3455 | rateset->rates[i]); | |
3456 | continue; | |
3457 | } | |
3458 | ||
3459 | br[rate] = rate; | |
3460 | } | |
3461 | ||
3462 | /* The rate lookup table now has non-zero entries for each | |
3463 | * basic rate, equal to the basic rate: br[basicN] = basicN | |
3464 | * | |
3465 | * To look up the best basic rate corresponding to any | |
3466 | * particular rate, code can use the basic_rate table | |
3467 | * like this | |
3468 | * | |
3469 | * basic_rate = wlc->band->basic_rate[tx_rate] | |
3470 | * | |
3471 | * Make sure there is a best basic rate entry for | |
3472 | * every rate by walking up the table from low rates | |
3473 | * to high, filling in holes in the lookup table | |
3474 | */ | |
3475 | ||
3476 | for (i = 0; i < wlc->band->hw_rateset.count; i++) { | |
3477 | rate = wlc->band->hw_rateset.rates[i]; | |
3478 | ||
3479 | if (br[rate] != 0) { | |
3480 | /* This rate is a basic rate. | |
3481 | * Keep track of the best basic rate so far by | |
3482 | * modulation type. | |
3483 | */ | |
3484 | if (is_ofdm_rate(rate)) | |
3485 | ofdm_basic = rate; | |
3486 | else | |
3487 | cck_basic = rate; | |
3488 | ||
3489 | continue; | |
3490 | } | |
3491 | ||
3492 | /* This rate is not a basic rate so figure out the | |
3493 | * best basic rate less than this rate and fill in | |
3494 | * the hole in the table | |
3495 | */ | |
3496 | ||
3497 | br[rate] = is_ofdm_rate(rate) ? ofdm_basic : cck_basic; | |
3498 | ||
3499 | if (br[rate] != 0) | |
3500 | continue; | |
3501 | ||
3502 | if (is_ofdm_rate(rate)) { | |
3503 | /* | |
3504 | * In 11g and 11a, the OFDM mandatory rates | |
3505 | * are 6, 12, and 24 Mbps | |
3506 | */ | |
3507 | if (rate >= BRCM_RATE_24M) | |
3508 | mandatory = BRCM_RATE_24M; | |
3509 | else if (rate >= BRCM_RATE_12M) | |
3510 | mandatory = BRCM_RATE_12M; | |
3511 | else | |
3512 | mandatory = BRCM_RATE_6M; | |
3513 | } else { | |
3514 | /* In 11b, all CCK rates are mandatory 1 - 11 Mbps */ | |
3515 | mandatory = rate; | |
3516 | } | |
3517 | ||
3518 | br[rate] = mandatory; | |
3519 | } | |
3520 | } | |
3521 | ||
3522 | static void brcms_c_bandinit_ordered(struct brcms_c_info *wlc, | |
3523 | u16 chanspec) | |
5b435de0 AS |
3524 | { |
3525 | struct brcms_c_rateset default_rateset; | |
3526 | uint parkband; | |
3527 | uint i, band_order[2]; | |
3528 | ||
3529 | BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit); | |
3530 | /* | |
3531 | * We might have been bandlocked during down and the chip | |
3532 | * power-cycled (hibernate). Figure out the right band to park on | |
3533 | */ | |
3534 | if (wlc->bandlocked || wlc->pub->_nbands == 1) { | |
3535 | /* updated in brcms_c_bandlock() */ | |
3536 | parkband = wlc->band->bandunit; | |
3537 | band_order[0] = band_order[1] = parkband; | |
3538 | } else { | |
3539 | /* park on the band of the specified chanspec */ | |
3540 | parkband = chspec_bandunit(chanspec); | |
3541 | ||
3542 | /* order so that parkband initialize last */ | |
3543 | band_order[0] = parkband ^ 1; | |
3544 | band_order[1] = parkband; | |
3545 | } | |
3546 | ||
3547 | /* make each band operational, software state init */ | |
3548 | for (i = 0; i < wlc->pub->_nbands; i++) { | |
3549 | uint j = band_order[i]; | |
3550 | ||
3551 | wlc->band = wlc->bandstate[j]; | |
3552 | ||
3553 | brcms_default_rateset(wlc, &default_rateset); | |
3554 | ||
3555 | /* fill in hw_rate */ | |
3556 | brcms_c_rateset_filter(&default_rateset, &wlc->band->hw_rateset, | |
3557 | false, BRCMS_RATES_CCK_OFDM, BRCMS_RATE_MASK, | |
3558 | (bool) (wlc->pub->_n_enab & SUPPORT_11N)); | |
3559 | ||
3560 | /* init basic rate lookup */ | |
3561 | brcms_c_rate_lookup_init(wlc, &default_rateset); | |
3562 | } | |
3563 | ||
3564 | /* sync up phy/radio chanspec */ | |
3565 | brcms_c_set_phy_chanspec(wlc, chanspec); | |
3566 | } | |
3567 | ||
02a588a2 | 3568 | /* |
be667669 AB |
3569 | * Set or clear filtering related maccontrol bits based on |
3570 | * specified filter flags | |
02a588a2 | 3571 | */ |
be667669 | 3572 | void brcms_c_mac_promisc(struct brcms_c_info *wlc, uint filter_flags) |
94bdc2a2 AB |
3573 | { |
3574 | u32 promisc_bits = 0; | |
3575 | ||
be667669 AB |
3576 | wlc->filter_flags = filter_flags; |
3577 | ||
3578 | if (filter_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) | |
3579 | promisc_bits |= MCTL_PROMISC; | |
3580 | ||
3581 | if (filter_flags & FIF_BCN_PRBRESP_PROMISC) | |
02a588a2 | 3582 | promisc_bits |= MCTL_BCNS_PROMISC; |
94bdc2a2 | 3583 | |
be667669 AB |
3584 | if (filter_flags & FIF_FCSFAIL) |
3585 | promisc_bits |= MCTL_KEEPBADFCS; | |
94bdc2a2 | 3586 | |
be667669 AB |
3587 | if (filter_flags & (FIF_CONTROL | FIF_PSPOLL)) |
3588 | promisc_bits |= MCTL_KEEPCONTROL; | |
02a588a2 | 3589 | |
be667669 AB |
3590 | brcms_b_mctrl(wlc->hw, |
3591 | MCTL_PROMISC | MCTL_BCNS_PROMISC | | |
3592 | MCTL_KEEPCONTROL | MCTL_KEEPBADFCS, | |
3593 | promisc_bits); | |
94bdc2a2 AB |
3594 | } |
3595 | ||
5b435de0 AS |
3596 | /* |
3597 | * ucode, hwmac update | |
3598 | * Channel dependent updates for ucode and hw | |
3599 | */ | |
3600 | static void brcms_c_ucode_mac_upd(struct brcms_c_info *wlc) | |
3601 | { | |
3602 | /* enable or disable any active IBSSs depending on whether or not | |
3603 | * we are on the home channel | |
3604 | */ | |
3605 | if (wlc->home_chanspec == wlc_phy_chanspec_get(wlc->band->pi)) { | |
3606 | if (wlc->pub->associated) { | |
3607 | /* | |
3608 | * BMAC_NOTE: This is something that should be fixed | |
3609 | * in ucode inits. I think that the ucode inits set | |
3610 | * up the bcn templates and shm values with a bogus | |
3611 | * beacon. This should not be done in the inits. If | |
3612 | * ucode needs to set up a beacon for testing, the | |
3613 | * test routines should write it down, not expect the | |
3614 | * inits to populate a bogus beacon. | |
3615 | */ | |
3616 | if (BRCMS_PHY_11N_CAP(wlc->band)) | |
3617 | brcms_b_write_shm(wlc->hw, | |
3618 | M_BCN_TXTSF_OFFSET, 0); | |
3619 | } | |
3620 | } else { | |
3621 | /* disable an active IBSS if we are not on the home channel */ | |
3622 | } | |
5b435de0 AS |
3623 | } |
3624 | ||
94bdc2a2 AB |
3625 | static void brcms_c_write_rate_shm(struct brcms_c_info *wlc, u8 rate, |
3626 | u8 basic_rate) | |
3627 | { | |
3628 | u8 phy_rate, index; | |
3629 | u8 basic_phy_rate, basic_index; | |
3630 | u16 dir_table, basic_table; | |
3631 | u16 basic_ptr; | |
3632 | ||
3633 | /* Shared memory address for the table we are reading */ | |
3634 | dir_table = is_ofdm_rate(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B; | |
3635 | ||
3636 | /* Shared memory address for the table we are writing */ | |
3637 | basic_table = is_ofdm_rate(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B; | |
3638 | ||
3639 | /* | |
3640 | * for a given rate, the LS-nibble of the PLCP SIGNAL field is | |
3641 | * the index into the rate table. | |
3642 | */ | |
3643 | phy_rate = rate_info[rate] & BRCMS_RATE_MASK; | |
3644 | basic_phy_rate = rate_info[basic_rate] & BRCMS_RATE_MASK; | |
3645 | index = phy_rate & 0xf; | |
3646 | basic_index = basic_phy_rate & 0xf; | |
3647 | ||
3648 | /* Find the SHM pointer to the ACK rate entry by looking in the | |
3649 | * Direct-map Table | |
3650 | */ | |
3651 | basic_ptr = brcms_b_read_shm(wlc->hw, (dir_table + basic_index * 2)); | |
3652 | ||
3653 | /* Update the SHM BSS-basic-rate-set mapping table with the pointer | |
3654 | * to the correct basic rate for the given incoming rate | |
3655 | */ | |
3656 | brcms_b_write_shm(wlc->hw, (basic_table + index * 2), basic_ptr); | |
3657 | } | |
3658 | ||
3659 | static const struct brcms_c_rateset * | |
3660 | brcms_c_rateset_get_hwrs(struct brcms_c_info *wlc) | |
3661 | { | |
3662 | const struct brcms_c_rateset *rs_dflt; | |
3663 | ||
3664 | if (BRCMS_PHY_11N_CAP(wlc->band)) { | |
3665 | if (wlc->band->bandtype == BRCM_BAND_5G) | |
3666 | rs_dflt = &ofdm_mimo_rates; | |
3667 | else | |
3668 | rs_dflt = &cck_ofdm_mimo_rates; | |
3669 | } else if (wlc->band->gmode) | |
3670 | rs_dflt = &cck_ofdm_rates; | |
3671 | else | |
3672 | rs_dflt = &cck_rates; | |
3673 | ||
3674 | return rs_dflt; | |
3675 | } | |
3676 | ||
3677 | static void brcms_c_set_ratetable(struct brcms_c_info *wlc) | |
3678 | { | |
3679 | const struct brcms_c_rateset *rs_dflt; | |
3680 | struct brcms_c_rateset rs; | |
3681 | u8 rate, basic_rate; | |
3682 | uint i; | |
3683 | ||
3684 | rs_dflt = brcms_c_rateset_get_hwrs(wlc); | |
3685 | ||
3686 | brcms_c_rateset_copy(rs_dflt, &rs); | |
3687 | brcms_c_rateset_mcs_upd(&rs, wlc->stf->txstreams); | |
3688 | ||
3689 | /* walk the phy rate table and update SHM basic rate lookup table */ | |
3690 | for (i = 0; i < rs.count; i++) { | |
3691 | rate = rs.rates[i] & BRCMS_RATE_MASK; | |
3692 | ||
3693 | /* for a given rate brcms_basic_rate returns the rate at | |
3694 | * which a response ACK/CTS should be sent. | |
3695 | */ | |
3696 | basic_rate = brcms_basic_rate(wlc, rate); | |
3697 | if (basic_rate == 0) | |
3698 | /* This should only happen if we are using a | |
3699 | * restricted rateset. | |
3700 | */ | |
3701 | basic_rate = rs.rates[0] & BRCMS_RATE_MASK; | |
3702 | ||
3703 | brcms_c_write_rate_shm(wlc, rate, basic_rate); | |
3704 | } | |
3705 | } | |
3706 | ||
5b435de0 AS |
3707 | /* band-specific init */ |
3708 | static void brcms_c_bsinit(struct brcms_c_info *wlc) | |
3709 | { | |
3710 | BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n", | |
3711 | wlc->pub->unit, wlc->band->bandunit); | |
3712 | ||
3713 | /* write ucode ACK/CTS rate table */ | |
3714 | brcms_c_set_ratetable(wlc); | |
3715 | ||
3716 | /* update some band specific mac configuration */ | |
3717 | brcms_c_ucode_mac_upd(wlc); | |
3718 | ||
3719 | /* init antenna selection */ | |
3720 | brcms_c_antsel_init(wlc->asi); | |
3721 | ||
3722 | } | |
3723 | ||
3724 | /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */ | |
3725 | static int | |
3726 | brcms_c_duty_cycle_set(struct brcms_c_info *wlc, int duty_cycle, bool isOFDM, | |
3727 | bool writeToShm) | |
3728 | { | |
3729 | int idle_busy_ratio_x_16 = 0; | |
3730 | uint offset = | |
3731 | isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM : | |
3732 | M_TX_IDLE_BUSY_RATIO_X_16_CCK; | |
3733 | if (duty_cycle > 100 || duty_cycle < 0) { | |
3734 | wiphy_err(wlc->wiphy, "wl%d: duty cycle value off limit\n", | |
3735 | wlc->pub->unit); | |
3736 | return -EINVAL; | |
3737 | } | |
3738 | if (duty_cycle) | |
3739 | idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle; | |
3740 | /* Only write to shared memory when wl is up */ | |
3741 | if (writeToShm) | |
3742 | brcms_b_write_shm(wlc->hw, offset, (u16) idle_busy_ratio_x_16); | |
3743 | ||
3744 | if (isOFDM) | |
3745 | wlc->tx_duty_cycle_ofdm = (u16) duty_cycle; | |
3746 | else | |
3747 | wlc->tx_duty_cycle_cck = (u16) duty_cycle; | |
3748 | ||
3749 | return 0; | |
3750 | } | |
3751 | ||
3752 | /* | |
3753 | * Initialize the base precedence map for dequeueing | |
3754 | * from txq based on WME settings | |
3755 | */ | |
3756 | static void brcms_c_tx_prec_map_init(struct brcms_c_info *wlc) | |
3757 | { | |
3758 | wlc->tx_prec_map = BRCMS_PREC_BMP_ALL; | |
3759 | memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16)); | |
3760 | ||
3761 | wlc->fifo2prec_map[TX_AC_BK_FIFO] = BRCMS_PREC_BMP_AC_BK; | |
3762 | wlc->fifo2prec_map[TX_AC_BE_FIFO] = BRCMS_PREC_BMP_AC_BE; | |
3763 | wlc->fifo2prec_map[TX_AC_VI_FIFO] = BRCMS_PREC_BMP_AC_VI; | |
3764 | wlc->fifo2prec_map[TX_AC_VO_FIFO] = BRCMS_PREC_BMP_AC_VO; | |
3765 | } | |
3766 | ||
3767 | static void | |
3768 | brcms_c_txflowcontrol_signal(struct brcms_c_info *wlc, | |
3769 | struct brcms_txq_info *qi, bool on, int prio) | |
3770 | { | |
3771 | /* transmit flowcontrol is not yet implemented */ | |
3772 | } | |
3773 | ||
3774 | static void brcms_c_txflowcontrol_reset(struct brcms_c_info *wlc) | |
3775 | { | |
3776 | struct brcms_txq_info *qi; | |
3777 | ||
3778 | for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) { | |
3779 | if (qi->stopped) { | |
3780 | brcms_c_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO); | |
3781 | qi->stopped = 0; | |
3782 | } | |
3783 | } | |
3784 | } | |
3785 | ||
94bdc2a2 AB |
3786 | /* push sw hps and wake state through hardware */ |
3787 | static void brcms_c_set_ps_ctrl(struct brcms_c_info *wlc) | |
5b435de0 | 3788 | { |
94bdc2a2 AB |
3789 | u32 v1, v2; |
3790 | bool hps; | |
3791 | bool awake_before; | |
5b435de0 | 3792 | |
94bdc2a2 | 3793 | hps = brcms_c_ps_allowed(wlc); |
5b435de0 | 3794 | |
94bdc2a2 | 3795 | BCMMSG(wlc->wiphy, "wl%d: hps %d\n", wlc->pub->unit, hps); |
5b435de0 | 3796 | |
16d2812e | 3797 | v1 = bcma_read32(wlc->hw->d11core, D11REGOFFS(maccontrol)); |
94bdc2a2 AB |
3798 | v2 = MCTL_WAKE; |
3799 | if (hps) | |
3800 | v2 |= MCTL_HPS; | |
5b435de0 | 3801 | |
94bdc2a2 | 3802 | brcms_b_mctrl(wlc->hw, MCTL_WAKE | MCTL_HPS, v2); |
5b435de0 | 3803 | |
94bdc2a2 | 3804 | awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0)); |
5b435de0 AS |
3805 | |
3806 | if (!awake_before) | |
3807 | brcms_b_wait_for_wake(wlc->hw); | |
5b435de0 AS |
3808 | } |
3809 | ||
3810 | /* | |
3811 | * Write this BSS config's MAC address to core. | |
3812 | * Updates RXE match engine. | |
3813 | */ | |
94bdc2a2 | 3814 | static int brcms_c_set_mac(struct brcms_bss_cfg *bsscfg) |
5b435de0 AS |
3815 | { |
3816 | int err = 0; | |
3817 | struct brcms_c_info *wlc = bsscfg->wlc; | |
3818 | ||
3819 | /* enter the MAC addr into the RXE match registers */ | |
3820 | brcms_c_set_addrmatch(wlc, RCM_MAC_OFFSET, bsscfg->cur_etheraddr); | |
3821 | ||
3822 | brcms_c_ampdu_macaddr_upd(wlc); | |
3823 | ||
3824 | return err; | |
3825 | } | |
3826 | ||
3827 | /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl). | |
3828 | * Updates RXE match engine. | |
3829 | */ | |
94bdc2a2 | 3830 | static void brcms_c_set_bssid(struct brcms_bss_cfg *bsscfg) |
5b435de0 AS |
3831 | { |
3832 | /* we need to update BSSID in RXE match registers */ | |
3833 | brcms_c_set_addrmatch(bsscfg->wlc, RCM_BSSID_OFFSET, bsscfg->BSSID); | |
3834 | } | |
3835 | ||
3836 | static void brcms_b_set_shortslot(struct brcms_hardware *wlc_hw, bool shortslot) | |
3837 | { | |
3838 | wlc_hw->shortslot = shortslot; | |
3839 | ||
3840 | if (wlc_hw->band->bandtype == BRCM_BAND_2G && wlc_hw->up) { | |
3841 | brcms_c_suspend_mac_and_wait(wlc_hw->wlc); | |
3842 | brcms_b_update_slot_timing(wlc_hw, shortslot); | |
3843 | brcms_c_enable_mac(wlc_hw->wlc); | |
3844 | } | |
3845 | } | |
3846 | ||
3847 | /* | |
3848 | * Suspend the the MAC and update the slot timing | |
3849 | * for standard 11b/g (20us slots) or shortslot 11g (9us slots). | |
3850 | */ | |
94bdc2a2 | 3851 | static void brcms_c_switch_shortslot(struct brcms_c_info *wlc, bool shortslot) |
5b435de0 AS |
3852 | { |
3853 | /* use the override if it is set */ | |
3854 | if (wlc->shortslot_override != BRCMS_SHORTSLOT_AUTO) | |
3855 | shortslot = (wlc->shortslot_override == BRCMS_SHORTSLOT_ON); | |
3856 | ||
3857 | if (wlc->shortslot == shortslot) | |
3858 | return; | |
3859 | ||
3860 | wlc->shortslot = shortslot; | |
3861 | ||
3862 | brcms_b_set_shortslot(wlc->hw, shortslot); | |
3863 | } | |
3864 | ||
94bdc2a2 | 3865 | static void brcms_c_set_home_chanspec(struct brcms_c_info *wlc, u16 chanspec) |
5b435de0 AS |
3866 | { |
3867 | if (wlc->home_chanspec != chanspec) { | |
3868 | wlc->home_chanspec = chanspec; | |
3869 | ||
3870 | if (wlc->bsscfg->associated) | |
3871 | wlc->bsscfg->current_bss->chanspec = chanspec; | |
3872 | } | |
3873 | } | |
3874 | ||
3875 | void | |
3876 | brcms_b_set_chanspec(struct brcms_hardware *wlc_hw, u16 chanspec, | |
c6c44893 | 3877 | bool mute_tx, struct txpwr_limits *txpwr) |
5b435de0 AS |
3878 | { |
3879 | uint bandunit; | |
3880 | ||
3881 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d: 0x%x\n", wlc_hw->unit, chanspec); | |
3882 | ||
3883 | wlc_hw->chanspec = chanspec; | |
3884 | ||
3885 | /* Switch bands if necessary */ | |
3886 | if (wlc_hw->_nbands > 1) { | |
3887 | bandunit = chspec_bandunit(chanspec); | |
3888 | if (wlc_hw->band->bandunit != bandunit) { | |
3889 | /* brcms_b_setband disables other bandunit, | |
3890 | * use light band switch if not up yet | |
3891 | */ | |
3892 | if (wlc_hw->up) { | |
3893 | wlc_phy_chanspec_radio_set(wlc_hw-> | |
3894 | bandstate[bandunit]-> | |
3895 | pi, chanspec); | |
3896 | brcms_b_setband(wlc_hw, bandunit, chanspec); | |
3897 | } else { | |
3898 | brcms_c_setxband(wlc_hw, bandunit); | |
3899 | } | |
3900 | } | |
3901 | } | |
3902 | ||
c6c44893 | 3903 | wlc_phy_initcal_enable(wlc_hw->band->pi, !mute_tx); |
5b435de0 AS |
3904 | |
3905 | if (!wlc_hw->up) { | |
3906 | if (wlc_hw->clk) | |
3907 | wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr, | |
3908 | chanspec); | |
3909 | wlc_phy_chanspec_radio_set(wlc_hw->band->pi, chanspec); | |
3910 | } else { | |
3911 | wlc_phy_chanspec_set(wlc_hw->band->pi, chanspec); | |
3912 | wlc_phy_txpower_limit_set(wlc_hw->band->pi, txpwr, chanspec); | |
3913 | ||
3914 | /* Update muting of the channel */ | |
c6c44893 | 3915 | brcms_b_mute(wlc_hw, mute_tx); |
5b435de0 AS |
3916 | } |
3917 | } | |
3918 | ||
3919 | /* switch to and initialize new band */ | |
3920 | static void brcms_c_setband(struct brcms_c_info *wlc, | |
3921 | uint bandunit) | |
3922 | { | |
3923 | wlc->band = wlc->bandstate[bandunit]; | |
3924 | ||
3925 | if (!wlc->pub->up) | |
3926 | return; | |
3927 | ||
3928 | /* wait for at least one beacon before entering sleeping state */ | |
3929 | brcms_c_set_ps_ctrl(wlc); | |
3930 | ||
3931 | /* band-specific initializations */ | |
3932 | brcms_c_bsinit(wlc); | |
3933 | } | |
3934 | ||
94bdc2a2 | 3935 | static void brcms_c_set_chanspec(struct brcms_c_info *wlc, u16 chanspec) |
5b435de0 AS |
3936 | { |
3937 | uint bandunit; | |
3938 | bool switchband = false; | |
3939 | u16 old_chanspec = wlc->chanspec; | |
3940 | ||
3941 | if (!brcms_c_valid_chanspec_db(wlc->cmi, chanspec)) { | |
3942 | wiphy_err(wlc->wiphy, "wl%d: %s: Bad channel %d\n", | |
3943 | wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec)); | |
3944 | return; | |
3945 | } | |
3946 | ||
3947 | /* Switch bands if necessary */ | |
3948 | if (wlc->pub->_nbands > 1) { | |
3949 | bandunit = chspec_bandunit(chanspec); | |
3950 | if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) { | |
3951 | switchband = true; | |
3952 | if (wlc->bandlocked) { | |
3953 | wiphy_err(wlc->wiphy, "wl%d: %s: chspec %d " | |
3954 | "band is locked!\n", | |
3955 | wlc->pub->unit, __func__, | |
3956 | CHSPEC_CHANNEL(chanspec)); | |
3957 | return; | |
3958 | } | |
3959 | /* | |
3960 | * should the setband call come after the | |
3961 | * brcms_b_chanspec() ? if the setband updates | |
3962 | * (brcms_c_bsinit) use low level calls to inspect and | |
3963 | * set state, the state inspected may be from the wrong | |
3964 | * band, or the following brcms_b_set_chanspec() may | |
3965 | * undo the work. | |
3966 | */ | |
3967 | brcms_c_setband(wlc, bandunit); | |
3968 | } | |
3969 | } | |
3970 | ||
3971 | /* sync up phy/radio chanspec */ | |
3972 | brcms_c_set_phy_chanspec(wlc, chanspec); | |
3973 | ||
3974 | /* init antenna selection */ | |
3975 | if (brcms_chspec_bw(old_chanspec) != brcms_chspec_bw(chanspec)) { | |
3976 | brcms_c_antsel_init(wlc->asi); | |
3977 | ||
3978 | /* Fix the hardware rateset based on bw. | |
3979 | * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz | |
3980 | */ | |
3981 | brcms_c_rateset_bw_mcs_filter(&wlc->band->hw_rateset, | |
3982 | wlc->band->mimo_cap_40 ? brcms_chspec_bw(chanspec) : 0); | |
3983 | } | |
3984 | ||
3985 | /* update some mac configuration since chanspec changed */ | |
3986 | brcms_c_ucode_mac_upd(wlc); | |
3987 | } | |
3988 | ||
5b435de0 AS |
3989 | /* |
3990 | * This function changes the phytxctl for beacon based on current | |
3991 | * beacon ratespec AND txant setting as per this table: | |
3992 | * ratespec CCK ant = wlc->stf->txant | |
3993 | * OFDM ant = 3 | |
3994 | */ | |
3995 | void brcms_c_beacon_phytxctl_txant_upd(struct brcms_c_info *wlc, | |
3996 | u32 bcn_rspec) | |
3997 | { | |
3998 | u16 phyctl; | |
3999 | u16 phytxant = wlc->stf->phytxant; | |
4000 | u16 mask = PHY_TXC_ANT_MASK; | |
4001 | ||
4002 | /* for non-siso rates or default setting, use the available chains */ | |
4003 | if (BRCMS_PHY_11N_CAP(wlc->band)) | |
4004 | phytxant = brcms_c_stf_phytxchain_sel(wlc, bcn_rspec); | |
4005 | ||
4006 | phyctl = brcms_b_read_shm(wlc->hw, M_BCN_PCTLWD); | |
4007 | phyctl = (phyctl & ~mask) | phytxant; | |
4008 | brcms_b_write_shm(wlc->hw, M_BCN_PCTLWD, phyctl); | |
4009 | } | |
4010 | ||
4011 | /* | |
4012 | * centralized protection config change function to simplify debugging, no | |
4013 | * consistency checking this should be called only on changes to avoid overhead | |
4014 | * in periodic function | |
4015 | */ | |
4016 | void brcms_c_protection_upd(struct brcms_c_info *wlc, uint idx, int val) | |
4017 | { | |
4018 | BCMMSG(wlc->wiphy, "idx %d, val %d\n", idx, val); | |
4019 | ||
4020 | switch (idx) { | |
4021 | case BRCMS_PROT_G_SPEC: | |
4022 | wlc->protection->_g = (bool) val; | |
4023 | break; | |
4024 | case BRCMS_PROT_G_OVR: | |
4025 | wlc->protection->g_override = (s8) val; | |
4026 | break; | |
4027 | case BRCMS_PROT_G_USER: | |
4028 | wlc->protection->gmode_user = (u8) val; | |
4029 | break; | |
4030 | case BRCMS_PROT_OVERLAP: | |
4031 | wlc->protection->overlap = (s8) val; | |
4032 | break; | |
4033 | case BRCMS_PROT_N_USER: | |
4034 | wlc->protection->nmode_user = (s8) val; | |
4035 | break; | |
4036 | case BRCMS_PROT_N_CFG: | |
4037 | wlc->protection->n_cfg = (s8) val; | |
4038 | break; | |
4039 | case BRCMS_PROT_N_CFG_OVR: | |
4040 | wlc->protection->n_cfg_override = (s8) val; | |
4041 | break; | |
4042 | case BRCMS_PROT_N_NONGF: | |
4043 | wlc->protection->nongf = (bool) val; | |
4044 | break; | |
4045 | case BRCMS_PROT_N_NONGF_OVR: | |
4046 | wlc->protection->nongf_override = (s8) val; | |
4047 | break; | |
4048 | case BRCMS_PROT_N_PAM_OVR: | |
4049 | wlc->protection->n_pam_override = (s8) val; | |
4050 | break; | |
4051 | case BRCMS_PROT_N_OBSS: | |
4052 | wlc->protection->n_obss = (bool) val; | |
4053 | break; | |
4054 | ||
4055 | default: | |
4056 | break; | |
4057 | } | |
4058 | ||
4059 | } | |
4060 | ||
4061 | static void brcms_c_ht_update_sgi_rx(struct brcms_c_info *wlc, int val) | |
4062 | { | |
4063 | if (wlc->pub->up) { | |
4064 | brcms_c_update_beacon(wlc); | |
4065 | brcms_c_update_probe_resp(wlc, true); | |
4066 | } | |
4067 | } | |
4068 | ||
4069 | static void brcms_c_ht_update_ldpc(struct brcms_c_info *wlc, s8 val) | |
4070 | { | |
4071 | wlc->stf->ldpc = val; | |
4072 | ||
4073 | if (wlc->pub->up) { | |
4074 | brcms_c_update_beacon(wlc); | |
4075 | brcms_c_update_probe_resp(wlc, true); | |
4076 | wlc_phy_ldpc_override_set(wlc->band->pi, (val ? true : false)); | |
4077 | } | |
4078 | } | |
4079 | ||
4080 | void brcms_c_wme_setparams(struct brcms_c_info *wlc, u16 aci, | |
4081 | const struct ieee80211_tx_queue_params *params, | |
4082 | bool suspend) | |
4083 | { | |
4084 | int i; | |
4085 | struct shm_acparams acp_shm; | |
4086 | u16 *shm_entry; | |
4087 | ||
4088 | /* Only apply params if the core is out of reset and has clocks */ | |
4089 | if (!wlc->clk) { | |
4090 | wiphy_err(wlc->wiphy, "wl%d: %s : no-clock\n", wlc->pub->unit, | |
4091 | __func__); | |
4092 | return; | |
4093 | } | |
4094 | ||
4095 | memset((char *)&acp_shm, 0, sizeof(struct shm_acparams)); | |
4096 | /* fill in shm ac params struct */ | |
4097 | acp_shm.txop = params->txop; | |
4098 | /* convert from units of 32us to us for ucode */ | |
4099 | wlc->edcf_txop[aci & 0x3] = acp_shm.txop = | |
4100 | EDCF_TXOP2USEC(acp_shm.txop); | |
4101 | acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK); | |
4102 | ||
b7eec423 | 4103 | if (aci == IEEE80211_AC_VI && acp_shm.txop == 0 |
5b435de0 AS |
4104 | && acp_shm.aifs < EDCF_AIFSN_MAX) |
4105 | acp_shm.aifs++; | |
4106 | ||
4107 | if (acp_shm.aifs < EDCF_AIFSN_MIN | |
4108 | || acp_shm.aifs > EDCF_AIFSN_MAX) { | |
4109 | wiphy_err(wlc->wiphy, "wl%d: edcf_setparams: bad " | |
4110 | "aifs %d\n", wlc->pub->unit, acp_shm.aifs); | |
4111 | } else { | |
4112 | acp_shm.cwmin = params->cw_min; | |
4113 | acp_shm.cwmax = params->cw_max; | |
4114 | acp_shm.cwcur = acp_shm.cwmin; | |
4115 | acp_shm.bslots = | |
16d2812e AS |
4116 | bcma_read16(wlc->hw->d11core, D11REGOFFS(tsf_random)) & |
4117 | acp_shm.cwcur; | |
5b435de0 AS |
4118 | acp_shm.reggap = acp_shm.bslots + acp_shm.aifs; |
4119 | /* Indicate the new params to the ucode */ | |
4120 | acp_shm.status = brcms_b_read_shm(wlc->hw, (M_EDCF_QINFO + | |
4121 | wme_ac2fifo[aci] * | |
4122 | M_EDCF_QLEN + | |
4123 | M_EDCF_STATUS_OFF)); | |
4124 | acp_shm.status |= WME_STATUS_NEWAC; | |
4125 | ||
4126 | /* Fill in shm acparam table */ | |
4127 | shm_entry = (u16 *) &acp_shm; | |
4128 | for (i = 0; i < (int)sizeof(struct shm_acparams); i += 2) | |
4129 | brcms_b_write_shm(wlc->hw, | |
4130 | M_EDCF_QINFO + | |
4131 | wme_ac2fifo[aci] * M_EDCF_QLEN + i, | |
4132 | *shm_entry++); | |
4133 | } | |
4134 | ||
4135 | if (suspend) { | |
4136 | brcms_c_suspend_mac_and_wait(wlc); | |
4137 | brcms_c_enable_mac(wlc); | |
4138 | } | |
4139 | } | |
4140 | ||
094b199b | 4141 | static void brcms_c_edcf_setparams(struct brcms_c_info *wlc, bool suspend) |
5b435de0 AS |
4142 | { |
4143 | u16 aci; | |
4144 | int i_ac; | |
4145 | struct ieee80211_tx_queue_params txq_pars; | |
4146 | static const struct edcf_acparam default_edcf_acparams[] = { | |
4147 | {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA, EDCF_AC_BE_TXOP_STA}, | |
4148 | {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA, EDCF_AC_BK_TXOP_STA}, | |
4149 | {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA, EDCF_AC_VI_TXOP_STA}, | |
4150 | {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA, EDCF_AC_VO_TXOP_STA} | |
4151 | }; /* ucode needs these parameters during its initialization */ | |
4152 | const struct edcf_acparam *edcf_acp = &default_edcf_acparams[0]; | |
4153 | ||
b7eec423 | 4154 | for (i_ac = 0; i_ac < IEEE80211_NUM_ACS; i_ac++, edcf_acp++) { |
5b435de0 AS |
4155 | /* find out which ac this set of params applies to */ |
4156 | aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT; | |
4157 | ||
4158 | /* fill in shm ac params struct */ | |
4159 | txq_pars.txop = edcf_acp->TXOP; | |
4160 | txq_pars.aifs = edcf_acp->ACI; | |
4161 | ||
4162 | /* CWmin = 2^(ECWmin) - 1 */ | |
4163 | txq_pars.cw_min = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK); | |
4164 | /* CWmax = 2^(ECWmax) - 1 */ | |
4165 | txq_pars.cw_max = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK) | |
4166 | >> EDCF_ECWMAX_SHIFT); | |
4167 | brcms_c_wme_setparams(wlc, aci, &txq_pars, suspend); | |
4168 | } | |
4169 | ||
4170 | if (suspend) { | |
4171 | brcms_c_suspend_mac_and_wait(wlc); | |
4172 | brcms_c_enable_mac(wlc); | |
4173 | } | |
4174 | } | |
4175 | ||
5b435de0 AS |
4176 | static void brcms_c_radio_monitor_start(struct brcms_c_info *wlc) |
4177 | { | |
4178 | /* Don't start the timer if HWRADIO feature is disabled */ | |
4179 | if (wlc->radio_monitor) | |
4180 | return; | |
4181 | ||
4182 | wlc->radio_monitor = true; | |
4183 | brcms_b_pllreq(wlc->hw, true, BRCMS_PLLREQ_RADIO_MON); | |
be69c4ef | 4184 | brcms_add_timer(wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, true); |
5b435de0 AS |
4185 | } |
4186 | ||
94bdc2a2 | 4187 | static bool brcms_c_radio_monitor_stop(struct brcms_c_info *wlc) |
5b435de0 AS |
4188 | { |
4189 | if (!wlc->radio_monitor) | |
4190 | return true; | |
4191 | ||
4192 | wlc->radio_monitor = false; | |
4193 | brcms_b_pllreq(wlc->hw, false, BRCMS_PLLREQ_RADIO_MON); | |
be69c4ef | 4194 | return brcms_del_timer(wlc->radio_timer); |
5b435de0 AS |
4195 | } |
4196 | ||
4197 | /* read hwdisable state and propagate to wlc flag */ | |
4198 | static void brcms_c_radio_hwdisable_upd(struct brcms_c_info *wlc) | |
4199 | { | |
4200 | if (wlc->pub->hw_off) | |
4201 | return; | |
4202 | ||
4203 | if (brcms_b_radio_read_hwdisabled(wlc->hw)) | |
4204 | mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE); | |
4205 | else | |
4206 | mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE); | |
4207 | } | |
4208 | ||
5b435de0 AS |
4209 | /* update hwradio status and return it */ |
4210 | bool brcms_c_check_radio_disabled(struct brcms_c_info *wlc) | |
4211 | { | |
4212 | brcms_c_radio_hwdisable_upd(wlc); | |
4213 | ||
4214 | return mboolisset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE) ? | |
4215 | true : false; | |
4216 | } | |
4217 | ||
4218 | /* periodical query hw radio button while driver is "down" */ | |
4219 | static void brcms_c_radio_timer(void *arg) | |
4220 | { | |
4221 | struct brcms_c_info *wlc = (struct brcms_c_info *) arg; | |
4222 | ||
4223 | if (brcms_deviceremoved(wlc)) { | |
4224 | wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", wlc->pub->unit, | |
4225 | __func__); | |
4226 | brcms_down(wlc->wl); | |
4227 | return; | |
4228 | } | |
4229 | ||
5b435de0 | 4230 | brcms_c_radio_hwdisable_upd(wlc); |
5b435de0 AS |
4231 | } |
4232 | ||
4233 | /* common low-level watchdog code */ | |
4234 | static void brcms_b_watchdog(void *arg) | |
4235 | { | |
4236 | struct brcms_c_info *wlc = (struct brcms_c_info *) arg; | |
4237 | struct brcms_hardware *wlc_hw = wlc->hw; | |
4238 | ||
4239 | BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
4240 | ||
4241 | if (!wlc_hw->up) | |
4242 | return; | |
4243 | ||
4244 | /* increment second count */ | |
4245 | wlc_hw->now++; | |
4246 | ||
4247 | /* Check for FIFO error interrupts */ | |
4248 | brcms_b_fifoerrors(wlc_hw); | |
4249 | ||
4250 | /* make sure RX dma has buffers */ | |
4251 | dma_rxfill(wlc->hw->di[RX_FIFO]); | |
4252 | ||
4253 | wlc_phy_watchdog(wlc_hw->band->pi); | |
4254 | } | |
4255 | ||
4256 | /* common watchdog code */ | |
4257 | static void brcms_c_watchdog(void *arg) | |
4258 | { | |
4259 | struct brcms_c_info *wlc = (struct brcms_c_info *) arg; | |
4260 | ||
4261 | BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit); | |
4262 | ||
4263 | if (!wlc->pub->up) | |
4264 | return; | |
4265 | ||
4266 | if (brcms_deviceremoved(wlc)) { | |
4267 | wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", wlc->pub->unit, | |
4268 | __func__); | |
4269 | brcms_down(wlc->wl); | |
4270 | return; | |
4271 | } | |
4272 | ||
4273 | /* increment second count */ | |
4274 | wlc->pub->now++; | |
4275 | ||
5b435de0 | 4276 | brcms_c_radio_hwdisable_upd(wlc); |
5b435de0 AS |
4277 | /* if radio is disable, driver may be down, quit here */ |
4278 | if (wlc->pub->radio_disabled) | |
4279 | return; | |
4280 | ||
4281 | brcms_b_watchdog(wlc); | |
4282 | ||
4283 | /* | |
4284 | * occasionally sample mac stat counters to | |
4285 | * detect 16-bit counter wrap | |
4286 | */ | |
4287 | if ((wlc->pub->now % SW_TIMER_MAC_STAT_UPD) == 0) | |
4288 | brcms_c_statsupd(wlc); | |
4289 | ||
4290 | if (BRCMS_ISNPHY(wlc->band) && | |
4291 | ((wlc->pub->now - wlc->tempsense_lasttime) >= | |
4292 | BRCMS_TEMPSENSE_PERIOD)) { | |
4293 | wlc->tempsense_lasttime = wlc->pub->now; | |
4294 | brcms_c_tempsense_upd(wlc); | |
4295 | } | |
4296 | } | |
4297 | ||
4298 | static void brcms_c_watchdog_by_timer(void *arg) | |
4299 | { | |
4300 | brcms_c_watchdog(arg); | |
4301 | } | |
4302 | ||
94bdc2a2 | 4303 | static bool brcms_c_timers_init(struct brcms_c_info *wlc, int unit) |
5b435de0 AS |
4304 | { |
4305 | wlc->wdtimer = brcms_init_timer(wlc->wl, brcms_c_watchdog_by_timer, | |
4306 | wlc, "watchdog"); | |
4307 | if (!wlc->wdtimer) { | |
4308 | wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for wdtimer " | |
4309 | "failed\n", unit); | |
4310 | goto fail; | |
4311 | } | |
4312 | ||
4313 | wlc->radio_timer = brcms_init_timer(wlc->wl, brcms_c_radio_timer, | |
4314 | wlc, "radio"); | |
4315 | if (!wlc->radio_timer) { | |
4316 | wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for radio_timer " | |
4317 | "failed\n", unit); | |
4318 | goto fail; | |
4319 | } | |
4320 | ||
4321 | return true; | |
4322 | ||
4323 | fail: | |
4324 | return false; | |
4325 | } | |
4326 | ||
4327 | /* | |
4328 | * Initialize brcms_c_info default values ... | |
4329 | * may get overrides later in this function | |
4330 | */ | |
94bdc2a2 | 4331 | static void brcms_c_info_init(struct brcms_c_info *wlc, int unit) |
5b435de0 AS |
4332 | { |
4333 | int i; | |
4334 | ||
4335 | /* Save our copy of the chanspec */ | |
4336 | wlc->chanspec = ch20mhz_chspec(1); | |
4337 | ||
4338 | /* various 802.11g modes */ | |
4339 | wlc->shortslot = false; | |
4340 | wlc->shortslot_override = BRCMS_SHORTSLOT_AUTO; | |
4341 | ||
4342 | brcms_c_protection_upd(wlc, BRCMS_PROT_G_OVR, BRCMS_PROTECTION_AUTO); | |
4343 | brcms_c_protection_upd(wlc, BRCMS_PROT_G_SPEC, false); | |
4344 | ||
4345 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_CFG_OVR, | |
4346 | BRCMS_PROTECTION_AUTO); | |
4347 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_CFG, BRCMS_N_PROTECTION_OFF); | |
4348 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_NONGF_OVR, | |
4349 | BRCMS_PROTECTION_AUTO); | |
4350 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_NONGF, false); | |
4351 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_PAM_OVR, AUTO); | |
4352 | ||
4353 | brcms_c_protection_upd(wlc, BRCMS_PROT_OVERLAP, | |
4354 | BRCMS_PROTECTION_CTL_OVERLAP); | |
4355 | ||
4356 | /* 802.11g draft 4.0 NonERP elt advertisement */ | |
4357 | wlc->include_legacy_erp = true; | |
4358 | ||
4359 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF; | |
4360 | wlc->stf->txant = ANT_TX_DEF; | |
4361 | ||
4362 | wlc->prb_resp_timeout = BRCMS_PRB_RESP_TIMEOUT; | |
4363 | ||
4364 | wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN; | |
4365 | for (i = 0; i < NFIFO; i++) | |
4366 | wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN; | |
4367 | wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN; | |
4368 | ||
4369 | /* default rate fallback retry limits */ | |
4370 | wlc->SFBL = RETRY_SHORT_FB; | |
4371 | wlc->LFBL = RETRY_LONG_FB; | |
4372 | ||
4373 | /* default mac retry limits */ | |
4374 | wlc->SRL = RETRY_SHORT_DEF; | |
4375 | wlc->LRL = RETRY_LONG_DEF; | |
4376 | ||
4377 | /* WME QoS mode is Auto by default */ | |
4378 | wlc->pub->_ampdu = AMPDU_AGG_HOST; | |
4379 | wlc->pub->bcmerror = 0; | |
5b435de0 AS |
4380 | } |
4381 | ||
4382 | static uint brcms_c_attach_module(struct brcms_c_info *wlc) | |
4383 | { | |
4384 | uint err = 0; | |
4385 | uint unit; | |
4386 | unit = wlc->pub->unit; | |
4387 | ||
4388 | wlc->asi = brcms_c_antsel_attach(wlc); | |
4389 | if (wlc->asi == NULL) { | |
4390 | wiphy_err(wlc->wiphy, "wl%d: attach: antsel_attach " | |
4391 | "failed\n", unit); | |
4392 | err = 44; | |
4393 | goto fail; | |
4394 | } | |
4395 | ||
4396 | wlc->ampdu = brcms_c_ampdu_attach(wlc); | |
4397 | if (wlc->ampdu == NULL) { | |
4398 | wiphy_err(wlc->wiphy, "wl%d: attach: ampdu_attach " | |
4399 | "failed\n", unit); | |
4400 | err = 50; | |
4401 | goto fail; | |
4402 | } | |
4403 | ||
4404 | if ((brcms_c_stf_attach(wlc) != 0)) { | |
4405 | wiphy_err(wlc->wiphy, "wl%d: attach: stf_attach " | |
4406 | "failed\n", unit); | |
4407 | err = 68; | |
4408 | goto fail; | |
4409 | } | |
4410 | fail: | |
4411 | return err; | |
4412 | } | |
4413 | ||
4414 | struct brcms_pub *brcms_c_pub(struct brcms_c_info *wlc) | |
4415 | { | |
4416 | return wlc->pub; | |
4417 | } | |
4418 | ||
4419 | /* low level attach | |
4420 | * run backplane attach, init nvram | |
4421 | * run phy attach | |
4422 | * initialize software state for each core and band | |
4423 | * put the whole chip in reset(driver down state), no clock | |
4424 | */ | |
b63337a0 AS |
4425 | static int brcms_b_attach(struct brcms_c_info *wlc, struct bcma_device *core, |
4426 | uint unit, bool piomode) | |
5b435de0 AS |
4427 | { |
4428 | struct brcms_hardware *wlc_hw; | |
5b435de0 AS |
4429 | uint err = 0; |
4430 | uint j; | |
4431 | bool wme = false; | |
4432 | struct shared_phy_params sha_params; | |
4433 | struct wiphy *wiphy = wlc->wiphy; | |
b63337a0 | 4434 | struct pci_dev *pcidev = core->bus->host_pci; |
898d3c3b | 4435 | struct ssb_sprom *sprom = &core->bus->sprom; |
5b435de0 | 4436 | |
b63337a0 AS |
4437 | BCMMSG(wlc->wiphy, "wl%d: vendor 0x%x device 0x%x\n", unit, |
4438 | pcidev->vendor, | |
4439 | pcidev->device); | |
5b435de0 AS |
4440 | |
4441 | wme = true; | |
4442 | ||
4443 | wlc_hw = wlc->hw; | |
4444 | wlc_hw->wlc = wlc; | |
4445 | wlc_hw->unit = unit; | |
4446 | wlc_hw->band = wlc_hw->bandstate[0]; | |
4447 | wlc_hw->_piomode = piomode; | |
4448 | ||
4449 | /* populate struct brcms_hardware with default values */ | |
4450 | brcms_b_info_init(wlc_hw); | |
4451 | ||
4452 | /* | |
4453 | * Do the hardware portion of the attach. Also initialize software | |
4454 | * state that depends on the particular hardware we are running. | |
4455 | */ | |
28a53442 | 4456 | wlc_hw->sih = ai_attach(core->bus); |
5b435de0 AS |
4457 | if (wlc_hw->sih == NULL) { |
4458 | wiphy_err(wiphy, "wl%d: brcms_b_attach: si_attach failed\n", | |
4459 | unit); | |
4460 | err = 11; | |
4461 | goto fail; | |
4462 | } | |
4463 | ||
4464 | /* verify again the device is supported */ | |
b63337a0 | 4465 | if (!brcms_c_chipmatch(pcidev->vendor, pcidev->device)) { |
5b435de0 AS |
4466 | wiphy_err(wiphy, "wl%d: brcms_b_attach: Unsupported " |
4467 | "vendor/device (0x%x/0x%x)\n", | |
b63337a0 | 4468 | unit, pcidev->vendor, pcidev->device); |
5b435de0 AS |
4469 | err = 12; |
4470 | goto fail; | |
4471 | } | |
4472 | ||
b63337a0 AS |
4473 | wlc_hw->vendorid = pcidev->vendor; |
4474 | wlc_hw->deviceid = pcidev->device; | |
5b435de0 | 4475 | |
16d2812e AS |
4476 | wlc_hw->d11core = core; |
4477 | wlc_hw->corerev = core->id.rev; | |
5b435de0 AS |
4478 | |
4479 | /* validate chip, chiprev and corerev */ | |
4480 | if (!brcms_c_isgoodchip(wlc_hw)) { | |
4481 | err = 13; | |
4482 | goto fail; | |
4483 | } | |
4484 | ||
4485 | /* initialize power control registers */ | |
4486 | ai_clkctl_init(wlc_hw->sih); | |
4487 | ||
4488 | /* request fastclock and force fastclock for the rest of attach | |
4489 | * bring the d11 core out of reset. | |
4490 | * For PMU chips, the first wlc_clkctl_clk is no-op since core-clk | |
4491 | * is still false; But it will be called again inside wlc_corereset, | |
4492 | * after d11 is out of reset. | |
4493 | */ | |
712e3c1f | 4494 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
5b435de0 AS |
4495 | brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS); |
4496 | ||
4497 | if (!brcms_b_validate_chip_access(wlc_hw)) { | |
4498 | wiphy_err(wiphy, "wl%d: brcms_b_attach: validate_chip_access " | |
4499 | "failed\n", unit); | |
4500 | err = 14; | |
4501 | goto fail; | |
4502 | } | |
4503 | ||
4504 | /* get the board rev, used just below */ | |
898d3c3b | 4505 | j = sprom->board_rev; |
5b435de0 AS |
4506 | /* promote srom boardrev of 0xFF to 1 */ |
4507 | if (j == BOARDREV_PROMOTABLE) | |
4508 | j = BOARDREV_PROMOTED; | |
4509 | wlc_hw->boardrev = (u16) j; | |
4510 | if (!brcms_c_validboardtype(wlc_hw)) { | |
4511 | wiphy_err(wiphy, "wl%d: brcms_b_attach: Unsupported Broadcom " | |
b2ffec46 AS |
4512 | "board type (0x%x)" " or revision level (0x%x)\n", |
4513 | unit, ai_get_boardtype(wlc_hw->sih), | |
4514 | wlc_hw->boardrev); | |
5b435de0 AS |
4515 | err = 15; |
4516 | goto fail; | |
4517 | } | |
898d3c3b HM |
4518 | wlc_hw->sromrev = sprom->revision; |
4519 | wlc_hw->boardflags = sprom->boardflags_lo + (sprom->boardflags_hi << 16); | |
4520 | wlc_hw->boardflags2 = sprom->boardflags2_lo + (sprom->boardflags2_hi << 16); | |
5b435de0 AS |
4521 | |
4522 | if (wlc_hw->boardflags & BFL_NOPLLDOWN) | |
4523 | brcms_b_pllreq(wlc_hw, true, BRCMS_PLLREQ_SHARED); | |
4524 | ||
4525 | /* check device id(srom, nvram etc.) to set bands */ | |
4526 | if (wlc_hw->deviceid == BCM43224_D11N_ID || | |
4527 | wlc_hw->deviceid == BCM43224_D11N_ID_VEN1) | |
4528 | /* Dualband boards */ | |
4529 | wlc_hw->_nbands = 2; | |
4530 | else | |
4531 | wlc_hw->_nbands = 1; | |
4532 | ||
b2ffec46 | 4533 | if ((ai_get_chip_id(wlc_hw->sih) == BCM43225_CHIP_ID)) |
5b435de0 AS |
4534 | wlc_hw->_nbands = 1; |
4535 | ||
4536 | /* BMAC_NOTE: remove init of pub values when brcms_c_attach() | |
4537 | * unconditionally does the init of these values | |
4538 | */ | |
4539 | wlc->vendorid = wlc_hw->vendorid; | |
4540 | wlc->deviceid = wlc_hw->deviceid; | |
4541 | wlc->pub->sih = wlc_hw->sih; | |
4542 | wlc->pub->corerev = wlc_hw->corerev; | |
4543 | wlc->pub->sromrev = wlc_hw->sromrev; | |
4544 | wlc->pub->boardrev = wlc_hw->boardrev; | |
4545 | wlc->pub->boardflags = wlc_hw->boardflags; | |
4546 | wlc->pub->boardflags2 = wlc_hw->boardflags2; | |
4547 | wlc->pub->_nbands = wlc_hw->_nbands; | |
4548 | ||
4549 | wlc_hw->physhim = wlc_phy_shim_attach(wlc_hw, wlc->wl, wlc); | |
4550 | ||
4551 | if (wlc_hw->physhim == NULL) { | |
4552 | wiphy_err(wiphy, "wl%d: brcms_b_attach: wlc_phy_shim_attach " | |
4553 | "failed\n", unit); | |
4554 | err = 25; | |
4555 | goto fail; | |
4556 | } | |
4557 | ||
4558 | /* pass all the parameters to wlc_phy_shared_attach in one struct */ | |
4559 | sha_params.sih = wlc_hw->sih; | |
4560 | sha_params.physhim = wlc_hw->physhim; | |
4561 | sha_params.unit = unit; | |
4562 | sha_params.corerev = wlc_hw->corerev; | |
4563 | sha_params.vid = wlc_hw->vendorid; | |
4564 | sha_params.did = wlc_hw->deviceid; | |
b2ffec46 AS |
4565 | sha_params.chip = ai_get_chip_id(wlc_hw->sih); |
4566 | sha_params.chiprev = ai_get_chiprev(wlc_hw->sih); | |
4567 | sha_params.chippkg = ai_get_chippkg(wlc_hw->sih); | |
5b435de0 | 4568 | sha_params.sromrev = wlc_hw->sromrev; |
b2ffec46 | 4569 | sha_params.boardtype = ai_get_boardtype(wlc_hw->sih); |
5b435de0 | 4570 | sha_params.boardrev = wlc_hw->boardrev; |
5b435de0 AS |
4571 | sha_params.boardflags = wlc_hw->boardflags; |
4572 | sha_params.boardflags2 = wlc_hw->boardflags2; | |
5b435de0 AS |
4573 | |
4574 | /* alloc and save pointer to shared phy state area */ | |
4575 | wlc_hw->phy_sh = wlc_phy_shared_attach(&sha_params); | |
4576 | if (!wlc_hw->phy_sh) { | |
4577 | err = 16; | |
4578 | goto fail; | |
4579 | } | |
4580 | ||
4581 | /* initialize software state for each core and band */ | |
4582 | for (j = 0; j < wlc_hw->_nbands; j++) { | |
4583 | /* | |
4584 | * band0 is always 2.4Ghz | |
4585 | * band1, if present, is 5Ghz | |
4586 | */ | |
4587 | ||
4588 | brcms_c_setxband(wlc_hw, j); | |
4589 | ||
4590 | wlc_hw->band->bandunit = j; | |
4591 | wlc_hw->band->bandtype = j ? BRCM_BAND_5G : BRCM_BAND_2G; | |
4592 | wlc->band->bandunit = j; | |
4593 | wlc->band->bandtype = j ? BRCM_BAND_5G : BRCM_BAND_2G; | |
3b758a68 | 4594 | wlc->core->coreidx = core->core_index; |
5b435de0 | 4595 | |
16d2812e | 4596 | wlc_hw->machwcap = bcma_read32(core, D11REGOFFS(machwcap)); |
5b435de0 AS |
4597 | wlc_hw->machwcap_backup = wlc_hw->machwcap; |
4598 | ||
4599 | /* init tx fifo size */ | |
4600 | wlc_hw->xmtfifo_sz = | |
4601 | xmtfifo_sz[(wlc_hw->corerev - XMTFIFOTBL_STARTREV)]; | |
4602 | ||
4603 | /* Get a phy for this band */ | |
4604 | wlc_hw->band->pi = | |
4b006b11 | 4605 | wlc_phy_attach(wlc_hw->phy_sh, core, |
5b435de0 AS |
4606 | wlc_hw->band->bandtype, |
4607 | wlc->wiphy); | |
4608 | if (wlc_hw->band->pi == NULL) { | |
4609 | wiphy_err(wiphy, "wl%d: brcms_b_attach: wlc_phy_" | |
4610 | "attach failed\n", unit); | |
4611 | err = 17; | |
4612 | goto fail; | |
4613 | } | |
4614 | ||
4615 | wlc_phy_machwcap_set(wlc_hw->band->pi, wlc_hw->machwcap); | |
4616 | ||
4617 | wlc_phy_get_phyversion(wlc_hw->band->pi, &wlc_hw->band->phytype, | |
4618 | &wlc_hw->band->phyrev, | |
4619 | &wlc_hw->band->radioid, | |
4620 | &wlc_hw->band->radiorev); | |
4621 | wlc_hw->band->abgphy_encore = | |
4622 | wlc_phy_get_encore(wlc_hw->band->pi); | |
4623 | wlc->band->abgphy_encore = wlc_phy_get_encore(wlc_hw->band->pi); | |
4624 | wlc_hw->band->core_flags = | |
4625 | wlc_phy_get_coreflags(wlc_hw->band->pi); | |
4626 | ||
4627 | /* verify good phy_type & supported phy revision */ | |
4628 | if (BRCMS_ISNPHY(wlc_hw->band)) { | |
4629 | if (NCONF_HAS(wlc_hw->band->phyrev)) | |
4630 | goto good_phy; | |
4631 | else | |
4632 | goto bad_phy; | |
4633 | } else if (BRCMS_ISLCNPHY(wlc_hw->band)) { | |
4634 | if (LCNCONF_HAS(wlc_hw->band->phyrev)) | |
4635 | goto good_phy; | |
4636 | else | |
4637 | goto bad_phy; | |
4638 | } else { | |
4639 | bad_phy: | |
4640 | wiphy_err(wiphy, "wl%d: brcms_b_attach: unsupported " | |
4641 | "phy type/rev (%d/%d)\n", unit, | |
4642 | wlc_hw->band->phytype, wlc_hw->band->phyrev); | |
4643 | err = 18; | |
4644 | goto fail; | |
4645 | } | |
4646 | ||
4647 | good_phy: | |
4648 | /* | |
4649 | * BMAC_NOTE: wlc->band->pi should not be set below and should | |
4650 | * be done in the high level attach. However we can not make | |
4651 | * that change until all low level access is changed to | |
4652 | * wlc_hw->band->pi. Instead do the wlc->band->pi init below, | |
4653 | * keeping wlc_hw->band->pi as well for incremental update of | |
4654 | * low level fns, and cut over low only init when all fns | |
4655 | * updated. | |
4656 | */ | |
4657 | wlc->band->pi = wlc_hw->band->pi; | |
4658 | wlc->band->phytype = wlc_hw->band->phytype; | |
4659 | wlc->band->phyrev = wlc_hw->band->phyrev; | |
4660 | wlc->band->radioid = wlc_hw->band->radioid; | |
4661 | wlc->band->radiorev = wlc_hw->band->radiorev; | |
4662 | ||
4663 | /* default contention windows size limits */ | |
4664 | wlc_hw->band->CWmin = APHY_CWMIN; | |
4665 | wlc_hw->band->CWmax = PHY_CWMAX; | |
4666 | ||
4667 | if (!brcms_b_attach_dmapio(wlc, j, wme)) { | |
4668 | err = 19; | |
4669 | goto fail; | |
4670 | } | |
4671 | } | |
4672 | ||
4673 | /* disable core to match driver "down" state */ | |
4674 | brcms_c_coredisable(wlc_hw); | |
4675 | ||
4676 | /* Match driver "down" state */ | |
4677 | ai_pci_down(wlc_hw->sih); | |
4678 | ||
5b435de0 AS |
4679 | /* turn off pll and xtal to match driver "down" state */ |
4680 | brcms_b_xtal(wlc_hw, OFF); | |
4681 | ||
4682 | /* ******************************************************************* | |
4683 | * The hardware is in the DOWN state at this point. D11 core | |
4684 | * or cores are in reset with clocks off, and the board PLLs | |
4685 | * are off if possible. | |
4686 | * | |
4687 | * Beyond this point, wlc->sbclk == false and chip registers | |
4688 | * should not be touched. | |
4689 | ********************************************************************* | |
4690 | */ | |
4691 | ||
4692 | /* init etheraddr state variables */ | |
898d3c3b HM |
4693 | brcms_c_get_macaddr(wlc_hw, wlc_hw->etheraddr); |
4694 | ||
4695 | if (is_broadcast_ether_addr(wlc_hw->etheraddr) || | |
5b435de0 | 4696 | is_zero_ether_addr(wlc_hw->etheraddr)) { |
898d3c3b HM |
4697 | wiphy_err(wiphy, "wl%d: brcms_b_attach: bad macaddr\n", |
4698 | unit); | |
5b435de0 AS |
4699 | err = 22; |
4700 | goto fail; | |
4701 | } | |
4702 | ||
898d3c3b HM |
4703 | BCMMSG(wlc->wiphy, "deviceid 0x%x nbands %d board 0x%x\n", |
4704 | wlc_hw->deviceid, wlc_hw->_nbands, ai_get_boardtype(wlc_hw->sih)); | |
5b435de0 AS |
4705 | |
4706 | return err; | |
4707 | ||
4708 | fail: | |
4709 | wiphy_err(wiphy, "wl%d: brcms_b_attach: failed with err %d\n", unit, | |
4710 | err); | |
4711 | return err; | |
4712 | } | |
4713 | ||
4714 | static void brcms_c_attach_antgain_init(struct brcms_c_info *wlc) | |
4715 | { | |
4716 | uint unit; | |
4717 | unit = wlc->pub->unit; | |
4718 | ||
4719 | if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) { | |
4720 | /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */ | |
4721 | wlc->band->antgain = 8; | |
4722 | } else if (wlc->band->antgain == -1) { | |
4723 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid antennas available in" | |
4724 | " srom, using 2dB\n", unit, __func__); | |
4725 | wlc->band->antgain = 8; | |
4726 | } else { | |
4727 | s8 gain, fract; | |
4728 | /* Older sroms specified gain in whole dbm only. In order | |
4729 | * be able to specify qdbm granularity and remain backward | |
4730 | * compatible the whole dbms are now encoded in only | |
4731 | * low 6 bits and remaining qdbms are encoded in the hi 2 bits. | |
4732 | * 6 bit signed number ranges from -32 - 31. | |
4733 | * | |
4734 | * Examples: | |
4735 | * 0x1 = 1 db, | |
4736 | * 0xc1 = 1.75 db (1 + 3 quarters), | |
4737 | * 0x3f = -1 (-1 + 0 quarters), | |
4738 | * 0x7f = -.75 (-1 + 1 quarters) = -3 qdbm. | |
4739 | * 0xbf = -.50 (-1 + 2 quarters) = -2 qdbm. | |
4740 | */ | |
4741 | gain = wlc->band->antgain & 0x3f; | |
4742 | gain <<= 2; /* Sign extend */ | |
4743 | gain >>= 2; | |
4744 | fract = (wlc->band->antgain & 0xc0) >> 6; | |
4745 | wlc->band->antgain = 4 * gain + fract; | |
4746 | } | |
4747 | } | |
4748 | ||
4749 | static bool brcms_c_attach_stf_ant_init(struct brcms_c_info *wlc) | |
4750 | { | |
4751 | int aa; | |
4752 | uint unit; | |
4753 | int bandtype; | |
898d3c3b | 4754 | struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom; |
5b435de0 AS |
4755 | |
4756 | unit = wlc->pub->unit; | |
4757 | bandtype = wlc->band->bandtype; | |
4758 | ||
4759 | /* get antennas available */ | |
4760 | if (bandtype == BRCM_BAND_5G) | |
898d3c3b | 4761 | aa = sprom->ant_available_a; |
5b435de0 | 4762 | else |
898d3c3b | 4763 | aa = sprom->ant_available_bg; |
5b435de0 AS |
4764 | |
4765 | if ((aa < 1) || (aa > 15)) { | |
4766 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid antennas available in" | |
4767 | " srom (0x%x), using 3\n", unit, __func__, aa); | |
4768 | aa = 3; | |
4769 | } | |
4770 | ||
4771 | /* reset the defaults if we have a single antenna */ | |
4772 | if (aa == 1) { | |
4773 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0; | |
4774 | wlc->stf->txant = ANT_TX_FORCE_0; | |
4775 | } else if (aa == 2) { | |
4776 | wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1; | |
4777 | wlc->stf->txant = ANT_TX_FORCE_1; | |
4778 | } else { | |
4779 | } | |
4780 | ||
4781 | /* Compute Antenna Gain */ | |
4782 | if (bandtype == BRCM_BAND_5G) | |
898d3c3b | 4783 | wlc->band->antgain = sprom->antenna_gain.a1; |
5b435de0 | 4784 | else |
898d3c3b | 4785 | wlc->band->antgain = sprom->antenna_gain.a0; |
5b435de0 AS |
4786 | |
4787 | brcms_c_attach_antgain_init(wlc); | |
4788 | ||
4789 | return true; | |
4790 | } | |
4791 | ||
4792 | static void brcms_c_bss_default_init(struct brcms_c_info *wlc) | |
4793 | { | |
4794 | u16 chanspec; | |
4795 | struct brcms_band *band; | |
4796 | struct brcms_bss_info *bi = wlc->default_bss; | |
4797 | ||
4798 | /* init default and target BSS with some sane initial values */ | |
4799 | memset((char *)(bi), 0, sizeof(struct brcms_bss_info)); | |
4800 | bi->beacon_period = BEACON_INTERVAL_DEFAULT; | |
4801 | ||
4802 | /* fill the default channel as the first valid channel | |
4803 | * starting from the 2G channels | |
4804 | */ | |
4805 | chanspec = ch20mhz_chspec(1); | |
4806 | wlc->home_chanspec = bi->chanspec = chanspec; | |
4807 | ||
4808 | /* find the band of our default channel */ | |
4809 | band = wlc->band; | |
4810 | if (wlc->pub->_nbands > 1 && | |
4811 | band->bandunit != chspec_bandunit(chanspec)) | |
4812 | band = wlc->bandstate[OTHERBANDUNIT(wlc)]; | |
4813 | ||
4814 | /* init bss rates to the band specific default rate set */ | |
4815 | brcms_c_rateset_default(&bi->rateset, NULL, band->phytype, | |
4816 | band->bandtype, false, BRCMS_RATE_MASK_FULL, | |
4817 | (bool) (wlc->pub->_n_enab & SUPPORT_11N), | |
4818 | brcms_chspec_bw(chanspec), wlc->stf->txstreams); | |
4819 | ||
4820 | if (wlc->pub->_n_enab & SUPPORT_11N) | |
4821 | bi->flags |= BRCMS_BSS_HT; | |
4822 | } | |
4823 | ||
4824 | static struct brcms_txq_info *brcms_c_txq_alloc(struct brcms_c_info *wlc) | |
4825 | { | |
4826 | struct brcms_txq_info *qi, *p; | |
4827 | ||
4828 | qi = kzalloc(sizeof(struct brcms_txq_info), GFP_ATOMIC); | |
4829 | if (qi != NULL) { | |
4830 | /* | |
4831 | * Have enough room for control packets along with HI watermark | |
4832 | * Also, add room to txq for total psq packets if all the SCBs | |
4833 | * leave PS mode. The watermark for flowcontrol to OS packets | |
4834 | * will remain the same | |
4835 | */ | |
4836 | brcmu_pktq_init(&qi->q, BRCMS_PREC_COUNT, | |
4837 | 2 * BRCMS_DATAHIWAT + PKTQ_LEN_DEFAULT); | |
4838 | ||
4839 | /* add this queue to the the global list */ | |
4840 | p = wlc->tx_queues; | |
4841 | if (p == NULL) { | |
4842 | wlc->tx_queues = qi; | |
4843 | } else { | |
4844 | while (p->next != NULL) | |
4845 | p = p->next; | |
4846 | p->next = qi; | |
4847 | } | |
4848 | } | |
4849 | return qi; | |
4850 | } | |
4851 | ||
4852 | static void brcms_c_txq_free(struct brcms_c_info *wlc, | |
4853 | struct brcms_txq_info *qi) | |
4854 | { | |
4855 | struct brcms_txq_info *p; | |
4856 | ||
4857 | if (qi == NULL) | |
4858 | return; | |
4859 | ||
4860 | /* remove the queue from the linked list */ | |
4861 | p = wlc->tx_queues; | |
4862 | if (p == qi) | |
4863 | wlc->tx_queues = p->next; | |
4864 | else { | |
4865 | while (p != NULL && p->next != qi) | |
4866 | p = p->next; | |
4867 | if (p != NULL) | |
4868 | p->next = p->next->next; | |
4869 | } | |
4870 | ||
4871 | kfree(qi); | |
4872 | } | |
4873 | ||
4874 | static void brcms_c_update_mimo_band_bwcap(struct brcms_c_info *wlc, u8 bwcap) | |
4875 | { | |
4876 | uint i; | |
4877 | struct brcms_band *band; | |
4878 | ||
4879 | for (i = 0; i < wlc->pub->_nbands; i++) { | |
4880 | band = wlc->bandstate[i]; | |
4881 | if (band->bandtype == BRCM_BAND_5G) { | |
4882 | if ((bwcap == BRCMS_N_BW_40ALL) | |
4883 | || (bwcap == BRCMS_N_BW_20IN2G_40IN5G)) | |
4884 | band->mimo_cap_40 = true; | |
4885 | else | |
4886 | band->mimo_cap_40 = false; | |
4887 | } else { | |
4888 | if (bwcap == BRCMS_N_BW_40ALL) | |
4889 | band->mimo_cap_40 = true; | |
4890 | else | |
4891 | band->mimo_cap_40 = false; | |
4892 | } | |
4893 | } | |
4894 | } | |
4895 | ||
94bdc2a2 | 4896 | static void brcms_c_timers_deinit(struct brcms_c_info *wlc) |
5b435de0 | 4897 | { |
94bdc2a2 AB |
4898 | /* free timer state */ |
4899 | if (wlc->wdtimer) { | |
4900 | brcms_free_timer(wlc->wdtimer); | |
4901 | wlc->wdtimer = NULL; | |
4902 | } | |
4903 | if (wlc->radio_timer) { | |
4904 | brcms_free_timer(wlc->radio_timer); | |
4905 | wlc->radio_timer = NULL; | |
4906 | } | |
4907 | } | |
5b435de0 | 4908 | |
94bdc2a2 AB |
4909 | static void brcms_c_detach_module(struct brcms_c_info *wlc) |
4910 | { | |
4911 | if (wlc->asi) { | |
4912 | brcms_c_antsel_detach(wlc->asi); | |
4913 | wlc->asi = NULL; | |
4914 | } | |
5b435de0 | 4915 | |
94bdc2a2 AB |
4916 | if (wlc->ampdu) { |
4917 | brcms_c_ampdu_detach(wlc->ampdu); | |
4918 | wlc->ampdu = NULL; | |
4919 | } | |
5b435de0 | 4920 | |
94bdc2a2 AB |
4921 | brcms_c_stf_detach(wlc); |
4922 | } | |
5b435de0 AS |
4923 | |
4924 | /* | |
4925 | * low level detach | |
4926 | */ | |
4927 | static int brcms_b_detach(struct brcms_c_info *wlc) | |
4928 | { | |
4929 | uint i; | |
4930 | struct brcms_hw_band *band; | |
4931 | struct brcms_hardware *wlc_hw = wlc->hw; | |
4932 | int callbacks; | |
4933 | ||
4934 | callbacks = 0; | |
4935 | ||
5b435de0 AS |
4936 | brcms_b_detach_dmapio(wlc_hw); |
4937 | ||
4938 | band = wlc_hw->band; | |
4939 | for (i = 0; i < wlc_hw->_nbands; i++) { | |
4940 | if (band->pi) { | |
4941 | /* Detach this band's phy */ | |
4942 | wlc_phy_detach(band->pi); | |
4943 | band->pi = NULL; | |
4944 | } | |
4945 | band = wlc_hw->bandstate[OTHERBANDUNIT(wlc)]; | |
4946 | } | |
4947 | ||
4948 | /* Free shared phy state */ | |
4949 | kfree(wlc_hw->phy_sh); | |
4950 | ||
4951 | wlc_phy_shim_detach(wlc_hw->physhim); | |
4952 | ||
4953 | if (wlc_hw->sih) { | |
4954 | ai_detach(wlc_hw->sih); | |
4955 | wlc_hw->sih = NULL; | |
4956 | } | |
4957 | ||
4958 | return callbacks; | |
4959 | ||
4960 | } | |
4961 | ||
4962 | /* | |
4963 | * Return a count of the number of driver callbacks still pending. | |
4964 | * | |
4965 | * General policy is that brcms_c_detach can only dealloc/free software states. | |
4966 | * It can NOT touch hardware registers since the d11core may be in reset and | |
4967 | * clock may not be available. | |
4968 | * One exception is sb register access, which is possible if crystal is turned | |
4969 | * on after "down" state, driver should avoid software timer with the exception | |
4970 | * of radio_monitor. | |
4971 | */ | |
4972 | uint brcms_c_detach(struct brcms_c_info *wlc) | |
4973 | { | |
4974 | uint callbacks = 0; | |
4975 | ||
4976 | if (wlc == NULL) | |
4977 | return 0; | |
4978 | ||
4979 | BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit); | |
4980 | ||
4981 | callbacks += brcms_b_detach(wlc); | |
4982 | ||
4983 | /* delete software timers */ | |
4984 | if (!brcms_c_radio_monitor_stop(wlc)) | |
4985 | callbacks++; | |
4986 | ||
4987 | brcms_c_channel_mgr_detach(wlc->cmi); | |
4988 | ||
4989 | brcms_c_timers_deinit(wlc); | |
4990 | ||
4991 | brcms_c_detach_module(wlc); | |
4992 | ||
4993 | ||
4994 | while (wlc->tx_queues != NULL) | |
4995 | brcms_c_txq_free(wlc, wlc->tx_queues); | |
4996 | ||
4997 | brcms_c_detach_mfree(wlc); | |
4998 | return callbacks; | |
4999 | } | |
5000 | ||
5001 | /* update state that depends on the current value of "ap" */ | |
94bdc2a2 | 5002 | static void brcms_c_ap_upd(struct brcms_c_info *wlc) |
5b435de0 AS |
5003 | { |
5004 | /* STA-BSS; short capable */ | |
5005 | wlc->PLCPHdr_override = BRCMS_PLCP_SHORT; | |
5b435de0 AS |
5006 | } |
5007 | ||
5b435de0 AS |
5008 | /* Initialize just the hardware when coming out of POR or S3/S5 system states */ |
5009 | static void brcms_b_hw_up(struct brcms_hardware *wlc_hw) | |
5010 | { | |
5011 | if (wlc_hw->wlc->pub->hw_up) | |
5012 | return; | |
5013 | ||
5014 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
5015 | ||
5016 | /* | |
5017 | * Enable pll and xtal, initialize the power control registers, | |
5018 | * and force fastclock for the remainder of brcms_c_up(). | |
5019 | */ | |
5020 | brcms_b_xtal(wlc_hw, ON); | |
5021 | ai_clkctl_init(wlc_hw->sih); | |
712e3c1f | 5022 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
5b435de0 | 5023 | |
5b435de0 | 5024 | /* |
3b758a68 AS |
5025 | * TODO: test suspend/resume |
5026 | * | |
5b435de0 AS |
5027 | * AI chip doesn't restore bar0win2 on |
5028 | * hibernation/resume, need sw fixup | |
5029 | */ | |
5b435de0 AS |
5030 | |
5031 | /* | |
5032 | * Inform phy that a POR reset has occurred so | |
5033 | * it does a complete phy init | |
5034 | */ | |
5035 | wlc_phy_por_inform(wlc_hw->band->pi); | |
5036 | ||
5037 | wlc_hw->ucode_loaded = false; | |
5038 | wlc_hw->wlc->pub->hw_up = true; | |
5039 | ||
5040 | if ((wlc_hw->boardflags & BFL_FEM) | |
b2ffec46 | 5041 | && (ai_get_chip_id(wlc_hw->sih) == BCM4313_CHIP_ID)) { |
5b435de0 AS |
5042 | if (! |
5043 | (wlc_hw->boardrev >= 0x1250 | |
5044 | && (wlc_hw->boardflags & BFL_FEM_BT))) | |
5045 | ai_epa_4313war(wlc_hw->sih); | |
5046 | } | |
5047 | } | |
5048 | ||
5049 | static int brcms_b_up_prep(struct brcms_hardware *wlc_hw) | |
5050 | { | |
5b435de0 AS |
5051 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); |
5052 | ||
5053 | /* | |
5054 | * Enable pll and xtal, initialize the power control registers, | |
5055 | * and force fastclock for the remainder of brcms_c_up(). | |
5056 | */ | |
5057 | brcms_b_xtal(wlc_hw, ON); | |
5058 | ai_clkctl_init(wlc_hw->sih); | |
712e3c1f | 5059 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
5b435de0 AS |
5060 | |
5061 | /* | |
5062 | * Configure pci/pcmcia here instead of in brcms_c_attach() | |
5063 | * to allow mfg hotswap: down, hotswap (chip power cycle), up. | |
5064 | */ | |
b30ee754 HM |
5065 | bcma_core_pci_irq_ctl(&wlc_hw->d11core->bus->drv_pci, wlc_hw->d11core, |
5066 | true); | |
5b435de0 AS |
5067 | |
5068 | /* | |
5069 | * Need to read the hwradio status here to cover the case where the | |
5070 | * system is loaded with the hw radio disabled. We do not want to | |
5071 | * bring the driver up in this case. | |
5072 | */ | |
5073 | if (brcms_b_radio_read_hwdisabled(wlc_hw)) { | |
5074 | /* put SB PCI in down state again */ | |
5075 | ai_pci_down(wlc_hw->sih); | |
5076 | brcms_b_xtal(wlc_hw, OFF); | |
5077 | return -ENOMEDIUM; | |
5078 | } | |
5079 | ||
5080 | ai_pci_up(wlc_hw->sih); | |
5081 | ||
5082 | /* reset the d11 core */ | |
5083 | brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS); | |
5084 | ||
5085 | return 0; | |
5086 | } | |
5087 | ||
5088 | static int brcms_b_up_finish(struct brcms_hardware *wlc_hw) | |
5089 | { | |
5090 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
5091 | ||
5092 | wlc_hw->up = true; | |
5093 | wlc_phy_hw_state_upd(wlc_hw->band->pi, true); | |
5094 | ||
5095 | /* FULLY enable dynamic power control and d11 core interrupt */ | |
712e3c1f | 5096 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_DYNAMIC); |
5b435de0 AS |
5097 | brcms_intrson(wlc_hw->wlc->wl); |
5098 | return 0; | |
5099 | } | |
5100 | ||
5101 | /* | |
5102 | * Write WME tunable parameters for retransmit/max rate | |
5103 | * from wlc struct to ucode | |
5104 | */ | |
5105 | static void brcms_c_wme_retries_write(struct brcms_c_info *wlc) | |
5106 | { | |
5107 | int ac; | |
5108 | ||
5109 | /* Need clock to do this */ | |
5110 | if (!wlc->clk) | |
5111 | return; | |
5112 | ||
b7eec423 | 5113 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
5b435de0 AS |
5114 | brcms_b_write_shm(wlc->hw, M_AC_TXLMT_ADDR(ac), |
5115 | wlc->wme_retries[ac]); | |
5116 | } | |
5117 | ||
5118 | /* make interface operational */ | |
5119 | int brcms_c_up(struct brcms_c_info *wlc) | |
5120 | { | |
5121 | BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit); | |
5122 | ||
5123 | /* HW is turned off so don't try to access it */ | |
5124 | if (wlc->pub->hw_off || brcms_deviceremoved(wlc)) | |
5125 | return -ENOMEDIUM; | |
5126 | ||
5127 | if (!wlc->pub->hw_up) { | |
5128 | brcms_b_hw_up(wlc->hw); | |
5129 | wlc->pub->hw_up = true; | |
5130 | } | |
5131 | ||
5132 | if ((wlc->pub->boardflags & BFL_FEM) | |
b2ffec46 | 5133 | && (ai_get_chip_id(wlc->hw->sih) == BCM4313_CHIP_ID)) { |
5b435de0 AS |
5134 | if (wlc->pub->boardrev >= 0x1250 |
5135 | && (wlc->pub->boardflags & BFL_FEM_BT)) | |
5136 | brcms_b_mhf(wlc->hw, MHF5, MHF5_4313_GPIOCTRL, | |
5137 | MHF5_4313_GPIOCTRL, BRCM_BAND_ALL); | |
5138 | else | |
5139 | brcms_b_mhf(wlc->hw, MHF4, MHF4_EXTPA_ENABLE, | |
5140 | MHF4_EXTPA_ENABLE, BRCM_BAND_ALL); | |
5141 | } | |
5142 | ||
5143 | /* | |
5144 | * Need to read the hwradio status here to cover the case where the | |
5145 | * system is loaded with the hw radio disabled. We do not want to bring | |
5146 | * the driver up in this case. If radio is disabled, abort up, lower | |
5147 | * power, start radio timer and return 0(for NDIS) don't call | |
5148 | * radio_update to avoid looping brcms_c_up. | |
5149 | * | |
5150 | * brcms_b_up_prep() returns either 0 or -BCME_RADIOOFF only | |
5151 | */ | |
5152 | if (!wlc->pub->radio_disabled) { | |
5153 | int status = brcms_b_up_prep(wlc->hw); | |
5154 | if (status == -ENOMEDIUM) { | |
5155 | if (!mboolisset | |
5156 | (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) { | |
5157 | struct brcms_bss_cfg *bsscfg = wlc->bsscfg; | |
5158 | mboolset(wlc->pub->radio_disabled, | |
5159 | WL_RADIO_HW_DISABLE); | |
5160 | ||
5161 | if (bsscfg->enable && bsscfg->BSS) | |
5162 | wiphy_err(wlc->wiphy, "wl%d: up" | |
5163 | ": rfdisable -> " | |
5164 | "bsscfg_disable()\n", | |
5165 | wlc->pub->unit); | |
5166 | } | |
5167 | } | |
5168 | } | |
5169 | ||
5170 | if (wlc->pub->radio_disabled) { | |
5171 | brcms_c_radio_monitor_start(wlc); | |
5172 | return 0; | |
5173 | } | |
5174 | ||
5175 | /* brcms_b_up_prep has done brcms_c_corereset(). so clk is on, set it */ | |
5176 | wlc->clk = true; | |
5177 | ||
5178 | brcms_c_radio_monitor_stop(wlc); | |
5179 | ||
5180 | /* Set EDCF hostflags */ | |
5181 | brcms_b_mhf(wlc->hw, MHF1, MHF1_EDCF, MHF1_EDCF, BRCM_BAND_ALL); | |
5182 | ||
5183 | brcms_init(wlc->wl); | |
5184 | wlc->pub->up = true; | |
5185 | ||
5186 | if (wlc->bandinit_pending) { | |
5187 | brcms_c_suspend_mac_and_wait(wlc); | |
5188 | brcms_c_set_chanspec(wlc, wlc->default_bss->chanspec); | |
5189 | wlc->bandinit_pending = false; | |
5190 | brcms_c_enable_mac(wlc); | |
5191 | } | |
5192 | ||
5193 | brcms_b_up_finish(wlc->hw); | |
5194 | ||
5195 | /* Program the TX wme params with the current settings */ | |
5196 | brcms_c_wme_retries_write(wlc); | |
5197 | ||
5198 | /* start one second watchdog timer */ | |
be69c4ef | 5199 | brcms_add_timer(wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true); |
5b435de0 AS |
5200 | wlc->WDarmed = true; |
5201 | ||
5202 | /* ensure antenna config is up to date */ | |
5203 | brcms_c_stf_phy_txant_upd(wlc); | |
5204 | /* ensure LDPC config is in sync */ | |
5205 | brcms_c_ht_update_ldpc(wlc, wlc->stf->ldpc); | |
5206 | ||
5207 | return 0; | |
5208 | } | |
5209 | ||
5210 | static uint brcms_c_down_del_timer(struct brcms_c_info *wlc) | |
5211 | { | |
5212 | uint callbacks = 0; | |
5213 | ||
5214 | return callbacks; | |
5215 | } | |
5216 | ||
5217 | static int brcms_b_bmac_down_prep(struct brcms_hardware *wlc_hw) | |
5218 | { | |
5219 | bool dev_gone; | |
5220 | uint callbacks = 0; | |
5221 | ||
5222 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
5223 | ||
5224 | if (!wlc_hw->up) | |
5225 | return callbacks; | |
5226 | ||
5227 | dev_gone = brcms_deviceremoved(wlc_hw->wlc); | |
5228 | ||
5229 | /* disable interrupts */ | |
5230 | if (dev_gone) | |
5231 | wlc_hw->wlc->macintmask = 0; | |
5232 | else { | |
5233 | /* now disable interrupts */ | |
5234 | brcms_intrsoff(wlc_hw->wlc->wl); | |
5235 | ||
5236 | /* ensure we're running on the pll clock again */ | |
712e3c1f | 5237 | brcms_b_clkctl_clk(wlc_hw, BCMA_CLKMODE_FAST); |
5b435de0 AS |
5238 | } |
5239 | /* down phy at the last of this stage */ | |
5240 | callbacks += wlc_phy_down(wlc_hw->band->pi); | |
5241 | ||
5242 | return callbacks; | |
5243 | } | |
5244 | ||
5245 | static int brcms_b_down_finish(struct brcms_hardware *wlc_hw) | |
5246 | { | |
5247 | uint callbacks = 0; | |
5248 | bool dev_gone; | |
5249 | ||
5250 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); | |
5251 | ||
5252 | if (!wlc_hw->up) | |
5253 | return callbacks; | |
5254 | ||
5255 | wlc_hw->up = false; | |
5256 | wlc_phy_hw_state_upd(wlc_hw->band->pi, false); | |
5257 | ||
5258 | dev_gone = brcms_deviceremoved(wlc_hw->wlc); | |
5259 | ||
5260 | if (dev_gone) { | |
5261 | wlc_hw->sbclk = false; | |
5262 | wlc_hw->clk = false; | |
5263 | wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false); | |
5264 | ||
5265 | /* reclaim any posted packets */ | |
5266 | brcms_c_flushqueues(wlc_hw->wlc); | |
5267 | } else { | |
5268 | ||
5269 | /* Reset and disable the core */ | |
a8779e4a | 5270 | if (bcma_core_is_enabled(wlc_hw->d11core)) { |
16d2812e AS |
5271 | if (bcma_read32(wlc_hw->d11core, |
5272 | D11REGOFFS(maccontrol)) & MCTL_EN_MAC) | |
5b435de0 AS |
5273 | brcms_c_suspend_mac_and_wait(wlc_hw->wlc); |
5274 | callbacks += brcms_reset(wlc_hw->wlc->wl); | |
5275 | brcms_c_coredisable(wlc_hw); | |
5276 | } | |
5277 | ||
5278 | /* turn off primary xtal and pll */ | |
5279 | if (!wlc_hw->noreset) { | |
5280 | ai_pci_down(wlc_hw->sih); | |
5281 | brcms_b_xtal(wlc_hw, OFF); | |
5282 | } | |
5283 | } | |
5284 | ||
5285 | return callbacks; | |
5286 | } | |
5287 | ||
5288 | /* | |
5289 | * Mark the interface nonoperational, stop the software mechanisms, | |
5290 | * disable the hardware, free any transient buffer state. | |
5291 | * Return a count of the number of driver callbacks still pending. | |
5292 | */ | |
5293 | uint brcms_c_down(struct brcms_c_info *wlc) | |
5294 | { | |
5295 | ||
5296 | uint callbacks = 0; | |
5297 | int i; | |
5298 | bool dev_gone = false; | |
5299 | struct brcms_txq_info *qi; | |
5300 | ||
5301 | BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit); | |
5302 | ||
5303 | /* check if we are already in the going down path */ | |
5304 | if (wlc->going_down) { | |
5305 | wiphy_err(wlc->wiphy, "wl%d: %s: Driver going down so return" | |
5306 | "\n", wlc->pub->unit, __func__); | |
5307 | return 0; | |
5308 | } | |
5309 | if (!wlc->pub->up) | |
5310 | return callbacks; | |
5311 | ||
5b435de0 AS |
5312 | wlc->going_down = true; |
5313 | ||
5314 | callbacks += brcms_b_bmac_down_prep(wlc->hw); | |
5315 | ||
5316 | dev_gone = brcms_deviceremoved(wlc); | |
5317 | ||
5318 | /* Call any registered down handlers */ | |
5319 | for (i = 0; i < BRCMS_MAXMODULES; i++) { | |
5320 | if (wlc->modulecb[i].down_fn) | |
5321 | callbacks += | |
5322 | wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl); | |
5323 | } | |
5324 | ||
5325 | /* cancel the watchdog timer */ | |
5326 | if (wlc->WDarmed) { | |
be69c4ef | 5327 | if (!brcms_del_timer(wlc->wdtimer)) |
5b435de0 AS |
5328 | callbacks++; |
5329 | wlc->WDarmed = false; | |
5330 | } | |
5331 | /* cancel all other timers */ | |
5332 | callbacks += brcms_c_down_del_timer(wlc); | |
5333 | ||
5334 | wlc->pub->up = false; | |
5335 | ||
5336 | wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL); | |
5337 | ||
5338 | /* clear txq flow control */ | |
5339 | brcms_c_txflowcontrol_reset(wlc); | |
5340 | ||
5341 | /* flush tx queues */ | |
5342 | for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) | |
5343 | brcmu_pktq_flush(&qi->q, true, NULL, NULL); | |
5344 | ||
5345 | callbacks += brcms_b_down_finish(wlc->hw); | |
5346 | ||
5347 | /* brcms_b_down_finish has done brcms_c_coredisable(). so clk is off */ | |
5348 | wlc->clk = false; | |
5349 | ||
5350 | wlc->going_down = false; | |
5351 | return callbacks; | |
5352 | } | |
5353 | ||
5354 | /* Set the current gmode configuration */ | |
5355 | int brcms_c_set_gmode(struct brcms_c_info *wlc, u8 gmode, bool config) | |
5356 | { | |
5357 | int ret = 0; | |
5358 | uint i; | |
5359 | struct brcms_c_rateset rs; | |
5360 | /* Default to 54g Auto */ | |
5361 | /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */ | |
5362 | s8 shortslot = BRCMS_SHORTSLOT_AUTO; | |
5363 | bool shortslot_restrict = false; /* Restrict association to stations | |
5364 | * that support shortslot | |
5365 | */ | |
5366 | bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */ | |
5367 | /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */ | |
5368 | int preamble = BRCMS_PLCP_LONG; | |
5369 | bool preamble_restrict = false; /* Restrict association to stations | |
5370 | * that support short preambles | |
5371 | */ | |
5372 | struct brcms_band *band; | |
5373 | ||
5374 | /* if N-support is enabled, allow Gmode set as long as requested | |
5375 | * Gmode is not GMODE_LEGACY_B | |
5376 | */ | |
5377 | if ((wlc->pub->_n_enab & SUPPORT_11N) && gmode == GMODE_LEGACY_B) | |
5378 | return -ENOTSUPP; | |
5379 | ||
5380 | /* verify that we are dealing with 2G band and grab the band pointer */ | |
5381 | if (wlc->band->bandtype == BRCM_BAND_2G) | |
5382 | band = wlc->band; | |
5383 | else if ((wlc->pub->_nbands > 1) && | |
5384 | (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == BRCM_BAND_2G)) | |
5385 | band = wlc->bandstate[OTHERBANDUNIT(wlc)]; | |
5386 | else | |
5387 | return -EINVAL; | |
5388 | ||
5389 | /* Legacy or bust when no OFDM is supported by regulatory */ | |
5390 | if ((brcms_c_channel_locale_flags_in_band(wlc->cmi, band->bandunit) & | |
5391 | BRCMS_NO_OFDM) && (gmode != GMODE_LEGACY_B)) | |
5392 | return -EINVAL; | |
5393 | ||
5394 | /* update configuration value */ | |
23677ce3 | 5395 | if (config) |
5b435de0 AS |
5396 | brcms_c_protection_upd(wlc, BRCMS_PROT_G_USER, gmode); |
5397 | ||
5398 | /* Clear rateset override */ | |
5399 | memset(&rs, 0, sizeof(struct brcms_c_rateset)); | |
5400 | ||
5401 | switch (gmode) { | |
5402 | case GMODE_LEGACY_B: | |
5403 | shortslot = BRCMS_SHORTSLOT_OFF; | |
5404 | brcms_c_rateset_copy(&gphy_legacy_rates, &rs); | |
5405 | ||
5406 | break; | |
5407 | ||
5408 | case GMODE_LRS: | |
5409 | break; | |
5410 | ||
5411 | case GMODE_AUTO: | |
5412 | /* Accept defaults */ | |
5413 | break; | |
5414 | ||
5415 | case GMODE_ONLY: | |
5416 | ofdm_basic = true; | |
5417 | preamble = BRCMS_PLCP_SHORT; | |
5418 | preamble_restrict = true; | |
5419 | break; | |
5420 | ||
5421 | case GMODE_PERFORMANCE: | |
5422 | shortslot = BRCMS_SHORTSLOT_ON; | |
5423 | shortslot_restrict = true; | |
5424 | ofdm_basic = true; | |
5425 | preamble = BRCMS_PLCP_SHORT; | |
5426 | preamble_restrict = true; | |
5427 | break; | |
5428 | ||
5429 | default: | |
5430 | /* Error */ | |
5431 | wiphy_err(wlc->wiphy, "wl%d: %s: invalid gmode %d\n", | |
5432 | wlc->pub->unit, __func__, gmode); | |
5433 | return -ENOTSUPP; | |
5434 | } | |
5435 | ||
5436 | band->gmode = gmode; | |
5437 | ||
5438 | wlc->shortslot_override = shortslot; | |
5439 | ||
5440 | /* Use the default 11g rateset */ | |
5441 | if (!rs.count) | |
5442 | brcms_c_rateset_copy(&cck_ofdm_rates, &rs); | |
5443 | ||
5444 | if (ofdm_basic) { | |
5445 | for (i = 0; i < rs.count; i++) { | |
5446 | if (rs.rates[i] == BRCM_RATE_6M | |
5447 | || rs.rates[i] == BRCM_RATE_12M | |
5448 | || rs.rates[i] == BRCM_RATE_24M) | |
5449 | rs.rates[i] |= BRCMS_RATE_FLAG; | |
5450 | } | |
5451 | } | |
5452 | ||
5453 | /* Set default bss rateset */ | |
5454 | wlc->default_bss->rateset.count = rs.count; | |
5455 | memcpy(wlc->default_bss->rateset.rates, rs.rates, | |
5456 | sizeof(wlc->default_bss->rateset.rates)); | |
5457 | ||
5458 | return ret; | |
5459 | } | |
5460 | ||
5461 | int brcms_c_set_nmode(struct brcms_c_info *wlc) | |
5462 | { | |
5463 | uint i; | |
5464 | s32 nmode = AUTO; | |
5465 | ||
5466 | if (wlc->stf->txstreams == WL_11N_3x3) | |
5467 | nmode = WL_11N_3x3; | |
5468 | else | |
5469 | nmode = WL_11N_2x2; | |
5470 | ||
5471 | /* force GMODE_AUTO if NMODE is ON */ | |
5472 | brcms_c_set_gmode(wlc, GMODE_AUTO, true); | |
5473 | if (nmode == WL_11N_3x3) | |
5474 | wlc->pub->_n_enab = SUPPORT_HT; | |
5475 | else | |
5476 | wlc->pub->_n_enab = SUPPORT_11N; | |
5477 | wlc->default_bss->flags |= BRCMS_BSS_HT; | |
5478 | /* add the mcs rates to the default and hw ratesets */ | |
5479 | brcms_c_rateset_mcs_build(&wlc->default_bss->rateset, | |
5480 | wlc->stf->txstreams); | |
5481 | for (i = 0; i < wlc->pub->_nbands; i++) | |
5482 | memcpy(wlc->bandstate[i]->hw_rateset.mcs, | |
5483 | wlc->default_bss->rateset.mcs, MCSSET_LEN); | |
5484 | ||
5485 | return 0; | |
5486 | } | |
5487 | ||
5488 | static int | |
5489 | brcms_c_set_internal_rateset(struct brcms_c_info *wlc, | |
5490 | struct brcms_c_rateset *rs_arg) | |
5491 | { | |
5492 | struct brcms_c_rateset rs, new; | |
5493 | uint bandunit; | |
5494 | ||
5495 | memcpy(&rs, rs_arg, sizeof(struct brcms_c_rateset)); | |
5496 | ||
5497 | /* check for bad count value */ | |
5498 | if ((rs.count == 0) || (rs.count > BRCMS_NUMRATES)) | |
5499 | return -EINVAL; | |
5500 | ||
5501 | /* try the current band */ | |
5502 | bandunit = wlc->band->bandunit; | |
5503 | memcpy(&new, &rs, sizeof(struct brcms_c_rateset)); | |
5504 | if (brcms_c_rate_hwrs_filter_sort_validate | |
5505 | (&new, &wlc->bandstate[bandunit]->hw_rateset, true, | |
5506 | wlc->stf->txstreams)) | |
5507 | goto good; | |
5508 | ||
5509 | /* try the other band */ | |
5510 | if (brcms_is_mband_unlocked(wlc)) { | |
5511 | bandunit = OTHERBANDUNIT(wlc); | |
5512 | memcpy(&new, &rs, sizeof(struct brcms_c_rateset)); | |
5513 | if (brcms_c_rate_hwrs_filter_sort_validate(&new, | |
5514 | &wlc-> | |
5515 | bandstate[bandunit]-> | |
5516 | hw_rateset, true, | |
5517 | wlc->stf->txstreams)) | |
5518 | goto good; | |
5519 | } | |
5520 | ||
5521 | return -EBADE; | |
5522 | ||
5523 | good: | |
5524 | /* apply new rateset */ | |
5525 | memcpy(&wlc->default_bss->rateset, &new, | |
5526 | sizeof(struct brcms_c_rateset)); | |
5527 | memcpy(&wlc->bandstate[bandunit]->defrateset, &new, | |
5528 | sizeof(struct brcms_c_rateset)); | |
5529 | return 0; | |
5530 | } | |
5531 | ||
5532 | static void brcms_c_ofdm_rateset_war(struct brcms_c_info *wlc) | |
5533 | { | |
5534 | u8 r; | |
5535 | bool war = false; | |
5536 | ||
5537 | if (wlc->bsscfg->associated) | |
5538 | r = wlc->bsscfg->current_bss->rateset.rates[0]; | |
5539 | else | |
5540 | r = wlc->default_bss->rateset.rates[0]; | |
5541 | ||
5542 | wlc_phy_ofdm_rateset_war(wlc->band->pi, war); | |
5543 | } | |
5544 | ||
5545 | int brcms_c_set_channel(struct brcms_c_info *wlc, u16 channel) | |
5546 | { | |
5547 | u16 chspec = ch20mhz_chspec(channel); | |
5548 | ||
5549 | if (channel < 0 || channel > MAXCHANNEL) | |
5550 | return -EINVAL; | |
5551 | ||
5552 | if (!brcms_c_valid_chanspec_db(wlc->cmi, chspec)) | |
5553 | return -EINVAL; | |
5554 | ||
5555 | ||
5556 | if (!wlc->pub->up && brcms_is_mband_unlocked(wlc)) { | |
5557 | if (wlc->band->bandunit != chspec_bandunit(chspec)) | |
5558 | wlc->bandinit_pending = true; | |
5559 | else | |
5560 | wlc->bandinit_pending = false; | |
5561 | } | |
5562 | ||
5563 | wlc->default_bss->chanspec = chspec; | |
5564 | /* brcms_c_BSSinit() will sanitize the rateset before | |
5565 | * using it.. */ | |
5566 | if (wlc->pub->up && (wlc_phy_chanspec_get(wlc->band->pi) != chspec)) { | |
5567 | brcms_c_set_home_chanspec(wlc, chspec); | |
5568 | brcms_c_suspend_mac_and_wait(wlc); | |
5569 | brcms_c_set_chanspec(wlc, chspec); | |
5570 | brcms_c_enable_mac(wlc); | |
5571 | } | |
5572 | return 0; | |
5573 | } | |
5574 | ||
5575 | int brcms_c_set_rate_limit(struct brcms_c_info *wlc, u16 srl, u16 lrl) | |
5576 | { | |
5577 | int ac; | |
5578 | ||
5579 | if (srl < 1 || srl > RETRY_SHORT_MAX || | |
5580 | lrl < 1 || lrl > RETRY_SHORT_MAX) | |
5581 | return -EINVAL; | |
5582 | ||
5583 | wlc->SRL = srl; | |
5584 | wlc->LRL = lrl; | |
5585 | ||
5586 | brcms_b_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL); | |
5587 | ||
b7eec423 | 5588 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
5b435de0 AS |
5589 | wlc->wme_retries[ac] = SFIELD(wlc->wme_retries[ac], |
5590 | EDCF_SHORT, wlc->SRL); | |
5591 | wlc->wme_retries[ac] = SFIELD(wlc->wme_retries[ac], | |
5592 | EDCF_LONG, wlc->LRL); | |
5593 | } | |
5594 | brcms_c_wme_retries_write(wlc); | |
5595 | ||
5596 | return 0; | |
5597 | } | |
5598 | ||
5599 | void brcms_c_get_current_rateset(struct brcms_c_info *wlc, | |
5600 | struct brcm_rateset *currs) | |
5601 | { | |
5602 | struct brcms_c_rateset *rs; | |
5603 | ||
5604 | if (wlc->pub->associated) | |
5605 | rs = &wlc->bsscfg->current_bss->rateset; | |
5606 | else | |
5607 | rs = &wlc->default_bss->rateset; | |
5608 | ||
5609 | /* Copy only legacy rateset section */ | |
5610 | currs->count = rs->count; | |
5611 | memcpy(&currs->rates, &rs->rates, rs->count); | |
5612 | } | |
5613 | ||
5614 | int brcms_c_set_rateset(struct brcms_c_info *wlc, struct brcm_rateset *rs) | |
5615 | { | |
5616 | struct brcms_c_rateset internal_rs; | |
5617 | int bcmerror; | |
5618 | ||
5619 | if (rs->count > BRCMS_NUMRATES) | |
5620 | return -ENOBUFS; | |
5621 | ||
5622 | memset(&internal_rs, 0, sizeof(struct brcms_c_rateset)); | |
5623 | ||
5624 | /* Copy only legacy rateset section */ | |
5625 | internal_rs.count = rs->count; | |
5626 | memcpy(&internal_rs.rates, &rs->rates, internal_rs.count); | |
5627 | ||
5628 | /* merge rateset coming in with the current mcsset */ | |
5629 | if (wlc->pub->_n_enab & SUPPORT_11N) { | |
5630 | struct brcms_bss_info *mcsset_bss; | |
5631 | if (wlc->bsscfg->associated) | |
5632 | mcsset_bss = wlc->bsscfg->current_bss; | |
5633 | else | |
5634 | mcsset_bss = wlc->default_bss; | |
5635 | memcpy(internal_rs.mcs, &mcsset_bss->rateset.mcs[0], | |
5636 | MCSSET_LEN); | |
5637 | } | |
5638 | ||
5639 | bcmerror = brcms_c_set_internal_rateset(wlc, &internal_rs); | |
5640 | if (!bcmerror) | |
5641 | brcms_c_ofdm_rateset_war(wlc); | |
5642 | ||
5643 | return bcmerror; | |
5644 | } | |
5645 | ||
5646 | int brcms_c_set_beacon_period(struct brcms_c_info *wlc, u16 period) | |
5647 | { | |
5648 | if (period < DOT11_MIN_BEACON_PERIOD || | |
5649 | period > DOT11_MAX_BEACON_PERIOD) | |
5650 | return -EINVAL; | |
5651 | ||
5652 | wlc->default_bss->beacon_period = period; | |
5653 | return 0; | |
5654 | } | |
5655 | ||
5656 | u16 brcms_c_get_phy_type(struct brcms_c_info *wlc, int phyidx) | |
5657 | { | |
5658 | return wlc->band->phytype; | |
5659 | } | |
5660 | ||
5661 | void brcms_c_set_shortslot_override(struct brcms_c_info *wlc, s8 sslot_override) | |
5662 | { | |
5663 | wlc->shortslot_override = sslot_override; | |
5664 | ||
5665 | /* | |
5666 | * shortslot is an 11g feature, so no more work if we are | |
5667 | * currently on the 5G band | |
5668 | */ | |
5669 | if (wlc->band->bandtype == BRCM_BAND_5G) | |
5670 | return; | |
5671 | ||
5672 | if (wlc->pub->up && wlc->pub->associated) { | |
5673 | /* let watchdog or beacon processing update shortslot */ | |
5674 | } else if (wlc->pub->up) { | |
5675 | /* unassociated shortslot is off */ | |
5676 | brcms_c_switch_shortslot(wlc, false); | |
5677 | } else { | |
5678 | /* driver is down, so just update the brcms_c_info | |
5679 | * value */ | |
5680 | if (wlc->shortslot_override == BRCMS_SHORTSLOT_AUTO) | |
5681 | wlc->shortslot = false; | |
5682 | else | |
5683 | wlc->shortslot = | |
5684 | (wlc->shortslot_override == | |
5685 | BRCMS_SHORTSLOT_ON); | |
5686 | } | |
5687 | } | |
5688 | ||
5689 | /* | |
5690 | * register watchdog and down handlers. | |
5691 | */ | |
5692 | int brcms_c_module_register(struct brcms_pub *pub, | |
5693 | const char *name, struct brcms_info *hdl, | |
5694 | int (*d_fn)(void *handle)) | |
5695 | { | |
5696 | struct brcms_c_info *wlc = (struct brcms_c_info *) pub->wlc; | |
5697 | int i; | |
5698 | ||
5699 | /* find an empty entry and just add, no duplication check! */ | |
5700 | for (i = 0; i < BRCMS_MAXMODULES; i++) { | |
5701 | if (wlc->modulecb[i].name[0] == '\0') { | |
5702 | strncpy(wlc->modulecb[i].name, name, | |
5703 | sizeof(wlc->modulecb[i].name) - 1); | |
5704 | wlc->modulecb[i].hdl = hdl; | |
5705 | wlc->modulecb[i].down_fn = d_fn; | |
5706 | return 0; | |
5707 | } | |
5708 | } | |
5709 | ||
5710 | return -ENOSR; | |
5711 | } | |
5712 | ||
5713 | /* unregister module callbacks */ | |
5714 | int brcms_c_module_unregister(struct brcms_pub *pub, const char *name, | |
5715 | struct brcms_info *hdl) | |
5716 | { | |
5717 | struct brcms_c_info *wlc = (struct brcms_c_info *) pub->wlc; | |
5718 | int i; | |
5719 | ||
5720 | if (wlc == NULL) | |
5721 | return -ENODATA; | |
5722 | ||
5723 | for (i = 0; i < BRCMS_MAXMODULES; i++) { | |
5724 | if (!strcmp(wlc->modulecb[i].name, name) && | |
5725 | (wlc->modulecb[i].hdl == hdl)) { | |
5726 | memset(&wlc->modulecb[i], 0, sizeof(struct modulecb)); | |
5727 | return 0; | |
5728 | } | |
5729 | } | |
5730 | ||
5731 | /* table not found! */ | |
5732 | return -ENODATA; | |
5733 | } | |
5734 | ||
5b435de0 AS |
5735 | void brcms_c_print_txstatus(struct tx_status *txs) |
5736 | { | |
18aad4f8 JP |
5737 | pr_debug("\ntxpkt (MPDU) Complete\n"); |
5738 | ||
5739 | pr_debug("FrameID: %04x TxStatus: %04x\n", txs->frameid, txs->status); | |
5740 | ||
5741 | pr_debug("[15:12] %d frame attempts\n", | |
5742 | (txs->status & TX_STATUS_FRM_RTX_MASK) >> | |
5743 | TX_STATUS_FRM_RTX_SHIFT); | |
5744 | pr_debug(" [11:8] %d rts attempts\n", | |
5745 | (txs->status & TX_STATUS_RTS_RTX_MASK) >> | |
5746 | TX_STATUS_RTS_RTX_SHIFT); | |
5747 | pr_debug(" [7] %d PM mode indicated\n", | |
5748 | txs->status & TX_STATUS_PMINDCTD ? 1 : 0); | |
5749 | pr_debug(" [6] %d intermediate status\n", | |
5750 | txs->status & TX_STATUS_INTERMEDIATE ? 1 : 0); | |
5751 | pr_debug(" [5] %d AMPDU\n", | |
5752 | txs->status & TX_STATUS_AMPDU ? 1 : 0); | |
5753 | pr_debug(" [4:2] %d Frame Suppressed Reason (%s)\n", | |
5754 | (txs->status & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT, | |
5755 | (const char *[]) { | |
5756 | "None", | |
5757 | "PMQ Entry", | |
5758 | "Flush request", | |
5759 | "Previous frag failure", | |
5760 | "Channel mismatch", | |
5761 | "Lifetime Expiry", | |
5762 | "Underflow" | |
5763 | } [(txs->status & TX_STATUS_SUPR_MASK) >> | |
5764 | TX_STATUS_SUPR_SHIFT]); | |
5765 | pr_debug(" [1] %d acked\n", | |
5766 | txs->status & TX_STATUS_ACK_RCV ? 1 : 0); | |
5767 | ||
5768 | pr_debug("LastTxTime: %04x Seq: %04x PHYTxStatus: %04x RxAckRSSI: %04x RxAckSQ: %04x\n", | |
5769 | txs->lasttxtime, txs->sequence, txs->phyerr, | |
5770 | (txs->ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT, | |
5771 | (txs->ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT); | |
5b435de0 AS |
5772 | } |
5773 | ||
94bdc2a2 | 5774 | bool brcms_c_chipmatch(u16 vendor, u16 device) |
5b435de0 AS |
5775 | { |
5776 | if (vendor != PCI_VENDOR_ID_BROADCOM) { | |
02f77195 | 5777 | pr_err("unknown vendor id %04x\n", vendor); |
5b435de0 AS |
5778 | return false; |
5779 | } | |
5780 | ||
5781 | if (device == BCM43224_D11N_ID_VEN1) | |
5782 | return true; | |
5783 | if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID)) | |
5784 | return true; | |
5785 | if (device == BCM4313_D11N2G_ID) | |
5786 | return true; | |
5787 | if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID)) | |
5788 | return true; | |
5789 | ||
02f77195 | 5790 | pr_err("unknown device id %04x\n", device); |
5b435de0 AS |
5791 | return false; |
5792 | } | |
5793 | ||
8ae74654 | 5794 | #if defined(DEBUG) |
5b435de0 AS |
5795 | void brcms_c_print_txdesc(struct d11txh *txh) |
5796 | { | |
5797 | u16 mtcl = le16_to_cpu(txh->MacTxControlLow); | |
5798 | u16 mtch = le16_to_cpu(txh->MacTxControlHigh); | |
5799 | u16 mfc = le16_to_cpu(txh->MacFrameControl); | |
5800 | u16 tfest = le16_to_cpu(txh->TxFesTimeNormal); | |
5801 | u16 ptcw = le16_to_cpu(txh->PhyTxControlWord); | |
5802 | u16 ptcw_1 = le16_to_cpu(txh->PhyTxControlWord_1); | |
5803 | u16 ptcw_1_Fbr = le16_to_cpu(txh->PhyTxControlWord_1_Fbr); | |
5804 | u16 ptcw_1_Rts = le16_to_cpu(txh->PhyTxControlWord_1_Rts); | |
5805 | u16 ptcw_1_FbrRts = le16_to_cpu(txh->PhyTxControlWord_1_FbrRts); | |
5806 | u16 mainrates = le16_to_cpu(txh->MainRates); | |
5807 | u16 xtraft = le16_to_cpu(txh->XtraFrameTypes); | |
5808 | u8 *iv = txh->IV; | |
5809 | u8 *ra = txh->TxFrameRA; | |
5810 | u16 tfestfb = le16_to_cpu(txh->TxFesTimeFallback); | |
5811 | u8 *rtspfb = txh->RTSPLCPFallback; | |
5812 | u16 rtsdfb = le16_to_cpu(txh->RTSDurFallback); | |
5813 | u8 *fragpfb = txh->FragPLCPFallback; | |
5814 | u16 fragdfb = le16_to_cpu(txh->FragDurFallback); | |
5815 | u16 mmodelen = le16_to_cpu(txh->MModeLen); | |
5816 | u16 mmodefbrlen = le16_to_cpu(txh->MModeFbrLen); | |
5817 | u16 tfid = le16_to_cpu(txh->TxFrameID); | |
5818 | u16 txs = le16_to_cpu(txh->TxStatus); | |
5819 | u16 mnmpdu = le16_to_cpu(txh->MaxNMpdus); | |
5820 | u16 mabyte = le16_to_cpu(txh->MaxABytes_MRT); | |
5821 | u16 mabyte_f = le16_to_cpu(txh->MaxABytes_FBR); | |
5822 | u16 mmbyte = le16_to_cpu(txh->MinMBytes); | |
5823 | ||
5824 | u8 *rtsph = txh->RTSPhyHeader; | |
5825 | struct ieee80211_rts rts = txh->rts_frame; | |
5b435de0 AS |
5826 | |
5827 | /* add plcp header along with txh descriptor */ | |
c2e6d5ab JP |
5828 | brcmu_dbg_hex_dump(txh, sizeof(struct d11txh) + 48, |
5829 | "Raw TxDesc + plcp header:\n"); | |
5b435de0 | 5830 | |
18aad4f8 JP |
5831 | pr_debug("TxCtlLow: %04x ", mtcl); |
5832 | pr_debug("TxCtlHigh: %04x ", mtch); | |
5833 | pr_debug("FC: %04x ", mfc); | |
5834 | pr_debug("FES Time: %04x\n", tfest); | |
5835 | pr_debug("PhyCtl: %04x%s ", ptcw, | |
5b435de0 | 5836 | (ptcw & PHY_TXC_SHORT_HDR) ? " short" : ""); |
18aad4f8 JP |
5837 | pr_debug("PhyCtl_1: %04x ", ptcw_1); |
5838 | pr_debug("PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr); | |
5839 | pr_debug("PhyCtl_1_Rts: %04x ", ptcw_1_Rts); | |
5840 | pr_debug("PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts); | |
5841 | pr_debug("MainRates: %04x ", mainrates); | |
5842 | pr_debug("XtraFrameTypes: %04x ", xtraft); | |
5843 | pr_debug("\n"); | |
5b435de0 | 5844 | |
09c7dfa0 AS |
5845 | print_hex_dump_bytes("SecIV:", DUMP_PREFIX_OFFSET, iv, sizeof(txh->IV)); |
5846 | print_hex_dump_bytes("RA:", DUMP_PREFIX_OFFSET, | |
5847 | ra, sizeof(txh->TxFrameRA)); | |
5b435de0 | 5848 | |
18aad4f8 | 5849 | pr_debug("Fb FES Time: %04x ", tfestfb); |
09c7dfa0 AS |
5850 | print_hex_dump_bytes("Fb RTS PLCP:", DUMP_PREFIX_OFFSET, |
5851 | rtspfb, sizeof(txh->RTSPLCPFallback)); | |
18aad4f8 | 5852 | pr_debug("RTS DUR: %04x ", rtsdfb); |
09c7dfa0 AS |
5853 | print_hex_dump_bytes("PLCP:", DUMP_PREFIX_OFFSET, |
5854 | fragpfb, sizeof(txh->FragPLCPFallback)); | |
18aad4f8 JP |
5855 | pr_debug("DUR: %04x", fragdfb); |
5856 | pr_debug("\n"); | |
5b435de0 | 5857 | |
18aad4f8 JP |
5858 | pr_debug("MModeLen: %04x ", mmodelen); |
5859 | pr_debug("MModeFbrLen: %04x\n", mmodefbrlen); | |
5b435de0 | 5860 | |
18aad4f8 JP |
5861 | pr_debug("FrameID: %04x\n", tfid); |
5862 | pr_debug("TxStatus: %04x\n", txs); | |
5b435de0 | 5863 | |
18aad4f8 JP |
5864 | pr_debug("MaxNumMpdu: %04x\n", mnmpdu); |
5865 | pr_debug("MaxAggbyte: %04x\n", mabyte); | |
5866 | pr_debug("MaxAggbyte_fb: %04x\n", mabyte_f); | |
5867 | pr_debug("MinByte: %04x\n", mmbyte); | |
5b435de0 | 5868 | |
09c7dfa0 AS |
5869 | print_hex_dump_bytes("RTS PLCP:", DUMP_PREFIX_OFFSET, |
5870 | rtsph, sizeof(txh->RTSPhyHeader)); | |
5871 | print_hex_dump_bytes("RTS Frame:", DUMP_PREFIX_OFFSET, | |
5872 | (u8 *)&rts, sizeof(txh->rts_frame)); | |
18aad4f8 | 5873 | pr_debug("\n"); |
5b435de0 | 5874 | } |
8ae74654 | 5875 | #endif /* defined(DEBUG) */ |
5b435de0 | 5876 | |
8ae74654 | 5877 | #if defined(DEBUG) |
094b199b | 5878 | static int |
44760651 | 5879 | brcms_c_format_flags(const struct brcms_c_bit_desc *bd, u32 flags, char *buf, |
094b199b | 5880 | int len) |
44760651 AB |
5881 | { |
5882 | int i; | |
5883 | char *p = buf; | |
5884 | char hexstr[16]; | |
5885 | int slen = 0, nlen = 0; | |
5886 | u32 bit; | |
5887 | const char *name; | |
5888 | ||
5889 | if (len < 2 || !buf) | |
5890 | return 0; | |
5891 | ||
5892 | buf[0] = '\0'; | |
5893 | ||
5894 | for (i = 0; flags != 0; i++) { | |
5895 | bit = bd[i].bit; | |
5896 | name = bd[i].name; | |
5897 | if (bit == 0 && flags != 0) { | |
5898 | /* print any unnamed bits */ | |
5899 | snprintf(hexstr, 16, "0x%X", flags); | |
5900 | name = hexstr; | |
5901 | flags = 0; /* exit loop */ | |
5902 | } else if ((flags & bit) == 0) | |
5903 | continue; | |
5904 | flags &= ~bit; | |
5905 | nlen = strlen(name); | |
5906 | slen += nlen; | |
5907 | /* count btwn flag space */ | |
5908 | if (flags != 0) | |
5909 | slen += 1; | |
5910 | /* need NULL char as well */ | |
5911 | if (len <= slen) | |
5912 | break; | |
5913 | /* copy NULL char but don't count it */ | |
5914 | strncpy(p, name, nlen + 1); | |
5915 | p += nlen; | |
5916 | /* copy btwn flag space and NULL char */ | |
5917 | if (flags != 0) | |
5918 | p += snprintf(p, 2, " "); | |
5919 | len -= slen; | |
5920 | } | |
5921 | ||
5922 | /* indicate the str was too short */ | |
5923 | if (flags != 0) { | |
5924 | if (len < 2) | |
5925 | p -= 2 - len; /* overwrite last char */ | |
5926 | p += snprintf(p, 2, ">"); | |
5927 | } | |
5928 | ||
5929 | return (int)(p - buf); | |
5930 | } | |
8ae74654 | 5931 | #endif /* defined(DEBUG) */ |
44760651 | 5932 | |
8ae74654 | 5933 | #if defined(DEBUG) |
5b435de0 AS |
5934 | void brcms_c_print_rxh(struct d11rxhdr *rxh) |
5935 | { | |
5936 | u16 len = rxh->RxFrameSize; | |
5937 | u16 phystatus_0 = rxh->PhyRxStatus_0; | |
5938 | u16 phystatus_1 = rxh->PhyRxStatus_1; | |
5939 | u16 phystatus_2 = rxh->PhyRxStatus_2; | |
5940 | u16 phystatus_3 = rxh->PhyRxStatus_3; | |
5941 | u16 macstatus1 = rxh->RxStatus1; | |
5942 | u16 macstatus2 = rxh->RxStatus2; | |
5943 | char flagstr[64]; | |
5944 | char lenbuf[20]; | |
44760651 | 5945 | static const struct brcms_c_bit_desc macstat_flags[] = { |
5b435de0 AS |
5946 | {RXS_FCSERR, "FCSErr"}, |
5947 | {RXS_RESPFRAMETX, "Reply"}, | |
5948 | {RXS_PBPRES, "PADDING"}, | |
5949 | {RXS_DECATMPT, "DeCr"}, | |
5950 | {RXS_DECERR, "DeCrErr"}, | |
5951 | {RXS_BCNSENT, "Bcn"}, | |
5952 | {0, NULL} | |
5953 | }; | |
5954 | ||
c2e6d5ab | 5955 | brcmu_dbg_hex_dump(rxh, sizeof(struct d11rxhdr), "Raw RxDesc:\n"); |
5b435de0 | 5956 | |
44760651 | 5957 | brcms_c_format_flags(macstat_flags, macstatus1, flagstr, 64); |
5b435de0 AS |
5958 | |
5959 | snprintf(lenbuf, sizeof(lenbuf), "0x%x", len); | |
5960 | ||
18aad4f8 | 5961 | pr_debug("RxFrameSize: %6s (%d)%s\n", lenbuf, len, |
5b435de0 | 5962 | (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : ""); |
18aad4f8 | 5963 | pr_debug("RxPHYStatus: %04x %04x %04x %04x\n", |
5b435de0 | 5964 | phystatus_0, phystatus_1, phystatus_2, phystatus_3); |
18aad4f8 JP |
5965 | pr_debug("RxMACStatus: %x %s\n", macstatus1, flagstr); |
5966 | pr_debug("RXMACaggtype: %x\n", | |
5b435de0 | 5967 | (macstatus2 & RXS_AGGTYPE_MASK)); |
18aad4f8 | 5968 | pr_debug("RxTSFTime: %04x\n", rxh->RxTSFTime); |
5b435de0 | 5969 | } |
8ae74654 | 5970 | #endif /* defined(DEBUG) */ |
5b435de0 AS |
5971 | |
5972 | u16 brcms_b_rate_shm_offset(struct brcms_hardware *wlc_hw, u8 rate) | |
5973 | { | |
5974 | u16 table_ptr; | |
5975 | u8 phy_rate, index; | |
5976 | ||
5977 | /* get the phy specific rate encoding for the PLCP SIGNAL field */ | |
5978 | if (is_ofdm_rate(rate)) | |
5979 | table_ptr = M_RT_DIRMAP_A; | |
5980 | else | |
5981 | table_ptr = M_RT_DIRMAP_B; | |
5982 | ||
5983 | /* for a given rate, the LS-nibble of the PLCP SIGNAL field is | |
5984 | * the index into the rate table. | |
5985 | */ | |
5986 | phy_rate = rate_info[rate] & BRCMS_RATE_MASK; | |
5987 | index = phy_rate & 0xf; | |
5988 | ||
5989 | /* Find the SHM pointer to the rate table entry by looking in the | |
5990 | * Direct-map Table | |
5991 | */ | |
5992 | return 2 * brcms_b_read_shm(wlc_hw, table_ptr + (index * 2)); | |
5993 | } | |
5994 | ||
94bdc2a2 | 5995 | static bool |
5b435de0 AS |
5996 | brcms_c_prec_enq_head(struct brcms_c_info *wlc, struct pktq *q, |
5997 | struct sk_buff *pkt, int prec, bool head) | |
5998 | { | |
5999 | struct sk_buff *p; | |
6000 | int eprec = -1; /* precedence to evict from */ | |
6001 | ||
6002 | /* Determine precedence from which to evict packet, if any */ | |
6003 | if (pktq_pfull(q, prec)) | |
6004 | eprec = prec; | |
6005 | else if (pktq_full(q)) { | |
6006 | p = brcmu_pktq_peek_tail(q, &eprec); | |
6007 | if (eprec > prec) { | |
6008 | wiphy_err(wlc->wiphy, "%s: Failing: eprec %d > prec %d" | |
6009 | "\n", __func__, eprec, prec); | |
6010 | return false; | |
6011 | } | |
6012 | } | |
6013 | ||
6014 | /* Evict if needed */ | |
6015 | if (eprec >= 0) { | |
6016 | bool discard_oldest; | |
6017 | ||
6018 | discard_oldest = ac_bitmap_tst(0, eprec); | |
6019 | ||
6020 | /* Refuse newer packet unless configured to discard oldest */ | |
6021 | if (eprec == prec && !discard_oldest) { | |
6022 | wiphy_err(wlc->wiphy, "%s: No where to go, prec == %d" | |
6023 | "\n", __func__, prec); | |
6024 | return false; | |
6025 | } | |
6026 | ||
6027 | /* Evict packet according to discard policy */ | |
6028 | p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) : | |
6029 | brcmu_pktq_pdeq_tail(q, eprec); | |
6030 | brcmu_pkt_buf_free_skb(p); | |
6031 | } | |
6032 | ||
6033 | /* Enqueue */ | |
6034 | if (head) | |
6035 | p = brcmu_pktq_penq_head(q, prec, pkt); | |
6036 | else | |
6037 | p = brcmu_pktq_penq(q, prec, pkt); | |
6038 | ||
6039 | return true; | |
6040 | } | |
6041 | ||
94bdc2a2 AB |
6042 | /* |
6043 | * Attempts to queue a packet onto a multiple-precedence queue, | |
6044 | * if necessary evicting a lower precedence packet from the queue. | |
6045 | * | |
6046 | * 'prec' is the precedence number that has already been mapped | |
6047 | * from the packet priority. | |
6048 | * | |
6049 | * Returns true if packet consumed (queued), false if not. | |
6050 | */ | |
6051 | static bool brcms_c_prec_enq(struct brcms_c_info *wlc, struct pktq *q, | |
6052 | struct sk_buff *pkt, int prec) | |
6053 | { | |
6054 | return brcms_c_prec_enq_head(wlc, q, pkt, prec, false); | |
6055 | } | |
6056 | ||
5b435de0 AS |
6057 | void brcms_c_txq_enq(struct brcms_c_info *wlc, struct scb *scb, |
6058 | struct sk_buff *sdu, uint prec) | |
6059 | { | |
6060 | struct brcms_txq_info *qi = wlc->pkt_queue; /* Check me */ | |
6061 | struct pktq *q = &qi->q; | |
6062 | int prio; | |
6063 | ||
6064 | prio = sdu->priority; | |
6065 | ||
6066 | if (!brcms_c_prec_enq(wlc, q, sdu, prec)) { | |
6067 | /* | |
6068 | * we might hit this condtion in case | |
6069 | * packet flooding from mac80211 stack | |
6070 | */ | |
6071 | brcmu_pkt_buf_free_skb(sdu); | |
6072 | } | |
6073 | } | |
6074 | ||
6075 | /* | |
6076 | * bcmc_fid_generate: | |
6077 | * Generate frame ID for a BCMC packet. The frag field is not used | |
6078 | * for MC frames so is used as part of the sequence number. | |
6079 | */ | |
6080 | static inline u16 | |
6081 | bcmc_fid_generate(struct brcms_c_info *wlc, struct brcms_bss_cfg *bsscfg, | |
6082 | struct d11txh *txh) | |
6083 | { | |
6084 | u16 frameid; | |
6085 | ||
6086 | frameid = le16_to_cpu(txh->TxFrameID) & ~(TXFID_SEQ_MASK | | |
6087 | TXFID_QUEUE_MASK); | |
6088 | frameid |= | |
6089 | (((wlc-> | |
6090 | mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) | | |
6091 | TX_BCMC_FIFO; | |
6092 | ||
6093 | return frameid; | |
6094 | } | |
6095 | ||
6096 | static uint | |
6097 | brcms_c_calc_ack_time(struct brcms_c_info *wlc, u32 rspec, | |
6098 | u8 preamble_type) | |
6099 | { | |
6100 | uint dur = 0; | |
6101 | ||
6102 | BCMMSG(wlc->wiphy, "wl%d: rspec 0x%x, preamble_type %d\n", | |
6103 | wlc->pub->unit, rspec, preamble_type); | |
6104 | /* | |
6105 | * Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that | |
6106 | * is less than or equal to the rate of the immediately previous | |
6107 | * frame in the FES | |
6108 | */ | |
6109 | rspec = brcms_basic_rate(wlc, rspec); | |
6110 | /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */ | |
6111 | dur = | |
6112 | brcms_c_calc_frame_time(wlc, rspec, preamble_type, | |
6113 | (DOT11_ACK_LEN + FCS_LEN)); | |
6114 | return dur; | |
6115 | } | |
6116 | ||
6117 | static uint | |
6118 | brcms_c_calc_cts_time(struct brcms_c_info *wlc, u32 rspec, | |
6119 | u8 preamble_type) | |
6120 | { | |
6121 | BCMMSG(wlc->wiphy, "wl%d: ratespec 0x%x, preamble_type %d\n", | |
6122 | wlc->pub->unit, rspec, preamble_type); | |
6123 | return brcms_c_calc_ack_time(wlc, rspec, preamble_type); | |
6124 | } | |
6125 | ||
6126 | static uint | |
6127 | brcms_c_calc_ba_time(struct brcms_c_info *wlc, u32 rspec, | |
6128 | u8 preamble_type) | |
6129 | { | |
6130 | BCMMSG(wlc->wiphy, "wl%d: rspec 0x%x, " | |
6131 | "preamble_type %d\n", wlc->pub->unit, rspec, preamble_type); | |
6132 | /* | |
6133 | * Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that | |
6134 | * is less than or equal to the rate of the immediately previous | |
6135 | * frame in the FES | |
6136 | */ | |
6137 | rspec = brcms_basic_rate(wlc, rspec); | |
6138 | /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */ | |
6139 | return brcms_c_calc_frame_time(wlc, rspec, preamble_type, | |
6140 | (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN + | |
6141 | FCS_LEN)); | |
6142 | } | |
6143 | ||
6144 | /* brcms_c_compute_frame_dur() | |
6145 | * | |
6146 | * Calculate the 802.11 MAC header DUR field for MPDU | |
6147 | * DUR for a single frame = 1 SIFS + 1 ACK | |
6148 | * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time | |
6149 | * | |
6150 | * rate MPDU rate in unit of 500kbps | |
6151 | * next_frag_len next MPDU length in bytes | |
6152 | * preamble_type use short/GF or long/MM PLCP header | |
6153 | */ | |
6154 | static u16 | |
6155 | brcms_c_compute_frame_dur(struct brcms_c_info *wlc, u32 rate, | |
6156 | u8 preamble_type, uint next_frag_len) | |
6157 | { | |
6158 | u16 dur, sifs; | |
6159 | ||
6160 | sifs = get_sifs(wlc->band); | |
6161 | ||
6162 | dur = sifs; | |
6163 | dur += (u16) brcms_c_calc_ack_time(wlc, rate, preamble_type); | |
6164 | ||
6165 | if (next_frag_len) { | |
6166 | /* Double the current DUR to get 2 SIFS + 2 ACKs */ | |
6167 | dur *= 2; | |
6168 | /* add another SIFS and the frag time */ | |
6169 | dur += sifs; | |
6170 | dur += | |
6171 | (u16) brcms_c_calc_frame_time(wlc, rate, preamble_type, | |
6172 | next_frag_len); | |
6173 | } | |
6174 | return dur; | |
6175 | } | |
6176 | ||
6177 | /* The opposite of brcms_c_calc_frame_time */ | |
6178 | static uint | |
6179 | brcms_c_calc_frame_len(struct brcms_c_info *wlc, u32 ratespec, | |
6180 | u8 preamble_type, uint dur) | |
6181 | { | |
6182 | uint nsyms, mac_len, Ndps, kNdps; | |
6183 | uint rate = rspec2rate(ratespec); | |
6184 | ||
6185 | BCMMSG(wlc->wiphy, "wl%d: rspec 0x%x, preamble_type %d, dur %d\n", | |
6186 | wlc->pub->unit, ratespec, preamble_type, dur); | |
6187 | ||
6188 | if (is_mcs_rate(ratespec)) { | |
6189 | uint mcs = ratespec & RSPEC_RATE_MASK; | |
6190 | int tot_streams = mcs_2_txstreams(mcs) + rspec_stc(ratespec); | |
6191 | dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT); | |
6192 | /* payload calculation matches that of regular ofdm */ | |
6193 | if (wlc->band->bandtype == BRCM_BAND_2G) | |
6194 | dur -= DOT11_OFDM_SIGNAL_EXTENSION; | |
6195 | /* kNdbps = kbps * 4 */ | |
6196 | kNdps = mcs_2_rate(mcs, rspec_is40mhz(ratespec), | |
6197 | rspec_issgi(ratespec)) * 4; | |
6198 | nsyms = dur / APHY_SYMBOL_TIME; | |
6199 | mac_len = | |
6200 | ((nsyms * kNdps) - | |
6201 | ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000; | |
6202 | } else if (is_ofdm_rate(ratespec)) { | |
6203 | dur -= APHY_PREAMBLE_TIME; | |
6204 | dur -= APHY_SIGNAL_TIME; | |
6205 | /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */ | |
6206 | Ndps = rate * 2; | |
6207 | nsyms = dur / APHY_SYMBOL_TIME; | |
6208 | mac_len = | |
6209 | ((nsyms * Ndps) - | |
6210 | (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8; | |
6211 | } else { | |
6212 | if (preamble_type & BRCMS_SHORT_PREAMBLE) | |
6213 | dur -= BPHY_PLCP_SHORT_TIME; | |
6214 | else | |
6215 | dur -= BPHY_PLCP_TIME; | |
6216 | mac_len = dur * rate; | |
6217 | /* divide out factor of 2 in rate (1/2 mbps) */ | |
6218 | mac_len = mac_len / 8 / 2; | |
6219 | } | |
6220 | return mac_len; | |
6221 | } | |
6222 | ||
94bdc2a2 AB |
6223 | /* |
6224 | * Return true if the specified rate is supported by the specified band. | |
6225 | * BRCM_BAND_AUTO indicates the current band. | |
6226 | */ | |
6227 | static bool brcms_c_valid_rate(struct brcms_c_info *wlc, u32 rspec, int band, | |
6228 | bool verbose) | |
6229 | { | |
6230 | struct brcms_c_rateset *hw_rateset; | |
6231 | uint i; | |
6232 | ||
6233 | if ((band == BRCM_BAND_AUTO) || (band == wlc->band->bandtype)) | |
6234 | hw_rateset = &wlc->band->hw_rateset; | |
6235 | else if (wlc->pub->_nbands > 1) | |
6236 | hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset; | |
6237 | else | |
6238 | /* other band specified and we are a single band device */ | |
6239 | return false; | |
6240 | ||
6241 | /* check if this is a mimo rate */ | |
6242 | if (is_mcs_rate(rspec)) { | |
6243 | if ((rspec & RSPEC_RATE_MASK) >= MCS_TABLE_SIZE) | |
6244 | goto error; | |
6245 | ||
6246 | return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK)); | |
6247 | } | |
6248 | ||
6249 | for (i = 0; i < hw_rateset->count; i++) | |
6250 | if (hw_rateset->rates[i] == rspec2rate(rspec)) | |
6251 | return true; | |
6252 | error: | |
6253 | if (verbose) | |
6254 | wiphy_err(wlc->wiphy, "wl%d: valid_rate: rate spec 0x%x " | |
6255 | "not in hw_rateset\n", wlc->pub->unit, rspec); | |
6256 | ||
6257 | return false; | |
6258 | } | |
6259 | ||
5b435de0 AS |
6260 | static u32 |
6261 | mac80211_wlc_set_nrate(struct brcms_c_info *wlc, struct brcms_band *cur_band, | |
6262 | u32 int_val) | |
6263 | { | |
6264 | u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT; | |
6265 | u8 rate = int_val & NRATE_RATE_MASK; | |
6266 | u32 rspec; | |
6267 | bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE); | |
6268 | bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT); | |
6269 | bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY) | |
6270 | == NRATE_OVERRIDE_MCS_ONLY); | |
6271 | int bcmerror = 0; | |
6272 | ||
6273 | if (!ismcs) | |
6274 | return (u32) rate; | |
6275 | ||
6276 | /* validate the combination of rate/mcs/stf is allowed */ | |
6277 | if ((wlc->pub->_n_enab & SUPPORT_11N) && ismcs) { | |
6278 | /* mcs only allowed when nmode */ | |
6279 | if (stf > PHY_TXC1_MODE_SDM) { | |
6280 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid stf\n", | |
6281 | wlc->pub->unit, __func__); | |
6282 | bcmerror = -EINVAL; | |
6283 | goto done; | |
6284 | } | |
6285 | ||
6286 | /* mcs 32 is a special case, DUP mode 40 only */ | |
6287 | if (rate == 32) { | |
6288 | if (!CHSPEC_IS40(wlc->home_chanspec) || | |
6289 | ((stf != PHY_TXC1_MODE_SISO) | |
6290 | && (stf != PHY_TXC1_MODE_CDD))) { | |
6291 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid mcs " | |
6292 | "32\n", wlc->pub->unit, __func__); | |
6293 | bcmerror = -EINVAL; | |
6294 | goto done; | |
6295 | } | |
6296 | /* mcs > 7 must use stf SDM */ | |
6297 | } else if (rate > HIGHEST_SINGLE_STREAM_MCS) { | |
6298 | /* mcs > 7 must use stf SDM */ | |
6299 | if (stf != PHY_TXC1_MODE_SDM) { | |
6300 | BCMMSG(wlc->wiphy, "wl%d: enabling " | |
6301 | "SDM mode for mcs %d\n", | |
6302 | wlc->pub->unit, rate); | |
6303 | stf = PHY_TXC1_MODE_SDM; | |
6304 | } | |
6305 | } else { | |
6306 | /* | |
6307 | * MCS 0-7 may use SISO, CDD, and for | |
6308 | * phy_rev >= 3 STBC | |
6309 | */ | |
6310 | if ((stf > PHY_TXC1_MODE_STBC) || | |
6311 | (!BRCMS_STBC_CAP_PHY(wlc) | |
6312 | && (stf == PHY_TXC1_MODE_STBC))) { | |
6313 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid STBC" | |
6314 | "\n", wlc->pub->unit, __func__); | |
6315 | bcmerror = -EINVAL; | |
6316 | goto done; | |
6317 | } | |
6318 | } | |
6319 | } else if (is_ofdm_rate(rate)) { | |
6320 | if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) { | |
6321 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid OFDM\n", | |
6322 | wlc->pub->unit, __func__); | |
6323 | bcmerror = -EINVAL; | |
6324 | goto done; | |
6325 | } | |
6326 | } else if (is_cck_rate(rate)) { | |
6327 | if ((cur_band->bandtype != BRCM_BAND_2G) | |
6328 | || (stf != PHY_TXC1_MODE_SISO)) { | |
6329 | wiphy_err(wlc->wiphy, "wl%d: %s: Invalid CCK\n", | |
6330 | wlc->pub->unit, __func__); | |
6331 | bcmerror = -EINVAL; | |
6332 | goto done; | |
6333 | } | |
6334 | } else { | |
6335 | wiphy_err(wlc->wiphy, "wl%d: %s: Unknown rate type\n", | |
6336 | wlc->pub->unit, __func__); | |
6337 | bcmerror = -EINVAL; | |
6338 | goto done; | |
6339 | } | |
6340 | /* make sure multiple antennae are available for non-siso rates */ | |
6341 | if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) { | |
6342 | wiphy_err(wlc->wiphy, "wl%d: %s: SISO antenna but !SISO " | |
6343 | "request\n", wlc->pub->unit, __func__); | |
6344 | bcmerror = -EINVAL; | |
6345 | goto done; | |
6346 | } | |
6347 | ||
6348 | rspec = rate; | |
6349 | if (ismcs) { | |
6350 | rspec |= RSPEC_MIMORATE; | |
6351 | /* For STBC populate the STC field of the ratespec */ | |
6352 | if (stf == PHY_TXC1_MODE_STBC) { | |
6353 | u8 stc; | |
6354 | stc = 1; /* Nss for single stream is always 1 */ | |
6355 | rspec |= (stc << RSPEC_STC_SHIFT); | |
6356 | } | |
6357 | } | |
6358 | ||
6359 | rspec |= (stf << RSPEC_STF_SHIFT); | |
6360 | ||
6361 | if (override_mcs_only) | |
6362 | rspec |= RSPEC_OVERRIDE_MCS_ONLY; | |
6363 | ||
6364 | if (issgi) | |
6365 | rspec |= RSPEC_SHORT_GI; | |
6366 | ||
6367 | if ((rate != 0) | |
6368 | && !brcms_c_valid_rate(wlc, rspec, cur_band->bandtype, true)) | |
6369 | return rate; | |
6370 | ||
6371 | return rspec; | |
6372 | done: | |
6373 | return rate; | |
6374 | } | |
6375 | ||
6376 | /* | |
94bdc2a2 AB |
6377 | * Compute PLCP, but only requires actual rate and length of pkt. |
6378 | * Rate is given in the driver standard multiple of 500 kbps. | |
6379 | * le is set for 11 Mbps rate if necessary. | |
6380 | * Broken out for PRQ. | |
5b435de0 | 6381 | */ |
5b435de0 | 6382 | |
94bdc2a2 AB |
6383 | static void brcms_c_cck_plcp_set(struct brcms_c_info *wlc, int rate_500, |
6384 | uint length, u8 *plcp) | |
6385 | { | |
6386 | u16 usec = 0; | |
6387 | u8 le = 0; | |
5b435de0 | 6388 | |
94bdc2a2 AB |
6389 | switch (rate_500) { |
6390 | case BRCM_RATE_1M: | |
6391 | usec = length << 3; | |
6392 | break; | |
6393 | case BRCM_RATE_2M: | |
6394 | usec = length << 2; | |
6395 | break; | |
6396 | case BRCM_RATE_5M5: | |
6397 | usec = (length << 4) / 11; | |
6398 | if ((length << 4) - (usec * 11) > 0) | |
6399 | usec++; | |
6400 | break; | |
6401 | case BRCM_RATE_11M: | |
6402 | usec = (length << 3) / 11; | |
6403 | if ((length << 3) - (usec * 11) > 0) { | |
6404 | usec++; | |
6405 | if ((usec * 11) - (length << 3) >= 8) | |
6406 | le = D11B_PLCP_SIGNAL_LE; | |
6407 | } | |
6408 | break; | |
5b435de0 | 6409 | |
94bdc2a2 AB |
6410 | default: |
6411 | wiphy_err(wlc->wiphy, | |
6412 | "brcms_c_cck_plcp_set: unsupported rate %d\n", | |
6413 | rate_500); | |
6414 | rate_500 = BRCM_RATE_1M; | |
6415 | usec = length << 3; | |
6416 | break; | |
6417 | } | |
6418 | /* PLCP signal byte */ | |
6419 | plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */ | |
6420 | /* PLCP service byte */ | |
6421 | plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED); | |
6422 | /* PLCP length u16, little endian */ | |
6423 | plcp[2] = usec & 0xff; | |
6424 | plcp[3] = (usec >> 8) & 0xff; | |
6425 | /* PLCP CRC16 */ | |
6426 | plcp[4] = 0; | |
6427 | plcp[5] = 0; | |
6428 | } | |
5b435de0 | 6429 | |
94bdc2a2 AB |
6430 | /* Rate: 802.11 rate code, length: PSDU length in octets */ |
6431 | static void brcms_c_compute_mimo_plcp(u32 rspec, uint length, u8 *plcp) | |
6432 | { | |
6433 | u8 mcs = (u8) (rspec & RSPEC_RATE_MASK); | |
6434 | plcp[0] = mcs; | |
6435 | if (rspec_is40mhz(rspec) || (mcs == 32)) | |
6436 | plcp[0] |= MIMO_PLCP_40MHZ; | |
6437 | BRCMS_SET_MIMO_PLCP_LEN(plcp, length); | |
6438 | plcp[3] = rspec_mimoplcp3(rspec); /* rspec already holds this byte */ | |
6439 | plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */ | |
6440 | plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */ | |
6441 | plcp[5] = 0; | |
6442 | } | |
5b435de0 | 6443 | |
94bdc2a2 AB |
6444 | /* Rate: 802.11 rate code, length: PSDU length in octets */ |
6445 | static void | |
6446 | brcms_c_compute_ofdm_plcp(u32 rspec, u32 length, u8 *plcp) | |
6447 | { | |
6448 | u8 rate_signal; | |
6449 | u32 tmp = 0; | |
6450 | int rate = rspec2rate(rspec); | |
5b435de0 | 6451 | |
94bdc2a2 AB |
6452 | /* |
6453 | * encode rate per 802.11a-1999 sec 17.3.4.1, with lsb | |
6454 | * transmitted first | |
6455 | */ | |
6456 | rate_signal = rate_info[rate] & BRCMS_RATE_MASK; | |
6457 | memset(plcp, 0, D11_PHY_HDR_LEN); | |
6458 | D11A_PHY_HDR_SRATE((struct ofdm_phy_hdr *) plcp, rate_signal); | |
5b435de0 | 6459 | |
94bdc2a2 AB |
6460 | tmp = (length & 0xfff) << 5; |
6461 | plcp[2] |= (tmp >> 16) & 0xff; | |
6462 | plcp[1] |= (tmp >> 8) & 0xff; | |
6463 | plcp[0] |= tmp & 0xff; | |
6464 | } | |
6465 | ||
6466 | /* Rate: 802.11 rate code, length: PSDU length in octets */ | |
6467 | static void brcms_c_compute_cck_plcp(struct brcms_c_info *wlc, u32 rspec, | |
6468 | uint length, u8 *plcp) | |
6469 | { | |
6470 | int rate = rspec2rate(rspec); | |
6471 | ||
6472 | brcms_c_cck_plcp_set(wlc, rate, length, plcp); | |
6473 | } | |
6474 | ||
6475 | static void | |
6476 | brcms_c_compute_plcp(struct brcms_c_info *wlc, u32 rspec, | |
6477 | uint length, u8 *plcp) | |
6478 | { | |
6479 | if (is_mcs_rate(rspec)) | |
6480 | brcms_c_compute_mimo_plcp(rspec, length, plcp); | |
6481 | else if (is_ofdm_rate(rspec)) | |
6482 | brcms_c_compute_ofdm_plcp(rspec, length, plcp); | |
6483 | else | |
6484 | brcms_c_compute_cck_plcp(wlc, rspec, length, plcp); | |
6485 | } | |
6486 | ||
6487 | /* brcms_c_compute_rtscts_dur() | |
6488 | * | |
6489 | * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame | |
6490 | * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK | |
6491 | * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK | |
6492 | * | |
6493 | * cts cts-to-self or rts/cts | |
6494 | * rts_rate rts or cts rate in unit of 500kbps | |
6495 | * rate next MPDU rate in unit of 500kbps | |
6496 | * frame_len next MPDU frame length in bytes | |
6497 | */ | |
6498 | u16 | |
6499 | brcms_c_compute_rtscts_dur(struct brcms_c_info *wlc, bool cts_only, | |
6500 | u32 rts_rate, | |
6501 | u32 frame_rate, u8 rts_preamble_type, | |
6502 | u8 frame_preamble_type, uint frame_len, bool ba) | |
6503 | { | |
6504 | u16 dur, sifs; | |
6505 | ||
6506 | sifs = get_sifs(wlc->band); | |
6507 | ||
6508 | if (!cts_only) { | |
6509 | /* RTS/CTS */ | |
6510 | dur = 3 * sifs; | |
6511 | dur += | |
6512 | (u16) brcms_c_calc_cts_time(wlc, rts_rate, | |
6513 | rts_preamble_type); | |
6514 | } else { | |
6515 | /* CTS-TO-SELF */ | |
6516 | dur = 2 * sifs; | |
6517 | } | |
6518 | ||
6519 | dur += | |
6520 | (u16) brcms_c_calc_frame_time(wlc, frame_rate, frame_preamble_type, | |
6521 | frame_len); | |
6522 | if (ba) | |
6523 | dur += | |
6524 | (u16) brcms_c_calc_ba_time(wlc, frame_rate, | |
6525 | BRCMS_SHORT_PREAMBLE); | |
6526 | else | |
6527 | dur += | |
6528 | (u16) brcms_c_calc_ack_time(wlc, frame_rate, | |
6529 | frame_preamble_type); | |
6530 | return dur; | |
6531 | } | |
6532 | ||
6533 | static u16 brcms_c_phytxctl1_calc(struct brcms_c_info *wlc, u32 rspec) | |
6534 | { | |
6535 | u16 phyctl1 = 0; | |
6536 | u16 bw; | |
6537 | ||
6538 | if (BRCMS_ISLCNPHY(wlc->band)) { | |
6539 | bw = PHY_TXC1_BW_20MHZ; | |
6540 | } else { | |
6541 | bw = rspec_get_bw(rspec); | |
6542 | /* 10Mhz is not supported yet */ | |
6543 | if (bw < PHY_TXC1_BW_20MHZ) { | |
6544 | wiphy_err(wlc->wiphy, "phytxctl1_calc: bw %d is " | |
6545 | "not supported yet, set to 20L\n", bw); | |
6546 | bw = PHY_TXC1_BW_20MHZ; | |
6547 | } | |
6548 | } | |
6549 | ||
6550 | if (is_mcs_rate(rspec)) { | |
6551 | uint mcs = rspec & RSPEC_RATE_MASK; | |
6552 | ||
6553 | /* bw, stf, coding-type is part of rspec_phytxbyte2 returns */ | |
6554 | phyctl1 = rspec_phytxbyte2(rspec); | |
6555 | /* set the upper byte of phyctl1 */ | |
6556 | phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8); | |
6557 | } else if (is_cck_rate(rspec) && !BRCMS_ISLCNPHY(wlc->band) | |
6558 | && !BRCMS_ISSSLPNPHY(wlc->band)) { | |
6559 | /* | |
6560 | * In CCK mode LPPHY overloads OFDM Modulation bits with CCK | |
6561 | * Data Rate. Eventually MIMOPHY would also be converted to | |
6562 | * this format | |
6563 | */ | |
6564 | /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */ | |
6565 | phyctl1 = (bw | (rspec_stf(rspec) << PHY_TXC1_MODE_SHIFT)); | |
6566 | } else { /* legacy OFDM/CCK */ | |
6567 | s16 phycfg; | |
6568 | /* get the phyctl byte from rate phycfg table */ | |
6569 | phycfg = brcms_c_rate_legacy_phyctl(rspec2rate(rspec)); | |
6570 | if (phycfg == -1) { | |
6571 | wiphy_err(wlc->wiphy, "phytxctl1_calc: wrong " | |
6572 | "legacy OFDM/CCK rate\n"); | |
6573 | phycfg = 0; | |
6574 | } | |
6575 | /* set the upper byte of phyctl1 */ | |
6576 | phyctl1 = | |
6577 | (bw | (phycfg << 8) | | |
6578 | (rspec_stf(rspec) << PHY_TXC1_MODE_SHIFT)); | |
6579 | } | |
6580 | return phyctl1; | |
6581 | } | |
6582 | ||
6583 | /* | |
6584 | * Add struct d11txh, struct cck_phy_hdr. | |
6585 | * | |
6586 | * 'p' data must start with 802.11 MAC header | |
6587 | * 'p' must allow enough bytes of local headers to be "pushed" onto the packet | |
6588 | * | |
6589 | * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes) | |
6590 | * | |
6591 | */ | |
6592 | static u16 | |
6593 | brcms_c_d11hdrs_mac80211(struct brcms_c_info *wlc, struct ieee80211_hw *hw, | |
6594 | struct sk_buff *p, struct scb *scb, uint frag, | |
6595 | uint nfrags, uint queue, uint next_frag_len) | |
6596 | { | |
6597 | struct ieee80211_hdr *h; | |
6598 | struct d11txh *txh; | |
6599 | u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN]; | |
6600 | int len, phylen, rts_phylen; | |
6601 | u16 mch, phyctl, xfts, mainrates; | |
6602 | u16 seq = 0, mcl = 0, status = 0, frameid = 0; | |
6603 | u32 rspec[2] = { BRCM_RATE_1M, BRCM_RATE_1M }; | |
6604 | u32 rts_rspec[2] = { BRCM_RATE_1M, BRCM_RATE_1M }; | |
6605 | bool use_rts = false; | |
6606 | bool use_cts = false; | |
6607 | bool use_rifs = false; | |
6608 | bool short_preamble[2] = { false, false }; | |
6609 | u8 preamble_type[2] = { BRCMS_LONG_PREAMBLE, BRCMS_LONG_PREAMBLE }; | |
6610 | u8 rts_preamble_type[2] = { BRCMS_LONG_PREAMBLE, BRCMS_LONG_PREAMBLE }; | |
6611 | u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN]; | |
6612 | struct ieee80211_rts *rts = NULL; | |
6613 | bool qos; | |
6614 | uint ac; | |
6615 | bool hwtkmic = false; | |
6616 | u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ; | |
6617 | #define ANTCFG_NONE 0xFF | |
6618 | u8 antcfg = ANTCFG_NONE; | |
6619 | u8 fbantcfg = ANTCFG_NONE; | |
6620 | uint phyctl1_stf = 0; | |
6621 | u16 durid = 0; | |
6622 | struct ieee80211_tx_rate *txrate[2]; | |
6623 | int k; | |
6624 | struct ieee80211_tx_info *tx_info; | |
6625 | bool is_mcs; | |
6626 | u16 mimo_txbw; | |
6627 | u8 mimo_preamble_type; | |
6628 | ||
6629 | /* locate 802.11 MAC header */ | |
6630 | h = (struct ieee80211_hdr *)(p->data); | |
6631 | qos = ieee80211_is_data_qos(h->frame_control); | |
6632 | ||
6633 | /* compute length of frame in bytes for use in PLCP computations */ | |
ad4d71f6 | 6634 | len = p->len; |
94bdc2a2 AB |
6635 | phylen = len + FCS_LEN; |
6636 | ||
6637 | /* Get tx_info */ | |
6638 | tx_info = IEEE80211_SKB_CB(p); | |
6639 | ||
6640 | /* add PLCP */ | |
6641 | plcp = skb_push(p, D11_PHY_HDR_LEN); | |
6642 | ||
6643 | /* add Broadcom tx descriptor header */ | |
6644 | txh = (struct d11txh *) skb_push(p, D11_TXH_LEN); | |
6645 | memset(txh, 0, D11_TXH_LEN); | |
6646 | ||
6647 | /* setup frameid */ | |
6648 | if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { | |
6649 | /* non-AP STA should never use BCMC queue */ | |
6650 | if (queue == TX_BCMC_FIFO) { | |
6651 | wiphy_err(wlc->wiphy, "wl%d: %s: ASSERT queue == " | |
6652 | "TX_BCMC!\n", wlc->pub->unit, __func__); | |
6653 | frameid = bcmc_fid_generate(wlc, NULL, txh); | |
6654 | } else { | |
6655 | /* Increment the counter for first fragment */ | |
6656 | if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) | |
6657 | scb->seqnum[p->priority]++; | |
6658 | ||
6659 | /* extract fragment number from frame first */ | |
6660 | seq = le16_to_cpu(h->seq_ctrl) & FRAGNUM_MASK; | |
6661 | seq |= (scb->seqnum[p->priority] << SEQNUM_SHIFT); | |
5b435de0 AS |
6662 | h->seq_ctrl = cpu_to_le16(seq); |
6663 | ||
6664 | frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) | | |
6665 | (queue & TXFID_QUEUE_MASK); | |
6666 | } | |
6667 | } | |
6668 | frameid |= queue & TXFID_QUEUE_MASK; | |
6669 | ||
6670 | /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */ | |
6671 | if (ieee80211_is_beacon(h->frame_control)) | |
6672 | mcl |= TXC_IGNOREPMQ; | |
6673 | ||
6674 | txrate[0] = tx_info->control.rates; | |
6675 | txrate[1] = txrate[0] + 1; | |
6676 | ||
6677 | /* | |
6678 | * if rate control algorithm didn't give us a fallback | |
6679 | * rate, use the primary rate | |
6680 | */ | |
6681 | if (txrate[1]->idx < 0) | |
6682 | txrate[1] = txrate[0]; | |
6683 | ||
6684 | for (k = 0; k < hw->max_rates; k++) { | |
6685 | is_mcs = txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false; | |
6686 | if (!is_mcs) { | |
6687 | if ((txrate[k]->idx >= 0) | |
6688 | && (txrate[k]->idx < | |
6689 | hw->wiphy->bands[tx_info->band]->n_bitrates)) { | |
6690 | rspec[k] = | |
6691 | hw->wiphy->bands[tx_info->band]-> | |
6692 | bitrates[txrate[k]->idx].hw_value; | |
6693 | short_preamble[k] = | |
6694 | txrate[k]-> | |
6695 | flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ? | |
6696 | true : false; | |
6697 | } else { | |
6698 | rspec[k] = BRCM_RATE_1M; | |
6699 | } | |
6700 | } else { | |
6701 | rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, | |
6702 | NRATE_MCS_INUSE | txrate[k]->idx); | |
6703 | } | |
6704 | ||
6705 | /* | |
6706 | * Currently only support same setting for primay and | |
6707 | * fallback rates. Unify flags for each rate into a | |
6708 | * single value for the frame | |
6709 | */ | |
6710 | use_rts |= | |
6711 | txrate[k]-> | |
6712 | flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false; | |
6713 | use_cts |= | |
6714 | txrate[k]-> | |
6715 | flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false; | |
6716 | ||
6717 | ||
6718 | /* | |
6719 | * (1) RATE: | |
6720 | * determine and validate primary rate | |
6721 | * and fallback rates | |
6722 | */ | |
6723 | if (!rspec_active(rspec[k])) { | |
6724 | rspec[k] = BRCM_RATE_1M; | |
6725 | } else { | |
6726 | if (!is_multicast_ether_addr(h->addr1)) { | |
6727 | /* set tx antenna config */ | |
6728 | brcms_c_antsel_antcfg_get(wlc->asi, false, | |
6729 | false, 0, 0, &antcfg, &fbantcfg); | |
6730 | } | |
6731 | } | |
6732 | } | |
6733 | ||
6734 | phyctl1_stf = wlc->stf->ss_opmode; | |
6735 | ||
6736 | if (wlc->pub->_n_enab & SUPPORT_11N) { | |
6737 | for (k = 0; k < hw->max_rates; k++) { | |
6738 | /* | |
6739 | * apply siso/cdd to single stream mcs's or ofdm | |
6740 | * if rspec is auto selected | |
6741 | */ | |
6742 | if (((is_mcs_rate(rspec[k]) && | |
6743 | is_single_stream(rspec[k] & RSPEC_RATE_MASK)) || | |
6744 | is_ofdm_rate(rspec[k])) | |
6745 | && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY) | |
6746 | || !(rspec[k] & RSPEC_OVERRIDE))) { | |
6747 | rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK); | |
6748 | ||
6749 | /* For SISO MCS use STBC if possible */ | |
6750 | if (is_mcs_rate(rspec[k]) | |
6751 | && BRCMS_STF_SS_STBC_TX(wlc, scb)) { | |
6752 | u8 stc; | |
6753 | ||
6754 | /* Nss for single stream is always 1 */ | |
6755 | stc = 1; | |
6756 | rspec[k] |= (PHY_TXC1_MODE_STBC << | |
6757 | RSPEC_STF_SHIFT) | | |
6758 | (stc << RSPEC_STC_SHIFT); | |
6759 | } else | |
6760 | rspec[k] |= | |
6761 | (phyctl1_stf << RSPEC_STF_SHIFT); | |
6762 | } | |
6763 | ||
6764 | /* | |
6765 | * Is the phy configured to use 40MHZ frames? If | |
6766 | * so then pick the desired txbw | |
6767 | */ | |
6768 | if (brcms_chspec_bw(wlc->chanspec) == BRCMS_40_MHZ) { | |
6769 | /* default txbw is 20in40 SB */ | |
6770 | mimo_ctlchbw = mimo_txbw = | |
6771 | CHSPEC_SB_UPPER(wlc_phy_chanspec_get( | |
6772 | wlc->band->pi)) | |
6773 | ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ; | |
6774 | ||
6775 | if (is_mcs_rate(rspec[k])) { | |
6776 | /* mcs 32 must be 40b/w DUP */ | |
6777 | if ((rspec[k] & RSPEC_RATE_MASK) | |
6778 | == 32) { | |
6779 | mimo_txbw = | |
6780 | PHY_TXC1_BW_40MHZ_DUP; | |
6781 | /* use override */ | |
6782 | } else if (wlc->mimo_40txbw != AUTO) | |
6783 | mimo_txbw = wlc->mimo_40txbw; | |
6784 | /* else check if dst is using 40 Mhz */ | |
6785 | else if (scb->flags & SCB_IS40) | |
6786 | mimo_txbw = PHY_TXC1_BW_40MHZ; | |
6787 | } else if (is_ofdm_rate(rspec[k])) { | |
6788 | if (wlc->ofdm_40txbw != AUTO) | |
6789 | mimo_txbw = wlc->ofdm_40txbw; | |
6790 | } else if (wlc->cck_40txbw != AUTO) { | |
6791 | mimo_txbw = wlc->cck_40txbw; | |
6792 | } | |
6793 | } else { | |
6794 | /* | |
6795 | * mcs32 is 40 b/w only. | |
6796 | * This is possible for probe packets on | |
6797 | * a STA during SCAN | |
6798 | */ | |
6799 | if ((rspec[k] & RSPEC_RATE_MASK) == 32) | |
6800 | /* mcs 0 */ | |
6801 | rspec[k] = RSPEC_MIMORATE; | |
6802 | ||
6803 | mimo_txbw = PHY_TXC1_BW_20MHZ; | |
6804 | } | |
6805 | ||
6806 | /* Set channel width */ | |
6807 | rspec[k] &= ~RSPEC_BW_MASK; | |
6808 | if ((k == 0) || ((k > 0) && is_mcs_rate(rspec[k]))) | |
6809 | rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT); | |
6810 | else | |
6811 | rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT); | |
6812 | ||
6813 | /* Disable short GI, not supported yet */ | |
6814 | rspec[k] &= ~RSPEC_SHORT_GI; | |
6815 | ||
6816 | mimo_preamble_type = BRCMS_MM_PREAMBLE; | |
6817 | if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD) | |
6818 | mimo_preamble_type = BRCMS_GF_PREAMBLE; | |
6819 | ||
6820 | if ((txrate[k]->flags & IEEE80211_TX_RC_MCS) | |
6821 | && (!is_mcs_rate(rspec[k]))) { | |
6822 | wiphy_err(wlc->wiphy, "wl%d: %s: IEEE80211_TX_" | |
6823 | "RC_MCS != is_mcs_rate(rspec)\n", | |
6824 | wlc->pub->unit, __func__); | |
6825 | } | |
6826 | ||
6827 | if (is_mcs_rate(rspec[k])) { | |
6828 | preamble_type[k] = mimo_preamble_type; | |
6829 | ||
6830 | /* | |
6831 | * if SGI is selected, then forced mm | |
6832 | * for single stream | |
6833 | */ | |
6834 | if ((rspec[k] & RSPEC_SHORT_GI) | |
6835 | && is_single_stream(rspec[k] & | |
6836 | RSPEC_RATE_MASK)) | |
6837 | preamble_type[k] = BRCMS_MM_PREAMBLE; | |
6838 | } | |
6839 | ||
6840 | /* should be better conditionalized */ | |
6841 | if (!is_mcs_rate(rspec[0]) | |
6842 | && (tx_info->control.rates[0]. | |
6843 | flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)) | |
6844 | preamble_type[k] = BRCMS_SHORT_PREAMBLE; | |
6845 | } | |
6846 | } else { | |
6847 | for (k = 0; k < hw->max_rates; k++) { | |
6848 | /* Set ctrlchbw as 20Mhz */ | |
6849 | rspec[k] &= ~RSPEC_BW_MASK; | |
6850 | rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT); | |
6851 | ||
6852 | /* for nphy, stf of ofdm frames must follow policies */ | |
6853 | if (BRCMS_ISNPHY(wlc->band) && is_ofdm_rate(rspec[k])) { | |
6854 | rspec[k] &= ~RSPEC_STF_MASK; | |
6855 | rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT; | |
6856 | } | |
6857 | } | |
6858 | } | |
6859 | ||
6860 | /* Reset these for use with AMPDU's */ | |
6861 | txrate[0]->count = 0; | |
6862 | txrate[1]->count = 0; | |
6863 | ||
6864 | /* (2) PROTECTION, may change rspec */ | |
6865 | if ((ieee80211_is_data(h->frame_control) || | |
6866 | ieee80211_is_mgmt(h->frame_control)) && | |
6867 | (phylen > wlc->RTSThresh) && !is_multicast_ether_addr(h->addr1)) | |
6868 | use_rts = true; | |
6869 | ||
6870 | /* (3) PLCP: determine PLCP header and MAC duration, | |
6871 | * fill struct d11txh */ | |
6872 | brcms_c_compute_plcp(wlc, rspec[0], phylen, plcp); | |
6873 | brcms_c_compute_plcp(wlc, rspec[1], phylen, plcp_fallback); | |
6874 | memcpy(&txh->FragPLCPFallback, | |
6875 | plcp_fallback, sizeof(txh->FragPLCPFallback)); | |
6876 | ||
6877 | /* Length field now put in CCK FBR CRC field */ | |
6878 | if (is_cck_rate(rspec[1])) { | |
6879 | txh->FragPLCPFallback[4] = phylen & 0xff; | |
6880 | txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8; | |
6881 | } | |
6882 | ||
6883 | /* MIMO-RATE: need validation ?? */ | |
6884 | mainrates = is_ofdm_rate(rspec[0]) ? | |
6885 | D11A_PHY_HDR_GRATE((struct ofdm_phy_hdr *) plcp) : | |
6886 | plcp[0]; | |
6887 | ||
6888 | /* DUR field for main rate */ | |
6889 | if (!ieee80211_is_pspoll(h->frame_control) && | |
6890 | !is_multicast_ether_addr(h->addr1) && !use_rifs) { | |
6891 | durid = | |
6892 | brcms_c_compute_frame_dur(wlc, rspec[0], preamble_type[0], | |
6893 | next_frag_len); | |
6894 | h->duration_id = cpu_to_le16(durid); | |
6895 | } else if (use_rifs) { | |
6896 | /* NAV protect to end of next max packet size */ | |
6897 | durid = | |
6898 | (u16) brcms_c_calc_frame_time(wlc, rspec[0], | |
6899 | preamble_type[0], | |
6900 | DOT11_MAX_FRAG_LEN); | |
6901 | durid += RIFS_11N_TIME; | |
6902 | h->duration_id = cpu_to_le16(durid); | |
6903 | } | |
6904 | ||
6905 | /* DUR field for fallback rate */ | |
6906 | if (ieee80211_is_pspoll(h->frame_control)) | |
6907 | txh->FragDurFallback = h->duration_id; | |
6908 | else if (is_multicast_ether_addr(h->addr1) || use_rifs) | |
6909 | txh->FragDurFallback = 0; | |
6910 | else { | |
6911 | durid = brcms_c_compute_frame_dur(wlc, rspec[1], | |
6912 | preamble_type[1], next_frag_len); | |
6913 | txh->FragDurFallback = cpu_to_le16(durid); | |
6914 | } | |
6915 | ||
6916 | /* (4) MAC-HDR: MacTxControlLow */ | |
6917 | if (frag == 0) | |
6918 | mcl |= TXC_STARTMSDU; | |
6919 | ||
6920 | if (!is_multicast_ether_addr(h->addr1)) | |
6921 | mcl |= TXC_IMMEDACK; | |
6922 | ||
6923 | if (wlc->band->bandtype == BRCM_BAND_5G) | |
6924 | mcl |= TXC_FREQBAND_5G; | |
6925 | ||
6926 | if (CHSPEC_IS40(wlc_phy_chanspec_get(wlc->band->pi))) | |
6927 | mcl |= TXC_BW_40; | |
6928 | ||
6929 | /* set AMIC bit if using hardware TKIP MIC */ | |
6930 | if (hwtkmic) | |
6931 | mcl |= TXC_AMIC; | |
6932 | ||
6933 | txh->MacTxControlLow = cpu_to_le16(mcl); | |
6934 | ||
6935 | /* MacTxControlHigh */ | |
6936 | mch = 0; | |
6937 | ||
6938 | /* Set fallback rate preamble type */ | |
6939 | if ((preamble_type[1] == BRCMS_SHORT_PREAMBLE) || | |
6940 | (preamble_type[1] == BRCMS_GF_PREAMBLE)) { | |
6941 | if (rspec2rate(rspec[1]) != BRCM_RATE_1M) | |
6942 | mch |= TXC_PREAMBLE_DATA_FB_SHORT; | |
6943 | } | |
6944 | ||
6945 | /* MacFrameControl */ | |
6946 | memcpy(&txh->MacFrameControl, &h->frame_control, sizeof(u16)); | |
6947 | txh->TxFesTimeNormal = cpu_to_le16(0); | |
6948 | ||
6949 | txh->TxFesTimeFallback = cpu_to_le16(0); | |
6950 | ||
6951 | /* TxFrameRA */ | |
6952 | memcpy(&txh->TxFrameRA, &h->addr1, ETH_ALEN); | |
6953 | ||
6954 | /* TxFrameID */ | |
6955 | txh->TxFrameID = cpu_to_le16(frameid); | |
6956 | ||
6957 | /* | |
6958 | * TxStatus, Note the case of recreating the first frag of a suppressed | |
6959 | * frame then we may need to reset the retry cnt's via the status reg | |
6960 | */ | |
6961 | txh->TxStatus = cpu_to_le16(status); | |
6962 | ||
6963 | /* | |
6964 | * extra fields for ucode AMPDU aggregation, the new fields are added to | |
6965 | * the END of previous structure so that it's compatible in driver. | |
6966 | */ | |
6967 | txh->MaxNMpdus = cpu_to_le16(0); | |
6968 | txh->MaxABytes_MRT = cpu_to_le16(0); | |
6969 | txh->MaxABytes_FBR = cpu_to_le16(0); | |
6970 | txh->MinMBytes = cpu_to_le16(0); | |
6971 | ||
6972 | /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, | |
6973 | * furnish struct d11txh */ | |
6974 | /* RTS PLCP header and RTS frame */ | |
6975 | if (use_rts || use_cts) { | |
6976 | if (use_rts && use_cts) | |
6977 | use_cts = false; | |
6978 | ||
6979 | for (k = 0; k < 2; k++) { | |
6980 | rts_rspec[k] = brcms_c_rspec_to_rts_rspec(wlc, rspec[k], | |
6981 | false, | |
6982 | mimo_ctlchbw); | |
6983 | } | |
6984 | ||
6985 | if (!is_ofdm_rate(rts_rspec[0]) && | |
6986 | !((rspec2rate(rts_rspec[0]) == BRCM_RATE_1M) || | |
6987 | (wlc->PLCPHdr_override == BRCMS_PLCP_LONG))) { | |
6988 | rts_preamble_type[0] = BRCMS_SHORT_PREAMBLE; | |
6989 | mch |= TXC_PREAMBLE_RTS_MAIN_SHORT; | |
6990 | } | |
6991 | ||
6992 | if (!is_ofdm_rate(rts_rspec[1]) && | |
6993 | !((rspec2rate(rts_rspec[1]) == BRCM_RATE_1M) || | |
6994 | (wlc->PLCPHdr_override == BRCMS_PLCP_LONG))) { | |
6995 | rts_preamble_type[1] = BRCMS_SHORT_PREAMBLE; | |
6996 | mch |= TXC_PREAMBLE_RTS_FB_SHORT; | |
6997 | } | |
6998 | ||
6999 | /* RTS/CTS additions to MacTxControlLow */ | |
7000 | if (use_cts) { | |
7001 | txh->MacTxControlLow |= cpu_to_le16(TXC_SENDCTS); | |
7002 | } else { | |
7003 | txh->MacTxControlLow |= cpu_to_le16(TXC_SENDRTS); | |
7004 | txh->MacTxControlLow |= cpu_to_le16(TXC_LONGFRAME); | |
7005 | } | |
7006 | ||
7007 | /* RTS PLCP header */ | |
7008 | rts_plcp = txh->RTSPhyHeader; | |
7009 | if (use_cts) | |
7010 | rts_phylen = DOT11_CTS_LEN + FCS_LEN; | |
7011 | else | |
7012 | rts_phylen = DOT11_RTS_LEN + FCS_LEN; | |
7013 | ||
7014 | brcms_c_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp); | |
7015 | ||
7016 | /* fallback rate version of RTS PLCP header */ | |
7017 | brcms_c_compute_plcp(wlc, rts_rspec[1], rts_phylen, | |
7018 | rts_plcp_fallback); | |
7019 | memcpy(&txh->RTSPLCPFallback, rts_plcp_fallback, | |
7020 | sizeof(txh->RTSPLCPFallback)); | |
7021 | ||
7022 | /* RTS frame fields... */ | |
7023 | rts = (struct ieee80211_rts *)&txh->rts_frame; | |
7024 | ||
7025 | durid = brcms_c_compute_rtscts_dur(wlc, use_cts, rts_rspec[0], | |
7026 | rspec[0], rts_preamble_type[0], | |
7027 | preamble_type[0], phylen, false); | |
7028 | rts->duration = cpu_to_le16(durid); | |
7029 | /* fallback rate version of RTS DUR field */ | |
7030 | durid = brcms_c_compute_rtscts_dur(wlc, use_cts, | |
7031 | rts_rspec[1], rspec[1], | |
7032 | rts_preamble_type[1], | |
7033 | preamble_type[1], phylen, false); | |
7034 | txh->RTSDurFallback = cpu_to_le16(durid); | |
7035 | ||
7036 | if (use_cts) { | |
7037 | rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | | |
7038 | IEEE80211_STYPE_CTS); | |
7039 | ||
7040 | memcpy(&rts->ra, &h->addr2, ETH_ALEN); | |
7041 | } else { | |
7042 | rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | | |
7043 | IEEE80211_STYPE_RTS); | |
7044 | ||
7045 | memcpy(&rts->ra, &h->addr1, 2 * ETH_ALEN); | |
7046 | } | |
7047 | ||
7048 | /* mainrate | |
7049 | * low 8 bits: main frag rate/mcs, | |
7050 | * high 8 bits: rts/cts rate/mcs | |
7051 | */ | |
7052 | mainrates |= (is_ofdm_rate(rts_rspec[0]) ? | |
7053 | D11A_PHY_HDR_GRATE( | |
7054 | (struct ofdm_phy_hdr *) rts_plcp) : | |
7055 | rts_plcp[0]) << 8; | |
7056 | } else { | |
7057 | memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN); | |
7058 | memset((char *)&txh->rts_frame, 0, | |
7059 | sizeof(struct ieee80211_rts)); | |
7060 | memset((char *)txh->RTSPLCPFallback, 0, | |
7061 | sizeof(txh->RTSPLCPFallback)); | |
7062 | txh->RTSDurFallback = 0; | |
7063 | } | |
7064 | ||
7065 | #ifdef SUPPORT_40MHZ | |
7066 | /* add null delimiter count */ | |
7067 | if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && is_mcs_rate(rspec)) | |
7068 | txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] = | |
7069 | brcm_c_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen); | |
7070 | ||
7071 | #endif | |
7072 | ||
7073 | /* | |
7074 | * Now that RTS/RTS FB preamble types are updated, write | |
7075 | * the final value | |
7076 | */ | |
7077 | txh->MacTxControlHigh = cpu_to_le16(mch); | |
7078 | ||
7079 | /* | |
7080 | * MainRates (both the rts and frag plcp rates have | |
7081 | * been calculated now) | |
7082 | */ | |
7083 | txh->MainRates = cpu_to_le16(mainrates); | |
7084 | ||
7085 | /* XtraFrameTypes */ | |
7086 | xfts = frametype(rspec[1], wlc->mimoft); | |
7087 | xfts |= (frametype(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT); | |
7088 | xfts |= (frametype(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT); | |
7089 | xfts |= CHSPEC_CHANNEL(wlc_phy_chanspec_get(wlc->band->pi)) << | |
7090 | XFTS_CHANNEL_SHIFT; | |
7091 | txh->XtraFrameTypes = cpu_to_le16(xfts); | |
7092 | ||
7093 | /* PhyTxControlWord */ | |
7094 | phyctl = frametype(rspec[0], wlc->mimoft); | |
7095 | if ((preamble_type[0] == BRCMS_SHORT_PREAMBLE) || | |
7096 | (preamble_type[0] == BRCMS_GF_PREAMBLE)) { | |
7097 | if (rspec2rate(rspec[0]) != BRCM_RATE_1M) | |
7098 | phyctl |= PHY_TXC_SHORT_HDR; | |
7099 | } | |
7100 | ||
7101 | /* phytxant is properly bit shifted */ | |
7102 | phyctl |= brcms_c_stf_d11hdrs_phyctl_txant(wlc, rspec[0]); | |
7103 | txh->PhyTxControlWord = cpu_to_le16(phyctl); | |
7104 | ||
7105 | /* PhyTxControlWord_1 */ | |
7106 | if (BRCMS_PHY_11N_CAP(wlc->band)) { | |
7107 | u16 phyctl1 = 0; | |
7108 | ||
7109 | phyctl1 = brcms_c_phytxctl1_calc(wlc, rspec[0]); | |
7110 | txh->PhyTxControlWord_1 = cpu_to_le16(phyctl1); | |
7111 | phyctl1 = brcms_c_phytxctl1_calc(wlc, rspec[1]); | |
7112 | txh->PhyTxControlWord_1_Fbr = cpu_to_le16(phyctl1); | |
7113 | ||
7114 | if (use_rts || use_cts) { | |
7115 | phyctl1 = brcms_c_phytxctl1_calc(wlc, rts_rspec[0]); | |
7116 | txh->PhyTxControlWord_1_Rts = cpu_to_le16(phyctl1); | |
7117 | phyctl1 = brcms_c_phytxctl1_calc(wlc, rts_rspec[1]); | |
7118 | txh->PhyTxControlWord_1_FbrRts = cpu_to_le16(phyctl1); | |
7119 | } | |
7120 | ||
7121 | /* | |
7122 | * For mcs frames, if mixedmode(overloaded with long preamble) | |
7123 | * is going to be set, fill in non-zero MModeLen and/or | |
7124 | * MModeFbrLen it will be unnecessary if they are separated | |
7125 | */ | |
7126 | if (is_mcs_rate(rspec[0]) && | |
7127 | (preamble_type[0] == BRCMS_MM_PREAMBLE)) { | |
7128 | u16 mmodelen = | |
7129 | brcms_c_calc_lsig_len(wlc, rspec[0], phylen); | |
7130 | txh->MModeLen = cpu_to_le16(mmodelen); | |
7131 | } | |
7132 | ||
7133 | if (is_mcs_rate(rspec[1]) && | |
7134 | (preamble_type[1] == BRCMS_MM_PREAMBLE)) { | |
7135 | u16 mmodefbrlen = | |
7136 | brcms_c_calc_lsig_len(wlc, rspec[1], phylen); | |
7137 | txh->MModeFbrLen = cpu_to_le16(mmodefbrlen); | |
7138 | } | |
7139 | } | |
7140 | ||
7141 | ac = skb_get_queue_mapping(p); | |
7142 | if ((scb->flags & SCB_WMECAP) && qos && wlc->edcf_txop[ac]) { | |
7143 | uint frag_dur, dur, dur_fallback; | |
7144 | ||
7145 | /* WME: Update TXOP threshold */ | |
7146 | if (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU) && frag == 0) { | |
7147 | frag_dur = | |
7148 | brcms_c_calc_frame_time(wlc, rspec[0], | |
7149 | preamble_type[0], phylen); | |
7150 | ||
7151 | if (rts) { | |
7152 | /* 1 RTS or CTS-to-self frame */ | |
7153 | dur = | |
7154 | brcms_c_calc_cts_time(wlc, rts_rspec[0], | |
7155 | rts_preamble_type[0]); | |
7156 | dur_fallback = | |
7157 | brcms_c_calc_cts_time(wlc, rts_rspec[1], | |
7158 | rts_preamble_type[1]); | |
7159 | /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */ | |
7160 | dur += le16_to_cpu(rts->duration); | |
7161 | dur_fallback += | |
7162 | le16_to_cpu(txh->RTSDurFallback); | |
7163 | } else if (use_rifs) { | |
7164 | dur = frag_dur; | |
7165 | dur_fallback = 0; | |
7166 | } else { | |
7167 | /* frame + SIFS + ACK */ | |
7168 | dur = frag_dur; | |
7169 | dur += | |
7170 | brcms_c_compute_frame_dur(wlc, rspec[0], | |
7171 | preamble_type[0], 0); | |
7172 | ||
7173 | dur_fallback = | |
7174 | brcms_c_calc_frame_time(wlc, rspec[1], | |
7175 | preamble_type[1], | |
7176 | phylen); | |
7177 | dur_fallback += | |
7178 | brcms_c_compute_frame_dur(wlc, rspec[1], | |
7179 | preamble_type[1], 0); | |
7180 | } | |
7181 | /* NEED to set TxFesTimeNormal (hard) */ | |
7182 | txh->TxFesTimeNormal = cpu_to_le16((u16) dur); | |
7183 | /* | |
7184 | * NEED to set fallback rate version of | |
7185 | * TxFesTimeNormal (hard) | |
7186 | */ | |
7187 | txh->TxFesTimeFallback = | |
7188 | cpu_to_le16((u16) dur_fallback); | |
7189 | ||
7190 | /* | |
7191 | * update txop byte threshold (txop minus intraframe | |
7192 | * overhead) | |
7193 | */ | |
7194 | if (wlc->edcf_txop[ac] >= (dur - frag_dur)) { | |
7195 | uint newfragthresh; | |
7196 | ||
7197 | newfragthresh = | |
7198 | brcms_c_calc_frame_len(wlc, | |
7199 | rspec[0], preamble_type[0], | |
7200 | (wlc->edcf_txop[ac] - | |
7201 | (dur - frag_dur))); | |
7202 | /* range bound the fragthreshold */ | |
7203 | if (newfragthresh < DOT11_MIN_FRAG_LEN) | |
7204 | newfragthresh = | |
7205 | DOT11_MIN_FRAG_LEN; | |
7206 | else if (newfragthresh > | |
7207 | wlc->usr_fragthresh) | |
7208 | newfragthresh = | |
7209 | wlc->usr_fragthresh; | |
7210 | /* update the fragthresh and do txc update */ | |
7211 | if (wlc->fragthresh[queue] != | |
7212 | (u16) newfragthresh) | |
7213 | wlc->fragthresh[queue] = | |
7214 | (u16) newfragthresh; | |
7215 | } else { | |
7216 | wiphy_err(wlc->wiphy, "wl%d: %s txop invalid " | |
7217 | "for rate %d\n", | |
7218 | wlc->pub->unit, fifo_names[queue], | |
7219 | rspec2rate(rspec[0])); | |
7220 | } | |
7221 | ||
7222 | if (dur > wlc->edcf_txop[ac]) | |
7223 | wiphy_err(wlc->wiphy, "wl%d: %s: %s txop " | |
7224 | "exceeded phylen %d/%d dur %d/%d\n", | |
7225 | wlc->pub->unit, __func__, | |
7226 | fifo_names[queue], | |
7227 | phylen, wlc->fragthresh[queue], | |
7228 | dur, wlc->edcf_txop[ac]); | |
7229 | } | |
7230 | } | |
7231 | ||
7232 | return 0; | |
7233 | } | |
7234 | ||
7235 | void brcms_c_sendpkt_mac80211(struct brcms_c_info *wlc, struct sk_buff *sdu, | |
7236 | struct ieee80211_hw *hw) | |
7237 | { | |
7238 | u8 prio; | |
7239 | uint fifo; | |
7240 | struct scb *scb = &wlc->pri_scb; | |
7241 | struct ieee80211_hdr *d11_header = (struct ieee80211_hdr *)(sdu->data); | |
7242 | ||
7243 | /* | |
7244 | * 802.11 standard requires management traffic | |
7245 | * to go at highest priority | |
7246 | */ | |
7247 | prio = ieee80211_is_data(d11_header->frame_control) ? sdu->priority : | |
7248 | MAXPRIO; | |
7249 | fifo = prio2fifo[prio]; | |
7250 | if (brcms_c_d11hdrs_mac80211(wlc, hw, sdu, scb, 0, 1, fifo, 0)) | |
7251 | return; | |
7252 | brcms_c_txq_enq(wlc, scb, sdu, BRCMS_PRIO_TO_PREC(prio)); | |
7253 | brcms_c_send_q(wlc); | |
7254 | } | |
7255 | ||
7256 | void brcms_c_send_q(struct brcms_c_info *wlc) | |
7257 | { | |
7258 | struct sk_buff *pkt[DOT11_MAXNUMFRAGS]; | |
7259 | int prec; | |
7260 | u16 prec_map; | |
7261 | int err = 0, i, count; | |
7262 | uint fifo; | |
7263 | struct brcms_txq_info *qi = wlc->pkt_queue; | |
7264 | struct pktq *q = &qi->q; | |
7265 | struct ieee80211_tx_info *tx_info; | |
7266 | ||
7267 | prec_map = wlc->tx_prec_map; | |
7268 | ||
7269 | /* Send all the enq'd pkts that we can. | |
7270 | * Dequeue packets with precedence with empty HW fifo only | |
7271 | */ | |
7272 | while (prec_map && (pkt[0] = brcmu_pktq_mdeq(q, prec_map, &prec))) { | |
7273 | tx_info = IEEE80211_SKB_CB(pkt[0]); | |
7274 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) { | |
7275 | err = brcms_c_sendampdu(wlc->ampdu, qi, pkt, prec); | |
7276 | } else { | |
7277 | count = 1; | |
7278 | err = brcms_c_prep_pdu(wlc, pkt[0], &fifo); | |
7279 | if (!err) { | |
7280 | for (i = 0; i < count; i++) | |
7281 | brcms_c_txfifo(wlc, fifo, pkt[i], true, | |
7282 | 1); | |
7283 | } | |
7284 | } | |
7285 | ||
7286 | if (err == -EBUSY) { | |
7287 | brcmu_pktq_penq_head(q, prec, pkt[0]); | |
7288 | /* | |
7289 | * If send failed due to any other reason than a | |
7290 | * change in HW FIFO condition, quit. Otherwise, | |
7291 | * read the new prec_map! | |
7292 | */ | |
7293 | if (prec_map == wlc->tx_prec_map) | |
7294 | break; | |
7295 | prec_map = wlc->tx_prec_map; | |
7296 | } | |
7297 | } | |
7298 | } | |
7299 | ||
7300 | void | |
7301 | brcms_c_txfifo(struct brcms_c_info *wlc, uint fifo, struct sk_buff *p, | |
7302 | bool commit, s8 txpktpend) | |
7303 | { | |
7304 | u16 frameid = INVALIDFID; | |
7305 | struct d11txh *txh; | |
7306 | ||
7307 | txh = (struct d11txh *) (p->data); | |
7308 | ||
7309 | /* When a BC/MC frame is being committed to the BCMC fifo | |
7310 | * via DMA (NOT PIO), update ucode or BSS info as appropriate. | |
7311 | */ | |
7312 | if (fifo == TX_BCMC_FIFO) | |
7313 | frameid = le16_to_cpu(txh->TxFrameID); | |
7314 | ||
7315 | /* | |
7316 | * Bump up pending count for if not using rpc. If rpc is | |
7317 | * used, this will be handled in brcms_b_txfifo() | |
7318 | */ | |
7319 | if (commit) { | |
7320 | wlc->core->txpktpend[fifo] += txpktpend; | |
7321 | BCMMSG(wlc->wiphy, "pktpend inc %d to %d\n", | |
7322 | txpktpend, wlc->core->txpktpend[fifo]); | |
7323 | } | |
7324 | ||
7325 | /* Commit BCMC sequence number in the SHM frame ID location */ | |
7326 | if (frameid != INVALIDFID) { | |
7327 | /* | |
7328 | * To inform the ucode of the last mcast frame posted | |
7329 | * so that it can clear moredata bit | |
7330 | */ | |
7331 | brcms_b_write_shm(wlc->hw, M_BCMC_FID, frameid); | |
7332 | } | |
7333 | ||
7334 | if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) | |
7335 | wiphy_err(wlc->wiphy, "txfifo: fatal, toss frames !!!\n"); | |
7336 | } | |
7337 | ||
94bdc2a2 AB |
7338 | u32 |
7339 | brcms_c_rspec_to_rts_rspec(struct brcms_c_info *wlc, u32 rspec, | |
7340 | bool use_rspec, u16 mimo_ctlchbw) | |
5b435de0 | 7341 | { |
94bdc2a2 | 7342 | u32 rts_rspec = 0; |
5b435de0 | 7343 | |
94bdc2a2 AB |
7344 | if (use_rspec) |
7345 | /* use frame rate as rts rate */ | |
7346 | rts_rspec = rspec; | |
7347 | else if (wlc->band->gmode && wlc->protection->_g && !is_cck_rate(rspec)) | |
7348 | /* Use 11Mbps as the g protection RTS target rate and fallback. | |
7349 | * Use the brcms_basic_rate() lookup to find the best basic rate | |
7350 | * under the target in case 11 Mbps is not Basic. | |
7351 | * 6 and 9 Mbps are not usually selected by rate selection, but | |
7352 | * even if the OFDM rate we are protecting is 6 or 9 Mbps, 11 | |
7353 | * is more robust. | |
7354 | */ | |
7355 | rts_rspec = brcms_basic_rate(wlc, BRCM_RATE_11M); | |
7356 | else | |
7357 | /* calculate RTS rate and fallback rate based on the frame rate | |
7358 | * RTS must be sent at a basic rate since it is a | |
7359 | * control frame, sec 9.6 of 802.11 spec | |
7360 | */ | |
7361 | rts_rspec = brcms_basic_rate(wlc, rspec); | |
5b435de0 AS |
7362 | |
7363 | if (BRCMS_PHY_11N_CAP(wlc->band)) { | |
7364 | /* set rts txbw to correct side band */ | |
7365 | rts_rspec &= ~RSPEC_BW_MASK; | |
7366 | ||
7367 | /* | |
7368 | * if rspec/rspec_fallback is 40MHz, then send RTS on both | |
7369 | * 20MHz channel (DUP), otherwise send RTS on control channel | |
7370 | */ | |
7371 | if (rspec_is40mhz(rspec) && !is_cck_rate(rts_rspec)) | |
7372 | rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT); | |
7373 | else | |
7374 | rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT); | |
7375 | ||
7376 | /* pick siso/cdd as default for ofdm */ | |
7377 | if (is_ofdm_rate(rts_rspec)) { | |
7378 | rts_rspec &= ~RSPEC_STF_MASK; | |
7379 | rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT); | |
7380 | } | |
7381 | } | |
7382 | return rts_rspec; | |
7383 | } | |
7384 | ||
5b435de0 AS |
7385 | void |
7386 | brcms_c_txfifo_complete(struct brcms_c_info *wlc, uint fifo, s8 txpktpend) | |
7387 | { | |
7388 | wlc->core->txpktpend[fifo] -= txpktpend; | |
7389 | BCMMSG(wlc->wiphy, "pktpend dec %d to %d\n", txpktpend, | |
7390 | wlc->core->txpktpend[fifo]); | |
7391 | ||
7392 | /* There is more room; mark precedences related to this FIFO sendable */ | |
7393 | wlc->tx_prec_map |= wlc->fifo2prec_map[fifo]; | |
7394 | ||
7395 | /* figure out which bsscfg is being worked on... */ | |
7396 | } | |
7397 | ||
7398 | /* Update beacon listen interval in shared memory */ | |
94bdc2a2 | 7399 | static void brcms_c_bcn_li_upd(struct brcms_c_info *wlc) |
5b435de0 AS |
7400 | { |
7401 | /* wake up every DTIM is the default */ | |
7402 | if (wlc->bcn_li_dtim == 1) | |
7403 | brcms_b_write_shm(wlc->hw, M_BCN_LI, 0); | |
7404 | else | |
7405 | brcms_b_write_shm(wlc->hw, M_BCN_LI, | |
7406 | (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn); | |
7407 | } | |
7408 | ||
7409 | static void | |
7410 | brcms_b_read_tsf(struct brcms_hardware *wlc_hw, u32 *tsf_l_ptr, | |
7411 | u32 *tsf_h_ptr) | |
7412 | { | |
16d2812e | 7413 | struct bcma_device *core = wlc_hw->d11core; |
5b435de0 AS |
7414 | |
7415 | /* read the tsf timer low, then high to get an atomic read */ | |
16d2812e AS |
7416 | *tsf_l_ptr = bcma_read32(core, D11REGOFFS(tsf_timerlow)); |
7417 | *tsf_h_ptr = bcma_read32(core, D11REGOFFS(tsf_timerhigh)); | |
5b435de0 AS |
7418 | } |
7419 | ||
7420 | /* | |
7421 | * recover 64bit TSF value from the 16bit TSF value in the rx header | |
7422 | * given the assumption that the TSF passed in header is within 65ms | |
7423 | * of the current tsf. | |
7424 | * | |
7425 | * 6 5 4 4 3 2 1 | |
7426 | * 3.......6.......8.......0.......2.......4.......6.......8......0 | |
7427 | * |<---------- tsf_h ----------->||<--- tsf_l -->||<-RxTSFTime ->| | |
7428 | * | |
7429 | * The RxTSFTime are the lowest 16 bits and provided by the ucode. The | |
7430 | * tsf_l is filled in by brcms_b_recv, which is done earlier in the | |
7431 | * receive call sequence after rx interrupt. Only the higher 16 bits | |
7432 | * are used. Finally, the tsf_h is read from the tsf register. | |
7433 | */ | |
7434 | static u64 brcms_c_recover_tsf64(struct brcms_c_info *wlc, | |
7435 | struct d11rxhdr *rxh) | |
7436 | { | |
7437 | u32 tsf_h, tsf_l; | |
7438 | u16 rx_tsf_0_15, rx_tsf_16_31; | |
7439 | ||
7440 | brcms_b_read_tsf(wlc->hw, &tsf_l, &tsf_h); | |
7441 | ||
7442 | rx_tsf_16_31 = (u16)(tsf_l >> 16); | |
7443 | rx_tsf_0_15 = rxh->RxTSFTime; | |
7444 | ||
7445 | /* | |
7446 | * a greater tsf time indicates the low 16 bits of | |
7447 | * tsf_l wrapped, so decrement the high 16 bits. | |
7448 | */ | |
7449 | if ((u16)tsf_l < rx_tsf_0_15) { | |
7450 | rx_tsf_16_31 -= 1; | |
7451 | if (rx_tsf_16_31 == 0xffff) | |
7452 | tsf_h -= 1; | |
7453 | } | |
7454 | ||
7455 | return ((u64)tsf_h << 32) | (((u32)rx_tsf_16_31 << 16) + rx_tsf_0_15); | |
7456 | } | |
7457 | ||
7458 | static void | |
7459 | prep_mac80211_status(struct brcms_c_info *wlc, struct d11rxhdr *rxh, | |
7460 | struct sk_buff *p, | |
7461 | struct ieee80211_rx_status *rx_status) | |
7462 | { | |
7463 | int preamble; | |
7464 | int channel; | |
7465 | u32 rspec; | |
7466 | unsigned char *plcp; | |
7467 | ||
7468 | /* fill in TSF and flag its presence */ | |
7469 | rx_status->mactime = brcms_c_recover_tsf64(wlc, rxh); | |
7470 | rx_status->flag |= RX_FLAG_MACTIME_MPDU; | |
7471 | ||
7472 | channel = BRCMS_CHAN_CHANNEL(rxh->RxChan); | |
7473 | ||
7474 | if (channel > 14) { | |
7475 | rx_status->band = IEEE80211_BAND_5GHZ; | |
7476 | rx_status->freq = ieee80211_ofdm_chan_to_freq( | |
7477 | WF_CHAN_FACTOR_5_G/2, channel); | |
7478 | ||
7479 | } else { | |
7480 | rx_status->band = IEEE80211_BAND_2GHZ; | |
7481 | rx_status->freq = ieee80211_dsss_chan_to_freq(channel); | |
7482 | } | |
7483 | ||
7484 | rx_status->signal = wlc_phy_rssi_compute(wlc->hw->band->pi, rxh); | |
7485 | ||
7486 | /* noise */ | |
7487 | /* qual */ | |
7488 | rx_status->antenna = | |
7489 | (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; | |
7490 | ||
7491 | plcp = p->data; | |
7492 | ||
7493 | rspec = brcms_c_compute_rspec(rxh, plcp); | |
7494 | if (is_mcs_rate(rspec)) { | |
7495 | rx_status->rate_idx = rspec & RSPEC_RATE_MASK; | |
7496 | rx_status->flag |= RX_FLAG_HT; | |
7497 | if (rspec_is40mhz(rspec)) | |
7498 | rx_status->flag |= RX_FLAG_40MHZ; | |
7499 | } else { | |
7500 | switch (rspec2rate(rspec)) { | |
7501 | case BRCM_RATE_1M: | |
7502 | rx_status->rate_idx = 0; | |
7503 | break; | |
7504 | case BRCM_RATE_2M: | |
7505 | rx_status->rate_idx = 1; | |
7506 | break; | |
7507 | case BRCM_RATE_5M5: | |
7508 | rx_status->rate_idx = 2; | |
7509 | break; | |
7510 | case BRCM_RATE_11M: | |
7511 | rx_status->rate_idx = 3; | |
7512 | break; | |
7513 | case BRCM_RATE_6M: | |
7514 | rx_status->rate_idx = 4; | |
7515 | break; | |
7516 | case BRCM_RATE_9M: | |
7517 | rx_status->rate_idx = 5; | |
7518 | break; | |
7519 | case BRCM_RATE_12M: | |
7520 | rx_status->rate_idx = 6; | |
7521 | break; | |
7522 | case BRCM_RATE_18M: | |
7523 | rx_status->rate_idx = 7; | |
7524 | break; | |
7525 | case BRCM_RATE_24M: | |
7526 | rx_status->rate_idx = 8; | |
7527 | break; | |
7528 | case BRCM_RATE_36M: | |
7529 | rx_status->rate_idx = 9; | |
7530 | break; | |
7531 | case BRCM_RATE_48M: | |
7532 | rx_status->rate_idx = 10; | |
7533 | break; | |
7534 | case BRCM_RATE_54M: | |
7535 | rx_status->rate_idx = 11; | |
7536 | break; | |
7537 | default: | |
7538 | wiphy_err(wlc->wiphy, "%s: Unknown rate\n", __func__); | |
7539 | } | |
7540 | ||
7541 | /* | |
7542 | * For 5GHz, we should decrease the index as it is | |
7543 | * a subset of the 2.4G rates. See bitrates field | |
7544 | * of brcms_band_5GHz_nphy (in mac80211_if.c). | |
7545 | */ | |
7546 | if (rx_status->band == IEEE80211_BAND_5GHZ) | |
7547 | rx_status->rate_idx -= BRCMS_LEGACY_5G_RATE_OFFSET; | |
7548 | ||
7549 | /* Determine short preamble and rate_idx */ | |
7550 | preamble = 0; | |
7551 | if (is_cck_rate(rspec)) { | |
7552 | if (rxh->PhyRxStatus_0 & PRXS0_SHORTH) | |
7553 | rx_status->flag |= RX_FLAG_SHORTPRE; | |
7554 | } else if (is_ofdm_rate(rspec)) { | |
7555 | rx_status->flag |= RX_FLAG_SHORTPRE; | |
7556 | } else { | |
7557 | wiphy_err(wlc->wiphy, "%s: Unknown modulation\n", | |
7558 | __func__); | |
7559 | } | |
7560 | } | |
7561 | ||
7562 | if (plcp3_issgi(plcp[3])) | |
7563 | rx_status->flag |= RX_FLAG_SHORT_GI; | |
7564 | ||
7565 | if (rxh->RxStatus1 & RXS_DECERR) { | |
7566 | rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC; | |
7567 | wiphy_err(wlc->wiphy, "%s: RX_FLAG_FAILED_PLCP_CRC\n", | |
7568 | __func__); | |
7569 | } | |
7570 | if (rxh->RxStatus1 & RXS_FCSERR) { | |
7571 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; | |
7572 | wiphy_err(wlc->wiphy, "%s: RX_FLAG_FAILED_FCS_CRC\n", | |
7573 | __func__); | |
7574 | } | |
7575 | } | |
7576 | ||
7577 | static void | |
7578 | brcms_c_recvctl(struct brcms_c_info *wlc, struct d11rxhdr *rxh, | |
7579 | struct sk_buff *p) | |
7580 | { | |
7581 | int len_mpdu; | |
7582 | struct ieee80211_rx_status rx_status; | |
badc4f07 | 7583 | struct ieee80211_hdr *hdr; |
5b435de0 AS |
7584 | |
7585 | memset(&rx_status, 0, sizeof(rx_status)); | |
7586 | prep_mac80211_status(wlc, rxh, p, &rx_status); | |
7587 | ||
7588 | /* mac header+body length, exclude CRC and plcp header */ | |
7589 | len_mpdu = p->len - D11_PHY_HDR_LEN - FCS_LEN; | |
7590 | skb_pull(p, D11_PHY_HDR_LEN); | |
7591 | __skb_trim(p, len_mpdu); | |
7592 | ||
badc4f07 AS |
7593 | /* unmute transmit */ |
7594 | if (wlc->hw->suspended_fifos) { | |
7595 | hdr = (struct ieee80211_hdr *)p->data; | |
7596 | if (ieee80211_is_beacon(hdr->frame_control)) | |
7597 | brcms_b_mute(wlc->hw, false); | |
7598 | } | |
7599 | ||
5b435de0 AS |
7600 | memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status)); |
7601 | ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p); | |
7602 | } | |
7603 | ||
94bdc2a2 AB |
7604 | /* calculate frame duration for Mixed-mode L-SIG spoofing, return |
7605 | * number of bytes goes in the length field | |
7606 | * | |
7607 | * Formula given by HT PHY Spec v 1.13 | |
7608 | * len = 3(nsyms + nstream + 3) - 3 | |
5b435de0 | 7609 | */ |
94bdc2a2 AB |
7610 | u16 |
7611 | brcms_c_calc_lsig_len(struct brcms_c_info *wlc, u32 ratespec, | |
7612 | uint mac_len) | |
5b435de0 | 7613 | { |
94bdc2a2 | 7614 | uint nsyms, len = 0, kNdps; |
5b435de0 | 7615 | |
94bdc2a2 AB |
7616 | BCMMSG(wlc->wiphy, "wl%d: rate %d, len%d\n", |
7617 | wlc->pub->unit, rspec2rate(ratespec), mac_len); | |
5b435de0 | 7618 | |
94bdc2a2 AB |
7619 | if (is_mcs_rate(ratespec)) { |
7620 | uint mcs = ratespec & RSPEC_RATE_MASK; | |
7621 | int tot_streams = (mcs_2_txstreams(mcs) + 1) + | |
7622 | rspec_stc(ratespec); | |
5b435de0 | 7623 | |
94bdc2a2 AB |
7624 | /* |
7625 | * the payload duration calculation matches that | |
7626 | * of regular ofdm | |
7627 | */ | |
7628 | /* 1000Ndbps = kbps * 4 */ | |
7629 | kNdps = mcs_2_rate(mcs, rspec_is40mhz(ratespec), | |
7630 | rspec_issgi(ratespec)) * 4; | |
5b435de0 AS |
7631 | |
7632 | if (rspec_stc(ratespec) == 0) | |
7633 | nsyms = | |
7634 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + | |
7635 | APHY_TAIL_NBITS) * 1000, kNdps); | |
7636 | else | |
7637 | /* STBC needs to have even number of symbols */ | |
7638 | nsyms = | |
7639 | 2 * | |
7640 | CEIL((APHY_SERVICE_NBITS + 8 * mac_len + | |
7641 | APHY_TAIL_NBITS) * 1000, 2 * kNdps); | |
7642 | ||
7643 | /* (+3) account for HT-SIG(2) and HT-STF(1) */ | |
7644 | nsyms += (tot_streams + 3); | |
7645 | /* | |
7646 | * 3 bytes/symbol @ legacy 6Mbps rate | |
7647 | * (-3) excluding service bits and tail bits | |
7648 | */ | |
7649 | len = (3 * nsyms) - 3; | |
7650 | } | |
7651 | ||
7652 | return (u16) len; | |
7653 | } | |
7654 | ||
94bdc2a2 AB |
7655 | static void |
7656 | brcms_c_mod_prb_rsp_rate_table(struct brcms_c_info *wlc, uint frame_len) | |
5b435de0 | 7657 | { |
94bdc2a2 AB |
7658 | const struct brcms_c_rateset *rs_dflt; |
7659 | struct brcms_c_rateset rs; | |
7660 | u8 rate; | |
7661 | u16 entry_ptr; | |
7662 | u8 plcp[D11_PHY_HDR_LEN]; | |
7663 | u16 dur, sifs; | |
7664 | uint i; | |
5b435de0 | 7665 | |
94bdc2a2 | 7666 | sifs = get_sifs(wlc->band); |
5b435de0 | 7667 | |
94bdc2a2 | 7668 | rs_dflt = brcms_c_rateset_get_hwrs(wlc); |
5b435de0 | 7669 | |
94bdc2a2 AB |
7670 | brcms_c_rateset_copy(rs_dflt, &rs); |
7671 | brcms_c_rateset_mcs_upd(&rs, wlc->stf->txstreams); | |
5b435de0 | 7672 | |
94bdc2a2 AB |
7673 | /* |
7674 | * walk the phy rate table and update MAC core SHM | |
7675 | * basic rate table entries | |
7676 | */ | |
7677 | for (i = 0; i < rs.count; i++) { | |
7678 | rate = rs.rates[i] & BRCMS_RATE_MASK; | |
5b435de0 | 7679 | |
94bdc2a2 AB |
7680 | entry_ptr = brcms_b_rate_shm_offset(wlc->hw, rate); |
7681 | ||
7682 | /* Calculate the Probe Response PLCP for the given rate */ | |
7683 | brcms_c_compute_plcp(wlc, rate, frame_len, plcp); | |
5b435de0 | 7684 | |
5b435de0 | 7685 | /* |
94bdc2a2 AB |
7686 | * Calculate the duration of the Probe Response |
7687 | * frame plus SIFS for the MAC | |
5b435de0 | 7688 | */ |
94bdc2a2 AB |
7689 | dur = (u16) brcms_c_calc_frame_time(wlc, rate, |
7690 | BRCMS_LONG_PREAMBLE, frame_len); | |
7691 | dur += sifs; | |
7692 | ||
7693 | /* Update the SHM Rate Table entry Probe Response values */ | |
7694 | brcms_b_write_shm(wlc->hw, entry_ptr + M_RT_PRS_PLCP_POS, | |
7695 | (u16) (plcp[0] + (plcp[1] << 8))); | |
7696 | brcms_b_write_shm(wlc->hw, entry_ptr + M_RT_PRS_PLCP_POS + 2, | |
7697 | (u16) (plcp[2] + (plcp[3] << 8))); | |
7698 | brcms_b_write_shm(wlc->hw, entry_ptr + M_RT_PRS_DUR_POS, dur); | |
5b435de0 | 7699 | } |
5b435de0 AS |
7700 | } |
7701 | ||
94bdc2a2 AB |
7702 | /* Max buffering needed for beacon template/prb resp template is 142 bytes. |
7703 | * | |
7704 | * PLCP header is 6 bytes. | |
7705 | * 802.11 A3 header is 24 bytes. | |
7706 | * Max beacon frame body template length is 112 bytes. | |
7707 | * Max probe resp frame body template length is 110 bytes. | |
7708 | * | |
7709 | * *len on input contains the max length of the packet available. | |
7710 | * | |
7711 | * The *len value is set to the number of bytes in buf used, and starts | |
7712 | * with the PLCP and included up to, but not including, the 4 byte FCS. | |
7713 | */ | |
7714 | static void | |
7715 | brcms_c_bcn_prb_template(struct brcms_c_info *wlc, u16 type, | |
7716 | u32 bcn_rspec, | |
7717 | struct brcms_bss_cfg *cfg, u16 *buf, int *len) | |
5b435de0 | 7718 | { |
94bdc2a2 AB |
7719 | static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255}; |
7720 | struct cck_phy_hdr *plcp; | |
7721 | struct ieee80211_mgmt *h; | |
7722 | int hdr_len, body_len; | |
5b435de0 | 7723 | |
94bdc2a2 | 7724 | hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN; |
5b435de0 | 7725 | |
94bdc2a2 AB |
7726 | /* calc buffer size provided for frame body */ |
7727 | body_len = *len - hdr_len; | |
7728 | /* return actual size */ | |
7729 | *len = hdr_len + body_len; | |
5b435de0 | 7730 | |
94bdc2a2 AB |
7731 | /* format PHY and MAC headers */ |
7732 | memset((char *)buf, 0, hdr_len); | |
5b435de0 | 7733 | |
94bdc2a2 | 7734 | plcp = (struct cck_phy_hdr *) buf; |
5b435de0 | 7735 | |
94bdc2a2 AB |
7736 | /* |
7737 | * PLCP for Probe Response frames are filled in from | |
7738 | * core's rate table | |
5b435de0 | 7739 | */ |
94bdc2a2 AB |
7740 | if (type == IEEE80211_STYPE_BEACON) |
7741 | /* fill in PLCP */ | |
7742 | brcms_c_compute_plcp(wlc, bcn_rspec, | |
7743 | (DOT11_MAC_HDR_LEN + body_len + FCS_LEN), | |
7744 | (u8 *) plcp); | |
5b435de0 | 7745 | |
94bdc2a2 AB |
7746 | /* "Regular" and 16 MBSS but not for 4 MBSS */ |
7747 | /* Update the phytxctl for the beacon based on the rspec */ | |
7748 | brcms_c_beacon_phytxctl_txant_upd(wlc, bcn_rspec); | |
5b435de0 | 7749 | |
94bdc2a2 | 7750 | h = (struct ieee80211_mgmt *)&plcp[1]; |
5b435de0 | 7751 | |
94bdc2a2 AB |
7752 | /* fill in 802.11 header */ |
7753 | h->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | type); | |
5b435de0 | 7754 | |
94bdc2a2 AB |
7755 | /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */ |
7756 | /* A1 filled in by MAC for prb resp, broadcast for bcn */ | |
7757 | if (type == IEEE80211_STYPE_BEACON) | |
7758 | memcpy(&h->da, ðer_bcast, ETH_ALEN); | |
7759 | memcpy(&h->sa, &cfg->cur_etheraddr, ETH_ALEN); | |
7760 | memcpy(&h->bssid, &cfg->BSSID, ETH_ALEN); | |
5b435de0 | 7761 | |
94bdc2a2 AB |
7762 | /* SEQ filled in by MAC */ |
7763 | } | |
5b435de0 | 7764 | |
94bdc2a2 AB |
7765 | int brcms_c_get_header_len(void) |
7766 | { | |
7767 | return TXOFF; | |
7768 | } | |
5b435de0 | 7769 | |
94bdc2a2 AB |
7770 | /* |
7771 | * Update all beacons for the system. | |
7772 | */ | |
7773 | void brcms_c_update_beacon(struct brcms_c_info *wlc) | |
7774 | { | |
7775 | struct brcms_bss_cfg *bsscfg = wlc->bsscfg; | |
5b435de0 | 7776 | |
94bdc2a2 AB |
7777 | if (bsscfg->up && !bsscfg->BSS) |
7778 | /* Clear the soft intmask */ | |
7779 | wlc->defmacintmask &= ~MI_BCNTPL; | |
5b435de0 AS |
7780 | } |
7781 | ||
94bdc2a2 AB |
7782 | /* Write ssid into shared memory */ |
7783 | static void | |
7784 | brcms_c_shm_ssid_upd(struct brcms_c_info *wlc, struct brcms_bss_cfg *cfg) | |
5b435de0 | 7785 | { |
94bdc2a2 AB |
7786 | u8 *ssidptr = cfg->SSID; |
7787 | u16 base = M_SSID; | |
7788 | u8 ssidbuf[IEEE80211_MAX_SSID_LEN]; | |
5b435de0 | 7789 | |
94bdc2a2 AB |
7790 | /* padding the ssid with zero and copy it into shm */ |
7791 | memset(ssidbuf, 0, IEEE80211_MAX_SSID_LEN); | |
7792 | memcpy(ssidbuf, ssidptr, cfg->SSID_len); | |
5b435de0 | 7793 | |
94bdc2a2 AB |
7794 | brcms_c_copyto_shm(wlc, base, ssidbuf, IEEE80211_MAX_SSID_LEN); |
7795 | brcms_b_write_shm(wlc->hw, M_SSIDLEN, (u16) cfg->SSID_len); | |
7796 | } | |
7797 | ||
7798 | static void | |
7799 | brcms_c_bss_update_probe_resp(struct brcms_c_info *wlc, | |
7800 | struct brcms_bss_cfg *cfg, | |
7801 | bool suspend) | |
7802 | { | |
7803 | u16 prb_resp[BCN_TMPL_LEN / 2]; | |
7804 | int len = BCN_TMPL_LEN; | |
5b435de0 AS |
7805 | |
7806 | /* | |
94bdc2a2 AB |
7807 | * write the probe response to hardware, or save in |
7808 | * the config structure | |
5b435de0 | 7809 | */ |
5b435de0 | 7810 | |
94bdc2a2 AB |
7811 | /* create the probe response template */ |
7812 | brcms_c_bcn_prb_template(wlc, IEEE80211_STYPE_PROBE_RESP, 0, | |
7813 | cfg, prb_resp, &len); | |
5b435de0 | 7814 | |
94bdc2a2 AB |
7815 | if (suspend) |
7816 | brcms_c_suspend_mac_and_wait(wlc); | |
7817 | ||
7818 | /* write the probe response into the template region */ | |
7819 | brcms_b_write_template_ram(wlc->hw, T_PRS_TPL_BASE, | |
7820 | (len + 3) & ~3, prb_resp); | |
7821 | ||
7822 | /* write the length of the probe response frame (+PLCP/-FCS) */ | |
7823 | brcms_b_write_shm(wlc->hw, M_PRB_RESP_FRM_LEN, (u16) len); | |
7824 | ||
7825 | /* write the SSID and SSID length */ | |
7826 | brcms_c_shm_ssid_upd(wlc, cfg); | |
7827 | ||
7828 | /* | |
7829 | * Write PLCP headers and durations for probe response frames | |
7830 | * at all rates. Use the actual frame length covered by the | |
7831 | * PLCP header for the call to brcms_c_mod_prb_rsp_rate_table() | |
7832 | * by subtracting the PLCP len and adding the FCS. | |
5b435de0 | 7833 | */ |
94bdc2a2 AB |
7834 | len += (-D11_PHY_HDR_LEN + FCS_LEN); |
7835 | brcms_c_mod_prb_rsp_rate_table(wlc, (u16) len); | |
7836 | ||
7837 | if (suspend) | |
7838 | brcms_c_enable_mac(wlc); | |
5b435de0 AS |
7839 | } |
7840 | ||
94bdc2a2 | 7841 | void brcms_c_update_probe_resp(struct brcms_c_info *wlc, bool suspend) |
5b435de0 | 7842 | { |
94bdc2a2 | 7843 | struct brcms_bss_cfg *bsscfg = wlc->bsscfg; |
5b435de0 | 7844 | |
94bdc2a2 AB |
7845 | /* update AP or IBSS probe responses */ |
7846 | if (bsscfg->up && !bsscfg->BSS) | |
7847 | brcms_c_bss_update_probe_resp(wlc, bsscfg, suspend); | |
5b435de0 AS |
7848 | } |
7849 | ||
94bdc2a2 AB |
7850 | /* prepares pdu for transmission. returns BCM error codes */ |
7851 | int brcms_c_prep_pdu(struct brcms_c_info *wlc, struct sk_buff *pdu, uint *fifop) | |
5b435de0 | 7852 | { |
94bdc2a2 AB |
7853 | uint fifo; |
7854 | struct d11txh *txh; | |
7855 | struct ieee80211_hdr *h; | |
7856 | struct scb *scb; | |
5b435de0 | 7857 | |
94bdc2a2 AB |
7858 | txh = (struct d11txh *) (pdu->data); |
7859 | h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN); | |
5b435de0 | 7860 | |
94bdc2a2 AB |
7861 | /* get the pkt queue info. This was put at brcms_c_sendctl or |
7862 | * brcms_c_send for PDU */ | |
7863 | fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK; | |
5b435de0 | 7864 | |
94bdc2a2 | 7865 | scb = NULL; |
5b435de0 | 7866 | |
94bdc2a2 | 7867 | *fifop = fifo; |
5b435de0 | 7868 | |
94bdc2a2 AB |
7869 | /* return if insufficient dma resources */ |
7870 | if (*wlc->core->txavail[fifo] < MAX_DMA_SEGS) { | |
7871 | /* Mark precedences related to this FIFO, unsendable */ | |
7872 | /* A fifo is full. Clear precedences related to that FIFO */ | |
7873 | wlc->tx_prec_map &= ~(wlc->fifo2prec_map[fifo]); | |
7874 | return -EBUSY; | |
5b435de0 | 7875 | } |
94bdc2a2 | 7876 | return 0; |
5b435de0 AS |
7877 | } |
7878 | ||
94bdc2a2 AB |
7879 | int brcms_b_xmtfifo_sz_get(struct brcms_hardware *wlc_hw, uint fifo, |
7880 | uint *blocks) | |
5b435de0 | 7881 | { |
94bdc2a2 AB |
7882 | if (fifo >= NFIFO) |
7883 | return -EINVAL; | |
5b435de0 | 7884 | |
94bdc2a2 | 7885 | *blocks = wlc_hw->xmtfifo_sz[fifo]; |
5b435de0 | 7886 | |
94bdc2a2 AB |
7887 | return 0; |
7888 | } | |
5b435de0 | 7889 | |
94bdc2a2 AB |
7890 | void |
7891 | brcms_c_set_addrmatch(struct brcms_c_info *wlc, int match_reg_offset, | |
7892 | const u8 *addr) | |
7893 | { | |
7894 | brcms_b_set_addrmatch(wlc->hw, match_reg_offset, addr); | |
7895 | if (match_reg_offset == RCM_BSSID_OFFSET) | |
7896 | memcpy(wlc->bsscfg->BSSID, addr, ETH_ALEN); | |
7897 | } | |
5b435de0 | 7898 | |
94bdc2a2 AB |
7899 | /* |
7900 | * Flag 'scan in progress' to withhold dynamic phy calibration | |
7901 | */ | |
7902 | void brcms_c_scan_start(struct brcms_c_info *wlc) | |
7903 | { | |
7904 | wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, true); | |
7905 | } | |
5b435de0 | 7906 | |
94bdc2a2 AB |
7907 | void brcms_c_scan_stop(struct brcms_c_info *wlc) |
7908 | { | |
7909 | wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, false); | |
5b435de0 AS |
7910 | } |
7911 | ||
94bdc2a2 | 7912 | void brcms_c_associate_upd(struct brcms_c_info *wlc, bool state) |
5b435de0 | 7913 | { |
94bdc2a2 AB |
7914 | wlc->pub->associated = state; |
7915 | wlc->bsscfg->associated = state; | |
7916 | } | |
5b435de0 | 7917 | |
94bdc2a2 AB |
7918 | /* |
7919 | * When a remote STA/AP is removed by Mac80211, or when it can no longer accept | |
7920 | * AMPDU traffic, packets pending in hardware have to be invalidated so that | |
7921 | * when later on hardware releases them, they can be handled appropriately. | |
7922 | */ | |
7923 | void brcms_c_inval_dma_pkts(struct brcms_hardware *hw, | |
7924 | struct ieee80211_sta *sta, | |
7925 | void (*dma_callback_fn)) | |
7926 | { | |
7927 | struct dma_pub *dmah; | |
7928 | int i; | |
7929 | for (i = 0; i < NFIFO; i++) { | |
7930 | dmah = hw->di[i]; | |
7931 | if (dmah != NULL) | |
7932 | dma_walk_packets(dmah, dma_callback_fn, sta); | |
7933 | } | |
7934 | } | |
5b435de0 | 7935 | |
94bdc2a2 AB |
7936 | int brcms_c_get_curband(struct brcms_c_info *wlc) |
7937 | { | |
7938 | return wlc->band->bandunit; | |
7939 | } | |
5b435de0 | 7940 | |
94bdc2a2 AB |
7941 | void brcms_c_wait_for_tx_completion(struct brcms_c_info *wlc, bool drop) |
7942 | { | |
f96b08a7 SG |
7943 | int timeout = 20; |
7944 | ||
94bdc2a2 AB |
7945 | /* flush packet queue when requested */ |
7946 | if (drop) | |
7947 | brcmu_pktq_flush(&wlc->pkt_queue->q, false, NULL, NULL); | |
5b435de0 | 7948 | |
94bdc2a2 | 7949 | /* wait for queue and DMA fifos to run dry */ |
f96b08a7 | 7950 | while (!pktq_empty(&wlc->pkt_queue->q) || brcms_txpktpendtot(wlc) > 0) { |
94bdc2a2 | 7951 | brcms_msleep(wlc->wl, 1); |
f96b08a7 SG |
7952 | |
7953 | if (--timeout == 0) | |
7954 | break; | |
7955 | } | |
7956 | ||
7957 | WARN_ON_ONCE(timeout == 0); | |
94bdc2a2 | 7958 | } |
5b435de0 | 7959 | |
94bdc2a2 AB |
7960 | void brcms_c_set_beacon_listen_interval(struct brcms_c_info *wlc, u8 interval) |
7961 | { | |
7962 | wlc->bcn_li_bcn = interval; | |
7963 | if (wlc->pub->up) | |
7964 | brcms_c_bcn_li_upd(wlc); | |
7965 | } | |
5b435de0 | 7966 | |
94bdc2a2 AB |
7967 | int brcms_c_set_tx_power(struct brcms_c_info *wlc, int txpwr) |
7968 | { | |
7969 | uint qdbm; | |
5b435de0 | 7970 | |
94bdc2a2 AB |
7971 | /* Remove override bit and clip to max qdbm value */ |
7972 | qdbm = min_t(uint, txpwr * BRCMS_TXPWR_DB_FACTOR, 0xff); | |
7973 | return wlc_phy_txpower_set(wlc->band->pi, qdbm, false); | |
7974 | } | |
5b435de0 | 7975 | |
94bdc2a2 AB |
7976 | int brcms_c_get_tx_power(struct brcms_c_info *wlc) |
7977 | { | |
7978 | uint qdbm; | |
7979 | bool override; | |
7980 | ||
7981 | wlc_phy_txpower_get(wlc->band->pi, &qdbm, &override); | |
7982 | ||
7983 | /* Return qdbm units */ | |
7984 | return (int)(qdbm / BRCMS_TXPWR_DB_FACTOR); | |
5b435de0 AS |
7985 | } |
7986 | ||
94bdc2a2 AB |
7987 | /* Process received frames */ |
7988 | /* | |
7989 | * Return true if more frames need to be processed. false otherwise. | |
7990 | * Param 'bound' indicates max. # frames to process before break out. | |
7991 | */ | |
7992 | static void brcms_c_recv(struct brcms_c_info *wlc, struct sk_buff *p) | |
7993 | { | |
7994 | struct d11rxhdr *rxh; | |
7995 | struct ieee80211_hdr *h; | |
7996 | uint len; | |
7997 | bool is_amsdu; | |
5b435de0 | 7998 | |
94bdc2a2 | 7999 | BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit); |
5b435de0 | 8000 | |
94bdc2a2 AB |
8001 | /* frame starts with rxhdr */ |
8002 | rxh = (struct d11rxhdr *) (p->data); | |
5b435de0 | 8003 | |
94bdc2a2 AB |
8004 | /* strip off rxhdr */ |
8005 | skb_pull(p, BRCMS_HWRXOFF); | |
5b435de0 | 8006 | |
94bdc2a2 AB |
8007 | /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */ |
8008 | if (rxh->RxStatus1 & RXS_PBPRES) { | |
8009 | if (p->len < 2) { | |
8010 | wiphy_err(wlc->wiphy, "wl%d: recv: rcvd runt of " | |
8011 | "len %d\n", wlc->pub->unit, p->len); | |
8012 | goto toss; | |
8013 | } | |
8014 | skb_pull(p, 2); | |
8015 | } | |
5b435de0 | 8016 | |
94bdc2a2 AB |
8017 | h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN); |
8018 | len = p->len; | |
5b435de0 | 8019 | |
94bdc2a2 | 8020 | if (rxh->RxStatus1 & RXS_FCSERR) { |
be667669 | 8021 | if (!(wlc->filter_flags & FIF_FCSFAIL)) |
94bdc2a2 | 8022 | goto toss; |
94bdc2a2 | 8023 | } |
5b435de0 | 8024 | |
94bdc2a2 AB |
8025 | /* check received pkt has at least frame control field */ |
8026 | if (len < D11_PHY_HDR_LEN + sizeof(h->frame_control)) | |
8027 | goto toss; | |
5b435de0 | 8028 | |
94bdc2a2 AB |
8029 | /* not supporting A-MSDU */ |
8030 | is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK; | |
8031 | if (is_amsdu) | |
8032 | goto toss; | |
5b435de0 | 8033 | |
94bdc2a2 AB |
8034 | brcms_c_recvctl(wlc, rxh, p); |
8035 | return; | |
5b435de0 | 8036 | |
94bdc2a2 AB |
8037 | toss: |
8038 | brcmu_pkt_buf_free_skb(p); | |
5b435de0 AS |
8039 | } |
8040 | ||
94bdc2a2 | 8041 | /* Process received frames */ |
5b435de0 | 8042 | /* |
94bdc2a2 AB |
8043 | * Return true if more frames need to be processed. false otherwise. |
8044 | * Param 'bound' indicates max. # frames to process before break out. | |
5b435de0 | 8045 | */ |
94bdc2a2 AB |
8046 | static bool |
8047 | brcms_b_recv(struct brcms_hardware *wlc_hw, uint fifo, bool bound) | |
5b435de0 | 8048 | { |
94bdc2a2 | 8049 | struct sk_buff *p; |
3fd172d3 AS |
8050 | struct sk_buff *next = NULL; |
8051 | struct sk_buff_head recv_frames; | |
8052 | ||
94bdc2a2 AB |
8053 | uint n = 0; |
8054 | uint bound_limit = bound ? RXBND : -1; | |
5b435de0 | 8055 | |
94bdc2a2 | 8056 | BCMMSG(wlc_hw->wlc->wiphy, "wl%d\n", wlc_hw->unit); |
3fd172d3 | 8057 | skb_queue_head_init(&recv_frames); |
5b435de0 | 8058 | |
3fd172d3 AS |
8059 | /* gather received frames */ |
8060 | while (dma_rx(wlc_hw->di[fifo], &recv_frames)) { | |
5b435de0 | 8061 | |
94bdc2a2 AB |
8062 | /* !give others some time to run! */ |
8063 | if (++n >= bound_limit) | |
8064 | break; | |
8065 | } | |
5b435de0 | 8066 | |
94bdc2a2 AB |
8067 | /* post more rbufs */ |
8068 | dma_rxfill(wlc_hw->di[fifo]); | |
8069 | ||
8070 | /* process each frame */ | |
3fd172d3 | 8071 | skb_queue_walk_safe(&recv_frames, p, next) { |
94bdc2a2 AB |
8072 | struct d11rxhdr_le *rxh_le; |
8073 | struct d11rxhdr *rxh; | |
94bdc2a2 | 8074 | |
3fd172d3 | 8075 | skb_unlink(p, &recv_frames); |
94bdc2a2 AB |
8076 | rxh_le = (struct d11rxhdr_le *)p->data; |
8077 | rxh = (struct d11rxhdr *)p->data; | |
8078 | ||
8079 | /* fixup rx header endianness */ | |
8080 | rxh->RxFrameSize = le16_to_cpu(rxh_le->RxFrameSize); | |
8081 | rxh->PhyRxStatus_0 = le16_to_cpu(rxh_le->PhyRxStatus_0); | |
8082 | rxh->PhyRxStatus_1 = le16_to_cpu(rxh_le->PhyRxStatus_1); | |
8083 | rxh->PhyRxStatus_2 = le16_to_cpu(rxh_le->PhyRxStatus_2); | |
8084 | rxh->PhyRxStatus_3 = le16_to_cpu(rxh_le->PhyRxStatus_3); | |
8085 | rxh->PhyRxStatus_4 = le16_to_cpu(rxh_le->PhyRxStatus_4); | |
8086 | rxh->PhyRxStatus_5 = le16_to_cpu(rxh_le->PhyRxStatus_5); | |
8087 | rxh->RxStatus1 = le16_to_cpu(rxh_le->RxStatus1); | |
8088 | rxh->RxStatus2 = le16_to_cpu(rxh_le->RxStatus2); | |
8089 | rxh->RxTSFTime = le16_to_cpu(rxh_le->RxTSFTime); | |
8090 | rxh->RxChan = le16_to_cpu(rxh_le->RxChan); | |
8091 | ||
8092 | brcms_c_recv(wlc_hw->wlc, p); | |
8093 | } | |
8094 | ||
8095 | return n >= bound_limit; | |
5b435de0 AS |
8096 | } |
8097 | ||
94bdc2a2 AB |
8098 | /* second-level interrupt processing |
8099 | * Return true if another dpc needs to be re-scheduled. false otherwise. | |
8100 | * Param 'bounded' indicates if applicable loops should be bounded. | |
8101 | */ | |
8102 | bool brcms_c_dpc(struct brcms_c_info *wlc, bool bounded) | |
5b435de0 | 8103 | { |
94bdc2a2 AB |
8104 | u32 macintstatus; |
8105 | struct brcms_hardware *wlc_hw = wlc->hw; | |
16d2812e | 8106 | struct bcma_device *core = wlc_hw->d11core; |
94bdc2a2 | 8107 | struct wiphy *wiphy = wlc->wiphy; |
5b435de0 | 8108 | |
94bdc2a2 AB |
8109 | if (brcms_deviceremoved(wlc)) { |
8110 | wiphy_err(wiphy, "wl%d: %s: dead chip\n", wlc_hw->unit, | |
8111 | __func__); | |
8112 | brcms_down(wlc->wl); | |
8113 | return false; | |
8114 | } | |
8115 | ||
8116 | /* grab and clear the saved software intstatus bits */ | |
8117 | macintstatus = wlc->macintstatus; | |
8118 | wlc->macintstatus = 0; | |
8119 | ||
8120 | BCMMSG(wlc->wiphy, "wl%d: macintstatus 0x%x\n", | |
8121 | wlc_hw->unit, macintstatus); | |
8122 | ||
8123 | WARN_ON(macintstatus & MI_PRQ); /* PRQ Interrupt in non-MBSS */ | |
8124 | ||
8125 | /* tx status */ | |
8126 | if (macintstatus & MI_TFS) { | |
8127 | bool fatal; | |
8128 | if (brcms_b_txstatus(wlc->hw, bounded, &fatal)) | |
8129 | wlc->macintstatus |= MI_TFS; | |
8130 | if (fatal) { | |
8131 | wiphy_err(wiphy, "MI_TFS: fatal\n"); | |
8132 | goto fatal; | |
8133 | } | |
8134 | } | |
8135 | ||
8136 | if (macintstatus & (MI_TBTT | MI_DTIM_TBTT)) | |
8137 | brcms_c_tbtt(wlc); | |
8138 | ||
8139 | /* ATIM window end */ | |
8140 | if (macintstatus & MI_ATIMWINEND) { | |
8141 | BCMMSG(wlc->wiphy, "end of ATIM window\n"); | |
16d2812e | 8142 | bcma_set32(core, D11REGOFFS(maccommand), wlc->qvalid); |
94bdc2a2 AB |
8143 | wlc->qvalid = 0; |
8144 | } | |
8145 | ||
8146 | /* | |
8147 | * received data or control frame, MI_DMAINT is | |
8148 | * indication of RX_FIFO interrupt | |
8149 | */ | |
8150 | if (macintstatus & MI_DMAINT) | |
8151 | if (brcms_b_recv(wlc_hw, RX_FIFO, bounded)) | |
8152 | wlc->macintstatus |= MI_DMAINT; | |
8153 | ||
8154 | /* noise sample collected */ | |
8155 | if (macintstatus & MI_BG_NOISE) | |
8156 | wlc_phy_noise_sample_intr(wlc_hw->band->pi); | |
8157 | ||
8158 | if (macintstatus & MI_GP0) { | |
8159 | wiphy_err(wiphy, "wl%d: PSM microcode watchdog fired at %d " | |
b2ffec46 | 8160 | "(seconds). Resetting.\n", wlc_hw->unit, wlc_hw->now); |
94bdc2a2 AB |
8161 | |
8162 | printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n", | |
b2ffec46 AS |
8163 | __func__, ai_get_chip_id(wlc_hw->sih), |
8164 | ai_get_chiprev(wlc_hw->sih)); | |
c261bdf8 | 8165 | brcms_fatal_error(wlc_hw->wlc->wl); |
94bdc2a2 AB |
8166 | } |
8167 | ||
8168 | /* gptimer timeout */ | |
8169 | if (macintstatus & MI_TO) | |
16d2812e | 8170 | bcma_write32(core, D11REGOFFS(gptimer), 0); |
94bdc2a2 AB |
8171 | |
8172 | if (macintstatus & MI_RFDISABLE) { | |
8173 | BCMMSG(wlc->wiphy, "wl%d: BMAC Detected a change on the" | |
8174 | " RF Disable Input\n", wlc_hw->unit); | |
8175 | brcms_rfkill_set_hw_state(wlc->wl); | |
8176 | } | |
8177 | ||
8178 | /* send any enq'd tx packets. Just makes sure to jump start tx */ | |
8179 | if (!pktq_empty(&wlc->pkt_queue->q)) | |
8180 | brcms_c_send_q(wlc); | |
8181 | ||
8182 | /* it isn't done and needs to be resched if macintstatus is non-zero */ | |
8183 | return wlc->macintstatus != 0; | |
8184 | ||
8185 | fatal: | |
c261bdf8 | 8186 | brcms_fatal_error(wlc_hw->wlc->wl); |
94bdc2a2 | 8187 | return wlc->macintstatus != 0; |
5b435de0 AS |
8188 | } |
8189 | ||
dc460127 | 8190 | void brcms_c_init(struct brcms_c_info *wlc, bool mute_tx) |
5b435de0 | 8191 | { |
16d2812e | 8192 | struct bcma_device *core = wlc->hw->d11core; |
94bdc2a2 | 8193 | u16 chanspec; |
94bdc2a2 AB |
8194 | |
8195 | BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit); | |
8196 | ||
5b435de0 | 8197 | /* |
94bdc2a2 AB |
8198 | * This will happen if a big-hammer was executed. In |
8199 | * that case, we want to go back to the channel that | |
8200 | * we were on and not new channel | |
5b435de0 | 8201 | */ |
94bdc2a2 AB |
8202 | if (wlc->pub->associated) |
8203 | chanspec = wlc->home_chanspec; | |
8204 | else | |
8205 | chanspec = brcms_c_init_chanspec(wlc); | |
5b435de0 | 8206 | |
a8bc4917 | 8207 | brcms_b_init(wlc->hw, chanspec); |
5b435de0 | 8208 | |
94bdc2a2 AB |
8209 | /* update beacon listen interval */ |
8210 | brcms_c_bcn_li_upd(wlc); | |
5b435de0 | 8211 | |
94bdc2a2 AB |
8212 | /* write ethernet address to core */ |
8213 | brcms_c_set_mac(wlc->bsscfg); | |
8214 | brcms_c_set_bssid(wlc->bsscfg); | |
5b435de0 | 8215 | |
94bdc2a2 AB |
8216 | /* Update tsf_cfprep if associated and up */ |
8217 | if (wlc->pub->associated && wlc->bsscfg->up) { | |
8218 | u32 bi; | |
5b435de0 | 8219 | |
94bdc2a2 AB |
8220 | /* get beacon period and convert to uS */ |
8221 | bi = wlc->bsscfg->current_bss->beacon_period << 10; | |
8222 | /* | |
8223 | * update since init path would reset | |
8224 | * to default value | |
8225 | */ | |
16d2812e AS |
8226 | bcma_write32(core, D11REGOFFS(tsf_cfprep), |
8227 | bi << CFPREP_CBI_SHIFT); | |
94bdc2a2 AB |
8228 | |
8229 | /* Update maccontrol PM related bits */ | |
8230 | brcms_c_set_ps_ctrl(wlc); | |
8231 | } | |
8232 | ||
8233 | brcms_c_bandinit_ordered(wlc, chanspec); | |
8234 | ||
8235 | /* init probe response timeout */ | |
8236 | brcms_b_write_shm(wlc->hw, M_PRS_MAXTIME, wlc->prb_resp_timeout); | |
8237 | ||
8238 | /* init max burst txop (framebursting) */ | |
8239 | brcms_b_write_shm(wlc->hw, M_MBURST_TXOP, | |
8240 | (wlc-> | |
8241 | _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP)); | |
8242 | ||
8243 | /* initialize maximum allowed duty cycle */ | |
8244 | brcms_c_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, true, true); | |
8245 | brcms_c_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, false, true); | |
5b435de0 AS |
8246 | |
8247 | /* | |
94bdc2a2 AB |
8248 | * Update some shared memory locations related to |
8249 | * max AMPDU size allowed to received | |
5b435de0 | 8250 | */ |
94bdc2a2 | 8251 | brcms_c_ampdu_shm_upd(wlc->ampdu); |
5b435de0 | 8252 | |
94bdc2a2 AB |
8253 | /* band-specific inits */ |
8254 | brcms_c_bsinit(wlc); | |
5b435de0 | 8255 | |
94bdc2a2 | 8256 | /* Enable EDCF mode (while the MAC is suspended) */ |
16d2812e | 8257 | bcma_set16(core, D11REGOFFS(ifs_ctl), IFS_USEEDCF); |
94bdc2a2 | 8258 | brcms_c_edcf_setparams(wlc, false); |
5b435de0 | 8259 | |
94bdc2a2 AB |
8260 | /* Init precedence maps for empty FIFOs */ |
8261 | brcms_c_tx_prec_map_init(wlc); | |
5b435de0 | 8262 | |
94bdc2a2 AB |
8263 | /* read the ucode version if we have not yet done so */ |
8264 | if (wlc->ucode_rev == 0) { | |
8265 | wlc->ucode_rev = | |
8266 | brcms_b_read_shm(wlc->hw, M_BOM_REV_MAJOR) << NBITS(u16); | |
8267 | wlc->ucode_rev |= brcms_b_read_shm(wlc->hw, M_BOM_REV_MINOR); | |
8268 | } | |
5b435de0 | 8269 | |
94bdc2a2 AB |
8270 | /* ..now really unleash hell (allow the MAC out of suspend) */ |
8271 | brcms_c_enable_mac(wlc); | |
5b435de0 | 8272 | |
a8bc4917 RV |
8273 | /* suspend the tx fifos and mute the phy for preism cac time */ |
8274 | if (mute_tx) | |
c6c44893 | 8275 | brcms_b_mute(wlc->hw, true); |
a8bc4917 | 8276 | |
94bdc2a2 AB |
8277 | /* clear tx flow control */ |
8278 | brcms_c_txflowcontrol_reset(wlc); | |
5b435de0 | 8279 | |
94bdc2a2 | 8280 | /* enable the RF Disable Delay timer */ |
16d2812e | 8281 | bcma_write32(core, D11REGOFFS(rfdisabledly), RFDISABLE_DEFAULT); |
5b435de0 | 8282 | |
94bdc2a2 AB |
8283 | /* |
8284 | * Initialize WME parameters; if they haven't been set by some other | |
8285 | * mechanism (IOVar, etc) then read them from the hardware. | |
8286 | */ | |
8287 | if (GFIELD(wlc->wme_retries[0], EDCF_SHORT) == 0) { | |
8288 | /* Uninitialized; read from HW */ | |
8289 | int ac; | |
8290 | ||
b7eec423 | 8291 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
94bdc2a2 AB |
8292 | wlc->wme_retries[ac] = |
8293 | brcms_b_read_shm(wlc->hw, M_AC_TXLMT_ADDR(ac)); | |
8294 | } | |
5b435de0 AS |
8295 | } |
8296 | ||
94bdc2a2 AB |
8297 | /* |
8298 | * The common driver entry routine. Error codes should be unique | |
8299 | */ | |
8300 | struct brcms_c_info * | |
b63337a0 AS |
8301 | brcms_c_attach(struct brcms_info *wl, struct bcma_device *core, uint unit, |
8302 | bool piomode, uint *perr) | |
5b435de0 | 8303 | { |
94bdc2a2 AB |
8304 | struct brcms_c_info *wlc; |
8305 | uint err = 0; | |
8306 | uint i, j; | |
8307 | struct brcms_pub *pub; | |
5b435de0 | 8308 | |
94bdc2a2 | 8309 | /* allocate struct brcms_c_info state and its substructures */ |
b63337a0 | 8310 | wlc = (struct brcms_c_info *) brcms_c_attach_malloc(unit, &err, 0); |
94bdc2a2 AB |
8311 | if (wlc == NULL) |
8312 | goto fail; | |
8313 | wlc->wiphy = wl->wiphy; | |
8314 | pub = wlc->pub; | |
5b435de0 | 8315 | |
8ae74654 | 8316 | #if defined(DEBUG) |
94bdc2a2 AB |
8317 | wlc_info_dbg = wlc; |
8318 | #endif | |
5b435de0 | 8319 | |
94bdc2a2 AB |
8320 | wlc->band = wlc->bandstate[0]; |
8321 | wlc->core = wlc->corestate; | |
8322 | wlc->wl = wl; | |
8323 | pub->unit = unit; | |
8324 | pub->_piomode = piomode; | |
8325 | wlc->bandinit_pending = false; | |
5b435de0 | 8326 | |
94bdc2a2 AB |
8327 | /* populate struct brcms_c_info with default values */ |
8328 | brcms_c_info_init(wlc, unit); | |
5b435de0 | 8329 | |
94bdc2a2 AB |
8330 | /* update sta/ap related parameters */ |
8331 | brcms_c_ap_upd(wlc); | |
5b435de0 | 8332 | |
94bdc2a2 AB |
8333 | /* |
8334 | * low level attach steps(all hw accesses go | |
8335 | * inside, no more in rest of the attach) | |
8336 | */ | |
b63337a0 | 8337 | err = brcms_b_attach(wlc, core, unit, piomode); |
94bdc2a2 AB |
8338 | if (err) |
8339 | goto fail; | |
5b435de0 | 8340 | |
94bdc2a2 | 8341 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_PAM_OVR, OFF); |
5b435de0 | 8342 | |
94bdc2a2 | 8343 | pub->phy_11ncapable = BRCMS_PHY_11N_CAP(wlc->band); |
5b435de0 | 8344 | |
94bdc2a2 AB |
8345 | /* disable allowed duty cycle */ |
8346 | wlc->tx_duty_cycle_ofdm = 0; | |
8347 | wlc->tx_duty_cycle_cck = 0; | |
5b435de0 | 8348 | |
94bdc2a2 | 8349 | brcms_c_stf_phy_chain_calc(wlc); |
5b435de0 | 8350 | |
94bdc2a2 AB |
8351 | /* txchain 1: txant 0, txchain 2: txant 1 */ |
8352 | if (BRCMS_ISNPHY(wlc->band) && (wlc->stf->txstreams == 1)) | |
8353 | wlc->stf->txant = wlc->stf->hw_txchain - 1; | |
5b435de0 | 8354 | |
94bdc2a2 AB |
8355 | /* push to BMAC driver */ |
8356 | wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain, | |
8357 | wlc->stf->hw_rxchain); | |
5b435de0 | 8358 | |
94bdc2a2 AB |
8359 | /* pull up some info resulting from the low attach */ |
8360 | for (i = 0; i < NFIFO; i++) | |
8361 | wlc->core->txavail[i] = wlc->hw->txavail[i]; | |
5b435de0 | 8362 | |
94bdc2a2 AB |
8363 | memcpy(&wlc->perm_etheraddr, &wlc->hw->etheraddr, ETH_ALEN); |
8364 | memcpy(&pub->cur_etheraddr, &wlc->hw->etheraddr, ETH_ALEN); | |
5b435de0 | 8365 | |
94bdc2a2 AB |
8366 | for (j = 0; j < wlc->pub->_nbands; j++) { |
8367 | wlc->band = wlc->bandstate[j]; | |
5b435de0 | 8368 | |
94bdc2a2 AB |
8369 | if (!brcms_c_attach_stf_ant_init(wlc)) { |
8370 | err = 24; | |
8371 | goto fail; | |
8372 | } | |
5b435de0 | 8373 | |
94bdc2a2 AB |
8374 | /* default contention windows size limits */ |
8375 | wlc->band->CWmin = APHY_CWMIN; | |
8376 | wlc->band->CWmax = PHY_CWMAX; | |
5b435de0 | 8377 | |
94bdc2a2 AB |
8378 | /* init gmode value */ |
8379 | if (wlc->band->bandtype == BRCM_BAND_2G) { | |
8380 | wlc->band->gmode = GMODE_AUTO; | |
8381 | brcms_c_protection_upd(wlc, BRCMS_PROT_G_USER, | |
8382 | wlc->band->gmode); | |
8383 | } | |
5b435de0 | 8384 | |
94bdc2a2 AB |
8385 | /* init _n_enab supported mode */ |
8386 | if (BRCMS_PHY_11N_CAP(wlc->band)) { | |
8387 | pub->_n_enab = SUPPORT_11N; | |
8388 | brcms_c_protection_upd(wlc, BRCMS_PROT_N_USER, | |
8389 | ((pub->_n_enab == | |
8390 | SUPPORT_11N) ? WL_11N_2x2 : | |
8391 | WL_11N_3x3)); | |
8392 | } | |
5b435de0 | 8393 | |
94bdc2a2 AB |
8394 | /* init per-band default rateset, depend on band->gmode */ |
8395 | brcms_default_rateset(wlc, &wlc->band->defrateset); | |
5b435de0 | 8396 | |
94bdc2a2 AB |
8397 | /* fill in hw_rateset */ |
8398 | brcms_c_rateset_filter(&wlc->band->defrateset, | |
8399 | &wlc->band->hw_rateset, false, | |
8400 | BRCMS_RATES_CCK_OFDM, BRCMS_RATE_MASK, | |
8401 | (bool) (wlc->pub->_n_enab & SUPPORT_11N)); | |
5b435de0 | 8402 | } |
5b435de0 | 8403 | |
94bdc2a2 AB |
8404 | /* |
8405 | * update antenna config due to | |
8406 | * wlc->stf->txant/txchain/ant_rx_ovr change | |
8407 | */ | |
8408 | brcms_c_stf_phy_txant_upd(wlc); | |
5b435de0 | 8409 | |
94bdc2a2 AB |
8410 | /* attach each modules */ |
8411 | err = brcms_c_attach_module(wlc); | |
8412 | if (err != 0) | |
8413 | goto fail; | |
5b435de0 | 8414 | |
94bdc2a2 AB |
8415 | if (!brcms_c_timers_init(wlc, unit)) { |
8416 | wiphy_err(wl->wiphy, "wl%d: %s: init_timer failed\n", unit, | |
8417 | __func__); | |
8418 | err = 32; | |
8419 | goto fail; | |
8420 | } | |
5b435de0 | 8421 | |
94bdc2a2 AB |
8422 | /* depend on rateset, gmode */ |
8423 | wlc->cmi = brcms_c_channel_mgr_attach(wlc); | |
8424 | if (!wlc->cmi) { | |
8425 | wiphy_err(wl->wiphy, "wl%d: %s: channel_mgr_attach failed" | |
8426 | "\n", unit, __func__); | |
8427 | err = 33; | |
8428 | goto fail; | |
5b435de0 | 8429 | } |
5b435de0 | 8430 | |
94bdc2a2 AB |
8431 | /* init default when all parameters are ready, i.e. ->rateset */ |
8432 | brcms_c_bss_default_init(wlc); | |
5b435de0 | 8433 | |
94bdc2a2 AB |
8434 | /* |
8435 | * Complete the wlc default state initializations.. | |
8436 | */ | |
5b435de0 | 8437 | |
94bdc2a2 AB |
8438 | /* allocate our initial queue */ |
8439 | wlc->pkt_queue = brcms_c_txq_alloc(wlc); | |
8440 | if (wlc->pkt_queue == NULL) { | |
8441 | wiphy_err(wl->wiphy, "wl%d: %s: failed to malloc tx queue\n", | |
8442 | unit, __func__); | |
8443 | err = 100; | |
8444 | goto fail; | |
8445 | } | |
5b435de0 | 8446 | |
94bdc2a2 | 8447 | wlc->bsscfg->wlc = wlc; |
5b435de0 | 8448 | |
94bdc2a2 AB |
8449 | wlc->mimoft = FT_HT; |
8450 | wlc->mimo_40txbw = AUTO; | |
8451 | wlc->ofdm_40txbw = AUTO; | |
8452 | wlc->cck_40txbw = AUTO; | |
8453 | brcms_c_update_mimo_band_bwcap(wlc, BRCMS_N_BW_20IN2G_40IN5G); | |
5b435de0 | 8454 | |
94bdc2a2 AB |
8455 | /* Set default values of SGI */ |
8456 | if (BRCMS_SGI_CAP_PHY(wlc)) { | |
8457 | brcms_c_ht_update_sgi_rx(wlc, (BRCMS_N_SGI_20 | | |
8458 | BRCMS_N_SGI_40)); | |
8459 | } else if (BRCMS_ISSSLPNPHY(wlc->band)) { | |
8460 | brcms_c_ht_update_sgi_rx(wlc, (BRCMS_N_SGI_20 | | |
8461 | BRCMS_N_SGI_40)); | |
8462 | } else { | |
8463 | brcms_c_ht_update_sgi_rx(wlc, 0); | |
8464 | } | |
5b435de0 | 8465 | |
94bdc2a2 | 8466 | brcms_b_antsel_set(wlc->hw, wlc->asi->antsel_avail); |
5b435de0 | 8467 | |
94bdc2a2 AB |
8468 | if (perr) |
8469 | *perr = 0; | |
5b435de0 | 8470 | |
94bdc2a2 | 8471 | return wlc; |
5b435de0 | 8472 | |
94bdc2a2 AB |
8473 | fail: |
8474 | wiphy_err(wl->wiphy, "wl%d: %s: failed with err %d\n", | |
8475 | unit, __func__, err); | |
8476 | if (wlc) | |
8477 | brcms_c_detach(wlc); | |
8478 | ||
8479 | if (perr) | |
8480 | *perr = err; | |
8481 | return NULL; | |
5b435de0 | 8482 | } |