talitos.c 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117
  1. /*
  2. * talitos - Freescale Integrated Security Engine (SEC) device driver
  3. *
  4. * Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
  5. *
  6. * Scatterlist Crypto API glue code copied from files with the following:
  7. * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au>
  8. *
  9. * Crypto algorithm registration code copied from hifn driver:
  10. * 2007+ Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
  11. * All rights reserved.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/mod_devicetable.h>
  30. #include <linux/device.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/crypto.h>
  33. #include <linux/hw_random.h>
  34. #include <linux/of_address.h>
  35. #include <linux/of_irq.h>
  36. #include <linux/of_platform.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/io.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/rtnetlink.h>
  41. #include <linux/slab.h>
  42. #include <crypto/algapi.h>
  43. #include <crypto/aes.h>
  44. #include <crypto/des.h>
  45. #include <crypto/sha.h>
  46. #include <crypto/md5.h>
  47. #include <crypto/internal/aead.h>
  48. #include <crypto/authenc.h>
  49. #include <crypto/skcipher.h>
  50. #include <crypto/hash.h>
  51. #include <crypto/internal/hash.h>
  52. #include <crypto/scatterwalk.h>
  53. #include "talitos.h"
  54. static void to_talitos_ptr(struct talitos_ptr *ptr, dma_addr_t dma_addr,
  55. bool is_sec1)
  56. {
  57. ptr->ptr = cpu_to_be32(lower_32_bits(dma_addr));
  58. if (!is_sec1)
  59. ptr->eptr = upper_32_bits(dma_addr);
  60. }
  61. static void to_talitos_ptr_len(struct talitos_ptr *ptr, unsigned int len,
  62. bool is_sec1)
  63. {
  64. if (is_sec1) {
  65. ptr->res = 0;
  66. ptr->len1 = cpu_to_be16(len);
  67. } else {
  68. ptr->len = cpu_to_be16(len);
  69. }
  70. }
  71. static unsigned short from_talitos_ptr_len(struct talitos_ptr *ptr,
  72. bool is_sec1)
  73. {
  74. if (is_sec1)
  75. return be16_to_cpu(ptr->len1);
  76. else
  77. return be16_to_cpu(ptr->len);
  78. }
  79. static void to_talitos_ptr_extent_clear(struct talitos_ptr *ptr, bool is_sec1)
  80. {
  81. if (!is_sec1)
  82. ptr->j_extent = 0;
  83. }
  84. /*
  85. * map virtual single (contiguous) pointer to h/w descriptor pointer
  86. */
  87. static void map_single_talitos_ptr(struct device *dev,
  88. struct talitos_ptr *ptr,
  89. unsigned int len, void *data,
  90. enum dma_data_direction dir)
  91. {
  92. dma_addr_t dma_addr = dma_map_single(dev, data, len, dir);
  93. struct talitos_private *priv = dev_get_drvdata(dev);
  94. bool is_sec1 = has_ftr_sec1(priv);
  95. to_talitos_ptr_len(ptr, len, is_sec1);
  96. to_talitos_ptr(ptr, dma_addr, is_sec1);
  97. to_talitos_ptr_extent_clear(ptr, is_sec1);
  98. }
  99. /*
  100. * unmap bus single (contiguous) h/w descriptor pointer
  101. */
  102. static void unmap_single_talitos_ptr(struct device *dev,
  103. struct talitos_ptr *ptr,
  104. enum dma_data_direction dir)
  105. {
  106. struct talitos_private *priv = dev_get_drvdata(dev);
  107. bool is_sec1 = has_ftr_sec1(priv);
  108. dma_unmap_single(dev, be32_to_cpu(ptr->ptr),
  109. from_talitos_ptr_len(ptr, is_sec1), dir);
  110. }
  111. static int reset_channel(struct device *dev, int ch)
  112. {
  113. struct talitos_private *priv = dev_get_drvdata(dev);
  114. unsigned int timeout = TALITOS_TIMEOUT;
  115. bool is_sec1 = has_ftr_sec1(priv);
  116. if (is_sec1) {
  117. setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO,
  118. TALITOS1_CCCR_LO_RESET);
  119. while ((in_be32(priv->chan[ch].reg + TALITOS_CCCR_LO) &
  120. TALITOS1_CCCR_LO_RESET) && --timeout)
  121. cpu_relax();
  122. } else {
  123. setbits32(priv->chan[ch].reg + TALITOS_CCCR,
  124. TALITOS2_CCCR_RESET);
  125. while ((in_be32(priv->chan[ch].reg + TALITOS_CCCR) &
  126. TALITOS2_CCCR_RESET) && --timeout)
  127. cpu_relax();
  128. }
  129. if (timeout == 0) {
  130. dev_err(dev, "failed to reset channel %d\n", ch);
  131. return -EIO;
  132. }
  133. /* set 36-bit addressing, done writeback enable and done IRQ enable */
  134. setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO, TALITOS_CCCR_LO_EAE |
  135. TALITOS_CCCR_LO_CDWE | TALITOS_CCCR_LO_CDIE);
  136. /* and ICCR writeback, if available */
  137. if (priv->features & TALITOS_FTR_HW_AUTH_CHECK)
  138. setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO,
  139. TALITOS_CCCR_LO_IWSE);
  140. return 0;
  141. }
  142. static int reset_device(struct device *dev)
  143. {
  144. struct talitos_private *priv = dev_get_drvdata(dev);
  145. unsigned int timeout = TALITOS_TIMEOUT;
  146. bool is_sec1 = has_ftr_sec1(priv);
  147. u32 mcr = is_sec1 ? TALITOS1_MCR_SWR : TALITOS2_MCR_SWR;
  148. setbits32(priv->reg + TALITOS_MCR, mcr);
  149. while ((in_be32(priv->reg + TALITOS_MCR) & mcr)
  150. && --timeout)
  151. cpu_relax();
  152. if (priv->irq[1]) {
  153. mcr = TALITOS_MCR_RCA1 | TALITOS_MCR_RCA3;
  154. setbits32(priv->reg + TALITOS_MCR, mcr);
  155. }
  156. if (timeout == 0) {
  157. dev_err(dev, "failed to reset device\n");
  158. return -EIO;
  159. }
  160. return 0;
  161. }
  162. /*
  163. * Reset and initialize the device
  164. */
  165. static int init_device(struct device *dev)
  166. {
  167. struct talitos_private *priv = dev_get_drvdata(dev);
  168. int ch, err;
  169. bool is_sec1 = has_ftr_sec1(priv);
  170. /*
  171. * Master reset
  172. * errata documentation: warning: certain SEC interrupts
  173. * are not fully cleared by writing the MCR:SWR bit,
  174. * set bit twice to completely reset
  175. */
  176. err = reset_device(dev);
  177. if (err)
  178. return err;
  179. err = reset_device(dev);
  180. if (err)
  181. return err;
  182. /* reset channels */
  183. for (ch = 0; ch < priv->num_channels; ch++) {
  184. err = reset_channel(dev, ch);
  185. if (err)
  186. return err;
  187. }
  188. /* enable channel done and error interrupts */
  189. if (is_sec1) {
  190. clrbits32(priv->reg + TALITOS_IMR, TALITOS1_IMR_INIT);
  191. clrbits32(priv->reg + TALITOS_IMR_LO, TALITOS1_IMR_LO_INIT);
  192. /* disable parity error check in DEU (erroneous? test vect.) */
  193. setbits32(priv->reg_deu + TALITOS_EUICR, TALITOS1_DEUICR_KPE);
  194. } else {
  195. setbits32(priv->reg + TALITOS_IMR, TALITOS2_IMR_INIT);
  196. setbits32(priv->reg + TALITOS_IMR_LO, TALITOS2_IMR_LO_INIT);
  197. }
  198. /* disable integrity check error interrupts (use writeback instead) */
  199. if (priv->features & TALITOS_FTR_HW_AUTH_CHECK)
  200. setbits32(priv->reg_mdeu + TALITOS_EUICR_LO,
  201. TALITOS_MDEUICR_LO_ICE);
  202. return 0;
  203. }
  204. /**
  205. * talitos_submit - submits a descriptor to the device for processing
  206. * @dev: the SEC device to be used
  207. * @ch: the SEC device channel to be used
  208. * @desc: the descriptor to be processed by the device
  209. * @callback: whom to call when processing is complete
  210. * @context: a handle for use by caller (optional)
  211. *
  212. * desc must contain valid dma-mapped (bus physical) address pointers.
  213. * callback must check err and feedback in descriptor header
  214. * for device processing status.
  215. */
  216. int talitos_submit(struct device *dev, int ch, struct talitos_desc *desc,
  217. void (*callback)(struct device *dev,
  218. struct talitos_desc *desc,
  219. void *context, int error),
  220. void *context)
  221. {
  222. struct talitos_private *priv = dev_get_drvdata(dev);
  223. struct talitos_request *request;
  224. unsigned long flags;
  225. int head;
  226. bool is_sec1 = has_ftr_sec1(priv);
  227. spin_lock_irqsave(&priv->chan[ch].head_lock, flags);
  228. if (!atomic_inc_not_zero(&priv->chan[ch].submit_count)) {
  229. /* h/w fifo is full */
  230. spin_unlock_irqrestore(&priv->chan[ch].head_lock, flags);
  231. return -EAGAIN;
  232. }
  233. head = priv->chan[ch].head;
  234. request = &priv->chan[ch].fifo[head];
  235. /* map descriptor and save caller data */
  236. if (is_sec1) {
  237. desc->hdr1 = desc->hdr;
  238. desc->next_desc = 0;
  239. request->dma_desc = dma_map_single(dev, &desc->hdr1,
  240. TALITOS_DESC_SIZE,
  241. DMA_BIDIRECTIONAL);
  242. } else {
  243. request->dma_desc = dma_map_single(dev, desc,
  244. TALITOS_DESC_SIZE,
  245. DMA_BIDIRECTIONAL);
  246. }
  247. request->callback = callback;
  248. request->context = context;
  249. /* increment fifo head */
  250. priv->chan[ch].head = (priv->chan[ch].head + 1) & (priv->fifo_len - 1);
  251. smp_wmb();
  252. request->desc = desc;
  253. /* GO! */
  254. wmb();
  255. out_be32(priv->chan[ch].reg + TALITOS_FF,
  256. upper_32_bits(request->dma_desc));
  257. out_be32(priv->chan[ch].reg + TALITOS_FF_LO,
  258. lower_32_bits(request->dma_desc));
  259. spin_unlock_irqrestore(&priv->chan[ch].head_lock, flags);
  260. return -EINPROGRESS;
  261. }
  262. EXPORT_SYMBOL(talitos_submit);
  263. /*
  264. * process what was done, notify callback of error if not
  265. */
  266. static void flush_channel(struct device *dev, int ch, int error, int reset_ch)
  267. {
  268. struct talitos_private *priv = dev_get_drvdata(dev);
  269. struct talitos_request *request, saved_req;
  270. unsigned long flags;
  271. int tail, status;
  272. bool is_sec1 = has_ftr_sec1(priv);
  273. spin_lock_irqsave(&priv->chan[ch].tail_lock, flags);
  274. tail = priv->chan[ch].tail;
  275. while (priv->chan[ch].fifo[tail].desc) {
  276. __be32 hdr;
  277. request = &priv->chan[ch].fifo[tail];
  278. /* descriptors with their done bits set don't get the error */
  279. rmb();
  280. hdr = is_sec1 ? request->desc->hdr1 : request->desc->hdr;
  281. if ((hdr & DESC_HDR_DONE) == DESC_HDR_DONE)
  282. status = 0;
  283. else
  284. if (!error)
  285. break;
  286. else
  287. status = error;
  288. dma_unmap_single(dev, request->dma_desc,
  289. TALITOS_DESC_SIZE,
  290. DMA_BIDIRECTIONAL);
  291. /* copy entries so we can call callback outside lock */
  292. saved_req.desc = request->desc;
  293. saved_req.callback = request->callback;
  294. saved_req.context = request->context;
  295. /* release request entry in fifo */
  296. smp_wmb();
  297. request->desc = NULL;
  298. /* increment fifo tail */
  299. priv->chan[ch].tail = (tail + 1) & (priv->fifo_len - 1);
  300. spin_unlock_irqrestore(&priv->chan[ch].tail_lock, flags);
  301. atomic_dec(&priv->chan[ch].submit_count);
  302. saved_req.callback(dev, saved_req.desc, saved_req.context,
  303. status);
  304. /* channel may resume processing in single desc error case */
  305. if (error && !reset_ch && status == error)
  306. return;
  307. spin_lock_irqsave(&priv->chan[ch].tail_lock, flags);
  308. tail = priv->chan[ch].tail;
  309. }
  310. spin_unlock_irqrestore(&priv->chan[ch].tail_lock, flags);
  311. }
  312. /*
  313. * process completed requests for channels that have done status
  314. */
  315. #define DEF_TALITOS1_DONE(name, ch_done_mask) \
  316. static void talitos1_done_##name(unsigned long data) \
  317. { \
  318. struct device *dev = (struct device *)data; \
  319. struct talitos_private *priv = dev_get_drvdata(dev); \
  320. unsigned long flags; \
  321. \
  322. if (ch_done_mask & 0x10000000) \
  323. flush_channel(dev, 0, 0, 0); \
  324. if (priv->num_channels == 1) \
  325. goto out; \
  326. if (ch_done_mask & 0x40000000) \
  327. flush_channel(dev, 1, 0, 0); \
  328. if (ch_done_mask & 0x00010000) \
  329. flush_channel(dev, 2, 0, 0); \
  330. if (ch_done_mask & 0x00040000) \
  331. flush_channel(dev, 3, 0, 0); \
  332. \
  333. out: \
  334. /* At this point, all completed channels have been processed */ \
  335. /* Unmask done interrupts for channels completed later on. */ \
  336. spin_lock_irqsave(&priv->reg_lock, flags); \
  337. clrbits32(priv->reg + TALITOS_IMR, ch_done_mask); \
  338. clrbits32(priv->reg + TALITOS_IMR_LO, TALITOS1_IMR_LO_INIT); \
  339. spin_unlock_irqrestore(&priv->reg_lock, flags); \
  340. }
  341. DEF_TALITOS1_DONE(4ch, TALITOS1_ISR_4CHDONE)
  342. #define DEF_TALITOS2_DONE(name, ch_done_mask) \
  343. static void talitos2_done_##name(unsigned long data) \
  344. { \
  345. struct device *dev = (struct device *)data; \
  346. struct talitos_private *priv = dev_get_drvdata(dev); \
  347. unsigned long flags; \
  348. \
  349. if (ch_done_mask & 1) \
  350. flush_channel(dev, 0, 0, 0); \
  351. if (priv->num_channels == 1) \
  352. goto out; \
  353. if (ch_done_mask & (1 << 2)) \
  354. flush_channel(dev, 1, 0, 0); \
  355. if (ch_done_mask & (1 << 4)) \
  356. flush_channel(dev, 2, 0, 0); \
  357. if (ch_done_mask & (1 << 6)) \
  358. flush_channel(dev, 3, 0, 0); \
  359. \
  360. out: \
  361. /* At this point, all completed channels have been processed */ \
  362. /* Unmask done interrupts for channels completed later on. */ \
  363. spin_lock_irqsave(&priv->reg_lock, flags); \
  364. setbits32(priv->reg + TALITOS_IMR, ch_done_mask); \
  365. setbits32(priv->reg + TALITOS_IMR_LO, TALITOS2_IMR_LO_INIT); \
  366. spin_unlock_irqrestore(&priv->reg_lock, flags); \
  367. }
  368. DEF_TALITOS2_DONE(4ch, TALITOS2_ISR_4CHDONE)
  369. DEF_TALITOS2_DONE(ch0_2, TALITOS2_ISR_CH_0_2_DONE)
  370. DEF_TALITOS2_DONE(ch1_3, TALITOS2_ISR_CH_1_3_DONE)
  371. /*
  372. * locate current (offending) descriptor
  373. */
  374. static u32 current_desc_hdr(struct device *dev, int ch)
  375. {
  376. struct talitos_private *priv = dev_get_drvdata(dev);
  377. int tail, iter;
  378. dma_addr_t cur_desc;
  379. cur_desc = ((u64)in_be32(priv->chan[ch].reg + TALITOS_CDPR)) << 32;
  380. cur_desc |= in_be32(priv->chan[ch].reg + TALITOS_CDPR_LO);
  381. if (!cur_desc) {
  382. dev_err(dev, "CDPR is NULL, giving up search for offending descriptor\n");
  383. return 0;
  384. }
  385. tail = priv->chan[ch].tail;
  386. iter = tail;
  387. while (priv->chan[ch].fifo[iter].dma_desc != cur_desc) {
  388. iter = (iter + 1) & (priv->fifo_len - 1);
  389. if (iter == tail) {
  390. dev_err(dev, "couldn't locate current descriptor\n");
  391. return 0;
  392. }
  393. }
  394. return priv->chan[ch].fifo[iter].desc->hdr;
  395. }
  396. /*
  397. * user diagnostics; report root cause of error based on execution unit status
  398. */
  399. static void report_eu_error(struct device *dev, int ch, u32 desc_hdr)
  400. {
  401. struct talitos_private *priv = dev_get_drvdata(dev);
  402. int i;
  403. if (!desc_hdr)
  404. desc_hdr = in_be32(priv->chan[ch].reg + TALITOS_DESCBUF);
  405. switch (desc_hdr & DESC_HDR_SEL0_MASK) {
  406. case DESC_HDR_SEL0_AFEU:
  407. dev_err(dev, "AFEUISR 0x%08x_%08x\n",
  408. in_be32(priv->reg_afeu + TALITOS_EUISR),
  409. in_be32(priv->reg_afeu + TALITOS_EUISR_LO));
  410. break;
  411. case DESC_HDR_SEL0_DEU:
  412. dev_err(dev, "DEUISR 0x%08x_%08x\n",
  413. in_be32(priv->reg_deu + TALITOS_EUISR),
  414. in_be32(priv->reg_deu + TALITOS_EUISR_LO));
  415. break;
  416. case DESC_HDR_SEL0_MDEUA:
  417. case DESC_HDR_SEL0_MDEUB:
  418. dev_err(dev, "MDEUISR 0x%08x_%08x\n",
  419. in_be32(priv->reg_mdeu + TALITOS_EUISR),
  420. in_be32(priv->reg_mdeu + TALITOS_EUISR_LO));
  421. break;
  422. case DESC_HDR_SEL0_RNG:
  423. dev_err(dev, "RNGUISR 0x%08x_%08x\n",
  424. in_be32(priv->reg_rngu + TALITOS_ISR),
  425. in_be32(priv->reg_rngu + TALITOS_ISR_LO));
  426. break;
  427. case DESC_HDR_SEL0_PKEU:
  428. dev_err(dev, "PKEUISR 0x%08x_%08x\n",
  429. in_be32(priv->reg_pkeu + TALITOS_EUISR),
  430. in_be32(priv->reg_pkeu + TALITOS_EUISR_LO));
  431. break;
  432. case DESC_HDR_SEL0_AESU:
  433. dev_err(dev, "AESUISR 0x%08x_%08x\n",
  434. in_be32(priv->reg_aesu + TALITOS_EUISR),
  435. in_be32(priv->reg_aesu + TALITOS_EUISR_LO));
  436. break;
  437. case DESC_HDR_SEL0_CRCU:
  438. dev_err(dev, "CRCUISR 0x%08x_%08x\n",
  439. in_be32(priv->reg_crcu + TALITOS_EUISR),
  440. in_be32(priv->reg_crcu + TALITOS_EUISR_LO));
  441. break;
  442. case DESC_HDR_SEL0_KEU:
  443. dev_err(dev, "KEUISR 0x%08x_%08x\n",
  444. in_be32(priv->reg_pkeu + TALITOS_EUISR),
  445. in_be32(priv->reg_pkeu + TALITOS_EUISR_LO));
  446. break;
  447. }
  448. switch (desc_hdr & DESC_HDR_SEL1_MASK) {
  449. case DESC_HDR_SEL1_MDEUA:
  450. case DESC_HDR_SEL1_MDEUB:
  451. dev_err(dev, "MDEUISR 0x%08x_%08x\n",
  452. in_be32(priv->reg_mdeu + TALITOS_EUISR),
  453. in_be32(priv->reg_mdeu + TALITOS_EUISR_LO));
  454. break;
  455. case DESC_HDR_SEL1_CRCU:
  456. dev_err(dev, "CRCUISR 0x%08x_%08x\n",
  457. in_be32(priv->reg_crcu + TALITOS_EUISR),
  458. in_be32(priv->reg_crcu + TALITOS_EUISR_LO));
  459. break;
  460. }
  461. for (i = 0; i < 8; i++)
  462. dev_err(dev, "DESCBUF 0x%08x_%08x\n",
  463. in_be32(priv->chan[ch].reg + TALITOS_DESCBUF + 8*i),
  464. in_be32(priv->chan[ch].reg + TALITOS_DESCBUF_LO + 8*i));
  465. }
  466. /*
  467. * recover from error interrupts
  468. */
  469. static void talitos_error(struct device *dev, u32 isr, u32 isr_lo)
  470. {
  471. struct talitos_private *priv = dev_get_drvdata(dev);
  472. unsigned int timeout = TALITOS_TIMEOUT;
  473. int ch, error, reset_dev = 0;
  474. u32 v_lo;
  475. bool is_sec1 = has_ftr_sec1(priv);
  476. int reset_ch = is_sec1 ? 1 : 0; /* only SEC2 supports continuation */
  477. for (ch = 0; ch < priv->num_channels; ch++) {
  478. /* skip channels without errors */
  479. if (is_sec1) {
  480. /* bits 29, 31, 17, 19 */
  481. if (!(isr & (1 << (29 + (ch & 1) * 2 - (ch & 2) * 6))))
  482. continue;
  483. } else {
  484. if (!(isr & (1 << (ch * 2 + 1))))
  485. continue;
  486. }
  487. error = -EINVAL;
  488. v_lo = in_be32(priv->chan[ch].reg + TALITOS_CCPSR_LO);
  489. if (v_lo & TALITOS_CCPSR_LO_DOF) {
  490. dev_err(dev, "double fetch fifo overflow error\n");
  491. error = -EAGAIN;
  492. reset_ch = 1;
  493. }
  494. if (v_lo & TALITOS_CCPSR_LO_SOF) {
  495. /* h/w dropped descriptor */
  496. dev_err(dev, "single fetch fifo overflow error\n");
  497. error = -EAGAIN;
  498. }
  499. if (v_lo & TALITOS_CCPSR_LO_MDTE)
  500. dev_err(dev, "master data transfer error\n");
  501. if (v_lo & TALITOS_CCPSR_LO_SGDLZ)
  502. dev_err(dev, is_sec1 ? "pointeur not complete error\n"
  503. : "s/g data length zero error\n");
  504. if (v_lo & TALITOS_CCPSR_LO_FPZ)
  505. dev_err(dev, is_sec1 ? "parity error\n"
  506. : "fetch pointer zero error\n");
  507. if (v_lo & TALITOS_CCPSR_LO_IDH)
  508. dev_err(dev, "illegal descriptor header error\n");
  509. if (v_lo & TALITOS_CCPSR_LO_IEU)
  510. dev_err(dev, is_sec1 ? "static assignment error\n"
  511. : "invalid exec unit error\n");
  512. if (v_lo & TALITOS_CCPSR_LO_EU)
  513. report_eu_error(dev, ch, current_desc_hdr(dev, ch));
  514. if (!is_sec1) {
  515. if (v_lo & TALITOS_CCPSR_LO_GB)
  516. dev_err(dev, "gather boundary error\n");
  517. if (v_lo & TALITOS_CCPSR_LO_GRL)
  518. dev_err(dev, "gather return/length error\n");
  519. if (v_lo & TALITOS_CCPSR_LO_SB)
  520. dev_err(dev, "scatter boundary error\n");
  521. if (v_lo & TALITOS_CCPSR_LO_SRL)
  522. dev_err(dev, "scatter return/length error\n");
  523. }
  524. flush_channel(dev, ch, error, reset_ch);
  525. if (reset_ch) {
  526. reset_channel(dev, ch);
  527. } else {
  528. setbits32(priv->chan[ch].reg + TALITOS_CCCR,
  529. TALITOS2_CCCR_CONT);
  530. setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO, 0);
  531. while ((in_be32(priv->chan[ch].reg + TALITOS_CCCR) &
  532. TALITOS2_CCCR_CONT) && --timeout)
  533. cpu_relax();
  534. if (timeout == 0) {
  535. dev_err(dev, "failed to restart channel %d\n",
  536. ch);
  537. reset_dev = 1;
  538. }
  539. }
  540. }
  541. if (reset_dev || (is_sec1 && isr & ~TALITOS1_ISR_4CHERR) ||
  542. (!is_sec1 && isr & ~TALITOS2_ISR_4CHERR) || isr_lo) {
  543. if (is_sec1 && (isr_lo & TALITOS1_ISR_TEA_ERR))
  544. dev_err(dev, "TEA error: ISR 0x%08x_%08x\n",
  545. isr, isr_lo);
  546. else
  547. dev_err(dev, "done overflow, internal time out, or "
  548. "rngu error: ISR 0x%08x_%08x\n", isr, isr_lo);
  549. /* purge request queues */
  550. for (ch = 0; ch < priv->num_channels; ch++)
  551. flush_channel(dev, ch, -EIO, 1);
  552. /* reset and reinitialize the device */
  553. init_device(dev);
  554. }
  555. }
  556. #define DEF_TALITOS1_INTERRUPT(name, ch_done_mask, ch_err_mask, tlet) \
  557. static irqreturn_t talitos1_interrupt_##name(int irq, void *data) \
  558. { \
  559. struct device *dev = data; \
  560. struct talitos_private *priv = dev_get_drvdata(dev); \
  561. u32 isr, isr_lo; \
  562. unsigned long flags; \
  563. \
  564. spin_lock_irqsave(&priv->reg_lock, flags); \
  565. isr = in_be32(priv->reg + TALITOS_ISR); \
  566. isr_lo = in_be32(priv->reg + TALITOS_ISR_LO); \
  567. /* Acknowledge interrupt */ \
  568. out_be32(priv->reg + TALITOS_ICR, isr & (ch_done_mask | ch_err_mask)); \
  569. out_be32(priv->reg + TALITOS_ICR_LO, isr_lo); \
  570. \
  571. if (unlikely(isr & ch_err_mask || isr_lo & TALITOS1_IMR_LO_INIT)) { \
  572. spin_unlock_irqrestore(&priv->reg_lock, flags); \
  573. talitos_error(dev, isr & ch_err_mask, isr_lo); \
  574. } \
  575. else { \
  576. if (likely(isr & ch_done_mask)) { \
  577. /* mask further done interrupts. */ \
  578. setbits32(priv->reg + TALITOS_IMR, ch_done_mask); \
  579. /* done_task will unmask done interrupts at exit */ \
  580. tasklet_schedule(&priv->done_task[tlet]); \
  581. } \
  582. spin_unlock_irqrestore(&priv->reg_lock, flags); \
  583. } \
  584. \
  585. return (isr & (ch_done_mask | ch_err_mask) || isr_lo) ? IRQ_HANDLED : \
  586. IRQ_NONE; \
  587. }
  588. DEF_TALITOS1_INTERRUPT(4ch, TALITOS1_ISR_4CHDONE, TALITOS1_ISR_4CHERR, 0)
  589. #define DEF_TALITOS2_INTERRUPT(name, ch_done_mask, ch_err_mask, tlet) \
  590. static irqreturn_t talitos2_interrupt_##name(int irq, void *data) \
  591. { \
  592. struct device *dev = data; \
  593. struct talitos_private *priv = dev_get_drvdata(dev); \
  594. u32 isr, isr_lo; \
  595. unsigned long flags; \
  596. \
  597. spin_lock_irqsave(&priv->reg_lock, flags); \
  598. isr = in_be32(priv->reg + TALITOS_ISR); \
  599. isr_lo = in_be32(priv->reg + TALITOS_ISR_LO); \
  600. /* Acknowledge interrupt */ \
  601. out_be32(priv->reg + TALITOS_ICR, isr & (ch_done_mask | ch_err_mask)); \
  602. out_be32(priv->reg + TALITOS_ICR_LO, isr_lo); \
  603. \
  604. if (unlikely(isr & ch_err_mask || isr_lo)) { \
  605. spin_unlock_irqrestore(&priv->reg_lock, flags); \
  606. talitos_error(dev, isr & ch_err_mask, isr_lo); \
  607. } \
  608. else { \
  609. if (likely(isr & ch_done_mask)) { \
  610. /* mask further done interrupts. */ \
  611. clrbits32(priv->reg + TALITOS_IMR, ch_done_mask); \
  612. /* done_task will unmask done interrupts at exit */ \
  613. tasklet_schedule(&priv->done_task[tlet]); \
  614. } \
  615. spin_unlock_irqrestore(&priv->reg_lock, flags); \
  616. } \
  617. \
  618. return (isr & (ch_done_mask | ch_err_mask) || isr_lo) ? IRQ_HANDLED : \
  619. IRQ_NONE; \
  620. }
  621. DEF_TALITOS2_INTERRUPT(4ch, TALITOS2_ISR_4CHDONE, TALITOS2_ISR_4CHERR, 0)
  622. DEF_TALITOS2_INTERRUPT(ch0_2, TALITOS2_ISR_CH_0_2_DONE, TALITOS2_ISR_CH_0_2_ERR,
  623. 0)
  624. DEF_TALITOS2_INTERRUPT(ch1_3, TALITOS2_ISR_CH_1_3_DONE, TALITOS2_ISR_CH_1_3_ERR,
  625. 1)
  626. /*
  627. * hwrng
  628. */
  629. static int talitos_rng_data_present(struct hwrng *rng, int wait)
  630. {
  631. struct device *dev = (struct device *)rng->priv;
  632. struct talitos_private *priv = dev_get_drvdata(dev);
  633. u32 ofl;
  634. int i;
  635. for (i = 0; i < 20; i++) {
  636. ofl = in_be32(priv->reg_rngu + TALITOS_EUSR_LO) &
  637. TALITOS_RNGUSR_LO_OFL;
  638. if (ofl || !wait)
  639. break;
  640. udelay(10);
  641. }
  642. return !!ofl;
  643. }
  644. static int talitos_rng_data_read(struct hwrng *rng, u32 *data)
  645. {
  646. struct device *dev = (struct device *)rng->priv;
  647. struct talitos_private *priv = dev_get_drvdata(dev);
  648. /* rng fifo requires 64-bit accesses */
  649. *data = in_be32(priv->reg_rngu + TALITOS_EU_FIFO);
  650. *data = in_be32(priv->reg_rngu + TALITOS_EU_FIFO_LO);
  651. return sizeof(u32);
  652. }
  653. static int talitos_rng_init(struct hwrng *rng)
  654. {
  655. struct device *dev = (struct device *)rng->priv;
  656. struct talitos_private *priv = dev_get_drvdata(dev);
  657. unsigned int timeout = TALITOS_TIMEOUT;
  658. setbits32(priv->reg_rngu + TALITOS_EURCR_LO, TALITOS_RNGURCR_LO_SR);
  659. while (!(in_be32(priv->reg_rngu + TALITOS_EUSR_LO)
  660. & TALITOS_RNGUSR_LO_RD)
  661. && --timeout)
  662. cpu_relax();
  663. if (timeout == 0) {
  664. dev_err(dev, "failed to reset rng hw\n");
  665. return -ENODEV;
  666. }
  667. /* start generating */
  668. setbits32(priv->reg_rngu + TALITOS_EUDSR_LO, 0);
  669. return 0;
  670. }
  671. static int talitos_register_rng(struct device *dev)
  672. {
  673. struct talitos_private *priv = dev_get_drvdata(dev);
  674. priv->rng.name = dev_driver_string(dev),
  675. priv->rng.init = talitos_rng_init,
  676. priv->rng.data_present = talitos_rng_data_present,
  677. priv->rng.data_read = talitos_rng_data_read,
  678. priv->rng.priv = (unsigned long)dev;
  679. return hwrng_register(&priv->rng);
  680. }
  681. static void talitos_unregister_rng(struct device *dev)
  682. {
  683. struct talitos_private *priv = dev_get_drvdata(dev);
  684. hwrng_unregister(&priv->rng);
  685. }
  686. /*
  687. * crypto alg
  688. */
  689. #define TALITOS_CRA_PRIORITY 3000
  690. #define TALITOS_MAX_KEY_SIZE 96
  691. #define TALITOS_MAX_IV_LENGTH 16 /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
  692. struct talitos_ctx {
  693. struct device *dev;
  694. int ch;
  695. __be32 desc_hdr_template;
  696. u8 key[TALITOS_MAX_KEY_SIZE];
  697. u8 iv[TALITOS_MAX_IV_LENGTH];
  698. unsigned int keylen;
  699. unsigned int enckeylen;
  700. unsigned int authkeylen;
  701. unsigned int authsize;
  702. };
  703. #define HASH_MAX_BLOCK_SIZE SHA512_BLOCK_SIZE
  704. #define TALITOS_MDEU_MAX_CONTEXT_SIZE TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512
  705. struct talitos_ahash_req_ctx {
  706. u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE / sizeof(u32)];
  707. unsigned int hw_context_size;
  708. u8 buf[HASH_MAX_BLOCK_SIZE];
  709. u8 bufnext[HASH_MAX_BLOCK_SIZE];
  710. unsigned int swinit;
  711. unsigned int first;
  712. unsigned int last;
  713. unsigned int to_hash_later;
  714. unsigned int nbuf;
  715. struct scatterlist bufsl[2];
  716. struct scatterlist *psrc;
  717. };
  718. static int aead_setauthsize(struct crypto_aead *authenc,
  719. unsigned int authsize)
  720. {
  721. struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
  722. ctx->authsize = authsize;
  723. return 0;
  724. }
  725. static int aead_setkey(struct crypto_aead *authenc,
  726. const u8 *key, unsigned int keylen)
  727. {
  728. struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
  729. struct crypto_authenc_keys keys;
  730. if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
  731. goto badkey;
  732. if (keys.authkeylen + keys.enckeylen > TALITOS_MAX_KEY_SIZE)
  733. goto badkey;
  734. memcpy(ctx->key, keys.authkey, keys.authkeylen);
  735. memcpy(&ctx->key[keys.authkeylen], keys.enckey, keys.enckeylen);
  736. ctx->keylen = keys.authkeylen + keys.enckeylen;
  737. ctx->enckeylen = keys.enckeylen;
  738. ctx->authkeylen = keys.authkeylen;
  739. return 0;
  740. badkey:
  741. crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
  742. return -EINVAL;
  743. }
  744. /*
  745. * talitos_edesc - s/w-extended descriptor
  746. * @assoc_nents: number of segments in associated data scatterlist
  747. * @src_nents: number of segments in input scatterlist
  748. * @dst_nents: number of segments in output scatterlist
  749. * @assoc_chained: whether assoc is chained or not
  750. * @src_chained: whether src is chained or not
  751. * @dst_chained: whether dst is chained or not
  752. * @iv_dma: dma address of iv for checking continuity and link table
  753. * @dma_len: length of dma mapped link_tbl space
  754. * @dma_link_tbl: bus physical address of link_tbl/buf
  755. * @desc: h/w descriptor
  756. * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) (SEC2)
  757. * @buf: input and output buffeur (if {src,dst}_nents > 1) (SEC1)
  758. *
  759. * if decrypting (with authcheck), or either one of src_nents or dst_nents
  760. * is greater than 1, an integrity check value is concatenated to the end
  761. * of link_tbl data
  762. */
  763. struct talitos_edesc {
  764. int assoc_nents;
  765. int src_nents;
  766. int dst_nents;
  767. bool assoc_chained;
  768. bool src_chained;
  769. bool dst_chained;
  770. dma_addr_t iv_dma;
  771. int dma_len;
  772. dma_addr_t dma_link_tbl;
  773. struct talitos_desc desc;
  774. union {
  775. struct talitos_ptr link_tbl[0];
  776. u8 buf[0];
  777. };
  778. };
  779. static int talitos_map_sg(struct device *dev, struct scatterlist *sg,
  780. unsigned int nents, enum dma_data_direction dir,
  781. bool chained)
  782. {
  783. if (unlikely(chained))
  784. while (sg) {
  785. dma_map_sg(dev, sg, 1, dir);
  786. sg = sg_next(sg);
  787. }
  788. else
  789. dma_map_sg(dev, sg, nents, dir);
  790. return nents;
  791. }
  792. static void talitos_unmap_sg_chain(struct device *dev, struct scatterlist *sg,
  793. enum dma_data_direction dir)
  794. {
  795. while (sg) {
  796. dma_unmap_sg(dev, sg, 1, dir);
  797. sg = sg_next(sg);
  798. }
  799. }
  800. static void talitos_sg_unmap(struct device *dev,
  801. struct talitos_edesc *edesc,
  802. struct scatterlist *src,
  803. struct scatterlist *dst)
  804. {
  805. unsigned int src_nents = edesc->src_nents ? : 1;
  806. unsigned int dst_nents = edesc->dst_nents ? : 1;
  807. if (src != dst) {
  808. if (edesc->src_chained)
  809. talitos_unmap_sg_chain(dev, src, DMA_TO_DEVICE);
  810. else
  811. dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
  812. if (dst) {
  813. if (edesc->dst_chained)
  814. talitos_unmap_sg_chain(dev, dst,
  815. DMA_FROM_DEVICE);
  816. else
  817. dma_unmap_sg(dev, dst, dst_nents,
  818. DMA_FROM_DEVICE);
  819. }
  820. } else
  821. if (edesc->src_chained)
  822. talitos_unmap_sg_chain(dev, src, DMA_BIDIRECTIONAL);
  823. else
  824. dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
  825. }
  826. static void ipsec_esp_unmap(struct device *dev,
  827. struct talitos_edesc *edesc,
  828. struct aead_request *areq)
  829. {
  830. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[6], DMA_FROM_DEVICE);
  831. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[3], DMA_TO_DEVICE);
  832. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], DMA_TO_DEVICE);
  833. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[0], DMA_TO_DEVICE);
  834. if (edesc->assoc_chained)
  835. talitos_unmap_sg_chain(dev, areq->assoc, DMA_TO_DEVICE);
  836. else if (areq->assoclen)
  837. /* assoc_nents counts also for IV in non-contiguous cases */
  838. dma_unmap_sg(dev, areq->assoc,
  839. edesc->assoc_nents ? edesc->assoc_nents - 1 : 1,
  840. DMA_TO_DEVICE);
  841. talitos_sg_unmap(dev, edesc, areq->src, areq->dst);
  842. if (edesc->dma_len)
  843. dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len,
  844. DMA_BIDIRECTIONAL);
  845. }
  846. /*
  847. * ipsec_esp descriptor callbacks
  848. */
  849. static void ipsec_esp_encrypt_done(struct device *dev,
  850. struct talitos_desc *desc, void *context,
  851. int err)
  852. {
  853. struct aead_request *areq = context;
  854. struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
  855. struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
  856. struct talitos_edesc *edesc;
  857. struct scatterlist *sg;
  858. void *icvdata;
  859. edesc = container_of(desc, struct talitos_edesc, desc);
  860. ipsec_esp_unmap(dev, edesc, areq);
  861. /* copy the generated ICV to dst */
  862. if (edesc->dst_nents) {
  863. icvdata = &edesc->link_tbl[edesc->src_nents +
  864. edesc->dst_nents + 2 +
  865. edesc->assoc_nents];
  866. sg = sg_last(areq->dst, edesc->dst_nents);
  867. memcpy((char *)sg_virt(sg) + sg->length - ctx->authsize,
  868. icvdata, ctx->authsize);
  869. }
  870. kfree(edesc);
  871. aead_request_complete(areq, err);
  872. }
  873. static void ipsec_esp_decrypt_swauth_done(struct device *dev,
  874. struct talitos_desc *desc,
  875. void *context, int err)
  876. {
  877. struct aead_request *req = context;
  878. struct crypto_aead *authenc = crypto_aead_reqtfm(req);
  879. struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
  880. struct talitos_edesc *edesc;
  881. struct scatterlist *sg;
  882. void *icvdata;
  883. edesc = container_of(desc, struct talitos_edesc, desc);
  884. ipsec_esp_unmap(dev, edesc, req);
  885. if (!err) {
  886. /* auth check */
  887. if (edesc->dma_len)
  888. icvdata = &edesc->link_tbl[edesc->src_nents +
  889. edesc->dst_nents + 2 +
  890. edesc->assoc_nents];
  891. else
  892. icvdata = &edesc->link_tbl[0];
  893. sg = sg_last(req->dst, edesc->dst_nents ? : 1);
  894. err = memcmp(icvdata, (char *)sg_virt(sg) + sg->length -
  895. ctx->authsize, ctx->authsize) ? -EBADMSG : 0;
  896. }
  897. kfree(edesc);
  898. aead_request_complete(req, err);
  899. }
  900. static void ipsec_esp_decrypt_hwauth_done(struct device *dev,
  901. struct talitos_desc *desc,
  902. void *context, int err)
  903. {
  904. struct aead_request *req = context;
  905. struct talitos_edesc *edesc;
  906. edesc = container_of(desc, struct talitos_edesc, desc);
  907. ipsec_esp_unmap(dev, edesc, req);
  908. /* check ICV auth status */
  909. if (!err && ((desc->hdr_lo & DESC_HDR_LO_ICCR1_MASK) !=
  910. DESC_HDR_LO_ICCR1_PASS))
  911. err = -EBADMSG;
  912. kfree(edesc);
  913. aead_request_complete(req, err);
  914. }
  915. /*
  916. * convert scatterlist to SEC h/w link table format
  917. * stop at cryptlen bytes
  918. */
  919. static int sg_to_link_tbl(struct scatterlist *sg, int sg_count,
  920. int cryptlen, struct talitos_ptr *link_tbl_ptr)
  921. {
  922. int n_sg = sg_count;
  923. while (sg && n_sg--) {
  924. to_talitos_ptr(link_tbl_ptr, sg_dma_address(sg), 0);
  925. link_tbl_ptr->len = cpu_to_be16(sg_dma_len(sg));
  926. link_tbl_ptr->j_extent = 0;
  927. link_tbl_ptr++;
  928. cryptlen -= sg_dma_len(sg);
  929. sg = sg_next(sg);
  930. }
  931. /* adjust (decrease) last one (or two) entry's len to cryptlen */
  932. link_tbl_ptr--;
  933. while (be16_to_cpu(link_tbl_ptr->len) <= (-cryptlen)) {
  934. /* Empty this entry, and move to previous one */
  935. cryptlen += be16_to_cpu(link_tbl_ptr->len);
  936. link_tbl_ptr->len = 0;
  937. sg_count--;
  938. link_tbl_ptr--;
  939. }
  940. link_tbl_ptr->len = cpu_to_be16(be16_to_cpu(link_tbl_ptr->len)
  941. + cryptlen);
  942. /* tag end of link table */
  943. link_tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN;
  944. return sg_count;
  945. }
  946. /*
  947. * fill in and submit ipsec_esp descriptor
  948. */
  949. static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
  950. u64 seq, void (*callback) (struct device *dev,
  951. struct talitos_desc *desc,
  952. void *context, int error))
  953. {
  954. struct crypto_aead *aead = crypto_aead_reqtfm(areq);
  955. struct talitos_ctx *ctx = crypto_aead_ctx(aead);
  956. struct device *dev = ctx->dev;
  957. struct talitos_desc *desc = &edesc->desc;
  958. unsigned int cryptlen = areq->cryptlen;
  959. unsigned int authsize = ctx->authsize;
  960. unsigned int ivsize = crypto_aead_ivsize(aead);
  961. int sg_count, ret;
  962. int sg_link_tbl_len;
  963. /* hmac key */
  964. map_single_talitos_ptr(dev, &desc->ptr[0], ctx->authkeylen, &ctx->key,
  965. DMA_TO_DEVICE);
  966. /* hmac data */
  967. desc->ptr[1].len = cpu_to_be16(areq->assoclen + ivsize);
  968. if (edesc->assoc_nents) {
  969. int tbl_off = edesc->src_nents + edesc->dst_nents + 2;
  970. struct talitos_ptr *tbl_ptr = &edesc->link_tbl[tbl_off];
  971. to_talitos_ptr(&desc->ptr[1], edesc->dma_link_tbl + tbl_off *
  972. sizeof(struct talitos_ptr), 0);
  973. desc->ptr[1].j_extent = DESC_PTR_LNKTBL_JUMP;
  974. /* assoc_nents - 1 entries for assoc, 1 for IV */
  975. sg_count = sg_to_link_tbl(areq->assoc, edesc->assoc_nents - 1,
  976. areq->assoclen, tbl_ptr);
  977. /* add IV to link table */
  978. tbl_ptr += sg_count - 1;
  979. tbl_ptr->j_extent = 0;
  980. tbl_ptr++;
  981. to_talitos_ptr(tbl_ptr, edesc->iv_dma, 0);
  982. tbl_ptr->len = cpu_to_be16(ivsize);
  983. tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN;
  984. dma_sync_single_for_device(dev, edesc->dma_link_tbl,
  985. edesc->dma_len, DMA_BIDIRECTIONAL);
  986. } else {
  987. if (areq->assoclen)
  988. to_talitos_ptr(&desc->ptr[1],
  989. sg_dma_address(areq->assoc), 0);
  990. else
  991. to_talitos_ptr(&desc->ptr[1], edesc->iv_dma, 0);
  992. desc->ptr[1].j_extent = 0;
  993. }
  994. /* cipher iv */
  995. to_talitos_ptr(&desc->ptr[2], edesc->iv_dma, 0);
  996. desc->ptr[2].len = cpu_to_be16(ivsize);
  997. desc->ptr[2].j_extent = 0;
  998. /* Sync needed for the aead_givencrypt case */
  999. dma_sync_single_for_device(dev, edesc->iv_dma, ivsize, DMA_TO_DEVICE);
  1000. /* cipher key */
  1001. map_single_talitos_ptr(dev, &desc->ptr[3], ctx->enckeylen,
  1002. (char *)&ctx->key + ctx->authkeylen,
  1003. DMA_TO_DEVICE);
  1004. /*
  1005. * cipher in
  1006. * map and adjust cipher len to aead request cryptlen.
  1007. * extent is bytes of HMAC postpended to ciphertext,
  1008. * typically 12 for ipsec
  1009. */
  1010. desc->ptr[4].len = cpu_to_be16(cryptlen);
  1011. desc->ptr[4].j_extent = authsize;
  1012. sg_count = talitos_map_sg(dev, areq->src, edesc->src_nents ? : 1,
  1013. (areq->src == areq->dst) ? DMA_BIDIRECTIONAL
  1014. : DMA_TO_DEVICE,
  1015. edesc->src_chained);
  1016. if (sg_count == 1) {
  1017. to_talitos_ptr(&desc->ptr[4], sg_dma_address(areq->src), 0);
  1018. } else {
  1019. sg_link_tbl_len = cryptlen;
  1020. if (edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV)
  1021. sg_link_tbl_len = cryptlen + authsize;
  1022. sg_count = sg_to_link_tbl(areq->src, sg_count, sg_link_tbl_len,
  1023. &edesc->link_tbl[0]);
  1024. if (sg_count > 1) {
  1025. desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP;
  1026. to_talitos_ptr(&desc->ptr[4], edesc->dma_link_tbl, 0);
  1027. dma_sync_single_for_device(dev, edesc->dma_link_tbl,
  1028. edesc->dma_len,
  1029. DMA_BIDIRECTIONAL);
  1030. } else {
  1031. /* Only one segment now, so no link tbl needed */
  1032. to_talitos_ptr(&desc->ptr[4],
  1033. sg_dma_address(areq->src), 0);
  1034. }
  1035. }
  1036. /* cipher out */
  1037. desc->ptr[5].len = cpu_to_be16(cryptlen);
  1038. desc->ptr[5].j_extent = authsize;
  1039. if (areq->src != areq->dst)
  1040. sg_count = talitos_map_sg(dev, areq->dst,
  1041. edesc->dst_nents ? : 1,
  1042. DMA_FROM_DEVICE, edesc->dst_chained);
  1043. if (sg_count == 1) {
  1044. to_talitos_ptr(&desc->ptr[5], sg_dma_address(areq->dst), 0);
  1045. } else {
  1046. int tbl_off = edesc->src_nents + 1;
  1047. struct talitos_ptr *tbl_ptr = &edesc->link_tbl[tbl_off];
  1048. to_talitos_ptr(&desc->ptr[5], edesc->dma_link_tbl +
  1049. tbl_off * sizeof(struct talitos_ptr), 0);
  1050. sg_count = sg_to_link_tbl(areq->dst, sg_count, cryptlen,
  1051. tbl_ptr);
  1052. /* Add an entry to the link table for ICV data */
  1053. tbl_ptr += sg_count - 1;
  1054. tbl_ptr->j_extent = 0;
  1055. tbl_ptr++;
  1056. tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN;
  1057. tbl_ptr->len = cpu_to_be16(authsize);
  1058. /* icv data follows link tables */
  1059. to_talitos_ptr(tbl_ptr, edesc->dma_link_tbl +
  1060. (tbl_off + edesc->dst_nents + 1 +
  1061. edesc->assoc_nents) *
  1062. sizeof(struct talitos_ptr), 0);
  1063. desc->ptr[5].j_extent |= DESC_PTR_LNKTBL_JUMP;
  1064. dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl,
  1065. edesc->dma_len, DMA_BIDIRECTIONAL);
  1066. }
  1067. /* iv out */
  1068. map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv,
  1069. DMA_FROM_DEVICE);
  1070. ret = talitos_submit(dev, ctx->ch, desc, callback, areq);
  1071. if (ret != -EINPROGRESS) {
  1072. ipsec_esp_unmap(dev, edesc, areq);
  1073. kfree(edesc);
  1074. }
  1075. return ret;
  1076. }
  1077. /*
  1078. * derive number of elements in scatterlist
  1079. */
  1080. static int sg_count(struct scatterlist *sg_list, int nbytes, bool *chained)
  1081. {
  1082. struct scatterlist *sg = sg_list;
  1083. int sg_nents = 0;
  1084. *chained = false;
  1085. while (nbytes > 0 && sg) {
  1086. sg_nents++;
  1087. nbytes -= sg->length;
  1088. if (!sg_is_last(sg) && (sg + 1)->length == 0)
  1089. *chained = true;
  1090. sg = sg_next(sg);
  1091. }
  1092. return sg_nents;
  1093. }
  1094. /*
  1095. * allocate and map the extended descriptor
  1096. */
  1097. static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
  1098. struct scatterlist *assoc,
  1099. struct scatterlist *src,
  1100. struct scatterlist *dst,
  1101. u8 *iv,
  1102. unsigned int assoclen,
  1103. unsigned int cryptlen,
  1104. unsigned int authsize,
  1105. unsigned int ivsize,
  1106. int icv_stashing,
  1107. u32 cryptoflags,
  1108. bool encrypt)
  1109. {
  1110. struct talitos_edesc *edesc;
  1111. int assoc_nents = 0, src_nents, dst_nents, alloc_len, dma_len;
  1112. bool assoc_chained = false, src_chained = false, dst_chained = false;
  1113. dma_addr_t iv_dma = 0;
  1114. gfp_t flags = cryptoflags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL :
  1115. GFP_ATOMIC;
  1116. struct talitos_private *priv = dev_get_drvdata(dev);
  1117. bool is_sec1 = has_ftr_sec1(priv);
  1118. int max_len = is_sec1 ? TALITOS1_MAX_DATA_LEN : TALITOS2_MAX_DATA_LEN;
  1119. if (cryptlen + authsize > max_len) {
  1120. dev_err(dev, "length exceeds h/w max limit\n");
  1121. return ERR_PTR(-EINVAL);
  1122. }
  1123. if (ivsize)
  1124. iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE);
  1125. if (assoclen) {
  1126. /*
  1127. * Currently it is assumed that iv is provided whenever assoc
  1128. * is.
  1129. */
  1130. BUG_ON(!iv);
  1131. assoc_nents = sg_count(assoc, assoclen, &assoc_chained);
  1132. talitos_map_sg(dev, assoc, assoc_nents, DMA_TO_DEVICE,
  1133. assoc_chained);
  1134. assoc_nents = (assoc_nents == 1) ? 0 : assoc_nents;
  1135. if (assoc_nents || sg_dma_address(assoc) + assoclen != iv_dma)
  1136. assoc_nents = assoc_nents ? assoc_nents + 1 : 2;
  1137. }
  1138. if (!dst || dst == src) {
  1139. src_nents = sg_count(src, cryptlen + authsize, &src_chained);
  1140. src_nents = (src_nents == 1) ? 0 : src_nents;
  1141. dst_nents = dst ? src_nents : 0;
  1142. } else { /* dst && dst != src*/
  1143. src_nents = sg_count(src, cryptlen + (encrypt ? 0 : authsize),
  1144. &src_chained);
  1145. src_nents = (src_nents == 1) ? 0 : src_nents;
  1146. dst_nents = sg_count(dst, cryptlen + (encrypt ? authsize : 0),
  1147. &dst_chained);
  1148. dst_nents = (dst_nents == 1) ? 0 : dst_nents;
  1149. }
  1150. /*
  1151. * allocate space for base edesc plus the link tables,
  1152. * allowing for two separate entries for ICV and generated ICV (+ 2),
  1153. * and the ICV data itself
  1154. */
  1155. alloc_len = sizeof(struct talitos_edesc);
  1156. if (assoc_nents || src_nents || dst_nents) {
  1157. if (is_sec1)
  1158. dma_len = (src_nents ? cryptlen : 0) +
  1159. (dst_nents ? cryptlen : 0);
  1160. else
  1161. dma_len = (src_nents + dst_nents + 2 + assoc_nents) *
  1162. sizeof(struct talitos_ptr) + authsize;
  1163. alloc_len += dma_len;
  1164. } else {
  1165. dma_len = 0;
  1166. alloc_len += icv_stashing ? authsize : 0;
  1167. }
  1168. edesc = kmalloc(alloc_len, GFP_DMA | flags);
  1169. if (!edesc) {
  1170. if (assoc_chained)
  1171. talitos_unmap_sg_chain(dev, assoc, DMA_TO_DEVICE);
  1172. else if (assoclen)
  1173. dma_unmap_sg(dev, assoc,
  1174. assoc_nents ? assoc_nents - 1 : 1,
  1175. DMA_TO_DEVICE);
  1176. if (iv_dma)
  1177. dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
  1178. dev_err(dev, "could not allocate edescriptor\n");
  1179. return ERR_PTR(-ENOMEM);
  1180. }
  1181. edesc->assoc_nents = assoc_nents;
  1182. edesc->src_nents = src_nents;
  1183. edesc->dst_nents = dst_nents;
  1184. edesc->assoc_chained = assoc_chained;
  1185. edesc->src_chained = src_chained;
  1186. edesc->dst_chained = dst_chained;
  1187. edesc->iv_dma = iv_dma;
  1188. edesc->dma_len = dma_len;
  1189. if (dma_len)
  1190. edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0],
  1191. edesc->dma_len,
  1192. DMA_BIDIRECTIONAL);
  1193. return edesc;
  1194. }
  1195. static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq, u8 *iv,
  1196. int icv_stashing, bool encrypt)
  1197. {
  1198. struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
  1199. struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
  1200. unsigned int ivsize = crypto_aead_ivsize(authenc);
  1201. return talitos_edesc_alloc(ctx->dev, areq->assoc, areq->src, areq->dst,
  1202. iv, areq->assoclen, areq->cryptlen,
  1203. ctx->authsize, ivsize, icv_stashing,
  1204. areq->base.flags, encrypt);
  1205. }
  1206. static int aead_encrypt(struct aead_request *req)
  1207. {
  1208. struct crypto_aead *authenc = crypto_aead_reqtfm(req);
  1209. struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
  1210. struct talitos_edesc *edesc;
  1211. /* allocate extended descriptor */
  1212. edesc = aead_edesc_alloc(req, req->iv, 0, true);
  1213. if (IS_ERR(edesc))
  1214. return PTR_ERR(edesc);
  1215. /* set encrypt */
  1216. edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
  1217. return ipsec_esp(edesc, req, 0, ipsec_esp_encrypt_done);
  1218. }
  1219. static int aead_decrypt(struct aead_request *req)
  1220. {
  1221. struct crypto_aead *authenc = crypto_aead_reqtfm(req);
  1222. struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
  1223. unsigned int authsize = ctx->authsize;
  1224. struct talitos_private *priv = dev_get_drvdata(ctx->dev);
  1225. struct talitos_edesc *edesc;
  1226. struct scatterlist *sg;
  1227. void *icvdata;
  1228. req->cryptlen -= authsize;
  1229. /* allocate extended descriptor */
  1230. edesc = aead_edesc_alloc(req, req->iv, 1, false);
  1231. if (IS_ERR(edesc))
  1232. return PTR_ERR(edesc);
  1233. if ((priv->features & TALITOS_FTR_HW_AUTH_CHECK) &&
  1234. ((!edesc->src_nents && !edesc->dst_nents) ||
  1235. priv->features & TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT)) {
  1236. /* decrypt and check the ICV */
  1237. edesc->desc.hdr = ctx->desc_hdr_template |
  1238. DESC_HDR_DIR_INBOUND |
  1239. DESC_HDR_MODE1_MDEU_CICV;
  1240. /* reset integrity check result bits */
  1241. edesc->desc.hdr_lo = 0;
  1242. return ipsec_esp(edesc, req, 0, ipsec_esp_decrypt_hwauth_done);
  1243. }
  1244. /* Have to check the ICV with software */
  1245. edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND;
  1246. /* stash incoming ICV for later cmp with ICV generated by the h/w */
  1247. if (edesc->dma_len)
  1248. icvdata = &edesc->link_tbl[edesc->src_nents +
  1249. edesc->dst_nents + 2 +
  1250. edesc->assoc_nents];
  1251. else
  1252. icvdata = &edesc->link_tbl[0];
  1253. sg = sg_last(req->src, edesc->src_nents ? : 1);
  1254. memcpy(icvdata, (char *)sg_virt(sg) + sg->length - ctx->authsize,
  1255. ctx->authsize);
  1256. return ipsec_esp(edesc, req, 0, ipsec_esp_decrypt_swauth_done);
  1257. }
  1258. static int aead_givencrypt(struct aead_givcrypt_request *req)
  1259. {
  1260. struct aead_request *areq = &req->areq;
  1261. struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
  1262. struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
  1263. struct talitos_edesc *edesc;
  1264. /* allocate extended descriptor */
  1265. edesc = aead_edesc_alloc(areq, req->giv, 0, true);
  1266. if (IS_ERR(edesc))
  1267. return PTR_ERR(edesc);
  1268. /* set encrypt */
  1269. edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
  1270. memcpy(req->giv, ctx->iv, crypto_aead_ivsize(authenc));
  1271. /* avoid consecutive packets going out with same IV */
  1272. *(__be64 *)req->giv ^= cpu_to_be64(req->seq);
  1273. return ipsec_esp(edesc, areq, req->seq, ipsec_esp_encrypt_done);
  1274. }
  1275. static int ablkcipher_setkey(struct crypto_ablkcipher *cipher,
  1276. const u8 *key, unsigned int keylen)
  1277. {
  1278. struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  1279. memcpy(&ctx->key, key, keylen);
  1280. ctx->keylen = keylen;
  1281. return 0;
  1282. }
  1283. static void unmap_sg_talitos_ptr(struct device *dev, struct scatterlist *src,
  1284. struct scatterlist *dst, unsigned int len,
  1285. struct talitos_edesc *edesc)
  1286. {
  1287. struct talitos_private *priv = dev_get_drvdata(dev);
  1288. bool is_sec1 = has_ftr_sec1(priv);
  1289. if (is_sec1) {
  1290. if (!edesc->src_nents) {
  1291. dma_unmap_sg(dev, src, 1,
  1292. dst != src ? DMA_TO_DEVICE
  1293. : DMA_BIDIRECTIONAL);
  1294. }
  1295. if (dst && edesc->dst_nents) {
  1296. dma_sync_single_for_device(dev,
  1297. edesc->dma_link_tbl + len,
  1298. len, DMA_FROM_DEVICE);
  1299. sg_copy_from_buffer(dst, edesc->dst_nents ? : 1,
  1300. edesc->buf + len, len);
  1301. } else if (dst && dst != src) {
  1302. dma_unmap_sg(dev, dst, 1, DMA_FROM_DEVICE);
  1303. }
  1304. } else {
  1305. talitos_sg_unmap(dev, edesc, src, dst);
  1306. }
  1307. }
  1308. static void common_nonsnoop_unmap(struct device *dev,
  1309. struct talitos_edesc *edesc,
  1310. struct ablkcipher_request *areq)
  1311. {
  1312. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[5], DMA_FROM_DEVICE);
  1313. unmap_sg_talitos_ptr(dev, areq->src, areq->dst, areq->nbytes, edesc);
  1314. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], DMA_TO_DEVICE);
  1315. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[1], DMA_TO_DEVICE);
  1316. if (edesc->dma_len)
  1317. dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len,
  1318. DMA_BIDIRECTIONAL);
  1319. }
  1320. static void ablkcipher_done(struct device *dev,
  1321. struct talitos_desc *desc, void *context,
  1322. int err)
  1323. {
  1324. struct ablkcipher_request *areq = context;
  1325. struct talitos_edesc *edesc;
  1326. edesc = container_of(desc, struct talitos_edesc, desc);
  1327. common_nonsnoop_unmap(dev, edesc, areq);
  1328. kfree(edesc);
  1329. areq->base.complete(&areq->base, err);
  1330. }
  1331. int map_sg_in_talitos_ptr(struct device *dev, struct scatterlist *src,
  1332. unsigned int len, struct talitos_edesc *edesc,
  1333. enum dma_data_direction dir, struct talitos_ptr *ptr)
  1334. {
  1335. int sg_count;
  1336. struct talitos_private *priv = dev_get_drvdata(dev);
  1337. bool is_sec1 = has_ftr_sec1(priv);
  1338. to_talitos_ptr_len(ptr, len, is_sec1);
  1339. if (is_sec1) {
  1340. sg_count = edesc->src_nents ? : 1;
  1341. if (sg_count == 1) {
  1342. dma_map_sg(dev, src, 1, dir);
  1343. to_talitos_ptr(ptr, sg_dma_address(src), is_sec1);
  1344. } else {
  1345. sg_copy_to_buffer(src, sg_count, edesc->buf, len);
  1346. to_talitos_ptr(ptr, edesc->dma_link_tbl, is_sec1);
  1347. dma_sync_single_for_device(dev, edesc->dma_link_tbl,
  1348. len, DMA_TO_DEVICE);
  1349. }
  1350. } else {
  1351. to_talitos_ptr_extent_clear(ptr, is_sec1);
  1352. sg_count = talitos_map_sg(dev, src, edesc->src_nents ? : 1, dir,
  1353. edesc->src_chained);
  1354. if (sg_count == 1) {
  1355. to_talitos_ptr(ptr, sg_dma_address(src), is_sec1);
  1356. } else {
  1357. sg_count = sg_to_link_tbl(src, sg_count, len,
  1358. &edesc->link_tbl[0]);
  1359. if (sg_count > 1) {
  1360. to_talitos_ptr(ptr, edesc->dma_link_tbl, 0);
  1361. ptr->j_extent |= DESC_PTR_LNKTBL_JUMP;
  1362. dma_sync_single_for_device(dev,
  1363. edesc->dma_link_tbl,
  1364. edesc->dma_len,
  1365. DMA_BIDIRECTIONAL);
  1366. } else {
  1367. /* Only one segment now, so no link tbl needed*/
  1368. to_talitos_ptr(ptr, sg_dma_address(src),
  1369. is_sec1);
  1370. }
  1371. }
  1372. }
  1373. return sg_count;
  1374. }
  1375. void map_sg_out_talitos_ptr(struct device *dev, struct scatterlist *dst,
  1376. unsigned int len, struct talitos_edesc *edesc,
  1377. enum dma_data_direction dir,
  1378. struct talitos_ptr *ptr, int sg_count)
  1379. {
  1380. struct talitos_private *priv = dev_get_drvdata(dev);
  1381. bool is_sec1 = has_ftr_sec1(priv);
  1382. if (dir != DMA_NONE)
  1383. sg_count = talitos_map_sg(dev, dst, edesc->dst_nents ? : 1,
  1384. dir, edesc->dst_chained);
  1385. to_talitos_ptr_len(ptr, len, is_sec1);
  1386. if (is_sec1) {
  1387. if (sg_count == 1) {
  1388. if (dir != DMA_NONE)
  1389. dma_map_sg(dev, dst, 1, dir);
  1390. to_talitos_ptr(ptr, sg_dma_address(dst), is_sec1);
  1391. } else {
  1392. to_talitos_ptr(ptr, edesc->dma_link_tbl + len, is_sec1);
  1393. dma_sync_single_for_device(dev,
  1394. edesc->dma_link_tbl + len,
  1395. len, DMA_FROM_DEVICE);
  1396. }
  1397. } else {
  1398. to_talitos_ptr_extent_clear(ptr, is_sec1);
  1399. if (sg_count == 1) {
  1400. to_talitos_ptr(ptr, sg_dma_address(dst), is_sec1);
  1401. } else {
  1402. struct talitos_ptr *link_tbl_ptr =
  1403. &edesc->link_tbl[edesc->src_nents + 1];
  1404. to_talitos_ptr(ptr, edesc->dma_link_tbl +
  1405. (edesc->src_nents + 1) *
  1406. sizeof(struct talitos_ptr), 0);
  1407. ptr->j_extent |= DESC_PTR_LNKTBL_JUMP;
  1408. sg_to_link_tbl(dst, sg_count, len, link_tbl_ptr);
  1409. dma_sync_single_for_device(dev, edesc->dma_link_tbl,
  1410. edesc->dma_len,
  1411. DMA_BIDIRECTIONAL);
  1412. }
  1413. }
  1414. }
  1415. static int common_nonsnoop(struct talitos_edesc *edesc,
  1416. struct ablkcipher_request *areq,
  1417. void (*callback) (struct device *dev,
  1418. struct talitos_desc *desc,
  1419. void *context, int error))
  1420. {
  1421. struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
  1422. struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  1423. struct device *dev = ctx->dev;
  1424. struct talitos_desc *desc = &edesc->desc;
  1425. unsigned int cryptlen = areq->nbytes;
  1426. unsigned int ivsize = crypto_ablkcipher_ivsize(cipher);
  1427. int sg_count, ret;
  1428. struct talitos_private *priv = dev_get_drvdata(dev);
  1429. bool is_sec1 = has_ftr_sec1(priv);
  1430. /* first DWORD empty */
  1431. desc->ptr[0] = zero_entry;
  1432. /* cipher iv */
  1433. to_talitos_ptr(&desc->ptr[1], edesc->iv_dma, is_sec1);
  1434. to_talitos_ptr_len(&desc->ptr[1], ivsize, is_sec1);
  1435. to_talitos_ptr_extent_clear(&desc->ptr[1], is_sec1);
  1436. /* cipher key */
  1437. map_single_talitos_ptr(dev, &desc->ptr[2], ctx->keylen,
  1438. (char *)&ctx->key, DMA_TO_DEVICE);
  1439. /*
  1440. * cipher in
  1441. */
  1442. sg_count = map_sg_in_talitos_ptr(dev, areq->src, cryptlen, edesc,
  1443. (areq->src == areq->dst) ?
  1444. DMA_BIDIRECTIONAL : DMA_TO_DEVICE,
  1445. &desc->ptr[3]);
  1446. /* cipher out */
  1447. map_sg_out_talitos_ptr(dev, areq->dst, cryptlen, edesc,
  1448. (areq->src == areq->dst) ? DMA_NONE
  1449. : DMA_FROM_DEVICE,
  1450. &desc->ptr[4], sg_count);
  1451. /* iv out */
  1452. map_single_talitos_ptr(dev, &desc->ptr[5], ivsize, ctx->iv,
  1453. DMA_FROM_DEVICE);
  1454. /* last DWORD empty */
  1455. desc->ptr[6] = zero_entry;
  1456. ret = talitos_submit(dev, ctx->ch, desc, callback, areq);
  1457. if (ret != -EINPROGRESS) {
  1458. common_nonsnoop_unmap(dev, edesc, areq);
  1459. kfree(edesc);
  1460. }
  1461. return ret;
  1462. }
  1463. static struct talitos_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request *
  1464. areq, bool encrypt)
  1465. {
  1466. struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
  1467. struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  1468. unsigned int ivsize = crypto_ablkcipher_ivsize(cipher);
  1469. return talitos_edesc_alloc(ctx->dev, NULL, areq->src, areq->dst,
  1470. areq->info, 0, areq->nbytes, 0, ivsize, 0,
  1471. areq->base.flags, encrypt);
  1472. }
  1473. static int ablkcipher_encrypt(struct ablkcipher_request *areq)
  1474. {
  1475. struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
  1476. struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  1477. struct talitos_edesc *edesc;
  1478. /* allocate extended descriptor */
  1479. edesc = ablkcipher_edesc_alloc(areq, true);
  1480. if (IS_ERR(edesc))
  1481. return PTR_ERR(edesc);
  1482. /* set encrypt */
  1483. edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
  1484. return common_nonsnoop(edesc, areq, ablkcipher_done);
  1485. }
  1486. static int ablkcipher_decrypt(struct ablkcipher_request *areq)
  1487. {
  1488. struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
  1489. struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
  1490. struct talitos_edesc *edesc;
  1491. /* allocate extended descriptor */
  1492. edesc = ablkcipher_edesc_alloc(areq, false);
  1493. if (IS_ERR(edesc))
  1494. return PTR_ERR(edesc);
  1495. edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND;
  1496. return common_nonsnoop(edesc, areq, ablkcipher_done);
  1497. }
  1498. static void common_nonsnoop_hash_unmap(struct device *dev,
  1499. struct talitos_edesc *edesc,
  1500. struct ahash_request *areq)
  1501. {
  1502. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1503. struct talitos_private *priv = dev_get_drvdata(dev);
  1504. bool is_sec1 = has_ftr_sec1(priv);
  1505. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[5], DMA_FROM_DEVICE);
  1506. unmap_sg_talitos_ptr(dev, req_ctx->psrc, NULL, 0, edesc);
  1507. /* When using hashctx-in, must unmap it. */
  1508. if (from_talitos_ptr_len(&edesc->desc.ptr[1], is_sec1))
  1509. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[1],
  1510. DMA_TO_DEVICE);
  1511. if (from_talitos_ptr_len(&edesc->desc.ptr[2], is_sec1))
  1512. unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2],
  1513. DMA_TO_DEVICE);
  1514. if (edesc->dma_len)
  1515. dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len,
  1516. DMA_BIDIRECTIONAL);
  1517. }
  1518. static void ahash_done(struct device *dev,
  1519. struct talitos_desc *desc, void *context,
  1520. int err)
  1521. {
  1522. struct ahash_request *areq = context;
  1523. struct talitos_edesc *edesc =
  1524. container_of(desc, struct talitos_edesc, desc);
  1525. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1526. if (!req_ctx->last && req_ctx->to_hash_later) {
  1527. /* Position any partial block for next update/final/finup */
  1528. memcpy(req_ctx->buf, req_ctx->bufnext, req_ctx->to_hash_later);
  1529. req_ctx->nbuf = req_ctx->to_hash_later;
  1530. }
  1531. common_nonsnoop_hash_unmap(dev, edesc, areq);
  1532. kfree(edesc);
  1533. areq->base.complete(&areq->base, err);
  1534. }
  1535. /*
  1536. * SEC1 doesn't like hashing of 0 sized message, so we do the padding
  1537. * ourself and submit a padded block
  1538. */
  1539. void talitos_handle_buggy_hash(struct talitos_ctx *ctx,
  1540. struct talitos_edesc *edesc,
  1541. struct talitos_ptr *ptr)
  1542. {
  1543. static u8 padded_hash[64] = {
  1544. 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1548. };
  1549. pr_err_once("Bug in SEC1, padding ourself\n");
  1550. edesc->desc.hdr &= ~DESC_HDR_MODE0_MDEU_PAD;
  1551. map_single_talitos_ptr(ctx->dev, ptr, sizeof(padded_hash),
  1552. (char *)padded_hash, DMA_TO_DEVICE);
  1553. }
  1554. static int common_nonsnoop_hash(struct talitos_edesc *edesc,
  1555. struct ahash_request *areq, unsigned int length,
  1556. void (*callback) (struct device *dev,
  1557. struct talitos_desc *desc,
  1558. void *context, int error))
  1559. {
  1560. struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
  1561. struct talitos_ctx *ctx = crypto_ahash_ctx(tfm);
  1562. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1563. struct device *dev = ctx->dev;
  1564. struct talitos_desc *desc = &edesc->desc;
  1565. int ret;
  1566. struct talitos_private *priv = dev_get_drvdata(dev);
  1567. bool is_sec1 = has_ftr_sec1(priv);
  1568. /* first DWORD empty */
  1569. desc->ptr[0] = zero_entry;
  1570. /* hash context in */
  1571. if (!req_ctx->first || req_ctx->swinit) {
  1572. map_single_talitos_ptr(dev, &desc->ptr[1],
  1573. req_ctx->hw_context_size,
  1574. (char *)req_ctx->hw_context,
  1575. DMA_TO_DEVICE);
  1576. req_ctx->swinit = 0;
  1577. } else {
  1578. desc->ptr[1] = zero_entry;
  1579. /* Indicate next op is not the first. */
  1580. req_ctx->first = 0;
  1581. }
  1582. /* HMAC key */
  1583. if (ctx->keylen)
  1584. map_single_talitos_ptr(dev, &desc->ptr[2], ctx->keylen,
  1585. (char *)&ctx->key, DMA_TO_DEVICE);
  1586. else
  1587. desc->ptr[2] = zero_entry;
  1588. /*
  1589. * data in
  1590. */
  1591. map_sg_in_talitos_ptr(dev, req_ctx->psrc, length, edesc,
  1592. DMA_TO_DEVICE, &desc->ptr[3]);
  1593. /* fifth DWORD empty */
  1594. desc->ptr[4] = zero_entry;
  1595. /* hash/HMAC out -or- hash context out */
  1596. if (req_ctx->last)
  1597. map_single_talitos_ptr(dev, &desc->ptr[5],
  1598. crypto_ahash_digestsize(tfm),
  1599. areq->result, DMA_FROM_DEVICE);
  1600. else
  1601. map_single_talitos_ptr(dev, &desc->ptr[5],
  1602. req_ctx->hw_context_size,
  1603. req_ctx->hw_context, DMA_FROM_DEVICE);
  1604. /* last DWORD empty */
  1605. desc->ptr[6] = zero_entry;
  1606. if (is_sec1 && from_talitos_ptr_len(&desc->ptr[3], true) == 0)
  1607. talitos_handle_buggy_hash(ctx, edesc, &desc->ptr[3]);
  1608. ret = talitos_submit(dev, ctx->ch, desc, callback, areq);
  1609. if (ret != -EINPROGRESS) {
  1610. common_nonsnoop_hash_unmap(dev, edesc, areq);
  1611. kfree(edesc);
  1612. }
  1613. return ret;
  1614. }
  1615. static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq,
  1616. unsigned int nbytes)
  1617. {
  1618. struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
  1619. struct talitos_ctx *ctx = crypto_ahash_ctx(tfm);
  1620. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1621. return talitos_edesc_alloc(ctx->dev, NULL, req_ctx->psrc, NULL, NULL, 0,
  1622. nbytes, 0, 0, 0, areq->base.flags, false);
  1623. }
  1624. static int ahash_init(struct ahash_request *areq)
  1625. {
  1626. struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
  1627. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1628. /* Initialize the context */
  1629. req_ctx->nbuf = 0;
  1630. req_ctx->first = 1; /* first indicates h/w must init its context */
  1631. req_ctx->swinit = 0; /* assume h/w init of context */
  1632. req_ctx->hw_context_size =
  1633. (crypto_ahash_digestsize(tfm) <= SHA256_DIGEST_SIZE)
  1634. ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256
  1635. : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512;
  1636. return 0;
  1637. }
  1638. /*
  1639. * on h/w without explicit sha224 support, we initialize h/w context
  1640. * manually with sha224 constants, and tell it to run sha256.
  1641. */
  1642. static int ahash_init_sha224_swinit(struct ahash_request *areq)
  1643. {
  1644. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1645. ahash_init(areq);
  1646. req_ctx->swinit = 1;/* prevent h/w initting context with sha256 values*/
  1647. req_ctx->hw_context[0] = SHA224_H0;
  1648. req_ctx->hw_context[1] = SHA224_H1;
  1649. req_ctx->hw_context[2] = SHA224_H2;
  1650. req_ctx->hw_context[3] = SHA224_H3;
  1651. req_ctx->hw_context[4] = SHA224_H4;
  1652. req_ctx->hw_context[5] = SHA224_H5;
  1653. req_ctx->hw_context[6] = SHA224_H6;
  1654. req_ctx->hw_context[7] = SHA224_H7;
  1655. /* init 64-bit count */
  1656. req_ctx->hw_context[8] = 0;
  1657. req_ctx->hw_context[9] = 0;
  1658. return 0;
  1659. }
  1660. static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)
  1661. {
  1662. struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
  1663. struct talitos_ctx *ctx = crypto_ahash_ctx(tfm);
  1664. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1665. struct talitos_edesc *edesc;
  1666. unsigned int blocksize =
  1667. crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
  1668. unsigned int nbytes_to_hash;
  1669. unsigned int to_hash_later;
  1670. unsigned int nsg;
  1671. bool chained;
  1672. if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) {
  1673. /* Buffer up to one whole block */
  1674. sg_copy_to_buffer(areq->src,
  1675. sg_count(areq->src, nbytes, &chained),
  1676. req_ctx->buf + req_ctx->nbuf, nbytes);
  1677. req_ctx->nbuf += nbytes;
  1678. return 0;
  1679. }
  1680. /* At least (blocksize + 1) bytes are available to hash */
  1681. nbytes_to_hash = nbytes + req_ctx->nbuf;
  1682. to_hash_later = nbytes_to_hash & (blocksize - 1);
  1683. if (req_ctx->last)
  1684. to_hash_later = 0;
  1685. else if (to_hash_later)
  1686. /* There is a partial block. Hash the full block(s) now */
  1687. nbytes_to_hash -= to_hash_later;
  1688. else {
  1689. /* Keep one block buffered */
  1690. nbytes_to_hash -= blocksize;
  1691. to_hash_later = blocksize;
  1692. }
  1693. /* Chain in any previously buffered data */
  1694. if (req_ctx->nbuf) {
  1695. nsg = (req_ctx->nbuf < nbytes_to_hash) ? 2 : 1;
  1696. sg_init_table(req_ctx->bufsl, nsg);
  1697. sg_set_buf(req_ctx->bufsl, req_ctx->buf, req_ctx->nbuf);
  1698. if (nsg > 1)
  1699. scatterwalk_sg_chain(req_ctx->bufsl, 2, areq->src);
  1700. req_ctx->psrc = req_ctx->bufsl;
  1701. } else
  1702. req_ctx->psrc = areq->src;
  1703. if (to_hash_later) {
  1704. int nents = sg_count(areq->src, nbytes, &chained);
  1705. sg_pcopy_to_buffer(areq->src, nents,
  1706. req_ctx->bufnext,
  1707. to_hash_later,
  1708. nbytes - to_hash_later);
  1709. }
  1710. req_ctx->to_hash_later = to_hash_later;
  1711. /* Allocate extended descriptor */
  1712. edesc = ahash_edesc_alloc(areq, nbytes_to_hash);
  1713. if (IS_ERR(edesc))
  1714. return PTR_ERR(edesc);
  1715. edesc->desc.hdr = ctx->desc_hdr_template;
  1716. /* On last one, request SEC to pad; otherwise continue */
  1717. if (req_ctx->last)
  1718. edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_PAD;
  1719. else
  1720. edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_CONT;
  1721. /* request SEC to INIT hash. */
  1722. if (req_ctx->first && !req_ctx->swinit)
  1723. edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_INIT;
  1724. /* When the tfm context has a keylen, it's an HMAC.
  1725. * A first or last (ie. not middle) descriptor must request HMAC.
  1726. */
  1727. if (ctx->keylen && (req_ctx->first || req_ctx->last))
  1728. edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_HMAC;
  1729. return common_nonsnoop_hash(edesc, areq, nbytes_to_hash,
  1730. ahash_done);
  1731. }
  1732. static int ahash_update(struct ahash_request *areq)
  1733. {
  1734. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1735. req_ctx->last = 0;
  1736. return ahash_process_req(areq, areq->nbytes);
  1737. }
  1738. static int ahash_final(struct ahash_request *areq)
  1739. {
  1740. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1741. req_ctx->last = 1;
  1742. return ahash_process_req(areq, 0);
  1743. }
  1744. static int ahash_finup(struct ahash_request *areq)
  1745. {
  1746. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1747. req_ctx->last = 1;
  1748. return ahash_process_req(areq, areq->nbytes);
  1749. }
  1750. static int ahash_digest(struct ahash_request *areq)
  1751. {
  1752. struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq);
  1753. struct crypto_ahash *ahash = crypto_ahash_reqtfm(areq);
  1754. ahash->init(areq);
  1755. req_ctx->last = 1;
  1756. return ahash_process_req(areq, areq->nbytes);
  1757. }
  1758. struct keyhash_result {
  1759. struct completion completion;
  1760. int err;
  1761. };
  1762. static void keyhash_complete(struct crypto_async_request *req, int err)
  1763. {
  1764. struct keyhash_result *res = req->data;
  1765. if (err == -EINPROGRESS)
  1766. return;
  1767. res->err = err;
  1768. complete(&res->completion);
  1769. }
  1770. static int keyhash(struct crypto_ahash *tfm, const u8 *key, unsigned int keylen,
  1771. u8 *hash)
  1772. {
  1773. struct talitos_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm));
  1774. struct scatterlist sg[1];
  1775. struct ahash_request *req;
  1776. struct keyhash_result hresult;
  1777. int ret;
  1778. init_completion(&hresult.completion);
  1779. req = ahash_request_alloc(tfm, GFP_KERNEL);
  1780. if (!req)
  1781. return -ENOMEM;
  1782. /* Keep tfm keylen == 0 during hash of the long key */
  1783. ctx->keylen = 0;
  1784. ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  1785. keyhash_complete, &hresult);
  1786. sg_init_one(&sg[0], key, keylen);
  1787. ahash_request_set_crypt(req, sg, hash, keylen);
  1788. ret = crypto_ahash_digest(req);
  1789. switch (ret) {
  1790. case 0:
  1791. break;
  1792. case -EINPROGRESS:
  1793. case -EBUSY:
  1794. ret = wait_for_completion_interruptible(
  1795. &hresult.completion);
  1796. if (!ret)
  1797. ret = hresult.err;
  1798. break;
  1799. default:
  1800. break;
  1801. }
  1802. ahash_request_free(req);
  1803. return ret;
  1804. }
  1805. static int ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
  1806. unsigned int keylen)
  1807. {
  1808. struct talitos_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm));
  1809. unsigned int blocksize =
  1810. crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
  1811. unsigned int digestsize = crypto_ahash_digestsize(tfm);
  1812. unsigned int keysize = keylen;
  1813. u8 hash[SHA512_DIGEST_SIZE];
  1814. int ret;
  1815. if (keylen <= blocksize)
  1816. memcpy(ctx->key, key, keysize);
  1817. else {
  1818. /* Must get the hash of the long key */
  1819. ret = keyhash(tfm, key, keylen, hash);
  1820. if (ret) {
  1821. crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
  1822. return -EINVAL;
  1823. }
  1824. keysize = digestsize;
  1825. memcpy(ctx->key, hash, digestsize);
  1826. }
  1827. ctx->keylen = keysize;
  1828. return 0;
  1829. }
  1830. struct talitos_alg_template {
  1831. u32 type;
  1832. union {
  1833. struct crypto_alg crypto;
  1834. struct ahash_alg hash;
  1835. } alg;
  1836. __be32 desc_hdr_template;
  1837. };
  1838. static struct talitos_alg_template driver_algs[] = {
  1839. /* AEAD algorithms. These use a single-pass ipsec_esp descriptor */
  1840. { .type = CRYPTO_ALG_TYPE_AEAD,
  1841. .alg.crypto = {
  1842. .cra_name = "authenc(hmac(sha1),cbc(aes))",
  1843. .cra_driver_name = "authenc-hmac-sha1-cbc-aes-talitos",
  1844. .cra_blocksize = AES_BLOCK_SIZE,
  1845. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  1846. .cra_aead = {
  1847. .ivsize = AES_BLOCK_SIZE,
  1848. .maxauthsize = SHA1_DIGEST_SIZE,
  1849. }
  1850. },
  1851. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  1852. DESC_HDR_SEL0_AESU |
  1853. DESC_HDR_MODE0_AESU_CBC |
  1854. DESC_HDR_SEL1_MDEUA |
  1855. DESC_HDR_MODE1_MDEU_INIT |
  1856. DESC_HDR_MODE1_MDEU_PAD |
  1857. DESC_HDR_MODE1_MDEU_SHA1_HMAC,
  1858. },
  1859. { .type = CRYPTO_ALG_TYPE_AEAD,
  1860. .alg.crypto = {
  1861. .cra_name = "authenc(hmac(sha1),cbc(des3_ede))",
  1862. .cra_driver_name = "authenc-hmac-sha1-cbc-3des-talitos",
  1863. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1864. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  1865. .cra_aead = {
  1866. .ivsize = DES3_EDE_BLOCK_SIZE,
  1867. .maxauthsize = SHA1_DIGEST_SIZE,
  1868. }
  1869. },
  1870. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  1871. DESC_HDR_SEL0_DEU |
  1872. DESC_HDR_MODE0_DEU_CBC |
  1873. DESC_HDR_MODE0_DEU_3DES |
  1874. DESC_HDR_SEL1_MDEUA |
  1875. DESC_HDR_MODE1_MDEU_INIT |
  1876. DESC_HDR_MODE1_MDEU_PAD |
  1877. DESC_HDR_MODE1_MDEU_SHA1_HMAC,
  1878. },
  1879. { .type = CRYPTO_ALG_TYPE_AEAD,
  1880. .alg.crypto = {
  1881. .cra_name = "authenc(hmac(sha224),cbc(aes))",
  1882. .cra_driver_name = "authenc-hmac-sha224-cbc-aes-talitos",
  1883. .cra_blocksize = AES_BLOCK_SIZE,
  1884. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  1885. .cra_aead = {
  1886. .ivsize = AES_BLOCK_SIZE,
  1887. .maxauthsize = SHA224_DIGEST_SIZE,
  1888. }
  1889. },
  1890. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  1891. DESC_HDR_SEL0_AESU |
  1892. DESC_HDR_MODE0_AESU_CBC |
  1893. DESC_HDR_SEL1_MDEUA |
  1894. DESC_HDR_MODE1_MDEU_INIT |
  1895. DESC_HDR_MODE1_MDEU_PAD |
  1896. DESC_HDR_MODE1_MDEU_SHA224_HMAC,
  1897. },
  1898. { .type = CRYPTO_ALG_TYPE_AEAD,
  1899. .alg.crypto = {
  1900. .cra_name = "authenc(hmac(sha224),cbc(des3_ede))",
  1901. .cra_driver_name = "authenc-hmac-sha224-cbc-3des-talitos",
  1902. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1903. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  1904. .cra_aead = {
  1905. .ivsize = DES3_EDE_BLOCK_SIZE,
  1906. .maxauthsize = SHA224_DIGEST_SIZE,
  1907. }
  1908. },
  1909. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  1910. DESC_HDR_SEL0_DEU |
  1911. DESC_HDR_MODE0_DEU_CBC |
  1912. DESC_HDR_MODE0_DEU_3DES |
  1913. DESC_HDR_SEL1_MDEUA |
  1914. DESC_HDR_MODE1_MDEU_INIT |
  1915. DESC_HDR_MODE1_MDEU_PAD |
  1916. DESC_HDR_MODE1_MDEU_SHA224_HMAC,
  1917. },
  1918. { .type = CRYPTO_ALG_TYPE_AEAD,
  1919. .alg.crypto = {
  1920. .cra_name = "authenc(hmac(sha256),cbc(aes))",
  1921. .cra_driver_name = "authenc-hmac-sha256-cbc-aes-talitos",
  1922. .cra_blocksize = AES_BLOCK_SIZE,
  1923. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  1924. .cra_aead = {
  1925. .ivsize = AES_BLOCK_SIZE,
  1926. .maxauthsize = SHA256_DIGEST_SIZE,
  1927. }
  1928. },
  1929. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  1930. DESC_HDR_SEL0_AESU |
  1931. DESC_HDR_MODE0_AESU_CBC |
  1932. DESC_HDR_SEL1_MDEUA |
  1933. DESC_HDR_MODE1_MDEU_INIT |
  1934. DESC_HDR_MODE1_MDEU_PAD |
  1935. DESC_HDR_MODE1_MDEU_SHA256_HMAC,
  1936. },
  1937. { .type = CRYPTO_ALG_TYPE_AEAD,
  1938. .alg.crypto = {
  1939. .cra_name = "authenc(hmac(sha256),cbc(des3_ede))",
  1940. .cra_driver_name = "authenc-hmac-sha256-cbc-3des-talitos",
  1941. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1942. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  1943. .cra_aead = {
  1944. .ivsize = DES3_EDE_BLOCK_SIZE,
  1945. .maxauthsize = SHA256_DIGEST_SIZE,
  1946. }
  1947. },
  1948. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  1949. DESC_HDR_SEL0_DEU |
  1950. DESC_HDR_MODE0_DEU_CBC |
  1951. DESC_HDR_MODE0_DEU_3DES |
  1952. DESC_HDR_SEL1_MDEUA |
  1953. DESC_HDR_MODE1_MDEU_INIT |
  1954. DESC_HDR_MODE1_MDEU_PAD |
  1955. DESC_HDR_MODE1_MDEU_SHA256_HMAC,
  1956. },
  1957. { .type = CRYPTO_ALG_TYPE_AEAD,
  1958. .alg.crypto = {
  1959. .cra_name = "authenc(hmac(sha384),cbc(aes))",
  1960. .cra_driver_name = "authenc-hmac-sha384-cbc-aes-talitos",
  1961. .cra_blocksize = AES_BLOCK_SIZE,
  1962. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  1963. .cra_aead = {
  1964. .ivsize = AES_BLOCK_SIZE,
  1965. .maxauthsize = SHA384_DIGEST_SIZE,
  1966. }
  1967. },
  1968. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  1969. DESC_HDR_SEL0_AESU |
  1970. DESC_HDR_MODE0_AESU_CBC |
  1971. DESC_HDR_SEL1_MDEUB |
  1972. DESC_HDR_MODE1_MDEU_INIT |
  1973. DESC_HDR_MODE1_MDEU_PAD |
  1974. DESC_HDR_MODE1_MDEUB_SHA384_HMAC,
  1975. },
  1976. { .type = CRYPTO_ALG_TYPE_AEAD,
  1977. .alg.crypto = {
  1978. .cra_name = "authenc(hmac(sha384),cbc(des3_ede))",
  1979. .cra_driver_name = "authenc-hmac-sha384-cbc-3des-talitos",
  1980. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1981. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  1982. .cra_aead = {
  1983. .ivsize = DES3_EDE_BLOCK_SIZE,
  1984. .maxauthsize = SHA384_DIGEST_SIZE,
  1985. }
  1986. },
  1987. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  1988. DESC_HDR_SEL0_DEU |
  1989. DESC_HDR_MODE0_DEU_CBC |
  1990. DESC_HDR_MODE0_DEU_3DES |
  1991. DESC_HDR_SEL1_MDEUB |
  1992. DESC_HDR_MODE1_MDEU_INIT |
  1993. DESC_HDR_MODE1_MDEU_PAD |
  1994. DESC_HDR_MODE1_MDEUB_SHA384_HMAC,
  1995. },
  1996. { .type = CRYPTO_ALG_TYPE_AEAD,
  1997. .alg.crypto = {
  1998. .cra_name = "authenc(hmac(sha512),cbc(aes))",
  1999. .cra_driver_name = "authenc-hmac-sha512-cbc-aes-talitos",
  2000. .cra_blocksize = AES_BLOCK_SIZE,
  2001. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  2002. .cra_aead = {
  2003. .ivsize = AES_BLOCK_SIZE,
  2004. .maxauthsize = SHA512_DIGEST_SIZE,
  2005. }
  2006. },
  2007. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  2008. DESC_HDR_SEL0_AESU |
  2009. DESC_HDR_MODE0_AESU_CBC |
  2010. DESC_HDR_SEL1_MDEUB |
  2011. DESC_HDR_MODE1_MDEU_INIT |
  2012. DESC_HDR_MODE1_MDEU_PAD |
  2013. DESC_HDR_MODE1_MDEUB_SHA512_HMAC,
  2014. },
  2015. { .type = CRYPTO_ALG_TYPE_AEAD,
  2016. .alg.crypto = {
  2017. .cra_name = "authenc(hmac(sha512),cbc(des3_ede))",
  2018. .cra_driver_name = "authenc-hmac-sha512-cbc-3des-talitos",
  2019. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2020. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  2021. .cra_aead = {
  2022. .ivsize = DES3_EDE_BLOCK_SIZE,
  2023. .maxauthsize = SHA512_DIGEST_SIZE,
  2024. }
  2025. },
  2026. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  2027. DESC_HDR_SEL0_DEU |
  2028. DESC_HDR_MODE0_DEU_CBC |
  2029. DESC_HDR_MODE0_DEU_3DES |
  2030. DESC_HDR_SEL1_MDEUB |
  2031. DESC_HDR_MODE1_MDEU_INIT |
  2032. DESC_HDR_MODE1_MDEU_PAD |
  2033. DESC_HDR_MODE1_MDEUB_SHA512_HMAC,
  2034. },
  2035. { .type = CRYPTO_ALG_TYPE_AEAD,
  2036. .alg.crypto = {
  2037. .cra_name = "authenc(hmac(md5),cbc(aes))",
  2038. .cra_driver_name = "authenc-hmac-md5-cbc-aes-talitos",
  2039. .cra_blocksize = AES_BLOCK_SIZE,
  2040. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  2041. .cra_aead = {
  2042. .ivsize = AES_BLOCK_SIZE,
  2043. .maxauthsize = MD5_DIGEST_SIZE,
  2044. }
  2045. },
  2046. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  2047. DESC_HDR_SEL0_AESU |
  2048. DESC_HDR_MODE0_AESU_CBC |
  2049. DESC_HDR_SEL1_MDEUA |
  2050. DESC_HDR_MODE1_MDEU_INIT |
  2051. DESC_HDR_MODE1_MDEU_PAD |
  2052. DESC_HDR_MODE1_MDEU_MD5_HMAC,
  2053. },
  2054. { .type = CRYPTO_ALG_TYPE_AEAD,
  2055. .alg.crypto = {
  2056. .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
  2057. .cra_driver_name = "authenc-hmac-md5-cbc-3des-talitos",
  2058. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2059. .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
  2060. .cra_aead = {
  2061. .ivsize = DES3_EDE_BLOCK_SIZE,
  2062. .maxauthsize = MD5_DIGEST_SIZE,
  2063. }
  2064. },
  2065. .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
  2066. DESC_HDR_SEL0_DEU |
  2067. DESC_HDR_MODE0_DEU_CBC |
  2068. DESC_HDR_MODE0_DEU_3DES |
  2069. DESC_HDR_SEL1_MDEUA |
  2070. DESC_HDR_MODE1_MDEU_INIT |
  2071. DESC_HDR_MODE1_MDEU_PAD |
  2072. DESC_HDR_MODE1_MDEU_MD5_HMAC,
  2073. },
  2074. /* ABLKCIPHER algorithms. */
  2075. { .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
  2076. .alg.crypto = {
  2077. .cra_name = "cbc(aes)",
  2078. .cra_driver_name = "cbc-aes-talitos",
  2079. .cra_blocksize = AES_BLOCK_SIZE,
  2080. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  2081. CRYPTO_ALG_ASYNC,
  2082. .cra_ablkcipher = {
  2083. .min_keysize = AES_MIN_KEY_SIZE,
  2084. .max_keysize = AES_MAX_KEY_SIZE,
  2085. .ivsize = AES_BLOCK_SIZE,
  2086. }
  2087. },
  2088. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2089. DESC_HDR_SEL0_AESU |
  2090. DESC_HDR_MODE0_AESU_CBC,
  2091. },
  2092. { .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
  2093. .alg.crypto = {
  2094. .cra_name = "cbc(des3_ede)",
  2095. .cra_driver_name = "cbc-3des-talitos",
  2096. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2097. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  2098. CRYPTO_ALG_ASYNC,
  2099. .cra_ablkcipher = {
  2100. .min_keysize = DES3_EDE_KEY_SIZE,
  2101. .max_keysize = DES3_EDE_KEY_SIZE,
  2102. .ivsize = DES3_EDE_BLOCK_SIZE,
  2103. }
  2104. },
  2105. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2106. DESC_HDR_SEL0_DEU |
  2107. DESC_HDR_MODE0_DEU_CBC |
  2108. DESC_HDR_MODE0_DEU_3DES,
  2109. },
  2110. /* AHASH algorithms. */
  2111. { .type = CRYPTO_ALG_TYPE_AHASH,
  2112. .alg.hash = {
  2113. .halg.digestsize = MD5_DIGEST_SIZE,
  2114. .halg.base = {
  2115. .cra_name = "md5",
  2116. .cra_driver_name = "md5-talitos",
  2117. .cra_blocksize = MD5_HMAC_BLOCK_SIZE,
  2118. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2119. CRYPTO_ALG_ASYNC,
  2120. }
  2121. },
  2122. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2123. DESC_HDR_SEL0_MDEUA |
  2124. DESC_HDR_MODE0_MDEU_MD5,
  2125. },
  2126. { .type = CRYPTO_ALG_TYPE_AHASH,
  2127. .alg.hash = {
  2128. .halg.digestsize = SHA1_DIGEST_SIZE,
  2129. .halg.base = {
  2130. .cra_name = "sha1",
  2131. .cra_driver_name = "sha1-talitos",
  2132. .cra_blocksize = SHA1_BLOCK_SIZE,
  2133. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2134. CRYPTO_ALG_ASYNC,
  2135. }
  2136. },
  2137. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2138. DESC_HDR_SEL0_MDEUA |
  2139. DESC_HDR_MODE0_MDEU_SHA1,
  2140. },
  2141. { .type = CRYPTO_ALG_TYPE_AHASH,
  2142. .alg.hash = {
  2143. .halg.digestsize = SHA224_DIGEST_SIZE,
  2144. .halg.base = {
  2145. .cra_name = "sha224",
  2146. .cra_driver_name = "sha224-talitos",
  2147. .cra_blocksize = SHA224_BLOCK_SIZE,
  2148. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2149. CRYPTO_ALG_ASYNC,
  2150. }
  2151. },
  2152. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2153. DESC_HDR_SEL0_MDEUA |
  2154. DESC_HDR_MODE0_MDEU_SHA224,
  2155. },
  2156. { .type = CRYPTO_ALG_TYPE_AHASH,
  2157. .alg.hash = {
  2158. .halg.digestsize = SHA256_DIGEST_SIZE,
  2159. .halg.base = {
  2160. .cra_name = "sha256",
  2161. .cra_driver_name = "sha256-talitos",
  2162. .cra_blocksize = SHA256_BLOCK_SIZE,
  2163. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2164. CRYPTO_ALG_ASYNC,
  2165. }
  2166. },
  2167. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2168. DESC_HDR_SEL0_MDEUA |
  2169. DESC_HDR_MODE0_MDEU_SHA256,
  2170. },
  2171. { .type = CRYPTO_ALG_TYPE_AHASH,
  2172. .alg.hash = {
  2173. .halg.digestsize = SHA384_DIGEST_SIZE,
  2174. .halg.base = {
  2175. .cra_name = "sha384",
  2176. .cra_driver_name = "sha384-talitos",
  2177. .cra_blocksize = SHA384_BLOCK_SIZE,
  2178. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2179. CRYPTO_ALG_ASYNC,
  2180. }
  2181. },
  2182. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2183. DESC_HDR_SEL0_MDEUB |
  2184. DESC_HDR_MODE0_MDEUB_SHA384,
  2185. },
  2186. { .type = CRYPTO_ALG_TYPE_AHASH,
  2187. .alg.hash = {
  2188. .halg.digestsize = SHA512_DIGEST_SIZE,
  2189. .halg.base = {
  2190. .cra_name = "sha512",
  2191. .cra_driver_name = "sha512-talitos",
  2192. .cra_blocksize = SHA512_BLOCK_SIZE,
  2193. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2194. CRYPTO_ALG_ASYNC,
  2195. }
  2196. },
  2197. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2198. DESC_HDR_SEL0_MDEUB |
  2199. DESC_HDR_MODE0_MDEUB_SHA512,
  2200. },
  2201. { .type = CRYPTO_ALG_TYPE_AHASH,
  2202. .alg.hash = {
  2203. .halg.digestsize = MD5_DIGEST_SIZE,
  2204. .halg.base = {
  2205. .cra_name = "hmac(md5)",
  2206. .cra_driver_name = "hmac-md5-talitos",
  2207. .cra_blocksize = MD5_HMAC_BLOCK_SIZE,
  2208. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2209. CRYPTO_ALG_ASYNC,
  2210. }
  2211. },
  2212. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2213. DESC_HDR_SEL0_MDEUA |
  2214. DESC_HDR_MODE0_MDEU_MD5,
  2215. },
  2216. { .type = CRYPTO_ALG_TYPE_AHASH,
  2217. .alg.hash = {
  2218. .halg.digestsize = SHA1_DIGEST_SIZE,
  2219. .halg.base = {
  2220. .cra_name = "hmac(sha1)",
  2221. .cra_driver_name = "hmac-sha1-talitos",
  2222. .cra_blocksize = SHA1_BLOCK_SIZE,
  2223. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2224. CRYPTO_ALG_ASYNC,
  2225. }
  2226. },
  2227. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2228. DESC_HDR_SEL0_MDEUA |
  2229. DESC_HDR_MODE0_MDEU_SHA1,
  2230. },
  2231. { .type = CRYPTO_ALG_TYPE_AHASH,
  2232. .alg.hash = {
  2233. .halg.digestsize = SHA224_DIGEST_SIZE,
  2234. .halg.base = {
  2235. .cra_name = "hmac(sha224)",
  2236. .cra_driver_name = "hmac-sha224-talitos",
  2237. .cra_blocksize = SHA224_BLOCK_SIZE,
  2238. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2239. CRYPTO_ALG_ASYNC,
  2240. }
  2241. },
  2242. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2243. DESC_HDR_SEL0_MDEUA |
  2244. DESC_HDR_MODE0_MDEU_SHA224,
  2245. },
  2246. { .type = CRYPTO_ALG_TYPE_AHASH,
  2247. .alg.hash = {
  2248. .halg.digestsize = SHA256_DIGEST_SIZE,
  2249. .halg.base = {
  2250. .cra_name = "hmac(sha256)",
  2251. .cra_driver_name = "hmac-sha256-talitos",
  2252. .cra_blocksize = SHA256_BLOCK_SIZE,
  2253. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2254. CRYPTO_ALG_ASYNC,
  2255. }
  2256. },
  2257. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2258. DESC_HDR_SEL0_MDEUA |
  2259. DESC_HDR_MODE0_MDEU_SHA256,
  2260. },
  2261. { .type = CRYPTO_ALG_TYPE_AHASH,
  2262. .alg.hash = {
  2263. .halg.digestsize = SHA384_DIGEST_SIZE,
  2264. .halg.base = {
  2265. .cra_name = "hmac(sha384)",
  2266. .cra_driver_name = "hmac-sha384-talitos",
  2267. .cra_blocksize = SHA384_BLOCK_SIZE,
  2268. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2269. CRYPTO_ALG_ASYNC,
  2270. }
  2271. },
  2272. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2273. DESC_HDR_SEL0_MDEUB |
  2274. DESC_HDR_MODE0_MDEUB_SHA384,
  2275. },
  2276. { .type = CRYPTO_ALG_TYPE_AHASH,
  2277. .alg.hash = {
  2278. .halg.digestsize = SHA512_DIGEST_SIZE,
  2279. .halg.base = {
  2280. .cra_name = "hmac(sha512)",
  2281. .cra_driver_name = "hmac-sha512-talitos",
  2282. .cra_blocksize = SHA512_BLOCK_SIZE,
  2283. .cra_flags = CRYPTO_ALG_TYPE_AHASH |
  2284. CRYPTO_ALG_ASYNC,
  2285. }
  2286. },
  2287. .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2288. DESC_HDR_SEL0_MDEUB |
  2289. DESC_HDR_MODE0_MDEUB_SHA512,
  2290. }
  2291. };
  2292. struct talitos_crypto_alg {
  2293. struct list_head entry;
  2294. struct device *dev;
  2295. struct talitos_alg_template algt;
  2296. };
  2297. static int talitos_cra_init(struct crypto_tfm *tfm)
  2298. {
  2299. struct crypto_alg *alg = tfm->__crt_alg;
  2300. struct talitos_crypto_alg *talitos_alg;
  2301. struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
  2302. struct talitos_private *priv;
  2303. if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_AHASH)
  2304. talitos_alg = container_of(__crypto_ahash_alg(alg),
  2305. struct talitos_crypto_alg,
  2306. algt.alg.hash);
  2307. else
  2308. talitos_alg = container_of(alg, struct talitos_crypto_alg,
  2309. algt.alg.crypto);
  2310. /* update context with ptr to dev */
  2311. ctx->dev = talitos_alg->dev;
  2312. /* assign SEC channel to tfm in round-robin fashion */
  2313. priv = dev_get_drvdata(ctx->dev);
  2314. ctx->ch = atomic_inc_return(&priv->last_chan) &
  2315. (priv->num_channels - 1);
  2316. /* copy descriptor header template value */
  2317. ctx->desc_hdr_template = talitos_alg->algt.desc_hdr_template;
  2318. /* select done notification */
  2319. ctx->desc_hdr_template |= DESC_HDR_DONE_NOTIFY;
  2320. return 0;
  2321. }
  2322. static int talitos_cra_init_aead(struct crypto_tfm *tfm)
  2323. {
  2324. struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
  2325. talitos_cra_init(tfm);
  2326. /* random first IV */
  2327. get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH);
  2328. return 0;
  2329. }
  2330. static int talitos_cra_init_ahash(struct crypto_tfm *tfm)
  2331. {
  2332. struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
  2333. talitos_cra_init(tfm);
  2334. ctx->keylen = 0;
  2335. crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
  2336. sizeof(struct talitos_ahash_req_ctx));
  2337. return 0;
  2338. }
  2339. /*
  2340. * given the alg's descriptor header template, determine whether descriptor
  2341. * type and primary/secondary execution units required match the hw
  2342. * capabilities description provided in the device tree node.
  2343. */
  2344. static int hw_supports(struct device *dev, __be32 desc_hdr_template)
  2345. {
  2346. struct talitos_private *priv = dev_get_drvdata(dev);
  2347. int ret;
  2348. ret = (1 << DESC_TYPE(desc_hdr_template) & priv->desc_types) &&
  2349. (1 << PRIMARY_EU(desc_hdr_template) & priv->exec_units);
  2350. if (SECONDARY_EU(desc_hdr_template))
  2351. ret = ret && (1 << SECONDARY_EU(desc_hdr_template)
  2352. & priv->exec_units);
  2353. return ret;
  2354. }
  2355. static int talitos_remove(struct platform_device *ofdev)
  2356. {
  2357. struct device *dev = &ofdev->dev;
  2358. struct talitos_private *priv = dev_get_drvdata(dev);
  2359. struct talitos_crypto_alg *t_alg, *n;
  2360. int i;
  2361. list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) {
  2362. switch (t_alg->algt.type) {
  2363. case CRYPTO_ALG_TYPE_ABLKCIPHER:
  2364. case CRYPTO_ALG_TYPE_AEAD:
  2365. crypto_unregister_alg(&t_alg->algt.alg.crypto);
  2366. break;
  2367. case CRYPTO_ALG_TYPE_AHASH:
  2368. crypto_unregister_ahash(&t_alg->algt.alg.hash);
  2369. break;
  2370. }
  2371. list_del(&t_alg->entry);
  2372. kfree(t_alg);
  2373. }
  2374. if (hw_supports(dev, DESC_HDR_SEL0_RNG))
  2375. talitos_unregister_rng(dev);
  2376. for (i = 0; i < priv->num_channels; i++)
  2377. kfree(priv->chan[i].fifo);
  2378. kfree(priv->chan);
  2379. for (i = 0; i < 2; i++)
  2380. if (priv->irq[i]) {
  2381. free_irq(priv->irq[i], dev);
  2382. irq_dispose_mapping(priv->irq[i]);
  2383. }
  2384. tasklet_kill(&priv->done_task[0]);
  2385. if (priv->irq[1])
  2386. tasklet_kill(&priv->done_task[1]);
  2387. iounmap(priv->reg);
  2388. kfree(priv);
  2389. return 0;
  2390. }
  2391. static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
  2392. struct talitos_alg_template
  2393. *template)
  2394. {
  2395. struct talitos_private *priv = dev_get_drvdata(dev);
  2396. struct talitos_crypto_alg *t_alg;
  2397. struct crypto_alg *alg;
  2398. t_alg = kzalloc(sizeof(struct talitos_crypto_alg), GFP_KERNEL);
  2399. if (!t_alg)
  2400. return ERR_PTR(-ENOMEM);
  2401. t_alg->algt = *template;
  2402. switch (t_alg->algt.type) {
  2403. case CRYPTO_ALG_TYPE_ABLKCIPHER:
  2404. alg = &t_alg->algt.alg.crypto;
  2405. alg->cra_init = talitos_cra_init;
  2406. alg->cra_type = &crypto_ablkcipher_type;
  2407. alg->cra_ablkcipher.setkey = ablkcipher_setkey;
  2408. alg->cra_ablkcipher.encrypt = ablkcipher_encrypt;
  2409. alg->cra_ablkcipher.decrypt = ablkcipher_decrypt;
  2410. alg->cra_ablkcipher.geniv = "eseqiv";
  2411. break;
  2412. case CRYPTO_ALG_TYPE_AEAD:
  2413. alg = &t_alg->algt.alg.crypto;
  2414. alg->cra_init = talitos_cra_init_aead;
  2415. alg->cra_type = &crypto_aead_type;
  2416. alg->cra_aead.setkey = aead_setkey;
  2417. alg->cra_aead.setauthsize = aead_setauthsize;
  2418. alg->cra_aead.encrypt = aead_encrypt;
  2419. alg->cra_aead.decrypt = aead_decrypt;
  2420. alg->cra_aead.givencrypt = aead_givencrypt;
  2421. alg->cra_aead.geniv = "<built-in>";
  2422. break;
  2423. case CRYPTO_ALG_TYPE_AHASH:
  2424. alg = &t_alg->algt.alg.hash.halg.base;
  2425. alg->cra_init = talitos_cra_init_ahash;
  2426. alg->cra_type = &crypto_ahash_type;
  2427. t_alg->algt.alg.hash.init = ahash_init;
  2428. t_alg->algt.alg.hash.update = ahash_update;
  2429. t_alg->algt.alg.hash.final = ahash_final;
  2430. t_alg->algt.alg.hash.finup = ahash_finup;
  2431. t_alg->algt.alg.hash.digest = ahash_digest;
  2432. t_alg->algt.alg.hash.setkey = ahash_setkey;
  2433. if (!(priv->features & TALITOS_FTR_HMAC_OK) &&
  2434. !strncmp(alg->cra_name, "hmac", 4)) {
  2435. kfree(t_alg);
  2436. return ERR_PTR(-ENOTSUPP);
  2437. }
  2438. if (!(priv->features & TALITOS_FTR_SHA224_HWINIT) &&
  2439. (!strcmp(alg->cra_name, "sha224") ||
  2440. !strcmp(alg->cra_name, "hmac(sha224)"))) {
  2441. t_alg->algt.alg.hash.init = ahash_init_sha224_swinit;
  2442. t_alg->algt.desc_hdr_template =
  2443. DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
  2444. DESC_HDR_SEL0_MDEUA |
  2445. DESC_HDR_MODE0_MDEU_SHA256;
  2446. }
  2447. break;
  2448. default:
  2449. dev_err(dev, "unknown algorithm type %d\n", t_alg->algt.type);
  2450. kfree(t_alg);
  2451. return ERR_PTR(-EINVAL);
  2452. }
  2453. alg->cra_module = THIS_MODULE;
  2454. alg->cra_priority = TALITOS_CRA_PRIORITY;
  2455. alg->cra_alignmask = 0;
  2456. alg->cra_ctxsize = sizeof(struct talitos_ctx);
  2457. alg->cra_flags |= CRYPTO_ALG_KERN_DRIVER_ONLY;
  2458. t_alg->dev = dev;
  2459. return t_alg;
  2460. }
  2461. static int talitos_probe_irq(struct platform_device *ofdev)
  2462. {
  2463. struct device *dev = &ofdev->dev;
  2464. struct device_node *np = ofdev->dev.of_node;
  2465. struct talitos_private *priv = dev_get_drvdata(dev);
  2466. int err;
  2467. bool is_sec1 = has_ftr_sec1(priv);
  2468. priv->irq[0] = irq_of_parse_and_map(np, 0);
  2469. if (!priv->irq[0]) {
  2470. dev_err(dev, "failed to map irq\n");
  2471. return -EINVAL;
  2472. }
  2473. if (is_sec1) {
  2474. err = request_irq(priv->irq[0], talitos1_interrupt_4ch, 0,
  2475. dev_driver_string(dev), dev);
  2476. goto primary_out;
  2477. }
  2478. priv->irq[1] = irq_of_parse_and_map(np, 1);
  2479. /* get the primary irq line */
  2480. if (!priv->irq[1]) {
  2481. err = request_irq(priv->irq[0], talitos2_interrupt_4ch, 0,
  2482. dev_driver_string(dev), dev);
  2483. goto primary_out;
  2484. }
  2485. err = request_irq(priv->irq[0], talitos2_interrupt_ch0_2, 0,
  2486. dev_driver_string(dev), dev);
  2487. if (err)
  2488. goto primary_out;
  2489. /* get the secondary irq line */
  2490. err = request_irq(priv->irq[1], talitos2_interrupt_ch1_3, 0,
  2491. dev_driver_string(dev), dev);
  2492. if (err) {
  2493. dev_err(dev, "failed to request secondary irq\n");
  2494. irq_dispose_mapping(priv->irq[1]);
  2495. priv->irq[1] = 0;
  2496. }
  2497. return err;
  2498. primary_out:
  2499. if (err) {
  2500. dev_err(dev, "failed to request primary irq\n");
  2501. irq_dispose_mapping(priv->irq[0]);
  2502. priv->irq[0] = 0;
  2503. }
  2504. return err;
  2505. }
  2506. static int talitos_probe(struct platform_device *ofdev)
  2507. {
  2508. struct device *dev = &ofdev->dev;
  2509. struct device_node *np = ofdev->dev.of_node;
  2510. struct talitos_private *priv;
  2511. const unsigned int *prop;
  2512. int i, err;
  2513. int stride;
  2514. priv = kzalloc(sizeof(struct talitos_private), GFP_KERNEL);
  2515. if (!priv)
  2516. return -ENOMEM;
  2517. INIT_LIST_HEAD(&priv->alg_list);
  2518. dev_set_drvdata(dev, priv);
  2519. priv->ofdev = ofdev;
  2520. spin_lock_init(&priv->reg_lock);
  2521. priv->reg = of_iomap(np, 0);
  2522. if (!priv->reg) {
  2523. dev_err(dev, "failed to of_iomap\n");
  2524. err = -ENOMEM;
  2525. goto err_out;
  2526. }
  2527. /* get SEC version capabilities from device tree */
  2528. prop = of_get_property(np, "fsl,num-channels", NULL);
  2529. if (prop)
  2530. priv->num_channels = *prop;
  2531. prop = of_get_property(np, "fsl,channel-fifo-len", NULL);
  2532. if (prop)
  2533. priv->chfifo_len = *prop;
  2534. prop = of_get_property(np, "fsl,exec-units-mask", NULL);
  2535. if (prop)
  2536. priv->exec_units = *prop;
  2537. prop = of_get_property(np, "fsl,descriptor-types-mask", NULL);
  2538. if (prop)
  2539. priv->desc_types = *prop;
  2540. if (!is_power_of_2(priv->num_channels) || !priv->chfifo_len ||
  2541. !priv->exec_units || !priv->desc_types) {
  2542. dev_err(dev, "invalid property data in device tree node\n");
  2543. err = -EINVAL;
  2544. goto err_out;
  2545. }
  2546. if (of_device_is_compatible(np, "fsl,sec3.0"))
  2547. priv->features |= TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT;
  2548. if (of_device_is_compatible(np, "fsl,sec2.1"))
  2549. priv->features |= TALITOS_FTR_HW_AUTH_CHECK |
  2550. TALITOS_FTR_SHA224_HWINIT |
  2551. TALITOS_FTR_HMAC_OK;
  2552. if (of_device_is_compatible(np, "fsl,sec1.0"))
  2553. priv->features |= TALITOS_FTR_SEC1;
  2554. if (of_device_is_compatible(np, "fsl,sec1.2")) {
  2555. priv->reg_deu = priv->reg + TALITOS12_DEU;
  2556. priv->reg_aesu = priv->reg + TALITOS12_AESU;
  2557. priv->reg_mdeu = priv->reg + TALITOS12_MDEU;
  2558. stride = TALITOS1_CH_STRIDE;
  2559. } else if (of_device_is_compatible(np, "fsl,sec1.0")) {
  2560. priv->reg_deu = priv->reg + TALITOS10_DEU;
  2561. priv->reg_aesu = priv->reg + TALITOS10_AESU;
  2562. priv->reg_mdeu = priv->reg + TALITOS10_MDEU;
  2563. priv->reg_afeu = priv->reg + TALITOS10_AFEU;
  2564. priv->reg_rngu = priv->reg + TALITOS10_RNGU;
  2565. priv->reg_pkeu = priv->reg + TALITOS10_PKEU;
  2566. stride = TALITOS1_CH_STRIDE;
  2567. } else {
  2568. priv->reg_deu = priv->reg + TALITOS2_DEU;
  2569. priv->reg_aesu = priv->reg + TALITOS2_AESU;
  2570. priv->reg_mdeu = priv->reg + TALITOS2_MDEU;
  2571. priv->reg_afeu = priv->reg + TALITOS2_AFEU;
  2572. priv->reg_rngu = priv->reg + TALITOS2_RNGU;
  2573. priv->reg_pkeu = priv->reg + TALITOS2_PKEU;
  2574. priv->reg_keu = priv->reg + TALITOS2_KEU;
  2575. priv->reg_crcu = priv->reg + TALITOS2_CRCU;
  2576. stride = TALITOS2_CH_STRIDE;
  2577. }
  2578. err = talitos_probe_irq(ofdev);
  2579. if (err)
  2580. goto err_out;
  2581. if (of_device_is_compatible(np, "fsl,sec1.0")) {
  2582. tasklet_init(&priv->done_task[0], talitos1_done_4ch,
  2583. (unsigned long)dev);
  2584. } else {
  2585. if (!priv->irq[1]) {
  2586. tasklet_init(&priv->done_task[0], talitos2_done_4ch,
  2587. (unsigned long)dev);
  2588. } else {
  2589. tasklet_init(&priv->done_task[0], talitos2_done_ch0_2,
  2590. (unsigned long)dev);
  2591. tasklet_init(&priv->done_task[1], talitos2_done_ch1_3,
  2592. (unsigned long)dev);
  2593. }
  2594. }
  2595. priv->chan = kzalloc(sizeof(struct talitos_channel) *
  2596. priv->num_channels, GFP_KERNEL);
  2597. if (!priv->chan) {
  2598. dev_err(dev, "failed to allocate channel management space\n");
  2599. err = -ENOMEM;
  2600. goto err_out;
  2601. }
  2602. priv->fifo_len = roundup_pow_of_two(priv->chfifo_len);
  2603. for (i = 0; i < priv->num_channels; i++) {
  2604. priv->chan[i].reg = priv->reg + stride * (i + 1);
  2605. if (!priv->irq[1] || !(i & 1))
  2606. priv->chan[i].reg += TALITOS_CH_BASE_OFFSET;
  2607. spin_lock_init(&priv->chan[i].head_lock);
  2608. spin_lock_init(&priv->chan[i].tail_lock);
  2609. priv->chan[i].fifo = kzalloc(sizeof(struct talitos_request) *
  2610. priv->fifo_len, GFP_KERNEL);
  2611. if (!priv->chan[i].fifo) {
  2612. dev_err(dev, "failed to allocate request fifo %d\n", i);
  2613. err = -ENOMEM;
  2614. goto err_out;
  2615. }
  2616. atomic_set(&priv->chan[i].submit_count,
  2617. -(priv->chfifo_len - 1));
  2618. }
  2619. dma_set_mask(dev, DMA_BIT_MASK(36));
  2620. /* reset and initialize the h/w */
  2621. err = init_device(dev);
  2622. if (err) {
  2623. dev_err(dev, "failed to initialize device\n");
  2624. goto err_out;
  2625. }
  2626. /* register the RNG, if available */
  2627. if (hw_supports(dev, DESC_HDR_SEL0_RNG)) {
  2628. err = talitos_register_rng(dev);
  2629. if (err) {
  2630. dev_err(dev, "failed to register hwrng: %d\n", err);
  2631. goto err_out;
  2632. } else
  2633. dev_info(dev, "hwrng\n");
  2634. }
  2635. /* register crypto algorithms the device supports */
  2636. for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
  2637. if (hw_supports(dev, driver_algs[i].desc_hdr_template)) {
  2638. struct talitos_crypto_alg *t_alg;
  2639. char *name = NULL;
  2640. t_alg = talitos_alg_alloc(dev, &driver_algs[i]);
  2641. if (IS_ERR(t_alg)) {
  2642. err = PTR_ERR(t_alg);
  2643. if (err == -ENOTSUPP)
  2644. continue;
  2645. goto err_out;
  2646. }
  2647. switch (t_alg->algt.type) {
  2648. case CRYPTO_ALG_TYPE_ABLKCIPHER:
  2649. case CRYPTO_ALG_TYPE_AEAD:
  2650. err = crypto_register_alg(
  2651. &t_alg->algt.alg.crypto);
  2652. name = t_alg->algt.alg.crypto.cra_driver_name;
  2653. break;
  2654. case CRYPTO_ALG_TYPE_AHASH:
  2655. err = crypto_register_ahash(
  2656. &t_alg->algt.alg.hash);
  2657. name =
  2658. t_alg->algt.alg.hash.halg.base.cra_driver_name;
  2659. break;
  2660. }
  2661. if (err) {
  2662. dev_err(dev, "%s alg registration failed\n",
  2663. name);
  2664. kfree(t_alg);
  2665. } else
  2666. list_add_tail(&t_alg->entry, &priv->alg_list);
  2667. }
  2668. }
  2669. if (!list_empty(&priv->alg_list))
  2670. dev_info(dev, "%s algorithms registered in /proc/crypto\n",
  2671. (char *)of_get_property(np, "compatible", NULL));
  2672. return 0;
  2673. err_out:
  2674. talitos_remove(ofdev);
  2675. return err;
  2676. }
  2677. static const struct of_device_id talitos_match[] = {
  2678. #ifdef CONFIG_CRYPTO_DEV_TALITOS1
  2679. {
  2680. .compatible = "fsl,sec1.0",
  2681. },
  2682. #endif
  2683. #ifdef CONFIG_CRYPTO_DEV_TALITOS2
  2684. {
  2685. .compatible = "fsl,sec2.0",
  2686. },
  2687. #endif
  2688. {},
  2689. };
  2690. MODULE_DEVICE_TABLE(of, talitos_match);
  2691. static struct platform_driver talitos_driver = {
  2692. .driver = {
  2693. .name = "talitos",
  2694. .of_match_table = talitos_match,
  2695. },
  2696. .probe = talitos_probe,
  2697. .remove = talitos_remove,
  2698. };
  2699. module_platform_driver(talitos_driver);
  2700. MODULE_LICENSE("GPL");
  2701. MODULE_AUTHOR("Kim Phillips <kim.phillips@freescale.com>");
  2702. MODULE_DESCRIPTION("Freescale integrated security engine (SEC) driver");