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