linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* PROBLEM: rt2800lib return -128db when signal is stronger than -12db
@ 2012-01-30 14:23 Luigi Tarenga
  2012-01-31 14:05 ` Stanislaw Gruszka
  0 siblings, 1 reply; 2+ messages in thread
From: Luigi Tarenga @ 2012-01-30 14:23 UTC (permalink / raw)
  To: Ivo van Doorn, Gertjan van Wingerde, Helmut Schaa; +Cc: linux-wireless, users

Hi,
I found that my rt2870 sometimes report -128db signal when very near to AP or
using a hi-gain antenna such a waveguide (checked from iw and nm-applet).
I found that the rssi from the hardware is a signed from -13db
(strongest signal)
to positive number (bigger is weaker) while the 0 is treated as error condition
but there is an error in casting the value when retrieved from the hardware.
I changed the type of the variables so the cast is correct and when i
get -13 rssi
from hw i return 0 db from the function.

attached the patch against linux-3.2.2 (my very first Linux patch :P).

Luigi

--- a/drivers/net/wireless/rt2x00/rt2800lib.c	2012-01-30
12:48:15.779238642 +0100
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c	2012-01-30
15:09:30.694287624 +0100
@@ -514,9 +514,9 @@

 static int rt2800_agc_to_rssi(struct rt2x00_dev *rt2x00dev, u32 rxwi_w2)
 {
-	int rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
-	int rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
-	int rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
+	s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
+	s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
+	s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
 	u16 eeprom;
 	u8 offset0;
 	u8 offset1;
@@ -539,11 +539,12 @@
 	/*
 	 * Convert the value from the descriptor into the RSSI value
 	 * If the value in the descriptor is 0, it is considered invalid
-	 * and the default (extremely low) rssi value is assumed
+	 * and the default (extremely low) rssi value is assumed.
+         * HW rssiX values go from -13 (strongest) to positive number
(weakest).
 	 */
-	rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
-	rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
-	rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;
+	rssi0 = (rssi0) ? (-13 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
+	rssi1 = (rssi1) ? (-13 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
+	rssi2 = (rssi2) ? (-13 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;

 	/*
 	 * mac80211 only accepts a single RSSI value. Calculating the
@@ -552,7 +553,7 @@
 	 * which gives less energy...
 	 */
 	rssi0 = max(rssi0, rssi1);
-	return max(rssi0, rssi2);
+	return (int)max(rssi0, rssi2);
 }

 void rt2800_process_rxwi(struct queue_entry *entry,

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

* Re: PROBLEM: rt2800lib return -128db when signal is stronger than -12db
  2012-01-30 14:23 PROBLEM: rt2800lib return -128db when signal is stronger than -12db Luigi Tarenga
@ 2012-01-31 14:05 ` Stanislaw Gruszka
  0 siblings, 0 replies; 2+ messages in thread
From: Stanislaw Gruszka @ 2012-01-31 14:05 UTC (permalink / raw)
  To: Luigi Tarenga
  Cc: Ivo van Doorn, Gertjan van Wingerde, Helmut Schaa, linux-wireless,
	users

On Mon, Jan 30, 2012 at 03:23:15PM +0100, Luigi Tarenga wrote:
> -	int rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
> -	int rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
> -	int rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
> +	s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
> +	s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
> +	s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
>  	u16 eeprom;
>  	u8 offset0;
>  	u8 offset1;
> @@ -539,11 +539,12 @@
>  	/*
>  	 * Convert the value from the descriptor into the RSSI value
>  	 * If the value in the descriptor is 0, it is considered invalid
> -	 * and the default (extremely low) rssi value is assumed
> +	 * and the default (extremely low) rssi value is assumed.
> +         * HW rssiX values go from -13 (strongest) to positive number
> (weakest).
>  	 */
> -	rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
> -	rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
> -	rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;
> +	rssi0 = (rssi0) ? (-13 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
> +	rssi1 = (rssi1) ? (-13 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
> +	rssi2 = (rssi2) ? (-13 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;

Not sure if change -12 to -13 is needed, seems not compatible with
vendor driver. If you just change rssiX type to s8, will it
fix the problem? That seems to be correct and enough to fix
(example why this make difference: 0xc0 gives s8: -64 int: 192).

If you will be reposting please follow
http://linux.yyz.us/patch-format.html
especially add Signed-off-by: line.

Thanks
Stanislaw

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

end of thread, other threads:[~2012-01-31 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-30 14:23 PROBLEM: rt2800lib return -128db when signal is stronger than -12db Luigi Tarenga
2012-01-31 14:05 ` Stanislaw Gruszka

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).