Add support for Actions Semi Owl Ethernet MAC
PATCH 1/3 dt-bindings: net: Add Actions Semi Owl Ethernet MAC binding
In reply to Cristian CiocalteaAdd devicetree binding for the Ethernet MAC present on the Actions Semi Owl family of SoCs.
For the moment enable only the support for the Actions Semi S500 SoC variant.
--- .../bindings/net/actions,owl-emac.yaml | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/actions,owl-emac.yaml
Documentation/devicetree/bindings/net/actions,owl-emac.yaml new file +91 -0
@@ -0,0 +1,91 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/actions,owl-emac.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Actions Semi Owl SoCs Ethernet MAC Controller + +maintainers: + - Cristian Ciocaltea <[email protected]> + +description: | + This Ethernet MAC is used on the Owl family of SoCs from Actions Semi. + It is compliant with the IEEE 802.3 CSMA/CD standard and supports both + half-duplex and full-duplex operation modes at 10/100 Mb/s. + +allOf: + - $ref: "ethernet-controller.yaml#" + +properties: + compatible: + oneOf: + - const: actions,owl-emac + - items: + - enum: + - actions,s500-emac + - const: actions,owl-emac + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + minItems: 2 + maxItems: 2 + + clock-names: + additionalItems: false + items: + - const: eth + - const: rmii + + resets: + maxItems: 1 + + actions,ethcfg: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle to the device containing custom config. + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - resets + - phy-mode + - phy-handle + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/actions,s500-cmu.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/reset/actions,s500-reset.h> + + ethernet@b0310000 { + compatible = "actions,s500-emac", "actions,owl-emac"; + reg = <0xb0310000 0x10000>; + interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cmu 59 /*CLK_ETHERNET*/>, <&cmu CLK_RMII_REF>; + clock-names = "eth", "rmii"; + resets = <&cmu RESET_ETHERNET>; + phy-handle = <ð_phy>; + phy-mode = "rmii"; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + eth_phy: ethernet-phy@3 { + reg = <0x3>; + interrupt-parent = <&sirq>; + interrupts = <0 IRQ_TYPE_LEVEL_LOW>; + }; + }; + };
Signature · 1 line
2.30.2
cover Add support for Actions Semi Owl Ethernet MAC
This patch series adds support for the Ethernet MAC found on the Actions Semi Owl family of SoCs.
For the moment I have only tested the driver on RoseapplePi SBC, which is based on the S500 SoC variant. It might work on S900 as well, but I cannot tell for sure since the S900 datasheet I currently have doesn't provide any information regarding the MAC registers - so I couldn't check the compatibility with S500.
Similar story for S700: the datasheet I own is incomplete, but it seems the MAC is advertised with Gigabit capabilities. For that reason most probably we need to extend the current implementation in order to support this SoC variant as well.
Please note that for testing the driver it is also necessary to update the S500 clock subsystem:
https://lore.kernel.org/lkml/[email protected]/
The DTS changes for the S500 SBCs will be provided separately.
Thanks,
Cristi
Cristian Ciocaltea (3):
dt-bindings: net: Add Actions Semi Owl Ethernet MAC binding
net: ethernet: actions: Add Actions Semi Owl Ethernet MAC driver
MAINTAINERS: Add entries for Actions Semi Owl Ethernet MAC
.../bindings/net/actions,owl-emac.yaml | 91 + MAINTAINERS | 2 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/actions/Kconfig | 39 + drivers/net/ethernet/actions/Makefile | 6 + drivers/net/ethernet/actions/owl-emac.c | 1660 +++++++++++++++++ drivers/net/ethernet/actions/owl-emac.h | 278 +++ 8 files changed, 2078 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/actions,owl-emac.yaml create mode 100644 drivers/net/ethernet/actions/Kconfig create mode 100644 drivers/net/ethernet/actions/Makefile create mode 100644 drivers/net/ethernet/actions/owl-emac.c create mode 100644 drivers/net/ethernet/actions/owl-emac.h
Signature · 1 line
2.30.2
PATCH 2/3 net: ethernet: actions: Add Actions Semi Owl Ethernet MAC driver
Add new driver for the Ethernet MAC used on the Actions Semi Owl family of SoCs.
Currently this has been tested only on the Actions Semi S500 SoC variant.
--- drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/actions/Kconfig | 39 + drivers/net/ethernet/actions/Makefile | 6 + drivers/net/ethernet/actions/owl-emac.c | 1660 +++++++++++++++++++++++ drivers/net/ethernet/actions/owl-emac.h | 278 ++++ 6 files changed, 1985 insertions(+) create mode 100644 drivers/net/ethernet/actions/Kconfig create mode 100644 drivers/net/ethernet/actions/Makefile create mode 100644 drivers/net/ethernet/actions/owl-emac.c create mode 100644 drivers/net/ethernet/actions/owl-emac.h
drivers/net/ethernet/Kconfig +1 -0
@@ -19,6 +19,7 @@ config SUNGEM_PHY tristate source "drivers/net/ethernet/3com/Kconfig" +source "drivers/net/ethernet/actions/Kconfig" source "drivers/net/ethernet/adaptec/Kconfig" source "drivers/net/ethernet/aeroflex/Kconfig" source "drivers/net/ethernet/agere/Kconfig"
drivers/net/ethernet/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_NET_VENDOR_3COM) += 3com/ obj-$(CONFIG_NET_VENDOR_8390) += 8390/ +obj-$(CONFIG_NET_VENDOR_ACTIONS) += actions/ obj-$(CONFIG_NET_VENDOR_ADAPTEC) += adaptec/ obj-$(CONFIG_GRETH) += aeroflex/ obj-$(CONFIG_NET_VENDOR_AGERE) += agere/
drivers/net/ethernet/actions/Kconfig new file +39 -0
@@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config NET_VENDOR_ACTIONS + bool "Actions Semi devices" + default y + depends on ARCH_ACTIONS + help + If you have a network (Ethernet) card 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 the + questions about Actions Semi devices. If you say Y, you will be + asked for your specific card in the following questions. + +if NET_VENDOR_ACTIONS + +config OWL_EMAC + tristate "Actions Semi Owl Ethernet MAC support" + select PHYLIB + help + This driver supports the Actions Semi Ethernet Media Access + Controller (EMAC) found on the S500 and S900 SoCs. The controller + is compliant with the IEEE 802.3 CSMA/CD standard and supports + both half-duplex and full-duplex operation modes at 10/100 Mb/s. + +config OWL_EMAC_GEN_ADDR_SYS_SN + bool "Enable generating MAC address based on system serial" + depends on OWL_EMAC + select CRYPTO + select CRYPTO_DES + select CRYPTO_ECB + select CRYPTO_SKCIPHER + default n + help + If you say Y here and no MAC address is available, the Actions Semi + Owl EMAC driver will generate the address based on the system serial + number. The fallback is to use a randomly generated MAC address. + +endif # NET_VENDOR_ACTIONS
drivers/net/ethernet/actions/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the Actions Semi Owl SoCs built-in ethernet macs +# + +obj-$(CONFIG_OWL_EMAC) += owl-emac.o
drivers/net/ethernet/actions/owl-emac.c new file +1660 -0
1,660 lines not on this page · raw message
drivers/net/ethernet/actions/owl-emac.h new file +278 -0
278 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH 3/3 MAINTAINERS: Add entries for Actions Semi Owl Ethernet MAC
In reply to Cristian CiocalteaAdd entries for Actions Semi Owl Ethernet MAC binding and driver.
--- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
@@ -1530,6 +1530,7 @@ F: Documentation/devicetree/bindings/dma/owl-dma.yaml F: Documentation/devicetree/bindings/i2c/i2c-owl.yaml F: Documentation/devicetree/bindings/interrupt-controller/actions,owl-sirq.yaml F: Documentation/devicetree/bindings/mmc/owl-mmc.yaml +F: Documentation/devicetree/bindings/net/actions,owl-emac.yaml F: Documentation/devicetree/bindings/pinctrl/actions,* F: Documentation/devicetree/bindings/power/actions,owl-sps.txt F: Documentation/devicetree/bindings/timer/actions,owl-timer.txt
@@ -1542,6 +1543,7 @@ F: drivers/dma/owl-dma.c F: drivers/i2c/busses/i2c-owl.c F: drivers/irqchip/irq-owl-sirq.c F: drivers/mmc/host/owl-mmc.c +F: drivers/net/ethernet/actions/ F: drivers/pinctrl/actions/* F: drivers/soc/actions/ F: include/dt-bindings/power/owl-*
Signature · 1 line
2.30.2
Re: [PATCH 2/3] net: ethernet: actions: Add Actions Semi Owl Ethernet MAC driver
In reply to Cristian CiocalteaHi Cristian,
Quoted 8 lines · Cristian Ciocaltea
Add new driver for the Ethernet MAC used on the Actions Semi Owl family of SoCs.
Currently this has been tested only on the Actions Semi S500 SoC variant.
Signed-off-by Cristian Ciocaltea <[email protected]>---
[...]
Quoted 6 lines
drivers/net/ethernet/actions/owl-emac.c new file +0
-0@@ -0,0 +1,1660 @@
[...]
Quoted 2 lines
drivers/net/ethernet/actions/owl-emac.c new file +2
-0+static int owl_emac_probe (struct platform_device *pdev) +{
[...]
drivers/net/ethernet/actions/owl-emac.c line 1583
Quoted 1 line
drivers/net/ethernet/actions/owl-emac.c new file +1
-0+ priv->reset =devm_reset_control_get (dev,NULL );
Please use
priv->reset = devm_reset_control_get_exclusive(dev, NULL);
instead, to explicitly state that the driver requires exclusive control over the reset line.
drivers/net/ethernet/actions/owl-emac.c line 1587
Quoted 4 lines
drivers/net/ethernet/actions/owl-emac.c new file +4
-0+if (IS_ERR (priv->reset)) { + ret =PTR_ERR (priv->reset); +dev_err (dev,"failed to get reset control: %d\n" , ret); +return ret;
You could use:
return dev_err_probe(dev, PTR_ERR(priv->reset), "failed to get reset control");
regards
Philipp
Re: [PATCH 2/3] net: ethernet: actions: Add Actions Semi Owl Ethernet MAC driver
Hi Philipp,
Thanks for your quick review!
I will incorporate the indicated changes in the next patch revision.
Kind regards,
Cristi
Quoted 43 lines · Philipp Zabel
Hi Cristian,
Quoted 8 lines · Cristian Ciocaltea
Add new driver for the Ethernet MAC used on the Actions Semi Owl family of SoCs.
Currently this has been tested only on the Actions Semi S500 SoC variant.
Signed-off-by Cristian Ciocaltea <[email protected]>---
[...]
Quoted 6 lines
drivers/net/ethernet/actions/owl-emac.c new file +0
-0@@ -0,0 +1,1660 @@[...]
Quoted 2 lines
drivers/net/ethernet/actions/owl-emac.c new file +2
-0+static int owl_emac_probe (struct platform_device *pdev) +{[...]
drivers/net/ethernet/actions/owl-emac.c line 1583
Quoted 1 line
drivers/net/ethernet/actions/owl-emac.c new file +1
-0+ priv->reset =devm_reset_control_get (dev,NULL );Please use
priv->reset = devm_reset_control_get_exclusive(dev, NULL);instead, to explicitly state that the driver requires exclusive control over the reset line.
drivers/net/ethernet/actions/owl-emac.c line 1587
Quoted 4 lines
drivers/net/ethernet/actions/owl-emac.c new file +4
-0+if (IS_ERR (priv->reset)) { + ret =PTR_ERR (priv->reset); +dev_err (dev,"failed to get reset control: %d\n" , ret); +return ret;You could use:
return dev_err_probe(dev, PTR_ERR(priv->reset), "failed to get reset control");regards
Philipp
Re: [PATCH 2/3] net: ethernet: actions: Add Actions Semi Owl Ethernet MAC driver
In reply to Cristian Ciocalteadrivers/net/ethernet/actions/owl-emac.c line 58
Quoted 5 lines · Cristian Ciocaltea
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+static inline void owl_emac_reg_set (struct owl_emac_priv *priv, +u32 reg,u32 bits) +{ +owl_emac_reg_update (priv, reg, bits, bits); +}
Hi Cristian
No inline functions in C files please. Let the compiler decide. Please fix them all.
drivers/net/ethernet/actions/owl-emac.c line 169
Quoted 4 lines
drivers/net/ethernet/actions/owl-emac.c new file +4
-0+static struct sk_buff *owl_emac_alloc_skb (struct net_device *netdev) +{ +int offset; +struct sk_buff *skb;
Reverse Christmas tree please.
Quoted 5 lines
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+ + skb =netdev_alloc_skb (netdev,OWL_EMAC_RX_FRAME_MAX_LEN + +OWL_EMAC_SKB_RESERVE ); +if (unlikely (!skb)) +return NULL ;
drivers/net/ethernet/actions/owl-emac.c
Quoted 10 lines
drivers/net/ethernet/actions/owl-emac.c new file +10
-0+ +/* Ensure 4 bytes DMA alignment. */ + offset = ((uintptr_t )skb->data) & (OWL_EMAC_SKB_ALIGN -1 ); +if (unlikely (offset)) +skb_reserve (skb,OWL_EMAC_SKB_ALIGN - offset); + +return skb; +} + +static void owl_emac_phy_config (struct owl_emac_priv *priv)
You are not really configuring the PHY here, but configuring the MAC with what the PHY tells you has been negotiated. So maybe change this name?
Quoted 30 lines
drivers/net/ethernet/actions/owl-emac.c new file +30
-0+{ +u32 val, status; + +if (priv->pause) { + val =OWL_EMAC_BIT_MAC_CSR20_FCE |OWL_EMAC_BIT_MAC_CSR20_TUE ; + val |=OWL_EMAC_BIT_MAC_CSR20_TPE |OWL_EMAC_BIT_MAC_CSR20_RPE ; + val |=OWL_EMAC_BIT_MAC_CSR20_BPE ; + }else { + val =0 ; + } + +/* Update flow control. */ +owl_emac_reg_write (priv,OWL_EMAC_REG_MAC_CSR20 , val); + + val = (priv->speed ==SPEED_100 ) ?OWL_EMAC_VAL_MAC_CSR6_SPEED_100M : +OWL_EMAC_VAL_MAC_CSR6_SPEED_10M ; + val <<=OWL_EMAC_OFF_MAC_CSR6_SPEED ; + +if (priv->duplex ==DUPLEX_FULL ) + val |=OWL_EMAC_BIT_MAC_CSR6_FD ; + +spin_lock_bh (&priv->lock); + +/* Temporarily stop DMA TX & RX. */ + status =owl_emac_dma_cmd_stop (priv); + +/* Update operation modes. */ +owl_emac_reg_update (priv,OWL_EMAC_REG_MAC_CSR6 , +OWL_EMAC_MSK_MAC_CSR6_SPEED | +OWL_EMAC_BIT_MAC_CSR6_FD , val);
drivers/net/ethernet/actions/owl-emac.c line 456
Quoted 10 lines
drivers/net/ethernet/actions/owl-emac.c new file +9
-0+ +/* Restore DMA TX & RX status. */ +owl_emac_dma_cmd_set (priv, status); + +spin_unlock_bh (&priv->lock); +} +static inline void owl_emac_ether_addr_push (u8 **dst,const u8 *src) +{ +u32 *a = (u32 *)(*dst);
Is *dst guaranteed to by 32bit aligned? Given that it is skb->data, i don't think it is.
drivers/net/ethernet/actions/owl-emac.c line 461
Quoted 5 lines
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+const u16 *b = (const u16 *)src; + + a[0 ] = b[0 ]; + a[1 ] = b[1 ]; + a[2 ] = b[2 ];
So i don't know if this is safe. Some architectures don't like doing miss aligned read/writes. You probably should be using one of the put_unaligned_() macros.
Quoted 16 lines
drivers/net/ethernet/actions/owl-emac.c new file +16
-0+ + *dst +=12 ; +} + +static void +owl_emac_setup_frame_prepare (struct owl_emac_priv *priv,struct sk_buff *skb) +{ +const u8 bcast_addr[] = {0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF }; +const u8 *mac_addr = priv->netdev->dev_addr; +u8 *frame; +int i; + +skb_put (skb,OWL_EMAC_SETUP_FRAME_LEN ); + + frame = skb->data; +memset (frame,0 , skb->len);
drivers/net/ethernet/actions/owl-emac.c line 487
Quoted 10 lines
drivers/net/ethernet/actions/owl-emac.c new file +10
-0+ +owl_emac_ether_addr_push (&frame, mac_addr); +owl_emac_ether_addr_push (&frame, bcast_addr); + +/* Fill multicast addresses. */ +WARN_ON (priv->mcaddr_list.count >=OWL_EMAC_MAX_MULTICAST_ADDRS ); +for (i =0 ; i < priv->mcaddr_list.count; i++) { + mac_addr = priv->mcaddr_list.addrs[i]; +owl_emac_ether_addr_push (&frame, mac_addr); + }
Please could you add some comments to this. You are building a rather odd frame here! What is it used form?
drivers/net/ethernet/actions/owl-emac.c line 871
Quoted 8 lines
drivers/net/ethernet/actions/owl-emac.c new file +8
-0+} +static int owl_emac_poll (struct napi_struct *napi,int budget) +{ +struct owl_emac_priv *priv; +u32 status, proc_status; +int work_done =0 , recv; +static int tx_err_cnt, rx_err_cnt; +int ru_cnt =0 ;
More reverse Christmas tree.
drivers/net/ethernet/actions/owl-emac.c line 945
Quoted 5 lines
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+static void owl_emac_mdio_clock_enable (struct owl_emac_priv *priv) +{ +u32 val; + +/* Enable MDC clock generation by setting CLKDIV to at least 128. */
You should be aiming for 2.5MHz bus clock. Does this depend on the speed of one of the two clocks you have? Maybe you can dynamically calculate the divider?
Quoted 17 lines
(quoted diff) +16
-0+ val = owl_emac_reg_read(priv, OWL_EMAC_REG_MAC_CSR10); + val &= OWL_EMAC_MSK_MAC_CSR10_CLKDIV; + val |= OWL_EMAC_VAL_MAC_CSR10_CLKDIV_128 << OWL_EMAC_OFF_MAC_CSR10_CLKDIV; + + val |= OWL_EMAC_BIT_MAC_CSR10_SB; + val |= OWL_EMAC_VAL_MAC_CSR10_OPCODE_CDS << OWL_EMAC_OFF_MAC_CSR10_OPCODE; + owl_emac_reg_write(priv, OWL_EMAC_REG_MAC_CSR10, val); +} +static int owl_emac_phy_init(struct net_device *netdev) +{ + struct owl_emac_priv *priv = netdev_priv(netdev); + struct device *dev = owl_emac_get_dev(priv); + struct phy_device *phy; + + phy = of_phy_get_and_connect(netdev, dev->of_node, + owl_emac_adjust_link);
Review
Quoted 10 lines
(quoted diff) +10
-0+ if (!phy) + return -ENODEV; + + if (phy->interface != PHY_INTERFACE_MODE_RMII) { + netdev_err(netdev, "unsupported phy mode: %s\n", + phy_modes(phy->interface)); + phy_disconnect(phy); + netdev->phydev = NULL; + return -EINVAL; + }
It looks like the MAC only supports symmetric pause. So you should call phy_set_sym_pause() to let the PHY know this.
Quoted 45 lines
drivers/net/ethernet/actions/owl-emac.c new file +45
-0+ +if (netif_msg_link (priv)) +phy_attached_info (phy); + +return 0 ; +} + +/* Generate the MAC address based on the system serial number. +*/ +static int owl_emac_generate_mac_addr (struct net_device *netdev) +{ +int ret = -ENXIO ; + +#ifdef CONFIG_OWL_EMAC_GEN_ADDR_SYS_SN +struct device *dev = netdev->dev.parent; +struct crypto_sync_skcipher *tfm; +struct scatterlist sg; +const u8 key[] = {1 ,4 ,13 ,21 ,59 ,67 ,69 ,127 }; +u64 sn; +u8 enc_sn[sizeof (key)]; + +SYNC_SKCIPHER_REQUEST_ON_STACK (req, tfm); + + sn = ((u64 )system_serial_high <<32 ) | system_serial_low; +if (!sn) +return ret; + + tfm =crypto_alloc_sync_skcipher ("ecb(des)" ,0 ,0 ); +if (IS_ERR (tfm)) { +dev_err (dev,"failed to allocate cipher: %ld\n" ,PTR_ERR (tfm)); +return PTR_ERR (tfm); + } + + ret =crypto_sync_skcipher_setkey (tfm, key,sizeof (key)); +if (ret) { +dev_err (dev,"failed to set cipher key: %d\n" , ret); + goto err_free_tfm; + } + +memcpy (enc_sn, &sn,sizeof (enc_sn)); + +sg_init_one (&sg, enc_sn,sizeof (enc_sn)); +skcipher_request_set_sync_tfm (req, tfm); +skcipher_request_set_callback (req,0 ,NULL ,NULL ); +skcipher_request_set_crypt (req, &sg, &sg,sizeof (enc_sn),NULL );
drivers/net/ethernet/actions/owl-emac.c line 1429
Quoted 10 lines
drivers/net/ethernet/actions/owl-emac.c new file +10
-0+ + ret =crypto_skcipher_encrypt (req); +if (ret) { +dev_err (dev,"failed to encrypt S/N: %d\n" , ret); + goto err_free_tfm; + } + + netdev->dev_addr[0 ] =0xF4 ; + netdev->dev_addr[1 ] =0x4E ; + netdev->dev_addr[2 ] =0xFD ;
0xF4 has the locally administered bit 0. So this is a true OUI. Who does it belong to? Ah!
F4:4E:FD Actions Semiconductor Co.,Ltd.(Cayman Islands)
Which makes sense. But is there any sort of agreement this is allowed? It is going to cause problems if they are giving out these MAC addresses in a controlled way.
Maybe it would be better to set bit 1 of byte 0? And then you can use 5 bytes from enc_sn, not just 4.
Quoted 70 lines
drivers/net/ethernet/actions/owl-emac.c new file +69
-0+ netdev->dev_addr[3 ] = enc_sn[0 ]; + netdev->dev_addr[4 ] = enc_sn[4 ]; + netdev->dev_addr[5 ] = enc_sn[7 ]; + +err_free_tfm: +crypto_free_sync_skcipher (tfm); +#endif /* CONFIG_OWL_EMAC_GEN_ADDR_SYS_SN */ + +return ret; +} +static int owl_emac_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct net_device *netdev; +struct owl_emac_priv *priv; +int ret, i; + + netdev =devm_alloc_etherdev (dev,sizeof (*priv)); +if (!netdev) +return -ENOMEM ; + +platform_set_drvdata (pdev, netdev); +SET_NETDEV_DEV (netdev, dev); + + priv =netdev_priv (netdev); + priv->netdev = netdev; + priv->msg_enable =netif_msg_init (debug,DEFAULT_MSG_ENABLE ); + +spin_lock_init (&priv->lock); + + ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 )); +if (ret) { +dev_err (dev,"unsupported DMA mask\n" ); +return ret; + } + + ret =owl_emac_ring_alloc (dev, &priv->rx_ring,OWL_EMAC_RX_RING_SIZE ); +if (ret) +return ret; + + ret =owl_emac_ring_alloc (dev, &priv->tx_ring,OWL_EMAC_TX_RING_SIZE ); +if (ret) +return ret; + + priv->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base); + + netdev->irq =platform_get_irq (pdev,0 ); +if (netdev->irq <0 ) +return netdev->irq; + + ret =devm_request_irq (dev, netdev->irq, owl_emac_handle_irq, +IRQF_SHARED , netdev->name, netdev); +if (ret) { +dev_err (dev,"failed to request irq: %d\n" , netdev->irq); +return ret; + } + +for (i =0 ; i <OWL_EMAC_NCLKS ; i++) + priv->clks[i].id = owl_emac_clk_names[i]; + + ret =devm_clk_bulk_get (dev,OWL_EMAC_NCLKS , priv->clks); +if (ret) +return ret; + + ret =clk_bulk_prepare_enable (OWL_EMAC_NCLKS , priv->clks); +if (ret) +return ret;
drivers/net/ethernet/actions/owl-emac.c line 1581
Quoted 10 lines
drivers/net/ethernet/actions/owl-emac.c new file +10
-0+ + ret =clk_set_rate (priv->clks[OWL_EMAC_CLK_RMII ].clk,50000000 ); +if (ret) { +dev_err (dev,"failed to set RMII clock rate: %d\n" , ret); +return ret; + } + + ret =devm_add_action_or_reset (dev, owl_emac_clk_disable_unprepare, priv); +if (ret) +return ret;
Maybe this should go before the clk_set_rate(), just in case it fail?
Otherwise, this look a new clean driver.
Andrew
Re: [PATCH 2/3] net: ethernet: actions: Add Actions Semi Owl Ethernet MAC driver
Hi Andrew,
Thank you for the detailed review!
Quoted 11 lines · Andrew Lunn
drivers/net/ethernet/actions/owl-emac.c line 58
Quoted 5 lines · Cristian Ciocaltea
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+static inline void owl_emac_reg_set (struct owl_emac_priv *priv, +u32 reg,u32 bits) +{ +owl_emac_reg_update (priv, reg, bits, bits); +}Hi Cristian
No inline functions in C files please. Let the compiler decide. Please fix them all.
Sure.
Quoted 6 lines
drivers/net/ethernet/actions/owl-emac.c line 169
Quoted 4 lines
drivers/net/ethernet/actions/owl-emac.c new file +4
-0+static struct sk_buff *owl_emac_alloc_skb (struct net_device *netdev) +{ +int offset; +struct sk_buff *skb;Reverse Christmas tree please.
Already fixed this and all the others I could find.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/actions/owl-emac.c new file +11
-0+ + skb =netdev_alloc_skb (netdev,OWL_EMAC_RX_FRAME_MAX_LEN + +OWL_EMAC_SKB_RESERVE ); +if (unlikely (!skb)) +return NULL ; + +/* Ensure 4 bytes DMA alignment. */ + offset = ((uintptr_t )skb->data) & (OWL_EMAC_SKB_ALIGN -1 ); +if (unlikely (offset)) +skb_reserve (skb,OWL_EMAC_SKB_ALIGN - offset); +
Quoted 8 lines
drivers/net/ethernet/actions/owl-emac.c
Quoted 4 lines
drivers/net/ethernet/actions/owl-emac.c new file +4
-0+return skb; +} + +static void owl_emac_phy_config (struct owl_emac_priv *priv)You are not really configuring the PHY here, but configuring the MAC with what the PHY tells you has been negotiated. So maybe change this name?
Right, this was an uninspired choice on my side! I think something like 'owl_emac_update_link_state' would be more appropriate..
Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/actions/owl-emac.c new file +13
-0+{ +u32 val, status; + +if (priv->pause) { + val =OWL_EMAC_BIT_MAC_CSR20_FCE |OWL_EMAC_BIT_MAC_CSR20_TUE ; + val |=OWL_EMAC_BIT_MAC_CSR20_TPE |OWL_EMAC_BIT_MAC_CSR20_RPE ; + val |=OWL_EMAC_BIT_MAC_CSR20_BPE ; + }else { + val =0 ; + } + +/* Update flow control. */ +owl_emac_reg_write (priv,OWL_EMAC_REG_MAC_CSR20 , val);
[...]
Quoted 7 lines
drivers/net/ethernet/actions/owl-emac.c line 456
Quoted 3 lines
drivers/net/ethernet/actions/owl-emac.c new file +3
-0+static inline void owl_emac_ether_addr_push (u8 **dst,const u8 *src) +{ +u32 *a = (u32 *)(*dst);Is *dst guaranteed to by 32bit aligned? Given that it is
skb->data, i don't think it is.
Quoted 9 lines
drivers/net/ethernet/actions/owl-emac.c line 461
Quoted 5 lines
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+const u16 *b = (const u16 *)src; + + a[0 ] = b[0 ]; + a[1 ] = b[1 ]; + a[2 ] = b[2 ];So i don't know if this is safe. Some architectures don't like doing miss aligned read/writes. You probably should be using one of the
put_unaligned_()macros.
Actually skb->data is 32bit aligned, as required by the MAC hardware for DMA access - please see 'owl_emac_alloc_skb()'.
Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/actions/owl-emac.c new file +21
-0+ + *dst +=12 ; +} + +static void +owl_emac_setup_frame_prepare (struct owl_emac_priv *priv,struct sk_buff *skb) +{ +const u8 bcast_addr[] = {0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF }; +const u8 *mac_addr = priv->netdev->dev_addr; +u8 *frame; +int i; + +skb_put (skb,OWL_EMAC_SETUP_FRAME_LEN ); + + frame = skb->data; +memset (frame,0 , skb->len); + +owl_emac_ether_addr_push (&frame, mac_addr); +owl_emac_ether_addr_push (&frame, bcast_addr); + +/* Fill multicast addresses. */
Quoted 8 lines
drivers/net/ethernet/actions/owl-emac.c line 487
Quoted 5 lines
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+WARN_ON (priv->mcaddr_list.count >=OWL_EMAC_MAX_MULTICAST_ADDRS ); +for (i =0 ; i < priv->mcaddr_list.count; i++) { + mac_addr = priv->mcaddr_list.addrs[i]; +owl_emac_ether_addr_push (&frame, mac_addr); + }Please could you add some comments to this. You are building a rather odd frame here! What is it used form?
Yes, I actually planned to document this but eventually I missed it. The setup frames are special descriptors used to provide physical addresses to the MAC hardware for filtering purposes.
[...]
Quoted 9 lines
drivers/net/ethernet/actions/owl-emac.c line 945
Quoted 5 lines
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+static void owl_emac_mdio_clock_enable (struct owl_emac_priv *priv) +{ +u32 val; + +/* Enable MDC clock generation by setting CLKDIV to at least 128. */ You should be aiming for 2.5MHz bus clock. Does this depend on the speed of one of the two clocks you have? Maybe you can dynamically calculate the divider?
Unfortunately this is not properly documented in the datasheet, so I cannot tell which is the reference clock for the MDC clock divider. With the current approach (taken from the old vendor driver code), the divider is actually set to 1024 (obtained by OR-ing the HW default with this "magic" 128 correspondent).
What I know for sure is that 'eth' clock has a fixed rate (25MHz), while 'rmii' is set by the driver to 50MHz, both of them having a 500MHz PLL clock as parent. Hence if the information in the datasheet is correct regarding the MDC divider settings, I would assume none of those two clocks could be used as direct reference for MDC clock output, unless there is a more complex logic behind than a simple clock divider (e.g. maybe using a factor clock?!)
For the moment, I'm going to provide an updated comment:
/* Enable MDC clock generation by adjusting CLKDIV according to * the implementation of the original (old) vendor driver code.
Quoted 22 lines
Quoted 22 lines
drivers/net/ethernet/actions/owl-emac.c new file +21
-0+ val =owl_emac_reg_read (priv,OWL_EMAC_REG_MAC_CSR10 ); + val &=OWL_EMAC_MSK_MAC_CSR10_CLKDIV ; + val |=OWL_EMAC_VAL_MAC_CSR10_CLKDIV_128 <<OWL_EMAC_OFF_MAC_CSR10_CLKDIV ; + + val |=OWL_EMAC_BIT_MAC_CSR10_SB ; + val |=OWL_EMAC_VAL_MAC_CSR10_OPCODE_CDS <<OWL_EMAC_OFF_MAC_CSR10_OPCODE ; +owl_emac_reg_write (priv,OWL_EMAC_REG_MAC_CSR10 , val); +} +static int owl_emac_phy_init (struct net_device *netdev) +{ +struct owl_emac_priv *priv =netdev_priv (netdev); +struct device *dev =owl_emac_get_dev (priv); +struct phy_device *phy; + + phy =of_phy_get_and_connect (netdev, dev->of_node, + owl_emac_adjust_link); +if (!phy) +return -ENODEV ; + +if (phy->interface !=PHY_INTERFACE_MODE_RMII ) { + netdev_err(netdev, "unsupported phy mode: %s\n",
Quoted 8 lines
drivers/net/ethernet/actions/owl-emac.c line 1374
Quoted 5 lines
drivers/net/ethernet/actions/owl-emac.c new file +5
-0+ phy_modes(phy->interface)); +phy_disconnect (phy); + netdev->phydev =NULL ; +return -EINVAL ; + }It looks like the MAC only supports symmetric pause. So you should call
phy_set_sym_pause()to let the PHY know this.
I did not find any reference related to the supported pause types, is this normally dependant on the PHY interface mode?
The MAC hardware also supports SMII, but I haven't enabled it in the driver, yet, since I cannot validate this with my SBC.
Can/should I still provide the SMII support in this context?
Quoted 59 lines
Quoted 45 lines
drivers/net/ethernet/actions/owl-emac.c new file +45
-0+ +if (netif_msg_link (priv)) +phy_attached_info (phy); + +return 0 ; +} + +/* Generate the MAC address based on the system serial number. +*/ +static int owl_emac_generate_mac_addr (struct net_device *netdev) +{ +int ret = -ENXIO ; + +#ifdef CONFIG_OWL_EMAC_GEN_ADDR_SYS_SN +struct device *dev = netdev->dev.parent; +struct crypto_sync_skcipher *tfm; +struct scatterlist sg; +const u8 key[] = {1 ,4 ,13 ,21 ,59 ,67 ,69 ,127 }; +u64 sn; +u8 enc_sn[sizeof (key)]; + +SYNC_SKCIPHER_REQUEST_ON_STACK (req, tfm); + + sn = ((u64 )system_serial_high <<32 ) | system_serial_low; +if (!sn) +return ret; + + tfm =crypto_alloc_sync_skcipher ("ecb(des)" ,0 ,0 ); +if (IS_ERR (tfm)) { +dev_err (dev,"failed to allocate cipher: %ld\n" ,PTR_ERR (tfm)); +return PTR_ERR (tfm); + } + + ret =crypto_sync_skcipher_setkey (tfm, key,sizeof (key)); +if (ret) { +dev_err (dev,"failed to set cipher key: %d\n" , ret); + goto err_free_tfm; + } + +memcpy (enc_sn, &sn,sizeof (enc_sn)); + +sg_init_one (&sg, enc_sn,sizeof (enc_sn)); +skcipher_request_set_sync_tfm (req, tfm); +skcipher_request_set_callback (req,0 ,NULL ,NULL ); +skcipher_request_set_crypt (req, &sg, &sg,sizeof (enc_sn),NULL );drivers/net/ethernet/actions/owl-emac.c line 1429
Quoted 10 lines
drivers/net/ethernet/actions/owl-emac.c new file +10
-0+ + ret =crypto_skcipher_encrypt (req); +if (ret) { +dev_err (dev,"failed to encrypt S/N: %d\n" , ret); + goto err_free_tfm; + } + + netdev->dev_addr[0 ] =0xF4 ; + netdev->dev_addr[1 ] =0x4E ; + netdev->dev_addr[2 ] =0xFD ;
0xF4has the locally administered bit 0. So this is a true OUI. Who does it belong to? Ah!
Quoted 5 lines
F4:4E:FD Actions Semiconductor Co.,Ltd.(Cayman Islands)
Which makes sense. But is there any sort of agreement this is allowed? It is going to cause problems if they are giving out these MAC addresses in a controlled way.
Unfortunately this is another undocumented logic taken from the vendor code. I have already disabled it from being built by default, although, personally, I prefer to have it enabled in order to get a stable MAC address instead of using a randomly generated one or manually providing it via DT.
Just for clarification, I did not have any agreement or preliminary discussion with the vendor. This is just a personal initiative to improve the Owl SoC support in the mainline kernel.
Quoted 2 lines
Maybe it would be better to set bit 1 of byte 0? And then you can use 5 bytes from
enc_sn, not just 4.
I included the MAC generation feature in the driver to be fully compatible with the original implementation, but I'm open for changes if it raises concerns and compatibility is less important.
Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/actions/owl-emac.c new file +16
-0+ netdev->dev_addr[3 ] = enc_sn[0 ]; + netdev->dev_addr[4 ] = enc_sn[4 ]; + netdev->dev_addr[5 ] = enc_sn[7 ]; + +err_free_tfm: +crypto_free_sync_skcipher (tfm); +#endif /* CONFIG_OWL_EMAC_GEN_ADDR_SYS_SN */ + +return ret; +} +static int owl_emac_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct net_device *netdev; +struct owl_emac_priv *priv; +int ret, i;
[...]
Quoted 11 lines
drivers/net/ethernet/actions/owl-emac.c line 1581
Quoted 9 lines
drivers/net/ethernet/actions/owl-emac.c new file +9
-0+ ret =clk_set_rate (priv->clks[OWL_EMAC_CLK_RMII ].clk,50000000 ); +if (ret) { +dev_err (dev,"failed to set RMII clock rate: %d\n" , ret); +return ret; + } + + ret =devm_add_action_or_reset (dev, owl_emac_clk_disable_unprepare, priv); +if (ret) +return ret;Maybe this should go before the
clk_set_rate(), just in case it fail?
Indeed, I missed this, thanks for spotting it out!
Quoted 1 line
Otherwise, this look a new clean driver.
Well, I tried to do my best, given my limited experience as a self-taught kernel developer. Hopefully reviewing my code will not cause too many headaches! :)
Quoted 1 line
Andrew
Kind regards,
Cristi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 2/3] net: ethernet: actions: Add Actions Semi Owl Ethernet MAC driver
Quoted 11 lines
Quoted 10 lines
drivers/net/ethernet/actions/owl-emac.c line 1374
Quoted 7 lines
drivers/net/ethernet/actions/owl-emac.c new file +7
-0+if (phy->interface !=PHY_INTERFACE_MODE_RMII ) { +netdev_err (netdev,"unsupported phy mode: %s\n" , +phy_modes (phy->interface)); +phy_disconnect (phy); + netdev->phydev =NULL ; +return -EINVAL ; + }It looks like the MAC only supports symmetric pause. So you should call
phy_set_sym_pause()to let the PHY know this.
Quoted 2 lines
I did not find any reference related to the supported pause types, is this normally dependant on the PHY interface mode?
There is a MAC / PHY split there. The PHY is responsible for the negotiation for what each end can do. But it is the MAC which actually implements pause. The MAC needs to listen to pause frames and not send out data frames when the link peer indicates pause. And the MAC needs to send a pause frames when its receive buffers are full. The code you have in this MAC driver seems to indicate the MAC only supports symmetric pause. Hence you need to configure the PHY to only auto-neg symmetric pause.
Quoted 29 lines
Quoted 13 lines
drivers/net/ethernet/actions/owl-emac.c line 1429
Quoted 9 lines
drivers/net/ethernet/actions/owl-emac.c new file +9
-0+ ret =crypto_skcipher_encrypt (req); +if (ret) { +dev_err (dev,"failed to encrypt S/N: %d\n" , ret); + goto err_free_tfm; + } + + netdev->dev_addr[0 ] =0xF4 ; + netdev->dev_addr[1 ] =0x4E ; + netdev->dev_addr[2 ] =0xFD ;
0xF4has the locally administered bit 0. So this is a true OUI. Who does it belong to? Ah!Quoted 5 lines
F4:4E:FD Actions Semiconductor Co.,Ltd.(Cayman Islands)
Which makes sense. But is there any sort of agreement this is allowed? It is going to cause problems if they are giving out these MAC addresses in a controlled way.
Unfortunately this is another undocumented logic taken from the vendor code. I have already disabled it from being built by default, although, personally, I prefer to have it enabled in order to get a stable MAC address instead of using a randomly generated one or manually providing it via DT.
Just for clarification, I did not have any agreement or preliminary discussion with the vendor. This is just a personal initiative to improve the Owl SoC support in the mainline kernel.
Quoted 6 lines
Quoted 2 lines
Maybe it would be better to set bit 1 of byte 0? And then you can use 5 bytes from
enc_sn, not just 4.I included the MAC generation feature in the driver to be fully compatible with the original implementation, but I'm open for changes if it raises concerns and compatibility is less important.
This is not a simple question to answer. If the vendor driver does this, then the vendor can never assign MAC addresses in a controlled way, unless they have a good idea how the algorithm turns serial numbers into MAC addresses, and they can avoid MAC addresses for serial numbers already issued.
But should the Linux kernel do the same? If all you want is a stable MAC address, my personal preference would be to set the locally administered bit, and fill the other 5 bytes from the hash algorithm. You then have a stable MAC addresses, but you clearly indicate it is not guaranteed to by globally unique, and you do not need to worry about what the vendor is doing.
Quoted 5 lines
Quoted 1 line
Otherwise, this look a new clean driver.
Well, I tried to do my best, given my limited experience as a self-taught kernel developer. Hopefully reviewing my code will not cause too many headaches! :)
This is actually above average for a self-taught kernel developer. Well done.
Andrew
Re: [PATCH 2/3] net: ethernet: actions: Add Actions Semi Owl Ethernet MAC driver
Quoted 14 lines · Andrew Lunn
Quoted 11 lines
Quoted 10 lines
drivers/net/ethernet/actions/owl-emac.c line 1374
Quoted 7 lines
drivers/net/ethernet/actions/owl-emac.c new file +7
-0+if (phy->interface !=PHY_INTERFACE_MODE_RMII ) { +netdev_err (netdev,"unsupported phy mode: %s\n" , +phy_modes (phy->interface)); +phy_disconnect (phy); + netdev->phydev =NULL ; +return -EINVAL ; + }It looks like the MAC only supports symmetric pause. So you should call
phy_set_sym_pause()to let the PHY know this.Quoted 2 lines
I did not find any reference related to the supported pause types, is this normally dependant on the PHY interface mode?
Quoted 8 lines
There is a MAC / PHY split there. The PHY is responsible for the negotiation for what each end can do. But it is the MAC which actually implements pause. The MAC needs to listen to pause frames and not send out data frames when the link peer indicates pause. And the MAC needs to send a pause frames when its receive buffers are full. The code you have in this MAC driver seems to indicate the MAC only supports symmetric pause. Hence you need to configure the PHY to only auto-neg symmetric pause.
Thanks for explaining this, I will implement the indicated PHY configuration and, additionally, also enable the SMII interface.
Quoted 42 lines
Quoted 29 lines
Quoted 13 lines
drivers/net/ethernet/actions/owl-emac.c line 1429
Quoted 9 lines
drivers/net/ethernet/actions/owl-emac.c new file +9
-0+ ret =crypto_skcipher_encrypt (req); +if (ret) { +dev_err (dev,"failed to encrypt S/N: %d\n" , ret); + goto err_free_tfm; + } + + netdev->dev_addr[0 ] =0xF4 ; + netdev->dev_addr[1 ] =0x4E ; + netdev->dev_addr[2 ] =0xFD ;
0xF4has the locally administered bit 0. So this is a true OUI. Who does it belong to? Ah!Quoted 5 lines
F4:4E:FD Actions Semiconductor Co.,Ltd.(Cayman Islands)
Which makes sense. But is there any sort of agreement this is allowed? It is going to cause problems if they are giving out these MAC addresses in a controlled way.
Unfortunately this is another undocumented logic taken from the vendor code. I have already disabled it from being built by default, although, personally, I prefer to have it enabled in order to get a stable MAC address instead of using a randomly generated one or manually providing it via DT.
Just for clarification, I did not have any agreement or preliminary discussion with the vendor. This is just a personal initiative to improve the Owl SoC support in the mainline kernel.
Quoted 6 lines
Quoted 2 lines
Maybe it would be better to set bit 1 of byte 0? And then you can use 5 bytes from
enc_sn, not just 4.I included the MAC generation feature in the driver to be fully compatible with the original implementation, but I'm open for changes if it raises concerns and compatibility is less important.
This is not a simple question to answer. If the vendor driver does this, then the vendor can never assign MAC addresses in a controlled way, unless they have a good idea how the algorithm turns serial numbers into MAC addresses, and they can avoid MAC addresses for serial numbers already issued.
Quoted 6 lines
But should the Linux kernel do the same? If all you want is a stable MAC address, my personal preference would be to set the locally administered bit, and fill the other 5 bytes from the hash algorithm. You then have a stable MAC addresses, but you clearly indicate it is not guaranteed to by globally unique, and you do not need to worry about what the vendor is doing.
I fully agree, so I'm going to set byte 0 to value 0xF6 and replace bytes 1 & 2 with entries from the computed hash. I will also document this modification and the rationale behind.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Otherwise, this look a new clean driver.
Well, I tried to do my best, given my limited experience as a self-taught kernel developer. Hopefully reviewing my code will not cause too many headaches! :)
This is actually above average for a self-taught kernel developer. Well done.
Thank you, Andrew!
Quoted 1 line
Andrew