Skip to contentSkip to conversation

mvme147: use correct order of ram pages

PATCH In review Amos Kong 3 participants 4 messages May 28, 2014

Subsystems (3)
lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 mvme147: use correct order of ram pages

16K is 2^2 * PAGE_SIZE, so the page order should be 2, not 3.

This patch uses get_order() to get correct order, and fixes one typo in comment.

---
This patch wasn't built. Geert, can you help to test it? I don't know if it needs a head file by using get_order().

---
 drivers/net/ethernet/amd/mvme147.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/amd/mvme147.c +5 -4
index 0e8399d..4e98bf8 100644
@@ -26,10 +26,11 @@
 #include <asm/pgtable.h>
 #include <asm/mvme147hw.h>
 
-/* We have 16834 bytes of RAM for the init block and buffers. This places
+/* We have 16384 bytes of RAM for the init block and buffers. This places
  * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
  * buffers and 2 Tx buffers.
  */
+#define M147LANCE_RAM_SIZE   16384 /* 16K */
 #define LANCE_LOG_TX_BUFFERS 1
 #define LANCE_LOG_RX_BUFFERS 3
 
@@ -111,7 +112,7 @@ struct net_device * __init mvme147lance_probe(int unit)
 	       dev->dev_addr);
 
 	lp = netdev_priv(dev);
-	lp->ram = __get_dma_pages(GFP_ATOMIC, 3);	/* 16K */
+	lp->ram = __get_dma_pages(GFP_ATOMIC, get_order(M147LANCE_RAM_SIZE));
 	if (!lp->ram) {
 		printk("%s: No memory for LANCE buffers\n", dev->name);
 		free_netdev(dev);
@@ -134,7 +135,7 @@ struct net_device * __init mvme147lance_probe(int unit)
 
 	err = register_netdev(dev);
 	if (err) {
-		free_pages(lp->ram, 3);
+		free_pages(lp->ram, get_order(M147LANCE_RAM_SIZE));
 		free_netdev(dev);
 		return ERR_PTR(err);
 	}
@@ -193,7 +194,7 @@ void __exit cleanup_module(void)
 {
 	struct m147lance_private *lp = netdev_priv(dev_mvme147_lance);
 	unregister_netdev(dev_mvme147_lance);
-	free_pages(lp->ram, 3);
+	free_pages(lp->ram, get_order(M147LANCE_RAM_SIZE));
 	free_netdev(dev_mvme147_lance);
 }
 
Signature · 1 line
1.9.0
#1 lore raw

Hi Amos,

Quoted 4 lines · Amos Kong

16K is 2^2 * PAGE_SIZE, so the page order should be 2, not 3.

This patch uses get_order() to get correct order, and fixes one typo in comment.

Thanks for your patch!

Quoted 4 lines

---
This patch wasn't built. Geert, can you help to test it? I don't know if it needs a head file by using get_order().

It builds fine. The get_order() is nicely expanded to "2" in the assembler output.

Now, I'd like to get some feedback from the MVME hackers first. Perhaps the comment was wrong?

drivers/net/ethernet/amd/mvme147.c line 35

Quoted 8 lines
drivers/net/ethernet/amd/mvme147.c +2 -1
-/* We have 16834 bytes of RAM for the init block and buffers. This places
+/* We have 16384 bytes of RAM for the init block and buffers. This places
  * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
  * buffers and 2 Tx buffers.
  */
+#define M147LANCE_RAM_SIZE   16384 /* 16K */
 #define LANCE_LOG_TX_BUFFERS 1
 #define LANCE_LOG_RX_BUFFERS 3

BTW,I also find it fishy why the driver uses only 1+3 buffers, since more RAM is available.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw
Quoted 11 lines · Geert Uytterhoeven

drivers/net/ethernet/amd/mvme147.c line 35

Quoted 8 lines
drivers/net/ethernet/amd/mvme147.c +2 -1
-/* We have 16834 bytes of RAM for the init block and buffers. This places
+/* We have 16384 bytes of RAM for the init block and buffers. This places
  * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
  * buffers and 2 Tx buffers.
  */
+#define M147LANCE_RAM_SIZE   16384 /* 16K */
 #define LANCE_LOG_TX_BUFFERS 1
 #define LANCE_LOG_RX_BUFFERS 3

BTW,I also find it fishy why the driver uses only 1+3 buffers, since more RAM is available.

It's 2^1+2^3.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
author
#3 lore raw
Quoted 11 lines · Andreas Schwab
Quoted 9 lines · Geert Uytterhoeven

drivers/net/ethernet/amd/mvme147.c line 35

Quoted 8 lines
drivers/net/ethernet/amd/mvme147.c +2 -1
-/* We have 16834 bytes of RAM for the init block and buffers. This places
+/* We have 16384 bytes of RAM for the init block and buffers. This places
  * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
  * buffers and 2 Tx buffers.
  */
+#define M147LANCE_RAM_SIZE   16384 /* 16K */
 #define LANCE_LOG_TX_BUFFERS 1
 #define LANCE_LOG_RX_BUFFERS 3

#define TX_RING_SIZE (1 << LANCE_LOG_TX_BUFFERS)
#define RX_RING_SIZE (1 << LANCE_LOG_RX_BUFFERS)

Quoted 4 lines
Quoted 2 lines

BTW,I also find it fishy why the driver uses only 1+3 buffers, since more RAM is available.

It's 2^1+2^3.

tx & rx bufs aren't 2^1 + 2^3 = 10 pages.

Rx buffers and Tx buffers are included in 'struct lance_init_block'

   volatile char tx_buf[TX_RING_SIZE][TX_BUFF_SIZE];
   volatile char rx_buf[RX_RING_SIZE][RX_BUFF_SIZE];

   volatile char tx_buf[2][1544];
   volatile char rx_buf[8][1544];

RX_BUFF_SIZE = TX_BUFF_SIZE = 1554
So tx_buf takes 1544 * 2 bytes, rx_buf takes 1544 * 8 bytes

In drivers/net/ethernet/amd/mvme147.c:
=====================================
lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */ lp->lance.lance_init_block = (struct lance_init_block*)(lp->ram); /* LANCE addr of same RAM */

init_block and lance_init_block are set same address

In drivers/net/ethernet/amd/a2065.c:
===================================
priv->init_block = (struct lance_init_block *)dev->mem_start; priv->lance_init_block = (struct lance_init_block *)A2065_RAM;

The ram size (A2065_RAM_SIZE) is 0x8000 -> 8 pages -> order is 3

It seems original 3 is a right order, we need to fix the comments. it's 2^3 * 4k = 32K = 32768 bytes.

But in drivers/net/ethernet/amd/hplance.c:
=========================================
#define HPLANCE_MEMOFF 0x8000 /* struct lance_init_block */ lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */

                                                          ^^^^ it skips 0x8000, that is for HPLANCE

lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */

We need 2 * 32k for lp->ram?

Quoted 10 lines

Andreas.

Signature · 7 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
			Amos.