Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7105073ybi; Thu, 13 Jun 2019 09:37:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzF9wEPV8wn6K35MK87piA1Hnw71TIh8MtlHEOWPi7RVI12zzWGq/6oztYKjRn+Mek//M3c X-Received: by 2002:a17:90a:bb8b:: with SMTP id v11mr33500pjr.64.1560443875993; Thu, 13 Jun 2019 09:37:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560443875; cv=none; d=google.com; s=arc-20160816; b=nh/iO9TwZmizWmtBx3E9WgQaUl301tizDB7qVoiqD8+F0oXI+4B8Bolgb4Pwo+R4DJ H22biujfzg69z05olxiyrd39F7qObnTFws8gUAAXkesHRRlOo474n9M3pPA79oa39/oN dzoluguNn6hqENPJaR9dKCwG1hBADJbc4wSHCJISek2/PszJdQJXa8sXgD3aQM5Y8U9J S2XODpbpYLgWtcMABvjDowK61CoC2e1kJnxiInP14Dt8JmjOtzTKziUnezIWTyJqBa20 eIDSOiaM7LPxDV2VYMvU/QERnh98m+GPlKBsw0Cn/6ozP8Vg699CPDFILSZwzCc4r/cq SCtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=yYNnzhk6jEAcl5xZESfksZB1PVlDdo0OUihdIHyFaY0=; b=NdssJDwXT7Wy1fW2yqJZhb+Uu5A8IWqln5BYWB6pP9uI1oJwrkZCQMTwG1dE0Yfgii huv5zPq7l8Bz136HUcYLJaH2jneNucxZLIJxAJD4Y+rIzBZSLZE35LTAjzuK84nyTIn1 bUd6qw+hjYDUEFmw7XRMsULtSheu+9z0sFCefFDUh4W8pzPU8Ds9SyjKk43S2fXlHdYW 6fO+VjqW5g3Kb27F0Y5KN2NIFP93uOHWJ2H90T//pJOt6a1VbxuAGg3KU49X5e75SUQ1 s62nFho6rFf8trqa4hAbDUNrb1KFM3iieG/ViEbByHhxYoXVOSoVkFlekascC5Uk5L6q qxjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i22si157250pjx.13.2019.06.13.09.37.40; Thu, 13 Jun 2019 09:37:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392643AbfFMQhb (ORCPT + 99 others); Thu, 13 Jun 2019 12:37:31 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:33523 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730633AbfFMHNp (ORCPT ); Thu, 13 Jun 2019 03:13:45 -0400 X-UUID: 8d11b3f032b84ee7afb6898613a88e4b-20190613 X-UUID: 8d11b3f032b84ee7afb6898613a88e4b-20190613 Received: from mtkmrs01.mediatek.inc [(172.21.131.159)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1719524668; Thu, 13 Jun 2019 15:13:34 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 13 Jun 2019 15:13:33 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 13 Jun 2019 15:13:32 +0800 From: Ryder Lee To: Felix Fietkau , Lorenzo Bianconi CC: Roy Luo , YF Luo , Yiwei Chung , Sean Wang , , , , Ryder Lee Subject: [PATCH v3] mt76: mt7615: add support for per-chain signal strength reporting Date: Thu, 13 Jun 2019 15:13:29 +0800 Message-ID: X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fill in RX status->chain_signal to avoid empty value. Signed-off-by: Ryder Lee --- Changes since v3 - use hweight8 instead. Changes since v2 - correct calculation sequence. --- .../net/wireless/mediatek/mt76/mt7615/mac.c | 22 ++++++++++++++++++- .../net/wireless/mediatek/mt76/mt7615/mac.h | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index b60d42b5923d..1eb0e9c9970c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -13,6 +13,11 @@ #include "../dma.h" #include "mac.h" +static inline s8 to_rssi(u32 field, u32 rxv) +{ + return (FIELD_GET(field, rxv) - 220) / 2; +} + static struct mt76_wcid *mt7615_rx_get_wcid(struct mt7615_dev *dev, u8 idx, bool unicast) { @@ -120,6 +125,7 @@ int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb) if (rxd0 & MT_RXD0_NORMAL_GROUP_3) { u32 rxdg0 = le32_to_cpu(rxd[0]); u32 rxdg1 = le32_to_cpu(rxd[1]); + u32 rxdg3 = le32_to_cpu(rxd[3]); u8 stbc = FIELD_GET(MT_RXV1_HT_STBC, rxdg0); bool cck = false; @@ -169,7 +175,21 @@ int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb) status->enc_flags |= RX_ENC_FLAG_STBC_MASK * stbc; - /* TODO: RSSI */ + status->chains = dev->mt76.antenna_mask; + status->chain_signal[0] = to_rssi(MT_RXV4_RCPI0, rxdg3); + status->chain_signal[1] = to_rssi(MT_RXV4_RCPI1, rxdg3); + status->chain_signal[2] = to_rssi(MT_RXV4_RCPI2, rxdg3); + status->chain_signal[3] = to_rssi(MT_RXV4_RCPI3, rxdg3); + status->signal = status->chain_signal[0]; + + for (i = 1; i < hweight8(dev->mt76.antenna_mask); i++) { + if (!(status->chains & BIT(i))) + continue; + + status->signal = max(status->signal, + status->chain_signal[i]); + } + rxd += 6; if ((u8 *)rxd - skb->data >= skb->len) return -EINVAL; diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.h b/drivers/net/wireless/mediatek/mt76/mt7615/mac.h index 18ad4b8a3807..b00ce8db58e9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.h +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.h @@ -98,6 +98,11 @@ enum rx_pkt_type { #define MT_RXV2_GROUP_ID GENMASK(26, 21) #define MT_RXV2_LENGTH GENMASK(20, 0) +#define MT_RXV4_RCPI3 GENMASK(31, 24) +#define MT_RXV4_RCPI2 GENMASK(23, 16) +#define MT_RXV4_RCPI1 GENMASK(15, 8) +#define MT_RXV4_RCPI0 GENMASK(7, 0) + enum tx_header_format { MT_HDR_FORMAT_802_3, MT_HDR_FORMAT_CMD, -- 2.18.0