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