Skip to contentSkip to conversation

ethernet/arc/arc_emac - Add new driver

PATCH Superseded Alexey Brodkin 2 participants 4 messages Jun 20, 2013 – Jun 21, 2013

Subsystems (3)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 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.

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]>
Cc Florian Fainelli <[email protected]>

---
Hi all,

please take a look at 6th re-spin of the patch.

There're only couple of minor changes compared to v5. Thanks to Andy Shevchenko and Florian Fainelli for comments.

1. Replaced "__cpu_to_le32" and "__le32_to_cpu" with non-"__" variants.
2. Reduced comments to minimum sensible contents.
3. Use "pdev->name" as a MII bus ID.

---
 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               |  814 ++++++++++++++++++++
 drivers/net/ethernet/arc/emac_mdio.c               |  152 ++++
 8 files changed, 1257 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 +814 -0

814 lines not on this page · raw message

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

152 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 3 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.

Few nitpicks below.

Quoted 1 line

please take a look at 6th re-spin of the patch.

Usually it's better to start new thread for new version of the patchset.

Quoted 8 lines

+++ b/drivers/net/ethernet/arc/emac_main.c

drivers/net/ethernet/arc/emac_main.c new file +6 -0
+static void arc_emac_tx_clean(struct net_device *ndev)
+{
+       struct arc_emac_priv *priv = netdev_priv(ndev);
+       struct net_device_stats *stats = &priv->stats;
+       unsigned int i;
+

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

Quoted 10 lines
drivers/net/ethernet/arc/emac_main.c new file +10 -0
+       for (i = 0; i < TX_BD_NUM; i++) {
+               unsigned int *txbd_dirty = &priv->txbd_dirty;
+               struct arc_emac_bd *txbd = &priv->txbd[*txbd_dirty];
+               struct buffer_state *tx_buff = &priv->tx_buff[*txbd_dirty];
+               struct sk_buff *skb = tx_buff->skb;
+               unsigned int info = le32_to_cpu(txbd->info);
+
+               *txbd_dirty = (*txbd_dirty + 1) % TX_BD_NUM;
+
+               if ((info & FOR_EMAC) || !txbd->data)

Redundant internal braces. Up to you.

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

Quoted 13 lines
drivers/net/ethernet/arc/emac_main.c new file +12 -0
+static int arc_emac_rx(struct net_device *ndev, int budget)
+{
+       struct arc_emac_priv *priv = netdev_priv(ndev);
+       unsigned int work_done;
+
+       for (work_done = 0; work_done <= budget; work_done++) {
 
+               /* Make a note that we saw a packet at this BD.
+                * So next time, driver starts from this + 1
+                */
+               *last_rx_bd = (*last_rx_bd + 1) % RX_BD_NUM;
+
+#define FRST_OR_LAST_MASK      (FRST_MASK | LAST_MASK)

You may re-use it in *_tx_clean() above.
Also, please use full English word FIRST. Actually is there any conflicts with existing drivers? Should it be with [ARC_]EMAC prefix?

Review

Quoted 2 lines
(quoted diff) +2 -0
+               /* Make sure pointer to data buffer is set */
+               mb();

I'm not so familiar with memory barriers, but is this somehow differ from smp_mb()?
Which one suits better? And what about the other places in this file?

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

Quoted 7 lines
drivers/net/ethernet/arc/emac_main.c new file +7 -0
+       /* Allocate Tx BD's similar to Rx BD's. All Tx BD's owned by CPU */
+       bd = priv->txbd;
+       for (i = 0; i < TX_BD_NUM; i++) {
+               bd->data = 0;
+               bd->info = 0;
+               bd++;
+       }

Looks like
memset(priv->txbd, 0, siezeof(*priv->txbd) * TX_BD_NUM);

Quoted 1 line

+ *info = cpu_to_le32(FOR_EMAC | FRST_MASK | LAST_MASK | len);

FOR_EMAC | FRST_OR_LAST_MASK | len ?

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

Quoted 2 lines
drivers/net/ethernet/arc/emac_main.c new file +2 -0
+       /* Increment index to point to the next BD */
+       *txbd_curr = (*txbd_curr + 1) % TX_BD_NUM;

+ Empty line?

Quoted 4 lines
drivers/net/ethernet/arc/emac_main.c new file +3 -0
+       /* Get "info" of the next BD */
 
+       /* Get PHY from device tree */
+       phy_node = of_parse_phandle(pdev->dev.of_node, "phy", 0);

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

Quoted 10 lines
drivers/net/ethernet/arc/emac_main.c new file +7 -0
 
+       /* Get EMAC registers base address from device tree */
+       err = of_address_to_resource(pdev->dev.of_node, 0, &res_regs);
 
+       /* Get CPU clock frequency from device tree */
+       if (of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+                                &clock_frequency)) {
 
+       /* Get IRQ from device tree */
+       err = of_irq_to_resource(pdev->dev.of_node, 0, &res_irq);

So, you don't like the idea to get as much as possible before alloc_netdev(), don't you?

--
With Best Regards,
Andy Shevchenko

#2 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Alexey Brodkin

please take a look at 6th re-spin of the patch.

Usually it's better to start new thread for new version of the patchset.

Oh, sorry, It seems Gmail too smart.

--
With Best Regards,
Andy Shevchenko

#3 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

On Thu, Jun 20, 2013 at 2:53 PM, Alexey Brodkin

Quoted 1 line

+ if ((info & FOR_EMAC) || !txbd->data)

Redundant internal braces. Up to you.

I left them so priorities of operations will be obvious.

Quoted 5 lines
Quoted 1 line

+#define FRST_OR_LAST_MASK (FRST_MASK | LAST_MASK)

You may re-use it in *_tx_clean() above.
Also, please use full English word FIRST. Actually is there any conflicts with existing drivers? Should it be with [ARC_]EMAC prefix?

Re-used it in 2 mentioned places. And changed FRST with FIRST. I don't see defines with the same name anywhere else.

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+               /* Make sure pointer to data buffer is set */
+               mb();

I'm not so familiar with memory barriers, but is this somehow differ from smp_mb()?
Which one suits better? And what about the other places in this file?

Since for now driver itself is not SMP-safe so I don't see any reason for "smp_" barriers. Later I plan to add SMP compatibility and that this point barriers will be replaced as well.

Another thing is I switched to "wmb()" (which is a barrier fror write in particular) instead of generic "mb()".

Quoted 10 lines

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

Quoted 7 lines
drivers/net/ethernet/arc/emac_main.c new file +7 -0
+       /* Allocate Tx BD's similar to Rx BD's. All Tx BD's owned by CPU */
+       bd = priv->txbd;
+       for (i = 0; i < TX_BD_NUM; i++) {
+               bd->data = 0;
+               bd->info = 0;
+               bd++;
+       }

Looks like
memset(priv->txbd, 0, siezeof(*priv->txbd) * TX_BD_NUM);

Correct.

Quoted 12 lines
Quoted 11 lines
drivers/net/ethernet/arc/emac_main.c new file +8 -0
+       /* Get "info" of the next BD */
 
+       /* Get PHY from device tree */
+       phy_node = of_parse_phandle(pdev->dev.of_node, "phy", 0);
 
+       /* Get EMAC registers base address from device tree */
+       err = of_address_to_resource(pdev->dev.of_node, 0, &res_regs);
 
+       /* Get CPU clock frequency from device tree */
+       if (of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+                                &clock_frequency)) {
Quoted 5 lines

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

Quoted 2 lines
drivers/net/ethernet/arc/emac_main.c new file +2 -0
+       /* Get IRQ from device tree */
+       err = of_irq_to_resource(pdev->dev.of_node, 0, &res_irq);

So, you don't like the idea to get as much as possible before alloc_netdev(), don't you?

Ok, I did this change)))

Regards,
Alexey