d1: add new target
[openwrt/staging/mans0n.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 --- a/drivers/mmc/host/sunxi-mmc.c
24 +++ b/drivers/mmc/host/sunxi-mmc.c
25 @@ -214,6 +214,9 @@
26 #define SDXC_IDMAC_DES0_CES BIT(30) /* card error summary */
27 #define SDXC_IDMAC_DES0_OWN BIT(31) /* 1-idma owns it, 0-host owns it */
28
29 +/* Buffer size must be a multiple of 4 bytes. */
30 +#define SDXC_IDMAC_SIZE_ALIGN 4
31 +
32 #define SDXC_CLK_400K 0
33 #define SDXC_CLK_25M 1
34 #define SDXC_CLK_50M 2
35 @@ -361,17 +364,15 @@ static void sunxi_mmc_init_idma_des(stru
36 {
37 struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu;
38 dma_addr_t next_desc = host->sg_dma;
39 - int i, max_len = (1 << host->cfg->idma_des_size_bits);
40 + int i;
41
42 for (i = 0; i < data->sg_len; i++) {
43 pdes[i].config = cpu_to_le32(SDXC_IDMAC_DES0_CH |
44 SDXC_IDMAC_DES0_OWN |
45 SDXC_IDMAC_DES0_DIC);
46
47 - if (data->sg[i].length == max_len)
48 - pdes[i].buf_size = 0; /* 0 == max_len */
49 - else
50 - pdes[i].buf_size = cpu_to_le32(data->sg[i].length);
51 + pdes[i].buf_size = cpu_to_le32(ALIGN(data->sg[i].length,
52 + SDXC_IDMAC_SIZE_ALIGN));
53
54 next_desc += sizeof(struct sunxi_idma_des);
55 pdes[i].buf_addr_ptr1 =
56 @@ -1421,7 +1422,8 @@ static int sunxi_mmc_probe(struct platfo
57 mmc->max_blk_count = 8192;
58 mmc->max_blk_size = 4096;
59 mmc->max_segs = PAGE_SIZE / sizeof(struct sunxi_idma_des);
60 - mmc->max_seg_size = (1 << host->cfg->idma_des_size_bits);
61 + mmc->max_seg_size = (1 << host->cfg->idma_des_size_bits) -
62 + SDXC_IDMAC_SIZE_ALIGN;
63 mmc->max_req_size = mmc->max_seg_size * mmc->max_segs;
64 /* 400kHz ~ 52MHz */
65 mmc->f_min = 400000;