2 * Intel Wireless Multicomm 3200 WiFi driver
4 * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com>
5 * Samuel Ortiz <samuel.ortiz@intel.com>
6 * Zhu Yi <yi.zhu@intel.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <linux/kernel.h>
25 #include <linux/bitops.h>
26 #include <linux/debugfs.h>
36 } iwm_debug_module[__IWM_DM_NR] = {
37 {IWM_DM_BOOT, "boot"},
39 {IWM_DM_SDIO, "sdio"},
43 {IWM_DM_MLME, "mlme"},
45 {IWM_DM_WEXT, "wext"},
48 #define add_dbg_module(dbg, name, id, initlevel) \
51 dbg.dbg_module[id] = (initlevel); \
52 d = debugfs_create_x8(name, 0600, dbg.dbgdir, \
53 &(dbg.dbg_module[id])); \
55 dbg.dbg_module_dentries[id] = d; \
58 static int iwm_debugfs_u32_read(void *data, u64 *val)
60 struct iwm_priv *iwm = data;
62 *val = iwm->dbg.dbg_level;
66 static int iwm_debugfs_dbg_level_write(void *data, u64 val)
68 struct iwm_priv *iwm = data;
71 iwm->dbg.dbg_level = val;
73 for (i = 0; i < __IWM_DM_NR; i++)
74 iwm->dbg.dbg_module[i] = val;
78 DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_level,
79 iwm_debugfs_u32_read, iwm_debugfs_dbg_level_write,
82 static int iwm_debugfs_dbg_modules_write(void *data, u64 val)
84 struct iwm_priv *iwm = data;
87 iwm->dbg.dbg_modules = val;
89 for (i = 0; i < __IWM_DM_NR; i++)
90 iwm->dbg.dbg_module[i] = 0;
92 for_each_bit(bit, &iwm->dbg.dbg_modules, __IWM_DM_NR)
93 iwm->dbg.dbg_module[bit] = iwm->dbg.dbg_level;
97 DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_modules,
98 iwm_debugfs_u32_read, iwm_debugfs_dbg_modules_write,
101 static int iwm_txrx_open(struct inode *inode, struct file *filp)
103 filp->private_data = inode->i_private;
108 static ssize_t iwm_debugfs_txq_read(struct file *filp, char __user *buffer,
109 size_t count, loff_t *ppos)
111 struct iwm_priv *iwm = filp->private_data;
113 int i, buf_len = 4096;
119 if (count < sizeof(buf))
122 buf = kzalloc(buf_len, GFP_KERNEL);
126 for (i = 0; i < IWM_TX_QUEUES; i++) {
127 struct iwm_tx_queue *txq = &iwm->txq[i];
132 spin_lock_irqsave(&txq->queue.lock, flags);
134 skb = (struct sk_buff *)&txq->queue;
136 len += snprintf(buf + len, buf_len - len, "TXQ #%d\n", i);
137 len += snprintf(buf + len, buf_len - len, "\tStopped: %d\n",
138 __netif_subqueue_stopped(iwm_to_ndev(iwm),
140 len += snprintf(buf + len, buf_len - len, "\tConcat count:%d\n",
142 len += snprintf(buf + len, buf_len - len, "\tQueue len: %d\n",
143 skb_queue_len(&txq->queue));
144 for (j = 0; j < skb_queue_len(&txq->queue); j++) {
145 struct iwm_tx_info *tx_info;
148 tx_info = skb_to_tx_info(skb);
150 len += snprintf(buf + len, buf_len - len,
152 len += snprintf(buf + len, buf_len - len,
153 "\t\tsta: %d\n", tx_info->sta);
154 len += snprintf(buf + len, buf_len - len,
155 "\t\tcolor: %d\n", tx_info->color);
156 len += snprintf(buf + len, buf_len - len,
157 "\t\ttid: %d\n", tx_info->tid);
160 spin_unlock_irqrestore(&txq->queue.lock, flags);
163 ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
169 static ssize_t iwm_debugfs_tx_credit_read(struct file *filp,
171 size_t count, loff_t *ppos)
173 struct iwm_priv *iwm = filp->private_data;
174 struct iwm_tx_credit *credit = &iwm->tx_credit;
176 int i, buf_len = 4096;
182 if (count < sizeof(buf))
185 buf = kzalloc(buf_len, GFP_KERNEL);
189 len += snprintf(buf + len, buf_len - len,
190 "NR pools: %d\n", credit->pool_nr);
191 len += snprintf(buf + len, buf_len - len,
192 "pools map: 0x%lx\n", credit->full_pools_map);
194 len += snprintf(buf + len, buf_len - len, "\n### POOLS ###\n");
195 for (i = 0; i < IWM_MACS_OUT_GROUPS; i++) {
196 len += snprintf(buf + len, buf_len - len,
197 "pools entry #%d\n", i);
198 len += snprintf(buf + len, buf_len - len,
200 credit->pools[i].id);
201 len += snprintf(buf + len, buf_len - len,
203 credit->pools[i].sid);
204 len += snprintf(buf + len, buf_len - len,
206 credit->pools[i].min_pages);
207 len += snprintf(buf + len, buf_len - len,
209 credit->pools[i].max_pages);
210 len += snprintf(buf + len, buf_len - len,
211 "\talloc_pages: %d\n",
212 credit->pools[i].alloc_pages);
213 len += snprintf(buf + len, buf_len - len,
214 "\tfreed_pages: %d\n",
215 credit->pools[i].total_freed_pages);
218 len += snprintf(buf + len, buf_len - len, "\n### SPOOLS ###\n");
219 for (i = 0; i < IWM_MACS_OUT_SGROUPS; i++) {
220 len += snprintf(buf + len, buf_len - len,
221 "spools entry #%d\n", i);
222 len += snprintf(buf + len, buf_len - len,
224 credit->spools[i].id);
225 len += snprintf(buf + len, buf_len - len,
227 credit->spools[i].max_pages);
228 len += snprintf(buf + len, buf_len - len,
229 "\talloc_pages: %d\n",
230 credit->spools[i].alloc_pages);
234 ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
240 static ssize_t iwm_debugfs_rx_ticket_read(struct file *filp,
242 size_t count, loff_t *ppos)
244 struct iwm_priv *iwm = filp->private_data;
245 struct iwm_rx_ticket_node *ticket, *next;
247 int buf_len = 4096, i;
253 if (count < sizeof(buf))
256 buf = kzalloc(buf_len, GFP_KERNEL);
260 list_for_each_entry_safe(ticket, next, &iwm->rx_tickets, node) {
261 len += snprintf(buf + len, buf_len - len, "Ticket #%d\n",
263 len += snprintf(buf + len, buf_len - len, "\taction: 0x%x\n",
264 ticket->ticket->action);
265 len += snprintf(buf + len, buf_len - len, "\tflags: 0x%x\n",
266 ticket->ticket->flags);
269 for (i = 0; i < IWM_RX_ID_HASH; i++) {
270 struct iwm_rx_packet *packet, *nxt;
271 struct list_head *pkt_list = &iwm->rx_packets[i];
272 if (!list_empty(pkt_list)) {
273 len += snprintf(buf + len, buf_len - len,
274 "Packet hash #%d\n", i);
275 list_for_each_entry_safe(packet, nxt, pkt_list, node) {
276 len += snprintf(buf + len, buf_len - len,
279 len += snprintf(buf + len, buf_len - len,
280 "\tPacket length: %lu\n",
286 ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
293 static const struct file_operations iwm_debugfs_txq_fops = {
294 .owner = THIS_MODULE,
295 .open = iwm_txrx_open,
296 .read = iwm_debugfs_txq_read,
299 static const struct file_operations iwm_debugfs_tx_credit_fops = {
300 .owner = THIS_MODULE,
301 .open = iwm_txrx_open,
302 .read = iwm_debugfs_tx_credit_read,
305 static const struct file_operations iwm_debugfs_rx_ticket_fops = {
306 .owner = THIS_MODULE,
307 .open = iwm_txrx_open,
308 .read = iwm_debugfs_rx_ticket_read,
311 int iwm_debugfs_init(struct iwm_priv *iwm)
316 iwm->dbg.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
317 result = PTR_ERR(iwm->dbg.rootdir);
318 if (!result || IS_ERR(iwm->dbg.rootdir)) {
319 if (result == -ENODEV) {
320 IWM_ERR(iwm, "DebugFS (CONFIG_DEBUG_FS) not "
321 "enabled in kernel config\n");
322 result = 0; /* No debugfs support */
324 IWM_ERR(iwm, "Couldn't create rootdir: %d\n", result);
328 snprintf(devdir, sizeof(devdir), "%s", wiphy_name(iwm_to_wiphy(iwm)));
330 iwm->dbg.devdir = debugfs_create_dir(devdir, iwm->dbg.rootdir);
331 result = PTR_ERR(iwm->dbg.devdir);
332 if (IS_ERR(iwm->dbg.devdir) && (result != -ENODEV)) {
333 IWM_ERR(iwm, "Couldn't create devdir: %d\n", result);
337 iwm->dbg.dbgdir = debugfs_create_dir("debug", iwm->dbg.devdir);
338 result = PTR_ERR(iwm->dbg.dbgdir);
339 if (IS_ERR(iwm->dbg.dbgdir) && (result != -ENODEV)) {
340 IWM_ERR(iwm, "Couldn't create dbgdir: %d\n", result);
344 iwm->dbg.rxdir = debugfs_create_dir("rx", iwm->dbg.devdir);
345 result = PTR_ERR(iwm->dbg.rxdir);
346 if (IS_ERR(iwm->dbg.rxdir) && (result != -ENODEV)) {
347 IWM_ERR(iwm, "Couldn't create rx dir: %d\n", result);
351 iwm->dbg.txdir = debugfs_create_dir("tx", iwm->dbg.devdir);
352 result = PTR_ERR(iwm->dbg.txdir);
353 if (IS_ERR(iwm->dbg.txdir) && (result != -ENODEV)) {
354 IWM_ERR(iwm, "Couldn't create tx dir: %d\n", result);
358 iwm->dbg.busdir = debugfs_create_dir("bus", iwm->dbg.devdir);
359 result = PTR_ERR(iwm->dbg.busdir);
360 if (IS_ERR(iwm->dbg.busdir) && (result != -ENODEV)) {
361 IWM_ERR(iwm, "Couldn't create bus dir: %d\n", result);
365 if (iwm->bus_ops->debugfs_init) {
366 result = iwm->bus_ops->debugfs_init(iwm, iwm->dbg.busdir);
368 IWM_ERR(iwm, "Couldn't create bus entry: %d\n", result);
374 iwm->dbg.dbg_level = IWM_DL_NONE;
375 iwm->dbg.dbg_level_dentry =
376 debugfs_create_file("level", 0200, iwm->dbg.dbgdir, iwm,
377 &fops_iwm_dbg_level);
378 result = PTR_ERR(iwm->dbg.dbg_level_dentry);
379 if (IS_ERR(iwm->dbg.dbg_level_dentry) && (result != -ENODEV)) {
380 IWM_ERR(iwm, "Couldn't create dbg_level: %d\n", result);
385 iwm->dbg.dbg_modules = IWM_DM_DEFAULT;
386 iwm->dbg.dbg_modules_dentry =
387 debugfs_create_file("modules", 0200, iwm->dbg.dbgdir, iwm,
388 &fops_iwm_dbg_modules);
389 result = PTR_ERR(iwm->dbg.dbg_modules_dentry);
390 if (IS_ERR(iwm->dbg.dbg_modules_dentry) && (result != -ENODEV)) {
391 IWM_ERR(iwm, "Couldn't create dbg_modules: %d\n", result);
395 for (i = 0; i < __IWM_DM_NR; i++)
396 add_dbg_module(iwm->dbg, iwm_debug_module[i].name,
397 iwm_debug_module[i].id, IWM_DL_DEFAULT);
399 iwm->dbg.txq_dentry = debugfs_create_file("queues", 0200,
401 &iwm_debugfs_txq_fops);
402 result = PTR_ERR(iwm->dbg.txq_dentry);
403 if (IS_ERR(iwm->dbg.txq_dentry) && (result != -ENODEV)) {
404 IWM_ERR(iwm, "Couldn't create tx queue: %d\n", result);
408 iwm->dbg.tx_credit_dentry = debugfs_create_file("credits", 0200,
410 &iwm_debugfs_tx_credit_fops);
411 result = PTR_ERR(iwm->dbg.tx_credit_dentry);
412 if (IS_ERR(iwm->dbg.tx_credit_dentry) && (result != -ENODEV)) {
413 IWM_ERR(iwm, "Couldn't create tx credit: %d\n", result);
417 iwm->dbg.rx_ticket_dentry = debugfs_create_file("tickets", 0200,
419 &iwm_debugfs_rx_ticket_fops);
420 result = PTR_ERR(iwm->dbg.rx_ticket_dentry);
421 if (IS_ERR(iwm->dbg.rx_ticket_dentry) && (result != -ENODEV)) {
422 IWM_ERR(iwm, "Couldn't create rx ticket: %d\n", result);
432 void iwm_debugfs_exit(struct iwm_priv *iwm)
436 for (i = 0; i < __IWM_DM_NR; i++)
437 debugfs_remove(iwm->dbg.dbg_module_dentries[i]);
439 debugfs_remove(iwm->dbg.dbg_modules_dentry);
440 debugfs_remove(iwm->dbg.dbg_level_dentry);
441 debugfs_remove(iwm->dbg.txq_dentry);
442 debugfs_remove(iwm->dbg.tx_credit_dentry);
443 debugfs_remove(iwm->dbg.rx_ticket_dentry);
444 if (iwm->bus_ops->debugfs_exit)
445 iwm->bus_ops->debugfs_exit(iwm);
447 debugfs_remove(iwm->dbg.busdir);
448 debugfs_remove(iwm->dbg.dbgdir);
449 debugfs_remove(iwm->dbg.txdir);
450 debugfs_remove(iwm->dbg.rxdir);
451 debugfs_remove(iwm->dbg.devdir);
452 debugfs_remove(iwm->dbg.rootdir);