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.
16 #include <linux/kernel.h>
17 #include <linux/ctype.h>
18 #include <linux/etherdevice.h>
26 #include <bcmendian.h>
38 #include <wlc_bsscfg.h>
39 #include <wlc_channel.h>
40 #include <wlc_event.h>
41 #include <wlc_mac80211.h>
44 #include <wlc_phy_hal.h>
45 #include <wlc_phy_shim.h>
46 #include <wlc_antsel.h>
48 #include <wlc_ampdu.h>
49 #include <wlc_event.h>
50 #include <wl_export.h>
51 #include "d11ucode_ext.h"
52 #include <wlc_alloc.h>
53 #include <net/mac80211.h>
60 #define RSN_CAP_4_REPLAY_CNTRS 2
61 #define RSN_CAP_16_REPLAY_CNTRS 3
63 #define WPA_CAP_4_REPLAY_CNTRS RSN_CAP_4_REPLAY_CNTRS
64 #define WPA_CAP_16_REPLAY_CNTRS RSN_CAP_16_REPLAY_CNTRS
67 * buffer length needed for wlc_format_ssid
68 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
70 #define SSID_FMT_BUF_LEN ((4 * IEEE80211_MAX_SSID_LEN) + 1)
72 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
73 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
75 #ifndef WLC_MPC_MAX_DELAYCNT
76 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
78 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
79 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
81 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
82 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
84 /* Scale down delays to accommodate QT slow speed */
85 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
86 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
88 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
91 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
92 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
93 * this low resolution driver tick can be used for maintenance tasks such as phy
94 * calibration and scb update
97 /* watchdog trigger mode: OSL timer or TBTT */
98 #define WLC_WATCHDOG_TBTT(wlc) \
99 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
101 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
102 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
104 #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
105 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
115 /* Find basic rate for a given rate */
116 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
117 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
118 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
120 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
122 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
124 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
126 #define SCAN_IN_PROGRESS(x) 0
128 #define EPI_VERSION_NUM 0x054b0b00
131 /* pointer to most recently allocated wl/wlc */
132 static struct wlc_info
*wlc_info_dbg
= (struct wlc_info
*) (NULL
);
137 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
138 * table and by the wlc_doiovar() function. No ordering is imposed:
139 * the table is keyed by name, and the function uses a switch.
144 IOV_BCN_LI_BCN
, /* Beacon listen interval in # of beacons */
145 IOV_LAST
/* In case of a need to check max ID number */
148 const bcm_iovar_t wlc_iovars
[] = {
149 {"mpc", IOV_MPC
, (IOVF_OPEN_ALLOW
), IOVT_BOOL
, 0},
150 {"qtxpower", IOV_QTXPOWER
, (IOVF_WHL
| IOVF_OPEN_ALLOW
), IOVT_UINT32
,
152 {"bcn_li_bcn", IOV_BCN_LI_BCN
, 0, IOVT_UINT8
, 0},
156 const u8 prio2fifo
[NUMPRIO
] = {
157 TX_AC_BE_FIFO
, /* 0 BE AC_BE Best Effort */
158 TX_AC_BK_FIFO
, /* 1 BK AC_BK Background */
159 TX_AC_BK_FIFO
, /* 2 -- AC_BK Background */
160 TX_AC_BE_FIFO
, /* 3 EE AC_BE Best Effort */
161 TX_AC_VI_FIFO
, /* 4 CL AC_VI Video */
162 TX_AC_VI_FIFO
, /* 5 VI AC_VI Video */
163 TX_AC_VO_FIFO
, /* 6 VO AC_VO Voice */
164 TX_AC_VO_FIFO
/* 7 NC AC_VO Voice */
167 /* precedences numbers for wlc queues. These are twice as may levels as
169 * Odd numbers are used for HI priority traffic at same precedence levels
170 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
172 #define _WLC_PREC_NONE 0 /* None = - */
173 #define _WLC_PREC_BK 2 /* BK - Background */
174 #define _WLC_PREC_BE 4 /* BE - Best-effort */
175 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
176 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
177 #define _WLC_PREC_VI 10 /* Vi - Video */
178 #define _WLC_PREC_VO 12 /* Vo - Voice */
179 #define _WLC_PREC_NC 14 /* NC - Network Control */
181 /* 802.1D Priority to precedence queue mapping */
182 const u8 wlc_prio2prec_map
[] = {
183 _WLC_PREC_BE
, /* 0 BE - Best-effort */
184 _WLC_PREC_BK
, /* 1 BK - Background */
185 _WLC_PREC_NONE
, /* 2 None = - */
186 _WLC_PREC_EE
, /* 3 EE - Excellent-effort */
187 _WLC_PREC_CL
, /* 4 CL - Controlled Load */
188 _WLC_PREC_VI
, /* 5 Vi - Video */
189 _WLC_PREC_VO
, /* 6 Vo - Voice */
190 _WLC_PREC_NC
, /* 7 NC - Network Control */
193 /* Sanity check for tx_prec_map and fifo synchup
194 * Either there are some packets pending for the fifo, else if fifo is empty then
195 * all the corresponding precmap bits should be set
197 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
198 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
199 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
200 (wlc)->fifo2prec_map[(fifo)]))
202 /* TX FIFO number to WME/802.1E Access Category */
203 const u8 wme_fifo2ac
[] = { AC_BK
, AC_BE
, AC_VI
, AC_VO
, AC_BE
, AC_BE
};
205 /* WME/802.1E Access Category to TX FIFO number */
206 static const u8 wme_ac2fifo
[] = { 1, 0, 2, 3 };
208 static bool in_send_q
= false;
210 /* Shared memory location index for various AC params */
211 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
214 static const char *fifo_names
[] = {
215 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
216 const char *aci_names
[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
219 static const u8 acbitmap2maxprio
[] = {
220 PRIO_8021D_BE
, PRIO_8021D_BE
, PRIO_8021D_BK
, PRIO_8021D_BK
,
221 PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
, PRIO_8021D_VI
,
222 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
,
223 PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
, PRIO_8021D_VO
226 /* currently the best mechanism for determining SIFS is the band in use */
227 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
229 /* value for # replay counters currently supported */
230 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
232 /* local prototypes */
233 static u16 BCMFASTPATH
wlc_d11hdrs_mac80211(struct wlc_info
*wlc
,
234 struct ieee80211_hw
*hw
,
236 struct scb
*scb
, uint frag
,
237 uint nfrags
, uint queue
,
240 ratespec_t rspec_override
);
242 static void wlc_bss_default_init(struct wlc_info
*wlc
);
243 static void wlc_ucode_mac_upd(struct wlc_info
*wlc
);
244 static ratespec_t
mac80211_wlc_set_nrate(struct wlc_info
*wlc
,
245 struct wlcband
*cur_band
, u32 int_val
);
246 static void wlc_tx_prec_map_init(struct wlc_info
*wlc
);
247 static void wlc_watchdog(void *arg
);
248 static void wlc_watchdog_by_timer(void *arg
);
249 static int wlc_set_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs_arg
);
250 static int wlc_iovar_rangecheck(struct wlc_info
*wlc
, u32 val
,
251 const bcm_iovar_t
*vi
);
252 static u8
wlc_local_constraint_qdbm(struct wlc_info
*wlc
);
254 /* send and receive */
255 static wlc_txq_info_t
*wlc_txq_alloc(struct wlc_info
*wlc
,
256 struct osl_info
*osh
);
257 static void wlc_txq_free(struct wlc_info
*wlc
, struct osl_info
*osh
,
259 static void wlc_txflowcontrol_signal(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
,
261 static void wlc_txflowcontrol_reset(struct wlc_info
*wlc
);
262 static u16
wlc_compute_airtime(struct wlc_info
*wlc
, ratespec_t rspec
,
264 static void wlc_compute_cck_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
265 static void wlc_compute_ofdm_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
266 static void wlc_compute_mimo_plcp(ratespec_t rate
, uint length
, u8
*plcp
);
267 static u16
wlc_compute_frame_dur(struct wlc_info
*wlc
, ratespec_t rate
,
268 u8 preamble_type
, uint next_frag_len
);
269 static void wlc_recvctl(struct wlc_info
*wlc
, struct osl_info
*osh
,
270 d11rxhdr_t
*rxh
, struct sk_buff
*p
);
271 static uint
wlc_calc_frame_len(struct wlc_info
*wlc
, ratespec_t rate
,
272 u8 preamble_type
, uint dur
);
273 static uint
wlc_calc_ack_time(struct wlc_info
*wlc
, ratespec_t rate
,
275 static uint
wlc_calc_cts_time(struct wlc_info
*wlc
, ratespec_t rate
,
277 /* interrupt, up/down, band */
278 static void wlc_setband(struct wlc_info
*wlc
, uint bandunit
);
279 static chanspec_t
wlc_init_chanspec(struct wlc_info
*wlc
);
280 static void wlc_bandinit_ordered(struct wlc_info
*wlc
, chanspec_t chanspec
);
281 static void wlc_bsinit(struct wlc_info
*wlc
);
282 static int wlc_duty_cycle_set(struct wlc_info
*wlc
, int duty_cycle
, bool isOFDM
,
284 static void wlc_radio_hwdisable_upd(struct wlc_info
*wlc
);
285 static bool wlc_radio_monitor_start(struct wlc_info
*wlc
);
286 static void wlc_radio_timer(void *arg
);
287 static void wlc_radio_enable(struct wlc_info
*wlc
);
288 static void wlc_radio_upd(struct wlc_info
*wlc
);
290 /* scan, association, BSS */
291 static uint
wlc_calc_ba_time(struct wlc_info
*wlc
, ratespec_t rate
,
293 static void wlc_update_mimo_band_bwcap(struct wlc_info
*wlc
, u8 bwcap
);
294 static void wlc_ht_update_sgi_rx(struct wlc_info
*wlc
, int val
);
295 static void wlc_ht_update_ldpc(struct wlc_info
*wlc
, s8 val
);
296 static void wlc_war16165(struct wlc_info
*wlc
, bool tx
);
298 static void wlc_process_eventq(void *arg
);
299 static void wlc_wme_retries_write(struct wlc_info
*wlc
);
300 static bool wlc_attach_stf_ant_init(struct wlc_info
*wlc
);
301 static uint
wlc_attach_module(struct wlc_info
*wlc
);
302 static void wlc_detach_module(struct wlc_info
*wlc
);
303 static void wlc_timers_deinit(struct wlc_info
*wlc
);
304 static void wlc_down_led_upd(struct wlc_info
*wlc
);
305 static uint
wlc_down_del_timer(struct wlc_info
*wlc
);
306 static void wlc_ofdm_rateset_war(struct wlc_info
*wlc
);
307 static int _wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
308 struct wlc_if
*wlcif
);
311 void wlc_get_rcmta(struct wlc_info
*wlc
, int idx
, u8
*addr
)
313 d11regs_t
*regs
= wlc
->regs
;
315 struct osl_info
*osh
;
317 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc
), __func__
);
319 ASSERT(wlc
->pub
->corerev
> 4);
323 W_REG(osh
, ®s
->objaddr
, (OBJADDR_RCMTA_SEL
| (idx
* 2)));
324 (void)R_REG(osh
, ®s
->objaddr
);
325 v32
= R_REG(osh
, ®s
->objdata
);
327 addr
[1] = (u8
) (v32
>> 8);
328 addr
[2] = (u8
) (v32
>> 16);
329 addr
[3] = (u8
) (v32
>> 24);
330 W_REG(osh
, ®s
->objaddr
, (OBJADDR_RCMTA_SEL
| ((idx
* 2) + 1)));
331 (void)R_REG(osh
, ®s
->objaddr
);
332 v32
= R_REG(osh
, (volatile u16
*)®s
->objdata
);
334 addr
[5] = (u8
) (v32
>> 8);
336 #endif /* defined(BCMDBG) */
338 /* keep the chip awake if needed */
339 bool wlc_stay_awake(struct wlc_info
*wlc
)
344 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
346 bool wlc_ps_allowed(struct wlc_info
*wlc
)
351 /* disallow PS when one of the following global conditions meets */
352 if (!wlc
->pub
->associated
|| !wlc
->PMenabled
|| wlc
->PM_override
)
355 /* disallow PS when one of these meets when not scanning */
356 if (!wlc
->PMblocked
) {
357 if (AP_ACTIVE(wlc
) || wlc
->monitor
)
361 FOREACH_AS_STA(wlc
, idx
, cfg
) {
362 /* disallow PS when one of the following bsscfg specific conditions meets */
363 if (!cfg
->BSS
|| !WLC_PORTOPEN(cfg
))
366 if (!cfg
->dtim_programmed
)
373 void wlc_reset(struct wlc_info
*wlc
)
375 WL_TRACE("wl%d: wlc_reset\n", wlc
->pub
->unit
);
377 wlc
->check_for_unaligned_tbtt
= false;
379 /* slurp up hw mac counters before core reset */
380 if (WLC_UPDATE_STATS(wlc
)) {
383 /* reset our snapshot of macstat counters */
384 memset((char *)wlc
->core
->macstat_snapshot
, 0,
388 wlc_bmac_reset(wlc
->hw
);
389 wlc_ampdu_reset(wlc
->ampdu
);
394 void wlc_fatal_error(struct wlc_info
*wlc
)
396 WL_ERROR("wl%d: fatal error, reinitializing\n", wlc
->pub
->unit
);
400 /* Return the channel the driver should initialize during wlc_init.
401 * the channel may have to be changed from the currently configured channel
402 * if other configurations are in conflict (bandlocked, 11n mode disabled,
403 * invalid channel for current country, etc.)
405 static chanspec_t
wlc_init_chanspec(struct wlc_info
*wlc
)
407 chanspec_t chanspec
=
408 1 | WL_CHANSPEC_BW_20
| WL_CHANSPEC_CTL_SB_NONE
|
411 /* make sure the channel is on the supported band if we are band-restricted */
412 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
413 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
415 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
419 struct scb global_scb
;
421 static void wlc_init_scb(struct wlc_info
*wlc
, struct scb
*scb
)
424 scb
->flags
= SCB_WMECAP
| SCB_HTCAP
;
425 for (i
= 0; i
< NUMPRIO
; i
++)
429 void wlc_init(struct wlc_info
*wlc
)
434 wlc_bsscfg_t
*bsscfg
;
437 WL_TRACE("wl%d: wlc_init\n", wlc
->pub
->unit
);
441 /* This will happen if a big-hammer was executed. In that case, we want to go back
442 * to the channel that we were on and not new channel
444 if (wlc
->pub
->associated
)
445 chanspec
= wlc
->home_chanspec
;
447 chanspec
= wlc_init_chanspec(wlc
);
449 wlc_bmac_init(wlc
->hw
, chanspec
, mute
);
451 wlc
->seckeys
= wlc_bmac_read_shm(wlc
->hw
, M_SECRXKEYS_PTR
) * 2;
452 if (D11REV_GE(wlc
->pub
->corerev
, 15) && (wlc
->machwcap
& MCAP_TKIPMIC
))
454 wlc_bmac_read_shm(wlc
->hw
, M_TKMICKEYS_PTR
) * 2;
456 /* update beacon listen interval */
459 (u8
) (wlc_bmac_read_shm(wlc
->hw
, M_NOSLPZNATDTIM
) >> 10);
460 ASSERT(wlc
->bcn_wait_prd
> 0);
462 /* the world is new again, so is our reported rate */
463 wlc_reprate_init(wlc
);
465 /* write ethernet address to core */
466 FOREACH_BSS(wlc
, i
, bsscfg
) {
468 wlc_set_bssid(bsscfg
);
471 /* Update tsf_cfprep if associated and up */
472 if (wlc
->pub
->associated
) {
473 FOREACH_BSS(wlc
, i
, bsscfg
) {
477 /* get beacon period from bsscfg and convert to uS */
478 bi
= bsscfg
->current_bss
->beacon_period
<< 10;
479 /* update the tsf_cfprep register */
480 /* since init path would reset to default value */
481 W_REG(wlc
->osh
, ®s
->tsf_cfprep
,
482 (bi
<< CFPREP_CBI_SHIFT
));
484 /* Update maccontrol PM related bits */
485 wlc_set_ps_ctrl(wlc
);
492 wlc_key_hw_init_all(wlc
);
494 wlc_bandinit_ordered(wlc
, chanspec
);
496 wlc_init_scb(wlc
, &global_scb
);
498 /* init probe response timeout */
499 wlc_write_shm(wlc
, M_PRS_MAXTIME
, wlc
->prb_resp_timeout
);
501 /* init max burst txop (framebursting) */
502 wlc_write_shm(wlc
, M_MBURST_TXOP
,
504 _rifs
? (EDCF_AC_VO_TXOP_AP
<< 5) : MAXFRAMEBURST_TXOP
));
506 /* initialize maximum allowed duty cycle */
507 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_ofdm
, true, true);
508 wlc_duty_cycle_set(wlc
, wlc
->tx_duty_cycle_cck
, false, true);
510 /* Update some shared memory locations related to max AMPDU size allowed to received */
511 wlc_ampdu_shm_upd(wlc
->ampdu
);
513 /* band-specific inits */
516 /* Enable EDCF mode (while the MAC is suspended) */
517 if (EDCF_ENAB(wlc
->pub
)) {
518 OR_REG(wlc
->osh
, ®s
->ifs_ctl
, IFS_USEEDCF
);
519 wlc_edcf_setparams(wlc
->cfg
, false);
522 /* Init precedence maps for empty FIFOs */
523 wlc_tx_prec_map_init(wlc
);
525 /* read the ucode version if we have not yet done so */
526 if (wlc
->ucode_rev
== 0) {
528 wlc_read_shm(wlc
, M_BOM_REV_MAJOR
) << NBITS(u16
);
529 wlc
->ucode_rev
|= wlc_read_shm(wlc
, M_BOM_REV_MINOR
);
532 /* ..now really unleash hell (allow the MAC out of suspend) */
535 /* clear tx flow control */
536 wlc_txflowcontrol_reset(wlc
);
538 /* clear tx data fifo suspends */
539 wlc
->tx_suspended
= false;
541 /* enable the RF Disable Delay timer */
542 if (D11REV_GE(wlc
->pub
->corerev
, 10))
543 W_REG(wlc
->osh
, &wlc
->regs
->rfdisabledly
, RFDISABLE_DEFAULT
);
545 /* initialize mpc delay */
546 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
549 * Initialize WME parameters; if they haven't been set by some other
550 * mechanism (IOVar, etc) then read them from the hardware.
552 if (WLC_WME_RETRY_SHORT_GET(wlc
, 0) == 0) { /* Unintialized; read from HW */
556 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
557 wlc
->wme_retries
[ac
] =
558 wlc_read_shm(wlc
, M_AC_TXLMT_ADDR(ac
));
563 void wlc_mac_bcn_promisc_change(struct wlc_info
*wlc
, bool promisc
)
565 wlc
->bcnmisc_monitor
= promisc
;
566 wlc_mac_bcn_promisc(wlc
);
569 void wlc_mac_bcn_promisc(struct wlc_info
*wlc
)
571 if ((AP_ENAB(wlc
->pub
) && (N_ENAB(wlc
->pub
) || wlc
->band
->gmode
)) ||
572 wlc
->bcnmisc_ibss
|| wlc
->bcnmisc_scan
|| wlc
->bcnmisc_monitor
)
573 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, MCTL_BCNS_PROMISC
);
575 wlc_mctrl(wlc
, MCTL_BCNS_PROMISC
, 0);
578 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
579 void wlc_mac_promisc(struct wlc_info
*wlc
)
581 u32 promisc_bits
= 0;
583 /* promiscuous mode just sets MCTL_PROMISC
584 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
585 * since all BSS data traffic is directed at the AP
587 if (PROMISC_ENAB(wlc
->pub
) && !AP_ENAB(wlc
->pub
) && !wlc
->wet
)
588 promisc_bits
|= MCTL_PROMISC
;
590 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
591 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
592 * handled in wlc_mac_bcn_promisc()
594 if (MONITOR_ENAB(wlc
))
595 promisc_bits
|= MCTL_PROMISC
| MCTL_KEEPCONTROL
;
597 wlc_mctrl(wlc
, MCTL_PROMISC
| MCTL_KEEPCONTROL
, promisc_bits
);
600 /* check if hps and wake states of sw and hw are in sync */
601 bool wlc_ps_check(struct wlc_info
*wlc
)
607 if (!AP_ACTIVE(wlc
)) {
609 tmp
= R_REG(wlc
->osh
, &wlc
->regs
->maccontrol
);
611 /* If deviceremoved is detected, then don't take any action as this can be called
612 * in any context. Assume that caller will take care of the condition. This is just
615 if (tmp
== 0xffffffff) {
616 WL_ERROR("wl%d: %s: dead chip\n",
617 wlc
->pub
->unit
, __func__
);
618 return DEVICEREMOVED(wlc
);
621 hps
= PS_ALLOWED(wlc
);
623 if (hps
!= ((tmp
& MCTL_HPS
) != 0)) {
626 WL_ERROR("wl%d: hps not sync, sw %d, maccontrol 0x%x\n",
627 wlc
->pub
->unit
, hps
, tmp
);
628 FOREACH_BSS(wlc
, idx
, cfg
) {
629 if (!BSSCFG_STA(cfg
))
635 /* For a monolithic build the wake check can be exact since it looks at wake
636 * override bits. The MCTL_WAKE bit should match the 'wake' value.
638 wake
= STAY_AWAKE(wlc
) || wlc
->hw
->wake_override
;
639 wake_ok
= (wake
== ((tmp
& MCTL_WAKE
) != 0));
640 if (hps
&& !wake_ok
) {
641 WL_ERROR("wl%d: wake not sync, sw %d maccontrol 0x%x\n",
642 wlc
->pub
->unit
, wake
, tmp
);
650 /* push sw hps and wake state through hardware */
651 void wlc_set_ps_ctrl(struct wlc_info
*wlc
)
657 hps
= PS_ALLOWED(wlc
);
658 wake
= hps
? (STAY_AWAKE(wlc
)) : true;
660 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
661 wlc
->pub
->unit
, hps
, wake
);
663 v1
= R_REG(wlc
->osh
, &wlc
->regs
->maccontrol
);
670 wlc_mctrl(wlc
, MCTL_WAKE
| MCTL_HPS
, v2
);
672 awake_before
= ((v1
& MCTL_WAKE
) || ((v1
& MCTL_HPS
) == 0));
674 if (wake
&& !awake_before
)
675 wlc_bmac_wait_for_wake(wlc
->hw
);
680 * Write this BSS config's MAC address to core.
681 * Updates RXE match engine.
683 int wlc_set_mac(wlc_bsscfg_t
*cfg
)
686 struct wlc_info
*wlc
= cfg
->wlc
;
688 if (cfg
== wlc
->cfg
) {
689 /* enter the MAC addr into the RXE match registers */
690 wlc_set_addrmatch(wlc
, RCM_MAC_OFFSET
, cfg
->cur_etheraddr
);
693 wlc_ampdu_macaddr_upd(wlc
);
698 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
699 * Updates RXE match engine.
701 void wlc_set_bssid(wlc_bsscfg_t
*cfg
)
703 struct wlc_info
*wlc
= cfg
->wlc
;
705 /* if primary config, we need to update BSSID in RXE match registers */
706 if (cfg
== wlc
->cfg
) {
707 wlc_set_addrmatch(wlc
, RCM_BSSID_OFFSET
, cfg
->BSSID
);
709 #ifdef SUPPORT_HWKEYS
710 else if (BSSCFG_STA(cfg
) && cfg
->BSS
) {
711 wlc_rcmta_add_bssid(wlc
, cfg
);
717 * Suspend the the MAC and update the slot timing
718 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
720 void wlc_switch_shortslot(struct wlc_info
*wlc
, bool shortslot
)
725 ASSERT(wlc
->band
->gmode
);
727 /* use the override if it is set */
728 if (wlc
->shortslot_override
!= WLC_SHORTSLOT_AUTO
)
729 shortslot
= (wlc
->shortslot_override
== WLC_SHORTSLOT_ON
);
731 if (wlc
->shortslot
== shortslot
)
734 wlc
->shortslot
= shortslot
;
736 /* update the capability based on current shortslot mode */
737 FOREACH_BSS(wlc
, idx
, cfg
) {
738 if (!cfg
->associated
)
740 cfg
->current_bss
->capability
&=
741 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
743 cfg
->current_bss
->capability
|=
744 WLAN_CAPABILITY_SHORT_SLOT_TIME
;
747 wlc_bmac_set_shortslot(wlc
->hw
, shortslot
);
750 static u8
wlc_local_constraint_qdbm(struct wlc_info
*wlc
)
755 local
= WLC_TXPWR_MAX
;
756 if (wlc
->pub
->associated
&&
757 (wf_chspec_ctlchan(wlc
->chanspec
) ==
758 wf_chspec_ctlchan(wlc
->home_chanspec
))) {
760 /* get the local power constraint if we are on the AP's
761 * channel [802.11h, 7.3.2.13]
763 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
765 (wlc
->txpwr_local_max
-
766 wlc
->txpwr_local_constraint
) * WLC_TXPWR_DB_FACTOR
;
767 if (local_max
> 0 && local_max
< WLC_TXPWR_MAX
)
768 return (u8
) local_max
;
776 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
777 void wlc_set_home_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
779 if (wlc
->home_chanspec
!= chanspec
) {
783 wlc
->home_chanspec
= chanspec
;
785 FOREACH_BSS(wlc
, idx
, cfg
) {
786 if (!cfg
->associated
)
788 cfg
->target_bss
->chanspec
= chanspec
;
789 cfg
->current_bss
->chanspec
= chanspec
;
795 static void wlc_set_phy_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
797 /* Save our copy of the chanspec */
798 wlc
->chanspec
= chanspec
;
800 /* Set the chanspec and power limits for this locale after computing
801 * any 11h local tx power constraints.
803 wlc_channel_set_chanspec(wlc
->cmi
, chanspec
,
804 wlc_local_constraint_qdbm(wlc
));
806 if (wlc
->stf
->ss_algosel_auto
)
807 wlc_stf_ss_algo_channel_get(wlc
, &wlc
->stf
->ss_algo_channel
,
810 wlc_stf_ss_update(wlc
, wlc
->band
);
814 void wlc_set_chanspec(struct wlc_info
*wlc
, chanspec_t chanspec
)
817 bool switchband
= false;
818 chanspec_t old_chanspec
= wlc
->chanspec
;
820 if (!wlc_valid_chanspec_db(wlc
->cmi
, chanspec
)) {
821 WL_ERROR("wl%d: %s: Bad channel %d\n",
822 wlc
->pub
->unit
, __func__
, CHSPEC_CHANNEL(chanspec
));
823 ASSERT(wlc_valid_chanspec_db(wlc
->cmi
, chanspec
));
827 /* Switch bands if necessary */
828 if (NBANDS(wlc
) > 1) {
829 bandunit
= CHSPEC_WLCBANDUNIT(chanspec
);
830 if (wlc
->band
->bandunit
!= bandunit
|| wlc
->bandinit_pending
) {
832 if (wlc
->bandlocked
) {
833 WL_ERROR("wl%d: %s: chspec %d band is locked!\n",
834 wlc
->pub
->unit
, __func__
,
835 CHSPEC_CHANNEL(chanspec
));
838 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
839 * if the setband updates (wlc_bsinit) use low level calls to inspect and
840 * set state, the state inspected may be from the wrong band, or the
841 * following wlc_bmac_set_chanspec() may undo the work.
843 wlc_setband(wlc
, bandunit
);
847 ASSERT(N_ENAB(wlc
->pub
) || !CHSPEC_IS40(chanspec
));
849 /* sync up phy/radio chanspec */
850 wlc_set_phy_chanspec(wlc
, chanspec
);
852 /* init antenna selection */
853 if (CHSPEC_WLC_BW(old_chanspec
) != CHSPEC_WLC_BW(chanspec
)) {
854 if (WLANTSEL_ENAB(wlc
))
855 wlc_antsel_init(wlc
->asi
);
857 /* Fix the hardware rateset based on bw.
858 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
860 wlc_rateset_bw_mcs_filter(&wlc
->band
->hw_rateset
,
862 mimo_cap_40
? CHSPEC_WLC_BW(chanspec
)
866 /* update some mac configuration since chanspec changed */
867 wlc_ucode_mac_upd(wlc
);
871 static int wlc_get_current_txpwr(struct wlc_info
*wlc
, void *pwr
, uint len
)
873 txpwr_limits_t txpwr
;
875 tx_power_legacy_t
*old_power
= NULL
;
880 if (len
== sizeof(tx_power_legacy_t
))
881 old_power
= (tx_power_legacy_t
*) pwr
;
882 else if (len
< sizeof(tx_power_t
))
883 return BCME_BUFTOOSHORT
;
885 memset(&power
, 0, sizeof(tx_power_t
));
887 power
.chanspec
= WLC_BAND_PI_RADIO_CHANSPEC
;
888 if (wlc
->pub
->associated
)
889 power
.local_chanspec
= wlc
->home_chanspec
;
891 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
892 * public interface only implements getting and setting a single value for all of
893 * rates, so we need to fill the array ourselves.
895 wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
, &override
);
896 for (r
= 0; r
< WL_TX_POWER_RATES
; r
++) {
897 power
.user_limit
[r
] = (u8
) qdbm
;
900 power
.local_max
= wlc
->txpwr_local_max
* WLC_TXPWR_DB_FACTOR
;
901 power
.local_constraint
=
902 wlc
->txpwr_local_constraint
* WLC_TXPWR_DB_FACTOR
;
904 power
.antgain
[0] = wlc
->bandstate
[BAND_2G_INDEX
]->antgain
;
905 power
.antgain
[1] = wlc
->bandstate
[BAND_5G_INDEX
]->antgain
;
907 wlc_channel_reg_limits(wlc
->cmi
, power
.chanspec
, &txpwr
);
909 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
910 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
913 /* CCK tx power limits */
914 for (c
= 0, r
= WL_TX_POWER_CCK_FIRST
; c
< WL_TX_POWER_CCK_NUM
;
916 power
.reg_limit
[r
] = txpwr
.cck
[c
];
918 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
919 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
922 /* 20 MHz OFDM SISO tx power limits */
923 for (c
= 0, r
= WL_TX_POWER_OFDM_FIRST
; c
< WL_TX_POWER_OFDM_NUM
;
925 power
.reg_limit
[r
] = txpwr
.ofdm
[c
];
927 if (WLC_PHY_11N_CAP(wlc
->band
)) {
929 /* 20 MHz OFDM CDD tx power limits */
930 for (c
= 0, r
= WL_TX_POWER_OFDM20_CDD_FIRST
;
931 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
932 power
.reg_limit
[r
] = txpwr
.ofdm_cdd
[c
];
934 /* 40 MHz OFDM SISO tx power limits */
935 for (c
= 0, r
= WL_TX_POWER_OFDM40_SISO_FIRST
;
936 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
937 power
.reg_limit
[r
] = txpwr
.ofdm_40_siso
[c
];
939 /* 40 MHz OFDM CDD tx power limits */
940 for (c
= 0, r
= WL_TX_POWER_OFDM40_CDD_FIRST
;
941 c
< WL_TX_POWER_OFDM_NUM
; c
++, r
++)
942 power
.reg_limit
[r
] = txpwr
.ofdm_40_cdd
[c
];
944 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
945 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
948 /* 20MHz MCS0-7 SISO tx power limits */
949 for (c
= 0, r
= WL_TX_POWER_MCS20_SISO_FIRST
;
950 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
951 power
.reg_limit
[r
] = txpwr
.mcs_20_siso
[c
];
953 /* 20MHz MCS0-7 CDD tx power limits */
954 for (c
= 0, r
= WL_TX_POWER_MCS20_CDD_FIRST
;
955 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
956 power
.reg_limit
[r
] = txpwr
.mcs_20_cdd
[c
];
958 /* 20MHz MCS0-7 STBC tx power limits */
959 for (c
= 0, r
= WL_TX_POWER_MCS20_STBC_FIRST
;
960 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
961 power
.reg_limit
[r
] = txpwr
.mcs_20_stbc
[c
];
963 /* 40MHz MCS0-7 SISO tx power limits */
964 for (c
= 0, r
= WL_TX_POWER_MCS40_SISO_FIRST
;
965 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
966 power
.reg_limit
[r
] = txpwr
.mcs_40_siso
[c
];
968 /* 40MHz MCS0-7 CDD tx power limits */
969 for (c
= 0, r
= WL_TX_POWER_MCS40_CDD_FIRST
;
970 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
971 power
.reg_limit
[r
] = txpwr
.mcs_40_cdd
[c
];
973 /* 40MHz MCS0-7 STBC tx power limits */
974 for (c
= 0, r
= WL_TX_POWER_MCS40_STBC_FIRST
;
975 c
< WLC_NUM_RATES_MCS_1_STREAM
; c
++, r
++)
976 power
.reg_limit
[r
] = txpwr
.mcs_40_stbc
[c
];
978 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
979 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
982 /* 20MHz MCS8-15 SDM tx power limits */
983 for (c
= 0, r
= WL_TX_POWER_MCS20_SDM_FIRST
;
984 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
985 power
.reg_limit
[r
] = txpwr
.mcs_20_mimo
[c
];
987 /* 40MHz MCS8-15 SDM tx power limits */
988 for (c
= 0, r
= WL_TX_POWER_MCS40_SDM_FIRST
;
989 c
< WLC_NUM_RATES_MCS_2_STREAM
; c
++, r
++)
990 power
.reg_limit
[r
] = txpwr
.mcs_40_mimo
[c
];
993 power
.reg_limit
[WL_TX_POWER_MCS_32
] = txpwr
.mcs32
;
996 wlc_phy_txpower_get_current(wlc
->band
->pi
, &power
,
997 CHSPEC_CHANNEL(power
.chanspec
));
999 /* copy the tx_power_t struct to the return buffer,
1000 * or convert to a tx_power_legacy_t struct
1003 bcopy(&power
, pwr
, sizeof(tx_power_t
));
1005 int band_idx
= CHSPEC_IS2G(power
.chanspec
) ? 0 : 1;
1007 memset(old_power
, 0, sizeof(tx_power_legacy_t
));
1009 old_power
->txpwr_local_max
= power
.local_max
;
1010 old_power
->txpwr_local_constraint
= power
.local_constraint
;
1011 if (CHSPEC_IS2G(power
.chanspec
)) {
1012 old_power
->txpwr_chan_reg_max
= txpwr
.cck
[0];
1013 old_power
->txpwr_est_Pout
[band_idx
] =
1015 old_power
->txpwr_est_Pout_gofdm
= power
.est_Pout
[0];
1017 old_power
->txpwr_chan_reg_max
= txpwr
.ofdm
[0];
1018 old_power
->txpwr_est_Pout
[band_idx
] = power
.est_Pout
[0];
1020 old_power
->txpwr_antgain
[0] = power
.antgain
[0];
1021 old_power
->txpwr_antgain
[1] = power
.antgain
[1];
1023 for (r
= 0; r
< NUM_PWRCTRL_RATES
; r
++) {
1024 old_power
->txpwr_band_max
[r
] = power
.user_limit
[r
];
1025 old_power
->txpwr_limit
[r
] = power
.reg_limit
[r
];
1026 old_power
->txpwr_target
[band_idx
][r
] = power
.target
[r
];
1027 if (CHSPEC_IS2G(power
.chanspec
))
1028 old_power
->txpwr_bphy_cck_max
[r
] =
1029 power
.board_limit
[r
];
1031 old_power
->txpwr_aphy_max
[r
] =
1032 power
.board_limit
[r
];
1038 #endif /* defined(BCMDBG) */
1040 static u32
wlc_watchdog_backup_bi(struct wlc_info
*wlc
)
1043 bi
= 2 * wlc
->cfg
->current_bss
->dtim_period
*
1044 wlc
->cfg
->current_bss
->beacon_period
;
1045 if (wlc
->bcn_li_dtim
)
1046 bi
*= wlc
->bcn_li_dtim
;
1047 else if (wlc
->bcn_li_bcn
)
1048 /* recalculate bi based on bcn_li_bcn */
1049 bi
= 2 * wlc
->bcn_li_bcn
* wlc
->cfg
->current_bss
->beacon_period
;
1051 if (bi
< 2 * TIMER_INTERVAL_WATCHDOG
)
1052 bi
= 2 * TIMER_INTERVAL_WATCHDOG
;
1056 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1057 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise.
1059 void wlc_watchdog_upd(struct wlc_info
*wlc
, bool tbtt
)
1061 /* make sure changing watchdog driver is allowed */
1062 if (!wlc
->pub
->up
|| !wlc
->pub
->align_wd_tbtt
)
1064 if (!tbtt
&& wlc
->WDarmed
) {
1065 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1066 wlc
->WDarmed
= false;
1069 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1070 if (tbtt
&& wlc
->WDarmed
) {
1071 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
1072 wlc
->WDarmed
= false;
1073 wlc
->WDlast
= OSL_SYSUPTIME();
1075 /* arm watchdog timer and drive the watchdog there */
1076 else if (!tbtt
&& !wlc
->WDarmed
) {
1077 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
1079 wlc
->WDarmed
= true;
1081 if (tbtt
&& !wlc
->WDarmed
) {
1082 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, wlc_watchdog_backup_bi(wlc
),
1084 wlc
->WDarmed
= true;
1088 ratespec_t
wlc_lowest_basic_rspec(struct wlc_info
*wlc
, wlc_rateset_t
*rs
)
1090 ratespec_t lowest_basic_rspec
;
1093 /* Use the lowest basic rate */
1094 lowest_basic_rspec
= rs
->rates
[0] & RATE_MASK
;
1095 for (i
= 0; i
< rs
->count
; i
++) {
1096 if (rs
->rates
[i
] & WLC_RATE_FLAG
) {
1097 lowest_basic_rspec
= rs
->rates
[i
] & RATE_MASK
;
1102 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1103 if (IS_OFDM(lowest_basic_rspec
)) {
1104 lowest_basic_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
1108 return lowest_basic_rspec
;
1111 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1112 * setting as per this table:
1113 * ratespec CCK ant = wlc->stf->txant
1116 void wlc_beacon_phytxctl_txant_upd(struct wlc_info
*wlc
, ratespec_t bcn_rspec
)
1119 u16 phytxant
= wlc
->stf
->phytxant
;
1120 u16 mask
= PHY_TXC_ANT_MASK
;
1122 /* for non-siso rates or default setting, use the available chains */
1123 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1124 phytxant
= wlc_stf_phytxchain_sel(wlc
, bcn_rspec
);
1127 phyctl
= wlc_read_shm(wlc
, M_BCN_PCTLWD
);
1128 phyctl
= (phyctl
& ~mask
) | phytxant
;
1129 wlc_write_shm(wlc
, M_BCN_PCTLWD
, phyctl
);
1132 /* centralized protection config change function to simplify debugging, no consistency checking
1133 * this should be called only on changes to avoid overhead in periodic function
1135 void wlc_protection_upd(struct wlc_info
*wlc
, uint idx
, int val
)
1137 WL_TRACE("wlc_protection_upd: idx %d, val %d\n", idx
, val
);
1140 case WLC_PROT_G_SPEC
:
1141 wlc
->protection
->_g
= (bool) val
;
1143 case WLC_PROT_G_OVR
:
1144 wlc
->protection
->g_override
= (s8
) val
;
1146 case WLC_PROT_G_USER
:
1147 wlc
->protection
->gmode_user
= (u8
) val
;
1149 case WLC_PROT_OVERLAP
:
1150 wlc
->protection
->overlap
= (s8
) val
;
1152 case WLC_PROT_N_USER
:
1153 wlc
->protection
->nmode_user
= (s8
) val
;
1155 case WLC_PROT_N_CFG
:
1156 wlc
->protection
->n_cfg
= (s8
) val
;
1158 case WLC_PROT_N_CFG_OVR
:
1159 wlc
->protection
->n_cfg_override
= (s8
) val
;
1161 case WLC_PROT_N_NONGF
:
1162 wlc
->protection
->nongf
= (bool) val
;
1164 case WLC_PROT_N_NONGF_OVR
:
1165 wlc
->protection
->nongf_override
= (s8
) val
;
1167 case WLC_PROT_N_PAM_OVR
:
1168 wlc
->protection
->n_pam_override
= (s8
) val
;
1170 case WLC_PROT_N_OBSS
:
1171 wlc
->protection
->n_obss
= (bool) val
;
1181 static void wlc_ht_update_sgi_rx(struct wlc_info
*wlc
, int val
)
1183 wlc
->ht_cap
.cap_info
&= ~(IEEE80211_HT_CAP_SGI_20
|
1184 IEEE80211_HT_CAP_SGI_40
);
1185 wlc
->ht_cap
.cap_info
|= (val
& WLC_N_SGI_20
) ?
1186 IEEE80211_HT_CAP_SGI_20
: 0;
1187 wlc
->ht_cap
.cap_info
|= (val
& WLC_N_SGI_40
) ?
1188 IEEE80211_HT_CAP_SGI_40
: 0;
1191 wlc_update_beacon(wlc
);
1192 wlc_update_probe_resp(wlc
, true);
1196 static void wlc_ht_update_ldpc(struct wlc_info
*wlc
, s8 val
)
1198 wlc
->stf
->ldpc
= val
;
1200 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_LDPC_CODING
;
1201 if (wlc
->stf
->ldpc
!= OFF
)
1202 wlc
->ht_cap
.cap_info
|= IEEE80211_HT_CAP_LDPC_CODING
;
1205 wlc_update_beacon(wlc
);
1206 wlc_update_probe_resp(wlc
, true);
1207 wlc_phy_ldpc_override_set(wlc
->band
->pi
, (val
? true : false));
1212 * ucode, hwmac update
1213 * Channel dependent updates for ucode and hw
1215 static void wlc_ucode_mac_upd(struct wlc_info
*wlc
)
1217 /* enable or disable any active IBSSs depending on whether or not
1218 * we are on the home channel
1220 if (wlc
->home_chanspec
== WLC_BAND_PI_RADIO_CHANSPEC
) {
1221 if (wlc
->pub
->associated
) {
1222 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1223 * I think that the ucode inits set up the bcn templates and shm values
1224 * with a bogus beacon. This should not be done in the inits. If ucode needs
1225 * to set up a beacon for testing, the test routines should write it down,
1226 * not expect the inits to populate a bogus beacon.
1228 if (WLC_PHY_11N_CAP(wlc
->band
)) {
1229 wlc_write_shm(wlc
, M_BCN_TXTSF_OFFSET
,
1230 wlc
->band
->bcntsfoff
);
1234 /* disable an active IBSS if we are not on the home channel */
1237 /* update the various promisc bits */
1238 wlc_mac_bcn_promisc(wlc
);
1239 wlc_mac_promisc(wlc
);
1242 static void wlc_bandinit_ordered(struct wlc_info
*wlc
, chanspec_t chanspec
)
1244 wlc_rateset_t default_rateset
;
1246 uint i
, band_order
[2];
1248 WL_TRACE("wl%d: wlc_bandinit_ordered\n", wlc
->pub
->unit
);
1250 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1251 * figure out the right band to park on
1253 if (wlc
->bandlocked
|| NBANDS(wlc
) == 1) {
1254 ASSERT(CHSPEC_WLCBANDUNIT(chanspec
) == wlc
->band
->bandunit
);
1256 parkband
= wlc
->band
->bandunit
; /* updated in wlc_bandlock() */
1257 band_order
[0] = band_order
[1] = parkband
;
1259 /* park on the band of the specified chanspec */
1260 parkband
= CHSPEC_WLCBANDUNIT(chanspec
);
1262 /* order so that parkband initialize last */
1263 band_order
[0] = parkband
^ 1;
1264 band_order
[1] = parkband
;
1267 /* make each band operational, software state init */
1268 for (i
= 0; i
< NBANDS(wlc
); i
++) {
1269 uint j
= band_order
[i
];
1271 wlc
->band
= wlc
->bandstate
[j
];
1273 wlc_default_rateset(wlc
, &default_rateset
);
1275 /* fill in hw_rate */
1276 wlc_rateset_filter(&default_rateset
, &wlc
->band
->hw_rateset
,
1277 false, WLC_RATES_CCK_OFDM
, RATE_MASK
,
1278 (bool) N_ENAB(wlc
->pub
));
1280 /* init basic rate lookup */
1281 wlc_rate_lookup_init(wlc
, &default_rateset
);
1284 /* sync up phy/radio chanspec */
1285 wlc_set_phy_chanspec(wlc
, chanspec
);
1288 /* band-specific init */
1289 static void WLBANDINITFN(wlc_bsinit
) (struct wlc_info
*wlc
)
1291 WL_TRACE("wl%d: wlc_bsinit: bandunit %d\n",
1292 wlc
->pub
->unit
, wlc
->band
->bandunit
);
1294 /* write ucode ACK/CTS rate table */
1295 wlc_set_ratetable(wlc
);
1297 /* update some band specific mac configuration */
1298 wlc_ucode_mac_upd(wlc
);
1300 /* init antenna selection */
1301 if (WLANTSEL_ENAB(wlc
))
1302 wlc_antsel_init(wlc
->asi
);
1306 /* switch to and initialize new band */
1307 static void WLBANDINITFN(wlc_setband
) (struct wlc_info
*wlc
, uint bandunit
)
1312 ASSERT(NBANDS(wlc
) > 1);
1313 ASSERT(!wlc
->bandlocked
);
1314 ASSERT(bandunit
!= wlc
->band
->bandunit
|| wlc
->bandinit_pending
);
1316 wlc
->band
= wlc
->bandstate
[bandunit
];
1321 /* wait for at least one beacon before entering sleeping state */
1322 wlc
->PMawakebcn
= true;
1323 FOREACH_AS_STA(wlc
, idx
, cfg
)
1324 cfg
->PMawakebcn
= true;
1325 wlc_set_ps_ctrl(wlc
);
1327 /* band-specific initializations */
1331 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1332 void wlc_wme_initparams_sta(struct wlc_info
*wlc
, wme_param_ie_t
*pe
)
1334 static const wme_param_ie_t stadef
= {
1337 WME_SUBTYPE_PARAM_IE
,
1342 {EDCF_AC_BE_ACI_STA
, EDCF_AC_BE_ECW_STA
,
1343 HTOL16(EDCF_AC_BE_TXOP_STA
)},
1344 {EDCF_AC_BK_ACI_STA
, EDCF_AC_BK_ECW_STA
,
1345 HTOL16(EDCF_AC_BK_TXOP_STA
)},
1346 {EDCF_AC_VI_ACI_STA
, EDCF_AC_VI_ECW_STA
,
1347 HTOL16(EDCF_AC_VI_TXOP_STA
)},
1348 {EDCF_AC_VO_ACI_STA
, EDCF_AC_VO_ECW_STA
,
1349 HTOL16(EDCF_AC_VO_TXOP_STA
)}
1353 ASSERT(sizeof(*pe
) == WME_PARAM_IE_LEN
);
1354 memcpy(pe
, &stadef
, sizeof(*pe
));
1357 void wlc_wme_setparams(struct wlc_info
*wlc
, u16 aci
, void *arg
, bool suspend
)
1360 shm_acparams_t acp_shm
;
1362 struct ieee80211_tx_queue_params
*params
= arg
;
1366 /* Only apply params if the core is out of reset and has clocks */
1368 WL_ERROR("wl%d: %s : no-clock\n", wlc
->pub
->unit
, __func__
);
1373 * AP uses AC params from wme_param_ie_ap.
1374 * AP advertises AC params from wme_param_ie.
1375 * STA uses AC params from wme_param_ie.
1378 wlc
->wme_admctl
= 0;
1381 memset((char *)&acp_shm
, 0, sizeof(shm_acparams_t
));
1382 /* find out which ac this set of params applies to */
1383 ASSERT(aci
< AC_COUNT
);
1384 /* set the admission control policy for this AC */
1385 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1387 /* fill in shm ac params struct */
1388 acp_shm
.txop
= ltoh16(params
->txop
);
1389 /* convert from units of 32us to us for ucode */
1390 wlc
->edcf_txop
[aci
& 0x3] = acp_shm
.txop
=
1391 EDCF_TXOP2USEC(acp_shm
.txop
);
1392 acp_shm
.aifs
= (params
->aifs
& EDCF_AIFSN_MASK
);
1394 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1395 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1398 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1399 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1400 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1401 wlc
->pub
->unit
, acp_shm
.aifs
);
1405 acp_shm
.cwmin
= params
->cw_min
;
1406 acp_shm
.cwmax
= params
->cw_max
;
1407 acp_shm
.cwcur
= acp_shm
.cwmin
;
1409 R_REG(wlc
->osh
, &wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1410 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1411 /* Indicate the new params to the ucode */
1412 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1413 wme_shmemacindex(aci
) *
1415 M_EDCF_STATUS_OFF
));
1416 acp_shm
.status
|= WME_STATUS_NEWAC
;
1418 /* Fill in shm acparam table */
1419 shm_entry
= (u16
*) &acp_shm
;
1420 for (i
= 0; i
< (int)sizeof(shm_acparams_t
); i
+= 2)
1423 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ i
,
1429 wlc_suspend_mac_and_wait(wlc
);
1432 wlc_enable_mac(wlc
);
1436 void wlc_edcf_setparams(wlc_bsscfg_t
*cfg
, bool suspend
)
1438 struct wlc_info
*wlc
= cfg
->wlc
;
1440 edcf_acparam_t
*edcf_acp
;
1441 shm_acparams_t acp_shm
;
1447 /* Only apply params if the core is out of reset and has clocks */
1452 * AP uses AC params from wme_param_ie_ap.
1453 * AP advertises AC params from wme_param_ie.
1454 * STA uses AC params from wme_param_ie.
1457 edcf_acp
= (edcf_acparam_t
*) &wlc
->wme_param_ie
.acparam
[0];
1459 wlc
->wme_admctl
= 0;
1461 for (i
= 0; i
< AC_COUNT
; i
++, edcf_acp
++) {
1462 memset((char *)&acp_shm
, 0, sizeof(shm_acparams_t
));
1463 /* find out which ac this set of params applies to */
1464 aci
= (edcf_acp
->ACI
& EDCF_ACI_MASK
) >> EDCF_ACI_SHIFT
;
1465 ASSERT(aci
< AC_COUNT
);
1466 /* set the admission control policy for this AC */
1467 if (edcf_acp
->ACI
& EDCF_ACM_MASK
) {
1468 wlc
->wme_admctl
|= 1 << aci
;
1471 /* fill in shm ac params struct */
1472 acp_shm
.txop
= ltoh16(edcf_acp
->TXOP
);
1473 /* convert from units of 32us to us for ucode */
1474 wlc
->edcf_txop
[aci
] = acp_shm
.txop
=
1475 EDCF_TXOP2USEC(acp_shm
.txop
);
1476 acp_shm
.aifs
= (edcf_acp
->ACI
& EDCF_AIFSN_MASK
);
1478 if (aci
== AC_VI
&& acp_shm
.txop
== 0
1479 && acp_shm
.aifs
< EDCF_AIFSN_MAX
)
1482 if (acp_shm
.aifs
< EDCF_AIFSN_MIN
1483 || acp_shm
.aifs
> EDCF_AIFSN_MAX
) {
1484 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1485 wlc
->pub
->unit
, acp_shm
.aifs
);
1489 /* CWmin = 2^(ECWmin) - 1 */
1490 acp_shm
.cwmin
= EDCF_ECW2CW(edcf_acp
->ECW
& EDCF_ECWMIN_MASK
);
1491 /* CWmax = 2^(ECWmax) - 1 */
1492 acp_shm
.cwmax
= EDCF_ECW2CW((edcf_acp
->ECW
& EDCF_ECWMAX_MASK
)
1493 >> EDCF_ECWMAX_SHIFT
);
1494 acp_shm
.cwcur
= acp_shm
.cwmin
;
1496 R_REG(wlc
->osh
, &wlc
->regs
->tsf_random
) & acp_shm
.cwcur
;
1497 acp_shm
.reggap
= acp_shm
.bslots
+ acp_shm
.aifs
;
1498 /* Indicate the new params to the ucode */
1499 acp_shm
.status
= wlc_read_shm(wlc
, (M_EDCF_QINFO
+
1500 wme_shmemacindex(aci
) *
1502 M_EDCF_STATUS_OFF
));
1503 acp_shm
.status
|= WME_STATUS_NEWAC
;
1505 /* Fill in shm acparam table */
1506 shm_entry
= (u16
*) &acp_shm
;
1507 for (j
= 0; j
< (int)sizeof(shm_acparams_t
); j
+= 2)
1510 wme_shmemacindex(aci
) * M_EDCF_QLEN
+ j
,
1515 wlc_suspend_mac_and_wait(wlc
);
1517 if (AP_ENAB(wlc
->pub
) && WME_ENAB(wlc
->pub
)) {
1518 wlc_update_beacon(wlc
);
1519 wlc_update_probe_resp(wlc
, false);
1523 wlc_enable_mac(wlc
);
1527 bool wlc_timers_init(struct wlc_info
*wlc
, int unit
)
1529 wlc
->wdtimer
= wl_init_timer(wlc
->wl
, wlc_watchdog_by_timer
,
1531 if (!wlc
->wdtimer
) {
1532 WL_ERROR("wl%d: wl_init_timer for wdtimer failed\n", unit
);
1536 wlc
->radio_timer
= wl_init_timer(wlc
->wl
, wlc_radio_timer
,
1538 if (!wlc
->radio_timer
) {
1539 WL_ERROR("wl%d: wl_init_timer for radio_timer failed\n", unit
);
1550 * Initialize wlc_info default values ...
1551 * may get overrides later in this function
1553 void wlc_info_init(struct wlc_info
*wlc
, int unit
)
1556 /* Assume the device is there until proven otherwise */
1557 wlc
->device_present
= true;
1559 /* set default power output percentage to 100 percent */
1560 wlc
->txpwr_percent
= 100;
1562 /* Save our copy of the chanspec */
1563 wlc
->chanspec
= CH20MHZ_CHSPEC(1);
1565 /* initialize CCK preamble mode to unassociated state */
1566 wlc
->shortpreamble
= false;
1568 wlc
->legacy_probe
= true;
1570 /* various 802.11g modes */
1571 wlc
->shortslot
= false;
1572 wlc
->shortslot_override
= WLC_SHORTSLOT_AUTO
;
1574 wlc
->barker_overlap_control
= true;
1575 wlc
->barker_preamble
= WLC_BARKER_SHORT_ALLOWED
;
1576 wlc
->txburst_limit_override
= AUTO
;
1578 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, WLC_PROTECTION_AUTO
);
1579 wlc_protection_upd(wlc
, WLC_PROT_G_SPEC
, false);
1581 wlc_protection_upd(wlc
, WLC_PROT_N_CFG_OVR
, WLC_PROTECTION_AUTO
);
1582 wlc_protection_upd(wlc
, WLC_PROT_N_CFG
, WLC_N_PROTECTION_OFF
);
1583 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF_OVR
, WLC_PROTECTION_AUTO
);
1584 wlc_protection_upd(wlc
, WLC_PROT_N_NONGF
, false);
1585 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
, AUTO
);
1587 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, WLC_PROTECTION_CTL_OVERLAP
);
1589 /* 802.11g draft 4.0 NonERP elt advertisement */
1590 wlc
->include_legacy_erp
= true;
1592 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_DEF
;
1593 wlc
->stf
->txant
= ANT_TX_DEF
;
1595 wlc
->prb_resp_timeout
= WLC_PRB_RESP_TIMEOUT
;
1597 wlc
->usr_fragthresh
= DOT11_DEFAULT_FRAG_LEN
;
1598 for (i
= 0; i
< NFIFO
; i
++)
1599 wlc
->fragthresh
[i
] = DOT11_DEFAULT_FRAG_LEN
;
1600 wlc
->RTSThresh
= DOT11_DEFAULT_RTS_LEN
;
1602 /* default rate fallback retry limits */
1603 wlc
->SFBL
= RETRY_SHORT_FB
;
1604 wlc
->LFBL
= RETRY_LONG_FB
;
1606 /* default mac retry limits */
1607 wlc
->SRL
= RETRY_SHORT_DEF
;
1608 wlc
->LRL
= RETRY_LONG_DEF
;
1611 wlc
->PM
= PM_OFF
; /* User's setting of PM mode through IOCTL */
1612 wlc
->PM_override
= false; /* Prevents from going to PM if our AP is 'ill' */
1613 wlc
->PMenabled
= false; /* Current PM state */
1614 wlc
->PMpending
= false; /* Tracks whether STA indicated PM in the last attempt */
1615 wlc
->PMblocked
= false; /* To allow blocking going into PM during RM and scans */
1617 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1618 wlc
->WME_PM_blocked
= false;
1620 /* Init wme queuing method */
1621 wlc
->wme_prec_queuing
= false;
1623 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1625 /* Are we waiting for a response to PS-Poll that we sent */
1626 wlc
->PSpoll
= false;
1629 wlc
->wme_apsd
= true;
1630 wlc
->apsd_sta_usp
= false;
1631 wlc
->apsd_trigger_timeout
= 0; /* disable the trigger timer */
1632 wlc
->apsd_trigger_ac
= AC_BITMAP_ALL
;
1634 /* Set flag to indicate that hw keys should be used when available. */
1635 wlc
->wsec_swkeys
= false;
1637 /* init the 4 static WEP default keys */
1638 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
1639 wlc
->wsec_keys
[i
] = wlc
->wsec_def_keys
[i
];
1640 wlc
->wsec_keys
[i
]->idx
= (u8
) i
;
1643 wlc
->_regulatory_domain
= false; /* 802.11d */
1645 /* WME QoS mode is Auto by default */
1646 wlc
->pub
->_wme
= AUTO
;
1648 #ifdef BCMSDIODEV_ENABLED
1649 wlc
->pub
->_priofc
= true; /* enable priority flow control for sdio dongle */
1652 wlc
->pub
->_ampdu
= AMPDU_AGG_HOST
;
1653 wlc
->pub
->bcmerror
= 0;
1654 wlc
->ibss_allowed
= true;
1655 wlc
->ibss_coalesce_allowed
= true;
1656 wlc
->pub
->_coex
= ON
;
1658 /* intialize mpc delay */
1659 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
1661 wlc
->pr80838_war
= true;
1664 static bool wlc_state_bmac_sync(struct wlc_info
*wlc
)
1666 wlc_bmac_state_t state_bmac
;
1668 if (wlc_bmac_state_get(wlc
->hw
, &state_bmac
) != 0)
1671 wlc
->machwcap
= state_bmac
.machwcap
;
1672 wlc_protection_upd(wlc
, WLC_PROT_N_PAM_OVR
,
1673 (s8
) state_bmac
.preamble_ovr
);
1678 static uint
wlc_attach_module(struct wlc_info
*wlc
)
1682 unit
= wlc
->pub
->unit
;
1684 wlc
->asi
= wlc_antsel_attach(wlc
, wlc
->osh
, wlc
->pub
, wlc
->hw
);
1685 if (wlc
->asi
== NULL
) {
1686 WL_ERROR("wl%d: wlc_attach: wlc_antsel_attach failed\n", unit
);
1691 wlc
->ampdu
= wlc_ampdu_attach(wlc
);
1692 if (wlc
->ampdu
== NULL
) {
1693 WL_ERROR("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit
);
1698 /* Initialize event queue; needed before following calls */
1700 wlc_eventq_attach(wlc
->pub
, wlc
, wlc
->wl
, wlc_process_eventq
);
1701 if (wlc
->eventq
== NULL
) {
1702 WL_ERROR("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit
);
1707 if ((wlc_stf_attach(wlc
) != 0)) {
1708 WL_ERROR("wl%d: wlc_attach: wlc_stf_attach failed\n", unit
);
1716 struct wlc_pub
*wlc_pub(void *wlc
)
1718 return ((struct wlc_info
*) wlc
)->pub
;
1721 #define CHIP_SUPPORTS_11N(wlc) 1
1724 * The common driver entry routine. Error codes should be unique
1726 void *wlc_attach(void *wl
, u16 vendor
, u16 device
, uint unit
, bool piomode
,
1727 struct osl_info
*osh
, void *regsva
, uint bustype
,
1728 void *btparam
, uint
*perr
)
1730 struct wlc_info
*wlc
;
1733 struct wlc_pub
*pub
;
1737 WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
1738 unit
, __func__
, vendor
, device
);
1740 ASSERT(WSEC_MAX_RCMTA_KEYS
<= WSEC_MAX_KEYS
);
1741 ASSERT(WSEC_MAX_DEFAULT_KEYS
== WLC_DEFAULT_KEYS
);
1743 /* some code depends on packed structures */
1744 ASSERT(sizeof(struct ethhdr
) == ETH_HLEN
);
1745 ASSERT(sizeof(d11regs_t
) == SI_CORE_SIZE
);
1746 ASSERT(sizeof(ofdm_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1747 ASSERT(sizeof(cck_phy_hdr_t
) == D11_PHY_HDR_LEN
);
1748 ASSERT(sizeof(d11txh_t
) == D11_TXH_LEN
);
1749 ASSERT(sizeof(d11rxhdr_t
) == RXHDR_LEN
);
1750 ASSERT(sizeof(struct ieee80211_hdr
) == DOT11_A4_HDR_LEN
);
1751 ASSERT(sizeof(struct ieee80211_rts
) == DOT11_RTS_LEN
);
1752 ASSERT(sizeof(tx_status_t
) == TXSTATUS_LEN
);
1753 ASSERT(sizeof(struct ieee80211_ht_cap
) == HT_CAP_IE_LEN
);
1755 ASSERT(offsetof(wl_scan_params_t
, channel_list
) ==
1756 WL_SCAN_PARAMS_FIXED_SIZE
);
1758 ASSERT(IS_ALIGNED(offsetof(wsec_key_t
, data
), sizeof(u32
)));
1759 ASSERT(ISPOWEROF2(MA_WINDOW_SZ
));
1761 ASSERT(sizeof(wlc_d11rxhdr_t
) <= WL_HWRXOFF
);
1764 * Number of replay counters value used in WPA IE must match # rxivs
1765 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1766 * 'RSN Information Element' figure 8 for this mapping.
1768 ASSERT((WPA_CAP_16_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1769 && 16 == WLC_NUMRXIVS
)
1770 || (WPA_CAP_4_REPLAY_CNTRS
== WLC_REPLAY_CNTRS_VALUE
1771 && 4 == WLC_NUMRXIVS
));
1773 /* allocate struct wlc_info state and its substructures */
1774 wlc
= (struct wlc_info
*) wlc_attach_malloc(osh
, unit
, &err
, device
);
1784 wlc
->band
= wlc
->bandstate
[0];
1785 wlc
->core
= wlc
->corestate
;
1789 wlc
->btparam
= btparam
;
1790 pub
->_piomode
= piomode
;
1791 wlc
->bandinit_pending
= false;
1792 /* By default restrict TKIP associations from 11n STA's */
1793 wlc
->ht_wsec_restriction
= WLC_HT_TKIP_RESTRICT
;
1795 /* populate struct wlc_info with default values */
1796 wlc_info_init(wlc
, unit
);
1798 /* update sta/ap related parameters */
1801 /* 11n_disable nvram */
1802 n_disabled
= getintvar(pub
->vars
, "11n_disable");
1804 /* register a module (to handle iovars) */
1805 wlc_module_register(wlc
->pub
, wlc_iovars
, "wlc_iovars", wlc
,
1806 wlc_doiovar
, NULL
, NULL
);
1808 /* low level attach steps(all hw accesses go inside, no more in rest of the attach) */
1809 err
= wlc_bmac_attach(wlc
, vendor
, device
, unit
, piomode
, osh
, regsva
,
1814 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1815 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1817 if (!wlc_state_bmac_sync(wlc
)) {
1822 pub
->phy_11ncapable
= WLC_PHY_11N_CAP(wlc
->band
);
1824 /* propagate *vars* from BMAC driver to high driver */
1825 wlc_bmac_copyfrom_vars(wlc
->hw
, &pub
->vars
, &wlc
->vars_size
);
1828 /* set maximum allowed duty cycle */
1829 wlc
->tx_duty_cycle_ofdm
=
1830 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_ofdm");
1831 wlc
->tx_duty_cycle_cck
=
1832 (u16
) getintvar(pub
->vars
, "tx_duty_cycle_cck");
1834 wlc_stf_phy_chain_calc(wlc
);
1836 /* txchain 1: txant 0, txchain 2: txant 1 */
1837 if (WLCISNPHY(wlc
->band
) && (wlc
->stf
->txstreams
== 1))
1838 wlc
->stf
->txant
= wlc
->stf
->hw_txchain
- 1;
1840 /* push to BMAC driver */
1841 wlc_phy_stf_chain_init(wlc
->band
->pi
, wlc
->stf
->hw_txchain
,
1842 wlc
->stf
->hw_rxchain
);
1844 /* pull up some info resulting from the low attach */
1847 for (i
= 0; i
< NFIFO
; i
++)
1848 wlc
->core
->txavail
[i
] = wlc
->hw
->txavail
[i
];
1851 wlc_bmac_hw_etheraddr(wlc
->hw
, wlc
->perm_etheraddr
);
1853 bcopy((char *)&wlc
->perm_etheraddr
, (char *)&pub
->cur_etheraddr
,
1856 for (j
= 0; j
< NBANDS(wlc
); j
++) {
1857 /* Use band 1 for single band 11a */
1858 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
1861 wlc
->band
= wlc
->bandstate
[j
];
1863 if (!wlc_attach_stf_ant_init(wlc
)) {
1868 /* default contention windows size limits */
1869 wlc
->band
->CWmin
= APHY_CWMIN
;
1870 wlc
->band
->CWmax
= PHY_CWMAX
;
1872 /* init gmode value */
1873 if (BAND_2G(wlc
->band
->bandtype
)) {
1874 wlc
->band
->gmode
= GMODE_AUTO
;
1875 wlc_protection_upd(wlc
, WLC_PROT_G_USER
,
1879 /* init _n_enab supported mode */
1880 if (WLC_PHY_11N_CAP(wlc
->band
) && CHIP_SUPPORTS_11N(wlc
)) {
1881 if (n_disabled
& WLFEATURE_DISABLE_11N
) {
1883 wlc_protection_upd(wlc
, WLC_PROT_N_USER
, OFF
);
1885 pub
->_n_enab
= SUPPORT_11N
;
1886 wlc_protection_upd(wlc
, WLC_PROT_N_USER
,
1888 SUPPORT_11N
) ? WL_11N_2x2
:
1893 /* init per-band default rateset, depend on band->gmode */
1894 wlc_default_rateset(wlc
, &wlc
->band
->defrateset
);
1896 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1897 wlc_rateset_filter(&wlc
->band
->defrateset
,
1898 &wlc
->band
->hw_rateset
, false,
1899 WLC_RATES_CCK_OFDM
, RATE_MASK
,
1900 (bool) N_ENAB(wlc
->pub
));
1903 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1904 wlc_stf_phy_txant_upd(wlc
);
1906 /* attach each modules */
1907 err
= wlc_attach_module(wlc
);
1911 if (!wlc_timers_init(wlc
, unit
)) {
1912 WL_ERROR("wl%d: %s: wlc_init_timer failed\n", unit
, __func__
);
1917 /* depend on rateset, gmode */
1918 wlc
->cmi
= wlc_channel_mgr_attach(wlc
);
1920 WL_ERROR("wl%d: %s: wlc_channel_mgr_attach failed\n",
1926 /* init default when all parameters are ready, i.e. ->rateset */
1927 wlc_bss_default_init(wlc
);
1930 * Complete the wlc default state initializations..
1933 /* allocate our initial queue */
1934 qi
= wlc_txq_alloc(wlc
, osh
);
1936 WL_ERROR("wl%d: %s: failed to malloc tx queue\n",
1941 wlc
->active_queue
= qi
;
1943 wlc
->bsscfg
[0] = wlc
->cfg
;
1945 wlc
->cfg
->wlc
= wlc
;
1946 pub
->txmaxpkts
= MAXTXPKTS
;
1948 WLCNTSET(pub
->_cnt
->version
, WL_CNT_T_VERSION
);
1949 WLCNTSET(pub
->_cnt
->length
, sizeof(wl_cnt_t
));
1951 WLCNTSET(pub
->_wme_cnt
->version
, WL_WME_CNT_VERSION
);
1952 WLCNTSET(pub
->_wme_cnt
->length
, sizeof(wl_wme_cnt_t
));
1954 wlc_wme_initparams_sta(wlc
, &wlc
->wme_param_ie
);
1956 wlc
->mimoft
= FT_HT
;
1957 wlc
->ht_cap
.cap_info
= HT_CAP
;
1958 if (HT_ENAB(wlc
->pub
))
1959 wlc
->stf
->ldpc
= AUTO
;
1961 wlc
->mimo_40txbw
= AUTO
;
1962 wlc
->ofdm_40txbw
= AUTO
;
1963 wlc
->cck_40txbw
= AUTO
;
1964 wlc_update_mimo_band_bwcap(wlc
, WLC_N_BW_20IN2G_40IN5G
);
1966 /* Enable setting the RIFS Mode bit by default in HT Info IE */
1967 wlc
->rifs_advert
= AUTO
;
1969 /* Set default values of SGI */
1970 if (WLC_SGI_CAP_PHY(wlc
)) {
1971 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
1973 } else if (WLCISSSLPNPHY(wlc
->band
)) {
1974 wlc_ht_update_sgi_rx(wlc
, (WLC_N_SGI_20
| WLC_N_SGI_40
));
1977 wlc_ht_update_sgi_rx(wlc
, 0);
1981 /* *******nvram 11n config overrides Start ********* */
1983 /* apply the sgi override from nvram conf */
1984 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_TX
)
1987 if (n_disabled
& WLFEATURE_DISABLE_11N_SGI_RX
)
1988 wlc_ht_update_sgi_rx(wlc
, 0);
1990 /* apply the stbc override from nvram conf */
1991 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_TX
) {
1992 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= OFF
;
1993 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= OFF
;
1994 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_TX_STBC
;
1996 if (n_disabled
& WLFEATURE_DISABLE_11N_STBC_RX
)
1997 wlc_stf_stbc_rx_set(wlc
, HT_CAP_RX_STBC_NO
);
1999 /* apply the GF override from nvram conf */
2000 if (n_disabled
& WLFEATURE_DISABLE_11N_GF
)
2001 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_GRN_FLD
;
2003 /* initialize radio_mpc_disable according to wlc->mpc */
2004 wlc_radio_mpc_upd(wlc
);
2006 if (WLANTSEL_ENAB(wlc
)) {
2007 if ((wlc
->pub
->sih
->chip
) == BCM43235_CHIP_ID
) {
2008 if ((getintvar(wlc
->pub
->vars
, "aa2g") == 7) ||
2009 (getintvar(wlc
->pub
->vars
, "aa5g") == 7)) {
2010 wlc_bmac_antsel_set(wlc
->hw
, 1);
2013 wlc_bmac_antsel_set(wlc
->hw
, wlc
->asi
->antsel_avail
);
2023 WL_ERROR("wl%d: %s: failed with err %d\n", unit
, __func__
, err
);
2032 static void wlc_attach_antgain_init(struct wlc_info
*wlc
)
2035 unit
= wlc
->pub
->unit
;
2037 if ((wlc
->band
->antgain
== -1) && (wlc
->pub
->sromrev
== 1)) {
2038 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2039 wlc
->band
->antgain
= 8;
2040 } else if (wlc
->band
->antgain
== -1) {
2041 WL_ERROR("wl%d: %s: Invalid antennas available in srom, using 2dB\n",
2043 wlc
->band
->antgain
= 8;
2046 /* Older sroms specified gain in whole dbm only. In order
2047 * be able to specify qdbm granularity and remain backward compatible
2048 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2049 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2050 * -32 - 31. Examples: 0x1 = 1 db,
2051 * 0xc1 = 1.75 db (1 + 3 quarters),
2052 * 0x3f = -1 (-1 + 0 quarters),
2053 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2054 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2056 gain
= wlc
->band
->antgain
& 0x3f;
2057 gain
<<= 2; /* Sign extend */
2059 fract
= (wlc
->band
->antgain
& 0xc0) >> 6;
2060 wlc
->band
->antgain
= 4 * gain
+ fract
;
2064 static bool wlc_attach_stf_ant_init(struct wlc_info
*wlc
)
2071 unit
= wlc
->pub
->unit
;
2072 vars
= wlc
->pub
->vars
;
2073 bandtype
= wlc
->band
->bandtype
;
2075 /* get antennas available */
2076 aa
= (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "aa5g" : "aa2g"));
2078 aa
= (s8
) getintvar(vars
,
2079 (BAND_5G(bandtype
) ? "aa1" : "aa0"));
2080 if ((aa
< 1) || (aa
> 15)) {
2081 WL_ERROR("wl%d: %s: Invalid antennas available in srom (0x%x), using 3\n",
2082 unit
, __func__
, aa
);
2086 /* reset the defaults if we have a single antenna */
2088 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_0
;
2089 wlc
->stf
->txant
= ANT_TX_FORCE_0
;
2090 } else if (aa
== 2) {
2091 wlc
->stf
->ant_rx_ovr
= ANT_RX_DIV_FORCE_1
;
2092 wlc
->stf
->txant
= ANT_TX_FORCE_1
;
2096 /* Compute Antenna Gain */
2097 wlc
->band
->antgain
=
2098 (s8
) getintvar(vars
, (BAND_5G(bandtype
) ? "ag1" : "ag0"));
2099 wlc_attach_antgain_init(wlc
);
2105 static void wlc_timers_deinit(struct wlc_info
*wlc
)
2107 /* free timer state */
2109 wl_free_timer(wlc
->wl
, wlc
->wdtimer
);
2110 wlc
->wdtimer
= NULL
;
2112 if (wlc
->radio_timer
) {
2113 wl_free_timer(wlc
->wl
, wlc
->radio_timer
);
2114 wlc
->radio_timer
= NULL
;
2118 static void wlc_detach_module(struct wlc_info
*wlc
)
2121 wlc_antsel_detach(wlc
->asi
);
2126 wlc_ampdu_detach(wlc
->ampdu
);
2130 wlc_stf_detach(wlc
);
2134 * Return a count of the number of driver callbacks still pending.
2136 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2137 * touch hardware registers since the d11core may be in reset and clock may not be available.
2138 * One exception is sb register access, which is possible if crystal is turned on
2139 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2141 uint
wlc_detach(struct wlc_info
*wlc
)
2149 WL_TRACE("wl%d: %s\n", wlc
->pub
->unit
, __func__
);
2151 ASSERT(!wlc
->pub
->up
);
2153 callbacks
+= wlc_bmac_detach(wlc
);
2155 /* delete software timers */
2156 if (!wlc_radio_monitor_stop(wlc
))
2160 wlc_eventq_detach(wlc
->eventq
);
2164 wlc_channel_mgr_detach(wlc
->cmi
);
2166 wlc_timers_deinit(wlc
);
2168 wlc_detach_module(wlc
);
2170 /* free other state */
2174 if (wlc
->country_ie_override
) {
2175 kfree(wlc
->country_ie_override
);
2176 wlc
->country_ie_override
= NULL
;
2181 /* free dumpcb list */
2182 dumpcb_t
*prev
, *ptr
;
2183 prev
= ptr
= wlc
->dumpcb_head
;
2189 wlc
->dumpcb_head
= NULL
;
2192 /* Detach from iovar manager */
2193 wlc_module_unregister(wlc
->pub
, "wlc_iovars", wlc
);
2195 while (wlc
->tx_queues
!= NULL
) {
2196 wlc_txq_free(wlc
, wlc
->osh
, wlc
->tx_queues
);
2200 * consistency check: wlc_module_register/wlc_module_unregister calls
2201 * should match therefore nothing should be left here.
2203 for (i
= 0; i
< WLC_MAXMODULES
; i
++)
2204 ASSERT(wlc
->modulecb
[i
].name
[0] == '\0');
2206 wlc_detach_mfree(wlc
, wlc
->osh
);
2210 /* update state that depends on the current value of "ap" */
2211 void wlc_ap_upd(struct wlc_info
*wlc
)
2213 if (AP_ENAB(wlc
->pub
))
2214 wlc
->PLCPHdr_override
= WLC_PLCP_AUTO
; /* AP: short not allowed, but not enforced */
2216 wlc
->PLCPHdr_override
= WLC_PLCP_SHORT
; /* STA-BSS; short capable */
2218 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2219 wlc
->vlan_mode
= AP_ENAB(wlc
->pub
) ? OFF
: AUTO
;
2225 /* read hwdisable state and propagate to wlc flag */
2226 static void wlc_radio_hwdisable_upd(struct wlc_info
*wlc
)
2228 if (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
|| wlc
->pub
->hw_off
)
2231 if (wlc_bmac_radio_read_hwdisabled(wlc
->hw
)) {
2232 mboolset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2234 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
);
2238 /* return true if Minimum Power Consumption should be entered, false otherwise */
2239 bool wlc_is_non_delay_mpc(struct wlc_info
*wlc
)
2244 bool wlc_ismpc(struct wlc_info
*wlc
)
2246 return (wlc
->mpc_delay_off
== 0) && (wlc_is_non_delay_mpc(wlc
));
2249 void wlc_radio_mpc_upd(struct wlc_info
*wlc
)
2251 bool mpc_radio
, radio_state
;
2254 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2255 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2256 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2257 * the radio is going down.
2260 if (!wlc
->pub
->radio_disabled
)
2262 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2264 if (!wlc
->pub
->radio_disabled
)
2265 wlc_radio_monitor_stop(wlc
);
2270 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2271 * to go ON, always call radio_upd synchronously
2272 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2275 (mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
) ? OFF
:
2277 mpc_radio
= (wlc_ismpc(wlc
) == true) ? OFF
: ON
;
2279 if (radio_state
== ON
&& mpc_radio
== OFF
)
2280 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2281 else if (radio_state
== OFF
&& mpc_radio
== ON
) {
2282 mboolclr(wlc
->pub
->radio_disabled
, WL_RADIO_MPC_DISABLE
);
2284 if (wlc
->mpc_offcnt
< WLC_MPC_THRESHOLD
) {
2285 wlc
->mpc_dlycnt
= WLC_MPC_MAX_DELAYCNT
;
2287 wlc
->mpc_dlycnt
= WLC_MPC_MIN_DELAYCNT
;
2288 wlc
->mpc_dur
+= OSL_SYSUPTIME() - wlc
->mpc_laston_ts
;
2290 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2291 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2292 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2294 if ((wlc
->prev_non_delay_mpc
== false) &&
2295 (wlc_is_non_delay_mpc(wlc
) == true) && wlc
->mpc_delay_off
) {
2296 wlc
->mpc_delay_off
= wlc
->mpc_dlycnt
;
2298 wlc
->prev_non_delay_mpc
= wlc_is_non_delay_mpc(wlc
);
2302 * centralized radio disable/enable function,
2303 * invoke radio enable/disable after updating hwradio status
2305 static void wlc_radio_upd(struct wlc_info
*wlc
)
2309 /* maintain LED behavior in down state */
2310 static void wlc_down_led_upd(struct wlc_info
*wlc
)
2312 ASSERT(!wlc
->pub
->up
);
2314 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2315 /* turn on sbclk if necessary */
2316 if (!AP_ENAB(wlc
->pub
)) {
2317 wlc_pllreq(wlc
, true, WLC_PLLREQ_FLIP
);
2319 wlc_pllreq(wlc
, false, WLC_PLLREQ_FLIP
);
2323 /* update hwradio status and return it */
2324 bool wlc_check_radio_disabled(struct wlc_info
*wlc
)
2326 wlc_radio_hwdisable_upd(wlc
);
2328 return mboolisset(wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
) ? true : false;
2331 void wlc_radio_disable(struct wlc_info
*wlc
)
2333 if (!wlc
->pub
->up
) {
2334 wlc_down_led_upd(wlc
);
2338 wlc_radio_monitor_start(wlc
);
2342 static void wlc_radio_enable(struct wlc_info
*wlc
)
2347 if (DEVICEREMOVED(wlc
))
2350 if (!wlc
->down_override
) { /* imposed by wl down/out ioctl */
2355 /* periodical query hw radio button while driver is "down" */
2356 static void wlc_radio_timer(void *arg
)
2358 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2360 if (DEVICEREMOVED(wlc
)) {
2361 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
2366 /* cap mpc off count */
2367 if (wlc
->mpc_offcnt
< WLC_MPC_MAX_DELAYCNT
)
2370 /* validate all the reasons driver could be down and running this radio_timer */
2371 ASSERT(wlc
->pub
->radio_disabled
|| wlc
->down_override
);
2372 wlc_radio_hwdisable_upd(wlc
);
2376 static bool wlc_radio_monitor_start(struct wlc_info
*wlc
)
2378 /* Don't start the timer if HWRADIO feature is disabled */
2379 if (wlc
->radio_monitor
|| (wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
))
2382 wlc
->radio_monitor
= true;
2383 wlc_pllreq(wlc
, true, WLC_PLLREQ_RADIO_MON
);
2384 wl_add_timer(wlc
->wl
, wlc
->radio_timer
, TIMER_INTERVAL_RADIOCHK
, true);
2388 bool wlc_radio_monitor_stop(struct wlc_info
*wlc
)
2390 if (!wlc
->radio_monitor
)
2393 ASSERT((wlc
->pub
->wlfeatureflag
& WL_SWFL_NOHWRADIO
) !=
2396 wlc
->radio_monitor
= false;
2397 wlc_pllreq(wlc
, false, WLC_PLLREQ_RADIO_MON
);
2398 return wl_del_timer(wlc
->wl
, wlc
->radio_timer
);
2401 /* bring the driver down, but don't reset hardware */
2402 void wlc_out(struct wlc_info
*wlc
)
2404 wlc_bmac_set_noreset(wlc
->hw
, true);
2407 wlc_bmac_set_noreset(wlc
->hw
, false);
2409 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2412 /* This will make sure that when 'up' is done
2413 * after 'out' it'll restore hardware (especially gpios)
2415 wlc
->pub
->hw_up
= false;
2419 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2420 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2421 * in prec_map. Of course, ignore this rule when block_datafifo is set
2423 static bool wlc_tx_prec_map_verify(struct wlc_info
*wlc
)
2425 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2428 if (!EDCF_ENAB(wlc
->pub
)) {
2429 if (!(WLC_TX_FIFO_CHECK(wlc
, TX_DATA_FIFO
) ||
2430 WLC_TX_FIFO_CHECK(wlc
, TX_CTL_FIFO
)))
2436 return WLC_TX_FIFO_CHECK(wlc
, TX_AC_BK_FIFO
)
2437 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_BE_FIFO
)
2438 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VI_FIFO
)
2439 && WLC_TX_FIFO_CHECK(wlc
, TX_AC_VO_FIFO
);
2443 static void wlc_watchdog_by_timer(void *arg
)
2445 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2447 if (WLC_WATCHDOG_TBTT(wlc
)) {
2448 /* set to normal osl watchdog period */
2449 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
2450 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
,
2455 /* common watchdog code */
2456 static void wlc_watchdog(void *arg
)
2458 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
2462 WL_TRACE("wl%d: wlc_watchdog\n", wlc
->pub
->unit
);
2467 if (DEVICEREMOVED(wlc
)) {
2468 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
2473 /* increment second count */
2476 /* delay radio disable */
2477 if (wlc
->mpc_delay_off
) {
2478 if (--wlc
->mpc_delay_off
== 0) {
2479 mboolset(wlc
->pub
->radio_disabled
,
2480 WL_RADIO_MPC_DISABLE
);
2481 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2482 wlc
->mpc_offcnt
= 0;
2483 wlc
->mpc_laston_ts
= OSL_SYSUPTIME();
2488 wlc_radio_mpc_upd(wlc
);
2489 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2490 wlc_radio_hwdisable_upd(wlc
);
2492 /* if ismpc, driver should be in down state if up/down is allowed */
2493 if (wlc
->mpc
&& wlc_ismpc(wlc
))
2494 ASSERT(!wlc
->pub
->up
);
2495 /* if radio is disable, driver may be down, quit here */
2496 if (wlc
->pub
->radio_disabled
)
2499 wlc_bmac_watchdog(wlc
);
2501 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2502 if ((WLC_UPDATE_STATS(wlc
))
2503 && (!(wlc
->pub
->now
% SW_TIMER_MAC_STAT_UPD
)))
2506 /* Manage TKIP countermeasures timers */
2507 FOREACH_BSS(wlc
, i
, cfg
) {
2508 if (cfg
->tk_cm_dt
) {
2511 if (cfg
->tk_cm_bt
) {
2516 /* Call any registered watchdog handlers */
2517 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2518 if (wlc
->modulecb
[i
].watchdog_fn
)
2519 wlc
->modulecb
[i
].watchdog_fn(wlc
->modulecb
[i
].hdl
);
2522 if (WLCISNPHY(wlc
->band
) && !wlc
->pub
->tempsense_disable
&&
2523 ((wlc
->pub
->now
- wlc
->tempsense_lasttime
) >=
2524 WLC_TEMPSENSE_PERIOD
)) {
2525 wlc
->tempsense_lasttime
= wlc
->pub
->now
;
2526 wlc_tempsense_upd(wlc
);
2528 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2529 ASSERT(wlc_bmac_taclear(wlc
->hw
, true));
2531 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2532 ASSERT(wlc_tx_prec_map_verify(wlc
));
2534 ASSERT(wlc_ps_check(wlc
));
2537 /* make interface operational */
2538 int wlc_up(struct wlc_info
*wlc
)
2540 WL_TRACE("wl%d: %s:\n", wlc
->pub
->unit
, __func__
);
2542 /* HW is turned off so don't try to access it */
2543 if (wlc
->pub
->hw_off
|| DEVICEREMOVED(wlc
))
2544 return BCME_RADIOOFF
;
2546 if (!wlc
->pub
->hw_up
) {
2547 wlc_bmac_hw_up(wlc
->hw
);
2548 wlc
->pub
->hw_up
= true;
2551 if ((wlc
->pub
->boardflags
& BFL_FEM
)
2552 && (wlc
->pub
->sih
->chip
== BCM4313_CHIP_ID
)) {
2553 if (wlc
->pub
->boardrev
>= 0x1250
2554 && (wlc
->pub
->boardflags
& BFL_FEM_BT
)) {
2555 wlc_mhf(wlc
, MHF5
, MHF5_4313_GPIOCTRL
,
2556 MHF5_4313_GPIOCTRL
, WLC_BAND_ALL
);
2558 wlc_mhf(wlc
, MHF4
, MHF4_EXTPA_ENABLE
, MHF4_EXTPA_ENABLE
,
2564 * Need to read the hwradio status here to cover the case where the system
2565 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2566 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2567 * don't call radio_update to avoid looping wlc_up.
2569 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2571 if (!wlc
->pub
->radio_disabled
) {
2572 int status
= wlc_bmac_up_prep(wlc
->hw
);
2573 if (status
== BCME_RADIOOFF
) {
2575 (wlc
->pub
->radio_disabled
, WL_RADIO_HW_DISABLE
)) {
2577 wlc_bsscfg_t
*bsscfg
;
2578 mboolset(wlc
->pub
->radio_disabled
,
2579 WL_RADIO_HW_DISABLE
);
2581 FOREACH_BSS(wlc
, idx
, bsscfg
) {
2582 if (!BSSCFG_STA(bsscfg
)
2583 || !bsscfg
->enable
|| !bsscfg
->BSS
)
2585 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2586 wlc
->pub
->unit
, idx
);
2593 if (wlc
->pub
->radio_disabled
) {
2594 wlc_radio_monitor_start(wlc
);
2598 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2601 wlc_radio_monitor_stop(wlc
);
2603 /* Set EDCF hostflags */
2604 if (EDCF_ENAB(wlc
->pub
)) {
2605 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, MHF1_EDCF
, WLC_BAND_ALL
);
2607 wlc_mhf(wlc
, MHF1
, MHF1_EDCF
, 0, WLC_BAND_ALL
);
2610 if (WLC_WAR16165(wlc
))
2611 wlc_mhf(wlc
, MHF2
, MHF2_PCISLOWCLKWAR
, MHF2_PCISLOWCLKWAR
,
2615 wlc
->pub
->up
= true;
2617 if (wlc
->bandinit_pending
) {
2618 wlc_suspend_mac_and_wait(wlc
);
2619 wlc_set_chanspec(wlc
, wlc
->default_bss
->chanspec
);
2620 wlc
->bandinit_pending
= false;
2621 wlc_enable_mac(wlc
);
2624 wlc_bmac_up_finish(wlc
->hw
);
2626 /* other software states up after ISR is running */
2627 /* start APs that were to be brought up but are not up yet */
2628 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2630 /* Program the TX wme params with the current settings */
2631 wlc_wme_retries_write(wlc
);
2633 /* start one second watchdog timer */
2634 ASSERT(!wlc
->WDarmed
);
2635 wl_add_timer(wlc
->wl
, wlc
->wdtimer
, TIMER_INTERVAL_WATCHDOG
, true);
2636 wlc
->WDarmed
= true;
2638 /* ensure antenna config is up to date */
2639 wlc_stf_phy_txant_upd(wlc
);
2640 /* ensure LDPC config is in sync */
2641 wlc_ht_update_ldpc(wlc
, wlc
->stf
->ldpc
);
2646 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2647 static void wlc_tx_prec_map_init(struct wlc_info
*wlc
)
2649 wlc
->tx_prec_map
= WLC_PREC_BMP_ALL
;
2650 memset(wlc
->fifo2prec_map
, 0, NFIFO
* sizeof(u16
));
2652 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2653 * if either is full.
2655 if (!EDCF_ENAB(wlc
->pub
)) {
2656 wlc
->fifo2prec_map
[TX_DATA_FIFO
] = WLC_PREC_BMP_ALL
;
2657 wlc
->fifo2prec_map
[TX_CTL_FIFO
] = WLC_PREC_BMP_ALL
;
2659 wlc
->fifo2prec_map
[TX_AC_BK_FIFO
] = WLC_PREC_BMP_AC_BK
;
2660 wlc
->fifo2prec_map
[TX_AC_BE_FIFO
] = WLC_PREC_BMP_AC_BE
;
2661 wlc
->fifo2prec_map
[TX_AC_VI_FIFO
] = WLC_PREC_BMP_AC_VI
;
2662 wlc
->fifo2prec_map
[TX_AC_VO_FIFO
] = WLC_PREC_BMP_AC_VO
;
2666 static uint
wlc_down_del_timer(struct wlc_info
*wlc
)
2674 * Mark the interface nonoperational, stop the software mechanisms,
2675 * disable the hardware, free any transient buffer state.
2676 * Return a count of the number of driver callbacks still pending.
2678 uint
wlc_down(struct wlc_info
*wlc
)
2683 bool dev_gone
= false;
2686 WL_TRACE("wl%d: %s:\n", wlc
->pub
->unit
, __func__
);
2688 /* check if we are already in the going down path */
2689 if (wlc
->going_down
) {
2690 WL_ERROR("wl%d: %s: Driver going down so return\n",
2691 wlc
->pub
->unit
, __func__
);
2697 /* in between, mpc could try to bring down again.. */
2698 wlc
->going_down
= true;
2700 callbacks
+= wlc_bmac_down_prep(wlc
->hw
);
2702 dev_gone
= DEVICEREMOVED(wlc
);
2704 /* Call any registered down handlers */
2705 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
2706 if (wlc
->modulecb
[i
].down_fn
)
2708 wlc
->modulecb
[i
].down_fn(wlc
->modulecb
[i
].hdl
);
2711 /* cancel the watchdog timer */
2713 if (!wl_del_timer(wlc
->wl
, wlc
->wdtimer
))
2715 wlc
->WDarmed
= false;
2717 /* cancel all other timers */
2718 callbacks
+= wlc_down_del_timer(wlc
);
2720 /* interrupt must have been blocked */
2721 ASSERT((wlc
->macintmask
== 0) || !wlc
->pub
->up
);
2723 wlc
->pub
->up
= false;
2725 wlc_phy_mute_upd(wlc
->band
->pi
, false, PHY_MUTE_ALL
);
2727 /* clear txq flow control */
2728 wlc_txflowcontrol_reset(wlc
);
2730 /* flush tx queues */
2731 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
2732 pktq_flush(wlc
->osh
, &qi
->q
, true, NULL
, 0);
2733 ASSERT(pktq_empty(&qi
->q
));
2736 /* flush event queue.
2737 * Should be the last thing done after all the events are generated
2738 * Just delivers the events synchronously instead of waiting for a timer
2740 callbacks
+= wlc_eventq_down(wlc
->eventq
);
2742 callbacks
+= wlc_bmac_down_finish(wlc
->hw
);
2744 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2748 /* Verify all packets are flushed from the driver */
2749 if (wlc
->osh
->pktalloced
!= 0) {
2750 WL_ERROR("%d packets not freed at wlc_down!!!!!!\n",
2751 wlc
->osh
->pktalloced
);
2754 /* Since all the packets should have been freed,
2755 * all callbacks should have been called
2757 for (i
= 1; i
<= wlc
->pub
->tunables
->maxpktcb
; i
++)
2758 ASSERT(wlc
->pkt_callback
[i
].fn
== NULL
);
2760 wlc
->going_down
= false;
2764 /* Set the current gmode configuration */
2765 int wlc_set_gmode(struct wlc_info
*wlc
, u8 gmode
, bool config
)
2770 /* Default to 54g Auto */
2771 s8 shortslot
= WLC_SHORTSLOT_AUTO
; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2772 bool shortslot_restrict
= false; /* Restrict association to stations that support shortslot
2774 bool ignore_bcns
= true; /* Ignore legacy beacons on the same channel */
2775 bool ofdm_basic
= false; /* Make 6, 12, and 24 basic rates */
2776 int preamble
= WLC_PLCP_LONG
; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2777 bool preamble_restrict
= false; /* Restrict association to stations that support short
2780 struct wlcband
*band
;
2782 /* if N-support is enabled, allow Gmode set as long as requested
2783 * Gmode is not GMODE_LEGACY_B
2785 if (N_ENAB(wlc
->pub
) && gmode
== GMODE_LEGACY_B
)
2786 return BCME_UNSUPPORTED
;
2788 /* verify that we are dealing with 2G band and grab the band pointer */
2789 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
2791 else if ((NBANDS(wlc
) > 1) &&
2792 (wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
== WLC_BAND_2G
))
2793 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
2795 return BCME_BADBAND
;
2797 /* Legacy or bust when no OFDM is supported by regulatory */
2798 if ((wlc_channel_locale_flags_in_band(wlc
->cmi
, band
->bandunit
) &
2799 WLC_NO_OFDM
) && (gmode
!= GMODE_LEGACY_B
))
2802 /* update configuration value */
2804 wlc_protection_upd(wlc
, WLC_PROT_G_USER
, gmode
);
2806 /* Clear supported rates filter */
2807 memset(&wlc
->sup_rates_override
, 0, sizeof(wlc_rateset_t
));
2809 /* Clear rateset override */
2810 memset(&rs
, 0, sizeof(wlc_rateset_t
));
2813 case GMODE_LEGACY_B
:
2814 shortslot
= WLC_SHORTSLOT_OFF
;
2815 wlc_rateset_copy(&gphy_legacy_rates
, &rs
);
2820 if (AP_ENAB(wlc
->pub
))
2821 wlc_rateset_copy(&cck_rates
, &wlc
->sup_rates_override
);
2825 /* Accept defaults */
2830 preamble
= WLC_PLCP_SHORT
;
2831 preamble_restrict
= true;
2834 case GMODE_PERFORMANCE
:
2835 if (AP_ENAB(wlc
->pub
)) /* Put all rates into the Supported Rates element */
2836 wlc_rateset_copy(&cck_ofdm_rates
,
2837 &wlc
->sup_rates_override
);
2839 shortslot
= WLC_SHORTSLOT_ON
;
2840 shortslot_restrict
= true;
2842 preamble
= WLC_PLCP_SHORT
;
2843 preamble_restrict
= true;
2848 WL_ERROR("wl%d: %s: invalid gmode %d\n",
2849 wlc
->pub
->unit
, __func__
, gmode
);
2850 return BCME_UNSUPPORTED
;
2854 * If we are switching to gmode == GMODE_LEGACY_B,
2855 * clean up rate info that may refer to OFDM rates.
2857 if ((gmode
== GMODE_LEGACY_B
) && (band
->gmode
!= GMODE_LEGACY_B
)) {
2858 band
->gmode
= gmode
;
2859 if (band
->rspec_override
&& !IS_CCK(band
->rspec_override
)) {
2860 band
->rspec_override
= 0;
2861 wlc_reprate_init(wlc
);
2863 if (band
->mrspec_override
&& !IS_CCK(band
->mrspec_override
)) {
2864 band
->mrspec_override
= 0;
2868 band
->gmode
= gmode
;
2870 wlc
->ignore_bcns
= ignore_bcns
;
2872 wlc
->shortslot_override
= shortslot
;
2874 if (AP_ENAB(wlc
->pub
)) {
2875 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2876 wlc
->PLCPHdr_override
=
2878 WLC_PLCP_LONG
) ? WLC_PLCP_SHORT
: WLC_PLCP_AUTO
;
2881 if ((AP_ENAB(wlc
->pub
) && preamble
!= WLC_PLCP_LONG
)
2882 || preamble
== WLC_PLCP_SHORT
)
2883 wlc
->default_bss
->capability
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
2885 wlc
->default_bss
->capability
&= ~WLAN_CAPABILITY_SHORT_PREAMBLE
;
2887 /* Update shortslot capability bit for AP and IBSS */
2888 if ((AP_ENAB(wlc
->pub
) && shortslot
== WLC_SHORTSLOT_AUTO
) ||
2889 shortslot
== WLC_SHORTSLOT_ON
)
2890 wlc
->default_bss
->capability
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2892 wlc
->default_bss
->capability
&=
2893 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2895 /* Use the default 11g rateset */
2897 wlc_rateset_copy(&cck_ofdm_rates
, &rs
);
2900 for (i
= 0; i
< rs
.count
; i
++) {
2901 if (rs
.rates
[i
] == WLC_RATE_6M
2902 || rs
.rates
[i
] == WLC_RATE_12M
2903 || rs
.rates
[i
] == WLC_RATE_24M
)
2904 rs
.rates
[i
] |= WLC_RATE_FLAG
;
2908 /* Set default bss rateset */
2909 wlc
->default_bss
->rateset
.count
= rs
.count
;
2910 bcopy((char *)rs
.rates
, (char *)wlc
->default_bss
->rateset
.rates
,
2911 sizeof(wlc
->default_bss
->rateset
.rates
));
2916 static int wlc_nmode_validate(struct wlc_info
*wlc
, s32 nmode
)
2928 if (!(WLC_PHY_11N_CAP(wlc
->band
)))
2940 int wlc_set_nmode(struct wlc_info
*wlc
, s32 nmode
)
2945 err
= wlc_nmode_validate(wlc
, nmode
);
2952 wlc
->pub
->_n_enab
= OFF
;
2953 wlc
->default_bss
->flags
&= ~WLC_BSS_HT
;
2954 /* delete the mcs rates from the default and hw ratesets */
2955 wlc_rateset_mcs_clear(&wlc
->default_bss
->rateset
);
2956 for (i
= 0; i
< NBANDS(wlc
); i
++) {
2957 memset(wlc
->bandstate
[i
]->hw_rateset
.mcs
, 0,
2959 if (IS_MCS(wlc
->band
->rspec_override
)) {
2960 wlc
->bandstate
[i
]->rspec_override
= 0;
2961 wlc_reprate_init(wlc
);
2963 if (IS_MCS(wlc
->band
->mrspec_override
))
2964 wlc
->bandstate
[i
]->mrspec_override
= 0;
2969 if (wlc
->stf
->txstreams
== WL_11N_3x3
)
2975 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
2976 /* force GMODE_AUTO if NMODE is ON */
2977 wlc_set_gmode(wlc
, GMODE_AUTO
, true);
2978 if (nmode
== WL_11N_3x3
)
2979 wlc
->pub
->_n_enab
= SUPPORT_HT
;
2981 wlc
->pub
->_n_enab
= SUPPORT_11N
;
2982 wlc
->default_bss
->flags
|= WLC_BSS_HT
;
2983 /* add the mcs rates to the default and hw ratesets */
2984 wlc_rateset_mcs_build(&wlc
->default_bss
->rateset
,
2985 wlc
->stf
->txstreams
);
2986 for (i
= 0; i
< NBANDS(wlc
); i
++)
2987 memcpy(wlc
->bandstate
[i
]->hw_rateset
.mcs
,
2988 wlc
->default_bss
->rateset
.mcs
, MCSSET_LEN
);
2999 static int wlc_set_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs_arg
)
3001 wlc_rateset_t rs
, new;
3004 bcopy((char *)rs_arg
, (char *)&rs
, sizeof(wlc_rateset_t
));
3006 /* check for bad count value */
3007 if ((rs
.count
== 0) || (rs
.count
> WLC_NUMRATES
))
3008 return BCME_BADRATESET
;
3010 /* try the current band */
3011 bandunit
= wlc
->band
->bandunit
;
3012 bcopy((char *)&rs
, (char *)&new, sizeof(wlc_rateset_t
));
3013 if (wlc_rate_hwrs_filter_sort_validate
3014 (&new, &wlc
->bandstate
[bandunit
]->hw_rateset
, true,
3015 wlc
->stf
->txstreams
))
3018 /* try the other band */
3019 if (IS_MBAND_UNLOCKED(wlc
)) {
3020 bandunit
= OTHERBANDUNIT(wlc
);
3021 bcopy((char *)&rs
, (char *)&new, sizeof(wlc_rateset_t
));
3022 if (wlc_rate_hwrs_filter_sort_validate(&new,
3024 bandstate
[bandunit
]->
3026 wlc
->stf
->txstreams
))
3033 /* apply new rateset */
3034 bcopy((char *)&new, (char *)&wlc
->default_bss
->rateset
,
3035 sizeof(wlc_rateset_t
));
3036 bcopy((char *)&new, (char *)&wlc
->bandstate
[bandunit
]->defrateset
,
3037 sizeof(wlc_rateset_t
));
3041 /* simplified integer set interface for common ioctl handler */
3042 int wlc_set(struct wlc_info
*wlc
, int cmd
, int arg
)
3044 return wlc_ioctl(wlc
, cmd
, (void *)&arg
, sizeof(arg
), NULL
);
3047 /* simplified integer get interface for common ioctl handler */
3048 int wlc_get(struct wlc_info
*wlc
, int cmd
, int *arg
)
3050 return wlc_ioctl(wlc
, cmd
, arg
, sizeof(int), NULL
);
3053 static void wlc_ofdm_rateset_war(struct wlc_info
*wlc
)
3058 if (wlc
->cfg
->associated
)
3059 r
= wlc
->cfg
->current_bss
->rateset
.rates
[0];
3061 r
= wlc
->default_bss
->rateset
.rates
[0];
3063 wlc_phy_ofdm_rateset_war(wlc
->band
->pi
, war
);
3069 wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
3070 struct wlc_if
*wlcif
)
3072 return _wlc_ioctl(wlc
, cmd
, arg
, len
, wlcif
);
3075 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3077 _wlc_ioctl(struct wlc_info
*wlc
, int cmd
, void *arg
, int len
,
3078 struct wlc_if
*wlcif
)
3085 struct scb
*nextscb
;
3089 wlc_bsscfg_t
*bsscfg
;
3090 struct osl_info
*osh
;
3091 wlc_bss_info_t
*current_bss
;
3093 /* update bsscfg pointer */
3094 bsscfg
= NULL
; /* XXX: Hack bsscfg to be size one and use this globally */
3097 /* initialize the following to get rid of compiler warning */
3103 /* If the device is turned off, then it's not "removed" */
3104 if (!wlc
->pub
->hw_off
&& DEVICEREMOVED(wlc
)) {
3105 WL_ERROR("wl%d: %s: dead chip\n", wlc
->pub
->unit
, __func__
);
3110 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
3112 /* default argument is generic integer */
3113 pval
= arg
? (int *)arg
:NULL
;
3115 /* This will prevent the misaligned access */
3116 if (pval
&& (u32
) len
>= sizeof(val
))
3117 bcopy(pval
, &val
, sizeof(val
));
3121 /* bool conversion to avoid duplication below */
3122 bool_val
= val
!= 0;
3124 if (cmd
!= WLC_SET_CHANNEL
)
3125 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3126 cmd
, (uint
)val
, val
, len
);
3132 /* A few commands don't need any arguments; all the others do. */
3140 case WLC_START_CHANNEL_QA
:
3145 if ((arg
== NULL
) || (len
<= 0)) {
3146 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3147 wlc
->pub
->unit
, __func__
, cmd
);
3148 bcmerror
= BCME_BADARG
;
3156 case WLC_GET_MSGLEVEL
:
3157 *pval
= wl_msg_level
;
3160 case WLC_SET_MSGLEVEL
:
3165 case WLC_GET_INSTANCE
:
3166 *pval
= wlc
->pub
->unit
;
3169 case WLC_GET_CHANNEL
:{
3170 channel_info_t
*ci
= (channel_info_t
*) arg
;
3172 ASSERT(len
> (int)sizeof(ci
));
3175 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
);
3176 ci
->target_channel
=
3177 CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
);
3178 ci
->scan_channel
= 0;
3183 case WLC_SET_CHANNEL
:{
3184 chanspec_t chspec
= CH20MHZ_CHSPEC(val
);
3186 if (val
< 0 || val
> MAXCHANNEL
) {
3187 bcmerror
= BCME_OUTOFRANGECHAN
;
3191 if (!wlc_valid_chanspec_db(wlc
->cmi
, chspec
)) {
3192 bcmerror
= BCME_BADCHAN
;
3196 if (!wlc
->pub
->up
&& IS_MBAND_UNLOCKED(wlc
)) {
3197 if (wlc
->band
->bandunit
!=
3198 CHSPEC_WLCBANDUNIT(chspec
))
3199 wlc
->bandinit_pending
= true;
3201 wlc
->bandinit_pending
= false;
3204 wlc
->default_bss
->chanspec
= chspec
;
3205 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3206 if (wlc
->pub
->up
&& !wlc
->pub
->associated
&&
3207 (WLC_BAND_PI_RADIO_CHANSPEC
!= chspec
)) {
3208 wlc_set_home_chanspec(wlc
, chspec
);
3209 wlc_suspend_mac_and_wait(wlc
);
3210 wlc_set_chanspec(wlc
, chspec
);
3211 wlc_enable_mac(wlc
);
3217 case WLC_GET_UCFLAGS
:
3218 if (!wlc
->pub
->up
) {
3219 bcmerror
= BCME_NOTUP
;
3223 /* optional band is stored in the second integer of incoming buffer */
3226 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3228 /* bcmerror checking */
3229 bcmerror
= wlc_iocregchk(wlc
, band
);
3233 if (val
>= MHFMAX
) {
3234 bcmerror
= BCME_RANGE
;
3238 *pval
= wlc_bmac_mhf_get(wlc
->hw
, (u8
) val
, WLC_BAND_AUTO
);
3241 case WLC_SET_UCFLAGS
:
3242 if (!wlc
->pub
->up
) {
3243 bcmerror
= BCME_NOTUP
;
3247 /* optional band is stored in the second integer of incoming buffer */
3250 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3252 /* bcmerror checking */
3253 bcmerror
= wlc_iocregchk(wlc
, band
);
3259 bcmerror
= BCME_RANGE
;
3263 wlc_mhf(wlc
, (u8
) i
, 0xffff, (u16
) (val
>> NBITS(u16
)),
3270 /* optional band is stored in the second integer of incoming buffer */
3273 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3275 /* bcmerror checking */
3276 bcmerror
= wlc_iocregchk(wlc
, band
);
3281 bcmerror
= BCME_BADADDR
;
3285 *pval
= wlc_read_shm(wlc
, (u16
) val
);
3291 /* optional band is stored in the second integer of incoming buffer */
3294 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO
: ((int *)arg
)[1];
3296 /* bcmerror checking */
3297 bcmerror
= wlc_iocregchk(wlc
, band
);
3302 bcmerror
= BCME_BADADDR
;
3306 wlc_write_shm(wlc
, (u16
) val
,
3307 (u16
) (val
>> NBITS(u16
)));
3310 case WLC_R_REG
: /* MAC registers */
3312 r
= (rw_reg_t
*) arg
;
3313 band
= WLC_BAND_AUTO
;
3315 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3316 bcmerror
= BCME_BUFTOOSHORT
;
3320 if (len
>= (int)sizeof(rw_reg_t
))
3323 /* bcmerror checking */
3324 bcmerror
= wlc_iocregchk(wlc
, band
);
3328 if ((r
->byteoff
+ r
->size
) > sizeof(d11regs_t
)) {
3329 bcmerror
= BCME_BADADDR
;
3332 if (r
->size
== sizeof(u32
))
3335 (u32
*)((unsigned char *)(unsigned long)regs
+
3337 else if (r
->size
== sizeof(u16
))
3340 (u16
*)((unsigned char *)(unsigned long)regs
+
3343 bcmerror
= BCME_BADADDR
;
3348 r
= (rw_reg_t
*) arg
;
3349 band
= WLC_BAND_AUTO
;
3351 if (len
< (int)(sizeof(rw_reg_t
) - sizeof(uint
))) {
3352 bcmerror
= BCME_BUFTOOSHORT
;
3356 if (len
>= (int)sizeof(rw_reg_t
))
3359 /* bcmerror checking */
3360 bcmerror
= wlc_iocregchk(wlc
, band
);
3364 if (r
->byteoff
+ r
->size
> sizeof(d11regs_t
)) {
3365 bcmerror
= BCME_BADADDR
;
3368 if (r
->size
== sizeof(u32
))
3370 (u32
*)((unsigned char *)(unsigned long) regs
+
3371 r
->byteoff
), r
->val
);
3372 else if (r
->size
== sizeof(u16
))
3374 (u16
*)((unsigned char *)(unsigned long) regs
+
3375 r
->byteoff
), r
->val
);
3377 bcmerror
= BCME_BADADDR
;
3382 *pval
= wlc
->stf
->txant
;
3386 bcmerror
= wlc_stf_ant_txant_validate(wlc
, (s8
) val
);
3390 wlc
->stf
->txant
= (s8
) val
;
3392 /* if down, we are done */
3396 wlc_suspend_mac_and_wait(wlc
);
3398 wlc_stf_phy_txant_upd(wlc
);
3399 wlc_beacon_phytxctl_txant_upd(wlc
, wlc
->bcn_rspec
);
3401 wlc_enable_mac(wlc
);
3405 case WLC_GET_ANTDIV
:{
3408 /* return configured value if core is down */
3409 if (!wlc
->pub
->up
) {
3410 *pval
= wlc
->stf
->ant_rx_ovr
;
3413 if (wlc_phy_ant_rxdiv_get
3414 (wlc
->band
->pi
, &phy_antdiv
))
3415 *pval
= (int)phy_antdiv
;
3417 *pval
= (int)wlc
->stf
->ant_rx_ovr
;
3422 case WLC_SET_ANTDIV
:
3423 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3424 if ((val
< -1) || (val
> 3)) {
3425 bcmerror
= BCME_RANGE
;
3430 val
= ANT_RX_DIV_DEF
;
3432 wlc
->stf
->ant_rx_ovr
= (u8
) val
;
3433 wlc_phy_ant_rxdiv_set(wlc
->band
->pi
, (u8
) val
);
3436 case WLC_GET_RX_ANT
:{ /* get latest used rx antenna */
3439 if (!wlc
->pub
->up
) {
3440 bcmerror
= BCME_NOTUP
;
3444 rxstatus
= R_REG(wlc
->osh
, &wlc
->regs
->phyrxstatus0
);
3445 if (rxstatus
== 0xdead || rxstatus
== (u16
) -1) {
3446 bcmerror
= BCME_ERROR
;
3449 *pval
= (rxstatus
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0;
3454 case WLC_GET_UCANTDIV
:
3456 bcmerror
= BCME_NOCLK
;
3461 (wlc_bmac_mhf_get(wlc
->hw
, MHF1
, WLC_BAND_AUTO
) &
3465 case WLC_SET_UCANTDIV
:{
3466 if (!wlc
->pub
->up
) {
3467 bcmerror
= BCME_NOTUP
;
3471 /* if multiband, band must be locked */
3472 if (IS_MBAND_UNLOCKED(wlc
)) {
3473 bcmerror
= BCME_NOTBANDLOCKED
;
3477 /* 4322 supports antdiv in phy, no need to set it to ucode */
3478 if (WLCISNPHY(wlc
->band
)
3479 && D11REV_IS(wlc
->pub
->corerev
, 16)) {
3480 WL_ERROR("wl%d: can't set ucantdiv for 4322\n",
3482 bcmerror
= BCME_UNSUPPORTED
;
3484 wlc_mhf(wlc
, MHF1
, MHF1_ANTDIV
,
3485 (val
? MHF1_ANTDIV
: 0), WLC_BAND_AUTO
);
3488 #endif /* defined(BCMDBG) */
3495 if (val
>= 1 && val
<= RETRY_SHORT_MAX
) {
3497 wlc
->SRL
= (u16
) val
;
3499 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3501 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3502 WLC_WME_RETRY_SHORT_SET(wlc
, ac
, wlc
->SRL
);
3504 wlc_wme_retries_write(wlc
);
3506 bcmerror
= BCME_RANGE
;
3514 if (val
>= 1 && val
<= 255) {
3516 wlc
->LRL
= (u16
) val
;
3518 wlc_bmac_retrylimit_upd(wlc
->hw
, wlc
->SRL
, wlc
->LRL
);
3520 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
3521 WLC_WME_RETRY_LONG_SET(wlc
, ac
, wlc
->LRL
);
3523 wlc_wme_retries_write(wlc
);
3525 bcmerror
= BCME_RANGE
;
3529 *pval
= wlc
->band
->CWmin
;
3534 bcmerror
= BCME_NOCLK
;
3538 if (val
>= 1 && val
<= 255) {
3539 wlc_set_cwmin(wlc
, (u16
) val
);
3541 bcmerror
= BCME_RANGE
;
3545 *pval
= wlc
->band
->CWmax
;
3550 bcmerror
= BCME_NOCLK
;
3554 if (val
>= 255 && val
<= 2047) {
3555 wlc_set_cwmax(wlc
, (u16
) val
);
3557 bcmerror
= BCME_RANGE
;
3560 case WLC_GET_RADIO
: /* use mask if don't want to expose some internal bits */
3561 *pval
= wlc
->pub
->radio_disabled
;
3564 case WLC_SET_RADIO
:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3567 u16 radiomask
, radioval
;
3569 WL_RADIO_SW_DISABLE
| WL_RADIO_HW_DISABLE
;
3572 radiomask
= (val
& 0xffff0000) >> 16;
3573 radioval
= val
& 0x0000ffff;
3575 if ((radiomask
== 0) || (radiomask
& ~validbits
)
3576 || (radioval
& ~validbits
)
3577 || ((radioval
& ~radiomask
) != 0)) {
3578 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3580 bcmerror
= BCME_RANGE
;
3585 (wlc
->pub
->radio_disabled
& ~radiomask
) | radioval
;
3586 wlc
->pub
->radio_disabled
= new;
3588 wlc_radio_hwdisable_upd(wlc
);
3593 case WLC_GET_PHYTYPE
:
3594 *pval
= WLC_PHYTYPE(wlc
->band
->phytype
);
3599 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
))) {
3602 wsec_key_t
*src_key
= wlc
->wsec_keys
[val
];
3604 if (len
< (int)sizeof(key
)) {
3605 bcmerror
= BCME_BUFTOOSHORT
;
3609 memset((char *)&key
, 0, sizeof(key
));
3611 key
.index
= src_key
->id
;
3612 key
.len
= src_key
->len
;
3613 bcopy(src_key
->data
, key
.data
, key
.len
);
3614 key
.algo
= src_key
->algo
;
3615 if (WSEC_SOFTKEY(wlc
, src_key
, bsscfg
))
3616 key
.flags
|= WL_SOFT_KEY
;
3617 if (src_key
->flags
& WSEC_PRIMARY_KEY
)
3618 key
.flags
|= WL_PRIMARY_KEY
;
3620 bcopy(src_key
->ea
, key
.ea
,
3624 bcopy((char *)&key
, arg
, sizeof(key
));
3626 bcmerror
= BCME_BADKEYIDX
;
3628 #endif /* defined(BCMDBG) */
3632 wlc_iovar_op(wlc
, "wsec_key", NULL
, 0, arg
, len
, IOV_SET
,
3636 case WLC_GET_KEY_SEQ
:{
3639 if (len
< DOT11_WPA_KEY_RSC_LEN
) {
3640 bcmerror
= BCME_BUFTOOSHORT
;
3644 /* Return the key's tx iv as an EAPOL sequence counter.
3645 * This will be used to supply the RSC value to a supplicant.
3646 * The format is 8 bytes, with least significant in seq[0].
3649 key
= WSEC_KEY(wlc
, val
);
3650 if ((val
>= 0) && (val
< WLC_MAX_WSEC_KEYS(wlc
)) &&
3652 u8 seq
[DOT11_WPA_KEY_RSC_LEN
];
3655 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3656 if ((bsscfg
->WPA_auth
& WPA_AUTH_NONE
) &&
3657 is_zero_ether_addr(key
->ea
)) {
3658 lo
= bsscfg
->wpa_none_txiv
.lo
;
3659 hi
= bsscfg
->wpa_none_txiv
.hi
;
3665 /* format the buffer, low to high */
3667 seq
[1] = (lo
>> 8) & 0xff;
3669 seq
[3] = (hi
>> 8) & 0xff;
3670 seq
[4] = (hi
>> 16) & 0xff;
3671 seq
[5] = (hi
>> 24) & 0xff;
3675 bcopy((char *)seq
, arg
, sizeof(seq
));
3677 bcmerror
= BCME_BADKEYIDX
;
3682 case WLC_GET_CURR_RATESET
:{
3683 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3686 if (bsscfg
->associated
)
3687 rs
= ¤t_bss
->rateset
;
3689 rs
= &wlc
->default_bss
->rateset
;
3691 if (len
< (int)(rs
->count
+ sizeof(rs
->count
))) {
3692 bcmerror
= BCME_BUFTOOSHORT
;
3696 /* Copy only legacy rateset section */
3697 ret_rs
->count
= rs
->count
;
3698 bcopy(&rs
->rates
, &ret_rs
->rates
, rs
->count
);
3702 case WLC_GET_RATESET
:{
3704 wl_rateset_t
*ret_rs
= (wl_rateset_t
*) arg
;
3706 memset(&rs
, 0, sizeof(wlc_rateset_t
));
3707 wlc_default_rateset(wlc
, (wlc_rateset_t
*) &rs
);
3709 if (len
< (int)(rs
.count
+ sizeof(rs
.count
))) {
3710 bcmerror
= BCME_BUFTOOSHORT
;
3714 /* Copy only legacy rateset section */
3715 ret_rs
->count
= rs
.count
;
3716 bcopy(&rs
.rates
, &ret_rs
->rates
, rs
.count
);
3720 case WLC_SET_RATESET
:{
3722 wl_rateset_t
*in_rs
= (wl_rateset_t
*) arg
;
3724 if (len
< (int)(in_rs
->count
+ sizeof(in_rs
->count
))) {
3725 bcmerror
= BCME_BUFTOOSHORT
;
3729 if (in_rs
->count
> WLC_NUMRATES
) {
3730 bcmerror
= BCME_BUFTOOLONG
;
3734 memset(&rs
, 0, sizeof(wlc_rateset_t
));
3736 /* Copy only legacy rateset section */
3737 rs
.count
= in_rs
->count
;
3738 bcopy(&in_rs
->rates
, &rs
.rates
, rs
.count
);
3740 /* merge rateset coming in with the current mcsset */
3741 if (N_ENAB(wlc
->pub
)) {
3742 if (bsscfg
->associated
)
3743 bcopy(¤t_bss
->rateset
.mcs
[0],
3744 rs
.mcs
, MCSSET_LEN
);
3746 bcopy(&wlc
->default_bss
->rateset
.mcs
[0],
3747 rs
.mcs
, MCSSET_LEN
);
3750 bcmerror
= wlc_set_rateset(wlc
, &rs
);
3753 wlc_ofdm_rateset_war(wlc
);
3758 case WLC_GET_BCNPRD
:
3759 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3760 *pval
= current_bss
->beacon_period
;
3762 *pval
= wlc
->default_bss
->beacon_period
;
3765 case WLC_SET_BCNPRD
:
3766 /* range [1, 0xffff] */
3767 if (val
>= DOT11_MIN_BEACON_PERIOD
3768 && val
<= DOT11_MAX_BEACON_PERIOD
) {
3769 wlc
->default_bss
->beacon_period
= (u16
) val
;
3771 bcmerror
= BCME_RANGE
;
3774 case WLC_GET_DTIMPRD
:
3775 if (BSSCFG_STA(bsscfg
) && bsscfg
->BSS
&& bsscfg
->associated
)
3776 *pval
= current_bss
->dtim_period
;
3778 *pval
= wlc
->default_bss
->dtim_period
;
3781 case WLC_SET_DTIMPRD
:
3782 /* range [1, 0xff] */
3783 if (val
>= DOT11_MIN_DTIM_PERIOD
3784 && val
<= DOT11_MAX_DTIM_PERIOD
) {
3785 wlc
->default_bss
->dtim_period
= (u8
) val
;
3787 bcmerror
= BCME_RANGE
;
3796 if ((val
>= PM_OFF
) && (val
<= PM_MAX
)) {
3800 /* Change watchdog driver to align watchdog with tbtt if possible */
3801 wlc_watchdog_upd(wlc
, PS_ALLOWED(wlc
));
3803 bcmerror
= BCME_ERROR
;
3805 #endif /* SUPPORT_PS */
3810 if (AP_ENAB(wlc
->pub
)) {
3811 bcmerror
= BCME_NOTSTA
;
3818 if (AP_ENAB(wlc
->pub
)) {
3819 bcmerror
= BCME_NOTSTA
;
3823 wlc
->wake
= val
? true : false;
3825 /* if down, we're done */
3829 /* apply to the mac */
3830 wlc_set_ps_ctrl(wlc
);
3833 #endif /* SUPPORT_PS */
3835 case WLC_GET_REVINFO
:
3836 bcmerror
= wlc_get_revision_info(wlc
, arg
, (uint
) len
);
3840 *pval
= (int)AP_ENAB(wlc
->pub
);
3844 if (bsscfg
->associated
)
3845 *pval
= (int)current_bss
->atim_window
;
3847 *pval
= (int)wlc
->default_bss
->atim_window
;
3851 wlc
->default_bss
->atim_window
= (u32
) val
;
3854 case WLC_GET_PKTCNTS
:{
3855 get_pktcnt_t
*pktcnt
= (get_pktcnt_t
*) pval
;
3856 if (WLC_UPDATE_STATS(wlc
))
3858 pktcnt
->rx_good_pkt
= WLCNTVAL(wlc
->pub
->_cnt
->rxframe
);
3859 pktcnt
->rx_bad_pkt
= WLCNTVAL(wlc
->pub
->_cnt
->rxerror
);
3860 pktcnt
->tx_good_pkt
=
3861 WLCNTVAL(wlc
->pub
->_cnt
->txfrmsnt
);
3862 pktcnt
->tx_bad_pkt
=
3863 WLCNTVAL(wlc
->pub
->_cnt
->txerror
) +
3864 WLCNTVAL(wlc
->pub
->_cnt
->txfail
);
3865 if (len
>= (int)sizeof(get_pktcnt_t
)) {
3866 /* Be backward compatible - only if buffer is large enough */
3867 pktcnt
->rx_ocast_good_pkt
=
3868 WLCNTVAL(wlc
->pub
->_cnt
->rxmfrmocast
);
3873 #ifdef SUPPORT_HWKEY
3876 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_GET
,
3882 wlc_iovar_op(wlc
, "wsec", NULL
, 0, arg
, len
, IOV_SET
,
3886 case WLC_GET_WPA_AUTH
:
3887 *pval
= (int)bsscfg
->WPA_auth
;
3890 case WLC_SET_WPA_AUTH
:
3891 /* change of WPA_Auth modifies the PS_ALLOWED state */
3892 if (BSSCFG_STA(bsscfg
)) {
3893 bsscfg
->WPA_auth
= (u16
) val
;
3895 bsscfg
->WPA_auth
= (u16
) val
;
3897 #endif /* SUPPORT_HWKEY */
3899 case WLC_GET_BANDLIST
:
3900 /* count of number of bands, followed by each band type */
3901 *pval
++ = NBANDS(wlc
);
3902 *pval
++ = wlc
->band
->bandtype
;
3903 if (NBANDS(wlc
) > 1)
3904 *pval
++ = wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->bandtype
;
3908 *pval
= wlc
->bandlocked
? wlc
->band
->bandtype
: WLC_BAND_AUTO
;
3911 case WLC_GET_PHYLIST
:
3913 unsigned char *cp
= arg
;
3915 bcmerror
= BCME_BUFTOOSHORT
;
3919 if (WLCISNPHY(wlc
->band
)) {
3921 } else if (WLCISLCNPHY(wlc
->band
)) {
3923 } else if (WLCISSSLPNPHY(wlc
->band
)) {
3930 case WLC_GET_SHORTSLOT
:
3931 *pval
= wlc
->shortslot
;
3934 case WLC_GET_SHORTSLOT_OVERRIDE
:
3935 *pval
= wlc
->shortslot_override
;
3938 case WLC_SET_SHORTSLOT_OVERRIDE
:
3939 if ((val
!= WLC_SHORTSLOT_AUTO
) &&
3940 (val
!= WLC_SHORTSLOT_OFF
) && (val
!= WLC_SHORTSLOT_ON
)) {
3941 bcmerror
= BCME_RANGE
;
3945 wlc
->shortslot_override
= (s8
) val
;
3947 /* shortslot is an 11g feature, so no more work if we are
3948 * currently on the 5G band
3950 if (BAND_5G(wlc
->band
->bandtype
))
3953 if (wlc
->pub
->up
&& wlc
->pub
->associated
) {
3954 /* let watchdog or beacon processing update shortslot */
3955 } else if (wlc
->pub
->up
) {
3956 /* unassociated shortslot is off */
3957 wlc_switch_shortslot(wlc
, false);
3959 /* driver is down, so just update the wlc_info value */
3960 if (wlc
->shortslot_override
== WLC_SHORTSLOT_AUTO
) {
3961 wlc
->shortslot
= false;
3964 (wlc
->shortslot_override
==
3971 case WLC_GET_LEGACY_ERP
:
3972 *pval
= wlc
->include_legacy_erp
;
3975 case WLC_SET_LEGACY_ERP
:
3976 if (wlc
->include_legacy_erp
== bool_val
)
3979 wlc
->include_legacy_erp
= bool_val
;
3981 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
3982 wlc_update_beacon(wlc
);
3983 wlc_update_probe_resp(wlc
, true);
3988 if (wlc
->band
->bandtype
== WLC_BAND_2G
)
3989 *pval
= wlc
->band
->gmode
;
3990 else if (NBANDS(wlc
) > 1)
3991 *pval
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
;
3995 if (!wlc
->pub
->associated
)
3996 bcmerror
= wlc_set_gmode(wlc
, (u8
) val
, true);
3998 bcmerror
= BCME_ASSOCIATED
;
4003 case WLC_GET_GMODE_PROTECTION
:
4004 *pval
= wlc
->protection
->_g
;
4007 case WLC_GET_PROTECTION_CONTROL
:
4008 *pval
= wlc
->protection
->overlap
;
4011 case WLC_SET_PROTECTION_CONTROL
:
4012 if ((val
!= WLC_PROTECTION_CTL_OFF
) &&
4013 (val
!= WLC_PROTECTION_CTL_LOCAL
) &&
4014 (val
!= WLC_PROTECTION_CTL_OVERLAP
)) {
4015 bcmerror
= BCME_RANGE
;
4019 wlc_protection_upd(wlc
, WLC_PROT_OVERLAP
, (s8
) val
);
4021 /* Current g_protection will sync up to the specified control alg in watchdog
4022 * if the driver is up and associated.
4023 * If the driver is down or not associated, the control setting has no effect.
4027 case WLC_GET_GMODE_PROTECTION_OVERRIDE
:
4028 *pval
= wlc
->protection
->g_override
;
4031 case WLC_SET_GMODE_PROTECTION_OVERRIDE
:
4032 if ((val
!= WLC_PROTECTION_AUTO
) &&
4033 (val
!= WLC_PROTECTION_OFF
) && (val
!= WLC_PROTECTION_ON
)) {
4034 bcmerror
= BCME_RANGE
;
4038 wlc_protection_upd(wlc
, WLC_PROT_G_OVR
, (s8
) val
);
4042 case WLC_SET_SUP_RATESET_OVERRIDE
:{
4043 wlc_rateset_t rs
, new;
4046 if (len
< (int)sizeof(wlc_rateset_t
)) {
4047 bcmerror
= BCME_BUFTOOSHORT
;
4050 bcopy((char *)arg
, (char *)&rs
, sizeof(wlc_rateset_t
));
4052 /* check for bad count value */
4053 if (rs
.count
> WLC_NUMRATES
) {
4054 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4058 /* this command is only appropriate for gmode operation */
4059 if (!(wlc
->band
->gmode
||
4061 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4062 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4066 /* check for an empty rateset to clear the override */
4067 if (rs
.count
== 0) {
4068 memset(&wlc
->sup_rates_override
, 0,
4069 sizeof(wlc_rateset_t
));
4073 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4074 wlc_rateset_filter(&rs
, &new, false, WLC_RATES_CCK_OFDM
,
4075 RATE_MASK
, BSS_N_ENAB(wlc
, bsscfg
));
4076 wlc_rate_hwrs_filter_sort_validate(&new,
4079 wlc
->stf
->txstreams
);
4080 if (rs
.count
!= new.count
) {
4081 bcmerror
= BCME_BADRATESET
; /* invalid rateset */
4085 /* apply new rateset to the override */
4086 bcopy((char *)&new, (char *)&wlc
->sup_rates_override
,
4087 sizeof(wlc_rateset_t
));
4089 /* update bcn and probe resp if needed */
4090 if (wlc
->pub
->up
&& AP_ENAB(wlc
->pub
)
4091 && wlc
->pub
->associated
) {
4092 wlc_update_beacon(wlc
);
4093 wlc_update_probe_resp(wlc
, true);
4098 case WLC_GET_SUP_RATESET_OVERRIDE
:
4099 /* this command is only appropriate for gmode operation */
4100 if (!(wlc
->band
->gmode
||
4102 && wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->gmode
))) {
4103 bcmerror
= BCME_BADBAND
; /* gmode only command when not in gmode */
4106 if (len
< (int)sizeof(wlc_rateset_t
)) {
4107 bcmerror
= BCME_BUFTOOSHORT
;
4110 bcopy((char *)&wlc
->sup_rates_override
, (char *)arg
,
4111 sizeof(wlc_rateset_t
));
4115 case WLC_GET_PRB_RESP_TIMEOUT
:
4116 *pval
= wlc
->prb_resp_timeout
;
4119 case WLC_SET_PRB_RESP_TIMEOUT
:
4121 bcmerror
= BCME_NOTDOWN
;
4124 if (val
< 0 || val
>= 0xFFFF) {
4125 bcmerror
= BCME_RANGE
; /* bad value */
4128 wlc
->prb_resp_timeout
= (u16
) val
;
4131 case WLC_GET_KEY_PRIMARY
:{
4134 /* treat the 'val' parm as the key id */
4135 key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4137 *pval
= key
->id
== val
? true : false;
4139 bcmerror
= BCME_BADKEYIDX
;
4144 case WLC_SET_KEY_PRIMARY
:{
4145 wsec_key_t
*key
, *old_key
;
4147 bcmerror
= BCME_BADKEYIDX
;
4149 /* treat the 'val' parm as the key id */
4150 for (i
= 0; i
< WSEC_MAX_DEFAULT_KEYS
; i
++) {
4151 key
= bsscfg
->bss_def_keys
[i
];
4152 if (key
!= NULL
&& key
->id
== val
) {
4153 old_key
= WSEC_BSS_DEFAULT_KEY(bsscfg
);
4154 if (old_key
!= NULL
)
4157 key
->flags
|= WSEC_PRIMARY_KEY
;
4158 bsscfg
->wsec_index
= i
;
4174 /* validate the name value */
4176 for (i
= 0; i
< (uint
) len
&& *name
!= '\0';
4180 if (i
== (uint
) len
) {
4181 bcmerror
= BCME_BUFTOOSHORT
;
4184 i
++; /* include the null in the string length */
4186 if (cmd
== WLC_GET_VAR
) {
4188 wlc_iovar_op(wlc
, arg
,
4189 (void *)((s8
*) arg
+ i
),
4190 len
- i
, arg
, len
, IOV_GET
,
4194 wlc_iovar_op(wlc
, arg
, NULL
, 0,
4195 (void *)((s8
*) arg
+ i
),
4196 len
- i
, IOV_SET
, wlcif
);
4201 case WLC_SET_WSEC_PMK
:
4202 bcmerror
= BCME_UNSUPPORTED
;
4206 case WLC_CURRENT_PWR
:
4208 bcmerror
= BCME_NOTUP
;
4210 bcmerror
= wlc_get_current_txpwr(wlc
, arg
, len
);
4215 WL_ERROR("%s: WLC_LAST\n", __func__
);
4220 if (VALID_BCMERROR(bcmerror
))
4221 wlc
->pub
->bcmerror
= bcmerror
;
4227 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4228 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4229 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4231 if (!(wlc
->pub
->hw_off
))
4232 ASSERT(wlc_bmac_taclear(wlc
->hw
, ta_ok
) || !ta_ok
);
4238 /* consolidated register access ioctl error checking */
4239 int wlc_iocregchk(struct wlc_info
*wlc
, uint band
)
4241 /* if band is specified, it must be the current band */
4242 if ((band
!= WLC_BAND_AUTO
) && (band
!= (uint
) wlc
->band
->bandtype
))
4243 return BCME_BADBAND
;
4245 /* if multiband and band is not specified, band must be locked */
4246 if ((band
== WLC_BAND_AUTO
) && IS_MBAND_UNLOCKED(wlc
))
4247 return BCME_NOTBANDLOCKED
;
4249 /* must have core clocks */
4255 #endif /* defined(BCMDBG) */
4258 /* For some ioctls, make sure that the pi pointer matches the current phy */
4259 int wlc_iocpichk(struct wlc_info
*wlc
, uint phytype
)
4261 if (wlc
->band
->phytype
!= phytype
)
4262 return BCME_BADBAND
;
4267 /* Look up the given var name in the given table */
4268 static const bcm_iovar_t
*wlc_iovar_lookup(const bcm_iovar_t
*table
,
4271 const bcm_iovar_t
*vi
;
4272 const char *lookup_name
;
4274 /* skip any ':' delimited option prefixes */
4275 lookup_name
= strrchr(name
, ':');
4276 if (lookup_name
!= NULL
)
4281 ASSERT(table
!= NULL
);
4283 for (vi
= table
; vi
->name
; vi
++) {
4284 if (!strcmp(vi
->name
, lookup_name
))
4287 /* ran to end of table */
4289 return NULL
; /* var name not found */
4292 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4293 int wlc_iovar_getint(struct wlc_info
*wlc
, const char *name
, int *arg
)
4295 return wlc_iovar_op(wlc
, name
, NULL
, 0, arg
, sizeof(s32
), IOV_GET
,
4299 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4300 int wlc_iovar_setint(struct wlc_info
*wlc
, const char *name
, int arg
)
4302 return wlc_iovar_op(wlc
, name
, NULL
, 0, (void *)&arg
, sizeof(arg
),
4306 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4307 int wlc_iovar_gets8(struct wlc_info
*wlc
, const char *name
, s8
*arg
)
4313 wlc_iovar_op(wlc
, name
, NULL
, 0, &iovar_int
, sizeof(iovar_int
),
4316 *arg
= (s8
) iovar_int
;
4322 * register iovar table, watchdog and down handlers.
4323 * calling function must keep 'iovars' until wlc_module_unregister is called.
4324 * 'iovar' must have the last entry's name field being NULL as terminator.
4326 int wlc_module_register(struct wlc_pub
*pub
, const bcm_iovar_t
*iovars
,
4327 const char *name
, void *hdl
, iovar_fn_t i_fn
,
4328 watchdog_fn_t w_fn
, down_fn_t d_fn
)
4330 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4333 ASSERT(name
!= NULL
);
4334 ASSERT(i_fn
!= NULL
|| w_fn
!= NULL
|| d_fn
!= NULL
);
4336 /* find an empty entry and just add, no duplication check! */
4337 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4338 if (wlc
->modulecb
[i
].name
[0] == '\0') {
4339 strncpy(wlc
->modulecb
[i
].name
, name
,
4340 sizeof(wlc
->modulecb
[i
].name
) - 1);
4341 wlc
->modulecb
[i
].iovars
= iovars
;
4342 wlc
->modulecb
[i
].hdl
= hdl
;
4343 wlc
->modulecb
[i
].iovar_fn
= i_fn
;
4344 wlc
->modulecb
[i
].watchdog_fn
= w_fn
;
4345 wlc
->modulecb
[i
].down_fn
= d_fn
;
4350 /* it is time to increase the capacity */
4351 ASSERT(i
< WLC_MAXMODULES
);
4352 return BCME_NORESOURCE
;
4355 /* unregister module callbacks */
4356 int wlc_module_unregister(struct wlc_pub
*pub
, const char *name
, void *hdl
)
4358 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4362 return BCME_NOTFOUND
;
4364 ASSERT(name
!= NULL
);
4366 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4367 if (!strcmp(wlc
->modulecb
[i
].name
, name
) &&
4368 (wlc
->modulecb
[i
].hdl
== hdl
)) {
4369 memset(&wlc
->modulecb
[i
], 0, sizeof(modulecb_t
));
4374 /* table not found! */
4375 return BCME_NOTFOUND
;
4378 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4379 static void wlc_wme_retries_write(struct wlc_info
*wlc
)
4383 /* Need clock to do this */
4387 for (ac
= 0; ac
< AC_COUNT
; ac
++) {
4388 wlc_write_shm(wlc
, M_AC_TXLMT_ADDR(ac
), wlc
->wme_retries
[ac
]);
4392 /* Get or set an iovar. The params/p_len pair specifies any additional
4393 * qualifying parameters (e.g. an "element index") for a get, while the
4394 * arg/len pair is the buffer for the value to be set or retrieved.
4395 * Operation (get/set) is specified by the last argument.
4396 * interface context provided by wlcif
4398 * All pointers may point into the same buffer.
4401 wlc_iovar_op(struct wlc_info
*wlc
, const char *name
,
4402 void *params
, int p_len
, void *arg
, int len
,
4403 bool set
, struct wlc_if
*wlcif
)
4407 const bcm_iovar_t
*vi
= NULL
;
4411 ASSERT(name
!= NULL
);
4415 /* Get MUST have return space */
4416 ASSERT(set
|| (arg
&& len
));
4418 ASSERT(!(wlc
->pub
->hw_off
&& wlc
->pub
->up
));
4420 /* Set does NOT take qualifiers */
4421 ASSERT(!set
|| (!params
&& !p_len
));
4423 if (!set
&& (len
== sizeof(int)) &&
4424 !(IS_ALIGNED((unsigned long)(arg
), (uint
) sizeof(int)))) {
4425 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4426 wlc
->pub
->unit
, __func__
, name
);
4430 /* find the given iovar name */
4431 for (i
= 0; i
< WLC_MAXMODULES
; i
++) {
4432 if (!wlc
->modulecb
[i
].iovars
)
4434 vi
= wlc_iovar_lookup(wlc
->modulecb
[i
].iovars
, name
);
4438 /* iovar name not found */
4439 if (i
>= WLC_MAXMODULES
) {
4440 err
= BCME_UNSUPPORTED
;
4444 /* set up 'params' pointer in case this is a set command so that
4445 * the convenience int and bool code can be common to set and get
4447 if (params
== NULL
) {
4452 if (vi
->type
== IOVT_VOID
)
4454 else if (vi
->type
== IOVT_BUFFER
)
4457 /* all other types are integer sized */
4458 val_size
= sizeof(int);
4460 actionid
= set
? IOV_SVAL(vi
->varid
) : IOV_GVAL(vi
->varid
);
4462 /* Do the actual parameter implementation */
4463 err
= wlc
->modulecb
[i
].iovar_fn(wlc
->modulecb
[i
].hdl
, vi
, actionid
,
4464 name
, params
, p_len
, arg
, len
, val_size
,
4472 wlc_iovar_check(struct wlc_pub
*pub
, const bcm_iovar_t
*vi
, void *arg
, int len
,
4475 struct wlc_info
*wlc
= (struct wlc_info
*) pub
->wlc
;
4479 /* check generic condition flags */
4481 if (((vi
->flags
& IOVF_SET_DOWN
) && wlc
->pub
->up
) ||
4482 ((vi
->flags
& IOVF_SET_UP
) && !wlc
->pub
->up
)) {
4483 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4484 } else if ((vi
->flags
& IOVF_SET_BAND
)
4485 && IS_MBAND_UNLOCKED(wlc
)) {
4486 err
= BCME_NOTBANDLOCKED
;
4487 } else if ((vi
->flags
& IOVF_SET_CLK
) && !wlc
->clk
) {
4491 if (((vi
->flags
& IOVF_GET_DOWN
) && wlc
->pub
->up
) ||
4492 ((vi
->flags
& IOVF_GET_UP
) && !wlc
->pub
->up
)) {
4493 err
= (wlc
->pub
->up
? BCME_NOTDOWN
: BCME_NOTUP
);
4494 } else if ((vi
->flags
& IOVF_GET_BAND
)
4495 && IS_MBAND_UNLOCKED(wlc
)) {
4496 err
= BCME_NOTBANDLOCKED
;
4497 } else if ((vi
->flags
& IOVF_GET_CLK
) && !wlc
->clk
) {
4505 /* length check on io buf */
4506 err
= bcm_iovar_lencheck(vi
, arg
, len
, set
);
4510 /* On set, check value ranges for integer types */
4520 bcopy(arg
, &int_val
, sizeof(int));
4521 err
= wlc_iovar_rangecheck(wlc
, int_val
, vi
);
4529 /* handler for iovar table wlc_iovars */
4531 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4532 * iovar case, the switch statement maps the iovar id into separate get
4533 * and set values. If you add a new iovar to the switch you MUST use
4534 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4536 * Please use params for additional qualifying parameters.
4539 wlc_doiovar(void *hdl
, const bcm_iovar_t
*vi
, u32 actionid
,
4540 const char *name
, void *params
, uint p_len
, void *arg
, int len
,
4541 int val_size
, struct wlc_if
*wlcif
)
4543 struct wlc_info
*wlc
= hdl
;
4544 wlc_bsscfg_t
*bsscfg
;
4551 wlc_bss_info_t
*current_bss
;
4553 WL_TRACE("wl%d: %s\n", wlc
->pub
->unit
, __func__
);
4558 err
= wlc_iovar_check(wlc
->pub
, vi
, arg
, len
, IOV_ISSET(actionid
));
4562 /* convenience int and bool vals for first 8 bytes of buffer */
4563 if (p_len
>= (int)sizeof(int_val
))
4564 bcopy(params
, &int_val
, sizeof(int_val
));
4566 if (p_len
>= (int)sizeof(int_val
) * 2)
4567 bcopy((void *)((unsigned long)params
+ sizeof(int_val
)), &int_val2
,
4570 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4571 ret_int_ptr
= (s32
*) arg
;
4573 bool_val
= (int_val
!= 0) ? true : false;
4574 bool_val2
= (int_val2
!= 0) ? true : false;
4576 WL_TRACE("wl%d: %s: id %d\n",
4577 wlc
->pub
->unit
, __func__
, IOV_ID(actionid
));
4578 /* Do the actual parameter implementation */
4581 case IOV_GVAL(IOV_QTXPOWER
):{
4585 err
= wlc_phy_txpower_get(wlc
->band
->pi
, &qdbm
,
4590 /* Return qdbm units */
4592 qdbm
| (override
? WL_TXPWR_OVERRIDE
: 0);
4596 /* As long as override is false, this only sets the *user* targets.
4597 User can twiddle this all he wants with no harm.
4598 wlc_phy_txpower_set() explicitly sets override to false if
4599 not internal or test.
4601 case IOV_SVAL(IOV_QTXPOWER
):{
4605 /* Remove override bit and clip to max qdbm value */
4606 qdbm
= (u8
)min_t(u32
, (int_val
& ~WL_TXPWR_OVERRIDE
), 0xff);
4607 /* Extract override setting */
4608 override
= (int_val
& WL_TXPWR_OVERRIDE
) ? true : false;
4610 wlc_phy_txpower_set(wlc
->band
->pi
, qdbm
, override
);
4614 case IOV_GVAL(IOV_MPC
):
4615 *ret_int_ptr
= (s32
) wlc
->mpc
;
4618 case IOV_SVAL(IOV_MPC
):
4619 wlc
->mpc
= bool_val
;
4620 wlc_radio_mpc_upd(wlc
);
4624 case IOV_GVAL(IOV_BCN_LI_BCN
):
4625 *ret_int_ptr
= wlc
->bcn_li_bcn
;
4628 case IOV_SVAL(IOV_BCN_LI_BCN
):
4629 wlc
->bcn_li_bcn
= (u8
) int_val
;
4631 wlc_bcn_li_upd(wlc
);
4635 WL_ERROR("wl%d: %s: unsupported\n", wlc
->pub
->unit
, __func__
);
4636 err
= BCME_UNSUPPORTED
;
4640 goto exit
; /* avoid unused label warning */
4647 wlc_iovar_rangecheck(struct wlc_info
*wlc
, u32 val
, const bcm_iovar_t
*vi
)
4653 /* Only ranged integers are checked */
4656 max_val
|= 0x7fffffff;
4659 max_val
|= 0x00007fff;
4662 max_val
|= 0x0000007f;
4664 if (vi
->flags
& IOVF_NTRL
)
4666 else if (vi
->flags
& IOVF_WHL
)
4668 /* Signed values are checked against max_val and min_val */
4669 if ((s32
) val
< (s32
) min_val
4670 || (s32
) val
> (s32
) max_val
)
4675 max_val
|= 0xffffffff;
4678 max_val
|= 0x0000ffff;
4681 max_val
|= 0x000000ff;
4682 if (vi
->flags
& IOVF_NTRL
)
4684 if ((val
< min_val
) || (val
> max_val
))
4693 static const char *supr_reason
[] = {
4694 "None", "PMQ Entry", "Flush request",
4695 "Previous frag failure", "Channel mismatch",
4696 "Lifetime Expiry", "Underflow"
4699 static void wlc_print_txs_status(u16 s
)
4701 printf("[15:12] %d frame attempts\n", (s
& TX_STATUS_FRM_RTX_MASK
) >>
4702 TX_STATUS_FRM_RTX_SHIFT
);
4703 printf(" [11:8] %d rts attempts\n", (s
& TX_STATUS_RTS_RTX_MASK
) >>
4704 TX_STATUS_RTS_RTX_SHIFT
);
4705 printf(" [7] %d PM mode indicated\n",
4706 ((s
& TX_STATUS_PMINDCTD
) ? 1 : 0));
4707 printf(" [6] %d intermediate status\n",
4708 ((s
& TX_STATUS_INTERMEDIATE
) ? 1 : 0));
4709 printf(" [5] %d AMPDU\n", (s
& TX_STATUS_AMPDU
) ? 1 : 0);
4710 printf(" [4:2] %d Frame Suppressed Reason (%s)\n",
4711 ((s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
),
4712 supr_reason
[(s
& TX_STATUS_SUPR_MASK
) >> TX_STATUS_SUPR_SHIFT
]);
4713 printf(" [1] %d acked\n", ((s
& TX_STATUS_ACK_RCV
) ? 1 : 0));
4717 void wlc_print_txstatus(tx_status_t
*txs
)
4720 u16 s
= txs
->status
;
4721 u16 ackphyrxsh
= txs
->ackphyrxsh
;
4723 printf("\ntxpkt (MPDU) Complete\n");
4725 printf("FrameID: %04x ", txs
->frameid
);
4726 printf("TxStatus: %04x", s
);
4729 wlc_print_txs_status(s
);
4731 printf("LastTxTime: %04x ", txs
->lasttxtime
);
4732 printf("Seq: %04x ", txs
->sequence
);
4733 printf("PHYTxStatus: %04x ", txs
->phyerr
);
4734 printf("RxAckRSSI: %04x ",
4735 (ackphyrxsh
& PRXS1_JSSI_MASK
) >> PRXS1_JSSI_SHIFT
);
4736 printf("RxAckSQ: %04x", (ackphyrxsh
& PRXS1_SQ_MASK
) >> PRXS1_SQ_SHIFT
);
4738 #endif /* defined(BCMDBG) */
4741 #define MACSTATUPD(name) \
4742 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4744 void wlc_statsupd(struct wlc_info
*wlc
)
4753 /* if driver down, make no sense to update stats */
4758 /* save last rx fifo 0 overflow count */
4759 rxf0ovfl
= wlc
->core
->macstat_snapshot
->rxf0ovfl
;
4761 /* save last tx fifo underflow count */
4762 for (i
= 0; i
< NFIFO
; i
++)
4763 txfunfl
[i
] = wlc
->core
->macstat_snapshot
->txfunfl
[i
];
4767 /* check for rx fifo 0 overflow */
4768 delta
= (u16
) (wlc
->core
->macstat_snapshot
->rxf0ovfl
- rxf0ovfl
);
4770 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4771 wlc
->pub
->unit
, delta
);
4773 /* check for tx fifo underflows */
4774 for (i
= 0; i
< NFIFO
; i
++) {
4776 (u16
) (wlc
->core
->macstat_snapshot
->txfunfl
[i
] -
4779 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4780 wlc
->pub
->unit
, delta
, i
);
4784 /* dot11 counter update */
4786 WLCNTSET(wlc
->pub
->_cnt
->txrts
,
4787 (wlc
->pub
->_cnt
->rxctsucast
-
4788 wlc
->pub
->_cnt
->d11cnt_txrts_off
));
4789 WLCNTSET(wlc
->pub
->_cnt
->rxcrc
,
4790 (wlc
->pub
->_cnt
->rxbadfcs
- wlc
->pub
->_cnt
->d11cnt_rxcrc_off
));
4791 WLCNTSET(wlc
->pub
->_cnt
->txnocts
,
4792 ((wlc
->pub
->_cnt
->txrtsfrm
- wlc
->pub
->_cnt
->rxctsucast
) -
4793 wlc
->pub
->_cnt
->d11cnt_txnocts_off
));
4795 /* merge counters from dma module */
4796 for (i
= 0; i
< NFIFO
; i
++) {
4797 if (wlc
->hw
->di
[i
]) {
4798 WLCNTADD(wlc
->pub
->_cnt
->txnobuf
,
4799 (wlc
->hw
->di
[i
])->txnobuf
);
4800 WLCNTADD(wlc
->pub
->_cnt
->rxnobuf
,
4801 (wlc
->hw
->di
[i
])->rxnobuf
);
4802 WLCNTADD(wlc
->pub
->_cnt
->rxgiant
,
4803 (wlc
->hw
->di
[i
])->rxgiants
);
4804 dma_counterreset(wlc
->hw
->di
[i
]);
4809 * Aggregate transmit and receive errors that probably resulted
4810 * in the loss of a frame are computed on the fly.
4812 WLCNTSET(wlc
->pub
->_cnt
->txerror
,
4813 wlc
->pub
->_cnt
->txnobuf
+ wlc
->pub
->_cnt
->txnoassoc
+
4814 wlc
->pub
->_cnt
->txuflo
+ wlc
->pub
->_cnt
->txrunt
+
4815 wlc
->pub
->_cnt
->dmade
+ wlc
->pub
->_cnt
->dmada
+
4816 wlc
->pub
->_cnt
->dmape
);
4817 WLCNTSET(wlc
->pub
->_cnt
->rxerror
,
4818 wlc
->pub
->_cnt
->rxoflo
+ wlc
->pub
->_cnt
->rxnobuf
+
4819 wlc
->pub
->_cnt
->rxfragerr
+ wlc
->pub
->_cnt
->rxrunt
+
4820 wlc
->pub
->_cnt
->rxgiant
+ wlc
->pub
->_cnt
->rxnoscb
+
4821 wlc
->pub
->_cnt
->rxbadsrcmac
);
4822 for (i
= 0; i
< NFIFO
; i
++)
4823 WLCNTADD(wlc
->pub
->_cnt
->rxerror
, wlc
->pub
->_cnt
->rxuflo
[i
]);
4826 bool wlc_chipmatch(u16 vendor
, u16 device
)
4828 if (vendor
!= VENDOR_BROADCOM
) {
4829 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor
);
4833 if ((device
== BCM43224_D11N_ID
) || (device
== BCM43225_D11N2G_ID
))
4836 if (device
== BCM4313_D11N2G_ID
)
4838 if ((device
== BCM43236_D11N_ID
) || (device
== BCM43236_D11N2G_ID
))
4841 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device
);
4846 void wlc_print_txdesc(d11txh_t
*txh
)
4848 u16 mtcl
= ltoh16(txh
->MacTxControlLow
);
4849 u16 mtch
= ltoh16(txh
->MacTxControlHigh
);
4850 u16 mfc
= ltoh16(txh
->MacFrameControl
);
4851 u16 tfest
= ltoh16(txh
->TxFesTimeNormal
);
4852 u16 ptcw
= ltoh16(txh
->PhyTxControlWord
);
4853 u16 ptcw_1
= ltoh16(txh
->PhyTxControlWord_1
);
4854 u16 ptcw_1_Fbr
= ltoh16(txh
->PhyTxControlWord_1_Fbr
);
4855 u16 ptcw_1_Rts
= ltoh16(txh
->PhyTxControlWord_1_Rts
);
4856 u16 ptcw_1_FbrRts
= ltoh16(txh
->PhyTxControlWord_1_FbrRts
);
4857 u16 mainrates
= ltoh16(txh
->MainRates
);
4858 u16 xtraft
= ltoh16(txh
->XtraFrameTypes
);
4860 u8
*ra
= txh
->TxFrameRA
;
4861 u16 tfestfb
= ltoh16(txh
->TxFesTimeFallback
);
4862 u8
*rtspfb
= txh
->RTSPLCPFallback
;
4863 u16 rtsdfb
= ltoh16(txh
->RTSDurFallback
);
4864 u8
*fragpfb
= txh
->FragPLCPFallback
;
4865 u16 fragdfb
= ltoh16(txh
->FragDurFallback
);
4866 u16 mmodelen
= ltoh16(txh
->MModeLen
);
4867 u16 mmodefbrlen
= ltoh16(txh
->MModeFbrLen
);
4868 u16 tfid
= ltoh16(txh
->TxFrameID
);
4869 u16 txs
= ltoh16(txh
->TxStatus
);
4870 u16 mnmpdu
= ltoh16(txh
->MaxNMpdus
);
4871 u16 mabyte
= ltoh16(txh
->MaxABytes_MRT
);
4872 u16 mabyte_f
= ltoh16(txh
->MaxABytes_FBR
);
4873 u16 mmbyte
= ltoh16(txh
->MinMBytes
);
4875 u8
*rtsph
= txh
->RTSPhyHeader
;
4876 struct ieee80211_rts rts
= txh
->rts_frame
;
4879 /* add plcp header along with txh descriptor */
4880 prhex("Raw TxDesc + plcp header", (unsigned char *) txh
, sizeof(d11txh_t
) + 48);
4882 printf("TxCtlLow: %04x ", mtcl
);
4883 printf("TxCtlHigh: %04x ", mtch
);
4884 printf("FC: %04x ", mfc
);
4885 printf("FES Time: %04x\n", tfest
);
4886 printf("PhyCtl: %04x%s ", ptcw
,
4887 (ptcw
& PHY_TXC_SHORT_HDR
) ? " short" : "");
4888 printf("PhyCtl_1: %04x ", ptcw_1
);
4889 printf("PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr
);
4890 printf("PhyCtl_1_Rts: %04x ", ptcw_1_Rts
);
4891 printf("PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts
);
4892 printf("MainRates: %04x ", mainrates
);
4893 printf("XtraFrameTypes: %04x ", xtraft
);
4896 bcm_format_hex(hexbuf
, iv
, sizeof(txh
->IV
));
4897 printf("SecIV: %s\n", hexbuf
);
4898 bcm_format_hex(hexbuf
, ra
, sizeof(txh
->TxFrameRA
));
4899 printf("RA: %s\n", hexbuf
);
4901 printf("Fb FES Time: %04x ", tfestfb
);
4902 bcm_format_hex(hexbuf
, rtspfb
, sizeof(txh
->RTSPLCPFallback
));
4903 printf("RTS PLCP: %s ", hexbuf
);
4904 printf("RTS DUR: %04x ", rtsdfb
);
4905 bcm_format_hex(hexbuf
, fragpfb
, sizeof(txh
->FragPLCPFallback
));
4906 printf("PLCP: %s ", hexbuf
);
4907 printf("DUR: %04x", fragdfb
);
4910 printf("MModeLen: %04x ", mmodelen
);
4911 printf("MModeFbrLen: %04x\n", mmodefbrlen
);
4913 printf("FrameID: %04x\n", tfid
);
4914 printf("TxStatus: %04x\n", txs
);
4916 printf("MaxNumMpdu: %04x\n", mnmpdu
);
4917 printf("MaxAggbyte: %04x\n", mabyte
);
4918 printf("MaxAggbyte_fb: %04x\n", mabyte_f
);
4919 printf("MinByte: %04x\n", mmbyte
);
4921 bcm_format_hex(hexbuf
, rtsph
, sizeof(txh
->RTSPhyHeader
));
4922 printf("RTS PLCP: %s ", hexbuf
);
4923 bcm_format_hex(hexbuf
, (u8
*) &rts
, sizeof(txh
->rts_frame
));
4924 printf("RTS Frame: %s", hexbuf
);
4928 #endif /* defined(BCMDBG) */
4931 void wlc_print_rxh(d11rxhdr_t
*rxh
)
4933 u16 len
= rxh
->RxFrameSize
;
4934 u16 phystatus_0
= rxh
->PhyRxStatus_0
;
4935 u16 phystatus_1
= rxh
->PhyRxStatus_1
;
4936 u16 phystatus_2
= rxh
->PhyRxStatus_2
;
4937 u16 phystatus_3
= rxh
->PhyRxStatus_3
;
4938 u16 macstatus1
= rxh
->RxStatus1
;
4939 u16 macstatus2
= rxh
->RxStatus2
;
4942 static const bcm_bit_desc_t macstat_flags
[] = {
4943 {RXS_FCSERR
, "FCSErr"},
4944 {RXS_RESPFRAMETX
, "Reply"},
4945 {RXS_PBPRES
, "PADDING"},
4946 {RXS_DECATMPT
, "DeCr"},
4947 {RXS_DECERR
, "DeCrErr"},
4948 {RXS_BCNSENT
, "Bcn"},
4952 prhex("Raw RxDesc", (unsigned char *) rxh
, sizeof(d11rxhdr_t
));
4954 bcm_format_flags(macstat_flags
, macstatus1
, flagstr
, 64);
4956 snprintf(lenbuf
, sizeof(lenbuf
), "0x%x", len
);
4958 printf("RxFrameSize: %6s (%d)%s\n", lenbuf
, len
,
4959 (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
) ? " short preamble" : "");
4960 printf("RxPHYStatus: %04x %04x %04x %04x\n",
4961 phystatus_0
, phystatus_1
, phystatus_2
, phystatus_3
);
4962 printf("RxMACStatus: %x %s\n", macstatus1
, flagstr
);
4963 printf("RXMACaggtype: %x\n", (macstatus2
& RXS_AGGTYPE_MASK
));
4964 printf("RxTSFTime: %04x\n", rxh
->RxTSFTime
);
4966 #endif /* defined(BCMDBG) */
4969 int wlc_format_ssid(char *buf
, const unsigned char ssid
[], uint ssid_len
)
4973 char *endp
= buf
+ SSID_FMT_BUF_LEN
;
4975 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
4976 ssid_len
= IEEE80211_MAX_SSID_LEN
;
4978 for (i
= 0; i
< ssid_len
; i
++) {
4983 } else if (isprint((unsigned char) c
)) {
4986 p
+= snprintf(p
, (endp
- p
), "\\x%02X", c
);
4992 return (int)(p
- buf
);
4994 #endif /* defined(BCMDBG) */
4996 u16
wlc_rate_shm_offset(struct wlc_info
*wlc
, u8 rate
)
4998 return wlc_bmac_rate_shm_offset(wlc
->hw
, rate
);
5001 /* Callback for device removed */
5004 * Attempts to queue a packet onto a multiple-precedence queue,
5005 * if necessary evicting a lower precedence packet from the queue.
5007 * 'prec' is the precedence number that has already been mapped
5008 * from the packet priority.
5010 * Returns true if packet consumed (queued), false if not.
5013 wlc_prec_enq(struct wlc_info
*wlc
, struct pktq
*q
, void *pkt
, int prec
)
5015 return wlc_prec_enq_head(wlc
, q
, pkt
, prec
, false);
5019 wlc_prec_enq_head(struct wlc_info
*wlc
, struct pktq
*q
, struct sk_buff
*pkt
,
5020 int prec
, bool head
)
5023 int eprec
= -1; /* precedence to evict from */
5025 /* Determine precedence from which to evict packet, if any */
5026 if (pktq_pfull(q
, prec
))
5028 else if (pktq_full(q
)) {
5029 p
= pktq_peek_tail(q
, &eprec
);
5032 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5033 __func__
, eprec
, prec
);
5038 /* Evict if needed */
5040 bool discard_oldest
;
5042 /* Detect queueing to unconfigured precedence */
5043 ASSERT(!pktq_pempty(q
, eprec
));
5045 discard_oldest
= AC_BITMAP_TST(wlc
->wme_dp
, eprec
);
5047 /* Refuse newer packet unless configured to discard oldest */
5048 if (eprec
== prec
&& !discard_oldest
) {
5049 WL_ERROR("%s: No where to go, prec == %d\n",
5054 /* Evict packet according to discard policy */
5055 p
= discard_oldest
? pktq_pdeq(q
, eprec
) : pktq_pdeq_tail(q
,
5059 /* Increment wme stats */
5060 if (WME_ENAB(wlc
->pub
)) {
5061 WLCNTINCR(wlc
->pub
->_wme_cnt
->
5062 tx_failed
[WME_PRIO2AC(p
->priority
)].packets
);
5063 WLCNTADD(wlc
->pub
->_wme_cnt
->
5064 tx_failed
[WME_PRIO2AC(p
->priority
)].bytes
,
5065 pkttotlen(wlc
->osh
, p
));
5069 pkt_buf_free_skb(wlc
->osh
, p
, true);
5070 WLCNTINCR(wlc
->pub
->_cnt
->txnobuf
);
5075 p
= pktq_penq_head(q
, prec
, pkt
);
5077 p
= pktq_penq(q
, prec
, pkt
);
5083 void BCMFASTPATH
wlc_txq_enq(void *ctx
, struct scb
*scb
, struct sk_buff
*sdu
,
5086 struct wlc_info
*wlc
= (struct wlc_info
*) ctx
;
5087 wlc_txq_info_t
*qi
= wlc
->active_queue
; /* Check me */
5088 struct pktq
*q
= &qi
->q
;
5091 prio
= sdu
->priority
;
5093 ASSERT(pktq_max(q
) >= wlc
->pub
->tunables
->datahiwat
);
5095 if (!wlc_prec_enq(wlc
, q
, sdu
, prec
)) {
5096 if (!EDCF_ENAB(wlc
->pub
)
5097 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
))
5098 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5101 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5102 pkt_buf_free_skb(wlc
->osh
, sdu
, true);
5103 WLCNTINCR(wlc
->pub
->_cnt
->txnobuf
);
5106 /* Check if flow control needs to be turned on after enqueuing the packet
5107 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5108 * to drop instead of relying on stack to make the right decision
5110 if (!EDCF_ENAB(wlc
->pub
)
5111 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5112 if (pktq_len(q
) >= wlc
->pub
->tunables
->datahiwat
) {
5113 wlc_txflowcontrol(wlc
, qi
, ON
, ALLPRIO
);
5115 } else if (wlc
->pub
->_priofc
) {
5116 if (pktq_plen(q
, wlc_prio2prec_map
[prio
]) >=
5117 wlc
->pub
->tunables
->datahiwat
) {
5118 wlc_txflowcontrol(wlc
, qi
, ON
, prio
);
5124 wlc_sendpkt_mac80211(struct wlc_info
*wlc
, struct sk_buff
*sdu
,
5125 struct ieee80211_hw
*hw
)
5130 struct scb
*scb
= &global_scb
;
5131 struct ieee80211_hdr
*d11_header
= (struct ieee80211_hdr
*)(sdu
->data
);
5136 fc
= ltoh16(d11_header
->frame_control
);
5137 type
= (fc
& IEEE80211_FCTL_FTYPE
);
5139 /* 802.11 standard requires management traffic to go at highest priority */
5140 prio
= (type
== IEEE80211_FTYPE_DATA
? sdu
->priority
: MAXPRIO
);
5141 fifo
= prio2fifo
[prio
];
5143 ASSERT((uint
) skb_headroom(sdu
) >= TXOFF
);
5144 ASSERT(!(sdu
->next
));
5145 ASSERT(!(sdu
->prev
));
5146 ASSERT(fifo
< NFIFO
);
5150 (wlc_d11hdrs_mac80211(wlc
, hw
, pkt
, scb
, 0, 1, fifo
, 0, NULL
, 0)))
5152 wlc_txq_enq(wlc
, scb
, pkt
, WLC_PRIO_TO_PREC(prio
));
5153 wlc_send_q(wlc
, wlc
->active_queue
);
5155 WLCNTINCR(wlc
->pub
->_cnt
->ieee_tx
);
5159 void BCMFASTPATH
wlc_send_q(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
)
5161 struct sk_buff
*pkt
[DOT11_MAXNUMFRAGS
];
5164 int err
= 0, i
, count
;
5166 struct pktq
*q
= &qi
->q
;
5167 struct ieee80211_tx_info
*tx_info
;
5169 /* only do work for the active queue */
5170 if (qi
!= wlc
->active_queue
)
5178 prec_map
= wlc
->tx_prec_map
;
5180 /* Send all the enq'd pkts that we can.
5181 * Dequeue packets with precedence with empty HW fifo only
5183 while (prec_map
&& (pkt
[0] = pktq_mdeq(q
, prec_map
, &prec
))) {
5184 tx_info
= IEEE80211_SKB_CB(pkt
[0]);
5185 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
5186 err
= wlc_sendampdu(wlc
->ampdu
, qi
, pkt
, prec
);
5189 err
= wlc_prep_pdu(wlc
, pkt
[0], &fifo
);
5191 for (i
= 0; i
< count
; i
++) {
5192 wlc_txfifo(wlc
, fifo
, pkt
[i
], true, 1);
5197 if (err
== BCME_BUSY
) {
5198 pktq_penq_head(q
, prec
, pkt
[0]);
5199 /* If send failed due to any other reason than a change in
5200 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5202 if (prec_map
== wlc
->tx_prec_map
)
5204 prec_map
= wlc
->tx_prec_map
;
5208 /* Check if flow control needs to be turned off after sending the packet */
5209 if (!EDCF_ENAB(wlc
->pub
)
5210 || (wlc
->pub
->wlfeatureflag
& WL_SWFL_FLOWCONTROL
)) {
5211 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, ALLPRIO
)
5212 && (pktq_len(q
) < wlc
->pub
->tunables
->datahiwat
/ 2)) {
5213 wlc_txflowcontrol(wlc
, qi
, OFF
, ALLPRIO
);
5215 } else if (wlc
->pub
->_priofc
) {
5217 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
5218 if (wlc_txflowcontrol_prio_isset(wlc
, qi
, prio
) &&
5219 (pktq_plen(q
, wlc_prio2prec_map
[prio
]) <
5220 wlc
->pub
->tunables
->datahiwat
/ 2)) {
5221 wlc_txflowcontrol(wlc
, qi
, OFF
, prio
);
5229 * bcmc_fid_generate:
5230 * Generate frame ID for a BCMC packet. The frag field is not used
5231 * for MC frames so is used as part of the sequence number.
5234 bcmc_fid_generate(struct wlc_info
*wlc
, wlc_bsscfg_t
*bsscfg
, d11txh_t
*txh
)
5238 frameid
= ltoh16(txh
->TxFrameID
) & ~(TXFID_SEQ_MASK
| TXFID_QUEUE_MASK
);
5241 mc_fid_counter
++) << TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5248 wlc_txfifo(struct wlc_info
*wlc
, uint fifo
, struct sk_buff
*p
, bool commit
,
5251 u16 frameid
= INVALIDFID
;
5254 ASSERT(fifo
< NFIFO
);
5255 txh
= (d11txh_t
*) (p
->data
);
5257 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5258 * ucode or BSS info as appropriate.
5260 if (fifo
== TX_BCMC_FIFO
) {
5261 frameid
= ltoh16(txh
->TxFrameID
);
5265 if (WLC_WAR16165(wlc
))
5266 wlc_war16165(wlc
, true);
5269 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5270 * in wlc_bmac_txfifo()
5273 TXPKTPENDINC(wlc
, fifo
, txpktpend
);
5274 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5275 txpktpend
, TXPKTPENDGET(wlc
, fifo
));
5278 /* Commit BCMC sequence number in the SHM frame ID location */
5279 if (frameid
!= INVALIDFID
)
5280 BCMCFID(wlc
, frameid
);
5282 if (dma_txfast(wlc
->hw
->di
[fifo
], p
, commit
) < 0) {
5283 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5288 wlc_compute_airtime(struct wlc_info
*wlc
, ratespec_t rspec
, uint length
)
5291 uint mac_rate
= RSPEC2RATE(rspec
);
5294 if (IS_MCS(rspec
)) {
5295 /* not supported yet */
5297 } else if (IS_OFDM(rspec
)) {
5298 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5300 * Nbits = length * 8
5301 * Nbits/sym = Mbps * 4 = mac_rate * 2
5303 nsyms
= CEIL((length
* 8), (mac_rate
* 2));
5305 /* usec = symbols * usec/symbol */
5306 usec
= (u16
) (nsyms
* APHY_SYMBOL_TIME
);
5317 usec
= (length
<< 4) / 11;
5320 usec
= (length
<< 3) / 11;
5323 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5324 wlc
->pub
->unit
, rspec
);
5325 ASSERT((const char *)"Bad phy_rate" == NULL
);
5334 wlc_compute_plcp(struct wlc_info
*wlc
, ratespec_t rspec
, uint length
, u8
*plcp
)
5336 if (IS_MCS(rspec
)) {
5337 wlc_compute_mimo_plcp(rspec
, length
, plcp
);
5338 } else if (IS_OFDM(rspec
)) {
5339 wlc_compute_ofdm_plcp(rspec
, length
, plcp
);
5341 wlc_compute_cck_plcp(rspec
, length
, plcp
);
5346 /* Rate: 802.11 rate code, length: PSDU length in octets */
5347 static void wlc_compute_mimo_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5349 u8 mcs
= (u8
) (rspec
& RSPEC_RATE_MASK
);
5350 ASSERT(IS_MCS(rspec
));
5352 if (RSPEC_IS40MHZ(rspec
) || (mcs
== 32))
5353 plcp
[0] |= MIMO_PLCP_40MHZ
;
5354 WLC_SET_MIMO_PLCP_LEN(plcp
, length
);
5355 plcp
[3] = RSPEC_MIMOPLCP3(rspec
); /* rspec already holds this byte */
5356 plcp
[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5357 plcp
[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5361 /* Rate: 802.11 rate code, length: PSDU length in octets */
5362 static void BCMFASTPATH
5363 wlc_compute_ofdm_plcp(ratespec_t rspec
, u32 length
, u8
*plcp
)
5367 int rate
= RSPEC2RATE(rspec
);
5369 ASSERT(IS_OFDM(rspec
));
5371 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5372 rate_signal
= rate_info
[rate
] & RATE_MASK
;
5373 ASSERT(rate_signal
!= 0);
5375 memset(plcp
, 0, D11_PHY_HDR_LEN
);
5376 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t
*) plcp
, rate_signal
);
5378 tmp
= (length
& 0xfff) << 5;
5379 plcp
[2] |= (tmp
>> 16) & 0xff;
5380 plcp
[1] |= (tmp
>> 8) & 0xff;
5381 plcp
[0] |= tmp
& 0xff;
5387 * Compute PLCP, but only requires actual rate and length of pkt.
5388 * Rate is given in the driver standard multiple of 500 kbps.
5389 * le is set for 11 Mbps rate if necessary.
5390 * Broken out for PRQ.
5393 static void wlc_cck_plcp_set(int rate_500
, uint length
, u8
*plcp
)
5406 usec
= (length
<< 4) / 11;
5407 if ((length
<< 4) - (usec
* 11) > 0)
5411 usec
= (length
<< 3) / 11;
5412 if ((length
<< 3) - (usec
* 11) > 0) {
5414 if ((usec
* 11) - (length
<< 3) >= 8)
5415 le
= D11B_PLCP_SIGNAL_LE
;
5420 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500
);
5421 rate_500
= WLC_RATE_1M
;
5425 /* PLCP signal byte */
5426 plcp
[0] = rate_500
* 5; /* r (500kbps) * 5 == r (100kbps) */
5427 /* PLCP service byte */
5428 plcp
[1] = (u8
) (le
| D11B_PLCP_SIGNAL_LOCKED
);
5429 /* PLCP length u16, little endian */
5430 plcp
[2] = usec
& 0xff;
5431 plcp
[3] = (usec
>> 8) & 0xff;
5437 /* Rate: 802.11 rate code, length: PSDU length in octets */
5438 static void wlc_compute_cck_plcp(ratespec_t rspec
, uint length
, u8
*plcp
)
5440 int rate
= RSPEC2RATE(rspec
);
5442 ASSERT(IS_CCK(rspec
));
5444 wlc_cck_plcp_set(rate
, length
, plcp
);
5447 /* wlc_compute_frame_dur()
5449 * Calculate the 802.11 MAC header DUR field for MPDU
5450 * DUR for a single frame = 1 SIFS + 1 ACK
5451 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5453 * rate MPDU rate in unit of 500kbps
5454 * next_frag_len next MPDU length in bytes
5455 * preamble_type use short/GF or long/MM PLCP header
5457 static u16 BCMFASTPATH
5458 wlc_compute_frame_dur(struct wlc_info
*wlc
, ratespec_t rate
, u8 preamble_type
,
5463 sifs
= SIFS(wlc
->band
);
5466 dur
+= (u16
) wlc_calc_ack_time(wlc
, rate
, preamble_type
);
5468 if (next_frag_len
) {
5469 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5471 /* add another SIFS and the frag time */
5474 (u16
) wlc_calc_frame_time(wlc
, rate
, preamble_type
,
5480 /* wlc_compute_rtscts_dur()
5482 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5483 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5484 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5486 * cts cts-to-self or rts/cts
5487 * rts_rate rts or cts rate in unit of 500kbps
5488 * rate next MPDU rate in unit of 500kbps
5489 * frame_len next MPDU frame length in bytes
5492 wlc_compute_rtscts_dur(struct wlc_info
*wlc
, bool cts_only
, ratespec_t rts_rate
,
5493 ratespec_t frame_rate
, u8 rts_preamble_type
,
5494 u8 frame_preamble_type
, uint frame_len
, bool ba
)
5498 sifs
= SIFS(wlc
->band
);
5500 if (!cts_only
) { /* RTS/CTS */
5503 (u16
) wlc_calc_cts_time(wlc
, rts_rate
,
5505 } else { /* CTS-TO-SELF */
5510 (u16
) wlc_calc_frame_time(wlc
, frame_rate
, frame_preamble_type
,
5514 (u16
) wlc_calc_ba_time(wlc
, frame_rate
,
5515 WLC_SHORT_PREAMBLE
);
5518 (u16
) wlc_calc_ack_time(wlc
, frame_rate
,
5519 frame_preamble_type
);
5523 static bool wlc_phy_rspec_check(struct wlc_info
*wlc
, u16 bw
, ratespec_t rspec
)
5525 if (IS_MCS(rspec
)) {
5526 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5529 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5530 } else if ((mcs
>= 8) && (mcs
<= 23)) {
5531 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SDM
);
5532 } else if (mcs
== 32) {
5533 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_SDM
);
5534 ASSERT(bw
== PHY_TXC1_BW_40MHZ_DUP
);
5536 } else if (IS_OFDM(rspec
)) {
5537 ASSERT(RSPEC_STF(rspec
) < PHY_TXC1_MODE_STBC
);
5539 ASSERT(IS_CCK(rspec
));
5541 ASSERT((bw
== PHY_TXC1_BW_20MHZ
)
5542 || (bw
== PHY_TXC1_BW_20MHZ_UP
));
5543 ASSERT(RSPEC_STF(rspec
) == PHY_TXC1_MODE_SISO
);
5549 u16 BCMFASTPATH
wlc_phytxctl1_calc(struct wlc_info
*wlc
, ratespec_t rspec
)
5554 if (WLCISLCNPHY(wlc
->band
)) {
5555 bw
= PHY_TXC1_BW_20MHZ
;
5557 bw
= RSPEC_GET_BW(rspec
);
5558 /* 10Mhz is not supported yet */
5559 if (bw
< PHY_TXC1_BW_20MHZ
) {
5560 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5562 bw
= PHY_TXC1_BW_20MHZ
;
5565 wlc_phy_rspec_check(wlc
, bw
, rspec
);
5568 if (IS_MCS(rspec
)) {
5569 uint mcs
= rspec
& RSPEC_RATE_MASK
;
5571 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5572 phyctl1
= RSPEC_PHYTXBYTE2(rspec
);
5573 /* set the upper byte of phyctl1 */
5574 phyctl1
|= (mcs_table
[mcs
].tx_phy_ctl3
<< 8);
5575 } else if (IS_CCK(rspec
) && !WLCISLCNPHY(wlc
->band
)
5576 && !WLCISSSLPNPHY(wlc
->band
)) {
5577 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5578 /* Eventually MIMOPHY would also be converted to this format */
5579 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5580 phyctl1
= (bw
| (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5581 } else { /* legacy OFDM/CCK */
5583 /* get the phyctl byte from rate phycfg table */
5584 phycfg
= wlc_rate_legacy_phyctl(RSPEC2RATE(rspec
));
5586 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5590 /* set the upper byte of phyctl1 */
5592 (bw
| (phycfg
<< 8) |
5593 (RSPEC_STF(rspec
) << PHY_TXC1_MODE_SHIFT
));
5597 /* phy clock must support 40Mhz if tx descriptor uses it */
5598 if ((phyctl1
& PHY_TXC1_BW_MASK
) >= PHY_TXC1_BW_40MHZ
) {
5599 ASSERT(CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
);
5600 ASSERT(wlc
->chanspec
== wlc_phy_chanspec_get(wlc
->band
->pi
));
5606 ratespec_t BCMFASTPATH
5607 wlc_rspec_to_rts_rspec(struct wlc_info
*wlc
, ratespec_t rspec
, bool use_rspec
,
5610 ratespec_t rts_rspec
= 0;
5613 /* use frame rate as rts rate */
5616 } else if (wlc
->band
->gmode
&& wlc
->protection
->_g
&& !IS_CCK(rspec
)) {
5617 /* Use 11Mbps as the g protection RTS target rate and fallback.
5618 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5619 * target in case 11 Mbps is not Basic.
5620 * 6 and 9 Mbps are not usually selected by rate selection, but even
5621 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5623 rts_rspec
= WLC_BASIC_RATE(wlc
, WLC_RATE_11M
);
5625 /* calculate RTS rate and fallback rate based on the frame rate
5626 * RTS must be sent at a basic rate since it is a
5627 * control frame, sec 9.6 of 802.11 spec
5629 rts_rspec
= WLC_BASIC_RATE(wlc
, rspec
);
5632 if (WLC_PHY_11N_CAP(wlc
->band
)) {
5633 /* set rts txbw to correct side band */
5634 rts_rspec
&= ~RSPEC_BW_MASK
;
5636 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5637 * (DUP), otherwise send RTS on control channel
5639 if (RSPEC_IS40MHZ(rspec
) && !IS_CCK(rts_rspec
))
5640 rts_rspec
|= (PHY_TXC1_BW_40MHZ_DUP
<< RSPEC_BW_SHIFT
);
5642 rts_rspec
|= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5644 /* pick siso/cdd as default for ofdm */
5645 if (IS_OFDM(rts_rspec
)) {
5646 rts_rspec
&= ~RSPEC_STF_MASK
;
5647 rts_rspec
|= (wlc
->stf
->ss_opmode
<< RSPEC_STF_SHIFT
);
5654 * Add d11txh_t, cck_phy_hdr_t.
5656 * 'p' data must start with 802.11 MAC header
5657 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5659 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5662 static u16 BCMFASTPATH
5663 wlc_d11hdrs_mac80211(struct wlc_info
*wlc
, struct ieee80211_hw
*hw
,
5664 struct sk_buff
*p
, struct scb
*scb
, uint frag
,
5665 uint nfrags
, uint queue
, uint next_frag_len
,
5666 wsec_key_t
*key
, ratespec_t rspec_override
)
5668 struct ieee80211_hdr
*h
;
5670 u8
*plcp
, plcp_fallback
[D11_PHY_HDR_LEN
];
5671 struct osl_info
*osh
;
5672 int len
, phylen
, rts_phylen
;
5673 u16 fc
, type
, frameid
, mch
, phyctl
, xfts
, mainrates
;
5674 u16 seq
= 0, mcl
= 0, status
= 0;
5675 ratespec_t rspec
[2] = { WLC_RATE_1M
, WLC_RATE_1M
}, rts_rspec
[2] = {
5676 WLC_RATE_1M
, WLC_RATE_1M
};
5677 bool use_rts
= false;
5678 bool use_cts
= false;
5679 bool use_rifs
= false;
5680 bool short_preamble
[2] = { false, false };
5681 u8 preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5682 u8 rts_preamble_type
[2] = { WLC_LONG_PREAMBLE
, WLC_LONG_PREAMBLE
};
5683 u8
*rts_plcp
, rts_plcp_fallback
[D11_PHY_HDR_LEN
];
5684 struct ieee80211_rts
*rts
= NULL
;
5688 bool hwtkmic
= false;
5689 u16 mimo_ctlchbw
= PHY_TXC1_BW_20MHZ
;
5691 #define ANTCFG_NONE 0xFF
5692 u8 antcfg
= ANTCFG_NONE
;
5693 u8 fbantcfg
= ANTCFG_NONE
;
5695 uint phyctl1_stf
= 0;
5697 struct ieee80211_tx_rate
*txrate
[2];
5699 struct ieee80211_tx_info
*tx_info
;
5702 u8 mimo_preamble_type
;
5706 ASSERT(queue
< NFIFO
);
5710 /* locate 802.11 MAC header */
5711 h
= (struct ieee80211_hdr
*)(p
->data
);
5712 fc
= ltoh16(h
->frame_control
);
5713 type
= (fc
& IEEE80211_FCTL_FTYPE
);
5715 qos
= (type
== IEEE80211_FTYPE_DATA
&&
5716 FC_SUBTYPE_ANY_QOS(fc
));
5718 /* compute length of frame in bytes for use in PLCP computations */
5719 len
= pkttotlen(osh
, p
);
5720 phylen
= len
+ FCS_LEN
;
5722 /* If WEP enabled, add room in phylen for the additional bytes of
5723 * ICV which MAC generates. We do NOT add the additional bytes to
5724 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5728 phylen
+= key
->icv_len
;
5732 tx_info
= IEEE80211_SKB_CB(p
);
5736 plcp
= skb_push(p
, D11_PHY_HDR_LEN
);
5738 /* add Broadcom tx descriptor header */
5739 txh
= (d11txh_t
*) skb_push(p
, D11_TXH_LEN
);
5740 memset((char *)txh
, 0, D11_TXH_LEN
);
5743 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
5744 /* non-AP STA should never use BCMC queue */
5745 ASSERT(queue
!= TX_BCMC_FIFO
);
5746 if (queue
== TX_BCMC_FIFO
) {
5747 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5748 WLCWLUNIT(wlc
), __func__
);
5749 frameid
= bcmc_fid_generate(wlc
, NULL
, txh
);
5751 /* Increment the counter for first fragment */
5752 if (tx_info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
) {
5753 SCB_SEQNUM(scb
, p
->priority
)++;
5756 /* extract fragment number from frame first */
5757 seq
= ltoh16(seq
) & FRAGNUM_MASK
;
5758 seq
|= (SCB_SEQNUM(scb
, p
->priority
) << SEQNUM_SHIFT
);
5759 h
->seq_ctrl
= htol16(seq
);
5761 frameid
= ((seq
<< TXFID_SEQ_SHIFT
) & TXFID_SEQ_MASK
) |
5762 (queue
& TXFID_QUEUE_MASK
);
5765 frameid
|= queue
& TXFID_QUEUE_MASK
;
5767 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5768 if (SCB_PS(scb
) || ((fc
& FC_KIND_MASK
) == FC_BEACON
))
5769 mcl
|= TXC_IGNOREPMQ
;
5771 ASSERT(hw
->max_rates
<= IEEE80211_TX_MAX_RATES
);
5772 ASSERT(hw
->max_rates
== 2);
5774 txrate
[0] = tx_info
->control
.rates
;
5775 txrate
[1] = txrate
[0] + 1;
5777 ASSERT(txrate
[0]->idx
>= 0);
5778 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5779 if (txrate
[1]->idx
< 0) {
5780 txrate
[1] = txrate
[0];
5783 for (k
= 0; k
< hw
->max_rates
; k
++) {
5785 txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
? true : false;
5787 ASSERT(!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
));
5788 if ((txrate
[k
]->idx
>= 0)
5789 && (txrate
[k
]->idx
<
5790 hw
->wiphy
->bands
[tx_info
->band
]->n_bitrates
)) {
5792 hw
->wiphy
->bands
[tx_info
->band
]->
5793 bitrates
[txrate
[k
]->idx
].hw_value
;
5796 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
?
5799 ASSERT((txrate
[k
]->idx
>= 0) &&
5801 hw
->wiphy
->bands
[tx_info
->band
]->
5803 rate_val
[k
] = WLC_RATE_1M
;
5806 rate_val
[k
] = txrate
[k
]->idx
;
5808 /* Currently only support same setting for primay and fallback rates.
5809 * Unify flags for each rate into a single value for the frame
5813 flags
& IEEE80211_TX_RC_USE_RTS_CTS
? true : false;
5816 flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
? true : false;
5819 rate_val
[k
] |= NRATE_MCS_INUSE
;
5821 rspec
[k
] = mac80211_wlc_set_nrate(wlc
, wlc
->band
, rate_val
[k
]);
5823 /* (1) RATE: determine and validate primary rate and fallback rates */
5824 if (!RSPEC_ACTIVE(rspec
[k
])) {
5825 ASSERT(RSPEC_ACTIVE(rspec
[k
]));
5826 rspec
[k
] = WLC_RATE_1M
;
5828 if (WLANTSEL_ENAB(wlc
) &&
5829 !is_multicast_ether_addr(h
->addr1
)) {
5830 /* set tx antenna config */
5831 wlc_antsel_antcfg_get(wlc
->asi
, false, false, 0,
5832 0, &antcfg
, &fbantcfg
);
5837 phyctl1_stf
= wlc
->stf
->ss_opmode
;
5839 if (N_ENAB(wlc
->pub
)) {
5840 for (k
= 0; k
< hw
->max_rates
; k
++) {
5841 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5842 if (((IS_MCS(rspec
[k
]) &&
5843 IS_SINGLE_STREAM(rspec
[k
] & RSPEC_RATE_MASK
)) ||
5845 && ((rspec
[k
] & RSPEC_OVERRIDE_MCS_ONLY
)
5846 || !(rspec
[k
] & RSPEC_OVERRIDE
))) {
5847 rspec
[k
] &= ~(RSPEC_STF_MASK
| RSPEC_STC_MASK
);
5849 /* For SISO MCS use STBC if possible */
5850 if (IS_MCS(rspec
[k
])
5851 && WLC_STF_SS_STBC_TX(wlc
, scb
)) {
5854 ASSERT(WLC_STBC_CAP_PHY(wlc
));
5855 stc
= 1; /* Nss for single stream is always 1 */
5857 (PHY_TXC1_MODE_STBC
<<
5858 RSPEC_STF_SHIFT
) | (stc
<<
5862 (phyctl1_stf
<< RSPEC_STF_SHIFT
);
5865 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5866 if (CHSPEC_WLC_BW(wlc
->chanspec
) == WLC_40_MHZ
) {
5867 /* default txbw is 20in40 SB */
5868 mimo_ctlchbw
= mimo_txbw
=
5869 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC
)
5870 ? PHY_TXC1_BW_20MHZ_UP
: PHY_TXC1_BW_20MHZ
;
5872 if (IS_MCS(rspec
[k
])) {
5873 /* mcs 32 must be 40b/w DUP */
5874 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
5876 PHY_TXC1_BW_40MHZ_DUP
;
5878 } else if (wlc
->mimo_40txbw
!= AUTO
)
5879 mimo_txbw
= wlc
->mimo_40txbw
;
5880 /* else check if dst is using 40 Mhz */
5881 else if (scb
->flags
& SCB_IS40
)
5882 mimo_txbw
= PHY_TXC1_BW_40MHZ
;
5883 } else if (IS_OFDM(rspec
[k
])) {
5884 if (wlc
->ofdm_40txbw
!= AUTO
)
5885 mimo_txbw
= wlc
->ofdm_40txbw
;
5887 ASSERT(IS_CCK(rspec
[k
]));
5888 if (wlc
->cck_40txbw
!= AUTO
)
5889 mimo_txbw
= wlc
->cck_40txbw
;
5892 /* mcs32 is 40 b/w only.
5893 * This is possible for probe packets on a STA during SCAN
5895 if ((rspec
[k
] & RSPEC_RATE_MASK
) == 32) {
5897 rspec
[k
] = RSPEC_MIMORATE
;
5899 mimo_txbw
= PHY_TXC1_BW_20MHZ
;
5902 /* Set channel width */
5903 rspec
[k
] &= ~RSPEC_BW_MASK
;
5904 if ((k
== 0) || ((k
> 0) && IS_MCS(rspec
[k
])))
5905 rspec
[k
] |= (mimo_txbw
<< RSPEC_BW_SHIFT
);
5907 rspec
[k
] |= (mimo_ctlchbw
<< RSPEC_BW_SHIFT
);
5911 if (IS_MCS(rspec
[k
])
5912 && (txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
5913 rspec
[k
] |= RSPEC_SHORT_GI
;
5914 else if (!(txrate
[k
]->flags
& IEEE80211_TX_RC_SHORT_GI
))
5915 rspec
[k
] &= ~RSPEC_SHORT_GI
;
5917 rspec
[k
] &= ~RSPEC_SHORT_GI
;
5920 mimo_preamble_type
= WLC_MM_PREAMBLE
;
5921 if (txrate
[k
]->flags
& IEEE80211_TX_RC_GREEN_FIELD
)
5922 mimo_preamble_type
= WLC_GF_PREAMBLE
;
5924 if ((txrate
[k
]->flags
& IEEE80211_TX_RC_MCS
)
5925 && (!IS_MCS(rspec
[k
]))) {
5926 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
5927 WLCWLUNIT(wlc
), __func__
);
5928 ASSERT(0 && "Rate mismatch");
5931 if (IS_MCS(rspec
[k
])) {
5932 preamble_type
[k
] = mimo_preamble_type
;
5934 /* if SGI is selected, then forced mm for single stream */
5935 if ((rspec
[k
] & RSPEC_SHORT_GI
)
5936 && IS_SINGLE_STREAM(rspec
[k
] &
5938 preamble_type
[k
] = WLC_MM_PREAMBLE
;
5942 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
5943 ASSERT(VALID_RATE_DBG(wlc
, rspec
[0]));
5945 /* should be better conditionalized */
5946 if (!IS_MCS(rspec
[0])
5947 && (tx_info
->control
.rates
[0].
5948 flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
))
5949 preamble_type
[k
] = WLC_SHORT_PREAMBLE
;
5951 ASSERT(!IS_MCS(rspec
[0])
5952 || WLC_IS_MIMO_PREAMBLE(preamble_type
[k
]));
5955 for (k
= 0; k
< hw
->max_rates
; k
++) {
5956 /* Set ctrlchbw as 20Mhz */
5957 ASSERT(!IS_MCS(rspec
[k
]));
5958 rspec
[k
] &= ~RSPEC_BW_MASK
;
5959 rspec
[k
] |= (PHY_TXC1_BW_20MHZ
<< RSPEC_BW_SHIFT
);
5961 /* for nphy, stf of ofdm frames must follow policies */
5962 if (WLCISNPHY(wlc
->band
) && IS_OFDM(rspec
[k
])) {
5963 rspec
[k
] &= ~RSPEC_STF_MASK
;
5964 rspec
[k
] |= phyctl1_stf
<< RSPEC_STF_SHIFT
;
5969 /* Reset these for use with AMPDU's */
5970 txrate
[0]->count
= 0;
5971 txrate
[1]->count
= 0;
5973 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
5974 wlc_compute_plcp(wlc
, rspec
[0], phylen
, plcp
);
5975 wlc_compute_plcp(wlc
, rspec
[1], phylen
, plcp_fallback
);
5976 bcopy(plcp_fallback
, (char *)&txh
->FragPLCPFallback
,
5977 sizeof(txh
->FragPLCPFallback
));
5979 /* Length field now put in CCK FBR CRC field */
5980 if (IS_CCK(rspec
[1])) {
5981 txh
->FragPLCPFallback
[4] = phylen
& 0xff;
5982 txh
->FragPLCPFallback
[5] = (phylen
& 0xff00) >> 8;
5985 /* MIMO-RATE: need validation ?? */
5987 IS_OFDM(rspec
[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) plcp
) :
5990 /* DUR field for main rate */
5991 if ((fc
!= FC_PS_POLL
) &&
5992 !is_multicast_ether_addr(h
->addr1
) && !use_rifs
) {
5994 wlc_compute_frame_dur(wlc
, rspec
[0], preamble_type
[0],
5996 h
->duration_id
= htol16(durid
);
5997 } else if (use_rifs
) {
5998 /* NAV protect to end of next max packet size */
6000 (u16
) wlc_calc_frame_time(wlc
, rspec
[0],
6002 DOT11_MAX_FRAG_LEN
);
6003 durid
+= RIFS_11N_TIME
;
6004 h
->duration_id
= htol16(durid
);
6007 /* DUR field for fallback rate */
6008 if (fc
== FC_PS_POLL
)
6009 txh
->FragDurFallback
= h
->duration_id
;
6010 else if (is_multicast_ether_addr(h
->addr1
) || use_rifs
)
6011 txh
->FragDurFallback
= 0;
6013 durid
= wlc_compute_frame_dur(wlc
, rspec
[1],
6014 preamble_type
[1], next_frag_len
);
6015 txh
->FragDurFallback
= htol16(durid
);
6018 /* (4) MAC-HDR: MacTxControlLow */
6020 mcl
|= TXC_STARTMSDU
;
6022 if (!is_multicast_ether_addr(h
->addr1
))
6023 mcl
|= TXC_IMMEDACK
;
6025 if (BAND_5G(wlc
->band
->bandtype
))
6026 mcl
|= TXC_FREQBAND_5G
;
6028 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC
))
6031 /* set AMIC bit if using hardware TKIP MIC */
6035 txh
->MacTxControlLow
= htol16(mcl
);
6037 /* MacTxControlHigh */
6040 /* Set fallback rate preamble type */
6041 if ((preamble_type
[1] == WLC_SHORT_PREAMBLE
) ||
6042 (preamble_type
[1] == WLC_GF_PREAMBLE
)) {
6043 ASSERT((preamble_type
[1] == WLC_GF_PREAMBLE
) ||
6044 (!IS_MCS(rspec
[1])));
6045 if (RSPEC2RATE(rspec
[1]) != WLC_RATE_1M
)
6046 mch
|= TXC_PREAMBLE_DATA_FB_SHORT
;
6049 /* MacFrameControl */
6050 bcopy((char *)&h
->frame_control
, (char *)&txh
->MacFrameControl
,
6052 txh
->TxFesTimeNormal
= htol16(0);
6054 txh
->TxFesTimeFallback
= htol16(0);
6057 bcopy((char *)&h
->addr1
, (char *)&txh
->TxFrameRA
, ETH_ALEN
);
6060 txh
->TxFrameID
= htol16(frameid
);
6062 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6063 * then we may need to reset the retry cnt's via the status reg
6065 txh
->TxStatus
= htol16(status
);
6067 if (D11REV_GE(wlc
->pub
->corerev
, 16)) {
6068 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6069 * the END of previous structure so that it's compatible in driver.
6070 * In old rev ucode, these fields should be ignored
6072 txh
->MaxNMpdus
= htol16(0);
6073 txh
->MaxABytes_MRT
= htol16(0);
6074 txh
->MaxABytes_FBR
= htol16(0);
6075 txh
->MinMBytes
= htol16(0);
6078 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6079 /* RTS PLCP header and RTS frame */
6080 if (use_rts
|| use_cts
) {
6081 if (use_rts
&& use_cts
)
6084 for (k
= 0; k
< 2; k
++) {
6085 rts_rspec
[k
] = wlc_rspec_to_rts_rspec(wlc
, rspec
[k
],
6090 if (!IS_OFDM(rts_rspec
[0]) &&
6091 !((RSPEC2RATE(rts_rspec
[0]) == WLC_RATE_1M
) ||
6092 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6093 rts_preamble_type
[0] = WLC_SHORT_PREAMBLE
;
6094 mch
|= TXC_PREAMBLE_RTS_MAIN_SHORT
;
6097 if (!IS_OFDM(rts_rspec
[1]) &&
6098 !((RSPEC2RATE(rts_rspec
[1]) == WLC_RATE_1M
) ||
6099 (wlc
->PLCPHdr_override
== WLC_PLCP_LONG
))) {
6100 rts_preamble_type
[1] = WLC_SHORT_PREAMBLE
;
6101 mch
|= TXC_PREAMBLE_RTS_FB_SHORT
;
6104 /* RTS/CTS additions to MacTxControlLow */
6106 txh
->MacTxControlLow
|= htol16(TXC_SENDCTS
);
6108 txh
->MacTxControlLow
|= htol16(TXC_SENDRTS
);
6109 txh
->MacTxControlLow
|= htol16(TXC_LONGFRAME
);
6112 /* RTS PLCP header */
6113 ASSERT(IS_ALIGNED((unsigned long)txh
->RTSPhyHeader
, sizeof(u16
)));
6114 rts_plcp
= txh
->RTSPhyHeader
;
6116 rts_phylen
= DOT11_CTS_LEN
+ FCS_LEN
;
6118 rts_phylen
= DOT11_RTS_LEN
+ FCS_LEN
;
6120 wlc_compute_plcp(wlc
, rts_rspec
[0], rts_phylen
, rts_plcp
);
6122 /* fallback rate version of RTS PLCP header */
6123 wlc_compute_plcp(wlc
, rts_rspec
[1], rts_phylen
,
6125 bcopy(rts_plcp_fallback
, (char *)&txh
->RTSPLCPFallback
,
6126 sizeof(txh
->RTSPLCPFallback
));
6128 /* RTS frame fields... */
6129 rts
= (struct ieee80211_rts
*)&txh
->rts_frame
;
6131 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
, rts_rspec
[0],
6132 rspec
[0], rts_preamble_type
[0],
6133 preamble_type
[0], phylen
, false);
6134 rts
->duration
= htol16(durid
);
6135 /* fallback rate version of RTS DUR field */
6136 durid
= wlc_compute_rtscts_dur(wlc
, use_cts
,
6137 rts_rspec
[1], rspec
[1],
6138 rts_preamble_type
[1],
6139 preamble_type
[1], phylen
, false);
6140 txh
->RTSDurFallback
= htol16(durid
);
6143 rts
->frame_control
= htol16(FC_CTS
);
6144 bcopy((char *)&h
->addr2
, (char *)&rts
->ra
, ETH_ALEN
);
6146 rts
->frame_control
= htol16((u16
) FC_RTS
);
6147 bcopy((char *)&h
->addr1
, (char *)&rts
->ra
,
6152 * low 8 bits: main frag rate/mcs,
6153 * high 8 bits: rts/cts rate/mcs
6155 mainrates
|= (IS_OFDM(rts_rspec
[0]) ?
6156 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t
*) rts_plcp
) :
6159 memset((char *)txh
->RTSPhyHeader
, 0, D11_PHY_HDR_LEN
);
6160 memset((char *)&txh
->rts_frame
, 0,
6161 sizeof(struct ieee80211_rts
));
6162 memset((char *)txh
->RTSPLCPFallback
, 0,
6163 sizeof(txh
->RTSPLCPFallback
));
6164 txh
->RTSDurFallback
= 0;
6167 #ifdef SUPPORT_40MHZ
6168 /* add null delimiter count */
6169 if ((tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) && IS_MCS(rspec
)) {
6170 txh
->RTSPLCPFallback
[AMPDU_FBR_NULL_DELIM
] =
6171 wlc_ampdu_null_delim_cnt(wlc
->ampdu
, scb
, rspec
, phylen
);
6175 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6176 txh
->MacTxControlHigh
= htol16(mch
);
6178 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6179 txh
->MainRates
= htol16(mainrates
);
6181 /* XtraFrameTypes */
6182 xfts
= FRAMETYPE(rspec
[1], wlc
->mimoft
);
6183 xfts
|= (FRAMETYPE(rts_rspec
[0], wlc
->mimoft
) << XFTS_RTS_FT_SHIFT
);
6184 xfts
|= (FRAMETYPE(rts_rspec
[1], wlc
->mimoft
) << XFTS_FBRRTS_FT_SHIFT
);
6186 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC
) << XFTS_CHANNEL_SHIFT
;
6187 txh
->XtraFrameTypes
= htol16(xfts
);
6189 /* PhyTxControlWord */
6190 phyctl
= FRAMETYPE(rspec
[0], wlc
->mimoft
);
6191 if ((preamble_type
[0] == WLC_SHORT_PREAMBLE
) ||
6192 (preamble_type
[0] == WLC_GF_PREAMBLE
)) {
6193 ASSERT((preamble_type
[0] == WLC_GF_PREAMBLE
)
6194 || !IS_MCS(rspec
[0]));
6195 if (RSPEC2RATE(rspec
[0]) != WLC_RATE_1M
)
6196 phyctl
|= PHY_TXC_SHORT_HDR
;
6197 WLCNTINCR(wlc
->pub
->_cnt
->txprshort
);
6200 /* phytxant is properly bit shifted */
6201 phyctl
|= wlc_stf_d11hdrs_phyctl_txant(wlc
, rspec
[0]);
6202 txh
->PhyTxControlWord
= htol16(phyctl
);
6204 /* PhyTxControlWord_1 */
6205 if (WLC_PHY_11N_CAP(wlc
->band
)) {
6208 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[0]);
6209 txh
->PhyTxControlWord_1
= htol16(phyctl1
);
6210 phyctl1
= wlc_phytxctl1_calc(wlc
, rspec
[1]);
6211 txh
->PhyTxControlWord_1_Fbr
= htol16(phyctl1
);
6213 if (use_rts
|| use_cts
) {
6214 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[0]);
6215 txh
->PhyTxControlWord_1_Rts
= htol16(phyctl1
);
6216 phyctl1
= wlc_phytxctl1_calc(wlc
, rts_rspec
[1]);
6217 txh
->PhyTxControlWord_1_FbrRts
= htol16(phyctl1
);
6221 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6222 * fill in non-zero MModeLen and/or MModeFbrLen
6223 * it will be unnecessary if they are separated
6225 if (IS_MCS(rspec
[0]) && (preamble_type
[0] == WLC_MM_PREAMBLE
)) {
6227 wlc_calc_lsig_len(wlc
, rspec
[0], phylen
);
6228 txh
->MModeLen
= htol16(mmodelen
);
6231 if (IS_MCS(rspec
[1]) && (preamble_type
[1] == WLC_MM_PREAMBLE
)) {
6233 wlc_calc_lsig_len(wlc
, rspec
[1], phylen
);
6234 txh
->MModeFbrLen
= htol16(mmodefbrlen
);
6238 if (IS_MCS(rspec
[0]))
6239 ASSERT(IS_MCS(rspec
[1]));
6241 ASSERT(!IS_MCS(rspec
[0]) ||
6242 ((preamble_type
[0] == WLC_MM_PREAMBLE
) == (txh
->MModeLen
!= 0)));
6243 ASSERT(!IS_MCS(rspec
[1]) ||
6244 ((preamble_type
[1] == WLC_MM_PREAMBLE
) ==
6245 (txh
->MModeFbrLen
!= 0)));
6247 ac
= wme_fifo2ac
[queue
];
6248 if (SCB_WME(scb
) && qos
&& wlc
->edcf_txop
[ac
]) {
6249 uint frag_dur
, dur
, dur_fallback
;
6251 ASSERT(!is_multicast_ether_addr(h
->addr1
));
6253 /* WME: Update TXOP threshold */
6254 if ((!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)) && (frag
== 0)) {
6256 wlc_calc_frame_time(wlc
, rspec
[0], preamble_type
[0],
6260 /* 1 RTS or CTS-to-self frame */
6262 wlc_calc_cts_time(wlc
, rts_rspec
[0],
6263 rts_preamble_type
[0]);
6265 wlc_calc_cts_time(wlc
, rts_rspec
[1],
6266 rts_preamble_type
[1]);
6267 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6268 dur
+= ltoh16(rts
->duration
);
6269 dur_fallback
+= ltoh16(txh
->RTSDurFallback
);
6270 } else if (use_rifs
) {
6274 /* frame + SIFS + ACK */
6277 wlc_compute_frame_dur(wlc
, rspec
[0],
6278 preamble_type
[0], 0);
6281 wlc_calc_frame_time(wlc
, rspec
[1],
6285 wlc_compute_frame_dur(wlc
, rspec
[1],
6286 preamble_type
[1], 0);
6288 /* NEED to set TxFesTimeNormal (hard) */
6289 txh
->TxFesTimeNormal
= htol16((u16
) dur
);
6290 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6291 txh
->TxFesTimeFallback
= htol16((u16
) dur_fallback
);
6293 /* update txop byte threshold (txop minus intraframe overhead) */
6294 if (wlc
->edcf_txop
[ac
] >= (dur
- frag_dur
)) {
6299 wlc_calc_frame_len(wlc
, rspec
[0],
6305 /* range bound the fragthreshold */
6306 if (newfragthresh
< DOT11_MIN_FRAG_LEN
)
6309 else if (newfragthresh
>
6310 wlc
->usr_fragthresh
)
6312 wlc
->usr_fragthresh
;
6313 /* update the fragthresh and do txc update */
6314 if (wlc
->fragthresh
[queue
] !=
6315 (u16
) newfragthresh
) {
6316 wlc
->fragthresh
[queue
] =
6317 (u16
) newfragthresh
;
6321 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6322 wlc
->pub
->unit
, fifo_names
[queue
],
6323 RSPEC2RATE(rspec
[0]));
6325 if (dur
> wlc
->edcf_txop
[ac
])
6326 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6327 wlc
->pub
->unit
, __func__
,
6329 phylen
, wlc
->fragthresh
[queue
],
6330 dur
, wlc
->edcf_txop
[ac
]);
6337 void wlc_tbtt(struct wlc_info
*wlc
, d11regs_t
*regs
)
6339 wlc_bsscfg_t
*cfg
= wlc
->cfg
;
6341 WLCNTINCR(wlc
->pub
->_cnt
->tbtt
);
6343 if (BSSCFG_STA(cfg
)) {
6344 /* run watchdog here if the watchdog timer is not armed */
6345 if (WLC_WATCHDOG_TBTT(wlc
)) {
6348 wl_del_timer(wlc
->wl
, wlc
->wdtimer
);
6349 wlc
->WDarmed
= false;
6352 cur
= OSL_SYSUPTIME();
6353 delta
= cur
> wlc
->WDlast
? cur
- wlc
->WDlast
:
6354 (u32
) ~0 - wlc
->WDlast
+ cur
+ 1;
6355 if (delta
>= TIMER_INTERVAL_WATCHDOG
) {
6356 wlc_watchdog((void *)wlc
);
6360 wl_add_timer(wlc
->wl
, wlc
->wdtimer
,
6361 wlc_watchdog_backup_bi(wlc
), true);
6362 wlc
->WDarmed
= true;
6367 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6368 wlc
->qvalid
|= MCMD_DIRFRMQVAL
;
6372 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6373 void wlc_hwtimer_gptimer_set(struct wlc_info
*wlc
, uint us
)
6375 ASSERT(wlc
->pub
->corerev
>= 3); /* no gptimer in earlier revs */
6376 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, us
);
6379 void wlc_hwtimer_gptimer_abort(struct wlc_info
*wlc
)
6381 ASSERT(wlc
->pub
->corerev
>= 3);
6382 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, 0);
6385 static void wlc_hwtimer_gptimer_cb(struct wlc_info
*wlc
)
6387 /* when interrupt is generated, the counter is loaded with last value
6388 * written and continue to decrement. So it has to be cleaned first
6390 W_REG(wlc
->osh
, &wlc
->regs
->gptimer
, 0);
6394 * This fn has all the high level dpc processing from wlc_dpc.
6395 * POLICY: no macinstatus change, no bounding loop.
6396 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6398 void wlc_high_dpc(struct wlc_info
*wlc
, u32 macintstatus
)
6400 d11regs_t
*regs
= wlc
->regs
;
6403 static const bcm_bit_desc_t int_flags
[] = {
6404 {MI_MACSSPNDD
, "MACSSPNDD"},
6405 {MI_BCNTPL
, "BCNTPL"},
6407 {MI_BCNSUCCESS
, "BCNSUCCESS"},
6408 {MI_BCNCANCLD
, "BCNCANCLD"},
6409 {MI_ATIMWINEND
, "ATIMWINEND"},
6411 {MI_NSPECGEN_0
, "NSPECGEN_0"},
6412 {MI_NSPECGEN_1
, "NSPECGEN_1"},
6413 {MI_MACTXERR
, "MACTXERR"},
6414 {MI_NSPECGEN_3
, "NSPECGEN_3"},
6415 {MI_PHYTXERR
, "PHYTXERR"},
6419 {MI_DMAINT
, "DMAINT"},
6420 {MI_TXSTOP
, "TXSTOP"},
6422 {MI_BG_NOISE
, "BG_NOISE"},
6423 {MI_DTIM_TBTT
, "DTIM_TBTT"},
6425 {MI_PWRUP
, "PWRUP"},
6426 {MI_RFDISABLE
, "RFDISABLE"},
6428 {MI_PHYCHANGED
, "PHYCHANGED"},
6433 if (macintstatus
& ~(MI_TBTT
| MI_TXSTOP
)) {
6434 bcm_format_flags(int_flags
, macintstatus
, flagstr
,
6436 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6437 wlc
->pub
->unit
, macintstatus
, flagstr
);
6441 if (macintstatus
& MI_PRQ
) {
6442 /* Process probe request FIFO */
6443 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6446 /* TBTT indication */
6447 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6448 if (macintstatus
& (MI_TBTT
| MI_DTIM_TBTT
))
6449 wlc_tbtt(wlc
, regs
);
6451 if (macintstatus
& MI_GP0
) {
6452 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6453 wlc
->pub
->unit
, wlc
->pub
->now
);
6455 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6456 __func__
, wlc
->pub
->sih
->chip
,
6457 wlc
->pub
->sih
->chiprev
);
6459 WLCNTINCR(wlc
->pub
->_cnt
->psmwds
);
6465 /* gptimer timeout */
6466 if (macintstatus
& MI_TO
) {
6467 wlc_hwtimer_gptimer_cb(wlc
);
6470 if (macintstatus
& MI_RFDISABLE
) {
6471 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6473 R_REG(wlc
->osh
, ®s
->phydebug
) & PDBG_RFD
);
6474 /* delay the cleanup to wl_down in IBSS case */
6475 if ((R_REG(wlc
->osh
, ®s
->phydebug
) & PDBG_RFD
)) {
6477 wlc_bsscfg_t
*bsscfg
;
6478 FOREACH_BSS(wlc
, idx
, bsscfg
) {
6479 if (!BSSCFG_STA(bsscfg
) || !bsscfg
->enable
6482 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6488 /* send any enq'd tx packets. Just makes sure to jump start tx */
6489 if (!pktq_empty(&wlc
->active_queue
->q
))
6490 wlc_send_q(wlc
, wlc
->active_queue
);
6492 ASSERT(wlc_ps_check(wlc
));
6495 static void *wlc_15420war(struct wlc_info
*wlc
, uint queue
)
6497 struct hnddma_pub
*di
;
6500 ASSERT(queue
< NFIFO
);
6502 if ((D11REV_IS(wlc
->pub
->corerev
, 4))
6503 || (D11REV_GT(wlc
->pub
->corerev
, 6)))
6506 di
= wlc
->hw
->di
[queue
];
6509 /* get next packet, ignoring XmtStatus.Curr */
6510 p
= dma_getnexttxp(di
, HNDDMA_RANGE_ALL
);
6512 /* sw block tx dma */
6515 /* if tx ring is now empty, reset and re-init the tx dma channel */
6516 if (dma_txactive(wlc
->hw
->di
[queue
]) == 0) {
6517 WLCNTINCR(wlc
->pub
->_cnt
->txdmawar
);
6518 if (!dma_txreset(di
))
6519 WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n",
6520 wlc
->pub
->unit
, __func__
, queue
);
6526 static void wlc_war16165(struct wlc_info
*wlc
, bool tx
)
6529 /* the post-increment is used in STAY_AWAKE macro */
6530 if (wlc
->txpend16165war
++ == 0)
6531 wlc_set_ps_ctrl(wlc
);
6533 wlc
->txpend16165war
--;
6534 if (wlc
->txpend16165war
== 0)
6535 wlc_set_ps_ctrl(wlc
);
6539 /* process an individual tx_status_t */
6542 wlc_dotxstatus(struct wlc_info
*wlc
, tx_status_t
*txs
, u32 frm_tx2
)
6547 struct scb
*scb
= NULL
;
6549 struct osl_info
*osh
;
6550 int tx_rts
, tx_frame_count
, tx_rts_count
;
6551 uint totlen
, supr_status
;
6553 struct ieee80211_hdr
*h
;
6556 struct ieee80211_tx_info
*tx_info
;
6557 struct ieee80211_tx_rate
*txrate
;
6560 (void)(frm_tx2
); /* Compiler reference to avoid unused variable warning */
6562 /* discard intermediate indications for ucode with one legitimate case:
6563 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6564 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6565 * transmission count)
6567 if (!(txs
->status
& TX_STATUS_AMPDU
)
6568 && (txs
->status
& TX_STATUS_INTERMEDIATE
)) {
6569 WLCNTADD(wlc
->pub
->_cnt
->txnoack
,
6571 status
& TX_STATUS_FRM_RTX_MASK
) >>
6572 TX_STATUS_FRM_RTX_SHIFT
));
6573 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__
);
6578 queue
= txs
->frameid
& TXFID_QUEUE_MASK
;
6579 ASSERT(queue
< NFIFO
);
6580 if (queue
>= NFIFO
) {
6585 p
= GETNEXTTXP(wlc
, queue
);
6586 if (WLC_WAR16165(wlc
))
6587 wlc_war16165(wlc
, false);
6589 p
= wlc_15420war(wlc
, queue
);
6594 txh
= (d11txh_t
*) (p
->data
);
6595 mcl
= ltoh16(txh
->MacTxControlLow
);
6598 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6599 txs
->phyerr
, txh
->MainRates
);
6600 wlc_print_txdesc(txh
);
6601 wlc_print_txstatus(txs
);
6604 ASSERT(txs
->frameid
== htol16(txh
->TxFrameID
));
6605 if (txs
->frameid
!= htol16(txh
->TxFrameID
))
6608 tx_info
= IEEE80211_SKB_CB(p
);
6609 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
6610 fc
= ltoh16(h
->frame_control
);
6612 scb
= (struct scb
*)tx_info
->control
.sta
->drv_priv
;
6614 if (N_ENAB(wlc
->pub
)) {
6615 u8
*plcp
= (u8
*) (txh
+ 1);
6616 if (PLCP3_ISSGI(plcp
[3]))
6617 WLCNTINCR(wlc
->pub
->_cnt
->txmpdu_sgi
);
6618 if (PLCP3_ISSTBC(plcp
[3]))
6619 WLCNTINCR(wlc
->pub
->_cnt
->txmpdu_stbc
);
6622 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
6623 ASSERT((mcl
& TXC_AMPDU_MASK
) != TXC_AMPDU_NONE
);
6624 wlc_ampdu_dotxstatus(wlc
->ampdu
, scb
, p
, txs
);
6628 supr_status
= txs
->status
& TX_STATUS_SUPR_MASK
;
6629 if (supr_status
== TX_STATUS_SUPR_BADCH
)
6630 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6631 __func__
, CHSPEC_CHANNEL(wlc
->default_bss
->chanspec
));
6633 tx_rts
= htol16(txh
->MacTxControlLow
) & TXC_SENDRTS
;
6635 (txs
->status
& TX_STATUS_FRM_RTX_MASK
) >> TX_STATUS_FRM_RTX_SHIFT
;
6637 (txs
->status
& TX_STATUS_RTS_RTX_MASK
) >> TX_STATUS_RTS_RTX_SHIFT
;
6639 lastframe
= (fc
& IEEE80211_FCTL_MOREFRAGS
) == 0;
6642 WL_ERROR("Not last frame!\n");
6645 ieee80211_tx_info_clear_status(tx_info
);
6646 if (queue
< AC_COUNT
) {
6647 sfbl
= WLC_WME_RETRY_SFB_GET(wlc
, wme_fifo2ac
[queue
]);
6648 lfbl
= WLC_WME_RETRY_LFB_GET(wlc
, wme_fifo2ac
[queue
]);
6654 txrate
= tx_info
->status
.rates
;
6655 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6656 if ((tx_frame_count
> sfbl
) && (txrate
[1].idx
>= 0)) {
6657 /* rate selection requested a fallback rate and we used it */
6658 txrate
->count
= lfbl
;
6659 txrate
[1].count
= tx_frame_count
- lfbl
;
6661 /* rate selection did not request fallback rate, or we didn't need it */
6662 txrate
->count
= tx_frame_count
;
6663 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6665 txrate
[1].count
= 0;
6668 /* clear the rest of the rates */
6669 for (i
= 2; i
< IEEE80211_TX_MAX_RATES
; i
++) {
6671 txrate
[i
].count
= 0;
6674 if (txs
->status
& TX_STATUS_ACK_RCV
)
6675 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
6678 totlen
= pkttotlen(osh
, p
);
6681 wlc_txfifo_complete(wlc
, queue
, 1);
6687 /* remove PLCP & Broadcom tx descriptor header */
6688 skb_pull(p
, D11_PHY_HDR_LEN
);
6689 skb_pull(p
, D11_TXH_LEN
);
6690 ieee80211_tx_status_irqsafe(wlc
->pub
->ieee_hw
, p
);
6691 WLCNTINCR(wlc
->pub
->_cnt
->ieee_tx_status
);
6693 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6702 pkt_buf_free_skb(osh
, p
, true);
6709 wlc_txfifo_complete(struct wlc_info
*wlc
, uint fifo
, s8 txpktpend
)
6711 TXPKTPENDDEC(wlc
, fifo
, txpktpend
);
6712 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6713 txpktpend
, TXPKTPENDGET(wlc
, fifo
));
6715 /* There is more room; mark precedences related to this FIFO sendable */
6716 WLC_TX_FIFO_ENAB(wlc
, fifo
);
6717 ASSERT(TXPKTPENDGET(wlc
, fifo
) >= 0);
6719 if (!TXPKTPENDTOT(wlc
)) {
6720 if (wlc
->block_datafifo
& DATA_BLOCK_TX_SUPR
)
6721 wlc_bsscfg_tx_check(wlc
);
6724 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6725 if (AP_ENAB(wlc
->pub
) &&
6726 wlc
->bcmcfifo_drain
&& !TXPKTPENDGET(wlc
, TX_BCMC_FIFO
)) {
6727 wlc
->bcmcfifo_drain
= false;
6728 wlc_mhf(wlc
, MHF2
, MHF2_TXBCMC_NOW
, 0, WLC_BAND_AUTO
);
6731 /* figure out which bsscfg is being worked on... */
6734 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6735 * return the offset (in us) of the TSF from the last TBTT
6737 u32
wlc_calc_tbtt_offset(u32 bp
, u32 tsf_h
, u32 tsf_l
)
6739 u32 k
, btklo
, btkhi
, offset
;
6741 /* TBTT is always an even multiple of the beacon_interval,
6742 * so the TBTT less than or equal to the beacon timestamp is
6743 * the beacon timestamp minus the beacon timestamp modulo
6744 * the beacon interval.
6746 * TBTT = BT - (BT % BIu)
6747 * = (BTk - (BTk % BP)) * 2^10
6749 * BT = beacon timestamp (usec, 64bits)
6750 * BTk = beacon timestamp (Kusec, 54bits)
6751 * BP = beacon interval (Kusec, 16bits)
6752 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6754 * To keep the calculations in u32s, the modulo operation
6755 * on the high part of BT needs to be done in parts using the
6757 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6759 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6761 * So, if BTk[n] = u16 n [0,3] of BTk.
6762 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6763 * and the SUM term can be broken down:
6764 * (BTk[n] * 2^16n) % BP
6765 * (BTk[n] * (2^16n % BP)) % BP
6767 * Create a set of power of 2 mod BP constants:
6768 * K[n] = 2^(16n) % BP
6769 * = (K[n-1] * 2^16) % BP
6770 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6772 * BTk % BP = BTk[0-1] % BP +
6773 * (BTk[2] * K[2]) % BP +
6774 * (BTk[3] * K[3]) % BP
6776 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6779 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6780 btklo
= (tsf_h
<< 22) | (tsf_l
>> 10);
6781 btkhi
= tsf_h
>> 10;
6783 /* offset = BTk % BP */
6784 offset
= btklo
% bp
;
6786 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6787 k
= (u32
) (1 << 16) % bp
;
6788 k
= (u32
) (k
* 1 << 16) % (u32
) bp
;
6790 /* offset += (BTk[2] * K[2]) % BP */
6791 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
6794 btkhi
= btkhi
>> 16;
6796 /* k[3] = (K[2] * 2^16) % BP */
6799 /* offset += (BTk[3] * K[3]) % BP */
6800 offset
+= ((btkhi
& 0xffff) * k
) % bp
;
6802 offset
= offset
% bp
;
6804 /* convert offset from kus to us by shifting up 10 bits and
6805 * add in the low 10 bits of tsf that we ignored
6807 offset
= (offset
<< 10) + (tsf_l
& 0x3FF);
6812 /* Update beacon listen interval in shared memory */
6813 void wlc_bcn_li_upd(struct wlc_info
*wlc
)
6815 if (AP_ENAB(wlc
->pub
))
6818 /* wake up every DTIM is the default */
6819 if (wlc
->bcn_li_dtim
== 1)
6820 wlc_write_shm(wlc
, M_BCN_LI
, 0);
6822 wlc_write_shm(wlc
, M_BCN_LI
,
6823 (wlc
->bcn_li_dtim
<< 8) | wlc
->bcn_li_bcn
);
6827 prep_mac80211_status(struct wlc_info
*wlc
, d11rxhdr_t
*rxh
, struct sk_buff
*p
,
6828 struct ieee80211_rx_status
*rx_status
)
6831 wlc_d11rxhdr_t
*wlc_rxh
= (wlc_d11rxhdr_t
*) rxh
;
6835 unsigned char *plcp
;
6837 wlc_read_tsf(wlc
, &tsf_l
, &tsf_h
); /* mactime */
6838 rx_status
->mactime
= tsf_h
;
6839 rx_status
->mactime
<<= 32;
6840 rx_status
->mactime
|= tsf_l
;
6841 rx_status
->flag
|= RX_FLAG_TSFT
;
6843 channel
= WLC_CHAN_CHANNEL(rxh
->RxChan
);
6845 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
6847 rx_status
->band
= IEEE80211_BAND_5GHZ
;
6848 rx_status
->freq
= ieee80211_ofdm_chan_to_freq(
6849 WF_CHAN_FACTOR_5_G
/2, channel
);
6852 rx_status
->band
= IEEE80211_BAND_2GHZ
;
6853 rx_status
->freq
= ieee80211_dsss_chan_to_freq(channel
);
6856 rx_status
->signal
= wlc_rxh
->rssi
; /* signal */
6860 rx_status
->antenna
= (rxh
->PhyRxStatus_0
& PRXS0_RXANT_UPSUBBAND
) ? 1 : 0; /* ant */
6864 rspec
= wlc_compute_rspec(rxh
, plcp
);
6865 if (IS_MCS(rspec
)) {
6866 rx_status
->rate_idx
= rspec
& RSPEC_RATE_MASK
;
6867 rx_status
->flag
|= RX_FLAG_HT
;
6868 if (RSPEC_IS40MHZ(rspec
))
6869 rx_status
->flag
|= RX_FLAG_40MHZ
;
6871 switch (RSPEC2RATE(rspec
)) {
6873 rx_status
->rate_idx
= 0;
6876 rx_status
->rate_idx
= 1;
6879 rx_status
->rate_idx
= 2;
6882 rx_status
->rate_idx
= 3;
6885 rx_status
->rate_idx
= 4;
6888 rx_status
->rate_idx
= 5;
6891 rx_status
->rate_idx
= 6;
6894 rx_status
->rate_idx
= 7;
6897 rx_status
->rate_idx
= 8;
6900 rx_status
->rate_idx
= 9;
6903 rx_status
->rate_idx
= 10;
6906 rx_status
->rate_idx
= 11;
6909 WL_ERROR("%s: Unknown rate\n", __func__
);
6912 /* Determine short preamble and rate_idx */
6914 if (IS_CCK(rspec
)) {
6915 if (rxh
->PhyRxStatus_0
& PRXS0_SHORTH
)
6916 WL_ERROR("Short CCK\n");
6917 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
6918 } else if (IS_OFDM(rspec
)) {
6919 rx_status
->flag
|= RX_FLAG_SHORTPRE
;
6921 WL_ERROR("%s: Unknown modulation\n", __func__
);
6925 if (PLCP3_ISSGI(plcp
[3]))
6926 rx_status
->flag
|= RX_FLAG_SHORT_GI
;
6928 if (rxh
->RxStatus1
& RXS_DECERR
) {
6929 rx_status
->flag
|= RX_FLAG_FAILED_PLCP_CRC
;
6930 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__
);
6932 if (rxh
->RxStatus1
& RXS_FCSERR
) {
6933 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
6934 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__
);
6939 wlc_recvctl(struct wlc_info
*wlc
, struct osl_info
*osh
, d11rxhdr_t
*rxh
,
6943 struct ieee80211_rx_status rx_status
;
6945 struct sk_buff
*skb
= p
;
6948 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
6949 * Test for INTERMEDIATE like so:
6950 * if (!(plcp[0] | plcp[1] | plcp[2]))
6953 memset(&rx_status
, 0, sizeof(rx_status
));
6954 prep_mac80211_status(wlc
, rxh
, p
, &rx_status
);
6956 /* mac header+body length, exclude CRC and plcp header */
6957 len_mpdu
= p
->len
- D11_PHY_HDR_LEN
- FCS_LEN
;
6958 skb_pull(p
, D11_PHY_HDR_LEN
);
6959 __skb_trim(p
, len_mpdu
);
6964 ASSERT(IS_ALIGNED((unsigned long)skb
->data
, 2));
6966 memcpy(IEEE80211_SKB_RXCB(p
), &rx_status
, sizeof(rx_status
));
6967 ieee80211_rx_irqsafe(wlc
->pub
->ieee_hw
, p
);
6969 WLCNTINCR(wlc
->pub
->_cnt
->ieee_rx
);
6974 void wlc_bss_list_free(struct wlc_info
*wlc
, wlc_bss_list_t
*bss_list
)
6980 WL_ERROR("%s: Attempting to free NULL list\n", __func__
);
6983 /* inspect all BSS descriptor */
6984 for (index
= 0; index
< bss_list
->count
; index
++) {
6985 bi
= bss_list
->ptrs
[index
];
6988 bss_list
->ptrs
[index
] = NULL
;
6991 bss_list
->count
= 0;
6994 /* Process received frames */
6996 * Return true if more frames need to be processed. false otherwise.
6997 * Param 'bound' indicates max. # frames to process before break out.
7000 void BCMFASTPATH
wlc_recv(struct wlc_info
*wlc
, struct sk_buff
*p
)
7003 struct ieee80211_hdr
*h
;
7004 struct osl_info
*osh
;
7009 WL_TRACE("wl%d: wlc_recv\n", wlc
->pub
->unit
);
7013 /* frame starts with rxhdr */
7014 rxh
= (d11rxhdr_t
*) (p
->data
);
7016 /* strip off rxhdr */
7017 skb_pull(p
, wlc
->hwrxoff
);
7019 /* fixup rx header endianness */
7020 ltoh16_buf((void *)rxh
, sizeof(d11rxhdr_t
));
7022 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7023 if (rxh
->RxStatus1
& RXS_PBPRES
) {
7025 WLCNTINCR(wlc
->pub
->_cnt
->rxrunt
);
7026 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7027 wlc
->pub
->unit
, p
->len
);
7033 h
= (struct ieee80211_hdr
*)(p
->data
+ D11_PHY_HDR_LEN
);
7036 if (rxh
->RxStatus1
& RXS_FCSERR
) {
7037 if (wlc
->pub
->mac80211_state
& MAC80211_PROMISC_BCNS
) {
7038 WL_ERROR("FCSERR while scanning******* - tossing\n");
7041 WL_ERROR("RCSERR!!!\n");
7046 /* check received pkt has at least frame control field */
7047 if (len
>= D11_PHY_HDR_LEN
+ sizeof(h
->frame_control
)) {
7048 fc
= ltoh16(h
->frame_control
);
7050 WLCNTINCR(wlc
->pub
->_cnt
->rxrunt
);
7054 is_amsdu
= rxh
->RxStatus2
& RXS_AMSDU_MASK
;
7056 /* explicitly test bad src address to avoid sending bad deauth */
7058 /* CTS and ACK CTL frames are w/o a2 */
7059 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
||
7060 (fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
7061 if ((is_zero_ether_addr(h
->addr2
) ||
7062 is_multicast_ether_addr(h
->addr2
))) {
7063 WL_ERROR("wl%d: %s: dropping a frame with "
7064 "invalid src mac address, a2: %pM\n",
7065 wlc
->pub
->unit
, __func__
, h
->addr2
);
7066 WLCNTINCR(wlc
->pub
->_cnt
->rxbadsrcmac
);
7069 WLCNTINCR(wlc
->pub
->_cnt
->rxfrag
);
7073 /* due to sheer numbers, toss out probe reqs for now */
7074 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
7075 if ((fc
& FC_KIND_MASK
) == FC_PROBE_REQ
)
7080 WL_ERROR("%s: is_amsdu causing toss\n", __func__
);
7084 wlc_recvctl(wlc
, osh
, rxh
, p
);
7088 pkt_buf_free_skb(osh
, p
, false);
7091 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7092 * number of bytes goes in the length field
7094 * Formula given by HT PHY Spec v 1.13
7095 * len = 3(nsyms + nstream + 3) - 3
7098 wlc_calc_lsig_len(struct wlc_info
*wlc
, ratespec_t ratespec
, uint mac_len
)
7100 uint nsyms
, len
= 0, kNdps
;
7102 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7103 wlc
->pub
->unit
, RSPEC2RATE(ratespec
), mac_len
);
7105 if (IS_MCS(ratespec
)) {
7106 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7107 /* MCS_TXS(mcs) returns num tx streams - 1 */
7108 int tot_streams
= (MCS_TXS(mcs
) + 1) + RSPEC_STC(ratespec
);
7110 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7111 /* the payload duration calculation matches that of regular ofdm */
7112 /* 1000Ndbps = kbps * 4 */
7114 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7115 RSPEC_ISSGI(ratespec
)) * 4;
7117 if (RSPEC_STC(ratespec
) == 0)
7118 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7120 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7121 APHY_TAIL_NBITS
) * 1000, kNdps
);
7123 /* STBC needs to have even number of symbols */
7126 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7127 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7129 nsyms
+= (tot_streams
+ 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7130 /* 3 bytes/symbol @ legacy 6Mbps rate */
7131 len
= (3 * nsyms
) - 3; /* (-3) excluding service bits and tail bits */
7137 /* calculate frame duration of a given rate and length, return time in usec unit */
7139 wlc_calc_frame_time(struct wlc_info
*wlc
, ratespec_t ratespec
, u8 preamble_type
,
7142 uint nsyms
, dur
= 0, Ndps
, kNdps
;
7143 uint rate
= RSPEC2RATE(ratespec
);
7147 WL_ERROR("wl%d: WAR: using rate of 1 mbps\n", wlc
->pub
->unit
);
7151 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7152 wlc
->pub
->unit
, ratespec
, preamble_type
, mac_len
);
7154 if (IS_MCS(ratespec
)) {
7155 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7156 int tot_streams
= MCS_TXS(mcs
) + RSPEC_STC(ratespec
);
7157 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7158 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type
));
7160 dur
= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
7161 if (preamble_type
== WLC_MM_PREAMBLE
)
7163 /* 1000Ndbps = kbps * 4 */
7165 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7166 RSPEC_ISSGI(ratespec
)) * 4;
7168 if (RSPEC_STC(ratespec
) == 0)
7169 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7171 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7172 APHY_TAIL_NBITS
) * 1000, kNdps
);
7174 /* STBC needs to have even number of symbols */
7177 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+
7178 APHY_TAIL_NBITS
) * 1000, 2 * kNdps
);
7180 dur
+= APHY_SYMBOL_TIME
* nsyms
;
7181 if (BAND_2G(wlc
->band
->bandtype
))
7182 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
7183 } else if (IS_OFDM(rate
)) {
7184 dur
= APHY_PREAMBLE_TIME
;
7185 dur
+= APHY_SIGNAL_TIME
;
7186 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7188 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7190 CEIL((APHY_SERVICE_NBITS
+ 8 * mac_len
+ APHY_TAIL_NBITS
),
7192 dur
+= APHY_SYMBOL_TIME
* nsyms
;
7193 if (BAND_2G(wlc
->band
->bandtype
))
7194 dur
+= DOT11_OFDM_SIGNAL_EXTENSION
;
7196 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7197 mac_len
= mac_len
* 8 * 2;
7198 /* calc ceiling of bits/rate = microseconds of air time */
7199 dur
= (mac_len
+ rate
- 1) / rate
;
7200 if (preamble_type
& WLC_SHORT_PREAMBLE
)
7201 dur
+= BPHY_PLCP_SHORT_TIME
;
7203 dur
+= BPHY_PLCP_TIME
;
7208 /* The opposite of wlc_calc_frame_time */
7210 wlc_calc_frame_len(struct wlc_info
*wlc
, ratespec_t ratespec
, u8 preamble_type
,
7213 uint nsyms
, mac_len
, Ndps
, kNdps
;
7214 uint rate
= RSPEC2RATE(ratespec
);
7216 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7217 wlc
->pub
->unit
, ratespec
, preamble_type
, dur
);
7219 if (IS_MCS(ratespec
)) {
7220 uint mcs
= ratespec
& RSPEC_RATE_MASK
;
7221 int tot_streams
= MCS_TXS(mcs
) + RSPEC_STC(ratespec
);
7222 ASSERT(WLC_PHY_11N_CAP(wlc
->band
));
7223 dur
-= PREN_PREAMBLE
+ (tot_streams
* PREN_PREAMBLE_EXT
);
7224 /* payload calculation matches that of regular ofdm */
7225 if (BAND_2G(wlc
->band
->bandtype
))
7226 dur
-= DOT11_OFDM_SIGNAL_EXTENSION
;
7227 /* kNdbps = kbps * 4 */
7229 MCS_RATE(mcs
, RSPEC_IS40MHZ(ratespec
),
7230 RSPEC_ISSGI(ratespec
)) * 4;
7231 nsyms
= dur
/ APHY_SYMBOL_TIME
;
7234 ((APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
) * 1000)) / 8000;
7235 } else if (IS_OFDM(ratespec
)) {
7236 dur
-= APHY_PREAMBLE_TIME
;
7237 dur
-= APHY_SIGNAL_TIME
;
7238 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7240 nsyms
= dur
/ APHY_SYMBOL_TIME
;
7243 (APHY_SERVICE_NBITS
+ APHY_TAIL_NBITS
)) / 8;
7245 if (preamble_type
& WLC_SHORT_PREAMBLE
)
7246 dur
-= BPHY_PLCP_SHORT_TIME
;
7248 dur
-= BPHY_PLCP_TIME
;
7249 mac_len
= dur
* rate
;
7250 /* divide out factor of 2 in rate (1/2 mbps) */
7251 mac_len
= mac_len
/ 8 / 2;
7257 wlc_calc_ba_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7259 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7260 wlc
->pub
->unit
, rspec
, preamble_type
);
7261 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7262 * or equal to the rate of the immediately previous frame in the FES
7264 rspec
= WLC_BASIC_RATE(wlc
, rspec
);
7265 ASSERT(VALID_RATE_DBG(wlc
, rspec
));
7267 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7268 return wlc_calc_frame_time(wlc
, rspec
, preamble_type
,
7269 (DOT11_BA_LEN
+ DOT11_BA_BITMAP_LEN
+
7273 static uint BCMFASTPATH
7274 wlc_calc_ack_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7278 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7279 wlc
->pub
->unit
, rspec
, preamble_type
);
7280 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7281 * or equal to the rate of the immediately previous frame in the FES
7283 rspec
= WLC_BASIC_RATE(wlc
, rspec
);
7284 ASSERT(VALID_RATE_DBG(wlc
, rspec
));
7286 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7288 wlc_calc_frame_time(wlc
, rspec
, preamble_type
,
7289 (DOT11_ACK_LEN
+ FCS_LEN
));
7294 wlc_calc_cts_time(struct wlc_info
*wlc
, ratespec_t rspec
, u8 preamble_type
)
7296 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7297 wlc
->pub
->unit
, rspec
, preamble_type
);
7298 return wlc_calc_ack_time(wlc
, rspec
, preamble_type
);
7301 /* derive wlc->band->basic_rate[] table from 'rateset' */
7302 void wlc_rate_lookup_init(struct wlc_info
*wlc
, wlc_rateset_t
*rateset
)
7308 u8
*br
= wlc
->band
->basic_rate
;
7311 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7312 memset(br
, 0, WLC_MAXRATE
+ 1);
7314 /* For each basic rate in the rates list, make an entry in the
7315 * best basic lookup.
7317 for (i
= 0; i
< rateset
->count
; i
++) {
7318 /* only make an entry for a basic rate */
7319 if (!(rateset
->rates
[i
] & WLC_RATE_FLAG
))
7322 /* mask off basic bit */
7323 rate
= (rateset
->rates
[i
] & RATE_MASK
);
7325 if (rate
> WLC_MAXRATE
) {
7326 WL_ERROR("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n",
7334 /* The rate lookup table now has non-zero entries for each
7335 * basic rate, equal to the basic rate: br[basicN] = basicN
7337 * To look up the best basic rate corresponding to any
7338 * particular rate, code can use the basic_rate table
7341 * basic_rate = wlc->band->basic_rate[tx_rate]
7343 * Make sure there is a best basic rate entry for
7344 * every rate by walking up the table from low rates
7345 * to high, filling in holes in the lookup table
7348 for (i
= 0; i
< wlc
->band
->hw_rateset
.count
; i
++) {
7349 rate
= wlc
->band
->hw_rateset
.rates
[i
];
7350 ASSERT(rate
<= WLC_MAXRATE
);
7352 if (br
[rate
] != 0) {
7353 /* This rate is a basic rate.
7354 * Keep track of the best basic rate so far by
7365 /* This rate is not a basic rate so figure out the
7366 * best basic rate less than this rate and fill in
7367 * the hole in the table
7370 br
[rate
] = IS_OFDM(rate
) ? ofdm_basic
: cck_basic
;
7375 if (IS_OFDM(rate
)) {
7376 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7377 if (rate
>= WLC_RATE_24M
)
7378 mandatory
= WLC_RATE_24M
;
7379 else if (rate
>= WLC_RATE_12M
)
7380 mandatory
= WLC_RATE_12M
;
7382 mandatory
= WLC_RATE_6M
;
7384 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7388 br
[rate
] = mandatory
;
7392 static void wlc_write_rate_shm(struct wlc_info
*wlc
, u8 rate
, u8 basic_rate
)
7395 u8 basic_phy_rate
, basic_index
;
7396 u16 dir_table
, basic_table
;
7399 /* Shared memory address for the table we are reading */
7400 dir_table
= IS_OFDM(basic_rate
) ? M_RT_DIRMAP_A
: M_RT_DIRMAP_B
;
7402 /* Shared memory address for the table we are writing */
7403 basic_table
= IS_OFDM(rate
) ? M_RT_BBRSMAP_A
: M_RT_BBRSMAP_B
;
7406 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7407 * the index into the rate table.
7409 phy_rate
= rate_info
[rate
] & RATE_MASK
;
7410 basic_phy_rate
= rate_info
[basic_rate
] & RATE_MASK
;
7411 index
= phy_rate
& 0xf;
7412 basic_index
= basic_phy_rate
& 0xf;
7414 /* Find the SHM pointer to the ACK rate entry by looking in the
7417 basic_ptr
= wlc_read_shm(wlc
, (dir_table
+ basic_index
* 2));
7419 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7420 * to the correct basic rate for the given incoming rate
7422 wlc_write_shm(wlc
, (basic_table
+ index
* 2), basic_ptr
);
7425 static const wlc_rateset_t
*wlc_rateset_get_hwrs(struct wlc_info
*wlc
)
7427 const wlc_rateset_t
*rs_dflt
;
7429 if (WLC_PHY_11N_CAP(wlc
->band
)) {
7430 if (BAND_5G(wlc
->band
->bandtype
))
7431 rs_dflt
= &ofdm_mimo_rates
;
7433 rs_dflt
= &cck_ofdm_mimo_rates
;
7434 } else if (wlc
->band
->gmode
)
7435 rs_dflt
= &cck_ofdm_rates
;
7437 rs_dflt
= &cck_rates
;
7442 void wlc_set_ratetable(struct wlc_info
*wlc
)
7444 const wlc_rateset_t
*rs_dflt
;
7446 u8 rate
, basic_rate
;
7449 rs_dflt
= wlc_rateset_get_hwrs(wlc
);
7450 ASSERT(rs_dflt
!= NULL
);
7452 wlc_rateset_copy(rs_dflt
, &rs
);
7453 wlc_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7455 /* walk the phy rate table and update SHM basic rate lookup table */
7456 for (i
= 0; i
< rs
.count
; i
++) {
7457 rate
= rs
.rates
[i
] & RATE_MASK
;
7459 /* for a given rate WLC_BASIC_RATE returns the rate at
7460 * which a response ACK/CTS should be sent.
7462 basic_rate
= WLC_BASIC_RATE(wlc
, rate
);
7463 if (basic_rate
== 0) {
7464 /* This should only happen if we are using a
7465 * restricted rateset.
7467 basic_rate
= rs
.rates
[0] & RATE_MASK
;
7470 wlc_write_rate_shm(wlc
, rate
, basic_rate
);
7475 * Return true if the specified rate is supported by the specified band.
7476 * WLC_BAND_AUTO indicates the current band.
7478 bool wlc_valid_rate(struct wlc_info
*wlc
, ratespec_t rspec
, int band
,
7481 wlc_rateset_t
*hw_rateset
;
7484 if ((band
== WLC_BAND_AUTO
) || (band
== wlc
->band
->bandtype
)) {
7485 hw_rateset
= &wlc
->band
->hw_rateset
;
7486 } else if (NBANDS(wlc
) > 1) {
7487 hw_rateset
= &wlc
->bandstate
[OTHERBANDUNIT(wlc
)]->hw_rateset
;
7489 /* other band specified and we are a single band device */
7493 /* check if this is a mimo rate */
7494 if (IS_MCS(rspec
)) {
7495 if (!VALID_MCS((rspec
& RSPEC_RATE_MASK
)))
7498 return isset(hw_rateset
->mcs
, (rspec
& RSPEC_RATE_MASK
));
7501 for (i
= 0; i
< hw_rateset
->count
; i
++)
7502 if (hw_rateset
->rates
[i
] == RSPEC2RATE(rspec
))
7506 WL_ERROR("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n",
7507 wlc
->pub
->unit
, rspec
);
7513 static void wlc_update_mimo_band_bwcap(struct wlc_info
*wlc
, u8 bwcap
)
7516 struct wlcband
*band
;
7518 for (i
= 0; i
< NBANDS(wlc
); i
++) {
7519 if (IS_SINGLEBAND_5G(wlc
->deviceid
))
7521 band
= wlc
->bandstate
[i
];
7522 if (band
->bandtype
== WLC_BAND_5G
) {
7523 if ((bwcap
== WLC_N_BW_40ALL
)
7524 || (bwcap
== WLC_N_BW_20IN2G_40IN5G
))
7525 band
->mimo_cap_40
= true;
7527 band
->mimo_cap_40
= false;
7529 ASSERT(band
->bandtype
== WLC_BAND_2G
);
7530 if (bwcap
== WLC_N_BW_40ALL
)
7531 band
->mimo_cap_40
= true;
7533 band
->mimo_cap_40
= false;
7537 wlc
->mimo_band_bwcap
= bwcap
;
7540 void wlc_mod_prb_rsp_rate_table(struct wlc_info
*wlc
, uint frame_len
)
7542 const wlc_rateset_t
*rs_dflt
;
7546 u8 plcp
[D11_PHY_HDR_LEN
];
7550 sifs
= SIFS(wlc
->band
);
7552 rs_dflt
= wlc_rateset_get_hwrs(wlc
);
7553 ASSERT(rs_dflt
!= NULL
);
7555 wlc_rateset_copy(rs_dflt
, &rs
);
7556 wlc_rateset_mcs_upd(&rs
, wlc
->stf
->txstreams
);
7558 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7559 for (i
= 0; i
< rs
.count
; i
++) {
7560 rate
= rs
.rates
[i
] & RATE_MASK
;
7562 entry_ptr
= wlc_rate_shm_offset(wlc
, rate
);
7564 /* Calculate the Probe Response PLCP for the given rate */
7565 wlc_compute_plcp(wlc
, rate
, frame_len
, plcp
);
7567 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7569 (u16
) wlc_calc_frame_time(wlc
, rate
, WLC_LONG_PREAMBLE
,
7573 /* Update the SHM Rate Table entry Probe Response values */
7574 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_PLCP_POS
,
7575 (u16
) (plcp
[0] + (plcp
[1] << 8)));
7576 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_PLCP_POS
+ 2,
7577 (u16
) (plcp
[2] + (plcp
[3] << 8)));
7578 wlc_write_shm(wlc
, entry_ptr
+ M_RT_PRS_DUR_POS
, dur
);
7583 wlc_compute_bcntsfoff(struct wlc_info
*wlc
, ratespec_t rspec
,
7584 bool short_preamble
, bool phydelay
)
7588 if (IS_MCS(rspec
)) {
7589 WL_ERROR("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7590 wlc
->pub
->unit
, rspec
);
7591 } else if (IS_OFDM(rspec
)) {
7592 /* tx delay from MAC through phy to air (2.1 usec) +
7593 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7594 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7595 * bytes at beacon rate)
7597 bcntsfoff
+= phydelay
? D11A_PHY_TX_DELAY
: 0;
7598 bcntsfoff
+= APHY_PREAMBLE_TIME
+ APHY_SIGNAL_TIME
;
7600 wlc_compute_airtime(wlc
, rspec
,
7601 APHY_SERVICE_NBITS
/ 8 +
7604 /* tx delay from MAC through phy to air (3.4 usec) +
7605 * phy header time (long preamble + PLCP == 192 usec) +
7606 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7608 bcntsfoff
+= phydelay
? D11B_PHY_TX_DELAY
: 0;
7610 short_preamble
? D11B_PHY_SPREHDR_TIME
:
7611 D11B_PHY_LPREHDR_TIME
;
7612 bcntsfoff
+= wlc_compute_airtime(wlc
, rspec
, DOT11_MAC_HDR_LEN
);
7614 return (u16
) (bcntsfoff
);
7617 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7619 * PLCP header is 6 bytes.
7620 * 802.11 A3 header is 24 bytes.
7621 * Max beacon frame body template length is 112 bytes.
7622 * Max probe resp frame body template length is 110 bytes.
7624 * *len on input contains the max length of the packet available.
7626 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7627 * and included up to, but not including, the 4 byte FCS.
7630 wlc_bcn_prb_template(struct wlc_info
*wlc
, uint type
, ratespec_t bcn_rspec
,
7631 wlc_bsscfg_t
*cfg
, u16
*buf
, int *len
)
7633 static const u8 ether_bcast
[ETH_ALEN
] = {255, 255, 255, 255, 255, 255};
7634 cck_phy_hdr_t
*plcp
;
7635 struct ieee80211_mgmt
*h
;
7636 int hdr_len
, body_len
;
7638 ASSERT(*len
>= 142);
7639 ASSERT(type
== FC_BEACON
|| type
== FC_PROBE_RESP
);
7641 if (MBSS_BCN_ENAB(cfg
) && type
== FC_BEACON
)
7642 hdr_len
= DOT11_MAC_HDR_LEN
;
7644 hdr_len
= D11_PHY_HDR_LEN
+ DOT11_MAC_HDR_LEN
;
7645 body_len
= *len
- hdr_len
; /* calc buffer size provided for frame body */
7647 *len
= hdr_len
+ body_len
; /* return actual size */
7649 /* format PHY and MAC headers */
7650 memset((char *)buf
, 0, hdr_len
);
7652 plcp
= (cck_phy_hdr_t
*) buf
;
7654 /* PLCP for Probe Response frames are filled in from core's rate table */
7655 if (type
== FC_BEACON
&& !MBSS_BCN_ENAB(cfg
)) {
7657 wlc_compute_plcp(wlc
, bcn_rspec
,
7658 (DOT11_MAC_HDR_LEN
+ body_len
+ FCS_LEN
),
7662 /* "Regular" and 16 MBSS but not for 4 MBSS */
7663 /* Update the phytxctl for the beacon based on the rspec */
7664 if (!SOFTBCN_ENAB(cfg
))
7665 wlc_beacon_phytxctl_txant_upd(wlc
, bcn_rspec
);
7667 if (MBSS_BCN_ENAB(cfg
) && type
== FC_BEACON
)
7668 h
= (struct ieee80211_mgmt
*)&plcp
[0];
7670 h
= (struct ieee80211_mgmt
*)&plcp
[1];
7672 /* fill in 802.11 header */
7673 h
->frame_control
= htol16((u16
) type
);
7675 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7676 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7677 if (type
== FC_BEACON
)
7678 bcopy((const char *)ðer_bcast
, (char *)&h
->da
,
7680 bcopy((char *)&cfg
->cur_etheraddr
, (char *)&h
->sa
, ETH_ALEN
);
7681 bcopy((char *)&cfg
->BSSID
, (char *)&h
->bssid
, ETH_ALEN
);
7683 /* SEQ filled in by MAC */
7688 int wlc_get_header_len()
7693 /* Update a beacon for a particular BSS
7694 * For MBSS, this updates the software template and sets "latest" to the index of the
7696 * Otherwise, it updates the hardware template.
7698 void wlc_bss_update_beacon(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
)
7700 int len
= BCN_TMPL_LEN
;
7702 /* Clear the soft intmask */
7703 wlc
->defmacintmask
&= ~MI_BCNTPL
;
7705 if (!cfg
->up
) { /* Only allow updates on an UP bss */
7709 if (MBSS_BCN_ENAB(cfg
)) { /* Optimize: Some of if/else could be combined */
7710 } else if (HWBCN_ENAB(cfg
)) { /* Hardware beaconing for this config */
7711 u16 bcn
[BCN_TMPL_LEN
/ 2];
7712 u32 both_valid
= MCMD_BCN0VLD
| MCMD_BCN1VLD
;
7713 d11regs_t
*regs
= wlc
->regs
;
7714 struct osl_info
*osh
= NULL
;
7718 /* Check if both templates are in use, if so sched. an interrupt
7719 * that will call back into this routine
7721 if ((R_REG(osh
, ®s
->maccommand
) & both_valid
) == both_valid
) {
7722 /* clear any previous status */
7723 W_REG(osh
, ®s
->macintstatus
, MI_BCNTPL
);
7725 /* Check that after scheduling the interrupt both of the
7726 * templates are still busy. if not clear the int. & remask
7728 if ((R_REG(osh
, ®s
->maccommand
) & both_valid
) == both_valid
) {
7729 wlc
->defmacintmask
|= MI_BCNTPL
;
7734 wlc_lowest_basic_rspec(wlc
, &cfg
->current_bss
->rateset
);
7735 ASSERT(wlc_valid_rate
7736 (wlc
, wlc
->bcn_rspec
,
7737 CHSPEC_IS2G(cfg
->current_bss
->
7738 chanspec
) ? WLC_BAND_2G
: WLC_BAND_5G
,
7741 /* update the template and ucode shm */
7742 wlc_bcn_prb_template(wlc
, FC_BEACON
, wlc
->bcn_rspec
, cfg
, bcn
,
7744 wlc_write_hw_bcntemplates(wlc
, bcn
, len
, false);
7749 * Update all beacons for the system.
7751 void wlc_update_beacon(struct wlc_info
*wlc
)
7754 wlc_bsscfg_t
*bsscfg
;
7756 /* update AP or IBSS beacons */
7757 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7758 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7759 wlc_bss_update_beacon(wlc
, bsscfg
);
7763 /* Write ssid into shared memory */
7764 void wlc_shm_ssid_upd(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
)
7766 u8
*ssidptr
= cfg
->SSID
;
7768 u8 ssidbuf
[IEEE80211_MAX_SSID_LEN
];
7770 /* padding the ssid with zero and copy it into shm */
7771 memset(ssidbuf
, 0, IEEE80211_MAX_SSID_LEN
);
7772 bcopy(ssidptr
, ssidbuf
, cfg
->SSID_len
);
7774 wlc_copyto_shm(wlc
, base
, ssidbuf
, IEEE80211_MAX_SSID_LEN
);
7776 if (!MBSS_BCN_ENAB(cfg
))
7777 wlc_write_shm(wlc
, M_SSIDLEN
, (u16
) cfg
->SSID_len
);
7780 void wlc_update_probe_resp(struct wlc_info
*wlc
, bool suspend
)
7783 wlc_bsscfg_t
*bsscfg
;
7785 /* update AP or IBSS probe responses */
7786 FOREACH_BSS(wlc
, idx
, bsscfg
) {
7787 if (bsscfg
->up
&& (BSSCFG_AP(bsscfg
) || !bsscfg
->BSS
))
7788 wlc_bss_update_probe_resp(wlc
, bsscfg
, suspend
);
7793 wlc_bss_update_probe_resp(struct wlc_info
*wlc
, wlc_bsscfg_t
*cfg
, bool suspend
)
7795 u16 prb_resp
[BCN_TMPL_LEN
/ 2];
7796 int len
= BCN_TMPL_LEN
;
7798 /* write the probe response to hardware, or save in the config structure */
7799 if (!MBSS_PRB_ENAB(cfg
)) {
7801 /* create the probe response template */
7802 wlc_bcn_prb_template(wlc
, FC_PROBE_RESP
, 0, cfg
, prb_resp
,
7806 wlc_suspend_mac_and_wait(wlc
);
7808 /* write the probe response into the template region */
7809 wlc_bmac_write_template_ram(wlc
->hw
, T_PRS_TPL_BASE
,
7810 (len
+ 3) & ~3, prb_resp
);
7812 /* write the length of the probe response frame (+PLCP/-FCS) */
7813 wlc_write_shm(wlc
, M_PRB_RESP_FRM_LEN
, (u16
) len
);
7815 /* write the SSID and SSID length */
7816 wlc_shm_ssid_upd(wlc
, cfg
);
7819 * Write PLCP headers and durations for probe response frames at all rates.
7820 * Use the actual frame length covered by the PLCP header for the call to
7821 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7823 len
+= (-D11_PHY_HDR_LEN
+ FCS_LEN
);
7824 wlc_mod_prb_rsp_rate_table(wlc
, (u16
) len
);
7827 wlc_enable_mac(wlc
);
7828 } else { /* Generating probe resp in sw; update local template */
7829 ASSERT(0 && "No software probe response support without MBSS");
7833 /* prepares pdu for transmission. returns BCM error codes */
7834 int wlc_prep_pdu(struct wlc_info
*wlc
, struct sk_buff
*pdu
, uint
*fifop
)
7836 struct osl_info
*osh
;
7839 struct ieee80211_hdr
*h
;
7846 txh
= (d11txh_t
*) (pdu
->data
);
7848 h
= (struct ieee80211_hdr
*)((u8
*) (txh
+ 1) + D11_PHY_HDR_LEN
);
7850 fc
= ltoh16(h
->frame_control
);
7852 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7853 fifo
= ltoh16(txh
->TxFrameID
) & TXFID_QUEUE_MASK
;
7859 /* return if insufficient dma resources */
7860 if (TXAVAIL(wlc
, fifo
) < MAX_DMA_SEGS
) {
7861 /* Mark precedences related to this FIFO, unsendable */
7862 WLC_TX_FIFO_CLEAR(wlc
, fifo
);
7866 if ((ltoh16(txh
->MacFrameControl
) & IEEE80211_FCTL_FTYPE
) !=
7867 IEEE80211_FTYPE_DATA
)
7868 WLCNTINCR(wlc
->pub
->_cnt
->txctl
);
7873 /* init tx reported rate mechanism */
7874 void wlc_reprate_init(struct wlc_info
*wlc
)
7877 wlc_bsscfg_t
*bsscfg
;
7879 FOREACH_BSS(wlc
, i
, bsscfg
) {
7880 wlc_bsscfg_reprate_init(bsscfg
);
7884 /* per bsscfg init tx reported rate mechanism */
7885 void wlc_bsscfg_reprate_init(wlc_bsscfg_t
*bsscfg
)
7887 bsscfg
->txrspecidx
= 0;
7888 memset((char *)bsscfg
->txrspec
, 0, sizeof(bsscfg
->txrspec
));
7891 /* Retrieve a consolidated set of revision information,
7892 * typically for the WLC_GET_REVINFO ioctl
7894 int wlc_get_revision_info(struct wlc_info
*wlc
, void *buf
, uint len
)
7896 wlc_rev_info_t
*rinfo
= (wlc_rev_info_t
*) buf
;
7898 if (len
< WL_REV_INFO_LEGACY_LENGTH
)
7899 return BCME_BUFTOOSHORT
;
7901 rinfo
->vendorid
= wlc
->vendorid
;
7902 rinfo
->deviceid
= wlc
->deviceid
;
7903 rinfo
->radiorev
= (wlc
->band
->radiorev
<< IDCODE_REV_SHIFT
) |
7904 (wlc
->band
->radioid
<< IDCODE_ID_SHIFT
);
7905 rinfo
->chiprev
= wlc
->pub
->sih
->chiprev
;
7906 rinfo
->corerev
= wlc
->pub
->corerev
;
7907 rinfo
->boardid
= wlc
->pub
->sih
->boardtype
;
7908 rinfo
->boardvendor
= wlc
->pub
->sih
->boardvendor
;
7909 rinfo
->boardrev
= wlc
->pub
->boardrev
;
7910 rinfo
->ucoderev
= wlc
->ucode_rev
;
7911 rinfo
->driverrev
= EPI_VERSION_NUM
;
7912 rinfo
->bus
= wlc
->pub
->sih
->bustype
;
7913 rinfo
->chipnum
= wlc
->pub
->sih
->chip
;
7915 if (len
>= (offsetof(wlc_rev_info_t
, chippkg
))) {
7916 rinfo
->phytype
= wlc
->band
->phytype
;
7917 rinfo
->phyrev
= wlc
->band
->phyrev
;
7918 rinfo
->anarev
= 0; /* obsolete stuff, suppress */
7921 if (len
>= sizeof(*rinfo
)) {
7922 rinfo
->chippkg
= wlc
->pub
->sih
->chippkg
;
7928 void wlc_default_rateset(struct wlc_info
*wlc
, wlc_rateset_t
*rs
)
7930 wlc_rateset_default(rs
, NULL
, wlc
->band
->phytype
, wlc
->band
->bandtype
,
7931 false, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
7932 CHSPEC_WLC_BW(wlc
->default_bss
->chanspec
),
7933 wlc
->stf
->txstreams
);
7936 static void wlc_bss_default_init(struct wlc_info
*wlc
)
7938 chanspec_t chanspec
;
7939 struct wlcband
*band
;
7940 wlc_bss_info_t
*bi
= wlc
->default_bss
;
7942 /* init default and target BSS with some sane initial values */
7943 memset((char *)(bi
), 0, sizeof(wlc_bss_info_t
));
7944 bi
->beacon_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? BEACON_INTERVAL_DEF_QT
:
7945 BEACON_INTERVAL_DEFAULT
;
7946 bi
->dtim_period
= ISSIM_ENAB(wlc
->pub
->sih
) ? DTIM_INTERVAL_DEF_QT
:
7947 DTIM_INTERVAL_DEFAULT
;
7949 /* fill the default channel as the first valid channel
7950 * starting from the 2G channels
7952 chanspec
= CH20MHZ_CHSPEC(1);
7953 ASSERT(chanspec
!= INVCHANSPEC
);
7955 wlc
->home_chanspec
= bi
->chanspec
= chanspec
;
7957 /* find the band of our default channel */
7959 if (NBANDS(wlc
) > 1 && band
->bandunit
!= CHSPEC_WLCBANDUNIT(chanspec
))
7960 band
= wlc
->bandstate
[OTHERBANDUNIT(wlc
)];
7962 /* init bss rates to the band specific default rate set */
7963 wlc_rateset_default(&bi
->rateset
, NULL
, band
->phytype
, band
->bandtype
,
7964 false, RATE_MASK_FULL
, (bool) N_ENAB(wlc
->pub
),
7965 CHSPEC_WLC_BW(chanspec
), wlc
->stf
->txstreams
);
7967 if (N_ENAB(wlc
->pub
))
7968 bi
->flags
|= WLC_BSS_HT
;
7971 /* Deferred event processing */
7972 static void wlc_process_eventq(void *arg
)
7974 struct wlc_info
*wlc
= (struct wlc_info
*) arg
;
7977 while ((etmp
= wlc_eventq_deq(wlc
->eventq
))) {
7978 /* Perform OS specific event processing */
7979 wl_event(wlc
->wl
, etmp
->event
.ifname
, etmp
);
7984 wlc_event_free(wlc
->eventq
, etmp
);
7989 wlc_uint64_sub(u32
*a_high
, u32
*a_low
, u32 b_high
, u32 b_low
)
7991 if (b_low
> *a_low
) {
7992 /* low half needs a carry */
8000 mac80211_wlc_set_nrate(struct wlc_info
*wlc
, struct wlcband
*cur_band
,
8003 u8 stf
= (int_val
& NRATE_STF_MASK
) >> NRATE_STF_SHIFT
;
8004 u8 rate
= int_val
& NRATE_RATE_MASK
;
8006 bool ismcs
= ((int_val
& NRATE_MCS_INUSE
) == NRATE_MCS_INUSE
);
8007 bool issgi
= ((int_val
& NRATE_SGI_MASK
) >> NRATE_SGI_SHIFT
);
8008 bool override_mcs_only
= ((int_val
& NRATE_OVERRIDE_MCS_ONLY
)
8009 == NRATE_OVERRIDE_MCS_ONLY
);
8013 return (ratespec_t
) rate
;
8016 /* validate the combination of rate/mcs/stf is allowed */
8017 if (N_ENAB(wlc
->pub
) && ismcs
) {
8018 /* mcs only allowed when nmode */
8019 if (stf
> PHY_TXC1_MODE_SDM
) {
8020 WL_ERROR("wl%d: %s: Invalid stf\n",
8021 WLCWLUNIT(wlc
), __func__
);
8022 bcmerror
= BCME_RANGE
;
8026 /* mcs 32 is a special case, DUP mode 40 only */
8028 if (!CHSPEC_IS40(wlc
->home_chanspec
) ||
8029 ((stf
!= PHY_TXC1_MODE_SISO
)
8030 && (stf
!= PHY_TXC1_MODE_CDD
))) {
8031 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8032 WLCWLUNIT(wlc
), __func__
);
8033 bcmerror
= BCME_RANGE
;
8036 /* mcs > 7 must use stf SDM */
8037 } else if (rate
> HIGHEST_SINGLE_STREAM_MCS
) {
8038 /* mcs > 7 must use stf SDM */
8039 if (stf
!= PHY_TXC1_MODE_SDM
) {
8040 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8041 WLCWLUNIT(wlc
), __func__
, rate
);
8042 stf
= PHY_TXC1_MODE_SDM
;
8045 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8046 if ((stf
> PHY_TXC1_MODE_STBC
) ||
8047 (!WLC_STBC_CAP_PHY(wlc
)
8048 && (stf
== PHY_TXC1_MODE_STBC
))) {
8049 WL_ERROR("wl%d: %s: Invalid STBC\n",
8050 WLCWLUNIT(wlc
), __func__
);
8051 bcmerror
= BCME_RANGE
;
8055 } else if (IS_OFDM(rate
)) {
8056 if ((stf
!= PHY_TXC1_MODE_CDD
) && (stf
!= PHY_TXC1_MODE_SISO
)) {
8057 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8058 WLCWLUNIT(wlc
), __func__
);
8059 bcmerror
= BCME_RANGE
;
8062 } else if (IS_CCK(rate
)) {
8063 if ((cur_band
->bandtype
!= WLC_BAND_2G
)
8064 || (stf
!= PHY_TXC1_MODE_SISO
)) {
8065 WL_ERROR("wl%d: %s: Invalid CCK\n",
8066 WLCWLUNIT(wlc
), __func__
);
8067 bcmerror
= BCME_RANGE
;
8071 WL_ERROR("wl%d: %s: Unknown rate type\n",
8072 WLCWLUNIT(wlc
), __func__
);
8073 bcmerror
= BCME_RANGE
;
8076 /* make sure multiple antennae are available for non-siso rates */
8077 if ((stf
!= PHY_TXC1_MODE_SISO
) && (wlc
->stf
->txstreams
== 1)) {
8078 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8079 WLCWLUNIT(wlc
), __func__
);
8080 bcmerror
= BCME_RANGE
;
8086 rspec
|= RSPEC_MIMORATE
;
8087 /* For STBC populate the STC field of the ratespec */
8088 if (stf
== PHY_TXC1_MODE_STBC
) {
8090 stc
= 1; /* Nss for single stream is always 1 */
8091 rspec
|= (stc
<< RSPEC_STC_SHIFT
);
8095 rspec
|= (stf
<< RSPEC_STF_SHIFT
);
8097 if (override_mcs_only
)
8098 rspec
|= RSPEC_OVERRIDE_MCS_ONLY
;
8101 rspec
|= RSPEC_SHORT_GI
;
8104 && !wlc_valid_rate(wlc
, rspec
, cur_band
->bandtype
, true)) {
8110 WL_ERROR("Hoark\n");
8114 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8116 wlc_duty_cycle_set(struct wlc_info
*wlc
, int duty_cycle
, bool isOFDM
,
8119 int idle_busy_ratio_x_16
= 0;
8121 isOFDM
? M_TX_IDLE_BUSY_RATIO_X_16_OFDM
:
8122 M_TX_IDLE_BUSY_RATIO_X_16_CCK
;
8123 if (duty_cycle
> 100 || duty_cycle
< 0) {
8124 WL_ERROR("wl%d: duty cycle value off limit\n", wlc
->pub
->unit
);
8128 idle_busy_ratio_x_16
= (100 - duty_cycle
) * 16 / duty_cycle
;
8129 /* Only write to shared memory when wl is up */
8131 wlc_write_shm(wlc
, offset
, (u16
) idle_busy_ratio_x_16
);
8134 wlc
->tx_duty_cycle_ofdm
= (u16
) duty_cycle
;
8136 wlc
->tx_duty_cycle_cck
= (u16
) duty_cycle
;
8141 /* Read a single u16 from shared memory.
8142 * SHM 'offset' needs to be an even address
8144 u16
wlc_read_shm(struct wlc_info
*wlc
, uint offset
)
8146 return wlc_bmac_read_shm(wlc
->hw
, offset
);
8149 /* Write a single u16 to shared memory.
8150 * SHM 'offset' needs to be an even address
8152 void wlc_write_shm(struct wlc_info
*wlc
, uint offset
, u16 v
)
8154 wlc_bmac_write_shm(wlc
->hw
, offset
, v
);
8157 /* Set a range of shared memory to a value.
8158 * SHM 'offset' needs to be an even address and
8159 * Range length 'len' must be an even number of bytes
8161 void wlc_set_shm(struct wlc_info
*wlc
, uint offset
, u16 v
, int len
)
8163 /* offset and len need to be even */
8164 ASSERT((offset
& 1) == 0);
8165 ASSERT((len
& 1) == 0);
8170 wlc_bmac_set_shm(wlc
->hw
, offset
, v
, len
);
8173 /* Copy a buffer to shared memory.
8174 * SHM 'offset' needs to be an even address and
8175 * Buffer length 'len' must be an even number of bytes
8177 void wlc_copyto_shm(struct wlc_info
*wlc
, uint offset
, const void *buf
, int len
)
8179 /* offset and len need to be even */
8180 ASSERT((offset
& 1) == 0);
8181 ASSERT((len
& 1) == 0);
8185 wlc_bmac_copyto_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8189 /* Copy from shared memory to a buffer.
8190 * SHM 'offset' needs to be an even address and
8191 * Buffer length 'len' must be an even number of bytes
8193 void wlc_copyfrom_shm(struct wlc_info
*wlc
, uint offset
, void *buf
, int len
)
8195 /* offset and len need to be even */
8196 ASSERT((offset
& 1) == 0);
8197 ASSERT((len
& 1) == 0);
8202 wlc_bmac_copyfrom_objmem(wlc
->hw
, offset
, buf
, len
, OBJADDR_SHM_SEL
);
8205 /* wrapper BMAC functions to for HIGH driver access */
8206 void wlc_mctrl(struct wlc_info
*wlc
, u32 mask
, u32 val
)
8208 wlc_bmac_mctrl(wlc
->hw
, mask
, val
);
8211 void wlc_corereset(struct wlc_info
*wlc
, u32 flags
)
8213 wlc_bmac_corereset(wlc
->hw
, flags
);
8216 void wlc_mhf(struct wlc_info
*wlc
, u8 idx
, u16 mask
, u16 val
, int bands
)
8218 wlc_bmac_mhf(wlc
->hw
, idx
, mask
, val
, bands
);
8221 u16
wlc_mhf_get(struct wlc_info
*wlc
, u8 idx
, int bands
)
8223 return wlc_bmac_mhf_get(wlc
->hw
, idx
, bands
);
8226 int wlc_xmtfifo_sz_get(struct wlc_info
*wlc
, uint fifo
, uint
*blocks
)
8228 return wlc_bmac_xmtfifo_sz_get(wlc
->hw
, fifo
, blocks
);
8231 void wlc_write_template_ram(struct wlc_info
*wlc
, int offset
, int len
,
8234 wlc_bmac_write_template_ram(wlc
->hw
, offset
, len
, buf
);
8237 void wlc_write_hw_bcntemplates(struct wlc_info
*wlc
, void *bcn
, int len
,
8240 wlc_bmac_write_hw_bcntemplates(wlc
->hw
, bcn
, len
, both
);
8244 wlc_set_addrmatch(struct wlc_info
*wlc
, int match_reg_offset
,
8247 wlc_bmac_set_addrmatch(wlc
->hw
, match_reg_offset
, addr
);
8250 void wlc_set_rcmta(struct wlc_info
*wlc
, int idx
, const u8
*addr
)
8252 wlc_bmac_set_rcmta(wlc
->hw
, idx
, addr
);
8255 void wlc_read_tsf(struct wlc_info
*wlc
, u32
*tsf_l_ptr
, u32
*tsf_h_ptr
)
8257 wlc_bmac_read_tsf(wlc
->hw
, tsf_l_ptr
, tsf_h_ptr
);
8260 void wlc_set_cwmin(struct wlc_info
*wlc
, u16 newmin
)
8262 wlc
->band
->CWmin
= newmin
;
8263 wlc_bmac_set_cwmin(wlc
->hw
, newmin
);
8266 void wlc_set_cwmax(struct wlc_info
*wlc
, u16 newmax
)
8268 wlc
->band
->CWmax
= newmax
;
8269 wlc_bmac_set_cwmax(wlc
->hw
, newmax
);
8272 void wlc_fifoerrors(struct wlc_info
*wlc
)
8275 wlc_bmac_fifoerrors(wlc
->hw
);
8278 /* Search mem rw utilities */
8280 void wlc_pllreq(struct wlc_info
*wlc
, bool set
, mbool req_bit
)
8282 wlc_bmac_pllreq(wlc
->hw
, set
, req_bit
);
8285 void wlc_reset_bmac_done(struct wlc_info
*wlc
)
8289 void wlc_ht_mimops_cap_update(struct wlc_info
*wlc
, u8 mimops_mode
)
8291 wlc
->ht_cap
.cap_info
&= ~HT_CAP_MIMO_PS_MASK
;
8292 wlc
->ht_cap
.cap_info
|= (mimops_mode
<< IEEE80211_HT_CAP_SM_PS_SHIFT
);
8294 if (AP_ENAB(wlc
->pub
) && wlc
->clk
) {
8295 wlc_update_beacon(wlc
);
8296 wlc_update_probe_resp(wlc
, true);
8300 /* check for the particular priority flow control bit being set */
8302 wlc_txflowcontrol_prio_isset(struct wlc_info
*wlc
, wlc_txq_info_t
*q
, int prio
)
8306 if (prio
== ALLPRIO
) {
8307 prio_mask
= TXQ_STOP_FOR_PRIOFC_MASK
;
8309 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8310 prio_mask
= NBITVAL(prio
);
8313 return (q
->stopped
& prio_mask
) == prio_mask
;
8316 /* propogate the flow control to all interfaces using the given tx queue */
8317 void wlc_txflowcontrol(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
,
8323 WL_ERROR("%s: flow control kicks in\n", __func__
);
8325 if (prio
== ALLPRIO
) {
8326 prio_bits
= TXQ_STOP_FOR_PRIOFC_MASK
;
8328 ASSERT(prio
>= 0 && prio
<= MAXPRIO
);
8329 prio_bits
= NBITVAL(prio
);
8332 cur_bits
= qi
->stopped
& prio_bits
;
8334 /* Check for the case of no change and return early
8335 * Otherwise update the bit and continue
8338 if (cur_bits
== prio_bits
) {
8341 mboolset(qi
->stopped
, prio_bits
);
8343 if (cur_bits
== 0) {
8346 mboolclr(qi
->stopped
, prio_bits
);
8349 /* If there is a flow control override we will not change the external
8350 * flow control state.
8352 if (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
) {
8356 wlc_txflowcontrol_signal(wlc
, qi
, on
, prio
);
8360 wlc_txflowcontrol_override(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
, bool on
,
8365 ASSERT(override
!= 0);
8366 ASSERT((override
& TXQ_STOP_FOR_PRIOFC_MASK
) == 0);
8368 prev_override
= (qi
->stopped
& ~TXQ_STOP_FOR_PRIOFC_MASK
);
8370 /* Update the flow control bits and do an early return if there is
8371 * no change in the external flow control state.
8374 mboolset(qi
->stopped
, override
);
8375 /* if there was a previous override bit on, then setting this
8376 * makes no difference.
8378 if (prev_override
) {
8382 wlc_txflowcontrol_signal(wlc
, qi
, ON
, ALLPRIO
);
8384 mboolclr(qi
->stopped
, override
);
8385 /* clearing an override bit will only make a difference for
8386 * flow control if it was the only bit set. For any other
8387 * override setting, just return
8389 if (prev_override
!= override
) {
8393 if (qi
->stopped
== 0) {
8394 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8398 for (prio
= MAXPRIO
; prio
>= 0; prio
--) {
8399 if (!mboolisset(qi
->stopped
, NBITVAL(prio
)))
8400 wlc_txflowcontrol_signal(wlc
, qi
, OFF
,
8407 static void wlc_txflowcontrol_reset(struct wlc_info
*wlc
)
8411 for (qi
= wlc
->tx_queues
; qi
!= NULL
; qi
= qi
->next
) {
8413 wlc_txflowcontrol_signal(wlc
, qi
, OFF
, ALLPRIO
);
8420 wlc_txflowcontrol_signal(struct wlc_info
*wlc
, wlc_txq_info_t
*qi
, bool on
,
8423 struct wlc_if
*wlcif
;
8425 for (wlcif
= wlc
->wlcif_list
; wlcif
!= NULL
; wlcif
= wlcif
->next
) {
8426 if (wlcif
->qi
== qi
&& wlcif
->flags
& WLC_IF_LINKED
)
8427 wl_txflowcontrol(wlc
->wl
, wlcif
->wlif
, on
, prio
);
8431 static wlc_txq_info_t
*wlc_txq_alloc(struct wlc_info
*wlc
, struct osl_info
*osh
)
8433 wlc_txq_info_t
*qi
, *p
;
8435 qi
= (wlc_txq_info_t
*) wlc_calloc(osh
, wlc
->pub
->unit
,
8436 sizeof(wlc_txq_info_t
));
8441 /* Have enough room for control packets along with HI watermark */
8442 /* Also, add room to txq for total psq packets if all the SCBs leave PS mode */
8443 /* The watermark for flowcontrol to OS packets will remain the same */
8444 pktq_init(&qi
->q
, WLC_PREC_COUNT
,
8445 (2 * wlc
->pub
->tunables
->datahiwat
) + PKTQ_LEN_DEFAULT
+
8446 wlc
->pub
->psq_pkts_total
);
8448 /* add this queue to the the global list */
8451 wlc
->tx_queues
= qi
;
8453 while (p
->next
!= NULL
)
8461 static void wlc_txq_free(struct wlc_info
*wlc
, struct osl_info
*osh
,
8469 /* remove the queue from the linked list */
8472 wlc
->tx_queues
= p
->next
;
8474 while (p
!= NULL
&& p
->next
!= qi
)
8476 ASSERT(p
->next
== qi
);
8478 p
->next
= p
->next
->next
;