ath79: add support for kernel 5.4
[openwrt/staging/stintel.git] / target / linux / apm821xx / patches-5.4 / 111-crypto-crypto4xx-reduce-memory-fragmentation.patch
1 From 3913dbe4b3256ead342572f7aba726a60ab5fd43 Mon Sep 17 00:00:00 2001
2 Message-Id: <3913dbe4b3256ead342572f7aba726a60ab5fd43.1577917078.git.chunkeey@gmail.com>
3 From: Christian Lamparter <chunkeey@gmail.com>
4 Date: Wed, 1 Jan 2020 22:28:28 +0100
5 Subject: [PATCH 1/2] crypto: crypto4xx - reduce memory fragmentation
6 To: linux-crypto@vger.kernel.org
7 Cc: Herbert Xu <herbert@gondor.apana.org.au>
8
9 With recent kernels (>5.2), the driver fails to probe, as the
10 allocation of the driver's scatter buffer fails with -ENOMEM.
11
12 This happens in crypto4xx_build_sdr(). Where the driver tries
13 to get 512KiB (=PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD) of
14 continuous memory. This big chunk is by design, since the driver
15 uses this circumstance in the crypto4xx_copy_pkt_to_dst() to
16 its advantage:
17 "all scatter-buffers are all neatly organized in one big
18 continuous ringbuffer; So scatterwalk_map_and_copy() can be
19 instructed to copy a range of buffers in one go."
20
21 The PowerPC arch does not have support for DMA_CMA. Hence,
22 this patch reorganizes the order in which the memory
23 allocations are done. Since the driver itself is responsible
24 for some of the issues.
25
26 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
27 ---
28 drivers/crypto/amcc/crypto4xx_core.c | 27 +++++++++++++--------------
29 1 file changed, 13 insertions(+), 14 deletions(-)
30
31 --- a/drivers/crypto/amcc/crypto4xx_core.c
32 +++ b/drivers/crypto/amcc/crypto4xx_core.c
33 @@ -286,7 +286,8 @@ static u32 crypto4xx_build_gdr(struct cr
34
35 static inline void crypto4xx_destroy_gdr(struct crypto4xx_device *dev)
36 {
37 - dma_free_coherent(dev->core_dev->device,
38 + if (dev->gdr)
39 + dma_free_coherent(dev->core_dev->device,
40 sizeof(struct ce_gd) * PPC4XX_NUM_GD,
41 dev->gdr, dev->gdr_pa);
42 }
43 @@ -354,13 +355,6 @@ static u32 crypto4xx_build_sdr(struct cr
44 {
45 int i;
46
47 - /* alloc memory for scatter descriptor ring */
48 - dev->sdr = dma_alloc_coherent(dev->core_dev->device,
49 - sizeof(struct ce_sd) * PPC4XX_NUM_SD,
50 - &dev->sdr_pa, GFP_ATOMIC);
51 - if (!dev->sdr)
52 - return -ENOMEM;
53 -
54 dev->scatter_buffer_va =
55 dma_alloc_coherent(dev->core_dev->device,
56 PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD,
57 @@ -368,6 +362,13 @@ static u32 crypto4xx_build_sdr(struct cr
58 if (!dev->scatter_buffer_va)
59 return -ENOMEM;
60
61 + /* alloc memory for scatter descriptor ring */
62 + dev->sdr = dma_alloc_coherent(dev->core_dev->device,
63 + sizeof(struct ce_sd) * PPC4XX_NUM_SD,
64 + &dev->sdr_pa, GFP_ATOMIC);
65 + if (!dev->sdr)
66 + return -ENOMEM;
67 +
68 for (i = 0; i < PPC4XX_NUM_SD; i++) {
69 dev->sdr[i].ptr = dev->scatter_buffer_pa +
70 PPC4XX_SD_BUFFER_SIZE * i;
71 @@ -1439,16 +1440,15 @@ static int crypto4xx_probe(struct platfo
72 spin_lock_init(&core_dev->lock);
73 INIT_LIST_HEAD(&core_dev->dev->alg_list);
74 ratelimit_default_init(&core_dev->dev->aead_ratelimit);
75 + rc = crypto4xx_build_sdr(core_dev->dev);
76 + if (rc)
77 + goto err_build_sdr;
78 rc = crypto4xx_build_pdr(core_dev->dev);
79 if (rc)
80 - goto err_build_pdr;
81 + goto err_build_sdr;
82
83 rc = crypto4xx_build_gdr(core_dev->dev);
84 if (rc)
85 - goto err_build_pdr;
86 -
87 - rc = crypto4xx_build_sdr(core_dev->dev);
88 - if (rc)
89 goto err_build_sdr;
90
91 /* Init tasklet for bottom half processing */
92 @@ -1493,7 +1493,6 @@ err_iomap:
93 err_build_sdr:
94 crypto4xx_destroy_sdr(core_dev->dev);
95 crypto4xx_destroy_gdr(core_dev->dev);
96 -err_build_pdr:
97 crypto4xx_destroy_pdr(core_dev->dev);
98 kfree(core_dev->dev);
99 err_alloc_dev: