staging: brcm80211: removed sys directory layer from brcmsmac driver
[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 if (wlc->pub->radio_disabled)
2308 wlc_radio_disable(wlc);
2309 else
2310 wlc_radio_enable(wlc);
2311 }
2312
2313 /* maintain LED behavior in down state */
2314 static void wlc_down_led_upd(struct wlc_info *wlc)
2315 {
2316 ASSERT(!wlc->pub->up);
2317
2318 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2319 /* turn on sbclk if necessary */
2320 if (!AP_ENAB(wlc->pub)) {
2321 wlc_pllreq(wlc, true, WLC_PLLREQ_FLIP);
2322
2323 wlc_pllreq(wlc, false, WLC_PLLREQ_FLIP);
2324 }
2325 }
2326
2327 void wlc_radio_disable(struct wlc_info *wlc)
2328 {
2329 if (!wlc->pub->up) {
2330 wlc_down_led_upd(wlc);
2331 return;
2332 }
2333
2334 wlc_radio_monitor_start(wlc);
2335 wl_down(wlc->wl);
2336 }
2337
2338 static void wlc_radio_enable(struct wlc_info *wlc)
2339 {
2340 if (wlc->pub->up)
2341 return;
2342
2343 if (DEVICEREMOVED(wlc))
2344 return;
2345
2346 if (!wlc->down_override) { /* imposed by wl down/out ioctl */
2347 wl_up(wlc->wl);
2348 }
2349 }
2350
2351 /* periodical query hw radio button while driver is "down" */
2352 static void wlc_radio_timer(void *arg)
2353 {
2354 struct wlc_info *wlc = (struct wlc_info *) arg;
2355
2356 if (DEVICEREMOVED(wlc)) {
2357 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2358 wl_down(wlc->wl);
2359 return;
2360 }
2361
2362 /* cap mpc off count */
2363 if (wlc->mpc_offcnt < WLC_MPC_MAX_DELAYCNT)
2364 wlc->mpc_offcnt++;
2365
2366 /* validate all the reasons driver could be down and running this radio_timer */
2367 ASSERT(wlc->pub->radio_disabled || wlc->down_override);
2368 wlc_radio_hwdisable_upd(wlc);
2369 wlc_radio_upd(wlc);
2370 }
2371
2372 static bool wlc_radio_monitor_start(struct wlc_info *wlc)
2373 {
2374 /* Don't start the timer if HWRADIO feature is disabled */
2375 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO))
2376 return true;
2377
2378 wlc->radio_monitor = true;
2379 wlc_pllreq(wlc, true, WLC_PLLREQ_RADIO_MON);
2380 wl_add_timer(wlc->wl, wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, true);
2381 return true;
2382 }
2383
2384 bool wlc_radio_monitor_stop(struct wlc_info *wlc)
2385 {
2386 if (!wlc->radio_monitor)
2387 return true;
2388
2389 ASSERT((wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO) !=
2390 WL_SWFL_NOHWRADIO);
2391
2392 wlc->radio_monitor = false;
2393 wlc_pllreq(wlc, false, WLC_PLLREQ_RADIO_MON);
2394 return wl_del_timer(wlc->wl, wlc->radio_timer);
2395 }
2396
2397 /* bring the driver down, but don't reset hardware */
2398 void wlc_out(struct wlc_info *wlc)
2399 {
2400 wlc_bmac_set_noreset(wlc->hw, true);
2401 wlc_radio_upd(wlc);
2402 wl_down(wlc->wl);
2403 wlc_bmac_set_noreset(wlc->hw, false);
2404
2405 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2406 wlc->clk = true;
2407
2408 /* This will make sure that when 'up' is done
2409 * after 'out' it'll restore hardware (especially gpios)
2410 */
2411 wlc->pub->hw_up = false;
2412 }
2413
2414 #if defined(BCMDBG)
2415 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2416 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2417 * in prec_map. Of course, ignore this rule when block_datafifo is set
2418 */
2419 static bool wlc_tx_prec_map_verify(struct wlc_info *wlc)
2420 {
2421 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2422 * fail the check.
2423 */
2424 if (!EDCF_ENAB(wlc->pub)) {
2425 if (!(WLC_TX_FIFO_CHECK(wlc, TX_DATA_FIFO) ||
2426 WLC_TX_FIFO_CHECK(wlc, TX_CTL_FIFO)))
2427 return false;
2428 else
2429 return true;
2430 }
2431
2432 return WLC_TX_FIFO_CHECK(wlc, TX_AC_BK_FIFO)
2433 && WLC_TX_FIFO_CHECK(wlc, TX_AC_BE_FIFO)
2434 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VI_FIFO)
2435 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VO_FIFO);
2436 }
2437 #endif /* BCMDBG */
2438
2439 static void wlc_watchdog_by_timer(void *arg)
2440 {
2441 struct wlc_info *wlc = (struct wlc_info *) arg;
2442 wlc_watchdog(arg);
2443 if (WLC_WATCHDOG_TBTT(wlc)) {
2444 /* set to normal osl watchdog period */
2445 wl_del_timer(wlc->wl, wlc->wdtimer);
2446 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
2447 true);
2448 }
2449 }
2450
2451 /* common watchdog code */
2452 static void wlc_watchdog(void *arg)
2453 {
2454 struct wlc_info *wlc = (struct wlc_info *) arg;
2455 int i;
2456 wlc_bsscfg_t *cfg;
2457
2458 WL_TRACE("wl%d: wlc_watchdog\n", wlc->pub->unit);
2459
2460 if (!wlc->pub->up)
2461 return;
2462
2463 if (DEVICEREMOVED(wlc)) {
2464 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2465 wl_down(wlc->wl);
2466 return;
2467 }
2468
2469 /* increment second count */
2470 wlc->pub->now++;
2471
2472 /* delay radio disable */
2473 if (wlc->mpc_delay_off) {
2474 if (--wlc->mpc_delay_off == 0) {
2475 mboolset(wlc->pub->radio_disabled,
2476 WL_RADIO_MPC_DISABLE);
2477 if (wlc->mpc && wlc_ismpc(wlc))
2478 wlc->mpc_offcnt = 0;
2479 wlc->mpc_laston_ts = OSL_SYSUPTIME();
2480 }
2481 }
2482
2483 /* mpc sync */
2484 wlc_radio_mpc_upd(wlc);
2485 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2486 wlc_radio_hwdisable_upd(wlc);
2487 wlc_radio_upd(wlc);
2488 /* if ismpc, driver should be in down state if up/down is allowed */
2489 if (wlc->mpc && wlc_ismpc(wlc))
2490 ASSERT(!wlc->pub->up);
2491 /* if radio is disable, driver may be down, quit here */
2492 if (wlc->pub->radio_disabled)
2493 return;
2494
2495 wlc_bmac_watchdog(wlc);
2496
2497 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2498 if ((WLC_UPDATE_STATS(wlc))
2499 && (!(wlc->pub->now % SW_TIMER_MAC_STAT_UPD)))
2500 wlc_statsupd(wlc);
2501
2502 /* Manage TKIP countermeasures timers */
2503 FOREACH_BSS(wlc, i, cfg) {
2504 if (cfg->tk_cm_dt) {
2505 cfg->tk_cm_dt--;
2506 }
2507 if (cfg->tk_cm_bt) {
2508 cfg->tk_cm_bt--;
2509 }
2510 }
2511
2512 /* Call any registered watchdog handlers */
2513 for (i = 0; i < WLC_MAXMODULES; i++) {
2514 if (wlc->modulecb[i].watchdog_fn)
2515 wlc->modulecb[i].watchdog_fn(wlc->modulecb[i].hdl);
2516 }
2517
2518 if (WLCISNPHY(wlc->band) && !wlc->pub->tempsense_disable &&
2519 ((wlc->pub->now - wlc->tempsense_lasttime) >=
2520 WLC_TEMPSENSE_PERIOD)) {
2521 wlc->tempsense_lasttime = wlc->pub->now;
2522 wlc_tempsense_upd(wlc);
2523 }
2524 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2525 ASSERT(wlc_bmac_taclear(wlc->hw, true));
2526
2527 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2528 ASSERT(wlc_tx_prec_map_verify(wlc));
2529
2530 ASSERT(wlc_ps_check(wlc));
2531 }
2532
2533 /* make interface operational */
2534 int wlc_up(struct wlc_info *wlc)
2535 {
2536 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2537
2538 /* HW is turned off so don't try to access it */
2539 if (wlc->pub->hw_off || DEVICEREMOVED(wlc))
2540 return BCME_RADIOOFF;
2541
2542 if (!wlc->pub->hw_up) {
2543 wlc_bmac_hw_up(wlc->hw);
2544 wlc->pub->hw_up = true;
2545 }
2546
2547 if ((wlc->pub->boardflags & BFL_FEM)
2548 && (wlc->pub->sih->chip == BCM4313_CHIP_ID)) {
2549 if (wlc->pub->boardrev >= 0x1250
2550 && (wlc->pub->boardflags & BFL_FEM_BT)) {
2551 wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL,
2552 MHF5_4313_GPIOCTRL, WLC_BAND_ALL);
2553 } else {
2554 wlc_mhf(wlc, MHF4, MHF4_EXTPA_ENABLE, MHF4_EXTPA_ENABLE,
2555 WLC_BAND_ALL);
2556 }
2557 }
2558
2559 /*
2560 * Need to read the hwradio status here to cover the case where the system
2561 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2562 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2563 * don't call radio_update to avoid looping wlc_up.
2564 *
2565 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2566 */
2567 if (!wlc->pub->radio_disabled) {
2568 int status = wlc_bmac_up_prep(wlc->hw);
2569 if (status == BCME_RADIOOFF) {
2570 if (!mboolisset
2571 (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) {
2572 int idx;
2573 wlc_bsscfg_t *bsscfg;
2574 mboolset(wlc->pub->radio_disabled,
2575 WL_RADIO_HW_DISABLE);
2576
2577 FOREACH_BSS(wlc, idx, bsscfg) {
2578 if (!BSSCFG_STA(bsscfg)
2579 || !bsscfg->enable || !bsscfg->BSS)
2580 continue;
2581 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2582 wlc->pub->unit, idx);
2583 }
2584 }
2585 } else
2586 ASSERT(!status);
2587 }
2588
2589 if (wlc->pub->radio_disabled) {
2590 wlc_radio_monitor_start(wlc);
2591 return 0;
2592 }
2593
2594 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2595 wlc->clk = true;
2596
2597 wlc_radio_monitor_stop(wlc);
2598
2599 /* Set EDCF hostflags */
2600 if (EDCF_ENAB(wlc->pub)) {
2601 wlc_mhf(wlc, MHF1, MHF1_EDCF, MHF1_EDCF, WLC_BAND_ALL);
2602 } else {
2603 wlc_mhf(wlc, MHF1, MHF1_EDCF, 0, WLC_BAND_ALL);
2604 }
2605
2606 if (WLC_WAR16165(wlc))
2607 wlc_mhf(wlc, MHF2, MHF2_PCISLOWCLKWAR, MHF2_PCISLOWCLKWAR,
2608 WLC_BAND_ALL);
2609
2610 wl_init(wlc->wl);
2611 wlc->pub->up = true;
2612
2613 if (wlc->bandinit_pending) {
2614 wlc_suspend_mac_and_wait(wlc);
2615 wlc_set_chanspec(wlc, wlc->default_bss->chanspec);
2616 wlc->bandinit_pending = false;
2617 wlc_enable_mac(wlc);
2618 }
2619
2620 wlc_bmac_up_finish(wlc->hw);
2621
2622 /* other software states up after ISR is running */
2623 /* start APs that were to be brought up but are not up yet */
2624 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2625
2626 /* Program the TX wme params with the current settings */
2627 wlc_wme_retries_write(wlc);
2628
2629 /* start one second watchdog timer */
2630 ASSERT(!wlc->WDarmed);
2631 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true);
2632 wlc->WDarmed = true;
2633
2634 /* ensure antenna config is up to date */
2635 wlc_stf_phy_txant_upd(wlc);
2636 /* ensure LDPC config is in sync */
2637 wlc_ht_update_ldpc(wlc, wlc->stf->ldpc);
2638
2639 return 0;
2640 }
2641
2642 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2643 static void wlc_tx_prec_map_init(struct wlc_info *wlc)
2644 {
2645 wlc->tx_prec_map = WLC_PREC_BMP_ALL;
2646 memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16));
2647
2648 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2649 * if either is full.
2650 */
2651 if (!EDCF_ENAB(wlc->pub)) {
2652 wlc->fifo2prec_map[TX_DATA_FIFO] = WLC_PREC_BMP_ALL;
2653 wlc->fifo2prec_map[TX_CTL_FIFO] = WLC_PREC_BMP_ALL;
2654 } else {
2655 wlc->fifo2prec_map[TX_AC_BK_FIFO] = WLC_PREC_BMP_AC_BK;
2656 wlc->fifo2prec_map[TX_AC_BE_FIFO] = WLC_PREC_BMP_AC_BE;
2657 wlc->fifo2prec_map[TX_AC_VI_FIFO] = WLC_PREC_BMP_AC_VI;
2658 wlc->fifo2prec_map[TX_AC_VO_FIFO] = WLC_PREC_BMP_AC_VO;
2659 }
2660 }
2661
2662 static uint wlc_down_del_timer(struct wlc_info *wlc)
2663 {
2664 uint callbacks = 0;
2665
2666 return callbacks;
2667 }
2668
2669 /*
2670 * Mark the interface nonoperational, stop the software mechanisms,
2671 * disable the hardware, free any transient buffer state.
2672 * Return a count of the number of driver callbacks still pending.
2673 */
2674 uint wlc_down(struct wlc_info *wlc)
2675 {
2676
2677 uint callbacks = 0;
2678 int i;
2679 bool dev_gone = false;
2680 wlc_txq_info_t *qi;
2681
2682 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2683
2684 /* check if we are already in the going down path */
2685 if (wlc->going_down) {
2686 WL_ERROR("wl%d: %s: Driver going down so return\n",
2687 wlc->pub->unit, __func__);
2688 return 0;
2689 }
2690 if (!wlc->pub->up)
2691 return callbacks;
2692
2693 /* in between, mpc could try to bring down again.. */
2694 wlc->going_down = true;
2695
2696 callbacks += wlc_bmac_down_prep(wlc->hw);
2697
2698 dev_gone = DEVICEREMOVED(wlc);
2699
2700 /* Call any registered down handlers */
2701 for (i = 0; i < WLC_MAXMODULES; i++) {
2702 if (wlc->modulecb[i].down_fn)
2703 callbacks +=
2704 wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl);
2705 }
2706
2707 /* cancel the watchdog timer */
2708 if (wlc->WDarmed) {
2709 if (!wl_del_timer(wlc->wl, wlc->wdtimer))
2710 callbacks++;
2711 wlc->WDarmed = false;
2712 }
2713 /* cancel all other timers */
2714 callbacks += wlc_down_del_timer(wlc);
2715
2716 /* interrupt must have been blocked */
2717 ASSERT((wlc->macintmask == 0) || !wlc->pub->up);
2718
2719 wlc->pub->up = false;
2720
2721 wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL);
2722
2723 /* clear txq flow control */
2724 wlc_txflowcontrol_reset(wlc);
2725
2726 /* flush tx queues */
2727 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
2728 pktq_flush(wlc->osh, &qi->q, true, NULL, 0);
2729 ASSERT(pktq_empty(&qi->q));
2730 }
2731
2732 /* flush event queue.
2733 * Should be the last thing done after all the events are generated
2734 * Just delivers the events synchronously instead of waiting for a timer
2735 */
2736 callbacks += wlc_eventq_down(wlc->eventq);
2737
2738 callbacks += wlc_bmac_down_finish(wlc->hw);
2739
2740 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2741 wlc->clk = false;
2742
2743
2744 /* Verify all packets are flushed from the driver */
2745 if (wlc->osh->pktalloced != 0) {
2746 WL_ERROR("%d packets not freed at wlc_down!!!!!!\n",
2747 wlc->osh->pktalloced);
2748 }
2749 #ifdef BCMDBG
2750 /* Since all the packets should have been freed,
2751 * all callbacks should have been called
2752 */
2753 for (i = 1; i <= wlc->pub->tunables->maxpktcb; i++)
2754 ASSERT(wlc->pkt_callback[i].fn == NULL);
2755 #endif
2756 wlc->going_down = false;
2757 return callbacks;
2758 }
2759
2760 /* Set the current gmode configuration */
2761 int wlc_set_gmode(struct wlc_info *wlc, u8 gmode, bool config)
2762 {
2763 int ret = 0;
2764 uint i;
2765 wlc_rateset_t rs;
2766 /* Default to 54g Auto */
2767 s8 shortslot = WLC_SHORTSLOT_AUTO; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2768 bool shortslot_restrict = false; /* Restrict association to stations that support shortslot
2769 */
2770 bool ignore_bcns = true; /* Ignore legacy beacons on the same channel */
2771 bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */
2772 int preamble = WLC_PLCP_LONG; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2773 bool preamble_restrict = false; /* Restrict association to stations that support short
2774 * preambles
2775 */
2776 struct wlcband *band;
2777
2778 /* if N-support is enabled, allow Gmode set as long as requested
2779 * Gmode is not GMODE_LEGACY_B
2780 */
2781 if (N_ENAB(wlc->pub) && gmode == GMODE_LEGACY_B)
2782 return BCME_UNSUPPORTED;
2783
2784 /* verify that we are dealing with 2G band and grab the band pointer */
2785 if (wlc->band->bandtype == WLC_BAND_2G)
2786 band = wlc->band;
2787 else if ((NBANDS(wlc) > 1) &&
2788 (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == WLC_BAND_2G))
2789 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
2790 else
2791 return BCME_BADBAND;
2792
2793 /* Legacy or bust when no OFDM is supported by regulatory */
2794 if ((wlc_channel_locale_flags_in_band(wlc->cmi, band->bandunit) &
2795 WLC_NO_OFDM) && (gmode != GMODE_LEGACY_B))
2796 return BCME_RANGE;
2797
2798 /* update configuration value */
2799 if (config == true)
2800 wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode);
2801
2802 /* Clear supported rates filter */
2803 memset(&wlc->sup_rates_override, 0, sizeof(wlc_rateset_t));
2804
2805 /* Clear rateset override */
2806 memset(&rs, 0, sizeof(wlc_rateset_t));
2807
2808 switch (gmode) {
2809 case GMODE_LEGACY_B:
2810 shortslot = WLC_SHORTSLOT_OFF;
2811 wlc_rateset_copy(&gphy_legacy_rates, &rs);
2812
2813 break;
2814
2815 case GMODE_LRS:
2816 if (AP_ENAB(wlc->pub))
2817 wlc_rateset_copy(&cck_rates, &wlc->sup_rates_override);
2818 break;
2819
2820 case GMODE_AUTO:
2821 /* Accept defaults */
2822 break;
2823
2824 case GMODE_ONLY:
2825 ofdm_basic = true;
2826 preamble = WLC_PLCP_SHORT;
2827 preamble_restrict = true;
2828 break;
2829
2830 case GMODE_PERFORMANCE:
2831 if (AP_ENAB(wlc->pub)) /* Put all rates into the Supported Rates element */
2832 wlc_rateset_copy(&cck_ofdm_rates,
2833 &wlc->sup_rates_override);
2834
2835 shortslot = WLC_SHORTSLOT_ON;
2836 shortslot_restrict = true;
2837 ofdm_basic = true;
2838 preamble = WLC_PLCP_SHORT;
2839 preamble_restrict = true;
2840 break;
2841
2842 default:
2843 /* Error */
2844 WL_ERROR("wl%d: %s: invalid gmode %d\n",
2845 wlc->pub->unit, __func__, gmode);
2846 return BCME_UNSUPPORTED;
2847 }
2848
2849 /*
2850 * If we are switching to gmode == GMODE_LEGACY_B,
2851 * clean up rate info that may refer to OFDM rates.
2852 */
2853 if ((gmode == GMODE_LEGACY_B) && (band->gmode != GMODE_LEGACY_B)) {
2854 band->gmode = gmode;
2855 if (band->rspec_override && !IS_CCK(band->rspec_override)) {
2856 band->rspec_override = 0;
2857 wlc_reprate_init(wlc);
2858 }
2859 if (band->mrspec_override && !IS_CCK(band->mrspec_override)) {
2860 band->mrspec_override = 0;
2861 }
2862 }
2863
2864 band->gmode = gmode;
2865
2866 wlc->ignore_bcns = ignore_bcns;
2867
2868 wlc->shortslot_override = shortslot;
2869
2870 if (AP_ENAB(wlc->pub)) {
2871 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2872 wlc->PLCPHdr_override =
2873 (preamble !=
2874 WLC_PLCP_LONG) ? WLC_PLCP_SHORT : WLC_PLCP_AUTO;
2875 }
2876
2877 if ((AP_ENAB(wlc->pub) && preamble != WLC_PLCP_LONG)
2878 || preamble == WLC_PLCP_SHORT)
2879 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2880 else
2881 wlc->default_bss->capability &= ~WLAN_CAPABILITY_SHORT_PREAMBLE;
2882
2883 /* Update shortslot capability bit for AP and IBSS */
2884 if ((AP_ENAB(wlc->pub) && shortslot == WLC_SHORTSLOT_AUTO) ||
2885 shortslot == WLC_SHORTSLOT_ON)
2886 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2887 else
2888 wlc->default_bss->capability &=
2889 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
2890
2891 /* Use the default 11g rateset */
2892 if (!rs.count)
2893 wlc_rateset_copy(&cck_ofdm_rates, &rs);
2894
2895 if (ofdm_basic) {
2896 for (i = 0; i < rs.count; i++) {
2897 if (rs.rates[i] == WLC_RATE_6M
2898 || rs.rates[i] == WLC_RATE_12M
2899 || rs.rates[i] == WLC_RATE_24M)
2900 rs.rates[i] |= WLC_RATE_FLAG;
2901 }
2902 }
2903
2904 /* Set default bss rateset */
2905 wlc->default_bss->rateset.count = rs.count;
2906 bcopy((char *)rs.rates, (char *)wlc->default_bss->rateset.rates,
2907 sizeof(wlc->default_bss->rateset.rates));
2908
2909 return ret;
2910 }
2911
2912 static int wlc_nmode_validate(struct wlc_info *wlc, s32 nmode)
2913 {
2914 int err = 0;
2915
2916 switch (nmode) {
2917
2918 case OFF:
2919 break;
2920
2921 case AUTO:
2922 case WL_11N_2x2:
2923 case WL_11N_3x3:
2924 if (!(WLC_PHY_11N_CAP(wlc->band)))
2925 err = BCME_BADBAND;
2926 break;
2927
2928 default:
2929 err = BCME_RANGE;
2930 break;
2931 }
2932
2933 return err;
2934 }
2935
2936 int wlc_set_nmode(struct wlc_info *wlc, s32 nmode)
2937 {
2938 uint i;
2939 int err;
2940
2941 err = wlc_nmode_validate(wlc, nmode);
2942 ASSERT(err == 0);
2943 if (err)
2944 return err;
2945
2946 switch (nmode) {
2947 case OFF:
2948 wlc->pub->_n_enab = OFF;
2949 wlc->default_bss->flags &= ~WLC_BSS_HT;
2950 /* delete the mcs rates from the default and hw ratesets */
2951 wlc_rateset_mcs_clear(&wlc->default_bss->rateset);
2952 for (i = 0; i < NBANDS(wlc); i++) {
2953 memset(wlc->bandstate[i]->hw_rateset.mcs, 0,
2954 MCSSET_LEN);
2955 if (IS_MCS(wlc->band->rspec_override)) {
2956 wlc->bandstate[i]->rspec_override = 0;
2957 wlc_reprate_init(wlc);
2958 }
2959 if (IS_MCS(wlc->band->mrspec_override))
2960 wlc->bandstate[i]->mrspec_override = 0;
2961 }
2962 break;
2963
2964 case AUTO:
2965 if (wlc->stf->txstreams == WL_11N_3x3)
2966 nmode = WL_11N_3x3;
2967 else
2968 nmode = WL_11N_2x2;
2969 case WL_11N_2x2:
2970 case WL_11N_3x3:
2971 ASSERT(WLC_PHY_11N_CAP(wlc->band));
2972 /* force GMODE_AUTO if NMODE is ON */
2973 wlc_set_gmode(wlc, GMODE_AUTO, true);
2974 if (nmode == WL_11N_3x3)
2975 wlc->pub->_n_enab = SUPPORT_HT;
2976 else
2977 wlc->pub->_n_enab = SUPPORT_11N;
2978 wlc->default_bss->flags |= WLC_BSS_HT;
2979 /* add the mcs rates to the default and hw ratesets */
2980 wlc_rateset_mcs_build(&wlc->default_bss->rateset,
2981 wlc->stf->txstreams);
2982 for (i = 0; i < NBANDS(wlc); i++)
2983 memcpy(wlc->bandstate[i]->hw_rateset.mcs,
2984 wlc->default_bss->rateset.mcs, MCSSET_LEN);
2985 break;
2986
2987 default:
2988 ASSERT(0);
2989 break;
2990 }
2991
2992 return err;
2993 }
2994
2995 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg)
2996 {
2997 wlc_rateset_t rs, new;
2998 uint bandunit;
2999
3000 bcopy((char *)rs_arg, (char *)&rs, sizeof(wlc_rateset_t));
3001
3002 /* check for bad count value */
3003 if ((rs.count == 0) || (rs.count > WLC_NUMRATES))
3004 return BCME_BADRATESET;
3005
3006 /* try the current band */
3007 bandunit = wlc->band->bandunit;
3008 bcopy((char *)&rs, (char *)&new, sizeof(wlc_rateset_t));
3009 if (wlc_rate_hwrs_filter_sort_validate
3010 (&new, &wlc->bandstate[bandunit]->hw_rateset, true,
3011 wlc->stf->txstreams))
3012 goto good;
3013
3014 /* try the other band */
3015 if (IS_MBAND_UNLOCKED(wlc)) {
3016 bandunit = OTHERBANDUNIT(wlc);
3017 bcopy((char *)&rs, (char *)&new, sizeof(wlc_rateset_t));
3018 if (wlc_rate_hwrs_filter_sort_validate(&new,
3019 &wlc->
3020 bandstate[bandunit]->
3021 hw_rateset, true,
3022 wlc->stf->txstreams))
3023 goto good;
3024 }
3025
3026 return BCME_ERROR;
3027
3028 good:
3029 /* apply new rateset */
3030 bcopy((char *)&new, (char *)&wlc->default_bss->rateset,
3031 sizeof(wlc_rateset_t));
3032 bcopy((char *)&new, (char *)&wlc->bandstate[bandunit]->defrateset,
3033 sizeof(wlc_rateset_t));
3034 return 0;
3035 }
3036
3037 /* simplified integer set interface for common ioctl handler */
3038 int wlc_set(struct wlc_info *wlc, int cmd, int arg)
3039 {
3040 return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL);
3041 }
3042
3043 /* simplified integer get interface for common ioctl handler */
3044 int wlc_get(struct wlc_info *wlc, int cmd, int *arg)
3045 {
3046 return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL);
3047 }
3048
3049 static void wlc_ofdm_rateset_war(struct wlc_info *wlc)
3050 {
3051 u8 r;
3052 bool war = false;
3053
3054 if (wlc->cfg->associated)
3055 r = wlc->cfg->current_bss->rateset.rates[0];
3056 else
3057 r = wlc->default_bss->rateset.rates[0];
3058
3059 wlc_phy_ofdm_rateset_war(wlc->band->pi, war);
3060
3061 return;
3062 }
3063
3064 int
3065 wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3066 struct wlc_if *wlcif)
3067 {
3068 return _wlc_ioctl(wlc, cmd, arg, len, wlcif);
3069 }
3070
3071 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3072 static int
3073 _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3074 struct wlc_if *wlcif)
3075 {
3076 int val, *pval;
3077 bool bool_val;
3078 int bcmerror;
3079 d11regs_t *regs;
3080 uint i;
3081 struct scb *nextscb;
3082 bool ta_ok;
3083 uint band;
3084 rw_reg_t *r;
3085 wlc_bsscfg_t *bsscfg;
3086 struct osl_info *osh;
3087 wlc_bss_info_t *current_bss;
3088
3089 /* update bsscfg pointer */
3090 bsscfg = NULL; /* XXX: Hack bsscfg to be size one and use this globally */
3091 current_bss = NULL;
3092
3093 /* initialize the following to get rid of compiler warning */
3094 nextscb = NULL;
3095 ta_ok = false;
3096 band = 0;
3097 r = NULL;
3098
3099 /* If the device is turned off, then it's not "removed" */
3100 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) {
3101 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
3102 wl_down(wlc->wl);
3103 return BCME_ERROR;
3104 }
3105
3106 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
3107
3108 /* default argument is generic integer */
3109 pval = arg ? (int *)arg:NULL;
3110
3111 /* This will prevent the misaligned access */
3112 if (pval && (u32) len >= sizeof(val))
3113 bcopy(pval, &val, sizeof(val));
3114 else
3115 val = 0;
3116
3117 /* bool conversion to avoid duplication below */
3118 bool_val = val != 0;
3119
3120 if (cmd != WLC_SET_CHANNEL)
3121 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3122 cmd, (uint)val, val, len);
3123
3124 bcmerror = 0;
3125 regs = wlc->regs;
3126 osh = wlc->osh;
3127
3128 /* A few commands don't need any arguments; all the others do. */
3129 switch (cmd) {
3130 case WLC_UP:
3131 case WLC_OUT:
3132 case WLC_DOWN:
3133 case WLC_DISASSOC:
3134 case WLC_RESTART:
3135 case WLC_REBOOT:
3136 case WLC_START_CHANNEL_QA:
3137 case WLC_INIT:
3138 break;
3139
3140 default:
3141 if ((arg == NULL) || (len <= 0)) {
3142 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3143 wlc->pub->unit, __func__, cmd);
3144 bcmerror = BCME_BADARG;
3145 goto done;
3146 }
3147 }
3148
3149 switch (cmd) {
3150
3151 #if defined(BCMDBG)
3152 case WLC_GET_MSGLEVEL:
3153 *pval = wl_msg_level;
3154 break;
3155
3156 case WLC_SET_MSGLEVEL:
3157 wl_msg_level = val;
3158 break;
3159 #endif
3160
3161 case WLC_GET_INSTANCE:
3162 *pval = wlc->pub->unit;
3163 break;
3164
3165 case WLC_GET_CHANNEL:{
3166 channel_info_t *ci = (channel_info_t *) arg;
3167
3168 ASSERT(len > (int)sizeof(ci));
3169
3170 ci->hw_channel =
3171 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC);
3172 ci->target_channel =
3173 CHSPEC_CHANNEL(wlc->default_bss->chanspec);
3174 ci->scan_channel = 0;
3175
3176 break;
3177 }
3178
3179 case WLC_SET_CHANNEL:{
3180 chanspec_t chspec = CH20MHZ_CHSPEC(val);
3181
3182 if (val < 0 || val > MAXCHANNEL) {
3183 bcmerror = BCME_OUTOFRANGECHAN;
3184 break;
3185 }
3186
3187 if (!wlc_valid_chanspec_db(wlc->cmi, chspec)) {
3188 bcmerror = BCME_BADCHAN;
3189 break;
3190 }
3191
3192 if (!wlc->pub->up && IS_MBAND_UNLOCKED(wlc)) {
3193 if (wlc->band->bandunit !=
3194 CHSPEC_WLCBANDUNIT(chspec))
3195 wlc->bandinit_pending = true;
3196 else
3197 wlc->bandinit_pending = false;
3198 }
3199
3200 wlc->default_bss->chanspec = chspec;
3201 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3202 if (wlc->pub->up && !wlc->pub->associated &&
3203 (WLC_BAND_PI_RADIO_CHANSPEC != chspec)) {
3204 wlc_set_home_chanspec(wlc, chspec);
3205 wlc_suspend_mac_and_wait(wlc);
3206 wlc_set_chanspec(wlc, chspec);
3207 wlc_enable_mac(wlc);
3208 }
3209 break;
3210 }
3211
3212 #if defined(BCMDBG)
3213 case WLC_GET_UCFLAGS:
3214 if (!wlc->pub->up) {
3215 bcmerror = BCME_NOTUP;
3216 break;
3217 }
3218
3219 /* optional band is stored in the second integer of incoming buffer */
3220 band =
3221 (len <
3222 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3223
3224 /* bcmerror checking */
3225 bcmerror = wlc_iocregchk(wlc, band);
3226 if (bcmerror)
3227 break;
3228
3229 if (val >= MHFMAX) {
3230 bcmerror = BCME_RANGE;
3231 break;
3232 }
3233
3234 *pval = wlc_bmac_mhf_get(wlc->hw, (u8) val, WLC_BAND_AUTO);
3235 break;
3236
3237 case WLC_SET_UCFLAGS:
3238 if (!wlc->pub->up) {
3239 bcmerror = BCME_NOTUP;
3240 break;
3241 }
3242
3243 /* optional band is stored in the second integer of incoming buffer */
3244 band =
3245 (len <
3246 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3247
3248 /* bcmerror checking */
3249 bcmerror = wlc_iocregchk(wlc, band);
3250 if (bcmerror)
3251 break;
3252
3253 i = (u16) val;
3254 if (i >= MHFMAX) {
3255 bcmerror = BCME_RANGE;
3256 break;
3257 }
3258
3259 wlc_mhf(wlc, (u8) i, 0xffff, (u16) (val >> NBITS(u16)),
3260 WLC_BAND_AUTO);
3261 break;
3262
3263 case WLC_GET_SHMEM:
3264 ta_ok = true;
3265
3266 /* optional band is stored in the second integer of incoming buffer */
3267 band =
3268 (len <
3269 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3270
3271 /* bcmerror checking */
3272 bcmerror = wlc_iocregchk(wlc, band);
3273 if (bcmerror)
3274 break;
3275
3276 if (val & 1) {
3277 bcmerror = BCME_BADADDR;
3278 break;
3279 }
3280
3281 *pval = wlc_read_shm(wlc, (u16) val);
3282 break;
3283
3284 case WLC_SET_SHMEM:
3285 ta_ok = true;
3286
3287 /* optional band is stored in the second integer of incoming buffer */
3288 band =
3289 (len <
3290 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3291
3292 /* bcmerror checking */
3293 bcmerror = wlc_iocregchk(wlc, band);
3294 if (bcmerror)
3295 break;
3296
3297 if (val & 1) {
3298 bcmerror = BCME_BADADDR;
3299 break;
3300 }
3301
3302 wlc_write_shm(wlc, (u16) val,
3303 (u16) (val >> NBITS(u16)));
3304 break;
3305
3306 case WLC_R_REG: /* MAC registers */
3307 ta_ok = true;
3308 r = (rw_reg_t *) arg;
3309 band = WLC_BAND_AUTO;
3310
3311 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3312 bcmerror = BCME_BUFTOOSHORT;
3313 break;
3314 }
3315
3316 if (len >= (int)sizeof(rw_reg_t))
3317 band = r->band;
3318
3319 /* bcmerror checking */
3320 bcmerror = wlc_iocregchk(wlc, band);
3321 if (bcmerror)
3322 break;
3323
3324 if ((r->byteoff + r->size) > sizeof(d11regs_t)) {
3325 bcmerror = BCME_BADADDR;
3326 break;
3327 }
3328 if (r->size == sizeof(u32))
3329 r->val =
3330 R_REG(osh,
3331 (u32 *)((unsigned char *)(unsigned long)regs +
3332 r->byteoff));
3333 else if (r->size == sizeof(u16))
3334 r->val =
3335 R_REG(osh,
3336 (u16 *)((unsigned char *)(unsigned long)regs +
3337 r->byteoff));
3338 else
3339 bcmerror = BCME_BADADDR;
3340 break;
3341
3342 case WLC_W_REG:
3343 ta_ok = true;
3344 r = (rw_reg_t *) arg;
3345 band = WLC_BAND_AUTO;
3346
3347 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3348 bcmerror = BCME_BUFTOOSHORT;
3349 break;
3350 }
3351
3352 if (len >= (int)sizeof(rw_reg_t))
3353 band = r->band;
3354
3355 /* bcmerror checking */
3356 bcmerror = wlc_iocregchk(wlc, band);
3357 if (bcmerror)
3358 break;
3359
3360 if (r->byteoff + r->size > sizeof(d11regs_t)) {
3361 bcmerror = BCME_BADADDR;
3362 break;
3363 }
3364 if (r->size == sizeof(u32))
3365 W_REG(osh,
3366 (u32 *)((unsigned char *)(unsigned long) regs +
3367 r->byteoff), r->val);
3368 else if (r->size == sizeof(u16))
3369 W_REG(osh,
3370 (u16 *)((unsigned char *)(unsigned long) regs +
3371 r->byteoff), r->val);
3372 else
3373 bcmerror = BCME_BADADDR;
3374 break;
3375 #endif /* BCMDBG */
3376
3377 case WLC_GET_TXANT:
3378 *pval = wlc->stf->txant;
3379 break;
3380
3381 case WLC_SET_TXANT:
3382 bcmerror = wlc_stf_ant_txant_validate(wlc, (s8) val);
3383 if (bcmerror < 0)
3384 break;
3385
3386 wlc->stf->txant = (s8) val;
3387
3388 /* if down, we are done */
3389 if (!wlc->pub->up)
3390 break;
3391
3392 wlc_suspend_mac_and_wait(wlc);
3393
3394 wlc_stf_phy_txant_upd(wlc);
3395 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
3396
3397 wlc_enable_mac(wlc);
3398
3399 break;
3400
3401 case WLC_GET_ANTDIV:{
3402 u8 phy_antdiv;
3403
3404 /* return configured value if core is down */
3405 if (!wlc->pub->up) {
3406 *pval = wlc->stf->ant_rx_ovr;
3407
3408 } else {
3409 if (wlc_phy_ant_rxdiv_get
3410 (wlc->band->pi, &phy_antdiv))
3411 *pval = (int)phy_antdiv;
3412 else
3413 *pval = (int)wlc->stf->ant_rx_ovr;
3414 }
3415
3416 break;
3417 }
3418 case WLC_SET_ANTDIV:
3419 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3420 if ((val < -1) || (val > 3)) {
3421 bcmerror = BCME_RANGE;
3422 break;
3423 }
3424
3425 if (val == -1)
3426 val = ANT_RX_DIV_DEF;
3427
3428 wlc->stf->ant_rx_ovr = (u8) val;
3429 wlc_phy_ant_rxdiv_set(wlc->band->pi, (u8) val);
3430 break;
3431
3432 case WLC_GET_RX_ANT:{ /* get latest used rx antenna */
3433 u16 rxstatus;
3434
3435 if (!wlc->pub->up) {
3436 bcmerror = BCME_NOTUP;
3437 break;
3438 }
3439
3440 rxstatus = R_REG(wlc->osh, &wlc->regs->phyrxstatus0);
3441 if (rxstatus == 0xdead || rxstatus == (u16) -1) {
3442 bcmerror = BCME_ERROR;
3443 break;
3444 }
3445 *pval = (rxstatus & PRXS0_RXANT_UPSUBBAND) ? 1 : 0;
3446 break;
3447 }
3448
3449 #if defined(BCMDBG)
3450 case WLC_GET_UCANTDIV:
3451 if (!wlc->clk) {
3452 bcmerror = BCME_NOCLK;
3453 break;
3454 }
3455
3456 *pval =
3457 (wlc_bmac_mhf_get(wlc->hw, MHF1, WLC_BAND_AUTO) &
3458 MHF1_ANTDIV);
3459 break;
3460
3461 case WLC_SET_UCANTDIV:{
3462 if (!wlc->pub->up) {
3463 bcmerror = BCME_NOTUP;
3464 break;
3465 }
3466
3467 /* if multiband, band must be locked */
3468 if (IS_MBAND_UNLOCKED(wlc)) {
3469 bcmerror = BCME_NOTBANDLOCKED;
3470 break;
3471 }
3472
3473 /* 4322 supports antdiv in phy, no need to set it to ucode */
3474 if (WLCISNPHY(wlc->band)
3475 && D11REV_IS(wlc->pub->corerev, 16)) {
3476 WL_ERROR("wl%d: can't set ucantdiv for 4322\n",
3477 wlc->pub->unit);
3478 bcmerror = BCME_UNSUPPORTED;
3479 } else
3480 wlc_mhf(wlc, MHF1, MHF1_ANTDIV,
3481 (val ? MHF1_ANTDIV : 0), WLC_BAND_AUTO);
3482 break;
3483 }
3484 #endif /* defined(BCMDBG) */
3485
3486 case WLC_GET_SRL:
3487 *pval = wlc->SRL;
3488 break;
3489
3490 case WLC_SET_SRL:
3491 if (val >= 1 && val <= RETRY_SHORT_MAX) {
3492 int ac;
3493 wlc->SRL = (u16) val;
3494
3495 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3496
3497 for (ac = 0; ac < AC_COUNT; ac++) {
3498 WLC_WME_RETRY_SHORT_SET(wlc, ac, wlc->SRL);
3499 }
3500 wlc_wme_retries_write(wlc);
3501 } else
3502 bcmerror = BCME_RANGE;
3503 break;
3504
3505 case WLC_GET_LRL:
3506 *pval = wlc->LRL;
3507 break;
3508
3509 case WLC_SET_LRL:
3510 if (val >= 1 && val <= 255) {
3511 int ac;
3512 wlc->LRL = (u16) val;
3513
3514 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3515
3516 for (ac = 0; ac < AC_COUNT; ac++) {
3517 WLC_WME_RETRY_LONG_SET(wlc, ac, wlc->LRL);
3518 }
3519 wlc_wme_retries_write(wlc);
3520 } else
3521 bcmerror = BCME_RANGE;
3522 break;
3523
3524 case WLC_GET_CWMIN:
3525 *pval = wlc->band->CWmin;
3526 break;
3527
3528 case WLC_SET_CWMIN:
3529 if (!wlc->clk) {
3530 bcmerror = BCME_NOCLK;
3531 break;
3532 }
3533
3534 if (val >= 1 && val <= 255) {
3535 wlc_set_cwmin(wlc, (u16) val);
3536 } else
3537 bcmerror = BCME_RANGE;
3538 break;
3539
3540 case WLC_GET_CWMAX:
3541 *pval = wlc->band->CWmax;
3542 break;
3543
3544 case WLC_SET_CWMAX:
3545 if (!wlc->clk) {
3546 bcmerror = BCME_NOCLK;
3547 break;
3548 }
3549
3550 if (val >= 255 && val <= 2047) {
3551 wlc_set_cwmax(wlc, (u16) val);
3552 } else
3553 bcmerror = BCME_RANGE;
3554 break;
3555
3556 case WLC_GET_RADIO: /* use mask if don't want to expose some internal bits */
3557 *pval = wlc->pub->radio_disabled;
3558 break;
3559
3560 case WLC_SET_RADIO:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3561 * set
3562 */
3563 u16 radiomask, radioval;
3564 uint validbits =
3565 WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE;
3566 mbool new = 0;
3567
3568 radiomask = (val & 0xffff0000) >> 16;
3569 radioval = val & 0x0000ffff;
3570
3571 if ((radiomask == 0) || (radiomask & ~validbits)
3572 || (radioval & ~validbits)
3573 || ((radioval & ~radiomask) != 0)) {
3574 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3575 val);
3576 bcmerror = BCME_RANGE;
3577 break;
3578 }
3579
3580 new =
3581 (wlc->pub->radio_disabled & ~radiomask) | radioval;
3582 wlc->pub->radio_disabled = new;
3583
3584 wlc_radio_hwdisable_upd(wlc);
3585 wlc_radio_upd(wlc);
3586 break;
3587 }
3588
3589 case WLC_GET_PHYTYPE:
3590 *pval = WLC_PHYTYPE(wlc->band->phytype);
3591 break;
3592
3593 #if defined(BCMDBG)
3594 case WLC_GET_KEY:
3595 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc))) {
3596 wl_wsec_key_t key;
3597
3598 wsec_key_t *src_key = wlc->wsec_keys[val];
3599
3600 if (len < (int)sizeof(key)) {
3601 bcmerror = BCME_BUFTOOSHORT;
3602 break;
3603 }
3604
3605 memset((char *)&key, 0, sizeof(key));
3606 if (src_key) {
3607 key.index = src_key->id;
3608 key.len = src_key->len;
3609 bcopy(src_key->data, key.data, key.len);
3610 key.algo = src_key->algo;
3611 if (WSEC_SOFTKEY(wlc, src_key, bsscfg))
3612 key.flags |= WL_SOFT_KEY;
3613 if (src_key->flags & WSEC_PRIMARY_KEY)
3614 key.flags |= WL_PRIMARY_KEY;
3615
3616 bcopy(src_key->ea, key.ea,
3617 ETH_ALEN);
3618 }
3619
3620 bcopy((char *)&key, arg, sizeof(key));
3621 } else
3622 bcmerror = BCME_BADKEYIDX;
3623 break;
3624 #endif /* defined(BCMDBG) */
3625
3626 case WLC_SET_KEY:
3627 bcmerror =
3628 wlc_iovar_op(wlc, "wsec_key", NULL, 0, arg, len, IOV_SET,
3629 wlcif);
3630 break;
3631
3632 case WLC_GET_KEY_SEQ:{
3633 wsec_key_t *key;
3634
3635 if (len < DOT11_WPA_KEY_RSC_LEN) {
3636 bcmerror = BCME_BUFTOOSHORT;
3637 break;
3638 }
3639
3640 /* Return the key's tx iv as an EAPOL sequence counter.
3641 * This will be used to supply the RSC value to a supplicant.
3642 * The format is 8 bytes, with least significant in seq[0].
3643 */
3644
3645 key = WSEC_KEY(wlc, val);
3646 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc)) &&
3647 (key != NULL)) {
3648 u8 seq[DOT11_WPA_KEY_RSC_LEN];
3649 u16 lo;
3650 u32 hi;
3651 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3652 if ((bsscfg->WPA_auth & WPA_AUTH_NONE) &&
3653 is_zero_ether_addr(key->ea)) {
3654 lo = bsscfg->wpa_none_txiv.lo;
3655 hi = bsscfg->wpa_none_txiv.hi;
3656 } else {
3657 lo = key->txiv.lo;
3658 hi = key->txiv.hi;
3659 }
3660
3661 /* format the buffer, low to high */
3662 seq[0] = lo & 0xff;
3663 seq[1] = (lo >> 8) & 0xff;
3664 seq[2] = hi & 0xff;
3665 seq[3] = (hi >> 8) & 0xff;
3666 seq[4] = (hi >> 16) & 0xff;
3667 seq[5] = (hi >> 24) & 0xff;
3668 seq[6] = 0;
3669 seq[7] = 0;
3670
3671 bcopy((char *)seq, arg, sizeof(seq));
3672 } else {
3673 bcmerror = BCME_BADKEYIDX;
3674 }
3675 break;
3676 }
3677
3678 case WLC_GET_CURR_RATESET:{
3679 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3680 wlc_rateset_t *rs;
3681
3682 if (bsscfg->associated)
3683 rs = &current_bss->rateset;
3684 else
3685 rs = &wlc->default_bss->rateset;
3686
3687 if (len < (int)(rs->count + sizeof(rs->count))) {
3688 bcmerror = BCME_BUFTOOSHORT;
3689 break;
3690 }
3691
3692 /* Copy only legacy rateset section */
3693 ret_rs->count = rs->count;
3694 bcopy(&rs->rates, &ret_rs->rates, rs->count);
3695 break;
3696 }
3697
3698 case WLC_GET_RATESET:{
3699 wlc_rateset_t rs;
3700 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3701
3702 memset(&rs, 0, sizeof(wlc_rateset_t));
3703 wlc_default_rateset(wlc, (wlc_rateset_t *) &rs);
3704
3705 if (len < (int)(rs.count + sizeof(rs.count))) {
3706 bcmerror = BCME_BUFTOOSHORT;
3707 break;
3708 }
3709
3710 /* Copy only legacy rateset section */
3711 ret_rs->count = rs.count;
3712 bcopy(&rs.rates, &ret_rs->rates, rs.count);
3713 break;
3714 }
3715
3716 case WLC_SET_RATESET:{
3717 wlc_rateset_t rs;
3718 wl_rateset_t *in_rs = (wl_rateset_t *) arg;
3719
3720 if (len < (int)(in_rs->count + sizeof(in_rs->count))) {
3721 bcmerror = BCME_BUFTOOSHORT;
3722 break;
3723 }
3724
3725 if (in_rs->count > WLC_NUMRATES) {
3726 bcmerror = BCME_BUFTOOLONG;
3727 break;
3728 }
3729
3730 memset(&rs, 0, sizeof(wlc_rateset_t));
3731
3732 /* Copy only legacy rateset section */
3733 rs.count = in_rs->count;
3734 bcopy(&in_rs->rates, &rs.rates, rs.count);
3735
3736 /* merge rateset coming in with the current mcsset */
3737 if (N_ENAB(wlc->pub)) {
3738 if (bsscfg->associated)
3739 bcopy(&current_bss->rateset.mcs[0],
3740 rs.mcs, MCSSET_LEN);
3741 else
3742 bcopy(&wlc->default_bss->rateset.mcs[0],
3743 rs.mcs, MCSSET_LEN);
3744 }
3745
3746 bcmerror = wlc_set_rateset(wlc, &rs);
3747
3748 if (!bcmerror)
3749 wlc_ofdm_rateset_war(wlc);
3750
3751 break;
3752 }
3753
3754 case WLC_GET_BCNPRD:
3755 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3756 *pval = current_bss->beacon_period;
3757 else
3758 *pval = wlc->default_bss->beacon_period;
3759 break;
3760
3761 case WLC_SET_BCNPRD:
3762 /* range [1, 0xffff] */
3763 if (val >= DOT11_MIN_BEACON_PERIOD
3764 && val <= DOT11_MAX_BEACON_PERIOD) {
3765 wlc->default_bss->beacon_period = (u16) val;
3766 } else
3767 bcmerror = BCME_RANGE;
3768 break;
3769
3770 case WLC_GET_DTIMPRD:
3771 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3772 *pval = current_bss->dtim_period;
3773 else
3774 *pval = wlc->default_bss->dtim_period;
3775 break;
3776
3777 case WLC_SET_DTIMPRD:
3778 /* range [1, 0xff] */
3779 if (val >= DOT11_MIN_DTIM_PERIOD
3780 && val <= DOT11_MAX_DTIM_PERIOD) {
3781 wlc->default_bss->dtim_period = (u8) val;
3782 } else
3783 bcmerror = BCME_RANGE;
3784 break;
3785
3786 #ifdef SUPPORT_PS
3787 case WLC_GET_PM:
3788 *pval = wlc->PM;
3789 break;
3790
3791 case WLC_SET_PM:
3792 if ((val >= PM_OFF) && (val <= PM_MAX)) {
3793 wlc->PM = (u8) val;
3794 if (wlc->pub->up) {
3795 }
3796 /* Change watchdog driver to align watchdog with tbtt if possible */
3797 wlc_watchdog_upd(wlc, PS_ALLOWED(wlc));
3798 } else
3799 bcmerror = BCME_ERROR;
3800 break;
3801 #endif /* SUPPORT_PS */
3802
3803 #ifdef SUPPORT_PS
3804 #ifdef BCMDBG
3805 case WLC_GET_WAKE:
3806 if (AP_ENAB(wlc->pub)) {
3807 bcmerror = BCME_NOTSTA;
3808 break;
3809 }
3810 *pval = wlc->wake;
3811 break;
3812
3813 case WLC_SET_WAKE:
3814 if (AP_ENAB(wlc->pub)) {
3815 bcmerror = BCME_NOTSTA;
3816 break;
3817 }
3818
3819 wlc->wake = val ? true : false;
3820
3821 /* if down, we're done */
3822 if (!wlc->pub->up)
3823 break;
3824
3825 /* apply to the mac */
3826 wlc_set_ps_ctrl(wlc);
3827 break;
3828 #endif /* BCMDBG */
3829 #endif /* SUPPORT_PS */
3830
3831 case WLC_GET_REVINFO:
3832 bcmerror = wlc_get_revision_info(wlc, arg, (uint) len);
3833 break;
3834
3835 case WLC_GET_AP:
3836 *pval = (int)AP_ENAB(wlc->pub);
3837 break;
3838
3839 case WLC_GET_ATIM:
3840 if (bsscfg->associated)
3841 *pval = (int)current_bss->atim_window;
3842 else
3843 *pval = (int)wlc->default_bss->atim_window;
3844 break;
3845
3846 case WLC_SET_ATIM:
3847 wlc->default_bss->atim_window = (u32) val;
3848 break;
3849
3850 case WLC_GET_PKTCNTS:{
3851 get_pktcnt_t *pktcnt = (get_pktcnt_t *) pval;
3852 if (WLC_UPDATE_STATS(wlc))
3853 wlc_statsupd(wlc);
3854 pktcnt->rx_good_pkt = WLCNTVAL(wlc->pub->_cnt->rxframe);
3855 pktcnt->rx_bad_pkt = WLCNTVAL(wlc->pub->_cnt->rxerror);
3856 pktcnt->tx_good_pkt =
3857 WLCNTVAL(wlc->pub->_cnt->txfrmsnt);
3858 pktcnt->tx_bad_pkt =
3859 WLCNTVAL(wlc->pub->_cnt->txerror) +
3860 WLCNTVAL(wlc->pub->_cnt->txfail);
3861 if (len >= (int)sizeof(get_pktcnt_t)) {
3862 /* Be backward compatible - only if buffer is large enough */
3863 pktcnt->rx_ocast_good_pkt =
3864 WLCNTVAL(wlc->pub->_cnt->rxmfrmocast);
3865 }
3866 break;
3867 }
3868
3869 #ifdef SUPPORT_HWKEY
3870 case WLC_GET_WSEC:
3871 bcmerror =
3872 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_GET,
3873 wlcif);
3874 break;
3875
3876 case WLC_SET_WSEC:
3877 bcmerror =
3878 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_SET,
3879 wlcif);
3880 break;
3881
3882 case WLC_GET_WPA_AUTH:
3883 *pval = (int)bsscfg->WPA_auth;
3884 break;
3885
3886 case WLC_SET_WPA_AUTH:
3887 /* change of WPA_Auth modifies the PS_ALLOWED state */
3888 if (BSSCFG_STA(bsscfg)) {
3889 bsscfg->WPA_auth = (u16) val;
3890 } else
3891 bsscfg->WPA_auth = (u16) val;
3892 break;
3893 #endif /* SUPPORT_HWKEY */
3894
3895 case WLC_GET_BANDLIST:
3896 /* count of number of bands, followed by each band type */
3897 *pval++ = NBANDS(wlc);
3898 *pval++ = wlc->band->bandtype;
3899 if (NBANDS(wlc) > 1)
3900 *pval++ = wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype;
3901 break;
3902
3903 case WLC_GET_BAND:
3904 *pval = wlc->bandlocked ? wlc->band->bandtype : WLC_BAND_AUTO;
3905 break;
3906
3907 case WLC_GET_PHYLIST:
3908 {
3909 unsigned char *cp = arg;
3910 if (len < 3) {
3911 bcmerror = BCME_BUFTOOSHORT;
3912 break;
3913 }
3914
3915 if (WLCISNPHY(wlc->band)) {
3916 *cp++ = 'n';
3917 } else if (WLCISLCNPHY(wlc->band)) {
3918 *cp++ = 'c';
3919 } else if (WLCISSSLPNPHY(wlc->band)) {
3920 *cp++ = 's';
3921 }
3922 *cp = '\0';
3923 break;
3924 }
3925
3926 case WLC_GET_SHORTSLOT:
3927 *pval = wlc->shortslot;
3928 break;
3929
3930 case WLC_GET_SHORTSLOT_OVERRIDE:
3931 *pval = wlc->shortslot_override;
3932 break;
3933
3934 case WLC_SET_SHORTSLOT_OVERRIDE:
3935 if ((val != WLC_SHORTSLOT_AUTO) &&
3936 (val != WLC_SHORTSLOT_OFF) && (val != WLC_SHORTSLOT_ON)) {
3937 bcmerror = BCME_RANGE;
3938 break;
3939 }
3940
3941 wlc->shortslot_override = (s8) val;
3942
3943 /* shortslot is an 11g feature, so no more work if we are
3944 * currently on the 5G band
3945 */
3946 if (BAND_5G(wlc->band->bandtype))
3947 break;
3948
3949 if (wlc->pub->up && wlc->pub->associated) {
3950 /* let watchdog or beacon processing update shortslot */
3951 } else if (wlc->pub->up) {
3952 /* unassociated shortslot is off */
3953 wlc_switch_shortslot(wlc, false);
3954 } else {
3955 /* driver is down, so just update the wlc_info value */
3956 if (wlc->shortslot_override == WLC_SHORTSLOT_AUTO) {
3957 wlc->shortslot = false;
3958 } else {
3959 wlc->shortslot =
3960 (wlc->shortslot_override ==
3961 WLC_SHORTSLOT_ON);
3962 }
3963 }
3964
3965 break;
3966
3967 case WLC_GET_LEGACY_ERP:
3968 *pval = wlc->include_legacy_erp;
3969 break;
3970
3971 case WLC_SET_LEGACY_ERP:
3972 if (wlc->include_legacy_erp == bool_val)
3973 break;
3974
3975 wlc->include_legacy_erp = bool_val;
3976
3977 if (AP_ENAB(wlc->pub) && wlc->clk) {
3978 wlc_update_beacon(wlc);
3979 wlc_update_probe_resp(wlc, true);
3980 }
3981 break;
3982
3983 case WLC_GET_GMODE:
3984 if (wlc->band->bandtype == WLC_BAND_2G)
3985 *pval = wlc->band->gmode;
3986 else if (NBANDS(wlc) > 1)
3987 *pval = wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode;
3988 break;
3989
3990 case WLC_SET_GMODE:
3991 if (!wlc->pub->associated)
3992 bcmerror = wlc_set_gmode(wlc, (u8) val, true);
3993 else {
3994 bcmerror = BCME_ASSOCIATED;
3995 break;
3996 }
3997 break;
3998
3999 case WLC_GET_GMODE_PROTECTION:
4000 *pval = wlc->protection->_g;
4001 break;
4002
4003 case WLC_GET_PROTECTION_CONTROL:
4004 *pval = wlc->protection->overlap;
4005 break;
4006
4007 case WLC_SET_PROTECTION_CONTROL:
4008 if ((val != WLC_PROTECTION_CTL_OFF) &&
4009 (val != WLC_PROTECTION_CTL_LOCAL) &&
4010 (val != WLC_PROTECTION_CTL_OVERLAP)) {
4011 bcmerror = BCME_RANGE;
4012 break;
4013 }
4014
4015 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, (s8) val);
4016
4017 /* Current g_protection will sync up to the specified control alg in watchdog
4018 * if the driver is up and associated.
4019 * If the driver is down or not associated, the control setting has no effect.
4020 */
4021 break;
4022
4023 case WLC_GET_GMODE_PROTECTION_OVERRIDE:
4024 *pval = wlc->protection->g_override;
4025 break;
4026
4027 case WLC_SET_GMODE_PROTECTION_OVERRIDE:
4028 if ((val != WLC_PROTECTION_AUTO) &&
4029 (val != WLC_PROTECTION_OFF) && (val != WLC_PROTECTION_ON)) {
4030 bcmerror = BCME_RANGE;
4031 break;
4032 }
4033
4034 wlc_protection_upd(wlc, WLC_PROT_G_OVR, (s8) val);
4035
4036 break;
4037
4038 case WLC_SET_SUP_RATESET_OVERRIDE:{
4039 wlc_rateset_t rs, new;
4040
4041 /* copyin */
4042 if (len < (int)sizeof(wlc_rateset_t)) {
4043 bcmerror = BCME_BUFTOOSHORT;
4044 break;
4045 }
4046 bcopy((char *)arg, (char *)&rs, sizeof(wlc_rateset_t));
4047
4048 /* check for bad count value */
4049 if (rs.count > WLC_NUMRATES) {
4050 bcmerror = BCME_BADRATESET; /* invalid rateset */
4051 break;
4052 }
4053
4054 /* this command is only appropriate for gmode operation */
4055 if (!(wlc->band->gmode ||
4056 ((NBANDS(wlc) > 1)
4057 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4058 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4059 break;
4060 }
4061
4062 /* check for an empty rateset to clear the override */
4063 if (rs.count == 0) {
4064 memset(&wlc->sup_rates_override, 0,
4065 sizeof(wlc_rateset_t));
4066 break;
4067 }
4068
4069 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4070 wlc_rateset_filter(&rs, &new, false, WLC_RATES_CCK_OFDM,
4071 RATE_MASK, BSS_N_ENAB(wlc, bsscfg));
4072 wlc_rate_hwrs_filter_sort_validate(&new,
4073 &cck_ofdm_rates,
4074 false,
4075 wlc->stf->txstreams);
4076 if (rs.count != new.count) {
4077 bcmerror = BCME_BADRATESET; /* invalid rateset */
4078 break;
4079 }
4080
4081 /* apply new rateset to the override */
4082 bcopy((char *)&new, (char *)&wlc->sup_rates_override,
4083 sizeof(wlc_rateset_t));
4084
4085 /* update bcn and probe resp if needed */
4086 if (wlc->pub->up && AP_ENAB(wlc->pub)
4087 && wlc->pub->associated) {
4088 wlc_update_beacon(wlc);
4089 wlc_update_probe_resp(wlc, true);
4090 }
4091 break;
4092 }
4093
4094 case WLC_GET_SUP_RATESET_OVERRIDE:
4095 /* this command is only appropriate for gmode operation */
4096 if (!(wlc->band->gmode ||
4097 ((NBANDS(wlc) > 1)
4098 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4099 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4100 break;
4101 }
4102 if (len < (int)sizeof(wlc_rateset_t)) {
4103 bcmerror = BCME_BUFTOOSHORT;
4104 break;
4105 }
4106 bcopy((char *)&wlc->sup_rates_override, (char *)arg,
4107 sizeof(wlc_rateset_t));
4108
4109 break;
4110
4111 case WLC_GET_PRB_RESP_TIMEOUT:
4112 *pval = wlc->prb_resp_timeout;
4113 break;
4114
4115 case WLC_SET_PRB_RESP_TIMEOUT:
4116 if (wlc->pub->up) {
4117 bcmerror = BCME_NOTDOWN;
4118 break;
4119 }
4120 if (val < 0 || val >= 0xFFFF) {
4121 bcmerror = BCME_RANGE; /* bad value */
4122 break;
4123 }
4124 wlc->prb_resp_timeout = (u16) val;
4125 break;
4126
4127 case WLC_GET_KEY_PRIMARY:{
4128 wsec_key_t *key;
4129
4130 /* treat the 'val' parm as the key id */
4131 key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4132 if (key != NULL) {
4133 *pval = key->id == val ? true : false;
4134 } else {
4135 bcmerror = BCME_BADKEYIDX;
4136 }
4137 break;
4138 }
4139
4140 case WLC_SET_KEY_PRIMARY:{
4141 wsec_key_t *key, *old_key;
4142
4143 bcmerror = BCME_BADKEYIDX;
4144
4145 /* treat the 'val' parm as the key id */
4146 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
4147 key = bsscfg->bss_def_keys[i];
4148 if (key != NULL && key->id == val) {
4149 old_key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4150 if (old_key != NULL)
4151 old_key->flags &=
4152 ~WSEC_PRIMARY_KEY;
4153 key->flags |= WSEC_PRIMARY_KEY;
4154 bsscfg->wsec_index = i;
4155 bcmerror = BCME_OK;
4156 }
4157 }
4158 break;
4159 }
4160
4161 #ifdef BCMDBG
4162 case WLC_INIT:
4163 wl_init(wlc->wl);
4164 break;
4165 #endif
4166
4167 case WLC_SET_VAR:
4168 case WLC_GET_VAR:{
4169 char *name;
4170 /* validate the name value */
4171 name = (char *)arg;
4172 for (i = 0; i < (uint) len && *name != '\0';
4173 i++, name++)
4174 ;
4175
4176 if (i == (uint) len) {
4177 bcmerror = BCME_BUFTOOSHORT;
4178 break;
4179 }
4180 i++; /* include the null in the string length */
4181
4182 if (cmd == WLC_GET_VAR) {
4183 bcmerror =
4184 wlc_iovar_op(wlc, arg,
4185 (void *)((s8 *) arg + i),
4186 len - i, arg, len, IOV_GET,
4187 wlcif);
4188 } else
4189 bcmerror =
4190 wlc_iovar_op(wlc, arg, NULL, 0,
4191 (void *)((s8 *) arg + i),
4192 len - i, IOV_SET, wlcif);
4193
4194 break;
4195 }
4196
4197 case WLC_SET_WSEC_PMK:
4198 bcmerror = BCME_UNSUPPORTED;
4199 break;
4200
4201 #if defined(BCMDBG)
4202 case WLC_CURRENT_PWR:
4203 if (!wlc->pub->up)
4204 bcmerror = BCME_NOTUP;
4205 else
4206 bcmerror = wlc_get_current_txpwr(wlc, arg, len);
4207 break;
4208 #endif
4209
4210 case WLC_LAST:
4211 WL_ERROR("%s: WLC_LAST\n", __func__);
4212 }
4213 done:
4214
4215 if (bcmerror) {
4216 if (VALID_BCMERROR(bcmerror))
4217 wlc->pub->bcmerror = bcmerror;
4218 else {
4219 bcmerror = 0;
4220 }
4221
4222 }
4223 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4224 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4225 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4226 */
4227 if (!(wlc->pub->hw_off))
4228 ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok);
4229
4230 return bcmerror;
4231 }
4232
4233 #if defined(BCMDBG)
4234 /* consolidated register access ioctl error checking */
4235 int wlc_iocregchk(struct wlc_info *wlc, uint band)
4236 {
4237 /* if band is specified, it must be the current band */
4238 if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype))
4239 return BCME_BADBAND;
4240
4241 /* if multiband and band is not specified, band must be locked */
4242 if ((band == WLC_BAND_AUTO) && IS_MBAND_UNLOCKED(wlc))
4243 return BCME_NOTBANDLOCKED;
4244
4245 /* must have core clocks */
4246 if (!wlc->clk)
4247 return BCME_NOCLK;
4248
4249 return 0;
4250 }
4251 #endif /* defined(BCMDBG) */
4252
4253 #if defined(BCMDBG)
4254 /* For some ioctls, make sure that the pi pointer matches the current phy */
4255 int wlc_iocpichk(struct wlc_info *wlc, uint phytype)
4256 {
4257 if (wlc->band->phytype != phytype)
4258 return BCME_BADBAND;
4259 return 0;
4260 }
4261 #endif
4262
4263 /* Look up the given var name in the given table */
4264 static const bcm_iovar_t *wlc_iovar_lookup(const bcm_iovar_t *table,
4265 const char *name)
4266 {
4267 const bcm_iovar_t *vi;
4268 const char *lookup_name;
4269
4270 /* skip any ':' delimited option prefixes */
4271 lookup_name = strrchr(name, ':');
4272 if (lookup_name != NULL)
4273 lookup_name++;
4274 else
4275 lookup_name = name;
4276
4277 ASSERT(table != NULL);
4278
4279 for (vi = table; vi->name; vi++) {
4280 if (!strcmp(vi->name, lookup_name))
4281 return vi;
4282 }
4283 /* ran to end of table */
4284
4285 return NULL; /* var name not found */
4286 }
4287
4288 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4289 int wlc_iovar_getint(struct wlc_info *wlc, const char *name, int *arg)
4290 {
4291 return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(s32), IOV_GET,
4292 NULL);
4293 }
4294
4295 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4296 int wlc_iovar_setint(struct wlc_info *wlc, const char *name, int arg)
4297 {
4298 return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg),
4299 IOV_SET, NULL);
4300 }
4301
4302 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4303 int wlc_iovar_gets8(struct wlc_info *wlc, const char *name, s8 *arg)
4304 {
4305 int iovar_int;
4306 int err;
4307
4308 err =
4309 wlc_iovar_op(wlc, name, NULL, 0, &iovar_int, sizeof(iovar_int),
4310 IOV_GET, NULL);
4311 if (!err)
4312 *arg = (s8) iovar_int;
4313
4314 return err;
4315 }
4316
4317 /*
4318 * register iovar table, watchdog and down handlers.
4319 * calling function must keep 'iovars' until wlc_module_unregister is called.
4320 * 'iovar' must have the last entry's name field being NULL as terminator.
4321 */
4322 int wlc_module_register(struct wlc_pub *pub, const bcm_iovar_t *iovars,
4323 const char *name, void *hdl, iovar_fn_t i_fn,
4324 watchdog_fn_t w_fn, down_fn_t d_fn)
4325 {
4326 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4327 int i;
4328
4329 ASSERT(name != NULL);
4330 ASSERT(i_fn != NULL || w_fn != NULL || d_fn != NULL);
4331
4332 /* find an empty entry and just add, no duplication check! */
4333 for (i = 0; i < WLC_MAXMODULES; i++) {
4334 if (wlc->modulecb[i].name[0] == '\0') {
4335 strncpy(wlc->modulecb[i].name, name,
4336 sizeof(wlc->modulecb[i].name) - 1);
4337 wlc->modulecb[i].iovars = iovars;
4338 wlc->modulecb[i].hdl = hdl;
4339 wlc->modulecb[i].iovar_fn = i_fn;
4340 wlc->modulecb[i].watchdog_fn = w_fn;
4341 wlc->modulecb[i].down_fn = d_fn;
4342 return 0;
4343 }
4344 }
4345
4346 /* it is time to increase the capacity */
4347 ASSERT(i < WLC_MAXMODULES);
4348 return BCME_NORESOURCE;
4349 }
4350
4351 /* unregister module callbacks */
4352 int wlc_module_unregister(struct wlc_pub *pub, const char *name, void *hdl)
4353 {
4354 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4355 int i;
4356
4357 if (wlc == NULL)
4358 return BCME_NOTFOUND;
4359
4360 ASSERT(name != NULL);
4361
4362 for (i = 0; i < WLC_MAXMODULES; i++) {
4363 if (!strcmp(wlc->modulecb[i].name, name) &&
4364 (wlc->modulecb[i].hdl == hdl)) {
4365 memset(&wlc->modulecb[i], 0, sizeof(modulecb_t));
4366 return 0;
4367 }
4368 }
4369
4370 /* table not found! */
4371 return BCME_NOTFOUND;
4372 }
4373
4374 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4375 static void wlc_wme_retries_write(struct wlc_info *wlc)
4376 {
4377 int ac;
4378
4379 /* Need clock to do this */
4380 if (!wlc->clk)
4381 return;
4382
4383 for (ac = 0; ac < AC_COUNT; ac++) {
4384 wlc_write_shm(wlc, M_AC_TXLMT_ADDR(ac), wlc->wme_retries[ac]);
4385 }
4386 }
4387
4388 /* Get or set an iovar. The params/p_len pair specifies any additional
4389 * qualifying parameters (e.g. an "element index") for a get, while the
4390 * arg/len pair is the buffer for the value to be set or retrieved.
4391 * Operation (get/set) is specified by the last argument.
4392 * interface context provided by wlcif
4393 *
4394 * All pointers may point into the same buffer.
4395 */
4396 int
4397 wlc_iovar_op(struct wlc_info *wlc, const char *name,
4398 void *params, int p_len, void *arg, int len,
4399 bool set, struct wlc_if *wlcif)
4400 {
4401 int err = 0;
4402 int val_size;
4403 const bcm_iovar_t *vi = NULL;
4404 u32 actionid;
4405 int i;
4406
4407 ASSERT(name != NULL);
4408
4409 ASSERT(len >= 0);
4410
4411 /* Get MUST have return space */
4412 ASSERT(set || (arg && len));
4413
4414 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
4415
4416 /* Set does NOT take qualifiers */
4417 ASSERT(!set || (!params && !p_len));
4418
4419 if (!set && (len == sizeof(int)) &&
4420 !(IS_ALIGNED((unsigned long)(arg), (uint) sizeof(int)))) {
4421 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4422 wlc->pub->unit, __func__, name);
4423 ASSERT(0);
4424 }
4425
4426 /* find the given iovar name */
4427 for (i = 0; i < WLC_MAXMODULES; i++) {
4428 if (!wlc->modulecb[i].iovars)
4429 continue;
4430 vi = wlc_iovar_lookup(wlc->modulecb[i].iovars, name);
4431 if (vi)
4432 break;
4433 }
4434 /* iovar name not found */
4435 if (i >= WLC_MAXMODULES) {
4436 err = BCME_UNSUPPORTED;
4437 goto exit;
4438 }
4439
4440 /* set up 'params' pointer in case this is a set command so that
4441 * the convenience int and bool code can be common to set and get
4442 */
4443 if (params == NULL) {
4444 params = arg;
4445 p_len = len;
4446 }
4447
4448 if (vi->type == IOVT_VOID)
4449 val_size = 0;
4450 else if (vi->type == IOVT_BUFFER)
4451 val_size = len;
4452 else
4453 /* all other types are integer sized */
4454 val_size = sizeof(int);
4455
4456 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
4457
4458 /* Do the actual parameter implementation */
4459 err = wlc->modulecb[i].iovar_fn(wlc->modulecb[i].hdl, vi, actionid,
4460 name, params, p_len, arg, len, val_size,
4461 wlcif);
4462
4463 exit:
4464 return err;
4465 }
4466
4467 int
4468 wlc_iovar_check(struct wlc_pub *pub, const bcm_iovar_t *vi, void *arg, int len,
4469 bool set)
4470 {
4471 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4472 int err = 0;
4473 s32 int_val = 0;
4474
4475 /* check generic condition flags */
4476 if (set) {
4477 if (((vi->flags & IOVF_SET_DOWN) && wlc->pub->up) ||
4478 ((vi->flags & IOVF_SET_UP) && !wlc->pub->up)) {
4479 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4480 } else if ((vi->flags & IOVF_SET_BAND)
4481 && IS_MBAND_UNLOCKED(wlc)) {
4482 err = BCME_NOTBANDLOCKED;
4483 } else if ((vi->flags & IOVF_SET_CLK) && !wlc->clk) {
4484 err = BCME_NOCLK;
4485 }
4486 } else {
4487 if (((vi->flags & IOVF_GET_DOWN) && wlc->pub->up) ||
4488 ((vi->flags & IOVF_GET_UP) && !wlc->pub->up)) {
4489 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4490 } else if ((vi->flags & IOVF_GET_BAND)
4491 && IS_MBAND_UNLOCKED(wlc)) {
4492 err = BCME_NOTBANDLOCKED;
4493 } else if ((vi->flags & IOVF_GET_CLK) && !wlc->clk) {
4494 err = BCME_NOCLK;
4495 }
4496 }
4497
4498 if (err)
4499 goto exit;
4500
4501 /* length check on io buf */
4502 err = bcm_iovar_lencheck(vi, arg, len, set);
4503 if (err)
4504 goto exit;
4505
4506 /* On set, check value ranges for integer types */
4507 if (set) {
4508 switch (vi->type) {
4509 case IOVT_BOOL:
4510 case IOVT_INT8:
4511 case IOVT_INT16:
4512 case IOVT_INT32:
4513 case IOVT_UINT8:
4514 case IOVT_UINT16:
4515 case IOVT_UINT32:
4516 bcopy(arg, &int_val, sizeof(int));
4517 err = wlc_iovar_rangecheck(wlc, int_val, vi);
4518 break;
4519 }
4520 }
4521 exit:
4522 return err;
4523 }
4524
4525 /* handler for iovar table wlc_iovars */
4526 /*
4527 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4528 * iovar case, the switch statement maps the iovar id into separate get
4529 * and set values. If you add a new iovar to the switch you MUST use
4530 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4531 * another case.
4532 * Please use params for additional qualifying parameters.
4533 */
4534 int
4535 wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4536 const char *name, void *params, uint p_len, void *arg, int len,
4537 int val_size, struct wlc_if *wlcif)
4538 {
4539 struct wlc_info *wlc = hdl;
4540 wlc_bsscfg_t *bsscfg;
4541 int err = 0;
4542 s32 int_val = 0;
4543 s32 int_val2 = 0;
4544 s32 *ret_int_ptr;
4545 bool bool_val;
4546 bool bool_val2;
4547 wlc_bss_info_t *current_bss;
4548
4549 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
4550
4551 bsscfg = NULL;
4552 current_bss = NULL;
4553
4554 err = wlc_iovar_check(wlc->pub, vi, arg, len, IOV_ISSET(actionid));
4555 if (err != 0)
4556 return err;
4557
4558 /* convenience int and bool vals for first 8 bytes of buffer */
4559 if (p_len >= (int)sizeof(int_val))
4560 bcopy(params, &int_val, sizeof(int_val));
4561
4562 if (p_len >= (int)sizeof(int_val) * 2)
4563 bcopy((void *)((unsigned long)params + sizeof(int_val)), &int_val2,
4564 sizeof(int_val));
4565
4566 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4567 ret_int_ptr = (s32 *) arg;
4568
4569 bool_val = (int_val != 0) ? true : false;
4570 bool_val2 = (int_val2 != 0) ? true : false;
4571
4572 WL_TRACE("wl%d: %s: id %d\n",
4573 wlc->pub->unit, __func__, IOV_ID(actionid));
4574 /* Do the actual parameter implementation */
4575 switch (actionid) {
4576
4577 case IOV_GVAL(IOV_QTXPOWER):{
4578 uint qdbm;
4579 bool override;
4580
4581 err = wlc_phy_txpower_get(wlc->band->pi, &qdbm,
4582 &override);
4583 if (err != BCME_OK)
4584 return err;
4585
4586 /* Return qdbm units */
4587 *ret_int_ptr =
4588 qdbm | (override ? WL_TXPWR_OVERRIDE : 0);
4589 break;
4590 }
4591
4592 /* As long as override is false, this only sets the *user* targets.
4593 User can twiddle this all he wants with no harm.
4594 wlc_phy_txpower_set() explicitly sets override to false if
4595 not internal or test.
4596 */
4597 case IOV_SVAL(IOV_QTXPOWER):{
4598 u8 qdbm;
4599 bool override;
4600
4601 /* Remove override bit and clip to max qdbm value */
4602 qdbm = (u8)min_t(u32, (int_val & ~WL_TXPWR_OVERRIDE), 0xff);
4603 /* Extract override setting */
4604 override = (int_val & WL_TXPWR_OVERRIDE) ? true : false;
4605 err =
4606 wlc_phy_txpower_set(wlc->band->pi, qdbm, override);
4607 break;
4608 }
4609
4610 case IOV_GVAL(IOV_MPC):
4611 *ret_int_ptr = (s32) wlc->mpc;
4612 break;
4613
4614 case IOV_SVAL(IOV_MPC):
4615 wlc->mpc = bool_val;
4616 wlc_radio_mpc_upd(wlc);
4617
4618 break;
4619
4620 case IOV_GVAL(IOV_BCN_LI_BCN):
4621 *ret_int_ptr = wlc->bcn_li_bcn;
4622 break;
4623
4624 case IOV_SVAL(IOV_BCN_LI_BCN):
4625 wlc->bcn_li_bcn = (u8) int_val;
4626 if (wlc->pub->up)
4627 wlc_bcn_li_upd(wlc);
4628 break;
4629
4630 default:
4631 WL_ERROR("wl%d: %s: unsupported\n", wlc->pub->unit, __func__);
4632 err = BCME_UNSUPPORTED;
4633 break;
4634 }
4635
4636 goto exit; /* avoid unused label warning */
4637
4638 exit:
4639 return err;
4640 }
4641
4642 static int
4643 wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val, const bcm_iovar_t *vi)
4644 {
4645 int err = 0;
4646 u32 min_val = 0;
4647 u32 max_val = 0;
4648
4649 /* Only ranged integers are checked */
4650 switch (vi->type) {
4651 case IOVT_INT32:
4652 max_val |= 0x7fffffff;
4653 /* fall through */
4654 case IOVT_INT16:
4655 max_val |= 0x00007fff;
4656 /* fall through */
4657 case IOVT_INT8:
4658 max_val |= 0x0000007f;
4659 min_val = ~max_val;
4660 if (vi->flags & IOVF_NTRL)
4661 min_val = 1;
4662 else if (vi->flags & IOVF_WHL)
4663 min_val = 0;
4664 /* Signed values are checked against max_val and min_val */
4665 if ((s32) val < (s32) min_val
4666 || (s32) val > (s32) max_val)
4667 err = BCME_RANGE;
4668 break;
4669
4670 case IOVT_UINT32:
4671 max_val |= 0xffffffff;
4672 /* fall through */
4673 case IOVT_UINT16:
4674 max_val |= 0x0000ffff;
4675 /* fall through */
4676 case IOVT_UINT8:
4677 max_val |= 0x000000ff;
4678 if (vi->flags & IOVF_NTRL)
4679 min_val = 1;
4680 if ((val < min_val) || (val > max_val))
4681 err = BCME_RANGE;
4682 break;
4683 }
4684
4685 return err;
4686 }
4687
4688 #ifdef BCMDBG
4689 static const char *supr_reason[] = {
4690 "None", "PMQ Entry", "Flush request",
4691 "Previous frag failure", "Channel mismatch",
4692 "Lifetime Expiry", "Underflow"
4693 };
4694
4695 static void wlc_print_txs_status(u16 s)
4696 {
4697 printf("[15:12] %d frame attempts\n", (s & TX_STATUS_FRM_RTX_MASK) >>
4698 TX_STATUS_FRM_RTX_SHIFT);
4699 printf(" [11:8] %d rts attempts\n", (s & TX_STATUS_RTS_RTX_MASK) >>
4700 TX_STATUS_RTS_RTX_SHIFT);
4701 printf(" [7] %d PM mode indicated\n",
4702 ((s & TX_STATUS_PMINDCTD) ? 1 : 0));
4703 printf(" [6] %d intermediate status\n",
4704 ((s & TX_STATUS_INTERMEDIATE) ? 1 : 0));
4705 printf(" [5] %d AMPDU\n", (s & TX_STATUS_AMPDU) ? 1 : 0);
4706 printf(" [4:2] %d Frame Suppressed Reason (%s)\n",
4707 ((s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT),
4708 supr_reason[(s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT]);
4709 printf(" [1] %d acked\n", ((s & TX_STATUS_ACK_RCV) ? 1 : 0));
4710 }
4711 #endif /* BCMDBG */
4712
4713 void wlc_print_txstatus(tx_status_t *txs)
4714 {
4715 #if defined(BCMDBG)
4716 u16 s = txs->status;
4717 u16 ackphyrxsh = txs->ackphyrxsh;
4718
4719 printf("\ntxpkt (MPDU) Complete\n");
4720
4721 printf("FrameID: %04x ", txs->frameid);
4722 printf("TxStatus: %04x", s);
4723 printf("\n");
4724 #ifdef BCMDBG
4725 wlc_print_txs_status(s);
4726 #endif
4727 printf("LastTxTime: %04x ", txs->lasttxtime);
4728 printf("Seq: %04x ", txs->sequence);
4729 printf("PHYTxStatus: %04x ", txs->phyerr);
4730 printf("RxAckRSSI: %04x ",
4731 (ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT);
4732 printf("RxAckSQ: %04x", (ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT);
4733 printf("\n");
4734 #endif /* defined(BCMDBG) */
4735 }
4736
4737 #define MACSTATUPD(name) \
4738 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4739
4740 void wlc_statsupd(struct wlc_info *wlc)
4741 {
4742 int i;
4743 #ifdef BCMDBG
4744 u16 delta;
4745 u16 rxf0ovfl;
4746 u16 txfunfl[NFIFO];
4747 #endif /* BCMDBG */
4748
4749 /* if driver down, make no sense to update stats */
4750 if (!wlc->pub->up)
4751 return;
4752
4753 #ifdef BCMDBG
4754 /* save last rx fifo 0 overflow count */
4755 rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl;
4756
4757 /* save last tx fifo underflow count */
4758 for (i = 0; i < NFIFO; i++)
4759 txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i];
4760 #endif /* BCMDBG */
4761
4762 #ifdef BCMDBG
4763 /* check for rx fifo 0 overflow */
4764 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl);
4765 if (delta)
4766 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4767 wlc->pub->unit, delta);
4768
4769 /* check for tx fifo underflows */
4770 for (i = 0; i < NFIFO; i++) {
4771 delta =
4772 (u16) (wlc->core->macstat_snapshot->txfunfl[i] -
4773 txfunfl[i]);
4774 if (delta)
4775 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4776 wlc->pub->unit, delta, i);
4777 }
4778 #endif /* BCMDBG */
4779
4780 /* dot11 counter update */
4781
4782 WLCNTSET(wlc->pub->_cnt->txrts,
4783 (wlc->pub->_cnt->rxctsucast -
4784 wlc->pub->_cnt->d11cnt_txrts_off));
4785 WLCNTSET(wlc->pub->_cnt->rxcrc,
4786 (wlc->pub->_cnt->rxbadfcs - wlc->pub->_cnt->d11cnt_rxcrc_off));
4787 WLCNTSET(wlc->pub->_cnt->txnocts,
4788 ((wlc->pub->_cnt->txrtsfrm - wlc->pub->_cnt->rxctsucast) -
4789 wlc->pub->_cnt->d11cnt_txnocts_off));
4790
4791 /* merge counters from dma module */
4792 for (i = 0; i < NFIFO; i++) {
4793 if (wlc->hw->di[i]) {
4794 WLCNTADD(wlc->pub->_cnt->txnobuf,
4795 (wlc->hw->di[i])->txnobuf);
4796 WLCNTADD(wlc->pub->_cnt->rxnobuf,
4797 (wlc->hw->di[i])->rxnobuf);
4798 WLCNTADD(wlc->pub->_cnt->rxgiant,
4799 (wlc->hw->di[i])->rxgiants);
4800 dma_counterreset(wlc->hw->di[i]);
4801 }
4802 }
4803
4804 /*
4805 * Aggregate transmit and receive errors that probably resulted
4806 * in the loss of a frame are computed on the fly.
4807 */
4808 WLCNTSET(wlc->pub->_cnt->txerror,
4809 wlc->pub->_cnt->txnobuf + wlc->pub->_cnt->txnoassoc +
4810 wlc->pub->_cnt->txuflo + wlc->pub->_cnt->txrunt +
4811 wlc->pub->_cnt->dmade + wlc->pub->_cnt->dmada +
4812 wlc->pub->_cnt->dmape);
4813 WLCNTSET(wlc->pub->_cnt->rxerror,
4814 wlc->pub->_cnt->rxoflo + wlc->pub->_cnt->rxnobuf +
4815 wlc->pub->_cnt->rxfragerr + wlc->pub->_cnt->rxrunt +
4816 wlc->pub->_cnt->rxgiant + wlc->pub->_cnt->rxnoscb +
4817 wlc->pub->_cnt->rxbadsrcmac);
4818 for (i = 0; i < NFIFO; i++)
4819 WLCNTADD(wlc->pub->_cnt->rxerror, wlc->pub->_cnt->rxuflo[i]);
4820 }
4821
4822 bool wlc_chipmatch(u16 vendor, u16 device)
4823 {
4824 if (vendor != VENDOR_BROADCOM) {
4825 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor);
4826 return false;
4827 }
4828
4829 if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID))
4830 return true;
4831
4832 if (device == BCM4313_D11N2G_ID)
4833 return true;
4834 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID))
4835 return true;
4836
4837 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device);
4838 return false;
4839 }
4840
4841 #if defined(BCMDBG)
4842 void wlc_print_txdesc(d11txh_t *txh)
4843 {
4844 u16 mtcl = ltoh16(txh->MacTxControlLow);
4845 u16 mtch = ltoh16(txh->MacTxControlHigh);
4846 u16 mfc = ltoh16(txh->MacFrameControl);
4847 u16 tfest = ltoh16(txh->TxFesTimeNormal);
4848 u16 ptcw = ltoh16(txh->PhyTxControlWord);
4849 u16 ptcw_1 = ltoh16(txh->PhyTxControlWord_1);
4850 u16 ptcw_1_Fbr = ltoh16(txh->PhyTxControlWord_1_Fbr);
4851 u16 ptcw_1_Rts = ltoh16(txh->PhyTxControlWord_1_Rts);
4852 u16 ptcw_1_FbrRts = ltoh16(txh->PhyTxControlWord_1_FbrRts);
4853 u16 mainrates = ltoh16(txh->MainRates);
4854 u16 xtraft = ltoh16(txh->XtraFrameTypes);
4855 u8 *iv = txh->IV;
4856 u8 *ra = txh->TxFrameRA;
4857 u16 tfestfb = ltoh16(txh->TxFesTimeFallback);
4858 u8 *rtspfb = txh->RTSPLCPFallback;
4859 u16 rtsdfb = ltoh16(txh->RTSDurFallback);
4860 u8 *fragpfb = txh->FragPLCPFallback;
4861 u16 fragdfb = ltoh16(txh->FragDurFallback);
4862 u16 mmodelen = ltoh16(txh->MModeLen);
4863 u16 mmodefbrlen = ltoh16(txh->MModeFbrLen);
4864 u16 tfid = ltoh16(txh->TxFrameID);
4865 u16 txs = ltoh16(txh->TxStatus);
4866 u16 mnmpdu = ltoh16(txh->MaxNMpdus);
4867 u16 mabyte = ltoh16(txh->MaxABytes_MRT);
4868 u16 mabyte_f = ltoh16(txh->MaxABytes_FBR);
4869 u16 mmbyte = ltoh16(txh->MinMBytes);
4870
4871 u8 *rtsph = txh->RTSPhyHeader;
4872 struct ieee80211_rts rts = txh->rts_frame;
4873 char hexbuf[256];
4874
4875 /* add plcp header along with txh descriptor */
4876 prhex("Raw TxDesc + plcp header", (unsigned char *) txh, sizeof(d11txh_t) + 48);
4877
4878 printf("TxCtlLow: %04x ", mtcl);
4879 printf("TxCtlHigh: %04x ", mtch);
4880 printf("FC: %04x ", mfc);
4881 printf("FES Time: %04x\n", tfest);
4882 printf("PhyCtl: %04x%s ", ptcw,
4883 (ptcw & PHY_TXC_SHORT_HDR) ? " short" : "");
4884 printf("PhyCtl_1: %04x ", ptcw_1);
4885 printf("PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr);
4886 printf("PhyCtl_1_Rts: %04x ", ptcw_1_Rts);
4887 printf("PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts);
4888 printf("MainRates: %04x ", mainrates);
4889 printf("XtraFrameTypes: %04x ", xtraft);
4890 printf("\n");
4891
4892 bcm_format_hex(hexbuf, iv, sizeof(txh->IV));
4893 printf("SecIV: %s\n", hexbuf);
4894 bcm_format_hex(hexbuf, ra, sizeof(txh->TxFrameRA));
4895 printf("RA: %s\n", hexbuf);
4896
4897 printf("Fb FES Time: %04x ", tfestfb);
4898 bcm_format_hex(hexbuf, rtspfb, sizeof(txh->RTSPLCPFallback));
4899 printf("RTS PLCP: %s ", hexbuf);
4900 printf("RTS DUR: %04x ", rtsdfb);
4901 bcm_format_hex(hexbuf, fragpfb, sizeof(txh->FragPLCPFallback));
4902 printf("PLCP: %s ", hexbuf);
4903 printf("DUR: %04x", fragdfb);
4904 printf("\n");
4905
4906 printf("MModeLen: %04x ", mmodelen);
4907 printf("MModeFbrLen: %04x\n", mmodefbrlen);
4908
4909 printf("FrameID: %04x\n", tfid);
4910 printf("TxStatus: %04x\n", txs);
4911
4912 printf("MaxNumMpdu: %04x\n", mnmpdu);
4913 printf("MaxAggbyte: %04x\n", mabyte);
4914 printf("MaxAggbyte_fb: %04x\n", mabyte_f);
4915 printf("MinByte: %04x\n", mmbyte);
4916
4917 bcm_format_hex(hexbuf, rtsph, sizeof(txh->RTSPhyHeader));
4918 printf("RTS PLCP: %s ", hexbuf);
4919 bcm_format_hex(hexbuf, (u8 *) &rts, sizeof(txh->rts_frame));
4920 printf("RTS Frame: %s", hexbuf);
4921 printf("\n");
4922
4923 }
4924 #endif /* defined(BCMDBG) */
4925
4926 #if defined(BCMDBG)
4927 void wlc_print_rxh(d11rxhdr_t *rxh)
4928 {
4929 u16 len = rxh->RxFrameSize;
4930 u16 phystatus_0 = rxh->PhyRxStatus_0;
4931 u16 phystatus_1 = rxh->PhyRxStatus_1;
4932 u16 phystatus_2 = rxh->PhyRxStatus_2;
4933 u16 phystatus_3 = rxh->PhyRxStatus_3;
4934 u16 macstatus1 = rxh->RxStatus1;
4935 u16 macstatus2 = rxh->RxStatus2;
4936 char flagstr[64];
4937 char lenbuf[20];
4938 static const bcm_bit_desc_t macstat_flags[] = {
4939 {RXS_FCSERR, "FCSErr"},
4940 {RXS_RESPFRAMETX, "Reply"},
4941 {RXS_PBPRES, "PADDING"},
4942 {RXS_DECATMPT, "DeCr"},
4943 {RXS_DECERR, "DeCrErr"},
4944 {RXS_BCNSENT, "Bcn"},
4945 {0, NULL}
4946 };
4947
4948 prhex("Raw RxDesc", (unsigned char *) rxh, sizeof(d11rxhdr_t));
4949
4950 bcm_format_flags(macstat_flags, macstatus1, flagstr, 64);
4951
4952 snprintf(lenbuf, sizeof(lenbuf), "0x%x", len);
4953
4954 printf("RxFrameSize: %6s (%d)%s\n", lenbuf, len,
4955 (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : "");
4956 printf("RxPHYStatus: %04x %04x %04x %04x\n",
4957 phystatus_0, phystatus_1, phystatus_2, phystatus_3);
4958 printf("RxMACStatus: %x %s\n", macstatus1, flagstr);
4959 printf("RXMACaggtype: %x\n", (macstatus2 & RXS_AGGTYPE_MASK));
4960 printf("RxTSFTime: %04x\n", rxh->RxTSFTime);
4961 }
4962 #endif /* defined(BCMDBG) */
4963
4964 #if defined(BCMDBG)
4965 int wlc_format_ssid(char *buf, const unsigned char ssid[], uint ssid_len)
4966 {
4967 uint i, c;
4968 char *p = buf;
4969 char *endp = buf + SSID_FMT_BUF_LEN;
4970
4971 if (ssid_len > IEEE80211_MAX_SSID_LEN)
4972 ssid_len = IEEE80211_MAX_SSID_LEN;
4973
4974 for (i = 0; i < ssid_len; i++) {
4975 c = (uint) ssid[i];
4976 if (c == '\\') {
4977 *p++ = '\\';
4978 *p++ = '\\';
4979 } else if (isprint((unsigned char) c)) {
4980 *p++ = (char)c;
4981 } else {
4982 p += snprintf(p, (endp - p), "\\x%02X", c);
4983 }
4984 }
4985 *p = '\0';
4986 ASSERT(p < endp);
4987
4988 return (int)(p - buf);
4989 }
4990 #endif /* defined(BCMDBG) */
4991
4992 u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate)
4993 {
4994 return wlc_bmac_rate_shm_offset(wlc->hw, rate);
4995 }
4996
4997 /* Callback for device removed */
4998
4999 /*
5000 * Attempts to queue a packet onto a multiple-precedence queue,
5001 * if necessary evicting a lower precedence packet from the queue.
5002 *
5003 * 'prec' is the precedence number that has already been mapped
5004 * from the packet priority.
5005 *
5006 * Returns true if packet consumed (queued), false if not.
5007 */
5008 bool BCMFASTPATH
5009 wlc_prec_enq(struct wlc_info *wlc, struct pktq *q, void *pkt, int prec)
5010 {
5011 return wlc_prec_enq_head(wlc, q, pkt, prec, false);
5012 }
5013
5014 bool BCMFASTPATH
5015 wlc_prec_enq_head(struct wlc_info *wlc, struct pktq *q, struct sk_buff *pkt,
5016 int prec, bool head)
5017 {
5018 struct sk_buff *p;
5019 int eprec = -1; /* precedence to evict from */
5020
5021 /* Determine precedence from which to evict packet, if any */
5022 if (pktq_pfull(q, prec))
5023 eprec = prec;
5024 else if (pktq_full(q)) {
5025 p = pktq_peek_tail(q, &eprec);
5026 ASSERT(p != NULL);
5027 if (eprec > prec) {
5028 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5029 __func__, eprec, prec);
5030 return false;
5031 }
5032 }
5033
5034 /* Evict if needed */
5035 if (eprec >= 0) {
5036 bool discard_oldest;
5037
5038 /* Detect queueing to unconfigured precedence */
5039 ASSERT(!pktq_pempty(q, eprec));
5040
5041 discard_oldest = AC_BITMAP_TST(wlc->wme_dp, eprec);
5042
5043 /* Refuse newer packet unless configured to discard oldest */
5044 if (eprec == prec && !discard_oldest) {
5045 WL_ERROR("%s: No where to go, prec == %d\n",
5046 __func__, prec);
5047 return false;
5048 }
5049
5050 /* Evict packet according to discard policy */
5051 p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q,
5052 eprec);
5053 ASSERT(p != NULL);
5054
5055 /* Increment wme stats */
5056 if (WME_ENAB(wlc->pub)) {
5057 WLCNTINCR(wlc->pub->_wme_cnt->
5058 tx_failed[WME_PRIO2AC(p->priority)].packets);
5059 WLCNTADD(wlc->pub->_wme_cnt->
5060 tx_failed[WME_PRIO2AC(p->priority)].bytes,
5061 pkttotlen(wlc->osh, p));
5062 }
5063
5064 ASSERT(0);
5065 pkt_buf_free_skb(wlc->osh, p, true);
5066 WLCNTINCR(wlc->pub->_cnt->txnobuf);
5067 }
5068
5069 /* Enqueue */
5070 if (head)
5071 p = pktq_penq_head(q, prec, pkt);
5072 else
5073 p = pktq_penq(q, prec, pkt);
5074 ASSERT(p != NULL);
5075
5076 return true;
5077 }
5078
5079 void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu,
5080 uint prec)
5081 {
5082 struct wlc_info *wlc = (struct wlc_info *) ctx;
5083 wlc_txq_info_t *qi = wlc->active_queue; /* Check me */
5084 struct pktq *q = &qi->q;
5085 int prio;
5086
5087 prio = sdu->priority;
5088
5089 ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat);
5090
5091 if (!wlc_prec_enq(wlc, q, sdu, prec)) {
5092 if (!EDCF_ENAB(wlc->pub)
5093 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL))
5094 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5095 wlc->pub->unit);
5096
5097 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5098 pkt_buf_free_skb(wlc->osh, sdu, true);
5099 WLCNTINCR(wlc->pub->_cnt->txnobuf);
5100 }
5101
5102 /* Check if flow control needs to be turned on after enqueuing the packet
5103 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5104 * to drop instead of relying on stack to make the right decision
5105 */
5106 if (!EDCF_ENAB(wlc->pub)
5107 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5108 if (pktq_len(q) >= wlc->pub->tunables->datahiwat) {
5109 wlc_txflowcontrol(wlc, qi, ON, ALLPRIO);
5110 }
5111 } else if (wlc->pub->_priofc) {
5112 if (pktq_plen(q, wlc_prio2prec_map[prio]) >=
5113 wlc->pub->tunables->datahiwat) {
5114 wlc_txflowcontrol(wlc, qi, ON, prio);
5115 }
5116 }
5117 }
5118
5119 bool BCMFASTPATH
5120 wlc_sendpkt_mac80211(struct wlc_info *wlc, struct sk_buff *sdu,
5121 struct ieee80211_hw *hw)
5122 {
5123 u8 prio;
5124 uint fifo;
5125 void *pkt;
5126 struct scb *scb = &global_scb;
5127 struct ieee80211_hdr *d11_header = (struct ieee80211_hdr *)(sdu->data);
5128 u16 type, fc;
5129
5130 ASSERT(sdu);
5131
5132 fc = ltoh16(d11_header->frame_control);
5133 type = (fc & IEEE80211_FCTL_FTYPE);
5134
5135 /* 802.11 standard requires management traffic to go at highest priority */
5136 prio = (type == IEEE80211_FTYPE_DATA ? sdu->priority : MAXPRIO);
5137 fifo = prio2fifo[prio];
5138
5139 ASSERT((uint) skb_headroom(sdu) >= TXOFF);
5140 ASSERT(!(sdu->cloned));
5141 ASSERT(!(sdu->next));
5142 ASSERT(!(sdu->prev));
5143 ASSERT(fifo < NFIFO);
5144
5145 pkt = sdu;
5146 if (unlikely
5147 (wlc_d11hdrs_mac80211(wlc, hw, pkt, scb, 0, 1, fifo, 0, NULL, 0)))
5148 return -EINVAL;
5149 wlc_txq_enq(wlc, scb, pkt, WLC_PRIO_TO_PREC(prio));
5150 wlc_send_q(wlc, wlc->active_queue);
5151
5152 WLCNTINCR(wlc->pub->_cnt->ieee_tx);
5153 return 0;
5154 }
5155
5156 void BCMFASTPATH wlc_send_q(struct wlc_info *wlc, wlc_txq_info_t *qi)
5157 {
5158 struct sk_buff *pkt[DOT11_MAXNUMFRAGS];
5159 int prec;
5160 u16 prec_map;
5161 int err = 0, i, count;
5162 uint fifo;
5163 struct pktq *q = &qi->q;
5164 struct ieee80211_tx_info *tx_info;
5165
5166 /* only do work for the active queue */
5167 if (qi != wlc->active_queue)
5168 return;
5169
5170 if (in_send_q)
5171 return;
5172 else
5173 in_send_q = true;
5174
5175 prec_map = wlc->tx_prec_map;
5176
5177 /* Send all the enq'd pkts that we can.
5178 * Dequeue packets with precedence with empty HW fifo only
5179 */
5180 while (prec_map && (pkt[0] = pktq_mdeq(q, prec_map, &prec))) {
5181 tx_info = IEEE80211_SKB_CB(pkt[0]);
5182 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
5183 err = wlc_sendampdu(wlc->ampdu, qi, pkt, prec);
5184 } else {
5185 count = 1;
5186 err = wlc_prep_pdu(wlc, pkt[0], &fifo);
5187 if (!err) {
5188 for (i = 0; i < count; i++) {
5189 wlc_txfifo(wlc, fifo, pkt[i], true, 1);
5190 }
5191 }
5192 }
5193
5194 if (err == BCME_BUSY) {
5195 pktq_penq_head(q, prec, pkt[0]);
5196 /* If send failed due to any other reason than a change in
5197 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5198 */
5199 if (prec_map == wlc->tx_prec_map)
5200 break;
5201 prec_map = wlc->tx_prec_map;
5202 }
5203 }
5204
5205 /* Check if flow control needs to be turned off after sending the packet */
5206 if (!EDCF_ENAB(wlc->pub)
5207 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5208 if (wlc_txflowcontrol_prio_isset(wlc, qi, ALLPRIO)
5209 && (pktq_len(q) < wlc->pub->tunables->datahiwat / 2)) {
5210 wlc_txflowcontrol(wlc, qi, OFF, ALLPRIO);
5211 }
5212 } else if (wlc->pub->_priofc) {
5213 int prio;
5214 for (prio = MAXPRIO; prio >= 0; prio--) {
5215 if (wlc_txflowcontrol_prio_isset(wlc, qi, prio) &&
5216 (pktq_plen(q, wlc_prio2prec_map[prio]) <
5217 wlc->pub->tunables->datahiwat / 2)) {
5218 wlc_txflowcontrol(wlc, qi, OFF, prio);
5219 }
5220 }
5221 }
5222 in_send_q = false;
5223 }
5224
5225 /*
5226 * bcmc_fid_generate:
5227 * Generate frame ID for a BCMC packet. The frag field is not used
5228 * for MC frames so is used as part of the sequence number.
5229 */
5230 static inline u16
5231 bcmc_fid_generate(struct wlc_info *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh)
5232 {
5233 u16 frameid;
5234
5235 frameid = ltoh16(txh->TxFrameID) & ~(TXFID_SEQ_MASK | TXFID_QUEUE_MASK);
5236 frameid |=
5237 (((wlc->
5238 mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5239 TX_BCMC_FIFO;
5240
5241 return frameid;
5242 }
5243
5244 void BCMFASTPATH
5245 wlc_txfifo(struct wlc_info *wlc, uint fifo, struct sk_buff *p, bool commit,
5246 s8 txpktpend)
5247 {
5248 u16 frameid = INVALIDFID;
5249 d11txh_t *txh;
5250
5251 ASSERT(fifo < NFIFO);
5252 txh = (d11txh_t *) (p->data);
5253
5254 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5255 * ucode or BSS info as appropriate.
5256 */
5257 if (fifo == TX_BCMC_FIFO) {
5258 frameid = ltoh16(txh->TxFrameID);
5259
5260 }
5261
5262 if (WLC_WAR16165(wlc))
5263 wlc_war16165(wlc, true);
5264
5265
5266 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5267 * in wlc_bmac_txfifo()
5268 */
5269 if (commit) {
5270 TXPKTPENDINC(wlc, fifo, txpktpend);
5271 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5272 txpktpend, TXPKTPENDGET(wlc, fifo));
5273 }
5274
5275 /* Commit BCMC sequence number in the SHM frame ID location */
5276 if (frameid != INVALIDFID)
5277 BCMCFID(wlc, frameid);
5278
5279 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) {
5280 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5281 }
5282 }
5283
5284 static u16
5285 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec, uint length)
5286 {
5287 u16 usec = 0;
5288 uint mac_rate = RSPEC2RATE(rspec);
5289 uint nsyms;
5290
5291 if (IS_MCS(rspec)) {
5292 /* not supported yet */
5293 ASSERT(0);
5294 } else if (IS_OFDM(rspec)) {
5295 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5296 *
5297 * Nbits = length * 8
5298 * Nbits/sym = Mbps * 4 = mac_rate * 2
5299 */
5300 nsyms = CEIL((length * 8), (mac_rate * 2));
5301
5302 /* usec = symbols * usec/symbol */
5303 usec = (u16) (nsyms * APHY_SYMBOL_TIME);
5304 return usec;
5305 } else {
5306 switch (mac_rate) {
5307 case WLC_RATE_1M:
5308 usec = length << 3;
5309 break;
5310 case WLC_RATE_2M:
5311 usec = length << 2;
5312 break;
5313 case WLC_RATE_5M5:
5314 usec = (length << 4) / 11;
5315 break;
5316 case WLC_RATE_11M:
5317 usec = (length << 3) / 11;
5318 break;
5319 default:
5320 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5321 wlc->pub->unit, rspec);
5322 ASSERT((const char *)"Bad phy_rate" == NULL);
5323 break;
5324 }
5325 }
5326
5327 return usec;
5328 }
5329
5330 void BCMFASTPATH
5331 wlc_compute_plcp(struct wlc_info *wlc, ratespec_t rspec, uint length, u8 *plcp)
5332 {
5333 if (IS_MCS(rspec)) {
5334 wlc_compute_mimo_plcp(rspec, length, plcp);
5335 } else if (IS_OFDM(rspec)) {
5336 wlc_compute_ofdm_plcp(rspec, length, plcp);
5337 } else {
5338 wlc_compute_cck_plcp(rspec, length, plcp);
5339 }
5340 return;
5341 }
5342
5343 /* Rate: 802.11 rate code, length: PSDU length in octets */
5344 static void wlc_compute_mimo_plcp(ratespec_t rspec, uint length, u8 *plcp)
5345 {
5346 u8 mcs = (u8) (rspec & RSPEC_RATE_MASK);
5347 ASSERT(IS_MCS(rspec));
5348 plcp[0] = mcs;
5349 if (RSPEC_IS40MHZ(rspec) || (mcs == 32))
5350 plcp[0] |= MIMO_PLCP_40MHZ;
5351 WLC_SET_MIMO_PLCP_LEN(plcp, length);
5352 plcp[3] = RSPEC_MIMOPLCP3(rspec); /* rspec already holds this byte */
5353 plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5354 plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5355 plcp[5] = 0;
5356 }
5357
5358 /* Rate: 802.11 rate code, length: PSDU length in octets */
5359 static void BCMFASTPATH
5360 wlc_compute_ofdm_plcp(ratespec_t rspec, u32 length, u8 *plcp)
5361 {
5362 u8 rate_signal;
5363 u32 tmp = 0;
5364 int rate = RSPEC2RATE(rspec);
5365
5366 ASSERT(IS_OFDM(rspec));
5367
5368 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5369 rate_signal = rate_info[rate] & RATE_MASK;
5370 ASSERT(rate_signal != 0);
5371
5372 memset(plcp, 0, D11_PHY_HDR_LEN);
5373 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal);
5374
5375 tmp = (length & 0xfff) << 5;
5376 plcp[2] |= (tmp >> 16) & 0xff;
5377 plcp[1] |= (tmp >> 8) & 0xff;
5378 plcp[0] |= tmp & 0xff;
5379
5380 return;
5381 }
5382
5383 /*
5384 * Compute PLCP, but only requires actual rate and length of pkt.
5385 * Rate is given in the driver standard multiple of 500 kbps.
5386 * le is set for 11 Mbps rate if necessary.
5387 * Broken out for PRQ.
5388 */
5389
5390 static void wlc_cck_plcp_set(int rate_500, uint length, u8 *plcp)
5391 {
5392 u16 usec = 0;
5393 u8 le = 0;
5394
5395 switch (rate_500) {
5396 case WLC_RATE_1M:
5397 usec = length << 3;
5398 break;
5399 case WLC_RATE_2M:
5400 usec = length << 2;
5401 break;
5402 case WLC_RATE_5M5:
5403 usec = (length << 4) / 11;
5404 if ((length << 4) - (usec * 11) > 0)
5405 usec++;
5406 break;
5407 case WLC_RATE_11M:
5408 usec = (length << 3) / 11;
5409 if ((length << 3) - (usec * 11) > 0) {
5410 usec++;
5411 if ((usec * 11) - (length << 3) >= 8)
5412 le = D11B_PLCP_SIGNAL_LE;
5413 }
5414 break;
5415
5416 default:
5417 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500);
5418 rate_500 = WLC_RATE_1M;
5419 usec = length << 3;
5420 break;
5421 }
5422 /* PLCP signal byte */
5423 plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */
5424 /* PLCP service byte */
5425 plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED);
5426 /* PLCP length u16, little endian */
5427 plcp[2] = usec & 0xff;
5428 plcp[3] = (usec >> 8) & 0xff;
5429 /* PLCP CRC16 */
5430 plcp[4] = 0;
5431 plcp[5] = 0;
5432 }
5433
5434 /* Rate: 802.11 rate code, length: PSDU length in octets */
5435 static void wlc_compute_cck_plcp(ratespec_t rspec, uint length, u8 *plcp)
5436 {
5437 int rate = RSPEC2RATE(rspec);
5438
5439 ASSERT(IS_CCK(rspec));
5440
5441 wlc_cck_plcp_set(rate, length, plcp);
5442 }
5443
5444 /* wlc_compute_frame_dur()
5445 *
5446 * Calculate the 802.11 MAC header DUR field for MPDU
5447 * DUR for a single frame = 1 SIFS + 1 ACK
5448 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5449 *
5450 * rate MPDU rate in unit of 500kbps
5451 * next_frag_len next MPDU length in bytes
5452 * preamble_type use short/GF or long/MM PLCP header
5453 */
5454 static u16 BCMFASTPATH
5455 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate, u8 preamble_type,
5456 uint next_frag_len)
5457 {
5458 u16 dur, sifs;
5459
5460 sifs = SIFS(wlc->band);
5461
5462 dur = sifs;
5463 dur += (u16) wlc_calc_ack_time(wlc, rate, preamble_type);
5464
5465 if (next_frag_len) {
5466 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5467 dur *= 2;
5468 /* add another SIFS and the frag time */
5469 dur += sifs;
5470 dur +=
5471 (u16) wlc_calc_frame_time(wlc, rate, preamble_type,
5472 next_frag_len);
5473 }
5474 return dur;
5475 }
5476
5477 /* wlc_compute_rtscts_dur()
5478 *
5479 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5480 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5481 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5482 *
5483 * cts cts-to-self or rts/cts
5484 * rts_rate rts or cts rate in unit of 500kbps
5485 * rate next MPDU rate in unit of 500kbps
5486 * frame_len next MPDU frame length in bytes
5487 */
5488 u16 BCMFASTPATH
5489 wlc_compute_rtscts_dur(struct wlc_info *wlc, bool cts_only, ratespec_t rts_rate,
5490 ratespec_t frame_rate, u8 rts_preamble_type,
5491 u8 frame_preamble_type, uint frame_len, bool ba)
5492 {
5493 u16 dur, sifs;
5494
5495 sifs = SIFS(wlc->band);
5496
5497 if (!cts_only) { /* RTS/CTS */
5498 dur = 3 * sifs;
5499 dur +=
5500 (u16) wlc_calc_cts_time(wlc, rts_rate,
5501 rts_preamble_type);
5502 } else { /* CTS-TO-SELF */
5503 dur = 2 * sifs;
5504 }
5505
5506 dur +=
5507 (u16) wlc_calc_frame_time(wlc, frame_rate, frame_preamble_type,
5508 frame_len);
5509 if (ba)
5510 dur +=
5511 (u16) wlc_calc_ba_time(wlc, frame_rate,
5512 WLC_SHORT_PREAMBLE);
5513 else
5514 dur +=
5515 (u16) wlc_calc_ack_time(wlc, frame_rate,
5516 frame_preamble_type);
5517 return dur;
5518 }
5519
5520 static bool wlc_phy_rspec_check(struct wlc_info *wlc, u16 bw, ratespec_t rspec)
5521 {
5522 if (IS_MCS(rspec)) {
5523 uint mcs = rspec & RSPEC_RATE_MASK;
5524
5525 if (mcs < 8) {
5526 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5527 } else if ((mcs >= 8) && (mcs <= 23)) {
5528 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SDM);
5529 } else if (mcs == 32) {
5530 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5531 ASSERT(bw == PHY_TXC1_BW_40MHZ_DUP);
5532 }
5533 } else if (IS_OFDM(rspec)) {
5534 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_STBC);
5535 } else {
5536 ASSERT(IS_CCK(rspec));
5537
5538 ASSERT((bw == PHY_TXC1_BW_20MHZ)
5539 || (bw == PHY_TXC1_BW_20MHZ_UP));
5540 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SISO);
5541 }
5542
5543 return true;
5544 }
5545
5546 u16 BCMFASTPATH wlc_phytxctl1_calc(struct wlc_info *wlc, ratespec_t rspec)
5547 {
5548 u16 phyctl1 = 0;
5549 u16 bw;
5550
5551 if (WLCISLCNPHY(wlc->band)) {
5552 bw = PHY_TXC1_BW_20MHZ;
5553 } else {
5554 bw = RSPEC_GET_BW(rspec);
5555 /* 10Mhz is not supported yet */
5556 if (bw < PHY_TXC1_BW_20MHZ) {
5557 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5558 bw);
5559 bw = PHY_TXC1_BW_20MHZ;
5560 }
5561
5562 wlc_phy_rspec_check(wlc, bw, rspec);
5563 }
5564
5565 if (IS_MCS(rspec)) {
5566 uint mcs = rspec & RSPEC_RATE_MASK;
5567
5568 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5569 phyctl1 = RSPEC_PHYTXBYTE2(rspec);
5570 /* set the upper byte of phyctl1 */
5571 phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8);
5572 } else if (IS_CCK(rspec) && !WLCISLCNPHY(wlc->band)
5573 && !WLCISSSLPNPHY(wlc->band)) {
5574 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5575 /* Eventually MIMOPHY would also be converted to this format */
5576 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5577 phyctl1 = (bw | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5578 } else { /* legacy OFDM/CCK */
5579 s16 phycfg;
5580 /* get the phyctl byte from rate phycfg table */
5581 phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec));
5582 if (phycfg == -1) {
5583 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5584 ASSERT(0);
5585 phycfg = 0;
5586 }
5587 /* set the upper byte of phyctl1 */
5588 phyctl1 =
5589 (bw | (phycfg << 8) |
5590 (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5591 }
5592
5593 #ifdef BCMDBG
5594 /* phy clock must support 40Mhz if tx descriptor uses it */
5595 if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) {
5596 ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ);
5597 ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi));
5598 }
5599 #endif /* BCMDBG */
5600 return phyctl1;
5601 }
5602
5603 ratespec_t BCMFASTPATH
5604 wlc_rspec_to_rts_rspec(struct wlc_info *wlc, ratespec_t rspec, bool use_rspec,
5605 u16 mimo_ctlchbw)
5606 {
5607 ratespec_t rts_rspec = 0;
5608
5609 if (use_rspec) {
5610 /* use frame rate as rts rate */
5611 rts_rspec = rspec;
5612
5613 } else if (wlc->band->gmode && wlc->protection->_g && !IS_CCK(rspec)) {
5614 /* Use 11Mbps as the g protection RTS target rate and fallback.
5615 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5616 * target in case 11 Mbps is not Basic.
5617 * 6 and 9 Mbps are not usually selected by rate selection, but even
5618 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5619 */
5620 rts_rspec = WLC_BASIC_RATE(wlc, WLC_RATE_11M);
5621 } else {
5622 /* calculate RTS rate and fallback rate based on the frame rate
5623 * RTS must be sent at a basic rate since it is a
5624 * control frame, sec 9.6 of 802.11 spec
5625 */
5626 rts_rspec = WLC_BASIC_RATE(wlc, rspec);
5627 }
5628
5629 if (WLC_PHY_11N_CAP(wlc->band)) {
5630 /* set rts txbw to correct side band */
5631 rts_rspec &= ~RSPEC_BW_MASK;
5632
5633 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5634 * (DUP), otherwise send RTS on control channel
5635 */
5636 if (RSPEC_IS40MHZ(rspec) && !IS_CCK(rts_rspec))
5637 rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT);
5638 else
5639 rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5640
5641 /* pick siso/cdd as default for ofdm */
5642 if (IS_OFDM(rts_rspec)) {
5643 rts_rspec &= ~RSPEC_STF_MASK;
5644 rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
5645 }
5646 }
5647 return rts_rspec;
5648 }
5649
5650 /*
5651 * Add d11txh_t, cck_phy_hdr_t.
5652 *
5653 * 'p' data must start with 802.11 MAC header
5654 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5655 *
5656 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5657 *
5658 */
5659 static u16 BCMFASTPATH
5660 wlc_d11hdrs_mac80211(struct wlc_info *wlc, struct ieee80211_hw *hw,
5661 struct sk_buff *p, struct scb *scb, uint frag,
5662 uint nfrags, uint queue, uint next_frag_len,
5663 wsec_key_t *key, ratespec_t rspec_override)
5664 {
5665 struct ieee80211_hdr *h;
5666 d11txh_t *txh;
5667 u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN];
5668 struct osl_info *osh;
5669 int len, phylen, rts_phylen;
5670 u16 fc, type, frameid, mch, phyctl, xfts, mainrates;
5671 u16 seq = 0, mcl = 0, status = 0;
5672 ratespec_t rspec[2] = { WLC_RATE_1M, WLC_RATE_1M }, rts_rspec[2] = {
5673 WLC_RATE_1M, WLC_RATE_1M};
5674 bool use_rts = false;
5675 bool use_cts = false;
5676 bool use_rifs = false;
5677 bool short_preamble[2] = { false, false };
5678 u8 preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5679 u8 rts_preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5680 u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN];
5681 struct ieee80211_rts *rts = NULL;
5682 bool qos;
5683 uint ac;
5684 u32 rate_val[2];
5685 bool hwtkmic = false;
5686 u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
5687 #ifdef WLANTSEL
5688 #define ANTCFG_NONE 0xFF
5689 u8 antcfg = ANTCFG_NONE;
5690 u8 fbantcfg = ANTCFG_NONE;
5691 #endif
5692 uint phyctl1_stf = 0;
5693 u16 durid = 0;
5694 struct ieee80211_tx_rate *txrate[2];
5695 int k;
5696 struct ieee80211_tx_info *tx_info;
5697 bool is_mcs[2];
5698 u16 mimo_txbw;
5699 u8 mimo_preamble_type;
5700
5701 frameid = 0;
5702
5703 ASSERT(queue < NFIFO);
5704
5705 osh = wlc->osh;
5706
5707 /* locate 802.11 MAC header */
5708 h = (struct ieee80211_hdr *)(p->data);
5709 fc = ltoh16(h->frame_control);
5710 type = (fc & IEEE80211_FCTL_FTYPE);
5711
5712 qos = (type == IEEE80211_FTYPE_DATA &&
5713 FC_SUBTYPE_ANY_QOS(fc));
5714
5715 /* compute length of frame in bytes for use in PLCP computations */
5716 len = pkttotlen(osh, p);
5717 phylen = len + FCS_LEN;
5718
5719 /* If WEP enabled, add room in phylen for the additional bytes of
5720 * ICV which MAC generates. We do NOT add the additional bytes to
5721 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5722 * in this case
5723 */
5724 if (key) {
5725 phylen += key->icv_len;
5726 }
5727
5728 /* Get tx_info */
5729 tx_info = IEEE80211_SKB_CB(p);
5730 ASSERT(tx_info);
5731
5732 /* add PLCP */
5733 plcp = skb_push(p, D11_PHY_HDR_LEN);
5734
5735 /* add Broadcom tx descriptor header */
5736 txh = (d11txh_t *) skb_push(p, D11_TXH_LEN);
5737 memset((char *)txh, 0, D11_TXH_LEN);
5738
5739 /* setup frameid */
5740 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
5741 /* non-AP STA should never use BCMC queue */
5742 ASSERT(queue != TX_BCMC_FIFO);
5743 if (queue == TX_BCMC_FIFO) {
5744 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5745 WLCWLUNIT(wlc), __func__);
5746 frameid = bcmc_fid_generate(wlc, NULL, txh);
5747 } else {
5748 /* Increment the counter for first fragment */
5749 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
5750 SCB_SEQNUM(scb, p->priority)++;
5751 }
5752
5753 /* extract fragment number from frame first */
5754 seq = ltoh16(seq) & FRAGNUM_MASK;
5755 seq |= (SCB_SEQNUM(scb, p->priority) << SEQNUM_SHIFT);
5756 h->seq_ctrl = htol16(seq);
5757
5758 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5759 (queue & TXFID_QUEUE_MASK);
5760 }
5761 }
5762 frameid |= queue & TXFID_QUEUE_MASK;
5763
5764 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5765 if (SCB_PS(scb) || ((fc & FC_KIND_MASK) == FC_BEACON))
5766 mcl |= TXC_IGNOREPMQ;
5767
5768 ASSERT(hw->max_rates <= IEEE80211_TX_MAX_RATES);
5769 ASSERT(hw->max_rates == 2);
5770
5771 txrate[0] = tx_info->control.rates;
5772 txrate[1] = txrate[0] + 1;
5773
5774 ASSERT(txrate[0]->idx >= 0);
5775 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5776 if (txrate[1]->idx < 0) {
5777 txrate[1] = txrate[0];
5778 }
5779
5780 for (k = 0; k < hw->max_rates; k++) {
5781 is_mcs[k] =
5782 txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false;
5783 if (!is_mcs[k]) {
5784 ASSERT(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU));
5785 if ((txrate[k]->idx >= 0)
5786 && (txrate[k]->idx <
5787 hw->wiphy->bands[tx_info->band]->n_bitrates)) {
5788 rate_val[k] =
5789 hw->wiphy->bands[tx_info->band]->
5790 bitrates[txrate[k]->idx].hw_value;
5791 short_preamble[k] =
5792 txrate[k]->
5793 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ?
5794 true : false;
5795 } else {
5796 ASSERT((txrate[k]->idx >= 0) &&
5797 (txrate[k]->idx <
5798 hw->wiphy->bands[tx_info->band]->
5799 n_bitrates));
5800 rate_val[k] = WLC_RATE_1M;
5801 }
5802 } else {
5803 rate_val[k] = txrate[k]->idx;
5804 }
5805 /* Currently only support same setting for primay and fallback rates.
5806 * Unify flags for each rate into a single value for the frame
5807 */
5808 use_rts |=
5809 txrate[k]->
5810 flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false;
5811 use_cts |=
5812 txrate[k]->
5813 flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false;
5814
5815 if (is_mcs[k])
5816 rate_val[k] |= NRATE_MCS_INUSE;
5817
5818 rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, rate_val[k]);
5819
5820 /* (1) RATE: determine and validate primary rate and fallback rates */
5821 if (!RSPEC_ACTIVE(rspec[k])) {
5822 ASSERT(RSPEC_ACTIVE(rspec[k]));
5823 rspec[k] = WLC_RATE_1M;
5824 } else {
5825 if (WLANTSEL_ENAB(wlc) &&
5826 !is_multicast_ether_addr(h->addr1)) {
5827 /* set tx antenna config */
5828 wlc_antsel_antcfg_get(wlc->asi, false, false, 0,
5829 0, &antcfg, &fbantcfg);
5830 }
5831 }
5832 }
5833
5834 phyctl1_stf = wlc->stf->ss_opmode;
5835
5836 if (N_ENAB(wlc->pub)) {
5837 for (k = 0; k < hw->max_rates; k++) {
5838 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5839 if (((IS_MCS(rspec[k]) &&
5840 IS_SINGLE_STREAM(rspec[k] & RSPEC_RATE_MASK)) ||
5841 IS_OFDM(rspec[k]))
5842 && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY)
5843 || !(rspec[k] & RSPEC_OVERRIDE))) {
5844 rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK);
5845
5846 /* For SISO MCS use STBC if possible */
5847 if (IS_MCS(rspec[k])
5848 && WLC_STF_SS_STBC_TX(wlc, scb)) {
5849 u8 stc;
5850
5851 ASSERT(WLC_STBC_CAP_PHY(wlc));
5852 stc = 1; /* Nss for single stream is always 1 */
5853 rspec[k] |=
5854 (PHY_TXC1_MODE_STBC <<
5855 RSPEC_STF_SHIFT) | (stc <<
5856 RSPEC_STC_SHIFT);
5857 } else
5858 rspec[k] |=
5859 (phyctl1_stf << RSPEC_STF_SHIFT);
5860 }
5861
5862 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5863 if (CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ) {
5864 /* default txbw is 20in40 SB */
5865 mimo_ctlchbw = mimo_txbw =
5866 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC)
5867 ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
5868
5869 if (IS_MCS(rspec[k])) {
5870 /* mcs 32 must be 40b/w DUP */
5871 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5872 mimo_txbw =
5873 PHY_TXC1_BW_40MHZ_DUP;
5874 /* use override */
5875 } else if (wlc->mimo_40txbw != AUTO)
5876 mimo_txbw = wlc->mimo_40txbw;
5877 /* else check if dst is using 40 Mhz */
5878 else if (scb->flags & SCB_IS40)
5879 mimo_txbw = PHY_TXC1_BW_40MHZ;
5880 } else if (IS_OFDM(rspec[k])) {
5881 if (wlc->ofdm_40txbw != AUTO)
5882 mimo_txbw = wlc->ofdm_40txbw;
5883 } else {
5884 ASSERT(IS_CCK(rspec[k]));
5885 if (wlc->cck_40txbw != AUTO)
5886 mimo_txbw = wlc->cck_40txbw;
5887 }
5888 } else {
5889 /* mcs32 is 40 b/w only.
5890 * This is possible for probe packets on a STA during SCAN
5891 */
5892 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5893 /* mcs 0 */
5894 rspec[k] = RSPEC_MIMORATE;
5895 }
5896 mimo_txbw = PHY_TXC1_BW_20MHZ;
5897 }
5898
5899 /* Set channel width */
5900 rspec[k] &= ~RSPEC_BW_MASK;
5901 if ((k == 0) || ((k > 0) && IS_MCS(rspec[k])))
5902 rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT);
5903 else
5904 rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5905
5906 /* Set Short GI */
5907 #ifdef NOSGIYET
5908 if (IS_MCS(rspec[k])
5909 && (txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
5910 rspec[k] |= RSPEC_SHORT_GI;
5911 else if (!(txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
5912 rspec[k] &= ~RSPEC_SHORT_GI;
5913 #else
5914 rspec[k] &= ~RSPEC_SHORT_GI;
5915 #endif
5916
5917 mimo_preamble_type = WLC_MM_PREAMBLE;
5918 if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD)
5919 mimo_preamble_type = WLC_GF_PREAMBLE;
5920
5921 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS)
5922 && (!IS_MCS(rspec[k]))) {
5923 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
5924 WLCWLUNIT(wlc), __func__);
5925 ASSERT(0 && "Rate mismatch");
5926 }
5927
5928 if (IS_MCS(rspec[k])) {
5929 preamble_type[k] = mimo_preamble_type;
5930
5931 /* if SGI is selected, then forced mm for single stream */
5932 if ((rspec[k] & RSPEC_SHORT_GI)
5933 && IS_SINGLE_STREAM(rspec[k] &
5934 RSPEC_RATE_MASK)) {
5935 preamble_type[k] = WLC_MM_PREAMBLE;
5936 }
5937 }
5938
5939 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
5940 ASSERT(VALID_RATE_DBG(wlc, rspec[0]));
5941
5942 /* should be better conditionalized */
5943 if (!IS_MCS(rspec[0])
5944 && (tx_info->control.rates[0].
5945 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
5946 preamble_type[k] = WLC_SHORT_PREAMBLE;
5947
5948 ASSERT(!IS_MCS(rspec[0])
5949 || WLC_IS_MIMO_PREAMBLE(preamble_type[k]));
5950 }
5951 } else {
5952 for (k = 0; k < hw->max_rates; k++) {
5953 /* Set ctrlchbw as 20Mhz */
5954 ASSERT(!IS_MCS(rspec[k]));
5955 rspec[k] &= ~RSPEC_BW_MASK;
5956 rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT);
5957
5958 /* for nphy, stf of ofdm frames must follow policies */
5959 if (WLCISNPHY(wlc->band) && IS_OFDM(rspec[k])) {
5960 rspec[k] &= ~RSPEC_STF_MASK;
5961 rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT;
5962 }
5963 }
5964 }
5965
5966 /* Reset these for use with AMPDU's */
5967 txrate[0]->count = 0;
5968 txrate[1]->count = 0;
5969
5970 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
5971 wlc_compute_plcp(wlc, rspec[0], phylen, plcp);
5972 wlc_compute_plcp(wlc, rspec[1], phylen, plcp_fallback);
5973 bcopy(plcp_fallback, (char *)&txh->FragPLCPFallback,
5974 sizeof(txh->FragPLCPFallback));
5975
5976 /* Length field now put in CCK FBR CRC field */
5977 if (IS_CCK(rspec[1])) {
5978 txh->FragPLCPFallback[4] = phylen & 0xff;
5979 txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8;
5980 }
5981
5982 /* MIMO-RATE: need validation ?? */
5983 mainrates =
5984 IS_OFDM(rspec[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) plcp) :
5985 plcp[0];
5986
5987 /* DUR field for main rate */
5988 if ((fc != FC_PS_POLL) &&
5989 !is_multicast_ether_addr(h->addr1) && !use_rifs) {
5990 durid =
5991 wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0],
5992 next_frag_len);
5993 h->duration_id = htol16(durid);
5994 } else if (use_rifs) {
5995 /* NAV protect to end of next max packet size */
5996 durid =
5997 (u16) wlc_calc_frame_time(wlc, rspec[0],
5998 preamble_type[0],
5999 DOT11_MAX_FRAG_LEN);
6000 durid += RIFS_11N_TIME;
6001 h->duration_id = htol16(durid);
6002 }
6003
6004 /* DUR field for fallback rate */
6005 if (fc == FC_PS_POLL)
6006 txh->FragDurFallback = h->duration_id;
6007 else if (is_multicast_ether_addr(h->addr1) || use_rifs)
6008 txh->FragDurFallback = 0;
6009 else {
6010 durid = wlc_compute_frame_dur(wlc, rspec[1],
6011 preamble_type[1], next_frag_len);
6012 txh->FragDurFallback = htol16(durid);
6013 }
6014
6015 /* (4) MAC-HDR: MacTxControlLow */
6016 if (frag == 0)
6017 mcl |= TXC_STARTMSDU;
6018
6019 if (!is_multicast_ether_addr(h->addr1))
6020 mcl |= TXC_IMMEDACK;
6021
6022 if (BAND_5G(wlc->band->bandtype))
6023 mcl |= TXC_FREQBAND_5G;
6024
6025 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC))
6026 mcl |= TXC_BW_40;
6027
6028 /* set AMIC bit if using hardware TKIP MIC */
6029 if (hwtkmic)
6030 mcl |= TXC_AMIC;
6031
6032 txh->MacTxControlLow = htol16(mcl);
6033
6034 /* MacTxControlHigh */
6035 mch = 0;
6036
6037 /* Set fallback rate preamble type */
6038 if ((preamble_type[1] == WLC_SHORT_PREAMBLE) ||
6039 (preamble_type[1] == WLC_GF_PREAMBLE)) {
6040 ASSERT((preamble_type[1] == WLC_GF_PREAMBLE) ||
6041 (!IS_MCS(rspec[1])));
6042 if (RSPEC2RATE(rspec[1]) != WLC_RATE_1M)
6043 mch |= TXC_PREAMBLE_DATA_FB_SHORT;
6044 }
6045
6046 /* MacFrameControl */
6047 bcopy((char *)&h->frame_control, (char *)&txh->MacFrameControl,
6048 sizeof(u16));
6049 txh->TxFesTimeNormal = htol16(0);
6050
6051 txh->TxFesTimeFallback = htol16(0);
6052
6053 /* TxFrameRA */
6054 bcopy((char *)&h->addr1, (char *)&txh->TxFrameRA, ETH_ALEN);
6055
6056 /* TxFrameID */
6057 txh->TxFrameID = htol16(frameid);
6058
6059 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6060 * then we may need to reset the retry cnt's via the status reg
6061 */
6062 txh->TxStatus = htol16(status);
6063
6064 if (D11REV_GE(wlc->pub->corerev, 16)) {
6065 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6066 * the END of previous structure so that it's compatible in driver.
6067 * In old rev ucode, these fields should be ignored
6068 */
6069 txh->MaxNMpdus = htol16(0);
6070 txh->MaxABytes_MRT = htol16(0);
6071 txh->MaxABytes_FBR = htol16(0);
6072 txh->MinMBytes = htol16(0);
6073 }
6074
6075 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6076 /* RTS PLCP header and RTS frame */
6077 if (use_rts || use_cts) {
6078 if (use_rts && use_cts)
6079 use_cts = false;
6080
6081 for (k = 0; k < 2; k++) {
6082 rts_rspec[k] = wlc_rspec_to_rts_rspec(wlc, rspec[k],
6083 false,
6084 mimo_ctlchbw);
6085 }
6086
6087 if (!IS_OFDM(rts_rspec[0]) &&
6088 !((RSPEC2RATE(rts_rspec[0]) == WLC_RATE_1M) ||
6089 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6090 rts_preamble_type[0] = WLC_SHORT_PREAMBLE;
6091 mch |= TXC_PREAMBLE_RTS_MAIN_SHORT;
6092 }
6093
6094 if (!IS_OFDM(rts_rspec[1]) &&
6095 !((RSPEC2RATE(rts_rspec[1]) == WLC_RATE_1M) ||
6096 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6097 rts_preamble_type[1] = WLC_SHORT_PREAMBLE;
6098 mch |= TXC_PREAMBLE_RTS_FB_SHORT;
6099 }
6100
6101 /* RTS/CTS additions to MacTxControlLow */
6102 if (use_cts) {
6103 txh->MacTxControlLow |= htol16(TXC_SENDCTS);
6104 } else {
6105 txh->MacTxControlLow |= htol16(TXC_SENDRTS);
6106 txh->MacTxControlLow |= htol16(TXC_LONGFRAME);
6107 }
6108
6109 /* RTS PLCP header */
6110 ASSERT(IS_ALIGNED((unsigned long)txh->RTSPhyHeader, sizeof(u16)));
6111 rts_plcp = txh->RTSPhyHeader;
6112 if (use_cts)
6113 rts_phylen = DOT11_CTS_LEN + FCS_LEN;
6114 else
6115 rts_phylen = DOT11_RTS_LEN + FCS_LEN;
6116
6117 wlc_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp);
6118
6119 /* fallback rate version of RTS PLCP header */
6120 wlc_compute_plcp(wlc, rts_rspec[1], rts_phylen,
6121 rts_plcp_fallback);
6122 bcopy(rts_plcp_fallback, (char *)&txh->RTSPLCPFallback,
6123 sizeof(txh->RTSPLCPFallback));
6124
6125 /* RTS frame fields... */
6126 rts = (struct ieee80211_rts *)&txh->rts_frame;
6127
6128 durid = wlc_compute_rtscts_dur(wlc, use_cts, rts_rspec[0],
6129 rspec[0], rts_preamble_type[0],
6130 preamble_type[0], phylen, false);
6131 rts->duration = htol16(durid);
6132 /* fallback rate version of RTS DUR field */
6133 durid = wlc_compute_rtscts_dur(wlc, use_cts,
6134 rts_rspec[1], rspec[1],
6135 rts_preamble_type[1],
6136 preamble_type[1], phylen, false);
6137 txh->RTSDurFallback = htol16(durid);
6138
6139 if (use_cts) {
6140 rts->frame_control = htol16(FC_CTS);
6141 bcopy((char *)&h->addr2, (char *)&rts->ra, ETH_ALEN);
6142 } else {
6143 rts->frame_control = htol16((u16) FC_RTS);
6144 bcopy((char *)&h->addr1, (char *)&rts->ra,
6145 2 * ETH_ALEN);
6146 }
6147
6148 /* mainrate
6149 * low 8 bits: main frag rate/mcs,
6150 * high 8 bits: rts/cts rate/mcs
6151 */
6152 mainrates |= (IS_OFDM(rts_rspec[0]) ?
6153 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) :
6154 rts_plcp[0]) << 8;
6155 } else {
6156 memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN);
6157 memset((char *)&txh->rts_frame, 0,
6158 sizeof(struct ieee80211_rts));
6159 memset((char *)txh->RTSPLCPFallback, 0,
6160 sizeof(txh->RTSPLCPFallback));
6161 txh->RTSDurFallback = 0;
6162 }
6163
6164 #ifdef SUPPORT_40MHZ
6165 /* add null delimiter count */
6166 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && IS_MCS(rspec)) {
6167 txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] =
6168 wlc_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen);
6169 }
6170 #endif
6171
6172 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6173 txh->MacTxControlHigh = htol16(mch);
6174
6175 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6176 txh->MainRates = htol16(mainrates);
6177
6178 /* XtraFrameTypes */
6179 xfts = FRAMETYPE(rspec[1], wlc->mimoft);
6180 xfts |= (FRAMETYPE(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT);
6181 xfts |= (FRAMETYPE(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT);
6182 xfts |=
6183 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC) << XFTS_CHANNEL_SHIFT;
6184 txh->XtraFrameTypes = htol16(xfts);
6185
6186 /* PhyTxControlWord */
6187 phyctl = FRAMETYPE(rspec[0], wlc->mimoft);
6188 if ((preamble_type[0] == WLC_SHORT_PREAMBLE) ||
6189 (preamble_type[0] == WLC_GF_PREAMBLE)) {
6190 ASSERT((preamble_type[0] == WLC_GF_PREAMBLE)
6191 || !IS_MCS(rspec[0]));
6192 if (RSPEC2RATE(rspec[0]) != WLC_RATE_1M)
6193 phyctl |= PHY_TXC_SHORT_HDR;
6194 WLCNTINCR(wlc->pub->_cnt->txprshort);
6195 }
6196
6197 /* phytxant is properly bit shifted */
6198 phyctl |= wlc_stf_d11hdrs_phyctl_txant(wlc, rspec[0]);
6199 txh->PhyTxControlWord = htol16(phyctl);
6200
6201 /* PhyTxControlWord_1 */
6202 if (WLC_PHY_11N_CAP(wlc->band)) {
6203 u16 phyctl1 = 0;
6204
6205 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[0]);
6206 txh->PhyTxControlWord_1 = htol16(phyctl1);
6207 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[1]);
6208 txh->PhyTxControlWord_1_Fbr = htol16(phyctl1);
6209
6210 if (use_rts || use_cts) {
6211 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[0]);
6212 txh->PhyTxControlWord_1_Rts = htol16(phyctl1);
6213 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[1]);
6214 txh->PhyTxControlWord_1_FbrRts = htol16(phyctl1);
6215 }
6216
6217 /*
6218 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6219 * fill in non-zero MModeLen and/or MModeFbrLen
6220 * it will be unnecessary if they are separated
6221 */
6222 if (IS_MCS(rspec[0]) && (preamble_type[0] == WLC_MM_PREAMBLE)) {
6223 u16 mmodelen =
6224 wlc_calc_lsig_len(wlc, rspec[0], phylen);
6225 txh->MModeLen = htol16(mmodelen);
6226 }
6227
6228 if (IS_MCS(rspec[1]) && (preamble_type[1] == WLC_MM_PREAMBLE)) {
6229 u16 mmodefbrlen =
6230 wlc_calc_lsig_len(wlc, rspec[1], phylen);
6231 txh->MModeFbrLen = htol16(mmodefbrlen);
6232 }
6233 }
6234
6235 if (IS_MCS(rspec[0]))
6236 ASSERT(IS_MCS(rspec[1]));
6237
6238 ASSERT(!IS_MCS(rspec[0]) ||
6239 ((preamble_type[0] == WLC_MM_PREAMBLE) == (txh->MModeLen != 0)));
6240 ASSERT(!IS_MCS(rspec[1]) ||
6241 ((preamble_type[1] == WLC_MM_PREAMBLE) ==
6242 (txh->MModeFbrLen != 0)));
6243
6244 ac = wme_fifo2ac[queue];
6245 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) {
6246 uint frag_dur, dur, dur_fallback;
6247
6248 ASSERT(!is_multicast_ether_addr(h->addr1));
6249
6250 /* WME: Update TXOP threshold */
6251 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) {
6252 frag_dur =
6253 wlc_calc_frame_time(wlc, rspec[0], preamble_type[0],
6254 phylen);
6255
6256 if (rts) {
6257 /* 1 RTS or CTS-to-self frame */
6258 dur =
6259 wlc_calc_cts_time(wlc, rts_rspec[0],
6260 rts_preamble_type[0]);
6261 dur_fallback =
6262 wlc_calc_cts_time(wlc, rts_rspec[1],
6263 rts_preamble_type[1]);
6264 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6265 dur += ltoh16(rts->duration);
6266 dur_fallback += ltoh16(txh->RTSDurFallback);
6267 } else if (use_rifs) {
6268 dur = frag_dur;
6269 dur_fallback = 0;
6270 } else {
6271 /* frame + SIFS + ACK */
6272 dur = frag_dur;
6273 dur +=
6274 wlc_compute_frame_dur(wlc, rspec[0],
6275 preamble_type[0], 0);
6276
6277 dur_fallback =
6278 wlc_calc_frame_time(wlc, rspec[1],
6279 preamble_type[1],
6280 phylen);
6281 dur_fallback +=
6282 wlc_compute_frame_dur(wlc, rspec[1],
6283 preamble_type[1], 0);
6284 }
6285 /* NEED to set TxFesTimeNormal (hard) */
6286 txh->TxFesTimeNormal = htol16((u16) dur);
6287 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6288 txh->TxFesTimeFallback = htol16((u16) dur_fallback);
6289
6290 /* update txop byte threshold (txop minus intraframe overhead) */
6291 if (wlc->edcf_txop[ac] >= (dur - frag_dur)) {
6292 {
6293 uint newfragthresh;
6294
6295 newfragthresh =
6296 wlc_calc_frame_len(wlc, rspec[0],
6297 preamble_type[0],
6298 (wlc->
6299 edcf_txop[ac] -
6300 (dur -
6301 frag_dur)));
6302 /* range bound the fragthreshold */
6303 if (newfragthresh < DOT11_MIN_FRAG_LEN)
6304 newfragthresh =
6305 DOT11_MIN_FRAG_LEN;
6306 else if (newfragthresh >
6307 wlc->usr_fragthresh)
6308 newfragthresh =
6309 wlc->usr_fragthresh;
6310 /* update the fragthresh and do txc update */
6311 if (wlc->fragthresh[queue] !=
6312 (u16) newfragthresh) {
6313 wlc->fragthresh[queue] =
6314 (u16) newfragthresh;
6315 }
6316 }
6317 } else
6318 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6319 wlc->pub->unit, fifo_names[queue],
6320 RSPEC2RATE(rspec[0]));
6321
6322 if (dur > wlc->edcf_txop[ac])
6323 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6324 wlc->pub->unit, __func__,
6325 fifo_names[queue],
6326 phylen, wlc->fragthresh[queue],
6327 dur, wlc->edcf_txop[ac]);
6328 }
6329 }
6330
6331 return 0;
6332 }
6333
6334 void wlc_tbtt(struct wlc_info *wlc, d11regs_t *regs)
6335 {
6336 wlc_bsscfg_t *cfg = wlc->cfg;
6337
6338 WLCNTINCR(wlc->pub->_cnt->tbtt);
6339
6340 if (BSSCFG_STA(cfg)) {
6341 /* run watchdog here if the watchdog timer is not armed */
6342 if (WLC_WATCHDOG_TBTT(wlc)) {
6343 u32 cur, delta;
6344 if (wlc->WDarmed) {
6345 wl_del_timer(wlc->wl, wlc->wdtimer);
6346 wlc->WDarmed = false;
6347 }
6348
6349 cur = OSL_SYSUPTIME();
6350 delta = cur > wlc->WDlast ? cur - wlc->WDlast :
6351 (u32) ~0 - wlc->WDlast + cur + 1;
6352 if (delta >= TIMER_INTERVAL_WATCHDOG) {
6353 wlc_watchdog((void *)wlc);
6354 wlc->WDlast = cur;
6355 }
6356
6357 wl_add_timer(wlc->wl, wlc->wdtimer,
6358 wlc_watchdog_backup_bi(wlc), true);
6359 wlc->WDarmed = true;
6360 }
6361 }
6362
6363 if (!cfg->BSS) {
6364 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6365 wlc->qvalid |= MCMD_DIRFRMQVAL;
6366 }
6367 }
6368
6369 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6370 void wlc_hwtimer_gptimer_set(struct wlc_info *wlc, uint us)
6371 {
6372 ASSERT(wlc->pub->corerev >= 3); /* no gptimer in earlier revs */
6373 W_REG(wlc->osh, &wlc->regs->gptimer, us);
6374 }
6375
6376 void wlc_hwtimer_gptimer_abort(struct wlc_info *wlc)
6377 {
6378 ASSERT(wlc->pub->corerev >= 3);
6379 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6380 }
6381
6382 static void wlc_hwtimer_gptimer_cb(struct wlc_info *wlc)
6383 {
6384 /* when interrupt is generated, the counter is loaded with last value
6385 * written and continue to decrement. So it has to be cleaned first
6386 */
6387 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6388 }
6389
6390 /*
6391 * This fn has all the high level dpc processing from wlc_dpc.
6392 * POLICY: no macinstatus change, no bounding loop.
6393 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6394 */
6395 void wlc_high_dpc(struct wlc_info *wlc, u32 macintstatus)
6396 {
6397 d11regs_t *regs = wlc->regs;
6398 #ifdef BCMDBG
6399 char flagstr[128];
6400 static const bcm_bit_desc_t int_flags[] = {
6401 {MI_MACSSPNDD, "MACSSPNDD"},
6402 {MI_BCNTPL, "BCNTPL"},
6403 {MI_TBTT, "TBTT"},
6404 {MI_BCNSUCCESS, "BCNSUCCESS"},
6405 {MI_BCNCANCLD, "BCNCANCLD"},
6406 {MI_ATIMWINEND, "ATIMWINEND"},
6407 {MI_PMQ, "PMQ"},
6408 {MI_NSPECGEN_0, "NSPECGEN_0"},
6409 {MI_NSPECGEN_1, "NSPECGEN_1"},
6410 {MI_MACTXERR, "MACTXERR"},
6411 {MI_NSPECGEN_3, "NSPECGEN_3"},
6412 {MI_PHYTXERR, "PHYTXERR"},
6413 {MI_PME, "PME"},
6414 {MI_GP0, "GP0"},
6415 {MI_GP1, "GP1"},
6416 {MI_DMAINT, "DMAINT"},
6417 {MI_TXSTOP, "TXSTOP"},
6418 {MI_CCA, "CCA"},
6419 {MI_BG_NOISE, "BG_NOISE"},
6420 {MI_DTIM_TBTT, "DTIM_TBTT"},
6421 {MI_PRQ, "PRQ"},
6422 {MI_PWRUP, "PWRUP"},
6423 {MI_RFDISABLE, "RFDISABLE"},
6424 {MI_TFS, "TFS"},
6425 {MI_PHYCHANGED, "PHYCHANGED"},
6426 {MI_TO, "TO"},
6427 {0, NULL}
6428 };
6429
6430 if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) {
6431 bcm_format_flags(int_flags, macintstatus, flagstr,
6432 sizeof(flagstr));
6433 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6434 wlc->pub->unit, macintstatus, flagstr);
6435 }
6436 #endif /* BCMDBG */
6437
6438 if (macintstatus & MI_PRQ) {
6439 /* Process probe request FIFO */
6440 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6441 }
6442
6443 /* TBTT indication */
6444 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6445 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
6446 wlc_tbtt(wlc, regs);
6447
6448 if (macintstatus & MI_GP0) {
6449 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6450 wlc->pub->unit, wlc->pub->now);
6451
6452 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6453 __func__, wlc->pub->sih->chip,
6454 wlc->pub->sih->chiprev);
6455
6456 WLCNTINCR(wlc->pub->_cnt->psmwds);
6457
6458 /* big hammer */
6459 wl_init(wlc->wl);
6460 }
6461
6462 /* gptimer timeout */
6463 if (macintstatus & MI_TO) {
6464 wlc_hwtimer_gptimer_cb(wlc);
6465 }
6466
6467 if (macintstatus & MI_RFDISABLE) {
6468 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6469 wlc->pub->unit,
6470 R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD);
6471 /* delay the cleanup to wl_down in IBSS case */
6472 if ((R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD)) {
6473 int idx;
6474 wlc_bsscfg_t *bsscfg;
6475 FOREACH_BSS(wlc, idx, bsscfg) {
6476 if (!BSSCFG_STA(bsscfg) || !bsscfg->enable
6477 || !bsscfg->BSS)
6478 continue;
6479 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6480 wlc->pub->unit);
6481 }
6482 }
6483 }
6484
6485 /* send any enq'd tx packets. Just makes sure to jump start tx */
6486 if (!pktq_empty(&wlc->active_queue->q))
6487 wlc_send_q(wlc, wlc->active_queue);
6488
6489 ASSERT(wlc_ps_check(wlc));
6490 }
6491
6492 static void *wlc_15420war(struct wlc_info *wlc, uint queue)
6493 {
6494 struct hnddma_pub *di;
6495 void *p;
6496
6497 ASSERT(queue < NFIFO);
6498
6499 if ((D11REV_IS(wlc->pub->corerev, 4))
6500 || (D11REV_GT(wlc->pub->corerev, 6)))
6501 return NULL;
6502
6503 di = wlc->hw->di[queue];
6504 ASSERT(di != NULL);
6505
6506 /* get next packet, ignoring XmtStatus.Curr */
6507 p = dma_getnexttxp(di, HNDDMA_RANGE_ALL);
6508
6509 /* sw block tx dma */
6510 dma_txblock(di);
6511
6512 /* if tx ring is now empty, reset and re-init the tx dma channel */
6513 if (dma_txactive(wlc->hw->di[queue]) == 0) {
6514 WLCNTINCR(wlc->pub->_cnt->txdmawar);
6515 if (!dma_txreset(di))
6516 WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n",
6517 wlc->pub->unit, __func__, queue);
6518 dma_txinit(di);
6519 }
6520 return p;
6521 }
6522
6523 static void wlc_war16165(struct wlc_info *wlc, bool tx)
6524 {
6525 if (tx) {
6526 /* the post-increment is used in STAY_AWAKE macro */
6527 if (wlc->txpend16165war++ == 0)
6528 wlc_set_ps_ctrl(wlc);
6529 } else {
6530 wlc->txpend16165war--;
6531 if (wlc->txpend16165war == 0)
6532 wlc_set_ps_ctrl(wlc);
6533 }
6534 }
6535
6536 /* process an individual tx_status_t */
6537 /* WLC_HIGH_API */
6538 bool BCMFASTPATH
6539 wlc_dotxstatus(struct wlc_info *wlc, tx_status_t *txs, u32 frm_tx2)
6540 {
6541 struct sk_buff *p;
6542 uint queue;
6543 d11txh_t *txh;
6544 struct scb *scb = NULL;
6545 bool free_pdu;
6546 struct osl_info *osh;
6547 int tx_rts, tx_frame_count, tx_rts_count;
6548 uint totlen, supr_status;
6549 bool lastframe;
6550 struct ieee80211_hdr *h;
6551 u16 fc;
6552 u16 mcl;
6553 struct ieee80211_tx_info *tx_info;
6554 struct ieee80211_tx_rate *txrate;
6555 int i;
6556
6557 (void)(frm_tx2); /* Compiler reference to avoid unused variable warning */
6558
6559 /* discard intermediate indications for ucode with one legitimate case:
6560 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6561 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6562 * transmission count)
6563 */
6564 if (!(txs->status & TX_STATUS_AMPDU)
6565 && (txs->status & TX_STATUS_INTERMEDIATE)) {
6566 WLCNTADD(wlc->pub->_cnt->txnoack,
6567 ((txs->
6568 status & TX_STATUS_FRM_RTX_MASK) >>
6569 TX_STATUS_FRM_RTX_SHIFT));
6570 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__);
6571 return false;
6572 }
6573
6574 osh = wlc->osh;
6575 queue = txs->frameid & TXFID_QUEUE_MASK;
6576 ASSERT(queue < NFIFO);
6577 if (queue >= NFIFO) {
6578 p = NULL;
6579 goto fatal;
6580 }
6581
6582 p = GETNEXTTXP(wlc, queue);
6583 if (WLC_WAR16165(wlc))
6584 wlc_war16165(wlc, false);
6585 if (p == NULL)
6586 p = wlc_15420war(wlc, queue);
6587 ASSERT(p != NULL);
6588 if (p == NULL)
6589 goto fatal;
6590
6591 txh = (d11txh_t *) (p->data);
6592 mcl = ltoh16(txh->MacTxControlLow);
6593
6594 if (txs->phyerr) {
6595 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6596 txs->phyerr, txh->MainRates);
6597 wlc_print_txdesc(txh);
6598 wlc_print_txstatus(txs);
6599 }
6600
6601 ASSERT(txs->frameid == htol16(txh->TxFrameID));
6602 if (txs->frameid != htol16(txh->TxFrameID))
6603 goto fatal;
6604
6605 tx_info = IEEE80211_SKB_CB(p);
6606 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
6607 fc = ltoh16(h->frame_control);
6608
6609 scb = (struct scb *)tx_info->control.sta->drv_priv;
6610
6611 if (N_ENAB(wlc->pub)) {
6612 u8 *plcp = (u8 *) (txh + 1);
6613 if (PLCP3_ISSGI(plcp[3]))
6614 WLCNTINCR(wlc->pub->_cnt->txmpdu_sgi);
6615 if (PLCP3_ISSTBC(plcp[3]))
6616 WLCNTINCR(wlc->pub->_cnt->txmpdu_stbc);
6617 }
6618
6619 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
6620 ASSERT((mcl & TXC_AMPDU_MASK) != TXC_AMPDU_NONE);
6621 wlc_ampdu_dotxstatus(wlc->ampdu, scb, p, txs);
6622 return false;
6623 }
6624
6625 supr_status = txs->status & TX_STATUS_SUPR_MASK;
6626 if (supr_status == TX_STATUS_SUPR_BADCH)
6627 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6628 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec));
6629
6630 tx_rts = htol16(txh->MacTxControlLow) & TXC_SENDRTS;
6631 tx_frame_count =
6632 (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT;
6633 tx_rts_count =
6634 (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT;
6635
6636 lastframe = (fc & IEEE80211_FCTL_MOREFRAGS) == 0;
6637
6638 if (!lastframe) {
6639 WL_ERROR("Not last frame!\n");
6640 } else {
6641 u16 sfbl, lfbl;
6642 ieee80211_tx_info_clear_status(tx_info);
6643 if (queue < AC_COUNT) {
6644 sfbl = WLC_WME_RETRY_SFB_GET(wlc, wme_fifo2ac[queue]);
6645 lfbl = WLC_WME_RETRY_LFB_GET(wlc, wme_fifo2ac[queue]);
6646 } else {
6647 sfbl = wlc->SFBL;
6648 lfbl = wlc->LFBL;
6649 }
6650
6651 txrate = tx_info->status.rates;
6652 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6653 if ((tx_frame_count > sfbl) && (txrate[1].idx >= 0)) {
6654 /* rate selection requested a fallback rate and we used it */
6655 txrate->count = lfbl;
6656 txrate[1].count = tx_frame_count - lfbl;
6657 } else {
6658 /* rate selection did not request fallback rate, or we didn't need it */
6659 txrate->count = tx_frame_count;
6660 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6661 txrate[1].idx = -1;
6662 txrate[1].count = 0;
6663 }
6664
6665 /* clear the rest of the rates */
6666 for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
6667 txrate[i].idx = -1;
6668 txrate[i].count = 0;
6669 }
6670
6671 if (txs->status & TX_STATUS_ACK_RCV)
6672 tx_info->flags |= IEEE80211_TX_STAT_ACK;
6673 }
6674
6675 totlen = pkttotlen(osh, p);
6676 free_pdu = true;
6677
6678 wlc_txfifo_complete(wlc, queue, 1);
6679
6680 if (lastframe) {
6681 p->next = NULL;
6682 p->prev = NULL;
6683 wlc->txretried = 0;
6684 /* remove PLCP & Broadcom tx descriptor header */
6685 skb_pull(p, D11_PHY_HDR_LEN);
6686 skb_pull(p, D11_TXH_LEN);
6687 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
6688 WLCNTINCR(wlc->pub->_cnt->ieee_tx_status);
6689 } else {
6690 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6691 __func__);
6692 }
6693
6694 return false;
6695
6696 fatal:
6697 ASSERT(0);
6698 if (p)
6699 pkt_buf_free_skb(osh, p, true);
6700
6701 return true;
6702
6703 }
6704
6705 void BCMFASTPATH
6706 wlc_txfifo_complete(struct wlc_info *wlc, uint fifo, s8 txpktpend)
6707 {
6708 TXPKTPENDDEC(wlc, fifo, txpktpend);
6709 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6710 txpktpend, TXPKTPENDGET(wlc, fifo));
6711
6712 /* There is more room; mark precedences related to this FIFO sendable */
6713 WLC_TX_FIFO_ENAB(wlc, fifo);
6714 ASSERT(TXPKTPENDGET(wlc, fifo) >= 0);
6715
6716 if (!TXPKTPENDTOT(wlc)) {
6717 if (wlc->block_datafifo & DATA_BLOCK_TX_SUPR)
6718 wlc_bsscfg_tx_check(wlc);
6719 }
6720
6721 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6722 if (AP_ENAB(wlc->pub) &&
6723 wlc->bcmcfifo_drain && !TXPKTPENDGET(wlc, TX_BCMC_FIFO)) {
6724 wlc->bcmcfifo_drain = false;
6725 wlc_mhf(wlc, MHF2, MHF2_TXBCMC_NOW, 0, WLC_BAND_AUTO);
6726 }
6727
6728 /* figure out which bsscfg is being worked on... */
6729 }
6730
6731 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6732 * return the offset (in us) of the TSF from the last TBTT
6733 */
6734 u32 wlc_calc_tbtt_offset(u32 bp, u32 tsf_h, u32 tsf_l)
6735 {
6736 u32 k, btklo, btkhi, offset;
6737
6738 /* TBTT is always an even multiple of the beacon_interval,
6739 * so the TBTT less than or equal to the beacon timestamp is
6740 * the beacon timestamp minus the beacon timestamp modulo
6741 * the beacon interval.
6742 *
6743 * TBTT = BT - (BT % BIu)
6744 * = (BTk - (BTk % BP)) * 2^10
6745 *
6746 * BT = beacon timestamp (usec, 64bits)
6747 * BTk = beacon timestamp (Kusec, 54bits)
6748 * BP = beacon interval (Kusec, 16bits)
6749 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6750 *
6751 * To keep the calculations in u32s, the modulo operation
6752 * on the high part of BT needs to be done in parts using the
6753 * relations:
6754 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6755 * and
6756 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6757 *
6758 * So, if BTk[n] = u16 n [0,3] of BTk.
6759 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6760 * and the SUM term can be broken down:
6761 * (BTk[n] * 2^16n) % BP
6762 * (BTk[n] * (2^16n % BP)) % BP
6763 *
6764 * Create a set of power of 2 mod BP constants:
6765 * K[n] = 2^(16n) % BP
6766 * = (K[n-1] * 2^16) % BP
6767 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6768 *
6769 * BTk % BP = BTk[0-1] % BP +
6770 * (BTk[2] * K[2]) % BP +
6771 * (BTk[3] * K[3]) % BP
6772 *
6773 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6774 */
6775
6776 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6777 btklo = (tsf_h << 22) | (tsf_l >> 10);
6778 btkhi = tsf_h >> 10;
6779
6780 /* offset = BTk % BP */
6781 offset = btklo % bp;
6782
6783 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6784 k = (u32) (1 << 16) % bp;
6785 k = (u32) (k * 1 << 16) % (u32) bp;
6786
6787 /* offset += (BTk[2] * K[2]) % BP */
6788 offset += ((btkhi & 0xffff) * k) % bp;
6789
6790 /* BTk[3] */
6791 btkhi = btkhi >> 16;
6792
6793 /* k[3] = (K[2] * 2^16) % BP */
6794 k = (k << 16) % bp;
6795
6796 /* offset += (BTk[3] * K[3]) % BP */
6797 offset += ((btkhi & 0xffff) * k) % bp;
6798
6799 offset = offset % bp;
6800
6801 /* convert offset from kus to us by shifting up 10 bits and
6802 * add in the low 10 bits of tsf that we ignored
6803 */
6804 offset = (offset << 10) + (tsf_l & 0x3FF);
6805
6806 return offset;
6807 }
6808
6809 /* Update beacon listen interval in shared memory */
6810 void wlc_bcn_li_upd(struct wlc_info *wlc)
6811 {
6812 if (AP_ENAB(wlc->pub))
6813 return;
6814
6815 /* wake up every DTIM is the default */
6816 if (wlc->bcn_li_dtim == 1)
6817 wlc_write_shm(wlc, M_BCN_LI, 0);
6818 else
6819 wlc_write_shm(wlc, M_BCN_LI,
6820 (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn);
6821 }
6822
6823 static void
6824 prep_mac80211_status(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p,
6825 struct ieee80211_rx_status *rx_status)
6826 {
6827 u32 tsf_l, tsf_h;
6828 wlc_d11rxhdr_t *wlc_rxh = (wlc_d11rxhdr_t *) rxh;
6829 int preamble;
6830 int channel;
6831 ratespec_t rspec;
6832 unsigned char *plcp;
6833
6834 wlc_read_tsf(wlc, &tsf_l, &tsf_h); /* mactime */
6835 rx_status->mactime = tsf_h;
6836 rx_status->mactime <<= 32;
6837 rx_status->mactime |= tsf_l;
6838 rx_status->flag |= RX_FLAG_TSFT;
6839
6840 channel = WLC_CHAN_CHANNEL(rxh->RxChan);
6841
6842 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
6843 if (channel > 14) {
6844 rx_status->band = IEEE80211_BAND_5GHZ;
6845 rx_status->freq = ieee80211_ofdm_chan_to_freq(
6846 WF_CHAN_FACTOR_5_G/2, channel);
6847
6848 } else {
6849 rx_status->band = IEEE80211_BAND_2GHZ;
6850 rx_status->freq = ieee80211_dsss_chan_to_freq(channel);
6851 }
6852
6853 rx_status->signal = wlc_rxh->rssi; /* signal */
6854
6855 /* noise */
6856 /* qual */
6857 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */
6858
6859 plcp = p->data;
6860
6861 rspec = wlc_compute_rspec(rxh, plcp);
6862 if (IS_MCS(rspec)) {
6863 rx_status->rate_idx = rspec & RSPEC_RATE_MASK;
6864 rx_status->flag |= RX_FLAG_HT;
6865 if (RSPEC_IS40MHZ(rspec))
6866 rx_status->flag |= RX_FLAG_40MHZ;
6867 } else {
6868 switch (RSPEC2RATE(rspec)) {
6869 case WLC_RATE_1M:
6870 rx_status->rate_idx = 0;
6871 break;
6872 case WLC_RATE_2M:
6873 rx_status->rate_idx = 1;
6874 break;
6875 case WLC_RATE_5M5:
6876 rx_status->rate_idx = 2;
6877 break;
6878 case WLC_RATE_11M:
6879 rx_status->rate_idx = 3;
6880 break;
6881 case WLC_RATE_6M:
6882 rx_status->rate_idx = 4;
6883 break;
6884 case WLC_RATE_9M:
6885 rx_status->rate_idx = 5;
6886 break;
6887 case WLC_RATE_12M:
6888 rx_status->rate_idx = 6;
6889 break;
6890 case WLC_RATE_18M:
6891 rx_status->rate_idx = 7;
6892 break;
6893 case WLC_RATE_24M:
6894 rx_status->rate_idx = 8;
6895 break;
6896 case WLC_RATE_36M:
6897 rx_status->rate_idx = 9;
6898 break;
6899 case WLC_RATE_48M:
6900 rx_status->rate_idx = 10;
6901 break;
6902 case WLC_RATE_54M:
6903 rx_status->rate_idx = 11;
6904 break;
6905 default:
6906 WL_ERROR("%s: Unknown rate\n", __func__);
6907 }
6908
6909 /* Determine short preamble and rate_idx */
6910 preamble = 0;
6911 if (IS_CCK(rspec)) {
6912 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
6913 WL_ERROR("Short CCK\n");
6914 rx_status->flag |= RX_FLAG_SHORTPRE;
6915 } else if (IS_OFDM(rspec)) {
6916 rx_status->flag |= RX_FLAG_SHORTPRE;
6917 } else {
6918 WL_ERROR("%s: Unknown modulation\n", __func__);
6919 }
6920 }
6921
6922 if (PLCP3_ISSGI(plcp[3]))
6923 rx_status->flag |= RX_FLAG_SHORT_GI;
6924
6925 if (rxh->RxStatus1 & RXS_DECERR) {
6926 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC;
6927 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__);
6928 }
6929 if (rxh->RxStatus1 & RXS_FCSERR) {
6930 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
6931 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__);
6932 }
6933 }
6934
6935 static void
6936 wlc_recvctl(struct wlc_info *wlc, struct osl_info *osh, d11rxhdr_t *rxh,
6937 struct sk_buff *p)
6938 {
6939 int len_mpdu;
6940 struct ieee80211_rx_status rx_status;
6941 #if defined(BCMDBG)
6942 struct sk_buff *skb = p;
6943 #endif /* BCMDBG */
6944 /* Todo:
6945 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
6946 * Test for INTERMEDIATE like so:
6947 * if (!(plcp[0] | plcp[1] | plcp[2]))
6948 */
6949
6950 memset(&rx_status, 0, sizeof(rx_status));
6951 prep_mac80211_status(wlc, rxh, p, &rx_status);
6952
6953 /* mac header+body length, exclude CRC and plcp header */
6954 len_mpdu = p->len - D11_PHY_HDR_LEN - FCS_LEN;
6955 skb_pull(p, D11_PHY_HDR_LEN);
6956 __skb_trim(p, len_mpdu);
6957
6958 ASSERT(!(p->next));
6959 ASSERT(!(p->prev));
6960
6961 ASSERT(IS_ALIGNED((unsigned long)skb->data, 2));
6962
6963 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status));
6964 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
6965
6966 WLCNTINCR(wlc->pub->_cnt->ieee_rx);
6967 osh->pktalloced--;
6968 return;
6969 }
6970
6971 void wlc_bss_list_free(struct wlc_info *wlc, wlc_bss_list_t *bss_list)
6972 {
6973 uint index;
6974 wlc_bss_info_t *bi;
6975
6976 if (!bss_list) {
6977 WL_ERROR("%s: Attempting to free NULL list\n", __func__);
6978 return;
6979 }
6980 /* inspect all BSS descriptor */
6981 for (index = 0; index < bss_list->count; index++) {
6982 bi = bss_list->ptrs[index];
6983 if (bi) {
6984 kfree(bi);
6985 bss_list->ptrs[index] = NULL;
6986 }
6987 }
6988 bss_list->count = 0;
6989 }
6990
6991 /* Process received frames */
6992 /*
6993 * Return true if more frames need to be processed. false otherwise.
6994 * Param 'bound' indicates max. # frames to process before break out.
6995 */
6996 /* WLC_HIGH_API */
6997 void BCMFASTPATH wlc_recv(struct wlc_info *wlc, struct sk_buff *p)
6998 {
6999 d11rxhdr_t *rxh;
7000 struct ieee80211_hdr *h;
7001 struct osl_info *osh;
7002 u16 fc;
7003 uint len;
7004 bool is_amsdu;
7005
7006 WL_TRACE("wl%d: wlc_recv\n", wlc->pub->unit);
7007
7008 osh = wlc->osh;
7009
7010 /* frame starts with rxhdr */
7011 rxh = (d11rxhdr_t *) (p->data);
7012
7013 /* strip off rxhdr */
7014 skb_pull(p, wlc->hwrxoff);
7015
7016 /* fixup rx header endianness */
7017 ltoh16_buf((void *)rxh, sizeof(d11rxhdr_t));
7018
7019 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7020 if (rxh->RxStatus1 & RXS_PBPRES) {
7021 if (p->len < 2) {
7022 WLCNTINCR(wlc->pub->_cnt->rxrunt);
7023 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7024 wlc->pub->unit, p->len);
7025 goto toss;
7026 }
7027 skb_pull(p, 2);
7028 }
7029
7030 h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN);
7031 len = p->len;
7032
7033 if (rxh->RxStatus1 & RXS_FCSERR) {
7034 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) {
7035 WL_ERROR("FCSERR while scanning******* - tossing\n");
7036 goto toss;
7037 } else {
7038 WL_ERROR("RCSERR!!!\n");
7039 goto toss;
7040 }
7041 }
7042
7043 /* check received pkt has at least frame control field */
7044 if (len >= D11_PHY_HDR_LEN + sizeof(h->frame_control)) {
7045 fc = ltoh16(h->frame_control);
7046 } else {
7047 WLCNTINCR(wlc->pub->_cnt->rxrunt);
7048 goto toss;
7049 }
7050
7051 is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK;
7052
7053 /* explicitly test bad src address to avoid sending bad deauth */
7054 if (!is_amsdu) {
7055 /* CTS and ACK CTL frames are w/o a2 */
7056 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
7057 (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
7058 if ((is_zero_ether_addr(h->addr2) ||
7059 is_multicast_ether_addr(h->addr2))) {
7060 WL_ERROR("wl%d: %s: dropping a frame with "
7061 "invalid src mac address, a2: %pM\n",
7062 wlc->pub->unit, __func__, h->addr2);
7063 WLCNTINCR(wlc->pub->_cnt->rxbadsrcmac);
7064 goto toss;
7065 }
7066 WLCNTINCR(wlc->pub->_cnt->rxfrag);
7067 }
7068 }
7069
7070 /* due to sheer numbers, toss out probe reqs for now */
7071 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
7072 if ((fc & FC_KIND_MASK) == FC_PROBE_REQ)
7073 goto toss;
7074 }
7075
7076 if (is_amsdu) {
7077 WL_ERROR("%s: is_amsdu causing toss\n", __func__);
7078 goto toss;
7079 }
7080
7081 wlc_recvctl(wlc, osh, rxh, p);
7082 return;
7083
7084 toss:
7085 pkt_buf_free_skb(osh, p, false);
7086 }
7087
7088 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7089 * number of bytes goes in the length field
7090 *
7091 * Formula given by HT PHY Spec v 1.13
7092 * len = 3(nsyms + nstream + 3) - 3
7093 */
7094 u16 BCMFASTPATH
7095 wlc_calc_lsig_len(struct wlc_info *wlc, ratespec_t ratespec, uint mac_len)
7096 {
7097 uint nsyms, len = 0, kNdps;
7098
7099 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7100 wlc->pub->unit, RSPEC2RATE(ratespec), mac_len);
7101
7102 if (IS_MCS(ratespec)) {
7103 uint mcs = ratespec & RSPEC_RATE_MASK;
7104 /* MCS_TXS(mcs) returns num tx streams - 1 */
7105 int tot_streams = (MCS_TXS(mcs) + 1) + RSPEC_STC(ratespec);
7106
7107 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7108 /* the payload duration calculation matches that of regular ofdm */
7109 /* 1000Ndbps = kbps * 4 */
7110 kNdps =
7111 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7112 RSPEC_ISSGI(ratespec)) * 4;
7113
7114 if (RSPEC_STC(ratespec) == 0)
7115 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7116 nsyms =
7117 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7118 APHY_TAIL_NBITS) * 1000, kNdps);
7119 else
7120 /* STBC needs to have even number of symbols */
7121 nsyms =
7122 2 *
7123 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7124 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7125
7126 nsyms += (tot_streams + 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7127 /* 3 bytes/symbol @ legacy 6Mbps rate */
7128 len = (3 * nsyms) - 3; /* (-3) excluding service bits and tail bits */
7129 }
7130
7131 return (u16) len;
7132 }
7133
7134 /* calculate frame duration of a given rate and length, return time in usec unit */
7135 uint BCMFASTPATH
7136 wlc_calc_frame_time(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7137 uint mac_len)
7138 {
7139 uint nsyms, dur = 0, Ndps, kNdps;
7140 uint rate = RSPEC2RATE(ratespec);
7141
7142 if (rate == 0) {
7143 ASSERT(0);
7144 WL_ERROR("wl%d: WAR: using rate of 1 mbps\n", wlc->pub->unit);
7145 rate = WLC_RATE_1M;
7146 }
7147
7148 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7149 wlc->pub->unit, ratespec, preamble_type, mac_len);
7150
7151 if (IS_MCS(ratespec)) {
7152 uint mcs = ratespec & RSPEC_RATE_MASK;
7153 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7154 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7155 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type));
7156
7157 dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7158 if (preamble_type == WLC_MM_PREAMBLE)
7159 dur += PREN_MM_EXT;
7160 /* 1000Ndbps = kbps * 4 */
7161 kNdps =
7162 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7163 RSPEC_ISSGI(ratespec)) * 4;
7164
7165 if (RSPEC_STC(ratespec) == 0)
7166 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7167 nsyms =
7168 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7169 APHY_TAIL_NBITS) * 1000, kNdps);
7170 else
7171 /* STBC needs to have even number of symbols */
7172 nsyms =
7173 2 *
7174 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7175 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7176
7177 dur += APHY_SYMBOL_TIME * nsyms;
7178 if (BAND_2G(wlc->band->bandtype))
7179 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7180 } else if (IS_OFDM(rate)) {
7181 dur = APHY_PREAMBLE_TIME;
7182 dur += APHY_SIGNAL_TIME;
7183 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7184 Ndps = rate * 2;
7185 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7186 nsyms =
7187 CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS),
7188 Ndps);
7189 dur += APHY_SYMBOL_TIME * nsyms;
7190 if (BAND_2G(wlc->band->bandtype))
7191 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7192 } else {
7193 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7194 mac_len = mac_len * 8 * 2;
7195 /* calc ceiling of bits/rate = microseconds of air time */
7196 dur = (mac_len + rate - 1) / rate;
7197 if (preamble_type & WLC_SHORT_PREAMBLE)
7198 dur += BPHY_PLCP_SHORT_TIME;
7199 else
7200 dur += BPHY_PLCP_TIME;
7201 }
7202 return dur;
7203 }
7204
7205 /* The opposite of wlc_calc_frame_time */
7206 static uint
7207 wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7208 uint dur)
7209 {
7210 uint nsyms, mac_len, Ndps, kNdps;
7211 uint rate = RSPEC2RATE(ratespec);
7212
7213 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7214 wlc->pub->unit, ratespec, preamble_type, dur);
7215
7216 if (IS_MCS(ratespec)) {
7217 uint mcs = ratespec & RSPEC_RATE_MASK;
7218 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7219 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7220 dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7221 /* payload calculation matches that of regular ofdm */
7222 if (BAND_2G(wlc->band->bandtype))
7223 dur -= DOT11_OFDM_SIGNAL_EXTENSION;
7224 /* kNdbps = kbps * 4 */
7225 kNdps =
7226 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7227 RSPEC_ISSGI(ratespec)) * 4;
7228 nsyms = dur / APHY_SYMBOL_TIME;
7229 mac_len =
7230 ((nsyms * kNdps) -
7231 ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000;
7232 } else if (IS_OFDM(ratespec)) {
7233 dur -= APHY_PREAMBLE_TIME;
7234 dur -= APHY_SIGNAL_TIME;
7235 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7236 Ndps = rate * 2;
7237 nsyms = dur / APHY_SYMBOL_TIME;
7238 mac_len =
7239 ((nsyms * Ndps) -
7240 (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8;
7241 } else {
7242 if (preamble_type & WLC_SHORT_PREAMBLE)
7243 dur -= BPHY_PLCP_SHORT_TIME;
7244 else
7245 dur -= BPHY_PLCP_TIME;
7246 mac_len = dur * rate;
7247 /* divide out factor of 2 in rate (1/2 mbps) */
7248 mac_len = mac_len / 8 / 2;
7249 }
7250 return mac_len;
7251 }
7252
7253 static uint
7254 wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7255 {
7256 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7257 wlc->pub->unit, rspec, preamble_type);
7258 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7259 * or equal to the rate of the immediately previous frame in the FES
7260 */
7261 rspec = WLC_BASIC_RATE(wlc, rspec);
7262 ASSERT(VALID_RATE_DBG(wlc, rspec));
7263
7264 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7265 return wlc_calc_frame_time(wlc, rspec, preamble_type,
7266 (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN +
7267 FCS_LEN));
7268 }
7269
7270 static uint BCMFASTPATH
7271 wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7272 {
7273 uint dur = 0;
7274
7275 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7276 wlc->pub->unit, rspec, preamble_type);
7277 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7278 * or equal to the rate of the immediately previous frame in the FES
7279 */
7280 rspec = WLC_BASIC_RATE(wlc, rspec);
7281 ASSERT(VALID_RATE_DBG(wlc, rspec));
7282
7283 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7284 dur =
7285 wlc_calc_frame_time(wlc, rspec, preamble_type,
7286 (DOT11_ACK_LEN + FCS_LEN));
7287 return dur;
7288 }
7289
7290 static uint
7291 wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7292 {
7293 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7294 wlc->pub->unit, rspec, preamble_type);
7295 return wlc_calc_ack_time(wlc, rspec, preamble_type);
7296 }
7297
7298 /* derive wlc->band->basic_rate[] table from 'rateset' */
7299 void wlc_rate_lookup_init(struct wlc_info *wlc, wlc_rateset_t *rateset)
7300 {
7301 u8 rate;
7302 u8 mandatory;
7303 u8 cck_basic = 0;
7304 u8 ofdm_basic = 0;
7305 u8 *br = wlc->band->basic_rate;
7306 uint i;
7307
7308 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7309 memset(br, 0, WLC_MAXRATE + 1);
7310
7311 /* For each basic rate in the rates list, make an entry in the
7312 * best basic lookup.
7313 */
7314 for (i = 0; i < rateset->count; i++) {
7315 /* only make an entry for a basic rate */
7316 if (!(rateset->rates[i] & WLC_RATE_FLAG))
7317 continue;
7318
7319 /* mask off basic bit */
7320 rate = (rateset->rates[i] & RATE_MASK);
7321
7322 if (rate > WLC_MAXRATE) {
7323 WL_ERROR("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n",
7324 rateset->rates[i]);
7325 continue;
7326 }
7327
7328 br[rate] = rate;
7329 }
7330
7331 /* The rate lookup table now has non-zero entries for each
7332 * basic rate, equal to the basic rate: br[basicN] = basicN
7333 *
7334 * To look up the best basic rate corresponding to any
7335 * particular rate, code can use the basic_rate table
7336 * like this
7337 *
7338 * basic_rate = wlc->band->basic_rate[tx_rate]
7339 *
7340 * Make sure there is a best basic rate entry for
7341 * every rate by walking up the table from low rates
7342 * to high, filling in holes in the lookup table
7343 */
7344
7345 for (i = 0; i < wlc->band->hw_rateset.count; i++) {
7346 rate = wlc->band->hw_rateset.rates[i];
7347 ASSERT(rate <= WLC_MAXRATE);
7348
7349 if (br[rate] != 0) {
7350 /* This rate is a basic rate.
7351 * Keep track of the best basic rate so far by
7352 * modulation type.
7353 */
7354 if (IS_OFDM(rate))
7355 ofdm_basic = rate;
7356 else
7357 cck_basic = rate;
7358
7359 continue;
7360 }
7361
7362 /* This rate is not a basic rate so figure out the
7363 * best basic rate less than this rate and fill in
7364 * the hole in the table
7365 */
7366
7367 br[rate] = IS_OFDM(rate) ? ofdm_basic : cck_basic;
7368
7369 if (br[rate] != 0)
7370 continue;
7371
7372 if (IS_OFDM(rate)) {
7373 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7374 if (rate >= WLC_RATE_24M)
7375 mandatory = WLC_RATE_24M;
7376 else if (rate >= WLC_RATE_12M)
7377 mandatory = WLC_RATE_12M;
7378 else
7379 mandatory = WLC_RATE_6M;
7380 } else {
7381 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7382 mandatory = rate;
7383 }
7384
7385 br[rate] = mandatory;
7386 }
7387 }
7388
7389 static void wlc_write_rate_shm(struct wlc_info *wlc, u8 rate, u8 basic_rate)
7390 {
7391 u8 phy_rate, index;
7392 u8 basic_phy_rate, basic_index;
7393 u16 dir_table, basic_table;
7394 u16 basic_ptr;
7395
7396 /* Shared memory address for the table we are reading */
7397 dir_table = IS_OFDM(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B;
7398
7399 /* Shared memory address for the table we are writing */
7400 basic_table = IS_OFDM(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B;
7401
7402 /*
7403 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7404 * the index into the rate table.
7405 */
7406 phy_rate = rate_info[rate] & RATE_MASK;
7407 basic_phy_rate = rate_info[basic_rate] & RATE_MASK;
7408 index = phy_rate & 0xf;
7409 basic_index = basic_phy_rate & 0xf;
7410
7411 /* Find the SHM pointer to the ACK rate entry by looking in the
7412 * Direct-map Table
7413 */
7414 basic_ptr = wlc_read_shm(wlc, (dir_table + basic_index * 2));
7415
7416 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7417 * to the correct basic rate for the given incoming rate
7418 */
7419 wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr);
7420 }
7421
7422 static const wlc_rateset_t *wlc_rateset_get_hwrs(struct wlc_info *wlc)
7423 {
7424 const wlc_rateset_t *rs_dflt;
7425
7426 if (WLC_PHY_11N_CAP(wlc->band)) {
7427 if (BAND_5G(wlc->band->bandtype))
7428 rs_dflt = &ofdm_mimo_rates;
7429 else
7430 rs_dflt = &cck_ofdm_mimo_rates;
7431 } else if (wlc->band->gmode)
7432 rs_dflt = &cck_ofdm_rates;
7433 else
7434 rs_dflt = &cck_rates;
7435
7436 return rs_dflt;
7437 }
7438
7439 void wlc_set_ratetable(struct wlc_info *wlc)
7440 {
7441 const wlc_rateset_t *rs_dflt;
7442 wlc_rateset_t rs;
7443 u8 rate, basic_rate;
7444 uint i;
7445
7446 rs_dflt = wlc_rateset_get_hwrs(wlc);
7447 ASSERT(rs_dflt != NULL);
7448
7449 wlc_rateset_copy(rs_dflt, &rs);
7450 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7451
7452 /* walk the phy rate table and update SHM basic rate lookup table */
7453 for (i = 0; i < rs.count; i++) {
7454 rate = rs.rates[i] & RATE_MASK;
7455
7456 /* for a given rate WLC_BASIC_RATE returns the rate at
7457 * which a response ACK/CTS should be sent.
7458 */
7459 basic_rate = WLC_BASIC_RATE(wlc, rate);
7460 if (basic_rate == 0) {
7461 /* This should only happen if we are using a
7462 * restricted rateset.
7463 */
7464 basic_rate = rs.rates[0] & RATE_MASK;
7465 }
7466
7467 wlc_write_rate_shm(wlc, rate, basic_rate);
7468 }
7469 }
7470
7471 /*
7472 * Return true if the specified rate is supported by the specified band.
7473 * WLC_BAND_AUTO indicates the current band.
7474 */
7475 bool wlc_valid_rate(struct wlc_info *wlc, ratespec_t rspec, int band,
7476 bool verbose)
7477 {
7478 wlc_rateset_t *hw_rateset;
7479 uint i;
7480
7481 if ((band == WLC_BAND_AUTO) || (band == wlc->band->bandtype)) {
7482 hw_rateset = &wlc->band->hw_rateset;
7483 } else if (NBANDS(wlc) > 1) {
7484 hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset;
7485 } else {
7486 /* other band specified and we are a single band device */
7487 return false;
7488 }
7489
7490 /* check if this is a mimo rate */
7491 if (IS_MCS(rspec)) {
7492 if (!VALID_MCS((rspec & RSPEC_RATE_MASK)))
7493 goto error;
7494
7495 return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK));
7496 }
7497
7498 for (i = 0; i < hw_rateset->count; i++)
7499 if (hw_rateset->rates[i] == RSPEC2RATE(rspec))
7500 return true;
7501 error:
7502 if (verbose) {
7503 WL_ERROR("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n",
7504 wlc->pub->unit, rspec);
7505 }
7506
7507 return false;
7508 }
7509
7510 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap)
7511 {
7512 uint i;
7513 struct wlcband *band;
7514
7515 for (i = 0; i < NBANDS(wlc); i++) {
7516 if (IS_SINGLEBAND_5G(wlc->deviceid))
7517 i = BAND_5G_INDEX;
7518 band = wlc->bandstate[i];
7519 if (band->bandtype == WLC_BAND_5G) {
7520 if ((bwcap == WLC_N_BW_40ALL)
7521 || (bwcap == WLC_N_BW_20IN2G_40IN5G))
7522 band->mimo_cap_40 = true;
7523 else
7524 band->mimo_cap_40 = false;
7525 } else {
7526 ASSERT(band->bandtype == WLC_BAND_2G);
7527 if (bwcap == WLC_N_BW_40ALL)
7528 band->mimo_cap_40 = true;
7529 else
7530 band->mimo_cap_40 = false;
7531 }
7532 }
7533
7534 wlc->mimo_band_bwcap = bwcap;
7535 }
7536
7537 void wlc_mod_prb_rsp_rate_table(struct wlc_info *wlc, uint frame_len)
7538 {
7539 const wlc_rateset_t *rs_dflt;
7540 wlc_rateset_t rs;
7541 u8 rate;
7542 u16 entry_ptr;
7543 u8 plcp[D11_PHY_HDR_LEN];
7544 u16 dur, sifs;
7545 uint i;
7546
7547 sifs = SIFS(wlc->band);
7548
7549 rs_dflt = wlc_rateset_get_hwrs(wlc);
7550 ASSERT(rs_dflt != NULL);
7551
7552 wlc_rateset_copy(rs_dflt, &rs);
7553 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7554
7555 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7556 for (i = 0; i < rs.count; i++) {
7557 rate = rs.rates[i] & RATE_MASK;
7558
7559 entry_ptr = wlc_rate_shm_offset(wlc, rate);
7560
7561 /* Calculate the Probe Response PLCP for the given rate */
7562 wlc_compute_plcp(wlc, rate, frame_len, plcp);
7563
7564 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7565 dur =
7566 (u16) wlc_calc_frame_time(wlc, rate, WLC_LONG_PREAMBLE,
7567 frame_len);
7568 dur += sifs;
7569
7570 /* Update the SHM Rate Table entry Probe Response values */
7571 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS,
7572 (u16) (plcp[0] + (plcp[1] << 8)));
7573 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS + 2,
7574 (u16) (plcp[2] + (plcp[3] << 8)));
7575 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_DUR_POS, dur);
7576 }
7577 }
7578
7579 u16
7580 wlc_compute_bcntsfoff(struct wlc_info *wlc, ratespec_t rspec,
7581 bool short_preamble, bool phydelay)
7582 {
7583 uint bcntsfoff = 0;
7584
7585 if (IS_MCS(rspec)) {
7586 WL_ERROR("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7587 wlc->pub->unit, rspec);
7588 } else if (IS_OFDM(rspec)) {
7589 /* tx delay from MAC through phy to air (2.1 usec) +
7590 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7591 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7592 * bytes at beacon rate)
7593 */
7594 bcntsfoff += phydelay ? D11A_PHY_TX_DELAY : 0;
7595 bcntsfoff += APHY_PREAMBLE_TIME + APHY_SIGNAL_TIME;
7596 bcntsfoff +=
7597 wlc_compute_airtime(wlc, rspec,
7598 APHY_SERVICE_NBITS / 8 +
7599 DOT11_MAC_HDR_LEN);
7600 } else {
7601 /* tx delay from MAC through phy to air (3.4 usec) +
7602 * phy header time (long preamble + PLCP == 192 usec) +
7603 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7604 */
7605 bcntsfoff += phydelay ? D11B_PHY_TX_DELAY : 0;
7606 bcntsfoff +=
7607 short_preamble ? D11B_PHY_SPREHDR_TIME :
7608 D11B_PHY_LPREHDR_TIME;
7609 bcntsfoff += wlc_compute_airtime(wlc, rspec, DOT11_MAC_HDR_LEN);
7610 }
7611 return (u16) (bcntsfoff);
7612 }
7613
7614 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7615 *
7616 * PLCP header is 6 bytes.
7617 * 802.11 A3 header is 24 bytes.
7618 * Max beacon frame body template length is 112 bytes.
7619 * Max probe resp frame body template length is 110 bytes.
7620 *
7621 * *len on input contains the max length of the packet available.
7622 *
7623 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7624 * and included up to, but not including, the 4 byte FCS.
7625 */
7626 static void
7627 wlc_bcn_prb_template(struct wlc_info *wlc, uint type, ratespec_t bcn_rspec,
7628 wlc_bsscfg_t *cfg, u16 *buf, int *len)
7629 {
7630 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
7631 cck_phy_hdr_t *plcp;
7632 struct ieee80211_mgmt *h;
7633 int hdr_len, body_len;
7634
7635 ASSERT(*len >= 142);
7636 ASSERT(type == FC_BEACON || type == FC_PROBE_RESP);
7637
7638 if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON)
7639 hdr_len = DOT11_MAC_HDR_LEN;
7640 else
7641 hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN;
7642 body_len = *len - hdr_len; /* calc buffer size provided for frame body */
7643
7644 *len = hdr_len + body_len; /* return actual size */
7645
7646 /* format PHY and MAC headers */
7647 memset((char *)buf, 0, hdr_len);
7648
7649 plcp = (cck_phy_hdr_t *) buf;
7650
7651 /* PLCP for Probe Response frames are filled in from core's rate table */
7652 if (type == FC_BEACON && !MBSS_BCN_ENAB(cfg)) {
7653 /* fill in PLCP */
7654 wlc_compute_plcp(wlc, bcn_rspec,
7655 (DOT11_MAC_HDR_LEN + body_len + FCS_LEN),
7656 (u8 *) plcp);
7657
7658 }
7659 /* "Regular" and 16 MBSS but not for 4 MBSS */
7660 /* Update the phytxctl for the beacon based on the rspec */
7661 if (!SOFTBCN_ENAB(cfg))
7662 wlc_beacon_phytxctl_txant_upd(wlc, bcn_rspec);
7663
7664 if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON)
7665 h = (struct ieee80211_mgmt *)&plcp[0];
7666 else
7667 h = (struct ieee80211_mgmt *)&plcp[1];
7668
7669 /* fill in 802.11 header */
7670 h->frame_control = htol16((u16) type);
7671
7672 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7673 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7674 if (type == FC_BEACON)
7675 bcopy((const char *)&ether_bcast, (char *)&h->da,
7676 ETH_ALEN);
7677 bcopy((char *)&cfg->cur_etheraddr, (char *)&h->sa, ETH_ALEN);
7678 bcopy((char *)&cfg->BSSID, (char *)&h->bssid, ETH_ALEN);
7679
7680 /* SEQ filled in by MAC */
7681
7682 return;
7683 }
7684
7685 int wlc_get_header_len()
7686 {
7687 return TXOFF;
7688 }
7689
7690 /* Update a beacon for a particular BSS
7691 * For MBSS, this updates the software template and sets "latest" to the index of the
7692 * template updated.
7693 * Otherwise, it updates the hardware template.
7694 */
7695 void wlc_bss_update_beacon(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7696 {
7697 int len = BCN_TMPL_LEN;
7698
7699 /* Clear the soft intmask */
7700 wlc->defmacintmask &= ~MI_BCNTPL;
7701
7702 if (!cfg->up) { /* Only allow updates on an UP bss */
7703 return;
7704 }
7705
7706 if (MBSS_BCN_ENAB(cfg)) { /* Optimize: Some of if/else could be combined */
7707 } else if (HWBCN_ENAB(cfg)) { /* Hardware beaconing for this config */
7708 u16 bcn[BCN_TMPL_LEN / 2];
7709 u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
7710 d11regs_t *regs = wlc->regs;
7711 struct osl_info *osh = NULL;
7712
7713 osh = wlc->osh;
7714
7715 /* Check if both templates are in use, if so sched. an interrupt
7716 * that will call back into this routine
7717 */
7718 if ((R_REG(osh, &regs->maccommand) & both_valid) == both_valid) {
7719 /* clear any previous status */
7720 W_REG(osh, &regs->macintstatus, MI_BCNTPL);
7721 }
7722 /* Check that after scheduling the interrupt both of the
7723 * templates are still busy. if not clear the int. & remask
7724 */
7725 if ((R_REG(osh, &regs->maccommand) & both_valid) == both_valid) {
7726 wlc->defmacintmask |= MI_BCNTPL;
7727 return;
7728 }
7729
7730 wlc->bcn_rspec =
7731 wlc_lowest_basic_rspec(wlc, &cfg->current_bss->rateset);
7732 ASSERT(wlc_valid_rate
7733 (wlc, wlc->bcn_rspec,
7734 CHSPEC_IS2G(cfg->current_bss->
7735 chanspec) ? WLC_BAND_2G : WLC_BAND_5G,
7736 true));
7737
7738 /* update the template and ucode shm */
7739 wlc_bcn_prb_template(wlc, FC_BEACON, wlc->bcn_rspec, cfg, bcn,
7740 &len);
7741 wlc_write_hw_bcntemplates(wlc, bcn, len, false);
7742 }
7743 }
7744
7745 /*
7746 * Update all beacons for the system.
7747 */
7748 void wlc_update_beacon(struct wlc_info *wlc)
7749 {
7750 int idx;
7751 wlc_bsscfg_t *bsscfg;
7752
7753 /* update AP or IBSS beacons */
7754 FOREACH_BSS(wlc, idx, bsscfg) {
7755 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7756 wlc_bss_update_beacon(wlc, bsscfg);
7757 }
7758 }
7759
7760 /* Write ssid into shared memory */
7761 void wlc_shm_ssid_upd(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7762 {
7763 u8 *ssidptr = cfg->SSID;
7764 u16 base = M_SSID;
7765 u8 ssidbuf[IEEE80211_MAX_SSID_LEN];
7766
7767 /* padding the ssid with zero and copy it into shm */
7768 memset(ssidbuf, 0, IEEE80211_MAX_SSID_LEN);
7769 bcopy(ssidptr, ssidbuf, cfg->SSID_len);
7770
7771 wlc_copyto_shm(wlc, base, ssidbuf, IEEE80211_MAX_SSID_LEN);
7772
7773 if (!MBSS_BCN_ENAB(cfg))
7774 wlc_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len);
7775 }
7776
7777 void wlc_update_probe_resp(struct wlc_info *wlc, bool suspend)
7778 {
7779 int idx;
7780 wlc_bsscfg_t *bsscfg;
7781
7782 /* update AP or IBSS probe responses */
7783 FOREACH_BSS(wlc, idx, bsscfg) {
7784 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7785 wlc_bss_update_probe_resp(wlc, bsscfg, suspend);
7786 }
7787 }
7788
7789 void
7790 wlc_bss_update_probe_resp(struct wlc_info *wlc, wlc_bsscfg_t *cfg, bool suspend)
7791 {
7792 u16 prb_resp[BCN_TMPL_LEN / 2];
7793 int len = BCN_TMPL_LEN;
7794
7795 /* write the probe response to hardware, or save in the config structure */
7796 if (!MBSS_PRB_ENAB(cfg)) {
7797
7798 /* create the probe response template */
7799 wlc_bcn_prb_template(wlc, FC_PROBE_RESP, 0, cfg, prb_resp,
7800 &len);
7801
7802 if (suspend)
7803 wlc_suspend_mac_and_wait(wlc);
7804
7805 /* write the probe response into the template region */
7806 wlc_bmac_write_template_ram(wlc->hw, T_PRS_TPL_BASE,
7807 (len + 3) & ~3, prb_resp);
7808
7809 /* write the length of the probe response frame (+PLCP/-FCS) */
7810 wlc_write_shm(wlc, M_PRB_RESP_FRM_LEN, (u16) len);
7811
7812 /* write the SSID and SSID length */
7813 wlc_shm_ssid_upd(wlc, cfg);
7814
7815 /*
7816 * Write PLCP headers and durations for probe response frames at all rates.
7817 * Use the actual frame length covered by the PLCP header for the call to
7818 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7819 */
7820 len += (-D11_PHY_HDR_LEN + FCS_LEN);
7821 wlc_mod_prb_rsp_rate_table(wlc, (u16) len);
7822
7823 if (suspend)
7824 wlc_enable_mac(wlc);
7825 } else { /* Generating probe resp in sw; update local template */
7826 ASSERT(0 && "No software probe response support without MBSS");
7827 }
7828 }
7829
7830 /* prepares pdu for transmission. returns BCM error codes */
7831 int wlc_prep_pdu(struct wlc_info *wlc, struct sk_buff *pdu, uint *fifop)
7832 {
7833 struct osl_info *osh;
7834 uint fifo;
7835 d11txh_t *txh;
7836 struct ieee80211_hdr *h;
7837 struct scb *scb;
7838 u16 fc;
7839
7840 osh = wlc->osh;
7841
7842 ASSERT(pdu);
7843 txh = (d11txh_t *) (pdu->data);
7844 ASSERT(txh);
7845 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
7846 ASSERT(h);
7847 fc = ltoh16(h->frame_control);
7848
7849 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7850 fifo = ltoh16(txh->TxFrameID) & TXFID_QUEUE_MASK;
7851
7852 scb = NULL;
7853
7854 *fifop = fifo;
7855
7856 /* return if insufficient dma resources */
7857 if (TXAVAIL(wlc, fifo) < MAX_DMA_SEGS) {
7858 /* Mark precedences related to this FIFO, unsendable */
7859 WLC_TX_FIFO_CLEAR(wlc, fifo);
7860 return BCME_BUSY;
7861 }
7862
7863 if ((ltoh16(txh->MacFrameControl) & IEEE80211_FCTL_FTYPE) !=
7864 IEEE80211_FTYPE_DATA)
7865 WLCNTINCR(wlc->pub->_cnt->txctl);
7866
7867 return 0;
7868 }
7869
7870 /* init tx reported rate mechanism */
7871 void wlc_reprate_init(struct wlc_info *wlc)
7872 {
7873 int i;
7874 wlc_bsscfg_t *bsscfg;
7875
7876 FOREACH_BSS(wlc, i, bsscfg) {
7877 wlc_bsscfg_reprate_init(bsscfg);
7878 }
7879 }
7880
7881 /* per bsscfg init tx reported rate mechanism */
7882 void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg)
7883 {
7884 bsscfg->txrspecidx = 0;
7885 memset((char *)bsscfg->txrspec, 0, sizeof(bsscfg->txrspec));
7886 }
7887
7888 /* Retrieve a consolidated set of revision information,
7889 * typically for the WLC_GET_REVINFO ioctl
7890 */
7891 int wlc_get_revision_info(struct wlc_info *wlc, void *buf, uint len)
7892 {
7893 wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf;
7894
7895 if (len < WL_REV_INFO_LEGACY_LENGTH)
7896 return BCME_BUFTOOSHORT;
7897
7898 rinfo->vendorid = wlc->vendorid;
7899 rinfo->deviceid = wlc->deviceid;
7900 rinfo->radiorev = (wlc->band->radiorev << IDCODE_REV_SHIFT) |
7901 (wlc->band->radioid << IDCODE_ID_SHIFT);
7902 rinfo->chiprev = wlc->pub->sih->chiprev;
7903 rinfo->corerev = wlc->pub->corerev;
7904 rinfo->boardid = wlc->pub->sih->boardtype;
7905 rinfo->boardvendor = wlc->pub->sih->boardvendor;
7906 rinfo->boardrev = wlc->pub->boardrev;
7907 rinfo->ucoderev = wlc->ucode_rev;
7908 rinfo->driverrev = EPI_VERSION_NUM;
7909 rinfo->bus = wlc->pub->sih->bustype;
7910 rinfo->chipnum = wlc->pub->sih->chip;
7911
7912 if (len >= (offsetof(wlc_rev_info_t, chippkg))) {
7913 rinfo->phytype = wlc->band->phytype;
7914 rinfo->phyrev = wlc->band->phyrev;
7915 rinfo->anarev = 0; /* obsolete stuff, suppress */
7916 }
7917
7918 if (len >= sizeof(*rinfo)) {
7919 rinfo->chippkg = wlc->pub->sih->chippkg;
7920 }
7921
7922 return BCME_OK;
7923 }
7924
7925 void wlc_default_rateset(struct wlc_info *wlc, wlc_rateset_t *rs)
7926 {
7927 wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype,
7928 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
7929 CHSPEC_WLC_BW(wlc->default_bss->chanspec),
7930 wlc->stf->txstreams);
7931 }
7932
7933 static void wlc_bss_default_init(struct wlc_info *wlc)
7934 {
7935 chanspec_t chanspec;
7936 struct wlcband *band;
7937 wlc_bss_info_t *bi = wlc->default_bss;
7938
7939 /* init default and target BSS with some sane initial values */
7940 memset((char *)(bi), 0, sizeof(wlc_bss_info_t));
7941 bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT :
7942 BEACON_INTERVAL_DEFAULT;
7943 bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT :
7944 DTIM_INTERVAL_DEFAULT;
7945
7946 /* fill the default channel as the first valid channel
7947 * starting from the 2G channels
7948 */
7949 chanspec = CH20MHZ_CHSPEC(1);
7950 ASSERT(chanspec != INVCHANSPEC);
7951
7952 wlc->home_chanspec = bi->chanspec = chanspec;
7953
7954 /* find the band of our default channel */
7955 band = wlc->band;
7956 if (NBANDS(wlc) > 1 && band->bandunit != CHSPEC_WLCBANDUNIT(chanspec))
7957 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
7958
7959 /* init bss rates to the band specific default rate set */
7960 wlc_rateset_default(&bi->rateset, NULL, band->phytype, band->bandtype,
7961 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
7962 CHSPEC_WLC_BW(chanspec), wlc->stf->txstreams);
7963
7964 if (N_ENAB(wlc->pub))
7965 bi->flags |= WLC_BSS_HT;
7966 }
7967
7968 /* Deferred event processing */
7969 static void wlc_process_eventq(void *arg)
7970 {
7971 struct wlc_info *wlc = (struct wlc_info *) arg;
7972 wlc_event_t *etmp;
7973
7974 while ((etmp = wlc_eventq_deq(wlc->eventq))) {
7975 /* Perform OS specific event processing */
7976 wl_event(wlc->wl, etmp->event.ifname, etmp);
7977 if (etmp->data) {
7978 kfree(etmp->data);
7979 etmp->data = NULL;
7980 }
7981 wlc_event_free(wlc->eventq, etmp);
7982 }
7983 }
7984
7985 void
7986 wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high, u32 b_low)
7987 {
7988 if (b_low > *a_low) {
7989 /* low half needs a carry */
7990 b_high += 1;
7991 }
7992 *a_low -= b_low;
7993 *a_high -= b_high;
7994 }
7995
7996 static ratespec_t
7997 mac80211_wlc_set_nrate(struct wlc_info *wlc, struct wlcband *cur_band,
7998 u32 int_val)
7999 {
8000 u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT;
8001 u8 rate = int_val & NRATE_RATE_MASK;
8002 ratespec_t rspec;
8003 bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE);
8004 bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT);
8005 bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY)
8006 == NRATE_OVERRIDE_MCS_ONLY);
8007 int bcmerror = 0;
8008
8009 if (!ismcs) {
8010 return (ratespec_t) rate;
8011 }
8012
8013 /* validate the combination of rate/mcs/stf is allowed */
8014 if (N_ENAB(wlc->pub) && ismcs) {
8015 /* mcs only allowed when nmode */
8016 if (stf > PHY_TXC1_MODE_SDM) {
8017 WL_ERROR("wl%d: %s: Invalid stf\n",
8018 WLCWLUNIT(wlc), __func__);
8019 bcmerror = BCME_RANGE;
8020 goto done;
8021 }
8022
8023 /* mcs 32 is a special case, DUP mode 40 only */
8024 if (rate == 32) {
8025 if (!CHSPEC_IS40(wlc->home_chanspec) ||
8026 ((stf != PHY_TXC1_MODE_SISO)
8027 && (stf != PHY_TXC1_MODE_CDD))) {
8028 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8029 WLCWLUNIT(wlc), __func__);
8030 bcmerror = BCME_RANGE;
8031 goto done;
8032 }
8033 /* mcs > 7 must use stf SDM */
8034 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) {
8035 /* mcs > 7 must use stf SDM */
8036 if (stf != PHY_TXC1_MODE_SDM) {
8037 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8038 WLCWLUNIT(wlc), __func__, rate);
8039 stf = PHY_TXC1_MODE_SDM;
8040 }
8041 } else {
8042 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8043 if ((stf > PHY_TXC1_MODE_STBC) ||
8044 (!WLC_STBC_CAP_PHY(wlc)
8045 && (stf == PHY_TXC1_MODE_STBC))) {
8046 WL_ERROR("wl%d: %s: Invalid STBC\n",
8047 WLCWLUNIT(wlc), __func__);
8048 bcmerror = BCME_RANGE;
8049 goto done;
8050 }
8051 }
8052 } else if (IS_OFDM(rate)) {
8053 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
8054 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8055 WLCWLUNIT(wlc), __func__);
8056 bcmerror = BCME_RANGE;
8057 goto done;
8058 }
8059 } else if (IS_CCK(rate)) {
8060 if ((cur_band->bandtype != WLC_BAND_2G)
8061 || (stf != PHY_TXC1_MODE_SISO)) {
8062 WL_ERROR("wl%d: %s: Invalid CCK\n",
8063 WLCWLUNIT(wlc), __func__);
8064 bcmerror = BCME_RANGE;
8065 goto done;
8066 }
8067 } else {
8068 WL_ERROR("wl%d: %s: Unknown rate type\n",
8069 WLCWLUNIT(wlc), __func__);
8070 bcmerror = BCME_RANGE;
8071 goto done;
8072 }
8073 /* make sure multiple antennae are available for non-siso rates */
8074 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
8075 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8076 WLCWLUNIT(wlc), __func__);
8077 bcmerror = BCME_RANGE;
8078 goto done;
8079 }
8080
8081 rspec = rate;
8082 if (ismcs) {
8083 rspec |= RSPEC_MIMORATE;
8084 /* For STBC populate the STC field of the ratespec */
8085 if (stf == PHY_TXC1_MODE_STBC) {
8086 u8 stc;
8087 stc = 1; /* Nss for single stream is always 1 */
8088 rspec |= (stc << RSPEC_STC_SHIFT);
8089 }
8090 }
8091
8092 rspec |= (stf << RSPEC_STF_SHIFT);
8093
8094 if (override_mcs_only)
8095 rspec |= RSPEC_OVERRIDE_MCS_ONLY;
8096
8097 if (issgi)
8098 rspec |= RSPEC_SHORT_GI;
8099
8100 if ((rate != 0)
8101 && !wlc_valid_rate(wlc, rspec, cur_band->bandtype, true)) {
8102 return rate;
8103 }
8104
8105 return rspec;
8106 done:
8107 WL_ERROR("Hoark\n");
8108 return rate;
8109 }
8110
8111 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8112 static int
8113 wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
8114 bool writeToShm)
8115 {
8116 int idle_busy_ratio_x_16 = 0;
8117 uint offset =
8118 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM :
8119 M_TX_IDLE_BUSY_RATIO_X_16_CCK;
8120 if (duty_cycle > 100 || duty_cycle < 0) {
8121 WL_ERROR("wl%d: duty cycle value off limit\n", wlc->pub->unit);
8122 return BCME_RANGE;
8123 }
8124 if (duty_cycle)
8125 idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle;
8126 /* Only write to shared memory when wl is up */
8127 if (writeToShm)
8128 wlc_write_shm(wlc, offset, (u16) idle_busy_ratio_x_16);
8129
8130 if (isOFDM)
8131 wlc->tx_duty_cycle_ofdm = (u16) duty_cycle;
8132 else
8133 wlc->tx_duty_cycle_cck = (u16) duty_cycle;
8134
8135 return BCME_OK;
8136 }
8137
8138 /* Read a single u16 from shared memory.
8139 * SHM 'offset' needs to be an even address
8140 */
8141 u16 wlc_read_shm(struct wlc_info *wlc, uint offset)
8142 {
8143 return wlc_bmac_read_shm(wlc->hw, offset);
8144 }
8145
8146 /* Write a single u16 to shared memory.
8147 * SHM 'offset' needs to be an even address
8148 */
8149 void wlc_write_shm(struct wlc_info *wlc, uint offset, u16 v)
8150 {
8151 wlc_bmac_write_shm(wlc->hw, offset, v);
8152 }
8153
8154 /* Set a range of shared memory to a value.
8155 * SHM 'offset' needs to be an even address and
8156 * Range length 'len' must be an even number of bytes
8157 */
8158 void wlc_set_shm(struct wlc_info *wlc, uint offset, u16 v, int len)
8159 {
8160 /* offset and len need to be even */
8161 ASSERT((offset & 1) == 0);
8162 ASSERT((len & 1) == 0);
8163
8164 if (len <= 0)
8165 return;
8166
8167 wlc_bmac_set_shm(wlc->hw, offset, v, len);
8168 }
8169
8170 /* Copy a buffer to shared memory.
8171 * SHM 'offset' needs to be an even address and
8172 * Buffer length 'len' must be an even number of bytes
8173 */
8174 void wlc_copyto_shm(struct wlc_info *wlc, uint offset, const void *buf, int len)
8175 {
8176 /* offset and len need to be even */
8177 ASSERT((offset & 1) == 0);
8178 ASSERT((len & 1) == 0);
8179
8180 if (len <= 0)
8181 return;
8182 wlc_bmac_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8183
8184 }
8185
8186 /* Copy from shared memory to a buffer.
8187 * SHM 'offset' needs to be an even address and
8188 * Buffer length 'len' must be an even number of bytes
8189 */
8190 void wlc_copyfrom_shm(struct wlc_info *wlc, uint offset, void *buf, int len)
8191 {
8192 /* offset and len need to be even */
8193 ASSERT((offset & 1) == 0);
8194 ASSERT((len & 1) == 0);
8195
8196 if (len <= 0)
8197 return;
8198
8199 wlc_bmac_copyfrom_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8200 }
8201
8202 /* wrapper BMAC functions to for HIGH driver access */
8203 void wlc_mctrl(struct wlc_info *wlc, u32 mask, u32 val)
8204 {
8205 wlc_bmac_mctrl(wlc->hw, mask, val);
8206 }
8207
8208 void wlc_corereset(struct wlc_info *wlc, u32 flags)
8209 {
8210 wlc_bmac_corereset(wlc->hw, flags);
8211 }
8212
8213 void wlc_mhf(struct wlc_info *wlc, u8 idx, u16 mask, u16 val, int bands)
8214 {
8215 wlc_bmac_mhf(wlc->hw, idx, mask, val, bands);
8216 }
8217
8218 u16 wlc_mhf_get(struct wlc_info *wlc, u8 idx, int bands)
8219 {
8220 return wlc_bmac_mhf_get(wlc->hw, idx, bands);
8221 }
8222
8223 int wlc_xmtfifo_sz_get(struct wlc_info *wlc, uint fifo, uint *blocks)
8224 {
8225 return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks);
8226 }
8227
8228 void wlc_write_template_ram(struct wlc_info *wlc, int offset, int len,
8229 void *buf)
8230 {
8231 wlc_bmac_write_template_ram(wlc->hw, offset, len, buf);
8232 }
8233
8234 void wlc_write_hw_bcntemplates(struct wlc_info *wlc, void *bcn, int len,
8235 bool both)
8236 {
8237 wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both);
8238 }
8239
8240 void
8241 wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
8242 const u8 *addr)
8243 {
8244 wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr);
8245 }
8246
8247 void wlc_set_rcmta(struct wlc_info *wlc, int idx, const u8 *addr)
8248 {
8249 wlc_bmac_set_rcmta(wlc->hw, idx, addr);
8250 }
8251
8252 void wlc_read_tsf(struct wlc_info *wlc, u32 *tsf_l_ptr, u32 *tsf_h_ptr)
8253 {
8254 wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr);
8255 }
8256
8257 void wlc_set_cwmin(struct wlc_info *wlc, u16 newmin)
8258 {
8259 wlc->band->CWmin = newmin;
8260 wlc_bmac_set_cwmin(wlc->hw, newmin);
8261 }
8262
8263 void wlc_set_cwmax(struct wlc_info *wlc, u16 newmax)
8264 {
8265 wlc->band->CWmax = newmax;
8266 wlc_bmac_set_cwmax(wlc->hw, newmax);
8267 }
8268
8269 void wlc_fifoerrors(struct wlc_info *wlc)
8270 {
8271
8272 wlc_bmac_fifoerrors(wlc->hw);
8273 }
8274
8275 /* Search mem rw utilities */
8276
8277 void wlc_pllreq(struct wlc_info *wlc, bool set, mbool req_bit)
8278 {
8279 wlc_bmac_pllreq(wlc->hw, set, req_bit);
8280 }
8281
8282 void wlc_reset_bmac_done(struct wlc_info *wlc)
8283 {
8284 }
8285
8286 void wlc_ht_mimops_cap_update(struct wlc_info *wlc, u8 mimops_mode)
8287 {
8288 wlc->ht_cap.cap_info &= ~HT_CAP_MIMO_PS_MASK;
8289 wlc->ht_cap.cap_info |= (mimops_mode << IEEE80211_HT_CAP_SM_PS_SHIFT);
8290
8291 if (AP_ENAB(wlc->pub) && wlc->clk) {
8292 wlc_update_beacon(wlc);
8293 wlc_update_probe_resp(wlc, true);
8294 }
8295 }
8296
8297 /* check for the particular priority flow control bit being set */
8298 bool
8299 wlc_txflowcontrol_prio_isset(struct wlc_info *wlc, wlc_txq_info_t *q, int prio)
8300 {
8301 uint prio_mask;
8302
8303 if (prio == ALLPRIO) {
8304 prio_mask = TXQ_STOP_FOR_PRIOFC_MASK;
8305 } else {
8306 ASSERT(prio >= 0 && prio <= MAXPRIO);
8307 prio_mask = NBITVAL(prio);
8308 }
8309
8310 return (q->stopped & prio_mask) == prio_mask;
8311 }
8312
8313 /* propogate the flow control to all interfaces using the given tx queue */
8314 void wlc_txflowcontrol(struct wlc_info *wlc, wlc_txq_info_t *qi,
8315 bool on, int prio)
8316 {
8317 uint prio_bits;
8318 uint cur_bits;
8319
8320 WL_ERROR("%s: flow control kicks in\n", __func__);
8321
8322 if (prio == ALLPRIO) {
8323 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK;
8324 } else {
8325 ASSERT(prio >= 0 && prio <= MAXPRIO);
8326 prio_bits = NBITVAL(prio);
8327 }
8328
8329 cur_bits = qi->stopped & prio_bits;
8330
8331 /* Check for the case of no change and return early
8332 * Otherwise update the bit and continue
8333 */
8334 if (on) {
8335 if (cur_bits == prio_bits) {
8336 return;
8337 }
8338 mboolset(qi->stopped, prio_bits);
8339 } else {
8340 if (cur_bits == 0) {
8341 return;
8342 }
8343 mboolclr(qi->stopped, prio_bits);
8344 }
8345
8346 /* If there is a flow control override we will not change the external
8347 * flow control state.
8348 */
8349 if (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK) {
8350 return;
8351 }
8352
8353 wlc_txflowcontrol_signal(wlc, qi, on, prio);
8354 }
8355
8356 void
8357 wlc_txflowcontrol_override(struct wlc_info *wlc, wlc_txq_info_t *qi, bool on,
8358 uint override)
8359 {
8360 uint prev_override;
8361
8362 ASSERT(override != 0);
8363 ASSERT((override & TXQ_STOP_FOR_PRIOFC_MASK) == 0);
8364
8365 prev_override = (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK);
8366
8367 /* Update the flow control bits and do an early return if there is
8368 * no change in the external flow control state.
8369 */
8370 if (on) {
8371 mboolset(qi->stopped, override);
8372 /* if there was a previous override bit on, then setting this
8373 * makes no difference.
8374 */
8375 if (prev_override) {
8376 return;
8377 }
8378
8379 wlc_txflowcontrol_signal(wlc, qi, ON, ALLPRIO);
8380 } else {
8381 mboolclr(qi->stopped, override);
8382 /* clearing an override bit will only make a difference for
8383 * flow control if it was the only bit set. For any other
8384 * override setting, just return
8385 */
8386 if (prev_override != override) {
8387 return;
8388 }
8389
8390 if (qi->stopped == 0) {
8391 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8392 } else {
8393 int prio;
8394
8395 for (prio = MAXPRIO; prio >= 0; prio--) {
8396 if (!mboolisset(qi->stopped, NBITVAL(prio)))
8397 wlc_txflowcontrol_signal(wlc, qi, OFF,
8398 prio);
8399 }
8400 }
8401 }
8402 }
8403
8404 static void wlc_txflowcontrol_reset(struct wlc_info *wlc)
8405 {
8406 wlc_txq_info_t *qi;
8407
8408 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
8409 if (qi->stopped) {
8410 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8411 qi->stopped = 0;
8412 }
8413 }
8414 }
8415
8416 static void
8417 wlc_txflowcontrol_signal(struct wlc_info *wlc, wlc_txq_info_t *qi, bool on,
8418 int prio)
8419 {
8420 struct wlc_if *wlcif;
8421
8422 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) {
8423 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED)
8424 wl_txflowcontrol(wlc->wl, wlcif->wlif, on, prio);
8425 }
8426 }
8427
8428 static wlc_txq_info_t *wlc_txq_alloc(struct wlc_info *wlc, struct osl_info *osh)
8429 {
8430 wlc_txq_info_t *qi, *p;
8431
8432 qi = (wlc_txq_info_t *) wlc_calloc(osh, wlc->pub->unit,
8433 sizeof(wlc_txq_info_t));
8434 if (qi == NULL) {
8435 return NULL;
8436 }
8437
8438 /* Have enough room for control packets along with HI watermark */
8439 /* Also, add room to txq for total psq packets if all the SCBs leave PS mode */
8440 /* The watermark for flowcontrol to OS packets will remain the same */
8441 pktq_init(&qi->q, WLC_PREC_COUNT,
8442 (2 * wlc->pub->tunables->datahiwat) + PKTQ_LEN_DEFAULT +
8443 wlc->pub->psq_pkts_total);
8444
8445 /* add this queue to the the global list */
8446 p = wlc->tx_queues;
8447 if (p == NULL) {
8448 wlc->tx_queues = qi;
8449 } else {
8450 while (p->next != NULL)
8451 p = p->next;
8452 p->next = qi;
8453 }
8454
8455 return qi;
8456 }
8457
8458 static void wlc_txq_free(struct wlc_info *wlc, struct osl_info *osh,
8459 wlc_txq_info_t *qi)
8460 {
8461 wlc_txq_info_t *p;
8462
8463 if (qi == NULL)
8464 return;
8465
8466 /* remove the queue from the linked list */
8467 p = wlc->tx_queues;
8468 if (p == qi)
8469 wlc->tx_queues = p->next;
8470 else {
8471 while (p != NULL && p->next != qi)
8472 p = p->next;
8473 ASSERT(p->next == qi);
8474 if (p != NULL)
8475 p->next = p->next->next;
8476 }
8477
8478 kfree(qi);
8479 }
This page took 0.209614 seconds and 6 git commands to generate.