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