qcedev.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847
  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 64
  34. #define CE_SHA_BLOCK_SIZE SHA256_BLOCK_SIZE
  35. #define MAX_CEHW_REQ_TRANSFER_SIZE (128*32*1024)
  36. /*
  37. * Max wait time once a crypto request is done.
  38. * Assuming 5ms per crypto operation, this is calculated for
  39. * the scenario of having 3 offload reqs + 1 tz req + buffer.
  40. */
  41. #define MAX_CRYPTO_WAIT_TIME 25
  42. #define MAX_REQUEST_TIME 5000
  43. enum qcedev_req_status {
  44. QCEDEV_REQ_CURRENT = 0,
  45. QCEDEV_REQ_WAITING = 1,
  46. QCEDEV_REQ_SUBMITTED = 2,
  47. };
  48. static uint8_t _std_init_vector_sha1_uint8[] = {
  49. 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB, 0x89,
  50. 0x98, 0xBA, 0xDC, 0xFE, 0x10, 0x32, 0x54, 0x76,
  51. 0xC3, 0xD2, 0xE1, 0xF0
  52. };
  53. /* standard initialization vector for SHA-256, source: FIPS 180-2 */
  54. static uint8_t _std_init_vector_sha256_uint8[] = {
  55. 0x6A, 0x09, 0xE6, 0x67, 0xBB, 0x67, 0xAE, 0x85,
  56. 0x3C, 0x6E, 0xF3, 0x72, 0xA5, 0x4F, 0xF5, 0x3A,
  57. 0x51, 0x0E, 0x52, 0x7F, 0x9B, 0x05, 0x68, 0x8C,
  58. 0x1F, 0x83, 0xD9, 0xAB, 0x5B, 0xE0, 0xCD, 0x19
  59. };
  60. #define QCEDEV_CTX_KEY_MASK 0x000000ff
  61. #define QCEDEV_CTX_USE_HW_KEY 0x00000001
  62. #define QCEDEV_CTX_USE_PIPE_KEY 0x00000002
  63. // Key timer expiry for pipes 1-15 (Status3)
  64. #define PIPE_KEY_TIMER_EXPIRED_STATUS3_MASK 0x000000FF
  65. // Key timer expiry for pipes 16-19 (Status6)
  66. #define PIPE_KEY_TIMER_EXPIRED_STATUS6_MASK 0x00000003
  67. // Key pause for pipes 1-15 (Status3)
  68. #define PIPE_KEY_PAUSE_STATUS3_MASK 0xFF0000
  69. // Key pause for pipes 16-19 (Status6)
  70. #define PIPE_KEY_PAUSE_STATUS6_MASK 0x30000
  71. #define QCEDEV_STATUS1_ERR_INTR_MASK 0x10
  72. static DEFINE_MUTEX(send_cmd_lock);
  73. static DEFINE_MUTEX(qcedev_sent_bw_req);
  74. static DEFINE_MUTEX(hash_access_lock);
  75. static dev_t qcedev_device_no;
  76. static struct class *driver_class;
  77. static struct device *class_dev;
  78. static const struct of_device_id qcedev_match[] = {
  79. { .compatible = "qcom,qcedev"},
  80. { .compatible = "qcom,qcedev,context-bank"},
  81. {}
  82. };
  83. MODULE_DEVICE_TABLE(of, qcedev_match);
  84. static int qcedev_control_clocks(struct qcedev_control *podev, bool enable)
  85. {
  86. unsigned int control_flag;
  87. int ret = 0;
  88. if (podev->ce_support.req_bw_before_clk) {
  89. if (enable)
  90. control_flag = QCE_BW_REQUEST_FIRST;
  91. else
  92. control_flag = QCE_CLK_DISABLE_FIRST;
  93. } else {
  94. if (enable)
  95. control_flag = QCE_CLK_ENABLE_FIRST;
  96. else
  97. control_flag = QCE_BW_REQUEST_RESET_FIRST;
  98. }
  99. switch (control_flag) {
  100. case QCE_CLK_ENABLE_FIRST:
  101. ret = qce_enable_clk(podev->qce);
  102. if (ret) {
  103. pr_err("%s Unable enable clk\n", __func__);
  104. return ret;
  105. }
  106. ret = icc_set_bw(podev->icc_path,
  107. podev->icc_avg_bw, podev->icc_peak_bw);
  108. if (ret) {
  109. pr_err("%s Unable to set high bw\n", __func__);
  110. ret = qce_disable_clk(podev->qce);
  111. if (ret)
  112. pr_err("%s Unable disable clk\n", __func__);
  113. return ret;
  114. }
  115. break;
  116. case QCE_BW_REQUEST_FIRST:
  117. ret = icc_set_bw(podev->icc_path,
  118. podev->icc_avg_bw, podev->icc_peak_bw);
  119. if (ret) {
  120. pr_err("%s Unable to set high bw\n", __func__);
  121. return ret;
  122. }
  123. ret = qce_enable_clk(podev->qce);
  124. if (ret) {
  125. pr_err("%s Unable enable clk\n", __func__);
  126. ret = icc_set_bw(podev->icc_path, 0, 0);
  127. if (ret)
  128. pr_err("%s Unable to set low bw\n", __func__);
  129. return ret;
  130. }
  131. break;
  132. case QCE_CLK_DISABLE_FIRST:
  133. ret = qce_disable_clk(podev->qce);
  134. if (ret) {
  135. pr_err("%s Unable to disable clk\n", __func__);
  136. return ret;
  137. }
  138. ret = icc_set_bw(podev->icc_path, 0, 0);
  139. if (ret) {
  140. pr_err("%s Unable to set low bw\n", __func__);
  141. ret = qce_enable_clk(podev->qce);
  142. if (ret)
  143. pr_err("%s Unable enable clk\n", __func__);
  144. return ret;
  145. }
  146. break;
  147. case QCE_BW_REQUEST_RESET_FIRST:
  148. ret = icc_set_bw(podev->icc_path, 0, 0);
  149. if (ret) {
  150. pr_err("%s Unable to set low bw\n", __func__);
  151. return ret;
  152. }
  153. ret = qce_disable_clk(podev->qce);
  154. if (ret) {
  155. pr_err("%s Unable to disable clk\n", __func__);
  156. ret = icc_set_bw(podev->icc_path,
  157. podev->icc_avg_bw, podev->icc_peak_bw);
  158. if (ret)
  159. pr_err("%s Unable to set high bw\n", __func__);
  160. return ret;
  161. }
  162. break;
  163. default:
  164. return -ENOENT;
  165. }
  166. return 0;
  167. }
  168. static void qcedev_ce_high_bw_req(struct qcedev_control *podev,
  169. bool high_bw_req)
  170. {
  171. int ret = 0;
  172. mutex_lock(&qcedev_sent_bw_req);
  173. if (high_bw_req) {
  174. if (podev->high_bw_req_count == 0) {
  175. ret = qcedev_control_clocks(podev, true);
  176. if (ret)
  177. goto exit_unlock_mutex;
  178. }
  179. podev->high_bw_req_count++;
  180. } else {
  181. if (podev->high_bw_req_count == 1) {
  182. ret = qcedev_control_clocks(podev, false);
  183. if (ret)
  184. goto exit_unlock_mutex;
  185. }
  186. podev->high_bw_req_count--;
  187. }
  188. exit_unlock_mutex:
  189. mutex_unlock(&qcedev_sent_bw_req);
  190. }
  191. #define QCEDEV_MAGIC 0x56434544 /* "qced" */
  192. static int qcedev_open(struct inode *inode, struct file *file);
  193. static int qcedev_release(struct inode *inode, struct file *file);
  194. static int start_cipher_req(struct qcedev_control *podev,
  195. int *current_req_info);
  196. static int start_offload_cipher_req(struct qcedev_control *podev,
  197. int *current_req_info);
  198. static int start_sha_req(struct qcedev_control *podev,
  199. int *current_req_info);
  200. static const struct file_operations qcedev_fops = {
  201. .owner = THIS_MODULE,
  202. .unlocked_ioctl = qcedev_ioctl,
  203. #ifdef CONFIG_COMPAT
  204. .compat_ioctl = compat_qcedev_ioctl,
  205. #endif
  206. .open = qcedev_open,
  207. .release = qcedev_release,
  208. };
  209. static struct qcedev_control qce_dev[] = {
  210. {
  211. .magic = QCEDEV_MAGIC,
  212. },
  213. };
  214. #define MAX_QCE_DEVICE ARRAY_SIZE(qce_dev)
  215. #define DEBUG_MAX_FNAME 16
  216. #define DEBUG_MAX_RW_BUF 1024
  217. struct qcedev_stat {
  218. u32 qcedev_dec_success;
  219. u32 qcedev_dec_fail;
  220. u32 qcedev_enc_success;
  221. u32 qcedev_enc_fail;
  222. u32 qcedev_sha_success;
  223. u32 qcedev_sha_fail;
  224. };
  225. static struct qcedev_stat _qcedev_stat;
  226. static struct dentry *_debug_dent;
  227. static char _debug_read_buf[DEBUG_MAX_RW_BUF];
  228. static int _debug_qcedev;
  229. static struct qcedev_control *qcedev_minor_to_control(unsigned int n)
  230. {
  231. int i;
  232. for (i = 0; i < MAX_QCE_DEVICE; i++) {
  233. if (qce_dev[i].minor == n)
  234. return &qce_dev[n];
  235. }
  236. return NULL;
  237. }
  238. static int qcedev_open(struct inode *inode, struct file *file)
  239. {
  240. struct qcedev_handle *handle;
  241. struct qcedev_control *podev;
  242. podev = qcedev_minor_to_control(MINOR(inode->i_rdev));
  243. if (podev == NULL) {
  244. pr_err("%s: no such device %d\n", __func__,
  245. MINOR(inode->i_rdev));
  246. return -ENOENT;
  247. }
  248. handle = kzalloc(sizeof(struct qcedev_handle), GFP_KERNEL);
  249. if (handle == NULL)
  250. return -ENOMEM;
  251. handle->cntl = podev;
  252. file->private_data = handle;
  253. qcedev_ce_high_bw_req(podev, true);
  254. mutex_init(&handle->registeredbufs.lock);
  255. INIT_LIST_HEAD(&handle->registeredbufs.list);
  256. return 0;
  257. }
  258. static int qcedev_release(struct inode *inode, struct file *file)
  259. {
  260. struct qcedev_control *podev;
  261. struct qcedev_handle *handle;
  262. handle = file->private_data;
  263. podev = handle->cntl;
  264. if (podev != NULL && podev->magic != QCEDEV_MAGIC) {
  265. pr_err("%s: invalid handle %pK\n",
  266. __func__, podev);
  267. }
  268. qcedev_ce_high_bw_req(podev, false);
  269. if (qcedev_unmap_all_buffers(handle))
  270. pr_err("%s: failed to unmap all ion buffers\n", __func__);
  271. kfree_sensitive(handle);
  272. file->private_data = NULL;
  273. return 0;
  274. }
  275. static void req_done(unsigned long data)
  276. {
  277. struct qcedev_control *podev = (struct qcedev_control *)data;
  278. struct qcedev_async_req *areq;
  279. unsigned long flags = 0;
  280. struct qcedev_async_req *new_req = NULL;
  281. spin_lock_irqsave(&podev->lock, flags);
  282. areq = podev->active_command;
  283. podev->active_command = NULL;
  284. if (areq && !areq->timed_out)
  285. complete(&areq->complete);
  286. /* Look through queued requests and wake up the corresponding thread */
  287. if (!list_empty(&podev->ready_commands)) {
  288. new_req = container_of(podev->ready_commands.next,
  289. struct qcedev_async_req, list);
  290. list_del(&new_req->list);
  291. new_req->state = QCEDEV_REQ_CURRENT;
  292. wake_up_interruptible(&new_req->wait_q);
  293. }
  294. spin_unlock_irqrestore(&podev->lock, flags);
  295. }
  296. void qcedev_sha_req_cb(void *cookie, unsigned char *digest,
  297. unsigned char *authdata, int ret)
  298. {
  299. struct qcedev_sha_req *areq;
  300. struct qcedev_control *pdev;
  301. struct qcedev_handle *handle;
  302. uint32_t *auth32 = (uint32_t *)authdata;
  303. areq = (struct qcedev_sha_req *) cookie;
  304. if (!areq || !areq->cookie)
  305. return;
  306. handle = (struct qcedev_handle *) areq->cookie;
  307. pdev = handle->cntl;
  308. if (!pdev)
  309. return;
  310. if (digest)
  311. memcpy(&handle->sha_ctxt.digest[0], digest, 32);
  312. if (authdata) {
  313. handle->sha_ctxt.auth_data[0] = auth32[0];
  314. handle->sha_ctxt.auth_data[1] = auth32[1];
  315. }
  316. tasklet_schedule(&pdev->done_tasklet);
  317. };
  318. void qcedev_cipher_req_cb(void *cookie, unsigned char *icv,
  319. unsigned char *iv, int ret)
  320. {
  321. struct qcedev_cipher_req *areq;
  322. struct qcedev_handle *handle;
  323. struct qcedev_control *podev;
  324. struct qcedev_async_req *qcedev_areq;
  325. areq = (struct qcedev_cipher_req *) cookie;
  326. if (!areq || !areq->cookie)
  327. return;
  328. handle = (struct qcedev_handle *) areq->cookie;
  329. podev = handle->cntl;
  330. if (!podev)
  331. return;
  332. qcedev_areq = podev->active_command;
  333. if (iv)
  334. memcpy(&qcedev_areq->cipher_op_req.iv[0], iv,
  335. qcedev_areq->cipher_op_req.ivlen);
  336. tasklet_schedule(&podev->done_tasklet);
  337. };
  338. static int start_cipher_req(struct qcedev_control *podev,
  339. int *current_req_info)
  340. {
  341. struct qcedev_async_req *qcedev_areq;
  342. struct qce_req creq;
  343. int ret = 0;
  344. memset(&creq, 0, sizeof(creq));
  345. /* start the command on the podev->active_command */
  346. qcedev_areq = podev->active_command;
  347. qcedev_areq->cipher_req.cookie = qcedev_areq->handle;
  348. if (qcedev_areq->cipher_op_req.use_pmem == QCEDEV_USE_PMEM) {
  349. pr_err("%s: Use of PMEM is not supported\n", __func__);
  350. goto unsupported;
  351. }
  352. creq.pmem = NULL;
  353. switch (qcedev_areq->cipher_op_req.alg) {
  354. case QCEDEV_ALG_DES:
  355. creq.alg = CIPHER_ALG_DES;
  356. break;
  357. case QCEDEV_ALG_3DES:
  358. creq.alg = CIPHER_ALG_3DES;
  359. break;
  360. case QCEDEV_ALG_AES:
  361. creq.alg = CIPHER_ALG_AES;
  362. break;
  363. default:
  364. return -EINVAL;
  365. }
  366. switch (qcedev_areq->cipher_op_req.mode) {
  367. case QCEDEV_AES_MODE_CBC:
  368. case QCEDEV_DES_MODE_CBC:
  369. creq.mode = QCE_MODE_CBC;
  370. break;
  371. case QCEDEV_AES_MODE_ECB:
  372. case QCEDEV_DES_MODE_ECB:
  373. creq.mode = QCE_MODE_ECB;
  374. break;
  375. case QCEDEV_AES_MODE_CTR:
  376. creq.mode = QCE_MODE_CTR;
  377. break;
  378. case QCEDEV_AES_MODE_XTS:
  379. creq.mode = QCE_MODE_XTS;
  380. break;
  381. default:
  382. return -EINVAL;
  383. }
  384. if ((creq.alg == CIPHER_ALG_AES) &&
  385. (creq.mode == QCE_MODE_CTR)) {
  386. creq.dir = QCE_ENCRYPT;
  387. } else {
  388. if (qcedev_areq->cipher_op_req.op == QCEDEV_OPER_ENC)
  389. creq.dir = QCE_ENCRYPT;
  390. else
  391. creq.dir = QCE_DECRYPT;
  392. }
  393. creq.iv = &qcedev_areq->cipher_op_req.iv[0];
  394. creq.ivsize = qcedev_areq->cipher_op_req.ivlen;
  395. creq.iv_ctr_size = 0;
  396. creq.enckey = &qcedev_areq->cipher_op_req.enckey[0];
  397. creq.encklen = qcedev_areq->cipher_op_req.encklen;
  398. creq.cryptlen = qcedev_areq->cipher_op_req.data_len;
  399. if (qcedev_areq->cipher_op_req.encklen == 0) {
  400. if ((qcedev_areq->cipher_op_req.op == QCEDEV_OPER_ENC_NO_KEY)
  401. || (qcedev_areq->cipher_op_req.op ==
  402. QCEDEV_OPER_DEC_NO_KEY))
  403. creq.op = QCE_REQ_ABLK_CIPHER_NO_KEY;
  404. else {
  405. int i;
  406. for (i = 0; i < QCEDEV_MAX_KEY_SIZE; i++) {
  407. if (qcedev_areq->cipher_op_req.enckey[i] != 0)
  408. break;
  409. }
  410. if ((podev->platform_support.hw_key_support == 1) &&
  411. (i == QCEDEV_MAX_KEY_SIZE))
  412. creq.op = QCE_REQ_ABLK_CIPHER;
  413. else {
  414. ret = -EINVAL;
  415. goto unsupported;
  416. }
  417. }
  418. } else {
  419. creq.op = QCE_REQ_ABLK_CIPHER;
  420. }
  421. creq.qce_cb = qcedev_cipher_req_cb;
  422. creq.areq = (void *)&qcedev_areq->cipher_req;
  423. creq.flags = 0;
  424. creq.offload_op = QCE_OFFLOAD_NONE;
  425. ret = qce_ablk_cipher_req(podev->qce, &creq);
  426. *current_req_info = creq.current_req_info;
  427. unsupported:
  428. qcedev_areq->err = ret ? -ENXIO : 0;
  429. return ret;
  430. };
  431. void qcedev_offload_cipher_req_cb(void *cookie, unsigned char *icv,
  432. unsigned char *iv, int ret)
  433. {
  434. struct qcedev_cipher_req *areq;
  435. struct qcedev_handle *handle;
  436. struct qcedev_control *podev;
  437. struct qcedev_async_req *qcedev_areq;
  438. areq = (struct qcedev_cipher_req *) cookie;
  439. if (!areq || !areq->cookie)
  440. return;
  441. handle = (struct qcedev_handle *) areq->cookie;
  442. podev = handle->cntl;
  443. if (!podev)
  444. return;
  445. qcedev_areq = podev->active_command;
  446. if (iv)
  447. memcpy(&qcedev_areq->offload_cipher_op_req.iv[0], iv,
  448. qcedev_areq->offload_cipher_op_req.ivlen);
  449. tasklet_schedule(&podev->done_tasklet);
  450. }
  451. static int start_offload_cipher_req(struct qcedev_control *podev,
  452. int *current_req_info)
  453. {
  454. struct qcedev_async_req *qcedev_areq;
  455. struct qce_req creq;
  456. u8 patt_sz = 0, proc_data_sz = 0;
  457. int ret = 0;
  458. memset(&creq, 0, sizeof(creq));
  459. /* Start the command on the podev->active_command */
  460. qcedev_areq = podev->active_command;
  461. qcedev_areq->cipher_req.cookie = qcedev_areq->handle;
  462. switch (qcedev_areq->offload_cipher_op_req.alg) {
  463. case QCEDEV_ALG_AES:
  464. creq.alg = CIPHER_ALG_AES;
  465. break;
  466. default:
  467. return -EINVAL;
  468. }
  469. switch (qcedev_areq->offload_cipher_op_req.mode) {
  470. case QCEDEV_AES_MODE_CBC:
  471. creq.mode = QCE_MODE_CBC;
  472. break;
  473. case QCEDEV_AES_MODE_CTR:
  474. creq.mode = QCE_MODE_CTR;
  475. break;
  476. default:
  477. return -EINVAL;
  478. }
  479. if (qcedev_areq->offload_cipher_op_req.is_copy_op) {
  480. creq.dir = QCE_ENCRYPT;
  481. } else {
  482. switch(qcedev_areq->offload_cipher_op_req.op) {
  483. case QCEDEV_OFFLOAD_HLOS_HLOS:
  484. case QCEDEV_OFFLOAD_HLOS_CPB:
  485. creq.dir = QCE_DECRYPT;
  486. break;
  487. case QCEDEV_OFFLOAD_CPB_HLOS:
  488. creq.dir = QCE_ENCRYPT;
  489. break;
  490. default:
  491. return -EINVAL;
  492. }
  493. }
  494. creq.iv = &qcedev_areq->offload_cipher_op_req.iv[0];
  495. creq.ivsize = qcedev_areq->offload_cipher_op_req.ivlen;
  496. creq.iv_ctr_size = qcedev_areq->offload_cipher_op_req.iv_ctr_size;
  497. creq.encklen = qcedev_areq->offload_cipher_op_req.encklen;
  498. /* OFFLOAD use cases use PIPE keys so no need to set keys */
  499. creq.flags = QCEDEV_CTX_USE_PIPE_KEY;
  500. creq.op = QCE_REQ_ABLK_CIPHER_NO_KEY;
  501. creq.offload_op = (int)qcedev_areq->offload_cipher_op_req.op;
  502. if (qcedev_areq->offload_cipher_op_req.is_copy_op)
  503. creq.is_copy_op = true;
  504. creq.cryptlen = qcedev_areq->offload_cipher_op_req.data_len;
  505. creq.qce_cb = qcedev_offload_cipher_req_cb;
  506. creq.areq = (void *)&qcedev_areq->cipher_req;
  507. patt_sz = qcedev_areq->offload_cipher_op_req.pattern_info.patt_sz;
  508. proc_data_sz =
  509. qcedev_areq->offload_cipher_op_req.pattern_info.proc_data_sz;
  510. creq.is_pattern_valid =
  511. qcedev_areq->offload_cipher_op_req.is_pattern_valid;
  512. if (creq.is_pattern_valid) {
  513. creq.pattern_info = 0x1;
  514. if (patt_sz)
  515. creq.pattern_info |= (patt_sz - 1) << 4;
  516. if (proc_data_sz)
  517. creq.pattern_info |= (proc_data_sz - 1) << 8;
  518. creq.pattern_info |=
  519. qcedev_areq->offload_cipher_op_req.pattern_info.patt_offset << 12;
  520. }
  521. creq.block_offset = qcedev_areq->offload_cipher_op_req.block_offset;
  522. ret = qce_ablk_cipher_req(podev->qce, &creq);
  523. *current_req_info = creq.current_req_info;
  524. qcedev_areq->err = ret ? -ENXIO : 0;
  525. return ret;
  526. }
  527. static int start_sha_req(struct qcedev_control *podev,
  528. int *current_req_info)
  529. {
  530. struct qcedev_async_req *qcedev_areq;
  531. struct qce_sha_req sreq;
  532. int ret = 0;
  533. struct qcedev_handle *handle;
  534. /* start the command on the podev->active_command */
  535. qcedev_areq = podev->active_command;
  536. handle = qcedev_areq->handle;
  537. switch (qcedev_areq->sha_op_req.alg) {
  538. case QCEDEV_ALG_SHA1:
  539. sreq.alg = QCE_HASH_SHA1;
  540. break;
  541. case QCEDEV_ALG_SHA256:
  542. sreq.alg = QCE_HASH_SHA256;
  543. break;
  544. case QCEDEV_ALG_SHA1_HMAC:
  545. if (podev->ce_support.sha_hmac) {
  546. sreq.alg = QCE_HASH_SHA1_HMAC;
  547. sreq.authkey = &handle->sha_ctxt.authkey[0];
  548. sreq.authklen = QCEDEV_MAX_SHA_BLOCK_SIZE;
  549. } else {
  550. sreq.alg = QCE_HASH_SHA1;
  551. sreq.authkey = NULL;
  552. }
  553. break;
  554. case QCEDEV_ALG_SHA256_HMAC:
  555. if (podev->ce_support.sha_hmac) {
  556. sreq.alg = QCE_HASH_SHA256_HMAC;
  557. sreq.authkey = &handle->sha_ctxt.authkey[0];
  558. sreq.authklen = QCEDEV_MAX_SHA_BLOCK_SIZE;
  559. } else {
  560. sreq.alg = QCE_HASH_SHA256;
  561. sreq.authkey = NULL;
  562. }
  563. break;
  564. case QCEDEV_ALG_AES_CMAC:
  565. sreq.alg = QCE_HASH_AES_CMAC;
  566. sreq.authkey = &handle->sha_ctxt.authkey[0];
  567. sreq.authklen = qcedev_areq->sha_op_req.authklen;
  568. break;
  569. default:
  570. pr_err("Algorithm %d not supported, exiting\n",
  571. qcedev_areq->sha_op_req.alg);
  572. return -EINVAL;
  573. }
  574. qcedev_areq->sha_req.cookie = handle;
  575. sreq.qce_cb = qcedev_sha_req_cb;
  576. if (qcedev_areq->sha_op_req.alg != QCEDEV_ALG_AES_CMAC) {
  577. sreq.auth_data[0] = handle->sha_ctxt.auth_data[0];
  578. sreq.auth_data[1] = handle->sha_ctxt.auth_data[1];
  579. sreq.auth_data[2] = handle->sha_ctxt.auth_data[2];
  580. sreq.auth_data[3] = handle->sha_ctxt.auth_data[3];
  581. sreq.digest = &handle->sha_ctxt.digest[0];
  582. sreq.first_blk = handle->sha_ctxt.first_blk;
  583. sreq.last_blk = handle->sha_ctxt.last_blk;
  584. }
  585. sreq.size = qcedev_areq->sha_req.sreq.nbytes;
  586. sreq.src = qcedev_areq->sha_req.sreq.src;
  587. sreq.areq = (void *)&qcedev_areq->sha_req;
  588. sreq.flags = 0;
  589. ret = qce_process_sha_req(podev->qce, &sreq);
  590. *current_req_info = sreq.current_req_info;
  591. qcedev_areq->err = ret ? -ENXIO : 0;
  592. return ret;
  593. };
  594. static void qcedev_check_crypto_status(
  595. struct qcedev_async_req *qcedev_areq, void *handle,
  596. bool print_err)
  597. {
  598. unsigned int s1, s2, s3, s4, s5, s6;
  599. qcedev_areq->offload_cipher_op_req.err = QCEDEV_OFFLOAD_NO_ERROR;
  600. qce_get_crypto_status(handle, &s1, &s2, &s3, &s4, &s5, &s6);
  601. if (print_err) {
  602. pr_err("%s: sts = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", __func__,
  603. s1, s2, s3, s4, s5, s6);
  604. }
  605. // Check for key timer expiry
  606. if ((s6 & PIPE_KEY_TIMER_EXPIRED_STATUS6_MASK) ||
  607. (s3 & PIPE_KEY_TIMER_EXPIRED_STATUS3_MASK)) {
  608. pr_info("%s: crypto timer expired\n", __func__);
  609. pr_info("%s: sts = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", __func__,
  610. s1, s2, s3, s4, s5, s6);
  611. qcedev_areq->offload_cipher_op_req.err =
  612. QCEDEV_OFFLOAD_KEY_TIMER_EXPIRED_ERROR;
  613. return;
  614. }
  615. // Check for key pause
  616. if ((s6 & PIPE_KEY_PAUSE_STATUS6_MASK) ||
  617. (s3 & PIPE_KEY_PAUSE_STATUS3_MASK)) {
  618. pr_info("%s: crypto key paused\n", __func__);
  619. pr_info("%s: sts = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", __func__,
  620. s1, s2, s3, s4, s5, s6);
  621. qcedev_areq->offload_cipher_op_req.err =
  622. QCEDEV_OFFLOAD_KEY_PAUSE_ERROR;
  623. return;
  624. }
  625. // Check for generic error
  626. if (s1 & QCEDEV_STATUS1_ERR_INTR_MASK) {
  627. pr_err("%s: generic crypto error\n", __func__);
  628. pr_info("%s: sts = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", __func__,
  629. s1, s2, s3, s4, s5, s6);
  630. qcedev_areq->offload_cipher_op_req.err =
  631. QCEDEV_OFFLOAD_GENERIC_ERROR;
  632. return;
  633. }
  634. }
  635. static int submit_req(struct qcedev_async_req *qcedev_areq,
  636. struct qcedev_handle *handle)
  637. {
  638. struct qcedev_control *podev;
  639. unsigned long flags = 0;
  640. int ret = 0;
  641. struct qcedev_stat *pstat;
  642. int current_req_info = 0;
  643. int wait = MAX_CRYPTO_WAIT_TIME;
  644. bool print_sts = false;
  645. struct qcedev_async_req *new_req = NULL;
  646. qcedev_areq->err = 0;
  647. podev = handle->cntl;
  648. init_waitqueue_head(&qcedev_areq->wait_q);
  649. spin_lock_irqsave(&podev->lock, flags);
  650. /*
  651. * Service only one crypto request at a time.
  652. * Any other new requests are queued in ready_commands and woken up
  653. * only when the active command has finished successfully or when the
  654. * request times out or when the command failed when setting up.
  655. */
  656. do {
  657. if (podev->active_command == NULL) {
  658. podev->active_command = qcedev_areq;
  659. qcedev_areq->state = QCEDEV_REQ_SUBMITTED;
  660. switch (qcedev_areq->op_type) {
  661. case QCEDEV_CRYPTO_OPER_CIPHER:
  662. ret = start_cipher_req(podev,
  663. &current_req_info);
  664. break;
  665. case QCEDEV_CRYPTO_OPER_OFFLOAD_CIPHER:
  666. ret = start_offload_cipher_req(podev,
  667. &current_req_info);
  668. break;
  669. default:
  670. ret = start_sha_req(podev,
  671. &current_req_info);
  672. break;
  673. }
  674. } else {
  675. list_add_tail(&qcedev_areq->list,
  676. &podev->ready_commands);
  677. qcedev_areq->state = QCEDEV_REQ_WAITING;
  678. if (wait_event_interruptible_lock_irq_timeout(
  679. qcedev_areq->wait_q,
  680. (qcedev_areq->state == QCEDEV_REQ_CURRENT),
  681. podev->lock,
  682. msecs_to_jiffies(MAX_REQUEST_TIME)) == 0) {
  683. pr_err("%s: request timed out\n", __func__);
  684. spin_unlock_irqrestore(&podev->lock, flags);
  685. return qcedev_areq->err;
  686. }
  687. }
  688. } while (qcedev_areq->state != QCEDEV_REQ_SUBMITTED);
  689. if (ret != 0) {
  690. podev->active_command = NULL;
  691. /*
  692. * Look through queued requests and wake up the corresponding
  693. * thread.
  694. */
  695. if (!list_empty(&podev->ready_commands)) {
  696. new_req = container_of(podev->ready_commands.next,
  697. struct qcedev_async_req, list);
  698. list_del(&new_req->list);
  699. new_req->state = QCEDEV_REQ_CURRENT;
  700. wake_up_interruptible(&new_req->wait_q);
  701. }
  702. }
  703. spin_unlock_irqrestore(&podev->lock, flags);
  704. qcedev_areq->timed_out = false;
  705. if (ret == 0)
  706. wait = wait_for_completion_timeout(&qcedev_areq->complete,
  707. msecs_to_jiffies(MAX_CRYPTO_WAIT_TIME));
  708. if (!wait) {
  709. /*
  710. * This means wait timed out, and the callback routine was not
  711. * exercised. The callback sequence does some housekeeping which
  712. * would be missed here, hence having a call to qce here to do
  713. * that.
  714. */
  715. pr_err("%s: wait timed out, req info = %d\n", __func__,
  716. current_req_info);
  717. print_sts = true;
  718. spin_lock_irqsave(&podev->lock, flags);
  719. qcedev_check_crypto_status(qcedev_areq, podev->qce, print_sts);
  720. qcedev_areq->timed_out = true;
  721. ret = qce_manage_timeout(podev->qce, current_req_info);
  722. if (ret) {
  723. pr_err("%s: error during manage timeout", __func__);
  724. qcedev_areq->err = -EIO;
  725. spin_unlock_irqrestore(&podev->lock, flags);
  726. return qcedev_areq->err;
  727. }
  728. spin_unlock_irqrestore(&podev->lock, flags);
  729. tasklet_schedule(&podev->done_tasklet);
  730. if (qcedev_areq->offload_cipher_op_req.err !=
  731. QCEDEV_OFFLOAD_NO_ERROR)
  732. return 0;
  733. }
  734. if (ret)
  735. qcedev_areq->err = -EIO;
  736. pstat = &_qcedev_stat;
  737. if (qcedev_areq->op_type == QCEDEV_CRYPTO_OPER_CIPHER) {
  738. switch (qcedev_areq->cipher_op_req.op) {
  739. case QCEDEV_OPER_DEC:
  740. if (qcedev_areq->err)
  741. pstat->qcedev_dec_fail++;
  742. else
  743. pstat->qcedev_dec_success++;
  744. break;
  745. case QCEDEV_OPER_ENC:
  746. if (qcedev_areq->err)
  747. pstat->qcedev_enc_fail++;
  748. else
  749. pstat->qcedev_enc_success++;
  750. break;
  751. default:
  752. break;
  753. }
  754. } else if (qcedev_areq->op_type == QCEDEV_CRYPTO_OPER_OFFLOAD_CIPHER) {
  755. //Do nothing
  756. } else {
  757. if (qcedev_areq->err)
  758. pstat->qcedev_sha_fail++;
  759. else
  760. pstat->qcedev_sha_success++;
  761. }
  762. return qcedev_areq->err;
  763. }
  764. static int qcedev_sha_init(struct qcedev_async_req *areq,
  765. struct qcedev_handle *handle)
  766. {
  767. struct qcedev_sha_ctxt *sha_ctxt = &handle->sha_ctxt;
  768. memset(sha_ctxt, 0, sizeof(struct qcedev_sha_ctxt));
  769. sha_ctxt->first_blk = 1;
  770. if ((areq->sha_op_req.alg == QCEDEV_ALG_SHA1) ||
  771. (areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC)) {
  772. memcpy(&sha_ctxt->digest[0],
  773. &_std_init_vector_sha1_uint8[0], SHA1_DIGEST_SIZE);
  774. sha_ctxt->diglen = SHA1_DIGEST_SIZE;
  775. } else {
  776. if ((areq->sha_op_req.alg == QCEDEV_ALG_SHA256) ||
  777. (areq->sha_op_req.alg == QCEDEV_ALG_SHA256_HMAC)) {
  778. memcpy(&sha_ctxt->digest[0],
  779. &_std_init_vector_sha256_uint8[0],
  780. SHA256_DIGEST_SIZE);
  781. sha_ctxt->diglen = SHA256_DIGEST_SIZE;
  782. }
  783. }
  784. sha_ctxt->init_done = true;
  785. return 0;
  786. }
  787. static int qcedev_sha_update_max_xfer(struct qcedev_async_req *qcedev_areq,
  788. struct qcedev_handle *handle,
  789. struct scatterlist *sg_src)
  790. {
  791. int err = 0;
  792. int i = 0;
  793. uint32_t total;
  794. uint8_t *user_src = NULL;
  795. uint8_t *k_src = NULL;
  796. uint8_t *k_buf_src = NULL;
  797. uint8_t *k_align_src = NULL;
  798. uint32_t sha_pad_len = 0;
  799. uint32_t trailing_buf_len = 0;
  800. uint32_t t_buf = handle->sha_ctxt.trailing_buf_len;
  801. uint32_t sha_block_size;
  802. total = qcedev_areq->sha_op_req.data_len + t_buf;
  803. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA1)
  804. sha_block_size = SHA1_BLOCK_SIZE;
  805. else
  806. sha_block_size = SHA256_BLOCK_SIZE;
  807. if (total <= sha_block_size) {
  808. uint32_t len = qcedev_areq->sha_op_req.data_len;
  809. i = 0;
  810. k_src = &handle->sha_ctxt.trailing_buf[t_buf];
  811. /* Copy data from user src(s) */
  812. while (len > 0) {
  813. user_src = qcedev_areq->sha_op_req.data[i].vaddr;
  814. if (user_src && copy_from_user(k_src,
  815. (void __user *)user_src,
  816. qcedev_areq->sha_op_req.data[i].len))
  817. return -EFAULT;
  818. len -= qcedev_areq->sha_op_req.data[i].len;
  819. k_src += qcedev_areq->sha_op_req.data[i].len;
  820. i++;
  821. }
  822. handle->sha_ctxt.trailing_buf_len = total;
  823. return 0;
  824. }
  825. k_buf_src = kmalloc(total + CACHE_LINE_SIZE * 2,
  826. GFP_KERNEL);
  827. if (k_buf_src == NULL)
  828. return -ENOMEM;
  829. k_align_src = (uint8_t *)ALIGN(((uintptr_t)k_buf_src),
  830. CACHE_LINE_SIZE);
  831. k_src = k_align_src;
  832. /* check for trailing buffer from previous updates and append it */
  833. if (t_buf > 0) {
  834. memcpy(k_src, &handle->sha_ctxt.trailing_buf[0],
  835. t_buf);
  836. k_src += t_buf;
  837. }
  838. /* Copy data from user src(s) */
  839. user_src = qcedev_areq->sha_op_req.data[0].vaddr;
  840. if (user_src && copy_from_user(k_src,
  841. (void __user *)user_src,
  842. qcedev_areq->sha_op_req.data[0].len)) {
  843. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  844. kfree(k_buf_src);
  845. return -EFAULT;
  846. }
  847. k_src += qcedev_areq->sha_op_req.data[0].len;
  848. for (i = 1; i < qcedev_areq->sha_op_req.entries; i++) {
  849. user_src = qcedev_areq->sha_op_req.data[i].vaddr;
  850. if (user_src && copy_from_user(k_src,
  851. (void __user *)user_src,
  852. qcedev_areq->sha_op_req.data[i].len)) {
  853. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  854. kfree(k_buf_src);
  855. return -EFAULT;
  856. }
  857. k_src += qcedev_areq->sha_op_req.data[i].len;
  858. }
  859. /* get new trailing buffer */
  860. sha_pad_len = ALIGN(total, CE_SHA_BLOCK_SIZE) - total;
  861. trailing_buf_len = CE_SHA_BLOCK_SIZE - sha_pad_len;
  862. qcedev_areq->sha_req.sreq.src = sg_src;
  863. sg_init_one(qcedev_areq->sha_req.sreq.src, k_align_src,
  864. total-trailing_buf_len);
  865. qcedev_areq->sha_req.sreq.nbytes = total - trailing_buf_len;
  866. /* update sha_ctxt trailing buf content to new trailing buf */
  867. if (trailing_buf_len > 0) {
  868. memset(&handle->sha_ctxt.trailing_buf[0], 0, 64);
  869. memcpy(&handle->sha_ctxt.trailing_buf[0],
  870. (k_src - trailing_buf_len),
  871. trailing_buf_len);
  872. }
  873. handle->sha_ctxt.trailing_buf_len = trailing_buf_len;
  874. err = submit_req(qcedev_areq, handle);
  875. handle->sha_ctxt.last_blk = 0;
  876. handle->sha_ctxt.first_blk = 0;
  877. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  878. kfree(k_buf_src);
  879. return err;
  880. }
  881. static int qcedev_sha_update(struct qcedev_async_req *qcedev_areq,
  882. struct qcedev_handle *handle,
  883. struct scatterlist *sg_src)
  884. {
  885. int err = 0;
  886. int i = 0;
  887. int j = 0;
  888. int k = 0;
  889. int num_entries = 0;
  890. uint32_t total = 0;
  891. if (!handle->sha_ctxt.init_done) {
  892. pr_err("%s Init was not called\n", __func__);
  893. return -EINVAL;
  894. }
  895. if (qcedev_areq->sha_op_req.data_len > QCE_MAX_OPER_DATA) {
  896. struct qcedev_sha_op_req *saved_req;
  897. struct qcedev_sha_op_req req;
  898. struct qcedev_sha_op_req *sreq = &qcedev_areq->sha_op_req;
  899. /* save the original req structure */
  900. saved_req =
  901. kmalloc(sizeof(struct qcedev_sha_op_req), GFP_KERNEL);
  902. if (saved_req == NULL) {
  903. pr_err("%s:Can't Allocate mem:saved_req 0x%lx\n",
  904. __func__, (uintptr_t)saved_req);
  905. return -ENOMEM;
  906. }
  907. memcpy(&req, sreq, sizeof(struct qcedev_sha_op_req));
  908. memcpy(saved_req, sreq, sizeof(struct qcedev_sha_op_req));
  909. i = 0;
  910. /* Address 32 KB at a time */
  911. while ((i < req.entries) && (err == 0)) {
  912. if (sreq->data[i].len > QCE_MAX_OPER_DATA) {
  913. sreq->data[0].len = QCE_MAX_OPER_DATA;
  914. if (i > 0) {
  915. sreq->data[0].vaddr =
  916. sreq->data[i].vaddr;
  917. }
  918. sreq->data_len = QCE_MAX_OPER_DATA;
  919. sreq->entries = 1;
  920. err = qcedev_sha_update_max_xfer(qcedev_areq,
  921. handle, sg_src);
  922. sreq->data[i].len = req.data[i].len -
  923. QCE_MAX_OPER_DATA;
  924. sreq->data[i].vaddr = req.data[i].vaddr +
  925. QCE_MAX_OPER_DATA;
  926. req.data[i].vaddr = sreq->data[i].vaddr;
  927. req.data[i].len = sreq->data[i].len;
  928. } else {
  929. total = 0;
  930. for (j = i; j < req.entries; j++) {
  931. num_entries++;
  932. if ((total + sreq->data[j].len) >=
  933. QCE_MAX_OPER_DATA) {
  934. sreq->data[j].len =
  935. (QCE_MAX_OPER_DATA - total);
  936. total = QCE_MAX_OPER_DATA;
  937. break;
  938. }
  939. total += sreq->data[j].len;
  940. }
  941. sreq->data_len = total;
  942. if (i > 0)
  943. for (k = 0; k < num_entries; k++) {
  944. sreq->data[k].len =
  945. sreq->data[i+k].len;
  946. sreq->data[k].vaddr =
  947. sreq->data[i+k].vaddr;
  948. }
  949. sreq->entries = num_entries;
  950. i = j;
  951. err = qcedev_sha_update_max_xfer(qcedev_areq,
  952. handle, sg_src);
  953. num_entries = 0;
  954. sreq->data[i].vaddr = req.data[i].vaddr +
  955. sreq->data[i].len;
  956. sreq->data[i].len = req.data[i].len -
  957. sreq->data[i].len;
  958. req.data[i].vaddr = sreq->data[i].vaddr;
  959. req.data[i].len = sreq->data[i].len;
  960. if (sreq->data[i].len == 0)
  961. i++;
  962. }
  963. } /* end of while ((i < req.entries) && (err == 0)) */
  964. /* Restore the original req structure */
  965. for (i = 0; i < saved_req->entries; i++) {
  966. sreq->data[i].len = saved_req->data[i].len;
  967. sreq->data[i].vaddr = saved_req->data[i].vaddr;
  968. }
  969. sreq->entries = saved_req->entries;
  970. sreq->data_len = saved_req->data_len;
  971. memset(saved_req, 0, ksize((void *)saved_req));
  972. kfree(saved_req);
  973. } else
  974. err = qcedev_sha_update_max_xfer(qcedev_areq, handle, sg_src);
  975. return err;
  976. }
  977. static int qcedev_sha_final(struct qcedev_async_req *qcedev_areq,
  978. struct qcedev_handle *handle)
  979. {
  980. int err = 0;
  981. struct scatterlist sg_src;
  982. uint32_t total;
  983. uint8_t *k_buf_src = NULL;
  984. uint8_t *k_align_src = NULL;
  985. if (!handle->sha_ctxt.init_done) {
  986. pr_err("%s Init was not called\n", __func__);
  987. return -EINVAL;
  988. }
  989. handle->sha_ctxt.last_blk = 1;
  990. total = handle->sha_ctxt.trailing_buf_len;
  991. k_buf_src = kmalloc(total + CACHE_LINE_SIZE * 2,
  992. GFP_KERNEL);
  993. if (k_buf_src == NULL)
  994. return -ENOMEM;
  995. k_align_src = (uint8_t *)ALIGN(((uintptr_t)k_buf_src),
  996. CACHE_LINE_SIZE);
  997. memcpy(k_align_src, &handle->sha_ctxt.trailing_buf[0], total);
  998. qcedev_areq->sha_req.sreq.src = (struct scatterlist *) &sg_src;
  999. sg_init_one(qcedev_areq->sha_req.sreq.src, k_align_src, total);
  1000. qcedev_areq->sha_req.sreq.nbytes = total;
  1001. err = submit_req(qcedev_areq, handle);
  1002. handle->sha_ctxt.first_blk = 0;
  1003. handle->sha_ctxt.last_blk = 0;
  1004. handle->sha_ctxt.auth_data[0] = 0;
  1005. handle->sha_ctxt.auth_data[1] = 0;
  1006. handle->sha_ctxt.trailing_buf_len = 0;
  1007. handle->sha_ctxt.init_done = false;
  1008. memset(&handle->sha_ctxt.trailing_buf[0], 0, 64);
  1009. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  1010. kfree(k_buf_src);
  1011. qcedev_areq->sha_req.sreq.src = NULL;
  1012. return err;
  1013. }
  1014. static int qcedev_hash_cmac(struct qcedev_async_req *qcedev_areq,
  1015. struct qcedev_handle *handle,
  1016. struct scatterlist *sg_src)
  1017. {
  1018. int err = 0;
  1019. int i = 0;
  1020. uint32_t total;
  1021. uint8_t *user_src = NULL;
  1022. uint8_t *k_src = NULL;
  1023. uint8_t *k_buf_src = NULL;
  1024. total = qcedev_areq->sha_op_req.data_len;
  1025. if ((qcedev_areq->sha_op_req.authklen != QCEDEV_AES_KEY_128) &&
  1026. (qcedev_areq->sha_op_req.authklen != QCEDEV_AES_KEY_256)) {
  1027. pr_err("%s: unsupported key length\n", __func__);
  1028. return -EINVAL;
  1029. }
  1030. if (copy_from_user(&handle->sha_ctxt.authkey[0],
  1031. (void __user *)qcedev_areq->sha_op_req.authkey,
  1032. qcedev_areq->sha_op_req.authklen))
  1033. return -EFAULT;
  1034. if (total > U32_MAX - CACHE_LINE_SIZE * 2)
  1035. return -EINVAL;
  1036. k_buf_src = kmalloc(total + CACHE_LINE_SIZE * 2, GFP_KERNEL);
  1037. if (k_buf_src == NULL)
  1038. return -ENOMEM;
  1039. k_src = k_buf_src;
  1040. /* Copy data from user src(s) */
  1041. user_src = qcedev_areq->sha_op_req.data[0].vaddr;
  1042. for (i = 0; i < qcedev_areq->sha_op_req.entries; i++) {
  1043. user_src = qcedev_areq->sha_op_req.data[i].vaddr;
  1044. if (user_src && copy_from_user(k_src, (void __user *)user_src,
  1045. qcedev_areq->sha_op_req.data[i].len)) {
  1046. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  1047. kfree(k_buf_src);
  1048. return -EFAULT;
  1049. }
  1050. k_src += qcedev_areq->sha_op_req.data[i].len;
  1051. }
  1052. qcedev_areq->sha_req.sreq.src = sg_src;
  1053. sg_init_one(qcedev_areq->sha_req.sreq.src, k_buf_src, total);
  1054. qcedev_areq->sha_req.sreq.nbytes = total;
  1055. handle->sha_ctxt.diglen = qcedev_areq->sha_op_req.diglen;
  1056. err = submit_req(qcedev_areq, handle);
  1057. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  1058. kfree(k_buf_src);
  1059. return err;
  1060. }
  1061. static int qcedev_set_hmac_auth_key(struct qcedev_async_req *areq,
  1062. struct qcedev_handle *handle,
  1063. struct scatterlist *sg_src)
  1064. {
  1065. int err = 0;
  1066. if (areq->sha_op_req.authklen <= QCEDEV_MAX_KEY_SIZE) {
  1067. qcedev_sha_init(areq, handle);
  1068. if (copy_from_user(&handle->sha_ctxt.authkey[0],
  1069. (void __user *)areq->sha_op_req.authkey,
  1070. areq->sha_op_req.authklen))
  1071. return -EFAULT;
  1072. } else {
  1073. struct qcedev_async_req authkey_areq;
  1074. uint8_t authkey[QCEDEV_MAX_SHA_BLOCK_SIZE];
  1075. init_completion(&authkey_areq.complete);
  1076. authkey_areq.sha_op_req.entries = 1;
  1077. authkey_areq.sha_op_req.data[0].vaddr =
  1078. areq->sha_op_req.authkey;
  1079. authkey_areq.sha_op_req.data[0].len = areq->sha_op_req.authklen;
  1080. authkey_areq.sha_op_req.data_len = areq->sha_op_req.authklen;
  1081. authkey_areq.sha_op_req.diglen = 0;
  1082. authkey_areq.handle = handle;
  1083. memset(&authkey_areq.sha_op_req.digest[0], 0,
  1084. QCEDEV_MAX_SHA_DIGEST);
  1085. if (areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC)
  1086. authkey_areq.sha_op_req.alg = QCEDEV_ALG_SHA1;
  1087. if (areq->sha_op_req.alg == QCEDEV_ALG_SHA256_HMAC)
  1088. authkey_areq.sha_op_req.alg = QCEDEV_ALG_SHA256;
  1089. authkey_areq.op_type = QCEDEV_CRYPTO_OPER_SHA;
  1090. qcedev_sha_init(&authkey_areq, handle);
  1091. err = qcedev_sha_update(&authkey_areq, handle, sg_src);
  1092. if (!err)
  1093. err = qcedev_sha_final(&authkey_areq, handle);
  1094. else
  1095. return err;
  1096. memcpy(&authkey[0], &handle->sha_ctxt.digest[0],
  1097. handle->sha_ctxt.diglen);
  1098. qcedev_sha_init(areq, handle);
  1099. memcpy(&handle->sha_ctxt.authkey[0], &authkey[0],
  1100. handle->sha_ctxt.diglen);
  1101. }
  1102. return err;
  1103. }
  1104. static int qcedev_hmac_get_ohash(struct qcedev_async_req *qcedev_areq,
  1105. struct qcedev_handle *handle)
  1106. {
  1107. int err = 0;
  1108. struct scatterlist sg_src;
  1109. uint8_t *k_src = NULL;
  1110. uint32_t sha_block_size = 0;
  1111. uint32_t sha_digest_size = 0;
  1112. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC) {
  1113. sha_digest_size = SHA1_DIGEST_SIZE;
  1114. sha_block_size = SHA1_BLOCK_SIZE;
  1115. } else {
  1116. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA256_HMAC) {
  1117. sha_digest_size = SHA256_DIGEST_SIZE;
  1118. sha_block_size = SHA256_BLOCK_SIZE;
  1119. }
  1120. }
  1121. k_src = kmalloc(sha_block_size, GFP_KERNEL);
  1122. if (k_src == NULL)
  1123. return -ENOMEM;
  1124. /* check for trailing buffer from previous updates and append it */
  1125. memcpy(k_src, &handle->sha_ctxt.trailing_buf[0],
  1126. handle->sha_ctxt.trailing_buf_len);
  1127. qcedev_areq->sha_req.sreq.src = (struct scatterlist *) &sg_src;
  1128. sg_init_one(qcedev_areq->sha_req.sreq.src, k_src, sha_block_size);
  1129. qcedev_areq->sha_req.sreq.nbytes = sha_block_size;
  1130. memset(&handle->sha_ctxt.trailing_buf[0], 0, sha_block_size);
  1131. memcpy(&handle->sha_ctxt.trailing_buf[0], &handle->sha_ctxt.digest[0],
  1132. sha_digest_size);
  1133. handle->sha_ctxt.trailing_buf_len = sha_digest_size;
  1134. handle->sha_ctxt.first_blk = 1;
  1135. handle->sha_ctxt.last_blk = 0;
  1136. handle->sha_ctxt.auth_data[0] = 0;
  1137. handle->sha_ctxt.auth_data[1] = 0;
  1138. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC) {
  1139. memcpy(&handle->sha_ctxt.digest[0],
  1140. &_std_init_vector_sha1_uint8[0], SHA1_DIGEST_SIZE);
  1141. handle->sha_ctxt.diglen = SHA1_DIGEST_SIZE;
  1142. }
  1143. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_SHA256_HMAC) {
  1144. memcpy(&handle->sha_ctxt.digest[0],
  1145. &_std_init_vector_sha256_uint8[0], SHA256_DIGEST_SIZE);
  1146. handle->sha_ctxt.diglen = SHA256_DIGEST_SIZE;
  1147. }
  1148. err = submit_req(qcedev_areq, handle);
  1149. handle->sha_ctxt.last_blk = 0;
  1150. handle->sha_ctxt.first_blk = 0;
  1151. memset(k_src, 0, ksize((void *)k_src));
  1152. kfree(k_src);
  1153. qcedev_areq->sha_req.sreq.src = NULL;
  1154. return err;
  1155. }
  1156. static int qcedev_hmac_update_iokey(struct qcedev_async_req *areq,
  1157. struct qcedev_handle *handle, bool ikey)
  1158. {
  1159. int i;
  1160. uint32_t constant;
  1161. uint32_t sha_block_size;
  1162. if (ikey)
  1163. constant = 0x36;
  1164. else
  1165. constant = 0x5c;
  1166. if (areq->sha_op_req.alg == QCEDEV_ALG_SHA1_HMAC)
  1167. sha_block_size = SHA1_BLOCK_SIZE;
  1168. else
  1169. sha_block_size = SHA256_BLOCK_SIZE;
  1170. memset(&handle->sha_ctxt.trailing_buf[0], 0, sha_block_size);
  1171. for (i = 0; i < sha_block_size; i++)
  1172. handle->sha_ctxt.trailing_buf[i] =
  1173. (handle->sha_ctxt.authkey[i] ^ constant);
  1174. handle->sha_ctxt.trailing_buf_len = sha_block_size;
  1175. return 0;
  1176. }
  1177. static int qcedev_hmac_init(struct qcedev_async_req *areq,
  1178. struct qcedev_handle *handle,
  1179. struct scatterlist *sg_src)
  1180. {
  1181. int err;
  1182. struct qcedev_control *podev = handle->cntl;
  1183. err = qcedev_set_hmac_auth_key(areq, handle, sg_src);
  1184. if (err)
  1185. return err;
  1186. if (!podev->ce_support.sha_hmac)
  1187. qcedev_hmac_update_iokey(areq, handle, true);
  1188. return 0;
  1189. }
  1190. static int qcedev_hmac_final(struct qcedev_async_req *areq,
  1191. struct qcedev_handle *handle)
  1192. {
  1193. int err;
  1194. struct qcedev_control *podev = handle->cntl;
  1195. err = qcedev_sha_final(areq, handle);
  1196. if (podev->ce_support.sha_hmac)
  1197. return err;
  1198. qcedev_hmac_update_iokey(areq, handle, false);
  1199. err = qcedev_hmac_get_ohash(areq, handle);
  1200. if (err)
  1201. return err;
  1202. err = qcedev_sha_final(areq, handle);
  1203. return err;
  1204. }
  1205. static int qcedev_hash_init(struct qcedev_async_req *areq,
  1206. struct qcedev_handle *handle,
  1207. struct scatterlist *sg_src)
  1208. {
  1209. if ((areq->sha_op_req.alg == QCEDEV_ALG_SHA1) ||
  1210. (areq->sha_op_req.alg == QCEDEV_ALG_SHA256))
  1211. return qcedev_sha_init(areq, handle);
  1212. else
  1213. return qcedev_hmac_init(areq, handle, sg_src);
  1214. }
  1215. static int qcedev_hash_update(struct qcedev_async_req *qcedev_areq,
  1216. struct qcedev_handle *handle,
  1217. struct scatterlist *sg_src)
  1218. {
  1219. return qcedev_sha_update(qcedev_areq, handle, sg_src);
  1220. }
  1221. static int qcedev_hash_final(struct qcedev_async_req *areq,
  1222. struct qcedev_handle *handle)
  1223. {
  1224. if ((areq->sha_op_req.alg == QCEDEV_ALG_SHA1) ||
  1225. (areq->sha_op_req.alg == QCEDEV_ALG_SHA256))
  1226. return qcedev_sha_final(areq, handle);
  1227. else
  1228. return qcedev_hmac_final(areq, handle);
  1229. }
  1230. static int qcedev_vbuf_ablk_cipher_max_xfer(struct qcedev_async_req *areq,
  1231. int *di, struct qcedev_handle *handle,
  1232. uint8_t *k_align_src)
  1233. {
  1234. int err = 0;
  1235. int i = 0;
  1236. int dst_i = *di;
  1237. struct scatterlist sg_src;
  1238. uint32_t byteoffset = 0;
  1239. uint8_t *user_src = NULL;
  1240. uint8_t *k_align_dst = k_align_src;
  1241. struct qcedev_cipher_op_req *creq = &areq->cipher_op_req;
  1242. if (areq->cipher_op_req.mode == QCEDEV_AES_MODE_CTR)
  1243. byteoffset = areq->cipher_op_req.byteoffset;
  1244. user_src = areq->cipher_op_req.vbuf.src[0].vaddr;
  1245. if (user_src && copy_from_user((k_align_src + byteoffset),
  1246. (void __user *)user_src,
  1247. areq->cipher_op_req.vbuf.src[0].len))
  1248. return -EFAULT;
  1249. k_align_src += byteoffset + areq->cipher_op_req.vbuf.src[0].len;
  1250. for (i = 1; i < areq->cipher_op_req.entries; i++) {
  1251. user_src = areq->cipher_op_req.vbuf.src[i].vaddr;
  1252. if (user_src && copy_from_user(k_align_src,
  1253. (void __user *)user_src,
  1254. areq->cipher_op_req.vbuf.src[i].len)) {
  1255. return -EFAULT;
  1256. }
  1257. k_align_src += areq->cipher_op_req.vbuf.src[i].len;
  1258. }
  1259. /* restore src beginning */
  1260. k_align_src = k_align_dst;
  1261. areq->cipher_op_req.data_len += byteoffset;
  1262. areq->cipher_req.creq.src = (struct scatterlist *) &sg_src;
  1263. areq->cipher_req.creq.dst = (struct scatterlist *) &sg_src;
  1264. /* In place encryption/decryption */
  1265. sg_init_one(areq->cipher_req.creq.src,
  1266. k_align_dst,
  1267. areq->cipher_op_req.data_len);
  1268. areq->cipher_req.creq.cryptlen = areq->cipher_op_req.data_len;
  1269. areq->cipher_req.creq.iv = areq->cipher_op_req.iv;
  1270. areq->cipher_op_req.entries = 1;
  1271. err = submit_req(areq, handle);
  1272. /* copy data to destination buffer*/
  1273. creq->data_len -= byteoffset;
  1274. while (creq->data_len > 0) {
  1275. if (creq->vbuf.dst[dst_i].len <= creq->data_len) {
  1276. if (err == 0 && copy_to_user(
  1277. (void __user *)creq->vbuf.dst[dst_i].vaddr,
  1278. (k_align_dst + byteoffset),
  1279. creq->vbuf.dst[dst_i].len)) {
  1280. err = -EFAULT;
  1281. goto exit;
  1282. }
  1283. k_align_dst += creq->vbuf.dst[dst_i].len;
  1284. creq->data_len -= creq->vbuf.dst[dst_i].len;
  1285. dst_i++;
  1286. } else {
  1287. if (err == 0 && copy_to_user(
  1288. (void __user *)creq->vbuf.dst[dst_i].vaddr,
  1289. (k_align_dst + byteoffset),
  1290. creq->data_len)) {
  1291. err = -EFAULT;
  1292. goto exit;
  1293. }
  1294. k_align_dst += creq->data_len;
  1295. creq->vbuf.dst[dst_i].len -= creq->data_len;
  1296. creq->vbuf.dst[dst_i].vaddr += creq->data_len;
  1297. creq->data_len = 0;
  1298. }
  1299. }
  1300. *di = dst_i;
  1301. exit:
  1302. areq->cipher_req.creq.src = NULL;
  1303. areq->cipher_req.creq.dst = NULL;
  1304. return err;
  1305. };
  1306. static int qcedev_vbuf_ablk_cipher(struct qcedev_async_req *areq,
  1307. struct qcedev_handle *handle)
  1308. {
  1309. int err = 0;
  1310. int di = 0;
  1311. int i = 0;
  1312. int j = 0;
  1313. int k = 0;
  1314. uint32_t byteoffset = 0;
  1315. int num_entries = 0;
  1316. uint32_t total = 0;
  1317. uint32_t len;
  1318. uint8_t *k_buf_src = NULL;
  1319. uint8_t *k_align_src = NULL;
  1320. uint32_t max_data_xfer;
  1321. struct qcedev_cipher_op_req *saved_req;
  1322. struct qcedev_cipher_op_req *creq = &areq->cipher_op_req;
  1323. total = 0;
  1324. if (areq->cipher_op_req.mode == QCEDEV_AES_MODE_CTR)
  1325. byteoffset = areq->cipher_op_req.byteoffset;
  1326. k_buf_src = kmalloc(QCE_MAX_OPER_DATA + CACHE_LINE_SIZE * 2,
  1327. GFP_KERNEL);
  1328. if (k_buf_src == NULL)
  1329. return -ENOMEM;
  1330. k_align_src = (uint8_t *)ALIGN(((uintptr_t)k_buf_src),
  1331. CACHE_LINE_SIZE);
  1332. max_data_xfer = QCE_MAX_OPER_DATA - byteoffset;
  1333. saved_req = kmemdup(creq, sizeof(struct qcedev_cipher_op_req),
  1334. GFP_KERNEL);
  1335. if (saved_req == NULL) {
  1336. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  1337. kfree(k_buf_src);
  1338. return -ENOMEM;
  1339. }
  1340. if (areq->cipher_op_req.data_len > max_data_xfer) {
  1341. struct qcedev_cipher_op_req req;
  1342. /* save the original req structure */
  1343. memcpy(&req, creq, sizeof(struct qcedev_cipher_op_req));
  1344. i = 0;
  1345. /* Address 32 KB at a time */
  1346. while ((i < req.entries) && (err == 0)) {
  1347. if (creq->vbuf.src[i].len > max_data_xfer) {
  1348. creq->vbuf.src[0].len = max_data_xfer;
  1349. if (i > 0) {
  1350. creq->vbuf.src[0].vaddr =
  1351. creq->vbuf.src[i].vaddr;
  1352. }
  1353. creq->data_len = max_data_xfer;
  1354. creq->entries = 1;
  1355. err = qcedev_vbuf_ablk_cipher_max_xfer(areq,
  1356. &di, handle, k_align_src);
  1357. if (err < 0) {
  1358. memset(saved_req, 0,
  1359. ksize((void *)saved_req));
  1360. memset(k_buf_src, 0,
  1361. ksize((void *)k_buf_src));
  1362. kfree(k_buf_src);
  1363. kfree(saved_req);
  1364. return err;
  1365. }
  1366. creq->vbuf.src[i].len = req.vbuf.src[i].len -
  1367. max_data_xfer;
  1368. creq->vbuf.src[i].vaddr =
  1369. req.vbuf.src[i].vaddr +
  1370. max_data_xfer;
  1371. req.vbuf.src[i].vaddr =
  1372. creq->vbuf.src[i].vaddr;
  1373. req.vbuf.src[i].len = creq->vbuf.src[i].len;
  1374. } else {
  1375. total = areq->cipher_op_req.byteoffset;
  1376. for (j = i; j < req.entries; j++) {
  1377. num_entries++;
  1378. if ((total + creq->vbuf.src[j].len)
  1379. >= max_data_xfer) {
  1380. creq->vbuf.src[j].len =
  1381. max_data_xfer - total;
  1382. total = max_data_xfer;
  1383. break;
  1384. }
  1385. total += creq->vbuf.src[j].len;
  1386. }
  1387. creq->data_len = total;
  1388. if (i > 0)
  1389. for (k = 0; k < num_entries; k++) {
  1390. creq->vbuf.src[k].len =
  1391. creq->vbuf.src[i+k].len;
  1392. creq->vbuf.src[k].vaddr =
  1393. creq->vbuf.src[i+k].vaddr;
  1394. }
  1395. creq->entries = num_entries;
  1396. i = j;
  1397. err = qcedev_vbuf_ablk_cipher_max_xfer(areq,
  1398. &di, handle, k_align_src);
  1399. if (err < 0) {
  1400. memset(saved_req, 0,
  1401. ksize((void *)saved_req));
  1402. memset(k_buf_src, 0,
  1403. ksize((void *)k_buf_src));
  1404. kfree(k_buf_src);
  1405. kfree(saved_req);
  1406. return err;
  1407. }
  1408. num_entries = 0;
  1409. areq->cipher_op_req.byteoffset = 0;
  1410. creq->vbuf.src[i].vaddr = req.vbuf.src[i].vaddr
  1411. + creq->vbuf.src[i].len;
  1412. creq->vbuf.src[i].len = req.vbuf.src[i].len -
  1413. creq->vbuf.src[i].len;
  1414. req.vbuf.src[i].vaddr =
  1415. creq->vbuf.src[i].vaddr;
  1416. req.vbuf.src[i].len = creq->vbuf.src[i].len;
  1417. if (creq->vbuf.src[i].len == 0)
  1418. i++;
  1419. }
  1420. areq->cipher_op_req.byteoffset = 0;
  1421. max_data_xfer = QCE_MAX_OPER_DATA;
  1422. byteoffset = 0;
  1423. } /* end of while ((i < req.entries) && (err == 0)) */
  1424. } else
  1425. err = qcedev_vbuf_ablk_cipher_max_xfer(areq, &di, handle,
  1426. k_align_src);
  1427. /* Restore the original req structure */
  1428. for (i = 0; i < saved_req->entries; i++) {
  1429. creq->vbuf.src[i].len = saved_req->vbuf.src[i].len;
  1430. creq->vbuf.src[i].vaddr = saved_req->vbuf.src[i].vaddr;
  1431. }
  1432. for (len = 0, i = 0; len < saved_req->data_len; i++) {
  1433. creq->vbuf.dst[i].len = saved_req->vbuf.dst[i].len;
  1434. creq->vbuf.dst[i].vaddr = saved_req->vbuf.dst[i].vaddr;
  1435. len += saved_req->vbuf.dst[i].len;
  1436. }
  1437. creq->entries = saved_req->entries;
  1438. creq->data_len = saved_req->data_len;
  1439. creq->byteoffset = saved_req->byteoffset;
  1440. memset(saved_req, 0, ksize((void *)saved_req));
  1441. memset(k_buf_src, 0, ksize((void *)k_buf_src));
  1442. kfree(saved_req);
  1443. kfree(k_buf_src);
  1444. return err;
  1445. }
  1446. static int qcedev_smmu_ablk_offload_cipher(struct qcedev_async_req *areq,
  1447. struct qcedev_handle *handle)
  1448. {
  1449. int i = 0;
  1450. int err = 0;
  1451. size_t byteoffset = 0;
  1452. size_t transfer_data_len = 0;
  1453. size_t pending_data_len = 0;
  1454. size_t max_data_xfer = MAX_CEHW_REQ_TRANSFER_SIZE - byteoffset;
  1455. uint8_t *user_src = NULL;
  1456. uint8_t *user_dst = NULL;
  1457. struct scatterlist sg_src;
  1458. struct scatterlist sg_dst;
  1459. if (areq->offload_cipher_op_req.mode == QCEDEV_AES_MODE_CTR)
  1460. byteoffset = areq->offload_cipher_op_req.byteoffset;
  1461. /*
  1462. * areq has two components:
  1463. * a) Request that comes from userspace i.e. offload_cipher_op_req
  1464. * b) Request that QCE understands - skcipher i.e. cipher_req.creq
  1465. * skcipher has sglist pointers src and dest that would carry
  1466. * data to/from CE.
  1467. */
  1468. areq->cipher_req.creq.src = &sg_src;
  1469. areq->cipher_req.creq.dst = &sg_dst;
  1470. sg_init_table(&sg_src, 1);
  1471. sg_init_table(&sg_dst, 1);
  1472. for (i = 0; i < areq->offload_cipher_op_req.entries; i++) {
  1473. transfer_data_len = 0;
  1474. pending_data_len = areq->offload_cipher_op_req.vbuf.src[i].len;
  1475. user_src = areq->offload_cipher_op_req.vbuf.src[i].vaddr;
  1476. user_src += byteoffset;
  1477. user_dst = areq->offload_cipher_op_req.vbuf.dst[i].vaddr;
  1478. user_dst += byteoffset;
  1479. areq->cipher_req.creq.iv = areq->offload_cipher_op_req.iv;
  1480. while (pending_data_len) {
  1481. transfer_data_len = min(max_data_xfer,
  1482. pending_data_len);
  1483. sg_src.dma_address = (dma_addr_t)user_src;
  1484. sg_dst.dma_address = (dma_addr_t)user_dst;
  1485. areq->cipher_req.creq.cryptlen = transfer_data_len;
  1486. sg_src.length = transfer_data_len;
  1487. sg_dst.length = transfer_data_len;
  1488. err = submit_req(areq, handle);
  1489. if (err) {
  1490. pr_err("%s: Error processing req, err = %d\n",
  1491. __func__, err);
  1492. goto exit;
  1493. }
  1494. /* update data len to be processed */
  1495. pending_data_len -= transfer_data_len;
  1496. user_src += transfer_data_len;
  1497. user_dst += transfer_data_len;
  1498. }
  1499. }
  1500. exit:
  1501. return err;
  1502. }
  1503. static int qcedev_check_cipher_key(struct qcedev_cipher_op_req *req,
  1504. struct qcedev_control *podev)
  1505. {
  1506. /* if intending to use HW key make sure key fields are set
  1507. * correctly and HW key is indeed supported in target
  1508. */
  1509. if (req->encklen == 0) {
  1510. int i;
  1511. for (i = 0; i < QCEDEV_MAX_KEY_SIZE; i++) {
  1512. if (req->enckey[i]) {
  1513. pr_err("%s: Invalid key: non-zero key input\n",
  1514. __func__);
  1515. goto error;
  1516. }
  1517. }
  1518. if ((req->op != QCEDEV_OPER_ENC_NO_KEY) &&
  1519. (req->op != QCEDEV_OPER_DEC_NO_KEY))
  1520. if (!podev->platform_support.hw_key_support) {
  1521. pr_err("%s: Invalid op %d\n", __func__,
  1522. (uint32_t)req->op);
  1523. goto error;
  1524. }
  1525. } else {
  1526. if (req->encklen == QCEDEV_AES_KEY_192) {
  1527. if (!podev->ce_support.aes_key_192) {
  1528. pr_err("%s: AES-192 not supported\n", __func__);
  1529. goto error;
  1530. }
  1531. } else {
  1532. /* if not using HW key make sure key
  1533. * length is valid
  1534. */
  1535. if (req->mode == QCEDEV_AES_MODE_XTS) {
  1536. if ((req->encklen != QCEDEV_AES_KEY_128*2) &&
  1537. (req->encklen != QCEDEV_AES_KEY_256*2)) {
  1538. pr_err("%s: unsupported key size: %d\n",
  1539. __func__, req->encklen);
  1540. goto error;
  1541. }
  1542. } else {
  1543. if ((req->encklen != QCEDEV_AES_KEY_128) &&
  1544. (req->encklen != QCEDEV_AES_KEY_256)) {
  1545. pr_err("%s: unsupported key size %d\n",
  1546. __func__, req->encklen);
  1547. goto error;
  1548. }
  1549. }
  1550. }
  1551. }
  1552. return 0;
  1553. error:
  1554. return -EINVAL;
  1555. }
  1556. static int qcedev_check_cipher_params(struct qcedev_cipher_op_req *req,
  1557. struct qcedev_control *podev)
  1558. {
  1559. uint32_t total = 0;
  1560. uint32_t i;
  1561. if (req->use_pmem) {
  1562. pr_err("%s: Use of PMEM is not supported\n", __func__);
  1563. goto error;
  1564. }
  1565. if ((req->entries == 0) || (req->data_len == 0) ||
  1566. (req->entries > QCEDEV_MAX_BUFFERS)) {
  1567. pr_err("%s: Invalid cipher length/entries\n", __func__);
  1568. goto error;
  1569. }
  1570. if ((req->alg >= QCEDEV_ALG_LAST) ||
  1571. (req->mode >= QCEDEV_AES_DES_MODE_LAST)) {
  1572. pr_err("%s: Invalid algorithm %d\n", __func__,
  1573. (uint32_t)req->alg);
  1574. goto error;
  1575. }
  1576. if ((req->mode == QCEDEV_AES_MODE_XTS) &&
  1577. (!podev->ce_support.aes_xts)) {
  1578. pr_err("%s: XTS algorithm is not supported\n", __func__);
  1579. goto error;
  1580. }
  1581. if (req->alg == QCEDEV_ALG_AES) {
  1582. if (qcedev_check_cipher_key(req, podev))
  1583. goto error;
  1584. }
  1585. /* if using a byteoffset, make sure it is CTR mode using vbuf */
  1586. if (req->byteoffset) {
  1587. if (req->mode != QCEDEV_AES_MODE_CTR) {
  1588. pr_err("%s: Operation on byte offset not supported\n",
  1589. __func__);
  1590. goto error;
  1591. }
  1592. if (req->byteoffset >= AES_CE_BLOCK_SIZE) {
  1593. pr_err("%s: Invalid byte offset\n", __func__);
  1594. goto error;
  1595. }
  1596. total = req->byteoffset;
  1597. for (i = 0; i < req->entries; i++) {
  1598. if (total > U32_MAX - req->vbuf.src[i].len) {
  1599. pr_err("%s:Integer overflow on total src len\n",
  1600. __func__);
  1601. goto error;
  1602. }
  1603. total += req->vbuf.src[i].len;
  1604. }
  1605. }
  1606. if (req->data_len < req->byteoffset) {
  1607. pr_err("%s: req data length %u is less than byteoffset %u\n",
  1608. __func__, req->data_len, req->byteoffset);
  1609. goto error;
  1610. }
  1611. /* Ensure IV size */
  1612. if (req->ivlen > QCEDEV_MAX_IV_SIZE) {
  1613. pr_err("%s: ivlen is not correct: %u\n", __func__, req->ivlen);
  1614. goto error;
  1615. }
  1616. /* Ensure Key size */
  1617. if (req->encklen > QCEDEV_MAX_KEY_SIZE) {
  1618. pr_err("%s: Klen is not correct: %u\n", __func__, req->encklen);
  1619. goto error;
  1620. }
  1621. /* Ensure zer ivlen for ECB mode */
  1622. if (req->ivlen > 0) {
  1623. if ((req->mode == QCEDEV_AES_MODE_ECB) ||
  1624. (req->mode == QCEDEV_DES_MODE_ECB)) {
  1625. pr_err("%s: Expecting a zero length IV\n", __func__);
  1626. goto error;
  1627. }
  1628. } else {
  1629. if ((req->mode != QCEDEV_AES_MODE_ECB) &&
  1630. (req->mode != QCEDEV_DES_MODE_ECB)) {
  1631. pr_err("%s: Expecting a non-zero ength IV\n", __func__);
  1632. goto error;
  1633. }
  1634. }
  1635. /* Check for sum of all dst length is equal to data_len */
  1636. for (i = 0, total = 0; i < req->entries; i++) {
  1637. if (!req->vbuf.dst[i].vaddr && req->vbuf.dst[i].len) {
  1638. pr_err("%s: NULL req dst vbuf[%d] with length %d\n",
  1639. __func__, i, req->vbuf.dst[i].len);
  1640. goto error;
  1641. }
  1642. if (req->vbuf.dst[i].len >= U32_MAX - total) {
  1643. pr_err("%s: Integer overflow on total req dst vbuf length\n",
  1644. __func__);
  1645. goto error;
  1646. }
  1647. total += req->vbuf.dst[i].len;
  1648. }
  1649. if (total != req->data_len) {
  1650. pr_err("%s: Total (i=%d) dst(%d) buf size != data_len (%d)\n",
  1651. __func__, i, total, req->data_len);
  1652. goto error;
  1653. }
  1654. /* Check for sum of all src length is equal to data_len */
  1655. for (i = 0, total = 0; i < req->entries; i++) {
  1656. if (!req->vbuf.src[i].vaddr && req->vbuf.src[i].len) {
  1657. pr_err("%s: NULL req src vbuf[%d] with length %d\n",
  1658. __func__, i, req->vbuf.src[i].len);
  1659. goto error;
  1660. }
  1661. if (req->vbuf.src[i].len > U32_MAX - total) {
  1662. pr_err("%s: Integer overflow on total req src vbuf length\n",
  1663. __func__);
  1664. goto error;
  1665. }
  1666. total += req->vbuf.src[i].len;
  1667. }
  1668. if (total != req->data_len) {
  1669. pr_err("%s: Total src(%d) buf size != data_len (%d)\n",
  1670. __func__, total, req->data_len);
  1671. goto error;
  1672. }
  1673. return 0;
  1674. error:
  1675. return -EINVAL;
  1676. }
  1677. static int qcedev_check_sha_params(struct qcedev_sha_op_req *req,
  1678. struct qcedev_control *podev)
  1679. {
  1680. uint32_t total = 0;
  1681. uint32_t i;
  1682. if ((req->alg == QCEDEV_ALG_AES_CMAC) &&
  1683. (!podev->ce_support.cmac)) {
  1684. pr_err("%s: CMAC not supported\n", __func__);
  1685. goto sha_error;
  1686. }
  1687. if ((!req->entries) || (req->entries > QCEDEV_MAX_BUFFERS)) {
  1688. pr_err("%s: Invalid num entries (%d)\n",
  1689. __func__, req->entries);
  1690. goto sha_error;
  1691. }
  1692. if (req->alg >= QCEDEV_ALG_SHA_ALG_LAST) {
  1693. pr_err("%s: Invalid algorithm (%d)\n", __func__, req->alg);
  1694. goto sha_error;
  1695. }
  1696. if ((req->alg == QCEDEV_ALG_SHA1_HMAC) ||
  1697. (req->alg == QCEDEV_ALG_SHA256_HMAC)) {
  1698. if (req->authkey == NULL) {
  1699. pr_err("%s: Invalid authkey pointer\n", __func__);
  1700. goto sha_error;
  1701. }
  1702. if (req->authklen <= 0) {
  1703. pr_err("%s: Invalid authkey length (%d)\n",
  1704. __func__, req->authklen);
  1705. goto sha_error;
  1706. }
  1707. }
  1708. if (req->alg == QCEDEV_ALG_AES_CMAC) {
  1709. if ((req->authklen != QCEDEV_AES_KEY_128) &&
  1710. (req->authklen != QCEDEV_AES_KEY_256)) {
  1711. pr_err("%s: unsupported key length\n", __func__);
  1712. goto sha_error;
  1713. }
  1714. }
  1715. /* Check for sum of all src length is equal to data_len */
  1716. for (i = 0, total = 0; i < req->entries; i++) {
  1717. if (req->data[i].len > U32_MAX - total) {
  1718. pr_err("%s: Integer overflow on total req buf length\n",
  1719. __func__);
  1720. goto sha_error;
  1721. }
  1722. total += req->data[i].len;
  1723. }
  1724. if (total != req->data_len) {
  1725. pr_err("%s: Total src(%d) buf size != data_len (%d)\n",
  1726. __func__, total, req->data_len);
  1727. goto sha_error;
  1728. }
  1729. return 0;
  1730. sha_error:
  1731. return -EINVAL;
  1732. }
  1733. static int qcedev_check_offload_cipher_key(struct qcedev_offload_cipher_op_req *req,
  1734. struct qcedev_control *podev)
  1735. {
  1736. if (req->encklen == 0)
  1737. return -EINVAL;
  1738. /* AES-192 is not a valid option for OFFLOAD use case */
  1739. if ((req->encklen != QCEDEV_AES_KEY_128) &&
  1740. (req->encklen != QCEDEV_AES_KEY_256)) {
  1741. pr_err("%s: unsupported key size %d\n",
  1742. __func__, req->encklen);
  1743. goto error;
  1744. }
  1745. return 0;
  1746. error:
  1747. return -EINVAL;
  1748. }
  1749. static int qcedev_check_offload_cipher_params(struct qcedev_offload_cipher_op_req *req,
  1750. struct qcedev_control *podev)
  1751. {
  1752. uint32_t total = 0;
  1753. int i = 0;
  1754. if ((req->entries == 0) || (req->data_len == 0) ||
  1755. (req->entries > QCEDEV_MAX_BUFFERS)) {
  1756. pr_err("%s: Invalid cipher length/entries\n", __func__);
  1757. goto error;
  1758. }
  1759. if ((req->alg != QCEDEV_ALG_AES) ||
  1760. (req->mode > QCEDEV_AES_MODE_CTR)) {
  1761. pr_err("%s: Invalid algorithm %d\n", __func__,
  1762. (uint32_t)req->alg);
  1763. goto error;
  1764. }
  1765. if (qcedev_check_offload_cipher_key(req, podev))
  1766. goto error;
  1767. if (req->block_offset >= AES_CE_BLOCK_SIZE)
  1768. goto error;
  1769. /* if using a byteoffset, make sure it is CTR mode using vbuf */
  1770. if (req->byteoffset) {
  1771. if (req->mode != QCEDEV_AES_MODE_CTR) {
  1772. pr_err("%s: Operation on byte offset not supported\n",
  1773. __func__);
  1774. goto error;
  1775. }
  1776. if (req->byteoffset >= AES_CE_BLOCK_SIZE) {
  1777. pr_err("%s: Invalid byte offset\n", __func__);
  1778. goto error;
  1779. }
  1780. total = req->byteoffset;
  1781. for (i = 0; i < req->entries; i++) {
  1782. if (total > U32_MAX - req->vbuf.src[i].len) {
  1783. pr_err("%s:Int overflow on total src len\n",
  1784. __func__);
  1785. goto error;
  1786. }
  1787. total += req->vbuf.src[i].len;
  1788. }
  1789. }
  1790. if (req->data_len < req->byteoffset) {
  1791. pr_err("%s: req data length %u is less than byteoffset %u\n",
  1792. __func__, req->data_len, req->byteoffset);
  1793. goto error;
  1794. }
  1795. /* Ensure IV size */
  1796. if (req->ivlen > QCEDEV_MAX_IV_SIZE) {
  1797. pr_err("%s: ivlen is not correct: %u\n", __func__, req->ivlen);
  1798. goto error;
  1799. }
  1800. /* Ensure Key size */
  1801. if (req->encklen > QCEDEV_MAX_KEY_SIZE) {
  1802. pr_err("%s: Klen is not correct: %u\n", __func__,
  1803. req->encklen);
  1804. goto error;
  1805. }
  1806. /* Check for sum of all dst length is equal to data_len */
  1807. for (i = 0, total = 0; i < req->entries; i++) {
  1808. if (!req->vbuf.dst[i].vaddr && req->vbuf.dst[i].len) {
  1809. pr_err("%s: NULL req dst vbuf[%d] with length %d\n",
  1810. __func__, i, req->vbuf.dst[i].len);
  1811. goto error;
  1812. }
  1813. if (req->vbuf.dst[i].len >= U32_MAX - total) {
  1814. pr_err("%s: Int overflow on total req dst vbuf len\n",
  1815. __func__);
  1816. goto error;
  1817. }
  1818. total += req->vbuf.dst[i].len;
  1819. }
  1820. if (total != req->data_len) {
  1821. pr_err("%s: Total (i=%d) dst(%d) buf size != data_len (%d)\n",
  1822. __func__, i, total, req->data_len);
  1823. goto error;
  1824. }
  1825. /* Check for sum of all src length is equal to data_len */
  1826. for (i = 0, total = 0; i < req->entries; i++) {
  1827. if (!req->vbuf.src[i].vaddr && req->vbuf.src[i].len) {
  1828. pr_err("%s: NULL req src vbuf[%d] with length %d\n",
  1829. __func__, i, req->vbuf.src[i].len);
  1830. goto error;
  1831. }
  1832. if (req->vbuf.src[i].len > U32_MAX - total) {
  1833. pr_err("%s: Int overflow on total req src vbuf len\n",
  1834. __func__);
  1835. goto error;
  1836. }
  1837. total += req->vbuf.src[i].len;
  1838. }
  1839. if (total != req->data_len) {
  1840. pr_err("%s: Total src(%d) buf size != data_len (%d)\n",
  1841. __func__, total, req->data_len);
  1842. goto error;
  1843. }
  1844. return 0;
  1845. error:
  1846. return -EINVAL;
  1847. }
  1848. long qcedev_ioctl(struct file *file,
  1849. unsigned int cmd, unsigned long arg)
  1850. {
  1851. int err = 0;
  1852. struct qcedev_handle *handle;
  1853. struct qcedev_control *podev;
  1854. struct qcedev_async_req *qcedev_areq;
  1855. struct qcedev_stat *pstat;
  1856. qcedev_areq = kzalloc(sizeof(struct qcedev_async_req), GFP_KERNEL);
  1857. if (!qcedev_areq)
  1858. return -ENOMEM;
  1859. handle = file->private_data;
  1860. podev = handle->cntl;
  1861. qcedev_areq->handle = handle;
  1862. if (podev == NULL || podev->magic != QCEDEV_MAGIC) {
  1863. pr_err("%s: invalid handle %pK\n",
  1864. __func__, podev);
  1865. err = -ENOENT;
  1866. goto exit_free_qcedev_areq;
  1867. }
  1868. /* Verify user arguments. */
  1869. if (_IOC_TYPE(cmd) != QCEDEV_IOC_MAGIC) {
  1870. err = -ENOTTY;
  1871. goto exit_free_qcedev_areq;
  1872. }
  1873. init_completion(&qcedev_areq->complete);
  1874. pstat = &_qcedev_stat;
  1875. switch (cmd) {
  1876. case QCEDEV_IOCTL_ENC_REQ:
  1877. case QCEDEV_IOCTL_DEC_REQ:
  1878. if (copy_from_user(&qcedev_areq->cipher_op_req,
  1879. (void __user *)arg,
  1880. sizeof(struct qcedev_cipher_op_req))) {
  1881. err = -EFAULT;
  1882. goto exit_free_qcedev_areq;
  1883. }
  1884. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_CIPHER;
  1885. if (qcedev_check_cipher_params(&qcedev_areq->cipher_op_req,
  1886. podev)) {
  1887. err = -EINVAL;
  1888. goto exit_free_qcedev_areq;
  1889. }
  1890. err = qcedev_vbuf_ablk_cipher(qcedev_areq, handle);
  1891. if (err)
  1892. goto exit_free_qcedev_areq;
  1893. if (copy_to_user((void __user *)arg,
  1894. &qcedev_areq->cipher_op_req,
  1895. sizeof(struct qcedev_cipher_op_req))) {
  1896. err = -EFAULT;
  1897. goto exit_free_qcedev_areq;
  1898. }
  1899. break;
  1900. case QCEDEV_IOCTL_OFFLOAD_OP_REQ:
  1901. if (copy_from_user(&qcedev_areq->offload_cipher_op_req,
  1902. (void __user *)arg,
  1903. sizeof(struct qcedev_offload_cipher_op_req))) {
  1904. err = -EFAULT;
  1905. goto exit_free_qcedev_areq;
  1906. }
  1907. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_OFFLOAD_CIPHER;
  1908. if (qcedev_check_offload_cipher_params(
  1909. &qcedev_areq->offload_cipher_op_req, podev)) {
  1910. err = -EINVAL;
  1911. goto exit_free_qcedev_areq;
  1912. }
  1913. qcedev_areq->offload_cipher_op_req.err = QCEDEV_OFFLOAD_NO_ERROR;
  1914. err = qcedev_smmu_ablk_offload_cipher(qcedev_areq, handle);
  1915. if (err)
  1916. goto exit_free_qcedev_areq;
  1917. if (copy_to_user((void __user *)arg,
  1918. &qcedev_areq->offload_cipher_op_req,
  1919. sizeof(struct qcedev_offload_cipher_op_req))) {
  1920. err = -EFAULT;
  1921. goto exit_free_qcedev_areq;
  1922. }
  1923. break;
  1924. case QCEDEV_IOCTL_SHA_INIT_REQ:
  1925. {
  1926. struct scatterlist sg_src;
  1927. if (copy_from_user(&qcedev_areq->sha_op_req,
  1928. (void __user *)arg,
  1929. sizeof(struct qcedev_sha_op_req))) {
  1930. err = -EFAULT;
  1931. goto exit_free_qcedev_areq;
  1932. }
  1933. mutex_lock(&hash_access_lock);
  1934. if (qcedev_check_sha_params(&qcedev_areq->sha_op_req, podev)) {
  1935. mutex_unlock(&hash_access_lock);
  1936. err = -EINVAL;
  1937. goto exit_free_qcedev_areq;
  1938. }
  1939. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_SHA;
  1940. err = qcedev_hash_init(qcedev_areq, handle, &sg_src);
  1941. if (err) {
  1942. mutex_unlock(&hash_access_lock);
  1943. goto exit_free_qcedev_areq;
  1944. }
  1945. mutex_unlock(&hash_access_lock);
  1946. if (copy_to_user((void __user *)arg, &qcedev_areq->sha_op_req,
  1947. sizeof(struct qcedev_sha_op_req))) {
  1948. err = -EFAULT;
  1949. goto exit_free_qcedev_areq;
  1950. }
  1951. handle->sha_ctxt.init_done = true;
  1952. }
  1953. break;
  1954. case QCEDEV_IOCTL_GET_CMAC_REQ:
  1955. if (!podev->ce_support.cmac) {
  1956. err = -ENOTTY;
  1957. goto exit_free_qcedev_areq;
  1958. }
  1959. fallthrough;
  1960. case QCEDEV_IOCTL_SHA_UPDATE_REQ:
  1961. {
  1962. struct scatterlist sg_src;
  1963. if (copy_from_user(&qcedev_areq->sha_op_req,
  1964. (void __user *)arg,
  1965. sizeof(struct qcedev_sha_op_req))) {
  1966. err = -EFAULT;
  1967. goto exit_free_qcedev_areq;
  1968. }
  1969. mutex_lock(&hash_access_lock);
  1970. if (qcedev_check_sha_params(&qcedev_areq->sha_op_req, podev)) {
  1971. mutex_unlock(&hash_access_lock);
  1972. err = -EINVAL;
  1973. goto exit_free_qcedev_areq;
  1974. }
  1975. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_SHA;
  1976. if (qcedev_areq->sha_op_req.alg == QCEDEV_ALG_AES_CMAC) {
  1977. err = qcedev_hash_cmac(qcedev_areq, handle, &sg_src);
  1978. if (err) {
  1979. mutex_unlock(&hash_access_lock);
  1980. goto exit_free_qcedev_areq;
  1981. }
  1982. } else {
  1983. if (!handle->sha_ctxt.init_done) {
  1984. pr_err("%s Init was not called\n", __func__);
  1985. mutex_unlock(&hash_access_lock);
  1986. err = -EINVAL;
  1987. goto exit_free_qcedev_areq;
  1988. }
  1989. err = qcedev_hash_update(qcedev_areq, handle, &sg_src);
  1990. if (err) {
  1991. mutex_unlock(&hash_access_lock);
  1992. goto exit_free_qcedev_areq;
  1993. }
  1994. }
  1995. if (handle->sha_ctxt.diglen > QCEDEV_MAX_SHA_DIGEST) {
  1996. pr_err("Invalid sha_ctxt.diglen %d\n",
  1997. handle->sha_ctxt.diglen);
  1998. mutex_unlock(&hash_access_lock);
  1999. err = -EINVAL;
  2000. goto exit_free_qcedev_areq;
  2001. }
  2002. memcpy(&qcedev_areq->sha_op_req.digest[0],
  2003. &handle->sha_ctxt.digest[0],
  2004. handle->sha_ctxt.diglen);
  2005. mutex_unlock(&hash_access_lock);
  2006. if (copy_to_user((void __user *)arg, &qcedev_areq->sha_op_req,
  2007. sizeof(struct qcedev_sha_op_req))) {
  2008. err = -EFAULT;
  2009. goto exit_free_qcedev_areq;
  2010. }
  2011. }
  2012. break;
  2013. case QCEDEV_IOCTL_SHA_FINAL_REQ:
  2014. if (!handle->sha_ctxt.init_done) {
  2015. pr_err("%s Init was not called\n", __func__);
  2016. err = -EINVAL;
  2017. goto exit_free_qcedev_areq;
  2018. }
  2019. if (copy_from_user(&qcedev_areq->sha_op_req,
  2020. (void __user *)arg,
  2021. sizeof(struct qcedev_sha_op_req))) {
  2022. err = -EFAULT;
  2023. goto exit_free_qcedev_areq;
  2024. }
  2025. mutex_lock(&hash_access_lock);
  2026. if (qcedev_check_sha_params(&qcedev_areq->sha_op_req, podev)) {
  2027. mutex_unlock(&hash_access_lock);
  2028. err = -EINVAL;
  2029. goto exit_free_qcedev_areq;
  2030. }
  2031. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_SHA;
  2032. err = qcedev_hash_final(qcedev_areq, handle);
  2033. if (err) {
  2034. mutex_unlock(&hash_access_lock);
  2035. goto exit_free_qcedev_areq;
  2036. }
  2037. if (handle->sha_ctxt.diglen > QCEDEV_MAX_SHA_DIGEST) {
  2038. pr_err("Invalid sha_ctxt.diglen %d\n",
  2039. handle->sha_ctxt.diglen);
  2040. mutex_unlock(&hash_access_lock);
  2041. err = -EINVAL;
  2042. goto exit_free_qcedev_areq;
  2043. }
  2044. qcedev_areq->sha_op_req.diglen = handle->sha_ctxt.diglen;
  2045. memcpy(&qcedev_areq->sha_op_req.digest[0],
  2046. &handle->sha_ctxt.digest[0],
  2047. handle->sha_ctxt.diglen);
  2048. mutex_unlock(&hash_access_lock);
  2049. if (copy_to_user((void __user *)arg, &qcedev_areq->sha_op_req,
  2050. sizeof(struct qcedev_sha_op_req))) {
  2051. err = -EFAULT;
  2052. goto exit_free_qcedev_areq;
  2053. }
  2054. handle->sha_ctxt.init_done = false;
  2055. break;
  2056. case QCEDEV_IOCTL_GET_SHA_REQ:
  2057. {
  2058. struct scatterlist sg_src;
  2059. if (copy_from_user(&qcedev_areq->sha_op_req,
  2060. (void __user *)arg,
  2061. sizeof(struct qcedev_sha_op_req))) {
  2062. err = -EFAULT;
  2063. goto exit_free_qcedev_areq;
  2064. }
  2065. mutex_lock(&hash_access_lock);
  2066. if (qcedev_check_sha_params(&qcedev_areq->sha_op_req, podev)) {
  2067. mutex_unlock(&hash_access_lock);
  2068. err = -EINVAL;
  2069. goto exit_free_qcedev_areq;
  2070. }
  2071. qcedev_areq->op_type = QCEDEV_CRYPTO_OPER_SHA;
  2072. qcedev_hash_init(qcedev_areq, handle, &sg_src);
  2073. err = qcedev_hash_update(qcedev_areq, handle, &sg_src);
  2074. if (err) {
  2075. mutex_unlock(&hash_access_lock);
  2076. goto exit_free_qcedev_areq;
  2077. }
  2078. err = qcedev_hash_final(qcedev_areq, handle);
  2079. if (err) {
  2080. mutex_unlock(&hash_access_lock);
  2081. goto exit_free_qcedev_areq;
  2082. }
  2083. if (handle->sha_ctxt.diglen > QCEDEV_MAX_SHA_DIGEST) {
  2084. pr_err("Invalid sha_ctxt.diglen %d\n",
  2085. handle->sha_ctxt.diglen);
  2086. mutex_unlock(&hash_access_lock);
  2087. err = -EINVAL;
  2088. goto exit_free_qcedev_areq;
  2089. }
  2090. qcedev_areq->sha_op_req.diglen = handle->sha_ctxt.diglen;
  2091. memcpy(&qcedev_areq->sha_op_req.digest[0],
  2092. &handle->sha_ctxt.digest[0],
  2093. handle->sha_ctxt.diglen);
  2094. mutex_unlock(&hash_access_lock);
  2095. if (copy_to_user((void __user *)arg, &qcedev_areq->sha_op_req,
  2096. sizeof(struct qcedev_sha_op_req))) {
  2097. err = -EFAULT;
  2098. goto exit_free_qcedev_areq;
  2099. }
  2100. }
  2101. break;
  2102. case QCEDEV_IOCTL_MAP_BUF_REQ:
  2103. {
  2104. unsigned long long vaddr = 0;
  2105. struct qcedev_map_buf_req map_buf = { {0} };
  2106. int i = 0;
  2107. if (copy_from_user(&map_buf,
  2108. (void __user *)arg, sizeof(map_buf))) {
  2109. err = -EFAULT;
  2110. goto exit_free_qcedev_areq;
  2111. }
  2112. if (map_buf.num_fds > ARRAY_SIZE(map_buf.fd)) {
  2113. pr_err("%s: err: num_fds = %d exceeds max value\n",
  2114. __func__, map_buf.num_fds);
  2115. err = -EINVAL;
  2116. goto exit_free_qcedev_areq;
  2117. }
  2118. for (i = 0; i < map_buf.num_fds; i++) {
  2119. err = qcedev_check_and_map_buffer(handle,
  2120. map_buf.fd[i],
  2121. map_buf.fd_offset[i],
  2122. map_buf.fd_size[i],
  2123. &vaddr);
  2124. if (err) {
  2125. pr_err(
  2126. "%s: err: failed to map fd(%d) - %d\n",
  2127. __func__, map_buf.fd[i], err);
  2128. goto exit_free_qcedev_areq;
  2129. }
  2130. map_buf.buf_vaddr[i] = vaddr;
  2131. pr_info("%s: info: vaddr = %llx\n, fd = %d",
  2132. __func__, vaddr, map_buf.fd[i]);
  2133. }
  2134. if (copy_to_user((void __user *)arg, &map_buf,
  2135. sizeof(map_buf))) {
  2136. err = -EFAULT;
  2137. goto exit_free_qcedev_areq;
  2138. }
  2139. break;
  2140. }
  2141. case QCEDEV_IOCTL_UNMAP_BUF_REQ:
  2142. {
  2143. struct qcedev_unmap_buf_req unmap_buf = { { 0 } };
  2144. int i = 0;
  2145. if (copy_from_user(&unmap_buf,
  2146. (void __user *)arg, sizeof(unmap_buf))) {
  2147. err = -EFAULT;
  2148. goto exit_free_qcedev_areq;
  2149. }
  2150. if (unmap_buf.num_fds > ARRAY_SIZE(unmap_buf.fd)) {
  2151. pr_err("%s: err: num_fds = %d exceeds max value\n",
  2152. __func__, unmap_buf.num_fds);
  2153. err = -EINVAL;
  2154. goto exit_free_qcedev_areq;
  2155. }
  2156. for (i = 0; i < unmap_buf.num_fds; i++) {
  2157. err = qcedev_check_and_unmap_buffer(handle,
  2158. unmap_buf.fd[i]);
  2159. if (err) {
  2160. pr_err(
  2161. "%s: err: failed to unmap fd(%d) - %d\n",
  2162. __func__,
  2163. unmap_buf.fd[i], err);
  2164. goto exit_free_qcedev_areq;
  2165. }
  2166. }
  2167. break;
  2168. }
  2169. default:
  2170. err = -ENOTTY;
  2171. goto exit_free_qcedev_areq;
  2172. }
  2173. exit_free_qcedev_areq:
  2174. kfree(qcedev_areq);
  2175. return err;
  2176. }
  2177. static int qcedev_probe_device(struct platform_device *pdev)
  2178. {
  2179. void *handle = NULL;
  2180. int rc = 0;
  2181. struct qcedev_control *podev;
  2182. struct msm_ce_hw_support *platform_support;
  2183. podev = &qce_dev[0];
  2184. rc = alloc_chrdev_region(&qcedev_device_no, 0, 1, QCEDEV_DEV);
  2185. if (rc < 0) {
  2186. pr_err("alloc_chrdev_region failed %d\n", rc);
  2187. return rc;
  2188. }
  2189. driver_class = class_create(THIS_MODULE, QCEDEV_DEV);
  2190. if (IS_ERR(driver_class)) {
  2191. rc = -ENOMEM;
  2192. pr_err("class_create failed %d\n", rc);
  2193. goto exit_unreg_chrdev_region;
  2194. }
  2195. class_dev = device_create(driver_class, NULL, qcedev_device_no, NULL,
  2196. QCEDEV_DEV);
  2197. if (IS_ERR(class_dev)) {
  2198. pr_err("class_device_create failed %d\n", rc);
  2199. rc = -ENOMEM;
  2200. goto exit_destroy_class;
  2201. }
  2202. cdev_init(&podev->cdev, &qcedev_fops);
  2203. podev->cdev.owner = THIS_MODULE;
  2204. rc = cdev_add(&podev->cdev, MKDEV(MAJOR(qcedev_device_no), 0), 1);
  2205. if (rc < 0) {
  2206. pr_err("cdev_add failed %d\n", rc);
  2207. goto exit_destroy_device;
  2208. }
  2209. podev->minor = 0;
  2210. podev->high_bw_req_count = 0;
  2211. INIT_LIST_HEAD(&podev->ready_commands);
  2212. podev->active_command = NULL;
  2213. INIT_LIST_HEAD(&podev->context_banks);
  2214. spin_lock_init(&podev->lock);
  2215. tasklet_init(&podev->done_tasklet, req_done, (unsigned long)podev);
  2216. podev->icc_path = of_icc_get(&pdev->dev, "data_path");
  2217. if (IS_ERR(podev->icc_path)) {
  2218. rc = PTR_ERR(podev->icc_path);
  2219. pr_err("%s Failed to get icc path with error %d\n",
  2220. __func__, rc);
  2221. goto exit_del_cdev;
  2222. }
  2223. /*
  2224. * HLOS crypto vote values from DTSI. If no values specified, use
  2225. * nominal values.
  2226. */
  2227. if (of_property_read_u32((&pdev->dev)->of_node,
  2228. "qcom,icc_avg_bw",
  2229. &podev->icc_avg_bw)) {
  2230. pr_warn("%s: No icc avg BW set, using default\n", __func__);
  2231. podev->icc_avg_bw = CRYPTO_AVG_BW;
  2232. }
  2233. if (of_property_read_u32((&pdev->dev)->of_node,
  2234. "qcom,icc_peak_bw",
  2235. &podev->icc_peak_bw)) {
  2236. pr_warn("%s: No icc peak BW set, using default\n", __func__);
  2237. podev->icc_peak_bw = CRYPTO_PEAK_BW;
  2238. }
  2239. rc = icc_set_bw(podev->icc_path, podev->icc_avg_bw,
  2240. podev->icc_peak_bw);
  2241. if (rc) {
  2242. pr_err("%s Unable to set high bandwidth\n", __func__);
  2243. goto exit_unregister_bus_scale;
  2244. }
  2245. handle = qce_open(pdev, &rc);
  2246. if (handle == NULL) {
  2247. rc = -ENODEV;
  2248. goto exit_scale_busbandwidth;
  2249. }
  2250. rc = icc_set_bw(podev->icc_path, 0, 0);
  2251. if (rc) {
  2252. pr_err("%s Unable to set to low bandwidth\n", __func__);
  2253. goto exit_qce_close;
  2254. }
  2255. podev->qce = handle;
  2256. podev->pdev = pdev;
  2257. platform_set_drvdata(pdev, podev);
  2258. qce_hw_support(podev->qce, &podev->ce_support);
  2259. if (podev->ce_support.bam) {
  2260. podev->platform_support.ce_shared = 0;
  2261. podev->platform_support.shared_ce_resource = 0;
  2262. podev->platform_support.hw_key_support =
  2263. podev->ce_support.hw_key;
  2264. podev->platform_support.sha_hmac = 1;
  2265. } else {
  2266. platform_support =
  2267. (struct msm_ce_hw_support *)pdev->dev.platform_data;
  2268. podev->platform_support.ce_shared = platform_support->ce_shared;
  2269. podev->platform_support.shared_ce_resource =
  2270. platform_support->shared_ce_resource;
  2271. podev->platform_support.hw_key_support =
  2272. platform_support->hw_key_support;
  2273. podev->platform_support.sha_hmac = platform_support->sha_hmac;
  2274. }
  2275. podev->mem_client = qcedev_mem_new_client(MEM_ION);
  2276. if (!podev->mem_client) {
  2277. pr_err("%s: err: qcedev_mem_new_client failed\n", __func__);
  2278. goto exit_qce_close;
  2279. }
  2280. rc = of_platform_populate(pdev->dev.of_node, qcedev_match,
  2281. NULL, &pdev->dev);
  2282. if (rc) {
  2283. pr_err("%s: err: of_platform_populate failed: %d\n",
  2284. __func__, rc);
  2285. goto exit_mem_new_client;
  2286. }
  2287. return 0;
  2288. exit_mem_new_client:
  2289. if (podev->mem_client)
  2290. qcedev_mem_delete_client(podev->mem_client);
  2291. podev->mem_client = NULL;
  2292. exit_qce_close:
  2293. if (handle)
  2294. qce_close(handle);
  2295. exit_scale_busbandwidth:
  2296. icc_set_bw(podev->icc_path, 0, 0);
  2297. exit_unregister_bus_scale:
  2298. if (podev->icc_path)
  2299. icc_put(podev->icc_path);
  2300. exit_del_cdev:
  2301. cdev_del(&podev->cdev);
  2302. exit_destroy_device:
  2303. device_destroy(driver_class, qcedev_device_no);
  2304. exit_destroy_class:
  2305. class_destroy(driver_class);
  2306. exit_unreg_chrdev_region:
  2307. unregister_chrdev_region(qcedev_device_no, 1);
  2308. podev->icc_path = NULL;
  2309. platform_set_drvdata(pdev, NULL);
  2310. podev->pdev = NULL;
  2311. podev->qce = NULL;
  2312. return rc;
  2313. }
  2314. static int qcedev_probe(struct platform_device *pdev)
  2315. {
  2316. if (of_device_is_compatible(pdev->dev.of_node, "qcom,qcedev"))
  2317. return qcedev_probe_device(pdev);
  2318. else if (of_device_is_compatible(pdev->dev.of_node,
  2319. "qcom,qcedev,context-bank"))
  2320. return qcedev_parse_context_bank(pdev);
  2321. return -EINVAL;
  2322. };
  2323. static int qcedev_remove(struct platform_device *pdev)
  2324. {
  2325. struct qcedev_control *podev;
  2326. podev = platform_get_drvdata(pdev);
  2327. if (!podev)
  2328. return 0;
  2329. if (podev->qce)
  2330. qce_close(podev->qce);
  2331. if (podev->icc_path)
  2332. icc_put(podev->icc_path);
  2333. tasklet_kill(&podev->done_tasklet);
  2334. cdev_del(&podev->cdev);
  2335. device_destroy(driver_class, qcedev_device_no);
  2336. class_destroy(driver_class);
  2337. unregister_chrdev_region(qcedev_device_no, 1);
  2338. return 0;
  2339. };
  2340. static int qcedev_suspend(struct platform_device *pdev, pm_message_t state)
  2341. {
  2342. struct qcedev_control *podev;
  2343. int ret;
  2344. podev = platform_get_drvdata(pdev);
  2345. if (!podev)
  2346. return 0;
  2347. mutex_lock(&qcedev_sent_bw_req);
  2348. if (podev->high_bw_req_count) {
  2349. ret = qcedev_control_clocks(podev, false);
  2350. if (ret)
  2351. goto suspend_exit;
  2352. }
  2353. suspend_exit:
  2354. mutex_unlock(&qcedev_sent_bw_req);
  2355. return 0;
  2356. }
  2357. static int qcedev_resume(struct platform_device *pdev)
  2358. {
  2359. struct qcedev_control *podev;
  2360. int ret;
  2361. podev = platform_get_drvdata(pdev);
  2362. if (!podev)
  2363. return 0;
  2364. mutex_lock(&qcedev_sent_bw_req);
  2365. if (podev->high_bw_req_count) {
  2366. ret = qcedev_control_clocks(podev, true);
  2367. if (ret)
  2368. goto resume_exit;
  2369. }
  2370. resume_exit:
  2371. mutex_unlock(&qcedev_sent_bw_req);
  2372. return 0;
  2373. }
  2374. static struct platform_driver qcedev_plat_driver = {
  2375. .probe = qcedev_probe,
  2376. .remove = qcedev_remove,
  2377. .suspend = qcedev_suspend,
  2378. .resume = qcedev_resume,
  2379. .driver = {
  2380. .name = "qce",
  2381. .of_match_table = qcedev_match,
  2382. },
  2383. };
  2384. static int _disp_stats(int id)
  2385. {
  2386. struct qcedev_stat *pstat;
  2387. int len = 0;
  2388. pstat = &_qcedev_stat;
  2389. len = scnprintf(_debug_read_buf, DEBUG_MAX_RW_BUF - 1,
  2390. "\nQTI QCE dev driver %d Statistics:\n",
  2391. id + 1);
  2392. len += scnprintf(_debug_read_buf + len, DEBUG_MAX_RW_BUF - len - 1,
  2393. " Encryption operation success : %d\n",
  2394. pstat->qcedev_enc_success);
  2395. len += scnprintf(_debug_read_buf + len, DEBUG_MAX_RW_BUF - len - 1,
  2396. " Encryption operation fail : %d\n",
  2397. pstat->qcedev_enc_fail);
  2398. len += scnprintf(_debug_read_buf + len, DEBUG_MAX_RW_BUF - len - 1,
  2399. " Decryption operation success : %d\n",
  2400. pstat->qcedev_dec_success);
  2401. len += scnprintf(_debug_read_buf + len, DEBUG_MAX_RW_BUF - len - 1,
  2402. " Encryption operation fail : %d\n",
  2403. pstat->qcedev_dec_fail);
  2404. return len;
  2405. }
  2406. static ssize_t _debug_stats_read(struct file *file, char __user *buf,
  2407. size_t count, loff_t *ppos)
  2408. {
  2409. ssize_t rc = -EINVAL;
  2410. int qcedev = *((int *) file->private_data);
  2411. int len;
  2412. len = _disp_stats(qcedev);
  2413. if (len <= count)
  2414. rc = simple_read_from_buffer((void __user *) buf, len,
  2415. ppos, (void *) _debug_read_buf, len);
  2416. return rc;
  2417. }
  2418. static ssize_t _debug_stats_write(struct file *file, const char __user *buf,
  2419. size_t count, loff_t *ppos)
  2420. {
  2421. memset((char *)&_qcedev_stat, 0, sizeof(struct qcedev_stat));
  2422. return count;
  2423. };
  2424. static const struct file_operations _debug_stats_ops = {
  2425. .open = simple_open,
  2426. .read = _debug_stats_read,
  2427. .write = _debug_stats_write,
  2428. };
  2429. static int _qcedev_debug_init(void)
  2430. {
  2431. int rc;
  2432. char name[DEBUG_MAX_FNAME];
  2433. struct dentry *dent;
  2434. _debug_dent = debugfs_create_dir("qcedev", NULL);
  2435. if (IS_ERR(_debug_dent)) {
  2436. pr_debug("qcedev debugfs_create_dir fail, error %ld\n",
  2437. PTR_ERR(_debug_dent));
  2438. return PTR_ERR(_debug_dent);
  2439. }
  2440. snprintf(name, DEBUG_MAX_FNAME-1, "stats-%d", 1);
  2441. _debug_qcedev = 0;
  2442. dent = debugfs_create_file(name, 0644, _debug_dent,
  2443. &_debug_qcedev, &_debug_stats_ops);
  2444. if (dent == NULL) {
  2445. pr_debug("qcedev debugfs_create_file fail, error %ld\n",
  2446. PTR_ERR(dent));
  2447. rc = PTR_ERR(dent);
  2448. goto err;
  2449. }
  2450. return 0;
  2451. err:
  2452. debugfs_remove_recursive(_debug_dent);
  2453. return rc;
  2454. }
  2455. static int qcedev_init(void)
  2456. {
  2457. _qcedev_debug_init();
  2458. return platform_driver_register(&qcedev_plat_driver);
  2459. }
  2460. static void qcedev_exit(void)
  2461. {
  2462. debugfs_remove_recursive(_debug_dent);
  2463. platform_driver_unregister(&qcedev_plat_driver);
  2464. }
  2465. MODULE_LICENSE("GPL v2");
  2466. MODULE_DESCRIPTION("QTI DEV Crypto driver");
  2467. MODULE_IMPORT_NS(DMA_BUF);
  2468. module_init(qcedev_init);
  2469. module_exit(qcedev_exit);