26eb69fd552a37f95af58bf9207f8f7cad399b04
[deliverable/linux.git] / drivers / staging / brcm80211 / brcmsmac / wlc_mac80211.c
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 #include <linux/kernel.h>
17 #include <linux/ctype.h>
18 #include <linux/etherdevice.h>
19 #include <net/mac80211.h>
20
21 #include <bcmdefs.h>
22 #include <bcmdevs.h>
23 #include <osl.h>
24 #include <bcmutils.h>
25 #include <bcmwifi.h>
26 #include <siutils.h>
27 #include <pcicfg.h>
28 #include <bcmsrom.h>
29 #include <wlioctl.h>
30 #include <sbhnddma.h>
31 #include <hnddma.h>
32 #include <hndpmu.h>
33
34 #include "d11.h"
35 #include "wlc_types.h"
36 #include "wlc_cfg.h"
37 #include "wlc_rate.h"
38 #include "wlc_scb.h"
39 #include "wlc_pub.h"
40 #include "wlc_key.h"
41 #include "wlc_bsscfg.h"
42 #include "phy/wlc_phy_hal.h"
43 #include "wlc_channel.h"
44 #include "wlc_mac80211.h"
45 #include "wlc_bmac.h"
46 #include "wlc_phy_hal.h"
47 #include "wlc_phy_shim.h"
48 #include "wlc_antsel.h"
49 #include "wlc_stf.h"
50 #include "wlc_ampdu.h"
51 #include "wl_export.h"
52 #include "wlc_alloc.h"
53 #include "wl_dbg.h"
54
55 /*
56 * Disable statistics counting for WME
57 */
58 #define WLCNTSET(a, b)
59 #define WLCNTINCR(a)
60 #define WLCNTADD(a, b)
61
62 /*
63 * WPA(2) definitions
64 */
65 #define RSN_CAP_4_REPLAY_CNTRS 2
66 #define RSN_CAP_16_REPLAY_CNTRS 3
67
68 #define WPA_CAP_4_REPLAY_CNTRS RSN_CAP_4_REPLAY_CNTRS
69 #define WPA_CAP_16_REPLAY_CNTRS RSN_CAP_16_REPLAY_CNTRS
70
71 /*
72 * Indication for txflowcontrol that all priority bits in
73 * TXQ_STOP_FOR_PRIOFC_MASK are to be considered.
74 */
75 #define ALLPRIO -1
76
77 /*
78 * buffer length needed for wlc_format_ssid
79 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
80 */
81 #define SSID_FMT_BUF_LEN ((4 * IEEE80211_MAX_SSID_LEN) + 1)
82
83 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
84 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
85
86 #ifndef WLC_MPC_MAX_DELAYCNT
87 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
88 #endif
89 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
90 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
91
92 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
93 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
94
95 /* Scale down delays to accommodate QT slow speed */
96 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
97 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
98
99 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
100
101 /*
102 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
103 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
104 * this low resolution driver tick can be used for maintenance tasks such as phy
105 * calibration and scb update
106 */
107
108 /* watchdog trigger mode: OSL timer or TBTT */
109 #define WLC_WATCHDOG_TBTT(wlc) \
110 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
111
112 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
113 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
114
115 #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
116 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
117
118 /* debug/trace */
119 uint wl_msg_level =
120 #if defined(BCMDBG)
121 WL_ERROR_VAL;
122 #else
123 0;
124 #endif /* BCMDBG */
125
126 /* Find basic rate for a given rate */
127 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
128 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
129 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
130
131 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
132
133 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
134
135 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
136
137 #define SCAN_IN_PROGRESS(x) 0
138
139 #define EPI_VERSION_NUM 0x054b0b00
140
141 #ifdef BCMDBG
142 /* pointer to most recently allocated wl/wlc */
143 static struct wlc_info *wlc_info_dbg = (struct wlc_info *) (NULL);
144 #endif
145
146 /* IOVar table */
147
148 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
149 * table and by the wlc_doiovar() function. No ordering is imposed:
150 * the table is keyed by name, and the function uses a switch.
151 */
152 enum {
153 IOV_MPC = 1,
154 IOV_RTSTHRESH,
155 IOV_QTXPOWER,
156 IOV_BCN_LI_BCN, /* Beacon listen interval in # of beacons */
157 IOV_LAST /* In case of a need to check max ID number */
158 };
159
160 const bcm_iovar_t wlc_iovars[] = {
161 {"mpc", IOV_MPC, (0), IOVT_BOOL, 0},
162 {"rtsthresh", IOV_RTSTHRESH, (IOVF_WHL), IOVT_UINT16, 0},
163 {"qtxpower", IOV_QTXPOWER, (IOVF_WHL), IOVT_UINT32, 0},
164 {"bcn_li_bcn", IOV_BCN_LI_BCN, (0), IOVT_UINT8, 0},
165 {NULL, 0, 0, 0, 0}
166 };
167
168 const u8 prio2fifo[NUMPRIO] = {
169 TX_AC_BE_FIFO, /* 0 BE AC_BE Best Effort */
170 TX_AC_BK_FIFO, /* 1 BK AC_BK Background */
171 TX_AC_BK_FIFO, /* 2 -- AC_BK Background */
172 TX_AC_BE_FIFO, /* 3 EE AC_BE Best Effort */
173 TX_AC_VI_FIFO, /* 4 CL AC_VI Video */
174 TX_AC_VI_FIFO, /* 5 VI AC_VI Video */
175 TX_AC_VO_FIFO, /* 6 VO AC_VO Voice */
176 TX_AC_VO_FIFO /* 7 NC AC_VO Voice */
177 };
178
179 /* precedences numbers for wlc queues. These are twice as may levels as
180 * 802.1D priorities.
181 * Odd numbers are used for HI priority traffic at same precedence levels
182 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
183 */
184 #define _WLC_PREC_NONE 0 /* None = - */
185 #define _WLC_PREC_BK 2 /* BK - Background */
186 #define _WLC_PREC_BE 4 /* BE - Best-effort */
187 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
188 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
189 #define _WLC_PREC_VI 10 /* Vi - Video */
190 #define _WLC_PREC_VO 12 /* Vo - Voice */
191 #define _WLC_PREC_NC 14 /* NC - Network Control */
192
193 /* 802.1D Priority to precedence queue mapping */
194 const u8 wlc_prio2prec_map[] = {
195 _WLC_PREC_BE, /* 0 BE - Best-effort */
196 _WLC_PREC_BK, /* 1 BK - Background */
197 _WLC_PREC_NONE, /* 2 None = - */
198 _WLC_PREC_EE, /* 3 EE - Excellent-effort */
199 _WLC_PREC_CL, /* 4 CL - Controlled Load */
200 _WLC_PREC_VI, /* 5 Vi - Video */
201 _WLC_PREC_VO, /* 6 Vo - Voice */
202 _WLC_PREC_NC, /* 7 NC - Network Control */
203 };
204
205 /* Sanity check for tx_prec_map and fifo synchup
206 * Either there are some packets pending for the fifo, else if fifo is empty then
207 * all the corresponding precmap bits should be set
208 */
209 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
210 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
211 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
212 (wlc)->fifo2prec_map[(fifo)]))
213
214 /* TX FIFO number to WME/802.1E Access Category */
215 const u8 wme_fifo2ac[] = { AC_BK, AC_BE, AC_VI, AC_VO, AC_BE, AC_BE };
216
217 /* WME/802.1E Access Category to TX FIFO number */
218 static const u8 wme_ac2fifo[] = { 1, 0, 2, 3 };
219
220 static bool in_send_q = false;
221
222 /* Shared memory location index for various AC params */
223 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
224
225 #ifdef BCMDBG
226 static const char *fifo_names[] = {
227 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
228 #else
229 static const char fifo_names[6][0];
230 #endif
231
232 static const u8 acbitmap2maxprio[] = {
233 PRIO_8021D_BE, PRIO_8021D_BE, PRIO_8021D_BK, PRIO_8021D_BK,
234 PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI,
235 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO,
236 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO
237 };
238
239 /* currently the best mechanism for determining SIFS is the band in use */
240 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
241
242 /* value for # replay counters currently supported */
243 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
244
245 /* local prototypes */
246 static u16 BCMFASTPATH wlc_d11hdrs_mac80211(struct wlc_info *wlc,
247 struct ieee80211_hw *hw,
248 struct sk_buff *p,
249 struct scb *scb, uint frag,
250 uint nfrags, uint queue,
251 uint next_frag_len,
252 wsec_key_t *key,
253 ratespec_t rspec_override);
254
255 static void wlc_ctrupd_cache(u16 cur_stat, u16 *macstat_snapshot, u32 *macstat);
256 static void wlc_bss_default_init(struct wlc_info *wlc);
257 static void wlc_ucode_mac_upd(struct wlc_info *wlc);
258 static ratespec_t mac80211_wlc_set_nrate(struct wlc_info *wlc,
259 struct wlcband *cur_band, u32 int_val);
260 static void wlc_tx_prec_map_init(struct wlc_info *wlc);
261 static void wlc_watchdog(void *arg);
262 static void wlc_watchdog_by_timer(void *arg);
263 static u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate);
264 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg);
265 static int wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val,
266 const bcm_iovar_t *vi);
267 static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc);
268
269 /* send and receive */
270 static struct wlc_txq_info *wlc_txq_alloc(struct wlc_info *wlc,
271 struct osl_info *osh);
272 static void wlc_txq_free(struct wlc_info *wlc, struct osl_info *osh,
273 struct wlc_txq_info *qi);
274 static void wlc_txflowcontrol_signal(struct wlc_info *wlc,
275 struct wlc_txq_info *qi,
276 bool on, int prio);
277 static void wlc_txflowcontrol_reset(struct wlc_info *wlc);
278 static u16 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec,
279 uint length);
280 static void wlc_compute_cck_plcp(ratespec_t rate, uint length, u8 *plcp);
281 static void wlc_compute_ofdm_plcp(ratespec_t rate, uint length, u8 *plcp);
282 static void wlc_compute_mimo_plcp(ratespec_t rate, uint length, u8 *plcp);
283 static u16 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate,
284 u8 preamble_type, uint next_frag_len);
285 static void wlc_recvctl(struct wlc_info *wlc, struct osl_info *osh,
286 d11rxhdr_t *rxh, struct sk_buff *p);
287 static uint wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t rate,
288 u8 preamble_type, uint dur);
289 static uint wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rate,
290 u8 preamble_type);
291 static uint wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rate,
292 u8 preamble_type);
293 /* interrupt, up/down, band */
294 static void wlc_setband(struct wlc_info *wlc, uint bandunit);
295 static chanspec_t wlc_init_chanspec(struct wlc_info *wlc);
296 static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec);
297 static void wlc_bsinit(struct wlc_info *wlc);
298 static int wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
299 bool writeToShm);
300 static void wlc_radio_hwdisable_upd(struct wlc_info *wlc);
301 static bool wlc_radio_monitor_start(struct wlc_info *wlc);
302 static void wlc_radio_timer(void *arg);
303 static void wlc_radio_enable(struct wlc_info *wlc);
304 static void wlc_radio_upd(struct wlc_info *wlc);
305
306 /* scan, association, BSS */
307 static uint wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rate,
308 u8 preamble_type);
309 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap);
310 static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val);
311 static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val);
312 static void wlc_war16165(struct wlc_info *wlc, bool tx);
313
314 static void wlc_wme_retries_write(struct wlc_info *wlc);
315 static bool wlc_attach_stf_ant_init(struct wlc_info *wlc);
316 static uint wlc_attach_module(struct wlc_info *wlc);
317 static void wlc_detach_module(struct wlc_info *wlc);
318 static void wlc_timers_deinit(struct wlc_info *wlc);
319 static void wlc_down_led_upd(struct wlc_info *wlc);
320 static uint wlc_down_del_timer(struct wlc_info *wlc);
321 static void wlc_ofdm_rateset_war(struct wlc_info *wlc);
322 static int _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
323 struct wlc_if *wlcif);
324
325 #if defined(BCMDBG)
326 void wlc_get_rcmta(struct wlc_info *wlc, int idx, u8 *addr)
327 {
328 d11regs_t *regs = wlc->regs;
329 u32 v32;
330 struct osl_info *osh;
331
332 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc), __func__);
333
334 osh = wlc->osh;
335
336 W_REG(osh, &regs->objaddr, (OBJADDR_RCMTA_SEL | (idx * 2)));
337 (void)R_REG(osh, &regs->objaddr);
338 v32 = R_REG(osh, &regs->objdata);
339 addr[0] = (u8) v32;
340 addr[1] = (u8) (v32 >> 8);
341 addr[2] = (u8) (v32 >> 16);
342 addr[3] = (u8) (v32 >> 24);
343 W_REG(osh, &regs->objaddr, (OBJADDR_RCMTA_SEL | ((idx * 2) + 1)));
344 (void)R_REG(osh, &regs->objaddr);
345 v32 = R_REG(osh, (volatile u16 *)&regs->objdata);
346 addr[4] = (u8) v32;
347 addr[5] = (u8) (v32 >> 8);
348 }
349 #endif /* defined(BCMDBG) */
350
351 /* keep the chip awake if needed */
352 bool wlc_stay_awake(struct wlc_info *wlc)
353 {
354 return true;
355 }
356
357 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
358 */
359 bool wlc_ps_allowed(struct wlc_info *wlc)
360 {
361 int idx;
362 wlc_bsscfg_t *cfg;
363
364 /* disallow PS when one of the following global conditions meets */
365 if (!wlc->pub->associated || !wlc->PMenabled || wlc->PM_override)
366 return false;
367
368 /* disallow PS when one of these meets when not scanning */
369 if (!wlc->PMblocked) {
370 if (AP_ACTIVE(wlc) || wlc->monitor)
371 return false;
372 }
373
374 FOREACH_AS_STA(wlc, idx, cfg) {
375 /* disallow PS when one of the following bsscfg specific conditions meets */
376 if (!cfg->BSS || !WLC_PORTOPEN(cfg))
377 return false;
378
379 if (!cfg->dtim_programmed)
380 return false;
381 }
382
383 return true;
384 }
385
386 void wlc_reset(struct wlc_info *wlc)
387 {
388 WL_TRACE("wl%d: wlc_reset\n", wlc->pub->unit);
389
390 wlc->check_for_unaligned_tbtt = false;
391
392 /* slurp up hw mac counters before core reset */
393 wlc_statsupd(wlc);
394
395 /* reset our snapshot of macstat counters */
396 memset((char *)wlc->core->macstat_snapshot, 0,
397 sizeof(macstat_t));
398
399 wlc_bmac_reset(wlc->hw);
400 wlc_ampdu_reset(wlc->ampdu);
401 wlc->txretried = 0;
402
403 }
404
405 void wlc_fatal_error(struct wlc_info *wlc)
406 {
407 WL_ERROR("wl%d: fatal error, reinitializing\n", wlc->pub->unit);
408 wl_init(wlc->wl);
409 }
410
411 /* Return the channel the driver should initialize during wlc_init.
412 * the channel may have to be changed from the currently configured channel
413 * if other configurations are in conflict (bandlocked, 11n mode disabled,
414 * invalid channel for current country, etc.)
415 */
416 static chanspec_t wlc_init_chanspec(struct wlc_info *wlc)
417 {
418 chanspec_t chanspec =
419 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE |
420 WL_CHANSPEC_BAND_2G;
421
422 /* make sure the channel is on the supported band if we are band-restricted */
423 if (wlc->bandlocked || NBANDS(wlc) == 1) {
424 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
425 }
426 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
427 return chanspec;
428 }
429
430 struct scb global_scb;
431
432 static void wlc_init_scb(struct wlc_info *wlc, struct scb *scb)
433 {
434 int i;
435 scb->flags = SCB_WMECAP | SCB_HTCAP;
436 for (i = 0; i < NUMPRIO; i++)
437 scb->seqnum[i] = 0;
438 }
439
440 void wlc_init(struct wlc_info *wlc)
441 {
442 d11regs_t *regs;
443 chanspec_t chanspec;
444 int i;
445 wlc_bsscfg_t *bsscfg;
446 bool mute = false;
447
448 WL_TRACE("wl%d: wlc_init\n", wlc->pub->unit);
449
450 regs = wlc->regs;
451
452 /* This will happen if a big-hammer was executed. In that case, we want to go back
453 * to the channel that we were on and not new channel
454 */
455 if (wlc->pub->associated)
456 chanspec = wlc->home_chanspec;
457 else
458 chanspec = wlc_init_chanspec(wlc);
459
460 wlc_bmac_init(wlc->hw, chanspec, mute);
461
462 wlc->seckeys = wlc_bmac_read_shm(wlc->hw, M_SECRXKEYS_PTR) * 2;
463 if (wlc->machwcap & MCAP_TKIPMIC)
464 wlc->tkmickeys =
465 wlc_bmac_read_shm(wlc->hw, M_TKMICKEYS_PTR) * 2;
466
467 /* update beacon listen interval */
468 wlc_bcn_li_upd(wlc);
469 wlc->bcn_wait_prd =
470 (u8) (wlc_bmac_read_shm(wlc->hw, M_NOSLPZNATDTIM) >> 10);
471 ASSERT(wlc->bcn_wait_prd > 0);
472
473 /* the world is new again, so is our reported rate */
474 wlc_reprate_init(wlc);
475
476 /* write ethernet address to core */
477 FOREACH_BSS(wlc, i, bsscfg) {
478 wlc_set_mac(bsscfg);
479 wlc_set_bssid(bsscfg);
480 }
481
482 /* Update tsf_cfprep if associated and up */
483 if (wlc->pub->associated) {
484 FOREACH_BSS(wlc, i, bsscfg) {
485 if (bsscfg->up) {
486 u32 bi;
487
488 /* get beacon period from bsscfg and convert to uS */
489 bi = bsscfg->current_bss->beacon_period << 10;
490 /* update the tsf_cfprep register */
491 /* since init path would reset to default value */
492 W_REG(wlc->osh, &regs->tsf_cfprep,
493 (bi << CFPREP_CBI_SHIFT));
494
495 /* Update maccontrol PM related bits */
496 wlc_set_ps_ctrl(wlc);
497
498 break;
499 }
500 }
501 }
502
503 wlc_key_hw_init_all(wlc);
504
505 wlc_bandinit_ordered(wlc, chanspec);
506
507 wlc_init_scb(wlc, &global_scb);
508
509 /* init probe response timeout */
510 wlc_write_shm(wlc, M_PRS_MAXTIME, wlc->prb_resp_timeout);
511
512 /* init max burst txop (framebursting) */
513 wlc_write_shm(wlc, M_MBURST_TXOP,
514 (wlc->
515 _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP));
516
517 /* initialize maximum allowed duty cycle */
518 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, true, true);
519 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, false, true);
520
521 /* Update some shared memory locations related to max AMPDU size allowed to received */
522 wlc_ampdu_shm_upd(wlc->ampdu);
523
524 /* band-specific inits */
525 wlc_bsinit(wlc);
526
527 /* Enable EDCF mode (while the MAC is suspended) */
528 if (EDCF_ENAB(wlc->pub)) {
529 OR_REG(wlc->osh, &regs->ifs_ctl, IFS_USEEDCF);
530 wlc_edcf_setparams(wlc->cfg, false);
531 }
532
533 /* Init precedence maps for empty FIFOs */
534 wlc_tx_prec_map_init(wlc);
535
536 /* read the ucode version if we have not yet done so */
537 if (wlc->ucode_rev == 0) {
538 wlc->ucode_rev =
539 wlc_read_shm(wlc, M_BOM_REV_MAJOR) << NBITS(u16);
540 wlc->ucode_rev |= wlc_read_shm(wlc, M_BOM_REV_MINOR);
541 }
542
543 /* ..now really unleash hell (allow the MAC out of suspend) */
544 wlc_enable_mac(wlc);
545
546 /* clear tx flow control */
547 wlc_txflowcontrol_reset(wlc);
548
549 /* clear tx data fifo suspends */
550 wlc->tx_suspended = false;
551
552 /* enable the RF Disable Delay timer */
553 W_REG(wlc->osh, &wlc->regs->rfdisabledly, RFDISABLE_DEFAULT);
554
555 /* initialize mpc delay */
556 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
557
558 /*
559 * Initialize WME parameters; if they haven't been set by some other
560 * mechanism (IOVar, etc) then read them from the hardware.
561 */
562 if (WLC_WME_RETRY_SHORT_GET(wlc, 0) == 0) { /* Uninitialized; read from HW */
563 int ac;
564
565 ASSERT(wlc->clk);
566 for (ac = 0; ac < AC_COUNT; ac++) {
567 wlc->wme_retries[ac] =
568 wlc_read_shm(wlc, M_AC_TXLMT_ADDR(ac));
569 }
570 }
571 }
572
573 void wlc_mac_bcn_promisc_change(struct wlc_info *wlc, bool promisc)
574 {
575 wlc->bcnmisc_monitor = promisc;
576 wlc_mac_bcn_promisc(wlc);
577 }
578
579 void wlc_mac_bcn_promisc(struct wlc_info *wlc)
580 {
581 if ((AP_ENAB(wlc->pub) && (N_ENAB(wlc->pub) || wlc->band->gmode)) ||
582 wlc->bcnmisc_ibss || wlc->bcnmisc_scan || wlc->bcnmisc_monitor)
583 wlc_mctrl(wlc, MCTL_BCNS_PROMISC, MCTL_BCNS_PROMISC);
584 else
585 wlc_mctrl(wlc, MCTL_BCNS_PROMISC, 0);
586 }
587
588 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
589 void wlc_mac_promisc(struct wlc_info *wlc)
590 {
591 u32 promisc_bits = 0;
592
593 /* promiscuous mode just sets MCTL_PROMISC
594 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
595 * since all BSS data traffic is directed at the AP
596 */
597 if (PROMISC_ENAB(wlc->pub) && !AP_ENAB(wlc->pub) && !wlc->wet)
598 promisc_bits |= MCTL_PROMISC;
599
600 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
601 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
602 * handled in wlc_mac_bcn_promisc()
603 */
604 if (MONITOR_ENAB(wlc))
605 promisc_bits |= MCTL_PROMISC | MCTL_KEEPCONTROL;
606
607 wlc_mctrl(wlc, MCTL_PROMISC | MCTL_KEEPCONTROL, promisc_bits);
608 }
609
610 /* check if hps and wake states of sw and hw are in sync */
611 bool wlc_ps_check(struct wlc_info *wlc)
612 {
613 bool res = true;
614 bool hps, wake;
615 bool wake_ok;
616
617 if (!AP_ACTIVE(wlc)) {
618 volatile u32 tmp;
619 tmp = R_REG(wlc->osh, &wlc->regs->maccontrol);
620
621 /* If deviceremoved is detected, then don't take any action as this can be called
622 * in any context. Assume that caller will take care of the condition. This is just
623 * to avoid assert
624 */
625 if (tmp == 0xffffffff) {
626 WL_ERROR("wl%d: %s: dead chip\n",
627 wlc->pub->unit, __func__);
628 return DEVICEREMOVED(wlc);
629 }
630
631 hps = PS_ALLOWED(wlc);
632
633 if (hps != ((tmp & MCTL_HPS) != 0)) {
634 int idx;
635 wlc_bsscfg_t *cfg;
636 WL_ERROR("wl%d: hps not sync, sw %d, maccontrol 0x%x\n",
637 wlc->pub->unit, hps, tmp);
638 FOREACH_BSS(wlc, idx, cfg) {
639 if (!BSSCFG_STA(cfg))
640 continue;
641 }
642
643 res = false;
644 }
645 /* For a monolithic build the wake check can be exact since it looks at wake
646 * override bits. The MCTL_WAKE bit should match the 'wake' value.
647 */
648 wake = STAY_AWAKE(wlc) || wlc->hw->wake_override;
649 wake_ok = (wake == ((tmp & MCTL_WAKE) != 0));
650 if (hps && !wake_ok) {
651 WL_ERROR("wl%d: wake not sync, sw %d maccontrol 0x%x\n",
652 wlc->pub->unit, wake, tmp);
653 res = false;
654 }
655 }
656 ASSERT(res);
657 return res;
658 }
659
660 /* push sw hps and wake state through hardware */
661 void wlc_set_ps_ctrl(struct wlc_info *wlc)
662 {
663 u32 v1, v2;
664 bool hps, wake;
665 bool awake_before;
666
667 hps = PS_ALLOWED(wlc);
668 wake = hps ? (STAY_AWAKE(wlc)) : true;
669
670 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
671 wlc->pub->unit, hps, wake);
672
673 v1 = R_REG(wlc->osh, &wlc->regs->maccontrol);
674 v2 = 0;
675 if (hps)
676 v2 |= MCTL_HPS;
677 if (wake)
678 v2 |= MCTL_WAKE;
679
680 wlc_mctrl(wlc, MCTL_WAKE | MCTL_HPS, v2);
681
682 awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0));
683
684 if (wake && !awake_before)
685 wlc_bmac_wait_for_wake(wlc->hw);
686
687 }
688
689 /*
690 * Write this BSS config's MAC address to core.
691 * Updates RXE match engine.
692 */
693 int wlc_set_mac(wlc_bsscfg_t *cfg)
694 {
695 int err = 0;
696 struct wlc_info *wlc = cfg->wlc;
697
698 if (cfg == wlc->cfg) {
699 /* enter the MAC addr into the RXE match registers */
700 wlc_set_addrmatch(wlc, RCM_MAC_OFFSET, cfg->cur_etheraddr);
701 }
702
703 wlc_ampdu_macaddr_upd(wlc);
704
705 return err;
706 }
707
708 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
709 * Updates RXE match engine.
710 */
711 void wlc_set_bssid(wlc_bsscfg_t *cfg)
712 {
713 struct wlc_info *wlc = cfg->wlc;
714
715 /* if primary config, we need to update BSSID in RXE match registers */
716 if (cfg == wlc->cfg) {
717 wlc_set_addrmatch(wlc, RCM_BSSID_OFFSET, cfg->BSSID);
718 }
719 #ifdef SUPPORT_HWKEYS
720 else if (BSSCFG_STA(cfg) && cfg->BSS) {
721 wlc_rcmta_add_bssid(wlc, cfg);
722 }
723 #endif
724 }
725
726 /*
727 * Suspend the the MAC and update the slot timing
728 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
729 */
730 void wlc_switch_shortslot(struct wlc_info *wlc, bool shortslot)
731 {
732 int idx;
733 wlc_bsscfg_t *cfg;
734
735 ASSERT(wlc->band->gmode);
736
737 /* use the override if it is set */
738 if (wlc->shortslot_override != WLC_SHORTSLOT_AUTO)
739 shortslot = (wlc->shortslot_override == WLC_SHORTSLOT_ON);
740
741 if (wlc->shortslot == shortslot)
742 return;
743
744 wlc->shortslot = shortslot;
745
746 /* update the capability based on current shortslot mode */
747 FOREACH_BSS(wlc, idx, cfg) {
748 if (!cfg->associated)
749 continue;
750 cfg->current_bss->capability &=
751 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
752 if (wlc->shortslot)
753 cfg->current_bss->capability |=
754 WLAN_CAPABILITY_SHORT_SLOT_TIME;
755 }
756
757 wlc_bmac_set_shortslot(wlc->hw, shortslot);
758 }
759
760 static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc)
761 {
762 u8 local;
763 s16 local_max;
764
765 local = WLC_TXPWR_MAX;
766 if (wlc->pub->associated &&
767 (wf_chspec_ctlchan(wlc->chanspec) ==
768 wf_chspec_ctlchan(wlc->home_chanspec))) {
769
770 /* get the local power constraint if we are on the AP's
771 * channel [802.11h, 7.3.2.13]
772 */
773 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
774 local_max =
775 (wlc->txpwr_local_max -
776 wlc->txpwr_local_constraint) * WLC_TXPWR_DB_FACTOR;
777 if (local_max > 0 && local_max < WLC_TXPWR_MAX)
778 return (u8) local_max;
779 if (local_max < 0)
780 return 0;
781 }
782
783 return local;
784 }
785
786 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
787 void wlc_set_home_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
788 {
789 if (wlc->home_chanspec != chanspec) {
790 int idx;
791 wlc_bsscfg_t *cfg;
792
793 wlc->home_chanspec = chanspec;
794
795 FOREACH_BSS(wlc, idx, cfg) {
796 if (!cfg->associated)
797 continue;
798
799 cfg->current_bss->chanspec = chanspec;
800 }
801
802 }
803 }
804
805 static void wlc_set_phy_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
806 {
807 /* Save our copy of the chanspec */
808 wlc->chanspec = chanspec;
809
810 /* Set the chanspec and power limits for this locale after computing
811 * any 11h local tx power constraints.
812 */
813 wlc_channel_set_chanspec(wlc->cmi, chanspec,
814 wlc_local_constraint_qdbm(wlc));
815
816 if (wlc->stf->ss_algosel_auto)
817 wlc_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel,
818 chanspec);
819
820 wlc_stf_ss_update(wlc, wlc->band);
821
822 }
823
824 void wlc_set_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
825 {
826 uint bandunit;
827 bool switchband = false;
828 chanspec_t old_chanspec = wlc->chanspec;
829
830 if (!wlc_valid_chanspec_db(wlc->cmi, chanspec)) {
831 WL_ERROR("wl%d: %s: Bad channel %d\n",
832 wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec));
833 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
834 return;
835 }
836
837 /* Switch bands if necessary */
838 if (NBANDS(wlc) > 1) {
839 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
840 if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) {
841 switchband = true;
842 if (wlc->bandlocked) {
843 WL_ERROR("wl%d: %s: chspec %d band is locked!\n",
844 wlc->pub->unit, __func__,
845 CHSPEC_CHANNEL(chanspec));
846 return;
847 }
848 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
849 * if the setband updates (wlc_bsinit) use low level calls to inspect and
850 * set state, the state inspected may be from the wrong band, or the
851 * following wlc_bmac_set_chanspec() may undo the work.
852 */
853 wlc_setband(wlc, bandunit);
854 }
855 }
856
857 ASSERT(N_ENAB(wlc->pub) || !CHSPEC_IS40(chanspec));
858
859 /* sync up phy/radio chanspec */
860 wlc_set_phy_chanspec(wlc, chanspec);
861
862 /* init antenna selection */
863 if (CHSPEC_WLC_BW(old_chanspec) != CHSPEC_WLC_BW(chanspec)) {
864 wlc_antsel_init(wlc->asi);
865
866 /* Fix the hardware rateset based on bw.
867 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
868 */
869 wlc_rateset_bw_mcs_filter(&wlc->band->hw_rateset,
870 wlc->band->
871 mimo_cap_40 ? CHSPEC_WLC_BW(chanspec)
872 : 0);
873 }
874
875 /* update some mac configuration since chanspec changed */
876 wlc_ucode_mac_upd(wlc);
877 }
878
879 #if defined(BCMDBG)
880 static int wlc_get_current_txpwr(struct wlc_info *wlc, void *pwr, uint len)
881 {
882 txpwr_limits_t txpwr;
883 tx_power_t power;
884 tx_power_legacy_t *old_power = NULL;
885 int r, c;
886 uint qdbm;
887 bool override;
888
889 if (len == sizeof(tx_power_legacy_t))
890 old_power = (tx_power_legacy_t *) pwr;
891 else if (len < sizeof(tx_power_t))
892 return BCME_BUFTOOSHORT;
893
894 memset(&power, 0, sizeof(tx_power_t));
895
896 power.chanspec = WLC_BAND_PI_RADIO_CHANSPEC;
897 if (wlc->pub->associated)
898 power.local_chanspec = wlc->home_chanspec;
899
900 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
901 * public interface only implements getting and setting a single value for all of
902 * rates, so we need to fill the array ourselves.
903 */
904 wlc_phy_txpower_get(wlc->band->pi, &qdbm, &override);
905 for (r = 0; r < WL_TX_POWER_RATES; r++) {
906 power.user_limit[r] = (u8) qdbm;
907 }
908
909 power.local_max = wlc->txpwr_local_max * WLC_TXPWR_DB_FACTOR;
910 power.local_constraint =
911 wlc->txpwr_local_constraint * WLC_TXPWR_DB_FACTOR;
912
913 power.antgain[0] = wlc->bandstate[BAND_2G_INDEX]->antgain;
914 power.antgain[1] = wlc->bandstate[BAND_5G_INDEX]->antgain;
915
916 wlc_channel_reg_limits(wlc->cmi, power.chanspec, &txpwr);
917
918 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
919 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
920 #endif
921
922 /* CCK tx power limits */
923 for (c = 0, r = WL_TX_POWER_CCK_FIRST; c < WL_TX_POWER_CCK_NUM;
924 c++, r++)
925 power.reg_limit[r] = txpwr.cck[c];
926
927 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
928 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
929 #endif
930
931 /* 20 MHz OFDM SISO tx power limits */
932 for (c = 0, r = WL_TX_POWER_OFDM_FIRST; c < WL_TX_POWER_OFDM_NUM;
933 c++, r++)
934 power.reg_limit[r] = txpwr.ofdm[c];
935
936 if (WLC_PHY_11N_CAP(wlc->band)) {
937
938 /* 20 MHz OFDM CDD tx power limits */
939 for (c = 0, r = WL_TX_POWER_OFDM20_CDD_FIRST;
940 c < WL_TX_POWER_OFDM_NUM; c++, r++)
941 power.reg_limit[r] = txpwr.ofdm_cdd[c];
942
943 /* 40 MHz OFDM SISO tx power limits */
944 for (c = 0, r = WL_TX_POWER_OFDM40_SISO_FIRST;
945 c < WL_TX_POWER_OFDM_NUM; c++, r++)
946 power.reg_limit[r] = txpwr.ofdm_40_siso[c];
947
948 /* 40 MHz OFDM CDD tx power limits */
949 for (c = 0, r = WL_TX_POWER_OFDM40_CDD_FIRST;
950 c < WL_TX_POWER_OFDM_NUM; c++, r++)
951 power.reg_limit[r] = txpwr.ofdm_40_cdd[c];
952
953 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
954 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
955 #endif
956
957 /* 20MHz MCS0-7 SISO tx power limits */
958 for (c = 0, r = WL_TX_POWER_MCS20_SISO_FIRST;
959 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
960 power.reg_limit[r] = txpwr.mcs_20_siso[c];
961
962 /* 20MHz MCS0-7 CDD tx power limits */
963 for (c = 0, r = WL_TX_POWER_MCS20_CDD_FIRST;
964 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
965 power.reg_limit[r] = txpwr.mcs_20_cdd[c];
966
967 /* 20MHz MCS0-7 STBC tx power limits */
968 for (c = 0, r = WL_TX_POWER_MCS20_STBC_FIRST;
969 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
970 power.reg_limit[r] = txpwr.mcs_20_stbc[c];
971
972 /* 40MHz MCS0-7 SISO tx power limits */
973 for (c = 0, r = WL_TX_POWER_MCS40_SISO_FIRST;
974 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
975 power.reg_limit[r] = txpwr.mcs_40_siso[c];
976
977 /* 40MHz MCS0-7 CDD tx power limits */
978 for (c = 0, r = WL_TX_POWER_MCS40_CDD_FIRST;
979 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
980 power.reg_limit[r] = txpwr.mcs_40_cdd[c];
981
982 /* 40MHz MCS0-7 STBC tx power limits */
983 for (c = 0, r = WL_TX_POWER_MCS40_STBC_FIRST;
984 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
985 power.reg_limit[r] = txpwr.mcs_40_stbc[c];
986
987 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
988 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
989 #endif
990
991 /* 20MHz MCS8-15 SDM tx power limits */
992 for (c = 0, r = WL_TX_POWER_MCS20_SDM_FIRST;
993 c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++)
994 power.reg_limit[r] = txpwr.mcs_20_mimo[c];
995
996 /* 40MHz MCS8-15 SDM tx power limits */
997 for (c = 0, r = WL_TX_POWER_MCS40_SDM_FIRST;
998 c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++)
999 power.reg_limit[r] = txpwr.mcs_40_mimo[c];
1000
1001 /* MCS 32 */
1002 power.reg_limit[WL_TX_POWER_MCS_32] = txpwr.mcs32;
1003 }
1004
1005 wlc_phy_txpower_get_current(wlc->band->pi, &power,
1006 CHSPEC_CHANNEL(power.chanspec));
1007
1008 /* copy the tx_power_t struct to the return buffer,
1009 * or convert to a tx_power_legacy_t struct
1010 */
1011 if (!old_power) {
1012 memcpy(pwr, &power, sizeof(tx_power_t));
1013 } else {
1014 int band_idx = CHSPEC_IS2G(power.chanspec) ? 0 : 1;
1015
1016 memset(old_power, 0, sizeof(tx_power_legacy_t));
1017
1018 old_power->txpwr_local_max = power.local_max;
1019 old_power->txpwr_local_constraint = power.local_constraint;
1020 if (CHSPEC_IS2G(power.chanspec)) {
1021 old_power->txpwr_chan_reg_max = txpwr.cck[0];
1022 old_power->txpwr_est_Pout[band_idx] =
1023 power.est_Pout_cck;
1024 old_power->txpwr_est_Pout_gofdm = power.est_Pout[0];
1025 } else {
1026 old_power->txpwr_chan_reg_max = txpwr.ofdm[0];
1027 old_power->txpwr_est_Pout[band_idx] = power.est_Pout[0];
1028 }
1029 old_power->txpwr_antgain[0] = power.antgain[0];
1030 old_power->txpwr_antgain[1] = power.antgain[1];
1031
1032 for (r = 0; r < NUM_PWRCTRL_RATES; r++) {
1033 old_power->txpwr_band_max[r] = power.user_limit[r];
1034 old_power->txpwr_limit[r] = power.reg_limit[r];
1035 old_power->txpwr_target[band_idx][r] = power.target[r];
1036 if (CHSPEC_IS2G(power.chanspec))
1037 old_power->txpwr_bphy_cck_max[r] =
1038 power.board_limit[r];
1039 else
1040 old_power->txpwr_aphy_max[r] =
1041 power.board_limit[r];
1042 }
1043 }
1044
1045 return 0;
1046 }
1047 #endif /* defined(BCMDBG) */
1048
1049 static u32 wlc_watchdog_backup_bi(struct wlc_info *wlc)
1050 {
1051 u32 bi;
1052 bi = 2 * wlc->cfg->current_bss->dtim_period *
1053 wlc->cfg->current_bss->beacon_period;
1054 if (wlc->bcn_li_dtim)
1055 bi *= wlc->bcn_li_dtim;
1056 else if (wlc->bcn_li_bcn)
1057 /* recalculate bi based on bcn_li_bcn */
1058 bi = 2 * wlc->bcn_li_bcn * wlc->cfg->current_bss->beacon_period;
1059
1060 if (bi < 2 * TIMER_INTERVAL_WATCHDOG)
1061 bi = 2 * TIMER_INTERVAL_WATCHDOG;
1062 return bi;
1063 }
1064
1065 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1066 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise.
1067 */
1068 void wlc_watchdog_upd(struct wlc_info *wlc, bool tbtt)
1069 {
1070 /* make sure changing watchdog driver is allowed */
1071 if (!wlc->pub->up || !wlc->pub->align_wd_tbtt)
1072 return;
1073 if (!tbtt && wlc->WDarmed) {
1074 wl_del_timer(wlc->wl, wlc->wdtimer);
1075 wlc->WDarmed = false;
1076 }
1077
1078 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1079 if (tbtt && wlc->WDarmed) {
1080 wl_del_timer(wlc->wl, wlc->wdtimer);
1081 wlc->WDarmed = false;
1082 wlc->WDlast = OSL_SYSUPTIME();
1083 }
1084 /* arm watchdog timer and drive the watchdog there */
1085 else if (!tbtt && !wlc->WDarmed) {
1086 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
1087 true);
1088 wlc->WDarmed = true;
1089 }
1090 if (tbtt && !wlc->WDarmed) {
1091 wl_add_timer(wlc->wl, wlc->wdtimer, wlc_watchdog_backup_bi(wlc),
1092 true);
1093 wlc->WDarmed = true;
1094 }
1095 }
1096
1097 ratespec_t wlc_lowest_basic_rspec(struct wlc_info *wlc, wlc_rateset_t *rs)
1098 {
1099 ratespec_t lowest_basic_rspec;
1100 uint i;
1101
1102 /* Use the lowest basic rate */
1103 lowest_basic_rspec = rs->rates[0] & RATE_MASK;
1104 for (i = 0; i < rs->count; i++) {
1105 if (rs->rates[i] & WLC_RATE_FLAG) {
1106 lowest_basic_rspec = rs->rates[i] & RATE_MASK;
1107 break;
1108 }
1109 }
1110 #if NCONF
1111 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1112 if (IS_OFDM(lowest_basic_rspec)) {
1113 lowest_basic_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
1114 }
1115 #endif
1116
1117 return lowest_basic_rspec;
1118 }
1119
1120 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1121 * setting as per this table:
1122 * ratespec CCK ant = wlc->stf->txant
1123 * OFDM ant = 3
1124 */
1125 void wlc_beacon_phytxctl_txant_upd(struct wlc_info *wlc, ratespec_t bcn_rspec)
1126 {
1127 u16 phyctl;
1128 u16 phytxant = wlc->stf->phytxant;
1129 u16 mask = PHY_TXC_ANT_MASK;
1130
1131 /* for non-siso rates or default setting, use the available chains */
1132 if (WLC_PHY_11N_CAP(wlc->band)) {
1133 phytxant = wlc_stf_phytxchain_sel(wlc, bcn_rspec);
1134 }
1135
1136 phyctl = wlc_read_shm(wlc, M_BCN_PCTLWD);
1137 phyctl = (phyctl & ~mask) | phytxant;
1138 wlc_write_shm(wlc, M_BCN_PCTLWD, phyctl);
1139 }
1140
1141 /* centralized protection config change function to simplify debugging, no consistency checking
1142 * this should be called only on changes to avoid overhead in periodic function
1143 */
1144 void wlc_protection_upd(struct wlc_info *wlc, uint idx, int val)
1145 {
1146 WL_TRACE("wlc_protection_upd: idx %d, val %d\n", idx, val);
1147
1148 switch (idx) {
1149 case WLC_PROT_G_SPEC:
1150 wlc->protection->_g = (bool) val;
1151 break;
1152 case WLC_PROT_G_OVR:
1153 wlc->protection->g_override = (s8) val;
1154 break;
1155 case WLC_PROT_G_USER:
1156 wlc->protection->gmode_user = (u8) val;
1157 break;
1158 case WLC_PROT_OVERLAP:
1159 wlc->protection->overlap = (s8) val;
1160 break;
1161 case WLC_PROT_N_USER:
1162 wlc->protection->nmode_user = (s8) val;
1163 break;
1164 case WLC_PROT_N_CFG:
1165 wlc->protection->n_cfg = (s8) val;
1166 break;
1167 case WLC_PROT_N_CFG_OVR:
1168 wlc->protection->n_cfg_override = (s8) val;
1169 break;
1170 case WLC_PROT_N_NONGF:
1171 wlc->protection->nongf = (bool) val;
1172 break;
1173 case WLC_PROT_N_NONGF_OVR:
1174 wlc->protection->nongf_override = (s8) val;
1175 break;
1176 case WLC_PROT_N_PAM_OVR:
1177 wlc->protection->n_pam_override = (s8) val;
1178 break;
1179 case WLC_PROT_N_OBSS:
1180 wlc->protection->n_obss = (bool) val;
1181 break;
1182
1183 default:
1184 ASSERT(0);
1185 break;
1186 }
1187
1188 }
1189
1190 static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val)
1191 {
1192 wlc->ht_cap.cap_info &= ~(IEEE80211_HT_CAP_SGI_20 |
1193 IEEE80211_HT_CAP_SGI_40);
1194 wlc->ht_cap.cap_info |= (val & WLC_N_SGI_20) ?
1195 IEEE80211_HT_CAP_SGI_20 : 0;
1196 wlc->ht_cap.cap_info |= (val & WLC_N_SGI_40) ?
1197 IEEE80211_HT_CAP_SGI_40 : 0;
1198
1199 if (wlc->pub->up) {
1200 wlc_update_beacon(wlc);
1201 wlc_update_probe_resp(wlc, true);
1202 }
1203 }
1204
1205 static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val)
1206 {
1207 wlc->stf->ldpc = val;
1208
1209 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_LDPC_CODING;
1210 if (wlc->stf->ldpc != OFF)
1211 wlc->ht_cap.cap_info |= IEEE80211_HT_CAP_LDPC_CODING;
1212
1213 if (wlc->pub->up) {
1214 wlc_update_beacon(wlc);
1215 wlc_update_probe_resp(wlc, true);
1216 wlc_phy_ldpc_override_set(wlc->band->pi, (val ? true : false));
1217 }
1218 }
1219
1220 /*
1221 * ucode, hwmac update
1222 * Channel dependent updates for ucode and hw
1223 */
1224 static void wlc_ucode_mac_upd(struct wlc_info *wlc)
1225 {
1226 /* enable or disable any active IBSSs depending on whether or not
1227 * we are on the home channel
1228 */
1229 if (wlc->home_chanspec == WLC_BAND_PI_RADIO_CHANSPEC) {
1230 if (wlc->pub->associated) {
1231 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1232 * I think that the ucode inits set up the bcn templates and shm values
1233 * with a bogus beacon. This should not be done in the inits. If ucode needs
1234 * to set up a beacon for testing, the test routines should write it down,
1235 * not expect the inits to populate a bogus beacon.
1236 */
1237 if (WLC_PHY_11N_CAP(wlc->band)) {
1238 wlc_write_shm(wlc, M_BCN_TXTSF_OFFSET,
1239 wlc->band->bcntsfoff);
1240 }
1241 }
1242 } else {
1243 /* disable an active IBSS if we are not on the home channel */
1244 }
1245
1246 /* update the various promisc bits */
1247 wlc_mac_bcn_promisc(wlc);
1248 wlc_mac_promisc(wlc);
1249 }
1250
1251 static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec)
1252 {
1253 wlc_rateset_t default_rateset;
1254 uint parkband;
1255 uint i, band_order[2];
1256
1257 WL_TRACE("wl%d: wlc_bandinit_ordered\n", wlc->pub->unit);
1258 /*
1259 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1260 * figure out the right band to park on
1261 */
1262 if (wlc->bandlocked || NBANDS(wlc) == 1) {
1263 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
1264
1265 parkband = wlc->band->bandunit; /* updated in wlc_bandlock() */
1266 band_order[0] = band_order[1] = parkband;
1267 } else {
1268 /* park on the band of the specified chanspec */
1269 parkband = CHSPEC_WLCBANDUNIT(chanspec);
1270
1271 /* order so that parkband initialize last */
1272 band_order[0] = parkband ^ 1;
1273 band_order[1] = parkband;
1274 }
1275
1276 /* make each band operational, software state init */
1277 for (i = 0; i < NBANDS(wlc); i++) {
1278 uint j = band_order[i];
1279
1280 wlc->band = wlc->bandstate[j];
1281
1282 wlc_default_rateset(wlc, &default_rateset);
1283
1284 /* fill in hw_rate */
1285 wlc_rateset_filter(&default_rateset, &wlc->band->hw_rateset,
1286 false, WLC_RATES_CCK_OFDM, RATE_MASK,
1287 (bool) N_ENAB(wlc->pub));
1288
1289 /* init basic rate lookup */
1290 wlc_rate_lookup_init(wlc, &default_rateset);
1291 }
1292
1293 /* sync up phy/radio chanspec */
1294 wlc_set_phy_chanspec(wlc, chanspec);
1295 }
1296
1297 /* band-specific init */
1298 static void WLBANDINITFN(wlc_bsinit) (struct wlc_info *wlc)
1299 {
1300 WL_TRACE("wl%d: wlc_bsinit: bandunit %d\n",
1301 wlc->pub->unit, wlc->band->bandunit);
1302
1303 /* write ucode ACK/CTS rate table */
1304 wlc_set_ratetable(wlc);
1305
1306 /* update some band specific mac configuration */
1307 wlc_ucode_mac_upd(wlc);
1308
1309 /* init antenna selection */
1310 wlc_antsel_init(wlc->asi);
1311
1312 }
1313
1314 /* switch to and initialize new band */
1315 static void WLBANDINITFN(wlc_setband) (struct wlc_info *wlc, uint bandunit)
1316 {
1317 int idx;
1318 wlc_bsscfg_t *cfg;
1319
1320 ASSERT(NBANDS(wlc) > 1);
1321 ASSERT(!wlc->bandlocked);
1322 ASSERT(bandunit != wlc->band->bandunit || wlc->bandinit_pending);
1323
1324 wlc->band = wlc->bandstate[bandunit];
1325
1326 if (!wlc->pub->up)
1327 return;
1328
1329 /* wait for at least one beacon before entering sleeping state */
1330 wlc->PMawakebcn = true;
1331 FOREACH_AS_STA(wlc, idx, cfg)
1332 cfg->PMawakebcn = true;
1333 wlc_set_ps_ctrl(wlc);
1334
1335 /* band-specific initializations */
1336 wlc_bsinit(wlc);
1337 }
1338
1339 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1340 void wlc_wme_initparams_sta(struct wlc_info *wlc, wme_param_ie_t *pe)
1341 {
1342 static const wme_param_ie_t stadef = {
1343 WME_OUI,
1344 WME_TYPE,
1345 WME_SUBTYPE_PARAM_IE,
1346 WME_VER,
1347 0,
1348 0,
1349 {
1350 {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA,
1351 cpu_to_le16(EDCF_AC_BE_TXOP_STA)},
1352 {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA,
1353 cpu_to_le16(EDCF_AC_BK_TXOP_STA)},
1354 {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA,
1355 cpu_to_le16(EDCF_AC_VI_TXOP_STA)},
1356 {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA,
1357 cpu_to_le16(EDCF_AC_VO_TXOP_STA)}
1358 }
1359 };
1360
1361 ASSERT(sizeof(*pe) == WME_PARAM_IE_LEN);
1362 memcpy(pe, &stadef, sizeof(*pe));
1363 }
1364
1365 void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, void *arg, bool suspend)
1366 {
1367 int i;
1368 shm_acparams_t acp_shm;
1369 u16 *shm_entry;
1370 struct ieee80211_tx_queue_params *params = arg;
1371
1372 ASSERT(wlc);
1373
1374 /* Only apply params if the core is out of reset and has clocks */
1375 if (!wlc->clk) {
1376 WL_ERROR("wl%d: %s : no-clock\n", wlc->pub->unit, __func__);
1377 return;
1378 }
1379
1380 /*
1381 * AP uses AC params from wme_param_ie_ap.
1382 * AP advertises AC params from wme_param_ie.
1383 * STA uses AC params from wme_param_ie.
1384 */
1385
1386 wlc->wme_admctl = 0;
1387
1388 do {
1389 memset((char *)&acp_shm, 0, sizeof(shm_acparams_t));
1390 /* find out which ac this set of params applies to */
1391 ASSERT(aci < AC_COUNT);
1392 /* set the admission control policy for this AC */
1393 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1394
1395 /* fill in shm ac params struct */
1396 acp_shm.txop = le16_to_cpu(params->txop);
1397 /* convert from units of 32us to us for ucode */
1398 wlc->edcf_txop[aci & 0x3] = acp_shm.txop =
1399 EDCF_TXOP2USEC(acp_shm.txop);
1400 acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK);
1401
1402 if (aci == AC_VI && acp_shm.txop == 0
1403 && acp_shm.aifs < EDCF_AIFSN_MAX)
1404 acp_shm.aifs++;
1405
1406 if (acp_shm.aifs < EDCF_AIFSN_MIN
1407 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1408 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1409 wlc->pub->unit, acp_shm.aifs);
1410 continue;
1411 }
1412
1413 acp_shm.cwmin = params->cw_min;
1414 acp_shm.cwmax = params->cw_max;
1415 acp_shm.cwcur = acp_shm.cwmin;
1416 acp_shm.bslots =
1417 R_REG(wlc->osh, &wlc->regs->tsf_random) & acp_shm.cwcur;
1418 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1419 /* Indicate the new params to the ucode */
1420 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1421 wme_shmemacindex(aci) *
1422 M_EDCF_QLEN +
1423 M_EDCF_STATUS_OFF));
1424 acp_shm.status |= WME_STATUS_NEWAC;
1425
1426 /* Fill in shm acparam table */
1427 shm_entry = (u16 *) &acp_shm;
1428 for (i = 0; i < (int)sizeof(shm_acparams_t); i += 2)
1429 wlc_write_shm(wlc,
1430 M_EDCF_QINFO +
1431 wme_shmemacindex(aci) * M_EDCF_QLEN + i,
1432 *shm_entry++);
1433
1434 } while (0);
1435
1436 if (suspend)
1437 wlc_suspend_mac_and_wait(wlc);
1438
1439 if (suspend)
1440 wlc_enable_mac(wlc);
1441
1442 }
1443
1444 void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend)
1445 {
1446 struct wlc_info *wlc = cfg->wlc;
1447 uint aci, i, j;
1448 edcf_acparam_t *edcf_acp;
1449 shm_acparams_t acp_shm;
1450 u16 *shm_entry;
1451
1452 ASSERT(cfg);
1453 ASSERT(wlc);
1454
1455 /* Only apply params if the core is out of reset and has clocks */
1456 if (!wlc->clk)
1457 return;
1458
1459 /*
1460 * AP uses AC params from wme_param_ie_ap.
1461 * AP advertises AC params from wme_param_ie.
1462 * STA uses AC params from wme_param_ie.
1463 */
1464
1465 edcf_acp = (edcf_acparam_t *) &wlc->wme_param_ie.acparam[0];
1466
1467 wlc->wme_admctl = 0;
1468
1469 for (i = 0; i < AC_COUNT; i++, edcf_acp++) {
1470 memset((char *)&acp_shm, 0, sizeof(shm_acparams_t));
1471 /* find out which ac this set of params applies to */
1472 aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT;
1473 ASSERT(aci < AC_COUNT);
1474 /* set the admission control policy for this AC */
1475 if (edcf_acp->ACI & EDCF_ACM_MASK) {
1476 wlc->wme_admctl |= 1 << aci;
1477 }
1478
1479 /* fill in shm ac params struct */
1480 acp_shm.txop = le16_to_cpu(edcf_acp->TXOP);
1481 /* convert from units of 32us to us for ucode */
1482 wlc->edcf_txop[aci] = acp_shm.txop =
1483 EDCF_TXOP2USEC(acp_shm.txop);
1484 acp_shm.aifs = (edcf_acp->ACI & EDCF_AIFSN_MASK);
1485
1486 if (aci == AC_VI && acp_shm.txop == 0
1487 && acp_shm.aifs < EDCF_AIFSN_MAX)
1488 acp_shm.aifs++;
1489
1490 if (acp_shm.aifs < EDCF_AIFSN_MIN
1491 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1492 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1493 wlc->pub->unit, acp_shm.aifs);
1494 continue;
1495 }
1496
1497 /* CWmin = 2^(ECWmin) - 1 */
1498 acp_shm.cwmin = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK);
1499 /* CWmax = 2^(ECWmax) - 1 */
1500 acp_shm.cwmax = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK)
1501 >> EDCF_ECWMAX_SHIFT);
1502 acp_shm.cwcur = acp_shm.cwmin;
1503 acp_shm.bslots =
1504 R_REG(wlc->osh, &wlc->regs->tsf_random) & acp_shm.cwcur;
1505 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1506 /* Indicate the new params to the ucode */
1507 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1508 wme_shmemacindex(aci) *
1509 M_EDCF_QLEN +
1510 M_EDCF_STATUS_OFF));
1511 acp_shm.status |= WME_STATUS_NEWAC;
1512
1513 /* Fill in shm acparam table */
1514 shm_entry = (u16 *) &acp_shm;
1515 for (j = 0; j < (int)sizeof(shm_acparams_t); j += 2)
1516 wlc_write_shm(wlc,
1517 M_EDCF_QINFO +
1518 wme_shmemacindex(aci) * M_EDCF_QLEN + j,
1519 *shm_entry++);
1520 }
1521
1522 if (suspend)
1523 wlc_suspend_mac_and_wait(wlc);
1524
1525 if (AP_ENAB(wlc->pub) && WME_ENAB(wlc->pub)) {
1526 wlc_update_beacon(wlc);
1527 wlc_update_probe_resp(wlc, false);
1528 }
1529
1530 if (suspend)
1531 wlc_enable_mac(wlc);
1532
1533 }
1534
1535 bool wlc_timers_init(struct wlc_info *wlc, int unit)
1536 {
1537 wlc->wdtimer = wl_init_timer(wlc->wl, wlc_watchdog_by_timer,
1538 wlc, "watchdog");
1539 if (!wlc->wdtimer) {
1540 WL_ERROR("wl%d: wl_init_timer for wdtimer failed\n", unit);
1541 goto fail;
1542 }
1543
1544 wlc->radio_timer = wl_init_timer(wlc->wl, wlc_radio_timer,
1545 wlc, "radio");
1546 if (!wlc->radio_timer) {
1547 WL_ERROR("wl%d: wl_init_timer for radio_timer failed\n", unit);
1548 goto fail;
1549 }
1550
1551 return true;
1552
1553 fail:
1554 return false;
1555 }
1556
1557 /*
1558 * Initialize wlc_info default values ...
1559 * may get overrides later in this function
1560 */
1561 void wlc_info_init(struct wlc_info *wlc, int unit)
1562 {
1563 int i;
1564 /* Assume the device is there until proven otherwise */
1565 wlc->device_present = true;
1566
1567 /* set default power output percentage to 100 percent */
1568 wlc->txpwr_percent = 100;
1569
1570 /* Save our copy of the chanspec */
1571 wlc->chanspec = CH20MHZ_CHSPEC(1);
1572
1573 /* initialize CCK preamble mode to unassociated state */
1574 wlc->shortpreamble = false;
1575
1576 wlc->legacy_probe = true;
1577
1578 /* various 802.11g modes */
1579 wlc->shortslot = false;
1580 wlc->shortslot_override = WLC_SHORTSLOT_AUTO;
1581
1582 wlc->barker_overlap_control = true;
1583 wlc->barker_preamble = WLC_BARKER_SHORT_ALLOWED;
1584 wlc->txburst_limit_override = AUTO;
1585
1586 wlc_protection_upd(wlc, WLC_PROT_G_OVR, WLC_PROTECTION_AUTO);
1587 wlc_protection_upd(wlc, WLC_PROT_G_SPEC, false);
1588
1589 wlc_protection_upd(wlc, WLC_PROT_N_CFG_OVR, WLC_PROTECTION_AUTO);
1590 wlc_protection_upd(wlc, WLC_PROT_N_CFG, WLC_N_PROTECTION_OFF);
1591 wlc_protection_upd(wlc, WLC_PROT_N_NONGF_OVR, WLC_PROTECTION_AUTO);
1592 wlc_protection_upd(wlc, WLC_PROT_N_NONGF, false);
1593 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR, AUTO);
1594
1595 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, WLC_PROTECTION_CTL_OVERLAP);
1596
1597 /* 802.11g draft 4.0 NonERP elt advertisement */
1598 wlc->include_legacy_erp = true;
1599
1600 wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF;
1601 wlc->stf->txant = ANT_TX_DEF;
1602
1603 wlc->prb_resp_timeout = WLC_PRB_RESP_TIMEOUT;
1604
1605 wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN;
1606 for (i = 0; i < NFIFO; i++)
1607 wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN;
1608 wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN;
1609
1610 /* default rate fallback retry limits */
1611 wlc->SFBL = RETRY_SHORT_FB;
1612 wlc->LFBL = RETRY_LONG_FB;
1613
1614 /* default mac retry limits */
1615 wlc->SRL = RETRY_SHORT_DEF;
1616 wlc->LRL = RETRY_LONG_DEF;
1617
1618 /* init PM state */
1619 wlc->PM = PM_OFF; /* User's setting of PM mode through IOCTL */
1620 wlc->PM_override = false; /* Prevents from going to PM if our AP is 'ill' */
1621 wlc->PMenabled = false; /* Current PM state */
1622 wlc->PMpending = false; /* Tracks whether STA indicated PM in the last attempt */
1623 wlc->PMblocked = false; /* To allow blocking going into PM during RM and scans */
1624
1625 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1626 wlc->WME_PM_blocked = false;
1627
1628 /* Init wme queuing method */
1629 wlc->wme_prec_queuing = false;
1630
1631 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1632 wlc->wake = false;
1633 /* Are we waiting for a response to PS-Poll that we sent */
1634 wlc->PSpoll = false;
1635
1636 /* APSD defaults */
1637 wlc->wme_apsd = true;
1638 wlc->apsd_sta_usp = false;
1639 wlc->apsd_trigger_timeout = 0; /* disable the trigger timer */
1640 wlc->apsd_trigger_ac = AC_BITMAP_ALL;
1641
1642 /* Set flag to indicate that hw keys should be used when available. */
1643 wlc->wsec_swkeys = false;
1644
1645 /* init the 4 static WEP default keys */
1646 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
1647 wlc->wsec_keys[i] = wlc->wsec_def_keys[i];
1648 wlc->wsec_keys[i]->idx = (u8) i;
1649 }
1650
1651 wlc->_regulatory_domain = false; /* 802.11d */
1652
1653 /* WME QoS mode is Auto by default */
1654 wlc->pub->_wme = AUTO;
1655
1656 #ifdef BCMSDIODEV_ENABLED
1657 wlc->pub->_priofc = true; /* enable priority flow control for sdio dongle */
1658 #endif
1659
1660 wlc->pub->_ampdu = AMPDU_AGG_HOST;
1661 wlc->pub->bcmerror = 0;
1662 wlc->ibss_allowed = true;
1663 wlc->ibss_coalesce_allowed = true;
1664 wlc->pub->_coex = ON;
1665
1666 /* initialize mpc delay */
1667 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
1668
1669 wlc->pr80838_war = true;
1670 }
1671
1672 static bool wlc_state_bmac_sync(struct wlc_info *wlc)
1673 {
1674 wlc_bmac_state_t state_bmac;
1675
1676 if (wlc_bmac_state_get(wlc->hw, &state_bmac) != 0)
1677 return false;
1678
1679 wlc->machwcap = state_bmac.machwcap;
1680 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR,
1681 (s8) state_bmac.preamble_ovr);
1682
1683 return true;
1684 }
1685
1686 static uint wlc_attach_module(struct wlc_info *wlc)
1687 {
1688 uint err = 0;
1689 uint unit;
1690 unit = wlc->pub->unit;
1691
1692 wlc->asi = wlc_antsel_attach(wlc, wlc->osh, wlc->pub, wlc->hw);
1693 if (wlc->asi == NULL) {
1694 WL_ERROR("wl%d: wlc_attach: wlc_antsel_attach failed\n", unit);
1695 err = 44;
1696 goto fail;
1697 }
1698
1699 wlc->ampdu = wlc_ampdu_attach(wlc);
1700 if (wlc->ampdu == NULL) {
1701 WL_ERROR("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit);
1702 err = 50;
1703 goto fail;
1704 }
1705
1706 if ((wlc_stf_attach(wlc) != 0)) {
1707 WL_ERROR("wl%d: wlc_attach: wlc_stf_attach failed\n", unit);
1708 err = 68;
1709 goto fail;
1710 }
1711 fail:
1712 return err;
1713 }
1714
1715 struct wlc_pub *wlc_pub(void *wlc)
1716 {
1717 return ((struct wlc_info *) wlc)->pub;
1718 }
1719
1720 #define CHIP_SUPPORTS_11N(wlc) 1
1721
1722 /*
1723 * The common driver entry routine. Error codes should be unique
1724 */
1725 void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1726 struct osl_info *osh, void *regsva, uint bustype,
1727 void *btparam, uint *perr)
1728 {
1729 struct wlc_info *wlc;
1730 uint err = 0;
1731 uint j;
1732 struct wlc_pub *pub;
1733 struct wlc_txq_info *qi;
1734 uint n_disabled;
1735
1736 WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
1737 unit, __func__, vendor, device);
1738
1739 ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS);
1740 ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS);
1741
1742 /* some code depends on packed structures */
1743 ASSERT(sizeof(struct ethhdr) == ETH_HLEN);
1744 ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE);
1745 ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN);
1746 ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN);
1747 ASSERT(sizeof(d11txh_t) == D11_TXH_LEN);
1748 ASSERT(sizeof(d11rxhdr_t) == RXHDR_LEN);
1749 ASSERT(sizeof(struct ieee80211_hdr) == DOT11_A4_HDR_LEN);
1750 ASSERT(sizeof(struct ieee80211_rts) == DOT11_RTS_LEN);
1751 ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN);
1752 ASSERT(sizeof(struct ieee80211_ht_cap) == HT_CAP_IE_LEN);
1753 #ifdef BRCM_FULLMAC
1754 ASSERT(offsetof(wl_scan_params_t, channel_list) ==
1755 WL_SCAN_PARAMS_FIXED_SIZE);
1756 #endif
1757 ASSERT(IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32)));
1758 ASSERT(ISPOWEROF2(MA_WINDOW_SZ));
1759
1760 ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
1761
1762 /*
1763 * Number of replay counters value used in WPA IE must match # rxivs
1764 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1765 * 'RSN Information Element' figure 8 for this mapping.
1766 */
1767 ASSERT((WPA_CAP_16_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1768 && 16 == WLC_NUMRXIVS)
1769 || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1770 && 4 == WLC_NUMRXIVS));
1771
1772 /* allocate struct wlc_info state and its substructures */
1773 wlc = (struct wlc_info *) wlc_attach_malloc(unit, &err, device);
1774 if (wlc == NULL)
1775 goto fail;
1776 wlc->osh = osh;
1777 pub = wlc->pub;
1778
1779 #if defined(BCMDBG)
1780 wlc_info_dbg = wlc;
1781 #endif
1782
1783 wlc->band = wlc->bandstate[0];
1784 wlc->core = wlc->corestate;
1785 wlc->wl = wl;
1786 pub->unit = unit;
1787 pub->osh = osh;
1788 wlc->btparam = btparam;
1789 pub->_piomode = piomode;
1790 wlc->bandinit_pending = false;
1791 /* By default restrict TKIP associations from 11n STA's */
1792 wlc->ht_wsec_restriction = WLC_HT_TKIP_RESTRICT;
1793
1794 /* populate struct wlc_info with default values */
1795 wlc_info_init(wlc, unit);
1796
1797 /* update sta/ap related parameters */
1798 wlc_ap_upd(wlc);
1799
1800 /* 11n_disable nvram */
1801 n_disabled = getintvar(pub->vars, "11n_disable");
1802
1803 /* register a module (to handle iovars) */
1804 wlc_module_register(wlc->pub, wlc_iovars, "wlc_iovars", wlc,
1805 wlc_doiovar, NULL, NULL);
1806
1807 /* low level attach steps(all hw accesses go inside, no more in rest of the attach) */
1808 err = wlc_bmac_attach(wlc, vendor, device, unit, piomode, osh, regsva,
1809 bustype, btparam);
1810 if (err)
1811 goto fail;
1812
1813 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1814 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1815 */
1816 if (!wlc_state_bmac_sync(wlc)) {
1817 err = 20;
1818 goto fail;
1819 }
1820
1821 pub->phy_11ncapable = WLC_PHY_11N_CAP(wlc->band);
1822
1823 /* propagate *vars* from BMAC driver to high driver */
1824 wlc_bmac_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size);
1825
1826
1827 /* set maximum allowed duty cycle */
1828 wlc->tx_duty_cycle_ofdm =
1829 (u16) getintvar(pub->vars, "tx_duty_cycle_ofdm");
1830 wlc->tx_duty_cycle_cck =
1831 (u16) getintvar(pub->vars, "tx_duty_cycle_cck");
1832
1833 wlc_stf_phy_chain_calc(wlc);
1834
1835 /* txchain 1: txant 0, txchain 2: txant 1 */
1836 if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
1837 wlc->stf->txant = wlc->stf->hw_txchain - 1;
1838
1839 /* push to BMAC driver */
1840 wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain,
1841 wlc->stf->hw_rxchain);
1842
1843 /* pull up some info resulting from the low attach */
1844 {
1845 int i;
1846 for (i = 0; i < NFIFO; i++)
1847 wlc->core->txavail[i] = wlc->hw->txavail[i];
1848 }
1849
1850 wlc_bmac_hw_etheraddr(wlc->hw, wlc->perm_etheraddr);
1851
1852 memcpy(&pub->cur_etheraddr, &wlc->perm_etheraddr, ETH_ALEN);
1853
1854 for (j = 0; j < NBANDS(wlc); j++) {
1855 /* Use band 1 for single band 11a */
1856 if (IS_SINGLEBAND_5G(wlc->deviceid))
1857 j = BAND_5G_INDEX;
1858
1859 wlc->band = wlc->bandstate[j];
1860
1861 if (!wlc_attach_stf_ant_init(wlc)) {
1862 err = 24;
1863 goto fail;
1864 }
1865
1866 /* default contention windows size limits */
1867 wlc->band->CWmin = APHY_CWMIN;
1868 wlc->band->CWmax = PHY_CWMAX;
1869
1870 /* init gmode value */
1871 if (BAND_2G(wlc->band->bandtype)) {
1872 wlc->band->gmode = GMODE_AUTO;
1873 wlc_protection_upd(wlc, WLC_PROT_G_USER,
1874 wlc->band->gmode);
1875 }
1876
1877 /* init _n_enab supported mode */
1878 if (WLC_PHY_11N_CAP(wlc->band) && CHIP_SUPPORTS_11N(wlc)) {
1879 if (n_disabled & WLFEATURE_DISABLE_11N) {
1880 pub->_n_enab = OFF;
1881 wlc_protection_upd(wlc, WLC_PROT_N_USER, OFF);
1882 } else {
1883 pub->_n_enab = SUPPORT_11N;
1884 wlc_protection_upd(wlc, WLC_PROT_N_USER,
1885 ((pub->_n_enab ==
1886 SUPPORT_11N) ? WL_11N_2x2 :
1887 WL_11N_3x3));
1888 }
1889 }
1890
1891 /* init per-band default rateset, depend on band->gmode */
1892 wlc_default_rateset(wlc, &wlc->band->defrateset);
1893
1894 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1895 wlc_rateset_filter(&wlc->band->defrateset,
1896 &wlc->band->hw_rateset, false,
1897 WLC_RATES_CCK_OFDM, RATE_MASK,
1898 (bool) N_ENAB(wlc->pub));
1899 }
1900
1901 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1902 wlc_stf_phy_txant_upd(wlc);
1903
1904 /* attach each modules */
1905 err = wlc_attach_module(wlc);
1906 if (err != 0)
1907 goto fail;
1908
1909 if (!wlc_timers_init(wlc, unit)) {
1910 WL_ERROR("wl%d: %s: wlc_init_timer failed\n", unit, __func__);
1911 err = 32;
1912 goto fail;
1913 }
1914
1915 /* depend on rateset, gmode */
1916 wlc->cmi = wlc_channel_mgr_attach(wlc);
1917 if (!wlc->cmi) {
1918 WL_ERROR("wl%d: %s: wlc_channel_mgr_attach failed\n",
1919 unit, __func__);
1920 err = 33;
1921 goto fail;
1922 }
1923
1924 /* init default when all parameters are ready, i.e. ->rateset */
1925 wlc_bss_default_init(wlc);
1926
1927 /*
1928 * Complete the wlc default state initializations..
1929 */
1930
1931 /* allocate our initial queue */
1932 qi = wlc_txq_alloc(wlc, osh);
1933 if (qi == NULL) {
1934 WL_ERROR("wl%d: %s: failed to malloc tx queue\n",
1935 unit, __func__);
1936 err = 100;
1937 goto fail;
1938 }
1939 wlc->active_queue = qi;
1940
1941 wlc->bsscfg[0] = wlc->cfg;
1942 wlc->cfg->_idx = 0;
1943 wlc->cfg->wlc = wlc;
1944 pub->txmaxpkts = MAXTXPKTS;
1945
1946 pub->_cnt->version = WL_CNT_T_VERSION;
1947 pub->_cnt->length = sizeof(struct wl_cnt);
1948
1949 WLCNTSET(pub->_wme_cnt->version, WL_WME_CNT_VERSION);
1950 WLCNTSET(pub->_wme_cnt->length, sizeof(wl_wme_cnt_t));
1951
1952 wlc_wme_initparams_sta(wlc, &wlc->wme_param_ie);
1953
1954 wlc->mimoft = FT_HT;
1955 wlc->ht_cap.cap_info = HT_CAP;
1956 if (HT_ENAB(wlc->pub))
1957 wlc->stf->ldpc = AUTO;
1958
1959 wlc->mimo_40txbw = AUTO;
1960 wlc->ofdm_40txbw = AUTO;
1961 wlc->cck_40txbw = AUTO;
1962 wlc_update_mimo_band_bwcap(wlc, WLC_N_BW_20IN2G_40IN5G);
1963
1964 /* Enable setting the RIFS Mode bit by default in HT Info IE */
1965 wlc->rifs_advert = AUTO;
1966
1967 /* Set default values of SGI */
1968 if (WLC_SGI_CAP_PHY(wlc)) {
1969 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1970 wlc->sgi_tx = AUTO;
1971 } else if (WLCISSSLPNPHY(wlc->band)) {
1972 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1973 wlc->sgi_tx = AUTO;
1974 } else {
1975 wlc_ht_update_sgi_rx(wlc, 0);
1976 wlc->sgi_tx = OFF;
1977 }
1978
1979 /* *******nvram 11n config overrides Start ********* */
1980
1981 /* apply the sgi override from nvram conf */
1982 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_TX)
1983 wlc->sgi_tx = OFF;
1984
1985 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_RX)
1986 wlc_ht_update_sgi_rx(wlc, 0);
1987
1988 /* apply the stbc override from nvram conf */
1989 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_TX) {
1990 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
1991 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
1992 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_TX_STBC;
1993 }
1994 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_RX)
1995 wlc_stf_stbc_rx_set(wlc, HT_CAP_RX_STBC_NO);
1996
1997 /* apply the GF override from nvram conf */
1998 if (n_disabled & WLFEATURE_DISABLE_11N_GF)
1999 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_GRN_FLD;
2000
2001 /* initialize radio_mpc_disable according to wlc->mpc */
2002 wlc_radio_mpc_upd(wlc);
2003
2004 if ((wlc->pub->sih->chip) == BCM43235_CHIP_ID) {
2005 if ((getintvar(wlc->pub->vars, "aa2g") == 7) ||
2006 (getintvar(wlc->pub->vars, "aa5g") == 7)) {
2007 wlc_bmac_antsel_set(wlc->hw, 1);
2008 }
2009 } else {
2010 wlc_bmac_antsel_set(wlc->hw, wlc->asi->antsel_avail);
2011 }
2012
2013 if (perr)
2014 *perr = 0;
2015
2016 return (void *)wlc;
2017
2018 fail:
2019 WL_ERROR("wl%d: %s: failed with err %d\n", unit, __func__, err);
2020 if (wlc)
2021 wlc_detach(wlc);
2022
2023 if (perr)
2024 *perr = err;
2025 return NULL;
2026 }
2027
2028 static void wlc_attach_antgain_init(struct wlc_info *wlc)
2029 {
2030 uint unit;
2031 unit = wlc->pub->unit;
2032
2033 if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) {
2034 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2035 wlc->band->antgain = 8;
2036 } else if (wlc->band->antgain == -1) {
2037 WL_ERROR("wl%d: %s: Invalid antennas available in srom, using 2dB\n",
2038 unit, __func__);
2039 wlc->band->antgain = 8;
2040 } else {
2041 s8 gain, fract;
2042 /* Older sroms specified gain in whole dbm only. In order
2043 * be able to specify qdbm granularity and remain backward compatible
2044 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2045 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2046 * -32 - 31. Examples: 0x1 = 1 db,
2047 * 0xc1 = 1.75 db (1 + 3 quarters),
2048 * 0x3f = -1 (-1 + 0 quarters),
2049 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2050 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2051 */
2052 gain = wlc->band->antgain & 0x3f;
2053 gain <<= 2; /* Sign extend */
2054 gain >>= 2;
2055 fract = (wlc->band->antgain & 0xc0) >> 6;
2056 wlc->band->antgain = 4 * gain + fract;
2057 }
2058 }
2059
2060 static bool wlc_attach_stf_ant_init(struct wlc_info *wlc)
2061 {
2062 int aa;
2063 uint unit;
2064 char *vars;
2065 int bandtype;
2066
2067 unit = wlc->pub->unit;
2068 vars = wlc->pub->vars;
2069 bandtype = wlc->band->bandtype;
2070
2071 /* get antennas available */
2072 aa = (s8) getintvar(vars, (BAND_5G(bandtype) ? "aa5g" : "aa2g"));
2073 if (aa == 0)
2074 aa = (s8) getintvar(vars,
2075 (BAND_5G(bandtype) ? "aa1" : "aa0"));
2076 if ((aa < 1) || (aa > 15)) {
2077 WL_ERROR("wl%d: %s: Invalid antennas available in srom (0x%x), using 3\n",
2078 unit, __func__, aa);
2079 aa = 3;
2080 }
2081
2082 /* reset the defaults if we have a single antenna */
2083 if (aa == 1) {
2084 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0;
2085 wlc->stf->txant = ANT_TX_FORCE_0;
2086 } else if (aa == 2) {
2087 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1;
2088 wlc->stf->txant = ANT_TX_FORCE_1;
2089 } else {
2090 }
2091
2092 /* Compute Antenna Gain */
2093 wlc->band->antgain =
2094 (s8) getintvar(vars, (BAND_5G(bandtype) ? "ag1" : "ag0"));
2095 wlc_attach_antgain_init(wlc);
2096
2097 return true;
2098 }
2099
2100
2101 static void wlc_timers_deinit(struct wlc_info *wlc)
2102 {
2103 /* free timer state */
2104 if (wlc->wdtimer) {
2105 wl_free_timer(wlc->wl, wlc->wdtimer);
2106 wlc->wdtimer = NULL;
2107 }
2108 if (wlc->radio_timer) {
2109 wl_free_timer(wlc->wl, wlc->radio_timer);
2110 wlc->radio_timer = NULL;
2111 }
2112 }
2113
2114 static void wlc_detach_module(struct wlc_info *wlc)
2115 {
2116 if (wlc->asi) {
2117 wlc_antsel_detach(wlc->asi);
2118 wlc->asi = NULL;
2119 }
2120
2121 if (wlc->ampdu) {
2122 wlc_ampdu_detach(wlc->ampdu);
2123 wlc->ampdu = NULL;
2124 }
2125
2126 wlc_stf_detach(wlc);
2127 }
2128
2129 /*
2130 * Return a count of the number of driver callbacks still pending.
2131 *
2132 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2133 * touch hardware registers since the d11core may be in reset and clock may not be available.
2134 * One exception is sb register access, which is possible if crystal is turned on
2135 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2136 */
2137 uint wlc_detach(struct wlc_info *wlc)
2138 {
2139 uint i;
2140 uint callbacks = 0;
2141
2142 if (wlc == NULL)
2143 return 0;
2144
2145 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
2146
2147 ASSERT(!wlc->pub->up);
2148
2149 callbacks += wlc_bmac_detach(wlc);
2150
2151 /* delete software timers */
2152 if (!wlc_radio_monitor_stop(wlc))
2153 callbacks++;
2154
2155 wlc_channel_mgr_detach(wlc->cmi);
2156
2157 wlc_timers_deinit(wlc);
2158
2159 wlc_detach_module(wlc);
2160
2161 /* free other state */
2162
2163
2164 #ifdef BCMDBG
2165 if (wlc->country_ie_override) {
2166 kfree(wlc->country_ie_override);
2167 wlc->country_ie_override = NULL;
2168 }
2169 #endif /* BCMDBG */
2170
2171 {
2172 /* free dumpcb list */
2173 struct dumpcb_s *prev, *ptr;
2174 prev = ptr = wlc->dumpcb_head;
2175 while (ptr) {
2176 ptr = prev->next;
2177 kfree(prev);
2178 prev = ptr;
2179 }
2180 wlc->dumpcb_head = NULL;
2181 }
2182
2183 /* Detach from iovar manager */
2184 wlc_module_unregister(wlc->pub, "wlc_iovars", wlc);
2185
2186 while (wlc->tx_queues != NULL) {
2187 wlc_txq_free(wlc, wlc->osh, wlc->tx_queues);
2188 }
2189
2190 /*
2191 * consistency check: wlc_module_register/wlc_module_unregister calls
2192 * should match therefore nothing should be left here.
2193 */
2194 for (i = 0; i < WLC_MAXMODULES; i++)
2195 ASSERT(wlc->modulecb[i].name[0] == '\0');
2196
2197 wlc_detach_mfree(wlc);
2198 return callbacks;
2199 }
2200
2201 /* update state that depends on the current value of "ap" */
2202 void wlc_ap_upd(struct wlc_info *wlc)
2203 {
2204 if (AP_ENAB(wlc->pub))
2205 wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */
2206 else
2207 wlc->PLCPHdr_override = WLC_PLCP_SHORT; /* STA-BSS; short capable */
2208
2209 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2210 wlc->vlan_mode = AP_ENAB(wlc->pub) ? OFF : AUTO;
2211
2212 /* fixup mpc */
2213 wlc->mpc = true;
2214 }
2215
2216 /* read hwdisable state and propagate to wlc flag */
2217 static void wlc_radio_hwdisable_upd(struct wlc_info *wlc)
2218 {
2219 if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off)
2220 return;
2221
2222 if (wlc_bmac_radio_read_hwdisabled(wlc->hw)) {
2223 mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2224 } else {
2225 mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2226 }
2227 }
2228
2229 /* return true if Minimum Power Consumption should be entered, false otherwise */
2230 bool wlc_is_non_delay_mpc(struct wlc_info *wlc)
2231 {
2232 return false;
2233 }
2234
2235 bool wlc_ismpc(struct wlc_info *wlc)
2236 {
2237 return (wlc->mpc_delay_off == 0) && (wlc_is_non_delay_mpc(wlc));
2238 }
2239
2240 void wlc_radio_mpc_upd(struct wlc_info *wlc)
2241 {
2242 bool mpc_radio, radio_state;
2243
2244 /*
2245 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2246 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2247 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2248 * the radio is going down.
2249 */
2250 if (!wlc->mpc) {
2251 if (!wlc->pub->radio_disabled)
2252 return;
2253 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2254 wlc_radio_upd(wlc);
2255 if (!wlc->pub->radio_disabled)
2256 wlc_radio_monitor_stop(wlc);
2257 return;
2258 }
2259
2260 /*
2261 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2262 * to go ON, always call radio_upd synchronously
2263 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2264 */
2265 radio_state =
2266 (mboolisset(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE) ? OFF :
2267 ON);
2268 mpc_radio = (wlc_ismpc(wlc) == true) ? OFF : ON;
2269
2270 if (radio_state == ON && mpc_radio == OFF)
2271 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2272 else if (radio_state == OFF && mpc_radio == ON) {
2273 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2274 wlc_radio_upd(wlc);
2275 if (wlc->mpc_offcnt < WLC_MPC_THRESHOLD) {
2276 wlc->mpc_dlycnt = WLC_MPC_MAX_DELAYCNT;
2277 } else
2278 wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
2279 wlc->mpc_dur += OSL_SYSUPTIME() - wlc->mpc_laston_ts;
2280 }
2281 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2282 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2283 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2284 */
2285 if ((wlc->prev_non_delay_mpc == false) &&
2286 (wlc_is_non_delay_mpc(wlc) == true) && wlc->mpc_delay_off) {
2287 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2288 }
2289 wlc->prev_non_delay_mpc = wlc_is_non_delay_mpc(wlc);
2290 }
2291
2292 /*
2293 * centralized radio disable/enable function,
2294 * invoke radio enable/disable after updating hwradio status
2295 */
2296 static void wlc_radio_upd(struct wlc_info *wlc)
2297 {
2298 if (wlc->pub->radio_disabled) {
2299 wlc_radio_disable(wlc);
2300 } else {
2301 wlc_radio_enable(wlc);
2302 }
2303 }
2304
2305 /* maintain LED behavior in down state */
2306 static void wlc_down_led_upd(struct wlc_info *wlc)
2307 {
2308 ASSERT(!wlc->pub->up);
2309
2310 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2311 /* turn on sbclk if necessary */
2312 if (!AP_ENAB(wlc->pub)) {
2313 wlc_pllreq(wlc, true, WLC_PLLREQ_FLIP);
2314
2315 wlc_pllreq(wlc, false, WLC_PLLREQ_FLIP);
2316 }
2317 }
2318
2319 /* update hwradio status and return it */
2320 bool wlc_check_radio_disabled(struct wlc_info *wlc)
2321 {
2322 wlc_radio_hwdisable_upd(wlc);
2323
2324 return mboolisset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE) ? true : false;
2325 }
2326
2327 void wlc_radio_disable(struct wlc_info *wlc)
2328 {
2329 if (!wlc->pub->up) {
2330 wlc_down_led_upd(wlc);
2331 return;
2332 }
2333
2334 wlc_radio_monitor_start(wlc);
2335 wl_down(wlc->wl);
2336 }
2337
2338 static void wlc_radio_enable(struct wlc_info *wlc)
2339 {
2340 if (wlc->pub->up)
2341 return;
2342
2343 if (DEVICEREMOVED(wlc))
2344 return;
2345
2346 if (!wlc->down_override) { /* imposed by wl down/out ioctl */
2347 wl_up(wlc->wl);
2348 }
2349 }
2350
2351 /* periodical query hw radio button while driver is "down" */
2352 static void wlc_radio_timer(void *arg)
2353 {
2354 struct wlc_info *wlc = (struct wlc_info *) arg;
2355
2356 if (DEVICEREMOVED(wlc)) {
2357 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2358 wl_down(wlc->wl);
2359 return;
2360 }
2361
2362 /* cap mpc off count */
2363 if (wlc->mpc_offcnt < WLC_MPC_MAX_DELAYCNT)
2364 wlc->mpc_offcnt++;
2365
2366 /* validate all the reasons driver could be down and running this radio_timer */
2367 ASSERT(wlc->pub->radio_disabled || wlc->down_override);
2368 wlc_radio_hwdisable_upd(wlc);
2369 wlc_radio_upd(wlc);
2370 }
2371
2372 static bool wlc_radio_monitor_start(struct wlc_info *wlc)
2373 {
2374 /* Don't start the timer if HWRADIO feature is disabled */
2375 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO))
2376 return true;
2377
2378 wlc->radio_monitor = true;
2379 wlc_pllreq(wlc, true, WLC_PLLREQ_RADIO_MON);
2380 wl_add_timer(wlc->wl, wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, true);
2381 return true;
2382 }
2383
2384 bool wlc_radio_monitor_stop(struct wlc_info *wlc)
2385 {
2386 if (!wlc->radio_monitor)
2387 return true;
2388
2389 ASSERT((wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO) !=
2390 WL_SWFL_NOHWRADIO);
2391
2392 wlc->radio_monitor = false;
2393 wlc_pllreq(wlc, false, WLC_PLLREQ_RADIO_MON);
2394 return wl_del_timer(wlc->wl, wlc->radio_timer);
2395 }
2396
2397 /* bring the driver down, but don't reset hardware */
2398 void wlc_out(struct wlc_info *wlc)
2399 {
2400 wlc_bmac_set_noreset(wlc->hw, true);
2401 wlc_radio_upd(wlc);
2402 wl_down(wlc->wl);
2403 wlc_bmac_set_noreset(wlc->hw, false);
2404
2405 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2406 wlc->clk = true;
2407
2408 /* This will make sure that when 'up' is done
2409 * after 'out' it'll restore hardware (especially gpios)
2410 */
2411 wlc->pub->hw_up = false;
2412 }
2413
2414 #if defined(BCMDBG)
2415 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2416 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2417 * in prec_map. Of course, ignore this rule when block_datafifo is set
2418 */
2419 static bool wlc_tx_prec_map_verify(struct wlc_info *wlc)
2420 {
2421 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2422 * fail the check.
2423 */
2424 if (!EDCF_ENAB(wlc->pub)) {
2425 if (!(WLC_TX_FIFO_CHECK(wlc, TX_DATA_FIFO) ||
2426 WLC_TX_FIFO_CHECK(wlc, TX_CTL_FIFO)))
2427 return false;
2428 else
2429 return true;
2430 }
2431
2432 return WLC_TX_FIFO_CHECK(wlc, TX_AC_BK_FIFO)
2433 && WLC_TX_FIFO_CHECK(wlc, TX_AC_BE_FIFO)
2434 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VI_FIFO)
2435 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VO_FIFO);
2436 }
2437 #endif /* BCMDBG */
2438
2439 static void wlc_watchdog_by_timer(void *arg)
2440 {
2441 struct wlc_info *wlc = (struct wlc_info *) arg;
2442 wlc_watchdog(arg);
2443 if (WLC_WATCHDOG_TBTT(wlc)) {
2444 /* set to normal osl watchdog period */
2445 wl_del_timer(wlc->wl, wlc->wdtimer);
2446 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
2447 true);
2448 }
2449 }
2450
2451 /* common watchdog code */
2452 static void wlc_watchdog(void *arg)
2453 {
2454 struct wlc_info *wlc = (struct wlc_info *) arg;
2455 int i;
2456 wlc_bsscfg_t *cfg;
2457
2458 WL_TRACE("wl%d: wlc_watchdog\n", wlc->pub->unit);
2459
2460 if (!wlc->pub->up)
2461 return;
2462
2463 if (DEVICEREMOVED(wlc)) {
2464 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2465 wl_down(wlc->wl);
2466 return;
2467 }
2468
2469 /* increment second count */
2470 wlc->pub->now++;
2471
2472 /* delay radio disable */
2473 if (wlc->mpc_delay_off) {
2474 if (--wlc->mpc_delay_off == 0) {
2475 mboolset(wlc->pub->radio_disabled,
2476 WL_RADIO_MPC_DISABLE);
2477 if (wlc->mpc && wlc_ismpc(wlc))
2478 wlc->mpc_offcnt = 0;
2479 wlc->mpc_laston_ts = OSL_SYSUPTIME();
2480 }
2481 }
2482
2483 /* mpc sync */
2484 wlc_radio_mpc_upd(wlc);
2485 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2486 wlc_radio_hwdisable_upd(wlc);
2487 wlc_radio_upd(wlc);
2488 /* if ismpc, driver should be in down state if up/down is allowed */
2489 if (wlc->mpc && wlc_ismpc(wlc))
2490 ASSERT(!wlc->pub->up);
2491 /* if radio is disable, driver may be down, quit here */
2492 if (wlc->pub->radio_disabled)
2493 return;
2494
2495 wlc_bmac_watchdog(wlc);
2496
2497 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2498 if ((wlc->pub->now % SW_TIMER_MAC_STAT_UPD) == 0)
2499 wlc_statsupd(wlc);
2500
2501 /* Manage TKIP countermeasures timers */
2502 FOREACH_BSS(wlc, i, cfg) {
2503 if (cfg->tk_cm_dt) {
2504 cfg->tk_cm_dt--;
2505 }
2506 if (cfg->tk_cm_bt) {
2507 cfg->tk_cm_bt--;
2508 }
2509 }
2510
2511 /* Call any registered watchdog handlers */
2512 for (i = 0; i < WLC_MAXMODULES; i++) {
2513 if (wlc->modulecb[i].watchdog_fn)
2514 wlc->modulecb[i].watchdog_fn(wlc->modulecb[i].hdl);
2515 }
2516
2517 if (WLCISNPHY(wlc->band) && !wlc->pub->tempsense_disable &&
2518 ((wlc->pub->now - wlc->tempsense_lasttime) >=
2519 WLC_TEMPSENSE_PERIOD)) {
2520 wlc->tempsense_lasttime = wlc->pub->now;
2521 wlc_tempsense_upd(wlc);
2522 }
2523 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2524 ASSERT(wlc_bmac_taclear(wlc->hw, true));
2525
2526 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2527 ASSERT(wlc_tx_prec_map_verify(wlc));
2528
2529 ASSERT(wlc_ps_check(wlc));
2530 }
2531
2532 /* make interface operational */
2533 int wlc_up(struct wlc_info *wlc)
2534 {
2535 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2536
2537 /* HW is turned off so don't try to access it */
2538 if (wlc->pub->hw_off || DEVICEREMOVED(wlc))
2539 return BCME_RADIOOFF;
2540
2541 if (!wlc->pub->hw_up) {
2542 wlc_bmac_hw_up(wlc->hw);
2543 wlc->pub->hw_up = true;
2544 }
2545
2546 if ((wlc->pub->boardflags & BFL_FEM)
2547 && (wlc->pub->sih->chip == BCM4313_CHIP_ID)) {
2548 if (wlc->pub->boardrev >= 0x1250
2549 && (wlc->pub->boardflags & BFL_FEM_BT)) {
2550 wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL,
2551 MHF5_4313_GPIOCTRL, WLC_BAND_ALL);
2552 } else {
2553 wlc_mhf(wlc, MHF4, MHF4_EXTPA_ENABLE, MHF4_EXTPA_ENABLE,
2554 WLC_BAND_ALL);
2555 }
2556 }
2557
2558 /*
2559 * Need to read the hwradio status here to cover the case where the system
2560 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2561 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2562 * don't call radio_update to avoid looping wlc_up.
2563 *
2564 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2565 */
2566 if (!wlc->pub->radio_disabled) {
2567 int status = wlc_bmac_up_prep(wlc->hw);
2568 if (status == BCME_RADIOOFF) {
2569 if (!mboolisset
2570 (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) {
2571 int idx;
2572 wlc_bsscfg_t *bsscfg;
2573 mboolset(wlc->pub->radio_disabled,
2574 WL_RADIO_HW_DISABLE);
2575
2576 FOREACH_BSS(wlc, idx, bsscfg) {
2577 if (!BSSCFG_STA(bsscfg)
2578 || !bsscfg->enable || !bsscfg->BSS)
2579 continue;
2580 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2581 wlc->pub->unit, idx);
2582 }
2583 }
2584 } else
2585 ASSERT(!status);
2586 }
2587
2588 if (wlc->pub->radio_disabled) {
2589 wlc_radio_monitor_start(wlc);
2590 return 0;
2591 }
2592
2593 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2594 wlc->clk = true;
2595
2596 wlc_radio_monitor_stop(wlc);
2597
2598 /* Set EDCF hostflags */
2599 if (EDCF_ENAB(wlc->pub)) {
2600 wlc_mhf(wlc, MHF1, MHF1_EDCF, MHF1_EDCF, WLC_BAND_ALL);
2601 } else {
2602 wlc_mhf(wlc, MHF1, MHF1_EDCF, 0, WLC_BAND_ALL);
2603 }
2604
2605 if (WLC_WAR16165(wlc))
2606 wlc_mhf(wlc, MHF2, MHF2_PCISLOWCLKWAR, MHF2_PCISLOWCLKWAR,
2607 WLC_BAND_ALL);
2608
2609 wl_init(wlc->wl);
2610 wlc->pub->up = true;
2611
2612 if (wlc->bandinit_pending) {
2613 wlc_suspend_mac_and_wait(wlc);
2614 wlc_set_chanspec(wlc, wlc->default_bss->chanspec);
2615 wlc->bandinit_pending = false;
2616 wlc_enable_mac(wlc);
2617 }
2618
2619 wlc_bmac_up_finish(wlc->hw);
2620
2621 /* other software states up after ISR is running */
2622 /* start APs that were to be brought up but are not up yet */
2623 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2624
2625 /* Program the TX wme params with the current settings */
2626 wlc_wme_retries_write(wlc);
2627
2628 /* start one second watchdog timer */
2629 ASSERT(!wlc->WDarmed);
2630 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true);
2631 wlc->WDarmed = true;
2632
2633 /* ensure antenna config is up to date */
2634 wlc_stf_phy_txant_upd(wlc);
2635 /* ensure LDPC config is in sync */
2636 wlc_ht_update_ldpc(wlc, wlc->stf->ldpc);
2637
2638 return 0;
2639 }
2640
2641 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2642 static void wlc_tx_prec_map_init(struct wlc_info *wlc)
2643 {
2644 wlc->tx_prec_map = WLC_PREC_BMP_ALL;
2645 memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16));
2646
2647 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2648 * if either is full.
2649 */
2650 if (!EDCF_ENAB(wlc->pub)) {
2651 wlc->fifo2prec_map[TX_DATA_FIFO] = WLC_PREC_BMP_ALL;
2652 wlc->fifo2prec_map[TX_CTL_FIFO] = WLC_PREC_BMP_ALL;
2653 } else {
2654 wlc->fifo2prec_map[TX_AC_BK_FIFO] = WLC_PREC_BMP_AC_BK;
2655 wlc->fifo2prec_map[TX_AC_BE_FIFO] = WLC_PREC_BMP_AC_BE;
2656 wlc->fifo2prec_map[TX_AC_VI_FIFO] = WLC_PREC_BMP_AC_VI;
2657 wlc->fifo2prec_map[TX_AC_VO_FIFO] = WLC_PREC_BMP_AC_VO;
2658 }
2659 }
2660
2661 static uint wlc_down_del_timer(struct wlc_info *wlc)
2662 {
2663 uint callbacks = 0;
2664
2665 return callbacks;
2666 }
2667
2668 /*
2669 * Mark the interface nonoperational, stop the software mechanisms,
2670 * disable the hardware, free any transient buffer state.
2671 * Return a count of the number of driver callbacks still pending.
2672 */
2673 uint wlc_down(struct wlc_info *wlc)
2674 {
2675
2676 uint callbacks = 0;
2677 int i;
2678 bool dev_gone = false;
2679 struct wlc_txq_info *qi;
2680
2681 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2682
2683 /* check if we are already in the going down path */
2684 if (wlc->going_down) {
2685 WL_ERROR("wl%d: %s: Driver going down so return\n",
2686 wlc->pub->unit, __func__);
2687 return 0;
2688 }
2689 if (!wlc->pub->up)
2690 return callbacks;
2691
2692 /* in between, mpc could try to bring down again.. */
2693 wlc->going_down = true;
2694
2695 callbacks += wlc_bmac_down_prep(wlc->hw);
2696
2697 dev_gone = DEVICEREMOVED(wlc);
2698
2699 /* Call any registered down handlers */
2700 for (i = 0; i < WLC_MAXMODULES; i++) {
2701 if (wlc->modulecb[i].down_fn)
2702 callbacks +=
2703 wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl);
2704 }
2705
2706 /* cancel the watchdog timer */
2707 if (wlc->WDarmed) {
2708 if (!wl_del_timer(wlc->wl, wlc->wdtimer))
2709 callbacks++;
2710 wlc->WDarmed = false;
2711 }
2712 /* cancel all other timers */
2713 callbacks += wlc_down_del_timer(wlc);
2714
2715 /* interrupt must have been blocked */
2716 ASSERT((wlc->macintmask == 0) || !wlc->pub->up);
2717
2718 wlc->pub->up = false;
2719
2720 wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL);
2721
2722 /* clear txq flow control */
2723 wlc_txflowcontrol_reset(wlc);
2724
2725 /* flush tx queues */
2726 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
2727 pktq_flush(wlc->osh, &qi->q, true, NULL, 0);
2728 ASSERT(pktq_empty(&qi->q));
2729 }
2730
2731 callbacks += wlc_bmac_down_finish(wlc->hw);
2732
2733 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2734 wlc->clk = false;
2735
2736
2737 /* Verify all packets are flushed from the driver */
2738 if (wlc->osh->pktalloced != 0) {
2739 WL_ERROR("%d packets not freed at wlc_down!!!!!!\n",
2740 wlc->osh->pktalloced);
2741 }
2742 #ifdef BCMDBG
2743 /* Since all the packets should have been freed,
2744 * all callbacks should have been called
2745 */
2746 for (i = 1; i <= wlc->pub->tunables->maxpktcb; i++)
2747 ASSERT(wlc->pkt_callback[i].fn == NULL);
2748 #endif
2749 wlc->going_down = false;
2750 return callbacks;
2751 }
2752
2753 /* Set the current gmode configuration */
2754 int wlc_set_gmode(struct wlc_info *wlc, u8 gmode, bool config)
2755 {
2756 int ret = 0;
2757 uint i;
2758 wlc_rateset_t rs;
2759 /* Default to 54g Auto */
2760 s8 shortslot = WLC_SHORTSLOT_AUTO; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2761 bool shortslot_restrict = false; /* Restrict association to stations that support shortslot
2762 */
2763 bool ignore_bcns = true; /* Ignore legacy beacons on the same channel */
2764 bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */
2765 int preamble = WLC_PLCP_LONG; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2766 bool preamble_restrict = false; /* Restrict association to stations that support short
2767 * preambles
2768 */
2769 struct wlcband *band;
2770
2771 /* if N-support is enabled, allow Gmode set as long as requested
2772 * Gmode is not GMODE_LEGACY_B
2773 */
2774 if (N_ENAB(wlc->pub) && gmode == GMODE_LEGACY_B)
2775 return BCME_UNSUPPORTED;
2776
2777 /* verify that we are dealing with 2G band and grab the band pointer */
2778 if (wlc->band->bandtype == WLC_BAND_2G)
2779 band = wlc->band;
2780 else if ((NBANDS(wlc) > 1) &&
2781 (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == WLC_BAND_2G))
2782 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
2783 else
2784 return BCME_BADBAND;
2785
2786 /* Legacy or bust when no OFDM is supported by regulatory */
2787 if ((wlc_channel_locale_flags_in_band(wlc->cmi, band->bandunit) &
2788 WLC_NO_OFDM) && (gmode != GMODE_LEGACY_B))
2789 return BCME_RANGE;
2790
2791 /* update configuration value */
2792 if (config == true)
2793 wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode);
2794
2795 /* Clear supported rates filter */
2796 memset(&wlc->sup_rates_override, 0, sizeof(wlc_rateset_t));
2797
2798 /* Clear rateset override */
2799 memset(&rs, 0, sizeof(wlc_rateset_t));
2800
2801 switch (gmode) {
2802 case GMODE_LEGACY_B:
2803 shortslot = WLC_SHORTSLOT_OFF;
2804 wlc_rateset_copy(&gphy_legacy_rates, &rs);
2805
2806 break;
2807
2808 case GMODE_LRS:
2809 if (AP_ENAB(wlc->pub))
2810 wlc_rateset_copy(&cck_rates, &wlc->sup_rates_override);
2811 break;
2812
2813 case GMODE_AUTO:
2814 /* Accept defaults */
2815 break;
2816
2817 case GMODE_ONLY:
2818 ofdm_basic = true;
2819 preamble = WLC_PLCP_SHORT;
2820 preamble_restrict = true;
2821 break;
2822
2823 case GMODE_PERFORMANCE:
2824 if (AP_ENAB(wlc->pub)) /* Put all rates into the Supported Rates element */
2825 wlc_rateset_copy(&cck_ofdm_rates,
2826 &wlc->sup_rates_override);
2827
2828 shortslot = WLC_SHORTSLOT_ON;
2829 shortslot_restrict = true;
2830 ofdm_basic = true;
2831 preamble = WLC_PLCP_SHORT;
2832 preamble_restrict = true;
2833 break;
2834
2835 default:
2836 /* Error */
2837 WL_ERROR("wl%d: %s: invalid gmode %d\n",
2838 wlc->pub->unit, __func__, gmode);
2839 return BCME_UNSUPPORTED;
2840 }
2841
2842 /*
2843 * If we are switching to gmode == GMODE_LEGACY_B,
2844 * clean up rate info that may refer to OFDM rates.
2845 */
2846 if ((gmode == GMODE_LEGACY_B) && (band->gmode != GMODE_LEGACY_B)) {
2847 band->gmode = gmode;
2848 if (band->rspec_override && !IS_CCK(band->rspec_override)) {
2849 band->rspec_override = 0;
2850 wlc_reprate_init(wlc);
2851 }
2852 if (band->mrspec_override && !IS_CCK(band->mrspec_override)) {
2853 band->mrspec_override = 0;
2854 }
2855 }
2856
2857 band->gmode = gmode;
2858
2859 wlc->ignore_bcns = ignore_bcns;
2860
2861 wlc->shortslot_override = shortslot;
2862
2863 if (AP_ENAB(wlc->pub)) {
2864 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2865 wlc->PLCPHdr_override =
2866 (preamble !=
2867 WLC_PLCP_LONG) ? WLC_PLCP_SHORT : WLC_PLCP_AUTO;
2868 }
2869
2870 if ((AP_ENAB(wlc->pub) && preamble != WLC_PLCP_LONG)
2871 || preamble == WLC_PLCP_SHORT)
2872 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2873 else
2874 wlc->default_bss->capability &= ~WLAN_CAPABILITY_SHORT_PREAMBLE;
2875
2876 /* Update shortslot capability bit for AP and IBSS */
2877 if ((AP_ENAB(wlc->pub) && shortslot == WLC_SHORTSLOT_AUTO) ||
2878 shortslot == WLC_SHORTSLOT_ON)
2879 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2880 else
2881 wlc->default_bss->capability &=
2882 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
2883
2884 /* Use the default 11g rateset */
2885 if (!rs.count)
2886 wlc_rateset_copy(&cck_ofdm_rates, &rs);
2887
2888 if (ofdm_basic) {
2889 for (i = 0; i < rs.count; i++) {
2890 if (rs.rates[i] == WLC_RATE_6M
2891 || rs.rates[i] == WLC_RATE_12M
2892 || rs.rates[i] == WLC_RATE_24M)
2893 rs.rates[i] |= WLC_RATE_FLAG;
2894 }
2895 }
2896
2897 /* Set default bss rateset */
2898 wlc->default_bss->rateset.count = rs.count;
2899 memcpy(wlc->default_bss->rateset.rates, rs.rates,
2900 sizeof(wlc->default_bss->rateset.rates));
2901
2902 return ret;
2903 }
2904
2905 static int wlc_nmode_validate(struct wlc_info *wlc, s32 nmode)
2906 {
2907 int err = 0;
2908
2909 switch (nmode) {
2910
2911 case OFF:
2912 break;
2913
2914 case AUTO:
2915 case WL_11N_2x2:
2916 case WL_11N_3x3:
2917 if (!(WLC_PHY_11N_CAP(wlc->band)))
2918 err = BCME_BADBAND;
2919 break;
2920
2921 default:
2922 err = BCME_RANGE;
2923 break;
2924 }
2925
2926 return err;
2927 }
2928
2929 int wlc_set_nmode(struct wlc_info *wlc, s32 nmode)
2930 {
2931 uint i;
2932 int err;
2933
2934 err = wlc_nmode_validate(wlc, nmode);
2935 ASSERT(err == 0);
2936 if (err)
2937 return err;
2938
2939 switch (nmode) {
2940 case OFF:
2941 wlc->pub->_n_enab = OFF;
2942 wlc->default_bss->flags &= ~WLC_BSS_HT;
2943 /* delete the mcs rates from the default and hw ratesets */
2944 wlc_rateset_mcs_clear(&wlc->default_bss->rateset);
2945 for (i = 0; i < NBANDS(wlc); i++) {
2946 memset(wlc->bandstate[i]->hw_rateset.mcs, 0,
2947 MCSSET_LEN);
2948 if (IS_MCS(wlc->band->rspec_override)) {
2949 wlc->bandstate[i]->rspec_override = 0;
2950 wlc_reprate_init(wlc);
2951 }
2952 if (IS_MCS(wlc->band->mrspec_override))
2953 wlc->bandstate[i]->mrspec_override = 0;
2954 }
2955 break;
2956
2957 case AUTO:
2958 if (wlc->stf->txstreams == WL_11N_3x3)
2959 nmode = WL_11N_3x3;
2960 else
2961 nmode = WL_11N_2x2;
2962 case WL_11N_2x2:
2963 case WL_11N_3x3:
2964 ASSERT(WLC_PHY_11N_CAP(wlc->band));
2965 /* force GMODE_AUTO if NMODE is ON */
2966 wlc_set_gmode(wlc, GMODE_AUTO, true);
2967 if (nmode == WL_11N_3x3)
2968 wlc->pub->_n_enab = SUPPORT_HT;
2969 else
2970 wlc->pub->_n_enab = SUPPORT_11N;
2971 wlc->default_bss->flags |= WLC_BSS_HT;
2972 /* add the mcs rates to the default and hw ratesets */
2973 wlc_rateset_mcs_build(&wlc->default_bss->rateset,
2974 wlc->stf->txstreams);
2975 for (i = 0; i < NBANDS(wlc); i++)
2976 memcpy(wlc->bandstate[i]->hw_rateset.mcs,
2977 wlc->default_bss->rateset.mcs, MCSSET_LEN);
2978 break;
2979
2980 default:
2981 ASSERT(0);
2982 break;
2983 }
2984
2985 return err;
2986 }
2987
2988 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg)
2989 {
2990 wlc_rateset_t rs, new;
2991 uint bandunit;
2992
2993 memcpy(&rs, rs_arg, sizeof(wlc_rateset_t));
2994
2995 /* check for bad count value */
2996 if ((rs.count == 0) || (rs.count > WLC_NUMRATES))
2997 return BCME_BADRATESET;
2998
2999 /* try the current band */
3000 bandunit = wlc->band->bandunit;
3001 memcpy(&new, &rs, sizeof(wlc_rateset_t));
3002 if (wlc_rate_hwrs_filter_sort_validate
3003 (&new, &wlc->bandstate[bandunit]->hw_rateset, true,
3004 wlc->stf->txstreams))
3005 goto good;
3006
3007 /* try the other band */
3008 if (IS_MBAND_UNLOCKED(wlc)) {
3009 bandunit = OTHERBANDUNIT(wlc);
3010 memcpy(&new, &rs, sizeof(wlc_rateset_t));
3011 if (wlc_rate_hwrs_filter_sort_validate(&new,
3012 &wlc->
3013 bandstate[bandunit]->
3014 hw_rateset, true,
3015 wlc->stf->txstreams))
3016 goto good;
3017 }
3018
3019 return BCME_ERROR;
3020
3021 good:
3022 /* apply new rateset */
3023 memcpy(&wlc->default_bss->rateset, &new, sizeof(wlc_rateset_t));
3024 memcpy(&wlc->bandstate[bandunit]->defrateset, &new,
3025 sizeof(wlc_rateset_t));
3026 return 0;
3027 }
3028
3029 /* simplified integer set interface for common ioctl handler */
3030 int wlc_set(struct wlc_info *wlc, int cmd, int arg)
3031 {
3032 return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL);
3033 }
3034
3035 /* simplified integer get interface for common ioctl handler */
3036 int wlc_get(struct wlc_info *wlc, int cmd, int *arg)
3037 {
3038 return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL);
3039 }
3040
3041 static void wlc_ofdm_rateset_war(struct wlc_info *wlc)
3042 {
3043 u8 r;
3044 bool war = false;
3045
3046 if (wlc->cfg->associated)
3047 r = wlc->cfg->current_bss->rateset.rates[0];
3048 else
3049 r = wlc->default_bss->rateset.rates[0];
3050
3051 wlc_phy_ofdm_rateset_war(wlc->band->pi, war);
3052
3053 return;
3054 }
3055
3056 int
3057 wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3058 struct wlc_if *wlcif)
3059 {
3060 return _wlc_ioctl(wlc, cmd, arg, len, wlcif);
3061 }
3062
3063 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3064 static int
3065 _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3066 struct wlc_if *wlcif)
3067 {
3068 int val, *pval;
3069 bool bool_val;
3070 int bcmerror;
3071 d11regs_t *regs;
3072 uint i;
3073 struct scb *nextscb;
3074 bool ta_ok;
3075 uint band;
3076 rw_reg_t *r;
3077 wlc_bsscfg_t *bsscfg;
3078 struct osl_info *osh;
3079 wlc_bss_info_t *current_bss;
3080
3081 /* update bsscfg pointer */
3082 bsscfg = NULL; /* XXX: Hack bsscfg to be size one and use this globally */
3083 current_bss = NULL;
3084
3085 /* initialize the following to get rid of compiler warning */
3086 nextscb = NULL;
3087 ta_ok = false;
3088 band = 0;
3089 r = NULL;
3090
3091 /* If the device is turned off, then it's not "removed" */
3092 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) {
3093 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
3094 wl_down(wlc->wl);
3095 return BCME_ERROR;
3096 }
3097
3098 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
3099
3100 /* default argument is generic integer */
3101 pval = arg ? (int *)arg:NULL;
3102
3103 /* This will prevent the misaligned access */
3104 if (pval && (u32) len >= sizeof(val))
3105 memcpy(&val, pval, sizeof(val));
3106 else
3107 val = 0;
3108
3109 /* bool conversion to avoid duplication below */
3110 bool_val = val != 0;
3111
3112 if (cmd != WLC_SET_CHANNEL)
3113 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3114 cmd, (uint)val, val, len);
3115
3116 bcmerror = 0;
3117 regs = wlc->regs;
3118 osh = wlc->osh;
3119
3120 /* A few commands don't need any arguments; all the others do. */
3121 switch (cmd) {
3122 case WLC_UP:
3123 case WLC_OUT:
3124 case WLC_DOWN:
3125 case WLC_DISASSOC:
3126 case WLC_RESTART:
3127 case WLC_REBOOT:
3128 case WLC_START_CHANNEL_QA:
3129 case WLC_INIT:
3130 break;
3131
3132 default:
3133 if ((arg == NULL) || (len <= 0)) {
3134 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3135 wlc->pub->unit, __func__, cmd);
3136 bcmerror = BCME_BADARG;
3137 goto done;
3138 }
3139 }
3140
3141 switch (cmd) {
3142
3143 #if defined(BCMDBG)
3144 case WLC_GET_MSGLEVEL:
3145 *pval = wl_msg_level;
3146 break;
3147
3148 case WLC_SET_MSGLEVEL:
3149 wl_msg_level = val;
3150 break;
3151 #endif
3152
3153 case WLC_GET_INSTANCE:
3154 *pval = wlc->pub->unit;
3155 break;
3156
3157 case WLC_GET_CHANNEL:{
3158 channel_info_t *ci = (channel_info_t *) arg;
3159
3160 ASSERT(len > (int)sizeof(ci));
3161
3162 ci->hw_channel =
3163 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC);
3164 ci->target_channel =
3165 CHSPEC_CHANNEL(wlc->default_bss->chanspec);
3166 ci->scan_channel = 0;
3167
3168 break;
3169 }
3170
3171 case WLC_SET_CHANNEL:{
3172 chanspec_t chspec = CH20MHZ_CHSPEC(val);
3173
3174 if (val < 0 || val > MAXCHANNEL) {
3175 bcmerror = BCME_OUTOFRANGECHAN;
3176 break;
3177 }
3178
3179 if (!wlc_valid_chanspec_db(wlc->cmi, chspec)) {
3180 bcmerror = BCME_BADCHAN;
3181 break;
3182 }
3183
3184 if (!wlc->pub->up && IS_MBAND_UNLOCKED(wlc)) {
3185 if (wlc->band->bandunit !=
3186 CHSPEC_WLCBANDUNIT(chspec))
3187 wlc->bandinit_pending = true;
3188 else
3189 wlc->bandinit_pending = false;
3190 }
3191
3192 wlc->default_bss->chanspec = chspec;
3193 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3194 if (wlc->pub->up &&
3195 (WLC_BAND_PI_RADIO_CHANSPEC != chspec)) {
3196 wlc_set_home_chanspec(wlc, chspec);
3197 wlc_suspend_mac_and_wait(wlc);
3198 wlc_set_chanspec(wlc, chspec);
3199 wlc_enable_mac(wlc);
3200 }
3201 break;
3202 }
3203
3204 #if defined(BCMDBG)
3205 case WLC_GET_UCFLAGS:
3206 if (!wlc->pub->up) {
3207 bcmerror = BCME_NOTUP;
3208 break;
3209 }
3210
3211 /* optional band is stored in the second integer of incoming buffer */
3212 band =
3213 (len <
3214 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3215
3216 /* bcmerror checking */
3217 bcmerror = wlc_iocregchk(wlc, band);
3218 if (bcmerror)
3219 break;
3220
3221 if (val >= MHFMAX) {
3222 bcmerror = BCME_RANGE;
3223 break;
3224 }
3225
3226 *pval = wlc_bmac_mhf_get(wlc->hw, (u8) val, WLC_BAND_AUTO);
3227 break;
3228
3229 case WLC_SET_UCFLAGS:
3230 if (!wlc->pub->up) {
3231 bcmerror = BCME_NOTUP;
3232 break;
3233 }
3234
3235 /* optional band is stored in the second integer of incoming buffer */
3236 band =
3237 (len <
3238 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3239
3240 /* bcmerror checking */
3241 bcmerror = wlc_iocregchk(wlc, band);
3242 if (bcmerror)
3243 break;
3244
3245 i = (u16) val;
3246 if (i >= MHFMAX) {
3247 bcmerror = BCME_RANGE;
3248 break;
3249 }
3250
3251 wlc_mhf(wlc, (u8) i, 0xffff, (u16) (val >> NBITS(u16)),
3252 WLC_BAND_AUTO);
3253 break;
3254
3255 case WLC_GET_SHMEM:
3256 ta_ok = true;
3257
3258 /* optional band is stored in the second integer of incoming buffer */
3259 band =
3260 (len <
3261 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3262
3263 /* bcmerror checking */
3264 bcmerror = wlc_iocregchk(wlc, band);
3265 if (bcmerror)
3266 break;
3267
3268 if (val & 1) {
3269 bcmerror = BCME_BADADDR;
3270 break;
3271 }
3272
3273 *pval = wlc_read_shm(wlc, (u16) val);
3274 break;
3275
3276 case WLC_SET_SHMEM:
3277 ta_ok = true;
3278
3279 /* optional band is stored in the second integer of incoming buffer */
3280 band =
3281 (len <
3282 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3283
3284 /* bcmerror checking */
3285 bcmerror = wlc_iocregchk(wlc, band);
3286 if (bcmerror)
3287 break;
3288
3289 if (val & 1) {
3290 bcmerror = BCME_BADADDR;
3291 break;
3292 }
3293
3294 wlc_write_shm(wlc, (u16) val,
3295 (u16) (val >> NBITS(u16)));
3296 break;
3297
3298 case WLC_R_REG: /* MAC registers */
3299 ta_ok = true;
3300 r = (rw_reg_t *) arg;
3301 band = WLC_BAND_AUTO;
3302
3303 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3304 bcmerror = BCME_BUFTOOSHORT;
3305 break;
3306 }
3307
3308 if (len >= (int)sizeof(rw_reg_t))
3309 band = r->band;
3310
3311 /* bcmerror checking */
3312 bcmerror = wlc_iocregchk(wlc, band);
3313 if (bcmerror)
3314 break;
3315
3316 if ((r->byteoff + r->size) > sizeof(d11regs_t)) {
3317 bcmerror = BCME_BADADDR;
3318 break;
3319 }
3320 if (r->size == sizeof(u32))
3321 r->val =
3322 R_REG(osh,
3323 (u32 *)((unsigned char *)(unsigned long)regs +
3324 r->byteoff));
3325 else if (r->size == sizeof(u16))
3326 r->val =
3327 R_REG(osh,
3328 (u16 *)((unsigned char *)(unsigned long)regs +
3329 r->byteoff));
3330 else
3331 bcmerror = BCME_BADADDR;
3332 break;
3333
3334 case WLC_W_REG:
3335 ta_ok = true;
3336 r = (rw_reg_t *) arg;
3337 band = WLC_BAND_AUTO;
3338
3339 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3340 bcmerror = BCME_BUFTOOSHORT;
3341 break;
3342 }
3343
3344 if (len >= (int)sizeof(rw_reg_t))
3345 band = r->band;
3346
3347 /* bcmerror checking */
3348 bcmerror = wlc_iocregchk(wlc, band);
3349 if (bcmerror)
3350 break;
3351
3352 if (r->byteoff + r->size > sizeof(d11regs_t)) {
3353 bcmerror = BCME_BADADDR;
3354 break;
3355 }
3356 if (r->size == sizeof(u32))
3357 W_REG(osh,
3358 (u32 *)((unsigned char *)(unsigned long) regs +
3359 r->byteoff), r->val);
3360 else if (r->size == sizeof(u16))
3361 W_REG(osh,
3362 (u16 *)((unsigned char *)(unsigned long) regs +
3363 r->byteoff), r->val);
3364 else
3365 bcmerror = BCME_BADADDR;
3366 break;
3367 #endif /* BCMDBG */
3368
3369 case WLC_GET_TXANT:
3370 *pval = wlc->stf->txant;
3371 break;
3372
3373 case WLC_SET_TXANT:
3374 bcmerror = wlc_stf_ant_txant_validate(wlc, (s8) val);
3375 if (bcmerror < 0)
3376 break;
3377
3378 wlc->stf->txant = (s8) val;
3379
3380 /* if down, we are done */
3381 if (!wlc->pub->up)
3382 break;
3383
3384 wlc_suspend_mac_and_wait(wlc);
3385
3386 wlc_stf_phy_txant_upd(wlc);
3387 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
3388
3389 wlc_enable_mac(wlc);
3390
3391 break;
3392
3393 case WLC_GET_ANTDIV:{
3394 u8 phy_antdiv;
3395
3396 /* return configured value if core is down */
3397 if (!wlc->pub->up) {
3398 *pval = wlc->stf->ant_rx_ovr;
3399
3400 } else {
3401 if (wlc_phy_ant_rxdiv_get
3402 (wlc->band->pi, &phy_antdiv))
3403 *pval = (int)phy_antdiv;
3404 else
3405 *pval = (int)wlc->stf->ant_rx_ovr;
3406 }
3407
3408 break;
3409 }
3410 case WLC_SET_ANTDIV:
3411 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3412 if ((val < -1) || (val > 3)) {
3413 bcmerror = BCME_RANGE;
3414 break;
3415 }
3416
3417 if (val == -1)
3418 val = ANT_RX_DIV_DEF;
3419
3420 wlc->stf->ant_rx_ovr = (u8) val;
3421 wlc_phy_ant_rxdiv_set(wlc->band->pi, (u8) val);
3422 break;
3423
3424 case WLC_GET_RX_ANT:{ /* get latest used rx antenna */
3425 u16 rxstatus;
3426
3427 if (!wlc->pub->up) {
3428 bcmerror = BCME_NOTUP;
3429 break;
3430 }
3431
3432 rxstatus = R_REG(wlc->osh, &wlc->regs->phyrxstatus0);
3433 if (rxstatus == 0xdead || rxstatus == (u16) -1) {
3434 bcmerror = BCME_ERROR;
3435 break;
3436 }
3437 *pval = (rxstatus & PRXS0_RXANT_UPSUBBAND) ? 1 : 0;
3438 break;
3439 }
3440
3441 #if defined(BCMDBG)
3442 case WLC_GET_UCANTDIV:
3443 if (!wlc->clk) {
3444 bcmerror = BCME_NOCLK;
3445 break;
3446 }
3447
3448 *pval =
3449 (wlc_bmac_mhf_get(wlc->hw, MHF1, WLC_BAND_AUTO) &
3450 MHF1_ANTDIV);
3451 break;
3452
3453 case WLC_SET_UCANTDIV:{
3454 if (!wlc->pub->up) {
3455 bcmerror = BCME_NOTUP;
3456 break;
3457 }
3458
3459 /* if multiband, band must be locked */
3460 if (IS_MBAND_UNLOCKED(wlc)) {
3461 bcmerror = BCME_NOTBANDLOCKED;
3462 break;
3463 }
3464
3465 wlc_mhf(wlc, MHF1, MHF1_ANTDIV,
3466 (val ? MHF1_ANTDIV : 0), WLC_BAND_AUTO);
3467 break;
3468 }
3469 #endif /* defined(BCMDBG) */
3470
3471 case WLC_GET_SRL:
3472 *pval = wlc->SRL;
3473 break;
3474
3475 case WLC_SET_SRL:
3476 if (val >= 1 && val <= RETRY_SHORT_MAX) {
3477 int ac;
3478 wlc->SRL = (u16) val;
3479
3480 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3481
3482 for (ac = 0; ac < AC_COUNT; ac++) {
3483 WLC_WME_RETRY_SHORT_SET(wlc, ac, wlc->SRL);
3484 }
3485 wlc_wme_retries_write(wlc);
3486 } else
3487 bcmerror = BCME_RANGE;
3488 break;
3489
3490 case WLC_GET_LRL:
3491 *pval = wlc->LRL;
3492 break;
3493
3494 case WLC_SET_LRL:
3495 if (val >= 1 && val <= 255) {
3496 int ac;
3497 wlc->LRL = (u16) val;
3498
3499 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3500
3501 for (ac = 0; ac < AC_COUNT; ac++) {
3502 WLC_WME_RETRY_LONG_SET(wlc, ac, wlc->LRL);
3503 }
3504 wlc_wme_retries_write(wlc);
3505 } else
3506 bcmerror = BCME_RANGE;
3507 break;
3508
3509 case WLC_GET_CWMIN:
3510 *pval = wlc->band->CWmin;
3511 break;
3512
3513 case WLC_SET_CWMIN:
3514 if (!wlc->clk) {
3515 bcmerror = BCME_NOCLK;
3516 break;
3517 }
3518
3519 if (val >= 1 && val <= 255) {
3520 wlc_set_cwmin(wlc, (u16) val);
3521 } else
3522 bcmerror = BCME_RANGE;
3523 break;
3524
3525 case WLC_GET_CWMAX:
3526 *pval = wlc->band->CWmax;
3527 break;
3528
3529 case WLC_SET_CWMAX:
3530 if (!wlc->clk) {
3531 bcmerror = BCME_NOCLK;
3532 break;
3533 }
3534
3535 if (val >= 255 && val <= 2047) {
3536 wlc_set_cwmax(wlc, (u16) val);
3537 } else
3538 bcmerror = BCME_RANGE;
3539 break;
3540
3541 case WLC_GET_RADIO: /* use mask if don't want to expose some internal bits */
3542 *pval = wlc->pub->radio_disabled;
3543 break;
3544
3545 case WLC_SET_RADIO:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3546 * set
3547 */
3548 u16 radiomask, radioval;
3549 uint validbits =
3550 WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE;
3551 mbool new = 0;
3552
3553 radiomask = (val & 0xffff0000) >> 16;
3554 radioval = val & 0x0000ffff;
3555
3556 if ((radiomask == 0) || (radiomask & ~validbits)
3557 || (radioval & ~validbits)
3558 || ((radioval & ~radiomask) != 0)) {
3559 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3560 val);
3561 bcmerror = BCME_RANGE;
3562 break;
3563 }
3564
3565 new =
3566 (wlc->pub->radio_disabled & ~radiomask) | radioval;
3567 wlc->pub->radio_disabled = new;
3568
3569 wlc_radio_hwdisable_upd(wlc);
3570 wlc_radio_upd(wlc);
3571 break;
3572 }
3573
3574 case WLC_GET_PHYTYPE:
3575 *pval = WLC_PHYTYPE(wlc->band->phytype);
3576 break;
3577
3578 #if defined(BCMDBG)
3579 case WLC_GET_KEY:
3580 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc))) {
3581 wl_wsec_key_t key;
3582
3583 wsec_key_t *src_key = wlc->wsec_keys[val];
3584
3585 if (len < (int)sizeof(key)) {
3586 bcmerror = BCME_BUFTOOSHORT;
3587 break;
3588 }
3589
3590 memset((char *)&key, 0, sizeof(key));
3591 if (src_key) {
3592 key.index = src_key->id;
3593 key.len = src_key->len;
3594 memcpy(key.data, src_key->data, key.len);
3595 key.algo = src_key->algo;
3596 if (WSEC_SOFTKEY(wlc, src_key, bsscfg))
3597 key.flags |= WL_SOFT_KEY;
3598 if (src_key->flags & WSEC_PRIMARY_KEY)
3599 key.flags |= WL_PRIMARY_KEY;
3600
3601 memcpy(key.ea, src_key->ea, ETH_ALEN);
3602 }
3603
3604 memcpy(arg, &key, sizeof(key));
3605 } else
3606 bcmerror = BCME_BADKEYIDX;
3607 break;
3608 #endif /* defined(BCMDBG) */
3609
3610 case WLC_SET_KEY:
3611 bcmerror =
3612 wlc_iovar_op(wlc, "wsec_key", NULL, 0, arg, len, IOV_SET,
3613 wlcif);
3614 break;
3615
3616 case WLC_GET_KEY_SEQ:{
3617 wsec_key_t *key;
3618
3619 if (len < DOT11_WPA_KEY_RSC_LEN) {
3620 bcmerror = BCME_BUFTOOSHORT;
3621 break;
3622 }
3623
3624 /* Return the key's tx iv as an EAPOL sequence counter.
3625 * This will be used to supply the RSC value to a supplicant.
3626 * The format is 8 bytes, with least significant in seq[0].
3627 */
3628
3629 key = WSEC_KEY(wlc, val);
3630 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc)) &&
3631 (key != NULL)) {
3632 u8 seq[DOT11_WPA_KEY_RSC_LEN];
3633 u16 lo;
3634 u32 hi;
3635 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3636 if ((bsscfg->WPA_auth & WPA_AUTH_NONE) &&
3637 is_zero_ether_addr(key->ea)) {
3638 lo = bsscfg->wpa_none_txiv.lo;
3639 hi = bsscfg->wpa_none_txiv.hi;
3640 } else {
3641 lo = key->txiv.lo;
3642 hi = key->txiv.hi;
3643 }
3644
3645 /* format the buffer, low to high */
3646 seq[0] = lo & 0xff;
3647 seq[1] = (lo >> 8) & 0xff;
3648 seq[2] = hi & 0xff;
3649 seq[3] = (hi >> 8) & 0xff;
3650 seq[4] = (hi >> 16) & 0xff;
3651 seq[5] = (hi >> 24) & 0xff;
3652 seq[6] = 0;
3653 seq[7] = 0;
3654
3655 memcpy(arg, seq, sizeof(seq));
3656 } else {
3657 bcmerror = BCME_BADKEYIDX;
3658 }
3659 break;
3660 }
3661
3662 case WLC_GET_CURR_RATESET:{
3663 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3664 wlc_rateset_t *rs;
3665
3666 if (bsscfg->associated)
3667 rs = &current_bss->rateset;
3668 else
3669 rs = &wlc->default_bss->rateset;
3670
3671 if (len < (int)(rs->count + sizeof(rs->count))) {
3672 bcmerror = BCME_BUFTOOSHORT;
3673 break;
3674 }
3675
3676 /* Copy only legacy rateset section */
3677 ret_rs->count = rs->count;
3678 memcpy(&ret_rs->rates, &rs->rates, rs->count);
3679 break;
3680 }
3681
3682 case WLC_GET_RATESET:{
3683 wlc_rateset_t rs;
3684 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3685
3686 memset(&rs, 0, sizeof(wlc_rateset_t));
3687 wlc_default_rateset(wlc, (wlc_rateset_t *) &rs);
3688
3689 if (len < (int)(rs.count + sizeof(rs.count))) {
3690 bcmerror = BCME_BUFTOOSHORT;
3691 break;
3692 }
3693
3694 /* Copy only legacy rateset section */
3695 ret_rs->count = rs.count;
3696 memcpy(&ret_rs->rates, &rs.rates, rs.count);
3697 break;
3698 }
3699
3700 case WLC_SET_RATESET:{
3701 wlc_rateset_t rs;
3702 wl_rateset_t *in_rs = (wl_rateset_t *) arg;
3703
3704 if (len < (int)(in_rs->count + sizeof(in_rs->count))) {
3705 bcmerror = BCME_BUFTOOSHORT;
3706 break;
3707 }
3708
3709 if (in_rs->count > WLC_NUMRATES) {
3710 bcmerror = BCME_BUFTOOLONG;
3711 break;
3712 }
3713
3714 memset(&rs, 0, sizeof(wlc_rateset_t));
3715
3716 /* Copy only legacy rateset section */
3717 rs.count = in_rs->count;
3718 memcpy(&rs.rates, &in_rs->rates, rs.count);
3719
3720 /* merge rateset coming in with the current mcsset */
3721 if (N_ENAB(wlc->pub)) {
3722 if (bsscfg->associated)
3723 memcpy(rs.mcs,
3724 &current_bss->rateset.mcs[0],
3725 MCSSET_LEN);
3726 else
3727 memcpy(rs.mcs,
3728 &wlc->default_bss->rateset.mcs[0],
3729 MCSSET_LEN);
3730 }
3731
3732 bcmerror = wlc_set_rateset(wlc, &rs);
3733
3734 if (!bcmerror)
3735 wlc_ofdm_rateset_war(wlc);
3736
3737 break;
3738 }
3739
3740 case WLC_GET_BCNPRD:
3741 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3742 *pval = current_bss->beacon_period;
3743 else
3744 *pval = wlc->default_bss->beacon_period;
3745 break;
3746
3747 case WLC_SET_BCNPRD:
3748 /* range [1, 0xffff] */
3749 if (val >= DOT11_MIN_BEACON_PERIOD
3750 && val <= DOT11_MAX_BEACON_PERIOD) {
3751 wlc->default_bss->beacon_period = (u16) val;
3752 } else
3753 bcmerror = BCME_RANGE;
3754 break;
3755
3756 case WLC_GET_DTIMPRD:
3757 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3758 *pval = current_bss->dtim_period;
3759 else
3760 *pval = wlc->default_bss->dtim_period;
3761 break;
3762
3763 case WLC_SET_DTIMPRD:
3764 /* range [1, 0xff] */
3765 if (val >= DOT11_MIN_DTIM_PERIOD
3766 && val <= DOT11_MAX_DTIM_PERIOD) {
3767 wlc->default_bss->dtim_period = (u8) val;
3768 } else
3769 bcmerror = BCME_RANGE;
3770 break;
3771
3772 #ifdef SUPPORT_PS
3773 case WLC_GET_PM:
3774 *pval = wlc->PM;
3775 break;
3776
3777 case WLC_SET_PM:
3778 if ((val >= PM_OFF) && (val <= PM_MAX)) {
3779 wlc->PM = (u8) val;
3780 if (wlc->pub->up) {
3781 }
3782 /* Change watchdog driver to align watchdog with tbtt if possible */
3783 wlc_watchdog_upd(wlc, PS_ALLOWED(wlc));
3784 } else
3785 bcmerror = BCME_ERROR;
3786 break;
3787 #endif /* SUPPORT_PS */
3788
3789 #ifdef SUPPORT_PS
3790 #ifdef BCMDBG
3791 case WLC_GET_WAKE:
3792 if (AP_ENAB(wlc->pub)) {
3793 bcmerror = BCME_NOTSTA;
3794 break;
3795 }
3796 *pval = wlc->wake;
3797 break;
3798
3799 case WLC_SET_WAKE:
3800 if (AP_ENAB(wlc->pub)) {
3801 bcmerror = BCME_NOTSTA;
3802 break;
3803 }
3804
3805 wlc->wake = val ? true : false;
3806
3807 /* if down, we're done */
3808 if (!wlc->pub->up)
3809 break;
3810
3811 /* apply to the mac */
3812 wlc_set_ps_ctrl(wlc);
3813 break;
3814 #endif /* BCMDBG */
3815 #endif /* SUPPORT_PS */
3816
3817 case WLC_GET_REVINFO:
3818 bcmerror = wlc_get_revision_info(wlc, arg, (uint) len);
3819 break;
3820
3821 case WLC_GET_AP:
3822 *pval = (int)AP_ENAB(wlc->pub);
3823 break;
3824
3825 case WLC_GET_ATIM:
3826 if (bsscfg->associated)
3827 *pval = (int)current_bss->atim_window;
3828 else
3829 *pval = (int)wlc->default_bss->atim_window;
3830 break;
3831
3832 case WLC_SET_ATIM:
3833 wlc->default_bss->atim_window = (u32) val;
3834 break;
3835
3836 case WLC_GET_PKTCNTS:{
3837 get_pktcnt_t *pktcnt = (get_pktcnt_t *) pval;
3838 wlc_statsupd(wlc);
3839 pktcnt->rx_good_pkt = wlc->pub->_cnt->rxframe;
3840 pktcnt->rx_bad_pkt = wlc->pub->_cnt->rxerror;
3841 pktcnt->tx_good_pkt =
3842 wlc->pub->_cnt->txfrmsnt;
3843 pktcnt->tx_bad_pkt =
3844 wlc->pub->_cnt->txerror +
3845 wlc->pub->_cnt->txfail;
3846 if (len >= (int)sizeof(get_pktcnt_t)) {
3847 /* Be backward compatible - only if buffer is large enough */
3848 pktcnt->rx_ocast_good_pkt =
3849 wlc->pub->_cnt->rxmfrmocast;
3850 }
3851 break;
3852 }
3853
3854 #ifdef SUPPORT_HWKEY
3855 case WLC_GET_WSEC:
3856 bcmerror =
3857 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_GET,
3858 wlcif);
3859 break;
3860
3861 case WLC_SET_WSEC:
3862 bcmerror =
3863 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_SET,
3864 wlcif);
3865 break;
3866
3867 case WLC_GET_WPA_AUTH:
3868 *pval = (int)bsscfg->WPA_auth;
3869 break;
3870
3871 case WLC_SET_WPA_AUTH:
3872 /* change of WPA_Auth modifies the PS_ALLOWED state */
3873 if (BSSCFG_STA(bsscfg)) {
3874 bsscfg->WPA_auth = (u16) val;
3875 } else
3876 bsscfg->WPA_auth = (u16) val;
3877 break;
3878 #endif /* SUPPORT_HWKEY */
3879
3880 case WLC_GET_BANDLIST:
3881 /* count of number of bands, followed by each band type */
3882 *pval++ = NBANDS(wlc);
3883 *pval++ = wlc->band->bandtype;
3884 if (NBANDS(wlc) > 1)
3885 *pval++ = wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype;
3886 break;
3887
3888 case WLC_GET_BAND:
3889 *pval = wlc->bandlocked ? wlc->band->bandtype : WLC_BAND_AUTO;
3890 break;
3891
3892 case WLC_GET_PHYLIST:
3893 {
3894 unsigned char *cp = arg;
3895 if (len < 3) {
3896 bcmerror = BCME_BUFTOOSHORT;
3897 break;
3898 }
3899
3900 if (WLCISNPHY(wlc->band)) {
3901 *cp++ = 'n';
3902 } else if (WLCISLCNPHY(wlc->band)) {
3903 *cp++ = 'c';
3904 } else if (WLCISSSLPNPHY(wlc->band)) {
3905 *cp++ = 's';
3906 }
3907 *cp = '\0';
3908 break;
3909 }
3910
3911 case WLC_GET_SHORTSLOT:
3912 *pval = wlc->shortslot;
3913 break;
3914
3915 case WLC_GET_SHORTSLOT_OVERRIDE:
3916 *pval = wlc->shortslot_override;
3917 break;
3918
3919 case WLC_SET_SHORTSLOT_OVERRIDE:
3920 if ((val != WLC_SHORTSLOT_AUTO) &&
3921 (val != WLC_SHORTSLOT_OFF) && (val != WLC_SHORTSLOT_ON)) {
3922 bcmerror = BCME_RANGE;
3923 break;
3924 }
3925
3926 wlc->shortslot_override = (s8) val;
3927
3928 /* shortslot is an 11g feature, so no more work if we are
3929 * currently on the 5G band
3930 */
3931 if (BAND_5G(wlc->band->bandtype))
3932 break;
3933
3934 if (wlc->pub->up && wlc->pub->associated) {
3935 /* let watchdog or beacon processing update shortslot */
3936 } else if (wlc->pub->up) {
3937 /* unassociated shortslot is off */
3938 wlc_switch_shortslot(wlc, false);
3939 } else {
3940 /* driver is down, so just update the wlc_info value */
3941 if (wlc->shortslot_override == WLC_SHORTSLOT_AUTO) {
3942 wlc->shortslot = false;
3943 } else {
3944 wlc->shortslot =
3945 (wlc->shortslot_override ==
3946 WLC_SHORTSLOT_ON);
3947 }
3948 }
3949
3950 break;
3951
3952 case WLC_GET_LEGACY_ERP:
3953 *pval = wlc->include_legacy_erp;
3954 break;
3955
3956 case WLC_SET_LEGACY_ERP:
3957 if (wlc->include_legacy_erp == bool_val)
3958 break;
3959
3960 wlc->include_legacy_erp = bool_val;
3961
3962 if (AP_ENAB(wlc->pub) && wlc->clk) {
3963 wlc_update_beacon(wlc);
3964 wlc_update_probe_resp(wlc, true);
3965 }
3966 break;
3967
3968 case WLC_GET_GMODE:
3969 if (wlc->band->bandtype == WLC_BAND_2G)
3970 *pval = wlc->band->gmode;
3971 else if (NBANDS(wlc) > 1)
3972 *pval = wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode;
3973 break;
3974
3975 case WLC_SET_GMODE:
3976 if (!wlc->pub->associated)
3977 bcmerror = wlc_set_gmode(wlc, (u8) val, true);
3978 else {
3979 bcmerror = BCME_ASSOCIATED;
3980 break;
3981 }
3982 break;
3983
3984 case WLC_GET_GMODE_PROTECTION:
3985 *pval = wlc->protection->_g;
3986 break;
3987
3988 case WLC_GET_PROTECTION_CONTROL:
3989 *pval = wlc->protection->overlap;
3990 break;
3991
3992 case WLC_SET_PROTECTION_CONTROL:
3993 if ((val != WLC_PROTECTION_CTL_OFF) &&
3994 (val != WLC_PROTECTION_CTL_LOCAL) &&
3995 (val != WLC_PROTECTION_CTL_OVERLAP)) {
3996 bcmerror = BCME_RANGE;
3997 break;
3998 }
3999
4000 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, (s8) val);
4001
4002 /* Current g_protection will sync up to the specified control alg in watchdog
4003 * if the driver is up and associated.
4004 * If the driver is down or not associated, the control setting has no effect.
4005 */
4006 break;
4007
4008 case WLC_GET_GMODE_PROTECTION_OVERRIDE:
4009 *pval = wlc->protection->g_override;
4010 break;
4011
4012 case WLC_SET_GMODE_PROTECTION_OVERRIDE:
4013 if ((val != WLC_PROTECTION_AUTO) &&
4014 (val != WLC_PROTECTION_OFF) && (val != WLC_PROTECTION_ON)) {
4015 bcmerror = BCME_RANGE;
4016 break;
4017 }
4018
4019 wlc_protection_upd(wlc, WLC_PROT_G_OVR, (s8) val);
4020
4021 break;
4022
4023 case WLC_SET_SUP_RATESET_OVERRIDE:{
4024 wlc_rateset_t rs, new;
4025
4026 /* copyin */
4027 if (len < (int)sizeof(wlc_rateset_t)) {
4028 bcmerror = BCME_BUFTOOSHORT;
4029 break;
4030 }
4031 memcpy(&rs, arg, sizeof(wlc_rateset_t));
4032
4033 /* check for bad count value */
4034 if (rs.count > WLC_NUMRATES) {
4035 bcmerror = BCME_BADRATESET; /* invalid rateset */
4036 break;
4037 }
4038
4039 /* this command is only appropriate for gmode operation */
4040 if (!(wlc->band->gmode ||
4041 ((NBANDS(wlc) > 1)
4042 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4043 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4044 break;
4045 }
4046
4047 /* check for an empty rateset to clear the override */
4048 if (rs.count == 0) {
4049 memset(&wlc->sup_rates_override, 0,
4050 sizeof(wlc_rateset_t));
4051 break;
4052 }
4053
4054 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4055 wlc_rateset_filter(&rs, &new, false, WLC_RATES_CCK_OFDM,
4056 RATE_MASK, BSS_N_ENAB(wlc, bsscfg));
4057 wlc_rate_hwrs_filter_sort_validate(&new,
4058 &cck_ofdm_rates,
4059 false,
4060 wlc->stf->txstreams);
4061 if (rs.count != new.count) {
4062 bcmerror = BCME_BADRATESET; /* invalid rateset */
4063 break;
4064 }
4065
4066 /* apply new rateset to the override */
4067 memcpy(&wlc->sup_rates_override, &new,
4068 sizeof(wlc_rateset_t));
4069
4070 /* update bcn and probe resp if needed */
4071 if (wlc->pub->up && AP_ENAB(wlc->pub)
4072 && wlc->pub->associated) {
4073 wlc_update_beacon(wlc);
4074 wlc_update_probe_resp(wlc, true);
4075 }
4076 break;
4077 }
4078
4079 case WLC_GET_SUP_RATESET_OVERRIDE:
4080 /* this command is only appropriate for gmode operation */
4081 if (!(wlc->band->gmode ||
4082 ((NBANDS(wlc) > 1)
4083 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4084 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4085 break;
4086 }
4087 if (len < (int)sizeof(wlc_rateset_t)) {
4088 bcmerror = BCME_BUFTOOSHORT;
4089 break;
4090 }
4091 memcpy(arg, &wlc->sup_rates_override, sizeof(wlc_rateset_t));
4092
4093 break;
4094
4095 case WLC_GET_PRB_RESP_TIMEOUT:
4096 *pval = wlc->prb_resp_timeout;
4097 break;
4098
4099 case WLC_SET_PRB_RESP_TIMEOUT:
4100 if (wlc->pub->up) {
4101 bcmerror = BCME_NOTDOWN;
4102 break;
4103 }
4104 if (val < 0 || val >= 0xFFFF) {
4105 bcmerror = BCME_RANGE; /* bad value */
4106 break;
4107 }
4108 wlc->prb_resp_timeout = (u16) val;
4109 break;
4110
4111 case WLC_GET_KEY_PRIMARY:{
4112 wsec_key_t *key;
4113
4114 /* treat the 'val' parm as the key id */
4115 key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4116 if (key != NULL) {
4117 *pval = key->id == val ? true : false;
4118 } else {
4119 bcmerror = BCME_BADKEYIDX;
4120 }
4121 break;
4122 }
4123
4124 case WLC_SET_KEY_PRIMARY:{
4125 wsec_key_t *key, *old_key;
4126
4127 bcmerror = BCME_BADKEYIDX;
4128
4129 /* treat the 'val' parm as the key id */
4130 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
4131 key = bsscfg->bss_def_keys[i];
4132 if (key != NULL && key->id == val) {
4133 old_key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4134 if (old_key != NULL)
4135 old_key->flags &=
4136 ~WSEC_PRIMARY_KEY;
4137 key->flags |= WSEC_PRIMARY_KEY;
4138 bsscfg->wsec_index = i;
4139 bcmerror = BCME_OK;
4140 }
4141 }
4142 break;
4143 }
4144
4145 #ifdef BCMDBG
4146 case WLC_INIT:
4147 wl_init(wlc->wl);
4148 break;
4149 #endif
4150
4151 case WLC_SET_VAR:
4152 case WLC_GET_VAR:{
4153 char *name;
4154 /* validate the name value */
4155 name = (char *)arg;
4156 for (i = 0; i < (uint) len && *name != '\0';
4157 i++, name++)
4158 ;
4159
4160 if (i == (uint) len) {
4161 bcmerror = BCME_BUFTOOSHORT;
4162 break;
4163 }
4164 i++; /* include the null in the string length */
4165
4166 if (cmd == WLC_GET_VAR) {
4167 bcmerror =
4168 wlc_iovar_op(wlc, arg,
4169 (void *)((s8 *) arg + i),
4170 len - i, arg, len, IOV_GET,
4171 wlcif);
4172 } else
4173 bcmerror =
4174 wlc_iovar_op(wlc, arg, NULL, 0,
4175 (void *)((s8 *) arg + i),
4176 len - i, IOV_SET, wlcif);
4177
4178 break;
4179 }
4180
4181 case WLC_SET_WSEC_PMK:
4182 bcmerror = BCME_UNSUPPORTED;
4183 break;
4184
4185 #if defined(BCMDBG)
4186 case WLC_CURRENT_PWR:
4187 if (!wlc->pub->up)
4188 bcmerror = BCME_NOTUP;
4189 else
4190 bcmerror = wlc_get_current_txpwr(wlc, arg, len);
4191 break;
4192 #endif
4193
4194 case WLC_LAST:
4195 WL_ERROR("%s: WLC_LAST\n", __func__);
4196 }
4197 done:
4198
4199 if (bcmerror) {
4200 if (VALID_BCMERROR(bcmerror))
4201 wlc->pub->bcmerror = bcmerror;
4202 else {
4203 bcmerror = 0;
4204 }
4205
4206 }
4207 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4208 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4209 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4210 */
4211 if (!(wlc->pub->hw_off))
4212 ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok);
4213
4214 return bcmerror;
4215 }
4216
4217 #if defined(BCMDBG)
4218 /* consolidated register access ioctl error checking */
4219 int wlc_iocregchk(struct wlc_info *wlc, uint band)
4220 {
4221 /* if band is specified, it must be the current band */
4222 if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype))
4223 return BCME_BADBAND;
4224
4225 /* if multiband and band is not specified, band must be locked */
4226 if ((band == WLC_BAND_AUTO) && IS_MBAND_UNLOCKED(wlc))
4227 return BCME_NOTBANDLOCKED;
4228
4229 /* must have core clocks */
4230 if (!wlc->clk)
4231 return BCME_NOCLK;
4232
4233 return 0;
4234 }
4235 #endif /* defined(BCMDBG) */
4236
4237 #if defined(BCMDBG)
4238 /* For some ioctls, make sure that the pi pointer matches the current phy */
4239 int wlc_iocpichk(struct wlc_info *wlc, uint phytype)
4240 {
4241 if (wlc->band->phytype != phytype)
4242 return BCME_BADBAND;
4243 return 0;
4244 }
4245 #endif
4246
4247 /* Look up the given var name in the given table */
4248 static const bcm_iovar_t *wlc_iovar_lookup(const bcm_iovar_t *table,
4249 const char *name)
4250 {
4251 const bcm_iovar_t *vi;
4252 const char *lookup_name;
4253
4254 /* skip any ':' delimited option prefixes */
4255 lookup_name = strrchr(name, ':');
4256 if (lookup_name != NULL)
4257 lookup_name++;
4258 else
4259 lookup_name = name;
4260
4261 ASSERT(table != NULL);
4262
4263 for (vi = table; vi->name; vi++) {
4264 if (!strcmp(vi->name, lookup_name))
4265 return vi;
4266 }
4267 /* ran to end of table */
4268
4269 return NULL; /* var name not found */
4270 }
4271
4272 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4273 int wlc_iovar_getint(struct wlc_info *wlc, const char *name, int *arg)
4274 {
4275 return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(s32), IOV_GET,
4276 NULL);
4277 }
4278
4279 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4280 int wlc_iovar_setint(struct wlc_info *wlc, const char *name, int arg)
4281 {
4282 return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg),
4283 IOV_SET, NULL);
4284 }
4285
4286 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4287 int wlc_iovar_gets8(struct wlc_info *wlc, const char *name, s8 *arg)
4288 {
4289 int iovar_int;
4290 int err;
4291
4292 err =
4293 wlc_iovar_op(wlc, name, NULL, 0, &iovar_int, sizeof(iovar_int),
4294 IOV_GET, NULL);
4295 if (!err)
4296 *arg = (s8) iovar_int;
4297
4298 return err;
4299 }
4300
4301 /*
4302 * register iovar table, watchdog and down handlers.
4303 * calling function must keep 'iovars' until wlc_module_unregister is called.
4304 * 'iovar' must have the last entry's name field being NULL as terminator.
4305 */
4306 int wlc_module_register(struct wlc_pub *pub, const bcm_iovar_t *iovars,
4307 const char *name, void *hdl, iovar_fn_t i_fn,
4308 watchdog_fn_t w_fn, down_fn_t d_fn)
4309 {
4310 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4311 int i;
4312
4313 ASSERT(name != NULL);
4314 ASSERT(i_fn != NULL || w_fn != NULL || d_fn != NULL);
4315
4316 /* find an empty entry and just add, no duplication check! */
4317 for (i = 0; i < WLC_MAXMODULES; i++) {
4318 if (wlc->modulecb[i].name[0] == '\0') {
4319 strncpy(wlc->modulecb[i].name, name,
4320 sizeof(wlc->modulecb[i].name) - 1);
4321 wlc->modulecb[i].iovars = iovars;
4322 wlc->modulecb[i].hdl = hdl;
4323 wlc->modulecb[i].iovar_fn = i_fn;
4324 wlc->modulecb[i].watchdog_fn = w_fn;
4325 wlc->modulecb[i].down_fn = d_fn;
4326 return 0;
4327 }
4328 }
4329
4330 /* it is time to increase the capacity */
4331 ASSERT(i < WLC_MAXMODULES);
4332 return BCME_NORESOURCE;
4333 }
4334
4335 /* unregister module callbacks */
4336 int wlc_module_unregister(struct wlc_pub *pub, const char *name, void *hdl)
4337 {
4338 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4339 int i;
4340
4341 if (wlc == NULL)
4342 return BCME_NOTFOUND;
4343
4344 ASSERT(name != NULL);
4345
4346 for (i = 0; i < WLC_MAXMODULES; i++) {
4347 if (!strcmp(wlc->modulecb[i].name, name) &&
4348 (wlc->modulecb[i].hdl == hdl)) {
4349 memset(&wlc->modulecb[i], 0, sizeof(struct modulecb));
4350 return 0;
4351 }
4352 }
4353
4354 /* table not found! */
4355 return BCME_NOTFOUND;
4356 }
4357
4358 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4359 static void wlc_wme_retries_write(struct wlc_info *wlc)
4360 {
4361 int ac;
4362
4363 /* Need clock to do this */
4364 if (!wlc->clk)
4365 return;
4366
4367 for (ac = 0; ac < AC_COUNT; ac++) {
4368 wlc_write_shm(wlc, M_AC_TXLMT_ADDR(ac), wlc->wme_retries[ac]);
4369 }
4370 }
4371
4372 /* Get or set an iovar. The params/p_len pair specifies any additional
4373 * qualifying parameters (e.g. an "element index") for a get, while the
4374 * arg/len pair is the buffer for the value to be set or retrieved.
4375 * Operation (get/set) is specified by the last argument.
4376 * interface context provided by wlcif
4377 *
4378 * All pointers may point into the same buffer.
4379 */
4380 int
4381 wlc_iovar_op(struct wlc_info *wlc, const char *name,
4382 void *params, int p_len, void *arg, int len,
4383 bool set, struct wlc_if *wlcif)
4384 {
4385 int err = 0;
4386 int val_size;
4387 const bcm_iovar_t *vi = NULL;
4388 u32 actionid;
4389 int i;
4390
4391 ASSERT(name != NULL);
4392
4393 ASSERT(len >= 0);
4394
4395 /* Get MUST have return space */
4396 ASSERT(set || (arg && len));
4397
4398 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
4399
4400 /* Set does NOT take qualifiers */
4401 ASSERT(!set || (!params && !p_len));
4402
4403 if (!set && (len == sizeof(int)) &&
4404 !(IS_ALIGNED((unsigned long)(arg), (uint) sizeof(int)))) {
4405 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4406 wlc->pub->unit, __func__, name);
4407 ASSERT(0);
4408 }
4409
4410 /* find the given iovar name */
4411 for (i = 0; i < WLC_MAXMODULES; i++) {
4412 if (!wlc->modulecb[i].iovars)
4413 continue;
4414 vi = wlc_iovar_lookup(wlc->modulecb[i].iovars, name);
4415 if (vi)
4416 break;
4417 }
4418 /* iovar name not found */
4419 if (i >= WLC_MAXMODULES) {
4420 err = BCME_UNSUPPORTED;
4421 goto exit;
4422 }
4423
4424 /* set up 'params' pointer in case this is a set command so that
4425 * the convenience int and bool code can be common to set and get
4426 */
4427 if (params == NULL) {
4428 params = arg;
4429 p_len = len;
4430 }
4431
4432 if (vi->type == IOVT_VOID)
4433 val_size = 0;
4434 else if (vi->type == IOVT_BUFFER)
4435 val_size = len;
4436 else
4437 /* all other types are integer sized */
4438 val_size = sizeof(int);
4439
4440 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
4441
4442 /* Do the actual parameter implementation */
4443 err = wlc->modulecb[i].iovar_fn(wlc->modulecb[i].hdl, vi, actionid,
4444 name, params, p_len, arg, len, val_size,
4445 wlcif);
4446
4447 exit:
4448 return err;
4449 }
4450
4451 int
4452 wlc_iovar_check(struct wlc_pub *pub, const bcm_iovar_t *vi, void *arg, int len,
4453 bool set)
4454 {
4455 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4456 int err = 0;
4457 s32 int_val = 0;
4458
4459 /* check generic condition flags */
4460 if (set) {
4461 if (((vi->flags & IOVF_SET_DOWN) && wlc->pub->up) ||
4462 ((vi->flags & IOVF_SET_UP) && !wlc->pub->up)) {
4463 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4464 } else if ((vi->flags & IOVF_SET_BAND)
4465 && IS_MBAND_UNLOCKED(wlc)) {
4466 err = BCME_NOTBANDLOCKED;
4467 } else if ((vi->flags & IOVF_SET_CLK) && !wlc->clk) {
4468 err = BCME_NOCLK;
4469 }
4470 } else {
4471 if (((vi->flags & IOVF_GET_DOWN) && wlc->pub->up) ||
4472 ((vi->flags & IOVF_GET_UP) && !wlc->pub->up)) {
4473 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4474 } else if ((vi->flags & IOVF_GET_BAND)
4475 && IS_MBAND_UNLOCKED(wlc)) {
4476 err = BCME_NOTBANDLOCKED;
4477 } else if ((vi->flags & IOVF_GET_CLK) && !wlc->clk) {
4478 err = BCME_NOCLK;
4479 }
4480 }
4481
4482 if (err)
4483 goto exit;
4484
4485 /* length check on io buf */
4486 err = bcm_iovar_lencheck(vi, arg, len, set);
4487 if (err)
4488 goto exit;
4489
4490 /* On set, check value ranges for integer types */
4491 if (set) {
4492 switch (vi->type) {
4493 case IOVT_BOOL:
4494 case IOVT_INT8:
4495 case IOVT_INT16:
4496 case IOVT_INT32:
4497 case IOVT_UINT8:
4498 case IOVT_UINT16:
4499 case IOVT_UINT32:
4500 memcpy(&int_val, arg, sizeof(int));
4501 err = wlc_iovar_rangecheck(wlc, int_val, vi);
4502 break;
4503 }
4504 }
4505 exit:
4506 return err;
4507 }
4508
4509 /* handler for iovar table wlc_iovars */
4510 /*
4511 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4512 * iovar case, the switch statement maps the iovar id into separate get
4513 * and set values. If you add a new iovar to the switch you MUST use
4514 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4515 * another case.
4516 * Please use params for additional qualifying parameters.
4517 */
4518 int
4519 wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4520 const char *name, void *params, uint p_len, void *arg, int len,
4521 int val_size, struct wlc_if *wlcif)
4522 {
4523 struct wlc_info *wlc = hdl;
4524 wlc_bsscfg_t *bsscfg;
4525 int err = 0;
4526 s32 int_val = 0;
4527 s32 int_val2 = 0;
4528 s32 *ret_int_ptr;
4529 bool bool_val;
4530 bool bool_val2;
4531 wlc_bss_info_t *current_bss;
4532
4533 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
4534
4535 bsscfg = NULL;
4536 current_bss = NULL;
4537
4538 err = wlc_iovar_check(wlc->pub, vi, arg, len, IOV_ISSET(actionid));
4539 if (err != 0)
4540 return err;
4541
4542 /* convenience int and bool vals for first 8 bytes of buffer */
4543 if (p_len >= (int)sizeof(int_val))
4544 memcpy(&int_val, params, sizeof(int_val));
4545
4546 if (p_len >= (int)sizeof(int_val) * 2)
4547 memcpy(&int_val2,
4548 (void *)((unsigned long)params + sizeof(int_val)),
4549 sizeof(int_val));
4550
4551 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4552 ret_int_ptr = (s32 *) arg;
4553
4554 bool_val = (int_val != 0) ? true : false;
4555 bool_val2 = (int_val2 != 0) ? true : false;
4556
4557 WL_TRACE("wl%d: %s: id %d\n",
4558 wlc->pub->unit, __func__, IOV_ID(actionid));
4559 /* Do the actual parameter implementation */
4560 switch (actionid) {
4561 case IOV_SVAL(IOV_RTSTHRESH):
4562 wlc->RTSThresh = int_val;
4563 break;
4564
4565 case IOV_GVAL(IOV_QTXPOWER):{
4566 uint qdbm;
4567 bool override;
4568
4569 err = wlc_phy_txpower_get(wlc->band->pi, &qdbm,
4570 &override);
4571 if (err != BCME_OK)
4572 return err;
4573
4574 /* Return qdbm units */
4575 *ret_int_ptr =
4576 qdbm | (override ? WL_TXPWR_OVERRIDE : 0);
4577 break;
4578 }
4579
4580 /* As long as override is false, this only sets the *user* targets.
4581 User can twiddle this all he wants with no harm.
4582 wlc_phy_txpower_set() explicitly sets override to false if
4583 not internal or test.
4584 */
4585 case IOV_SVAL(IOV_QTXPOWER):{
4586 u8 qdbm;
4587 bool override;
4588
4589 /* Remove override bit and clip to max qdbm value */
4590 qdbm = (u8)min_t(u32, (int_val & ~WL_TXPWR_OVERRIDE), 0xff);
4591 /* Extract override setting */
4592 override = (int_val & WL_TXPWR_OVERRIDE) ? true : false;
4593 err =
4594 wlc_phy_txpower_set(wlc->band->pi, qdbm, override);
4595 break;
4596 }
4597
4598 case IOV_GVAL(IOV_MPC):
4599 *ret_int_ptr = (s32) wlc->mpc;
4600 break;
4601
4602 case IOV_SVAL(IOV_MPC):
4603 wlc->mpc = bool_val;
4604 wlc_radio_mpc_upd(wlc);
4605
4606 break;
4607
4608 case IOV_GVAL(IOV_BCN_LI_BCN):
4609 *ret_int_ptr = wlc->bcn_li_bcn;
4610 break;
4611
4612 case IOV_SVAL(IOV_BCN_LI_BCN):
4613 wlc->bcn_li_bcn = (u8) int_val;
4614 if (wlc->pub->up)
4615 wlc_bcn_li_upd(wlc);
4616 break;
4617
4618 default:
4619 WL_ERROR("wl%d: %s: unsupported\n", wlc->pub->unit, __func__);
4620 err = BCME_UNSUPPORTED;
4621 break;
4622 }
4623
4624 goto exit; /* avoid unused label warning */
4625
4626 exit:
4627 return err;
4628 }
4629
4630 static int
4631 wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val, const bcm_iovar_t *vi)
4632 {
4633 int err = 0;
4634 u32 min_val = 0;
4635 u32 max_val = 0;
4636
4637 /* Only ranged integers are checked */
4638 switch (vi->type) {
4639 case IOVT_INT32:
4640 max_val |= 0x7fffffff;
4641 /* fall through */
4642 case IOVT_INT16:
4643 max_val |= 0x00007fff;
4644 /* fall through */
4645 case IOVT_INT8:
4646 max_val |= 0x0000007f;
4647 min_val = ~max_val;
4648 if (vi->flags & IOVF_NTRL)
4649 min_val = 1;
4650 else if (vi->flags & IOVF_WHL)
4651 min_val = 0;
4652 /* Signed values are checked against max_val and min_val */
4653 if ((s32) val < (s32) min_val
4654 || (s32) val > (s32) max_val)
4655 err = BCME_RANGE;
4656 break;
4657
4658 case IOVT_UINT32:
4659 max_val |= 0xffffffff;
4660 /* fall through */
4661 case IOVT_UINT16:
4662 max_val |= 0x0000ffff;
4663 /* fall through */
4664 case IOVT_UINT8:
4665 max_val |= 0x000000ff;
4666 if (vi->flags & IOVF_NTRL)
4667 min_val = 1;
4668 if ((val < min_val) || (val > max_val))
4669 err = BCME_RANGE;
4670 break;
4671 }
4672
4673 return err;
4674 }
4675
4676 #ifdef BCMDBG
4677 static const char *supr_reason[] = {
4678 "None", "PMQ Entry", "Flush request",
4679 "Previous frag failure", "Channel mismatch",
4680 "Lifetime Expiry", "Underflow"
4681 };
4682
4683 static void wlc_print_txs_status(u16 s)
4684 {
4685 printk(KERN_DEBUG "[15:12] %d frame attempts\n",
4686 (s & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT);
4687 printk(KERN_DEBUG " [11:8] %d rts attempts\n",
4688 (s & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT);
4689 printk(KERN_DEBUG " [7] %d PM mode indicated\n",
4690 ((s & TX_STATUS_PMINDCTD) ? 1 : 0));
4691 printk(KERN_DEBUG " [6] %d intermediate status\n",
4692 ((s & TX_STATUS_INTERMEDIATE) ? 1 : 0));
4693 printk(KERN_DEBUG " [5] %d AMPDU\n",
4694 (s & TX_STATUS_AMPDU) ? 1 : 0);
4695 printk(KERN_DEBUG " [4:2] %d Frame Suppressed Reason (%s)\n",
4696 ((s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT),
4697 supr_reason[(s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT]);
4698 printk(KERN_DEBUG " [1] %d acked\n",
4699 ((s & TX_STATUS_ACK_RCV) ? 1 : 0));
4700 }
4701 #endif /* BCMDBG */
4702
4703 void wlc_print_txstatus(tx_status_t *txs)
4704 {
4705 #if defined(BCMDBG)
4706 u16 s = txs->status;
4707 u16 ackphyrxsh = txs->ackphyrxsh;
4708
4709 printk(KERN_DEBUG "\ntxpkt (MPDU) Complete\n");
4710
4711 printk(KERN_DEBUG "FrameID: %04x ", txs->frameid);
4712 printk(KERN_DEBUG "TxStatus: %04x", s);
4713 printk(KERN_DEBUG "\n");
4714
4715 wlc_print_txs_status(s);
4716
4717 printk(KERN_DEBUG "LastTxTime: %04x ", txs->lasttxtime);
4718 printk(KERN_DEBUG "Seq: %04x ", txs->sequence);
4719 printk(KERN_DEBUG "PHYTxStatus: %04x ", txs->phyerr);
4720 printk(KERN_DEBUG "RxAckRSSI: %04x ",
4721 (ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT);
4722 printk(KERN_DEBUG "RxAckSQ: %04x",
4723 (ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT);
4724 printk(KERN_DEBUG "\n");
4725 #endif /* defined(BCMDBG) */
4726 }
4727
4728 static void
4729 wlc_ctrupd_cache(u16 cur_stat, u16 *macstat_snapshot, u32 *macstat)
4730 {
4731 u16 v;
4732 u16 delta;
4733
4734 v = le16_to_cpu(cur_stat);
4735 delta = (u16)(v - *macstat_snapshot);
4736
4737 if (delta != 0) {
4738 *macstat += delta;
4739 *macstat_snapshot = v;
4740 }
4741 }
4742
4743 #define MACSTATUPD(name) \
4744 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4745
4746 void wlc_statsupd(struct wlc_info *wlc)
4747 {
4748 int i;
4749 macstat_t macstats;
4750 #ifdef BCMDBG
4751 u16 delta;
4752 u16 rxf0ovfl;
4753 u16 txfunfl[NFIFO];
4754 #endif /* BCMDBG */
4755
4756 /* if driver down, make no sense to update stats */
4757 if (!wlc->pub->up)
4758 return;
4759
4760 #ifdef BCMDBG
4761 /* save last rx fifo 0 overflow count */
4762 rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl;
4763
4764 /* save last tx fifo underflow count */
4765 for (i = 0; i < NFIFO; i++)
4766 txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i];
4767 #endif /* BCMDBG */
4768
4769 /* Read mac stats from contiguous shared memory */
4770 wlc_bmac_copyfrom_shm(wlc->hw, M_UCODE_MACSTAT,
4771 &macstats, sizeof(macstat_t));
4772
4773 /* update mac stats */
4774 MACSTATUPD(txallfrm);
4775 MACSTATUPD(txrtsfrm);
4776 MACSTATUPD(txctsfrm);
4777 MACSTATUPD(txackfrm);
4778 MACSTATUPD(txdnlfrm);
4779 MACSTATUPD(txbcnfrm);
4780 for (i = 0; i < NFIFO; i++)
4781 MACSTATUPD(txfunfl[i]);
4782 MACSTATUPD(txtplunfl);
4783 MACSTATUPD(txphyerr);
4784 MACSTATUPD(rxfrmtoolong);
4785 MACSTATUPD(rxfrmtooshrt);
4786 MACSTATUPD(rxinvmachdr);
4787 MACSTATUPD(rxbadfcs);
4788 MACSTATUPD(rxbadplcp);
4789 MACSTATUPD(rxcrsglitch);
4790 MACSTATUPD(rxstrt);
4791 MACSTATUPD(rxdfrmucastmbss);
4792 MACSTATUPD(rxmfrmucastmbss);
4793 MACSTATUPD(rxcfrmucast);
4794 MACSTATUPD(rxrtsucast);
4795 MACSTATUPD(rxctsucast);
4796 MACSTATUPD(rxackucast);
4797 MACSTATUPD(rxdfrmocast);
4798 MACSTATUPD(rxmfrmocast);
4799 MACSTATUPD(rxcfrmocast);
4800 MACSTATUPD(rxrtsocast);
4801 MACSTATUPD(rxctsocast);
4802 MACSTATUPD(rxdfrmmcast);
4803 MACSTATUPD(rxmfrmmcast);
4804 MACSTATUPD(rxcfrmmcast);
4805 MACSTATUPD(rxbeaconmbss);
4806 MACSTATUPD(rxdfrmucastobss);
4807 MACSTATUPD(rxbeaconobss);
4808 MACSTATUPD(rxrsptmout);
4809 MACSTATUPD(bcntxcancl);
4810 MACSTATUPD(rxf0ovfl);
4811 MACSTATUPD(rxf1ovfl);
4812 MACSTATUPD(rxf2ovfl);
4813 MACSTATUPD(txsfovfl);
4814 MACSTATUPD(pmqovfl);
4815 MACSTATUPD(rxcgprqfrm);
4816 MACSTATUPD(rxcgprsqovfl);
4817 MACSTATUPD(txcgprsfail);
4818 MACSTATUPD(txcgprssuc);
4819 MACSTATUPD(prs_timeout);
4820 MACSTATUPD(rxnack);
4821 MACSTATUPD(frmscons);
4822 MACSTATUPD(txnack);
4823 MACSTATUPD(txglitch_nack);
4824 MACSTATUPD(txburst);
4825 MACSTATUPD(phywatchdog);
4826 MACSTATUPD(pktengrxducast);
4827 MACSTATUPD(pktengrxdmcast);
4828
4829 #ifdef BCMDBG
4830 /* check for rx fifo 0 overflow */
4831 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl);
4832 if (delta)
4833 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4834 wlc->pub->unit, delta);
4835
4836 /* check for tx fifo underflows */
4837 for (i = 0; i < NFIFO; i++) {
4838 delta =
4839 (u16) (wlc->core->macstat_snapshot->txfunfl[i] -
4840 txfunfl[i]);
4841 if (delta)
4842 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4843 wlc->pub->unit, delta, i);
4844 }
4845 #endif /* BCMDBG */
4846
4847 /* dot11 counter update */
4848
4849 WLCNTSET(wlc->pub->_cnt->txrts,
4850 (wlc->pub->_cnt->rxctsucast -
4851 wlc->pub->_cnt->d11cnt_txrts_off));
4852 WLCNTSET(wlc->pub->_cnt->rxcrc,
4853 (wlc->pub->_cnt->rxbadfcs - wlc->pub->_cnt->d11cnt_rxcrc_off));
4854 WLCNTSET(wlc->pub->_cnt->txnocts,
4855 ((wlc->pub->_cnt->txrtsfrm - wlc->pub->_cnt->rxctsucast) -
4856 wlc->pub->_cnt->d11cnt_txnocts_off));
4857
4858 /* merge counters from dma module */
4859 for (i = 0; i < NFIFO; i++) {
4860 if (wlc->hw->di[i]) {
4861 WLCNTADD(wlc->pub->_cnt->txnobuf,
4862 (wlc->hw->di[i])->txnobuf);
4863 WLCNTADD(wlc->pub->_cnt->rxnobuf,
4864 (wlc->hw->di[i])->rxnobuf);
4865 WLCNTADD(wlc->pub->_cnt->rxgiant,
4866 (wlc->hw->di[i])->rxgiants);
4867 dma_counterreset(wlc->hw->di[i]);
4868 }
4869 }
4870
4871 /*
4872 * Aggregate transmit and receive errors that probably resulted
4873 * in the loss of a frame are computed on the fly.
4874 */
4875 WLCNTSET(wlc->pub->_cnt->txerror,
4876 wlc->pub->_cnt->txnobuf + wlc->pub->_cnt->txnoassoc +
4877 wlc->pub->_cnt->txuflo + wlc->pub->_cnt->txrunt +
4878 wlc->pub->_cnt->dmade + wlc->pub->_cnt->dmada +
4879 wlc->pub->_cnt->dmape);
4880 WLCNTSET(wlc->pub->_cnt->rxerror,
4881 wlc->pub->_cnt->rxoflo + wlc->pub->_cnt->rxnobuf +
4882 wlc->pub->_cnt->rxfragerr + wlc->pub->_cnt->rxrunt +
4883 wlc->pub->_cnt->rxgiant + wlc->pub->_cnt->rxnoscb +
4884 wlc->pub->_cnt->rxbadsrcmac);
4885 for (i = 0; i < NFIFO; i++)
4886 wlc->pub->_cnt->rxerror += wlc->pub->_cnt->rxuflo[i];
4887 }
4888
4889 bool wlc_chipmatch(u16 vendor, u16 device)
4890 {
4891 if (vendor != VENDOR_BROADCOM) {
4892 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor);
4893 return false;
4894 }
4895
4896 if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID))
4897 return true;
4898
4899 if (device == BCM4313_D11N2G_ID)
4900 return true;
4901 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID))
4902 return true;
4903
4904 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device);
4905 return false;
4906 }
4907
4908 #if defined(BCMDBG)
4909 void wlc_print_txdesc(d11txh_t *txh)
4910 {
4911 u16 mtcl = le16_to_cpu(txh->MacTxControlLow);
4912 u16 mtch = le16_to_cpu(txh->MacTxControlHigh);
4913 u16 mfc = le16_to_cpu(txh->MacFrameControl);
4914 u16 tfest = le16_to_cpu(txh->TxFesTimeNormal);
4915 u16 ptcw = le16_to_cpu(txh->PhyTxControlWord);
4916 u16 ptcw_1 = le16_to_cpu(txh->PhyTxControlWord_1);
4917 u16 ptcw_1_Fbr = le16_to_cpu(txh->PhyTxControlWord_1_Fbr);
4918 u16 ptcw_1_Rts = le16_to_cpu(txh->PhyTxControlWord_1_Rts);
4919 u16 ptcw_1_FbrRts = le16_to_cpu(txh->PhyTxControlWord_1_FbrRts);
4920 u16 mainrates = le16_to_cpu(txh->MainRates);
4921 u16 xtraft = le16_to_cpu(txh->XtraFrameTypes);
4922 u8 *iv = txh->IV;
4923 u8 *ra = txh->TxFrameRA;
4924 u16 tfestfb = le16_to_cpu(txh->TxFesTimeFallback);
4925 u8 *rtspfb = txh->RTSPLCPFallback;
4926 u16 rtsdfb = le16_to_cpu(txh->RTSDurFallback);
4927 u8 *fragpfb = txh->FragPLCPFallback;
4928 u16 fragdfb = le16_to_cpu(txh->FragDurFallback);
4929 u16 mmodelen = le16_to_cpu(txh->MModeLen);
4930 u16 mmodefbrlen = le16_to_cpu(txh->MModeFbrLen);
4931 u16 tfid = le16_to_cpu(txh->TxFrameID);
4932 u16 txs = le16_to_cpu(txh->TxStatus);
4933 u16 mnmpdu = le16_to_cpu(txh->MaxNMpdus);
4934 u16 mabyte = le16_to_cpu(txh->MaxABytes_MRT);
4935 u16 mabyte_f = le16_to_cpu(txh->MaxABytes_FBR);
4936 u16 mmbyte = le16_to_cpu(txh->MinMBytes);
4937
4938 u8 *rtsph = txh->RTSPhyHeader;
4939 struct ieee80211_rts rts = txh->rts_frame;
4940 char hexbuf[256];
4941
4942 /* add plcp header along with txh descriptor */
4943 prhex("Raw TxDesc + plcp header", (unsigned char *) txh, sizeof(d11txh_t) + 48);
4944
4945 printk(KERN_DEBUG "TxCtlLow: %04x ", mtcl);
4946 printk(KERN_DEBUG "TxCtlHigh: %04x ", mtch);
4947 printk(KERN_DEBUG "FC: %04x ", mfc);
4948 printk(KERN_DEBUG "FES Time: %04x\n", tfest);
4949 printk(KERN_DEBUG "PhyCtl: %04x%s ", ptcw,
4950 (ptcw & PHY_TXC_SHORT_HDR) ? " short" : "");
4951 printk(KERN_DEBUG "PhyCtl_1: %04x ", ptcw_1);
4952 printk(KERN_DEBUG "PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr);
4953 printk(KERN_DEBUG "PhyCtl_1_Rts: %04x ", ptcw_1_Rts);
4954 printk(KERN_DEBUG "PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts);
4955 printk(KERN_DEBUG "MainRates: %04x ", mainrates);
4956 printk(KERN_DEBUG "XtraFrameTypes: %04x ", xtraft);
4957 printk(KERN_DEBUG "\n");
4958
4959 bcm_format_hex(hexbuf, iv, sizeof(txh->IV));
4960 printk(KERN_DEBUG "SecIV: %s\n", hexbuf);
4961 bcm_format_hex(hexbuf, ra, sizeof(txh->TxFrameRA));
4962 printk(KERN_DEBUG "RA: %s\n", hexbuf);
4963
4964 printk(KERN_DEBUG "Fb FES Time: %04x ", tfestfb);
4965 bcm_format_hex(hexbuf, rtspfb, sizeof(txh->RTSPLCPFallback));
4966 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
4967 printk(KERN_DEBUG "RTS DUR: %04x ", rtsdfb);
4968 bcm_format_hex(hexbuf, fragpfb, sizeof(txh->FragPLCPFallback));
4969 printk(KERN_DEBUG "PLCP: %s ", hexbuf);
4970 printk(KERN_DEBUG "DUR: %04x", fragdfb);
4971 printk(KERN_DEBUG "\n");
4972
4973 printk(KERN_DEBUG "MModeLen: %04x ", mmodelen);
4974 printk(KERN_DEBUG "MModeFbrLen: %04x\n", mmodefbrlen);
4975
4976 printk(KERN_DEBUG "FrameID: %04x\n", tfid);
4977 printk(KERN_DEBUG "TxStatus: %04x\n", txs);
4978
4979 printk(KERN_DEBUG "MaxNumMpdu: %04x\n", mnmpdu);
4980 printk(KERN_DEBUG "MaxAggbyte: %04x\n", mabyte);
4981 printk(KERN_DEBUG "MaxAggbyte_fb: %04x\n", mabyte_f);
4982 printk(KERN_DEBUG "MinByte: %04x\n", mmbyte);
4983
4984 bcm_format_hex(hexbuf, rtsph, sizeof(txh->RTSPhyHeader));
4985 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
4986 bcm_format_hex(hexbuf, (u8 *) &rts, sizeof(txh->rts_frame));
4987 printk(KERN_DEBUG "RTS Frame: %s", hexbuf);
4988 printk(KERN_DEBUG "\n");
4989 }
4990 #endif /* defined(BCMDBG) */
4991
4992 #if defined(BCMDBG)
4993 void wlc_print_rxh(d11rxhdr_t *rxh)
4994 {
4995 u16 len = rxh->RxFrameSize;
4996 u16 phystatus_0 = rxh->PhyRxStatus_0;
4997 u16 phystatus_1 = rxh->PhyRxStatus_1;
4998 u16 phystatus_2 = rxh->PhyRxStatus_2;
4999 u16 phystatus_3 = rxh->PhyRxStatus_3;
5000 u16 macstatus1 = rxh->RxStatus1;
5001 u16 macstatus2 = rxh->RxStatus2;
5002 char flagstr[64];
5003 char lenbuf[20];
5004 static const bcm_bit_desc_t macstat_flags[] = {
5005 {RXS_FCSERR, "FCSErr"},
5006 {RXS_RESPFRAMETX, "Reply"},
5007 {RXS_PBPRES, "PADDING"},
5008 {RXS_DECATMPT, "DeCr"},
5009 {RXS_DECERR, "DeCrErr"},
5010 {RXS_BCNSENT, "Bcn"},
5011 {0, NULL}
5012 };
5013
5014 prhex("Raw RxDesc", (unsigned char *) rxh, sizeof(d11rxhdr_t));
5015
5016 bcm_format_flags(macstat_flags, macstatus1, flagstr, 64);
5017
5018 snprintf(lenbuf, sizeof(lenbuf), "0x%x", len);
5019
5020 printk(KERN_DEBUG "RxFrameSize: %6s (%d)%s\n", lenbuf, len,
5021 (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : "");
5022 printk(KERN_DEBUG "RxPHYStatus: %04x %04x %04x %04x\n",
5023 phystatus_0, phystatus_1, phystatus_2, phystatus_3);
5024 printk(KERN_DEBUG "RxMACStatus: %x %s\n", macstatus1, flagstr);
5025 printk(KERN_DEBUG "RXMACaggtype: %x\n",
5026 (macstatus2 & RXS_AGGTYPE_MASK));
5027 printk(KERN_DEBUG "RxTSFTime: %04x\n", rxh->RxTSFTime);
5028 }
5029 #endif /* defined(BCMDBG) */
5030
5031 #if defined(BCMDBG)
5032 int wlc_format_ssid(char *buf, const unsigned char ssid[], uint ssid_len)
5033 {
5034 uint i, c;
5035 char *p = buf;
5036 char *endp = buf + SSID_FMT_BUF_LEN;
5037
5038 if (ssid_len > IEEE80211_MAX_SSID_LEN)
5039 ssid_len = IEEE80211_MAX_SSID_LEN;
5040
5041 for (i = 0; i < ssid_len; i++) {
5042 c = (uint) ssid[i];
5043 if (c == '\\') {
5044 *p++ = '\\';
5045 *p++ = '\\';
5046 } else if (isprint((unsigned char) c)) {
5047 *p++ = (char)c;
5048 } else {
5049 p += snprintf(p, (endp - p), "\\x%02X", c);
5050 }
5051 }
5052 *p = '\0';
5053 ASSERT(p < endp);
5054
5055 return (int)(p - buf);
5056 }
5057 #endif /* defined(BCMDBG) */
5058
5059 static u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate)
5060 {
5061 return wlc_bmac_rate_shm_offset(wlc->hw, rate);
5062 }
5063
5064 /* Callback for device removed */
5065
5066 /*
5067 * Attempts to queue a packet onto a multiple-precedence queue,
5068 * if necessary evicting a lower precedence packet from the queue.
5069 *
5070 * 'prec' is the precedence number that has already been mapped
5071 * from the packet priority.
5072 *
5073 * Returns true if packet consumed (queued), false if not.
5074 */
5075 bool BCMFASTPATH
5076 wlc_prec_enq(struct wlc_info *wlc, struct pktq *q, void *pkt, int prec)
5077 {
5078 return wlc_prec_enq_head(wlc, q, pkt, prec, false);
5079 }
5080
5081 bool BCMFASTPATH
5082 wlc_prec_enq_head(struct wlc_info *wlc, struct pktq *q, struct sk_buff *pkt,
5083 int prec, bool head)
5084 {
5085 struct sk_buff *p;
5086 int eprec = -1; /* precedence to evict from */
5087
5088 /* Determine precedence from which to evict packet, if any */
5089 if (pktq_pfull(q, prec))
5090 eprec = prec;
5091 else if (pktq_full(q)) {
5092 p = pktq_peek_tail(q, &eprec);
5093 ASSERT(p != NULL);
5094 if (eprec > prec) {
5095 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5096 __func__, eprec, prec);
5097 return false;
5098 }
5099 }
5100
5101 /* Evict if needed */
5102 if (eprec >= 0) {
5103 bool discard_oldest;
5104
5105 /* Detect queueing to unconfigured precedence */
5106 ASSERT(!pktq_pempty(q, eprec));
5107
5108 discard_oldest = AC_BITMAP_TST(wlc->wme_dp, eprec);
5109
5110 /* Refuse newer packet unless configured to discard oldest */
5111 if (eprec == prec && !discard_oldest) {
5112 WL_ERROR("%s: No where to go, prec == %d\n",
5113 __func__, prec);
5114 return false;
5115 }
5116
5117 /* Evict packet according to discard policy */
5118 p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q,
5119 eprec);
5120 ASSERT(p != NULL);
5121
5122 /* Increment wme stats */
5123 if (WME_ENAB(wlc->pub)) {
5124 WLCNTINCR(wlc->pub->_wme_cnt->
5125 tx_failed[WME_PRIO2AC(p->priority)].packets);
5126 WLCNTADD(wlc->pub->_wme_cnt->
5127 tx_failed[WME_PRIO2AC(p->priority)].bytes,
5128 pkttotlen(p));
5129 }
5130 pkt_buf_free_skb(wlc->osh, p, true);
5131 wlc->pub->_cnt->txnobuf++;
5132 }
5133
5134 /* Enqueue */
5135 if (head)
5136 p = pktq_penq_head(q, prec, pkt);
5137 else
5138 p = pktq_penq(q, prec, pkt);
5139 ASSERT(p != NULL);
5140
5141 return true;
5142 }
5143
5144 void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu,
5145 uint prec)
5146 {
5147 struct wlc_info *wlc = (struct wlc_info *) ctx;
5148 struct wlc_txq_info *qi = wlc->active_queue; /* Check me */
5149 struct pktq *q = &qi->q;
5150 int prio;
5151
5152 prio = sdu->priority;
5153
5154 ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat);
5155
5156 if (!wlc_prec_enq(wlc, q, sdu, prec)) {
5157 if (!EDCF_ENAB(wlc->pub)
5158 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL))
5159 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5160 wlc->pub->unit);
5161
5162 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5163 pkt_buf_free_skb(wlc->osh, sdu, true);
5164 wlc->pub->_cnt->txnobuf++;
5165 }
5166
5167 /* Check if flow control needs to be turned on after enqueuing the packet
5168 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5169 * to drop instead of relying on stack to make the right decision
5170 */
5171 if (!EDCF_ENAB(wlc->pub)
5172 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5173 if (pktq_len(q) >= wlc->pub->tunables->datahiwat) {
5174 wlc_txflowcontrol(wlc, qi, ON, ALLPRIO);
5175 }
5176 } else if (wlc->pub->_priofc) {
5177 if (pktq_plen(q, wlc_prio2prec_map[prio]) >=
5178 wlc->pub->tunables->datahiwat) {
5179 wlc_txflowcontrol(wlc, qi, ON, prio);
5180 }
5181 }
5182 }
5183
5184 bool BCMFASTPATH
5185 wlc_sendpkt_mac80211(struct wlc_info *wlc, struct sk_buff *sdu,
5186 struct ieee80211_hw *hw)
5187 {
5188 u8 prio;
5189 uint fifo;
5190 void *pkt;
5191 struct scb *scb = &global_scb;
5192 struct ieee80211_hdr *d11_header = (struct ieee80211_hdr *)(sdu->data);
5193 u16 type, fc;
5194
5195 ASSERT(sdu);
5196
5197 fc = le16_to_cpu(d11_header->frame_control);
5198 type = (fc & IEEE80211_FCTL_FTYPE);
5199
5200 /* 802.11 standard requires management traffic to go at highest priority */
5201 prio = (type == IEEE80211_FTYPE_DATA ? sdu->priority : MAXPRIO);
5202 fifo = prio2fifo[prio];
5203
5204 ASSERT((uint) skb_headroom(sdu) >= TXOFF);
5205 ASSERT(!(sdu->next));
5206 ASSERT(!(sdu->prev));
5207 ASSERT(fifo < NFIFO);
5208
5209 pkt = sdu;
5210 if (unlikely
5211 (wlc_d11hdrs_mac80211(wlc, hw, pkt, scb, 0, 1, fifo, 0, NULL, 0)))
5212 return -EINVAL;
5213 wlc_txq_enq(wlc, scb, pkt, WLC_PRIO_TO_PREC(prio));
5214 wlc_send_q(wlc, wlc->active_queue);
5215
5216 wlc->pub->_cnt->ieee_tx++;
5217 return 0;
5218 }
5219
5220 void BCMFASTPATH wlc_send_q(struct wlc_info *wlc, struct wlc_txq_info *qi)
5221 {
5222 struct sk_buff *pkt[DOT11_MAXNUMFRAGS];
5223 int prec;
5224 u16 prec_map;
5225 int err = 0, i, count;
5226 uint fifo;
5227 struct pktq *q = &qi->q;
5228 struct ieee80211_tx_info *tx_info;
5229
5230 /* only do work for the active queue */
5231 if (qi != wlc->active_queue)
5232 return;
5233
5234 if (in_send_q)
5235 return;
5236 else
5237 in_send_q = true;
5238
5239 prec_map = wlc->tx_prec_map;
5240
5241 /* Send all the enq'd pkts that we can.
5242 * Dequeue packets with precedence with empty HW fifo only
5243 */
5244 while (prec_map && (pkt[0] = pktq_mdeq(q, prec_map, &prec))) {
5245 tx_info = IEEE80211_SKB_CB(pkt[0]);
5246 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
5247 err = wlc_sendampdu(wlc->ampdu, qi, pkt, prec);
5248 } else {
5249 count = 1;
5250 err = wlc_prep_pdu(wlc, pkt[0], &fifo);
5251 if (!err) {
5252 for (i = 0; i < count; i++) {
5253 wlc_txfifo(wlc, fifo, pkt[i], true, 1);
5254 }
5255 }
5256 }
5257
5258 if (err == BCME_BUSY) {
5259 pktq_penq_head(q, prec, pkt[0]);
5260 /* If send failed due to any other reason than a change in
5261 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5262 */
5263 if (prec_map == wlc->tx_prec_map)
5264 break;
5265 prec_map = wlc->tx_prec_map;
5266 }
5267 }
5268
5269 /* Check if flow control needs to be turned off after sending the packet */
5270 if (!EDCF_ENAB(wlc->pub)
5271 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5272 if (wlc_txflowcontrol_prio_isset(wlc, qi, ALLPRIO)
5273 && (pktq_len(q) < wlc->pub->tunables->datahiwat / 2)) {
5274 wlc_txflowcontrol(wlc, qi, OFF, ALLPRIO);
5275 }
5276 } else if (wlc->pub->_priofc) {
5277 int prio;
5278 for (prio = MAXPRIO; prio >= 0; prio--) {
5279 if (wlc_txflowcontrol_prio_isset(wlc, qi, prio) &&
5280 (pktq_plen(q, wlc_prio2prec_map[prio]) <
5281 wlc->pub->tunables->datahiwat / 2)) {
5282 wlc_txflowcontrol(wlc, qi, OFF, prio);
5283 }
5284 }
5285 }
5286 in_send_q = false;
5287 }
5288
5289 /*
5290 * bcmc_fid_generate:
5291 * Generate frame ID for a BCMC packet. The frag field is not used
5292 * for MC frames so is used as part of the sequence number.
5293 */
5294 static inline u16
5295 bcmc_fid_generate(struct wlc_info *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh)
5296 {
5297 u16 frameid;
5298
5299 frameid = le16_to_cpu(txh->TxFrameID) & ~(TXFID_SEQ_MASK |
5300 TXFID_QUEUE_MASK);
5301 frameid |=
5302 (((wlc->
5303 mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5304 TX_BCMC_FIFO;
5305
5306 return frameid;
5307 }
5308
5309 void BCMFASTPATH
5310 wlc_txfifo(struct wlc_info *wlc, uint fifo, struct sk_buff *p, bool commit,
5311 s8 txpktpend)
5312 {
5313 u16 frameid = INVALIDFID;
5314 d11txh_t *txh;
5315
5316 ASSERT(fifo < NFIFO);
5317 txh = (d11txh_t *) (p->data);
5318
5319 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5320 * ucode or BSS info as appropriate.
5321 */
5322 if (fifo == TX_BCMC_FIFO) {
5323 frameid = le16_to_cpu(txh->TxFrameID);
5324
5325 }
5326
5327 if (WLC_WAR16165(wlc))
5328 wlc_war16165(wlc, true);
5329
5330
5331 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5332 * in wlc_bmac_txfifo()
5333 */
5334 if (commit) {
5335 TXPKTPENDINC(wlc, fifo, txpktpend);
5336 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5337 txpktpend, TXPKTPENDGET(wlc, fifo));
5338 }
5339
5340 /* Commit BCMC sequence number in the SHM frame ID location */
5341 if (frameid != INVALIDFID)
5342 BCMCFID(wlc, frameid);
5343
5344 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) {
5345 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5346 }
5347 }
5348
5349 static u16
5350 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec, uint length)
5351 {
5352 u16 usec = 0;
5353 uint mac_rate = RSPEC2RATE(rspec);
5354 uint nsyms;
5355
5356 if (IS_MCS(rspec)) {
5357 /* not supported yet */
5358 ASSERT(0);
5359 } else if (IS_OFDM(rspec)) {
5360 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5361 *
5362 * Nbits = length * 8
5363 * Nbits/sym = Mbps * 4 = mac_rate * 2
5364 */
5365 nsyms = CEIL((length * 8), (mac_rate * 2));
5366
5367 /* usec = symbols * usec/symbol */
5368 usec = (u16) (nsyms * APHY_SYMBOL_TIME);
5369 return usec;
5370 } else {
5371 switch (mac_rate) {
5372 case WLC_RATE_1M:
5373 usec = length << 3;
5374 break;
5375 case WLC_RATE_2M:
5376 usec = length << 2;
5377 break;
5378 case WLC_RATE_5M5:
5379 usec = (length << 4) / 11;
5380 break;
5381 case WLC_RATE_11M:
5382 usec = (length << 3) / 11;
5383 break;
5384 default:
5385 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5386 wlc->pub->unit, rspec);
5387 ASSERT((const char *)"Bad phy_rate" == NULL);
5388 break;
5389 }
5390 }
5391
5392 return usec;
5393 }
5394
5395 void BCMFASTPATH
5396 wlc_compute_plcp(struct wlc_info *wlc, ratespec_t rspec, uint length, u8 *plcp)
5397 {
5398 if (IS_MCS(rspec)) {
5399 wlc_compute_mimo_plcp(rspec, length, plcp);
5400 } else if (IS_OFDM(rspec)) {
5401 wlc_compute_ofdm_plcp(rspec, length, plcp);
5402 } else {
5403 wlc_compute_cck_plcp(rspec, length, plcp);
5404 }
5405 return;
5406 }
5407
5408 /* Rate: 802.11 rate code, length: PSDU length in octets */
5409 static void wlc_compute_mimo_plcp(ratespec_t rspec, uint length, u8 *plcp)
5410 {
5411 u8 mcs = (u8) (rspec & RSPEC_RATE_MASK);
5412 ASSERT(IS_MCS(rspec));
5413 plcp[0] = mcs;
5414 if (RSPEC_IS40MHZ(rspec) || (mcs == 32))
5415 plcp[0] |= MIMO_PLCP_40MHZ;
5416 WLC_SET_MIMO_PLCP_LEN(plcp, length);
5417 plcp[3] = RSPEC_MIMOPLCP3(rspec); /* rspec already holds this byte */
5418 plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5419 plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5420 plcp[5] = 0;
5421 }
5422
5423 /* Rate: 802.11 rate code, length: PSDU length in octets */
5424 static void BCMFASTPATH
5425 wlc_compute_ofdm_plcp(ratespec_t rspec, u32 length, u8 *plcp)
5426 {
5427 u8 rate_signal;
5428 u32 tmp = 0;
5429 int rate = RSPEC2RATE(rspec);
5430
5431 ASSERT(IS_OFDM(rspec));
5432
5433 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5434 rate_signal = rate_info[rate] & RATE_MASK;
5435 ASSERT(rate_signal != 0);
5436
5437 memset(plcp, 0, D11_PHY_HDR_LEN);
5438 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal);
5439
5440 tmp = (length & 0xfff) << 5;
5441 plcp[2] |= (tmp >> 16) & 0xff;
5442 plcp[1] |= (tmp >> 8) & 0xff;
5443 plcp[0] |= tmp & 0xff;
5444
5445 return;
5446 }
5447
5448 /*
5449 * Compute PLCP, but only requires actual rate and length of pkt.
5450 * Rate is given in the driver standard multiple of 500 kbps.
5451 * le is set for 11 Mbps rate if necessary.
5452 * Broken out for PRQ.
5453 */
5454
5455 static void wlc_cck_plcp_set(int rate_500, uint length, u8 *plcp)
5456 {
5457 u16 usec = 0;
5458 u8 le = 0;
5459
5460 switch (rate_500) {
5461 case WLC_RATE_1M:
5462 usec = length << 3;
5463 break;
5464 case WLC_RATE_2M:
5465 usec = length << 2;
5466 break;
5467 case WLC_RATE_5M5:
5468 usec = (length << 4) / 11;
5469 if ((length << 4) - (usec * 11) > 0)
5470 usec++;
5471 break;
5472 case WLC_RATE_11M:
5473 usec = (length << 3) / 11;
5474 if ((length << 3) - (usec * 11) > 0) {
5475 usec++;
5476 if ((usec * 11) - (length << 3) >= 8)
5477 le = D11B_PLCP_SIGNAL_LE;
5478 }
5479 break;
5480
5481 default:
5482 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500);
5483 rate_500 = WLC_RATE_1M;
5484 usec = length << 3;
5485 break;
5486 }
5487 /* PLCP signal byte */
5488 plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */
5489 /* PLCP service byte */
5490 plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED);
5491 /* PLCP length u16, little endian */
5492 plcp[2] = usec & 0xff;
5493 plcp[3] = (usec >> 8) & 0xff;
5494 /* PLCP CRC16 */
5495 plcp[4] = 0;
5496 plcp[5] = 0;
5497 }
5498
5499 /* Rate: 802.11 rate code, length: PSDU length in octets */
5500 static void wlc_compute_cck_plcp(ratespec_t rspec, uint length, u8 *plcp)
5501 {
5502 int rate = RSPEC2RATE(rspec);
5503
5504 ASSERT(IS_CCK(rspec));
5505
5506 wlc_cck_plcp_set(rate, length, plcp);
5507 }
5508
5509 /* wlc_compute_frame_dur()
5510 *
5511 * Calculate the 802.11 MAC header DUR field for MPDU
5512 * DUR for a single frame = 1 SIFS + 1 ACK
5513 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5514 *
5515 * rate MPDU rate in unit of 500kbps
5516 * next_frag_len next MPDU length in bytes
5517 * preamble_type use short/GF or long/MM PLCP header
5518 */
5519 static u16 BCMFASTPATH
5520 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate, u8 preamble_type,
5521 uint next_frag_len)
5522 {
5523 u16 dur, sifs;
5524
5525 sifs = SIFS(wlc->band);
5526
5527 dur = sifs;
5528 dur += (u16) wlc_calc_ack_time(wlc, rate, preamble_type);
5529
5530 if (next_frag_len) {
5531 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5532 dur *= 2;
5533 /* add another SIFS and the frag time */
5534 dur += sifs;
5535 dur +=
5536 (u16) wlc_calc_frame_time(wlc, rate, preamble_type,
5537 next_frag_len);
5538 }
5539 return dur;
5540 }
5541
5542 /* wlc_compute_rtscts_dur()
5543 *
5544 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5545 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5546 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5547 *
5548 * cts cts-to-self or rts/cts
5549 * rts_rate rts or cts rate in unit of 500kbps
5550 * rate next MPDU rate in unit of 500kbps
5551 * frame_len next MPDU frame length in bytes
5552 */
5553 u16 BCMFASTPATH
5554 wlc_compute_rtscts_dur(struct wlc_info *wlc, bool cts_only, ratespec_t rts_rate,
5555 ratespec_t frame_rate, u8 rts_preamble_type,
5556 u8 frame_preamble_type, uint frame_len, bool ba)
5557 {
5558 u16 dur, sifs;
5559
5560 sifs = SIFS(wlc->band);
5561
5562 if (!cts_only) { /* RTS/CTS */
5563 dur = 3 * sifs;
5564 dur +=
5565 (u16) wlc_calc_cts_time(wlc, rts_rate,
5566 rts_preamble_type);
5567 } else { /* CTS-TO-SELF */
5568 dur = 2 * sifs;
5569 }
5570
5571 dur +=
5572 (u16) wlc_calc_frame_time(wlc, frame_rate, frame_preamble_type,
5573 frame_len);
5574 if (ba)
5575 dur +=
5576 (u16) wlc_calc_ba_time(wlc, frame_rate,
5577 WLC_SHORT_PREAMBLE);
5578 else
5579 dur +=
5580 (u16) wlc_calc_ack_time(wlc, frame_rate,
5581 frame_preamble_type);
5582 return dur;
5583 }
5584
5585 static bool wlc_phy_rspec_check(struct wlc_info *wlc, u16 bw, ratespec_t rspec)
5586 {
5587 if (IS_MCS(rspec)) {
5588 uint mcs = rspec & RSPEC_RATE_MASK;
5589
5590 if (mcs < 8) {
5591 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5592 } else if ((mcs >= 8) && (mcs <= 23)) {
5593 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SDM);
5594 } else if (mcs == 32) {
5595 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5596 ASSERT(bw == PHY_TXC1_BW_40MHZ_DUP);
5597 }
5598 } else if (IS_OFDM(rspec)) {
5599 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_STBC);
5600 } else {
5601 ASSERT(IS_CCK(rspec));
5602
5603 ASSERT((bw == PHY_TXC1_BW_20MHZ)
5604 || (bw == PHY_TXC1_BW_20MHZ_UP));
5605 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SISO);
5606 }
5607
5608 return true;
5609 }
5610
5611 u16 BCMFASTPATH wlc_phytxctl1_calc(struct wlc_info *wlc, ratespec_t rspec)
5612 {
5613 u16 phyctl1 = 0;
5614 u16 bw;
5615
5616 if (WLCISLCNPHY(wlc->band)) {
5617 bw = PHY_TXC1_BW_20MHZ;
5618 } else {
5619 bw = RSPEC_GET_BW(rspec);
5620 /* 10Mhz is not supported yet */
5621 if (bw < PHY_TXC1_BW_20MHZ) {
5622 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5623 bw);
5624 bw = PHY_TXC1_BW_20MHZ;
5625 }
5626
5627 wlc_phy_rspec_check(wlc, bw, rspec);
5628 }
5629
5630 if (IS_MCS(rspec)) {
5631 uint mcs = rspec & RSPEC_RATE_MASK;
5632
5633 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5634 phyctl1 = RSPEC_PHYTXBYTE2(rspec);
5635 /* set the upper byte of phyctl1 */
5636 phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8);
5637 } else if (IS_CCK(rspec) && !WLCISLCNPHY(wlc->band)
5638 && !WLCISSSLPNPHY(wlc->band)) {
5639 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5640 /* Eventually MIMOPHY would also be converted to this format */
5641 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5642 phyctl1 = (bw | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5643 } else { /* legacy OFDM/CCK */
5644 s16 phycfg;
5645 /* get the phyctl byte from rate phycfg table */
5646 phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec));
5647 if (phycfg == -1) {
5648 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5649 ASSERT(0);
5650 phycfg = 0;
5651 }
5652 /* set the upper byte of phyctl1 */
5653 phyctl1 =
5654 (bw | (phycfg << 8) |
5655 (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5656 }
5657
5658 #ifdef BCMDBG
5659 /* phy clock must support 40Mhz if tx descriptor uses it */
5660 if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) {
5661 ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ);
5662 ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi));
5663 }
5664 #endif /* BCMDBG */
5665 return phyctl1;
5666 }
5667
5668 ratespec_t BCMFASTPATH
5669 wlc_rspec_to_rts_rspec(struct wlc_info *wlc, ratespec_t rspec, bool use_rspec,
5670 u16 mimo_ctlchbw)
5671 {
5672 ratespec_t rts_rspec = 0;
5673
5674 if (use_rspec) {
5675 /* use frame rate as rts rate */
5676 rts_rspec = rspec;
5677
5678 } else if (wlc->band->gmode && wlc->protection->_g && !IS_CCK(rspec)) {
5679 /* Use 11Mbps as the g protection RTS target rate and fallback.
5680 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5681 * target in case 11 Mbps is not Basic.
5682 * 6 and 9 Mbps are not usually selected by rate selection, but even
5683 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5684 */
5685 rts_rspec = WLC_BASIC_RATE(wlc, WLC_RATE_11M);
5686 } else {
5687 /* calculate RTS rate and fallback rate based on the frame rate
5688 * RTS must be sent at a basic rate since it is a
5689 * control frame, sec 9.6 of 802.11 spec
5690 */
5691 rts_rspec = WLC_BASIC_RATE(wlc, rspec);
5692 }
5693
5694 if (WLC_PHY_11N_CAP(wlc->band)) {
5695 /* set rts txbw to correct side band */
5696 rts_rspec &= ~RSPEC_BW_MASK;
5697
5698 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5699 * (DUP), otherwise send RTS on control channel
5700 */
5701 if (RSPEC_IS40MHZ(rspec) && !IS_CCK(rts_rspec))
5702 rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT);
5703 else
5704 rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5705
5706 /* pick siso/cdd as default for ofdm */
5707 if (IS_OFDM(rts_rspec)) {
5708 rts_rspec &= ~RSPEC_STF_MASK;
5709 rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
5710 }
5711 }
5712 return rts_rspec;
5713 }
5714
5715 /*
5716 * Add d11txh_t, cck_phy_hdr_t.
5717 *
5718 * 'p' data must start with 802.11 MAC header
5719 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5720 *
5721 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5722 *
5723 */
5724 static u16 BCMFASTPATH
5725 wlc_d11hdrs_mac80211(struct wlc_info *wlc, struct ieee80211_hw *hw,
5726 struct sk_buff *p, struct scb *scb, uint frag,
5727 uint nfrags, uint queue, uint next_frag_len,
5728 wsec_key_t *key, ratespec_t rspec_override)
5729 {
5730 struct ieee80211_hdr *h;
5731 d11txh_t *txh;
5732 u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN];
5733 struct osl_info *osh;
5734 int len, phylen, rts_phylen;
5735 u16 fc, type, frameid, mch, phyctl, xfts, mainrates;
5736 u16 seq = 0, mcl = 0, status = 0;
5737 ratespec_t rspec[2] = { WLC_RATE_1M, WLC_RATE_1M }, rts_rspec[2] = {
5738 WLC_RATE_1M, WLC_RATE_1M};
5739 bool use_rts = false;
5740 bool use_cts = false;
5741 bool use_rifs = false;
5742 bool short_preamble[2] = { false, false };
5743 u8 preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5744 u8 rts_preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5745 u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN];
5746 struct ieee80211_rts *rts = NULL;
5747 bool qos;
5748 uint ac;
5749 u32 rate_val[2];
5750 bool hwtkmic = false;
5751 u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
5752 #define ANTCFG_NONE 0xFF
5753 u8 antcfg = ANTCFG_NONE;
5754 u8 fbantcfg = ANTCFG_NONE;
5755 uint phyctl1_stf = 0;
5756 u16 durid = 0;
5757 struct ieee80211_tx_rate *txrate[2];
5758 int k;
5759 struct ieee80211_tx_info *tx_info;
5760 bool is_mcs[2];
5761 u16 mimo_txbw;
5762 u8 mimo_preamble_type;
5763
5764 frameid = 0;
5765
5766 ASSERT(queue < NFIFO);
5767
5768 osh = wlc->osh;
5769
5770 /* locate 802.11 MAC header */
5771 h = (struct ieee80211_hdr *)(p->data);
5772 fc = le16_to_cpu(h->frame_control);
5773 type = (fc & IEEE80211_FCTL_FTYPE);
5774
5775 qos = (type == IEEE80211_FTYPE_DATA &&
5776 FC_SUBTYPE_ANY_QOS(fc));
5777
5778 /* compute length of frame in bytes for use in PLCP computations */
5779 len = pkttotlen(p);
5780 phylen = len + FCS_LEN;
5781
5782 /* If WEP enabled, add room in phylen for the additional bytes of
5783 * ICV which MAC generates. We do NOT add the additional bytes to
5784 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5785 * in this case
5786 */
5787 if (key) {
5788 phylen += key->icv_len;
5789 }
5790
5791 /* Get tx_info */
5792 tx_info = IEEE80211_SKB_CB(p);
5793 ASSERT(tx_info);
5794
5795 /* add PLCP */
5796 plcp = skb_push(p, D11_PHY_HDR_LEN);
5797
5798 /* add Broadcom tx descriptor header */
5799 txh = (d11txh_t *) skb_push(p, D11_TXH_LEN);
5800 memset(txh, 0, D11_TXH_LEN);
5801
5802 /* setup frameid */
5803 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
5804 /* non-AP STA should never use BCMC queue */
5805 ASSERT(queue != TX_BCMC_FIFO);
5806 if (queue == TX_BCMC_FIFO) {
5807 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5808 WLCWLUNIT(wlc), __func__);
5809 frameid = bcmc_fid_generate(wlc, NULL, txh);
5810 } else {
5811 /* Increment the counter for first fragment */
5812 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
5813 SCB_SEQNUM(scb, p->priority)++;
5814 }
5815
5816 /* extract fragment number from frame first */
5817 seq = le16_to_cpu(seq) & FRAGNUM_MASK;
5818 seq |= (SCB_SEQNUM(scb, p->priority) << SEQNUM_SHIFT);
5819 h->seq_ctrl = cpu_to_le16(seq);
5820
5821 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5822 (queue & TXFID_QUEUE_MASK);
5823 }
5824 }
5825 frameid |= queue & TXFID_QUEUE_MASK;
5826
5827 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5828 if (SCB_PS(scb) || ((fc & FC_KIND_MASK) == FC_BEACON))
5829 mcl |= TXC_IGNOREPMQ;
5830
5831 ASSERT(hw->max_rates <= IEEE80211_TX_MAX_RATES);
5832 ASSERT(hw->max_rates == 2);
5833
5834 txrate[0] = tx_info->control.rates;
5835 txrate[1] = txrate[0] + 1;
5836
5837 ASSERT(txrate[0]->idx >= 0);
5838 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5839 if (txrate[1]->idx < 0) {
5840 txrate[1] = txrate[0];
5841 }
5842
5843 for (k = 0; k < hw->max_rates; k++) {
5844 is_mcs[k] =
5845 txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false;
5846 if (!is_mcs[k]) {
5847 ASSERT(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU));
5848 if ((txrate[k]->idx >= 0)
5849 && (txrate[k]->idx <
5850 hw->wiphy->bands[tx_info->band]->n_bitrates)) {
5851 rate_val[k] =
5852 hw->wiphy->bands[tx_info->band]->
5853 bitrates[txrate[k]->idx].hw_value;
5854 short_preamble[k] =
5855 txrate[k]->
5856 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ?
5857 true : false;
5858 } else {
5859 ASSERT((txrate[k]->idx >= 0) &&
5860 (txrate[k]->idx <
5861 hw->wiphy->bands[tx_info->band]->
5862 n_bitrates));
5863 rate_val[k] = WLC_RATE_1M;
5864 }
5865 } else {
5866 rate_val[k] = txrate[k]->idx;
5867 }
5868 /* Currently only support same setting for primay and fallback rates.
5869 * Unify flags for each rate into a single value for the frame
5870 */
5871 use_rts |=
5872 txrate[k]->
5873 flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false;
5874 use_cts |=
5875 txrate[k]->
5876 flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false;
5877
5878 if (is_mcs[k])
5879 rate_val[k] |= NRATE_MCS_INUSE;
5880
5881 rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, rate_val[k]);
5882
5883 /* (1) RATE: determine and validate primary rate and fallback rates */
5884 if (!RSPEC_ACTIVE(rspec[k])) {
5885 ASSERT(RSPEC_ACTIVE(rspec[k]));
5886 rspec[k] = WLC_RATE_1M;
5887 } else {
5888 if (!is_multicast_ether_addr(h->addr1)) {
5889 /* set tx antenna config */
5890 wlc_antsel_antcfg_get(wlc->asi, false, false, 0,
5891 0, &antcfg, &fbantcfg);
5892 }
5893 }
5894 }
5895
5896 phyctl1_stf = wlc->stf->ss_opmode;
5897
5898 if (N_ENAB(wlc->pub)) {
5899 for (k = 0; k < hw->max_rates; k++) {
5900 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5901 if (((IS_MCS(rspec[k]) &&
5902 IS_SINGLE_STREAM(rspec[k] & RSPEC_RATE_MASK)) ||
5903 IS_OFDM(rspec[k]))
5904 && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY)
5905 || !(rspec[k] & RSPEC_OVERRIDE))) {
5906 rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK);
5907
5908 /* For SISO MCS use STBC if possible */
5909 if (IS_MCS(rspec[k])
5910 && WLC_STF_SS_STBC_TX(wlc, scb)) {
5911 u8 stc;
5912
5913 ASSERT(WLC_STBC_CAP_PHY(wlc));
5914 stc = 1; /* Nss for single stream is always 1 */
5915 rspec[k] |=
5916 (PHY_TXC1_MODE_STBC <<
5917 RSPEC_STF_SHIFT) | (stc <<
5918 RSPEC_STC_SHIFT);
5919 } else
5920 rspec[k] |=
5921 (phyctl1_stf << RSPEC_STF_SHIFT);
5922 }
5923
5924 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5925 if (CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ) {
5926 /* default txbw is 20in40 SB */
5927 mimo_ctlchbw = mimo_txbw =
5928 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC)
5929 ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
5930
5931 if (IS_MCS(rspec[k])) {
5932 /* mcs 32 must be 40b/w DUP */
5933 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5934 mimo_txbw =
5935 PHY_TXC1_BW_40MHZ_DUP;
5936 /* use override */
5937 } else if (wlc->mimo_40txbw != AUTO)
5938 mimo_txbw = wlc->mimo_40txbw;
5939 /* else check if dst is using 40 Mhz */
5940 else if (scb->flags & SCB_IS40)
5941 mimo_txbw = PHY_TXC1_BW_40MHZ;
5942 } else if (IS_OFDM(rspec[k])) {
5943 if (wlc->ofdm_40txbw != AUTO)
5944 mimo_txbw = wlc->ofdm_40txbw;
5945 } else {
5946 ASSERT(IS_CCK(rspec[k]));
5947 if (wlc->cck_40txbw != AUTO)
5948 mimo_txbw = wlc->cck_40txbw;
5949 }
5950 } else {
5951 /* mcs32 is 40 b/w only.
5952 * This is possible for probe packets on a STA during SCAN
5953 */
5954 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5955 /* mcs 0 */
5956 rspec[k] = RSPEC_MIMORATE;
5957 }
5958 mimo_txbw = PHY_TXC1_BW_20MHZ;
5959 }
5960
5961 /* Set channel width */
5962 rspec[k] &= ~RSPEC_BW_MASK;
5963 if ((k == 0) || ((k > 0) && IS_MCS(rspec[k])))
5964 rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT);
5965 else
5966 rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5967
5968 /* Set Short GI */
5969 #ifdef NOSGIYET
5970 if (IS_MCS(rspec[k])
5971 && (txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
5972 rspec[k] |= RSPEC_SHORT_GI;
5973 else if (!(txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
5974 rspec[k] &= ~RSPEC_SHORT_GI;
5975 #else
5976 rspec[k] &= ~RSPEC_SHORT_GI;
5977 #endif
5978
5979 mimo_preamble_type = WLC_MM_PREAMBLE;
5980 if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD)
5981 mimo_preamble_type = WLC_GF_PREAMBLE;
5982
5983 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS)
5984 && (!IS_MCS(rspec[k]))) {
5985 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
5986 WLCWLUNIT(wlc), __func__);
5987 ASSERT(0 && "Rate mismatch");
5988 }
5989
5990 if (IS_MCS(rspec[k])) {
5991 preamble_type[k] = mimo_preamble_type;
5992
5993 /* if SGI is selected, then forced mm for single stream */
5994 if ((rspec[k] & RSPEC_SHORT_GI)
5995 && IS_SINGLE_STREAM(rspec[k] &
5996 RSPEC_RATE_MASK)) {
5997 preamble_type[k] = WLC_MM_PREAMBLE;
5998 }
5999 }
6000
6001 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
6002 ASSERT(VALID_RATE_DBG(wlc, rspec[0]));
6003
6004 /* should be better conditionalized */
6005 if (!IS_MCS(rspec[0])
6006 && (tx_info->control.rates[0].
6007 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
6008 preamble_type[k] = WLC_SHORT_PREAMBLE;
6009
6010 ASSERT(!IS_MCS(rspec[0])
6011 || WLC_IS_MIMO_PREAMBLE(preamble_type[k]));
6012 }
6013 } else {
6014 for (k = 0; k < hw->max_rates; k++) {
6015 /* Set ctrlchbw as 20Mhz */
6016 ASSERT(!IS_MCS(rspec[k]));
6017 rspec[k] &= ~RSPEC_BW_MASK;
6018 rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT);
6019
6020 /* for nphy, stf of ofdm frames must follow policies */
6021 if (WLCISNPHY(wlc->band) && IS_OFDM(rspec[k])) {
6022 rspec[k] &= ~RSPEC_STF_MASK;
6023 rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT;
6024 }
6025 }
6026 }
6027
6028 /* Reset these for use with AMPDU's */
6029 txrate[0]->count = 0;
6030 txrate[1]->count = 0;
6031
6032 /* (2) PROTECTION, may change rspec */
6033 if ((ieee80211_is_data(fc) || ieee80211_is_mgmt(fc)) &&
6034 (phylen > wlc->RTSThresh) && !is_multicast_ether_addr(h->addr1))
6035 use_rts = true;
6036
6037 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
6038 wlc_compute_plcp(wlc, rspec[0], phylen, plcp);
6039 wlc_compute_plcp(wlc, rspec[1], phylen, plcp_fallback);
6040 memcpy(&txh->FragPLCPFallback,
6041 plcp_fallback, sizeof(txh->FragPLCPFallback));
6042
6043 /* Length field now put in CCK FBR CRC field */
6044 if (IS_CCK(rspec[1])) {
6045 txh->FragPLCPFallback[4] = phylen & 0xff;
6046 txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8;
6047 }
6048
6049 /* MIMO-RATE: need validation ?? */
6050 mainrates =
6051 IS_OFDM(rspec[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) plcp) :
6052 plcp[0];
6053
6054 /* DUR field for main rate */
6055 if ((fc != FC_PS_POLL) &&
6056 !is_multicast_ether_addr(h->addr1) && !use_rifs) {
6057 durid =
6058 wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0],
6059 next_frag_len);
6060 h->duration_id = cpu_to_le16(durid);
6061 } else if (use_rifs) {
6062 /* NAV protect to end of next max packet size */
6063 durid =
6064 (u16) wlc_calc_frame_time(wlc, rspec[0],
6065 preamble_type[0],
6066 DOT11_MAX_FRAG_LEN);
6067 durid += RIFS_11N_TIME;
6068 h->duration_id = cpu_to_le16(durid);
6069 }
6070
6071 /* DUR field for fallback rate */
6072 if (fc == FC_PS_POLL)
6073 txh->FragDurFallback = h->duration_id;
6074 else if (is_multicast_ether_addr(h->addr1) || use_rifs)
6075 txh->FragDurFallback = 0;
6076 else {
6077 durid = wlc_compute_frame_dur(wlc, rspec[1],
6078 preamble_type[1], next_frag_len);
6079 txh->FragDurFallback = cpu_to_le16(durid);
6080 }
6081
6082 /* (4) MAC-HDR: MacTxControlLow */
6083 if (frag == 0)
6084 mcl |= TXC_STARTMSDU;
6085
6086 if (!is_multicast_ether_addr(h->addr1))
6087 mcl |= TXC_IMMEDACK;
6088
6089 if (BAND_5G(wlc->band->bandtype))
6090 mcl |= TXC_FREQBAND_5G;
6091
6092 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC))
6093 mcl |= TXC_BW_40;
6094
6095 /* set AMIC bit if using hardware TKIP MIC */
6096 if (hwtkmic)
6097 mcl |= TXC_AMIC;
6098
6099 txh->MacTxControlLow = cpu_to_le16(mcl);
6100
6101 /* MacTxControlHigh */
6102 mch = 0;
6103
6104 /* Set fallback rate preamble type */
6105 if ((preamble_type[1] == WLC_SHORT_PREAMBLE) ||
6106 (preamble_type[1] == WLC_GF_PREAMBLE)) {
6107 ASSERT((preamble_type[1] == WLC_GF_PREAMBLE) ||
6108 (!IS_MCS(rspec[1])));
6109 if (RSPEC2RATE(rspec[1]) != WLC_RATE_1M)
6110 mch |= TXC_PREAMBLE_DATA_FB_SHORT;
6111 }
6112
6113 /* MacFrameControl */
6114 memcpy(&txh->MacFrameControl, &h->frame_control, sizeof(u16));
6115 txh->TxFesTimeNormal = cpu_to_le16(0);
6116
6117 txh->TxFesTimeFallback = cpu_to_le16(0);
6118
6119 /* TxFrameRA */
6120 memcpy(&txh->TxFrameRA, &h->addr1, ETH_ALEN);
6121
6122 /* TxFrameID */
6123 txh->TxFrameID = cpu_to_le16(frameid);
6124
6125 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6126 * then we may need to reset the retry cnt's via the status reg
6127 */
6128 txh->TxStatus = cpu_to_le16(status);
6129
6130 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6131 * the END of previous structure so that it's compatible in driver.
6132 */
6133 txh->MaxNMpdus = cpu_to_le16(0);
6134 txh->MaxABytes_MRT = cpu_to_le16(0);
6135 txh->MaxABytes_FBR = cpu_to_le16(0);
6136 txh->MinMBytes = cpu_to_le16(0);
6137
6138 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6139 /* RTS PLCP header and RTS frame */
6140 if (use_rts || use_cts) {
6141 if (use_rts && use_cts)
6142 use_cts = false;
6143
6144 for (k = 0; k < 2; k++) {
6145 rts_rspec[k] = wlc_rspec_to_rts_rspec(wlc, rspec[k],
6146 false,
6147 mimo_ctlchbw);
6148 }
6149
6150 if (!IS_OFDM(rts_rspec[0]) &&
6151 !((RSPEC2RATE(rts_rspec[0]) == WLC_RATE_1M) ||
6152 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6153 rts_preamble_type[0] = WLC_SHORT_PREAMBLE;
6154 mch |= TXC_PREAMBLE_RTS_MAIN_SHORT;
6155 }
6156
6157 if (!IS_OFDM(rts_rspec[1]) &&
6158 !((RSPEC2RATE(rts_rspec[1]) == WLC_RATE_1M) ||
6159 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6160 rts_preamble_type[1] = WLC_SHORT_PREAMBLE;
6161 mch |= TXC_PREAMBLE_RTS_FB_SHORT;
6162 }
6163
6164 /* RTS/CTS additions to MacTxControlLow */
6165 if (use_cts) {
6166 txh->MacTxControlLow |= cpu_to_le16(TXC_SENDCTS);
6167 } else {
6168 txh->MacTxControlLow |= cpu_to_le16(TXC_SENDRTS);
6169 txh->MacTxControlLow |= cpu_to_le16(TXC_LONGFRAME);
6170 }
6171
6172 /* RTS PLCP header */
6173 ASSERT(IS_ALIGNED((unsigned long)txh->RTSPhyHeader, sizeof(u16)));
6174 rts_plcp = txh->RTSPhyHeader;
6175 if (use_cts)
6176 rts_phylen = DOT11_CTS_LEN + FCS_LEN;
6177 else
6178 rts_phylen = DOT11_RTS_LEN + FCS_LEN;
6179
6180 wlc_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp);
6181
6182 /* fallback rate version of RTS PLCP header */
6183 wlc_compute_plcp(wlc, rts_rspec[1], rts_phylen,
6184 rts_plcp_fallback);
6185 memcpy(&txh->RTSPLCPFallback, rts_plcp_fallback,
6186 sizeof(txh->RTSPLCPFallback));
6187
6188 /* RTS frame fields... */
6189 rts = (struct ieee80211_rts *)&txh->rts_frame;
6190
6191 durid = wlc_compute_rtscts_dur(wlc, use_cts, rts_rspec[0],
6192 rspec[0], rts_preamble_type[0],
6193 preamble_type[0], phylen, false);
6194 rts->duration = cpu_to_le16(durid);
6195 /* fallback rate version of RTS DUR field */
6196 durid = wlc_compute_rtscts_dur(wlc, use_cts,
6197 rts_rspec[1], rspec[1],
6198 rts_preamble_type[1],
6199 preamble_type[1], phylen, false);
6200 txh->RTSDurFallback = cpu_to_le16(durid);
6201
6202 if (use_cts) {
6203 rts->frame_control = cpu_to_le16(FC_CTS);
6204 memcpy(&rts->ra, &h->addr2, ETH_ALEN);
6205 } else {
6206 rts->frame_control = cpu_to_le16((u16) FC_RTS);
6207 memcpy(&rts->ra, &h->addr1, 2 * ETH_ALEN);
6208 }
6209
6210 /* mainrate
6211 * low 8 bits: main frag rate/mcs,
6212 * high 8 bits: rts/cts rate/mcs
6213 */
6214 mainrates |= (IS_OFDM(rts_rspec[0]) ?
6215 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) :
6216 rts_plcp[0]) << 8;
6217 } else {
6218 memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN);
6219 memset((char *)&txh->rts_frame, 0,
6220 sizeof(struct ieee80211_rts));
6221 memset((char *)txh->RTSPLCPFallback, 0,
6222 sizeof(txh->RTSPLCPFallback));
6223 txh->RTSDurFallback = 0;
6224 }
6225
6226 #ifdef SUPPORT_40MHZ
6227 /* add null delimiter count */
6228 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && IS_MCS(rspec)) {
6229 txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] =
6230 wlc_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen);
6231 }
6232 #endif
6233
6234 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6235 txh->MacTxControlHigh = cpu_to_le16(mch);
6236
6237 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6238 txh->MainRates = cpu_to_le16(mainrates);
6239
6240 /* XtraFrameTypes */
6241 xfts = FRAMETYPE(rspec[1], wlc->mimoft);
6242 xfts |= (FRAMETYPE(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT);
6243 xfts |= (FRAMETYPE(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT);
6244 xfts |=
6245 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC) << XFTS_CHANNEL_SHIFT;
6246 txh->XtraFrameTypes = cpu_to_le16(xfts);
6247
6248 /* PhyTxControlWord */
6249 phyctl = FRAMETYPE(rspec[0], wlc->mimoft);
6250 if ((preamble_type[0] == WLC_SHORT_PREAMBLE) ||
6251 (preamble_type[0] == WLC_GF_PREAMBLE)) {
6252 ASSERT((preamble_type[0] == WLC_GF_PREAMBLE)
6253 || !IS_MCS(rspec[0]));
6254 if (RSPEC2RATE(rspec[0]) != WLC_RATE_1M)
6255 phyctl |= PHY_TXC_SHORT_HDR;
6256 wlc->pub->_cnt->txprshort++;
6257 }
6258
6259 /* phytxant is properly bit shifted */
6260 phyctl |= wlc_stf_d11hdrs_phyctl_txant(wlc, rspec[0]);
6261 txh->PhyTxControlWord = cpu_to_le16(phyctl);
6262
6263 /* PhyTxControlWord_1 */
6264 if (WLC_PHY_11N_CAP(wlc->band)) {
6265 u16 phyctl1 = 0;
6266
6267 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[0]);
6268 txh->PhyTxControlWord_1 = cpu_to_le16(phyctl1);
6269 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[1]);
6270 txh->PhyTxControlWord_1_Fbr = cpu_to_le16(phyctl1);
6271
6272 if (use_rts || use_cts) {
6273 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[0]);
6274 txh->PhyTxControlWord_1_Rts = cpu_to_le16(phyctl1);
6275 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[1]);
6276 txh->PhyTxControlWord_1_FbrRts = cpu_to_le16(phyctl1);
6277 }
6278
6279 /*
6280 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6281 * fill in non-zero MModeLen and/or MModeFbrLen
6282 * it will be unnecessary if they are separated
6283 */
6284 if (IS_MCS(rspec[0]) && (preamble_type[0] == WLC_MM_PREAMBLE)) {
6285 u16 mmodelen =
6286 wlc_calc_lsig_len(wlc, rspec[0], phylen);
6287 txh->MModeLen = cpu_to_le16(mmodelen);
6288 }
6289
6290 if (IS_MCS(rspec[1]) && (preamble_type[1] == WLC_MM_PREAMBLE)) {
6291 u16 mmodefbrlen =
6292 wlc_calc_lsig_len(wlc, rspec[1], phylen);
6293 txh->MModeFbrLen = cpu_to_le16(mmodefbrlen);
6294 }
6295 }
6296
6297 if (IS_MCS(rspec[0]))
6298 ASSERT(IS_MCS(rspec[1]));
6299
6300 ASSERT(!IS_MCS(rspec[0]) ||
6301 ((preamble_type[0] == WLC_MM_PREAMBLE) == (txh->MModeLen != 0)));
6302 ASSERT(!IS_MCS(rspec[1]) ||
6303 ((preamble_type[1] == WLC_MM_PREAMBLE) ==
6304 (txh->MModeFbrLen != 0)));
6305
6306 ac = wme_fifo2ac[queue];
6307 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) {
6308 uint frag_dur, dur, dur_fallback;
6309
6310 ASSERT(!is_multicast_ether_addr(h->addr1));
6311
6312 /* WME: Update TXOP threshold */
6313 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) {
6314 frag_dur =
6315 wlc_calc_frame_time(wlc, rspec[0], preamble_type[0],
6316 phylen);
6317
6318 if (rts) {
6319 /* 1 RTS or CTS-to-self frame */
6320 dur =
6321 wlc_calc_cts_time(wlc, rts_rspec[0],
6322 rts_preamble_type[0]);
6323 dur_fallback =
6324 wlc_calc_cts_time(wlc, rts_rspec[1],
6325 rts_preamble_type[1]);
6326 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6327 dur += le16_to_cpu(rts->duration);
6328 dur_fallback +=
6329 le16_to_cpu(txh->RTSDurFallback);
6330 } else if (use_rifs) {
6331 dur = frag_dur;
6332 dur_fallback = 0;
6333 } else {
6334 /* frame + SIFS + ACK */
6335 dur = frag_dur;
6336 dur +=
6337 wlc_compute_frame_dur(wlc, rspec[0],
6338 preamble_type[0], 0);
6339
6340 dur_fallback =
6341 wlc_calc_frame_time(wlc, rspec[1],
6342 preamble_type[1],
6343 phylen);
6344 dur_fallback +=
6345 wlc_compute_frame_dur(wlc, rspec[1],
6346 preamble_type[1], 0);
6347 }
6348 /* NEED to set TxFesTimeNormal (hard) */
6349 txh->TxFesTimeNormal = cpu_to_le16((u16) dur);
6350 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6351 txh->TxFesTimeFallback =
6352 cpu_to_le16((u16) dur_fallback);
6353
6354 /* update txop byte threshold (txop minus intraframe overhead) */
6355 if (wlc->edcf_txop[ac] >= (dur - frag_dur)) {
6356 {
6357 uint newfragthresh;
6358
6359 newfragthresh =
6360 wlc_calc_frame_len(wlc, rspec[0],
6361 preamble_type[0],
6362 (wlc->
6363 edcf_txop[ac] -
6364 (dur -
6365 frag_dur)));
6366 /* range bound the fragthreshold */
6367 if (newfragthresh < DOT11_MIN_FRAG_LEN)
6368 newfragthresh =
6369 DOT11_MIN_FRAG_LEN;
6370 else if (newfragthresh >
6371 wlc->usr_fragthresh)
6372 newfragthresh =
6373 wlc->usr_fragthresh;
6374 /* update the fragthresh and do txc update */
6375 if (wlc->fragthresh[queue] !=
6376 (u16) newfragthresh) {
6377 wlc->fragthresh[queue] =
6378 (u16) newfragthresh;
6379 }
6380 }
6381 } else
6382 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6383 wlc->pub->unit, fifo_names[queue],
6384 RSPEC2RATE(rspec[0]));
6385
6386 if (dur > wlc->edcf_txop[ac])
6387 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6388 wlc->pub->unit, __func__,
6389 fifo_names[queue],
6390 phylen, wlc->fragthresh[queue],
6391 dur, wlc->edcf_txop[ac]);
6392 }
6393 }
6394
6395 return 0;
6396 }
6397
6398 void wlc_tbtt(struct wlc_info *wlc, d11regs_t *regs)
6399 {
6400 wlc_bsscfg_t *cfg = wlc->cfg;
6401
6402 wlc->pub->_cnt->tbtt++;
6403
6404 if (BSSCFG_STA(cfg)) {
6405 /* run watchdog here if the watchdog timer is not armed */
6406 if (WLC_WATCHDOG_TBTT(wlc)) {
6407 u32 cur, delta;
6408 if (wlc->WDarmed) {
6409 wl_del_timer(wlc->wl, wlc->wdtimer);
6410 wlc->WDarmed = false;
6411 }
6412
6413 cur = OSL_SYSUPTIME();
6414 delta = cur > wlc->WDlast ? cur - wlc->WDlast :
6415 (u32) ~0 - wlc->WDlast + cur + 1;
6416 if (delta >= TIMER_INTERVAL_WATCHDOG) {
6417 wlc_watchdog((void *)wlc);
6418 wlc->WDlast = cur;
6419 }
6420
6421 wl_add_timer(wlc->wl, wlc->wdtimer,
6422 wlc_watchdog_backup_bi(wlc), true);
6423 wlc->WDarmed = true;
6424 }
6425 }
6426
6427 if (!cfg->BSS) {
6428 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6429 wlc->qvalid |= MCMD_DIRFRMQVAL;
6430 }
6431 }
6432
6433 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6434 void wlc_hwtimer_gptimer_set(struct wlc_info *wlc, uint us)
6435 {
6436 W_REG(wlc->osh, &wlc->regs->gptimer, us);
6437 }
6438
6439 void wlc_hwtimer_gptimer_abort(struct wlc_info *wlc)
6440 {
6441 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6442 }
6443
6444 static void wlc_hwtimer_gptimer_cb(struct wlc_info *wlc)
6445 {
6446 /* when interrupt is generated, the counter is loaded with last value
6447 * written and continue to decrement. So it has to be cleaned first
6448 */
6449 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6450 }
6451
6452 /*
6453 * This fn has all the high level dpc processing from wlc_dpc.
6454 * POLICY: no macinstatus change, no bounding loop.
6455 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6456 */
6457 void wlc_high_dpc(struct wlc_info *wlc, u32 macintstatus)
6458 {
6459 d11regs_t *regs = wlc->regs;
6460 #ifdef BCMDBG
6461 char flagstr[128];
6462 static const bcm_bit_desc_t int_flags[] = {
6463 {MI_MACSSPNDD, "MACSSPNDD"},
6464 {MI_BCNTPL, "BCNTPL"},
6465 {MI_TBTT, "TBTT"},
6466 {MI_BCNSUCCESS, "BCNSUCCESS"},
6467 {MI_BCNCANCLD, "BCNCANCLD"},
6468 {MI_ATIMWINEND, "ATIMWINEND"},
6469 {MI_PMQ, "PMQ"},
6470 {MI_NSPECGEN_0, "NSPECGEN_0"},
6471 {MI_NSPECGEN_1, "NSPECGEN_1"},
6472 {MI_MACTXERR, "MACTXERR"},
6473 {MI_NSPECGEN_3, "NSPECGEN_3"},
6474 {MI_PHYTXERR, "PHYTXERR"},
6475 {MI_PME, "PME"},
6476 {MI_GP0, "GP0"},
6477 {MI_GP1, "GP1"},
6478 {MI_DMAINT, "DMAINT"},
6479 {MI_TXSTOP, "TXSTOP"},
6480 {MI_CCA, "CCA"},
6481 {MI_BG_NOISE, "BG_NOISE"},
6482 {MI_DTIM_TBTT, "DTIM_TBTT"},
6483 {MI_PRQ, "PRQ"},
6484 {MI_PWRUP, "PWRUP"},
6485 {MI_RFDISABLE, "RFDISABLE"},
6486 {MI_TFS, "TFS"},
6487 {MI_PHYCHANGED, "PHYCHANGED"},
6488 {MI_TO, "TO"},
6489 {0, NULL}
6490 };
6491
6492 if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) {
6493 bcm_format_flags(int_flags, macintstatus, flagstr,
6494 sizeof(flagstr));
6495 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6496 wlc->pub->unit, macintstatus, flagstr);
6497 }
6498 #endif /* BCMDBG */
6499
6500 if (macintstatus & MI_PRQ) {
6501 /* Process probe request FIFO */
6502 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6503 }
6504
6505 /* TBTT indication */
6506 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6507 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
6508 wlc_tbtt(wlc, regs);
6509
6510 if (macintstatus & MI_GP0) {
6511 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6512 wlc->pub->unit, wlc->pub->now);
6513
6514 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6515 __func__, wlc->pub->sih->chip,
6516 wlc->pub->sih->chiprev);
6517
6518 wlc->pub->_cnt->psmwds++;
6519
6520 /* big hammer */
6521 wl_init(wlc->wl);
6522 }
6523
6524 /* gptimer timeout */
6525 if (macintstatus & MI_TO) {
6526 wlc_hwtimer_gptimer_cb(wlc);
6527 }
6528
6529 if (macintstatus & MI_RFDISABLE) {
6530 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6531 wlc->pub->unit,
6532 R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD);
6533 /* delay the cleanup to wl_down in IBSS case */
6534 if ((R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD)) {
6535 int idx;
6536 wlc_bsscfg_t *bsscfg;
6537 FOREACH_BSS(wlc, idx, bsscfg) {
6538 if (!BSSCFG_STA(bsscfg) || !bsscfg->enable
6539 || !bsscfg->BSS)
6540 continue;
6541 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6542 wlc->pub->unit);
6543 }
6544 }
6545 }
6546
6547 /* send any enq'd tx packets. Just makes sure to jump start tx */
6548 if (!pktq_empty(&wlc->active_queue->q))
6549 wlc_send_q(wlc, wlc->active_queue);
6550
6551 ASSERT(wlc_ps_check(wlc));
6552 }
6553
6554 static void wlc_war16165(struct wlc_info *wlc, bool tx)
6555 {
6556 if (tx) {
6557 /* the post-increment is used in STAY_AWAKE macro */
6558 if (wlc->txpend16165war++ == 0)
6559 wlc_set_ps_ctrl(wlc);
6560 } else {
6561 wlc->txpend16165war--;
6562 if (wlc->txpend16165war == 0)
6563 wlc_set_ps_ctrl(wlc);
6564 }
6565 }
6566
6567 /* process an individual tx_status_t */
6568 /* WLC_HIGH_API */
6569 bool BCMFASTPATH
6570 wlc_dotxstatus(struct wlc_info *wlc, tx_status_t *txs, u32 frm_tx2)
6571 {
6572 struct sk_buff *p;
6573 uint queue;
6574 d11txh_t *txh;
6575 struct scb *scb = NULL;
6576 bool free_pdu;
6577 struct osl_info *osh;
6578 int tx_rts, tx_frame_count, tx_rts_count;
6579 uint totlen, supr_status;
6580 bool lastframe;
6581 struct ieee80211_hdr *h;
6582 u16 fc;
6583 u16 mcl;
6584 struct ieee80211_tx_info *tx_info;
6585 struct ieee80211_tx_rate *txrate;
6586 int i;
6587
6588 (void)(frm_tx2); /* Compiler reference to avoid unused variable warning */
6589
6590 /* discard intermediate indications for ucode with one legitimate case:
6591 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6592 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6593 * transmission count)
6594 */
6595 if (!(txs->status & TX_STATUS_AMPDU)
6596 && (txs->status & TX_STATUS_INTERMEDIATE)) {
6597 WLCNTADD(wlc->pub->_cnt->txnoack,
6598 ((txs->
6599 status & TX_STATUS_FRM_RTX_MASK) >>
6600 TX_STATUS_FRM_RTX_SHIFT));
6601 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__);
6602 return false;
6603 }
6604
6605 osh = wlc->osh;
6606 queue = txs->frameid & TXFID_QUEUE_MASK;
6607 ASSERT(queue < NFIFO);
6608 if (queue >= NFIFO) {
6609 p = NULL;
6610 goto fatal;
6611 }
6612
6613 p = GETNEXTTXP(wlc, queue);
6614 if (WLC_WAR16165(wlc))
6615 wlc_war16165(wlc, false);
6616 if (p == NULL)
6617 goto fatal;
6618
6619 txh = (d11txh_t *) (p->data);
6620 mcl = le16_to_cpu(txh->MacTxControlLow);
6621
6622 if (txs->phyerr) {
6623 if (WL_ERROR_ON()) {
6624 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6625 txs->phyerr, txh->MainRates);
6626 wlc_print_txdesc(txh);
6627 }
6628 wlc_print_txstatus(txs);
6629 }
6630
6631 ASSERT(txs->frameid == cpu_to_le16(txh->TxFrameID));
6632 if (txs->frameid != cpu_to_le16(txh->TxFrameID))
6633 goto fatal;
6634
6635 tx_info = IEEE80211_SKB_CB(p);
6636 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
6637 fc = le16_to_cpu(h->frame_control);
6638
6639 scb = (struct scb *)tx_info->control.sta->drv_priv;
6640
6641 if (N_ENAB(wlc->pub)) {
6642 u8 *plcp = (u8 *) (txh + 1);
6643 if (PLCP3_ISSGI(plcp[3]))
6644 wlc->pub->_cnt->txmpdu_sgi++;
6645 if (PLCP3_ISSTBC(plcp[3]))
6646 wlc->pub->_cnt->txmpdu_stbc++;
6647 }
6648
6649 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
6650 ASSERT((mcl & TXC_AMPDU_MASK) != TXC_AMPDU_NONE);
6651 wlc_ampdu_dotxstatus(wlc->ampdu, scb, p, txs);
6652 return false;
6653 }
6654
6655 supr_status = txs->status & TX_STATUS_SUPR_MASK;
6656 if (supr_status == TX_STATUS_SUPR_BADCH)
6657 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6658 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec));
6659
6660 tx_rts = cpu_to_le16(txh->MacTxControlLow) & TXC_SENDRTS;
6661 tx_frame_count =
6662 (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT;
6663 tx_rts_count =
6664 (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT;
6665
6666 lastframe = (fc & IEEE80211_FCTL_MOREFRAGS) == 0;
6667
6668 if (!lastframe) {
6669 WL_ERROR("Not last frame!\n");
6670 } else {
6671 u16 sfbl, lfbl;
6672 ieee80211_tx_info_clear_status(tx_info);
6673 if (queue < AC_COUNT) {
6674 sfbl = WLC_WME_RETRY_SFB_GET(wlc, wme_fifo2ac[queue]);
6675 lfbl = WLC_WME_RETRY_LFB_GET(wlc, wme_fifo2ac[queue]);
6676 } else {
6677 sfbl = wlc->SFBL;
6678 lfbl = wlc->LFBL;
6679 }
6680
6681 txrate = tx_info->status.rates;
6682 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6683 if ((tx_frame_count > sfbl) && (txrate[1].idx >= 0)) {
6684 /* rate selection requested a fallback rate and we used it */
6685 txrate->count = lfbl;
6686 txrate[1].count = tx_frame_count - lfbl;
6687 } else {
6688 /* rate selection did not request fallback rate, or we didn't need it */
6689 txrate->count = tx_frame_count;
6690 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6691 txrate[1].idx = -1;
6692 txrate[1].count = 0;
6693 }
6694
6695 /* clear the rest of the rates */
6696 for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
6697 txrate[i].idx = -1;
6698 txrate[i].count = 0;
6699 }
6700
6701 if (txs->status & TX_STATUS_ACK_RCV)
6702 tx_info->flags |= IEEE80211_TX_STAT_ACK;
6703 }
6704
6705 totlen = pkttotlen(p);
6706 free_pdu = true;
6707
6708 wlc_txfifo_complete(wlc, queue, 1);
6709
6710 if (lastframe) {
6711 p->next = NULL;
6712 p->prev = NULL;
6713 wlc->txretried = 0;
6714 /* remove PLCP & Broadcom tx descriptor header */
6715 skb_pull(p, D11_PHY_HDR_LEN);
6716 skb_pull(p, D11_TXH_LEN);
6717 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
6718 wlc->pub->_cnt->ieee_tx_status++;
6719 } else {
6720 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6721 __func__);
6722 }
6723
6724 return false;
6725
6726 fatal:
6727 ASSERT(0);
6728 if (p)
6729 pkt_buf_free_skb(osh, p, true);
6730
6731 return true;
6732
6733 }
6734
6735 void BCMFASTPATH
6736 wlc_txfifo_complete(struct wlc_info *wlc, uint fifo, s8 txpktpend)
6737 {
6738 TXPKTPENDDEC(wlc, fifo, txpktpend);
6739 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6740 txpktpend, TXPKTPENDGET(wlc, fifo));
6741
6742 /* There is more room; mark precedences related to this FIFO sendable */
6743 WLC_TX_FIFO_ENAB(wlc, fifo);
6744 ASSERT(TXPKTPENDGET(wlc, fifo) >= 0);
6745
6746 if (!TXPKTPENDTOT(wlc)) {
6747 if (wlc->block_datafifo & DATA_BLOCK_TX_SUPR)
6748 wlc_bsscfg_tx_check(wlc);
6749 }
6750
6751 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6752 if (AP_ENAB(wlc->pub) &&
6753 wlc->bcmcfifo_drain && !TXPKTPENDGET(wlc, TX_BCMC_FIFO)) {
6754 wlc->bcmcfifo_drain = false;
6755 wlc_mhf(wlc, MHF2, MHF2_TXBCMC_NOW, 0, WLC_BAND_AUTO);
6756 }
6757
6758 /* figure out which bsscfg is being worked on... */
6759 }
6760
6761 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6762 * return the offset (in us) of the TSF from the last TBTT
6763 */
6764 u32 wlc_calc_tbtt_offset(u32 bp, u32 tsf_h, u32 tsf_l)
6765 {
6766 u32 k, btklo, btkhi, offset;
6767
6768 /* TBTT is always an even multiple of the beacon_interval,
6769 * so the TBTT less than or equal to the beacon timestamp is
6770 * the beacon timestamp minus the beacon timestamp modulo
6771 * the beacon interval.
6772 *
6773 * TBTT = BT - (BT % BIu)
6774 * = (BTk - (BTk % BP)) * 2^10
6775 *
6776 * BT = beacon timestamp (usec, 64bits)
6777 * BTk = beacon timestamp (Kusec, 54bits)
6778 * BP = beacon interval (Kusec, 16bits)
6779 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6780 *
6781 * To keep the calculations in u32s, the modulo operation
6782 * on the high part of BT needs to be done in parts using the
6783 * relations:
6784 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6785 * and
6786 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6787 *
6788 * So, if BTk[n] = u16 n [0,3] of BTk.
6789 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6790 * and the SUM term can be broken down:
6791 * (BTk[n] * 2^16n) % BP
6792 * (BTk[n] * (2^16n % BP)) % BP
6793 *
6794 * Create a set of power of 2 mod BP constants:
6795 * K[n] = 2^(16n) % BP
6796 * = (K[n-1] * 2^16) % BP
6797 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6798 *
6799 * BTk % BP = BTk[0-1] % BP +
6800 * (BTk[2] * K[2]) % BP +
6801 * (BTk[3] * K[3]) % BP
6802 *
6803 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6804 */
6805
6806 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6807 btklo = (tsf_h << 22) | (tsf_l >> 10);
6808 btkhi = tsf_h >> 10;
6809
6810 /* offset = BTk % BP */
6811 offset = btklo % bp;
6812
6813 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6814 k = (u32) (1 << 16) % bp;
6815 k = (u32) (k * 1 << 16) % (u32) bp;
6816
6817 /* offset += (BTk[2] * K[2]) % BP */
6818 offset += ((btkhi & 0xffff) * k) % bp;
6819
6820 /* BTk[3] */
6821 btkhi = btkhi >> 16;
6822
6823 /* k[3] = (K[2] * 2^16) % BP */
6824 k = (k << 16) % bp;
6825
6826 /* offset += (BTk[3] * K[3]) % BP */
6827 offset += ((btkhi & 0xffff) * k) % bp;
6828
6829 offset = offset % bp;
6830
6831 /* convert offset from kus to us by shifting up 10 bits and
6832 * add in the low 10 bits of tsf that we ignored
6833 */
6834 offset = (offset << 10) + (tsf_l & 0x3FF);
6835
6836 return offset;
6837 }
6838
6839 /* Update beacon listen interval in shared memory */
6840 void wlc_bcn_li_upd(struct wlc_info *wlc)
6841 {
6842 if (AP_ENAB(wlc->pub))
6843 return;
6844
6845 /* wake up every DTIM is the default */
6846 if (wlc->bcn_li_dtim == 1)
6847 wlc_write_shm(wlc, M_BCN_LI, 0);
6848 else
6849 wlc_write_shm(wlc, M_BCN_LI,
6850 (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn);
6851 }
6852
6853 static void
6854 prep_mac80211_status(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p,
6855 struct ieee80211_rx_status *rx_status)
6856 {
6857 u32 tsf_l, tsf_h;
6858 wlc_d11rxhdr_t *wlc_rxh = (wlc_d11rxhdr_t *) rxh;
6859 int preamble;
6860 int channel;
6861 ratespec_t rspec;
6862 unsigned char *plcp;
6863
6864 wlc_read_tsf(wlc, &tsf_l, &tsf_h); /* mactime */
6865 rx_status->mactime = tsf_h;
6866 rx_status->mactime <<= 32;
6867 rx_status->mactime |= tsf_l;
6868 rx_status->flag |= RX_FLAG_TSFT;
6869
6870 channel = WLC_CHAN_CHANNEL(rxh->RxChan);
6871
6872 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
6873 if (channel > 14) {
6874 rx_status->band = IEEE80211_BAND_5GHZ;
6875 rx_status->freq = ieee80211_ofdm_chan_to_freq(
6876 WF_CHAN_FACTOR_5_G/2, channel);
6877
6878 } else {
6879 rx_status->band = IEEE80211_BAND_2GHZ;
6880 rx_status->freq = ieee80211_dsss_chan_to_freq(channel);
6881 }
6882
6883 rx_status->signal = wlc_rxh->rssi; /* signal */
6884
6885 /* noise */
6886 /* qual */
6887 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */
6888
6889 plcp = p->data;
6890
6891 rspec = wlc_compute_rspec(rxh, plcp);
6892 if (IS_MCS(rspec)) {
6893 rx_status->rate_idx = rspec & RSPEC_RATE_MASK;
6894 rx_status->flag |= RX_FLAG_HT;
6895 if (RSPEC_IS40MHZ(rspec))
6896 rx_status->flag |= RX_FLAG_40MHZ;
6897 } else {
6898 switch (RSPEC2RATE(rspec)) {
6899 case WLC_RATE_1M:
6900 rx_status->rate_idx = 0;
6901 break;
6902 case WLC_RATE_2M:
6903 rx_status->rate_idx = 1;
6904 break;
6905 case WLC_RATE_5M5:
6906 rx_status->rate_idx = 2;
6907 break;
6908 case WLC_RATE_11M:
6909 rx_status->rate_idx = 3;
6910 break;
6911 case WLC_RATE_6M:
6912 rx_status->rate_idx = 4;
6913 break;
6914 case WLC_RATE_9M:
6915 rx_status->rate_idx = 5;
6916 break;
6917 case WLC_RATE_12M:
6918 rx_status->rate_idx = 6;
6919 break;
6920 case WLC_RATE_18M:
6921 rx_status->rate_idx = 7;
6922 break;
6923 case WLC_RATE_24M:
6924 rx_status->rate_idx = 8;
6925 break;
6926 case WLC_RATE_36M:
6927 rx_status->rate_idx = 9;
6928 break;
6929 case WLC_RATE_48M:
6930 rx_status->rate_idx = 10;
6931 break;
6932 case WLC_RATE_54M:
6933 rx_status->rate_idx = 11;
6934 break;
6935 default:
6936 WL_ERROR("%s: Unknown rate\n", __func__);
6937 }
6938
6939 /* Determine short preamble and rate_idx */
6940 preamble = 0;
6941 if (IS_CCK(rspec)) {
6942 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
6943 WL_ERROR("Short CCK\n");
6944 rx_status->flag |= RX_FLAG_SHORTPRE;
6945 } else if (IS_OFDM(rspec)) {
6946 rx_status->flag |= RX_FLAG_SHORTPRE;
6947 } else {
6948 WL_ERROR("%s: Unknown modulation\n", __func__);
6949 }
6950 }
6951
6952 if (PLCP3_ISSGI(plcp[3]))
6953 rx_status->flag |= RX_FLAG_SHORT_GI;
6954
6955 if (rxh->RxStatus1 & RXS_DECERR) {
6956 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC;
6957 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__);
6958 }
6959 if (rxh->RxStatus1 & RXS_FCSERR) {
6960 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
6961 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__);
6962 }
6963 }
6964
6965 static void
6966 wlc_recvctl(struct wlc_info *wlc, struct osl_info *osh, d11rxhdr_t *rxh,
6967 struct sk_buff *p)
6968 {
6969 int len_mpdu;
6970 struct ieee80211_rx_status rx_status;
6971 #if defined(BCMDBG)
6972 struct sk_buff *skb = p;
6973 #endif /* BCMDBG */
6974 /* Todo:
6975 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
6976 * Test for INTERMEDIATE like so:
6977 * if (!(plcp[0] | plcp[1] | plcp[2]))
6978 */
6979
6980 memset(&rx_status, 0, sizeof(rx_status));
6981 prep_mac80211_status(wlc, rxh, p, &rx_status);
6982
6983 /* mac header+body length, exclude CRC and plcp header */
6984 len_mpdu = p->len - D11_PHY_HDR_LEN - FCS_LEN;
6985 skb_pull(p, D11_PHY_HDR_LEN);
6986 __skb_trim(p, len_mpdu);
6987
6988 ASSERT(!(p->next));
6989 ASSERT(!(p->prev));
6990
6991 ASSERT(IS_ALIGNED((unsigned long)skb->data, 2));
6992
6993 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status));
6994 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
6995
6996 wlc->pub->_cnt->ieee_rx++;
6997 osh->pktalloced--;
6998 return;
6999 }
7000
7001 void wlc_bss_list_free(struct wlc_info *wlc, struct wlc_bss_list *bss_list)
7002 {
7003 uint index;
7004
7005 if (!bss_list) {
7006 WL_ERROR("%s: Attempting to free NULL list\n", __func__);
7007 return;
7008 }
7009 /* inspect all BSS descriptor */
7010 for (index = 0; index < bss_list->count; index++) {
7011 kfree(bss_list->ptrs[index]);
7012 bss_list->ptrs[index] = NULL;
7013 }
7014 bss_list->count = 0;
7015 }
7016
7017 /* Process received frames */
7018 /*
7019 * Return true if more frames need to be processed. false otherwise.
7020 * Param 'bound' indicates max. # frames to process before break out.
7021 */
7022 /* WLC_HIGH_API */
7023 void BCMFASTPATH wlc_recv(struct wlc_info *wlc, struct sk_buff *p)
7024 {
7025 d11rxhdr_t *rxh;
7026 struct ieee80211_hdr *h;
7027 struct osl_info *osh;
7028 u16 fc;
7029 uint len;
7030 bool is_amsdu;
7031
7032 WL_TRACE("wl%d: wlc_recv\n", wlc->pub->unit);
7033
7034 osh = wlc->osh;
7035
7036 /* frame starts with rxhdr */
7037 rxh = (d11rxhdr_t *) (p->data);
7038
7039 /* strip off rxhdr */
7040 skb_pull(p, wlc->hwrxoff);
7041
7042 /* fixup rx header endianness */
7043 rxh->RxFrameSize = le16_to_cpu(rxh->RxFrameSize);
7044 rxh->PhyRxStatus_0 = le16_to_cpu(rxh->PhyRxStatus_0);
7045 rxh->PhyRxStatus_1 = le16_to_cpu(rxh->PhyRxStatus_1);
7046 rxh->PhyRxStatus_2 = le16_to_cpu(rxh->PhyRxStatus_2);
7047 rxh->PhyRxStatus_3 = le16_to_cpu(rxh->PhyRxStatus_3);
7048 rxh->PhyRxStatus_4 = le16_to_cpu(rxh->PhyRxStatus_4);
7049 rxh->PhyRxStatus_5 = le16_to_cpu(rxh->PhyRxStatus_5);
7050 rxh->RxStatus1 = le16_to_cpu(rxh->RxStatus1);
7051 rxh->RxStatus2 = le16_to_cpu(rxh->RxStatus2);
7052 rxh->RxTSFTime = le16_to_cpu(rxh->RxTSFTime);
7053 rxh->RxChan = le16_to_cpu(rxh->RxChan);
7054
7055 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7056 if (rxh->RxStatus1 & RXS_PBPRES) {
7057 if (p->len < 2) {
7058 wlc->pub->_cnt->rxrunt++;
7059 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7060 wlc->pub->unit, p->len);
7061 goto toss;
7062 }
7063 skb_pull(p, 2);
7064 }
7065
7066 h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN);
7067 len = p->len;
7068
7069 if (rxh->RxStatus1 & RXS_FCSERR) {
7070 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) {
7071 WL_ERROR("FCSERR while scanning******* - tossing\n");
7072 goto toss;
7073 } else {
7074 WL_ERROR("RCSERR!!!\n");
7075 goto toss;
7076 }
7077 }
7078
7079 /* check received pkt has at least frame control field */
7080 if (len >= D11_PHY_HDR_LEN + sizeof(h->frame_control)) {
7081 fc = le16_to_cpu(h->frame_control);
7082 } else {
7083 wlc->pub->_cnt->rxrunt++;
7084 goto toss;
7085 }
7086
7087 is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK;
7088
7089 /* explicitly test bad src address to avoid sending bad deauth */
7090 if (!is_amsdu) {
7091 /* CTS and ACK CTL frames are w/o a2 */
7092 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
7093 (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
7094 if ((is_zero_ether_addr(h->addr2) ||
7095 is_multicast_ether_addr(h->addr2))) {
7096 WL_ERROR("wl%d: %s: dropping a frame with "
7097 "invalid src mac address, a2: %pM\n",
7098 wlc->pub->unit, __func__, h->addr2);
7099 wlc->pub->_cnt->rxbadsrcmac++;
7100 goto toss;
7101 }
7102 wlc->pub->_cnt->rxfrag++;
7103 }
7104 }
7105
7106 /* due to sheer numbers, toss out probe reqs for now */
7107 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
7108 if ((fc & FC_KIND_MASK) == FC_PROBE_REQ)
7109 goto toss;
7110 }
7111
7112 if (is_amsdu) {
7113 WL_ERROR("%s: is_amsdu causing toss\n", __func__);
7114 goto toss;
7115 }
7116
7117 wlc_recvctl(wlc, osh, rxh, p);
7118 return;
7119
7120 toss:
7121 pkt_buf_free_skb(osh, p, false);
7122 }
7123
7124 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7125 * number of bytes goes in the length field
7126 *
7127 * Formula given by HT PHY Spec v 1.13
7128 * len = 3(nsyms + nstream + 3) - 3
7129 */
7130 u16 BCMFASTPATH
7131 wlc_calc_lsig_len(struct wlc_info *wlc, ratespec_t ratespec, uint mac_len)
7132 {
7133 uint nsyms, len = 0, kNdps;
7134
7135 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7136 wlc->pub->unit, RSPEC2RATE(ratespec), mac_len);
7137
7138 if (IS_MCS(ratespec)) {
7139 uint mcs = ratespec & RSPEC_RATE_MASK;
7140 /* MCS_TXS(mcs) returns num tx streams - 1 */
7141 int tot_streams = (MCS_TXS(mcs) + 1) + RSPEC_STC(ratespec);
7142
7143 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7144 /* the payload duration calculation matches that of regular ofdm */
7145 /* 1000Ndbps = kbps * 4 */
7146 kNdps =
7147 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7148 RSPEC_ISSGI(ratespec)) * 4;
7149
7150 if (RSPEC_STC(ratespec) == 0)
7151 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7152 nsyms =
7153 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7154 APHY_TAIL_NBITS) * 1000, kNdps);
7155 else
7156 /* STBC needs to have even number of symbols */
7157 nsyms =
7158 2 *
7159 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7160 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7161
7162 nsyms += (tot_streams + 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7163 /* 3 bytes/symbol @ legacy 6Mbps rate */
7164 len = (3 * nsyms) - 3; /* (-3) excluding service bits and tail bits */
7165 }
7166
7167 return (u16) len;
7168 }
7169
7170 /* calculate frame duration of a given rate and length, return time in usec unit */
7171 uint BCMFASTPATH
7172 wlc_calc_frame_time(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7173 uint mac_len)
7174 {
7175 uint nsyms, dur = 0, Ndps, kNdps;
7176 uint rate = RSPEC2RATE(ratespec);
7177
7178 if (rate == 0) {
7179 ASSERT(0);
7180 WL_ERROR("wl%d: WAR: using rate of 1 mbps\n", wlc->pub->unit);
7181 rate = WLC_RATE_1M;
7182 }
7183
7184 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7185 wlc->pub->unit, ratespec, preamble_type, mac_len);
7186
7187 if (IS_MCS(ratespec)) {
7188 uint mcs = ratespec & RSPEC_RATE_MASK;
7189 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7190 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7191 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type));
7192
7193 dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7194 if (preamble_type == WLC_MM_PREAMBLE)
7195 dur += PREN_MM_EXT;
7196 /* 1000Ndbps = kbps * 4 */
7197 kNdps =
7198 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7199 RSPEC_ISSGI(ratespec)) * 4;
7200
7201 if (RSPEC_STC(ratespec) == 0)
7202 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7203 nsyms =
7204 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7205 APHY_TAIL_NBITS) * 1000, kNdps);
7206 else
7207 /* STBC needs to have even number of symbols */
7208 nsyms =
7209 2 *
7210 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7211 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7212
7213 dur += APHY_SYMBOL_TIME * nsyms;
7214 if (BAND_2G(wlc->band->bandtype))
7215 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7216 } else if (IS_OFDM(rate)) {
7217 dur = APHY_PREAMBLE_TIME;
7218 dur += APHY_SIGNAL_TIME;
7219 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7220 Ndps = rate * 2;
7221 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7222 nsyms =
7223 CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS),
7224 Ndps);
7225 dur += APHY_SYMBOL_TIME * nsyms;
7226 if (BAND_2G(wlc->band->bandtype))
7227 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7228 } else {
7229 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7230 mac_len = mac_len * 8 * 2;
7231 /* calc ceiling of bits/rate = microseconds of air time */
7232 dur = (mac_len + rate - 1) / rate;
7233 if (preamble_type & WLC_SHORT_PREAMBLE)
7234 dur += BPHY_PLCP_SHORT_TIME;
7235 else
7236 dur += BPHY_PLCP_TIME;
7237 }
7238 return dur;
7239 }
7240
7241 /* The opposite of wlc_calc_frame_time */
7242 static uint
7243 wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7244 uint dur)
7245 {
7246 uint nsyms, mac_len, Ndps, kNdps;
7247 uint rate = RSPEC2RATE(ratespec);
7248
7249 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7250 wlc->pub->unit, ratespec, preamble_type, dur);
7251
7252 if (IS_MCS(ratespec)) {
7253 uint mcs = ratespec & RSPEC_RATE_MASK;
7254 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7255 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7256 dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7257 /* payload calculation matches that of regular ofdm */
7258 if (BAND_2G(wlc->band->bandtype))
7259 dur -= DOT11_OFDM_SIGNAL_EXTENSION;
7260 /* kNdbps = kbps * 4 */
7261 kNdps =
7262 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7263 RSPEC_ISSGI(ratespec)) * 4;
7264 nsyms = dur / APHY_SYMBOL_TIME;
7265 mac_len =
7266 ((nsyms * kNdps) -
7267 ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000;
7268 } else if (IS_OFDM(ratespec)) {
7269 dur -= APHY_PREAMBLE_TIME;
7270 dur -= APHY_SIGNAL_TIME;
7271 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7272 Ndps = rate * 2;
7273 nsyms = dur / APHY_SYMBOL_TIME;
7274 mac_len =
7275 ((nsyms * Ndps) -
7276 (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8;
7277 } else {
7278 if (preamble_type & WLC_SHORT_PREAMBLE)
7279 dur -= BPHY_PLCP_SHORT_TIME;
7280 else
7281 dur -= BPHY_PLCP_TIME;
7282 mac_len = dur * rate;
7283 /* divide out factor of 2 in rate (1/2 mbps) */
7284 mac_len = mac_len / 8 / 2;
7285 }
7286 return mac_len;
7287 }
7288
7289 static uint
7290 wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7291 {
7292 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7293 wlc->pub->unit, rspec, preamble_type);
7294 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7295 * or equal to the rate of the immediately previous frame in the FES
7296 */
7297 rspec = WLC_BASIC_RATE(wlc, rspec);
7298 ASSERT(VALID_RATE_DBG(wlc, rspec));
7299
7300 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7301 return wlc_calc_frame_time(wlc, rspec, preamble_type,
7302 (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN +
7303 FCS_LEN));
7304 }
7305
7306 static uint BCMFASTPATH
7307 wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7308 {
7309 uint dur = 0;
7310
7311 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7312 wlc->pub->unit, rspec, preamble_type);
7313 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7314 * or equal to the rate of the immediately previous frame in the FES
7315 */
7316 rspec = WLC_BASIC_RATE(wlc, rspec);
7317 ASSERT(VALID_RATE_DBG(wlc, rspec));
7318
7319 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7320 dur =
7321 wlc_calc_frame_time(wlc, rspec, preamble_type,
7322 (DOT11_ACK_LEN + FCS_LEN));
7323 return dur;
7324 }
7325
7326 static uint
7327 wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7328 {
7329 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7330 wlc->pub->unit, rspec, preamble_type);
7331 return wlc_calc_ack_time(wlc, rspec, preamble_type);
7332 }
7333
7334 /* derive wlc->band->basic_rate[] table from 'rateset' */
7335 void wlc_rate_lookup_init(struct wlc_info *wlc, wlc_rateset_t *rateset)
7336 {
7337 u8 rate;
7338 u8 mandatory;
7339 u8 cck_basic = 0;
7340 u8 ofdm_basic = 0;
7341 u8 *br = wlc->band->basic_rate;
7342 uint i;
7343
7344 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7345 memset(br, 0, WLC_MAXRATE + 1);
7346
7347 /* For each basic rate in the rates list, make an entry in the
7348 * best basic lookup.
7349 */
7350 for (i = 0; i < rateset->count; i++) {
7351 /* only make an entry for a basic rate */
7352 if (!(rateset->rates[i] & WLC_RATE_FLAG))
7353 continue;
7354
7355 /* mask off basic bit */
7356 rate = (rateset->rates[i] & RATE_MASK);
7357
7358 if (rate > WLC_MAXRATE) {
7359 WL_ERROR("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n",
7360 rateset->rates[i]);
7361 continue;
7362 }
7363
7364 br[rate] = rate;
7365 }
7366
7367 /* The rate lookup table now has non-zero entries for each
7368 * basic rate, equal to the basic rate: br[basicN] = basicN
7369 *
7370 * To look up the best basic rate corresponding to any
7371 * particular rate, code can use the basic_rate table
7372 * like this
7373 *
7374 * basic_rate = wlc->band->basic_rate[tx_rate]
7375 *
7376 * Make sure there is a best basic rate entry for
7377 * every rate by walking up the table from low rates
7378 * to high, filling in holes in the lookup table
7379 */
7380
7381 for (i = 0; i < wlc->band->hw_rateset.count; i++) {
7382 rate = wlc->band->hw_rateset.rates[i];
7383 ASSERT(rate <= WLC_MAXRATE);
7384
7385 if (br[rate] != 0) {
7386 /* This rate is a basic rate.
7387 * Keep track of the best basic rate so far by
7388 * modulation type.
7389 */
7390 if (IS_OFDM(rate))
7391 ofdm_basic = rate;
7392 else
7393 cck_basic = rate;
7394
7395 continue;
7396 }
7397
7398 /* This rate is not a basic rate so figure out the
7399 * best basic rate less than this rate and fill in
7400 * the hole in the table
7401 */
7402
7403 br[rate] = IS_OFDM(rate) ? ofdm_basic : cck_basic;
7404
7405 if (br[rate] != 0)
7406 continue;
7407
7408 if (IS_OFDM(rate)) {
7409 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7410 if (rate >= WLC_RATE_24M)
7411 mandatory = WLC_RATE_24M;
7412 else if (rate >= WLC_RATE_12M)
7413 mandatory = WLC_RATE_12M;
7414 else
7415 mandatory = WLC_RATE_6M;
7416 } else {
7417 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7418 mandatory = rate;
7419 }
7420
7421 br[rate] = mandatory;
7422 }
7423 }
7424
7425 static void wlc_write_rate_shm(struct wlc_info *wlc, u8 rate, u8 basic_rate)
7426 {
7427 u8 phy_rate, index;
7428 u8 basic_phy_rate, basic_index;
7429 u16 dir_table, basic_table;
7430 u16 basic_ptr;
7431
7432 /* Shared memory address for the table we are reading */
7433 dir_table = IS_OFDM(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B;
7434
7435 /* Shared memory address for the table we are writing */
7436 basic_table = IS_OFDM(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B;
7437
7438 /*
7439 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7440 * the index into the rate table.
7441 */
7442 phy_rate = rate_info[rate] & RATE_MASK;
7443 basic_phy_rate = rate_info[basic_rate] & RATE_MASK;
7444 index = phy_rate & 0xf;
7445 basic_index = basic_phy_rate & 0xf;
7446
7447 /* Find the SHM pointer to the ACK rate entry by looking in the
7448 * Direct-map Table
7449 */
7450 basic_ptr = wlc_read_shm(wlc, (dir_table + basic_index * 2));
7451
7452 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7453 * to the correct basic rate for the given incoming rate
7454 */
7455 wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr);
7456 }
7457
7458 static const wlc_rateset_t *wlc_rateset_get_hwrs(struct wlc_info *wlc)
7459 {
7460 const wlc_rateset_t *rs_dflt;
7461
7462 if (WLC_PHY_11N_CAP(wlc->band)) {
7463 if (BAND_5G(wlc->band->bandtype))
7464 rs_dflt = &ofdm_mimo_rates;
7465 else
7466 rs_dflt = &cck_ofdm_mimo_rates;
7467 } else if (wlc->band->gmode)
7468 rs_dflt = &cck_ofdm_rates;
7469 else
7470 rs_dflt = &cck_rates;
7471
7472 return rs_dflt;
7473 }
7474
7475 void wlc_set_ratetable(struct wlc_info *wlc)
7476 {
7477 const wlc_rateset_t *rs_dflt;
7478 wlc_rateset_t rs;
7479 u8 rate, basic_rate;
7480 uint i;
7481
7482 rs_dflt = wlc_rateset_get_hwrs(wlc);
7483 ASSERT(rs_dflt != NULL);
7484
7485 wlc_rateset_copy(rs_dflt, &rs);
7486 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7487
7488 /* walk the phy rate table and update SHM basic rate lookup table */
7489 for (i = 0; i < rs.count; i++) {
7490 rate = rs.rates[i] & RATE_MASK;
7491
7492 /* for a given rate WLC_BASIC_RATE returns the rate at
7493 * which a response ACK/CTS should be sent.
7494 */
7495 basic_rate = WLC_BASIC_RATE(wlc, rate);
7496 if (basic_rate == 0) {
7497 /* This should only happen if we are using a
7498 * restricted rateset.
7499 */
7500 basic_rate = rs.rates[0] & RATE_MASK;
7501 }
7502
7503 wlc_write_rate_shm(wlc, rate, basic_rate);
7504 }
7505 }
7506
7507 /*
7508 * Return true if the specified rate is supported by the specified band.
7509 * WLC_BAND_AUTO indicates the current band.
7510 */
7511 bool wlc_valid_rate(struct wlc_info *wlc, ratespec_t rspec, int band,
7512 bool verbose)
7513 {
7514 wlc_rateset_t *hw_rateset;
7515 uint i;
7516
7517 if ((band == WLC_BAND_AUTO) || (band == wlc->band->bandtype)) {
7518 hw_rateset = &wlc->band->hw_rateset;
7519 } else if (NBANDS(wlc) > 1) {
7520 hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset;
7521 } else {
7522 /* other band specified and we are a single band device */
7523 return false;
7524 }
7525
7526 /* check if this is a mimo rate */
7527 if (IS_MCS(rspec)) {
7528 if (!VALID_MCS((rspec & RSPEC_RATE_MASK)))
7529 goto error;
7530
7531 return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK));
7532 }
7533
7534 for (i = 0; i < hw_rateset->count; i++)
7535 if (hw_rateset->rates[i] == RSPEC2RATE(rspec))
7536 return true;
7537 error:
7538 if (verbose) {
7539 WL_ERROR("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n",
7540 wlc->pub->unit, rspec);
7541 }
7542
7543 return false;
7544 }
7545
7546 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap)
7547 {
7548 uint i;
7549 struct wlcband *band;
7550
7551 for (i = 0; i < NBANDS(wlc); i++) {
7552 if (IS_SINGLEBAND_5G(wlc->deviceid))
7553 i = BAND_5G_INDEX;
7554 band = wlc->bandstate[i];
7555 if (band->bandtype == WLC_BAND_5G) {
7556 if ((bwcap == WLC_N_BW_40ALL)
7557 || (bwcap == WLC_N_BW_20IN2G_40IN5G))
7558 band->mimo_cap_40 = true;
7559 else
7560 band->mimo_cap_40 = false;
7561 } else {
7562 ASSERT(band->bandtype == WLC_BAND_2G);
7563 if (bwcap == WLC_N_BW_40ALL)
7564 band->mimo_cap_40 = true;
7565 else
7566 band->mimo_cap_40 = false;
7567 }
7568 }
7569
7570 wlc->mimo_band_bwcap = bwcap;
7571 }
7572
7573 void wlc_mod_prb_rsp_rate_table(struct wlc_info *wlc, uint frame_len)
7574 {
7575 const wlc_rateset_t *rs_dflt;
7576 wlc_rateset_t rs;
7577 u8 rate;
7578 u16 entry_ptr;
7579 u8 plcp[D11_PHY_HDR_LEN];
7580 u16 dur, sifs;
7581 uint i;
7582
7583 sifs = SIFS(wlc->band);
7584
7585 rs_dflt = wlc_rateset_get_hwrs(wlc);
7586 ASSERT(rs_dflt != NULL);
7587
7588 wlc_rateset_copy(rs_dflt, &rs);
7589 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7590
7591 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7592 for (i = 0; i < rs.count; i++) {
7593 rate = rs.rates[i] & RATE_MASK;
7594
7595 entry_ptr = wlc_rate_shm_offset(wlc, rate);
7596
7597 /* Calculate the Probe Response PLCP for the given rate */
7598 wlc_compute_plcp(wlc, rate, frame_len, plcp);
7599
7600 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7601 dur =
7602 (u16) wlc_calc_frame_time(wlc, rate, WLC_LONG_PREAMBLE,
7603 frame_len);
7604 dur += sifs;
7605
7606 /* Update the SHM Rate Table entry Probe Response values */
7607 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS,
7608 (u16) (plcp[0] + (plcp[1] << 8)));
7609 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS + 2,
7610 (u16) (plcp[2] + (plcp[3] << 8)));
7611 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_DUR_POS, dur);
7612 }
7613 }
7614
7615 u16
7616 wlc_compute_bcntsfoff(struct wlc_info *wlc, ratespec_t rspec,
7617 bool short_preamble, bool phydelay)
7618 {
7619 uint bcntsfoff = 0;
7620
7621 if (IS_MCS(rspec)) {
7622 WL_ERROR("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7623 wlc->pub->unit, rspec);
7624 } else if (IS_OFDM(rspec)) {
7625 /* tx delay from MAC through phy to air (2.1 usec) +
7626 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7627 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7628 * bytes at beacon rate)
7629 */
7630 bcntsfoff += phydelay ? D11A_PHY_TX_DELAY : 0;
7631 bcntsfoff += APHY_PREAMBLE_TIME + APHY_SIGNAL_TIME;
7632 bcntsfoff +=
7633 wlc_compute_airtime(wlc, rspec,
7634 APHY_SERVICE_NBITS / 8 +
7635 DOT11_MAC_HDR_LEN);
7636 } else {
7637 /* tx delay from MAC through phy to air (3.4 usec) +
7638 * phy header time (long preamble + PLCP == 192 usec) +
7639 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7640 */
7641 bcntsfoff += phydelay ? D11B_PHY_TX_DELAY : 0;
7642 bcntsfoff +=
7643 short_preamble ? D11B_PHY_SPREHDR_TIME :
7644 D11B_PHY_LPREHDR_TIME;
7645 bcntsfoff += wlc_compute_airtime(wlc, rspec, DOT11_MAC_HDR_LEN);
7646 }
7647 return (u16) (bcntsfoff);
7648 }
7649
7650 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7651 *
7652 * PLCP header is 6 bytes.
7653 * 802.11 A3 header is 24 bytes.
7654 * Max beacon frame body template length is 112 bytes.
7655 * Max probe resp frame body template length is 110 bytes.
7656 *
7657 * *len on input contains the max length of the packet available.
7658 *
7659 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7660 * and included up to, but not including, the 4 byte FCS.
7661 */
7662 static void
7663 wlc_bcn_prb_template(struct wlc_info *wlc, uint type, ratespec_t bcn_rspec,
7664 wlc_bsscfg_t *cfg, u16 *buf, int *len)
7665 {
7666 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
7667 cck_phy_hdr_t *plcp;
7668 struct ieee80211_mgmt *h;
7669 int hdr_len, body_len;
7670
7671 ASSERT(*len >= 142);
7672 ASSERT(type == FC_BEACON || type == FC_PROBE_RESP);
7673
7674 if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON)
7675 hdr_len = DOT11_MAC_HDR_LEN;
7676 else
7677 hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN;
7678 body_len = *len - hdr_len; /* calc buffer size provided for frame body */
7679
7680 *len = hdr_len + body_len; /* return actual size */
7681
7682 /* format PHY and MAC headers */
7683 memset((char *)buf, 0, hdr_len);
7684
7685 plcp = (cck_phy_hdr_t *) buf;
7686
7687 /* PLCP for Probe Response frames are filled in from core's rate table */
7688 if (type == FC_BEACON && !MBSS_BCN_ENAB(cfg)) {
7689 /* fill in PLCP */
7690 wlc_compute_plcp(wlc, bcn_rspec,
7691 (DOT11_MAC_HDR_LEN + body_len + FCS_LEN),
7692 (u8 *) plcp);
7693
7694 }
7695 /* "Regular" and 16 MBSS but not for 4 MBSS */
7696 /* Update the phytxctl for the beacon based on the rspec */
7697 if (!SOFTBCN_ENAB(cfg))
7698 wlc_beacon_phytxctl_txant_upd(wlc, bcn_rspec);
7699
7700 if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON)
7701 h = (struct ieee80211_mgmt *)&plcp[0];
7702 else
7703 h = (struct ieee80211_mgmt *)&plcp[1];
7704
7705 /* fill in 802.11 header */
7706 h->frame_control = cpu_to_le16((u16) type);
7707
7708 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7709 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7710 if (type == FC_BEACON)
7711 memcpy(&h->da, &ether_bcast, ETH_ALEN);
7712 memcpy(&h->sa, &cfg->cur_etheraddr, ETH_ALEN);
7713 memcpy(&h->bssid, &cfg->BSSID, ETH_ALEN);
7714
7715 /* SEQ filled in by MAC */
7716
7717 return;
7718 }
7719
7720 int wlc_get_header_len()
7721 {
7722 return TXOFF;
7723 }
7724
7725 /* Update a beacon for a particular BSS
7726 * For MBSS, this updates the software template and sets "latest" to the index of the
7727 * template updated.
7728 * Otherwise, it updates the hardware template.
7729 */
7730 void wlc_bss_update_beacon(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7731 {
7732 int len = BCN_TMPL_LEN;
7733
7734 /* Clear the soft intmask */
7735 wlc->defmacintmask &= ~MI_BCNTPL;
7736
7737 if (!cfg->up) { /* Only allow updates on an UP bss */
7738 return;
7739 }
7740
7741 if (MBSS_BCN_ENAB(cfg)) { /* Optimize: Some of if/else could be combined */
7742 } else if (HWBCN_ENAB(cfg)) { /* Hardware beaconing for this config */
7743 u16 bcn[BCN_TMPL_LEN / 2];
7744 u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
7745 d11regs_t *regs = wlc->regs;
7746 struct osl_info *osh = NULL;
7747
7748 osh = wlc->osh;
7749
7750 /* Check if both templates are in use, if so sched. an interrupt
7751 * that will call back into this routine
7752 */
7753 if ((R_REG(osh, &regs->maccommand) & both_valid) == both_valid) {
7754 /* clear any previous status */
7755 W_REG(osh, &regs->macintstatus, MI_BCNTPL);
7756 }
7757 /* Check that after scheduling the interrupt both of the
7758 * templates are still busy. if not clear the int. & remask
7759 */
7760 if ((R_REG(osh, &regs->maccommand) & both_valid) == both_valid) {
7761 wlc->defmacintmask |= MI_BCNTPL;
7762 return;
7763 }
7764
7765 wlc->bcn_rspec =
7766 wlc_lowest_basic_rspec(wlc, &cfg->current_bss->rateset);
7767 ASSERT(wlc_valid_rate
7768 (wlc, wlc->bcn_rspec,
7769 CHSPEC_IS2G(cfg->current_bss->
7770 chanspec) ? WLC_BAND_2G : WLC_BAND_5G,
7771 true));
7772
7773 /* update the template and ucode shm */
7774 wlc_bcn_prb_template(wlc, FC_BEACON, wlc->bcn_rspec, cfg, bcn,
7775 &len);
7776 wlc_write_hw_bcntemplates(wlc, bcn, len, false);
7777 }
7778 }
7779
7780 /*
7781 * Update all beacons for the system.
7782 */
7783 void wlc_update_beacon(struct wlc_info *wlc)
7784 {
7785 int idx;
7786 wlc_bsscfg_t *bsscfg;
7787
7788 /* update AP or IBSS beacons */
7789 FOREACH_BSS(wlc, idx, bsscfg) {
7790 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7791 wlc_bss_update_beacon(wlc, bsscfg);
7792 }
7793 }
7794
7795 /* Write ssid into shared memory */
7796 void wlc_shm_ssid_upd(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7797 {
7798 u8 *ssidptr = cfg->SSID;
7799 u16 base = M_SSID;
7800 u8 ssidbuf[IEEE80211_MAX_SSID_LEN];
7801
7802 /* padding the ssid with zero and copy it into shm */
7803 memset(ssidbuf, 0, IEEE80211_MAX_SSID_LEN);
7804 memcpy(ssidbuf, ssidptr, cfg->SSID_len);
7805
7806 wlc_copyto_shm(wlc, base, ssidbuf, IEEE80211_MAX_SSID_LEN);
7807
7808 if (!MBSS_BCN_ENAB(cfg))
7809 wlc_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len);
7810 }
7811
7812 void wlc_update_probe_resp(struct wlc_info *wlc, bool suspend)
7813 {
7814 int idx;
7815 wlc_bsscfg_t *bsscfg;
7816
7817 /* update AP or IBSS probe responses */
7818 FOREACH_BSS(wlc, idx, bsscfg) {
7819 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7820 wlc_bss_update_probe_resp(wlc, bsscfg, suspend);
7821 }
7822 }
7823
7824 void
7825 wlc_bss_update_probe_resp(struct wlc_info *wlc, wlc_bsscfg_t *cfg, bool suspend)
7826 {
7827 u16 prb_resp[BCN_TMPL_LEN / 2];
7828 int len = BCN_TMPL_LEN;
7829
7830 /* write the probe response to hardware, or save in the config structure */
7831 if (!MBSS_PRB_ENAB(cfg)) {
7832
7833 /* create the probe response template */
7834 wlc_bcn_prb_template(wlc, FC_PROBE_RESP, 0, cfg, prb_resp,
7835 &len);
7836
7837 if (suspend)
7838 wlc_suspend_mac_and_wait(wlc);
7839
7840 /* write the probe response into the template region */
7841 wlc_bmac_write_template_ram(wlc->hw, T_PRS_TPL_BASE,
7842 (len + 3) & ~3, prb_resp);
7843
7844 /* write the length of the probe response frame (+PLCP/-FCS) */
7845 wlc_write_shm(wlc, M_PRB_RESP_FRM_LEN, (u16) len);
7846
7847 /* write the SSID and SSID length */
7848 wlc_shm_ssid_upd(wlc, cfg);
7849
7850 /*
7851 * Write PLCP headers and durations for probe response frames at all rates.
7852 * Use the actual frame length covered by the PLCP header for the call to
7853 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7854 */
7855 len += (-D11_PHY_HDR_LEN + FCS_LEN);
7856 wlc_mod_prb_rsp_rate_table(wlc, (u16) len);
7857
7858 if (suspend)
7859 wlc_enable_mac(wlc);
7860 } else { /* Generating probe resp in sw; update local template */
7861 ASSERT(0 && "No software probe response support without MBSS");
7862 }
7863 }
7864
7865 /* prepares pdu for transmission. returns BCM error codes */
7866 int wlc_prep_pdu(struct wlc_info *wlc, struct sk_buff *pdu, uint *fifop)
7867 {
7868 struct osl_info *osh;
7869 uint fifo;
7870 d11txh_t *txh;
7871 struct ieee80211_hdr *h;
7872 struct scb *scb;
7873 u16 fc;
7874
7875 osh = wlc->osh;
7876
7877 ASSERT(pdu);
7878 txh = (d11txh_t *) (pdu->data);
7879 ASSERT(txh);
7880 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
7881 ASSERT(h);
7882 fc = le16_to_cpu(h->frame_control);
7883
7884 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7885 fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK;
7886
7887 scb = NULL;
7888
7889 *fifop = fifo;
7890
7891 /* return if insufficient dma resources */
7892 if (TXAVAIL(wlc, fifo) < MAX_DMA_SEGS) {
7893 /* Mark precedences related to this FIFO, unsendable */
7894 WLC_TX_FIFO_CLEAR(wlc, fifo);
7895 return BCME_BUSY;
7896 }
7897
7898 if (!ieee80211_is_data(txh->MacFrameControl))
7899 wlc->pub->_cnt->txctl++;
7900
7901 return 0;
7902 }
7903
7904 /* init tx reported rate mechanism */
7905 void wlc_reprate_init(struct wlc_info *wlc)
7906 {
7907 int i;
7908 wlc_bsscfg_t *bsscfg;
7909
7910 FOREACH_BSS(wlc, i, bsscfg) {
7911 wlc_bsscfg_reprate_init(bsscfg);
7912 }
7913 }
7914
7915 /* per bsscfg init tx reported rate mechanism */
7916 void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg)
7917 {
7918 bsscfg->txrspecidx = 0;
7919 memset((char *)bsscfg->txrspec, 0, sizeof(bsscfg->txrspec));
7920 }
7921
7922 /* Retrieve a consolidated set of revision information,
7923 * typically for the WLC_GET_REVINFO ioctl
7924 */
7925 int wlc_get_revision_info(struct wlc_info *wlc, void *buf, uint len)
7926 {
7927 wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf;
7928
7929 if (len < WL_REV_INFO_LEGACY_LENGTH)
7930 return BCME_BUFTOOSHORT;
7931
7932 rinfo->vendorid = wlc->vendorid;
7933 rinfo->deviceid = wlc->deviceid;
7934 rinfo->radiorev = (wlc->band->radiorev << IDCODE_REV_SHIFT) |
7935 (wlc->band->radioid << IDCODE_ID_SHIFT);
7936 rinfo->chiprev = wlc->pub->sih->chiprev;
7937 rinfo->corerev = wlc->pub->corerev;
7938 rinfo->boardid = wlc->pub->sih->boardtype;
7939 rinfo->boardvendor = wlc->pub->sih->boardvendor;
7940 rinfo->boardrev = wlc->pub->boardrev;
7941 rinfo->ucoderev = wlc->ucode_rev;
7942 rinfo->driverrev = EPI_VERSION_NUM;
7943 rinfo->bus = wlc->pub->sih->bustype;
7944 rinfo->chipnum = wlc->pub->sih->chip;
7945
7946 if (len >= (offsetof(wlc_rev_info_t, chippkg))) {
7947 rinfo->phytype = wlc->band->phytype;
7948 rinfo->phyrev = wlc->band->phyrev;
7949 rinfo->anarev = 0; /* obsolete stuff, suppress */
7950 }
7951
7952 if (len >= sizeof(*rinfo)) {
7953 rinfo->chippkg = wlc->pub->sih->chippkg;
7954 }
7955
7956 return BCME_OK;
7957 }
7958
7959 void wlc_default_rateset(struct wlc_info *wlc, wlc_rateset_t *rs)
7960 {
7961 wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype,
7962 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
7963 CHSPEC_WLC_BW(wlc->default_bss->chanspec),
7964 wlc->stf->txstreams);
7965 }
7966
7967 static void wlc_bss_default_init(struct wlc_info *wlc)
7968 {
7969 chanspec_t chanspec;
7970 struct wlcband *band;
7971 wlc_bss_info_t *bi = wlc->default_bss;
7972
7973 /* init default and target BSS with some sane initial values */
7974 memset((char *)(bi), 0, sizeof(wlc_bss_info_t));
7975 bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT :
7976 BEACON_INTERVAL_DEFAULT;
7977 bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT :
7978 DTIM_INTERVAL_DEFAULT;
7979
7980 /* fill the default channel as the first valid channel
7981 * starting from the 2G channels
7982 */
7983 chanspec = CH20MHZ_CHSPEC(1);
7984 ASSERT(chanspec != INVCHANSPEC);
7985
7986 wlc->home_chanspec = bi->chanspec = chanspec;
7987
7988 /* find the band of our default channel */
7989 band = wlc->band;
7990 if (NBANDS(wlc) > 1 && band->bandunit != CHSPEC_WLCBANDUNIT(chanspec))
7991 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
7992
7993 /* init bss rates to the band specific default rate set */
7994 wlc_rateset_default(&bi->rateset, NULL, band->phytype, band->bandtype,
7995 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
7996 CHSPEC_WLC_BW(chanspec), wlc->stf->txstreams);
7997
7998 if (N_ENAB(wlc->pub))
7999 bi->flags |= WLC_BSS_HT;
8000 }
8001
8002 void
8003 wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high, u32 b_low)
8004 {
8005 if (b_low > *a_low) {
8006 /* low half needs a carry */
8007 b_high += 1;
8008 }
8009 *a_low -= b_low;
8010 *a_high -= b_high;
8011 }
8012
8013 static ratespec_t
8014 mac80211_wlc_set_nrate(struct wlc_info *wlc, struct wlcband *cur_band,
8015 u32 int_val)
8016 {
8017 u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT;
8018 u8 rate = int_val & NRATE_RATE_MASK;
8019 ratespec_t rspec;
8020 bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE);
8021 bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT);
8022 bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY)
8023 == NRATE_OVERRIDE_MCS_ONLY);
8024 int bcmerror = 0;
8025
8026 if (!ismcs) {
8027 return (ratespec_t) rate;
8028 }
8029
8030 /* validate the combination of rate/mcs/stf is allowed */
8031 if (N_ENAB(wlc->pub) && ismcs) {
8032 /* mcs only allowed when nmode */
8033 if (stf > PHY_TXC1_MODE_SDM) {
8034 WL_ERROR("wl%d: %s: Invalid stf\n",
8035 WLCWLUNIT(wlc), __func__);
8036 bcmerror = BCME_RANGE;
8037 goto done;
8038 }
8039
8040 /* mcs 32 is a special case, DUP mode 40 only */
8041 if (rate == 32) {
8042 if (!CHSPEC_IS40(wlc->home_chanspec) ||
8043 ((stf != PHY_TXC1_MODE_SISO)
8044 && (stf != PHY_TXC1_MODE_CDD))) {
8045 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8046 WLCWLUNIT(wlc), __func__);
8047 bcmerror = BCME_RANGE;
8048 goto done;
8049 }
8050 /* mcs > 7 must use stf SDM */
8051 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) {
8052 /* mcs > 7 must use stf SDM */
8053 if (stf != PHY_TXC1_MODE_SDM) {
8054 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8055 WLCWLUNIT(wlc), __func__, rate);
8056 stf = PHY_TXC1_MODE_SDM;
8057 }
8058 } else {
8059 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8060 if ((stf > PHY_TXC1_MODE_STBC) ||
8061 (!WLC_STBC_CAP_PHY(wlc)
8062 && (stf == PHY_TXC1_MODE_STBC))) {
8063 WL_ERROR("wl%d: %s: Invalid STBC\n",
8064 WLCWLUNIT(wlc), __func__);
8065 bcmerror = BCME_RANGE;
8066 goto done;
8067 }
8068 }
8069 } else if (IS_OFDM(rate)) {
8070 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
8071 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8072 WLCWLUNIT(wlc), __func__);
8073 bcmerror = BCME_RANGE;
8074 goto done;
8075 }
8076 } else if (IS_CCK(rate)) {
8077 if ((cur_band->bandtype != WLC_BAND_2G)
8078 || (stf != PHY_TXC1_MODE_SISO)) {
8079 WL_ERROR("wl%d: %s: Invalid CCK\n",
8080 WLCWLUNIT(wlc), __func__);
8081 bcmerror = BCME_RANGE;
8082 goto done;
8083 }
8084 } else {
8085 WL_ERROR("wl%d: %s: Unknown rate type\n",
8086 WLCWLUNIT(wlc), __func__);
8087 bcmerror = BCME_RANGE;
8088 goto done;
8089 }
8090 /* make sure multiple antennae are available for non-siso rates */
8091 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
8092 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8093 WLCWLUNIT(wlc), __func__);
8094 bcmerror = BCME_RANGE;
8095 goto done;
8096 }
8097
8098 rspec = rate;
8099 if (ismcs) {
8100 rspec |= RSPEC_MIMORATE;
8101 /* For STBC populate the STC field of the ratespec */
8102 if (stf == PHY_TXC1_MODE_STBC) {
8103 u8 stc;
8104 stc = 1; /* Nss for single stream is always 1 */
8105 rspec |= (stc << RSPEC_STC_SHIFT);
8106 }
8107 }
8108
8109 rspec |= (stf << RSPEC_STF_SHIFT);
8110
8111 if (override_mcs_only)
8112 rspec |= RSPEC_OVERRIDE_MCS_ONLY;
8113
8114 if (issgi)
8115 rspec |= RSPEC_SHORT_GI;
8116
8117 if ((rate != 0)
8118 && !wlc_valid_rate(wlc, rspec, cur_band->bandtype, true)) {
8119 return rate;
8120 }
8121
8122 return rspec;
8123 done:
8124 WL_ERROR("Hoark\n");
8125 return rate;
8126 }
8127
8128 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8129 static int
8130 wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
8131 bool writeToShm)
8132 {
8133 int idle_busy_ratio_x_16 = 0;
8134 uint offset =
8135 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM :
8136 M_TX_IDLE_BUSY_RATIO_X_16_CCK;
8137 if (duty_cycle > 100 || duty_cycle < 0) {
8138 WL_ERROR("wl%d: duty cycle value off limit\n", wlc->pub->unit);
8139 return BCME_RANGE;
8140 }
8141 if (duty_cycle)
8142 idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle;
8143 /* Only write to shared memory when wl is up */
8144 if (writeToShm)
8145 wlc_write_shm(wlc, offset, (u16) idle_busy_ratio_x_16);
8146
8147 if (isOFDM)
8148 wlc->tx_duty_cycle_ofdm = (u16) duty_cycle;
8149 else
8150 wlc->tx_duty_cycle_cck = (u16) duty_cycle;
8151
8152 return BCME_OK;
8153 }
8154
8155 /* Read a single u16 from shared memory.
8156 * SHM 'offset' needs to be an even address
8157 */
8158 u16 wlc_read_shm(struct wlc_info *wlc, uint offset)
8159 {
8160 return wlc_bmac_read_shm(wlc->hw, offset);
8161 }
8162
8163 /* Write a single u16 to shared memory.
8164 * SHM 'offset' needs to be an even address
8165 */
8166 void wlc_write_shm(struct wlc_info *wlc, uint offset, u16 v)
8167 {
8168 wlc_bmac_write_shm(wlc->hw, offset, v);
8169 }
8170
8171 /* Set a range of shared memory to a value.
8172 * SHM 'offset' needs to be an even address and
8173 * Range length 'len' must be an even number of bytes
8174 */
8175 void wlc_set_shm(struct wlc_info *wlc, uint offset, u16 v, int len)
8176 {
8177 /* offset and len need to be even */
8178 ASSERT((offset & 1) == 0);
8179 ASSERT((len & 1) == 0);
8180
8181 if (len <= 0)
8182 return;
8183
8184 wlc_bmac_set_shm(wlc->hw, offset, v, len);
8185 }
8186
8187 /* Copy a buffer to shared memory.
8188 * SHM 'offset' needs to be an even address and
8189 * Buffer length 'len' must be an even number of bytes
8190 */
8191 void wlc_copyto_shm(struct wlc_info *wlc, uint offset, const void *buf, int len)
8192 {
8193 /* offset and len need to be even */
8194 ASSERT((offset & 1) == 0);
8195 ASSERT((len & 1) == 0);
8196
8197 if (len <= 0)
8198 return;
8199 wlc_bmac_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8200
8201 }
8202
8203 /* Copy from shared memory to a buffer.
8204 * SHM 'offset' needs to be an even address and
8205 * Buffer length 'len' must be an even number of bytes
8206 */
8207 void wlc_copyfrom_shm(struct wlc_info *wlc, uint offset, void *buf, int len)
8208 {
8209 /* offset and len need to be even */
8210 ASSERT((offset & 1) == 0);
8211 ASSERT((len & 1) == 0);
8212
8213 if (len <= 0)
8214 return;
8215
8216 wlc_bmac_copyfrom_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8217 }
8218
8219 /* wrapper BMAC functions to for HIGH driver access */
8220 void wlc_mctrl(struct wlc_info *wlc, u32 mask, u32 val)
8221 {
8222 wlc_bmac_mctrl(wlc->hw, mask, val);
8223 }
8224
8225 void wlc_corereset(struct wlc_info *wlc, u32 flags)
8226 {
8227 wlc_bmac_corereset(wlc->hw, flags);
8228 }
8229
8230 void wlc_mhf(struct wlc_info *wlc, u8 idx, u16 mask, u16 val, int bands)
8231 {
8232 wlc_bmac_mhf(wlc->hw, idx, mask, val, bands);
8233 }
8234
8235 u16 wlc_mhf_get(struct wlc_info *wlc, u8 idx, int bands)
8236 {
8237 return wlc_bmac_mhf_get(wlc->hw, idx, bands);
8238 }
8239
8240 int wlc_xmtfifo_sz_get(struct wlc_info *wlc, uint fifo, uint *blocks)
8241 {
8242 return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks);
8243 }
8244
8245 void wlc_write_template_ram(struct wlc_info *wlc, int offset, int len,
8246 void *buf)
8247 {
8248 wlc_bmac_write_template_ram(wlc->hw, offset, len, buf);
8249 }
8250
8251 void wlc_write_hw_bcntemplates(struct wlc_info *wlc, void *bcn, int len,
8252 bool both)
8253 {
8254 wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both);
8255 }
8256
8257 void
8258 wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
8259 const u8 *addr)
8260 {
8261 wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr);
8262 if (match_reg_offset == RCM_BSSID_OFFSET)
8263 memcpy(wlc->cfg->BSSID, addr, ETH_ALEN);
8264 }
8265
8266 void wlc_set_rcmta(struct wlc_info *wlc, int idx, const u8 *addr)
8267 {
8268 wlc_bmac_set_rcmta(wlc->hw, idx, addr);
8269 }
8270
8271 void wlc_read_tsf(struct wlc_info *wlc, u32 *tsf_l_ptr, u32 *tsf_h_ptr)
8272 {
8273 wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr);
8274 }
8275
8276 void wlc_set_cwmin(struct wlc_info *wlc, u16 newmin)
8277 {
8278 wlc->band->CWmin = newmin;
8279 wlc_bmac_set_cwmin(wlc->hw, newmin);
8280 }
8281
8282 void wlc_set_cwmax(struct wlc_info *wlc, u16 newmax)
8283 {
8284 wlc->band->CWmax = newmax;
8285 wlc_bmac_set_cwmax(wlc->hw, newmax);
8286 }
8287
8288 void wlc_fifoerrors(struct wlc_info *wlc)
8289 {
8290
8291 wlc_bmac_fifoerrors(wlc->hw);
8292 }
8293
8294 /* Search mem rw utilities */
8295
8296 void wlc_pllreq(struct wlc_info *wlc, bool set, mbool req_bit)
8297 {
8298 wlc_bmac_pllreq(wlc->hw, set, req_bit);
8299 }
8300
8301 void wlc_reset_bmac_done(struct wlc_info *wlc)
8302 {
8303 }
8304
8305 void wlc_ht_mimops_cap_update(struct wlc_info *wlc, u8 mimops_mode)
8306 {
8307 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_SM_PS;
8308 wlc->ht_cap.cap_info |= (mimops_mode << IEEE80211_HT_CAP_SM_PS_SHIFT);
8309
8310 if (AP_ENAB(wlc->pub) && wlc->clk) {
8311 wlc_update_beacon(wlc);
8312 wlc_update_probe_resp(wlc, true);
8313 }
8314 }
8315
8316 /* check for the particular priority flow control bit being set */
8317 bool
8318 wlc_txflowcontrol_prio_isset(struct wlc_info *wlc, struct wlc_txq_info *q,
8319 int prio)
8320 {
8321 uint prio_mask;
8322
8323 if (prio == ALLPRIO) {
8324 prio_mask = TXQ_STOP_FOR_PRIOFC_MASK;
8325 } else {
8326 ASSERT(prio >= 0 && prio <= MAXPRIO);
8327 prio_mask = NBITVAL(prio);
8328 }
8329
8330 return (q->stopped & prio_mask) == prio_mask;
8331 }
8332
8333 /* propogate the flow control to all interfaces using the given tx queue */
8334 void wlc_txflowcontrol(struct wlc_info *wlc, struct wlc_txq_info *qi,
8335 bool on, int prio)
8336 {
8337 uint prio_bits;
8338 uint cur_bits;
8339
8340 WL_TRACE("%s: flow control kicks in\n", __func__);
8341
8342 if (prio == ALLPRIO) {
8343 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK;
8344 } else {
8345 ASSERT(prio >= 0 && prio <= MAXPRIO);
8346 prio_bits = NBITVAL(prio);
8347 }
8348
8349 cur_bits = qi->stopped & prio_bits;
8350
8351 /* Check for the case of no change and return early
8352 * Otherwise update the bit and continue
8353 */
8354 if (on) {
8355 if (cur_bits == prio_bits) {
8356 return;
8357 }
8358 mboolset(qi->stopped, prio_bits);
8359 } else {
8360 if (cur_bits == 0) {
8361 return;
8362 }
8363 mboolclr(qi->stopped, prio_bits);
8364 }
8365
8366 /* If there is a flow control override we will not change the external
8367 * flow control state.
8368 */
8369 if (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK) {
8370 return;
8371 }
8372
8373 wlc_txflowcontrol_signal(wlc, qi, on, prio);
8374 }
8375
8376 void
8377 wlc_txflowcontrol_override(struct wlc_info *wlc, struct wlc_txq_info *qi,
8378 bool on, uint override)
8379 {
8380 uint prev_override;
8381
8382 ASSERT(override != 0);
8383 ASSERT((override & TXQ_STOP_FOR_PRIOFC_MASK) == 0);
8384
8385 prev_override = (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK);
8386
8387 /* Update the flow control bits and do an early return if there is
8388 * no change in the external flow control state.
8389 */
8390 if (on) {
8391 mboolset(qi->stopped, override);
8392 /* if there was a previous override bit on, then setting this
8393 * makes no difference.
8394 */
8395 if (prev_override) {
8396 return;
8397 }
8398
8399 wlc_txflowcontrol_signal(wlc, qi, ON, ALLPRIO);
8400 } else {
8401 mboolclr(qi->stopped, override);
8402 /* clearing an override bit will only make a difference for
8403 * flow control if it was the only bit set. For any other
8404 * override setting, just return
8405 */
8406 if (prev_override != override) {
8407 return;
8408 }
8409
8410 if (qi->stopped == 0) {
8411 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8412 } else {
8413 int prio;
8414
8415 for (prio = MAXPRIO; prio >= 0; prio--) {
8416 if (!mboolisset(qi->stopped, NBITVAL(prio)))
8417 wlc_txflowcontrol_signal(wlc, qi, OFF,
8418 prio);
8419 }
8420 }
8421 }
8422 }
8423
8424 static void wlc_txflowcontrol_reset(struct wlc_info *wlc)
8425 {
8426 struct wlc_txq_info *qi;
8427
8428 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
8429 if (qi->stopped) {
8430 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8431 qi->stopped = 0;
8432 }
8433 }
8434 }
8435
8436 static void
8437 wlc_txflowcontrol_signal(struct wlc_info *wlc, struct wlc_txq_info *qi, bool on,
8438 int prio)
8439 {
8440 struct wlc_if *wlcif;
8441
8442 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) {
8443 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED)
8444 wl_txflowcontrol(wlc->wl, wlcif->wlif, on, prio);
8445 }
8446 }
8447
8448 static struct wlc_txq_info *wlc_txq_alloc(struct wlc_info *wlc,
8449 struct osl_info *osh)
8450 {
8451 struct wlc_txq_info *qi, *p;
8452
8453 qi = wlc_calloc(wlc->pub->unit, sizeof(struct wlc_txq_info));
8454 if (qi != NULL) {
8455 /*
8456 * Have enough room for control packets along with HI watermark
8457 * Also, add room to txq for total psq packets if all the SCBs
8458 * leave PS mode. The watermark for flowcontrol to OS packets
8459 * will remain the same
8460 */
8461 pktq_init(&qi->q, WLC_PREC_COUNT,
8462 (2 * wlc->pub->tunables->datahiwat) + PKTQ_LEN_DEFAULT
8463 + wlc->pub->psq_pkts_total);
8464
8465 /* add this queue to the the global list */
8466 p = wlc->tx_queues;
8467 if (p == NULL) {
8468 wlc->tx_queues = qi;
8469 } else {
8470 while (p->next != NULL)
8471 p = p->next;
8472 p->next = qi;
8473 }
8474 }
8475 return qi;
8476 }
8477
8478 static void wlc_txq_free(struct wlc_info *wlc, struct osl_info *osh,
8479 struct wlc_txq_info *qi)
8480 {
8481 struct wlc_txq_info *p;
8482
8483 if (qi == NULL)
8484 return;
8485
8486 /* remove the queue from the linked list */
8487 p = wlc->tx_queues;
8488 if (p == qi)
8489 wlc->tx_queues = p->next;
8490 else {
8491 while (p != NULL && p->next != qi)
8492 p = p->next;
8493 ASSERT(p->next == qi);
8494 if (p != NULL)
8495 p->next = p->next->next;
8496 }
8497
8498 kfree(qi);
8499 }
8500
8501 /*
8502 * Flag 'scan in progress' to withold dynamic phy calibration
8503 */
8504 void wlc_scan_start(struct wlc_info *wlc)
8505 {
8506 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, true);
8507 }
8508
8509 void wlc_scan_stop(struct wlc_info *wlc)
8510 {
8511 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, false);
8512 }
8513
8514 void wlc_associate_upd(struct wlc_info *wlc, bool state)
8515 {
8516 wlc->pub->associated = state;
8517 wlc->cfg->associated = state;
8518 }
This page took 0.202211 seconds and 4 git commands to generate.