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