xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/bcm_app_utils.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Misc utility routines used by kernel or app-level.
3  * Contents are wifi-specific, used by any kernel or app-level
4  * software that might want wifi things as it grows.
5  *
6  * Copyright (C) 2020, Broadcom.
7  *
8  *      Unless you and Broadcom execute a separate written software license
9  * agreement governing use of this software, this software is licensed to you
10  * under the terms of the GNU General Public License version 2 (the "GPL"),
11  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12  * following added to such license:
13  *
14  *      As a special exception, the copyright holders of this software give you
15  * permission to link this software with independent modules, and to copy and
16  * distribute the resulting executable under terms of your choice, provided that
17  * you also meet, for each linked independent module, the terms and conditions of
18  * the license of that module.  An independent module is a module which is not
19  * derived from this software.  The special exception does not apply to any
20  * modifications of the software.
21  *
22  *
23  * <<Broadcom-WL-IPTag/Dual:>>
24  */
25 
26 #include <typedefs.h>
27 
28 #ifdef BCMDRIVER
29 #include <osl.h>
30 #define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
31 #define tolower(c) (bcm_isupper((c)) ? ((c) + 'a' - 'A') : (c))
32 #else /* BCMDRIVER */
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37 #ifndef ASSERT
38 #define ASSERT(exp)
39 #endif
40 #endif /* BCMDRIVER */
41 #include <bcmwifi_channels.h>
42 
43 #if defined(WIN32) && (defined(BCMDLL) || defined(WLMDLL))
44 #include <bcmstdlib.h>	/* For wlexe/Makefile.wlm_dll */
45 #endif
46 
47 #include <bcmutils.h>
48 #include <wlioctl.h>
49 #include <wlioctl_utils.h>
50 
51 #ifndef BCMDRIVER
52 /*	Take an array of measurments representing a single channel over time and return
53 	a summary. Currently implemented as a simple average but could easily evolve
54 	into more cpomplex alogrithms.
55 */
56 cca_congest_channel_req_t *
cca_per_chan_summary(cca_congest_channel_req_t * input,cca_congest_channel_req_t * avg,bool percent)57 cca_per_chan_summary(cca_congest_channel_req_t *input, cca_congest_channel_req_t *avg, bool percent)
58 {
59 	int sec;
60 	cca_congest_t totals;
61 
62 	totals.duration  = 0;
63 	totals.congest_ibss  = 0;
64 	totals.congest_obss  = 0;
65 	totals.interference  = 0;
66 	avg->num_secs = 0;
67 
68 	for (sec = 0; sec < input->num_secs; sec++) {
69 		if (input->secs[sec].duration) {
70 			totals.duration += input->secs[sec].duration;
71 			totals.congest_ibss += input->secs[sec].congest_ibss;
72 			totals.congest_obss += input->secs[sec].congest_obss;
73 			totals.interference += input->secs[sec].interference;
74 			avg->num_secs++;
75 		}
76 	}
77 	avg->chanspec = input->chanspec;
78 
79 	if (!avg->num_secs || !totals.duration)
80 		return (avg);
81 
82 	if (percent) {
83 		avg->secs[0].duration = totals.duration / avg->num_secs;
84 		avg->secs[0].congest_ibss = totals.congest_ibss * 100/totals.duration;
85 		avg->secs[0].congest_obss = totals.congest_obss * 100/totals.duration;
86 		avg->secs[0].interference = totals.interference * 100/totals.duration;
87 	} else {
88 		avg->secs[0].duration = totals.duration / avg->num_secs;
89 		avg->secs[0].congest_ibss = totals.congest_ibss / avg->num_secs;
90 		avg->secs[0].congest_obss = totals.congest_obss / avg->num_secs;
91 		avg->secs[0].interference = totals.interference / avg->num_secs;
92 	}
93 
94 	return (avg);
95 }
96 
97 static void
cca_info(uint8 * bitmap,int num_bits,int * left,int * bit_pos)98 cca_info(uint8 *bitmap, int num_bits, int *left, int *bit_pos)
99 {
100 	int i;
101 	for (*left = 0, i = 0; i < num_bits; i++) {
102 		if (isset(bitmap, i)) {
103 			(*left)++;
104 			*bit_pos = i;
105 		}
106 	}
107 }
108 
109 static uint8
spec_to_chan(chanspec_t chspec)110 spec_to_chan(chanspec_t chspec)
111 {
112 	uint8 center_ch, edge, primary, sb;
113 
114 	center_ch = CHSPEC_CHANNEL(chspec);
115 
116 	if (CHSPEC_IS20(chspec)) {
117 		return center_ch;
118 	} else {
119 		/* the lower edge of the wide channel is half the bw from
120 		 * the center channel.
121 		 */
122 		if (CHSPEC_IS40(chspec)) {
123 			edge = center_ch - CH_20MHZ_APART;
124 		} else {
125 			/* must be 80MHz (until we support more) */
126 			ASSERT(CHSPEC_IS80(chspec));
127 			edge = center_ch - CH_40MHZ_APART;
128 		}
129 
130 		/* find the channel number of the lowest 20MHz primary channel */
131 		primary = edge + CH_10MHZ_APART;
132 
133 		/* select the actual subband */
134 		sb = (chspec & WL_CHANSPEC_CTL_SB_MASK) >> WL_CHANSPEC_CTL_SB_SHIFT;
135 		primary = primary + sb * CH_20MHZ_APART;
136 
137 		return primary;
138 	}
139 }
140 
141 /*
142 	Take an array of measumrements representing summaries of different channels.
143 	Return a recomended channel.
144 	Interference is evil, get rid of that first.
145 	Then hunt for lowest Other bss traffic.
146 	Don't forget that channels with low duration times may not have accurate readings.
147 	For the moment, do not overwrite input array.
148 */
149 int
cca_analyze(cca_congest_channel_req_t * input[],int num_chans,uint flags,chanspec_t * answer)150 cca_analyze(cca_congest_channel_req_t *input[], int num_chans, uint flags, chanspec_t *answer)
151 {
152 	uint8 *bitmap = NULL;	/* 38 Max channels needs 5 bytes  = 40 */
153 	int i, left, winner, ret_val = 0;
154 	uint32 min_obss = 1 << 30;
155 	uint bitmap_sz;
156 
157 	bitmap_sz = CEIL(num_chans, NBBY);
158 	bitmap = (uint8 *)malloc(bitmap_sz);
159 	if (bitmap == NULL) {
160 		printf("unable to allocate memory\n");
161 		return BCME_NOMEM;
162 	}
163 
164 	memset(bitmap, 0, bitmap_sz);
165 	/* Initially, all channels are up for consideration */
166 	for (i = 0; i < num_chans; i++) {
167 		if (input[i]->chanspec)
168 			setbit(bitmap, i);
169 	}
170 	cca_info(bitmap, num_chans, &left, &i);
171 	if (!left) {
172 		ret_val = CCA_ERRNO_TOO_FEW;
173 		goto f_exit;
174 	}
175 
176 	/* Filter for 2.4 GHz Band */
177 	if (flags & CCA_FLAG_2G_ONLY) {
178 		for (i = 0; i < num_chans; i++) {
179 			if (!CHSPEC_IS2G(input[i]->chanspec))
180 				clrbit(bitmap, i);
181 		}
182 	}
183 	cca_info(bitmap, num_chans, &left, &i);
184 	if (!left) {
185 		ret_val = CCA_ERRNO_BAND;
186 		goto f_exit;
187 	}
188 
189 	/* Filter for 5 GHz Band */
190 	if (flags & CCA_FLAG_5G_ONLY) {
191 		for (i = 0; i < num_chans; i++) {
192 			if (!CHSPEC_IS5G(input[i]->chanspec))
193 				clrbit(bitmap, i);
194 		}
195 	}
196 	cca_info(bitmap, num_chans, &left, &i);
197 	if (!left) {
198 		ret_val = CCA_ERRNO_BAND;
199 		goto f_exit;
200 	}
201 
202 	/* Filter for Duration */
203 	if (!(flags & CCA_FLAG_IGNORE_DURATION)) {
204 		for (i = 0; i < num_chans; i++) {
205 			if (input[i]->secs[0].duration < CCA_THRESH_MILLI)
206 				clrbit(bitmap, i);
207 		}
208 	}
209 	cca_info(bitmap, num_chans, &left, &i);
210 	if (!left) {
211 		ret_val = CCA_ERRNO_DURATION;
212 		goto f_exit;
213 	}
214 
215 	/* Filter for 1 6 11 on 2.4 Band */
216 	if (flags &  CCA_FLAGS_PREFER_1_6_11) {
217 		int tmp_channel = spec_to_chan(input[i]->chanspec);
218 		int is2g = CHSPEC_IS2G(input[i]->chanspec);
219 		for (i = 0; i < num_chans; i++) {
220 			if (is2g && tmp_channel != 1 && tmp_channel != 6 && tmp_channel != 11)
221 				clrbit(bitmap, i);
222 		}
223 	}
224 	cca_info(bitmap, num_chans, &left, &i);
225 	if (!left) {
226 		ret_val = CCA_ERRNO_PREF_CHAN;
227 		goto f_exit;
228 	}
229 
230 	/* Toss high interference interference */
231 	if (!(flags & CCA_FLAG_IGNORE_INTERFER)) {
232 		for (i = 0; i < num_chans; i++) {
233 			if (input[i]->secs[0].interference > CCA_THRESH_INTERFERE)
234 				clrbit(bitmap, i);
235 		}
236 		cca_info(bitmap, num_chans, &left, &i);
237 		if (!left) {
238 			ret_val = CCA_ERRNO_INTERFER;
239 			goto f_exit;
240 		}
241 	}
242 
243 	/* Now find lowest obss */
244 	winner = 0;
245 	for (i = 0; i < num_chans; i++) {
246 		if (isset(bitmap, i) && input[i]->secs[0].congest_obss < min_obss) {
247 			winner = i;
248 			min_obss = input[i]->secs[0].congest_obss;
249 		}
250 	}
251 	*answer = input[winner]->chanspec;
252 	f_exit:
253 	free(bitmap);	/* free the allocated memory for bitmap */
254 	return ret_val;
255 }
256 #endif /* !BCMDRIVER */
257 
258 /* offset of cntmember by sizeof(uint32) from the first cnt variable, txframe. */
259 #define IDX_IN_WL_CNT_VER_6_T(cntmember)		\
260 	((OFFSETOF(wl_cnt_ver_6_t, cntmember) - OFFSETOF(wl_cnt_ver_6_t, txframe)) / sizeof(uint32))
261 
262 #define IDX_IN_WL_CNT_VER_7_T(cntmember)		\
263 	((OFFSETOF(wl_cnt_ver_7_t, cntmember) - OFFSETOF(wl_cnt_ver_7_t, txframe)) / sizeof(uint32))
264 
265 #define IDX_IN_WL_CNT_VER_11_T(cntmember)		\
266 	((OFFSETOF(wl_cnt_ver_11_t, cntmember) - OFFSETOF(wl_cnt_ver_11_t, txframe))	\
267 	/ sizeof(uint32))
268 
269 /* Exclude version and length fields */
270 #define NUM_OF_CNT_IN_WL_CNT_VER_6_T	\
271 	((sizeof(wl_cnt_ver_6_t) - 2 * sizeof(uint16)) / sizeof(uint32))
272 /* Exclude macstat cnt variables. wl_cnt_ver_6_t only has 62 macstat cnt variables. */
273 #define NUM_OF_WLCCNT_IN_WL_CNT_VER_6_T			\
274 	(NUM_OF_CNT_IN_WL_CNT_VER_6_T - (WL_CNT_MCST_VAR_NUM - 2))
275 
276 /* Exclude version and length fields */
277 #define NUM_OF_CNT_IN_WL_CNT_VER_7_T	\
278 	((sizeof(wl_cnt_ver_7_t) - 2 * sizeof(uint16)) / sizeof(uint32))
279 
280 /* Exclude version and length fields */
281 #define NUM_OF_CNT_IN_WL_CNT_VER_11_T	\
282 	((sizeof(wl_cnt_ver_11_t) - 2 * sizeof(uint16)) / sizeof(uint32))
283 /* Exclude 64 macstat cnt variables. */
284 #define NUM_OF_WLCCNT_IN_WL_CNT_VER_11_T	\
285 	((sizeof(wl_cnt_wlc_t)) / sizeof(uint32))
286 
287 /* Index conversion table from wl_cnt_ver_6_t to wl_cnt_wlc_t */
288 static const uint8 wlcntver6t_to_wlcntwlct[NUM_OF_WLCCNT_IN_WL_CNT_VER_6_T] = {
289 	IDX_IN_WL_CNT_VER_6_T(txframe),
290 	IDX_IN_WL_CNT_VER_6_T(txbyte),
291 	IDX_IN_WL_CNT_VER_6_T(txretrans),
292 	IDX_IN_WL_CNT_VER_6_T(txerror),
293 	IDX_IN_WL_CNT_VER_6_T(txctl),
294 	IDX_IN_WL_CNT_VER_6_T(txprshort),
295 	IDX_IN_WL_CNT_VER_6_T(txserr),
296 	IDX_IN_WL_CNT_VER_6_T(txnobuf),
297 	IDX_IN_WL_CNT_VER_6_T(txnoassoc),
298 	IDX_IN_WL_CNT_VER_6_T(txrunt),
299 	IDX_IN_WL_CNT_VER_6_T(txchit),
300 	IDX_IN_WL_CNT_VER_6_T(txcmiss),
301 	IDX_IN_WL_CNT_VER_6_T(txuflo),
302 	IDX_IN_WL_CNT_VER_6_T(txphyerr),
303 	IDX_IN_WL_CNT_VER_6_T(txphycrs),
304 	IDX_IN_WL_CNT_VER_6_T(rxframe),
305 	IDX_IN_WL_CNT_VER_6_T(rxbyte),
306 	IDX_IN_WL_CNT_VER_6_T(rxerror),
307 	IDX_IN_WL_CNT_VER_6_T(rxctl),
308 	IDX_IN_WL_CNT_VER_6_T(rxnobuf),
309 	IDX_IN_WL_CNT_VER_6_T(rxnondata),
310 	IDX_IN_WL_CNT_VER_6_T(rxbadds),
311 	IDX_IN_WL_CNT_VER_6_T(rxbadcm),
312 	IDX_IN_WL_CNT_VER_6_T(rxfragerr),
313 	IDX_IN_WL_CNT_VER_6_T(rxrunt),
314 	IDX_IN_WL_CNT_VER_6_T(rxgiant),
315 	IDX_IN_WL_CNT_VER_6_T(rxnoscb),
316 	IDX_IN_WL_CNT_VER_6_T(rxbadproto),
317 	IDX_IN_WL_CNT_VER_6_T(rxbadsrcmac),
318 	IDX_IN_WL_CNT_VER_6_T(rxbadda),
319 	IDX_IN_WL_CNT_VER_6_T(rxfilter),
320 	IDX_IN_WL_CNT_VER_6_T(rxoflo),
321 	IDX_IN_WL_CNT_VER_6_T(rxuflo),
322 	IDX_IN_WL_CNT_VER_6_T(rxuflo) + 1,
323 	IDX_IN_WL_CNT_VER_6_T(rxuflo) + 2,
324 	IDX_IN_WL_CNT_VER_6_T(rxuflo) + 3,
325 	IDX_IN_WL_CNT_VER_6_T(rxuflo) + 4,
326 	IDX_IN_WL_CNT_VER_6_T(rxuflo) + 5,
327 	IDX_IN_WL_CNT_VER_6_T(d11cnt_txrts_off),
328 	IDX_IN_WL_CNT_VER_6_T(d11cnt_rxcrc_off),
329 	IDX_IN_WL_CNT_VER_6_T(d11cnt_txnocts_off),
330 	IDX_IN_WL_CNT_VER_6_T(dmade),
331 	IDX_IN_WL_CNT_VER_6_T(dmada),
332 	IDX_IN_WL_CNT_VER_6_T(dmape),
333 	IDX_IN_WL_CNT_VER_6_T(reset),
334 	IDX_IN_WL_CNT_VER_6_T(tbtt),
335 	IDX_IN_WL_CNT_VER_6_T(txdmawar),
336 	IDX_IN_WL_CNT_VER_6_T(pkt_callback_reg_fail),
337 	IDX_IN_WL_CNT_VER_6_T(txfrag),
338 	IDX_IN_WL_CNT_VER_6_T(txmulti),
339 	IDX_IN_WL_CNT_VER_6_T(txfail),
340 	IDX_IN_WL_CNT_VER_6_T(txretry),
341 	IDX_IN_WL_CNT_VER_6_T(txretrie),
342 	IDX_IN_WL_CNT_VER_6_T(rxdup),
343 	IDX_IN_WL_CNT_VER_6_T(txrts),
344 	IDX_IN_WL_CNT_VER_6_T(txnocts),
345 	IDX_IN_WL_CNT_VER_6_T(txnoack),
346 	IDX_IN_WL_CNT_VER_6_T(rxfrag),
347 	IDX_IN_WL_CNT_VER_6_T(rxmulti),
348 	IDX_IN_WL_CNT_VER_6_T(rxcrc),
349 	IDX_IN_WL_CNT_VER_6_T(txfrmsnt),
350 	IDX_IN_WL_CNT_VER_6_T(rxundec),
351 	IDX_IN_WL_CNT_VER_6_T(tkipmicfaill),
352 	IDX_IN_WL_CNT_VER_6_T(tkipcntrmsr),
353 	IDX_IN_WL_CNT_VER_6_T(tkipreplay),
354 	IDX_IN_WL_CNT_VER_6_T(ccmpfmterr),
355 	IDX_IN_WL_CNT_VER_6_T(ccmpreplay),
356 	IDX_IN_WL_CNT_VER_6_T(ccmpundec),
357 	IDX_IN_WL_CNT_VER_6_T(fourwayfail),
358 	IDX_IN_WL_CNT_VER_6_T(wepundec),
359 	IDX_IN_WL_CNT_VER_6_T(wepicverr),
360 	IDX_IN_WL_CNT_VER_6_T(decsuccess),
361 	IDX_IN_WL_CNT_VER_6_T(tkipicverr),
362 	IDX_IN_WL_CNT_VER_6_T(wepexcluded),
363 	IDX_IN_WL_CNT_VER_6_T(txchanrej),
364 	IDX_IN_WL_CNT_VER_6_T(psmwds),
365 	IDX_IN_WL_CNT_VER_6_T(phywatchdog),
366 	IDX_IN_WL_CNT_VER_6_T(prq_entries_handled),
367 	IDX_IN_WL_CNT_VER_6_T(prq_undirected_entries),
368 	IDX_IN_WL_CNT_VER_6_T(prq_bad_entries),
369 	IDX_IN_WL_CNT_VER_6_T(atim_suppress_count),
370 	IDX_IN_WL_CNT_VER_6_T(bcn_template_not_ready),
371 	IDX_IN_WL_CNT_VER_6_T(bcn_template_not_ready_done),
372 	IDX_IN_WL_CNT_VER_6_T(late_tbtt_dpc),
373 	IDX_IN_WL_CNT_VER_6_T(rx1mbps),
374 	IDX_IN_WL_CNT_VER_6_T(rx2mbps),
375 	IDX_IN_WL_CNT_VER_6_T(rx5mbps5),
376 	IDX_IN_WL_CNT_VER_6_T(rx6mbps),
377 	IDX_IN_WL_CNT_VER_6_T(rx9mbps),
378 	IDX_IN_WL_CNT_VER_6_T(rx11mbps),
379 	IDX_IN_WL_CNT_VER_6_T(rx12mbps),
380 	IDX_IN_WL_CNT_VER_6_T(rx18mbps),
381 	IDX_IN_WL_CNT_VER_6_T(rx24mbps),
382 	IDX_IN_WL_CNT_VER_6_T(rx36mbps),
383 	IDX_IN_WL_CNT_VER_6_T(rx48mbps),
384 	IDX_IN_WL_CNT_VER_6_T(rx54mbps),
385 	IDX_IN_WL_CNT_VER_6_T(rx108mbps),
386 	IDX_IN_WL_CNT_VER_6_T(rx162mbps),
387 	IDX_IN_WL_CNT_VER_6_T(rx216mbps),
388 	IDX_IN_WL_CNT_VER_6_T(rx270mbps),
389 	IDX_IN_WL_CNT_VER_6_T(rx324mbps),
390 	IDX_IN_WL_CNT_VER_6_T(rx378mbps),
391 	IDX_IN_WL_CNT_VER_6_T(rx432mbps),
392 	IDX_IN_WL_CNT_VER_6_T(rx486mbps),
393 	IDX_IN_WL_CNT_VER_6_T(rx540mbps),
394 	IDX_IN_WL_CNT_VER_6_T(rfdisable),
395 	IDX_IN_WL_CNT_VER_6_T(txexptime),
396 	IDX_IN_WL_CNT_VER_6_T(txmpdu_sgi),
397 	IDX_IN_WL_CNT_VER_6_T(rxmpdu_sgi),
398 	IDX_IN_WL_CNT_VER_6_T(txmpdu_stbc),
399 	IDX_IN_WL_CNT_VER_6_T(rxmpdu_stbc),
400 	IDX_IN_WL_CNT_VER_6_T(rxundec_mcst),
401 	IDX_IN_WL_CNT_VER_6_T(tkipmicfaill_mcst),
402 	IDX_IN_WL_CNT_VER_6_T(tkipcntrmsr_mcst),
403 	IDX_IN_WL_CNT_VER_6_T(tkipreplay_mcst),
404 	IDX_IN_WL_CNT_VER_6_T(ccmpfmterr_mcst),
405 	IDX_IN_WL_CNT_VER_6_T(ccmpreplay_mcst),
406 	IDX_IN_WL_CNT_VER_6_T(ccmpundec_mcst),
407 	IDX_IN_WL_CNT_VER_6_T(fourwayfail_mcst),
408 	IDX_IN_WL_CNT_VER_6_T(wepundec_mcst),
409 	IDX_IN_WL_CNT_VER_6_T(wepicverr_mcst),
410 	IDX_IN_WL_CNT_VER_6_T(decsuccess_mcst),
411 	IDX_IN_WL_CNT_VER_6_T(tkipicverr_mcst),
412 	IDX_IN_WL_CNT_VER_6_T(wepexcluded_mcst)
413 };
414 
415 #define INVALID_IDX ((uint8)(-1))
416 
417 /* Index conversion table from wl_cnt_ver_7_t to wl_cnt_wlc_t */
418 static const uint8 wlcntver7t_to_wlcntwlct[] = {
419 	IDX_IN_WL_CNT_VER_7_T(txframe),
420 	IDX_IN_WL_CNT_VER_7_T(txbyte),
421 	IDX_IN_WL_CNT_VER_7_T(txretrans),
422 	IDX_IN_WL_CNT_VER_7_T(txerror),
423 	IDX_IN_WL_CNT_VER_7_T(txctl),
424 	IDX_IN_WL_CNT_VER_7_T(txprshort),
425 	IDX_IN_WL_CNT_VER_7_T(txserr),
426 	IDX_IN_WL_CNT_VER_7_T(txnobuf),
427 	IDX_IN_WL_CNT_VER_7_T(txnoassoc),
428 	IDX_IN_WL_CNT_VER_7_T(txrunt),
429 	IDX_IN_WL_CNT_VER_7_T(txchit),
430 	IDX_IN_WL_CNT_VER_7_T(txcmiss),
431 	IDX_IN_WL_CNT_VER_7_T(txuflo),
432 	IDX_IN_WL_CNT_VER_7_T(txphyerr),
433 	IDX_IN_WL_CNT_VER_7_T(txphycrs),
434 	IDX_IN_WL_CNT_VER_7_T(rxframe),
435 	IDX_IN_WL_CNT_VER_7_T(rxbyte),
436 	IDX_IN_WL_CNT_VER_7_T(rxerror),
437 	IDX_IN_WL_CNT_VER_7_T(rxctl),
438 	IDX_IN_WL_CNT_VER_7_T(rxnobuf),
439 	IDX_IN_WL_CNT_VER_7_T(rxnondata),
440 	IDX_IN_WL_CNT_VER_7_T(rxbadds),
441 	IDX_IN_WL_CNT_VER_7_T(rxbadcm),
442 	IDX_IN_WL_CNT_VER_7_T(rxfragerr),
443 	IDX_IN_WL_CNT_VER_7_T(rxrunt),
444 	IDX_IN_WL_CNT_VER_7_T(rxgiant),
445 	IDX_IN_WL_CNT_VER_7_T(rxnoscb),
446 	IDX_IN_WL_CNT_VER_7_T(rxbadproto),
447 	IDX_IN_WL_CNT_VER_7_T(rxbadsrcmac),
448 	IDX_IN_WL_CNT_VER_7_T(rxbadda),
449 	IDX_IN_WL_CNT_VER_7_T(rxfilter),
450 	IDX_IN_WL_CNT_VER_7_T(rxoflo),
451 	IDX_IN_WL_CNT_VER_7_T(rxuflo),
452 	IDX_IN_WL_CNT_VER_7_T(rxuflo) + 1,
453 	IDX_IN_WL_CNT_VER_7_T(rxuflo) + 2,
454 	IDX_IN_WL_CNT_VER_7_T(rxuflo) + 3,
455 	IDX_IN_WL_CNT_VER_7_T(rxuflo) + 4,
456 	IDX_IN_WL_CNT_VER_7_T(rxuflo) + 5,
457 	IDX_IN_WL_CNT_VER_7_T(d11cnt_txrts_off),
458 	IDX_IN_WL_CNT_VER_7_T(d11cnt_rxcrc_off),
459 	IDX_IN_WL_CNT_VER_7_T(d11cnt_txnocts_off),
460 	IDX_IN_WL_CNT_VER_7_T(dmade),
461 	IDX_IN_WL_CNT_VER_7_T(dmada),
462 	IDX_IN_WL_CNT_VER_7_T(dmape),
463 	IDX_IN_WL_CNT_VER_7_T(reset),
464 	IDX_IN_WL_CNT_VER_7_T(tbtt),
465 	IDX_IN_WL_CNT_VER_7_T(txdmawar),
466 	IDX_IN_WL_CNT_VER_7_T(pkt_callback_reg_fail),
467 	IDX_IN_WL_CNT_VER_7_T(txfrag),
468 	IDX_IN_WL_CNT_VER_7_T(txmulti),
469 	IDX_IN_WL_CNT_VER_7_T(txfail),
470 	IDX_IN_WL_CNT_VER_7_T(txretry),
471 	IDX_IN_WL_CNT_VER_7_T(txretrie),
472 	IDX_IN_WL_CNT_VER_7_T(rxdup),
473 	IDX_IN_WL_CNT_VER_7_T(txrts),
474 	IDX_IN_WL_CNT_VER_7_T(txnocts),
475 	IDX_IN_WL_CNT_VER_7_T(txnoack),
476 	IDX_IN_WL_CNT_VER_7_T(rxfrag),
477 	IDX_IN_WL_CNT_VER_7_T(rxmulti),
478 	IDX_IN_WL_CNT_VER_7_T(rxcrc),
479 	IDX_IN_WL_CNT_VER_7_T(txfrmsnt),
480 	IDX_IN_WL_CNT_VER_7_T(rxundec),
481 	IDX_IN_WL_CNT_VER_7_T(tkipmicfaill),
482 	IDX_IN_WL_CNT_VER_7_T(tkipcntrmsr),
483 	IDX_IN_WL_CNT_VER_7_T(tkipreplay),
484 	IDX_IN_WL_CNT_VER_7_T(ccmpfmterr),
485 	IDX_IN_WL_CNT_VER_7_T(ccmpreplay),
486 	IDX_IN_WL_CNT_VER_7_T(ccmpundec),
487 	IDX_IN_WL_CNT_VER_7_T(fourwayfail),
488 	IDX_IN_WL_CNT_VER_7_T(wepundec),
489 	IDX_IN_WL_CNT_VER_7_T(wepicverr),
490 	IDX_IN_WL_CNT_VER_7_T(decsuccess),
491 	IDX_IN_WL_CNT_VER_7_T(tkipicverr),
492 	IDX_IN_WL_CNT_VER_7_T(wepexcluded),
493 	IDX_IN_WL_CNT_VER_7_T(txchanrej),
494 	IDX_IN_WL_CNT_VER_7_T(psmwds),
495 	IDX_IN_WL_CNT_VER_7_T(phywatchdog),
496 	IDX_IN_WL_CNT_VER_7_T(prq_entries_handled),
497 	IDX_IN_WL_CNT_VER_7_T(prq_undirected_entries),
498 	IDX_IN_WL_CNT_VER_7_T(prq_bad_entries),
499 	IDX_IN_WL_CNT_VER_7_T(atim_suppress_count),
500 	IDX_IN_WL_CNT_VER_7_T(bcn_template_not_ready),
501 	IDX_IN_WL_CNT_VER_7_T(bcn_template_not_ready_done),
502 	IDX_IN_WL_CNT_VER_7_T(late_tbtt_dpc),
503 	IDX_IN_WL_CNT_VER_7_T(rx1mbps),
504 	IDX_IN_WL_CNT_VER_7_T(rx2mbps),
505 	IDX_IN_WL_CNT_VER_7_T(rx5mbps5),
506 	IDX_IN_WL_CNT_VER_7_T(rx6mbps),
507 	IDX_IN_WL_CNT_VER_7_T(rx9mbps),
508 	IDX_IN_WL_CNT_VER_7_T(rx11mbps),
509 	IDX_IN_WL_CNT_VER_7_T(rx12mbps),
510 	IDX_IN_WL_CNT_VER_7_T(rx18mbps),
511 	IDX_IN_WL_CNT_VER_7_T(rx24mbps),
512 	IDX_IN_WL_CNT_VER_7_T(rx36mbps),
513 	IDX_IN_WL_CNT_VER_7_T(rx48mbps),
514 	IDX_IN_WL_CNT_VER_7_T(rx54mbps),
515 	IDX_IN_WL_CNT_VER_7_T(rx108mbps),
516 	IDX_IN_WL_CNT_VER_7_T(rx162mbps),
517 	IDX_IN_WL_CNT_VER_7_T(rx216mbps),
518 	IDX_IN_WL_CNT_VER_7_T(rx270mbps),
519 	IDX_IN_WL_CNT_VER_7_T(rx324mbps),
520 	IDX_IN_WL_CNT_VER_7_T(rx378mbps),
521 	IDX_IN_WL_CNT_VER_7_T(rx432mbps),
522 	IDX_IN_WL_CNT_VER_7_T(rx486mbps),
523 	IDX_IN_WL_CNT_VER_7_T(rx540mbps),
524 	IDX_IN_WL_CNT_VER_7_T(rfdisable),
525 	IDX_IN_WL_CNT_VER_7_T(txexptime),
526 	IDX_IN_WL_CNT_VER_7_T(txmpdu_sgi),
527 	IDX_IN_WL_CNT_VER_7_T(rxmpdu_sgi),
528 	IDX_IN_WL_CNT_VER_7_T(txmpdu_stbc),
529 	IDX_IN_WL_CNT_VER_7_T(rxmpdu_stbc),
530 	IDX_IN_WL_CNT_VER_7_T(rxundec_mcst),
531 	IDX_IN_WL_CNT_VER_7_T(tkipmicfaill_mcst),
532 	IDX_IN_WL_CNT_VER_7_T(tkipcntrmsr_mcst),
533 	IDX_IN_WL_CNT_VER_7_T(tkipreplay_mcst),
534 	IDX_IN_WL_CNT_VER_7_T(ccmpfmterr_mcst),
535 	IDX_IN_WL_CNT_VER_7_T(ccmpreplay_mcst),
536 	IDX_IN_WL_CNT_VER_7_T(ccmpundec_mcst),
537 	IDX_IN_WL_CNT_VER_7_T(fourwayfail_mcst),
538 	IDX_IN_WL_CNT_VER_7_T(wepundec_mcst),
539 	IDX_IN_WL_CNT_VER_7_T(wepicverr_mcst),
540 	IDX_IN_WL_CNT_VER_7_T(decsuccess_mcst),
541 	IDX_IN_WL_CNT_VER_7_T(tkipicverr_mcst),
542 	IDX_IN_WL_CNT_VER_7_T(wepexcluded_mcst),
543 	IDX_IN_WL_CNT_VER_7_T(dma_hang),
544 	INVALID_IDX,
545 	INVALID_IDX,
546 	INVALID_IDX,
547 	INVALID_IDX,
548 	INVALID_IDX,
549 	INVALID_IDX,
550 	INVALID_IDX,
551 	INVALID_IDX,
552 	INVALID_IDX,
553 	INVALID_IDX,
554 	INVALID_IDX,
555 	INVALID_IDX,
556 	INVALID_IDX,
557 	INVALID_IDX,
558 	INVALID_IDX,
559 	INVALID_IDX,
560 	INVALID_IDX,
561 	INVALID_IDX,
562 	INVALID_IDX,
563 	INVALID_IDX,
564 	INVALID_IDX,
565 	INVALID_IDX,
566 	INVALID_IDX,
567 	IDX_IN_WL_CNT_VER_7_T(rxrtry)
568 };
569 
570 /* Max wl_cnt_wlc_t fields including rxrtry */
571 #define NUM_OF_WLCCNT_IN_WL_CNT_VER_7_T				\
572 	(sizeof(wlcntver7t_to_wlcntwlct) / sizeof(uint8))
573 
574 /* Index conversion table from wl_cnt_ver_11_t to wl_cnt_wlc_t */
575 static const uint8 wlcntver11t_to_wlcntwlct[NUM_OF_WLCCNT_IN_WL_CNT_VER_11_T] = {
576 	IDX_IN_WL_CNT_VER_11_T(txframe),
577 	IDX_IN_WL_CNT_VER_11_T(txbyte),
578 	IDX_IN_WL_CNT_VER_11_T(txretrans),
579 	IDX_IN_WL_CNT_VER_11_T(txerror),
580 	IDX_IN_WL_CNT_VER_11_T(txctl),
581 	IDX_IN_WL_CNT_VER_11_T(txprshort),
582 	IDX_IN_WL_CNT_VER_11_T(txserr),
583 	IDX_IN_WL_CNT_VER_11_T(txnobuf),
584 	IDX_IN_WL_CNT_VER_11_T(txnoassoc),
585 	IDX_IN_WL_CNT_VER_11_T(txrunt),
586 	IDX_IN_WL_CNT_VER_11_T(txchit),
587 	IDX_IN_WL_CNT_VER_11_T(txcmiss),
588 	IDX_IN_WL_CNT_VER_11_T(txuflo),
589 	IDX_IN_WL_CNT_VER_11_T(txphyerr),
590 	IDX_IN_WL_CNT_VER_11_T(txphycrs),
591 	IDX_IN_WL_CNT_VER_11_T(rxframe),
592 	IDX_IN_WL_CNT_VER_11_T(rxbyte),
593 	IDX_IN_WL_CNT_VER_11_T(rxerror),
594 	IDX_IN_WL_CNT_VER_11_T(rxctl),
595 	IDX_IN_WL_CNT_VER_11_T(rxnobuf),
596 	IDX_IN_WL_CNT_VER_11_T(rxnondata),
597 	IDX_IN_WL_CNT_VER_11_T(rxbadds),
598 	IDX_IN_WL_CNT_VER_11_T(rxbadcm),
599 	IDX_IN_WL_CNT_VER_11_T(rxfragerr),
600 	IDX_IN_WL_CNT_VER_11_T(rxrunt),
601 	IDX_IN_WL_CNT_VER_11_T(rxgiant),
602 	IDX_IN_WL_CNT_VER_11_T(rxnoscb),
603 	IDX_IN_WL_CNT_VER_11_T(rxbadproto),
604 	IDX_IN_WL_CNT_VER_11_T(rxbadsrcmac),
605 	IDX_IN_WL_CNT_VER_11_T(rxbadda),
606 	IDX_IN_WL_CNT_VER_11_T(rxfilter),
607 	IDX_IN_WL_CNT_VER_11_T(rxoflo),
608 	IDX_IN_WL_CNT_VER_11_T(rxuflo),
609 	IDX_IN_WL_CNT_VER_11_T(rxuflo) + 1,
610 	IDX_IN_WL_CNT_VER_11_T(rxuflo) + 2,
611 	IDX_IN_WL_CNT_VER_11_T(rxuflo) + 3,
612 	IDX_IN_WL_CNT_VER_11_T(rxuflo) + 4,
613 	IDX_IN_WL_CNT_VER_11_T(rxuflo) + 5,
614 	IDX_IN_WL_CNT_VER_11_T(d11cnt_txrts_off),
615 	IDX_IN_WL_CNT_VER_11_T(d11cnt_rxcrc_off),
616 	IDX_IN_WL_CNT_VER_11_T(d11cnt_txnocts_off),
617 	IDX_IN_WL_CNT_VER_11_T(dmade),
618 	IDX_IN_WL_CNT_VER_11_T(dmada),
619 	IDX_IN_WL_CNT_VER_11_T(dmape),
620 	IDX_IN_WL_CNT_VER_11_T(reset),
621 	IDX_IN_WL_CNT_VER_11_T(tbtt),
622 	IDX_IN_WL_CNT_VER_11_T(txdmawar),
623 	IDX_IN_WL_CNT_VER_11_T(pkt_callback_reg_fail),
624 	IDX_IN_WL_CNT_VER_11_T(txfrag),
625 	IDX_IN_WL_CNT_VER_11_T(txmulti),
626 	IDX_IN_WL_CNT_VER_11_T(txfail),
627 	IDX_IN_WL_CNT_VER_11_T(txretry),
628 	IDX_IN_WL_CNT_VER_11_T(txretrie),
629 	IDX_IN_WL_CNT_VER_11_T(rxdup),
630 	IDX_IN_WL_CNT_VER_11_T(txrts),
631 	IDX_IN_WL_CNT_VER_11_T(txnocts),
632 	IDX_IN_WL_CNT_VER_11_T(txnoack),
633 	IDX_IN_WL_CNT_VER_11_T(rxfrag),
634 	IDX_IN_WL_CNT_VER_11_T(rxmulti),
635 	IDX_IN_WL_CNT_VER_11_T(rxcrc),
636 	IDX_IN_WL_CNT_VER_11_T(txfrmsnt),
637 	IDX_IN_WL_CNT_VER_11_T(rxundec),
638 	IDX_IN_WL_CNT_VER_11_T(tkipmicfaill),
639 	IDX_IN_WL_CNT_VER_11_T(tkipcntrmsr),
640 	IDX_IN_WL_CNT_VER_11_T(tkipreplay),
641 	IDX_IN_WL_CNT_VER_11_T(ccmpfmterr),
642 	IDX_IN_WL_CNT_VER_11_T(ccmpreplay),
643 	IDX_IN_WL_CNT_VER_11_T(ccmpundec),
644 	IDX_IN_WL_CNT_VER_11_T(fourwayfail),
645 	IDX_IN_WL_CNT_VER_11_T(wepundec),
646 	IDX_IN_WL_CNT_VER_11_T(wepicverr),
647 	IDX_IN_WL_CNT_VER_11_T(decsuccess),
648 	IDX_IN_WL_CNT_VER_11_T(tkipicverr),
649 	IDX_IN_WL_CNT_VER_11_T(wepexcluded),
650 	IDX_IN_WL_CNT_VER_11_T(txchanrej),
651 	IDX_IN_WL_CNT_VER_11_T(psmwds),
652 	IDX_IN_WL_CNT_VER_11_T(phywatchdog),
653 	IDX_IN_WL_CNT_VER_11_T(prq_entries_handled),
654 	IDX_IN_WL_CNT_VER_11_T(prq_undirected_entries),
655 	IDX_IN_WL_CNT_VER_11_T(prq_bad_entries),
656 	IDX_IN_WL_CNT_VER_11_T(atim_suppress_count),
657 	IDX_IN_WL_CNT_VER_11_T(bcn_template_not_ready),
658 	IDX_IN_WL_CNT_VER_11_T(bcn_template_not_ready_done),
659 	IDX_IN_WL_CNT_VER_11_T(late_tbtt_dpc),
660 	IDX_IN_WL_CNT_VER_11_T(rx1mbps),
661 	IDX_IN_WL_CNT_VER_11_T(rx2mbps),
662 	IDX_IN_WL_CNT_VER_11_T(rx5mbps5),
663 	IDX_IN_WL_CNT_VER_11_T(rx6mbps),
664 	IDX_IN_WL_CNT_VER_11_T(rx9mbps),
665 	IDX_IN_WL_CNT_VER_11_T(rx11mbps),
666 	IDX_IN_WL_CNT_VER_11_T(rx12mbps),
667 	IDX_IN_WL_CNT_VER_11_T(rx18mbps),
668 	IDX_IN_WL_CNT_VER_11_T(rx24mbps),
669 	IDX_IN_WL_CNT_VER_11_T(rx36mbps),
670 	IDX_IN_WL_CNT_VER_11_T(rx48mbps),
671 	IDX_IN_WL_CNT_VER_11_T(rx54mbps),
672 	IDX_IN_WL_CNT_VER_11_T(rx108mbps),
673 	IDX_IN_WL_CNT_VER_11_T(rx162mbps),
674 	IDX_IN_WL_CNT_VER_11_T(rx216mbps),
675 	IDX_IN_WL_CNT_VER_11_T(rx270mbps),
676 	IDX_IN_WL_CNT_VER_11_T(rx324mbps),
677 	IDX_IN_WL_CNT_VER_11_T(rx378mbps),
678 	IDX_IN_WL_CNT_VER_11_T(rx432mbps),
679 	IDX_IN_WL_CNT_VER_11_T(rx486mbps),
680 	IDX_IN_WL_CNT_VER_11_T(rx540mbps),
681 	IDX_IN_WL_CNT_VER_11_T(rfdisable),
682 	IDX_IN_WL_CNT_VER_11_T(txexptime),
683 	IDX_IN_WL_CNT_VER_11_T(txmpdu_sgi),
684 	IDX_IN_WL_CNT_VER_11_T(rxmpdu_sgi),
685 	IDX_IN_WL_CNT_VER_11_T(txmpdu_stbc),
686 	IDX_IN_WL_CNT_VER_11_T(rxmpdu_stbc),
687 	IDX_IN_WL_CNT_VER_11_T(rxundec_mcst),
688 	IDX_IN_WL_CNT_VER_11_T(tkipmicfaill_mcst),
689 	IDX_IN_WL_CNT_VER_11_T(tkipcntrmsr_mcst),
690 	IDX_IN_WL_CNT_VER_11_T(tkipreplay_mcst),
691 	IDX_IN_WL_CNT_VER_11_T(ccmpfmterr_mcst),
692 	IDX_IN_WL_CNT_VER_11_T(ccmpreplay_mcst),
693 	IDX_IN_WL_CNT_VER_11_T(ccmpundec_mcst),
694 	IDX_IN_WL_CNT_VER_11_T(fourwayfail_mcst),
695 	IDX_IN_WL_CNT_VER_11_T(wepundec_mcst),
696 	IDX_IN_WL_CNT_VER_11_T(wepicverr_mcst),
697 	IDX_IN_WL_CNT_VER_11_T(decsuccess_mcst),
698 	IDX_IN_WL_CNT_VER_11_T(tkipicverr_mcst),
699 	IDX_IN_WL_CNT_VER_11_T(wepexcluded_mcst),
700 	IDX_IN_WL_CNT_VER_11_T(dma_hang),
701 	IDX_IN_WL_CNT_VER_11_T(reinit),
702 	IDX_IN_WL_CNT_VER_11_T(pstatxucast),
703 	IDX_IN_WL_CNT_VER_11_T(pstatxnoassoc),
704 	IDX_IN_WL_CNT_VER_11_T(pstarxucast),
705 	IDX_IN_WL_CNT_VER_11_T(pstarxbcmc),
706 	IDX_IN_WL_CNT_VER_11_T(pstatxbcmc),
707 	IDX_IN_WL_CNT_VER_11_T(cso_passthrough),
708 	IDX_IN_WL_CNT_VER_11_T(cso_normal),
709 	IDX_IN_WL_CNT_VER_11_T(chained),
710 	IDX_IN_WL_CNT_VER_11_T(chainedsz1),
711 	IDX_IN_WL_CNT_VER_11_T(unchained),
712 	IDX_IN_WL_CNT_VER_11_T(maxchainsz),
713 	IDX_IN_WL_CNT_VER_11_T(currchainsz),
714 	IDX_IN_WL_CNT_VER_11_T(pciereset),
715 	IDX_IN_WL_CNT_VER_11_T(cfgrestore),
716 	IDX_IN_WL_CNT_VER_11_T(reinitreason),
717 	IDX_IN_WL_CNT_VER_11_T(reinitreason) + 1,
718 	IDX_IN_WL_CNT_VER_11_T(reinitreason) + 2,
719 	IDX_IN_WL_CNT_VER_11_T(reinitreason) + 3,
720 	IDX_IN_WL_CNT_VER_11_T(reinitreason) + 4,
721 	IDX_IN_WL_CNT_VER_11_T(reinitreason) + 5,
722 	IDX_IN_WL_CNT_VER_11_T(reinitreason) + 6,
723 	IDX_IN_WL_CNT_VER_11_T(reinitreason) + 7,
724 	IDX_IN_WL_CNT_VER_11_T(rxrtry),
725 	IDX_IN_WL_CNT_VER_11_T(rxmpdu_mu),
726 	IDX_IN_WL_CNT_VER_11_T(txbar),
727 	IDX_IN_WL_CNT_VER_11_T(rxbar),
728 	IDX_IN_WL_CNT_VER_11_T(txpspoll),
729 	IDX_IN_WL_CNT_VER_11_T(rxpspoll),
730 	IDX_IN_WL_CNT_VER_11_T(txnull),
731 	IDX_IN_WL_CNT_VER_11_T(rxnull),
732 	IDX_IN_WL_CNT_VER_11_T(txqosnull),
733 	IDX_IN_WL_CNT_VER_11_T(rxqosnull),
734 	IDX_IN_WL_CNT_VER_11_T(txassocreq),
735 	IDX_IN_WL_CNT_VER_11_T(rxassocreq),
736 	IDX_IN_WL_CNT_VER_11_T(txreassocreq),
737 	IDX_IN_WL_CNT_VER_11_T(rxreassocreq),
738 	IDX_IN_WL_CNT_VER_11_T(txdisassoc),
739 	IDX_IN_WL_CNT_VER_11_T(rxdisassoc),
740 	IDX_IN_WL_CNT_VER_11_T(txassocrsp),
741 	IDX_IN_WL_CNT_VER_11_T(rxassocrsp),
742 	IDX_IN_WL_CNT_VER_11_T(txreassocrsp),
743 	IDX_IN_WL_CNT_VER_11_T(rxreassocrsp),
744 	IDX_IN_WL_CNT_VER_11_T(txauth),
745 	IDX_IN_WL_CNT_VER_11_T(rxauth),
746 	IDX_IN_WL_CNT_VER_11_T(txdeauth),
747 	IDX_IN_WL_CNT_VER_11_T(rxdeauth),
748 	IDX_IN_WL_CNT_VER_11_T(txprobereq),
749 	IDX_IN_WL_CNT_VER_11_T(rxprobereq),
750 	IDX_IN_WL_CNT_VER_11_T(txprobersp),
751 	IDX_IN_WL_CNT_VER_11_T(rxprobersp),
752 	IDX_IN_WL_CNT_VER_11_T(txaction),
753 	IDX_IN_WL_CNT_VER_11_T(rxaction),
754 	IDX_IN_WL_CNT_VER_11_T(ampdu_wds),
755 	IDX_IN_WL_CNT_VER_11_T(txlost),
756 	IDX_IN_WL_CNT_VER_11_T(txdatamcast),
757 	IDX_IN_WL_CNT_VER_11_T(txdatabcast),
758 	INVALID_IDX,
759 	IDX_IN_WL_CNT_VER_11_T(rxback),
760 	IDX_IN_WL_CNT_VER_11_T(txback),
761 	INVALID_IDX,
762 	INVALID_IDX,
763 	INVALID_IDX,
764 	INVALID_IDX,
765 	IDX_IN_WL_CNT_VER_11_T(txbcast),
766 	IDX_IN_WL_CNT_VER_11_T(txdropped),
767 	IDX_IN_WL_CNT_VER_11_T(rxbcast),
768 	IDX_IN_WL_CNT_VER_11_T(rxdropped)
769 };
770 
771 /* Index conversion table from wl_cnt_ver_11_t to
772  * either wl_cnt_ge40mcst_v1_t or wl_cnt_lt40mcst_v1_t
773  */
774 static const uint8 wlcntver11t_to_wlcntXX40mcstv1t[WL_CNT_MCST_VAR_NUM] = {
775 	IDX_IN_WL_CNT_VER_11_T(txallfrm),
776 	IDX_IN_WL_CNT_VER_11_T(txrtsfrm),
777 	IDX_IN_WL_CNT_VER_11_T(txctsfrm),
778 	IDX_IN_WL_CNT_VER_11_T(txackfrm),
779 	IDX_IN_WL_CNT_VER_11_T(txdnlfrm),
780 	IDX_IN_WL_CNT_VER_11_T(txbcnfrm),
781 	IDX_IN_WL_CNT_VER_11_T(txfunfl),
782 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 1,
783 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 2,
784 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 3,
785 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 4,
786 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 5,
787 	IDX_IN_WL_CNT_VER_11_T(txfbw),
788 	IDX_IN_WL_CNT_VER_11_T(txmpdu),
789 	IDX_IN_WL_CNT_VER_11_T(txtplunfl),
790 	IDX_IN_WL_CNT_VER_11_T(txphyerror),
791 	IDX_IN_WL_CNT_VER_11_T(pktengrxducast),
792 	IDX_IN_WL_CNT_VER_11_T(pktengrxdmcast),
793 	IDX_IN_WL_CNT_VER_11_T(rxfrmtoolong),
794 	IDX_IN_WL_CNT_VER_11_T(rxfrmtooshrt),
795 	IDX_IN_WL_CNT_VER_11_T(rxinvmachdr),
796 	IDX_IN_WL_CNT_VER_11_T(rxbadfcs),
797 	IDX_IN_WL_CNT_VER_11_T(rxbadplcp),
798 	IDX_IN_WL_CNT_VER_11_T(rxcrsglitch),
799 	IDX_IN_WL_CNT_VER_11_T(rxstrt),
800 	IDX_IN_WL_CNT_VER_11_T(rxdfrmucastmbss),
801 	IDX_IN_WL_CNT_VER_11_T(rxmfrmucastmbss),
802 	IDX_IN_WL_CNT_VER_11_T(rxcfrmucast),
803 	IDX_IN_WL_CNT_VER_11_T(rxrtsucast),
804 	IDX_IN_WL_CNT_VER_11_T(rxctsucast),
805 	IDX_IN_WL_CNT_VER_11_T(rxackucast),
806 	IDX_IN_WL_CNT_VER_11_T(rxdfrmocast),
807 	IDX_IN_WL_CNT_VER_11_T(rxmfrmocast),
808 	IDX_IN_WL_CNT_VER_11_T(rxcfrmocast),
809 	IDX_IN_WL_CNT_VER_11_T(rxrtsocast),
810 	IDX_IN_WL_CNT_VER_11_T(rxctsocast),
811 	IDX_IN_WL_CNT_VER_11_T(rxdfrmmcast),
812 	IDX_IN_WL_CNT_VER_11_T(rxmfrmmcast),
813 	IDX_IN_WL_CNT_VER_11_T(rxcfrmmcast),
814 	IDX_IN_WL_CNT_VER_11_T(rxbeaconmbss),
815 	IDX_IN_WL_CNT_VER_11_T(rxdfrmucastobss),
816 	IDX_IN_WL_CNT_VER_11_T(rxbeaconobss),
817 	IDX_IN_WL_CNT_VER_11_T(rxrsptmout),
818 	IDX_IN_WL_CNT_VER_11_T(bcntxcancl),
819 	IDX_IN_WL_CNT_VER_11_T(rxnodelim),
820 	IDX_IN_WL_CNT_VER_11_T(rxf0ovfl),
821 	IDX_IN_WL_CNT_VER_11_T(rxf1ovfl),
822 	IDX_IN_WL_CNT_VER_11_T(rxf2ovfl),
823 	IDX_IN_WL_CNT_VER_11_T(txsfovfl),
824 	IDX_IN_WL_CNT_VER_11_T(pmqovfl),
825 	IDX_IN_WL_CNT_VER_11_T(rxcgprqfrm),
826 	IDX_IN_WL_CNT_VER_11_T(rxcgprsqovfl),
827 	IDX_IN_WL_CNT_VER_11_T(txcgprsfail),
828 	IDX_IN_WL_CNT_VER_11_T(txcgprssuc),
829 	IDX_IN_WL_CNT_VER_11_T(prs_timeout),
830 	IDX_IN_WL_CNT_VER_11_T(rxnack),
831 	IDX_IN_WL_CNT_VER_11_T(frmscons),
832 	IDX_IN_WL_CNT_VER_11_T(txnack),
833 	IDX_IN_WL_CNT_VER_11_T(rxback),
834 	IDX_IN_WL_CNT_VER_11_T(txback),
835 	IDX_IN_WL_CNT_VER_11_T(bphy_rxcrsglitch),
836 	IDX_IN_WL_CNT_VER_11_T(rxdrop20s),
837 	IDX_IN_WL_CNT_VER_11_T(rxtoolate),
838 	IDX_IN_WL_CNT_VER_11_T(bphy_badplcp)
839 };
840 
841 /* For mcst offsets that were not used. (2 Pads) */
842 #define INVALID_MCST_IDX ((uint8)(-1))
843 /* Index conversion table from wl_cnt_ver_11_t to wl_cnt_v_le10_mcst_t */
844 static const uint8 wlcntver11t_to_wlcntvle10mcstt[WL_CNT_MCST_VAR_NUM] = {
845 	IDX_IN_WL_CNT_VER_11_T(txallfrm),
846 	IDX_IN_WL_CNT_VER_11_T(txrtsfrm),
847 	IDX_IN_WL_CNT_VER_11_T(txctsfrm),
848 	IDX_IN_WL_CNT_VER_11_T(txackfrm),
849 	IDX_IN_WL_CNT_VER_11_T(txdnlfrm),
850 	IDX_IN_WL_CNT_VER_11_T(txbcnfrm),
851 	IDX_IN_WL_CNT_VER_11_T(txfunfl),
852 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 1,
853 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 2,
854 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 3,
855 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 4,
856 	IDX_IN_WL_CNT_VER_11_T(txfunfl) + 5,
857 	IDX_IN_WL_CNT_VER_11_T(txfbw),
858 	INVALID_MCST_IDX,
859 	IDX_IN_WL_CNT_VER_11_T(txtplunfl),
860 	IDX_IN_WL_CNT_VER_11_T(txphyerror),
861 	IDX_IN_WL_CNT_VER_11_T(pktengrxducast),
862 	IDX_IN_WL_CNT_VER_11_T(pktengrxdmcast),
863 	IDX_IN_WL_CNT_VER_11_T(rxfrmtoolong),
864 	IDX_IN_WL_CNT_VER_11_T(rxfrmtooshrt),
865 	IDX_IN_WL_CNT_VER_11_T(rxinvmachdr),
866 	IDX_IN_WL_CNT_VER_11_T(rxbadfcs),
867 	IDX_IN_WL_CNT_VER_11_T(rxbadplcp),
868 	IDX_IN_WL_CNT_VER_11_T(rxcrsglitch),
869 	IDX_IN_WL_CNT_VER_11_T(rxstrt),
870 	IDX_IN_WL_CNT_VER_11_T(rxdfrmucastmbss),
871 	IDX_IN_WL_CNT_VER_11_T(rxmfrmucastmbss),
872 	IDX_IN_WL_CNT_VER_11_T(rxcfrmucast),
873 	IDX_IN_WL_CNT_VER_11_T(rxrtsucast),
874 	IDX_IN_WL_CNT_VER_11_T(rxctsucast),
875 	IDX_IN_WL_CNT_VER_11_T(rxackucast),
876 	IDX_IN_WL_CNT_VER_11_T(rxdfrmocast),
877 	IDX_IN_WL_CNT_VER_11_T(rxmfrmocast),
878 	IDX_IN_WL_CNT_VER_11_T(rxcfrmocast),
879 	IDX_IN_WL_CNT_VER_11_T(rxrtsocast),
880 	IDX_IN_WL_CNT_VER_11_T(rxctsocast),
881 	IDX_IN_WL_CNT_VER_11_T(rxdfrmmcast),
882 	IDX_IN_WL_CNT_VER_11_T(rxmfrmmcast),
883 	IDX_IN_WL_CNT_VER_11_T(rxcfrmmcast),
884 	IDX_IN_WL_CNT_VER_11_T(rxbeaconmbss),
885 	IDX_IN_WL_CNT_VER_11_T(rxdfrmucastobss),
886 	IDX_IN_WL_CNT_VER_11_T(rxbeaconobss),
887 	IDX_IN_WL_CNT_VER_11_T(rxrsptmout),
888 	IDX_IN_WL_CNT_VER_11_T(bcntxcancl),
889 	INVALID_MCST_IDX,
890 	IDX_IN_WL_CNT_VER_11_T(rxf0ovfl),
891 	IDX_IN_WL_CNT_VER_11_T(rxf1ovfl),
892 	IDX_IN_WL_CNT_VER_11_T(rxf2ovfl),
893 	IDX_IN_WL_CNT_VER_11_T(txsfovfl),
894 	IDX_IN_WL_CNT_VER_11_T(pmqovfl),
895 	IDX_IN_WL_CNT_VER_11_T(rxcgprqfrm),
896 	IDX_IN_WL_CNT_VER_11_T(rxcgprsqovfl),
897 	IDX_IN_WL_CNT_VER_11_T(txcgprsfail),
898 	IDX_IN_WL_CNT_VER_11_T(txcgprssuc),
899 	IDX_IN_WL_CNT_VER_11_T(prs_timeout),
900 	IDX_IN_WL_CNT_VER_11_T(rxnack),
901 	IDX_IN_WL_CNT_VER_11_T(frmscons),
902 	IDX_IN_WL_CNT_VER_11_T(txnack),
903 	IDX_IN_WL_CNT_VER_11_T(rxback),
904 	IDX_IN_WL_CNT_VER_11_T(txback),
905 	IDX_IN_WL_CNT_VER_11_T(bphy_rxcrsglitch),
906 	IDX_IN_WL_CNT_VER_11_T(rxdrop20s),
907 	IDX_IN_WL_CNT_VER_11_T(rxtoolate),
908 	IDX_IN_WL_CNT_VER_11_T(bphy_badplcp)
909 };
910 
911 /* Index conversion table from wl_cnt_ver_6_t to wl_cnt_v_le10_mcst_t */
912 static const uint8 wlcntver6t_to_wlcntvle10mcstt[WL_CNT_MCST_VAR_NUM] = {
913 	IDX_IN_WL_CNT_VER_6_T(txallfrm),
914 	IDX_IN_WL_CNT_VER_6_T(txrtsfrm),
915 	IDX_IN_WL_CNT_VER_6_T(txctsfrm),
916 	IDX_IN_WL_CNT_VER_6_T(txackfrm),
917 	IDX_IN_WL_CNT_VER_6_T(txdnlfrm),
918 	IDX_IN_WL_CNT_VER_6_T(txbcnfrm),
919 	IDX_IN_WL_CNT_VER_6_T(txfunfl),
920 	IDX_IN_WL_CNT_VER_6_T(txfunfl) + 1,
921 	IDX_IN_WL_CNT_VER_6_T(txfunfl) + 2,
922 	IDX_IN_WL_CNT_VER_6_T(txfunfl) + 3,
923 	IDX_IN_WL_CNT_VER_6_T(txfunfl) + 4,
924 	IDX_IN_WL_CNT_VER_6_T(txfunfl) + 5,
925 	IDX_IN_WL_CNT_VER_6_T(txfbw),
926 	INVALID_MCST_IDX,
927 	IDX_IN_WL_CNT_VER_6_T(txtplunfl),
928 	IDX_IN_WL_CNT_VER_6_T(txphyerror),
929 	IDX_IN_WL_CNT_VER_6_T(pktengrxducast),
930 	IDX_IN_WL_CNT_VER_6_T(pktengrxdmcast),
931 	IDX_IN_WL_CNT_VER_6_T(rxfrmtoolong),
932 	IDX_IN_WL_CNT_VER_6_T(rxfrmtooshrt),
933 	IDX_IN_WL_CNT_VER_6_T(rxinvmachdr),
934 	IDX_IN_WL_CNT_VER_6_T(rxbadfcs),
935 	IDX_IN_WL_CNT_VER_6_T(rxbadplcp),
936 	IDX_IN_WL_CNT_VER_6_T(rxcrsglitch),
937 	IDX_IN_WL_CNT_VER_6_T(rxstrt),
938 	IDX_IN_WL_CNT_VER_6_T(rxdfrmucastmbss),
939 	IDX_IN_WL_CNT_VER_6_T(rxmfrmucastmbss),
940 	IDX_IN_WL_CNT_VER_6_T(rxcfrmucast),
941 	IDX_IN_WL_CNT_VER_6_T(rxrtsucast),
942 	IDX_IN_WL_CNT_VER_6_T(rxctsucast),
943 	IDX_IN_WL_CNT_VER_6_T(rxackucast),
944 	IDX_IN_WL_CNT_VER_6_T(rxdfrmocast),
945 	IDX_IN_WL_CNT_VER_6_T(rxmfrmocast),
946 	IDX_IN_WL_CNT_VER_6_T(rxcfrmocast),
947 	IDX_IN_WL_CNT_VER_6_T(rxrtsocast),
948 	IDX_IN_WL_CNT_VER_6_T(rxctsocast),
949 	IDX_IN_WL_CNT_VER_6_T(rxdfrmmcast),
950 	IDX_IN_WL_CNT_VER_6_T(rxmfrmmcast),
951 	IDX_IN_WL_CNT_VER_6_T(rxcfrmmcast),
952 	IDX_IN_WL_CNT_VER_6_T(rxbeaconmbss),
953 	IDX_IN_WL_CNT_VER_6_T(rxdfrmucastobss),
954 	IDX_IN_WL_CNT_VER_6_T(rxbeaconobss),
955 	IDX_IN_WL_CNT_VER_6_T(rxrsptmout),
956 	IDX_IN_WL_CNT_VER_6_T(bcntxcancl),
957 	INVALID_MCST_IDX,
958 	IDX_IN_WL_CNT_VER_6_T(rxf0ovfl),
959 	IDX_IN_WL_CNT_VER_6_T(rxf1ovfl),
960 	IDX_IN_WL_CNT_VER_6_T(rxf2ovfl),
961 	IDX_IN_WL_CNT_VER_6_T(txsfovfl),
962 	IDX_IN_WL_CNT_VER_6_T(pmqovfl),
963 	IDX_IN_WL_CNT_VER_6_T(rxcgprqfrm),
964 	IDX_IN_WL_CNT_VER_6_T(rxcgprsqovfl),
965 	IDX_IN_WL_CNT_VER_6_T(txcgprsfail),
966 	IDX_IN_WL_CNT_VER_6_T(txcgprssuc),
967 	IDX_IN_WL_CNT_VER_6_T(prs_timeout),
968 	IDX_IN_WL_CNT_VER_6_T(rxnack),
969 	IDX_IN_WL_CNT_VER_6_T(frmscons),
970 	IDX_IN_WL_CNT_VER_6_T(txnack),
971 	IDX_IN_WL_CNT_VER_6_T(rxback),
972 	IDX_IN_WL_CNT_VER_6_T(txback),
973 	IDX_IN_WL_CNT_VER_6_T(bphy_rxcrsglitch),
974 	IDX_IN_WL_CNT_VER_6_T(rxdrop20s),
975 	IDX_IN_WL_CNT_VER_6_T(rxtoolate),
976 	IDX_IN_WL_CNT_VER_6_T(bphy_badplcp)
977 };
978 
979 /* Index conversion table from wl_cnt_ver_7_t to wl_cnt_v_le10_mcst_t */
980 static const uint8 wlcntver7t_to_wlcntvle10mcstt[WL_CNT_MCST_VAR_NUM] = {
981 	IDX_IN_WL_CNT_VER_7_T(txallfrm),
982 	IDX_IN_WL_CNT_VER_7_T(txrtsfrm),
983 	IDX_IN_WL_CNT_VER_7_T(txctsfrm),
984 	IDX_IN_WL_CNT_VER_7_T(txackfrm),
985 	IDX_IN_WL_CNT_VER_7_T(txdnlfrm),
986 	IDX_IN_WL_CNT_VER_7_T(txbcnfrm),
987 	IDX_IN_WL_CNT_VER_7_T(txfunfl),
988 	IDX_IN_WL_CNT_VER_7_T(txfunfl) + 1,
989 	IDX_IN_WL_CNT_VER_7_T(txfunfl) + 2,
990 	IDX_IN_WL_CNT_VER_7_T(txfunfl) + 3,
991 	IDX_IN_WL_CNT_VER_7_T(txfunfl) + 4,
992 	IDX_IN_WL_CNT_VER_7_T(txfunfl) + 5,
993 	INVALID_MCST_IDX,
994 	INVALID_MCST_IDX,
995 	IDX_IN_WL_CNT_VER_7_T(txtplunfl),
996 	IDX_IN_WL_CNT_VER_7_T(txphyerror),
997 	IDX_IN_WL_CNT_VER_7_T(pktengrxducast),
998 	IDX_IN_WL_CNT_VER_7_T(pktengrxdmcast),
999 	IDX_IN_WL_CNT_VER_7_T(rxfrmtoolong),
1000 	IDX_IN_WL_CNT_VER_7_T(rxfrmtooshrt),
1001 	IDX_IN_WL_CNT_VER_7_T(rxinvmachdr),
1002 	IDX_IN_WL_CNT_VER_7_T(rxbadfcs),
1003 	IDX_IN_WL_CNT_VER_7_T(rxbadplcp),
1004 	IDX_IN_WL_CNT_VER_7_T(rxcrsglitch),
1005 	IDX_IN_WL_CNT_VER_7_T(rxstrt),
1006 	IDX_IN_WL_CNT_VER_7_T(rxdfrmucastmbss),
1007 	IDX_IN_WL_CNT_VER_7_T(rxmfrmucastmbss),
1008 	IDX_IN_WL_CNT_VER_7_T(rxcfrmucast),
1009 	IDX_IN_WL_CNT_VER_7_T(rxrtsucast),
1010 	IDX_IN_WL_CNT_VER_7_T(rxctsucast),
1011 	IDX_IN_WL_CNT_VER_7_T(rxackucast),
1012 	IDX_IN_WL_CNT_VER_7_T(rxdfrmocast),
1013 	IDX_IN_WL_CNT_VER_7_T(rxmfrmocast),
1014 	IDX_IN_WL_CNT_VER_7_T(rxcfrmocast),
1015 	IDX_IN_WL_CNT_VER_7_T(rxrtsocast),
1016 	IDX_IN_WL_CNT_VER_7_T(rxctsocast),
1017 	IDX_IN_WL_CNT_VER_7_T(rxdfrmmcast),
1018 	IDX_IN_WL_CNT_VER_7_T(rxmfrmmcast),
1019 	IDX_IN_WL_CNT_VER_7_T(rxcfrmmcast),
1020 	IDX_IN_WL_CNT_VER_7_T(rxbeaconmbss),
1021 	IDX_IN_WL_CNT_VER_7_T(rxdfrmucastobss),
1022 	IDX_IN_WL_CNT_VER_7_T(rxbeaconobss),
1023 	IDX_IN_WL_CNT_VER_7_T(rxrsptmout),
1024 	IDX_IN_WL_CNT_VER_7_T(bcntxcancl),
1025 	INVALID_MCST_IDX,
1026 	IDX_IN_WL_CNT_VER_7_T(rxf0ovfl),
1027 	IDX_IN_WL_CNT_VER_7_T(rxf1ovfl),
1028 	IDX_IN_WL_CNT_VER_7_T(rxf2ovfl),
1029 	IDX_IN_WL_CNT_VER_7_T(txsfovfl),
1030 	IDX_IN_WL_CNT_VER_7_T(pmqovfl),
1031 	IDX_IN_WL_CNT_VER_7_T(rxcgprqfrm),
1032 	IDX_IN_WL_CNT_VER_7_T(rxcgprsqovfl),
1033 	IDX_IN_WL_CNT_VER_7_T(txcgprsfail),
1034 	IDX_IN_WL_CNT_VER_7_T(txcgprssuc),
1035 	IDX_IN_WL_CNT_VER_7_T(prs_timeout),
1036 	IDX_IN_WL_CNT_VER_7_T(rxnack),
1037 	IDX_IN_WL_CNT_VER_7_T(frmscons),
1038 	IDX_IN_WL_CNT_VER_7_T(txnack),
1039 	INVALID_MCST_IDX,
1040 	INVALID_MCST_IDX,
1041 	IDX_IN_WL_CNT_VER_7_T(bphy_rxcrsglitch),
1042 	INVALID_MCST_IDX,
1043 	INVALID_MCST_IDX,
1044 	INVALID_MCST_IDX
1045 };
1046 
1047 /* copy wlc layer counters from old type cntbuf to wl_cnt_wlc_t type. */
1048 static int
wl_copy_wlccnt(uint16 cntver,uint32 * dst,uint32 * src,uint8 src_max_idx)1049 wl_copy_wlccnt(uint16 cntver, uint32 *dst, uint32 *src, uint8 src_max_idx)
1050 {
1051 	uint i;
1052 	if (dst == NULL || src == NULL) {
1053 		return BCME_ERROR;
1054 	}
1055 
1056 	/* Init wlccnt with invalid value. Unchanged value will not be printed out */
1057 	for (i = 0; i < (sizeof(wl_cnt_wlc_t) / sizeof(uint32)); i++) {
1058 		dst[i] = INVALID_CNT_VAL;
1059 	}
1060 
1061 	if (cntver == WL_CNT_VERSION_6) {
1062 		for (i = 0; i < NUM_OF_WLCCNT_IN_WL_CNT_VER_6_T; i++) {
1063 			if (wlcntver6t_to_wlcntwlct[i] >= src_max_idx) {
1064 				/* src buffer does not have counters from here */
1065 				break;
1066 			}
1067 			dst[i] = src[wlcntver6t_to_wlcntwlct[i]];
1068 		}
1069 	} else if (cntver == WL_CNT_VERSION_7) {
1070 		for (i = 0; i < NUM_OF_WLCCNT_IN_WL_CNT_VER_7_T; i++) {
1071 			if (wlcntver7t_to_wlcntwlct[i] >= src_max_idx ||
1072 				wlcntver7t_to_wlcntwlct[i] == INVALID_IDX) {
1073 				continue;
1074 			}
1075 			dst[i] = src[wlcntver7t_to_wlcntwlct[i]];
1076 		}
1077 	} else {
1078 		for (i = 0; i < NUM_OF_WLCCNT_IN_WL_CNT_VER_11_T; i++) {
1079 			if (wlcntver11t_to_wlcntwlct[i] >= src_max_idx) {
1080 				if (wlcntver11t_to_wlcntwlct[i] == INVALID_IDX) {
1081 					continue;
1082 				}
1083 				else {
1084 					/* src buffer does not have counters from here */
1085 					break;
1086 				}
1087 			}
1088 			dst[i] = src[wlcntver11t_to_wlcntwlct[i]];
1089 		}
1090 	}
1091 	return BCME_OK;
1092 }
1093 
1094 /* copy macstat counters from old type cntbuf to wl_cnt_v_le10_mcst_t type. */
1095 static int
wl_copy_macstat_upto_ver10(uint16 cntver,uint32 * dst,uint32 * src)1096 wl_copy_macstat_upto_ver10(uint16 cntver, uint32 *dst, uint32 *src)
1097 {
1098 	uint i;
1099 
1100 	if (dst == NULL || src == NULL) {
1101 		return BCME_ERROR;
1102 	}
1103 
1104 	if (cntver == WL_CNT_VERSION_6) {
1105 		for (i = 0; i < WL_CNT_MCST_VAR_NUM; i++) {
1106 			if (wlcntver6t_to_wlcntvle10mcstt[i] == INVALID_MCST_IDX) {
1107 				/* This mcst counter does not exist in wl_cnt_ver_6_t */
1108 				dst[i] = INVALID_CNT_VAL;
1109 			} else {
1110 				dst[i] = src[wlcntver6t_to_wlcntvle10mcstt[i]];
1111 			}
1112 		}
1113 	} else if (cntver == WL_CNT_VERSION_7) {
1114 		for (i = 0; i < WL_CNT_MCST_VAR_NUM; i++) {
1115 			if (wlcntver7t_to_wlcntvle10mcstt[i] == INVALID_MCST_IDX) {
1116 				/* This mcst counter does not exist in wl_cnt_ver_7_t */
1117 				dst[i] = INVALID_CNT_VAL;
1118 			} else {
1119 				dst[i] = src[wlcntver7t_to_wlcntvle10mcstt[i]];
1120 			}
1121 		}
1122 	} else {
1123 		for (i = 0; i < WL_CNT_MCST_VAR_NUM; i++) {
1124 			if (wlcntver11t_to_wlcntvle10mcstt[i] == INVALID_MCST_IDX) {
1125 				/* This mcst counter does not exist in wl_cnt_ver_11_t */
1126 				dst[i] = INVALID_CNT_VAL;
1127 			} else {
1128 				dst[i] = src[wlcntver11t_to_wlcntvle10mcstt[i]];
1129 			}
1130 		}
1131 	}
1132 	return BCME_OK;
1133 }
1134 
1135 static int
wl_copy_macstat_ver11(uint32 * dst,uint32 * src)1136 wl_copy_macstat_ver11(uint32 *dst, uint32 *src)
1137 {
1138 	uint i;
1139 
1140 	if (dst == NULL || src == NULL) {
1141 		return BCME_ERROR;
1142 	}
1143 
1144 	for (i = 0; i < WL_CNT_MCST_VAR_NUM; i++) {
1145 		dst[i] = src[wlcntver11t_to_wlcntXX40mcstv1t[i]];
1146 	}
1147 	return BCME_OK;
1148 }
1149 
1150 /**
1151  * Translate non-xtlv 'wl counters' IOVar buffer received by old driver/FW to xtlv format.
1152  * Parameters:
1153  *	cntbuf: pointer to non-xtlv 'wl counters' IOVar buffer received by old driver/FW.
1154  *		Newly translated xtlv format is written to this pointer.
1155  *	buflen: length of the "cntbuf" without any padding.
1156  *	corerev: chip core revision of the driver/FW.
1157  */
1158 int
wl_cntbuf_to_xtlv_format(void * ctx,void * cntbuf,int buflen,uint32 corerev)1159 wl_cntbuf_to_xtlv_format(void *ctx, void *cntbuf, int buflen, uint32 corerev)
1160 {
1161 	wl_cnt_wlc_t *wlccnt = NULL;
1162 	uint32 *macstat = NULL;
1163 	xtlv_desc_t xtlv_desc[3];
1164 	uint16 mcst_xtlv_id;
1165 	int res = BCME_OK;
1166 	wl_cnt_info_t *cntinfo = cntbuf;
1167 	uint8 *xtlvbuf_p = cntinfo->data;
1168 	uint16 ver = cntinfo->version;
1169 	uint16 xtlvbuflen = (uint16)buflen;
1170 	uint16 src_max_idx;
1171 #ifdef BCMDRIVER
1172 	osl_t *osh = ctx;
1173 #else
1174 	BCM_REFERENCE(ctx);
1175 #endif
1176 
1177 	if (ver >= WL_CNT_VERSION_XTLV) {
1178 		/* Already in xtlv format. */
1179 		goto exit;
1180 	}
1181 
1182 #ifdef BCMDRIVER
1183 	wlccnt = MALLOC(osh, sizeof(*wlccnt));
1184 	macstat = MALLOC(osh, WL_CNT_MCST_STRUCT_SZ);
1185 #else
1186 	wlccnt = (wl_cnt_wlc_t *)malloc(sizeof(*wlccnt));
1187 	macstat = (uint32 *)malloc(WL_CNT_MCST_STRUCT_SZ);
1188 #endif
1189 	if (!wlccnt || !macstat) {
1190 		printf("wl_cntbuf_to_xtlv_format: malloc fail!\n");
1191 		res = BCME_NOMEM;
1192 		goto exit;
1193 	}
1194 
1195 	/* Check if the max idx in the struct exceeds the boundary of uint8 */
1196 	if (NUM_OF_CNT_IN_WL_CNT_VER_6_T > ((uint8)(-1) + 1) ||
1197 		NUM_OF_CNT_IN_WL_CNT_VER_7_T > ((uint8)(-1) + 1) ||
1198 		NUM_OF_CNT_IN_WL_CNT_VER_11_T > ((uint8)(-1) + 1)) {
1199 		printf("wlcntverXXt_to_wlcntwlct and src_max_idx need"
1200 			" to be of uint16 instead of uint8\n");
1201 		res = BCME_ERROR;
1202 		goto exit;
1203 	}
1204 
1205 	/* Exclude version and length fields in either wlc_cnt_ver_6_t or wlc_cnt_ver_11_t */
1206 	src_max_idx = (cntinfo->datalen - OFFSETOF(wl_cnt_info_t, data)) / sizeof(uint32);
1207 	if (src_max_idx > (uint8)(-1)) {
1208 		printf("wlcntverXXt_to_wlcntwlct and src_max_idx need"
1209 			" to be of uint16 instead of uint8\n"
1210 			"Try updating wl utility to the latest.\n");
1211 		src_max_idx = (uint8)(-1);
1212 	}
1213 
1214 	/* Copy wlc layer counters to wl_cnt_wlc_t */
1215 	res = wl_copy_wlccnt(ver, (uint32 *)wlccnt, (uint32 *)cntinfo->data, (uint8)src_max_idx);
1216 	if (res != BCME_OK) {
1217 		printf("wl_copy_wlccnt fail!\n");
1218 		goto exit;
1219 	}
1220 
1221 	/* Copy macstat counters to wl_cnt_wlc_t */
1222 	if (ver == WL_CNT_VERSION_11) {
1223 		res = wl_copy_macstat_ver11(macstat, (uint32 *)cntinfo->data);
1224 		if (res != BCME_OK) {
1225 			printf("wl_copy_macstat_ver11 fail!\n");
1226 			goto exit;
1227 		}
1228 		if (corerev >= 40) {
1229 			mcst_xtlv_id = WL_CNT_XTLV_GE40_UCODE_V1;
1230 		} else {
1231 			mcst_xtlv_id = WL_CNT_XTLV_LT40_UCODE_V1;
1232 		}
1233 	} else {
1234 		res = wl_copy_macstat_upto_ver10(ver, macstat, (uint32 *)cntinfo->data);
1235 		if (res != BCME_OK) {
1236 			printf("wl_copy_macstat_upto_ver10 fail!\n");
1237 			goto exit;
1238 		}
1239 		mcst_xtlv_id = WL_CNT_XTLV_CNTV_LE10_UCODE;
1240 	}
1241 
1242 	xtlv_desc[0].type = WL_CNT_XTLV_WLC;
1243 	xtlv_desc[0].len = sizeof(*wlccnt);
1244 	xtlv_desc[0].ptr = wlccnt;
1245 
1246 	xtlv_desc[1].type = mcst_xtlv_id;
1247 	xtlv_desc[1].len = WL_CNT_MCST_STRUCT_SZ;
1248 	xtlv_desc[1].ptr = macstat;
1249 
1250 	xtlv_desc[2].type = 0;
1251 	xtlv_desc[2].len = 0;
1252 	xtlv_desc[2].ptr = NULL;
1253 
1254 	memset(cntbuf, 0, buflen);
1255 
1256 	res = bcm_pack_xtlv_buf_from_mem(&xtlvbuf_p, &xtlvbuflen,
1257 		xtlv_desc, BCM_XTLV_OPTION_ALIGN32);
1258 	cntinfo->datalen = (buflen - xtlvbuflen);
1259 exit:
1260 #ifdef BCMDRIVER
1261 	if (wlccnt) {
1262 		MFREE(osh, wlccnt, sizeof(*wlccnt));
1263 	}
1264 	if (macstat) {
1265 		MFREE(osh, macstat, WL_CNT_MCST_STRUCT_SZ);
1266 	}
1267 #else
1268 	if (wlccnt) {
1269 		free(wlccnt);
1270 	}
1271 	if (macstat) {
1272 		free(macstat);
1273 	}
1274 #endif
1275 	return res;
1276 }
1277