Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7875143rwb; Wed, 23 Nov 2022 12:00:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf46wN8VlZBLGU0GTxTs8bciciLhYZWMD88Rutk7Vzwvf92LboW/HmHcuecs0SvAe4HS7Grp X-Received: by 2002:a63:1a55:0:b0:477:4ba4:c278 with SMTP id a21-20020a631a55000000b004774ba4c278mr10058645pgm.482.1669233624174; Wed, 23 Nov 2022 12:00:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669233624; cv=none; d=google.com; s=arc-20160816; b=Q+Zb9OLCr+w5Dv9qDUmC+F3Lpx8io3Mzv0ZitFXw5ojhr27SRu5x8N7ywRyzOWX7H2 H1awXp4Y1n4DnX48/rKN36OzNsC7JqoV0c2RltospDnvFQl+5EdGjSu+Qh/A4jQOf9w3 R/weRiGIify5X8V4QnGI4U0TO5S1+xub5hbv9Ixo6kZOvpCYtRZo9IwTYYTFS33HxXKE ou/+3wRoPasl6nC3A15RlrBtuyHdT2JPesQEjayUeXMxFmxIXImaxNwtlG1Q0gIqjjoR kAKNB9QD3reJlsXHAD0vU+p4clEx6klDoJEpnvIa/NEYtZl7ibHGNFEXY5dbMtgLIPEj wOQQ== 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 :dkim-signature; bh=/bGL7NeH7E4fkHcQ5YBrB8gRbZfK+h45aAwfGCIDyJQ=; b=e997lpLe3Ee5i55BtYHeE/9U6we+eP0jBkzNHqPrrRnkXIpmcfyi+Jtlzwvkl4a6Ue J+gES3JJHh08SszpBxuVCvOq7iSWsKzncHMBamPdbR7DGQ2wGI3Xk7L9Y5e9ugUYnmLr 0GEyc8d2ihUDLg1xi/rncOJYAADaCEElw1f72EP93Q7iavUVcwfUDWmnEwg4O5fIgnbH Hm5G5ckI+QbO7X7xtorgQxYJIN+UVG5B9MGQbEWqJYuOp0hFMtfm4vdrqZwdfkNlZ5Ac w4vCkUE6YNXvEKs3QdXYMGNN04BWhocMSYz+ir9mv2sFp+ZHGEkoV5o7TmK6ygZBFYXM JUSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=AaiMVNcp; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a170903244c00b00186ada5d4e2si1654012pls.215.2022.11.23.12.00.15; Wed, 23 Nov 2022 12:00:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=AaiMVNcp; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238720AbiKWUAE (ORCPT + 68 others); Wed, 23 Nov 2022 15:00:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239478AbiKWT7x (ORCPT ); Wed, 23 Nov 2022 14:59:53 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6554B78D53 for ; Wed, 23 Nov 2022 11:59:19 -0800 (PST) X-UUID: 83ff6d3fa9a440879ba0c39cedbe5873-20221124 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=/bGL7NeH7E4fkHcQ5YBrB8gRbZfK+h45aAwfGCIDyJQ=; b=AaiMVNcphGzYub0M69f6BwTCbZpoqdmLcQNXn8/MFytlqQhLJlbcSd4yYlaXtMtjwkbKPflFLxLQqZimsj7kS2ZWZhyMPvLwAHXoZ4No6dM/+5nYevAxf/XHZ+WM+PooOMaGxsOBgza5WIm27RkAn+56+5+G/3+FeDw8pb9TLiA=; X-CID-CACHE: Type:Local,Time:202211240337+08,HitQuantity:1 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.13,REQID:dfd93491-44b4-40cc-a6c1-0fcb50f88c32,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:d12e911,CLOUDID:b2221ff9-3a34-4838-abcf-dfedf9dd068e,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 83ff6d3fa9a440879ba0c39cedbe5873-20221124 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1020878835; Thu, 24 Nov 2022 03:59:14 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Thu, 24 Nov 2022 03:59:12 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Thu, 24 Nov 2022 03:59:12 +0800 From: Ryder Lee To: Felix Fietkau , CC: Lorenzo Bianconi , Shayne Chen , Evelyn Tsai , , Ryder Lee Subject: [PATCH v2 1/2] wifi: mt76: mt7915: introduce mt7915_get_power_bound() Date: Thu, 24 Nov 2022 03:59:10 +0800 Message-ID: <9a67f1617249be2c73bb5900d2df971b682f8772.1669232969.git.ryder.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Add a helper for common boundary check. This is a preliminary patch to add per bandwidth power control. Signed-off-by: Ryder Lee --- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 12 +++++------- drivers/net/wireless/mediatek/mt76/mt7915/mcu.h | 12 ++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c index f329705c4fa1..8a2546699c3b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c @@ -3122,14 +3122,14 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy, .txpower_max = DIV_ROUND_UP(mphy->txpower_cur, 2), .wcid = cpu_to_le16(msta->wcid.idx), }; - int ret, n_chains = hweight8(mphy->antenna_mask); + int ret; s8 txpower_sku[MT7915_SKU_RATE_NUM]; ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku)); if (ret) return ret; - txpower = txpower * 2 - mt76_tx_power_nss_delta(n_chains); + txpower = mt7915_get_power_bound(phy, txpower); if (txpower > mphy->txpower_cur || txpower < 0) return -EINVAL; @@ -3181,12 +3181,10 @@ int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy) }; struct mt76_power_limits limits_array; s8 *la = (s8 *)&limits_array; - int i, idx, n_chains = hweight8(mphy->antenna_mask); - int tx_power = hw->conf.power_level * 2; + int i, idx; + int tx_power; - tx_power = mt76_get_sar_power(mphy, mphy->chandef.chan, - tx_power); - tx_power -= mt76_tx_power_nss_delta(n_chains); + tx_power = mt7915_get_power_bound(phy, hw->conf.power_level); tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan, &limits_array, tx_power); mphy->txpower_cur = tx_power; diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h index 46c517e50ae4..382dcbda50bb 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h @@ -509,4 +509,16 @@ enum { sizeof(struct bss_info_bcn_cont) + \ sizeof(struct bss_info_inband_discovery)) +static inline s8 +mt7915_get_power_bound(struct mt7915_phy *phy, s8 txpower) +{ + struct mt76_phy *mphy = phy->mt76; + int n_chains = hweight8(mphy->antenna_mask); + + txpower = mt76_get_sar_power(mphy, mphy->chandef.chan, txpower * 2); + txpower -= mt76_tx_power_nss_delta(n_chains); + + return txpower; +} + #endif -- 2.36.1