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