* Re: [PATCH net-next v3 0/3] net: ethernet: mediatek: check the hw lro capability by the chip id instead of the dtsi
From: David Miller @ 2016-10-07 1:08 UTC (permalink / raw)
To: nelson.chang; +Cc: john, nbd, netdev, linux-mediatek, nelsonch.tw
In-Reply-To: <1475754243-12557-1-git-send-email-nelson.chang@mediatek.com>
From: Nelson Chang <nelson.chang@mediatek.com>
Date: Thu, 6 Oct 2016 19:44:00 +0800
> The series modify to check if hw lro is supported by the chip id.
>
> changes since v3:
> - Refine mtk_is_hwlro_supported() function
>
> changes since v2:
> - Refine mtk_get_chip_id() function
>
> changes since v1:
> - Because hw lro started to be supported from MT7623, the proper way to check if the feature is capable is to judge by the chip id instead of by the dtsi.
Series applied, thanks.
^ permalink raw reply
* Re: [PATCH v2] ethernet: qualcomm: QCOM_EMAC should depend on HAS_DMA and HAS_IOMEM
From: David Miller @ 2016-10-07 1:13 UTC (permalink / raw)
To: geert; +Cc: timur, netdev, linux-kernel
In-Reply-To: <1475765093-15536-1-git-send-email-geert@linux-m68k.org>
From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: Thu, 6 Oct 2016 16:44:53 +0200
> If NO_DMA=y:
>
> drivers/built-in.o: In function `emac_probe':
> emac.c:(.text+0x3780b8): undefined reference to `bad_dma_ops'
> emac.c:(.text+0x3780e2): undefined reference to `bad_dma_ops'
> emac.c:(.text+0x378112): undefined reference to `bad_dma_ops'
> emac.c:(.text+0x378146): undefined reference to `bad_dma_ops'
> emac.c:(.text+0x37816e): undefined reference to `bad_dma_ops'
> drivers/built-in.o:emac.c:(.text+0x37819a): more undefined references to `bad_dma_ops' follow
>
> If NO_IOMEM=y:
>
> drivers/net/ethernet/qualcomm/emac/emac.c: In function ‘emac_remove’:
> drivers/net/ethernet/qualcomm/emac/emac.c:736:3: error: implicit declaration of function ‘iounmap’ [-Werror=implicit-function-declaration]
> iounmap(adpt->phy.digital);
> ^
>
> Add dependencies on HAS_DMA and HAS_IOMEM to fix this.
>
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Applied.
^ permalink raw reply
* Re: [PATCH] drivers: net: phy: Correct duplicate MDIO_XGENE entry
From: David Miller @ 2016-10-07 1:15 UTC (permalink / raw)
To: labbott; +Cc: f.fainelli, andrew, netdev, linux-kernel
In-Reply-To: <1475778171-10905-1-git-send-email-labbott@redhat.com>
From: Laura Abbott <labbott@redhat.com>
Date: Thu, 6 Oct 2016 11:22:51 -0700
> An extra entry for MDIO_XGENE got added during merging.
> Delete it.
>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Laura Abbott <labbott@redhat.com>
Applied, thanks.
^ permalink raw reply
* Re: [PATCH][RESEND] dt-bindings: net: renesas-ravb: Add support for R8A7796 RAVB
From: Simon Horman @ 2016-10-07 3:29 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: netdev, linux-renesas-soc
In-Reply-To: <1475599546-29209-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com>
On Tue, Oct 04, 2016 at 07:45:46PM +0300, Laurent Pinchart wrote:
> Add a new compatible string for the R8A7796 (M3-W) RAVB.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
> ---
> Documentation/devicetree/bindings/net/renesas,ravb.txt | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> The patch has been posted to the linux-renesas-soc mailing list only, adding
> the netdev mailing list to get it upstreamed.
>
> diff --git a/Documentation/devicetree/bindings/net/renesas,ravb.txt b/Documentation/devicetree/bindings/net/renesas,ravb.txt
> index c8ac222eac67..b519503be51a 100644
> --- a/Documentation/devicetree/bindings/net/renesas,ravb.txt
> +++ b/Documentation/devicetree/bindings/net/renesas,ravb.txt
> @@ -10,6 +10,7 @@ Required properties:
> "renesas,etheravb-r8a7793" if the device is a part of R8A7793 SoC.
> "renesas,etheravb-r8a7794" if the device is a part of R8A7794 SoC.
> "renesas,etheravb-r8a7795" if the device is a part of R8A7795 SoC.
> + "renesas,etheravb-r8a7796" if the device is a part of R8A7796 SoC.
> "renesas,etheravb-rcar-gen2" for generic R-Car Gen 2 compatible interface.
> "renesas,etheravb-rcar-gen3" for generic R-Car Gen 3 compatible interface.
>
> @@ -33,7 +34,7 @@ Optional properties:
> - interrupt-parent: the phandle for the interrupt controller that services
> interrupts for this device.
> - interrupt-names: A list of interrupt names.
> - For the R8A7795 SoC this property is mandatory;
> + For the R8A779[56] SoCs this property is mandatory;
> it should include one entry per channel, named "ch%u",
> where %u is the channel number ranging from 0 to 24.
> For other SoCs this property is optional; if present
> --
> Regards,
>
> Laurent Pinchart
>
^ permalink raw reply
* Re: [PATCH net] xen-netback: make sure that hashes are not send to unaware frontends
From: David Miller @ 2016-10-07 5:38 UTC (permalink / raw)
To: paul.durrant; +Cc: netdev, xen-devel, wei.liu2
In-Reply-To: <1475765230-11936-1-git-send-email-paul.durrant@citrix.com>
From: Paul Durrant <paul.durrant@citrix.com>
Date: Thu, 6 Oct 2016 15:47:10 +0100
> In the case when a frontend only negotiates a single queue with xen-
> netback it is possible for a skbuff with a s/w hash to result in a
> hash extra_info segment being sent to the frontend even when no hash
> algorithm has been configured. (The ndo_select_queue() entry point makes
> sure the hash is not set if no algorithm is configured, but this entry
> point is not called when there is only a single queue). This can result
> in a frontend that isunable to handle extra_info segments being given
> such a segment, causing it to crash.
>
> This patch fixes the problem by gating whether the extra_info is sent
> not only on the presence of a s/w hash, but also on whether the hash
> algorithm has been configured.
>
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
This doesn't apply cleanly to the current 'net' tree, please respin.
Thanks.
^ permalink raw reply
* RE: [PATCH net] xen-netback: make sure that hashes are not send to unaware frontends
From: Paul Durrant @ 2016-10-07 7:49 UTC (permalink / raw)
To: David Miller
Cc: netdev@vger.kernel.org, xen-devel@lists.xenproject.org, Wei Liu
In-Reply-To: <20161007.013801.2201234350691558646.davem@davemloft.net>
> -----Original Message-----
> From: David Miller [mailto:davem@davemloft.net]
> Sent: 07 October 2016 06:38
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: netdev@vger.kernel.org; xen-devel@lists.xenproject.org; Wei Liu
> <wei.liu2@citrix.com>
> Subject: Re: [PATCH net] xen-netback: make sure that hashes are not send
> to unaware frontends
>
> From: Paul Durrant <paul.durrant@citrix.com>
> Date: Thu, 6 Oct 2016 15:47:10 +0100
>
> > In the case when a frontend only negotiates a single queue with xen-
> > netback it is possible for a skbuff with a s/w hash to result in a
> > hash extra_info segment being sent to the frontend even when no hash
> > algorithm has been configured. (The ndo_select_queue() entry point
> > makes sure the hash is not set if no algorithm is configured, but this
> > entry point is not called when there is only a single queue). This can
> > result in a frontend that isunable to handle extra_info segments being
> > given such a segment, causing it to crash.
> >
> > This patch fixes the problem by gating whether the extra_info is sent
> > not only on the presence of a s/w hash, but also on whether the hash
> > algorithm has been configured.
> >
> > Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
>
> This doesn't apply cleanly to the current 'net' tree, please respin.
>
Sure. V2 coming.
Paul
> Thanks.
^ permalink raw reply
* [PATCH v2] ipv6 addrconf: disallow rtr_solicits < -1
From: Maciej Żenczykowski @ 2016-10-07 8:00 UTC (permalink / raw)
To: Maciej Żenczykowski, David S . Miller
Cc: netdev, Erik Kline, Lorenzo Colitti
In-Reply-To: <CANP3RGdVquyFe1VA2mKMC1HNgnXPhmpsv45R-7P6boWCb8oC2A@mail.gmail.com>
From: Maciej Żenczykowski <maze@google.com>
This disallows setting /proc/sys/net/ipv6/conf/*/router_solicitations
to values below -1.
-1 continues to mean an unlimited number of retransmits.
Note: this depends on 'ipv6 addrconf: remove addrconf_sysctl_hop_limit()'
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
net/ipv6/addrconf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index cbd9343751a2..d8983e15f859 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -5729,6 +5729,7 @@ int addrconf_sysctl_ignore_routes_with_linkdown(struct ctl_table *ctl,
return ret;
}
+static int minus_one = -1;
static const int one = 1;
static const int two_five_five = 255;
@@ -5789,7 +5790,8 @@ static const struct ctl_table addrconf_sysctl[] = {
.data = &ipv6_devconf.rtr_solicits,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec,
+ .proc_handler = proc_dointvec_minmax,
+ .extra1 = &minus_one,
},
{
.procname = "router_solicitation_interval",
--
2.8.0.rc3.226.g39d4020
^ permalink raw reply related
* [PATCH v4 00/10] net-next: ethernet: add sun8i-emac driver
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8, wens-jdAy2FN1RRM,
linux-I+IVW8TIWO2tmTQ+vhA3Yw, davem-fT/PcQaiUtIeIZ0/mPfg9Q,
f.fainelli-Re5JQEeQqe8AvxtiuMwx3w, andrew-g2DYL2Zd6BY
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Corentin Labbe
Hello
This patch series add the driver for sun8i-emac which handle the Ethernet MAC
present on Allwinner H3/A83T/A64 SoCs.
It supports 10/100/1000 Mbit/s speed with half/full duplex.
It can use an internal PHY (MII 10/100) or an external PHY
via RGMII/RMII.
This patch series enable the driver only for the H3 SoC since A83T and A64
doesn't have the necessary clocks present in mainline.
This patch series enable the driver only for OrangePiPC and OrangePIOne boards
since other board with H3 use external PHY which need optional regulators
that will be supported later.
The driver have been tested on the following boards:
- H3 Orange PI PC, Orange PI Plus, BananaPI-M2+
- A64 Pine64
- A83T BananaPI-M3
I would like to thanks Chen-Yu Tsai for his help on developing this driver.
Regards
Changes since v3
- sun8i-emac require a DT mdio node
- moved sun8i_emac_power() so that no clock/reset/regulator is used
until netdev/open is called
- Removed PM patch until proper tests are done
- DT use phy-handle instead of phy
- Moved DT aliases ethernet to subnodes
- Renamed PHY nodes to [int|ext]_[r|g]mii_phy
- Moved clock/reset for internal PHY to PHY node.
Changes since v2
- Added patch to support Orange PI One
- Added a patch to enable SUN8I_EMAC in sunxi_defconfig
- Added a patch to enable pm_runtime
- The Emac clock is now used standard syscon/regmap
- Added netdev_sent_queue/netdev_completed_queue
- Added lots of documentation on working (locks, memory barrier, etc...)
- Cleaned DT bindings documentation
- Added ethernet0 aliases as suggested by Hans de Goede
- Change prefix of all DEFINE to EMAC_
- The driver is now endian safe
- Reworked the internal PHY mechanism
- Removed dma_set_mask_and_coherent(32) since it is the default for of_platform_driver
Changes since v1
- Implement NAPI
- Sorted and reworded all define
- Reworked ethtools stats strings
- Removed all unneeded __packked and __aligned
- Added tuning of RX/TX ring size via ethtool
- Corrected use of sk/skb naming
- Added some wmb when needed
- Moved irq claim/free to emac_open/close
- Lots of code refactoring
Corentin Labbe (9):
ethernet: add sun8i-emac driver
MAINTAINERS: Add myself as maintainer of sun8i-emac
ARM: sun8i: dt: Add DT bindings documentation for Allwinner sun8i-emac
ARM: dts: sun8i-h3: Add dt node for the syscon control module
ARM: dts: sun8i-h3: add sun8i-emac ethernet driver
ARM: dts: sun8i: Enable sun8i-emac on the Orange PI PC
ARM: dts: sun8i: Enable sun8i-emac on the Orange Pi 2
ARM: sunxi: Enable sun8i-emac driver on multi_v7_defconfig
ARM: sunxi: Enable sun8i-emac driver on sunxi_defconfig
Hans de Goede (1):
ARM: dts: sun8i: Enable sun8i-emac on the Orange PI One
.../bindings/net/allwinner,sun8i-emac.txt | 70 +
MAINTAINERS | 6 +
arch/arm/boot/dts/sun8i-h3-orangepi-2.dts | 8 +
arch/arm/boot/dts/sun8i-h3-orangepi-one.dts | 8 +
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 8 +
arch/arm/boot/dts/sun8i-h3.dtsi | 29 +
arch/arm/configs/multi_v7_defconfig | 1 +
arch/arm/configs/sunxi_defconfig | 1 +
drivers/net/ethernet/allwinner/Kconfig | 13 +
drivers/net/ethernet/allwinner/Makefile | 1 +
drivers/net/ethernet/allwinner/sun8i-emac.c | 2266 ++++++++++++++++++++
11 files changed, 2411 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
create mode 100644 drivers/net/ethernet/allwinner/sun8i-emac.c
--
2.7.3
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* [PATCH v4 01/10] ethernet: add sun8i-emac driver
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8, wens-jdAy2FN1RRM,
linux-I+IVW8TIWO2tmTQ+vhA3Yw, davem-fT/PcQaiUtIeIZ0/mPfg9Q,
f.fainelli-Re5JQEeQqe8AvxtiuMwx3w, andrew-g2DYL2Zd6BY
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Corentin Labbe
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
This patch add support for sun8i-emac ethernet MAC hardware.
It could be found in Allwinner H3/A83T/A64 SoCs.
It supports 10/100/1000 Mbit/s speed with half/full duplex.
It can use an internal PHY (MII 10/100) or an external PHY
via RGMII/RMII.
Signed-off-by: Corentin Labbe <clabbe.montjoie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/net/ethernet/allwinner/Kconfig | 13 +
drivers/net/ethernet/allwinner/Makefile | 1 +
drivers/net/ethernet/allwinner/sun8i-emac.c | 2266 +++++++++++++++++++++++++++
3 files changed, 2280 insertions(+)
create mode 100644 drivers/net/ethernet/allwinner/sun8i-emac.c
diff --git a/drivers/net/ethernet/allwinner/Kconfig b/drivers/net/ethernet/allwinner/Kconfig
index 47da7e7..060569c 100644
--- a/drivers/net/ethernet/allwinner/Kconfig
+++ b/drivers/net/ethernet/allwinner/Kconfig
@@ -33,4 +33,17 @@ config SUN4I_EMAC
To compile this driver as a module, choose M here. The module
will be called sun4i-emac.
+config SUN8I_EMAC
+ tristate "Allwinner sun8i EMAC support"
+ depends on ARCH_SUNXI || COMPILE_TEST
+ depends on OF
+ select MII
+ select PHYLIB
+ ---help---
+ This driver support the sun8i EMAC ethernet driver present on
+ H3/A83T/A64 Allwinner SoCs.
+
+ To compile this driver as a module, choose M here. The module
+ will be called sun8i-emac.
+
endif # NET_VENDOR_ALLWINNER
diff --git a/drivers/net/ethernet/allwinner/Makefile b/drivers/net/ethernet/allwinner/Makefile
index 03129f7..8bd1693c 100644
--- a/drivers/net/ethernet/allwinner/Makefile
+++ b/drivers/net/ethernet/allwinner/Makefile
@@ -3,3 +3,4 @@
#
obj-$(CONFIG_SUN4I_EMAC) += sun4i-emac.o
+obj-$(CONFIG_SUN8I_EMAC) += sun8i-emac.o
diff --git a/drivers/net/ethernet/allwinner/sun8i-emac.c b/drivers/net/ethernet/allwinner/sun8i-emac.c
new file mode 100644
index 0000000..aa525d7
--- /dev/null
+++ b/drivers/net/ethernet/allwinner/sun8i-emac.c
@@ -0,0 +1,2266 @@
+/*
+ * sun8i-emac driver
+ *
+ * Copyright (C) 2015-2016 Corentin LABBE <clabbe.montjoie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
+ *
+ * This is the driver for Allwinner Ethernet MAC found in H3/A83T/A64 SoC
+ *
+ * TODO:
+ * - MAC filtering
+ * - Jumbo frame
+ * - features rx-all (NETIF_F_RXALL_BIT)
+ * - PM runtime
+ */
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+#include <linux/etherdevice.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/mii.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/of_device.h>
+#include <linux/of_mdio.h>
+#include <linux/of_net.h>
+#include <linux/phy.h>
+#include <linux/pinctrl/consumer.h>
+#include <linux/pinctrl/pinctrl.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/scatterlist.h>
+#include <linux/skbuff.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
+
+#define EMAC_BASIC_CTL0 0x00
+#define EMAC_BASIC_CTL1 0x04
+#define EMAC_INT_STA 0x08
+#define EMAC_INT_EN 0x0C
+#define EMAC_TX_CTL0 0x10
+#define EMAC_TX_CTL1 0x14
+#define EMAC_TX_FLOW_CTL 0x1C
+#define EMAC_RX_CTL0 0x24
+#define EMAC_RX_CTL1 0x28
+#define EMAC_RX_FRM_FLT 0x38
+#define EMAC_MDIO_CMD 0x48
+#define EMAC_MDIO_DATA 0x4C
+#define EMAC_TX_DMA_STA 0xB0
+#define EMAC_TX_CUR_DESC 0xB4
+#define EMAC_TX_CUR_BUF 0xB8
+#define EMAC_RX_DMA_STA 0xC0
+
+#define MDIO_CMD_MII_BUSY BIT(0)
+#define MDIO_CMD_MII_WRITE BIT(1)
+#define MDIO_CMD_MII_PHY_REG_ADDR_MASK GENMASK(8, 4)
+#define MDIO_CMD_MII_PHY_REG_ADDR_SHIFT 4
+#define MDIO_CMD_MII_PHY_ADDR_MASK GENMASK(16, 12)
+#define MDIO_CMD_MII_PHY_ADDR_SHIFT 12
+
+#define EMAC_MACADDR_HI 0x50
+#define EMAC_MACADDR_LO 0x54
+
+#define EMAC_RX_DESC_LIST 0x34
+#define EMAC_TX_DESC_LIST 0x20
+
+#define EMAC_RX_DO_CRC BIT(27)
+#define EMAC_RX_STRIP_FCS BIT(28)
+
+#define LE32_BIT(x) (cpu_to_le32(BIT(x)))
+
+#define EMAC_COULD_BE_USED_BY_DMA LE32_BIT(31)
+
+/* Used in RX_CTL1*/
+#define EMAC_RX_DMA_EN BIT(30)
+#define EMAC_RX_DMA_START BIT(31)
+/* Used in TX_CTL1*/
+#define EMAC_TX_DMA_EN BIT(30)
+#define EMAC_TX_DMA_START BIT(31)
+
+/* Used in RX_CTL0 */
+#define EMAC_RX_RECEIVER_EN BIT(31)
+/* Used in TX_CTL0 */
+#define EMAC_TX_TRANSMITTER_EN BIT(31)
+
+/* Basic CTL0 */
+#define EMAC_BCTL0_FD BIT(0)
+#define EMAC_BCTL0_SPEED_10 2
+#define EMAC_BCTL0_SPEED_100 3
+#define EMAC_BCTL0_SPEED_MASK GENMASK(3, 2)
+#define EMAC_BCTL0_SPEED_SHIFT 2
+
+#define EMAC_FLOW_RX 1
+#define EMAC_FLOW_TX 2
+
+#define EMAC_TX_INT BIT(0)
+#define EMAC_TX_DMA_STOP_INT BIT(1)
+#define EMAC_TX_BUF_UA_INT BIT(2)
+#define EMAC_TX_TIMEOUT_INT BIT(3)
+#define EMAC_TX_UNDERFLOW_INT BIT(4)
+#define EMAC_TX_EARLY_INT BIT(5)
+#define EMAC_RX_INT BIT(8)
+#define EMAC_RX_BUF_UA_INT BIT(9)
+#define EMAC_RX_DMA_STOP_INT BIT(10)
+#define EMAC_RX_TIMEOUT_INT BIT(11)
+#define EMAC_RX_OVERFLOW_INT BIT(12)
+#define EMAC_RX_EARLY_INT BIT(13)
+#define EMAC_RGMII_STA_INT BIT(16)
+
+/* Bits used in frame RX status */
+#define EMAC_DSC_RX_FIRST BIT(9)
+#define EMAC_DSC_RX_LAST BIT(8)
+
+/* Bits used in frame TX ctl */
+#define EMAC_MAGIC_TX_BIT LE32_BIT(24)
+#define EMAC_TX_DO_CRC (LE32_BIT(27) | LE32_BIT(28))
+#define EMAC_DSC_TX_FIRST LE32_BIT(29)
+#define EMAC_DSC_TX_LAST LE32_BIT(30)
+#define EMAC_WANT_INT LE32_BIT(31)
+
+/* struct emac_variant - Describe an emac variant of sun8i-emac
+ * @default_syscon_value: Default value of the syscon EMAC register
+ * The default_syscon_value is also used for powering down the PHY
+ * @internal_phy: which PHY type is internal
+ * @support_mii: Does the SoC support MII
+ * @support_rmii: Does the SoC support RMII
+ * @support_rgmii: Does the SoC support RGMII
+ */
+struct emac_variant {
+ u32 default_syscon_value;
+ int internal_phy;
+ bool support_mii;
+ bool support_rmii;
+ bool support_rgmii;
+};
+
+static const struct emac_variant emac_variant_h3 = {
+ .default_syscon_value = 0x58000,
+ .internal_phy = PHY_INTERFACE_MODE_MII,
+ .support_mii = true,
+ .support_rmii = true,
+ .support_rgmii = true
+};
+
+static const struct emac_variant emac_variant_a83t = {
+ .default_syscon_value = 0,
+ .internal_phy = 0,
+ .support_mii = true,
+ .support_rgmii = true
+};
+
+static const struct emac_variant emac_variant_a64 = {
+ .default_syscon_value = 0,
+ .internal_phy = 0,
+ .support_mii = true,
+ .support_rmii = true,
+ .support_rgmii = true
+};
+
+static const char const estats_str[][ETH_GSTRING_LEN] = {
+ /* errors */
+ "rx_payload_error",
+ "rx_CRC_error",
+ "rx_phy_error",
+ "rx_length_error",
+ "rx_col_error",
+ "rx_header_error",
+ "rx_overflow_error",
+ "rx_saf_error",
+ "rx_daf_error",
+ "rx_buf_error",
+ "rx_invalid_error",
+ "tx_timeout",
+ /* misc infos */
+ "tx_stop_queue",
+ "rx_dma_ua",
+ "rx_dma_stop",
+ "tx_dma_ua",
+ "tx_dma_stop",
+ "rx_hw_csum",
+ "tx_hw_csum",
+ /* interrupts */
+ "rx_int",
+ "tx_int",
+ "tx_early_int",
+ "tx_underflow_int",
+ "tx_timeout_int",
+ "rx_early_int",
+ "rx_overflow_int",
+ "rx_timeout_int",
+ "rgmii_state_int",
+ /* debug */
+ "tx_used_desc",
+ "napi_schedule",
+ "napi_underflow",
+};
+
+struct sun8i_emac_stats {
+ u64 rx_payload_error;
+ u64 rx_crc_error;
+ u64 rx_phy_error;
+ u64 rx_length_error;
+ u64 rx_col_error;
+ u64 rx_header_error;
+ u64 rx_overflow_error;
+ u64 rx_saf_fail;
+ u64 rx_daf_fail;
+ u64 rx_buf_error;
+ u64 rx_invalid_error;
+ u64 tx_timeout;
+
+ u64 tx_stop_queue;
+ u64 rx_dma_ua;
+ u64 rx_dma_stop;
+ u64 tx_dma_ua;
+ u64 tx_dma_stop;
+ u64 rx_hw_csum;
+ u64 tx_hw_csum;
+
+ u64 rx_int;
+ u64 tx_int;
+ u64 tx_early_int;
+ u64 tx_underflow_int;
+ u64 tx_timeout_int;
+ u64 rx_early_int;
+ u64 rx_overflow_int;
+ u64 rx_timeout_int;
+ u64 rgmii_state_int;
+
+ u64 tx_used_desc;
+ u64 napi_schedule;
+ u64 napi_underflow;
+};
+
+/* The datasheet said that each descriptor can transfers up to 4096bytes
+ * But latter, a register documentation reduce that value to 2048
+ * Anyway using 2048 cause strange behaviours and even BSP driver use 2047
+ */
+#define DESC_BUF_MAX 2044
+
+/* MAGIC value for knowing if a descriptor is available or not */
+#define DCLEAN cpu_to_le32(BIT(16) | BIT(14) | BIT(12) | BIT(10) | BIT(9))
+
+/* struct dma_desc - Structure of DMA descriptor used by the hardware
+ * @status: Status of the frame written by HW, so RO for the
+ * driver (except for BIT(31) which is R/W)
+ * @ctl: Information on the frame written by the driver (INT, len,...)
+ * @buf_addr: physical address of the frame data
+ * @next: physical address of next dma_desc
+ */
+struct dma_desc {
+ __le32 status;
+ __le32 ctl;
+ __le32 buf_addr;
+ __le32 next;
+};
+
+/* Describe how data from skb are DMA mapped (used in txinfo map member) */
+#define MAP_SINGLE 1
+#define MAP_PAGE 2
+
+/* Structure for storing information about data in TX ring buffer */
+struct txinfo {
+ struct sk_buff *skb;
+ int map;
+};
+
+struct sun8i_emac_priv {
+ void __iomem *base;
+ struct regmap *regmap;
+ int irq;
+ struct device *dev;
+ struct net_device *ndev;
+ struct mii_bus *mdio;
+ struct napi_struct napi;
+ spinlock_t tx_lock;/* control the access of transmit descriptors */
+ int duplex;
+ int speed;
+ int link;
+ int phy_interface;
+ const struct emac_variant *variant;
+ struct device_node *phy_node;
+ struct device_node *mdio_node;
+ struct clk *ahb_clk;
+ struct clk *ephy_clk;
+ bool use_internal_phy;
+
+ struct reset_control *rst_mac;
+ struct reset_control *rst_ephy;
+
+ struct dma_desc *dd_rx;
+ dma_addr_t dd_rx_phy;
+ struct dma_desc *dd_tx;
+ dma_addr_t dd_tx_phy;
+ struct sk_buff **rx_skb;
+ struct txinfo *txl;
+
+ int nbdesc_tx;
+ int nbdesc_rx;
+ int tx_slot;
+ int tx_dirty;
+ int rx_dirty;
+ struct sun8i_emac_stats estats;
+ u32 msg_enable;
+ int flow_ctrl;
+ int pause;
+};
+
+static irqreturn_t sun8i_emac_dma_interrupt(int irq, void *dev_id);
+
+static void rb_inc(int *p, const int max)
+{
+ (*p)++;
+ (*p) %= max;
+}
+
+/* Locking strategy:
+ * RX queue does not need any lock since only sun8i_emac_poll() access it.
+ * (All other RX modifiers (ringparam/ndo_stop) disable NAPI and so
+ * sun8i_emac_poll())
+ * TX queue is handled by sun8i_emac_xmit(), sun8i_emac_complete_xmit() and
+ * sun8i_emac_tx_timeout()
+ * (All other RX modifiers (ringparam/ndo_stop) disable NAPI and stop queue)
+ *
+ * sun8i_emac_xmit() could fire only once (netif_tx_lock)
+ * sun8i_emac_complete_xmit() could fire only once (called from NAPI)
+ * sun8i_emac_tx_timeout() could fire only once (netif_tx_lock) and could not
+ * race with sun8i_emac_xmit (due to netif_tx_lock) and with
+ * sun8i_emac_complete_xmit which disable NAPI.
+ *
+ * So only sun8i_emac_xmit and sun8i_emac_complete_xmit could fire at the same
+ * time.
+ * But they never could modify the same descriptors:
+ * - sun8i_emac_complete_xmit() will modify only descriptors with empty status
+ * - sun8i_emac_xmit() will modify only descriptors set to DCLEAN
+ * Proper memory barriers ensure that descriptor set to DCLEAN could not be
+ * modified latter by sun8i_emac_complete_xmit().
+ */
+
+/* Return the number of contiguous free descriptors
+ * starting from tx_slot
+ */
+static int rb_tx_numfreedesc(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ if (priv->tx_slot < priv->tx_dirty)
+ return priv->tx_dirty - priv->tx_slot;
+
+ return (priv->nbdesc_tx - priv->tx_slot) + priv->tx_dirty;
+}
+
+/* sun8i_emac_rx_skb - Allocate a skb in a DMA descriptor
+ *
+ * @ndev: The net_device for this interface
+ * @i: index of slot to fill
+ *
+ * Refill a DMA descriptor with a fresh skb and map it for DMA.
+*/
+static int sun8i_emac_rx_skb(struct net_device *ndev, int i)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct dma_desc *ddesc;
+ struct sk_buff *skb;
+
+ ddesc = priv->dd_rx + i;
+
+ ddesc->ctl = 0;
+
+ skb = netdev_alloc_skb_ip_align(ndev, DESC_BUF_MAX);
+ if (!skb)
+ return -ENOMEM;
+
+ /* should not happen */
+ if (unlikely(priv->rx_skb[i]))
+ dev_warn(priv->dev, "BUG: Leaking a skbuff\n");
+
+ priv->rx_skb[i] = skb;
+
+ ddesc->buf_addr = dma_map_single(priv->dev, skb->data,
+ DESC_BUF_MAX, DMA_FROM_DEVICE);
+ if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
+ dev_err(priv->dev, "ERROR: Cannot map RX buffer for DMA\n");
+ dev_kfree_skb(skb);
+ return -EFAULT;
+ }
+ /* We cannot direcly use cpu_to_le32() after dma_map_single
+ * since dma_mapping_error use it
+ */
+ ddesc->buf_addr = cpu_to_le32(ddesc->buf_addr);
+ ddesc->ctl |= cpu_to_le32(DESC_BUF_MAX);
+ /* EMAC_COULD_BE_USED_BY_DMA must be the last value written */
+ wmb();
+ ddesc->status = EMAC_COULD_BE_USED_BY_DMA;
+
+ return 0;
+}
+
+static void sun8i_emac_stop_tx(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 v;
+
+ netif_stop_queue(ndev);
+
+ v = readl(priv->base + EMAC_TX_CTL0);
+ /* Disable transmitter after current reception */
+ v &= ~EMAC_TX_TRANSMITTER_EN;
+ writel(v, priv->base + EMAC_TX_CTL0);
+
+ v = readl(priv->base + EMAC_TX_CTL1);
+ /* Stop TX DMA */
+ v &= ~EMAC_TX_DMA_EN;
+ writel(v, priv->base + EMAC_TX_CTL1);
+
+ /* We must be sure that all is stopped before leaving this function */
+ wmb();
+}
+
+static void sun8i_emac_stop_rx(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 v;
+
+ v = readl(priv->base + EMAC_RX_CTL0);
+ /* Disable receiver after current reception */
+ v &= ~EMAC_RX_RECEIVER_EN;
+ writel(v, priv->base + EMAC_RX_CTL0);
+
+ v = readl(priv->base + EMAC_RX_CTL1);
+ /* Stop RX DMA */
+ v &= ~EMAC_RX_DMA_EN;
+ writel(v, priv->base + EMAC_RX_CTL1);
+
+ /* We must be sure that all is stopped before leaving this function */
+ wmb();
+}
+
+static void sun8i_emac_start_rx(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 v;
+
+ v = readl(priv->base + EMAC_RX_CTL0);
+ /* Enable receiver */
+ v |= EMAC_RX_RECEIVER_EN;
+ writel(v, priv->base + EMAC_RX_CTL0);
+
+ v = readl(priv->base + EMAC_RX_CTL1);
+ v |= EMAC_RX_DMA_START;
+ v |= EMAC_RX_DMA_EN;
+ writel(v, priv->base + EMAC_RX_CTL1);
+}
+
+static void sun8i_emac_start_tx(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 v;
+
+ v = readl(priv->base + EMAC_TX_CTL0);
+ v |= EMAC_TX_TRANSMITTER_EN;
+ writel(v, priv->base + EMAC_TX_CTL0);
+
+ v = readl(priv->base + EMAC_TX_CTL1);
+ v |= EMAC_TX_DMA_START;
+ v |= EMAC_TX_DMA_EN;
+ writel(v, priv->base + EMAC_TX_CTL1);
+}
+
+/* sun8i_emac_set_macaddr - Set MAC address for slot index
+ *
+ * @addr: the MAC address to set
+ * @index: The index of slot where to set address.
+ *
+ * The slot 0 is the main MAC address
+ */
+static void sun8i_emac_set_macaddr(struct sun8i_emac_priv *priv,
+ const u8 *addr, int index)
+{
+ u32 v;
+
+ dev_info(priv->dev, "device MAC address slot %d %pM", index, addr);
+
+ v = (addr[5] << 8) | addr[4];
+ writel(v, priv->base + EMAC_MACADDR_HI + index * 8);
+
+ v = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
+ writel(v, priv->base + EMAC_MACADDR_LO + index * 8);
+}
+
+static void sun8i_emac_set_link_mode(struct sun8i_emac_priv *priv)
+{
+ u32 v;
+
+ v = readl(priv->base + EMAC_BASIC_CTL0);
+
+ if (priv->duplex)
+ v |= EMAC_BCTL0_FD;
+ else
+ v &= ~EMAC_BCTL0_FD;
+
+ v &= ~EMAC_BCTL0_SPEED_MASK;
+
+ switch (priv->speed) {
+ case 1000:
+ break;
+ case 100:
+ v |= EMAC_BCTL0_SPEED_100 << EMAC_BCTL0_SPEED_SHIFT;
+ break;
+ case 10:
+ v |= EMAC_BCTL0_SPEED_10 << EMAC_BCTL0_SPEED_SHIFT;
+ break;
+ default:
+ dev_err(priv->dev, "Unsupported speed %d\n", priv->speed);
+ return;
+ }
+
+ writel(v, priv->base + EMAC_BASIC_CTL0);
+}
+
+static void sun8i_emac_flow_ctrl(struct sun8i_emac_priv *priv, int duplex,
+ int fc)
+{
+ u32 flow = 0;
+
+ flow = readl(priv->base + EMAC_RX_CTL0);
+ if (fc & EMAC_FLOW_RX)
+ flow |= BIT(16);
+ else
+ flow &= ~BIT(16);
+ writel(flow, priv->base + EMAC_RX_CTL0);
+
+ flow = readl(priv->base + EMAC_TX_FLOW_CTL);
+ if (fc & EMAC_FLOW_TX)
+ flow |= BIT(0);
+ else
+ flow &= ~BIT(0);
+ writel(flow, priv->base + EMAC_TX_FLOW_CTL);
+}
+
+/* Grab a frame into a skb from descriptor number i */
+static int sun8i_emac_rx_from_ddesc(struct net_device *ndev, int i)
+{
+ struct sk_buff *skb;
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct dma_desc *ddesc = priv->dd_rx + i;
+ int frame_len;
+ int rxcsum_done = 0;
+ u32 dstatus = le32_to_cpu(ddesc->status);
+
+ if (ndev->features & NETIF_F_RXCSUM)
+ rxcsum_done = 1;
+
+ /* bit0/bit7 work only on IPv4/IPv6 TCP traffic,
+ * (not on ARP for example) so we do not raise rx_errors/discard frame
+ */
+ /* the checksum or length of received frame's payload is wrong*/
+ if (dstatus & BIT(0)) {
+ priv->estats.rx_payload_error++;
+ rxcsum_done = 0;
+ }
+
+ /* RX_CRC_ERR */
+ if (dstatus & BIT(1)) {
+ priv->ndev->stats.rx_errors++;
+ priv->ndev->stats.rx_crc_errors++;
+ priv->estats.rx_crc_error++;
+ goto discard_frame;
+ }
+
+ /* RX_PHY_ERR */
+ if ((dstatus & BIT(3))) {
+ priv->ndev->stats.rx_errors++;
+ priv->estats.rx_phy_error++;
+ goto discard_frame;
+ }
+
+ /* RX_LENGTH_ERR */
+ if ((dstatus & BIT(4))) {
+ priv->ndev->stats.rx_errors++;
+ priv->ndev->stats.rx_length_errors++;
+ priv->estats.rx_length_error++;
+ goto discard_frame;
+ }
+
+ /* RX_COL_ERR */
+ if ((dstatus & BIT(6))) {
+ priv->ndev->stats.rx_errors++;
+ priv->estats.rx_col_error++;
+ goto discard_frame;
+ }
+
+ /* RX_HEADER_ERR */
+ if ((dstatus & BIT(7))) {
+ priv->estats.rx_header_error++;
+ rxcsum_done = 0;
+ }
+
+ /* RX_OVERFLOW_ERR */
+ if ((dstatus & BIT(11))) {
+ priv->ndev->stats.rx_over_errors++;
+ priv->estats.rx_overflow_error++;
+ goto discard_frame;
+ }
+
+ /* RX_NO_ENOUGTH_BUF_ERR */
+ if ((dstatus & BIT(14))) {
+ priv->ndev->stats.rx_errors++;
+ priv->estats.rx_buf_error++;
+ goto discard_frame;
+ }
+
+ /* BIT(9) is for the first frame, not having it is bad since we do not
+ * handle Jumbo frame
+ */
+ if ((dstatus & EMAC_DSC_RX_FIRST) == 0) {
+ priv->ndev->stats.rx_errors++;
+ priv->estats.rx_invalid_error++;
+ goto discard_frame;
+ }
+
+ /* this frame is not the last */
+ if ((dstatus & EMAC_DSC_RX_LAST) == 0) {
+ priv->ndev->stats.rx_errors++;
+ priv->estats.rx_invalid_error++;
+ goto discard_frame;
+ }
+
+ frame_len = (dstatus >> 16) & 0x3FFF;
+ if (!(ndev->features & NETIF_F_RXFCS))
+ frame_len -= ETH_FCS_LEN;
+
+ skb = priv->rx_skb[i];
+
+ netif_dbg(priv, rx_status, priv->ndev,
+ "%s from %02d %pad len=%d status=%x st=%x\n",
+ __func__, i, &ddesc, frame_len, dstatus,
+ cpu_to_le32(ddesc->ctl));
+
+ skb_put(skb, frame_len);
+
+ dma_unmap_single(priv->dev, le32_to_cpu(ddesc->buf_addr), DESC_BUF_MAX,
+ DMA_FROM_DEVICE);
+ skb->protocol = eth_type_trans(skb, priv->ndev);
+ if (rxcsum_done) {
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+ priv->estats.rx_hw_csum++;
+ } else {
+ skb->ip_summed = CHECKSUM_PARTIAL;
+ }
+
+ priv->ndev->stats.rx_packets++;
+ priv->ndev->stats.rx_bytes += frame_len;
+ priv->rx_skb[i] = NULL;
+
+ sun8i_emac_rx_skb(ndev, i);
+ napi_gro_receive(&priv->napi, skb);
+
+ return 0;
+ /* If the frame need to be dropped, we simply reuse the buffer */
+discard_frame:
+ ddesc->ctl = cpu_to_le32(DESC_BUF_MAX);
+ /* EMAC_COULD_BE_USED_BY_DMA must be the last value written */
+ wmb();
+ ddesc->status = EMAC_COULD_BE_USED_BY_DMA;
+ return 0;
+}
+
+/* Iterate over dma_desc for finding completed xmit.
+ *
+ * The problem is: how to know that a descriptor is sent and not just in
+ * preparation.
+ * Need to have status=0 and st set but this is the state of first frame just
+ * before setting the own-by-DMA bit.
+ * The solution is to used the artificial value DCLEAN.
+ */
+static int sun8i_emac_complete_xmit(struct net_device *ndev, int budget)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct dma_desc *ddesc;
+ int frame_len;
+ int work = 0;
+ unsigned int bytes_compl = 0, pkts_compl = 0;
+ u32 dstatus;
+
+ do {
+ ddesc = priv->dd_tx + priv->tx_dirty;
+
+ if (ddesc->status & EMAC_COULD_BE_USED_BY_DMA)
+ goto xmit_end;
+
+ if (ddesc->status == DCLEAN)
+ goto xmit_end;
+
+ dstatus = cpu_to_le32(ddesc->status);
+
+ if (ddesc->status == 0 && !ddesc->ctl) {
+ dev_err(priv->dev, "BUG: reached the void %d %d\n",
+ priv->tx_dirty, priv->tx_slot);
+ goto xmit_end;
+ }
+
+ /* TX_UNDERFLOW_ERR */
+ if (dstatus & BIT(1))
+ priv->ndev->stats.tx_errors++;
+ /* TX_DEFER_ERR */
+ if (dstatus & BIT(2))
+ priv->ndev->stats.tx_errors++;
+ /* BIT 6:3 numbers of collisions */
+ if (dstatus & 0x78)
+ priv->ndev->stats.collisions +=
+ (dstatus & 0x78) >> 3;
+ /* TX_COL_ERR_1 */
+ if (dstatus & BIT(8))
+ priv->ndev->stats.tx_errors++;
+ /* TX_COL_ERR_0 */
+ if (dstatus & BIT(9))
+ priv->ndev->stats.tx_errors++;
+ /* TX_CRS_ERR */
+ if (dstatus & BIT(10))
+ priv->ndev->stats.tx_carrier_errors++;
+ /* TX_PAYLOAD_ERR */
+ if (dstatus & BIT(12))
+ priv->ndev->stats.tx_errors++;
+ /* TX_LENGTH_ERR */
+ if (dstatus & BIT(14))
+ priv->ndev->stats.tx_errors++;
+ /* TX_HEADER_ERR */
+ if (dstatus & BIT(16))
+ priv->ndev->stats.tx_errors++;
+
+ frame_len = le32_to_cpu(ddesc->ctl) & 0x3FFF;
+ bytes_compl += frame_len;
+
+ if (priv->txl[priv->tx_dirty].map == MAP_SINGLE)
+ dma_unmap_single(priv->dev,
+ le32_to_cpu(ddesc->buf_addr),
+ frame_len, DMA_TO_DEVICE);
+ else
+ dma_unmap_page(priv->dev,
+ le32_to_cpu(ddesc->buf_addr),
+ frame_len, DMA_TO_DEVICE);
+ /* we can free skb only on last frame */
+ if (priv->txl[priv->tx_dirty].skb &&
+ (ddesc->ctl & EMAC_DSC_TX_LAST)) {
+ dev_kfree_skb_irq(priv->txl[priv->tx_dirty].skb);
+ pkts_compl++;
+ }
+
+ priv->txl[priv->tx_dirty].skb = NULL;
+ priv->txl[priv->tx_dirty].map = 0;
+ ddesc->ctl = 0;
+ /* setting status to DCLEAN is the last value to be set */
+ wmb();
+ ddesc->status = DCLEAN;
+ work++;
+
+ rb_inc(&priv->tx_dirty, priv->nbdesc_tx);
+ ddesc = priv->dd_tx + priv->tx_dirty;
+ } while (ddesc->ctl &&
+ !(ddesc->status & EMAC_COULD_BE_USED_BY_DMA) &&
+ work < budget);
+
+xmit_end:
+ netdev_completed_queue(ndev, pkts_compl, bytes_compl);
+
+ /* if we don't have handled all packets */
+ if (work < budget)
+ work = 0;
+
+ if (netif_queue_stopped(ndev) &&
+ rb_tx_numfreedesc(ndev) > MAX_SKB_FRAGS + 1)
+ netif_wake_queue(ndev);
+ return work;
+}
+
+static int sun8i_emac_poll(struct napi_struct *napi, int budget)
+{
+ struct sun8i_emac_priv *priv =
+ container_of(napi, struct sun8i_emac_priv, napi);
+ struct net_device *ndev = priv->ndev;
+ int worked;
+ struct dma_desc *ddesc;
+
+ priv->estats.napi_schedule++;
+ worked = sun8i_emac_complete_xmit(ndev, budget);
+
+ ddesc = priv->dd_rx + priv->rx_dirty;
+ while (!(ddesc->status & EMAC_COULD_BE_USED_BY_DMA) &&
+ worked < budget) {
+ sun8i_emac_rx_from_ddesc(ndev, priv->rx_dirty);
+ worked++;
+ rb_inc(&priv->rx_dirty, priv->nbdesc_rx);
+ ddesc = priv->dd_rx + priv->rx_dirty;
+ };
+ if (worked < budget) {
+ priv->estats.napi_underflow++;
+ napi_complete(&priv->napi);
+ writel(EMAC_RX_INT | EMAC_TX_INT, priv->base + EMAC_INT_EN);
+ }
+ return worked;
+}
+
+static int sun8i_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg)
+{
+ struct net_device *ndev = bus->priv;
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ int err;
+ u32 reg;
+
+ err = readl_poll_timeout(priv->base + EMAC_MDIO_CMD, reg,
+ !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
+ if (err) {
+ dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
+ return err;
+ }
+
+ reg &= ~MDIO_CMD_MII_WRITE;
+ reg &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
+ reg |= (phy_reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
+ MDIO_CMD_MII_PHY_REG_ADDR_MASK;
+
+ reg &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
+
+ reg |= (phy_addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
+ MDIO_CMD_MII_PHY_ADDR_MASK;
+
+ reg |= MDIO_CMD_MII_BUSY;
+
+ writel(reg, priv->base + EMAC_MDIO_CMD);
+
+ err = readl_poll_timeout(priv->base + EMAC_MDIO_CMD, reg,
+ !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
+
+ if (err) {
+ dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
+ return err;
+ }
+
+ return readl(priv->base + EMAC_MDIO_DATA);
+}
+
+static int sun8i_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg,
+ u16 data)
+{
+ struct net_device *ndev = bus->priv;
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 reg;
+ int err;
+
+ err = readl_poll_timeout(priv->base + EMAC_MDIO_CMD, reg,
+ !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
+ if (err) {
+ dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
+ return err;
+ }
+
+ reg &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
+ reg |= (phy_reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
+ MDIO_CMD_MII_PHY_REG_ADDR_MASK;
+
+ reg &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
+ reg |= (phy_addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
+ MDIO_CMD_MII_PHY_ADDR_MASK;
+
+ reg |= MDIO_CMD_MII_WRITE;
+ reg |= MDIO_CMD_MII_BUSY;
+
+ writel(reg, priv->base + EMAC_MDIO_CMD);
+ writel(data, priv->base + EMAC_MDIO_DATA);
+
+ err = readl_poll_timeout(priv->base + EMAC_MDIO_CMD, reg,
+ !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
+ if (err) {
+ dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
+ return err;
+ }
+
+ return 0;
+}
+
+static int sun8i_emac_mdio_register(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct mii_bus *bus;
+ int ret;
+
+ bus = mdiobus_alloc();
+ if (!bus) {
+ netdev_err(ndev, "Failed to allocate a new mdio bus\n");
+ return -ENOMEM;
+ }
+
+ bus->name = dev_name(priv->dev);
+ bus->read = &sun8i_mdio_read;
+ bus->write = &sun8i_mdio_write;
+ snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%x", bus->name, priv->dev->id);
+
+ bus->parent = priv->dev;
+ bus->priv = ndev;
+
+ ret = of_mdiobus_register(bus, priv->mdio_node);
+ if (ret) {
+ netdev_err(ndev, "Could not register a MDIO bus: %d\n", ret);
+ mdiobus_free(bus);
+ return ret;
+ }
+
+ priv->mdio = bus;
+
+ return 0;
+}
+
+static void sun8i_emac_mdio_unregister(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ mdiobus_unregister(priv->mdio);
+ mdiobus_free(priv->mdio);
+}
+
+/* Run within phydev->lock */
+static void sun8i_emac_adjust_link(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct phy_device *phydev = ndev->phydev;
+ int new_state = 0;
+
+ netif_dbg(priv, link, priv->ndev,
+ "%s link=%x duplex=%x speed=%x\n", __func__,
+ phydev->link, phydev->duplex, phydev->speed);
+ if (!phydev)
+ return;
+
+ if (phydev->link) {
+ if (phydev->duplex != priv->duplex) {
+ new_state = 1;
+ priv->duplex = phydev->duplex;
+ }
+ if (phydev->pause)
+ sun8i_emac_flow_ctrl(priv, phydev->duplex,
+ priv->flow_ctrl);
+
+ if (phydev->speed != priv->speed) {
+ new_state = 1;
+ priv->speed = phydev->speed;
+ }
+
+ if (priv->link == 0) {
+ new_state = 1;
+ priv->link = phydev->link;
+ }
+
+ netif_dbg(priv, link, priv->ndev,
+ "%s new=%d link=%d pause=%d\n",
+ __func__, new_state, priv->link, phydev->pause);
+ if (new_state)
+ sun8i_emac_set_link_mode(priv);
+ } else if (priv->link != phydev->link) {
+ new_state = 1;
+ priv->link = 0;
+ priv->speed = 0;
+ priv->duplex = -1;
+ }
+
+ if (new_state)
+ phy_print_status(phydev);
+}
+
+/* H3 specific bits for EPHY */
+#define H3_EPHY_ADDR_SHIFT 20
+#define H3_EPHY_LED_POL BIT(17) /* 1: active low, 0: active high */
+#define H3_EPHY_SHUTDOWN BIT(16) /* 1: shutdown, 0: power up */
+#define H3_EPHY_SELECT BIT(15) /* 1: internal PHY, 0: external PHY */
+
+/* H3/A64 specific bits */
+#define SYSCON_RMII_EN BIT(13) /* 1: enable RMII (overrides EPIT) */
+
+/* Generic system control EMAC_CLK bits */
+#define SYSCON_ETXDC_MASK GENMASK(2, 0)
+#define SYSCON_ETXDC_SHIFT 10
+#define SYSCON_ERXDC_MASK GENMASK(4, 0)
+#define SYSCON_ERXDC_SHIFT 5
+/* EMAC PHY Interface Type */
+#define SYSCON_EPIT BIT(2) /* 1: RGMII, 0: MII */
+#define SYSCON_ETCS_MASK GENMASK(1, 0)
+#define SYSCON_ETCS_MII 0x0
+#define SYSCON_ETCS_EXT_GMII 0x1
+#define SYSCON_ETCS_INT_GMII 0x2
+#define SYSCON_EMAC_REG 0x30
+
+static int sun8i_emac_set_syscon(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct device_node *node = priv->dev->of_node;
+ int ret;
+ u32 reg, val;
+
+ reg = priv->variant->default_syscon_value;
+
+ if (priv->variant->internal_phy) {
+ if (!priv->use_internal_phy) {
+ /* switch to external PHY interface */
+ reg &= ~H3_EPHY_SELECT;
+ } else {
+ reg |= H3_EPHY_SELECT;
+ reg &= ~H3_EPHY_SHUTDOWN;
+
+ if (of_property_read_bool(priv->phy_node,
+ "allwinner,leds-active-low"))
+ reg |= H3_EPHY_LED_POL;
+
+ ret = of_mdio_parse_addr(priv->dev, priv->phy_node);
+ if (ret < 0) {
+ netdev_err(ndev, "Could not parse MDIO addr\n");
+ return ret;
+ }
+ /* of_mdio_parse_addr returns a valid (0 ~ 31) PHY
+ * address. No need to mask it again.
+ */
+ reg |= ret << H3_EPHY_ADDR_SHIFT;
+ }
+ }
+
+ if (!of_property_read_u32(node, "allwinner,tx-delay", &val)) {
+ if (val <= SYSCON_ETXDC_MASK) {
+ reg &= ~(SYSCON_ETXDC_MASK << SYSCON_ETXDC_SHIFT);
+ reg |= (val << SYSCON_ETXDC_SHIFT);
+ } else {
+ netdev_warn(ndev, "Invalid TX clock delay: %d\n", val);
+ }
+ }
+
+ if (!of_property_read_u32(node, "allwinner,rx-delay", &val)) {
+ if (val <= SYSCON_ERXDC_MASK) {
+ reg &= ~(SYSCON_ERXDC_MASK << SYSCON_ERXDC_SHIFT);
+ reg |= (val << SYSCON_ERXDC_SHIFT);
+ } else {
+ netdev_warn(ndev, "Invalid RX clock delay: %d\n", val);
+ }
+ }
+
+ /* Clear interface mode bits */
+ reg &= ~(SYSCON_ETCS_MASK | SYSCON_EPIT);
+ if (priv->variant->support_rmii)
+ reg &= ~SYSCON_RMII_EN;
+
+ switch (priv->phy_interface) {
+ case PHY_INTERFACE_MODE_MII:
+ /* default */
+ break;
+ case PHY_INTERFACE_MODE_RGMII:
+ reg |= SYSCON_EPIT | SYSCON_ETCS_INT_GMII;
+ break;
+ case PHY_INTERFACE_MODE_RMII:
+ reg |= SYSCON_RMII_EN | SYSCON_ETCS_EXT_GMII;
+ break;
+ default:
+ netdev_err(ndev, "Unsupported interface mode: %s",
+ phy_modes(priv->phy_interface));
+ return -EINVAL;
+ }
+
+ regmap_write(priv->regmap, SYSCON_EMAC_REG, reg);
+
+ return 0;
+}
+
+static void sun8i_emac_unset_syscon(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 reg = priv->variant->default_syscon_value;
+
+ regmap_write(priv->regmap, SYSCON_EMAC_REG, reg);
+}
+
+/* Set Management Data Clock, must be call after device reset */
+static void sun8i_emac_set_mdc(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ unsigned long rate;
+ u32 reg;
+
+ rate = clk_get_rate(priv->ahb_clk);
+ if (rate > 160000000)
+ reg = 0x3 << 20; /* AHB / 128 */
+ else if (rate > 80000000)
+ reg = 0x2 << 20; /* AHB / 64 */
+ else if (rate > 40000000)
+ reg = 0x1 << 20; /* AHB / 32 */
+ else
+ reg = 0x0 << 20; /* AHB / 16 */
+ netif_dbg(priv, link, ndev, "MDC auto : %x\n", reg);
+ writel(reg, priv->base + EMAC_MDIO_CMD);
+}
+
+/* "power" the device, by enabling clk/reset/regulators */
+static int sun8i_emac_power(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ int ret;
+
+ ret = clk_prepare_enable(priv->ahb_clk);
+ if (ret) {
+ netdev_err(ndev, "Could not enable AHB clock\n");
+ return ret;
+ }
+
+ if (priv->rst_mac) {
+ ret = reset_control_deassert(priv->rst_mac);
+ if (ret) {
+ netdev_err(ndev, "Could not deassert reset\n");
+ goto err_reset;
+ }
+ }
+
+ if (priv->ephy_clk) {
+ ret = clk_prepare_enable(priv->ephy_clk);
+ if (ret) {
+ netdev_err(ndev, "Could not enable EPHY clock\n");
+ goto err_ephy_clk;
+ }
+ }
+
+ if (priv->rst_ephy) {
+ ret = reset_control_deassert(priv->rst_ephy);
+ if (ret) {
+ netdev_err(ndev, "Could not deassert EPHY reset\n");
+ goto err_ephy_reset;
+ }
+ }
+
+ return 0;
+
+err_ephy_reset:
+ if (priv->ephy_clk)
+ clk_disable_unprepare(priv->ephy_clk);
+err_ephy_clk:
+ if (priv->rst_mac)
+ reset_control_assert(priv->rst_mac);
+err_reset:
+ clk_disable_unprepare(priv->ahb_clk);
+ return ret;
+}
+
+/* "Unpower" the device, disabling clocks and regulators, asserting reset */
+static void sun8i_emac_unpower(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ if (priv->rst_ephy)
+ reset_control_assert(priv->rst_ephy);
+
+ if (priv->ephy_clk)
+ clk_disable_unprepare(priv->ephy_clk);
+
+ if (priv->rst_mac)
+ reset_control_assert(priv->rst_mac);
+
+ clk_disable_unprepare(priv->ahb_clk);
+}
+
+static int sun8i_emac_init(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct device_node *node = priv->dev->of_node;
+ const u8 *addr;
+
+ /* Try to get MAC address from DT, or assign a random one */
+ addr = of_get_mac_address(node);
+ if (addr)
+ ether_addr_copy(ndev->dev_addr, addr);
+ else
+ eth_hw_addr_random(ndev);
+
+ return 0;
+}
+
+static int sun8i_emac_mdio_probe(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct phy_device *phydev = NULL;
+
+ phydev = of_phy_connect(ndev, priv->phy_node, &sun8i_emac_adjust_link,
+ 0, priv->phy_interface);
+
+ if (!phydev) {
+ netdev_err(ndev, "Could not attach to PHY\n");
+ return -ENODEV;
+ }
+
+ phy_attached_info(phydev);
+
+ /* mask with MAC supported features */
+ phydev->supported &= PHY_GBIT_FEATURES;
+ phydev->advertising = phydev->supported;
+
+ priv->link = 0;
+ priv->speed = 0;
+ priv->duplex = -1;
+
+ return 0;
+}
+
+/* Allocate both RX and TX ring buffer and init them
+ * This function also write the startbase of thoses ring in the device.
+ * All structures that help managing thoses rings are also handled
+ * by this functions (rx_skb/txl)
+ */
+static int sun8i_emac_alloc_rings(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct dma_desc *ddesc;
+ int err, i;
+
+ priv->rx_skb = kcalloc(priv->nbdesc_rx, sizeof(struct sk_buff *),
+ GFP_KERNEL);
+ if (!priv->rx_skb) {
+ err = -ENOMEM;
+ goto rx_skb_error;
+ }
+ priv->txl = kcalloc(priv->nbdesc_tx, sizeof(struct txinfo), GFP_KERNEL);
+ if (!priv->txl) {
+ err = -ENOMEM;
+ goto tx_error;
+ }
+
+ /* allocate/init RX ring */
+ priv->dd_rx = dma_zalloc_coherent(priv->dev,
+ priv->nbdesc_rx * sizeof(struct dma_desc),
+ &priv->dd_rx_phy, GFP_KERNEL);
+ if (!priv->dd_rx) {
+ dev_err(priv->dev, "ERROR: cannot allocate DMA RX buffer");
+ err = -ENOMEM;
+ goto dma_rx_error;
+ }
+ ddesc = priv->dd_rx;
+ for (i = 0; i < priv->nbdesc_rx; i++) {
+ sun8i_emac_rx_skb(ndev, i);
+ ddesc->next = cpu_to_le32(priv->dd_rx_phy + (i + 1)
+ * sizeof(struct dma_desc));
+ ddesc++;
+ }
+ /* last descriptor point back to first one */
+ ddesc--;
+ ddesc->next = cpu_to_le32(priv->dd_rx_phy);
+
+ /* allocate/init TX ring */
+ priv->dd_tx = dma_zalloc_coherent(priv->dev,
+ priv->nbdesc_tx * sizeof(struct dma_desc),
+ &priv->dd_tx_phy, GFP_KERNEL);
+ if (!priv->dd_tx) {
+ dev_err(priv->dev, "ERROR: cannot allocate DMA TX buffer");
+ err = -ENOMEM;
+ goto dma_tx_error;
+ }
+ ddesc = priv->dd_tx;
+ for (i = 0; i < priv->nbdesc_tx; i++) {
+ ddesc->status = DCLEAN;
+ ddesc->ctl = 0;
+ ddesc->next = cpu_to_le32(priv->dd_tx_phy + (i + 1)
+ * sizeof(struct dma_desc));
+ ddesc++;
+ }
+ /* last descriptor point back to first one */
+ ddesc--;
+ ddesc->next = cpu_to_le32(priv->dd_tx_phy);
+ i--;
+
+ priv->tx_slot = 0;
+ priv->tx_dirty = 0;
+ priv->rx_dirty = 0;
+
+ /* write start of RX ring descriptor */
+ writel(priv->dd_rx_phy, priv->base + EMAC_RX_DESC_LIST);
+ /* write start of TX ring descriptor */
+ writel(priv->dd_tx_phy, priv->base + EMAC_TX_DESC_LIST);
+
+ return 0;
+dma_tx_error:
+ dma_free_coherent(priv->dev, priv->nbdesc_rx * sizeof(struct dma_desc),
+ priv->dd_rx, priv->dd_rx_phy);
+dma_rx_error:
+ kfree(priv->txl);
+tx_error:
+ kfree(priv->rx_skb);
+rx_skb_error:
+ return err;
+}
+
+static int sun8i_emac_open(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ int err;
+ u32 v;
+
+ err = sun8i_emac_power(ndev);
+ if (err)
+ return err;
+
+ err = request_irq(priv->irq, sun8i_emac_dma_interrupt, 0,
+ dev_name(priv->dev), ndev);
+ if (err) {
+ dev_err(priv->dev, "Cannot request IRQ: %d\n", err);
+ goto err_power;
+ }
+
+ /* Set interface mode (and configure internal PHY on H3) */
+ err = sun8i_emac_set_syscon(ndev);
+ if (err)
+ goto err_irq;
+
+ /* Do SOFT RST */
+ v = readl(priv->base + EMAC_BASIC_CTL1);
+ writel(v | 0x01, priv->base + EMAC_BASIC_CTL1);
+
+ err = readl_poll_timeout(priv->base + EMAC_BASIC_CTL1, v,
+ !(v & 0x01), 100, 10000);
+ if (err) {
+ dev_err(priv->dev, "EMAC reset timeout\n");
+ err = -EFAULT;
+ goto err_syscon;
+ }
+
+ sun8i_emac_set_mdc(ndev);
+
+ err = sun8i_emac_mdio_register(ndev);
+ if (err)
+ goto err_syscon;
+
+ err = sun8i_emac_mdio_probe(ndev);
+ if (err)
+ goto err_syscon;
+
+ /* DMA */
+ v = (8 << 24);/* burst len */
+ writel(v, priv->base + EMAC_BASIC_CTL1);
+
+ writel(EMAC_RX_INT | EMAC_TX_INT, priv->base + EMAC_INT_EN);
+
+ v = readl(priv->base + EMAC_RX_CTL0);
+ /* CHECK_CRC */
+ if (ndev->features & NETIF_F_RXCSUM)
+ v |= EMAC_RX_DO_CRC;
+ else
+ v &= ~EMAC_RX_DO_CRC;
+ /* STRIP_FCS */
+ if (ndev->features & NETIF_F_RXFCS)
+ v &= ~EMAC_RX_STRIP_FCS;
+ else
+ v |= EMAC_RX_STRIP_FCS;
+ writel(v, priv->base + EMAC_RX_CTL0);
+
+ v = readl(priv->base + EMAC_TX_CTL1);
+ /* TX_MD Transmission starts after a full frame located in TX DMA FIFO*/
+ v |= BIT(1);
+ /* Undocumented bit (called TX_NEXT_FRM in BSP), the original comment is
+ * "Operating on second frame increase the performance
+ * especially when transmit store-and-forward is used."
+ */
+ v |= BIT(2);
+ writel(v, priv->base + EMAC_TX_CTL1);
+
+ v = readl(priv->base + EMAC_RX_CTL1);
+ /* RX_MD RX DMA reads data from RX DMA FIFO to host memory after a
+ * complete frame has been written to RX DMA FIFO
+ */
+ v |= BIT(1);
+ writel(v, priv->base + EMAC_RX_CTL1);
+
+ sun8i_emac_set_macaddr(priv, ndev->dev_addr, 0);
+
+ err = sun8i_emac_alloc_rings(ndev);
+ if (err) {
+ netdev_err(ndev, "Fail to allocate rings\n");
+ goto err_mdio;
+ }
+
+ phy_start(ndev->phydev);
+
+ sun8i_emac_start_rx(ndev);
+ sun8i_emac_start_tx(ndev);
+
+ netif_napi_add(ndev, &priv->napi, sun8i_emac_poll, 64);
+ napi_enable(&priv->napi);
+ netif_start_queue(ndev);
+
+ return 0;
+err_mdio:
+ phy_disconnect(ndev->phydev);
+err_syscon:
+ sun8i_emac_unset_syscon(ndev);
+err_irq:
+ free_irq(priv->irq, ndev);
+err_power:
+ sun8i_emac_unpower(ndev);
+ return err;
+}
+
+/* Clean the TX ring of any accepted skb for xmit */
+static void sun8i_emac_tx_clean(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ int i;
+ struct dma_desc *ddesc;
+ int frame_len;
+
+ for (i = 0; i < priv->nbdesc_tx; i++) {
+ if (priv->txl[i].skb) {
+ ddesc = priv->dd_tx + i;
+ frame_len = le32_to_cpu(ddesc->ctl) & 0x3FFF;
+ switch (priv->txl[i].map) {
+ case MAP_SINGLE:
+ dma_unmap_single(priv->dev,
+ le32_to_cpu(ddesc->buf_addr),
+ frame_len, DMA_TO_DEVICE);
+ break;
+ case MAP_PAGE:
+ dma_unmap_page(priv->dev,
+ le32_to_cpu(ddesc->buf_addr),
+ frame_len, DMA_TO_DEVICE);
+ break;
+ default:
+ dev_err(priv->dev, "Trying to free an empty slot\n");
+ continue;
+ }
+ dev_kfree_skb_any(priv->txl[i].skb);
+ priv->txl[i].skb = NULL;
+ ddesc->ctl = 0;
+ ddesc->status = DCLEAN;
+ }
+ }
+ priv->tx_slot = 0;
+ priv->tx_dirty = 0;
+}
+
+/* Clean the RX ring */
+static void sun8i_emac_rx_clean(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ int i;
+ struct dma_desc *ddesc;
+
+ /* clean RX ring */
+ for (i = 0; i < priv->nbdesc_rx; i++)
+ if (priv->rx_skb[i]) {
+ ddesc = priv->dd_rx + i;
+ dma_unmap_single(priv->dev,
+ le32_to_cpu(ddesc->buf_addr),
+ DESC_BUF_MAX, DMA_FROM_DEVICE);
+ dev_kfree_skb_any(priv->rx_skb[i]);
+ priv->rx_skb[i] = NULL;
+ }
+}
+
+static int sun8i_emac_stop(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ napi_disable(&priv->napi);
+
+ sun8i_emac_stop_tx(ndev);
+ sun8i_emac_stop_rx(ndev);
+
+ phy_stop(ndev->phydev);
+ phy_disconnect(ndev->phydev);
+
+ sun8i_emac_mdio_unregister(ndev);
+
+ sun8i_emac_unset_syscon(ndev);
+
+ free_irq(priv->irq, ndev);
+
+ sun8i_emac_rx_clean(ndev);
+ sun8i_emac_tx_clean(ndev);
+
+ kfree(priv->rx_skb);
+ kfree(priv->txl);
+
+ dma_free_coherent(priv->dev, priv->nbdesc_rx * sizeof(struct dma_desc),
+ priv->dd_rx, priv->dd_rx_phy);
+ dma_free_coherent(priv->dev, priv->nbdesc_tx * sizeof(struct dma_desc),
+ priv->dd_tx, priv->dd_tx_phy);
+
+ sun8i_emac_unpower(ndev);
+
+ return 0;
+}
+
+static netdev_tx_t sun8i_emac_xmit(struct sk_buff *skb, struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct dma_desc *ddesc;
+ struct dma_desc *first;
+ int i = 0, rbd_first;
+ unsigned int len, fraglen, tlen;
+ u32 v;
+ int n;
+ int nf;
+ const skb_frag_t *frag;
+ int do_csum = 0;
+
+ if (skb_put_padto(skb, ETH_ZLEN))
+ return NETDEV_TX_OK;
+ len = skb_headlen(skb);
+
+ n = skb_shinfo(skb)->nr_frags;
+
+ if (skb->ip_summed == CHECKSUM_PARTIAL) {
+ do_csum = 1;
+ priv->estats.tx_hw_csum++;
+ }
+ netif_dbg(priv, tx_queued, ndev, "%s len=%u skblen=%u %x\n", __func__,
+ len, skb->len,
+ (skb->ip_summed == CHECKSUM_PARTIAL));
+
+ /* check for contigous space
+ * We need at least 1(skb->data) + n(numfrags) + 1(one clean slot)
+ */
+ if (rb_tx_numfreedesc(ndev) < n + 2) {
+ dev_err_ratelimited(priv->dev, "BUG!: TX is full %d %d\n",
+ priv->tx_dirty, priv->tx_slot);
+ netif_stop_queue(ndev);
+ return NETDEV_TX_BUSY;
+ }
+ i = priv->tx_slot;
+
+ ddesc = priv->dd_tx + i;
+ first = priv->dd_tx + i;
+ rbd_first = i;
+
+ ddesc->buf_addr = dma_map_single(priv->dev, skb->data, len,
+ DMA_TO_DEVICE);
+ if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
+ dev_err(priv->dev, "ERROR: Cannot map buffer for DMA\n");
+ goto xmit_error;
+ }
+ /* We cannot direcly use cpu_to_le32() after dma_map_single
+ * since dma_mapping_error use it
+ */
+ ddesc->buf_addr = cpu_to_le32(ddesc->buf_addr);
+ priv->txl[i].map = MAP_SINGLE;
+ priv->txl[i].skb = skb;
+
+ tlen = len;
+ ddesc->ctl = le32_to_cpu(len);
+ /* Undocumented bit that make it works
+ * Without it, packets never be sent on H3 SoC
+ */
+ ddesc->ctl |= EMAC_MAGIC_TX_BIT;
+ if (do_csum)
+ ddesc->ctl |= EMAC_TX_DO_CRC;
+
+ /* handle fragmented skb, one descriptor per fragment */
+ for (nf = 0; nf < n; nf++) {
+ frag = &skb_shinfo(skb)->frags[nf];
+ rb_inc(&i, priv->nbdesc_tx);
+ priv->txl[i].skb = skb;
+ ddesc = priv->dd_tx + i;
+ fraglen = skb_frag_size(frag);
+ ddesc->ctl = le32_to_cpu(fraglen);
+ tlen += fraglen,
+ ddesc->ctl |= EMAC_MAGIC_TX_BIT;
+ if (do_csum)
+ ddesc->ctl |= EMAC_TX_DO_CRC;
+
+ ddesc->buf_addr = skb_frag_dma_map(priv->dev, frag, 0,
+ fraglen, DMA_TO_DEVICE);
+ if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
+ dev_err(priv->dev, "Cannot map buffer for DMA\n");
+ goto xmit_error;
+ }
+ /* Cannot directly use cpu_to_le32() after skb_frag_dma_map
+ * since dma_mapping_error use it
+ */
+ ddesc->buf_addr = cpu_to_le32(ddesc->buf_addr);
+ priv->txl[i].map = MAP_PAGE;
+ ddesc->status = EMAC_COULD_BE_USED_BY_DMA;
+ }
+
+ /* frame end */
+ ddesc->ctl |= EMAC_DSC_TX_LAST;
+ /* We want an interrupt after transmission */
+ ddesc->ctl |= EMAC_WANT_INT;
+
+ rb_inc(&i, priv->nbdesc_tx);
+
+ /* This line was previously after DMA start, but with that we hit a
+ * small race with complete_xmit() where we complete more data than
+ * sent.
+ * The packet is sent just after EMAC_COULD_BE_USED_BY_DMA flag set and
+ * complete_xmit fire just after before netdev_sent_queue().
+ * This race could be observed only when overflowing a gigabit line.
+ */
+ netdev_sent_queue(ndev, skb->len);
+
+ /* frame begin */
+ first->ctl |= EMAC_DSC_TX_FIRST;
+ wmb();/* EMAC_COULD_BE_USED_BY_DMA must be the last value written */
+ first->status = EMAC_COULD_BE_USED_BY_DMA;
+ priv->tx_slot = i;
+
+ /* Trying to optimize this (recording DMA start/stop) seems
+ * to lead to errors. So we always start DMA.
+ */
+ v = readl(priv->base + EMAC_TX_CTL1);
+ v |= EMAC_TX_DMA_START;
+ v |= EMAC_TX_DMA_EN;
+ writel_relaxed(v, priv->base + EMAC_TX_CTL1);
+
+ if (rb_tx_numfreedesc(ndev) < MAX_SKB_FRAGS + 1) {
+ netif_stop_queue(ndev);
+ priv->estats.tx_stop_queue++;
+ }
+ priv->estats.tx_used_desc = rb_tx_numfreedesc(ndev);
+ priv->ndev->stats.tx_packets++;
+ priv->ndev->stats.tx_bytes += tlen;
+
+ return NETDEV_TX_OK;
+
+xmit_error:
+ /* destroy skb and return TX OK Documentation/DMA-API-HOWTO.txt */
+ /* clean descritors from rbd_first to i */
+ ddesc->ctl = 0;
+ /* setting status to DCLEAN is the last value to be set */
+ wmb();
+ ddesc->status = DCLEAN;
+ do {
+ ddesc = priv->dd_tx + rbd_first;
+ ddesc->ctl = 0;
+ /* setting status to DCLEAN is the last value to be set */
+ wmb();
+ ddesc->status = DCLEAN;
+ rb_inc(&rbd_first, priv->nbdesc_tx);
+ } while (rbd_first != i);
+ dev_kfree_skb_any(skb);
+ return NETDEV_TX_OK;
+}
+
+static int sun8i_emac_change_mtu(struct net_device *ndev, int new_mtu)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ int max_mtu;
+
+ dev_info(priv->dev, "%s set MTU to %d\n", __func__, new_mtu);
+
+ if (netif_running(ndev)) {
+ dev_err(priv->dev, "%s: must be stopped to change its MTU\n",
+ ndev->name);
+ return -EBUSY;
+ }
+
+ max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
+
+ if ((new_mtu < 68) || (new_mtu > max_mtu)) {
+ dev_err(priv->dev, "%s: invalid MTU, max MTU is: %d\n",
+ ndev->name, max_mtu);
+ return -EINVAL;
+ }
+
+ ndev->mtu = new_mtu;
+ netdev_update_features(ndev);
+ return 0;
+}
+
+static int sun8i_emac_set_features(struct net_device *ndev,
+ netdev_features_t features)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 v;
+
+ v = readl(priv->base + EMAC_BASIC_CTL0);
+ if (features & NETIF_F_LOOPBACK && netif_running(ndev)) {
+ netif_info(priv, hw, ndev, "Set loopback features");
+ v |= BIT(1);
+ } else {
+ netif_info(priv, hw, ndev, "Unset loopback features");
+ v &= ~BIT(1);
+ }
+ writel(v, priv->base + EMAC_BASIC_CTL0);
+
+ v = readl(priv->base + EMAC_RX_CTL0);
+ if (features & NETIF_F_RXCSUM) {
+ v |= EMAC_RX_DO_CRC;
+ netif_info(priv, hw, ndev, "Doing RX CRC check by hardware");
+ } else {
+ v &= ~EMAC_RX_DO_CRC;
+ netif_info(priv, hw, ndev, "No RX CRC check by hardware");
+ }
+ if (features & NETIF_F_RXFCS) {
+ v &= ~EMAC_RX_STRIP_FCS;
+ netif_info(priv, hw, ndev, "Keep FCS");
+ } else {
+ v |= EMAC_RX_STRIP_FCS;
+ netif_info(priv, hw, ndev, "Strip FCS");
+ }
+ writel(v, priv->base + EMAC_RX_CTL0);
+
+ netif_dbg(priv, drv, ndev, "%s %llx %x\n", __func__, features, v);
+
+ return 0;
+}
+
+static void sun8i_emac_set_rx_mode(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 v = 0;
+ int i = 0;
+ struct netdev_hw_addr *ha;
+
+ /* Receive all multicast frames */
+ v |= BIT(16);
+ /* Receive all control frames */
+ v |= BIT(13);
+ if (ndev->flags & IFF_PROMISC)
+ v |= BIT(1);
+ if (netdev_uc_count(ndev) > 7) {
+ v |= BIT(1);
+ } else {
+ netdev_for_each_uc_addr(ha, ndev) {
+ i++;
+ sun8i_emac_set_macaddr(priv, ha->addr, i);
+ }
+ }
+ writel(v, priv->base + EMAC_RX_FRM_FLT);
+}
+
+static void sun8i_emac_tx_timeout(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ netdev_err(ndev, "%s\n", __func__);
+
+ sun8i_emac_stop_tx(ndev);
+
+ sun8i_emac_tx_clean(ndev);
+
+ /* write start of the new TX ring descriptor */
+ writel(priv->dd_tx_phy, priv->base + EMAC_TX_DESC_LIST);
+
+ sun8i_emac_start_tx(ndev);
+
+ netdev_reset_queue(ndev);
+
+ priv->estats.tx_timeout++;
+ ndev->stats.tx_errors++;
+ netif_wake_queue(ndev);
+}
+
+static int sun8i_emac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
+{
+ struct phy_device *phydev = ndev->phydev;
+
+ if (!netif_running(ndev))
+ return -EINVAL;
+
+ if (!phydev)
+ return -ENODEV;
+
+ return phy_mii_ioctl(phydev, rq, cmd);
+}
+
+static int sun8i_emac_check_if_running(struct net_device *ndev)
+{
+ if (!netif_running(ndev))
+ return -EINVAL;
+ return 0;
+}
+
+static int sun8i_emac_get_sset_count(struct net_device *ndev, int sset)
+{
+ switch (sset) {
+ case ETH_SS_STATS:
+ return ARRAY_SIZE(estats_str);
+ }
+ return -EOPNOTSUPP;
+}
+
+static int sun8i_emac_ethtool_get_settings(struct net_device *ndev,
+ struct ethtool_cmd *cmd)
+{
+ struct phy_device *phy = ndev->phydev;
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ if (!phy) {
+ netdev_err(ndev, "%s: %s: PHY is not registered\n",
+ __func__, ndev->name);
+ return -ENODEV;
+ }
+
+ if (!netif_running(ndev)) {
+ dev_err(priv->dev, "interface disabled: we cannot track link speed / duplex setting\n");
+ return -EBUSY;
+ }
+
+ return phy_ethtool_gset(phy, cmd);
+}
+
+static int sun8i_emac_ethtool_set_settings(struct net_device *ndev,
+ struct ethtool_cmd *cmd)
+{
+ struct phy_device *phy = ndev->phydev;
+
+ return phy_ethtool_sset(phy, cmd);
+}
+
+static void sun8i_emac_ethtool_getdrvinfo(struct net_device *ndev,
+ struct ethtool_drvinfo *info)
+{
+ strlcpy(info->driver, "sun8i_emac", sizeof(info->driver));
+ strcpy(info->version, "00");
+ info->fw_version[0] = '\0';
+}
+
+static void sun8i_emac_ethtool_stats(struct net_device *ndev,
+ struct ethtool_stats *dummy, u64 *data)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ memcpy(data, &priv->estats,
+ sun8i_emac_get_sset_count(ndev, ETH_SS_STATS) * sizeof(u64));
+}
+
+static void sun8i_emac_ethtool_strings(struct net_device *dev, u32 stringset,
+ u8 *buffer)
+{
+ switch (stringset) {
+ case ETH_SS_STATS:
+ memcpy(buffer, &estats_str, sizeof(estats_str));
+ break;
+ }
+}
+
+static u32 sun8i_emac_ethtool_getmsglevel(struct net_device *ndev)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ return priv->msg_enable;
+}
+
+static void sun8i_emac_ethtool_setmsglevel(struct net_device *ndev, u32 level)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ priv->msg_enable = level;
+}
+
+static void sun8i_emac_get_pauseparam(struct net_device *ndev,
+ struct ethtool_pauseparam *pause)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ pause->rx_pause = 0;
+ pause->tx_pause = 0;
+ pause->autoneg = ndev->phydev->autoneg;
+
+ if (priv->flow_ctrl & EMAC_FLOW_RX)
+ pause->rx_pause = 1;
+ if (priv->flow_ctrl & EMAC_FLOW_TX)
+ pause->tx_pause = 1;
+}
+
+static int sun8i_emac_set_pauseparam(struct net_device *ndev,
+ struct ethtool_pauseparam *pause)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ struct phy_device *phy = ndev->phydev;
+ int new_pause = 0;
+ int ret = 0;
+
+ if (pause->rx_pause)
+ new_pause |= EMAC_FLOW_RX;
+ if (pause->tx_pause)
+ new_pause |= EMAC_FLOW_TX;
+
+ priv->flow_ctrl = new_pause;
+ phy->autoneg = pause->autoneg;
+
+ if (phy->autoneg) {
+ if (netif_running(ndev))
+ ret = phy_start_aneg(phy);
+ } else {
+ sun8i_emac_flow_ctrl(priv, phy->duplex, priv->flow_ctrl);
+ }
+ return ret;
+}
+
+static void sun8i_emac_ethtool_get_ringparam(struct net_device *ndev,
+ struct ethtool_ringparam *ring)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+
+ ring->rx_pending = priv->nbdesc_rx;
+ ring->tx_pending = priv->nbdesc_tx;
+}
+
+static int sun8i_emac_ethtool_set_ringparam(struct net_device *ndev,
+ struct ethtool_ringparam *ring)
+{
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ int err;
+
+ if (ring->rx_max_pending || ring->rx_mini_max_pending ||
+ ring->rx_jumbo_max_pending || ring->rx_mini_pending ||
+ ring->rx_jumbo_pending || ring->tx_max_pending)
+ return -EINVAL;
+
+ if (ring->tx_pending < MAX_SKB_FRAGS + 1) {
+ netdev_err(ndev, "The number of TX descriptors is too low");
+ return -EINVAL;
+ }
+
+ sun8i_emac_stop_tx(ndev);
+ sun8i_emac_stop_rx(ndev);
+
+ sun8i_emac_rx_clean(ndev);
+ sun8i_emac_tx_clean(ndev);
+
+ kfree(priv->rx_skb);
+ kfree(priv->txl);
+
+ dma_free_coherent(priv->dev, priv->nbdesc_rx * sizeof(struct dma_desc),
+ priv->dd_rx, priv->dd_rx_phy);
+ dma_free_coherent(priv->dev, priv->nbdesc_tx * sizeof(struct dma_desc),
+ priv->dd_tx, priv->dd_tx_phy);
+
+ priv->nbdesc_rx = ring->rx_pending;
+ priv->nbdesc_tx = ring->tx_pending;
+ err = sun8i_emac_alloc_rings(ndev);
+ if (err) {
+ /* Fatal error, we cannot re start */
+ netdev_err(ndev, "Fail to allocate rings\n");
+ return -EFAULT;
+ }
+
+ sun8i_emac_start_rx(ndev);
+ sun8i_emac_start_tx(ndev);
+
+ netif_start_queue(ndev);
+
+ netdev_info(ndev, "Ring Param settings: rx: %d, tx %d\n",
+ ring->rx_pending, ring->tx_pending);
+ return 0;
+}
+
+static const struct ethtool_ops sun8i_emac_ethtool_ops = {
+ .begin = sun8i_emac_check_if_running,
+ .get_settings = sun8i_emac_ethtool_get_settings,
+ .set_settings = sun8i_emac_ethtool_set_settings,
+ .get_link = ethtool_op_get_link,
+ .get_pauseparam = sun8i_emac_get_pauseparam,
+ .set_pauseparam = sun8i_emac_set_pauseparam,
+ .get_ethtool_stats = sun8i_emac_ethtool_stats,
+ .get_strings = sun8i_emac_ethtool_strings,
+ .get_sset_count = sun8i_emac_get_sset_count,
+ .get_drvinfo = sun8i_emac_ethtool_getdrvinfo,
+ .get_msglevel = sun8i_emac_ethtool_getmsglevel,
+ .set_msglevel = sun8i_emac_ethtool_setmsglevel,
+ .get_ringparam = sun8i_emac_ethtool_get_ringparam,
+ .set_ringparam = sun8i_emac_ethtool_set_ringparam,
+};
+
+static const struct net_device_ops sun8i_emac_netdev_ops = {
+ .ndo_init = sun8i_emac_init,
+ .ndo_open = sun8i_emac_open,
+ .ndo_start_xmit = sun8i_emac_xmit,
+ .ndo_stop = sun8i_emac_stop,
+ .ndo_change_mtu = sun8i_emac_change_mtu,
+ .ndo_set_features = sun8i_emac_set_features,
+ .ndo_set_rx_mode = sun8i_emac_set_rx_mode,
+ .ndo_tx_timeout = sun8i_emac_tx_timeout,
+ .ndo_do_ioctl = sun8i_emac_ioctl,
+ .ndo_set_mac_address = eth_mac_addr,
+};
+
+/* No locking in this function since it is guaranteed to be run once and
+ * do actions only done here:
+ * - Scheduling NAPI
+ * - Stopping interrupts
+ * - Updating stats
+ *
+ * Even when not enabled via EMAC_INT_EN, some interrupt could fire, so we need
+ * to handle all of them.
+ * Interrupts know to fire when not enabled are:
+ * - EMAC_TX_DMA_STOP_INT
+ * - EMAC_TX_BUF_UA_INT
+ * - EMAC_TX_EARLY_INT
+ * - EMAC_RX_BUF_UA_INT
+ * - EMAC_RX_EARLY_INT
+ */
+static irqreturn_t sun8i_emac_dma_interrupt(int irq, void *dev_id)
+{
+ struct net_device *ndev = dev_id;
+ struct sun8i_emac_priv *priv = netdev_priv(ndev);
+ u32 v, u;
+
+ v = readl(priv->base + EMAC_INT_STA);
+
+ /* When this bit is asserted, a frame transmission is completed. */
+ if (v & EMAC_TX_INT) {
+ priv->estats.tx_int++;
+ writel(0, priv->base + EMAC_INT_EN);
+ napi_schedule(&priv->napi);
+ }
+
+ /* When this bit is asserted, the TX DMA FSM is stopped.
+ * For the moment only a call to tx_timeout cause this interrupt
+ * to fire.
+ */
+ if (v & EMAC_TX_DMA_STOP_INT)
+ priv->estats.tx_dma_stop++;
+
+ /* When this asserted, the TX DMA can not acquire next TX descriptor
+ * and TX DMA FSM is suspended.
+ */
+ if (v & EMAC_TX_BUF_UA_INT) {
+ priv->estats.tx_dma_ua++;
+ writel(0, priv->base + EMAC_INT_EN);
+ napi_schedule(&priv->napi);
+ }
+
+ if (v & EMAC_TX_TIMEOUT_INT)
+ priv->estats.tx_timeout_int++;
+
+ if (v & EMAC_TX_UNDERFLOW_INT)
+ priv->estats.tx_underflow_int++;
+
+ /* When this bit asserted , the frame is transmitted to FIFO totally. */
+ if (v & EMAC_TX_EARLY_INT)
+ priv->estats.tx_early_int++;
+
+ /* When this bit is asserted, a frame reception is completed */
+ if (v & EMAC_RX_INT) {
+ priv->estats.rx_int++;
+ writel(0, priv->base + EMAC_INT_EN);
+ napi_schedule(&priv->napi);
+ }
+
+ /* When this asserted, the RX DMA can not acquire next RX descriptor
+ * and RX DMA FSM is suspended.
+ */
+ if (v & EMAC_RX_BUF_UA_INT) {
+ u = readl(priv->base + EMAC_RX_CTL1);
+ writel(u | EMAC_RX_DMA_START, priv->base + EMAC_RX_CTL1);
+ priv->estats.rx_dma_ua++;
+ }
+
+ /* Same as TX DMA STOP, but never hit it */
+ if (v & EMAC_RX_DMA_STOP_INT)
+ priv->estats.rx_dma_stop++;
+
+ if (v & EMAC_RX_TIMEOUT_INT)
+ priv->estats.rx_timeout_int++;
+
+ if (v & EMAC_RX_OVERFLOW_INT)
+ priv->estats.rx_overflow_int++;
+
+ if (v & EMAC_RX_EARLY_INT)
+ priv->estats.rx_early_int++;
+
+ if (v & EMAC_RGMII_STA_INT)
+ priv->estats.rgmii_state_int++;
+
+ /* the datasheet state those register as read-only
+ * but nothing work(freeze) without writing to it
+ */
+ writel(v, priv->base + EMAC_INT_STA);
+
+ return IRQ_HANDLED;
+}
+
+static int sun8i_emac_probe(struct platform_device *pdev)
+{
+ struct device_node *node = pdev->dev.of_node;
+ struct sun8i_emac_priv *priv;
+ struct net_device *ndev;
+ struct resource *res;
+ int ret;
+
+ ndev = alloc_etherdev(sizeof(*priv));
+ if (!ndev)
+ return -ENOMEM;
+
+ SET_NETDEV_DEV(ndev, &pdev->dev);
+ priv = netdev_priv(ndev);
+ platform_set_drvdata(pdev, ndev);
+
+ priv->variant = of_device_get_match_data(&pdev->dev);
+ if (!priv->variant) {
+ dev_err(&pdev->dev, "Missing sun8i-emac variant\n");
+ return -EINVAL;
+ }
+
+ priv->mdio_node = of_get_child_by_name(node, "mdio");
+ if (!priv->mdio_node) {
+ netdev_err(ndev, "Could not find a MDIO node\n");
+ return -EINVAL;
+ }
+
+ priv->phy_node = of_parse_phandle(node, "phy-handle", 0);
+ if (!priv->phy_node) {
+ netdev_err(ndev, "No associated PHY\n");
+ return -EINVAL;
+ }
+
+ priv->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
+ "syscon");
+ if (IS_ERR(priv->regmap)) {
+ ret = PTR_ERR(priv->regmap);
+ dev_err(&pdev->dev, "unable to map SYSCON:%d\n", ret);
+ return ret;
+ }
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ priv->base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(priv->base)) {
+ ret = PTR_ERR(priv->base);
+ dev_err(&pdev->dev, "Cannot request MMIO: %d\n", ret);
+ return ret;
+ }
+
+ priv->ahb_clk = devm_clk_get(&pdev->dev, "ahb");
+ if (IS_ERR(priv->ahb_clk)) {
+ ret = PTR_ERR(priv->ahb_clk);
+ dev_err(&pdev->dev, "Cannot get AHB clock err=%d\n", ret);
+ goto probe_err;
+ }
+
+ priv->rst_mac = devm_reset_control_get_optional(&pdev->dev, "ahb");
+ if (IS_ERR(priv->rst_mac)) {
+ ret = PTR_ERR(priv->rst_mac);
+ if (ret == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ dev_info(&pdev->dev, "No MAC reset control found %d\n", ret);
+ priv->rst_mac = NULL;
+ }
+
+ priv->phy_interface = of_get_phy_mode(node);
+ if (priv->phy_interface < 0) {
+ netdev_err(ndev, "PHY interface mode node unspecified\n");
+ return priv->phy_interface;
+ }
+
+ switch (priv->phy_interface) {
+ case PHY_INTERFACE_MODE_MII:
+ if (!priv->variant->support_mii)
+ return -EINVAL;
+ break;
+ case PHY_INTERFACE_MODE_RMII:
+ if (!priv->variant->support_rmii)
+ return -EINVAL;
+ break;
+ case PHY_INTERFACE_MODE_RGMII:
+ if (!priv->variant->support_rgmii)
+ return -EINVAL;
+ break;
+ default:
+ netdev_err(ndev, "Unsupported interface mode: %s",
+ phy_modes(priv->phy_interface));
+ return -EINVAL;
+ }
+
+ if (priv->phy_interface == priv->variant->internal_phy)
+ priv->use_internal_phy = true;
+
+ if (priv->use_internal_phy) {
+ priv->ephy_clk = of_clk_get(priv->phy_node, 0);
+ if (IS_ERR(priv->ephy_clk)) {
+ ret = PTR_ERR(priv->ephy_clk);
+ dev_err(&pdev->dev, "Cannot get EPHY clock err=%d\n",
+ ret);
+ goto probe_err;
+ }
+
+ priv->rst_ephy = of_reset_control_get(priv->phy_node, 0);
+ if (IS_ERR(priv->rst_ephy)) {
+ ret = PTR_ERR(priv->rst_ephy);
+ if (ret == -EPROBE_DEFER)
+ goto probe_err;
+ dev_info(&pdev->dev,
+ "No EPHY reset control found %d\n", ret);
+ priv->rst_ephy = NULL;
+ }
+ }
+
+ priv->irq = platform_get_irq(pdev, 0);
+ if (priv->irq < 0) {
+ ret = priv->irq;
+ dev_err(&pdev->dev, "Cannot claim IRQ: %d\n", ret);
+ goto probe_err;
+ }
+
+ spin_lock_init(&priv->tx_lock);
+
+ ndev->netdev_ops = &sun8i_emac_netdev_ops;
+ ndev->ethtool_ops = &sun8i_emac_ethtool_ops;
+
+ priv->ndev = ndev;
+ priv->dev = &pdev->dev;
+
+ ndev->hw_features = NETIF_F_SG | NETIF_F_HIGHDMA;
+ ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
+ NETIF_F_RXCSUM;
+ ndev->features |= ndev->hw_features;
+ ndev->hw_features |= NETIF_F_RXFCS;
+ ndev->hw_features |= NETIF_F_RXALL;
+ ndev->hw_features |= NETIF_F_LOOPBACK;
+ ndev->priv_flags |= IFF_UNICAST_FLT;
+
+ ndev->watchdog_timeo = msecs_to_jiffies(5000);
+ netif_carrier_off(ndev);
+
+ /* Benched on OPIPC with 100M, setting more than 256 does not give any
+ * perf boost
+ */
+ priv->nbdesc_rx = 128;
+ priv->nbdesc_tx = 256;
+
+ ret = register_netdev(ndev);
+ if (ret) {
+ dev_err(&pdev->dev, "ERROR: Register %s failed\n", ndev->name);
+ goto probe_err;
+ }
+
+ return 0;
+
+probe_err:
+ free_netdev(ndev);
+ return ret;
+}
+
+static int sun8i_emac_remove(struct platform_device *pdev)
+{
+ struct net_device *ndev = platform_get_drvdata(pdev);
+
+ unregister_netdev(ndev);
+ platform_set_drvdata(pdev, NULL);
+ free_netdev(ndev);
+
+ return 0;
+}
+
+static const struct of_device_id sun8i_emac_of_match_table[] = {
+ { .compatible = "allwinner,sun8i-a83t-emac",
+ .data = &emac_variant_a83t },
+ { .compatible = "allwinner,sun8i-h3-emac",
+ .data = &emac_variant_h3 },
+ { .compatible = "allwinner,sun50i-a64-emac",
+ .data = &emac_variant_a64 },
+ {}
+};
+MODULE_DEVICE_TABLE(of, sun8i_emac_of_match_table);
+
+static struct platform_driver sun8i_emac_driver = {
+ .probe = sun8i_emac_probe,
+ .remove = sun8i_emac_remove,
+ .driver = {
+ .name = "sun8i-emac",
+ .of_match_table = sun8i_emac_of_match_table,
+ },
+};
+
+module_platform_driver(sun8i_emac_driver);
+
+MODULE_DESCRIPTION("sun8i Ethernet driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Corentin Labbe <clabbe.montjoie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org");
--
2.7.3
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related
* [PATCH v4 05/10] ARM: dts: sun8i-h3: add sun8i-emac ethernet driver
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: netdev, Corentin Labbe, linux-kernel, linux-arm-kernel,
devicetree
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
The sun8i-emac is an ethernet MAC hardware that support 10/100/1000
speed.
This patch enable the sun8i-emac on the Allwinner H3 SoC Device-tree.
The SoC H3 have an internal PHY, so optionals syscon and ephy are set.
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
arch/arm/boot/dts/sun8i-h3.dtsi | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 1101d2f..d218154 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -446,6 +446,30 @@
status = "disabled";
};
+ emac: ethernet@1c30000 {
+ compatible = "allwinner,sun8i-h3-emac";
+ syscon = <&syscon>;
+ reg = <0x01c30000 0x104>;
+ interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>;
+ resets = <&ccu RST_BUS_EMAC>;
+ reset-names = "ahb";
+ clocks = <&ccu CLK_BUS_EMAC>;
+ clock-names = "ahb";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "disabled";
+
+ mdio: mdio {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ int_mii_phy: ethernet-phy@1 {
+ reg = <1>;
+ clocks = <&ccu CLK_BUS_EPHY>;
+ resets = <&ccu RST_BUS_EPHY>;
+ };
+ };
+ };
+
gic: interrupt-controller@01c81000 {
compatible = "arm,cortex-a7-gic", "arm,cortex-a15-gic";
reg = <0x01c81000 0x1000>,
--
2.7.3
^ permalink raw reply related
* [PATCH v4 06/10] ARM: dts: sun8i: Enable sun8i-emac on the Orange PI PC
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: netdev, Corentin Labbe, linux-kernel, linux-arm-kernel,
devicetree
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
The sun8i-emac hardware is present on the Orange PI PC.
It uses the internal PHY.
This patch create the needed emac node.
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
index daf50b9a6..71717cc 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts
@@ -54,6 +54,7 @@
aliases {
serial0 = &uart0;
+ ethernet0 = &emac;
};
chosen {
@@ -165,3 +166,10 @@
/* USB VBUS is always on */
status = "okay";
};
+
+&emac {
+ phy-handle = <&int_mii_phy>;
+ phy-mode = "mii";
+ allwinner,leds-active-low;
+ status = "okay";
+};
--
2.7.3
^ permalink raw reply related
* [PATCH v4 07/10] ARM: dts: sun8i: Enable sun8i-emac on the Orange PI One
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: devicetree, netdev, linux-kernel, Hans de Goede, Corentin Labbe,
linux-arm-kernel
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
From: Hans de Goede <hdegoede@redhat.com>
The sun8i-emac hardware is present on the Orange PI One.
It uses the internal PHY.
This patch create the needed emac node.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
arch/arm/boot/dts/sun8i-h3-orangepi-one.dts | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
index 0adf932..25f2455 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
@@ -54,6 +54,7 @@
aliases {
serial0 = &uart0;
+ ethernet0 = &emac;
};
chosen {
@@ -94,6 +95,13 @@
status = "okay";
};
+&emac {
+ phy-handle = <&int_mii_phy>;
+ phy-mode = "mii";
+ allwinner,leds-active-low;
+ status = "okay";
+};
+
&mmc0 {
pinctrl-names = "default";
pinctrl-0 = <&mmc0_pins_a>, <&mmc0_cd_pin>;
--
2.7.3
^ permalink raw reply related
* [PATCH v4 08/10] ARM: dts: sun8i: Enable sun8i-emac on the Orange Pi 2
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
Corentin Labbe
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
The sun8i-emac hardware is present on the Orange PI 2.
It uses the internal PHY.
This patch create the needed emac node.
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
arch/arm/boot/dts/sun8i-h3-orangepi-2.dts | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-2.dts b/arch/arm/boot/dts/sun8i-h3-orangepi-2.dts
index f93f5d1..5608eb4 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-2.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-2.dts
@@ -54,6 +54,7 @@
aliases {
serial0 = &uart0;
+ ethernet0 = &emac;
};
chosen {
@@ -184,3 +185,10 @@
usb1_vbus-supply = <®_usb1_vbus>;
status = "okay";
};
+
+&emac {
+ phy-handle = <&int_mii_phy>;
+ phy-mode = "mii";
+ allwinner,leds-active-low;
+ status = "okay";
+};
--
2.7.3
^ permalink raw reply related
* [PATCH v4 10/10] ARM: sunxi: Enable sun8i-emac driver on multi_v7_defconfig
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
Corentin Labbe
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
Enable the sun8i-emac driver in the multi_v7 default configuration
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
arch/arm/configs/multi_v7_defconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index 5845910..f44d633 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -229,6 +229,7 @@ CONFIG_NETDEVICES=y
CONFIG_VIRTIO_NET=y
CONFIG_HIX5HD2_GMAC=y
CONFIG_SUN4I_EMAC=y
+CONFIG_SUN8I_EMAC=y
CONFIG_MACB=y
CONFIG_BCMGENET=m
CONFIG_SYSTEMPORT=m
--
2.7.3
^ permalink raw reply related
* [PATCH v4 03/10] ARM: sun8i: dt: Add DT bindings documentation for Allwinner sun8i-emac
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
Corentin Labbe
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
This patch adds documentation for Device-Tree bindings for the
Allwinner sun8i-emac driver.
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
.../bindings/net/allwinner,sun8i-emac.txt | 70 ++++++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
diff --git a/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt b/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
new file mode 100644
index 0000000..92e4ef3b
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
@@ -0,0 +1,70 @@
+* Allwinner sun8i EMAC ethernet controller
+
+Required properties:
+- compatible: should be one of the following string:
+ "allwinner,sun8i-a83t-emac"
+ "allwinner,sun8i-h3-emac"
+ "allwinner,sun50i-a64-emac"
+- reg: address and length of the register for the device.
+- syscon: A phandle to the syscon of the SoC
+- interrupts: interrupt for the device
+- clocks: A phandle to the reference clock for this device
+- clock-names: should be "ahb"
+- resets: A phandle to the reset control for this device
+- reset-names: should be "ahb"
+- phy-mode: See ethernet.txt
+- phy-handle: See ethernet.txt
+- #address-cells: shall be 1
+- #size-cells: shall be 0
+
+Optional properties:
+- allwinner,tx-delay: TX clock delay chain value. Range value is 0-0x07. Default is 0)
+- allwinner,rx-delay: RX clock delay chain value. Range value is 0-0x1F. Default is 0)
+Both delay properties does not have units, there are arbitrary value.
+The TX/RX clock delay chain settings are board specific and could be found
+in vendor FEX files.
+
+Optional properties for "allwinner,sun8i-h3-emac":
+- allwinner,leds-active-low: EPHY LEDs are active low
+
+Required child node of emac:
+- mdio bus node: should be named mdio
+
+Required properties of the mdio node:
+- #address-cells: shall be 1
+- #size-cells: shall be 0
+
+The device node referenced by "phy" or "phy-handle" should be a child node
+of the mdio node. See phy.txt for the generic PHY bindings.
+
+Required properties of the phy node with "allwinner,sun8i-h3-emac":
+- clocks: an extra phandle to the reference clock for the EPHY
+- resets: an extra phandle to the reset control for the EPHY
+
+Example:
+
+emac: ethernet@01c0b000 {
+ compatible = "allwinner,sun8i-h3-emac";
+ syscon = <&syscon>;
+ reg = <0x01c0b000 0x104>;
+ interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>;
+ resets = <&ccu RST_BUS_EMAC>;
+ reset-names = "ahb";
+ clocks = <&ccu CLK_BUS_EMAC>;
+ clock-names = "ahb";
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ phy = <&int_mii_phy>;
+ phy-mode = "mii";
+ allwinner,leds-active-low;
+ mdio: mdio {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ int_mii_phy: ethernet-phy@1 {
+ reg = <1>;
+ clocks = <&ccu CLK_BUS_EPHY>;
+ resets = <&ccu RST_BUS_EPHY>;
+ };
+ };
+};
--
2.7.3
^ permalink raw reply related
* [PATCH v4 02/10] MAINTAINERS: Add myself as maintainer of sun8i-emac
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
Corentin Labbe
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
This patch add myself as maintainer of the sun8i-emac driver.
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
MAINTAINERS | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 40f4629..e197d82 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -582,6 +582,12 @@ S: Maintained
F: Documentation/i2c/busses/i2c-ali1563
F: drivers/i2c/busses/i2c-ali1563.c
+ALLWINNER SUN8I-EMAC ETHERNET DRIVER
+M: Corentin Labbe <clabbe.montjoie@gmail.com>
+L: netdev@vger.kernel.org
+S: Maintained
+F: drivers/net/ethernet/allwinner/sun8i-emac.c
+
ALLWINNER SECURITY SYSTEM
M: Corentin Labbe <clabbe.montjoie@gmail.com>
L: linux-crypto@vger.kernel.org
--
2.7.3
^ permalink raw reply related
* [PATCH v4 04/10] ARM: dts: sun8i-h3: Add dt node for the syscon control module
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
Corentin Labbe
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
This patch add the dt node for the syscon register present on the
Allwinner H3.
Only two register are present in this syscon and the only one useful is
the one dedicated to EMAC clock.
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
arch/arm/boot/dts/sun8i-h3.dtsi | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 8a95e36..1101d2f 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -140,6 +140,11 @@
#size-cells = <1>;
ranges;
+ syscon: syscon@01c00000 {
+ compatible = "syscon";
+ reg = <0x01c00000 0x1000>;
+ };
+
dma: dma-controller@01c02000 {
compatible = "allwinner,sun8i-h3-dma";
reg = <0x01c02000 0x1000>;
--
2.7.3
^ permalink raw reply related
* [PATCH v4 09/10] ARM: sunxi: Enable sun8i-emac driver on sunxi_defconfig
From: Corentin Labbe @ 2016-10-07 8:25 UTC (permalink / raw)
To: robh+dt, mark.rutland, maxime.ripard, wens, linux, davem,
f.fainelli, andrew
Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
Corentin Labbe
In-Reply-To: <1475828757-926-1-git-send-email-clabbe.montjoie@gmail.com>
Enable the sun8i-emac driver in the sunxi default configuration
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
arch/arm/configs/sunxi_defconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/configs/sunxi_defconfig b/arch/arm/configs/sunxi_defconfig
index 714da33..153707a 100644
--- a/arch/arm/configs/sunxi_defconfig
+++ b/arch/arm/configs/sunxi_defconfig
@@ -40,6 +40,7 @@ CONFIG_ATA=y
CONFIG_AHCI_SUNXI=y
CONFIG_NETDEVICES=y
CONFIG_SUN4I_EMAC=y
+CONFIG_SUN8I_EMAC=y
# CONFIG_NET_VENDOR_ARC is not set
# CONFIG_NET_CADENCE is not set
# CONFIG_NET_VENDOR_BROADCOM is not set
--
2.7.3
^ permalink raw reply related
* [PATCH net-next v9 1/1] net: phy: Cleanup the Edge-Rate feature in Microsemi PHYs.
From: Allan W. Nielsen @ 2016-10-07 8:28 UTC (permalink / raw)
To: netdev; +Cc: andrew, f.fainelli, raju.lakkaraju, allan.nielsen
In-Reply-To: <1475828904-13839-1-git-send-email-allan.nielsen@microsemi.com>
Edge-Rate cleanup include the following:
- Updated device tree bindings documentation for edge-rate
- The edge-rate is now specified as a "slowdown", meaning that it is now
being specified as positive values instead of negative (both
documentation and implementation wise).
- Only explicitly documented values for "vsc8531,vddmac" and
"vsc8531,edge-slowdown" are accepted by the device driver.
- Deleting include/dt-bindings/net/mscc-phy-vsc8531.h as it was not needed.
Signed-off-by: Allan W. Nielsen <allan.nielsen@microsemi.com>
Signed-off-by: Raju Lakkaraju <raju.lakkaraju@microsemi.com>
---
.../devicetree/bindings/net/mscc-phy-vsc8531.txt | 49 ++++++++------
drivers/net/phy/mscc.c | 79 +++++++++++++---------
include/dt-bindings/net/mscc-phy-vsc8531.h | 21 ------
3 files changed, 75 insertions(+), 74 deletions(-)
delete mode 100644 include/dt-bindings/net/mscc-phy-vsc8531.h
diff --git a/Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt b/Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt
index 99c7eb0..f552033 100644
--- a/Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt
+++ b/Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt
@@ -6,20 +6,27 @@ Required properties:
Documentation/devicetree/bindings/net/phy.txt
Optional properties:
-- vsc8531,vddmac : The vddmac in mV.
+- vsc8531,vddmac : The vddmac in mV. Allowed values is listed
+ in the first row of Table 1 (below).
+ This property is only used in combination
+ with the 'edge-slowdown' property.
+ Default value is 3300.
- vsc8531,edge-slowdown : % the edge should be slowed down relative to
- the fastest possible edge time. Native sign
- need not enter.
+ the fastest possible edge time.
Edge rate sets the drive strength of the MAC
- interface output signals. Changing the drive
- strength will affect the edge rate of the output
- signal. The goal of this setting is to help
- reduce electrical emission (EMI) by being able
- to reprogram drive strength and in effect slow
- down the edge rate if desired. Table 1 shows the
- impact to the edge rate per VDDMAC supply for each
- drive strength setting.
- Ref: Table:1 - Edge rate change below.
+ interface output signals. Changing the
+ drive strength will affect the edge rate of
+ the output signal. The goal of this setting
+ is to help reduce electrical emission (EMI)
+ by being able to reprogram drive strength
+ and in effect slow down the edge rate if
+ desired.
+ To adjust the edge-slowdown, the 'vddmac'
+ must be specified. Table 1 lists the
+ supported edge-slowdown values for a given
+ 'vddmac'.
+ Default value is 0%.
+ Ref: Table:1 - Edge rate change (below).
Note: see dt-bindings/net/mscc-phy-vsc8531.h for applicable values
@@ -29,23 +36,23 @@ Table: 1 - Edge rate change
| |
| 3300 mV 2500 mV 1800 mV 1500 mV |
|---------------------------------------------------------------|
-| Default Deafult Default Default |
+| 0% 0% 0% 0% |
| (Fastest) (recommended) (recommended) |
|---------------------------------------------------------------|
-| -2% -3% -5% -6% |
+| 2% 3% 5% 6% |
|---------------------------------------------------------------|
-| -4% -6% -9% -14% |
+| 4% 6% 9% 14% |
|---------------------------------------------------------------|
-| -7% -10% -16% -21% |
+| 7% 10% 16% 21% |
|(recommended) (recommended) |
|---------------------------------------------------------------|
-| -10% -14% -23% -29% |
+| 10% 14% 23% 29% |
|---------------------------------------------------------------|
-| -17% -23% -35% -42% |
+| 17% 23% 35% 42% |
|---------------------------------------------------------------|
-| -29% -37% -52% -58% |
+| 29% 37% 52% 58% |
|---------------------------------------------------------------|
-| -53% -63% -76% -77% |
+| 53% 63% 76% 77% |
| (slowest) |
|---------------------------------------------------------------|
@@ -54,5 +61,5 @@ Example:
vsc8531_0: ethernet-phy@0 {
compatible = "ethernet-phy-id0007.0570";
vsc8531,vddmac = <3300>;
- vsc8531,edge-slowdown = <21>;
+ vsc8531,edge-slowdown = <7>;
};
diff --git a/drivers/net/phy/mscc.c b/drivers/net/phy/mscc.c
index a17573e..2bd00b6 100644
--- a/drivers/net/phy/mscc.c
+++ b/drivers/net/phy/mscc.c
@@ -12,7 +12,6 @@
#include <linux/mii.h>
#include <linux/phy.h>
#include <linux/of.h>
-#include <dt-bindings/net/mscc-phy-vsc8531.h>
enum rgmii_rx_clock_delay {
RGMII_RX_CLK_DELAY_0_2_NS = 0,
@@ -56,21 +55,27 @@ enum rgmii_rx_clock_delay {
#define PHY_ID_VSC8531 0x00070570
#define PHY_ID_VSC8541 0x00070770
-struct edge_rate_table {
+#define MSCC_VDDMAC_1500 1500
+#define MSCC_VDDMAC_1800 1800
+#define MSCC_VDDMAC_2500 2500
+#define MSCC_VDDMAC_3300 3300
+
+struct vsc8531_edge_rate_table {
u16 vddmac;
- int slowdown[MSCC_SLOWDOWN_MAX];
+ u8 slowdown[8];
};
-struct edge_rate_table edge_table[MSCC_VDDMAC_MAX] = {
- {3300, { 0, -2, -4, -7, -10, -17, -29, -53} },
- {2500, { 0, -3, -6, -10, -14, -23, -37, -63} },
- {1800, { 0, -5, -9, -16, -23, -35, -52, -76} },
- {1500, { 0, -6, -14, -21, -29, -42, -58, -77} },
+static const struct vsc8531_edge_rate_table edge_table[] = {
+ {MSCC_VDDMAC_3300, { 0, 2, 4, 7, 10, 17, 29, 53} },
+ {MSCC_VDDMAC_2500, { 0, 3, 6, 10, 14, 23, 37, 63} },
+ {MSCC_VDDMAC_1800, { 0, 5, 9, 16, 23, 35, 52, 76} },
+ {MSCC_VDDMAC_1500, { 0, 6, 14, 21, 29, 42, 58, 77} },
};
struct vsc8531_private {
u8 edge_slowdown;
u16 vddmac;
+ int rate_magic;
};
static int vsc85xx_phy_page_set(struct phy_device *phydev, u8 page)
@@ -81,29 +86,21 @@ static int vsc85xx_phy_page_set(struct phy_device *phydev, u8 page)
return rc;
}
-static u8 edge_rate_magic_get(u16 vddmac,
- int slowdown)
+static int vsc85xx_edge_rate_magic_get(u16 vddmac, u8 slowdown)
{
- int rc = (MSCC_SLOWDOWN_MAX - 1);
u8 vdd;
u8 sd;
-
- for (vdd = 0; vdd < MSCC_VDDMAC_MAX; vdd++) {
- if (edge_table[vdd].vddmac == vddmac) {
- for (sd = 0; sd < MSCC_SLOWDOWN_MAX; sd++) {
- if (edge_table[vdd].slowdown[sd] <= slowdown) {
- rc = (MSCC_SLOWDOWN_MAX - sd - 1);
- break;
- }
- }
- }
- }
-
- return rc;
+ u8 sd_array_size = ARRAY_SIZE(edge_table[0].slowdown);
+
+ for (vdd = 0; vdd < ARRAY_SIZE(edge_table); vdd++)
+ if (edge_table[vdd].vddmac == vddmac)
+ for (sd = 0; sd < sd_array_size; sd++)
+ if (edge_table[vdd].slowdown[sd] == slowdown)
+ return (sd_array_size - sd - 1);
+ return -EINVAL;
}
-static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev,
- u8 edge_rate)
+static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev, u8 edge_rate)
{
int rc;
u16 reg_val;
@@ -199,17 +196,38 @@ static int vsc8531_of_init(struct phy_device *phydev)
&vsc8531->vddmac);
if (rc == -EINVAL)
vsc8531->vddmac = MSCC_VDDMAC_3300;
+
rc = of_property_read_u8(of_node, "vsc8531,edge-slowdown",
&vsc8531->edge_slowdown);
if (rc == -EINVAL)
vsc8531->edge_slowdown = 0;
- rc = 0;
- return rc;
+ vsc8531->rate_magic = vsc85xx_edge_rate_magic_get(
+ vsc8531->vddmac, vsc8531->edge_slowdown);
+ if (vsc8531->rate_magic < 0) {
+ phydev_err(phydev,
+ "Invalid vsc8531,vddmac or vsc8531,edge-slowdown");
+ return vsc8531->rate_magic;
+ }
+
+ return 0;
}
#else
static int vsc8531_of_init(struct phy_device *phydev)
{
+ struct vsc8531_private *vsc8531 = phydev->priv;
+
+ vsc8531->vddmac = MSCC_VDDMAC_3300;
+ vsc8531->edge_slowdown = 0;
+
+ vsc8531->rate_magic = vsc85xx_edge_rate_magic_get(
+ vsc8531->vddmac, vsc8531->edge_slowdown);
+ if (vsc8531->rate_magic < 0) {
+ phydev_err(phydev,
+ "Invalid vsc8531,vddmac or vsc8531,edge-slowdown");
+ return vsc8531->rate_magic;
+ }
+
return 0;
}
#endif /* CONFIG_OF_MDIO */
@@ -218,7 +236,6 @@ static int vsc85xx_config_init(struct phy_device *phydev)
{
int rc;
struct vsc8531_private *vsc8531 = phydev->priv;
- u8 edge_rate;
rc = vsc8531_of_init(phydev);
if (rc)
@@ -232,9 +249,7 @@ static int vsc85xx_config_init(struct phy_device *phydev)
if (rc)
return rc;
- edge_rate = edge_rate_magic_get(vsc8531->vddmac,
- -(int)vsc8531->edge_slowdown);
- rc = vsc85xx_edge_rate_cntl_set(phydev, edge_rate);
+ rc = vsc85xx_edge_rate_cntl_set(phydev, vsc8531->rate_magic);
if (rc)
return rc;
diff --git a/include/dt-bindings/net/mscc-phy-vsc8531.h b/include/dt-bindings/net/mscc-phy-vsc8531.h
deleted file mode 100644
index 2383dd2..0000000
--- a/include/dt-bindings/net/mscc-phy-vsc8531.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Device Tree constants for Microsemi VSC8531 PHY
- *
- * Author: Nagaraju Lakkaraju
- *
- * License: Dual MIT/GPL
- * Copyright (c) 2016 Microsemi Corporation
- */
-
-#ifndef _DT_BINDINGS_MSCC_VSC8531_H
-#define _DT_BINDINGS_MSCC_VSC8531_H
-
-/* MAC interface Edge rate control VDDMAC in milli Volts */
-#define MSCC_VDDMAC_3300 3300
-#define MSCC_VDDMAC_2500 2500
-#define MSCC_VDDMAC_1800 1800
-#define MSCC_VDDMAC_1500 1500
-#define MSCC_VDDMAC_MAX 4
-#define MSCC_SLOWDOWN_MAX 8
-
-#endif
--
2.7.3
^ permalink raw reply related
* [PATCH net-next v9 0/1] net: phy: Cleanup the Edge-Rate feature in Microsemi PHYs
From: Allan W. Nielsen @ 2016-10-07 8:28 UTC (permalink / raw)
To: netdev; +Cc: andrew, f.fainelli, raju.lakkaraju, allan.nielsen
Hi Andrew (and other),
Raju and I have been going through all the comments received on the edge-rate
feature, and tried to address them (once again...).
The patch is rebased to fit on top of net-next (it depends on a4cc96d1f).
Following initiatives is covered:
- Updated device tree bindings documentation for edge-rate
- The edge-rate is now specified as a "slowdown", meaning that it is now
being specified as positive values instead of negative (both
documentation and implementation wise).
- Only explicitly documented values for "vsc8531,vddmac" and
"vsc8531,edge-slowdown" are accepted by the device driver.
- Deleting include/dt-bindings/net/mscc-phy-vsc8531.h as it was not needed.
- Initialize to default values when CONFIG_OF_MDIO is not defined
- Using ARRAY_SIZE when iterating through an array.
Please review.
Best regards
Allan W. Nielsen
^ permalink raw reply
* [PATCH v2 net] xen-netback: make sure that hashes are not send to unaware frontends
From: Paul Durrant @ 2016-10-07 8:32 UTC (permalink / raw)
To: netdev, xen-devl; +Cc: Paul Durrant, Wei Liu
In the case when a frontend only negotiates a single queue with xen-
netback it is possible for a skbuff with a s/w hash to result in a
hash extra_info segment being sent to the frontend even when no hash
algorithm has been configured. (The ndo_select_queue() entry point makes
sure the hash is not set if no algorithm is configured, but this entry
point is not called when there is only a single queue). This can result
in a frontend that is unable to handle extra_info segments being given
such a segment, causing it to crash.
This patch fixes the problem by clearing the hash in ndo_start_xmit()
instead, which is clearly guaranteed to be called irrespective of the
number of queues.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
v2:
- Simplified and re-based onto re-factored net branch
---
drivers/net/xen-netback/interface.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 4af532a..74dc2bf 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -149,17 +149,8 @@ static u16 xenvif_select_queue(struct net_device *dev, struct sk_buff *skb,
struct xenvif *vif = netdev_priv(dev);
unsigned int size = vif->hash.size;
- if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE) {
- u16 index = fallback(dev, skb) % dev->real_num_tx_queues;
-
- /* Make sure there is no hash information in the socket
- * buffer otherwise it would be incorrectly forwarded
- * to the frontend.
- */
- skb_clear_hash(skb);
-
- return index;
- }
+ if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE)
+ return fallback(dev, skb) % dev->real_num_tx_queues;
xenvif_set_skb_hash(vif, skb);
@@ -208,6 +199,13 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
cb = XENVIF_RX_CB(skb);
cb->expires = jiffies + vif->drain_timeout;
+ /* If there is no hash algorithm configured then make sure there
+ * is no hash information in the socket buffer otherwise it
+ * would be incorrectly forwarded to the frontend.
+ */
+ if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE)
+ skb_clear_hash(skb);
+
xenvif_rx_queue_tail(queue, skb);
xenvif_kick_thread(queue);
--
2.1.4
^ permalink raw reply related
* Re: Kernel 4.6.7-rt13: Intel Ethernet driver igb causes huge latencies in cyclictest
From: Koehrer Mathias (ETAS/ESW5) @ 2016-10-07 8:58 UTC (permalink / raw)
To: Williams, Mitch A, Julia Cartwright, Kirsher, Jeffrey T, Greg
Cc: netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org,
linux-rt-users@vger.kernel.org, Sebastian Andrzej Siewior
In-Reply-To: <AAEA33E297BCAC4B9BB20A7C2DF0AB8D8045E418@FMSMSX113.amr.corp.intel.com>
Hi Mitch,
> > >
> > > Although, to be clear, it isn't the fact that there exists 8
> > > threads, it's
> > that the device is
> > > firing all 8 interrupts at the same time. The time spent in hardirq
> > context just waking
> > > up all 8 of those threads (and the cyclictest wakeup) is enough to
> > > cause
> > your
> > > regression.
> > >
> > > netdev/igb folks-
> > >
> > > Under what conditions should it be expected that the i350 trigger
> > > all of
> > the TxRx
> > > interrupts simultaneously? Any ideas here?
>
> I can answer that! I wrote that code.
>
> We trigger the interrupts once a second because MSI and MSI-X interrupts are NOT
> guaranteed to be delivered. If this happens, the queues being serviced by this "lost"
> interrupt are completely stuck.
>
> The device automatically masks each interrupt vector after it fires, expecting the
> ISR to re-enable the vector after processing is complete. If the interrupt is lost, the
> ISR doesn't run, so the vector ends up permanently masked. At this point, any
> queues associated with that vector are stuck. The only recovery is through the
> netdev watchdog, which initiates a reset.
>
> During development of igb, we had several platforms with chipsets that routinely
> dropped MSI messages under stress. Things would be running fine and then, pow,
> all the traffic on a queue would stop.
>
> So, I added code to fire each vector once per second. Just unmasking the interrupt
> isn't enough - we need to trigger the ISR to get the queues cleaned up so the device
> can work again.
>
> Is this workaround still needed? I don't know. Modern chipsets don't break a sweat
> handling gigabit-speed traffic, and they *probably* don't drop interrupts. But I'd still
> rather have that insurance.
>
> You could try to remove the write to the EICS registers in the watchdog task to see if
> that takes care of your problem. But I wouldn't want to remove that code
> permanently, because we have seen lost interrupts in the past.
>
> You also could try staggering the writes so that not all vectors fire each second. But
> then you'll potentially incur a much longer delay if an interrupt does get lost, which
> means you could trigger netdev watchdog events.
>
> -Mitch
Thanks for the explanation. Now I have switched over to kernel 4.8-rt1.
This shows the very same effect.
I modified the in-kernel's igb_main.c (function igb_watchdog_task) to comment out
the access to the EICS registers:
--- igb_main.c.orig 2016-10-07 10:43:37.855873754 +0200
+++ igb_main.c 2016-10-07 10:31:51.451346292 +0200
@@ -4613,6 +4613,7 @@ no_wait:
}
/* Cause software interrupt to ensure Rx ring is cleaned */
+#if 0
if (adapter->flags & IGB_FLAG_HAS_MSIX) {
u32 eics = 0;
@@ -4622,6 +4623,7 @@ no_wait:
} else {
wr32(E1000_ICS, E1000_ICS_RXDMT0);
}
+#endif
igb_spoof_check(adapter);
igb_ptp_rx_hang(adapter);
The result is now slighty better, however the max latency that has been measured by
cyclictest is still much higher compared to the values of kernel 3.18.27-rt27.
I have now enabled all events, the execution of
# cyclictest -a -i 105 -m -n -p 80 -t 1 -b 30 -C
delivers the following trace values
cyclicte-10062 0....... 10025813402us : sys_exit: NR 230 = 0
cyclicte-10062 0....... 10025813402us : sys_enter: NR 230 (1, 1, 7ffff73ff930, 0, 0, 2bd7e12e)
cyclicte-10062 0....... 10025813402us : hrtimer_init: hrtimer=ffff88040a017e18 clockid=CLOCK_MONOTONIC mode=HRTIMER_MODE_ABS
cyclicte-10062 0d...1.. 10025813403us : hrtimer_start: hrtimer=ffff88040a017e18 function=hrtimer_wakeup expires=10024735653388 softexpires=10024735653388
cyclicte-10062 0d...1.. 10025813403us : write_msr: 6e0, value 20ca630b9aef
cyclicte-10062 0d...1.. 10025813403us : rcu_utilization: Start context switch
cyclicte-10062 0d...1.. 10025813403us : rcu_utilization: End context switch
cyclicte-10062 0d...2.. 10025813404us : sched_switch: prev_comm=cyclictest prev_pid=10062 prev_prio=19 prev_state=S ==> next_comm=kworker/0:3 next_pid=1388 next_prio=120
cyclicte-10062 0d...2.. 10025813404us+: x86_fpu_regs_deactivated: x86/fpu: ffff88040c603ec0 fpregs_active: 0 fpstate_active: 1 counter: 69 xfeatures: 2 xcomp_bv: 0
kworker/-1388 0d..h... 10025813468us : irq_handler_entry: irq=48 name=eth2-tx-0
kworker/-1388 0d..h... 10025813468us : irq_handler_exit: irq=48 ret=handled
kworker/-1388 0d..h1.. 10025813469us : sched_waking: comm=irq/48-eth2-tx- pid=10057 prio=49 target_cpu=000
kworker/-1388 0dN.h2.. 10025813469us : sched_wakeup: comm=irq/48-eth2-tx- pid=10057 prio=49 target_cpu=000
kworker/-1388 0dN.h1.. 10025813470us : irq_handler_entry: irq=47 name=eth2-rx-0
kworker/-1388 0dN.h1.. 10025813470us : irq_handler_exit: irq=47 ret=handled
kworker/-1388 0dN.h2.. 10025813471us : sched_waking: comm=irq/47-eth2-rx- pid=10056 prio=49 target_cpu=000
kworker/-1388 0dN.h3.. 10025813471us : sched_wakeup: comm=irq/47-eth2-rx- pid=10056 prio=49 target_cpu=000
kworker/-1388 0dN..1.. 10025813472us : rcu_utilization: Start context switch
kworker/-1388 0dN..1.. 10025813472us : rcu_utilization: End context switch
kworker/-1388 0dN..2.. 10025813472us : sched_stat_runtime: comm=kworker/0:3 pid=1388 runtime=67566 [ns] vruntime=101216288332 [ns]
kworker/-1388 0d...2.. 10025813472us : sched_switch: prev_comm=kworker/0:3 prev_pid=1388 prev_prio=120 prev_state=R+ ==> next_comm=irq/48-eth2-tx- next_pid=10057 next_prio=49
irq/48-e-10057 0d....11 10025813473us : softirq_raise: vec=3 [action=NET_RX]
irq/48-e-10057 0.....12 10025813474us : softirq_entry: vec=3 [action=NET_RX]
irq/48-e-10057 0.....12 10025813475us : napi_poll: napi poll on napi struct ffff88040a582850 for device eth2 work 0 budget 64
irq/48-e-10057 0.....12 10025813475us : softirq_exit: vec=3 [action=NET_RX]
irq/48-e-10057 0d...1.. 10025813475us : rcu_utilization: Start context switch
irq/48-e-10057 0d...1.. 10025813476us : rcu_utilization: End context switch
irq/48-e-10057 0d...2.. 10025813476us : sched_switch: prev_comm=irq/48-eth2-tx- prev_pid=10057 prev_prio=49 prev_state=S ==> next_comm=irq/47-eth2-rx- next_pid=10056 next_prio=49
irq/47-e-10056 0d....11 10025813477us : softirq_raise: vec=3 [action=NET_RX]
irq/47-e-10056 0.....12 10025813477us : softirq_entry: vec=3 [action=NET_RX]
irq/47-e-10056 0.....12 10025813478us : napi_poll: napi poll on napi struct ffff88040a580850 for device eth2 work 0 budget 64
irq/47-e-10056 0.....12 10025813478us : softirq_exit: vec=3 [action=NET_RX]
irq/47-e-10056 0d...1.. 10025813479us : rcu_utilization: Start context switch
irq/47-e-10056 0d...1.. 10025813479us : rcu_utilization: End context switch
irq/47-e-10056 0d...2.. 10025813479us+: sched_switch: prev_comm=irq/47-eth2-rx- prev_pid=10056 prev_prio=49 prev_state=S ==> next_comm=kworker/0:3 next_pid=1388 next_prio=120
kworker/-1388 0d..h... 10025813516us : local_timer_entry: vector=239
kworker/-1388 0d..h1.. 10025813516us : hrtimer_interrupt: cpu=0 offset=-28999 curr=kworker/0:3[120] thread=cyclictest[19]
kworker/-1388 0d..h1.. 10025813517us : hrtimer_cancel: hrtimer=ffff88040a017e18
kworker/-1388 0d..h... 10025813517us : hrtimer_expire_entry: hrtimer=ffff88040a017e18 function=hrtimer_wakeup now=10024735682387
kworker/-1388 0d..h1.. 10025813517us : sched_waking: comm=cyclictest pid=10062 prio=19 target_cpu=000
kworker/-1388 0dN.h2.. 10025813517us : sched_wakeup: comm=cyclictest pid=10062 prio=19 target_cpu=000
kworker/-1388 0dN.h... 10025813517us : hrtimer_expire_exit: hrtimer=ffff88040a017e18
kworker/-1388 0dN.h1.. 10025813518us : hrtimer_interrupt: cpu=0 offset=317613 curr=kworker/0:3[120] thread=<none>[-1]
kworker/-1388 0dN.h... 10025813518us : write_msr: 6e0, value 20ca631e99f8
kworker/-1388 0dN.h... 10025813518us : local_timer_exit: vector=239
kworker/-1388 0dN..1.. 10025813518us : rcu_utilization: Start context switch
kworker/-1388 0dN..1.. 10025813518us : rcu_utilization: End context switch
kworker/-1388 0dN..2.. 10025813518us : sched_stat_runtime: comm=kworker/0:3 pid=1388 runtime=38173 [ns] vruntime=101216326505 [ns]
kworker/-1388 0d...2.. 10025813519us : sched_switch: prev_comm=kworker/0:3 prev_pid=1388 prev_prio=120 prev_state=R+ ==> next_comm=cyclictest next_pid=10062 next_prio=19
kworker/-1388 0d...2.. 10025813519us : x86_fpu_regs_activated: x86/fpu: ffff88040c603ec0 fpregs_active: 1 fpstate_active: 1 counter: 70 xfeatures: 2 xcomp_bv: 0
kworker/-1388 0d...2.. 10025813519us : write_msr: c0000100, value 7ffff7400700
cyclicte-10062 0....... 10025813519us : sys_exit: NR 230 = 0
cyclicte-10062 0....... 10025813524us : sys_enter: NR 1 (5, 7ffff7400300, 1f, 7ffff77a5460, 2, 7ffff744c99a)
cyclicte-10062 0.....11 10025813526us : tracing_mark_write: hit latency threshold (32 > 30)
cyclicte-10062 0....... 10025813526us : sys_exit: NR 1 = 31
cyclicte-10062 0....... 10025813527us : sys_enter: NR 1 (4, 4076b0, 2, 7ffff77a5460, 2, 7ffff744c99a)
Also, I notice that there is still roughly one irq every 2 seconds on irq/47 (eth2-rx-0) and irq/48 (eth2-tx-0).
Any idea or feedback on this?
Thanks
Mathias
^ permalink raw reply
* Re: [PATCH v2 net] xen-netback: make sure that hashes are not send to unaware frontends
From: Wei Liu @ 2016-10-07 9:07 UTC (permalink / raw)
To: Paul Durrant; +Cc: netdev, xen-devl, Wei Liu
In-Reply-To: <1475829151-3707-1-git-send-email-paul.durrant@citrix.com>
On Fri, Oct 07, 2016 at 09:32:31AM +0100, Paul Durrant wrote:
> In the case when a frontend only negotiates a single queue with xen-
> netback it is possible for a skbuff with a s/w hash to result in a
> hash extra_info segment being sent to the frontend even when no hash
> algorithm has been configured. (The ndo_select_queue() entry point makes
> sure the hash is not set if no algorithm is configured, but this entry
> point is not called when there is only a single queue). This can result
> in a frontend that is unable to handle extra_info segments being given
> such a segment, causing it to crash.
>
> This patch fixes the problem by clearing the hash in ndo_start_xmit()
> instead, which is clearly guaranteed to be called irrespective of the
> number of queues.
>
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
> ---
>
> v2:
> - Simplified and re-based onto re-factored net branch
> ---
> drivers/net/xen-netback/interface.c | 20 +++++++++-----------
> 1 file changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
> index 4af532a..74dc2bf 100644
> --- a/drivers/net/xen-netback/interface.c
> +++ b/drivers/net/xen-netback/interface.c
> @@ -149,17 +149,8 @@ static u16 xenvif_select_queue(struct net_device *dev, struct sk_buff *skb,
> struct xenvif *vif = netdev_priv(dev);
> unsigned int size = vif->hash.size;
>
> - if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE) {
> - u16 index = fallback(dev, skb) % dev->real_num_tx_queues;
> -
> - /* Make sure there is no hash information in the socket
> - * buffer otherwise it would be incorrectly forwarded
> - * to the frontend.
> - */
> - skb_clear_hash(skb);
> -
> - return index;
> - }
> + if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE)
> + return fallback(dev, skb) % dev->real_num_tx_queues;
>
> xenvif_set_skb_hash(vif, skb);
>
> @@ -208,6 +199,13 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
> cb = XENVIF_RX_CB(skb);
> cb->expires = jiffies + vif->drain_timeout;
>
> + /* If there is no hash algorithm configured then make sure there
> + * is no hash information in the socket buffer otherwise it
> + * would be incorrectly forwarded to the frontend.
> + */
> + if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE)
> + skb_clear_hash(skb);
> +
> xenvif_rx_queue_tail(queue, skb);
> xenvif_kick_thread(queue);
>
> --
> 2.1.4
>
^ permalink raw reply
* Re: [PATCH RFC 0/4] xfs: Transmit flow steering
From: Juerg Haefliger @ 2016-10-07 9:18 UTC (permalink / raw)
To: Rick Jones, Tom Herbert, davem, netdev; +Cc: kernel-team, Balliet, Drew
In-Reply-To: <7c278b6b-085c-e77c-ed77-0150e1718e7f@hpe.com>
[-- Attachment #1.1: Type: text/plain, Size: 7197 bytes --]
As Rick states, this fixes a performance issue with the 4.4 kernel for us.
Tested-by: Juerg Haefliger <juerg.haefliger@hpe.com>
On 09/28/2016 05:13 PM, Rick Jones wrote:
>
> Here is a quick look at performance tests for the result of trying the
> prototype fix for the packet reordering problem with VMs sending over
> an XPS-configured NIC. In particular, the Emulex/Avago/Broadcom
> Skyhawk. The fix was applied to a 4.4 kernel.
>
> Before: 3884 Mbit/s
> After: 8897 Mbit/s
>
> That was from a VM on a node with a Skyhawk and 2 E5-2640 processors
> to baremetal E5-2640 with a BE3. Physical MTU was 1500, the VM's
> vNIC's MTU was 1400. Systems were HPE ProLiants in OS Control Mode
> for power management, with the "performance" frequency governor
> loaded. An OpenStack Mitaka setup with Distributed Virtual Router.
>
> We had some other NIC types in the setup as well. XPS was also
> enabled on the ConnectX3-Pro. It was not enabled on the 82599ES (a
> function of the kernel being used, which had it disabled from the
> first reports of XPS negatively affecting VM traffic at the beginning
> of the year)
>
> Average Mbit/s From NIC type To Bare Metal BE3:
> NIC Type,
> CPU on VM Host Before After
> ------------------------------------------------
> ConnectX-3 Pro,E5-2670v3 9224 9271
> BE3, E5-2640 9016 9022
> 82599, E5-2640 9192 9003
> BCM57840, E5-2640 9213 9153
> Skyhawk, E5-2640 3884 8897
>
> For completeness:
> Average Mbit/s To NIC type from Bare Metal BE3:
> NIC Type,
> CPU on VM Host Before After
> ------------------------------------------------
> ConnectX-3 Pro,E5-2670v3 9322 9144
> BE3, E5-2640 9074 9017
> 82599, E5-2640 8670 8564
> BCM57840, E5-2640 2468 * 7979
> Skyhawk, E5-2640 8897 9269
>
> * This is the Busted bnx2x NIC FW GRO implementation issue. It was
> not visible in the "After" because the system was setup to disable
> the NIC FW GRO by the time it booted on the fix kernel.
>
> Average Transactions/s Between NIC type and Bare Metal BE3:
> NIC Type,
> CPU on VM Host Before After
> ------------------------------------------------
> ConnectX-3 Pro,E5-2670v3 12421 12612
> BE3, E5-2640 8178 8484
> 82599, E5-2640 8499 8549
> BCM57840, E5-2640 8544 8560
> Skyhawk, E5-2640 8537 8701
>
> happy benchmarking,
>
> Drew Balliet
> Jeurg Haefliger
> rick jones
>
> The semi-cooked results with additional statistics:
>
> 554M - BE3
> 544+M - ConnectX-3 Pro
> 560M - 82599ES
> 630M - BCM57840
> 650M - Skyhawk
>
> (substitute is simply replacing a system name with the model of NIC and CPU)
> Bulk To (South) and From (North) VM, Before:
> $ ../substitute.sh vxlan_554m_control_performance_gvnr_dvr_northsouth_stream.log |
> ~/netperf2_trunk/doc/examples/parse_single_stream.py -r -5 -f 1 -f 3 -f 4 -f 7 -f 8
> Field1,Field3,Field4,Field7,Field8,Min,P10,Median,Average,P90,P99,Max,Count
> North,560M,E5-2640,554FLB,E5-2640,8148.090,9048.830,9235.400,9192.868,9315.980,9338.845,9339.500,113
> North,630M,E5-2640,554FLB,E5-2640,8909.980,9113.238,9234.750,9213.140,9299.442,9336.206,9337.830,47
> North,544+M,E5-2670v3,554FLB,E5-2640,9013.740,9182.546,9229.620,9224.025,9264.036,9299.206,9301.970,99
> North,650M,E5-2640,554FLB,E5-2640,3187.680,3393.724,3796.160,3884.765,4405.096,4941.391,4956.300,129
> North,554M,E5-2640,554FLB,E5-2640,8700.930,8855.768,9026.030,9016.061,9158.846,9213.687,9226.150,135
> South,554FLB,E5-2640,560M,E5-2640,7754.350,8193.114,8718.540,8670.612,9026.436,9262.355,9285.010,113
> South,554FLB,E5-2640,630M,E5-2640,1897.660,2068.290,2514.430,2468.323,2787.162,2942.934,2957.250,53
> South,554FLB,E5-2640,544+M,E5-2670v3,9298.260,9314.432,9323.220,9322.207,9328.324,9330.704,9331.080,100
> South,554FLB,E5-2640,650M,E5-2640,8407.050,8907.136,9304.390,9206.776,9321.320,9325.347,9326.410,103
> South,554FLB,E5-2640,554M,E5-2640,7844.900,8632.530,9199.385,9074.535,9308.070,9319.224,9322.360,132
> 0 too-short lines ignored.
>
> Bulk To (South) and From (North) VM, After:
>
> $ ../substitute.sh vxlan_554m_control_performance_gvnr_xpsfix_dvr_northsouth_stream.log |
> ~/netperf2_trunk/doc/examples/parse_single_stream.py -r -5 -f 1 -f 3 -f 4 -f 7 -f 8
> Field1,Field3,Field4,Field7,Field8,Min,P10,Median,Average,P90,P99,Max,Count
> North,560M,E5-2640,554FLB,E5-2640,7576.790,8213.890,9182.870,9003.190,9295.975,9315.878,9318.160,36
> North,630M,E5-2640,554FLB,E5-2640,8811.800,8924.000,9206.660,9153.076,9306.287,9315.152,9315.790,12
> North,544+M,E5-2670v3,554FLB,E5-2640,9135.990,9228.520,9277.465,9271.875,9324.545,9339.604,9339.780,46
> North,650M,E5-2640,554FLB,E5-2640,8133.420,8483.340,8995.040,8897.779,9129.056,9165.230,9165.860,43
> North,554M,E5-2640,554FLB,E5-2640,8438.390,8879.150,9048.590,9022.813,9181.540,9248.650,9297.660,101
> South,554FLB,E5-2640,630M,E5-2640,7347.120,7592.565,7951.325,7979.951,8365.400,8575.837,8579.890,16
> South,554FLB,E5-2640,560M,E5-2640,7719.510,8044.496,8602.750,8564.741,9172.824,9248.686,9259.070,45
> South,554FLB,E5-2640,544+M,E5-2670v3,8838.660,8907.402,9112.335,9114.040,9326.510,9329.062,9329.990,52
> South,554FLB,E5-2640,650M,E5-2640,8699.660,9204.378,9307.940,9269.755,9321.060,9328.007,9331.370,58
> South,554FLB,E5-2640,554M,E5-2640,7893.310,8483.182,9111.070,9017.273,9314.984,9322.822,9326.750,103
>
> Request/Response Before:
> $ ../substitute.sh vxlan_554m_control_performance_gvnr_dvr_northsouth_rr.log |
> ~/netperf2_trunk/doc/examples/parse_single_stream.py -r -5 -f 1 -f 3 -f 4 -f 7 -f 8
> Field1,Field3,Field4,Field7,Field8,Min,P10,Median,Average,P90,P99,Max,Count
> RR,554FLB,E5-2640,560M,E5-2640,6971.540,8356.420,8515.275,8499.397,8717.740,9023.489,9114.990,186
> RR,554FLB,E5-2640,630M,E5-2640,7538.530,8461.090,8532.970,8544.005,8665.414,8895.486,9003.330,119
> RR,554FLB,E5-2640,544+M,E5-2670v3,8825.970,12279.268,12504.175,12421.076,12646.219,12742.536,12831.490,238
>
> RR,554FLB,E5-2640,650M,E5-2640,7152.220,8425.368,8535.370,8537.314,8757.256,9046.692,9128.290,219
>
> Request/Response After:
>
> $ ../substitute.sh vxlan_554m_control_performance_gvnr_xpsfix_dvr_northsouth_rr.log |
> ~/netperf2_trunk/doc/examples/parse_single_stream.py -r -5 -f 1 -f 3 -f 4 -f 7 -f 8
> Field1,Field3,Field4,Field7,Field8,Min,P10,Median,Average,P90,P99,Max,Count
> RR,554FLB,E5-2640,560M,E5-2640,7385.910,8411.654,8568.280,8549.659,8724.006,8874.092,8971.860,85
> RR,554FLB,E5-2640,630M,E5-2640,8265.030,8472.924,8543.215,8560.117,8657.339,8900.349,8902.260,34
> RR,554FLB,E5-2640,544+M,E5-2670v3,12365.830,12446.182,12597.575,12612.538,12790.654,12939.399,12968.120,78
>
> RR,554FLB,E5-2640,650M,E5-2640,8391.870,8516.924,8672.000,8701.399,8977.302,9100.178,9130.380,89
> RR,554FLB,E5-2640,554M,E5-2640,6859.680,8390.240,8481.835,8484.884,8649.290,8850.360,8976.960,226
>
--
Juerg Haefliger
Hewlett Packard Enterprise
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
^ permalink raw reply
* Reversion of "xen-netback: create a debugfs node for hash information"
From: Paul Durrant @ 2016-10-07 9:50 UTC (permalink / raw)
To: David Miller (davem@davemloft.net); +Cc: netdev@vger.kernel.org, Wei Liu
Dave,
I notice that you have made the above reversion of commit c0c64c15 (debugfs node) due to a build failure, despite the failure being caused by commit 0364a882 (switch to threaded irq) which was made subsequently. I assume you want me to re-spin a new patch for the debugfs node to fix the build problem?
Cheers,
Paul
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox