Skip to contentSkip to conversation

net: ethernet: add driver for Aurora VLSI NB8800 Ethernet controller

PATCH Applied Mans Rullgard 4 participants 11 messages Nov 19, 2015 – Nov 25, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v8 1/1 net: ethernet: add driver for Aurora VLSI NB8800 Ethernet controller

This adds a driver for the Aurora VLSI NB8800 Ethernet controller. It is an almost complete rewrite of a driver originally found in a Sigma Designs 2.6.22 tree.

---
Changes:
- make some variables unsigned

---
 drivers/net/ethernet/Kconfig         |    1 +
 drivers/net/ethernet/Makefile        |    1 +
 drivers/net/ethernet/aurora/Kconfig  |   20 +
 drivers/net/ethernet/aurora/Makefile |    1 +
 drivers/net/ethernet/aurora/nb8800.c | 1552 ++++++++++++++++++++++++++++++++++
 drivers/net/ethernet/aurora/nb8800.h |  316 +++++++
 6 files changed, 1891 insertions(+)
 create mode 100644 drivers/net/ethernet/aurora/Kconfig
 create mode 100644 drivers/net/ethernet/aurora/Makefile
 create mode 100644 drivers/net/ethernet/aurora/nb8800.c
 create mode 100644 drivers/net/ethernet/aurora/nb8800.h
drivers/net/ethernet/Kconfig +1 -0
index 05aa759..8310163 100644
@@ -29,6 +29,7 @@ source "drivers/net/ethernet/apm/Kconfig"
 source "drivers/net/ethernet/apple/Kconfig"
 source "drivers/net/ethernet/arc/Kconfig"
 source "drivers/net/ethernet/atheros/Kconfig"
+source "drivers/net/ethernet/aurora/Kconfig"
 source "drivers/net/ethernet/cadence/Kconfig"
 source "drivers/net/ethernet/adi/Kconfig"
 source "drivers/net/ethernet/broadcom/Kconfig"
drivers/net/ethernet/Makefile +1 -0
index ddfc808..b435fb0 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_NET_XGENE) += apm/
 obj-$(CONFIG_NET_VENDOR_APPLE) += apple/
 obj-$(CONFIG_NET_VENDOR_ARC) += arc/
 obj-$(CONFIG_NET_VENDOR_ATHEROS) += atheros/
+obj-$(CONFIG_NET_VENDOR_AURORA) += aurora/
 obj-$(CONFIG_NET_CADENCE) += cadence/
 obj-$(CONFIG_NET_BFIN) += adi/
 obj-$(CONFIG_NET_VENDOR_BROADCOM) += broadcom/
drivers/net/ethernet/aurora/Kconfig new file +20 -0
new file mode 100644
index 0000000..a3c7106
@@ -0,0 +1,20 @@
+config NET_VENDOR_AURORA
+	bool "Aurora VLSI devices"
+	help
+	  If you have a network (Ethernet) device belonging to this class,
+	  say Y.
+
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  questions about Aurora devices. If you say Y, you will be asked
+	  for your specific device in the following questions.
+
+if NET_VENDOR_AURORA
+
+config AURORA_NB8800
+	tristate "Aurora AU-NB8800 support"
+	select PHYLIB
+	help
+	 Support for the AU-NB8800 gigabit Ethernet controller.
+
+endif
drivers/net/ethernet/aurora/Makefile new file +1 -0
new file mode 100644
index 0000000..6cb528a
@@ -0,0 +1 @@
+obj-$(CONFIG_AURORA_NB8800) += nb8800.o
drivers/net/ethernet/aurora/nb8800.c new file +1552 -0

1,552 lines not on this page · raw message

drivers/net/ethernet/aurora/nb8800.h new file +316 -0

316 lines not on this page · raw message

Signature · 1 line
2.6.3
maintainer Applied
#1 lore raw

From: Mans Rullgard <[email protected]>
Date: Thu, 19 Nov 2015 13:02:59 +0000

Quoted 5 lines

This adds a driver for the Aurora VLSI NB8800 Ethernet controller. It is an almost complete rewrite of a driver originally found in a Sigma Designs 2.6.22 tree.

Applied, thank you.

#2 lore raw
In reply to Mans Rullgard

drivers/net/ethernet/aurora/nb8800.c line 221

Quoted 4 lines · Mans Rullgard
drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+	if (dma_mapping_error(&dev->dev, dma_addr)) {
+		skb_free_frag(data);
+		return -ENOMEM;
+	}

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

+static inline void skb_free_frag(void *addr)
+{
+ __free_page_frag(addr);
+}

Should I just copy the definition of __free_page_frag() ?

/*
* Frees a page fragment allocated out of either a compound or order 0 page. */
void __free_page_frag(void *addr)

{
	struct page *page = virt_to_head_page(addr);

	if (unlikely(put_page_testzero(page)))
		__free_pages_ok(page, compound_order(page));
}

Regards.

#3 lore raw
Quoted 16 lines · Mason

drivers/net/ethernet/aurora/nb8800.c line 221

Quoted 4 lines · Mans Rullgard
drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+	if (dma_mapping_error(&dev->dev, dma_addr)) {
+		skb_free_frag(data);
+		return -ENOMEM;
+	}

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+static inline void skb_free_frag(void *addr)
+{
+       __free_page_frag(addr);
+}
Quoted 1 line

Should I just copy the definition of __free_page_frag() ?

Looks like it ought to work. Try and find out. Not that you'll ever hit that error condition unless you fake it.

Quoted 13 lines

/*
* Frees a page fragment allocated out of either a compound or order 0 page. */
void __free_page_frag(void *addr)

{
	struct page *page = virt_to_head_page(addr);

	if (unlikely(put_page_testzero(page)))
		__free_pages_ok(page, compound_order(page));
}

Regards.

Signature · 2 lines
Måns Rullgård
[email protected]
#4 lore raw
Quoted 18 lines · Måns Rullgård
Quoted 16 lines · Mason

drivers/net/ethernet/aurora/nb8800.c line 221

Quoted 4 lines · Mans Rullgard
drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+	if (dma_mapping_error(&dev->dev, dma_addr)) {
+		skb_free_frag(data);
+		return -ENOMEM;
+	}

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+static inline void skb_free_frag(void *addr)
+{
+       __free_page_frag(addr);
+}
Quoted 4 lines
Quoted 1 line

Should I just copy the definition of __free_page_frag() ?

Looks like it ought to work. Try and find out. Not that you'll ever hit that error condition unless you fake it.

Turns out __free_pages_ok() is static and I'd rather not touch mm/page_alloc.c in my back-port.

Since you say the error condition is rare, I think I'll go with the code that 181edb2bfa22b replaced (put_page, IIUC).

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #define skb_free_frag(data) put_page(virt_to_head_page(data)) #else
#error DELETE ME NOW (see commit 181edb2bfa22b) #endif

Alexander, does that look correct?

Regards.

#5 lore raw
Quoted 31 lines · Mason
Quoted 18 lines · Måns Rullgård
Quoted 16 lines · Mason

drivers/net/ethernet/aurora/nb8800.c line 221

Quoted 4 lines · Mans Rullgard
drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+	if (dma_mapping_error(&dev->dev, dma_addr)) {
+		skb_free_frag(data);
+		return -ENOMEM;
+	}

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+static inline void skb_free_frag(void *addr)
+{
+       __free_page_frag(addr);
+}
Quoted 4 lines
Quoted 1 line

Should I just copy the definition of __free_page_frag() ?

Looks like it ought to work. Try and find out. Not that you'll ever hit that error condition unless you fake it.

Turns out __free_pages_ok() is static and I'd rather not touch mm/page_alloc.c in my back-port.

Since you say the error condition is rare, I think I'll go with the code that 181edb2bfa22b replaced (put_page, IIUC).

Quoted 6 lines

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #define skb_free_frag(data) put_page(virt_to_head_page(data)) #else
#error DELETE ME NOW (see commit 181edb2bfa22b) #endif

You can simply put_page(page) instead since we already have the virt_to_head_page() a few lines up.

Signature · 2 lines
Måns Rullgård
[email protected]
#6 lore raw
Quoted 40 lines · Måns Rullgård
Quoted 31 lines · Mason
Quoted 18 lines · Måns Rullgård
Quoted 16 lines · Mason

drivers/net/ethernet/aurora/nb8800.c line 221

Quoted 4 lines · Mans Rullgard
drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+  if (dma_mapping_error(&dev->dev, dma_addr)) {
+          skb_free_frag(data);
+          return -ENOMEM;
+  }

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+static inline void skb_free_frag(void *addr)
+{
+       __free_page_frag(addr);
+}
Quoted 4 lines
Quoted 1 line

Should I just copy the definition of __free_page_frag() ?

Looks like it ought to work. Try and find out. Not that you'll ever hit that error condition unless you fake it.

Turns out __free_pages_ok() is static and I'd rather not touch mm/page_alloc.c in my back-port.

Since you say the error condition is rare, I think I'll go with the code that 181edb2bfa22b replaced (put_page, IIUC).

Quoted 6 lines

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #define skb_free_frag(data) put_page(virt_to_head_page(data)) #else
#error DELETE ME NOW (see commit 181edb2bfa22b) #endif

Quoted 2 lines

You can simply put_page(page) instead since we already have the virt_to_head_page() a few lines up.

What you could do is use __free_pages instead of __free_pages_ok. Generally you will want to use __free_pages instead of put_page just to avoid a bunch of unnecessary tests and function pointer accesses.

The result would look something like:
static inline void skb_free_frag(void *addr)

{
       struct page *page = virt_to_head_page(addr);

        __free_pages(page, compound_order(page));
}

Hope that helps.

- Alex

#7 lore raw
Quoted 41 lines · Alexander Duyck
Quoted 40 lines · Måns Rullgård
Quoted 37 lines · Mason
Quoted 18 lines · Måns Rullgård
Quoted 16 lines · Mason

drivers/net/ethernet/aurora/nb8800.c line 221

Quoted 4 lines · Mans Rullgard
drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+  if (dma_mapping_error(&dev->dev, dma_addr)) {
+          skb_free_frag(data);
+          return -ENOMEM;
+  }

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+static inline void skb_free_frag(void *addr)
+{
+       __free_page_frag(addr);
+}
Quoted 4 lines
Quoted 1 line

Should I just copy the definition of __free_page_frag() ?

Looks like it ought to work. Try and find out. Not that you'll ever hit that error condition unless you fake it.

Turns out __free_pages_ok() is static and I'd rather not touch mm/page_alloc.c in my back-port.

Since you say the error condition is rare, I think I'll go with the code that 181edb2bfa22b replaced (put_page, IIUC).

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #define skb_free_frag(data) put_page(virt_to_head_page(data)) #else
#error DELETE ME NOW (see commit 181edb2bfa22b) #endif

Quoted 6 lines
Quoted 2 lines

You can simply put_page(page) instead since we already have the virt_to_head_page() a few lines up.

What you could do is use __free_pages instead of __free_pages_ok. Generally you will want to use __free_pages instead of put_page just to avoid a bunch of unnecessary tests and function pointer accesses.

Note that this is on a should-never-happen error path, so there's no need to be counting cycles.

Signature · 2 lines
Måns Rullgård
[email protected]
#8 lore raw
Quoted 47 lines · Måns Rullgård
Quoted 45 lines · Alexander Duyck
Quoted 42 lines · Måns Rullgård
Quoted 31 lines · Mason
Quoted 18 lines · Måns Rullgård
Quoted 16 lines · Mason

Review

Quoted 4 lines · Mans Rullgard
(quoted diff) +4 -0
+  if (dma_mapping_error(&dev->dev, dma_addr)) {
+          skb_free_frag(data);
+          return -ENOMEM;
+  }

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

(quoted diff) +4 -0
+static inline void skb_free_frag(void *addr)
+{
+       __free_page_frag(addr);
+}
Quoted 4 lines
Quoted 1 line

Should I just copy the definition of __free_page_frag() ?

Looks like it ought to work. Try and find out. Not that you'll ever hit that error condition unless you fake it.

Turns out __free_pages_ok() is static and I'd rather not touch mm/page_alloc.c in my back-port.

Since you say the error condition is rare, I think I'll go with the code that 181edb2bfa22b replaced (put_page, IIUC).

Quoted 6 lines

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #define skb_free_frag(data) put_page(virt_to_head_page(data)) #else
#error DELETE ME NOW (see commit 181edb2bfa22b) #endif

You can simply put_page(page) instead since we already have the virt_to_head_page() a few lines up.

Quoted 6 lines
Quoted 3 lines

What you could do is use __free_pages instead of __free_pages_ok. Generally you will want to use __free_pages instead of put_page just to avoid a bunch of unnecessary tests and function pointer accesses.

Note that this is on a should-never-happen error path, so there's no need to be counting cycles.

Per Mans' advice, I have locally committed this patch:

drivers/net/ethernet/aurora/nb8800.c +7 -0
index ecc4a334c507..9f929be96b74 100644
@@ -39,6 +39,13 @@
 
 #include "nb8800.h"
 
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
+#define skb_free_frag(data) put_page(page)
+#else
+#error DELETE ME NOW (see commit 181edb2bfa22)
+#endif
+
 static void nb8800_tx_done(struct net_device *dev);
 static int nb8800_dma_stop(struct net_device *dev);
 

Regards.

#9 lore raw
Quoted 65 lines · Mason
Quoted 47 lines · Måns Rullgård
Quoted 45 lines · Alexander Duyck
Quoted 42 lines · Måns Rullgård
Quoted 31 lines · Mason
Quoted 18 lines · Måns Rullgård
Quoted 16 lines · Mason

Review

Quoted 4 lines · Mans Rullgard
(quoted diff) +4 -0
+  if (dma_mapping_error(&dev->dev, dma_addr)) {
+          skb_free_frag(data);
+          return -ENOMEM;
+  }

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

(quoted diff) +4 -0
+static inline void skb_free_frag(void *addr)
+{
+       __free_page_frag(addr);
+}
Quoted 4 lines
Quoted 1 line

Should I just copy the definition of __free_page_frag() ?

Looks like it ought to work. Try and find out. Not that you'll ever hit that error condition unless you fake it.

Turns out __free_pages_ok() is static and I'd rather not touch mm/page_alloc.c in my back-port.

Since you say the error condition is rare, I think I'll go with the code that 181edb2bfa22b replaced (put_page, IIUC).

Quoted 6 lines

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #define skb_free_frag(data) put_page(virt_to_head_page(data)) #else
#error DELETE ME NOW (see commit 181edb2bfa22b) #endif

You can simply put_page(page) instead since we already have the virt_to_head_page() a few lines up.

Quoted 6 lines
Quoted 3 lines

What you could do is use __free_pages instead of __free_pages_ok. Generally you will want to use __free_pages instead of put_page just to avoid a bunch of unnecessary tests and function pointer accesses.

Note that this is on a should-never-happen error path, so there's no need to be counting cycles.

Per Mans' advice, I have locally committed this patch:

drivers/net/ethernet/aurora/nb8800.c +0 -0
index ecc4a334c507..9f929be96b74 100644
@@ -39,6 +39,13 @@
 
 #include "nb8800.h"

drivers/net/ethernet/aurora/nb8800.c line 50

Quoted 10 lines
drivers/net/ethernet/aurora/nb8800.c +7 -0
 
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
+#define skb_free_frag(data) put_page(page)
+#else
+#error DELETE ME NOW (see commit 181edb2bfa22)
+#endif
+
 static void nb8800_tx_done(struct net_device *dev);
 static int nb8800_dma_stop(struct net_device *dev);

That works only by accident due to how local variables are named. If you want a macro to emulate the new function, your first suggestion is better. I thought you were going to change the actual function.

Signature · 2 lines
Måns Rullgård
[email protected]
#10 lore raw
In reply to Mason

[ Using different address for Alexander ]

Quoted 28 lines · Mason

drivers/net/ethernet/aurora/nb8800.c line 221

Quoted 4 lines · Mans Rullgard
drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+	if (dma_mapping_error(&dev->dev, dma_addr)) {
+		skb_free_frag(data);
+		return -ENOMEM;
+	}

I'm back-porting this driver to 4.1

skb_free_frag() was introduced in 4.2 by 181edb2bfa22b IIUC.

drivers/net/ethernet/aurora/nb8800.c new file +4 -0
+static inline void skb_free_frag(void *addr)
+{
+       __free_page_frag(addr);
+}

Should I just copy the definition of __free_page_frag() ?

/*
* Frees a page fragment allocated out of either a compound or order 0 page. */
void __free_page_frag(void *addr)

{
	struct page *page = virt_to_head_page(addr);

	if (unlikely(put_page_testzero(page)))
		__free_pages_ok(page, compound_order(page));
}