summaryrefslogtreecommitdiff
path: root/debugfs.c
blob: e2afa5ecf0bb54aef947553f7518c4bc325194b3 (plain)
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
/*
 * Copyright (C) 2006-2015, Marvell International Ltd.
 *
 * This software file (the "File") is distributed by Marvell International
 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
 * (the "License").  You may use, redistribute and/or modify this File in
 * accordance with the terms and conditions of the License, a copy of which
 * is available by writing to the Free Software Foundation, Inc.
 *
 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
 * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
 * this warranty disclaimer.
 */

/* Description:  This file implements debug fs related functions. */

#include <linux/debugfs.h>

#include "sysadpt.h"
#include "dev.h"
#include "hostcmd.h"
#include "fwcmd.h"
#include "debugfs.h"

#define MWLWIFI_DEBUGFS_ADD_FILE(name) do { \
	if (!debugfs_create_file(#name, 0644, priv->debugfs_phy, \
				 priv, &mwl_debugfs_##name##_fops)) \
		return; \
} while (0)

#define MWLWIFI_DEBUGFS_FILE_OPS(name) \
static const struct file_operations mwl_debugfs_##name##_fops = { \
	.read = mwl_debugfs_##name##_read, \
	.write = mwl_debugfs_##name##_write, \
	.open = simple_open, \
}

#define MWLWIFI_DEBUGFS_FILE_READ_OPS(name) \
static const struct file_operations mwl_debugfs_##name##_fops = { \
	.read = mwl_debugfs_##name##_read, \
	.open = simple_open, \
}

#define MWLWIFI_DEBUGFS_FILE_WRITE_OPS(name) \
static const struct file_operations mwl_debugfs_##name##_fops = { \
	.write = mwl_debugfs_##name##_write, \
	.open = simple_open, \
}

static int dump_data(char *p, u8 *data, int len, char *title)
{
	char *str = p;
	int cur_byte = 0;
	int i;

	str += sprintf(str, "%s\n", title);
	for (cur_byte = 0; cur_byte < len; cur_byte += 8) {
		if ((cur_byte + 8) < len) {
			for (i = 0; i < 8; i++)
				str += sprintf(str, "0x%02x ",
					       *(data + cur_byte + i));
			str += sprintf(str, "\n");
		} else {
			for (i = 0; i < (len - cur_byte); i++)
				str += sprintf(str, "0x%02x ",
					       *(data + cur_byte + i));
			str += sprintf(str, "\n");
			break;
		}
	}

	return (str - p);
}

static ssize_t mwl_debugfs_info_read(struct file *file, char __user *ubuf,
				     size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	unsigned long page = get_zeroed_page(GFP_KERNEL);
	char *p = (char *)page;
	ssize_t ret;

	if (!p)
		return -ENOMEM;

	p += sprintf(p, "\n");
	p += sprintf(p, "driver name: %s\n", MWL_DRV_NAME);
	p += sprintf(p, "chip type: %s\n",
		     (priv->chip_type == MWL8864) ? "88W8864" : "88W8897");
	p += sprintf(p, "hw version: %X\n", priv->hw_data.hw_version);
	p += sprintf(p, "driver version: %s\n", MWL_DRV_VERSION);
	p += sprintf(p, "firmware version: 0x%08x\n",
		     priv->hw_data.fw_release_num);
	p += sprintf(p, "mac address: %pM\n", priv->hw_data.mac_addr);
	p += sprintf(p, "2g: %s\n", priv->disable_2g ? "disable" : "enable");
	p += sprintf(p, "5g: %s\n", priv->disable_5g ? "disable" : "enable");
	p += sprintf(p, "antenna: %d %d\n",
		     (priv->antenna_tx == ANTENNA_TX_4_AUTO) ? 4 : 2,
		     (priv->antenna_rx == ANTENNA_TX_4_AUTO) ? 4 : 2);
	p += sprintf(p, "irq number: %d\n", priv->irq);
	p += sprintf(p, "iobase0: %p\n", priv->iobase0);
	p += sprintf(p, "iobase1: %p\n", priv->iobase1);
	p += sprintf(p, "tx limit: %d\n", priv->txq_limit);
	p += sprintf(p, "rx limit: %d\n", priv->recv_limit);
	p += sprintf(p, "ap macid support: %08x\n",
		     priv->ap_macids_supported);
	p += sprintf(p, "sta macid support: %08x\n",
		     priv->sta_macids_supported);
	p += sprintf(p, "macid used: %08x\n", priv->macids_used);
	p += sprintf(p, "qe trigger number: %d\n", priv->qe_trigger_num);
	p += sprintf(p, "mfg mode: %s\n", priv->mfg_mode ? "true" : "false");
	p += sprintf(p, "\n");

	ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
				      (unsigned long)p - page);
	free_page(page);

	return ret;
}

static ssize_t mwl_debugfs_vif_read(struct file *file, char __user *ubuf,
				    size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	unsigned long page = get_zeroed_page(GFP_KERNEL);
	char *p = (char *)page;
	struct mwl_vif *mwl_vif;
	struct ieee80211_vif *vif;
	char ssid[IEEE80211_MAX_SSID_LEN + 1];
	ssize_t ret;

	if (!p)
		return -ENOMEM;

	p += sprintf(p, "\n");
	spin_lock_bh(&priv->vif_lock);
	list_for_each_entry(mwl_vif, &priv->vif_list, list) {
		vif = container_of((char *)mwl_vif, struct ieee80211_vif,
				   drv_priv[0]);
		p += sprintf(p, "macid: %d\n", mwl_vif->macid);
		switch (vif->type) {
		case NL80211_IFTYPE_AP:
			p += sprintf(p, "type: ap\n");
			memcpy(ssid, vif->bss_conf.ssid,
			       vif->bss_conf.ssid_len);
			ssid[vif->bss_conf.ssid_len] = 0;
			p += sprintf(p, "ssid: %s\n", ssid);
			p += sprintf(p, "mac address: %pM\n", mwl_vif->bssid);
			break;
		case NL80211_IFTYPE_MESH_POINT:
			p += sprintf(p, "type: mesh\n");
			p += sprintf(p, "mac address: %pM\n", mwl_vif->bssid);
			break;
		case NL80211_IFTYPE_STATION:
			p += sprintf(p, "type: sta\n");
			p += sprintf(p, "mac address: %pM\n", mwl_vif->sta_mac);
			break;
		default:
			p += sprintf(p, "type: unknown\n");
			break;
		}
		p += sprintf(p, "hw_crypto_enabled: %s\n",
			     mwl_vif->is_hw_crypto_enabled ? "true" : "false");
		p += sprintf(p, "key idx: %d\n", mwl_vif->keyidx);
		p += sprintf(p, "IV: %08x%04x\n", mwl_vif->iv32, mwl_vif->iv16);
		p += dump_data(p, mwl_vif->beacon_info.ie_wmm_ptr,
			       mwl_vif->beacon_info.ie_wmm_len, "WMM:");
		p += dump_data(p, mwl_vif->beacon_info.ie_rsn_ptr,
			       mwl_vif->beacon_info.ie_rsn_len, "RSN:");
		p += dump_data(p, mwl_vif->beacon_info.ie_rsn48_ptr,
			       mwl_vif->beacon_info.ie_rsn48_len, "RSN48:");
		p += dump_data(p, mwl_vif->beacon_info.ie_ht_ptr,
			       mwl_vif->beacon_info.ie_ht_len, "HT:");
		p += dump_data(p, mwl_vif->beacon_info.ie_vht_ptr,
			       mwl_vif->beacon_info.ie_vht_len, "VHT:");
		p += sprintf(p, "\n");
	}
	spin_unlock_bh(&priv->vif_lock);

	ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
				      (unsigned long)p - page);
	free_page(page);

	return ret;
}

static ssize_t mwl_debugfs_sta_read(struct file *file, char __user *ubuf,
				    size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	unsigned long page = get_zeroed_page(GFP_KERNEL);
	char *p = (char *)page;
	struct mwl_sta *sta_info;
	struct ieee80211_sta *sta;
	ssize_t ret;

	if (!p)
		return -ENOMEM;

	p += sprintf(p, "\n");
	spin_lock_bh(&priv->sta_lock);
	list_for_each_entry(sta_info, &priv->sta_list, list) {
		sta = container_of((char *)sta_info, struct ieee80211_sta,
				   drv_priv[0]);
		p += sprintf(p, "mac address: %pM\n", sta->addr);
		p += sprintf(p, "aid: %u\n", sta->aid);
		p += sprintf(p, "ampdu: %s\n",
			     sta_info->is_ampdu_allowed ? "true" : "false");
		p += sprintf(p, "amsdu: %s\n",
			     sta_info->is_amsdu_allowed ? "true" : "false");
		if (sta_info->is_amsdu_allowed) {
			p += sprintf(p, "amsdu cap: 0x%02x\n",
				     sta_info->amsdu_ctrl.cap);
		}
		p += sprintf(p, "IV: %08x%04x\n",
			     sta_info->iv32, sta_info->iv16);
		p += sprintf(p, "\n");
	}
	spin_unlock_bh(&priv->sta_lock);

	ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
				      (unsigned long)p - page);
	free_page(page);

	return ret;
}

static ssize_t mwl_debugfs_ampdu_read(struct file *file, char __user *ubuf,
				      size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	unsigned long page = get_zeroed_page(GFP_KERNEL);
	char *p = (char *)page;
	struct mwl_ampdu_stream *stream;
	int i;
	ssize_t ret;

	if (!p)
		return -ENOMEM;

	p += sprintf(p, "\n");
	spin_lock_bh(&priv->stream_lock);
	for (i = 0; i < SYSADPT_TX_AMPDU_QUEUES; i++) {
		stream = &priv->ampdu[i];
		p += sprintf(p, "stream: %d\n", i);
		p += sprintf(p, "idx: %u\n", stream->idx);
		p += sprintf(p, "state: %u\n", stream->state);
		if (stream->sta) {
			p += sprintf(p, "mac address: %pM\n",
				     stream->sta->addr);
			p += sprintf(p, "tid: %u\n", stream->tid);
		}
	}
	spin_unlock_bh(&priv->stream_lock);
	p += sprintf(p, "\n");

	ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
				      (unsigned long)p - page);
	free_page(page);

	return ret;
}

static ssize_t mwl_debugfs_dfs_channel_read(struct file *file,
					    char __user *ubuf,
					    size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	unsigned long page = get_zeroed_page(GFP_KERNEL);
	char *p = (char *)page;
	struct ieee80211_supported_band *sband;
	struct ieee80211_channel*channel;
	int i;
	ssize_t ret;

	if (!p)
		return -ENOMEM;

	sband = priv->hw->wiphy->bands[NL80211_BAND_5GHZ];
	if (!sband)
		return -EINVAL;

	p += sprintf(p, "\n");
	for (i = 0; i < sband->n_channels; i++) {
		channel = &sband->channels[i];
		if (channel->flags & IEEE80211_CHAN_RADAR) {
			p += sprintf(p, "%d(%d): flags: %08x dfs_state: %d\n",
				     channel->hw_value, channel->center_freq,
				     channel->flags, channel->dfs_state);
			p += sprintf(p, "cac timer: %d ms\n", channel->dfs_cac_ms);
		}
	}
	p += sprintf(p, "\n");

	ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
				      (unsigned long)p - page);
	free_page(page);

	return ret;
}

static ssize_t mwl_debugfs_dfs_channel_write(struct file *file,
					     const char __user *ubuf,
					     size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	struct ieee80211_supported_band *sband;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;
	size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
	int dfs_state = 0;
	int cac_time = -1;
	struct ieee80211_channel*channel;
	int i;
	ssize_t ret = count;

	if (!buf)
		return -ENOMEM;

	sband = priv->hw->wiphy->bands[NL80211_BAND_5GHZ];
	if (!sband) {
		ret = -EINVAL;
		goto done;
	}

	if (copy_from_user(buf, ubuf, buf_size)) {
		ret = -EFAULT;
		goto done;
	}

	sscanf(buf, "%d %d", &dfs_state, &cac_time);

	for (i = 0; i < sband->n_channels; i++) {
		channel = &sband->channels[i];
		if (channel->flags & IEEE80211_CHAN_RADAR) {
			channel->dfs_state = dfs_state;
			if (cac_time != -1)
				channel->dfs_cac_ms = cac_time * 1000;
		}
	}

done:
	free_page(addr);
	return ret;
}

static ssize_t mwl_debugfs_dfs_radar_read(struct file *file, char __user *ubuf,
					  size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	unsigned long page = get_zeroed_page(GFP_KERNEL);
	char *p = (char *)page;
	ssize_t ret;

	if (!p)
		return -ENOMEM;

	p += sprintf(p, "\n");
	p += sprintf(p, "csa_active: %d\n", priv->csa_active);
	p += sprintf(p, "dfs_region: %d\n", priv->dfs_region);
	p += sprintf(p, "chirp_count_min: %d\n", priv->dfs_chirp_count_min);
	p += sprintf(p, "chirp_time_interval: %d\n",
		     priv->dfs_chirp_time_interval);
	p += sprintf(p, "pw_filter: %d\n", priv->dfs_pw_filter);
	p += sprintf(p, "min_num_radar: %d\n", priv->dfs_min_num_radar);
	p += sprintf(p, "min_pri_count: %d\n", priv->dfs_min_pri_count);
	p += sprintf(p, "\n");

	ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
				      (unsigned long)p - page);
	free_page(page);

	return ret;
}

static ssize_t mwl_debugfs_dfs_radar_write(struct file *file,
					   const char __user *ubuf,
					   size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;

	wiphy_info(priv->hw->wiphy, "simulate radar detected\n");
	ieee80211_radar_detected(priv->hw);

	return count;
}

static int mwl_debugfs_reg_access(struct mwl_priv *priv, bool write)
{
	struct ieee80211_hw *hw = priv->hw;
	u8 set;
	u32 *addr_val;
	int ret = 0;

	set = write ? WL_SET : WL_GET;

	switch (priv->reg_type) {
	case MWL_ACCESS_ADDR0:
		if (set == WL_GET)
			priv->reg_value =
				readl(priv->iobase0 + priv->reg_offset);
		else
			writel(priv->reg_value,
			       priv->iobase0 + priv->reg_offset);
		break;
	case MWL_ACCESS_ADDR1:
		if (set == WL_GET)
			priv->reg_value =
				readl(priv->iobase1 + priv->reg_offset);
		else
			writel(priv->reg_value,
			       priv->iobase1 + priv->reg_offset);
		break;
	case MWL_ACCESS_ADDR:
		addr_val = kmalloc(64 * sizeof(u32), GFP_KERNEL);
		if (addr_val) {
			memset(addr_val, 0, 64 * sizeof(u32));
			addr_val[0] = priv->reg_value;
			ret = mwl_fwcmd_get_addr_value(hw, priv->reg_offset,
						       4, addr_val, set);
			if ((!ret) && (set == WL_GET))
				priv->reg_value = addr_val[0];
			kfree(addr_val);
		} else {
			ret = -ENOMEM;
		}
		break;
	default:
		ret = -EINVAL;
		break;
	}

	return ret;
}

static ssize_t mwl_debugfs_regrdwr_read(struct file *file, char __user *ubuf,
					size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;
	int pos = 0, ret = 0;

	if (!buf)
		return -ENOMEM;

	if (!priv->reg_type) {
		/* No command has been given */
		pos += snprintf(buf, PAGE_SIZE, "0");
		goto none;
	}

	/* Set command has been given */
	if (priv->reg_value != UINT_MAX) {
		ret = mwl_debugfs_reg_access(priv, true);
		goto done;
	}
	/* Get command has been given */
	ret = mwl_debugfs_reg_access(priv, false);

done:
	if (!ret)
		pos += snprintf(buf, PAGE_SIZE, "%u 0x%08x 0x%08x\n",
				priv->reg_type, priv->reg_offset,
				priv->reg_value);
	else
		pos += snprintf(buf, PAGE_SIZE, "error: %d(%u 0x%08x 0x%08x)\n",
				ret, priv->reg_type, priv->reg_offset,
				priv->reg_value);

	ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);

none:

	free_page(addr);
	return ret;
}

static ssize_t mwl_debugfs_regrdwr_write(struct file *file,
					 const char __user *ubuf,
					 size_t count, loff_t *ppos)
{
	struct mwl_priv *priv = (struct mwl_priv *)file->private_data;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;
	size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
	int ret;
	u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;

	if (!buf)
		return -ENOMEM;

	if (copy_from_user(buf, ubuf, buf_size)) {
		ret = -EFAULT;
		goto done;
	}

	ret = sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);

	if (!reg_type) {
		ret = -EINVAL;
		goto done;
	} else {
		priv->reg_type = reg_type;
		priv->reg_offset = reg_offset;
		priv->reg_value = reg_value;
		ret = count;
	}
done:

	free_page(addr);
	return ret;
}

MWLWIFI_DEBUGFS_FILE_READ_OPS(info);
MWLWIFI_DEBUGFS_FILE_READ_OPS(vif);
MWLWIFI_DEBUGFS_FILE_READ_OPS(sta);
MWLWIFI_DEBUGFS_FILE_READ_OPS(ampdu);
MWLWIFI_DEBUGFS_FILE_OPS(dfs_channel);
MWLWIFI_DEBUGFS_FILE_OPS(dfs_radar);
MWLWIFI_DEBUGFS_FILE_OPS(regrdwr);

void mwl_debugfs_init(struct ieee80211_hw *hw)
{
	struct mwl_priv *priv = hw->priv;

	if (!priv->debugfs_phy)
		priv->debugfs_phy = debugfs_create_dir("mwlwifi",
						       hw->wiphy->debugfsdir);

	if (!priv->debugfs_phy)
		return;

	MWLWIFI_DEBUGFS_ADD_FILE(info);
	MWLWIFI_DEBUGFS_ADD_FILE(vif);
	MWLWIFI_DEBUGFS_ADD_FILE(sta);
	MWLWIFI_DEBUGFS_ADD_FILE(ampdu);
	MWLWIFI_DEBUGFS_ADD_FILE(dfs_channel);
	MWLWIFI_DEBUGFS_ADD_FILE(dfs_radar);
	MWLWIFI_DEBUGFS_ADD_FILE(regrdwr);
}

void mwl_debugfs_remove(struct ieee80211_hw *hw)
{
	struct mwl_priv *priv = hw->priv;

	debugfs_remove(priv->debugfs_phy);
	priv->debugfs_phy = NULL;
}