]> err.no Git - linux-2.6/blob - drivers/net/wireless/iwlwifi/iwl-debugfs.c
iwlwifi: generalize iwlwifi init flow
[linux-2.6] / drivers / net / wireless / iwlwifi / iwl-debugfs.c
1 /******************************************************************************
2  *
3  * GPL LICENSE SUMMARY
4  *
5  * Copyright(c) 2008 Intel Corporation. All rights reserved.
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:
25  * Tomas Winkler <tomas.winkler@intel.com>
26  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27  *****************************************************************************/
28
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/debugfs.h>
32
33 #include <linux/ieee80211.h>
34 #include <net/mac80211.h>
35
36
37 #include "iwl-4965.h"
38 #include "iwl-debug.h"
39 #include "iwl-core.h"
40 #include "iwl-io.h"
41
42
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))                                       \
47                 goto err;                                               \
48 } while (0)
49
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))               \
55                 goto err;                                               \
56 } while (0)
57
58 #define DEBUGFS_REMOVE(name)  do {              \
59         debugfs_remove(name);                   \
60         name = NULL;                            \
61 } while (0);
62
63 /* file operation */
64 #define DEBUGFS_READ_FUNC(name)                                         \
65 static ssize_t iwl_dbgfs_##name##_read(struct file *file,               \
66                                         char __user *user_buf,          \
67                                         size_t count, loff_t *ppos);
68
69 #define DEBUGFS_WRITE_FUNC(name)                                        \
70 static ssize_t iwl_dbgfs_##name##_write(struct file *file,              \
71                                         const char __user *user_buf,    \
72                                         size_t count, loff_t *ppos);
73
74
75 static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
76 {
77         file->private_data = inode->i_private;
78         return 0;
79 }
80
81 #define DEBUGFS_READ_FILE_OPS(name)                                     \
82         DEBUGFS_READ_FUNC(name);                                        \
83 static const struct file_operations iwl_dbgfs_##name##_ops = {          \
84         .read = iwl_dbgfs_##name##_read,                                \
85         .open = iwl_dbgfs_open_file_generic,                            \
86 };
87
88 #define DEBUGFS_READ_WRITE_FILE_OPS(name)                               \
89         DEBUGFS_READ_FUNC(name);                                        \
90         DEBUGFS_WRITE_FUNC(name);                                       \
91 static const struct file_operations iwl_dbgfs_##name##_ops = {          \
92         .write = iwl_dbgfs_##name##_write,                              \
93         .read = iwl_dbgfs_##name##_read,                                \
94         .open = iwl_dbgfs_open_file_generic,                            \
95 };
96
97
98 static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
99                                                 char __user *user_buf,
100                                                 size_t count, loff_t *ppos) {
101
102         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
103         char buf[256];
104         int pos = 0;
105
106         pos += sprintf(buf+pos, "mgmt: %u\n", priv->tx_stats[0].cnt);
107         pos += sprintf(buf+pos, "ctrl: %u\n", priv->tx_stats[1].cnt);
108         pos += sprintf(buf+pos, "data: %u\n", priv->tx_stats[2].cnt);
109
110         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
111 }
112
113 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
114                                                 char __user *user_buf,
115                                                 size_t count, loff_t *ppos) {
116
117         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
118         char buf[256];
119         int pos = 0;
120
121         pos += sprintf(buf+pos, "mgmt: %u\n", priv->rx_stats[0].cnt);
122         pos += sprintf(buf+pos, "ctrl: %u\n", priv->rx_stats[1].cnt);
123         pos += sprintf(buf+pos, "data: %u\n", priv->rx_stats[2].cnt);
124
125         return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
126 }
127
128 #define BYTE1_MASK 0x000000ff;
129 #define BYTE2_MASK 0x0000ffff;
130 #define BYTE3_MASK 0x00ffffff;
131 static ssize_t iwl_dbgfs_sram_read(struct file *file,
132                                         char __user *user_buf,
133                                         size_t count, loff_t *ppos)
134 {
135         u32 val;
136         char buf[1024];
137         ssize_t ret;
138         int i;
139         int pos = 0;
140         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
141
142         printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
143         priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
144
145         iwl_grab_nic_access(priv);
146         for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
147                 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
148                                         priv->dbgfs->sram_len - i);
149                 if (i < 4) {
150                         switch (i) {
151                         case 1:
152                                 val &= BYTE1_MASK;
153                                 break;
154                         case 2:
155                                 val &= BYTE2_MASK;
156                                 break;
157                         case 3:
158                                 val &= BYTE3_MASK;
159                                 break;
160                         }
161                 }
162                 pos += sprintf(buf+pos, "0x%08x ", val);
163         }
164         pos += sprintf(buf+pos, "\n");
165         iwl_release_nic_access(priv);
166
167         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
168         return ret;
169 }
170
171 static ssize_t iwl_dbgfs_sram_write(struct file *file,
172                                         const char __user *user_buf,
173                                         size_t count, loff_t *ppos)
174 {
175         struct iwl_priv *priv = file->private_data;
176         char buf[64];
177         int buf_size;
178         u32 offset, len;
179
180         memset(buf, 0, sizeof(buf));
181         buf_size = min(count, sizeof(buf) -  1);
182         if (copy_from_user(buf, user_buf, buf_size))
183                 return -EFAULT;
184
185         if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
186                 priv->dbgfs->sram_offset = offset;
187                 priv->dbgfs->sram_len = len;
188         } else {
189                 priv->dbgfs->sram_offset = 0;
190                 priv->dbgfs->sram_len = 0;
191         }
192
193         return count;
194 }
195
196 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
197                                         size_t count, loff_t *ppos)
198 {
199         struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
200         struct iwl4965_station_entry *station;
201         int max_sta = priv->hw_setting.max_stations;
202         char *buf;
203         int i, j, pos = 0;
204         ssize_t ret;
205         /* Add 30 for initial string */
206         const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
207         DECLARE_MAC_BUF(mac);
208
209         buf = kmalloc(bufsz, GFP_KERNEL);
210         if(!buf)
211                 return -ENOMEM;
212
213         pos += sprintf(buf+pos, "num of stations: %d\n\n",
214                         priv->num_stations);
215
216         for (i = 0; i < max_sta; i++) {
217                 station = &priv->stations[i];
218                 if (station->used) {
219                         pos += sprintf(buf+pos, "station %d:\ngeneral data:\n",
220                                         i+1);
221                         print_mac(mac, station->sta.sta.addr);
222                         pos += sprintf(buf+pos, "id: %u\n",
223                                         station->sta.sta.sta_id);
224                         pos += sprintf(buf+pos, "mode: %u\n",
225                                         station->sta.mode);
226                         pos += sprintf(buf+pos, "flags: 0x%x\n",
227                                         station->sta.station_flags_msk);
228                         pos += sprintf(buf+pos, "ps_status: %u\n",
229                                         station->ps_status);
230
231                         pos += sprintf(buf+pos, "tid data:\n");
232
233                         pos += sprintf(buf+pos, "seq_num\t\ttxq_id\t");
234                         pos += sprintf(buf+pos, "frame_count\twait_for_ba\t");
235                         pos += sprintf(buf+pos, "start_idx\tbitmap0\t");
236                         pos += sprintf(buf+pos, "bitmap1\trate_n_flags\n");
237
238                         for (j = 0; j < MAX_TID_COUNT; j++) {
239                                 pos += sprintf(buf+pos, "[%d]:\t\t%u\t",
240                                                 j, station->tid[j].seq_number);
241                                 pos += sprintf(buf+pos, "%u\t\t%u\t\t%u\t\t",
242                                                 station->tid[j].agg.txq_id,
243                                                 station->tid[j].agg.frame_count,
244                                                 station->tid[j].agg.wait_for_ba);
245                                 pos += sprintf(buf+pos, "%u\t%llu\t%u\n",
246                                                 station->tid[j].agg.start_idx,
247                                                 (unsigned long long)station->tid[j].agg.bitmap,
248                                                 station->tid[j].agg.rate_n_flags);
249                         }
250                         pos += sprintf(buf+pos, "\n");
251                 }
252         }
253
254         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
255         kfree(buf);
256         return ret;
257 }
258
259
260 DEBUGFS_READ_WRITE_FILE_OPS(sram);
261 DEBUGFS_READ_FILE_OPS(stations);
262 DEBUGFS_READ_FILE_OPS(rx_statistics);
263 DEBUGFS_READ_FILE_OPS(tx_statistics);
264
265 /*
266  * Create the debugfs files and directories
267  *
268  */
269 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
270 {
271         struct iwl_debugfs *dbgfs;
272
273         dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
274         if (!dbgfs) {
275                 goto err;
276         }
277
278         priv->dbgfs = dbgfs;
279         dbgfs->name = name;
280         dbgfs->dir_drv = debugfs_create_dir(name, NULL);
281         if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
282                 goto err;
283         }
284
285         DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
286         DEBUGFS_ADD_FILE(sram, data);
287         DEBUGFS_ADD_FILE(stations, data);
288         DEBUGFS_ADD_FILE(rx_statistics, data);
289         DEBUGFS_ADD_FILE(tx_statistics, data);
290
291         return 0;
292
293 err:
294         IWL_ERROR("Can't open the debugfs directory\n");
295         iwl_dbgfs_unregister(priv);
296         return -ENOENT;
297 }
298 EXPORT_SYMBOL(iwl_dbgfs_register);
299
300 /**
301  * Remove the debugfs files and directories
302  *
303  */
304 void iwl_dbgfs_unregister(struct iwl_priv *priv)
305 {
306         if (!(priv->dbgfs))
307                 return;
308
309         DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
310         DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
311         DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
312         DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
313         DEBUGFS_REMOVE(priv->dbgfs->dir_data);
314         DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
315         kfree(priv->dbgfs);
316         priv->dbgfs = NULL;
317 }
318 EXPORT_SYMBOL(iwl_dbgfs_unregister);
319
320