ethernet/arc/arc_emac - Add new driver
Subsystems (3)
PATCH v5 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.
---
Hi all,
please take a look at 5th re-spin of the patch.
There's only 1 change compared to v4 enspired by Joe Perches' comment:
* Remove error messages on "netdev_alloc_skb_ip_align" failure as
redundant since alloc errors emit a dump_stack() already.
--- 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 | 828 ++++++++++++++++++++ drivers/net/ethernet/arc/emac_mdio.c | 151 ++++ 8 files changed, 1270 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 +828 -0
828 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
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.
This is based off of current Linus tree.
This line should go away from commit message.
Quoted 1 line
please take a look at 5th re-spin of the patch.
Few small things I commented below.
Quoted 12 lines
+++
b/drivers/net/ethernet/arc/emac_main.cdrivers/net/ethernet/arc/emac_main.c new file +9
-0@@ -0,0 +1,828 @@ +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;) { +unsigned int *last_rx_bd = &priv->last_rx_bd; +struct net_device_stats *stats = &priv->stats; +struct buffer_state *rx_buff = &priv->rx_buff[*last_rx_bd];
drivers/net/ethernet/arc/emac_main.c line 213
Quoted 10 lines
drivers/net/ethernet/arc/emac_main.c new file +9
-0+struct arc_emac_bd *rxbd = &priv->rxbd[*last_rx_bd]; +unsigned int buflen =EMAC_BUFFER_SIZE ; +unsigned int pktlen, info =__le32_to_cpu (rxbd->info); +struct sk_buff *skb; +dma_addr_t addr; + +if (unlikely ((info &OWN_MASK ) ==FOR_EMAC )) +break ; + work_done++;
Why it can't be inside for()?
drivers/net/ethernet/arc/emac_main.c line 230
Quoted 9 lines
drivers/net/ethernet/arc/emac_main.c new file +9
-0+if (unlikely ((info &FRST_OR_LAST_MASK ) !=FRST_OR_LAST_MASK )) { +/* Buffer chaining results in a significant +* amount of additional bus overhead and thus +* a higher CLK frequency or larger FIFOs are required. +* Because of that fact we don't support +* chaining of receive packets. We pre-allocate +* buffers of MTU size so incoming packets +* won't be chained. +*/
Could that comment take less LOC?
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* Return ownership to EMAC */ + rxbd->info = __cpu_to_le32(FOR_EMAC | buflen);
Here and in the whole file. Parhaps cpu_to_le32()?
drivers/net/ethernet/arc/emac_main.c line 283
Quoted 6 lines
drivers/net/ethernet/arc/emac_main.c new file +6
-0+/* Once EMAC sees he is an owner of this BD, EMAC will start to +* use it for receiving or transmitting packets, +* depending on BD: Tx or Rx. +* That's why we need to make sure "data" has proper address +* before writing "info" word with owner flag. +*/
Less LOC?
drivers/net/ethernet/arc/emac_main.c line 352
Quoted 6 lines
drivers/net/ethernet/arc/emac_main.c new file +6
-0+if (status &ERR_MASK ) { +/* MSER/RXCR/RXFR/RXFL interrupt fires on corresponding +* 8-bit error counter overrun. +* Because of this fact we add 256 (0x100) items each time +* overrun interrupt happens. +*/
Ditto.
drivers/net/ethernet/arc/emac_main.c line 550
Quoted 9 lines
drivers/net/ethernet/arc/emac_main.c new file +8
-0+static int arc_emac_tx (struct sk_buff *skb,struct net_device *ndev) +{ + len = max_t(unsigned int, ETH_ZLEN, skb->len); + +/* EMAC still holds this buffer in its possession. +* CPU must not modify this buffer descriptor +*/ +if (unlikely ((__le32_to_cpu (*info) &OWN_MASK ) ==FOR_EMAC )) {
Perhaps le32_to_cpu() here and in whole file?
drivers/net/ethernet/arc/emac_main.c line 712
Quoted 9 lines
drivers/net/ethernet/arc/emac_main.c new file +6
-0+static int arc_emac_probe (struct platform_device *pdev) +{ + err =of_address_to_resource (pdev->dev.of_node,0 , &res_regs); +if (of_property_read_u32 (pdev->dev.of_node,"clock-frequency" , + &clock_frequency)) { + err =of_irq_to_resource (pdev->dev.of_node,0 , &res_irq);
You may save few lines if you move those checks before allocation of the netdev.
drivers/net/ethernet/arc/emac_main.c line 769
Quoted 10 lines
drivers/net/ethernet/arc/emac_main.c new file +10
-0+ err =arc_mdio_probe (pdev->dev.of_node, priv); +if (err) { +dev_err (&pdev->dev,"failed to probe MII bus\n" ); + goto out; + } + + priv->phy_dev =of_phy_connect (ndev, phy_node, arc_emac_adjust_link,0 , +PHY_INTERFACE_MODE_MII ); +if (!priv->phy_dev) { +netdev_err (ndev,"of_phy_connect() failed\n" );
Can we be consistent and use here dev_err()?
drivers/net/ethernet/arc/emac_mdio.c line 36
Quoted 10 lines
+++
b/drivers/net/ethernet/arc/emac_mdio.cdrivers/net/ethernet/arc/emac_mdio.c new file +6
-0@@ -0,0 +1,151 @@ +static int arc_mdio_complete_wait (struct arc_emac_priv *priv) +{ +unsigned int i; + +for (i =0 ; i <ARC_MDIO_COMPLETE_POLL_COUNT *40 ; i++) { +msleep (25 );
So, in the worst case it takes ARC_MDIO_COMPLETE_POLL_COUNT seconds to wait. Quite a long time.
Does user expect such a delay?
drivers/net/ethernet/arc/emac_mdio.c line 126
Quoted 4 lines
drivers/net/ethernet/arc/emac_mdio.c new file +3
-0+int arc_mdio_probe (struct device_node *dev_node,struct arc_emac_priv *priv) +{ +snprintf (bus->id,MII_BUS_ID_SIZE ,"%.8x" , (unsigned int )priv->regs);
Is bus->id exposed to user-space somehow?
--
With Best Regards,
Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
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.
This is based off of current Linus tree.
This line should go away from commit message.
Ok, will do.
Quoted 18 lines
Quoted 17 lines
drivers/net/ethernet/arc/emac_main.c new file +17
-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;) { +unsigned int *last_rx_bd = &priv->last_rx_bd; +struct net_device_stats *stats = &priv->stats; +struct buffer_state *rx_buff = &priv->rx_buff[*last_rx_bd]; +struct arc_emac_bd *rxbd = &priv->rxbd[*last_rx_bd]; +unsigned int buflen =EMAC_BUFFER_SIZE ; +unsigned int pktlen, info =__le32_to_cpu (rxbd->info); +struct sk_buff *skb; +dma_addr_t addr; + +if (unlikely ((info &OWN_MASK ) ==FOR_EMAC )) +break ;
Quoted 3 lines
Quoted 1 line
+ work_done++;
Why it can't be inside
for()?
Indeed it can. Earlier there was "continue" instead of "break" that's why increment was done at this particular place. With "break" in place I'm moving incrementation in "for".
Quoted 10 lines
drivers/net/ethernet/arc/emac_main.c line 230
Quoted 9 lines
drivers/net/ethernet/arc/emac_main.c new file +9
-0+if (unlikely ((info &FRST_OR_LAST_MASK ) !=FRST_OR_LAST_MASK )) { +/* Buffer chaining results in a significant +* amount of additional bus overhead and thus +* a higher CLK frequency or larger FIFOs are required. +* Because of that fact we don't support +* chaining of receive packets. We pre-allocate +* buffers of MTU size so incoming packets +* won't be chained. +*/
Quoted 6 lines
Could that comment take less LOC?
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* Return ownership to EMAC */ + rxbd->info = __cpu_to_le32(FOR_EMAC | buflen);Here and in the whole file. Parhaps
cpu_to_le32()?
Indeed. Replaced both "__cpu_to_le32" and "__le32_to_cpu" with no "__" versions.
Quoted 8 lines
drivers/net/ethernet/arc/emac_main.c line 283
Quoted 6 lines
drivers/net/ethernet/arc/emac_main.c new file +6
-0+/* Once EMAC sees he is an owner of this BD, EMAC will start to +* use it for receiving or transmitting packets, +* depending on BD: Tx or Rx. +* That's why we need to make sure "data" has proper address +* before writing "info" word with owner flag. +*/ Less LOC?
Reduced.
Quoted 11 lines
drivers/net/ethernet/arc/emac_main.c line 712
Quoted 9 lines
drivers/net/ethernet/arc/emac_main.c new file +6
-0+static int arc_emac_probe (struct platform_device *pdev) +{ + err =of_address_to_resource (pdev->dev.of_node,0 , &res_regs); +if (of_property_read_u32 (pdev->dev.of_node,"clock-frequency" , + &clock_frequency)) { + err =of_irq_to_resource (pdev->dev.of_node,0 , &res_irq);You may save few lines if you move those checks before allocation of the netdev.
Correct, but having netdev is handy because I may have driver's private structure allocated as well and may set corresponding values right in the order I parse them from DT.
Moreover I need to have private structure pretty early in place just to read EMAC's ID from a register.
So I'd better leave netdev allocation on top of the probe.
Quoted 11 lines
drivers/net/ethernet/arc/emac_main.c line 769
Quoted 10 lines
drivers/net/ethernet/arc/emac_main.c new file +10
-0+ err =arc_mdio_probe (pdev->dev.of_node, priv); +if (err) { +dev_err (&pdev->dev,"failed to probe MII bus\n" ); + goto out; + } + + priv->phy_dev =of_phy_connect (ndev, phy_node, arc_emac_adjust_link,0 , +PHY_INTERFACE_MODE_MII ); +if (!priv->phy_dev) { +netdev_err (ndev,"of_phy_connect() failed\n" );
Quoted 1 line
Can we be consistent and use here
dev_err()?
Right. Replaced.
Quoted 9 lines
Quoted 8 lines
+++
b/drivers/net/ethernet/arc/emac_mdio.cdrivers/net/ethernet/arc/emac_mdio.c new file +5
-0@@ -0,0 +1,151 @@ +static int arc_mdio_complete_wait (struct arc_emac_priv *priv) +{ +unsigned int i; + +for (i =0 ; i <ARC_MDIO_COMPLETE_POLL_COUNT *40 ; i++) {
Quoted 5 lines
Quoted 1 line
+ msleep(25);
So, in the worst case it takes
ARC_MDIO_COMPLETE_POLL_COUNTseconds to wait. Quite a long time.
Does user expect such a delay?
Well, but it shouldn't be that long. It's just a check for illegal situation. If this transaction never ends then it doesn't matter if we wait for 1 second or 2 - after this time period "libphy" will "halt" MDIO anyways.
In general MDIO register gets polled by "libphy" once in a couple of seconds, so delay of 25 milliseconds IMHO is fine.
Quoted 6 lines
drivers/net/ethernet/arc/emac_mdio.c line 126
Quoted 4 lines
drivers/net/ethernet/arc/emac_mdio.c new file +3
-0+int arc_mdio_probe (struct device_node *dev_node,struct arc_emac_priv *priv) +{ +snprintf (bus->id,MII_BUS_ID_SIZE ,"%.8x" , (unsigned int )priv->regs);Is
bus->idexposed to user-space somehow?
Well as a boot-up message from "libphy":
====
libphy: Synopsys MII Bus: probed
====
Regards,
Alexey
2013/6/20 Alexey Brodkin <[email protected]>:
[snip]
Quoted 7 lines
In general MDIO register gets polled by "libphy" once in a couple of seconds, so delay of 25 milliseconds IMHO is fine.
Quoted 3 lines
Quoted 2 lines
(quoted diff) +2
-0+int arc_mdio_probe(struct device_node *dev_node, struct arc_emac_priv *priv) +{
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+
snprintf(bus->id, MII_BUS_ID_SIZE, "%.8x", (unsigned int)priv->regs);Is
bus->idexposed to user-space somehow?Well as a boot-up message from "libphy":
====
libphy: Synopsys MII Bus: probed
====
Well not only as a boot-up message, this serves as unique identifer in the entire system for your MDIO bus. It is crucial that you have an unique MDIO bus identifier for at least the two following reasons:
- the corresponding kobject/sysfs node that is going to be created also needs to be unique in the system
- you may have multiple MDIO bus in the system (e.g: the one for your specific driver and the fixed MDIO bus)
Since you are using Device Tree already, you may just turn this into:
snprintf(bus->id, MII_BUS_ID_SIZE, "%s", pdev->name);
assuming that your node is already properly labelleled (e.g:
mdio@deadbeef) which would be exactly equivalent to what you are doing with priv->regs;
--
Florian
Quoted 19 lines · Florian Fainelli
2013/6/20 Alexey Brodkin <[email protected]>:
[snip]Quoted 7 lines
In general MDIO register gets polled by "libphy" once in a couple of seconds, so delay of 25 milliseconds IMHO is fine.
Quoted 3 lines
Quoted 2 lines
(quoted diff) +2
-0+int arc_mdio_probe(struct device_node *dev_node, struct arc_emac_priv *priv) +{Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+
snprintf(bus->id, MII_BUS_ID_SIZE, "%.8x", (unsigned int)priv->regs);Is
bus->idexposed to user-space somehow?Well as a boot-up message from "libphy":
====
libphy: Synopsys MII Bus: probed
====
Quoted 8 lines
Well not only as a boot-up message, this serves as unique identifer in the entire system for your MDIO bus. It is crucial that you have an unique MDIO bus identifier for at least the two following reasons:
- the corresponding kobject/sysfs node that is going to be created also needs to be unique in the system
- you may have multiple MDIO bus in the system (e.g: the one for your specific driver and the fixed MDIO bus)
Good explanation. I didn't realize it yet. And it seems like I talked about bus "name", not "id".
Quoted 7 lines
Since you are using Device Tree already, you may just turn this into:
snprintf(bus->id, MII_BUS_ID_SIZE, "%s", pdev->name);assuming that your node is already properly labelleled (e.g:
mdio@deadbeef) which would be exactly equivalent to what you are doing withpriv->regs;
The thing is I don't have separate "mdio" device description in DT. Regs value is read from "ethernet" device description.
Here's my DT entry for entire emac:
=============
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>;
};
};=============
So with your proposal bus id will be just "ethernet" which is not that unique, right?
That's why address of registers IMHO fits better to a bus id.
-Alexey
2013/6/20 Alexey Brodkin <Alexey.Brodkin-HKixBCOQz3hWk0Htik3J/[email protected]>:
Quoted 60 lines · Florian Fainelli
Quoted 19 lines
2013/6/20 Alexey Brodkin <Alexey.Brodkin-HKixBCOQz3hWk0Htik3J/[email protected]>:
[snip]Quoted 7 lines
In general MDIO register gets polled by "libphy" once in a couple of seconds, so delay of 25 milliseconds IMHO is fine.
Quoted 3 lines
Quoted 2 lines
(quoted diff) +2
-0+int arc_mdio_probe(struct device_node *dev_node, struct arc_emac_priv *priv) +{Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+
snprintf(bus->id, MII_BUS_ID_SIZE, "%.8x", (unsigned int)priv->regs);Is
bus->idexposed to user-space somehow?Well as a boot-up message from "libphy":
====
libphy: Synopsys MII Bus: probed
====Quoted 8 lines
Well not only as a boot-up message, this serves as unique identifer in the entire system for your MDIO bus. It is crucial that you have an unique MDIO bus identifier for at least the two following reasons:
- the corresponding kobject/sysfs node that is going to be created also needs to be unique in the system
- you may have multiple MDIO bus in the system (e.g: the one for your specific driver and the fixed MDIO bus)Good explanation. I didn't realize it yet. And it seems like I talked about bus "name", not "id".
Quoted 7 lines
Since you are using Device Tree already, you may just turn this into:
snprintf(bus->id, MII_BUS_ID_SIZE, "%s", pdev->name);assuming that your node is already properly labelleled (e.g:
mdio@deadbeef) which would be exactly equivalent to what you are doing withpriv->regs;The thing is I don't have separate "mdio" device description in DT. Regs value is read from "ethernet" device description.
Here's my DT entry for entire emac:
=============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>; }; };
Quoted 4 lines
=============
So with your proposal bus id will be just "ethernet" which is not that unique, right?
No, it would be c0fc2000, which is, so we are just fine. Drivers that support DT instantiation or platform_device/driver should in general use <pdev->name>-<pdev->id> which works fine in both cases. --
Florian
Quoted 3 lines · Florian Fainelli
2013/6/20 Alexey Brodkin <[email protected]>:
Quoted 2 lines · Florian Fainelli
Quoted 1 line
2013/6/20 Alexey Brodkin <[email protected]>:
[]
Quoted 3 lines
No, it would be
c0fc2000, which is, so we are just fine. Drivers that support DT instantiation or platform_device/driver should in general use <pdev->name>-<pdev->id> which works fine in both cases.
Ok, I see now.
"pdev->name" indeed leads to "bus->id" = "c0fc2000.etherne". Initially I thought about "pdev->dev.of_node->name" because I passed "pdev->dev.of_node" to "arc_mdio_probe".
Thanks for clarification.
-Alexey