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 {