diff options
Diffstat (limited to 'drivers/crypto/caam/caamalg.c')
| -rw-r--r-- | drivers/crypto/caam/caamalg.c | 83 |
1 files changed, 20 insertions, 63 deletions
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 7c63b72ecd75..4f44b71b9e24 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c | |||
| @@ -86,6 +86,7 @@ | |||
| 86 | #else | 86 | #else |
| 87 | #define debug(format, arg...) | 87 | #define debug(format, arg...) |
| 88 | #endif | 88 | #endif |
| 89 | static struct list_head alg_list; | ||
| 89 | 90 | ||
| 90 | /* Set DK bit in class 1 operation if shared */ | 91 | /* Set DK bit in class 1 operation if shared */ |
| 91 | static inline void append_dec_op1(u32 *desc, u32 type) | 92 | static inline void append_dec_op1(u32 *desc, u32 type) |
| @@ -2057,7 +2058,6 @@ static struct caam_alg_template driver_algs[] = { | |||
| 2057 | 2058 | ||
| 2058 | struct caam_crypto_alg { | 2059 | struct caam_crypto_alg { |
| 2059 | struct list_head entry; | 2060 | struct list_head entry; |
| 2060 | struct device *ctrldev; | ||
| 2061 | int class1_alg_type; | 2061 | int class1_alg_type; |
| 2062 | int class2_alg_type; | 2062 | int class2_alg_type; |
| 2063 | int alg_op; | 2063 | int alg_op; |
| @@ -2070,14 +2070,12 @@ static int caam_cra_init(struct crypto_tfm *tfm) | |||
| 2070 | struct caam_crypto_alg *caam_alg = | 2070 | struct caam_crypto_alg *caam_alg = |
| 2071 | container_of(alg, struct caam_crypto_alg, crypto_alg); | 2071 | container_of(alg, struct caam_crypto_alg, crypto_alg); |
| 2072 | struct caam_ctx *ctx = crypto_tfm_ctx(tfm); | 2072 | struct caam_ctx *ctx = crypto_tfm_ctx(tfm); |
| 2073 | struct caam_drv_private *priv = dev_get_drvdata(caam_alg->ctrldev); | ||
| 2074 | int tgt_jr = atomic_inc_return(&priv->tfm_count); | ||
| 2075 | 2073 | ||
| 2076 | /* | 2074 | ctx->jrdev = caam_jr_alloc(); |
| 2077 | * distribute tfms across job rings to ensure in-order | 2075 | if (IS_ERR(ctx->jrdev)) { |
| 2078 | * crypto request processing per tfm | 2076 | pr_err("Job Ring Device allocation for transform failed\n"); |
| 2079 | */ | 2077 | return PTR_ERR(ctx->jrdev); |
| 2080 | ctx->jrdev = priv->jrdev[(tgt_jr / 2) % priv->total_jobrs]; | 2078 | } |
| 2081 | 2079 | ||
| 2082 | /* copy descriptor header template value */ | 2080 | /* copy descriptor header template value */ |
| 2083 | ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam_alg->class1_alg_type; | 2081 | ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam_alg->class1_alg_type; |
| @@ -2104,44 +2102,26 @@ static void caam_cra_exit(struct crypto_tfm *tfm) | |||
| 2104 | dma_unmap_single(ctx->jrdev, ctx->sh_desc_givenc_dma, | 2102 | dma_unmap_single(ctx->jrdev, ctx->sh_desc_givenc_dma, |
| 2105 | desc_bytes(ctx->sh_desc_givenc), | 2103 | desc_bytes(ctx->sh_desc_givenc), |
| 2106 | DMA_TO_DEVICE); | 2104 | DMA_TO_DEVICE); |
| 2105 | |||
| 2106 | caam_jr_free(ctx->jrdev); | ||
| 2107 | } | 2107 | } |
| 2108 | 2108 | ||
| 2109 | static void __exit caam_algapi_exit(void) | 2109 | static void __exit caam_algapi_exit(void) |
| 2110 | { | 2110 | { |
| 2111 | 2111 | ||
| 2112 | struct device_node *dev_node; | ||
| 2113 | struct platform_device *pdev; | ||
| 2114 | struct device *ctrldev; | ||
| 2115 | struct caam_drv_private *priv; | ||
| 2116 | struct caam_crypto_alg *t_alg, *n; | 2112 | struct caam_crypto_alg *t_alg, *n; |
| 2117 | 2113 | ||
| 2118 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); | 2114 | if (!alg_list.next) |
| 2119 | if (!dev_node) { | ||
| 2120 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0"); | ||
| 2121 | if (!dev_node) | ||
| 2122 | return; | ||
| 2123 | } | ||
| 2124 | |||
| 2125 | pdev = of_find_device_by_node(dev_node); | ||
| 2126 | if (!pdev) | ||
| 2127 | return; | ||
| 2128 | |||
| 2129 | ctrldev = &pdev->dev; | ||
| 2130 | of_node_put(dev_node); | ||
| 2131 | priv = dev_get_drvdata(ctrldev); | ||
| 2132 | |||
| 2133 | if (!priv->alg_list.next) | ||
| 2134 | return; | 2115 | return; |
| 2135 | 2116 | ||
| 2136 | list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { | 2117 | list_for_each_entry_safe(t_alg, n, &alg_list, entry) { |
| 2137 | crypto_unregister_alg(&t_alg->crypto_alg); | 2118 | crypto_unregister_alg(&t_alg->crypto_alg); |
| 2138 | list_del(&t_alg->entry); | 2119 | list_del(&t_alg->entry); |
| 2139 | kfree(t_alg); | 2120 | kfree(t_alg); |
| 2140 | } | 2121 | } |
| 2141 | } | 2122 | } |
| 2142 | 2123 | ||
| 2143 | static struct caam_crypto_alg *caam_alg_alloc(struct device *ctrldev, | 2124 | static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template |
| 2144 | struct caam_alg_template | ||
| 2145 | *template) | 2125 | *template) |
| 2146 | { | 2126 | { |
| 2147 | struct caam_crypto_alg *t_alg; | 2127 | struct caam_crypto_alg *t_alg; |
| @@ -2149,7 +2129,7 @@ static struct caam_crypto_alg *caam_alg_alloc(struct device *ctrldev, | |||
| 2149 | 2129 | ||
| 2150 | t_alg = kzalloc(sizeof(struct caam_crypto_alg), GFP_KERNEL); | 2130 | t_alg = kzalloc(sizeof(struct caam_crypto_alg), GFP_KERNEL); |
| 2151 | if (!t_alg) { | 2131 | if (!t_alg) { |
| 2152 | dev_err(ctrldev, "failed to allocate t_alg\n"); | 2132 | pr_err("failed to allocate t_alg\n"); |
| 2153 | return ERR_PTR(-ENOMEM); | 2133 | return ERR_PTR(-ENOMEM); |
| 2154 | } | 2134 | } |
| 2155 | 2135 | ||
| @@ -2181,62 +2161,39 @@ static struct caam_crypto_alg *caam_alg_alloc(struct device *ctrldev, | |||
| 2181 | t_alg->class1_alg_type = template->class1_alg_type; | 2161 | t_alg->class1_alg_type = template->class1_alg_type; |
| 2182 | t_alg->class2_alg_type = template->class2_alg_type; | 2162 | t_alg->class2_alg_type = template->class2_alg_type; |
| 2183 | t_alg->alg_op = template->alg_op; | 2163 | t_alg->alg_op = template->alg_op; |
| 2184 | t_alg->ctrldev = ctrldev; | ||
| 2185 | 2164 | ||
| 2186 | return t_alg; | 2165 | return t_alg; |
| 2187 | } | 2166 | } |
| 2188 | 2167 | ||
| 2189 | static int __init caam_algapi_init(void) | 2168 | static int __init caam_algapi_init(void) |
| 2190 | { | 2169 | { |
| 2191 | struct device_node *dev_node; | ||
| 2192 | struct platform_device *pdev; | ||
| 2193 | struct device *ctrldev; | ||
| 2194 | struct caam_drv_private *priv; | ||
| 2195 | int i = 0, err = 0; | 2170 | int i = 0, err = 0; |
| 2196 | 2171 | ||
| 2197 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); | 2172 | INIT_LIST_HEAD(&alg_list); |
| 2198 | if (!dev_node) { | ||
| 2199 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0"); | ||
| 2200 | if (!dev_node) | ||
| 2201 | return -ENODEV; | ||
| 2202 | } | ||
| 2203 | |||
| 2204 | pdev = of_find_device_by_node(dev_node); | ||
| 2205 | if (!pdev) | ||
| 2206 | return -ENODEV; | ||
| 2207 | |||
| 2208 | ctrldev = &pdev->dev; | ||
| 2209 | priv = dev_get_drvdata(ctrldev); | ||
| 2210 | of_node_put(dev_node); | ||
| 2211 | |||
| 2212 | INIT_LIST_HEAD(&priv->alg_list); | ||
| 2213 | |||
| 2214 | atomic_set(&priv->tfm_count, -1); | ||
| 2215 | 2173 | ||
| 2216 | /* register crypto algorithms the device supports */ | 2174 | /* register crypto algorithms the device supports */ |
| 2217 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { | 2175 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { |
| 2218 | /* TODO: check if h/w supports alg */ | 2176 | /* TODO: check if h/w supports alg */ |
| 2219 | struct caam_crypto_alg *t_alg; | 2177 | struct caam_crypto_alg *t_alg; |
| 2220 | 2178 | ||
| 2221 | t_alg = caam_alg_alloc(ctrldev, &driver_algs[i]); | 2179 | t_alg = caam_alg_alloc(&driver_algs[i]); |
| 2222 | if (IS_ERR(t_alg)) { | 2180 | if (IS_ERR(t_alg)) { |
| 2223 | err = PTR_ERR(t_alg); | 2181 | err = PTR_ERR(t_alg); |
| 2224 | dev_warn(ctrldev, "%s alg allocation failed\n", | 2182 | pr_warn("%s alg allocation failed\n", |
| 2225 | driver_algs[i].driver_name); | 2183 | driver_algs[i].driver_name); |
| 2226 | continue; | 2184 | continue; |
| 2227 | } | 2185 | } |
| 2228 | 2186 | ||
| 2229 | err = crypto_register_alg(&t_alg->crypto_alg); | 2187 | err = crypto_register_alg(&t_alg->crypto_alg); |
| 2230 | if (err) { | 2188 | if (err) { |
| 2231 | dev_warn(ctrldev, "%s alg registration failed\n", | 2189 | pr_warn("%s alg registration failed\n", |
| 2232 | t_alg->crypto_alg.cra_driver_name); | 2190 | t_alg->crypto_alg.cra_driver_name); |
| 2233 | kfree(t_alg); | 2191 | kfree(t_alg); |
| 2234 | } else | 2192 | } else |
| 2235 | list_add_tail(&t_alg->entry, &priv->alg_list); | 2193 | list_add_tail(&t_alg->entry, &alg_list); |
| 2236 | } | 2194 | } |
| 2237 | if (!list_empty(&priv->alg_list)) | 2195 | if (!list_empty(&alg_list)) |
| 2238 | dev_info(ctrldev, "%s algorithms registered in /proc/crypto\n", | 2196 | pr_info("caam algorithms registered in /proc/crypto\n"); |
| 2239 | (char *)of_get_property(dev_node, "compatible", NULL)); | ||
| 2240 | 2197 | ||
| 2241 | return err; | 2198 | return err; |
| 2242 | } | 2199 | } |
