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>
9 With recent kernels (>5.2), the driver fails to probe, as the
10 allocation of the driver's scatter buffer fails with -ENOMEM.
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
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."
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.
26 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
28 drivers/crypto/amcc/crypto4xx_core.c | 27 +++++++++++++--------------
29 1 file changed, 13 insertions(+), 14 deletions(-)
31 diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
32 index 7d6b695c4ab3..3ce5f0a24cbc 100644
33 --- a/drivers/crypto/amcc/crypto4xx_core.c
34 +++ b/drivers/crypto/amcc/crypto4xx_core.c
35 @@ -286,7 +286,8 @@ static u32 crypto4xx_build_gdr(struct crypto4xx_device *dev)
37 static inline void crypto4xx_destroy_gdr(struct crypto4xx_device *dev)
39 - dma_free_coherent(dev->core_dev->device,
41 + dma_free_coherent(dev->core_dev->device,
42 sizeof(struct ce_gd) * PPC4XX_NUM_GD,
43 dev->gdr, dev->gdr_pa);
45 @@ -354,13 +355,6 @@ static u32 crypto4xx_build_sdr(struct crypto4xx_device *dev)
49 - /* alloc memory for scatter descriptor ring */
50 - dev->sdr = dma_alloc_coherent(dev->core_dev->device,
51 - sizeof(struct ce_sd) * PPC4XX_NUM_SD,
52 - &dev->sdr_pa, GFP_ATOMIC);
56 dev->scatter_buffer_va =
57 dma_alloc_coherent(dev->core_dev->device,
58 PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD,
59 @@ -368,6 +362,13 @@ static u32 crypto4xx_build_sdr(struct crypto4xx_device *dev)
60 if (!dev->scatter_buffer_va)
63 + /* alloc memory for scatter descriptor ring */
64 + dev->sdr = dma_alloc_coherent(dev->core_dev->device,
65 + sizeof(struct ce_sd) * PPC4XX_NUM_SD,
66 + &dev->sdr_pa, GFP_ATOMIC);
70 for (i = 0; i < PPC4XX_NUM_SD; i++) {
71 dev->sdr[i].ptr = dev->scatter_buffer_pa +
72 PPC4XX_SD_BUFFER_SIZE * i;
73 @@ -1439,15 +1440,14 @@ static int crypto4xx_probe(struct platform_device *ofdev)
74 spin_lock_init(&core_dev->lock);
75 INIT_LIST_HEAD(&core_dev->dev->alg_list);
76 ratelimit_default_init(&core_dev->dev->aead_ratelimit);
77 + rc = crypto4xx_build_sdr(core_dev->dev);
80 rc = crypto4xx_build_pdr(core_dev->dev);
85 rc = crypto4xx_build_gdr(core_dev->dev);
89 - rc = crypto4xx_build_sdr(core_dev->dev);
93 @@ -1493,7 +1493,6 @@ static int crypto4xx_probe(struct platform_device *ofdev)
95 crypto4xx_destroy_sdr(core_dev->dev);
96 crypto4xx_destroy_gdr(core_dev->dev);
98 crypto4xx_destroy_pdr(core_dev->dev);