d1: add new target
[openwrt/staging/wigyori.git] / target / linux / d1 / patches-6.1 / 0014-mmc-sunxi-mmc-Correct-the-maximum-segment-size.patch
1 From 0e871e791a2530562851109346affa1c0d9987e0 Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Sun, 13 Jun 2021 23:15:56 -0500
4 Subject: [PATCH 014/117] mmc: sunxi-mmc: Correct the maximum segment size
5
6 According to the DMA descriptor documentation, the lowest two bits of
7 the size field are ignored, so the size must be rounded up to a multiple
8 of 4 bytes. Furthermore, 0 is not a valid buffer size; setting the size
9 to 0 will cause that DMA descriptor to be ignored.
10
11 Together, these restrictions limit the maximum DMA segment size to 4
12 less than the power-of-two width of the size field.
13
14 Series-to: Ulf Hansson <ulf.hansson@linaro.org>
15 Series-to: linux-mmc@vger.kernel.org
16
17 Fixes: 3cbcb16095f9 ("mmc: sunxi: Add driver for SD/MMC hosts found on Allwinner sunxi SoCs")
18 Signed-off-by: Samuel Holland <samuel@sholland.org>
19 ---
20 drivers/mmc/host/sunxi-mmc.c | 14 ++++++++------
21 1 file changed, 8 insertions(+), 6 deletions(-)
22
23 diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
24 index 69dcb8805e05..3a8f5fcb4bf1 100644
25 --- a/drivers/mmc/host/sunxi-mmc.c
26 +++ b/drivers/mmc/host/sunxi-mmc.c
27 @@ -214,6 +214,9 @@
28 #define SDXC_IDMAC_DES0_CES BIT(30) /* card error summary */
29 #define SDXC_IDMAC_DES0_OWN BIT(31) /* 1-idma owns it, 0-host owns it */
30
31 +/* Buffer size must be a multiple of 4 bytes. */
32 +#define SDXC_IDMAC_SIZE_ALIGN 4
33 +
34 #define SDXC_CLK_400K 0
35 #define SDXC_CLK_25M 1
36 #define SDXC_CLK_50M 2
37 @@ -361,17 +364,15 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
38 {
39 struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu;
40 dma_addr_t next_desc = host->sg_dma;
41 - int i, max_len = (1 << host->cfg->idma_des_size_bits);
42 + int i;
43
44 for (i = 0; i < data->sg_len; i++) {
45 pdes[i].config = cpu_to_le32(SDXC_IDMAC_DES0_CH |
46 SDXC_IDMAC_DES0_OWN |
47 SDXC_IDMAC_DES0_DIC);
48
49 - if (data->sg[i].length == max_len)
50 - pdes[i].buf_size = 0; /* 0 == max_len */
51 - else
52 - pdes[i].buf_size = cpu_to_le32(data->sg[i].length);
53 + pdes[i].buf_size = cpu_to_le32(ALIGN(data->sg[i].length,
54 + SDXC_IDMAC_SIZE_ALIGN));
55
56 next_desc += sizeof(struct sunxi_idma_des);
57 pdes[i].buf_addr_ptr1 =
58 @@ -1421,7 +1422,8 @@ static int sunxi_mmc_probe(struct platform_device *pdev)
59 mmc->max_blk_count = 8192;
60 mmc->max_blk_size = 4096;
61 mmc->max_segs = PAGE_SIZE / sizeof(struct sunxi_idma_des);
62 - mmc->max_seg_size = (1 << host->cfg->idma_des_size_bits);
63 + mmc->max_seg_size = (1 << host->cfg->idma_des_size_bits) -
64 + SDXC_IDMAC_SIZE_ALIGN;
65 mmc->max_req_size = mmc->max_seg_size * mmc->max_segs;
66 /* 400kHz ~ 52MHz */
67 mmc->f_min = 400000;
68 --
69 2.20.1
70