hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/dhd_debug_linux.c
....@@ -1,15 +1,18 @@
1
-/* SPDX-License-Identifier: GPL-2.0 */
21 /*
32 * DHD debugability Linux os layer
43 *
5
- * Copyright (C) 1999-2019, Broadcom Corporation
6
- *
4
+ * <<Broadcom-WL-IPTag/Open:>>
5
+ *
6
+ * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
7
+ *
8
+ * Copyright (C) 1999-2017, Broadcom Corporation
9
+ *
710 * Unless you and Broadcom execute a separate written software license
811 * agreement governing use of this software, this software is licensed to you
912 * under the terms of the GNU General Public License version 2 (the "GPL"),
1013 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
1114 * following added to such license:
12
- *
15
+ *
1316 * As a special exception, the copyright holders of this software give you
1417 * permission to link this software with independent modules, and to copy and
1518 * distribute the resulting executable under terms of your choice, provided that
....@@ -17,21 +20,18 @@
1720 * the license of that module. An independent module is a module which is not
1821 * derived from this software. The special exception does not apply to any
1922 * modifications of the software.
20
- *
23
+ *
2124 * Notwithstanding the above, under no circumstances may you combine this
2225 * software in any way with any other Broadcom software provided under a license
2326 * other than the GPL, without Broadcom's express prior written consent.
2427 *
25
- * $Id: dhd_debug_linux.c 554441 2015-05-05 18:45:58Z $
28
+ * $Id: dhd_debug_linux.c 696754 2017-04-28 00:21:58Z $
2629 */
2730
2831 #include <typedefs.h>
2932 #include <osl.h>
3033 #include <bcmutils.h>
3134 #include <bcmendian.h>
32
-#ifndef CUSTOMER_IPCAM
33
-#include <bcmpcie.h>
34
-#endif
3535 #include <dngl_stats.h>
3636 #include <dhd.h>
3737 #include <dhd_dbg.h>
....@@ -61,7 +61,13 @@
6161 {1, WIFI_EVENT_DRIVER_EAPOL_FRAME_RECEIVED, "DRIVER EAPOL RX"},
6262 {2, WIFI_EVENT_DRIVER_SCAN_REQUESTED, "SCAN_REQUESTED"},
6363 {2, WIFI_EVENT_DRIVER_SCAN_COMPLETE, "SCAN COMPELETE"},
64
- {3, WIFI_EVENT_DRIVER_SCAN_RESULT_FOUND, "SCAN RESULT FOUND"}
64
+ {3, WIFI_EVENT_DRIVER_SCAN_RESULT_FOUND, "SCAN RESULT FOUND"},
65
+ {2, WIFI_EVENT_DRIVER_PNO_ADD, "PNO ADD"},
66
+ {2, WIFI_EVENT_DRIVER_PNO_REMOVE, "PNO REMOVE"},
67
+ {2, WIFI_EVENT_DRIVER_PNO_NETWORK_FOUND, "PNO NETWORK FOUND"},
68
+ {2, WIFI_EVENT_DRIVER_PNO_SCAN_REQUESTED, "PNO SCAN_REQUESTED"},
69
+ {1, WIFI_EVENT_DRIVER_PNO_SCAN_RESULT_FOUND, "PNO SCAN RESULT FOUND"},
70
+ {1, WIFI_EVENT_DRIVER_PNO_SCAN_COMPLETE, "PNO SCAN COMPELETE"}
6571 };
6672
6773 static void
....@@ -72,6 +78,8 @@
7278 dbg_ring_send_sub_t ring_sub_send;
7379 ndev = dhd_linux_get_primary_netdev(dhdp);
7480 if (!ndev)
81
+ return;
82
+ if (!VALID_RING(ring_id))
7583 return;
7684 if (ring_send_sub_cb[ring_id]) {
7785 ring_sub_send = ring_send_sub_cb[ring_id];
....@@ -95,53 +103,76 @@
95103 dbg_ring_poll_worker(struct work_struct *work)
96104 {
97105 struct delayed_work *d_work = to_delayed_work(work);
106
+ bool sched = TRUE;
107
+ dhd_dbg_ring_t *ring;
108
+#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
109
+#pragma GCC diagnostic push
110
+#pragma GCC diagnostic ignored "-Wcast-qual"
111
+#endif // endif
98112 linux_dbgring_info_t *ring_info =
99113 container_of(d_work, linux_dbgring_info_t, work);
114
+#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
115
+#pragma GCC diagnostic pop
116
+#endif // endif
100117 dhd_pub_t *dhdp = ring_info->dhdp;
101118 int ringid = ring_info->ring_id;
102119 dhd_dbg_ring_status_t ring_status;
103120 void *buf;
104121 dhd_dbg_ring_entry_t *hdr;
105122 uint32 buflen, rlen;
123
+ unsigned long flags;
106124
125
+ ring = &dhdp->dbg->dbg_rings[ringid];
126
+ DHD_DBG_RING_LOCK(ring->lock, flags);
107127 dhd_dbg_get_ring_status(dhdp, ringid, &ring_status);
108
- if (ring_status.written_bytes > ring_status.read_bytes)
109
- buflen = ring_status.written_bytes - ring_status.read_bytes;
110
- else if (ring_status.written_bytes < ring_status.read_bytes)
111
- buflen = 0xFFFFFFFF + ring_status.written_bytes -
112
- ring_status.read_bytes;
113
- else
128
+
129
+ if (ring->wp > ring->rp) {
130
+ buflen = ring->wp - ring->rp;
131
+ } else if (ring->wp < ring->rp) {
132
+ buflen = ring->ring_size - ring->rp + ring->wp;
133
+ } else {
114134 goto exit;
115
- buf = MALLOC(dhdp->osh, buflen);
135
+ }
136
+
137
+ if (buflen > ring->ring_size) {
138
+ goto exit;
139
+ }
140
+
141
+ buf = MALLOCZ(dhdp->osh, buflen);
116142 if (!buf) {
117143 DHD_ERROR(("%s failed to allocate read buf\n", __FUNCTION__));
118
- return;
144
+ sched = FALSE;
145
+ goto exit;
119146 }
120
- rlen = dhd_dbg_ring_pull(dhdp, ringid, buf, buflen);
147
+
148
+ rlen = dhd_dbg_pull_from_ring(dhdp, ringid, buf, buflen);
149
+
150
+ if (!ring->sched_pull) {
151
+ ring->sched_pull = TRUE;
152
+ }
153
+
121154 hdr = (dhd_dbg_ring_entry_t *)buf;
122155 while (rlen > 0) {
123156 ring_status.read_bytes += ENTRY_LENGTH(hdr);
124157 /* offset fw ts to host ts */
125158 hdr->timestamp += ring_info->tsoffset;
126159 debug_data_send(dhdp, ringid, hdr, ENTRY_LENGTH(hdr),
127
- ring_status);
160
+ ring_status);
128161 rlen -= ENTRY_LENGTH(hdr);
129
- hdr = (dhd_dbg_ring_entry_t *)((void *)hdr + ENTRY_LENGTH(hdr));
162
+ hdr = (dhd_dbg_ring_entry_t *)((char *)hdr + ENTRY_LENGTH(hdr));
130163 }
131164 MFREE(dhdp->osh, buf, buflen);
132165
133
- if (!ring_info->interval)
134
- return;
135
- dhd_dbg_get_ring_status(dhdp, ring_info->ring_id, &ring_status);
136
-
137166 exit:
138
- if (ring_info->interval) {
167
+ if (sched) {
139168 /* retrigger the work at same interval */
140
- if (ring_status.written_bytes == ring_status.read_bytes)
169
+ if ((ring_status.written_bytes == ring_status.read_bytes) &&
170
+ (ring_info->interval)) {
141171 schedule_delayed_work(d_work, ring_info->interval);
142
- else
143
- schedule_delayed_work(d_work, 0);
172
+ }
144173 }
174
+
175
+ DHD_DBG_RING_UNLOCK(ring->lock, flags);
145176
146177 return;
147178 }
....@@ -173,7 +204,6 @@
173204 int ret = BCME_OK;
174205 int ring_id;
175206 linux_dbgring_info_t *os_priv, *ring_info;
176
- uint32 ms;
177207
178208 ring_id = dhd_dbg_find_ring_id(dhdp, ring_name);
179209 if (!VALID_RING(ring_id))
....@@ -194,19 +224,13 @@
194224 return BCME_ERROR;
195225 ring_info = &os_priv[ring_id];
196226 ring_info->log_level = log_level;
197
- if (ring_id == FW_VERBOSE_RING_ID || ring_id == FW_EVENT_RING_ID) {
198
- ring_info->tsoffset = local_clock();
199
- if (dhd_wl_ioctl_get_intiovar(dhdp, "rte_timesync", &ms, WLC_GET_VAR,
200
- FALSE, 0))
201
- DHD_ERROR(("%s rte_timesync failed\n", __FUNCTION__));
202
- do_div(ring_info->tsoffset, 1000000);
203
- ring_info->tsoffset -= ms;
204
- }
227
+
205228 if (time_intval == 0 || log_level == 0) {
206229 ring_info->interval = 0;
207230 cancel_delayed_work_sync(&ring_info->work);
208231 } else {
209232 ring_info->interval = msecs_to_jiffies(time_intval * MSEC_PER_SEC);
233
+ cancel_delayed_work_sync(&ring_info->work);
210234 schedule_delayed_work(&ring_info->work, ring_info->interval);
211235 }
212236
....@@ -257,12 +281,12 @@
257281 if (!os_priv)
258282 return BCME_ERROR;
259283
260
- max_log_level = MAX(os_priv[FW_VERBOSE_RING_ID].log_level,
261
- os_priv[FW_EVENT_RING_ID].log_level);
284
+ max_log_level = os_priv[FW_VERBOSE_RING_ID].log_level;
285
+
262286 if (max_log_level == SUPPRESS_LOG_LEVEL) {
263287 /* suppress the logging in FW not to wake up host while device in suspend mode */
264288 ret = dhd_iovar(dhdp, 0, "logtrace", (char *)&enable, sizeof(enable), NULL, 0,
265
- TRUE);
289
+ TRUE);
266290 if (ret < 0 && (ret != BCME_UNSUPPORTED)) {
267291 DHD_ERROR(("logtrace is failed : %d\n", ret));
268292 }
....@@ -305,17 +329,17 @@
305329 {
306330 int ret = BCME_OK, i;
307331 dhd_dbg_ring_entry_t msg_hdr;
308
- log_conn_event_t event_data;
332
+ log_conn_event_t *event_data = (log_conn_event_t *)data;
309333 linux_dbgring_info_t *os_priv, *ring_info = NULL;
310334
311335 if (!VALID_RING(ring_id))
312336 return BCME_UNSUPPORTED;
313
-
314337 os_priv = dhd_dbg_get_priv(dhdp);
315
- if (!os_priv)
316
- return BCME_UNSUPPORTED;
317338
318
- ring_info = &os_priv[ring_id];
339
+ if (os_priv) {
340
+ ring_info = &os_priv[ring_id];
341
+ } else
342
+ return BCME_NORESOURCE;
319343
320344 memset(&msg_hdr, 0, sizeof(dhd_dbg_ring_entry_t));
321345
....@@ -325,18 +349,17 @@
325349 msg_hdr.flags |= DBG_RING_ENTRY_FLAGS_HAS_BINARY;
326350 msg_hdr.timestamp = local_clock();
327351 /* convert to ms */
328
- do_div(msg_hdr.timestamp, 1000000);
329
- msg_hdr.len = sizeof(event_data);
330
- event_data.event = *((uint16 *)(data));
352
+ msg_hdr.timestamp = DIV_U64_BY_U32(msg_hdr.timestamp, NSEC_PER_MSEC);
353
+ msg_hdr.len = data_len;
331354 /* filter the event for higher log level with current log level */
332355 for (i = 0; i < ARRAYSIZE(dhd_event_map); i++) {
333
- if ((dhd_event_map[i].tag == event_data.event) &&
356
+ if ((dhd_event_map[i].tag == event_data->event) &&
334357 dhd_event_map[i].log_level > ring_info->log_level) {
335358 return ret;
336359 }
337360 }
338361 }
339
- ret = dhd_dbg_ring_push(dhdp, ring_id, &msg_hdr, &event_data);
362
+ ret = dhd_dbg_push_to_ring(dhdp, ring_id, &msg_hdr, event_data);
340363 if (ret) {
341364 DHD_ERROR(("%s : failed to push data into the ring (%d) with ret(%d)\n",
342365 __FUNCTION__, ring_id, ret));
....@@ -345,11 +368,72 @@
345368 return ret;
346369 }
347370
371
+#ifdef DBG_PKT_MON
372
+int
373
+dhd_os_dbg_attach_pkt_monitor(dhd_pub_t *dhdp)
374
+{
375
+ return dhd_dbg_attach_pkt_monitor(dhdp, dhd_os_dbg_monitor_tx_pkts,
376
+ dhd_os_dbg_monitor_tx_status, dhd_os_dbg_monitor_rx_pkts);
377
+}
378
+
379
+int
380
+dhd_os_dbg_start_pkt_monitor(dhd_pub_t *dhdp)
381
+{
382
+ return dhd_dbg_start_pkt_monitor(dhdp);
383
+}
384
+
385
+int
386
+dhd_os_dbg_monitor_tx_pkts(dhd_pub_t *dhdp, void *pkt, uint32 pktid)
387
+{
388
+ return dhd_dbg_monitor_tx_pkts(dhdp, pkt, pktid);
389
+}
390
+
391
+int
392
+dhd_os_dbg_monitor_tx_status(dhd_pub_t *dhdp, void *pkt, uint32 pktid,
393
+ uint16 status)
394
+{
395
+ return dhd_dbg_monitor_tx_status(dhdp, pkt, pktid, status);
396
+}
397
+
398
+int
399
+dhd_os_dbg_monitor_rx_pkts(dhd_pub_t *dhdp, void *pkt)
400
+{
401
+ return dhd_dbg_monitor_rx_pkts(dhdp, pkt);
402
+}
403
+
404
+int
405
+dhd_os_dbg_stop_pkt_monitor(dhd_pub_t *dhdp)
406
+{
407
+ return dhd_dbg_stop_pkt_monitor(dhdp);
408
+}
409
+
410
+int
411
+dhd_os_dbg_monitor_get_tx_pkts(dhd_pub_t *dhdp, void __user *user_buf,
412
+ uint16 req_count, uint16 *resp_count)
413
+{
414
+ return dhd_dbg_monitor_get_tx_pkts(dhdp, user_buf, req_count, resp_count);
415
+}
416
+
417
+int
418
+dhd_os_dbg_monitor_get_rx_pkts(dhd_pub_t *dhdp, void __user *user_buf,
419
+ uint16 req_count, uint16 *resp_count)
420
+{
421
+ return dhd_dbg_monitor_get_rx_pkts(dhdp, user_buf, req_count, resp_count);
422
+}
423
+
424
+int
425
+dhd_os_dbg_detach_pkt_monitor(dhd_pub_t *dhdp)
426
+{
427
+ return dhd_dbg_detach_pkt_monitor(dhdp);
428
+}
429
+#endif /* DBG_PKT_MON */
430
+
348431 int
349432 dhd_os_dbg_get_feature(dhd_pub_t *dhdp, int32 *features)
350433 {
351434 int ret = BCME_OK;
352435 *features = 0;
436
+#ifdef DEBUGABILITY
353437 *features |= DBG_MEMORY_DUMP_SUPPORTED;
354438 if (FW_SUPPORTED(dhdp, logtrace)) {
355439 *features |= DBG_CONNECT_EVENT_SUPPORTED;
....@@ -358,6 +442,12 @@
358442 if (FW_SUPPORTED(dhdp, hchk)) {
359443 *features |= DBG_HEALTH_CHECK_SUPPORTED;
360444 }
445
+#ifdef DBG_PKT_MON
446
+ if (FW_SUPPORTED(dhdp, d11status)) {
447
+ *features |= DBG_PACKET_FATE_SUPPORTED;
448
+ }
449
+#endif /* DBG_PKT_MON */
450
+#endif /* DEBUGABILITY */
361451 return ret;
362452 }
363453
....@@ -367,8 +457,8 @@
367457 linux_dbgring_info_t *ring_info;
368458
369459 ring_info = &((linux_dbgring_info_t *)os_priv)[ring_id];
370
- if (ring_info->interval != 0)
371
- schedule_delayed_work(&ring_info->work, 0);
460
+ cancel_delayed_work(&ring_info->work);
461
+ schedule_delayed_work(&ring_info->work, 0);
372462 }
373463
374464 int
....@@ -405,6 +495,8 @@
405495 int ring_id;
406496 /* free os_dbg data */
407497 os_priv = dhd_dbg_get_priv(dhdp);
498
+ if (!os_priv)
499
+ return;
408500 /* abort pending any job */
409501 for (ring_id = DEBUG_RING_ID_INVALID + 1; ring_id < DEBUG_RING_ID_MAX; ring_id++) {
410502 ring_info = &os_priv[ring_id];