Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp63987pxt; Wed, 4 Aug 2021 15:55:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwO8Ph9a8eIQlBXKAO33DU2p1P3UKLJFQo5Uta2UL/i5rbqWdb6l73qgEH3ISxLMwnLDlpZ X-Received: by 2002:a05:6402:100c:: with SMTP id c12mr2405100edu.326.1628117716243; Wed, 04 Aug 2021 15:55:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628117716; cv=none; d=google.com; s=arc-20160816; b=p7RDxhQTl0jFHBLzdjPah9kPLqI1wlqVcLd5ousyaKzgLgAv1aTF1apC0tyjnzCYdh puQr9+Xia5TJGRUJ4/mq58QEE+xR0rgbVvZtZrgQEsnKUkqBHVo5cud1csFHciWsmLvE MzcYF5ou8n6g8rmt2tFi2gVytIlNxbTLeg5p/Lps9EmB3ET4NZrgNN1Zt/oNlLF/LQ7z dmzQ6URQXdLLR0MeGh2vmMTqowS46dhODsGu54Atxt8Ou3SaUvp4OmELq2fBlD3T+aPC qZXvuLpJXs3KuWWAOgkYUJ4Uzx0yn4FVDn9atx/UZGyI0T6TXLnlaqchYrdXDCjQhVkT f6dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=ViidrIlEcxqf/nB3O9ZC1jcbXhOLZ9EFrb6fr7TfMAM=; b=kiYz9E/mVsfq9ZFpWu0u/X5jFa0U0kn6oROuhPd5wwuJHCTC73g8J1+GNfbe4oV/GH 7bB0Vp2EPdLbTajtBHUDVtH7lkDrjOUC7wypOm96cmyorjr++OIHDvAdvPvCJWyQwS4M KoA6CXCG3DqI7OZAzJmk0mJXSilHVpZuxmhegHxaleA/2qyupUYYMBN+QtoDwT4E4O0A FKsjeWzjIlhjc6ukDRIhSKJvdzJapAZUpAByB8bKrg49SGEFpvjkajqgiXOrgiGkFlsl LB8cmQp3Zb5Eke6Cs0nT1boAQuIrUYM/2xzqmEkTvUzIABZFuZHm22t8Ta9t+xJ4DJ1T w/tQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h29si3286594edz.349.2021.08.04.15.54.49; Wed, 04 Aug 2021 15:55:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233487AbhHDWX2 (ORCPT + 99 others); Wed, 4 Aug 2021 18:23:28 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:35044 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230236AbhHDWX2 (ORCPT ); Wed, 4 Aug 2021 18:23:28 -0400 X-UUID: d1e909313d2e421b82c0b8d3fb9bbc16-20210805 X-UUID: d1e909313d2e421b82c0b8d3fb9bbc16-20210805 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 291457690; Thu, 05 Aug 2021 06:23:10 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 5 Aug 2021 06:23:08 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 5 Aug 2021 06:23:02 +0800 From: To: , CC: , , , , , , , , , , , , , , , Subject: [PATCH v2] mt76: connac: add support maximum regulatory Tx power Date: Thu, 5 Aug 2021 06:23:00 +0800 Message-ID: X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: YN Chen 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 Signed-off-by: Sean Wang Signed-off-by: YN Chen --- v2: consider the power limit that can be allowed on mt7663 --- .../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..80987af03efe 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 (is_mt7663(dev) && (power > 63 || power < -64)) + power = 63; + 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