mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] commands: loady: fix bug with netconsole
@ 2015-01-01 20:04 Robert Jarzmik
  2015-01-01 20:04 ` [PATCH] net: smc1111: fix memory congestions Robert Jarzmik
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Robert Jarzmik @ 2015-01-01 20:04 UTC (permalink / raw)
  To: barebox

Netconsole doesn't have a baudrate. Loady supposes a console has one,
and tries to compute the console's baudrate variable value, regardless
of its existence.

This triggers a NULL pointer dereference on netconsole. If attempting
loady on a netconsole is a bit useless, barebox should not panic. Fix
this by checking the variable exists before reading its value.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
 commands/loadxy.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/commands/loadxy.c b/commands/loadxy.c
index df14043..1e65cb6 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -43,10 +43,10 @@
 static int console_change_speed(struct console_device *cdev, int baudrate)
 {
 	int current_baudrate;
+	const char *bstr;
 
-	current_baudrate =
-		(int)simple_strtoul(dev_get_param(&cdev->class_dev,
-						  "baudrate"), NULL, 10);
+	bstr = dev_get_param(&cdev->class_dev, "baudrate");
+	current_baudrate = bstr ? (int)simple_strtoul(bstr, NULL, 10) : 0;
 	if (baudrate && baudrate != current_baudrate) {
 		printf("## Switch baudrate from %d to %d bps and press ENTER ...\n",
 		       current_baudrate, baudrate);
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH] net: smc1111: fix memory congestions
  2015-01-01 20:04 [PATCH] commands: loady: fix bug with netconsole Robert Jarzmik
@ 2015-01-01 20:04 ` Robert Jarzmik
  2015-01-05 12:11   ` Sascha Hauer
  2015-01-01 20:04 ` [PATCH] net: smc1111: move print_packet function Robert Jarzmik
  2015-01-05 12:12 ` [PATCH] commands: loady: fix bug with netconsole Sascha Hauer
  2 siblings, 1 reply; 8+ messages in thread
From: Robert Jarzmik @ 2015-01-01 20:04 UTC (permalink / raw)
  To: barebox

As the SMC1111 has a shared pool of 2k memory buckets for both
transmission and reception, and as there are variants which have as few
as 4 buckets in total, the memory pool can be hogged by unclaimed
receptions, and impeed any further transmission.

This happens on the zylonite pxa board, where 4 packets, most probably
icmp and arp, fill the 4 buckets, preventing any further ethernet
transmission, and stalling the driver.

The fix is rather rough : whenever all the buckets are filled by
reception packets, and if a transmission is required, the transmission
code path will empty up all received packets.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
 drivers/net/smc91111.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/net/smc91111.c b/drivers/net/smc91111.c
index 55d9367..91bb845 100644
--- a/drivers/net/smc91111.c
+++ b/drivers/net/smc91111.c
@@ -152,6 +152,7 @@
 /* Memory Information Register */
 /* BANK 0  */
 #define MIR_REG		0x0008
+#define MIR_FREE_MASK	0xff00
 
 /* Receive/Phy Control Register */
 /* BANK 0  */
@@ -916,6 +917,30 @@ static int smc91c111_eth_open(struct eth_device *edev)
 	return 0;
 }
 
+static void smc91c111_ensure_freemem(struct eth_device *edev)
+{
+	struct smc91c111_priv *priv = (struct smc91c111_priv *)edev->priv;
+	u16 mir, rxfifo;
+
+	SMC_SELECT_BANK(priv, 0);
+	mir = SMC_inw(priv, MIR_REG);
+	SMC_SELECT_BANK(priv, 2);
+
+	if ((mir & MIR_FREE_MASK) == 0) {
+		do {
+			SMC_outw(priv, MC_RELEASE, MMU_CMD_REG);
+			smc_wait_mmu_release_complete(priv);
+
+			SMC_SELECT_BANK(priv, 0);
+			mir = SMC_inw(priv, MIR_REG);
+			SMC_SELECT_BANK(priv, 2);
+			rxfifo = SMC_inw(priv, RXFIFO_REG);
+			dev_dbg(&edev->dev, "%s: card memory saturated, tidying up (rx_tx_fifo=0x%04x mir=0x%04x)\n",
+				SMC_DEV_NAME, rxfifo, mir);
+		} while (!(rxfifo & RXFIFO_REMPTY));
+	}
+}
+
 static int smc91c111_eth_send(struct eth_device *edev, void *packet,
 				int packet_length)
 {
@@ -957,6 +982,7 @@ static int smc91c111_eth_send(struct eth_device *edev, void *packet,
 		return -EOVERFLOW;
 	}
 
+	smc91c111_ensure_freemem(edev);
 	/* now, try to allocate the memory */
 	SMC_SELECT_BANK(priv, 2);
 	SMC_outw(priv, MC_ALLOC | numPages, MMU_CMD_REG);
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH] net: smc1111: move print_packet function
  2015-01-01 20:04 [PATCH] commands: loady: fix bug with netconsole Robert Jarzmik
  2015-01-01 20:04 ` [PATCH] net: smc1111: fix memory congestions Robert Jarzmik
@ 2015-01-01 20:04 ` Robert Jarzmik
  2015-01-05 12:12   ` Sascha Hauer
  2015-01-05 12:12 ` [PATCH] commands: loady: fix bug with netconsole Sascha Hauer
  2 siblings, 1 reply; 8+ messages in thread
From: Robert Jarzmik @ 2015-01-01 20:04 UTC (permalink / raw)
  To: barebox

Fix for a compiler complaint, because print_packet is needed by a
function before it is declared.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
 drivers/net/smc91111.c | 75 +++++++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 38 deletions(-)

diff --git a/drivers/net/smc91111.c b/drivers/net/smc91111.c
index 91bb845..100688c 100644
--- a/drivers/net/smc91111.c
+++ b/drivers/net/smc91111.c
@@ -583,6 +583,43 @@ static inline void SMC_SELECT_BANK(struct smc91c111_priv *p, int bank)
 	SMC_outw(p, bank, BANK_SELECT);
 }
 
+#if SMC_DEBUG > 2
+static void print_packet( unsigned char * buf, int length )
+{
+	int i;
+	int remainder;
+	int lines;
+
+	printf("Packet of length %d \n", length );
+
+#if SMC_DEBUG > 3
+	lines = length / 16;
+	remainder = length % 16;
+
+	for ( i = 0; i < lines ; i ++ ) {
+		int cur;
+
+		for ( cur = 0; cur < 8; cur ++ ) {
+			unsigned char a, b;
+
+			a = *(buf ++ );
+			b = *(buf ++ );
+			printf("%02x%02x ", a, b );
+		}
+		printf("\n");
+	}
+	for ( i = 0; i < remainder/2 ; i++ ) {
+		unsigned char a, b;
+
+		a = *(buf ++ );
+		b = *(buf ++ );
+		printf("%02x%02x ", a, b );
+	}
+	printf("\n");
+#endif
+}
+#endif
+
 /* note: timeout in seconds */
 static int poll4int(struct smc91c111_priv *priv, unsigned char mask,
 			int timeout)
@@ -1281,44 +1318,6 @@ static void smc_dump_mii_stream (unsigned char * bits, int size)
 }
 #endif
 
-
-#if SMC_DEBUG > 2
-static void print_packet( unsigned char * buf, int length )
-{
-	int i;
-	int remainder;
-	int lines;
-
-	printf("Packet of length %d \n", length );
-
-#if SMC_DEBUG > 3
-	lines = length / 16;
-	remainder = length % 16;
-
-	for ( i = 0; i < lines ; i ++ ) {
-		int cur;
-
-		for ( cur = 0; cur < 8; cur ++ ) {
-			unsigned char a, b;
-
-			a = *(buf ++ );
-			b = *(buf ++ );
-			printf("%02x%02x ", a, b );
-		}
-		printf("\n");
-	}
-	for ( i = 0; i < remainder/2 ; i++ ) {
-		unsigned char a, b;
-
-		a = *(buf ++ );
-		b = *(buf ++ );
-		printf("%02x%02x ", a, b );
-	}
-	printf("\n");
-#endif
-}
-#endif
-
 static int smc91c111_init_dev(struct eth_device *edev)
 {
 	return 0;
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: smc1111: fix memory congestions
  2015-01-01 20:04 ` [PATCH] net: smc1111: fix memory congestions Robert Jarzmik
@ 2015-01-05 12:11   ` Sascha Hauer
  2015-01-05 16:16     ` robert.jarzmik
  0 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2015-01-05 12:11 UTC (permalink / raw)
  To: Robert Jarzmik; +Cc: barebox

On Thu, Jan 01, 2015 at 09:04:22PM +0100, Robert Jarzmik wrote:
> As the SMC1111 has a shared pool of 2k memory buckets for both
> transmission and reception, and as there are variants which have as few
> as 4 buckets in total, the memory pool can be hogged by unclaimed
> receptions, and impeed any further transmission.
> 
> This happens on the zylonite pxa board, where 4 packets, most probably
> icmp and arp, fill the 4 buckets, preventing any further ethernet
> transmission, and stalling the driver.
> 
> The fix is rather rough : whenever all the buckets are filled by
> reception packets, and if a transmission is required, the transmission
> code path will empty up all received packets.

I don't know the hardware (not anymore, fortunately ;), but isn't it
possible to dedicate one bucket for transmitting only, so that it will
never be occupied by a received packet?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] commands: loady: fix bug with netconsole
  2015-01-01 20:04 [PATCH] commands: loady: fix bug with netconsole Robert Jarzmik
  2015-01-01 20:04 ` [PATCH] net: smc1111: fix memory congestions Robert Jarzmik
  2015-01-01 20:04 ` [PATCH] net: smc1111: move print_packet function Robert Jarzmik
@ 2015-01-05 12:12 ` Sascha Hauer
  2 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2015-01-05 12:12 UTC (permalink / raw)
  To: Robert Jarzmik; +Cc: barebox

On Thu, Jan 01, 2015 at 09:04:21PM +0100, Robert Jarzmik wrote:
> Netconsole doesn't have a baudrate. Loady supposes a console has one,
> and tries to compute the console's baudrate variable value, regardless
> of its existence.
> 
> This triggers a NULL pointer dereference on netconsole. If attempting
> loady on a netconsole is a bit useless, barebox should not panic. Fix
> this by checking the variable exists before reading its value.
> 
> Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: smc1111: move print_packet function
  2015-01-01 20:04 ` [PATCH] net: smc1111: move print_packet function Robert Jarzmik
@ 2015-01-05 12:12   ` Sascha Hauer
  0 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2015-01-05 12:12 UTC (permalink / raw)
  To: Robert Jarzmik; +Cc: barebox

On Thu, Jan 01, 2015 at 09:04:23PM +0100, Robert Jarzmik wrote:
> Fix for a compiler complaint, because print_packet is needed by a
> function before it is declared.
> 
> Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: smc1111: fix memory congestions
  2015-01-05 12:11   ` Sascha Hauer
@ 2015-01-05 16:16     ` robert.jarzmik
  2015-01-06 13:58       ` Sascha Hauer
  0 siblings, 1 reply; 8+ messages in thread
From: robert.jarzmik @ 2015-01-05 16:16 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


----- Mail original -----
De: "Sascha Hauer" <s.hauer@pengutronix.de>
À: "Robert Jarzmik" <robert.jarzmik@free.fr>
Cc: barebox@lists.infradead.org
Envoyé: Lundi 5 Janvier 2015 13:11:50
Objet: Re: [PATCH] net: smc1111: fix memory congestions

> I don't know the hardware (not anymore, fortunately ;), but isn't it
> possible to dedicate one bucket for transmitting only, so that it will
> never be occupied by a received packet?
None I'm aware of.
I've been through the specification many times, and my understanding is
that :
 - the MMU allocation is symmetric (either from CPU for TX or from NIC
   for RX)
 - there is no configurable threshold or limit
 - first customer is first served from the MMU point of view

Cheers.

--
Robert

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: smc1111: fix memory congestions
  2015-01-05 16:16     ` robert.jarzmik
@ 2015-01-06 13:58       ` Sascha Hauer
  0 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2015-01-06 13:58 UTC (permalink / raw)
  To: robert.jarzmik; +Cc: barebox

On Mon, Jan 05, 2015 at 05:16:48PM +0100, robert.jarzmik@free.fr wrote:
> 
> ----- Mail original -----
> De: "Sascha Hauer" <s.hauer@pengutronix.de>
> À: "Robert Jarzmik" <robert.jarzmik@free.fr>
> Cc: barebox@lists.infradead.org
> Envoyé: Lundi 5 Janvier 2015 13:11:50
> Objet: Re: [PATCH] net: smc1111: fix memory congestions
> 
> > I don't know the hardware (not anymore, fortunately ;), but isn't it
> > possible to dedicate one bucket for transmitting only, so that it will
> > never be occupied by a received packet?
> None I'm aware of.
> I've been through the specification many times, and my understanding is
> that :
>  - the MMU allocation is symmetric (either from CPU for TX or from NIC
>    for RX)
>  - there is no configurable threshold or limit
>  - first customer is first served from the MMU point of view

Ok then, applied.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2015-01-06 13:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-01 20:04 [PATCH] commands: loady: fix bug with netconsole Robert Jarzmik
2015-01-01 20:04 ` [PATCH] net: smc1111: fix memory congestions Robert Jarzmik
2015-01-05 12:11   ` Sascha Hauer
2015-01-05 16:16     ` robert.jarzmik
2015-01-06 13:58       ` Sascha Hauer
2015-01-01 20:04 ` [PATCH] net: smc1111: move print_packet function Robert Jarzmik
2015-01-05 12:12   ` Sascha Hauer
2015-01-05 12:12 ` [PATCH] commands: loady: fix bug with netconsole Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox