linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info
       [not found] <cover.1548587542.git.lorenzo.bianconi@redhat.com>
@ 2019-01-27 11:15 ` Lorenzo Bianconi
  2019-01-28 20:07   ` Kalle Valo
  2019-01-31 16:56   ` Kalle Valo
  0 siblings, 2 replies; 8+ messages in thread
From: Lorenzo Bianconi @ 2019-01-27 11:15 UTC (permalink / raw)
  To: linux-wireless; +Cc: nbd, sgruszka

Report correct eeprom per channel power value.
Fix chan_vs_power map in mt76x0_get_power_info routine

Fixes: f2a2e819d672 ("mt76x0: remove eeprom dependency from mt76x0_get_power_info")
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 .../wireless/mediatek/mt76/mt76x0/eeprom.c    | 40 +++++++++----------
 .../wireless/mediatek/mt76/mt76x0/eeprom.h    |  2 +-
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   | 10 ++---
 3 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
index 497e762978cc..b2cabce1d74d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
@@ -212,24 +212,24 @@ void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev)
 	mt76x02_add_rate_power_offset(t, delta);
 }
 
-void mt76x0_get_power_info(struct mt76x02_dev *dev, u8 *info)
+void mt76x0_get_power_info(struct mt76x02_dev *dev, s8 *tp)
 {
 	struct mt76x0_chan_map {
 		u8 chan;
 		u8 offset;
 	} chan_map[] = {
-		{   2,  0 }, {   4,  1 }, {   6,  2 }, {   8,  3 },
-		{  10,  4 }, {  12,  5 }, {  14,  6 }, {  38,  0 },
-		{  44,  1 }, {  48,  2 }, {  54,  3 }, {  60,  4 },
-		{  64,  5 }, { 102,  6 }, { 108,  7 }, { 112,  8 },
-		{ 118,  9 }, { 124, 10 }, { 128, 11 }, { 134, 12 },
-		{ 140, 13 }, { 151, 14 }, { 157, 15 }, { 161, 16 },
-		{ 167, 17 }, { 171, 18 }, { 173, 19 },
+		{   2,  0 }, {   4,  2 }, {   6,  4 }, {   8,  6 },
+		{  10,  8 }, {  12, 10 }, {  14, 12 }, {  38,  0 },
+		{  44,  2 }, {  48,  4 }, {  54,  6 }, {  60,  8 },
+		{  64, 10 }, { 102, 12 }, { 108, 14 }, { 112, 16 },
+		{ 118, 18 }, { 124, 20 }, { 128, 22 }, { 134, 24 },
+		{ 140, 26 }, { 151, 28 }, { 157, 30 }, { 161, 32 },
+		{ 167, 34 }, { 171, 36 }, { 175, 38 },
 	};
 	struct ieee80211_channel *chan = dev->mt76.chandef.chan;
 	u8 offset, addr;
+	int i, idx = 0;
 	u16 data;
-	int i;
 
 	if (mt76x0_tssi_enabled(dev)) {
 		s8 target_power;
@@ -239,14 +239,14 @@ void mt76x0_get_power_info(struct mt76x02_dev *dev, u8 *info)
 		else
 			data = mt76x02_eeprom_get(dev, MT_EE_2G_TARGET_POWER);
 		target_power = (data & 0xff) - dev->mt76.rate_power.ofdm[7];
-		info[0] = target_power + mt76x0_get_delta(dev);
-		info[1] = 0;
+		*tp = target_power + mt76x0_get_delta(dev);
 
 		return;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(chan_map); i++) {
-		if (chan_map[i].chan <= chan->hw_value) {
+		if (chan->hw_value <= chan_map[i].chan) {
+			idx = (chan->hw_value == chan_map[i].chan);
 			offset = chan_map[i].offset;
 			break;
 		}
@@ -258,13 +258,16 @@ void mt76x0_get_power_info(struct mt76x02_dev *dev, u8 *info)
 		addr = MT_EE_TX_POWER_DELTA_BW80 + offset;
 	} else {
 		switch (chan->hw_value) {
+		case 42:
+			offset = 2;
+			break;
 		case 58:
 			offset = 8;
 			break;
 		case 106:
 			offset = 14;
 			break;
-		case 112:
+		case 122:
 			offset = 20;
 			break;
 		case 155:
@@ -277,14 +280,9 @@ void mt76x0_get_power_info(struct mt76x02_dev *dev, u8 *info)
 	}
 
 	data = mt76x02_eeprom_get(dev, addr);
-
-	info[0] = data;
-	if (!info[0] || info[0] > 0x3f)
-		info[0] = 5;
-
-	info[1] = data >> 8;
-	if (!info[1] || info[1] > 0x3f)
-		info[1] = 5;
+	*tp = data >> (8 * idx);
+	if (*tp < 0 || *tp > 0x3f)
+		*tp = 5;
 }
 
 static int mt76x0_check_eeprom(struct mt76x02_dev *dev)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h
index ee9ade9f3c8b..42b259f90b6d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h
@@ -26,7 +26,7 @@ struct mt76x02_dev;
 int mt76x0_eeprom_init(struct mt76x02_dev *dev);
 void mt76x0_read_rx_gain(struct mt76x02_dev *dev);
 void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev);
-void mt76x0_get_power_info(struct mt76x02_dev *dev, u8 *info);
+void mt76x0_get_power_info(struct mt76x02_dev *dev, s8 *tp);
 
 static inline s8 s6_to_s8(u32 val)
 {
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index 1eb1a802ed20..b6166703ad76 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -845,17 +845,17 @@ static void mt76x0_phy_tssi_calibrate(struct mt76x02_dev *dev)
 void mt76x0_phy_set_txpower(struct mt76x02_dev *dev)
 {
 	struct mt76_rate_power *t = &dev->mt76.rate_power;
-	u8 info[2];
+	s8 info;
 
 	mt76x0_get_tx_power_per_rate(dev);
-	mt76x0_get_power_info(dev, info);
+	mt76x0_get_power_info(dev, &info);
 
-	mt76x02_add_rate_power_offset(t, info[0]);
+	mt76x02_add_rate_power_offset(t, info);
 	mt76x02_limit_rate_power(t, dev->mt76.txpower_conf);
 	dev->mt76.txpower_cur = mt76x02_get_max_rate_power(t);
-	mt76x02_add_rate_power_offset(t, -info[0]);
+	mt76x02_add_rate_power_offset(t, -info);
 
-	mt76x02_phy_set_txpower(dev, info[0], info[1]);
+	mt76x02_phy_set_txpower(dev, info, info);
 }
 
 void mt76x0_phy_calibrate(struct mt76x02_dev *dev, bool power_on)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info
  2019-01-27 11:15 ` [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info Lorenzo Bianconi
@ 2019-01-28 20:07   ` Kalle Valo
  2019-01-28 20:50     ` Lorenzo Bianconi
  2019-01-31 16:56   ` Kalle Valo
  1 sibling, 1 reply; 8+ messages in thread
From: Kalle Valo @ 2019-01-28 20:07 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: linux-wireless, nbd, sgruszka

Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:

> Report correct eeprom per channel power value.
> Fix chan_vs_power map in mt76x0_get_power_info routine
>
> Fixes: f2a2e819d672 ("mt76x0: remove eeprom dependency from mt76x0_get_power_info")
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>

So what's the actual bug this fixes? The commit log is not really clear
on that. Wondering because you marked this for wireless-drivers.

-- 
Kalle Valo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info
  2019-01-28 20:07   ` Kalle Valo
@ 2019-01-28 20:50     ` Lorenzo Bianconi
  2019-01-29  7:08       ` Kalle Valo
  0 siblings, 1 reply; 8+ messages in thread
From: Lorenzo Bianconi @ 2019-01-28 20:50 UTC (permalink / raw)
  To: Kalle Valo; +Cc: linux-wireless, nbd, sgruszka

> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
> 
> > Report correct eeprom per channel power value.
> > Fix chan_vs_power map in mt76x0_get_power_info routine
> >
> > Fixes: f2a2e819d672 ("mt76x0: remove eeprom dependency from mt76x0_get_power_info")
> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> 
> So what's the actual bug this fixes? The commit log is not really clear
> on that. Wondering because you marked this for wireless-drivers.

Hi Kalle,

You are right, I have been not so clear in the commit log.
Offsets in chan_map were wrong since mt76x02_eeprom_get() reads at even addresses.
Moreover 'if' condition in the for loop was wrong (chan->hw_value and
chan_map[i].chan were swapped)

Regards,
Lorenzo

> 
> -- 
> Kalle Valo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info
  2019-01-28 20:50     ` Lorenzo Bianconi
@ 2019-01-29  7:08       ` Kalle Valo
  2019-01-29  7:28         ` Lorenzo Bianconi
  0 siblings, 1 reply; 8+ messages in thread
From: Kalle Valo @ 2019-01-29  7:08 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: linux-wireless, nbd, sgruszka

Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:

>> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
>> 
>> > Report correct eeprom per channel power value.
>> > Fix chan_vs_power map in mt76x0_get_power_info routine
>> >
>> > Fixes: f2a2e819d672 ("mt76x0: remove eeprom dependency from mt76x0_get_power_info")
>> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
>> 
>> So what's the actual bug this fixes? The commit log is not really clear
>> on that. Wondering because you marked this for wireless-drivers.
>
> Hi Kalle,
>
> You are right, I have been not so clear in the commit log.
> Offsets in chan_map were wrong since mt76x02_eeprom_get() reads at even addresses.
> Moreover 'if' condition in the for loop was wrong (chan->hw_value and
> chan_map[i].chan were swapped)

But how does this affect from user's point of view? I mean what feature
is broken and how does this fix that?

-- 
Kalle Valo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info
  2019-01-29  7:08       ` Kalle Valo
@ 2019-01-29  7:28         ` Lorenzo Bianconi
  2019-01-29  9:53           ` Kalle Valo
  0 siblings, 1 reply; 8+ messages in thread
From: Lorenzo Bianconi @ 2019-01-29  7:28 UTC (permalink / raw)
  To: Kalle Valo; +Cc: linux-wireless, Felix Fietkau, Stanislaw Gruszka

>
> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
>
> >> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
> >>
> >> > Report correct eeprom per channel power value.
> >> > Fix chan_vs_power map in mt76x0_get_power_info routine
> >> >
> >> > Fixes: f2a2e819d672 ("mt76x0: remove eeprom dependency from mt76x0_get_power_info")
> >> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> >>
> >> So what's the actual bug this fixes? The commit log is not really clear
> >> on that. Wondering because you marked this for wireless-drivers.
> >
> > Hi Kalle,
> >
> > You are right, I have been not so clear in the commit log.
> > Offsets in chan_map were wrong since mt76x02_eeprom_get() reads at even addresses.
> > Moreover 'if' condition in the for loop was wrong (chan->hw_value and
> > chan_map[i].chan were swapped)
>
> But how does this affect from user's point of view? I mean what feature
> is broken and how does this fix that?
>
> --
> Kalle Valo

mt76x0_get_power_info() is used to read from eeprom the global max tx
power according to the operating channel.
mt76x02_eeprom_get() reads just at even addresses and it reports -1
for odd ones (so offset must be a even).
This issue will affect the tx power that userspace is able to configure.
Do you think it is better to merge it in wireless-drivers-next?

Regards,
Lorenzo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info
  2019-01-29  7:28         ` Lorenzo Bianconi
@ 2019-01-29  9:53           ` Kalle Valo
  2019-01-29  9:57             ` Lorenzo Bianconi
  0 siblings, 1 reply; 8+ messages in thread
From: Kalle Valo @ 2019-01-29  9:53 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: linux-wireless, Felix Fietkau, Stanislaw Gruszka

Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:

>>
>> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
>>
>> >> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
>> >>
>> >> > Report correct eeprom per channel power value.
>> >> > Fix chan_vs_power map in mt76x0_get_power_info routine
>> >> >
>> >> > Fixes: f2a2e819d672 ("mt76x0: remove eeprom dependency from mt76x0_get_power_info")
>> >> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
>> >>
>> >> So what's the actual bug this fixes? The commit log is not really clear
>> >> on that. Wondering because you marked this for wireless-drivers.
>> >
>> > Hi Kalle,
>> >
>> > You are right, I have been not so clear in the commit log.
>> > Offsets in chan_map were wrong since mt76x02_eeprom_get() reads at even addresses.
>> > Moreover 'if' condition in the for loop was wrong (chan->hw_value and
>> > chan_map[i].chan were swapped)
>>
>> But how does this affect from user's point of view? I mean what feature
>> is broken and how does this fix that?
>>
>> --
>> Kalle Valo
>
> mt76x0_get_power_info() is used to read from eeprom the global max tx
> power according to the operating channel.
> mt76x02_eeprom_get() reads just at even addresses and it reports -1
> for odd ones (so offset must be a even).
> This issue will affect the tx power that userspace is able to configure.
> Do you think it is better to merge it in wireless-drivers-next?

Ok, I think this is fine for wireless-drivers. I just want to understand
the bug being fixed before I apply the patch to w-d.

If no objections I'll queue this for 5.0.

-- 
Kalle Valo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info
  2019-01-29  9:53           ` Kalle Valo
@ 2019-01-29  9:57             ` Lorenzo Bianconi
  0 siblings, 0 replies; 8+ messages in thread
From: Lorenzo Bianconi @ 2019-01-29  9:57 UTC (permalink / raw)
  To: Kalle Valo; +Cc: linux-wireless, Felix Fietkau, Stanislaw Gruszka

> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
> 
> >>
> >> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
> >>
> >> >> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
> >> >>
> >> >> > Report correct eeprom per channel power value.
> >> >> > Fix chan_vs_power map in mt76x0_get_power_info routine
> >> >> >
> >> >> > Fixes: f2a2e819d672 ("mt76x0: remove eeprom dependency from mt76x0_get_power_info")
> >> >> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> >> >>
> >> >> So what's the actual bug this fixes? The commit log is not really clear
> >> >> on that. Wondering because you marked this for wireless-drivers.
> >> >
> >> > Hi Kalle,
> >> >
> >> > You are right, I have been not so clear in the commit log.
> >> > Offsets in chan_map were wrong since mt76x02_eeprom_get() reads at even addresses.
> >> > Moreover 'if' condition in the for loop was wrong (chan->hw_value and
> >> > chan_map[i].chan were swapped)
> >>
> >> But how does this affect from user's point of view? I mean what feature
> >> is broken and how does this fix that?
> >>
> >> --
> >> Kalle Valo
> >
> > mt76x0_get_power_info() is used to read from eeprom the global max tx
> > power according to the operating channel.
> > mt76x02_eeprom_get() reads just at even addresses and it reports -1
> > for odd ones (so offset must be a even).
> > This issue will affect the tx power that userspace is able to configure.
> > Do you think it is better to merge it in wireless-drivers-next?
> 
> Ok, I think this is fine for wireless-drivers. I just want to understand
> the bug being fixed before I apply the patch to w-d.
> 
> If no objections I'll queue this for 5.0.

ack, thx. I will be more clear next time :)

Regards,
Lorenzo

> 
> -- 
> Kalle Valo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info
  2019-01-27 11:15 ` [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info Lorenzo Bianconi
  2019-01-28 20:07   ` Kalle Valo
@ 2019-01-31 16:56   ` Kalle Valo
  1 sibling, 0 replies; 8+ messages in thread
From: Kalle Valo @ 2019-01-31 16:56 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: linux-wireless, nbd, sgruszka

Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:

> Report correct eeprom per channel power value.
> Fix chan_vs_power map in mt76x0_get_power_info routine
> 
> Fixes: f2a2e819d672 ("mt76x0: remove eeprom dependency from mt76x0_get_power_info")
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>

Patch applied to wireless-drivers.git, thanks.

05672636b339 mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info

-- 
https://patchwork.kernel.org/patch/10782801/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-01-31 16:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1548587542.git.lorenzo.bianconi@redhat.com>
2019-01-27 11:15 ` [PATCH wireless-drivers] mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info Lorenzo Bianconi
2019-01-28 20:07   ` Kalle Valo
2019-01-28 20:50     ` Lorenzo Bianconi
2019-01-29  7:08       ` Kalle Valo
2019-01-29  7:28         ` Lorenzo Bianconi
2019-01-29  9:53           ` Kalle Valo
2019-01-29  9:57             ` Lorenzo Bianconi
2019-01-31 16:56   ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).