From patchwork Tue Jun 16 12:46:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shayne Chen X-Patchwork-Id: 11607337 X-Patchwork-Delegate: kvalo@adurom.com 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 7FEED138C for ; Tue, 16 Jun 2020 12:46:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68E3A2080D for ; Tue, 16 Jun 2020 12:46:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="BmQx9CxU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728666AbgFPMqu (ORCPT ); Tue, 16 Jun 2020 08:46:50 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:27315 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726526AbgFPMqu (ORCPT ); Tue, 16 Jun 2020 08:46:50 -0400 X-UUID: 08d2f915be1d4ee0a9833f846b7fe853-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:Message-ID:Date:Subject:CC:To:From; bh=0zUnaVwf7NdA/yxdczKheQ3t79GOtZpyyLqwBUW4cDQ=; b=BmQx9CxUC+mvkntAi/PYoOWuPOxQuABN/tk84EaTG8t8jGwvGOcNZutj1k7WqQ3cQj5cRRpaG+u+Iss7+DDWSo1Y8L3VomXwxrY0SlHoriTJ6JEdXOv5kYUe4QcIUWnCC35dHV3UCrkhs9P2dtzJe0witpKJCCK9MwQpdLMobno=; X-UUID: 08d2f915be1d4ee0a9833f846b7fe853-20200616 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1121773539; Tue, 16 Jun 2020 20:46:46 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 16 Jun 2020 20:46:43 +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:43 +0800 From: Shayne Chen To: Felix Fietkau CC: linux-wireless , Lorenzo Bianconi , Ryder Lee , Evelyn Tsai , linux-mediatek , Shayne Chen , Subject: [PATCH 1/4] dt-bindings: net: wireless: mt76: add ru property in power-limits node Date: Tue, 16 Jun 2020 20:46:10 +0800 Message-ID: <9ae2b6233284b60206e3513f7bf2eb03d2fbd724.1592276165.git.ryder.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org This new property of power-limits node can be used to set per-rate tx power limits for 802.11ax rates. Cc: devicetree@vger.kernel.org Tested-by: Evelyn Tsai Signed-off-by: Shayne Chen --- The series is based on Felix's https://patchwork.kernel.org/project/linux-wireless/list/?series=295809 --- .../devicetree/bindings/net/wireless/mediatek,mt76.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.txt b/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.txt index 9d9ace0cfbf9..aefe880d36ff 100644 --- a/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.txt +++ b/Documentation/devicetree/bindings/net/wireless/mediatek,mt76.txt @@ -101,6 +101,13 @@ Properties: which the rate set applies, followed by either 8 (MT7603/MT7628) or 10 (all other chips) power limit values. The order of the channel bandwidth settings is: 20, 40, 80, 160 MHz. +- ru: + sets of per-rate power limit values for 802.11ax rates for multiple + channel bandwidth or resource unit settings. + Each set starts with the number of channel bandwidth or resource unit + settings for which the rate set applies, followed by 12 power limit + values. The order of the channel resource unit settings is: + RU26, RU52, RU106, RU242/SU20, RU484/SU40, RU996/SU80, RU2x996/SU160. power-limit example: @@ -114,11 +121,14 @@ power-limits { ofdm = <23 23 23 23 23 23 23 23>; mcs = <1 23 23 23 23 23 23 23 23 23 23>, <3 22 22 22 22 22 22 22 22 22 22>; + ru = <3 22 22 22 22 22 22 22 22 22 22 22 22>, + <4 20 20 20 20 20 20 20 20 20 20 20 20>; }; r2 { channels = <100 181>; ofdm = <14 14 14 14 14 14 14 14>; mcs = <4 14 14 14 14 14 14 14 14 14 14>; + ru = <7 14 14 14 14 14 14 14 14 14 14 14 14>; }; }; }; From patchwork Tue Jun 16 12:46:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shayne Chen X-Patchwork-Id: 11607341 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 ACD7A92A for ; Tue, 16 Jun 2020 12:47:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 971C020B1F for ; Tue, 16 Jun 2020 12:47:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="YBYgl4UG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728771AbgFPMrC (ORCPT ); Tue, 16 Jun 2020 08:47:02 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:17121 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725901AbgFPMrC (ORCPT ); Tue, 16 Jun 2020 08:47:02 -0400 X-UUID: 6ab7a681ab6648f7867b780c320cff90-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=zlMoMDUbTsExrKd8RFq8cHNFiYg9RxmBmUZDOlfOEwY=; b=YBYgl4UGPxsMrRjq5R5U4SxhKri0FJXqSPMB1SA6lwq2xxqvtF7APOfgH227DlS//4TqHmlDYUQGvVqtYfWh7+QGAgjqBgrdccbXF6X2LjUQftcB243pL50D+GjrdT/CoTT8TR/LJUve5JSoND0ZPdG4H6JhIEPvikF0gnP1mcU=; X-UUID: 6ab7a681ab6648f7867b780c320cff90-20200616 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 191896191; Tue, 16 Jun 2020 20:46:57 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 16 Jun 2020 20:46:55 +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:54 +0800 From: Shayne Chen To: Felix Fietkau CC: linux-wireless , Lorenzo Bianconi , Ryder Lee , Evelyn Tsai , linux-mediatek , Shayne Chen Subject: [PATCH 2/4] mt76: extend DT rate power limits to support 11ax devices Date: Tue, 16 Jun 2020 20:46:11 +0800 Message-ID: <08d8c206b15e705489fab96dbe9dd8a77874c4a4.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-MTK: N Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Enable parsing per-rate txpower limits from DT for 11ax chipsets. Tested-by: Evelyn Tsai Signed-off-by: Shayne Chen --- drivers/net/wireless/mediatek/mt76/eeprom.c | 63 ++++++++++++++------- drivers/net/wireless/mediatek/mt76/mt76.h | 1 + 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c index 334606b07693..87a5d2db05e1 100644 --- a/drivers/net/wireless/mediatek/mt76/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/eeprom.c @@ -221,6 +221,41 @@ mt76_apply_array_limit(s8 *pwr, size_t pwr_len, const __be32 *data, } } +static void +mt76_apply_mcs_limit(struct mt76_power_limits *dest, u32 mcs_rates, + const __be32 *data, size_t len, s8 target_power, + s8 nss_delta, s8 *max_power) +{ + s8 *pwr = (s8 *)dest->mcs; + u8 pwr_num = ARRAY_SIZE(dest->mcs), pwr_len = ARRAY_SIZE(dest->mcs[0]); + int i, cur; + + if (mcs_rates == ARRAY_SIZE(dest->ru[0])) { + pwr = (s8 *)dest->ru; + pwr_num = ARRAY_SIZE(dest->ru); + pwr_len = ARRAY_SIZE(dest->ru[0]); + } + + len /= 4; + cur = be32_to_cpu(data[0]); + for (i = 0; i < pwr_num; i++) { + if (len < mcs_rates + 1) + break; + + mt76_apply_array_limit(pwr + pwr_len * i, pwr_len, data + 1, + target_power, nss_delta, max_power); + if (--cur > 0) + continue; + + data += mcs_rates + 1; + len -= mcs_rates + 1; + if (!len) + break; + + cur = be32_to_cpu(data[0]); + } +} + s8 mt76_get_rate_power_limits(struct mt76_phy *phy, struct ieee80211_channel *chan, struct mt76_power_limits *dest, @@ -231,9 +266,9 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, const __be32 *val; char name[16]; u32 mcs_rates = dev->drv->mcs_rates; + u32 ru_rates = ARRAY_SIZE(dest->ru[0]); char band; size_t len; - int i, cur; s8 max_power = 0; s8 txs_delta; @@ -282,26 +317,14 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, val = mt76_get_of_array(np, "mcs", &len, mcs_rates + 1); if (!val) return max_power; + mt76_apply_mcs_limit(dest, mcs_rates, val, len, target_power, + txs_delta, &max_power); - len /= 4; - cur = be32_to_cpu(val[0]); - for (i = 0; i < ARRAY_SIZE(dest->mcs); i++) { - if (len < mcs_rates + 1) - break; - - mt76_apply_array_limit(dest->mcs[i], ARRAY_SIZE(dest->mcs[i]), - val + 1, target_power, txs_delta, - &max_power); - if (--cur > 0) - continue; - - val += mcs_rates + 1; - len -= mcs_rates + 1; - if (!len) - break; - - cur = be32_to_cpu(val[0]); - } + val = mt76_get_of_array(np, "ru", &len, ru_rates + 1); + if (!val) + return max_power; + mt76_apply_mcs_limit(dest, ru_rates, val, len, target_power, + txs_delta, &max_power); return max_power; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 9c5488ffbe5e..d50871653de1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -584,6 +584,7 @@ struct mt76_power_limits { s8 cck[4]; s8 ofdm[8]; s8 mcs[4][10]; + s8 ru[7][12]; }; enum mt76_phy_type { 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, From patchwork Tue Jun 16 12:46:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shayne Chen X-Patchwork-Id: 11607345 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 860D692A for ; Tue, 16 Jun 2020 12:47:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 665232071A for ; Tue, 16 Jun 2020 12:47:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="CVLdvla8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728785AbgFPMrL (ORCPT ); Tue, 16 Jun 2020 08:47:11 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:17214 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728782AbgFPMrL (ORCPT ); Tue, 16 Jun 2020 08:47:11 -0400 X-UUID: 8e5d8c1d343340709e227d0a63e6cc76-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=cFT7b6H2LRT9dSPfnxzcUSZBaTbz+EV+Si2bOMAYrIw=; b=CVLdvla8BrzOiM9OfMgIjTPXh4mzM2WqEjiOy2mRWxf8ypIYwlqIx8kL8kgdfE4XHVcYVWZPKFInxuYz8A7L7npcT9Qb6Rag7t3JYvVkO066bLMDG6SIkkW8DGcMBTXL/NjEUONSzfypvKeoJQCTqLZImcQB2pwyAER2Myidt1Y=; X-UUID: 8e5d8c1d343340709e227d0a63e6cc76-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 1902203524; 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:47:03 +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:47:02 +0800 From: Shayne Chen To: Felix Fietkau CC: linux-wireless , Lorenzo Bianconi , Ryder Lee , Evelyn Tsai , linux-mediatek , Shayne Chen Subject: [PATCH 4/4] mt76: mt7915: add support to read per-rate tx power from HW in debugfs Date: Tue, 16 Jun 2020 20:46:13 +0800 Message-ID: <05dcb80b4bac2e274f2b49479d030588f9dba326.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: 81AD79F399CF7952C93F3F0FD4020AFF4A34E91C3EFF498E24B5505F11A4EFE82000:8 X-MTK: N Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org In the previous version, the values of per-rate tx power are calculated from SW side, but it may be inaccurate if additional limits are applied. This patch adds support for getting per-rate tx power directly from registers. Tested-by: Evelyn Tsai Signed-off-by: Shayne Chen --- .../wireless/mediatek/mt76/mt7915/debugfs.c | 60 +++++++++++++------ .../net/wireless/mediatek/mt76/mt7915/regs.h | 5 ++ 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c index 38f473d587c9..67bc05600190 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c @@ -307,8 +307,8 @@ mt7915_queues_read(struct seq_file *s, void *data) } static void -mt7915_puts_rate_txpower(struct seq_file *s, s8 *delta, - s8 txpower_cur, int band) +mt7915_puts_rate_txpower(struct seq_file *s, struct mt7915_dev *dev, + int band, bool ext_phy) { static const char * const sku_group_name[] = { "CCK", "OFDM", "HT20", "HT40", @@ -316,24 +316,51 @@ mt7915_puts_rate_txpower(struct seq_file *s, s8 *delta, "RU26", "RU52", "RU106", "RU242/SU20", "RU484/SU40", "RU996/SU80", "RU2x996/SU160" }; - s8 txpower[MT7915_SKU_RATE_NUM]; + u32 reg_base = MT_TMAC_FP0R0(ext_phy); int i, idx = 0; - for (i = 0; i < MT7915_SKU_RATE_NUM; i++) - txpower[i] = DIV_ROUND_UP(txpower_cur + delta[i], 2); - for (i = 0; i < MAX_SKU_RATE_GROUP_NUM; i++) { const struct sku_group *sku = &mt7915_sku_groups[i]; u32 offset = sku->offset[band]; + u8 cnt, mcs_num = sku->len; + s8 txpower[12]; + int j; + + if (i == SKU_HT_BW20 || i == SKU_HT_BW40) { + mcs_num = 8; + } else if (i >= SKU_VHT_BW20 && i <= SKU_VHT_BW160) { + mcs_num = 10; + + if (idx == 60) { + reg_base = MT_TMAC_FP0R15(ext_phy); + idx = 0; + } + } else if (i == SKU_HE_RU26) { + reg_base = MT_TMAC_FP0R18(ext_phy); + idx = 0; + } if (!offset) { - idx += sku->len; + idx += mcs_num; continue; } - mt76_seq_puts_array(s, sku_group_name[i], - txpower + idx, sku->len); - idx += sku->len; + for (j = 0, cnt = 0; j < DIV_ROUND_UP(mcs_num, 4); j++) { + u32 val = mt76_rr(dev, reg_base + (idx / 4) * 4); + + if (idx && idx % 4) + val >>= (idx % 4) * 8; + + while (val > 0 && cnt < mcs_num) { + s8 pwr = FIELD_GET(MT_TMAC_FP_MASK, val); + + txpower[cnt++] = pwr; + val >>= 8; + idx++; + } + } + + mt76_seq_puts_array(s, sku_group_name[i], txpower, mcs_num); } } @@ -343,21 +370,16 @@ mt7915_read_rate_txpower(struct seq_file *s, void *data) struct mt7915_dev *dev = dev_get_drvdata(s->private); struct mt76_phy *mphy = &dev->mphy; enum nl80211_band band = mphy->chandef.chan->band; - s8 *delta = dev->rate_power[band]; - s8 txpower_base = mphy->txpower_cur - delta[MT7915_SKU_MAX_DELTA_IDX]; - seq_puts(s, "Band 0:\n"); - mt7915_puts_rate_txpower(s, delta, txpower_base, band); + seq_puts(s, "Band 0: (unit: 0.5 dBm)\n"); + mt7915_puts_rate_txpower(s, dev, band, false); if (dev->mt76.phy2) { mphy = dev->mt76.phy2; band = mphy->chandef.chan->band; - delta = dev->rate_power[band]; - txpower_base = mphy->txpower_cur - - delta[MT7915_SKU_MAX_DELTA_IDX]; - seq_puts(s, "Band 1:\n"); - mt7915_puts_rate_txpower(s, delta, txpower_base, band); + seq_puts(s, "Band 1: (unit: 0.5 dBm)\n"); + mt7915_puts_rate_txpower(s, dev, band, true); } return 0; diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/regs.h b/drivers/net/wireless/mediatek/mt76/mt7915/regs.h index e0989141d9da..afd582fd20a1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/regs.h +++ b/drivers/net/wireless/mediatek/mt76/mt7915/regs.h @@ -67,6 +67,11 @@ #define MT_TMAC_CTCR0_INS_DDLMT_EN BIT(17) #define MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN BIT(18) +#define MT_TMAC_FP0R0(_band) MT_WF_TMAC(_band, 0x020) +#define MT_TMAC_FP0R15(_band) MT_WF_TMAC(_band, 0x080) +#define MT_TMAC_FP0R18(_band) MT_WF_TMAC(_band, 0x270) +#define MT_TMAC_FP_MASK GENMASK(7, 0) + /* DMA Band 0 */ #define MT_WF_DMA_BASE 0x21e00 #define MT_WF_DMA(ofs) (MT_WF_DMA_BASE + (ofs))