6e4323987a569406d7c85962be03fdf3fd4c3250
[openwrt/staging/pepe2k.git] /
1 From 20f552cafd7dda6f5d25128bbc04ea2c91d9f5d1 Mon Sep 17 00:00:00 2001
2 From: Radu Alexe <radu.alexe@nxp.com>
3 Date: Thu, 26 Oct 2017 10:45:14 +0300
4 Subject: [PATCH] crypto: caam - add functionality used by the caam_dma driver
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The caam_dma is a memcpy DMA driver based on the DMA functionality of
10 the CAAM hardware block. It creates a DMA channel for each JR of the
11 CAAM. This patch adds functionality that is used by the caam_dma that is
12 not yet part of the JR driver.
13
14 Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
15 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
16 ---
17 drivers/crypto/caam/desc.h | 2 ++
18 drivers/crypto/caam/jr.c | 41 +++++++++++++++++++++++++++++++++++++++++
19 drivers/crypto/caam/jr.h | 2 ++
20 3 files changed, 45 insertions(+)
21
22 --- a/drivers/crypto/caam/desc.h
23 +++ b/drivers/crypto/caam/desc.h
24 @@ -364,6 +364,7 @@
25 #define FIFOLD_TYPE_PK_N (0x08 << FIFOLD_TYPE_SHIFT)
26 #define FIFOLD_TYPE_PK_A (0x0c << FIFOLD_TYPE_SHIFT)
27 #define FIFOLD_TYPE_PK_B (0x0d << FIFOLD_TYPE_SHIFT)
28 +#define FIFOLD_TYPE_IFIFO (0x0f << FIFOLD_TYPE_SHIFT)
29
30 /* Other types. Need to OR in last/flush bits as desired */
31 #define FIFOLD_TYPE_MSG_MASK (0x38 << FIFOLD_TYPE_SHIFT)
32 @@ -1522,6 +1523,7 @@
33 #define MATH_SRC1_INFIFO (0x0a << MATH_SRC1_SHIFT)
34 #define MATH_SRC1_OUTFIFO (0x0b << MATH_SRC1_SHIFT)
35 #define MATH_SRC1_ONE (0x0c << MATH_SRC1_SHIFT)
36 +#define MATH_SRC1_ZERO (0x0f << MATH_SRC1_SHIFT)
37
38 /* Destination selectors */
39 #define MATH_DEST_SHIFT 8
40 --- a/drivers/crypto/caam/jr.c
41 +++ b/drivers/crypto/caam/jr.c
42 @@ -62,6 +62,14 @@ algs_unlock:
43 mutex_unlock(&algs_lock);
44 }
45
46 +static int jr_driver_probed;
47 +
48 +int caam_jr_driver_probed(void)
49 +{
50 + return jr_driver_probed;
51 +}
52 +EXPORT_SYMBOL(caam_jr_driver_probed);
53 +
54 static int caam_reset_hw_jr(struct device *dev)
55 {
56 struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
57 @@ -147,6 +155,8 @@ static int caam_jr_remove(struct platfor
58 if (ret)
59 dev_err(jrdev, "Failed to shut down job ring\n");
60
61 + jr_driver_probed--;
62 +
63 return ret;
64 }
65
66 @@ -311,6 +321,36 @@ struct device *caam_jr_alloc(void)
67 EXPORT_SYMBOL(caam_jr_alloc);
68
69 /**
70 + * caam_jridx_alloc() - Alloc a specific job ring based on its index.
71 + *
72 + * returns : pointer to the newly allocated physical
73 + * JobR dev can be written to if successful.
74 + **/
75 +struct device *caam_jridx_alloc(int idx)
76 +{
77 + struct caam_drv_private_jr *jrpriv;
78 + struct device *dev = ERR_PTR(-ENODEV);
79 +
80 + spin_lock(&driver_data.jr_alloc_lock);
81 +
82 + if (list_empty(&driver_data.jr_list))
83 + goto end;
84 +
85 + list_for_each_entry(jrpriv, &driver_data.jr_list, list_node) {
86 + if (jrpriv->ridx == idx) {
87 + atomic_inc(&jrpriv->tfm_count);
88 + dev = jrpriv->dev;
89 + break;
90 + }
91 + }
92 +
93 +end:
94 + spin_unlock(&driver_data.jr_alloc_lock);
95 + return dev;
96 +}
97 +EXPORT_SYMBOL(caam_jridx_alloc);
98 +
99 +/**
100 * caam_jr_free() - Free the Job Ring
101 * @rdev - points to the dev that identifies the Job ring to
102 * be released.
103 @@ -565,6 +605,7 @@ static int caam_jr_probe(struct platform
104 device_set_wakeup_enable(&pdev->dev, false);
105
106 register_algs(jrdev->parent);
107 + jr_driver_probed++;
108
109 return 0;
110 }
111 --- a/drivers/crypto/caam/jr.h
112 +++ b/drivers/crypto/caam/jr.h
113 @@ -9,7 +9,9 @@
114 #define JR_H
115
116 /* Prototypes for backend-level services exposed to APIs */
117 +int caam_jr_driver_probed(void);
118 struct device *caam_jr_alloc(void);
119 +struct device *caam_jridx_alloc(int idx);
120 void caam_jr_free(struct device *rdev);
121 int caam_jr_enqueue(struct device *dev, u32 *desc,
122 void (*cbk)(struct device *dev, u32 *desc, u32 status,