Skip to contentSkip to conversation

libertas: fixes for slow hardware

PATCH In review Holger Schurig 3 participants 6 messages Oct 8, 2007 – Oct 10, 2007 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libertas: fixes for slow hardware

This fixes issues where either the CF module is slow (and needs more time while downloading the firmware) or where the host computer is slow, so that some card interrupts arrive while the system was still downloading the firmware.

Signature · 38 lines
Index: libertas-2.6/drivers/net/wireless/libertas/if_cs.c
===================================================================
--- libertas-2.6.orig/drivers/net/wireless/libertas/if_cs.c	
2007-10-01 14:05:53.000000000 +0200
+++ libertas-2.6/drivers/net/wireless/libertas/if_cs.c	2007-10-01 
14:06:43.000000000 +0200
@@ -148,11 +148,11 @@ static int if_cs_poll_while_fw_download(
 {
 	int i;
 
-	for (i = 0; i < 500; i++) {
+	for (i = 0; i < 1000; i++) {
 		u8 val = if_cs_read8(card, addr);
 		if (val == reg)
 			return i;
-		udelay(100);
+		udelay(500);
 	}
 	return -ETIME;
 }
@@ -405,6 +405,7 @@ static struct sk_buff *if_cs_receive_dat
 	skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
 	if (!skb)
 		goto out;
+	skb->dev = priv->dev;
 	skb_put(skb, len);
 	skb_reserve(skb, 2);/* 16 byte align */
 	data = skb->data;
@@ -878,6 +879,9 @@ static int if_cs_probe(struct pcmcia_dev
 		goto out3;
 	}
 
+	/* Clear any interrupt cause that happend while sending
+	 * firmware/initializing card */
+	if_cs_write16(card, IF_CS_C_INT_CAUSE, IF_CS_C_IC_MASK);
 	if_cs_enable_ints(card);
 
 	/* And finally bring the card up */
#1 lore raw
Quoted 7 lines · Holger Schurig

This fixes issues where either the CF module is slow (and needs more time while downloading the firmware) or where the host computer is slow, so that some card interrupts arrive while the system was still downloading the firmware.

@@ -405,6 +405,7 @@ static struct sk_buff *if_cs_receive_dat

        skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
        if (!skb)
                goto out;
+       skb->dev = priv->dev;
        skb_put(skb, len);
        skb_reserve(skb, 2);/* 16 byte align */
        data = skb->data;

This hunk is not necessary, the skb->dev gets set in libertas_upload_rx_packet() when calling eth_type_trans(). If using a kernel <= 2.6.21, setting skb->dev should be handled by libertas_upload_rx_packet() for you later on.

Dan

#2 lore raw

PATCH 1/1 libertas: fixes for slow hardware

Fixes for slow hardware.

drivers/net/wireless/libertas/if_cs.c +5 -2
Index: libertas-2.6/drivers/net/wireless/libertas/if_cs.c
===================================================================
@@ -148,11 +148,11 @@ static int if_cs_poll_while_fw_download(
 {
 	int i;
 
-	for (i = 0; i < 500; i++) {
+	for (i = 0; i < 1000; i++) {
 		u8 val = if_cs_read8(card, addr);
 		if (val == reg)
 			return i;
-		udelay(100);
+		udelay(500);
 	}
 	return -ETIME;
 }
@@ -878,6 +878,9 @@ static int if_cs_probe(struct pcmcia_dev
 		goto out3;
 	}
 
+	/* Clear any interrupt cause that happend while sending
+	 * firmware/initializing card */
+	if_cs_write16(card, IF_CS_C_INT_CAUSE, IF_CS_C_IC_MASK);
 	if_cs_enable_ints(card);
 
 	/* And finally bring the card up */
Acked-by on v1 1/1
#3 lore raw
Quoted 4 lines · Holger Schurig

Fixes for slow hardware.

Quoted 29 lines

Index: libertas-2.6/drivers/net/wireless/libertas/if_cs.c
===================================================================

drivers/net/wireless/libertas/if_cs.c +5 -2
@@ -148,11 +148,11 @@ static int if_cs_poll_while_fw_download(
 {
 	int i;
 
-	for (i = 0; i < 500; i++) {
+	for (i = 0; i < 1000; i++) {
 		u8 val = if_cs_read8(card, addr);
 		if (val == reg)
 			return i;
-		udelay(100);
+		udelay(500);
 	}
 	return -ETIME;
 }
@@ -878,6 +878,9 @@ static int if_cs_probe(struct pcmcia_dev
 		goto out3;
 	}
 
+	/* Clear any interrupt cause that happend while sending
+	 * firmware/initializing card */
+	if_cs_write16(card, IF_CS_C_INT_CAUSE, IF_CS_C_IC_MASK);
 	if_cs_enable_ints(card);
 
 	/* And finally bring the card up */
#4 lore raw
In reply to Holger Schurig
Quoted 4 lines · Holger Schurig
drivers/net/wireless/libertas/if_cs.c +0 -0
@@ -148,11 +148,11 @@ static int if_cs_poll_while_fw_download(
 {
 	int i;
 

drivers/net/wireless/libertas/if_cs.c static int if_cs_poll_while_fw_download( · line 158

Quoted 10 lines
drivers/net/wireless/libertas/if_cs.c +2 -2
-	for (i = 0; i < 500; i++) {
+	for (i = 0; i < 1000; i++) {
 		u8 val = if_cs_read8(card, addr);
 		if (val == reg)
 			return i;
-		udelay(100);
+		udelay(500);
 	}
 	return -ETIME;
 }

10x the maximum delay? Is this really necessary? How did you determine this was needed?

If it really is necessary, you need to change the "The host polls the Card Status register for 50 ms..." comment in if_cs_prog_helper as well.

John

Signature · 2 lines
John W. Linville
[email protected]
#5 lore raw
Quoted 17 lines
Quoted 4 lines
drivers/net/wireless/libertas/if_cs.c +0 -0
@@ -148,11 +148,11 @@ static int
 if_cs_poll_while_fw_download( {
 	int i;
 

drivers/net/wireless/libertas/if_cs.c static int · line 158

Quoted 10 lines
drivers/net/wireless/libertas/if_cs.c +2 -2
-	for (i = 0; i < 500; i++) {
+	for (i = 0; i < 1000; i++) {
 		u8 val = if_cs_read8(card, addr);
 		if (val == reg)
 			return i;
-		udelay(100);
+		udelay(500);
 	}
 	return -ETIME;
 }

10x the maximum delay? Is this really necessary?

Quoted 1 line

How did you determine this was needed?

For my hardware, it was not necessary. My CF card worked with the old settings.

The documentation, in 2.2.1.2 "CF Interface" says at point 3. a)

"The host polls this for 50 ms before declaring a failure on the particular block of firmware being downloaded".

Some lines below, in the section about the real firmware (the former citation was from the section about the helper firmware), it just says in "8.", after polling card status register:

"The is no definite time period that the host polls this bit before declaring a failure on this particular block of firmware".

and in "9.", after card configuration and scratch port register:

"The host polls this 50ms before declaring a failure ..."

So, two times it's 50ms, once it's unspecified.

For me 50ms worked in all cases (my hardware actually reacts in way less than 50 millisends).

However, Vitaly sent this patch, he had hardware where the firmware download was failing with the original approach and where it was necessary to make those values larger. I'm actually don't know in which of the three cases it failed for him. But this code piece isn't so time critical:

* the routine will only called during firmware download, not for normal operation. Especially not when sending commands, receiving responses or sending/receiving packets

* for my hardware, I never reach the upper ceilings, the routine routines always way faster.

This are my findings how often it spun loops in
if_cs_poll_while_fw_download():

* While programming the helper firmware: 10 * 1 loop
* While programming the real firmware, 1 * 0 loop, 363 * 1 loop
* While waiting for the expected value in the scratch pad
register: 88 loops

With the original code:

* While programming the helper firmware: 8 * 3 loops, 2 * 1 loop
* While programming the real firmware: 1 * 0 loop, 363 * 1 loop
* While waiting for the expected value in the scratch pad
register: 434 loops

Quoted 3 lines

If it really is necessary, you need to change the "The host polls the Card Status register for 50 ms..." comment in if_cs_prog_helper as well.

As this is an excerpt from the docs, I don't want to change this arbitrary.

My problem is that I don't have the hardware that failed with the original code. If I would have this hardware, I would have changed if_cs_poll_while_fw_download() so that I could specify the amount of time it should wait. Or so that I can change the number of loops it should wait.