Skip to contentSkip to conversation

ethernet/arc/arc_emac - Add new driver

PATCH Superseded Alexey Brodkin 2 participants 5 messages Jun 15, 2013 – Jun 17, 2013

Subsystems (3)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 ethernet/arc/arc_emac - Add new driver

Driver for non-standard on-chip ethernet device ARC EMAC 10/100, instantiated in some legacy ARC (Synopsys) FPGA Boards such as ARCAngel4/ML50x.

This is based off of current Linus tree.

Cc Andy Shevchenko <[email protected]>
Cc Francois Romieu <[email protected]>
Cc Joe Perches <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc Mischa Jonker <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Paul Gortmaker <[email protected]>
Cc "David S. Miller" <[email protected]>

---
Hi all,

please take a look at 4th iteration of my patch.

Even though it's already 4th re-spin it still contains some major changes.
Once again I have to thank Andy Shevchenko & Francois Romieu for their attention and very valuable advices.

Below is a list of main changes in this re-spin.

1. Functional changes:
1.1. Endian-friendly access to buffer descriptors.
1.2. Introduce separate "arc_emac_rx" for receiving packets and invoke it from NAPI poll routine.
1.3. Introduce separate "arc_emac_tx_clean" for cleaing transmitted BDs and invoke it from NAPI poll routine.
1.4. Add memory barriers to make sure pointers to valid data buffers are set before EMAC may start dealing with it.
1.5. Use "skb_padto" for packets smaller than ETH_ZLEN.
1.6. Move "clock_frequency" as a local variable to "probe". It is only used once to set poll period in EMAC, so why don't do it in probe. 1.7. "netif_receive_skb" only if next skb was allocated. 1.8. Fix bahavior of "arc_emac_rx" - stop processing on the first BD owned by EMAC.
1.9. Add more errors to "stats".
1.10. Move "phy_node" variable from private structure to local in "arc_emac_probe" as used only once.

2. Cosmetics:
2.1. Rename source files - no need to have "arc_" prefix in separate "arc" folder.
2.1. Add kernel-doc description to data structures in "emac.h". 2.3. Rename some fields in EMAC's private data structure. 2.2. Minor cosmetics.

---
 Documentation/devicetree/bindings/net/arc_emac.txt |   38 +
 drivers/net/ethernet/Kconfig                       |    1 +
 drivers/net/ethernet/Makefile                      |    1 +
 drivers/net/ethernet/arc/Kconfig                   |   31 +
 drivers/net/ethernet/arc/Makefile                  |    6 +
 drivers/net/ethernet/arc/emac.h                    |  214 +++++
 drivers/net/ethernet/arc/emac_main.c               |  832 ++++++++++++++++++++
 drivers/net/ethernet/arc/emac_mdio.c               |  151 ++++
 8 files changed, 1274 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/arc_emac.txt
 create mode 100644 drivers/net/ethernet/arc/Kconfig
 create mode 100644 drivers/net/ethernet/arc/Makefile
 create mode 100644 drivers/net/ethernet/arc/emac.h
 create mode 100644 drivers/net/ethernet/arc/emac_main.c
 create mode 100644 drivers/net/ethernet/arc/emac_mdio.c
Documentation/devicetree/bindings/net/arc_emac.txt new file +38 -0
new file mode 100644
index 0000000..bcbc3f0
@@ -0,0 +1,38 @@
+* Synopsys ARC EMAC 10/100 Ethernet driver (EMAC)
+
+Required properties:
+- compatible: Should be "snps,arc-emac"
+- reg: Address and length of the register set for the device
+- interrupts: Should contain the EMAC interrupts
+- clock-frequency: CPU frequency. It is needed to calculate and set polling
+period of EMAC.
+- max-speed: Maximum supported data-rate in Mbit/s. In some HW configurations
+bandwidth of external memory controller might be a limiting factor. That's why
+it's required to specify which data-rate is supported on current SoC or FPGA.
+For example if only 10 Mbit/s is supported (10BASE-T) set "10". If 100 Mbit/s is
+supported (100BASE-TX) set "100".
+- phy: PHY device attached to the EMAC via MDIO bus
+
+Child nodes of the driver are the individual PHY devices connected to the
+MDIO bus. They must have a "reg" property given the PHY address on the MDIO bus.
+
+Optional properties:
+- mac-address: 6 bytes, mac address
+
+Examples:
+
+	ethernet@c0fc2000 {
+		compatible = "snps,arc-emac";
+		reg = <0xc0fc2000 0x3c>;
+		interrupts = <6>;
+		mac-address = [ 00 11 22 33 44 55 ];
+		clock-frequency = <80000000>;
+		max-speed = <100>;
+		phy = <&phy0>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+		phy0: ethernet-phy@0 {
+			reg = <1>;
+		};
+	};
drivers/net/ethernet/Kconfig +1 -0
index 4bedae2..98eec48 100644
@@ -23,6 +23,7 @@ source "drivers/net/ethernet/aeroflex/Kconfig"
 source "drivers/net/ethernet/alteon/Kconfig"
 source "drivers/net/ethernet/amd/Kconfig"
 source "drivers/net/ethernet/apple/Kconfig"
+source "drivers/net/ethernet/arc/Kconfig"
 source "drivers/net/ethernet/atheros/Kconfig"
 source "drivers/net/ethernet/cadence/Kconfig"
 source "drivers/net/ethernet/adi/Kconfig"
drivers/net/ethernet/Makefile +1 -0
index 183e3f4..b764c73 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_GRETH) += aeroflex/
 obj-$(CONFIG_NET_VENDOR_ALTEON) += alteon/
 obj-$(CONFIG_NET_VENDOR_AMD) += amd/
 obj-$(CONFIG_NET_VENDOR_APPLE) += apple/
+obj-$(CONFIG_NET_VENDOR_ARC) += arc/
 obj-$(CONFIG_NET_VENDOR_ATHEROS) += atheros/
 obj-$(CONFIG_NET_CADENCE) += cadence/
 obj-$(CONFIG_NET_BFIN) += adi/
drivers/net/ethernet/arc/Kconfig new file +31 -0
new file mode 100644
index 0000000..514c57f
@@ -0,0 +1,31 @@
+#
+# ARC EMAC network device configuration
+#
+
+config NET_VENDOR_ARC
+	bool "ARC devices"
+	default y
+	---help---
+	  If you have a network (Ethernet) card belonging to this class, say Y
+	  and read the Ethernet-HOWTO, available from
+	  <http://www.tldp.org/docs.html#howto>.
+
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about ARC cards. If you say Y, you will be asked for
+	  your specific card in the following questions.
+
+if NET_VENDOR_ARC
+
+config ARC_EMAC
+	tristate "ARC EMAC support"
+	select MII
+	select PHYLIB
+	depends on OF_IRQ
+	depends on OF_NET
+	---help---
+	  On some legacy ARC (Synopsys) FPGA boards such as ARCAngel4/ML50x
+	  non-standard on-chip ethernet device ARC EMAC 10/100 is used.
+	  Say Y here if you have such a board.  If unsure, say N.
+
+endif # NET_VENDOR_ARC
drivers/net/ethernet/arc/Makefile new file +6 -0
new file mode 100644
index 0000000..00c8657
@@ -0,0 +1,6 @@
+#
+# Makefile for the ARC network device drivers.
+#
+
+arc_emac-objs := emac_main.o emac_mdio.o
+obj-$(CONFIG_ARC_EMAC) += arc_emac.o
drivers/net/ethernet/arc/emac.h new file +214 -0

214 lines not on this page · raw message

drivers/net/ethernet/arc/emac_main.c new file +832 -0

832 lines not on this page · raw message

drivers/net/ethernet/arc/emac_mdio.c new file +151 -0

151 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#1 lore raw

drivers/net/ethernet/arc/emac_main.c

Quoted 5 lines · Alexey Brodkin

Driver for non-standard on-chip ethernet device ARC EMAC 10/100, instantiated in some legacy ARC (Synopsys) FPGA Boards such as ARCAngel4/ML50x.

drivers/net/ethernet/arc/emac_main.c +0 -0

[]

drivers/net/ethernet/arc/emac_main.c line 57

Quoted 1 line
drivers/net/ethernet/arc/emac_main.c +1 -0
+		if (DUPLEX_FULL == phy_dev->duplex)

Most all kernel code uses "if (var == constant)"
as that's how most people think.

[]

Quoted 1 line

+static int arc_emac_rx(struct net_device *ndev, int budget)

[]

drivers/net/ethernet/arc/emac_main.c line 256

Quoted 5 lines
drivers/net/ethernet/arc/emac_main.c +5 -0
+		/* Prepare the BD for next cycle */
+		rx_buff->skb = netdev_alloc_skb_ip_align(ndev, buflen);
+		if (unlikely(!rx_buff->skb)) {
+			if (net_ratelimit())
+				netdev_err(ndev, "cannot allocate skb\n");

Unnecessary OOM message, might as well remove it.
rx_dropped gives the same info.

#2 lore raw
Quoted 11 lines · Joe Perches

drivers/net/ethernet/arc/emac_main.c

Quoted 5 lines · Alexey Brodkin

Driver for non-standard on-chip ethernet device ARC EMAC 10/100, instantiated in some legacy ARC (Synopsys) FPGA Boards such as ARCAngel4/ML50x.

drivers/net/ethernet/arc/emac_main.c +0 -0

[]

drivers/net/ethernet/arc/emac_main.c line 57

Quoted 1 line
drivers/net/ethernet/arc/emac_main.c +1 -0
+		if (DUPLEX_FULL == phy_dev->duplex)

Most all kernel code uses "if (var == constant)"
as that's how most people think.

Makes sense.

Quoted 4 lines

[]

Quoted 1 line

+static int arc_emac_rx(struct net_device *ndev, int budget)

[]

Quoted 8 lines

drivers/net/ethernet/arc/emac_main.c line 256

Quoted 5 lines
drivers/net/ethernet/arc/emac_main.c +5 -0
+		/* Prepare the BD for next cycle */
+		rx_buff->skb = netdev_alloc_skb_ip_align(ndev, buflen);
+		if (unlikely(!rx_buff->skb)) {
+			if (net_ratelimit())
+				netdev_err(ndev, "cannot allocate skb\n");

Unnecessary OOM message, might as well remove it.
rx_dropped gives the same info.

With all those error messages I wanted to make life easier (especially for me) if errors appear. User will immediately know where problem happened. Indeed "rx_dropped" (when it is used only once in driver) may show where issue happened, but if later at some point "rx_dropped" will be incremented in other locations then user won't understand immediately where error happened.

-Alexey

#3 lore raw
Quoted 2 lines · Alexey Brodkin
Quoted 1 line · Joe Perches

On Sun, 2013-06-16 at 00:20 +0400, Alexey Brodkin wrote:

[]

Quoted 11 lines
Quoted 10 lines
Quoted 1 line

+static int arc_emac_rx(struct net_device *ndev, int budget)

[]

drivers/net/ethernet/arc/emac_main.c line 256

Quoted 5 lines
drivers/net/ethernet/arc/emac_main.c new file +5 -0
+		/* Prepare the BD for next cycle */
+		rx_buff->skb = netdev_alloc_skb_ip_align(ndev, buflen);
+		if (unlikely(!rx_buff->skb)) {
+			if (net_ratelimit())
+				netdev_err(ndev, "cannot allocate skb\n");

Unnecessary OOM message, might as well remove it.
rx_dropped gives the same info.

Quoted 6 lines

With all those error messages I wanted to make life easier (especially for me) if errors appear. User will immediately know where problem happened. Indeed "rx_dropped" (when it is used only once in driver) may show where issue happened, but if later at some point "rx_dropped" will be incremented in other locations then user won't understand immediately where error happened.

Alloc errors emit a dump_stack() already so this is redundant.

#4 lore raw
Quoted 15 lines · Joe Perches
Quoted 2 lines · Alexey Brodkin
Quoted 1 line · Joe Perches

On Sun, 2013-06-16 at 00:20 +0400, Alexey Brodkin wrote:

[]

Quoted 11 lines
Quoted 10 lines
Quoted 1 line

+static int arc_emac_rx(struct net_device *ndev, int budget)

[]

drivers/net/ethernet/arc/emac_main.c line 256

Quoted 5 lines
drivers/net/ethernet/arc/emac_main.c new file +5 -0
+		/* Prepare the BD for next cycle */
+		rx_buff->skb = netdev_alloc_skb_ip_align(ndev, buflen);
+		if (unlikely(!rx_buff->skb)) {
+			if (net_ratelimit())
+				netdev_err(ndev, "cannot allocate skb\n");

Unnecessary OOM message, might as well remove it.
rx_dropped gives the same info.

Quoted 8 lines
Quoted 6 lines

With all those error messages I wanted to make life easier (especially for me) if errors appear. User will immediately know where problem happened. Indeed "rx_dropped" (when it is used only once in driver) may show where issue happened, but if later at some point "rx_dropped" will be incremented in other locations then user won't understand immediately where error happened.

Alloc errors emit a dump_stack() already so this is redundant.

Makes sense. Will remove this comment.

-Alexey