2017-03-16 15:21:55

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 0/3] Channels in licensed bands, noise floor override

This series contains two patches to enable channels in licensed bands.
Note that there are quite a few requirements to enable those:

* channels must be explicitly enabled using a licensed band kernel config
which contains a warning
* it depends on CFG80211_CERTIFICATION_ONUS
* users must install a custom regdb, since channels in those licensed
bands are not included in the standard regdb

The ath9k patch has been proposed two times and rejected, but it also
included some channels on fractional center frequencies, which is not
the case this time (this would require more changes in mac80211 and
also userspace). The other concern about useres accidently tuning
should not be a problem based on the requirements mentioned above. I've
added another patch doing the same thing for ath10k.

Here is some more info on our need/background:

"We are working on a project that involves the use of Public Safety
channels (4.9x GHz). It is typical 'First Responder' scenario where a
communication network infrastructure should be set up in catastrophe
situations.

As this is a controlled and managed network, the organization setting up
the network has control over the channels that are being used, when and
for how long and in which geographical area. The enforcement of such a
temporary license is a major requirement in this project.

To reduce the cost for the equipment (compared to commercial offerings
in the 4k USD range), the outdoor devices run on hardened, but standard
embedded hardware with a recent linux kernel and use Atheros radios.

We believe, that driver support for 4.9GHz channels should be included
in the Linux kernel, as the driver just exposes specified hardware
features which are disabled by default via

a) a separate compile-time flag. This is similar to the code used for
compliance testing.

b) The default CRDA should (and does) not enable such channels.

Those two safeguards seem sufficient to protect against accidental misuse."

The third patch is adding an experimental debug option to override
the noise floor level, which is usually calibrated automatically.

Cheers,
Simon

Ben Greear (1):
ath9k: Support channels in licensed bands

Simon Wunderlich (2):
ath10k: add support for channels in licensed bands
ath9k: add noise floor override option

drivers/net/wireless/ath/ath10k/Kconfig | 20 +++++++++
drivers/net/wireless/ath/ath10k/core.h | 4 ++
drivers/net/wireless/ath/ath10k/mac.c | 9 ++++
drivers/net/wireless/ath/ath10k/wmi.c | 7 +++-
drivers/net/wireless/ath/ath9k/Kconfig | 20 +++++++++
drivers/net/wireless/ath/ath9k/ath9k.h | 2 +-
drivers/net/wireless/ath/ath9k/calib.c | 5 ++-
drivers/net/wireless/ath/ath9k/common-init.c | 35 ++++++++++++----
drivers/net/wireless/ath/ath9k/debug.c | 62 ++++++++++++++++++++++++++++
drivers/net/wireless/ath/ath9k/hw.h | 5 ++-
10 files changed, 155 insertions(+), 14 deletions(-)

--
2.11.0


2017-03-17 08:48:45

by Janusz Dziedzic

[permalink] [raw]
Subject: Re: [PATCH 3/3] ath9k: add noise floor override option

On 16 March 2017 at 16:13, Simon Wunderlich <[email protected]> wrote:
> 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 <[email protected]>
> Signed-off-by: Mathias Kretschmer <[email protected]>
> ---
> drivers/net/wireless/ath/ath9k/calib.c | 5 ++-
> drivers/net/wireless/ath/ath9k/debug.c | 62 ++++++++++++++++++++++++++++++++++
> drivers/net/wireless/ath/ath9k/hw.h | 1 +
> 3 files changed, 67 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
> index 0f71146b781d..13ab6bc46775 100644
> --- a/drivers/net/wireless/ath/ath9k/calib.c
> +++ b/drivers/net/wireless/ath/ath9k/calib.c
> @@ -254,7 +254,9 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
> if ((i >= AR5416_MAX_CHAINS) && !IS_CHAN_HT40(chan))
> continue;
>
> - if (h)
> + if (ah->nf_override)
> + nfval = ah->nf_override;
> + else if (h)
> nfval = h[i].privNF;
> else
> nfval = default_nf;
> @@ -348,6 +350,7 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
>
> return 0;
> }
> +EXPORT_SYMBOL(ath9k_hw_loadnf);
>
>
> static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
> diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
> index 43930c336987..2e64977a8ab6 100644
> --- a/drivers/net/wireless/ath/ath9k/debug.c
> +++ b/drivers/net/wireless/ath/ath9k/debug.c
> @@ -1191,6 +1191,65 @@ static const struct file_operations fops_tpc = {
> .llseek = default_llseek,
> };
>
> +static ssize_t read_file_nf_override(struct file *file,
> + char __user *user_buf,
> + size_t count, loff_t *ppos)
> +{
> + struct ath_softc *sc = file->private_data;
> + struct ath_hw *ah = sc->sc_ah;
> + char buf[32];
> + unsigned int len;
> +
> + if (ah->nf_override == 0)
> + len = sprintf(buf, "off\n");
> + else
> + len = sprintf(buf, "%d\n", ah->nf_override);
> +
> + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
> +}
> +
> +static ssize_t write_file_nf_override(struct file *file,
> + const char __user *user_buf,
> + size_t count, loff_t *ppos)
> +{
> + struct ath_softc *sc = file->private_data;
> + struct ath_hw *ah = sc->sc_ah;
> + long val;
> + char buf[32];
> + ssize_t len;
> +
> + len = min(count, sizeof(buf) - 1);
> + if (copy_from_user(buf, user_buf, len))
> + return -EFAULT;
> +
> + buf[len] = '\0';
> + if (strncmp("off", buf, 3) == 0)
> + val = 0;
> + else if (kstrtol(buf, 0, &val))
> + return -EINVAL;
> +
> + if (val > 0)
> + return -EINVAL;
> +
> + if (val < -120)
> + return -EINVAL;
> +
> + ah->nf_override = val;
> +
> + if (ah->curchan)
> + ath9k_hw_loadnf(ah, ah->curchan);
> +
> + return count;
> +}
> +
> +static const struct file_operations fops_nf_override = {
> + .read = read_file_nf_override,
> + .write = write_file_nf_override,
> + .open = simple_open,
> + .owner = THIS_MODULE,
> + .llseek = default_llseek,
> +};
> +
> /* Ethtool support for get-stats */
>
> #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
> @@ -1402,5 +1461,8 @@ int ath9k_init_debug(struct ath_hw *ah)
> debugfs_create_u16("airtime_flags", S_IRUSR | S_IWUSR,
> sc->debug.debugfs_phy, &sc->airtime_flags);
>
> + debugfs_create_file("nf_override", S_IRUSR | S_IWUSR,
> + sc->debug.debugfs_phy, sc, &fops_nf_override);
> +

Why not simply:
debugfs_create_u32("nf_override", S_IRUSR|S_IWUSR ,
sc->debug.debugfs_phy,
&ah->nf_override);

One line patch :)

> return 0;
> }
> diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
> index 496e3cd1b509..eba478f052b9 100644
> --- a/drivers/net/wireless/ath/ath9k/hw.h
> +++ b/drivers/net/wireless/ath/ath9k/hw.h
> @@ -803,6 +803,7 @@ struct ath_hw {
> u32 rfkill_gpio;
> u32 rfkill_polarity;
> u32 ah_flags;
> + s16 nf_override;
>
> bool reset_power_on;
> bool htc_reset_init;
> --
> 2.11.0
>
>
> _______________________________________________
> ath10k mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/ath10k

2017-03-16 15:21:56

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 1/3] ath9k: Support channels in licensed bands

From: Ben Greear <[email protected]>

Many chips support channels in licensed bands. Add support for those,
along with a corresponding kernel config option to disable them by
default. Note that these channels are not selectable even if the
option has been compiled unless the user modifies the regulatory
database to explicitly enable the corresponding channels.

NOTE: These channels must not be used in most regulatory
domains unless you have a license from the FCC or similar!

Signed-off-by: Ben Greear <[email protected]>
[Hide this support behind a Kconfig option]
Signed-off-by: Julian Calaby <[email protected]>
[only use the 20 mhz channels, add 5 ghz, change to 4.9ghz to licensed bands]
Signed-off-by: Simon Wunderlich <[email protected]>
Signed-off-by: Mathias Kretschmer <[email protected]>
---
drivers/net/wireless/ath/ath9k/Kconfig | 20 ++++++++++++++++
drivers/net/wireless/ath/ath9k/ath9k.h | 2 +-
drivers/net/wireless/ath/ath9k/common-init.c | 35 +++++++++++++++++++++-------
drivers/net/wireless/ath/ath9k/hw.h | 4 ++--
4 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/ath/ath9k/Kconfig b/drivers/net/wireless/ath/ath9k/Kconfig
index 783a38f1a626..23b8abf4449a 100644
--- a/drivers/net/wireless/ath/ath9k/Kconfig
+++ b/drivers/net/wireless/ath/ath9k/Kconfig
@@ -116,6 +116,26 @@ config ATH9K_DFS_CERTIFIED
developed. At this point enabling this option won't do anything
except increase code size.

+config ATH9K_LICENSED_CHAN
+ bool "Support channels in licensed bands"
+ depends on ATH9K && CFG80211_CERTIFICATION_ONUS
+ default n
+ ---help---
+ This option enables support for licensed channels on such as
+ 4.9 GHz (public safety).
+
+ These are PUBLIC SAFETY CHANNELS and MUST NOT BE USED in most
+ regulatory domains UNLESS YOU HAVE A FULL LICENSE for their use from
+ your local radio regulator, e.g. the FCC or equivalent. Using these
+ channels without proper authorisation may result in serious legal
+ consequences.
+
+ You will also have to build a regulatory database with these channels
+ enabled to actually use them.
+
+ If you are a distro kernel builder or have any doubt whatsoever about
+ your legal ability to use these channels, say N.
+
config ATH9K_DYNACK
bool "Atheros ath9k ACK timeout estimation algorithm (EXPERIMENTAL)"
depends on ATH9K
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index cf076719c27e..d215c3f968d4 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -996,7 +996,7 @@ struct ath_softc {
struct device *dev;

struct survey_info *cur_survey;
- struct survey_info survey[ATH9K_NUM_CHANNELS];
+ struct survey_info survey[ATH9K_MAX_NUM_CHANNELS];

spinlock_t intr_lock;
struct tasklet_struct intr_tq;
diff --git a/drivers/net/wireless/ath/ath9k/common-init.c b/drivers/net/wireless/ath/ath9k/common-init.c
index 8b4f7fdabf58..0d632c22bc16 100644
--- a/drivers/net/wireless/ath/ath9k/common-init.c
+++ b/drivers/net/wireless/ath/ath9k/common-init.c
@@ -86,6 +86,22 @@ static const struct ieee80211_channel ath9k_5ghz_chantable[] = {
CHAN5G(5785, 35), /* Channel 157 */
CHAN5G(5805, 36), /* Channel 161 */
CHAN5G(5825, 37), /* Channel 165 */
+
+#ifdef CONFIG_ATH9K_LICENSED_CHAN
+ /* 4.9Ghz channels, public safety channels, license is required in US
+ * and most other regulatory domains!
+ */
+ /* 802.11j 4.9 GHz (20 MHz) */
+ CHAN5G(4920, 38), /* channel 184 */
+ CHAN5G(4940, 39), /* channel 188 */
+ CHAN5G(4960, 40), /* channel 192 */
+ CHAN5G(4980, 41), /* channel 196 */
+ /* 802.11j 5.030 - 5.080 GHz (20 MHz) */
+ CHAN5G(5040, 42), /* channel 8 */
+ CHAN5G(5060, 43), /* channel 12 */
+ CHAN5G(5080, 44), /* channel 16 */
+#endif
+#define ATH9K_NUM_LICENSED_CHANNELS 7
};

/* Atheros hardware rate code addition for short premble */
@@ -126,10 +142,14 @@ int ath9k_cmn_init_channels_rates(struct ath_common *common)
{
struct ath_hw *ah = (struct ath_hw *)common->ah;
void *channels;
+ int num_5ghz_chan = ARRAY_SIZE(ath9k_5ghz_chantable);
+
+ if (!IS_ENABLED(CONFIG_ATH9K_LICENSED_CHAN))
+ num_5ghz_chan -= ATH9K_NUM_LICENSED_CHANNELS;

BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
- ARRAY_SIZE(ath9k_5ghz_chantable) !=
- ATH9K_NUM_CHANNELS);
+ ARRAY_SIZE(ath9k_5ghz_chantable) >
+ ATH9K_MAX_NUM_CHANNELS);

if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
channels = devm_kzalloc(ah->dev,
@@ -149,17 +169,16 @@ int ath9k_cmn_init_channels_rates(struct ath_common *common)
}

if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
- channels = devm_kzalloc(ah->dev,
- sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
+ int ch_sz = num_5ghz_chan * sizeof(ath9k_5ghz_chantable[0]);
+
+ channels = devm_kzalloc(ah->dev, ch_sz, GFP_KERNEL);
if (!channels)
return -ENOMEM;

- memcpy(channels, ath9k_5ghz_chantable,
- sizeof(ath9k_5ghz_chantable));
+ memcpy(channels, ath9k_5ghz_chantable, ch_sz);
common->sbands[NL80211_BAND_5GHZ].channels = channels;
common->sbands[NL80211_BAND_5GHZ].band = NL80211_BAND_5GHZ;
- common->sbands[NL80211_BAND_5GHZ].n_channels =
- ARRAY_SIZE(ath9k_5ghz_chantable);
+ common->sbands[NL80211_BAND_5GHZ].n_channels = num_5ghz_chan;
common->sbands[NL80211_BAND_5GHZ].bitrates =
ath9k_legacy_rates + 4;
common->sbands[NL80211_BAND_5GHZ].n_bitrates =
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 9cbca1229bac..496e3cd1b509 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -73,7 +73,7 @@

#define ATH9K_RSSI_BAD -128

-#define ATH9K_NUM_CHANNELS 38
+#define ATH9K_MAX_NUM_CHANNELS 45

/* Register read/write primitives */
#define REG_WRITE(_ah, _reg, _val) \
@@ -777,7 +777,7 @@ struct ath_hw {
struct ath9k_hw_version hw_version;
struct ath9k_ops_config config;
struct ath9k_hw_capabilities caps;
- struct ath9k_channel channels[ATH9K_NUM_CHANNELS];
+ struct ath9k_channel channels[ATH9K_MAX_NUM_CHANNELS];
struct ath9k_channel *curchan;

union {
--
2.11.0

2017-03-17 16:02:05

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCHv2 1/3] ath9k: Support channels in licensed bands

From: Ben Greear <[email protected]>

Many chips support channels in licensed bands. Add support for those,
along with a corresponding kernel config option to disable them by
default. Note that these channels are not selectable even if the
option has been compiled unless the user modifies the regulatory
database to explicitly enable the corresponding channels.

NOTE: These channels must not be used in most regulatory
domains unless you have a license from the FCC or similar!

Signed-off-by: Ben Greear <[email protected]>
[Hide this support behind a Kconfig option]
Signed-off-by: Julian Calaby <[email protected]>
[only use the 20 mhz channels, add 5 ghz, change to 4.9ghz to licensed bands, simplify]
Signed-off-by: Simon Wunderlich <[email protected]>
Signed-off-by: Mathias Kretschmer <[email protected]>
---
Changes to PATCHv1:
* fix bug reported by Zefir, and simplify patch more
---
drivers/net/wireless/ath/ath9k/Kconfig | 20 ++++++++++++++++++++
drivers/net/wireless/ath/ath9k/common-init.c | 15 +++++++++++++++
drivers/net/wireless/ath/ath9k/hw.h | 4 ++++
3 files changed, 39 insertions(+)

diff --git a/drivers/net/wireless/ath/ath9k/Kconfig b/drivers/net/wireless/ath/ath9k/Kconfig
index 783a38f1a626..23b8abf4449a 100644
--- a/drivers/net/wireless/ath/ath9k/Kconfig
+++ b/drivers/net/wireless/ath/ath9k/Kconfig
@@ -116,6 +116,26 @@ config ATH9K_DFS_CERTIFIED
developed. At this point enabling this option won't do anything
except increase code size.

+config ATH9K_LICENSED_CHAN
+ bool "Support channels in licensed bands"
+ depends on ATH9K && CFG80211_CERTIFICATION_ONUS
+ default n
+ ---help---
+ This option enables support for licensed channels on such as
+ 4.9 GHz (public safety).
+
+ These are PUBLIC SAFETY CHANNELS and MUST NOT BE USED in most
+ regulatory domains UNLESS YOU HAVE A FULL LICENSE for their use from
+ your local radio regulator, e.g. the FCC or equivalent. Using these
+ channels without proper authorisation may result in serious legal
+ consequences.
+
+ You will also have to build a regulatory database with these channels
+ enabled to actually use them.
+
+ If you are a distro kernel builder or have any doubt whatsoever about
+ your legal ability to use these channels, say N.
+
config ATH9K_DYNACK
bool "Atheros ath9k ACK timeout estimation algorithm (EXPERIMENTAL)"
depends on ATH9K
diff --git a/drivers/net/wireless/ath/ath9k/common-init.c b/drivers/net/wireless/ath/ath9k/common-init.c
index 8b4f7fdabf58..3d65dce13048 100644
--- a/drivers/net/wireless/ath/ath9k/common-init.c
+++ b/drivers/net/wireless/ath/ath9k/common-init.c
@@ -86,6 +86,21 @@ static const struct ieee80211_channel ath9k_5ghz_chantable[] = {
CHAN5G(5785, 35), /* Channel 157 */
CHAN5G(5805, 36), /* Channel 161 */
CHAN5G(5825, 37), /* Channel 165 */
+
+#ifdef CONFIG_ATH9K_LICENSED_CHAN
+ /* 4.9Ghz channels, public safety channels, license is required in US
+ * and most other regulatory domains!
+ */
+ /* 802.11j 4.9 GHz (20 MHz) */
+ CHAN5G(4920, 38), /* channel 184 */
+ CHAN5G(4940, 39), /* channel 188 */
+ CHAN5G(4960, 40), /* channel 192 */
+ CHAN5G(4980, 41), /* channel 196 */
+ /* 802.11j 5.030 - 5.080 GHz (20 MHz) */
+ CHAN5G(5040, 42), /* channel 8 */
+ CHAN5G(5060, 43), /* channel 12 */
+ CHAN5G(5080, 44), /* channel 16 */
+#endif
};

/* Atheros hardware rate code addition for short premble */
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 9cbca1229bac..2166f644599d 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -73,7 +73,11 @@

#define ATH9K_RSSI_BAD -128

+#ifdef CONFIG_ATH9K_LICENSED_CHAN
+#define ATH9K_NUM_CHANNELS 45
+#else
#define ATH9K_NUM_CHANNELS 38
+#endif

/* Register read/write primitives */
#define REG_WRITE(_ah, _reg, _val) \
--
2.11.0

2017-03-23 09:00:30

by Simon Wunderlich

[permalink] [raw]
Subject: Re: [PATCH 2/3] ath10k: add support for channels in licensed bands

On Friday, March 17, 2017 7:49:55 PM CET Sebastian Gottschall wrote:
> you may quickly realize that this patch cannot be a solution
> example:
>
> - if (channel >= 1 && channel <= 14) {
> + if (channel >= 1 && channel <= 7) {
> status->band = NL80211_BAND_2GHZ;
>
>
> do you you really want to limit the 2.4 channels for all users?

Hi Sebastian,

you are right, this seems to be too limiting. I'll rework this part.

Cheers,
Simon


Attachments:
signature.asc (833.00 B)
This is a digitally signed message part.

2017-03-16 15:32:49

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 3/3] 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 <[email protected]>
Signed-off-by: Mathias Kretschmer <[email protected]>
---
drivers/net/wireless/ath/ath9k/calib.c | 5 ++-
drivers/net/wireless/ath/ath9k/debug.c | 62 ++++++++++++++++++++++++++++++++++
drivers/net/wireless/ath/ath9k/hw.h | 1 +
3 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 0f71146b781d..13ab6bc46775 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -254,7 +254,9 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
if ((i >= AR5416_MAX_CHAINS) && !IS_CHAN_HT40(chan))
continue;

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

return 0;
}
+EXPORT_SYMBOL(ath9k_hw_loadnf);


static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index 43930c336987..2e64977a8ab6 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -1191,6 +1191,65 @@ static const struct file_operations fops_tpc = {
.llseek = default_llseek,
};

+static ssize_t read_file_nf_override(struct file *file,
+ char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct ath_softc *sc = file->private_data;
+ struct ath_hw *ah = sc->sc_ah;
+ char buf[32];
+ unsigned int len;
+
+ if (ah->nf_override == 0)
+ len = sprintf(buf, "off\n");
+ else
+ len = sprintf(buf, "%d\n", ah->nf_override);
+
+ return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t write_file_nf_override(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct ath_softc *sc = file->private_data;
+ struct ath_hw *ah = sc->sc_ah;
+ long val;
+ char buf[32];
+ ssize_t len;
+
+ len = min(count, sizeof(buf) - 1);
+ if (copy_from_user(buf, user_buf, len))
+ return -EFAULT;
+
+ buf[len] = '\0';
+ if (strncmp("off", buf, 3) == 0)
+ val = 0;
+ else if (kstrtol(buf, 0, &val))
+ return -EINVAL;
+
+ if (val > 0)
+ return -EINVAL;
+
+ if (val < -120)
+ return -EINVAL;
+
+ ah->nf_override = val;
+
+ if (ah->curchan)
+ ath9k_hw_loadnf(ah, ah->curchan);
+
+ return count;
+}
+
+static const struct file_operations fops_nf_override = {
+ .read = read_file_nf_override,
+ .write = write_file_nf_override,
+ .open = simple_open,
+ .owner = THIS_MODULE,
+ .llseek = default_llseek,
+};
+
/* Ethtool support for get-stats */

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

+ debugfs_create_file("nf_override", S_IRUSR | S_IWUSR,
+ sc->debug.debugfs_phy, sc, &fops_nf_override);
+
return 0;
}
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 496e3cd1b509..eba478f052b9 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -803,6 +803,7 @@ struct ath_hw {
u32 rfkill_gpio;
u32 rfkill_polarity;
u32 ah_flags;
+ s16 nf_override;

bool reset_power_on;
bool htc_reset_init;
--
2.11.0

2017-03-17 18:50:42

by Sebastian Gottschall

[permalink] [raw]
Subject: Re: [PATCH 2/3] ath10k: add support for channels in licensed bands

you may quickly realize that this patch cannot be a solution
example:

- if (channel >= 1 && channel <= 14) {
+ if (channel >= 1 && channel <= 7) {
status->band = NL80211_BAND_2GHZ;


do you you really want to limit the 2.4 channels for all users?


Am 16.03.2017 um 16:13 schrieb Simon Wunderlich:
> Many chips support channels in licensed bands. Add support for those,
> along with a corresponding kernel config option to disable them by
> default. Note that these channels are not selectable even if the
> option has been compiled unless the user modifies the regulatory
> database to explicitly enable the corresponding channels.
>
> NOTE: These channels must not be used in most regulatory
> domains unless you have a license from the FCC or similar!
>
> Signed-off-by: Simon Wunderlich <[email protected]>
> Signed-off-by: Mathias Kretschmer <[email protected]>
> ---
> drivers/net/wireless/ath/ath10k/Kconfig | 20 ++++++++++++++++++++
> drivers/net/wireless/ath/ath10k/core.h | 4 ++++
> drivers/net/wireless/ath/ath10k/mac.c | 9 +++++++++
> drivers/net/wireless/ath/ath10k/wmi.c | 7 +++++--
> 4 files changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath10k/Kconfig b/drivers/net/wireless/ath/ath10k/Kconfig
> index b4241cf9b7ed..13a23ed33f91 100644
> --- a/drivers/net/wireless/ath/ath10k/Kconfig
> +++ b/drivers/net/wireless/ath/ath10k/Kconfig
> @@ -53,3 +53,23 @@ config ATH10K_DFS_CERTIFIED
> ---help---
> This option enables DFS support for initiating radiation on
> ath10k.
> +
> +config ATH10K_LICENSED_CHAN
> + bool "Support channels in licensed bands"
> + depends on ATH10K && CFG80211_CERTIFICATION_ONUS
> + default n
> + ---help---
> + This option enables support for licensed channels on such as
> + 4.9 GHz (public safety).
> +
> + These are PUBLIC SAFETY CHANNELS and MUST NOT BE USED in most
> + regulatory domains UNLESS YOU HAVE A FULL LICENSE for their use from
> + your local radio regulator, e.g. the FCC or equivalent. Using these
> + channels without proper authorisation may result in serious legal
> + consequences.
> +
> + You will also have to build a regulatory database with these channels
> + enabled to actually use them.
> +
> + If you are a distro kernel builder or have any doubt whatsoever about
> + your legal ability to use these channels, say N.
> diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
> index d4b9a0ec1bdc..7674641537b4 100644
> --- a/drivers/net/wireless/ath/ath10k/core.h
> +++ b/drivers/net/wireless/ath/ath10k/core.h
> @@ -46,7 +46,11 @@
> #define WMI_READY_TIMEOUT (5 * HZ)
> #define ATH10K_FLUSH_TIMEOUT_HZ (5 * HZ)
> #define ATH10K_CONNECTION_LOSS_HZ (3 * HZ)
> +#ifdef CONFIG_ATH10K_LICENSED_CHAN
> +#define ATH10K_NUM_CHANS 47
> +#else
> #define ATH10K_NUM_CHANS 40
> +#endif
>
> /* Antenna noise floor */
> #define ATH10K_DEFAULT_NOISE_FLOOR -95
> diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
> index a25f0ec15cf8..23895af0fc63 100644
> --- a/drivers/net/wireless/ath/ath10k/mac.c
> +++ b/drivers/net/wireless/ath/ath10k/mac.c
> @@ -7669,6 +7669,15 @@ static const struct ieee80211_channel ath10k_5ghz_channels[] = {
> CHAN5G(161, 5805, 0),
> CHAN5G(165, 5825, 0),
> CHAN5G(169, 5845, 0),
> +#ifdef CONFIG_ATH10K_LICENSED_CHAN
> + CHAN5G(184, 4920, 0),
> + CHAN5G(188, 4940, 0),
> + CHAN5G(192, 4960, 0),
> + CHAN5G(196, 4980, 0),
> + CHAN5G(8, 5040, 0),
> + CHAN5G(12, 5060, 0),
> + CHAN5G(16, 5080, 0),
> +#endif
> };
>
> struct ath10k *ath10k_mac_create(size_t priv_size)
> diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c
> index 4e60caec7ab4..de7a4fa9d347 100644
> --- a/drivers/net/wireless/ath/ath10k/wmi.c
> +++ b/drivers/net/wireless/ath/ath10k/wmi.c
> @@ -2323,10 +2323,13 @@ int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
> /* Hardware can Rx CCK rates on 5GHz. In that case phy_mode is set to
> * MODE_11B. This means phy_mode is not a reliable source for the band
> * of mgmt rx.
> + *
> + * On the other hand, channel 8, 12 and 16 are defined in 5GHz as well
> + * (5040 - 5080 MHz), therefore apply the override only for channels <=7
> */
> - if (channel >= 1 && channel <= 14) {
> + if (channel >= 1 && channel <= 7) {
> status->band = NL80211_BAND_2GHZ;
> - } else if (channel >= 36 && channel <= 169) {
> + } else if (channel >= 8 && channel <= 196) {
> status->band = NL80211_BAND_5GHZ;
> } else {
> /* Shouldn't happen unless list of advertised channels to


--
Mit freundlichen Gr?ssen / Regards

Sebastian Gottschall / CTO

NewMedia-NET GmbH - DD-WRT
Firmensitz: Berliner Ring 101, 64625 Bensheim
Registergericht: Amtsgericht Darmstadt, HRB 25473
Gesch?ftsf?hrer: Peter Steinh?user, Christian Scheele
http://www.dd-wrt.com
email: [email protected]
Tel.: +496251-582650 / Fax: +496251-5826565

2017-03-17 13:42:27

by Zefir Kurtisi

[permalink] [raw]
Subject: Re: [PATCH 1/3] ath9k: Support channels in licensed bands

On 03/16/2017 04:13 PM, Simon Wunderlich wrote:
> From: Ben Greear <[email protected]>
>
> Many chips support channels in licensed bands. Add support for those,
> along with a corresponding kernel config option to disable them by
> default. Note that these channels are not selectable even if the
> option has been compiled unless the user modifies the regulatory
> database to explicitly enable the corresponding channels.
>
> NOTE: These channels must not be used in most regulatory
> domains unless you have a license from the FCC or similar!
>
> Signed-off-by: Ben Greear <[email protected]>
> [Hide this support behind a Kconfig option]
> Signed-off-by: Julian Calaby <[email protected]>
> [only use the 20 mhz channels, add 5 ghz, change to 4.9ghz to licensed bands]
> Signed-off-by: Simon Wunderlich <[email protected]>
> Signed-off-by: Mathias Kretschmer <[email protected]>
> ---
> drivers/net/wireless/ath/ath9k/Kconfig | 20 ++++++++++++++++
> drivers/net/wireless/ath/ath9k/ath9k.h | 2 +-
> drivers/net/wireless/ath/ath9k/common-init.c | 35 +++++++++++++++++++++-------
> drivers/net/wireless/ath/ath9k/hw.h | 4 ++--
> 4 files changed, 50 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath9k/Kconfig b/drivers/net/wireless/ath/ath9k/Kconfig
> index 783a38f1a626..23b8abf4449a 100644
> --- a/drivers/net/wireless/ath/ath9k/Kconfig
> +++ b/drivers/net/wireless/ath/ath9k/Kconfig
> @@ -116,6 +116,26 @@ config ATH9K_DFS_CERTIFIED
> developed. At this point enabling this option won't do anything
> except increase code size.
>
> +config ATH9K_LICENSED_CHAN
> + bool "Support channels in licensed bands"
> + depends on ATH9K && CFG80211_CERTIFICATION_ONUS
> + default n
> + ---help---
> + This option enables support for licensed channels on such as
> + 4.9 GHz (public safety).
> +
> + These are PUBLIC SAFETY CHANNELS and MUST NOT BE USED in most
> + regulatory domains UNLESS YOU HAVE A FULL LICENSE for their use from
> + your local radio regulator, e.g. the FCC or equivalent. Using these
> + channels without proper authorisation may result in serious legal
> + consequences.
> +
> + You will also have to build a regulatory database with these channels
> + enabled to actually use them.
> +
> + If you are a distro kernel builder or have any doubt whatsoever about
> + your legal ability to use these channels, say N.
> +
> config ATH9K_DYNACK
> bool "Atheros ath9k ACK timeout estimation algorithm (EXPERIMENTAL)"
> depends on ATH9K
> diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
> index cf076719c27e..d215c3f968d4 100644
> --- a/drivers/net/wireless/ath/ath9k/ath9k.h
> +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
> @@ -996,7 +996,7 @@ struct ath_softc {
> struct device *dev;
>
> struct survey_info *cur_survey;
> - struct survey_info survey[ATH9K_NUM_CHANNELS];
> + struct survey_info survey[ATH9K_MAX_NUM_CHANNELS];
>
> spinlock_t intr_lock;
> struct tasklet_struct intr_tq;
> diff --git a/drivers/net/wireless/ath/ath9k/common-init.c b/drivers/net/wireless/ath/ath9k/common-init.c
> index 8b4f7fdabf58..0d632c22bc16 100644
> --- a/drivers/net/wireless/ath/ath9k/common-init.c
> +++ b/drivers/net/wireless/ath/ath9k/common-init.c
> @@ -86,6 +86,22 @@ static const struct ieee80211_channel ath9k_5ghz_chantable[] = {
> CHAN5G(5785, 35), /* Channel 157 */
> CHAN5G(5805, 36), /* Channel 161 */
> CHAN5G(5825, 37), /* Channel 165 */
> +
> +#ifdef CONFIG_ATH9K_LICENSED_CHAN
> + /* 4.9Ghz channels, public safety channels, license is required in US
> + * and most other regulatory domains!
> + */
> + /* 802.11j 4.9 GHz (20 MHz) */
> + CHAN5G(4920, 38), /* channel 184 */
> + CHAN5G(4940, 39), /* channel 188 */
> + CHAN5G(4960, 40), /* channel 192 */
> + CHAN5G(4980, 41), /* channel 196 */
> + /* 802.11j 5.030 - 5.080 GHz (20 MHz) */
> + CHAN5G(5040, 42), /* channel 8 */
> + CHAN5G(5060, 43), /* channel 12 */
> + CHAN5G(5080, 44), /* channel 16 */
> +#endif
> +#define ATH9K_NUM_LICENSED_CHANNELS 7
> };
>
> /* Atheros hardware rate code addition for short premble */
> @@ -126,10 +142,14 @@ int ath9k_cmn_init_channels_rates(struct ath_common *common)
> {
> struct ath_hw *ah = (struct ath_hw *)common->ah;
> void *channels;
> + int num_5ghz_chan = ARRAY_SIZE(ath9k_5ghz_chantable);
> +
> + if (!IS_ENABLED(CONFIG_ATH9K_LICENSED_CHAN))
> + num_5ghz_chan -= ATH9K_NUM_LICENSED_CHANNELS;
These two lines seem wrong to me, since the extra channels are only added to the
list if CONFIG_ATH9K_LICENSED_CHAN is defined. If it is not, this cuts off the
last 7 regular channels, no?

Cheers,
Zefir

2017-03-17 14:02:09

by Simon Wunderlich

[permalink] [raw]
Subject: Re: [PATCH 1/3] ath9k: Support channels in licensed bands

On Friday, March 17, 2017 2:40:50 PM CET Zefir Kurtisi wrote:
> On 03/16/2017 04:13 PM, Simon Wunderlich wrote:
> > @@ -126,10 +142,14 @@ int ath9k_cmn_init_channels_rates(struct ath_common
> > *common)>
> > {
> >
> > struct ath_hw *ah = (struct ath_hw *)common->ah;
> > void *channels;
> >
> > + int num_5ghz_chan = ARRAY_SIZE(ath9k_5ghz_chantable);
> > +
> > + if (!IS_ENABLED(CONFIG_ATH9K_LICENSED_CHAN))
> > + num_5ghz_chan -= ATH9K_NUM_LICENSED_CHANNELS;
>
> These two lines seem wrong to me, since the extra channels are only added to
> the list if CONFIG_ATH9K_LICENSED_CHAN is defined. If it is not, this cuts
> off the last 7 regular channels, no?

Oh, I think you are right!

I'll revise this part and re-send. Seems I can just get rid of those two lines
...

Cheers,
Simon


Attachments:
signature.asc (833.00 B)
This is a digitally signed message part.

2017-03-16 15:21:56

by Simon Wunderlich

[permalink] [raw]
Subject: [PATCH 2/3] ath10k: add support for channels in licensed bands

Many chips support channels in licensed bands. Add support for those,
along with a corresponding kernel config option to disable them by
default. Note that these channels are not selectable even if the
option has been compiled unless the user modifies the regulatory
database to explicitly enable the corresponding channels.

NOTE: These channels must not be used in most regulatory
domains unless you have a license from the FCC or similar!

Signed-off-by: Simon Wunderlich <[email protected]>
Signed-off-by: Mathias Kretschmer <[email protected]>
---
drivers/net/wireless/ath/ath10k/Kconfig | 20 ++++++++++++++++++++
drivers/net/wireless/ath/ath10k/core.h | 4 ++++
drivers/net/wireless/ath/ath10k/mac.c | 9 +++++++++
drivers/net/wireless/ath/ath10k/wmi.c | 7 +++++--
4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath10k/Kconfig b/drivers/net/wireless/ath/ath10k/Kconfig
index b4241cf9b7ed..13a23ed33f91 100644
--- a/drivers/net/wireless/ath/ath10k/Kconfig
+++ b/drivers/net/wireless/ath/ath10k/Kconfig
@@ -53,3 +53,23 @@ config ATH10K_DFS_CERTIFIED
---help---
This option enables DFS support for initiating radiation on
ath10k.
+
+config ATH10K_LICENSED_CHAN
+ bool "Support channels in licensed bands"
+ depends on ATH10K && CFG80211_CERTIFICATION_ONUS
+ default n
+ ---help---
+ This option enables support for licensed channels on such as
+ 4.9 GHz (public safety).
+
+ These are PUBLIC SAFETY CHANNELS and MUST NOT BE USED in most
+ regulatory domains UNLESS YOU HAVE A FULL LICENSE for their use from
+ your local radio regulator, e.g. the FCC or equivalent. Using these
+ channels without proper authorisation may result in serious legal
+ consequences.
+
+ You will also have to build a regulatory database with these channels
+ enabled to actually use them.
+
+ If you are a distro kernel builder or have any doubt whatsoever about
+ your legal ability to use these channels, say N.
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index d4b9a0ec1bdc..7674641537b4 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -46,7 +46,11 @@
#define WMI_READY_TIMEOUT (5 * HZ)
#define ATH10K_FLUSH_TIMEOUT_HZ (5 * HZ)
#define ATH10K_CONNECTION_LOSS_HZ (3 * HZ)
+#ifdef CONFIG_ATH10K_LICENSED_CHAN
+#define ATH10K_NUM_CHANS 47
+#else
#define ATH10K_NUM_CHANS 40
+#endif

/* Antenna noise floor */
#define ATH10K_DEFAULT_NOISE_FLOOR -95
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index a25f0ec15cf8..23895af0fc63 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -7669,6 +7669,15 @@ static const struct ieee80211_channel ath10k_5ghz_channels[] = {
CHAN5G(161, 5805, 0),
CHAN5G(165, 5825, 0),
CHAN5G(169, 5845, 0),
+#ifdef CONFIG_ATH10K_LICENSED_CHAN
+ CHAN5G(184, 4920, 0),
+ CHAN5G(188, 4940, 0),
+ CHAN5G(192, 4960, 0),
+ CHAN5G(196, 4980, 0),
+ CHAN5G(8, 5040, 0),
+ CHAN5G(12, 5060, 0),
+ CHAN5G(16, 5080, 0),
+#endif
};

struct ath10k *ath10k_mac_create(size_t priv_size)
diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c
index 4e60caec7ab4..de7a4fa9d347 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -2323,10 +2323,13 @@ int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
/* Hardware can Rx CCK rates on 5GHz. In that case phy_mode is set to
* MODE_11B. This means phy_mode is not a reliable source for the band
* of mgmt rx.
+ *
+ * On the other hand, channel 8, 12 and 16 are defined in 5GHz as well
+ * (5040 - 5080 MHz), therefore apply the override only for channels <=7
*/
- if (channel >= 1 && channel <= 14) {
+ if (channel >= 1 && channel <= 7) {
status->band = NL80211_BAND_2GHZ;
- } else if (channel >= 36 && channel <= 169) {
+ } else if (channel >= 8 && channel <= 196) {
status->band = NL80211_BAND_5GHZ;
} else {
/* Shouldn't happen unless list of advertised channels to
--
2.11.0

2017-03-17 09:20:51

by Simon Wunderlich

[permalink] [raw]
Subject: Re: [PATCH 3/3] ath9k: add noise floor override option

On Friday, March 17, 2017 9:48:07 AM CET Janusz Dziedzic wrote:
> On 16 March 2017 at 16:13, Simon Wunderlich <[email protected]> wrote:
> > 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 <[email protected]>
> > Signed-off-by: Mathias Kretschmer <[email protected]>
> > ---
> >
> > drivers/net/wireless/ath/ath9k/calib.c | 5 ++-
> > drivers/net/wireless/ath/ath9k/debug.c | 62
> > ++++++++++++++++++++++++++++++++++ drivers/net/wireless/ath/ath9k/hw.h
> > | 1 +
> > 3 files changed, 67 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/wireless/ath/ath9k/calib.c
> > b/drivers/net/wireless/ath/ath9k/calib.c index 0f71146b781d..13ab6bc46775
> > 100644
> > --- a/drivers/net/wireless/ath/ath9k/calib.c
> > +++ b/drivers/net/wireless/ath/ath9k/calib.c
> > @@ -254,7 +254,9 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct
> > ath9k_channel *chan)>
> > if ((i >= AR5416_MAX_CHAINS) &&
> > !IS_CHAN_HT40(chan))
> >
> > continue;
> >
> > - if (h)
> > + if (ah->nf_override)
> > + nfval = ah->nf_override;
> > + else if (h)
> >
> > nfval = h[i].privNF;
> >
> > else
> >
> > nfval = default_nf;
> >
> > @@ -348,6 +350,7 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct
> > ath9k_channel *chan)>
> > return 0;
> >
> > }
> >
> > +EXPORT_SYMBOL(ath9k_hw_loadnf);
> >
> > static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
> >
> > diff --git a/drivers/net/wireless/ath/ath9k/debug.c
> > b/drivers/net/wireless/ath/ath9k/debug.c index 43930c336987..2e64977a8ab6
> > 100644
> > --- a/drivers/net/wireless/ath/ath9k/debug.c
> > +++ b/drivers/net/wireless/ath/ath9k/debug.c
> > @@ -1191,6 +1191,65 @@ static const struct file_operations fops_tpc = {
> >
> > .llseek = default_llseek,
> >
> > };
> >
> > +static ssize_t read_file_nf_override(struct file *file,
> > + char __user *user_buf,
> > + size_t count, loff_t *ppos)
> > +{
> > + struct ath_softc *sc = file->private_data;
> > + struct ath_hw *ah = sc->sc_ah;
> > + char buf[32];
> > + unsigned int len;
> > +
> > + if (ah->nf_override == 0)
> > + len = sprintf(buf, "off\n");
> > + else
> > + len = sprintf(buf, "%d\n", ah->nf_override);
> > +
> > + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
> > +}
> > +
> > +static ssize_t write_file_nf_override(struct file *file,
> > + const char __user *user_buf,
> > + size_t count, loff_t *ppos)
> > +{
> > + struct ath_softc *sc = file->private_data;
> > + struct ath_hw *ah = sc->sc_ah;
> > + long val;
> > + char buf[32];
> > + ssize_t len;
> > +
> > + len = min(count, sizeof(buf) - 1);
> > + if (copy_from_user(buf, user_buf, len))
> > + return -EFAULT;
> > +
> > + buf[len] = '\0';
> > + if (strncmp("off", buf, 3) == 0)
> > + val = 0;
> > + else if (kstrtol(buf, 0, &val))
> > + return -EINVAL;
> > +
> > + if (val > 0)
> > + return -EINVAL;
> > +
> > + if (val < -120)
> > + return -EINVAL;
> > +
> > + ah->nf_override = val;
> > +
> > + if (ah->curchan)
> > + ath9k_hw_loadnf(ah, ah->curchan);
> > +
> > + return count;
> > +}
> > +
> > +static const struct file_operations fops_nf_override = {
> > + .read = read_file_nf_override,
> > + .write = write_file_nf_override,
> > + .open = simple_open,
> > + .owner = THIS_MODULE,
> > + .llseek = default_llseek,
> > +};
> > +
> >
> > /* Ethtool support for get-stats */
> >
> > #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
> >
> > @@ -1402,5 +1461,8 @@ int ath9k_init_debug(struct ath_hw *ah)
> >
> > debugfs_create_u16("airtime_flags", S_IRUSR | S_IWUSR,
> >
> > sc->debug.debugfs_phy, &sc->airtime_flags);
> >
> > + debugfs_create_file("nf_override", S_IRUSR | S_IWUSR,
> > + sc->debug.debugfs_phy, sc, &fops_nf_override);
> > +
>
> Why not simply:
> debugfs_create_u32("nf_override", S_IRUSR|S_IWUSR ,
> sc->debug.debugfs_phy,
> &ah->nf_override);
>
> One line patch :)

Thanks Janusz, good idea! That doesn't check the limits, which is probably not
a big deal anyway. What bothers me more is that it doesn't update the noise
floor immediately (ath9k_hw_loadnf()), which would be nice to have. Otherwise
you have to wait up to ~30 seconds or so until the noise floor is updated next
time. So I'd keep my variant for now, unless you have a good idea to fix the
latter. :)

Cheers,
Simon


Attachments:
signature.asc (833.00 B)
This is a digitally signed message part.

2017-03-17 12:44:43

by Janusz Dziedzic

[permalink] [raw]
Subject: Re: [PATCH 3/3] ath9k: add noise floor override option

On 17 March 2017 at 09:55, Simon Wunderlich <[email protected]> wrote:
> On Friday, March 17, 2017 9:48:07 AM CET Janusz Dziedzic wrote:
>> On 16 March 2017 at 16:13, Simon Wunderlich <[email protected]> wrote:
>> > 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 <[email protected]>
>> > Signed-off-by: Mathias Kretschmer <[email protected]>
>> > ---
>> >
>> > drivers/net/wireless/ath/ath9k/calib.c | 5 ++-
>> > drivers/net/wireless/ath/ath9k/debug.c | 62
>> > ++++++++++++++++++++++++++++++++++ drivers/net/wireless/ath/ath9k/hw.h
>> > | 1 +
>> > 3 files changed, 67 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/net/wireless/ath/ath9k/calib.c
>> > b/drivers/net/wireless/ath/ath9k/calib.c index 0f71146b781d..13ab6bc46775
>> > 100644
>> > --- a/drivers/net/wireless/ath/ath9k/calib.c
>> > +++ b/drivers/net/wireless/ath/ath9k/calib.c
>> > @@ -254,7 +254,9 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct
>> > ath9k_channel *chan)>
>> > if ((i >= AR5416_MAX_CHAINS) &&
>> > !IS_CHAN_HT40(chan))
>> >
>> > continue;
>> >
>> > - if (h)
>> > + if (ah->nf_override)
>> > + nfval = ah->nf_override;
>> > + else if (h)
>> >
>> > nfval = h[i].privNF;
>> >
>> > else
>> >
>> > nfval = default_nf;
>> >
>> > @@ -348,6 +350,7 @@ int ath9k_hw_loadnf(struct ath_hw *ah, struct
>> > ath9k_channel *chan)>
>> > return 0;
>> >
>> > }
>> >
>> > +EXPORT_SYMBOL(ath9k_hw_loadnf);
>> >
>> > static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
>> >
>> > diff --git a/drivers/net/wireless/ath/ath9k/debug.c
>> > b/drivers/net/wireless/ath/ath9k/debug.c index 43930c336987..2e64977a8ab6
>> > 100644
>> > --- a/drivers/net/wireless/ath/ath9k/debug.c
>> > +++ b/drivers/net/wireless/ath/ath9k/debug.c
>> > @@ -1191,6 +1191,65 @@ static const struct file_operations fops_tpc = {
>> >
>> > .llseek = default_llseek,
>> >
>> > };
>> >
>> > +static ssize_t read_file_nf_override(struct file *file,
>> > + char __user *user_buf,
>> > + size_t count, loff_t *ppos)
>> > +{
>> > + struct ath_softc *sc = file->private_data;
>> > + struct ath_hw *ah = sc->sc_ah;
>> > + char buf[32];
>> > + unsigned int len;
>> > +
>> > + if (ah->nf_override == 0)
>> > + len = sprintf(buf, "off\n");
>> > + else
>> > + len = sprintf(buf, "%d\n", ah->nf_override);
>> > +
>> > + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
>> > +}
>> > +
>> > +static ssize_t write_file_nf_override(struct file *file,
>> > + const char __user *user_buf,
>> > + size_t count, loff_t *ppos)
>> > +{
>> > + struct ath_softc *sc = file->private_data;
>> > + struct ath_hw *ah = sc->sc_ah;
>> > + long val;
>> > + char buf[32];
>> > + ssize_t len;
>> > +
>> > + len = min(count, sizeof(buf) - 1);
>> > + if (copy_from_user(buf, user_buf, len))
>> > + return -EFAULT;
>> > +
>> > + buf[len] = '\0';
>> > + if (strncmp("off", buf, 3) == 0)
>> > + val = 0;
>> > + else if (kstrtol(buf, 0, &val))
>> > + return -EINVAL;
>> > +
>> > + if (val > 0)
>> > + return -EINVAL;
>> > +
>> > + if (val < -120)
>> > + return -EINVAL;
>> > +
>> > + ah->nf_override = val;
>> > +
>> > + if (ah->curchan)
>> > + ath9k_hw_loadnf(ah, ah->curchan);
>> > +
>> > + return count;
>> > +}
>> > +
>> > +static const struct file_operations fops_nf_override = {
>> > + .read = read_file_nf_override,
>> > + .write = write_file_nf_override,
>> > + .open = simple_open,
>> > + .owner = THIS_MODULE,
>> > + .llseek = default_llseek,
>> > +};
>> > +
>> >
>> > /* Ethtool support for get-stats */
>> >
>> > #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
>> >
>> > @@ -1402,5 +1461,8 @@ int ath9k_init_debug(struct ath_hw *ah)
>> >
>> > debugfs_create_u16("airtime_flags", S_IRUSR | S_IWUSR,
>> >
>> > sc->debug.debugfs_phy, &sc->airtime_flags);
>> >
>> > + debugfs_create_file("nf_override", S_IRUSR | S_IWUSR,
>> > + sc->debug.debugfs_phy, sc, &fops_nf_override);
>> > +
>>
>> Why not simply:
>> debugfs_create_u32("nf_override", S_IRUSR|S_IWUSR ,
>> sc->debug.debugfs_phy,
>> &ah->nf_override);
>>
>> One line patch :)
>
> Thanks Janusz, good idea! That doesn't check the limits, which is probably not
> a big deal anyway. What bothers me more is that it doesn't update the noise
> floor immediately (ath9k_hw_loadnf()), which would be nice to have. Otherwise
> you have to wait up to ~30 seconds or so until the noise floor is updated next
> time. So I'd keep my variant for now, unless you have a good idea to fix the
> latter. :)
>
I see, seems I miss ath9k_hw_loadnf() call :)

> Cheers,
> Simon