cryp_core.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  1. /**
  2. * Copyright (C) ST-Ericsson SA 2010
  3. * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson.
  4. * Author: Joakim Bech <joakim.xx.bech@stericsson.com> for ST-Ericsson.
  5. * Author: Berne Hebark <berne.herbark@stericsson.com> for ST-Ericsson.
  6. * Author: Niklas Hernaeus <niklas.hernaeus@stericsson.com> for ST-Ericsson.
  7. * Author: Jonas Linde <jonas.linde@stericsson.com> for ST-Ericsson.
  8. * Author: Andreas Westin <andreas.westin@stericsson.com> for ST-Ericsson.
  9. * License terms: GNU General Public License (GPL) version 2
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/completion.h>
  13. #include <linux/crypto.h>
  14. #include <linux/dmaengine.h>
  15. #include <linux/err.h>
  16. #include <linux/errno.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/io.h>
  19. #include <linux/irqreturn.h>
  20. #include <linux/klist.h>
  21. #include <linux/module.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/regulator/consumer.h>
  24. #include <linux/semaphore.h>
  25. #include <linux/platform_data/dma-ste-dma40.h>
  26. #include <crypto/aes.h>
  27. #include <crypto/algapi.h>
  28. #include <crypto/ctr.h>
  29. #include <crypto/des.h>
  30. #include <crypto/scatterwalk.h>
  31. #include <linux/platform_data/crypto-ux500.h>
  32. #include "cryp_p.h"
  33. #include "cryp.h"
  34. #define CRYP_MAX_KEY_SIZE 32
  35. #define BYTES_PER_WORD 4
  36. static int cryp_mode;
  37. static atomic_t session_id;
  38. static struct stedma40_chan_cfg *mem_to_engine;
  39. static struct stedma40_chan_cfg *engine_to_mem;
  40. /**
  41. * struct cryp_driver_data - data specific to the driver.
  42. *
  43. * @device_list: A list of registered devices to choose from.
  44. * @device_allocation: A semaphore initialized with number of devices.
  45. */
  46. struct cryp_driver_data {
  47. struct klist device_list;
  48. struct semaphore device_allocation;
  49. };
  50. /**
  51. * struct cryp_ctx - Crypto context
  52. * @config: Crypto mode.
  53. * @key[CRYP_MAX_KEY_SIZE]: Key.
  54. * @keylen: Length of key.
  55. * @iv: Pointer to initialization vector.
  56. * @indata: Pointer to indata.
  57. * @outdata: Pointer to outdata.
  58. * @datalen: Length of indata.
  59. * @outlen: Length of outdata.
  60. * @blocksize: Size of blocks.
  61. * @updated: Updated flag.
  62. * @dev_ctx: Device dependent context.
  63. * @device: Pointer to the device.
  64. */
  65. struct cryp_ctx {
  66. struct cryp_config config;
  67. u8 key[CRYP_MAX_KEY_SIZE];
  68. u32 keylen;
  69. u8 *iv;
  70. const u8 *indata;
  71. u8 *outdata;
  72. u32 datalen;
  73. u32 outlen;
  74. u32 blocksize;
  75. u8 updated;
  76. struct cryp_device_context dev_ctx;
  77. struct cryp_device_data *device;
  78. u32 session_id;
  79. };
  80. static struct cryp_driver_data driver_data;
  81. /**
  82. * uint8p_to_uint32_be - 4*uint8 to uint32 big endian
  83. * @in: Data to convert.
  84. */
  85. static inline u32 uint8p_to_uint32_be(u8 *in)
  86. {
  87. u32 *data = (u32 *)in;
  88. return cpu_to_be32p(data);
  89. }
  90. /**
  91. * swap_bits_in_byte - mirror the bits in a byte
  92. * @b: the byte to be mirrored
  93. *
  94. * The bits are swapped the following way:
  95. * Byte b include bits 0-7, nibble 1 (n1) include bits 0-3 and
  96. * nibble 2 (n2) bits 4-7.
  97. *
  98. * Nibble 1 (n1):
  99. * (The "old" (moved) bit is replaced with a zero)
  100. * 1. Move bit 6 and 7, 4 positions to the left.
  101. * 2. Move bit 3 and 5, 2 positions to the left.
  102. * 3. Move bit 1-4, 1 position to the left.
  103. *
  104. * Nibble 2 (n2):
  105. * 1. Move bit 0 and 1, 4 positions to the right.
  106. * 2. Move bit 2 and 4, 2 positions to the right.
  107. * 3. Move bit 3-6, 1 position to the right.
  108. *
  109. * Combine the two nibbles to a complete and swapped byte.
  110. */
  111. static inline u8 swap_bits_in_byte(u8 b)
  112. {
  113. #define R_SHIFT_4_MASK 0xc0 /* Bits 6 and 7, right shift 4 */
  114. #define R_SHIFT_2_MASK 0x28 /* (After right shift 4) Bits 3 and 5,
  115. right shift 2 */
  116. #define R_SHIFT_1_MASK 0x1e /* (After right shift 2) Bits 1-4,
  117. right shift 1 */
  118. #define L_SHIFT_4_MASK 0x03 /* Bits 0 and 1, left shift 4 */
  119. #define L_SHIFT_2_MASK 0x14 /* (After left shift 4) Bits 2 and 4,
  120. left shift 2 */
  121. #define L_SHIFT_1_MASK 0x78 /* (After left shift 1) Bits 3-6,
  122. left shift 1 */
  123. u8 n1;
  124. u8 n2;
  125. /* Swap most significant nibble */
  126. /* Right shift 4, bits 6 and 7 */
  127. n1 = ((b & R_SHIFT_4_MASK) >> 4) | (b & ~(R_SHIFT_4_MASK >> 4));
  128. /* Right shift 2, bits 3 and 5 */
  129. n1 = ((n1 & R_SHIFT_2_MASK) >> 2) | (n1 & ~(R_SHIFT_2_MASK >> 2));
  130. /* Right shift 1, bits 1-4 */
  131. n1 = (n1 & R_SHIFT_1_MASK) >> 1;
  132. /* Swap least significant nibble */
  133. /* Left shift 4, bits 0 and 1 */
  134. n2 = ((b & L_SHIFT_4_MASK) << 4) | (b & ~(L_SHIFT_4_MASK << 4));
  135. /* Left shift 2, bits 2 and 4 */
  136. n2 = ((n2 & L_SHIFT_2_MASK) << 2) | (n2 & ~(L_SHIFT_2_MASK << 2));
  137. /* Left shift 1, bits 3-6 */
  138. n2 = (n2 & L_SHIFT_1_MASK) << 1;
  139. return n1 | n2;
  140. }
  141. static inline void swap_words_in_key_and_bits_in_byte(const u8 *in,
  142. u8 *out, u32 len)
  143. {
  144. unsigned int i = 0;
  145. int j;
  146. int index = 0;
  147. j = len - BYTES_PER_WORD;
  148. while (j >= 0) {
  149. for (i = 0; i < BYTES_PER_WORD; i++) {
  150. index = len - j - BYTES_PER_WORD + i;
  151. out[j + i] =
  152. swap_bits_in_byte(in[index]);
  153. }
  154. j -= BYTES_PER_WORD;
  155. }
  156. }
  157. static void add_session_id(struct cryp_ctx *ctx)
  158. {
  159. /*
  160. * We never want 0 to be a valid value, since this is the default value
  161. * for the software context.
  162. */
  163. if (unlikely(atomic_inc_and_test(&session_id)))
  164. atomic_inc(&session_id);
  165. ctx->session_id = atomic_read(&session_id);
  166. }
  167. static irqreturn_t cryp_interrupt_handler(int irq, void *param)
  168. {
  169. struct cryp_ctx *ctx;
  170. int i;
  171. struct cryp_device_data *device_data;
  172. if (param == NULL) {
  173. BUG_ON(!param);
  174. return IRQ_HANDLED;
  175. }
  176. /* The device is coming from the one found in hw_crypt_noxts. */
  177. device_data = (struct cryp_device_data *)param;
  178. ctx = device_data->current_ctx;
  179. if (ctx == NULL) {
  180. BUG_ON(!ctx);
  181. return IRQ_HANDLED;
  182. }
  183. dev_dbg(ctx->device->dev, "[%s] (len: %d) %s, ", __func__, ctx->outlen,
  184. cryp_pending_irq_src(device_data, CRYP_IRQ_SRC_OUTPUT_FIFO) ?
  185. "out" : "in");
  186. if (cryp_pending_irq_src(device_data,
  187. CRYP_IRQ_SRC_OUTPUT_FIFO)) {
  188. if (ctx->outlen / ctx->blocksize > 0) {
  189. for (i = 0; i < ctx->blocksize / 4; i++) {
  190. *(ctx->outdata) = readl_relaxed(
  191. &device_data->base->dout);
  192. ctx->outdata += 4;
  193. ctx->outlen -= 4;
  194. }
  195. if (ctx->outlen == 0) {
  196. cryp_disable_irq_src(device_data,
  197. CRYP_IRQ_SRC_OUTPUT_FIFO);
  198. }
  199. }
  200. } else if (cryp_pending_irq_src(device_data,
  201. CRYP_IRQ_SRC_INPUT_FIFO)) {
  202. if (ctx->datalen / ctx->blocksize > 0) {
  203. for (i = 0 ; i < ctx->blocksize / 4; i++) {
  204. writel_relaxed(ctx->indata,
  205. &device_data->base->din);
  206. ctx->indata += 4;
  207. ctx->datalen -= 4;
  208. }
  209. if (ctx->datalen == 0)
  210. cryp_disable_irq_src(device_data,
  211. CRYP_IRQ_SRC_INPUT_FIFO);
  212. if (ctx->config.algomode == CRYP_ALGO_AES_XTS) {
  213. CRYP_PUT_BITS(&device_data->base->cr,
  214. CRYP_START_ENABLE,
  215. CRYP_CR_START_POS,
  216. CRYP_CR_START_MASK);
  217. cryp_wait_until_done(device_data);
  218. }
  219. }
  220. }
  221. return IRQ_HANDLED;
  222. }
  223. static int mode_is_aes(enum cryp_algo_mode mode)
  224. {
  225. return CRYP_ALGO_AES_ECB == mode ||
  226. CRYP_ALGO_AES_CBC == mode ||
  227. CRYP_ALGO_AES_CTR == mode ||
  228. CRYP_ALGO_AES_XTS == mode;
  229. }
  230. static int cfg_iv(struct cryp_device_data *device_data, u32 left, u32 right,
  231. enum cryp_init_vector_index index)
  232. {
  233. struct cryp_init_vector_value vector_value;
  234. dev_dbg(device_data->dev, "[%s]", __func__);
  235. vector_value.init_value_left = left;
  236. vector_value.init_value_right = right;
  237. return cryp_configure_init_vector(device_data,
  238. index,
  239. vector_value);
  240. }
  241. static int cfg_ivs(struct cryp_device_data *device_data, struct cryp_ctx *ctx)
  242. {
  243. int i;
  244. int status = 0;
  245. int num_of_regs = ctx->blocksize / 8;
  246. u32 iv[AES_BLOCK_SIZE / 4];
  247. dev_dbg(device_data->dev, "[%s]", __func__);
  248. /*
  249. * Since we loop on num_of_regs we need to have a check in case
  250. * someone provides an incorrect blocksize which would force calling
  251. * cfg_iv with i greater than 2 which is an error.
  252. */
  253. if (num_of_regs > 2) {
  254. dev_err(device_data->dev, "[%s] Incorrect blocksize %d",
  255. __func__, ctx->blocksize);
  256. return -EINVAL;
  257. }
  258. for (i = 0; i < ctx->blocksize / 4; i++)
  259. iv[i] = uint8p_to_uint32_be(ctx->iv + i*4);
  260. for (i = 0; i < num_of_regs; i++) {
  261. status = cfg_iv(device_data, iv[i*2], iv[i*2+1],
  262. (enum cryp_init_vector_index) i);
  263. if (status != 0)
  264. return status;
  265. }
  266. return status;
  267. }
  268. static int set_key(struct cryp_device_data *device_data,
  269. u32 left_key,
  270. u32 right_key,
  271. enum cryp_key_reg_index index)
  272. {
  273. struct cryp_key_value key_value;
  274. int cryp_error;
  275. dev_dbg(device_data->dev, "[%s]", __func__);
  276. key_value.key_value_left = left_key;
  277. key_value.key_value_right = right_key;
  278. cryp_error = cryp_configure_key_values(device_data,
  279. index,
  280. key_value);
  281. if (cryp_error != 0)
  282. dev_err(device_data->dev, "[%s]: "
  283. "cryp_configure_key_values() failed!", __func__);
  284. return cryp_error;
  285. }
  286. static int cfg_keys(struct cryp_ctx *ctx)
  287. {
  288. int i;
  289. int num_of_regs = ctx->keylen / 8;
  290. u32 swapped_key[CRYP_MAX_KEY_SIZE / 4];
  291. int cryp_error = 0;
  292. dev_dbg(ctx->device->dev, "[%s]", __func__);
  293. if (mode_is_aes(ctx->config.algomode)) {
  294. swap_words_in_key_and_bits_in_byte((u8 *)ctx->key,
  295. (u8 *)swapped_key,
  296. ctx->keylen);
  297. } else {
  298. for (i = 0; i < ctx->keylen / 4; i++)
  299. swapped_key[i] = uint8p_to_uint32_be(ctx->key + i*4);
  300. }
  301. for (i = 0; i < num_of_regs; i++) {
  302. cryp_error = set_key(ctx->device,
  303. *(((u32 *)swapped_key)+i*2),
  304. *(((u32 *)swapped_key)+i*2+1),
  305. (enum cryp_key_reg_index) i);
  306. if (cryp_error != 0) {
  307. dev_err(ctx->device->dev, "[%s]: set_key() failed!",
  308. __func__);
  309. return cryp_error;
  310. }
  311. }
  312. return cryp_error;
  313. }
  314. static int cryp_setup_context(struct cryp_ctx *ctx,
  315. struct cryp_device_data *device_data)
  316. {
  317. u32 control_register = CRYP_CR_DEFAULT;
  318. switch (cryp_mode) {
  319. case CRYP_MODE_INTERRUPT:
  320. writel_relaxed(CRYP_IMSC_DEFAULT, &device_data->base->imsc);
  321. break;
  322. case CRYP_MODE_DMA:
  323. writel_relaxed(CRYP_DMACR_DEFAULT, &device_data->base->dmacr);
  324. break;
  325. default:
  326. break;
  327. }
  328. if (ctx->updated == 0) {
  329. cryp_flush_inoutfifo(device_data);
  330. if (cfg_keys(ctx) != 0) {
  331. dev_err(ctx->device->dev, "[%s]: cfg_keys failed!",
  332. __func__);
  333. return -EINVAL;
  334. }
  335. if (ctx->iv &&
  336. CRYP_ALGO_AES_ECB != ctx->config.algomode &&
  337. CRYP_ALGO_DES_ECB != ctx->config.algomode &&
  338. CRYP_ALGO_TDES_ECB != ctx->config.algomode) {
  339. if (cfg_ivs(device_data, ctx) != 0)
  340. return -EPERM;
  341. }
  342. cryp_set_configuration(device_data, &ctx->config,
  343. &control_register);
  344. add_session_id(ctx);
  345. } else if (ctx->updated == 1 &&
  346. ctx->session_id != atomic_read(&session_id)) {
  347. cryp_flush_inoutfifo(device_data);
  348. cryp_restore_device_context(device_data, &ctx->dev_ctx);
  349. add_session_id(ctx);
  350. control_register = ctx->dev_ctx.cr;
  351. } else
  352. control_register = ctx->dev_ctx.cr;
  353. writel(control_register |
  354. (CRYP_CRYPEN_ENABLE << CRYP_CR_CRYPEN_POS),
  355. &device_data->base->cr);
  356. return 0;
  357. }
  358. static int cryp_get_device_data(struct cryp_ctx *ctx,
  359. struct cryp_device_data **device_data)
  360. {
  361. int ret;
  362. struct klist_iter device_iterator;
  363. struct klist_node *device_node;
  364. struct cryp_device_data *local_device_data = NULL;
  365. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  366. /* Wait until a device is available */
  367. ret = down_interruptible(&driver_data.device_allocation);
  368. if (ret)
  369. return ret; /* Interrupted */
  370. /* Select a device */
  371. klist_iter_init(&driver_data.device_list, &device_iterator);
  372. device_node = klist_next(&device_iterator);
  373. while (device_node) {
  374. local_device_data = container_of(device_node,
  375. struct cryp_device_data, list_node);
  376. spin_lock(&local_device_data->ctx_lock);
  377. /* current_ctx allocates a device, NULL = unallocated */
  378. if (local_device_data->current_ctx) {
  379. device_node = klist_next(&device_iterator);
  380. } else {
  381. local_device_data->current_ctx = ctx;
  382. ctx->device = local_device_data;
  383. spin_unlock(&local_device_data->ctx_lock);
  384. break;
  385. }
  386. spin_unlock(&local_device_data->ctx_lock);
  387. }
  388. klist_iter_exit(&device_iterator);
  389. if (!device_node) {
  390. /**
  391. * No free device found.
  392. * Since we allocated a device with down_interruptible, this
  393. * should not be able to happen.
  394. * Number of available devices, which are contained in
  395. * device_allocation, is therefore decremented by not doing
  396. * an up(device_allocation).
  397. */
  398. return -EBUSY;
  399. }
  400. *device_data = local_device_data;
  401. return 0;
  402. }
  403. static void cryp_dma_setup_channel(struct cryp_device_data *device_data,
  404. struct device *dev)
  405. {
  406. struct dma_slave_config mem2cryp = {
  407. .direction = DMA_MEM_TO_DEV,
  408. .dst_addr = device_data->phybase + CRYP_DMA_TX_FIFO,
  409. .dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
  410. .dst_maxburst = 4,
  411. };
  412. struct dma_slave_config cryp2mem = {
  413. .direction = DMA_DEV_TO_MEM,
  414. .src_addr = device_data->phybase + CRYP_DMA_RX_FIFO,
  415. .src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
  416. .src_maxburst = 4,
  417. };
  418. dma_cap_zero(device_data->dma.mask);
  419. dma_cap_set(DMA_SLAVE, device_data->dma.mask);
  420. device_data->dma.cfg_mem2cryp = mem_to_engine;
  421. device_data->dma.chan_mem2cryp =
  422. dma_request_channel(device_data->dma.mask,
  423. stedma40_filter,
  424. device_data->dma.cfg_mem2cryp);
  425. device_data->dma.cfg_cryp2mem = engine_to_mem;
  426. device_data->dma.chan_cryp2mem =
  427. dma_request_channel(device_data->dma.mask,
  428. stedma40_filter,
  429. device_data->dma.cfg_cryp2mem);
  430. dmaengine_slave_config(device_data->dma.chan_mem2cryp, &mem2cryp);
  431. dmaengine_slave_config(device_data->dma.chan_cryp2mem, &cryp2mem);
  432. init_completion(&device_data->dma.cryp_dma_complete);
  433. }
  434. static void cryp_dma_out_callback(void *data)
  435. {
  436. struct cryp_ctx *ctx = (struct cryp_ctx *) data;
  437. dev_dbg(ctx->device->dev, "[%s]: ", __func__);
  438. complete(&ctx->device->dma.cryp_dma_complete);
  439. }
  440. static int cryp_set_dma_transfer(struct cryp_ctx *ctx,
  441. struct scatterlist *sg,
  442. int len,
  443. enum dma_data_direction direction)
  444. {
  445. struct dma_async_tx_descriptor *desc;
  446. struct dma_chan *channel = NULL;
  447. dma_cookie_t cookie;
  448. dev_dbg(ctx->device->dev, "[%s]: ", __func__);
  449. if (unlikely(!IS_ALIGNED((u32)sg, 4))) {
  450. dev_err(ctx->device->dev, "[%s]: Data in sg list isn't "
  451. "aligned! Addr: 0x%08x", __func__, (u32)sg);
  452. return -EFAULT;
  453. }
  454. switch (direction) {
  455. case DMA_TO_DEVICE:
  456. channel = ctx->device->dma.chan_mem2cryp;
  457. ctx->device->dma.sg_src = sg;
  458. ctx->device->dma.sg_src_len = dma_map_sg(channel->device->dev,
  459. ctx->device->dma.sg_src,
  460. ctx->device->dma.nents_src,
  461. direction);
  462. if (!ctx->device->dma.sg_src_len) {
  463. dev_dbg(ctx->device->dev,
  464. "[%s]: Could not map the sg list (TO_DEVICE)",
  465. __func__);
  466. return -EFAULT;
  467. }
  468. dev_dbg(ctx->device->dev, "[%s]: Setting up DMA for buffer "
  469. "(TO_DEVICE)", __func__);
  470. desc = dmaengine_prep_slave_sg(channel,
  471. ctx->device->dma.sg_src,
  472. ctx->device->dma.sg_src_len,
  473. direction, DMA_CTRL_ACK);
  474. break;
  475. case DMA_FROM_DEVICE:
  476. channel = ctx->device->dma.chan_cryp2mem;
  477. ctx->device->dma.sg_dst = sg;
  478. ctx->device->dma.sg_dst_len = dma_map_sg(channel->device->dev,
  479. ctx->device->dma.sg_dst,
  480. ctx->device->dma.nents_dst,
  481. direction);
  482. if (!ctx->device->dma.sg_dst_len) {
  483. dev_dbg(ctx->device->dev,
  484. "[%s]: Could not map the sg list (FROM_DEVICE)",
  485. __func__);
  486. return -EFAULT;
  487. }
  488. dev_dbg(ctx->device->dev, "[%s]: Setting up DMA for buffer "
  489. "(FROM_DEVICE)", __func__);
  490. desc = dmaengine_prep_slave_sg(channel,
  491. ctx->device->dma.sg_dst,
  492. ctx->device->dma.sg_dst_len,
  493. direction,
  494. DMA_CTRL_ACK |
  495. DMA_PREP_INTERRUPT);
  496. desc->callback = cryp_dma_out_callback;
  497. desc->callback_param = ctx;
  498. break;
  499. default:
  500. dev_dbg(ctx->device->dev, "[%s]: Invalid DMA direction",
  501. __func__);
  502. return -EFAULT;
  503. }
  504. cookie = dmaengine_submit(desc);
  505. dma_async_issue_pending(channel);
  506. return 0;
  507. }
  508. static void cryp_dma_done(struct cryp_ctx *ctx)
  509. {
  510. struct dma_chan *chan;
  511. dev_dbg(ctx->device->dev, "[%s]: ", __func__);
  512. chan = ctx->device->dma.chan_mem2cryp;
  513. dmaengine_device_control(chan, DMA_TERMINATE_ALL, 0);
  514. dma_unmap_sg(chan->device->dev, ctx->device->dma.sg_src,
  515. ctx->device->dma.sg_src_len, DMA_TO_DEVICE);
  516. chan = ctx->device->dma.chan_cryp2mem;
  517. dmaengine_device_control(chan, DMA_TERMINATE_ALL, 0);
  518. dma_unmap_sg(chan->device->dev, ctx->device->dma.sg_dst,
  519. ctx->device->dma.sg_dst_len, DMA_FROM_DEVICE);
  520. }
  521. static int cryp_dma_write(struct cryp_ctx *ctx, struct scatterlist *sg,
  522. int len)
  523. {
  524. int error = cryp_set_dma_transfer(ctx, sg, len, DMA_TO_DEVICE);
  525. dev_dbg(ctx->device->dev, "[%s]: ", __func__);
  526. if (error) {
  527. dev_dbg(ctx->device->dev, "[%s]: cryp_set_dma_transfer() "
  528. "failed", __func__);
  529. return error;
  530. }
  531. return len;
  532. }
  533. static int cryp_dma_read(struct cryp_ctx *ctx, struct scatterlist *sg, int len)
  534. {
  535. int error = cryp_set_dma_transfer(ctx, sg, len, DMA_FROM_DEVICE);
  536. if (error) {
  537. dev_dbg(ctx->device->dev, "[%s]: cryp_set_dma_transfer() "
  538. "failed", __func__);
  539. return error;
  540. }
  541. return len;
  542. }
  543. static void cryp_polling_mode(struct cryp_ctx *ctx,
  544. struct cryp_device_data *device_data)
  545. {
  546. int len = ctx->blocksize / BYTES_PER_WORD;
  547. int remaining_length = ctx->datalen;
  548. u32 *indata = (u32 *)ctx->indata;
  549. u32 *outdata = (u32 *)ctx->outdata;
  550. while (remaining_length > 0) {
  551. writesl(&device_data->base->din, indata, len);
  552. indata += len;
  553. remaining_length -= (len * BYTES_PER_WORD);
  554. cryp_wait_until_done(device_data);
  555. readsl(&device_data->base->dout, outdata, len);
  556. outdata += len;
  557. cryp_wait_until_done(device_data);
  558. }
  559. }
  560. static int cryp_disable_power(struct device *dev,
  561. struct cryp_device_data *device_data,
  562. bool save_device_context)
  563. {
  564. int ret = 0;
  565. dev_dbg(dev, "[%s]", __func__);
  566. spin_lock(&device_data->power_state_spinlock);
  567. if (!device_data->power_state)
  568. goto out;
  569. spin_lock(&device_data->ctx_lock);
  570. if (save_device_context && device_data->current_ctx) {
  571. cryp_save_device_context(device_data,
  572. &device_data->current_ctx->dev_ctx,
  573. cryp_mode);
  574. device_data->restore_dev_ctx = true;
  575. }
  576. spin_unlock(&device_data->ctx_lock);
  577. clk_disable(device_data->clk);
  578. ret = regulator_disable(device_data->pwr_regulator);
  579. if (ret)
  580. dev_err(dev, "[%s]: "
  581. "regulator_disable() failed!",
  582. __func__);
  583. device_data->power_state = false;
  584. out:
  585. spin_unlock(&device_data->power_state_spinlock);
  586. return ret;
  587. }
  588. static int cryp_enable_power(
  589. struct device *dev,
  590. struct cryp_device_data *device_data,
  591. bool restore_device_context)
  592. {
  593. int ret = 0;
  594. dev_dbg(dev, "[%s]", __func__);
  595. spin_lock(&device_data->power_state_spinlock);
  596. if (!device_data->power_state) {
  597. ret = regulator_enable(device_data->pwr_regulator);
  598. if (ret) {
  599. dev_err(dev, "[%s]: regulator_enable() failed!",
  600. __func__);
  601. goto out;
  602. }
  603. ret = clk_enable(device_data->clk);
  604. if (ret) {
  605. dev_err(dev, "[%s]: clk_enable() failed!",
  606. __func__);
  607. regulator_disable(device_data->pwr_regulator);
  608. goto out;
  609. }
  610. device_data->power_state = true;
  611. }
  612. if (device_data->restore_dev_ctx) {
  613. spin_lock(&device_data->ctx_lock);
  614. if (restore_device_context && device_data->current_ctx) {
  615. device_data->restore_dev_ctx = false;
  616. cryp_restore_device_context(device_data,
  617. &device_data->current_ctx->dev_ctx);
  618. }
  619. spin_unlock(&device_data->ctx_lock);
  620. }
  621. out:
  622. spin_unlock(&device_data->power_state_spinlock);
  623. return ret;
  624. }
  625. static int hw_crypt_noxts(struct cryp_ctx *ctx,
  626. struct cryp_device_data *device_data)
  627. {
  628. int ret = 0;
  629. const u8 *indata = ctx->indata;
  630. u8 *outdata = ctx->outdata;
  631. u32 datalen = ctx->datalen;
  632. u32 outlen = datalen;
  633. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  634. ctx->outlen = ctx->datalen;
  635. if (unlikely(!IS_ALIGNED((u32)indata, 4))) {
  636. pr_debug(DEV_DBG_NAME " [%s]: Data isn't aligned! Addr: "
  637. "0x%08x", __func__, (u32)indata);
  638. return -EINVAL;
  639. }
  640. ret = cryp_setup_context(ctx, device_data);
  641. if (ret)
  642. goto out;
  643. if (cryp_mode == CRYP_MODE_INTERRUPT) {
  644. cryp_enable_irq_src(device_data, CRYP_IRQ_SRC_INPUT_FIFO |
  645. CRYP_IRQ_SRC_OUTPUT_FIFO);
  646. /*
  647. * ctx->outlen is decremented in the cryp_interrupt_handler
  648. * function. We had to add cpu_relax() (barrier) to make sure
  649. * that gcc didn't optimze away this variable.
  650. */
  651. while (ctx->outlen > 0)
  652. cpu_relax();
  653. } else if (cryp_mode == CRYP_MODE_POLLING ||
  654. cryp_mode == CRYP_MODE_DMA) {
  655. /*
  656. * The reason for having DMA in this if case is that if we are
  657. * running cryp_mode = 2, then we separate DMA routines for
  658. * handling cipher/plaintext > blocksize, except when
  659. * running the normal CRYPTO_ALG_TYPE_CIPHER, then we still use
  660. * the polling mode. Overhead of doing DMA setup eats up the
  661. * benefits using it.
  662. */
  663. cryp_polling_mode(ctx, device_data);
  664. } else {
  665. dev_err(ctx->device->dev, "[%s]: Invalid operation mode!",
  666. __func__);
  667. ret = -EPERM;
  668. goto out;
  669. }
  670. cryp_save_device_context(device_data, &ctx->dev_ctx, cryp_mode);
  671. ctx->updated = 1;
  672. out:
  673. ctx->indata = indata;
  674. ctx->outdata = outdata;
  675. ctx->datalen = datalen;
  676. ctx->outlen = outlen;
  677. return ret;
  678. }
  679. static int get_nents(struct scatterlist *sg, int nbytes)
  680. {
  681. int nents = 0;
  682. while (nbytes > 0) {
  683. nbytes -= sg->length;
  684. sg = scatterwalk_sg_next(sg);
  685. nents++;
  686. }
  687. return nents;
  688. }
  689. static int ablk_dma_crypt(struct ablkcipher_request *areq)
  690. {
  691. struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
  692. struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  693. struct cryp_device_data *device_data;
  694. int bytes_written = 0;
  695. int bytes_read = 0;
  696. int ret;
  697. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  698. ctx->datalen = areq->nbytes;
  699. ctx->outlen = areq->nbytes;
  700. ret = cryp_get_device_data(ctx, &device_data);
  701. if (ret)
  702. return ret;
  703. ret = cryp_setup_context(ctx, device_data);
  704. if (ret)
  705. goto out;
  706. /* We have the device now, so store the nents in the dma struct. */
  707. ctx->device->dma.nents_src = get_nents(areq->src, ctx->datalen);
  708. ctx->device->dma.nents_dst = get_nents(areq->dst, ctx->outlen);
  709. /* Enable DMA in- and output. */
  710. cryp_configure_for_dma(device_data, CRYP_DMA_ENABLE_BOTH_DIRECTIONS);
  711. bytes_written = cryp_dma_write(ctx, areq->src, ctx->datalen);
  712. bytes_read = cryp_dma_read(ctx, areq->dst, bytes_written);
  713. wait_for_completion(&ctx->device->dma.cryp_dma_complete);
  714. cryp_dma_done(ctx);
  715. cryp_save_device_context(device_data, &ctx->dev_ctx, cryp_mode);
  716. ctx->updated = 1;
  717. out:
  718. spin_lock(&device_data->ctx_lock);
  719. device_data->current_ctx = NULL;
  720. ctx->device = NULL;
  721. spin_unlock(&device_data->ctx_lock);
  722. /*
  723. * The down_interruptible part for this semaphore is called in
  724. * cryp_get_device_data.
  725. */
  726. up(&driver_data.device_allocation);
  727. if (unlikely(bytes_written != bytes_read))
  728. return -EPERM;
  729. return 0;
  730. }
  731. static int ablk_crypt(struct ablkcipher_request *areq)
  732. {
  733. struct ablkcipher_walk walk;
  734. struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
  735. struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  736. struct cryp_device_data *device_data;
  737. unsigned long src_paddr;
  738. unsigned long dst_paddr;
  739. int ret;
  740. int nbytes;
  741. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  742. ret = cryp_get_device_data(ctx, &device_data);
  743. if (ret)
  744. goto out;
  745. ablkcipher_walk_init(&walk, areq->dst, areq->src, areq->nbytes);
  746. ret = ablkcipher_walk_phys(areq, &walk);
  747. if (ret) {
  748. pr_err(DEV_DBG_NAME "[%s]: ablkcipher_walk_phys() failed!",
  749. __func__);
  750. goto out;
  751. }
  752. while ((nbytes = walk.nbytes) > 0) {
  753. ctx->iv = walk.iv;
  754. src_paddr = (page_to_phys(walk.src.page) + walk.src.offset);
  755. ctx->indata = phys_to_virt(src_paddr);
  756. dst_paddr = (page_to_phys(walk.dst.page) + walk.dst.offset);
  757. ctx->outdata = phys_to_virt(dst_paddr);
  758. ctx->datalen = nbytes - (nbytes % ctx->blocksize);
  759. ret = hw_crypt_noxts(ctx, device_data);
  760. if (ret)
  761. goto out;
  762. nbytes -= ctx->datalen;
  763. ret = ablkcipher_walk_done(areq, &walk, nbytes);
  764. if (ret)
  765. goto out;
  766. }
  767. ablkcipher_walk_complete(&walk);
  768. out:
  769. /* Release the device */
  770. spin_lock(&device_data->ctx_lock);
  771. device_data->current_ctx = NULL;
  772. ctx->device = NULL;
  773. spin_unlock(&device_data->ctx_lock);
  774. /*
  775. * The down_interruptible part for this semaphore is called in
  776. * cryp_get_device_data.
  777. */
  778. up(&driver_data.device_allocation);
  779. return ret;
  780. }
  781. static int aes_ablkcipher_setkey(struct crypto_ablkcipher *cipher,
  782. const u8 *key, unsigned int keylen)
  783. {
  784. struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  785. u32 *flags = &cipher->base.crt_flags;
  786. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  787. switch (keylen) {
  788. case AES_KEYSIZE_128:
  789. ctx->config.keysize = CRYP_KEY_SIZE_128;
  790. break;
  791. case AES_KEYSIZE_192:
  792. ctx->config.keysize = CRYP_KEY_SIZE_192;
  793. break;
  794. case AES_KEYSIZE_256:
  795. ctx->config.keysize = CRYP_KEY_SIZE_256;
  796. break;
  797. default:
  798. pr_err(DEV_DBG_NAME "[%s]: Unknown keylen!", __func__);
  799. *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  800. return -EINVAL;
  801. }
  802. memcpy(ctx->key, key, keylen);
  803. ctx->keylen = keylen;
  804. ctx->updated = 0;
  805. return 0;
  806. }
  807. static int des_ablkcipher_setkey(struct crypto_ablkcipher *cipher,
  808. const u8 *key, unsigned int keylen)
  809. {
  810. struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  811. u32 *flags = &cipher->base.crt_flags;
  812. u32 tmp[DES_EXPKEY_WORDS];
  813. int ret;
  814. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  815. if (keylen != DES_KEY_SIZE) {
  816. *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  817. pr_debug(DEV_DBG_NAME " [%s]: CRYPTO_TFM_RES_BAD_KEY_LEN",
  818. __func__);
  819. return -EINVAL;
  820. }
  821. ret = des_ekey(tmp, key);
  822. if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
  823. *flags |= CRYPTO_TFM_RES_WEAK_KEY;
  824. pr_debug(DEV_DBG_NAME " [%s]: CRYPTO_TFM_REQ_WEAK_KEY",
  825. __func__);
  826. return -EINVAL;
  827. }
  828. memcpy(ctx->key, key, keylen);
  829. ctx->keylen = keylen;
  830. ctx->updated = 0;
  831. return 0;
  832. }
  833. static int des3_ablkcipher_setkey(struct crypto_ablkcipher *cipher,
  834. const u8 *key, unsigned int keylen)
  835. {
  836. struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  837. u32 *flags = &cipher->base.crt_flags;
  838. const u32 *K = (const u32 *)key;
  839. u32 tmp[DES3_EDE_EXPKEY_WORDS];
  840. int i, ret;
  841. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  842. if (keylen != DES3_EDE_KEY_SIZE) {
  843. *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  844. pr_debug(DEV_DBG_NAME " [%s]: CRYPTO_TFM_RES_BAD_KEY_LEN",
  845. __func__);
  846. return -EINVAL;
  847. }
  848. /* Checking key interdependency for weak key detection. */
  849. if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
  850. !((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
  851. (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
  852. *flags |= CRYPTO_TFM_RES_WEAK_KEY;
  853. pr_debug(DEV_DBG_NAME " [%s]: CRYPTO_TFM_REQ_WEAK_KEY",
  854. __func__);
  855. return -EINVAL;
  856. }
  857. for (i = 0; i < 3; i++) {
  858. ret = des_ekey(tmp, key + i*DES_KEY_SIZE);
  859. if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
  860. *flags |= CRYPTO_TFM_RES_WEAK_KEY;
  861. pr_debug(DEV_DBG_NAME " [%s]: "
  862. "CRYPTO_TFM_REQ_WEAK_KEY", __func__);
  863. return -EINVAL;
  864. }
  865. }
  866. memcpy(ctx->key, key, keylen);
  867. ctx->keylen = keylen;
  868. ctx->updated = 0;
  869. return 0;
  870. }
  871. static int cryp_blk_encrypt(struct ablkcipher_request *areq)
  872. {
  873. struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
  874. struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  875. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  876. ctx->config.algodir = CRYP_ALGORITHM_ENCRYPT;
  877. /*
  878. * DMA does not work for DES due to a hw bug */
  879. if (cryp_mode == CRYP_MODE_DMA && mode_is_aes(ctx->config.algomode))
  880. return ablk_dma_crypt(areq);
  881. /* For everything except DMA, we run the non DMA version. */
  882. return ablk_crypt(areq);
  883. }
  884. static int cryp_blk_decrypt(struct ablkcipher_request *areq)
  885. {
  886. struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
  887. struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  888. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  889. ctx->config.algodir = CRYP_ALGORITHM_DECRYPT;
  890. /* DMA does not work for DES due to a hw bug */
  891. if (cryp_mode == CRYP_MODE_DMA && mode_is_aes(ctx->config.algomode))
  892. return ablk_dma_crypt(areq);
  893. /* For everything except DMA, we run the non DMA version. */
  894. return ablk_crypt(areq);
  895. }
  896. struct cryp_algo_template {
  897. enum cryp_algo_mode algomode;
  898. struct crypto_alg crypto;
  899. };
  900. static int cryp_cra_init(struct crypto_tfm *tfm)
  901. {
  902. struct cryp_ctx *ctx = crypto_tfm_ctx(tfm);
  903. struct crypto_alg *alg = tfm->__crt_alg;
  904. struct cryp_algo_template *cryp_alg = container_of(alg,
  905. struct cryp_algo_template,
  906. crypto);
  907. ctx->config.algomode = cryp_alg->algomode;
  908. ctx->blocksize = crypto_tfm_alg_blocksize(tfm);
  909. return 0;
  910. }
  911. static struct cryp_algo_template cryp_algs[] = {
  912. {
  913. .algomode = CRYP_ALGO_AES_ECB,
  914. .crypto = {
  915. .cra_name = "aes",
  916. .cra_driver_name = "aes-ux500",
  917. .cra_priority = 300,
  918. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  919. CRYPTO_ALG_ASYNC,
  920. .cra_blocksize = AES_BLOCK_SIZE,
  921. .cra_ctxsize = sizeof(struct cryp_ctx),
  922. .cra_alignmask = 3,
  923. .cra_type = &crypto_ablkcipher_type,
  924. .cra_init = cryp_cra_init,
  925. .cra_module = THIS_MODULE,
  926. .cra_u = {
  927. .ablkcipher = {
  928. .min_keysize = AES_MIN_KEY_SIZE,
  929. .max_keysize = AES_MAX_KEY_SIZE,
  930. .setkey = aes_ablkcipher_setkey,
  931. .encrypt = cryp_blk_encrypt,
  932. .decrypt = cryp_blk_decrypt
  933. }
  934. }
  935. }
  936. },
  937. {
  938. .algomode = CRYP_ALGO_AES_ECB,
  939. .crypto = {
  940. .cra_name = "ecb(aes)",
  941. .cra_driver_name = "ecb-aes-ux500",
  942. .cra_priority = 300,
  943. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  944. CRYPTO_ALG_ASYNC,
  945. .cra_blocksize = AES_BLOCK_SIZE,
  946. .cra_ctxsize = sizeof(struct cryp_ctx),
  947. .cra_alignmask = 3,
  948. .cra_type = &crypto_ablkcipher_type,
  949. .cra_init = cryp_cra_init,
  950. .cra_module = THIS_MODULE,
  951. .cra_u = {
  952. .ablkcipher = {
  953. .min_keysize = AES_MIN_KEY_SIZE,
  954. .max_keysize = AES_MAX_KEY_SIZE,
  955. .setkey = aes_ablkcipher_setkey,
  956. .encrypt = cryp_blk_encrypt,
  957. .decrypt = cryp_blk_decrypt,
  958. }
  959. }
  960. }
  961. },
  962. {
  963. .algomode = CRYP_ALGO_AES_CBC,
  964. .crypto = {
  965. .cra_name = "cbc(aes)",
  966. .cra_driver_name = "cbc-aes-ux500",
  967. .cra_priority = 300,
  968. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  969. CRYPTO_ALG_ASYNC,
  970. .cra_blocksize = AES_BLOCK_SIZE,
  971. .cra_ctxsize = sizeof(struct cryp_ctx),
  972. .cra_alignmask = 3,
  973. .cra_type = &crypto_ablkcipher_type,
  974. .cra_init = cryp_cra_init,
  975. .cra_module = THIS_MODULE,
  976. .cra_u = {
  977. .ablkcipher = {
  978. .min_keysize = AES_MIN_KEY_SIZE,
  979. .max_keysize = AES_MAX_KEY_SIZE,
  980. .setkey = aes_ablkcipher_setkey,
  981. .encrypt = cryp_blk_encrypt,
  982. .decrypt = cryp_blk_decrypt,
  983. .ivsize = AES_BLOCK_SIZE,
  984. }
  985. }
  986. }
  987. },
  988. {
  989. .algomode = CRYP_ALGO_AES_CTR,
  990. .crypto = {
  991. .cra_name = "ctr(aes)",
  992. .cra_driver_name = "ctr-aes-ux500",
  993. .cra_priority = 300,
  994. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  995. CRYPTO_ALG_ASYNC,
  996. .cra_blocksize = AES_BLOCK_SIZE,
  997. .cra_ctxsize = sizeof(struct cryp_ctx),
  998. .cra_alignmask = 3,
  999. .cra_type = &crypto_ablkcipher_type,
  1000. .cra_init = cryp_cra_init,
  1001. .cra_module = THIS_MODULE,
  1002. .cra_u = {
  1003. .ablkcipher = {
  1004. .min_keysize = AES_MIN_KEY_SIZE,
  1005. .max_keysize = AES_MAX_KEY_SIZE,
  1006. .setkey = aes_ablkcipher_setkey,
  1007. .encrypt = cryp_blk_encrypt,
  1008. .decrypt = cryp_blk_decrypt,
  1009. .ivsize = AES_BLOCK_SIZE,
  1010. }
  1011. }
  1012. }
  1013. },
  1014. {
  1015. .algomode = CRYP_ALGO_DES_ECB,
  1016. .crypto = {
  1017. .cra_name = "des",
  1018. .cra_driver_name = "des-ux500",
  1019. .cra_priority = 300,
  1020. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  1021. CRYPTO_ALG_ASYNC,
  1022. .cra_blocksize = DES_BLOCK_SIZE,
  1023. .cra_ctxsize = sizeof(struct cryp_ctx),
  1024. .cra_alignmask = 3,
  1025. .cra_type = &crypto_ablkcipher_type,
  1026. .cra_init = cryp_cra_init,
  1027. .cra_module = THIS_MODULE,
  1028. .cra_u = {
  1029. .ablkcipher = {
  1030. .min_keysize = DES_KEY_SIZE,
  1031. .max_keysize = DES_KEY_SIZE,
  1032. .setkey = des_ablkcipher_setkey,
  1033. .encrypt = cryp_blk_encrypt,
  1034. .decrypt = cryp_blk_decrypt
  1035. }
  1036. }
  1037. }
  1038. },
  1039. {
  1040. .algomode = CRYP_ALGO_TDES_ECB,
  1041. .crypto = {
  1042. .cra_name = "des3_ede",
  1043. .cra_driver_name = "des3_ede-ux500",
  1044. .cra_priority = 300,
  1045. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  1046. CRYPTO_ALG_ASYNC,
  1047. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1048. .cra_ctxsize = sizeof(struct cryp_ctx),
  1049. .cra_alignmask = 3,
  1050. .cra_type = &crypto_ablkcipher_type,
  1051. .cra_init = cryp_cra_init,
  1052. .cra_module = THIS_MODULE,
  1053. .cra_u = {
  1054. .ablkcipher = {
  1055. .min_keysize = DES3_EDE_KEY_SIZE,
  1056. .max_keysize = DES3_EDE_KEY_SIZE,
  1057. .setkey = des_ablkcipher_setkey,
  1058. .encrypt = cryp_blk_encrypt,
  1059. .decrypt = cryp_blk_decrypt
  1060. }
  1061. }
  1062. }
  1063. },
  1064. {
  1065. .algomode = CRYP_ALGO_DES_ECB,
  1066. .crypto = {
  1067. .cra_name = "ecb(des)",
  1068. .cra_driver_name = "ecb-des-ux500",
  1069. .cra_priority = 300,
  1070. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  1071. CRYPTO_ALG_ASYNC,
  1072. .cra_blocksize = DES_BLOCK_SIZE,
  1073. .cra_ctxsize = sizeof(struct cryp_ctx),
  1074. .cra_alignmask = 3,
  1075. .cra_type = &crypto_ablkcipher_type,
  1076. .cra_init = cryp_cra_init,
  1077. .cra_module = THIS_MODULE,
  1078. .cra_u = {
  1079. .ablkcipher = {
  1080. .min_keysize = DES_KEY_SIZE,
  1081. .max_keysize = DES_KEY_SIZE,
  1082. .setkey = des_ablkcipher_setkey,
  1083. .encrypt = cryp_blk_encrypt,
  1084. .decrypt = cryp_blk_decrypt,
  1085. }
  1086. }
  1087. }
  1088. },
  1089. {
  1090. .algomode = CRYP_ALGO_TDES_ECB,
  1091. .crypto = {
  1092. .cra_name = "ecb(des3_ede)",
  1093. .cra_driver_name = "ecb-des3_ede-ux500",
  1094. .cra_priority = 300,
  1095. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  1096. CRYPTO_ALG_ASYNC,
  1097. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1098. .cra_ctxsize = sizeof(struct cryp_ctx),
  1099. .cra_alignmask = 3,
  1100. .cra_type = &crypto_ablkcipher_type,
  1101. .cra_init = cryp_cra_init,
  1102. .cra_module = THIS_MODULE,
  1103. .cra_u = {
  1104. .ablkcipher = {
  1105. .min_keysize = DES3_EDE_KEY_SIZE,
  1106. .max_keysize = DES3_EDE_KEY_SIZE,
  1107. .setkey = des3_ablkcipher_setkey,
  1108. .encrypt = cryp_blk_encrypt,
  1109. .decrypt = cryp_blk_decrypt,
  1110. }
  1111. }
  1112. }
  1113. },
  1114. {
  1115. .algomode = CRYP_ALGO_DES_CBC,
  1116. .crypto = {
  1117. .cra_name = "cbc(des)",
  1118. .cra_driver_name = "cbc-des-ux500",
  1119. .cra_priority = 300,
  1120. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  1121. CRYPTO_ALG_ASYNC,
  1122. .cra_blocksize = DES_BLOCK_SIZE,
  1123. .cra_ctxsize = sizeof(struct cryp_ctx),
  1124. .cra_alignmask = 3,
  1125. .cra_type = &crypto_ablkcipher_type,
  1126. .cra_init = cryp_cra_init,
  1127. .cra_module = THIS_MODULE,
  1128. .cra_u = {
  1129. .ablkcipher = {
  1130. .min_keysize = DES_KEY_SIZE,
  1131. .max_keysize = DES_KEY_SIZE,
  1132. .setkey = des_ablkcipher_setkey,
  1133. .encrypt = cryp_blk_encrypt,
  1134. .decrypt = cryp_blk_decrypt,
  1135. }
  1136. }
  1137. }
  1138. },
  1139. {
  1140. .algomode = CRYP_ALGO_TDES_CBC,
  1141. .crypto = {
  1142. .cra_name = "cbc(des3_ede)",
  1143. .cra_driver_name = "cbc-des3_ede-ux500",
  1144. .cra_priority = 300,
  1145. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  1146. CRYPTO_ALG_ASYNC,
  1147. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1148. .cra_ctxsize = sizeof(struct cryp_ctx),
  1149. .cra_alignmask = 3,
  1150. .cra_type = &crypto_ablkcipher_type,
  1151. .cra_init = cryp_cra_init,
  1152. .cra_module = THIS_MODULE,
  1153. .cra_u = {
  1154. .ablkcipher = {
  1155. .min_keysize = DES3_EDE_KEY_SIZE,
  1156. .max_keysize = DES3_EDE_KEY_SIZE,
  1157. .setkey = des3_ablkcipher_setkey,
  1158. .encrypt = cryp_blk_encrypt,
  1159. .decrypt = cryp_blk_decrypt,
  1160. .ivsize = DES3_EDE_BLOCK_SIZE,
  1161. }
  1162. }
  1163. }
  1164. }
  1165. };
  1166. /**
  1167. * cryp_algs_register_all -
  1168. */
  1169. static int cryp_algs_register_all(void)
  1170. {
  1171. int ret;
  1172. int i;
  1173. int count;
  1174. pr_debug("[%s]", __func__);
  1175. for (i = 0; i < ARRAY_SIZE(cryp_algs); i++) {
  1176. ret = crypto_register_alg(&cryp_algs[i].crypto);
  1177. if (ret) {
  1178. count = i;
  1179. pr_err("[%s] alg registration failed",
  1180. cryp_algs[i].crypto.cra_driver_name);
  1181. goto unreg;
  1182. }
  1183. }
  1184. return 0;
  1185. unreg:
  1186. for (i = 0; i < count; i++)
  1187. crypto_unregister_alg(&cryp_algs[i].crypto);
  1188. return ret;
  1189. }
  1190. /**
  1191. * cryp_algs_unregister_all -
  1192. */
  1193. static void cryp_algs_unregister_all(void)
  1194. {
  1195. int i;
  1196. pr_debug(DEV_DBG_NAME " [%s]", __func__);
  1197. for (i = 0; i < ARRAY_SIZE(cryp_algs); i++)
  1198. crypto_unregister_alg(&cryp_algs[i].crypto);
  1199. }
  1200. static int ux500_cryp_probe(struct platform_device *pdev)
  1201. {
  1202. int ret;
  1203. int cryp_error = 0;
  1204. struct resource *res = NULL;
  1205. struct resource *res_irq = NULL;
  1206. struct cryp_device_data *device_data;
  1207. struct cryp_protection_config prot = {
  1208. .privilege_access = CRYP_STATE_ENABLE
  1209. };
  1210. struct device *dev = &pdev->dev;
  1211. dev_dbg(dev, "[%s]", __func__);
  1212. device_data = kzalloc(sizeof(struct cryp_device_data), GFP_ATOMIC);
  1213. if (!device_data) {
  1214. dev_err(dev, "[%s]: kzalloc() failed!", __func__);
  1215. ret = -ENOMEM;
  1216. goto out;
  1217. }
  1218. device_data->dev = dev;
  1219. device_data->current_ctx = NULL;
  1220. /* Grab the DMA configuration from platform data. */
  1221. mem_to_engine = &((struct cryp_platform_data *)
  1222. dev->platform_data)->mem_to_engine;
  1223. engine_to_mem = &((struct cryp_platform_data *)
  1224. dev->platform_data)->engine_to_mem;
  1225. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1226. if (!res) {
  1227. dev_err(dev, "[%s]: platform_get_resource() failed",
  1228. __func__);
  1229. ret = -ENODEV;
  1230. goto out_kfree;
  1231. }
  1232. res = request_mem_region(res->start, resource_size(res), pdev->name);
  1233. if (res == NULL) {
  1234. dev_err(dev, "[%s]: request_mem_region() failed",
  1235. __func__);
  1236. ret = -EBUSY;
  1237. goto out_kfree;
  1238. }
  1239. device_data->phybase = res->start;
  1240. device_data->base = ioremap(res->start, resource_size(res));
  1241. if (!device_data->base) {
  1242. dev_err(dev, "[%s]: ioremap failed!", __func__);
  1243. ret = -ENOMEM;
  1244. goto out_free_mem;
  1245. }
  1246. spin_lock_init(&device_data->ctx_lock);
  1247. spin_lock_init(&device_data->power_state_spinlock);
  1248. /* Enable power for CRYP hardware block */
  1249. device_data->pwr_regulator = regulator_get(&pdev->dev, "v-ape");
  1250. if (IS_ERR(device_data->pwr_regulator)) {
  1251. dev_err(dev, "[%s]: could not get cryp regulator", __func__);
  1252. ret = PTR_ERR(device_data->pwr_regulator);
  1253. device_data->pwr_regulator = NULL;
  1254. goto out_unmap;
  1255. }
  1256. /* Enable the clk for CRYP hardware block */
  1257. device_data->clk = clk_get(&pdev->dev, NULL);
  1258. if (IS_ERR(device_data->clk)) {
  1259. dev_err(dev, "[%s]: clk_get() failed!", __func__);
  1260. ret = PTR_ERR(device_data->clk);
  1261. goto out_regulator;
  1262. }
  1263. ret = clk_prepare(device_data->clk);
  1264. if (ret) {
  1265. dev_err(dev, "[%s]: clk_prepare() failed!", __func__);
  1266. goto out_clk;
  1267. }
  1268. /* Enable device power (and clock) */
  1269. ret = cryp_enable_power(device_data->dev, device_data, false);
  1270. if (ret) {
  1271. dev_err(dev, "[%s]: cryp_enable_power() failed!", __func__);
  1272. goto out_clk_unprepare;
  1273. }
  1274. cryp_error = cryp_check(device_data);
  1275. if (cryp_error != 0) {
  1276. dev_err(dev, "[%s]: cryp_init() failed!", __func__);
  1277. ret = -EINVAL;
  1278. goto out_power;
  1279. }
  1280. cryp_error = cryp_configure_protection(device_data, &prot);
  1281. if (cryp_error != 0) {
  1282. dev_err(dev, "[%s]: cryp_configure_protection() failed!",
  1283. __func__);
  1284. ret = -EINVAL;
  1285. goto out_power;
  1286. }
  1287. res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1288. if (!res_irq) {
  1289. dev_err(dev, "[%s]: IORESOURCE_IRQ unavailable",
  1290. __func__);
  1291. ret = -ENODEV;
  1292. goto out_power;
  1293. }
  1294. ret = request_irq(res_irq->start,
  1295. cryp_interrupt_handler,
  1296. 0,
  1297. "cryp1",
  1298. device_data);
  1299. if (ret) {
  1300. dev_err(dev, "[%s]: Unable to request IRQ", __func__);
  1301. goto out_power;
  1302. }
  1303. if (cryp_mode == CRYP_MODE_DMA)
  1304. cryp_dma_setup_channel(device_data, dev);
  1305. platform_set_drvdata(pdev, device_data);
  1306. /* Put the new device into the device list... */
  1307. klist_add_tail(&device_data->list_node, &driver_data.device_list);
  1308. /* ... and signal that a new device is available. */
  1309. up(&driver_data.device_allocation);
  1310. atomic_set(&session_id, 1);
  1311. ret = cryp_algs_register_all();
  1312. if (ret) {
  1313. dev_err(dev, "[%s]: cryp_algs_register_all() failed!",
  1314. __func__);
  1315. goto out_power;
  1316. }
  1317. dev_info(dev, "successfully registered\n");
  1318. return 0;
  1319. out_power:
  1320. cryp_disable_power(device_data->dev, device_data, false);
  1321. out_clk_unprepare:
  1322. clk_unprepare(device_data->clk);
  1323. out_clk:
  1324. clk_put(device_data->clk);
  1325. out_regulator:
  1326. regulator_put(device_data->pwr_regulator);
  1327. out_unmap:
  1328. iounmap(device_data->base);
  1329. out_free_mem:
  1330. release_mem_region(res->start, resource_size(res));
  1331. out_kfree:
  1332. kfree(device_data);
  1333. out:
  1334. return ret;
  1335. }
  1336. static int ux500_cryp_remove(struct platform_device *pdev)
  1337. {
  1338. struct resource *res = NULL;
  1339. struct resource *res_irq = NULL;
  1340. struct cryp_device_data *device_data;
  1341. dev_dbg(&pdev->dev, "[%s]", __func__);
  1342. device_data = platform_get_drvdata(pdev);
  1343. if (!device_data) {
  1344. dev_err(&pdev->dev, "[%s]: platform_get_drvdata() failed!",
  1345. __func__);
  1346. return -ENOMEM;
  1347. }
  1348. /* Try to decrease the number of available devices. */
  1349. if (down_trylock(&driver_data.device_allocation))
  1350. return -EBUSY;
  1351. /* Check that the device is free */
  1352. spin_lock(&device_data->ctx_lock);
  1353. /* current_ctx allocates a device, NULL = unallocated */
  1354. if (device_data->current_ctx) {
  1355. /* The device is busy */
  1356. spin_unlock(&device_data->ctx_lock);
  1357. /* Return the device to the pool. */
  1358. up(&driver_data.device_allocation);
  1359. return -EBUSY;
  1360. }
  1361. spin_unlock(&device_data->ctx_lock);
  1362. /* Remove the device from the list */
  1363. if (klist_node_attached(&device_data->list_node))
  1364. klist_remove(&device_data->list_node);
  1365. /* If this was the last device, remove the services */
  1366. if (list_empty(&driver_data.device_list.k_list))
  1367. cryp_algs_unregister_all();
  1368. res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1369. if (!res_irq)
  1370. dev_err(&pdev->dev, "[%s]: IORESOURCE_IRQ, unavailable",
  1371. __func__);
  1372. else {
  1373. disable_irq(res_irq->start);
  1374. free_irq(res_irq->start, device_data);
  1375. }
  1376. if (cryp_disable_power(&pdev->dev, device_data, false))
  1377. dev_err(&pdev->dev, "[%s]: cryp_disable_power() failed",
  1378. __func__);
  1379. clk_unprepare(device_data->clk);
  1380. clk_put(device_data->clk);
  1381. regulator_put(device_data->pwr_regulator);
  1382. iounmap(device_data->base);
  1383. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1384. if (res)
  1385. release_mem_region(res->start, resource_size(res));
  1386. kfree(device_data);
  1387. return 0;
  1388. }
  1389. static void ux500_cryp_shutdown(struct platform_device *pdev)
  1390. {
  1391. struct resource *res_irq = NULL;
  1392. struct cryp_device_data *device_data;
  1393. dev_dbg(&pdev->dev, "[%s]", __func__);
  1394. device_data = platform_get_drvdata(pdev);
  1395. if (!device_data) {
  1396. dev_err(&pdev->dev, "[%s]: platform_get_drvdata() failed!",
  1397. __func__);
  1398. return;
  1399. }
  1400. /* Check that the device is free */
  1401. spin_lock(&device_data->ctx_lock);
  1402. /* current_ctx allocates a device, NULL = unallocated */
  1403. if (!device_data->current_ctx) {
  1404. if (down_trylock(&driver_data.device_allocation))
  1405. dev_dbg(&pdev->dev, "[%s]: Cryp still in use!"
  1406. "Shutting down anyway...", __func__);
  1407. /**
  1408. * (Allocate the device)
  1409. * Need to set this to non-null (dummy) value,
  1410. * to avoid usage if context switching.
  1411. */
  1412. device_data->current_ctx++;
  1413. }
  1414. spin_unlock(&device_data->ctx_lock);
  1415. /* Remove the device from the list */
  1416. if (klist_node_attached(&device_data->list_node))
  1417. klist_remove(&device_data->list_node);
  1418. /* If this was the last device, remove the services */
  1419. if (list_empty(&driver_data.device_list.k_list))
  1420. cryp_algs_unregister_all();
  1421. res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1422. if (!res_irq)
  1423. dev_err(&pdev->dev, "[%s]: IORESOURCE_IRQ, unavailable",
  1424. __func__);
  1425. else {
  1426. disable_irq(res_irq->start);
  1427. free_irq(res_irq->start, device_data);
  1428. }
  1429. if (cryp_disable_power(&pdev->dev, device_data, false))
  1430. dev_err(&pdev->dev, "[%s]: cryp_disable_power() failed",
  1431. __func__);
  1432. }
  1433. static int ux500_cryp_suspend(struct device *dev)
  1434. {
  1435. int ret;
  1436. struct platform_device *pdev = to_platform_device(dev);
  1437. struct cryp_device_data *device_data;
  1438. struct resource *res_irq;
  1439. struct cryp_ctx *temp_ctx = NULL;
  1440. dev_dbg(dev, "[%s]", __func__);
  1441. /* Handle state? */
  1442. device_data = platform_get_drvdata(pdev);
  1443. if (!device_data) {
  1444. dev_err(dev, "[%s]: platform_get_drvdata() failed!", __func__);
  1445. return -ENOMEM;
  1446. }
  1447. res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1448. if (!res_irq)
  1449. dev_err(dev, "[%s]: IORESOURCE_IRQ, unavailable", __func__);
  1450. else
  1451. disable_irq(res_irq->start);
  1452. spin_lock(&device_data->ctx_lock);
  1453. if (!device_data->current_ctx)
  1454. device_data->current_ctx++;
  1455. spin_unlock(&device_data->ctx_lock);
  1456. if (device_data->current_ctx == ++temp_ctx) {
  1457. if (down_interruptible(&driver_data.device_allocation))
  1458. dev_dbg(dev, "[%s]: down_interruptible() failed",
  1459. __func__);
  1460. ret = cryp_disable_power(dev, device_data, false);
  1461. } else
  1462. ret = cryp_disable_power(dev, device_data, true);
  1463. if (ret)
  1464. dev_err(dev, "[%s]: cryp_disable_power()", __func__);
  1465. return ret;
  1466. }
  1467. static int ux500_cryp_resume(struct device *dev)
  1468. {
  1469. int ret = 0;
  1470. struct platform_device *pdev = to_platform_device(dev);
  1471. struct cryp_device_data *device_data;
  1472. struct resource *res_irq;
  1473. struct cryp_ctx *temp_ctx = NULL;
  1474. dev_dbg(dev, "[%s]", __func__);
  1475. device_data = platform_get_drvdata(pdev);
  1476. if (!device_data) {
  1477. dev_err(dev, "[%s]: platform_get_drvdata() failed!", __func__);
  1478. return -ENOMEM;
  1479. }
  1480. spin_lock(&device_data->ctx_lock);
  1481. if (device_data->current_ctx == ++temp_ctx)
  1482. device_data->current_ctx = NULL;
  1483. spin_unlock(&device_data->ctx_lock);
  1484. if (!device_data->current_ctx)
  1485. up(&driver_data.device_allocation);
  1486. else
  1487. ret = cryp_enable_power(dev, device_data, true);
  1488. if (ret)
  1489. dev_err(dev, "[%s]: cryp_enable_power() failed!", __func__);
  1490. else {
  1491. res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1492. if (res_irq)
  1493. enable_irq(res_irq->start);
  1494. }
  1495. return ret;
  1496. }
  1497. static SIMPLE_DEV_PM_OPS(ux500_cryp_pm, ux500_cryp_suspend, ux500_cryp_resume);
  1498. static const struct of_device_id ux500_cryp_match[] = {
  1499. { .compatible = "stericsson,ux500-cryp" },
  1500. { },
  1501. };
  1502. static struct platform_driver cryp_driver = {
  1503. .probe = ux500_cryp_probe,
  1504. .remove = ux500_cryp_remove,
  1505. .shutdown = ux500_cryp_shutdown,
  1506. .driver = {
  1507. .owner = THIS_MODULE,
  1508. .name = "cryp1",
  1509. .of_match_table = ux500_cryp_match,
  1510. .pm = &ux500_cryp_pm,
  1511. }
  1512. };
  1513. static int __init ux500_cryp_mod_init(void)
  1514. {
  1515. pr_debug("[%s] is called!", __func__);
  1516. klist_init(&driver_data.device_list, NULL, NULL);
  1517. /* Initialize the semaphore to 0 devices (locked state) */
  1518. sema_init(&driver_data.device_allocation, 0);
  1519. return platform_driver_register(&cryp_driver);
  1520. }
  1521. static void __exit ux500_cryp_mod_fini(void)
  1522. {
  1523. pr_debug("[%s] is called!", __func__);
  1524. platform_driver_unregister(&cryp_driver);
  1525. return;
  1526. }
  1527. module_init(ux500_cryp_mod_init);
  1528. module_exit(ux500_cryp_mod_fini);
  1529. module_param(cryp_mode, int, 0);
  1530. MODULE_DESCRIPTION("Driver for ST-Ericsson UX500 CRYP crypto engine.");
  1531. MODULE_ALIAS("aes-all");
  1532. MODULE_ALIAS("des-all");
  1533. MODULE_LICENSE("GPL");