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