1/* 2 * This file is part of wl1271 3 * 4 * Copyright (C) 2009 Nokia Corporation 5 * 6 * Contact: Luciano Coelho <luciano.coelho@nokia.com> 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * version 2 as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 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 St, Fifth Floor, Boston, MA 20 * 02110-1301 USA 21 * 22 */ 23 24#include "wl1271_debugfs.h" 25 26#include <linux/skbuff.h> 27#include <linux/slab.h> 28 29#include "wl1271.h" 30#include "wl1271_acx.h" 31#include "wl1271_ps.h" 32#include "wl1271_io.h" 33 34/* ms */ 35#define WL1271_DEBUGFS_STATS_LIFETIME 1000 36 37/* debugfs macros idea from mac80211 */ 38 39#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ 40static ssize_t name## _read(struct file *file, char __user *userbuf, \ 41 size_t count, loff_t *ppos) \ 42{ \ 43 struct wl1271 *wl = file->private_data; \ 44 char buf[buflen]; \ 45 int res; \ 46 \ 47 res = scnprintf(buf, buflen, fmt "\n", ##value); \ 48 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ 49} \ 50 \ 51static const struct file_operations name## _ops = { \ 52 .read = name## _read, \ 53 .open = wl1271_open_file_generic, \ 54}; 55 56#define DEBUGFS_ADD(name, parent) \ 57 wl->debugfs.name = debugfs_create_file(#name, 0400, parent, \ 58 wl, &name## _ops); \ 59 if (IS_ERR(wl->debugfs.name)) { \ 60 ret = PTR_ERR(wl->debugfs.name); \ 61 wl->debugfs.name = NULL; \ 62 goto out; \ 63 } 64 65#define DEBUGFS_DEL(name) \ 66 do { \ 67 debugfs_remove(wl->debugfs.name); \ 68 wl->debugfs.name = NULL; \ 69 } while (0) 70 71#define DEBUGFS_FWSTATS_FILE(sub, name, buflen, fmt) \ 72static ssize_t sub## _ ##name## _read(struct file *file, \ 73 char __user *userbuf, \ 74 size_t count, loff_t *ppos) \ 75{ \ 76 struct wl1271 *wl = file->private_data; \ 77 char buf[buflen]; \ 78 int res; \ 79 \ 80 wl1271_debugfs_update_stats(wl); \ 81 \ 82 res = scnprintf(buf, buflen, fmt "\n", \ 83 wl->stats.fw_stats->sub.name); \ 84 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ 85} \ 86 \ 87static const struct file_operations sub## _ ##name## _ops = { \ 88 .read = sub## _ ##name## _read, \ 89 .open = wl1271_open_file_generic, \ 90}; 91 92#define DEBUGFS_FWSTATS_ADD(sub, name) \ 93 DEBUGFS_ADD(sub## _ ##name, wl->debugfs.fw_statistics) 94 95#define DEBUGFS_FWSTATS_DEL(sub, name) \ 96 DEBUGFS_DEL(sub## _ ##name) 97 98static void wl1271_debugfs_update_stats(struct wl1271 *wl) 99{ 100 int ret; 101 102 mutex_lock(&wl->mutex); 103 104 ret = wl1271_ps_elp_wakeup(wl, false); 105 if (ret < 0) 106 goto out; 107 108 if (wl->state == WL1271_STATE_ON && 109 time_after(jiffies, wl->stats.fw_stats_update + 110 msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) { 111 wl1271_acx_statistics(wl, wl->stats.fw_stats); 112 wl->stats.fw_stats_update = jiffies; 113 } 114 115 wl1271_ps_elp_sleep(wl); 116 117out: 118 mutex_unlock(&wl->mutex); 119} 120 121static int wl1271_open_file_generic(struct inode *inode, struct file *file) 122{ 123 file->private_data = inode->i_private; 124 return 0; 125} 126 127DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u"); 128 129DEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u"); 130DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, 20, "%u"); 131DEBUGFS_FWSTATS_FILE(rx, hw_stuck, 20, "%u"); 132DEBUGFS_FWSTATS_FILE(rx, dropped, 20, "%u"); 133DEBUGFS_FWSTATS_FILE(rx, fcs_err, 20, "%u"); 134DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, 20, "%u"); 135DEBUGFS_FWSTATS_FILE(rx, path_reset, 20, "%u"); 136DEBUGFS_FWSTATS_FILE(rx, reset_counter, 20, "%u"); 137 138DEBUGFS_FWSTATS_FILE(dma, rx_requested, 20, "%u"); 139DEBUGFS_FWSTATS_FILE(dma, rx_errors, 20, "%u"); 140DEBUGFS_FWSTATS_FILE(dma, tx_requested, 20, "%u"); 141DEBUGFS_FWSTATS_FILE(dma, tx_errors, 20, "%u"); 142 143DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, 20, "%u"); 144DEBUGFS_FWSTATS_FILE(isr, fiqs, 20, "%u"); 145DEBUGFS_FWSTATS_FILE(isr, rx_headers, 20, "%u"); 146DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, 20, "%u"); 147DEBUGFS_FWSTATS_FILE(isr, rx_rdys, 20, "%u"); 148DEBUGFS_FWSTATS_FILE(isr, irqs, 20, "%u"); 149DEBUGFS_FWSTATS_FILE(isr, tx_procs, 20, "%u"); 150DEBUGFS_FWSTATS_FILE(isr, decrypt_done, 20, "%u"); 151DEBUGFS_FWSTATS_FILE(isr, dma0_done, 20, "%u"); 152DEBUGFS_FWSTATS_FILE(isr, dma1_done, 20, "%u"); 153DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, 20, "%u"); 154DEBUGFS_FWSTATS_FILE(isr, commands, 20, "%u"); 155DEBUGFS_FWSTATS_FILE(isr, rx_procs, 20, "%u"); 156DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, 20, "%u"); 157DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, 20, "%u"); 158DEBUGFS_FWSTATS_FILE(isr, pci_pm, 20, "%u"); 159DEBUGFS_FWSTATS_FILE(isr, wakeups, 20, "%u"); 160DEBUGFS_FWSTATS_FILE(isr, low_rssi, 20, "%u"); 161 162DEBUGFS_FWSTATS_FILE(wep, addr_key_count, 20, "%u"); 163DEBUGFS_FWSTATS_FILE(wep, default_key_count, 20, "%u"); 164/* skipping wep.reserved */ 165DEBUGFS_FWSTATS_FILE(wep, key_not_found, 20, "%u"); 166DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, 20, "%u"); 167DEBUGFS_FWSTATS_FILE(wep, packets, 20, "%u"); 168DEBUGFS_FWSTATS_FILE(wep, interrupt, 20, "%u"); 169 170DEBUGFS_FWSTATS_FILE(pwr, ps_enter, 20, "%u"); 171DEBUGFS_FWSTATS_FILE(pwr, elp_enter, 20, "%u"); 172DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, 20, "%u"); 173DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, 20, "%u"); 174DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, 20, "%u"); 175DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, 20, "%u"); 176DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, 20, "%u"); 177DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, 20, "%u"); 178DEBUGFS_FWSTATS_FILE(pwr, power_save_off, 20, "%u"); 179DEBUGFS_FWSTATS_FILE(pwr, enable_ps, 20, "%u"); 180DEBUGFS_FWSTATS_FILE(pwr, disable_ps, 20, "%u"); 181DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, 20, "%u"); 182/* skipping cont_miss_bcns_spread for now */ 183DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, 20, "%u"); 184 185DEBUGFS_FWSTATS_FILE(mic, rx_pkts, 20, "%u"); 186DEBUGFS_FWSTATS_FILE(mic, calc_failure, 20, "%u"); 187 188DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, 20, "%u"); 189DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, 20, "%u"); 190DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, 20, "%u"); 191DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, 20, "%u"); 192DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, 20, "%u"); 193DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, 20, "%u"); 194 195DEBUGFS_FWSTATS_FILE(event, heart_beat, 20, "%u"); 196DEBUGFS_FWSTATS_FILE(event, calibration, 20, "%u"); 197DEBUGFS_FWSTATS_FILE(event, rx_mismatch, 20, "%u"); 198DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, 20, "%u"); 199DEBUGFS_FWSTATS_FILE(event, rx_pool, 20, "%u"); 200DEBUGFS_FWSTATS_FILE(event, oom_late, 20, "%u"); 201DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, 20, "%u"); 202DEBUGFS_FWSTATS_FILE(event, tx_stuck, 20, "%u"); 203 204DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, 20, "%u"); 205DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, 20, "%u"); 206DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, 20, "%u"); 207DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, 20, "%u"); 208DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, 20, "%u"); 209DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, 20, "%u"); 210DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, 20, "%u"); 211 212DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, 20, "%u"); 213DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, 20, "%u"); 214DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, 215 20, "%u"); 216DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, 20, "%u"); 217DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, 20, "%u"); 218 219DEBUGFS_READONLY_FILE(retry_count, 20, "%u", wl->stats.retry_count); 220DEBUGFS_READONLY_FILE(excessive_retries, 20, "%u", 221 wl->stats.excessive_retries); 222 223static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf, 224 size_t count, loff_t *ppos) 225{ 226 struct wl1271 *wl = file->private_data; 227 u32 queue_len; 228 char buf[20]; 229 int res; 230 231 queue_len = skb_queue_len(&wl->tx_queue); 232 233 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len); 234 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 235} 236 237static const struct file_operations tx_queue_len_ops = { 238 .read = tx_queue_len_read, 239 .open = wl1271_open_file_generic, 240}; 241 242static ssize_t gpio_power_read(struct file *file, char __user *user_buf, 243 size_t count, loff_t *ppos) 244{ 245 struct wl1271 *wl = file->private_data; 246 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 247 248 int res; 249 char buf[10]; 250 251 res = scnprintf(buf, sizeof(buf), "%d\n", state); 252 253 return simple_read_from_buffer(user_buf, count, ppos, buf, res); 254} 255 256static ssize_t gpio_power_write(struct file *file, 257 const char __user *user_buf, 258 size_t count, loff_t *ppos) 259{ 260 struct wl1271 *wl = file->private_data; 261 char buf[10]; 262 size_t len; 263 unsigned long value; 264 int ret; 265 266 mutex_lock(&wl->mutex); 267 268 len = min(count, sizeof(buf) - 1); 269 if (copy_from_user(buf, user_buf, len)) { 270 ret = -EFAULT; 271 goto out; 272 } 273 buf[len] = '\0'; 274 275 ret = strict_strtoul(buf, 0, &value); 276 if (ret < 0) { 277 wl1271_warning("illegal value in gpio_power"); 278 goto out; 279 } 280 281 if (value) 282 wl1271_power_on(wl); 283 else 284 wl1271_power_off(wl); 285 286out: 287 mutex_unlock(&wl->mutex); 288 return count; 289} 290 291static const struct file_operations gpio_power_ops = { 292 .read = gpio_power_read, 293 .write = gpio_power_write, 294 .open = wl1271_open_file_generic 295}; 296 297static void wl1271_debugfs_delete_files(struct wl1271 *wl) 298{ 299 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow); 300 301 DEBUGFS_FWSTATS_DEL(rx, out_of_mem); 302 DEBUGFS_FWSTATS_DEL(rx, hdr_overflow); 303 DEBUGFS_FWSTATS_DEL(rx, hw_stuck); 304 DEBUGFS_FWSTATS_DEL(rx, dropped); 305 DEBUGFS_FWSTATS_DEL(rx, fcs_err); 306 DEBUGFS_FWSTATS_DEL(rx, xfr_hint_trig); 307 DEBUGFS_FWSTATS_DEL(rx, path_reset); 308 DEBUGFS_FWSTATS_DEL(rx, reset_counter); 309 310 DEBUGFS_FWSTATS_DEL(dma, rx_requested); 311 DEBUGFS_FWSTATS_DEL(dma, rx_errors); 312 DEBUGFS_FWSTATS_DEL(dma, tx_requested); 313 DEBUGFS_FWSTATS_DEL(dma, tx_errors); 314 315 DEBUGFS_FWSTATS_DEL(isr, cmd_cmplt); 316 DEBUGFS_FWSTATS_DEL(isr, fiqs); 317 DEBUGFS_FWSTATS_DEL(isr, rx_headers); 318 DEBUGFS_FWSTATS_DEL(isr, rx_mem_overflow); 319 DEBUGFS_FWSTATS_DEL(isr, rx_rdys); 320 DEBUGFS_FWSTATS_DEL(isr, irqs); 321 DEBUGFS_FWSTATS_DEL(isr, tx_procs); 322 DEBUGFS_FWSTATS_DEL(isr, decrypt_done); 323 DEBUGFS_FWSTATS_DEL(isr, dma0_done); 324 DEBUGFS_FWSTATS_DEL(isr, dma1_done); 325 DEBUGFS_FWSTATS_DEL(isr, tx_exch_complete); 326 DEBUGFS_FWSTATS_DEL(isr, commands); 327 DEBUGFS_FWSTATS_DEL(isr, rx_procs); 328 DEBUGFS_FWSTATS_DEL(isr, hw_pm_mode_changes); 329 DEBUGFS_FWSTATS_DEL(isr, host_acknowledges); 330 DEBUGFS_FWSTATS_DEL(isr, pci_pm); 331 DEBUGFS_FWSTATS_DEL(isr, wakeups); 332 DEBUGFS_FWSTATS_DEL(isr, low_rssi); 333 334 DEBUGFS_FWSTATS_DEL(wep, addr_key_count); 335 DEBUGFS_FWSTATS_DEL(wep, default_key_count); 336 /* skipping wep.reserved */ 337 DEBUGFS_FWSTATS_DEL(wep, key_not_found); 338 DEBUGFS_FWSTATS_DEL(wep, decrypt_fail); 339 DEBUGFS_FWSTATS_DEL(wep, packets); 340 DEBUGFS_FWSTATS_DEL(wep, interrupt); 341 342 DEBUGFS_FWSTATS_DEL(pwr, ps_enter); 343 DEBUGFS_FWSTATS_DEL(pwr, elp_enter); 344 DEBUGFS_FWSTATS_DEL(pwr, missing_bcns); 345 DEBUGFS_FWSTATS_DEL(pwr, wake_on_host); 346 DEBUGFS_FWSTATS_DEL(pwr, wake_on_timer_exp); 347 DEBUGFS_FWSTATS_DEL(pwr, tx_with_ps); 348 DEBUGFS_FWSTATS_DEL(pwr, tx_without_ps); 349 DEBUGFS_FWSTATS_DEL(pwr, rcvd_beacons); 350 DEBUGFS_FWSTATS_DEL(pwr, power_save_off); 351 DEBUGFS_FWSTATS_DEL(pwr, enable_ps); 352 DEBUGFS_FWSTATS_DEL(pwr, disable_ps); 353 DEBUGFS_FWSTATS_DEL(pwr, fix_tsf_ps); 354 /* skipping cont_miss_bcns_spread for now */ 355 DEBUGFS_FWSTATS_DEL(pwr, rcvd_awake_beacons); 356 357 DEBUGFS_FWSTATS_DEL(mic, rx_pkts); 358 DEBUGFS_FWSTATS_DEL(mic, calc_failure); 359 360 DEBUGFS_FWSTATS_DEL(aes, encrypt_fail); 361 DEBUGFS_FWSTATS_DEL(aes, decrypt_fail); 362 DEBUGFS_FWSTATS_DEL(aes, encrypt_packets); 363 DEBUGFS_FWSTATS_DEL(aes, decrypt_packets); 364 DEBUGFS_FWSTATS_DEL(aes, encrypt_interrupt); 365 DEBUGFS_FWSTATS_DEL(aes, decrypt_interrupt); 366 367 DEBUGFS_FWSTATS_DEL(event, heart_beat); 368 DEBUGFS_FWSTATS_DEL(event, calibration); 369 DEBUGFS_FWSTATS_DEL(event, rx_mismatch); 370 DEBUGFS_FWSTATS_DEL(event, rx_mem_empty); 371 DEBUGFS_FWSTATS_DEL(event, rx_pool); 372 DEBUGFS_FWSTATS_DEL(event, oom_late); 373 DEBUGFS_FWSTATS_DEL(event, phy_transmit_error); 374 DEBUGFS_FWSTATS_DEL(event, tx_stuck); 375 376 DEBUGFS_FWSTATS_DEL(ps, pspoll_timeouts); 377 DEBUGFS_FWSTATS_DEL(ps, upsd_timeouts); 378 DEBUGFS_FWSTATS_DEL(ps, upsd_max_sptime); 379 DEBUGFS_FWSTATS_DEL(ps, upsd_max_apturn); 380 DEBUGFS_FWSTATS_DEL(ps, pspoll_max_apturn); 381 DEBUGFS_FWSTATS_DEL(ps, pspoll_utilization); 382 DEBUGFS_FWSTATS_DEL(ps, upsd_utilization); 383 384 DEBUGFS_FWSTATS_DEL(rxpipe, rx_prep_beacon_drop); 385 DEBUGFS_FWSTATS_DEL(rxpipe, descr_host_int_trig_rx_data); 386 DEBUGFS_FWSTATS_DEL(rxpipe, beacon_buffer_thres_host_int_trig_rx_data); 387 DEBUGFS_FWSTATS_DEL(rxpipe, missed_beacon_host_int_trig_rx_data); 388 DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data); 389 390 DEBUGFS_DEL(tx_queue_len); 391 DEBUGFS_DEL(retry_count); 392 DEBUGFS_DEL(excessive_retries); 393 394 DEBUGFS_DEL(gpio_power); 395} 396 397static int wl1271_debugfs_add_files(struct wl1271 *wl) 398{ 399 int ret = 0; 400 401 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow); 402 403 DEBUGFS_FWSTATS_ADD(rx, out_of_mem); 404 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow); 405 DEBUGFS_FWSTATS_ADD(rx, hw_stuck); 406 DEBUGFS_FWSTATS_ADD(rx, dropped); 407 DEBUGFS_FWSTATS_ADD(rx, fcs_err); 408 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig); 409 DEBUGFS_FWSTATS_ADD(rx, path_reset); 410 DEBUGFS_FWSTATS_ADD(rx, reset_counter); 411 412 DEBUGFS_FWSTATS_ADD(dma, rx_requested); 413 DEBUGFS_FWSTATS_ADD(dma, rx_errors); 414 DEBUGFS_FWSTATS_ADD(dma, tx_requested); 415 DEBUGFS_FWSTATS_ADD(dma, tx_errors); 416 417 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt); 418 DEBUGFS_FWSTATS_ADD(isr, fiqs); 419 DEBUGFS_FWSTATS_ADD(isr, rx_headers); 420 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow); 421 DEBUGFS_FWSTATS_ADD(isr, rx_rdys); 422 DEBUGFS_FWSTATS_ADD(isr, irqs); 423 DEBUGFS_FWSTATS_ADD(isr, tx_procs); 424 DEBUGFS_FWSTATS_ADD(isr, decrypt_done); 425 DEBUGFS_FWSTATS_ADD(isr, dma0_done); 426 DEBUGFS_FWSTATS_ADD(isr, dma1_done); 427 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete); 428 DEBUGFS_FWSTATS_ADD(isr, commands); 429 DEBUGFS_FWSTATS_ADD(isr, rx_procs); 430 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes); 431 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges); 432 DEBUGFS_FWSTATS_ADD(isr, pci_pm); 433 DEBUGFS_FWSTATS_ADD(isr, wakeups); 434 DEBUGFS_FWSTATS_ADD(isr, low_rssi); 435 436 DEBUGFS_FWSTATS_ADD(wep, addr_key_count); 437 DEBUGFS_FWSTATS_ADD(wep, default_key_count); 438 /* skipping wep.reserved */ 439 DEBUGFS_FWSTATS_ADD(wep, key_not_found); 440 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail); 441 DEBUGFS_FWSTATS_ADD(wep, packets); 442 DEBUGFS_FWSTATS_ADD(wep, interrupt); 443 444 DEBUGFS_FWSTATS_ADD(pwr, ps_enter); 445 DEBUGFS_FWSTATS_ADD(pwr, elp_enter); 446 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns); 447 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host); 448 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp); 449 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps); 450 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps); 451 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons); 452 DEBUGFS_FWSTATS_ADD(pwr, power_save_off); 453 DEBUGFS_FWSTATS_ADD(pwr, enable_ps); 454 DEBUGFS_FWSTATS_ADD(pwr, disable_ps); 455 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps); 456 /* skipping cont_miss_bcns_spread for now */ 457 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons); 458 459 DEBUGFS_FWSTATS_ADD(mic, rx_pkts); 460 DEBUGFS_FWSTATS_ADD(mic, calc_failure); 461 462 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail); 463 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail); 464 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets); 465 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets); 466 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt); 467 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt); 468 469 DEBUGFS_FWSTATS_ADD(event, heart_beat); 470 DEBUGFS_FWSTATS_ADD(event, calibration); 471 DEBUGFS_FWSTATS_ADD(event, rx_mismatch); 472 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty); 473 DEBUGFS_FWSTATS_ADD(event, rx_pool); 474 DEBUGFS_FWSTATS_ADD(event, oom_late); 475 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error); 476 DEBUGFS_FWSTATS_ADD(event, tx_stuck); 477 478 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts); 479 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts); 480 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime); 481 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn); 482 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn); 483 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization); 484 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization); 485 486 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop); 487 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data); 488 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data); 489 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data); 490 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data); 491 492 DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir); 493 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir); 494 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir); 495 496 DEBUGFS_ADD(gpio_power, wl->debugfs.rootdir); 497 498out: 499 if (ret < 0) 500 wl1271_debugfs_delete_files(wl); 501 502 return ret; 503} 504 505void wl1271_debugfs_reset(struct wl1271 *wl) 506{ 507 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats)); 508 wl->stats.retry_count = 0; 509 wl->stats.excessive_retries = 0; 510} 511 512int wl1271_debugfs_init(struct wl1271 *wl) 513{ 514 int ret; 515 516 wl->debugfs.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL); 517 518 if (IS_ERR(wl->debugfs.rootdir)) { 519 ret = PTR_ERR(wl->debugfs.rootdir); 520 wl->debugfs.rootdir = NULL; 521 goto err; 522 } 523 524 wl->debugfs.fw_statistics = debugfs_create_dir("fw-statistics", 525 wl->debugfs.rootdir); 526 527 if (IS_ERR(wl->debugfs.fw_statistics)) { 528 ret = PTR_ERR(wl->debugfs.fw_statistics); 529 wl->debugfs.fw_statistics = NULL; 530 goto err_root; 531 } 532 533 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats), 534 GFP_KERNEL); 535 536 if (!wl->stats.fw_stats) { 537 ret = -ENOMEM; 538 goto err_fw; 539 } 540 541 wl->stats.fw_stats_update = jiffies; 542 543 ret = wl1271_debugfs_add_files(wl); 544 545 if (ret < 0) 546 goto err_file; 547 548 return 0; 549 550err_file: 551 kfree(wl->stats.fw_stats); 552 wl->stats.fw_stats = NULL; 553 554err_fw: 555 debugfs_remove(wl->debugfs.fw_statistics); 556 wl->debugfs.fw_statistics = NULL; 557 558err_root: 559 debugfs_remove(wl->debugfs.rootdir); 560 wl->debugfs.rootdir = NULL; 561 562err: 563 return ret; 564} 565 566void wl1271_debugfs_exit(struct wl1271 *wl) 567{ 568 wl1271_debugfs_delete_files(wl); 569 570 kfree(wl->stats.fw_stats); 571 wl->stats.fw_stats = NULL; 572 573 debugfs_remove(wl->debugfs.fw_statistics); 574 wl->debugfs.fw_statistics = NULL; 575 576 debugfs_remove(wl->debugfs.rootdir); 577 wl->debugfs.rootdir = NULL; 578 579} 580