From patchwork Tue Jun 16 12:46:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shayne Chen X-Patchwork-Id: 11607343 X-Patchwork-Delegate: nbd@nbd.name Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B0AD92A for ; Tue, 16 Jun 2020 12:47:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4415E2080D for ; Tue, 16 Jun 2020 12:47:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="bFfmgrL9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728271AbgFPMrK (ORCPT ); Tue, 16 Jun 2020 08:47:10 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:38020 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725901AbgFPMrK (ORCPT ); Tue, 16 Jun 2020 08:47:10 -0400 X-UUID: 22fa8ade47ad4d9d93accefb4df73746-20200616 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=EHgc6usT4G4/hgz5NXvICcMpwnoY3iXu64idsp5U1Jk=; b=bFfmgrL9h50b1IAUQmp80u69FpIF88j8AspvEpXpIr1zCTAimuBkyjlNe9i1vqAyRG1egmS8Wrfw4PM0RmKPbmL6UbLBZw/Aouy4/WLCgaOqM6Z5qmgeXRj3NgUFHg4LZhCts339BiVNr/QtGqUd5bTeQAKGWnvJHMu5Ndvm2aE=; X-UUID: 22fa8ade47ad4d9d93accefb4df73746-20200616 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1979095913; Tue, 16 Jun 2020 20:47:07 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs02n2.mediatek.inc (172.21.101.101) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 16 Jun 2020 20:46:59 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 16 Jun 2020 20:46:58 +0800 From: Shayne Chen To: Felix Fietkau CC: linux-wireless , Lorenzo Bianconi , Ryder Lee , Evelyn Tsai , linux-mediatek , Shayne Chen Subject: [PATCH 3/4] mt76: mt7915: add support for DT rate power limits Date: Tue, 16 Jun 2020 20:46:12 +0800 Message-ID: <279b29408c742c4b043e7af11217dcd5eeb7b8c2.1592276165.git.ryder.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <9ae2b6233284b60206e3513f7bf2eb03d2fbd724.1592276165.git.ryder.lee@mediatek.com> References: <9ae2b6233284b60206e3513f7bf2eb03d2fbd724.1592276165.git.ryder.lee@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 24678ACB82BEA57D358342FF229A7D0922D92586A8DF5F8F21FBBA311760836D2000:8 X-MTK: N Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Add support to limit per-rate max txpower from DT. Tested-by: Evelyn Tsai Signed-off-by: Shayne Chen --- .../wireless/mediatek/mt76/mt7915/eeprom.h | 2 +- .../net/wireless/mediatek/mt76/mt7915/mcu.c | 38 +++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h index 4e31d6ab4fa6..284de8b4e0a4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h @@ -120,6 +120,6 @@ mt7915_tssi_enabled(struct mt7915_dev *dev, enum nl80211_band band) return eep[MT_EE_WIFI_CONF + 7] & MT_EE_WIFI_CONF_TSSI0_2G; } -extern const struct sku_group mt7915_sku_groups[]; +extern const struct sku_group mt7915_sku_groups[MAX_SKU_RATE_GROUP_NUM]; #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c index 349163d0b7f2..c5e9893cbd87 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c @@ -3171,15 +3171,45 @@ int mt7915_mcu_set_sku(struct mt7915_phy *phy) .format_id = 4, .dbdc_idx = phy != &dev->phy, }; - int i; - s8 *delta; + struct mt76_power_limits limits_array; + s8 *delta, *la = (s8 *)&limits_array; + int i, idx; delta = dev->rate_power[mphy->chandef.chan->band]; mphy->txpower_cur = hw->conf.power_level * 2 + delta[MT7915_SKU_MAX_DELTA_IDX]; - for (i = 0; i < MT7915_SKU_RATE_NUM; i++) - req.val[i] = hw->conf.power_level * 2 + delta[i]; + mt76_get_rate_power_limits(mphy, mphy->chandef.chan, + &limits_array, mphy->txpower_cur); + + for (i = 0, idx = 0; i < ARRAY_SIZE(mt7915_sku_groups); i++) { + const struct sku_group *sku = &mt7915_sku_groups[i]; + u32 offset = sku->offset[mphy->chandef.chan->band]; + u8 mcs_num = sku->len; + int j; + + if (i >= SKU_HT_BW20 && i <= SKU_VHT_BW160) { + mcs_num = 10; + + if (i == SKU_HT_BW20 || i == SKU_VHT_BW20) + la = (s8 *)&limits_array + 12; + } + + if (!offset) { + idx += sku->len; + la += mcs_num; + continue; + } + + for (j = 0; j < min_t(u8, mcs_num, sku->len); j++) { + s8 rate_power; + + rate_power = hw->conf.power_level * 2 + delta[idx + j]; + req.val[idx + j] = min_t(s8, la[j], rate_power); + } + la += mcs_num; + idx += sku->len; + } return __mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_TX_POWER_FEATURE_CTRL,