apm821xx: add linux 4.19 apm821xx patches
[openwrt/staging/mkresin.git] / target / linux / apm821xx / patches-4.19 / 010-dmaengine-dw-dmac-implement-dma-prot.patch
1 From 7b0c03ecc42fb223baf015877fee9d517c2c8af1 Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@gmail.com>
3 Date: Sat, 17 Nov 2018 17:17:21 +0100
4 Subject: dmaengine: dw-dmac: implement dma protection control setting
5
6 This patch adds a new device-tree property that allows to
7 specify the dma protection control bits for the all of the
8 DMA controller's channel uniformly.
9
10 Setting the "correct" bits can have a huge impact on the
11 PPC460EX and APM82181 that use this DMA engine in combination
12 with a DesignWare' SATA-II core (sata_dwc_460ex driver).
13
14 In the OpenWrt Forum, the user takimata reported that:
15 |It seems your patch unleashed the full power of the SATA port.
16 |Where I was previously hitting a really hard limit at around
17 |82 MB/s for reading and 27 MB/s for writing, I am now getting this:
18 |
19 |root@OpenWrt:/mnt# time dd if=/dev/zero of=tempfile bs=1M count=1024
20 |1024+0 records in
21 |1024+0 records out
22 |real 0m 13.65s
23 |user 0m 0.01s
24 |sys 0m 11.89s
25 |
26 |root@OpenWrt:/mnt# time dd if=tempfile of=/dev/null bs=1M count=1024
27 |1024+0 records in
28 |1024+0 records out
29 |real 0m 8.41s
30 |user 0m 0.01s
31 |sys 0m 4.70s
32 |
33 |This means: 121 MB/s reading and 75 MB/s writing!
34 |
35 |The drive is a WD Green WD10EARX taken from an older MBL Single.
36 |I repeated the test a few times with even larger files to rule out
37 |any caching, I'm still seeing the same great performance. OpenWrt is
38 |now completely on par with the original MBL firmware's performance.
39
40 Another user And.short reported:
41 |I can report that your fix worked! Boots up fine with two
42 |drives even with more partitions, and no more reboot on
43 |concurrent disk access!
44
45 A closer look into the sata_dwc_460ex code revealed that
46 the driver did initally set the correct protection control
47 bits. However, this feature was lost when the sata_dwc_460ex
48 driver was converted to the generic DMA driver framework.
49
50 BugLink: https://forum.openwrt.org/t/wd-mybook-live-duo-two-disks/16195/55
51 BugLink: https://forum.openwrt.org/t/wd-mybook-live-duo-two-disks/16195/50
52 Fixes: 8b3444852a2b ("sata_dwc_460ex: move to generic DMA driver")
53 Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
54 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
55 Signed-off-by: Vinod Koul <vkoul@kernel.org>
56 ---
57
58 diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c
59 index d0c3e50b39fb..2c5ca1961256 100644
60 --- a/drivers/dma/dw/core.c
61 +++ b/drivers/dma/dw/core.c
62 @@ -160,12 +160,14 @@ static void dwc_initialize_chan_idma32(struct dw_dma_chan *dwc)
63
64 static void dwc_initialize_chan_dw(struct dw_dma_chan *dwc)
65 {
66 + struct dw_dma *dw = to_dw_dma(dwc->chan.device);
67 u32 cfghi = DWC_CFGH_FIFO_MODE;
68 u32 cfglo = DWC_CFGL_CH_PRIOR(dwc->priority);
69 bool hs_polarity = dwc->dws.hs_polarity;
70
71 cfghi |= DWC_CFGH_DST_PER(dwc->dws.dst_id);
72 cfghi |= DWC_CFGH_SRC_PER(dwc->dws.src_id);
73 + cfghi |= DWC_CFGH_PROTCTL(dw->pdata->protctl);
74
75 /* Set polarity of handshake interface */
76 cfglo |= hs_polarity ? DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL : 0;
77 diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
78 index f01b2c173fa6..31ff8113c3de 100644
79 --- a/drivers/dma/dw/platform.c
80 +++ b/drivers/dma/dw/platform.c
81 @@ -162,6 +162,12 @@ dw_dma_parse_dt(struct platform_device *pdev)
82 pdata->multi_block[tmp] = 1;
83 }
84
85 + if (!of_property_read_u32(np, "snps,dma-protection-control", &tmp)) {
86 + if (tmp > CHAN_PROTCTL_MASK)
87 + return NULL;
88 + pdata->protctl = tmp;
89 + }
90 +
91 return pdata;
92 }
93 #else
94 diff --git a/drivers/dma/dw/regs.h b/drivers/dma/dw/regs.h
95 index 09e7dfdbb790..646c9c960c07 100644
96 --- a/drivers/dma/dw/regs.h
97 +++ b/drivers/dma/dw/regs.h
98 @@ -200,6 +200,10 @@ enum dw_dma_msize {
99 #define DWC_CFGH_FCMODE (1 << 0)
100 #define DWC_CFGH_FIFO_MODE (1 << 1)
101 #define DWC_CFGH_PROTCTL(x) ((x) << 2)
102 +#define DWC_CFGH_PROTCTL_DATA (0 << 2) /* data access - always set */
103 +#define DWC_CFGH_PROTCTL_PRIV (1 << 2) /* privileged -> AHB HPROT[1] */
104 +#define DWC_CFGH_PROTCTL_BUFFER (2 << 2) /* bufferable -> AHB HPROT[2] */
105 +#define DWC_CFGH_PROTCTL_CACHE (4 << 2) /* cacheable -> AHB HPROT[3] */
106 #define DWC_CFGH_DS_UPD_EN (1 << 5)
107 #define DWC_CFGH_SS_UPD_EN (1 << 6)
108 #define DWC_CFGH_SRC_PER(x) ((x) << 7)
109 diff --git a/include/linux/platform_data/dma-dw.h b/include/linux/platform_data/dma-dw.h
110 index 896cb71a382c..1a1d58ebffbf 100644
111 --- a/include/linux/platform_data/dma-dw.h
112 +++ b/include/linux/platform_data/dma-dw.h
113 @@ -49,6 +49,7 @@ struct dw_dma_slave {
114 * @data_width: Maximum data width supported by hardware per AHB master
115 * (in bytes, power of 2)
116 * @multi_block: Multi block transfers supported by hardware per channel.
117 + * @protctl: Protection control signals setting per channel.
118 */
119 struct dw_dma_platform_data {
120 unsigned int nr_channels;
121 @@ -65,6 +66,11 @@ struct dw_dma_platform_data {
122 unsigned char nr_masters;
123 unsigned char data_width[DW_DMA_MAX_NR_MASTERS];
124 unsigned char multi_block[DW_DMA_MAX_NR_CHANNELS];
125 +#define CHAN_PROTCTL_PRIVILEGED BIT(0)
126 +#define CHAN_PROTCTL_BUFFERABLE BIT(1)
127 +#define CHAN_PROTCTL_CACHEABLE BIT(2)
128 +#define CHAN_PROTCTL_MASK GENMASK(2, 0)
129 + unsigned char protctl;
130 };
131
132 #endif /* _PLATFORM_DATA_DMA_DW_H */
133 diff --git a/include/dt-bindings/dma/dw-dmac.h b/include/dt-bindings/dma/dw-dmac.h
134 new file mode 100644
135 index 000000000000..d1ca705c95b3
136 --- /dev/null
137 +++ b/include/dt-bindings/dma/dw-dmac.h
138 @@ -0,0 +1,14 @@
139 +/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
140 +
141 +#ifndef __DT_BINDINGS_DMA_DW_DMAC_H__
142 +#define __DT_BINDINGS_DMA_DW_DMAC_H__
143 +
144 +/*
145 + * Protection Control bits provide protection against illegal transactions.
146 + * The protection bits[0:2] are one-to-one mapped to AHB HPROT[3:1] signals.
147 + */
148 +#define DW_DMAC_HPROT1_PRIVILEGED_MODE (1 << 0) /* Privileged Mode */
149 +#define DW_DMAC_HPROT2_BUFFERABLE (1 << 1) /* DMA is bufferable */
150 +#define DW_DMAC_HPROT3_CACHEABLE (1 << 2) /* DMA is cacheable */
151 +
152 +#endif /* __DT_BINDINGS_DMA_DW_DMAC_H__ */
153 --
154 cgit 1.2-0.3.lf.el7
155