ethernet/arc/arc_emac - Add new driver
Subsystems (3)
PATCH v7 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.
---
Hi all,
please take a look at 7th re-spin of the patch.
Here I addressed another set of comments from Andy Shevchenko.
1. Re-use FIRST_OR_LAST_MASK more extensively.
2. Use write-specific barrier "wmb()" instead of generic "mb()".
3. Do netdev allocation as late as possible.
--- 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 | 806 ++++++++++++++++++++ drivers/net/ethernet/arc/emac_mdio.c | 152 ++++ 8 files changed, 1249 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +806 -0
806 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
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.
Looks fine to me.
One nit you could fix later and a question.
drivers/net/ethernet/arc/emac_main.c
Quoted 1 line
drivers/net/ethernet/arc/emac_main.c +0
-0
[]
drivers/net/ethernet/arc/emac_main.c line 198
Quoted 2 lines
drivers/net/ethernet/arc/emac_main.c +2
-0+static int arc_emac_rx (struct net_device *ndev,int budget) +{
[]
drivers/net/ethernet/arc/emac_main.c line 226
Quoted 2 lines
drivers/net/ethernet/arc/emac_main.c +2
-0+if (net_ratelimit ()) +netdev_err (ndev,"incomplete packed received\n" );
s/packed/packet/
drivers/net/ethernet/arc/emac_main.c line 270
Quoted 1 line
drivers/net/ethernet/arc/emac_main.c +1
-0+ rxbd->data = (unsigned char *)cpu_to_le32 (rx_buff->skb->data);
32 bit only. Should the Kconfig block have some arch_arc dependency so it can't get compiled for 64 bit systems?
Quoted 11 lines · Joe Perches
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.
Looks fine to me.
One nit you could fix later and a question.
drivers/net/ethernet/arc/emac_main.c
Quoted 1 line
drivers/net/ethernet/arc/emac_main.c +0
-0[]
Quoted 7 lines
drivers/net/ethernet/arc/emac_main.c line 198
Quoted 2 lines
drivers/net/ethernet/arc/emac_main.c +2
-0+static int arc_emac_rx (struct net_device *ndev,int budget) +{[]
drivers/net/ethernet/arc/emac_main.c line 226
Quoted 2 lines
drivers/net/ethernet/arc/emac_main.c +2
-0+if (net_ratelimit ()) +netdev_err (ndev,"incomplete packed received\n" );s/packed/packet/
Ooops. Thanks for noticing this subtle misspelling.
Quoted 4 lines
drivers/net/ethernet/arc/emac_main.c line 270
Quoted 1 line
drivers/net/ethernet/arc/emac_main.c +1
-0+ rxbd->data = (unsigned char *)cpu_to_le32 (rx_buff->skb->data);32 bit only. Should the
Kconfigblock have somearch_arcdependency so it can't get compiled for 64 bit systems?
Well, initially I add dependency on ARC in Kconfig.
But later removed it because in driver itself there're really no ARC-specific things. So why don't make it available for any other arch? For example I re-used Xilinx SystemACE driver on ARC even though it was only targeted for PPC/Microblaze. And now I need to add another dependency (+ || ARC) in Kconfig for all block devices.
But your comment regarding 64-bit arches makes perfect sense. But still I don't know if there's a way to restrict usage on only 32-bit arches (independent of being x86/arc/mips/etc). I may suppose that only strict specification of all virtually supported 32-bit arches - which is nonsense I think.
Also independence of architecture makes it possible to compile driver on x86 for x86 with native toolchain. In other words anybody may try to compile it. And I thought it's if not mandatory but at least very welcome - if maintainer or reviewer may compile stuff and teach me how to eliminate all compile-time warnings/errors.
But during compilation on x86 one needs to enable OF. Which will lead to compilation errors in other things.
So for now I may easily add dependency on ARC if it makes acceptance of driver easier.
-Alexey
On Fri, Jun 21, 2013 at 1:53 PM, Alexey Brodkin
<[email protected]> wrote:
[]
Quoted 2 lines
But during compilation on x86 one needs to enable OF. Which will lead to compilation errors in other things.
JFYI, x86 has at least one platform with official OF dependency. Once I actually tried to build kernel for Intel MID with OF enabled (it required a hack in the arch Kconfig, of course), compiled fine.
--
With Best Regards,
Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
On Fri, Jun 21, 2013 at 1:53 PM, Alexey Brodkin
<[email protected]> wrote:[]
Quoted 2 lines
But during compilation on x86 one needs to enable OF. Which will lead to compilation errors in other things.
JFYI, x86 has at least one platform with official OF dependency. Once I actually tried to build kernel for Intel MID with OF enabled (it required a hack in the arch
Kconfig, of course), compiled fine.
Ok, good to know it.
Any other comments on patch itself?
-Alexey
Quoted 1 line · Alexey Brodkin
Any other comments on patch itself?
Looks fine to me.
--
With Best Regards,
Andy Shevchenko
Quoted 5 lines · Alexey Brodkin
Quoted 4 lines · Joe Perches
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.
[]
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/arc/emac_main.c line 270
Quoted 1 line
drivers/net/ethernet/arc/emac_main.c new file +1
-0+ rxbd->data = (unsigned char *)cpu_to_le32 (rx_buff->skb->data);32 bit only. Should the
Kconfigblock have somearch_arcdependency so it can't get compiled for 64 bit systems?
[]
Quoted 2 lines
So for now I may easily add dependency on ARC if it makes acceptance of driver easier.
I don't think it's a big problem.
Maybe add a Kconfig "depends on !64BIT".
Another thing to do would be to run it through sparse with make C=1
Quoted 15 lines · Joe Perches
Quoted 5 lines · Alexey Brodkin
Quoted 4 lines · Joe Perches
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.
[]
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
rxbd->data= (unsigned char *)cpu_to_le32(rx_buff->skb->data);32 bit only. Should the
Kconfigblock have somearch_arcdependency so it can't get compiled for 64 bit systems?[]
Quoted 2 lines
So for now I may easily add dependency on ARC if it makes acceptance of driver easier.
Quoted 6 lines
I don't think it's a big problem.
Maybe add a
Kconfig"depends on !64BIT".Another thing to do would be to run it through sparse with make C=1
No, I think the driver should just be made 64-bit clean. Not because anyone is going to need that of course, but to avoid having to add silly dependencies.
The problem is that rxbd->data is the wrong type. It is declared as a void*, but it is not a kernel pointer at all, it is a DMA pointer. Look at this code in context:
+ addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data,
+ buflen, DMA_FROM_DEVICE);
+ if (dma_mapping_error(&ndev->dev, addr)) {
+ if (net_ratelimit())
+ netdev_err(ndev, "cannot dma map\n");
+ dev_kfree_skb(rx_buff->skb); + stats->rx_errors++; + continue; + } + dma_unmap_addr_set(&rx_buff, mapping, addr); + dma_unmap_len_set(&rx_buff, len, buflen);
+
+ rxbd->data = (unsigned char *)cpu_to_le32(rx_buff->skb->data);
the 'addr' returned by dma_map_single is what the device really needs, although it is the same as rx_buff->skb->data with the trivial definition of dma_map_single.
The last line here needs to be
rxbd->data = cpu_to_le32(addr);
which fixes the bug, and has no dependency on a 32 bit CPU.
Arnd
Quoted 23 lines · Arnd Bergmann
Quoted 15 lines · Joe Perches
Quoted 5 lines · Alexey Brodkin
Quoted 4 lines · Joe Perches
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.
[]
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
rxbd->data= (unsigned char *)cpu_to_le32(rx_buff->skb->data);32 bit only. Should the
Kconfigblock have somearch_arcdependency so it can't get compiled for 64 bit systems?[]
Quoted 2 lines
So for now I may easily add dependency on ARC if it makes acceptance of driver easier.
Quoted 6 lines
I don't think it's a big problem.
Maybe add a
Kconfig"depends on !64BIT".Another thing to do would be to run it through sparse with make C=1
Quoted 7 lines
No, I think the driver should just be made 64-bit clean. Not because anyone is going to need that of course, but to avoid having to add silly dependencies.
The problem is that
rxbd->datais the wrong type. It is declared as a void*, but it is not a kernel pointer at all, it is a DMA pointer. Look at this code in context:
So it should be declared dma_addr_t then,
Quoted 14 lines
drivers/net/ethernet/arc/emac_main.c new file +13
-0+ addr =dma_map_single (&ndev->dev, (void *)rx_buff->skb->data, + buflen,DMA_FROM_DEVICE ); +if (dma_mapping_error (&ndev->dev, addr)) { +if (net_ratelimit ()) +netdev_err (ndev,"cannot dma map\n" ); +dev_kfree_skb (rx_buff->skb); + stats->rx_errors++; +continue ; + } +dma_unmap_addr_set (&rx_buff, mapping, addr); +dma_unmap_len_set (&rx_buff, len, buflen); + + rxbd->data = (unsigned char *)cpu_to_le32 (rx_buff->skb->data);
Quoted 8 lines
the 'addr' returned by
dma_map_singleis what the device really needs, although it is the same asrx_buff->skb->datawith the trivial definition ofdma_map_single.The last line here needs to be
rxbd->data = cpu_to_le32(addr);which fixes the bug, and has no dependency on a 32 bit CPU.
It still has a dependency on dma_addr_t size being 32 bit
Quoted 20 lines
So it should be declared
dma_addr_tthen,Quoted 18 lines
drivers/net/ethernet/arc/emac_main.c new file +13
-0+ addr =dma_map_single (&ndev->dev, (void *)rx_buff->skb->data, + buflen,DMA_FROM_DEVICE ); +if (dma_mapping_error (&ndev->dev, addr)) { +if (net_ratelimit ()) +netdev_err (ndev,"cannot dma map\n" ); +dev_kfree_skb (rx_buff->skb); + stats->rx_errors++; +continue ; + } +dma_unmap_addr_set (&rx_buff, mapping, addr); +dma_unmap_len_set (&rx_buff, len, buflen); + + rxbd->data = (unsigned char *)cpu_to_le32 (rx_buff->skb->data);the 'addr' returned by
dma_map_singleis what the device really needs, although it is the same asrx_buff->skb->datawith the trivial definition ofdma_map_single.
Quoted 6 lines
Quoted 4 lines
The last line here needs to be
rxbd->data = cpu_to_le32(addr);which fixes the bug, and has no dependency on a 32 bit CPU.
It still has a dependency on
dma_addr_tsize being 32 bit
No - just a dependency on memory being mapped to a 32bit physical address accessible from the device.
Many 64 bit systems have devices that can only access 32bit address space, either the memory has to be allocated from the correct arena, of DMA bounce buffers are used.
David
David Miller
maintainerFrom: Joe Perches <[email protected]>
Date: Fri, 21 Jun 2013 07:43:33 -0700
Quoted 1 line
Maybe add a
Kconfig"depends on !64BIT".
Please, no.