• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Broadcom Dongle Host Driver (DHD)
3  *
4  * Copyright (C) 1999-2018, Broadcom.
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  * $Id: dhd_csi.c 606280 2015-12-15 05:28:25Z $
25  */
26 #include <osl.h>
27 
28 #include <bcmutils.h>
29 
30 #include <bcmendian.h>
31 #include <linuxver.h>
32 #include <linux/list.h>
33 #include <linux/sort.h>
34 #include <dngl_stats.h>
35 #include <wlioctl.h>
36 
37 #include <bcmevent.h>
38 #include <dhd.h>
39 #include <dhd_dbg.h>
40 #include <dhd_csi.h>
41 
42 #define NULL_CHECK(p, s, err)  \
43 	do { \
44 		if (!(p)) { \
45 			printf("NULL POINTER (%s) : %s\n", __FUNCTION__, (s)); \
46 			err = BCME_ERROR; \
47 			return err; \
48 		} \
49 	} while (0)
50 
51 #define TIMESPEC_TO_US(ts)  (((uint64)(ts).tv_sec * USEC_PER_SEC) + \
52 						(ts).tv_nsec / NSEC_PER_USEC)
53 
54 #define NULL_ADDR	"\x00\x00\x00\x00\x00\x00"
55 
56 int
dhd_csi_event_handler(dhd_pub_t * dhd,wl_event_msg_t * event,void * event_data)57 dhd_csi_event_handler(dhd_pub_t *dhd, wl_event_msg_t *event, void *event_data)
58 {
59 	int ret = BCME_OK;
60 	bool is_new = TRUE;
61 	cfr_dump_data_t *p_event;
62 	cfr_dump_list_t *ptr, *next, *new;
63 
64 	NULL_CHECK(dhd, "dhd is NULL", ret);
65 
66 	DHD_TRACE(("Enter %s\n", __FUNCTION__));
67 
68 	if (!event_data) {
69 		DHD_ERROR(("%s: event_data is NULL\n", __FUNCTION__));
70 		return -EINVAL;
71 	}
72 	p_event = (cfr_dump_data_t *)event_data;
73 
74 	/* check if this addr exist */
75 	if (!list_empty(&dhd->csi_list)) {
76 		list_for_each_entry_safe(ptr, next, &dhd->csi_list, list) {
77 			if (bcmp(&ptr->entry.header.peer_macaddr, &p_event->header.peer_macaddr,
78 					ETHER_ADDR_LEN) == 0) {
79 				int pos = 0, dump_len = 0, remain = 0;
80 				is_new = FALSE;
81 				DHD_INFO(("CSI data exist\n"));
82 				if (p_event->header.status == 0) {
83 					bcopy(&p_event->header, &ptr->entry.header, sizeof(cfr_dump_header_t));
84 					dump_len = p_event->header.cfr_dump_length;
85 					if (dump_len < MAX_EVENT_SIZE) {
86 						bcopy(&p_event->data, &ptr->entry.data, dump_len);
87 					} else {
88 						/* for big csi data */
89 						uint8 *p = (uint8 *)&ptr->entry.data;
90 						remain = p_event->header.remain_length;
91 						if (remain) {
92 							pos = dump_len - remain - MAX_EVENT_SIZE;
93 							p += pos;
94 							bcopy(&p_event->data, p, MAX_EVENT_SIZE);
95 						}
96 						/* copy rest of csi data */
97 						else {
98 							pos = dump_len - (dump_len % MAX_EVENT_SIZE);
99 							p += pos;
100 							bcopy(&p_event->data, p, (dump_len % MAX_EVENT_SIZE));
101 						}
102 					}
103 					return BCME_OK;
104 				}
105 			}
106 		}
107 	}
108 	if (is_new) {
109 		if (dhd->csi_count < MAX_CSI_NUM) {
110 			new = (cfr_dump_list_t *)MALLOCZ(dhd->osh, sizeof(cfr_dump_list_t));
111 			if (!new){
112 				DHD_ERROR(("Malloc cfr dump list error\n"));
113 				return BCME_NOMEM;
114 			}
115 			bcopy(&p_event->header, &new->entry.header, sizeof(cfr_dump_header_t));
116 			DHD_INFO(("New entry data size %d\n", p_event->header.cfr_dump_length));
117 			/* for big csi data */
118 			if (p_event->header.remain_length) {
119 				DHD_TRACE(("remain %d\n", p_event->header.remain_length));
120 				bcopy(&p_event->data, &new->entry.data, MAX_EVENT_SIZE);
121 			}
122 			else
123 				bcopy(&p_event->data, &new->entry.data, p_event->header.cfr_dump_length);
124 			INIT_LIST_HEAD(&(new->list));
125 			list_add_tail(&(new->list), &dhd->csi_list);
126 			dhd->csi_count++;
127 		}
128 		else {
129 			DHD_TRACE(("Over maximum CSI Number 8. SKIP it.\n"));
130 		}
131 	}
132 	return ret;
133 }
134 
135 int
dhd_csi_init(dhd_pub_t * dhd)136 dhd_csi_init(dhd_pub_t *dhd)
137 {
138 	int err = BCME_OK;
139 
140 	NULL_CHECK(dhd, "dhd is NULL", err);
141 	INIT_LIST_HEAD(&dhd->csi_list);
142 	dhd->csi_count = 0;
143 
144 	return err;
145 }
146 
147 int
dhd_csi_deinit(dhd_pub_t * dhd)148 dhd_csi_deinit(dhd_pub_t *dhd)
149 {
150 	int err = BCME_OK;
151 	cfr_dump_list_t *ptr, *next;
152 
153 	NULL_CHECK(dhd, "dhd is NULL", err);
154 
155 	if (!list_empty(&dhd->csi_list)) {
156 		list_for_each_entry_safe(ptr, next, &dhd->csi_list, list) {
157 			list_del(&ptr->list);
158 			MFREE(dhd->osh, ptr, sizeof(cfr_dump_list_t));
159 		}
160 	}
161 	return err;
162 }
163 
164 void
dhd_csi_clean_list(dhd_pub_t * dhd)165 dhd_csi_clean_list(dhd_pub_t *dhd)
166 {
167 	cfr_dump_list_t *ptr, *next;
168 	int num = 0;
169 
170 	if (!dhd) {
171 		DHD_ERROR(("NULL POINTER: %s\n", __FUNCTION__));
172 		return;
173 	}
174 
175 	if (!list_empty(&dhd->csi_list)) {
176 		list_for_each_entry_safe(ptr, next, &dhd->csi_list, list) {
177 			if (0 == ptr->entry.header.remain_length) {
178 				list_del(&ptr->list);
179 				num++;
180 				MFREE(dhd->osh, ptr, sizeof(cfr_dump_list_t));
181 			}
182 		}
183 	}
184 	dhd->csi_count = 0;
185 	DHD_TRACE(("Clean up %d record\n", num));
186 }
187 
188 int
dhd_csi_dump_list(dhd_pub_t * dhd,char * buf)189 dhd_csi_dump_list(dhd_pub_t *dhd, char *buf)
190 {
191 	int ret = BCME_OK;
192 	cfr_dump_list_t *ptr, *next;
193 	uint8 * pbuf = buf;
194 	int num = 0;
195 	int length = 0;
196 
197 	NULL_CHECK(dhd, "dhd is NULL", ret);
198 
199 	/* check if this addr exist */
200 	if (!list_empty(&dhd->csi_list)) {
201 		list_for_each_entry_safe(ptr, next, &dhd->csi_list, list) {
202 			if (ptr->entry.header.remain_length) {
203 				DHD_ERROR(("data not ready %d\n", ptr->entry.header.remain_length));
204 				continue;
205 			}
206 			bcopy(&ptr->entry.header, pbuf, sizeof(cfr_dump_header_t));
207 			length += sizeof(cfr_dump_header_t);
208 			pbuf += sizeof(cfr_dump_header_t);
209 			DHD_TRACE(("Copy data size %d\n", ptr->entry.header.cfr_dump_length));
210 			bcopy(&ptr->entry.data, pbuf, ptr->entry.header.cfr_dump_length);
211 			length += ptr->entry.header.cfr_dump_length;
212 			pbuf += ptr->entry.header.cfr_dump_length;
213 			num++;
214 		}
215 	}
216 	DHD_TRACE(("dump %d record %d bytes\n", num, length));
217 
218 	return length;
219 }
220 
221