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.
19 #include <linux/kernel.h>
23 #include <linux/ctype.h>
27 #include <bcmendian.h>
28 #include <proto/wpa.h>
41 #include <wlc_bsscfg.h>
42 #include <wlc_channel.h>
43 #include <wlc_mac80211.h>
46 #include <wlc_phy_hal.h>
47 #include <wlc_phy_shim.h>
48 #include <wlc_antsel.h>
50 #include <wlc_ampdu.h>
51 #include <wlc_event.h>
52 #include <wl_export.h>
56 #include "d11ucode_ext.h"
59 #include <bcm_rpc_tp.h>
63 #include <wlc_rpctx.h>
64 #endif /* WLC_HIGH_ONLY */
65 #include <wlc_alloc.h>
66 #include <net/mac80211.h>
71 #define R_REG(osh, r) RPC_READ_REG(osh, r)
72 #define W_REG(osh, r, v) RPC_WRITE_REG(osh, r, v)
76 * buffer length needed for wlc_format_ssid
77 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
79 #define SSID_FMT_BUF_LEN ((4 * DOT11_MAX_SSID_LEN) + 1)
81 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
82 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
84 #ifndef WLC_MPC_MAX_DELAYCNT
85 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
87 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
88 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
90 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
91 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
93 /* Scale down delays to accommodate QT slow speed */
94 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
95 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
97 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
100 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
101 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
102 * this low resolution driver tick can be used for maintenance tasks such as phy
103 * calibration and scb update
106 /* watchdog trigger mode: OSL timer or TBTT */
107 #define WLC_WATCHDOG_TBTT(wlc) \
108 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
110 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
111 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
113 #ifndef WLC_HIGH_ONLY
114 #define WLC_WAR16165(wlc) (BUSTYPE(wlc->pub->sih->bustype) == PCI_BUS && \
115 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
117 #define WLC_WAR16165(wlc) (FALSE)
118 #endif /* WLC_HIGH_ONLY */
128 /* Find basic rate for a given rate */
129 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
130 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
131 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
133 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
135 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
137 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
139 #define SCAN_IN_PROGRESS(x) 0
142 /* pointer to most recently allocated wl/wlc */
143 static wlc_info_t
*wlc_info_dbg
= (wlc_info_t
*) (NULL
);
147 struct wlc_id_name_entry
{
151 typedef struct wlc_id_name_entry wlc_id_name_table_t
[];
156 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
157 * table and by the wlc_doiovar() function. No ordering is imposed:
158 * the table is keyed by name, and the function uses a switch.
163 IOV_BCN_LI_BCN
, /* Beacon listen interval in # of beacons */
164 IOV_LAST
/* In case of a need to check max ID number */
167 const bcm_iovar_t wlc_iovars
[] = {
168 {"mpc", IOV_MPC
, (IOVF_OPEN_ALLOW
), IOVT_BOOL
, 0},
169 {"qtxpower", IOV_QTXPOWER
, (IOVF_WHL
| IOVF_OPEN_ALLOW
), IOVT_UINT32
,
171 {"bcn_li_bcn", IOV_BCN_LI_BCN
, 0, IOVT_UINT8
, 0},
175 const u8 prio2fifo
[NUMPRIO
] = {
176 TX_AC_BE_FIFO
, /* 0 BE AC_BE Best Effort */
177 TX_AC_BK_FIFO
, /* 1 BK AC_BK Background */
178 TX_AC_BK_FIFO
, /* 2 -- AC_BK Background */
179 TX_AC_BE_FIFO
, /* 3 EE AC_BE Best Effort */
180 TX_AC_VI_FIFO
, /* 4 CL AC_VI Video */
181 TX_AC_VI_FIFO
, /* 5 VI AC_VI Video */
182 TX_AC_VO_FIFO
, /* 6 VO AC_VO Voice */
183 TX_AC_VO_FIFO
/* 7 NC AC_VO Voice */
186 /* precedences numbers for wlc queues. These are twice as may levels as
188 * Odd numbers are used for HI priority traffic at same precedence levels
189 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
191 #define _WLC_PREC_NONE 0 /* None = - */
192 #define _WLC_PREC_BK 2 /* BK - Background */
193 #define _WLC_PREC_BE 4 /* BE - Best-effort */
194 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
195 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
196 #define _WLC_PREC_VI 10 /* Vi - Video */
197 #define _WLC_PREC_VO 12 /* Vo - Voice */
198 #define _WLC_PREC_NC 14 /* NC - Network Control */
200 /* 802.1D Priority to precedence queue mapping */
201 const u8 wlc_prio2prec_map
[] = {
202 _WLC_PREC_BE
, /* 0 BE - Best-effort */
203 _WLC_PREC_BK
, /* 1 BK - Background */
204 _WLC_PREC_NONE
, /* 2 None = - */
205 _WLC_PREC_EE
, /* 3 EE - Excellent-effort */
206 _WLC_PREC_CL
, /* 4 CL - Controlled Load */
207 _WLC_PREC_VI
, /* 5 Vi - Video */
208 _WLC_PREC_VO
, /* 6 Vo - Voice */
209 _WLC_PREC_NC
, /* 7 NC - Network Control */
212 /* Sanity check for tx_prec_map and fifo synchup
213 * Either there are some packets pending for the fifo, else if fifo is empty then
214 * all the corresponding precmap bits should be set
216 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
217 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
218 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
219 (wlc)->fifo2prec_map[(fifo)]))
221 /* TX FIFO number to WME/802.1E Access Category */
222 const u8 wme_fifo2ac
[] = { AC_BK
, AC_BE
, AC_VI
, AC_VO
, AC_BE
, AC_BE
};
224 /* WME/802.1E Access Category to TX FIFO number */
225 static const u8 wme_ac2fifo
[] = { 1, 0, 2, 3 };
227 static bool in_send_q
= FALSE
;
229 /* Shared memory location index for various AC params */
230 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
233 static const char *fifo_names
[] = {
234 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
235 const char *aci_names
[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
238 static const u8 acbitmap2maxprio
[] = {
239 PRIO_8021D_BE
, PRIO_8021D_BE
, PRIO_8021D_BK
, PRIO_8021D_BK
,
240 PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
,
241 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
,
242 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
245 /* currently the best mechanism for determining SIFS is the band in use */
246 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
248 /* value for # replay counters currently supported */
249 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
251 /* local prototypes */
252 extern void wlc_txq_enq(void *ctx
, struct scb
*scb
, void *sdu
, uint prec
);
253 static u16 BCMFASTPATH
wlc_d11hdrs_mac80211(wlc_info_t
*wlc
,
254 struct ieee80211_hw
*hw
, void *p
,
255 struct scb
*scb
, uint frag
,
256 uint nfrags
, uint queue
,
259 ratespec_t rspec_override
);
260 bool wlc_sendpkt_mac80211(wlc_info_t
*wlc
, void *sdu
, struct ieee80211_hw
*hw
);
261 void wlc_wme_setparams(wlc_info_t
*wlc
, u16 aci
, void *arg
, bool suspend
);
262 static void wlc_bss_default_init(wlc_info_t
*wlc
);
263 static void wlc_ucode_mac_upd(wlc_info_t
*wlc
);
264 static ratespec_t
mac80211_wlc_set_nrate(wlc_info_t
*wlc
, wlcband_t
*cur_band
,
266 static void wlc_tx_prec_map_init(wlc_info_t
*wlc
);
267 static void wlc_watchdog(void *arg
);
268 static void wlc_watchdog_by_timer(void *arg
);
269 static int wlc_set_rateset(wlc_info_t
*wlc
, wlc_rateset_t
*rs_arg
);
270 static int wlc_iovar_rangecheck(wlc_info_t
*wlc
, u32 val
,
271 const bcm_iovar_t
*vi
);
272 static u8
wlc_local_constraint_qdbm(wlc_info_t
*wlc
);
274 /* send and receive */
275 static wlc_txq_info_t
*wlc_txq_alloc(wlc_info_t
*wlc
, osl_t
*osh
);
276 static void wlc_txq_free(wlc_info_t
*wlc
, osl_t
*osh
, wlc_txq_info_t
*qi
);
277 static void wlc_txflowcontrol_signal(wlc_info_t
*wlc
, wlc_txq_info_t
*qi
,
279 static void wlc_txflowcontrol_reset(wlc_info_t
*wlc
);
280 static u16
wlc_compute_airtime(wlc_info_t
*wlc
, ratespec_t rspec
,
282 static void wlc_compute_cck_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
283 static void wlc_compute_ofdm_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
284 static void wlc_compute_mimo_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
285 static u16
wlc_compute_frame_dur(wlc_info_t
*wlc
, ratespec_t rate
,
286 u8 preamble_type
, uint next_frag_len
);
287 static void wlc_recvctl(wlc_info_t
*wlc
, osl_t
*osh
, d11rxhdr_t
*rxh
,
289 static uint
wlc_calc_frame_len(wlc_info_t
*wlc
, ratespec_t rate
,
290 u8 preamble_type
, uint dur
);
291 static uint
wlc_calc_ack_time(wlc_info_t
*wlc
, ratespec_t rate
,
293 static uint
wlc_calc_cts_time(wlc_info_t
*wlc
, ratespec_t rate
,
295 /* interrupt, up/down, band */
296 static void wlc_setband(wlc_info_t
*wlc
, uint bandunit
);
297 static chanspec_t
wlc_init_chanspec(wlc_info_t
*wlc
);
298 static void wlc_bandinit_ordered(wlc_info_t
*wlc
, chanspec_t chanspec
);
299 static void wlc_bsinit(wlc_info_t
*wlc
);
300 static int wlc_duty_cycle_set(wlc_info_t
*wlc
, int duty_cycle
, bool isOFDM
,
302 static void wlc_radio_hwdisable_upd(wlc_info_t
*wlc
);
303 static bool wlc_radio_monitor_start(wlc_info_t
*wlc
);
304 static void wlc_radio_timer(void *arg
);
305 static void wlc_radio_enable(wlc_info_t
*wlc
);
306 static void wlc_radio_upd(wlc_info_t
*wlc
);
308 /* scan, association, BSS */
309 static uint
wlc_calc_ba_time(wlc_info_t
*wlc
, ratespec_t rate
,
311 static void wlc_update_mimo_band_bwcap(wlc_info_t
*wlc
, u8 bwcap
);
312 static void wlc_ht_update_sgi_rx(wlc_info_t
*wlc
, int val
);
313 void wlc_ht_mimops_cap_update(wlc_info_t
*wlc
, u8 mimops_mode
);
314 static void wlc_ht_update_ldpc(wlc_info_t
*wlc
, s8 val
);
315 static void wlc_war16165(wlc_info_t
*wlc
, bool tx
);
317 static void wlc_process_eventq(void *arg
);
318 static void wlc_wme_retries_write(wlc_info_t
*wlc
);
319 static bool wlc_attach_stf_ant_init(wlc_info_t
*wlc
);
320 static uint
wlc_attach_module(wlc_info_t
*wlc
);
321 static void wlc_detach_module(wlc_info_t
*wlc
);
322 static void wlc_timers_deinit(wlc_info_t
*wlc
);
323 static void wlc_down_led_upd(wlc_info_t
*wlc
);
324 static uint
wlc_down_del_timer(wlc_info_t
*wlc
);
325 static void wlc_ofdm_rateset_war(wlc_info_t
*wlc
);
326 static int _wlc_ioctl(wlc_info_t
*wlc
, int cmd
, void *arg
, int len
,
327 struct wlc_if
*wlcif
);
330 void wlc_get_rcmta(wlc_info_t
*wlc
, int idx
, struct ether_addr
*addr
)
332 d11regs_t
*regs
= wlc
->regs
;
336 WL_TRACE(("wl%d: %s\n", WLCWLUNIT(wlc
), __func__
));
338 ASSERT(wlc
->pub
->corerev
> 4);
342 W_REG(osh
, ®s
->objaddr
, (OBJADDR_RCMTA_SEL
| (idx
* 2)));
343 (void)R_REG(osh
, ®s
->objaddr
);
344 v32
= R_REG(osh
, ®s
->objdata
);
345 addr
->octet
[0] = (u8
) v32
;
346 addr
->octet
[1] = (u8
) (v32
>> 8);
347 addr
->octet
[2] = (u8
) (v32
>> 16);
348 addr
->octet
[3] = (u8
) (v32
>> 24);
349 W_REG(osh
, ®s
->objaddr
, (OBJADDR_RCMTA_SEL
| ((idx
* 2) + 1)));
350 (void)R_REG(osh
, ®s
->objaddr
);
351 v32
= R_REG(osh
, (volatile u16
*)(uintptr
) & regs
->objdata
);
352 addr
->octet
[4] = (u8
) v32
;
353 addr
->octet
[5] = (u8
) (v32
>> 8);
355 #endif /* defined(BCMDBG) */
357 /* keep the chip awake if needed */
358 bool wlc_stay_awake(wlc_info_t
*wlc
)
363 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
365 bool wlc_ps_allowed(wlc_info_t
*wlc
)
370 /* disallow PS when one of the following global conditions meets */
371 if (!wlc
->pub
->associated
|| !wlc
->PMenabled
|| wlc
->PM_override
)
374 /* disallow PS when one of these meets when not scanning */
375 if (!wlc
->PMblocked
) {
376 if (AP_ACTIVE(wlc
) || wlc
->monitor
)
380 FOREACH_AS_STA(wlc
, idx
, cfg
) {
381 /* disallow PS when one of the following bsscfg specific conditions meets */
382 if (!cfg
->BSS
|| !WLC_PORTOPEN(cfg
))
385 if (!cfg
->dtim_programmed
)
392 void BCMINITFN(wlc_reset
) (wlc_info_t
*wlc
)
394 WL_TRACE(("wl%d: wlc_reset\n", wlc
->pub
->unit
));
396 wlc
->check_for_unaligned_tbtt
= FALSE
;
398 /* slurp up hw mac counters before core reset */
399 if (WLC_UPDATE_STATS(wlc
)) {
402 /* reset our snapshot of macstat counters */
403 bzero((char *)wlc
->core
->macstat_snapshot
, sizeof(macstat_t
));
406 wlc_bmac_reset(wlc
->hw
);
407 wlc_ampdu_reset(wlc
->ampdu
);
411 /* Need to set a flag(to be cleared asynchronously by BMAC driver with high call)
412 * in order to prevent wlc_rpctx_txreclaim() from screwing wlc_rpctx_getnexttxp(),
413 * which could be invoked by already QUEUED high call(s) from BMAC driver before
414 * wlc_bmac_reset() finishes.
415 * It's not needed before in monolithic driver model because d11core interrupts would
416 * have been cleared instantly in wlc_bmac_reset() and no txstatus interrupt
417 * will come to driver to fetch those flushed dma pkt pointers.
419 wlc
->reset_bmac_pending
= TRUE
;
421 wlc_rpctx_txreclaim(wlc
->rpctx
);
423 wlc_stf_phy_txant_upd(wlc
);
424 wlc_phy_ant_rxdiv_set(wlc
->band
->pi
, wlc
->stf
->ant_rx_ovr
);
428 void wlc_fatal_error(wlc_info_t
*wlc
)
430 WL_ERROR(("wl%d: fatal error, reinitializing\n", wlc
->pub
->unit
));
434 /* Return the channel the driver should initialize during wlc_init.
435 * the channel may have to be changed from the currently configured channel
436 * if other configurations are in conflict (bandlocked, 11n mode disabled,
437 * invalid channel for current country, etc.)
439 static chanspec_t
BCMINITFN(wlc_init_chanspec
) (wlc_info_t
*wlc
)
441 chanspec_t chanspec
=
442 1 | WL_CHANSPEC_BW_20
| WL_CHANSPEC_CTL_SB_NONE
|
445 /* make sure the channel is on the supported band if we are band-restricted */
446 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
447 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
449 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
453 struct scb global_scb
;
455 static void wlc_init_scb(wlc_info_t
*wlc
, struct scb
*scb
)
458 scb
->flags
= SCB_WMECAP
| SCB_HTCAP
;
459 for (i
= 0; i
< NUMPRIO
; i
++)
463 void BCMINITFN(wlc_init
) (wlc_info_t
*wlc
)
468 wlc_bsscfg_t
*bsscfg
;
471 WL_TRACE(("wl%d: wlc_init\n", wlc
->pub
->unit
));
475 /* This will happen if a big-hammer was executed. In that case, we want to go back
476 * to the channel that we were on and not new channel
478 if (wlc
->pub
->associated
)
479 chanspec
= wlc
->home_chanspec
;
481 chanspec
= wlc_init_chanspec(wlc
);
483 wlc_bmac_init(wlc
->hw
, chanspec
, mute
);
485 wlc
->seckeys
= wlc_bmac_read_shm(wlc
->hw
, M_SECRXKEYS_PTR
) * 2;
486 if (D11REV_GE(wlc
->pub
->corerev
, 15) && (wlc
->machwcap
& MCAP_TKIPMIC
))
488 wlc_bmac_read_shm(wlc
->hw
, M_TKMICKEYS_PTR
) * 2;
490 /* update beacon listen interval */
493 (u8
) (wlc_bmac_read_shm(wlc
->hw
, M_NOSLPZNATDTIM
) >> 10);
494 ASSERT(wlc
->bcn_wait_prd
> 0);
496 /* the world is new again, so is our reported rate */
497 wlc_reprate_init(wlc
);
499 /* write ethernet address to core */
500 FOREACH_BSS(wlc
, i
, bsscfg
) {
502 wlc_set_bssid(bsscfg
);
505 /* Update tsf_cfprep if associated and up */
506 if (wlc
->pub
->associated
) {
507 FOREACH_BSS(wlc
, i
, bsscfg
) {
511 /* get beacon period from bsscfg and convert to uS */
512 bi
= bsscfg
->current_bss
->beacon_period
<< 10;
513 /* update the tsf_cfprep register */
514 /* since init path would reset to default value */
515 W_REG(wlc
->osh
, ®s
->tsf_cfprep
,
516 (bi
<< CFPREP_CBI_SHIFT
));
518 /* Update maccontrol PM related bits */
519 wlc_set_ps_ctrl(wlc
);
526 wlc_key_hw_init_all(wlc
);
528 wlc_bandinit_ordered(wlc
, chanspec
);
530 wlc_init_scb(wlc
, &global_scb
);
532 /* init probe response timeout */
533 wlc_write_shm(wlc
, M_PRS_MAXTIME
, wlc
->prb_resp_timeout
);
535 /* init max burst txop (framebursting) */
536 wlc_write_shm(wlc
, M_MBURST_TXOP
,
538 _rifs
? (EDCF_AC_VO_TXOP_AP
<< 5) : MAXFRAMEBURST_TXOP
));
540 /* initialize maximum allowed duty cycle */
541 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_ofdm
, TRUE
, TRUE
);
542 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_cck
, FALSE
, TRUE
);
544 /* Update some shared memory locations related to max AMPDU size allowed to received */
545 wlc_ampdu_shm_upd(wlc
->ampdu
);
547 /* band-specific inits */
550 /* Enable EDCF mode (while the MAC is suspended) */
551 if (EDCF_ENAB(wlc
->pub
)) {
552 OR_REG(wlc
->osh
, ®s
->ifs_ctl
, IFS_USEEDCF
);
553 wlc_edcf_setparams(wlc
->cfg
, FALSE
);
556 /* Init precedence maps for empty FIFOs */
557 wlc_tx_prec_map_init(wlc
);
559 /* read the ucode version if we have not yet done so */
560 if (wlc
->ucode_rev
== 0) {
562 wlc_read_shm(wlc
, M_BOM_REV_MAJOR
) << NBITS(u16
);
563 wlc
->ucode_rev
|= wlc_read_shm(wlc
, M_BOM_REV_MINOR
);
566 /* ..now really unleash hell (allow the MAC out of suspend) */
569 /* clear tx flow control */
570 wlc_txflowcontrol_reset(wlc
);
572 /* clear tx data fifo suspends */
573 wlc
->tx_suspended
= FALSE
;
575 /* enable the RF Disable Delay timer */
576 if (D11REV_GE(wlc
->pub
->corerev
, 10))
577 W_REG(wlc
->osh
, &wlc
->regs
->rfdisabledly
, RFDISABLE_DEFAULT
);
579 /* initialize mpc delay */
580 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
583 * Initialize WME parameters; if they haven't been set by some other
584 * mechanism (IOVar, etc) then read them from the hardware.
586 if (WLC_WME_RETRY_SHORT_GET(wlc
, 0) == 0) { /* Unintialized; read from HW */
590 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
591 wlc
->wme_retries
[ac
] =
592 wlc_read_shm(wlc
, M_AC_TXLMT_ADDR(ac
));
597 void wlc_mac_bcn_promisc_change(wlc_info_t
*wlc
, bool promisc
)
599 wlc
->bcnmisc_monitor
= promisc
;
600 wlc_mac_bcn_promisc(wlc
);
603 void wlc_mac_bcn_promisc(wlc_info_t
*wlc
)
605 if ((AP_ENAB(wlc
->pub
) && (N_ENAB(wlc
->pub
) || wlc
->band
->gmode
)) ||
606 wlc
->bcnmisc_ibss
|| wlc
->bcnmisc_scan
|| wlc
->bcnmisc_monitor
)
607 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, MCTL_BCNS_PROMISC
);
609 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, 0);
612 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
613 void wlc_mac_promisc(wlc_info_t
*wlc
)
615 u32 promisc_bits
= 0;
617 /* promiscuous mode just sets MCTL_PROMISC
618 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
619 * since all BSS data traffic is directed at the AP
621 if (PROMISC_ENAB(wlc
->pub
) && !AP_ENAB(wlc
->pub
) && !wlc
->wet
)
622 promisc_bits
|= MCTL_PROMISC
;
624 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
625 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
626 * handled in wlc_mac_bcn_promisc()
628 if (MONITOR_ENAB(wlc
))
629 promisc_bits
|= MCTL_PROMISC
| MCTL_KEEPCONTROL
;
631 wlc_mctrl(wlc
, MCTL_PROMISC
| MCTL_KEEPCONTROL
, promisc_bits
);
634 /* check if hps and wake states of sw and hw are in sync */
635 bool wlc_ps_check(wlc_info_t
*wlc
)
641 if (!AP_ACTIVE(wlc
)) {
643 tmp
= R_REG(wlc
->osh
, &wlc
->regs
->maccontrol
);
645 /* If deviceremoved is detected, then don't take any action as this can be called
646 * in any context. Assume that caller will take care of the condition. This is just
649 if (tmp
== 0xffffffff) {
650 WL_ERROR(("wl%d: %s: dead chip\n", wlc
->pub
->unit
,
652 return DEVICEREMOVED(wlc
);
655 hps
= PS_ALLOWED(wlc
);
657 if (hps
!= ((tmp
& MCTL_HPS
) != 0)) {
660 WL_ERROR(("wl%d: hps not sync, sw %d, maccontrol 0x%x\n", wlc
->pub
->unit
, hps
, tmp
));
661 FOREACH_BSS(wlc
, idx
, cfg
) {
662 if (!BSSCFG_STA(cfg
))
669 /* For a monolithic build the wake check can be exact since it looks at wake
670 * override bits. The MCTL_WAKE bit should match the 'wake' value.
672 wake
= STAY_AWAKE(wlc
) || wlc
->hw
->wake_override
;
673 wake_ok
= (wake
== ((tmp
& MCTL_WAKE
) != 0));
675 /* For a split build we will not have access to any wake overrides from the low
676 * level. The check can only make sure the MCTL_WAKE bit is on if the high
677 * level 'wake' value is true. If the high level 'wake' is false, the MCTL_WAKE
678 * may be either true or false due to the low level override.
680 wake
= STAY_AWAKE(wlc
);
681 wake_ok
= (wake
&& ((tmp
& MCTL_WAKE
) != 0)) || !wake
;
683 if (hps
&& !wake_ok
) {
684 WL_ERROR(("wl%d: wake not sync, sw %d maccontrol 0x%x\n", wlc
->pub
->unit
, wake
, tmp
));
692 /* push sw hps and wake state through hardware */
693 void wlc_set_ps_ctrl(wlc_info_t
*wlc
)
699 hps
= PS_ALLOWED(wlc
);
700 wake
= hps
? (STAY_AWAKE(wlc
)) : TRUE
;
702 WL_TRACE(("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n", wlc
->pub
->unit
,
705 v1
= R_REG(wlc
->osh
, &wlc
->regs
->maccontrol
);
712 wlc_mctrl(wlc
, MCTL_WAKE
| MCTL_HPS
, v2
);
714 awake_before
= ((v1
& MCTL_WAKE
) || ((v1
& MCTL_HPS
) == 0));
716 if (wake
&& !awake_before
)
717 wlc_bmac_wait_for_wake(wlc
->hw
);
722 * Write this BSS config's MAC address to core.
723 * Updates RXE match engine.
725 int wlc_set_mac(wlc_bsscfg_t
*cfg
)
728 wlc_info_t
*wlc
= cfg
->wlc
;
730 if (cfg
== wlc
->cfg
) {
731 /* enter the MAC addr into the RXE match registers */
732 wlc_set_addrmatch(wlc
, RCM_MAC_OFFSET
, &cfg
->cur_etheraddr
);
735 wlc_ampdu_macaddr_upd(wlc
);
740 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
741 * Updates RXE match engine.
743 void wlc_set_bssid(wlc_bsscfg_t
*cfg
)
745 wlc_info_t
*wlc
= cfg
->wlc
;
747 /* if primary config, we need to update BSSID in RXE match registers */
748 if (cfg
== wlc
->cfg
) {
749 wlc_set_addrmatch(wlc
, RCM_BSSID_OFFSET
, &cfg
->BSSID
);
751 #ifdef SUPPORT_HWKEYS
752 else if (BSSCFG_STA(cfg
) && cfg
->BSS
) {
753 wlc_rcmta_add_bssid(wlc
, cfg
);
759 * Suspend the the MAC and update the slot timing
760 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
762 void wlc_switch_shortslot(wlc_info_t
*wlc
, bool shortslot
)
767 ASSERT(wlc
->band
->gmode
);
769 /* use the override if it is set */
770 if (wlc
->shortslot_override
!= WLC_SHORTSLOT_AUTO
)
771 shortslot
= (wlc
->shortslot_override
== WLC_SHORTSLOT_ON
);
773 if (wlc
->shortslot
== shortslot
)
776 wlc
->shortslot
= shortslot
;
778 /* update the capability based on current shortslot mode */
779 FOREACH_BSS(wlc
, idx
, cfg
) {
780 if (!cfg
->associated
)
782 cfg
->current_bss
->capability
&= ~DOT11_CAP_SHORTSLOT
;
784 cfg
->current_bss
->capability
|= DOT11_CAP_SHORTSLOT
;
787 wlc_bmac_set_shortslot(wlc
->hw
, shortslot
);
790 static u8
wlc_local_constraint_qdbm(wlc_info_t
*wlc
)
795 local
= WLC_TXPWR_MAX
;
796 if (wlc
->pub
->associated
&&
797 (wf_chspec_ctlchan(wlc
->chanspec
) ==
798 wf_chspec_ctlchan(wlc
->home_chanspec
))) {
800 /* get the local power constraint if we are on the AP's
801 * channel [802.11h, 7.3.2.13]
803 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
805 (wlc
->txpwr_local_max
-
806 wlc
->txpwr_local_constraint
) * WLC_TXPWR_DB_FACTOR
;
807 if (local_max
> 0 && local_max
< WLC_TXPWR_MAX
)
808 return (u8
) local_max
;
816 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
817 void wlc_set_home_chanspec(wlc_info_t
*wlc
, chanspec_t chanspec
)
819 if (wlc
->home_chanspec
!= chanspec
) {
823 wlc
->home_chanspec
= chanspec
;
825 FOREACH_BSS(wlc
, idx
, cfg
) {
826 if (!cfg
->associated
)
828 cfg
->target_bss
->chanspec
= chanspec
;
829 cfg
->current_bss
->chanspec
= chanspec
;
835 static void wlc_set_phy_chanspec(wlc_info_t
*wlc
, chanspec_t chanspec
)
837 /* Save our copy of the chanspec */
838 wlc
->chanspec
= chanspec
;
840 /* Set the chanspec and power limits for this locale after computing
841 * any 11h local tx power constraints.
843 wlc_channel_set_chanspec(wlc
->cmi
, chanspec
,
844 wlc_local_constraint_qdbm(wlc
));
846 if (wlc
->stf
->ss_algosel_auto
)
847 wlc_stf_ss_algo_channel_get(wlc
, &wlc
->stf
->ss_algo_channel
,
850 wlc_stf_ss_update(wlc
, wlc
->band
);
854 void wlc_set_chanspec(wlc_info_t
*wlc
, chanspec_t chanspec
)
857 bool switchband
= FALSE
;
858 chanspec_t old_chanspec
= wlc
->chanspec
;
860 if (!wlc_valid_chanspec_db(wlc
->cmi
, chanspec
)) {
861 WL_ERROR(("wl%d: %s: Bad channel %d\n",
862 wlc
->pub
->unit
, __func__
, CHSPEC_CHANNEL(chanspec
)));
863 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
867 /* Switch bands if necessary */
868 if (NBANDS(wlc
) > 1) {
869 bandunit
= CHSPEC_WLCBANDUNIT(chanspec
);
870 if (wlc
->band
->bandunit
!= bandunit
|| wlc
->bandinit_pending
) {
872 if (wlc
->bandlocked
) {
873 WL_ERROR(("wl%d: %s: chspec %d band is locked!\n", wlc
->pub
->unit
, __func__
, CHSPEC_CHANNEL(chanspec
)));
876 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
877 * if the setband updates (wlc_bsinit) use low level calls to inspect and
878 * set state, the state inspected may be from the wrong band, or the
879 * following wlc_bmac_set_chanspec() may undo the work.
881 wlc_setband(wlc
, bandunit
);
885 ASSERT(N_ENAB(wlc
->pub
) || !CHSPEC_IS40(chanspec
));
887 /* sync up phy/radio chanspec */
888 wlc_set_phy_chanspec(wlc
, chanspec
);
890 /* init antenna selection */
891 if (CHSPEC_WLC_BW(old_chanspec
) != CHSPEC_WLC_BW(chanspec
)) {
892 if (WLANTSEL_ENAB(wlc
))
893 wlc_antsel_init(wlc
->asi
);
895 /* Fix the hardware rateset based on bw.
896 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
898 wlc_rateset_bw_mcs_filter(&wlc
->band
->hw_rateset
,
900 mimo_cap_40
? CHSPEC_WLC_BW(chanspec
)
904 /* update some mac configuration since chanspec changed */
905 wlc_ucode_mac_upd(wlc
);
909 static int wlc_get_current_txpwr(wlc_info_t
*wlc
, void *pwr
, uint len
)
911 txpwr_limits_t txpwr
;
913 tx_power_legacy_t
*old_power
= NULL
;
918 if (len
== sizeof(tx_power_legacy_t
))
919 old_power
= (tx_power_legacy_t
*) pwr
;
920 else if (len
< sizeof(tx_power_t
))
921 return BCME_BUFTOOSHORT
;
923 bzero(&power
, sizeof(tx_power_t
));
925 power
.chanspec
= WLC_BAND_PI_RADIO_CHANSPEC
;
926 if (wlc
->pub
->associated
)
927 power
.local_chanspec
= wlc
->home_chanspec
;
929 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
930 * public interface only implements getting and setting a single value for all of
931 * rates, so we need to fill the array ourselves.
933 wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
, &override
);
934 for (r
= 0; r
< WL_TX_POWER_RATES
; r
++) {
935 power
.user_limit
[r
] = (u8
) qdbm
;
938 power
.local_max
= wlc
->txpwr_local_max
* WLC_TXPWR_DB_FACTOR
;
939 power
.local_constraint
=
940 wlc
->txpwr_local_constraint
* WLC_TXPWR_DB_FACTOR
;
942 power
.antgain
[0] = wlc
->bandstate
[BAND_2G_INDEX
]->antgain
;
943 power
.antgain
[1] = wlc
->bandstate
[BAND_5G_INDEX
]->antgain
;
945 wlc_channel_reg_limits(wlc
->cmi
, power
.chanspec
, &txpwr
);
947 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
948 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
951 /* CCK tx power limits */
952 for (c
= 0, r
= WL_TX_POWER_CCK_FIRST
; c
< WL_TX_POWER_CCK_NUM
;
954 power
.reg_limit
[r
] = txpwr
.cck
[c
];
956 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
957 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
960 /* 20 MHz OFDM SISO tx power limits */
961 for (c
= 0, r
= WL_TX_POWER_OFDM_FIRST
; c
< WL_TX_POWER_OFDM_NUM
;
963 power
.reg_limit
[r
] = txpwr
.ofdm
[c
];
965 if (WLC_PHY_11N_CAP(wlc
->band
)) {
967 /* 20 MHz OFDM CDD tx power limits */
968 for (c
= 0, r
= WL_TX_POWER_OFDM20_CDD_FIRST
;
969 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
970 power
.reg_limit
[r
] = txpwr
.ofdm_cdd
[c
];
972 /* 40 MHz OFDM SISO tx power limits */
973 for (c
= 0, r
= WL_TX_POWER_OFDM40_SISO_FIRST
;
974 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
975 power
.reg_limit
[r
] = txpwr
.ofdm_40_siso
[c
];
977 /* 40 MHz OFDM CDD tx power limits */
978 for (c
= 0, r
= WL_TX_POWER_OFDM40_CDD_FIRST
;
979 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
980 power
.reg_limit
[r
] = txpwr
.ofdm_40_cdd
[c
];
982 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
983 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
986 /* 20MHz MCS0-7 SISO tx power limits */
987 for (c
= 0, r
= WL_TX_POWER_MCS20_SISO_FIRST
;
988 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
989 power
.reg_limit
[r
] = txpwr
.mcs_20_siso
[c
];
991 /* 20MHz MCS0-7 CDD tx power limits */
992 for (c
= 0, r
= WL_TX_POWER_MCS20_CDD_FIRST
;
993 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
994 power
.reg_limit
[r
] = txpwr
.mcs_20_cdd
[c
];
996 /* 20MHz MCS0-7 STBC tx power limits */
997 for (c
= 0, r
= WL_TX_POWER_MCS20_STBC_FIRST
;
998 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
999 power
.reg_limit
[r
] = txpwr
.mcs_20_stbc
[c
];
1001 /* 40MHz MCS0-7 SISO tx power limits */
1002 for (c
= 0, r
= WL_TX_POWER_MCS40_SISO_FIRST
;
1003 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
1004 power
.reg_limit
[r
] = txpwr
.mcs_40_siso
[c
];
1006 /* 40MHz MCS0-7 CDD tx power limits */
1007 for (c
= 0, r
= WL_TX_POWER_MCS40_CDD_FIRST
;
1008 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
1009 power
.reg_limit
[r
] = txpwr
.mcs_40_cdd
[c
];
1011 /* 40MHz MCS0-7 STBC tx power limits */
1012 for (c
= 0, r
= WL_TX_POWER_MCS40_STBC_FIRST
;
1013 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
1014 power
.reg_limit
[r
] = txpwr
.mcs_40_stbc
[c
];
1016 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
1017 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
1020 /* 20MHz MCS8-15 SDM tx power limits */
1021 for (c
= 0, r
= WL_TX_POWER_MCS20_SDM_FIRST
;
1022 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
1023 power
.reg_limit
[r
] = txpwr
.mcs_20_mimo
[c
];
1025 /* 40MHz MCS8-15 SDM tx power limits */
1026 for (c
= 0, r
= WL_TX_POWER_MCS40_SDM_FIRST
;
1027 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
1028 power
.reg_limit
[r
] = txpwr
.mcs_40_mimo
[c
];
1031 power
.reg_limit
[WL_TX_POWER_MCS_32
] = txpwr
.mcs32
;
1034 wlc_phy_txpower_get_current(wlc
->band
->pi
, &power
,
1035 CHSPEC_CHANNEL(power
.chanspec
));
1037 /* copy the tx_power_t struct to the return buffer,
1038 * or convert to a tx_power_legacy_t struct
1041 bcopy(&power
, pwr
, sizeof(tx_power_t
));
1043 int band_idx
= CHSPEC_IS2G(power
.chanspec
) ? 0 : 1;
1045 bzero(old_power
, sizeof(tx_power_legacy_t
));
1047 old_power
->txpwr_local_max
= power
.local_max
;
1048 old_power
->txpwr_local_constraint
= power
.local_constraint
;
1049 if (CHSPEC_IS2G(power
.chanspec
)) {
1050 old_power
->txpwr_chan_reg_max
= txpwr
.cck
[0];
1051 old_power
->txpwr_est_Pout
[band_idx
] =
1053 old_power
->txpwr_est_Pout_gofdm
= power
.est_Pout
[0];
1055 old_power
->txpwr_chan_reg_max
= txpwr
.ofdm
[0];
1056 old_power
->txpwr_est_Pout
[band_idx
] = power
.est_Pout
[0];
1058 old_power
->txpwr_antgain
[0] = power
.antgain
[0];
1059 old_power
->txpwr_antgain
[1] = power
.antgain
[1];
1061 for (r
= 0; r
< NUM_PWRCTRL_RATES
; r
++) {
1062 old_power
->txpwr_band_max
[r
] = power
.user_limit
[r
];
1063 old_power
->txpwr_limit
[r
] = power
.reg_limit
[r
];
1064 old_power
->txpwr_target
[band_idx
][r
] = power
.target
[r
];
1065 if (CHSPEC_IS2G(power
.chanspec
))
1066 old_power
->txpwr_bphy_cck_max
[r
] =
1067 power
.board_limit
[r
];
1069 old_power
->txpwr_aphy_max
[r
] =
1070 power
.board_limit
[r
];
1076 #endif /* defined(BCMDBG) */
1078 static u32
wlc_watchdog_backup_bi(wlc_info_t
*wlc
)
1081 bi
= 2 * wlc
->cfg
->current_bss
->dtim_period
*
1082 wlc
->cfg
->current_bss
->beacon_period
;
1083 if (wlc
->bcn_li_dtim
)
1084 bi
*= wlc
->bcn_li_dtim
;
1085 else if (wlc
->bcn_li_bcn
)
1086 /* recalculate bi based on bcn_li_bcn */
1087 bi
= 2 * wlc
->bcn_li_bcn
* wlc
->cfg
->current_bss
->beacon_period
;
1089 if (bi
< 2 * TIMER_INTERVAL_WATCHDOG
)
1090 bi
= 2 * TIMER_INTERVAL_WATCHDOG
;
1094 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1095 * Call watchdog from tbtt handler if tbtt is TRUE, watchdog timer otherwise.
1097 void wlc_watchdog_upd(wlc_info_t
*wlc
, bool tbtt
)
1099 /* make sure changing watchdog driver is allowed */
1100 if (!wlc
->pub
->up
|| !wlc
->pub
->align_wd_tbtt
)
1102 if (!tbtt
&& wlc
->WDarmed
) {
1103 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1104 wlc
->WDarmed
= FALSE
;
1107 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1108 if (tbtt
&& wlc
->WDarmed
) {
1109 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1110 wlc
->WDarmed
= FALSE
;
1111 wlc
->WDlast
= OSL_SYSUPTIME();
1113 /* arm watchdog timer and drive the watchdog there */
1114 else if (!tbtt
&& !wlc
->WDarmed
) {
1115 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
1117 wlc
->WDarmed
= TRUE
;
1119 if (tbtt
&& !wlc
->WDarmed
) {
1120 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, wlc_watchdog_backup_bi(wlc
),
1122 wlc
->WDarmed
= TRUE
;
1126 ratespec_t
wlc_lowest_basic_rspec(wlc_info_t
*wlc
, wlc_rateset_t
*rs
)
1128 ratespec_t lowest_basic_rspec
;
1131 /* Use the lowest basic rate */
1132 lowest_basic_rspec
= rs
->rates
[0] & RATE_MASK
;
1133 for (i
= 0; i
< rs
->count
; i
++) {
1134 if (rs
->rates
[i
] & WLC_RATE_FLAG
) {
1135 lowest_basic_rspec
= rs
->rates
[i
] & RATE_MASK
;
1140 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1141 if (IS_OFDM(lowest_basic_rspec
)) {
1142 lowest_basic_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
1146 return lowest_basic_rspec
;
1149 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1150 * setting as per this table:
1151 * ratespec CCK ant = wlc->stf->txant
1154 void wlc_beacon_phytxctl_txant_upd(wlc_info_t
*wlc
, ratespec_t bcn_rspec
)
1157 u16 phytxant
= wlc
->stf
->phytxant
;
1158 u16 mask
= PHY_TXC_ANT_MASK
;
1160 /* for non-siso rates or default setting, use the available chains */
1161 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1162 phytxant
= wlc_stf_phytxchain_sel(wlc
, bcn_rspec
);
1165 phyctl
= wlc_read_shm(wlc
, M_BCN_PCTLWD
);
1166 phyctl
= (phyctl
& ~mask
) | phytxant
;
1167 wlc_write_shm(wlc
, M_BCN_PCTLWD
, phyctl
);
1170 /* centralized protection config change function to simplify debugging, no consistency checking
1171 * this should be called only on changes to avoid overhead in periodic function
1173 void wlc_protection_upd(wlc_info_t
*wlc
, uint idx
, int val
)
1175 WL_TRACE(("wlc_protection_upd: idx %d, val %d\n", idx
, val
));
1178 case WLC_PROT_G_SPEC
:
1179 wlc
->protection
->_g
= (bool) val
;
1181 case WLC_PROT_G_OVR
:
1182 wlc
->protection
->g_override
= (s8
) val
;
1184 case WLC_PROT_G_USER
:
1185 wlc
->protection
->gmode_user
= (u8
) val
;
1187 case WLC_PROT_OVERLAP
:
1188 wlc
->protection
->overlap
= (s8
) val
;
1190 case WLC_PROT_N_USER
:
1191 wlc
->protection
->nmode_user
= (s8
) val
;
1193 case WLC_PROT_N_CFG
:
1194 wlc
->protection
->n_cfg
= (s8
) val
;
1196 case WLC_PROT_N_CFG_OVR
:
1197 wlc
->protection
->n_cfg_override
= (s8
) val
;
1199 case WLC_PROT_N_NONGF
:
1200 wlc
->protection
->nongf
= (bool) val
;
1202 case WLC_PROT_N_NONGF_OVR
:
1203 wlc
->protection
->nongf_override
= (s8
) val
;
1205 case WLC_PROT_N_PAM_OVR
:
1206 wlc
->protection
->n_pam_override
= (s8
) val
;
1208 case WLC_PROT_N_OBSS
:
1209 wlc
->protection
->n_obss
= (bool) val
;
1219 static void wlc_ht_update_sgi_rx(wlc_info_t
*wlc
, int val
)
1221 wlc
->ht_cap
.cap
&= ~(HT_CAP_SHORT_GI_20
| HT_CAP_SHORT_GI_40
);
1222 wlc
->ht_cap
.cap
|= (val
& WLC_N_SGI_20
) ? HT_CAP_SHORT_GI_20
: 0;
1223 wlc
->ht_cap
.cap
|= (val
& WLC_N_SGI_40
) ? HT_CAP_SHORT_GI_40
: 0;
1226 wlc_update_beacon(wlc
);
1227 wlc_update_probe_resp(wlc
, TRUE
);
1231 static void wlc_ht_update_ldpc(wlc_info_t
*wlc
, s8 val
)
1233 wlc
->stf
->ldpc
= val
;
1235 wlc
->ht_cap
.cap
&= ~HT_CAP_LDPC_CODING
;
1236 if (wlc
->stf
->ldpc
!= OFF
)
1237 wlc
->ht_cap
.cap
|= HT_CAP_LDPC_CODING
;
1240 wlc_update_beacon(wlc
);
1241 wlc_update_probe_resp(wlc
, TRUE
);
1242 wlc_phy_ldpc_override_set(wlc
->band
->pi
, (val
? TRUE
: FALSE
));
1247 * ucode, hwmac update
1248 * Channel dependent updates for ucode and hw
1250 static void wlc_ucode_mac_upd(wlc_info_t
*wlc
)
1252 /* enable or disable any active IBSSs depending on whether or not
1253 * we are on the home channel
1255 if (wlc
->home_chanspec
== WLC_BAND_PI_RADIO_CHANSPEC
) {
1256 if (wlc
->pub
->associated
) {
1257 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1258 * I think that the ucode inits set up the bcn templates and shm values
1259 * with a bogus beacon. This should not be done in the inits. If ucode needs
1260 * to set up a beacon for testing, the test routines should write it down,
1261 * not expect the inits to populate a bogus beacon.
1263 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1264 wlc_write_shm(wlc
, M_BCN_TXTSF_OFFSET
,
1265 wlc
->band
->bcntsfoff
);
1269 /* disable an active IBSS if we are not on the home channel */
1272 /* update the various promisc bits */
1273 wlc_mac_bcn_promisc(wlc
);
1274 wlc_mac_promisc(wlc
);
1277 static void wlc_bandinit_ordered(wlc_info_t
*wlc
, chanspec_t chanspec
)
1279 wlc_rateset_t default_rateset
;
1281 uint i
, band_order
[2];
1283 WL_TRACE(("wl%d: wlc_bandinit_ordered\n", wlc
->pub
->unit
));
1285 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1286 * figure out the right band to park on
1288 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
1289 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
1291 parkband
= wlc
->band
->bandunit
; /* updated in wlc_bandlock() */
1292 band_order
[0] = band_order
[1] = parkband
;
1294 /* park on the band of the specified chanspec */
1295 parkband
= CHSPEC_WLCBANDUNIT(chanspec
);
1297 /* order so that parkband initialize last */
1298 band_order
[0] = parkband
^ 1;
1299 band_order
[1] = parkband
;
1302 /* make each band operational, software state init */
1303 for (i
= 0; i
< NBANDS(wlc
); i
++) {
1304 uint j
= band_order
[i
];
1306 wlc
->band
= wlc
->bandstate
[j
];
1308 wlc_default_rateset(wlc
, &default_rateset
);
1310 /* fill in hw_rate */
1311 wlc_rateset_filter(&default_rateset
, &wlc
->band
->hw_rateset
,
1312 FALSE
, WLC_RATES_CCK_OFDM
, RATE_MASK
,
1313 (bool) N_ENAB(wlc
->pub
));
1315 /* init basic rate lookup */
1316 wlc_rate_lookup_init(wlc
, &default_rateset
);
1319 /* sync up phy/radio chanspec */
1320 wlc_set_phy_chanspec(wlc
, chanspec
);
1323 /* band-specific init */
1324 static void WLBANDINITFN(wlc_bsinit
) (wlc_info_t
*wlc
)
1326 WL_TRACE(("wl%d: wlc_bsinit: bandunit %d\n", wlc
->pub
->unit
,
1327 wlc
->band
->bandunit
));
1329 /* write ucode ACK/CTS rate table */
1330 wlc_set_ratetable(wlc
);
1332 /* update some band specific mac configuration */
1333 wlc_ucode_mac_upd(wlc
);
1335 /* init antenna selection */
1336 if (WLANTSEL_ENAB(wlc
))
1337 wlc_antsel_init(wlc
->asi
);
1341 /* switch to and initialize new band */
1342 static void WLBANDINITFN(wlc_setband
) (wlc_info_t
*wlc
, uint bandunit
)
1347 ASSERT(NBANDS(wlc
) > 1);
1348 ASSERT(!wlc
->bandlocked
);
1349 ASSERT(bandunit
!= wlc
->band
->bandunit
|| wlc
->bandinit_pending
);
1351 wlc
->band
= wlc
->bandstate
[bandunit
];
1356 /* wait for at least one beacon before entering sleeping state */
1357 wlc
->PMawakebcn
= TRUE
;
1358 FOREACH_AS_STA(wlc
, idx
, cfg
)
1359 cfg
->PMawakebcn
= TRUE
;
1360 wlc_set_ps_ctrl(wlc
);
1362 /* band-specific initializations */
1366 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1367 void wlc_wme_initparams_sta(wlc_info_t
*wlc
, wme_param_ie_t
*pe
)
1369 static const wme_param_ie_t stadef
= {
1372 WME_SUBTYPE_PARAM_IE
,
1377 {EDCF_AC_BE_ACI_STA
, EDCF_AC_BE_ECW_STA
,
1378 HTOL16(EDCF_AC_BE_TXOP_STA
)},
1379 {EDCF_AC_BK_ACI_STA
, EDCF_AC_BK_ECW_STA
,
1380 HTOL16(EDCF_AC_BK_TXOP_STA
)},
1381 {EDCF_AC_VI_ACI_STA
, EDCF_AC_VI_ECW_STA
,
1382 HTOL16(EDCF_AC_VI_TXOP_STA
)},
1383 {EDCF_AC_VO_ACI_STA
, EDCF_AC_VO_ECW_STA
,
1384 HTOL16(EDCF_AC_VO_TXOP_STA
)}
1388 ASSERT(sizeof(*pe
) == WME_PARAM_IE_LEN
);
1389 memcpy(pe
, &stadef
, sizeof(*pe
));
1392 void wlc_wme_setparams(wlc_info_t
*wlc
, u16 aci
, void *arg
, bool suspend
)
1395 shm_acparams_t acp_shm
;
1397 struct ieee80211_tx_queue_params
*params
= arg
;
1401 /* Only apply params if the core is out of reset and has clocks */
1403 WL_ERROR(("wl%d: %s : no-clock\n", wlc
->pub
->unit
, __func__
));
1408 * AP uses AC params from wme_param_ie_ap.
1409 * AP advertises AC params from wme_param_ie.
1410 * STA uses AC params from wme_param_ie.
1413 wlc
->wme_admctl
= 0;
1416 bzero((char *)&acp_shm
, sizeof(shm_acparams_t
));
1417 /* find out which ac this set of params applies to */
1418 ASSERT(aci
< AC_COUNT
);
1419 /* set the admission control policy for this AC */
1420 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1422 /* fill in shm ac params struct */
1423 acp_shm
.txop
= ltoh16(params
->txop
);
1424 /* convert from units of 32us to us for ucode */
1425 wlc
->edcf_txop
[aci
& 0x3] = acp_shm
.txop
=
1426 EDCF_TXOP2USEC(acp_shm
.txop
);
1427 acp_shm
.aifs
= (params
->aifs
& EDCF_AIFSN_MASK
);
1429 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1430 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1433 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1434 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1435 WL_ERROR(("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1436 wlc
->pub
->unit
, acp_shm
.aifs
));
1440 acp_shm
.cwmin
= params
->cw_min
;
1441 acp_shm
.cwmax
= params
->cw_max
;
1442 acp_shm
.cwcur
= acp_shm
.cwmin
;
1444 R_REG(wlc
->osh
, &wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1445 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1446 /* Indicate the new params to the ucode */
1447 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1448 wme_shmemacindex(aci
) *
1450 M_EDCF_STATUS_OFF
));
1451 acp_shm
.status
|= WME_STATUS_NEWAC
;
1453 /* Fill in shm acparam table */
1454 shm_entry
= (u16
*) &acp_shm
;
1455 for (i
= 0; i
< (int)sizeof(shm_acparams_t
); i
+= 2)
1458 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ i
,
1464 wlc_suspend_mac_and_wait(wlc
);
1467 wlc_enable_mac(wlc
);
1471 void wlc_edcf_setparams(wlc_bsscfg_t
*cfg
, bool suspend
)
1473 wlc_info_t
*wlc
= cfg
->wlc
;
1475 edcf_acparam_t
*edcf_acp
;
1476 shm_acparams_t acp_shm
;
1482 /* Only apply params if the core is out of reset and has clocks */
1487 * AP uses AC params from wme_param_ie_ap.
1488 * AP advertises AC params from wme_param_ie.
1489 * STA uses AC params from wme_param_ie.
1492 edcf_acp
= (edcf_acparam_t
*) &wlc
->wme_param_ie
.acparam
[0];
1494 wlc
->wme_admctl
= 0;
1496 for (i
= 0; i
< AC_COUNT
; i
++, edcf_acp
++) {
1497 bzero((char *)&acp_shm
, sizeof(shm_acparams_t
));
1498 /* find out which ac this set of params applies to */
1499 aci
= (edcf_acp
->ACI
& EDCF_ACI_MASK
) >> EDCF_ACI_SHIFT
;
1500 ASSERT(aci
< AC_COUNT
);
1501 /* set the admission control policy for this AC */
1502 if (edcf_acp
->ACI
& EDCF_ACM_MASK
) {
1503 wlc
->wme_admctl
|= 1 << aci
;
1506 /* fill in shm ac params struct */
1507 acp_shm
.txop
= ltoh16(edcf_acp
->TXOP
);
1508 /* convert from units of 32us to us for ucode */
1509 wlc
->edcf_txop
[aci
] = acp_shm
.txop
=
1510 EDCF_TXOP2USEC(acp_shm
.txop
);
1511 acp_shm
.aifs
= (edcf_acp
->ACI
& EDCF_AIFSN_MASK
);
1513 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1514 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1517 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1518 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1519 WL_ERROR(("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1520 wlc
->pub
->unit
, acp_shm
.aifs
));
1524 /* CWmin = 2^(ECWmin) - 1 */
1525 acp_shm
.cwmin
= EDCF_ECW2CW(edcf_acp
->ECW
& EDCF_ECWMIN_MASK
);
1526 /* CWmax = 2^(ECWmax) - 1 */
1527 acp_shm
.cwmax
= EDCF_ECW2CW((edcf_acp
->ECW
& EDCF_ECWMAX_MASK
)
1528 >> EDCF_ECWMAX_SHIFT
);
1529 acp_shm
.cwcur
= acp_shm
.cwmin
;
1531 R_REG(wlc
->osh
, &wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1532 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1533 /* Indicate the new params to the ucode */
1534 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1535 wme_shmemacindex(aci
) *
1537 M_EDCF_STATUS_OFF
));
1538 acp_shm
.status
|= WME_STATUS_NEWAC
;
1540 /* Fill in shm acparam table */
1541 shm_entry
= (u16
*) &acp_shm
;
1542 for (j
= 0; j
< (int)sizeof(shm_acparams_t
); j
+= 2)
1545 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ j
,
1550 wlc_suspend_mac_and_wait(wlc
);
1552 if (AP_ENAB(wlc
->pub
) && WME_ENAB(wlc
->pub
)) {
1553 wlc_update_beacon(wlc
);
1554 wlc_update_probe_resp(wlc
, FALSE
);
1558 wlc_enable_mac(wlc
);
1562 bool BCMATTACHFN(wlc_timers_init
) (wlc_info_t
*wlc
, int unit
)
1564 wlc
->wdtimer
= wl_init_timer(wlc
->wl
, wlc_watchdog_by_timer
,
1566 if (!wlc
->wdtimer
) {
1567 WL_ERROR(("wl%d: wl_init_timer for wdtimer failed\n", unit
));
1571 wlc
->radio_timer
= wl_init_timer(wlc
->wl
, wlc_radio_timer
,
1573 if (!wlc
->radio_timer
) {
1574 WL_ERROR(("wl%d: wl_init_timer for radio_timer failed\n",
1586 * Initialize wlc_info default values ...
1587 * may get overrides later in this function
1589 void BCMATTACHFN(wlc_info_init
) (wlc_info_t
*wlc
, int unit
)
1592 /* Assume the device is there until proven otherwise */
1593 wlc
->device_present
= TRUE
;
1595 /* set default power output percentage to 100 percent */
1596 wlc
->txpwr_percent
= 100;
1598 /* Save our copy of the chanspec */
1599 wlc
->chanspec
= CH20MHZ_CHSPEC(1);
1601 /* initialize CCK preamble mode to unassociated state */
1602 wlc
->shortpreamble
= FALSE
;
1604 wlc
->legacy_probe
= TRUE
;
1606 /* various 802.11g modes */
1607 wlc
->shortslot
= FALSE
;
1608 wlc
->shortslot_override
= WLC_SHORTSLOT_AUTO
;
1610 wlc
->barker_overlap_control
= TRUE
;
1611 wlc
->barker_preamble
= WLC_BARKER_SHORT_ALLOWED
;
1612 wlc
->txburst_limit_override
= AUTO
;
1614 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, WLC_PROTECTION_AUTO
);
1615 wlc_protection_upd(wlc
, WLC_PROT_G_SPEC
, FALSE
);
1617 wlc_protection_upd(wlc
, WLC_PROT_N_CFG_OVR
, WLC_PROTECTION_AUTO
);
1618 wlc_protection_upd(wlc
, WLC_PROT_N_CFG
, WLC_N_PROTECTION_OFF
);
1619 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF_OVR
, WLC_PROTECTION_AUTO
);
1620 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF
, FALSE
);
1621 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
, AUTO
);
1623 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, WLC_PROTECTION_CTL_OVERLAP
);
1625 /* 802.11g draft 4.0 NonERP elt advertisement */
1626 wlc
->include_legacy_erp
= TRUE
;
1628 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_DEF
;
1629 wlc
->stf
->txant
= ANT_TX_DEF
;
1631 wlc
->prb_resp_timeout
= WLC_PRB_RESP_TIMEOUT
;
1633 wlc
->usr_fragthresh
= DOT11_DEFAULT_FRAG_LEN
;
1634 for (i
= 0; i
< NFIFO
; i
++)
1635 wlc
->fragthresh
[i
] = DOT11_DEFAULT_FRAG_LEN
;
1636 wlc
->RTSThresh
= DOT11_DEFAULT_RTS_LEN
;
1638 /* default rate fallback retry limits */
1639 wlc
->SFBL
= RETRY_SHORT_FB
;
1640 wlc
->LFBL
= RETRY_LONG_FB
;
1642 /* default mac retry limits */
1643 wlc
->SRL
= RETRY_SHORT_DEF
;
1644 wlc
->LRL
= RETRY_LONG_DEF
;
1647 wlc
->PM
= PM_OFF
; /* User's setting of PM mode through IOCTL */
1648 wlc
->PM_override
= FALSE
; /* Prevents from going to PM if our AP is 'ill' */
1649 wlc
->PMenabled
= FALSE
; /* Current PM state */
1650 wlc
->PMpending
= FALSE
; /* Tracks whether STA indicated PM in the last attempt */
1651 wlc
->PMblocked
= FALSE
; /* To allow blocking going into PM during RM and scans */
1653 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1654 wlc
->WME_PM_blocked
= FALSE
;
1656 /* Init wme queuing method */
1657 wlc
->wme_prec_queuing
= FALSE
;
1659 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1661 /* Are we waiting for a response to PS-Poll that we sent */
1662 wlc
->PSpoll
= FALSE
;
1665 wlc
->wme_apsd
= TRUE
;
1666 wlc
->apsd_sta_usp
= FALSE
;
1667 wlc
->apsd_trigger_timeout
= 0; /* disable the trigger timer */
1668 wlc
->apsd_trigger_ac
= AC_BITMAP_ALL
;
1670 /* Set flag to indicate that hw keys should be used when available. */
1671 wlc
->wsec_swkeys
= FALSE
;
1673 /* init the 4 static WEP default keys */
1674 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
1675 wlc
->wsec_keys
[i
] = wlc
->wsec_def_keys
[i
];
1676 wlc
->wsec_keys
[i
]->idx
= (u8
) i
;
1679 wlc
->_regulatory_domain
= FALSE
; /* 802.11d */
1681 /* WME QoS mode is Auto by default */
1682 wlc
->pub
->_wme
= AUTO
;
1684 #ifdef BCMSDIODEV_ENABLED
1685 wlc
->pub
->_priofc
= TRUE
; /* enable priority flow control for sdio dongle */
1688 wlc
->pub
->_ampdu
= AMPDU_AGG_HOST
;
1689 wlc
->pub
->bcmerror
= 0;
1690 wlc
->ibss_allowed
= TRUE
;
1691 wlc
->ibss_coalesce_allowed
= TRUE
;
1692 wlc
->pub
->_coex
= ON
;
1694 /* intialize mpc delay */
1695 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
1697 wlc
->pr80838_war
= TRUE
;
1700 static bool wlc_state_bmac_sync(wlc_info_t
*wlc
)
1702 wlc_bmac_state_t state_bmac
;
1704 if (wlc_bmac_state_get(wlc
->hw
, &state_bmac
) != 0)
1707 wlc
->machwcap
= state_bmac
.machwcap
;
1708 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
,
1709 (s8
) state_bmac
.preamble_ovr
);
1714 static uint
BCMATTACHFN(wlc_attach_module
) (wlc_info_t
*wlc
)
1718 unit
= wlc
->pub
->unit
;
1720 wlc
->asi
= wlc_antsel_attach(wlc
, wlc
->osh
, wlc
->pub
, wlc
->hw
);
1721 if (wlc
->asi
== NULL
) {
1722 WL_ERROR(("wl%d: wlc_attach: wlc_antsel_attach failed\n",
1728 wlc
->ampdu
= wlc_ampdu_attach(wlc
);
1729 if (wlc
->ampdu
== NULL
) {
1730 WL_ERROR(("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit
));
1735 /* Initialize event queue; needed before following calls */
1737 wlc_eventq_attach(wlc
->pub
, wlc
, wlc
->wl
, wlc_process_eventq
);
1738 if (wlc
->eventq
== NULL
) {
1739 WL_ERROR(("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit
));
1744 if ((wlc_stf_attach(wlc
) != 0)) {
1745 WL_ERROR(("wl%d: wlc_attach: wlc_stf_attach failed\n", unit
));
1753 wlc_pub_t
*wlc_pub(void *wlc
)
1755 return ((wlc_info_t
*) wlc
)->pub
;
1758 #define CHIP_SUPPORTS_11N(wlc) 1
1761 * The common driver entry routine. Error codes should be unique
1763 void *BCMATTACHFN(wlc_attach
) (void *wl
, u16 vendor
, u16 device
,
1764 uint unit
, bool piomode
, osl_t
*osh
,
1765 void *regsva
, uint bustype
, void *btparam
,
1774 WL_NONE(("wl%d: %s: vendor 0x%x device 0x%x\n", unit
, __func__
, vendor
,
1777 ASSERT(WSEC_MAX_RCMTA_KEYS
<= WSEC_MAX_KEYS
);
1778 ASSERT(WSEC_MAX_DEFAULT_KEYS
== WLC_DEFAULT_KEYS
);
1780 /* some code depends on packed structures */
1781 ASSERT(sizeof(struct ether_addr
) == ETHER_ADDR_LEN
);
1782 ASSERT(sizeof(struct ether_header
) == ETHER_HDR_LEN
);
1783 ASSERT(sizeof(d11regs_t
) == SI_CORE_SIZE
);
1784 ASSERT(sizeof(ofdm_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1785 ASSERT(sizeof(cck_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1786 ASSERT(sizeof(d11txh_t
) == D11_TXH_LEN
);
1787 ASSERT(sizeof(d11rxhdr_t
) == RXHDR_LEN
);
1788 ASSERT(sizeof(struct dot11_header
) == DOT11_A4_HDR_LEN
);
1789 ASSERT(sizeof(struct dot11_rts_frame
) == DOT11_RTS_LEN
);
1790 ASSERT(sizeof(struct dot11_management_header
) == DOT11_MGMT_HDR_LEN
);
1791 ASSERT(sizeof(struct dot11_bcn_prb
) == DOT11_BCN_PRB_LEN
);
1792 ASSERT(sizeof(tx_status_t
) == TXSTATUS_LEN
);
1793 ASSERT(sizeof(ht_cap_ie_t
) == HT_CAP_IE_LEN
);
1794 ASSERT(OFFSETOF(wl_scan_params_t
, channel_list
) ==
1795 WL_SCAN_PARAMS_FIXED_SIZE
);
1796 ASSERT(ISALIGNED(OFFSETOF(wsec_key_t
, data
), sizeof(u32
)));
1797 ASSERT(ISPOWEROF2(MA_WINDOW_SZ
));
1799 ASSERT(sizeof(wlc_d11rxhdr_t
) <= WL_HWRXOFF
);
1802 * Number of replay counters value used in WPA IE must match # rxivs
1803 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1804 * 'RSN Information Element' figure 8 for this mapping.
1806 ASSERT((WPA_CAP_16_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1807 && 16 == WLC_NUMRXIVS
)
1808 || (WPA_CAP_4_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1809 && 4 == WLC_NUMRXIVS
));
1811 /* allocate wlc_info_t state and its substructures */
1812 wlc
= (wlc_info_t
*) wlc_attach_malloc(osh
, unit
, &err
, device
);
1822 wlc
->band
= wlc
->bandstate
[0];
1823 wlc
->core
= wlc
->corestate
;
1827 wlc
->btparam
= btparam
;
1828 pub
->_piomode
= piomode
;
1829 wlc
->bandinit_pending
= FALSE
;
1830 /* By default restrict TKIP associations from 11n STA's */
1831 wlc
->ht_wsec_restriction
= WLC_HT_TKIP_RESTRICT
;
1833 /* populate wlc_info_t with default values */
1834 wlc_info_init(wlc
, unit
);
1836 /* update sta/ap related parameters */
1839 /* 11n_disable nvram */
1840 n_disabled
= getintvar(pub
->vars
, "11n_disable");
1842 /* register a module (to handle iovars) */
1843 wlc_module_register(wlc
->pub
, wlc_iovars
, "wlc_iovars", wlc
,
1844 wlc_doiovar
, NULL
, NULL
);
1846 /* low level attach steps(all hw accesses go inside, no more in rest of the attach) */
1847 err
= wlc_bmac_attach(wlc
, vendor
, device
, unit
, piomode
, osh
, regsva
,
1852 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1853 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1855 if (!wlc_state_bmac_sync(wlc
)) {
1860 pub
->phy_11ncapable
= WLC_PHY_11N_CAP(wlc
->band
);
1862 /* propagate *vars* from BMAC driver to high driver */
1863 wlc_bmac_copyfrom_vars(wlc
->hw
, &pub
->vars
, &wlc
->vars_size
);
1865 #ifdef WLC_HIGH_ONLY
1866 WL_TRACE(("nvram : vars %p , vars_size %d\n", pub
->vars
,
1870 /* set maximum allowed duty cycle */
1871 wlc
->tx_duty_cycle_ofdm
=
1872 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_ofdm");
1873 wlc
->tx_duty_cycle_cck
=
1874 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_cck");
1876 wlc_stf_phy_chain_calc(wlc
);
1878 /* txchain 1: txant 0, txchain 2: txant 1 */
1879 if (WLCISNPHY(wlc
->band
) && (wlc
->stf
->txstreams
== 1))
1880 wlc
->stf
->txant
= wlc
->stf
->hw_txchain
- 1;
1882 /* push to BMAC driver */
1883 wlc_phy_stf_chain_init(wlc
->band
->pi
, wlc
->stf
->hw_txchain
,
1884 wlc
->stf
->hw_rxchain
);
1887 /* pull up some info resulting from the low attach */
1890 for (i
= 0; i
< NFIFO
; i
++)
1891 wlc
->core
->txavail
[i
] = wlc
->hw
->txavail
[i
];
1893 #endif /* WLC_LOW */
1895 wlc_bmac_hw_etheraddr(wlc
->hw
, &wlc
->perm_etheraddr
);
1897 bcopy((char *)&wlc
->perm_etheraddr
, (char *)&pub
->cur_etheraddr
,
1900 for (j
= 0; j
< NBANDS(wlc
); j
++) {
1901 /* Use band 1 for single band 11a */
1902 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
1905 wlc
->band
= wlc
->bandstate
[j
];
1907 if (!wlc_attach_stf_ant_init(wlc
)) {
1912 /* default contention windows size limits */
1913 wlc
->band
->CWmin
= APHY_CWMIN
;
1914 wlc
->band
->CWmax
= PHY_CWMAX
;
1916 /* init gmode value */
1917 if (BAND_2G(wlc
->band
->bandtype
)) {
1918 wlc
->band
->gmode
= GMODE_AUTO
;
1919 wlc_protection_upd(wlc
, WLC_PROT_G_USER
,
1923 /* init _n_enab supported mode */
1924 if (WLC_PHY_11N_CAP(wlc
->band
) && CHIP_SUPPORTS_11N(wlc
)) {
1925 if (n_disabled
& WLFEATURE_DISABLE_11N
) {
1927 wlc_protection_upd(wlc
, WLC_PROT_N_USER
, OFF
);
1929 pub
->_n_enab
= SUPPORT_11N
;
1930 wlc_protection_upd(wlc
, WLC_PROT_N_USER
,
1932 SUPPORT_11N
) ? WL_11N_2x2
:
1937 /* init per-band default rateset, depend on band->gmode */
1938 wlc_default_rateset(wlc
, &wlc
->band
->defrateset
);
1940 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1941 wlc_rateset_filter(&wlc
->band
->defrateset
,
1942 &wlc
->band
->hw_rateset
, FALSE
,
1943 WLC_RATES_CCK_OFDM
, RATE_MASK
,
1944 (bool) N_ENAB(wlc
->pub
));
1947 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1948 wlc_stf_phy_txant_upd(wlc
);
1950 /* attach each modules */
1951 err
= wlc_attach_module(wlc
);
1955 if (!wlc_timers_init(wlc
, unit
)) {
1956 WL_ERROR(("wl%d: %s: wlc_init_timer failed\n", unit
, __func__
));
1961 /* depend on rateset, gmode */
1962 wlc
->cmi
= wlc_channel_mgr_attach(wlc
);
1964 WL_ERROR(("wl%d: %s: wlc_channel_mgr_attach failed\n", unit
,
1970 /* init default when all parameters are ready, i.e. ->rateset */
1971 wlc_bss_default_init(wlc
);
1974 * Complete the wlc default state initializations..
1977 /* allocate our initial queue */
1978 qi
= wlc_txq_alloc(wlc
, osh
);
1980 WL_ERROR(("wl%d: %s: failed to malloc tx queue\n", unit
,
1985 wlc
->active_queue
= qi
;
1987 wlc
->bsscfg
[0] = wlc
->cfg
;
1989 wlc
->cfg
->wlc
= wlc
;
1990 pub
->txmaxpkts
= MAXTXPKTS
;
1992 WLCNTSET(pub
->_cnt
->version
, WL_CNT_T_VERSION
);
1993 WLCNTSET(pub
->_cnt
->length
, sizeof(wl_cnt_t
));
1995 WLCNTSET(pub
->_wme_cnt
->version
, WL_WME_CNT_VERSION
);
1996 WLCNTSET(pub
->_wme_cnt
->length
, sizeof(wl_wme_cnt_t
));
1998 wlc_wme_initparams_sta(wlc
, &wlc
->wme_param_ie
);
2000 wlc
->mimoft
= FT_HT
;
2001 wlc
->ht_cap
.cap
= HT_CAP
;
2002 if (HT_ENAB(wlc
->pub
))
2003 wlc
->stf
->ldpc
= AUTO
;
2005 wlc
->mimo_40txbw
= AUTO
;
2006 wlc
->ofdm_40txbw
= AUTO
;
2007 wlc
->cck_40txbw
= AUTO
;
2008 wlc_update_mimo_band_bwcap(wlc
, WLC_N_BW_20IN2G_40IN5G
);
2010 /* Enable setting the RIFS Mode bit by default in HT Info IE */
2011 wlc
->rifs_advert
= AUTO
;
2013 /* Set default values of SGI */
2014 if (WLC_SGI_CAP_PHY(wlc
)) {
2015 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
2017 } else if (WLCISSSLPNPHY(wlc
->band
)) {
2018 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
2021 wlc_ht_update_sgi_rx(wlc
, 0);
2025 /* *******nvram 11n config overrides Start ********* */
2027 /* apply the sgi override from nvram conf */
2028 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_TX
)
2031 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_RX
)
2032 wlc_ht_update_sgi_rx(wlc
, 0);
2034 /* apply the stbc override from nvram conf */
2035 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_TX
) {
2036 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= OFF
;
2037 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= OFF
;
2038 wlc
->ht_cap
.cap
&= ~HT_CAP_TX_STBC
;
2040 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_RX
)
2041 wlc_stf_stbc_rx_set(wlc
, HT_CAP_RX_STBC_NO
);
2043 /* apply the GF override from nvram conf */
2044 if (n_disabled
& WLFEATURE_DISABLE_11N_GF
)
2045 wlc
->ht_cap
.cap
&= ~HT_CAP_GF
;
2047 /* initialize radio_mpc_disable according to wlc->mpc */
2048 wlc_radio_mpc_upd(wlc
);
2050 if (WLANTSEL_ENAB(wlc
)) {
2051 if ((CHIPID(wlc
->pub
->sih
->chip
)) == BCM43235_CHIP_ID
) {
2052 if ((getintvar(wlc
->pub
->vars
, "aa2g") == 7) ||
2053 (getintvar(wlc
->pub
->vars
, "aa5g") == 7)) {
2054 wlc_bmac_antsel_set(wlc
->hw
, 1);
2057 wlc_bmac_antsel_set(wlc
->hw
, wlc
->asi
->antsel_avail
);
2067 WL_ERROR(("wl%d: %s: failed with err %d\n", unit
, __func__
, err
));
2076 static void BCMNMIATTACHFN(wlc_attach_antgain_init
) (wlc_info_t
*wlc
)
2079 unit
= wlc
->pub
->unit
;
2081 if ((wlc
->band
->antgain
== -1) && (wlc
->pub
->sromrev
== 1)) {
2082 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2083 wlc
->band
->antgain
= 8;
2084 } else if (wlc
->band
->antgain
== -1) {
2085 WL_ERROR(("wl%d: %s: Invalid antennas available in srom, using 2dB\n", unit
, __func__
));
2086 wlc
->band
->antgain
= 8;
2089 /* Older sroms specified gain in whole dbm only. In order
2090 * be able to specify qdbm granularity and remain backward compatible
2091 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2092 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2093 * -32 - 31. Examples: 0x1 = 1 db,
2094 * 0xc1 = 1.75 db (1 + 3 quarters),
2095 * 0x3f = -1 (-1 + 0 quarters),
2096 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2097 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2099 gain
= wlc
->band
->antgain
& 0x3f;
2100 gain
<<= 2; /* Sign extend */
2102 fract
= (wlc
->band
->antgain
& 0xc0) >> 6;
2103 wlc
->band
->antgain
= 4 * gain
+ fract
;
2107 static bool BCMATTACHFN(wlc_attach_stf_ant_init
) (wlc_info_t
*wlc
)
2114 unit
= wlc
->pub
->unit
;
2115 vars
= wlc
->pub
->vars
;
2116 bandtype
= wlc
->band
->bandtype
;
2118 /* get antennas available */
2119 aa
= (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "aa5g" : "aa2g"));
2121 aa
= (s8
) getintvar(vars
,
2122 (BAND_5G(bandtype
) ? "aa1" : "aa0"));
2123 if ((aa
< 1) || (aa
> 15)) {
2124 WL_ERROR(("wl%d: %s: Invalid antennas available in srom (0x%x), using 3.\n", unit
, __func__
, aa
));
2128 /* reset the defaults if we have a single antenna */
2130 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_0
;
2131 wlc
->stf
->txant
= ANT_TX_FORCE_0
;
2132 } else if (aa
== 2) {
2133 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_1
;
2134 wlc
->stf
->txant
= ANT_TX_FORCE_1
;
2138 /* Compute Antenna Gain */
2139 wlc
->band
->antgain
=
2140 (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "ag1" : "ag0"));
2141 wlc_attach_antgain_init(wlc
);
2146 #ifdef WLC_HIGH_ONLY
2147 /* HIGH_ONLY bmac_attach, which sync over LOW_ONLY bmac_attach states */
2149 BCMATTACHFN(wlc_bmac_attach
) (wlc_info_t
*wlc
, u16 vendor
, u16 device
,
2150 uint unit
, bool piomode
, osl_t
*osh
,
2151 void *regsva
, uint bustype
, void *btparam
) {
2152 wlc_bmac_revinfo_t revinfo
;
2154 rpc_info_t
*rpc
= (rpc_info_t
*) btparam
;
2156 ASSERT(bustype
== RPC_BUS
);
2158 /* install the rpc handle in the various state structures used by stub RPC functions */
2165 wlc
->rpctx
= wlc_rpctx_attach(wlc
->pub
, wlc
);
2166 if (wlc
->rpctx
== NULL
)
2171 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
2173 /* Always initialized */
2174 ASSERT(NRPCTXBUFPOST
<= NTXD
);
2175 wlc_rpctx_fifoinit(wlc
->rpctx
, TX_DATA_FIFO
, NRPCTXBUFPOST
);
2176 wlc_rpctx_fifoinit(wlc
->rpctx
, TX_CTL_FIFO
, NRPCTXBUFPOST
);
2177 wlc_rpctx_fifoinit(wlc
->rpctx
, TX_BCMC_FIFO
, NRPCTXBUFPOST
);
2179 /* VI and BK inited only if WME */
2180 if (WME_ENAB(wlc
->pub
)) {
2181 wlc_rpctx_fifoinit(wlc
->rpctx
, TX_AC_BK_FIFO
, NRPCTXBUFPOST
);
2182 wlc_rpctx_fifoinit(wlc
->rpctx
, TX_AC_VI_FIFO
, NRPCTXBUFPOST
);
2185 /* Allocate SB handle */
2186 wlc
->pub
->sih
= osl_malloc(wlc
->osh
, sizeof(si_t
));
2189 bzero(wlc
->pub
->sih
, sizeof(si_t
));
2191 /* sync up revinfo with BMAC */
2192 bzero(&revinfo
, sizeof(wlc_bmac_revinfo_t
));
2193 if (wlc_bmac_revinfo_get(wlc
->hw
, &revinfo
) != 0)
2195 wlc
->vendorid
= (u16
) revinfo
.vendorid
;
2196 wlc
->deviceid
= (u16
) revinfo
.deviceid
;
2198 wlc
->pub
->boardrev
= (u16
) revinfo
.boardrev
;
2199 wlc
->pub
->corerev
= revinfo
.corerev
;
2200 wlc
->pub
->sromrev
= (u8
) revinfo
.sromrev
;
2201 wlc
->pub
->sih
->chiprev
= revinfo
.chiprev
;
2202 wlc
->pub
->sih
->chip
= revinfo
.chip
;
2203 wlc
->pub
->sih
->chippkg
= revinfo
.chippkg
;
2204 wlc
->pub
->sih
->boardtype
= revinfo
.boardtype
;
2205 wlc
->pub
->sih
->boardvendor
= revinfo
.boardvendor
;
2206 wlc
->pub
->sih
->bustype
= revinfo
.bustype
;
2207 wlc
->pub
->sih
->buscoretype
= revinfo
.buscoretype
;
2208 wlc
->pub
->sih
->buscorerev
= revinfo
.buscorerev
;
2209 wlc
->pub
->sih
->issim
= (bool) revinfo
.issim
;
2210 wlc
->pub
->sih
->rpc
= rpc
;
2212 if (revinfo
.nbands
== 0 || revinfo
.nbands
> 2)
2214 wlc
->pub
->_nbands
= revinfo
.nbands
;
2216 for (idx
= 0; idx
< wlc
->pub
->_nbands
; idx
++) {
2217 uint bandunit
, bandtype
; /* To access bandstate */
2218 wlc_phy_t
*pi
= osl_malloc(wlc
->osh
, sizeof(wlc_phy_t
));
2222 bzero(pi
, sizeof(wlc_phy_t
));
2225 bandunit
= revinfo
.band
[idx
].bandunit
;
2226 bandtype
= revinfo
.band
[idx
].bandtype
;
2227 wlc
->bandstate
[bandunit
]->radiorev
=
2228 (u8
) revinfo
.band
[idx
].radiorev
;
2229 wlc
->bandstate
[bandunit
]->phytype
=
2230 (u16
) revinfo
.band
[idx
].phytype
;
2231 wlc
->bandstate
[bandunit
]->phyrev
=
2232 (u16
) revinfo
.band
[idx
].phyrev
;
2233 wlc
->bandstate
[bandunit
]->radioid
=
2234 (u16
) revinfo
.band
[idx
].radioid
;
2235 wlc
->bandstate
[bandunit
]->abgphy_encore
=
2236 revinfo
.band
[idx
].abgphy_encore
;
2238 wlc
->bandstate
[bandunit
]->pi
= pi
;
2239 wlc
->bandstate
[bandunit
]->bandunit
= bandunit
;
2240 wlc
->bandstate
[bandunit
]->bandtype
= bandtype
;
2248 /* Free the convenience handles */
2249 int wlc_bmac_detach(wlc_info_t
*wlc
)
2253 if (wlc
->pub
->sih
) {
2254 osl_mfree(wlc
->osh
, (void *)wlc
->pub
->sih
, sizeof(si_t
));
2255 wlc
->pub
->sih
= NULL
;
2258 for (idx
= 0; idx
< MAXBANDS
; idx
++)
2259 if (wlc
->bandstate
[idx
]->pi
) {
2260 osl_mfree(wlc
->osh
, wlc
->bandstate
[idx
]->pi
,
2262 wlc
->bandstate
[idx
]->pi
= NULL
;
2266 wlc_rpctx_detach(wlc
->rpctx
);
2274 #endif /* WLC_HIGH_ONLY */
2276 static void BCMATTACHFN(wlc_timers_deinit
) (wlc_info_t
*wlc
)
2278 /* free timer state */
2280 wl_free_timer(wlc
->wl
, wlc
->wdtimer
);
2281 wlc
->wdtimer
= NULL
;
2283 if (wlc
->radio_timer
) {
2284 wl_free_timer(wlc
->wl
, wlc
->radio_timer
);
2285 wlc
->radio_timer
= NULL
;
2289 static void BCMATTACHFN(wlc_detach_module
) (wlc_info_t
*wlc
)
2292 wlc_antsel_detach(wlc
->asi
);
2297 wlc_ampdu_detach(wlc
->ampdu
);
2301 wlc_stf_detach(wlc
);
2305 * Return a count of the number of driver callbacks still pending.
2307 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2308 * touch hardware registers since the d11core may be in reset and clock may not be available.
2309 * One exception is sb register access, which is possible if crystal is turned on
2310 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2312 uint
BCMATTACHFN(wlc_detach
) (wlc_info_t
*wlc
)
2320 WL_TRACE(("wl%d: %s\n", wlc
->pub
->unit
, __func__
));
2322 ASSERT(!wlc
->pub
->up
);
2324 callbacks
+= wlc_bmac_detach(wlc
);
2326 /* delete software timers */
2327 if (!wlc_radio_monitor_stop(wlc
))
2331 wlc_eventq_detach(wlc
->eventq
);
2335 wlc_channel_mgr_detach(wlc
->cmi
);
2337 wlc_timers_deinit(wlc
);
2339 wlc_detach_module(wlc
);
2341 /* free other state */
2343 #ifdef WLC_HIGH_ONLY
2344 /* High-Only driver has an allocated copy of vars, monolithic just
2345 * references the wlc->hw->vars which is freed in wlc_bmac_detach()
2347 if (wlc
->pub
->vars
) {
2348 osl_mfree(wlc
->osh
, wlc
->pub
->vars
, wlc
->vars_size
);
2349 wlc
->pub
->vars
= NULL
;
2354 if (wlc
->country_ie_override
) {
2355 osl_mfree(wlc
->osh
, wlc
->country_ie_override
,
2356 wlc
->country_ie_override
->len
+ TLV_HDR_LEN
);
2357 wlc
->country_ie_override
= NULL
;
2362 /* free dumpcb list */
2363 dumpcb_t
*prev
, *ptr
;
2364 prev
= ptr
= wlc
->dumpcb_head
;
2367 osl_mfree(wlc
->osh
, prev
, sizeof(dumpcb_t
));
2370 wlc
->dumpcb_head
= NULL
;
2373 /* Detach from iovar manager */
2374 wlc_module_unregister(wlc
->pub
, "wlc_iovars", wlc
);
2378 wlc_ap_detach(wlc->ap);
2383 while (wlc
->tx_queues
!= NULL
) {
2384 wlc_txq_free(wlc
, wlc
->osh
, wlc
->tx_queues
);
2388 * consistency check: wlc_module_register/wlc_module_unregister calls
2389 * should match therefore nothing should be left here.
2391 for (i
= 0; i
< WLC_MAXMODULES
; i
++)
2392 ASSERT(wlc
->modulecb
[i
].name
[0] == '\0');
2394 wlc_detach_mfree(wlc
, wlc
->osh
);
2398 /* update state that depends on the current value of "ap" */
2399 void wlc_ap_upd(wlc_info_t
*wlc
)
2401 if (AP_ENAB(wlc
->pub
))
2402 wlc
->PLCPHdr_override
= WLC_PLCP_AUTO
; /* AP: short not allowed, but not enforced */
2404 wlc
->PLCPHdr_override
= WLC_PLCP_SHORT
; /* STA-BSS; short capable */
2406 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2407 wlc
->vlan_mode
= AP_ENAB(wlc
->pub
) ? OFF
: AUTO
;
2413 /* read hwdisable state and propagate to wlc flag */
2414 static void wlc_radio_hwdisable_upd(wlc_info_t
*wlc
)
2416 if (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
|| wlc
->pub
->hw_off
)
2419 if (wlc_bmac_radio_read_hwdisabled(wlc
->hw
)) {
2420 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2422 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2426 /* return TRUE if Minimum Power Consumption should be entered, FALSE otherwise */
2427 bool wlc_is_non_delay_mpc(wlc_info_t
*wlc
)
2432 bool wlc_ismpc(wlc_info_t
*wlc
)
2434 return (wlc
->mpc_delay_off
== 0) && (wlc_is_non_delay_mpc(wlc
));
2437 void wlc_radio_mpc_upd(wlc_info_t
*wlc
)
2439 bool mpc_radio
, radio_state
;
2442 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2443 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2444 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2445 * the radio is going down.
2448 if (!wlc
->pub
->radio_disabled
)
2450 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2452 if (!wlc
->pub
->radio_disabled
)
2453 wlc_radio_monitor_stop(wlc
);
2458 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2459 * to go ON, always call radio_upd synchronously
2460 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2463 (mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
) ? OFF
:
2465 mpc_radio
= (wlc_ismpc(wlc
) == TRUE
) ? OFF
: ON
;
2467 if (radio_state
== ON
&& mpc_radio
== OFF
)
2468 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2469 else if (radio_state
== OFF
&& mpc_radio
== ON
) {
2470 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2472 if (wlc
->mpc_offcnt
< WLC_MPC_THRESHOLD
) {
2473 wlc
->mpc_dlycnt
= WLC_MPC_MAX_DELAYCNT
;
2475 wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
2476 wlc
->mpc_dur
+= OSL_SYSUPTIME() - wlc
->mpc_laston_ts
;
2478 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2479 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2480 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2482 if ((wlc
->prev_non_delay_mpc
== FALSE
) &&
2483 (wlc_is_non_delay_mpc(wlc
) == TRUE
) && wlc
->mpc_delay_off
) {
2484 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2486 wlc
->prev_non_delay_mpc
= wlc_is_non_delay_mpc(wlc
);
2490 * centralized radio disable/enable function,
2491 * invoke radio enable/disable after updating hwradio status
2493 static void wlc_radio_upd(wlc_info_t
*wlc
)
2495 if (wlc
->pub
->radio_disabled
)
2496 wlc_radio_disable(wlc
);
2498 wlc_radio_enable(wlc
);
2501 /* maintain LED behavior in down state */
2502 static void wlc_down_led_upd(wlc_info_t
*wlc
)
2504 ASSERT(!wlc
->pub
->up
);
2506 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2507 /* turn on sbclk if necessary */
2508 if (!AP_ENAB(wlc
->pub
)) {
2509 wlc_pllreq(wlc
, TRUE
, WLC_PLLREQ_FLIP
);
2511 wlc_pllreq(wlc
, FALSE
, WLC_PLLREQ_FLIP
);
2515 void wlc_radio_disable(wlc_info_t
*wlc
)
2517 if (!wlc
->pub
->up
) {
2518 wlc_down_led_upd(wlc
);
2522 wlc_radio_monitor_start(wlc
);
2526 static void wlc_radio_enable(wlc_info_t
*wlc
)
2531 if (DEVICEREMOVED(wlc
))
2534 if (!wlc
->down_override
) { /* imposed by wl down/out ioctl */
2539 /* periodical query hw radio button while driver is "down" */
2540 static void wlc_radio_timer(void *arg
)
2542 wlc_info_t
*wlc
= (wlc_info_t
*) arg
;
2544 if (DEVICEREMOVED(wlc
)) {
2545 WL_ERROR(("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
));
2550 /* cap mpc off count */
2551 if (wlc
->mpc_offcnt
< WLC_MPC_MAX_DELAYCNT
)
2554 /* validate all the reasons driver could be down and running this radio_timer */
2555 ASSERT(wlc
->pub
->radio_disabled
|| wlc
->down_override
);
2556 wlc_radio_hwdisable_upd(wlc
);
2560 static bool wlc_radio_monitor_start(wlc_info_t
*wlc
)
2562 /* Don't start the timer if HWRADIO feature is disabled */
2563 if (wlc
->radio_monitor
|| (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
))
2566 wlc
->radio_monitor
= TRUE
;
2567 wlc_pllreq(wlc
, TRUE
, WLC_PLLREQ_RADIO_MON
);
2568 wl_add_timer(wlc
->wl
, wlc
->radio_timer
, TIMER_INTERVAL_RADIOCHK
, TRUE
);
2572 bool wlc_radio_monitor_stop(wlc_info_t
*wlc
)
2574 if (!wlc
->radio_monitor
)
2577 ASSERT((wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
) !=
2580 wlc
->radio_monitor
= FALSE
;
2581 wlc_pllreq(wlc
, FALSE
, WLC_PLLREQ_RADIO_MON
);
2582 return wl_del_timer(wlc
->wl
, wlc
->radio_timer
);
2585 /* bring the driver down, but don't reset hardware */
2586 void wlc_out(wlc_info_t
*wlc
)
2588 wlc_bmac_set_noreset(wlc
->hw
, TRUE
);
2591 wlc_bmac_set_noreset(wlc
->hw
, FALSE
);
2593 /* core clk is TRUE in BMAC driver due to noreset, need to mirror it in HIGH */
2596 /* This will make sure that when 'up' is done
2597 * after 'out' it'll restore hardware (especially gpios)
2599 wlc
->pub
->hw_up
= FALSE
;
2603 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2604 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2605 * in prec_map. Of course, ignore this rule when block_datafifo is set
2607 static bool wlc_tx_prec_map_verify(wlc_info_t
*wlc
)
2609 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2612 if (!EDCF_ENAB(wlc
->pub
)) {
2613 if (!(WLC_TX_FIFO_CHECK(wlc
, TX_DATA_FIFO
) ||
2614 WLC_TX_FIFO_CHECK(wlc
, TX_CTL_FIFO
)))
2620 return WLC_TX_FIFO_CHECK(wlc
, TX_AC_BK_FIFO
)
2621 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_BE_FIFO
)
2622 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VI_FIFO
)
2623 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VO_FIFO
);
2627 static void wlc_watchdog_by_timer(void *arg
)
2629 wlc_info_t
*wlc
= (wlc_info_t
*) arg
;
2631 if (WLC_WATCHDOG_TBTT(wlc
)) {
2632 /* set to normal osl watchdog period */
2633 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
2634 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
2639 /* common watchdog code */
2640 static void wlc_watchdog(void *arg
)
2642 wlc_info_t
*wlc
= (wlc_info_t
*) arg
;
2646 WL_TRACE(("wl%d: wlc_watchdog\n", wlc
->pub
->unit
));
2651 if (DEVICEREMOVED(wlc
)) {
2652 WL_ERROR(("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
));
2657 /* increment second count */
2660 /* delay radio disable */
2661 if (wlc
->mpc_delay_off
) {
2662 if (--wlc
->mpc_delay_off
== 0) {
2663 mboolset(wlc
->pub
->radio_disabled
,
2664 WL_RADIO_MPC_DISABLE
);
2665 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2666 wlc
->mpc_offcnt
= 0;
2667 wlc
->mpc_laston_ts
= OSL_SYSUPTIME();
2672 wlc_radio_mpc_upd(wlc
);
2673 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2674 wlc_radio_hwdisable_upd(wlc
);
2676 /* if ismpc, driver should be in down state if up/down is allowed */
2677 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2678 ASSERT(!wlc
->pub
->up
);
2679 /* if radio is disable, driver may be down, quit here */
2680 if (wlc
->pub
->radio_disabled
)
2684 wlc_bmac_watchdog(wlc
);
2686 #ifdef WLC_HIGH_ONLY
2688 wlc_bmac_rpc_watchdog(wlc
);
2691 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2692 if ((WLC_UPDATE_STATS(wlc
))
2693 && (!(wlc
->pub
->now
% SW_TIMER_MAC_STAT_UPD
)))
2696 /* Manage TKIP countermeasures timers */
2697 FOREACH_BSS(wlc
, i
, cfg
) {
2698 if (cfg
->tk_cm_dt
) {
2701 if (cfg
->tk_cm_bt
) {
2706 /* Call any registered watchdog handlers */
2707 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2708 if (wlc
->modulecb
[i
].watchdog_fn
)
2709 wlc
->modulecb
[i
].watchdog_fn(wlc
->modulecb
[i
].hdl
);
2712 if (WLCISNPHY(wlc
->band
) && !wlc
->pub
->tempsense_disable
&&
2713 ((wlc
->pub
->now
- wlc
->tempsense_lasttime
) >=
2714 WLC_TEMPSENSE_PERIOD
)) {
2715 wlc
->tempsense_lasttime
= wlc
->pub
->now
;
2716 wlc_tempsense_upd(wlc
);
2719 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2720 ASSERT(wlc_bmac_taclear(wlc
->hw
, TRUE
));
2723 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2724 ASSERT(wlc_tx_prec_map_verify(wlc
));
2726 ASSERT(wlc_ps_check(wlc
));
2729 /* make interface operational */
2730 int BCMINITFN(wlc_up
) (wlc_info_t
*wlc
)
2732 WL_TRACE(("wl%d: %s:\n", wlc
->pub
->unit
, __func__
));
2734 /* HW is turned off so don't try to access it */
2735 if (wlc
->pub
->hw_off
|| DEVICEREMOVED(wlc
))
2736 return BCME_RADIOOFF
;
2738 if (!wlc
->pub
->hw_up
) {
2739 wlc_bmac_hw_up(wlc
->hw
);
2740 wlc
->pub
->hw_up
= TRUE
;
2743 if ((wlc
->pub
->boardflags
& BFL_FEM
)
2744 && (CHIPID(wlc
->pub
->sih
->chip
) == BCM4313_CHIP_ID
)) {
2745 if (wlc
->pub
->boardrev
>= 0x1250
2746 && (wlc
->pub
->boardflags
& BFL_FEM_BT
)) {
2747 wlc_mhf(wlc
, MHF5
, MHF5_4313_GPIOCTRL
,
2748 MHF5_4313_GPIOCTRL
, WLC_BAND_ALL
);
2750 wlc_mhf(wlc
, MHF4
, MHF4_EXTPA_ENABLE
, MHF4_EXTPA_ENABLE
,
2756 * Need to read the hwradio status here to cover the case where the system
2757 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2758 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2759 * don't call radio_update to avoid looping wlc_up.
2761 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2763 if (!wlc
->pub
->radio_disabled
) {
2764 int status
= wlc_bmac_up_prep(wlc
->hw
);
2765 if (status
== BCME_RADIOOFF
) {
2767 (wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
)) {
2769 wlc_bsscfg_t
*bsscfg
;
2770 mboolset(wlc
->pub
->radio_disabled
,
2771 WL_RADIO_HW_DISABLE
);
2773 FOREACH_BSS(wlc
, idx
, bsscfg
) {
2774 if (!BSSCFG_STA(bsscfg
)
2775 || !bsscfg
->enable
|| !bsscfg
->BSS
)
2777 WL_ERROR(("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n", wlc
->pub
->unit
, idx
));
2784 if (wlc
->pub
->radio_disabled
) {
2785 wlc_radio_monitor_start(wlc
);
2789 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2792 wlc_radio_monitor_stop(wlc
);
2794 /* Set EDCF hostflags */
2795 if (EDCF_ENAB(wlc
->pub
)) {
2796 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, MHF1_EDCF
, WLC_BAND_ALL
);
2798 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, 0, WLC_BAND_ALL
);
2801 if (WLC_WAR16165(wlc
))
2802 wlc_mhf(wlc
, MHF2
, MHF2_PCISLOWCLKWAR
, MHF2_PCISLOWCLKWAR
,
2806 wlc
->pub
->up
= TRUE
;
2808 if (wlc
->bandinit_pending
) {
2809 wlc_suspend_mac_and_wait(wlc
);
2810 wlc_set_chanspec(wlc
, wlc
->default_bss
->chanspec
);
2811 wlc
->bandinit_pending
= FALSE
;
2812 wlc_enable_mac(wlc
);
2815 wlc_bmac_up_finish(wlc
->hw
);
2817 /* other software states up after ISR is running */
2818 /* start APs that were to be brought up but are not up yet */
2819 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2821 /* Program the TX wme params with the current settings */
2822 wlc_wme_retries_write(wlc
);
2824 /* start one second watchdog timer */
2825 ASSERT(!wlc
->WDarmed
);
2826 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
, TRUE
);
2827 wlc
->WDarmed
= TRUE
;
2829 /* ensure antenna config is up to date */
2830 wlc_stf_phy_txant_upd(wlc
);
2831 /* ensure LDPC config is in sync */
2832 wlc_ht_update_ldpc(wlc
, wlc
->stf
->ldpc
);
2837 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2838 static void BCMINITFN(wlc_tx_prec_map_init
) (wlc_info_t
*wlc
)
2840 wlc
->tx_prec_map
= WLC_PREC_BMP_ALL
;
2841 bzero(wlc
->fifo2prec_map
, sizeof(u16
) * NFIFO
);
2843 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2844 * if either is full.
2846 if (!EDCF_ENAB(wlc
->pub
)) {
2847 wlc
->fifo2prec_map
[TX_DATA_FIFO
] = WLC_PREC_BMP_ALL
;
2848 wlc
->fifo2prec_map
[TX_CTL_FIFO
] = WLC_PREC_BMP_ALL
;
2850 wlc
->fifo2prec_map
[TX_AC_BK_FIFO
] = WLC_PREC_BMP_AC_BK
;
2851 wlc
->fifo2prec_map
[TX_AC_BE_FIFO
] = WLC_PREC_BMP_AC_BE
;
2852 wlc
->fifo2prec_map
[TX_AC_VI_FIFO
] = WLC_PREC_BMP_AC_VI
;
2853 wlc
->fifo2prec_map
[TX_AC_VO_FIFO
] = WLC_PREC_BMP_AC_VO
;
2857 static uint
BCMUNINITFN(wlc_down_del_timer
) (wlc_info_t
*wlc
)
2865 * Mark the interface nonoperational, stop the software mechanisms,
2866 * disable the hardware, free any transient buffer state.
2867 * Return a count of the number of driver callbacks still pending.
2869 uint
BCMUNINITFN(wlc_down
) (wlc_info_t
*wlc
)
2874 bool dev_gone
= FALSE
;
2877 WL_TRACE(("wl%d: %s:\n", wlc
->pub
->unit
, __func__
));
2879 /* check if we are already in the going down path */
2880 if (wlc
->going_down
) {
2881 WL_ERROR(("wl%d: %s: Driver going down so return\n",
2882 wlc
->pub
->unit
, __func__
));
2888 /* in between, mpc could try to bring down again.. */
2889 wlc
->going_down
= TRUE
;
2891 callbacks
+= wlc_bmac_down_prep(wlc
->hw
);
2893 dev_gone
= DEVICEREMOVED(wlc
);
2895 /* Call any registered down handlers */
2896 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2897 if (wlc
->modulecb
[i
].down_fn
)
2899 wlc
->modulecb
[i
].down_fn(wlc
->modulecb
[i
].hdl
);
2902 /* cancel the watchdog timer */
2904 if (!wl_del_timer(wlc
->wl
, wlc
->wdtimer
))
2906 wlc
->WDarmed
= FALSE
;
2908 /* cancel all other timers */
2909 callbacks
+= wlc_down_del_timer(wlc
);
2911 /* interrupt must have been blocked */
2912 ASSERT((wlc
->macintmask
== 0) || !wlc
->pub
->up
);
2914 wlc
->pub
->up
= FALSE
;
2916 wlc_phy_mute_upd(wlc
->band
->pi
, FALSE
, PHY_MUTE_ALL
);
2918 /* clear txq flow control */
2919 wlc_txflowcontrol_reset(wlc
);
2921 /* flush tx queues */
2922 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
2923 pktq_flush(wlc
->osh
, &qi
->q
, TRUE
, NULL
, 0);
2924 ASSERT(pktq_empty(&qi
->q
));
2927 /* flush event queue.
2928 * Should be the last thing done after all the events are generated
2929 * Just delivers the events synchronously instead of waiting for a timer
2931 callbacks
+= wlc_eventq_down(wlc
->eventq
);
2933 callbacks
+= wlc_bmac_down_finish(wlc
->hw
);
2935 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2938 #ifdef WLC_HIGH_ONLY
2939 wlc_rpctx_txreclaim(wlc
->rpctx
);
2942 /* Verify all packets are flushed from the driver */
2943 if (PKTALLOCED(wlc
->osh
) != 0) {
2944 WL_ERROR(("%d packets not freed at wlc_down!!!!!!\n",
2945 PKTALLOCED(wlc
->osh
)));
2948 /* Since all the packets should have been freed,
2949 * all callbacks should have been called
2951 for (i
= 1; i
<= wlc
->pub
->tunables
->maxpktcb
; i
++)
2952 ASSERT(wlc
->pkt_callback
[i
].fn
== NULL
);
2954 wlc
->going_down
= FALSE
;
2958 /* Set the current gmode configuration */
2959 int wlc_set_gmode(wlc_info_t
*wlc
, u8 gmode
, bool config
)
2964 /* Default to 54g Auto */
2965 s8 shortslot
= WLC_SHORTSLOT_AUTO
; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2966 bool shortslot_restrict
= FALSE
; /* Restrict association to stations that support shortslot
2968 bool ignore_bcns
= TRUE
; /* Ignore legacy beacons on the same channel */
2969 bool ofdm_basic
= FALSE
; /* Make 6, 12, and 24 basic rates */
2970 int preamble
= WLC_PLCP_LONG
; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2971 bool preamble_restrict
= FALSE
; /* Restrict association to stations that support short
2976 /* if N-support is enabled, allow Gmode set as long as requested
2977 * Gmode is not GMODE_LEGACY_B
2979 if (N_ENAB(wlc
->pub
) && gmode
== GMODE_LEGACY_B
)
2980 return BCME_UNSUPPORTED
;
2982 /* verify that we are dealing with 2G band and grab the band pointer */
2983 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
2985 else if ((NBANDS(wlc
) > 1) &&
2986 (wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
== WLC_BAND_2G
))
2987 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
2989 return BCME_BADBAND
;
2991 /* Legacy or bust when no OFDM is supported by regulatory */
2992 if ((wlc_channel_locale_flags_in_band(wlc
->cmi
, band
->bandunit
) &
2993 WLC_NO_OFDM
) && (gmode
!= GMODE_LEGACY_B
))
2996 /* update configuration value */
2998 wlc_protection_upd(wlc
, WLC_PROT_G_USER
, gmode
);
3000 /* Clear supported rates filter */
3001 bzero(&wlc
->sup_rates_override
, sizeof(wlc_rateset_t
));
3003 /* Clear rateset override */
3004 bzero(&rs
, sizeof(wlc_rateset_t
));
3007 case GMODE_LEGACY_B
:
3008 shortslot
= WLC_SHORTSLOT_OFF
;
3009 wlc_rateset_copy(&gphy_legacy_rates
, &rs
);
3014 if (AP_ENAB(wlc
->pub
))
3015 wlc_rateset_copy(&cck_rates
, &wlc
->sup_rates_override
);
3019 /* Accept defaults */
3024 preamble
= WLC_PLCP_SHORT
;
3025 preamble_restrict
= TRUE
;
3028 case GMODE_PERFORMANCE
:
3029 if (AP_ENAB(wlc
->pub
)) /* Put all rates into the Supported Rates element */
3030 wlc_rateset_copy(&cck_ofdm_rates
,
3031 &wlc
->sup_rates_override
);
3033 shortslot
= WLC_SHORTSLOT_ON
;
3034 shortslot_restrict
= TRUE
;
3036 preamble
= WLC_PLCP_SHORT
;
3037 preamble_restrict
= TRUE
;
3042 WL_ERROR(("wl%d: %s: invalid gmode %d\n", wlc
->pub
->unit
,
3044 return BCME_UNSUPPORTED
;
3048 * If we are switching to gmode == GMODE_LEGACY_B,
3049 * clean up rate info that may refer to OFDM rates.
3051 if ((gmode
== GMODE_LEGACY_B
) && (band
->gmode
!= GMODE_LEGACY_B
)) {
3052 band
->gmode
= gmode
;
3053 if (band
->rspec_override
&& !IS_CCK(band
->rspec_override
)) {
3054 band
->rspec_override
= 0;
3055 wlc_reprate_init(wlc
);
3057 if (band
->mrspec_override
&& !IS_CCK(band
->mrspec_override
)) {
3058 band
->mrspec_override
= 0;
3062 band
->gmode
= gmode
;
3064 wlc
->ignore_bcns
= ignore_bcns
;
3066 wlc
->shortslot_override
= shortslot
;
3068 if (AP_ENAB(wlc
->pub
)) {
3069 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
3070 wlc
->PLCPHdr_override
=
3072 WLC_PLCP_LONG
) ? WLC_PLCP_SHORT
: WLC_PLCP_AUTO
;
3075 if ((AP_ENAB(wlc
->pub
) && preamble
!= WLC_PLCP_LONG
)
3076 || preamble
== WLC_PLCP_SHORT
)
3077 wlc
->default_bss
->capability
|= DOT11_CAP_SHORT
;
3079 wlc
->default_bss
->capability
&= ~DOT11_CAP_SHORT
;
3081 /* Update shortslot capability bit for AP and IBSS */
3082 if ((AP_ENAB(wlc
->pub
) && shortslot
== WLC_SHORTSLOT_AUTO
) ||
3083 shortslot
== WLC_SHORTSLOT_ON
)
3084 wlc
->default_bss
->capability
|= DOT11_CAP_SHORTSLOT
;
3086 wlc
->default_bss
->capability
&= ~DOT11_CAP_SHORTSLOT
;
3088 /* Use the default 11g rateset */
3090 wlc_rateset_copy(&cck_ofdm_rates
, &rs
);
3093 for (i
= 0; i
< rs
.count
; i
++) {
3094 if (rs
.rates
[i
] == WLC_RATE_6M
3095 || rs
.rates
[i
] == WLC_RATE_12M
3096 || rs
.rates
[i
] == WLC_RATE_24M
)
3097 rs
.rates
[i
] |= WLC_RATE_FLAG
;
3101 /* Set default bss rateset */
3102 wlc
->default_bss
->rateset
.count
= rs
.count
;
3103 bcopy((char *)rs
.rates
, (char *)wlc
->default_bss
->rateset
.rates
,
3104 sizeof(wlc
->default_bss
->rateset
.rates
));
3109 static int wlc_nmode_validate(wlc_info_t
*wlc
, int32 nmode
)
3121 if (!(WLC_PHY_11N_CAP(wlc
->band
)))
3133 int wlc_set_nmode(wlc_info_t
*wlc
, int32 nmode
)
3138 err
= wlc_nmode_validate(wlc
, nmode
);
3145 wlc
->pub
->_n_enab
= OFF
;
3146 wlc
->default_bss
->flags
&= ~WLC_BSS_HT
;
3147 /* delete the mcs rates from the default and hw ratesets */
3148 wlc_rateset_mcs_clear(&wlc
->default_bss
->rateset
);
3149 for (i
= 0; i
< NBANDS(wlc
); i
++) {
3150 memset(wlc
->bandstate
[i
]->hw_rateset
.mcs
, 0,
3152 if (IS_MCS(wlc
->band
->rspec_override
)) {
3153 wlc
->bandstate
[i
]->rspec_override
= 0;
3154 wlc_reprate_init(wlc
);
3156 if (IS_MCS(wlc
->band
->mrspec_override
))
3157 wlc
->bandstate
[i
]->mrspec_override
= 0;
3162 if (wlc
->stf
->txstreams
== WL_11N_3x3
)
3168 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
3169 /* force GMODE_AUTO if NMODE is ON */
3170 wlc_set_gmode(wlc
, GMODE_AUTO
, TRUE
);
3171 if (nmode
== WL_11N_3x3
)
3172 wlc
->pub
->_n_enab
= SUPPORT_HT
;
3174 wlc
->pub
->_n_enab
= SUPPORT_11N
;
3175 wlc
->default_bss
->flags
|= WLC_BSS_HT
;
3176 /* add the mcs rates to the default and hw ratesets */
3177 wlc_rateset_mcs_build(&wlc
->default_bss
->rateset
,
3178 wlc
->stf
->txstreams
);
3179 for (i
= 0; i
< NBANDS(wlc
); i
++)
3180 memcpy(wlc
->bandstate
[i
]->hw_rateset
.mcs
,
3181 wlc
->default_bss
->rateset
.mcs
, MCSSET_LEN
);
3192 static int wlc_set_rateset(wlc_info_t
*wlc
, wlc_rateset_t
*rs_arg
)
3194 wlc_rateset_t rs
, new;
3197 bcopy((char *)rs_arg
, (char *)&rs
, sizeof(wlc_rateset_t
));
3199 /* check for bad count value */
3200 if ((rs
.count
== 0) || (rs
.count
> WLC_NUMRATES
))
3201 return BCME_BADRATESET
;
3203 /* try the current band */
3204 bandunit
= wlc
->band
->bandunit
;
3205 bcopy((char *)&rs
, (char *)&new, sizeof(wlc_rateset_t
));
3206 if (wlc_rate_hwrs_filter_sort_validate
3207 (&new, &wlc
->bandstate
[bandunit
]->hw_rateset
, TRUE
,
3208 wlc
->stf
->txstreams
))
3211 /* try the other band */
3212 if (IS_MBAND_UNLOCKED(wlc
)) {
3213 bandunit
= OTHERBANDUNIT(wlc
);
3214 bcopy((char *)&rs
, (char *)&new, sizeof(wlc_rateset_t
));
3215 if (wlc_rate_hwrs_filter_sort_validate(&new,
3217 bandstate
[bandunit
]->
3219 wlc
->stf
->txstreams
))
3226 /* apply new rateset */
3227 bcopy((char *)&new, (char *)&wlc
->default_bss
->rateset
,
3228 sizeof(wlc_rateset_t
));
3229 bcopy((char *)&new, (char *)&wlc
->bandstate
[bandunit
]->defrateset
,
3230 sizeof(wlc_rateset_t
));
3234 /* simplified integer set interface for common ioctl handler */
3235 int wlc_set(wlc_info_t
*wlc
, int cmd
, int arg
)
3237 return wlc_ioctl(wlc
, cmd
, (void *)&arg
, sizeof(arg
), NULL
);
3240 /* simplified integer get interface for common ioctl handler */
3241 int wlc_get(wlc_info_t
*wlc
, int cmd
, int *arg
)
3243 return wlc_ioctl(wlc
, cmd
, arg
, sizeof(int), NULL
);
3246 static void wlc_ofdm_rateset_war(wlc_info_t
*wlc
)
3251 if (wlc
->cfg
->associated
)
3252 r
= wlc
->cfg
->current_bss
->rateset
.rates
[0];
3254 r
= wlc
->default_bss
->rateset
.rates
[0];
3256 wlc_phy_ofdm_rateset_war(wlc
->band
->pi
, war
);
3262 wlc_ioctl(wlc_info_t
*wlc
, int cmd
, void *arg
, int len
, struct wlc_if
*wlcif
)
3264 return _wlc_ioctl(wlc
, cmd
, arg
, len
, wlcif
);
3267 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3269 _wlc_ioctl(wlc_info_t
*wlc
, int cmd
, void *arg
, int len
, struct wlc_if
*wlcif
)
3276 struct scb
*nextscb
;
3280 wlc_bsscfg_t
*bsscfg
;
3282 wlc_bss_info_t
*current_bss
;
3284 /* update bsscfg pointer */
3285 bsscfg
= NULL
; /* XXX: Hack bsscfg to be size one and use this globally */
3288 /* initialize the following to get rid of compiler warning */
3294 /* If the device is turned off, then it's not "removed" */
3295 if (!wlc
->pub
->hw_off
&& DEVICEREMOVED(wlc
)) {
3296 WL_ERROR(("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
));
3301 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
3303 /* default argument is generic integer */
3304 pval
= arg
? (int *)arg
:NULL
;
3306 /* This will prevent the misaligned access */
3307 if (pval
&& (u32
) len
>= sizeof(val
))
3308 bcopy(pval
, &val
, sizeof(val
));
3312 /* bool conversion to avoid duplication below */
3313 bool_val
= val
!= 0;
3315 if (cmd
!= WLC_SET_CHANNEL
)
3316 WL_NONE(("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n", cmd
,
3317 (uint
) val
, val
, len
));
3323 /* A few commands don't need any arguments; all the others do. */
3331 case WLC_START_CHANNEL_QA
:
3336 if ((arg
== NULL
) || (len
<= 0)) {
3337 WL_ERROR(("wl%d: %s: Command %d needs arguments\n",
3338 wlc
->pub
->unit
, __func__
, cmd
));
3339 bcmerror
= BCME_BADARG
;
3347 case WLC_GET_MSGLEVEL
:
3348 *pval
= wl_msg_level
;
3351 case WLC_SET_MSGLEVEL
:
3356 case WLC_GET_INSTANCE
:
3357 *pval
= wlc
->pub
->unit
;
3360 case WLC_GET_CHANNEL
:{
3361 channel_info_t
*ci
= (channel_info_t
*) arg
;
3363 ASSERT(len
> (int)sizeof(ci
));
3366 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
);
3367 ci
->target_channel
=
3368 CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
);
3369 ci
->scan_channel
= 0;
3374 case WLC_SET_CHANNEL
:{
3375 chanspec_t chspec
= CH20MHZ_CHSPEC(val
);
3377 if (val
< 0 || val
> MAXCHANNEL
) {
3378 bcmerror
= BCME_OUTOFRANGECHAN
;
3382 if (!wlc_valid_chanspec_db(wlc
->cmi
, chspec
)) {
3383 bcmerror
= BCME_BADCHAN
;
3387 if (!wlc
->pub
->up
&& IS_MBAND_UNLOCKED(wlc
)) {
3388 if (wlc
->band
->bandunit
!=
3389 CHSPEC_WLCBANDUNIT(chspec
))
3390 wlc
->bandinit_pending
= TRUE
;
3392 wlc
->bandinit_pending
= FALSE
;
3395 wlc
->default_bss
->chanspec
= chspec
;
3396 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3397 if (wlc
->pub
->up
&& !wlc
->pub
->associated
&&
3398 (WLC_BAND_PI_RADIO_CHANSPEC
!= chspec
)) {
3399 wlc_set_home_chanspec(wlc
, chspec
);
3400 wlc_suspend_mac_and_wait(wlc
);
3401 wlc_set_chanspec(wlc
, chspec
);
3402 wlc_enable_mac(wlc
);
3404 #ifdef WLC_HIGH_ONLY
3405 /* delay for channel change */
3412 case WLC_GET_UCFLAGS
:
3413 if (!wlc
->pub
->up
) {
3414 bcmerror
= BCME_NOTUP
;
3418 /* optional band is stored in the second integer of incoming buffer */
3421 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3423 /* bcmerror checking */
3424 bcmerror
= wlc_iocregchk(wlc
, band
);
3428 if (val
>= MHFMAX
) {
3429 bcmerror
= BCME_RANGE
;
3433 *pval
= wlc_bmac_mhf_get(wlc
->hw
, (u8
) val
, WLC_BAND_AUTO
);
3436 case WLC_SET_UCFLAGS
:
3437 if (!wlc
->pub
->up
) {
3438 bcmerror
= BCME_NOTUP
;
3442 /* optional band is stored in the second integer of incoming buffer */
3445 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3447 /* bcmerror checking */
3448 bcmerror
= wlc_iocregchk(wlc
, band
);
3454 bcmerror
= BCME_RANGE
;
3458 wlc_mhf(wlc
, (u8
) i
, 0xffff, (u16
) (val
>> NBITS(u16
)),
3465 /* optional band is stored in the second integer of incoming buffer */
3468 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3470 /* bcmerror checking */
3471 bcmerror
= wlc_iocregchk(wlc
, band
);
3476 bcmerror
= BCME_BADADDR
;
3480 *pval
= wlc_read_shm(wlc
, (u16
) val
);
3486 /* optional band is stored in the second integer of incoming buffer */
3489 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3491 /* bcmerror checking */
3492 bcmerror
= wlc_iocregchk(wlc
, band
);
3497 bcmerror
= BCME_BADADDR
;
3501 wlc_write_shm(wlc
, (u16
) val
,
3502 (u16
) (val
>> NBITS(u16
)));
3505 case WLC_R_REG
: /* MAC registers */
3507 r
= (rw_reg_t
*) arg
;
3508 band
= WLC_BAND_AUTO
;
3510 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3511 bcmerror
= BCME_BUFTOOSHORT
;
3515 if (len
>= (int)sizeof(rw_reg_t
))
3518 /* bcmerror checking */
3519 bcmerror
= wlc_iocregchk(wlc
, band
);
3523 if ((r
->byteoff
+ r
->size
) > sizeof(d11regs_t
)) {
3524 bcmerror
= BCME_BADADDR
;
3527 if (r
->size
== sizeof(u32
))
3530 (u32
*) ((unsigned char *) (uintptr
) regs
+
3532 else if (r
->size
== sizeof(u16
))
3535 (u16
*) ((unsigned char *) (uintptr
) regs
+
3538 bcmerror
= BCME_BADADDR
;
3543 r
= (rw_reg_t
*) arg
;
3544 band
= WLC_BAND_AUTO
;
3546 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3547 bcmerror
= BCME_BUFTOOSHORT
;
3551 if (len
>= (int)sizeof(rw_reg_t
))
3554 /* bcmerror checking */
3555 bcmerror
= wlc_iocregchk(wlc
, band
);
3559 if (r
->byteoff
+ r
->size
> sizeof(d11regs_t
)) {
3560 bcmerror
= BCME_BADADDR
;
3563 if (r
->size
== sizeof(u32
))
3565 (u32
*) ((unsigned char *) (uintptr
) regs
+
3566 r
->byteoff
), r
->val
);
3567 else if (r
->size
== sizeof(u16
))
3569 (u16
*) ((unsigned char *) (uintptr
) regs
+
3570 r
->byteoff
), r
->val
);
3572 bcmerror
= BCME_BADADDR
;
3577 *pval
= wlc
->stf
->txant
;
3581 bcmerror
= wlc_stf_ant_txant_validate(wlc
, (s8
) val
);
3585 wlc
->stf
->txant
= (s8
) val
;
3587 /* if down, we are done */
3591 wlc_suspend_mac_and_wait(wlc
);
3593 wlc_stf_phy_txant_upd(wlc
);
3594 wlc_beacon_phytxctl_txant_upd(wlc
, wlc
->bcn_rspec
);
3596 wlc_enable_mac(wlc
);
3600 case WLC_GET_ANTDIV
:{
3603 /* return configured value if core is down */
3604 if (!wlc
->pub
->up
) {
3605 *pval
= wlc
->stf
->ant_rx_ovr
;
3608 if (wlc_phy_ant_rxdiv_get
3609 (wlc
->band
->pi
, &phy_antdiv
))
3610 *pval
= (int)phy_antdiv
;
3612 *pval
= (int)wlc
->stf
->ant_rx_ovr
;
3617 case WLC_SET_ANTDIV
:
3618 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3619 if ((val
< -1) || (val
> 3)) {
3620 bcmerror
= BCME_RANGE
;
3625 val
= ANT_RX_DIV_DEF
;
3627 wlc
->stf
->ant_rx_ovr
= (u8
) val
;
3628 wlc_phy_ant_rxdiv_set(wlc
->band
->pi
, (u8
) val
);
3631 case WLC_GET_RX_ANT
:{ /* get latest used rx antenna */
3634 if (!wlc
->pub
->up
) {
3635 bcmerror
= BCME_NOTUP
;
3639 rxstatus
= R_REG(wlc
->osh
, &wlc
->regs
->phyrxstatus0
);
3640 if (rxstatus
== 0xdead || rxstatus
== (u16
) -1) {
3641 bcmerror
= BCME_ERROR
;
3644 *pval
= (rxstatus
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0;
3649 case WLC_GET_UCANTDIV
:
3651 bcmerror
= BCME_NOCLK
;
3656 (wlc_bmac_mhf_get(wlc
->hw
, MHF1
, WLC_BAND_AUTO
) &
3660 case WLC_SET_UCANTDIV
:{
3661 if (!wlc
->pub
->up
) {
3662 bcmerror
= BCME_NOTUP
;
3666 /* if multiband, band must be locked */
3667 if (IS_MBAND_UNLOCKED(wlc
)) {
3668 bcmerror
= BCME_NOTBANDLOCKED
;
3672 /* 4322 supports antdiv in phy, no need to set it to ucode */
3673 if (WLCISNPHY(wlc
->band
)
3674 && D11REV_IS(wlc
->pub
->corerev
, 16)) {
3675 WL_ERROR(("wl%d: can't set ucantdiv for 4322\n",
3677 bcmerror
= BCME_UNSUPPORTED
;
3679 wlc_mhf(wlc
, MHF1
, MHF1_ANTDIV
,
3680 (val
? MHF1_ANTDIV
: 0), WLC_BAND_AUTO
);
3683 #endif /* defined(BCMDBG) */
3690 if (val
>= 1 && val
<= RETRY_SHORT_MAX
) {
3692 wlc
->SRL
= (u16
) val
;
3694 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3696 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3697 WLC_WME_RETRY_SHORT_SET(wlc
, ac
, wlc
->SRL
);
3699 wlc_wme_retries_write(wlc
);
3701 bcmerror
= BCME_RANGE
;
3709 if (val
>= 1 && val
<= 255) {
3711 wlc
->LRL
= (u16
) val
;
3713 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3715 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3716 WLC_WME_RETRY_LONG_SET(wlc
, ac
, wlc
->LRL
);
3718 wlc_wme_retries_write(wlc
);
3720 bcmerror
= BCME_RANGE
;
3724 *pval
= wlc
->band
->CWmin
;
3729 bcmerror
= BCME_NOCLK
;
3733 if (val
>= 1 && val
<= 255) {
3734 wlc_set_cwmin(wlc
, (u16
) val
);
3736 bcmerror
= BCME_RANGE
;
3740 *pval
= wlc
->band
->CWmax
;
3745 bcmerror
= BCME_NOCLK
;
3749 if (val
>= 255 && val
<= 2047) {
3750 wlc_set_cwmax(wlc
, (u16
) val
);
3752 bcmerror
= BCME_RANGE
;
3755 case WLC_GET_RADIO
: /* use mask if don't want to expose some internal bits */
3756 *pval
= wlc
->pub
->radio_disabled
;
3759 case WLC_SET_RADIO
:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3762 u16 radiomask
, radioval
;
3764 WL_RADIO_SW_DISABLE
| WL_RADIO_HW_DISABLE
;
3767 radiomask
= (val
& 0xffff0000) >> 16;
3768 radioval
= val
& 0x0000ffff;
3770 if ((radiomask
== 0) || (radiomask
& ~validbits
)
3771 || (radioval
& ~validbits
)
3772 || ((radioval
& ~radiomask
) != 0)) {
3773 WL_ERROR(("SET_RADIO with wrong bits 0x%x\n",
3775 bcmerror
= BCME_RANGE
;
3780 (wlc
->pub
->radio_disabled
& ~radiomask
) | radioval
;
3781 wlc
->pub
->radio_disabled
= new;
3783 wlc_radio_hwdisable_upd(wlc
);
3788 case WLC_GET_PHYTYPE
:
3789 *pval
= WLC_PHYTYPE(wlc
->band
->phytype
);
3794 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
))) {
3797 wsec_key_t
*src_key
= wlc
->wsec_keys
[val
];
3799 if (len
< (int)sizeof(key
)) {
3800 bcmerror
= BCME_BUFTOOSHORT
;
3804 bzero((char *)&key
, sizeof(key
));
3806 key
.index
= src_key
->id
;
3807 key
.len
= src_key
->len
;
3808 bcopy(src_key
->data
, key
.data
, key
.len
);
3809 key
.algo
= src_key
->algo
;
3810 if (WSEC_SOFTKEY(wlc
, src_key
, bsscfg
))
3811 key
.flags
|= WL_SOFT_KEY
;
3812 if (src_key
->flags
& WSEC_PRIMARY_KEY
)
3813 key
.flags
|= WL_PRIMARY_KEY
;
3815 bcopy(src_key
->ea
.octet
, key
.ea
.octet
,
3819 bcopy((char *)&key
, arg
, sizeof(key
));
3821 bcmerror
= BCME_BADKEYIDX
;
3823 #endif /* defined(BCMDBG) */
3827 wlc_iovar_op(wlc
, "wsec_key", NULL
, 0, arg
, len
, IOV_SET
,
3831 case WLC_GET_KEY_SEQ
:{
3834 if (len
< DOT11_WPA_KEY_RSC_LEN
) {
3835 bcmerror
= BCME_BUFTOOSHORT
;
3839 /* Return the key's tx iv as an EAPOL sequence counter.
3840 * This will be used to supply the RSC value to a supplicant.
3841 * The format is 8 bytes, with least significant in seq[0].
3844 key
= WSEC_KEY(wlc
, val
);
3845 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
)) &&
3847 u8 seq
[DOT11_WPA_KEY_RSC_LEN
];
3850 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3851 if ((bsscfg
->WPA_auth
& WPA_AUTH_NONE
)
3852 && ETHER_ISNULLADDR(&key
->ea
)) {
3853 lo
= bsscfg
->wpa_none_txiv
.lo
;
3854 hi
= bsscfg
->wpa_none_txiv
.hi
;
3860 /* format the buffer, low to high */
3862 seq
[1] = (lo
>> 8) & 0xff;
3864 seq
[3] = (hi
>> 8) & 0xff;
3865 seq
[4] = (hi
>> 16) & 0xff;
3866 seq
[5] = (hi
>> 24) & 0xff;
3870 bcopy((char *)seq
, arg
, sizeof(seq
));
3872 bcmerror
= BCME_BADKEYIDX
;
3877 case WLC_GET_CURR_RATESET
:{
3878 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3881 if (bsscfg
->associated
)
3882 rs
= ¤t_bss
->rateset
;
3884 rs
= &wlc
->default_bss
->rateset
;
3886 if (len
< (int)(rs
->count
+ sizeof(rs
->count
))) {
3887 bcmerror
= BCME_BUFTOOSHORT
;
3891 /* Copy only legacy rateset section */
3892 ret_rs
->count
= rs
->count
;
3893 bcopy(&rs
->rates
, &ret_rs
->rates
, rs
->count
);
3897 case WLC_GET_RATESET
:{
3899 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3901 bzero(&rs
, sizeof(wlc_rateset_t
));
3902 wlc_default_rateset(wlc
, (wlc_rateset_t
*) &rs
);
3904 if (len
< (int)(rs
.count
+ sizeof(rs
.count
))) {
3905 bcmerror
= BCME_BUFTOOSHORT
;
3909 /* Copy only legacy rateset section */
3910 ret_rs
->count
= rs
.count
;
3911 bcopy(&rs
.rates
, &ret_rs
->rates
, rs
.count
);
3915 case WLC_SET_RATESET
:{
3917 wl_rateset_t
*in_rs
= (wl_rateset_t
*) arg
;
3919 if (len
< (int)(in_rs
->count
+ sizeof(in_rs
->count
))) {
3920 bcmerror
= BCME_BUFTOOSHORT
;
3924 if (in_rs
->count
> WLC_NUMRATES
) {
3925 bcmerror
= BCME_BUFTOOLONG
;
3929 bzero(&rs
, sizeof(wlc_rateset_t
));
3931 /* Copy only legacy rateset section */
3932 rs
.count
= in_rs
->count
;
3933 bcopy(&in_rs
->rates
, &rs
.rates
, rs
.count
);
3935 /* merge rateset coming in with the current mcsset */
3936 if (N_ENAB(wlc
->pub
)) {
3937 if (bsscfg
->associated
)
3938 bcopy(¤t_bss
->rateset
.mcs
[0],
3939 rs
.mcs
, MCSSET_LEN
);
3941 bcopy(&wlc
->default_bss
->rateset
.mcs
[0],
3942 rs
.mcs
, MCSSET_LEN
);
3945 bcmerror
= wlc_set_rateset(wlc
, &rs
);
3948 wlc_ofdm_rateset_war(wlc
);
3953 case WLC_GET_BCNPRD
:
3954 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3955 *pval
= current_bss
->beacon_period
;
3957 *pval
= wlc
->default_bss
->beacon_period
;
3960 case WLC_SET_BCNPRD
:
3961 /* range [1, 0xffff] */
3962 if (val
>= DOT11_MIN_BEACON_PERIOD
3963 && val
<= DOT11_MAX_BEACON_PERIOD
) {
3964 wlc
->default_bss
->beacon_period
= (u16
) val
;
3966 bcmerror
= BCME_RANGE
;
3969 case WLC_GET_DTIMPRD
:
3970 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3971 *pval
= current_bss
->dtim_period
;
3973 *pval
= wlc
->default_bss
->dtim_period
;
3976 case WLC_SET_DTIMPRD
:
3977 /* range [1, 0xff] */
3978 if (val
>= DOT11_MIN_DTIM_PERIOD
3979 && val
<= DOT11_MAX_DTIM_PERIOD
) {
3980 wlc
->default_bss
->dtim_period
= (u8
) val
;
3982 bcmerror
= BCME_RANGE
;
3991 if ((val
>= PM_OFF
) && (val
<= PM_MAX
)) {
3995 /* Change watchdog driver to align watchdog with tbtt if possible */
3996 wlc_watchdog_upd(wlc
, PS_ALLOWED(wlc
));
3998 bcmerror
= BCME_ERROR
;
4000 #endif /* SUPPORT_PS */
4005 if (AP_ENAB(wlc
->pub
)) {
4006 bcmerror
= BCME_NOTSTA
;
4013 if (AP_ENAB(wlc
->pub
)) {
4014 bcmerror
= BCME_NOTSTA
;
4018 wlc
->wake
= val
? TRUE
: FALSE
;
4020 /* if down, we're done */
4024 /* apply to the mac */
4025 wlc_set_ps_ctrl(wlc
);
4028 #endif /* SUPPORT_PS */
4030 case WLC_GET_REVINFO
:
4031 bcmerror
= wlc_get_revision_info(wlc
, arg
, (uint
) len
);
4035 *pval
= (int)AP_ENAB(wlc
->pub
);
4039 if (bsscfg
->associated
)
4040 *pval
= (int)current_bss
->atim_window
;
4042 *pval
= (int)wlc
->default_bss
->atim_window
;
4046 wlc
->default_bss
->atim_window
= (u32
) val
;
4049 case WLC_GET_PKTCNTS
:{
4050 get_pktcnt_t
*pktcnt
= (get_pktcnt_t
*) pval
;
4051 if (WLC_UPDATE_STATS(wlc
))
4053 pktcnt
->rx_good_pkt
= WLCNTVAL(wlc
->pub
->_cnt
->rxframe
);
4054 pktcnt
->rx_bad_pkt
= WLCNTVAL(wlc
->pub
->_cnt
->rxerror
);
4055 pktcnt
->tx_good_pkt
=
4056 WLCNTVAL(wlc
->pub
->_cnt
->txfrmsnt
);
4057 pktcnt
->tx_bad_pkt
=
4058 WLCNTVAL(wlc
->pub
->_cnt
->txerror
) +
4059 WLCNTVAL(wlc
->pub
->_cnt
->txfail
);
4060 if (len
>= (int)sizeof(get_pktcnt_t
)) {
4061 /* Be backward compatible - only if buffer is large enough */
4062 pktcnt
->rx_ocast_good_pkt
=
4063 WLCNTVAL(wlc
->pub
->_cnt
->rxmfrmocast
);
4068 #ifdef SUPPORT_HWKEY
4071 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_GET
,
4077 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_SET
,
4081 case WLC_GET_WPA_AUTH
:
4082 *pval
= (int)bsscfg
->WPA_auth
;
4085 case WLC_SET_WPA_AUTH
:
4086 /* change of WPA_Auth modifies the PS_ALLOWED state */
4087 if (BSSCFG_STA(bsscfg
)) {
4088 bsscfg
->WPA_auth
= (u16
) val
;
4090 bsscfg
->WPA_auth
= (u16
) val
;
4092 #endif /* SUPPORT_HWKEY */
4094 case WLC_GET_BANDLIST
:
4095 /* count of number of bands, followed by each band type */
4096 *pval
++ = NBANDS(wlc
);
4097 *pval
++ = wlc
->band
->bandtype
;
4098 if (NBANDS(wlc
) > 1)
4099 *pval
++ = wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
;
4103 *pval
= wlc
->bandlocked
? wlc
->band
->bandtype
: WLC_BAND_AUTO
;
4106 case WLC_GET_PHYLIST
:
4108 unsigned char *cp
= arg
;
4110 bcmerror
= BCME_BUFTOOSHORT
;
4114 if (WLCISNPHY(wlc
->band
)) {
4116 } else if (WLCISLCNPHY(wlc
->band
)) {
4118 } else if (WLCISSSLPNPHY(wlc
->band
)) {
4125 case WLC_GET_SHORTSLOT
:
4126 *pval
= wlc
->shortslot
;
4129 case WLC_GET_SHORTSLOT_OVERRIDE
:
4130 *pval
= wlc
->shortslot_override
;
4133 case WLC_SET_SHORTSLOT_OVERRIDE
:
4134 if ((val
!= WLC_SHORTSLOT_AUTO
) &&
4135 (val
!= WLC_SHORTSLOT_OFF
) && (val
!= WLC_SHORTSLOT_ON
)) {
4136 bcmerror
= BCME_RANGE
;
4140 wlc
->shortslot_override
= (s8
) val
;
4142 /* shortslot is an 11g feature, so no more work if we are
4143 * currently on the 5G band
4145 if (BAND_5G(wlc
->band
->bandtype
))
4148 if (wlc
->pub
->up
&& wlc
->pub
->associated
) {
4149 /* let watchdog or beacon processing update shortslot */
4150 } else if (wlc
->pub
->up
) {
4151 /* unassociated shortslot is off */
4152 wlc_switch_shortslot(wlc
, FALSE
);
4154 /* driver is down, so just update the wlc_info value */
4155 if (wlc
->shortslot_override
== WLC_SHORTSLOT_AUTO
) {
4156 wlc
->shortslot
= FALSE
;
4159 (wlc
->shortslot_override
==
4166 case WLC_GET_LEGACY_ERP
:
4167 *pval
= wlc
->include_legacy_erp
;
4170 case WLC_SET_LEGACY_ERP
:
4171 if (wlc
->include_legacy_erp
== bool_val
)
4174 wlc
->include_legacy_erp
= bool_val
;
4176 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
4177 wlc_update_beacon(wlc
);
4178 wlc_update_probe_resp(wlc
, TRUE
);
4183 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
4184 *pval
= wlc
->band
->gmode
;
4185 else if (NBANDS(wlc
) > 1)
4186 *pval
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
;
4190 if (!wlc
->pub
->associated
)
4191 bcmerror
= wlc_set_gmode(wlc
, (u8
) val
, TRUE
);
4193 bcmerror
= BCME_ASSOCIATED
;
4198 case WLC_GET_GMODE_PROTECTION
:
4199 *pval
= wlc
->protection
->_g
;
4202 case WLC_GET_PROTECTION_CONTROL
:
4203 *pval
= wlc
->protection
->overlap
;
4206 case WLC_SET_PROTECTION_CONTROL
:
4207 if ((val
!= WLC_PROTECTION_CTL_OFF
) &&
4208 (val
!= WLC_PROTECTION_CTL_LOCAL
) &&
4209 (val
!= WLC_PROTECTION_CTL_OVERLAP
)) {
4210 bcmerror
= BCME_RANGE
;
4214 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, (s8
) val
);
4216 /* Current g_protection will sync up to the specified control alg in watchdog
4217 * if the driver is up and associated.
4218 * If the driver is down or not associated, the control setting has no effect.
4222 case WLC_GET_GMODE_PROTECTION_OVERRIDE
:
4223 *pval
= wlc
->protection
->g_override
;
4226 case WLC_SET_GMODE_PROTECTION_OVERRIDE
:
4227 if ((val
!= WLC_PROTECTION_AUTO
) &&
4228 (val
!= WLC_PROTECTION_OFF
) && (val
!= WLC_PROTECTION_ON
)) {
4229 bcmerror
= BCME_RANGE
;
4233 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, (s8
) val
);
4237 case WLC_SET_SUP_RATESET_OVERRIDE
:{
4238 wlc_rateset_t rs
, new;
4241 if (len
< (int)sizeof(wlc_rateset_t
)) {
4242 bcmerror
= BCME_BUFTOOSHORT
;
4245 bcopy((char *)arg
, (char *)&rs
, sizeof(wlc_rateset_t
));
4247 /* check for bad count value */
4248 if (rs
.count
> WLC_NUMRATES
) {
4249 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4253 /* this command is only appropriate for gmode operation */
4254 if (!(wlc
->band
->gmode
||
4256 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4257 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4261 /* check for an empty rateset to clear the override */
4262 if (rs
.count
== 0) {
4263 bzero(&wlc
->sup_rates_override
,
4264 sizeof(wlc_rateset_t
));
4268 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4269 wlc_rateset_filter(&rs
, &new, FALSE
, WLC_RATES_CCK_OFDM
,
4270 RATE_MASK
, BSS_N_ENAB(wlc
, bsscfg
));
4271 wlc_rate_hwrs_filter_sort_validate(&new,
4274 wlc
->stf
->txstreams
);
4275 if (rs
.count
!= new.count
) {
4276 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4280 /* apply new rateset to the override */
4281 bcopy((char *)&new, (char *)&wlc
->sup_rates_override
,
4282 sizeof(wlc_rateset_t
));
4284 /* update bcn and probe resp if needed */
4285 if (wlc
->pub
->up
&& AP_ENAB(wlc
->pub
)
4286 && wlc
->pub
->associated
) {
4287 wlc_update_beacon(wlc
);
4288 wlc_update_probe_resp(wlc
, TRUE
);
4293 case WLC_GET_SUP_RATESET_OVERRIDE
:
4294 /* this command is only appropriate for gmode operation */
4295 if (!(wlc
->band
->gmode
||
4297 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4298 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4301 if (len
< (int)sizeof(wlc_rateset_t
)) {
4302 bcmerror
= BCME_BUFTOOSHORT
;
4305 bcopy((char *)&wlc
->sup_rates_override
, (char *)arg
,
4306 sizeof(wlc_rateset_t
));
4310 case WLC_GET_PRB_RESP_TIMEOUT
:
4311 *pval
= wlc
->prb_resp_timeout
;
4314 case WLC_SET_PRB_RESP_TIMEOUT
:
4316 bcmerror
= BCME_NOTDOWN
;
4319 if (val
< 0 || val
>= 0xFFFF) {
4320 bcmerror
= BCME_RANGE
; /* bad value */
4323 wlc
->prb_resp_timeout
= (u16
) val
;
4326 case WLC_GET_KEY_PRIMARY
:{
4329 /* treat the 'val' parm as the key id */
4330 key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4332 *pval
= key
->id
== val
? TRUE
: FALSE
;
4334 bcmerror
= BCME_BADKEYIDX
;
4339 case WLC_SET_KEY_PRIMARY
:{
4340 wsec_key_t
*key
, *old_key
;
4342 bcmerror
= BCME_BADKEYIDX
;
4344 /* treat the 'val' parm as the key id */
4345 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
4346 key
= bsscfg
->bss_def_keys
[i
];
4347 if (key
!= NULL
&& key
->id
== val
) {
4348 old_key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4349 if (old_key
!= NULL
)
4352 key
->flags
|= WSEC_PRIMARY_KEY
;
4353 bsscfg
->wsec_index
= i
;
4369 /* validate the name value */
4371 for (i
= 0; i
< (uint
) len
&& *name
!= '\0';
4375 if (i
== (uint
) len
) {
4376 bcmerror
= BCME_BUFTOOSHORT
;
4379 i
++; /* include the null in the string length */
4381 if (cmd
== WLC_GET_VAR
) {
4383 wlc_iovar_op(wlc
, arg
,
4384 (void *)((s8
*) arg
+ i
),
4385 len
- i
, arg
, len
, IOV_GET
,
4389 wlc_iovar_op(wlc
, arg
, NULL
, 0,
4390 (void *)((s8
*) arg
+ i
),
4391 len
- i
, IOV_SET
, wlcif
);
4396 case WLC_SET_WSEC_PMK
:
4397 bcmerror
= BCME_UNSUPPORTED
;
4401 case WLC_CURRENT_PWR
:
4403 bcmerror
= BCME_NOTUP
;
4405 bcmerror
= wlc_get_current_txpwr(wlc
, arg
, len
);
4410 WL_ERROR(("%s: WLC_LAST\n", __func__
));
4415 if (VALID_BCMERROR(bcmerror
))
4416 wlc
->pub
->bcmerror
= bcmerror
;
4423 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4424 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4425 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4427 if (!(wlc
->pub
->hw_off
))
4428 ASSERT(wlc_bmac_taclear(wlc
->hw
, ta_ok
) || !ta_ok
);
4435 /* consolidated register access ioctl error checking */
4436 int wlc_iocregchk(wlc_info_t
*wlc
, uint band
)
4438 /* if band is specified, it must be the current band */
4439 if ((band
!= WLC_BAND_AUTO
) && (band
!= (uint
) wlc
->band
->bandtype
))
4440 return BCME_BADBAND
;
4442 /* if multiband and band is not specified, band must be locked */
4443 if ((band
== WLC_BAND_AUTO
) && IS_MBAND_UNLOCKED(wlc
))
4444 return BCME_NOTBANDLOCKED
;
4446 /* must have core clocks */
4452 #endif /* defined(BCMDBG) */
4455 /* For some ioctls, make sure that the pi pointer matches the current phy */
4456 int wlc_iocpichk(wlc_info_t
*wlc
, uint phytype
)
4458 if (wlc
->band
->phytype
!= phytype
)
4459 return BCME_BADBAND
;
4464 /* Look up the given var name in the given table */
4465 static const bcm_iovar_t
*wlc_iovar_lookup(const bcm_iovar_t
*table
,
4468 const bcm_iovar_t
*vi
;
4469 const char *lookup_name
;
4471 /* skip any ':' delimited option prefixes */
4472 lookup_name
= strrchr(name
, ':');
4473 if (lookup_name
!= NULL
)
4478 ASSERT(table
!= NULL
);
4480 for (vi
= table
; vi
->name
; vi
++) {
4481 if (!strcmp(vi
->name
, lookup_name
))
4484 /* ran to end of table */
4486 return NULL
; /* var name not found */
4489 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4490 int wlc_iovar_getint(wlc_info_t
*wlc
, const char *name
, int *arg
)
4492 return wlc_iovar_op(wlc
, name
, NULL
, 0, arg
, sizeof(int32
), IOV_GET
,
4496 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4497 int wlc_iovar_setint(wlc_info_t
*wlc
, const char *name
, int arg
)
4499 return wlc_iovar_op(wlc
, name
, NULL
, 0, (void *)&arg
, sizeof(arg
),
4503 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4504 int wlc_iovar_gets8(wlc_info_t
*wlc
, const char *name
, s8
*arg
)
4510 wlc_iovar_op(wlc
, name
, NULL
, 0, &iovar_int
, sizeof(iovar_int
),
4513 *arg
= (s8
) iovar_int
;
4519 * register iovar table, watchdog and down handlers.
4520 * calling function must keep 'iovars' until wlc_module_unregister is called.
4521 * 'iovar' must have the last entry's name field being NULL as terminator.
4524 BCMATTACHFN(wlc_module_register
) (wlc_pub_t
*pub
, const bcm_iovar_t
*iovars
,
4525 const char *name
, void *hdl
, iovar_fn_t i_fn
,
4526 watchdog_fn_t w_fn
, down_fn_t d_fn
) {
4527 wlc_info_t
*wlc
= (wlc_info_t
*) pub
->wlc
;
4530 ASSERT(name
!= NULL
);
4531 ASSERT(i_fn
!= NULL
|| w_fn
!= NULL
|| d_fn
!= NULL
);
4533 /* find an empty entry and just add, no duplication check! */
4534 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4535 if (wlc
->modulecb
[i
].name
[0] == '\0') {
4536 strncpy(wlc
->modulecb
[i
].name
, name
,
4537 sizeof(wlc
->modulecb
[i
].name
) - 1);
4538 wlc
->modulecb
[i
].iovars
= iovars
;
4539 wlc
->modulecb
[i
].hdl
= hdl
;
4540 wlc
->modulecb
[i
].iovar_fn
= i_fn
;
4541 wlc
->modulecb
[i
].watchdog_fn
= w_fn
;
4542 wlc
->modulecb
[i
].down_fn
= d_fn
;
4547 /* it is time to increase the capacity */
4548 ASSERT(i
< WLC_MAXMODULES
);
4549 return BCME_NORESOURCE
;
4552 /* unregister module callbacks */
4554 BCMATTACHFN(wlc_module_unregister
) (wlc_pub_t
*pub
, const char *name
,
4556 wlc_info_t
*wlc
= (wlc_info_t
*) pub
->wlc
;
4560 return BCME_NOTFOUND
;
4562 ASSERT(name
!= NULL
);
4564 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4565 if (!strcmp(wlc
->modulecb
[i
].name
, name
) &&
4566 (wlc
->modulecb
[i
].hdl
== hdl
)) {
4567 bzero(&wlc
->modulecb
[i
], sizeof(modulecb_t
));
4572 /* table not found! */
4573 return BCME_NOTFOUND
;
4576 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4577 static void wlc_wme_retries_write(wlc_info_t
*wlc
)
4581 /* Need clock to do this */
4585 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
4586 wlc_write_shm(wlc
, M_AC_TXLMT_ADDR(ac
), wlc
->wme_retries
[ac
]);
4590 /* Get or set an iovar. The params/p_len pair specifies any additional
4591 * qualifying parameters (e.g. an "element index") for a get, while the
4592 * arg/len pair is the buffer for the value to be set or retrieved.
4593 * Operation (get/set) is specified by the last argument.
4594 * interface context provided by wlcif
4596 * All pointers may point into the same buffer.
4599 wlc_iovar_op(wlc_info_t
*wlc
, const char *name
,
4600 void *params
, int p_len
, void *arg
, int len
,
4601 bool set
, struct wlc_if
*wlcif
)
4605 const bcm_iovar_t
*vi
= NULL
;
4609 ASSERT(name
!= NULL
);
4613 /* Get MUST have return space */
4614 ASSERT(set
|| (arg
&& len
));
4616 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
4618 /* Set does NOT take qualifiers */
4619 ASSERT(!set
|| (!params
&& !p_len
));
4621 if (!set
&& (len
== sizeof(int)) &&
4622 !(ISALIGNED((uintptr
) (arg
), (uint
) sizeof(int)))) {
4623 WL_ERROR(("wl%d: %s unaligned get ptr for %s\n",
4624 wlc
->pub
->unit
, __func__
, name
));
4628 /* find the given iovar name */
4629 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4630 if (!wlc
->modulecb
[i
].iovars
)
4632 vi
= wlc_iovar_lookup(wlc
->modulecb
[i
].iovars
, name
);
4636 /* iovar name not found */
4637 if (i
>= WLC_MAXMODULES
) {
4638 err
= BCME_UNSUPPORTED
;
4639 #ifdef WLC_HIGH_ONLY
4641 bcmsdh_iovar_op(wlc
->btparam
, name
, params
, p_len
, arg
, len
,
4647 /* set up 'params' pointer in case this is a set command so that
4648 * the convenience int and bool code can be common to set and get
4650 if (params
== NULL
) {
4655 if (vi
->type
== IOVT_VOID
)
4657 else if (vi
->type
== IOVT_BUFFER
)
4660 /* all other types are integer sized */
4661 val_size
= sizeof(int);
4663 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
4665 /* Do the actual parameter implementation */
4666 err
= wlc
->modulecb
[i
].iovar_fn(wlc
->modulecb
[i
].hdl
, vi
, actionid
,
4667 name
, params
, p_len
, arg
, len
, val_size
,
4675 wlc_iovar_check(wlc_pub_t
*pub
, const bcm_iovar_t
*vi
, void *arg
, int len
,
4678 wlc_info_t
*wlc
= (wlc_info_t
*) pub
->wlc
;
4682 /* check generic condition flags */
4684 if (((vi
->flags
& IOVF_SET_DOWN
) && wlc
->pub
->up
) ||
4685 ((vi
->flags
& IOVF_SET_UP
) && !wlc
->pub
->up
)) {
4686 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4687 } else if ((vi
->flags
& IOVF_SET_BAND
)
4688 && IS_MBAND_UNLOCKED(wlc
)) {
4689 err
= BCME_NOTBANDLOCKED
;
4690 } else if ((vi
->flags
& IOVF_SET_CLK
) && !wlc
->clk
) {
4694 if (((vi
->flags
& IOVF_GET_DOWN
) && wlc
->pub
->up
) ||
4695 ((vi
->flags
& IOVF_GET_UP
) && !wlc
->pub
->up
)) {
4696 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4697 } else if ((vi
->flags
& IOVF_GET_BAND
)
4698 && IS_MBAND_UNLOCKED(wlc
)) {
4699 err
= BCME_NOTBANDLOCKED
;
4700 } else if ((vi
->flags
& IOVF_GET_CLK
) && !wlc
->clk
) {
4708 /* length check on io buf */
4709 err
= bcm_iovar_lencheck(vi
, arg
, len
, set
);
4713 /* On set, check value ranges for integer types */
4723 bcopy(arg
, &int_val
, sizeof(int));
4724 err
= wlc_iovar_rangecheck(wlc
, int_val
, vi
);
4732 /* handler for iovar table wlc_iovars */
4734 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4735 * iovar case, the switch statement maps the iovar id into separate get
4736 * and set values. If you add a new iovar to the switch you MUST use
4737 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4739 * Please use params for additional qualifying parameters.
4742 wlc_doiovar(void *hdl
, const bcm_iovar_t
*vi
, u32 actionid
,
4743 const char *name
, void *params
, uint p_len
, void *arg
, int len
,
4744 int val_size
, struct wlc_if
*wlcif
)
4746 wlc_info_t
*wlc
= hdl
;
4747 wlc_bsscfg_t
*bsscfg
;
4754 wlc_bss_info_t
*current_bss
;
4756 WL_TRACE(("wl%d: %s\n", wlc
->pub
->unit
, __func__
));
4761 err
= wlc_iovar_check(wlc
->pub
, vi
, arg
, len
, IOV_ISSET(actionid
));
4765 /* convenience int and bool vals for first 8 bytes of buffer */
4766 if (p_len
>= (int)sizeof(int_val
))
4767 bcopy(params
, &int_val
, sizeof(int_val
));
4769 if (p_len
>= (int)sizeof(int_val
) * 2)
4770 bcopy((void *)((uintptr
) params
+ sizeof(int_val
)), &int_val2
,
4773 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4774 ret_int_ptr
= (int32
*) arg
;
4776 bool_val
= (int_val
!= 0) ? TRUE
: FALSE
;
4777 bool_val2
= (int_val2
!= 0) ? TRUE
: FALSE
;
4779 WL_TRACE(("wl%d: %s: id %d\n", wlc
->pub
->unit
, __func__
,
4781 /* Do the actual parameter implementation */
4784 case IOV_GVAL(IOV_QTXPOWER
):{
4788 err
= wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
,
4793 /* Return qdbm units */
4795 qdbm
| (override
? WL_TXPWR_OVERRIDE
: 0);
4799 /* As long as override is false, this only sets the *user* targets.
4800 User can twiddle this all he wants with no harm.
4801 wlc_phy_txpower_set() explicitly sets override to false if
4802 not internal or test.
4804 case IOV_SVAL(IOV_QTXPOWER
):{
4808 /* Remove override bit and clip to max qdbm value */
4810 (u8
) MIN((int_val
& ~WL_TXPWR_OVERRIDE
), 0xff);
4811 /* Extract override setting */
4812 override
= (int_val
& WL_TXPWR_OVERRIDE
) ? TRUE
: FALSE
;
4814 wlc_phy_txpower_set(wlc
->band
->pi
, qdbm
, override
);
4818 case IOV_GVAL(IOV_MPC
):
4819 *ret_int_ptr
= (int32
) wlc
->mpc
;
4822 case IOV_SVAL(IOV_MPC
):
4823 wlc
->mpc
= bool_val
;
4824 wlc_radio_mpc_upd(wlc
);
4828 case IOV_GVAL(IOV_BCN_LI_BCN
):
4829 *ret_int_ptr
= wlc
->bcn_li_bcn
;
4832 case IOV_SVAL(IOV_BCN_LI_BCN
):
4833 wlc
->bcn_li_bcn
= (u8
) int_val
;
4835 wlc_bcn_li_upd(wlc
);
4839 WL_ERROR(("wl%d: %s: unsupported\n", wlc
->pub
->unit
, __func__
));
4840 err
= BCME_UNSUPPORTED
;
4844 goto exit
; /* avoid unused label warning */
4851 wlc_iovar_rangecheck(wlc_info_t
*wlc
, u32 val
, const bcm_iovar_t
*vi
)
4857 /* Only ranged integers are checked */
4860 max_val
|= 0x7fffffff;
4863 max_val
|= 0x00007fff;
4866 max_val
|= 0x0000007f;
4868 if (vi
->flags
& IOVF_NTRL
)
4870 else if (vi
->flags
& IOVF_WHL
)
4872 /* Signed values are checked against max_val and min_val */
4873 if ((int32
) val
< (int32
) min_val
4874 || (int32
) val
> (int32
) max_val
)
4879 max_val
|= 0xffffffff;
4882 max_val
|= 0x0000ffff;
4885 max_val
|= 0x000000ff;
4886 if (vi
->flags
& IOVF_NTRL
)
4888 if ((val
< min_val
) || (val
> max_val
))
4897 static const char *supr_reason
[] = {
4898 "None", "PMQ Entry", "Flush request",
4899 "Previous frag failure", "Channel mismatch",
4900 "Lifetime Expiry", "Underflow"
4903 static void wlc_print_txs_status(u16 s
)
4905 printf("[15:12] %d frame attempts\n", (s
& TX_STATUS_FRM_RTX_MASK
) >>
4906 TX_STATUS_FRM_RTX_SHIFT
);
4907 printf(" [11:8] %d rts attempts\n", (s
& TX_STATUS_RTS_RTX_MASK
) >>
4908 TX_STATUS_RTS_RTX_SHIFT
);
4909 printf(" [7] %d PM mode indicated\n",
4910 ((s
& TX_STATUS_PMINDCTD
) ? 1 : 0));
4911 printf(" [6] %d intermediate status\n",
4912 ((s
& TX_STATUS_INTERMEDIATE
) ? 1 : 0));
4913 printf(" [5] %d AMPDU\n", (s
& TX_STATUS_AMPDU
) ? 1 : 0);
4914 printf(" [4:2] %d Frame Suppressed Reason (%s)\n",
4915 ((s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
),
4916 supr_reason
[(s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
]);
4917 printf(" [1] %d acked\n", ((s
& TX_STATUS_ACK_RCV
) ? 1 : 0));
4921 void wlc_print_txstatus(tx_status_t
*txs
)
4924 u16 s
= txs
->status
;
4925 u16 ackphyrxsh
= txs
->ackphyrxsh
;
4927 printf("\ntxpkt (MPDU) Complete\n");
4929 printf("FrameID: %04x ", txs
->frameid
);
4930 printf("TxStatus: %04x", s
);
4933 wlc_print_txs_status(s
);
4935 printf("LastTxTime: %04x ", txs
->lasttxtime
);
4936 printf("Seq: %04x ", txs
->sequence
);
4937 printf("PHYTxStatus: %04x ", txs
->phyerr
);
4938 printf("RxAckRSSI: %04x ",
4939 (ackphyrxsh
& PRXS1_JSSI_MASK
) >> PRXS1_JSSI_SHIFT
);
4940 printf("RxAckSQ: %04x", (ackphyrxsh
& PRXS1_SQ_MASK
) >> PRXS1_SQ_SHIFT
);
4942 #endif /* defined(BCMDBG) */
4945 #define MACSTATUPD(name) \
4946 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4948 void wlc_statsupd(wlc_info_t
*wlc
)
4957 /* if driver down, make no sense to update stats */
4962 /* save last rx fifo 0 overflow count */
4963 rxf0ovfl
= wlc
->core
->macstat_snapshot
->rxf0ovfl
;
4965 /* save last tx fifo underflow count */
4966 for (i
= 0; i
< NFIFO
; i
++)
4967 txfunfl
[i
] = wlc
->core
->macstat_snapshot
->txfunfl
[i
];
4971 /* check for rx fifo 0 overflow */
4972 delta
= (u16
) (wlc
->core
->macstat_snapshot
->rxf0ovfl
- rxf0ovfl
);
4974 WL_ERROR(("wl%d: %u rx fifo 0 overflows!\n", wlc
->pub
->unit
,
4977 /* check for tx fifo underflows */
4978 for (i
= 0; i
< NFIFO
; i
++) {
4980 (u16
) (wlc
->core
->macstat_snapshot
->txfunfl
[i
] -
4983 WL_ERROR(("wl%d: %u tx fifo %d underflows!\n",
4984 wlc
->pub
->unit
, delta
, i
));
4988 /* dot11 counter update */
4990 WLCNTSET(wlc
->pub
->_cnt
->txrts
,
4991 (wlc
->pub
->_cnt
->rxctsucast
-
4992 wlc
->pub
->_cnt
->d11cnt_txrts_off
));
4993 WLCNTSET(wlc
->pub
->_cnt
->rxcrc
,
4994 (wlc
->pub
->_cnt
->rxbadfcs
- wlc
->pub
->_cnt
->d11cnt_rxcrc_off
));
4995 WLCNTSET(wlc
->pub
->_cnt
->txnocts
,
4996 ((wlc
->pub
->_cnt
->txrtsfrm
- wlc
->pub
->_cnt
->rxctsucast
) -
4997 wlc
->pub
->_cnt
->d11cnt_txnocts_off
));
4999 /* merge counters from dma module */
5000 for (i
= 0; i
< NFIFO
; i
++) {
5001 if (wlc
->hw
->di
[i
]) {
5002 WLCNTADD(wlc
->pub
->_cnt
->txnobuf
,
5003 (wlc
->hw
->di
[i
])->txnobuf
);
5004 WLCNTADD(wlc
->pub
->_cnt
->rxnobuf
,
5005 (wlc
->hw
->di
[i
])->rxnobuf
);
5006 WLCNTADD(wlc
->pub
->_cnt
->rxgiant
,
5007 (wlc
->hw
->di
[i
])->rxgiants
);
5008 dma_counterreset(wlc
->hw
->di
[i
]);
5013 * Aggregate transmit and receive errors that probably resulted
5014 * in the loss of a frame are computed on the fly.
5016 WLCNTSET(wlc
->pub
->_cnt
->txerror
,
5017 wlc
->pub
->_cnt
->txnobuf
+ wlc
->pub
->_cnt
->txnoassoc
+
5018 wlc
->pub
->_cnt
->txuflo
+ wlc
->pub
->_cnt
->txrunt
+
5019 wlc
->pub
->_cnt
->dmade
+ wlc
->pub
->_cnt
->dmada
+
5020 wlc
->pub
->_cnt
->dmape
);
5021 WLCNTSET(wlc
->pub
->_cnt
->rxerror
,
5022 wlc
->pub
->_cnt
->rxoflo
+ wlc
->pub
->_cnt
->rxnobuf
+
5023 wlc
->pub
->_cnt
->rxfragerr
+ wlc
->pub
->_cnt
->rxrunt
+
5024 wlc
->pub
->_cnt
->rxgiant
+ wlc
->pub
->_cnt
->rxnoscb
+
5025 wlc
->pub
->_cnt
->rxbadsrcmac
);
5026 for (i
= 0; i
< NFIFO
; i
++)
5027 WLCNTADD(wlc
->pub
->_cnt
->rxerror
, wlc
->pub
->_cnt
->rxuflo
[i
]);
5030 bool wlc_chipmatch(u16 vendor
, u16 device
)
5032 if (vendor
!= VENDOR_BROADCOM
) {
5033 WL_ERROR(("wlc_chipmatch: unknown vendor id %04x\n", vendor
));
5037 if ((device
== BCM43224_D11N_ID
) || (device
== BCM43225_D11N2G_ID
))
5040 if (device
== BCM4313_D11N2G_ID
)
5042 if ((device
== BCM43236_D11N_ID
) || (device
== BCM43236_D11N2G_ID
))
5045 WL_ERROR(("wlc_chipmatch: unknown device id %04x\n", device
));
5050 void wlc_print_txdesc(d11txh_t
*txh
)
5052 u16 mtcl
= ltoh16(txh
->MacTxControlLow
);
5053 u16 mtch
= ltoh16(txh
->MacTxControlHigh
);
5054 u16 mfc
= ltoh16(txh
->MacFrameControl
);
5055 u16 tfest
= ltoh16(txh
->TxFesTimeNormal
);
5056 u16 ptcw
= ltoh16(txh
->PhyTxControlWord
);
5057 u16 ptcw_1
= ltoh16(txh
->PhyTxControlWord_1
);
5058 u16 ptcw_1_Fbr
= ltoh16(txh
->PhyTxControlWord_1_Fbr
);
5059 u16 ptcw_1_Rts
= ltoh16(txh
->PhyTxControlWord_1_Rts
);
5060 u16 ptcw_1_FbrRts
= ltoh16(txh
->PhyTxControlWord_1_FbrRts
);
5061 u16 mainrates
= ltoh16(txh
->MainRates
);
5062 u16 xtraft
= ltoh16(txh
->XtraFrameTypes
);
5064 u8
*ra
= txh
->TxFrameRA
;
5065 u16 tfestfb
= ltoh16(txh
->TxFesTimeFallback
);
5066 u8
*rtspfb
= txh
->RTSPLCPFallback
;
5067 u16 rtsdfb
= ltoh16(txh
->RTSDurFallback
);
5068 u8
*fragpfb
= txh
->FragPLCPFallback
;
5069 u16 fragdfb
= ltoh16(txh
->FragDurFallback
);
5070 u16 mmodelen
= ltoh16(txh
->MModeLen
);
5071 u16 mmodefbrlen
= ltoh16(txh
->MModeFbrLen
);
5072 u16 tfid
= ltoh16(txh
->TxFrameID
);
5073 u16 txs
= ltoh16(txh
->TxStatus
);
5074 u16 mnmpdu
= ltoh16(txh
->MaxNMpdus
);
5075 u16 mabyte
= ltoh16(txh
->MaxABytes_MRT
);
5076 u16 mabyte_f
= ltoh16(txh
->MaxABytes_FBR
);
5077 u16 mmbyte
= ltoh16(txh
->MinMBytes
);
5079 u8
*rtsph
= txh
->RTSPhyHeader
;
5080 struct dot11_rts_frame rts
= txh
->rts_frame
;
5083 /* add plcp header along with txh descriptor */
5084 prhex("Raw TxDesc + plcp header", (unsigned char *) txh
, sizeof(d11txh_t
) + 48);
5086 printf("TxCtlLow: %04x ", mtcl
);
5087 printf("TxCtlHigh: %04x ", mtch
);
5088 printf("FC: %04x ", mfc
);
5089 printf("FES Time: %04x\n", tfest
);
5090 printf("PhyCtl: %04x%s ", ptcw
,
5091 (ptcw
& PHY_TXC_SHORT_HDR
) ? " short" : "");
5092 printf("PhyCtl_1: %04x ", ptcw_1
);
5093 printf("PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr
);
5094 printf("PhyCtl_1_Rts: %04x ", ptcw_1_Rts
);
5095 printf("PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts
);
5096 printf("MainRates: %04x ", mainrates
);
5097 printf("XtraFrameTypes: %04x ", xtraft
);
5100 bcm_format_hex(hexbuf
, iv
, sizeof(txh
->IV
));
5101 printf("SecIV: %s\n", hexbuf
);
5102 bcm_format_hex(hexbuf
, ra
, sizeof(txh
->TxFrameRA
));
5103 printf("RA: %s\n", hexbuf
);
5105 printf("Fb FES Time: %04x ", tfestfb
);
5106 bcm_format_hex(hexbuf
, rtspfb
, sizeof(txh
->RTSPLCPFallback
));
5107 printf("RTS PLCP: %s ", hexbuf
);
5108 printf("RTS DUR: %04x ", rtsdfb
);
5109 bcm_format_hex(hexbuf
, fragpfb
, sizeof(txh
->FragPLCPFallback
));
5110 printf("PLCP: %s ", hexbuf
);
5111 printf("DUR: %04x", fragdfb
);
5114 printf("MModeLen: %04x ", mmodelen
);
5115 printf("MModeFbrLen: %04x\n", mmodefbrlen
);
5117 printf("FrameID: %04x\n", tfid
);
5118 printf("TxStatus: %04x\n", txs
);
5120 printf("MaxNumMpdu: %04x\n", mnmpdu
);
5121 printf("MaxAggbyte: %04x\n", mabyte
);
5122 printf("MaxAggbyte_fb: %04x\n", mabyte_f
);
5123 printf("MinByte: %04x\n", mmbyte
);
5125 bcm_format_hex(hexbuf
, rtsph
, sizeof(txh
->RTSPhyHeader
));
5126 printf("RTS PLCP: %s ", hexbuf
);
5127 bcm_format_hex(hexbuf
, (u8
*) &rts
, sizeof(txh
->rts_frame
));
5128 printf("RTS Frame: %s", hexbuf
);
5132 #endif /* defined(BCMDBG) */
5135 void wlc_print_rxh(d11rxhdr_t
*rxh
)
5137 u16 len
= rxh
->RxFrameSize
;
5138 u16 phystatus_0
= rxh
->PhyRxStatus_0
;
5139 u16 phystatus_1
= rxh
->PhyRxStatus_1
;
5140 u16 phystatus_2
= rxh
->PhyRxStatus_2
;
5141 u16 phystatus_3
= rxh
->PhyRxStatus_3
;
5142 u16 macstatus1
= rxh
->RxStatus1
;
5143 u16 macstatus2
= rxh
->RxStatus2
;
5146 static const bcm_bit_desc_t macstat_flags
[] = {
5147 {RXS_FCSERR
, "FCSErr"},
5148 {RXS_RESPFRAMETX
, "Reply"},
5149 {RXS_PBPRES
, "PADDING"},
5150 {RXS_DECATMPT
, "DeCr"},
5151 {RXS_DECERR
, "DeCrErr"},
5152 {RXS_BCNSENT
, "Bcn"},
5156 prhex("Raw RxDesc", (unsigned char *) rxh
, sizeof(d11rxhdr_t
));
5158 bcm_format_flags(macstat_flags
, macstatus1
, flagstr
, 64);
5160 snprintf(lenbuf
, sizeof(lenbuf
), "0x%x", len
);
5162 printf("RxFrameSize: %6s (%d)%s\n", lenbuf
, len
,
5163 (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
) ? " short preamble" : "");
5164 printf("RxPHYStatus: %04x %04x %04x %04x\n",
5165 phystatus_0
, phystatus_1
, phystatus_2
, phystatus_3
);
5166 printf("RxMACStatus: %x %s\n", macstatus1
, flagstr
);
5167 printf("RXMACaggtype: %x\n", (macstatus2
& RXS_AGGTYPE_MASK
));
5168 printf("RxTSFTime: %04x\n", rxh
->RxTSFTime
);
5170 #endif /* defined(BCMDBG) */
5173 int wlc_format_ssid(char *buf
, const unsigned char ssid
[], uint ssid_len
)
5177 char *endp
= buf
+ SSID_FMT_BUF_LEN
;
5179 if (ssid_len
> DOT11_MAX_SSID_LEN
)
5180 ssid_len
= DOT11_MAX_SSID_LEN
;
5182 for (i
= 0; i
< ssid_len
; i
++) {
5187 } else if (isprint((unsigned char) c
)) {
5190 p
+= snprintf(p
, (endp
- p
), "\\x%02X", c
);
5196 return (int)(p
- buf
);
5198 #endif /* defined(BCMDBG) */
5200 u16
wlc_rate_shm_offset(wlc_info_t
*wlc
, u8 rate
)
5202 return wlc_bmac_rate_shm_offset(wlc
->hw
, rate
);
5205 /* Callback for device removed */
5206 #if defined(WLC_HIGH_ONLY)
5207 void wlc_device_removed(void *arg
)
5209 wlc_info_t
*wlc
= (wlc_info_t
*) arg
;
5211 wlc
->device_present
= FALSE
;
5213 #endif /* WLC_HIGH_ONLY */
5216 * Attempts to queue a packet onto a multiple-precedence queue,
5217 * if necessary evicting a lower precedence packet from the queue.
5219 * 'prec' is the precedence number that has already been mapped
5220 * from the packet priority.
5222 * Returns TRUE if packet consumed (queued), FALSE if not.
5225 wlc_prec_enq(wlc_info_t
*wlc
, struct pktq
*q
, void *pkt
, int prec
)
5227 return wlc_prec_enq_head(wlc
, q
, pkt
, prec
, FALSE
);
5231 wlc_prec_enq_head(wlc_info_t
*wlc
, struct pktq
*q
, void *pkt
, int prec
,
5235 int eprec
= -1; /* precedence to evict from */
5237 /* Determine precedence from which to evict packet, if any */
5238 if (pktq_pfull(q
, prec
))
5240 else if (pktq_full(q
)) {
5241 p
= pktq_peek_tail(q
, &eprec
);
5244 WL_ERROR(("%s: Failing: eprec %d > prec %d\n", __func__
,
5250 /* Evict if needed */
5252 bool discard_oldest
;
5254 /* Detect queueing to unconfigured precedence */
5255 ASSERT(!pktq_pempty(q
, eprec
));
5257 discard_oldest
= AC_BITMAP_TST(wlc
->wme_dp
, eprec
);
5259 /* Refuse newer packet unless configured to discard oldest */
5260 if (eprec
== prec
&& !discard_oldest
) {
5261 WL_ERROR(("%s: No where to go, prec == %d\n", __func__
,
5266 /* Evict packet according to discard policy */
5267 p
= discard_oldest
? pktq_pdeq(q
, eprec
) : pktq_pdeq_tail(q
,
5271 /* Increment wme stats */
5272 if (WME_ENAB(wlc
->pub
)) {
5273 WLCNTINCR(wlc
->pub
->_wme_cnt
->
5274 tx_failed
[WME_PRIO2AC(PKTPRIO(p
))].packets
);
5275 WLCNTADD(wlc
->pub
->_wme_cnt
->
5276 tx_failed
[WME_PRIO2AC(PKTPRIO(p
))].bytes
,
5277 pkttotlen(wlc
->osh
, p
));
5281 PKTFREE(wlc
->osh
, p
, TRUE
);
5282 WLCNTINCR(wlc
->pub
->_cnt
->txnobuf
);
5287 p
= pktq_penq_head(q
, prec
, pkt
);
5289 p
= pktq_penq(q
, prec
, pkt
);
5295 void BCMFASTPATH
wlc_txq_enq(void *ctx
, struct scb
*scb
, void *sdu
, uint prec
)
5297 wlc_info_t
*wlc
= (wlc_info_t
*) ctx
;
5298 wlc_txq_info_t
*qi
= wlc
->active_queue
; /* Check me */
5299 struct pktq
*q
= &qi
->q
;
5302 prio
= PKTPRIO(sdu
);
5304 ASSERT(pktq_max(q
) >= wlc
->pub
->tunables
->datahiwat
);
5306 if (!wlc_prec_enq(wlc
, q
, sdu
, prec
)) {
5307 if (!EDCF_ENAB(wlc
->pub
)
5308 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
))
5309 WL_ERROR(("wl%d: wlc_txq_enq: txq overflow\n",
5312 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5313 PKTFREE(wlc
->osh
, sdu
, TRUE
);
5314 WLCNTINCR(wlc
->pub
->_cnt
->txnobuf
);
5317 /* Check if flow control needs to be turned on after enqueuing the packet
5318 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5319 * to drop instead of relying on stack to make the right decision
5321 if (!EDCF_ENAB(wlc
->pub
)
5322 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5323 if (pktq_len(q
) >= wlc
->pub
->tunables
->datahiwat
) {
5324 wlc_txflowcontrol(wlc
, qi
, ON
, ALLPRIO
);
5326 } else if (wlc
->pub
->_priofc
) {
5327 if (pktq_plen(q
, wlc_prio2prec_map
[prio
]) >=
5328 wlc
->pub
->tunables
->datahiwat
) {
5329 wlc_txflowcontrol(wlc
, qi
, ON
, prio
);
5335 wlc_sendpkt_mac80211(wlc_info_t
*wlc
, void *sdu
, struct ieee80211_hw
*hw
)
5340 struct scb
*scb
= &global_scb
;
5341 struct dot11_header
*d11_header
= (struct dot11_header
*)PKTDATA(sdu
);
5346 fc
= ltoh16(d11_header
->fc
);
5349 /* 802.11 standard requires management traffic to go at highest priority */
5350 prio
= (type
== FC_TYPE_DATA
? PKTPRIO(sdu
) : MAXPRIO
);
5351 fifo
= prio2fifo
[prio
];
5353 ASSERT((uint
) PKTHEADROOM(sdu
) >= TXOFF
);
5354 ASSERT(!PKTSHARED(sdu
));
5355 ASSERT(!PKTNEXT(sdu
));
5356 ASSERT(!PKTLINK(sdu
));
5357 ASSERT(fifo
< NFIFO
);
5361 (wlc_d11hdrs_mac80211(wlc
, hw
, pkt
, scb
, 0, 1, fifo
, 0, NULL
, 0)))
5363 wlc_txq_enq(wlc
, scb
, pkt
, WLC_PRIO_TO_PREC(prio
));
5364 wlc_send_q(wlc
, wlc
->active_queue
);
5366 WLCNTINCR(wlc
->pub
->_cnt
->ieee_tx
);
5370 void BCMFASTPATH
wlc_send_q(wlc_info_t
*wlc
, wlc_txq_info_t
*qi
)
5372 void *pkt
[DOT11_MAXNUMFRAGS
];
5375 int err
= 0, i
, count
;
5377 struct pktq
*q
= &qi
->q
;
5378 struct ieee80211_tx_info
*tx_info
;
5380 /* only do work for the active queue */
5381 if (qi
!= wlc
->active_queue
)
5389 prec_map
= wlc
->tx_prec_map
;
5391 /* Send all the enq'd pkts that we can.
5392 * Dequeue packets with precedence with empty HW fifo only
5394 while (prec_map
&& (pkt
[0] = pktq_mdeq(q
, prec_map
, &prec
))) {
5395 tx_info
= IEEE80211_SKB_CB(pkt
[0]);
5396 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
5397 err
= wlc_sendampdu(wlc
->ampdu
, qi
, pkt
, prec
);
5400 err
= wlc_prep_pdu(wlc
, pkt
[0], &fifo
);
5402 for (i
= 0; i
< count
; i
++) {
5403 wlc_txfifo(wlc
, fifo
, pkt
[i
], TRUE
, 1);
5408 if (err
== BCME_BUSY
) {
5409 pktq_penq_head(q
, prec
, pkt
[0]);
5410 /* If send failed due to any other reason than a change in
5411 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5413 if (prec_map
== wlc
->tx_prec_map
)
5415 prec_map
= wlc
->tx_prec_map
;
5419 /* Check if flow control needs to be turned off after sending the packet */
5420 if (!EDCF_ENAB(wlc
->pub
)
5421 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5422 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, ALLPRIO
)
5423 && (pktq_len(q
) < wlc
->pub
->tunables
->datahiwat
/ 2)) {
5424 wlc_txflowcontrol(wlc
, qi
, OFF
, ALLPRIO
);
5426 } else if (wlc
->pub
->_priofc
) {
5428 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
5429 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, prio
) &&
5430 (pktq_plen(q
, wlc_prio2prec_map
[prio
]) <
5431 wlc
->pub
->tunables
->datahiwat
/ 2)) {
5432 wlc_txflowcontrol(wlc
, qi
, OFF
, prio
);
5440 * bcmc_fid_generate:
5441 * Generate frame ID for a BCMC packet. The frag field is not used
5442 * for MC frames so is used as part of the sequence number.
5445 bcmc_fid_generate(wlc_info_t
*wlc
, wlc_bsscfg_t
*bsscfg
, d11txh_t
*txh
)
5449 frameid
= ltoh16(txh
->TxFrameID
) & ~(TXFID_SEQ_MASK
| TXFID_QUEUE_MASK
);
5452 mc_fid_counter
++) << TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5459 wlc_txfifo(wlc_info_t
*wlc
, uint fifo
, void *p
, bool commit
, s8 txpktpend
)
5461 u16 frameid
= INVALIDFID
;
5464 ASSERT(fifo
< NFIFO
);
5465 txh
= (d11txh_t
*) PKTDATA(p
);
5467 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5468 * ucode or BSS info as appropriate.
5470 if (fifo
== TX_BCMC_FIFO
) {
5471 frameid
= ltoh16(txh
->TxFrameID
);
5475 if (WLC_WAR16165(wlc
))
5476 wlc_war16165(wlc
, TRUE
);
5478 #ifdef WLC_HIGH_ONLY
5479 if (RPCTX_ENAB(wlc
->pub
)) {
5480 (void)wlc_rpctx_tx(wlc
->rpctx
, fifo
, p
, commit
, frameid
,
5486 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5487 * in wlc_bmac_txfifo()
5490 TXPKTPENDINC(wlc
, fifo
, txpktpend
);
5491 WL_TRACE(("wlc_txfifo, pktpend inc %d to %d\n", txpktpend
,
5492 TXPKTPENDGET(wlc
, fifo
)));
5495 /* Commit BCMC sequence number in the SHM frame ID location */
5496 if (frameid
!= INVALIDFID
)
5497 BCMCFID(wlc
, frameid
);
5499 if (dma_txfast(wlc
->hw
->di
[fifo
], p
, commit
) < 0) {
5500 WL_ERROR(("wlc_txfifo: fatal, toss frames !!!\n"));
5502 #endif /* WLC_HIGH_ONLY */
5506 wlc_compute_airtime(wlc_info_t
*wlc
, ratespec_t rspec
, uint length
)
5509 uint mac_rate
= RSPEC2RATE(rspec
);
5512 if (IS_MCS(rspec
)) {
5513 /* not supported yet */
5515 } else if (IS_OFDM(rspec
)) {
5516 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5518 * Nbits = length * 8
5519 * Nbits/sym = Mbps * 4 = mac_rate * 2
5521 nsyms
= CEIL((length
* 8), (mac_rate
* 2));
5523 /* usec = symbols * usec/symbol */
5524 usec
= (u16
) (nsyms
* APHY_SYMBOL_TIME
);
5535 usec
= (length
<< 4) / 11;
5538 usec
= (length
<< 3) / 11;
5541 WL_ERROR(("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n", wlc
->pub
->unit
, rspec
));
5542 ASSERT((const char *)"Bad phy_rate" == NULL
);
5551 wlc_compute_plcp(wlc_info_t
*wlc
, ratespec_t rspec
, uint length
, u8
*plcp
)
5553 if (IS_MCS(rspec
)) {
5554 wlc_compute_mimo_plcp(rspec
, length
, plcp
);
5555 } else if (IS_OFDM(rspec
)) {
5556 wlc_compute_ofdm_plcp(rspec
, length
, plcp
);
5558 wlc_compute_cck_plcp(rspec
, length
, plcp
);
5563 /* Rate: 802.11 rate code, length: PSDU length in octets */
5564 static void wlc_compute_mimo_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5566 u8 mcs
= (u8
) (rspec
& RSPEC_RATE_MASK
);
5567 ASSERT(IS_MCS(rspec
));
5569 if (RSPEC_IS40MHZ(rspec
) || (mcs
== 32))
5570 plcp
[0] |= MIMO_PLCP_40MHZ
;
5571 WLC_SET_MIMO_PLCP_LEN(plcp
, length
);
5572 plcp
[3] = RSPEC_MIMOPLCP3(rspec
); /* rspec already holds this byte */
5573 plcp
[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5574 plcp
[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5578 /* Rate: 802.11 rate code, length: PSDU length in octets */
5579 static void BCMFASTPATH
5580 wlc_compute_ofdm_plcp(ratespec_t rspec
, u32 length
, u8
*plcp
)
5584 int rate
= RSPEC2RATE(rspec
);
5586 ASSERT(IS_OFDM(rspec
));
5588 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5589 rate_signal
= rate_info
[rate
] & RATE_MASK
;
5590 ASSERT(rate_signal
!= 0);
5592 bzero(plcp
, D11_PHY_HDR_LEN
);
5593 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t
*) plcp
, rate_signal
);
5595 tmp
= (length
& 0xfff) << 5;
5596 plcp
[2] |= (tmp
>> 16) & 0xff;
5597 plcp
[1] |= (tmp
>> 8) & 0xff;
5598 plcp
[0] |= tmp
& 0xff;
5604 * Compute PLCP, but only requires actual rate and length of pkt.
5605 * Rate is given in the driver standard multiple of 500 kbps.
5606 * le is set for 11 Mbps rate if necessary.
5607 * Broken out for PRQ.
5610 static void wlc_cck_plcp_set(int rate_500
, uint length
, u8
*plcp
)
5623 usec
= (length
<< 4) / 11;
5624 if ((length
<< 4) - (usec
* 11) > 0)
5628 usec
= (length
<< 3) / 11;
5629 if ((length
<< 3) - (usec
* 11) > 0) {
5631 if ((usec
* 11) - (length
<< 3) >= 8)
5632 le
= D11B_PLCP_SIGNAL_LE
;
5637 WL_ERROR(("wlc_cck_plcp_set: unsupported rate %d\n", rate_500
));
5638 rate_500
= WLC_RATE_1M
;
5642 /* PLCP signal byte */
5643 plcp
[0] = rate_500
* 5; /* r (500kbps) * 5 == r (100kbps) */
5644 /* PLCP service byte */
5645 plcp
[1] = (u8
) (le
| D11B_PLCP_SIGNAL_LOCKED
);
5646 /* PLCP length u16, little endian */
5647 plcp
[2] = usec
& 0xff;
5648 plcp
[3] = (usec
>> 8) & 0xff;
5654 /* Rate: 802.11 rate code, length: PSDU length in octets */
5655 static void wlc_compute_cck_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5657 int rate
= RSPEC2RATE(rspec
);
5659 ASSERT(IS_CCK(rspec
));
5661 wlc_cck_plcp_set(rate
, length
, plcp
);
5664 /* wlc_compute_frame_dur()
5666 * Calculate the 802.11 MAC header DUR field for MPDU
5667 * DUR for a single frame = 1 SIFS + 1 ACK
5668 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5670 * rate MPDU rate in unit of 500kbps
5671 * next_frag_len next MPDU length in bytes
5672 * preamble_type use short/GF or long/MM PLCP header
5674 static u16 BCMFASTPATH
5675 wlc_compute_frame_dur(wlc_info_t
*wlc
, ratespec_t rate
, u8 preamble_type
,
5680 sifs
= SIFS(wlc
->band
);
5683 dur
+= (u16
) wlc_calc_ack_time(wlc
, rate
, preamble_type
);
5685 if (next_frag_len
) {
5686 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5688 /* add another SIFS and the frag time */
5691 (u16
) wlc_calc_frame_time(wlc
, rate
, preamble_type
,
5697 /* wlc_compute_rtscts_dur()
5699 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5700 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5701 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5703 * cts cts-to-self or rts/cts
5704 * rts_rate rts or cts rate in unit of 500kbps
5705 * rate next MPDU rate in unit of 500kbps
5706 * frame_len next MPDU frame length in bytes
5709 wlc_compute_rtscts_dur(wlc_info_t
*wlc
, bool cts_only
, ratespec_t rts_rate
,
5710 ratespec_t frame_rate
, u8 rts_preamble_type
,
5711 u8 frame_preamble_type
, uint frame_len
, bool ba
)
5715 sifs
= SIFS(wlc
->band
);
5717 if (!cts_only
) { /* RTS/CTS */
5720 (u16
) wlc_calc_cts_time(wlc
, rts_rate
,
5722 } else { /* CTS-TO-SELF */
5727 (u16
) wlc_calc_frame_time(wlc
, frame_rate
, frame_preamble_type
,
5731 (u16
) wlc_calc_ba_time(wlc
, frame_rate
,
5732 WLC_SHORT_PREAMBLE
);
5735 (u16
) wlc_calc_ack_time(wlc
, frame_rate
,
5736 frame_preamble_type
);
5740 static bool wlc_phy_rspec_check(wlc_info_t
*wlc
, u16 bw
, ratespec_t rspec
)
5742 if (IS_MCS(rspec
)) {
5743 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5746 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5747 } else if ((mcs
>= 8) && (mcs
<= 23)) {
5748 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SDM
);
5749 } else if (mcs
== 32) {
5750 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5751 ASSERT(bw
== PHY_TXC1_BW_40MHZ_DUP
);
5753 } else if (IS_OFDM(rspec
)) {
5754 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_STBC
);
5756 ASSERT(IS_CCK(rspec
));
5758 ASSERT((bw
== PHY_TXC1_BW_20MHZ
)
5759 || (bw
== PHY_TXC1_BW_20MHZ_UP
));
5760 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SISO
);
5766 u16 BCMFASTPATH
wlc_phytxctl1_calc(wlc_info_t
*wlc
, ratespec_t rspec
)
5771 if (WLCISLCNPHY(wlc
->band
)) {
5772 bw
= PHY_TXC1_BW_20MHZ
;
5774 bw
= RSPEC_GET_BW(rspec
);
5775 /* 10Mhz is not supported yet */
5776 if (bw
< PHY_TXC1_BW_20MHZ
) {
5777 WL_ERROR(("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n", bw
));
5778 bw
= PHY_TXC1_BW_20MHZ
;
5781 wlc_phy_rspec_check(wlc
, bw
, rspec
);
5784 if (IS_MCS(rspec
)) {
5785 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5787 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5788 phyctl1
= RSPEC_PHYTXBYTE2(rspec
);
5789 /* set the upper byte of phyctl1 */
5790 phyctl1
|= (mcs_table
[mcs
].tx_phy_ctl3
<< 8);
5791 } else if (IS_CCK(rspec
) && !WLCISLCNPHY(wlc
->band
)
5792 && !WLCISSSLPNPHY(wlc
->band
)) {
5793 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5794 /* Eventually MIMOPHY would also be converted to this format */
5795 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5796 phyctl1
= (bw
| (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5797 } else { /* legacy OFDM/CCK */
5799 /* get the phyctl byte from rate phycfg table */
5800 phycfg
= wlc_rate_legacy_phyctl(RSPEC2RATE(rspec
));
5802 WL_ERROR(("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n"));
5806 /* set the upper byte of phyctl1 */
5808 (bw
| (phycfg
<< 8) |
5809 (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5813 /* phy clock must support 40Mhz if tx descriptor uses it */
5814 if ((phyctl1
& PHY_TXC1_BW_MASK
) >= PHY_TXC1_BW_40MHZ
) {
5815 ASSERT(CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
);
5816 #ifndef WLC_HIGH_ONLY
5817 ASSERT(wlc
->chanspec
== wlc_phy_chanspec_get(wlc
->band
->pi
));
5824 ratespec_t BCMFASTPATH
5825 wlc_rspec_to_rts_rspec(wlc_info_t
*wlc
, ratespec_t rspec
, bool use_rspec
,
5828 ratespec_t rts_rspec
= 0;
5831 /* use frame rate as rts rate */
5834 } else if (wlc
->band
->gmode
&& wlc
->protection
->_g
&& !IS_CCK(rspec
)) {
5835 /* Use 11Mbps as the g protection RTS target rate and fallback.
5836 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5837 * target in case 11 Mbps is not Basic.
5838 * 6 and 9 Mbps are not usually selected by rate selection, but even
5839 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5841 rts_rspec
= WLC_BASIC_RATE(wlc
, WLC_RATE_11M
);
5843 /* calculate RTS rate and fallback rate based on the frame rate
5844 * RTS must be sent at a basic rate since it is a
5845 * control frame, sec 9.6 of 802.11 spec
5847 rts_rspec
= WLC_BASIC_RATE(wlc
, rspec
);
5850 if (WLC_PHY_11N_CAP(wlc
->band
)) {
5851 /* set rts txbw to correct side band */
5852 rts_rspec
&= ~RSPEC_BW_MASK
;
5854 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5855 * (DUP), otherwise send RTS on control channel
5857 if (RSPEC_IS40MHZ(rspec
) && !IS_CCK(rts_rspec
))
5858 rts_rspec
|= (PHY_TXC1_BW_40MHZ_DUP
<< RSPEC_BW_SHIFT
);
5860 rts_rspec
|= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5862 /* pick siso/cdd as default for ofdm */
5863 if (IS_OFDM(rts_rspec
)) {
5864 rts_rspec
&= ~RSPEC_STF_MASK
;
5865 rts_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
5872 * Add d11txh_t, cck_phy_hdr_t.
5874 * 'p' data must start with 802.11 MAC header
5875 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5877 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5880 static u16 BCMFASTPATH
5881 wlc_d11hdrs_mac80211(wlc_info_t
*wlc
, struct ieee80211_hw
*hw
,
5882 void *p
, struct scb
*scb
, uint frag
,
5883 uint nfrags
, uint queue
, uint next_frag_len
,
5884 wsec_key_t
*key
, ratespec_t rspec_override
)
5886 struct dot11_header
*h
;
5888 u8
*plcp
, plcp_fallback
[D11_PHY_HDR_LEN
];
5890 int len
, phylen
, rts_phylen
;
5891 u16 fc
, type
, frameid
, mch
, phyctl
, xfts
, mainrates
;
5892 u16 seq
= 0, mcl
= 0, status
= 0;
5893 ratespec_t rspec
[2] = { WLC_RATE_1M
, WLC_RATE_1M
}, rts_rspec
[2] = {
5894 WLC_RATE_1M
, WLC_RATE_1M
};
5895 bool use_rts
= FALSE
;
5896 bool use_cts
= FALSE
;
5897 bool use_rifs
= FALSE
;
5898 bool short_preamble
[2] = { FALSE
, FALSE
};
5899 u8 preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5900 u8 rts_preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5901 u8
*rts_plcp
, rts_plcp_fallback
[D11_PHY_HDR_LEN
];
5902 struct dot11_rts_frame
*rts
= NULL
;
5906 bool hwtkmic
= FALSE
;
5907 u16 mimo_ctlchbw
= PHY_TXC1_BW_20MHZ
;
5909 #define ANTCFG_NONE 0xFF
5910 u8 antcfg
= ANTCFG_NONE
;
5911 u8 fbantcfg
= ANTCFG_NONE
;
5913 uint phyctl1_stf
= 0;
5915 struct ieee80211_tx_rate
*txrate
[2];
5917 struct ieee80211_tx_info
*tx_info
;
5920 u8 mimo_preamble_type
;
5924 ASSERT(queue
< NFIFO
);
5928 /* locate 802.11 MAC header */
5929 h
= (struct dot11_header
*)PKTDATA(p
);
5933 qos
= (type
== FC_TYPE_DATA
&& FC_SUBTYPE_ANY_QOS(FC_SUBTYPE(fc
)));
5935 /* compute length of frame in bytes for use in PLCP computations */
5936 len
= pkttotlen(osh
, p
);
5937 phylen
= len
+ DOT11_FCS_LEN
;
5939 /* If WEP enabled, add room in phylen for the additional bytes of
5940 * ICV which MAC generates. We do NOT add the additional bytes to
5941 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5945 phylen
+= key
->icv_len
;
5949 tx_info
= IEEE80211_SKB_CB(p
);
5953 plcp
= PKTPUSH(p
, D11_PHY_HDR_LEN
);
5955 /* add Broadcom tx descriptor header */
5956 txh
= (d11txh_t
*) PKTPUSH(p
, D11_TXH_LEN
);
5957 bzero((char *)txh
, D11_TXH_LEN
);
5960 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
5961 /* non-AP STA should never use BCMC queue */
5962 ASSERT(queue
!= TX_BCMC_FIFO
);
5963 if (queue
== TX_BCMC_FIFO
) {
5964 WL_ERROR(("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5965 WLCWLUNIT(wlc
), __func__
));
5966 frameid
= bcmc_fid_generate(wlc
, NULL
, txh
);
5968 /* Increment the counter for first fragment */
5969 if (tx_info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
) {
5970 SCB_SEQNUM(scb
, PKTPRIO(p
))++;
5973 /* extract fragment number from frame first */
5974 seq
= ltoh16(seq
) & FRAGNUM_MASK
;
5975 seq
|= (SCB_SEQNUM(scb
, PKTPRIO(p
)) << SEQNUM_SHIFT
);
5976 h
->seq
= htol16(seq
);
5978 frameid
= ((seq
<< TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5979 (queue
& TXFID_QUEUE_MASK
);
5982 frameid
|= queue
& TXFID_QUEUE_MASK
;
5984 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5985 if (SCB_PS(scb
) || ((fc
& FC_KIND_MASK
) == FC_BEACON
))
5986 mcl
|= TXC_IGNOREPMQ
;
5988 ASSERT(hw
->max_rates
<= IEEE80211_TX_MAX_RATES
);
5989 ASSERT(hw
->max_rates
== 2);
5991 txrate
[0] = tx_info
->control
.rates
;
5992 txrate
[1] = txrate
[0] + 1;
5994 ASSERT(txrate
[0]->idx
>= 0);
5995 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5996 if (txrate
[1]->idx
< 0) {
5997 txrate
[1] = txrate
[0];
5999 #ifdef WLC_HIGH_ONLY
6000 /* Double protection , just in case */
6001 if (txrate
[0]->idx
> HIGHEST_SINGLE_STREAM_MCS
)
6002 txrate
[0]->idx
= HIGHEST_SINGLE_STREAM_MCS
;
6003 if (txrate
[1]->idx
> HIGHEST_SINGLE_STREAM_MCS
)
6004 txrate
[1]->idx
= HIGHEST_SINGLE_STREAM_MCS
;
6007 for (k
= 0; k
< hw
->max_rates
; k
++) {
6009 txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
? TRUE
: FALSE
;
6011 ASSERT(!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
));
6012 if ((txrate
[k
]->idx
>= 0)
6013 && (txrate
[k
]->idx
<
6014 hw
->wiphy
->bands
[tx_info
->band
]->n_bitrates
)) {
6016 hw
->wiphy
->bands
[tx_info
->band
]->
6017 bitrates
[txrate
[k
]->idx
].hw_value
;
6020 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
?
6023 ASSERT((txrate
[k
]->idx
>= 0) &&
6025 hw
->wiphy
->bands
[tx_info
->band
]->
6027 rate_val
[k
] = WLC_RATE_1M
;
6030 rate_val
[k
] = txrate
[k
]->idx
;
6032 /* Currently only support same setting for primay and fallback rates.
6033 * Unify flags for each rate into a single value for the frame
6037 flags
& IEEE80211_TX_RC_USE_RTS_CTS
? TRUE
: FALSE
;
6040 flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
? TRUE
: FALSE
;
6043 rate_val
[k
] |= NRATE_MCS_INUSE
;
6045 rspec
[k
] = mac80211_wlc_set_nrate(wlc
, wlc
->band
, rate_val
[k
]);
6047 /* (1) RATE: determine and validate primary rate and fallback rates */
6048 if (!RSPEC_ACTIVE(rspec
[k
])) {
6049 ASSERT(RSPEC_ACTIVE(rspec
[k
]));
6050 rspec
[k
] = WLC_RATE_1M
;
6052 if (WLANTSEL_ENAB(wlc
) && !ETHER_ISMULTI(&h
->a1
)) {
6053 /* set tx antenna config */
6054 wlc_antsel_antcfg_get(wlc
->asi
, FALSE
, FALSE
, 0,
6055 0, &antcfg
, &fbantcfg
);
6060 phyctl1_stf
= wlc
->stf
->ss_opmode
;
6062 if (N_ENAB(wlc
->pub
)) {
6063 for (k
= 0; k
< hw
->max_rates
; k
++) {
6064 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
6065 if (((IS_MCS(rspec
[k
]) &&
6066 IS_SINGLE_STREAM(rspec
[k
] & RSPEC_RATE_MASK
)) ||
6068 && ((rspec
[k
] & RSPEC_OVERRIDE_MCS_ONLY
)
6069 || !(rspec
[k
] & RSPEC_OVERRIDE
))) {
6070 rspec
[k
] &= ~(RSPEC_STF_MASK
| RSPEC_STC_MASK
);
6072 /* For SISO MCS use STBC if possible */
6073 if (IS_MCS(rspec
[k
])
6074 && WLC_STF_SS_STBC_TX(wlc
, scb
)) {
6077 ASSERT(WLC_STBC_CAP_PHY(wlc
));
6078 stc
= 1; /* Nss for single stream is always 1 */
6080 (PHY_TXC1_MODE_STBC
<<
6081 RSPEC_STF_SHIFT
) | (stc
<<
6085 (phyctl1_stf
<< RSPEC_STF_SHIFT
);
6088 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
6089 if (CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
) {
6090 /* default txbw is 20in40 SB */
6091 mimo_ctlchbw
= mimo_txbw
=
6092 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC
)
6093 ? PHY_TXC1_BW_20MHZ_UP
: PHY_TXC1_BW_20MHZ
;
6095 if (IS_MCS(rspec
[k
])) {
6096 /* mcs 32 must be 40b/w DUP */
6097 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
6099 PHY_TXC1_BW_40MHZ_DUP
;
6101 } else if (wlc
->mimo_40txbw
!= AUTO
)
6102 mimo_txbw
= wlc
->mimo_40txbw
;
6103 /* else check if dst is using 40 Mhz */
6104 else if (scb
->flags
& SCB_IS40
)
6105 mimo_txbw
= PHY_TXC1_BW_40MHZ
;
6106 } else if (IS_OFDM(rspec
[k
])) {
6107 if (wlc
->ofdm_40txbw
!= AUTO
)
6108 mimo_txbw
= wlc
->ofdm_40txbw
;
6110 ASSERT(IS_CCK(rspec
[k
]));
6111 if (wlc
->cck_40txbw
!= AUTO
)
6112 mimo_txbw
= wlc
->cck_40txbw
;
6115 /* mcs32 is 40 b/w only.
6116 * This is possible for probe packets on a STA during SCAN
6118 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
6120 rspec
[k
] = RSPEC_MIMORATE
;
6122 mimo_txbw
= PHY_TXC1_BW_20MHZ
;
6125 /* Set channel width */
6126 rspec
[k
] &= ~RSPEC_BW_MASK
;
6127 if ((k
== 0) || ((k
> 0) && IS_MCS(rspec
[k
])))
6128 rspec
[k
] |= (mimo_txbw
<< RSPEC_BW_SHIFT
);
6130 rspec
[k
] |= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
6134 if (IS_MCS(rspec
[k
])
6135 && (txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
6136 rspec
[k
] |= RSPEC_SHORT_GI
;
6137 else if (!(txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
6138 rspec
[k
] &= ~RSPEC_SHORT_GI
;
6140 rspec
[k
] &= ~RSPEC_SHORT_GI
;
6143 mimo_preamble_type
= WLC_MM_PREAMBLE
;
6144 if (txrate
[k
]->flags
& IEEE80211_TX_RC_GREEN_FIELD
)
6145 mimo_preamble_type
= WLC_GF_PREAMBLE
;
6147 if ((txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
)
6148 && (!IS_MCS(rspec
[k
]))) {
6149 WL_ERROR(("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n", WLCWLUNIT(wlc
), __func__
));
6150 ASSERT(0 && "Rate mismatch");
6153 if (IS_MCS(rspec
[k
])) {
6154 preamble_type
[k
] = mimo_preamble_type
;
6156 /* if SGI is selected, then forced mm for single stream */
6157 if ((rspec
[k
] & RSPEC_SHORT_GI
)
6158 && IS_SINGLE_STREAM(rspec
[k
] &
6160 preamble_type
[k
] = WLC_MM_PREAMBLE
;
6164 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
6165 ASSERT(VALID_RATE_DBG(wlc
, rspec
[0]));
6167 /* should be better conditionalized */
6168 if (!IS_MCS(rspec
[0])
6169 && (tx_info
->control
.rates
[0].
6170 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
))
6171 preamble_type
[k
] = WLC_SHORT_PREAMBLE
;
6173 ASSERT(!IS_MCS(rspec
[0])
6174 || WLC_IS_MIMO_PREAMBLE(preamble_type
[k
]));
6177 for (k
= 0; k
< hw
->max_rates
; k
++) {
6178 /* Set ctrlchbw as 20Mhz */
6179 ASSERT(!IS_MCS(rspec
[k
]));
6180 rspec
[k
] &= ~RSPEC_BW_MASK
;
6181 rspec
[k
] |= (PHY_TXC1_BW_20MHZ
<< RSPEC_BW_SHIFT
);
6183 /* for nphy, stf of ofdm frames must follow policies */
6184 if (WLCISNPHY(wlc
->band
) && IS_OFDM(rspec
[k
])) {
6185 rspec
[k
] &= ~RSPEC_STF_MASK
;
6186 rspec
[k
] |= phyctl1_stf
<< RSPEC_STF_SHIFT
;
6191 /* Reset these for use with AMPDU's */
6192 txrate
[0]->count
= 0;
6193 txrate
[1]->count
= 0;
6195 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
6196 wlc_compute_plcp(wlc
, rspec
[0], phylen
, plcp
);
6197 wlc_compute_plcp(wlc
, rspec
[1], phylen
, plcp_fallback
);
6198 bcopy(plcp_fallback
, (char *)&txh
->FragPLCPFallback
,
6199 sizeof(txh
->FragPLCPFallback
));
6201 /* Length field now put in CCK FBR CRC field */
6202 if (IS_CCK(rspec
[1])) {
6203 txh
->FragPLCPFallback
[4] = phylen
& 0xff;
6204 txh
->FragPLCPFallback
[5] = (phylen
& 0xff00) >> 8;
6207 /* MIMO-RATE: need validation ?? */
6209 IS_OFDM(rspec
[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) plcp
) :
6212 /* DUR field for main rate */
6213 if ((fc
!= FC_PS_POLL
) && !ETHER_ISMULTI(&h
->a1
) && !use_rifs
) {
6215 wlc_compute_frame_dur(wlc
, rspec
[0], preamble_type
[0],
6217 h
->durid
= htol16(durid
);
6218 } else if (use_rifs
) {
6219 /* NAV protect to end of next max packet size */
6221 (u16
) wlc_calc_frame_time(wlc
, rspec
[0],
6223 DOT11_MAX_FRAG_LEN
);
6224 durid
+= RIFS_11N_TIME
;
6225 h
->durid
= htol16(durid
);
6228 /* DUR field for fallback rate */
6229 if (fc
== FC_PS_POLL
)
6230 txh
->FragDurFallback
= h
->durid
;
6231 else if (ETHER_ISMULTI(&h
->a1
) || use_rifs
)
6232 txh
->FragDurFallback
= 0;
6234 durid
= wlc_compute_frame_dur(wlc
, rspec
[1],
6235 preamble_type
[1], next_frag_len
);
6236 txh
->FragDurFallback
= htol16(durid
);
6239 /* (4) MAC-HDR: MacTxControlLow */
6241 mcl
|= TXC_STARTMSDU
;
6243 if (!ETHER_ISMULTI(&h
->a1
))
6244 mcl
|= TXC_IMMEDACK
;
6246 if (BAND_5G(wlc
->band
->bandtype
))
6247 mcl
|= TXC_FREQBAND_5G
;
6249 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC
))
6252 /* set AMIC bit if using hardware TKIP MIC */
6256 txh
->MacTxControlLow
= htol16(mcl
);
6258 /* MacTxControlHigh */
6261 /* Set fallback rate preamble type */
6262 if ((preamble_type
[1] == WLC_SHORT_PREAMBLE
) ||
6263 (preamble_type
[1] == WLC_GF_PREAMBLE
)) {
6264 ASSERT((preamble_type
[1] == WLC_GF_PREAMBLE
) ||
6265 (!IS_MCS(rspec
[1])));
6266 if (RSPEC2RATE(rspec
[1]) != WLC_RATE_1M
)
6267 mch
|= TXC_PREAMBLE_DATA_FB_SHORT
;
6270 /* MacFrameControl */
6271 bcopy((char *)&h
->fc
, (char *)&txh
->MacFrameControl
, sizeof(u16
));
6273 txh
->TxFesTimeNormal
= htol16(0);
6275 txh
->TxFesTimeFallback
= htol16(0);
6278 bcopy((char *)&h
->a1
, (char *)&txh
->TxFrameRA
, ETHER_ADDR_LEN
);
6281 txh
->TxFrameID
= htol16(frameid
);
6283 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6284 * then we may need to reset the retry cnt's via the status reg
6286 txh
->TxStatus
= htol16(status
);
6288 if (D11REV_GE(wlc
->pub
->corerev
, 16)) {
6289 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6290 * the END of previous structure so that it's compatible in driver.
6291 * In old rev ucode, these fields should be ignored
6293 txh
->MaxNMpdus
= htol16(0);
6294 txh
->MaxABytes_MRT
= htol16(0);
6295 txh
->MaxABytes_FBR
= htol16(0);
6296 txh
->MinMBytes
= htol16(0);
6299 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6300 /* RTS PLCP header and RTS frame */
6301 if (use_rts
|| use_cts
) {
6302 if (use_rts
&& use_cts
)
6305 for (k
= 0; k
< 2; k
++) {
6306 rts_rspec
[k
] = wlc_rspec_to_rts_rspec(wlc
, rspec
[k
],
6311 if (!IS_OFDM(rts_rspec
[0]) &&
6312 !((RSPEC2RATE(rts_rspec
[0]) == WLC_RATE_1M
) ||
6313 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6314 rts_preamble_type
[0] = WLC_SHORT_PREAMBLE
;
6315 mch
|= TXC_PREAMBLE_RTS_MAIN_SHORT
;
6318 if (!IS_OFDM(rts_rspec
[1]) &&
6319 !((RSPEC2RATE(rts_rspec
[1]) == WLC_RATE_1M
) ||
6320 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6321 rts_preamble_type
[1] = WLC_SHORT_PREAMBLE
;
6322 mch
|= TXC_PREAMBLE_RTS_FB_SHORT
;
6325 /* RTS/CTS additions to MacTxControlLow */
6327 txh
->MacTxControlLow
|= htol16(TXC_SENDCTS
);
6329 txh
->MacTxControlLow
|= htol16(TXC_SENDRTS
);
6330 txh
->MacTxControlLow
|= htol16(TXC_LONGFRAME
);
6333 /* RTS PLCP header */
6334 ASSERT(ISALIGNED((uintptr
) txh
->RTSPhyHeader
, sizeof(u16
)));
6335 rts_plcp
= txh
->RTSPhyHeader
;
6337 rts_phylen
= DOT11_CTS_LEN
+ DOT11_FCS_LEN
;
6339 rts_phylen
= DOT11_RTS_LEN
+ DOT11_FCS_LEN
;
6341 wlc_compute_plcp(wlc
, rts_rspec
[0], rts_phylen
, rts_plcp
);
6343 /* fallback rate version of RTS PLCP header */
6344 wlc_compute_plcp(wlc
, rts_rspec
[1], rts_phylen
,
6346 bcopy(rts_plcp_fallback
, (char *)&txh
->RTSPLCPFallback
,
6347 sizeof(txh
->RTSPLCPFallback
));
6349 /* RTS frame fields... */
6350 rts
= (struct dot11_rts_frame
*)&txh
->rts_frame
;
6352 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
, rts_rspec
[0],
6353 rspec
[0], rts_preamble_type
[0],
6354 preamble_type
[0], phylen
, FALSE
);
6355 rts
->durid
= htol16(durid
);
6356 /* fallback rate version of RTS DUR field */
6357 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
,
6358 rts_rspec
[1], rspec
[1],
6359 rts_preamble_type
[1],
6360 preamble_type
[1], phylen
, FALSE
);
6361 txh
->RTSDurFallback
= htol16(durid
);
6364 rts
->fc
= htol16(FC_CTS
);
6365 bcopy((char *)&h
->a2
, (char *)&rts
->ra
, ETHER_ADDR_LEN
);
6367 rts
->fc
= htol16((u16
) FC_RTS
);
6368 bcopy((char *)&h
->a1
, (char *)&rts
->ra
,
6369 2 * ETHER_ADDR_LEN
);
6373 * low 8 bits: main frag rate/mcs,
6374 * high 8 bits: rts/cts rate/mcs
6376 mainrates
|= (IS_OFDM(rts_rspec
[0]) ?
6377 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) rts_plcp
) :
6380 bzero((char *)txh
->RTSPhyHeader
, D11_PHY_HDR_LEN
);
6381 bzero((char *)&txh
->rts_frame
, sizeof(struct dot11_rts_frame
));
6382 bzero((char *)txh
->RTSPLCPFallback
,
6383 sizeof(txh
->RTSPLCPFallback
));
6384 txh
->RTSDurFallback
= 0;
6387 #ifdef SUPPORT_40MHZ
6388 /* add null delimiter count */
6389 if ((tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) && IS_MCS(rspec
)) {
6390 txh
->RTSPLCPFallback
[AMPDU_FBR_NULL_DELIM
] =
6391 wlc_ampdu_null_delim_cnt(wlc
->ampdu
, scb
, rspec
, phylen
);
6395 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6396 txh
->MacTxControlHigh
= htol16(mch
);
6398 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6399 txh
->MainRates
= htol16(mainrates
);
6401 /* XtraFrameTypes */
6402 xfts
= FRAMETYPE(rspec
[1], wlc
->mimoft
);
6403 xfts
|= (FRAMETYPE(rts_rspec
[0], wlc
->mimoft
) << XFTS_RTS_FT_SHIFT
);
6404 xfts
|= (FRAMETYPE(rts_rspec
[1], wlc
->mimoft
) << XFTS_FBRRTS_FT_SHIFT
);
6406 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
) << XFTS_CHANNEL_SHIFT
;
6407 txh
->XtraFrameTypes
= htol16(xfts
);
6409 /* PhyTxControlWord */
6410 phyctl
= FRAMETYPE(rspec
[0], wlc
->mimoft
);
6411 if ((preamble_type
[0] == WLC_SHORT_PREAMBLE
) ||
6412 (preamble_type
[0] == WLC_GF_PREAMBLE
)) {
6413 ASSERT((preamble_type
[0] == WLC_GF_PREAMBLE
)
6414 || !IS_MCS(rspec
[0]));
6415 if (RSPEC2RATE(rspec
[0]) != WLC_RATE_1M
)
6416 phyctl
|= PHY_TXC_SHORT_HDR
;
6417 WLCNTINCR(wlc
->pub
->_cnt
->txprshort
);
6420 /* phytxant is properly bit shifted */
6421 phyctl
|= wlc_stf_d11hdrs_phyctl_txant(wlc
, rspec
[0]);
6422 txh
->PhyTxControlWord
= htol16(phyctl
);
6424 /* PhyTxControlWord_1 */
6425 if (WLC_PHY_11N_CAP(wlc
->band
)) {
6428 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[0]);
6429 txh
->PhyTxControlWord_1
= htol16(phyctl1
);
6430 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[1]);
6431 txh
->PhyTxControlWord_1_Fbr
= htol16(phyctl1
);
6433 if (use_rts
|| use_cts
) {
6434 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[0]);
6435 txh
->PhyTxControlWord_1_Rts
= htol16(phyctl1
);
6436 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[1]);
6437 txh
->PhyTxControlWord_1_FbrRts
= htol16(phyctl1
);
6441 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6442 * fill in non-zero MModeLen and/or MModeFbrLen
6443 * it will be unnecessary if they are separated
6445 if (IS_MCS(rspec
[0]) && (preamble_type
[0] == WLC_MM_PREAMBLE
)) {
6447 wlc_calc_lsig_len(wlc
, rspec
[0], phylen
);
6448 txh
->MModeLen
= htol16(mmodelen
);
6451 if (IS_MCS(rspec
[1]) && (preamble_type
[1] == WLC_MM_PREAMBLE
)) {
6453 wlc_calc_lsig_len(wlc
, rspec
[1], phylen
);
6454 txh
->MModeFbrLen
= htol16(mmodefbrlen
);
6458 if (IS_MCS(rspec
[0]))
6459 ASSERT(IS_MCS(rspec
[1]));
6461 ASSERT(!IS_MCS(rspec
[0]) ||
6462 ((preamble_type
[0] == WLC_MM_PREAMBLE
) == (txh
->MModeLen
!= 0)));
6463 ASSERT(!IS_MCS(rspec
[1]) ||
6464 ((preamble_type
[1] == WLC_MM_PREAMBLE
) ==
6465 (txh
->MModeFbrLen
!= 0)));
6467 ac
= wme_fifo2ac
[queue
];
6468 if (SCB_WME(scb
) && qos
&& wlc
->edcf_txop
[ac
]) {
6469 uint frag_dur
, dur
, dur_fallback
;
6471 ASSERT(!ETHER_ISMULTI(&h
->a1
));
6473 /* WME: Update TXOP threshold */
6474 if ((!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)) && (frag
== 0)) {
6476 wlc_calc_frame_time(wlc
, rspec
[0], preamble_type
[0],
6480 /* 1 RTS or CTS-to-self frame */
6482 wlc_calc_cts_time(wlc
, rts_rspec
[0],
6483 rts_preamble_type
[0]);
6485 wlc_calc_cts_time(wlc
, rts_rspec
[1],
6486 rts_preamble_type
[1]);
6487 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6488 dur
+= ltoh16(rts
->durid
);
6489 dur_fallback
+= ltoh16(txh
->RTSDurFallback
);
6490 } else if (use_rifs
) {
6494 /* frame + SIFS + ACK */
6497 wlc_compute_frame_dur(wlc
, rspec
[0],
6498 preamble_type
[0], 0);
6501 wlc_calc_frame_time(wlc
, rspec
[1],
6505 wlc_compute_frame_dur(wlc
, rspec
[1],
6506 preamble_type
[1], 0);
6508 /* NEED to set TxFesTimeNormal (hard) */
6509 txh
->TxFesTimeNormal
= htol16((u16
) dur
);
6510 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6511 txh
->TxFesTimeFallback
= htol16((u16
) dur_fallback
);
6513 /* update txop byte threshold (txop minus intraframe overhead) */
6514 if (wlc
->edcf_txop
[ac
] >= (dur
- frag_dur
)) {
6519 wlc_calc_frame_len(wlc
, rspec
[0],
6525 /* range bound the fragthreshold */
6526 if (newfragthresh
< DOT11_MIN_FRAG_LEN
)
6529 else if (newfragthresh
>
6530 wlc
->usr_fragthresh
)
6532 wlc
->usr_fragthresh
;
6533 /* update the fragthresh and do txc update */
6534 if (wlc
->fragthresh
[queue
] !=
6535 (u16
) newfragthresh
) {
6536 wlc
->fragthresh
[queue
] =
6537 (u16
) newfragthresh
;
6541 WL_ERROR(("wl%d: %s txop invalid for rate %d\n",
6542 wlc
->pub
->unit
, fifo_names
[queue
],
6543 RSPEC2RATE(rspec
[0])));
6545 if (dur
> wlc
->edcf_txop
[ac
])
6546 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
]));
6553 void wlc_tbtt(wlc_info_t
*wlc
, d11regs_t
*regs
)
6555 wlc_bsscfg_t
*cfg
= wlc
->cfg
;
6557 WLCNTINCR(wlc
->pub
->_cnt
->tbtt
);
6559 if (BSSCFG_STA(cfg
)) {
6560 /* run watchdog here if the watchdog timer is not armed */
6561 if (WLC_WATCHDOG_TBTT(wlc
)) {
6564 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
6565 wlc
->WDarmed
= FALSE
;
6568 cur
= OSL_SYSUPTIME();
6569 delta
= cur
> wlc
->WDlast
? cur
- wlc
->WDlast
:
6570 (u32
) ~0 - wlc
->WDlast
+ cur
+ 1;
6571 if (delta
>= TIMER_INTERVAL_WATCHDOG
) {
6572 wlc_watchdog((void *)wlc
);
6576 wl_add_timer(wlc
->wl
, wlc
->wdtimer
,
6577 wlc_watchdog_backup_bi(wlc
), TRUE
);
6578 wlc
->WDarmed
= TRUE
;
6583 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6584 wlc
->qvalid
|= MCMD_DIRFRMQVAL
;
6588 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6589 void wlc_hwtimer_gptimer_set(wlc_info_t
*wlc
, uint us
)
6591 ASSERT(wlc
->pub
->corerev
>= 3); /* no gptimer in earlier revs */
6592 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, us
);
6595 void wlc_hwtimer_gptimer_abort(wlc_info_t
*wlc
)
6597 ASSERT(wlc
->pub
->corerev
>= 3);
6598 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, 0);
6601 static void wlc_hwtimer_gptimer_cb(wlc_info_t
*wlc
)
6603 /* when interrupt is generated, the counter is loaded with last value
6604 * written and continue to decrement. So it has to be cleaned first
6606 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, 0);
6610 * This fn has all the high level dpc processing from wlc_dpc.
6611 * POLICY: no macinstatus change, no bounding loop.
6612 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6614 void wlc_high_dpc(wlc_info_t
*wlc
, u32 macintstatus
)
6616 d11regs_t
*regs
= wlc
->regs
;
6619 static const bcm_bit_desc_t int_flags
[] = {
6620 {MI_MACSSPNDD
, "MACSSPNDD"},
6621 {MI_BCNTPL
, "BCNTPL"},
6623 {MI_BCNSUCCESS
, "BCNSUCCESS"},
6624 {MI_BCNCANCLD
, "BCNCANCLD"},
6625 {MI_ATIMWINEND
, "ATIMWINEND"},
6627 {MI_NSPECGEN_0
, "NSPECGEN_0"},
6628 {MI_NSPECGEN_1
, "NSPECGEN_1"},
6629 {MI_MACTXERR
, "MACTXERR"},
6630 {MI_NSPECGEN_3
, "NSPECGEN_3"},
6631 {MI_PHYTXERR
, "PHYTXERR"},
6635 {MI_DMAINT
, "DMAINT"},
6636 {MI_TXSTOP
, "TXSTOP"},
6638 {MI_BG_NOISE
, "BG_NOISE"},
6639 {MI_DTIM_TBTT
, "DTIM_TBTT"},
6641 {MI_PWRUP
, "PWRUP"},
6642 {MI_RFDISABLE
, "RFDISABLE"},
6644 {MI_PHYCHANGED
, "PHYCHANGED"},
6649 if (macintstatus
& ~(MI_TBTT
| MI_TXSTOP
)) {
6650 bcm_format_flags(int_flags
, macintstatus
, flagstr
,
6652 WL_TRACE(("wl%d: macintstatus 0x%x %s\n", wlc
->pub
->unit
,
6653 macintstatus
, flagstr
));
6657 if (macintstatus
& MI_PRQ
) {
6658 /* Process probe request FIFO */
6659 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6662 /* TBTT indication */
6663 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6664 if (macintstatus
& (MI_TBTT
| MI_DTIM_TBTT
))
6665 wlc_tbtt(wlc
, regs
);
6667 if (macintstatus
& MI_GP0
) {
6668 WL_ERROR(("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n", wlc
->pub
->unit
, wlc
->pub
->now
));
6670 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6671 __func__
, CHIPID(wlc
->pub
->sih
->chip
),
6672 CHIPREV(wlc
->pub
->sih
->chiprev
));
6674 WLCNTINCR(wlc
->pub
->_cnt
->psmwds
);
6680 /* gptimer timeout */
6681 if (macintstatus
& MI_TO
) {
6682 wlc_hwtimer_gptimer_cb(wlc
);
6685 if (macintstatus
& MI_RFDISABLE
) {
6686 WL_ERROR(("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n", wlc
->pub
->unit
, R_REG(wlc
->osh
, ®s
->phydebug
) & PDBG_RFD
));
6687 /* delay the cleanup to wl_down in IBSS case */
6688 if ((R_REG(wlc
->osh
, ®s
->phydebug
) & PDBG_RFD
)) {
6690 wlc_bsscfg_t
*bsscfg
;
6691 FOREACH_BSS(wlc
, idx
, bsscfg
) {
6692 if (!BSSCFG_STA(bsscfg
) || !bsscfg
->enable
6695 WL_ERROR(("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n", wlc
->pub
->unit
));
6700 /* send any enq'd tx packets. Just makes sure to jump start tx */
6701 if (!pktq_empty(&wlc
->active_queue
->q
))
6702 wlc_send_q(wlc
, wlc
->active_queue
);
6704 #ifndef WLC_HIGH_ONLY
6705 ASSERT(wlc_ps_check(wlc
));
6709 static void *wlc_15420war(wlc_info_t
*wlc
, uint queue
)
6714 ASSERT(queue
< NFIFO
);
6716 if ((D11REV_IS(wlc
->pub
->corerev
, 4))
6717 || (D11REV_GT(wlc
->pub
->corerev
, 6)))
6720 di
= wlc
->hw
->di
[queue
];
6723 /* get next packet, ignoring XmtStatus.Curr */
6724 p
= dma_getnexttxp(di
, HNDDMA_RANGE_ALL
);
6726 /* sw block tx dma */
6729 /* if tx ring is now empty, reset and re-init the tx dma channel */
6730 if (dma_txactive(wlc
->hw
->di
[queue
]) == 0) {
6731 WLCNTINCR(wlc
->pub
->_cnt
->txdmawar
);
6732 if (!dma_txreset(di
))
6733 WL_ERROR(("wl%d: %s: dma_txreset[%d]: cannot stop dma\n", wlc
->pub
->unit
, __func__
, queue
));
6739 static void wlc_war16165(wlc_info_t
*wlc
, bool tx
)
6742 /* the post-increment is used in STAY_AWAKE macro */
6743 if (wlc
->txpend16165war
++ == 0)
6744 wlc_set_ps_ctrl(wlc
);
6746 wlc
->txpend16165war
--;
6747 if (wlc
->txpend16165war
== 0)
6748 wlc_set_ps_ctrl(wlc
);
6752 /* process an individual tx_status_t */
6755 wlc_dotxstatus(wlc_info_t
*wlc
, tx_status_t
*txs
, u32 frm_tx2
)
6760 struct scb
*scb
= NULL
;
6763 int tx_rts
, tx_frame_count
, tx_rts_count
;
6764 uint totlen
, supr_status
;
6766 struct dot11_header
*h
;
6769 struct ieee80211_tx_info
*tx_info
;
6770 struct ieee80211_tx_rate
*txrate
;
6773 (void)(frm_tx2
); /* Compiler reference to avoid unused variable warning */
6775 /* discard intermediate indications for ucode with one legitimate case:
6776 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6777 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6778 * transmission count)
6780 if (!(txs
->status
& TX_STATUS_AMPDU
)
6781 && (txs
->status
& TX_STATUS_INTERMEDIATE
)) {
6782 WLCNTADD(wlc
->pub
->_cnt
->txnoack
,
6784 status
& TX_STATUS_FRM_RTX_MASK
) >>
6785 TX_STATUS_FRM_RTX_SHIFT
));
6786 WL_ERROR(("%s: INTERMEDIATE but not AMPDU\n", __func__
));
6791 queue
= txs
->frameid
& TXFID_QUEUE_MASK
;
6792 ASSERT(queue
< NFIFO
);
6793 if (queue
>= NFIFO
) {
6798 p
= GETNEXTTXP(wlc
, queue
);
6799 if (WLC_WAR16165(wlc
))
6800 wlc_war16165(wlc
, FALSE
);
6802 p
= wlc_15420war(wlc
, queue
);
6807 txh
= (d11txh_t
*) PKTDATA(p
);
6808 mcl
= ltoh16(txh
->MacTxControlLow
);
6811 WL_ERROR(("phyerr 0x%x, rate 0x%x\n", txs
->phyerr
,
6813 wlc_print_txdesc(txh
);
6814 wlc_print_txstatus(txs
);
6817 ASSERT(txs
->frameid
== htol16(txh
->TxFrameID
));
6818 if (txs
->frameid
!= htol16(txh
->TxFrameID
))
6821 tx_info
= IEEE80211_SKB_CB(p
);
6822 h
= (struct dot11_header
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
6825 scb
= (struct scb
*)tx_info
->control
.sta
->drv_priv
;
6827 if (N_ENAB(wlc
->pub
)) {
6828 u8
*plcp
= (u8
*) (txh
+ 1);
6829 if (PLCP3_ISSGI(plcp
[3]))
6830 WLCNTINCR(wlc
->pub
->_cnt
->txmpdu_sgi
);
6831 if (PLCP3_ISSTBC(plcp
[3]))
6832 WLCNTINCR(wlc
->pub
->_cnt
->txmpdu_stbc
);
6835 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
6836 ASSERT((mcl
& TXC_AMPDU_MASK
) != TXC_AMPDU_NONE
);
6837 wlc_ampdu_dotxstatus(wlc
->ampdu
, scb
, p
, txs
);
6841 supr_status
= txs
->status
& TX_STATUS_SUPR_MASK
;
6842 if (supr_status
== TX_STATUS_SUPR_BADCH
)
6843 WL_NONE(("%s: Pkt tx suppressed, possibly channel %d\n",
6844 __func__
, CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
)));
6846 tx_rts
= htol16(txh
->MacTxControlLow
) & TXC_SENDRTS
;
6848 (txs
->status
& TX_STATUS_FRM_RTX_MASK
) >> TX_STATUS_FRM_RTX_SHIFT
;
6850 (txs
->status
& TX_STATUS_RTS_RTX_MASK
) >> TX_STATUS_RTS_RTX_SHIFT
;
6852 lastframe
= (fc
& FC_MOREFRAG
) == 0;
6855 WL_ERROR(("Not last frame!\n"));
6858 ieee80211_tx_info_clear_status(tx_info
);
6859 if (queue
< AC_COUNT
) {
6860 sfbl
= WLC_WME_RETRY_SFB_GET(wlc
, wme_fifo2ac
[queue
]);
6861 lfbl
= WLC_WME_RETRY_LFB_GET(wlc
, wme_fifo2ac
[queue
]);
6867 txrate
= tx_info
->status
.rates
;
6868 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6869 if ((tx_frame_count
> sfbl
) && (txrate
[1].idx
>= 0)) {
6870 /* rate selection requested a fallback rate and we used it */
6871 txrate
->count
= lfbl
;
6872 txrate
[1].count
= tx_frame_count
- lfbl
;
6874 /* rate selection did not request fallback rate, or we didn't need it */
6875 txrate
->count
= tx_frame_count
;
6876 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6878 txrate
[1].count
= 0;
6881 /* clear the rest of the rates */
6882 for (i
= 2; i
< IEEE80211_TX_MAX_RATES
; i
++) {
6884 txrate
[i
].count
= 0;
6887 if (txs
->status
& TX_STATUS_ACK_RCV
)
6888 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
6891 totlen
= pkttotlen(osh
, p
);
6894 wlc_txfifo_complete(wlc
, queue
, 1);
6897 PKTSETNEXT(p
, NULL
);
6898 PKTSETLINK(p
, NULL
);
6900 /* remove PLCP & Broadcom tx descriptor header */
6901 PKTPULL(p
, D11_PHY_HDR_LEN
);
6902 PKTPULL(p
, D11_TXH_LEN
);
6903 ieee80211_tx_status_irqsafe(wlc
->pub
->ieee_hw
, p
);
6904 WLCNTINCR(wlc
->pub
->_cnt
->ieee_tx_status
);
6906 WL_ERROR(("%s: Not last frame => not calling tx_status\n",
6915 PKTFREE(osh
, p
, TRUE
);
6917 #ifdef WLC_HIGH_ONLY
6918 /* If this is a split driver, do the big-hammer here.
6919 * If this is a monolithic driver, wlc_bmac.c:wlc_dpc() will do the big-hammer.
6928 wlc_txfifo_complete(wlc_info_t
*wlc
, uint fifo
, s8 txpktpend
)
6930 TXPKTPENDDEC(wlc
, fifo
, txpktpend
);
6931 WL_TRACE(("wlc_txfifo_complete, pktpend dec %d to %d\n", txpktpend
,
6932 TXPKTPENDGET(wlc
, fifo
)));
6934 /* There is more room; mark precedences related to this FIFO sendable */
6935 WLC_TX_FIFO_ENAB(wlc
, fifo
);
6936 ASSERT(TXPKTPENDGET(wlc
, fifo
) >= 0);
6938 if (!TXPKTPENDTOT(wlc
)) {
6939 if (wlc
->block_datafifo
& DATA_BLOCK_TX_SUPR
)
6940 wlc_bsscfg_tx_check(wlc
);
6943 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6944 if (AP_ENAB(wlc
->pub
) &&
6945 wlc
->bcmcfifo_drain
&& !TXPKTPENDGET(wlc
, TX_BCMC_FIFO
)) {
6946 wlc
->bcmcfifo_drain
= FALSE
;
6947 wlc_mhf(wlc
, MHF2
, MHF2_TXBCMC_NOW
, 0, WLC_BAND_AUTO
);
6950 /* figure out which bsscfg is being worked on... */
6953 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6954 * return the offset (in us) of the TSF from the last TBTT
6956 u32
wlc_calc_tbtt_offset(u32 bp
, u32 tsf_h
, u32 tsf_l
)
6958 u32 k
, btklo
, btkhi
, offset
;
6960 /* TBTT is always an even multiple of the beacon_interval,
6961 * so the TBTT less than or equal to the beacon timestamp is
6962 * the beacon timestamp minus the beacon timestamp modulo
6963 * the beacon interval.
6965 * TBTT = BT - (BT % BIu)
6966 * = (BTk - (BTk % BP)) * 2^10
6968 * BT = beacon timestamp (usec, 64bits)
6969 * BTk = beacon timestamp (Kusec, 54bits)
6970 * BP = beacon interval (Kusec, 16bits)
6971 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6973 * To keep the calculations in u32s, the modulo operation
6974 * on the high part of BT needs to be done in parts using the
6976 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6978 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6980 * So, if BTk[n] = u16 n [0,3] of BTk.
6981 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6982 * and the SUM term can be broken down:
6983 * (BTk[n] * 2^16n) % BP
6984 * (BTk[n] * (2^16n % BP)) % BP
6986 * Create a set of power of 2 mod BP constants:
6987 * K[n] = 2^(16n) % BP
6988 * = (K[n-1] * 2^16) % BP
6989 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6991 * BTk % BP = BTk[0-1] % BP +
6992 * (BTk[2] * K[2]) % BP +
6993 * (BTk[3] * K[3]) % BP
6995 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6998 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6999 btklo
= (tsf_h
<< 22) | (tsf_l
>> 10);
7000 btkhi
= tsf_h
>> 10;
7002 /* offset = BTk % BP */
7003 offset
= btklo
% bp
;
7005 /* K[2] = ((2^16 % BP) * 2^16) % BP */
7006 k
= (u32
) (1 << 16) % bp
;
7007 k
= (u32
) (k
* 1 << 16) % (u32
) bp
;
7009 /* offset += (BTk[2] * K[2]) % BP */
7010 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
7013 btkhi
= btkhi
>> 16;
7015 /* k[3] = (K[2] * 2^16) % BP */
7018 /* offset += (BTk[3] * K[3]) % BP */
7019 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
7021 offset
= offset
% bp
;
7023 /* convert offset from kus to us by shifting up 10 bits and
7024 * add in the low 10 bits of tsf that we ignored
7026 offset
= (offset
<< 10) + (tsf_l
& 0x3FF);
7031 /* Update beacon listen interval in shared memory */
7032 void wlc_bcn_li_upd(wlc_info_t
*wlc
)
7034 if (AP_ENAB(wlc
->pub
))
7037 /* wake up every DTIM is the default */
7038 if (wlc
->bcn_li_dtim
== 1)
7039 wlc_write_shm(wlc
, M_BCN_LI
, 0);
7041 wlc_write_shm(wlc
, M_BCN_LI
,
7042 (wlc
->bcn_li_dtim
<< 8) | wlc
->bcn_li_bcn
);
7046 prep_mac80211_status(wlc_info_t
*wlc
, d11rxhdr_t
*rxh
, void *p
,
7047 struct ieee80211_rx_status
*rx_status
)
7050 wlc_d11rxhdr_t
*wlc_rxh
= (wlc_d11rxhdr_t
*) rxh
;
7054 unsigned char *plcp
;
7056 wlc_read_tsf(wlc
, &tsf_l
, &tsf_h
); /* mactime */
7057 rx_status
->mactime
= tsf_h
;
7058 rx_status
->mactime
<<= 32;
7059 rx_status
->mactime
|= tsf_l
;
7060 rx_status
->flag
|= RX_FLAG_TSFT
;
7062 channel
= WLC_CHAN_CHANNEL(rxh
->RxChan
);
7064 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
7066 rx_status
->band
= IEEE80211_BAND_5GHZ
;
7067 rx_status
->freq
= wf_channel2mhz(channel
, WF_CHAN_FACTOR_5_G
);
7069 rx_status
->band
= IEEE80211_BAND_2GHZ
;
7070 rx_status
->freq
= wf_channel2mhz(channel
, WF_CHAN_FACTOR_2_4_G
);
7073 rx_status
->signal
= wlc_rxh
->rssi
; /* signal */
7077 rx_status
->antenna
= (rxh
->PhyRxStatus_0
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0; /* ant */
7081 rspec
= wlc_compute_rspec(rxh
, plcp
);
7082 if (IS_MCS(rspec
)) {
7083 rx_status
->rate_idx
= rspec
& RSPEC_RATE_MASK
;
7084 rx_status
->flag
|= RX_FLAG_HT
;
7085 if (RSPEC_IS40MHZ(rspec
))
7086 rx_status
->flag
|= RX_FLAG_40MHZ
;
7088 switch (RSPEC2RATE(rspec
)) {
7090 rx_status
->rate_idx
= 0;
7093 rx_status
->rate_idx
= 1;
7096 rx_status
->rate_idx
= 2;
7099 rx_status
->rate_idx
= 3;
7102 rx_status
->rate_idx
= 4;
7105 rx_status
->rate_idx
= 5;
7108 rx_status
->rate_idx
= 6;
7111 rx_status
->rate_idx
= 7;
7114 rx_status
->rate_idx
= 8;
7117 rx_status
->rate_idx
= 9;
7120 rx_status
->rate_idx
= 10;
7123 rx_status
->rate_idx
= 11;
7126 WL_ERROR(("%s: Unknown rate\n", __func__
));
7129 /* Determine short preamble and rate_idx */
7131 if (IS_CCK(rspec
)) {
7132 if (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
)
7133 WL_ERROR(("Short CCK\n"));
7134 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
7135 } else if (IS_OFDM(rspec
)) {
7136 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
7138 WL_ERROR(("%s: Unknown modulation\n", __func__
));
7142 if (PLCP3_ISSGI(plcp
[3]))
7143 rx_status
->flag
|= RX_FLAG_SHORT_GI
;
7145 if (rxh
->RxStatus1
& RXS_DECERR
) {
7146 rx_status
->flag
|= RX_FLAG_FAILED_PLCP_CRC
;
7147 WL_ERROR(("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__
));
7149 if (rxh
->RxStatus1
& RXS_FCSERR
) {
7150 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
7151 WL_ERROR(("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__
));
7156 wlc_recvctl(wlc_info_t
*wlc
, osl_t
*osh
, d11rxhdr_t
*rxh
, void *p
)
7159 struct ieee80211_rx_status rx_status
;
7161 struct sk_buff
*skb
= p
;
7164 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
7165 * Test for INTERMEDIATE like so:
7166 * if (!(plcp[0] | plcp[1] | plcp[2]))
7169 memset(&rx_status
, 0, sizeof(rx_status
));
7170 prep_mac80211_status(wlc
, rxh
, p
, &rx_status
);
7172 /* mac header+body length, exclude CRC and plcp header */
7173 len_mpdu
= PKTLEN(p
) - D11_PHY_HDR_LEN
- DOT11_FCS_LEN
;
7174 PKTPULL(p
, D11_PHY_HDR_LEN
);
7175 PKTSETLEN(p
, len_mpdu
);
7177 ASSERT(!PKTNEXT(p
));
7178 ASSERT(!PKTLINK(p
));
7180 ASSERT(ISALIGNED((uintptr
) skb
->data
, 2));
7182 memcpy(IEEE80211_SKB_RXCB(p
), &rx_status
, sizeof(rx_status
));
7183 ieee80211_rx_irqsafe(wlc
->pub
->ieee_hw
, p
);
7185 WLCNTINCR(wlc
->pub
->_cnt
->ieee_rx
);
7190 void wlc_bss_list_free(wlc_info_t
*wlc
, wlc_bss_list_t
*bss_list
)
7196 WL_ERROR(("%s: Attempting to free NULL list\n", __func__
));
7199 /* inspect all BSS descriptor */
7200 for (index
= 0; index
< bss_list
->count
; index
++) {
7201 bi
= bss_list
->ptrs
[index
];
7204 osl_mfree(wlc
->osh
, bi
->bcn_prb
,
7207 osl_mfree(wlc
->osh
, bi
, sizeof(wlc_bss_info_t
));
7208 bss_list
->ptrs
[index
] = NULL
;
7211 bss_list
->count
= 0;
7214 /* Process received frames */
7216 * Return TRUE if more frames need to be processed. FALSE otherwise.
7217 * Param 'bound' indicates max. # frames to process before break out.
7220 void BCMFASTPATH
wlc_recv(wlc_info_t
*wlc
, void *p
)
7223 struct dot11_header
*h
;
7229 char eabuf
[ETHER_ADDR_STR_LEN
];
7232 WL_TRACE(("wl%d: wlc_recv\n", wlc
->pub
->unit
));
7236 /* frame starts with rxhdr */
7237 rxh
= (d11rxhdr_t
*) PKTDATA(p
);
7239 /* strip off rxhdr */
7240 PKTPULL(p
, wlc
->hwrxoff
);
7242 /* fixup rx header endianness */
7243 ltoh16_buf((void *)rxh
, sizeof(d11rxhdr_t
));
7245 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7246 if (rxh
->RxStatus1
& RXS_PBPRES
) {
7247 if (PKTLEN(p
) < 2) {
7248 WLCNTINCR(wlc
->pub
->_cnt
->rxrunt
);
7249 WL_ERROR(("wl%d: wlc_recv: rcvd runt of len %d\n",
7250 wlc
->pub
->unit
, PKTLEN(p
)));
7256 h
= (struct dot11_header
*)(PKTDATA(p
) + D11_PHY_HDR_LEN
);
7259 if (rxh
->RxStatus1
& RXS_FCSERR
) {
7260 if (wlc
->pub
->mac80211_state
& MAC80211_PROMISC_BCNS
) {
7261 WL_ERROR(("FCSERR while scanning******* - tossing\n"));
7264 WL_ERROR(("RCSERR!!!\n"));
7269 /* check received pkt has at least frame control field */
7270 if (len
>= D11_PHY_HDR_LEN
+ sizeof(h
->fc
)) {
7273 WLCNTINCR(wlc
->pub
->_cnt
->rxrunt
);
7277 is_amsdu
= rxh
->RxStatus2
& RXS_AMSDU_MASK
;
7279 /* explicitly test bad src address to avoid sending bad deauth */
7281 /* CTS and ACK CTL frames are w/o a2 */
7282 if (FC_TYPE(fc
) == FC_TYPE_DATA
|| FC_TYPE(fc
) == FC_TYPE_MNG
) {
7283 if ((ETHER_ISNULLADDR(&h
->a2
) || ETHER_ISMULTI(&h
->a2
))) {
7284 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
)));
7285 WLCNTINCR(wlc
->pub
->_cnt
->rxbadsrcmac
);
7288 WLCNTINCR(wlc
->pub
->_cnt
->rxfrag
);
7292 /* due to sheer numbers, toss out probe reqs for now */
7293 if (FC_TYPE(fc
) == FC_TYPE_MNG
) {
7294 if ((fc
& FC_KIND_MASK
) == FC_PROBE_REQ
)
7299 WL_ERROR(("%s: is_amsdu causing toss\n", __func__
));
7303 wlc_recvctl(wlc
, osh
, rxh
, p
);
7307 PKTFREE(osh
, p
, FALSE
);
7310 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7311 * number of bytes goes in the length field
7313 * Formula given by HT PHY Spec v 1.13
7314 * len = 3(nsyms + nstream + 3) - 3
7317 wlc_calc_lsig_len(wlc_info_t
*wlc
, ratespec_t ratespec
, uint mac_len
)
7319 uint nsyms
, len
= 0, kNdps
;
7321 WL_TRACE(("wl%d: wlc_calc_lsig_len: rate %d, len%d\n", wlc
->pub
->unit
,
7322 RSPEC2RATE(ratespec
), mac_len
));
7324 if (IS_MCS(ratespec
)) {
7325 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7326 /* MCS_TXS(mcs) returns num tx streams - 1 */
7327 int tot_streams
= (MCS_TXS(mcs
) + 1) + RSPEC_STC(ratespec
);
7329 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7330 /* the payload duration calculation matches that of regular ofdm */
7331 /* 1000Ndbps = kbps * 4 */
7333 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7334 RSPEC_ISSGI(ratespec
)) * 4;
7336 if (RSPEC_STC(ratespec
) == 0)
7337 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7339 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7340 APHY_TAIL_NBITS
) * 1000, kNdps
);
7342 /* STBC needs to have even number of symbols */
7345 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7346 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7348 nsyms
+= (tot_streams
+ 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7349 /* 3 bytes/symbol @ legacy 6Mbps rate */
7350 len
= (3 * nsyms
) - 3; /* (-3) excluding service bits and tail bits */
7356 /* calculate frame duration of a given rate and length, return time in usec unit */
7358 wlc_calc_frame_time(wlc_info_t
*wlc
, ratespec_t ratespec
, u8 preamble_type
,
7361 uint nsyms
, dur
= 0, Ndps
, kNdps
;
7362 uint rate
= RSPEC2RATE(ratespec
);
7366 WL_ERROR(("wl%d: WAR: using rate of 1 mbps\n", wlc
->pub
->unit
));
7370 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
));
7372 if (IS_MCS(ratespec
)) {
7373 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7374 int tot_streams
= MCS_TXS(mcs
) + RSPEC_STC(ratespec
);
7375 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7376 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type
));
7378 dur
= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
7379 if (preamble_type
== WLC_MM_PREAMBLE
)
7381 /* 1000Ndbps = kbps * 4 */
7383 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7384 RSPEC_ISSGI(ratespec
)) * 4;
7386 if (RSPEC_STC(ratespec
) == 0)
7387 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7389 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7390 APHY_TAIL_NBITS
) * 1000, kNdps
);
7392 /* STBC needs to have even number of symbols */
7395 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7396 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7398 dur
+= APHY_SYMBOL_TIME
* nsyms
;
7399 if (BAND_2G(wlc
->band
->bandtype
))
7400 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
7401 } else if (IS_OFDM(rate
)) {
7402 dur
= APHY_PREAMBLE_TIME
;
7403 dur
+= APHY_SIGNAL_TIME
;
7404 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7406 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7408 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+ APHY_TAIL_NBITS
),
7410 dur
+= APHY_SYMBOL_TIME
* nsyms
;
7411 if (BAND_2G(wlc
->band
->bandtype
))
7412 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
7414 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7415 mac_len
= mac_len
* 8 * 2;
7416 /* calc ceiling of bits/rate = microseconds of air time */
7417 dur
= (mac_len
+ rate
- 1) / rate
;
7418 if (preamble_type
& WLC_SHORT_PREAMBLE
)
7419 dur
+= BPHY_PLCP_SHORT_TIME
;
7421 dur
+= BPHY_PLCP_TIME
;
7426 /* The opposite of wlc_calc_frame_time */
7428 wlc_calc_frame_len(wlc_info_t
*wlc
, ratespec_t ratespec
, u8 preamble_type
,
7431 uint nsyms
, mac_len
, Ndps
, kNdps
;
7432 uint rate
= RSPEC2RATE(ratespec
);
7434 WL_TRACE(("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n", wlc
->pub
->unit
, ratespec
, preamble_type
, dur
));
7436 if (IS_MCS(ratespec
)) {
7437 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7438 int tot_streams
= MCS_TXS(mcs
) + RSPEC_STC(ratespec
);
7439 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7440 dur
-= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
7441 /* payload calculation matches that of regular ofdm */
7442 if (BAND_2G(wlc
->band
->bandtype
))
7443 dur
-= DOT11_OFDM_SIGNAL_EXTENSION
;
7444 /* kNdbps = kbps * 4 */
7446 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7447 RSPEC_ISSGI(ratespec
)) * 4;
7448 nsyms
= dur
/ APHY_SYMBOL_TIME
;
7451 ((APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
) * 1000)) / 8000;
7452 } else if (IS_OFDM(ratespec
)) {
7453 dur
-= APHY_PREAMBLE_TIME
;
7454 dur
-= APHY_SIGNAL_TIME
;
7455 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7457 nsyms
= dur
/ APHY_SYMBOL_TIME
;
7460 (APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
)) / 8;
7462 if (preamble_type
& WLC_SHORT_PREAMBLE
)
7463 dur
-= BPHY_PLCP_SHORT_TIME
;
7465 dur
-= BPHY_PLCP_TIME
;
7466 mac_len
= dur
* rate
;
7467 /* divide out factor of 2 in rate (1/2 mbps) */
7468 mac_len
= mac_len
/ 8 / 2;
7474 wlc_calc_ba_time(wlc_info_t
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7476 WL_TRACE(("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7477 wlc
->pub
->unit
, rspec
, preamble_type
));
7478 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7479 * or equal to the rate of the immediately previous frame in the FES
7481 rspec
= WLC_BASIC_RATE(wlc
, rspec
);
7482 ASSERT(VALID_RATE_DBG(wlc
, rspec
));
7484 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7485 return wlc_calc_frame_time(wlc
, rspec
, preamble_type
,
7486 (DOT11_BA_LEN
+ DOT11_BA_BITMAP_LEN
+
7490 static uint BCMFASTPATH
7491 wlc_calc_ack_time(wlc_info_t
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7495 WL_TRACE(("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7496 wlc
->pub
->unit
, rspec
, preamble_type
));
7497 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7498 * or equal to the rate of the immediately previous frame in the FES
7500 rspec
= WLC_BASIC_RATE(wlc
, rspec
);
7501 ASSERT(VALID_RATE_DBG(wlc
, rspec
));
7503 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7505 wlc_calc_frame_time(wlc
, rspec
, preamble_type
,
7506 (DOT11_ACK_LEN
+ DOT11_FCS_LEN
));
7511 wlc_calc_cts_time(wlc_info_t
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7513 WL_TRACE(("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7514 wlc
->pub
->unit
, rspec
, preamble_type
));
7515 return wlc_calc_ack_time(wlc
, rspec
, preamble_type
);
7518 /* derive wlc->band->basic_rate[] table from 'rateset' */
7519 void wlc_rate_lookup_init(wlc_info_t
*wlc
, wlc_rateset_t
*rateset
)
7525 u8
*br
= wlc
->band
->basic_rate
;
7528 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7529 bzero(br
, WLC_MAXRATE
+ 1);
7531 /* For each basic rate in the rates list, make an entry in the
7532 * best basic lookup.
7534 for (i
= 0; i
< rateset
->count
; i
++) {
7535 /* only make an entry for a basic rate */
7536 if (!(rateset
->rates
[i
] & WLC_RATE_FLAG
))
7539 /* mask off basic bit */
7540 rate
= (rateset
->rates
[i
] & RATE_MASK
);
7542 if (rate
> WLC_MAXRATE
) {
7543 WL_ERROR(("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n", rateset
->rates
[i
]));
7550 /* The rate lookup table now has non-zero entries for each
7551 * basic rate, equal to the basic rate: br[basicN] = basicN
7553 * To look up the best basic rate corresponding to any
7554 * particular rate, code can use the basic_rate table
7557 * basic_rate = wlc->band->basic_rate[tx_rate]
7559 * Make sure there is a best basic rate entry for
7560 * every rate by walking up the table from low rates
7561 * to high, filling in holes in the lookup table
7564 for (i
= 0; i
< wlc
->band
->hw_rateset
.count
; i
++) {
7565 rate
= wlc
->band
->hw_rateset
.rates
[i
];
7566 ASSERT(rate
<= WLC_MAXRATE
);
7568 if (br
[rate
] != 0) {
7569 /* This rate is a basic rate.
7570 * Keep track of the best basic rate so far by
7581 /* This rate is not a basic rate so figure out the
7582 * best basic rate less than this rate and fill in
7583 * the hole in the table
7586 br
[rate
] = IS_OFDM(rate
) ? ofdm_basic
: cck_basic
;
7591 if (IS_OFDM(rate
)) {
7592 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7593 if (rate
>= WLC_RATE_24M
)
7594 mandatory
= WLC_RATE_24M
;
7595 else if (rate
>= WLC_RATE_12M
)
7596 mandatory
= WLC_RATE_12M
;
7598 mandatory
= WLC_RATE_6M
;
7600 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7604 br
[rate
] = mandatory
;
7608 static void wlc_write_rate_shm(wlc_info_t
*wlc
, u8 rate
, u8 basic_rate
)
7611 u8 basic_phy_rate
, basic_index
;
7612 u16 dir_table
, basic_table
;
7615 /* Shared memory address for the table we are reading */
7616 dir_table
= IS_OFDM(basic_rate
) ? M_RT_DIRMAP_A
: M_RT_DIRMAP_B
;
7618 /* Shared memory address for the table we are writing */
7619 basic_table
= IS_OFDM(rate
) ? M_RT_BBRSMAP_A
: M_RT_BBRSMAP_B
;
7622 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7623 * the index into the rate table.
7625 phy_rate
= rate_info
[rate
] & RATE_MASK
;
7626 basic_phy_rate
= rate_info
[basic_rate
] & RATE_MASK
;
7627 index
= phy_rate
& 0xf;
7628 basic_index
= basic_phy_rate
& 0xf;
7630 /* Find the SHM pointer to the ACK rate entry by looking in the
7633 basic_ptr
= wlc_read_shm(wlc
, (dir_table
+ basic_index
* 2));
7635 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7636 * to the correct basic rate for the given incoming rate
7638 wlc_write_shm(wlc
, (basic_table
+ index
* 2), basic_ptr
);
7641 static const wlc_rateset_t
*wlc_rateset_get_hwrs(wlc_info_t
*wlc
)
7643 const wlc_rateset_t
*rs_dflt
;
7645 if (WLC_PHY_11N_CAP(wlc
->band
)) {
7646 if (BAND_5G(wlc
->band
->bandtype
))
7647 rs_dflt
= &ofdm_mimo_rates
;
7649 rs_dflt
= &cck_ofdm_mimo_rates
;
7650 } else if (wlc
->band
->gmode
)
7651 rs_dflt
= &cck_ofdm_rates
;
7653 rs_dflt
= &cck_rates
;
7658 void wlc_set_ratetable(wlc_info_t
*wlc
)
7660 const wlc_rateset_t
*rs_dflt
;
7662 u8 rate
, basic_rate
;
7665 rs_dflt
= wlc_rateset_get_hwrs(wlc
);
7666 ASSERT(rs_dflt
!= NULL
);
7668 wlc_rateset_copy(rs_dflt
, &rs
);
7669 wlc_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7671 /* walk the phy rate table and update SHM basic rate lookup table */
7672 for (i
= 0; i
< rs
.count
; i
++) {
7673 rate
= rs
.rates
[i
] & RATE_MASK
;
7675 /* for a given rate WLC_BASIC_RATE returns the rate at
7676 * which a response ACK/CTS should be sent.
7678 basic_rate
= WLC_BASIC_RATE(wlc
, rate
);
7679 if (basic_rate
== 0) {
7680 /* This should only happen if we are using a
7681 * restricted rateset.
7683 basic_rate
= rs
.rates
[0] & RATE_MASK
;
7686 wlc_write_rate_shm(wlc
, rate
, basic_rate
);
7691 * Return true if the specified rate is supported by the specified band.
7692 * WLC_BAND_AUTO indicates the current band.
7694 bool wlc_valid_rate(wlc_info_t
*wlc
, ratespec_t rspec
, int band
, bool verbose
)
7696 wlc_rateset_t
*hw_rateset
;
7699 if ((band
== WLC_BAND_AUTO
) || (band
== wlc
->band
->bandtype
)) {
7700 hw_rateset
= &wlc
->band
->hw_rateset
;
7701 } else if (NBANDS(wlc
) > 1) {
7702 hw_rateset
= &wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->hw_rateset
;
7704 /* other band specified and we are a single band device */
7708 /* check if this is a mimo rate */
7709 if (IS_MCS(rspec
)) {
7710 if (!VALID_MCS((rspec
& RSPEC_RATE_MASK
)))
7713 return isset(hw_rateset
->mcs
, (rspec
& RSPEC_RATE_MASK
));
7716 for (i
= 0; i
< hw_rateset
->count
; i
++)
7717 if (hw_rateset
->rates
[i
] == RSPEC2RATE(rspec
))
7721 WL_ERROR(("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n", wlc
->pub
->unit
, rspec
));
7727 static void wlc_update_mimo_band_bwcap(wlc_info_t
*wlc
, u8 bwcap
)
7732 for (i
= 0; i
< NBANDS(wlc
); i
++) {
7733 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
7735 band
= wlc
->bandstate
[i
];
7736 if (band
->bandtype
== WLC_BAND_5G
) {
7737 if ((bwcap
== WLC_N_BW_40ALL
)
7738 || (bwcap
== WLC_N_BW_20IN2G_40IN5G
))
7739 band
->mimo_cap_40
= TRUE
;
7741 band
->mimo_cap_40
= FALSE
;
7743 ASSERT(band
->bandtype
== WLC_BAND_2G
);
7744 if (bwcap
== WLC_N_BW_40ALL
)
7745 band
->mimo_cap_40
= TRUE
;
7747 band
->mimo_cap_40
= FALSE
;
7751 wlc
->mimo_band_bwcap
= bwcap
;
7754 void wlc_mod_prb_rsp_rate_table(wlc_info_t
*wlc
, uint frame_len
)
7756 const wlc_rateset_t
*rs_dflt
;
7760 u8 plcp
[D11_PHY_HDR_LEN
];
7764 sifs
= SIFS(wlc
->band
);
7766 rs_dflt
= wlc_rateset_get_hwrs(wlc
);
7767 ASSERT(rs_dflt
!= NULL
);
7769 wlc_rateset_copy(rs_dflt
, &rs
);
7770 wlc_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7772 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7773 for (i
= 0; i
< rs
.count
; i
++) {
7774 rate
= rs
.rates
[i
] & RATE_MASK
;
7776 entry_ptr
= wlc_rate_shm_offset(wlc
, rate
);
7778 /* Calculate the Probe Response PLCP for the given rate */
7779 wlc_compute_plcp(wlc
, rate
, frame_len
, plcp
);
7781 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7783 (u16
) wlc_calc_frame_time(wlc
, rate
, WLC_LONG_PREAMBLE
,
7787 /* Update the SHM Rate Table entry Probe Response values */
7788 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_PLCP_POS
,
7789 (u16
) (plcp
[0] + (plcp
[1] << 8)));
7790 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_PLCP_POS
+ 2,
7791 (u16
) (plcp
[2] + (plcp
[3] << 8)));
7792 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_DUR_POS
, dur
);
7797 wlc_compute_bcntsfoff(wlc_info_t
*wlc
, ratespec_t rspec
, bool short_preamble
,
7802 if (IS_MCS(rspec
)) {
7803 WL_ERROR(("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7804 wlc
->pub
->unit
, rspec
));
7805 } else if (IS_OFDM(rspec
)) {
7806 /* tx delay from MAC through phy to air (2.1 usec) +
7807 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7808 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7809 * bytes at beacon rate)
7811 bcntsfoff
+= phydelay
? D11A_PHY_TX_DELAY
: 0;
7812 bcntsfoff
+= APHY_PREAMBLE_TIME
+ APHY_SIGNAL_TIME
;
7814 wlc_compute_airtime(wlc
, rspec
,
7815 APHY_SERVICE_NBITS
/ 8 +
7818 /* tx delay from MAC through phy to air (3.4 usec) +
7819 * phy header time (long preamble + PLCP == 192 usec) +
7820 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7822 bcntsfoff
+= phydelay
? D11B_PHY_TX_DELAY
: 0;
7824 short_preamble
? D11B_PHY_SPREHDR_TIME
:
7825 D11B_PHY_LPREHDR_TIME
;
7826 bcntsfoff
+= wlc_compute_airtime(wlc
, rspec
, DOT11_MAC_HDR_LEN
);
7828 return (u16
) (bcntsfoff
);
7831 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7833 * PLCP header is 6 bytes.
7834 * 802.11 A3 header is 24 bytes.
7835 * Max beacon frame body template length is 112 bytes.
7836 * Max probe resp frame body template length is 110 bytes.
7838 * *len on input contains the max length of the packet available.
7840 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7841 * and included up to, but not including, the 4 byte FCS.
7844 wlc_bcn_prb_template(wlc_info_t
*wlc
, uint type
, ratespec_t bcn_rspec
,
7845 wlc_bsscfg_t
*cfg
, u16
*buf
, int *len
)
7847 cck_phy_hdr_t
*plcp
;
7848 struct dot11_management_header
*h
;
7849 int hdr_len
, body_len
;
7851 ASSERT(*len
>= 142);
7852 ASSERT(type
== FC_BEACON
|| type
== FC_PROBE_RESP
);
7854 if (MBSS_BCN_ENAB(cfg
) && type
== FC_BEACON
)
7855 hdr_len
= DOT11_MAC_HDR_LEN
;
7857 hdr_len
= D11_PHY_HDR_LEN
+ DOT11_MAC_HDR_LEN
;
7858 body_len
= *len
- hdr_len
; /* calc buffer size provided for frame body */
7860 *len
= hdr_len
+ body_len
; /* return actual size */
7862 /* format PHY and MAC headers */
7863 bzero((char *)buf
, hdr_len
);
7865 plcp
= (cck_phy_hdr_t
*) buf
;
7867 /* PLCP for Probe Response frames are filled in from core's rate table */
7868 if (type
== FC_BEACON
&& !MBSS_BCN_ENAB(cfg
)) {
7870 wlc_compute_plcp(wlc
, bcn_rspec
,
7871 (DOT11_MAC_HDR_LEN
+ body_len
+ DOT11_FCS_LEN
),
7875 /* "Regular" and 16 MBSS but not for 4 MBSS */
7876 /* Update the phytxctl for the beacon based on the rspec */
7877 if (!SOFTBCN_ENAB(cfg
))
7878 wlc_beacon_phytxctl_txant_upd(wlc
, bcn_rspec
);
7880 if (MBSS_BCN_ENAB(cfg
) && type
== FC_BEACON
)
7881 h
= (struct dot11_management_header
*)&plcp
[0];
7883 h
= (struct dot11_management_header
*)&plcp
[1];
7885 /* fill in 802.11 header */
7886 h
->fc
= htol16((u16
) type
);
7888 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7889 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7890 if (type
== FC_BEACON
)
7891 bcopy((const char *)ðer_bcast
, (char *)&h
->da
,
7893 bcopy((char *)&cfg
->cur_etheraddr
, (char *)&h
->sa
, ETHER_ADDR_LEN
);
7894 bcopy((char *)&cfg
->BSSID
, (char *)&h
->bssid
, ETHER_ADDR_LEN
);
7896 /* SEQ filled in by MAC */
7901 int wlc_get_header_len()
7906 /* Update a beacon for a particular BSS
7907 * For MBSS, this updates the software template and sets "latest" to the index of the
7909 * Otherwise, it updates the hardware template.
7911 void wlc_bss_update_beacon(wlc_info_t
*wlc
, wlc_bsscfg_t
*cfg
)
7913 int len
= BCN_TMPL_LEN
;
7915 /* Clear the soft intmask */
7916 wlc
->defmacintmask
&= ~MI_BCNTPL
;
7918 if (!cfg
->up
) { /* Only allow updates on an UP bss */
7922 if (MBSS_BCN_ENAB(cfg
)) { /* Optimize: Some of if/else could be combined */
7923 } else if (HWBCN_ENAB(cfg
)) { /* Hardware beaconing for this config */
7924 u16 bcn
[BCN_TMPL_LEN
/ 2];
7925 u32 both_valid
= MCMD_BCN0VLD
| MCMD_BCN1VLD
;
7926 d11regs_t
*regs
= wlc
->regs
;
7931 /* Check if both templates are in use, if so sched. an interrupt
7932 * that will call back into this routine
7934 if ((R_REG(osh
, ®s
->maccommand
) & both_valid
) == both_valid
) {
7935 /* clear any previous status */
7936 W_REG(osh
, ®s
->macintstatus
, MI_BCNTPL
);
7938 /* Check that after scheduling the interrupt both of the
7939 * templates are still busy. if not clear the int. & remask
7941 if ((R_REG(osh
, ®s
->maccommand
) & both_valid
) == both_valid
) {
7942 wlc
->defmacintmask
|= MI_BCNTPL
;
7947 wlc_lowest_basic_rspec(wlc
, &cfg
->current_bss
->rateset
);
7948 ASSERT(wlc_valid_rate
7949 (wlc
, wlc
->bcn_rspec
,
7950 CHSPEC_IS2G(cfg
->current_bss
->
7951 chanspec
) ? WLC_BAND_2G
: WLC_BAND_5G
,
7954 /* update the template and ucode shm */
7955 wlc_bcn_prb_template(wlc
, FC_BEACON
, wlc
->bcn_rspec
, cfg
, bcn
,
7957 wlc_write_hw_bcntemplates(wlc
, bcn
, len
, FALSE
);
7962 * Update all beacons for the system.
7964 void wlc_update_beacon(wlc_info_t
*wlc
)
7967 wlc_bsscfg_t
*bsscfg
;
7969 /* update AP or IBSS beacons */
7970 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7971 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7972 wlc_bss_update_beacon(wlc
, bsscfg
);
7976 /* Write ssid into shared memory */
7977 void wlc_shm_ssid_upd(wlc_info_t
*wlc
, wlc_bsscfg_t
*cfg
)
7979 u8
*ssidptr
= cfg
->SSID
;
7981 u8 ssidbuf
[DOT11_MAX_SSID_LEN
];
7983 /* padding the ssid with zero and copy it into shm */
7984 bzero(ssidbuf
, DOT11_MAX_SSID_LEN
);
7985 bcopy(ssidptr
, ssidbuf
, cfg
->SSID_len
);
7987 wlc_copyto_shm(wlc
, base
, ssidbuf
, DOT11_MAX_SSID_LEN
);
7989 if (!MBSS_BCN_ENAB(cfg
))
7990 wlc_write_shm(wlc
, M_SSIDLEN
, (u16
) cfg
->SSID_len
);
7993 void wlc_update_probe_resp(wlc_info_t
*wlc
, bool suspend
)
7996 wlc_bsscfg_t
*bsscfg
;
7998 /* update AP or IBSS probe responses */
7999 FOREACH_BSS(wlc
, idx
, bsscfg
) {
8000 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
8001 wlc_bss_update_probe_resp(wlc
, bsscfg
, suspend
);
8006 wlc_bss_update_probe_resp(wlc_info_t
*wlc
, wlc_bsscfg_t
*cfg
, bool suspend
)
8008 u16 prb_resp
[BCN_TMPL_LEN
/ 2];
8009 int len
= BCN_TMPL_LEN
;
8011 /* write the probe response to hardware, or save in the config structure */
8012 if (!MBSS_PRB_ENAB(cfg
)) {
8014 /* create the probe response template */
8015 wlc_bcn_prb_template(wlc
, FC_PROBE_RESP
, 0, cfg
, prb_resp
,
8019 wlc_suspend_mac_and_wait(wlc
);
8021 /* write the probe response into the template region */
8022 wlc_bmac_write_template_ram(wlc
->hw
, T_PRS_TPL_BASE
,
8023 (len
+ 3) & ~3, prb_resp
);
8025 /* write the length of the probe response frame (+PLCP/-FCS) */
8026 wlc_write_shm(wlc
, M_PRB_RESP_FRM_LEN
, (u16
) len
);
8028 /* write the SSID and SSID length */
8029 wlc_shm_ssid_upd(wlc
, cfg
);
8032 * Write PLCP headers and durations for probe response frames at all rates.
8033 * Use the actual frame length covered by the PLCP header for the call to
8034 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
8036 len
+= (-D11_PHY_HDR_LEN
+ DOT11_FCS_LEN
);
8037 wlc_mod_prb_rsp_rate_table(wlc
, (u16
) len
);
8040 wlc_enable_mac(wlc
);
8041 } else { /* Generating probe resp in sw; update local template */
8042 ASSERT(0 && "No software probe response support without MBSS");
8046 /* prepares pdu for transmission. returns BCM error codes */
8047 int wlc_prep_pdu(wlc_info_t
*wlc
, void *pdu
, uint
*fifop
)
8052 struct dot11_header
*h
;
8059 txh
= (d11txh_t
*) PKTDATA(pdu
);
8061 h
= (struct dot11_header
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
8065 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
8066 fifo
= ltoh16(txh
->TxFrameID
) & TXFID_QUEUE_MASK
;
8072 /* return if insufficient dma resources */
8073 if (TXAVAIL(wlc
, fifo
) < MAX_DMA_SEGS
) {
8074 /* Mark precedences related to this FIFO, unsendable */
8075 WLC_TX_FIFO_CLEAR(wlc
, fifo
);
8079 if (FC_TYPE(ltoh16(txh
->MacFrameControl
)) != FC_TYPE_DATA
)
8080 WLCNTINCR(wlc
->pub
->_cnt
->txctl
);
8085 /* init tx reported rate mechanism */
8086 void wlc_reprate_init(wlc_info_t
*wlc
)
8089 wlc_bsscfg_t
*bsscfg
;
8091 FOREACH_BSS(wlc
, i
, bsscfg
) {
8092 wlc_bsscfg_reprate_init(bsscfg
);
8096 /* per bsscfg init tx reported rate mechanism */
8097 void wlc_bsscfg_reprate_init(wlc_bsscfg_t
*bsscfg
)
8099 bsscfg
->txrspecidx
= 0;
8100 bzero((char *)bsscfg
->txrspec
, sizeof(bsscfg
->txrspec
));
8103 /* Retrieve a consolidated set of revision information,
8104 * typically for the WLC_GET_REVINFO ioctl
8106 int wlc_get_revision_info(wlc_info_t
*wlc
, void *buf
, uint len
)
8108 wlc_rev_info_t
*rinfo
= (wlc_rev_info_t
*) buf
;
8110 if (len
< WL_REV_INFO_LEGACY_LENGTH
)
8111 return BCME_BUFTOOSHORT
;
8113 rinfo
->vendorid
= wlc
->vendorid
;
8114 rinfo
->deviceid
= wlc
->deviceid
;
8115 rinfo
->radiorev
= (wlc
->band
->radiorev
<< IDCODE_REV_SHIFT
) |
8116 (wlc
->band
->radioid
<< IDCODE_ID_SHIFT
);
8117 rinfo
->chiprev
= wlc
->pub
->sih
->chiprev
;
8118 rinfo
->corerev
= wlc
->pub
->corerev
;
8119 rinfo
->boardid
= wlc
->pub
->sih
->boardtype
;
8120 rinfo
->boardvendor
= wlc
->pub
->sih
->boardvendor
;
8121 rinfo
->boardrev
= wlc
->pub
->boardrev
;
8122 rinfo
->ucoderev
= wlc
->ucode_rev
;
8123 rinfo
->driverrev
= EPI_VERSION_NUM
;
8124 rinfo
->bus
= wlc
->pub
->sih
->bustype
;
8125 rinfo
->chipnum
= wlc
->pub
->sih
->chip
;
8127 if (len
>= (OFFSETOF(wlc_rev_info_t
, chippkg
))) {
8128 rinfo
->phytype
= wlc
->band
->phytype
;
8129 rinfo
->phyrev
= wlc
->band
->phyrev
;
8130 rinfo
->anarev
= 0; /* obsolete stuff, suppress */
8133 if (len
>= sizeof(*rinfo
)) {
8134 rinfo
->chippkg
= wlc
->pub
->sih
->chippkg
;
8140 void wlc_default_rateset(wlc_info_t
*wlc
, wlc_rateset_t
*rs
)
8142 wlc_rateset_default(rs
, NULL
, wlc
->band
->phytype
, wlc
->band
->bandtype
,
8143 FALSE
, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
8144 CHSPEC_WLC_BW(wlc
->default_bss
->chanspec
),
8145 wlc
->stf
->txstreams
);
8148 static void BCMATTACHFN(wlc_bss_default_init
) (wlc_info_t
*wlc
)
8150 chanspec_t chanspec
;
8152 wlc_bss_info_t
*bi
= wlc
->default_bss
;
8154 /* init default and target BSS with some sane initial values */
8155 bzero((char *)(bi
), sizeof(wlc_bss_info_t
));
8156 bi
->beacon_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? BEACON_INTERVAL_DEF_QT
:
8157 BEACON_INTERVAL_DEFAULT
;
8158 bi
->dtim_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? DTIM_INTERVAL_DEF_QT
:
8159 DTIM_INTERVAL_DEFAULT
;
8161 /* fill the default channel as the first valid channel
8162 * starting from the 2G channels
8164 chanspec
= CH20MHZ_CHSPEC(1);
8165 ASSERT(chanspec
!= INVCHANSPEC
);
8167 wlc
->home_chanspec
= bi
->chanspec
= chanspec
;
8169 /* find the band of our default channel */
8171 if (NBANDS(wlc
) > 1 && band
->bandunit
!= CHSPEC_WLCBANDUNIT(chanspec
))
8172 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
8174 /* init bss rates to the band specific default rate set */
8175 wlc_rateset_default(&bi
->rateset
, NULL
, band
->phytype
, band
->bandtype
,
8176 FALSE
, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
8177 CHSPEC_WLC_BW(chanspec
), wlc
->stf
->txstreams
);
8179 if (N_ENAB(wlc
->pub
))
8180 bi
->flags
|= WLC_BSS_HT
;
8183 /* Deferred event processing */
8184 static void wlc_process_eventq(void *arg
)
8186 wlc_info_t
*wlc
= (wlc_info_t
*) arg
;
8189 while ((etmp
= wlc_eventq_deq(wlc
->eventq
))) {
8190 /* Perform OS specific event processing */
8191 wl_event(wlc
->wl
, etmp
->event
.ifname
, etmp
);
8193 osl_mfree(wlc
->osh
, etmp
->data
, etmp
->event
.datalen
);
8196 wlc_event_free(wlc
->eventq
, etmp
);
8201 wlc_uint64_sub(u32
*a_high
, u32
*a_low
, u32 b_high
, u32 b_low
)
8203 if (b_low
> *a_low
) {
8204 /* low half needs a carry */
8212 mac80211_wlc_set_nrate(wlc_info_t
*wlc
, wlcband_t
*cur_band
, u32 int_val
)
8214 u8 stf
= (int_val
& NRATE_STF_MASK
) >> NRATE_STF_SHIFT
;
8215 u8 rate
= int_val
& NRATE_RATE_MASK
;
8217 bool ismcs
= ((int_val
& NRATE_MCS_INUSE
) == NRATE_MCS_INUSE
);
8218 bool issgi
= ((int_val
& NRATE_SGI_MASK
) >> NRATE_SGI_SHIFT
);
8219 bool override_mcs_only
= ((int_val
& NRATE_OVERRIDE_MCS_ONLY
)
8220 == NRATE_OVERRIDE_MCS_ONLY
);
8224 return (ratespec_t
) rate
;
8227 /* validate the combination of rate/mcs/stf is allowed */
8228 if (N_ENAB(wlc
->pub
) && ismcs
) {
8229 /* mcs only allowed when nmode */
8230 if (stf
> PHY_TXC1_MODE_SDM
) {
8231 WL_ERROR(("wl%d: %s: Invalid stf\n", WLCWLUNIT(wlc
),
8233 bcmerror
= BCME_RANGE
;
8237 /* mcs 32 is a special case, DUP mode 40 only */
8239 if (!CHSPEC_IS40(wlc
->home_chanspec
) ||
8240 ((stf
!= PHY_TXC1_MODE_SISO
)
8241 && (stf
!= PHY_TXC1_MODE_CDD
))) {
8242 WL_ERROR(("wl%d: %s: Invalid mcs 32\n",
8243 WLCWLUNIT(wlc
), __func__
));
8244 bcmerror
= BCME_RANGE
;
8247 /* mcs > 7 must use stf SDM */
8248 } else if (rate
> HIGHEST_SINGLE_STREAM_MCS
) {
8249 /* mcs > 7 must use stf SDM */
8250 if (stf
!= PHY_TXC1_MODE_SDM
) {
8251 WL_TRACE(("wl%d: %s: enabling SDM mode for mcs %d\n", WLCWLUNIT(wlc
), __func__
, rate
));
8252 stf
= PHY_TXC1_MODE_SDM
;
8255 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8256 if ((stf
> PHY_TXC1_MODE_STBC
) ||
8257 (!WLC_STBC_CAP_PHY(wlc
)
8258 && (stf
== PHY_TXC1_MODE_STBC
))) {
8259 WL_ERROR(("wl%d: %s: Invalid STBC\n",
8260 WLCWLUNIT(wlc
), __func__
));
8261 bcmerror
= BCME_RANGE
;
8265 } else if (IS_OFDM(rate
)) {
8266 if ((stf
!= PHY_TXC1_MODE_CDD
) && (stf
!= PHY_TXC1_MODE_SISO
)) {
8267 WL_ERROR(("wl%d: %s: Invalid OFDM\n", WLCWLUNIT(wlc
),
8269 bcmerror
= BCME_RANGE
;
8272 } else if (IS_CCK(rate
)) {
8273 if ((cur_band
->bandtype
!= WLC_BAND_2G
)
8274 || (stf
!= PHY_TXC1_MODE_SISO
)) {
8275 WL_ERROR(("wl%d: %s: Invalid CCK\n", WLCWLUNIT(wlc
),
8277 bcmerror
= BCME_RANGE
;
8281 WL_ERROR(("wl%d: %s: Unknown rate type\n", WLCWLUNIT(wlc
),
8283 bcmerror
= BCME_RANGE
;
8286 /* make sure multiple antennae are available for non-siso rates */
8287 if ((stf
!= PHY_TXC1_MODE_SISO
) && (wlc
->stf
->txstreams
== 1)) {
8288 WL_ERROR(("wl%d: %s: SISO antenna but !SISO request\n",
8289 WLCWLUNIT(wlc
), __func__
));
8290 bcmerror
= BCME_RANGE
;
8296 rspec
|= RSPEC_MIMORATE
;
8297 /* For STBC populate the STC field of the ratespec */
8298 if (stf
== PHY_TXC1_MODE_STBC
) {
8300 stc
= 1; /* Nss for single stream is always 1 */
8301 rspec
|= (stc
<< RSPEC_STC_SHIFT
);
8305 rspec
|= (stf
<< RSPEC_STF_SHIFT
);
8307 if (override_mcs_only
)
8308 rspec
|= RSPEC_OVERRIDE_MCS_ONLY
;
8311 rspec
|= RSPEC_SHORT_GI
;
8314 && !wlc_valid_rate(wlc
, rspec
, cur_band
->bandtype
, TRUE
)) {
8320 WL_ERROR(("Hoark\n"));
8324 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8326 wlc_duty_cycle_set(wlc_info_t
*wlc
, int duty_cycle
, bool isOFDM
,
8329 int idle_busy_ratio_x_16
= 0;
8331 isOFDM
? M_TX_IDLE_BUSY_RATIO_X_16_OFDM
:
8332 M_TX_IDLE_BUSY_RATIO_X_16_CCK
;
8333 if (duty_cycle
> 100 || duty_cycle
< 0) {
8334 WL_ERROR(("wl%d: duty cycle value off limit\n",
8339 idle_busy_ratio_x_16
= (100 - duty_cycle
) * 16 / duty_cycle
;
8340 /* Only write to shared memory when wl is up */
8342 wlc_write_shm(wlc
, offset
, (u16
) idle_busy_ratio_x_16
);
8345 wlc
->tx_duty_cycle_ofdm
= (u16
) duty_cycle
;
8347 wlc
->tx_duty_cycle_cck
= (u16
) duty_cycle
;
8353 wlc_pktengtx(wlc_info_t
*wlc
, wl_pkteng_t
*pkteng
, u8 rate
,
8354 struct ether_addr
*sa
, u32 wait_delay
)
8357 u16 val
= M_PKTENG_MODE_TX
;
8358 volatile u16 frame_cnt_check
;
8361 wlc_bmac_set_deaf(wlc
->hw
, TRUE
);
8364 (0 == (R_REG(wlc
->hw
->osh
, &wlc
->regs
->maccontrol
) & MCTL_EN_MAC
));
8366 wlc_enable_mac(wlc
);
8369 if (pkteng
->nframes
) {
8370 /* retry counter is used to replay the packet */
8371 wlc_bmac_write_shm(wlc
->hw
, M_PKTENG_FRMCNT_LO
,
8372 (pkteng
->nframes
& 0xffff));
8373 wlc_bmac_write_shm(wlc
->hw
, M_PKTENG_FRMCNT_HI
,
8374 ((pkteng
->nframes
>> 16) & 0xffff));
8375 val
|= M_PKTENG_FRMCNT_VLD
;
8378 if (pkteng
->length
) {
8380 wlc_bmac_write_shm(wlc
->hw
, M_PKTENG_CTRL
, val
);
8381 /* we write to M_MFGTEST_IFS the IFS required in 1/8us factor */
8382 /* 10 : for factoring difference b/w Tx.crs and energy in air */
8383 /* 44 : amount of time spent after TX_RRSP to frame start */
8385 wlc_bmac_write_shm(wlc
->hw
, M_PKTENG_IFS
,
8386 (pkteng
->delay
- 10) * 8 - 44);
8389 val
|= M_PKTENG_MODE_TX_CTS
;
8390 wlc_bmac_write_shm(wlc
->hw
, M_PKTENG_IFS
,
8391 (u16
) pkteng
->delay
);
8392 wlc_bmac_write_shm(wlc
->hw
, M_PKTENG_CTRL
, val
);
8395 /* Wait for packets to finish */
8396 frame_cnt_check
= wlc_bmac_read_shm(wlc
->hw
, M_PKTENG_FRMCNT_LO
);
8397 while ((counter
< 100) && (frame_cnt_check
!= 0)) {
8400 wlc_bmac_read_shm(wlc
->hw
, M_PKTENG_FRMCNT_LO
);
8404 wlc_bmac_write_shm(wlc
->hw
, M_PKTENG_CTRL
, 0);
8407 wlc_suspend_mac_and_wait(wlc
);
8409 wlc_bmac_set_deaf(wlc
->hw
, FALSE
);
8412 /* Read a single u16 from shared memory.
8413 * SHM 'offset' needs to be an even address
8415 u16
wlc_read_shm(wlc_info_t
*wlc
, uint offset
)
8417 return wlc_bmac_read_shm(wlc
->hw
, offset
);
8420 /* Write a single u16 to shared memory.
8421 * SHM 'offset' needs to be an even address
8423 void wlc_write_shm(wlc_info_t
*wlc
, uint offset
, u16 v
)
8425 wlc_bmac_write_shm(wlc
->hw
, offset
, v
);
8428 /* Set a range of shared memory to a value.
8429 * SHM 'offset' needs to be an even address and
8430 * Range length 'len' must be an even number of bytes
8432 void wlc_set_shm(wlc_info_t
*wlc
, uint offset
, u16 v
, int len
)
8434 /* offset and len need to be even */
8435 ASSERT((offset
& 1) == 0);
8436 ASSERT((len
& 1) == 0);
8441 wlc_bmac_set_shm(wlc
->hw
, offset
, v
, len
);
8444 /* Copy a buffer to shared memory.
8445 * SHM 'offset' needs to be an even address and
8446 * Buffer length 'len' must be an even number of bytes
8448 void wlc_copyto_shm(wlc_info_t
*wlc
, uint offset
, const void *buf
, int len
)
8450 /* offset and len need to be even */
8451 ASSERT((offset
& 1) == 0);
8452 ASSERT((len
& 1) == 0);
8456 wlc_bmac_copyto_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8460 /* Copy from shared memory to a buffer.
8461 * SHM 'offset' needs to be an even address and
8462 * Buffer length 'len' must be an even number of bytes
8464 void wlc_copyfrom_shm(wlc_info_t
*wlc
, uint offset
, void *buf
, int len
)
8466 /* offset and len need to be even */
8467 ASSERT((offset
& 1) == 0);
8468 ASSERT((len
& 1) == 0);
8473 wlc_bmac_copyfrom_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8476 /* wrapper BMAC functions to for HIGH driver access */
8477 void wlc_mctrl(wlc_info_t
*wlc
, u32 mask
, u32 val
)
8479 wlc_bmac_mctrl(wlc
->hw
, mask
, val
);
8482 void wlc_corereset(wlc_info_t
*wlc
, u32 flags
)
8484 wlc_bmac_corereset(wlc
->hw
, flags
);
8487 void wlc_mhf(wlc_info_t
*wlc
, u8 idx
, u16 mask
, u16 val
, int bands
)
8489 wlc_bmac_mhf(wlc
->hw
, idx
, mask
, val
, bands
);
8492 u16
wlc_mhf_get(wlc_info_t
*wlc
, u8 idx
, int bands
)
8494 return wlc_bmac_mhf_get(wlc
->hw
, idx
, bands
);
8497 int wlc_xmtfifo_sz_get(wlc_info_t
*wlc
, uint fifo
, uint
*blocks
)
8499 return wlc_bmac_xmtfifo_sz_get(wlc
->hw
, fifo
, blocks
);
8502 void wlc_write_template_ram(wlc_info_t
*wlc
, int offset
, int len
, void *buf
)
8504 wlc_bmac_write_template_ram(wlc
->hw
, offset
, len
, buf
);
8507 void wlc_write_hw_bcntemplates(wlc_info_t
*wlc
, void *bcn
, int len
, bool both
)
8509 wlc_bmac_write_hw_bcntemplates(wlc
->hw
, bcn
, len
, both
);
8513 wlc_set_addrmatch(wlc_info_t
*wlc
, int match_reg_offset
,
8514 const struct ether_addr
*addr
)
8516 wlc_bmac_set_addrmatch(wlc
->hw
, match_reg_offset
, addr
);
8519 void wlc_set_rcmta(wlc_info_t
*wlc
, int idx
, const struct ether_addr
*addr
)
8521 wlc_bmac_set_rcmta(wlc
->hw
, idx
, addr
);
8524 void wlc_read_tsf(wlc_info_t
*wlc
, u32
*tsf_l_ptr
, u32
*tsf_h_ptr
)
8526 wlc_bmac_read_tsf(wlc
->hw
, tsf_l_ptr
, tsf_h_ptr
);
8529 void wlc_set_cwmin(wlc_info_t
*wlc
, u16 newmin
)
8531 wlc
->band
->CWmin
= newmin
;
8532 wlc_bmac_set_cwmin(wlc
->hw
, newmin
);
8535 void wlc_set_cwmax(wlc_info_t
*wlc
, u16 newmax
)
8537 wlc
->band
->CWmax
= newmax
;
8538 wlc_bmac_set_cwmax(wlc
->hw
, newmax
);
8541 void wlc_fifoerrors(wlc_info_t
*wlc
)
8544 wlc_bmac_fifoerrors(wlc
->hw
);
8547 /* Search mem rw utilities */
8549 void wlc_pllreq(wlc_info_t
*wlc
, bool set
, mbool req_bit
)
8551 wlc_bmac_pllreq(wlc
->hw
, set
, req_bit
);
8554 void wlc_reset_bmac_done(wlc_info_t
*wlc
)
8556 #ifdef WLC_HIGH_ONLY
8557 wlc
->reset_bmac_pending
= FALSE
;
8561 void wlc_ht_mimops_cap_update(wlc_info_t
*wlc
, u8 mimops_mode
)
8563 wlc
->ht_cap
.cap
&= ~HT_CAP_MIMO_PS_MASK
;
8564 wlc
->ht_cap
.cap
|= (mimops_mode
<< HT_CAP_MIMO_PS_SHIFT
);
8566 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
8567 wlc_update_beacon(wlc
);
8568 wlc_update_probe_resp(wlc
, TRUE
);
8572 /* check for the particular priority flow control bit being set */
8574 wlc_txflowcontrol_prio_isset(wlc_info_t
*wlc
, wlc_txq_info_t
*q
, int prio
)
8578 if (prio
== ALLPRIO
) {
8579 prio_mask
= TXQ_STOP_FOR_PRIOFC_MASK
;
8581 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8582 prio_mask
= NBITVAL(prio
);
8585 return (q
->stopped
& prio_mask
) == prio_mask
;
8588 /* propogate the flow control to all interfaces using the given tx queue */
8589 void wlc_txflowcontrol(wlc_info_t
*wlc
, wlc_txq_info_t
*qi
, bool on
, int prio
)
8594 WL_ERROR(("%s: flow contro kicks in\n", __func__
));
8596 if (prio
== ALLPRIO
) {
8597 prio_bits
= TXQ_STOP_FOR_PRIOFC_MASK
;
8599 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8600 prio_bits
= NBITVAL(prio
);
8603 cur_bits
= qi
->stopped
& prio_bits
;
8605 /* Check for the case of no change and return early
8606 * Otherwise update the bit and continue
8609 if (cur_bits
== prio_bits
) {
8612 mboolset(qi
->stopped
, prio_bits
);
8614 if (cur_bits
== 0) {
8617 mboolclr(qi
->stopped
, prio_bits
);
8620 /* If there is a flow control override we will not change the external
8621 * flow control state.
8623 if (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
) {
8627 wlc_txflowcontrol_signal(wlc
, qi
, on
, prio
);
8631 wlc_txflowcontrol_override(wlc_info_t
*wlc
, wlc_txq_info_t
*qi
, bool on
,
8636 ASSERT(override
!= 0);
8637 ASSERT((override
& TXQ_STOP_FOR_PRIOFC_MASK
) == 0);
8639 prev_override
= (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
);
8641 /* Update the flow control bits and do an early return if there is
8642 * no change in the external flow control state.
8645 mboolset(qi
->stopped
, override
);
8646 /* if there was a previous override bit on, then setting this
8647 * makes no difference.
8649 if (prev_override
) {
8653 wlc_txflowcontrol_signal(wlc
, qi
, ON
, ALLPRIO
);
8655 mboolclr(qi
->stopped
, override
);
8656 /* clearing an override bit will only make a difference for
8657 * flow control if it was the only bit set. For any other
8658 * override setting, just return
8660 if (prev_override
!= override
) {
8664 if (qi
->stopped
== 0) {
8665 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8669 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
8670 if (!mboolisset(qi
->stopped
, NBITVAL(prio
)))
8671 wlc_txflowcontrol_signal(wlc
, qi
, OFF
,
8678 static void wlc_txflowcontrol_reset(wlc_info_t
*wlc
)
8682 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
8684 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8691 wlc_txflowcontrol_signal(wlc_info_t
*wlc
, wlc_txq_info_t
*qi
, bool on
,
8696 for (wlcif
= wlc
->wlcif_list
; wlcif
!= NULL
; wlcif
= wlcif
->next
) {
8697 if (wlcif
->qi
== qi
&& wlcif
->flags
& WLC_IF_LINKED
)
8698 wl_txflowcontrol(wlc
->wl
, wlcif
->wlif
, on
, prio
);
8702 static wlc_txq_info_t
*wlc_txq_alloc(wlc_info_t
*wlc
, osl_t
*osh
)
8704 wlc_txq_info_t
*qi
, *p
;
8706 qi
= (wlc_txq_info_t
*) wlc_calloc(osh
, wlc
->pub
->unit
,
8707 sizeof(wlc_txq_info_t
));
8712 /* Have enough room for control packets along with HI watermark */
8713 /* Also, add room to txq for total psq packets if all the SCBs leave PS mode */
8714 /* The watermark for flowcontrol to OS packets will remain the same */
8715 pktq_init(&qi
->q
, WLC_PREC_COUNT
,
8716 (2 * wlc
->pub
->tunables
->datahiwat
) + PKTQ_LEN_DEFAULT
+
8717 wlc
->pub
->psq_pkts_total
);
8719 /* add this queue to the the global list */
8722 wlc
->tx_queues
= qi
;
8724 while (p
->next
!= NULL
)
8732 static void wlc_txq_free(wlc_info_t
*wlc
, osl_t
*osh
, wlc_txq_info_t
*qi
)
8739 /* remove the queue from the linked list */
8742 wlc
->tx_queues
= p
->next
;
8744 while (p
!= NULL
&& p
->next
!= qi
)
8746 ASSERT(p
->next
== qi
);
8748 p
->next
= p
->next
->next
;
8751 osl_mfree(osh
, qi
, sizeof(wlc_txq_info_t
));