diff mbox series

mt76: mt7615: add support for per-chain signal strength reporting

Message ID 3912a2863e858f3623ced61737836e42c7b19149.1560071167.git.ryder.lee@mediatek.com (mailing list archive)
State Superseded
Delegated to: Felix Fietkau
Headers show
Series mt76: mt7615: add support for per-chain signal strength reporting | expand

Commit Message

Ryder Lee June 9, 2019, 9:09 a.m. UTC
Fill in RX status->chain_signal to avoid empty value.

Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
---
 .../net/wireless/mediatek/mt76/mt7615/mac.c   | 30 ++++++++++++++++++-
 .../net/wireless/mediatek/mt76/mt7615/mac.h   |  5 ++++
 2 files changed, 34 insertions(+), 1 deletion(-)

Comments

Sebastian Gottschall June 9, 2019, 2:44 p.m. UTC | #1
according to my findings

MT_RXV4_RCPI1 is part of rx descriptor 4 and not 3
so it must be rxdg4 = rxd[4] etc.
however rxdg3 contains MT_RXV3_IB_RSSIRX which can be used for signal calculation.
i already wrote a similar code for this driver which i sended to felix a long time ago.

my variant looks like
                 status->signal = (FIELD_GET(MT_RXV3_IB_RSSIRX, rxdg3) - 220) / 2;
                 status->chain_signal[0] = (FIELD_GET(MT_RXV4_RCPI0, rxdg4) - 220) / 2;
                 status->chain_signal[1] = (FIELD_GET(MT_RXV4_RCPI1, rxdg4) - 220) / 2;
                 status->chain_signal[2] = (FIELD_GET(MT_RXV4_RCPI2, rxdg4) - 220) / 2;
                 status->chain_signal[3] = (FIELD_GET(MT_RXV4_RCPI3, rxdg4) - 220) / 2;


Am 09.06.2019 um 11:09 schrieb Ryder Lee:
> Fill in RX status->chain_signal to avoid empty value.
>
> Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
> ---
>   .../net/wireless/mediatek/mt76/mt7615/mac.c   | 30 ++++++++++++++++++-
>   .../net/wireless/mediatek/mt76/mt7615/mac.h   |  5 ++++
>   2 files changed, 34 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..9ee83ea11b8c
> --- 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,29 @@ 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->signal = status->chain_signal[0];
> +
> +		switch (status->chains) {
> +		case 0x3:
> +			status->chain_signal[1] = to_rssi(MT_RXV4_RCPI1, rxdg3);
> +			status->signal = max(status->signal,
> +					     status->chain_signal[1]);
> +			break;
> +		case 0x7:
> +			status->chain_signal[2] = to_rssi(MT_RXV4_RCPI2, rxdg3);
> +			status->signal = max(status->signal,
> +					     status->chain_signal[2]);
> +			break;
> +		case 0xf:
> +			status->chain_signal[3] = to_rssi(MT_RXV4_RCPI3, rxdg3);
> +			status->signal = max(status->signal,
> +					     status->chain_signal[3]);
> +			break;
> +		default:
> +			break;
> +		}
>   		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
> --- 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,
Ryder Lee June 10, 2019, 2:09 a.m. UTC | #2
On Sun, 2019-06-09 at 16:44 +0200, Sebastian Gottschall wrote:
> according to my findings
> 
> MT_RXV4_RCPI1 is part of rx descriptor 4 and not 3
> so it must be rxdg4 = rxd[4] etc.

RXV start from 1 in the code.

That is: RXV1 <-> rxdg0, RXV2 <-> rxdg1 ...so RXV4 <-> rxdg3

> however rxdg3 contains MT_RXV3_IB_RSSIRX which can be used for signal calculation.
> i already wrote a similar code for this driver which i sended to felix a long time ago.
> my variant looks like
>                  status->signal = (FIELD_GET(MT_RXV3_IB_RSSIRX, rxdg3) - 220) / 2;
>                  status->chain_signal[0] = (FIELD_GET(MT_RXV4_RCPI0, rxdg4) - 220) / 2;
>                  status->chain_signal[1] = (FIELD_GET(MT_RXV4_RCPI1, rxdg4) - 220) / 2;
>                  status->chain_signal[2] = (FIELD_GET(MT_RXV4_RCPI2, rxdg4) - 220) / 2;
>                  status->chain_signal[3] = (FIELD_GET(MT_RXV4_RCPI3, rxdg4) - 220) / 2;

> Am 09.06.2019 um 11:09 schrieb Ryder Lee:
> > Fill in RX status->chain_signal to avoid empty value.
> >
> > Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
> > ---
> >   .../net/wireless/mediatek/mt76/mt7615/mac.c   | 30 ++++++++++++++++++-
> >   .../net/wireless/mediatek/mt76/mt7615/mac.h   |  5 ++++
> >   2 files changed, 34 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..9ee83ea11b8c
> > --- 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,29 @@ 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->signal = status->chain_signal[0];
> > +
> > +		switch (status->chains) {
> > +		case 0x3:
> > +			status->chain_signal[1] = to_rssi(MT_RXV4_RCPI1, rxdg3);
> > +			status->signal = max(status->signal,
> > +					     status->chain_signal[1]);
> > +			break;
> > +		case 0x7:
> > +			status->chain_signal[2] = to_rssi(MT_RXV4_RCPI2, rxdg3);
> > +			status->signal = max(status->signal,
> > +					     status->chain_signal[2]);
> > +			break;
> > +		case 0xf:
> > +			status->chain_signal[3] = to_rssi(MT_RXV4_RCPI3, rxdg3);
> > +			status->signal = max(status->signal,
> > +					     status->chain_signal[3]);
> > +			break;
> > +		default:
> > +			break;
> > +		}
> >   		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
> > --- 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,
> 
> _______________________________________________
> Linux-mediatek mailing list
> Linux-mediatek@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-mediatek
Ryder Lee June 10, 2019, 4:22 a.m. UTC | #3
On Mon, 2019-06-10 at 10:09 +0800, Ryder Lee wrote:
> On Sun, 2019-06-09 at 16:44 +0200, Sebastian Gottschall wrote:
> > according to my findings
> > 
> > MT_RXV4_RCPI1 is part of rx descriptor 4 and not 3
> > so it must be rxdg4 = rxd[4] etc.
> 
> RXV start from 1 in the code.
> 
> That is: RXV1 <-> rxdg0, RXV2 <-> rxdg1 ...so RXV4 <-> rxdg3
> 
> > however rxdg3 contains MT_RXV3_IB_RSSIRX which can be used for signal calculation.
> > i already wrote a similar code for this driver which i sended to felix a long time ago.
> > my variant looks like
> >                  status->signal = (FIELD_GET(MT_RXV3_IB_RSSIRX, rxdg3) - 220) / 2;
> >                  status->chain_signal[0] = (FIELD_GET(MT_RXV4_RCPI0, rxdg4) - 220) / 2;
> >                  status->chain_signal[1] = (FIELD_GET(MT_RXV4_RCPI1, rxdg4) - 220) / 2;
> >                  status->chain_signal[2] = (FIELD_GET(MT_RXV4_RCPI2, rxdg4) - 220) / 2;
> >                  status->chain_signal[3] = (FIELD_GET(MT_RXV4_RCPI3, rxdg4) - 220) / 2;

mt7615 actually doesn't use in-band RSSI for signal calculation, but it
occurs to me that i should modify the code to compare per-chain's
signal. Something like this:

		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];

		switch (status->chains) {
		case 0xf:
			status->signal = max(status->signal,
					     status->chain_signal[3]);
		case 0x7:
			status->signal = max(status->signal,
					     status->chain_signal[2]);
		case 0x3:
			status->signal = max(status->signal,
					     status->chain_signal[1]);
			break;
		default:
			break;
		}


I could send a v2 or you can take care of that.

Ryder
Sebastian Gottschall June 10, 2019, 4:47 a.m. UTC | #4
okay. curious is, that my variant works with sane results too.
i will test your variant and check the results

Sebastian

Am 10.06.2019 um 06:22 schrieb Ryder Lee:
> On Mon, 2019-06-10 at 10:09 +0800, Ryder Lee wrote:
>> On Sun, 2019-06-09 at 16:44 +0200, Sebastian Gottschall wrote:
>>> according to my findings
>>>
>>> MT_RXV4_RCPI1 is part of rx descriptor 4 and not 3
>>> so it must be rxdg4 = rxd[4] etc.
>> RXV start from 1 in the code.
>>
>> That is: RXV1 <-> rxdg0, RXV2 <-> rxdg1 ...so RXV4 <-> rxdg3
>>
>>> however rxdg3 contains MT_RXV3_IB_RSSIRX which can be used for signal calculation.
>>> i already wrote a similar code for this driver which i sended to felix a long time ago.
>>> my variant looks like
>>>                   status->signal = (FIELD_GET(MT_RXV3_IB_RSSIRX, rxdg3) - 220) / 2;
>>>                   status->chain_signal[0] = (FIELD_GET(MT_RXV4_RCPI0, rxdg4) - 220) / 2;
>>>                   status->chain_signal[1] = (FIELD_GET(MT_RXV4_RCPI1, rxdg4) - 220) / 2;
>>>                   status->chain_signal[2] = (FIELD_GET(MT_RXV4_RCPI2, rxdg4) - 220) / 2;
>>>                   status->chain_signal[3] = (FIELD_GET(MT_RXV4_RCPI3, rxdg4) - 220) / 2;
> mt7615 actually doesn't use in-band RSSI for signal calculation, but it
> occurs to me that i should modify the code to compare per-chain's
> signal. Something like this:
>
> 		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];
>
> 		switch (status->chains) {
> 		case 0xf:
> 			status->signal = max(status->signal,
> 					     status->chain_signal[3]);
> 		case 0x7:
> 			status->signal = max(status->signal,
> 					     status->chain_signal[2]);
> 		case 0x3:
> 			status->signal = max(status->signal,
> 					     status->chain_signal[1]);
> 			break;
> 		default:
> 			break;
> 		}
>
>
> I could send a v2 or you can take care of that.
>
> Ryder
>
>
Ryder Lee June 10, 2019, 7:12 a.m. UTC | #5
On Mon, 2019-06-10 at 06:47 +0200, Sebastian Gottschall wrote:
> okay. curious is, that my variant works with sane results too.
> i will test your variant and check the results
> 
> Sebastian

Please don't top post as it's hard to track the thread.

More specifically, IBRSSI is obtained from packet's L-STF portion and
MTK HW PD (packet detection) will take it as a reference. (with
variation more or less)

As for RCPI which is calculated from packet's data portion. The other
MTK chipsets may use IBRSSI as their baseband couldn't report RCPI.

Ryder

> Am 10.06.2019 um 06:22 schrieb Ryder Lee:
> > On Mon, 2019-06-10 at 10:09 +0800, Ryder Lee wrote:
> >> On Sun, 2019-06-09 at 16:44 +0200, Sebastian Gottschall wrote:
> >>> according to my findings
> >>>
> >>> MT_RXV4_RCPI1 is part of rx descriptor 4 and not 3
> >>> so it must be rxdg4 = rxd[4] etc.
> >> RXV start from 1 in the code.
> >>
> >> That is: RXV1 <-> rxdg0, RXV2 <-> rxdg1 ...so RXV4 <-> rxdg3
> >>
> >>> however rxdg3 contains MT_RXV3_IB_RSSIRX which can be used for signal calculation.
> >>> i already wrote a similar code for this driver which i sended to felix a long time ago.
> >>> my variant looks like
> >>>                   status->signal = (FIELD_GET(MT_RXV3_IB_RSSIRX, rxdg3) - 220) / 2;
> >>>                   status->chain_signal[0] = (FIELD_GET(MT_RXV4_RCPI0, rxdg4) - 220) / 2;
> >>>                   status->chain_signal[1] = (FIELD_GET(MT_RXV4_RCPI1, rxdg4) - 220) / 2;
> >>>                   status->chain_signal[2] = (FIELD_GET(MT_RXV4_RCPI2, rxdg4) - 220) / 2;
> >>>                   status->chain_signal[3] = (FIELD_GET(MT_RXV4_RCPI3, rxdg4) - 220) / 2;
> > mt7615 actually doesn't use in-band RSSI for signal calculation, but it
> > occurs to me that i should modify the code to compare per-chain's
> > signal. Something like this:
> >
> > 		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];
> >
> > 		switch (status->chains) {
> > 		case 0xf:
> > 			status->signal = max(status->signal,
> > 					     status->chain_signal[3]);
> > 		case 0x7:
> > 			status->signal = max(status->signal,
> > 					     status->chain_signal[2]);
> > 		case 0x3:
> > 			status->signal = max(status->signal,
> > 					     status->chain_signal[1]);
> > 			break;
> > 		default:
> > 			break;
> > 		}
> >
> >
> > I could send a v2 or you can take care of that.
> >
> > Ryder
> >
> >
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
index b60d42b5923d..9ee83ea11b8c
--- 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,29 @@  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->signal = status->chain_signal[0];
+
+		switch (status->chains) {
+		case 0x3:
+			status->chain_signal[1] = to_rssi(MT_RXV4_RCPI1, rxdg3);
+			status->signal = max(status->signal,
+					     status->chain_signal[1]);
+			break;
+		case 0x7:
+			status->chain_signal[2] = to_rssi(MT_RXV4_RCPI2, rxdg3);
+			status->signal = max(status->signal,
+					     status->chain_signal[2]);
+			break;
+		case 0xf:
+			status->chain_signal[3] = to_rssi(MT_RXV4_RCPI3, rxdg3);
+			status->signal = max(status->signal,
+					     status->chain_signal[3]);
+			break;
+		default:
+			break;
+		}
 		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
--- 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,