mv_cesa.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. /*
  2. * Support for Marvell's crypto engine which can be found on some Orion5X
  3. * boards.
  4. *
  5. * Author: Sebastian Andrzej Siewior < sebastian at breakpoint dot cc >
  6. * License: GPLv2
  7. *
  8. */
  9. #include <crypto/aes.h>
  10. #include <crypto/algapi.h>
  11. #include <linux/crypto.h>
  12. #include <linux/genalloc.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/io.h>
  15. #include <linux/kthread.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/scatterlist.h>
  18. #include <linux/slab.h>
  19. #include <linux/module.h>
  20. #include <linux/clk.h>
  21. #include <crypto/internal/hash.h>
  22. #include <crypto/sha.h>
  23. #include <linux/of.h>
  24. #include <linux/of_platform.h>
  25. #include <linux/of_irq.h>
  26. #include "mv_cesa.h"
  27. #define MV_CESA "MV-CESA:"
  28. #define MAX_HW_HASH_SIZE 0xFFFF
  29. #define MV_CESA_EXPIRE 500 /* msec */
  30. #define MV_CESA_DEFAULT_SRAM_SIZE 2048
  31. /*
  32. * STM:
  33. * /---------------------------------------\
  34. * | | request complete
  35. * \./ |
  36. * IDLE -> new request -> BUSY -> done -> DEQUEUE
  37. * /°\ |
  38. * | | more scatter entries
  39. * \________________/
  40. */
  41. enum engine_status {
  42. ENGINE_IDLE,
  43. ENGINE_BUSY,
  44. ENGINE_W_DEQUEUE,
  45. };
  46. /**
  47. * struct req_progress - used for every crypt request
  48. * @src_sg_it: sg iterator for src
  49. * @dst_sg_it: sg iterator for dst
  50. * @sg_src_left: bytes left in src to process (scatter list)
  51. * @src_start: offset to add to src start position (scatter list)
  52. * @crypt_len: length of current hw crypt/hash process
  53. * @hw_nbytes: total bytes to process in hw for this request
  54. * @copy_back: whether to copy data back (crypt) or not (hash)
  55. * @sg_dst_left: bytes left dst to process in this scatter list
  56. * @dst_start: offset to add to dst start position (scatter list)
  57. * @hw_processed_bytes: number of bytes processed by hw (request).
  58. *
  59. * sg helper are used to iterate over the scatterlist. Since the size of the
  60. * SRAM may be less than the scatter size, this struct struct is used to keep
  61. * track of progress within current scatterlist.
  62. */
  63. struct req_progress {
  64. struct sg_mapping_iter src_sg_it;
  65. struct sg_mapping_iter dst_sg_it;
  66. void (*complete) (void);
  67. void (*process) (int is_first);
  68. /* src mostly */
  69. int sg_src_left;
  70. int src_start;
  71. int crypt_len;
  72. int hw_nbytes;
  73. /* dst mostly */
  74. int copy_back;
  75. int sg_dst_left;
  76. int dst_start;
  77. int hw_processed_bytes;
  78. };
  79. struct crypto_priv {
  80. void __iomem *reg;
  81. void __iomem *sram;
  82. struct gen_pool *sram_pool;
  83. dma_addr_t sram_dma;
  84. int irq;
  85. struct clk *clk;
  86. struct task_struct *queue_th;
  87. /* the lock protects queue and eng_st */
  88. spinlock_t lock;
  89. struct crypto_queue queue;
  90. enum engine_status eng_st;
  91. struct timer_list completion_timer;
  92. struct crypto_async_request *cur_req;
  93. struct req_progress p;
  94. int max_req_size;
  95. int sram_size;
  96. int has_sha1;
  97. int has_hmac_sha1;
  98. };
  99. static struct crypto_priv *cpg;
  100. struct mv_ctx {
  101. u8 aes_enc_key[AES_KEY_LEN];
  102. u32 aes_dec_key[8];
  103. int key_len;
  104. u32 need_calc_aes_dkey;
  105. };
  106. enum crypto_op {
  107. COP_AES_ECB,
  108. COP_AES_CBC,
  109. };
  110. struct mv_req_ctx {
  111. enum crypto_op op;
  112. int decrypt;
  113. };
  114. enum hash_op {
  115. COP_SHA1,
  116. COP_HMAC_SHA1
  117. };
  118. struct mv_tfm_hash_ctx {
  119. struct crypto_shash *fallback;
  120. struct crypto_shash *base_hash;
  121. u32 ivs[2 * SHA1_DIGEST_SIZE / 4];
  122. int count_add;
  123. enum hash_op op;
  124. };
  125. struct mv_req_hash_ctx {
  126. u64 count;
  127. u32 state[SHA1_DIGEST_SIZE / 4];
  128. u8 buffer[SHA1_BLOCK_SIZE];
  129. int first_hash; /* marks that we don't have previous state */
  130. int last_chunk; /* marks that this is the 'final' request */
  131. int extra_bytes; /* unprocessed bytes in buffer */
  132. enum hash_op op;
  133. int count_add;
  134. };
  135. static void mv_completion_timer_callback(unsigned long unused)
  136. {
  137. int active = readl(cpg->reg + SEC_ACCEL_CMD) & SEC_CMD_EN_SEC_ACCL0;
  138. printk(KERN_ERR MV_CESA
  139. "completion timer expired (CESA %sactive), cleaning up.\n",
  140. active ? "" : "in");
  141. del_timer(&cpg->completion_timer);
  142. writel(SEC_CMD_DISABLE_SEC, cpg->reg + SEC_ACCEL_CMD);
  143. while(readl(cpg->reg + SEC_ACCEL_CMD) & SEC_CMD_DISABLE_SEC)
  144. printk(KERN_INFO MV_CESA "%s: waiting for engine finishing\n", __func__);
  145. cpg->eng_st = ENGINE_W_DEQUEUE;
  146. wake_up_process(cpg->queue_th);
  147. }
  148. static void mv_setup_timer(void)
  149. {
  150. setup_timer(&cpg->completion_timer, &mv_completion_timer_callback, 0);
  151. mod_timer(&cpg->completion_timer,
  152. jiffies + msecs_to_jiffies(MV_CESA_EXPIRE));
  153. }
  154. static void compute_aes_dec_key(struct mv_ctx *ctx)
  155. {
  156. struct crypto_aes_ctx gen_aes_key;
  157. int key_pos;
  158. if (!ctx->need_calc_aes_dkey)
  159. return;
  160. crypto_aes_expand_key(&gen_aes_key, ctx->aes_enc_key, ctx->key_len);
  161. key_pos = ctx->key_len + 24;
  162. memcpy(ctx->aes_dec_key, &gen_aes_key.key_enc[key_pos], 4 * 4);
  163. switch (ctx->key_len) {
  164. case AES_KEYSIZE_256:
  165. key_pos -= 2;
  166. /* fall */
  167. case AES_KEYSIZE_192:
  168. key_pos -= 2;
  169. memcpy(&ctx->aes_dec_key[4], &gen_aes_key.key_enc[key_pos],
  170. 4 * 4);
  171. break;
  172. }
  173. ctx->need_calc_aes_dkey = 0;
  174. }
  175. static int mv_setkey_aes(struct crypto_ablkcipher *cipher, const u8 *key,
  176. unsigned int len)
  177. {
  178. struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
  179. struct mv_ctx *ctx = crypto_tfm_ctx(tfm);
  180. switch (len) {
  181. case AES_KEYSIZE_128:
  182. case AES_KEYSIZE_192:
  183. case AES_KEYSIZE_256:
  184. break;
  185. default:
  186. crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
  187. return -EINVAL;
  188. }
  189. ctx->key_len = len;
  190. ctx->need_calc_aes_dkey = 1;
  191. memcpy(ctx->aes_enc_key, key, AES_KEY_LEN);
  192. return 0;
  193. }
  194. static void copy_src_to_buf(struct req_progress *p, char *dbuf, int len)
  195. {
  196. int ret;
  197. void *sbuf;
  198. int copy_len;
  199. while (len) {
  200. if (!p->sg_src_left) {
  201. ret = sg_miter_next(&p->src_sg_it);
  202. BUG_ON(!ret);
  203. p->sg_src_left = p->src_sg_it.length;
  204. p->src_start = 0;
  205. }
  206. sbuf = p->src_sg_it.addr + p->src_start;
  207. copy_len = min(p->sg_src_left, len);
  208. memcpy(dbuf, sbuf, copy_len);
  209. p->src_start += copy_len;
  210. p->sg_src_left -= copy_len;
  211. len -= copy_len;
  212. dbuf += copy_len;
  213. }
  214. }
  215. static void setup_data_in(void)
  216. {
  217. struct req_progress *p = &cpg->p;
  218. int data_in_sram =
  219. min(p->hw_nbytes - p->hw_processed_bytes, cpg->max_req_size);
  220. copy_src_to_buf(p, cpg->sram + SRAM_DATA_IN_START + p->crypt_len,
  221. data_in_sram - p->crypt_len);
  222. p->crypt_len = data_in_sram;
  223. }
  224. static void mv_process_current_q(int first_block)
  225. {
  226. struct ablkcipher_request *req = ablkcipher_request_cast(cpg->cur_req);
  227. struct mv_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
  228. struct mv_req_ctx *req_ctx = ablkcipher_request_ctx(req);
  229. struct sec_accel_config op;
  230. switch (req_ctx->op) {
  231. case COP_AES_ECB:
  232. op.config = CFG_OP_CRYPT_ONLY | CFG_ENCM_AES | CFG_ENC_MODE_ECB;
  233. break;
  234. case COP_AES_CBC:
  235. default:
  236. op.config = CFG_OP_CRYPT_ONLY | CFG_ENCM_AES | CFG_ENC_MODE_CBC;
  237. op.enc_iv = ENC_IV_POINT(SRAM_DATA_IV) |
  238. ENC_IV_BUF_POINT(SRAM_DATA_IV_BUF);
  239. if (first_block)
  240. memcpy(cpg->sram + SRAM_DATA_IV, req->info, 16);
  241. break;
  242. }
  243. if (req_ctx->decrypt) {
  244. op.config |= CFG_DIR_DEC;
  245. memcpy(cpg->sram + SRAM_DATA_KEY_P, ctx->aes_dec_key,
  246. AES_KEY_LEN);
  247. } else {
  248. op.config |= CFG_DIR_ENC;
  249. memcpy(cpg->sram + SRAM_DATA_KEY_P, ctx->aes_enc_key,
  250. AES_KEY_LEN);
  251. }
  252. switch (ctx->key_len) {
  253. case AES_KEYSIZE_128:
  254. op.config |= CFG_AES_LEN_128;
  255. break;
  256. case AES_KEYSIZE_192:
  257. op.config |= CFG_AES_LEN_192;
  258. break;
  259. case AES_KEYSIZE_256:
  260. op.config |= CFG_AES_LEN_256;
  261. break;
  262. }
  263. op.enc_p = ENC_P_SRC(SRAM_DATA_IN_START) |
  264. ENC_P_DST(SRAM_DATA_OUT_START);
  265. op.enc_key_p = SRAM_DATA_KEY_P;
  266. setup_data_in();
  267. op.enc_len = cpg->p.crypt_len;
  268. memcpy(cpg->sram + SRAM_CONFIG, &op,
  269. sizeof(struct sec_accel_config));
  270. /* GO */
  271. mv_setup_timer();
  272. writel(SEC_CMD_EN_SEC_ACCL0, cpg->reg + SEC_ACCEL_CMD);
  273. }
  274. static void mv_crypto_algo_completion(void)
  275. {
  276. struct ablkcipher_request *req = ablkcipher_request_cast(cpg->cur_req);
  277. struct mv_req_ctx *req_ctx = ablkcipher_request_ctx(req);
  278. sg_miter_stop(&cpg->p.src_sg_it);
  279. sg_miter_stop(&cpg->p.dst_sg_it);
  280. if (req_ctx->op != COP_AES_CBC)
  281. return ;
  282. memcpy(req->info, cpg->sram + SRAM_DATA_IV_BUF, 16);
  283. }
  284. static void mv_process_hash_current(int first_block)
  285. {
  286. struct ahash_request *req = ahash_request_cast(cpg->cur_req);
  287. const struct mv_tfm_hash_ctx *tfm_ctx = crypto_tfm_ctx(req->base.tfm);
  288. struct mv_req_hash_ctx *req_ctx = ahash_request_ctx(req);
  289. struct req_progress *p = &cpg->p;
  290. struct sec_accel_config op = { 0 };
  291. int is_last;
  292. switch (req_ctx->op) {
  293. case COP_SHA1:
  294. default:
  295. op.config = CFG_OP_MAC_ONLY | CFG_MACM_SHA1;
  296. break;
  297. case COP_HMAC_SHA1:
  298. op.config = CFG_OP_MAC_ONLY | CFG_MACM_HMAC_SHA1;
  299. memcpy(cpg->sram + SRAM_HMAC_IV_IN,
  300. tfm_ctx->ivs, sizeof(tfm_ctx->ivs));
  301. break;
  302. }
  303. op.mac_src_p =
  304. MAC_SRC_DATA_P(SRAM_DATA_IN_START) | MAC_SRC_TOTAL_LEN((u32)
  305. req_ctx->
  306. count);
  307. setup_data_in();
  308. op.mac_digest =
  309. MAC_DIGEST_P(SRAM_DIGEST_BUF) | MAC_FRAG_LEN(p->crypt_len);
  310. op.mac_iv =
  311. MAC_INNER_IV_P(SRAM_HMAC_IV_IN) |
  312. MAC_OUTER_IV_P(SRAM_HMAC_IV_OUT);
  313. is_last = req_ctx->last_chunk
  314. && (p->hw_processed_bytes + p->crypt_len >= p->hw_nbytes)
  315. && (req_ctx->count <= MAX_HW_HASH_SIZE);
  316. if (req_ctx->first_hash) {
  317. if (is_last)
  318. op.config |= CFG_NOT_FRAG;
  319. else
  320. op.config |= CFG_FIRST_FRAG;
  321. req_ctx->first_hash = 0;
  322. } else {
  323. if (is_last)
  324. op.config |= CFG_LAST_FRAG;
  325. else
  326. op.config |= CFG_MID_FRAG;
  327. if (first_block) {
  328. writel(req_ctx->state[0], cpg->reg + DIGEST_INITIAL_VAL_A);
  329. writel(req_ctx->state[1], cpg->reg + DIGEST_INITIAL_VAL_B);
  330. writel(req_ctx->state[2], cpg->reg + DIGEST_INITIAL_VAL_C);
  331. writel(req_ctx->state[3], cpg->reg + DIGEST_INITIAL_VAL_D);
  332. writel(req_ctx->state[4], cpg->reg + DIGEST_INITIAL_VAL_E);
  333. }
  334. }
  335. memcpy(cpg->sram + SRAM_CONFIG, &op, sizeof(struct sec_accel_config));
  336. /* GO */
  337. mv_setup_timer();
  338. writel(SEC_CMD_EN_SEC_ACCL0, cpg->reg + SEC_ACCEL_CMD);
  339. }
  340. static inline int mv_hash_import_sha1_ctx(const struct mv_req_hash_ctx *ctx,
  341. struct shash_desc *desc)
  342. {
  343. int i;
  344. struct sha1_state shash_state;
  345. shash_state.count = ctx->count + ctx->count_add;
  346. for (i = 0; i < 5; i++)
  347. shash_state.state[i] = ctx->state[i];
  348. memcpy(shash_state.buffer, ctx->buffer, sizeof(shash_state.buffer));
  349. return crypto_shash_import(desc, &shash_state);
  350. }
  351. static int mv_hash_final_fallback(struct ahash_request *req)
  352. {
  353. const struct mv_tfm_hash_ctx *tfm_ctx = crypto_tfm_ctx(req->base.tfm);
  354. struct mv_req_hash_ctx *req_ctx = ahash_request_ctx(req);
  355. SHASH_DESC_ON_STACK(shash, tfm_ctx->fallback);
  356. int rc;
  357. shash->tfm = tfm_ctx->fallback;
  358. shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
  359. if (unlikely(req_ctx->first_hash)) {
  360. crypto_shash_init(shash);
  361. crypto_shash_update(shash, req_ctx->buffer,
  362. req_ctx->extra_bytes);
  363. } else {
  364. /* only SHA1 for now....
  365. */
  366. rc = mv_hash_import_sha1_ctx(req_ctx, shash);
  367. if (rc)
  368. goto out;
  369. }
  370. rc = crypto_shash_final(shash, req->result);
  371. out:
  372. return rc;
  373. }
  374. static void mv_save_digest_state(struct mv_req_hash_ctx *ctx)
  375. {
  376. ctx->state[0] = readl(cpg->reg + DIGEST_INITIAL_VAL_A);
  377. ctx->state[1] = readl(cpg->reg + DIGEST_INITIAL_VAL_B);
  378. ctx->state[2] = readl(cpg->reg + DIGEST_INITIAL_VAL_C);
  379. ctx->state[3] = readl(cpg->reg + DIGEST_INITIAL_VAL_D);
  380. ctx->state[4] = readl(cpg->reg + DIGEST_INITIAL_VAL_E);
  381. }
  382. static void mv_hash_algo_completion(void)
  383. {
  384. struct ahash_request *req = ahash_request_cast(cpg->cur_req);
  385. struct mv_req_hash_ctx *ctx = ahash_request_ctx(req);
  386. if (ctx->extra_bytes)
  387. copy_src_to_buf(&cpg->p, ctx->buffer, ctx->extra_bytes);
  388. sg_miter_stop(&cpg->p.src_sg_it);
  389. if (likely(ctx->last_chunk)) {
  390. if (likely(ctx->count <= MAX_HW_HASH_SIZE)) {
  391. memcpy(req->result, cpg->sram + SRAM_DIGEST_BUF,
  392. crypto_ahash_digestsize(crypto_ahash_reqtfm
  393. (req)));
  394. } else {
  395. mv_save_digest_state(ctx);
  396. mv_hash_final_fallback(req);
  397. }
  398. } else {
  399. mv_save_digest_state(ctx);
  400. }
  401. }
  402. static void dequeue_complete_req(void)
  403. {
  404. struct crypto_async_request *req = cpg->cur_req;
  405. void *buf;
  406. int ret;
  407. cpg->p.hw_processed_bytes += cpg->p.crypt_len;
  408. if (cpg->p.copy_back) {
  409. int need_copy_len = cpg->p.crypt_len;
  410. int sram_offset = 0;
  411. do {
  412. int dst_copy;
  413. if (!cpg->p.sg_dst_left) {
  414. ret = sg_miter_next(&cpg->p.dst_sg_it);
  415. BUG_ON(!ret);
  416. cpg->p.sg_dst_left = cpg->p.dst_sg_it.length;
  417. cpg->p.dst_start = 0;
  418. }
  419. buf = cpg->p.dst_sg_it.addr;
  420. buf += cpg->p.dst_start;
  421. dst_copy = min(need_copy_len, cpg->p.sg_dst_left);
  422. memcpy(buf,
  423. cpg->sram + SRAM_DATA_OUT_START + sram_offset,
  424. dst_copy);
  425. sram_offset += dst_copy;
  426. cpg->p.sg_dst_left -= dst_copy;
  427. need_copy_len -= dst_copy;
  428. cpg->p.dst_start += dst_copy;
  429. } while (need_copy_len > 0);
  430. }
  431. cpg->p.crypt_len = 0;
  432. BUG_ON(cpg->eng_st != ENGINE_W_DEQUEUE);
  433. if (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) {
  434. /* process next scatter list entry */
  435. cpg->eng_st = ENGINE_BUSY;
  436. cpg->p.process(0);
  437. } else {
  438. cpg->p.complete();
  439. cpg->eng_st = ENGINE_IDLE;
  440. local_bh_disable();
  441. req->complete(req, 0);
  442. local_bh_enable();
  443. }
  444. }
  445. static int count_sgs(struct scatterlist *sl, unsigned int total_bytes)
  446. {
  447. int i = 0;
  448. size_t cur_len;
  449. while (sl) {
  450. cur_len = sl[i].length;
  451. ++i;
  452. if (total_bytes > cur_len)
  453. total_bytes -= cur_len;
  454. else
  455. break;
  456. }
  457. return i;
  458. }
  459. static void mv_start_new_crypt_req(struct ablkcipher_request *req)
  460. {
  461. struct req_progress *p = &cpg->p;
  462. int num_sgs;
  463. cpg->cur_req = &req->base;
  464. memset(p, 0, sizeof(struct req_progress));
  465. p->hw_nbytes = req->nbytes;
  466. p->complete = mv_crypto_algo_completion;
  467. p->process = mv_process_current_q;
  468. p->copy_back = 1;
  469. num_sgs = count_sgs(req->src, req->nbytes);
  470. sg_miter_start(&p->src_sg_it, req->src, num_sgs, SG_MITER_FROM_SG);
  471. num_sgs = count_sgs(req->dst, req->nbytes);
  472. sg_miter_start(&p->dst_sg_it, req->dst, num_sgs, SG_MITER_TO_SG);
  473. mv_process_current_q(1);
  474. }
  475. static void mv_start_new_hash_req(struct ahash_request *req)
  476. {
  477. struct req_progress *p = &cpg->p;
  478. struct mv_req_hash_ctx *ctx = ahash_request_ctx(req);
  479. int num_sgs, hw_bytes, old_extra_bytes, rc;
  480. cpg->cur_req = &req->base;
  481. memset(p, 0, sizeof(struct req_progress));
  482. hw_bytes = req->nbytes + ctx->extra_bytes;
  483. old_extra_bytes = ctx->extra_bytes;
  484. ctx->extra_bytes = hw_bytes % SHA1_BLOCK_SIZE;
  485. if (ctx->extra_bytes != 0
  486. && (!ctx->last_chunk || ctx->count > MAX_HW_HASH_SIZE))
  487. hw_bytes -= ctx->extra_bytes;
  488. else
  489. ctx->extra_bytes = 0;
  490. num_sgs = count_sgs(req->src, req->nbytes);
  491. sg_miter_start(&p->src_sg_it, req->src, num_sgs, SG_MITER_FROM_SG);
  492. if (hw_bytes) {
  493. p->hw_nbytes = hw_bytes;
  494. p->complete = mv_hash_algo_completion;
  495. p->process = mv_process_hash_current;
  496. if (unlikely(old_extra_bytes)) {
  497. memcpy(cpg->sram + SRAM_DATA_IN_START, ctx->buffer,
  498. old_extra_bytes);
  499. p->crypt_len = old_extra_bytes;
  500. }
  501. mv_process_hash_current(1);
  502. } else {
  503. copy_src_to_buf(p, ctx->buffer + old_extra_bytes,
  504. ctx->extra_bytes - old_extra_bytes);
  505. sg_miter_stop(&p->src_sg_it);
  506. if (ctx->last_chunk)
  507. rc = mv_hash_final_fallback(req);
  508. else
  509. rc = 0;
  510. cpg->eng_st = ENGINE_IDLE;
  511. local_bh_disable();
  512. req->base.complete(&req->base, rc);
  513. local_bh_enable();
  514. }
  515. }
  516. static int queue_manag(void *data)
  517. {
  518. cpg->eng_st = ENGINE_IDLE;
  519. do {
  520. struct crypto_async_request *async_req = NULL;
  521. struct crypto_async_request *backlog = NULL;
  522. __set_current_state(TASK_INTERRUPTIBLE);
  523. if (cpg->eng_st == ENGINE_W_DEQUEUE)
  524. dequeue_complete_req();
  525. spin_lock_irq(&cpg->lock);
  526. if (cpg->eng_st == ENGINE_IDLE) {
  527. backlog = crypto_get_backlog(&cpg->queue);
  528. async_req = crypto_dequeue_request(&cpg->queue);
  529. if (async_req) {
  530. BUG_ON(cpg->eng_st != ENGINE_IDLE);
  531. cpg->eng_st = ENGINE_BUSY;
  532. }
  533. }
  534. spin_unlock_irq(&cpg->lock);
  535. if (backlog) {
  536. backlog->complete(backlog, -EINPROGRESS);
  537. backlog = NULL;
  538. }
  539. if (async_req) {
  540. if (crypto_tfm_alg_type(async_req->tfm) !=
  541. CRYPTO_ALG_TYPE_AHASH) {
  542. struct ablkcipher_request *req =
  543. ablkcipher_request_cast(async_req);
  544. mv_start_new_crypt_req(req);
  545. } else {
  546. struct ahash_request *req =
  547. ahash_request_cast(async_req);
  548. mv_start_new_hash_req(req);
  549. }
  550. async_req = NULL;
  551. }
  552. schedule();
  553. } while (!kthread_should_stop());
  554. return 0;
  555. }
  556. static int mv_handle_req(struct crypto_async_request *req)
  557. {
  558. unsigned long flags;
  559. int ret;
  560. spin_lock_irqsave(&cpg->lock, flags);
  561. ret = crypto_enqueue_request(&cpg->queue, req);
  562. spin_unlock_irqrestore(&cpg->lock, flags);
  563. wake_up_process(cpg->queue_th);
  564. return ret;
  565. }
  566. static int mv_enc_aes_ecb(struct ablkcipher_request *req)
  567. {
  568. struct mv_req_ctx *req_ctx = ablkcipher_request_ctx(req);
  569. req_ctx->op = COP_AES_ECB;
  570. req_ctx->decrypt = 0;
  571. return mv_handle_req(&req->base);
  572. }
  573. static int mv_dec_aes_ecb(struct ablkcipher_request *req)
  574. {
  575. struct mv_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
  576. struct mv_req_ctx *req_ctx = ablkcipher_request_ctx(req);
  577. req_ctx->op = COP_AES_ECB;
  578. req_ctx->decrypt = 1;
  579. compute_aes_dec_key(ctx);
  580. return mv_handle_req(&req->base);
  581. }
  582. static int mv_enc_aes_cbc(struct ablkcipher_request *req)
  583. {
  584. struct mv_req_ctx *req_ctx = ablkcipher_request_ctx(req);
  585. req_ctx->op = COP_AES_CBC;
  586. req_ctx->decrypt = 0;
  587. return mv_handle_req(&req->base);
  588. }
  589. static int mv_dec_aes_cbc(struct ablkcipher_request *req)
  590. {
  591. struct mv_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
  592. struct mv_req_ctx *req_ctx = ablkcipher_request_ctx(req);
  593. req_ctx->op = COP_AES_CBC;
  594. req_ctx->decrypt = 1;
  595. compute_aes_dec_key(ctx);
  596. return mv_handle_req(&req->base);
  597. }
  598. static int mv_cra_init(struct crypto_tfm *tfm)
  599. {
  600. tfm->crt_ablkcipher.reqsize = sizeof(struct mv_req_ctx);
  601. return 0;
  602. }
  603. static void mv_init_hash_req_ctx(struct mv_req_hash_ctx *ctx, int op,
  604. int is_last, unsigned int req_len,
  605. int count_add)
  606. {
  607. memset(ctx, 0, sizeof(*ctx));
  608. ctx->op = op;
  609. ctx->count = req_len;
  610. ctx->first_hash = 1;
  611. ctx->last_chunk = is_last;
  612. ctx->count_add = count_add;
  613. }
  614. static void mv_update_hash_req_ctx(struct mv_req_hash_ctx *ctx, int is_last,
  615. unsigned req_len)
  616. {
  617. ctx->last_chunk = is_last;
  618. ctx->count += req_len;
  619. }
  620. static int mv_hash_init(struct ahash_request *req)
  621. {
  622. const struct mv_tfm_hash_ctx *tfm_ctx = crypto_tfm_ctx(req->base.tfm);
  623. mv_init_hash_req_ctx(ahash_request_ctx(req), tfm_ctx->op, 0, 0,
  624. tfm_ctx->count_add);
  625. return 0;
  626. }
  627. static int mv_hash_update(struct ahash_request *req)
  628. {
  629. if (!req->nbytes)
  630. return 0;
  631. mv_update_hash_req_ctx(ahash_request_ctx(req), 0, req->nbytes);
  632. return mv_handle_req(&req->base);
  633. }
  634. static int mv_hash_final(struct ahash_request *req)
  635. {
  636. struct mv_req_hash_ctx *ctx = ahash_request_ctx(req);
  637. ahash_request_set_crypt(req, NULL, req->result, 0);
  638. mv_update_hash_req_ctx(ctx, 1, 0);
  639. return mv_handle_req(&req->base);
  640. }
  641. static int mv_hash_finup(struct ahash_request *req)
  642. {
  643. mv_update_hash_req_ctx(ahash_request_ctx(req), 1, req->nbytes);
  644. return mv_handle_req(&req->base);
  645. }
  646. static int mv_hash_digest(struct ahash_request *req)
  647. {
  648. const struct mv_tfm_hash_ctx *tfm_ctx = crypto_tfm_ctx(req->base.tfm);
  649. mv_init_hash_req_ctx(ahash_request_ctx(req), tfm_ctx->op, 1,
  650. req->nbytes, tfm_ctx->count_add);
  651. return mv_handle_req(&req->base);
  652. }
  653. static void mv_hash_init_ivs(struct mv_tfm_hash_ctx *ctx, const void *istate,
  654. const void *ostate)
  655. {
  656. const struct sha1_state *isha1_state = istate, *osha1_state = ostate;
  657. int i;
  658. for (i = 0; i < 5; i++) {
  659. ctx->ivs[i] = cpu_to_be32(isha1_state->state[i]);
  660. ctx->ivs[i + 5] = cpu_to_be32(osha1_state->state[i]);
  661. }
  662. }
  663. static int mv_hash_setkey(struct crypto_ahash *tfm, const u8 * key,
  664. unsigned int keylen)
  665. {
  666. int rc;
  667. struct mv_tfm_hash_ctx *ctx = crypto_tfm_ctx(&tfm->base);
  668. int bs, ds, ss;
  669. if (!ctx->base_hash)
  670. return 0;
  671. rc = crypto_shash_setkey(ctx->fallback, key, keylen);
  672. if (rc)
  673. return rc;
  674. /* Can't see a way to extract the ipad/opad from the fallback tfm
  675. so I'm basically copying code from the hmac module */
  676. bs = crypto_shash_blocksize(ctx->base_hash);
  677. ds = crypto_shash_digestsize(ctx->base_hash);
  678. ss = crypto_shash_statesize(ctx->base_hash);
  679. {
  680. SHASH_DESC_ON_STACK(shash, ctx->base_hash);
  681. unsigned int i;
  682. char ipad[ss];
  683. char opad[ss];
  684. shash->tfm = ctx->base_hash;
  685. shash->flags = crypto_shash_get_flags(ctx->base_hash) &
  686. CRYPTO_TFM_REQ_MAY_SLEEP;
  687. if (keylen > bs) {
  688. int err;
  689. err =
  690. crypto_shash_digest(shash, key, keylen, ipad);
  691. if (err)
  692. return err;
  693. keylen = ds;
  694. } else
  695. memcpy(ipad, key, keylen);
  696. memset(ipad + keylen, 0, bs - keylen);
  697. memcpy(opad, ipad, bs);
  698. for (i = 0; i < bs; i++) {
  699. ipad[i] ^= 0x36;
  700. opad[i] ^= 0x5c;
  701. }
  702. rc = crypto_shash_init(shash) ? :
  703. crypto_shash_update(shash, ipad, bs) ? :
  704. crypto_shash_export(shash, ipad) ? :
  705. crypto_shash_init(shash) ? :
  706. crypto_shash_update(shash, opad, bs) ? :
  707. crypto_shash_export(shash, opad);
  708. if (rc == 0)
  709. mv_hash_init_ivs(ctx, ipad, opad);
  710. return rc;
  711. }
  712. }
  713. static int mv_cra_hash_init(struct crypto_tfm *tfm, const char *base_hash_name,
  714. enum hash_op op, int count_add)
  715. {
  716. const char *fallback_driver_name = crypto_tfm_alg_name(tfm);
  717. struct mv_tfm_hash_ctx *ctx = crypto_tfm_ctx(tfm);
  718. struct crypto_shash *fallback_tfm = NULL;
  719. struct crypto_shash *base_hash = NULL;
  720. int err = -ENOMEM;
  721. ctx->op = op;
  722. ctx->count_add = count_add;
  723. /* Allocate a fallback and abort if it failed. */
  724. fallback_tfm = crypto_alloc_shash(fallback_driver_name, 0,
  725. CRYPTO_ALG_NEED_FALLBACK);
  726. if (IS_ERR(fallback_tfm)) {
  727. printk(KERN_WARNING MV_CESA
  728. "Fallback driver '%s' could not be loaded!\n",
  729. fallback_driver_name);
  730. err = PTR_ERR(fallback_tfm);
  731. goto out;
  732. }
  733. ctx->fallback = fallback_tfm;
  734. if (base_hash_name) {
  735. /* Allocate a hash to compute the ipad/opad of hmac. */
  736. base_hash = crypto_alloc_shash(base_hash_name, 0,
  737. CRYPTO_ALG_NEED_FALLBACK);
  738. if (IS_ERR(base_hash)) {
  739. printk(KERN_WARNING MV_CESA
  740. "Base driver '%s' could not be loaded!\n",
  741. base_hash_name);
  742. err = PTR_ERR(base_hash);
  743. goto err_bad_base;
  744. }
  745. }
  746. ctx->base_hash = base_hash;
  747. crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
  748. sizeof(struct mv_req_hash_ctx) +
  749. crypto_shash_descsize(ctx->fallback));
  750. return 0;
  751. err_bad_base:
  752. crypto_free_shash(fallback_tfm);
  753. out:
  754. return err;
  755. }
  756. static void mv_cra_hash_exit(struct crypto_tfm *tfm)
  757. {
  758. struct mv_tfm_hash_ctx *ctx = crypto_tfm_ctx(tfm);
  759. crypto_free_shash(ctx->fallback);
  760. if (ctx->base_hash)
  761. crypto_free_shash(ctx->base_hash);
  762. }
  763. static int mv_cra_hash_sha1_init(struct crypto_tfm *tfm)
  764. {
  765. return mv_cra_hash_init(tfm, NULL, COP_SHA1, 0);
  766. }
  767. static int mv_cra_hash_hmac_sha1_init(struct crypto_tfm *tfm)
  768. {
  769. return mv_cra_hash_init(tfm, "sha1", COP_HMAC_SHA1, SHA1_BLOCK_SIZE);
  770. }
  771. static irqreturn_t crypto_int(int irq, void *priv)
  772. {
  773. u32 val;
  774. val = readl(cpg->reg + SEC_ACCEL_INT_STATUS);
  775. if (!(val & SEC_INT_ACCEL0_DONE))
  776. return IRQ_NONE;
  777. if (!del_timer(&cpg->completion_timer)) {
  778. printk(KERN_WARNING MV_CESA
  779. "got an interrupt but no pending timer?\n");
  780. }
  781. val &= ~SEC_INT_ACCEL0_DONE;
  782. writel(val, cpg->reg + FPGA_INT_STATUS);
  783. writel(val, cpg->reg + SEC_ACCEL_INT_STATUS);
  784. BUG_ON(cpg->eng_st != ENGINE_BUSY);
  785. cpg->eng_st = ENGINE_W_DEQUEUE;
  786. wake_up_process(cpg->queue_th);
  787. return IRQ_HANDLED;
  788. }
  789. static struct crypto_alg mv_aes_alg_ecb = {
  790. .cra_name = "ecb(aes)",
  791. .cra_driver_name = "mv-ecb-aes",
  792. .cra_priority = 300,
  793. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  794. CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC,
  795. .cra_blocksize = 16,
  796. .cra_ctxsize = sizeof(struct mv_ctx),
  797. .cra_alignmask = 0,
  798. .cra_type = &crypto_ablkcipher_type,
  799. .cra_module = THIS_MODULE,
  800. .cra_init = mv_cra_init,
  801. .cra_u = {
  802. .ablkcipher = {
  803. .min_keysize = AES_MIN_KEY_SIZE,
  804. .max_keysize = AES_MAX_KEY_SIZE,
  805. .setkey = mv_setkey_aes,
  806. .encrypt = mv_enc_aes_ecb,
  807. .decrypt = mv_dec_aes_ecb,
  808. },
  809. },
  810. };
  811. static struct crypto_alg mv_aes_alg_cbc = {
  812. .cra_name = "cbc(aes)",
  813. .cra_driver_name = "mv-cbc-aes",
  814. .cra_priority = 300,
  815. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  816. CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC,
  817. .cra_blocksize = AES_BLOCK_SIZE,
  818. .cra_ctxsize = sizeof(struct mv_ctx),
  819. .cra_alignmask = 0,
  820. .cra_type = &crypto_ablkcipher_type,
  821. .cra_module = THIS_MODULE,
  822. .cra_init = mv_cra_init,
  823. .cra_u = {
  824. .ablkcipher = {
  825. .ivsize = AES_BLOCK_SIZE,
  826. .min_keysize = AES_MIN_KEY_SIZE,
  827. .max_keysize = AES_MAX_KEY_SIZE,
  828. .setkey = mv_setkey_aes,
  829. .encrypt = mv_enc_aes_cbc,
  830. .decrypt = mv_dec_aes_cbc,
  831. },
  832. },
  833. };
  834. static struct ahash_alg mv_sha1_alg = {
  835. .init = mv_hash_init,
  836. .update = mv_hash_update,
  837. .final = mv_hash_final,
  838. .finup = mv_hash_finup,
  839. .digest = mv_hash_digest,
  840. .halg = {
  841. .digestsize = SHA1_DIGEST_SIZE,
  842. .base = {
  843. .cra_name = "sha1",
  844. .cra_driver_name = "mv-sha1",
  845. .cra_priority = 300,
  846. .cra_flags =
  847. CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
  848. CRYPTO_ALG_NEED_FALLBACK,
  849. .cra_blocksize = SHA1_BLOCK_SIZE,
  850. .cra_ctxsize = sizeof(struct mv_tfm_hash_ctx),
  851. .cra_init = mv_cra_hash_sha1_init,
  852. .cra_exit = mv_cra_hash_exit,
  853. .cra_module = THIS_MODULE,
  854. }
  855. }
  856. };
  857. static struct ahash_alg mv_hmac_sha1_alg = {
  858. .init = mv_hash_init,
  859. .update = mv_hash_update,
  860. .final = mv_hash_final,
  861. .finup = mv_hash_finup,
  862. .digest = mv_hash_digest,
  863. .setkey = mv_hash_setkey,
  864. .halg = {
  865. .digestsize = SHA1_DIGEST_SIZE,
  866. .base = {
  867. .cra_name = "hmac(sha1)",
  868. .cra_driver_name = "mv-hmac-sha1",
  869. .cra_priority = 300,
  870. .cra_flags =
  871. CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
  872. CRYPTO_ALG_NEED_FALLBACK,
  873. .cra_blocksize = SHA1_BLOCK_SIZE,
  874. .cra_ctxsize = sizeof(struct mv_tfm_hash_ctx),
  875. .cra_init = mv_cra_hash_hmac_sha1_init,
  876. .cra_exit = mv_cra_hash_exit,
  877. .cra_module = THIS_MODULE,
  878. }
  879. }
  880. };
  881. static int mv_cesa_get_sram(struct platform_device *pdev,
  882. struct crypto_priv *cp)
  883. {
  884. struct resource *res;
  885. u32 sram_size = MV_CESA_DEFAULT_SRAM_SIZE;
  886. of_property_read_u32(pdev->dev.of_node, "marvell,crypto-sram-size",
  887. &sram_size);
  888. cp->sram_size = sram_size;
  889. cp->sram_pool = of_gen_pool_get(pdev->dev.of_node,
  890. "marvell,crypto-srams", 0);
  891. if (cp->sram_pool) {
  892. cp->sram = gen_pool_dma_alloc(cp->sram_pool, sram_size,
  893. &cp->sram_dma);
  894. if (cp->sram)
  895. return 0;
  896. return -ENOMEM;
  897. }
  898. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  899. "sram");
  900. if (!res || resource_size(res) < cp->sram_size)
  901. return -EINVAL;
  902. cp->sram = devm_ioremap_resource(&pdev->dev, res);
  903. if (IS_ERR(cp->sram))
  904. return PTR_ERR(cp->sram);
  905. return 0;
  906. }
  907. static int mv_probe(struct platform_device *pdev)
  908. {
  909. struct crypto_priv *cp;
  910. struct resource *res;
  911. int irq;
  912. int ret;
  913. if (cpg) {
  914. printk(KERN_ERR MV_CESA "Second crypto dev?\n");
  915. return -EEXIST;
  916. }
  917. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
  918. if (!res)
  919. return -ENXIO;
  920. cp = kzalloc(sizeof(*cp), GFP_KERNEL);
  921. if (!cp)
  922. return -ENOMEM;
  923. spin_lock_init(&cp->lock);
  924. crypto_init_queue(&cp->queue, 50);
  925. cp->reg = devm_ioremap_resource(&pdev->dev, res);
  926. if (IS_ERR(cp->reg)) {
  927. ret = PTR_ERR(cp->reg);
  928. goto err;
  929. }
  930. ret = mv_cesa_get_sram(pdev, cp);
  931. if (ret)
  932. goto err;
  933. cp->max_req_size = cp->sram_size - SRAM_CFG_SPACE;
  934. if (pdev->dev.of_node)
  935. irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
  936. else
  937. irq = platform_get_irq(pdev, 0);
  938. if (irq < 0 || irq == NO_IRQ) {
  939. ret = irq;
  940. goto err;
  941. }
  942. cp->irq = irq;
  943. platform_set_drvdata(pdev, cp);
  944. cpg = cp;
  945. cp->queue_th = kthread_run(queue_manag, cp, "mv_crypto");
  946. if (IS_ERR(cp->queue_th)) {
  947. ret = PTR_ERR(cp->queue_th);
  948. goto err;
  949. }
  950. ret = request_irq(irq, crypto_int, 0, dev_name(&pdev->dev),
  951. cp);
  952. if (ret)
  953. goto err_thread;
  954. /* Not all platforms can gate the clock, so it is not
  955. an error if the clock does not exists. */
  956. cp->clk = clk_get(&pdev->dev, NULL);
  957. if (!IS_ERR(cp->clk))
  958. clk_prepare_enable(cp->clk);
  959. writel(0, cpg->reg + SEC_ACCEL_INT_STATUS);
  960. writel(SEC_INT_ACCEL0_DONE, cpg->reg + SEC_ACCEL_INT_MASK);
  961. writel(SEC_CFG_STOP_DIG_ERR, cpg->reg + SEC_ACCEL_CFG);
  962. writel(SRAM_CONFIG, cpg->reg + SEC_ACCEL_DESC_P0);
  963. ret = crypto_register_alg(&mv_aes_alg_ecb);
  964. if (ret) {
  965. printk(KERN_WARNING MV_CESA
  966. "Could not register aes-ecb driver\n");
  967. goto err_irq;
  968. }
  969. ret = crypto_register_alg(&mv_aes_alg_cbc);
  970. if (ret) {
  971. printk(KERN_WARNING MV_CESA
  972. "Could not register aes-cbc driver\n");
  973. goto err_unreg_ecb;
  974. }
  975. ret = crypto_register_ahash(&mv_sha1_alg);
  976. if (ret == 0)
  977. cpg->has_sha1 = 1;
  978. else
  979. printk(KERN_WARNING MV_CESA "Could not register sha1 driver\n");
  980. ret = crypto_register_ahash(&mv_hmac_sha1_alg);
  981. if (ret == 0) {
  982. cpg->has_hmac_sha1 = 1;
  983. } else {
  984. printk(KERN_WARNING MV_CESA
  985. "Could not register hmac-sha1 driver\n");
  986. }
  987. return 0;
  988. err_unreg_ecb:
  989. crypto_unregister_alg(&mv_aes_alg_ecb);
  990. err_irq:
  991. free_irq(irq, cp);
  992. if (!IS_ERR(cp->clk)) {
  993. clk_disable_unprepare(cp->clk);
  994. clk_put(cp->clk);
  995. }
  996. err_thread:
  997. kthread_stop(cp->queue_th);
  998. err:
  999. kfree(cp);
  1000. cpg = NULL;
  1001. return ret;
  1002. }
  1003. static int mv_remove(struct platform_device *pdev)
  1004. {
  1005. struct crypto_priv *cp = platform_get_drvdata(pdev);
  1006. crypto_unregister_alg(&mv_aes_alg_ecb);
  1007. crypto_unregister_alg(&mv_aes_alg_cbc);
  1008. if (cp->has_sha1)
  1009. crypto_unregister_ahash(&mv_sha1_alg);
  1010. if (cp->has_hmac_sha1)
  1011. crypto_unregister_ahash(&mv_hmac_sha1_alg);
  1012. kthread_stop(cp->queue_th);
  1013. free_irq(cp->irq, cp);
  1014. memset(cp->sram, 0, cp->sram_size);
  1015. if (!IS_ERR(cp->clk)) {
  1016. clk_disable_unprepare(cp->clk);
  1017. clk_put(cp->clk);
  1018. }
  1019. kfree(cp);
  1020. cpg = NULL;
  1021. return 0;
  1022. }
  1023. static const struct of_device_id mv_cesa_of_match_table[] = {
  1024. { .compatible = "marvell,orion-crypto", },
  1025. { .compatible = "marvell,kirkwood-crypto", },
  1026. { .compatible = "marvell,dove-crypto", },
  1027. {}
  1028. };
  1029. MODULE_DEVICE_TABLE(of, mv_cesa_of_match_table);
  1030. static struct platform_driver marvell_crypto = {
  1031. .probe = mv_probe,
  1032. .remove = mv_remove,
  1033. .driver = {
  1034. .name = "mv_crypto",
  1035. .of_match_table = mv_cesa_of_match_table,
  1036. },
  1037. };
  1038. MODULE_ALIAS("platform:mv_crypto");
  1039. module_platform_driver(marvell_crypto);
  1040. MODULE_AUTHOR("Sebastian Andrzej Siewior <sebastian@breakpoint.cc>");
  1041. MODULE_DESCRIPTION("Support for Marvell's cryptographic engine");
  1042. MODULE_LICENSE("GPL");