staging: brcm80211: fix "ERROR: space prohibited after that ..."
[linux-2.6/libata-dev.git] / drivers / staging / brcm80211 / sys / wlc_mac80211.c
blob1837cd5f3c138c276621c9a5c0e0d6e4356d8648
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #include <wlc_cfg.h>
18 #include <typedefs.h>
19 #include <bcmdefs.h>
20 #include <osl.h>
21 #include <bcmutils.h>
22 #include <bcmwifi.h>
23 #include <siutils.h>
24 #include <bcmendian.h>
25 #include <proto/802.1d.h>
26 #include <proto/802.11.h>
27 #include <proto/802.11e.h>
28 #include <proto/wpa.h>
29 #include <hndsoc.h>
30 #include <sbchipc.h>
31 #include <pcicfg.h>
32 #include <bcmsrom.h>
33 #include <wlioctl.h>
34 #include <epivers.h>
35 #include <bcmwpa.h>
36 #include <sbhndpio.h>
37 #include <sbhnddma.h>
38 #include <hnddma.h>
39 #include <hndpmu.h>
40 #include <d11.h>
41 #include <wlc_rate.h>
42 #include <wlc_pub.h>
43 #include <wlc_key.h>
44 #include <wlc_bsscfg.h>
45 #include <wlc_channel.h>
46 #include <wlc_mac80211.h>
47 #include <wlc_bmac.h>
48 #include <wlc_scb.h>
49 #include <wlc_phy_hal.h>
50 #include <wlc_phy_shim.h>
51 #include <wlc_antsel.h>
52 #include <wlc_stf.h>
53 #include <wlc_ampdu.h>
54 #include <wlc_event.h>
55 #include <wl_export.h>
56 #ifdef BCMSDIO
57 #include <bcmsdh.h>
58 #else
59 #include "d11ucode_ext.h"
60 #endif
61 #ifdef WLC_HIGH_ONLY
62 #include <bcm_rpc_tp.h>
63 #include <bcm_rpc.h>
64 #include <bcm_xdr.h>
65 #include <wlc_rpc.h>
66 #include <wlc_rpctx.h>
67 #endif /* WLC_HIGH_ONLY */
68 #include <wlc_alloc.h>
69 #include <net/mac80211.h>
71 #ifdef WLC_HIGH_ONLY
72 #undef R_REG
73 #undef W_REG
74 #define R_REG(osh, r) RPC_READ_REG(osh, r)
75 #define W_REG(osh, r, v) RPC_WRITE_REG(osh, r, v)
76 #endif
79 * buffer length needed for wlc_format_ssid
80 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
82 #define SSID_FMT_BUF_LEN ((4 * DOT11_MAX_SSID_LEN) + 1)
84 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
85 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
87 #ifndef WLC_MPC_MAX_DELAYCNT
88 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
89 #endif
90 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
91 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
93 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
94 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
96 /* Scale down delays to accommodate QT slow speed */
97 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
98 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
100 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
103 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
104 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
105 * this low resolution driver tick can be used for maintenance tasks such as phy
106 * calibration and scb update
109 /* watchdog trigger mode: OSL timer or TBTT */
110 #define WLC_WATCHDOG_TBTT(wlc) \
111 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
113 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
114 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
116 #ifndef WLC_HIGH_ONLY
117 #define WLC_WAR16165(wlc) (BUSTYPE(wlc->pub->sih->bustype) == PCI_BUS && \
118 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
119 #else
120 #define WLC_WAR16165(wlc) (FALSE)
121 #endif /* WLC_HIGH_ONLY */
123 /* debug/trace */
124 uint wl_msg_level =
125 #if defined(BCMDBG)
126 WL_ERROR_VAL;
127 #else
129 #endif /* BCMDBG */
131 /* Find basic rate for a given rate */
132 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
133 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
134 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
136 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
138 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
140 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
142 #define SCAN_IN_PROGRESS(x) 0
144 #ifdef BCMDBG
145 /* pointer to most recently allocated wl/wlc */
146 static wlc_info_t *wlc_info_dbg = (wlc_info_t *) (NULL);
147 #endif
149 #if defined(BCMDBG)
150 struct wlc_id_name_entry {
151 int id;
152 const char *name;
154 typedef struct wlc_id_name_entry wlc_id_name_table_t[];
155 #endif
157 /* IOVar table */
159 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
160 * table and by the wlc_doiovar() function. No ordering is imposed:
161 * the table is keyed by name, and the function uses a switch.
163 enum {
164 IOV_MPC = 1,
165 IOV_QTXPOWER,
166 IOV_BCN_LI_BCN, /* Beacon listen interval in # of beacons */
167 IOV_LAST /* In case of a need to check max ID number */
170 const bcm_iovar_t wlc_iovars[] = {
171 {"mpc", IOV_MPC, (IOVF_OPEN_ALLOW), IOVT_BOOL, 0},
172 {"qtxpower", IOV_QTXPOWER, (IOVF_WHL | IOVF_OPEN_ALLOW), IOVT_UINT32,
174 {"bcn_li_bcn", IOV_BCN_LI_BCN, 0, IOVT_UINT8, 0},
175 {NULL, 0, 0, 0, 0}
178 const uint8 prio2fifo[NUMPRIO] = {
179 TX_AC_BE_FIFO, /* 0 BE AC_BE Best Effort */
180 TX_AC_BK_FIFO, /* 1 BK AC_BK Background */
181 TX_AC_BK_FIFO, /* 2 -- AC_BK Background */
182 TX_AC_BE_FIFO, /* 3 EE AC_BE Best Effort */
183 TX_AC_VI_FIFO, /* 4 CL AC_VI Video */
184 TX_AC_VI_FIFO, /* 5 VI AC_VI Video */
185 TX_AC_VO_FIFO, /* 6 VO AC_VO Voice */
186 TX_AC_VO_FIFO /* 7 NC AC_VO Voice */
189 /* precedences numbers for wlc queues. These are twice as may levels as
190 * 802.1D priorities.
191 * Odd numbers are used for HI priority traffic at same precedence levels
192 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
194 #define _WLC_PREC_NONE 0 /* None = - */
195 #define _WLC_PREC_BK 2 /* BK - Background */
196 #define _WLC_PREC_BE 4 /* BE - Best-effort */
197 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
198 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
199 #define _WLC_PREC_VI 10 /* Vi - Video */
200 #define _WLC_PREC_VO 12 /* Vo - Voice */
201 #define _WLC_PREC_NC 14 /* NC - Network Control */
203 /* 802.1D Priority to precedence queue mapping */
204 const uint8 wlc_prio2prec_map[] = {
205 _WLC_PREC_BE, /* 0 BE - Best-effort */
206 _WLC_PREC_BK, /* 1 BK - Background */
207 _WLC_PREC_NONE, /* 2 None = - */
208 _WLC_PREC_EE, /* 3 EE - Excellent-effort */
209 _WLC_PREC_CL, /* 4 CL - Controlled Load */
210 _WLC_PREC_VI, /* 5 Vi - Video */
211 _WLC_PREC_VO, /* 6 Vo - Voice */
212 _WLC_PREC_NC, /* 7 NC - Network Control */
215 /* Sanity check for tx_prec_map and fifo synchup
216 * Either there are some packets pending for the fifo, else if fifo is empty then
217 * all the corresponding precmap bits should be set
219 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
220 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
221 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
222 (wlc)->fifo2prec_map[(fifo)]))
224 /* TX FIFO number to WME/802.1E Access Category */
225 const uint8 wme_fifo2ac[] = { AC_BK, AC_BE, AC_VI, AC_VO, AC_BE, AC_BE };
227 /* WME/802.1E Access Category to TX FIFO number */
228 static const uint8 wme_ac2fifo[] = { 1, 0, 2, 3 };
230 static bool in_send_q = FALSE;
232 /* Shared memory location index for various AC params */
233 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
235 #ifdef BCMDBG
236 static const char *fifo_names[] = {
237 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
238 const char *aci_names[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
239 #endif
241 static const uint8 acbitmap2maxprio[] = {
242 PRIO_8021D_BE, PRIO_8021D_BE, PRIO_8021D_BK, PRIO_8021D_BK,
243 PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI,
244 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO,
245 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO
248 /* currently the best mechanism for determining SIFS is the band in use */
249 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
251 /* value for # replay counters currently supported */
252 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
254 /* local prototypes */
255 extern void wlc_txq_enq(void *ctx, struct scb *scb, void *sdu, uint prec);
256 static uint16 BCMFASTPATH wlc_d11hdrs_mac80211(wlc_info_t *wlc,
257 struct ieee80211_hw *hw, void *p,
258 struct scb *scb, uint frag,
259 uint nfrags, uint queue,
260 uint next_frag_len,
261 wsec_key_t *key,
262 ratespec_t rspec_override);
263 bool wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw);
264 void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend);
265 static void wlc_bss_default_init(wlc_info_t *wlc);
266 static void wlc_ucode_mac_upd(wlc_info_t *wlc);
267 static ratespec_t mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band,
268 uint32 int_val);
269 static void wlc_tx_prec_map_init(wlc_info_t *wlc);
270 static void wlc_watchdog(void *arg);
271 static void wlc_watchdog_by_timer(void *arg);
272 static int wlc_set_rateset(wlc_info_t *wlc, wlc_rateset_t *rs_arg);
273 static int wlc_iovar_rangecheck(wlc_info_t *wlc, uint32 val,
274 const bcm_iovar_t *vi);
275 static uint8 wlc_local_constraint_qdbm(wlc_info_t *wlc);
277 #if defined(BCMDBG)
278 static void wlc_print_dot11hdr(uint8 *buf, int len);
279 #endif
281 /* send and receive */
282 static wlc_txq_info_t *wlc_txq_alloc(wlc_info_t *wlc, osl_t *osh);
283 static void wlc_txq_free(wlc_info_t *wlc, osl_t *osh, wlc_txq_info_t *qi);
284 static void wlc_txflowcontrol_signal(wlc_info_t *wlc, wlc_txq_info_t *qi,
285 bool on, int prio);
286 static void wlc_txflowcontrol_reset(wlc_info_t *wlc);
287 static uint16 wlc_compute_airtime(wlc_info_t *wlc, ratespec_t rspec,
288 uint length);
289 static void wlc_compute_cck_plcp(ratespec_t rate, uint length, uint8 *plcp);
290 static void wlc_compute_ofdm_plcp(ratespec_t rate, uint length, uint8 *plcp);
291 static void wlc_compute_mimo_plcp(ratespec_t rate, uint length, uint8 *plcp);
292 static uint16 wlc_compute_frame_dur(wlc_info_t *wlc, ratespec_t rate,
293 uint8 preamble_type, uint next_frag_len);
294 static void wlc_recvctl(wlc_info_t *wlc, osl_t *osh, d11rxhdr_t *rxh,
295 void *p);
296 static uint wlc_calc_frame_len(wlc_info_t *wlc, ratespec_t rate,
297 uint8 preamble_type, uint dur);
298 static uint wlc_calc_ack_time(wlc_info_t *wlc, ratespec_t rate,
299 uint8 preamble_type);
300 static uint wlc_calc_cts_time(wlc_info_t *wlc, ratespec_t rate,
301 uint8 preamble_type);
302 /* interrupt, up/down, band */
303 static void wlc_setband(wlc_info_t *wlc, uint bandunit);
304 static chanspec_t wlc_init_chanspec(wlc_info_t *wlc);
305 static void wlc_bandinit_ordered(wlc_info_t *wlc, chanspec_t chanspec);
306 static void wlc_bsinit(wlc_info_t *wlc);
307 static int wlc_duty_cycle_set(wlc_info_t *wlc, int duty_cycle, bool isOFDM,
308 bool writeToShm);
309 static void wlc_radio_hwdisable_upd(wlc_info_t *wlc);
310 static bool wlc_radio_monitor_start(wlc_info_t *wlc);
311 static void wlc_radio_timer(void *arg);
312 static void wlc_radio_enable(wlc_info_t *wlc);
313 static void wlc_radio_upd(wlc_info_t *wlc);
315 /* scan, association, BSS */
316 static uint wlc_calc_ba_time(wlc_info_t *wlc, ratespec_t rate,
317 uint8 preamble_type);
318 static void wlc_update_mimo_band_bwcap(wlc_info_t *wlc, uint8 bwcap);
319 static void wlc_ht_update_sgi_rx(wlc_info_t *wlc, int val);
320 void wlc_ht_mimops_cap_update(wlc_info_t *wlc, uint8 mimops_mode);
321 static void wlc_ht_update_ldpc(wlc_info_t *wlc, int8 val);
322 static void wlc_war16165(wlc_info_t *wlc, bool tx);
324 static void wlc_process_eventq(void *arg);
325 static void wlc_wme_retries_write(wlc_info_t *wlc);
326 static bool wlc_attach_stf_ant_init(wlc_info_t *wlc);
327 static uint wlc_attach_module(wlc_info_t *wlc);
328 static void wlc_detach_module(wlc_info_t *wlc);
329 static void wlc_timers_deinit(wlc_info_t *wlc);
330 static void wlc_down_led_upd(wlc_info_t *wlc);
331 static uint wlc_down_del_timer(wlc_info_t *wlc);
332 static void wlc_ofdm_rateset_war(wlc_info_t *wlc);
333 static int _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len,
334 struct wlc_if *wlcif);
335 char *print_fk(uint16 fk);
337 #if defined(BCMDBG)
338 void wlc_get_rcmta(wlc_info_t *wlc, int idx, struct ether_addr *addr)
340 d11regs_t *regs = wlc->regs;
341 uint32 v32;
342 osl_t *osh;
344 WL_TRACE(("wl%d: %s\n", WLCWLUNIT(wlc), __func__));
346 ASSERT(wlc->pub->corerev > 4);
348 osh = wlc->osh;
350 W_REG(osh, &regs->objaddr, (OBJADDR_RCMTA_SEL | (idx * 2)));
351 (void)R_REG(osh, &regs->objaddr);
352 v32 = R_REG(osh, &regs->objdata);
353 addr->octet[0] = (uint8) v32;
354 addr->octet[1] = (uint8) (v32 >> 8);
355 addr->octet[2] = (uint8) (v32 >> 16);
356 addr->octet[3] = (uint8) (v32 >> 24);
357 W_REG(osh, &regs->objaddr, (OBJADDR_RCMTA_SEL | ((idx * 2) + 1)));
358 (void)R_REG(osh, &regs->objaddr);
359 v32 = R_REG(osh, (volatile uint16 *)(uintptr) & regs->objdata);
360 addr->octet[4] = (uint8) v32;
361 addr->octet[5] = (uint8) (v32 >> 8);
363 #endif /* defined(BCMDBG) */
365 /* keep the chip awake if needed */
366 bool wlc_stay_awake(wlc_info_t *wlc)
368 return TRUE;
371 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
373 bool wlc_ps_allowed(wlc_info_t *wlc)
375 int idx;
376 wlc_bsscfg_t *cfg;
378 /* disallow PS when one of the following global conditions meets */
379 if (!wlc->pub->associated || !wlc->PMenabled || wlc->PM_override)
380 return FALSE;
382 /* disallow PS when one of these meets when not scanning */
383 if (!wlc->PMblocked) {
384 if (AP_ACTIVE(wlc) || wlc->monitor)
385 return FALSE;
388 FOREACH_AS_STA(wlc, idx, cfg) {
389 /* disallow PS when one of the following bsscfg specific conditions meets */
390 if (!cfg->BSS || !WLC_PORTOPEN(cfg))
391 return FALSE;
393 if (!cfg->dtim_programmed)
394 return FALSE;
397 return TRUE;
400 void BCMINITFN(wlc_reset) (wlc_info_t *wlc)
402 WL_TRACE(("wl%d: wlc_reset\n", wlc->pub->unit));
404 wlc->check_for_unaligned_tbtt = FALSE;
406 /* slurp up hw mac counters before core reset */
407 if (WLC_UPDATE_STATS(wlc)) {
408 wlc_statsupd(wlc);
410 /* reset our snapshot of macstat counters */
411 bzero((char *)wlc->core->macstat_snapshot, sizeof(macstat_t));
414 wlc_bmac_reset(wlc->hw);
415 wlc_ampdu_reset(wlc->ampdu);
416 wlc->txretried = 0;
418 #ifdef WLC_HIGH_ONLY
419 /* Need to set a flag(to be cleared asynchronously by BMAC driver with high call)
420 * in order to prevent wlc_rpctx_txreclaim() from screwing wlc_rpctx_getnexttxp(),
421 * which could be invoked by already QUEUED high call(s) from BMAC driver before
422 * wlc_bmac_reset() finishes.
423 * It's not needed before in monolithic driver model because d11core interrupts would
424 * have been cleared instantly in wlc_bmac_reset() and no txstatus interrupt
425 * will come to driver to fetch those flushed dma pkt pointers.
427 wlc->reset_bmac_pending = TRUE;
429 wlc_rpctx_txreclaim(wlc->rpctx);
431 wlc_stf_phy_txant_upd(wlc);
432 wlc_phy_ant_rxdiv_set(wlc->band->pi, wlc->stf->ant_rx_ovr);
433 #endif
436 void wlc_fatal_error(wlc_info_t *wlc)
438 WL_ERROR(("wl%d: fatal error, reinitializing\n", wlc->pub->unit));
439 wl_init(wlc->wl);
442 /* Return the channel the driver should initialize during wlc_init.
443 * the channel may have to be changed from the currently configured channel
444 * if other configurations are in conflict (bandlocked, 11n mode disabled,
445 * invalid channel for current country, etc.)
447 static chanspec_t BCMINITFN(wlc_init_chanspec) (wlc_info_t *wlc)
449 chanspec_t chanspec =
450 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE |
451 WL_CHANSPEC_BAND_2G;
453 /* make sure the channel is on the supported band if we are band-restricted */
454 if (wlc->bandlocked || NBANDS(wlc) == 1) {
455 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
457 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
458 return chanspec;
461 struct scb global_scb;
463 static void wlc_init_scb(wlc_info_t *wlc, struct scb *scb)
465 int i;
466 scb->flags = SCB_WMECAP | SCB_HTCAP;
467 for (i = 0; i < NUMPRIO; i++)
468 scb->seqnum[i] = 0;
471 void BCMINITFN(wlc_init) (wlc_info_t *wlc)
473 d11regs_t *regs;
474 chanspec_t chanspec;
475 int i;
476 wlc_bsscfg_t *bsscfg;
477 bool mute = FALSE;
479 WL_TRACE(("wl%d: wlc_init\n", wlc->pub->unit));
481 regs = wlc->regs;
483 /* This will happen if a big-hammer was executed. In that case, we want to go back
484 * to the channel that we were on and not new channel
486 if (wlc->pub->associated)
487 chanspec = wlc->home_chanspec;
488 else
489 chanspec = wlc_init_chanspec(wlc);
491 wlc_bmac_init(wlc->hw, chanspec, mute);
493 wlc->seckeys = wlc_bmac_read_shm(wlc->hw, M_SECRXKEYS_PTR) * 2;
494 if (D11REV_GE(wlc->pub->corerev, 15) && (wlc->machwcap & MCAP_TKIPMIC))
495 wlc->tkmickeys =
496 wlc_bmac_read_shm(wlc->hw, M_TKMICKEYS_PTR) * 2;
498 /* update beacon listen interval */
499 wlc_bcn_li_upd(wlc);
500 wlc->bcn_wait_prd =
501 (uint8) (wlc_bmac_read_shm(wlc->hw, M_NOSLPZNATDTIM) >> 10);
502 ASSERT(wlc->bcn_wait_prd > 0);
504 /* the world is new again, so is our reported rate */
505 wlc_reprate_init(wlc);
507 /* write ethernet address to core */
508 FOREACH_BSS(wlc, i, bsscfg) {
509 wlc_set_mac(bsscfg);
510 wlc_set_bssid(bsscfg);
513 /* Update tsf_cfprep if associated and up */
514 if (wlc->pub->associated) {
515 FOREACH_BSS(wlc, i, bsscfg) {
516 if (bsscfg->up) {
517 uint32 bi;
519 /* get beacon period from bsscfg and convert to uS */
520 bi = bsscfg->current_bss->beacon_period << 10;
521 /* update the tsf_cfprep register */
522 /* since init path would reset to default value */
523 W_REG(wlc->osh, &regs->tsf_cfprep,
524 (bi << CFPREP_CBI_SHIFT));
526 /* Update maccontrol PM related bits */
527 wlc_set_ps_ctrl(wlc);
529 break;
534 wlc_key_hw_init_all(wlc);
536 wlc_bandinit_ordered(wlc, chanspec);
538 wlc_init_scb(wlc, &global_scb);
540 /* init probe response timeout */
541 wlc_write_shm(wlc, M_PRS_MAXTIME, wlc->prb_resp_timeout);
543 /* init max burst txop (framebursting) */
544 wlc_write_shm(wlc, M_MBURST_TXOP,
545 (wlc->
546 _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP));
548 /* initialize maximum allowed duty cycle */
549 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, TRUE, TRUE);
550 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, FALSE, TRUE);
552 /* Update some shared memory locations related to max AMPDU size allowed to received */
553 wlc_ampdu_shm_upd(wlc->ampdu);
555 /* band-specific inits */
556 wlc_bsinit(wlc);
558 /* Enable EDCF mode (while the MAC is suspended) */
559 if (EDCF_ENAB(wlc->pub)) {
560 OR_REG(wlc->osh, &regs->ifs_ctl, IFS_USEEDCF);
561 wlc_edcf_setparams(wlc->cfg, FALSE);
564 /* Init precedence maps for empty FIFOs */
565 wlc_tx_prec_map_init(wlc);
567 /* read the ucode version if we have not yet done so */
568 if (wlc->ucode_rev == 0) {
569 wlc->ucode_rev =
570 wlc_read_shm(wlc, M_BOM_REV_MAJOR) << NBITS(uint16);
571 wlc->ucode_rev |= wlc_read_shm(wlc, M_BOM_REV_MINOR);
574 /* ..now really unleash hell (allow the MAC out of suspend) */
575 wlc_enable_mac(wlc);
577 /* clear tx flow control */
578 wlc_txflowcontrol_reset(wlc);
580 /* clear tx data fifo suspends */
581 wlc->tx_suspended = FALSE;
583 /* enable the RF Disable Delay timer */
584 if (D11REV_GE(wlc->pub->corerev, 10))
585 W_REG(wlc->osh, &wlc->regs->rfdisabledly, RFDISABLE_DEFAULT);
587 /* initialize mpc delay */
588 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
591 * Initialize WME parameters; if they haven't been set by some other
592 * mechanism (IOVar, etc) then read them from the hardware.
594 if (WLC_WME_RETRY_SHORT_GET(wlc, 0) == 0) { /* Unintialized; read from HW */
595 int ac;
597 ASSERT(wlc->clk);
598 for (ac = 0; ac < AC_COUNT; ac++) {
599 wlc->wme_retries[ac] =
600 wlc_read_shm(wlc, M_AC_TXLMT_ADDR(ac));
605 void wlc_mac_bcn_promisc_change(wlc_info_t *wlc, bool promisc)
607 wlc->bcnmisc_monitor = promisc;
608 wlc_mac_bcn_promisc(wlc);
611 void wlc_mac_bcn_promisc(wlc_info_t *wlc)
613 if ((AP_ENAB(wlc->pub) && (N_ENAB(wlc->pub) || wlc->band->gmode)) ||
614 wlc->bcnmisc_ibss || wlc->bcnmisc_scan || wlc->bcnmisc_monitor)
615 wlc_mctrl(wlc, MCTL_BCNS_PROMISC, MCTL_BCNS_PROMISC);
616 else
617 wlc_mctrl(wlc, MCTL_BCNS_PROMISC, 0);
620 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
621 void wlc_mac_promisc(wlc_info_t *wlc)
623 uint32 promisc_bits = 0;
625 /* promiscuous mode just sets MCTL_PROMISC
626 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
627 * since all BSS data traffic is directed at the AP
629 if (PROMISC_ENAB(wlc->pub) && !AP_ENAB(wlc->pub) && !wlc->wet)
630 promisc_bits |= MCTL_PROMISC;
632 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
633 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
634 * handled in wlc_mac_bcn_promisc()
636 if (MONITOR_ENAB(wlc))
637 promisc_bits |= MCTL_PROMISC | MCTL_KEEPCONTROL;
639 wlc_mctrl(wlc, MCTL_PROMISC | MCTL_KEEPCONTROL, promisc_bits);
642 /* check if hps and wake states of sw and hw are in sync */
643 bool wlc_ps_check(wlc_info_t *wlc)
645 bool res = TRUE;
646 bool hps, wake;
647 bool wake_ok;
649 if (!AP_ACTIVE(wlc)) {
650 volatile uint32 tmp;
651 tmp = R_REG(wlc->osh, &wlc->regs->maccontrol);
653 /* If deviceremoved is detected, then don't take any action as this can be called
654 * in any context. Assume that caller will take care of the condition. This is just
655 * to avoid assert
657 if (tmp == 0xffffffff) {
658 WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit,
659 __func__));
660 return DEVICEREMOVED(wlc);
663 hps = PS_ALLOWED(wlc);
665 if (hps != ((tmp & MCTL_HPS) != 0)) {
666 int idx;
667 wlc_bsscfg_t *cfg;
668 WL_ERROR(("wl%d: hps not sync, sw %d, maccontrol 0x%x\n", wlc->pub->unit, hps, tmp));
669 FOREACH_BSS(wlc, idx, cfg) {
670 if (!BSSCFG_STA(cfg))
671 continue;
674 res = FALSE;
676 #ifdef WLC_LOW
677 /* For a monolithic build the wake check can be exact since it looks at wake
678 * override bits. The MCTL_WAKE bit should match the 'wake' value.
680 wake = STAY_AWAKE(wlc) || wlc->hw->wake_override;
681 wake_ok = (wake == ((tmp & MCTL_WAKE) != 0));
682 #else
683 /* For a split build we will not have access to any wake overrides from the low
684 * level. The check can only make sure the MCTL_WAKE bit is on if the high
685 * level 'wake' value is true. If the high level 'wake' is false, the MCTL_WAKE
686 * may be either true or false due to the low level override.
688 wake = STAY_AWAKE(wlc);
689 wake_ok = (wake && ((tmp & MCTL_WAKE) != 0)) || !wake;
690 #endif
691 if (hps && !wake_ok) {
692 WL_ERROR(("wl%d: wake not sync, sw %d maccontrol 0x%x\n", wlc->pub->unit, wake, tmp));
693 res = FALSE;
696 ASSERT(res);
697 return res;
700 /* push sw hps and wake state through hardware */
701 void wlc_set_ps_ctrl(wlc_info_t *wlc)
703 uint32 v1, v2;
704 bool hps, wake;
705 bool awake_before;
707 hps = PS_ALLOWED(wlc);
708 wake = hps ? (STAY_AWAKE(wlc)) : TRUE;
710 WL_TRACE(("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n", wlc->pub->unit,
711 hps, wake));
713 v1 = R_REG(wlc->osh, &wlc->regs->maccontrol);
714 v2 = 0;
715 if (hps)
716 v2 |= MCTL_HPS;
717 if (wake)
718 v2 |= MCTL_WAKE;
720 wlc_mctrl(wlc, MCTL_WAKE | MCTL_HPS, v2);
722 awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0));
724 if (wake && !awake_before)
725 wlc_bmac_wait_for_wake(wlc->hw);
730 * Write this BSS config's MAC address to core.
731 * Updates RXE match engine.
733 int wlc_set_mac(wlc_bsscfg_t *cfg)
735 int err = 0;
736 wlc_info_t *wlc = cfg->wlc;
738 if (cfg == wlc->cfg) {
739 /* enter the MAC addr into the RXE match registers */
740 wlc_set_addrmatch(wlc, RCM_MAC_OFFSET, &cfg->cur_etheraddr);
743 wlc_ampdu_macaddr_upd(wlc);
745 return err;
748 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
749 * Updates RXE match engine.
751 void wlc_set_bssid(wlc_bsscfg_t *cfg)
753 wlc_info_t *wlc = cfg->wlc;
755 /* if primary config, we need to update BSSID in RXE match registers */
756 if (cfg == wlc->cfg) {
757 wlc_set_addrmatch(wlc, RCM_BSSID_OFFSET, &cfg->BSSID);
759 #ifdef SUPPORT_HWKEYS
760 else if (BSSCFG_STA(cfg) && cfg->BSS) {
761 wlc_rcmta_add_bssid(wlc, cfg);
763 #endif
767 * Suspend the the MAC and update the slot timing
768 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
770 void wlc_switch_shortslot(wlc_info_t *wlc, bool shortslot)
772 int idx;
773 wlc_bsscfg_t *cfg;
775 ASSERT(wlc->band->gmode);
777 /* use the override if it is set */
778 if (wlc->shortslot_override != WLC_SHORTSLOT_AUTO)
779 shortslot = (wlc->shortslot_override == WLC_SHORTSLOT_ON);
781 if (wlc->shortslot == shortslot)
782 return;
784 wlc->shortslot = shortslot;
786 /* update the capability based on current shortslot mode */
787 FOREACH_BSS(wlc, idx, cfg) {
788 if (!cfg->associated)
789 continue;
790 cfg->current_bss->capability &= ~DOT11_CAP_SHORTSLOT;
791 if (wlc->shortslot)
792 cfg->current_bss->capability |= DOT11_CAP_SHORTSLOT;
795 wlc_bmac_set_shortslot(wlc->hw, shortslot);
798 static uint8 wlc_local_constraint_qdbm(wlc_info_t *wlc)
800 uint8 local;
801 int16 local_max;
803 local = WLC_TXPWR_MAX;
804 if (wlc->pub->associated &&
805 (wf_chspec_ctlchan(wlc->chanspec) ==
806 wf_chspec_ctlchan(wlc->home_chanspec))) {
808 /* get the local power constraint if we are on the AP's
809 * channel [802.11h, 7.3.2.13]
811 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
812 local_max =
813 (wlc->txpwr_local_max -
814 wlc->txpwr_local_constraint) * WLC_TXPWR_DB_FACTOR;
815 if (local_max > 0 && local_max < WLC_TXPWR_MAX)
816 return (uint8) local_max;
817 if (local_max < 0)
818 return 0;
821 return local;
824 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
825 void wlc_set_home_chanspec(wlc_info_t *wlc, chanspec_t chanspec)
827 if (wlc->home_chanspec != chanspec) {
828 int idx;
829 wlc_bsscfg_t *cfg;
831 wlc->home_chanspec = chanspec;
833 FOREACH_BSS(wlc, idx, cfg) {
834 if (!cfg->associated)
835 continue;
836 cfg->target_bss->chanspec = chanspec;
837 cfg->current_bss->chanspec = chanspec;
843 static void wlc_set_phy_chanspec(wlc_info_t *wlc, chanspec_t chanspec)
845 /* Save our copy of the chanspec */
846 wlc->chanspec = chanspec;
848 /* Set the chanspec and power limits for this locale after computing
849 * any 11h local tx power constraints.
851 wlc_channel_set_chanspec(wlc->cmi, chanspec,
852 wlc_local_constraint_qdbm(wlc));
854 if (wlc->stf->ss_algosel_auto)
855 wlc_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel,
856 chanspec);
858 wlc_stf_ss_update(wlc, wlc->band);
862 void wlc_set_chanspec(wlc_info_t *wlc, chanspec_t chanspec)
864 uint bandunit;
865 bool switchband = FALSE;
866 chanspec_t old_chanspec = wlc->chanspec;
868 if (!wlc_valid_chanspec_db(wlc->cmi, chanspec)) {
869 WL_ERROR(("wl%d: %s: Bad channel %d\n",
870 wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec)));
871 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
872 return;
875 /* Switch bands if necessary */
876 if (NBANDS(wlc) > 1) {
877 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
878 if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) {
879 switchband = TRUE;
880 if (wlc->bandlocked) {
881 WL_ERROR(("wl%d: %s: chspec %d band is locked!\n", wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec)));
882 return;
884 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
885 * if the setband updates (wlc_bsinit) use low level calls to inspect and
886 * set state, the state inspected may be from the wrong band, or the
887 * following wlc_bmac_set_chanspec() may undo the work.
889 wlc_setband(wlc, bandunit);
893 ASSERT(N_ENAB(wlc->pub) || !CHSPEC_IS40(chanspec));
895 /* sync up phy/radio chanspec */
896 wlc_set_phy_chanspec(wlc, chanspec);
898 /* init antenna selection */
899 if (CHSPEC_WLC_BW(old_chanspec) != CHSPEC_WLC_BW(chanspec)) {
900 if (WLANTSEL_ENAB(wlc))
901 wlc_antsel_init(wlc->asi);
903 /* Fix the hardware rateset based on bw.
904 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
906 wlc_rateset_bw_mcs_filter(&wlc->band->hw_rateset,
907 wlc->band->
908 mimo_cap_40 ? CHSPEC_WLC_BW(chanspec)
909 : 0);
912 /* update some mac configuration since chanspec changed */
913 wlc_ucode_mac_upd(wlc);
916 #if defined(BCMDBG)
917 static int wlc_get_current_txpwr(wlc_info_t *wlc, void *pwr, uint len)
919 txpwr_limits_t txpwr;
920 tx_power_t power;
921 tx_power_legacy_t *old_power = NULL;
922 int r, c;
923 uint qdbm;
924 bool override;
926 if (len == sizeof(tx_power_legacy_t))
927 old_power = (tx_power_legacy_t *) pwr;
928 else if (len < sizeof(tx_power_t))
929 return BCME_BUFTOOSHORT;
931 bzero(&power, sizeof(tx_power_t));
933 power.chanspec = WLC_BAND_PI_RADIO_CHANSPEC;
934 if (wlc->pub->associated)
935 power.local_chanspec = wlc->home_chanspec;
937 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
938 * public interface only implements getting and setting a single value for all of
939 * rates, so we need to fill the array ourselves.
941 wlc_phy_txpower_get(wlc->band->pi, &qdbm, &override);
942 for (r = 0; r < WL_TX_POWER_RATES; r++) {
943 power.user_limit[r] = (uint8) qdbm;
946 power.local_max = wlc->txpwr_local_max * WLC_TXPWR_DB_FACTOR;
947 power.local_constraint =
948 wlc->txpwr_local_constraint * WLC_TXPWR_DB_FACTOR;
950 power.antgain[0] = wlc->bandstate[BAND_2G_INDEX]->antgain;
951 power.antgain[1] = wlc->bandstate[BAND_5G_INDEX]->antgain;
953 wlc_channel_reg_limits(wlc->cmi, power.chanspec, &txpwr);
955 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
956 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
957 #endif
959 /* CCK tx power limits */
960 for (c = 0, r = WL_TX_POWER_CCK_FIRST; c < WL_TX_POWER_CCK_NUM;
961 c++, r++)
962 power.reg_limit[r] = txpwr.cck[c];
964 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
965 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
966 #endif
968 /* 20 MHz OFDM SISO tx power limits */
969 for (c = 0, r = WL_TX_POWER_OFDM_FIRST; c < WL_TX_POWER_OFDM_NUM;
970 c++, r++)
971 power.reg_limit[r] = txpwr.ofdm[c];
973 if (WLC_PHY_11N_CAP(wlc->band)) {
975 /* 20 MHz OFDM CDD tx power limits */
976 for (c = 0, r = WL_TX_POWER_OFDM20_CDD_FIRST;
977 c < WL_TX_POWER_OFDM_NUM; c++, r++)
978 power.reg_limit[r] = txpwr.ofdm_cdd[c];
980 /* 40 MHz OFDM SISO tx power limits */
981 for (c = 0, r = WL_TX_POWER_OFDM40_SISO_FIRST;
982 c < WL_TX_POWER_OFDM_NUM; c++, r++)
983 power.reg_limit[r] = txpwr.ofdm_40_siso[c];
985 /* 40 MHz OFDM CDD tx power limits */
986 for (c = 0, r = WL_TX_POWER_OFDM40_CDD_FIRST;
987 c < WL_TX_POWER_OFDM_NUM; c++, r++)
988 power.reg_limit[r] = txpwr.ofdm_40_cdd[c];
990 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
991 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
992 #endif
994 /* 20MHz MCS0-7 SISO tx power limits */
995 for (c = 0, r = WL_TX_POWER_MCS20_SISO_FIRST;
996 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
997 power.reg_limit[r] = txpwr.mcs_20_siso[c];
999 /* 20MHz MCS0-7 CDD tx power limits */
1000 for (c = 0, r = WL_TX_POWER_MCS20_CDD_FIRST;
1001 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
1002 power.reg_limit[r] = txpwr.mcs_20_cdd[c];
1004 /* 20MHz MCS0-7 STBC tx power limits */
1005 for (c = 0, r = WL_TX_POWER_MCS20_STBC_FIRST;
1006 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
1007 power.reg_limit[r] = txpwr.mcs_20_stbc[c];
1009 /* 40MHz MCS0-7 SISO tx power limits */
1010 for (c = 0, r = WL_TX_POWER_MCS40_SISO_FIRST;
1011 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
1012 power.reg_limit[r] = txpwr.mcs_40_siso[c];
1014 /* 40MHz MCS0-7 CDD tx power limits */
1015 for (c = 0, r = WL_TX_POWER_MCS40_CDD_FIRST;
1016 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
1017 power.reg_limit[r] = txpwr.mcs_40_cdd[c];
1019 /* 40MHz MCS0-7 STBC tx power limits */
1020 for (c = 0, r = WL_TX_POWER_MCS40_STBC_FIRST;
1021 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
1022 power.reg_limit[r] = txpwr.mcs_40_stbc[c];
1024 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
1025 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
1026 #endif
1028 /* 20MHz MCS8-15 SDM tx power limits */
1029 for (c = 0, r = WL_TX_POWER_MCS20_SDM_FIRST;
1030 c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++)
1031 power.reg_limit[r] = txpwr.mcs_20_mimo[c];
1033 /* 40MHz MCS8-15 SDM tx power limits */
1034 for (c = 0, r = WL_TX_POWER_MCS40_SDM_FIRST;
1035 c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++)
1036 power.reg_limit[r] = txpwr.mcs_40_mimo[c];
1038 /* MCS 32 */
1039 power.reg_limit[WL_TX_POWER_MCS_32] = txpwr.mcs32;
1042 wlc_phy_txpower_get_current(wlc->band->pi, &power,
1043 CHSPEC_CHANNEL(power.chanspec));
1045 /* copy the tx_power_t struct to the return buffer,
1046 * or convert to a tx_power_legacy_t struct
1048 if (!old_power) {
1049 bcopy(&power, pwr, sizeof(tx_power_t));
1050 } else {
1051 int band_idx = CHSPEC_IS2G(power.chanspec) ? 0 : 1;
1053 bzero(old_power, sizeof(tx_power_legacy_t));
1055 old_power->txpwr_local_max = power.local_max;
1056 old_power->txpwr_local_constraint = power.local_constraint;
1057 if (CHSPEC_IS2G(power.chanspec)) {
1058 old_power->txpwr_chan_reg_max = txpwr.cck[0];
1059 old_power->txpwr_est_Pout[band_idx] =
1060 power.est_Pout_cck;
1061 old_power->txpwr_est_Pout_gofdm = power.est_Pout[0];
1062 } else {
1063 old_power->txpwr_chan_reg_max = txpwr.ofdm[0];
1064 old_power->txpwr_est_Pout[band_idx] = power.est_Pout[0];
1066 old_power->txpwr_antgain[0] = power.antgain[0];
1067 old_power->txpwr_antgain[1] = power.antgain[1];
1069 for (r = 0; r < NUM_PWRCTRL_RATES; r++) {
1070 old_power->txpwr_band_max[r] = power.user_limit[r];
1071 old_power->txpwr_limit[r] = power.reg_limit[r];
1072 old_power->txpwr_target[band_idx][r] = power.target[r];
1073 if (CHSPEC_IS2G(power.chanspec))
1074 old_power->txpwr_bphy_cck_max[r] =
1075 power.board_limit[r];
1076 else
1077 old_power->txpwr_aphy_max[r] =
1078 power.board_limit[r];
1082 return 0;
1084 #endif /* defined(BCMDBG) */
1086 static uint32 wlc_watchdog_backup_bi(wlc_info_t *wlc)
1088 uint32 bi;
1089 bi = 2 * wlc->cfg->current_bss->dtim_period *
1090 wlc->cfg->current_bss->beacon_period;
1091 if (wlc->bcn_li_dtim)
1092 bi *= wlc->bcn_li_dtim;
1093 else if (wlc->bcn_li_bcn)
1094 /* recalculate bi based on bcn_li_bcn */
1095 bi = 2 * wlc->bcn_li_bcn * wlc->cfg->current_bss->beacon_period;
1097 if (bi < 2 * TIMER_INTERVAL_WATCHDOG)
1098 bi = 2 * TIMER_INTERVAL_WATCHDOG;
1099 return bi;
1102 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1103 * Call watchdog from tbtt handler if tbtt is TRUE, watchdog timer otherwise.
1105 void wlc_watchdog_upd(wlc_info_t *wlc, bool tbtt)
1107 /* make sure changing watchdog driver is allowed */
1108 if (!wlc->pub->up || !wlc->pub->align_wd_tbtt)
1109 return;
1110 if (!tbtt && wlc->WDarmed) {
1111 wl_del_timer(wlc->wl, wlc->wdtimer);
1112 wlc->WDarmed = FALSE;
1115 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1116 if (tbtt && wlc->WDarmed) {
1117 wl_del_timer(wlc->wl, wlc->wdtimer);
1118 wlc->WDarmed = FALSE;
1119 wlc->WDlast = OSL_SYSUPTIME();
1121 /* arm watchdog timer and drive the watchdog there */
1122 else if (!tbtt && !wlc->WDarmed) {
1123 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
1124 TRUE);
1125 wlc->WDarmed = TRUE;
1127 if (tbtt && !wlc->WDarmed) {
1128 wl_add_timer(wlc->wl, wlc->wdtimer, wlc_watchdog_backup_bi(wlc),
1129 TRUE);
1130 wlc->WDarmed = TRUE;
1134 ratespec_t wlc_lowest_basic_rspec(wlc_info_t *wlc, wlc_rateset_t *rs)
1136 ratespec_t lowest_basic_rspec;
1137 uint i;
1139 /* Use the lowest basic rate */
1140 lowest_basic_rspec = rs->rates[0] & RATE_MASK;
1141 for (i = 0; i < rs->count; i++) {
1142 if (rs->rates[i] & WLC_RATE_FLAG) {
1143 lowest_basic_rspec = rs->rates[i] & RATE_MASK;
1144 break;
1147 #if NCONF
1148 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1149 if (IS_OFDM(lowest_basic_rspec)) {
1150 lowest_basic_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
1152 #endif
1154 return lowest_basic_rspec;
1157 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1158 * setting as per this table:
1159 * ratespec CCK ant = wlc->stf->txant
1160 * OFDM ant = 3
1162 void wlc_beacon_phytxctl_txant_upd(wlc_info_t *wlc, ratespec_t bcn_rspec)
1164 uint16 phyctl;
1165 uint16 phytxant = wlc->stf->phytxant;
1166 uint16 mask = PHY_TXC_ANT_MASK;
1168 /* for non-siso rates or default setting, use the available chains */
1169 if (WLC_PHY_11N_CAP(wlc->band)) {
1170 phytxant = wlc_stf_phytxchain_sel(wlc, bcn_rspec);
1173 phyctl = wlc_read_shm(wlc, M_BCN_PCTLWD);
1174 phyctl = (phyctl & ~mask) | phytxant;
1175 wlc_write_shm(wlc, M_BCN_PCTLWD, phyctl);
1178 /* centralized protection config change function to simplify debugging, no consistency checking
1179 * this should be called only on changes to avoid overhead in periodic function
1181 void wlc_protection_upd(wlc_info_t *wlc, uint idx, int val)
1183 WL_TRACE(("wlc_protection_upd: idx %d, val %d\n", idx, val));
1185 switch (idx) {
1186 case WLC_PROT_G_SPEC:
1187 wlc->protection->_g = (bool) val;
1188 break;
1189 case WLC_PROT_G_OVR:
1190 wlc->protection->g_override = (int8) val;
1191 break;
1192 case WLC_PROT_G_USER:
1193 wlc->protection->gmode_user = (uint8) val;
1194 break;
1195 case WLC_PROT_OVERLAP:
1196 wlc->protection->overlap = (int8) val;
1197 break;
1198 case WLC_PROT_N_USER:
1199 wlc->protection->nmode_user = (int8) val;
1200 break;
1201 case WLC_PROT_N_CFG:
1202 wlc->protection->n_cfg = (int8) val;
1203 break;
1204 case WLC_PROT_N_CFG_OVR:
1205 wlc->protection->n_cfg_override = (int8) val;
1206 break;
1207 case WLC_PROT_N_NONGF:
1208 wlc->protection->nongf = (bool) val;
1209 break;
1210 case WLC_PROT_N_NONGF_OVR:
1211 wlc->protection->nongf_override = (int8) val;
1212 break;
1213 case WLC_PROT_N_PAM_OVR:
1214 wlc->protection->n_pam_override = (int8) val;
1215 break;
1216 case WLC_PROT_N_OBSS:
1217 wlc->protection->n_obss = (bool) val;
1218 break;
1220 default:
1221 ASSERT(0);
1222 break;
1227 static void wlc_ht_update_sgi_rx(wlc_info_t *wlc, int val)
1229 wlc->ht_cap.cap &= ~(HT_CAP_SHORT_GI_20 | HT_CAP_SHORT_GI_40);
1230 wlc->ht_cap.cap |= (val & WLC_N_SGI_20) ? HT_CAP_SHORT_GI_20 : 0;
1231 wlc->ht_cap.cap |= (val & WLC_N_SGI_40) ? HT_CAP_SHORT_GI_40 : 0;
1233 if (wlc->pub->up) {
1234 wlc_update_beacon(wlc);
1235 wlc_update_probe_resp(wlc, TRUE);
1239 static void wlc_ht_update_ldpc(wlc_info_t *wlc, int8 val)
1241 wlc->stf->ldpc = val;
1243 wlc->ht_cap.cap &= ~HT_CAP_LDPC_CODING;
1244 if (wlc->stf->ldpc != OFF)
1245 wlc->ht_cap.cap |= HT_CAP_LDPC_CODING;
1247 if (wlc->pub->up) {
1248 wlc_update_beacon(wlc);
1249 wlc_update_probe_resp(wlc, TRUE);
1250 wlc_phy_ldpc_override_set(wlc->band->pi, (val ? TRUE : FALSE));
1255 * ucode, hwmac update
1256 * Channel dependent updates for ucode and hw
1258 static void wlc_ucode_mac_upd(wlc_info_t *wlc)
1260 /* enable or disable any active IBSSs depending on whether or not
1261 * we are on the home channel
1263 if (wlc->home_chanspec == WLC_BAND_PI_RADIO_CHANSPEC) {
1264 if (wlc->pub->associated) {
1265 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1266 * I think that the ucode inits set up the bcn templates and shm values
1267 * with a bogus beacon. This should not be done in the inits. If ucode needs
1268 * to set up a beacon for testing, the test routines should write it down,
1269 * not expect the inits to populate a bogus beacon.
1271 if (WLC_PHY_11N_CAP(wlc->band)) {
1272 wlc_write_shm(wlc, M_BCN_TXTSF_OFFSET,
1273 wlc->band->bcntsfoff);
1276 } else {
1277 /* disable an active IBSS if we are not on the home channel */
1280 /* update the various promisc bits */
1281 wlc_mac_bcn_promisc(wlc);
1282 wlc_mac_promisc(wlc);
1285 static void wlc_bandinit_ordered(wlc_info_t *wlc, chanspec_t chanspec)
1287 wlc_rateset_t default_rateset;
1288 uint parkband;
1289 uint i, band_order[2];
1291 WL_TRACE(("wl%d: wlc_bandinit_ordered\n", wlc->pub->unit));
1293 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1294 * figure out the right band to park on
1296 if (wlc->bandlocked || NBANDS(wlc) == 1) {
1297 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
1299 parkband = wlc->band->bandunit; /* updated in wlc_bandlock() */
1300 band_order[0] = band_order[1] = parkband;
1301 } else {
1302 /* park on the band of the specified chanspec */
1303 parkband = CHSPEC_WLCBANDUNIT(chanspec);
1305 /* order so that parkband initialize last */
1306 band_order[0] = parkband ^ 1;
1307 band_order[1] = parkband;
1310 /* make each band operational, software state init */
1311 for (i = 0; i < NBANDS(wlc); i++) {
1312 uint j = band_order[i];
1314 wlc->band = wlc->bandstate[j];
1316 wlc_default_rateset(wlc, &default_rateset);
1318 /* fill in hw_rate */
1319 wlc_rateset_filter(&default_rateset, &wlc->band->hw_rateset,
1320 FALSE, WLC_RATES_CCK_OFDM, RATE_MASK,
1321 (bool) N_ENAB(wlc->pub));
1323 /* init basic rate lookup */
1324 wlc_rate_lookup_init(wlc, &default_rateset);
1327 /* sync up phy/radio chanspec */
1328 wlc_set_phy_chanspec(wlc, chanspec);
1331 /* band-specific init */
1332 static void WLBANDINITFN(wlc_bsinit) (wlc_info_t *wlc)
1334 WL_TRACE(("wl%d: wlc_bsinit: bandunit %d\n", wlc->pub->unit,
1335 wlc->band->bandunit));
1337 /* write ucode ACK/CTS rate table */
1338 wlc_set_ratetable(wlc);
1340 /* update some band specific mac configuration */
1341 wlc_ucode_mac_upd(wlc);
1343 /* init antenna selection */
1344 if (WLANTSEL_ENAB(wlc))
1345 wlc_antsel_init(wlc->asi);
1349 /* switch to and initialize new band */
1350 static void WLBANDINITFN(wlc_setband) (wlc_info_t *wlc, uint bandunit)
1352 int idx;
1353 wlc_bsscfg_t *cfg;
1355 ASSERT(NBANDS(wlc) > 1);
1356 ASSERT(!wlc->bandlocked);
1357 ASSERT(bandunit != wlc->band->bandunit || wlc->bandinit_pending);
1359 wlc->band = wlc->bandstate[bandunit];
1361 if (!wlc->pub->up)
1362 return;
1364 /* wait for at least one beacon before entering sleeping state */
1365 wlc->PMawakebcn = TRUE;
1366 FOREACH_AS_STA(wlc, idx, cfg)
1367 cfg->PMawakebcn = TRUE;
1368 wlc_set_ps_ctrl(wlc);
1370 /* band-specific initializations */
1371 wlc_bsinit(wlc);
1374 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1375 void wlc_wme_initparams_sta(wlc_info_t *wlc, wme_param_ie_t *pe)
1377 static const wme_param_ie_t stadef = {
1378 WME_OUI,
1379 WME_TYPE,
1380 WME_SUBTYPE_PARAM_IE,
1381 WME_VER,
1385 {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA,
1386 HTOL16(EDCF_AC_BE_TXOP_STA)},
1387 {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA,
1388 HTOL16(EDCF_AC_BK_TXOP_STA)},
1389 {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA,
1390 HTOL16(EDCF_AC_VI_TXOP_STA)},
1391 {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA,
1392 HTOL16(EDCF_AC_VO_TXOP_STA)}
1396 ASSERT(sizeof(*pe) == WME_PARAM_IE_LEN);
1397 memcpy(pe, &stadef, sizeof(*pe));
1400 void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend)
1402 int i;
1403 shm_acparams_t acp_shm;
1404 uint16 *shm_entry;
1405 struct ieee80211_tx_queue_params *params = arg;
1407 ASSERT(wlc);
1409 /* Only apply params if the core is out of reset and has clocks */
1410 if (!wlc->clk) {
1411 WL_ERROR(("wl%d: %s : no-clock\n", wlc->pub->unit, __func__));
1412 return;
1416 * AP uses AC params from wme_param_ie_ap.
1417 * AP advertises AC params from wme_param_ie.
1418 * STA uses AC params from wme_param_ie.
1421 wlc->wme_admctl = 0;
1423 do {
1424 bzero((char *)&acp_shm, sizeof(shm_acparams_t));
1425 /* find out which ac this set of params applies to */
1426 ASSERT(aci < AC_COUNT);
1427 /* set the admission control policy for this AC */
1428 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1430 /* fill in shm ac params struct */
1431 acp_shm.txop = ltoh16(params->txop);
1432 /* convert from units of 32us to us for ucode */
1433 wlc->edcf_txop[aci & 0x3] = acp_shm.txop =
1434 EDCF_TXOP2USEC(acp_shm.txop);
1435 acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK);
1437 if (aci == AC_VI && acp_shm.txop == 0
1438 && acp_shm.aifs < EDCF_AIFSN_MAX)
1439 acp_shm.aifs++;
1441 if (acp_shm.aifs < EDCF_AIFSN_MIN
1442 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1443 WL_ERROR(("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1444 wlc->pub->unit, acp_shm.aifs));
1445 continue;
1448 acp_shm.cwmin = params->cw_min;
1449 acp_shm.cwmax = params->cw_max;
1450 acp_shm.cwcur = acp_shm.cwmin;
1451 acp_shm.bslots =
1452 R_REG(wlc->osh, &wlc->regs->tsf_random) & acp_shm.cwcur;
1453 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1454 /* Indicate the new params to the ucode */
1455 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1456 wme_shmemacindex(aci) *
1457 M_EDCF_QLEN +
1458 M_EDCF_STATUS_OFF));
1459 acp_shm.status |= WME_STATUS_NEWAC;
1461 /* Fill in shm acparam table */
1462 shm_entry = (uint16 *) &acp_shm;
1463 for (i = 0; i < (int)sizeof(shm_acparams_t); i += 2)
1464 wlc_write_shm(wlc,
1465 M_EDCF_QINFO +
1466 wme_shmemacindex(aci) * M_EDCF_QLEN + i,
1467 *shm_entry++);
1469 } while (0);
1471 if (suspend)
1472 wlc_suspend_mac_and_wait(wlc);
1474 if (suspend)
1475 wlc_enable_mac(wlc);
1479 void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend)
1481 wlc_info_t *wlc = cfg->wlc;
1482 uint aci, i, j;
1483 edcf_acparam_t *edcf_acp;
1484 shm_acparams_t acp_shm;
1485 uint16 *shm_entry;
1487 ASSERT(cfg);
1488 ASSERT(wlc);
1490 /* Only apply params if the core is out of reset and has clocks */
1491 if (!wlc->clk)
1492 return;
1495 * AP uses AC params from wme_param_ie_ap.
1496 * AP advertises AC params from wme_param_ie.
1497 * STA uses AC params from wme_param_ie.
1500 edcf_acp = (edcf_acparam_t *) &wlc->wme_param_ie.acparam[0];
1502 wlc->wme_admctl = 0;
1504 for (i = 0; i < AC_COUNT; i++, edcf_acp++) {
1505 bzero((char *)&acp_shm, sizeof(shm_acparams_t));
1506 /* find out which ac this set of params applies to */
1507 aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT;
1508 ASSERT(aci < AC_COUNT);
1509 /* set the admission control policy for this AC */
1510 if (edcf_acp->ACI & EDCF_ACM_MASK) {
1511 wlc->wme_admctl |= 1 << aci;
1514 /* fill in shm ac params struct */
1515 acp_shm.txop = ltoh16(edcf_acp->TXOP);
1516 /* convert from units of 32us to us for ucode */
1517 wlc->edcf_txop[aci] = acp_shm.txop =
1518 EDCF_TXOP2USEC(acp_shm.txop);
1519 acp_shm.aifs = (edcf_acp->ACI & EDCF_AIFSN_MASK);
1521 if (aci == AC_VI && acp_shm.txop == 0
1522 && acp_shm.aifs < EDCF_AIFSN_MAX)
1523 acp_shm.aifs++;
1525 if (acp_shm.aifs < EDCF_AIFSN_MIN
1526 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1527 WL_ERROR(("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1528 wlc->pub->unit, acp_shm.aifs));
1529 continue;
1532 /* CWmin = 2^(ECWmin) - 1 */
1533 acp_shm.cwmin = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK);
1534 /* CWmax = 2^(ECWmax) - 1 */
1535 acp_shm.cwmax = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK)
1536 >> EDCF_ECWMAX_SHIFT);
1537 acp_shm.cwcur = acp_shm.cwmin;
1538 acp_shm.bslots =
1539 R_REG(wlc->osh, &wlc->regs->tsf_random) & acp_shm.cwcur;
1540 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1541 /* Indicate the new params to the ucode */
1542 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1543 wme_shmemacindex(aci) *
1544 M_EDCF_QLEN +
1545 M_EDCF_STATUS_OFF));
1546 acp_shm.status |= WME_STATUS_NEWAC;
1548 /* Fill in shm acparam table */
1549 shm_entry = (uint16 *) &acp_shm;
1550 for (j = 0; j < (int)sizeof(shm_acparams_t); j += 2)
1551 wlc_write_shm(wlc,
1552 M_EDCF_QINFO +
1553 wme_shmemacindex(aci) * M_EDCF_QLEN + j,
1554 *shm_entry++);
1557 if (suspend)
1558 wlc_suspend_mac_and_wait(wlc);
1560 if (AP_ENAB(wlc->pub) && WME_ENAB(wlc->pub)) {
1561 wlc_update_beacon(wlc);
1562 wlc_update_probe_resp(wlc, FALSE);
1565 if (suspend)
1566 wlc_enable_mac(wlc);
1570 bool BCMATTACHFN(wlc_timers_init) (wlc_info_t *wlc, int unit)
1572 wlc->wdtimer = wl_init_timer(wlc->wl, wlc_watchdog_by_timer,
1573 wlc, "watchdog");
1574 if (!wlc->wdtimer) {
1575 WL_ERROR(("wl%d: wl_init_timer for wdtimer failed\n", unit));
1576 goto fail;
1579 wlc->radio_timer = wl_init_timer(wlc->wl, wlc_radio_timer,
1580 wlc, "radio");
1581 if (!wlc->radio_timer) {
1582 WL_ERROR(("wl%d: wl_init_timer for radio_timer failed\n",
1583 unit));
1584 goto fail;
1587 return TRUE;
1589 fail:
1590 return FALSE;
1594 * Initialize wlc_info default values ...
1595 * may get overrides later in this function
1597 void BCMATTACHFN(wlc_info_init) (wlc_info_t *wlc, int unit)
1599 int i;
1600 /* Assume the device is there until proven otherwise */
1601 wlc->device_present = TRUE;
1603 /* set default power output percentage to 100 percent */
1604 wlc->txpwr_percent = 100;
1606 /* Save our copy of the chanspec */
1607 wlc->chanspec = CH20MHZ_CHSPEC(1);
1609 /* initialize CCK preamble mode to unassociated state */
1610 wlc->shortpreamble = FALSE;
1612 wlc->legacy_probe = TRUE;
1614 /* various 802.11g modes */
1615 wlc->shortslot = FALSE;
1616 wlc->shortslot_override = WLC_SHORTSLOT_AUTO;
1618 wlc->barker_overlap_control = TRUE;
1619 wlc->barker_preamble = WLC_BARKER_SHORT_ALLOWED;
1620 wlc->txburst_limit_override = AUTO;
1622 wlc_protection_upd(wlc, WLC_PROT_G_OVR, WLC_PROTECTION_AUTO);
1623 wlc_protection_upd(wlc, WLC_PROT_G_SPEC, FALSE);
1625 wlc_protection_upd(wlc, WLC_PROT_N_CFG_OVR, WLC_PROTECTION_AUTO);
1626 wlc_protection_upd(wlc, WLC_PROT_N_CFG, WLC_N_PROTECTION_OFF);
1627 wlc_protection_upd(wlc, WLC_PROT_N_NONGF_OVR, WLC_PROTECTION_AUTO);
1628 wlc_protection_upd(wlc, WLC_PROT_N_NONGF, FALSE);
1629 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR, AUTO);
1631 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, WLC_PROTECTION_CTL_OVERLAP);
1633 /* 802.11g draft 4.0 NonERP elt advertisement */
1634 wlc->include_legacy_erp = TRUE;
1636 wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF;
1637 wlc->stf->txant = ANT_TX_DEF;
1639 wlc->prb_resp_timeout = WLC_PRB_RESP_TIMEOUT;
1641 wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN;
1642 for (i = 0; i < NFIFO; i++)
1643 wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN;
1644 wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN;
1646 /* default rate fallback retry limits */
1647 wlc->SFBL = RETRY_SHORT_FB;
1648 wlc->LFBL = RETRY_LONG_FB;
1650 /* default mac retry limits */
1651 wlc->SRL = RETRY_SHORT_DEF;
1652 wlc->LRL = RETRY_LONG_DEF;
1654 /* init PM state */
1655 wlc->PM = PM_OFF; /* User's setting of PM mode through IOCTL */
1656 wlc->PM_override = FALSE; /* Prevents from going to PM if our AP is 'ill' */
1657 wlc->PMenabled = FALSE; /* Current PM state */
1658 wlc->PMpending = FALSE; /* Tracks whether STA indicated PM in the last attempt */
1659 wlc->PMblocked = FALSE; /* To allow blocking going into PM during RM and scans */
1661 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1662 wlc->WME_PM_blocked = FALSE;
1664 /* Init wme queuing method */
1665 wlc->wme_prec_queuing = FALSE;
1667 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1668 wlc->wake = FALSE;
1669 /* Are we waiting for a response to PS-Poll that we sent */
1670 wlc->PSpoll = FALSE;
1672 /* APSD defaults */
1673 wlc->wme_apsd = TRUE;
1674 wlc->apsd_sta_usp = FALSE;
1675 wlc->apsd_trigger_timeout = 0; /* disable the trigger timer */
1676 wlc->apsd_trigger_ac = AC_BITMAP_ALL;
1678 /* Set flag to indicate that hw keys should be used when available. */
1679 wlc->wsec_swkeys = FALSE;
1681 /* init the 4 static WEP default keys */
1682 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
1683 wlc->wsec_keys[i] = wlc->wsec_def_keys[i];
1684 wlc->wsec_keys[i]->idx = (uint8) i;
1687 wlc->_regulatory_domain = FALSE; /* 802.11d */
1689 /* WME QoS mode is Auto by default */
1690 wlc->pub->_wme = AUTO;
1692 #ifdef BCMSDIODEV_ENABLED
1693 wlc->pub->_priofc = TRUE; /* enable priority flow control for sdio dongle */
1694 #endif
1696 wlc->pub->_ampdu = AMPDU_AGG_HOST;
1697 wlc->pub->bcmerror = 0;
1698 wlc->ibss_allowed = TRUE;
1699 wlc->ibss_coalesce_allowed = TRUE;
1700 wlc->pub->_coex = ON;
1702 /* intialize mpc delay */
1703 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
1705 wlc->pr80838_war = TRUE;
1708 static bool wlc_state_bmac_sync(wlc_info_t *wlc)
1710 wlc_bmac_state_t state_bmac;
1712 if (wlc_bmac_state_get(wlc->hw, &state_bmac) != 0)
1713 return FALSE;
1715 wlc->machwcap = state_bmac.machwcap;
1716 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR,
1717 (int8) state_bmac.preamble_ovr);
1719 return TRUE;
1722 static uint BCMATTACHFN(wlc_attach_module) (wlc_info_t *wlc)
1724 uint err = 0;
1725 uint unit;
1726 unit = wlc->pub->unit;
1728 wlc->asi = wlc_antsel_attach(wlc, wlc->osh, wlc->pub, wlc->hw);
1729 if (wlc->asi == NULL) {
1730 WL_ERROR(("wl%d: wlc_attach: wlc_antsel_attach failed\n",
1731 unit));
1732 err = 44;
1733 goto fail;
1736 wlc->ampdu = wlc_ampdu_attach(wlc);
1737 if (wlc->ampdu == NULL) {
1738 WL_ERROR(("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit));
1739 err = 50;
1740 goto fail;
1743 /* Initialize event queue; needed before following calls */
1744 wlc->eventq =
1745 wlc_eventq_attach(wlc->pub, wlc, wlc->wl, wlc_process_eventq);
1746 if (wlc->eventq == NULL) {
1747 WL_ERROR(("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit));
1748 err = 57;
1749 goto fail;
1752 if ((wlc_stf_attach(wlc) != 0)) {
1753 WL_ERROR(("wl%d: wlc_attach: wlc_stf_attach failed\n", unit));
1754 err = 68;
1755 goto fail;
1757 fail:
1758 return err;
1761 wlc_pub_t *wlc_pub(void *wlc)
1763 return ((wlc_info_t *) wlc)->pub;
1766 #define CHIP_SUPPORTS_11N(wlc) 1
1769 * The common driver entry routine. Error codes should be unique
1771 void *BCMATTACHFN(wlc_attach) (void *wl, uint16 vendor, uint16 device,
1772 uint unit, bool piomode, osl_t *osh,
1773 void *regsva, uint bustype, void *btparam,
1774 uint *perr) {
1775 wlc_info_t *wlc;
1776 uint err = 0;
1777 uint j;
1778 wlc_pub_t *pub;
1779 wlc_txq_info_t *qi;
1780 uint n_disabled;
1782 WL_NONE(("wl%d: %s: vendor 0x%x device 0x%x\n", unit, __func__, vendor,
1783 device));
1785 ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS);
1786 ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS);
1788 /* some code depends on packed structures */
1789 ASSERT(sizeof(struct ether_addr) == ETHER_ADDR_LEN);
1790 ASSERT(sizeof(struct ether_header) == ETHER_HDR_LEN);
1791 ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE);
1792 ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN);
1793 ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN);
1794 ASSERT(sizeof(d11txh_t) == D11_TXH_LEN);
1795 ASSERT(sizeof(d11rxhdr_t) == RXHDR_LEN);
1796 ASSERT(sizeof(struct dot11_llc_snap_header) == DOT11_LLC_SNAP_HDR_LEN);
1797 ASSERT(sizeof(struct dot11_header) == DOT11_A4_HDR_LEN);
1798 ASSERT(sizeof(struct dot11_rts_frame) == DOT11_RTS_LEN);
1799 ASSERT(sizeof(struct dot11_cts_frame) == DOT11_CTS_LEN);
1800 ASSERT(sizeof(struct dot11_ack_frame) == DOT11_ACK_LEN);
1801 ASSERT(sizeof(struct dot11_ps_poll_frame) == DOT11_PS_POLL_LEN);
1802 ASSERT(sizeof(struct dot11_cf_end_frame) == DOT11_CS_END_LEN);
1803 ASSERT(sizeof(struct dot11_management_header) == DOT11_MGMT_HDR_LEN);
1804 ASSERT(sizeof(struct dot11_auth) == DOT11_AUTH_FIXED_LEN);
1805 ASSERT(sizeof(struct dot11_bcn_prb) == DOT11_BCN_PRB_LEN);
1806 ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN);
1807 ASSERT(sizeof(ht_add_ie_t) == HT_ADD_IE_LEN);
1808 ASSERT(sizeof(ht_cap_ie_t) == HT_CAP_IE_LEN);
1809 ASSERT(OFFSETOF(wl_scan_params_t, channel_list) ==
1810 WL_SCAN_PARAMS_FIXED_SIZE);
1811 ASSERT(TKIP_MIC_SIZE == (2 * sizeof(uint32)));
1812 ASSERT(ISALIGNED(OFFSETOF(wsec_key_t, data), sizeof(uint32)));
1813 ASSERT(ISPOWEROF2(MA_WINDOW_SZ));
1815 ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
1818 * Number of replay counters value used in WPA IE must match # rxivs
1819 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1820 * 'RSN Information Element' figure 8 for this mapping.
1822 ASSERT((WPA_CAP_16_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1823 && 16 == WLC_NUMRXIVS)
1824 || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1825 && 4 == WLC_NUMRXIVS));
1827 /* allocate wlc_info_t state and its substructures */
1828 wlc = (wlc_info_t *) wlc_attach_malloc(osh, unit, &err, device);
1829 if (wlc == NULL)
1830 goto fail;
1831 wlc->osh = osh;
1832 pub = wlc->pub;
1834 #if defined(BCMDBG)
1835 wlc_info_dbg = wlc;
1836 #endif
1838 wlc->band = wlc->bandstate[0];
1839 wlc->core = wlc->corestate;
1840 wlc->wl = wl;
1841 pub->unit = unit;
1842 pub->osh = osh;
1843 wlc->btparam = btparam;
1844 pub->_piomode = piomode;
1845 wlc->bandinit_pending = FALSE;
1846 /* By default restrict TKIP associations from 11n STA's */
1847 wlc->ht_wsec_restriction = WLC_HT_TKIP_RESTRICT;
1849 /* populate wlc_info_t with default values */
1850 wlc_info_init(wlc, unit);
1852 /* update sta/ap related parameters */
1853 wlc_ap_upd(wlc);
1855 /* 11n_disable nvram */
1856 n_disabled = getintvar(pub->vars, "11n_disable");
1858 /* register a module (to handle iovars) */
1859 wlc_module_register(wlc->pub, wlc_iovars, "wlc_iovars", wlc,
1860 wlc_doiovar, NULL, NULL);
1862 /* low level attach steps(all hw accesses go inside, no more in rest of the attach) */
1863 err = wlc_bmac_attach(wlc, vendor, device, unit, piomode, osh, regsva,
1864 bustype, btparam);
1865 if (err)
1866 goto fail;
1868 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1869 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1871 if (!wlc_state_bmac_sync(wlc)) {
1872 err = 20;
1873 goto fail;
1876 pub->phy_11ncapable = WLC_PHY_11N_CAP(wlc->band);
1878 /* propagate *vars* from BMAC driver to high driver */
1879 wlc_bmac_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size);
1881 #ifdef WLC_HIGH_ONLY
1882 WL_TRACE(("nvram : vars %p , vars_size %d\n", pub->vars,
1883 wlc->vars_size));
1884 #endif
1886 /* set maximum allowed duty cycle */
1887 wlc->tx_duty_cycle_ofdm =
1888 (uint16) getintvar(pub->vars, "tx_duty_cycle_ofdm");
1889 wlc->tx_duty_cycle_cck =
1890 (uint16) getintvar(pub->vars, "tx_duty_cycle_cck");
1892 wlc_stf_phy_chain_calc(wlc);
1894 /* txchain 1: txant 0, txchain 2: txant 1 */
1895 if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
1896 wlc->stf->txant = wlc->stf->hw_txchain - 1;
1898 /* push to BMAC driver */
1899 wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain,
1900 wlc->stf->hw_rxchain);
1902 #ifdef WLC_LOW
1903 /* pull up some info resulting from the low attach */
1905 int i;
1906 for (i = 0; i < NFIFO; i++)
1907 wlc->core->txavail[i] = wlc->hw->txavail[i];
1909 #endif /* WLC_LOW */
1911 wlc_bmac_hw_etheraddr(wlc->hw, &wlc->perm_etheraddr);
1913 bcopy((char *)&wlc->perm_etheraddr, (char *)&pub->cur_etheraddr,
1914 ETHER_ADDR_LEN);
1916 for (j = 0; j < NBANDS(wlc); j++) {
1917 /* Use band 1 for single band 11a */
1918 if (IS_SINGLEBAND_5G(wlc->deviceid))
1919 j = BAND_5G_INDEX;
1921 wlc->band = wlc->bandstate[j];
1923 if (!wlc_attach_stf_ant_init(wlc)) {
1924 err = 24;
1925 goto fail;
1928 /* default contention windows size limits */
1929 wlc->band->CWmin = APHY_CWMIN;
1930 wlc->band->CWmax = PHY_CWMAX;
1932 /* init gmode value */
1933 if (BAND_2G(wlc->band->bandtype)) {
1934 wlc->band->gmode = GMODE_AUTO;
1935 wlc_protection_upd(wlc, WLC_PROT_G_USER,
1936 wlc->band->gmode);
1939 /* init _n_enab supported mode */
1940 if (WLC_PHY_11N_CAP(wlc->band) && CHIP_SUPPORTS_11N(wlc)) {
1941 if (n_disabled & WLFEATURE_DISABLE_11N) {
1942 pub->_n_enab = OFF;
1943 wlc_protection_upd(wlc, WLC_PROT_N_USER, OFF);
1944 } else {
1945 pub->_n_enab = SUPPORT_11N;
1946 wlc_protection_upd(wlc, WLC_PROT_N_USER,
1947 ((pub->_n_enab ==
1948 SUPPORT_11N) ? WL_11N_2x2 :
1949 WL_11N_3x3));
1953 /* init per-band default rateset, depend on band->gmode */
1954 wlc_default_rateset(wlc, &wlc->band->defrateset);
1956 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1957 wlc_rateset_filter(&wlc->band->defrateset,
1958 &wlc->band->hw_rateset, FALSE,
1959 WLC_RATES_CCK_OFDM, RATE_MASK,
1960 (bool) N_ENAB(wlc->pub));
1963 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1964 wlc_stf_phy_txant_upd(wlc);
1966 /* attach each modules */
1967 err = wlc_attach_module(wlc);
1968 if (err != 0)
1969 goto fail;
1971 if (!wlc_timers_init(wlc, unit)) {
1972 WL_ERROR(("wl%d: %s: wlc_init_timer failed\n", unit, __func__));
1973 err = 32;
1974 goto fail;
1977 /* depend on rateset, gmode */
1978 wlc->cmi = wlc_channel_mgr_attach(wlc);
1979 if (!wlc->cmi) {
1980 WL_ERROR(("wl%d: %s: wlc_channel_mgr_attach failed\n", unit,
1981 __func__));
1982 err = 33;
1983 goto fail;
1986 /* init default when all parameters are ready, i.e. ->rateset */
1987 wlc_bss_default_init(wlc);
1990 * Complete the wlc default state initializations..
1993 /* allocate our initial queue */
1994 qi = wlc_txq_alloc(wlc, osh);
1995 if (qi == NULL) {
1996 WL_ERROR(("wl%d: %s: failed to malloc tx queue\n", unit,
1997 __func__));
1998 err = 100;
1999 goto fail;
2001 wlc->active_queue = qi;
2003 wlc->bsscfg[0] = wlc->cfg;
2004 wlc->cfg->_idx = 0;
2005 wlc->cfg->wlc = wlc;
2006 pub->txmaxpkts = MAXTXPKTS;
2008 WLCNTSET(pub->_cnt->version, WL_CNT_T_VERSION);
2009 WLCNTSET(pub->_cnt->length, sizeof(wl_cnt_t));
2011 WLCNTSET(pub->_wme_cnt->version, WL_WME_CNT_VERSION);
2012 WLCNTSET(pub->_wme_cnt->length, sizeof(wl_wme_cnt_t));
2014 wlc_wme_initparams_sta(wlc, &wlc->wme_param_ie);
2016 wlc->mimoft = FT_HT;
2017 wlc->ht_cap.cap = HT_CAP;
2018 if (HT_ENAB(wlc->pub))
2019 wlc->stf->ldpc = AUTO;
2021 wlc->mimo_40txbw = AUTO;
2022 wlc->ofdm_40txbw = AUTO;
2023 wlc->cck_40txbw = AUTO;
2024 wlc_update_mimo_band_bwcap(wlc, WLC_N_BW_20IN2G_40IN5G);
2026 /* Enable setting the RIFS Mode bit by default in HT Info IE */
2027 wlc->rifs_advert = AUTO;
2029 /* Set default values of SGI */
2030 if (WLC_SGI_CAP_PHY(wlc)) {
2031 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
2032 wlc->sgi_tx = AUTO;
2033 } else if (WLCISSSLPNPHY(wlc->band)) {
2034 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
2035 wlc->sgi_tx = AUTO;
2036 } else {
2037 wlc_ht_update_sgi_rx(wlc, 0);
2038 wlc->sgi_tx = OFF;
2041 /* *******nvram 11n config overrides Start ********* */
2043 /* apply the sgi override from nvram conf */
2044 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_TX)
2045 wlc->sgi_tx = OFF;
2047 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_RX)
2048 wlc_ht_update_sgi_rx(wlc, 0);
2050 /* apply the stbc override from nvram conf */
2051 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_TX) {
2052 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
2053 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
2054 wlc->ht_cap.cap &= ~HT_CAP_TX_STBC;
2056 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_RX)
2057 wlc_stf_stbc_rx_set(wlc, HT_CAP_RX_STBC_NO);
2059 /* apply the GF override from nvram conf */
2060 if (n_disabled & WLFEATURE_DISABLE_11N_GF)
2061 wlc->ht_cap.cap &= ~HT_CAP_GF;
2063 /* initialize radio_mpc_disable according to wlc->mpc */
2064 wlc_radio_mpc_upd(wlc);
2066 if (WLANTSEL_ENAB(wlc)) {
2067 if ((CHIPID(wlc->pub->sih->chip)) == BCM43235_CHIP_ID) {
2068 if ((getintvar(wlc->pub->vars, "aa2g") == 7) ||
2069 (getintvar(wlc->pub->vars, "aa5g") == 7)) {
2070 wlc_bmac_antsel_set(wlc->hw, 1);
2072 } else {
2073 wlc_bmac_antsel_set(wlc->hw, wlc->asi->antsel_avail);
2077 if (perr)
2078 *perr = 0;
2080 return (void *)wlc;
2082 fail:
2083 WL_ERROR(("wl%d: %s: failed with err %d\n", unit, __func__, err));
2084 if (wlc)
2085 wlc_detach(wlc);
2087 if (perr)
2088 *perr = err;
2089 return NULL;
2092 static void BCMNMIATTACHFN(wlc_attach_antgain_init) (wlc_info_t *wlc)
2094 uint unit;
2095 unit = wlc->pub->unit;
2097 if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) {
2098 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2099 wlc->band->antgain = 8;
2100 } else if (wlc->band->antgain == -1) {
2101 WL_ERROR(("wl%d: %s: Invalid antennas available in srom, using 2dB\n", unit, __func__));
2102 wlc->band->antgain = 8;
2103 } else {
2104 int8 gain, fract;
2105 /* Older sroms specified gain in whole dbm only. In order
2106 * be able to specify qdbm granularity and remain backward compatible
2107 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2108 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2109 * -32 - 31. Examples: 0x1 = 1 db,
2110 * 0xc1 = 1.75 db (1 + 3 quarters),
2111 * 0x3f = -1 (-1 + 0 quarters),
2112 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2113 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2115 gain = wlc->band->antgain & 0x3f;
2116 gain <<= 2; /* Sign extend */
2117 gain >>= 2;
2118 fract = (wlc->band->antgain & 0xc0) >> 6;
2119 wlc->band->antgain = 4 * gain + fract;
2123 static bool BCMATTACHFN(wlc_attach_stf_ant_init) (wlc_info_t *wlc)
2125 int aa;
2126 uint unit;
2127 char *vars;
2128 int bandtype;
2130 unit = wlc->pub->unit;
2131 vars = wlc->pub->vars;
2132 bandtype = wlc->band->bandtype;
2134 /* get antennas available */
2135 aa = (int8) getintvar(vars, (BAND_5G(bandtype) ? "aa5g" : "aa2g"));
2136 if (aa == 0)
2137 aa = (int8) getintvar(vars,
2138 (BAND_5G(bandtype) ? "aa1" : "aa0"));
2139 if ((aa < 1) || (aa > 15)) {
2140 WL_ERROR(("wl%d: %s: Invalid antennas available in srom (0x%x), using 3.\n", unit, __func__, aa));
2141 aa = 3;
2144 /* reset the defaults if we have a single antenna */
2145 if (aa == 1) {
2146 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0;
2147 wlc->stf->txant = ANT_TX_FORCE_0;
2148 } else if (aa == 2) {
2149 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1;
2150 wlc->stf->txant = ANT_TX_FORCE_1;
2151 } else {
2154 /* Compute Antenna Gain */
2155 wlc->band->antgain =
2156 (int8) getintvar(vars, (BAND_5G(bandtype) ? "ag1" : "ag0"));
2157 wlc_attach_antgain_init(wlc);
2159 return TRUE;
2162 #ifdef WLC_HIGH_ONLY
2163 /* HIGH_ONLY bmac_attach, which sync over LOW_ONLY bmac_attach states */
2165 BCMATTACHFN(wlc_bmac_attach) (wlc_info_t *wlc, uint16 vendor, uint16 device,
2166 uint unit, bool piomode, osl_t *osh,
2167 void *regsva, uint bustype, void *btparam) {
2168 wlc_bmac_revinfo_t revinfo;
2169 uint idx = 0;
2170 rpc_info_t *rpc = (rpc_info_t *) btparam;
2172 ASSERT(bustype == RPC_BUS);
2174 /* install the rpc handle in the various state structures used by stub RPC functions */
2175 wlc->rpc = rpc;
2176 wlc->hw->rpc = rpc;
2177 wlc->hw->osh = osh;
2179 wlc->regs = 0;
2181 wlc->rpctx = wlc_rpctx_attach(wlc->pub, wlc);
2182 if (wlc->rpctx == NULL)
2183 return -1;
2186 * FIFO 0
2187 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
2189 /* Always initialized */
2190 ASSERT(NRPCTXBUFPOST <= NTXD);
2191 wlc_rpctx_fifoinit(wlc->rpctx, TX_DATA_FIFO, NRPCTXBUFPOST);
2192 wlc_rpctx_fifoinit(wlc->rpctx, TX_CTL_FIFO, NRPCTXBUFPOST);
2193 wlc_rpctx_fifoinit(wlc->rpctx, TX_BCMC_FIFO, NRPCTXBUFPOST);
2195 /* VI and BK inited only if WME */
2196 if (WME_ENAB(wlc->pub)) {
2197 wlc_rpctx_fifoinit(wlc->rpctx, TX_AC_BK_FIFO, NRPCTXBUFPOST);
2198 wlc_rpctx_fifoinit(wlc->rpctx, TX_AC_VI_FIFO, NRPCTXBUFPOST);
2201 /* Allocate SB handle */
2202 wlc->pub->sih = osl_malloc(wlc->osh, sizeof(si_t));
2203 if (!wlc->pub->sih)
2204 return -1;
2205 bzero(wlc->pub->sih, sizeof(si_t));
2207 /* sync up revinfo with BMAC */
2208 bzero(&revinfo, sizeof(wlc_bmac_revinfo_t));
2209 if (wlc_bmac_revinfo_get(wlc->hw, &revinfo) != 0)
2210 return -1;
2211 wlc->vendorid = (uint16) revinfo.vendorid;
2212 wlc->deviceid = (uint16) revinfo.deviceid;
2214 wlc->pub->boardrev = (uint16) revinfo.boardrev;
2215 wlc->pub->corerev = revinfo.corerev;
2216 wlc->pub->sromrev = (uint8) revinfo.sromrev;
2217 wlc->pub->sih->chiprev = revinfo.chiprev;
2218 wlc->pub->sih->chip = revinfo.chip;
2219 wlc->pub->sih->chippkg = revinfo.chippkg;
2220 wlc->pub->sih->boardtype = revinfo.boardtype;
2221 wlc->pub->sih->boardvendor = revinfo.boardvendor;
2222 wlc->pub->sih->bustype = revinfo.bustype;
2223 wlc->pub->sih->buscoretype = revinfo.buscoretype;
2224 wlc->pub->sih->buscorerev = revinfo.buscorerev;
2225 wlc->pub->sih->issim = (bool) revinfo.issim;
2226 wlc->pub->sih->rpc = rpc;
2228 if (revinfo.nbands == 0 || revinfo.nbands > 2)
2229 return -1;
2230 wlc->pub->_nbands = revinfo.nbands;
2232 for (idx = 0; idx < wlc->pub->_nbands; idx++) {
2233 uint bandunit, bandtype; /* To access bandstate */
2234 wlc_phy_t *pi = osl_malloc(wlc->osh, sizeof(wlc_phy_t));
2236 if (!pi)
2237 return -1;
2238 bzero(pi, sizeof(wlc_phy_t));
2239 pi->rpc = rpc;
2241 bandunit = revinfo.band[idx].bandunit;
2242 bandtype = revinfo.band[idx].bandtype;
2243 wlc->bandstate[bandunit]->radiorev =
2244 (uint8) revinfo.band[idx].radiorev;
2245 wlc->bandstate[bandunit]->phytype =
2246 (uint16) revinfo.band[idx].phytype;
2247 wlc->bandstate[bandunit]->phyrev =
2248 (uint16) revinfo.band[idx].phyrev;
2249 wlc->bandstate[bandunit]->radioid =
2250 (uint16) revinfo.band[idx].radioid;
2251 wlc->bandstate[bandunit]->abgphy_encore =
2252 revinfo.band[idx].abgphy_encore;
2254 wlc->bandstate[bandunit]->pi = pi;
2255 wlc->bandstate[bandunit]->bandunit = bandunit;
2256 wlc->bandstate[bandunit]->bandtype = bandtype;
2259 /* misc stuff */
2261 return 0;
2264 /* Free the convenience handles */
2265 int wlc_bmac_detach(wlc_info_t *wlc)
2267 uint idx;
2269 if (wlc->pub->sih) {
2270 osl_mfree(wlc->osh, (void *)wlc->pub->sih, sizeof(si_t));
2271 wlc->pub->sih = NULL;
2274 for (idx = 0; idx < MAXBANDS; idx++)
2275 if (wlc->bandstate[idx]->pi) {
2276 osl_mfree(wlc->osh, wlc->bandstate[idx]->pi,
2277 sizeof(wlc_phy_t));
2278 wlc->bandstate[idx]->pi = NULL;
2281 if (wlc->rpctx) {
2282 wlc_rpctx_detach(wlc->rpctx);
2283 wlc->rpctx = NULL;
2286 return 0;
2290 #endif /* WLC_HIGH_ONLY */
2292 static void BCMATTACHFN(wlc_timers_deinit) (wlc_info_t *wlc)
2294 /* free timer state */
2295 if (wlc->wdtimer) {
2296 wl_free_timer(wlc->wl, wlc->wdtimer);
2297 wlc->wdtimer = NULL;
2299 if (wlc->radio_timer) {
2300 wl_free_timer(wlc->wl, wlc->radio_timer);
2301 wlc->radio_timer = NULL;
2305 static void BCMATTACHFN(wlc_detach_module) (wlc_info_t *wlc)
2307 if (wlc->asi) {
2308 wlc_antsel_detach(wlc->asi);
2309 wlc->asi = NULL;
2312 if (wlc->ampdu) {
2313 wlc_ampdu_detach(wlc->ampdu);
2314 wlc->ampdu = NULL;
2317 wlc_stf_detach(wlc);
2321 * Return a count of the number of driver callbacks still pending.
2323 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2324 * touch hardware registers since the d11core may be in reset and clock may not be available.
2325 * One exception is sb register access, which is possible if crystal is turned on
2326 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2328 uint BCMATTACHFN(wlc_detach) (wlc_info_t *wlc)
2330 uint i;
2331 uint callbacks = 0;
2333 if (wlc == NULL)
2334 return 0;
2336 WL_TRACE(("wl%d: %s\n", wlc->pub->unit, __func__));
2338 ASSERT(!wlc->pub->up);
2340 callbacks += wlc_bmac_detach(wlc);
2342 /* delete software timers */
2343 if (!wlc_radio_monitor_stop(wlc))
2344 callbacks++;
2346 if (wlc->eventq) {
2347 wlc_eventq_detach(wlc->eventq);
2348 wlc->eventq = NULL;
2351 wlc_channel_mgr_detach(wlc->cmi);
2353 wlc_timers_deinit(wlc);
2355 wlc_detach_module(wlc);
2357 /* free other state */
2359 #ifdef WLC_HIGH_ONLY
2360 /* High-Only driver has an allocated copy of vars, monolithic just
2361 * references the wlc->hw->vars which is freed in wlc_bmac_detach()
2363 if (wlc->pub->vars) {
2364 osl_mfree(wlc->osh, wlc->pub->vars, wlc->vars_size);
2365 wlc->pub->vars = NULL;
2367 #endif
2369 #ifdef BCMDBG
2370 if (wlc->country_ie_override) {
2371 osl_mfree(wlc->osh, wlc->country_ie_override,
2372 wlc->country_ie_override->len + TLV_HDR_LEN);
2373 wlc->country_ie_override = NULL;
2375 #endif /* BCMDBG */
2378 /* free dumpcb list */
2379 dumpcb_t *prev, *ptr;
2380 prev = ptr = wlc->dumpcb_head;
2381 while (ptr) {
2382 ptr = prev->next;
2383 osl_mfree(wlc->osh, prev, sizeof(dumpcb_t));
2384 prev = ptr;
2386 wlc->dumpcb_head = NULL;
2389 /* Detach from iovar manager */
2390 wlc_module_unregister(wlc->pub, "wlc_iovars", wlc);
2393 if (wlc->ap) {
2394 wlc_ap_detach(wlc->ap);
2395 wlc->ap = NULL;
2399 while (wlc->tx_queues != NULL) {
2400 wlc_txq_free(wlc, wlc->osh, wlc->tx_queues);
2404 * consistency check: wlc_module_register/wlc_module_unregister calls
2405 * should match therefore nothing should be left here.
2407 for (i = 0; i < WLC_MAXMODULES; i++)
2408 ASSERT(wlc->modulecb[i].name[0] == '\0');
2410 wlc_detach_mfree(wlc, wlc->osh);
2411 return callbacks;
2414 /* update state that depends on the current value of "ap" */
2415 void wlc_ap_upd(wlc_info_t *wlc)
2417 if (AP_ENAB(wlc->pub))
2418 wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */
2419 else
2420 wlc->PLCPHdr_override = WLC_PLCP_SHORT; /* STA-BSS; short capable */
2422 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2423 wlc->vlan_mode = AP_ENAB(wlc->pub) ? OFF : AUTO;
2425 /* fixup mpc */
2426 wlc->mpc = TRUE;
2429 /* read hwdisable state and propagate to wlc flag */
2430 static void wlc_radio_hwdisable_upd(wlc_info_t *wlc)
2432 if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off)
2433 return;
2435 if (wlc_bmac_radio_read_hwdisabled(wlc->hw)) {
2436 mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2437 } else {
2438 mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2442 /* return TRUE if Minimum Power Consumption should be entered, FALSE otherwise */
2443 bool wlc_is_non_delay_mpc(wlc_info_t *wlc)
2445 return FALSE;
2448 bool wlc_ismpc(wlc_info_t *wlc)
2450 return (wlc->mpc_delay_off == 0) && (wlc_is_non_delay_mpc(wlc));
2453 void wlc_radio_mpc_upd(wlc_info_t *wlc)
2455 bool mpc_radio, radio_state;
2458 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2459 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2460 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2461 * the radio is going down.
2463 if (!wlc->mpc) {
2464 if (!wlc->pub->radio_disabled)
2465 return;
2466 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2467 wlc_radio_upd(wlc);
2468 if (!wlc->pub->radio_disabled)
2469 wlc_radio_monitor_stop(wlc);
2470 return;
2474 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2475 * to go ON, always call radio_upd synchronously
2476 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2478 radio_state =
2479 (mboolisset(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE) ? OFF :
2480 ON);
2481 mpc_radio = (wlc_ismpc(wlc) == TRUE) ? OFF : ON;
2483 if (radio_state == ON && mpc_radio == OFF)
2484 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2485 else if (radio_state == OFF && mpc_radio == ON) {
2486 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2487 wlc_radio_upd(wlc);
2488 if (wlc->mpc_offcnt < WLC_MPC_THRESHOLD) {
2489 wlc->mpc_dlycnt = WLC_MPC_MAX_DELAYCNT;
2490 } else
2491 wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
2492 wlc->mpc_dur += OSL_SYSUPTIME() - wlc->mpc_laston_ts;
2494 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2495 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2496 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2498 if ((wlc->prev_non_delay_mpc == FALSE) &&
2499 (wlc_is_non_delay_mpc(wlc) == TRUE) && wlc->mpc_delay_off) {
2500 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2502 wlc->prev_non_delay_mpc = wlc_is_non_delay_mpc(wlc);
2506 * centralized radio disable/enable function,
2507 * invoke radio enable/disable after updating hwradio status
2509 static void wlc_radio_upd(wlc_info_t *wlc)
2511 if (wlc->pub->radio_disabled)
2512 wlc_radio_disable(wlc);
2513 else
2514 wlc_radio_enable(wlc);
2517 /* maintain LED behavior in down state */
2518 static void wlc_down_led_upd(wlc_info_t *wlc)
2520 ASSERT(!wlc->pub->up);
2522 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2523 /* turn on sbclk if necessary */
2524 if (!AP_ENAB(wlc->pub)) {
2525 wlc_pllreq(wlc, TRUE, WLC_PLLREQ_FLIP);
2527 wlc_pllreq(wlc, FALSE, WLC_PLLREQ_FLIP);
2531 void wlc_radio_disable(wlc_info_t *wlc)
2533 if (!wlc->pub->up) {
2534 wlc_down_led_upd(wlc);
2535 return;
2538 wlc_radio_monitor_start(wlc);
2539 wl_down(wlc->wl);
2542 static void wlc_radio_enable(wlc_info_t *wlc)
2544 if (wlc->pub->up)
2545 return;
2547 if (DEVICEREMOVED(wlc))
2548 return;
2550 if (!wlc->down_override) { /* imposed by wl down/out ioctl */
2551 wl_up(wlc->wl);
2555 /* periodical query hw radio button while driver is "down" */
2556 static void wlc_radio_timer(void *arg)
2558 wlc_info_t *wlc = (wlc_info_t *) arg;
2560 if (DEVICEREMOVED(wlc)) {
2561 WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__));
2562 wl_down(wlc->wl);
2563 return;
2566 /* cap mpc off count */
2567 if (wlc->mpc_offcnt < WLC_MPC_MAX_DELAYCNT)
2568 wlc->mpc_offcnt++;
2570 /* validate all the reasons driver could be down and running this radio_timer */
2571 ASSERT(wlc->pub->radio_disabled || wlc->down_override);
2572 wlc_radio_hwdisable_upd(wlc);
2573 wlc_radio_upd(wlc);
2576 static bool wlc_radio_monitor_start(wlc_info_t *wlc)
2578 /* Don't start the timer if HWRADIO feature is disabled */
2579 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO))
2580 return TRUE;
2582 wlc->radio_monitor = TRUE;
2583 wlc_pllreq(wlc, TRUE, WLC_PLLREQ_RADIO_MON);
2584 wl_add_timer(wlc->wl, wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, TRUE);
2585 return TRUE;
2588 bool wlc_radio_monitor_stop(wlc_info_t *wlc)
2590 if (!wlc->radio_monitor)
2591 return TRUE;
2593 ASSERT((wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO) !=
2594 WL_SWFL_NOHWRADIO);
2596 wlc->radio_monitor = FALSE;
2597 wlc_pllreq(wlc, FALSE, WLC_PLLREQ_RADIO_MON);
2598 return wl_del_timer(wlc->wl, wlc->radio_timer);
2601 /* bring the driver down, but don't reset hardware */
2602 void wlc_out(wlc_info_t *wlc)
2604 wlc_bmac_set_noreset(wlc->hw, TRUE);
2605 wlc_radio_upd(wlc);
2606 wl_down(wlc->wl);
2607 wlc_bmac_set_noreset(wlc->hw, FALSE);
2609 /* core clk is TRUE in BMAC driver due to noreset, need to mirror it in HIGH */
2610 wlc->clk = TRUE;
2612 /* This will make sure that when 'up' is done
2613 * after 'out' it'll restore hardware (especially gpios)
2615 wlc->pub->hw_up = FALSE;
2618 #if defined(BCMDBG)
2619 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2620 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2621 * in prec_map. Of course, ignore this rule when block_datafifo is set
2623 static bool wlc_tx_prec_map_verify(wlc_info_t *wlc)
2625 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2626 * fail the check.
2628 if (!EDCF_ENAB(wlc->pub)) {
2629 if (!(WLC_TX_FIFO_CHECK(wlc, TX_DATA_FIFO) ||
2630 WLC_TX_FIFO_CHECK(wlc, TX_CTL_FIFO)))
2631 return FALSE;
2632 else
2633 return TRUE;
2636 return WLC_TX_FIFO_CHECK(wlc, TX_AC_BK_FIFO)
2637 && WLC_TX_FIFO_CHECK(wlc, TX_AC_BE_FIFO)
2638 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VI_FIFO)
2639 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VO_FIFO);
2641 #endif /* BCMDBG */
2643 static void wlc_watchdog_by_timer(void *arg)
2645 wlc_info_t *wlc = (wlc_info_t *) arg;
2646 wlc_watchdog(arg);
2647 if (WLC_WATCHDOG_TBTT(wlc)) {
2648 /* set to normal osl watchdog period */
2649 wl_del_timer(wlc->wl, wlc->wdtimer);
2650 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
2651 TRUE);
2655 /* common watchdog code */
2656 static void wlc_watchdog(void *arg)
2658 wlc_info_t *wlc = (wlc_info_t *) arg;
2659 int i;
2660 wlc_bsscfg_t *cfg;
2662 WL_TRACE(("wl%d: wlc_watchdog\n", wlc->pub->unit));
2664 if (!wlc->pub->up)
2665 return;
2667 if (DEVICEREMOVED(wlc)) {
2668 WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__));
2669 wl_down(wlc->wl);
2670 return;
2673 /* increment second count */
2674 wlc->pub->now++;
2676 /* delay radio disable */
2677 if (wlc->mpc_delay_off) {
2678 if (--wlc->mpc_delay_off == 0) {
2679 mboolset(wlc->pub->radio_disabled,
2680 WL_RADIO_MPC_DISABLE);
2681 if (wlc->mpc && wlc_ismpc(wlc))
2682 wlc->mpc_offcnt = 0;
2683 wlc->mpc_laston_ts = OSL_SYSUPTIME();
2687 /* mpc sync */
2688 wlc_radio_mpc_upd(wlc);
2689 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2690 wlc_radio_hwdisable_upd(wlc);
2691 wlc_radio_upd(wlc);
2692 /* if ismpc, driver should be in down state if up/down is allowed */
2693 if (wlc->mpc && wlc_ismpc(wlc))
2694 ASSERT(!wlc->pub->up);
2695 /* if radio is disable, driver may be down, quit here */
2696 if (wlc->pub->radio_disabled)
2697 return;
2699 #ifdef WLC_LOW
2700 wlc_bmac_watchdog(wlc);
2701 #endif
2702 #ifdef WLC_HIGH_ONLY
2703 /* maintenance */
2704 wlc_bmac_rpc_watchdog(wlc);
2705 #endif
2707 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2708 if ((WLC_UPDATE_STATS(wlc))
2709 && (!(wlc->pub->now % SW_TIMER_MAC_STAT_UPD)))
2710 wlc_statsupd(wlc);
2712 /* Manage TKIP countermeasures timers */
2713 FOREACH_BSS(wlc, i, cfg) {
2714 if (cfg->tk_cm_dt) {
2715 cfg->tk_cm_dt--;
2717 if (cfg->tk_cm_bt) {
2718 cfg->tk_cm_bt--;
2722 /* Call any registered watchdog handlers */
2723 for (i = 0; i < WLC_MAXMODULES; i++) {
2724 if (wlc->modulecb[i].watchdog_fn)
2725 wlc->modulecb[i].watchdog_fn(wlc->modulecb[i].hdl);
2728 if (WLCISNPHY(wlc->band) && !wlc->pub->tempsense_disable &&
2729 ((wlc->pub->now - wlc->tempsense_lasttime) >=
2730 WLC_TEMPSENSE_PERIOD)) {
2731 wlc->tempsense_lasttime = wlc->pub->now;
2732 wlc_tempsense_upd(wlc);
2734 #ifdef WLC_LOW
2735 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2736 ASSERT(wlc_bmac_taclear(wlc->hw, TRUE));
2737 #endif
2739 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2740 ASSERT(wlc_tx_prec_map_verify(wlc));
2742 ASSERT(wlc_ps_check(wlc));
2745 /* make interface operational */
2746 int BCMINITFN(wlc_up) (wlc_info_t *wlc)
2748 WL_TRACE(("wl%d: %s:\n", wlc->pub->unit, __func__));
2750 /* HW is turned off so don't try to access it */
2751 if (wlc->pub->hw_off || DEVICEREMOVED(wlc))
2752 return BCME_RADIOOFF;
2754 if (!wlc->pub->hw_up) {
2755 wlc_bmac_hw_up(wlc->hw);
2756 wlc->pub->hw_up = TRUE;
2759 if ((wlc->pub->boardflags & BFL_FEM)
2760 && (CHIPID(wlc->pub->sih->chip) == BCM4313_CHIP_ID)) {
2761 if (wlc->pub->boardrev >= 0x1250
2762 && (wlc->pub->boardflags & BFL_FEM_BT)) {
2763 wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL,
2764 MHF5_4313_GPIOCTRL, WLC_BAND_ALL);
2765 } else {
2766 wlc_mhf(wlc, MHF4, MHF4_EXTPA_ENABLE, MHF4_EXTPA_ENABLE,
2767 WLC_BAND_ALL);
2772 * Need to read the hwradio status here to cover the case where the system
2773 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2774 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2775 * don't call radio_update to avoid looping wlc_up.
2777 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2779 if (!wlc->pub->radio_disabled) {
2780 int status = wlc_bmac_up_prep(wlc->hw);
2781 if (status == BCME_RADIOOFF) {
2782 if (!mboolisset
2783 (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) {
2784 int idx;
2785 wlc_bsscfg_t *bsscfg;
2786 mboolset(wlc->pub->radio_disabled,
2787 WL_RADIO_HW_DISABLE);
2789 FOREACH_BSS(wlc, idx, bsscfg) {
2790 if (!BSSCFG_STA(bsscfg)
2791 || !bsscfg->enable || !bsscfg->BSS)
2792 continue;
2793 WL_ERROR(("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n", wlc->pub->unit, idx));
2796 } else
2797 ASSERT(!status);
2800 if (wlc->pub->radio_disabled) {
2801 wlc_radio_monitor_start(wlc);
2802 return 0;
2805 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2806 wlc->clk = TRUE;
2808 wlc_radio_monitor_stop(wlc);
2810 /* Set EDCF hostflags */
2811 if (EDCF_ENAB(wlc->pub)) {
2812 wlc_mhf(wlc, MHF1, MHF1_EDCF, MHF1_EDCF, WLC_BAND_ALL);
2813 } else {
2814 wlc_mhf(wlc, MHF1, MHF1_EDCF, 0, WLC_BAND_ALL);
2817 if (WLC_WAR16165(wlc))
2818 wlc_mhf(wlc, MHF2, MHF2_PCISLOWCLKWAR, MHF2_PCISLOWCLKWAR,
2819 WLC_BAND_ALL);
2821 wl_init(wlc->wl);
2822 wlc->pub->up = TRUE;
2824 if (wlc->bandinit_pending) {
2825 wlc_suspend_mac_and_wait(wlc);
2826 wlc_set_chanspec(wlc, wlc->default_bss->chanspec);
2827 wlc->bandinit_pending = FALSE;
2828 wlc_enable_mac(wlc);
2831 wlc_bmac_up_finish(wlc->hw);
2833 /* other software states up after ISR is running */
2834 /* start APs that were to be brought up but are not up yet */
2835 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2837 /* Program the TX wme params with the current settings */
2838 wlc_wme_retries_write(wlc);
2840 /* start one second watchdog timer */
2841 ASSERT(!wlc->WDarmed);
2842 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, TRUE);
2843 wlc->WDarmed = TRUE;
2845 /* ensure antenna config is up to date */
2846 wlc_stf_phy_txant_upd(wlc);
2847 /* ensure LDPC config is in sync */
2848 wlc_ht_update_ldpc(wlc, wlc->stf->ldpc);
2850 return 0;
2853 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2854 static void BCMINITFN(wlc_tx_prec_map_init) (wlc_info_t *wlc)
2856 wlc->tx_prec_map = WLC_PREC_BMP_ALL;
2857 bzero(wlc->fifo2prec_map, sizeof(uint16) * NFIFO);
2859 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2860 * if either is full.
2862 if (!EDCF_ENAB(wlc->pub)) {
2863 wlc->fifo2prec_map[TX_DATA_FIFO] = WLC_PREC_BMP_ALL;
2864 wlc->fifo2prec_map[TX_CTL_FIFO] = WLC_PREC_BMP_ALL;
2865 } else {
2866 wlc->fifo2prec_map[TX_AC_BK_FIFO] = WLC_PREC_BMP_AC_BK;
2867 wlc->fifo2prec_map[TX_AC_BE_FIFO] = WLC_PREC_BMP_AC_BE;
2868 wlc->fifo2prec_map[TX_AC_VI_FIFO] = WLC_PREC_BMP_AC_VI;
2869 wlc->fifo2prec_map[TX_AC_VO_FIFO] = WLC_PREC_BMP_AC_VO;
2873 static uint BCMUNINITFN(wlc_down_del_timer) (wlc_info_t *wlc)
2875 uint callbacks = 0;
2877 return callbacks;
2881 * Mark the interface nonoperational, stop the software mechanisms,
2882 * disable the hardware, free any transient buffer state.
2883 * Return a count of the number of driver callbacks still pending.
2885 uint BCMUNINITFN(wlc_down) (wlc_info_t *wlc)
2888 uint callbacks = 0;
2889 int i;
2890 bool dev_gone = FALSE;
2891 wlc_txq_info_t *qi;
2893 WL_TRACE(("wl%d: %s:\n", wlc->pub->unit, __func__));
2895 /* check if we are already in the going down path */
2896 if (wlc->going_down) {
2897 WL_ERROR(("wl%d: %s: Driver going down so return\n",
2898 wlc->pub->unit, __func__));
2899 return 0;
2901 if (!wlc->pub->up)
2902 return callbacks;
2904 /* in between, mpc could try to bring down again.. */
2905 wlc->going_down = TRUE;
2907 callbacks += wlc_bmac_down_prep(wlc->hw);
2909 dev_gone = DEVICEREMOVED(wlc);
2911 /* Call any registered down handlers */
2912 for (i = 0; i < WLC_MAXMODULES; i++) {
2913 if (wlc->modulecb[i].down_fn)
2914 callbacks +=
2915 wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl);
2918 /* cancel the watchdog timer */
2919 if (wlc->WDarmed) {
2920 if (!wl_del_timer(wlc->wl, wlc->wdtimer))
2921 callbacks++;
2922 wlc->WDarmed = FALSE;
2924 /* cancel all other timers */
2925 callbacks += wlc_down_del_timer(wlc);
2927 /* interrupt must have been blocked */
2928 ASSERT((wlc->macintmask == 0) || !wlc->pub->up);
2930 wlc->pub->up = FALSE;
2932 wlc_phy_mute_upd(wlc->band->pi, FALSE, PHY_MUTE_ALL);
2934 /* clear txq flow control */
2935 wlc_txflowcontrol_reset(wlc);
2937 /* flush tx queues */
2938 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
2939 pktq_flush(wlc->osh, &qi->q, TRUE, NULL, 0);
2940 ASSERT(pktq_empty(&qi->q));
2943 /* flush event queue.
2944 * Should be the last thing done after all the events are generated
2945 * Just delivers the events synchronously instead of waiting for a timer
2947 callbacks += wlc_eventq_down(wlc->eventq);
2949 callbacks += wlc_bmac_down_finish(wlc->hw);
2951 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2952 wlc->clk = FALSE;
2954 #ifdef WLC_HIGH_ONLY
2955 wlc_rpctx_txreclaim(wlc->rpctx);
2956 #endif
2958 /* Verify all packets are flushed from the driver */
2959 if (PKTALLOCED(wlc->osh) != 0) {
2960 WL_ERROR(("%d packets not freed at wlc_down!!!!!!\n",
2961 PKTALLOCED(wlc->osh)));
2963 #ifdef BCMDBG
2964 /* Since all the packets should have been freed,
2965 * all callbacks should have been called
2967 for (i = 1; i <= wlc->pub->tunables->maxpktcb; i++)
2968 ASSERT(wlc->pkt_callback[i].fn == NULL);
2969 #endif
2970 wlc->going_down = FALSE;
2971 return callbacks;
2974 /* Set the current gmode configuration */
2975 int wlc_set_gmode(wlc_info_t *wlc, uint8 gmode, bool config)
2977 int ret = 0;
2978 uint i;
2979 wlc_rateset_t rs;
2980 /* Default to 54g Auto */
2981 int8 shortslot = WLC_SHORTSLOT_AUTO; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2982 bool shortslot_restrict = FALSE; /* Restrict association to stations that support shortslot
2984 bool ignore_bcns = TRUE; /* Ignore legacy beacons on the same channel */
2985 bool ofdm_basic = FALSE; /* Make 6, 12, and 24 basic rates */
2986 int preamble = WLC_PLCP_LONG; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2987 bool preamble_restrict = FALSE; /* Restrict association to stations that support short
2988 * preambles
2990 wlcband_t *band;
2992 /* if N-support is enabled, allow Gmode set as long as requested
2993 * Gmode is not GMODE_LEGACY_B
2995 if (N_ENAB(wlc->pub) && gmode == GMODE_LEGACY_B)
2996 return BCME_UNSUPPORTED;
2998 /* verify that we are dealing with 2G band and grab the band pointer */
2999 if (wlc->band->bandtype == WLC_BAND_2G)
3000 band = wlc->band;
3001 else if ((NBANDS(wlc) > 1) &&
3002 (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == WLC_BAND_2G))
3003 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
3004 else
3005 return BCME_BADBAND;
3007 /* Legacy or bust when no OFDM is supported by regulatory */
3008 if ((wlc_channel_locale_flags_in_band(wlc->cmi, band->bandunit) &
3009 WLC_NO_OFDM) && (gmode != GMODE_LEGACY_B))
3010 return BCME_RANGE;
3012 /* update configuration value */
3013 if (config == TRUE)
3014 wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode);
3016 /* Clear supported rates filter */
3017 bzero(&wlc->sup_rates_override, sizeof(wlc_rateset_t));
3019 /* Clear rateset override */
3020 bzero(&rs, sizeof(wlc_rateset_t));
3022 switch (gmode) {
3023 case GMODE_LEGACY_B:
3024 shortslot = WLC_SHORTSLOT_OFF;
3025 wlc_rateset_copy(&gphy_legacy_rates, &rs);
3027 break;
3029 case GMODE_LRS:
3030 if (AP_ENAB(wlc->pub))
3031 wlc_rateset_copy(&cck_rates, &wlc->sup_rates_override);
3032 break;
3034 case GMODE_AUTO:
3035 /* Accept defaults */
3036 break;
3038 case GMODE_ONLY:
3039 ofdm_basic = TRUE;
3040 preamble = WLC_PLCP_SHORT;
3041 preamble_restrict = TRUE;
3042 break;
3044 case GMODE_PERFORMANCE:
3045 if (AP_ENAB(wlc->pub)) /* Put all rates into the Supported Rates element */
3046 wlc_rateset_copy(&cck_ofdm_rates,
3047 &wlc->sup_rates_override);
3049 shortslot = WLC_SHORTSLOT_ON;
3050 shortslot_restrict = TRUE;
3051 ofdm_basic = TRUE;
3052 preamble = WLC_PLCP_SHORT;
3053 preamble_restrict = TRUE;
3054 break;
3056 default:
3057 /* Error */
3058 WL_ERROR(("wl%d: %s: invalid gmode %d\n", wlc->pub->unit,
3059 __func__, gmode));
3060 return BCME_UNSUPPORTED;
3064 * If we are switching to gmode == GMODE_LEGACY_B,
3065 * clean up rate info that may refer to OFDM rates.
3067 if ((gmode == GMODE_LEGACY_B) && (band->gmode != GMODE_LEGACY_B)) {
3068 band->gmode = gmode;
3069 if (band->rspec_override && !IS_CCK(band->rspec_override)) {
3070 band->rspec_override = 0;
3071 wlc_reprate_init(wlc);
3073 if (band->mrspec_override && !IS_CCK(band->mrspec_override)) {
3074 band->mrspec_override = 0;
3078 band->gmode = gmode;
3080 wlc->ignore_bcns = ignore_bcns;
3082 wlc->shortslot_override = shortslot;
3084 if (AP_ENAB(wlc->pub)) {
3085 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
3086 wlc->PLCPHdr_override =
3087 (preamble !=
3088 WLC_PLCP_LONG) ? WLC_PLCP_SHORT : WLC_PLCP_AUTO;
3091 if ((AP_ENAB(wlc->pub) && preamble != WLC_PLCP_LONG)
3092 || preamble == WLC_PLCP_SHORT)
3093 wlc->default_bss->capability |= DOT11_CAP_SHORT;
3094 else
3095 wlc->default_bss->capability &= ~DOT11_CAP_SHORT;
3097 /* Update shortslot capability bit for AP and IBSS */
3098 if ((AP_ENAB(wlc->pub) && shortslot == WLC_SHORTSLOT_AUTO) ||
3099 shortslot == WLC_SHORTSLOT_ON)
3100 wlc->default_bss->capability |= DOT11_CAP_SHORTSLOT;
3101 else
3102 wlc->default_bss->capability &= ~DOT11_CAP_SHORTSLOT;
3104 /* Use the default 11g rateset */
3105 if (!rs.count)
3106 wlc_rateset_copy(&cck_ofdm_rates, &rs);
3108 if (ofdm_basic) {
3109 for (i = 0; i < rs.count; i++) {
3110 if (rs.rates[i] == WLC_RATE_6M
3111 || rs.rates[i] == WLC_RATE_12M
3112 || rs.rates[i] == WLC_RATE_24M)
3113 rs.rates[i] |= WLC_RATE_FLAG;
3117 /* Set default bss rateset */
3118 wlc->default_bss->rateset.count = rs.count;
3119 bcopy((char *)rs.rates, (char *)wlc->default_bss->rateset.rates,
3120 sizeof(wlc->default_bss->rateset.rates));
3122 return ret;
3125 static int wlc_nmode_validate(wlc_info_t *wlc, int32 nmode)
3127 int err = 0;
3129 switch (nmode) {
3131 case OFF:
3132 break;
3134 case AUTO:
3135 case WL_11N_2x2:
3136 case WL_11N_3x3:
3137 if (!(WLC_PHY_11N_CAP(wlc->band)))
3138 err = BCME_BADBAND;
3139 break;
3141 default:
3142 err = BCME_RANGE;
3143 break;
3146 return err;
3149 int wlc_set_nmode(wlc_info_t *wlc, int32 nmode)
3151 uint i;
3152 int err;
3154 err = wlc_nmode_validate(wlc, nmode);
3155 ASSERT(err == 0);
3156 if (err)
3157 return err;
3159 switch (nmode) {
3160 case OFF:
3161 wlc->pub->_n_enab = OFF;
3162 wlc->default_bss->flags &= ~WLC_BSS_HT;
3163 /* delete the mcs rates from the default and hw ratesets */
3164 wlc_rateset_mcs_clear(&wlc->default_bss->rateset);
3165 for (i = 0; i < NBANDS(wlc); i++) {
3166 memset(wlc->bandstate[i]->hw_rateset.mcs, 0,
3167 MCSSET_LEN);
3168 if (IS_MCS(wlc->band->rspec_override)) {
3169 wlc->bandstate[i]->rspec_override = 0;
3170 wlc_reprate_init(wlc);
3172 if (IS_MCS(wlc->band->mrspec_override))
3173 wlc->bandstate[i]->mrspec_override = 0;
3175 break;
3177 case AUTO:
3178 if (wlc->stf->txstreams == WL_11N_3x3)
3179 nmode = WL_11N_3x3;
3180 else
3181 nmode = WL_11N_2x2;
3182 case WL_11N_2x2:
3183 case WL_11N_3x3:
3184 ASSERT(WLC_PHY_11N_CAP(wlc->band));
3185 /* force GMODE_AUTO if NMODE is ON */
3186 wlc_set_gmode(wlc, GMODE_AUTO, TRUE);
3187 if (nmode == WL_11N_3x3)
3188 wlc->pub->_n_enab = SUPPORT_HT;
3189 else
3190 wlc->pub->_n_enab = SUPPORT_11N;
3191 wlc->default_bss->flags |= WLC_BSS_HT;
3192 /* add the mcs rates to the default and hw ratesets */
3193 wlc_rateset_mcs_build(&wlc->default_bss->rateset,
3194 wlc->stf->txstreams);
3195 for (i = 0; i < NBANDS(wlc); i++)
3196 memcpy(wlc->bandstate[i]->hw_rateset.mcs,
3197 wlc->default_bss->rateset.mcs, MCSSET_LEN);
3198 break;
3200 default:
3201 ASSERT(0);
3202 break;
3205 return err;
3208 static int wlc_set_rateset(wlc_info_t *wlc, wlc_rateset_t *rs_arg)
3210 wlc_rateset_t rs, new;
3211 uint bandunit;
3213 bcopy((char *)rs_arg, (char *)&rs, sizeof(wlc_rateset_t));
3215 /* check for bad count value */
3216 if ((rs.count == 0) || (rs.count > WLC_NUMRATES))
3217 return BCME_BADRATESET;
3219 /* try the current band */
3220 bandunit = wlc->band->bandunit;
3221 bcopy((char *)&rs, (char *)&new, sizeof(wlc_rateset_t));
3222 if (wlc_rate_hwrs_filter_sort_validate
3223 (&new, &wlc->bandstate[bandunit]->hw_rateset, TRUE,
3224 wlc->stf->txstreams))
3225 goto good;
3227 /* try the other band */
3228 if (IS_MBAND_UNLOCKED(wlc)) {
3229 bandunit = OTHERBANDUNIT(wlc);
3230 bcopy((char *)&rs, (char *)&new, sizeof(wlc_rateset_t));
3231 if (wlc_rate_hwrs_filter_sort_validate(&new,
3232 &wlc->
3233 bandstate[bandunit]->
3234 hw_rateset, TRUE,
3235 wlc->stf->txstreams))
3236 goto good;
3239 return BCME_ERROR;
3241 good:
3242 /* apply new rateset */
3243 bcopy((char *)&new, (char *)&wlc->default_bss->rateset,
3244 sizeof(wlc_rateset_t));
3245 bcopy((char *)&new, (char *)&wlc->bandstate[bandunit]->defrateset,
3246 sizeof(wlc_rateset_t));
3247 return 0;
3250 /* simplified integer set interface for common ioctl handler */
3251 int wlc_set(wlc_info_t *wlc, int cmd, int arg)
3253 return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL);
3256 /* simplified integer get interface for common ioctl handler */
3257 int wlc_get(wlc_info_t *wlc, int cmd, int *arg)
3259 return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL);
3262 static void wlc_ofdm_rateset_war(wlc_info_t *wlc)
3264 uint8 r;
3265 bool war = FALSE;
3267 if (wlc->cfg->associated)
3268 r = wlc->cfg->current_bss->rateset.rates[0];
3269 else
3270 r = wlc->default_bss->rateset.rates[0];
3272 wlc_phy_ofdm_rateset_war(wlc->band->pi, war);
3274 return;
3278 wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3280 return _wlc_ioctl(wlc, cmd, arg, len, wlcif);
3283 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3284 static int
3285 _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3287 int val, *pval;
3288 bool bool_val;
3289 int bcmerror;
3290 d11regs_t *regs;
3291 uint i;
3292 struct scb *nextscb;
3293 bool ta_ok;
3294 uint band;
3295 rw_reg_t *r;
3296 wlc_bsscfg_t *bsscfg;
3297 osl_t *osh;
3298 wlc_bss_info_t *current_bss;
3300 /* update bsscfg pointer */
3301 bsscfg = NULL; /* XXX: Hack bsscfg to be size one and use this globally */
3302 current_bss = NULL;
3304 /* initialize the following to get rid of compiler warning */
3305 nextscb = NULL;
3306 ta_ok = FALSE;
3307 band = 0;
3308 r = NULL;
3310 /* If the device is turned off, then it's not "removed" */
3311 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) {
3312 WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__));
3313 wl_down(wlc->wl);
3314 return BCME_ERROR;
3317 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
3319 /* default argument is generic integer */
3320 pval = arg ? (int *)arg : NULL;
3322 /* This will prevent the misaligned access */
3323 if (pval && (uint32) len >= sizeof(val))
3324 bcopy(pval, &val, sizeof(val));
3325 else
3326 val = 0;
3328 /* bool conversion to avoid duplication below */
3329 bool_val = val != 0;
3331 if (cmd != WLC_SET_CHANNEL)
3332 WL_NONE(("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n", cmd,
3333 (uint) val, val, len));
3335 bcmerror = 0;
3336 regs = wlc->regs;
3337 osh = wlc->osh;
3339 /* A few commands don't need any arguments; all the others do. */
3340 switch (cmd) {
3341 case WLC_UP:
3342 case WLC_OUT:
3343 case WLC_DOWN:
3344 case WLC_DISASSOC:
3345 case WLC_RESTART:
3346 case WLC_REBOOT:
3347 case WLC_START_CHANNEL_QA:
3348 case WLC_INIT:
3349 break;
3351 default:
3352 if ((arg == NULL) || (len <= 0)) {
3353 WL_ERROR(("wl%d: %s: Command %d needs arguments\n",
3354 wlc->pub->unit, __func__, cmd));
3355 bcmerror = BCME_BADARG;
3356 goto done;
3360 switch (cmd) {
3362 #if defined(BCMDBG)
3363 case WLC_GET_MSGLEVEL:
3364 *pval = wl_msg_level;
3365 break;
3367 case WLC_SET_MSGLEVEL:
3368 wl_msg_level = val;
3369 break;
3370 #endif
3372 case WLC_GET_INSTANCE:
3373 *pval = wlc->pub->unit;
3374 break;
3376 case WLC_GET_CHANNEL:{
3377 channel_info_t *ci = (channel_info_t *) arg;
3379 ASSERT(len > (int)sizeof(ci));
3381 ci->hw_channel =
3382 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC);
3383 ci->target_channel =
3384 CHSPEC_CHANNEL(wlc->default_bss->chanspec);
3385 ci->scan_channel = 0;
3387 break;
3390 case WLC_SET_CHANNEL:{
3391 chanspec_t chspec = CH20MHZ_CHSPEC(val);
3393 if (val < 0 || val > MAXCHANNEL) {
3394 bcmerror = BCME_OUTOFRANGECHAN;
3395 break;
3398 if (!wlc_valid_chanspec_db(wlc->cmi, chspec)) {
3399 bcmerror = BCME_BADCHAN;
3400 break;
3403 if (!wlc->pub->up && IS_MBAND_UNLOCKED(wlc)) {
3404 if (wlc->band->bandunit !=
3405 CHSPEC_WLCBANDUNIT(chspec))
3406 wlc->bandinit_pending = TRUE;
3407 else
3408 wlc->bandinit_pending = FALSE;
3411 wlc->default_bss->chanspec = chspec;
3412 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3413 if (wlc->pub->up && !wlc->pub->associated &&
3414 (WLC_BAND_PI_RADIO_CHANSPEC != chspec)) {
3415 wlc_set_home_chanspec(wlc, chspec);
3416 wlc_suspend_mac_and_wait(wlc);
3417 wlc_set_chanspec(wlc, chspec);
3418 wlc_enable_mac(wlc);
3420 #ifdef WLC_HIGH_ONLY
3421 /* delay for channel change */
3422 msleep(50);
3423 #endif
3424 break;
3427 #if defined(BCMDBG)
3428 case WLC_GET_UCFLAGS:
3429 if (!wlc->pub->up) {
3430 bcmerror = BCME_NOTUP;
3431 break;
3434 /* optional band is stored in the second integer of incoming buffer */
3435 band =
3436 (len <
3437 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3439 /* bcmerror checking */
3440 bcmerror = wlc_iocregchk(wlc, band);
3441 if (bcmerror)
3442 break;
3444 if (val >= MHFMAX) {
3445 bcmerror = BCME_RANGE;
3446 break;
3449 *pval = wlc_bmac_mhf_get(wlc->hw, (uint8) val, WLC_BAND_AUTO);
3450 break;
3452 case WLC_SET_UCFLAGS:
3453 if (!wlc->pub->up) {
3454 bcmerror = BCME_NOTUP;
3455 break;
3458 /* optional band is stored in the second integer of incoming buffer */
3459 band =
3460 (len <
3461 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3463 /* bcmerror checking */
3464 bcmerror = wlc_iocregchk(wlc, band);
3465 if (bcmerror)
3466 break;
3468 i = (uint16) val;
3469 if (i >= MHFMAX) {
3470 bcmerror = BCME_RANGE;
3471 break;
3474 wlc_mhf(wlc, (uint8) i, 0xffff, (uint16) (val >> NBITS(uint16)),
3475 WLC_BAND_AUTO);
3476 break;
3478 case WLC_GET_SHMEM:
3479 ta_ok = TRUE;
3481 /* optional band is stored in the second integer of incoming buffer */
3482 band =
3483 (len <
3484 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3486 /* bcmerror checking */
3487 bcmerror = wlc_iocregchk(wlc, band);
3488 if (bcmerror)
3489 break;
3491 if (val & 1) {
3492 bcmerror = BCME_BADADDR;
3493 break;
3496 *pval = wlc_read_shm(wlc, (uint16) val);
3497 break;
3499 case WLC_SET_SHMEM:
3500 ta_ok = TRUE;
3502 /* optional band is stored in the second integer of incoming buffer */
3503 band =
3504 (len <
3505 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3507 /* bcmerror checking */
3508 bcmerror = wlc_iocregchk(wlc, band);
3509 if (bcmerror)
3510 break;
3512 if (val & 1) {
3513 bcmerror = BCME_BADADDR;
3514 break;
3517 wlc_write_shm(wlc, (uint16) val,
3518 (uint16) (val >> NBITS(uint16)));
3519 break;
3521 case WLC_R_REG: /* MAC registers */
3522 ta_ok = TRUE;
3523 r = (rw_reg_t *) arg;
3524 band = WLC_BAND_AUTO;
3526 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3527 bcmerror = BCME_BUFTOOSHORT;
3528 break;
3531 if (len >= (int)sizeof(rw_reg_t))
3532 band = r->band;
3534 /* bcmerror checking */
3535 bcmerror = wlc_iocregchk(wlc, band);
3536 if (bcmerror)
3537 break;
3539 if ((r->byteoff + r->size) > sizeof(d11regs_t)) {
3540 bcmerror = BCME_BADADDR;
3541 break;
3543 if (r->size == sizeof(uint32))
3544 r->val =
3545 R_REG(osh,
3546 (uint32 *) ((uchar *) (uintptr) regs +
3547 r->byteoff));
3548 else if (r->size == sizeof(uint16))
3549 r->val =
3550 R_REG(osh,
3551 (uint16 *) ((uchar *) (uintptr) regs +
3552 r->byteoff));
3553 else
3554 bcmerror = BCME_BADADDR;
3555 break;
3557 case WLC_W_REG:
3558 ta_ok = TRUE;
3559 r = (rw_reg_t *) arg;
3560 band = WLC_BAND_AUTO;
3562 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3563 bcmerror = BCME_BUFTOOSHORT;
3564 break;
3567 if (len >= (int)sizeof(rw_reg_t))
3568 band = r->band;
3570 /* bcmerror checking */
3571 bcmerror = wlc_iocregchk(wlc, band);
3572 if (bcmerror)
3573 break;
3575 if (r->byteoff + r->size > sizeof(d11regs_t)) {
3576 bcmerror = BCME_BADADDR;
3577 break;
3579 if (r->size == sizeof(uint32))
3580 W_REG(osh,
3581 (uint32 *) ((uchar *) (uintptr) regs +
3582 r->byteoff), r->val);
3583 else if (r->size == sizeof(uint16))
3584 W_REG(osh,
3585 (uint16 *) ((uchar *) (uintptr) regs +
3586 r->byteoff), r->val);
3587 else
3588 bcmerror = BCME_BADADDR;
3589 break;
3590 #endif /* BCMDBG */
3592 case WLC_GET_TXANT:
3593 *pval = wlc->stf->txant;
3594 break;
3596 case WLC_SET_TXANT:
3597 bcmerror = wlc_stf_ant_txant_validate(wlc, (int8) val);
3598 if (bcmerror < 0)
3599 break;
3601 wlc->stf->txant = (int8) val;
3603 /* if down, we are done */
3604 if (!wlc->pub->up)
3605 break;
3607 wlc_suspend_mac_and_wait(wlc);
3609 wlc_stf_phy_txant_upd(wlc);
3610 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
3612 wlc_enable_mac(wlc);
3614 break;
3616 case WLC_GET_ANTDIV:{
3617 uint8 phy_antdiv;
3619 /* return configured value if core is down */
3620 if (!wlc->pub->up) {
3621 *pval = wlc->stf->ant_rx_ovr;
3623 } else {
3624 if (wlc_phy_ant_rxdiv_get
3625 (wlc->band->pi, &phy_antdiv))
3626 *pval = (int)phy_antdiv;
3627 else
3628 *pval = (int)wlc->stf->ant_rx_ovr;
3631 break;
3633 case WLC_SET_ANTDIV:
3634 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3635 if ((val < -1) || (val > 3)) {
3636 bcmerror = BCME_RANGE;
3637 break;
3640 if (val == -1)
3641 val = ANT_RX_DIV_DEF;
3643 wlc->stf->ant_rx_ovr = (uint8) val;
3644 wlc_phy_ant_rxdiv_set(wlc->band->pi, (uint8) val);
3645 break;
3647 case WLC_GET_RX_ANT:{ /* get latest used rx antenna */
3648 uint16 rxstatus;
3650 if (!wlc->pub->up) {
3651 bcmerror = BCME_NOTUP;
3652 break;
3655 rxstatus = R_REG(wlc->osh, &wlc->regs->phyrxstatus0);
3656 if (rxstatus == 0xdead || rxstatus == (uint16) -1) {
3657 bcmerror = BCME_ERROR;
3658 break;
3660 *pval = (rxstatus & PRXS0_RXANT_UPSUBBAND) ? 1 : 0;
3661 break;
3664 #if defined(BCMDBG)
3665 case WLC_GET_UCANTDIV:
3666 if (!wlc->clk) {
3667 bcmerror = BCME_NOCLK;
3668 break;
3671 *pval =
3672 (wlc_bmac_mhf_get(wlc->hw, MHF1, WLC_BAND_AUTO) &
3673 MHF1_ANTDIV);
3674 break;
3676 case WLC_SET_UCANTDIV:{
3677 if (!wlc->pub->up) {
3678 bcmerror = BCME_NOTUP;
3679 break;
3682 /* if multiband, band must be locked */
3683 if (IS_MBAND_UNLOCKED(wlc)) {
3684 bcmerror = BCME_NOTBANDLOCKED;
3685 break;
3688 /* 4322 supports antdiv in phy, no need to set it to ucode */
3689 if (WLCISNPHY(wlc->band)
3690 && D11REV_IS(wlc->pub->corerev, 16)) {
3691 WL_ERROR(("wl%d: can't set ucantdiv for 4322\n",
3692 wlc->pub->unit));
3693 bcmerror = BCME_UNSUPPORTED;
3694 } else
3695 wlc_mhf(wlc, MHF1, MHF1_ANTDIV,
3696 (val ? MHF1_ANTDIV : 0), WLC_BAND_AUTO);
3697 break;
3699 #endif /* defined(BCMDBG) */
3701 case WLC_GET_SRL:
3702 *pval = wlc->SRL;
3703 break;
3705 case WLC_SET_SRL:
3706 if (val >= 1 && val <= RETRY_SHORT_MAX) {
3707 int ac;
3708 wlc->SRL = (uint16) val;
3710 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3712 for (ac = 0; ac < AC_COUNT; ac++) {
3713 WLC_WME_RETRY_SHORT_SET(wlc, ac, wlc->SRL);
3715 wlc_wme_retries_write(wlc);
3716 } else
3717 bcmerror = BCME_RANGE;
3718 break;
3720 case WLC_GET_LRL:
3721 *pval = wlc->LRL;
3722 break;
3724 case WLC_SET_LRL:
3725 if (val >= 1 && val <= 255) {
3726 int ac;
3727 wlc->LRL = (uint16) val;
3729 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3731 for (ac = 0; ac < AC_COUNT; ac++) {
3732 WLC_WME_RETRY_LONG_SET(wlc, ac, wlc->LRL);
3734 wlc_wme_retries_write(wlc);
3735 } else
3736 bcmerror = BCME_RANGE;
3737 break;
3739 case WLC_GET_CWMIN:
3740 *pval = wlc->band->CWmin;
3741 break;
3743 case WLC_SET_CWMIN:
3744 if (!wlc->clk) {
3745 bcmerror = BCME_NOCLK;
3746 break;
3749 if (val >= 1 && val <= 255) {
3750 wlc_set_cwmin(wlc, (uint16) val);
3751 } else
3752 bcmerror = BCME_RANGE;
3753 break;
3755 case WLC_GET_CWMAX:
3756 *pval = wlc->band->CWmax;
3757 break;
3759 case WLC_SET_CWMAX:
3760 if (!wlc->clk) {
3761 bcmerror = BCME_NOCLK;
3762 break;
3765 if (val >= 255 && val <= 2047) {
3766 wlc_set_cwmax(wlc, (uint16) val);
3767 } else
3768 bcmerror = BCME_RANGE;
3769 break;
3771 case WLC_GET_RADIO: /* use mask if don't want to expose some internal bits */
3772 *pval = wlc->pub->radio_disabled;
3773 break;
3775 case WLC_SET_RADIO:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3776 * set
3778 uint16 radiomask, radioval;
3779 uint validbits =
3780 WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE;
3781 mbool new = 0;
3783 radiomask = (val & 0xffff0000) >> 16;
3784 radioval = val & 0x0000ffff;
3786 if ((radiomask == 0) || (radiomask & ~validbits)
3787 || (radioval & ~validbits)
3788 || ((radioval & ~radiomask) != 0)) {
3789 WL_ERROR(("SET_RADIO with wrong bits 0x%x\n",
3790 val));
3791 bcmerror = BCME_RANGE;
3792 break;
3795 new =
3796 (wlc->pub->radio_disabled & ~radiomask) | radioval;
3797 wlc->pub->radio_disabled = new;
3799 wlc_radio_hwdisable_upd(wlc);
3800 wlc_radio_upd(wlc);
3801 break;
3804 case WLC_GET_PHYTYPE:
3805 *pval = WLC_PHYTYPE(wlc->band->phytype);
3806 break;
3808 #if defined(BCMDBG)
3809 case WLC_GET_KEY:
3810 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc))) {
3811 wl_wsec_key_t key;
3813 wsec_key_t *src_key = wlc->wsec_keys[val];
3815 if (len < (int)sizeof(key)) {
3816 bcmerror = BCME_BUFTOOSHORT;
3817 break;
3820 bzero((char *)&key, sizeof(key));
3821 if (src_key) {
3822 key.index = src_key->id;
3823 key.len = src_key->len;
3824 bcopy(src_key->data, key.data, key.len);
3825 key.algo = src_key->algo;
3826 if (WSEC_SOFTKEY(wlc, src_key, bsscfg))
3827 key.flags |= WL_SOFT_KEY;
3828 if (src_key->flags & WSEC_PRIMARY_KEY)
3829 key.flags |= WL_PRIMARY_KEY;
3831 bcopy(src_key->ea.octet, key.ea.octet,
3832 ETHER_ADDR_LEN);
3835 bcopy((char *)&key, arg, sizeof(key));
3836 } else
3837 bcmerror = BCME_BADKEYIDX;
3838 break;
3839 #endif /* defined(BCMDBG) */
3841 case WLC_SET_KEY:
3842 bcmerror =
3843 wlc_iovar_op(wlc, "wsec_key", NULL, 0, arg, len, IOV_SET,
3844 wlcif);
3845 break;
3847 case WLC_GET_KEY_SEQ:{
3848 wsec_key_t *key;
3850 if (len < DOT11_WPA_KEY_RSC_LEN) {
3851 bcmerror = BCME_BUFTOOSHORT;
3852 break;
3855 /* Return the key's tx iv as an EAPOL sequence counter.
3856 * This will be used to supply the RSC value to a supplicant.
3857 * The format is 8 bytes, with least significant in seq[0].
3860 key = WSEC_KEY(wlc, val);
3861 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc)) &&
3862 (key != NULL)) {
3863 uint8 seq[DOT11_WPA_KEY_RSC_LEN];
3864 uint16 lo;
3865 uint32 hi;
3866 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3867 if ((bsscfg->WPA_auth & WPA_AUTH_NONE)
3868 && ETHER_ISNULLADDR(&key->ea)) {
3869 lo = bsscfg->wpa_none_txiv.lo;
3870 hi = bsscfg->wpa_none_txiv.hi;
3871 } else {
3872 lo = key->txiv.lo;
3873 hi = key->txiv.hi;
3876 /* format the buffer, low to high */
3877 seq[0] = lo & 0xff;
3878 seq[1] = (lo >> 8) & 0xff;
3879 seq[2] = hi & 0xff;
3880 seq[3] = (hi >> 8) & 0xff;
3881 seq[4] = (hi >> 16) & 0xff;
3882 seq[5] = (hi >> 24) & 0xff;
3883 seq[6] = 0;
3884 seq[7] = 0;
3886 bcopy((char *)seq, arg, sizeof(seq));
3887 } else {
3888 bcmerror = BCME_BADKEYIDX;
3890 break;
3893 case WLC_GET_CURR_RATESET:{
3894 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3895 wlc_rateset_t *rs;
3897 if (bsscfg->associated)
3898 rs = &current_bss->rateset;
3899 else
3900 rs = &wlc->default_bss->rateset;
3902 if (len < (int)(rs->count + sizeof(rs->count))) {
3903 bcmerror = BCME_BUFTOOSHORT;
3904 break;
3907 /* Copy only legacy rateset section */
3908 ret_rs->count = rs->count;
3909 bcopy(&rs->rates, &ret_rs->rates, rs->count);
3910 break;
3913 case WLC_GET_RATESET:{
3914 wlc_rateset_t rs;
3915 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3917 bzero(&rs, sizeof(wlc_rateset_t));
3918 wlc_default_rateset(wlc, (wlc_rateset_t *) &rs);
3920 if (len < (int)(rs.count + sizeof(rs.count))) {
3921 bcmerror = BCME_BUFTOOSHORT;
3922 break;
3925 /* Copy only legacy rateset section */
3926 ret_rs->count = rs.count;
3927 bcopy(&rs.rates, &ret_rs->rates, rs.count);
3928 break;
3931 case WLC_SET_RATESET:{
3932 wlc_rateset_t rs;
3933 wl_rateset_t *in_rs = (wl_rateset_t *) arg;
3935 if (len < (int)(in_rs->count + sizeof(in_rs->count))) {
3936 bcmerror = BCME_BUFTOOSHORT;
3937 break;
3940 if (in_rs->count > WLC_NUMRATES) {
3941 bcmerror = BCME_BUFTOOLONG;
3942 break;
3945 bzero(&rs, sizeof(wlc_rateset_t));
3947 /* Copy only legacy rateset section */
3948 rs.count = in_rs->count;
3949 bcopy(&in_rs->rates, &rs.rates, rs.count);
3951 /* merge rateset coming in with the current mcsset */
3952 if (N_ENAB(wlc->pub)) {
3953 if (bsscfg->associated)
3954 bcopy(&current_bss->rateset.mcs[0],
3955 rs.mcs, MCSSET_LEN);
3956 else
3957 bcopy(&wlc->default_bss->rateset.mcs[0],
3958 rs.mcs, MCSSET_LEN);
3961 bcmerror = wlc_set_rateset(wlc, &rs);
3963 if (!bcmerror)
3964 wlc_ofdm_rateset_war(wlc);
3966 break;
3969 case WLC_GET_BCNPRD:
3970 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3971 *pval = current_bss->beacon_period;
3972 else
3973 *pval = wlc->default_bss->beacon_period;
3974 break;
3976 case WLC_SET_BCNPRD:
3977 /* range [1, 0xffff] */
3978 if (val >= DOT11_MIN_BEACON_PERIOD
3979 && val <= DOT11_MAX_BEACON_PERIOD) {
3980 wlc->default_bss->beacon_period = (uint16) val;
3981 } else
3982 bcmerror = BCME_RANGE;
3983 break;
3985 case WLC_GET_DTIMPRD:
3986 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3987 *pval = current_bss->dtim_period;
3988 else
3989 *pval = wlc->default_bss->dtim_period;
3990 break;
3992 case WLC_SET_DTIMPRD:
3993 /* range [1, 0xff] */
3994 if (val >= DOT11_MIN_DTIM_PERIOD
3995 && val <= DOT11_MAX_DTIM_PERIOD) {
3996 wlc->default_bss->dtim_period = (uint8) val;
3997 } else
3998 bcmerror = BCME_RANGE;
3999 break;
4001 #ifdef SUPPORT_PS
4002 case WLC_GET_PM:
4003 *pval = wlc->PM;
4004 break;
4006 case WLC_SET_PM:
4007 if ((val >= PM_OFF) && (val <= PM_MAX)) {
4008 wlc->PM = (uint8) val;
4009 if (wlc->pub->up) {
4011 /* Change watchdog driver to align watchdog with tbtt if possible */
4012 wlc_watchdog_upd(wlc, PS_ALLOWED(wlc));
4013 } else
4014 bcmerror = BCME_ERROR;
4015 break;
4016 #endif /* SUPPORT_PS */
4018 #ifdef SUPPORT_PS
4019 #ifdef BCMDBG
4020 case WLC_GET_WAKE:
4021 if (AP_ENAB(wlc->pub)) {
4022 bcmerror = BCME_NOTSTA;
4023 break;
4025 *pval = wlc->wake;
4026 break;
4028 case WLC_SET_WAKE:
4029 if (AP_ENAB(wlc->pub)) {
4030 bcmerror = BCME_NOTSTA;
4031 break;
4034 wlc->wake = val ? TRUE : FALSE;
4036 /* if down, we're done */
4037 if (!wlc->pub->up)
4038 break;
4040 /* apply to the mac */
4041 wlc_set_ps_ctrl(wlc);
4042 break;
4043 #endif /* BCMDBG */
4044 #endif /* SUPPORT_PS */
4046 case WLC_GET_REVINFO:
4047 bcmerror = wlc_get_revision_info(wlc, arg, (uint) len);
4048 break;
4050 case WLC_GET_AP:
4051 *pval = (int)AP_ENAB(wlc->pub);
4052 break;
4054 case WLC_GET_ATIM:
4055 if (bsscfg->associated)
4056 *pval = (int)current_bss->atim_window;
4057 else
4058 *pval = (int)wlc->default_bss->atim_window;
4059 break;
4061 case WLC_SET_ATIM:
4062 wlc->default_bss->atim_window = (uint32) val;
4063 break;
4065 case WLC_GET_PKTCNTS:{
4066 get_pktcnt_t *pktcnt = (get_pktcnt_t *) pval;
4067 if (WLC_UPDATE_STATS(wlc))
4068 wlc_statsupd(wlc);
4069 pktcnt->rx_good_pkt = WLCNTVAL(wlc->pub->_cnt->rxframe);
4070 pktcnt->rx_bad_pkt = WLCNTVAL(wlc->pub->_cnt->rxerror);
4071 pktcnt->tx_good_pkt =
4072 WLCNTVAL(wlc->pub->_cnt->txfrmsnt);
4073 pktcnt->tx_bad_pkt =
4074 WLCNTVAL(wlc->pub->_cnt->txerror) +
4075 WLCNTVAL(wlc->pub->_cnt->txfail);
4076 if (len >= (int)sizeof(get_pktcnt_t)) {
4077 /* Be backward compatible - only if buffer is large enough */
4078 pktcnt->rx_ocast_good_pkt =
4079 WLCNTVAL(wlc->pub->_cnt->rxmfrmocast);
4081 break;
4084 #ifdef SUPPORT_HWKEY
4085 case WLC_GET_WSEC:
4086 bcmerror =
4087 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_GET,
4088 wlcif);
4089 break;
4091 case WLC_SET_WSEC:
4092 bcmerror =
4093 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_SET,
4094 wlcif);
4095 break;
4097 case WLC_GET_WPA_AUTH:
4098 *pval = (int)bsscfg->WPA_auth;
4099 break;
4101 case WLC_SET_WPA_AUTH:
4102 /* change of WPA_Auth modifies the PS_ALLOWED state */
4103 if (BSSCFG_STA(bsscfg)) {
4104 bsscfg->WPA_auth = (uint16) val;
4105 } else
4106 bsscfg->WPA_auth = (uint16) val;
4107 break;
4108 #endif /* SUPPORT_HWKEY */
4110 case WLC_GET_BANDLIST:
4111 /* count of number of bands, followed by each band type */
4112 *pval++ = NBANDS(wlc);
4113 *pval++ = wlc->band->bandtype;
4114 if (NBANDS(wlc) > 1)
4115 *pval++ = wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype;
4116 break;
4118 case WLC_GET_BAND:
4119 *pval = wlc->bandlocked ? wlc->band->bandtype : WLC_BAND_AUTO;
4120 break;
4122 case WLC_GET_PHYLIST:
4124 uchar *cp = arg;
4125 if (len < 3) {
4126 bcmerror = BCME_BUFTOOSHORT;
4127 break;
4130 if (WLCISNPHY(wlc->band)) {
4131 *cp++ = 'n';
4132 } else if (WLCISLCNPHY(wlc->band)) {
4133 *cp++ = 'c';
4134 } else if (WLCISSSLPNPHY(wlc->band)) {
4135 *cp++ = 's';
4137 *cp = '\0';
4138 break;
4141 case WLC_GET_SHORTSLOT:
4142 *pval = wlc->shortslot;
4143 break;
4145 case WLC_GET_SHORTSLOT_OVERRIDE:
4146 *pval = wlc->shortslot_override;
4147 break;
4149 case WLC_SET_SHORTSLOT_OVERRIDE:
4150 if ((val != WLC_SHORTSLOT_AUTO) &&
4151 (val != WLC_SHORTSLOT_OFF) && (val != WLC_SHORTSLOT_ON)) {
4152 bcmerror = BCME_RANGE;
4153 break;
4156 wlc->shortslot_override = (int8) val;
4158 /* shortslot is an 11g feature, so no more work if we are
4159 * currently on the 5G band
4161 if (BAND_5G(wlc->band->bandtype))
4162 break;
4164 if (wlc->pub->up && wlc->pub->associated) {
4165 /* let watchdog or beacon processing update shortslot */
4166 } else if (wlc->pub->up) {
4167 /* unassociated shortslot is off */
4168 wlc_switch_shortslot(wlc, FALSE);
4169 } else {
4170 /* driver is down, so just update the wlc_info value */
4171 if (wlc->shortslot_override == WLC_SHORTSLOT_AUTO) {
4172 wlc->shortslot = FALSE;
4173 } else {
4174 wlc->shortslot =
4175 (wlc->shortslot_override ==
4176 WLC_SHORTSLOT_ON);
4180 break;
4182 case WLC_GET_LEGACY_ERP:
4183 *pval = wlc->include_legacy_erp;
4184 break;
4186 case WLC_SET_LEGACY_ERP:
4187 if (wlc->include_legacy_erp == bool_val)
4188 break;
4190 wlc->include_legacy_erp = bool_val;
4192 if (AP_ENAB(wlc->pub) && wlc->clk) {
4193 wlc_update_beacon(wlc);
4194 wlc_update_probe_resp(wlc, TRUE);
4196 break;
4198 case WLC_GET_GMODE:
4199 if (wlc->band->bandtype == WLC_BAND_2G)
4200 *pval = wlc->band->gmode;
4201 else if (NBANDS(wlc) > 1)
4202 *pval = wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode;
4203 break;
4205 case WLC_SET_GMODE:
4206 if (!wlc->pub->associated)
4207 bcmerror = wlc_set_gmode(wlc, (uint8) val, TRUE);
4208 else {
4209 bcmerror = BCME_ASSOCIATED;
4210 break;
4212 break;
4214 case WLC_GET_GMODE_PROTECTION:
4215 *pval = wlc->protection->_g;
4216 break;
4218 case WLC_GET_PROTECTION_CONTROL:
4219 *pval = wlc->protection->overlap;
4220 break;
4222 case WLC_SET_PROTECTION_CONTROL:
4223 if ((val != WLC_PROTECTION_CTL_OFF) &&
4224 (val != WLC_PROTECTION_CTL_LOCAL) &&
4225 (val != WLC_PROTECTION_CTL_OVERLAP)) {
4226 bcmerror = BCME_RANGE;
4227 break;
4230 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, (int8) val);
4232 /* Current g_protection will sync up to the specified control alg in watchdog
4233 * if the driver is up and associated.
4234 * If the driver is down or not associated, the control setting has no effect.
4236 break;
4238 case WLC_GET_GMODE_PROTECTION_OVERRIDE:
4239 *pval = wlc->protection->g_override;
4240 break;
4242 case WLC_SET_GMODE_PROTECTION_OVERRIDE:
4243 if ((val != WLC_PROTECTION_AUTO) &&
4244 (val != WLC_PROTECTION_OFF) && (val != WLC_PROTECTION_ON)) {
4245 bcmerror = BCME_RANGE;
4246 break;
4249 wlc_protection_upd(wlc, WLC_PROT_G_OVR, (int8) val);
4251 break;
4253 case WLC_SET_SUP_RATESET_OVERRIDE:{
4254 wlc_rateset_t rs, new;
4256 /* copyin */
4257 if (len < (int)sizeof(wlc_rateset_t)) {
4258 bcmerror = BCME_BUFTOOSHORT;
4259 break;
4261 bcopy((char *)arg, (char *)&rs, sizeof(wlc_rateset_t));
4263 /* check for bad count value */
4264 if (rs.count > WLC_NUMRATES) {
4265 bcmerror = BCME_BADRATESET; /* invalid rateset */
4266 break;
4269 /* this command is only appropriate for gmode operation */
4270 if (!(wlc->band->gmode ||
4271 ((NBANDS(wlc) > 1)
4272 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4273 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4274 break;
4277 /* check for an empty rateset to clear the override */
4278 if (rs.count == 0) {
4279 bzero(&wlc->sup_rates_override,
4280 sizeof(wlc_rateset_t));
4281 break;
4284 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4285 wlc_rateset_filter(&rs, &new, FALSE, WLC_RATES_CCK_OFDM,
4286 RATE_MASK, BSS_N_ENAB(wlc, bsscfg));
4287 wlc_rate_hwrs_filter_sort_validate(&new,
4288 &cck_ofdm_rates,
4289 FALSE,
4290 wlc->stf->txstreams);
4291 if (rs.count != new.count) {
4292 bcmerror = BCME_BADRATESET; /* invalid rateset */
4293 break;
4296 /* apply new rateset to the override */
4297 bcopy((char *)&new, (char *)&wlc->sup_rates_override,
4298 sizeof(wlc_rateset_t));
4300 /* update bcn and probe resp if needed */
4301 if (wlc->pub->up && AP_ENAB(wlc->pub)
4302 && wlc->pub->associated) {
4303 wlc_update_beacon(wlc);
4304 wlc_update_probe_resp(wlc, TRUE);
4306 break;
4309 case WLC_GET_SUP_RATESET_OVERRIDE:
4310 /* this command is only appropriate for gmode operation */
4311 if (!(wlc->band->gmode ||
4312 ((NBANDS(wlc) > 1)
4313 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4314 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4315 break;
4317 if (len < (int)sizeof(wlc_rateset_t)) {
4318 bcmerror = BCME_BUFTOOSHORT;
4319 break;
4321 bcopy((char *)&wlc->sup_rates_override, (char *)arg,
4322 sizeof(wlc_rateset_t));
4324 break;
4326 case WLC_GET_PRB_RESP_TIMEOUT:
4327 *pval = wlc->prb_resp_timeout;
4328 break;
4330 case WLC_SET_PRB_RESP_TIMEOUT:
4331 if (wlc->pub->up) {
4332 bcmerror = BCME_NOTDOWN;
4333 break;
4335 if (val < 0 || val >= 0xFFFF) {
4336 bcmerror = BCME_RANGE; /* bad value */
4337 break;
4339 wlc->prb_resp_timeout = (uint16) val;
4340 break;
4342 case WLC_GET_KEY_PRIMARY:{
4343 wsec_key_t *key;
4345 /* treat the 'val' parm as the key id */
4346 key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4347 if (key != NULL) {
4348 *pval = key->id == val ? TRUE : FALSE;
4349 } else {
4350 bcmerror = BCME_BADKEYIDX;
4352 break;
4355 case WLC_SET_KEY_PRIMARY:{
4356 wsec_key_t *key, *old_key;
4358 bcmerror = BCME_BADKEYIDX;
4360 /* treat the 'val' parm as the key id */
4361 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
4362 key = bsscfg->bss_def_keys[i];
4363 if (key != NULL && key->id == val) {
4364 old_key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4365 if (old_key != NULL)
4366 old_key->flags &=
4367 ~WSEC_PRIMARY_KEY;
4368 key->flags |= WSEC_PRIMARY_KEY;
4369 bsscfg->wsec_index = i;
4370 bcmerror = BCME_OK;
4373 break;
4376 #ifdef BCMDBG
4377 case WLC_INIT:
4378 wl_init(wlc->wl);
4379 break;
4380 #endif
4382 case WLC_SET_VAR:
4383 case WLC_GET_VAR:{
4384 char *name;
4385 /* validate the name value */
4386 name = (char *)arg;
4387 for (i = 0; i < (uint) len && *name != '\0';
4388 i++, name++)
4391 if (i == (uint) len) {
4392 bcmerror = BCME_BUFTOOSHORT;
4393 break;
4395 i++; /* include the null in the string length */
4397 if (cmd == WLC_GET_VAR) {
4398 bcmerror =
4399 wlc_iovar_op(wlc, arg,
4400 (void *)((int8 *) arg + i),
4401 len - i, arg, len, IOV_GET,
4402 wlcif);
4403 } else
4404 bcmerror =
4405 wlc_iovar_op(wlc, arg, NULL, 0,
4406 (void *)((int8 *) arg + i),
4407 len - i, IOV_SET, wlcif);
4409 break;
4412 case WLC_SET_WSEC_PMK:
4413 bcmerror = BCME_UNSUPPORTED;
4414 break;
4416 #if defined(BCMDBG)
4417 case WLC_CURRENT_PWR:
4418 if (!wlc->pub->up)
4419 bcmerror = BCME_NOTUP;
4420 else
4421 bcmerror = wlc_get_current_txpwr(wlc, arg, len);
4422 break;
4423 #endif
4425 case WLC_LAST:
4426 WL_ERROR(("%s: WLC_LAST\n", __func__));
4428 done:
4430 if (bcmerror) {
4431 if (VALID_BCMERROR(bcmerror))
4432 wlc->pub->bcmerror = bcmerror;
4433 else {
4434 bcmerror = 0;
4438 #ifdef WLC_LOW
4439 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4440 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4441 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4443 if (!(wlc->pub->hw_off))
4444 ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok);
4445 #endif
4447 return bcmerror;
4450 #if defined(BCMDBG)
4451 /* consolidated register access ioctl error checking */
4452 int wlc_iocregchk(wlc_info_t *wlc, uint band)
4454 /* if band is specified, it must be the current band */
4455 if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype))
4456 return BCME_BADBAND;
4458 /* if multiband and band is not specified, band must be locked */
4459 if ((band == WLC_BAND_AUTO) && IS_MBAND_UNLOCKED(wlc))
4460 return BCME_NOTBANDLOCKED;
4462 /* must have core clocks */
4463 if (!wlc->clk)
4464 return BCME_NOCLK;
4466 return 0;
4468 #endif /* defined(BCMDBG) */
4470 #if defined(BCMDBG)
4471 /* For some ioctls, make sure that the pi pointer matches the current phy */
4472 int wlc_iocpichk(wlc_info_t *wlc, uint phytype)
4474 if (wlc->band->phytype != phytype)
4475 return BCME_BADBAND;
4476 return 0;
4478 #endif
4480 /* Look up the given var name in the given table */
4481 static const bcm_iovar_t *wlc_iovar_lookup(const bcm_iovar_t *table,
4482 const char *name)
4484 const bcm_iovar_t *vi;
4485 const char *lookup_name;
4487 /* skip any ':' delimited option prefixes */
4488 lookup_name = strrchr(name, ':');
4489 if (lookup_name != NULL)
4490 lookup_name++;
4491 else
4492 lookup_name = name;
4494 ASSERT(table != NULL);
4496 for (vi = table; vi->name; vi++) {
4497 if (!strcmp(vi->name, lookup_name))
4498 return vi;
4500 /* ran to end of table */
4502 return NULL; /* var name not found */
4505 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4506 int wlc_iovar_getint(wlc_info_t *wlc, const char *name, int *arg)
4508 return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(int32), IOV_GET,
4509 NULL);
4512 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4513 int wlc_iovar_setint(wlc_info_t *wlc, const char *name, int arg)
4515 return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg),
4516 IOV_SET, NULL);
4519 /* simplified int8 get interface for common WLC_GET_VAR ioctl handler */
4520 int wlc_iovar_getint8(wlc_info_t *wlc, const char *name, int8 *arg)
4522 int iovar_int;
4523 int err;
4525 err =
4526 wlc_iovar_op(wlc, name, NULL, 0, &iovar_int, sizeof(iovar_int),
4527 IOV_GET, NULL);
4528 if (!err)
4529 *arg = (int8) iovar_int;
4531 return err;
4535 * register iovar table, watchdog and down handlers.
4536 * calling function must keep 'iovars' until wlc_module_unregister is called.
4537 * 'iovar' must have the last entry's name field being NULL as terminator.
4540 BCMATTACHFN(wlc_module_register) (wlc_pub_t *pub, const bcm_iovar_t *iovars,
4541 const char *name, void *hdl, iovar_fn_t i_fn,
4542 watchdog_fn_t w_fn, down_fn_t d_fn) {
4543 wlc_info_t *wlc = (wlc_info_t *) pub->wlc;
4544 int i;
4546 ASSERT(name != NULL);
4547 ASSERT(i_fn != NULL || w_fn != NULL || d_fn != NULL);
4549 /* find an empty entry and just add, no duplication check! */
4550 for (i = 0; i < WLC_MAXMODULES; i++) {
4551 if (wlc->modulecb[i].name[0] == '\0') {
4552 strncpy(wlc->modulecb[i].name, name,
4553 sizeof(wlc->modulecb[i].name) - 1);
4554 wlc->modulecb[i].iovars = iovars;
4555 wlc->modulecb[i].hdl = hdl;
4556 wlc->modulecb[i].iovar_fn = i_fn;
4557 wlc->modulecb[i].watchdog_fn = w_fn;
4558 wlc->modulecb[i].down_fn = d_fn;
4559 return 0;
4563 /* it is time to increase the capacity */
4564 ASSERT(i < WLC_MAXMODULES);
4565 return BCME_NORESOURCE;
4568 /* unregister module callbacks */
4570 BCMATTACHFN(wlc_module_unregister) (wlc_pub_t *pub, const char *name,
4571 void *hdl) {
4572 wlc_info_t *wlc = (wlc_info_t *) pub->wlc;
4573 int i;
4575 if (wlc == NULL)
4576 return BCME_NOTFOUND;
4578 ASSERT(name != NULL);
4580 for (i = 0; i < WLC_MAXMODULES; i++) {
4581 if (!strcmp(wlc->modulecb[i].name, name) &&
4582 (wlc->modulecb[i].hdl == hdl)) {
4583 bzero(&wlc->modulecb[i], sizeof(modulecb_t));
4584 return 0;
4588 /* table not found! */
4589 return BCME_NOTFOUND;
4592 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4593 static void wlc_wme_retries_write(wlc_info_t *wlc)
4595 int ac;
4597 /* Need clock to do this */
4598 if (!wlc->clk)
4599 return;
4601 for (ac = 0; ac < AC_COUNT; ac++) {
4602 wlc_write_shm(wlc, M_AC_TXLMT_ADDR(ac), wlc->wme_retries[ac]);
4606 /* Get or set an iovar. The params/p_len pair specifies any additional
4607 * qualifying parameters (e.g. an "element index") for a get, while the
4608 * arg/len pair is the buffer for the value to be set or retrieved.
4609 * Operation (get/set) is specified by the last argument.
4610 * interface context provided by wlcif
4612 * All pointers may point into the same buffer.
4615 wlc_iovar_op(wlc_info_t *wlc, const char *name,
4616 void *params, int p_len, void *arg, int len,
4617 bool set, struct wlc_if *wlcif)
4619 int err = 0;
4620 int val_size;
4621 const bcm_iovar_t *vi = NULL;
4622 uint32 actionid;
4623 int i;
4625 ASSERT(name != NULL);
4627 ASSERT(len >= 0);
4629 /* Get MUST have return space */
4630 ASSERT(set || (arg && len));
4632 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
4634 /* Set does NOT take qualifiers */
4635 ASSERT(!set || (!params && !p_len));
4637 if (!set && (len == sizeof(int)) &&
4638 !(ISALIGNED((uintptr) (arg), (uint) sizeof(int)))) {
4639 WL_ERROR(("wl%d: %s unaligned get ptr for %s\n",
4640 wlc->pub->unit, __func__, name));
4641 ASSERT(0);
4644 /* find the given iovar name */
4645 for (i = 0; i < WLC_MAXMODULES; i++) {
4646 if (!wlc->modulecb[i].iovars)
4647 continue;
4648 vi = wlc_iovar_lookup(wlc->modulecb[i].iovars, name);
4649 if (vi)
4650 break;
4652 /* iovar name not found */
4653 if (i >= WLC_MAXMODULES) {
4654 err = BCME_UNSUPPORTED;
4655 #ifdef WLC_HIGH_ONLY
4656 err =
4657 bcmsdh_iovar_op(wlc->btparam, name, params, p_len, arg, len,
4658 set);
4659 #endif
4660 goto exit;
4663 /* set up 'params' pointer in case this is a set command so that
4664 * the convenience int and bool code can be common to set and get
4666 if (params == NULL) {
4667 params = arg;
4668 p_len = len;
4671 if (vi->type == IOVT_VOID)
4672 val_size = 0;
4673 else if (vi->type == IOVT_BUFFER)
4674 val_size = len;
4675 else
4676 /* all other types are integer sized */
4677 val_size = sizeof(int);
4679 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
4681 /* Do the actual parameter implementation */
4682 err = wlc->modulecb[i].iovar_fn(wlc->modulecb[i].hdl, vi, actionid,
4683 name, params, p_len, arg, len, val_size,
4684 wlcif);
4686 exit:
4687 return err;
4691 wlc_iovar_check(wlc_pub_t *pub, const bcm_iovar_t *vi, void *arg, int len,
4692 bool set)
4694 wlc_info_t *wlc = (wlc_info_t *) pub->wlc;
4695 int err = 0;
4696 int32 int_val = 0;
4698 /* check generic condition flags */
4699 if (set) {
4700 if (((vi->flags & IOVF_SET_DOWN) && wlc->pub->up) ||
4701 ((vi->flags & IOVF_SET_UP) && !wlc->pub->up)) {
4702 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4703 } else if ((vi->flags & IOVF_SET_BAND)
4704 && IS_MBAND_UNLOCKED(wlc)) {
4705 err = BCME_NOTBANDLOCKED;
4706 } else if ((vi->flags & IOVF_SET_CLK) && !wlc->clk) {
4707 err = BCME_NOCLK;
4709 } else {
4710 if (((vi->flags & IOVF_GET_DOWN) && wlc->pub->up) ||
4711 ((vi->flags & IOVF_GET_UP) && !wlc->pub->up)) {
4712 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4713 } else if ((vi->flags & IOVF_GET_BAND)
4714 && IS_MBAND_UNLOCKED(wlc)) {
4715 err = BCME_NOTBANDLOCKED;
4716 } else if ((vi->flags & IOVF_GET_CLK) && !wlc->clk) {
4717 err = BCME_NOCLK;
4721 if (err)
4722 goto exit;
4724 /* length check on io buf */
4725 err = bcm_iovar_lencheck(vi, arg, len, set);
4726 if (err)
4727 goto exit;
4729 /* On set, check value ranges for integer types */
4730 if (set) {
4731 switch (vi->type) {
4732 case IOVT_BOOL:
4733 case IOVT_INT8:
4734 case IOVT_INT16:
4735 case IOVT_INT32:
4736 case IOVT_UINT8:
4737 case IOVT_UINT16:
4738 case IOVT_UINT32:
4739 bcopy(arg, &int_val, sizeof(int));
4740 err = wlc_iovar_rangecheck(wlc, int_val, vi);
4741 break;
4744 exit:
4745 return err;
4748 /* handler for iovar table wlc_iovars */
4750 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4751 * iovar case, the switch statement maps the iovar id into separate get
4752 * and set values. If you add a new iovar to the switch you MUST use
4753 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4754 * another case.
4755 * Please use params for additional qualifying parameters.
4758 wlc_doiovar(void *hdl, const bcm_iovar_t *vi, uint32 actionid,
4759 const char *name, void *params, uint p_len, void *arg, int len,
4760 int val_size, struct wlc_if *wlcif)
4762 wlc_info_t *wlc = hdl;
4763 wlc_bsscfg_t *bsscfg;
4764 int err = 0;
4765 int32 int_val = 0;
4766 int32 int_val2 = 0;
4767 int32 *ret_int_ptr;
4768 bool bool_val;
4769 bool bool_val2;
4770 wlc_bss_info_t *current_bss;
4772 WL_TRACE(("wl%d: %s\n", wlc->pub->unit, __func__));
4774 bsscfg = NULL;
4775 current_bss = NULL;
4777 err = wlc_iovar_check(wlc->pub, vi, arg, len, IOV_ISSET(actionid));
4778 if (err != 0)
4779 return err;
4781 /* convenience int and bool vals for first 8 bytes of buffer */
4782 if (p_len >= (int)sizeof(int_val))
4783 bcopy(params, &int_val, sizeof(int_val));
4785 if (p_len >= (int)sizeof(int_val) * 2)
4786 bcopy((void *)((uintptr) params + sizeof(int_val)), &int_val2,
4787 sizeof(int_val));
4789 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4790 ret_int_ptr = (int32 *) arg;
4792 bool_val = (int_val != 0) ? TRUE : FALSE;
4793 bool_val2 = (int_val2 != 0) ? TRUE : FALSE;
4795 WL_TRACE(("wl%d: %s: id %d\n", wlc->pub->unit, __func__,
4796 IOV_ID(actionid)));
4797 /* Do the actual parameter implementation */
4798 switch (actionid) {
4800 case IOV_GVAL(IOV_QTXPOWER):{
4801 uint qdbm;
4802 bool override;
4804 err = wlc_phy_txpower_get(wlc->band->pi, &qdbm,
4805 &override);
4806 if (err != BCME_OK)
4807 return err;
4809 /* Return qdbm units */
4810 *ret_int_ptr =
4811 qdbm | (override ? WL_TXPWR_OVERRIDE : 0);
4812 break;
4815 /* As long as override is false, this only sets the *user* targets.
4816 User can twiddle this all he wants with no harm.
4817 wlc_phy_txpower_set() explicitly sets override to false if
4818 not internal or test.
4820 case IOV_SVAL(IOV_QTXPOWER):{
4821 uint8 qdbm;
4822 bool override;
4824 /* Remove override bit and clip to max qdbm value */
4825 qdbm =
4826 (uint8) MIN((int_val & ~WL_TXPWR_OVERRIDE), 0xff);
4827 /* Extract override setting */
4828 override = (int_val & WL_TXPWR_OVERRIDE) ? TRUE : FALSE;
4829 err =
4830 wlc_phy_txpower_set(wlc->band->pi, qdbm, override);
4831 break;
4834 case IOV_GVAL(IOV_MPC):
4835 *ret_int_ptr = (int32) wlc->mpc;
4836 break;
4838 case IOV_SVAL(IOV_MPC):
4839 wlc->mpc = bool_val;
4840 wlc_radio_mpc_upd(wlc);
4842 break;
4844 case IOV_GVAL(IOV_BCN_LI_BCN):
4845 *ret_int_ptr = wlc->bcn_li_bcn;
4846 break;
4848 case IOV_SVAL(IOV_BCN_LI_BCN):
4849 wlc->bcn_li_bcn = (uint8) int_val;
4850 if (wlc->pub->up)
4851 wlc_bcn_li_upd(wlc);
4852 break;
4854 default:
4855 WL_ERROR(("wl%d: %s: unsupported\n", wlc->pub->unit, __func__));
4856 err = BCME_UNSUPPORTED;
4857 break;
4860 goto exit; /* avoid unused label warning */
4862 exit:
4863 return err;
4866 static int
4867 wlc_iovar_rangecheck(wlc_info_t *wlc, uint32 val, const bcm_iovar_t *vi)
4869 int err = 0;
4870 uint32 min_val = 0;
4871 uint32 max_val = 0;
4873 /* Only ranged integers are checked */
4874 switch (vi->type) {
4875 case IOVT_INT32:
4876 max_val |= 0x7fffffff;
4877 /* fall through */
4878 case IOVT_INT16:
4879 max_val |= 0x00007fff;
4880 /* fall through */
4881 case IOVT_INT8:
4882 max_val |= 0x0000007f;
4883 min_val = ~max_val;
4884 if (vi->flags & IOVF_NTRL)
4885 min_val = 1;
4886 else if (vi->flags & IOVF_WHL)
4887 min_val = 0;
4888 /* Signed values are checked against max_val and min_val */
4889 if ((int32) val < (int32) min_val
4890 || (int32) val > (int32) max_val)
4891 err = BCME_RANGE;
4892 break;
4894 case IOVT_UINT32:
4895 max_val |= 0xffffffff;
4896 /* fall through */
4897 case IOVT_UINT16:
4898 max_val |= 0x0000ffff;
4899 /* fall through */
4900 case IOVT_UINT8:
4901 max_val |= 0x000000ff;
4902 if (vi->flags & IOVF_NTRL)
4903 min_val = 1;
4904 if ((val < min_val) || (val > max_val))
4905 err = BCME_RANGE;
4906 break;
4909 return err;
4912 #if defined(BCMDBG)
4913 static const struct wlc_id_name_entry dot11_ie_names[] = {
4914 {DOT11_MNG_SSID_ID, "SSID"},
4915 {DOT11_MNG_RATES_ID, "Rates"},
4916 {DOT11_MNG_FH_PARMS_ID, "FH Parms"},
4917 {DOT11_MNG_DS_PARMS_ID, "DS Parms"},
4918 {DOT11_MNG_CF_PARMS_ID, "CF Parms"},
4919 {DOT11_MNG_TIM_ID, "TIM"},
4920 {DOT11_MNG_IBSS_PARMS_ID, "IBSS Parms"},
4921 {DOT11_MNG_COUNTRY_ID, "Country"},
4922 {DOT11_MNG_HOPPING_PARMS_ID, "Hopping Parms"},
4923 {DOT11_MNG_HOPPING_TABLE_ID, "Hopping Table"},
4924 {DOT11_MNG_REQUEST_ID, "Request"},
4925 {DOT11_MNG_QBSS_LOAD_ID, "QBSS LOAD"},
4926 {DOT11_MNG_CHALLENGE_ID, "Challenge"},
4927 {DOT11_MNG_PWR_CONSTRAINT_ID, "Pwr Constraint"},
4928 {DOT11_MNG_PWR_CAP_ID, "Pwr Capability"},
4929 {DOT11_MNG_TPC_REQUEST_ID, "TPC Request"},
4930 {DOT11_MNG_TPC_REPORT_ID, "TPC Report"},
4931 {DOT11_MNG_SUPP_CHANNELS_ID, "Supported Channels"},
4932 {DOT11_MNG_CHANNEL_SWITCH_ID, "Channel Switch"},
4933 {DOT11_MNG_MEASURE_REQUEST_ID, "Measure Request"},
4934 {DOT11_MNG_MEASURE_REPORT_ID, "Measure Report"},
4935 {DOT11_MNG_QUIET_ID, "Quiet"},
4936 {DOT11_MNG_IBSS_DFS_ID, "IBSS DFS"},
4937 {DOT11_MNG_ERP_ID, "ERP Info"},
4938 {DOT11_MNG_TS_DELAY_ID, "TS Delay"},
4939 {DOT11_MNG_HT_CAP, "HT Capability"},
4940 {DOT11_MNG_NONERP_ID, "Legacy ERP Info"},
4941 {DOT11_MNG_RSN_ID, "RSN"},
4942 {DOT11_MNG_EXT_RATES_ID, "Ext Rates"},
4943 {DOT11_MNG_HT_ADD, "HT Additional"},
4944 {DOT11_MNG_EXT_CHANNEL_OFFSET, "Ext Channel Offset"},
4945 {DOT11_MNG_VS_ID, "Vendor Specific"},
4946 {0, NULL}
4948 #endif /* defined(BCMDBG) */
4950 #ifdef BCMDBG
4951 static const char *supr_reason[] = {
4952 "None", "PMQ Entry", "Flush request",
4953 "Previous frag failure", "Channel mismatch",
4954 "Lifetime Expiry", "Underflow"
4957 static void wlc_print_txs_status(uint16 s)
4959 printf("[15:12] %d frame attempts\n", (s & TX_STATUS_FRM_RTX_MASK) >>
4960 TX_STATUS_FRM_RTX_SHIFT);
4961 printf(" [11:8] %d rts attempts\n", (s & TX_STATUS_RTS_RTX_MASK) >>
4962 TX_STATUS_RTS_RTX_SHIFT);
4963 printf(" [7] %d PM mode indicated\n",
4964 ((s & TX_STATUS_PMINDCTD) ? 1 : 0));
4965 printf(" [6] %d intermediate status\n",
4966 ((s & TX_STATUS_INTERMEDIATE) ? 1 : 0));
4967 printf(" [5] %d AMPDU\n", (s & TX_STATUS_AMPDU) ? 1 : 0);
4968 printf(" [4:2] %d Frame Suppressed Reason (%s)\n",
4969 ((s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT),
4970 supr_reason[(s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT]);
4971 printf(" [1] %d acked\n", ((s & TX_STATUS_ACK_RCV) ? 1 : 0));
4973 #endif /* BCMDBG */
4975 void wlc_print_txstatus(tx_status_t *txs)
4977 #if defined(BCMDBG)
4978 uint16 s = txs->status;
4979 uint16 ackphyrxsh = txs->ackphyrxsh;
4981 printf("\ntxpkt (MPDU) Complete\n");
4983 printf("FrameID: %04x ", txs->frameid);
4984 printf("TxStatus: %04x", s);
4985 printf("\n");
4986 #ifdef BCMDBG
4987 wlc_print_txs_status(s);
4988 #endif
4989 printf("LastTxTime: %04x ", txs->lasttxtime);
4990 printf("Seq: %04x ", txs->sequence);
4991 printf("PHYTxStatus: %04x ", txs->phyerr);
4992 printf("RxAckRSSI: %04x ",
4993 (ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT);
4994 printf("RxAckSQ: %04x", (ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT);
4995 printf("\n");
4996 #endif /* defined(BCMDBG) */
4999 #define MACSTATUPD(name) \
5000 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
5002 void wlc_statsupd(wlc_info_t *wlc)
5004 int i;
5005 #ifdef BCMDBG
5006 uint16 delta;
5007 uint16 rxf0ovfl;
5008 uint16 txfunfl[NFIFO];
5009 #endif /* BCMDBG */
5011 /* if driver down, make no sense to update stats */
5012 if (!wlc->pub->up)
5013 return;
5015 #ifdef BCMDBG
5016 /* save last rx fifo 0 overflow count */
5017 rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl;
5019 /* save last tx fifo underflow count */
5020 for (i = 0; i < NFIFO; i++)
5021 txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i];
5022 #endif /* BCMDBG */
5024 #ifdef BCMDBG
5025 /* check for rx fifo 0 overflow */
5026 delta = (uint16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl);
5027 if (delta)
5028 WL_ERROR(("wl%d: %u rx fifo 0 overflows!\n", wlc->pub->unit,
5029 delta));
5031 /* check for tx fifo underflows */
5032 for (i = 0; i < NFIFO; i++) {
5033 delta =
5034 (uint16) (wlc->core->macstat_snapshot->txfunfl[i] -
5035 txfunfl[i]);
5036 if (delta)
5037 WL_ERROR(("wl%d: %u tx fifo %d underflows!\n",
5038 wlc->pub->unit, delta, i));
5040 #endif /* BCMDBG */
5042 /* dot11 counter update */
5044 WLCNTSET(wlc->pub->_cnt->txrts,
5045 (wlc->pub->_cnt->rxctsucast -
5046 wlc->pub->_cnt->d11cnt_txrts_off));
5047 WLCNTSET(wlc->pub->_cnt->rxcrc,
5048 (wlc->pub->_cnt->rxbadfcs - wlc->pub->_cnt->d11cnt_rxcrc_off));
5049 WLCNTSET(wlc->pub->_cnt->txnocts,
5050 ((wlc->pub->_cnt->txrtsfrm - wlc->pub->_cnt->rxctsucast) -
5051 wlc->pub->_cnt->d11cnt_txnocts_off));
5053 /* merge counters from dma module */
5054 for (i = 0; i < NFIFO; i++) {
5055 if (wlc->hw->di[i]) {
5056 WLCNTADD(wlc->pub->_cnt->txnobuf,
5057 (wlc->hw->di[i])->txnobuf);
5058 WLCNTADD(wlc->pub->_cnt->rxnobuf,
5059 (wlc->hw->di[i])->rxnobuf);
5060 WLCNTADD(wlc->pub->_cnt->rxgiant,
5061 (wlc->hw->di[i])->rxgiants);
5062 dma_counterreset(wlc->hw->di[i]);
5067 * Aggregate transmit and receive errors that probably resulted
5068 * in the loss of a frame are computed on the fly.
5070 WLCNTSET(wlc->pub->_cnt->txerror,
5071 wlc->pub->_cnt->txnobuf + wlc->pub->_cnt->txnoassoc +
5072 wlc->pub->_cnt->txuflo + wlc->pub->_cnt->txrunt +
5073 wlc->pub->_cnt->dmade + wlc->pub->_cnt->dmada +
5074 wlc->pub->_cnt->dmape);
5075 WLCNTSET(wlc->pub->_cnt->rxerror,
5076 wlc->pub->_cnt->rxoflo + wlc->pub->_cnt->rxnobuf +
5077 wlc->pub->_cnt->rxfragerr + wlc->pub->_cnt->rxrunt +
5078 wlc->pub->_cnt->rxgiant + wlc->pub->_cnt->rxnoscb +
5079 wlc->pub->_cnt->rxbadsrcmac);
5080 for (i = 0; i < NFIFO; i++)
5081 WLCNTADD(wlc->pub->_cnt->rxerror, wlc->pub->_cnt->rxuflo[i]);
5084 bool wlc_chipmatch(uint16 vendor, uint16 device)
5086 if (vendor != VENDOR_BROADCOM) {
5087 WL_ERROR(("wlc_chipmatch: unknown vendor id %04x\n", vendor));
5088 return FALSE;
5091 if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID))
5092 return TRUE;
5094 if (device == BCM4313_D11N2G_ID)
5095 return TRUE;
5096 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID))
5097 return TRUE;
5099 WL_ERROR(("wlc_chipmatch: unknown device id %04x\n", device));
5100 return FALSE;
5103 #if defined(BCMDBG)
5104 static const char *errstr = "802.11 Header INCOMPLETE\n";
5105 static const char *fillstr = "------------";
5106 static void wlc_print_dot11hdr(uint8 *buf, int len)
5108 char hexbuf[(2 * D11B_PHY_HDR_LEN) + 1];
5110 if (len == 0) {
5111 printf("802.11 Header MISSING\n");
5112 return;
5115 if (len < D11B_PHY_HDR_LEN) {
5116 bcm_format_hex(hexbuf, buf, len);
5117 strncpy(hexbuf + (2 * len), fillstr,
5118 2 * (D11B_PHY_HDR_LEN - len));
5119 hexbuf[sizeof(hexbuf) - 1] = '\0';
5120 } else {
5121 bcm_format_hex(hexbuf, buf, D11B_PHY_HDR_LEN);
5124 printf("PLCPHdr: %s ", hexbuf);
5125 if (len < D11B_PHY_HDR_LEN) {
5126 printf("%s\n", errstr);
5127 return;
5130 len -= D11B_PHY_HDR_LEN;
5131 buf += D11B_PHY_HDR_LEN;
5133 wlc_print_dot11_mac_hdr(buf, len);
5136 void wlc_print_dot11_mac_hdr(uint8 *buf, int len)
5138 char hexbuf[(2 * D11B_PHY_HDR_LEN) + 1];
5139 char a1[(2 * ETHER_ADDR_LEN) + 1], a2[(2 * ETHER_ADDR_LEN) + 1];
5140 char a3[(2 * ETHER_ADDR_LEN) + 1];
5141 char flagstr[64];
5142 uint16 fc, kind, toDS, fromDS;
5143 uint16 v;
5144 int fill_len = 0;
5145 static const bcm_bit_desc_t fc_flags[] = {
5146 {FC_TODS, "ToDS"},
5147 {FC_FROMDS, "FromDS"},
5148 {FC_MOREFRAG, "MoreFrag"},
5149 {FC_RETRY, "Retry"},
5150 {FC_PM, "PM"},
5151 {FC_MOREDATA, "MoreData"},
5152 {FC_WEP, "WEP"},
5153 {FC_ORDER, "Order"},
5154 {0, NULL}
5157 if (len < 2) {
5158 printf("FC: ------ ");
5159 printf("%s\n", errstr);
5160 return;
5163 fc = buf[0] | (buf[1] << 8);
5164 kind = fc & FC_KIND_MASK;
5165 toDS = (fc & FC_TODS) != 0;
5166 fromDS = (fc & FC_FROMDS) != 0;
5168 bcm_format_flags(fc_flags, fc, flagstr, 64);
5170 printf("FC: 0x%04x ", fc);
5171 if (flagstr[0] != '\0')
5172 printf("(%s) ", flagstr);
5174 len -= 2;
5175 buf += 2;
5177 if (len < 2) {
5178 printf("Dur/AID: ----- ");
5179 printf("%s\n", errstr);
5180 return;
5183 v = buf[0] | (buf[1] << 8);
5184 if (kind == FC_PS_POLL) {
5185 printf("AID: 0x%04x", v);
5186 } else {
5187 printf("Dur: 0x%04x", v);
5189 printf("\n");
5190 len -= 2;
5191 buf += 2;
5193 strncpy(a1, fillstr, sizeof(a1));
5194 strncpy(a2, fillstr, sizeof(a2));
5195 strncpy(a3, fillstr, sizeof(a3));
5197 if (len < ETHER_ADDR_LEN) {
5198 bcm_format_hex(a1, buf, len);
5199 strncpy(a1 + (2 * len), fillstr, 2 * (ETHER_ADDR_LEN - len));
5200 } else if (len < 2 * ETHER_ADDR_LEN) {
5201 bcm_format_hex(a1, buf, ETHER_ADDR_LEN);
5202 bcm_format_hex(a2, buf + ETHER_ADDR_LEN, len - ETHER_ADDR_LEN);
5203 fill_len = len - ETHER_ADDR_LEN;
5204 strncpy(a2 + (2 * fill_len), fillstr,
5205 2 * (ETHER_ADDR_LEN - fill_len));
5206 } else if (len < 3 * ETHER_ADDR_LEN) {
5207 bcm_format_hex(a1, buf, ETHER_ADDR_LEN);
5208 bcm_format_hex(a2, buf + ETHER_ADDR_LEN, ETHER_ADDR_LEN);
5209 bcm_format_hex(a3, buf + (2 * ETHER_ADDR_LEN),
5210 len - (2 * ETHER_ADDR_LEN));
5211 fill_len = len - (2 * ETHER_ADDR_LEN);
5212 strncpy(a3 + (2 * fill_len), fillstr,
5213 2 * (ETHER_ADDR_LEN - fill_len));
5214 } else {
5215 bcm_format_hex(a1, buf, ETHER_ADDR_LEN);
5216 bcm_format_hex(a2, buf + ETHER_ADDR_LEN, ETHER_ADDR_LEN);
5217 bcm_format_hex(a3, buf + (2 * ETHER_ADDR_LEN), ETHER_ADDR_LEN);
5220 if (kind == FC_RTS) {
5221 printf("RA: %s ", a1);
5222 printf("TA: %s ", a2);
5223 if (len < 2 * ETHER_ADDR_LEN)
5224 printf("%s ", errstr);
5225 } else if (kind == FC_CTS || kind == FC_ACK) {
5226 printf("RA: %s ", a1);
5227 if (len < ETHER_ADDR_LEN)
5228 printf("%s ", errstr);
5229 } else if (kind == FC_PS_POLL) {
5230 printf("BSSID: %s", a1);
5231 printf("TA: %s ", a2);
5232 if (len < 2 * ETHER_ADDR_LEN)
5233 printf("%s ", errstr);
5234 } else if (kind == FC_CF_END || kind == FC_CF_END_ACK) {
5235 printf("RA: %s ", a1);
5236 printf("BSSID: %s ", a2);
5237 if (len < 2 * ETHER_ADDR_LEN)
5238 printf("%s ", errstr);
5239 } else if (FC_TYPE(fc) == FC_TYPE_DATA) {
5240 if (!toDS) {
5241 printf("DA: %s ", a1);
5242 if (!fromDS) {
5243 printf("SA: %s ", a2);
5244 printf("BSSID: %s ", a3);
5245 } else {
5246 printf("BSSID: %s ", a2);
5247 printf("SA: %s ", a3);
5249 } else if (!fromDS) {
5250 printf("BSSID: %s ", a1);
5251 printf("SA: %s ", a2);
5252 printf("DA: %s ", a3);
5253 } else {
5254 printf("RA: %s ", a1);
5255 printf("TA: %s ", a2);
5256 printf("DA: %s ", a3);
5258 if (len < 3 * ETHER_ADDR_LEN) {
5259 printf("%s ", errstr);
5260 } else if (len < 20) {
5261 printf("SeqCtl: ------ ");
5262 printf("%s ", errstr);
5263 } else {
5264 len -= 3 * ETHER_ADDR_LEN;
5265 buf += 3 * ETHER_ADDR_LEN;
5266 v = buf[0] | (buf[1] << 8);
5267 printf("SeqCtl: 0x%04x ", v);
5268 len -= 2;
5269 buf += 2;
5271 } else if (FC_TYPE(fc) == FC_TYPE_MNG) {
5272 printf("DA: %s ", a1);
5273 printf("SA: %s ", a2);
5274 printf("BSSID: %s ", a3);
5275 if (len < 3 * ETHER_ADDR_LEN) {
5276 printf("%s ", errstr);
5277 } else if (len < 20) {
5278 printf("SeqCtl: ------ ");
5279 printf("%s ", errstr);
5280 } else {
5281 len -= 3 * ETHER_ADDR_LEN;
5282 buf += 3 * ETHER_ADDR_LEN;
5283 v = buf[0] | (buf[1] << 8);
5284 printf("SeqCtl: 0x%04x ", v);
5285 len -= 2;
5286 buf += 2;
5290 if ((FC_TYPE(fc) == FC_TYPE_DATA) && toDS && fromDS) {
5292 if (len < ETHER_ADDR_LEN) {
5293 bcm_format_hex(hexbuf, buf, len);
5294 strncpy(hexbuf + (2 * len), fillstr,
5295 2 * (ETHER_ADDR_LEN - len));
5296 } else {
5297 bcm_format_hex(hexbuf, buf, ETHER_ADDR_LEN);
5300 printf("SA: %s ", hexbuf);
5302 if (len < ETHER_ADDR_LEN) {
5303 printf("%s ", errstr);
5304 } else {
5305 len -= ETHER_ADDR_LEN;
5306 buf += ETHER_ADDR_LEN;
5310 if ((FC_TYPE(fc) == FC_TYPE_DATA) && (kind == FC_QOS_DATA)) {
5311 if (len < 2) {
5312 printf("QoS: ------");
5313 printf("%s ", errstr);
5314 } else {
5315 v = buf[0] | (buf[1] << 8);
5316 printf("QoS: 0x%04x ", v);
5317 len -= 2;
5318 buf += 2;
5322 printf("\n");
5323 return;
5325 #endif /* defined(BCMDBG) */
5327 #if defined(BCMDBG)
5328 void wlc_print_txdesc(d11txh_t *txh)
5330 uint16 mtcl = ltoh16(txh->MacTxControlLow);
5331 uint16 mtch = ltoh16(txh->MacTxControlHigh);
5332 uint16 mfc = ltoh16(txh->MacFrameControl);
5333 uint16 tfest = ltoh16(txh->TxFesTimeNormal);
5334 uint16 ptcw = ltoh16(txh->PhyTxControlWord);
5335 uint16 ptcw_1 = ltoh16(txh->PhyTxControlWord_1);
5336 uint16 ptcw_1_Fbr = ltoh16(txh->PhyTxControlWord_1_Fbr);
5337 uint16 ptcw_1_Rts = ltoh16(txh->PhyTxControlWord_1_Rts);
5338 uint16 ptcw_1_FbrRts = ltoh16(txh->PhyTxControlWord_1_FbrRts);
5339 uint16 mainrates = ltoh16(txh->MainRates);
5340 uint16 xtraft = ltoh16(txh->XtraFrameTypes);
5341 uint8 *iv = txh->IV;
5342 uint8 *ra = txh->TxFrameRA;
5343 uint16 tfestfb = ltoh16(txh->TxFesTimeFallback);
5344 uint8 *rtspfb = txh->RTSPLCPFallback;
5345 uint16 rtsdfb = ltoh16(txh->RTSDurFallback);
5346 uint8 *fragpfb = txh->FragPLCPFallback;
5347 uint16 fragdfb = ltoh16(txh->FragDurFallback);
5348 uint16 mmodelen = ltoh16(txh->MModeLen);
5349 uint16 mmodefbrlen = ltoh16(txh->MModeFbrLen);
5350 uint16 tfid = ltoh16(txh->TxFrameID);
5351 uint16 txs = ltoh16(txh->TxStatus);
5352 uint16 mnmpdu = ltoh16(txh->MaxNMpdus);
5353 uint16 mabyte = ltoh16(txh->MaxABytes_MRT);
5354 uint16 mabyte_f = ltoh16(txh->MaxABytes_FBR);
5355 uint16 mmbyte = ltoh16(txh->MinMBytes);
5357 uint8 *rtsph = txh->RTSPhyHeader;
5358 struct dot11_rts_frame rts = txh->rts_frame;
5359 char hexbuf[256];
5361 /* add plcp header along with txh descriptor */
5362 prhex("Raw TxDesc + plcp header", (uchar *) txh, sizeof(d11txh_t) + 48);
5364 printf("TxCtlLow: %04x ", mtcl);
5365 printf("TxCtlHigh: %04x ", mtch);
5366 printf("FC: %04x ", mfc);
5367 printf("FES Time: %04x\n", tfest);
5368 printf("PhyCtl: %04x%s ", ptcw,
5369 (ptcw & PHY_TXC_SHORT_HDR) ? " short" : "");
5370 printf("PhyCtl_1: %04x ", ptcw_1);
5371 printf("PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr);
5372 printf("PhyCtl_1_Rts: %04x ", ptcw_1_Rts);
5373 printf("PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts);
5374 printf("MainRates: %04x ", mainrates);
5375 printf("XtraFrameTypes: %04x ", xtraft);
5376 printf("\n");
5378 bcm_format_hex(hexbuf, iv, sizeof(txh->IV));
5379 printf("SecIV: %s\n", hexbuf);
5380 bcm_format_hex(hexbuf, ra, sizeof(txh->TxFrameRA));
5381 printf("RA: %s\n", hexbuf);
5383 printf("Fb FES Time: %04x ", tfestfb);
5384 bcm_format_hex(hexbuf, rtspfb, sizeof(txh->RTSPLCPFallback));
5385 printf("RTS PLCP: %s ", hexbuf);
5386 printf("RTS DUR: %04x ", rtsdfb);
5387 bcm_format_hex(hexbuf, fragpfb, sizeof(txh->FragPLCPFallback));
5388 printf("PLCP: %s ", hexbuf);
5389 printf("DUR: %04x", fragdfb);
5390 printf("\n");
5392 printf("MModeLen: %04x ", mmodelen);
5393 printf("MModeFbrLen: %04x\n", mmodefbrlen);
5395 printf("FrameID: %04x\n", tfid);
5396 printf("TxStatus: %04x\n", txs);
5398 printf("MaxNumMpdu: %04x\n", mnmpdu);
5399 printf("MaxAggbyte: %04x\n", mabyte);
5400 printf("MaxAggbyte_fb: %04x\n", mabyte_f);
5401 printf("MinByte: %04x\n", mmbyte);
5403 bcm_format_hex(hexbuf, rtsph, sizeof(txh->RTSPhyHeader));
5404 printf("RTS PLCP: %s ", hexbuf);
5405 bcm_format_hex(hexbuf, (uint8 *) &rts, sizeof(txh->rts_frame));
5406 printf("RTS Frame: %s", hexbuf);
5407 printf("\n");
5409 if (mtcl & TXC_SENDRTS) {
5410 wlc_print_dot11_mac_hdr((uint8 *) &rts,
5411 sizeof(txh->rts_frame));
5414 #endif /* defined(BCMDBG) */
5416 #if defined(BCMDBG)
5417 void wlc_print_rxh(d11rxhdr_t *rxh)
5419 uint16 len = rxh->RxFrameSize;
5420 uint16 phystatus_0 = rxh->PhyRxStatus_0;
5421 uint16 phystatus_1 = rxh->PhyRxStatus_1;
5422 uint16 phystatus_2 = rxh->PhyRxStatus_2;
5423 uint16 phystatus_3 = rxh->PhyRxStatus_3;
5424 uint16 macstatus1 = rxh->RxStatus1;
5425 uint16 macstatus2 = rxh->RxStatus2;
5426 char flagstr[64];
5427 char lenbuf[20];
5428 static const bcm_bit_desc_t macstat_flags[] = {
5429 {RXS_FCSERR, "FCSErr"},
5430 {RXS_RESPFRAMETX, "Reply"},
5431 {RXS_PBPRES, "PADDING"},
5432 {RXS_DECATMPT, "DeCr"},
5433 {RXS_DECERR, "DeCrErr"},
5434 {RXS_BCNSENT, "Bcn"},
5435 {0, NULL}
5438 prhex("Raw RxDesc", (uchar *) rxh, sizeof(d11rxhdr_t));
5440 bcm_format_flags(macstat_flags, macstatus1, flagstr, 64);
5442 snprintf(lenbuf, sizeof(lenbuf), "0x%x", len);
5444 printf("RxFrameSize: %6s (%d)%s\n", lenbuf, len,
5445 (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : "");
5446 printf("RxPHYStatus: %04x %04x %04x %04x\n",
5447 phystatus_0, phystatus_1, phystatus_2, phystatus_3);
5448 printf("RxMACStatus: %x %s\n", macstatus1, flagstr);
5449 printf("RXMACaggtype: %x\n", (macstatus2 & RXS_AGGTYPE_MASK));
5450 printf("RxTSFTime: %04x\n", rxh->RxTSFTime);
5453 void
5454 wlc_print_hdrs(wlc_info_t *wlc, const char *prefix, uint8 *frame,
5455 d11txh_t *txh, d11rxhdr_t *rxh, uint len)
5457 ASSERT(!(txh && rxh));
5459 printf("\nwl%d: %s:\n", wlc->pub->unit, prefix);
5461 if (txh) {
5462 wlc_print_txdesc(txh);
5463 } else if (rxh) {
5464 wlc_print_rxh(rxh);
5467 if (len > 0) {
5468 ASSERT(frame != NULL);
5469 wlc_print_dot11hdr(frame, len);
5472 #endif /* defined(BCMDBG) */
5474 #if defined(BCMDBG)
5475 int wlc_format_ssid(char *buf, const uchar ssid[], uint ssid_len)
5477 uint i, c;
5478 char *p = buf;
5479 char *endp = buf + SSID_FMT_BUF_LEN;
5481 if (ssid_len > DOT11_MAX_SSID_LEN)
5482 ssid_len = DOT11_MAX_SSID_LEN;
5484 for (i = 0; i < ssid_len; i++) {
5485 c = (uint) ssid[i];
5486 if (c == '\\') {
5487 *p++ = '\\';
5488 *p++ = '\\';
5489 } else if (bcm_isprint((uchar) c)) {
5490 *p++ = (char)c;
5491 } else {
5492 p += snprintf(p, (endp - p), "\\x%02X", c);
5495 *p = '\0';
5496 ASSERT(p < endp);
5498 return (int)(p - buf);
5500 #endif /* defined(BCMDBG) */
5502 uint16 wlc_rate_shm_offset(wlc_info_t *wlc, uint8 rate)
5504 return wlc_bmac_rate_shm_offset(wlc->hw, rate);
5507 /* Callback for device removed */
5508 #if defined(WLC_HIGH_ONLY)
5509 void wlc_device_removed(void *arg)
5511 wlc_info_t *wlc = (wlc_info_t *) arg;
5513 wlc->device_present = FALSE;
5515 #endif /* WLC_HIGH_ONLY */
5518 * Attempts to queue a packet onto a multiple-precedence queue,
5519 * if necessary evicting a lower precedence packet from the queue.
5521 * 'prec' is the precedence number that has already been mapped
5522 * from the packet priority.
5524 * Returns TRUE if packet consumed (queued), FALSE if not.
5526 bool BCMFASTPATH
5527 wlc_prec_enq(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec)
5529 return wlc_prec_enq_head(wlc, q, pkt, prec, FALSE);
5532 bool BCMFASTPATH
5533 wlc_prec_enq_head(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec,
5534 bool head)
5536 void *p;
5537 int eprec = -1; /* precedence to evict from */
5539 /* Determine precedence from which to evict packet, if any */
5540 if (pktq_pfull(q, prec))
5541 eprec = prec;
5542 else if (pktq_full(q)) {
5543 p = pktq_peek_tail(q, &eprec);
5544 ASSERT(p != NULL);
5545 if (eprec > prec) {
5546 WL_ERROR(("%s: Failing: eprec %d > prec %d\n", __func__,
5547 eprec, prec));
5548 return FALSE;
5552 /* Evict if needed */
5553 if (eprec >= 0) {
5554 bool discard_oldest;
5556 /* Detect queueing to unconfigured precedence */
5557 ASSERT(!pktq_pempty(q, eprec));
5559 discard_oldest = AC_BITMAP_TST(wlc->wme_dp, eprec);
5561 /* Refuse newer packet unless configured to discard oldest */
5562 if (eprec == prec && !discard_oldest) {
5563 WL_ERROR(("%s: No where to go, prec == %d\n", __func__,
5564 prec));
5565 return FALSE;
5568 /* Evict packet according to discard policy */
5569 p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q,
5570 eprec);
5571 ASSERT(p != NULL);
5573 /* Increment wme stats */
5574 if (WME_ENAB(wlc->pub)) {
5575 WLCNTINCR(wlc->pub->_wme_cnt->
5576 tx_failed[WME_PRIO2AC(PKTPRIO(p))].packets);
5577 WLCNTADD(wlc->pub->_wme_cnt->
5578 tx_failed[WME_PRIO2AC(PKTPRIO(p))].bytes,
5579 pkttotlen(wlc->osh, p));
5582 ASSERT(0);
5583 PKTFREE(wlc->osh, p, TRUE);
5584 WLCNTINCR(wlc->pub->_cnt->txnobuf);
5587 /* Enqueue */
5588 if (head)
5589 p = pktq_penq_head(q, prec, pkt);
5590 else
5591 p = pktq_penq(q, prec, pkt);
5592 ASSERT(p != NULL);
5594 return TRUE;
5597 void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, void *sdu, uint prec)
5599 wlc_info_t *wlc = (wlc_info_t *) ctx;
5600 wlc_txq_info_t *qi = wlc->active_queue; /* Check me */
5601 struct pktq *q = &qi->q;
5602 int prio;
5604 prio = PKTPRIO(sdu);
5606 ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat);
5608 if (!wlc_prec_enq(wlc, q, sdu, prec)) {
5609 if (!EDCF_ENAB(wlc->pub)
5610 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL))
5611 WL_ERROR(("wl%d: wlc_txq_enq: txq overflow\n",
5612 wlc->pub->unit));
5614 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5615 PKTFREE(wlc->osh, sdu, TRUE);
5616 WLCNTINCR(wlc->pub->_cnt->txnobuf);
5619 /* Check if flow control needs to be turned on after enqueuing the packet
5620 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5621 * to drop instead of relying on stack to make the right decision
5623 if (!EDCF_ENAB(wlc->pub)
5624 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5625 if (pktq_len(q) >= wlc->pub->tunables->datahiwat) {
5626 wlc_txflowcontrol(wlc, qi, ON, ALLPRIO);
5628 } else if (wlc->pub->_priofc) {
5629 if (pktq_plen(q, wlc_prio2prec_map[prio]) >=
5630 wlc->pub->tunables->datahiwat) {
5631 wlc_txflowcontrol(wlc, qi, ON, prio);
5636 bool BCMFASTPATH
5637 wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw)
5639 uint8 prio;
5640 uint fifo;
5641 void *pkt;
5642 struct scb *scb = &global_scb;
5643 struct dot11_header *d11_header = (struct dot11_header *)PKTDATA(sdu);
5644 uint16 type, fc;
5646 ASSERT(sdu);
5648 fc = ltoh16(d11_header->fc);
5649 type = FC_TYPE(fc);
5651 /* 802.11 standard requires management traffic to go at highest priority */
5652 prio = (type == FC_TYPE_DATA ? PKTPRIO(sdu) : MAXPRIO);
5653 fifo = prio2fifo[prio];
5655 ASSERT((uint) PKTHEADROOM(sdu) >= TXOFF);
5656 ASSERT(!PKTSHARED(sdu));
5657 ASSERT(!PKTNEXT(sdu));
5658 ASSERT(!PKTLINK(sdu));
5659 ASSERT(fifo < NFIFO);
5661 pkt = sdu;
5662 if (unlikely
5663 (wlc_d11hdrs_mac80211(wlc, hw, pkt, scb, 0, 1, fifo, 0, NULL, 0)))
5664 return -EINVAL;
5665 wlc_txq_enq(wlc, scb, pkt, WLC_PRIO_TO_PREC(prio));
5666 wlc_send_q(wlc, wlc->active_queue);
5668 WLCNTINCR(wlc->pub->_cnt->ieee_tx);
5669 return 0;
5672 void BCMFASTPATH wlc_send_q(wlc_info_t *wlc, wlc_txq_info_t *qi)
5674 void *pkt[DOT11_MAXNUMFRAGS];
5675 int prec;
5676 uint16 prec_map;
5677 int err = 0, i, count;
5678 uint fifo;
5679 struct pktq *q = &qi->q;
5680 struct ieee80211_tx_info *tx_info;
5682 /* only do work for the active queue */
5683 if (qi != wlc->active_queue)
5684 return;
5686 if (in_send_q)
5687 return;
5688 else
5689 in_send_q = TRUE;
5691 prec_map = wlc->tx_prec_map;
5693 /* Send all the enq'd pkts that we can.
5694 * Dequeue packets with precedence with empty HW fifo only
5696 while (prec_map && (pkt[0] = pktq_mdeq(q, prec_map, &prec))) {
5697 tx_info = IEEE80211_SKB_CB(pkt[0]);
5698 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
5699 err = wlc_sendampdu(wlc->ampdu, qi, pkt, prec);
5700 } else {
5701 count = 1;
5702 err = wlc_prep_pdu(wlc, pkt[0], &fifo);
5703 if (!err) {
5704 for (i = 0; i < count; i++) {
5705 wlc_txfifo(wlc, fifo, pkt[i], TRUE, 1);
5710 if (err == BCME_BUSY) {
5711 pktq_penq_head(q, prec, pkt[0]);
5712 /* If send failed due to any other reason than a change in
5713 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5715 if (prec_map == wlc->tx_prec_map)
5716 break;
5717 prec_map = wlc->tx_prec_map;
5721 /* Check if flow control needs to be turned off after sending the packet */
5722 if (!EDCF_ENAB(wlc->pub)
5723 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5724 if (wlc_txflowcontrol_prio_isset(wlc, qi, ALLPRIO)
5725 && (pktq_len(q) < wlc->pub->tunables->datahiwat / 2)) {
5726 wlc_txflowcontrol(wlc, qi, OFF, ALLPRIO);
5728 } else if (wlc->pub->_priofc) {
5729 int prio;
5730 for (prio = MAXPRIO; prio >= 0; prio--) {
5731 if (wlc_txflowcontrol_prio_isset(wlc, qi, prio) &&
5732 (pktq_plen(q, wlc_prio2prec_map[prio]) <
5733 wlc->pub->tunables->datahiwat / 2)) {
5734 wlc_txflowcontrol(wlc, qi, OFF, prio);
5738 in_send_q = FALSE;
5742 * bcmc_fid_generate:
5743 * Generate frame ID for a BCMC packet. The frag field is not used
5744 * for MC frames so is used as part of the sequence number.
5746 static INLINE uint16
5747 bcmc_fid_generate(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh)
5749 uint16 frameid;
5751 frameid = ltoh16(txh->TxFrameID) & ~(TXFID_SEQ_MASK | TXFID_QUEUE_MASK);
5752 frameid |=
5753 (((wlc->
5754 mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5755 TX_BCMC_FIFO;
5757 return frameid;
5760 void BCMFASTPATH
5761 wlc_txfifo(wlc_info_t *wlc, uint fifo, void *p, bool commit, int8 txpktpend)
5763 uint16 frameid = INVALIDFID;
5764 d11txh_t *txh;
5766 ASSERT(fifo < NFIFO);
5767 txh = (d11txh_t *) PKTDATA(p);
5769 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5770 * ucode or BSS info as appropriate.
5772 if (fifo == TX_BCMC_FIFO) {
5773 frameid = ltoh16(txh->TxFrameID);
5777 if (WLC_WAR16165(wlc))
5778 wlc_war16165(wlc, TRUE);
5780 #ifdef WLC_HIGH_ONLY
5781 if (RPCTX_ENAB(wlc->pub)) {
5782 (void)wlc_rpctx_tx(wlc->rpctx, fifo, p, commit, frameid,
5783 txpktpend);
5784 return;
5786 #else
5788 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5789 * in wlc_bmac_txfifo()
5791 if (commit) {
5792 TXPKTPENDINC(wlc, fifo, txpktpend);
5793 WL_TRACE(("wlc_txfifo, pktpend inc %d to %d\n", txpktpend,
5794 TXPKTPENDGET(wlc, fifo)));
5797 /* Commit BCMC sequence number in the SHM frame ID location */
5798 if (frameid != INVALIDFID)
5799 BCMCFID(wlc, frameid);
5801 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) {
5802 WL_ERROR(("wlc_txfifo: fatal, toss frames !!!\n"));
5804 #endif /* WLC_HIGH_ONLY */
5807 static uint16
5808 wlc_compute_airtime(wlc_info_t *wlc, ratespec_t rspec, uint length)
5810 uint16 usec = 0;
5811 uint mac_rate = RSPEC2RATE(rspec);
5812 uint nsyms;
5814 if (IS_MCS(rspec)) {
5815 /* not supported yet */
5816 ASSERT(0);
5817 } else if (IS_OFDM(rspec)) {
5818 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5820 * Nbits = length * 8
5821 * Nbits/sym = Mbps * 4 = mac_rate * 2
5823 nsyms = CEIL((length * 8), (mac_rate * 2));
5825 /* usec = symbols * usec/symbol */
5826 usec = (uint16) (nsyms * APHY_SYMBOL_TIME);
5827 return usec;
5828 } else {
5829 switch (mac_rate) {
5830 case WLC_RATE_1M:
5831 usec = length << 3;
5832 break;
5833 case WLC_RATE_2M:
5834 usec = length << 2;
5835 break;
5836 case WLC_RATE_5M5:
5837 usec = (length << 4) / 11;
5838 break;
5839 case WLC_RATE_11M:
5840 usec = (length << 3) / 11;
5841 break;
5842 default:
5843 WL_ERROR(("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n", wlc->pub->unit, rspec));
5844 ASSERT((const char *)"Bad phy_rate" == NULL);
5845 break;
5849 return usec;
5852 void BCMFASTPATH
5853 wlc_compute_plcp(wlc_info_t *wlc, ratespec_t rspec, uint length, uint8 *plcp)
5855 if (IS_MCS(rspec)) {
5856 wlc_compute_mimo_plcp(rspec, length, plcp);
5857 } else if (IS_OFDM(rspec)) {
5858 wlc_compute_ofdm_plcp(rspec, length, plcp);
5859 } else {
5860 wlc_compute_cck_plcp(rspec, length, plcp);
5862 return;
5865 /* Rate: 802.11 rate code, length: PSDU length in octets */
5866 static void wlc_compute_mimo_plcp(ratespec_t rspec, uint length, uint8 *plcp)
5868 uint8 mcs = (uint8) (rspec & RSPEC_RATE_MASK);
5869 ASSERT(IS_MCS(rspec));
5870 plcp[0] = mcs;
5871 if (RSPEC_IS40MHZ(rspec) || (mcs == 32))
5872 plcp[0] |= MIMO_PLCP_40MHZ;
5873 WLC_SET_MIMO_PLCP_LEN(plcp, length);
5874 plcp[3] = RSPEC_MIMOPLCP3(rspec); /* rspec already holds this byte */
5875 plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5876 plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5877 plcp[5] = 0;
5880 /* Rate: 802.11 rate code, length: PSDU length in octets */
5881 static void BCMFASTPATH
5882 wlc_compute_ofdm_plcp(ratespec_t rspec, uint32 length, uint8 *plcp)
5884 uint8 rate_signal;
5885 uint32 tmp = 0;
5886 int rate = RSPEC2RATE(rspec);
5888 ASSERT(IS_OFDM(rspec));
5890 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5891 rate_signal = rate_info[rate] & RATE_MASK;
5892 ASSERT(rate_signal != 0);
5894 bzero(plcp, D11_PHY_HDR_LEN);
5895 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal);
5897 tmp = (length & 0xfff) << 5;
5898 plcp[2] |= (tmp >> 16) & 0xff;
5899 plcp[1] |= (tmp >> 8) & 0xff;
5900 plcp[0] |= tmp & 0xff;
5902 return;
5906 * Compute PLCP, but only requires actual rate and length of pkt.
5907 * Rate is given in the driver standard multiple of 500 kbps.
5908 * le is set for 11 Mbps rate if necessary.
5909 * Broken out for PRQ.
5912 static void wlc_cck_plcp_set(int rate_500, uint length, uint8 *plcp)
5914 uint16 usec = 0;
5915 uint8 le = 0;
5917 switch (rate_500) {
5918 case WLC_RATE_1M:
5919 usec = length << 3;
5920 break;
5921 case WLC_RATE_2M:
5922 usec = length << 2;
5923 break;
5924 case WLC_RATE_5M5:
5925 usec = (length << 4) / 11;
5926 if ((length << 4) - (usec * 11) > 0)
5927 usec++;
5928 break;
5929 case WLC_RATE_11M:
5930 usec = (length << 3) / 11;
5931 if ((length << 3) - (usec * 11) > 0) {
5932 usec++;
5933 if ((usec * 11) - (length << 3) >= 8)
5934 le = D11B_PLCP_SIGNAL_LE;
5936 break;
5938 default:
5939 WL_ERROR(("wlc_cck_plcp_set: unsupported rate %d\n", rate_500));
5940 rate_500 = WLC_RATE_1M;
5941 usec = length << 3;
5942 break;
5944 /* PLCP signal byte */
5945 plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */
5946 /* PLCP service byte */
5947 plcp[1] = (uint8) (le | D11B_PLCP_SIGNAL_LOCKED);
5948 /* PLCP length uint16, little endian */
5949 plcp[2] = usec & 0xff;
5950 plcp[3] = (usec >> 8) & 0xff;
5951 /* PLCP CRC16 */
5952 plcp[4] = 0;
5953 plcp[5] = 0;
5956 /* Rate: 802.11 rate code, length: PSDU length in octets */
5957 static void wlc_compute_cck_plcp(ratespec_t rspec, uint length, uint8 *plcp)
5959 int rate = RSPEC2RATE(rspec);
5961 ASSERT(IS_CCK(rspec));
5963 wlc_cck_plcp_set(rate, length, plcp);
5966 /* wlc_compute_frame_dur()
5968 * Calculate the 802.11 MAC header DUR field for MPDU
5969 * DUR for a single frame = 1 SIFS + 1 ACK
5970 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5972 * rate MPDU rate in unit of 500kbps
5973 * next_frag_len next MPDU length in bytes
5974 * preamble_type use short/GF or long/MM PLCP header
5976 static uint16 BCMFASTPATH
5977 wlc_compute_frame_dur(wlc_info_t *wlc, ratespec_t rate, uint8 preamble_type,
5978 uint next_frag_len)
5980 uint16 dur, sifs;
5982 sifs = SIFS(wlc->band);
5984 dur = sifs;
5985 dur += (uint16) wlc_calc_ack_time(wlc, rate, preamble_type);
5987 if (next_frag_len) {
5988 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5989 dur *= 2;
5990 /* add another SIFS and the frag time */
5991 dur += sifs;
5992 dur +=
5993 (uint16) wlc_calc_frame_time(wlc, rate, preamble_type,
5994 next_frag_len);
5996 return dur;
5999 /* wlc_compute_rtscts_dur()
6001 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
6002 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
6003 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
6005 * cts cts-to-self or rts/cts
6006 * rts_rate rts or cts rate in unit of 500kbps
6007 * rate next MPDU rate in unit of 500kbps
6008 * frame_len next MPDU frame length in bytes
6010 uint16 BCMFASTPATH
6011 wlc_compute_rtscts_dur(wlc_info_t *wlc, bool cts_only, ratespec_t rts_rate,
6012 ratespec_t frame_rate, uint8 rts_preamble_type,
6013 uint8 frame_preamble_type, uint frame_len, bool ba)
6015 uint16 dur, sifs;
6017 sifs = SIFS(wlc->band);
6019 if (!cts_only) { /* RTS/CTS */
6020 dur = 3 * sifs;
6021 dur +=
6022 (uint16) wlc_calc_cts_time(wlc, rts_rate,
6023 rts_preamble_type);
6024 } else { /* CTS-TO-SELF */
6025 dur = 2 * sifs;
6028 dur +=
6029 (uint16) wlc_calc_frame_time(wlc, frame_rate, frame_preamble_type,
6030 frame_len);
6031 if (ba)
6032 dur +=
6033 (uint16) wlc_calc_ba_time(wlc, frame_rate,
6034 WLC_SHORT_PREAMBLE);
6035 else
6036 dur +=
6037 (uint16) wlc_calc_ack_time(wlc, frame_rate,
6038 frame_preamble_type);
6039 return dur;
6042 static bool wlc_phy_rspec_check(wlc_info_t *wlc, uint16 bw, ratespec_t rspec)
6044 if (IS_MCS(rspec)) {
6045 uint mcs = rspec & RSPEC_RATE_MASK;
6047 if (mcs < 8) {
6048 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
6049 } else if ((mcs >= 8) && (mcs <= 23)) {
6050 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SDM);
6051 } else if (mcs == 32) {
6052 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
6053 ASSERT(bw == PHY_TXC1_BW_40MHZ_DUP);
6055 } else if (IS_OFDM(rspec)) {
6056 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_STBC);
6057 } else {
6058 ASSERT(IS_CCK(rspec));
6060 ASSERT((bw == PHY_TXC1_BW_20MHZ)
6061 || (bw == PHY_TXC1_BW_20MHZ_UP));
6062 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SISO);
6065 return TRUE;
6068 uint16 BCMFASTPATH wlc_phytxctl1_calc(wlc_info_t *wlc, ratespec_t rspec)
6070 uint16 phyctl1 = 0;
6071 uint16 bw;
6073 if (WLCISLCNPHY(wlc->band)) {
6074 bw = PHY_TXC1_BW_20MHZ;
6075 } else {
6076 bw = RSPEC_GET_BW(rspec);
6077 /* 10Mhz is not supported yet */
6078 if (bw < PHY_TXC1_BW_20MHZ) {
6079 WL_ERROR(("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n", bw));
6080 bw = PHY_TXC1_BW_20MHZ;
6083 wlc_phy_rspec_check(wlc, bw, rspec);
6086 if (IS_MCS(rspec)) {
6087 uint mcs = rspec & RSPEC_RATE_MASK;
6089 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
6090 phyctl1 = RSPEC_PHYTXBYTE2(rspec);
6091 /* set the upper byte of phyctl1 */
6092 phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8);
6093 } else if (IS_CCK(rspec) && !WLCISLCNPHY(wlc->band)
6094 && !WLCISSSLPNPHY(wlc->band)) {
6095 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
6096 /* Eventually MIMOPHY would also be converted to this format */
6097 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
6098 phyctl1 = (bw | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
6099 } else { /* legacy OFDM/CCK */
6100 int16 phycfg;
6101 /* get the phyctl byte from rate phycfg table */
6102 phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec));
6103 if (phycfg == -1) {
6104 WL_ERROR(("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n"));
6105 ASSERT(0);
6106 phycfg = 0;
6108 /* set the upper byte of phyctl1 */
6109 phyctl1 =
6110 (bw | (phycfg << 8) |
6111 (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
6114 #ifdef BCMDBG
6115 /* phy clock must support 40Mhz if tx descriptor uses it */
6116 if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) {
6117 ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ);
6118 #ifndef WLC_HIGH_ONLY
6119 ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi));
6120 #endif
6122 #endif /* BCMDBG */
6123 return phyctl1;
6126 ratespec_t BCMFASTPATH
6127 wlc_rspec_to_rts_rspec(wlc_info_t *wlc, ratespec_t rspec, bool use_rspec,
6128 uint16 mimo_ctlchbw)
6130 ratespec_t rts_rspec = 0;
6132 if (use_rspec) {
6133 /* use frame rate as rts rate */
6134 rts_rspec = rspec;
6136 } else if (wlc->band->gmode && wlc->protection->_g && !IS_CCK(rspec)) {
6137 /* Use 11Mbps as the g protection RTS target rate and fallback.
6138 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
6139 * target in case 11 Mbps is not Basic.
6140 * 6 and 9 Mbps are not usually selected by rate selection, but even
6141 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
6143 rts_rspec = WLC_BASIC_RATE(wlc, WLC_RATE_11M);
6144 } else {
6145 /* calculate RTS rate and fallback rate based on the frame rate
6146 * RTS must be sent at a basic rate since it is a
6147 * control frame, sec 9.6 of 802.11 spec
6149 rts_rspec = WLC_BASIC_RATE(wlc, rspec);
6152 if (WLC_PHY_11N_CAP(wlc->band)) {
6153 /* set rts txbw to correct side band */
6154 rts_rspec &= ~RSPEC_BW_MASK;
6156 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
6157 * (DUP), otherwise send RTS on control channel
6159 if (RSPEC_IS40MHZ(rspec) && !IS_CCK(rts_rspec))
6160 rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT);
6161 else
6162 rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
6164 /* pick siso/cdd as default for ofdm */
6165 if (IS_OFDM(rts_rspec)) {
6166 rts_rspec &= ~RSPEC_STF_MASK;
6167 rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
6170 return rts_rspec;
6174 * Add d11txh_t, cck_phy_hdr_t.
6176 * 'p' data must start with 802.11 MAC header
6177 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
6179 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
6182 static uint16 BCMFASTPATH
6183 wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6184 void *p, struct scb *scb, uint frag,
6185 uint nfrags, uint queue, uint next_frag_len,
6186 wsec_key_t *key, ratespec_t rspec_override)
6188 struct dot11_header *h;
6189 d11txh_t *txh;
6190 uint8 *plcp, plcp_fallback[D11_PHY_HDR_LEN];
6191 osl_t *osh;
6192 int len, phylen, rts_phylen;
6193 uint16 fc, type, frameid, mch, phyctl, xfts, mainrates;
6194 uint16 seq = 0, mcl = 0, status = 0;
6195 ratespec_t rspec[2] = { WLC_RATE_1M, WLC_RATE_1M }, rts_rspec[2] = {
6196 WLC_RATE_1M, WLC_RATE_1M};
6197 bool use_rts = FALSE;
6198 bool use_cts = FALSE;
6199 bool use_rifs = FALSE;
6200 bool short_preamble[2] = { FALSE, FALSE };
6201 uint8 preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
6202 uint8 rts_preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
6203 uint8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN];
6204 struct dot11_rts_frame *rts = NULL;
6205 bool qos;
6206 uint ac;
6207 uint32 rate_val[2];
6208 bool hwtkmic = FALSE;
6209 uint16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
6210 #ifdef WLANTSEL
6211 #define ANTCFG_NONE 0xFF
6212 uint8 antcfg = ANTCFG_NONE;
6213 uint8 fbantcfg = ANTCFG_NONE;
6214 #endif
6215 uint phyctl1_stf = 0;
6216 uint16 durid = 0;
6217 struct ieee80211_tx_rate *txrate[2];
6218 int k;
6219 struct ieee80211_tx_info *tx_info;
6220 bool is_mcs[2];
6221 uint16 mimo_txbw;
6222 uint8 mimo_preamble_type;
6224 frameid = 0;
6226 ASSERT(queue < NFIFO);
6228 osh = wlc->osh;
6230 /* locate 802.11 MAC header */
6231 h = (struct dot11_header *)PKTDATA(p);
6232 fc = ltoh16(h->fc);
6233 type = FC_TYPE(fc);
6235 qos = (type == FC_TYPE_DATA && FC_SUBTYPE_ANY_QOS(FC_SUBTYPE(fc)));
6237 /* compute length of frame in bytes for use in PLCP computations */
6238 len = pkttotlen(osh, p);
6239 phylen = len + DOT11_FCS_LEN;
6241 /* If WEP enabled, add room in phylen for the additional bytes of
6242 * ICV which MAC generates. We do NOT add the additional bytes to
6243 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
6244 * in this case
6246 if (key) {
6247 phylen += key->icv_len;
6250 /* Get tx_info */
6251 tx_info = IEEE80211_SKB_CB(p);
6252 ASSERT(tx_info);
6254 /* add PLCP */
6255 plcp = PKTPUSH(p, D11_PHY_HDR_LEN);
6257 /* add Broadcom tx descriptor header */
6258 txh = (d11txh_t *) PKTPUSH(p, D11_TXH_LEN);
6259 bzero((char *)txh, D11_TXH_LEN);
6261 /* setup frameid */
6262 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
6263 /* non-AP STA should never use BCMC queue */
6264 ASSERT(queue != TX_BCMC_FIFO);
6265 if (queue == TX_BCMC_FIFO) {
6266 WL_ERROR(("wl%d: %s: ASSERT queue == TX_BCMC!\n",
6267 WLCWLUNIT(wlc), __func__));
6268 frameid = bcmc_fid_generate(wlc, NULL, txh);
6269 } else {
6270 /* Increment the counter for first fragment */
6271 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
6272 SCB_SEQNUM(scb, PKTPRIO(p))++;
6275 /* extract fragment number from frame first */
6276 seq = ltoh16(seq) & FRAGNUM_MASK;
6277 seq |= (SCB_SEQNUM(scb, PKTPRIO(p)) << SEQNUM_SHIFT);
6278 h->seq = htol16(seq);
6280 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
6281 (queue & TXFID_QUEUE_MASK);
6284 frameid |= queue & TXFID_QUEUE_MASK;
6286 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
6287 if (SCB_PS(scb) || ((fc & FC_KIND_MASK) == FC_BEACON))
6288 mcl |= TXC_IGNOREPMQ;
6290 ASSERT(hw->max_rates <= IEEE80211_TX_MAX_RATES);
6291 ASSERT(hw->max_rates == 2);
6293 txrate[0] = tx_info->control.rates;
6294 txrate[1] = txrate[0] + 1;
6296 ASSERT(txrate[0]->idx >= 0);
6297 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
6298 if (txrate[1]->idx < 0) {
6299 txrate[1] = txrate[0];
6301 #ifdef WLC_HIGH_ONLY
6302 /* Double protection , just in case */
6303 if (txrate[0]->idx > HIGHEST_SINGLE_STREAM_MCS)
6304 txrate[0]->idx = HIGHEST_SINGLE_STREAM_MCS;
6305 if (txrate[1]->idx > HIGHEST_SINGLE_STREAM_MCS)
6306 txrate[1]->idx = HIGHEST_SINGLE_STREAM_MCS;
6307 #endif
6309 for (k = 0; k < hw->max_rates; k++) {
6310 is_mcs[k] =
6311 txrate[k]->flags & IEEE80211_TX_RC_MCS ? TRUE : FALSE;
6312 if (!is_mcs[k]) {
6313 ASSERT(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU));
6314 if ((txrate[k]->idx >= 0)
6315 && (txrate[k]->idx <
6316 hw->wiphy->bands[tx_info->band]->n_bitrates)) {
6317 rate_val[k] =
6318 hw->wiphy->bands[tx_info->band]->
6319 bitrates[txrate[k]->idx].hw_value;
6320 short_preamble[k] =
6321 txrate[k]->
6322 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ?
6323 TRUE : FALSE;
6324 } else {
6325 ASSERT((txrate[k]->idx >= 0) &&
6326 (txrate[k]->idx <
6327 hw->wiphy->bands[tx_info->band]->
6328 n_bitrates));
6329 rate_val[k] = WLC_RATE_1M;
6331 } else {
6332 rate_val[k] = txrate[k]->idx;
6334 /* Currently only support same setting for primay and fallback rates.
6335 * Unify flags for each rate into a single value for the frame
6337 use_rts |=
6338 txrate[k]->
6339 flags & IEEE80211_TX_RC_USE_RTS_CTS ? TRUE : FALSE;
6340 use_cts |=
6341 txrate[k]->
6342 flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? TRUE : FALSE;
6344 if (is_mcs[k])
6345 rate_val[k] |= NRATE_MCS_INUSE;
6347 rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, rate_val[k]);
6349 /* (1) RATE: determine and validate primary rate and fallback rates */
6350 if (!RSPEC_ACTIVE(rspec[k])) {
6351 ASSERT(RSPEC_ACTIVE(rspec[k]));
6352 rspec[k] = WLC_RATE_1M;
6353 } else {
6354 if (WLANTSEL_ENAB(wlc) && !ETHER_ISMULTI(&h->a1)) {
6355 /* set tx antenna config */
6356 wlc_antsel_antcfg_get(wlc->asi, FALSE, FALSE, 0,
6357 0, &antcfg, &fbantcfg);
6362 phyctl1_stf = wlc->stf->ss_opmode;
6364 if (N_ENAB(wlc->pub)) {
6365 for (k = 0; k < hw->max_rates; k++) {
6366 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
6367 if (((IS_MCS(rspec[k]) &&
6368 IS_SINGLE_STREAM(rspec[k] & RSPEC_RATE_MASK)) ||
6369 IS_OFDM(rspec[k]))
6370 && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY)
6371 || !(rspec[k] & RSPEC_OVERRIDE))) {
6372 rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK);
6374 /* For SISO MCS use STBC if possible */
6375 if (IS_MCS(rspec[k])
6376 && WLC_STF_SS_STBC_TX(wlc, scb)) {
6377 uint8 stc;
6379 ASSERT(WLC_STBC_CAP_PHY(wlc));
6380 stc = 1; /* Nss for single stream is always 1 */
6381 rspec[k] |=
6382 (PHY_TXC1_MODE_STBC <<
6383 RSPEC_STF_SHIFT) | (stc <<
6384 RSPEC_STC_SHIFT);
6385 } else
6386 rspec[k] |=
6387 (phyctl1_stf << RSPEC_STF_SHIFT);
6390 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
6391 if (CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ) {
6392 /* default txbw is 20in40 SB */
6393 mimo_ctlchbw = mimo_txbw =
6394 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC)
6395 ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
6397 if (IS_MCS(rspec[k])) {
6398 /* mcs 32 must be 40b/w DUP */
6399 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
6400 mimo_txbw =
6401 PHY_TXC1_BW_40MHZ_DUP;
6402 /* use override */
6403 } else if (wlc->mimo_40txbw != AUTO)
6404 mimo_txbw = wlc->mimo_40txbw;
6405 /* else check if dst is using 40 Mhz */
6406 else if (scb->flags & SCB_IS40)
6407 mimo_txbw = PHY_TXC1_BW_40MHZ;
6408 } else if (IS_OFDM(rspec[k])) {
6409 if (wlc->ofdm_40txbw != AUTO)
6410 mimo_txbw = wlc->ofdm_40txbw;
6411 } else {
6412 ASSERT(IS_CCK(rspec[k]));
6413 if (wlc->cck_40txbw != AUTO)
6414 mimo_txbw = wlc->cck_40txbw;
6416 } else {
6417 /* mcs32 is 40 b/w only.
6418 * This is possible for probe packets on a STA during SCAN
6420 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
6421 /* mcs 0 */
6422 rspec[k] = RSPEC_MIMORATE;
6424 mimo_txbw = PHY_TXC1_BW_20MHZ;
6427 /* Set channel width */
6428 rspec[k] &= ~RSPEC_BW_MASK;
6429 if ((k == 0) || ((k > 0) && IS_MCS(rspec[k])))
6430 rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT);
6431 else
6432 rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
6434 /* Set Short GI */
6435 #ifdef NOSGIYET
6436 if (IS_MCS(rspec[k])
6437 && (txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
6438 rspec[k] |= RSPEC_SHORT_GI;
6439 else if (!(txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
6440 rspec[k] &= ~RSPEC_SHORT_GI;
6441 #else
6442 rspec[k] &= ~RSPEC_SHORT_GI;
6443 #endif
6445 mimo_preamble_type = WLC_MM_PREAMBLE;
6446 if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD)
6447 mimo_preamble_type = WLC_GF_PREAMBLE;
6449 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS)
6450 && (!IS_MCS(rspec[k]))) {
6451 WL_ERROR(("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n", WLCWLUNIT(wlc), __func__));
6452 ASSERT(0 && "Rate mismatch");
6455 if (IS_MCS(rspec[k])) {
6456 preamble_type[k] = mimo_preamble_type;
6458 /* if SGI is selected, then forced mm for single stream */
6459 if ((rspec[k] & RSPEC_SHORT_GI)
6460 && IS_SINGLE_STREAM(rspec[k] &
6461 RSPEC_RATE_MASK)) {
6462 preamble_type[k] = WLC_MM_PREAMBLE;
6466 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
6467 ASSERT(VALID_RATE_DBG(wlc, rspec[0]));
6469 /* should be better conditionalized */
6470 if (!IS_MCS(rspec[0])
6471 && (tx_info->control.rates[0].
6472 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
6473 preamble_type[k] = WLC_SHORT_PREAMBLE;
6475 ASSERT(!IS_MCS(rspec[0])
6476 || WLC_IS_MIMO_PREAMBLE(preamble_type[k]));
6478 } else {
6479 for (k = 0; k < hw->max_rates; k++) {
6480 /* Set ctrlchbw as 20Mhz */
6481 ASSERT(!IS_MCS(rspec[k]));
6482 rspec[k] &= ~RSPEC_BW_MASK;
6483 rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT);
6485 /* for nphy, stf of ofdm frames must follow policies */
6486 if (WLCISNPHY(wlc->band) && IS_OFDM(rspec[k])) {
6487 rspec[k] &= ~RSPEC_STF_MASK;
6488 rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT;
6493 /* Reset these for use with AMPDU's */
6494 txrate[0]->count = 0;
6495 txrate[1]->count = 0;
6497 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
6498 wlc_compute_plcp(wlc, rspec[0], phylen, plcp);
6499 wlc_compute_plcp(wlc, rspec[1], phylen, plcp_fallback);
6500 bcopy(plcp_fallback, (char *)&txh->FragPLCPFallback,
6501 sizeof(txh->FragPLCPFallback));
6503 /* Length field now put in CCK FBR CRC field */
6504 if (IS_CCK(rspec[1])) {
6505 txh->FragPLCPFallback[4] = phylen & 0xff;
6506 txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8;
6509 /* MIMO-RATE: need validation ?? */
6510 mainrates =
6511 IS_OFDM(rspec[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) plcp) :
6512 plcp[0];
6514 /* DUR field for main rate */
6515 if ((fc != FC_PS_POLL) && !ETHER_ISMULTI(&h->a1) && !use_rifs) {
6516 durid =
6517 wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0],
6518 next_frag_len);
6519 h->durid = htol16(durid);
6520 } else if (use_rifs) {
6521 /* NAV protect to end of next max packet size */
6522 durid =
6523 (uint16) wlc_calc_frame_time(wlc, rspec[0],
6524 preamble_type[0],
6525 DOT11_MAX_FRAG_LEN);
6526 durid += RIFS_11N_TIME;
6527 h->durid = htol16(durid);
6530 /* DUR field for fallback rate */
6531 if (fc == FC_PS_POLL)
6532 txh->FragDurFallback = h->durid;
6533 else if (ETHER_ISMULTI(&h->a1) || use_rifs)
6534 txh->FragDurFallback = 0;
6535 else {
6536 durid = wlc_compute_frame_dur(wlc, rspec[1],
6537 preamble_type[1], next_frag_len);
6538 txh->FragDurFallback = htol16(durid);
6541 /* (4) MAC-HDR: MacTxControlLow */
6542 if (frag == 0)
6543 mcl |= TXC_STARTMSDU;
6545 if (!ETHER_ISMULTI(&h->a1))
6546 mcl |= TXC_IMMEDACK;
6548 if (BAND_5G(wlc->band->bandtype))
6549 mcl |= TXC_FREQBAND_5G;
6551 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC))
6552 mcl |= TXC_BW_40;
6554 /* set AMIC bit if using hardware TKIP MIC */
6555 if (hwtkmic)
6556 mcl |= TXC_AMIC;
6558 txh->MacTxControlLow = htol16(mcl);
6560 /* MacTxControlHigh */
6561 mch = 0;
6563 /* Set fallback rate preamble type */
6564 if ((preamble_type[1] == WLC_SHORT_PREAMBLE) ||
6565 (preamble_type[1] == WLC_GF_PREAMBLE)) {
6566 ASSERT((preamble_type[1] == WLC_GF_PREAMBLE) ||
6567 (!IS_MCS(rspec[1])));
6568 if (RSPEC2RATE(rspec[1]) != WLC_RATE_1M)
6569 mch |= TXC_PREAMBLE_DATA_FB_SHORT;
6572 /* MacFrameControl */
6573 bcopy((char *)&h->fc, (char *)&txh->MacFrameControl, sizeof(uint16));
6575 txh->TxFesTimeNormal = htol16(0);
6577 txh->TxFesTimeFallback = htol16(0);
6579 /* TxFrameRA */
6580 bcopy((char *)&h->a1, (char *)&txh->TxFrameRA, ETHER_ADDR_LEN);
6582 /* TxFrameID */
6583 txh->TxFrameID = htol16(frameid);
6585 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6586 * then we may need to reset the retry cnt's via the status reg
6588 txh->TxStatus = htol16(status);
6590 if (D11REV_GE(wlc->pub->corerev, 16)) {
6591 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6592 * the END of previous structure so that it's compatible in driver.
6593 * In old rev ucode, these fields should be ignored
6595 txh->MaxNMpdus = htol16(0);
6596 txh->MaxABytes_MRT = htol16(0);
6597 txh->MaxABytes_FBR = htol16(0);
6598 txh->MinMBytes = htol16(0);
6601 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6602 /* RTS PLCP header and RTS frame */
6603 if (use_rts || use_cts) {
6604 if (use_rts && use_cts)
6605 use_cts = FALSE;
6607 for (k = 0; k < 2; k++) {
6608 rts_rspec[k] = wlc_rspec_to_rts_rspec(wlc, rspec[k],
6609 FALSE,
6610 mimo_ctlchbw);
6613 if (!IS_OFDM(rts_rspec[0]) &&
6614 !((RSPEC2RATE(rts_rspec[0]) == WLC_RATE_1M) ||
6615 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6616 rts_preamble_type[0] = WLC_SHORT_PREAMBLE;
6617 mch |= TXC_PREAMBLE_RTS_MAIN_SHORT;
6620 if (!IS_OFDM(rts_rspec[1]) &&
6621 !((RSPEC2RATE(rts_rspec[1]) == WLC_RATE_1M) ||
6622 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6623 rts_preamble_type[1] = WLC_SHORT_PREAMBLE;
6624 mch |= TXC_PREAMBLE_RTS_FB_SHORT;
6627 /* RTS/CTS additions to MacTxControlLow */
6628 if (use_cts) {
6629 txh->MacTxControlLow |= htol16(TXC_SENDCTS);
6630 } else {
6631 txh->MacTxControlLow |= htol16(TXC_SENDRTS);
6632 txh->MacTxControlLow |= htol16(TXC_LONGFRAME);
6635 /* RTS PLCP header */
6636 ASSERT(ISALIGNED((uintptr) txh->RTSPhyHeader, sizeof(uint16)));
6637 rts_plcp = txh->RTSPhyHeader;
6638 if (use_cts)
6639 rts_phylen = DOT11_CTS_LEN + DOT11_FCS_LEN;
6640 else
6641 rts_phylen = DOT11_RTS_LEN + DOT11_FCS_LEN;
6643 wlc_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp);
6645 /* fallback rate version of RTS PLCP header */
6646 wlc_compute_plcp(wlc, rts_rspec[1], rts_phylen,
6647 rts_plcp_fallback);
6648 bcopy(rts_plcp_fallback, (char *)&txh->RTSPLCPFallback,
6649 sizeof(txh->RTSPLCPFallback));
6651 /* RTS frame fields... */
6652 rts = (struct dot11_rts_frame *)&txh->rts_frame;
6654 durid = wlc_compute_rtscts_dur(wlc, use_cts, rts_rspec[0],
6655 rspec[0], rts_preamble_type[0],
6656 preamble_type[0], phylen, FALSE);
6657 rts->durid = htol16(durid);
6658 /* fallback rate version of RTS DUR field */
6659 durid = wlc_compute_rtscts_dur(wlc, use_cts,
6660 rts_rspec[1], rspec[1],
6661 rts_preamble_type[1],
6662 preamble_type[1], phylen, FALSE);
6663 txh->RTSDurFallback = htol16(durid);
6665 if (use_cts) {
6666 rts->fc = htol16(FC_CTS);
6667 bcopy((char *)&h->a2, (char *)&rts->ra, ETHER_ADDR_LEN);
6668 } else {
6669 rts->fc = htol16((uint16) FC_RTS);
6670 bcopy((char *)&h->a1, (char *)&rts->ra,
6671 2 * ETHER_ADDR_LEN);
6674 /* mainrate
6675 * low 8 bits: main frag rate/mcs,
6676 * high 8 bits: rts/cts rate/mcs
6678 mainrates |= (IS_OFDM(rts_rspec[0]) ?
6679 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) :
6680 rts_plcp[0]) << 8;
6681 } else {
6682 bzero((char *)txh->RTSPhyHeader, D11_PHY_HDR_LEN);
6683 bzero((char *)&txh->rts_frame, sizeof(struct dot11_rts_frame));
6684 bzero((char *)txh->RTSPLCPFallback,
6685 sizeof(txh->RTSPLCPFallback));
6686 txh->RTSDurFallback = 0;
6689 #ifdef SUPPORT_40MHZ
6690 /* add null delimiter count */
6691 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && IS_MCS(rspec)) {
6692 txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] =
6693 wlc_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen);
6695 #endif
6697 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6698 txh->MacTxControlHigh = htol16(mch);
6700 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6701 txh->MainRates = htol16(mainrates);
6703 /* XtraFrameTypes */
6704 xfts = FRAMETYPE(rspec[1], wlc->mimoft);
6705 xfts |= (FRAMETYPE(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT);
6706 xfts |= (FRAMETYPE(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT);
6707 xfts |=
6708 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC) << XFTS_CHANNEL_SHIFT;
6709 txh->XtraFrameTypes = htol16(xfts);
6711 /* PhyTxControlWord */
6712 phyctl = FRAMETYPE(rspec[0], wlc->mimoft);
6713 if ((preamble_type[0] == WLC_SHORT_PREAMBLE) ||
6714 (preamble_type[0] == WLC_GF_PREAMBLE)) {
6715 ASSERT((preamble_type[0] == WLC_GF_PREAMBLE)
6716 || !IS_MCS(rspec[0]));
6717 if (RSPEC2RATE(rspec[0]) != WLC_RATE_1M)
6718 phyctl |= PHY_TXC_SHORT_HDR;
6719 WLCNTINCR(wlc->pub->_cnt->txprshort);
6722 /* phytxant is properly bit shifted */
6723 phyctl |= wlc_stf_d11hdrs_phyctl_txant(wlc, rspec[0]);
6724 txh->PhyTxControlWord = htol16(phyctl);
6726 /* PhyTxControlWord_1 */
6727 if (WLC_PHY_11N_CAP(wlc->band)) {
6728 uint16 phyctl1 = 0;
6730 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[0]);
6731 txh->PhyTxControlWord_1 = htol16(phyctl1);
6732 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[1]);
6733 txh->PhyTxControlWord_1_Fbr = htol16(phyctl1);
6735 if (use_rts || use_cts) {
6736 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[0]);
6737 txh->PhyTxControlWord_1_Rts = htol16(phyctl1);
6738 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[1]);
6739 txh->PhyTxControlWord_1_FbrRts = htol16(phyctl1);
6743 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6744 * fill in non-zero MModeLen and/or MModeFbrLen
6745 * it will be unnecessary if they are separated
6747 if (IS_MCS(rspec[0]) && (preamble_type[0] == WLC_MM_PREAMBLE)) {
6748 uint16 mmodelen =
6749 wlc_calc_lsig_len(wlc, rspec[0], phylen);
6750 txh->MModeLen = htol16(mmodelen);
6753 if (IS_MCS(rspec[1]) && (preamble_type[1] == WLC_MM_PREAMBLE)) {
6754 uint16 mmodefbrlen =
6755 wlc_calc_lsig_len(wlc, rspec[1], phylen);
6756 txh->MModeFbrLen = htol16(mmodefbrlen);
6760 if (IS_MCS(rspec[0]))
6761 ASSERT(IS_MCS(rspec[1]));
6763 ASSERT(!IS_MCS(rspec[0]) ||
6764 ((preamble_type[0] == WLC_MM_PREAMBLE) == (txh->MModeLen != 0)));
6765 ASSERT(!IS_MCS(rspec[1]) ||
6766 ((preamble_type[1] == WLC_MM_PREAMBLE) ==
6767 (txh->MModeFbrLen != 0)));
6769 ac = wme_fifo2ac[queue];
6770 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) {
6771 uint frag_dur, dur, dur_fallback;
6773 ASSERT(!ETHER_ISMULTI(&h->a1));
6775 /* WME: Update TXOP threshold */
6776 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) {
6777 frag_dur =
6778 wlc_calc_frame_time(wlc, rspec[0], preamble_type[0],
6779 phylen);
6781 if (rts) {
6782 /* 1 RTS or CTS-to-self frame */
6783 dur =
6784 wlc_calc_cts_time(wlc, rts_rspec[0],
6785 rts_preamble_type[0]);
6786 dur_fallback =
6787 wlc_calc_cts_time(wlc, rts_rspec[1],
6788 rts_preamble_type[1]);
6789 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6790 dur += ltoh16(rts->durid);
6791 dur_fallback += ltoh16(txh->RTSDurFallback);
6792 } else if (use_rifs) {
6793 dur = frag_dur;
6794 dur_fallback = 0;
6795 } else {
6796 /* frame + SIFS + ACK */
6797 dur = frag_dur;
6798 dur +=
6799 wlc_compute_frame_dur(wlc, rspec[0],
6800 preamble_type[0], 0);
6802 dur_fallback =
6803 wlc_calc_frame_time(wlc, rspec[1],
6804 preamble_type[1],
6805 phylen);
6806 dur_fallback +=
6807 wlc_compute_frame_dur(wlc, rspec[1],
6808 preamble_type[1], 0);
6810 /* NEED to set TxFesTimeNormal (hard) */
6811 txh->TxFesTimeNormal = htol16((uint16) dur);
6812 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6813 txh->TxFesTimeFallback = htol16((uint16) dur_fallback);
6815 /* update txop byte threshold (txop minus intraframe overhead) */
6816 if (wlc->edcf_txop[ac] >= (dur - frag_dur)) {
6818 uint newfragthresh;
6820 newfragthresh =
6821 wlc_calc_frame_len(wlc, rspec[0],
6822 preamble_type[0],
6823 (wlc->
6824 edcf_txop[ac] -
6825 (dur -
6826 frag_dur)));
6827 /* range bound the fragthreshold */
6828 if (newfragthresh < DOT11_MIN_FRAG_LEN)
6829 newfragthresh =
6830 DOT11_MIN_FRAG_LEN;
6831 else if (newfragthresh >
6832 wlc->usr_fragthresh)
6833 newfragthresh =
6834 wlc->usr_fragthresh;
6835 /* update the fragthresh and do txc update */
6836 if (wlc->fragthresh[queue] !=
6837 (uint16) newfragthresh) {
6838 wlc->fragthresh[queue] =
6839 (uint16) newfragthresh;
6842 } else
6843 WL_ERROR(("wl%d: %s txop invalid for rate %d\n",
6844 wlc->pub->unit, fifo_names[queue],
6845 RSPEC2RATE(rspec[0])));
6847 if (dur > wlc->edcf_txop[ac])
6848 WL_ERROR(("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n", wlc->pub->unit, __func__, fifo_names[queue], phylen, wlc->fragthresh[queue], dur, wlc->edcf_txop[ac]));
6852 return 0;
6855 void wlc_tbtt(wlc_info_t *wlc, d11regs_t *regs)
6857 wlc_bsscfg_t *cfg = wlc->cfg;
6859 WLCNTINCR(wlc->pub->_cnt->tbtt);
6861 if (BSSCFG_STA(cfg)) {
6862 /* run watchdog here if the watchdog timer is not armed */
6863 if (WLC_WATCHDOG_TBTT(wlc)) {
6864 uint32 cur, delta;
6865 if (wlc->WDarmed) {
6866 wl_del_timer(wlc->wl, wlc->wdtimer);
6867 wlc->WDarmed = FALSE;
6870 cur = OSL_SYSUPTIME();
6871 delta = cur > wlc->WDlast ? cur - wlc->WDlast :
6872 (uint32) ~0 - wlc->WDlast + cur + 1;
6873 if (delta >= TIMER_INTERVAL_WATCHDOG) {
6874 wlc_watchdog((void *)wlc);
6875 wlc->WDlast = cur;
6878 wl_add_timer(wlc->wl, wlc->wdtimer,
6879 wlc_watchdog_backup_bi(wlc), TRUE);
6880 wlc->WDarmed = TRUE;
6884 if (!cfg->BSS) {
6885 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6886 wlc->qvalid |= MCMD_DIRFRMQVAL;
6890 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6891 void wlc_hwtimer_gptimer_set(wlc_info_t *wlc, uint us)
6893 ASSERT(wlc->pub->corerev >= 3); /* no gptimer in earlier revs */
6894 W_REG(wlc->osh, &wlc->regs->gptimer, us);
6897 void wlc_hwtimer_gptimer_abort(wlc_info_t *wlc)
6899 ASSERT(wlc->pub->corerev >= 3);
6900 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6903 static void wlc_hwtimer_gptimer_cb(wlc_info_t *wlc)
6905 /* when interrupt is generated, the counter is loaded with last value
6906 * written and continue to decrement. So it has to be cleaned first
6908 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6912 * This fn has all the high level dpc processing from wlc_dpc.
6913 * POLICY: no macinstatus change, no bounding loop.
6914 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6916 void wlc_high_dpc(wlc_info_t *wlc, uint32 macintstatus)
6918 d11regs_t *regs = wlc->regs;
6919 #ifdef BCMDBG
6920 char flagstr[128];
6921 static const bcm_bit_desc_t int_flags[] = {
6922 {MI_MACSSPNDD, "MACSSPNDD"},
6923 {MI_BCNTPL, "BCNTPL"},
6924 {MI_TBTT, "TBTT"},
6925 {MI_BCNSUCCESS, "BCNSUCCESS"},
6926 {MI_BCNCANCLD, "BCNCANCLD"},
6927 {MI_ATIMWINEND, "ATIMWINEND"},
6928 {MI_PMQ, "PMQ"},
6929 {MI_NSPECGEN_0, "NSPECGEN_0"},
6930 {MI_NSPECGEN_1, "NSPECGEN_1"},
6931 {MI_MACTXERR, "MACTXERR"},
6932 {MI_NSPECGEN_3, "NSPECGEN_3"},
6933 {MI_PHYTXERR, "PHYTXERR"},
6934 {MI_PME, "PME"},
6935 {MI_GP0, "GP0"},
6936 {MI_GP1, "GP1"},
6937 {MI_DMAINT, "DMAINT"},
6938 {MI_TXSTOP, "TXSTOP"},
6939 {MI_CCA, "CCA"},
6940 {MI_BG_NOISE, "BG_NOISE"},
6941 {MI_DTIM_TBTT, "DTIM_TBTT"},
6942 {MI_PRQ, "PRQ"},
6943 {MI_PWRUP, "PWRUP"},
6944 {MI_RFDISABLE, "RFDISABLE"},
6945 {MI_TFS, "TFS"},
6946 {MI_PHYCHANGED, "PHYCHANGED"},
6947 {MI_TO, "TO"},
6948 {0, NULL}
6951 if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) {
6952 bcm_format_flags(int_flags, macintstatus, flagstr,
6953 sizeof(flagstr));
6954 WL_TRACE(("wl%d: macintstatus 0x%x %s\n", wlc->pub->unit,
6955 macintstatus, flagstr));
6957 #endif /* BCMDBG */
6959 if (macintstatus & MI_PRQ) {
6960 /* Process probe request FIFO */
6961 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6964 /* TBTT indication */
6965 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6966 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
6967 wlc_tbtt(wlc, regs);
6969 if (macintstatus & MI_GP0) {
6970 WL_ERROR(("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n", wlc->pub->unit, wlc->pub->now));
6972 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6973 __func__, CHIPID(wlc->pub->sih->chip),
6974 CHIPREV(wlc->pub->sih->chiprev));
6976 WLCNTINCR(wlc->pub->_cnt->psmwds);
6978 /* big hammer */
6979 wl_init(wlc->wl);
6982 /* gptimer timeout */
6983 if (macintstatus & MI_TO) {
6984 wlc_hwtimer_gptimer_cb(wlc);
6987 if (macintstatus & MI_RFDISABLE) {
6988 WL_ERROR(("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n", wlc->pub->unit, R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD));
6989 /* delay the cleanup to wl_down in IBSS case */
6990 if ((R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD)) {
6991 int idx;
6992 wlc_bsscfg_t *bsscfg;
6993 FOREACH_BSS(wlc, idx, bsscfg) {
6994 if (!BSSCFG_STA(bsscfg) || !bsscfg->enable
6995 || !bsscfg->BSS)
6996 continue;
6997 WL_ERROR(("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n", wlc->pub->unit));
7002 /* send any enq'd tx packets. Just makes sure to jump start tx */
7003 if (!pktq_empty(&wlc->active_queue->q))
7004 wlc_send_q(wlc, wlc->active_queue);
7006 #ifndef WLC_HIGH_ONLY
7007 ASSERT(wlc_ps_check(wlc));
7008 #endif
7011 static void *wlc_15420war(wlc_info_t *wlc, uint queue)
7013 hnddma_t *di;
7014 void *p;
7016 ASSERT(queue < NFIFO);
7018 if ((D11REV_IS(wlc->pub->corerev, 4))
7019 || (D11REV_GT(wlc->pub->corerev, 6)))
7020 return NULL;
7022 di = wlc->hw->di[queue];
7023 ASSERT(di != NULL);
7025 /* get next packet, ignoring XmtStatus.Curr */
7026 p = dma_getnexttxp(di, HNDDMA_RANGE_ALL);
7028 /* sw block tx dma */
7029 dma_txblock(di);
7031 /* if tx ring is now empty, reset and re-init the tx dma channel */
7032 if (dma_txactive(wlc->hw->di[queue]) == 0) {
7033 WLCNTINCR(wlc->pub->_cnt->txdmawar);
7034 if (!dma_txreset(di))
7035 WL_ERROR(("wl%d: %s: dma_txreset[%d]: cannot stop dma\n", wlc->pub->unit, __func__, queue));
7036 dma_txinit(di);
7038 return p;
7041 static void wlc_war16165(wlc_info_t *wlc, bool tx)
7043 if (tx) {
7044 /* the post-increment is used in STAY_AWAKE macro */
7045 if (wlc->txpend16165war++ == 0)
7046 wlc_set_ps_ctrl(wlc);
7047 } else {
7048 wlc->txpend16165war--;
7049 if (wlc->txpend16165war == 0)
7050 wlc_set_ps_ctrl(wlc);
7054 /* process an individual tx_status_t */
7055 /* WLC_HIGH_API */
7056 bool BCMFASTPATH
7057 wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, uint32 frm_tx2)
7059 void *p;
7060 uint queue;
7061 d11txh_t *txh;
7062 struct scb *scb = NULL;
7063 bool free_pdu;
7064 osl_t *osh;
7065 int tx_rts, tx_frame_count, tx_rts_count;
7066 uint totlen, supr_status;
7067 bool lastframe;
7068 struct dot11_header *h;
7069 uint16 fc;
7070 uint16 mcl;
7071 struct ieee80211_tx_info *tx_info;
7072 struct ieee80211_tx_rate *txrate;
7073 int i;
7075 (void)(frm_tx2); /* Compiler reference to avoid unused variable warning */
7077 /* discard intermediate indications for ucode with one legitimate case:
7078 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
7079 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
7080 * transmission count)
7082 if (!(txs->status & TX_STATUS_AMPDU)
7083 && (txs->status & TX_STATUS_INTERMEDIATE)) {
7084 WLCNTADD(wlc->pub->_cnt->txnoack,
7085 ((txs->
7086 status & TX_STATUS_FRM_RTX_MASK) >>
7087 TX_STATUS_FRM_RTX_SHIFT));
7088 WL_ERROR(("%s: INTERMEDIATE but not AMPDU\n", __func__));
7089 return FALSE;
7092 osh = wlc->osh;
7093 queue = txs->frameid & TXFID_QUEUE_MASK;
7094 ASSERT(queue < NFIFO);
7095 if (queue >= NFIFO) {
7096 p = NULL;
7097 goto fatal;
7100 p = GETNEXTTXP(wlc, queue);
7101 if (WLC_WAR16165(wlc))
7102 wlc_war16165(wlc, FALSE);
7103 if (p == NULL)
7104 p = wlc_15420war(wlc, queue);
7105 ASSERT(p != NULL);
7106 if (p == NULL)
7107 goto fatal;
7109 txh = (d11txh_t *) PKTDATA(p);
7110 mcl = ltoh16(txh->MacTxControlLow);
7112 if (txs->phyerr) {
7113 WL_ERROR(("phyerr 0x%x, rate 0x%x\n", txs->phyerr,
7114 txh->MainRates));
7115 wlc_print_txdesc(txh);
7116 wlc_print_txstatus(txs);
7119 ASSERT(txs->frameid == htol16(txh->TxFrameID));
7120 if (txs->frameid != htol16(txh->TxFrameID))
7121 goto fatal;
7123 tx_info = IEEE80211_SKB_CB(p);
7124 h = (struct dot11_header *)((uint8 *) (txh + 1) + D11_PHY_HDR_LEN);
7125 fc = ltoh16(h->fc);
7127 scb = (struct scb *)tx_info->control.sta->drv_priv;
7129 if (N_ENAB(wlc->pub)) {
7130 uint8 *plcp = (uint8 *) (txh + 1);
7131 if (PLCP3_ISSGI(plcp[3]))
7132 WLCNTINCR(wlc->pub->_cnt->txmpdu_sgi);
7133 if (PLCP3_ISSTBC(plcp[3]))
7134 WLCNTINCR(wlc->pub->_cnt->txmpdu_stbc);
7137 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
7138 ASSERT((mcl & TXC_AMPDU_MASK) != TXC_AMPDU_NONE);
7139 wlc_ampdu_dotxstatus(wlc->ampdu, scb, p, txs);
7140 return FALSE;
7143 supr_status = txs->status & TX_STATUS_SUPR_MASK;
7144 if (supr_status == TX_STATUS_SUPR_BADCH)
7145 WL_NONE(("%s: Pkt tx suppressed, possibly channel %d\n",
7146 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec)));
7148 tx_rts = htol16(txh->MacTxControlLow) & TXC_SENDRTS;
7149 tx_frame_count =
7150 (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT;
7151 tx_rts_count =
7152 (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT;
7154 lastframe = (fc & FC_MOREFRAG) == 0;
7156 if (!lastframe) {
7157 WL_ERROR(("Not last frame!\n"));
7158 } else {
7159 uint16 sfbl, lfbl;
7160 ieee80211_tx_info_clear_status(tx_info);
7161 if (queue < AC_COUNT) {
7162 sfbl = WLC_WME_RETRY_SFB_GET(wlc, wme_fifo2ac[queue]);
7163 lfbl = WLC_WME_RETRY_LFB_GET(wlc, wme_fifo2ac[queue]);
7164 } else {
7165 sfbl = wlc->SFBL;
7166 lfbl = wlc->LFBL;
7169 txrate = tx_info->status.rates;
7170 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
7171 if ((tx_frame_count > sfbl) && (txrate[1].idx >= 0)) {
7172 /* rate selection requested a fallback rate and we used it */
7173 txrate->count = lfbl;
7174 txrate[1].count = tx_frame_count - lfbl;
7175 } else {
7176 /* rate selection did not request fallback rate, or we didn't need it */
7177 txrate->count = tx_frame_count;
7178 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
7179 txrate[1].idx = -1;
7180 txrate[1].count = 0;
7183 /* clear the rest of the rates */
7184 for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
7185 txrate[i].idx = -1;
7186 txrate[i].count = 0;
7189 if (txs->status & TX_STATUS_ACK_RCV)
7190 tx_info->flags |= IEEE80211_TX_STAT_ACK;
7193 totlen = pkttotlen(osh, p);
7194 free_pdu = TRUE;
7196 wlc_txfifo_complete(wlc, queue, 1);
7198 if (lastframe) {
7199 PKTSETNEXT(p, NULL);
7200 PKTSETLINK(p, NULL);
7201 wlc->txretried = 0;
7202 /* remove PLCP & Broadcom tx descriptor header */
7203 PKTPULL(p, D11_PHY_HDR_LEN);
7204 PKTPULL(p, D11_TXH_LEN);
7205 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
7206 WLCNTINCR(wlc->pub->_cnt->ieee_tx_status);
7207 } else {
7208 WL_ERROR(("%s: Not last frame => not calling tx_status\n",
7209 __func__));
7212 return FALSE;
7214 fatal:
7215 ASSERT(0);
7216 if (p)
7217 PKTFREE(osh, p, TRUE);
7219 #ifdef WLC_HIGH_ONLY
7220 /* If this is a split driver, do the big-hammer here.
7221 * If this is a monolithic driver, wlc_bmac.c:wlc_dpc() will do the big-hammer.
7223 wl_init(wlc->wl);
7224 #endif
7225 return TRUE;
7229 void BCMFASTPATH
7230 wlc_txfifo_complete(wlc_info_t *wlc, uint fifo, int8 txpktpend)
7232 TXPKTPENDDEC(wlc, fifo, txpktpend);
7233 WL_TRACE(("wlc_txfifo_complete, pktpend dec %d to %d\n", txpktpend,
7234 TXPKTPENDGET(wlc, fifo)));
7236 /* There is more room; mark precedences related to this FIFO sendable */
7237 WLC_TX_FIFO_ENAB(wlc, fifo);
7238 ASSERT(TXPKTPENDGET(wlc, fifo) >= 0);
7240 if (!TXPKTPENDTOT(wlc)) {
7241 if (wlc->block_datafifo & DATA_BLOCK_TX_SUPR)
7242 wlc_bsscfg_tx_check(wlc);
7245 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
7246 if (AP_ENAB(wlc->pub) &&
7247 wlc->bcmcfifo_drain && !TXPKTPENDGET(wlc, TX_BCMC_FIFO)) {
7248 wlc->bcmcfifo_drain = FALSE;
7249 wlc_mhf(wlc, MHF2, MHF2_TXBCMC_NOW, 0, WLC_BAND_AUTO);
7252 /* figure out which bsscfg is being worked on... */
7255 /* Given the beacon interval in kus, and a 64 bit TSF in us,
7256 * return the offset (in us) of the TSF from the last TBTT
7258 uint32 wlc_calc_tbtt_offset(uint32 bp, uint32 tsf_h, uint32 tsf_l)
7260 uint32 k, btklo, btkhi, offset;
7262 /* TBTT is always an even multiple of the beacon_interval,
7263 * so the TBTT less than or equal to the beacon timestamp is
7264 * the beacon timestamp minus the beacon timestamp modulo
7265 * the beacon interval.
7267 * TBTT = BT - (BT % BIu)
7268 * = (BTk - (BTk % BP)) * 2^10
7270 * BT = beacon timestamp (usec, 64bits)
7271 * BTk = beacon timestamp (Kusec, 54bits)
7272 * BP = beacon interval (Kusec, 16bits)
7273 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
7275 * To keep the calculations in uint32s, the modulo operation
7276 * on the high part of BT needs to be done in parts using the
7277 * relations:
7278 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
7279 * and
7280 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
7282 * So, if BTk[n] = uint16 n [0,3] of BTk.
7283 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
7284 * and the SUM term can be broken down:
7285 * (BTk[n] * 2^16n) % BP
7286 * (BTk[n] * (2^16n % BP)) % BP
7288 * Create a set of power of 2 mod BP constants:
7289 * K[n] = 2^(16n) % BP
7290 * = (K[n-1] * 2^16) % BP
7291 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
7293 * BTk % BP = BTk[0-1] % BP +
7294 * (BTk[2] * K[2]) % BP +
7295 * (BTk[3] * K[3]) % BP
7297 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
7300 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
7301 btklo = (tsf_h << 22) | (tsf_l >> 10);
7302 btkhi = tsf_h >> 10;
7304 /* offset = BTk % BP */
7305 offset = btklo % bp;
7307 /* K[2] = ((2^16 % BP) * 2^16) % BP */
7308 k = (uint32) (1 << 16) % bp;
7309 k = (uint32) (k * 1 << 16) % (uint32) bp;
7311 /* offset += (BTk[2] * K[2]) % BP */
7312 offset += ((btkhi & 0xffff) * k) % bp;
7314 /* BTk[3] */
7315 btkhi = btkhi >> 16;
7317 /* k[3] = (K[2] * 2^16) % BP */
7318 k = (k << 16) % bp;
7320 /* offset += (BTk[3] * K[3]) % BP */
7321 offset += ((btkhi & 0xffff) * k) % bp;
7323 offset = offset % bp;
7325 /* convert offset from kus to us by shifting up 10 bits and
7326 * add in the low 10 bits of tsf that we ignored
7328 offset = (offset << 10) + (tsf_l & 0x3FF);
7330 return offset;
7333 /* Update beacon listen interval in shared memory */
7334 void wlc_bcn_li_upd(wlc_info_t *wlc)
7336 if (AP_ENAB(wlc->pub))
7337 return;
7339 /* wake up every DTIM is the default */
7340 if (wlc->bcn_li_dtim == 1)
7341 wlc_write_shm(wlc, M_BCN_LI, 0);
7342 else
7343 wlc_write_shm(wlc, M_BCN_LI,
7344 (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn);
7347 static void
7348 prep_mac80211_status(wlc_info_t *wlc, d11rxhdr_t *rxh, void *p,
7349 struct ieee80211_rx_status *rx_status)
7351 uint32 tsf_l, tsf_h;
7352 wlc_d11rxhdr_t *wlc_rxh = (wlc_d11rxhdr_t *) rxh;
7353 int preamble;
7354 int channel;
7355 ratespec_t rspec;
7356 uchar *plcp;
7358 wlc_read_tsf(wlc, &tsf_l, &tsf_h); /* mactime */
7359 rx_status->mactime = tsf_h;
7360 rx_status->mactime <<= 32;
7361 rx_status->mactime |= tsf_l;
7362 rx_status->flag |= RX_FLAG_TSFT;
7364 channel = WLC_CHAN_CHANNEL(rxh->RxChan);
7366 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
7367 if (channel > 14) {
7368 rx_status->band = IEEE80211_BAND_5GHZ;
7369 rx_status->freq = wf_channel2mhz(channel, WF_CHAN_FACTOR_5_G);
7370 } else {
7371 rx_status->band = IEEE80211_BAND_2GHZ;
7372 rx_status->freq = wf_channel2mhz(channel, WF_CHAN_FACTOR_2_4_G);
7375 rx_status->signal = wlc_rxh->rssi; /* signal */
7377 /* noise */
7378 /* qual */
7379 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */
7381 plcp = PKTDATA(p);
7383 rspec = wlc_compute_rspec(rxh, plcp);
7384 if (IS_MCS(rspec)) {
7385 rx_status->rate_idx = rspec & RSPEC_RATE_MASK;
7386 rx_status->flag |= RX_FLAG_HT;
7387 if (RSPEC_IS40MHZ(rspec))
7388 rx_status->flag |= RX_FLAG_40MHZ;
7389 } else {
7390 switch (RSPEC2RATE(rspec)) {
7391 case WLC_RATE_1M:
7392 rx_status->rate_idx = 0;
7393 break;
7394 case WLC_RATE_2M:
7395 rx_status->rate_idx = 1;
7396 break;
7397 case WLC_RATE_5M5:
7398 rx_status->rate_idx = 2;
7399 break;
7400 case WLC_RATE_11M:
7401 rx_status->rate_idx = 3;
7402 break;
7403 case WLC_RATE_6M:
7404 rx_status->rate_idx = 4;
7405 break;
7406 case WLC_RATE_9M:
7407 rx_status->rate_idx = 5;
7408 break;
7409 case WLC_RATE_12M:
7410 rx_status->rate_idx = 6;
7411 break;
7412 case WLC_RATE_18M:
7413 rx_status->rate_idx = 7;
7414 break;
7415 case WLC_RATE_24M:
7416 rx_status->rate_idx = 8;
7417 break;
7418 case WLC_RATE_36M:
7419 rx_status->rate_idx = 9;
7420 break;
7421 case WLC_RATE_48M:
7422 rx_status->rate_idx = 10;
7423 break;
7424 case WLC_RATE_54M:
7425 rx_status->rate_idx = 11;
7426 break;
7427 default:
7428 WL_ERROR(("%s: Unknown rate\n", __func__));
7431 /* Determine short preamble and rate_idx */
7432 preamble = 0;
7433 if (IS_CCK(rspec)) {
7434 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
7435 WL_ERROR(("Short CCK\n"));
7436 rx_status->flag |= RX_FLAG_SHORTPRE;
7437 } else if (IS_OFDM(rspec)) {
7438 rx_status->flag |= RX_FLAG_SHORTPRE;
7439 } else {
7440 WL_ERROR(("%s: Unknown modulation\n", __func__));
7444 if (PLCP3_ISSGI(plcp[3]))
7445 rx_status->flag |= RX_FLAG_SHORT_GI;
7447 if (rxh->RxStatus1 & RXS_DECERR) {
7448 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC;
7449 WL_ERROR(("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__));
7451 if (rxh->RxStatus1 & RXS_FCSERR) {
7452 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
7453 WL_ERROR(("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__));
7457 char *print_fk(uint16 fk)
7459 char *str;
7460 switch (fk) {
7461 case FC_ASSOC_REQ:
7462 str = "FC_ASSOC_REQ";
7463 break;
7464 case FC_ASSOC_RESP:
7465 str = "FC_ASSOC_RESP";
7466 break;
7467 case FC_REASSOC_REQ:
7468 str = "FC_REASSOC_REQ";
7469 break;
7470 case FC_REASSOC_RESP:
7471 str = "FC_REASSOC_RESP";
7472 break;
7473 case FC_PROBE_REQ:
7474 str = "FC_PROBE_REQ";
7475 break;
7476 case FC_PROBE_RESP:
7477 str = "FC_PROBE_RESP";
7478 break;
7479 case FC_BEACON:
7480 str = "FC_BEACON";
7481 break;
7482 case FC_DISASSOC:
7483 str = "FC_DISASSOC";
7484 break;
7485 case FC_AUTH:
7486 str = "FC_AUTH";
7487 break;
7488 case FC_DEAUTH:
7489 str = "FC_DEAUTH";
7490 break;
7491 case FC_ACTION:
7492 str = "FC_ACTION";
7493 break;
7494 case FC_ACTION_NOACK:
7495 str = "FC_ACTION_NOACK";
7496 break;
7497 case FC_CTL_WRAPPER:
7498 str = "FC_CTL_WRAPPER";
7499 break;
7500 case FC_BLOCKACK_REQ:
7501 str = "FC_BLOCKACK_REQ";
7502 break;
7503 case FC_BLOCKACK:
7504 str = "FC_BLOCKACK";
7505 break;
7506 case FC_PS_POLL:
7507 str = "FC_PS_POLL";
7508 break;
7509 case FC_RTS:
7510 str = "FC_RTS";
7511 break;
7512 case FC_CTS:
7513 str = "FC_CTS";
7514 break;
7515 case FC_ACK:
7516 str = "FC_ACK";
7517 break;
7518 case FC_CF_END:
7519 str = "FC_CF_END";
7520 break;
7521 case FC_CF_END_ACK:
7522 str = "FC_CF_END_ACK";
7523 break;
7524 case FC_DATA:
7525 str = "FC_DATA";
7526 break;
7527 case FC_NULL_DATA:
7528 str = "FC_NULL_DATA";
7529 break;
7530 case FC_DATA_CF_ACK:
7531 str = "FC_DATA_CF_ACK";
7532 break;
7533 case FC_QOS_DATA:
7534 str = "FC_QOS_DATA";
7535 break;
7536 case FC_QOS_NULL:
7537 str = "FC_QOS_NULL";
7538 break;
7539 default:
7540 str = "Unknown!!";
7541 break;
7543 return str;
7546 static void
7547 wlc_recvctl(wlc_info_t *wlc, osl_t *osh, d11rxhdr_t *rxh, void *p)
7549 int len_mpdu;
7550 struct ieee80211_rx_status rx_status;
7551 #if defined(BCMDBG)
7552 struct sk_buff *skb = p;
7553 #endif /* BCMDBG */
7554 /* Todo:
7555 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
7556 * Test for INTERMEDIATE like so:
7557 * if (!(plcp[0] | plcp[1] | plcp[2]))
7560 memset(&rx_status, 0, sizeof(rx_status));
7561 prep_mac80211_status(wlc, rxh, p, &rx_status);
7563 /* mac header+body length, exclude CRC and plcp header */
7564 len_mpdu = PKTLEN(p) - D11_PHY_HDR_LEN - DOT11_FCS_LEN;
7565 PKTPULL(p, D11_PHY_HDR_LEN);
7566 PKTSETLEN(p, len_mpdu);
7568 ASSERT(!PKTNEXT(p));
7569 ASSERT(!PKTLINK(p));
7571 ASSERT(ISALIGNED((uintptr) skb->data, 2));
7573 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status));
7574 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
7576 WLCNTINCR(wlc->pub->_cnt->ieee_rx);
7577 PKTUNALLOC(osh);
7578 return;
7581 void wlc_bss_list_free(wlc_info_t *wlc, wlc_bss_list_t *bss_list)
7583 uint index;
7584 wlc_bss_info_t *bi;
7586 if (!bss_list) {
7587 WL_ERROR(("%s: Attempting to free NULL list\n", __func__));
7588 return;
7590 /* inspect all BSS descriptor */
7591 for (index = 0; index < bss_list->count; index++) {
7592 bi = bss_list->ptrs[index];
7593 if (bi) {
7594 if (bi->bcn_prb) {
7595 osl_mfree(wlc->osh, bi->bcn_prb,
7596 bi->bcn_prb_len);
7598 osl_mfree(wlc->osh, bi, sizeof(wlc_bss_info_t));
7599 bss_list->ptrs[index] = NULL;
7602 bss_list->count = 0;
7605 /* Process received frames */
7607 * Return TRUE if more frames need to be processed. FALSE otherwise.
7608 * Param 'bound' indicates max. # frames to process before break out.
7610 /* WLC_HIGH_API */
7611 void BCMFASTPATH wlc_recv(wlc_info_t *wlc, void *p)
7613 d11rxhdr_t *rxh;
7614 struct dot11_header *h;
7615 osl_t *osh;
7616 uint16 fc;
7617 uint len;
7618 bool is_amsdu;
7619 #ifdef BCMDBG
7620 char eabuf[ETHER_ADDR_STR_LEN];
7621 #endif
7623 WL_TRACE(("wl%d: wlc_recv\n", wlc->pub->unit));
7625 osh = wlc->osh;
7627 /* frame starts with rxhdr */
7628 rxh = (d11rxhdr_t *) PKTDATA(p);
7630 /* strip off rxhdr */
7631 PKTPULL(p, wlc->hwrxoff);
7633 /* fixup rx header endianness */
7634 ltoh16_buf((void *)rxh, sizeof(d11rxhdr_t));
7636 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7637 if (rxh->RxStatus1 & RXS_PBPRES) {
7638 if (PKTLEN(p) < 2) {
7639 WLCNTINCR(wlc->pub->_cnt->rxrunt);
7640 WL_ERROR(("wl%d: wlc_recv: rcvd runt of len %d\n",
7641 wlc->pub->unit, PKTLEN(p)));
7642 goto toss;
7644 PKTPULL(p, 2);
7647 h = (struct dot11_header *)(PKTDATA(p) + D11_PHY_HDR_LEN);
7648 len = PKTLEN(p);
7650 if (rxh->RxStatus1 & RXS_FCSERR) {
7651 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) {
7652 WL_ERROR(("FCSERR while scanning******* - tossing\n"));
7653 goto toss;
7654 } else {
7655 WL_ERROR(("RCSERR!!!\n"));
7656 goto toss;
7660 /* check received pkt has at least frame control field */
7661 if (len >= D11_PHY_HDR_LEN + sizeof(h->fc)) {
7662 fc = ltoh16(h->fc);
7663 } else {
7664 WLCNTINCR(wlc->pub->_cnt->rxrunt);
7665 goto toss;
7668 is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK;
7670 /* explicitly test bad src address to avoid sending bad deauth */
7671 if (!is_amsdu) {
7672 /* CTS and ACK CTL frames are w/o a2 */
7673 if (FC_TYPE(fc) == FC_TYPE_DATA || FC_TYPE(fc) == FC_TYPE_MNG) {
7674 if ((ETHER_ISNULLADDR(&h->a2) || ETHER_ISMULTI(&h->a2))) {
7675 WL_ERROR(("wl%d: %s: dropping a frame with invalid" " src mac address, a2: %s\n", wlc->pub->unit, __func__, bcm_ether_ntoa(&h->a2, eabuf)));
7676 WLCNTINCR(wlc->pub->_cnt->rxbadsrcmac);
7677 goto toss;
7679 WLCNTINCR(wlc->pub->_cnt->rxfrag);
7683 /* due to sheer numbers, toss out probe reqs for now */
7684 if (FC_TYPE(fc) == FC_TYPE_MNG) {
7685 if ((fc & FC_KIND_MASK) == FC_PROBE_REQ)
7686 goto toss;
7689 if (is_amsdu) {
7690 WL_ERROR(("%s: is_amsdu causing toss\n", __func__));
7691 goto toss;
7694 wlc_recvctl(wlc, osh, rxh, p);
7695 return;
7697 toss:
7698 PKTFREE(osh, p, FALSE);
7701 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7702 * number of bytes goes in the length field
7704 * Formula given by HT PHY Spec v 1.13
7705 * len = 3(nsyms + nstream + 3) - 3
7707 uint16 BCMFASTPATH
7708 wlc_calc_lsig_len(wlc_info_t *wlc, ratespec_t ratespec, uint mac_len)
7710 uint nsyms, len = 0, kNdps;
7712 WL_TRACE(("wl%d: wlc_calc_lsig_len: rate %d, len%d\n", wlc->pub->unit,
7713 RSPEC2RATE(ratespec), mac_len));
7715 if (IS_MCS(ratespec)) {
7716 uint mcs = ratespec & RSPEC_RATE_MASK;
7717 /* MCS_TXS(mcs) returns num tx streams - 1 */
7718 int tot_streams = (MCS_TXS(mcs) + 1) + RSPEC_STC(ratespec);
7720 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7721 /* the payload duration calculation matches that of regular ofdm */
7722 /* 1000Ndbps = kbps * 4 */
7723 kNdps =
7724 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7725 RSPEC_ISSGI(ratespec)) * 4;
7727 if (RSPEC_STC(ratespec) == 0)
7728 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7729 nsyms =
7730 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7731 APHY_TAIL_NBITS) * 1000, kNdps);
7732 else
7733 /* STBC needs to have even number of symbols */
7734 nsyms =
7736 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7737 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7739 nsyms += (tot_streams + 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7740 /* 3 bytes/symbol @ legacy 6Mbps rate */
7741 len = (3 * nsyms) - 3; /* (-3) excluding service bits and tail bits */
7744 return (uint16) len;
7747 /* calculate frame duration of a given rate and length, return time in usec unit */
7748 uint BCMFASTPATH
7749 wlc_calc_frame_time(wlc_info_t *wlc, ratespec_t ratespec, uint8 preamble_type,
7750 uint mac_len)
7752 uint nsyms, dur = 0, Ndps, kNdps;
7753 uint rate = RSPEC2RATE(ratespec);
7755 if (rate == 0) {
7756 ASSERT(0);
7757 WL_ERROR(("wl%d: WAR: using rate of 1 mbps\n", wlc->pub->unit));
7758 rate = WLC_RATE_1M;
7761 WL_TRACE(("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n", wlc->pub->unit, ratespec, preamble_type, mac_len));
7763 if (IS_MCS(ratespec)) {
7764 uint mcs = ratespec & RSPEC_RATE_MASK;
7765 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7766 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7767 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type));
7769 dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7770 if (preamble_type == WLC_MM_PREAMBLE)
7771 dur += PREN_MM_EXT;
7772 /* 1000Ndbps = kbps * 4 */
7773 kNdps =
7774 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7775 RSPEC_ISSGI(ratespec)) * 4;
7777 if (RSPEC_STC(ratespec) == 0)
7778 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7779 nsyms =
7780 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7781 APHY_TAIL_NBITS) * 1000, kNdps);
7782 else
7783 /* STBC needs to have even number of symbols */
7784 nsyms =
7786 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7787 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7789 dur += APHY_SYMBOL_TIME * nsyms;
7790 if (BAND_2G(wlc->band->bandtype))
7791 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7792 } else if (IS_OFDM(rate)) {
7793 dur = APHY_PREAMBLE_TIME;
7794 dur += APHY_SIGNAL_TIME;
7795 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7796 Ndps = rate * 2;
7797 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7798 nsyms =
7799 CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS),
7800 Ndps);
7801 dur += APHY_SYMBOL_TIME * nsyms;
7802 if (BAND_2G(wlc->band->bandtype))
7803 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7804 } else {
7805 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7806 mac_len = mac_len * 8 * 2;
7807 /* calc ceiling of bits/rate = microseconds of air time */
7808 dur = (mac_len + rate - 1) / rate;
7809 if (preamble_type & WLC_SHORT_PREAMBLE)
7810 dur += BPHY_PLCP_SHORT_TIME;
7811 else
7812 dur += BPHY_PLCP_TIME;
7814 return dur;
7817 /* The opposite of wlc_calc_frame_time */
7818 static uint
7819 wlc_calc_frame_len(wlc_info_t *wlc, ratespec_t ratespec, uint8 preamble_type,
7820 uint dur)
7822 uint nsyms, mac_len, Ndps, kNdps;
7823 uint rate = RSPEC2RATE(ratespec);
7825 WL_TRACE(("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n", wlc->pub->unit, ratespec, preamble_type, dur));
7827 if (IS_MCS(ratespec)) {
7828 uint mcs = ratespec & RSPEC_RATE_MASK;
7829 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7830 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7831 dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7832 /* payload calculation matches that of regular ofdm */
7833 if (BAND_2G(wlc->band->bandtype))
7834 dur -= DOT11_OFDM_SIGNAL_EXTENSION;
7835 /* kNdbps = kbps * 4 */
7836 kNdps =
7837 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7838 RSPEC_ISSGI(ratespec)) * 4;
7839 nsyms = dur / APHY_SYMBOL_TIME;
7840 mac_len =
7841 ((nsyms * kNdps) -
7842 ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000;
7843 } else if (IS_OFDM(ratespec)) {
7844 dur -= APHY_PREAMBLE_TIME;
7845 dur -= APHY_SIGNAL_TIME;
7846 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7847 Ndps = rate * 2;
7848 nsyms = dur / APHY_SYMBOL_TIME;
7849 mac_len =
7850 ((nsyms * Ndps) -
7851 (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8;
7852 } else {
7853 if (preamble_type & WLC_SHORT_PREAMBLE)
7854 dur -= BPHY_PLCP_SHORT_TIME;
7855 else
7856 dur -= BPHY_PLCP_TIME;
7857 mac_len = dur * rate;
7858 /* divide out factor of 2 in rate (1/2 mbps) */
7859 mac_len = mac_len / 8 / 2;
7861 return mac_len;
7864 static uint
7865 wlc_calc_ba_time(wlc_info_t *wlc, ratespec_t rspec, uint8 preamble_type)
7867 WL_TRACE(("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7868 wlc->pub->unit, rspec, preamble_type));
7869 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7870 * or equal to the rate of the immediately previous frame in the FES
7872 rspec = WLC_BASIC_RATE(wlc, rspec);
7873 ASSERT(VALID_RATE_DBG(wlc, rspec));
7875 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7876 return wlc_calc_frame_time(wlc, rspec, preamble_type,
7877 (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN +
7878 DOT11_FCS_LEN));
7881 static uint BCMFASTPATH
7882 wlc_calc_ack_time(wlc_info_t *wlc, ratespec_t rspec, uint8 preamble_type)
7884 uint dur = 0;
7886 WL_TRACE(("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7887 wlc->pub->unit, rspec, preamble_type));
7888 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7889 * or equal to the rate of the immediately previous frame in the FES
7891 rspec = WLC_BASIC_RATE(wlc, rspec);
7892 ASSERT(VALID_RATE_DBG(wlc, rspec));
7894 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7895 dur =
7896 wlc_calc_frame_time(wlc, rspec, preamble_type,
7897 (DOT11_ACK_LEN + DOT11_FCS_LEN));
7898 return dur;
7901 static uint
7902 wlc_calc_cts_time(wlc_info_t *wlc, ratespec_t rspec, uint8 preamble_type)
7904 WL_TRACE(("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7905 wlc->pub->unit, rspec, preamble_type));
7906 return wlc_calc_ack_time(wlc, rspec, preamble_type);
7909 /* derive wlc->band->basic_rate[] table from 'rateset' */
7910 void wlc_rate_lookup_init(wlc_info_t *wlc, wlc_rateset_t *rateset)
7912 uint8 rate;
7913 uint8 mandatory;
7914 uint8 cck_basic = 0;
7915 uint8 ofdm_basic = 0;
7916 uint8 *br = wlc->band->basic_rate;
7917 uint i;
7919 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7920 bzero(br, WLC_MAXRATE + 1);
7922 /* For each basic rate in the rates list, make an entry in the
7923 * best basic lookup.
7925 for (i = 0; i < rateset->count; i++) {
7926 /* only make an entry for a basic rate */
7927 if (!(rateset->rates[i] & WLC_RATE_FLAG))
7928 continue;
7930 /* mask off basic bit */
7931 rate = (rateset->rates[i] & RATE_MASK);
7933 if (rate > WLC_MAXRATE) {
7934 WL_ERROR(("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n", rateset->rates[i]));
7935 continue;
7938 br[rate] = rate;
7941 /* The rate lookup table now has non-zero entries for each
7942 * basic rate, equal to the basic rate: br[basicN] = basicN
7944 * To look up the best basic rate corresponding to any
7945 * particular rate, code can use the basic_rate table
7946 * like this
7948 * basic_rate = wlc->band->basic_rate[tx_rate]
7950 * Make sure there is a best basic rate entry for
7951 * every rate by walking up the table from low rates
7952 * to high, filling in holes in the lookup table
7955 for (i = 0; i < wlc->band->hw_rateset.count; i++) {
7956 rate = wlc->band->hw_rateset.rates[i];
7957 ASSERT(rate <= WLC_MAXRATE);
7959 if (br[rate] != 0) {
7960 /* This rate is a basic rate.
7961 * Keep track of the best basic rate so far by
7962 * modulation type.
7964 if (IS_OFDM(rate))
7965 ofdm_basic = rate;
7966 else
7967 cck_basic = rate;
7969 continue;
7972 /* This rate is not a basic rate so figure out the
7973 * best basic rate less than this rate and fill in
7974 * the hole in the table
7977 br[rate] = IS_OFDM(rate) ? ofdm_basic : cck_basic;
7979 if (br[rate] != 0)
7980 continue;
7982 if (IS_OFDM(rate)) {
7983 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7984 if (rate >= WLC_RATE_24M)
7985 mandatory = WLC_RATE_24M;
7986 else if (rate >= WLC_RATE_12M)
7987 mandatory = WLC_RATE_12M;
7988 else
7989 mandatory = WLC_RATE_6M;
7990 } else {
7991 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7992 mandatory = rate;
7995 br[rate] = mandatory;
7999 static void wlc_write_rate_shm(wlc_info_t *wlc, uint8 rate, uint8 basic_rate)
8001 uint8 phy_rate, index;
8002 uint8 basic_phy_rate, basic_index;
8003 uint16 dir_table, basic_table;
8004 uint16 basic_ptr;
8006 /* Shared memory address for the table we are reading */
8007 dir_table = IS_OFDM(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B;
8009 /* Shared memory address for the table we are writing */
8010 basic_table = IS_OFDM(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B;
8013 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
8014 * the index into the rate table.
8016 phy_rate = rate_info[rate] & RATE_MASK;
8017 basic_phy_rate = rate_info[basic_rate] & RATE_MASK;
8018 index = phy_rate & 0xf;
8019 basic_index = basic_phy_rate & 0xf;
8021 /* Find the SHM pointer to the ACK rate entry by looking in the
8022 * Direct-map Table
8024 basic_ptr = wlc_read_shm(wlc, (dir_table + basic_index * 2));
8026 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
8027 * to the correct basic rate for the given incoming rate
8029 wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr);
8032 static const wlc_rateset_t *wlc_rateset_get_hwrs(wlc_info_t *wlc)
8034 const wlc_rateset_t *rs_dflt;
8036 if (WLC_PHY_11N_CAP(wlc->band)) {
8037 if (BAND_5G(wlc->band->bandtype))
8038 rs_dflt = &ofdm_mimo_rates;
8039 else
8040 rs_dflt = &cck_ofdm_mimo_rates;
8041 } else if (wlc->band->gmode)
8042 rs_dflt = &cck_ofdm_rates;
8043 else
8044 rs_dflt = &cck_rates;
8046 return rs_dflt;
8049 void wlc_set_ratetable(wlc_info_t *wlc)
8051 const wlc_rateset_t *rs_dflt;
8052 wlc_rateset_t rs;
8053 uint8 rate, basic_rate;
8054 uint i;
8056 rs_dflt = wlc_rateset_get_hwrs(wlc);
8057 ASSERT(rs_dflt != NULL);
8059 wlc_rateset_copy(rs_dflt, &rs);
8060 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
8062 /* walk the phy rate table and update SHM basic rate lookup table */
8063 for (i = 0; i < rs.count; i++) {
8064 rate = rs.rates[i] & RATE_MASK;
8066 /* for a given rate WLC_BASIC_RATE returns the rate at
8067 * which a response ACK/CTS should be sent.
8069 basic_rate = WLC_BASIC_RATE(wlc, rate);
8070 if (basic_rate == 0) {
8071 /* This should only happen if we are using a
8072 * restricted rateset.
8074 basic_rate = rs.rates[0] & RATE_MASK;
8077 wlc_write_rate_shm(wlc, rate, basic_rate);
8082 * Return true if the specified rate is supported by the specified band.
8083 * WLC_BAND_AUTO indicates the current band.
8085 bool wlc_valid_rate(wlc_info_t *wlc, ratespec_t rspec, int band, bool verbose)
8087 wlc_rateset_t *hw_rateset;
8088 uint i;
8090 if ((band == WLC_BAND_AUTO) || (band == wlc->band->bandtype)) {
8091 hw_rateset = &wlc->band->hw_rateset;
8092 } else if (NBANDS(wlc) > 1) {
8093 hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset;
8094 } else {
8095 /* other band specified and we are a single band device */
8096 return FALSE;
8099 /* check if this is a mimo rate */
8100 if (IS_MCS(rspec)) {
8101 if (!VALID_MCS((rspec & RSPEC_RATE_MASK)))
8102 goto error;
8104 return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK));
8107 for (i = 0; i < hw_rateset->count; i++)
8108 if (hw_rateset->rates[i] == RSPEC2RATE(rspec))
8109 return TRUE;
8110 error:
8111 if (verbose) {
8112 WL_ERROR(("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n", wlc->pub->unit, rspec));
8115 return FALSE;
8118 static void wlc_update_mimo_band_bwcap(wlc_info_t *wlc, uint8 bwcap)
8120 uint i;
8121 wlcband_t *band;
8123 for (i = 0; i < NBANDS(wlc); i++) {
8124 if (IS_SINGLEBAND_5G(wlc->deviceid))
8125 i = BAND_5G_INDEX;
8126 band = wlc->bandstate[i];
8127 if (band->bandtype == WLC_BAND_5G) {
8128 if ((bwcap == WLC_N_BW_40ALL)
8129 || (bwcap == WLC_N_BW_20IN2G_40IN5G))
8130 band->mimo_cap_40 = TRUE;
8131 else
8132 band->mimo_cap_40 = FALSE;
8133 } else {
8134 ASSERT(band->bandtype == WLC_BAND_2G);
8135 if (bwcap == WLC_N_BW_40ALL)
8136 band->mimo_cap_40 = TRUE;
8137 else
8138 band->mimo_cap_40 = FALSE;
8142 wlc->mimo_band_bwcap = bwcap;
8145 void wlc_mod_prb_rsp_rate_table(wlc_info_t *wlc, uint frame_len)
8147 const wlc_rateset_t *rs_dflt;
8148 wlc_rateset_t rs;
8149 uint8 rate;
8150 uint16 entry_ptr;
8151 uint8 plcp[D11_PHY_HDR_LEN];
8152 uint16 dur, sifs;
8153 uint i;
8155 sifs = SIFS(wlc->band);
8157 rs_dflt = wlc_rateset_get_hwrs(wlc);
8158 ASSERT(rs_dflt != NULL);
8160 wlc_rateset_copy(rs_dflt, &rs);
8161 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
8163 /* walk the phy rate table and update MAC core SHM basic rate table entries */
8164 for (i = 0; i < rs.count; i++) {
8165 rate = rs.rates[i] & RATE_MASK;
8167 entry_ptr = wlc_rate_shm_offset(wlc, rate);
8169 /* Calculate the Probe Response PLCP for the given rate */
8170 wlc_compute_plcp(wlc, rate, frame_len, plcp);
8172 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
8173 dur =
8174 (uint16) wlc_calc_frame_time(wlc, rate, WLC_LONG_PREAMBLE,
8175 frame_len);
8176 dur += sifs;
8178 /* Update the SHM Rate Table entry Probe Response values */
8179 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS,
8180 (uint16) (plcp[0] + (plcp[1] << 8)));
8181 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS + 2,
8182 (uint16) (plcp[2] + (plcp[3] << 8)));
8183 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_DUR_POS, dur);
8187 uint16
8188 wlc_compute_bcntsfoff(wlc_info_t *wlc, ratespec_t rspec, bool short_preamble,
8189 bool phydelay)
8191 uint bcntsfoff = 0;
8193 if (IS_MCS(rspec)) {
8194 WL_ERROR(("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
8195 wlc->pub->unit, rspec));
8196 } else if (IS_OFDM(rspec)) {
8197 /* tx delay from MAC through phy to air (2.1 usec) +
8198 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
8199 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
8200 * bytes at beacon rate)
8202 bcntsfoff += phydelay ? D11A_PHY_TX_DELAY : 0;
8203 bcntsfoff += APHY_PREAMBLE_TIME + APHY_SIGNAL_TIME;
8204 bcntsfoff +=
8205 wlc_compute_airtime(wlc, rspec,
8206 APHY_SERVICE_NBITS / 8 +
8207 DOT11_MAC_HDR_LEN);
8208 } else {
8209 /* tx delay from MAC through phy to air (3.4 usec) +
8210 * phy header time (long preamble + PLCP == 192 usec) +
8211 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
8213 bcntsfoff += phydelay ? D11B_PHY_TX_DELAY : 0;
8214 bcntsfoff +=
8215 short_preamble ? D11B_PHY_SPREHDR_TIME :
8216 D11B_PHY_LPREHDR_TIME;
8217 bcntsfoff += wlc_compute_airtime(wlc, rspec, DOT11_MAC_HDR_LEN);
8219 return (uint16) (bcntsfoff);
8222 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
8224 * PLCP header is 6 bytes.
8225 * 802.11 A3 header is 24 bytes.
8226 * Max beacon frame body template length is 112 bytes.
8227 * Max probe resp frame body template length is 110 bytes.
8229 * *len on input contains the max length of the packet available.
8231 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
8232 * and included up to, but not including, the 4 byte FCS.
8234 static void
8235 wlc_bcn_prb_template(wlc_info_t *wlc, uint type, ratespec_t bcn_rspec,
8236 wlc_bsscfg_t *cfg, uint16 *buf, int *len)
8238 cck_phy_hdr_t *plcp;
8239 struct dot11_management_header *h;
8240 int hdr_len, body_len;
8242 ASSERT(*len >= 142);
8243 ASSERT(type == FC_BEACON || type == FC_PROBE_RESP);
8245 if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON)
8246 hdr_len = DOT11_MAC_HDR_LEN;
8247 else
8248 hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN;
8249 body_len = *len - hdr_len; /* calc buffer size provided for frame body */
8251 *len = hdr_len + body_len; /* return actual size */
8253 /* format PHY and MAC headers */
8254 bzero((char *)buf, hdr_len);
8256 plcp = (cck_phy_hdr_t *) buf;
8258 /* PLCP for Probe Response frames are filled in from core's rate table */
8259 if (type == FC_BEACON && !MBSS_BCN_ENAB(cfg)) {
8260 /* fill in PLCP */
8261 wlc_compute_plcp(wlc, bcn_rspec,
8262 (DOT11_MAC_HDR_LEN + body_len + DOT11_FCS_LEN),
8263 (uint8 *) plcp);
8266 /* "Regular" and 16 MBSS but not for 4 MBSS */
8267 /* Update the phytxctl for the beacon based on the rspec */
8268 if (!SOFTBCN_ENAB(cfg))
8269 wlc_beacon_phytxctl_txant_upd(wlc, bcn_rspec);
8271 if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON)
8272 h = (struct dot11_management_header *)&plcp[0];
8273 else
8274 h = (struct dot11_management_header *)&plcp[1];
8276 /* fill in 802.11 header */
8277 h->fc = htol16((uint16) type);
8279 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
8280 /* A1 filled in by MAC for prb resp, broadcast for bcn */
8281 if (type == FC_BEACON)
8282 bcopy((const char *)&ether_bcast, (char *)&h->da,
8283 ETHER_ADDR_LEN);
8284 bcopy((char *)&cfg->cur_etheraddr, (char *)&h->sa, ETHER_ADDR_LEN);
8285 bcopy((char *)&cfg->BSSID, (char *)&h->bssid, ETHER_ADDR_LEN);
8287 /* SEQ filled in by MAC */
8289 return;
8292 int wlc_get_header_len()
8294 return TXOFF;
8297 /* Update a beacon for a particular BSS
8298 * For MBSS, this updates the software template and sets "latest" to the index of the
8299 * template updated.
8300 * Otherwise, it updates the hardware template.
8302 void wlc_bss_update_beacon(wlc_info_t *wlc, wlc_bsscfg_t *cfg)
8304 int len = BCN_TMPL_LEN;
8306 /* Clear the soft intmask */
8307 wlc->defmacintmask &= ~MI_BCNTPL;
8309 if (!cfg->up) { /* Only allow updates on an UP bss */
8310 return;
8313 if (MBSS_BCN_ENAB(cfg)) { /* Optimize: Some of if/else could be combined */
8314 } else if (HWBCN_ENAB(cfg)) { /* Hardware beaconing for this config */
8315 uint16 bcn[BCN_TMPL_LEN / 2];
8316 uint32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
8317 d11regs_t *regs = wlc->regs;
8318 osl_t *osh = NULL;
8320 osh = wlc->osh;
8322 /* Check if both templates are in use, if so sched. an interrupt
8323 * that will call back into this routine
8325 if ((R_REG(osh, &regs->maccommand) & both_valid) == both_valid) {
8326 /* clear any previous status */
8327 W_REG(osh, &regs->macintstatus, MI_BCNTPL);
8329 /* Check that after scheduling the interrupt both of the
8330 * templates are still busy. if not clear the int. & remask
8332 if ((R_REG(osh, &regs->maccommand) & both_valid) == both_valid) {
8333 wlc->defmacintmask |= MI_BCNTPL;
8334 return;
8337 wlc->bcn_rspec =
8338 wlc_lowest_basic_rspec(wlc, &cfg->current_bss->rateset);
8339 ASSERT(wlc_valid_rate
8340 (wlc, wlc->bcn_rspec,
8341 CHSPEC_IS2G(cfg->current_bss->
8342 chanspec) ? WLC_BAND_2G : WLC_BAND_5G,
8343 TRUE));
8345 /* update the template and ucode shm */
8346 wlc_bcn_prb_template(wlc, FC_BEACON, wlc->bcn_rspec, cfg, bcn,
8347 &len);
8348 wlc_write_hw_bcntemplates(wlc, bcn, len, FALSE);
8353 * Update all beacons for the system.
8355 void wlc_update_beacon(wlc_info_t *wlc)
8357 int idx;
8358 wlc_bsscfg_t *bsscfg;
8360 /* update AP or IBSS beacons */
8361 FOREACH_BSS(wlc, idx, bsscfg) {
8362 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
8363 wlc_bss_update_beacon(wlc, bsscfg);
8367 /* Write ssid into shared memory */
8368 void wlc_shm_ssid_upd(wlc_info_t *wlc, wlc_bsscfg_t *cfg)
8370 uint8 *ssidptr = cfg->SSID;
8371 uint16 base = M_SSID;
8372 uint8 ssidbuf[DOT11_MAX_SSID_LEN];
8374 /* padding the ssid with zero and copy it into shm */
8375 bzero(ssidbuf, DOT11_MAX_SSID_LEN);
8376 bcopy(ssidptr, ssidbuf, cfg->SSID_len);
8378 wlc_copyto_shm(wlc, base, ssidbuf, DOT11_MAX_SSID_LEN);
8380 if (!MBSS_BCN_ENAB(cfg))
8381 wlc_write_shm(wlc, M_SSIDLEN, (uint16) cfg->SSID_len);
8384 void wlc_update_probe_resp(wlc_info_t *wlc, bool suspend)
8386 int idx;
8387 wlc_bsscfg_t *bsscfg;
8389 /* update AP or IBSS probe responses */
8390 FOREACH_BSS(wlc, idx, bsscfg) {
8391 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
8392 wlc_bss_update_probe_resp(wlc, bsscfg, suspend);
8396 void
8397 wlc_bss_update_probe_resp(wlc_info_t *wlc, wlc_bsscfg_t *cfg, bool suspend)
8399 uint16 prb_resp[BCN_TMPL_LEN / 2];
8400 int len = BCN_TMPL_LEN;
8402 /* write the probe response to hardware, or save in the config structure */
8403 if (!MBSS_PRB_ENAB(cfg)) {
8405 /* create the probe response template */
8406 wlc_bcn_prb_template(wlc, FC_PROBE_RESP, 0, cfg, prb_resp,
8407 &len);
8409 if (suspend)
8410 wlc_suspend_mac_and_wait(wlc);
8412 /* write the probe response into the template region */
8413 wlc_bmac_write_template_ram(wlc->hw, T_PRS_TPL_BASE,
8414 (len + 3) & ~3, prb_resp);
8416 /* write the length of the probe response frame (+PLCP/-FCS) */
8417 wlc_write_shm(wlc, M_PRB_RESP_FRM_LEN, (uint16) len);
8419 /* write the SSID and SSID length */
8420 wlc_shm_ssid_upd(wlc, cfg);
8423 * Write PLCP headers and durations for probe response frames at all rates.
8424 * Use the actual frame length covered by the PLCP header for the call to
8425 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
8427 len += (-D11_PHY_HDR_LEN + DOT11_FCS_LEN);
8428 wlc_mod_prb_rsp_rate_table(wlc, (uint16) len);
8430 if (suspend)
8431 wlc_enable_mac(wlc);
8432 } else { /* Generating probe resp in sw; update local template */
8433 ASSERT(0 && "No software probe response support without MBSS");
8437 /* prepares pdu for transmission. returns BCM error codes */
8438 int wlc_prep_pdu(wlc_info_t *wlc, void *pdu, uint *fifop)
8440 osl_t *osh;
8441 uint fifo;
8442 d11txh_t *txh;
8443 struct dot11_header *h;
8444 struct scb *scb;
8445 uint16 fc;
8447 osh = wlc->osh;
8449 ASSERT(pdu);
8450 txh = (d11txh_t *) PKTDATA(pdu);
8451 ASSERT(txh);
8452 h = (struct dot11_header *)((uint8 *) (txh + 1) + D11_PHY_HDR_LEN);
8453 ASSERT(h);
8454 fc = ltoh16(h->fc);
8456 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
8457 fifo = ltoh16(txh->TxFrameID) & TXFID_QUEUE_MASK;
8459 scb = NULL;
8461 *fifop = fifo;
8463 /* return if insufficient dma resources */
8464 if (TXAVAIL(wlc, fifo) < MAX_DMA_SEGS) {
8465 /* Mark precedences related to this FIFO, unsendable */
8466 WLC_TX_FIFO_CLEAR(wlc, fifo);
8467 return BCME_BUSY;
8470 if (FC_TYPE(ltoh16(txh->MacFrameControl)) != FC_TYPE_DATA)
8471 WLCNTINCR(wlc->pub->_cnt->txctl);
8473 return 0;
8476 /* init tx reported rate mechanism */
8477 void wlc_reprate_init(wlc_info_t *wlc)
8479 int i;
8480 wlc_bsscfg_t *bsscfg;
8482 FOREACH_BSS(wlc, i, bsscfg) {
8483 wlc_bsscfg_reprate_init(bsscfg);
8487 /* per bsscfg init tx reported rate mechanism */
8488 void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg)
8490 bsscfg->txrspecidx = 0;
8491 bzero((char *)bsscfg->txrspec, sizeof(bsscfg->txrspec));
8494 /* Retrieve a consolidated set of revision information,
8495 * typically for the WLC_GET_REVINFO ioctl
8497 int wlc_get_revision_info(wlc_info_t *wlc, void *buf, uint len)
8499 wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf;
8501 if (len < WL_REV_INFO_LEGACY_LENGTH)
8502 return BCME_BUFTOOSHORT;
8504 rinfo->vendorid = wlc->vendorid;
8505 rinfo->deviceid = wlc->deviceid;
8506 rinfo->radiorev = (wlc->band->radiorev << IDCODE_REV_SHIFT) |
8507 (wlc->band->radioid << IDCODE_ID_SHIFT);
8508 rinfo->chiprev = wlc->pub->sih->chiprev;
8509 rinfo->corerev = wlc->pub->corerev;
8510 rinfo->boardid = wlc->pub->sih->boardtype;
8511 rinfo->boardvendor = wlc->pub->sih->boardvendor;
8512 rinfo->boardrev = wlc->pub->boardrev;
8513 rinfo->ucoderev = wlc->ucode_rev;
8514 rinfo->driverrev = EPI_VERSION_NUM;
8515 rinfo->bus = wlc->pub->sih->bustype;
8516 rinfo->chipnum = wlc->pub->sih->chip;
8518 if (len >= (OFFSETOF(wlc_rev_info_t, chippkg))) {
8519 rinfo->phytype = wlc->band->phytype;
8520 rinfo->phyrev = wlc->band->phyrev;
8521 rinfo->anarev = 0; /* obsolete stuff, suppress */
8524 if (len >= sizeof(*rinfo)) {
8525 rinfo->chippkg = wlc->pub->sih->chippkg;
8528 return BCME_OK;
8531 void wlc_default_rateset(wlc_info_t *wlc, wlc_rateset_t *rs)
8533 wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype,
8534 FALSE, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
8535 CHSPEC_WLC_BW(wlc->default_bss->chanspec),
8536 wlc->stf->txstreams);
8539 static void BCMATTACHFN(wlc_bss_default_init) (wlc_info_t *wlc)
8541 chanspec_t chanspec;
8542 wlcband_t *band;
8543 wlc_bss_info_t *bi = wlc->default_bss;
8545 /* init default and target BSS with some sane initial values */
8546 bzero((char *)(bi), sizeof(wlc_bss_info_t));
8547 bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT :
8548 BEACON_INTERVAL_DEFAULT;
8549 bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT :
8550 DTIM_INTERVAL_DEFAULT;
8552 /* fill the default channel as the first valid channel
8553 * starting from the 2G channels
8555 chanspec = CH20MHZ_CHSPEC(1);
8556 ASSERT(chanspec != INVCHANSPEC);
8558 wlc->home_chanspec = bi->chanspec = chanspec;
8560 /* find the band of our default channel */
8561 band = wlc->band;
8562 if (NBANDS(wlc) > 1 && band->bandunit != CHSPEC_WLCBANDUNIT(chanspec))
8563 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
8565 /* init bss rates to the band specific default rate set */
8566 wlc_rateset_default(&bi->rateset, NULL, band->phytype, band->bandtype,
8567 FALSE, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
8568 CHSPEC_WLC_BW(chanspec), wlc->stf->txstreams);
8570 if (N_ENAB(wlc->pub))
8571 bi->flags |= WLC_BSS_HT;
8574 /* Deferred event processing */
8575 static void wlc_process_eventq(void *arg)
8577 wlc_info_t *wlc = (wlc_info_t *) arg;
8578 wlc_event_t *etmp;
8580 while ((etmp = wlc_eventq_deq(wlc->eventq))) {
8581 /* Perform OS specific event processing */
8582 wl_event(wlc->wl, etmp->event.ifname, etmp);
8583 if (etmp->data) {
8584 osl_mfree(wlc->osh, etmp->data, etmp->event.datalen);
8585 etmp->data = NULL;
8587 wlc_event_free(wlc->eventq, etmp);
8591 void
8592 wlc_uint64_sub(uint32 *a_high, uint32 *a_low, uint32 b_high, uint32 b_low)
8594 if (b_low > *a_low) {
8595 /* low half needs a carry */
8596 b_high += 1;
8598 *a_low -= b_low;
8599 *a_high -= b_high;
8602 static ratespec_t
8603 mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, uint32 int_val)
8605 uint8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT;
8606 uint8 rate = int_val & NRATE_RATE_MASK;
8607 ratespec_t rspec;
8608 bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE);
8609 bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT);
8610 bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY)
8611 == NRATE_OVERRIDE_MCS_ONLY);
8612 int bcmerror = 0;
8614 if (!ismcs) {
8615 return (ratespec_t) rate;
8618 /* validate the combination of rate/mcs/stf is allowed */
8619 if (N_ENAB(wlc->pub) && ismcs) {
8620 /* mcs only allowed when nmode */
8621 if (stf > PHY_TXC1_MODE_SDM) {
8622 WL_ERROR(("wl%d: %s: Invalid stf\n", WLCWLUNIT(wlc),
8623 __func__));
8624 bcmerror = BCME_RANGE;
8625 goto done;
8628 /* mcs 32 is a special case, DUP mode 40 only */
8629 if (rate == 32) {
8630 if (!CHSPEC_IS40(wlc->home_chanspec) ||
8631 ((stf != PHY_TXC1_MODE_SISO)
8632 && (stf != PHY_TXC1_MODE_CDD))) {
8633 WL_ERROR(("wl%d: %s: Invalid mcs 32\n",
8634 WLCWLUNIT(wlc), __func__));
8635 bcmerror = BCME_RANGE;
8636 goto done;
8638 /* mcs > 7 must use stf SDM */
8639 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) {
8640 /* mcs > 7 must use stf SDM */
8641 if (stf != PHY_TXC1_MODE_SDM) {
8642 WL_TRACE(("wl%d: %s: enabling SDM mode for mcs %d\n", WLCWLUNIT(wlc), __func__, rate));
8643 stf = PHY_TXC1_MODE_SDM;
8645 } else {
8646 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8647 if ((stf > PHY_TXC1_MODE_STBC) ||
8648 (!WLC_STBC_CAP_PHY(wlc)
8649 && (stf == PHY_TXC1_MODE_STBC))) {
8650 WL_ERROR(("wl%d: %s: Invalid STBC\n",
8651 WLCWLUNIT(wlc), __func__));
8652 bcmerror = BCME_RANGE;
8653 goto done;
8656 } else if (IS_OFDM(rate)) {
8657 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
8658 WL_ERROR(("wl%d: %s: Invalid OFDM\n", WLCWLUNIT(wlc),
8659 __func__));
8660 bcmerror = BCME_RANGE;
8661 goto done;
8663 } else if (IS_CCK(rate)) {
8664 if ((cur_band->bandtype != WLC_BAND_2G)
8665 || (stf != PHY_TXC1_MODE_SISO)) {
8666 WL_ERROR(("wl%d: %s: Invalid CCK\n", WLCWLUNIT(wlc),
8667 __func__));
8668 bcmerror = BCME_RANGE;
8669 goto done;
8671 } else {
8672 WL_ERROR(("wl%d: %s: Unknown rate type\n", WLCWLUNIT(wlc),
8673 __func__));
8674 bcmerror = BCME_RANGE;
8675 goto done;
8677 /* make sure multiple antennae are available for non-siso rates */
8678 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
8679 WL_ERROR(("wl%d: %s: SISO antenna but !SISO request\n",
8680 WLCWLUNIT(wlc), __func__));
8681 bcmerror = BCME_RANGE;
8682 goto done;
8685 rspec = rate;
8686 if (ismcs) {
8687 rspec |= RSPEC_MIMORATE;
8688 /* For STBC populate the STC field of the ratespec */
8689 if (stf == PHY_TXC1_MODE_STBC) {
8690 uint8 stc;
8691 stc = 1; /* Nss for single stream is always 1 */
8692 rspec |= (stc << RSPEC_STC_SHIFT);
8696 rspec |= (stf << RSPEC_STF_SHIFT);
8698 if (override_mcs_only)
8699 rspec |= RSPEC_OVERRIDE_MCS_ONLY;
8701 if (issgi)
8702 rspec |= RSPEC_SHORT_GI;
8704 if ((rate != 0)
8705 && !wlc_valid_rate(wlc, rspec, cur_band->bandtype, TRUE)) {
8706 return rate;
8709 return rspec;
8710 done:
8711 WL_ERROR(("Hoark\n"));
8712 return rate;
8715 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8716 static int
8717 wlc_duty_cycle_set(wlc_info_t *wlc, int duty_cycle, bool isOFDM,
8718 bool writeToShm)
8720 int idle_busy_ratio_x_16 = 0;
8721 uint offset =
8722 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM :
8723 M_TX_IDLE_BUSY_RATIO_X_16_CCK;
8724 if (duty_cycle > 100 || duty_cycle < 0) {
8725 WL_ERROR(("wl%d: duty cycle value off limit\n",
8726 wlc->pub->unit));
8727 return BCME_RANGE;
8729 if (duty_cycle)
8730 idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle;
8731 /* Only write to shared memory when wl is up */
8732 if (writeToShm)
8733 wlc_write_shm(wlc, offset, (uint16) idle_busy_ratio_x_16);
8735 if (isOFDM)
8736 wlc->tx_duty_cycle_ofdm = (uint16) duty_cycle;
8737 else
8738 wlc->tx_duty_cycle_cck = (uint16) duty_cycle;
8740 return BCME_OK;
8743 void
8744 wlc_pktengtx(wlc_info_t *wlc, wl_pkteng_t *pkteng, uint8 rate,
8745 struct ether_addr *sa, uint32 wait_delay)
8747 bool suspend;
8748 uint16 val = M_PKTENG_MODE_TX;
8749 volatile uint16 frame_cnt_check;
8750 uint8 counter = 0;
8752 wlc_bmac_set_deaf(wlc->hw, TRUE);
8754 suspend =
8755 (0 == (R_REG(wlc->hw->osh, &wlc->regs->maccontrol) & MCTL_EN_MAC));
8756 if (suspend)
8757 wlc_enable_mac(wlc);
8759 /* set nframes */
8760 if (pkteng->nframes) {
8761 /* retry counter is used to replay the packet */
8762 wlc_bmac_write_shm(wlc->hw, M_PKTENG_FRMCNT_LO,
8763 (pkteng->nframes & 0xffff));
8764 wlc_bmac_write_shm(wlc->hw, M_PKTENG_FRMCNT_HI,
8765 ((pkteng->nframes >> 16) & 0xffff));
8766 val |= M_PKTENG_FRMCNT_VLD;
8769 if (pkteng->length) {
8770 /* DATA frame */
8771 wlc_bmac_write_shm(wlc->hw, M_PKTENG_CTRL, val);
8772 /* we write to M_MFGTEST_IFS the IFS required in 1/8us factor */
8773 /* 10 : for factoring difference b/w Tx.crs and energy in air */
8774 /* 44 : amount of time spent after TX_RRSP to frame start */
8775 /* IFS */
8776 wlc_bmac_write_shm(wlc->hw, M_PKTENG_IFS,
8777 (pkteng->delay - 10) * 8 - 44);
8778 } else {
8779 /* CTS frame */
8780 val |= M_PKTENG_MODE_TX_CTS;
8781 wlc_bmac_write_shm(wlc->hw, M_PKTENG_IFS,
8782 (uint16) pkteng->delay);
8783 wlc_bmac_write_shm(wlc->hw, M_PKTENG_CTRL, val);
8786 /* Wait for packets to finish */
8787 frame_cnt_check = wlc_bmac_read_shm(wlc->hw, M_PKTENG_FRMCNT_LO);
8788 while ((counter < 100) && (frame_cnt_check != 0)) {
8789 OSL_DELAY(100);
8790 frame_cnt_check =
8791 wlc_bmac_read_shm(wlc->hw, M_PKTENG_FRMCNT_LO);
8792 counter++;
8795 wlc_bmac_write_shm(wlc->hw, M_PKTENG_CTRL, 0);
8797 if (suspend)
8798 wlc_suspend_mac_and_wait(wlc);
8800 wlc_bmac_set_deaf(wlc->hw, FALSE);
8803 /* Read a single uint16 from shared memory.
8804 * SHM 'offset' needs to be an even address
8806 uint16 wlc_read_shm(wlc_info_t *wlc, uint offset)
8808 return wlc_bmac_read_shm(wlc->hw, offset);
8811 /* Write a single uint16 to shared memory.
8812 * SHM 'offset' needs to be an even address
8814 void wlc_write_shm(wlc_info_t *wlc, uint offset, uint16 v)
8816 wlc_bmac_write_shm(wlc->hw, offset, v);
8819 /* Set a range of shared memory to a value.
8820 * SHM 'offset' needs to be an even address and
8821 * Range length 'len' must be an even number of bytes
8823 void wlc_set_shm(wlc_info_t *wlc, uint offset, uint16 v, int len)
8825 /* offset and len need to be even */
8826 ASSERT((offset & 1) == 0);
8827 ASSERT((len & 1) == 0);
8829 if (len <= 0)
8830 return;
8832 wlc_bmac_set_shm(wlc->hw, offset, v, len);
8835 /* Copy a buffer to shared memory.
8836 * SHM 'offset' needs to be an even address and
8837 * Buffer length 'len' must be an even number of bytes
8839 void wlc_copyto_shm(wlc_info_t *wlc, uint offset, const void *buf, int len)
8841 /* offset and len need to be even */
8842 ASSERT((offset & 1) == 0);
8843 ASSERT((len & 1) == 0);
8845 if (len <= 0)
8846 return;
8847 wlc_bmac_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8851 /* Copy from shared memory to a buffer.
8852 * SHM 'offset' needs to be an even address and
8853 * Buffer length 'len' must be an even number of bytes
8855 void wlc_copyfrom_shm(wlc_info_t *wlc, uint offset, void *buf, int len)
8857 /* offset and len need to be even */
8858 ASSERT((offset & 1) == 0);
8859 ASSERT((len & 1) == 0);
8861 if (len <= 0)
8862 return;
8864 wlc_bmac_copyfrom_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8867 /* wrapper BMAC functions to for HIGH driver access */
8868 void wlc_mctrl(wlc_info_t *wlc, uint32 mask, uint32 val)
8870 wlc_bmac_mctrl(wlc->hw, mask, val);
8873 void wlc_corereset(wlc_info_t *wlc, uint32 flags)
8875 wlc_bmac_corereset(wlc->hw, flags);
8878 void wlc_mhf(wlc_info_t *wlc, uint8 idx, uint16 mask, uint16 val, int bands)
8880 wlc_bmac_mhf(wlc->hw, idx, mask, val, bands);
8883 uint16 wlc_mhf_get(wlc_info_t *wlc, uint8 idx, int bands)
8885 return wlc_bmac_mhf_get(wlc->hw, idx, bands);
8888 int wlc_xmtfifo_sz_get(wlc_info_t *wlc, uint fifo, uint *blocks)
8890 return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks);
8893 void wlc_write_template_ram(wlc_info_t *wlc, int offset, int len, void *buf)
8895 wlc_bmac_write_template_ram(wlc->hw, offset, len, buf);
8898 void wlc_write_hw_bcntemplates(wlc_info_t *wlc, void *bcn, int len, bool both)
8900 wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both);
8903 void
8904 wlc_set_addrmatch(wlc_info_t *wlc, int match_reg_offset,
8905 const struct ether_addr *addr)
8907 wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr);
8910 void wlc_set_rcmta(wlc_info_t *wlc, int idx, const struct ether_addr *addr)
8912 wlc_bmac_set_rcmta(wlc->hw, idx, addr);
8915 void wlc_read_tsf(wlc_info_t *wlc, uint32 *tsf_l_ptr, uint32 *tsf_h_ptr)
8917 wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr);
8920 void wlc_set_cwmin(wlc_info_t *wlc, uint16 newmin)
8922 wlc->band->CWmin = newmin;
8923 wlc_bmac_set_cwmin(wlc->hw, newmin);
8926 void wlc_set_cwmax(wlc_info_t *wlc, uint16 newmax)
8928 wlc->band->CWmax = newmax;
8929 wlc_bmac_set_cwmax(wlc->hw, newmax);
8932 void wlc_fifoerrors(wlc_info_t *wlc)
8935 wlc_bmac_fifoerrors(wlc->hw);
8938 /* Search mem rw utilities */
8940 void wlc_pllreq(wlc_info_t *wlc, bool set, mbool req_bit)
8942 wlc_bmac_pllreq(wlc->hw, set, req_bit);
8945 void wlc_reset_bmac_done(wlc_info_t *wlc)
8947 #ifdef WLC_HIGH_ONLY
8948 wlc->reset_bmac_pending = FALSE;
8949 #endif
8952 void wlc_ht_mimops_cap_update(wlc_info_t *wlc, uint8 mimops_mode)
8954 wlc->ht_cap.cap &= ~HT_CAP_MIMO_PS_MASK;
8955 wlc->ht_cap.cap |= (mimops_mode << HT_CAP_MIMO_PS_SHIFT);
8957 if (AP_ENAB(wlc->pub) && wlc->clk) {
8958 wlc_update_beacon(wlc);
8959 wlc_update_probe_resp(wlc, TRUE);
8963 /* check for the particular priority flow control bit being set */
8964 bool
8965 wlc_txflowcontrol_prio_isset(wlc_info_t *wlc, wlc_txq_info_t *q, int prio)
8967 uint prio_mask;
8969 if (prio == ALLPRIO) {
8970 prio_mask = TXQ_STOP_FOR_PRIOFC_MASK;
8971 } else {
8972 ASSERT(prio >= 0 && prio <= MAXPRIO);
8973 prio_mask = NBITVAL(prio);
8976 return (q->stopped & prio_mask) == prio_mask;
8979 /* propogate the flow control to all interfaces using the given tx queue */
8980 void wlc_txflowcontrol(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, int prio)
8982 uint prio_bits;
8983 uint cur_bits;
8985 WL_ERROR(("%s: flow contro kicks in\n", __func__));
8987 if (prio == ALLPRIO) {
8988 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK;
8989 } else {
8990 ASSERT(prio >= 0 && prio <= MAXPRIO);
8991 prio_bits = NBITVAL(prio);
8994 cur_bits = qi->stopped & prio_bits;
8996 /* Check for the case of no change and return early
8997 * Otherwise update the bit and continue
8999 if (on) {
9000 if (cur_bits == prio_bits) {
9001 return;
9003 mboolset(qi->stopped, prio_bits);
9004 } else {
9005 if (cur_bits == 0) {
9006 return;
9008 mboolclr(qi->stopped, prio_bits);
9011 /* If there is a flow control override we will not change the external
9012 * flow control state.
9014 if (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK) {
9015 return;
9018 wlc_txflowcontrol_signal(wlc, qi, on, prio);
9021 void
9022 wlc_txflowcontrol_override(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on,
9023 uint override)
9025 uint prev_override;
9027 ASSERT(override != 0);
9028 ASSERT((override & TXQ_STOP_FOR_PRIOFC_MASK) == 0);
9030 prev_override = (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK);
9032 /* Update the flow control bits and do an early return if there is
9033 * no change in the external flow control state.
9035 if (on) {
9036 mboolset(qi->stopped, override);
9037 /* if there was a previous override bit on, then setting this
9038 * makes no difference.
9040 if (prev_override) {
9041 return;
9044 wlc_txflowcontrol_signal(wlc, qi, ON, ALLPRIO);
9045 } else {
9046 mboolclr(qi->stopped, override);
9047 /* clearing an override bit will only make a difference for
9048 * flow control if it was the only bit set. For any other
9049 * override setting, just return
9051 if (prev_override != override) {
9052 return;
9055 if (qi->stopped == 0) {
9056 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
9057 } else {
9058 int prio;
9060 for (prio = MAXPRIO; prio >= 0; prio--) {
9061 if (!mboolisset(qi->stopped, NBITVAL(prio)))
9062 wlc_txflowcontrol_signal(wlc, qi, OFF,
9063 prio);
9069 static void wlc_txflowcontrol_reset(wlc_info_t *wlc)
9071 wlc_txq_info_t *qi;
9073 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
9074 if (qi->stopped) {
9075 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
9076 qi->stopped = 0;
9081 static void
9082 wlc_txflowcontrol_signal(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on,
9083 int prio)
9085 wlc_if_t *wlcif;
9087 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) {
9088 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED)
9089 wl_txflowcontrol(wlc->wl, wlcif->wlif, on, prio);
9093 static wlc_txq_info_t *wlc_txq_alloc(wlc_info_t *wlc, osl_t *osh)
9095 wlc_txq_info_t *qi, *p;
9097 qi = (wlc_txq_info_t *) wlc_calloc(osh, wlc->pub->unit,
9098 sizeof(wlc_txq_info_t));
9099 if (qi == NULL) {
9100 return NULL;
9103 /* Have enough room for control packets along with HI watermark */
9104 /* Also, add room to txq for total psq packets if all the SCBs leave PS mode */
9105 /* The watermark for flowcontrol to OS packets will remain the same */
9106 pktq_init(&qi->q, WLC_PREC_COUNT,
9107 (2 * wlc->pub->tunables->datahiwat) + PKTQ_LEN_DEFAULT +
9108 wlc->pub->psq_pkts_total);
9110 /* add this queue to the the global list */
9111 p = wlc->tx_queues;
9112 if (p == NULL) {
9113 wlc->tx_queues = qi;
9114 } else {
9115 while (p->next != NULL)
9116 p = p->next;
9117 p->next = qi;
9120 return qi;
9123 static void wlc_txq_free(wlc_info_t *wlc, osl_t *osh, wlc_txq_info_t *qi)
9125 wlc_txq_info_t *p;
9127 if (qi == NULL)
9128 return;
9130 /* remove the queue from the linked list */
9131 p = wlc->tx_queues;
9132 if (p == qi)
9133 wlc->tx_queues = p->next;
9134 else {
9135 while (p != NULL && p->next != qi)
9136 p = p->next;
9137 ASSERT(p->next == qi);
9138 if (p != NULL)
9139 p->next = p->next->next;
9142 osl_mfree(osh, qi, sizeof(wlc_txq_info_t));