d3ff33c71aa5bbd2074d4d64c2a92c41ab144c91
[linux-2.6.git] / drivers / net / wireless / ath / ath9k / htc_drv_debug.c
1 /*
2  * Copyright (c) 2010-2011 Atheros Communications Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include "htc.h"
18
19 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
20 {
21         file->private_data = inode->i_private;
22         return 0;
23 }
24
25 static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf,
26                                        size_t count, loff_t *ppos)
27 {
28         struct ath9k_htc_priv *priv = file->private_data;
29         struct ath9k_htc_target_int_stats cmd_rsp;
30         char buf[512];
31         unsigned int len = 0;
32         int ret = 0;
33
34         memset(&cmd_rsp, 0, sizeof(cmd_rsp));
35
36         ath9k_htc_ps_wakeup(priv);
37
38         WMI_CMD(WMI_INT_STATS_CMDID);
39         if (ret) {
40                 ath9k_htc_ps_restore(priv);
41                 return -EINVAL;
42         }
43
44         ath9k_htc_ps_restore(priv);
45
46         len += snprintf(buf + len, sizeof(buf) - len,
47                         "%20s : %10u\n", "RX",
48                         be32_to_cpu(cmd_rsp.rx));
49
50         len += snprintf(buf + len, sizeof(buf) - len,
51                         "%20s : %10u\n", "RXORN",
52                         be32_to_cpu(cmd_rsp.rxorn));
53
54         len += snprintf(buf + len, sizeof(buf) - len,
55                         "%20s : %10u\n", "RXEOL",
56                         be32_to_cpu(cmd_rsp.rxeol));
57
58         len += snprintf(buf + len, sizeof(buf) - len,
59                         "%20s : %10u\n", "TXURN",
60                         be32_to_cpu(cmd_rsp.txurn));
61
62         len += snprintf(buf + len, sizeof(buf) - len,
63                         "%20s : %10u\n", "TXTO",
64                         be32_to_cpu(cmd_rsp.txto));
65
66         len += snprintf(buf + len, sizeof(buf) - len,
67                         "%20s : %10u\n", "CST",
68                         be32_to_cpu(cmd_rsp.cst));
69
70         if (len > sizeof(buf))
71                 len = sizeof(buf);
72
73         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
74 }
75
76 static const struct file_operations fops_tgt_int_stats = {
77         .read = read_file_tgt_int_stats,
78         .open = ath9k_debugfs_open,
79         .owner = THIS_MODULE,
80         .llseek = default_llseek,
81 };
82
83 static ssize_t read_file_tgt_tx_stats(struct file *file, char __user *user_buf,
84                                       size_t count, loff_t *ppos)
85 {
86         struct ath9k_htc_priv *priv = file->private_data;
87         struct ath9k_htc_target_tx_stats cmd_rsp;
88         char buf[512];
89         unsigned int len = 0;
90         int ret = 0;
91
92         memset(&cmd_rsp, 0, sizeof(cmd_rsp));
93
94         ath9k_htc_ps_wakeup(priv);
95
96         WMI_CMD(WMI_TX_STATS_CMDID);
97         if (ret) {
98                 ath9k_htc_ps_restore(priv);
99                 return -EINVAL;
100         }
101
102         ath9k_htc_ps_restore(priv);
103
104         len += snprintf(buf + len, sizeof(buf) - len,
105                         "%20s : %10u\n", "Xretries",
106                         be32_to_cpu(cmd_rsp.xretries));
107
108         len += snprintf(buf + len, sizeof(buf) - len,
109                         "%20s : %10u\n", "FifoErr",
110                         be32_to_cpu(cmd_rsp.fifoerr));
111
112         len += snprintf(buf + len, sizeof(buf) - len,
113                         "%20s : %10u\n", "Filtered",
114                         be32_to_cpu(cmd_rsp.filtered));
115
116         len += snprintf(buf + len, sizeof(buf) - len,
117                         "%20s : %10u\n", "TimerExp",
118                         be32_to_cpu(cmd_rsp.timer_exp));
119
120         len += snprintf(buf + len, sizeof(buf) - len,
121                         "%20s : %10u\n", "ShortRetries",
122                         be32_to_cpu(cmd_rsp.shortretries));
123
124         len += snprintf(buf + len, sizeof(buf) - len,
125                         "%20s : %10u\n", "LongRetries",
126                         be32_to_cpu(cmd_rsp.longretries));
127
128         len += snprintf(buf + len, sizeof(buf) - len,
129                         "%20s : %10u\n", "QueueNull",
130                         be32_to_cpu(cmd_rsp.qnull));
131
132         len += snprintf(buf + len, sizeof(buf) - len,
133                         "%20s : %10u\n", "EncapFail",
134                         be32_to_cpu(cmd_rsp.encap_fail));
135
136         len += snprintf(buf + len, sizeof(buf) - len,
137                         "%20s : %10u\n", "NoBuf",
138                         be32_to_cpu(cmd_rsp.nobuf));
139
140         if (len > sizeof(buf))
141                 len = sizeof(buf);
142
143         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
144 }
145
146 static const struct file_operations fops_tgt_tx_stats = {
147         .read = read_file_tgt_tx_stats,
148         .open = ath9k_debugfs_open,
149         .owner = THIS_MODULE,
150         .llseek = default_llseek,
151 };
152
153 static ssize_t read_file_tgt_rx_stats(struct file *file, char __user *user_buf,
154                                       size_t count, loff_t *ppos)
155 {
156         struct ath9k_htc_priv *priv = file->private_data;
157         struct ath9k_htc_target_rx_stats cmd_rsp;
158         char buf[512];
159         unsigned int len = 0;
160         int ret = 0;
161
162         memset(&cmd_rsp, 0, sizeof(cmd_rsp));
163
164         ath9k_htc_ps_wakeup(priv);
165
166         WMI_CMD(WMI_RX_STATS_CMDID);
167         if (ret) {
168                 ath9k_htc_ps_restore(priv);
169                 return -EINVAL;
170         }
171
172         ath9k_htc_ps_restore(priv);
173
174         len += snprintf(buf + len, sizeof(buf) - len,
175                         "%20s : %10u\n", "NoBuf",
176                         be32_to_cpu(cmd_rsp.nobuf));
177
178         len += snprintf(buf + len, sizeof(buf) - len,
179                         "%20s : %10u\n", "HostSend",
180                         be32_to_cpu(cmd_rsp.host_send));
181
182         len += snprintf(buf + len, sizeof(buf) - len,
183                         "%20s : %10u\n", "HostDone",
184                         be32_to_cpu(cmd_rsp.host_done));
185
186         if (len > sizeof(buf))
187                 len = sizeof(buf);
188
189         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
190 }
191
192 static const struct file_operations fops_tgt_rx_stats = {
193         .read = read_file_tgt_rx_stats,
194         .open = ath9k_debugfs_open,
195         .owner = THIS_MODULE,
196         .llseek = default_llseek,
197 };
198
199 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
200                               size_t count, loff_t *ppos)
201 {
202         struct ath9k_htc_priv *priv = file->private_data;
203         char buf[512];
204         unsigned int len = 0;
205
206         len += snprintf(buf + len, sizeof(buf) - len,
207                         "%20s : %10u\n", "Buffers queued",
208                         priv->debug.tx_stats.buf_queued);
209         len += snprintf(buf + len, sizeof(buf) - len,
210                         "%20s : %10u\n", "Buffers completed",
211                         priv->debug.tx_stats.buf_completed);
212         len += snprintf(buf + len, sizeof(buf) - len,
213                         "%20s : %10u\n", "SKBs queued",
214                         priv->debug.tx_stats.skb_queued);
215         len += snprintf(buf + len, sizeof(buf) - len,
216                         "%20s : %10u\n", "SKBs success",
217                         priv->debug.tx_stats.skb_success);
218         len += snprintf(buf + len, sizeof(buf) - len,
219                         "%20s : %10u\n", "SKBs failed",
220                         priv->debug.tx_stats.skb_failed);
221         len += snprintf(buf + len, sizeof(buf) - len,
222                         "%20s : %10u\n", "CAB queued",
223                         priv->debug.tx_stats.cab_queued);
224
225         len += snprintf(buf + len, sizeof(buf) - len,
226                         "%20s : %10u\n", "BE queued",
227                         priv->debug.tx_stats.queue_stats[WME_AC_BE]);
228         len += snprintf(buf + len, sizeof(buf) - len,
229                         "%20s : %10u\n", "BK queued",
230                         priv->debug.tx_stats.queue_stats[WME_AC_BK]);
231         len += snprintf(buf + len, sizeof(buf) - len,
232                         "%20s : %10u\n", "VI queued",
233                         priv->debug.tx_stats.queue_stats[WME_AC_VI]);
234         len += snprintf(buf + len, sizeof(buf) - len,
235                         "%20s : %10u\n", "VO queued",
236                         priv->debug.tx_stats.queue_stats[WME_AC_VO]);
237
238         if (len > sizeof(buf))
239                 len = sizeof(buf);
240
241         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
242 }
243
244 static const struct file_operations fops_xmit = {
245         .read = read_file_xmit,
246         .open = ath9k_debugfs_open,
247         .owner = THIS_MODULE,
248         .llseek = default_llseek,
249 };
250
251 void ath9k_htc_err_stat_rx(struct ath9k_htc_priv *priv,
252                            struct ath_htc_rx_status *rxs)
253 {
254 #define RX_PHY_ERR_INC(c) priv->debug.rx_stats.err_phy_stats[c]++
255
256         if (rxs->rs_status & ATH9K_RXERR_CRC)
257                 priv->debug.rx_stats.err_crc++;
258         if (rxs->rs_status & ATH9K_RXERR_DECRYPT)
259                 priv->debug.rx_stats.err_decrypt_crc++;
260         if (rxs->rs_status & ATH9K_RXERR_MIC)
261                 priv->debug.rx_stats.err_mic++;
262         if (rxs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
263                 priv->debug.rx_stats.err_pre_delim++;
264         if (rxs->rs_status & ATH9K_RX_DELIM_CRC_POST)
265                 priv->debug.rx_stats.err_post_delim++;
266         if (rxs->rs_status & ATH9K_RX_DECRYPT_BUSY)
267                 priv->debug.rx_stats.err_decrypt_busy++;
268
269         if (rxs->rs_status & ATH9K_RXERR_PHY) {
270                 priv->debug.rx_stats.err_phy++;
271                 if (rxs->rs_phyerr < ATH9K_PHYERR_MAX)
272                         RX_PHY_ERR_INC(rxs->rs_phyerr);
273         }
274
275 #undef RX_PHY_ERR_INC
276 }
277
278 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
279                               size_t count, loff_t *ppos)
280 {
281 #define PHY_ERR(s, p)                                                   \
282         len += snprintf(buf + len, size - len, "%20s : %10u\n", s,      \
283                         priv->debug.rx_stats.err_phy_stats[p]);
284
285         struct ath9k_htc_priv *priv = file->private_data;
286         char *buf;
287         unsigned int len = 0, size = 1500;
288         ssize_t retval = 0;
289
290         buf = kzalloc(size, GFP_KERNEL);
291         if (buf == NULL)
292                 return -ENOMEM;
293
294         len += snprintf(buf + len, size - len,
295                         "%20s : %10u\n", "SKBs allocated",
296                         priv->debug.rx_stats.skb_allocated);
297         len += snprintf(buf + len, size - len,
298                         "%20s : %10u\n", "SKBs completed",
299                         priv->debug.rx_stats.skb_completed);
300         len += snprintf(buf + len, size - len,
301                         "%20s : %10u\n", "SKBs Dropped",
302                         priv->debug.rx_stats.skb_dropped);
303
304         len += snprintf(buf + len, size - len,
305                         "%20s : %10u\n", "CRC ERR",
306                         priv->debug.rx_stats.err_crc);
307         len += snprintf(buf + len, size - len,
308                         "%20s : %10u\n", "DECRYPT CRC ERR",
309                         priv->debug.rx_stats.err_decrypt_crc);
310         len += snprintf(buf + len, size - len,
311                         "%20s : %10u\n", "MIC ERR",
312                         priv->debug.rx_stats.err_mic);
313         len += snprintf(buf + len, size - len,
314                         "%20s : %10u\n", "PRE-DELIM CRC ERR",
315                         priv->debug.rx_stats.err_pre_delim);
316         len += snprintf(buf + len, size - len,
317                         "%20s : %10u\n", "POST-DELIM CRC ERR",
318                         priv->debug.rx_stats.err_post_delim);
319         len += snprintf(buf + len, size - len,
320                         "%20s : %10u\n", "DECRYPT BUSY ERR",
321                         priv->debug.rx_stats.err_decrypt_busy);
322         len += snprintf(buf + len, size - len,
323                         "%20s : %10u\n", "TOTAL PHY ERR",
324                         priv->debug.rx_stats.err_phy);
325
326
327         PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
328         PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
329         PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
330         PHY_ERR("RATE", ATH9K_PHYERR_RATE);
331         PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
332         PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
333         PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
334         PHY_ERR("TOR", ATH9K_PHYERR_TOR);
335         PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
336         PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
337         PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
338         PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
339         PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
340         PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
341         PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
342         PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
343         PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
344         PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
345         PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
346         PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
347         PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
348         PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
349         PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
350         PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
351         PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
352         PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
353
354         if (len > size)
355                 len = size;
356
357         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
358         kfree(buf);
359
360         return retval;
361
362 #undef PHY_ERR
363 }
364
365 static const struct file_operations fops_recv = {
366         .read = read_file_recv,
367         .open = ath9k_debugfs_open,
368         .owner = THIS_MODULE,
369         .llseek = default_llseek,
370 };
371
372 static ssize_t read_file_slot(struct file *file, char __user *user_buf,
373                               size_t count, loff_t *ppos)
374 {
375         struct ath9k_htc_priv *priv = file->private_data;
376         char buf[512];
377         unsigned int len = 0;
378
379         spin_lock_bh(&priv->tx.tx_lock);
380
381         len += snprintf(buf + len, sizeof(buf) - len, "TX slot bitmap : ");
382
383         len += bitmap_scnprintf(buf + len, sizeof(buf) - len,
384                                priv->tx.tx_slot, MAX_TX_BUF_NUM);
385
386         len += snprintf(buf + len, sizeof(buf) - len, "\n");
387
388         len += snprintf(buf + len, sizeof(buf) - len,
389                         "Used slots     : %d\n",
390                         bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM));
391
392         spin_unlock_bh(&priv->tx.tx_lock);
393
394         if (len > sizeof(buf))
395                 len = sizeof(buf);
396
397         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
398 }
399
400 static const struct file_operations fops_slot = {
401         .read = read_file_slot,
402         .open = ath9k_debugfs_open,
403         .owner = THIS_MODULE,
404         .llseek = default_llseek,
405 };
406
407 static ssize_t read_file_queue(struct file *file, char __user *user_buf,
408                                size_t count, loff_t *ppos)
409 {
410         struct ath9k_htc_priv *priv = file->private_data;
411         char buf[512];
412         unsigned int len = 0;
413
414         len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
415                         "Mgmt endpoint", skb_queue_len(&priv->tx.mgmt_ep_queue));
416
417         len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
418                         "Cab endpoint", skb_queue_len(&priv->tx.cab_ep_queue));
419
420         len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
421                         "Data BE endpoint", skb_queue_len(&priv->tx.data_be_queue));
422
423         len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
424                         "Data BK endpoint", skb_queue_len(&priv->tx.data_bk_queue));
425
426         len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
427                         "Data VI endpoint", skb_queue_len(&priv->tx.data_vi_queue));
428
429         len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
430                         "Data VO endpoint", skb_queue_len(&priv->tx.data_vo_queue));
431
432         len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
433                         "Failed queue", skb_queue_len(&priv->tx.tx_failed));
434
435         spin_lock_bh(&priv->tx.tx_lock);
436         len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
437                         "Queued count", priv->tx.queued_cnt);
438         spin_unlock_bh(&priv->tx.tx_lock);
439
440         if (len > sizeof(buf))
441                 len = sizeof(buf);
442
443         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
444
445 }
446
447 static const struct file_operations fops_queue = {
448         .read = read_file_queue,
449         .open = ath9k_debugfs_open,
450         .owner = THIS_MODULE,
451         .llseek = default_llseek,
452 };
453
454 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
455                                size_t count, loff_t *ppos)
456 {
457         struct ath9k_htc_priv *priv = file->private_data;
458         struct ath_common *common = ath9k_hw_common(priv->ah);
459         char buf[32];
460         unsigned int len;
461
462         len = sprintf(buf, "0x%08x\n", common->debug_mask);
463         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
464 }
465
466 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
467                                 size_t count, loff_t *ppos)
468 {
469         struct ath9k_htc_priv *priv = file->private_data;
470         struct ath_common *common = ath9k_hw_common(priv->ah);
471         unsigned long mask;
472         char buf[32];
473         ssize_t len;
474
475         len = min(count, sizeof(buf) - 1);
476         if (copy_from_user(buf, user_buf, len))
477                 return -EFAULT;
478
479         buf[len] = '\0';
480         if (strict_strtoul(buf, 0, &mask))
481                 return -EINVAL;
482
483         common->debug_mask = mask;
484         return count;
485 }
486
487 static const struct file_operations fops_debug = {
488         .read = read_file_debug,
489         .write = write_file_debug,
490         .open = ath9k_debugfs_open,
491         .owner = THIS_MODULE,
492         .llseek = default_llseek,
493 };
494
495 static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
496                                      size_t count, loff_t *ppos)
497 {
498         struct ath9k_htc_priv *priv = file->private_data;
499         struct ath_common *common = ath9k_hw_common(priv->ah);
500         struct base_eep_header *pBase = NULL;
501         unsigned int len = 0, size = 1500;
502         ssize_t retval = 0;
503         char *buf;
504
505         /*
506          * This can be done since all the 3 EEPROM families have the
507          * same base header upto a certain point, and we are interested in
508          * the data only upto that point.
509          */
510
511         if (AR_SREV_9271(priv->ah))
512                 pBase = (struct base_eep_header *)
513                         &priv->ah->eeprom.map4k.baseEepHeader;
514         else if (priv->ah->hw_version.usbdev == AR9280_USB)
515                 pBase = (struct base_eep_header *)
516                         &priv->ah->eeprom.def.baseEepHeader;
517         else if (priv->ah->hw_version.usbdev == AR9287_USB)
518                 pBase = (struct base_eep_header *)
519                         &priv->ah->eeprom.map9287.baseEepHeader;
520
521         if (pBase == NULL) {
522                 ath_err(common, "Unknown EEPROM type\n");
523                 return 0;
524         }
525
526         buf = kzalloc(size, GFP_KERNEL);
527         if (buf == NULL)
528                 return -ENOMEM;
529
530         len += snprintf(buf + len, size - len,
531                         "%20s : %10d\n", "Major Version",
532                         pBase->version >> 12);
533         len += snprintf(buf + len, size - len,
534                         "%20s : %10d\n", "Minor Version",
535                         pBase->version & 0xFFF);
536         len += snprintf(buf + len, size - len,
537                         "%20s : %10d\n", "Checksum",
538                         pBase->checksum);
539         len += snprintf(buf + len, size - len,
540                         "%20s : %10d\n", "Length",
541                         pBase->length);
542         len += snprintf(buf + len, size - len,
543                         "%20s : %10d\n", "RegDomain1",
544                         pBase->regDmn[0]);
545         len += snprintf(buf + len, size - len,
546                         "%20s : %10d\n", "RegDomain2",
547                         pBase->regDmn[1]);
548         len += snprintf(buf + len, size - len,
549                         "%20s : %10d\n",
550                         "TX Mask", pBase->txMask);
551         len += snprintf(buf + len, size - len,
552                         "%20s : %10d\n",
553                         "RX Mask", pBase->rxMask);
554         len += snprintf(buf + len, size - len,
555                         "%20s : %10d\n",
556                         "Allow 5GHz",
557                         !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
558         len += snprintf(buf + len, size - len,
559                         "%20s : %10d\n",
560                         "Allow 2GHz",
561                         !!(pBase->opCapFlags & AR5416_OPFLAGS_11G));
562         len += snprintf(buf + len, size - len,
563                         "%20s : %10d\n",
564                         "Disable 2GHz HT20",
565                         !!(pBase->opCapFlags & AR5416_OPFLAGS_N_2G_HT20));
566         len += snprintf(buf + len, size - len,
567                         "%20s : %10d\n",
568                         "Disable 2GHz HT40",
569                         !!(pBase->opCapFlags & AR5416_OPFLAGS_N_2G_HT40));
570         len += snprintf(buf + len, size - len,
571                         "%20s : %10d\n",
572                         "Disable 5Ghz HT20",
573                         !!(pBase->opCapFlags & AR5416_OPFLAGS_N_5G_HT20));
574         len += snprintf(buf + len, size - len,
575                         "%20s : %10d\n",
576                         "Disable 5Ghz HT40",
577                         !!(pBase->opCapFlags & AR5416_OPFLAGS_N_5G_HT40));
578         len += snprintf(buf + len, size - len,
579                         "%20s : %10d\n",
580                         "Big Endian",
581                         !!(pBase->eepMisc & 0x01));
582         len += snprintf(buf + len, size - len,
583                         "%20s : %10d\n",
584                         "Cal Bin Major Ver",
585                         (pBase->binBuildNumber >> 24) & 0xFF);
586         len += snprintf(buf + len, size - len,
587                         "%20s : %10d\n",
588                         "Cal Bin Minor Ver",
589                         (pBase->binBuildNumber >> 16) & 0xFF);
590         len += snprintf(buf + len, size - len,
591                         "%20s : %10d\n",
592                         "Cal Bin Build",
593                         (pBase->binBuildNumber >> 8) & 0xFF);
594
595         /*
596          * UB91 specific data.
597          */
598         if (AR_SREV_9271(priv->ah)) {
599                 struct base_eep_header_4k *pBase4k =
600                         &priv->ah->eeprom.map4k.baseEepHeader;
601
602                 len += snprintf(buf + len, size - len,
603                                 "%20s : %10d\n",
604                                 "TX Gain type",
605                                 pBase4k->txGainType);
606         }
607
608         /*
609          * UB95 specific data.
610          */
611         if (priv->ah->hw_version.usbdev == AR9287_USB) {
612                 struct base_eep_ar9287_header *pBase9287 =
613                         &priv->ah->eeprom.map9287.baseEepHeader;
614
615                 len += snprintf(buf + len, size - len,
616                                 "%20s : %10ddB\n",
617                                 "Power Table Offset",
618                                 pBase9287->pwrTableOffset);
619
620                 len += snprintf(buf + len, size - len,
621                                 "%20s : %10d\n",
622                                 "OpenLoop Power Ctrl",
623                                 pBase9287->openLoopPwrCntl);
624         }
625
626         len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
627                         pBase->macAddr);
628         if (len > size)
629                 len = size;
630
631         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
632         kfree(buf);
633
634         return retval;
635 }
636
637 static const struct file_operations fops_base_eeprom = {
638         .read = read_file_base_eeprom,
639         .open = ath9k_debugfs_open,
640         .owner = THIS_MODULE,
641         .llseek = default_llseek,
642 };
643
644 static ssize_t read_4k_modal_eeprom(struct file *file,
645                                     char __user *user_buf,
646                                     size_t count, loff_t *ppos)
647 {
648 #define PR_EEP(_s, _val)                                                \
649         do {                                                            \
650                 len += snprintf(buf + len, size - len, "%20s : %10d\n", \
651                                 _s, (_val));                            \
652         } while (0)
653
654         struct ath9k_htc_priv *priv = file->private_data;
655         struct modal_eep_4k_header *pModal = &priv->ah->eeprom.map4k.modalHeader;
656         unsigned int len = 0, size = 2048;
657         ssize_t retval = 0;
658         char *buf;
659
660         buf = kzalloc(size, GFP_KERNEL);
661         if (buf == NULL)
662                 return -ENOMEM;
663
664         PR_EEP("Chain0 Ant. Control", pModal->antCtrlChain[0]);
665         PR_EEP("Ant. Common Control", pModal->antCtrlCommon);
666         PR_EEP("Chain0 Ant. Gain", pModal->antennaGainCh[0]);
667         PR_EEP("Switch Settle", pModal->switchSettling);
668         PR_EEP("Chain0 TxRxAtten", pModal->txRxAttenCh[0]);
669         PR_EEP("Chain0 RxTxMargin", pModal->rxTxMarginCh[0]);
670         PR_EEP("ADC Desired size", pModal->adcDesiredSize);
671         PR_EEP("PGA Desired size", pModal->pgaDesiredSize);
672         PR_EEP("Chain0 xlna Gain", pModal->xlnaGainCh[0]);
673         PR_EEP("txEndToXpaOff", pModal->txEndToXpaOff);
674         PR_EEP("txEndToRxOn", pModal->txEndToRxOn);
675         PR_EEP("txFrameToXpaOn", pModal->txFrameToXpaOn);
676         PR_EEP("CCA Threshold)", pModal->thresh62);
677         PR_EEP("Chain0 NF Threshold", pModal->noiseFloorThreshCh[0]);
678         PR_EEP("xpdGain", pModal->xpdGain);
679         PR_EEP("External PD", pModal->xpd);
680         PR_EEP("Chain0 I Coefficient", pModal->iqCalICh[0]);
681         PR_EEP("Chain0 Q Coefficient", pModal->iqCalQCh[0]);
682         PR_EEP("pdGainOverlap", pModal->pdGainOverlap);
683         PR_EEP("O/D Bias Version", pModal->version);
684         PR_EEP("CCK OutputBias", pModal->ob_0);
685         PR_EEP("BPSK OutputBias", pModal->ob_1);
686         PR_EEP("QPSK OutputBias", pModal->ob_2);
687         PR_EEP("16QAM OutputBias", pModal->ob_3);
688         PR_EEP("64QAM OutputBias", pModal->ob_4);
689         PR_EEP("CCK Driver1_Bias", pModal->db1_0);
690         PR_EEP("BPSK Driver1_Bias", pModal->db1_1);
691         PR_EEP("QPSK Driver1_Bias", pModal->db1_2);
692         PR_EEP("16QAM Driver1_Bias", pModal->db1_3);
693         PR_EEP("64QAM Driver1_Bias", pModal->db1_4);
694         PR_EEP("CCK Driver2_Bias", pModal->db2_0);
695         PR_EEP("BPSK Driver2_Bias", pModal->db2_1);
696         PR_EEP("QPSK Driver2_Bias", pModal->db2_2);
697         PR_EEP("16QAM Driver2_Bias", pModal->db2_3);
698         PR_EEP("64QAM Driver2_Bias", pModal->db2_4);
699         PR_EEP("xPA Bias Level", pModal->xpaBiasLvl);
700         PR_EEP("txFrameToDataStart", pModal->txFrameToDataStart);
701         PR_EEP("txFrameToPaOn", pModal->txFrameToPaOn);
702         PR_EEP("HT40 Power Inc.", pModal->ht40PowerIncForPdadc);
703         PR_EEP("Chain0 bswAtten", pModal->bswAtten[0]);
704         PR_EEP("Chain0 bswMargin", pModal->bswMargin[0]);
705         PR_EEP("HT40 Switch Settle", pModal->swSettleHt40);
706         PR_EEP("Chain0 xatten2Db", pModal->xatten2Db[0]);
707         PR_EEP("Chain0 xatten2Margin", pModal->xatten2Margin[0]);
708         PR_EEP("Ant. Diversity ctl1", pModal->antdiv_ctl1);
709         PR_EEP("Ant. Diversity ctl2", pModal->antdiv_ctl2);
710         PR_EEP("TX Diversity", pModal->tx_diversity);
711
712         if (len > size)
713                 len = size;
714
715         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
716         kfree(buf);
717
718         return retval;
719
720 #undef PR_EEP
721 }
722
723 static ssize_t read_def_modal_eeprom(struct file *file,
724                                      char __user *user_buf,
725                                      size_t count, loff_t *ppos)
726 {
727 #define PR_EEP(_s, _val)                                                \
728         do {                                                            \
729                 if (pBase->opCapFlags & AR5416_OPFLAGS_11G) {           \
730                         pModal = &priv->ah->eeprom.def.modalHeader[1];  \
731                         len += snprintf(buf + len, size - len, "%20s : %8d%7s", \
732                                         _s, (_val), "|");               \
733                 }                                                       \
734                 if (pBase->opCapFlags & AR5416_OPFLAGS_11A) {           \
735                         pModal = &priv->ah->eeprom.def.modalHeader[0];  \
736                         len += snprintf(buf + len, size - len, "%9d\n", \
737                                         (_val));                        \
738                 }                                                       \
739         } while (0)
740
741         struct ath9k_htc_priv *priv = file->private_data;
742         struct base_eep_header *pBase = &priv->ah->eeprom.def.baseEepHeader;
743         struct modal_eep_header *pModal = NULL;
744         unsigned int len = 0, size = 3500;
745         ssize_t retval = 0;
746         char *buf;
747
748         buf = kzalloc(size, GFP_KERNEL);
749         if (buf == NULL)
750                 return -ENOMEM;
751
752         len += snprintf(buf + len, size - len,
753                         "%31s %15s\n", "2G", "5G");
754         len += snprintf(buf + len, size - len,
755                         "%32s %16s\n", "====", "====\n");
756
757         PR_EEP("Chain0 Ant. Control", pModal->antCtrlChain[0]);
758         PR_EEP("Chain1 Ant. Control", pModal->antCtrlChain[1]);
759         PR_EEP("Chain2 Ant. Control", pModal->antCtrlChain[2]);
760         PR_EEP("Ant. Common Control", pModal->antCtrlCommon);
761         PR_EEP("Chain0 Ant. Gain", pModal->antennaGainCh[0]);
762         PR_EEP("Chain1 Ant. Gain", pModal->antennaGainCh[1]);
763         PR_EEP("Chain2 Ant. Gain", pModal->antennaGainCh[2]);
764         PR_EEP("Switch Settle", pModal->switchSettling);
765         PR_EEP("Chain0 TxRxAtten", pModal->txRxAttenCh[0]);
766         PR_EEP("Chain1 TxRxAtten", pModal->txRxAttenCh[1]);
767         PR_EEP("Chain2 TxRxAtten", pModal->txRxAttenCh[2]);
768         PR_EEP("Chain0 RxTxMargin", pModal->rxTxMarginCh[0]);
769         PR_EEP("Chain1 RxTxMargin", pModal->rxTxMarginCh[1]);
770         PR_EEP("Chain2 RxTxMargin", pModal->rxTxMarginCh[2]);
771         PR_EEP("ADC Desired size", pModal->adcDesiredSize);
772         PR_EEP("PGA Desired size", pModal->pgaDesiredSize);
773         PR_EEP("Chain0 xlna Gain", pModal->xlnaGainCh[0]);
774         PR_EEP("Chain1 xlna Gain", pModal->xlnaGainCh[1]);
775         PR_EEP("Chain2 xlna Gain", pModal->xlnaGainCh[2]);
776         PR_EEP("txEndToXpaOff", pModal->txEndToXpaOff);
777         PR_EEP("txEndToRxOn", pModal->txEndToRxOn);
778         PR_EEP("txFrameToXpaOn", pModal->txFrameToXpaOn);
779         PR_EEP("CCA Threshold)", pModal->thresh62);
780         PR_EEP("Chain0 NF Threshold", pModal->noiseFloorThreshCh[0]);
781         PR_EEP("Chain1 NF Threshold", pModal->noiseFloorThreshCh[1]);
782         PR_EEP("Chain2 NF Threshold", pModal->noiseFloorThreshCh[2]);
783         PR_EEP("xpdGain", pModal->xpdGain);
784         PR_EEP("External PD", pModal->xpd);
785         PR_EEP("Chain0 I Coefficient", pModal->iqCalICh[0]);
786         PR_EEP("Chain1 I Coefficient", pModal->iqCalICh[1]);
787         PR_EEP("Chain2 I Coefficient", pModal->iqCalICh[2]);
788         PR_EEP("Chain0 Q Coefficient", pModal->iqCalQCh[0]);
789         PR_EEP("Chain1 Q Coefficient", pModal->iqCalQCh[1]);
790         PR_EEP("Chain2 Q Coefficient", pModal->iqCalQCh[2]);
791         PR_EEP("pdGainOverlap", pModal->pdGainOverlap);
792         PR_EEP("Chain0 OutputBias", pModal->ob);
793         PR_EEP("Chain0 DriverBias", pModal->db);
794         PR_EEP("xPA Bias Level", pModal->xpaBiasLvl);
795         PR_EEP("2chain pwr decrease", pModal->pwrDecreaseFor2Chain);
796         PR_EEP("3chain pwr decrease", pModal->pwrDecreaseFor3Chain);
797         PR_EEP("txFrameToDataStart", pModal->txFrameToDataStart);
798         PR_EEP("txFrameToPaOn", pModal->txFrameToPaOn);
799         PR_EEP("HT40 Power Inc.", pModal->ht40PowerIncForPdadc);
800         PR_EEP("Chain0 bswAtten", pModal->bswAtten[0]);
801         PR_EEP("Chain1 bswAtten", pModal->bswAtten[1]);
802         PR_EEP("Chain2 bswAtten", pModal->bswAtten[2]);
803         PR_EEP("Chain0 bswMargin", pModal->bswMargin[0]);
804         PR_EEP("Chain1 bswMargin", pModal->bswMargin[1]);
805         PR_EEP("Chain2 bswMargin", pModal->bswMargin[2]);
806         PR_EEP("HT40 Switch Settle", pModal->swSettleHt40);
807         PR_EEP("Chain0 xatten2Db", pModal->xatten2Db[0]);
808         PR_EEP("Chain1 xatten2Db", pModal->xatten2Db[1]);
809         PR_EEP("Chain2 xatten2Db", pModal->xatten2Db[2]);
810         PR_EEP("Chain0 xatten2Margin", pModal->xatten2Margin[0]);
811         PR_EEP("Chain1 xatten2Margin", pModal->xatten2Margin[1]);
812         PR_EEP("Chain2 xatten2Margin", pModal->xatten2Margin[2]);
813         PR_EEP("Chain1 OutputBias", pModal->ob_ch1);
814         PR_EEP("Chain1 DriverBias", pModal->db_ch1);
815         PR_EEP("LNA Control", pModal->lna_ctl);
816         PR_EEP("XPA Bias Freq0", pModal->xpaBiasLvlFreq[0]);
817         PR_EEP("XPA Bias Freq1", pModal->xpaBiasLvlFreq[1]);
818         PR_EEP("XPA Bias Freq2", pModal->xpaBiasLvlFreq[2]);
819
820         if (len > size)
821                 len = size;
822
823         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
824         kfree(buf);
825
826         return retval;
827
828 #undef PR_EEP
829 }
830
831 static ssize_t read_9287_modal_eeprom(struct file *file,
832                                       char __user *user_buf,
833                                       size_t count, loff_t *ppos)
834 {
835 #define PR_EEP(_s, _val)                                                \
836         do {                                                            \
837                 len += snprintf(buf + len, size - len, "%20s : %10d\n", \
838                                 _s, (_val));                            \
839         } while (0)
840
841         struct ath9k_htc_priv *priv = file->private_data;
842         struct modal_eep_ar9287_header *pModal = &priv->ah->eeprom.map9287.modalHeader;
843         unsigned int len = 0, size = 3000;
844         ssize_t retval = 0;
845         char *buf;
846
847         buf = kzalloc(size, GFP_KERNEL);
848         if (buf == NULL)
849                 return -ENOMEM;
850
851         PR_EEP("Chain0 Ant. Control", pModal->antCtrlChain[0]);
852         PR_EEP("Chain1 Ant. Control", pModal->antCtrlChain[1]);
853         PR_EEP("Ant. Common Control", pModal->antCtrlCommon);
854         PR_EEP("Chain0 Ant. Gain", pModal->antennaGainCh[0]);
855         PR_EEP("Chain1 Ant. Gain", pModal->antennaGainCh[1]);
856         PR_EEP("Switch Settle", pModal->switchSettling);
857         PR_EEP("Chain0 TxRxAtten", pModal->txRxAttenCh[0]);
858         PR_EEP("Chain1 TxRxAtten", pModal->txRxAttenCh[1]);
859         PR_EEP("Chain0 RxTxMargin", pModal->rxTxMarginCh[0]);
860         PR_EEP("Chain1 RxTxMargin", pModal->rxTxMarginCh[1]);
861         PR_EEP("ADC Desired size", pModal->adcDesiredSize);
862         PR_EEP("txEndToXpaOff", pModal->txEndToXpaOff);
863         PR_EEP("txEndToRxOn", pModal->txEndToRxOn);
864         PR_EEP("txFrameToXpaOn", pModal->txFrameToXpaOn);
865         PR_EEP("CCA Threshold)", pModal->thresh62);
866         PR_EEP("Chain0 NF Threshold", pModal->noiseFloorThreshCh[0]);
867         PR_EEP("Chain1 NF Threshold", pModal->noiseFloorThreshCh[1]);
868         PR_EEP("xpdGain", pModal->xpdGain);
869         PR_EEP("External PD", pModal->xpd);
870         PR_EEP("Chain0 I Coefficient", pModal->iqCalICh[0]);
871         PR_EEP("Chain1 I Coefficient", pModal->iqCalICh[1]);
872         PR_EEP("Chain0 Q Coefficient", pModal->iqCalQCh[0]);
873         PR_EEP("Chain1 Q Coefficient", pModal->iqCalQCh[1]);
874         PR_EEP("pdGainOverlap", pModal->pdGainOverlap);
875         PR_EEP("xPA Bias Level", pModal->xpaBiasLvl);
876         PR_EEP("txFrameToDataStart", pModal->txFrameToDataStart);
877         PR_EEP("txFrameToPaOn", pModal->txFrameToPaOn);
878         PR_EEP("HT40 Power Inc.", pModal->ht40PowerIncForPdadc);
879         PR_EEP("Chain0 bswAtten", pModal->bswAtten[0]);
880         PR_EEP("Chain1 bswAtten", pModal->bswAtten[1]);
881         PR_EEP("Chain0 bswMargin", pModal->bswMargin[0]);
882         PR_EEP("Chain1 bswMargin", pModal->bswMargin[1]);
883         PR_EEP("HT40 Switch Settle", pModal->swSettleHt40);
884         PR_EEP("AR92x7 Version", pModal->version);
885         PR_EEP("DriverBias1", pModal->db1);
886         PR_EEP("DriverBias2", pModal->db1);
887         PR_EEP("CCK OutputBias", pModal->ob_cck);
888         PR_EEP("PSK OutputBias", pModal->ob_psk);
889         PR_EEP("QAM OutputBias", pModal->ob_qam);
890         PR_EEP("PAL_OFF OutputBias", pModal->ob_pal_off);
891
892         if (len > size)
893                 len = size;
894
895         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
896         kfree(buf);
897
898         return retval;
899
900 #undef PR_EEP
901 }
902
903 static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
904                                       size_t count, loff_t *ppos)
905 {
906         struct ath9k_htc_priv *priv = file->private_data;
907
908         if (AR_SREV_9271(priv->ah))
909                 return read_4k_modal_eeprom(file, user_buf, count, ppos);
910         else if (priv->ah->hw_version.usbdev == AR9280_USB)
911                 return read_def_modal_eeprom(file, user_buf, count, ppos);
912         else if (priv->ah->hw_version.usbdev == AR9287_USB)
913                 return read_9287_modal_eeprom(file, user_buf, count, ppos);
914
915         return 0;
916 }
917
918 static const struct file_operations fops_modal_eeprom = {
919         .read = read_file_modal_eeprom,
920         .open = ath9k_debugfs_open,
921         .owner = THIS_MODULE,
922         .llseek = default_llseek,
923 };
924
925 int ath9k_htc_init_debug(struct ath_hw *ah)
926 {
927         struct ath_common *common = ath9k_hw_common(ah);
928         struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
929
930         priv->debug.debugfs_phy = debugfs_create_dir(KBUILD_MODNAME,
931                                              priv->hw->wiphy->debugfsdir);
932         if (!priv->debug.debugfs_phy)
933                 return -ENOMEM;
934
935         debugfs_create_file("tgt_int_stats", S_IRUSR, priv->debug.debugfs_phy,
936                             priv, &fops_tgt_int_stats);
937         debugfs_create_file("tgt_tx_stats", S_IRUSR, priv->debug.debugfs_phy,
938                             priv, &fops_tgt_tx_stats);
939         debugfs_create_file("tgt_rx_stats", S_IRUSR, priv->debug.debugfs_phy,
940                             priv, &fops_tgt_rx_stats);
941         debugfs_create_file("xmit", S_IRUSR, priv->debug.debugfs_phy,
942                             priv, &fops_xmit);
943         debugfs_create_file("recv", S_IRUSR, priv->debug.debugfs_phy,
944                             priv, &fops_recv);
945         debugfs_create_file("slot", S_IRUSR, priv->debug.debugfs_phy,
946                             priv, &fops_slot);
947         debugfs_create_file("queue", S_IRUSR, priv->debug.debugfs_phy,
948                             priv, &fops_queue);
949         debugfs_create_file("debug", S_IRUSR | S_IWUSR, priv->debug.debugfs_phy,
950                             priv, &fops_debug);
951         debugfs_create_file("base_eeprom", S_IRUSR, priv->debug.debugfs_phy,
952                             priv, &fops_base_eeprom);
953         debugfs_create_file("modal_eeprom", S_IRUSR, priv->debug.debugfs_phy,
954                             priv, &fops_modal_eeprom);
955
956         return 0;
957 }