kernel: improve skb hash on the mtk ethernet driver
[openwrt/openwrt.git] / target / linux / mediatek / patches-5.4 / 1011-net-ethernet-mtk_eth_soc-add-support-for-coherent-DM.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 4 Sep 2020 18:36:06 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: add support for coherent DMA
4
5 It improves performance by eliminating the need for a cache flush on rx and tx
6
7 Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 ---
9
10 --- a/arch/arm64/boot/dts/mediatek/mt7622.dtsi
11 +++ b/arch/arm64/boot/dts/mediatek/mt7622.dtsi
12 @@ -357,7 +357,7 @@
13 };
14
15 cci_control2: slave-if@5000 {
16 - compatible = "arm,cci-400-ctrl-if";
17 + compatible = "arm,cci-400-ctrl-if", "syscon";
18 interface-type = "ace";
19 reg = <0x5000 0x1000>;
20 };
21 @@ -967,6 +967,8 @@
22 power-domains = <&scpsys MT7622_POWER_DOMAIN_ETHSYS>;
23 mediatek,ethsys = <&ethsys>;
24 mediatek,sgmiisys = <&sgmiisys>;
25 + mediatek,cci-control = <&cci_control2>;
26 + dma-coherent;
27 #address-cells = <1>;
28 #size-cells = <0>;
29 status = "disabled";
30 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
31 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
32 @@ -9,6 +9,7 @@
33 #include <linux/of_device.h>
34 #include <linux/of_mdio.h>
35 #include <linux/of_net.h>
36 +#include <linux/of_address.h>
37 #include <linux/mfd/syscon.h>
38 #include <linux/regmap.h>
39 #include <linux/clk.h>
40 @@ -2485,6 +2486,13 @@ static int mtk_hw_init(struct mtk_eth *e
41 if (ret)
42 goto err_disable_pm;
43
44 + if (of_dma_is_coherent(eth->dev->of_node)) {
45 + u32 mask = ETHSYS_DMA_AG_MAP_PDMA | ETHSYS_DMA_AG_MAP_QDMA |
46 + ETHSYS_DMA_AG_MAP_PPE;
47 +
48 + regmap_update_bits(eth->ethsys, ETHSYS_DMA_AG_MAP, mask, mask);
49 + }
50 +
51 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) {
52 ret = device_reset(eth->dev);
53 if (ret) {
54 @@ -3083,6 +3091,16 @@ static int mtk_probe(struct platform_dev
55 }
56 }
57
58 + if (of_dma_is_coherent(pdev->dev.of_node)) {
59 + struct regmap *cci;
60 +
61 + cci = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
62 + "mediatek,cci-control");
63 + /* enable CPU/bus coherency */
64 + if (!IS_ERR(cci))
65 + regmap_write(cci, 0, 3);
66 + }
67 +
68 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SGMII)) {
69 eth->sgmii = devm_kzalloc(eth->dev, sizeof(*eth->sgmii),
70 GFP_KERNEL);
71 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
72 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
73 @@ -435,6 +435,12 @@
74 #define RSTCTRL_FE BIT(6)
75 #define RSTCTRL_PPE BIT(31)
76
77 +/* ethernet dma channel agent map */
78 +#define ETHSYS_DMA_AG_MAP 0x408
79 +#define ETHSYS_DMA_AG_MAP_PDMA BIT(0)
80 +#define ETHSYS_DMA_AG_MAP_QDMA BIT(1)
81 +#define ETHSYS_DMA_AG_MAP_PPE BIT(2)
82 +
83 /* SGMII subsystem config registers */
84 /* Register to auto-negotiation restart */
85 #define SGMSYS_PCS_CONTROL_1 0x0