1 /******************************************************************************
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
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.
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.
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,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * Contact Information:
25 * Tomas Winkler <tomas.winkler@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/debugfs.h>
33 #include <linux/ieee80211.h>
34 #include <net/mac80211.h>
38 #include "iwl-debug.h"
43 /* create and remove of files */
44 #define DEBUGFS_ADD_DIR(name, parent) do { \
45 dbgfs->dir_##name = debugfs_create_dir(#name, parent); \
46 if (!(dbgfs->dir_##name)) \
50 #define DEBUGFS_ADD_FILE(name, parent) do { \
51 dbgfs->dbgfs_##parent##_files.file_##name = \
52 debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \
53 &iwl_dbgfs_##name##_ops); \
54 if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
58 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
59 dbgfs->dbgfs_##parent##_files.file_##name = \
60 debugfs_create_bool(#name, 0644, dbgfs->dir_##parent, ptr); \
61 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
62 || !dbgfs->dbgfs_##parent##_files.file_##name) \
66 #define DEBUGFS_REMOVE(name) do { \
67 debugfs_remove(name); \
72 #define DEBUGFS_READ_FUNC(name) \
73 static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
74 char __user *user_buf, \
75 size_t count, loff_t *ppos);
77 #define DEBUGFS_WRITE_FUNC(name) \
78 static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
79 const char __user *user_buf, \
80 size_t count, loff_t *ppos);
83 static int iwl_dbgfs_open_file_generic(struct inode
*inode
, struct file
*file
)
85 file
->private_data
= inode
->i_private
;
89 #define DEBUGFS_READ_FILE_OPS(name) \
90 DEBUGFS_READ_FUNC(name); \
91 static const struct file_operations iwl_dbgfs_##name##_ops = { \
92 .read = iwl_dbgfs_##name##_read, \
93 .open = iwl_dbgfs_open_file_generic, \
96 #define DEBUGFS_WRITE_FILE_OPS(name) \
97 DEBUGFS_WRITE_FUNC(name); \
98 static const struct file_operations iwl_dbgfs_##name##_ops = { \
99 .write = iwl_dbgfs_##name##_write, \
100 .open = iwl_dbgfs_open_file_generic, \
104 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
105 DEBUGFS_READ_FUNC(name); \
106 DEBUGFS_WRITE_FUNC(name); \
107 static const struct file_operations iwl_dbgfs_##name##_ops = { \
108 .write = iwl_dbgfs_##name##_write, \
109 .read = iwl_dbgfs_##name##_read, \
110 .open = iwl_dbgfs_open_file_generic, \
114 static ssize_t
iwl_dbgfs_tx_statistics_read(struct file
*file
,
115 char __user
*user_buf
,
116 size_t count
, loff_t
*ppos
) {
118 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
121 const size_t bufsz
= sizeof(buf
);
123 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "mgmt: %u\n",
124 priv
->tx_stats
[0].cnt
);
125 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "ctrl: %u\n",
126 priv
->tx_stats
[1].cnt
);
127 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "data: %u\n",
128 priv
->tx_stats
[2].cnt
);
130 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
133 static ssize_t
iwl_dbgfs_rx_statistics_read(struct file
*file
,
134 char __user
*user_buf
,
135 size_t count
, loff_t
*ppos
) {
137 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
140 const size_t bufsz
= sizeof(buf
);
142 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "mgmt: %u\n",
143 priv
->rx_stats
[0].cnt
);
144 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "ctrl: %u\n",
145 priv
->rx_stats
[1].cnt
);
146 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "data: %u\n",
147 priv
->rx_stats
[2].cnt
);
149 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
152 #define BYTE1_MASK 0x000000ff;
153 #define BYTE2_MASK 0x0000ffff;
154 #define BYTE3_MASK 0x00ffffff;
155 static ssize_t
iwl_dbgfs_sram_read(struct file
*file
,
156 char __user
*user_buf
,
157 size_t count
, loff_t
*ppos
)
164 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
165 const size_t bufsz
= sizeof(buf
);
167 printk(KERN_DEBUG
"offset is: 0x%x\tlen is: 0x%x\n",
168 priv
->dbgfs
->sram_offset
, priv
->dbgfs
->sram_len
);
170 iwl_grab_nic_access(priv
);
171 for (i
= priv
->dbgfs
->sram_len
; i
> 0; i
-= 4) {
172 val
= iwl_read_targ_mem(priv
, priv
->dbgfs
->sram_offset
+ \
173 priv
->dbgfs
->sram_len
- i
);
187 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "0x%08x ", val
);
189 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
190 iwl_release_nic_access(priv
);
192 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
196 static ssize_t
iwl_dbgfs_sram_write(struct file
*file
,
197 const char __user
*user_buf
,
198 size_t count
, loff_t
*ppos
)
200 struct iwl_priv
*priv
= file
->private_data
;
205 memset(buf
, 0, sizeof(buf
));
206 buf_size
= min(count
, sizeof(buf
) - 1);
207 if (copy_from_user(buf
, user_buf
, buf_size
))
210 if (sscanf(buf
, "%x,%x", &offset
, &len
) == 2) {
211 priv
->dbgfs
->sram_offset
= offset
;
212 priv
->dbgfs
->sram_len
= len
;
214 priv
->dbgfs
->sram_offset
= 0;
215 priv
->dbgfs
->sram_len
= 0;
221 static ssize_t
iwl_dbgfs_stations_read(struct file
*file
, char __user
*user_buf
,
222 size_t count
, loff_t
*ppos
)
224 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
225 struct iwl_station_entry
*station
;
226 int max_sta
= priv
->hw_params
.max_stations
;
230 /* Add 30 for initial string */
231 const size_t bufsz
= 30 + sizeof(char) * 500 * (priv
->num_stations
);
233 buf
= kmalloc(bufsz
, GFP_KERNEL
);
237 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "num of stations: %d\n\n",
240 for (i
= 0; i
< max_sta
; i
++) {
241 station
= &priv
->stations
[i
];
243 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
244 "station %d:\ngeneral data:\n", i
+1);
245 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "id: %u\n",
246 station
->sta
.sta
.sta_id
);
247 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "mode: %u\n",
249 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
251 station
->sta
.station_flags_msk
);
252 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
253 "ps_status: %u\n", station
->ps_status
);
254 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "tid data:\n");
255 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
256 "seq_num\t\ttxq_id");
257 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
258 "\tframe_count\twait_for_ba\t");
259 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
260 "start_idx\tbitmap0\t");
261 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
262 "bitmap1\trate_n_flags");
263 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
265 for (j
= 0; j
< MAX_TID_COUNT
; j
++) {
266 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
268 station
->tid
[j
].seq_number
);
269 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
270 "\t%u\t\t%u\t\t%u\t\t",
271 station
->tid
[j
].agg
.txq_id
,
272 station
->tid
[j
].agg
.frame_count
,
273 station
->tid
[j
].agg
.wait_for_ba
);
274 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
,
276 station
->tid
[j
].agg
.start_idx
,
277 (unsigned long long)station
->tid
[j
].agg
.bitmap
,
278 station
->tid
[j
].agg
.rate_n_flags
);
279 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
281 pos
+= scnprintf(buf
+ pos
, bufsz
- pos
, "\n");
285 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
290 static ssize_t
iwl_dbgfs_eeprom_read(struct file
*file
,
291 char __user
*user_buf
,
296 struct iwl_priv
*priv
= (struct iwl_priv
*)file
->private_data
;
297 int pos
= 0, ofs
= 0, buf_size
= 0;
300 size_t eeprom_len
= priv
->cfg
->eeprom_size
;
301 buf_size
= 4 * eeprom_len
+ 256;
303 if (eeprom_len
% 16) {
304 IWL_ERROR("EEPROM size is not multiple of 16.\n");
308 /* 4 characters for byte 0xYY */
309 buf
= kzalloc(buf_size
, GFP_KERNEL
);
311 IWL_ERROR("Can not allocate Buffer\n");
316 for (ofs
= 0 ; ofs
< eeprom_len
; ofs
+= 16) {
317 pos
+= scnprintf(buf
+ pos
, buf_size
- pos
, "0x%.4x ", ofs
);
318 hex_dump_to_buffer(ptr
+ ofs
, 16 , 16, 2, buf
+ pos
,
321 if (buf_size
- pos
> 0)
325 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, pos
);
330 static ssize_t
iwl_dbgfs_log_event_write(struct file
*file
,
331 const char __user
*user_buf
,
332 size_t count
, loff_t
*ppos
)
334 struct iwl_priv
*priv
= file
->private_data
;
339 memset(buf
, 0, sizeof(buf
));
340 buf_size
= min(count
, sizeof(buf
) - 1);
341 if (copy_from_user(buf
, user_buf
, buf_size
))
343 if (sscanf(buf
, "%d", &event_log_flag
) != 1)
345 if (event_log_flag
== 1)
346 iwl_dump_nic_event_log(priv
);
351 DEBUGFS_READ_WRITE_FILE_OPS(sram
);
352 DEBUGFS_WRITE_FILE_OPS(log_event
);
353 DEBUGFS_READ_FILE_OPS(eeprom
);
354 DEBUGFS_READ_FILE_OPS(stations
);
355 DEBUGFS_READ_FILE_OPS(rx_statistics
);
356 DEBUGFS_READ_FILE_OPS(tx_statistics
);
359 * Create the debugfs files and directories
362 int iwl_dbgfs_register(struct iwl_priv
*priv
, const char *name
)
364 struct iwl_debugfs
*dbgfs
;
365 struct dentry
*phyd
= priv
->hw
->wiphy
->debugfsdir
;
368 dbgfs
= kzalloc(sizeof(struct iwl_debugfs
), GFP_KERNEL
);
376 dbgfs
->dir_drv
= debugfs_create_dir(name
, phyd
);
377 if (!dbgfs
->dir_drv
|| IS_ERR(dbgfs
->dir_drv
)) {
382 DEBUGFS_ADD_DIR(data
, dbgfs
->dir_drv
);
383 DEBUGFS_ADD_DIR(rf
, dbgfs
->dir_drv
);
384 DEBUGFS_ADD_FILE(eeprom
, data
);
385 DEBUGFS_ADD_FILE(sram
, data
);
386 DEBUGFS_ADD_FILE(log_event
, data
);
387 DEBUGFS_ADD_FILE(stations
, data
);
388 DEBUGFS_ADD_FILE(rx_statistics
, data
);
389 DEBUGFS_ADD_FILE(tx_statistics
, data
);
390 DEBUGFS_ADD_BOOL(disable_sensitivity
, rf
, &priv
->disable_sens_cal
);
391 DEBUGFS_ADD_BOOL(disable_chain_noise
, rf
,
392 &priv
->disable_chain_noise_cal
);
393 DEBUGFS_ADD_BOOL(disable_tx_power
, rf
, &priv
->disable_tx_power_cal
);
397 IWL_ERROR("Can't open the debugfs directory\n");
398 iwl_dbgfs_unregister(priv
);
401 EXPORT_SYMBOL(iwl_dbgfs_register
);
404 * Remove the debugfs files and directories
407 void iwl_dbgfs_unregister(struct iwl_priv
*priv
)
412 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_data_files
.file_eeprom
);
413 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_data_files
.file_rx_statistics
);
414 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_data_files
.file_tx_statistics
);
415 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_data_files
.file_sram
);
416 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_data_files
.file_log_event
);
417 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_data_files
.file_stations
);
418 DEBUGFS_REMOVE(priv
->dbgfs
->dir_data
);
419 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_rf_files
.file_disable_sensitivity
);
420 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_rf_files
.file_disable_chain_noise
);
421 DEBUGFS_REMOVE(priv
->dbgfs
->dbgfs_rf_files
.file_disable_tx_power
);
422 DEBUGFS_REMOVE(priv
->dbgfs
->dir_rf
);
423 DEBUGFS_REMOVE(priv
->dbgfs
->dir_drv
);
427 EXPORT_SYMBOL(iwl_dbgfs_unregister
);