440-ath5k_channel_bw_debugfs.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. This adds a bwmode debugfs file which can be used to set alternate
  2. channel operating bandwidths. Only tested with AR5413 and only at
  3. 5 and 20 mhz channels.
  4. Signed-off-by: Pat Erley <pat-lkml at erley.org>
  5. ---
  6. Other devices will need to be added to the switch in write_file_bwmode
  7. drivers/net/wireless/ath/ath5k/debug.c | 86 ++++++++++++++++++++++++++++++++
  8. 1 files changed, 86 insertions(+), 0 deletions(-)
  9. --- a/drivers/net/wireless/ath/ath5k/debug.c
  10. +++ b/drivers/net/wireless/ath/ath5k/debug.c
  11. @@ -823,6 +823,97 @@ static const struct file_operations fops
  12. .llseek = default_llseek,
  13. };
  14. +/* debugfs: bwmode */
  15. +
  16. +static ssize_t read_file_bwmode(struct file *file, char __user *user_buf,
  17. + size_t count, loff_t *ppos)
  18. +{
  19. + struct ath5k_hw *ah = file->private_data;
  20. + char buf[15];
  21. + unsigned int len = 0;
  22. +
  23. + int cur_ah_bwmode = ah->ah_bwmode_debug;
  24. +
  25. +#define print_selected(MODE, LABEL) \
  26. + if (cur_ah_bwmode == MODE) \
  27. + len += snprintf(buf+len, sizeof(buf)-len, "[%s]", LABEL); \
  28. + else \
  29. + len += snprintf(buf+len, sizeof(buf)-len, "%s", LABEL); \
  30. + len += snprintf(buf+len, sizeof(buf)-len, " ");
  31. +
  32. + print_selected(AR5K_BWMODE_5MHZ, "5");
  33. + print_selected(AR5K_BWMODE_10MHZ, "10");
  34. + print_selected(AR5K_BWMODE_DEFAULT, "20");
  35. + print_selected(AR5K_BWMODE_40MHZ, "40");
  36. +#undef print_selected
  37. +
  38. + len += snprintf(buf+len, sizeof(buf)-len, "\n");
  39. +
  40. + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  41. +}
  42. +
  43. +static ssize_t write_file_bwmode(struct file *file,
  44. + const char __user *userbuf,
  45. + size_t count, loff_t *ppos)
  46. +{
  47. + struct ath5k_hw *ah = file->private_data;
  48. + char buf[3];
  49. + int bw = 20;
  50. + int tobwmode = AR5K_BWMODE_DEFAULT;
  51. +
  52. + if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  53. + return -EFAULT;
  54. +
  55. + /* TODO: Add check for active interface */
  56. +
  57. + if(strncmp(buf, "5", 1) == 0 ) {
  58. + tobwmode = AR5K_BWMODE_5MHZ;
  59. + bw = 5;
  60. + } else if ( strncmp(buf, "10", 2) == 0 ) {
  61. + tobwmode = AR5K_BWMODE_10MHZ;
  62. + bw = 10;
  63. + } else if ( strncmp(buf, "20", 2) == 0 ) {
  64. + tobwmode = AR5K_BWMODE_DEFAULT;
  65. + bw = 20;
  66. + } else if ( strncmp(buf, "40", 2) == 0 ) {
  67. + tobwmode = AR5K_BWMODE_40MHZ;
  68. + bw = 40;
  69. + } else
  70. + return -EINVAL;
  71. +
  72. + ATH5K_INFO(ah, "Changing to %imhz channel width[%i]\n",
  73. + bw, tobwmode);
  74. +
  75. + switch (ah->ah_radio) {
  76. + /* TODO: only define radios that actually support 5/10mhz channels */
  77. + case AR5K_RF5413:
  78. + case AR5K_RF5110:
  79. + case AR5K_RF5111:
  80. + case AR5K_RF5112:
  81. + case AR5K_RF2413:
  82. + case AR5K_RF2316:
  83. + case AR5K_RF2317:
  84. + case AR5K_RF2425:
  85. + if(ah->ah_bwmode_debug != tobwmode) {
  86. + mutex_lock(&ah->lock);
  87. + ah->ah_bwmode = tobwmode;
  88. + ah->ah_bwmode_debug = tobwmode;
  89. + mutex_unlock(&ah->lock);
  90. + }
  91. + break;
  92. + default:
  93. + return -EOPNOTSUPP;
  94. + }
  95. + return count;
  96. +}
  97. +
  98. +static const struct file_operations fops_bwmode = {
  99. + .read = read_file_bwmode,
  100. + .write = write_file_bwmode,
  101. + .open = simple_open,
  102. + .owner = THIS_MODULE,
  103. + .llseek = default_llseek,
  104. +};
  105. /* debugfs: queues etc */
  106. @@ -1010,6 +1101,9 @@ ath5k_debug_init_device(struct ath5k_hw
  107. debugfs_create_file("beacon", S_IWUSR | S_IRUSR, phydir, ah,
  108. &fops_beacon);
  109. + debugfs_create_file("bwmode", S_IWUSR | S_IRUSR, phydir, ah,
  110. + &fops_bwmode);
  111. +
  112. debugfs_create_file("reset", S_IWUSR, phydir, ah, &fops_reset);
  113. debugfs_create_file("antenna", S_IWUSR | S_IRUSR, phydir, ah,
  114. --- a/drivers/net/wireless/ath/ath5k/ath5k.h
  115. +++ b/drivers/net/wireless/ath/ath5k/ath5k.h
  116. @@ -1372,6 +1372,7 @@ struct ath5k_hw {
  117. u8 ah_coverage_class;
  118. bool ah_ack_bitrate_high;
  119. u8 ah_bwmode;
  120. + u8 ah_bwmode_debug;
  121. bool ah_short_slot;
  122. /* Antenna Control */
  123. --- a/drivers/net/wireless/ath/ath5k/base.c
  124. +++ b/drivers/net/wireless/ath/ath5k/base.c
  125. @@ -466,6 +466,9 @@ ath5k_chan_set(struct ath5k_hw *ah, stru
  126. return -EINVAL;
  127. }
  128. + if (ah->ah_bwmode_debug != AR5K_BWMODE_DEFAULT)
  129. + ah->ah_bwmode = ah->ah_bwmode_debug;
  130. +
  131. /*
  132. * To switch channels clear any pending DMA operations;
  133. * wait long enough for the RX fifo to drain, reset the