Skip to content

Commit b901897

Browse files
simonwunderlichkvalo
authored andcommitted
ath9k: add noise floor override option
Introduce a debugfs option to manually override the noise floor, ignoring the automatically tuned noise floor of the driver/hw. In my tests with a AR9580 based module and a tx99 5 MHz interferer, I could tune the noisefloor to -95 dBm or above to allow communication again. The automatic noise floor calibration sometimes could adapt to the situation as well, but not reliably and permanently. I would consider this "feature" experimental and interesting for people debugging the noise floor calibration or other effects of the hardware. Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de> Signed-off-by: Mathias Kretschmer <mathias.kretschmer@fit.fraunhofer.de> Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
1 parent aad1fd7 commit b901897

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

drivers/net/wireless/ath/ath9k/calib.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
254254
if ((i >= AR5416_MAX_CHAINS) && !IS_CHAN_HT40(chan))
255255
continue;
256256

257-
if (h)
257+
if (ah->nf_override)
258+
nfval = ah->nf_override;
259+
else if (h)
258260
nfval = h[i].privNF;
259261
else
260262
nfval = default_nf;
@@ -348,6 +350,7 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
348350

349351
return 0;
350352
}
353+
EXPORT_SYMBOL(ath9k_hw_loadnf);
351354

352355

353356
static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)

drivers/net/wireless/ath/ath9k/debug.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,65 @@ static const struct file_operations fops_tpc = {
11911191
.llseek = default_llseek,
11921192
};
11931193

1194+
static ssize_t read_file_nf_override(struct file *file,
1195+
char __user *user_buf,
1196+
size_t count, loff_t *ppos)
1197+
{
1198+
struct ath_softc *sc = file->private_data;
1199+
struct ath_hw *ah = sc->sc_ah;
1200+
char buf[32];
1201+
unsigned int len;
1202+
1203+
if (ah->nf_override == 0)
1204+
len = sprintf(buf, "off\n");
1205+
else
1206+
len = sprintf(buf, "%d\n", ah->nf_override);
1207+
1208+
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1209+
}
1210+
1211+
static ssize_t write_file_nf_override(struct file *file,
1212+
const char __user *user_buf,
1213+
size_t count, loff_t *ppos)
1214+
{
1215+
struct ath_softc *sc = file->private_data;
1216+
struct ath_hw *ah = sc->sc_ah;
1217+
long val;
1218+
char buf[32];
1219+
ssize_t len;
1220+
1221+
len = min(count, sizeof(buf) - 1);
1222+
if (copy_from_user(buf, user_buf, len))
1223+
return -EFAULT;
1224+
1225+
buf[len] = '\0';
1226+
if (strncmp("off", buf, 3) == 0)
1227+
val = 0;
1228+
else if (kstrtol(buf, 0, &val))
1229+
return -EINVAL;
1230+
1231+
if (val > 0)
1232+
return -EINVAL;
1233+
1234+
if (val < -120)
1235+
return -EINVAL;
1236+
1237+
ah->nf_override = val;
1238+
1239+
if (ah->curchan)
1240+
ath9k_hw_loadnf(ah, ah->curchan);
1241+
1242+
return count;
1243+
}
1244+
1245+
static const struct file_operations fops_nf_override = {
1246+
.read = read_file_nf_override,
1247+
.write = write_file_nf_override,
1248+
.open = simple_open,
1249+
.owner = THIS_MODULE,
1250+
.llseek = default_llseek,
1251+
};
1252+
11941253
/* Ethtool support for get-stats */
11951254

11961255
#define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
@@ -1402,5 +1461,8 @@ int ath9k_init_debug(struct ath_hw *ah)
14021461
debugfs_create_u16("airtime_flags", S_IRUSR | S_IWUSR,
14031462
sc->debug.debugfs_phy, &sc->airtime_flags);
14041463

1464+
debugfs_create_file("nf_override", S_IRUSR | S_IWUSR,
1465+
sc->debug.debugfs_phy, sc, &fops_nf_override);
1466+
14051467
return 0;
14061468
}

drivers/net/wireless/ath/ath9k/hw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ struct ath_hw {
803803
u32 rfkill_gpio;
804804
u32 rfkill_polarity;
805805
u32 ah_flags;
806+
s16 nf_override;
806807

807808
bool reset_power_on;
808809
bool htc_reset_init;

0 commit comments

Comments
 (0)