atmel-aes.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. /*
  2. * Cryptographic API.
  3. *
  4. * Support for ATMEL AES HW acceleration.
  5. *
  6. * Copyright (c) 2012 Eukréa Electromatique - ATMEL
  7. * Author: Nicolas Royer <nicolas@eukrea.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. *
  13. * Some ideas are from omap-aes.c driver.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/err.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/hw_random.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/device.h>
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/errno.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/kernel.h>
  29. #include <linux/clk.h>
  30. #include <linux/irq.h>
  31. #include <linux/io.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/scatterlist.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/delay.h>
  36. #include <linux/crypto.h>
  37. #include <linux/cryptohash.h>
  38. #include <crypto/scatterwalk.h>
  39. #include <crypto/algapi.h>
  40. #include <crypto/aes.h>
  41. #include <crypto/hash.h>
  42. #include <crypto/internal/hash.h>
  43. #include <linux/platform_data/atmel-aes.h>
  44. #include "atmel-aes-regs.h"
  45. #define CFB8_BLOCK_SIZE 1
  46. #define CFB16_BLOCK_SIZE 2
  47. #define CFB32_BLOCK_SIZE 4
  48. #define CFB64_BLOCK_SIZE 8
  49. /* AES flags */
  50. #define AES_FLAGS_MODE_MASK 0x01ff
  51. #define AES_FLAGS_ENCRYPT BIT(0)
  52. #define AES_FLAGS_CBC BIT(1)
  53. #define AES_FLAGS_CFB BIT(2)
  54. #define AES_FLAGS_CFB8 BIT(3)
  55. #define AES_FLAGS_CFB16 BIT(4)
  56. #define AES_FLAGS_CFB32 BIT(5)
  57. #define AES_FLAGS_CFB64 BIT(6)
  58. #define AES_FLAGS_OFB BIT(7)
  59. #define AES_FLAGS_CTR BIT(8)
  60. #define AES_FLAGS_INIT BIT(16)
  61. #define AES_FLAGS_DMA BIT(17)
  62. #define AES_FLAGS_BUSY BIT(18)
  63. #define AES_FLAGS_DUALBUFF BIT(24)
  64. #define ATMEL_AES_QUEUE_LENGTH 1
  65. #define ATMEL_AES_CACHE_SIZE 0
  66. #define ATMEL_AES_DMA_THRESHOLD 16
  67. struct atmel_aes_dev;
  68. struct atmel_aes_ctx {
  69. struct atmel_aes_dev *dd;
  70. int keylen;
  71. u32 key[AES_KEYSIZE_256 / sizeof(u32)];
  72. };
  73. struct atmel_aes_reqctx {
  74. unsigned long mode;
  75. };
  76. struct atmel_aes_dma {
  77. struct dma_chan *chan;
  78. struct dma_slave_config dma_conf;
  79. };
  80. struct atmel_aes_dev {
  81. struct list_head list;
  82. unsigned long phys_base;
  83. void __iomem *io_base;
  84. struct atmel_aes_ctx *ctx;
  85. struct device *dev;
  86. struct clk *iclk;
  87. int irq;
  88. unsigned long flags;
  89. int err;
  90. spinlock_t lock;
  91. struct crypto_queue queue;
  92. struct tasklet_struct done_task;
  93. struct tasklet_struct queue_task;
  94. struct ablkcipher_request *req;
  95. size_t total;
  96. struct scatterlist *in_sg;
  97. unsigned int nb_in_sg;
  98. struct scatterlist *out_sg;
  99. unsigned int nb_out_sg;
  100. size_t bufcnt;
  101. u8 buf_in[ATMEL_AES_DMA_THRESHOLD] __aligned(sizeof(u32));
  102. int dma_in;
  103. struct atmel_aes_dma dma_lch_in;
  104. u8 buf_out[ATMEL_AES_DMA_THRESHOLD] __aligned(sizeof(u32));
  105. int dma_out;
  106. struct atmel_aes_dma dma_lch_out;
  107. u32 hw_version;
  108. };
  109. struct atmel_aes_drv {
  110. struct list_head dev_list;
  111. spinlock_t lock;
  112. };
  113. static struct atmel_aes_drv atmel_aes = {
  114. .dev_list = LIST_HEAD_INIT(atmel_aes.dev_list),
  115. .lock = __SPIN_LOCK_UNLOCKED(atmel_aes.lock),
  116. };
  117. static int atmel_aes_sg_length(struct ablkcipher_request *req,
  118. struct scatterlist *sg)
  119. {
  120. unsigned int total = req->nbytes;
  121. int sg_nb;
  122. unsigned int len;
  123. struct scatterlist *sg_list;
  124. sg_nb = 0;
  125. sg_list = sg;
  126. total = req->nbytes;
  127. while (total) {
  128. len = min(sg_list->length, total);
  129. sg_nb++;
  130. total -= len;
  131. sg_list = sg_next(sg_list);
  132. if (!sg_list)
  133. total = 0;
  134. }
  135. return sg_nb;
  136. }
  137. static inline u32 atmel_aes_read(struct atmel_aes_dev *dd, u32 offset)
  138. {
  139. return readl_relaxed(dd->io_base + offset);
  140. }
  141. static inline void atmel_aes_write(struct atmel_aes_dev *dd,
  142. u32 offset, u32 value)
  143. {
  144. writel_relaxed(value, dd->io_base + offset);
  145. }
  146. static void atmel_aes_read_n(struct atmel_aes_dev *dd, u32 offset,
  147. u32 *value, int count)
  148. {
  149. for (; count--; value++, offset += 4)
  150. *value = atmel_aes_read(dd, offset);
  151. }
  152. static void atmel_aes_write_n(struct atmel_aes_dev *dd, u32 offset,
  153. u32 *value, int count)
  154. {
  155. for (; count--; value++, offset += 4)
  156. atmel_aes_write(dd, offset, *value);
  157. }
  158. static void atmel_aes_dualbuff_test(struct atmel_aes_dev *dd)
  159. {
  160. atmel_aes_write(dd, AES_MR, AES_MR_DUALBUFF);
  161. if (atmel_aes_read(dd, AES_MR) & AES_MR_DUALBUFF)
  162. dd->flags |= AES_FLAGS_DUALBUFF;
  163. }
  164. static struct atmel_aes_dev *atmel_aes_find_dev(struct atmel_aes_ctx *ctx)
  165. {
  166. struct atmel_aes_dev *aes_dd = NULL;
  167. struct atmel_aes_dev *tmp;
  168. spin_lock_bh(&atmel_aes.lock);
  169. if (!ctx->dd) {
  170. list_for_each_entry(tmp, &atmel_aes.dev_list, list) {
  171. aes_dd = tmp;
  172. break;
  173. }
  174. ctx->dd = aes_dd;
  175. } else {
  176. aes_dd = ctx->dd;
  177. }
  178. spin_unlock_bh(&atmel_aes.lock);
  179. return aes_dd;
  180. }
  181. static int atmel_aes_hw_init(struct atmel_aes_dev *dd)
  182. {
  183. clk_prepare_enable(dd->iclk);
  184. if (!(dd->flags & AES_FLAGS_INIT)) {
  185. atmel_aes_write(dd, AES_CR, AES_CR_SWRST);
  186. atmel_aes_dualbuff_test(dd);
  187. dd->flags |= AES_FLAGS_INIT;
  188. dd->err = 0;
  189. }
  190. return 0;
  191. }
  192. static void atmel_aes_hw_version_init(struct atmel_aes_dev *dd)
  193. {
  194. atmel_aes_hw_init(dd);
  195. dd->hw_version = atmel_aes_read(dd, AES_HW_VERSION);
  196. clk_disable_unprepare(dd->iclk);
  197. }
  198. static void atmel_aes_finish_req(struct atmel_aes_dev *dd, int err)
  199. {
  200. struct ablkcipher_request *req = dd->req;
  201. clk_disable_unprepare(dd->iclk);
  202. dd->flags &= ~AES_FLAGS_BUSY;
  203. req->base.complete(&req->base, err);
  204. }
  205. static void atmel_aes_dma_callback(void *data)
  206. {
  207. struct atmel_aes_dev *dd = data;
  208. /* dma_lch_out - completed */
  209. tasklet_schedule(&dd->done_task);
  210. }
  211. static int atmel_aes_crypt_dma(struct atmel_aes_dev *dd)
  212. {
  213. struct dma_async_tx_descriptor *in_desc, *out_desc;
  214. int nb_dma_sg_in, nb_dma_sg_out;
  215. dd->nb_in_sg = atmel_aes_sg_length(dd->req, dd->in_sg);
  216. if (!dd->nb_in_sg)
  217. goto exit_err;
  218. nb_dma_sg_in = dma_map_sg(dd->dev, dd->in_sg, dd->nb_in_sg,
  219. DMA_TO_DEVICE);
  220. if (!nb_dma_sg_in)
  221. goto exit_err;
  222. in_desc = dmaengine_prep_slave_sg(dd->dma_lch_in.chan, dd->in_sg,
  223. nb_dma_sg_in, DMA_MEM_TO_DEV,
  224. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  225. if (!in_desc)
  226. goto unmap_in;
  227. /* callback not needed */
  228. dd->nb_out_sg = atmel_aes_sg_length(dd->req, dd->out_sg);
  229. if (!dd->nb_out_sg)
  230. goto unmap_in;
  231. nb_dma_sg_out = dma_map_sg(dd->dev, dd->out_sg, dd->nb_out_sg,
  232. DMA_FROM_DEVICE);
  233. if (!nb_dma_sg_out)
  234. goto unmap_out;
  235. out_desc = dmaengine_prep_slave_sg(dd->dma_lch_out.chan, dd->out_sg,
  236. nb_dma_sg_out, DMA_DEV_TO_MEM,
  237. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  238. if (!out_desc)
  239. goto unmap_out;
  240. out_desc->callback = atmel_aes_dma_callback;
  241. out_desc->callback_param = dd;
  242. dd->total -= dd->req->nbytes;
  243. dmaengine_submit(out_desc);
  244. dma_async_issue_pending(dd->dma_lch_out.chan);
  245. dmaengine_submit(in_desc);
  246. dma_async_issue_pending(dd->dma_lch_in.chan);
  247. return 0;
  248. unmap_out:
  249. dma_unmap_sg(dd->dev, dd->out_sg, dd->nb_out_sg,
  250. DMA_FROM_DEVICE);
  251. unmap_in:
  252. dma_unmap_sg(dd->dev, dd->in_sg, dd->nb_in_sg,
  253. DMA_TO_DEVICE);
  254. exit_err:
  255. return -EINVAL;
  256. }
  257. static int atmel_aes_crypt_cpu_start(struct atmel_aes_dev *dd)
  258. {
  259. dd->flags &= ~AES_FLAGS_DMA;
  260. /* use cache buffers */
  261. dd->nb_in_sg = atmel_aes_sg_length(dd->req, dd->in_sg);
  262. if (!dd->nb_in_sg)
  263. return -EINVAL;
  264. dd->nb_out_sg = atmel_aes_sg_length(dd->req, dd->out_sg);
  265. if (!dd->nb_in_sg)
  266. return -EINVAL;
  267. dd->bufcnt = sg_copy_to_buffer(dd->in_sg, dd->nb_in_sg,
  268. dd->buf_in, dd->total);
  269. if (!dd->bufcnt)
  270. return -EINVAL;
  271. dd->total -= dd->bufcnt;
  272. atmel_aes_write(dd, AES_IER, AES_INT_DATARDY);
  273. atmel_aes_write_n(dd, AES_IDATAR(0), (u32 *) dd->buf_in,
  274. dd->bufcnt >> 2);
  275. return 0;
  276. }
  277. static int atmel_aes_crypt_dma_start(struct atmel_aes_dev *dd)
  278. {
  279. int err;
  280. if (dd->flags & AES_FLAGS_CFB8) {
  281. dd->dma_lch_in.dma_conf.dst_addr_width =
  282. DMA_SLAVE_BUSWIDTH_1_BYTE;
  283. dd->dma_lch_out.dma_conf.src_addr_width =
  284. DMA_SLAVE_BUSWIDTH_1_BYTE;
  285. } else if (dd->flags & AES_FLAGS_CFB16) {
  286. dd->dma_lch_in.dma_conf.dst_addr_width =
  287. DMA_SLAVE_BUSWIDTH_2_BYTES;
  288. dd->dma_lch_out.dma_conf.src_addr_width =
  289. DMA_SLAVE_BUSWIDTH_2_BYTES;
  290. } else {
  291. dd->dma_lch_in.dma_conf.dst_addr_width =
  292. DMA_SLAVE_BUSWIDTH_4_BYTES;
  293. dd->dma_lch_out.dma_conf.src_addr_width =
  294. DMA_SLAVE_BUSWIDTH_4_BYTES;
  295. }
  296. dmaengine_slave_config(dd->dma_lch_in.chan, &dd->dma_lch_in.dma_conf);
  297. dmaengine_slave_config(dd->dma_lch_out.chan, &dd->dma_lch_out.dma_conf);
  298. dd->flags |= AES_FLAGS_DMA;
  299. err = atmel_aes_crypt_dma(dd);
  300. return err;
  301. }
  302. static int atmel_aes_write_ctrl(struct atmel_aes_dev *dd)
  303. {
  304. int err;
  305. u32 valcr = 0, valmr = 0;
  306. err = atmel_aes_hw_init(dd);
  307. if (err)
  308. return err;
  309. /* MR register must be set before IV registers */
  310. if (dd->ctx->keylen == AES_KEYSIZE_128)
  311. valmr |= AES_MR_KEYSIZE_128;
  312. else if (dd->ctx->keylen == AES_KEYSIZE_192)
  313. valmr |= AES_MR_KEYSIZE_192;
  314. else
  315. valmr |= AES_MR_KEYSIZE_256;
  316. if (dd->flags & AES_FLAGS_CBC) {
  317. valmr |= AES_MR_OPMOD_CBC;
  318. } else if (dd->flags & AES_FLAGS_CFB) {
  319. valmr |= AES_MR_OPMOD_CFB;
  320. if (dd->flags & AES_FLAGS_CFB8)
  321. valmr |= AES_MR_CFBS_8b;
  322. else if (dd->flags & AES_FLAGS_CFB16)
  323. valmr |= AES_MR_CFBS_16b;
  324. else if (dd->flags & AES_FLAGS_CFB32)
  325. valmr |= AES_MR_CFBS_32b;
  326. else if (dd->flags & AES_FLAGS_CFB64)
  327. valmr |= AES_MR_CFBS_64b;
  328. } else if (dd->flags & AES_FLAGS_OFB) {
  329. valmr |= AES_MR_OPMOD_OFB;
  330. } else if (dd->flags & AES_FLAGS_CTR) {
  331. valmr |= AES_MR_OPMOD_CTR;
  332. } else {
  333. valmr |= AES_MR_OPMOD_ECB;
  334. }
  335. if (dd->flags & AES_FLAGS_ENCRYPT)
  336. valmr |= AES_MR_CYPHER_ENC;
  337. if (dd->total > ATMEL_AES_DMA_THRESHOLD) {
  338. valmr |= AES_MR_SMOD_IDATAR0;
  339. if (dd->flags & AES_FLAGS_DUALBUFF)
  340. valmr |= AES_MR_DUALBUFF;
  341. } else {
  342. valmr |= AES_MR_SMOD_AUTO;
  343. }
  344. atmel_aes_write(dd, AES_CR, valcr);
  345. atmel_aes_write(dd, AES_MR, valmr);
  346. atmel_aes_write_n(dd, AES_KEYWR(0), dd->ctx->key,
  347. dd->ctx->keylen >> 2);
  348. if (((dd->flags & AES_FLAGS_CBC) || (dd->flags & AES_FLAGS_CFB) ||
  349. (dd->flags & AES_FLAGS_OFB) || (dd->flags & AES_FLAGS_CTR)) &&
  350. dd->req->info) {
  351. atmel_aes_write_n(dd, AES_IVR(0), dd->req->info, 4);
  352. }
  353. return 0;
  354. }
  355. static int atmel_aes_handle_queue(struct atmel_aes_dev *dd,
  356. struct ablkcipher_request *req)
  357. {
  358. struct crypto_async_request *async_req, *backlog;
  359. struct atmel_aes_ctx *ctx;
  360. struct atmel_aes_reqctx *rctx;
  361. unsigned long flags;
  362. int err, ret = 0;
  363. spin_lock_irqsave(&dd->lock, flags);
  364. if (req)
  365. ret = ablkcipher_enqueue_request(&dd->queue, req);
  366. if (dd->flags & AES_FLAGS_BUSY) {
  367. spin_unlock_irqrestore(&dd->lock, flags);
  368. return ret;
  369. }
  370. backlog = crypto_get_backlog(&dd->queue);
  371. async_req = crypto_dequeue_request(&dd->queue);
  372. if (async_req)
  373. dd->flags |= AES_FLAGS_BUSY;
  374. spin_unlock_irqrestore(&dd->lock, flags);
  375. if (!async_req)
  376. return ret;
  377. if (backlog)
  378. backlog->complete(backlog, -EINPROGRESS);
  379. req = ablkcipher_request_cast(async_req);
  380. /* assign new request to device */
  381. dd->req = req;
  382. dd->total = req->nbytes;
  383. dd->in_sg = req->src;
  384. dd->out_sg = req->dst;
  385. rctx = ablkcipher_request_ctx(req);
  386. ctx = crypto_ablkcipher_ctx(crypto_ablkcipher_reqtfm(req));
  387. rctx->mode &= AES_FLAGS_MODE_MASK;
  388. dd->flags = (dd->flags & ~AES_FLAGS_MODE_MASK) | rctx->mode;
  389. dd->ctx = ctx;
  390. ctx->dd = dd;
  391. err = atmel_aes_write_ctrl(dd);
  392. if (!err) {
  393. if (dd->total > ATMEL_AES_DMA_THRESHOLD)
  394. err = atmel_aes_crypt_dma_start(dd);
  395. else
  396. err = atmel_aes_crypt_cpu_start(dd);
  397. }
  398. if (err) {
  399. /* aes_task will not finish it, so do it here */
  400. atmel_aes_finish_req(dd, err);
  401. tasklet_schedule(&dd->queue_task);
  402. }
  403. return ret;
  404. }
  405. static int atmel_aes_crypt_dma_stop(struct atmel_aes_dev *dd)
  406. {
  407. int err = -EINVAL;
  408. if (dd->flags & AES_FLAGS_DMA) {
  409. dma_unmap_sg(dd->dev, dd->out_sg,
  410. dd->nb_out_sg, DMA_FROM_DEVICE);
  411. dma_unmap_sg(dd->dev, dd->in_sg,
  412. dd->nb_in_sg, DMA_TO_DEVICE);
  413. err = 0;
  414. }
  415. return err;
  416. }
  417. static int atmel_aes_crypt(struct ablkcipher_request *req, unsigned long mode)
  418. {
  419. struct atmel_aes_ctx *ctx = crypto_ablkcipher_ctx(
  420. crypto_ablkcipher_reqtfm(req));
  421. struct atmel_aes_reqctx *rctx = ablkcipher_request_ctx(req);
  422. struct atmel_aes_dev *dd;
  423. if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE)) {
  424. pr_err("request size is not exact amount of AES blocks\n");
  425. return -EINVAL;
  426. }
  427. dd = atmel_aes_find_dev(ctx);
  428. if (!dd)
  429. return -ENODEV;
  430. rctx->mode = mode;
  431. return atmel_aes_handle_queue(dd, req);
  432. }
  433. static bool atmel_aes_filter(struct dma_chan *chan, void *slave)
  434. {
  435. struct at_dma_slave *sl = slave;
  436. if (sl && sl->dma_dev == chan->device->dev) {
  437. chan->private = sl;
  438. return true;
  439. } else {
  440. return false;
  441. }
  442. }
  443. static int atmel_aes_dma_init(struct atmel_aes_dev *dd)
  444. {
  445. int err = -ENOMEM;
  446. struct aes_platform_data *pdata;
  447. dma_cap_mask_t mask_in, mask_out;
  448. pdata = dd->dev->platform_data;
  449. if (pdata && pdata->dma_slave->txdata.dma_dev &&
  450. pdata->dma_slave->rxdata.dma_dev) {
  451. /* Try to grab 2 DMA channels */
  452. dma_cap_zero(mask_in);
  453. dma_cap_set(DMA_SLAVE, mask_in);
  454. dd->dma_lch_in.chan = dma_request_channel(mask_in,
  455. atmel_aes_filter, &pdata->dma_slave->rxdata);
  456. if (!dd->dma_lch_in.chan)
  457. goto err_dma_in;
  458. dd->dma_lch_in.dma_conf.direction = DMA_MEM_TO_DEV;
  459. dd->dma_lch_in.dma_conf.dst_addr = dd->phys_base +
  460. AES_IDATAR(0);
  461. dd->dma_lch_in.dma_conf.src_maxburst = 1;
  462. dd->dma_lch_in.dma_conf.dst_maxburst = 1;
  463. dd->dma_lch_in.dma_conf.device_fc = false;
  464. dma_cap_zero(mask_out);
  465. dma_cap_set(DMA_SLAVE, mask_out);
  466. dd->dma_lch_out.chan = dma_request_channel(mask_out,
  467. atmel_aes_filter, &pdata->dma_slave->txdata);
  468. if (!dd->dma_lch_out.chan)
  469. goto err_dma_out;
  470. dd->dma_lch_out.dma_conf.direction = DMA_DEV_TO_MEM;
  471. dd->dma_lch_out.dma_conf.src_addr = dd->phys_base +
  472. AES_ODATAR(0);
  473. dd->dma_lch_out.dma_conf.src_maxburst = 1;
  474. dd->dma_lch_out.dma_conf.dst_maxburst = 1;
  475. dd->dma_lch_out.dma_conf.device_fc = false;
  476. return 0;
  477. } else {
  478. return -ENODEV;
  479. }
  480. err_dma_out:
  481. dma_release_channel(dd->dma_lch_in.chan);
  482. err_dma_in:
  483. return err;
  484. }
  485. static void atmel_aes_dma_cleanup(struct atmel_aes_dev *dd)
  486. {
  487. dma_release_channel(dd->dma_lch_in.chan);
  488. dma_release_channel(dd->dma_lch_out.chan);
  489. }
  490. static int atmel_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
  491. unsigned int keylen)
  492. {
  493. struct atmel_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
  494. if (keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_192 &&
  495. keylen != AES_KEYSIZE_256) {
  496. crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
  497. return -EINVAL;
  498. }
  499. memcpy(ctx->key, key, keylen);
  500. ctx->keylen = keylen;
  501. return 0;
  502. }
  503. static int atmel_aes_ecb_encrypt(struct ablkcipher_request *req)
  504. {
  505. return atmel_aes_crypt(req,
  506. AES_FLAGS_ENCRYPT);
  507. }
  508. static int atmel_aes_ecb_decrypt(struct ablkcipher_request *req)
  509. {
  510. return atmel_aes_crypt(req,
  511. 0);
  512. }
  513. static int atmel_aes_cbc_encrypt(struct ablkcipher_request *req)
  514. {
  515. return atmel_aes_crypt(req,
  516. AES_FLAGS_ENCRYPT | AES_FLAGS_CBC);
  517. }
  518. static int atmel_aes_cbc_decrypt(struct ablkcipher_request *req)
  519. {
  520. return atmel_aes_crypt(req,
  521. AES_FLAGS_CBC);
  522. }
  523. static int atmel_aes_ofb_encrypt(struct ablkcipher_request *req)
  524. {
  525. return atmel_aes_crypt(req,
  526. AES_FLAGS_ENCRYPT | AES_FLAGS_OFB);
  527. }
  528. static int atmel_aes_ofb_decrypt(struct ablkcipher_request *req)
  529. {
  530. return atmel_aes_crypt(req,
  531. AES_FLAGS_OFB);
  532. }
  533. static int atmel_aes_cfb_encrypt(struct ablkcipher_request *req)
  534. {
  535. return atmel_aes_crypt(req,
  536. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB);
  537. }
  538. static int atmel_aes_cfb_decrypt(struct ablkcipher_request *req)
  539. {
  540. return atmel_aes_crypt(req,
  541. AES_FLAGS_CFB);
  542. }
  543. static int atmel_aes_cfb64_encrypt(struct ablkcipher_request *req)
  544. {
  545. return atmel_aes_crypt(req,
  546. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB | AES_FLAGS_CFB64);
  547. }
  548. static int atmel_aes_cfb64_decrypt(struct ablkcipher_request *req)
  549. {
  550. return atmel_aes_crypt(req,
  551. AES_FLAGS_CFB | AES_FLAGS_CFB64);
  552. }
  553. static int atmel_aes_cfb32_encrypt(struct ablkcipher_request *req)
  554. {
  555. return atmel_aes_crypt(req,
  556. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB | AES_FLAGS_CFB32);
  557. }
  558. static int atmel_aes_cfb32_decrypt(struct ablkcipher_request *req)
  559. {
  560. return atmel_aes_crypt(req,
  561. AES_FLAGS_CFB | AES_FLAGS_CFB32);
  562. }
  563. static int atmel_aes_cfb16_encrypt(struct ablkcipher_request *req)
  564. {
  565. return atmel_aes_crypt(req,
  566. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB | AES_FLAGS_CFB16);
  567. }
  568. static int atmel_aes_cfb16_decrypt(struct ablkcipher_request *req)
  569. {
  570. return atmel_aes_crypt(req,
  571. AES_FLAGS_CFB | AES_FLAGS_CFB16);
  572. }
  573. static int atmel_aes_cfb8_encrypt(struct ablkcipher_request *req)
  574. {
  575. return atmel_aes_crypt(req,
  576. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB | AES_FLAGS_CFB8);
  577. }
  578. static int atmel_aes_cfb8_decrypt(struct ablkcipher_request *req)
  579. {
  580. return atmel_aes_crypt(req,
  581. AES_FLAGS_CFB | AES_FLAGS_CFB8);
  582. }
  583. static int atmel_aes_ctr_encrypt(struct ablkcipher_request *req)
  584. {
  585. return atmel_aes_crypt(req,
  586. AES_FLAGS_ENCRYPT | AES_FLAGS_CTR);
  587. }
  588. static int atmel_aes_ctr_decrypt(struct ablkcipher_request *req)
  589. {
  590. return atmel_aes_crypt(req,
  591. AES_FLAGS_CTR);
  592. }
  593. static int atmel_aes_cra_init(struct crypto_tfm *tfm)
  594. {
  595. tfm->crt_ablkcipher.reqsize = sizeof(struct atmel_aes_reqctx);
  596. return 0;
  597. }
  598. static void atmel_aes_cra_exit(struct crypto_tfm *tfm)
  599. {
  600. }
  601. static struct crypto_alg aes_algs[] = {
  602. {
  603. .cra_name = "ecb(aes)",
  604. .cra_driver_name = "atmel-ecb-aes",
  605. .cra_priority = 100,
  606. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  607. .cra_blocksize = AES_BLOCK_SIZE,
  608. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  609. .cra_alignmask = 0x0,
  610. .cra_type = &crypto_ablkcipher_type,
  611. .cra_module = THIS_MODULE,
  612. .cra_init = atmel_aes_cra_init,
  613. .cra_exit = atmel_aes_cra_exit,
  614. .cra_u.ablkcipher = {
  615. .min_keysize = AES_MIN_KEY_SIZE,
  616. .max_keysize = AES_MAX_KEY_SIZE,
  617. .setkey = atmel_aes_setkey,
  618. .encrypt = atmel_aes_ecb_encrypt,
  619. .decrypt = atmel_aes_ecb_decrypt,
  620. }
  621. },
  622. {
  623. .cra_name = "cbc(aes)",
  624. .cra_driver_name = "atmel-cbc-aes",
  625. .cra_priority = 100,
  626. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  627. .cra_blocksize = AES_BLOCK_SIZE,
  628. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  629. .cra_alignmask = 0x0,
  630. .cra_type = &crypto_ablkcipher_type,
  631. .cra_module = THIS_MODULE,
  632. .cra_init = atmel_aes_cra_init,
  633. .cra_exit = atmel_aes_cra_exit,
  634. .cra_u.ablkcipher = {
  635. .min_keysize = AES_MIN_KEY_SIZE,
  636. .max_keysize = AES_MAX_KEY_SIZE,
  637. .ivsize = AES_BLOCK_SIZE,
  638. .setkey = atmel_aes_setkey,
  639. .encrypt = atmel_aes_cbc_encrypt,
  640. .decrypt = atmel_aes_cbc_decrypt,
  641. }
  642. },
  643. {
  644. .cra_name = "ofb(aes)",
  645. .cra_driver_name = "atmel-ofb-aes",
  646. .cra_priority = 100,
  647. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  648. .cra_blocksize = AES_BLOCK_SIZE,
  649. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  650. .cra_alignmask = 0x0,
  651. .cra_type = &crypto_ablkcipher_type,
  652. .cra_module = THIS_MODULE,
  653. .cra_init = atmel_aes_cra_init,
  654. .cra_exit = atmel_aes_cra_exit,
  655. .cra_u.ablkcipher = {
  656. .min_keysize = AES_MIN_KEY_SIZE,
  657. .max_keysize = AES_MAX_KEY_SIZE,
  658. .ivsize = AES_BLOCK_SIZE,
  659. .setkey = atmel_aes_setkey,
  660. .encrypt = atmel_aes_ofb_encrypt,
  661. .decrypt = atmel_aes_ofb_decrypt,
  662. }
  663. },
  664. {
  665. .cra_name = "cfb(aes)",
  666. .cra_driver_name = "atmel-cfb-aes",
  667. .cra_priority = 100,
  668. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  669. .cra_blocksize = AES_BLOCK_SIZE,
  670. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  671. .cra_alignmask = 0x0,
  672. .cra_type = &crypto_ablkcipher_type,
  673. .cra_module = THIS_MODULE,
  674. .cra_init = atmel_aes_cra_init,
  675. .cra_exit = atmel_aes_cra_exit,
  676. .cra_u.ablkcipher = {
  677. .min_keysize = AES_MIN_KEY_SIZE,
  678. .max_keysize = AES_MAX_KEY_SIZE,
  679. .ivsize = AES_BLOCK_SIZE,
  680. .setkey = atmel_aes_setkey,
  681. .encrypt = atmel_aes_cfb_encrypt,
  682. .decrypt = atmel_aes_cfb_decrypt,
  683. }
  684. },
  685. {
  686. .cra_name = "cfb32(aes)",
  687. .cra_driver_name = "atmel-cfb32-aes",
  688. .cra_priority = 100,
  689. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  690. .cra_blocksize = CFB32_BLOCK_SIZE,
  691. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  692. .cra_alignmask = 0x0,
  693. .cra_type = &crypto_ablkcipher_type,
  694. .cra_module = THIS_MODULE,
  695. .cra_init = atmel_aes_cra_init,
  696. .cra_exit = atmel_aes_cra_exit,
  697. .cra_u.ablkcipher = {
  698. .min_keysize = AES_MIN_KEY_SIZE,
  699. .max_keysize = AES_MAX_KEY_SIZE,
  700. .ivsize = AES_BLOCK_SIZE,
  701. .setkey = atmel_aes_setkey,
  702. .encrypt = atmel_aes_cfb32_encrypt,
  703. .decrypt = atmel_aes_cfb32_decrypt,
  704. }
  705. },
  706. {
  707. .cra_name = "cfb16(aes)",
  708. .cra_driver_name = "atmel-cfb16-aes",
  709. .cra_priority = 100,
  710. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  711. .cra_blocksize = CFB16_BLOCK_SIZE,
  712. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  713. .cra_alignmask = 0x0,
  714. .cra_type = &crypto_ablkcipher_type,
  715. .cra_module = THIS_MODULE,
  716. .cra_init = atmel_aes_cra_init,
  717. .cra_exit = atmel_aes_cra_exit,
  718. .cra_u.ablkcipher = {
  719. .min_keysize = AES_MIN_KEY_SIZE,
  720. .max_keysize = AES_MAX_KEY_SIZE,
  721. .ivsize = AES_BLOCK_SIZE,
  722. .setkey = atmel_aes_setkey,
  723. .encrypt = atmel_aes_cfb16_encrypt,
  724. .decrypt = atmel_aes_cfb16_decrypt,
  725. }
  726. },
  727. {
  728. .cra_name = "cfb8(aes)",
  729. .cra_driver_name = "atmel-cfb8-aes",
  730. .cra_priority = 100,
  731. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  732. .cra_blocksize = CFB64_BLOCK_SIZE,
  733. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  734. .cra_alignmask = 0x0,
  735. .cra_type = &crypto_ablkcipher_type,
  736. .cra_module = THIS_MODULE,
  737. .cra_init = atmel_aes_cra_init,
  738. .cra_exit = atmel_aes_cra_exit,
  739. .cra_u.ablkcipher = {
  740. .min_keysize = AES_MIN_KEY_SIZE,
  741. .max_keysize = AES_MAX_KEY_SIZE,
  742. .ivsize = AES_BLOCK_SIZE,
  743. .setkey = atmel_aes_setkey,
  744. .encrypt = atmel_aes_cfb8_encrypt,
  745. .decrypt = atmel_aes_cfb8_decrypt,
  746. }
  747. },
  748. {
  749. .cra_name = "ctr(aes)",
  750. .cra_driver_name = "atmel-ctr-aes",
  751. .cra_priority = 100,
  752. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  753. .cra_blocksize = AES_BLOCK_SIZE,
  754. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  755. .cra_alignmask = 0x0,
  756. .cra_type = &crypto_ablkcipher_type,
  757. .cra_module = THIS_MODULE,
  758. .cra_init = atmel_aes_cra_init,
  759. .cra_exit = atmel_aes_cra_exit,
  760. .cra_u.ablkcipher = {
  761. .min_keysize = AES_MIN_KEY_SIZE,
  762. .max_keysize = AES_MAX_KEY_SIZE,
  763. .ivsize = AES_BLOCK_SIZE,
  764. .setkey = atmel_aes_setkey,
  765. .encrypt = atmel_aes_ctr_encrypt,
  766. .decrypt = atmel_aes_ctr_decrypt,
  767. }
  768. },
  769. };
  770. static struct crypto_alg aes_cfb64_alg[] = {
  771. {
  772. .cra_name = "cfb64(aes)",
  773. .cra_driver_name = "atmel-cfb64-aes",
  774. .cra_priority = 100,
  775. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  776. .cra_blocksize = CFB64_BLOCK_SIZE,
  777. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  778. .cra_alignmask = 0x0,
  779. .cra_type = &crypto_ablkcipher_type,
  780. .cra_module = THIS_MODULE,
  781. .cra_init = atmel_aes_cra_init,
  782. .cra_exit = atmel_aes_cra_exit,
  783. .cra_u.ablkcipher = {
  784. .min_keysize = AES_MIN_KEY_SIZE,
  785. .max_keysize = AES_MAX_KEY_SIZE,
  786. .ivsize = AES_BLOCK_SIZE,
  787. .setkey = atmel_aes_setkey,
  788. .encrypt = atmel_aes_cfb64_encrypt,
  789. .decrypt = atmel_aes_cfb64_decrypt,
  790. }
  791. },
  792. };
  793. static void atmel_aes_queue_task(unsigned long data)
  794. {
  795. struct atmel_aes_dev *dd = (struct atmel_aes_dev *)data;
  796. atmel_aes_handle_queue(dd, NULL);
  797. }
  798. static void atmel_aes_done_task(unsigned long data)
  799. {
  800. struct atmel_aes_dev *dd = (struct atmel_aes_dev *) data;
  801. int err;
  802. if (!(dd->flags & AES_FLAGS_DMA)) {
  803. atmel_aes_read_n(dd, AES_ODATAR(0), (u32 *) dd->buf_out,
  804. dd->bufcnt >> 2);
  805. if (sg_copy_from_buffer(dd->out_sg, dd->nb_out_sg,
  806. dd->buf_out, dd->bufcnt))
  807. err = 0;
  808. else
  809. err = -EINVAL;
  810. goto cpu_end;
  811. }
  812. err = atmel_aes_crypt_dma_stop(dd);
  813. err = dd->err ? : err;
  814. if (dd->total && !err) {
  815. err = atmel_aes_crypt_dma_start(dd);
  816. if (!err)
  817. return; /* DMA started. Not fininishing. */
  818. }
  819. cpu_end:
  820. atmel_aes_finish_req(dd, err);
  821. atmel_aes_handle_queue(dd, NULL);
  822. }
  823. static irqreturn_t atmel_aes_irq(int irq, void *dev_id)
  824. {
  825. struct atmel_aes_dev *aes_dd = dev_id;
  826. u32 reg;
  827. reg = atmel_aes_read(aes_dd, AES_ISR);
  828. if (reg & atmel_aes_read(aes_dd, AES_IMR)) {
  829. atmel_aes_write(aes_dd, AES_IDR, reg);
  830. if (AES_FLAGS_BUSY & aes_dd->flags)
  831. tasklet_schedule(&aes_dd->done_task);
  832. else
  833. dev_warn(aes_dd->dev, "AES interrupt when no active requests.\n");
  834. return IRQ_HANDLED;
  835. }
  836. return IRQ_NONE;
  837. }
  838. static void atmel_aes_unregister_algs(struct atmel_aes_dev *dd)
  839. {
  840. int i;
  841. for (i = 0; i < ARRAY_SIZE(aes_algs); i++)
  842. crypto_unregister_alg(&aes_algs[i]);
  843. if (dd->hw_version >= 0x130)
  844. crypto_unregister_alg(&aes_cfb64_alg[0]);
  845. }
  846. static int atmel_aes_register_algs(struct atmel_aes_dev *dd)
  847. {
  848. int err, i, j;
  849. for (i = 0; i < ARRAY_SIZE(aes_algs); i++) {
  850. err = crypto_register_alg(&aes_algs[i]);
  851. if (err)
  852. goto err_aes_algs;
  853. }
  854. atmel_aes_hw_version_init(dd);
  855. if (dd->hw_version >= 0x130) {
  856. err = crypto_register_alg(&aes_cfb64_alg[0]);
  857. if (err)
  858. goto err_aes_cfb64_alg;
  859. }
  860. return 0;
  861. err_aes_cfb64_alg:
  862. i = ARRAY_SIZE(aes_algs);
  863. err_aes_algs:
  864. for (j = 0; j < i; j++)
  865. crypto_unregister_alg(&aes_algs[j]);
  866. return err;
  867. }
  868. static int __devinit atmel_aes_probe(struct platform_device *pdev)
  869. {
  870. struct atmel_aes_dev *aes_dd;
  871. struct aes_platform_data *pdata;
  872. struct device *dev = &pdev->dev;
  873. struct resource *aes_res;
  874. unsigned long aes_phys_size;
  875. int err;
  876. pdata = pdev->dev.platform_data;
  877. if (!pdata) {
  878. err = -ENXIO;
  879. goto aes_dd_err;
  880. }
  881. aes_dd = kzalloc(sizeof(struct atmel_aes_dev), GFP_KERNEL);
  882. if (aes_dd == NULL) {
  883. dev_err(dev, "unable to alloc data struct.\n");
  884. err = -ENOMEM;
  885. goto aes_dd_err;
  886. }
  887. aes_dd->dev = dev;
  888. platform_set_drvdata(pdev, aes_dd);
  889. INIT_LIST_HEAD(&aes_dd->list);
  890. tasklet_init(&aes_dd->done_task, atmel_aes_done_task,
  891. (unsigned long)aes_dd);
  892. tasklet_init(&aes_dd->queue_task, atmel_aes_queue_task,
  893. (unsigned long)aes_dd);
  894. crypto_init_queue(&aes_dd->queue, ATMEL_AES_QUEUE_LENGTH);
  895. aes_dd->irq = -1;
  896. /* Get the base address */
  897. aes_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  898. if (!aes_res) {
  899. dev_err(dev, "no MEM resource info\n");
  900. err = -ENODEV;
  901. goto res_err;
  902. }
  903. aes_dd->phys_base = aes_res->start;
  904. aes_phys_size = resource_size(aes_res);
  905. /* Get the IRQ */
  906. aes_dd->irq = platform_get_irq(pdev, 0);
  907. if (aes_dd->irq < 0) {
  908. dev_err(dev, "no IRQ resource info\n");
  909. err = aes_dd->irq;
  910. goto aes_irq_err;
  911. }
  912. err = request_irq(aes_dd->irq, atmel_aes_irq, IRQF_SHARED, "atmel-aes",
  913. aes_dd);
  914. if (err) {
  915. dev_err(dev, "unable to request aes irq.\n");
  916. goto aes_irq_err;
  917. }
  918. /* Initializing the clock */
  919. aes_dd->iclk = clk_get(&pdev->dev, NULL);
  920. if (IS_ERR(aes_dd->iclk)) {
  921. dev_err(dev, "clock intialization failed.\n");
  922. err = PTR_ERR(aes_dd->iclk);
  923. goto clk_err;
  924. }
  925. aes_dd->io_base = ioremap(aes_dd->phys_base, aes_phys_size);
  926. if (!aes_dd->io_base) {
  927. dev_err(dev, "can't ioremap\n");
  928. err = -ENOMEM;
  929. goto aes_io_err;
  930. }
  931. err = atmel_aes_dma_init(aes_dd);
  932. if (err)
  933. goto err_aes_dma;
  934. spin_lock(&atmel_aes.lock);
  935. list_add_tail(&aes_dd->list, &atmel_aes.dev_list);
  936. spin_unlock(&atmel_aes.lock);
  937. err = atmel_aes_register_algs(aes_dd);
  938. if (err)
  939. goto err_algs;
  940. dev_info(dev, "Atmel AES\n");
  941. return 0;
  942. err_algs:
  943. spin_lock(&atmel_aes.lock);
  944. list_del(&aes_dd->list);
  945. spin_unlock(&atmel_aes.lock);
  946. atmel_aes_dma_cleanup(aes_dd);
  947. err_aes_dma:
  948. iounmap(aes_dd->io_base);
  949. aes_io_err:
  950. clk_put(aes_dd->iclk);
  951. clk_err:
  952. free_irq(aes_dd->irq, aes_dd);
  953. aes_irq_err:
  954. res_err:
  955. tasklet_kill(&aes_dd->done_task);
  956. tasklet_kill(&aes_dd->queue_task);
  957. kfree(aes_dd);
  958. aes_dd = NULL;
  959. aes_dd_err:
  960. dev_err(dev, "initialization failed.\n");
  961. return err;
  962. }
  963. static int __devexit atmel_aes_remove(struct platform_device *pdev)
  964. {
  965. static struct atmel_aes_dev *aes_dd;
  966. aes_dd = platform_get_drvdata(pdev);
  967. if (!aes_dd)
  968. return -ENODEV;
  969. spin_lock(&atmel_aes.lock);
  970. list_del(&aes_dd->list);
  971. spin_unlock(&atmel_aes.lock);
  972. atmel_aes_unregister_algs(aes_dd);
  973. tasklet_kill(&aes_dd->done_task);
  974. tasklet_kill(&aes_dd->queue_task);
  975. atmel_aes_dma_cleanup(aes_dd);
  976. iounmap(aes_dd->io_base);
  977. clk_put(aes_dd->iclk);
  978. if (aes_dd->irq > 0)
  979. free_irq(aes_dd->irq, aes_dd);
  980. kfree(aes_dd);
  981. aes_dd = NULL;
  982. return 0;
  983. }
  984. static struct platform_driver atmel_aes_driver = {
  985. .probe = atmel_aes_probe,
  986. .remove = __devexit_p(atmel_aes_remove),
  987. .driver = {
  988. .name = "atmel_aes",
  989. .owner = THIS_MODULE,
  990. },
  991. };
  992. module_platform_driver(atmel_aes_driver);
  993. MODULE_DESCRIPTION("Atmel AES hw acceleration support.");
  994. MODULE_LICENSE("GPL v2");
  995. MODULE_AUTHOR("Nicolas Royer - Eukréa Electromatique");