1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
// SPDX-License-Identifier: BSD-3-Clause-Clear
/*
* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
* Copyright (c) 2021-2025 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#include "core.h"
#include "debug.h"
#include "debugfs.h"
#include "debugfs_htt_stats.h"
static ssize_t ath12k_write_simulate_radar(struct file *file,
const char __user *user_buf,
size_t count, loff_t *ppos)
{
struct ath12k *ar = file->private_data;
int ret;
wiphy_lock(ath12k_ar_to_hw(ar)->wiphy);
ret = ath12k_wmi_simulate_radar(ar);
if (ret)
goto exit;
ret = count;
exit:
wiphy_unlock(ath12k_ar_to_hw(ar)->wiphy);
return ret;
}
static const struct file_operations fops_simulate_radar = {
.write = ath12k_write_simulate_radar,
.open = simple_open
};
static int ath12k_debug_tpc_stats_request(struct ath12k *ar)
{
enum wmi_halphy_ctrl_path_stats_id tpc_stats_sub_id;
struct ath12k_base *ab = ar->ab;
int ret;
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
reinit_completion(&ar->debug.tpc_complete);
spin_lock_bh(&ar->data_lock);
ar->debug.tpc_request = true;
tpc_stats_sub_id = ar->debug.tpc_stats_type;
spin_unlock_bh(&ar->data_lock);
ret = ath12k_wmi_send_tpc_stats_request(ar, tpc_stats_sub_id);
if (ret) {
ath12k_warn(ab, "failed to request pdev tpc stats: %d\n", ret);
spin_lock_bh(&ar->data_lock);
ar->debug.tpc_request = false;
spin_unlock_bh(&ar->data_lock);
return ret;
}
return 0;
}
static int ath12k_open_tpc_stats(struct inode *inode, struct file *file)
{
struct ath12k *ar = inode->i_private;
struct ath12k_hw *ah = ath12k_ar_to_ah(ar);
int ret;
guard(wiphy)(ath12k_ar_to_hw(ar)->wiphy);
if (ah->state != ATH12K_HW_STATE_ON) {
ath12k_warn(ar->ab, "Interface not up\n");
return -ENETDOWN;
}
void *buf __free(kfree) = kzalloc(ATH12K_TPC_STATS_BUF_SIZE, GFP_KERNEL);
if (!buf)
return -ENOMEM;
ret = ath12k_debug_tpc_stats_request(ar);
if (ret) {
ath12k_warn(ar->ab, "failed to request tpc stats: %d\n",
ret);
return ret;
}
if (!wait_for_completion_timeout(&ar->debug.tpc_complete, TPC_STATS_WAIT_TIME)) {
spin_lock_bh(&ar->data_lock);
ath12k_wmi_free_tpc_stats_mem(ar);
ar->debug.tpc_request = false;
spin_unlock_bh(&ar->data_lock);
return -ETIMEDOUT;
}
file->private_data = no_free_ptr(buf);
spin_lock_bh(&ar->data_lock);
ath12k_wmi_free_tpc_stats_mem(ar);
spin_unlock_bh(&ar->data_lock);
return 0;
}
static ssize_t ath12k_read_tpc_stats(struct file *file,
char __user *user_buf,
size_t count, loff_t *ppos)
{
const char *buf = file->private_data;
size_t len = strlen(buf);
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}
static int ath12k_release_tpc_stats(struct inode *inode,
struct file *file)
{
kfree(file->private_data);
return 0;
}
static const struct file_operations fops_tpc_stats = {
.open = ath12k_open_tpc_stats,
.release = ath12k_release_tpc_stats,
.read = ath12k_read_tpc_stats,
.owner = THIS_MODULE,
.llseek = default_llseek,
};
void ath12k_debugfs_soc_create(struct ath12k_base *ab)
{
bool dput_needed;
char soc_name[64] = { 0 };
struct dentry *debugfs_ath12k;
debugfs_ath12k = debugfs_lookup("ath12k", NULL);
if (debugfs_ath12k) {
/* a dentry from lookup() needs dput() after we don't use it */
dput_needed = true;
} else {
debugfs_ath12k = debugfs_create_dir("ath12k", NULL);
if (IS_ERR_OR_NULL(debugfs_ath12k))
return;
dput_needed = false;
}
scnprintf(soc_name, sizeof(soc_name), "%s-%s", ath12k_bus_str(ab->hif.bus),
dev_name(ab->dev));
ab->debugfs_soc = debugfs_create_dir(soc_name, debugfs_ath12k);
if (dput_needed)
dput(debugfs_ath12k);
}
void ath12k_debugfs_soc_destroy(struct ath12k_base *ab)
{
debugfs_remove_recursive(ab->debugfs_soc);
ab->debugfs_soc = NULL;
/* We are not removing ath12k directory on purpose, even if it
* would be empty. This simplifies the directory handling and it's
* a minor cosmetic issue to leave an empty ath12k directory to
* debugfs.
*/
}
static void ath12k_fw_stats_pdevs_free(struct list_head *head)
{
struct ath12k_fw_stats_pdev *i, *tmp;
list_for_each_entry_safe(i, tmp, head, list) {
list_del(&i->list);
kfree(i);
}
}
static void ath12k_fw_stats_bcn_free(struct list_head *head)
{
struct ath12k_fw_stats_bcn *i, *tmp;
list_for_each_entry_safe(i, tmp, head, list) {
list_del(&i->list);
kfree(i);
}
}
static void ath12k_fw_stats_vdevs_free(struct list_head *head)
{
struct ath12k_fw_stats_vdev *i, *tmp;
list_for_each_entry_safe(i, tmp, head, list) {
list_del(&i->list);
kfree(i);
}
}
void ath12k_debugfs_fw_stats_reset(struct ath12k *ar)
{
spin_lock_bh(&ar->data_lock);
ar->fw_stats.fw_stats_done = false;
ath12k_fw_stats_vdevs_free(&ar->fw_stats.vdevs);
ath12k_fw_stats_bcn_free(&ar->fw_stats.bcn);
ath12k_fw_stats_pdevs_free(&ar->fw_stats.pdevs);
spin_unlock_bh(&ar->data_lock);
}
static int ath12k_debugfs_fw_stats_request(struct ath12k *ar,
struct ath12k_fw_stats_req_params *param)
{
struct ath12k_base *ab = ar->ab;
unsigned long timeout, time_left;
int ret;
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
/* FW stats can get split when exceeding the stats data buffer limit.
* In that case, since there is no end marking for the back-to-back
* received 'update stats' event, we keep a 3 seconds timeout in case,
* fw_stats_done is not marked yet
*/
timeout = jiffies + msecs_to_jiffies(3 * 1000);
ath12k_debugfs_fw_stats_reset(ar);
reinit_completion(&ar->fw_stats_complete);
ret = ath12k_wmi_send_stats_request_cmd(ar, param->stats_id,
param->vdev_id, param->pdev_id);
if (ret) {
ath12k_warn(ab, "could not request fw stats (%d)\n",
ret);
return ret;
}
time_left = wait_for_completion_timeout(&ar->fw_stats_complete,
1 * HZ);
/* If the wait timed out, return -ETIMEDOUT */
if (!time_left)
return -ETIMEDOUT;
/* Firmware sends WMI_UPDATE_STATS_EVENTID back-to-back
* when stats data buffer limit is reached. fw_stats_complete
* is completed once host receives first event from firmware, but
* still end might not be marked in the TLV.
* Below loop is to confirm that firmware completed sending all the event
* and fw_stats_done is marked true when end is marked in the TLV
*/
for (;;) {
if (time_after(jiffies, timeout))
break;
spin_lock_bh(&ar->data_lock);
if (ar->fw_stats.fw_stats_done) {
spin_unlock_bh(&ar->data_lock);
break;
}
spin_unlock_bh(&ar->data_lock);
}
return 0;
}
void
ath12k_debugfs_fw_stats_process(struct ath12k *ar,
struct ath12k_fw_stats *stats)
{
struct ath12k_base *ab = ar->ab;
struct ath12k_pdev *pdev;
bool is_end;
static unsigned int num_vdev, num_bcn;
size_t total_vdevs_started = 0;
int i;
if (stats->stats_id == WMI_REQUEST_VDEV_STAT) {
if (list_empty(&stats->vdevs)) {
ath12k_warn(ab, "empty vdev stats");
return;
}
/* FW sends all the active VDEV stats irrespective of PDEV,
* hence limit until the count of all VDEVs started
*/
rcu_read_lock();
for (i = 0; i < ab->num_radios; i++) {
pdev = rcu_dereference(ab->pdevs_active[i]);
if (pdev && pdev->ar)
total_vdevs_started += pdev->ar->num_started_vdevs;
}
rcu_read_unlock();
is_end = ((++num_vdev) == total_vdevs_started);
list_splice_tail_init(&stats->vdevs,
&ar->fw_stats.vdevs);
if (is_end) {
ar->fw_stats.fw_stats_done = true;
num_vdev = 0;
}
return;
}
if (stats->stats_id == WMI_REQUEST_BCN_STAT) {
if (list_empty(&stats->bcn)) {
ath12k_warn(ab, "empty beacon stats");
return;
}
/* Mark end until we reached the count of all started VDEVs
* within the PDEV
*/
is_end = ((++num_bcn) == ar->num_started_vdevs);
list_splice_tail_init(&stats->bcn,
&ar->fw_stats.bcn);
if (is_end) {
ar->fw_stats.fw_stats_done = true;
num_bcn = 0;
}
}
if (stats->stats_id == WMI_REQUEST_PDEV_STAT) {
list_splice_tail_init(&stats->pdevs, &ar->fw_stats.pdevs);
ar->fw_stats.fw_stats_done = true;
}
}
static int ath12k_open_vdev_stats(struct inode *inode, struct file *file)
{
struct ath12k *ar = inode->i_private;
struct ath12k_fw_stats_req_params param;
struct ath12k_hw *ah = ath12k_ar_to_ah(ar);
int ret;
guard(wiphy)(ath12k_ar_to_hw(ar)->wiphy);
if (!ah)
return -ENETDOWN;
if (ah->state != ATH12K_HW_STATE_ON)
return -ENETDOWN;
void *buf __free(kfree) = kzalloc(ATH12K_FW_STATS_BUF_SIZE, GFP_ATOMIC);
if (!buf)
return -ENOMEM;
param.pdev_id = ath12k_mac_get_target_pdev_id(ar);
/* VDEV stats is always sent for all active VDEVs from FW */
param.vdev_id = 0;
param.stats_id = WMI_REQUEST_VDEV_STAT;
ret = ath12k_debugfs_fw_stats_request(ar, ¶m);
if (ret) {
ath12k_warn(ar->ab, "failed to request fw vdev stats: %d\n", ret);
return ret;
}
ath12k_wmi_fw_stats_dump(ar, &ar->fw_stats, param.stats_id,
buf);
file->private_data = no_free_ptr(buf);
return 0;
}
static int ath12k_release_vdev_stats(struct inode *inode, struct file *file)
{
kfree(file->private_data);
return 0;
}
static ssize_t ath12k_read_vdev_stats(struct file *file,
char __user *user_buf,
size_t count, loff_t *ppos)
{
const char *buf = file->private_data;
size_t len = strlen(buf);
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}
static const struct file_operations fops_vdev_stats = {
.open = ath12k_open_vdev_stats,
.release = ath12k_release_vdev_stats,
.read = ath12k_read_vdev_stats,
.owner = THIS_MODULE,
.llseek = default_llseek,
};
static int ath12k_open_bcn_stats(struct inode *inode, struct file *file)
{
struct ath12k *ar = inode->i_private;
struct ath12k_link_vif *arvif;
struct ath12k_fw_stats_req_params param;
struct ath12k_hw *ah = ath12k_ar_to_ah(ar);
int ret;
guard(wiphy)(ath12k_ar_to_hw(ar)->wiphy);
if (ah && ah->state != ATH12K_HW_STATE_ON)
return -ENETDOWN;
void *buf __free(kfree) = kzalloc(ATH12K_FW_STATS_BUF_SIZE, GFP_ATOMIC);
if (!buf)
return -ENOMEM;
param.pdev_id = ath12k_mac_get_target_pdev_id(ar);
param.stats_id = WMI_REQUEST_BCN_STAT;
/* loop all active VDEVs for bcn stats */
list_for_each_entry(arvif, &ar->arvifs, list) {
if (!arvif->is_up)
continue;
param.vdev_id = arvif->vdev_id;
ret = ath12k_debugfs_fw_stats_request(ar, ¶m);
if (ret) {
ath12k_warn(ar->ab, "failed to request fw bcn stats: %d\n", ret);
return ret;
}
}
ath12k_wmi_fw_stats_dump(ar, &ar->fw_stats, param.stats_id,
buf);
/* since beacon stats request is looped for all active VDEVs, saved fw
* stats is not freed for each request until done for all active VDEVs
*/
spin_lock_bh(&ar->data_lock);
ath12k_fw_stats_bcn_free(&ar->fw_stats.bcn);
spin_unlock_bh(&ar->data_lock);
file->private_data = no_free_ptr(buf);
return 0;
}
static int ath12k_release_bcn_stats(struct inode *inode, struct file *file)
{
kfree(file->private_data);
return 0;
}
static ssize_t ath12k_read_bcn_stats(struct file *file,
char __user *user_buf,
size_t count, loff_t *ppos)
{
const char *buf = file->private_data;
size_t len = strlen(buf);
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}
static const struct file_operations fops_bcn_stats = {
.open = ath12k_open_bcn_stats,
.release = ath12k_release_bcn_stats,
.read = ath12k_read_bcn_stats,
.owner = THIS_MODULE,
.llseek = default_llseek,
};
static int ath12k_open_pdev_stats(struct inode *inode, struct file *file)
{
struct ath12k *ar = inode->i_private;
struct ath12k_hw *ah = ath12k_ar_to_ah(ar);
struct ath12k_base *ab = ar->ab;
struct ath12k_fw_stats_req_params param;
int ret;
guard(wiphy)(ath12k_ar_to_hw(ar)->wiphy);
if (ah && ah->state != ATH12K_HW_STATE_ON)
return -ENETDOWN;
void *buf __free(kfree) = kzalloc(ATH12K_FW_STATS_BUF_SIZE, GFP_ATOMIC);
if (!buf)
return -ENOMEM;
param.pdev_id = ath12k_mac_get_target_pdev_id(ar);
param.vdev_id = 0;
param.stats_id = WMI_REQUEST_PDEV_STAT;
ret = ath12k_debugfs_fw_stats_request(ar, ¶m);
if (ret) {
ath12k_warn(ab, "failed to request fw pdev stats: %d\n", ret);
return ret;
}
ath12k_wmi_fw_stats_dump(ar, &ar->fw_stats, param.stats_id,
buf);
file->private_data = no_free_ptr(buf);
return 0;
}
static int ath12k_release_pdev_stats(struct inode *inode, struct file *file)
{
kfree(file->private_data);
return 0;
}
static ssize_t ath12k_read_pdev_stats(struct file *file,
char __user *user_buf,
size_t count, loff_t *ppos)
{
const char *buf = file->private_data;
size_t len = strlen(buf);
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
}
static const struct file_operations fops_pdev_stats = {
.open = ath12k_open_pdev_stats,
.release = ath12k_release_pdev_stats,
.read = ath12k_read_pdev_stats,
.owner = THIS_MODULE,
.llseek = default_llseek,
};
static
void ath12k_debugfs_fw_stats_register(struct ath12k *ar)
{
struct dentry *fwstats_dir = debugfs_create_dir("fw_stats",
ar->debug.debugfs_pdev);
/* all stats debugfs files created are under "fw_stats" directory
* created per PDEV
*/
debugfs_create_file("vdev_stats", 0600, fwstats_dir, ar,
&fops_vdev_stats);
debugfs_create_file("beacon_stats", 0600, fwstats_dir, ar,
&fops_bcn_stats);
debugfs_create_file("pdev_stats", 0600, fwstats_dir, ar,
&fops_pdev_stats);
INIT_LIST_HEAD(&ar->fw_stats.vdevs);
INIT_LIST_HEAD(&ar->fw_stats.bcn);
INIT_LIST_HEAD(&ar->fw_stats.pdevs);
init_completion(&ar->fw_stats_complete);
}
void ath12k_debugfs_register(struct ath12k *ar)
{
struct ath12k_base *ab = ar->ab;
struct ieee80211_hw *hw = ar->ah->hw;
char pdev_name[5];
char buf[100] = {0};
scnprintf(pdev_name, sizeof(pdev_name), "%s%d", "mac", ar->pdev_idx);
ar->debug.debugfs_pdev = debugfs_create_dir(pdev_name, ab->debugfs_soc);
/* Create a symlink under ieee80211/phy* */
scnprintf(buf, sizeof(buf), "../../ath12k/%pd2", ar->debug.debugfs_pdev);
ar->debug.debugfs_pdev_symlink = debugfs_create_symlink("ath12k",
hw->wiphy->debugfsdir,
buf);
if (ar->mac.sbands[NL80211_BAND_5GHZ].channels) {
debugfs_create_file("dfs_simulate_radar", 0200,
ar->debug.debugfs_pdev, ar,
&fops_simulate_radar);
}
debugfs_create_file("tpc_stats", 0400, ar->debug.debugfs_pdev, ar,
&fops_tpc_stats);
ath12k_debugfs_htt_stats_register(ar);
ath12k_debugfs_fw_stats_register(ar);
}
void ath12k_debugfs_unregister(struct ath12k *ar)
{
if (!ar->debug.debugfs_pdev)
return;
/* Remove symlink under ieee80211/phy* */
debugfs_remove(ar->debug.debugfs_pdev_symlink);
debugfs_remove_recursive(ar->debug.debugfs_pdev);
ar->debug.debugfs_pdev_symlink = NULL;
ar->debug.debugfs_pdev = NULL;
}
|