qcedev.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * QTI CE device driver.
  4. *
  5. * Copyright (c) 2010-2021, The Linux Foundation. All rights reserved.
  6. */
  7. #include <linux/mman.h>
  8. #include <linux/module.h>
  9. #include <linux/device.h>
  10. #include <linux/types.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/dma-mapping.h>
  13. #include <linux/kernel.h>
  14. #include <linux/dmapool.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <linux/fs.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/debugfs.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/crypto.h>
  24. #include "linux/platform_data/qcom_crypto_device.h"
  25. #include "linux/qcedev.h"
  26. #include <linux/interconnect.h>
  27. #include <crypto/hash.h>
  28. #include "qcedevi.h"
  29. #include "qce.h"
  30. #include "qcedev_smmu.h"
  31. #include "compat_qcedev.h"
  32. #include <linux/compat.h>
  33. #define CACHE_LINE_SIZE 32
  34. #define CE_SHA_BLOCK_SIZE SHA256_BLOCK_SIZE
  35. static uint8_t _std_init_vector_sha1_uint8[] = {
  36. 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB, 0x89,
  37. 0x98, 0xBA, 0xDC, 0xFE, 0x10, 0x32, 0x54, 0x76,
  38. 0xC3, 0xD2, 0xE1, 0xF0
  39. };
  40. /* standard initialization vector for SHA-256, source: FIPS 180-2 */
  41. static uint8_t _std_init_vector_sha256_uint8[] = {
  42. 0x6A, 0x09, 0xE6, 0x67, 0xBB, 0x67, 0xAE, 0x85,
  43. 0x3C, 0x6E, 0xF3, 0x72, 0xA5, 0x4F, 0xF5, 0x3A,
  44. 0x51, 0x0E, 0x52, 0x7F, 0x9B, 0x05, 0x68, 0x8C,
  45. 0x1F, 0x83, 0xD9, 0xAB, 0x5B, 0xE0, 0xCD, 0x19
  46. };
  47. static DEFINE_MUTEX(send_cmd_lock);
  48. static DEFINE_MUTEX(qcedev_sent_bw_req);
  49. static DEFINE_MUTEX(hash_access_lock);
  50. static dev_t qcedev_device_no;
  51. static struct class *driver_class;
  52. static struct device *class_dev;
  53. static const struct of_device_id qcedev_match[] = {
  54. { .compatible = "qcom,qcedev"},
  55. { .compatible = "qcom,qcedev,context-bank"},
  56. {}
  57. };
  58. MODULE_DEVICE_TABLE(of, qcedev_match);
  59. static int qcedev_control_clocks(struct qcedev_control *podev, bool enable)
  60. {
  61. unsigned int control_flag;
  62. int ret = 0;
  63. if (podev->ce_support.req_bw_before_clk) {
  64. if (enable)
  65. control_flag = QCE_BW_REQUEST_FIRST;
  66. else
  67. control_flag = QCE_CLK_DISABLE_FIRST;
  68. } else {
  69. if (enable)
  70. control_flag = QCE_CLK_ENABLE_FIRST;
  71. else
  72. control_flag = QCE_BW_REQUEST_RESET_FIRST;
  73. }
  74. switch (control_flag) {
  75. case QCE_CLK_ENABLE_FIRST:
  76. ret = qce_enable_clk(podev->qce);
  77. if (ret) {
  78. pr_err("%s Unable enable clk\n", __func__);
  79. return ret;
  80. }
  81. ret = icc_set_bw(podev->icc_path,
  82. CRYPTO_AVG_BW, CRYPTO_PEAK_BW);
  83. if (ret) {
  84. pr_err("%s Unable to set high bw\n", __func__);
  85. ret = qce_disable_clk(podev->qce);
  86. if (ret)
  87. pr_err("%s Unable disable clk\n", __func__);
  88. return ret;
  89. }
  90. break;
  91. case QCE_BW_REQUEST_FIRST:
  92. ret = icc_set_bw(podev->icc_path,
  93. CRYPTO_AVG_BW, CRYPTO_PEAK_BW);
  94. if (ret) {
  95. pr_err("%s Unable to set high bw\n", __func__);
  96. return ret;
  97. }
  98. ret = qce_enable_clk(podev->qce);
  99. if (ret) {
  100. pr_err("%s Unable enable clk\n", __func__);
  101. ret = icc_set_bw(podev->icc_path, 0, 0);
  102. if (ret)
  103. pr_err("%s Unable to set low bw\n", __func__);
  104. return ret;
  105. }
  106. break;
  107. case QCE_CLK_DISABLE_FIRST:
  108. ret = qce_disable_clk(podev->qce);
  109. if (ret) {
  110. pr_err("%s Unable to disable clk\n", __func__);
  111. return ret;
  112. }
  113. ret = icc_set_bw(podev->icc_path, 0, 0);
  114. if (ret) {
  115. pr_err("%s Unable to set low bw\n", __func__);
  116. ret = qce_enable_clk(podev->qce);
  117. if (ret)
  118. pr_err("%s Unable enable clk\n", __func__);
  119. return ret;
  120. }
  121. break;
  122. case QCE_BW_REQUEST_RESET_FIRST:
  123. ret = icc_set_bw(podev->icc_path, 0, 0);
  124. if (ret) {
  125. pr_err("%s Unable to set low bw\n", __func__);
  126. return ret;
  127. }
  128. ret = qce_disable_clk(podev->qce);
  129. if (ret) {
  130. pr_err("%s Unable to disable clk\n", __func__);
  131. ret = icc_set_bw(podev->icc_path,
  132. CRYPTO_AVG_BW, CRYPTO_PEAK_BW);
  133. if (ret)
  134. pr_err("%s Unable to set high bw\n", __func__);
  135. return ret;
  136. }
  137. break;
  138. default:
  139. return -ENOENT;
  140. }
  141. return 0;
  142. }
  143. static void qcedev_ce_high_bw_req(struct qcedev_control *podev,
  144. bool high_bw_req)
  145. {
  146. int ret = 0;
  147. mutex_lock(&qcedev_sent_bw_req);
  148. if (high_bw_req) {
  149. if (podev->high_bw_req_count == 0) {
  150. ret = qcedev_control_clocks(podev, true);
  151. if (ret)
  152. goto exit_unlock_mutex;
  153. }
  154. podev->high_bw_req_count++;
  155. } else {
  156. if (podev->high_bw_req_count == 1) {
  157. ret = qcedev_control_clocks(podev, false);
  158. if (ret)
  159. goto exit_unlock_mutex;
  160. }
  161. podev->high_bw_req_count--;
  162. }
  163. exit_unlock_mutex:
  164. mutex_unlock(&qcedev_sent_bw_req);
  165. }
  166. #define QCEDEV_MAGIC 0x56434544 /* "qced" */
  167. static int qcedev_open(struct inode *inode, struct file *file);
  168. static int qcedev_release(struct inode *inode, struct file *file);
  169. static int start_cipher_req(struct qcedev_control *podev);
  170. static int start_sha_req(struct qcedev_control *podev);
  171. static const struct file_operations qcedev_fops = {
  172. .owner = THIS_MODULE,
  173. .unlocked_ioctl = qcedev_ioctl,
  174. #ifdef CONFIG_COMPAT
  175. .compat_ioctl = compat_qcedev_ioctl,
  176. #endif
  177. .open = qcedev_open,
  178. .release = qcedev_release,
  179. };
  180. static struct qcedev_control qce_dev[] = {
  181. {
  182. .magic = QCEDEV_MAGIC,
  183. },
  184. };
  185. #define MAX_QCE_DEVICE ARRAY_SIZE(qce_dev)
  186. #define DEBUG_MAX_FNAME 16
  187. #define DEBUG_MAX_RW_BUF 1024
  188. struct qcedev_stat {
  189. u32 qcedev_dec_success;
  190. u32 qcedev_dec_fail;
  191. u32 qcedev_enc_success;
  192. u32 qcedev_enc_fail;
  193. u32 qcedev_sha_success;
  194. u32 qcedev_sha_fail;
  195. };
  196. static struct qcedev_stat _qcedev_stat;
  197. static struct dentry *_debug_dent;
  198. static char _debug_read_buf[DEBUG_MAX_RW_BUF];
  199. static int _debug_qcedev;
  200. static struct qcedev_control *qcedev_minor_to_control(unsigned int n)
  201. {
  202. int i;
  203. for (i = 0; i < MAX_QCE_DEVICE; i++) {
  204. if (qce_dev[i].minor == n)
  205. return &qce_dev[n];
  206. }
  207. return NULL;
  208. }
  209. static int qcedev_open(struct inode *inode, struct file *file)
  210. {
  211. struct qcedev_handle *handle;
  212. struct qcedev_control *podev;
  213. podev = qcedev_minor_to_control(MINOR(inode->i_rdev));
  214. if (podev == NULL) {
  215. pr_err("%s: no such device %d\n", __func__,
  216. MINOR(inode->i_rdev));
  217. return -ENOENT;
  218. }
  219. handle = kzalloc(sizeof(struct qcedev_handle), GFP_KERNEL);
  220. if (handle == NULL)
  221. return -ENOMEM;
  222. handle->cntl = podev;
  223. file->private_data = handle;
  224. mutex_init(&handle->registeredbufs.lock);
  225. INIT_LIST_HEAD(&handle->registeredbufs.list);
  226. return 0;
  227. }
  228. static int qcedev_release(struct inode *inode, struct file *file)
  229. {
  230. struct qcedev_control *podev;
  231. struct qcedev_handle *handle;
  232. handle = file->private_data;
  233. podev = handle->cntl;
  234. if (podev != NULL && podev->magic != QCEDEV_MAGIC) {
  235. pr_err("%s: invalid handle %pK\n",
  236. __func__, podev);
  237. }
  238. if (qcedev_unmap_all_buffers(handle))
  239. pr_err("%s: failed to unmap all ion buffers\n", __func__);
  240. kfree_sensitive(handle);
  241. file->private_data = NULL;
  242. return 0;
  243. }
  244. static void req_done(unsigned long data)
  245. {
  246. struct qcedev_control *podev = (struct qcedev_control *)data;
  247. struct qcedev_async_req *areq;
  248. unsigned long flags = 0;
  249. struct qcedev_async_req *new_req = NULL;
  250. int ret = 0;
  251. spin_lock_irqsave(&podev->lock, flags);
  252. areq = podev->active_command;
  253. podev->active_command = NULL;
  254. again:
  255. if (!list_empty(&podev->ready_commands)) {
  256. new_req = container_of(podev->ready_commands.next,
  257. struct qcedev_async_req, list);
  258. list_del(&new_req->list);
  259. podev->active_command = new_req;
  260. new_req->err = 0;
  261. if (new_req->op_type == QCEDEV_CRYPTO_OPER_CIPHER)
  262. ret = start_cipher_req(podev);
  263. else
  264. ret = start_sha_req(podev);
  265. }
  266. spin_unlock_irqrestore(&podev->lock, flags);
  267. if (areq)
  268. complete(&areq->complete);
  269. if (new_req && ret) {
  270. complete(&new_req->complete);
  271. spin_lock_irqsave(&podev->lock, flags);
  272. podev->active_command = NULL;
  273. areq = NULL;
  274. ret = 0;
  275. new_req = NULL;
  276. goto again;
  277. }
  278. }
  279. void qcedev_sha_req_cb(void *cookie, unsigned char *digest,
  280. unsigned char *authdata, int ret)
  281. {
  282. struct qcedev_sha_req *areq;
  283. struct qcedev_control *pdev;
  284. struct qcedev_handle *handle;
  285. uint32_t *auth32 = (uint32_t *)authdata;
  286. areq = (struct qcedev_sha_req *) cookie;
  287. handle = (struct qcedev_handle *) areq->cookie;
  288. pdev = handle->cntl;
  289. if (digest)
  290. memcpy(&handle->sha_ctxt.digest[0], digest, 32);
  291. if (authdata) {
  292. handle->sha_ctxt.auth_data[0] = auth32[0];
  293. handle->sha_ctxt.auth_data[1] = auth32[1];
  294. }
  295. tasklet_schedule(&pdev->done_tasklet);
  296. };
  297. void qcedev_cipher_req_cb(void *cookie, unsigned char *icv,
  298. unsigned char *iv, int ret)
  299. {
  300. struct qcedev_cipher_req *areq;
  301. struct qcedev_handle *handle;
  302. struct qcedev_control *podev;
  303. struct qcedev_async_req *qcedev_areq;
  304. areq = (struct qcedev_cipher_req *) cookie;
  305. handle = (struct qcedev_handle *) areq->cookie;
  306. podev = handle->cntl;
  307. qcedev_areq = podev->active_command;
  308. if (iv)
  309. memcpy(&qcedev_areq->cipher_op_req.iv[0], iv,
  310. qcedev_areq->cipher_op_req.ivlen);
  311. tasklet_schedule(&podev->done_tasklet);
  312. };
  313. static int start_cipher_req(struct qcedev_control *podev)
  314. {
  315. struct qcedev_async_req *qcedev_areq;
  316. struct qce_req creq;
  317. int ret = 0;
  318. /* start the command on the podev->active_command */
  319. qcedev_areq = podev->active_command;
  320. qcedev_areq->cipher_req.cookie = qcedev_areq->handle;
  321. if (qcedev_areq->cipher_op_req.use_pmem == QCEDEV_USE_PMEM) {
  322. pr_err("%s: Use of PMEM is not supported\n", __func__);
  323. goto unsupported;
  324. }
  325. creq.pmem = NULL;
  326. switch (qcedev_areq->cipher_op_req.alg) {
  327. case QCEDEV_ALG_DES:
  328. creq.alg = CIPHER_ALG_DES;
  329. break;
  330. case QCEDEV_ALG_3DES:
  331. creq.alg = CIPHER_ALG_3DES;
  332. break;
  333. case QCEDEV_ALG_AES:
  334. creq.alg = CIPHER_ALG_AES;
  335. break;
  336. default:
  337. return -EINVAL;
  338. }
  339. switch (qcedev_areq->cipher_op_req.mode) {
  340. case QCEDEV_AES_MODE_CBC:
  341. case QCEDEV_DES_MODE_CBC:
  342. creq.mode = QCE_MODE_CBC;
  343. break;
  344. case QCEDEV_AES_MODE_ECB:
  345. case QCEDEV_DES_MODE_ECB:
  346. creq.mode = QCE_MODE_ECB;
  347. break;
  348. case QCEDEV_AES_MODE_CTR:
  349. creq.mode = QCE_MODE_CTR;
  350. break;
  351. case QCEDEV_AES_MODE_XTS:
  352. creq.mode = QCE_MODE_XTS;
  353. break;
  354. default:
  355. return -EINVAL;
  356. }
  357. if ((creq.alg == CIPHER_ALG_AES) &&
  358. (creq.mode == QCE_MODE_CTR)) {
  359. creq.dir = QCE_ENCRYPT;
  360. } else {
  361. if (qcedev_areq->cipher_op_req.op == QCEDEV_OPER_ENC)
  362. creq.dir = QCE_ENCRYPT;
  363. else
  364. creq.dir = QCE_DECRYPT;
  365. }
  366. creq.iv = &qcedev_areq->cipher_op_req.iv[0];
  367. creq.ivsize = qcedev_areq->cipher_op_req.ivlen;
  368. creq.enckey = &qcedev_areq->cipher_op_req.enckey[0];
  369. creq.encklen = qcedev_areq->cipher_op_req.encklen;
  370. creq.cryptlen = qcedev_areq->cipher_op_req.data_len;
  371. if (qcedev_areq->cipher_op_req.encklen == 0) {
  372. if ((qcedev_areq->cipher_op_req.op == QCEDEV_OPER_ENC_NO_KEY)
  373. || (qcedev_areq->cipher_op_req.op ==
  374. QCEDEV_OPER_DEC_NO_KEY))
  375. creq.op = QCE_REQ_ABLK_CIPHER_NO_KEY;
  376. else {
  377. int i;
  378. for (i = 0; i < QCEDEV_MAX_KEY_SIZE; i++) {
  379. if (qcedev_areq->cipher_op_req.enckey[i] != 0)
  380. break;
  381. }
  382. if ((podev->platform_support.hw_key_support == 1) &&
  383. (i == QCEDEV_MAX_KEY_SIZE))
  384. creq.op = QCE_REQ_ABLK_CIPHER;
  385. else {
  386. ret = -EINVAL;
  387. goto unsupported;
  388. }
  389. }
  390. } else {
  391. creq.op = QCE_REQ_ABLK_CIPHER;
  392. }
  393. creq.qce_cb = qcedev_cipher_req_cb;
  394. creq.areq = (void *)&qcedev_areq->cipher_req;
  395. creq.flags = 0;
  396. ret = qce_ablk_cipher_req(podev->qce, &creq);
  397. unsupported:
  398. if (ret)
  399. qcedev_areq->err = -ENXIO;
  400. else
  401. qcedev_areq->err = 0;
  402. return ret;
  403. };
  404. static int start_sha_req(struct qcedev_control *podev)
  405. {
  406. struct qcedev_async_req *qcedev_areq;
  407. struct qce_sha_req sreq;
  408. int ret = 0;
  409. struct qcedev_handle *handle;
  410. /* start the command on the podev->active_command */
  411. qcedev_areq = podev->active_command;
  412. handle = qcedev_areq->handle;
  413. switch (qcedev_areq->sha_op_req.alg) {
  414. case QCEDEV_ALG_SHA1:
  415. sreq.alg = QCE_HASH_SHA1;
  416. break;
  417. case QCEDEV_ALG_SHA256:
  418. sreq.alg = QCE_HASH_SHA256;
  419. break;
  420. case QCEDEV_ALG_SHA1_HMAC:
  421. if (podev->ce_support.sha_hmac) {
  422. sreq.alg = QCE_HASH_SHA1_HMAC;
  423. sreq.authkey = &handle->sha_ctxt.authkey[0];
  424. sreq.authklen = QCEDEV_MAX_SHA_BLOCK_SIZE;
  425. } else {
  426. sreq.alg = QCE_HASH_SHA1;
  427. sreq.authkey = NULL;
  428. }
  429. break;
  430. case QCEDEV_ALG_SHA256_HMAC:
  431. if (podev->ce_support.sha_hmac) {
  432. sreq.alg = QCE_HASH_SHA256_HMAC;
  433. sreq.authkey = &handle->sha_ctxt.authkey[0];
  434. sreq.authklen = QCEDEV_MAX_SHA_BLOCK_SIZE;
  435. } else {
  436. sreq.alg = QCE_HASH_SHA256;
  437. sreq.authkey = NULL;
  438. }
  439. break;
  440. case QCEDEV_ALG_AES_CMAC:
  441. sreq.alg = QCE_HASH_AES_CMAC;
  442. sreq.authkey = &handle->sha_ctxt.authkey[0];
  443. sreq.authklen = qcedev_areq->sha_op_req.authklen;
  444. break;
  445. default:
  446. pr_err("Algorithm %d not supported, exiting\n",
  447. qcedev_areq->sha_op_req.alg);
  448. return -EINVAL;
  449. }
  450. qcedev_areq->sha_req.cookie = handle;
  451. sreq.qce_cb = qcedev_sha_req_cb;
  452. if (qcedev_areq->sha_op_req.alg != QCEDEV_ALG_AES_CMAC) {
  453. sreq.auth_data[0] = handle->sha_ctxt.auth_data[0];
  454. sreq.auth_data[1] = handle->sha_ctxt.auth_data[1];
  455. sreq.auth_data[2] = handle->sha_ctxt.auth_data[2];
  456. sreq.auth_data[3] = handle->sha_ctxt.auth_data[3];
  457. sreq.digest = &handle->sha_ctxt.digest[0];
  458. sreq.first_blk = handle->sha_ctxt.first_blk;
  459. sreq.last_blk = handle->sha_ctxt.last_blk;
  460. }
  461. sreq.size = qcedev_areq->sha_req.sreq.nbytes;
  462. sreq.src = qcedev_areq->sha_req.sreq.src;
  463. sreq.areq = (void *)&qcedev_areq->sha_req;
  464. sreq.flags = 0;
  465. ret = qce_process_sha_req(podev->qce, &sreq);
  466. if (ret)
  467. qcedev_areq->err = -ENXIO;
  468. else
  469. qcedev_areq->err = 0;
  470. return ret;
  471. };
  472. static int submit_req(struct qcedev_async_req *qcedev_areq,
  473. struct qcedev_handle *handle)
  474. {
  475. struct qcedev_control *podev;
  476. unsigned long flags = 0;
  477. int ret = 0;
  478. struct qcedev_stat *pstat;
  479. qcedev_areq->err = 0;
  480. podev = handle->cntl;
  481. spin_lock_irqsave(&podev->lock, flags);
  482. if (podev->active_command == NULL) {
  483. podev->active_command = qcedev_areq;
  484. if (qcedev_areq->op_type == QCEDEV_CRYPTO_OPER_CIPHER)
  485. ret = start_cipher_req(podev);
  486. else
  487. ret = start_sha_req(podev);
  488. } else {
  489. list_add_tail(&qcedev_areq->list, &podev->ready_commands);
  490. }
  491. if (ret != 0)
  492. podev->active_command = NULL;
  493. spin_unlock_irqrestore(&podev->lock, flags);
  494. if (ret == 0)
  495. wait_for_completion(&qcedev_areq->complete);
  496. if (ret)
  497. qcedev_areq->err = -EIO;
  498. pstat = &_qcedev_stat;
  499. if (qcedev_areq->op_type == QCEDEV_CRYPTO_OPER_CIPHER) {
  500. switch (qcedev_areq->cipher_op_req.op) {
  501. case QCEDEV_OPER_DEC:
  502. if (qcedev_areq->err)
  503. pstat->qcedev_dec_fail++;
  504. else
  505. pstat->qcedev_dec_success++;
  506. break;
  507. case QCEDEV_OPER_ENC:
  508. if (qcedev_areq->err)
  509. pstat->qcedev_enc_fail++;
  510. else
  511. pstat->qcedev_enc_success++;
  512. break;
  513. default:
  514. break;
  515. }
  516. } else {
  517. if (qcedev_areq->err)
  518. pstat->qcedev_sha_fail++;
  519. else
  520. pstat->qcedev_sha_success++;
  521. }
  522. return qcedev_areq->err;
  523. }
  524. static int qcedev_sha_init(struct qcedev_async_req *areq,
  525. struct qcedev_handle *handle)
  526. {
  527. struct qcedev_sha_ctxt *sha_ctxt = &handle->sha_ctxt;
  528. memset(sha_ctxt, 0, sizeof(struct qcedev_sha_ctxt));
  529. sha_ctxt->first_blk = 1;
  530. if ((areq->sha_op_req.alg == QCEDEV_ALG_SHA1) ||
  531. (areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC)) {
  532. memcpy(&sha_ctxt->digest[0],
  533. &_std_init_vector_sha1_uint8[0], SHA1_DIGEST_SIZE);
  534. sha_ctxt->diglen = SHA1_DIGEST_SIZE;
  535. } else {
  536. if ((areq->sha_op_req.alg == QCEDEV_ALG_SHA256) ||
  537. (areq->sha_op_req.alg == QCEDEV_ALG_SHA256_HMAC)) {
  538. memcpy(&sha_ctxt->digest[0],
  539. &_std_init_vector_sha256_uint8[0],
  540. SHA256_DIGEST_SIZE);
  541. sha_ctxt->diglen = SHA256_DIGEST_SIZE;
  542. }
  543. }
  544. sha_ctxt->init_done = true;
  545. return 0;
  546. }
  547. static int qcedev_sha_update_max_xfer(struct qcedev_async_req *qcedev_areq,
  548. struct qcedev_handle *handle,
  549. struct scatterlist *sg_src)
  550. {
  551. int err = 0;
  552. int i = 0;
  553. uint32_t total;
  554. uint8_t *user_src = NULL;
  555. uint8_t *k_src = NULL;
  556. uint8_t *k_buf_src = NULL;
  557. uint8_t *k_align_src = NULL;
  558. uint32_t sha_pad_len = 0;
  559. uint32_t trailing_buf_len = 0;
  560. uint32_t t_buf = handle->sha_ctxt.trailing_buf_len;
  561. uint32_t sha_block_size;
  562. total = qcedev_areq->sha_op_req.data_len + t_buf;
  563. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA1)
  564. sha_block_size = SHA1_BLOCK_SIZE;
  565. else
  566. sha_block_size = SHA256_BLOCK_SIZE;
  567. if (total <= sha_block_size) {
  568. uint32_t len = qcedev_areq->sha_op_req.data_len;
  569. i = 0;
  570. k_src = &handle->sha_ctxt.trailing_buf[t_buf];
  571. /* Copy data from user src(s) */
  572. while (len > 0) {
  573. user_src = qcedev_areq->sha_op_req.data[i].vaddr;
  574. if (user_src && copy_from_user(k_src,
  575. (void __user *)user_src,
  576. qcedev_areq->sha_op_req.data[i].len))
  577. return -EFAULT;
  578. len -= qcedev_areq->sha_op_req.data[i].len;
  579. k_src += qcedev_areq->sha_op_req.data[i].len;
  580. i++;
  581. }
  582. handle->sha_ctxt.trailing_buf_len = total;
  583. return 0;
  584. }
  585. k_buf_src = kmalloc(total + CACHE_LINE_SIZE * 2,
  586. GFP_KERNEL);
  587. if (k_buf_src == NULL)
  588. return -ENOMEM;
  589. k_align_src = (uint8_t *)ALIGN(((uintptr_t)k_buf_src),
  590. CACHE_LINE_SIZE);
  591. k_src = k_align_src;
  592. /* check for trailing buffer from previous updates and append it */
  593. if (t_buf > 0) {
  594. memcpy(k_src, &handle->sha_ctxt.trailing_buf[0],
  595. t_buf);
  596. k_src += t_buf;
  597. }
  598. /* Copy data from user src(s) */
  599. user_src = qcedev_areq->sha_op_req.data[0].vaddr;
  600. if (user_src && copy_from_user(k_src,
  601. (void __user *)user_src,
  602. qcedev_areq->sha_op_req.data[0].len)) {
  603. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  604. kfree(k_buf_src);
  605. return -EFAULT;
  606. }
  607. k_src += qcedev_areq->sha_op_req.data[0].len;
  608. for (i = 1; i < qcedev_areq->sha_op_req.entries; i++) {
  609. user_src = qcedev_areq->sha_op_req.data[i].vaddr;
  610. if (user_src && copy_from_user(k_src,
  611. (void __user *)user_src,
  612. qcedev_areq->sha_op_req.data[i].len)) {
  613. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  614. kfree(k_buf_src);
  615. return -EFAULT;
  616. }
  617. k_src += qcedev_areq->sha_op_req.data[i].len;
  618. }
  619. /* get new trailing buffer */
  620. sha_pad_len = ALIGN(total, CE_SHA_BLOCK_SIZE) - total;
  621. trailing_buf_len = CE_SHA_BLOCK_SIZE - sha_pad_len;
  622. qcedev_areq->sha_req.sreq.src = sg_src;
  623. sg_init_one(qcedev_areq->sha_req.sreq.src, k_align_src,
  624. total-trailing_buf_len);
  625. qcedev_areq->sha_req.sreq.nbytes = total - trailing_buf_len;
  626. /* update sha_ctxt trailing buf content to new trailing buf */
  627. if (trailing_buf_len > 0) {
  628. memset(&handle->sha_ctxt.trailing_buf[0], 0, 64);
  629. memcpy(&handle->sha_ctxt.trailing_buf[0],
  630. (k_src - trailing_buf_len),
  631. trailing_buf_len);
  632. }
  633. handle->sha_ctxt.trailing_buf_len = trailing_buf_len;
  634. err = submit_req(qcedev_areq, handle);
  635. handle->sha_ctxt.last_blk = 0;
  636. handle->sha_ctxt.first_blk = 0;
  637. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  638. kfree(k_buf_src);
  639. return err;
  640. }
  641. static int qcedev_sha_update(struct qcedev_async_req *qcedev_areq,
  642. struct qcedev_handle *handle,
  643. struct scatterlist *sg_src)
  644. {
  645. int err = 0;
  646. int i = 0;
  647. int j = 0;
  648. int k = 0;
  649. int num_entries = 0;
  650. uint32_t total = 0;
  651. if (!handle->sha_ctxt.init_done) {
  652. pr_err("%s Init was not called\n", __func__);
  653. return -EINVAL;
  654. }
  655. if (qcedev_areq->sha_op_req.data_len > QCE_MAX_OPER_DATA) {
  656. struct qcedev_sha_op_req *saved_req;
  657. struct qcedev_sha_op_req req;
  658. struct qcedev_sha_op_req *sreq = &qcedev_areq->sha_op_req;
  659. /* save the original req structure */
  660. saved_req =
  661. kmalloc(sizeof(struct qcedev_sha_op_req), GFP_KERNEL);
  662. if (saved_req == NULL) {
  663. pr_err("%s:Can't Allocate mem:saved_req 0x%lx\n",
  664. __func__, (uintptr_t)saved_req);
  665. return -ENOMEM;
  666. }
  667. memcpy(&req, sreq, sizeof(struct qcedev_sha_op_req));
  668. memcpy(saved_req, sreq, sizeof(struct qcedev_sha_op_req));
  669. i = 0;
  670. /* Address 32 KB at a time */
  671. while ((i < req.entries) && (err == 0)) {
  672. if (sreq->data[i].len > QCE_MAX_OPER_DATA) {
  673. sreq->data[0].len = QCE_MAX_OPER_DATA;
  674. if (i > 0) {
  675. sreq->data[0].vaddr =
  676. sreq->data[i].vaddr;
  677. }
  678. sreq->data_len = QCE_MAX_OPER_DATA;
  679. sreq->entries = 1;
  680. err = qcedev_sha_update_max_xfer(qcedev_areq,
  681. handle, sg_src);
  682. sreq->data[i].len = req.data[i].len -
  683. QCE_MAX_OPER_DATA;
  684. sreq->data[i].vaddr = req.data[i].vaddr +
  685. QCE_MAX_OPER_DATA;
  686. req.data[i].vaddr = sreq->data[i].vaddr;
  687. req.data[i].len = sreq->data[i].len;
  688. } else {
  689. total = 0;
  690. for (j = i; j < req.entries; j++) {
  691. num_entries++;
  692. if ((total + sreq->data[j].len) >=
  693. QCE_MAX_OPER_DATA) {
  694. sreq->data[j].len =
  695. (QCE_MAX_OPER_DATA - total);
  696. total = QCE_MAX_OPER_DATA;
  697. break;
  698. }
  699. total += sreq->data[j].len;
  700. }
  701. sreq->data_len = total;
  702. if (i > 0)
  703. for (k = 0; k < num_entries; k++) {
  704. sreq->data[k].len =
  705. sreq->data[i+k].len;
  706. sreq->data[k].vaddr =
  707. sreq->data[i+k].vaddr;
  708. }
  709. sreq->entries = num_entries;
  710. i = j;
  711. err = qcedev_sha_update_max_xfer(qcedev_areq,
  712. handle, sg_src);
  713. num_entries = 0;
  714. sreq->data[i].vaddr = req.data[i].vaddr +
  715. sreq->data[i].len;
  716. sreq->data[i].len = req.data[i].len -
  717. sreq->data[i].len;
  718. req.data[i].vaddr = sreq->data[i].vaddr;
  719. req.data[i].len = sreq->data[i].len;
  720. if (sreq->data[i].len == 0)
  721. i++;
  722. }
  723. } /* end of while ((i < req.entries) && (err == 0)) */
  724. /* Restore the original req structure */
  725. for (i = 0; i < saved_req->entries; i++) {
  726. sreq->data[i].len = saved_req->data[i].len;
  727. sreq->data[i].vaddr = saved_req->data[i].vaddr;
  728. }
  729. sreq->entries = saved_req->entries;
  730. sreq->data_len = saved_req->data_len;
  731. memset(saved_req, 0, ksize((void *)saved_req));
  732. kfree(saved_req);
  733. } else
  734. err = qcedev_sha_update_max_xfer(qcedev_areq, handle, sg_src);
  735. return err;
  736. }
  737. static int qcedev_sha_final(struct qcedev_async_req *qcedev_areq,
  738. struct qcedev_handle *handle)
  739. {
  740. int err = 0;
  741. struct scatterlist sg_src;
  742. uint32_t total;
  743. uint8_t *k_buf_src = NULL;
  744. uint8_t *k_align_src = NULL;
  745. if (!handle->sha_ctxt.init_done) {
  746. pr_err("%s Init was not called\n", __func__);
  747. return -EINVAL;
  748. }
  749. handle->sha_ctxt.last_blk = 1;
  750. total = handle->sha_ctxt.trailing_buf_len;
  751. k_buf_src = kmalloc(total + CACHE_LINE_SIZE * 2,
  752. GFP_KERNEL);
  753. if (k_buf_src == NULL)
  754. return -ENOMEM;
  755. k_align_src = (uint8_t *)ALIGN(((uintptr_t)k_buf_src),
  756. CACHE_LINE_SIZE);
  757. memcpy(k_align_src, &handle->sha_ctxt.trailing_buf[0], total);
  758. qcedev_areq->sha_req.sreq.src = (struct scatterlist *) &sg_src;
  759. sg_init_one(qcedev_areq->sha_req.sreq.src, k_align_src, total);
  760. qcedev_areq->sha_req.sreq.nbytes = total;
  761. err = submit_req(qcedev_areq, handle);
  762. handle->sha_ctxt.first_blk = 0;
  763. handle->sha_ctxt.last_blk = 0;
  764. handle->sha_ctxt.auth_data[0] = 0;
  765. handle->sha_ctxt.auth_data[1] = 0;
  766. handle->sha_ctxt.trailing_buf_len = 0;
  767. handle->sha_ctxt.init_done = false;
  768. memset(&handle->sha_ctxt.trailing_buf[0], 0, 64);
  769. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  770. kfree(k_buf_src);
  771. qcedev_areq->sha_req.sreq.src = NULL;
  772. return err;
  773. }
  774. static int qcedev_hash_cmac(struct qcedev_async_req *qcedev_areq,
  775. struct qcedev_handle *handle,
  776. struct scatterlist *sg_src)
  777. {
  778. int err = 0;
  779. int i = 0;
  780. uint32_t total;
  781. uint8_t *user_src = NULL;
  782. uint8_t *k_src = NULL;
  783. uint8_t *k_buf_src = NULL;
  784. total = qcedev_areq->sha_op_req.data_len;
  785. if ((qcedev_areq->sha_op_req.authklen != QCEDEV_AES_KEY_128) &&
  786. (qcedev_areq->sha_op_req.authklen != QCEDEV_AES_KEY_256)) {
  787. pr_err("%s: unsupported key length\n", __func__);
  788. return -EINVAL;
  789. }
  790. if (copy_from_user(&handle->sha_ctxt.authkey[0],
  791. (void __user *)qcedev_areq->sha_op_req.authkey,
  792. qcedev_areq->sha_op_req.authklen))
  793. return -EFAULT;
  794. if (total > U32_MAX - CACHE_LINE_SIZE * 2)
  795. return -EINVAL;
  796. k_buf_src = kmalloc(total + CACHE_LINE_SIZE * 2, GFP_KERNEL);
  797. if (k_buf_src == NULL)
  798. return -ENOMEM;
  799. k_src = k_buf_src;
  800. /* Copy data from user src(s) */
  801. user_src = qcedev_areq->sha_op_req.data[0].vaddr;
  802. for (i = 0; i < qcedev_areq->sha_op_req.entries; i++) {
  803. user_src = qcedev_areq->sha_op_req.data[i].vaddr;
  804. if (user_src && copy_from_user(k_src, (void __user *)user_src,
  805. qcedev_areq->sha_op_req.data[i].len)) {
  806. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  807. kfree(k_buf_src);
  808. return -EFAULT;
  809. }
  810. k_src += qcedev_areq->sha_op_req.data[i].len;
  811. }
  812. qcedev_areq->sha_req.sreq.src = sg_src;
  813. sg_init_one(qcedev_areq->sha_req.sreq.src, k_buf_src, total);
  814. qcedev_areq->sha_req.sreq.nbytes = total;
  815. handle->sha_ctxt.diglen = qcedev_areq->sha_op_req.diglen;
  816. err = submit_req(qcedev_areq, handle);
  817. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  818. kfree(k_buf_src);
  819. return err;
  820. }
  821. static int qcedev_set_hmac_auth_key(struct qcedev_async_req *areq,
  822. struct qcedev_handle *handle,
  823. struct scatterlist *sg_src)
  824. {
  825. int err = 0;
  826. if (areq->sha_op_req.authklen <= QCEDEV_MAX_KEY_SIZE) {
  827. qcedev_sha_init(areq, handle);
  828. if (copy_from_user(&handle->sha_ctxt.authkey[0],
  829. (void __user *)areq->sha_op_req.authkey,
  830. areq->sha_op_req.authklen))
  831. return -EFAULT;
  832. } else {
  833. struct qcedev_async_req authkey_areq;
  834. uint8_t authkey[QCEDEV_MAX_SHA_BLOCK_SIZE];
  835. init_completion(&authkey_areq.complete);
  836. authkey_areq.sha_op_req.entries = 1;
  837. authkey_areq.sha_op_req.data[0].vaddr =
  838. areq->sha_op_req.authkey;
  839. authkey_areq.sha_op_req.data[0].len = areq->sha_op_req.authklen;
  840. authkey_areq.sha_op_req.data_len = areq->sha_op_req.authklen;
  841. authkey_areq.sha_op_req.diglen = 0;
  842. authkey_areq.handle = handle;
  843. memset(&authkey_areq.sha_op_req.digest[0], 0,
  844. QCEDEV_MAX_SHA_DIGEST);
  845. if (areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC)
  846. authkey_areq.sha_op_req.alg = QCEDEV_ALG_SHA1;
  847. if (areq->sha_op_req.alg == QCEDEV_ALG_SHA256_HMAC)
  848. authkey_areq.sha_op_req.alg = QCEDEV_ALG_SHA256;
  849. authkey_areq.op_type = QCEDEV_CRYPTO_OPER_SHA;
  850. qcedev_sha_init(&authkey_areq, handle);
  851. err = qcedev_sha_update(&authkey_areq, handle, sg_src);
  852. if (!err)
  853. err = qcedev_sha_final(&authkey_areq, handle);
  854. else
  855. return err;
  856. memcpy(&authkey[0], &handle->sha_ctxt.digest[0],
  857. handle->sha_ctxt.diglen);
  858. qcedev_sha_init(areq, handle);
  859. memcpy(&handle->sha_ctxt.authkey[0], &authkey[0],
  860. handle->sha_ctxt.diglen);
  861. }
  862. return err;
  863. }
  864. static int qcedev_hmac_get_ohash(struct qcedev_async_req *qcedev_areq,
  865. struct qcedev_handle *handle)
  866. {
  867. int err = 0;
  868. struct scatterlist sg_src;
  869. uint8_t *k_src = NULL;
  870. uint32_t sha_block_size = 0;
  871. uint32_t sha_digest_size = 0;
  872. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC) {
  873. sha_digest_size = SHA1_DIGEST_SIZE;
  874. sha_block_size = SHA1_BLOCK_SIZE;
  875. } else {
  876. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA256_HMAC) {
  877. sha_digest_size = SHA256_DIGEST_SIZE;
  878. sha_block_size = SHA256_BLOCK_SIZE;
  879. }
  880. }
  881. k_src = kmalloc(sha_block_size, GFP_KERNEL);
  882. if (k_src == NULL)
  883. return -ENOMEM;
  884. /* check for trailing buffer from previous updates and append it */
  885. memcpy(k_src, &handle->sha_ctxt.trailing_buf[0],
  886. handle->sha_ctxt.trailing_buf_len);
  887. qcedev_areq->sha_req.sreq.src = (struct scatterlist *) &sg_src;
  888. sg_init_one(qcedev_areq->sha_req.sreq.src, k_src, sha_block_size);
  889. qcedev_areq->sha_req.sreq.nbytes = sha_block_size;
  890. memset(&handle->sha_ctxt.trailing_buf[0], 0, sha_block_size);
  891. memcpy(&handle->sha_ctxt.trailing_buf[0], &handle->sha_ctxt.digest[0],
  892. sha_digest_size);
  893. handle->sha_ctxt.trailing_buf_len = sha_digest_size;
  894. handle->sha_ctxt.first_blk = 1;
  895. handle->sha_ctxt.last_blk = 0;
  896. handle->sha_ctxt.auth_data[0] = 0;
  897. handle->sha_ctxt.auth_data[1] = 0;
  898. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC) {
  899. memcpy(&handle->sha_ctxt.digest[0],
  900. &_std_init_vector_sha1_uint8[0], SHA1_DIGEST_SIZE);
  901. handle->sha_ctxt.diglen = SHA1_DIGEST_SIZE;
  902. }
  903. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA256_HMAC) {
  904. memcpy(&handle->sha_ctxt.digest[0],
  905. &_std_init_vector_sha256_uint8[0], SHA256_DIGEST_SIZE);
  906. handle->sha_ctxt.diglen = SHA256_DIGEST_SIZE;
  907. }
  908. err = submit_req(qcedev_areq, handle);
  909. handle->sha_ctxt.last_blk = 0;
  910. handle->sha_ctxt.first_blk = 0;
  911. memset(k_src, 0, ksize((void *)k_src));
  912. kfree(k_src);
  913. qcedev_areq->sha_req.sreq.src = NULL;
  914. return err;
  915. }
  916. static int qcedev_hmac_update_iokey(struct qcedev_async_req *areq,
  917. struct qcedev_handle *handle, bool ikey)
  918. {
  919. int i;
  920. uint32_t constant;
  921. uint32_t sha_block_size;
  922. if (ikey)
  923. constant = 0x36;
  924. else
  925. constant = 0x5c;
  926. if (areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC)
  927. sha_block_size = SHA1_BLOCK_SIZE;
  928. else
  929. sha_block_size = SHA256_BLOCK_SIZE;
  930. memset(&handle->sha_ctxt.trailing_buf[0], 0, sha_block_size);
  931. for (i = 0; i < sha_block_size; i++)
  932. handle->sha_ctxt.trailing_buf[i] =
  933. (handle->sha_ctxt.authkey[i] ^ constant);
  934. handle->sha_ctxt.trailing_buf_len = sha_block_size;
  935. return 0;
  936. }
  937. static int qcedev_hmac_init(struct qcedev_async_req *areq,
  938. struct qcedev_handle *handle,
  939. struct scatterlist *sg_src)
  940. {
  941. int err;
  942. struct qcedev_control *podev = handle->cntl;
  943. err = qcedev_set_hmac_auth_key(areq, handle, sg_src);
  944. if (err)
  945. return err;
  946. if (!podev->ce_support.sha_hmac)
  947. qcedev_hmac_update_iokey(areq, handle, true);
  948. return 0;
  949. }
  950. static int qcedev_hmac_final(struct qcedev_async_req *areq,
  951. struct qcedev_handle *handle)
  952. {
  953. int err;
  954. struct qcedev_control *podev = handle->cntl;
  955. err = qcedev_sha_final(areq, handle);
  956. if (podev->ce_support.sha_hmac)
  957. return err;
  958. qcedev_hmac_update_iokey(areq, handle, false);
  959. err = qcedev_hmac_get_ohash(areq, handle);
  960. if (err)
  961. return err;
  962. err = qcedev_sha_final(areq, handle);
  963. return err;
  964. }
  965. static int qcedev_hash_init(struct qcedev_async_req *areq,
  966. struct qcedev_handle *handle,
  967. struct scatterlist *sg_src)
  968. {
  969. if ((areq->sha_op_req.alg == QCEDEV_ALG_SHA1) ||
  970. (areq->sha_op_req.alg == QCEDEV_ALG_SHA256))
  971. return qcedev_sha_init(areq, handle);
  972. else
  973. return qcedev_hmac_init(areq, handle, sg_src);
  974. }
  975. static int qcedev_hash_update(struct qcedev_async_req *qcedev_areq,
  976. struct qcedev_handle *handle,
  977. struct scatterlist *sg_src)
  978. {
  979. return qcedev_sha_update(qcedev_areq, handle, sg_src);
  980. }
  981. static int qcedev_hash_final(struct qcedev_async_req *areq,
  982. struct qcedev_handle *handle)
  983. {
  984. if ((areq->sha_op_req.alg == QCEDEV_ALG_SHA1) ||
  985. (areq->sha_op_req.alg == QCEDEV_ALG_SHA256))
  986. return qcedev_sha_final(areq, handle);
  987. else
  988. return qcedev_hmac_final(areq, handle);
  989. }
  990. static int qcedev_vbuf_ablk_cipher_max_xfer(struct qcedev_async_req *areq,
  991. int *di, struct qcedev_handle *handle,
  992. uint8_t *k_align_src)
  993. {
  994. int err = 0;
  995. int i = 0;
  996. int dst_i = *di;
  997. struct scatterlist sg_src;
  998. uint32_t byteoffset = 0;
  999. uint8_t *user_src = NULL;
  1000. uint8_t *k_align_dst = k_align_src;
  1001. struct qcedev_cipher_op_req *creq = &areq->cipher_op_req;
  1002. if (areq->cipher_op_req.mode == QCEDEV_AES_MODE_CTR)
  1003. byteoffset = areq->cipher_op_req.byteoffset;
  1004. user_src = areq->cipher_op_req.vbuf.src[0].vaddr;
  1005. if (user_src && copy_from_user((k_align_src + byteoffset),
  1006. (void __user *)user_src,
  1007. areq->cipher_op_req.vbuf.src[0].len))
  1008. return -EFAULT;
  1009. k_align_src += byteoffset + areq->cipher_op_req.vbuf.src[0].len;
  1010. for (i = 1; i < areq->cipher_op_req.entries; i++) {
  1011. user_src = areq->cipher_op_req.vbuf.src[i].vaddr;
  1012. if (user_src && copy_from_user(k_align_src,
  1013. (void __user *)user_src,
  1014. areq->cipher_op_req.vbuf.src[i].len)) {
  1015. return -EFAULT;
  1016. }
  1017. k_align_src += areq->cipher_op_req.vbuf.src[i].len;
  1018. }
  1019. /* restore src beginning */
  1020. k_align_src = k_align_dst;
  1021. areq->cipher_op_req.data_len += byteoffset;
  1022. areq->cipher_req.creq.src = (struct scatterlist *) &sg_src;
  1023. areq->cipher_req.creq.dst = (struct scatterlist *) &sg_src;
  1024. /* In place encryption/decryption */
  1025. sg_init_one(areq->cipher_req.creq.src,
  1026. k_align_dst,
  1027. areq->cipher_op_req.data_len);
  1028. areq->cipher_req.creq.cryptlen = areq->cipher_op_req.data_len;
  1029. areq->cipher_req.creq.iv = areq->cipher_op_req.iv;
  1030. areq->cipher_op_req.entries = 1;
  1031. err = submit_req(areq, handle);
  1032. /* copy data to destination buffer*/
  1033. creq->data_len -= byteoffset;
  1034. while (creq->data_len > 0) {
  1035. if (creq->vbuf.dst[dst_i].len <= creq->data_len) {
  1036. if (err == 0 && copy_to_user(
  1037. (void __user *)creq->vbuf.dst[dst_i].vaddr,
  1038. (k_align_dst + byteoffset),
  1039. creq->vbuf.dst[dst_i].len)) {
  1040. err = -EFAULT;
  1041. goto exit;
  1042. }
  1043. k_align_dst += creq->vbuf.dst[dst_i].len;
  1044. creq->data_len -= creq->vbuf.dst[dst_i].len;
  1045. dst_i++;
  1046. } else {
  1047. if (err == 0 && copy_to_user(
  1048. (void __user *)creq->vbuf.dst[dst_i].vaddr,
  1049. (k_align_dst + byteoffset),
  1050. creq->data_len)) {
  1051. err = -EFAULT;
  1052. goto exit;
  1053. }
  1054. k_align_dst += creq->data_len;
  1055. creq->vbuf.dst[dst_i].len -= creq->data_len;
  1056. creq->vbuf.dst[dst_i].vaddr += creq->data_len;
  1057. creq->data_len = 0;
  1058. }
  1059. }
  1060. *di = dst_i;
  1061. exit:
  1062. areq->cipher_req.creq.src = NULL;
  1063. areq->cipher_req.creq.dst = NULL;
  1064. return err;
  1065. };
  1066. static int qcedev_vbuf_ablk_cipher(struct qcedev_async_req *areq,
  1067. struct qcedev_handle *handle)
  1068. {
  1069. int err = 0;
  1070. int di = 0;
  1071. int i = 0;
  1072. int j = 0;
  1073. int k = 0;
  1074. uint32_t byteoffset = 0;
  1075. int num_entries = 0;
  1076. uint32_t total = 0;
  1077. uint32_t len;
  1078. uint8_t *k_buf_src = NULL;
  1079. uint8_t *k_align_src = NULL;
  1080. uint32_t max_data_xfer;
  1081. struct qcedev_cipher_op_req *saved_req;
  1082. struct qcedev_cipher_op_req *creq = &areq->cipher_op_req;
  1083. total = 0;
  1084. if (areq->cipher_op_req.mode == QCEDEV_AES_MODE_CTR)
  1085. byteoffset = areq->cipher_op_req.byteoffset;
  1086. k_buf_src = kmalloc(QCE_MAX_OPER_DATA + CACHE_LINE_SIZE * 2,
  1087. GFP_KERNEL);
  1088. if (k_buf_src == NULL)
  1089. return -ENOMEM;
  1090. k_align_src = (uint8_t *)ALIGN(((uintptr_t)k_buf_src),
  1091. CACHE_LINE_SIZE);
  1092. max_data_xfer = QCE_MAX_OPER_DATA - byteoffset;
  1093. saved_req = kmemdup(creq, sizeof(struct qcedev_cipher_op_req),
  1094. GFP_KERNEL);
  1095. if (saved_req == NULL) {
  1096. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  1097. kfree(k_buf_src);
  1098. return -ENOMEM;
  1099. }
  1100. if (areq->cipher_op_req.data_len > max_data_xfer) {
  1101. struct qcedev_cipher_op_req req;
  1102. /* save the original req structure */
  1103. memcpy(&req, creq, sizeof(struct qcedev_cipher_op_req));
  1104. i = 0;
  1105. /* Address 32 KB at a time */
  1106. while ((i < req.entries) && (err == 0)) {
  1107. if (creq->vbuf.src[i].len > max_data_xfer) {
  1108. creq->vbuf.src[0].len = max_data_xfer;
  1109. if (i > 0) {
  1110. creq->vbuf.src[0].vaddr =
  1111. creq->vbuf.src[i].vaddr;
  1112. }
  1113. creq->data_len = max_data_xfer;
  1114. creq->entries = 1;
  1115. err = qcedev_vbuf_ablk_cipher_max_xfer(areq,
  1116. &di, handle, k_align_src);
  1117. if (err < 0) {
  1118. memset(saved_req, 0,
  1119. ksize((void *)saved_req));
  1120. memset(k_buf_src, 0,
  1121. ksize((void *)k_buf_src));
  1122. kfree(k_buf_src);
  1123. kfree(saved_req);
  1124. return err;
  1125. }
  1126. creq->vbuf.src[i].len = req.vbuf.src[i].len -
  1127. max_data_xfer;
  1128. creq->vbuf.src[i].vaddr =
  1129. req.vbuf.src[i].vaddr +
  1130. max_data_xfer;
  1131. req.vbuf.src[i].vaddr =
  1132. creq->vbuf.src[i].vaddr;
  1133. req.vbuf.src[i].len = creq->vbuf.src[i].len;
  1134. } else {
  1135. total = areq->cipher_op_req.byteoffset;
  1136. for (j = i; j < req.entries; j++) {
  1137. num_entries++;
  1138. if ((total + creq->vbuf.src[j].len)
  1139. >= max_data_xfer) {
  1140. creq->vbuf.src[j].len =
  1141. max_data_xfer - total;
  1142. total = max_data_xfer;
  1143. break;
  1144. }
  1145. total += creq->vbuf.src[j].len;
  1146. }
  1147. creq->data_len = total;
  1148. if (i > 0)
  1149. for (k = 0; k < num_entries; k++) {
  1150. creq->vbuf.src[k].len =
  1151. creq->vbuf.src[i+k].len;
  1152. creq->vbuf.src[k].vaddr =
  1153. creq->vbuf.src[i+k].vaddr;
  1154. }
  1155. creq->entries = num_entries;
  1156. i = j;
  1157. err = qcedev_vbuf_ablk_cipher_max_xfer(areq,
  1158. &di, handle, k_align_src);
  1159. if (err < 0) {
  1160. memset(saved_req, 0,
  1161. ksize((void *)saved_req));
  1162. memset(k_buf_src, 0,
  1163. ksize((void *)k_buf_src));
  1164. kfree(k_buf_src);
  1165. kfree(saved_req);
  1166. return err;
  1167. }
  1168. num_entries = 0;
  1169. areq->cipher_op_req.byteoffset = 0;
  1170. creq->vbuf.src[i].vaddr = req.vbuf.src[i].vaddr
  1171. + creq->vbuf.src[i].len;
  1172. creq->vbuf.src[i].len = req.vbuf.src[i].len -
  1173. creq->vbuf.src[i].len;
  1174. req.vbuf.src[i].vaddr =
  1175. creq->vbuf.src[i].vaddr;
  1176. req.vbuf.src[i].len = creq->vbuf.src[i].len;
  1177. if (creq->vbuf.src[i].len == 0)
  1178. i++;
  1179. }
  1180. areq->cipher_op_req.byteoffset = 0;
  1181. max_data_xfer = QCE_MAX_OPER_DATA;
  1182. byteoffset = 0;
  1183. } /* end of while ((i < req.entries) && (err == 0)) */
  1184. } else
  1185. err = qcedev_vbuf_ablk_cipher_max_xfer(areq, &di, handle,
  1186. k_align_src);
  1187. /* Restore the original req structure */
  1188. for (i = 0; i < saved_req->entries; i++) {
  1189. creq->vbuf.src[i].len = saved_req->vbuf.src[i].len;
  1190. creq->vbuf.src[i].vaddr = saved_req->vbuf.src[i].vaddr;
  1191. }
  1192. for (len = 0, i = 0; len < saved_req->data_len; i++) {
  1193. creq->vbuf.dst[i].len = saved_req->vbuf.dst[i].len;
  1194. creq->vbuf.dst[i].vaddr = saved_req->vbuf.dst[i].vaddr;
  1195. len += saved_req->vbuf.dst[i].len;
  1196. }
  1197. creq->entries = saved_req->entries;
  1198. creq->data_len = saved_req->data_len;
  1199. creq->byteoffset = saved_req->byteoffset;
  1200. memset(saved_req, 0, ksize((void *)saved_req));
  1201. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  1202. kfree(saved_req);
  1203. kfree(k_buf_src);
  1204. return err;
  1205. }
  1206. static int qcedev_check_cipher_key(struct qcedev_cipher_op_req *req,
  1207. struct qcedev_control *podev)
  1208. {
  1209. /* if intending to use HW key make sure key fields are set
  1210. * correctly and HW key is indeed supported in target
  1211. */
  1212. if (req->encklen == 0) {
  1213. int i;
  1214. for (i = 0; i < QCEDEV_MAX_KEY_SIZE; i++) {
  1215. if (req->enckey[i]) {
  1216. pr_err("%s: Invalid key: non-zero key input\n",
  1217. __func__);
  1218. goto error;
  1219. }
  1220. }
  1221. if ((req->op != QCEDEV_OPER_ENC_NO_KEY) &&
  1222. (req->op != QCEDEV_OPER_DEC_NO_KEY))
  1223. if (!podev->platform_support.hw_key_support) {
  1224. pr_err("%s: Invalid op %d\n", __func__,
  1225. (uint32_t)req->op);
  1226. goto error;
  1227. }
  1228. } else {
  1229. if (req->encklen == QCEDEV_AES_KEY_192) {
  1230. if (!podev->ce_support.aes_key_192) {
  1231. pr_err("%s: AES-192 not supported\n", __func__);
  1232. goto error;
  1233. }
  1234. } else {
  1235. /* if not using HW key make sure key
  1236. * length is valid
  1237. */
  1238. if (req->mode == QCEDEV_AES_MODE_XTS) {
  1239. if ((req->encklen != QCEDEV_AES_KEY_128*2) &&
  1240. (req->encklen != QCEDEV_AES_KEY_256*2)) {
  1241. pr_err("%s: unsupported key size: %d\n",
  1242. __func__, req->encklen);
  1243. goto error;
  1244. }
  1245. } else {
  1246. if ((req->encklen != QCEDEV_AES_KEY_128) &&
  1247. (req->encklen != QCEDEV_AES_KEY_256)) {
  1248. pr_err("%s: unsupported key size %d\n",
  1249. __func__, req->encklen);
  1250. goto error;
  1251. }
  1252. }
  1253. }
  1254. }
  1255. return 0;
  1256. error:
  1257. return -EINVAL;
  1258. }
  1259. static int qcedev_check_cipher_params(struct qcedev_cipher_op_req *req,
  1260. struct qcedev_control *podev)
  1261. {
  1262. uint32_t total = 0;
  1263. uint32_t i;
  1264. if (req->use_pmem) {
  1265. pr_err("%s: Use of PMEM is not supported\n", __func__);
  1266. goto error;
  1267. }
  1268. if ((req->entries == 0) || (req->data_len == 0) ||
  1269. (req->entries > QCEDEV_MAX_BUFFERS)) {
  1270. pr_err("%s: Invalid cipher length/entries\n", __func__);
  1271. goto error;
  1272. }
  1273. if ((req->alg >= QCEDEV_ALG_LAST) ||
  1274. (req->mode >= QCEDEV_AES_DES_MODE_LAST)) {
  1275. pr_err("%s: Invalid algorithm %d\n", __func__,
  1276. (uint32_t)req->alg);
  1277. goto error;
  1278. }
  1279. if ((req->mode == QCEDEV_AES_MODE_XTS) &&
  1280. (!podev->ce_support.aes_xts)) {
  1281. pr_err("%s: XTS algorithm is not supported\n", __func__);
  1282. goto error;
  1283. }
  1284. if (req->alg == QCEDEV_ALG_AES) {
  1285. if (qcedev_check_cipher_key(req, podev))
  1286. goto error;
  1287. }
  1288. /* if using a byteoffset, make sure it is CTR mode using vbuf */
  1289. if (req->byteoffset) {
  1290. if (req->mode != QCEDEV_AES_MODE_CTR) {
  1291. pr_err("%s: Operation on byte offset not supported\n",
  1292. __func__);
  1293. goto error;
  1294. }
  1295. if (req->byteoffset >= AES_CE_BLOCK_SIZE) {
  1296. pr_err("%s: Invalid byte offset\n", __func__);
  1297. goto error;
  1298. }
  1299. total = req->byteoffset;
  1300. for (i = 0; i < req->entries; i++) {
  1301. if (total > U32_MAX - req->vbuf.src[i].len) {
  1302. pr_err("%s:Integer overflow on total src len\n",
  1303. __func__);
  1304. goto error;
  1305. }
  1306. total += req->vbuf.src[i].len;
  1307. }
  1308. }
  1309. if (req->data_len < req->byteoffset) {
  1310. pr_err("%s: req data length %u is less than byteoffset %u\n",
  1311. __func__, req->data_len, req->byteoffset);
  1312. goto error;
  1313. }
  1314. /* Ensure IV size */
  1315. if (req->ivlen > QCEDEV_MAX_IV_SIZE) {
  1316. pr_err("%s: ivlen is not correct: %u\n", __func__, req->ivlen);
  1317. goto error;
  1318. }
  1319. /* Ensure Key size */
  1320. if (req->encklen > QCEDEV_MAX_KEY_SIZE) {
  1321. pr_err("%s: Klen is not correct: %u\n", __func__, req->encklen);
  1322. goto error;
  1323. }
  1324. /* Ensure zer ivlen for ECB mode */
  1325. if (req->ivlen > 0) {
  1326. if ((req->mode == QCEDEV_AES_MODE_ECB) ||
  1327. (req->mode == QCEDEV_DES_MODE_ECB)) {
  1328. pr_err("%s: Expecting a zero length IV\n", __func__);
  1329. goto error;
  1330. }
  1331. } else {
  1332. if ((req->mode != QCEDEV_AES_MODE_ECB) &&
  1333. (req->mode != QCEDEV_DES_MODE_ECB)) {
  1334. pr_err("%s: Expecting a non-zero ength IV\n", __func__);
  1335. goto error;
  1336. }
  1337. }
  1338. /* Check for sum of all dst length is equal to data_len */
  1339. for (i = 0, total = 0; i < req->entries; i++) {
  1340. if (!req->vbuf.dst[i].vaddr && req->vbuf.dst[i].len) {
  1341. pr_err("%s: NULL req dst vbuf[%d] with length %d\n",
  1342. __func__, i, req->vbuf.dst[i].len);
  1343. goto error;
  1344. }
  1345. if (req->vbuf.dst[i].len >= U32_MAX - total) {
  1346. pr_err("%s: Integer overflow on total req dst vbuf length\n",
  1347. __func__);
  1348. goto error;
  1349. }
  1350. total += req->vbuf.dst[i].len;
  1351. }
  1352. if (total != req->data_len) {
  1353. pr_err("%s: Total (i=%d) dst(%d) buf size != data_len (%d)\n",
  1354. __func__, i, total, req->data_len);
  1355. goto error;
  1356. }
  1357. /* Check for sum of all src length is equal to data_len */
  1358. for (i = 0, total = 0; i < req->entries; i++) {
  1359. if (!req->vbuf.src[i].vaddr && req->vbuf.src[i].len) {
  1360. pr_err("%s: NULL req src vbuf[%d] with length %d\n",
  1361. __func__, i, req->vbuf.src[i].len);
  1362. goto error;
  1363. }
  1364. if (req->vbuf.src[i].len > U32_MAX - total) {
  1365. pr_err("%s: Integer overflow on total req src vbuf length\n",
  1366. __func__);
  1367. goto error;
  1368. }
  1369. total += req->vbuf.src[i].len;
  1370. }
  1371. if (total != req->data_len) {
  1372. pr_err("%s: Total src(%d) buf size != data_len (%d)\n",
  1373. __func__, total, req->data_len);
  1374. goto error;
  1375. }
  1376. return 0;
  1377. error:
  1378. return -EINVAL;
  1379. }
  1380. static int qcedev_check_sha_params(struct qcedev_sha_op_req *req,
  1381. struct qcedev_control *podev)
  1382. {
  1383. uint32_t total = 0;
  1384. uint32_t i;
  1385. if ((req->alg == QCEDEV_ALG_AES_CMAC) &&
  1386. (!podev->ce_support.cmac)) {
  1387. pr_err("%s: CMAC not supported\n", __func__);
  1388. goto sha_error;
  1389. }
  1390. if ((!req->entries) || (req->entries > QCEDEV_MAX_BUFFERS)) {
  1391. pr_err("%s: Invalid num entries (%d)\n",
  1392. __func__, req->entries);
  1393. goto sha_error;
  1394. }
  1395. if (req->alg >= QCEDEV_ALG_SHA_ALG_LAST) {
  1396. pr_err("%s: Invalid algorithm (%d)\n", __func__, req->alg);
  1397. goto sha_error;
  1398. }
  1399. if ((req->alg == QCEDEV_ALG_SHA1_HMAC) ||
  1400. (req->alg == QCEDEV_ALG_SHA256_HMAC)) {
  1401. if (req->authkey == NULL) {
  1402. pr_err("%s: Invalid authkey pointer\n", __func__);
  1403. goto sha_error;
  1404. }
  1405. if (req->authklen <= 0) {
  1406. pr_err("%s: Invalid authkey length (%d)\n",
  1407. __func__, req->authklen);
  1408. goto sha_error;
  1409. }
  1410. }
  1411. if (req->alg == QCEDEV_ALG_AES_CMAC) {
  1412. if ((req->authklen != QCEDEV_AES_KEY_128) &&
  1413. (req->authklen != QCEDEV_AES_KEY_256)) {
  1414. pr_err("%s: unsupported key length\n", __func__);
  1415. goto sha_error;
  1416. }
  1417. }
  1418. /* Check for sum of all src length is equal to data_len */
  1419. for (i = 0, total = 0; i < req->entries; i++) {
  1420. if (req->data[i].len > U32_MAX - total) {
  1421. pr_err("%s: Integer overflow on total req buf length\n",
  1422. __func__);
  1423. goto sha_error;
  1424. }
  1425. total += req->data[i].len;
  1426. }
  1427. if (total != req->data_len) {
  1428. pr_err("%s: Total src(%d) buf size != data_len (%d)\n",
  1429. __func__, total, req->data_len);
  1430. goto sha_error;
  1431. }
  1432. return 0;
  1433. sha_error:
  1434. return -EINVAL;
  1435. }
  1436. long qcedev_ioctl(struct file *file,
  1437. unsigned int cmd, unsigned long arg)
  1438. {
  1439. int err = 0;
  1440. struct qcedev_handle *handle;
  1441. struct qcedev_control *podev;
  1442. struct qcedev_async_req *qcedev_areq;
  1443. struct qcedev_stat *pstat;
  1444. qcedev_areq = kzalloc(sizeof(struct qcedev_async_req), GFP_KERNEL);
  1445. if (!qcedev_areq)
  1446. return -ENOMEM;
  1447. handle = file->private_data;
  1448. podev = handle->cntl;
  1449. qcedev_areq->handle = handle;
  1450. if (podev == NULL || podev->magic != QCEDEV_MAGIC) {
  1451. pr_err("%s: invalid handle %pK\n",
  1452. __func__, podev);
  1453. err = -ENOENT;
  1454. goto exit_free_qcedev_areq;
  1455. }
  1456. /* Verify user arguments. */
  1457. if (_IOC_TYPE(cmd) != QCEDEV_IOC_MAGIC) {
  1458. err = -ENOTTY;
  1459. goto exit_free_qcedev_areq;
  1460. }
  1461. init_completion(&qcedev_areq->complete);
  1462. pstat = &_qcedev_stat;
  1463. if (cmd != QCEDEV_IOCTL_MAP_BUF_REQ &&
  1464. cmd != QCEDEV_IOCTL_UNMAP_BUF_REQ)
  1465. qcedev_ce_high_bw_req(podev, true);
  1466. switch (cmd) {
  1467. case QCEDEV_IOCTL_ENC_REQ:
  1468. case QCEDEV_IOCTL_DEC_REQ:
  1469. if (copy_from_user(&qcedev_areq->cipher_op_req,
  1470. (void __user *)arg,
  1471. sizeof(struct qcedev_cipher_op_req))) {
  1472. err = -EFAULT;
  1473. goto exit_free_qcedev_areq;
  1474. }
  1475. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_CIPHER;
  1476. if (qcedev_check_cipher_params(&qcedev_areq->cipher_op_req,
  1477. podev)) {
  1478. err = -EINVAL;
  1479. goto exit_free_qcedev_areq;
  1480. }
  1481. err = qcedev_vbuf_ablk_cipher(qcedev_areq, handle);
  1482. if (err)
  1483. goto exit_free_qcedev_areq;
  1484. if (copy_to_user((void __user *)arg,
  1485. &qcedev_areq->cipher_op_req,
  1486. sizeof(struct qcedev_cipher_op_req))) {
  1487. err = -EFAULT;
  1488. goto exit_free_qcedev_areq;
  1489. }
  1490. break;
  1491. case QCEDEV_IOCTL_SHA_INIT_REQ:
  1492. {
  1493. struct scatterlist sg_src;
  1494. if (copy_from_user(&qcedev_areq->sha_op_req,
  1495. (void __user *)arg,
  1496. sizeof(struct qcedev_sha_op_req))) {
  1497. err = -EFAULT;
  1498. goto exit_free_qcedev_areq;
  1499. }
  1500. mutex_lock(&hash_access_lock);
  1501. if (qcedev_check_sha_params(&qcedev_areq->sha_op_req, podev)) {
  1502. mutex_unlock(&hash_access_lock);
  1503. err = -EINVAL;
  1504. goto exit_free_qcedev_areq;
  1505. }
  1506. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_SHA;
  1507. err = qcedev_hash_init(qcedev_areq, handle, &sg_src);
  1508. if (err) {
  1509. mutex_unlock(&hash_access_lock);
  1510. goto exit_free_qcedev_areq;
  1511. }
  1512. mutex_unlock(&hash_access_lock);
  1513. if (copy_to_user((void __user *)arg, &qcedev_areq->sha_op_req,
  1514. sizeof(struct qcedev_sha_op_req))) {
  1515. err = -EFAULT;
  1516. goto exit_free_qcedev_areq;
  1517. }
  1518. handle->sha_ctxt.init_done = true;
  1519. }
  1520. break;
  1521. case QCEDEV_IOCTL_GET_CMAC_REQ:
  1522. if (!podev->ce_support.cmac) {
  1523. err = -ENOTTY;
  1524. goto exit_free_qcedev_areq;
  1525. }
  1526. /* Fall-through */
  1527. case QCEDEV_IOCTL_SHA_UPDATE_REQ:
  1528. {
  1529. struct scatterlist sg_src;
  1530. if (copy_from_user(&qcedev_areq->sha_op_req,
  1531. (void __user *)arg,
  1532. sizeof(struct qcedev_sha_op_req))) {
  1533. err = -EFAULT;
  1534. goto exit_free_qcedev_areq;
  1535. }
  1536. mutex_lock(&hash_access_lock);
  1537. if (qcedev_check_sha_params(&qcedev_areq->sha_op_req, podev)) {
  1538. mutex_unlock(&hash_access_lock);
  1539. err = -EINVAL;
  1540. goto exit_free_qcedev_areq;
  1541. }
  1542. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_SHA;
  1543. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_AES_CMAC) {
  1544. err = qcedev_hash_cmac(qcedev_areq, handle, &sg_src);
  1545. if (err) {
  1546. mutex_unlock(&hash_access_lock);
  1547. goto exit_free_qcedev_areq;
  1548. }
  1549. } else {
  1550. if (!handle->sha_ctxt.init_done) {
  1551. pr_err("%s Init was not called\n", __func__);
  1552. mutex_unlock(&hash_access_lock);
  1553. err = -EINVAL;
  1554. goto exit_free_qcedev_areq;
  1555. }
  1556. err = qcedev_hash_update(qcedev_areq, handle, &sg_src);
  1557. if (err) {
  1558. mutex_unlock(&hash_access_lock);
  1559. goto exit_free_qcedev_areq;
  1560. }
  1561. }
  1562. if (handle->sha_ctxt.diglen > QCEDEV_MAX_SHA_DIGEST) {
  1563. pr_err("Invalid sha_ctxt.diglen %d\n",
  1564. handle->sha_ctxt.diglen);
  1565. mutex_unlock(&hash_access_lock);
  1566. err = -EINVAL;
  1567. goto exit_free_qcedev_areq;
  1568. }
  1569. memcpy(&qcedev_areq->sha_op_req.digest[0],
  1570. &handle->sha_ctxt.digest[0],
  1571. handle->sha_ctxt.diglen);
  1572. mutex_unlock(&hash_access_lock);
  1573. if (copy_to_user((void __user *)arg, &qcedev_areq->sha_op_req,
  1574. sizeof(struct qcedev_sha_op_req))) {
  1575. err = -EFAULT;
  1576. goto exit_free_qcedev_areq;
  1577. }
  1578. }
  1579. break;
  1580. case QCEDEV_IOCTL_SHA_FINAL_REQ:
  1581. if (!handle->sha_ctxt.init_done) {
  1582. pr_err("%s Init was not called\n", __func__);
  1583. err = -EINVAL;
  1584. goto exit_free_qcedev_areq;
  1585. }
  1586. if (copy_from_user(&qcedev_areq->sha_op_req,
  1587. (void __user *)arg,
  1588. sizeof(struct qcedev_sha_op_req))) {
  1589. err = -EFAULT;
  1590. goto exit_free_qcedev_areq;
  1591. }
  1592. mutex_lock(&hash_access_lock);
  1593. if (qcedev_check_sha_params(&qcedev_areq->sha_op_req, podev)) {
  1594. mutex_unlock(&hash_access_lock);
  1595. err = -EINVAL;
  1596. goto exit_free_qcedev_areq;
  1597. }
  1598. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_SHA;
  1599. err = qcedev_hash_final(qcedev_areq, handle);
  1600. if (err) {
  1601. mutex_unlock(&hash_access_lock);
  1602. goto exit_free_qcedev_areq;
  1603. }
  1604. if (handle->sha_ctxt.diglen > QCEDEV_MAX_SHA_DIGEST) {
  1605. pr_err("Invalid sha_ctxt.diglen %d\n",
  1606. handle->sha_ctxt.diglen);
  1607. mutex_unlock(&hash_access_lock);
  1608. err = -EINVAL;
  1609. goto exit_free_qcedev_areq;
  1610. }
  1611. qcedev_areq->sha_op_req.diglen = handle->sha_ctxt.diglen;
  1612. memcpy(&qcedev_areq->sha_op_req.digest[0],
  1613. &handle->sha_ctxt.digest[0],
  1614. handle->sha_ctxt.diglen);
  1615. mutex_unlock(&hash_access_lock);
  1616. if (copy_to_user((void __user *)arg, &qcedev_areq->sha_op_req,
  1617. sizeof(struct qcedev_sha_op_req))) {
  1618. err = -EFAULT;
  1619. goto exit_free_qcedev_areq;
  1620. }
  1621. handle->sha_ctxt.init_done = false;
  1622. break;
  1623. case QCEDEV_IOCTL_GET_SHA_REQ:
  1624. {
  1625. struct scatterlist sg_src;
  1626. if (copy_from_user(&qcedev_areq->sha_op_req,
  1627. (void __user *)arg,
  1628. sizeof(struct qcedev_sha_op_req))) {
  1629. err = -EFAULT;
  1630. goto exit_free_qcedev_areq;
  1631. }
  1632. mutex_lock(&hash_access_lock);
  1633. if (qcedev_check_sha_params(&qcedev_areq->sha_op_req, podev)) {
  1634. mutex_unlock(&hash_access_lock);
  1635. err = -EINVAL;
  1636. goto exit_free_qcedev_areq;
  1637. }
  1638. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_SHA;
  1639. qcedev_hash_init(qcedev_areq, handle, &sg_src);
  1640. err = qcedev_hash_update(qcedev_areq, handle, &sg_src);
  1641. if (err) {
  1642. mutex_unlock(&hash_access_lock);
  1643. goto exit_free_qcedev_areq;
  1644. }
  1645. err = qcedev_hash_final(qcedev_areq, handle);
  1646. if (err) {
  1647. mutex_unlock(&hash_access_lock);
  1648. goto exit_free_qcedev_areq;
  1649. }
  1650. if (handle->sha_ctxt.diglen > QCEDEV_MAX_SHA_DIGEST) {
  1651. pr_err("Invalid sha_ctxt.diglen %d\n",
  1652. handle->sha_ctxt.diglen);
  1653. mutex_unlock(&hash_access_lock);
  1654. err = -EINVAL;
  1655. goto exit_free_qcedev_areq;
  1656. }
  1657. qcedev_areq->sha_op_req.diglen = handle->sha_ctxt.diglen;
  1658. memcpy(&qcedev_areq->sha_op_req.digest[0],
  1659. &handle->sha_ctxt.digest[0],
  1660. handle->sha_ctxt.diglen);
  1661. mutex_unlock(&hash_access_lock);
  1662. if (copy_to_user((void __user *)arg, &qcedev_areq->sha_op_req,
  1663. sizeof(struct qcedev_sha_op_req))) {
  1664. err = -EFAULT;
  1665. goto exit_free_qcedev_areq;
  1666. }
  1667. }
  1668. break;
  1669. case QCEDEV_IOCTL_MAP_BUF_REQ:
  1670. {
  1671. unsigned long long vaddr = 0;
  1672. struct qcedev_map_buf_req map_buf = { {0} };
  1673. int i = 0;
  1674. if (copy_from_user(&map_buf,
  1675. (void __user *)arg, sizeof(map_buf))) {
  1676. err = -EFAULT;
  1677. goto exit_free_qcedev_areq;
  1678. }
  1679. if (map_buf.num_fds > QCEDEV_MAX_BUFFERS) {
  1680. err = -EINVAL;
  1681. goto exit_free_qcedev_areq;
  1682. }
  1683. for (i = 0; i < map_buf.num_fds; i++) {
  1684. err = qcedev_check_and_map_buffer(handle,
  1685. map_buf.fd[i],
  1686. map_buf.fd_offset[i],
  1687. map_buf.fd_size[i],
  1688. &vaddr);
  1689. if (err) {
  1690. pr_err(
  1691. "%s: err: failed to map fd(%d) - %d\n",
  1692. __func__, map_buf.fd[i], err);
  1693. goto exit_free_qcedev_areq;
  1694. }
  1695. map_buf.buf_vaddr[i] = vaddr;
  1696. pr_info("%s: info: vaddr = %llx\n",
  1697. __func__, vaddr);
  1698. }
  1699. if (copy_to_user((void __user *)arg, &map_buf,
  1700. sizeof(map_buf))) {
  1701. err = -EFAULT;
  1702. goto exit_free_qcedev_areq;
  1703. }
  1704. break;
  1705. }
  1706. case QCEDEV_IOCTL_UNMAP_BUF_REQ:
  1707. {
  1708. struct qcedev_unmap_buf_req unmap_buf = { { 0 } };
  1709. int i = 0;
  1710. if (copy_from_user(&unmap_buf,
  1711. (void __user *)arg, sizeof(unmap_buf))) {
  1712. err = -EFAULT;
  1713. goto exit_free_qcedev_areq;
  1714. }
  1715. for (i = 0; i < unmap_buf.num_fds; i++) {
  1716. err = qcedev_check_and_unmap_buffer(handle,
  1717. unmap_buf.fd[i]);
  1718. if (err) {
  1719. pr_err(
  1720. "%s: err: failed to unmap fd(%d) - %d\n",
  1721. __func__,
  1722. unmap_buf.fd[i], err);
  1723. goto exit_free_qcedev_areq;
  1724. }
  1725. }
  1726. break;
  1727. }
  1728. default:
  1729. err = -ENOTTY;
  1730. goto exit_free_qcedev_areq;
  1731. }
  1732. exit_free_qcedev_areq:
  1733. if (cmd != QCEDEV_IOCTL_MAP_BUF_REQ &&
  1734. cmd != QCEDEV_IOCTL_UNMAP_BUF_REQ && podev != NULL)
  1735. qcedev_ce_high_bw_req(podev, false);
  1736. kfree(qcedev_areq);
  1737. return err;
  1738. }
  1739. static int qcedev_probe_device(struct platform_device *pdev)
  1740. {
  1741. void *handle = NULL;
  1742. int rc = 0;
  1743. struct qcedev_control *podev;
  1744. struct msm_ce_hw_support *platform_support;
  1745. podev = &qce_dev[0];
  1746. rc = alloc_chrdev_region(&qcedev_device_no, 0, 1, QCEDEV_DEV);
  1747. if (rc < 0) {
  1748. pr_err("alloc_chrdev_region failed %d\n", rc);
  1749. return rc;
  1750. }
  1751. driver_class = class_create(THIS_MODULE, QCEDEV_DEV);
  1752. if (IS_ERR(driver_class)) {
  1753. rc = -ENOMEM;
  1754. pr_err("class_create failed %d\n", rc);
  1755. goto exit_unreg_chrdev_region;
  1756. }
  1757. class_dev = device_create(driver_class, NULL, qcedev_device_no, NULL,
  1758. QCEDEV_DEV);
  1759. if (IS_ERR(class_dev)) {
  1760. pr_err("class_device_create failed %d\n", rc);
  1761. rc = -ENOMEM;
  1762. goto exit_destroy_class;
  1763. }
  1764. cdev_init(&podev->cdev, &qcedev_fops);
  1765. podev->cdev.owner = THIS_MODULE;
  1766. rc = cdev_add(&podev->cdev, MKDEV(MAJOR(qcedev_device_no), 0), 1);
  1767. if (rc < 0) {
  1768. pr_err("cdev_add failed %d\n", rc);
  1769. goto exit_destroy_device;
  1770. }
  1771. podev->minor = 0;
  1772. podev->high_bw_req_count = 0;
  1773. INIT_LIST_HEAD(&podev->ready_commands);
  1774. podev->active_command = NULL;
  1775. INIT_LIST_HEAD(&podev->context_banks);
  1776. spin_lock_init(&podev->lock);
  1777. tasklet_init(&podev->done_tasklet, req_done, (unsigned long)podev);
  1778. podev->icc_path = of_icc_get(&pdev->dev, "data_path");
  1779. if (IS_ERR(podev->icc_path)) {
  1780. rc = PTR_ERR(podev->icc_path);
  1781. pr_err("%s Failed to get icc path with error %d\n",
  1782. __func__, rc);
  1783. goto exit_del_cdev;
  1784. }
  1785. rc = icc_set_bw(podev->icc_path, CRYPTO_AVG_BW, CRYPTO_PEAK_BW);
  1786. if (rc) {
  1787. pr_err("%s Unable to set high bandwidth\n", __func__);
  1788. goto exit_unregister_bus_scale;
  1789. }
  1790. handle = qce_open(pdev, &rc);
  1791. if (handle == NULL) {
  1792. rc = -ENODEV;
  1793. goto exit_scale_busbandwidth;
  1794. }
  1795. rc = icc_set_bw(podev->icc_path, 0, 0);
  1796. if (rc) {
  1797. pr_err("%s Unable to set to low bandwidth\n", __func__);
  1798. goto exit_qce_close;
  1799. }
  1800. podev->qce = handle;
  1801. podev->pdev = pdev;
  1802. platform_set_drvdata(pdev, podev);
  1803. qce_hw_support(podev->qce, &podev->ce_support);
  1804. if (podev->ce_support.bam) {
  1805. podev->platform_support.ce_shared = 0;
  1806. podev->platform_support.shared_ce_resource = 0;
  1807. podev->platform_support.hw_key_support =
  1808. podev->ce_support.hw_key;
  1809. podev->platform_support.sha_hmac = 1;
  1810. } else {
  1811. platform_support =
  1812. (struct msm_ce_hw_support *)pdev->dev.platform_data;
  1813. podev->platform_support.ce_shared = platform_support->ce_shared;
  1814. podev->platform_support.shared_ce_resource =
  1815. platform_support->shared_ce_resource;
  1816. podev->platform_support.hw_key_support =
  1817. platform_support->hw_key_support;
  1818. podev->platform_support.sha_hmac = platform_support->sha_hmac;
  1819. }
  1820. podev->mem_client = qcedev_mem_new_client(MEM_ION);
  1821. if (!podev->mem_client) {
  1822. pr_err("%s: err: qcedev_mem_new_client failed\n", __func__);
  1823. goto exit_qce_close;
  1824. }
  1825. rc = of_platform_populate(pdev->dev.of_node, qcedev_match,
  1826. NULL, &pdev->dev);
  1827. if (rc) {
  1828. pr_err("%s: err: of_platform_populate failed: %d\n",
  1829. __func__, rc);
  1830. goto exit_mem_new_client;
  1831. }
  1832. return 0;
  1833. exit_mem_new_client:
  1834. if (podev->mem_client)
  1835. qcedev_mem_delete_client(podev->mem_client);
  1836. podev->mem_client = NULL;
  1837. exit_qce_close:
  1838. if (handle)
  1839. qce_close(handle);
  1840. exit_scale_busbandwidth:
  1841. icc_set_bw(podev->icc_path, 0, 0);
  1842. exit_unregister_bus_scale:
  1843. if (podev->icc_path)
  1844. icc_put(podev->icc_path);
  1845. exit_del_cdev:
  1846. cdev_del(&podev->cdev);
  1847. exit_destroy_device:
  1848. device_destroy(driver_class, qcedev_device_no);
  1849. exit_destroy_class:
  1850. class_destroy(driver_class);
  1851. exit_unreg_chrdev_region:
  1852. unregister_chrdev_region(qcedev_device_no, 1);
  1853. podev->icc_path = NULL;
  1854. platform_set_drvdata(pdev, NULL);
  1855. podev->pdev = NULL;
  1856. podev->qce = NULL;
  1857. return rc;
  1858. }
  1859. static int qcedev_probe(struct platform_device *pdev)
  1860. {
  1861. if (of_device_is_compatible(pdev->dev.of_node, "qcom,qcedev"))
  1862. return qcedev_probe_device(pdev);
  1863. else if (of_device_is_compatible(pdev->dev.of_node,
  1864. "qcom,qcedev,context-bank"))
  1865. return qcedev_parse_context_bank(pdev);
  1866. return -EINVAL;
  1867. };
  1868. static int qcedev_remove(struct platform_device *pdev)
  1869. {
  1870. struct qcedev_control *podev;
  1871. podev = platform_get_drvdata(pdev);
  1872. if (!podev)
  1873. return 0;
  1874. if (podev->qce)
  1875. qce_close(podev->qce);
  1876. if (podev->icc_path)
  1877. icc_put(podev->icc_path);
  1878. tasklet_kill(&podev->done_tasklet);
  1879. cdev_del(&podev->cdev);
  1880. device_destroy(driver_class, qcedev_device_no);
  1881. class_destroy(driver_class);
  1882. unregister_chrdev_region(qcedev_device_no, 1);
  1883. return 0;
  1884. };
  1885. static int qcedev_suspend(struct platform_device *pdev, pm_message_t state)
  1886. {
  1887. struct qcedev_control *podev;
  1888. int ret;
  1889. podev = platform_get_drvdata(pdev);
  1890. if (!podev)
  1891. return 0;
  1892. mutex_lock(&qcedev_sent_bw_req);
  1893. if (podev->high_bw_req_count) {
  1894. ret = qcedev_control_clocks(podev, false);
  1895. if (ret)
  1896. goto suspend_exit;
  1897. }
  1898. suspend_exit:
  1899. mutex_unlock(&qcedev_sent_bw_req);
  1900. return 0;
  1901. }
  1902. static int qcedev_resume(struct platform_device *pdev)
  1903. {
  1904. struct qcedev_control *podev;
  1905. int ret;
  1906. podev = platform_get_drvdata(pdev);
  1907. if (!podev)
  1908. return 0;
  1909. mutex_lock(&qcedev_sent_bw_req);
  1910. if (podev->high_bw_req_count) {
  1911. ret = qcedev_control_clocks(podev, true);
  1912. if (ret)
  1913. goto resume_exit;
  1914. }
  1915. resume_exit:
  1916. mutex_unlock(&qcedev_sent_bw_req);
  1917. return 0;
  1918. }
  1919. static struct platform_driver qcedev_plat_driver = {
  1920. .probe = qcedev_probe,
  1921. .remove = qcedev_remove,
  1922. .suspend = qcedev_suspend,
  1923. .resume = qcedev_resume,
  1924. .driver = {
  1925. .name = "qce",
  1926. .of_match_table = qcedev_match,
  1927. },
  1928. };
  1929. static int _disp_stats(int id)
  1930. {
  1931. struct qcedev_stat *pstat;
  1932. int len = 0;
  1933. pstat = &_qcedev_stat;
  1934. len = scnprintf(_debug_read_buf, DEBUG_MAX_RW_BUF - 1,
  1935. "\nQTI QCE dev driver %d Statistics:\n",
  1936. id + 1);
  1937. len += scnprintf(_debug_read_buf + len, DEBUG_MAX_RW_BUF - len - 1,
  1938. " Encryption operation success : %d\n",
  1939. pstat->qcedev_enc_success);
  1940. len += scnprintf(_debug_read_buf + len, DEBUG_MAX_RW_BUF - len - 1,
  1941. " Encryption operation fail : %d\n",
  1942. pstat->qcedev_enc_fail);
  1943. len += scnprintf(_debug_read_buf + len, DEBUG_MAX_RW_BUF - len - 1,
  1944. " Decryption operation success : %d\n",
  1945. pstat->qcedev_dec_success);
  1946. len += scnprintf(_debug_read_buf + len, DEBUG_MAX_RW_BUF - len - 1,
  1947. " Encryption operation fail : %d\n",
  1948. pstat->qcedev_dec_fail);
  1949. return len;
  1950. }
  1951. static ssize_t _debug_stats_read(struct file *file, char __user *buf,
  1952. size_t count, loff_t *ppos)
  1953. {
  1954. ssize_t rc = -EINVAL;
  1955. int qcedev = *((int *) file->private_data);
  1956. int len;
  1957. len = _disp_stats(qcedev);
  1958. if (len <= count)
  1959. rc = simple_read_from_buffer((void __user *) buf, len,
  1960. ppos, (void *) _debug_read_buf, len);
  1961. return rc;
  1962. }
  1963. static ssize_t _debug_stats_write(struct file *file, const char __user *buf,
  1964. size_t count, loff_t *ppos)
  1965. {
  1966. memset((char *)&_qcedev_stat, 0, sizeof(struct qcedev_stat));
  1967. return count;
  1968. };
  1969. static const struct file_operations _debug_stats_ops = {
  1970. .open = simple_open,
  1971. .read = _debug_stats_read,
  1972. .write = _debug_stats_write,
  1973. };
  1974. static int _qcedev_debug_init(void)
  1975. {
  1976. int rc;
  1977. char name[DEBUG_MAX_FNAME];
  1978. struct dentry *dent;
  1979. _debug_dent = debugfs_create_dir("qcedev", NULL);
  1980. if (IS_ERR(_debug_dent)) {
  1981. pr_debug("qcedev debugfs_create_dir fail, error %ld\n",
  1982. PTR_ERR(_debug_dent));
  1983. return PTR_ERR(_debug_dent);
  1984. }
  1985. snprintf(name, DEBUG_MAX_FNAME-1, "stats-%d", 1);
  1986. _debug_qcedev = 0;
  1987. dent = debugfs_create_file(name, 0644, _debug_dent,
  1988. &_debug_qcedev, &_debug_stats_ops);
  1989. if (dent == NULL) {
  1990. pr_debug("qcedev debugfs_create_file fail, error %ld\n",
  1991. PTR_ERR(dent));
  1992. rc = PTR_ERR(dent);
  1993. goto err;
  1994. }
  1995. return 0;
  1996. err:
  1997. debugfs_remove_recursive(_debug_dent);
  1998. return rc;
  1999. }
  2000. static int qcedev_init(void)
  2001. {
  2002. _qcedev_debug_init();
  2003. return platform_driver_register(&qcedev_plat_driver);
  2004. }
  2005. static void qcedev_exit(void)
  2006. {
  2007. debugfs_remove_recursive(_debug_dent);
  2008. platform_driver_unregister(&qcedev_plat_driver);
  2009. }
  2010. MODULE_LICENSE("GPL v2");
  2011. MODULE_DESCRIPTION("QTI DEV Crypto driver");
  2012. module_init(qcedev_init);
  2013. module_exit(qcedev_exit);