xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/wl_bigdata.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Bigdata logging and report. None EWP and Hang event.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2020, Broadcom.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *      Unless you and Broadcom execute a separate written software license
7*4882a593Smuzhiyun  * agreement governing use of this software, this software is licensed to you
8*4882a593Smuzhiyun  * under the terms of the GNU General Public License version 2 (the "GPL"),
9*4882a593Smuzhiyun  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10*4882a593Smuzhiyun  * following added to such license:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *      As a special exception, the copyright holders of this software give you
13*4882a593Smuzhiyun  * permission to link this software with independent modules, and to copy and
14*4882a593Smuzhiyun  * distribute the resulting executable under terms of your choice, provided that
15*4882a593Smuzhiyun  * you also meet, for each linked independent module, the terms and conditions of
16*4882a593Smuzhiyun  * the license of that module.  An independent module is a module which is not
17*4882a593Smuzhiyun  * derived from this software.  The special exception does not apply to any
18*4882a593Smuzhiyun  * modifications of the software.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * <<Broadcom-WL-IPTag/Dual:>>
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun #include <typedefs.h>
24*4882a593Smuzhiyun #include <osl.h>
25*4882a593Smuzhiyun #include <dngl_stats.h>
26*4882a593Smuzhiyun #include <bcmutils.h>
27*4882a593Smuzhiyun #include <dhd.h>
28*4882a593Smuzhiyun #include <dhd_dbg.h>
29*4882a593Smuzhiyun #include <wl_cfg80211.h>
30*4882a593Smuzhiyun #include <wldev_common.h>
31*4882a593Smuzhiyun #include <bcmendian.h>
32*4882a593Smuzhiyun #include <wlioctl.h>
33*4882a593Smuzhiyun #include <dhd_linux_wq.h>
34*4882a593Smuzhiyun #include <wl_bigdata.h>
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define WL_AP_BIGDATA_LOG(args) WL_DBG(args)
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #define WLC_E_IS_ASSOC(e, r) \
39*4882a593Smuzhiyun 	(((e == WLC_E_ASSOC_IND) || (e == WLC_E_REASSOC_IND)) && r == DOT11_SC_SUCCESS)
40*4882a593Smuzhiyun #define WLC_E_IS_DEAUTH(e) \
41*4882a593Smuzhiyun 	(e == WLC_E_DISASSOC_IND || e == WLC_E_DEAUTH_IND || e == WLC_E_DEAUTH)
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun static void dump_ap_stadata(wl_ap_sta_data_t *ap_sta_data);
44*4882a593Smuzhiyun static inline void copy_ap_stadata(wl_ap_sta_data_t *dest, wl_ap_sta_data_t *src);
45*4882a593Smuzhiyun static void wg_rate_dot11mode(uint32 *rate, uint8 *channel, uint32 *mode_80211);
46*4882a593Smuzhiyun static void wg_ht_mimo_ant(uint32 *nss, wl_rateset_args_t *rateset);
47*4882a593Smuzhiyun static void wg_vht_mimo_ant(uint32 *nss, wl_rateset_args_t *rateset);
48*4882a593Smuzhiyun #if defined(WL11AX)
49*4882a593Smuzhiyun static void wg_he_mimo_ant(uint32 *nss, uint16 *mcsset);
50*4882a593Smuzhiyun #endif /* WL11AX */
51*4882a593Smuzhiyun static int wg_parse_ap_stadata(struct net_device *dev, struct ether_addr *sta_mac,
52*4882a593Smuzhiyun 		wl_ap_sta_data_t *ap_sta_data);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun static void
dump_ap_stadata(wl_ap_sta_data_t * ap_sta_data)55*4882a593Smuzhiyun dump_ap_stadata(wl_ap_sta_data_t *ap_sta_data)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun 	int i;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	if (!ap_sta_data) {
60*4882a593Smuzhiyun 		WL_AP_BIGDATA_LOG(("ap_sta_data is NULL\n"));
61*4882a593Smuzhiyun 		return;
62*4882a593Smuzhiyun 	}
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	for (i = 0; i < MAX_STA_INFO_AP_CNT; i++) {
65*4882a593Smuzhiyun 		if (!ap_sta_data[i].is_empty) {
66*4882a593Smuzhiyun 			WL_AP_BIGDATA_LOG(("idx %d "MACDBG" dis %d empty %d\n",
67*4882a593Smuzhiyun 				i, MAC2STRDBG((char *)&ap_sta_data[i].mac),
68*4882a593Smuzhiyun 				ap_sta_data[i].disconnected, ap_sta_data[i].is_empty));
69*4882a593Smuzhiyun 			WL_AP_BIGDATA_LOG(("mode %d nss %d chanspec %d rssi %d "
70*4882a593Smuzhiyun 						"rate %d reason_code %d\n\n",
71*4882a593Smuzhiyun 						ap_sta_data[i].mode_80211,
72*4882a593Smuzhiyun 						ap_sta_data[i].nss, ap_sta_data[i].chanspec,
73*4882a593Smuzhiyun 						ap_sta_data[i].rssi, ap_sta_data[i].rate,
74*4882a593Smuzhiyun 						ap_sta_data[i].reason_code));
75*4882a593Smuzhiyun 		}
76*4882a593Smuzhiyun 	}
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun static inline void
copy_ap_stadata(wl_ap_sta_data_t * dest,wl_ap_sta_data_t * src)80*4882a593Smuzhiyun copy_ap_stadata(wl_ap_sta_data_t *dest, wl_ap_sta_data_t *src)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun 	memcpy(dest, src, sizeof(wl_ap_sta_data_t));
83*4882a593Smuzhiyun 	dest->is_empty = FALSE;
84*4882a593Smuzhiyun 	dest->disconnected = FALSE;
85*4882a593Smuzhiyun 	dest->reason_code = 0;
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun static void
get_copy_ptr_stadata(struct ether_addr * sta_mac,wl_ap_sta_data_t * sta_data,uint32 * sta_list_cnt,void ** data)89*4882a593Smuzhiyun get_copy_ptr_stadata(struct ether_addr *sta_mac, wl_ap_sta_data_t *sta_data,
90*4882a593Smuzhiyun 		uint32 *sta_list_cnt, void **data)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun 	int i;
93*4882a593Smuzhiyun 	int discon_idx = -1;
94*4882a593Smuzhiyun 	int empty_idx = -1;
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	if  (!sta_mac || !sta_data || !sta_list_cnt ||!data) {
97*4882a593Smuzhiyun 		WL_ERR(("sta_mac=%p sta_data=%p sta_lit_cnt=%p data=%p\n",
98*4882a593Smuzhiyun 			sta_mac, sta_data, sta_list_cnt, data));
99*4882a593Smuzhiyun 		return;
100*4882a593Smuzhiyun 	}
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	/* Find already existed sta */
103*4882a593Smuzhiyun 	for (i = 0; i < MAX_STA_INFO_AP_CNT; i++) {
104*4882a593Smuzhiyun 		if (!memcmp((char*)sta_mac, (char*)&sta_data[i].mac, ETHER_ADDR_LEN)) {
105*4882a593Smuzhiyun 			WL_AP_BIGDATA_LOG(("found existed "
106*4882a593Smuzhiyun 						"STA idx %d "MACDBG"\n",
107*4882a593Smuzhiyun 						i, MAC2STRDBG((char *)sta_mac)));
108*4882a593Smuzhiyun 			*data = (wl_ap_sta_data_t *)&sta_data[i];
109*4882a593Smuzhiyun 			return;
110*4882a593Smuzhiyun 		}
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 		if (sta_data[i].disconnected && (discon_idx == -1)) {
113*4882a593Smuzhiyun 			discon_idx = i;
114*4882a593Smuzhiyun 		}
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 		if (sta_data[i].is_empty && (empty_idx == -1)) {
117*4882a593Smuzhiyun 			empty_idx = i;
118*4882a593Smuzhiyun 		}
119*4882a593Smuzhiyun 	}
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun 	/* Buf is max */
122*4882a593Smuzhiyun 	if (*sta_list_cnt >= MAX_STA_INFO_AP_CNT) {
123*4882a593Smuzhiyun 		if (discon_idx != -1) {
124*4882a593Smuzhiyun 			WL_AP_BIGDATA_LOG(("delete disconnected "
125*4882a593Smuzhiyun 						"idx %d "MACDBG"\n",
126*4882a593Smuzhiyun 						discon_idx, MAC2STRDBG((char *)sta_mac)));
127*4882a593Smuzhiyun 			*data = (wl_ap_sta_data_t *)&sta_data[discon_idx];
128*4882a593Smuzhiyun 			return;
129*4882a593Smuzhiyun 		}
130*4882a593Smuzhiyun 	}
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	/* Buf is not max */
133*4882a593Smuzhiyun 	if (empty_idx != -1) {
134*4882a593Smuzhiyun 		(*sta_list_cnt)++;
135*4882a593Smuzhiyun 		WL_AP_BIGDATA_LOG(("empty idx %d \n", empty_idx));
136*4882a593Smuzhiyun 		*data = (wl_ap_sta_data_t *)&sta_data[empty_idx];
137*4882a593Smuzhiyun 		return;
138*4882a593Smuzhiyun 	}
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun static void
wg_rate_dot11mode(uint32 * rate,uint8 * channel,uint32 * mode_80211)142*4882a593Smuzhiyun wg_rate_dot11mode(uint32 *rate, uint8 *channel, uint32 *mode_80211)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun 	if (*rate <= DOT11_11B_MAX_RATE) {
145*4882a593Smuzhiyun 		/* 11b maximum rate is 11Mbps. 11b mode */
146*4882a593Smuzhiyun 		*mode_80211 = BIGDATA_DOT11_11B_MODE;
147*4882a593Smuzhiyun 	} else {
148*4882a593Smuzhiyun 		/* It's not HT Capable case. */
149*4882a593Smuzhiyun 		if (*channel > DOT11_2GHZ_MAX_CH_NUM) {
150*4882a593Smuzhiyun 			*mode_80211 = BIGDATA_DOT11_11A_MODE; /* 11a mode */
151*4882a593Smuzhiyun 		} else {
152*4882a593Smuzhiyun 			*mode_80211 = BIGDATA_DOT11_11G_MODE; /* 11g mode */
153*4882a593Smuzhiyun 		}
154*4882a593Smuzhiyun 	}
155*4882a593Smuzhiyun }
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun static void
wg_ht_mimo_ant(uint32 * nss,wl_rateset_args_t * rateset)158*4882a593Smuzhiyun wg_ht_mimo_ant(uint32 *nss, wl_rateset_args_t *rateset)
159*4882a593Smuzhiyun {
160*4882a593Smuzhiyun 	int i;
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	*nss = 0;
163*4882a593Smuzhiyun 	for (i = 0; i < MAX_STREAMS_SUPPORTED; i++) {
164*4882a593Smuzhiyun 		int8 bitmap = DOT11_HT_MCS_RATE_MASK;
165*4882a593Smuzhiyun 		if (i == MAX_STREAMS_SUPPORTED-1) {
166*4882a593Smuzhiyun 			bitmap = DOT11_RATE_MASK;
167*4882a593Smuzhiyun 		}
168*4882a593Smuzhiyun 		if (rateset->mcs[i] & bitmap) {
169*4882a593Smuzhiyun 			(*nss)++;
170*4882a593Smuzhiyun 		}
171*4882a593Smuzhiyun 	}
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun static void
wg_vht_mimo_ant(uint32 * nss,wl_rateset_args_t * rateset)175*4882a593Smuzhiyun wg_vht_mimo_ant(uint32 *nss, wl_rateset_args_t *rateset)
176*4882a593Smuzhiyun {
177*4882a593Smuzhiyun 	int i;
178*4882a593Smuzhiyun 	uint32 mcs_code;
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	*nss = 0;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	for (i = 1; i <= VHT_CAP_MCS_MAP_NSS_MAX; i++) {
183*4882a593Smuzhiyun 		mcs_code = VHT_MCS_MAP_TO_MCS_CODE(rateset->vht_mcs[i - 1]);
184*4882a593Smuzhiyun 		if (mcs_code != VHT_CAP_MCS_MAP_NONE) {
185*4882a593Smuzhiyun 			(*nss)++;
186*4882a593Smuzhiyun 		}
187*4882a593Smuzhiyun 	}
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun #if defined(WL11AX)
191*4882a593Smuzhiyun static void
wg_he_mimo_ant(uint32 * nss,uint16 * mcsset)192*4882a593Smuzhiyun wg_he_mimo_ant(uint32 *nss, uint16 *mcsset)
193*4882a593Smuzhiyun {
194*4882a593Smuzhiyun 	int i;
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	*nss = 0;
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	for (i = 0; i <= HE_MCS_MAP_NSS_MAX; i++) {
199*4882a593Smuzhiyun 		if (mcsset[i]) {
200*4882a593Smuzhiyun 			(*nss)++;
201*4882a593Smuzhiyun 		}
202*4882a593Smuzhiyun 	}
203*4882a593Smuzhiyun }
204*4882a593Smuzhiyun #endif /* WL11AX */
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun static int
wg_parse_ap_stadata(struct net_device * dev,struct ether_addr * sta_mac,wl_ap_sta_data_t * ap_sta_data)207*4882a593Smuzhiyun wg_parse_ap_stadata(struct net_device *dev, struct ether_addr *sta_mac,
208*4882a593Smuzhiyun 		wl_ap_sta_data_t *ap_sta_data)
209*4882a593Smuzhiyun {
210*4882a593Smuzhiyun 	sta_info_v4_t *sta_v4 = NULL;
211*4882a593Smuzhiyun 	sta_info_v5_t *sta_v5 = NULL;
212*4882a593Smuzhiyun 	wl_rateset_args_t *rateset_adv;
213*4882a593Smuzhiyun 	int ret = BCME_OK;
214*4882a593Smuzhiyun 	char* ioctl_buf = NULL;
215*4882a593Smuzhiyun #if defined(WL11AX)
216*4882a593Smuzhiyun 	struct wl_rateset_args_v2 *rateset_adv_v2;
217*4882a593Smuzhiyun #endif
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 	ioctl_buf = (char*)kmalloc(WLC_IOCTL_MEDLEN, GFP_KERNEL);
220*4882a593Smuzhiyun 	if (ioctl_buf == NULL) {
221*4882a593Smuzhiyun 		WL_ERR(("failed to allocated ioctl_buf \n"));
222*4882a593Smuzhiyun 		return BCME_ERROR;
223*4882a593Smuzhiyun 	}
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun 	ret = wldev_iovar_getbuf(dev, "sta_info", (struct ether_addr *)sta_mac,
226*4882a593Smuzhiyun 			ETHER_ADDR_LEN, ioctl_buf, WLC_IOCTL_MEDLEN, NULL);
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun 	if (ret < 0) {
229*4882a593Smuzhiyun 		WL_ERR(("sta_info err value :%d\n", ret));
230*4882a593Smuzhiyun 		ret = BCME_ERROR;
231*4882a593Smuzhiyun 		goto done;
232*4882a593Smuzhiyun 	}
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun 	sta_v4 = (sta_info_v4_t *)ioctl_buf;
235*4882a593Smuzhiyun 	ap_sta_data->mac = *sta_mac;
236*4882a593Smuzhiyun 	ap_sta_data->rssi = 0;
237*4882a593Smuzhiyun 	ap_sta_data->mimo = 0;
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	rateset_adv = &sta_v4->rateset_adv;
240*4882a593Smuzhiyun 	ap_sta_data->chanspec = sta_v4->chanspec;
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun 	WL_AP_BIGDATA_LOG(("sta_info ver %d\n", sta_v4->ver));
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun 	if (sta_v4->ver == WL_STA_VER_5) {
245*4882a593Smuzhiyun 		sta_v5 = (sta_info_v5_t *)ioctl_buf;
246*4882a593Smuzhiyun 		ap_sta_data->chanspec = sta_v5->chanspec;
247*4882a593Smuzhiyun 		rateset_adv = &sta_v5->rateset_adv;
248*4882a593Smuzhiyun 	}
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun 	ap_sta_data->channel = wf_chspec_ctlchan(ap_sta_data->chanspec);
251*4882a593Smuzhiyun 	ap_sta_data->rate =
252*4882a593Smuzhiyun 		(sta_v4->rateset.rates[sta_v4->rateset.count - 1] & DOT11_RATE_MASK) / 2;
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 	if (sta_v4->vht_flags) {
255*4882a593Smuzhiyun 		ap_sta_data->mode_80211 = BIGDATA_DOT11_11AC_MODE;
256*4882a593Smuzhiyun 		wg_vht_mimo_ant(&ap_sta_data->nss, rateset_adv);
257*4882a593Smuzhiyun 	} else if (sta_v4->ht_capabilities) {
258*4882a593Smuzhiyun 		ap_sta_data->mode_80211 = BIGDATA_DOT11_11N_MODE;
259*4882a593Smuzhiyun 		wg_ht_mimo_ant(&ap_sta_data->nss, rateset_adv);
260*4882a593Smuzhiyun 	} else {
261*4882a593Smuzhiyun 		wg_rate_dot11mode(&ap_sta_data->rate, &ap_sta_data->channel,
262*4882a593Smuzhiyun 				&ap_sta_data->mode_80211);
263*4882a593Smuzhiyun 	}
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun #if defined(WL11AX)
266*4882a593Smuzhiyun 	ret = wldev_iovar_getbuf(dev, "rateset", NULL, 0, ioctl_buf,
267*4882a593Smuzhiyun 			sizeof(wl_rateset_args_v2_t), NULL);
268*4882a593Smuzhiyun 	if (ret < 0) {
269*4882a593Smuzhiyun 		WL_ERR(("get rateset failed = %d\n", ret));
270*4882a593Smuzhiyun 	} else {
271*4882a593Smuzhiyun 		rateset_adv_v2 = (wl_rateset_args_v2_t *)ioctl_buf;
272*4882a593Smuzhiyun 		WL_AP_BIGDATA_LOG(("rateset ver %d\n", rateset_adv_v2->version));
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun 		if (rateset_adv_v2->version == RATESET_ARGS_V2) {
275*4882a593Smuzhiyun 			rateset_adv_v2 = (wl_rateset_args_v2_t *)&sta_v4->rateset_adv;
276*4882a593Smuzhiyun 			if (sta_v4->ver == WL_STA_VER_5) {
277*4882a593Smuzhiyun 				rateset_adv_v2 = (wl_rateset_args_v2_t *)&sta_v5->rateset_adv;
278*4882a593Smuzhiyun 			}
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 			if (rateset_adv_v2->he_mcs[0]) {
281*4882a593Smuzhiyun 				WL_AP_BIGDATA_LOG(("there is he mcs rate\n"));
282*4882a593Smuzhiyun 				ap_sta_data->mode_80211 = BIGDATA_DOT11_11AX_MODE;
283*4882a593Smuzhiyun 				wg_he_mimo_ant(&ap_sta_data->nss, &rateset_adv_v2->he_mcs[0]);
284*4882a593Smuzhiyun 			}
285*4882a593Smuzhiyun 		}
286*4882a593Smuzhiyun 	}
287*4882a593Smuzhiyun #endif /* WL11AX */
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun 	if (ap_sta_data->nss) {
290*4882a593Smuzhiyun 		ap_sta_data->nss = ap_sta_data->nss - 1;
291*4882a593Smuzhiyun 	}
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun done:
294*4882a593Smuzhiyun 	if (ioctl_buf) {
295*4882a593Smuzhiyun 		kfree(ioctl_buf);
296*4882a593Smuzhiyun 	}
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 	return ret;
299*4882a593Smuzhiyun }
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun void
wl_gather_ap_stadata(void * handle,void * event_info,u8 event)302*4882a593Smuzhiyun wl_gather_ap_stadata(void *handle, void *event_info, u8 event)
303*4882a593Smuzhiyun {
304*4882a593Smuzhiyun 	u32 event_type = 0;
305*4882a593Smuzhiyun 	u32 reason = 0;
306*4882a593Smuzhiyun 	u32 status = 0;
307*4882a593Smuzhiyun 	struct ether_addr sta_mac;
308*4882a593Smuzhiyun 	dhd_pub_t *dhdp;
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 	struct net_device *dev = NULL;
311*4882a593Smuzhiyun 	struct bcm_cfg80211 *cfg = NULL;
312*4882a593Smuzhiyun 	wl_event_msg_t *e;
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun 	wl_ap_sta_data_t *sta_data;
315*4882a593Smuzhiyun 	wl_ap_sta_data_t temp_sta_data;
316*4882a593Smuzhiyun 	void *data = NULL;
317*4882a593Smuzhiyun 	int i;
318*4882a593Smuzhiyun 	int ret;
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun 	ap_sta_wq_data_t *wq_event_data = event_info;
321*4882a593Smuzhiyun 	if (!wq_event_data) {
322*4882a593Smuzhiyun 		WL_ERR(("wq_event_data is NULL\n"));
323*4882a593Smuzhiyun 		return;
324*4882a593Smuzhiyun 	}
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun 	cfg = (struct bcm_cfg80211 *)wq_event_data->bcm_cfg;
327*4882a593Smuzhiyun 	if (!cfg || !cfg->ap_sta_info) {
328*4882a593Smuzhiyun 		WL_ERR(("cfg=%p ap_sta_info=%p\n", cfg, (cfg ? cfg->ap_sta_info : NULL)));
329*4882a593Smuzhiyun 		if (wq_event_data) {
330*4882a593Smuzhiyun 			kfree(wq_event_data);
331*4882a593Smuzhiyun 		}
332*4882a593Smuzhiyun 		return;
333*4882a593Smuzhiyun 	}
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 	mutex_lock(&cfg->ap_sta_info->wq_data_sync);
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 	dhdp = (dhd_pub_t *)cfg->pub;
338*4882a593Smuzhiyun 	e = &wq_event_data->e;
339*4882a593Smuzhiyun 	dev = (struct net_device *)wq_event_data->ndev;
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun 	if (!e || !dev) {
342*4882a593Smuzhiyun 		WL_ERR(("e=%p dev=%p\n", e, dev));
343*4882a593Smuzhiyun 		goto done;
344*4882a593Smuzhiyun 	}
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun 	if (!wl_get_drv_status(cfg, AP_CREATED, dev)) {
347*4882a593Smuzhiyun 		WL_ERR(("skip to gather data becasue interface is not available\n"));
348*4882a593Smuzhiyun 		goto done;
349*4882a593Smuzhiyun 	}
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	sta_data = cfg->ap_sta_info->ap_sta_data;
352*4882a593Smuzhiyun 
353*4882a593Smuzhiyun 	event_type = ntoh32(e->event_type);
354*4882a593Smuzhiyun 	reason = ntoh32(e->reason);
355*4882a593Smuzhiyun 	status = ntoh32(e->status);
356*4882a593Smuzhiyun 	sta_mac = e->addr;
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	if (!sta_data) {
359*4882a593Smuzhiyun 		WL_ERR(("sta_data is NULL\n"));
360*4882a593Smuzhiyun 		goto done;
361*4882a593Smuzhiyun 	}
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun 	WL_AP_BIGDATA_LOG((""MACDBG" event %d status %d reason %d\n",
364*4882a593Smuzhiyun 		MAC2STRDBG((char*)&sta_mac), event_type, status, reason));
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun 	if (WLC_E_IS_ASSOC(event_type, reason)) {
367*4882a593Smuzhiyun 		ret = wg_parse_ap_stadata(dev, &sta_mac, &temp_sta_data);
368*4882a593Smuzhiyun 		if (ret < 0) {
369*4882a593Smuzhiyun 			WL_AP_BIGDATA_LOG(("sta_info err value :%d\n", ret));
370*4882a593Smuzhiyun 			goto done;
371*4882a593Smuzhiyun 		}
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun 		if (cfg->ap_sta_info->sta_list_cnt == 0) {
374*4882a593Smuzhiyun 			copy_ap_stadata(&sta_data[0], &temp_sta_data);
375*4882a593Smuzhiyun 			cfg->ap_sta_info->sta_list_cnt++;
376*4882a593Smuzhiyun 			dump_ap_stadata(sta_data);
377*4882a593Smuzhiyun 		} else {
378*4882a593Smuzhiyun 			get_copy_ptr_stadata(&sta_mac, sta_data,
379*4882a593Smuzhiyun 					&cfg->ap_sta_info->sta_list_cnt, &data);
380*4882a593Smuzhiyun 			if (data != NULL) {
381*4882a593Smuzhiyun 				copy_ap_stadata((wl_ap_sta_data_t *)data, &temp_sta_data);
382*4882a593Smuzhiyun 				dump_ap_stadata(sta_data);
383*4882a593Smuzhiyun 			}
384*4882a593Smuzhiyun 		}
385*4882a593Smuzhiyun 	}
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun 	if (WLC_E_IS_DEAUTH(event_type)) {
388*4882a593Smuzhiyun 		/* Find already existed sta */
389*4882a593Smuzhiyun 		for (i = 0; i < MAX_STA_INFO_AP_CNT; i++) {
390*4882a593Smuzhiyun 			if (!sta_data[i].is_empty &&
391*4882a593Smuzhiyun 				!memcmp((char*)&sta_mac, (char*)&sta_data[i].mac, ETHER_ADDR_LEN)) {
392*4882a593Smuzhiyun 				WL_AP_BIGDATA_LOG(("found disconnected "
393*4882a593Smuzhiyun 							"STA idx %d "MACDBG"\n",
394*4882a593Smuzhiyun 							i, MAC2STRDBG((char *)&sta_mac)));
395*4882a593Smuzhiyun 				sta_data[i].is_empty = FALSE;
396*4882a593Smuzhiyun 				sta_data[i].disconnected = TRUE;
397*4882a593Smuzhiyun 				sta_data[i].reason_code = reason;
398*4882a593Smuzhiyun 				dump_ap_stadata(sta_data);
399*4882a593Smuzhiyun 				goto done;
400*4882a593Smuzhiyun 			}
401*4882a593Smuzhiyun 		}
402*4882a593Smuzhiyun 	}
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun done:
405*4882a593Smuzhiyun 	if (wq_event_data) {
406*4882a593Smuzhiyun 		ASSERT(dhdp->osh);
407*4882a593Smuzhiyun 		MFREE(dhdp->osh, wq_event_data, sizeof(ap_sta_wq_data_t));
408*4882a593Smuzhiyun 	}
409*4882a593Smuzhiyun 	mutex_unlock(&cfg->ap_sta_info->wq_data_sync);
410*4882a593Smuzhiyun }
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun int
wl_attach_ap_stainfo(void * bcm_cfg)413*4882a593Smuzhiyun wl_attach_ap_stainfo(void *bcm_cfg)
414*4882a593Smuzhiyun {
415*4882a593Smuzhiyun 	gfp_t kflags;
416*4882a593Smuzhiyun 	uint32 alloc_len;
417*4882a593Smuzhiyun 	wl_ap_sta_info_t *sta_info;
418*4882a593Smuzhiyun 	wl_ap_sta_data_t *sta_data = NULL;
419*4882a593Smuzhiyun 	int i;
420*4882a593Smuzhiyun 	struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)bcm_cfg;
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	if (!cfg) {
423*4882a593Smuzhiyun 		WL_ERR(("cfg is NULL\n"));
424*4882a593Smuzhiyun 		return -EINVAL;
425*4882a593Smuzhiyun 	}
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun 	kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	alloc_len = sizeof(wl_ap_sta_info_t);
430*4882a593Smuzhiyun 	sta_info = (wl_ap_sta_info_t *)kzalloc(alloc_len, kflags);
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun 	if (unlikely(!sta_info)) {
433*4882a593Smuzhiyun 		WL_ERR(("could not allocate memory for - "
434*4882a593Smuzhiyun 					"wl_ap_sta_info_t\n"));
435*4882a593Smuzhiyun 		goto fail;
436*4882a593Smuzhiyun 	}
437*4882a593Smuzhiyun 	cfg->ap_sta_info = sta_info;
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun 	alloc_len = sizeof(wl_ap_sta_data_t) * MAX_STA_INFO_AP_CNT;
440*4882a593Smuzhiyun 	sta_data = (wl_ap_sta_data_t *)kzalloc(alloc_len, kflags);
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun 	if (unlikely(!sta_data)) {
443*4882a593Smuzhiyun 		WL_ERR(("could not allocate memory for - "
444*4882a593Smuzhiyun 					"wl_ap_sta_data_t\n"));
445*4882a593Smuzhiyun 		goto fail;
446*4882a593Smuzhiyun 	}
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun 	cfg->ap_sta_info->sta_list_cnt = 0;
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun 	for (i = 0; i < MAX_STA_INFO_AP_CNT; i++) {
451*4882a593Smuzhiyun 		sta_data[i].is_empty = TRUE;
452*4882a593Smuzhiyun 		memset(&sta_data[i].mac, 0, ETHER_ADDR_LEN);
453*4882a593Smuzhiyun 	}
454*4882a593Smuzhiyun 
455*4882a593Smuzhiyun 	cfg->ap_sta_info->ap_sta_data = sta_data;
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	mutex_init(&cfg->ap_sta_info->wq_data_sync);
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun 	WL_ERR(("attach success\n"));
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun 	return BCME_OK;
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun fail:
464*4882a593Smuzhiyun 	if (sta_data) {
465*4882a593Smuzhiyun 		kfree(sta_data);
466*4882a593Smuzhiyun 		cfg->ap_sta_info->ap_sta_data = NULL;
467*4882a593Smuzhiyun 	}
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun 	if (sta_info) {
470*4882a593Smuzhiyun 		kfree(sta_info);
471*4882a593Smuzhiyun 		cfg->ap_sta_info = NULL;
472*4882a593Smuzhiyun 	}
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun 	return BCME_ERROR;
475*4882a593Smuzhiyun }
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun int
wl_detach_ap_stainfo(void * bcm_cfg)478*4882a593Smuzhiyun wl_detach_ap_stainfo(void *bcm_cfg)
479*4882a593Smuzhiyun {
480*4882a593Smuzhiyun 	struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)bcm_cfg;
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun 	if (!cfg || !cfg->ap_sta_info) {
483*4882a593Smuzhiyun 		WL_ERR(("cfg=%p ap_sta_info=%p\n",
484*4882a593Smuzhiyun 			cfg, (cfg ? cfg->ap_sta_info : NULL)));
485*4882a593Smuzhiyun 		return -EINVAL;
486*4882a593Smuzhiyun 	}
487*4882a593Smuzhiyun 
488*4882a593Smuzhiyun 	if (cfg->ap_sta_info->ap_sta_data) {
489*4882a593Smuzhiyun 		kfree(cfg->ap_sta_info->ap_sta_data);
490*4882a593Smuzhiyun 		cfg->ap_sta_info->ap_sta_data = NULL;
491*4882a593Smuzhiyun 	}
492*4882a593Smuzhiyun 
493*4882a593Smuzhiyun 	mutex_destroy(&cfg->ap_sta_info->wq_data_sync);
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun 	kfree(cfg->ap_sta_info);
496*4882a593Smuzhiyun 	cfg->ap_sta_info = NULL;
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun 	WL_ERR(("detach success\n"));
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun 	return BCME_OK;
501*4882a593Smuzhiyun }
502*4882a593Smuzhiyun 
503*4882a593Smuzhiyun int
wl_ap_stainfo_init(void * bcm_cfg)504*4882a593Smuzhiyun wl_ap_stainfo_init(void *bcm_cfg)
505*4882a593Smuzhiyun {
506*4882a593Smuzhiyun 	int i;
507*4882a593Smuzhiyun 	wl_ap_sta_data_t *sta_data;
508*4882a593Smuzhiyun 	struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)bcm_cfg;
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun 	if (!cfg || !cfg->ap_sta_info) {
511*4882a593Smuzhiyun 		WL_ERR(("cfg=%p ap_sta_info=%p\n",
512*4882a593Smuzhiyun 			cfg, (cfg ? cfg->ap_sta_info : NULL)));
513*4882a593Smuzhiyun 		return -EINVAL;
514*4882a593Smuzhiyun 	}
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun 	sta_data = cfg->ap_sta_info->ap_sta_data;
517*4882a593Smuzhiyun 	cfg->ap_sta_info->sta_list_cnt = 0;
518*4882a593Smuzhiyun 
519*4882a593Smuzhiyun 	if (!sta_data) {
520*4882a593Smuzhiyun 		WL_ERR(("ap_sta_data is NULL\n"));
521*4882a593Smuzhiyun 		return -EINVAL;
522*4882a593Smuzhiyun 	}
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun 	for (i = 0; i < MAX_STA_INFO_AP_CNT; i++) {
525*4882a593Smuzhiyun 		sta_data[i].is_empty = TRUE;
526*4882a593Smuzhiyun 		memset(&sta_data[i].mac, 0, ETHER_ADDR_LEN);
527*4882a593Smuzhiyun 	}
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun 	return BCME_OK;
530*4882a593Smuzhiyun }
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun int
wl_get_ap_stadata(void * bcm_cfg,struct ether_addr * sta_mac,void ** data)533*4882a593Smuzhiyun wl_get_ap_stadata(void *bcm_cfg, struct ether_addr *sta_mac, void **data)
534*4882a593Smuzhiyun {
535*4882a593Smuzhiyun 	int i;
536*4882a593Smuzhiyun 	wl_ap_sta_data_t *sta_data;
537*4882a593Smuzhiyun 	struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)bcm_cfg;
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun 	if (!cfg || !cfg->ap_sta_info) {
540*4882a593Smuzhiyun 		WL_ERR(("cfg=%p ap_sta_info=%p\n",
541*4882a593Smuzhiyun 			cfg, (cfg ? cfg->ap_sta_info : NULL)));
542*4882a593Smuzhiyun 		return -EINVAL;
543*4882a593Smuzhiyun 	}
544*4882a593Smuzhiyun 
545*4882a593Smuzhiyun 	if  (!sta_mac || !data) {
546*4882a593Smuzhiyun 		WL_ERR(("sta_mac=%p data=%p\n", sta_mac, data));
547*4882a593Smuzhiyun 		return -EINVAL;
548*4882a593Smuzhiyun 	}
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun 	sta_data = cfg->ap_sta_info->ap_sta_data;
551*4882a593Smuzhiyun 
552*4882a593Smuzhiyun 	if (!sta_data) {
553*4882a593Smuzhiyun 		WL_ERR(("ap_sta_data is NULL\n"));
554*4882a593Smuzhiyun 		return -EINVAL;
555*4882a593Smuzhiyun 	}
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	/* Find already existed sta */
558*4882a593Smuzhiyun 	for (i = 0; i < MAX_STA_INFO_AP_CNT; i++) {
559*4882a593Smuzhiyun 		if (!sta_data[i].is_empty) {
560*4882a593Smuzhiyun 			WL_AP_BIGDATA_LOG(("%d " MACDBG " " MACDBG "\n", i,
561*4882a593Smuzhiyun 				MAC2STRDBG((char *)sta_mac),
562*4882a593Smuzhiyun 				MAC2STRDBG((char*)&sta_data[i].mac)));
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 			if (!memcmp(sta_mac, (char*)&sta_data[i].mac, ETHER_ADDR_LEN)) {
565*4882a593Smuzhiyun 				WL_AP_BIGDATA_LOG(("Found STA idx %d " MACDBG "\n",
566*4882a593Smuzhiyun 					i, MAC2STRDBG((char *)&sta_mac)));
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun 				*data = (wl_ap_sta_data_t*)&sta_data[i];
569*4882a593Smuzhiyun 				return BCME_OK;
570*4882a593Smuzhiyun 			}
571*4882a593Smuzhiyun 		}
572*4882a593Smuzhiyun 	}
573*4882a593Smuzhiyun 
574*4882a593Smuzhiyun 	return BCME_ERROR;
575*4882a593Smuzhiyun }
576