qce40.c 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695
  1. /* Qualcomm Crypto Engine driver.
  2. *
  3. * Copyright (c) 2011 - 2013, The Linux Foundation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 and
  7. * only version 2 as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/mod_devicetable.h>
  18. #include <linux/device.h>
  19. #include <linux/clk.h>
  20. #include <linux/err.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/io.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/delay.h>
  26. #include <linux/crypto.h>
  27. #include <linux/qcedev.h>
  28. #include <linux/bitops.h>
  29. #include <crypto/hash.h>
  30. #include <crypto/sha.h>
  31. #include <mach/dma.h>
  32. #include <mach/clk.h>
  33. #include <mach/socinfo.h>
  34. #include "qce.h"
  35. #include "qce40.h"
  36. #include "qcryptohw_40.h"
  37. /* ADM definitions */
  38. #define LI_SG_CMD (1 << 31) /* last index in the scatter gather cmd */
  39. #define SRC_INDEX_SG_CMD(index) ((index & 0x3fff) << 16)
  40. #define DST_INDEX_SG_CMD(index) (index & 0x3fff)
  41. #define ADM_DESC_LAST (1 << 31)
  42. #define QCE_FIFO_SIZE 0x8000
  43. /*
  44. * CE HW device structure.
  45. * Each engine has an instance of the structure.
  46. * Each engine can only handle one crypto operation at one time. It is up to
  47. * the sw above to ensure single threading of operation on an engine.
  48. */
  49. struct qce_device {
  50. struct device *pdev; /* Handle to platform_device structure */
  51. unsigned char *coh_vmem; /* Allocated coherent virtual memory */
  52. dma_addr_t coh_pmem; /* Allocated coherent physical memory */
  53. int memsize; /* Memory allocated */
  54. void __iomem *iobase; /* Virtual io base of CE HW */
  55. unsigned int phy_iobase; /* Physical io base of CE HW */
  56. struct clk *ce_core_src_clk; /* Handle to CE src clk*/
  57. struct clk *ce_core_clk; /* Handle to CE clk */
  58. struct clk *ce_clk; /* Handle to CE clk */
  59. qce_comp_func_ptr_t qce_cb; /* qce callback function pointer */
  60. int assoc_nents;
  61. int ivsize;
  62. int authsize;
  63. int src_nents;
  64. int dst_nents;
  65. void *areq;
  66. enum qce_cipher_mode_enum mode;
  67. struct ce_dm_data ce_dm;
  68. };
  69. /* Standard initialization vector for SHA-1, source: FIPS 180-2 */
  70. static uint8_t _std_init_vector_sha1_uint8[] = {
  71. 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB, 0x89,
  72. 0x98, 0xBA, 0xDC, 0xFE, 0x10, 0x32, 0x54, 0x76,
  73. 0xC3, 0xD2, 0xE1, 0xF0
  74. };
  75. /* Standard initialization vector for SHA-256, source: FIPS 180-2 */
  76. static uint8_t _std_init_vector_sha256_uint8[] = {
  77. 0x6A, 0x09, 0xE6, 0x67, 0xBB, 0x67, 0xAE, 0x85,
  78. 0x3C, 0x6E, 0xF3, 0x72, 0xA5, 0x4F, 0xF5, 0x3A,
  79. 0x51, 0x0E, 0x52, 0x7F, 0x9B, 0x05, 0x68, 0x8C,
  80. 0x1F, 0x83, 0xD9, 0xAB, 0x5B, 0xE0, 0xCD, 0x19
  81. };
  82. static void _byte_stream_swap_to_net_words(uint32_t *iv, unsigned char *b,
  83. unsigned int len)
  84. {
  85. unsigned i, j;
  86. unsigned char swap_iv[AES_IV_LENGTH];
  87. memset(swap_iv, 0, AES_IV_LENGTH);
  88. for (i = (AES_IV_LENGTH-len), j = len-1; i < AES_IV_LENGTH; i++, j--)
  89. swap_iv[i] = b[j];
  90. memcpy(iv, swap_iv, AES_IV_LENGTH);
  91. }
  92. static int count_sg(struct scatterlist *sg, int nbytes)
  93. {
  94. int i;
  95. for (i = 0; nbytes > 0; i++, sg = scatterwalk_sg_next(sg))
  96. nbytes -= sg->length;
  97. return i;
  98. }
  99. static int qce_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  100. enum dma_data_direction direction)
  101. {
  102. int i;
  103. for (i = 0; i < nents; ++i) {
  104. dma_map_sg(dev, sg, 1, direction);
  105. sg = scatterwalk_sg_next(sg);
  106. }
  107. return nents;
  108. }
  109. static int qce_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
  110. int nents, enum dma_data_direction direction)
  111. {
  112. int i;
  113. for (i = 0; i < nents; ++i) {
  114. dma_unmap_sg(dev, sg, 1, direction);
  115. sg = scatterwalk_sg_next(sg);
  116. }
  117. return nents;
  118. }
  119. static int dma_map_pmem_sg(struct buf_info *pmem, unsigned entries,
  120. struct scatterlist *sg)
  121. {
  122. int i;
  123. for (i = 0; i < entries; i++) {
  124. sg->dma_address = (dma_addr_t)pmem->offset;
  125. sg++;
  126. pmem++;
  127. }
  128. return 0;
  129. }
  130. static int _probe_ce_engine(struct qce_device *pce_dev)
  131. {
  132. unsigned int val;
  133. unsigned int rev;
  134. unsigned int ret;
  135. val = (uint32_t)(*((uint32_t *)pce_dev->ce_dm.buffer.version));
  136. if (((val & 0xfffffff) != 0x0000043) &&
  137. ((val & 0xfffffff) != 0x0000042) &&
  138. ((val & 0xfffffff) != 0x0000040)) {
  139. dev_err(pce_dev->pdev,
  140. "Unknown Qualcomm crypto device at 0x%x 0x%x\n",
  141. pce_dev->phy_iobase, val);
  142. return -EIO;
  143. };
  144. rev = (val & CRYPTO_CORE_REV_MASK);
  145. if (rev >= 0x42) {
  146. dev_info(pce_dev->pdev,
  147. "Qualcomm Crypto 4.2 device found at 0x%x\n",
  148. pce_dev->phy_iobase);
  149. pce_dev->ce_dm.ce_block_size = 64;
  150. /* Configure the crypto register to support 64byte CRCI if it
  151. * is not XPU protected and the HW version of device is greater
  152. * than 0x42.
  153. * Crypto config register returns a 0 when it is XPU protected.
  154. */
  155. ret = readl_relaxed(pce_dev->iobase + CRYPTO_CONFIG_REG);
  156. if (ret) {
  157. val = BIT(CRYPTO_MASK_DOUT_INTR) |
  158. BIT(CRYPTO_MASK_DIN_INTR) |
  159. BIT(CRYPTO_MASK_OP_DONE_INTR) |
  160. BIT(CRYPTO_MASK_ERR_INTR) |
  161. (CRYPTO_REQ_SIZE_ENUM_64_BYTES <<
  162. CRYPTO_REQ_SIZE) |
  163. (CRYPTO_FIFO_ENUM_64_BYTES <<
  164. CRYPTO_FIFO_THRESHOLD);
  165. writel_relaxed(val, pce_dev->iobase +
  166. CRYPTO_CONFIG_REG);
  167. } /* end of if (ret) */
  168. } else {
  169. if (rev == 0x40) {
  170. dev_info(pce_dev->pdev,
  171. "Qualcomm Crypto 4.0 device found at 0x%x\n",
  172. pce_dev->phy_iobase);
  173. pce_dev->ce_dm.ce_block_size = 16;
  174. }
  175. }
  176. dev_info(pce_dev->pdev,
  177. "IO base 0x%x\n, ce_in channel %d , "
  178. "ce_out channel %d\n, "
  179. "crci_in %d, crci_out %d\n",
  180. (unsigned int) pce_dev->iobase,
  181. pce_dev->ce_dm.chan_ce_in, pce_dev->ce_dm.chan_ce_out,
  182. pce_dev->ce_dm.crci_in, pce_dev->ce_dm.crci_out);
  183. return 0;
  184. };
  185. static void _check_probe_done_call_back(struct msm_dmov_cmd *cmd_ptr,
  186. unsigned int result, struct msm_dmov_errdata *err)
  187. {
  188. struct qce_device *pce_dev;
  189. pce_dev = (struct qce_device *) cmd_ptr->user;
  190. if (result != ADM_STATUS_OK) {
  191. dev_err(pce_dev->pdev, "Qualcomm ADM status error %x\n",
  192. result);
  193. pce_dev->ce_dm.chan_ce_in_status = -1;
  194. } else {
  195. _probe_ce_engine(pce_dev);
  196. pce_dev->ce_dm.chan_ce_in_status = 0;
  197. }
  198. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  199. };
  200. static int _init_ce_engine(struct qce_device *pce_dev)
  201. {
  202. int status;
  203. /* Reset ce */
  204. clk_reset(pce_dev->ce_core_clk, CLK_RESET_ASSERT);
  205. clk_reset(pce_dev->ce_core_clk, CLK_RESET_DEASSERT);
  206. /*
  207. * Ensure previous instruction (any writes to CLK registers)
  208. * to toggle the CLK reset lines was completed before configuring
  209. * ce engine. The ce engine configuration settings should not be lost
  210. * becasue of clk reset.
  211. */
  212. mb();
  213. /*
  214. * Clear ACCESS_VIOL bit in CRYPTO_STATUS REGISTER
  215. */
  216. status = readl_relaxed(pce_dev->iobase + CRYPTO_STATUS_REG);
  217. *((uint32_t *)(pce_dev->ce_dm.buffer.status)) = status & (~0x40000);
  218. /*
  219. * Ensure ce configuration is completed.
  220. */
  221. mb();
  222. pce_dev->ce_dm.chan_ce_in_cmd->complete_func =
  223. _check_probe_done_call_back;
  224. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  225. pce_dev->ce_dm.cmdptrlist.probe_ce_hw;
  226. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IN_PROG;
  227. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_COMP;
  228. msm_dmov_enqueue_cmd(pce_dev->ce_dm.chan_ce_in,
  229. pce_dev->ce_dm.chan_ce_in_cmd);
  230. return 0;
  231. };
  232. static int _ce_setup_hash_cmdrptrlist(struct qce_device *pce_dev,
  233. struct qce_sha_req *sreq)
  234. {
  235. struct ce_cmdptrlists_ops *cmdptrlist = &pce_dev->ce_dm.cmdptrlist;
  236. switch (sreq->alg) {
  237. case QCE_HASH_SHA1:
  238. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr = cmdptrlist->auth_sha1;
  239. break;
  240. case QCE_HASH_SHA256:
  241. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr = cmdptrlist->auth_sha256;
  242. break;
  243. case QCE_HASH_SHA1_HMAC:
  244. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  245. cmdptrlist->auth_sha1_hmac;
  246. break;
  247. case QCE_HASH_SHA256_HMAC:
  248. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  249. cmdptrlist->auth_sha256_hmac;
  250. break;
  251. case QCE_HASH_AES_CMAC:
  252. if (sreq->authklen == AES128_KEY_SIZE)
  253. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  254. cmdptrlist->auth_aes_128_cmac;
  255. else
  256. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  257. cmdptrlist->auth_aes_256_cmac;
  258. break;
  259. default:
  260. break;
  261. }
  262. return 0;
  263. }
  264. static int _ce_setup_hash(struct qce_device *pce_dev, struct qce_sha_req *sreq)
  265. {
  266. uint32_t diglen;
  267. int i;
  268. uint32_t auth_cfg = 0;
  269. bool sha1 = false;
  270. if (sreq->alg == QCE_HASH_AES_CMAC) {
  271. memcpy(pce_dev->ce_dm.buffer.auth_key, sreq->authkey,
  272. sreq->authklen);
  273. auth_cfg |= (1 << CRYPTO_LAST);
  274. auth_cfg |= (CRYPTO_AUTH_MODE_CMAC << CRYPTO_AUTH_MODE);
  275. auth_cfg |= (CRYPTO_AUTH_SIZE_ENUM_16_BYTES <<
  276. CRYPTO_AUTH_SIZE);
  277. auth_cfg |= CRYPTO_AUTH_ALG_AES << CRYPTO_AUTH_ALG;
  278. switch (sreq->authklen) {
  279. case AES128_KEY_SIZE:
  280. auth_cfg |= (CRYPTO_AUTH_KEY_SZ_AES128 <<
  281. CRYPTO_AUTH_KEY_SIZE);
  282. break;
  283. case AES256_KEY_SIZE:
  284. auth_cfg |= (CRYPTO_AUTH_KEY_SZ_AES256 <<
  285. CRYPTO_AUTH_KEY_SIZE);
  286. break;
  287. default:
  288. break;
  289. }
  290. goto go_proc;
  291. }
  292. /* if not the last, the size has to be on the block boundary */
  293. if (sreq->last_blk == 0 && (sreq->size % SHA256_BLOCK_SIZE))
  294. return -EIO;
  295. switch (sreq->alg) {
  296. case QCE_HASH_SHA1:
  297. case QCE_HASH_SHA1_HMAC:
  298. diglen = SHA1_DIGEST_SIZE;
  299. sha1 = true;
  300. break;
  301. case QCE_HASH_SHA256:
  302. case QCE_HASH_SHA256_HMAC:
  303. diglen = SHA256_DIGEST_SIZE;
  304. break;
  305. default:
  306. return -EINVAL;
  307. }
  308. if ((sreq->alg == QCE_HASH_SHA1_HMAC) ||
  309. (sreq->alg == QCE_HASH_SHA256_HMAC)) {
  310. memcpy(pce_dev->ce_dm.buffer.auth_key, sreq->authkey,
  311. sreq->authklen);
  312. auth_cfg |= (CRYPTO_AUTH_MODE_HMAC << CRYPTO_AUTH_MODE);
  313. } else {
  314. auth_cfg |= (CRYPTO_AUTH_MODE_HASH << CRYPTO_AUTH_MODE);
  315. }
  316. /* write 20/32 bytes, 5/8 words into auth_iv for SHA1/SHA256 */
  317. if (sreq->first_blk) {
  318. if (sha1)
  319. memcpy(pce_dev->ce_dm.buffer.auth_iv,
  320. _std_init_vector_sha1_uint8, diglen);
  321. else
  322. memcpy(pce_dev->ce_dm.buffer.auth_iv,
  323. _std_init_vector_sha256_uint8, diglen);
  324. } else {
  325. memcpy(pce_dev->ce_dm.buffer.auth_iv, sreq->digest,
  326. diglen);
  327. }
  328. /* write auth_bytecnt 0/1/2/3, start with 0 */
  329. for (i = 0; i < 4; i++)
  330. *(((uint32_t *)(pce_dev->ce_dm.buffer.auth_byte_count) + i)) =
  331. sreq->auth_data[i];
  332. /* write seg_cfg */
  333. if (sha1)
  334. auth_cfg |= (CRYPTO_AUTH_SIZE_SHA1 << CRYPTO_AUTH_SIZE);
  335. else
  336. auth_cfg |= (CRYPTO_AUTH_SIZE_SHA256 << CRYPTO_AUTH_SIZE);
  337. if (sreq->last_blk)
  338. auth_cfg |= 1 << CRYPTO_LAST;
  339. auth_cfg |= CRYPTO_AUTH_ALG_SHA << CRYPTO_AUTH_ALG;
  340. go_proc:
  341. auth_cfg |= (CRYPTO_AUTH_POS_BEFORE << CRYPTO_AUTH_POS);
  342. /* write auth seg cfg */
  343. *((uint32_t *)(pce_dev->ce_dm.buffer.auth_seg_cfg_size_start)) =
  344. auth_cfg;
  345. /* write auth seg size */
  346. *((uint32_t *)(pce_dev->ce_dm.buffer.auth_seg_cfg_size_start) + 1) =
  347. sreq->size;
  348. /* write auth seg size start*/
  349. *((uint32_t *)(pce_dev->ce_dm.buffer.auth_seg_cfg_size_start)+2) = 0;
  350. /* write seg size */
  351. *((uint32_t *)(pce_dev->ce_dm.buffer.seg_size)) = sreq->size;
  352. /* clear status */
  353. *((uint32_t *)(pce_dev->ce_dm.buffer.status)) = 0;
  354. _ce_setup_hash_cmdrptrlist(pce_dev, sreq);
  355. return 0;
  356. }
  357. static int _ce_setup_cipher_cmdrptrlist(struct qce_device *pce_dev,
  358. struct qce_req *creq)
  359. {
  360. struct ce_cmdptrlists_ops *cmdptrlist =
  361. &pce_dev->ce_dm.cmdptrlist;
  362. if (creq->alg != CIPHER_ALG_AES) {
  363. switch (creq->alg) {
  364. case CIPHER_ALG_DES:
  365. if (creq->mode == QCE_MODE_ECB) {
  366. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  367. cmdptrlist->cipher_des_ecb;
  368. } else {
  369. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  370. cmdptrlist->cipher_des_cbc;
  371. }
  372. break;
  373. case CIPHER_ALG_3DES:
  374. if (creq->mode == QCE_MODE_ECB) {
  375. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  376. cmdptrlist->cipher_3des_ecb;
  377. } else {
  378. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  379. cmdptrlist->cipher_3des_cbc;
  380. }
  381. break;
  382. default:
  383. break;
  384. }
  385. } else {
  386. switch (creq->mode) {
  387. case QCE_MODE_ECB:
  388. if (creq->encklen == AES128_KEY_SIZE) {
  389. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  390. cmdptrlist->cipher_aes_128_ecb;
  391. } else {
  392. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  393. cmdptrlist->cipher_aes_256_ecb;
  394. }
  395. break;
  396. case QCE_MODE_CBC:
  397. if (creq->encklen == AES128_KEY_SIZE) {
  398. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  399. cmdptrlist->cipher_aes_128_cbc_ctr;
  400. } else {
  401. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  402. cmdptrlist->cipher_aes_256_cbc_ctr;
  403. }
  404. break;
  405. case QCE_MODE_CTR:
  406. if (creq->encklen == AES128_KEY_SIZE) {
  407. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  408. cmdptrlist->cipher_aes_128_cbc_ctr;
  409. } else {
  410. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  411. cmdptrlist->cipher_aes_256_cbc_ctr;
  412. }
  413. break;
  414. case QCE_MODE_XTS:
  415. if (creq->encklen == AES128_KEY_SIZE) {
  416. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  417. cmdptrlist->cipher_aes_128_xts;
  418. } else {
  419. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  420. cmdptrlist->cipher_aes_256_xts;
  421. }
  422. break;
  423. case QCE_MODE_CCM:
  424. if (creq->encklen == AES128_KEY_SIZE) {
  425. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  426. cmdptrlist->aead_aes_128_ccm;
  427. } else {
  428. pce_dev->ce_dm.chan_ce_in_cmd->cmdptr =
  429. cmdptrlist->aead_aes_256_ccm;
  430. }
  431. break;
  432. default:
  433. break;
  434. }
  435. }
  436. switch (creq->mode) {
  437. case QCE_MODE_CCM:
  438. pce_dev->ce_dm.chan_ce_out_cmd->cmdptr =
  439. cmdptrlist->aead_ce_out;
  440. break;
  441. case QCE_MODE_ECB:
  442. pce_dev->ce_dm.chan_ce_out_cmd->cmdptr =
  443. cmdptrlist->cipher_ce_out;
  444. break;
  445. default:
  446. pce_dev->ce_dm.chan_ce_out_cmd->cmdptr =
  447. cmdptrlist->cipher_ce_out_get_iv;
  448. break;
  449. }
  450. return 0;
  451. }
  452. static int _ce_setup_cipher(struct qce_device *pce_dev, struct qce_req *creq,
  453. uint32_t totallen_in, uint32_t coffset)
  454. {
  455. uint32_t enck_size_in_word = creq->encklen / sizeof(uint32_t);
  456. uint32_t encr_cfg = 0;
  457. uint32_t ivsize = creq->ivsize;
  458. struct ce_reg_buffer_addr *buffer = &pce_dev->ce_dm.buffer;
  459. if (creq->mode == QCE_MODE_XTS)
  460. memcpy(buffer->encr_key, creq->enckey,
  461. creq->encklen/2);
  462. else
  463. memcpy(buffer->encr_key, creq->enckey, creq->encklen);
  464. if ((creq->op == QCE_REQ_AEAD) && (creq->mode == QCE_MODE_CCM)) {
  465. uint32_t noncelen32 = MAX_NONCE/sizeof(uint32_t);
  466. uint32_t auth_cfg = 0;
  467. /* write nonce */
  468. memcpy(buffer->auth_nonce_info, creq->nonce, MAX_NONCE);
  469. memcpy(buffer->auth_key, creq->enckey, creq->encklen);
  470. auth_cfg |= (noncelen32 << CRYPTO_AUTH_NONCE_NUM_WORDS);
  471. auth_cfg &= ~(1 << CRYPTO_USE_HW_KEY_AUTH);
  472. auth_cfg |= (1 << CRYPTO_LAST);
  473. if (creq->dir == QCE_ENCRYPT)
  474. auth_cfg |= (CRYPTO_AUTH_POS_BEFORE << CRYPTO_AUTH_POS);
  475. else
  476. auth_cfg |= (CRYPTO_AUTH_POS_AFTER << CRYPTO_AUTH_POS);
  477. auth_cfg |= (((creq->authsize >> 1) - 2) << CRYPTO_AUTH_SIZE);
  478. auth_cfg |= (CRYPTO_AUTH_MODE_CCM << CRYPTO_AUTH_MODE);
  479. if (creq->authklen == AES128_KEY_SIZE)
  480. auth_cfg |= (CRYPTO_AUTH_KEY_SZ_AES128 <<
  481. CRYPTO_AUTH_KEY_SIZE);
  482. else {
  483. if (creq->authklen == AES256_KEY_SIZE)
  484. auth_cfg |= (CRYPTO_AUTH_KEY_SZ_AES256 <<
  485. CRYPTO_AUTH_KEY_SIZE);
  486. }
  487. auth_cfg |= (CRYPTO_AUTH_ALG_AES << CRYPTO_AUTH_ALG);
  488. *((uint32_t *)(buffer->auth_seg_cfg_size_start)) = auth_cfg;
  489. if (creq->dir == QCE_ENCRYPT)
  490. *((uint32_t *)(buffer->auth_seg_cfg_size_start) + 1) =
  491. totallen_in;
  492. else
  493. *((uint32_t *)(buffer->auth_seg_cfg_size_start) + 1) =
  494. (totallen_in - creq->authsize);
  495. *((uint32_t *)(buffer->auth_seg_cfg_size_start) + 2) = 0;
  496. }
  497. *((uint32_t *)(buffer->auth_seg_cfg_size_start) + 2) = 0;
  498. switch (creq->mode) {
  499. case QCE_MODE_ECB:
  500. encr_cfg |= (CRYPTO_ENCR_MODE_ECB << CRYPTO_ENCR_MODE);
  501. break;
  502. case QCE_MODE_CBC:
  503. encr_cfg |= (CRYPTO_ENCR_MODE_CBC << CRYPTO_ENCR_MODE);
  504. break;
  505. case QCE_MODE_XTS:
  506. encr_cfg |= (CRYPTO_ENCR_MODE_XTS << CRYPTO_ENCR_MODE);
  507. break;
  508. case QCE_MODE_CCM:
  509. encr_cfg |= (CRYPTO_ENCR_MODE_CCM << CRYPTO_ENCR_MODE);
  510. break;
  511. case QCE_MODE_CTR:
  512. default:
  513. encr_cfg |= (CRYPTO_ENCR_MODE_CTR << CRYPTO_ENCR_MODE);
  514. break;
  515. }
  516. pce_dev->mode = creq->mode;
  517. switch (creq->alg) {
  518. case CIPHER_ALG_DES:
  519. if (creq->mode != QCE_MODE_ECB)
  520. memcpy(buffer->encr_cntr_iv, creq->iv, ivsize);
  521. encr_cfg |= ((CRYPTO_ENCR_KEY_SZ_DES << CRYPTO_ENCR_KEY_SZ) |
  522. (CRYPTO_ENCR_ALG_DES << CRYPTO_ENCR_ALG));
  523. break;
  524. case CIPHER_ALG_3DES:
  525. if (creq->mode != QCE_MODE_ECB)
  526. memcpy(buffer->encr_cntr_iv, creq->iv, ivsize);
  527. encr_cfg |= ((CRYPTO_ENCR_KEY_SZ_3DES << CRYPTO_ENCR_KEY_SZ) |
  528. (CRYPTO_ENCR_ALG_DES << CRYPTO_ENCR_ALG));
  529. break;
  530. case CIPHER_ALG_AES:
  531. default:
  532. if (creq->mode == QCE_MODE_XTS) {
  533. memcpy(buffer->encr_xts_key, (creq->enckey +
  534. creq->encklen/2), creq->encklen/2);
  535. *((uint32_t *)(buffer->encr_xts_du_size)) =
  536. creq->cryptlen;
  537. }
  538. if (creq->mode != QCE_MODE_ECB) {
  539. if (creq->mode == QCE_MODE_XTS)
  540. _byte_stream_swap_to_net_words(
  541. (uint32_t *)(buffer->encr_cntr_iv),
  542. creq->iv, ivsize);
  543. else
  544. memcpy(buffer->encr_cntr_iv, creq->iv,
  545. ivsize);
  546. }
  547. /* set number of counter bits */
  548. *((uint32_t *)(buffer->encr_mask)) = (uint32_t)0xffffffff;
  549. if (creq->op == QCE_REQ_ABLK_CIPHER_NO_KEY) {
  550. encr_cfg |= (CRYPTO_ENCR_KEY_SZ_AES128 <<
  551. CRYPTO_ENCR_KEY_SZ);
  552. encr_cfg |= CRYPTO_ENCR_ALG_AES << CRYPTO_ENCR_ALG;
  553. } else {
  554. uint32_t key_size;
  555. if (creq->mode == QCE_MODE_XTS) {
  556. key_size = creq->encklen/2;
  557. enck_size_in_word = key_size/sizeof(uint32_t);
  558. } else {
  559. key_size = creq->encklen;
  560. }
  561. switch (key_size) {
  562. case AES128_KEY_SIZE:
  563. encr_cfg |= (CRYPTO_ENCR_KEY_SZ_AES128 <<
  564. CRYPTO_ENCR_KEY_SZ);
  565. break;
  566. case AES256_KEY_SIZE:
  567. default:
  568. encr_cfg |= (CRYPTO_ENCR_KEY_SZ_AES256 <<
  569. CRYPTO_ENCR_KEY_SZ);
  570. break;
  571. } /* end of switch (creq->encklen) */
  572. encr_cfg |= CRYPTO_ENCR_ALG_AES << CRYPTO_ENCR_ALG;
  573. } /* else of if (creq->op == QCE_REQ_ABLK_CIPHER_NO_KEY) */
  574. break;
  575. } /* end of switch (creq->mode) */
  576. /* write encr seg cfg */
  577. encr_cfg |= ((creq->dir == QCE_ENCRYPT) ? 1 : 0) << CRYPTO_ENCODE;
  578. /* write encr seg cfg */
  579. *((uint32_t *)(buffer->encr_seg_cfg_size_start)) = encr_cfg;
  580. /* write encr seg size */
  581. if ((creq->mode == QCE_MODE_CCM) && (creq->dir == QCE_DECRYPT))
  582. *((uint32_t *)(buffer->encr_seg_cfg_size_start) + 1) =
  583. (creq->cryptlen + creq->authsize);
  584. else
  585. *((uint32_t *)(buffer->encr_seg_cfg_size_start) + 1) =
  586. creq->cryptlen;
  587. *((uint32_t *)(buffer->encr_seg_cfg_size_start) + 2) =
  588. (coffset & 0xffff);
  589. *((uint32_t *)(buffer->seg_size)) = totallen_in;
  590. /* clear status */
  591. *((uint32_t *)(pce_dev->ce_dm.buffer.status)) = 0;
  592. _ce_setup_cipher_cmdrptrlist(pce_dev, creq);
  593. return 0;
  594. };
  595. static int _aead_complete(struct qce_device *pce_dev)
  596. {
  597. struct aead_request *areq;
  598. areq = (struct aead_request *) pce_dev->areq;
  599. if (areq->src != areq->dst) {
  600. qce_dma_unmap_sg(pce_dev->pdev, areq->dst, pce_dev->dst_nents,
  601. DMA_FROM_DEVICE);
  602. }
  603. qce_dma_unmap_sg(pce_dev->pdev, areq->src, pce_dev->src_nents,
  604. (areq->src == areq->dst) ? DMA_BIDIRECTIONAL :
  605. DMA_TO_DEVICE);
  606. qce_dma_unmap_sg(pce_dev->pdev, areq->assoc, pce_dev->assoc_nents,
  607. DMA_TO_DEVICE);
  608. /* check MAC */
  609. if (pce_dev->mode == QCE_MODE_CCM) {
  610. int32_t result = 0;
  611. result =
  612. (uint32_t)(*((uint32_t *)pce_dev->ce_dm.buffer.status));
  613. result &= (1 << CRYPTO_MAC_FAILED);
  614. result |= (pce_dev->ce_dm.chan_ce_in_status |
  615. pce_dev->ce_dm.chan_ce_out_status);
  616. if (pce_dev->ce_dm.chan_ce_in_status |
  617. pce_dev->ce_dm.chan_ce_out_status)
  618. result = -ENXIO;
  619. else if (result & (1 << CRYPTO_MAC_FAILED))
  620. result = -EBADMSG;
  621. pce_dev->qce_cb(areq, pce_dev->ce_dm.buffer.auth_result, NULL,
  622. result);
  623. }
  624. return 0;
  625. };
  626. static void _sha_complete(struct qce_device *pce_dev)
  627. {
  628. struct ahash_request *areq;
  629. areq = (struct ahash_request *) pce_dev->areq;
  630. qce_dma_unmap_sg(pce_dev->pdev, areq->src, pce_dev->src_nents,
  631. DMA_TO_DEVICE);
  632. pce_dev->qce_cb(areq, pce_dev->ce_dm.buffer.auth_result,
  633. pce_dev->ce_dm.buffer.auth_byte_count,
  634. pce_dev->ce_dm.chan_ce_in_status);
  635. };
  636. static int _ablk_cipher_complete(struct qce_device *pce_dev)
  637. {
  638. struct ablkcipher_request *areq;
  639. areq = (struct ablkcipher_request *) pce_dev->areq;
  640. if (areq->src != areq->dst) {
  641. qce_dma_unmap_sg(pce_dev->pdev, areq->dst,
  642. pce_dev->dst_nents, DMA_FROM_DEVICE);
  643. }
  644. qce_dma_unmap_sg(pce_dev->pdev, areq->src, pce_dev->src_nents,
  645. (areq->src == areq->dst) ? DMA_BIDIRECTIONAL :
  646. DMA_TO_DEVICE);
  647. if (pce_dev->mode == QCE_MODE_ECB) {
  648. pce_dev->qce_cb(areq, NULL, NULL,
  649. pce_dev->ce_dm.chan_ce_in_status |
  650. pce_dev->ce_dm.chan_ce_out_status);
  651. } else {
  652. pce_dev->qce_cb(areq, NULL, pce_dev->ce_dm.buffer.encr_cntr_iv,
  653. pce_dev->ce_dm.chan_ce_in_status |
  654. pce_dev->ce_dm.chan_ce_out_status);
  655. }
  656. return 0;
  657. };
  658. static int _ablk_cipher_use_pmem_complete(struct qce_device *pce_dev)
  659. {
  660. struct ablkcipher_request *areq;
  661. areq = (struct ablkcipher_request *) pce_dev->areq;
  662. if (pce_dev->mode == QCE_MODE_ECB) {
  663. pce_dev->qce_cb(areq, NULL, NULL,
  664. pce_dev->ce_dm.chan_ce_in_status |
  665. pce_dev->ce_dm.chan_ce_out_status);
  666. } else {
  667. pce_dev->qce_cb(areq, NULL, pce_dev->ce_dm.buffer.encr_cntr_iv,
  668. pce_dev->ce_dm.chan_ce_in_status |
  669. pce_dev->ce_dm.chan_ce_out_status);
  670. }
  671. return 0;
  672. };
  673. static int qce_split_and_insert_dm_desc(struct dmov_desc *pdesc,
  674. unsigned int plen, unsigned int paddr, int *index)
  675. {
  676. while (plen > QCE_FIFO_SIZE) {
  677. pdesc->len = QCE_FIFO_SIZE;
  678. if (paddr > 0) {
  679. pdesc->addr = paddr;
  680. paddr += QCE_FIFO_SIZE;
  681. }
  682. plen -= pdesc->len;
  683. if (plen > 0) {
  684. *index = (*index) + 1;
  685. if ((*index) >= QCE_MAX_NUM_DESC)
  686. return -ENOMEM;
  687. pdesc++;
  688. }
  689. }
  690. if ((plen > 0) && (plen <= QCE_FIFO_SIZE)) {
  691. pdesc->len = plen;
  692. if (paddr > 0)
  693. pdesc->addr = paddr;
  694. }
  695. return 0;
  696. }
  697. static int _chain_sg_buffer_in(struct qce_device *pce_dev,
  698. struct scatterlist *sg, unsigned int nbytes)
  699. {
  700. unsigned int len;
  701. unsigned int dlen;
  702. struct dmov_desc *pdesc;
  703. pdesc = pce_dev->ce_dm.ce_in_src_desc +
  704. pce_dev->ce_dm.ce_in_src_desc_index;
  705. /*
  706. * Two consective chunks may be handled by the old
  707. * buffer descriptor.
  708. */
  709. while (nbytes > 0) {
  710. len = min(nbytes, sg_dma_len(sg));
  711. dlen = pdesc->len & ADM_DESC_LENGTH_MASK;
  712. nbytes -= len;
  713. if (dlen == 0) {
  714. pdesc->addr = sg_dma_address(sg);
  715. pdesc->len = len;
  716. if (pdesc->len > QCE_FIFO_SIZE)
  717. qce_split_and_insert_dm_desc(pdesc, pdesc->len,
  718. sg_dma_address(sg),
  719. &pce_dev->ce_dm.ce_in_src_desc_index);
  720. } else if (sg_dma_address(sg) == (pdesc->addr + dlen)) {
  721. pdesc->len = dlen + len;
  722. if (pdesc->len > QCE_FIFO_SIZE)
  723. qce_split_and_insert_dm_desc(pdesc, pdesc->len,
  724. pdesc->addr,
  725. &pce_dev->ce_dm.ce_in_src_desc_index);
  726. } else {
  727. pce_dev->ce_dm.ce_in_src_desc_index++;
  728. if (pce_dev->ce_dm.ce_in_src_desc_index >=
  729. QCE_MAX_NUM_DESC)
  730. return -ENOMEM;
  731. pdesc++;
  732. pdesc->len = len;
  733. pdesc->addr = sg_dma_address(sg);
  734. if (pdesc->len > QCE_FIFO_SIZE)
  735. qce_split_and_insert_dm_desc(pdesc, pdesc->len,
  736. sg_dma_address(sg),
  737. &pce_dev->ce_dm.ce_in_src_desc_index);
  738. }
  739. if (nbytes > 0)
  740. sg = scatterwalk_sg_next(sg);
  741. }
  742. return 0;
  743. }
  744. static int _chain_pm_buffer_in(struct qce_device *pce_dev,
  745. unsigned int pmem, unsigned int nbytes)
  746. {
  747. unsigned int dlen;
  748. struct dmov_desc *pdesc;
  749. pdesc = pce_dev->ce_dm.ce_in_src_desc +
  750. pce_dev->ce_dm.ce_in_src_desc_index;
  751. dlen = pdesc->len & ADM_DESC_LENGTH_MASK;
  752. if (dlen == 0) {
  753. pdesc->addr = pmem;
  754. pdesc->len = nbytes;
  755. } else if (pmem == (pdesc->addr + dlen)) {
  756. pdesc->len = dlen + nbytes;
  757. } else {
  758. pce_dev->ce_dm.ce_in_src_desc_index++;
  759. if (pce_dev->ce_dm.ce_in_src_desc_index >=
  760. QCE_MAX_NUM_DESC)
  761. return -ENOMEM;
  762. pdesc++;
  763. pdesc->len = nbytes;
  764. pdesc->addr = pmem;
  765. }
  766. return 0;
  767. }
  768. static void _chain_buffer_in_init(struct qce_device *pce_dev)
  769. {
  770. struct dmov_desc *pdesc;
  771. pce_dev->ce_dm.ce_in_src_desc_index = 0;
  772. pce_dev->ce_dm.ce_in_dst_desc_index = 0;
  773. pdesc = pce_dev->ce_dm.ce_in_src_desc;
  774. pdesc->len = 0;
  775. }
  776. static void _ce_in_final(struct qce_device *pce_dev, unsigned total)
  777. {
  778. struct dmov_desc *pdesc;
  779. dmov_sg *pcmd;
  780. pdesc = pce_dev->ce_dm.ce_in_src_desc +
  781. pce_dev->ce_dm.ce_in_src_desc_index;
  782. pdesc->len |= ADM_DESC_LAST;
  783. pdesc = pce_dev->ce_dm.ce_in_dst_desc;
  784. if (total > QCE_FIFO_SIZE) {
  785. qce_split_and_insert_dm_desc(pdesc, total, 0,
  786. &pce_dev->ce_dm.ce_in_dst_desc_index);
  787. pdesc = pce_dev->ce_dm.ce_in_dst_desc +
  788. pce_dev->ce_dm.ce_in_dst_desc_index;
  789. pdesc->len |= ADM_DESC_LAST;
  790. } else
  791. pdesc->len = ADM_DESC_LAST | total;
  792. pcmd = (dmov_sg *) pce_dev->ce_dm.cmdlist.ce_data_in;
  793. pcmd->cmd |= CMD_LC;
  794. }
  795. #ifdef QCE_DEBUG
  796. static void _ce_in_dump(struct qce_device *pce_dev)
  797. {
  798. int i;
  799. struct dmov_desc *pdesc;
  800. dev_info(pce_dev->pdev, "_ce_in_dump: src\n");
  801. for (i = 0; i <= pce_dev->ce_dm.ce_in_src_desc_index; i++) {
  802. pdesc = pce_dev->ce_dm.ce_in_src_desc + i;
  803. dev_info(pce_dev->pdev, "%x , %x\n", pdesc->addr,
  804. pdesc->len);
  805. }
  806. dev_info(pce_dev->pdev, "_ce_in_dump: dst\n");
  807. for (i = 0; i <= pce_dev->ce_dm.ce_in_dst_desc_index; i++) {
  808. pdesc = pce_dev->ce_dm.ce_in_dst_desc + i;
  809. dev_info(pce_dev->pdev, "%x , %x\n", pdesc->addr,
  810. pdesc->len);
  811. }
  812. };
  813. static void _ce_out_dump(struct qce_device *pce_dev)
  814. {
  815. int i;
  816. struct dmov_desc *pdesc;
  817. dev_info(pce_dev->pdev, "_ce_out_dump: src\n");
  818. for (i = 0; i <= pce_dev->ce_dm.ce_out_src_desc_index; i++) {
  819. pdesc = pce_dev->ce_dm.ce_out_src_desc + i;
  820. dev_info(pce_dev->pdev, "%x , %x\n", pdesc->addr,
  821. pdesc->len);
  822. }
  823. dev_info(pce_dev->pdev, "_ce_out_dump: dst\n");
  824. for (i = 0; i <= pce_dev->ce_dm.ce_out_dst_desc_index; i++) {
  825. pdesc = pce_dev->ce_dm.ce_out_dst_desc + i;
  826. dev_info(pce_dev->pdev, "%x , %x\n", pdesc->addr,
  827. pdesc->len);
  828. }
  829. };
  830. #else
  831. static void _ce_in_dump(struct qce_device *pce_dev)
  832. {
  833. };
  834. static void _ce_out_dump(struct qce_device *pce_dev)
  835. {
  836. };
  837. #endif
  838. static int _chain_sg_buffer_out(struct qce_device *pce_dev,
  839. struct scatterlist *sg, unsigned int nbytes)
  840. {
  841. unsigned int len;
  842. unsigned int dlen;
  843. struct dmov_desc *pdesc;
  844. pdesc = pce_dev->ce_dm.ce_out_dst_desc +
  845. pce_dev->ce_dm.ce_out_dst_desc_index;
  846. /*
  847. * Two consective chunks may be handled by the old
  848. * buffer descriptor.
  849. */
  850. while (nbytes > 0) {
  851. len = min(nbytes, sg_dma_len(sg));
  852. dlen = pdesc->len & ADM_DESC_LENGTH_MASK;
  853. nbytes -= len;
  854. if (dlen == 0) {
  855. pdesc->addr = sg_dma_address(sg);
  856. pdesc->len = len;
  857. if (pdesc->len > QCE_FIFO_SIZE)
  858. qce_split_and_insert_dm_desc(pdesc, pdesc->len,
  859. sg_dma_address(sg),
  860. &pce_dev->ce_dm.ce_out_dst_desc_index);
  861. } else if (sg_dma_address(sg) == (pdesc->addr + dlen)) {
  862. pdesc->len = dlen + len;
  863. if (pdesc->len > QCE_FIFO_SIZE)
  864. qce_split_and_insert_dm_desc(pdesc, pdesc->len,
  865. pdesc->addr,
  866. &pce_dev->ce_dm.ce_out_dst_desc_index);
  867. } else {
  868. pce_dev->ce_dm.ce_out_dst_desc_index++;
  869. if (pce_dev->ce_dm.ce_out_dst_desc_index >=
  870. QCE_MAX_NUM_DESC)
  871. return -EIO;
  872. pdesc++;
  873. pdesc->len = len;
  874. pdesc->addr = sg_dma_address(sg);
  875. if (pdesc->len > QCE_FIFO_SIZE)
  876. qce_split_and_insert_dm_desc(pdesc, pdesc->len,
  877. sg_dma_address(sg),
  878. &pce_dev->ce_dm.ce_out_dst_desc_index);
  879. }
  880. if (nbytes > 0)
  881. sg = scatterwalk_sg_next(sg);
  882. }
  883. return 0;
  884. }
  885. static int _chain_pm_buffer_out(struct qce_device *pce_dev,
  886. unsigned int pmem, unsigned int nbytes)
  887. {
  888. unsigned int dlen;
  889. struct dmov_desc *pdesc;
  890. pdesc = pce_dev->ce_dm.ce_out_dst_desc +
  891. pce_dev->ce_dm.ce_out_dst_desc_index;
  892. dlen = pdesc->len & ADM_DESC_LENGTH_MASK;
  893. if (dlen == 0) {
  894. pdesc->addr = pmem;
  895. pdesc->len = nbytes;
  896. } else if (pmem == (pdesc->addr + dlen)) {
  897. pdesc->len = dlen + nbytes;
  898. } else {
  899. pce_dev->ce_dm.ce_out_dst_desc_index++;
  900. if (pce_dev->ce_dm.ce_out_dst_desc_index >= QCE_MAX_NUM_DESC)
  901. return -EIO;
  902. pdesc++;
  903. pdesc->len = nbytes;
  904. pdesc->addr = pmem;
  905. }
  906. return 0;
  907. };
  908. static void _chain_buffer_out_init(struct qce_device *pce_dev)
  909. {
  910. struct dmov_desc *pdesc;
  911. pce_dev->ce_dm.ce_out_dst_desc_index = 0;
  912. pce_dev->ce_dm.ce_out_src_desc_index = 0;
  913. pdesc = pce_dev->ce_dm.ce_out_dst_desc;
  914. pdesc->len = 0;
  915. };
  916. static void _ce_out_final(struct qce_device *pce_dev, unsigned total)
  917. {
  918. struct dmov_desc *pdesc;
  919. dmov_sg *pcmd;
  920. pdesc = pce_dev->ce_dm.ce_out_dst_desc +
  921. pce_dev->ce_dm.ce_out_dst_desc_index;
  922. pdesc->len |= ADM_DESC_LAST;
  923. pdesc = pce_dev->ce_dm.ce_out_src_desc +
  924. pce_dev->ce_dm.ce_out_src_desc_index;
  925. if (total > QCE_FIFO_SIZE) {
  926. qce_split_and_insert_dm_desc(pdesc, total, 0,
  927. &pce_dev->ce_dm.ce_out_src_desc_index);
  928. pdesc = pce_dev->ce_dm.ce_out_src_desc +
  929. pce_dev->ce_dm.ce_out_src_desc_index;
  930. pdesc->len |= ADM_DESC_LAST;
  931. } else
  932. pdesc->len = ADM_DESC_LAST | total;
  933. pcmd = (dmov_sg *) pce_dev->ce_dm.cmdlist.ce_data_out;
  934. pcmd->cmd |= CMD_LC;
  935. };
  936. static void _aead_ce_in_call_back(struct msm_dmov_cmd *cmd_ptr,
  937. unsigned int result, struct msm_dmov_errdata *err)
  938. {
  939. struct qce_device *pce_dev;
  940. pce_dev = (struct qce_device *) cmd_ptr->user;
  941. if (result != ADM_STATUS_OK) {
  942. dev_err(pce_dev->pdev, "Qualcomm ADM status error %x\n",
  943. result);
  944. pce_dev->ce_dm.chan_ce_in_status = -1;
  945. } else {
  946. pce_dev->ce_dm.chan_ce_in_status = 0;
  947. }
  948. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_COMP;
  949. if (pce_dev->ce_dm.chan_ce_out_state == QCE_CHAN_STATE_COMP) {
  950. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  951. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_IDLE;
  952. /* done */
  953. _aead_complete(pce_dev);
  954. }
  955. };
  956. static void _aead_ce_out_call_back(struct msm_dmov_cmd *cmd_ptr,
  957. unsigned int result, struct msm_dmov_errdata *err)
  958. {
  959. struct qce_device *pce_dev;
  960. pce_dev = (struct qce_device *) cmd_ptr->user;
  961. if (result != ADM_STATUS_OK) {
  962. dev_err(pce_dev->pdev, "Qualcomm ADM status error %x\n",
  963. result);
  964. pce_dev->ce_dm.chan_ce_out_status = -1;
  965. } else {
  966. pce_dev->ce_dm.chan_ce_out_status = 0;
  967. };
  968. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_COMP;
  969. if (pce_dev->ce_dm.chan_ce_in_state == QCE_CHAN_STATE_COMP) {
  970. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  971. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_IDLE;
  972. /* done */
  973. _aead_complete(pce_dev);
  974. }
  975. };
  976. static void _sha_ce_in_call_back(struct msm_dmov_cmd *cmd_ptr,
  977. unsigned int result, struct msm_dmov_errdata *err)
  978. {
  979. struct qce_device *pce_dev;
  980. pce_dev = (struct qce_device *) cmd_ptr->user;
  981. if (result != ADM_STATUS_OK) {
  982. dev_err(pce_dev->pdev, "Qualcomm ADM status error %x\n",
  983. result);
  984. pce_dev->ce_dm.chan_ce_in_status = -1;
  985. } else {
  986. pce_dev->ce_dm.chan_ce_in_status = 0;
  987. }
  988. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  989. _sha_complete(pce_dev);
  990. };
  991. static void _ablk_cipher_ce_in_call_back(struct msm_dmov_cmd *cmd_ptr,
  992. unsigned int result, struct msm_dmov_errdata *err)
  993. {
  994. struct qce_device *pce_dev;
  995. pce_dev = (struct qce_device *) cmd_ptr->user;
  996. if (result != ADM_STATUS_OK) {
  997. dev_err(pce_dev->pdev, "Qualcomm ADM status error %x\n",
  998. result);
  999. pce_dev->ce_dm.chan_ce_in_status = -1;
  1000. } else {
  1001. pce_dev->ce_dm.chan_ce_in_status = 0;
  1002. }
  1003. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_COMP;
  1004. if (pce_dev->ce_dm.chan_ce_out_state == QCE_CHAN_STATE_COMP) {
  1005. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  1006. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_IDLE;
  1007. /* done */
  1008. _ablk_cipher_complete(pce_dev);
  1009. }
  1010. };
  1011. static void _ablk_cipher_ce_out_call_back(struct msm_dmov_cmd *cmd_ptr,
  1012. unsigned int result, struct msm_dmov_errdata *err)
  1013. {
  1014. struct qce_device *pce_dev;
  1015. pce_dev = (struct qce_device *) cmd_ptr->user;
  1016. if (result != ADM_STATUS_OK) {
  1017. dev_err(pce_dev->pdev, "Qualcomm ADM status error %x\n",
  1018. result);
  1019. pce_dev->ce_dm.chan_ce_out_status = -1;
  1020. } else {
  1021. pce_dev->ce_dm.chan_ce_out_status = 0;
  1022. };
  1023. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_COMP;
  1024. if (pce_dev->ce_dm.chan_ce_in_state == QCE_CHAN_STATE_COMP) {
  1025. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  1026. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_IDLE;
  1027. /* done */
  1028. _ablk_cipher_complete(pce_dev);
  1029. }
  1030. };
  1031. static void _ablk_cipher_ce_in_call_back_pmem(struct msm_dmov_cmd *cmd_ptr,
  1032. unsigned int result, struct msm_dmov_errdata *err)
  1033. {
  1034. struct qce_device *pce_dev;
  1035. pce_dev = (struct qce_device *) cmd_ptr->user;
  1036. if (result != ADM_STATUS_OK) {
  1037. dev_err(pce_dev->pdev, "Qualcomm ADM status error %x\n",
  1038. result);
  1039. pce_dev->ce_dm.chan_ce_in_status = -1;
  1040. } else {
  1041. pce_dev->ce_dm.chan_ce_in_status = 0;
  1042. }
  1043. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_COMP;
  1044. if (pce_dev->ce_dm.chan_ce_out_state == QCE_CHAN_STATE_COMP) {
  1045. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  1046. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_IDLE;
  1047. /* done */
  1048. _ablk_cipher_use_pmem_complete(pce_dev);
  1049. }
  1050. };
  1051. static void _ablk_cipher_ce_out_call_back_pmem(struct msm_dmov_cmd *cmd_ptr,
  1052. unsigned int result, struct msm_dmov_errdata *err)
  1053. {
  1054. struct qce_device *pce_dev;
  1055. pce_dev = (struct qce_device *) cmd_ptr->user;
  1056. if (result != ADM_STATUS_OK) {
  1057. dev_err(pce_dev->pdev, "Qualcomm ADM status error %x\n",
  1058. result);
  1059. pce_dev->ce_dm.chan_ce_out_status = -1;
  1060. } else {
  1061. pce_dev->ce_dm.chan_ce_out_status = 0;
  1062. };
  1063. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_COMP;
  1064. if (pce_dev->ce_dm.chan_ce_in_state == QCE_CHAN_STATE_COMP) {
  1065. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  1066. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_IDLE;
  1067. /* done */
  1068. _ablk_cipher_use_pmem_complete(pce_dev);
  1069. }
  1070. };
  1071. static int qce_setup_cmd_buffers(struct qce_device *pce_dev,
  1072. unsigned char **pvaddr)
  1073. {
  1074. struct ce_reg_buffers *addr = (struct ce_reg_buffers *)(*pvaddr);
  1075. struct ce_reg_buffer_addr *buffer = &pce_dev->ce_dm.buffer;
  1076. /*
  1077. * Designate chunks of the allocated memory to various
  1078. * buffer pointers
  1079. */
  1080. buffer->reset_buf_64 = addr->reset_buf_64;
  1081. buffer->version = addr->version;
  1082. buffer->encr_seg_cfg_size_start = addr->encr_seg_cfg_size_start;
  1083. buffer->encr_key = addr->encr_key;
  1084. buffer->encr_xts_key = addr->encr_xts_key;
  1085. buffer->encr_xts_du_size = addr->encr_xts_du_size;
  1086. buffer->encr_cntr_iv = addr->encr_cntr_iv;
  1087. buffer->encr_mask = addr->encr_mask;
  1088. buffer->auth_seg_cfg_size_start = addr->auth_seg_cfg_size_start;
  1089. buffer->auth_key = addr->auth_key;
  1090. buffer->auth_iv = addr->auth_iv;
  1091. buffer->auth_result = addr->auth_result;
  1092. buffer->auth_nonce_info = addr->auth_nonce_info;
  1093. buffer->auth_byte_count = addr->auth_byte_count;
  1094. buffer->seg_size = addr->seg_size;
  1095. buffer->go_proc = addr->go_proc;
  1096. buffer->status = addr->status;
  1097. buffer->pad = addr->pad;
  1098. memset(buffer->reset_buf_64, 0, 64);
  1099. *((uint32_t *)buffer->encr_mask) = (uint32_t)(0xffffffff);
  1100. *((uint32_t *)buffer->go_proc) = (uint32_t)(1 << CRYPTO_GO);
  1101. *pvaddr += sizeof(struct ce_reg_buffers);
  1102. return 0;
  1103. }
  1104. static int _setup_cipher_cmdlists(struct qce_device *pce_dev,
  1105. unsigned char **pvaddr)
  1106. {
  1107. dmov_s *pscmd = (dmov_s *)(*pvaddr);
  1108. /*
  1109. * Designate chunks of the allocated memory to various
  1110. * command list pointers related to cipher operation
  1111. */
  1112. pce_dev->ce_dm.cmdlist.set_cipher_cfg = pscmd;
  1113. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1114. pscmd->dst = (unsigned) (CRYPTO_ENCR_SEG_CFG_REG +
  1115. pce_dev->phy_iobase);
  1116. pscmd->len = CRYPTO_REG_SIZE * 3;
  1117. pscmd->src =
  1118. GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_seg_cfg_size_start);
  1119. pscmd++;
  1120. pce_dev->ce_dm.cmdlist.set_cipher_aes_128_key = pscmd;
  1121. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1122. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1123. pscmd->dst = (unsigned) (CRYPTO_ENCR_KEY0_REG + pce_dev->phy_iobase);
  1124. pscmd->len = CRYPTO_REG_SIZE * 4;
  1125. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_key);
  1126. pscmd++;
  1127. pce_dev->ce_dm.cmdlist.set_cipher_aes_256_key = pscmd;
  1128. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1129. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1130. pscmd->dst = (unsigned) (CRYPTO_ENCR_KEY0_REG + pce_dev->phy_iobase);
  1131. pscmd->len = CRYPTO_REG_SIZE * 8;
  1132. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_key);
  1133. pscmd++;
  1134. pce_dev->ce_dm.cmdlist.set_cipher_des_key = pscmd;
  1135. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1136. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1137. pscmd->dst = (unsigned) (CRYPTO_ENCR_KEY0_REG + pce_dev->phy_iobase);
  1138. pscmd->len = CRYPTO_REG_SIZE * 2;
  1139. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_key);
  1140. pscmd++;
  1141. pce_dev->ce_dm.cmdlist.set_cipher_3des_key = pscmd;
  1142. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1143. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1144. pscmd->dst = (unsigned) (CRYPTO_ENCR_KEY0_REG + pce_dev->phy_iobase);
  1145. pscmd->len = CRYPTO_REG_SIZE * 6;
  1146. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_key);
  1147. pscmd++;
  1148. pce_dev->ce_dm.cmdlist.set_cipher_aes_128_xts_key = pscmd;
  1149. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1150. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1151. pscmd->dst = (unsigned) (CRYPTO_ENCR_XTS_KEY0_REG +
  1152. pce_dev->phy_iobase);
  1153. pscmd->len = CRYPTO_REG_SIZE * 4;
  1154. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_xts_key);
  1155. pscmd++;
  1156. pce_dev->ce_dm.cmdlist.set_cipher_aes_256_xts_key = pscmd;
  1157. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1158. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1159. pscmd->dst = (unsigned) (CRYPTO_ENCR_XTS_KEY0_REG +
  1160. pce_dev->phy_iobase);
  1161. pscmd->len = CRYPTO_REG_SIZE * 8;
  1162. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_xts_key);
  1163. pscmd++;
  1164. pce_dev->ce_dm.cmdlist.set_cipher_xts_du_size = pscmd;
  1165. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1166. pscmd->dst = (unsigned) (CRYPTO_ENCR_XTS_DU_SIZE_REG +
  1167. pce_dev->phy_iobase);
  1168. pscmd->len = CRYPTO_REG_SIZE * 4;
  1169. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_xts_du_size);
  1170. pscmd++;
  1171. pce_dev->ce_dm.cmdlist.set_cipher_aes_iv = pscmd;
  1172. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1173. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1174. pscmd->dst = (unsigned) (CRYPTO_CNTR0_IV0_REG + pce_dev->phy_iobase);
  1175. pscmd->len = CRYPTO_REG_SIZE * 4;
  1176. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_cntr_iv);
  1177. pscmd++;
  1178. pce_dev->ce_dm.cmdlist.set_cipher_des_iv = pscmd;
  1179. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1180. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1181. pscmd->dst = (unsigned) (CRYPTO_CNTR0_IV0_REG + pce_dev->phy_iobase);
  1182. pscmd->len = CRYPTO_REG_SIZE * 2;
  1183. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_cntr_iv);
  1184. pscmd++;
  1185. pce_dev->ce_dm.cmdlist.get_cipher_iv = pscmd;
  1186. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1187. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1188. pscmd->src = (unsigned) (CRYPTO_CNTR0_IV0_REG + pce_dev->phy_iobase);
  1189. pscmd->len = CRYPTO_REG_SIZE * 4;
  1190. pscmd->dst = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_cntr_iv);
  1191. pscmd++;
  1192. pce_dev->ce_dm.cmdlist.set_cipher_mask = pscmd;
  1193. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1194. pscmd->dst = (unsigned) (CRYPTO_CNTR_MASK_REG + pce_dev->phy_iobase);
  1195. pscmd->len = CRYPTO_REG_SIZE;
  1196. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.encr_mask);
  1197. pscmd++;
  1198. /* RESET CIPHER AND AUTH REGISTERS COMMAND LISTS*/
  1199. pce_dev->ce_dm.cmdlist.reset_cipher_key = pscmd;
  1200. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1201. pscmd->dst = (unsigned) (CRYPTO_ENCR_KEY0_REG + pce_dev->phy_iobase);
  1202. pscmd->len = CRYPTO_REG_SIZE * 8;
  1203. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.reset_buf_64);
  1204. pscmd++;
  1205. pce_dev->ce_dm.cmdlist.reset_cipher_xts_key = pscmd;
  1206. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1207. pscmd->dst = (unsigned) (CRYPTO_ENCR_XTS_KEY0_REG +
  1208. pce_dev->phy_iobase);
  1209. pscmd->len = CRYPTO_REG_SIZE * 8;
  1210. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.reset_buf_64);
  1211. pscmd++;
  1212. pce_dev->ce_dm.cmdlist.reset_cipher_iv = pscmd;
  1213. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1214. pscmd->dst = (unsigned) (CRYPTO_CNTR0_IV0_REG + pce_dev->phy_iobase);
  1215. pscmd->len = CRYPTO_REG_SIZE * 4;
  1216. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.reset_buf_64);
  1217. pscmd++;
  1218. pce_dev->ce_dm.cmdlist.reset_cipher_cfg = pscmd;
  1219. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1220. pscmd->dst = (unsigned) (CRYPTO_ENCR_SEG_CFG_REG + pce_dev->phy_iobase);
  1221. pscmd->len = CRYPTO_REG_SIZE;
  1222. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.reset_buf_64);
  1223. pscmd++;
  1224. *pvaddr = (unsigned char *) pscmd;
  1225. return 0;
  1226. }
  1227. static int _setup_auth_cmdlists(struct qce_device *pce_dev,
  1228. unsigned char **pvaddr)
  1229. {
  1230. dmov_s *pscmd = (dmov_s *)(*pvaddr);
  1231. /*
  1232. * Designate chunks of the allocated memory to various
  1233. * command list pointers related to authentication operation
  1234. */
  1235. pce_dev->ce_dm.cmdlist.set_auth_cfg = pscmd;
  1236. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1237. pscmd->dst = (unsigned) (CRYPTO_AUTH_SEG_CFG_REG + pce_dev->phy_iobase);
  1238. pscmd->len = CRYPTO_REG_SIZE * 3;
  1239. pscmd->src =
  1240. GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_seg_cfg_size_start);
  1241. pscmd++;
  1242. pce_dev->ce_dm.cmdlist.set_auth_key_128 = pscmd;
  1243. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1244. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1245. pscmd->dst = (unsigned) (CRYPTO_AUTH_KEY0_REG + pce_dev->phy_iobase);
  1246. pscmd->len = CRYPTO_REG_SIZE * 4;
  1247. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_key);
  1248. pscmd++;
  1249. pce_dev->ce_dm.cmdlist.set_auth_key_256 = pscmd;
  1250. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1251. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1252. pscmd->dst = (unsigned) (CRYPTO_AUTH_KEY0_REG + pce_dev->phy_iobase);
  1253. pscmd->len = CRYPTO_REG_SIZE * 8;
  1254. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_key);
  1255. pscmd++;
  1256. pce_dev->ce_dm.cmdlist.set_auth_key_512 = pscmd;
  1257. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1258. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1259. pscmd->dst = (unsigned) (CRYPTO_AUTH_KEY0_REG + pce_dev->phy_iobase);
  1260. pscmd->len = CRYPTO_REG_SIZE * 16;
  1261. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_key);
  1262. pscmd++;
  1263. pce_dev->ce_dm.cmdlist.set_auth_iv_16 = pscmd;
  1264. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1265. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1266. pscmd->dst = (unsigned) (CRYPTO_AUTH_IV0_REG + pce_dev->phy_iobase);
  1267. pscmd->len = CRYPTO_REG_SIZE * 4;
  1268. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_iv);
  1269. pscmd++;
  1270. pce_dev->ce_dm.cmdlist.get_auth_result_16 = pscmd;
  1271. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1272. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1273. pscmd->src = (unsigned) (CRYPTO_AUTH_IV0_REG + pce_dev->phy_iobase);
  1274. pscmd->len = CRYPTO_REG_SIZE * 4;
  1275. pscmd->dst = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_result);
  1276. pscmd++;
  1277. pce_dev->ce_dm.cmdlist.set_auth_iv_20 = pscmd;
  1278. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1279. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1280. pscmd->dst = (unsigned) (CRYPTO_AUTH_IV0_REG + pce_dev->phy_iobase);
  1281. pscmd->len = CRYPTO_REG_SIZE * 5;
  1282. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_iv);
  1283. pscmd++;
  1284. pce_dev->ce_dm.cmdlist.get_auth_result_20 = pscmd;
  1285. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1286. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1287. pscmd->src = (unsigned) (CRYPTO_AUTH_IV0_REG + pce_dev->phy_iobase);
  1288. pscmd->len = CRYPTO_REG_SIZE * 5;
  1289. pscmd->dst = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_result);
  1290. pscmd++;
  1291. pce_dev->ce_dm.cmdlist.set_auth_iv_32 = pscmd;
  1292. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1293. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1294. pscmd->dst = (unsigned) (CRYPTO_AUTH_IV0_REG + pce_dev->phy_iobase);
  1295. pscmd->len = CRYPTO_REG_SIZE * 8;
  1296. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_iv);
  1297. pscmd++;
  1298. pce_dev->ce_dm.cmdlist.get_auth_result_32 = pscmd;
  1299. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1300. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1301. pscmd->src = (unsigned) (CRYPTO_AUTH_IV0_REG + pce_dev->phy_iobase);
  1302. pscmd->len = CRYPTO_REG_SIZE * 8;
  1303. pscmd->dst = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_result);
  1304. pscmd++;
  1305. pce_dev->ce_dm.cmdlist.set_auth_byte_count = pscmd;
  1306. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1307. pscmd->dst = (unsigned) (CRYPTO_AUTH_BYTECNT0_REG +
  1308. pce_dev->phy_iobase);
  1309. pscmd->len = CRYPTO_REG_SIZE * 4;
  1310. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_byte_count);
  1311. pscmd++;
  1312. pce_dev->ce_dm.cmdlist.get_auth_byte_count = pscmd;
  1313. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1314. pscmd->src = (unsigned) (CRYPTO_AUTH_BYTECNT0_REG +
  1315. pce_dev->phy_iobase);
  1316. pscmd->len = CRYPTO_REG_SIZE * 4;
  1317. pscmd->dst = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_byte_count);
  1318. pscmd++;
  1319. pce_dev->ce_dm.cmdlist.set_auth_nonce_info = pscmd;
  1320. pscmd->cmd = CMD_LC | CMD_SRC_SWAP_BYTES |
  1321. CMD_SRC_SWAP_SHORTS | CMD_MODE_SINGLE;
  1322. pscmd->dst = (unsigned) (CRYPTO_AUTH_INFO_NONCE0_REG +
  1323. pce_dev->phy_iobase);
  1324. pscmd->len = CRYPTO_REG_SIZE * 4;
  1325. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.auth_nonce_info);
  1326. pscmd++;
  1327. /* RESET CIPHER AND AUTH REGISTERS COMMAND LISTS*/
  1328. pce_dev->ce_dm.cmdlist.reset_auth_key = pscmd;
  1329. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1330. pscmd->dst = (unsigned) (CRYPTO_AUTH_KEY0_REG + pce_dev->phy_iobase);
  1331. pscmd->len = CRYPTO_REG_SIZE * 16;
  1332. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.reset_buf_64);
  1333. pscmd++;
  1334. pce_dev->ce_dm.cmdlist.reset_auth_iv = pscmd;
  1335. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1336. pscmd->dst = (unsigned) (CRYPTO_AUTH_IV0_REG + pce_dev->phy_iobase);
  1337. pscmd->len = CRYPTO_REG_SIZE * 16;
  1338. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.reset_buf_64);
  1339. pscmd++;
  1340. pce_dev->ce_dm.cmdlist.reset_auth_cfg = pscmd;
  1341. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1342. pscmd->dst = (unsigned) (CRYPTO_AUTH_SEG_CFG_REG + pce_dev->phy_iobase);
  1343. pscmd->len = CRYPTO_REG_SIZE;
  1344. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.reset_buf_64);
  1345. pscmd++;
  1346. pce_dev->ce_dm.cmdlist.reset_auth_byte_count = pscmd;
  1347. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1348. pscmd->dst = (unsigned) (CRYPTO_AUTH_BYTECNT0_REG +
  1349. pce_dev->phy_iobase);
  1350. pscmd->len = CRYPTO_REG_SIZE * 4;
  1351. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.reset_buf_64);
  1352. pscmd++;
  1353. /* WAIT UNTIL MAC OP IS DONE*/
  1354. pce_dev->ce_dm.cmdlist.get_status_wait = pscmd;
  1355. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1356. pscmd->src = (unsigned) (CRYPTO_STATUS_REG + pce_dev->phy_iobase);
  1357. pscmd->len = CRYPTO_REG_SIZE;
  1358. pscmd->dst = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.status);
  1359. pscmd++;
  1360. *pvaddr = (unsigned char *) pscmd;
  1361. return 0;
  1362. }
  1363. static int qce_setup_cmdlists(struct qce_device *pce_dev,
  1364. unsigned char **pvaddr)
  1365. {
  1366. dmov_sg *pcmd;
  1367. dmov_s *pscmd;
  1368. unsigned char *vaddr = *pvaddr;
  1369. struct dmov_desc *pdesc;
  1370. int i = 0;
  1371. /*
  1372. * Designate chunks of the allocated memory to various
  1373. * command list pointers related to operation define
  1374. * in ce_cmdlists structure.
  1375. */
  1376. vaddr = (unsigned char *) ALIGN(((unsigned int)vaddr), 16);
  1377. *pvaddr = (unsigned char *) vaddr;
  1378. _setup_cipher_cmdlists(pce_dev, pvaddr);
  1379. _setup_auth_cmdlists(pce_dev, pvaddr);
  1380. pscmd = (dmov_s *)(*pvaddr);
  1381. /* GET HW VERSION COMMAND LIST */
  1382. pce_dev->ce_dm.cmdlist.get_hw_version = pscmd;
  1383. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE | CMD_OCB;
  1384. pscmd->src = (unsigned) (CRYPTO_VERSION_REG + pce_dev->phy_iobase);
  1385. pscmd->len = CRYPTO_REG_SIZE;
  1386. pscmd->dst = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.version);
  1387. pscmd++;
  1388. /* SET SEG SIZE REGISTER LIST */
  1389. pce_dev->ce_dm.cmdlist.set_seg_size = pscmd;
  1390. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1391. pscmd->dst = (unsigned) (CRYPTO_SEG_SIZE_REG + pce_dev->phy_iobase);
  1392. pscmd->len = CRYPTO_REG_SIZE;
  1393. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.seg_size);
  1394. pscmd++;
  1395. /* Get status and OCU COMMAND LIST */
  1396. pce_dev->ce_dm.cmdlist.get_status_ocu = pscmd;
  1397. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE | CMD_OCU;
  1398. pscmd->src = (unsigned) (CRYPTO_STATUS_REG + pce_dev->phy_iobase);
  1399. pscmd->len = CRYPTO_REG_SIZE;
  1400. pscmd->dst = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.status);
  1401. pscmd++;
  1402. /* CLEAR STATUS and OCU COMMAND LIST */
  1403. pce_dev->ce_dm.cmdlist.clear_status = pscmd;
  1404. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE | CMD_OCU;
  1405. pscmd->dst = (unsigned) (CRYPTO_STATUS_REG + pce_dev->phy_iobase);
  1406. pscmd->len = CRYPTO_REG_SIZE;
  1407. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.status);
  1408. pscmd++;
  1409. /* CLEAR STATUS and OCB COMMAND LIST */
  1410. pce_dev->ce_dm.cmdlist.clear_status_ocb = pscmd;
  1411. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE | CMD_OCB;
  1412. pscmd->dst = (unsigned) (CRYPTO_STATUS_REG + pce_dev->phy_iobase);
  1413. pscmd->len = CRYPTO_REG_SIZE;
  1414. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.status);
  1415. pscmd++;
  1416. /* SET GO_PROC REGISTERS COMMAND LIST */
  1417. pce_dev->ce_dm.cmdlist.set_go_proc = pscmd;
  1418. pscmd->cmd = CMD_LC | CMD_MODE_SINGLE;
  1419. pscmd->dst = (unsigned) (CRYPTO_GOPROC_REG + pce_dev->phy_iobase);
  1420. pscmd->len = CRYPTO_REG_SIZE;
  1421. pscmd->src = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.go_proc);
  1422. pscmd++;
  1423. pcmd = (dmov_sg *)pscmd;
  1424. pce_dev->ce_dm.cmdlist.ce_data_in = pcmd;
  1425. /* swap byte and half word , dst crci , scatter gather */
  1426. pcmd->cmd = CMD_DST_SWAP_BYTES | CMD_DST_SWAP_SHORTS |
  1427. CMD_DST_CRCI(pce_dev->ce_dm.crci_in) | CMD_MODE_SG;
  1428. pdesc = pce_dev->ce_dm.ce_in_src_desc;
  1429. pdesc->addr = 0; /* to be filled in each operation */
  1430. pdesc->len = 0; /* to be filled in each operation */
  1431. pdesc = pce_dev->ce_dm.ce_in_dst_desc;
  1432. for (i = 0; i < QCE_MAX_NUM_DESC; i++) {
  1433. pdesc->addr = (CRYPTO_DATA_SHADOW0 + pce_dev->phy_iobase);
  1434. pdesc->len = 0; /* to be filled in each operation */
  1435. pdesc++;
  1436. }
  1437. pcmd->src_dscr = GET_PHYS_ADDR(pce_dev->ce_dm.ce_in_src_desc);
  1438. pcmd->dst_dscr = GET_PHYS_ADDR(pce_dev->ce_dm.ce_in_dst_desc);
  1439. pcmd->_reserved = LI_SG_CMD | SRC_INDEX_SG_CMD(0) |
  1440. DST_INDEX_SG_CMD(0);
  1441. pcmd++;
  1442. pce_dev->ce_dm.cmdlist.ce_data_out = pcmd;
  1443. /* swap byte, half word, source crci, scatter gather */
  1444. pcmd->cmd = CMD_SRC_SWAP_BYTES | CMD_SRC_SWAP_SHORTS |
  1445. CMD_SRC_CRCI(pce_dev->ce_dm.crci_out) | CMD_MODE_SG;
  1446. pdesc = pce_dev->ce_dm.ce_out_src_desc;
  1447. for (i = 0; i < QCE_MAX_NUM_DESC; i++) {
  1448. pdesc->addr = (CRYPTO_DATA_SHADOW0 + pce_dev->phy_iobase);
  1449. pdesc->len = 0; /* to be filled in each operation */
  1450. pdesc++;
  1451. }
  1452. pdesc = pce_dev->ce_dm.ce_out_dst_desc;
  1453. pdesc->addr = 0; /* to be filled in each operation */
  1454. pdesc->len = 0; /* to be filled in each operation */
  1455. pcmd->src_dscr = GET_PHYS_ADDR(pce_dev->ce_dm.ce_out_src_desc);
  1456. pcmd->dst_dscr = GET_PHYS_ADDR(pce_dev->ce_dm.ce_out_dst_desc);
  1457. pcmd->_reserved = LI_SG_CMD | SRC_INDEX_SG_CMD(0) |
  1458. DST_INDEX_SG_CMD(0);
  1459. pcmd++;
  1460. *pvaddr = (unsigned char *) pcmd;
  1461. return 0;
  1462. }
  1463. static int _setup_cipher_cmdptrlists(struct qce_device *pce_dev,
  1464. unsigned char **pvaddr)
  1465. {
  1466. uint32_t * cmd_ptr_vaddr = (uint32_t *)(*pvaddr);
  1467. struct ce_cmdlists *cmdlist = &pce_dev->ce_dm.cmdlist;
  1468. struct ce_cmdptrlists_ops *cmdptrlist = &pce_dev->ce_dm.cmdptrlist;
  1469. /*
  1470. * Designate chunks of the allocated memory to various
  1471. * command list pointers related to cipher operations defined
  1472. * in ce_cmdptrlists_ops structure.
  1473. */
  1474. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1475. cmdptrlist->cipher_aes_128_cbc_ctr = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1476. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1477. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1478. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1479. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_128_key);
  1480. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_iv);
  1481. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1482. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_mask);
  1483. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1484. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1485. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1486. cmdptrlist->cipher_aes_256_cbc_ctr = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1487. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1488. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1489. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1490. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_256_key);
  1491. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_iv);
  1492. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1493. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_mask);
  1494. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1495. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1496. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1497. cmdptrlist->cipher_aes_128_ecb = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1498. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1499. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1500. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1501. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_128_key);
  1502. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1503. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_mask);
  1504. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1505. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1506. cmd_ptr_vaddr = (uint32_t *)ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1507. cmdptrlist->cipher_aes_256_ecb = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1508. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1509. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1510. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1511. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_256_key);
  1512. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1513. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_mask);
  1514. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1515. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1516. cmd_ptr_vaddr = (uint32_t *)ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1517. cmdptrlist->cipher_aes_128_xts = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1518. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1519. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1520. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1521. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_128_key);
  1522. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_128_xts_key);
  1523. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_iv);
  1524. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1525. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_xts_du_size);
  1526. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_mask);
  1527. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1528. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1529. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1530. cmdptrlist->cipher_aes_256_xts = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1531. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1532. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1533. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1534. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_256_key);
  1535. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_256_xts_key);
  1536. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_iv);
  1537. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1538. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_xts_du_size);
  1539. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_mask);
  1540. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1541. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1542. cmd_ptr_vaddr = (uint32_t *)ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1543. cmdptrlist->cipher_des_cbc = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1544. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1545. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1546. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1547. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_des_key);
  1548. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_des_iv);
  1549. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1550. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1551. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1552. cmd_ptr_vaddr = (uint32_t *)ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1553. cmdptrlist->cipher_des_ecb = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1554. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1555. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1556. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1557. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_des_key);
  1558. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1559. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1560. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1561. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1562. cmdptrlist->cipher_3des_cbc = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1563. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1564. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1565. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1566. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_3des_key);
  1567. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_des_iv);
  1568. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1569. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1570. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1571. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1572. cmdptrlist->cipher_3des_ecb = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1573. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1574. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1575. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1576. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_3des_key);
  1577. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_cfg);
  1578. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1579. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1580. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1581. cmdptrlist->cipher_ce_out = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1582. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_out);
  1583. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1584. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1585. cmdptrlist->cipher_ce_out_get_iv = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1586. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_out);
  1587. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_cipher_iv);
  1588. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1589. *pvaddr = (unsigned char *) cmd_ptr_vaddr;
  1590. return 0;
  1591. }
  1592. static int _setup_auth_cmdptrlists(struct qce_device *pce_dev,
  1593. unsigned char **pvaddr)
  1594. {
  1595. uint32_t * cmd_ptr_vaddr = (uint32_t *)(*pvaddr);
  1596. struct ce_cmdlists *cmdlist = &pce_dev->ce_dm.cmdlist;
  1597. struct ce_cmdptrlists_ops *cmdptrlist = &pce_dev->ce_dm.cmdptrlist;
  1598. /*
  1599. * Designate chunks of the allocated memory to various
  1600. * command list pointers related to authentication operations
  1601. * defined in ce_cmdptrlists_ops structure.
  1602. */
  1603. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1604. cmdptrlist->auth_sha1 = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1605. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1606. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1607. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_cipher_cfg);
  1608. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_cfg);
  1609. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_iv_20);
  1610. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_byte_count);
  1611. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1612. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_in);
  1613. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1614. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1615. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1616. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1617. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_byte_count);
  1618. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_result_20);
  1619. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1620. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1621. cmdptrlist->auth_sha256 = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1622. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1623. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1624. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_cipher_cfg);
  1625. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_cfg);
  1626. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_iv_32);
  1627. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_byte_count);
  1628. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1629. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_in);
  1630. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1631. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1632. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1633. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1634. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_byte_count);
  1635. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_result_32);
  1636. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1637. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1638. cmdptrlist->auth_sha1_hmac = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1639. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1640. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1641. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_cipher_cfg);
  1642. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_key_512);
  1643. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_cfg);
  1644. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_iv_20);
  1645. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_byte_count);
  1646. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1647. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_in);
  1648. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1649. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1650. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1651. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1652. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_byte_count);
  1653. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_result_20);
  1654. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1655. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1656. cmdptrlist->auth_sha256_hmac = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1657. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1658. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1659. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_cipher_cfg);
  1660. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_key_512);
  1661. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_cfg);
  1662. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_iv_32);
  1663. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_byte_count);
  1664. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1665. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_in);
  1666. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1667. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1668. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1669. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1670. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_byte_count);
  1671. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_result_32);
  1672. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1673. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1674. cmdptrlist->auth_aes_128_cmac = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1675. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1676. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1677. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_cipher_cfg);
  1678. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_iv);
  1679. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_key);
  1680. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_byte_count);
  1681. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_key_128);
  1682. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_cfg);
  1683. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1684. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_in);
  1685. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1686. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1687. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_byte_count);
  1688. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_result_16);
  1689. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1690. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1691. cmdptrlist->auth_aes_256_cmac = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1692. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1693. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1694. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_cipher_cfg);
  1695. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_iv);
  1696. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_key);
  1697. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_byte_count);
  1698. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_key_256);
  1699. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_cfg);
  1700. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1701. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_in);
  1702. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1703. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1704. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_byte_count);
  1705. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_auth_result_16);
  1706. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1707. *pvaddr = (unsigned char *) cmd_ptr_vaddr;
  1708. return 0;
  1709. }
  1710. static int _setup_aead_cmdptrlists(struct qce_device *pce_dev,
  1711. unsigned char **pvaddr)
  1712. {
  1713. uint32_t * cmd_ptr_vaddr = (uint32_t *)(*pvaddr);
  1714. struct ce_cmdlists *cmdlist = &pce_dev->ce_dm.cmdlist;
  1715. struct ce_cmdptrlists_ops *cmdptrlist = &pce_dev->ce_dm.cmdptrlist;
  1716. /*
  1717. * Designate chunks of the allocated memory to various
  1718. * command list pointers related to aead operations
  1719. * defined in ce_cmdptrlists_ops structure.
  1720. */
  1721. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1722. cmdptrlist->aead_aes_128_ccm = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1723. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1724. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1725. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_iv);
  1726. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_key);
  1727. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_byte_count);
  1728. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_key_128);
  1729. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_nonce_info);
  1730. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_cfg);
  1731. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1732. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_128_key);
  1733. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_iv);
  1734. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_mask);
  1735. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1736. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1737. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1738. cmdptrlist->aead_aes_256_ccm = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1739. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status_ocb);
  1740. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_seg_size);
  1741. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_iv);
  1742. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_key);
  1743. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->reset_auth_byte_count);
  1744. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_key_256);
  1745. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_nonce_info);
  1746. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_auth_cfg);
  1747. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_cfg);
  1748. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_256_key);
  1749. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_aes_iv);
  1750. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_cipher_mask);
  1751. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->set_go_proc);
  1752. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->ce_data_in);
  1753. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1754. cmdptrlist->aead_ce_out = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1755. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->ce_data_out);
  1756. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1757. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_status_wait);
  1758. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1759. *pvaddr = (unsigned char *) cmd_ptr_vaddr;
  1760. return 0;
  1761. }
  1762. static int qce_setup_cmdptrlists(struct qce_device *pce_dev,
  1763. unsigned char **pvaddr)
  1764. {
  1765. uint32_t * cmd_ptr_vaddr = (uint32_t *)(*pvaddr);
  1766. struct ce_cmdlists *cmdlist = &pce_dev->ce_dm.cmdlist;
  1767. struct ce_cmdptrlists_ops *cmdptrlist = &pce_dev->ce_dm.cmdptrlist;
  1768. /*
  1769. * Designate chunks of the allocated memory to various
  1770. * command list pointers related to operations defined
  1771. * in ce_cmdptrlists_ops structure.
  1772. */
  1773. cmd_ptr_vaddr = (uint32_t *) ALIGN(((unsigned int) cmd_ptr_vaddr), 16);
  1774. cmdptrlist->probe_ce_hw = QCE_SET_CMD_PTR(cmd_ptr_vaddr);
  1775. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->get_hw_version);
  1776. *cmd_ptr_vaddr++ = QCE_SET_CMD_PTR(cmdlist->clear_status);
  1777. *cmd_ptr_vaddr++ = QCE_SET_LAST_CMD_PTR(cmdlist->get_status_ocu);
  1778. *pvaddr = (unsigned char *) cmd_ptr_vaddr;
  1779. _setup_cipher_cmdptrlists(pce_dev, pvaddr);
  1780. _setup_auth_cmdptrlists(pce_dev, pvaddr);
  1781. _setup_aead_cmdptrlists(pce_dev, pvaddr);
  1782. return 0;
  1783. }
  1784. static int qce_setup_ce_dm_data(struct qce_device *pce_dev)
  1785. {
  1786. unsigned char *vaddr;
  1787. /* 1. ce_in channel data xfer command src descriptors, 128 entries */
  1788. vaddr = pce_dev->coh_vmem;
  1789. vaddr = (unsigned char *) ALIGN(((unsigned int)vaddr), 16);
  1790. pce_dev->ce_dm.ce_in_src_desc = (struct dmov_desc *) vaddr;
  1791. vaddr = vaddr + (sizeof(struct dmov_desc) * QCE_MAX_NUM_DESC);
  1792. /* 2. ce_in channel data xfer command dst descriptors, 128 entries */
  1793. vaddr = (unsigned char *) ALIGN(((unsigned int)vaddr), 16);
  1794. pce_dev->ce_dm.ce_in_dst_desc = (struct dmov_desc *) vaddr;
  1795. vaddr = vaddr + (sizeof(struct dmov_desc) * QCE_MAX_NUM_DESC);
  1796. /* 3. ce_out channel data xfer command src descriptors, 128 entries */
  1797. vaddr = (unsigned char *) ALIGN(((unsigned int)vaddr), 16);
  1798. pce_dev->ce_dm.ce_out_src_desc = (struct dmov_desc *) vaddr;
  1799. vaddr = vaddr + (sizeof(struct dmov_desc) * QCE_MAX_NUM_DESC);
  1800. /* 4. ce_out channel data xfer command dst descriptors, 128 entries. */
  1801. vaddr = (unsigned char *) ALIGN(((unsigned int)vaddr), 16);
  1802. pce_dev->ce_dm.ce_out_dst_desc = (struct dmov_desc *) vaddr;
  1803. vaddr = vaddr + (sizeof(struct dmov_desc) * QCE_MAX_NUM_DESC);
  1804. qce_setup_cmd_buffers(pce_dev, &vaddr);
  1805. qce_setup_cmdlists(pce_dev, &vaddr);
  1806. qce_setup_cmdptrlists(pce_dev, &vaddr);
  1807. pce_dev->ce_dm.buffer.ignore_data = vaddr;
  1808. pce_dev->ce_dm.phy_ce_pad = GET_PHYS_ADDR(pce_dev->ce_dm.buffer.pad);
  1809. pce_dev->ce_dm.phy_ce_out_ignore =
  1810. GET_PHYS_ADDR(pce_dev->ce_dm.buffer.ignore_data);
  1811. pce_dev->ce_dm.chan_ce_in_cmd->user = (void *) pce_dev;
  1812. pce_dev->ce_dm.chan_ce_in_cmd->exec_func = NULL;
  1813. pce_dev->ce_dm.chan_ce_out_cmd->user = (void *) pce_dev;
  1814. pce_dev->ce_dm.chan_ce_out_cmd->exec_func = NULL;
  1815. return 0;
  1816. }
  1817. static int _qce_start_dma(struct qce_device *pce_dev, bool ce_in, bool ce_out)
  1818. {
  1819. if (ce_in)
  1820. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IN_PROG;
  1821. else
  1822. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_COMP;
  1823. if (ce_out)
  1824. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_IN_PROG;
  1825. else
  1826. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_COMP;
  1827. if (ce_in)
  1828. msm_dmov_enqueue_cmd(pce_dev->ce_dm.chan_ce_in,
  1829. pce_dev->ce_dm.chan_ce_in_cmd);
  1830. if (ce_out)
  1831. msm_dmov_enqueue_cmd(pce_dev->ce_dm.chan_ce_out,
  1832. pce_dev->ce_dm.chan_ce_out_cmd);
  1833. return 0;
  1834. };
  1835. int qce_aead_req(void *handle, struct qce_req *q_req)
  1836. {
  1837. struct qce_device *pce_dev = (struct qce_device *) handle;
  1838. struct aead_request *areq = (struct aead_request *) q_req->areq;
  1839. uint32_t authsize = q_req->authsize;
  1840. uint32_t totallen_in, totallen_out, out_len;
  1841. uint32_t pad_len_in, pad_len_out;
  1842. int rc = 0;
  1843. int ce_block_size;
  1844. ce_block_size = pce_dev->ce_dm.ce_block_size;
  1845. if (q_req->dir == QCE_ENCRYPT) {
  1846. uint32_t pad_mac_len_out;
  1847. q_req->cryptlen = areq->cryptlen;
  1848. totallen_in = q_req->cryptlen + areq->assoclen;
  1849. pad_len_in = ALIGN(totallen_in, ce_block_size) - totallen_in;
  1850. out_len = areq->cryptlen + authsize;
  1851. totallen_out = q_req->cryptlen + authsize + areq->assoclen;
  1852. pad_mac_len_out = ALIGN(authsize, ce_block_size) - authsize;
  1853. totallen_out += pad_mac_len_out;
  1854. pad_len_out = ALIGN(totallen_out, ce_block_size) -
  1855. totallen_out + pad_mac_len_out;
  1856. } else {
  1857. q_req->cryptlen = areq->cryptlen - authsize;
  1858. totallen_in = areq->cryptlen + areq->assoclen;
  1859. pad_len_in = ALIGN(totallen_in, ce_block_size) - totallen_in;
  1860. out_len = q_req->cryptlen;
  1861. totallen_out = totallen_in;
  1862. pad_len_out = ALIGN(totallen_out, ce_block_size) - totallen_out;
  1863. pad_len_out += authsize;
  1864. }
  1865. _chain_buffer_in_init(pce_dev);
  1866. _chain_buffer_out_init(pce_dev);
  1867. pce_dev->assoc_nents = 0;
  1868. pce_dev->src_nents = 0;
  1869. pce_dev->dst_nents = 0;
  1870. pce_dev->ivsize = q_req->ivsize;
  1871. pce_dev->authsize = q_req->authsize;
  1872. /* associated data input */
  1873. pce_dev->assoc_nents = count_sg(areq->assoc, areq->assoclen);
  1874. qce_dma_map_sg(pce_dev->pdev, areq->assoc, pce_dev->assoc_nents,
  1875. DMA_TO_DEVICE);
  1876. if (_chain_sg_buffer_in(pce_dev, areq->assoc, areq->assoclen) < 0) {
  1877. rc = -ENOMEM;
  1878. goto bad;
  1879. }
  1880. /* cipher input */
  1881. pce_dev->src_nents = count_sg(areq->src, areq->cryptlen);
  1882. qce_dma_map_sg(pce_dev->pdev, areq->src, pce_dev->src_nents,
  1883. (areq->src == areq->dst) ? DMA_BIDIRECTIONAL :
  1884. DMA_TO_DEVICE);
  1885. if (_chain_sg_buffer_in(pce_dev, areq->src, areq->cryptlen) < 0) {
  1886. rc = -ENOMEM;
  1887. goto bad;
  1888. }
  1889. /* pad data in */
  1890. if (pad_len_in) {
  1891. if (_chain_pm_buffer_in(pce_dev, pce_dev->ce_dm.phy_ce_pad,
  1892. pad_len_in) < 0) {
  1893. rc = -ENOMEM;
  1894. goto bad;
  1895. }
  1896. }
  1897. /* ignore associated data */
  1898. if (_chain_pm_buffer_out(pce_dev, pce_dev->ce_dm.phy_ce_out_ignore,
  1899. areq->assoclen) < 0) {
  1900. rc = -ENOMEM;
  1901. goto bad;
  1902. }
  1903. /* cipher + mac output for encryption */
  1904. if (areq->src != areq->dst) {
  1905. pce_dev->dst_nents = count_sg(areq->dst, out_len);
  1906. qce_dma_map_sg(pce_dev->pdev, areq->dst, pce_dev->dst_nents,
  1907. DMA_FROM_DEVICE);
  1908. };
  1909. if (_chain_sg_buffer_out(pce_dev, areq->dst, out_len) < 0) {
  1910. rc = -ENOMEM;
  1911. goto bad;
  1912. }
  1913. /* pad data out */
  1914. if (pad_len_out) {
  1915. if (_chain_pm_buffer_out(pce_dev, pce_dev->ce_dm.phy_ce_pad,
  1916. pad_len_out) < 0) {
  1917. rc = -ENOMEM;
  1918. goto bad;
  1919. }
  1920. }
  1921. /* finalize the ce_in and ce_out channels command lists */
  1922. _ce_in_final(pce_dev, ALIGN(totallen_in, ce_block_size));
  1923. _ce_out_final(pce_dev, ALIGN(totallen_out, ce_block_size));
  1924. /* set up crypto device */
  1925. rc = _ce_setup_cipher(pce_dev, q_req, totallen_in, areq->assoclen);
  1926. if (rc < 0)
  1927. goto bad;
  1928. /* setup for callback, and issue command to adm */
  1929. pce_dev->areq = q_req->areq;
  1930. pce_dev->qce_cb = q_req->qce_cb;
  1931. pce_dev->ce_dm.chan_ce_in_cmd->complete_func = _aead_ce_in_call_back;
  1932. pce_dev->ce_dm.chan_ce_out_cmd->complete_func = _aead_ce_out_call_back;
  1933. _ce_in_dump(pce_dev);
  1934. _ce_out_dump(pce_dev);
  1935. rc = _qce_start_dma(pce_dev, true, true);
  1936. if (rc == 0)
  1937. return 0;
  1938. bad:
  1939. if (pce_dev->assoc_nents) {
  1940. qce_dma_unmap_sg(pce_dev->pdev, areq->assoc,
  1941. pce_dev->assoc_nents, DMA_TO_DEVICE);
  1942. }
  1943. if (pce_dev->src_nents) {
  1944. qce_dma_unmap_sg(pce_dev->pdev, areq->src, pce_dev->src_nents,
  1945. (areq->src == areq->dst) ? DMA_BIDIRECTIONAL :
  1946. DMA_TO_DEVICE);
  1947. }
  1948. if (pce_dev->dst_nents) {
  1949. qce_dma_unmap_sg(pce_dev->pdev, areq->dst, pce_dev->dst_nents,
  1950. DMA_FROM_DEVICE);
  1951. }
  1952. return rc;
  1953. }
  1954. EXPORT_SYMBOL(qce_aead_req);
  1955. int qce_ablk_cipher_req(void *handle, struct qce_req *c_req)
  1956. {
  1957. int rc = 0;
  1958. struct qce_device *pce_dev = (struct qce_device *) handle;
  1959. struct ablkcipher_request *areq = (struct ablkcipher_request *)
  1960. c_req->areq;
  1961. uint32_t pad_len = ALIGN(areq->nbytes, pce_dev->ce_dm.ce_block_size)
  1962. - areq->nbytes;
  1963. _chain_buffer_in_init(pce_dev);
  1964. _chain_buffer_out_init(pce_dev);
  1965. pce_dev->src_nents = 0;
  1966. pce_dev->dst_nents = 0;
  1967. /* cipher input */
  1968. pce_dev->src_nents = count_sg(areq->src, areq->nbytes);
  1969. if (c_req->use_pmem != 1)
  1970. qce_dma_map_sg(pce_dev->pdev, areq->src, pce_dev->src_nents,
  1971. (areq->src == areq->dst) ? DMA_BIDIRECTIONAL :
  1972. DMA_TO_DEVICE);
  1973. else
  1974. dma_map_pmem_sg(&c_req->pmem->src[0], pce_dev->src_nents,
  1975. areq->src);
  1976. if (_chain_sg_buffer_in(pce_dev, areq->src, areq->nbytes) < 0) {
  1977. rc = -ENOMEM;
  1978. goto bad;
  1979. }
  1980. /* cipher output */
  1981. if (areq->src != areq->dst) {
  1982. pce_dev->dst_nents = count_sg(areq->dst, areq->nbytes);
  1983. if (c_req->use_pmem != 1)
  1984. qce_dma_map_sg(pce_dev->pdev, areq->dst,
  1985. pce_dev->dst_nents, DMA_FROM_DEVICE);
  1986. else
  1987. dma_map_pmem_sg(&c_req->pmem->dst[0],
  1988. pce_dev->dst_nents, areq->dst);
  1989. };
  1990. if (_chain_sg_buffer_out(pce_dev, areq->dst, areq->nbytes) < 0) {
  1991. rc = -ENOMEM;
  1992. goto bad;
  1993. }
  1994. /* pad data */
  1995. if (pad_len) {
  1996. if (_chain_pm_buffer_in(pce_dev, pce_dev->ce_dm.phy_ce_pad,
  1997. pad_len) < 0) {
  1998. rc = -ENOMEM;
  1999. goto bad;
  2000. }
  2001. if (_chain_pm_buffer_out(pce_dev, pce_dev->ce_dm.phy_ce_pad,
  2002. pad_len) < 0) {
  2003. rc = -ENOMEM;
  2004. goto bad;
  2005. }
  2006. }
  2007. /* finalize the ce_in and ce_out channels command lists */
  2008. _ce_in_final(pce_dev, areq->nbytes + pad_len);
  2009. _ce_out_final(pce_dev, areq->nbytes + pad_len);
  2010. _ce_in_dump(pce_dev);
  2011. _ce_out_dump(pce_dev);
  2012. /* set up crypto device */
  2013. rc = _ce_setup_cipher(pce_dev, c_req, areq->nbytes, 0);
  2014. if (rc < 0)
  2015. goto bad;
  2016. /* setup for callback, and issue command to adm */
  2017. pce_dev->areq = areq;
  2018. pce_dev->qce_cb = c_req->qce_cb;
  2019. if (c_req->use_pmem == 1) {
  2020. pce_dev->ce_dm.chan_ce_in_cmd->complete_func =
  2021. _ablk_cipher_ce_in_call_back_pmem;
  2022. pce_dev->ce_dm.chan_ce_out_cmd->complete_func =
  2023. _ablk_cipher_ce_out_call_back_pmem;
  2024. } else {
  2025. pce_dev->ce_dm.chan_ce_in_cmd->complete_func =
  2026. _ablk_cipher_ce_in_call_back;
  2027. pce_dev->ce_dm.chan_ce_out_cmd->complete_func =
  2028. _ablk_cipher_ce_out_call_back;
  2029. }
  2030. rc = _qce_start_dma(pce_dev, true, true);
  2031. if (rc == 0)
  2032. return 0;
  2033. bad:
  2034. if (c_req->use_pmem != 1) {
  2035. if (pce_dev->dst_nents) {
  2036. qce_dma_unmap_sg(pce_dev->pdev, areq->dst,
  2037. pce_dev->dst_nents, DMA_FROM_DEVICE);
  2038. }
  2039. if (pce_dev->src_nents) {
  2040. qce_dma_unmap_sg(pce_dev->pdev, areq->src,
  2041. pce_dev->src_nents,
  2042. (areq->src == areq->dst) ?
  2043. DMA_BIDIRECTIONAL :
  2044. DMA_TO_DEVICE);
  2045. }
  2046. }
  2047. return rc;
  2048. }
  2049. EXPORT_SYMBOL(qce_ablk_cipher_req);
  2050. int qce_process_sha_req(void *handle, struct qce_sha_req *sreq)
  2051. {
  2052. struct qce_device *pce_dev = (struct qce_device *) handle;
  2053. int rc;
  2054. uint32_t pad_len = ALIGN(sreq->size, pce_dev->ce_dm.ce_block_size) -
  2055. sreq->size;
  2056. struct ahash_request *areq = (struct ahash_request *)sreq->areq;
  2057. _chain_buffer_in_init(pce_dev);
  2058. pce_dev->src_nents = count_sg(sreq->src, sreq->size);
  2059. qce_dma_map_sg(pce_dev->pdev, sreq->src, pce_dev->src_nents,
  2060. DMA_TO_DEVICE);
  2061. if (_chain_sg_buffer_in(pce_dev, sreq->src, sreq->size) < 0) {
  2062. rc = -ENOMEM;
  2063. goto bad;
  2064. }
  2065. if (pad_len) {
  2066. if (_chain_pm_buffer_in(pce_dev, pce_dev->ce_dm.phy_ce_pad,
  2067. pad_len) < 0) {
  2068. rc = -ENOMEM;
  2069. goto bad;
  2070. }
  2071. }
  2072. _ce_in_final(pce_dev, sreq->size + pad_len);
  2073. _ce_in_dump(pce_dev);
  2074. rc = _ce_setup_hash(pce_dev, sreq);
  2075. if (rc < 0)
  2076. goto bad;
  2077. pce_dev->areq = areq;
  2078. pce_dev->qce_cb = sreq->qce_cb;
  2079. pce_dev->ce_dm.chan_ce_in_cmd->complete_func = _sha_ce_in_call_back;
  2080. rc = _qce_start_dma(pce_dev, true, false);
  2081. if (rc == 0)
  2082. return 0;
  2083. bad:
  2084. if (pce_dev->src_nents) {
  2085. qce_dma_unmap_sg(pce_dev->pdev, sreq->src,
  2086. pce_dev->src_nents, DMA_TO_DEVICE);
  2087. }
  2088. return rc;
  2089. }
  2090. EXPORT_SYMBOL(qce_process_sha_req);
  2091. int qce_enable_clk(void *handle)
  2092. {
  2093. return 0;
  2094. }
  2095. EXPORT_SYMBOL(qce_enable_clk);
  2096. int qce_disable_clk(void *handle)
  2097. {
  2098. return 0;
  2099. }
  2100. EXPORT_SYMBOL(qce_disable_clk);
  2101. /* crypto engine open function. */
  2102. void *qce_open(struct platform_device *pdev, int *rc)
  2103. {
  2104. struct qce_device *pce_dev;
  2105. struct resource *resource;
  2106. struct clk *ce_core_clk;
  2107. struct clk *ce_clk;
  2108. struct clk *ce_core_src_clk;
  2109. int ret = 0;
  2110. pce_dev = kzalloc(sizeof(struct qce_device), GFP_KERNEL);
  2111. if (!pce_dev) {
  2112. *rc = -ENOMEM;
  2113. dev_err(&pdev->dev, "Can not allocate memory\n");
  2114. return NULL;
  2115. }
  2116. pce_dev->pdev = &pdev->dev;
  2117. resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2118. if (!resource) {
  2119. *rc = -ENXIO;
  2120. dev_err(pce_dev->pdev, "Missing MEM resource\n");
  2121. goto err_pce_dev;
  2122. };
  2123. pce_dev->phy_iobase = resource->start;
  2124. pce_dev->iobase = ioremap_nocache(resource->start,
  2125. resource->end - resource->start + 1);
  2126. if (!pce_dev->iobase) {
  2127. *rc = -ENOMEM;
  2128. dev_err(pce_dev->pdev, "Can not map io memory\n");
  2129. goto err_pce_dev;
  2130. }
  2131. pce_dev->ce_dm.chan_ce_in_cmd = kzalloc(sizeof(struct msm_dmov_cmd),
  2132. GFP_KERNEL);
  2133. pce_dev->ce_dm.chan_ce_out_cmd = kzalloc(sizeof(struct msm_dmov_cmd),
  2134. GFP_KERNEL);
  2135. if (pce_dev->ce_dm.chan_ce_in_cmd == NULL ||
  2136. pce_dev->ce_dm.chan_ce_out_cmd == NULL) {
  2137. dev_err(pce_dev->pdev, "Can not allocate memory\n");
  2138. *rc = -ENOMEM;
  2139. goto err_dm_chan_cmd;
  2140. }
  2141. resource = platform_get_resource_byname(pdev, IORESOURCE_DMA,
  2142. "crypto_channels");
  2143. if (!resource) {
  2144. *rc = -ENXIO;
  2145. dev_err(pce_dev->pdev, "Missing DMA channel resource\n");
  2146. goto err_dm_chan_cmd;
  2147. };
  2148. pce_dev->ce_dm.chan_ce_in = resource->start;
  2149. pce_dev->ce_dm.chan_ce_out = resource->end;
  2150. resource = platform_get_resource_byname(pdev, IORESOURCE_DMA,
  2151. "crypto_crci_in");
  2152. if (!resource) {
  2153. *rc = -ENXIO;
  2154. dev_err(pce_dev->pdev, "Missing DMA crci in resource\n");
  2155. goto err_dm_chan_cmd;
  2156. };
  2157. pce_dev->ce_dm.crci_in = resource->start;
  2158. resource = platform_get_resource_byname(pdev, IORESOURCE_DMA,
  2159. "crypto_crci_out");
  2160. if (!resource) {
  2161. *rc = -ENXIO;
  2162. dev_err(pce_dev->pdev, "Missing DMA crci out resource\n");
  2163. goto err_dm_chan_cmd;
  2164. };
  2165. pce_dev->ce_dm.crci_out = resource->start;
  2166. pce_dev->memsize = 2 * PAGE_SIZE;
  2167. pce_dev->coh_vmem = dma_alloc_coherent(pce_dev->pdev,
  2168. pce_dev->memsize, &pce_dev->coh_pmem, GFP_KERNEL);
  2169. if (pce_dev->coh_vmem == NULL) {
  2170. *rc = -ENOMEM;
  2171. dev_err(pce_dev->pdev, "Can not allocate coherent memory.\n");
  2172. goto err;
  2173. }
  2174. /* Get CE3 src core clk. */
  2175. ce_core_src_clk = clk_get(pce_dev->pdev, "ce3_core_src_clk");
  2176. if (!IS_ERR(ce_core_src_clk)) {
  2177. pce_dev->ce_core_src_clk = ce_core_src_clk;
  2178. /* Set the core src clk @100Mhz */
  2179. ret = clk_set_rate(pce_dev->ce_core_src_clk, 100000000);
  2180. if (ret) {
  2181. clk_put(pce_dev->ce_core_src_clk);
  2182. goto err;
  2183. }
  2184. } else
  2185. pce_dev->ce_core_src_clk = NULL;
  2186. /* Get CE core clk */
  2187. ce_core_clk = clk_get(pce_dev->pdev, "core_clk");
  2188. if (IS_ERR(ce_core_clk)) {
  2189. *rc = PTR_ERR(ce_core_clk);
  2190. if (pce_dev->ce_core_src_clk != NULL)
  2191. clk_put(pce_dev->ce_core_src_clk);
  2192. goto err;
  2193. }
  2194. pce_dev->ce_core_clk = ce_core_clk;
  2195. /* Get CE clk */
  2196. ce_clk = clk_get(pce_dev->pdev, "iface_clk");
  2197. if (IS_ERR(ce_clk)) {
  2198. *rc = PTR_ERR(ce_clk);
  2199. if (pce_dev->ce_core_src_clk != NULL)
  2200. clk_put(pce_dev->ce_core_src_clk);
  2201. clk_put(pce_dev->ce_core_clk);
  2202. goto err;
  2203. }
  2204. pce_dev->ce_clk = ce_clk;
  2205. /* Enable CE core clk */
  2206. *rc = clk_prepare_enable(pce_dev->ce_core_clk);
  2207. if (*rc) {
  2208. if (pce_dev->ce_core_src_clk != NULL)
  2209. clk_put(pce_dev->ce_core_src_clk);
  2210. clk_put(pce_dev->ce_core_clk);
  2211. clk_put(pce_dev->ce_clk);
  2212. goto err;
  2213. } else {
  2214. /* Enable CE clk */
  2215. *rc = clk_prepare_enable(pce_dev->ce_clk);
  2216. if (*rc) {
  2217. clk_disable_unprepare(pce_dev->ce_core_clk);
  2218. if (pce_dev->ce_core_src_clk != NULL)
  2219. clk_put(pce_dev->ce_core_src_clk);
  2220. clk_put(pce_dev->ce_core_clk);
  2221. clk_put(pce_dev->ce_clk);
  2222. goto err;
  2223. }
  2224. }
  2225. qce_setup_ce_dm_data(pce_dev);
  2226. pce_dev->ce_dm.chan_ce_in_state = QCE_CHAN_STATE_IDLE;
  2227. pce_dev->ce_dm.chan_ce_out_state = QCE_CHAN_STATE_IDLE;
  2228. if (_init_ce_engine(pce_dev)) {
  2229. *rc = -ENXIO;
  2230. goto err;
  2231. }
  2232. *rc = 0;
  2233. return pce_dev;
  2234. err:
  2235. if (pce_dev->coh_vmem)
  2236. dma_free_coherent(pce_dev->pdev, pce_dev->memsize,
  2237. pce_dev->coh_vmem, pce_dev->coh_pmem);
  2238. err_dm_chan_cmd:
  2239. kfree(pce_dev->ce_dm.chan_ce_in_cmd);
  2240. kfree(pce_dev->ce_dm.chan_ce_out_cmd);
  2241. if (pce_dev->iobase)
  2242. iounmap(pce_dev->iobase);
  2243. err_pce_dev:
  2244. kfree(pce_dev);
  2245. return NULL;
  2246. }
  2247. EXPORT_SYMBOL(qce_open);
  2248. /* crypto engine close function. */
  2249. int qce_close(void *handle)
  2250. {
  2251. struct qce_device *pce_dev = (struct qce_device *) handle;
  2252. if (handle == NULL)
  2253. return -ENODEV;
  2254. if (pce_dev->iobase)
  2255. iounmap(pce_dev->iobase);
  2256. if (pce_dev->coh_vmem)
  2257. dma_free_coherent(pce_dev->pdev, pce_dev->memsize,
  2258. pce_dev->coh_vmem, pce_dev->coh_pmem);
  2259. clk_disable_unprepare(pce_dev->ce_clk);
  2260. clk_disable_unprepare(pce_dev->ce_core_clk);
  2261. if (pce_dev->ce_core_src_clk != NULL)
  2262. clk_put(pce_dev->ce_core_src_clk);
  2263. clk_put(pce_dev->ce_clk);
  2264. clk_put(pce_dev->ce_core_clk);
  2265. kfree(pce_dev->ce_dm.chan_ce_in_cmd);
  2266. kfree(pce_dev->ce_dm.chan_ce_out_cmd);
  2267. kfree(handle);
  2268. return 0;
  2269. }
  2270. EXPORT_SYMBOL(qce_close);
  2271. int qce_hw_support(void *handle, struct ce_hw_support *ce_support)
  2272. {
  2273. if (ce_support == NULL)
  2274. return -EINVAL;
  2275. ce_support->sha1_hmac_20 = false;
  2276. ce_support->sha1_hmac = false;
  2277. ce_support->sha256_hmac = false;
  2278. ce_support->sha_hmac = false;
  2279. ce_support->cmac = true;
  2280. ce_support->aes_key_192 = false;
  2281. ce_support->aes_xts = true;
  2282. ce_support->aes_ccm = true;
  2283. ce_support->ota = false;
  2284. ce_support->aligned_only = false;
  2285. ce_support->is_shared = false;
  2286. ce_support->bam = false;
  2287. return 0;
  2288. }
  2289. EXPORT_SYMBOL(qce_hw_support);
  2290. MODULE_LICENSE("GPL v2");
  2291. MODULE_DESCRIPTION("Crypto Engine driver");