2021-07-27 23:00:44

by Sean Wang

[permalink] [raw]
Subject: [PATCH 2/2] mt76: connac: add support maximum regulatory Tx power

From: YN Chen <[email protected]>

Consider .max_reg_power in struct ieee80211_channel to limit the
maximum power the wireless device allowed to transmit on the
corresponding channel according to the regulatory domain.

Co-developed-by: Sean Wang <[email protected]>
Signed-off-by: Sean Wang <[email protected]>
Signed-off-by: YN Chen <[email protected]>
---
.../wireless/mediatek/mt76/mt76_connac_mcu.c | 43 ++++++++++++++++++-
1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
index d71393b1c5e6..84f42ce12626 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
@@ -1773,6 +1773,43 @@ static s8 mt76_connac_get_sar_power(struct mt76_phy *phy,
return target_power;
}

+static s8 mt76_connac_get_ch_power(struct mt76_phy *phy,
+ struct ieee80211_channel *chan,
+ s8 target_power)
+{
+ struct mt76_dev *dev = phy->dev;
+ struct ieee80211_supported_band *sband;
+ int i;
+
+ switch (chan->band) {
+ case NL80211_BAND_2GHZ:
+ sband = &phy->sband_2g.sband;
+ break;
+ case NL80211_BAND_5GHZ:
+ sband = &phy->sband_5g.sband;
+ break;
+ default:
+ return target_power;
+ }
+
+ for (i = 0; i < sband->n_channels; i++) {
+ struct ieee80211_channel *ch = &sband->channels[i];
+
+ if (ch->hw_value == chan->hw_value) {
+ if (!(ch->flags & IEEE80211_CHAN_DISABLED)) {
+ int power = 2 * ch->max_reg_power;
+
+ if (power > 127 || power < -127)
+ power = 127;
+ target_power = min_t(s8, power, target_power);
+ }
+ break;
+ }
+ }
+
+ return target_power;
+}
+
static int
mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
enum nl80211_band band)
@@ -1840,10 +1877,12 @@ mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
.hw_value = ch_list[idx],
.band = band,
};
- s8 sar_power;
+ s8 reg_power, sar_power;

+ reg_power = mt76_connac_get_ch_power(phy, &chan,
+ tx_power);
sar_power = mt76_connac_get_sar_power(phy, &chan,
- tx_power);
+ reg_power);

mt76_get_rate_power_limits(phy, &chan, &limits,
sar_power);
--
2.25.1



2021-07-28 07:35:59

by Lorenzo Bianconi

[permalink] [raw]
Subject: Re: [PATCH 2/2] mt76: connac: add support maximum regulatory Tx power

> From: YN Chen <[email protected]>
>
> Consider .max_reg_power in struct ieee80211_channel to limit the
> maximum power the wireless device allowed to transmit on the
> corresponding channel according to the regulatory domain.
>
> Co-developed-by: Sean Wang <[email protected]>
> Signed-off-by: Sean Wang <[email protected]>
> Signed-off-by: YN Chen <[email protected]>
> ---
> .../wireless/mediatek/mt76/mt76_connac_mcu.c | 43 ++++++++++++++++++-
> 1 file changed, 41 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
> index d71393b1c5e6..84f42ce12626 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
> @@ -1773,6 +1773,43 @@ static s8 mt76_connac_get_sar_power(struct mt76_phy *phy,
> return target_power;
> }
>
> +static s8 mt76_connac_get_ch_power(struct mt76_phy *phy,
> + struct ieee80211_channel *chan,
> + s8 target_power)
> +{
> + struct mt76_dev *dev = phy->dev;

is it used?

> + struct ieee80211_supported_band *sband;
> + int i;
> +
> + switch (chan->band) {
> + case NL80211_BAND_2GHZ:
> + sband = &phy->sband_2g.sband;
> + break;
> + case NL80211_BAND_5GHZ:
> + sband = &phy->sband_5g.sband;
> + break;
> + default:
> + return target_power;
> + }
> +
> + for (i = 0; i < sband->n_channels; i++) {
> + struct ieee80211_channel *ch = &sband->channels[i];
> +
> + if (ch->hw_value == chan->hw_value) {
> + if (!(ch->flags & IEEE80211_CHAN_DISABLED)) {
> + int power = 2 * ch->max_reg_power;
> +
> + if (power > 127 || power < -127)
> + power = 127;

please correct me if I am wrong, but I guess the limit for mt7663 should be 63,
isn't it?

Regards,
Lorenzo

> + target_power = min_t(s8, power, target_power);
> + }
> + break;
> + }
> + }
> +
> + return target_power;
> +}
> +
> static int
> mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
> enum nl80211_band band)
> @@ -1840,10 +1877,12 @@ mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
> .hw_value = ch_list[idx],
> .band = band,
> };
> - s8 sar_power;
> + s8 reg_power, sar_power;
>
> + reg_power = mt76_connac_get_ch_power(phy, &chan,
> + tx_power);
> sar_power = mt76_connac_get_sar_power(phy, &chan,
> - tx_power);
> + reg_power);
>
> mt76_get_rate_power_limits(phy, &chan, &limits,
> sar_power);
> --
> 2.25.1
>


Attachments:
(No filename) (2.57 kB)
signature.asc (235.00 B)
Download all attachments