1// SPDX-License-Identifier: BSD-3-Clause-Clear
2/*
3 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
5 */
6
7#include "core.h"
8#include "debugfs.h"
9
10static ssize_t ath12k_write_simulate_radar(struct file *file,
11					   const char __user *user_buf,
12					   size_t count, loff_t *ppos)
13{
14	struct ath12k *ar = file->private_data;
15	int ret;
16
17	mutex_lock(&ar->conf_mutex);
18	ret = ath12k_wmi_simulate_radar(ar);
19	if (ret)
20		goto exit;
21
22	ret = count;
23exit:
24	mutex_unlock(&ar->conf_mutex);
25	return ret;
26}
27
28static const struct file_operations fops_simulate_radar = {
29	.write = ath12k_write_simulate_radar,
30	.open = simple_open
31};
32
33void ath12k_debugfs_soc_create(struct ath12k_base *ab)
34{
35	bool dput_needed;
36	char soc_name[64] = { 0 };
37	struct dentry *debugfs_ath12k;
38
39	debugfs_ath12k = debugfs_lookup("ath12k", NULL);
40	if (debugfs_ath12k) {
41		/* a dentry from lookup() needs dput() after we don't use it */
42		dput_needed = true;
43	} else {
44		debugfs_ath12k = debugfs_create_dir("ath12k", NULL);
45		if (IS_ERR_OR_NULL(debugfs_ath12k))
46			return;
47		dput_needed = false;
48	}
49
50	scnprintf(soc_name, sizeof(soc_name), "%s-%s", ath12k_bus_str(ab->hif.bus),
51		  dev_name(ab->dev));
52
53	ab->debugfs_soc = debugfs_create_dir(soc_name, debugfs_ath12k);
54
55	if (dput_needed)
56		dput(debugfs_ath12k);
57}
58
59void ath12k_debugfs_soc_destroy(struct ath12k_base *ab)
60{
61	debugfs_remove_recursive(ab->debugfs_soc);
62	ab->debugfs_soc = NULL;
63	/* We are not removing ath12k directory on purpose, even if it
64	 * would be empty. This simplifies the directory handling and it's
65	 * a minor cosmetic issue to leave an empty ath12k directory to
66	 * debugfs.
67	 */
68}
69
70void ath12k_debugfs_register(struct ath12k *ar)
71{
72	struct ath12k_base *ab = ar->ab;
73	struct ieee80211_hw *hw = ar->ah->hw;
74	char pdev_name[5];
75	char buf[100] = {0};
76
77	scnprintf(pdev_name, sizeof(pdev_name), "%s%d", "mac", ar->pdev_idx);
78
79	ar->debug.debugfs_pdev = debugfs_create_dir(pdev_name, ab->debugfs_soc);
80
81	/* Create a symlink under ieee80211/phy* */
82	scnprintf(buf, sizeof(buf), "../../ath12k/%pd2", ar->debug.debugfs_pdev);
83	debugfs_create_symlink("ath12k", hw->wiphy->debugfsdir, buf);
84
85	if (ar->mac.sbands[NL80211_BAND_5GHZ].channels) {
86		debugfs_create_file("dfs_simulate_radar", 0200,
87				    ar->debug.debugfs_pdev, ar,
88				    &fops_simulate_radar);
89	}
90}
91