Commit | Line | Data |
---|---|---|
712b6cf5 TW |
1 | /****************************************************************************** |
2 | * | |
3 | * GPL LICENSE SUMMARY | |
4 | * | |
1f447808 | 5 | * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved. |
712b6cf5 TW |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of version 2 of the GNU General Public License as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
19 | * USA | |
20 | * | |
21 | * The full GNU General Public License is included in this distribution | |
22 | * in the file called LICENSE.GPL. | |
23 | * | |
24 | * Contact Information: | |
759ef89f | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
712b6cf5 TW |
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
27 | *****************************************************************************/ | |
28 | ||
5a0e3ad6 | 29 | #include <linux/slab.h> |
712b6cf5 TW |
30 | #include <linux/kernel.h> |
31 | #include <linux/module.h> | |
32 | #include <linux/debugfs.h> | |
33 | ||
34 | #include <linux/ieee80211.h> | |
35 | #include <net/mac80211.h> | |
36 | ||
37 | ||
3e0d4cb1 | 38 | #include "iwl-dev.h" |
712b6cf5 | 39 | #include "iwl-debug.h" |
fee1247a | 40 | #include "iwl-core.h" |
3395f6e9 | 41 | #include "iwl-io.h" |
5225935b | 42 | #include "iwl-calib.h" |
712b6cf5 TW |
43 | |
44 | /* create and remove of files */ | |
4c84a8f1 JB |
45 | #define DEBUGFS_ADD_FILE(name, parent, mode) do { \ |
46 | if (!debugfs_create_file(#name, mode, parent, priv, \ | |
47 | &iwl_dbgfs_##name##_ops)) \ | |
48 | goto err; \ | |
712b6cf5 TW |
49 | } while (0) |
50 | ||
4c84a8f1 JB |
51 | #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \ |
52 | struct dentry *__tmp; \ | |
53 | __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \ | |
54 | parent, ptr); \ | |
55 | if (IS_ERR(__tmp) || !__tmp) \ | |
56 | goto err; \ | |
712b6cf5 TW |
57 | } while (0) |
58 | ||
4c84a8f1 JB |
59 | #define DEBUGFS_ADD_X32(name, parent, ptr) do { \ |
60 | struct dentry *__tmp; \ | |
61 | __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \ | |
62 | parent, ptr); \ | |
63 | if (IS_ERR(__tmp) || !__tmp) \ | |
64 | goto err; \ | |
445c2dff TW |
65 | } while (0) |
66 | ||
712b6cf5 TW |
67 | /* file operation */ |
68 | #define DEBUGFS_READ_FUNC(name) \ | |
69 | static ssize_t iwl_dbgfs_##name##_read(struct file *file, \ | |
70 | char __user *user_buf, \ | |
71 | size_t count, loff_t *ppos); | |
72 | ||
73 | #define DEBUGFS_WRITE_FUNC(name) \ | |
74 | static ssize_t iwl_dbgfs_##name##_write(struct file *file, \ | |
75 | const char __user *user_buf, \ | |
76 | size_t count, loff_t *ppos); | |
77 | ||
78 | ||
79 | static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file) | |
80 | { | |
81 | file->private_data = inode->i_private; | |
82 | return 0; | |
83 | } | |
84 | ||
85 | #define DEBUGFS_READ_FILE_OPS(name) \ | |
86 | DEBUGFS_READ_FUNC(name); \ | |
87 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
88 | .read = iwl_dbgfs_##name##_read, \ | |
89 | .open = iwl_dbgfs_open_file_generic, \ | |
90 | }; | |
91 | ||
189a2b59 EK |
92 | #define DEBUGFS_WRITE_FILE_OPS(name) \ |
93 | DEBUGFS_WRITE_FUNC(name); \ | |
94 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
95 | .write = iwl_dbgfs_##name##_write, \ | |
96 | .open = iwl_dbgfs_open_file_generic, \ | |
97 | }; | |
98 | ||
99 | ||
712b6cf5 TW |
100 | #define DEBUGFS_READ_WRITE_FILE_OPS(name) \ |
101 | DEBUGFS_READ_FUNC(name); \ | |
102 | DEBUGFS_WRITE_FUNC(name); \ | |
103 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
104 | .write = iwl_dbgfs_##name##_write, \ | |
105 | .read = iwl_dbgfs_##name##_read, \ | |
106 | .open = iwl_dbgfs_open_file_generic, \ | |
107 | }; | |
108 | ||
712b6cf5 TW |
109 | static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file, |
110 | char __user *user_buf, | |
111 | size_t count, loff_t *ppos) { | |
112 | ||
28f63a4b | 113 | struct iwl_priv *priv = file->private_data; |
22fdf3c9 | 114 | char *buf; |
712b6cf5 TW |
115 | int pos = 0; |
116 | ||
22fdf3c9 WYG |
117 | int cnt; |
118 | ssize_t ret; | |
98a7b43b WYG |
119 | const size_t bufsz = 100 + |
120 | sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX); | |
22fdf3c9 WYG |
121 | buf = kzalloc(bufsz, GFP_KERNEL); |
122 | if (!buf) | |
123 | return -ENOMEM; | |
124 | pos += scnprintf(buf + pos, bufsz - pos, "Management:\n"); | |
125 | for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) { | |
126 | pos += scnprintf(buf + pos, bufsz - pos, | |
98a7b43b | 127 | "\t%25s\t\t: %u\n", |
22fdf3c9 WYG |
128 | get_mgmt_string(cnt), |
129 | priv->tx_stats.mgmt[cnt]); | |
130 | } | |
131 | pos += scnprintf(buf + pos, bufsz - pos, "Control\n"); | |
132 | for (cnt = 0; cnt < CONTROL_MAX; cnt++) { | |
133 | pos += scnprintf(buf + pos, bufsz - pos, | |
98a7b43b | 134 | "\t%25s\t\t: %u\n", |
22fdf3c9 WYG |
135 | get_ctrl_string(cnt), |
136 | priv->tx_stats.ctrl[cnt]); | |
137 | } | |
138 | pos += scnprintf(buf + pos, bufsz - pos, "Data:\n"); | |
139 | pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n", | |
140 | priv->tx_stats.data_cnt); | |
141 | pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n", | |
142 | priv->tx_stats.data_bytes); | |
143 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
144 | kfree(buf); | |
145 | return ret; | |
146 | } | |
147 | ||
7163b8a4 | 148 | static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file, |
22fdf3c9 WYG |
149 | const char __user *user_buf, |
150 | size_t count, loff_t *ppos) | |
151 | { | |
152 | struct iwl_priv *priv = file->private_data; | |
153 | u32 clear_flag; | |
154 | char buf[8]; | |
155 | int buf_size; | |
712b6cf5 | 156 | |
22fdf3c9 WYG |
157 | memset(buf, 0, sizeof(buf)); |
158 | buf_size = min(count, sizeof(buf) - 1); | |
159 | if (copy_from_user(buf, user_buf, buf_size)) | |
160 | return -EFAULT; | |
161 | if (sscanf(buf, "%x", &clear_flag) != 1) | |
162 | return -EFAULT; | |
7163b8a4 | 163 | iwl_clear_traffic_stats(priv); |
22fdf3c9 WYG |
164 | |
165 | return count; | |
712b6cf5 TW |
166 | } |
167 | ||
168 | static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file, | |
169 | char __user *user_buf, | |
170 | size_t count, loff_t *ppos) { | |
171 | ||
28f63a4b | 172 | struct iwl_priv *priv = file->private_data; |
22fdf3c9 | 173 | char *buf; |
712b6cf5 | 174 | int pos = 0; |
22fdf3c9 WYG |
175 | int cnt; |
176 | ssize_t ret; | |
177 | const size_t bufsz = 100 + | |
98a7b43b | 178 | sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX); |
22fdf3c9 WYG |
179 | buf = kzalloc(bufsz, GFP_KERNEL); |
180 | if (!buf) | |
181 | return -ENOMEM; | |
712b6cf5 | 182 | |
22fdf3c9 WYG |
183 | pos += scnprintf(buf + pos, bufsz - pos, "Management:\n"); |
184 | for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) { | |
185 | pos += scnprintf(buf + pos, bufsz - pos, | |
98a7b43b | 186 | "\t%25s\t\t: %u\n", |
22fdf3c9 WYG |
187 | get_mgmt_string(cnt), |
188 | priv->rx_stats.mgmt[cnt]); | |
189 | } | |
190 | pos += scnprintf(buf + pos, bufsz - pos, "Control:\n"); | |
191 | for (cnt = 0; cnt < CONTROL_MAX; cnt++) { | |
192 | pos += scnprintf(buf + pos, bufsz - pos, | |
98a7b43b | 193 | "\t%25s\t\t: %u\n", |
22fdf3c9 WYG |
194 | get_ctrl_string(cnt), |
195 | priv->rx_stats.ctrl[cnt]); | |
196 | } | |
197 | pos += scnprintf(buf + pos, bufsz - pos, "Data:\n"); | |
198 | pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n", | |
199 | priv->rx_stats.data_cnt); | |
200 | pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n", | |
201 | priv->rx_stats.data_bytes); | |
712b6cf5 | 202 | |
22fdf3c9 WYG |
203 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
204 | kfree(buf); | |
205 | return ret; | |
206 | } | |
207 | ||
712b6cf5 TW |
208 | #define BYTE1_MASK 0x000000ff; |
209 | #define BYTE2_MASK 0x0000ffff; | |
210 | #define BYTE3_MASK 0x00ffffff; | |
211 | static ssize_t iwl_dbgfs_sram_read(struct file *file, | |
212 | char __user *user_buf, | |
213 | size_t count, loff_t *ppos) | |
214 | { | |
215 | u32 val; | |
2943f136 | 216 | char *buf; |
712b6cf5 TW |
217 | ssize_t ret; |
218 | int i; | |
219 | int pos = 0; | |
28f63a4b | 220 | struct iwl_priv *priv = file->private_data; |
2943f136 | 221 | size_t bufsz; |
712b6cf5 | 222 | |
5ade1e4d | 223 | /* default is to dump the entire data segment */ |
4c84a8f1 JB |
224 | if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) { |
225 | priv->dbgfs_sram_offset = 0x800000; | |
5ade1e4d | 226 | if (priv->ucode_type == UCODE_INIT) |
4c84a8f1 | 227 | priv->dbgfs_sram_len = priv->ucode_init_data.len; |
5ade1e4d | 228 | else |
4c84a8f1 | 229 | priv->dbgfs_sram_len = priv->ucode_data.len; |
5ade1e4d | 230 | } |
4c84a8f1 | 231 | bufsz = 30 + priv->dbgfs_sram_len * sizeof(char) * 10; |
2943f136 WYG |
232 | buf = kmalloc(bufsz, GFP_KERNEL); |
233 | if (!buf) | |
234 | return -ENOMEM; | |
5ade1e4d | 235 | pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", |
4c84a8f1 | 236 | priv->dbgfs_sram_len); |
5ade1e4d | 237 | pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", |
4c84a8f1 JB |
238 | priv->dbgfs_sram_offset); |
239 | for (i = priv->dbgfs_sram_len; i > 0; i -= 4) { | |
240 | val = iwl_read_targ_mem(priv, priv->dbgfs_sram_offset + \ | |
241 | priv->dbgfs_sram_len - i); | |
712b6cf5 TW |
242 | if (i < 4) { |
243 | switch (i) { | |
244 | case 1: | |
245 | val &= BYTE1_MASK; | |
246 | break; | |
247 | case 2: | |
248 | val &= BYTE2_MASK; | |
249 | break; | |
250 | case 3: | |
251 | val &= BYTE3_MASK; | |
252 | break; | |
253 | } | |
254 | } | |
2943f136 WYG |
255 | if (!(i % 16)) |
256 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | |
db0589f3 | 257 | pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val); |
712b6cf5 | 258 | } |
db0589f3 | 259 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); |
712b6cf5 TW |
260 | |
261 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
2943f136 | 262 | kfree(buf); |
712b6cf5 TW |
263 | return ret; |
264 | } | |
265 | ||
266 | static ssize_t iwl_dbgfs_sram_write(struct file *file, | |
267 | const char __user *user_buf, | |
268 | size_t count, loff_t *ppos) | |
269 | { | |
270 | struct iwl_priv *priv = file->private_data; | |
271 | char buf[64]; | |
272 | int buf_size; | |
273 | u32 offset, len; | |
274 | ||
275 | memset(buf, 0, sizeof(buf)); | |
276 | buf_size = min(count, sizeof(buf) - 1); | |
277 | if (copy_from_user(buf, user_buf, buf_size)) | |
278 | return -EFAULT; | |
279 | ||
280 | if (sscanf(buf, "%x,%x", &offset, &len) == 2) { | |
4c84a8f1 JB |
281 | priv->dbgfs_sram_offset = offset; |
282 | priv->dbgfs_sram_len = len; | |
712b6cf5 | 283 | } else { |
4c84a8f1 JB |
284 | priv->dbgfs_sram_offset = 0; |
285 | priv->dbgfs_sram_len = 0; | |
712b6cf5 TW |
286 | } |
287 | ||
288 | return count; | |
289 | } | |
290 | ||
291 | static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, | |
292 | size_t count, loff_t *ppos) | |
293 | { | |
28f63a4b | 294 | struct iwl_priv *priv = file->private_data; |
6def9761 | 295 | struct iwl_station_entry *station; |
5425e490 | 296 | int max_sta = priv->hw_params.max_stations; |
712b6cf5 TW |
297 | char *buf; |
298 | int i, j, pos = 0; | |
299 | ssize_t ret; | |
300 | /* Add 30 for initial string */ | |
301 | const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations); | |
712b6cf5 TW |
302 | |
303 | buf = kmalloc(bufsz, GFP_KERNEL); | |
3ac7f146 | 304 | if (!buf) |
712b6cf5 TW |
305 | return -ENOMEM; |
306 | ||
db0589f3 | 307 | pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n", |
712b6cf5 TW |
308 | priv->num_stations); |
309 | ||
310 | for (i = 0; i < max_sta; i++) { | |
311 | station = &priv->stations[i]; | |
da73511d JB |
312 | if (!station->used) |
313 | continue; | |
314 | pos += scnprintf(buf + pos, bufsz - pos, | |
315 | "station %d - addr: %pM, flags: %#x\n", | |
316 | i, station->sta.sta.addr, | |
317 | station->sta.station_flags_msk); | |
318 | pos += scnprintf(buf + pos, bufsz - pos, | |
319 | "TID\tseq_num\ttxq_id\tframes\ttfds\t"); | |
320 | pos += scnprintf(buf + pos, bufsz - pos, | |
321 | "start_idx\tbitmap\t\t\trate_n_flags\n"); | |
712b6cf5 | 322 | |
da73511d JB |
323 | for (j = 0; j < MAX_TID_COUNT; j++) { |
324 | pos += scnprintf(buf + pos, bufsz - pos, | |
325 | "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x", | |
326 | j, station->tid[j].seq_number, | |
327 | station->tid[j].agg.txq_id, | |
328 | station->tid[j].agg.frame_count, | |
329 | station->tid[j].tfds_in_queue, | |
330 | station->tid[j].agg.start_idx, | |
331 | station->tid[j].agg.bitmap, | |
332 | station->tid[j].agg.rate_n_flags); | |
333 | ||
334 | if (station->tid[j].agg.wait_for_ba) | |
db0589f3 | 335 | pos += scnprintf(buf + pos, bufsz - pos, |
da73511d | 336 | " - waitforba"); |
db0589f3 | 337 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); |
712b6cf5 | 338 | } |
da73511d JB |
339 | |
340 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | |
712b6cf5 TW |
341 | } |
342 | ||
343 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
344 | kfree(buf); | |
345 | return ret; | |
346 | } | |
347 | ||
0848e297 | 348 | static ssize_t iwl_dbgfs_nvm_read(struct file *file, |
8dd266ef TW |
349 | char __user *user_buf, |
350 | size_t count, | |
351 | loff_t *ppos) | |
352 | { | |
353 | ssize_t ret; | |
28f63a4b | 354 | struct iwl_priv *priv = file->private_data; |
8dd266ef TW |
355 | int pos = 0, ofs = 0, buf_size = 0; |
356 | const u8 *ptr; | |
357 | char *buf; | |
e307ddce | 358 | u16 eeprom_ver; |
8dd266ef TW |
359 | size_t eeprom_len = priv->cfg->eeprom_size; |
360 | buf_size = 4 * eeprom_len + 256; | |
361 | ||
362 | if (eeprom_len % 16) { | |
0848e297 | 363 | IWL_ERR(priv, "NVM size is not multiple of 16.\n"); |
8dd266ef TW |
364 | return -ENODATA; |
365 | } | |
366 | ||
c37457e6 JL |
367 | ptr = priv->eeprom; |
368 | if (!ptr) { | |
369 | IWL_ERR(priv, "Invalid EEPROM/OTP memory\n"); | |
370 | return -ENOMEM; | |
371 | } | |
372 | ||
8dd266ef TW |
373 | /* 4 characters for byte 0xYY */ |
374 | buf = kzalloc(buf_size, GFP_KERNEL); | |
375 | if (!buf) { | |
15b1687c | 376 | IWL_ERR(priv, "Can not allocate Buffer\n"); |
8dd266ef TW |
377 | return -ENOMEM; |
378 | } | |
e307ddce WYG |
379 | eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION); |
380 | pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, " | |
381 | "version: 0x%x\n", | |
0848e297 | 382 | (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) |
e307ddce | 383 | ? "OTP" : "EEPROM", eeprom_ver); |
8dd266ef TW |
384 | for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) { |
385 | pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs); | |
386 | hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos, | |
387 | buf_size - pos, 0); | |
2fac9717 | 388 | pos += strlen(buf + pos); |
8dd266ef TW |
389 | if (buf_size - pos > 0) |
390 | buf[pos++] = '\n'; | |
391 | } | |
392 | ||
393 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
394 | kfree(buf); | |
395 | return ret; | |
396 | } | |
712b6cf5 | 397 | |
b03d7d0f WYG |
398 | static ssize_t iwl_dbgfs_log_event_read(struct file *file, |
399 | char __user *user_buf, | |
400 | size_t count, loff_t *ppos) | |
401 | { | |
402 | struct iwl_priv *priv = file->private_data; | |
403 | char *buf; | |
404 | int pos = 0; | |
405 | ssize_t ret = -ENOMEM; | |
406 | ||
937c397e WYG |
407 | ret = pos = priv->cfg->ops->lib->dump_nic_event_log( |
408 | priv, true, &buf, true); | |
409 | if (buf) { | |
b03d7d0f WYG |
410 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
411 | kfree(buf); | |
412 | } | |
413 | return ret; | |
414 | } | |
415 | ||
189a2b59 EK |
416 | static ssize_t iwl_dbgfs_log_event_write(struct file *file, |
417 | const char __user *user_buf, | |
418 | size_t count, loff_t *ppos) | |
419 | { | |
420 | struct iwl_priv *priv = file->private_data; | |
421 | u32 event_log_flag; | |
422 | char buf[8]; | |
423 | int buf_size; | |
424 | ||
425 | memset(buf, 0, sizeof(buf)); | |
426 | buf_size = min(count, sizeof(buf) - 1); | |
427 | if (copy_from_user(buf, user_buf, buf_size)) | |
428 | return -EFAULT; | |
429 | if (sscanf(buf, "%d", &event_log_flag) != 1) | |
430 | return -EFAULT; | |
431 | if (event_log_flag == 1) | |
b03d7d0f WYG |
432 | priv->cfg->ops->lib->dump_nic_event_log(priv, true, |
433 | NULL, false); | |
189a2b59 EK |
434 | |
435 | return count; | |
436 | } | |
437 | ||
d366df5a WT |
438 | |
439 | ||
440 | static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf, | |
441 | size_t count, loff_t *ppos) | |
442 | { | |
28f63a4b | 443 | struct iwl_priv *priv = file->private_data; |
d366df5a WT |
444 | struct ieee80211_channel *channels = NULL; |
445 | const struct ieee80211_supported_band *supp_band = NULL; | |
446 | int pos = 0, i, bufsz = PAGE_SIZE; | |
447 | char *buf; | |
448 | ssize_t ret; | |
449 | ||
450 | if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status)) | |
451 | return -EAGAIN; | |
452 | ||
453 | buf = kzalloc(bufsz, GFP_KERNEL); | |
454 | if (!buf) { | |
15b1687c | 455 | IWL_ERR(priv, "Can not allocate Buffer\n"); |
d366df5a WT |
456 | return -ENOMEM; |
457 | } | |
458 | ||
459 | supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ); | |
a2e2322d WYG |
460 | if (supp_band) { |
461 | channels = supp_band->channels; | |
d366df5a | 462 | |
d366df5a | 463 | pos += scnprintf(buf + pos, bufsz - pos, |
a2e2322d WYG |
464 | "Displaying %d channels in 2.4GHz band 802.11bg):\n", |
465 | supp_band->n_channels); | |
d366df5a | 466 | |
a2e2322d WYG |
467 | for (i = 0; i < supp_band->n_channels; i++) |
468 | pos += scnprintf(buf + pos, bufsz - pos, | |
469 | "%d: %ddBm: BSS%s%s, %s.\n", | |
81e95430 | 470 | channels[i].hw_value, |
a2e2322d WYG |
471 | channels[i].max_power, |
472 | channels[i].flags & IEEE80211_CHAN_RADAR ? | |
473 | " (IEEE 802.11h required)" : "", | |
474 | ((channels[i].flags & IEEE80211_CHAN_NO_IBSS) | |
475 | || (channels[i].flags & | |
476 | IEEE80211_CHAN_RADAR)) ? "" : | |
477 | ", IBSS", | |
478 | channels[i].flags & | |
479 | IEEE80211_CHAN_PASSIVE_SCAN ? | |
480 | "passive only" : "active/passive"); | |
481 | } | |
d366df5a | 482 | supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ); |
a2e2322d WYG |
483 | if (supp_band) { |
484 | channels = supp_band->channels; | |
d366df5a | 485 | |
d366df5a | 486 | pos += scnprintf(buf + pos, bufsz - pos, |
a2e2322d WYG |
487 | "Displaying %d channels in 5.2GHz band (802.11a)\n", |
488 | supp_band->n_channels); | |
489 | ||
490 | for (i = 0; i < supp_band->n_channels; i++) | |
491 | pos += scnprintf(buf + pos, bufsz - pos, | |
492 | "%d: %ddBm: BSS%s%s, %s.\n", | |
81e95430 | 493 | channels[i].hw_value, |
a2e2322d WYG |
494 | channels[i].max_power, |
495 | channels[i].flags & IEEE80211_CHAN_RADAR ? | |
496 | " (IEEE 802.11h required)" : "", | |
497 | ((channels[i].flags & IEEE80211_CHAN_NO_IBSS) | |
498 | || (channels[i].flags & | |
499 | IEEE80211_CHAN_RADAR)) ? "" : | |
500 | ", IBSS", | |
501 | channels[i].flags & | |
502 | IEEE80211_CHAN_PASSIVE_SCAN ? | |
503 | "passive only" : "active/passive"); | |
504 | } | |
d366df5a WT |
505 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
506 | kfree(buf); | |
507 | return ret; | |
508 | } | |
509 | ||
08df05aa WYG |
510 | static ssize_t iwl_dbgfs_status_read(struct file *file, |
511 | char __user *user_buf, | |
512 | size_t count, loff_t *ppos) { | |
513 | ||
28f63a4b | 514 | struct iwl_priv *priv = file->private_data; |
08df05aa WYG |
515 | char buf[512]; |
516 | int pos = 0; | |
517 | const size_t bufsz = sizeof(buf); | |
518 | ||
519 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n", | |
520 | test_bit(STATUS_HCMD_ACTIVE, &priv->status)); | |
08df05aa WYG |
521 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n", |
522 | test_bit(STATUS_INT_ENABLED, &priv->status)); | |
523 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n", | |
524 | test_bit(STATUS_RF_KILL_HW, &priv->status)); | |
7812b167 WYG |
525 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n", |
526 | test_bit(STATUS_CT_KILL, &priv->status)); | |
08df05aa WYG |
527 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n", |
528 | test_bit(STATUS_INIT, &priv->status)); | |
529 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n", | |
530 | test_bit(STATUS_ALIVE, &priv->status)); | |
531 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n", | |
532 | test_bit(STATUS_READY, &priv->status)); | |
533 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n", | |
534 | test_bit(STATUS_TEMPERATURE, &priv->status)); | |
535 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n", | |
536 | test_bit(STATUS_GEO_CONFIGURED, &priv->status)); | |
537 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n", | |
538 | test_bit(STATUS_EXIT_PENDING, &priv->status)); | |
08df05aa WYG |
539 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n", |
540 | test_bit(STATUS_STATISTICS, &priv->status)); | |
541 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n", | |
542 | test_bit(STATUS_SCANNING, &priv->status)); | |
543 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n", | |
544 | test_bit(STATUS_SCAN_ABORTING, &priv->status)); | |
545 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n", | |
546 | test_bit(STATUS_SCAN_HW, &priv->status)); | |
547 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n", | |
548 | test_bit(STATUS_POWER_PMI, &priv->status)); | |
549 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n", | |
550 | test_bit(STATUS_FW_ERROR, &priv->status)); | |
08df05aa WYG |
551 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
552 | } | |
553 | ||
a83b9141 WYG |
554 | static ssize_t iwl_dbgfs_interrupt_read(struct file *file, |
555 | char __user *user_buf, | |
556 | size_t count, loff_t *ppos) { | |
557 | ||
28f63a4b | 558 | struct iwl_priv *priv = file->private_data; |
a83b9141 WYG |
559 | int pos = 0; |
560 | int cnt = 0; | |
561 | char *buf; | |
562 | int bufsz = 24 * 64; /* 24 items * 64 char per item */ | |
563 | ssize_t ret; | |
564 | ||
565 | buf = kzalloc(bufsz, GFP_KERNEL); | |
566 | if (!buf) { | |
567 | IWL_ERR(priv, "Can not allocate Buffer\n"); | |
568 | return -ENOMEM; | |
569 | } | |
570 | ||
571 | pos += scnprintf(buf + pos, bufsz - pos, | |
572 | "Interrupt Statistics Report:\n"); | |
573 | ||
574 | pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n", | |
575 | priv->isr_stats.hw); | |
576 | pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n", | |
577 | priv->isr_stats.sw); | |
578 | if (priv->isr_stats.sw > 0) { | |
579 | pos += scnprintf(buf + pos, bufsz - pos, | |
580 | "\tLast Restarting Code: 0x%X\n", | |
581 | priv->isr_stats.sw_err); | |
582 | } | |
583 | #ifdef CONFIG_IWLWIFI_DEBUG | |
584 | pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n", | |
585 | priv->isr_stats.sch); | |
586 | pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n", | |
587 | priv->isr_stats.alive); | |
588 | #endif | |
589 | pos += scnprintf(buf + pos, bufsz - pos, | |
590 | "HW RF KILL switch toggled:\t %u\n", | |
591 | priv->isr_stats.rfkill); | |
592 | ||
593 | pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n", | |
594 | priv->isr_stats.ctkill); | |
595 | ||
596 | pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n", | |
597 | priv->isr_stats.wakeup); | |
598 | ||
599 | pos += scnprintf(buf + pos, bufsz - pos, | |
600 | "Rx command responses:\t\t %u\n", | |
601 | priv->isr_stats.rx); | |
602 | for (cnt = 0; cnt < REPLY_MAX; cnt++) { | |
603 | if (priv->isr_stats.rx_handlers[cnt] > 0) | |
604 | pos += scnprintf(buf + pos, bufsz - pos, | |
605 | "\tRx handler[%36s]:\t\t %u\n", | |
606 | get_cmd_string(cnt), | |
607 | priv->isr_stats.rx_handlers[cnt]); | |
608 | } | |
609 | ||
610 | pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n", | |
611 | priv->isr_stats.tx); | |
612 | ||
613 | pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n", | |
614 | priv->isr_stats.unhandled); | |
615 | ||
616 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
617 | kfree(buf); | |
618 | return ret; | |
619 | } | |
620 | ||
621 | static ssize_t iwl_dbgfs_interrupt_write(struct file *file, | |
622 | const char __user *user_buf, | |
623 | size_t count, loff_t *ppos) | |
624 | { | |
625 | struct iwl_priv *priv = file->private_data; | |
626 | char buf[8]; | |
627 | int buf_size; | |
628 | u32 reset_flag; | |
629 | ||
630 | memset(buf, 0, sizeof(buf)); | |
631 | buf_size = min(count, sizeof(buf) - 1); | |
632 | if (copy_from_user(buf, user_buf, buf_size)) | |
633 | return -EFAULT; | |
634 | if (sscanf(buf, "%x", &reset_flag) != 1) | |
635 | return -EFAULT; | |
636 | if (reset_flag == 0) | |
637 | iwl_clear_isr_stats(priv); | |
638 | ||
639 | return count; | |
640 | } | |
641 | ||
f5ad69fa WYG |
642 | static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf, |
643 | size_t count, loff_t *ppos) | |
644 | { | |
28f63a4b | 645 | struct iwl_priv *priv = file->private_data; |
f5ad69fa WYG |
646 | int pos = 0, i; |
647 | char buf[256]; | |
648 | const size_t bufsz = sizeof(buf); | |
f5ad69fa WYG |
649 | |
650 | for (i = 0; i < AC_NUM; i++) { | |
651 | pos += scnprintf(buf + pos, bufsz - pos, | |
652 | "\tcw_min\tcw_max\taifsn\ttxop\n"); | |
653 | pos += scnprintf(buf + pos, bufsz - pos, | |
654 | "AC[%d]\t%u\t%u\t%u\t%u\n", i, | |
655 | priv->qos_data.def_qos_parm.ac[i].cw_min, | |
656 | priv->qos_data.def_qos_parm.ac[i].cw_max, | |
657 | priv->qos_data.def_qos_parm.ac[i].aifsn, | |
658 | priv->qos_data.def_qos_parm.ac[i].edca_txop); | |
659 | } | |
4967c316 | 660 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
f5ad69fa | 661 | } |
a83b9141 | 662 | |
a283c011 WYG |
663 | static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf, |
664 | size_t count, loff_t *ppos) | |
665 | { | |
28f63a4b | 666 | struct iwl_priv *priv = file->private_data; |
a283c011 WYG |
667 | int pos = 0; |
668 | char buf[256]; | |
669 | const size_t bufsz = sizeof(buf); | |
a283c011 WYG |
670 | |
671 | pos += scnprintf(buf + pos, bufsz - pos, | |
672 | "allow blinking: %s\n", | |
673 | (priv->allow_blinking) ? "True" : "False"); | |
674 | if (priv->allow_blinking) { | |
675 | pos += scnprintf(buf + pos, bufsz - pos, | |
676 | "Led blinking rate: %u\n", | |
677 | priv->last_blink_rate); | |
678 | pos += scnprintf(buf + pos, bufsz - pos, | |
679 | "Last blink time: %lu\n", | |
680 | priv->last_blink_time); | |
681 | } | |
682 | ||
4967c316 | 683 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
a283c011 | 684 | } |
a283c011 | 685 | |
fbf3a2af WYG |
686 | static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file, |
687 | char __user *user_buf, | |
688 | size_t count, loff_t *ppos) | |
689 | { | |
28f63a4b | 690 | struct iwl_priv *priv = file->private_data; |
3ad3b92a | 691 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; |
fbf3a2af WYG |
692 | struct iwl_tt_restriction *restriction; |
693 | char buf[100]; | |
694 | int pos = 0; | |
695 | const size_t bufsz = sizeof(buf); | |
fbf3a2af WYG |
696 | |
697 | pos += scnprintf(buf + pos, bufsz - pos, | |
698 | "Thermal Throttling Mode: %s\n", | |
3ad3b92a | 699 | tt->advanced_tt ? "Advance" : "Legacy"); |
fbf3a2af WYG |
700 | pos += scnprintf(buf + pos, bufsz - pos, |
701 | "Thermal Throttling State: %d\n", | |
702 | tt->state); | |
3ad3b92a | 703 | if (tt->advanced_tt) { |
fbf3a2af WYG |
704 | restriction = tt->restriction + tt->state; |
705 | pos += scnprintf(buf + pos, bufsz - pos, | |
706 | "Tx mode: %d\n", | |
707 | restriction->tx_stream); | |
708 | pos += scnprintf(buf + pos, bufsz - pos, | |
709 | "Rx mode: %d\n", | |
710 | restriction->rx_stream); | |
711 | pos += scnprintf(buf + pos, bufsz - pos, | |
712 | "HT mode: %d\n", | |
713 | restriction->is_ht); | |
714 | } | |
4967c316 | 715 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
fbf3a2af WYG |
716 | } |
717 | ||
1e4247d4 WYG |
718 | static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file, |
719 | const char __user *user_buf, | |
720 | size_t count, loff_t *ppos) | |
721 | { | |
722 | struct iwl_priv *priv = file->private_data; | |
723 | char buf[8]; | |
724 | int buf_size; | |
725 | int ht40; | |
726 | ||
727 | memset(buf, 0, sizeof(buf)); | |
728 | buf_size = min(count, sizeof(buf) - 1); | |
729 | if (copy_from_user(buf, user_buf, buf_size)) | |
730 | return -EFAULT; | |
731 | if (sscanf(buf, "%d", &ht40) != 1) | |
732 | return -EFAULT; | |
733 | if (!iwl_is_associated(priv)) | |
734 | priv->disable_ht40 = ht40 ? true : false; | |
735 | else { | |
736 | IWL_ERR(priv, "Sta associated with AP - " | |
737 | "Change to 40MHz channel support is not allowed\n"); | |
738 | return -EINVAL; | |
739 | } | |
740 | ||
741 | return count; | |
742 | } | |
743 | ||
744 | static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file, | |
745 | char __user *user_buf, | |
746 | size_t count, loff_t *ppos) | |
747 | { | |
28f63a4b | 748 | struct iwl_priv *priv = file->private_data; |
1e4247d4 WYG |
749 | char buf[100]; |
750 | int pos = 0; | |
751 | const size_t bufsz = sizeof(buf); | |
1e4247d4 WYG |
752 | |
753 | pos += scnprintf(buf + pos, bufsz - pos, | |
754 | "11n 40MHz Mode: %s\n", | |
755 | priv->disable_ht40 ? "Disabled" : "Enabled"); | |
4967c316 | 756 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
1e4247d4 WYG |
757 | } |
758 | ||
e312c24c JB |
759 | static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file, |
760 | const char __user *user_buf, | |
761 | size_t count, loff_t *ppos) | |
762 | { | |
763 | struct iwl_priv *priv = file->private_data; | |
764 | char buf[8]; | |
765 | int buf_size; | |
766 | int value; | |
767 | ||
768 | memset(buf, 0, sizeof(buf)); | |
769 | buf_size = min(count, sizeof(buf) - 1); | |
770 | if (copy_from_user(buf, user_buf, buf_size)) | |
771 | return -EFAULT; | |
772 | ||
773 | if (sscanf(buf, "%d", &value) != 1) | |
774 | return -EINVAL; | |
775 | ||
776 | /* | |
777 | * Our users expect 0 to be "CAM", but 0 isn't actually | |
778 | * valid here. However, let's not confuse them and present | |
779 | * IWL_POWER_INDEX_1 as "1", not "0". | |
780 | */ | |
1a34c043 RC |
781 | if (value == 0) |
782 | return -EINVAL; | |
783 | else if (value > 0) | |
e312c24c JB |
784 | value -= 1; |
785 | ||
786 | if (value != -1 && (value < 0 || value >= IWL_POWER_NUM)) | |
787 | return -EINVAL; | |
788 | ||
4ad177b5 WYG |
789 | if (!iwl_is_ready_rf(priv)) |
790 | return -EAGAIN; | |
791 | ||
e312c24c JB |
792 | priv->power_data.debug_sleep_level_override = value; |
793 | ||
d3a57197 | 794 | mutex_lock(&priv->mutex); |
4ad177b5 | 795 | iwl_power_update_mode(priv, true); |
d3a57197 | 796 | mutex_unlock(&priv->mutex); |
e312c24c JB |
797 | |
798 | return count; | |
799 | } | |
800 | ||
801 | static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file, | |
802 | char __user *user_buf, | |
803 | size_t count, loff_t *ppos) | |
804 | { | |
28f63a4b | 805 | struct iwl_priv *priv = file->private_data; |
e312c24c JB |
806 | char buf[10]; |
807 | int pos, value; | |
808 | const size_t bufsz = sizeof(buf); | |
809 | ||
810 | /* see the write function */ | |
811 | value = priv->power_data.debug_sleep_level_override; | |
812 | if (value >= 0) | |
813 | value += 1; | |
814 | ||
815 | pos = scnprintf(buf, bufsz, "%d\n", value); | |
816 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
817 | } | |
818 | ||
819 | static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file, | |
820 | char __user *user_buf, | |
821 | size_t count, loff_t *ppos) | |
822 | { | |
28f63a4b | 823 | struct iwl_priv *priv = file->private_data; |
e312c24c JB |
824 | char buf[200]; |
825 | int pos = 0, i; | |
826 | const size_t bufsz = sizeof(buf); | |
827 | struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd; | |
828 | ||
829 | pos += scnprintf(buf + pos, bufsz - pos, | |
830 | "flags: %#.2x\n", le16_to_cpu(cmd->flags)); | |
831 | pos += scnprintf(buf + pos, bufsz - pos, | |
832 | "RX/TX timeout: %d/%d usec\n", | |
833 | le32_to_cpu(cmd->rx_data_timeout), | |
834 | le32_to_cpu(cmd->tx_data_timeout)); | |
835 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) | |
836 | pos += scnprintf(buf + pos, bufsz - pos, | |
837 | "sleep_interval[%d]: %d\n", i, | |
838 | le32_to_cpu(cmd->sleep_interval[i])); | |
839 | ||
840 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
841 | } | |
842 | ||
712b6cf5 | 843 | DEBUGFS_READ_WRITE_FILE_OPS(sram); |
b03d7d0f | 844 | DEBUGFS_READ_WRITE_FILE_OPS(log_event); |
0848e297 | 845 | DEBUGFS_READ_FILE_OPS(nvm); |
712b6cf5 | 846 | DEBUGFS_READ_FILE_OPS(stations); |
d366df5a | 847 | DEBUGFS_READ_FILE_OPS(channels); |
08df05aa | 848 | DEBUGFS_READ_FILE_OPS(status); |
a83b9141 | 849 | DEBUGFS_READ_WRITE_FILE_OPS(interrupt); |
f5ad69fa | 850 | DEBUGFS_READ_FILE_OPS(qos); |
a283c011 | 851 | DEBUGFS_READ_FILE_OPS(led); |
fbf3a2af | 852 | DEBUGFS_READ_FILE_OPS(thermal_throttling); |
1e4247d4 | 853 | DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40); |
e312c24c JB |
854 | DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override); |
855 | DEBUGFS_READ_FILE_OPS(current_sleep_command); | |
712b6cf5 | 856 | |
20594eb0 WYG |
857 | static ssize_t iwl_dbgfs_traffic_log_read(struct file *file, |
858 | char __user *user_buf, | |
859 | size_t count, loff_t *ppos) | |
860 | { | |
861 | struct iwl_priv *priv = file->private_data; | |
862 | int pos = 0, ofs = 0; | |
863 | int cnt = 0, entry; | |
864 | struct iwl_tx_queue *txq; | |
865 | struct iwl_queue *q; | |
866 | struct iwl_rx_queue *rxq = &priv->rxq; | |
867 | char *buf; | |
868 | int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) + | |
88804e2b | 869 | (priv->cfg->num_of_queues * 32 * 8) + 400; |
20594eb0 WYG |
870 | const u8 *ptr; |
871 | ssize_t ret; | |
872 | ||
88804e2b WYG |
873 | if (!priv->txq) { |
874 | IWL_ERR(priv, "txq not ready\n"); | |
875 | return -EAGAIN; | |
876 | } | |
20594eb0 WYG |
877 | buf = kzalloc(bufsz, GFP_KERNEL); |
878 | if (!buf) { | |
879 | IWL_ERR(priv, "Can not allocate buffer\n"); | |
880 | return -ENOMEM; | |
881 | } | |
882 | pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n"); | |
883 | for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) { | |
884 | txq = &priv->txq[cnt]; | |
885 | q = &txq->q; | |
886 | pos += scnprintf(buf + pos, bufsz - pos, | |
887 | "q[%d]: read_ptr: %u, write_ptr: %u\n", | |
888 | cnt, q->read_ptr, q->write_ptr); | |
889 | } | |
890 | if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) { | |
891 | ptr = priv->tx_traffic; | |
892 | pos += scnprintf(buf + pos, bufsz - pos, | |
893 | "Tx Traffic idx: %u\n", priv->tx_traffic_idx); | |
894 | for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) { | |
895 | for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16; | |
896 | entry++, ofs += 16) { | |
897 | pos += scnprintf(buf + pos, bufsz - pos, | |
898 | "0x%.4x ", ofs); | |
899 | hex_dump_to_buffer(ptr + ofs, 16, 16, 2, | |
900 | buf + pos, bufsz - pos, 0); | |
2fac9717 | 901 | pos += strlen(buf + pos); |
20594eb0 WYG |
902 | if (bufsz - pos > 0) |
903 | buf[pos++] = '\n'; | |
904 | } | |
905 | } | |
906 | } | |
907 | ||
908 | pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n"); | |
909 | pos += scnprintf(buf + pos, bufsz - pos, | |
910 | "read: %u, write: %u\n", | |
911 | rxq->read, rxq->write); | |
912 | ||
913 | if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) { | |
914 | ptr = priv->rx_traffic; | |
915 | pos += scnprintf(buf + pos, bufsz - pos, | |
916 | "Rx Traffic idx: %u\n", priv->rx_traffic_idx); | |
917 | for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) { | |
918 | for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16; | |
919 | entry++, ofs += 16) { | |
920 | pos += scnprintf(buf + pos, bufsz - pos, | |
921 | "0x%.4x ", ofs); | |
922 | hex_dump_to_buffer(ptr + ofs, 16, 16, 2, | |
923 | buf + pos, bufsz - pos, 0); | |
2fac9717 | 924 | pos += strlen(buf + pos); |
20594eb0 WYG |
925 | if (bufsz - pos > 0) |
926 | buf[pos++] = '\n'; | |
927 | } | |
928 | } | |
929 | } | |
930 | ||
931 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
932 | kfree(buf); | |
933 | return ret; | |
934 | } | |
935 | ||
936 | static ssize_t iwl_dbgfs_traffic_log_write(struct file *file, | |
937 | const char __user *user_buf, | |
938 | size_t count, loff_t *ppos) | |
939 | { | |
940 | struct iwl_priv *priv = file->private_data; | |
941 | char buf[8]; | |
942 | int buf_size; | |
943 | int traffic_log; | |
944 | ||
945 | memset(buf, 0, sizeof(buf)); | |
946 | buf_size = min(count, sizeof(buf) - 1); | |
947 | if (copy_from_user(buf, user_buf, buf_size)) | |
948 | return -EFAULT; | |
949 | if (sscanf(buf, "%d", &traffic_log) != 1) | |
950 | return -EFAULT; | |
951 | if (traffic_log == 0) | |
952 | iwl_reset_traffic_log(priv); | |
953 | ||
954 | return count; | |
955 | } | |
956 | ||
141b03e0 WYG |
957 | static ssize_t iwl_dbgfs_tx_queue_read(struct file *file, |
958 | char __user *user_buf, | |
959 | size_t count, loff_t *ppos) { | |
960 | ||
28f63a4b | 961 | struct iwl_priv *priv = file->private_data; |
141b03e0 WYG |
962 | struct iwl_tx_queue *txq; |
963 | struct iwl_queue *q; | |
964 | char *buf; | |
965 | int pos = 0; | |
966 | int cnt; | |
967 | int ret; | |
d23db556 | 968 | const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues; |
141b03e0 | 969 | |
88804e2b WYG |
970 | if (!priv->txq) { |
971 | IWL_ERR(priv, "txq not ready\n"); | |
972 | return -EAGAIN; | |
973 | } | |
141b03e0 WYG |
974 | buf = kzalloc(bufsz, GFP_KERNEL); |
975 | if (!buf) | |
976 | return -ENOMEM; | |
977 | ||
978 | for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) { | |
979 | txq = &priv->txq[cnt]; | |
980 | q = &txq->q; | |
981 | pos += scnprintf(buf + pos, bufsz - pos, | |
982 | "hwq %.2d: read=%u write=%u stop=%d" | |
983 | " swq_id=%#.2x (ac %d/hwq %d)\n", | |
984 | cnt, q->read_ptr, q->write_ptr, | |
985 | !!test_bit(cnt, priv->queue_stopped), | |
986 | txq->swq_id, | |
987 | txq->swq_id & 0x80 ? txq->swq_id & 3 : | |
988 | txq->swq_id, | |
989 | txq->swq_id & 0x80 ? (txq->swq_id >> 2) & | |
990 | 0x1f : txq->swq_id); | |
991 | if (cnt >= 4) | |
992 | continue; | |
993 | /* for the ACs, display the stop count too */ | |
994 | pos += scnprintf(buf + pos, bufsz - pos, | |
995 | " stop-count: %d\n", | |
996 | atomic_read(&priv->queue_stop_count[cnt])); | |
997 | } | |
998 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
999 | kfree(buf); | |
1000 | return ret; | |
1001 | } | |
1002 | ||
1003 | static ssize_t iwl_dbgfs_rx_queue_read(struct file *file, | |
1004 | char __user *user_buf, | |
1005 | size_t count, loff_t *ppos) { | |
1006 | ||
28f63a4b | 1007 | struct iwl_priv *priv = file->private_data; |
141b03e0 WYG |
1008 | struct iwl_rx_queue *rxq = &priv->rxq; |
1009 | char buf[256]; | |
1010 | int pos = 0; | |
1011 | const size_t bufsz = sizeof(buf); | |
1012 | ||
1013 | pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n", | |
1014 | rxq->read); | |
1015 | pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n", | |
1016 | rxq->write); | |
1017 | pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n", | |
1018 | rxq->free_count); | |
f5cc6a22 DS |
1019 | if (rxq->rb_stts) { |
1020 | pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n", | |
141b03e0 | 1021 | le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF); |
f5cc6a22 DS |
1022 | } else { |
1023 | pos += scnprintf(buf + pos, bufsz - pos, | |
1024 | "closed_rb_num: Not Allocated\n"); | |
1025 | } | |
141b03e0 WYG |
1026 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
1027 | } | |
1028 | ||
e8fe59ae WYG |
1029 | static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file, |
1030 | char __user *user_buf, | |
1031 | size_t count, loff_t *ppos) | |
1032 | { | |
28f63a4b | 1033 | struct iwl_priv *priv = file->private_data; |
17f36fc6 AK |
1034 | return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file, |
1035 | user_buf, count, ppos); | |
e8fe59ae WYG |
1036 | } |
1037 | ||
1038 | static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file, | |
1039 | char __user *user_buf, | |
1040 | size_t count, loff_t *ppos) | |
1041 | { | |
28f63a4b | 1042 | struct iwl_priv *priv = file->private_data; |
17f36fc6 AK |
1043 | return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file, |
1044 | user_buf, count, ppos); | |
e8fe59ae WYG |
1045 | } |
1046 | ||
1047 | static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file, | |
1048 | char __user *user_buf, | |
1049 | size_t count, loff_t *ppos) | |
1050 | { | |
28f63a4b | 1051 | struct iwl_priv *priv = file->private_data; |
17f36fc6 AK |
1052 | return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file, |
1053 | user_buf, count, ppos); | |
e8fe59ae WYG |
1054 | } |
1055 | ||
5225935b WYG |
1056 | static ssize_t iwl_dbgfs_sensitivity_read(struct file *file, |
1057 | char __user *user_buf, | |
1058 | size_t count, loff_t *ppos) { | |
1059 | ||
28f63a4b | 1060 | struct iwl_priv *priv = file->private_data; |
5225935b WYG |
1061 | int pos = 0; |
1062 | int cnt = 0; | |
1063 | char *buf; | |
1064 | int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100; | |
1065 | ssize_t ret; | |
1066 | struct iwl_sensitivity_data *data; | |
1067 | ||
1068 | data = &priv->sensitivity_data; | |
1069 | buf = kzalloc(bufsz, GFP_KERNEL); | |
1070 | if (!buf) { | |
1071 | IWL_ERR(priv, "Can not allocate Buffer\n"); | |
1072 | return -ENOMEM; | |
1073 | } | |
1074 | ||
1075 | pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n", | |
1076 | data->auto_corr_ofdm); | |
1077 | pos += scnprintf(buf + pos, bufsz - pos, | |
1078 | "auto_corr_ofdm_mrc:\t\t %u\n", | |
1079 | data->auto_corr_ofdm_mrc); | |
1080 | pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n", | |
1081 | data->auto_corr_ofdm_x1); | |
1082 | pos += scnprintf(buf + pos, bufsz - pos, | |
1083 | "auto_corr_ofdm_mrc_x1:\t\t %u\n", | |
1084 | data->auto_corr_ofdm_mrc_x1); | |
1085 | pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n", | |
1086 | data->auto_corr_cck); | |
1087 | pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n", | |
1088 | data->auto_corr_cck_mrc); | |
1089 | pos += scnprintf(buf + pos, bufsz - pos, | |
1090 | "last_bad_plcp_cnt_ofdm:\t\t %u\n", | |
1091 | data->last_bad_plcp_cnt_ofdm); | |
1092 | pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n", | |
1093 | data->last_fa_cnt_ofdm); | |
1094 | pos += scnprintf(buf + pos, bufsz - pos, | |
1095 | "last_bad_plcp_cnt_cck:\t\t %u\n", | |
1096 | data->last_bad_plcp_cnt_cck); | |
1097 | pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n", | |
1098 | data->last_fa_cnt_cck); | |
1099 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n", | |
1100 | data->nrg_curr_state); | |
1101 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n", | |
1102 | data->nrg_prev_state); | |
1103 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t"); | |
1104 | for (cnt = 0; cnt < 10; cnt++) { | |
1105 | pos += scnprintf(buf + pos, bufsz - pos, " %u", | |
1106 | data->nrg_value[cnt]); | |
1107 | } | |
1108 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | |
1109 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t"); | |
1110 | for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) { | |
1111 | pos += scnprintf(buf + pos, bufsz - pos, " %u", | |
1112 | data->nrg_silence_rssi[cnt]); | |
1113 | } | |
1114 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | |
1115 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n", | |
1116 | data->nrg_silence_ref); | |
1117 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n", | |
1118 | data->nrg_energy_idx); | |
1119 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n", | |
1120 | data->nrg_silence_idx); | |
1121 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n", | |
1122 | data->nrg_th_cck); | |
1123 | pos += scnprintf(buf + pos, bufsz - pos, | |
1124 | "nrg_auto_corr_silence_diff:\t %u\n", | |
1125 | data->nrg_auto_corr_silence_diff); | |
1126 | pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n", | |
1127 | data->num_in_cck_no_fa); | |
1128 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n", | |
1129 | data->nrg_th_ofdm); | |
1130 | ||
1131 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
1132 | kfree(buf); | |
1133 | return ret; | |
1134 | } | |
1135 | ||
1136 | ||
1137 | static ssize_t iwl_dbgfs_chain_noise_read(struct file *file, | |
1138 | char __user *user_buf, | |
1139 | size_t count, loff_t *ppos) { | |
1140 | ||
28f63a4b | 1141 | struct iwl_priv *priv = file->private_data; |
5225935b WYG |
1142 | int pos = 0; |
1143 | int cnt = 0; | |
1144 | char *buf; | |
1145 | int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100; | |
1146 | ssize_t ret; | |
1147 | struct iwl_chain_noise_data *data; | |
1148 | ||
1149 | data = &priv->chain_noise_data; | |
1150 | buf = kzalloc(bufsz, GFP_KERNEL); | |
1151 | if (!buf) { | |
1152 | IWL_ERR(priv, "Can not allocate Buffer\n"); | |
1153 | return -ENOMEM; | |
1154 | } | |
1155 | ||
1156 | pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n", | |
1157 | data->active_chains); | |
1158 | pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n", | |
1159 | data->chain_noise_a); | |
1160 | pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n", | |
1161 | data->chain_noise_b); | |
1162 | pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n", | |
1163 | data->chain_noise_c); | |
1164 | pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n", | |
1165 | data->chain_signal_a); | |
1166 | pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n", | |
1167 | data->chain_signal_b); | |
1168 | pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n", | |
1169 | data->chain_signal_c); | |
1170 | pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n", | |
1171 | data->beacon_count); | |
1172 | ||
1173 | pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t"); | |
1174 | for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) { | |
1175 | pos += scnprintf(buf + pos, bufsz - pos, " %u", | |
1176 | data->disconn_array[cnt]); | |
1177 | } | |
1178 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | |
1179 | pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t"); | |
1180 | for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) { | |
1181 | pos += scnprintf(buf + pos, bufsz - pos, " %u", | |
1182 | data->delta_gain_code[cnt]); | |
1183 | } | |
1184 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | |
1185 | pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n", | |
1186 | data->radio_write); | |
1187 | pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n", | |
1188 | data->state); | |
1189 | ||
1190 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
1191 | kfree(buf); | |
1192 | return ret; | |
1193 | } | |
1194 | ||
c09430ab WYG |
1195 | static ssize_t iwl_dbgfs_power_save_status_read(struct file *file, |
1196 | char __user *user_buf, | |
1197 | size_t count, loff_t *ppos) | |
1198 | { | |
28f63a4b | 1199 | struct iwl_priv *priv = file->private_data; |
c09430ab WYG |
1200 | char buf[60]; |
1201 | int pos = 0; | |
1202 | const size_t bufsz = sizeof(buf); | |
1203 | u32 pwrsave_status; | |
1204 | ||
1205 | pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) & | |
1206 | CSR_GP_REG_POWER_SAVE_STATUS_MSK; | |
1207 | ||
1208 | pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: "); | |
1209 | pos += scnprintf(buf + pos, bufsz - pos, "%s\n", | |
1210 | (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" : | |
1211 | (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" : | |
1212 | (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" : | |
1213 | "error"); | |
1214 | ||
1215 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
1216 | } | |
1217 | ||
7163b8a4 | 1218 | static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file, |
ef8d5529 WYG |
1219 | const char __user *user_buf, |
1220 | size_t count, loff_t *ppos) | |
1221 | { | |
1222 | struct iwl_priv *priv = file->private_data; | |
1223 | char buf[8]; | |
1224 | int buf_size; | |
1225 | int clear; | |
1226 | ||
1227 | memset(buf, 0, sizeof(buf)); | |
1228 | buf_size = min(count, sizeof(buf) - 1); | |
1229 | if (copy_from_user(buf, user_buf, buf_size)) | |
1230 | return -EFAULT; | |
1231 | if (sscanf(buf, "%d", &clear) != 1) | |
1232 | return -EFAULT; | |
1233 | ||
1234 | /* make request to uCode to retrieve statistics information */ | |
1235 | mutex_lock(&priv->mutex); | |
1236 | iwl_send_statistics_request(priv, CMD_SYNC, true); | |
1237 | mutex_unlock(&priv->mutex); | |
1238 | ||
1239 | return count; | |
1240 | } | |
1241 | ||
696bdee3 WYG |
1242 | static ssize_t iwl_dbgfs_csr_write(struct file *file, |
1243 | const char __user *user_buf, | |
1244 | size_t count, loff_t *ppos) | |
1245 | { | |
1246 | struct iwl_priv *priv = file->private_data; | |
1247 | char buf[8]; | |
1248 | int buf_size; | |
1249 | int csr; | |
1250 | ||
1251 | memset(buf, 0, sizeof(buf)); | |
1252 | buf_size = min(count, sizeof(buf) - 1); | |
1253 | if (copy_from_user(buf, user_buf, buf_size)) | |
1254 | return -EFAULT; | |
1255 | if (sscanf(buf, "%d", &csr) != 1) | |
1256 | return -EFAULT; | |
1257 | ||
1258 | if (priv->cfg->ops->lib->dump_csr) | |
1259 | priv->cfg->ops->lib->dump_csr(priv); | |
1260 | ||
1261 | return count; | |
1262 | } | |
1263 | ||
a9e1cb6a WYG |
1264 | static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file, |
1265 | char __user *user_buf, | |
1266 | size_t count, loff_t *ppos) { | |
1267 | ||
57674308 | 1268 | struct iwl_priv *priv = file->private_data; |
a9e1cb6a WYG |
1269 | int pos = 0; |
1270 | char buf[128]; | |
1271 | const size_t bufsz = sizeof(buf); | |
a9e1cb6a WYG |
1272 | |
1273 | pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n", | |
1274 | priv->event_log.ucode_trace ? "On" : "Off"); | |
1275 | pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n", | |
1276 | priv->event_log.non_wraps_count); | |
1277 | pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n", | |
1278 | priv->event_log.wraps_once_count); | |
1279 | pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n", | |
1280 | priv->event_log.wraps_more_count); | |
1281 | ||
4967c316 | 1282 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
a9e1cb6a WYG |
1283 | } |
1284 | ||
1285 | static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file, | |
1286 | const char __user *user_buf, | |
1287 | size_t count, loff_t *ppos) | |
1288 | { | |
1289 | struct iwl_priv *priv = file->private_data; | |
1290 | char buf[8]; | |
1291 | int buf_size; | |
1292 | int trace; | |
1293 | ||
1294 | memset(buf, 0, sizeof(buf)); | |
1295 | buf_size = min(count, sizeof(buf) - 1); | |
1296 | if (copy_from_user(buf, user_buf, buf_size)) | |
1297 | return -EFAULT; | |
1298 | if (sscanf(buf, "%d", &trace) != 1) | |
1299 | return -EFAULT; | |
1300 | ||
1301 | if (trace) { | |
1302 | priv->event_log.ucode_trace = true; | |
1303 | /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */ | |
1304 | mod_timer(&priv->ucode_trace, | |
1305 | jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD)); | |
1306 | } else { | |
1307 | priv->event_log.ucode_trace = false; | |
1308 | del_timer_sync(&priv->ucode_trace); | |
1309 | } | |
1310 | ||
1311 | return count; | |
1312 | } | |
1313 | ||
60987206 JB |
1314 | static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file, |
1315 | char __user *user_buf, | |
1316 | size_t count, loff_t *ppos) { | |
1317 | ||
57674308 | 1318 | struct iwl_priv *priv = file->private_data; |
60987206 JB |
1319 | int len = 0; |
1320 | char buf[20]; | |
1321 | ||
1322 | len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags)); | |
1323 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
1324 | } | |
1325 | ||
1326 | static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file, | |
1327 | char __user *user_buf, | |
1328 | size_t count, loff_t *ppos) { | |
1329 | ||
57674308 | 1330 | struct iwl_priv *priv = file->private_data; |
60987206 JB |
1331 | int len = 0; |
1332 | char buf[20]; | |
1333 | ||
1334 | len = sprintf(buf, "0x%04X\n", | |
1335 | le32_to_cpu(priv->active_rxon.filter_flags)); | |
1336 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
1337 | } | |
1338 | ||
1b3eb823 WYG |
1339 | static ssize_t iwl_dbgfs_fh_reg_read(struct file *file, |
1340 | char __user *user_buf, | |
1341 | size_t count, loff_t *ppos) | |
1342 | { | |
57674308 | 1343 | struct iwl_priv *priv = file->private_data; |
1b3eb823 WYG |
1344 | char *buf; |
1345 | int pos = 0; | |
1346 | ssize_t ret = -EFAULT; | |
1347 | ||
1348 | if (priv->cfg->ops->lib->dump_fh) { | |
1349 | ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true); | |
1350 | if (buf) { | |
1351 | ret = simple_read_from_buffer(user_buf, | |
1352 | count, ppos, buf, pos); | |
1353 | kfree(buf); | |
1354 | } | |
1355 | } | |
1356 | ||
1357 | return ret; | |
1358 | } | |
1359 | ||
a13d276f WYG |
1360 | static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file, |
1361 | char __user *user_buf, | |
1362 | size_t count, loff_t *ppos) { | |
1363 | ||
1364 | struct iwl_priv *priv = file->private_data; | |
1365 | int pos = 0; | |
1366 | char buf[12]; | |
1367 | const size_t bufsz = sizeof(buf); | |
a13d276f WYG |
1368 | |
1369 | pos += scnprintf(buf + pos, bufsz - pos, "%d\n", | |
1370 | priv->missed_beacon_threshold); | |
1371 | ||
4967c316 | 1372 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
a13d276f WYG |
1373 | } |
1374 | ||
1375 | static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file, | |
1376 | const char __user *user_buf, | |
1377 | size_t count, loff_t *ppos) | |
1378 | { | |
1379 | struct iwl_priv *priv = file->private_data; | |
1380 | char buf[8]; | |
1381 | int buf_size; | |
1382 | int missed; | |
1383 | ||
1384 | memset(buf, 0, sizeof(buf)); | |
1385 | buf_size = min(count, sizeof(buf) - 1); | |
1386 | if (copy_from_user(buf, user_buf, buf_size)) | |
1387 | return -EFAULT; | |
1388 | if (sscanf(buf, "%d", &missed) != 1) | |
1389 | return -EINVAL; | |
1390 | ||
1391 | if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN || | |
1392 | missed > IWL_MISSED_BEACON_THRESHOLD_MAX) | |
1393 | priv->missed_beacon_threshold = | |
1394 | IWL_MISSED_BEACON_THRESHOLD_DEF; | |
1395 | else | |
1396 | priv->missed_beacon_threshold = missed; | |
1397 | ||
1398 | return count; | |
1399 | } | |
1400 | ||
3e4fb5fa TAN |
1401 | static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file, |
1402 | char __user *user_buf, | |
1403 | size_t count, loff_t *ppos) { | |
1404 | ||
57674308 | 1405 | struct iwl_priv *priv = file->private_data; |
3e4fb5fa TAN |
1406 | int pos = 0; |
1407 | char buf[12]; | |
1408 | const size_t bufsz = sizeof(buf); | |
3e4fb5fa TAN |
1409 | |
1410 | pos += scnprintf(buf + pos, bufsz - pos, "%u\n", | |
1411 | priv->cfg->plcp_delta_threshold); | |
1412 | ||
4967c316 | 1413 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
3e4fb5fa TAN |
1414 | } |
1415 | ||
1416 | static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file, | |
1417 | const char __user *user_buf, | |
1418 | size_t count, loff_t *ppos) { | |
1419 | ||
1420 | struct iwl_priv *priv = file->private_data; | |
1421 | char buf[8]; | |
1422 | int buf_size; | |
1423 | int plcp; | |
1424 | ||
1425 | memset(buf, 0, sizeof(buf)); | |
1426 | buf_size = min(count, sizeof(buf) - 1); | |
1427 | if (copy_from_user(buf, user_buf, buf_size)) | |
1428 | return -EFAULT; | |
1429 | if (sscanf(buf, "%d", &plcp) != 1) | |
1430 | return -EINVAL; | |
680788ac | 1431 | if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) || |
3e4fb5fa TAN |
1432 | (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX)) |
1433 | priv->cfg->plcp_delta_threshold = | |
680788ac | 1434 | IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE; |
3e4fb5fa TAN |
1435 | else |
1436 | priv->cfg->plcp_delta_threshold = plcp; | |
1437 | return count; | |
1438 | } | |
1439 | ||
528c3126 WYG |
1440 | static ssize_t iwl_dbgfs_force_reset_read(struct file *file, |
1441 | char __user *user_buf, | |
1442 | size_t count, loff_t *ppos) { | |
1443 | ||
1444 | struct iwl_priv *priv = file->private_data; | |
1445 | int i, pos = 0; | |
1446 | char buf[300]; | |
1447 | const size_t bufsz = sizeof(buf); | |
1448 | struct iwl_force_reset *force_reset; | |
1449 | ||
1450 | for (i = 0; i < IWL_MAX_FORCE_RESET; i++) { | |
1451 | force_reset = &priv->force_reset[i]; | |
1452 | pos += scnprintf(buf + pos, bufsz - pos, | |
1453 | "Force reset method %d\n", i); | |
1454 | pos += scnprintf(buf + pos, bufsz - pos, | |
1455 | "\tnumber of reset request: %d\n", | |
1456 | force_reset->reset_request_count); | |
1457 | pos += scnprintf(buf + pos, bufsz - pos, | |
1458 | "\tnumber of reset request success: %d\n", | |
1459 | force_reset->reset_success_count); | |
1460 | pos += scnprintf(buf + pos, bufsz - pos, | |
1461 | "\tnumber of reset request reject: %d\n", | |
1462 | force_reset->reset_reject_count); | |
1463 | pos += scnprintf(buf + pos, bufsz - pos, | |
1464 | "\treset duration: %lu\n", | |
1465 | force_reset->reset_duration); | |
1466 | } | |
1467 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
1468 | } | |
1469 | ||
04cafd7f WYG |
1470 | static ssize_t iwl_dbgfs_force_reset_write(struct file *file, |
1471 | const char __user *user_buf, | |
1472 | size_t count, loff_t *ppos) { | |
1473 | ||
1474 | struct iwl_priv *priv = file->private_data; | |
1475 | char buf[8]; | |
1476 | int buf_size; | |
1477 | int reset, ret; | |
1478 | ||
1479 | memset(buf, 0, sizeof(buf)); | |
1480 | buf_size = min(count, sizeof(buf) - 1); | |
1481 | if (copy_from_user(buf, user_buf, buf_size)) | |
1482 | return -EFAULT; | |
1483 | if (sscanf(buf, "%d", &reset) != 1) | |
1484 | return -EINVAL; | |
1485 | switch (reset) { | |
1486 | case IWL_RF_RESET: | |
1487 | case IWL_FW_RESET: | |
c04f9f22 | 1488 | ret = iwl_force_reset(priv, reset, true); |
04cafd7f WYG |
1489 | break; |
1490 | default: | |
1491 | return -EINVAL; | |
1492 | } | |
1493 | return ret ? ret : count; | |
1494 | } | |
1495 | ||
4bf49a90 WYG |
1496 | static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file, |
1497 | const char __user *user_buf, | |
1498 | size_t count, loff_t *ppos) { | |
1499 | ||
1500 | struct iwl_priv *priv = file->private_data; | |
1501 | char buf[8]; | |
1502 | int buf_size; | |
1503 | int flush; | |
1504 | ||
1505 | memset(buf, 0, sizeof(buf)); | |
1506 | buf_size = min(count, sizeof(buf) - 1); | |
1507 | if (copy_from_user(buf, user_buf, buf_size)) | |
1508 | return -EFAULT; | |
1509 | if (sscanf(buf, "%d", &flush) != 1) | |
1510 | return -EINVAL; | |
1511 | ||
1512 | if (iwl_is_rfkill(priv)) | |
1513 | return -EFAULT; | |
1514 | ||
1515 | priv->cfg->ops->lib->dev_txfifo_flush(priv, IWL_DROP_ALL); | |
1516 | ||
1517 | return count; | |
1518 | } | |
1519 | ||
ffb7d896 WYG |
1520 | static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file, |
1521 | char __user *user_buf, | |
1522 | size_t count, loff_t *ppos) | |
1523 | { | |
1524 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; | |
1525 | ||
1526 | return priv->cfg->ops->lib->debugfs_ops.bt_stats_read(file, | |
1527 | user_buf, count, ppos); | |
1528 | } | |
1529 | ||
7bdc473c WYG |
1530 | static ssize_t iwl_dbgfs_monitor_period_write(struct file *file, |
1531 | const char __user *user_buf, | |
1532 | size_t count, loff_t *ppos) { | |
1533 | ||
1534 | struct iwl_priv *priv = file->private_data; | |
1535 | char buf[8]; | |
1536 | int buf_size; | |
1537 | int period; | |
1538 | ||
1539 | memset(buf, 0, sizeof(buf)); | |
1540 | buf_size = min(count, sizeof(buf) - 1); | |
1541 | if (copy_from_user(buf, user_buf, buf_size)) | |
1542 | return -EFAULT; | |
1543 | if (sscanf(buf, "%d", &period) != 1) | |
1544 | return -EINVAL; | |
1545 | if (period < 0 || period > IWL_MAX_MONITORING_PERIOD) | |
1546 | priv->cfg->monitor_recover_period = IWL_DEF_MONITORING_PERIOD; | |
1547 | else | |
1548 | priv->cfg->monitor_recover_period = period; | |
1549 | ||
1550 | if (priv->cfg->monitor_recover_period) | |
1551 | mod_timer(&priv->monitor_recover, jiffies + msecs_to_jiffies( | |
1552 | priv->cfg->monitor_recover_period)); | |
1553 | else | |
1554 | del_timer_sync(&priv->monitor_recover); | |
1555 | return count; | |
1556 | } | |
1557 | ||
befe8c46 WYG |
1558 | static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file, |
1559 | char __user *user_buf, | |
1560 | size_t count, loff_t *ppos) { | |
1561 | ||
1562 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; | |
1563 | int pos = 0; | |
1564 | char buf[200]; | |
1565 | const size_t bufsz = sizeof(buf); | |
1566 | ssize_t ret; | |
1567 | ||
1568 | pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n", | |
1569 | priv->bt_full_concurrent ? "full concurrency" : "3-wire"); | |
1570 | pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, " | |
1571 | "last traffic notif: %d\n", | |
1572 | priv->bt_status ? "On" : "Off", priv->notif_bt_traffic_load); | |
1573 | pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, " | |
1574 | "sco_active: %d, kill_ack_mask: %x, " | |
1575 | "kill_cts_mask: %x\n", | |
1576 | priv->bt_ch_announce, priv->bt_sco_active, | |
1577 | priv->kill_ack_mask, priv->kill_cts_mask); | |
1578 | ||
1579 | pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: "); | |
1580 | switch (priv->bt_traffic_load) { | |
1581 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: | |
1582 | pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n"); | |
1583 | break; | |
1584 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: | |
1585 | pos += scnprintf(buf + pos, bufsz - pos, "High\n"); | |
1586 | break; | |
1587 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: | |
1588 | pos += scnprintf(buf + pos, bufsz - pos, "Low\n"); | |
1589 | break; | |
1590 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: | |
1591 | default: | |
1592 | pos += scnprintf(buf + pos, bufsz - pos, "None\n"); | |
1593 | break; | |
1594 | } | |
1595 | ||
1596 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
1597 | return ret; | |
1598 | } | |
1599 | ||
7163b8a4 WYG |
1600 | DEBUGFS_READ_FILE_OPS(rx_statistics); |
1601 | DEBUGFS_READ_FILE_OPS(tx_statistics); | |
20594eb0 | 1602 | DEBUGFS_READ_WRITE_FILE_OPS(traffic_log); |
141b03e0 WYG |
1603 | DEBUGFS_READ_FILE_OPS(rx_queue); |
1604 | DEBUGFS_READ_FILE_OPS(tx_queue); | |
e8fe59ae WYG |
1605 | DEBUGFS_READ_FILE_OPS(ucode_rx_stats); |
1606 | DEBUGFS_READ_FILE_OPS(ucode_tx_stats); | |
1607 | DEBUGFS_READ_FILE_OPS(ucode_general_stats); | |
5225935b WYG |
1608 | DEBUGFS_READ_FILE_OPS(sensitivity); |
1609 | DEBUGFS_READ_FILE_OPS(chain_noise); | |
c09430ab | 1610 | DEBUGFS_READ_FILE_OPS(power_save_status); |
7163b8a4 WYG |
1611 | DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics); |
1612 | DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics); | |
696bdee3 | 1613 | DEBUGFS_WRITE_FILE_OPS(csr); |
a9e1cb6a | 1614 | DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing); |
1b3eb823 | 1615 | DEBUGFS_READ_FILE_OPS(fh_reg); |
a13d276f | 1616 | DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon); |
3e4fb5fa | 1617 | DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta); |
528c3126 | 1618 | DEBUGFS_READ_WRITE_FILE_OPS(force_reset); |
60987206 JB |
1619 | DEBUGFS_READ_FILE_OPS(rxon_flags); |
1620 | DEBUGFS_READ_FILE_OPS(rxon_filter_flags); | |
4bf49a90 | 1621 | DEBUGFS_WRITE_FILE_OPS(txfifo_flush); |
ffb7d896 | 1622 | DEBUGFS_READ_FILE_OPS(ucode_bt_stats); |
7bdc473c | 1623 | DEBUGFS_WRITE_FILE_OPS(monitor_period); |
befe8c46 | 1624 | DEBUGFS_READ_FILE_OPS(bt_traffic); |
20594eb0 | 1625 | |
712b6cf5 TW |
1626 | /* |
1627 | * Create the debugfs files and directories | |
1628 | * | |
1629 | */ | |
1630 | int iwl_dbgfs_register(struct iwl_priv *priv, const char *name) | |
1631 | { | |
95b1a822 | 1632 | struct dentry *phyd = priv->hw->wiphy->debugfsdir; |
4c84a8f1 | 1633 | struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug; |
712b6cf5 | 1634 | |
4c84a8f1 JB |
1635 | dir_drv = debugfs_create_dir(name, phyd); |
1636 | if (!dir_drv) | |
1637 | return -ENOMEM; | |
712b6cf5 | 1638 | |
4c84a8f1 JB |
1639 | priv->debugfs_dir = dir_drv; |
1640 | ||
1641 | dir_data = debugfs_create_dir("data", dir_drv); | |
1642 | if (!dir_data) | |
1643 | goto err; | |
1644 | dir_rf = debugfs_create_dir("rf", dir_drv); | |
1645 | if (!dir_rf) | |
1646 | goto err; | |
1647 | dir_debug = debugfs_create_dir("debug", dir_drv); | |
1648 | if (!dir_debug) | |
712b6cf5 | 1649 | goto err; |
712b6cf5 | 1650 | |
4c84a8f1 JB |
1651 | DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR); |
1652 | DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR); | |
1653 | DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR); | |
1654 | DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR); | |
1655 | DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR); | |
1656 | DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR); | |
1657 | DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR); | |
1658 | DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR); | |
1659 | DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR); | |
381733cc WYG |
1660 | if (!priv->cfg->broken_powersave) { |
1661 | DEBUGFS_ADD_FILE(sleep_level_override, dir_data, | |
1662 | S_IWUSR | S_IRUSR); | |
1663 | DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR); | |
1664 | } | |
4c84a8f1 JB |
1665 | DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR); |
1666 | DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR); | |
1667 | DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR); | |
1668 | DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR); | |
1669 | DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR); | |
1670 | DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR); | |
1671 | DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR); | |
4c84a8f1 JB |
1672 | DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR); |
1673 | DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR); | |
1674 | DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR); | |
1675 | DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR); | |
1676 | DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR); | |
1677 | DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR); | |
4c84a8f1 | 1678 | DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR); |
528c3126 | 1679 | DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR); |
b8c76267 AK |
1680 | DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR); |
1681 | DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR); | |
1682 | DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR); | |
4bf49a90 WYG |
1683 | if (priv->cfg->ops->lib->dev_txfifo_flush) |
1684 | DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR); | |
b8c76267 | 1685 | |
65d1f896 | 1686 | if (priv->cfg->sensitivity_calib_by_driver) |
4c84a8f1 | 1687 | DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR); |
65d1f896 | 1688 | if (priv->cfg->chain_noise_calib_by_driver) |
4c84a8f1 | 1689 | DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR); |
6e5c800e | 1690 | if (priv->cfg->ucode_tracing) |
4c84a8f1 | 1691 | DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR); |
ffb7d896 WYG |
1692 | if (priv->cfg->bt_statistics) |
1693 | DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR); | |
60987206 JB |
1694 | DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR); |
1695 | DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR); | |
7bdc473c | 1696 | DEBUGFS_ADD_FILE(monitor_period, dir_debug, S_IWUSR); |
befe8c46 WYG |
1697 | if (priv->cfg->advanced_bt_coexist) |
1698 | DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR); | |
65d1f896 WYG |
1699 | if (priv->cfg->sensitivity_calib_by_driver) |
1700 | DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf, | |
1701 | &priv->disable_sens_cal); | |
1702 | if (priv->cfg->chain_noise_calib_by_driver) | |
1703 | DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf, | |
1704 | &priv->disable_chain_noise_cal); | |
4e7033ef | 1705 | if (priv->cfg->tx_power_by_driver) |
4c84a8f1 | 1706 | DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, |
030b8655 | 1707 | &priv->disable_tx_power_cal); |
712b6cf5 TW |
1708 | return 0; |
1709 | ||
1710 | err: | |
4c84a8f1 | 1711 | IWL_ERR(priv, "Can't create the debugfs directory\n"); |
712b6cf5 | 1712 | iwl_dbgfs_unregister(priv); |
4c84a8f1 | 1713 | return -ENOMEM; |
712b6cf5 TW |
1714 | } |
1715 | EXPORT_SYMBOL(iwl_dbgfs_register); | |
1716 | ||
1717 | /** | |
1718 | * Remove the debugfs files and directories | |
1719 | * | |
1720 | */ | |
1721 | void iwl_dbgfs_unregister(struct iwl_priv *priv) | |
1722 | { | |
4c84a8f1 | 1723 | if (!priv->debugfs_dir) |
712b6cf5 TW |
1724 | return; |
1725 | ||
4c84a8f1 JB |
1726 | debugfs_remove_recursive(priv->debugfs_dir); |
1727 | priv->debugfs_dir = NULL; | |
712b6cf5 TW |
1728 | } |
1729 | EXPORT_SYMBOL(iwl_dbgfs_unregister); | |
1730 | ||
1731 | ||
445c2dff | 1732 |