All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
@ 2010-11-07 13:51 Hin-Tak Leung
  0 siblings, 0 replies; 9+ messages in thread
From: Hin-Tak Leung @ 2010-11-07 13:51 UTC (permalink / raw)
  To: Herton Ronaldo Krzesinski, Larry Finger
  Cc: Thadeu Lima de Souza Cascardo, linux-wireless, John W Linville, seno

[-- Attachment #1: Type: text/plain, Size: 670 bytes --]

--- On Sun, 7/11/10, Larry Finger <Larry.Finger@lwfinger.net> wrote:

> > Do you have any pointer to it? (I can't find in the
> archives in April
> > 9 2009). Never saw it, if was posted in the mailing
> list certainly
> > missed it (and probably I was not in CC).
> 
> There is a reference to it at
> http://www.spinics.net/lists/linux-wireless/msg31345.html.
> The patches were
> never done quite right, and I do not remember testing. As I
> have only 1 antenna
> (I think), it likely would not have affected the results.
> 
> Larry

Yes, that's the one. Here is the patch from my stash anyway, it looks like it is exactly that.

Hin-Tak


      

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rtl8187_antenna_diversity.patch --]
[-- Type: text/x-patch; name="rtl8187_antenna_diversity.patch", Size: 11464 bytes --]

diff -urN compat-wireless-2.6-old.orig/drivers/net/wireless/Makefile compat-wireless-2.6-old/drivers/net/wireless/Makefile
--- compat-wireless-2.6-old.orig/drivers/net/wireless/Makefile	2008-12-17 19:03:17.000000000 +0200
+++ compat-wireless-2.6-old/drivers/net/wireless/Makefile	2009-04-07 20:15:28.000000000 +0300
@@ -1,6 +1,7 @@
 #
 # Makefile for the Linux Wireless network device drivers.
 #
+EXTRA_CFLAGS += -DSW_ANTENNA_DIVERSITY
 
 obj-$(CONFIG_IPW2100) += ipw2100.o
 
diff -urN compat-wireless-2.6-old.orig/drivers/net/wireless/rtl8187_dev.c compat-wireless-2.6-old/drivers/net/wireless/rtl8187_dev.c
--- compat-wireless-2.6-old.orig/drivers/net/wireless/rtl8187_dev.c	2008-09-15 19:57:24.000000000 +0300
+++ compat-wireless-2.6-old/drivers/net/wireless/rtl8187_dev.c	2009-04-08 15:18:09.000000000 +0300
@@ -21,6 +21,8 @@
 #include <linux/etherdevice.h>
 #include <linux/eeprom_93cx6.h>
 #include <net/mac80211.h>
+#include <linux/proc_fs.h>      // for use the proc fs
+
 
 #include "rtl8187.h"
 #include "rtl8187_rtl8225.h"
@@ -45,6 +47,8 @@
 	{USB_DEVICE(0x03f0, 0xca02), .driver_info = DEVICE_RTL8187},
 	/* Sitecom */
 	{USB_DEVICE(0x0df6, 0x000d), .driver_info = DEVICE_RTL8187},
+	{USB_DEVICE(0x13d1, 0xabe6), .driver_info = DEVICE_RTL8187},
+
 	{}
 };
 
@@ -257,6 +261,7 @@
 
 	usb_fill_bulk_urb(urb, priv->udev, usb_sndbulkpipe(priv->udev, ep),
 			  buf, skb->len, rtl8187_tx_cb, skb);
+	urb->transfer_flags |= URB_ZERO_PACKET;
 	rc = usb_submit_urb(urb, GFP_ATOMIC);
 	if (rc < 0) {
 		usb_free_urb(urb);
@@ -266,6 +271,15 @@
 	return 0;
 }
 
+#ifdef SW_ANTENNA_DIVERSITY
+inline void add_to_average_array(struct rtl8187_priv * priv, u8 val)
+{
+    priv->ant_diversity.agc_array[ priv->ant_diversity.count++ ] = val;
+    if (priv->ant_diversity.count >= VAL_ARRAY_SIZE)
+        priv->ant_diversity.count = 0;
+}
+#endif /* SW_ANTENNA_DIVERSITY */
+
 static void rtl8187_rx_cb(struct urb *urb)
 {
 	struct sk_buff *skb = (struct sk_buff *)urb->context;
@@ -320,6 +334,9 @@
 		}
 		rx_status.signal = signal;
 		priv->signal = signal;
+#ifdef SW_ANTENNA_DIVERSITY
+        add_to_average_array(priv, hdr->agc);
+#endif /* SW_ANTENNA_DIVERSITY */
 	} else {
 		struct rtl8187b_rx_hdr *hdr =
 			(typeof(hdr))(skb_tail_pointer(skb) - sizeof(*hdr));
@@ -555,6 +572,13 @@
 	rtl818x_iowrite8(priv, (u8 *)0xFFFF, 0x60);
 	rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
 
+#ifdef SW_ANTENNA_DIVERSITY 
+	INIT_DELAYED_WORK(&priv->antenna_work, SwAntennaWorkItemCallback);
+
+	priv->ant_diversity.switch_to = 0;
+	SwitchAntenna(priv);
+#endif /* SW_ANTENNA_DIVERSITY */
+
 	return 0;
 }
 
@@ -721,6 +745,8 @@
 static int rtl8187_start(struct ieee80211_hw *dev)
 {
 	struct rtl8187_priv *priv = dev->priv;
+
+	priv->hw = dev;
 	u32 reg;
 	int ret;
 
@@ -836,6 +862,10 @@
 	struct rtl8187_priv *priv = dev->priv;
 	int i;
 
+#ifdef SW_ANTENNA_DIVERSITY
+	sw_antenna_diversity_timer_callback(priv);
+#endif /* SW_ANTENNA_DIVERSITY */
+
 	if (priv->mode != NL80211_IFTYPE_MONITOR)
 		return -EOPNOTSUPP;
 
@@ -867,6 +897,12 @@
 	mutex_lock(&priv->conf_mutex);
 	priv->mode = NL80211_IFTYPE_MONITOR;
 	priv->vif = NULL;
+
+#ifdef SW_ANTENNA_DIVERSITY
+	del_timer_sync(&priv->sw_antenna_diversity_timer);
+	cancel_delayed_work(&priv->antenna_work);
+#endif /* SW_ANTENNA_DIVERSITY */
+
 	mutex_unlock(&priv->conf_mutex);
 }
 
@@ -970,6 +1006,127 @@
 	rtl818x_iowrite32_async(priv, &priv->map->RX_CONF, priv->rx_conf);
 }
 
+#ifdef SW_ANTENNA_DIVERSITY
+#define ANTENNA_DIVERSITY_TIMER_PERIOD          2000 // 1000 m
+#define ANTENNA_SWITCH_TIMER_PERIOD				300 // 300 m 
+void sw_antenna_diversity_timer_callback(struct rtl8187_priv *priv)
+{
+    static int tick_without_switch = 0;
+    static int old_value = 0;
+    int average = 0;
+    int i;
+    for ( i = 0; i < VAL_ARRAY_SIZE; ++i)
+    {
+        average += priv->ant_diversity.agc_array[i];
+    }
+    average /= VAL_ARRAY_SIZE;
+    average /= 10; // cut 1 chipher
+    printk("%d->%d\n", old_value, average);
+
+    int sub = average - old_value;
+    if (sub < 0)
+        sub *= -1;
+    if (average > old_value) 
+    {
+        priv->ant_diversity.switch_to ^= 1;    
+        queue_delayed_work(priv->hw->workqueue, &priv->antenna_work,
+                                    msecs_to_jiffies(ANTENNA_SWITCH_TIMER_PERIOD));
+    }
+    old_value = average;
+
+    priv->sw_antenna_diversity_timer.expires = jiffies + msecs_to_jiffies(ANTENNA_DIVERSITY_TIMER_PERIOD);
+	add_timer(&priv->sw_antenna_diversity_timer);
+
+}
+
+/*
+ * Change Antenna Switch.
+ */
+bool SwitchAntenna(struct rtl8187_priv *priv)
+{
+	u8 u1bAntennaIndex = priv->ant_diversity.switch_to;
+
+	bool bAntennaSwitched = false;
+	switch(u1bAntennaIndex)
+	{
+		case 0:
+		/* main antenna */
+			// Rx CCK.
+			/* original code from realtek driver */
+			write_nic_byte(priv, 0x7f, ((0x01009b90 & 0xff000000) >> 24));
+			write_nic_byte(priv, 0x7e, ((0x01009b90 & 0x00ff0000) >> 16));
+			write_nic_byte(priv, 0x7d, ((0x01009b90 & 0x0000ff00) >> 8));
+			write_nic_byte(priv, 0x7c, ((0x01009b90 & 0x000000ff) >> 0));
+
+			// Rx OFDM.
+			/* original code from realtek driver */
+			write_nic_byte(priv, 0x7f, ((0x000090a6 & 0xff000000) >> 24));
+			write_nic_byte(priv, 0x7e, ((0x000090a6 & 0x00ff0000) >> 16));
+			write_nic_byte(priv, 0x7d, ((0x000090a6 & 0x0000ff00) >> 8));
+			write_nic_byte(priv, 0x7c, ((0x000090a6 & 0x000000ff) >> 0));
+
+			// Tx Antenna.
+			/* original code from realtek driver */
+			write_nic_byte(priv, ANTSEL, 0x03); // Config TX antenna.
+
+			bAntennaSwitched = true;
+			printk("switch to ANT1 antenna\n");
+		break;
+		case 1: /* switch(u1bAntennaIndex) */
+			// Rx CCK.
+			/* original code from realtek driver */
+			write_nic_byte(priv, 0x7f, ((0x0100db90 & 0xff000000) >> 24));
+			write_nic_byte(priv, 0x7e, ((0x0100db90 & 0x00ff0000) >> 16));
+			write_nic_byte(priv, 0x7d, ((0x0100db90 & 0x0000ff00) >> 8));
+			write_nic_byte(priv, 0x7c, ((0x0100db90 & 0x000000ff) >> 0));
+
+			// Rx OFDM.
+			/* original code from realtek driver */
+			write_nic_byte(priv, 0x7f, ((0x000010a6 & 0xff000000) >> 24));
+			write_nic_byte(priv, 0x7e, ((0x000010a6 & 0x00ff0000) >> 16));
+			write_nic_byte(priv, 0x7d, ((0x000010a6 & 0x0000ff00) >> 8));
+			write_nic_byte(priv, 0x7c, ((0x000010a6 & 0x000000ff) >> 0));
+
+			// Tx Antenna.
+			/* original code from realtek driver */
+			write_nic_byte(priv, ANTSEL, 0x00); // Config TX antenna.
+
+			bAntennaSwitched = true;
+			printk("switch to AUX antenna\n");
+			break;
+		default:
+			printk("[%s] unkown u1bAntennaIndex(%d)\n", __FUNCTION__, u1bAntennaIndex);
+		break;
+	} /* switch(u1bAntennaIndex) */
+
+	if(bAntennaSwitched)
+	{
+		priv->ant_diversity.curr_ant_index = u1bAntennaIndex;
+	}
+
+	return bAntennaSwitched;
+}
+
+
+
+void write_nic_byte(struct rtl8187_priv *priv, int indx, u8 data)
+{
+        struct usb_device *udev = priv->udev;
+
+        usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+                               RTL8187_REQ_SET_REG, RTL8187_REQT_WRITE,
+                               indx|0xff00, 0, &data, 1, HZ / 2);
+}
+
+void SwAntennaWorkItemCallback(struct work_struct *work)
+{
+	struct rtl8187_priv * priv = container_of(work, struct rtl8187_priv, antenna_work.work);
+	SwitchAntenna(priv);
+}
+
+
+#endif /* SW_ANTENNA_DIVERSITY */
+
 static const struct ieee80211_ops rtl8187_ops = {
 	.tx			= rtl8187_tx,
 	.start			= rtl8187_start,
@@ -981,6 +1138,52 @@
 	.configure_filter	= rtl8187_configure_filter,
 };
 
+#ifdef SW_ANTENNA_DIVERSITY
+
+#define procfs_name_in "antenna_diversity"
+int procfile_write(struct file *file, const char *buffer, unsigned long count, void* data)
+{
+    struct rtl8187_priv *priv = (struct rtl8187_priv *)data;
+    if (strncmp(buffer, "ANT1", 4) == 0)
+    {    
+        priv->ant_diversity.switch_to = 0;
+        queue_delayed_work(priv->hw->workqueue, &priv->antenna_work,
+                                    msecs_to_jiffies(ANTENNA_SWITCH_TIMER_PERIOD));
+    }
+    else if (strncmp(buffer, "AUX", 3) == 0)
+    {
+        priv->ant_diversity.switch_to = 1;
+        queue_delayed_work(priv->hw->workqueue, &priv->antenna_work,
+                                   msecs_to_jiffies(ANTENNA_SWITCH_TIMER_PERIOD));
+    }
+    return count;
+}
+
+int init_module_proc(struct rtl8187_priv *priv)
+{
+    struct proc_dir_entry *proc_file;
+
+    proc_file = create_proc_entry(procfs_name_in, 0644, NULL);
+
+    if (proc_file == NULL)
+    {
+        printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", procfs_name_in);
+        return -ENOMEM;
+    }
+
+    proc_file->write_proc = procfile_write;
+    proc_file->owner      = THIS_MODULE;
+    proc_file->mode       = S_IFREG | S_IRUGO;
+    proc_file->uid        = 0;
+    proc_file->gid        = 0;
+    proc_file->size       = 0;
+    proc_file->data       =  priv;
+    printk(KERN_INFO "/proc/%s created\n", procfs_name_in);
+    return 0;
+}
+
+#endif //SW_ANTENNA_DIVERSITY
+
 static void rtl8187_eeprom_register_read(struct eeprom_93cx6 *eeprom)
 {
 	struct ieee80211_hw *dev = eeprom->data;
@@ -1209,6 +1412,13 @@
 	printk(KERN_INFO "%s: hwaddr %s, %s V%d + %s\n",
 	       wiphy_name(dev->wiphy), print_mac(mac, dev->wiphy->perm_addr),
 	       chip_name, priv->asic_rev, priv->rf->name);
+#ifdef SW_ANTENNA_DIVERSITY
+	#warning ANTENNA DIVERSITY enabled
+    init_module_proc(priv);
+	init_timer(&priv->sw_antenna_diversity_timer);
+	priv->sw_antenna_diversity_timer.data = (unsigned long)priv;
+	priv->sw_antenna_diversity_timer.function = (void *)sw_antenna_diversity_timer_callback;
+#endif /* SW_ANTENNA_DIVERSITY */
 
 	return 0;
 
diff -urN compat-wireless-2.6-old.orig/drivers/net/wireless/rtl8187.h compat-wireless-2.6-old/drivers/net/wireless/rtl8187.h
--- compat-wireless-2.6-old.orig/drivers/net/wireless/rtl8187.h	2008-09-04 00:04:20.000000000 +0300
+++ compat-wireless-2.6-old/drivers/net/wireless/rtl8187.h	2009-04-07 19:53:37.000000000 +0300
@@ -82,11 +82,28 @@
 	DEVICE_RTL8187B
 };
 
+#ifdef SW_ANTENNA_DIVERSITY
+
+#define VAL_ARRAY_SIZE 10
+
+#define ANTSEL 0x9F
+
+struct rtl8187_ant_diversity {
+	int count;
+	u8 agc_array[VAL_ARRAY_SIZE];
+
+    u8 switch_to;
+    u8 curr_ant_index;
+} __attribute__ ((packed));
+
+#endif /* SW_ANTENNA_DIVERSITY */
+
 struct rtl8187_priv {
 	/* common between rtl818x drivers */
 	struct rtl818x_csr *map;
 	const struct rtl818x_rf_ops *rf;
 	struct ieee80211_vif *vif;
+	struct ieee80211_hw *hw;
 	int mode;
 	/* The mutex protects the TX loopback state.
 	 * Any attempt to set channels concurrently locks the device.
@@ -112,6 +129,13 @@
 	u8 signal;
 	u8 quality;
 	u8 noise;
+
+#ifdef SW_ANTENNA_DIVERSITY
+	struct timer_list sw_antenna_diversity_timer;
+	struct rtl8187_ant_diversity ant_diversity;
+	struct delayed_work antenna_work;
+#endif /* SW_ANTENNA_DIVERSITY */
+
 };
 
 void rtl8187_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data);
@@ -218,4 +242,20 @@
 	rtl818x_iowrite32_idx(priv, addr, val, 0);
 }
 
+void rtl8187_bss_info_changed(struct ieee80211_hw *hw,
+								struct ieee80211_vif *vif,
+								struct ieee80211_bss_conf *bss_conf,
+								u32 changes);
+#ifdef SW_ANTENNA_DIVERSITY
+
+void sw_antenna_diversity_timer_callback(struct rtl8187_priv *dev);
+
+bool SwitchAntenna(struct rtl8187_priv *priv);
+
+void write_nic_byte(struct rtl8187_priv *priv, int indx, u8 data);
+
+void SwAntennaWorkItemCallback(struct work_struct *work);
+
+#endif /* SW_ANTENNA_DIVERSITY */
+
 #endif /* RTL8187_H */

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

* Re: [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
  2010-11-07  3:28             ` Herton Ronaldo Krzesinski
@ 2010-11-07  3:45               ` Larry Finger
  0 siblings, 0 replies; 9+ messages in thread
From: Larry Finger @ 2010-11-07  3:45 UTC (permalink / raw)
  To: Herton Ronaldo Krzesinski
  Cc: htl10, Thadeu Lima de Souza Cascardo, linux-wireless,
	John W Linville, seno

On 11/06/2010 10:28 PM, Herton Ronaldo Krzesinski wrote:
> Em Sun, 7 Nov 2010 01:29:30 +0000 (GMT)
> Hin-Tak Leung <htl10@users.sourceforge.net> escreveu:
> 
>> --- On Sun, 7/11/10, Herton Ronaldo Krzesinski
>> <herton@mandriva.com.br> wrote:
>>
>> <snipped>
>>> It's strange that with or without the patch you get too low
>>> transfer
>>> values. In this case we should have another bug with your
>>> device. I don't
>>> know now what could be happening, but first thing that I
>>> thought is that
>>> this could be related to antenna selection (and I'm curious
>>> about analog
>>> parameters on the eeprom of device too). Please try
>>> following debug patch
>>> and post results (also post what type of RTL8187 the driver
>>> detects/prints
>>> on kernel log too, may help). And if is something related
>>> to antena selection,
>>> try change the if condition on the patch and see if that
>>> helps.
>> <snipped>
>>
>> That reminds me - I have an "antenna diversity" patch dated "April 9
>> 2009" on my desktop which I think I got off linux-wireless from
>> somebody with a dual-antenna device, derived from scavenging from the
>> vendor driver, I think, that we are supposed to do something about
>> but I certainly haven't done anything about it. Did either/any of you
>> look at that and/or remember having done anything about that patch? 
> 
> Do you have any pointer to it? (I can't find in the archives in April
> 9 2009). Never saw it, if was posted in the mailing list certainly
> missed it (and probably I was not in CC).

There is a reference to it at
http://www.spinics.net/lists/linux-wireless/msg31345.html. The patches were
never done quite right, and I do not remember testing. As I have only 1 antenna
(I think), it likely would not have affected the results.

Larry


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

* Re: [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
  2010-11-07  1:29           ` Hin-Tak Leung
@ 2010-11-07  3:28             ` Herton Ronaldo Krzesinski
  2010-11-07  3:45               ` Larry Finger
  0 siblings, 1 reply; 9+ messages in thread
From: Herton Ronaldo Krzesinski @ 2010-11-07  3:28 UTC (permalink / raw)
  To: htl10
  Cc: Thadeu Lima de Souza Cascardo, linux-wireless, Larry Finger,
	John W Linville, seno

Em Sun, 7 Nov 2010 01:29:30 +0000 (GMT)
Hin-Tak Leung <htl10@users.sourceforge.net> escreveu:

> --- On Sun, 7/11/10, Herton Ronaldo Krzesinski
> <herton@mandriva.com.br> wrote:
> 
> <snipped>
> > It's strange that with or without the patch you get too low
> > transfer
> > values. In this case we should have another bug with your
> > device. I don't
> > know now what could be happening, but first thing that I
> > thought is that
> > this could be related to antenna selection (and I'm curious
> > about analog
> > parameters on the eeprom of device too). Please try
> > following debug patch
> > and post results (also post what type of RTL8187 the driver
> > detects/prints
> > on kernel log too, may help). And if is something related
> > to antena selection,
> > try change the if condition on the patch and see if that
> > helps.
> <snipped>
> 
> That reminds me - I have an "antenna diversity" patch dated "April 9
> 2009" on my desktop which I think I got off linux-wireless from
> somebody with a dual-antenna device, derived from scavenging from the
> vendor driver, I think, that we are supposed to do something about
> but I certainly haven't done anything about it. Did either/any of you
> look at that and/or remember having done anything about that patch? 

Do you have any pointer to it? (I can't find in the archives in April
9 2009). Never saw it, if was posted in the mailing list certainly
missed it (and probably I was not in CC).

--
[]'s
Herton

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

* Re: [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
  2010-11-07  1:07         ` Herton Ronaldo Krzesinski
@ 2010-11-07  1:29           ` Hin-Tak Leung
  2010-11-07  3:28             ` Herton Ronaldo Krzesinski
  0 siblings, 1 reply; 9+ messages in thread
From: Hin-Tak Leung @ 2010-11-07  1:29 UTC (permalink / raw)
  To: Thadeu Lima de Souza Cascardo, Herton Ronaldo Krzesinski
  Cc: linux-wireless, Larry Finger, John W Linville, seno

--- On Sun, 7/11/10, Herton Ronaldo Krzesinski <herton@mandriva.com.br> wrote:

<snipped>
> It's strange that with or without the patch you get too low
> transfer
> values. In this case we should have another bug with your
> device. I don't
> know now what could be happening, but first thing that I
> thought is that
> this could be related to antenna selection (and I'm curious
> about analog
> parameters on the eeprom of device too). Please try
> following debug patch
> and post results (also post what type of RTL8187 the driver
> detects/prints
> on kernel log too, may help). And if is something related
> to antena selection,
> try change the if condition on the patch and see if that
> helps.
<snipped>

That reminds me - I have an "antenna diversity" patch dated "April 9 2009" on my desktop which I think I got off linux-wireless from somebody with a dual-antenna device, derived from scavenging from the vendor driver, I think, that we are supposed to do something about but I certainly haven't done anything about it. Did either/any of you look at that and/or remember having done anything about that patch? 



      

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

* Re: [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
  2010-11-05 19:45       ` Thadeu Lima de Souza Cascardo
@ 2010-11-07  1:07         ` Herton Ronaldo Krzesinski
  2010-11-07  1:29           ` Hin-Tak Leung
  0 siblings, 1 reply; 9+ messages in thread
From: Herton Ronaldo Krzesinski @ 2010-11-07  1:07 UTC (permalink / raw)
  To: Thadeu Lima de Souza Cascardo
  Cc: linux-wireless, Larry Finger, Hin-Tak Leung, John W Linville, seno

Em Fri, 5 Nov 2010 17:45:50 -0200
Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com> escreveu:
[snip]
> 
> Hello, again.
> 
> I've done some more tests around here and I also get throughput
> improvements with the last patch when my AP is in my desk. It does
> happen that I have what seems to be a badly assembled card in my
> notebook. I can try to get one I can plug outside in the external USB
> port.
> 
> However, the tests I've done with my card with the AP a little further
> away (about 2.7 meters), I cannot ping the machine for more than the
> first seconds. Without the last patch, I get 50% loss, and, sometimes,
> iperf works and gives me more than 2Kbits/s (that's right, that
> little).
> 
> I have also tried with the AP whithin about 1 meter of distance.
> Without the patch, I get no loss and iperf gives me something between
> 1Mbit/s and 2Mbit/s. With the patch, sometimes I get 4Mbit/s,
> sometimes less than 10Kbit/s. In any occasion, with lots of losses
> using ping.

It's strange that with or without the patch you get too low transfer
values. In this case we should have another bug with your device. I don't
know now what could be happening, but first thing that I thought is that
this could be related to antenna selection (and I'm curious about analog
parameters on the eeprom of device too). Please try following debug patch
and post results (also post what type of RTL8187 the driver detects/prints
on kernel log too, may help). And if is something related to antena selection,
try change the if condition on the patch and see if that helps.

diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
index eeee244..d8271f0 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
@@ -1538,6 +1538,18 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
 #endif
 	rtl8187_rfkill_init(dev);
 
+	eeprom_93cx6_read(&eeprom, 0x3F, &reg);
+	printk("EEPROM_SW_REVD == 0x%04x\n", reg);
+
+	eeprom_93cx6_read(&eeprom, 0xe, &reg);
+	printk("ANA_PARM eeprom value: 0x%04x", reg);
+	eeprom_93cx6_read(&eeprom, 0xd, &reg);
+	printk("%04x\n", reg);
+	eeprom_93cx6_read(&eeprom, 0x19, &reg);
+	printk("ANA_PARM2 eeprom value: 0x%04x", reg);
+	eeprom_93cx6_read(&eeprom, 0x1a, &reg);
+	printk("%04x\n", reg);
+
 	return 0;
 
  err_free_dmabuf:
diff --git a/drivers/net/wireless/rtl818x/rtl8187_rtl8225.c b/drivers/net/wireless/rtl818x/rtl8187_rtl8225.c
index 5c6666f..15c0165 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_rtl8225.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_rtl8225.c
@@ -877,7 +877,6 @@ static void rtl8225z2_b_rf_init(struct ieee80211_hw *dev)
 
 	rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK, 0x03);
 	rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM, 0x07);
-	rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03);
 
 	rtl8225_write_phy_ofdm(dev, 0x80, 0x12);
 	for (i = 0; i < ARRAY_SIZE(rtl8225z2_agc); i++) {
@@ -894,6 +893,17 @@ static void rtl8225z2_b_rf_init(struct ieee80211_hw *dev)
 	rtl8225_write_phy_ofdm(dev, 0xa4, 0xb6);
 	rtl8225_write_phy_ofdm(dev, 0x85, 0xfc);
 	rtl8225_write_phy_cck(dev, 0xc1, 0x88);
+
+	if (0) {
+		rtl8225_write_phy_cck(dev, 0x10, 0xdb);
+		rtl8225_write_phy_ofdm(dev, 0x26, 0x10);
+		rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x00);
+	} else {
+		rtl8225_write_phy_cck(dev, 0x10, 0x9b);
+		rtl8225_write_phy_ofdm(dev, 0x26, 0x90);
+		rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03);
+	}
+	msleep(1);
 }
 
 static void rtl8225_rf_stop(struct ieee80211_hw *dev)


> 
> For reference, my "AP" is, in fact, a netbook using hostapd and a rt73
> USB dongle. I am going to send the patches for experimentation in an
> environment with many devices far away from the AP. As soon as I get
> the results (it may take a while), I'll send them to the list.
> 
> Anyway, although I am not very confident about this last patch,
> perhaps it should go forward and we get can revert it later if people
> does complain about it. Or we should add a comment stating in the
> code that it does improve throughput, but may cause packet losses
> when the devices are distant. Any thoughts on how to turn this on or
> off depending on the case too?
> 
> Regards,
> Cascardo.

--
[]'s
Herton

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

* Re: [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
  2010-11-04 15:50     ` Herton Ronaldo Krzesinski
@ 2010-11-05 19:45       ` Thadeu Lima de Souza Cascardo
  2010-11-07  1:07         ` Herton Ronaldo Krzesinski
  0 siblings, 1 reply; 9+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2010-11-05 19:45 UTC (permalink / raw)
  To: Herton Ronaldo Krzesinski
  Cc: linux-wireless, Larry Finger, Hin-Tak Leung, John W Linville, seno

[-- Attachment #1: Type: text/plain, Size: 4340 bytes --]

On Thu, Nov 04, 2010 at 01:50:37PM -0200, Herton Ronaldo Krzesinski wrote:
> On Thu, 4 Nov 2010 13:30:57 -0200
> Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com> wrote:
> 
> > On Mon, Nov 01, 2010 at 10:59:39PM -0200, Herton Ronaldo Krzesinski wrote:
> > > Current 8187B initialization misses anaparam registers restore after
> > > 8187 reset. This causes ANAPARAM register to stay zeroed out (ANAPARAM2
> > > kept its value on my tests). To avoid this, call rtl8187_set_anaparam
> > > right after chip reset (to be on the safe side, as it makes sure we
> > > restore all ANAPARAM registers).
> > > 
> > 
> > Hello, Herton.
> > 
> > Thank you very much for these patches. I am in the process of testing
> > them right now. The first thing I've noticed is a drop in the signal
> > level by 10dBm when using this last patch. Is this something we should
> > be concerned with?
> 
> I think not, may be the signal is a bit weaker with the anaparam now being
> what Realtek uses/recomends (unfortunately it's a magic number and not
> disclosed what each bit/parameter is doing..., probably the buggy previous
> behaviour of the setting being zero after reset was making the signal too
> high when not needed), but as with it we can get higher rate and bandwidth
> on same distance, it shouldn't be a concern (my iperf test results showed
> improvements too with the last two changes).
> 

Hello, again.

I've done some more tests around here and I also get throughput
improvements with the last patch when my AP is in my desk. It does
happen that I have what seems to be a badly assembled card in my
notebook. I can try to get one I can plug outside in the external USB
port.

However, the tests I've done with my card with the AP a little further
away (about 2.7 meters), I cannot ping the machine for more than the
first seconds. Without the last patch, I get 50% loss, and, sometimes,
iperf works and gives me more than 2Kbits/s (that's right, that little).

I have also tried with the AP whithin about 1 meter of distance.
Without the patch, I get no loss and iperf gives me something between
1Mbit/s and 2Mbit/s. With the patch, sometimes I get 4Mbit/s, sometimes
less than 10Kbit/s. In any occasion, with lots of losses using ping.

For reference, my "AP" is, in fact, a netbook using hostapd and a rt73
USB dongle. I am going to send the patches for experimentation in an
environment with many devices far away from the AP. As soon as I get the
results (it may take a while), I'll send them to the list.

Anyway, although I am not very confident about this last patch, perhaps
it should go forward and we get can revert it later if people does
complain about it. Or we should add a comment stating in the code that
it does improve throughput, but may cause packet losses when the devices
are distant. Any thoughts on how to turn this on or off depending on the
case too?

Regards,
Cascardo.

> > 
> > I will do some tests with the distance to the Access Point and send my
> > results later.
> > 
> > Regards,
> > Cascardo.
> > 
> > > Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
> > > Acked-by: Larry Finger <Larry.Finger@lwfinger.net>
> > > Cc: seno <senada@t-online.de>
> > > ---
> > >  drivers/net/wireless/rtl818x/rtl8187_dev.c |    2 ++
> > >  1 files changed, 2 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
> > > index 4448647..eeee244 100644
> > > --- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
> > > +++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
> > > @@ -771,6 +771,8 @@ static int rtl8187b_init_hw(struct ieee80211_hw *dev)
> > >  	if (res)
> > >  		return res;
> > >  
> > > +	rtl8187_set_anaparam(priv, true);
> > > +
> > >  	/* BRSR (Basic Rate Set Register) on 8187B looks to be the same as
> > >  	 * RESP_RATE on 8187L in Realtek sources: each bit should be each
> > >  	 * one of the 12 rates, all are enabled */
> > > -- 
> > > 1.7.3.2
> > > 
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> --
> []'s
> Herton

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
  2010-11-04 15:30   ` Thadeu Lima de Souza Cascardo
@ 2010-11-04 15:50     ` Herton Ronaldo Krzesinski
  2010-11-05 19:45       ` Thadeu Lima de Souza Cascardo
  0 siblings, 1 reply; 9+ messages in thread
From: Herton Ronaldo Krzesinski @ 2010-11-04 15:50 UTC (permalink / raw)
  To: Thadeu Lima de Souza Cascardo
  Cc: linux-wireless, Larry Finger, Hin-Tak Leung, John W Linville, seno

On Thu, 4 Nov 2010 13:30:57 -0200
Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com> wrote:

> On Mon, Nov 01, 2010 at 10:59:39PM -0200, Herton Ronaldo Krzesinski wrote:
> > Current 8187B initialization misses anaparam registers restore after
> > 8187 reset. This causes ANAPARAM register to stay zeroed out (ANAPARAM2
> > kept its value on my tests). To avoid this, call rtl8187_set_anaparam
> > right after chip reset (to be on the safe side, as it makes sure we
> > restore all ANAPARAM registers).
> > 
> 
> Hello, Herton.
> 
> Thank you very much for these patches. I am in the process of testing
> them right now. The first thing I've noticed is a drop in the signal
> level by 10dBm when using this last patch. Is this something we should
> be concerned with?

I think not, may be the signal is a bit weaker with the anaparam now being
what Realtek uses/recomends (unfortunately it's a magic number and not
disclosed what each bit/parameter is doing..., probably the buggy previous
behaviour of the setting being zero after reset was making the signal too
high when not needed), but as with it we can get higher rate and bandwidth
on same distance, it shouldn't be a concern (my iperf test results showed
improvements too with the last two changes).

> 
> I will do some tests with the distance to the Access Point and send my
> results later.
> 
> Regards,
> Cascardo.
> 
> > Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
> > Acked-by: Larry Finger <Larry.Finger@lwfinger.net>
> > Cc: seno <senada@t-online.de>
> > ---
> >  drivers/net/wireless/rtl818x/rtl8187_dev.c |    2 ++
> >  1 files changed, 2 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
> > index 4448647..eeee244 100644
> > --- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
> > +++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
> > @@ -771,6 +771,8 @@ static int rtl8187b_init_hw(struct ieee80211_hw *dev)
> >  	if (res)
> >  		return res;
> >  
> > +	rtl8187_set_anaparam(priv, true);
> > +
> >  	/* BRSR (Basic Rate Set Register) on 8187B looks to be the same as
> >  	 * RESP_RATE on 8187L in Realtek sources: each bit should be each
> >  	 * one of the 12 rates, all are enabled */
> > -- 
> > 1.7.3.2
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
[]'s
Herton

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

* Re: [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
  2010-11-02  0:59 ` [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B Herton Ronaldo Krzesinski
@ 2010-11-04 15:30   ` Thadeu Lima de Souza Cascardo
  2010-11-04 15:50     ` Herton Ronaldo Krzesinski
  0 siblings, 1 reply; 9+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2010-11-04 15:30 UTC (permalink / raw)
  To: Herton Ronaldo Krzesinski
  Cc: linux-wireless, Larry Finger, Hin-Tak Leung, John W Linville, seno

[-- Attachment #1: Type: text/plain, Size: 1874 bytes --]

On Mon, Nov 01, 2010 at 10:59:39PM -0200, Herton Ronaldo Krzesinski wrote:
> Current 8187B initialization misses anaparam registers restore after
> 8187 reset. This causes ANAPARAM register to stay zeroed out (ANAPARAM2
> kept its value on my tests). To avoid this, call rtl8187_set_anaparam
> right after chip reset (to be on the safe side, as it makes sure we
> restore all ANAPARAM registers).
> 

Hello, Herton.

Thank you very much for these patches. I am in the process of testing
them right now. The first thing I've noticed is a drop in the signal
level by 10dBm when using this last patch. Is this something we should
be concerned with?

I will do some tests with the distance to the Access Point and send my
results later.

Regards,
Cascardo.

> Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
> Acked-by: Larry Finger <Larry.Finger@lwfinger.net>
> Cc: seno <senada@t-online.de>
> ---
>  drivers/net/wireless/rtl818x/rtl8187_dev.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
> index 4448647..eeee244 100644
> --- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
> +++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
> @@ -771,6 +771,8 @@ static int rtl8187b_init_hw(struct ieee80211_hw *dev)
>  	if (res)
>  		return res;
>  
> +	rtl8187_set_anaparam(priv, true);
> +
>  	/* BRSR (Basic Rate Set Register) on 8187B looks to be the same as
>  	 * RESP_RATE on 8187L in Realtek sources: each bit should be each
>  	 * one of the 12 rates, all are enabled */
> -- 
> 1.7.3.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B
  2010-11-02  0:59 [PATCH 0/9] rtl8187: start cleanup/revisiting code Herton Ronaldo Krzesinski
@ 2010-11-02  0:59 ` Herton Ronaldo Krzesinski
  2010-11-04 15:30   ` Thadeu Lima de Souza Cascardo
  0 siblings, 1 reply; 9+ messages in thread
From: Herton Ronaldo Krzesinski @ 2010-11-02  0:59 UTC (permalink / raw)
  To: linux-wireless
  Cc: Larry Finger, Hin-Tak Leung, John W Linville,
	Herton Ronaldo Krzesinski, seno

Current 8187B initialization misses anaparam registers restore after
8187 reset. This causes ANAPARAM register to stay zeroed out (ANAPARAM2
kept its value on my tests). To avoid this, call rtl8187_set_anaparam
right after chip reset (to be on the safe side, as it makes sure we
restore all ANAPARAM registers).

Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
Acked-by: Larry Finger <Larry.Finger@lwfinger.net>
Cc: seno <senada@t-online.de>
---
 drivers/net/wireless/rtl818x/rtl8187_dev.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
index 4448647..eeee244 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
@@ -771,6 +771,8 @@ static int rtl8187b_init_hw(struct ieee80211_hw *dev)
 	if (res)
 		return res;
 
+	rtl8187_set_anaparam(priv, true);
+
 	/* BRSR (Basic Rate Set Register) on 8187B looks to be the same as
 	 * RESP_RATE on 8187L in Realtek sources: each bit should be each
 	 * one of the 12 rates, all are enabled */
-- 
1.7.3.2


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

end of thread, other threads:[~2010-11-07 13:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-07 13:51 [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B Hin-Tak Leung
  -- strict thread matches above, loose matches on Subject: below --
2010-11-02  0:59 [PATCH 0/9] rtl8187: start cleanup/revisiting code Herton Ronaldo Krzesinski
2010-11-02  0:59 ` [PATCH 9/9] rtl8187: restore anaparam registers after reset with 8187B Herton Ronaldo Krzesinski
2010-11-04 15:30   ` Thadeu Lima de Souza Cascardo
2010-11-04 15:50     ` Herton Ronaldo Krzesinski
2010-11-05 19:45       ` Thadeu Lima de Souza Cascardo
2010-11-07  1:07         ` Herton Ronaldo Krzesinski
2010-11-07  1:29           ` Hin-Tak Leung
2010-11-07  3:28             ` Herton Ronaldo Krzesinski
2010-11-07  3:45               ` Larry Finger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.