41 #include <linux/slab.h>
42 #include <linux/module.h>
48 #define ADD(buf, off, max, fmt, args...) \
49 off += snprintf(&buf[off], max - off, fmt, ##args);
63 static ssize_t carl9170_debugfs_read(
struct file *
file,
char __user *userbuf,
64 size_t count, loff_t *ppos)
113 static ssize_t carl9170_debugfs_write(
struct file *file,
114 const char __user *userbuf,
size_t count, loff_t *ppos)
155 err = dfops->
write(ar, buf, count);
167 #define __DEBUGFS_DECLARE_FILE(name, _read, _write, _read_bufsize, \
169 static const struct carl9170_debugfs_fops carl_debugfs_##name ##_ops = {\
170 .read_bufsize = _read_bufsize, \
174 .req_dev_state = _dstate, \
176 .open = simple_open, \
177 .read = carl9170_debugfs_read, \
178 .write = carl9170_debugfs_write, \
179 .owner = THIS_MODULE \
183 #define DEBUGFS_DECLARE_FILE(name, _read, _write, _read_bufsize, _attr) \
184 __DEBUGFS_DECLARE_FILE(name, _read, _write, _read_bufsize, \
185 _attr, CARL9170_STARTED) \
187 #define DEBUGFS_DECLARE_RO_FILE(name, _read_bufsize) \
188 DEBUGFS_DECLARE_FILE(name, carl9170_debugfs_##name ##_read, \
189 NULL, _read_bufsize, S_IRUSR)
191 #define DEBUGFS_DECLARE_WO_FILE(name) \
192 DEBUGFS_DECLARE_FILE(name, NULL, carl9170_debugfs_##name ##_write,\
195 #define DEBUGFS_DECLARE_RW_FILE(name, _read_bufsize) \
196 DEBUGFS_DECLARE_FILE(name, carl9170_debugfs_##name ##_read, \
197 carl9170_debugfs_##name ##_write, \
198 _read_bufsize, S_IRUSR | S_IWUSR)
200 #define __DEBUGFS_DECLARE_RW_FILE(name, _read_bufsize, _dstate) \
201 __DEBUGFS_DECLARE_FILE(name, carl9170_debugfs_##name ##_read, \
202 carl9170_debugfs_##name ##_write, \
203 _read_bufsize, S_IRUSR | S_IWUSR, _dstate)
205 #define DEBUGFS_READONLY_FILE(name, _read_bufsize, fmt, value...) \
206 static char *carl9170_debugfs_ ##name ## _read(struct ar9170 *ar, \
207 char *buf, size_t buf_size,\
210 ADD(buf, *len, buf_size, fmt "\n", ##value); \
213 DEBUGFS_DECLARE_RO_FILE(name, _read_bufsize)
215 static char *carl9170_debugfs_mem_usage_read(
struct ar9170 *ar,
char *buf,
218 ADD(buf, *len, bufsize,
"jar: [");
225 ADD(buf, *len, bufsize,
"]\n");
227 ADD(buf, *len, bufsize,
"cookies: used:%3d / total:%3d, allocs:%d\n",
231 ADD(buf, *len, bufsize,
"memory: free:%3d (%3d KiB) / total:%3d KiB)\n",
234 (ar->
fw.mem_blocks * ar->
fw.mem_block_size) / 1024);
242 static char *carl9170_debugfs_qos_stat_read(
struct ar9170 *ar,
char *buf,
248 ADD(buf, *len, bufsize,
"[ VO VI "
252 ADD(buf, *len, bufsize,
"[length/limit length/limit "
253 "length/limit length/limit ]\n"
255 " %3d/%3d %3d/%3d ]\n\n",
261 ADD(buf, *len, bufsize,
"[ total total "
263 "[%10d %10d %10d %10d ]\n\n",
269 ADD(buf, *len, bufsize,
"[ pend/waittx pend/waittx "
270 " pend/waittx pend/waittx]\n"
272 " %3d/%3d %3d/%3d ]\n\n",
286 static void carl9170_debugfs_format_frame(
struct ar9170 *ar,
295 ADD(buf, *off, bufsize,
"%s %p, c:%2x, DA:%pM, sq:%4d, mc:%.4x, "
296 "pc:%.8x, to:%d ms\n", prefix, skb, txc->
s.cookie,
297 ieee80211_get_DA(
hdr), get_seq_h(
hdr),
303 static char *carl9170_debugfs_ampdu_state_read(
struct ar9170 *ar,
char *buf,
314 spin_lock_bh(&iter->
lock);
315 ADD(buf, *len, bufsize,
"Entry: #%2d TID:%1d, BSN:%4d, "
316 "SNX:%4d, HSN:%4d, BAW:%2d, state:%1d, toggles:%d\n",
320 ADD(buf, *len, bufsize,
"\tWindow: [");
325 #define BM_STR_OFF(offset) \
326 ((CARL9170_BAW_BITS - (offset) - 1) / 4 + \
327 (CARL9170_BAW_BITS - (offset) - 1) / 32 + 1)
329 ADD(buf, *len, bufsize,
",W]\n");
332 ADD(buf, *len, bufsize,
"\tBase Seq: %*s\n", offset,
"T");
335 ADD(buf, *len, bufsize,
"\tNext Seq: %*s\n", offset,
"W");
339 ADD(buf, *len, bufsize,
"\tLast Seq: %*s\n", offset,
"N");
341 ADD(buf, *len, bufsize,
"\tPre-Aggregation reorder buffer: "
342 " currently queued:%d\n", skb_queue_len(&iter->
queue));
345 skb_queue_walk(&iter->
queue, skb) {
348 snprintf(prefix,
sizeof(prefix),
"\t\t%3d :",
fc);
349 carl9170_debugfs_format_frame(ar, skb, prefix, buf,
354 spin_unlock_bh(&iter->
lock);
363 static void carl9170_debugfs_queue_dump(
struct ar9170 *ar,
char *buf,
370 spin_lock_bh(&queue->
lock);
371 skb_queue_walk(queue, skb) {
372 snprintf(prefix,
sizeof(prefix),
"%3d :", fc);
373 carl9170_debugfs_format_frame(ar, skb, prefix, buf,
377 spin_unlock_bh(&queue->
lock);
380 #define DEBUGFS_QUEUE_DUMP(q, qi) \
381 static char *carl9170_debugfs_##q ##_##qi ##_read(struct ar9170 *ar, \
382 char *buf, size_t bufsize, ssize_t *len) \
384 carl9170_debugfs_queue_dump(ar, buf, len, bufsize, &ar->q[qi]); \
387 DEBUGFS_DECLARE_RO_FILE(q##_##qi, 8000);
389 static char *carl9170_debugfs_sta_psm_read(
struct ar9170 *ar,
char *buf,
392 ADD(buf, *len, bufsize,
"psm state: %s\n", (ar->
ps.off_override ?
393 "FORCE CAM" : (ar->
ps.state ?
"PSM" :
"CAM")));
395 ADD(buf, *len, bufsize,
"sleep duration: %d ms.\n", ar->
ps.sleep_ms);
396 ADD(buf, *len, bufsize,
"last power-state transition: %d ms ago.\n",
398 ADD(buf, *len, bufsize,
"last CAM->PSM transition: %d ms ago.\n",
405 static char *carl9170_debugfs_tx_stuck_read(
struct ar9170 *ar,
char *buf,
410 for (i = 0; i < ar->
hw->queues; i++) {
411 ADD(buf, *len, bufsize,
"TX queue [%d]: %10d max:%10d ms.\n",
423 static char *carl9170_debugfs_phy_noise_read(
struct ar9170 *ar,
char *buf,
434 ADD(buf, *len, bufsize,
"Chain 0: %10d dBm, ext. chan.:%10d dBm\n",
436 ADD(buf, *len, bufsize,
"Chain 2: %10d dBm, ext. chan.:%10d dBm\n",
443 static char *carl9170_debugfs_vif_dump_read(
struct ar9170 *ar,
char *buf,
449 ADD(buf, *len, bufsize,
"registered VIFs:%d \\ %d\n",
450 ar->
vifs, ar->
fw.vif_num);
452 ADD(buf, *len, bufsize,
"VIF bitmap: [");
457 ADD(buf, *len, bufsize,
"]\n");
462 ADD(buf, *len, bufsize,
"\t%d = [%s VIF, id:%d, type:%x "
463 " mac:%pM %s]\n", i, (carl9170_get_main_vif(ar) == vif ?
464 "Master" :
" Slave"), iter->
id, vif->
type, vif->
addr,
474 #define UPDATE_COUNTER(ar, name) ({ \
475 u32 __tmp[ARRAY_SIZE(name##_regs)]; \
476 unsigned int __i, __err = -ENODEV; \
478 for (__i = 0; __i < ARRAY_SIZE(name##_regs); __i++) { \
479 __tmp[__i] = name##_regs[__i].reg; \
480 ar->debug.stats.name##_counter[__i] = 0; \
483 if (IS_STARTED(ar)) \
484 __err = carl9170_read_mreg(ar, ARRAY_SIZE(name##_regs), \
485 __tmp, ar->debug.stats.name##_counter); \
488 #define TALLY_SUM_UP(ar, name) do { \
491 for (__i = 0; __i < ARRAY_SIZE(name##_regs); __i++) { \
492 ar->debug.stats.name##_sum[__i] += \
493 ar->debug.stats.name##_counter[__i]; \
497 #define DEBUGFS_HW_TALLY_FILE(name, f) \
498 static char *carl9170_debugfs_##name ## _read(struct ar9170 *ar, \
499 char *dum, size_t bufsize, ssize_t *ret) \
502 int i, max_len, err; \
504 max_len = ARRAY_SIZE(name##_regs) * 80; \
505 buf = vmalloc(max_len); \
509 err = UPDATE_COUNTER(ar, name); \
515 TALLY_SUM_UP(ar, name); \
517 for (i = 0; i < ARRAY_SIZE(name##_regs); i++) { \
518 ADD(buf, *ret, max_len, "%22s = %" f "[+%" f "]\n", \
519 name##_regs[i].nreg, ar->debug.stats.name ##_sum[i],\
520 ar->debug.stats.name ##_counter[i]); \
525 DEBUGFS_DECLARE_RO_FILE(name, 0);
527 #define DEBUGFS_HW_REG_FILE(name, f) \
528 static char *carl9170_debugfs_##name ## _read(struct ar9170 *ar, \
529 char *dum, size_t bufsize, ssize_t *ret) \
532 int i, max_len, err; \
534 max_len = ARRAY_SIZE(name##_regs) * 80; \
535 buf = vmalloc(max_len); \
539 err = UPDATE_COUNTER(ar, name); \
545 for (i = 0; i < ARRAY_SIZE(name##_regs); i++) { \
546 ADD(buf, *ret, max_len, "%22s = %" f "\n", \
547 name##_regs[i].nreg, \
548 ar->debug.stats.name##_counter[i]); \
553 DEBUGFS_DECLARE_RO_FILE(name, 0);
555 static ssize_t carl9170_debugfs_hw_ioread32_write(
struct ar9170 *ar,
556 const char *buf,
size_t count)
558 int err = 0,
i,
n = 0, max_len = 32,
res;
581 if ((reg >= 0x280000) || ((reg + (n << 2)) >= 0x280000)) {
591 for (i = 0; i <
n; i++) {
596 ar->debug.ring[ar->debug.ring_tail].reg = reg + (i << 2);
597 ar->debug.ring[ar->debug.ring_tail].value =
tmp;
598 ar->debug.ring_tail++;
603 return err ? err :
count;
606 static char *carl9170_debugfs_hw_ioread32_read(
struct ar9170 *ar,
char *buf,
611 while (ar->debug.ring_head != ar->debug.ring_tail) {
612 ADD(buf, *ret, bufsize,
"%.8x = %.8x\n",
613 ar->debug.ring[ar->debug.ring_head].reg,
614 ar->debug.ring[ar->debug.ring_head].value);
616 ar->debug.ring_head++;
622 ar->debug.ring_head = ar->debug.ring_tail;
627 static ssize_t carl9170_debugfs_bug_write(
struct ar9170 *ar,
const char *buf,
674 static char *carl9170_debugfs_bug_read(
struct ar9170 *ar,
char *buf,
677 ADD(buf, *ret, bufsize,
"[P]hy reinit, [R]estart, [F]ull usb reset, "
679 ADD(buf, *ret, bufsize,
"firmware restarts:%d, last reason:%d\n",
681 ADD(buf, *ret, bufsize,
"phy reinit errors:%d (%d)\n",
683 ADD(buf, *ret, bufsize,
"reported firmware errors:%d\n",
685 ADD(buf, *ret, bufsize,
"reported firmware BUGs:%d\n",
687 ADD(buf, *ret, bufsize,
"pending restart requests:%d\n",
693 static const char *
const erp_modes[] = {
702 static char *carl9170_debugfs_erp_read(
struct ar9170 *ar,
char *buf,
705 ADD(buf, *ret, bufsize,
"ERP Setting: (%d) -> %s\n", ar->
erp_mode,
710 static ssize_t carl9170_debugfs_erp_write(
struct ar9170 *ar,
const char *buf,
718 res =
sscanf(buf,
"%d", &val);
732 static ssize_t carl9170_debugfs_hw_iowrite32_write(
struct ar9170 *ar,
733 const char *buf,
size_t count)
735 int err = 0, max_len = 22,
res;
744 res =
sscanf(buf,
"0x%X 0x%X", ®, &val);
765 return err ? err :
count;
827 ar->
hw->wiphy->debugfsdir);
829 #define DEBUGFS_ADD(name) \
830 debugfs_create_file(#name, carl_debugfs_##name ##_ops.attr, \
832 &carl_debugfs_##name ## _ops.fops);