safexcel.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2017 Marvell
  4. *
  5. * Antoine Tenart <antoine.tenart@free-electrons.com>
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/device.h>
  9. #include <linux/dma-mapping.h>
  10. #include <linux/dmapool.h>
  11. #include <linux/firmware.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/module.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/of_irq.h>
  16. #include <linux/pci.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/workqueue.h>
  19. #include <crypto/internal/aead.h>
  20. #include <crypto/internal/hash.h>
  21. #include <crypto/internal/skcipher.h>
  22. #include "safexcel.h"
  23. static u32 max_rings = EIP197_MAX_RINGS;
  24. module_param(max_rings, uint, 0644);
  25. MODULE_PARM_DESC(max_rings, "Maximum number of rings to use.");
  26. static void eip197_trc_cache_setupvirt(struct safexcel_crypto_priv *priv)
  27. {
  28. int i;
  29. /*
  30. * Map all interfaces/rings to register index 0
  31. * so they can share contexts. Without this, the EIP197 will
  32. * assume each interface/ring to be in its own memory domain
  33. * i.e. have its own subset of UNIQUE memory addresses.
  34. * Which would cause records with the SAME memory address to
  35. * use DIFFERENT cache buffers, causing both poor cache utilization
  36. * AND serious coherence/invalidation issues.
  37. */
  38. for (i = 0; i < 4; i++)
  39. writel(0, priv->base + EIP197_FLUE_IFC_LUT(i));
  40. /*
  41. * Initialize other virtualization regs for cache
  42. * These may not be in their reset state ...
  43. */
  44. for (i = 0; i < priv->config.rings; i++) {
  45. writel(0, priv->base + EIP197_FLUE_CACHEBASE_LO(i));
  46. writel(0, priv->base + EIP197_FLUE_CACHEBASE_HI(i));
  47. writel(EIP197_FLUE_CONFIG_MAGIC,
  48. priv->base + EIP197_FLUE_CONFIG(i));
  49. }
  50. writel(0, priv->base + EIP197_FLUE_OFFSETS);
  51. writel(0, priv->base + EIP197_FLUE_ARC4_OFFSET);
  52. }
  53. static void eip197_trc_cache_banksel(struct safexcel_crypto_priv *priv,
  54. u32 addrmid, int *actbank)
  55. {
  56. u32 val;
  57. int curbank;
  58. curbank = addrmid >> 16;
  59. if (curbank != *actbank) {
  60. val = readl(priv->base + EIP197_CS_RAM_CTRL);
  61. val = (val & ~EIP197_CS_BANKSEL_MASK) |
  62. (curbank << EIP197_CS_BANKSEL_OFS);
  63. writel(val, priv->base + EIP197_CS_RAM_CTRL);
  64. *actbank = curbank;
  65. }
  66. }
  67. static u32 eip197_trc_cache_probe(struct safexcel_crypto_priv *priv,
  68. int maxbanks, u32 probemask, u32 stride)
  69. {
  70. u32 val, addrhi, addrlo, addrmid, addralias, delta, marker;
  71. int actbank;
  72. /*
  73. * And probe the actual size of the physically attached cache data RAM
  74. * Using a binary subdivision algorithm downto 32 byte cache lines.
  75. */
  76. addrhi = 1 << (16 + maxbanks);
  77. addrlo = 0;
  78. actbank = min(maxbanks - 1, 0);
  79. while ((addrhi - addrlo) > stride) {
  80. /* write marker to lowest address in top half */
  81. addrmid = (addrhi + addrlo) >> 1;
  82. marker = (addrmid ^ 0xabadbabe) & probemask; /* Unique */
  83. eip197_trc_cache_banksel(priv, addrmid, &actbank);
  84. writel(marker,
  85. priv->base + EIP197_CLASSIFICATION_RAMS +
  86. (addrmid & 0xffff));
  87. /* write invalid markers to possible aliases */
  88. delta = 1 << __fls(addrmid);
  89. while (delta >= stride) {
  90. addralias = addrmid - delta;
  91. eip197_trc_cache_banksel(priv, addralias, &actbank);
  92. writel(~marker,
  93. priv->base + EIP197_CLASSIFICATION_RAMS +
  94. (addralias & 0xffff));
  95. delta >>= 1;
  96. }
  97. /* read back marker from top half */
  98. eip197_trc_cache_banksel(priv, addrmid, &actbank);
  99. val = readl(priv->base + EIP197_CLASSIFICATION_RAMS +
  100. (addrmid & 0xffff));
  101. if ((val & probemask) == marker)
  102. /* read back correct, continue with top half */
  103. addrlo = addrmid;
  104. else
  105. /* not read back correct, continue with bottom half */
  106. addrhi = addrmid;
  107. }
  108. return addrhi;
  109. }
  110. static void eip197_trc_cache_clear(struct safexcel_crypto_priv *priv,
  111. int cs_rc_max, int cs_ht_wc)
  112. {
  113. int i;
  114. u32 htable_offset, val, offset;
  115. /* Clear all records in administration RAM */
  116. for (i = 0; i < cs_rc_max; i++) {
  117. offset = EIP197_CLASSIFICATION_RAMS + i * EIP197_CS_RC_SIZE;
  118. writel(EIP197_CS_RC_NEXT(EIP197_RC_NULL) |
  119. EIP197_CS_RC_PREV(EIP197_RC_NULL),
  120. priv->base + offset);
  121. val = EIP197_CS_RC_NEXT(i + 1) | EIP197_CS_RC_PREV(i - 1);
  122. if (i == 0)
  123. val |= EIP197_CS_RC_PREV(EIP197_RC_NULL);
  124. else if (i == cs_rc_max - 1)
  125. val |= EIP197_CS_RC_NEXT(EIP197_RC_NULL);
  126. writel(val, priv->base + offset + 4);
  127. /* must also initialize the address key due to ECC! */
  128. writel(0, priv->base + offset + 8);
  129. writel(0, priv->base + offset + 12);
  130. }
  131. /* Clear the hash table entries */
  132. htable_offset = cs_rc_max * EIP197_CS_RC_SIZE;
  133. for (i = 0; i < cs_ht_wc; i++)
  134. writel(GENMASK(29, 0),
  135. priv->base + EIP197_CLASSIFICATION_RAMS +
  136. htable_offset + i * sizeof(u32));
  137. }
  138. static int eip197_trc_cache_init(struct safexcel_crypto_priv *priv)
  139. {
  140. u32 val, dsize, asize;
  141. int cs_rc_max, cs_ht_wc, cs_trc_rec_wc, cs_trc_lg_rec_wc;
  142. int cs_rc_abs_max, cs_ht_sz;
  143. int maxbanks;
  144. /* Setup (dummy) virtualization for cache */
  145. eip197_trc_cache_setupvirt(priv);
  146. /*
  147. * Enable the record cache memory access and
  148. * probe the bank select width
  149. */
  150. val = readl(priv->base + EIP197_CS_RAM_CTRL);
  151. val &= ~EIP197_TRC_ENABLE_MASK;
  152. val |= EIP197_TRC_ENABLE_0 | EIP197_CS_BANKSEL_MASK;
  153. writel(val, priv->base + EIP197_CS_RAM_CTRL);
  154. val = readl(priv->base + EIP197_CS_RAM_CTRL);
  155. maxbanks = ((val&EIP197_CS_BANKSEL_MASK)>>EIP197_CS_BANKSEL_OFS) + 1;
  156. /* Clear all ECC errors */
  157. writel(0, priv->base + EIP197_TRC_ECCCTRL);
  158. /*
  159. * Make sure the cache memory is accessible by taking record cache into
  160. * reset. Need data memory access here, not admin access.
  161. */
  162. val = readl(priv->base + EIP197_TRC_PARAMS);
  163. val |= EIP197_TRC_PARAMS_SW_RESET | EIP197_TRC_PARAMS_DATA_ACCESS;
  164. writel(val, priv->base + EIP197_TRC_PARAMS);
  165. /* Probed data RAM size in bytes */
  166. dsize = eip197_trc_cache_probe(priv, maxbanks, 0xffffffff, 32);
  167. /*
  168. * Now probe the administration RAM size pretty much the same way
  169. * Except that only the lower 30 bits are writable and we don't need
  170. * bank selects
  171. */
  172. val = readl(priv->base + EIP197_TRC_PARAMS);
  173. /* admin access now */
  174. val &= ~(EIP197_TRC_PARAMS_DATA_ACCESS | EIP197_CS_BANKSEL_MASK);
  175. writel(val, priv->base + EIP197_TRC_PARAMS);
  176. /* Probed admin RAM size in admin words */
  177. asize = eip197_trc_cache_probe(priv, 0, 0x3fffffff, 16) >> 4;
  178. /* Clear any ECC errors detected while probing! */
  179. writel(0, priv->base + EIP197_TRC_ECCCTRL);
  180. /* Sanity check probing results */
  181. if (dsize < EIP197_MIN_DSIZE || asize < EIP197_MIN_ASIZE) {
  182. dev_err(priv->dev, "Record cache probing failed (%d,%d).",
  183. dsize, asize);
  184. return -ENODEV;
  185. }
  186. /*
  187. * Determine optimal configuration from RAM sizes
  188. * Note that we assume that the physical RAM configuration is sane
  189. * Therefore, we don't do any parameter error checking here ...
  190. */
  191. /* For now, just use a single record format covering everything */
  192. cs_trc_rec_wc = EIP197_CS_TRC_REC_WC;
  193. cs_trc_lg_rec_wc = EIP197_CS_TRC_REC_WC;
  194. /*
  195. * Step #1: How many records will physically fit?
  196. * Hard upper limit is 1023!
  197. */
  198. cs_rc_abs_max = min_t(uint, ((dsize >> 2) / cs_trc_lg_rec_wc), 1023);
  199. /* Step #2: Need at least 2 words in the admin RAM per record */
  200. cs_rc_max = min_t(uint, cs_rc_abs_max, (asize >> 1));
  201. /* Step #3: Determine log2 of hash table size */
  202. cs_ht_sz = __fls(asize - cs_rc_max) - 2;
  203. /* Step #4: determine current size of hash table in dwords */
  204. cs_ht_wc = 16 << cs_ht_sz; /* dwords, not admin words */
  205. /* Step #5: add back excess words and see if we can fit more records */
  206. cs_rc_max = min_t(uint, cs_rc_abs_max, asize - (cs_ht_wc >> 2));
  207. /* Clear the cache RAMs */
  208. eip197_trc_cache_clear(priv, cs_rc_max, cs_ht_wc);
  209. /* Disable the record cache memory access */
  210. val = readl(priv->base + EIP197_CS_RAM_CTRL);
  211. val &= ~EIP197_TRC_ENABLE_MASK;
  212. writel(val, priv->base + EIP197_CS_RAM_CTRL);
  213. /* Write head and tail pointers of the record free chain */
  214. val = EIP197_TRC_FREECHAIN_HEAD_PTR(0) |
  215. EIP197_TRC_FREECHAIN_TAIL_PTR(cs_rc_max - 1);
  216. writel(val, priv->base + EIP197_TRC_FREECHAIN);
  217. /* Configure the record cache #1 */
  218. val = EIP197_TRC_PARAMS2_RC_SZ_SMALL(cs_trc_rec_wc) |
  219. EIP197_TRC_PARAMS2_HTABLE_PTR(cs_rc_max);
  220. writel(val, priv->base + EIP197_TRC_PARAMS2);
  221. /* Configure the record cache #2 */
  222. val = EIP197_TRC_PARAMS_RC_SZ_LARGE(cs_trc_lg_rec_wc) |
  223. EIP197_TRC_PARAMS_BLK_TIMER_SPEED(1) |
  224. EIP197_TRC_PARAMS_HTABLE_SZ(cs_ht_sz);
  225. writel(val, priv->base + EIP197_TRC_PARAMS);
  226. dev_info(priv->dev, "TRC init: %dd,%da (%dr,%dh)\n",
  227. dsize, asize, cs_rc_max, cs_ht_wc + cs_ht_wc);
  228. return 0;
  229. }
  230. static void eip197_init_firmware(struct safexcel_crypto_priv *priv)
  231. {
  232. int pe, i;
  233. u32 val;
  234. for (pe = 0; pe < priv->config.pes; pe++) {
  235. /* Configure the token FIFO's */
  236. writel(3, EIP197_PE(priv) + EIP197_PE_ICE_PUTF_CTRL(pe));
  237. writel(0, EIP197_PE(priv) + EIP197_PE_ICE_PPTF_CTRL(pe));
  238. /* Clear the ICE scratchpad memory */
  239. val = readl(EIP197_PE(priv) + EIP197_PE_ICE_SCRATCH_CTRL(pe));
  240. val |= EIP197_PE_ICE_SCRATCH_CTRL_CHANGE_TIMER |
  241. EIP197_PE_ICE_SCRATCH_CTRL_TIMER_EN |
  242. EIP197_PE_ICE_SCRATCH_CTRL_SCRATCH_ACCESS |
  243. EIP197_PE_ICE_SCRATCH_CTRL_CHANGE_ACCESS;
  244. writel(val, EIP197_PE(priv) + EIP197_PE_ICE_SCRATCH_CTRL(pe));
  245. /* clear the scratchpad RAM using 32 bit writes only */
  246. for (i = 0; i < EIP197_NUM_OF_SCRATCH_BLOCKS; i++)
  247. writel(0, EIP197_PE(priv) +
  248. EIP197_PE_ICE_SCRATCH_RAM(pe) + (i << 2));
  249. /* Reset the IFPP engine to make its program mem accessible */
  250. writel(EIP197_PE_ICE_x_CTRL_SW_RESET |
  251. EIP197_PE_ICE_x_CTRL_CLR_ECC_CORR |
  252. EIP197_PE_ICE_x_CTRL_CLR_ECC_NON_CORR,
  253. EIP197_PE(priv) + EIP197_PE_ICE_FPP_CTRL(pe));
  254. /* Reset the IPUE engine to make its program mem accessible */
  255. writel(EIP197_PE_ICE_x_CTRL_SW_RESET |
  256. EIP197_PE_ICE_x_CTRL_CLR_ECC_CORR |
  257. EIP197_PE_ICE_x_CTRL_CLR_ECC_NON_CORR,
  258. EIP197_PE(priv) + EIP197_PE_ICE_PUE_CTRL(pe));
  259. /* Enable access to all IFPP program memories */
  260. writel(EIP197_PE_ICE_RAM_CTRL_FPP_PROG_EN,
  261. EIP197_PE(priv) + EIP197_PE_ICE_RAM_CTRL(pe));
  262. /* bypass the OCE, if present */
  263. if (priv->flags & EIP197_OCE)
  264. writel(EIP197_DEBUG_OCE_BYPASS, EIP197_PE(priv) +
  265. EIP197_PE_DEBUG(pe));
  266. }
  267. }
  268. static int eip197_write_firmware(struct safexcel_crypto_priv *priv,
  269. const struct firmware *fw)
  270. {
  271. u32 val;
  272. int i;
  273. /* Write the firmware */
  274. for (i = 0; i < fw->size / sizeof(u32); i++) {
  275. if (priv->data->fw_little_endian)
  276. val = le32_to_cpu(((const __le32 *)fw->data)[i]);
  277. else
  278. val = be32_to_cpu(((const __be32 *)fw->data)[i]);
  279. writel(val,
  280. priv->base + EIP197_CLASSIFICATION_RAMS +
  281. i * sizeof(val));
  282. }
  283. /* Exclude final 2 NOPs from size */
  284. return i - EIP197_FW_TERMINAL_NOPS;
  285. }
  286. /*
  287. * If FW is actual production firmware, then poll for its initialization
  288. * to complete and check if it is good for the HW, otherwise just return OK.
  289. */
  290. static bool poll_fw_ready(struct safexcel_crypto_priv *priv, int fpp)
  291. {
  292. int pe, pollcnt;
  293. u32 base, pollofs;
  294. if (fpp)
  295. pollofs = EIP197_FW_FPP_READY;
  296. else
  297. pollofs = EIP197_FW_PUE_READY;
  298. for (pe = 0; pe < priv->config.pes; pe++) {
  299. base = EIP197_PE_ICE_SCRATCH_RAM(pe);
  300. pollcnt = EIP197_FW_START_POLLCNT;
  301. while (pollcnt &&
  302. (readl_relaxed(EIP197_PE(priv) + base +
  303. pollofs) != 1)) {
  304. pollcnt--;
  305. }
  306. if (!pollcnt) {
  307. dev_err(priv->dev, "FW(%d) for PE %d failed to start\n",
  308. fpp, pe);
  309. return false;
  310. }
  311. }
  312. return true;
  313. }
  314. static bool eip197_start_firmware(struct safexcel_crypto_priv *priv,
  315. int ipuesz, int ifppsz, int minifw)
  316. {
  317. int pe;
  318. u32 val;
  319. for (pe = 0; pe < priv->config.pes; pe++) {
  320. /* Disable access to all program memory */
  321. writel(0, EIP197_PE(priv) + EIP197_PE_ICE_RAM_CTRL(pe));
  322. /* Start IFPP microengines */
  323. if (minifw)
  324. val = 0;
  325. else
  326. val = EIP197_PE_ICE_UENG_START_OFFSET((ifppsz - 1) &
  327. EIP197_PE_ICE_UENG_INIT_ALIGN_MASK) |
  328. EIP197_PE_ICE_UENG_DEBUG_RESET;
  329. writel(val, EIP197_PE(priv) + EIP197_PE_ICE_FPP_CTRL(pe));
  330. /* Start IPUE microengines */
  331. if (minifw)
  332. val = 0;
  333. else
  334. val = EIP197_PE_ICE_UENG_START_OFFSET((ipuesz - 1) &
  335. EIP197_PE_ICE_UENG_INIT_ALIGN_MASK) |
  336. EIP197_PE_ICE_UENG_DEBUG_RESET;
  337. writel(val, EIP197_PE(priv) + EIP197_PE_ICE_PUE_CTRL(pe));
  338. }
  339. /* For miniFW startup, there is no initialization, so always succeed */
  340. if (minifw)
  341. return true;
  342. /* Wait until all the firmwares have properly started up */
  343. if (!poll_fw_ready(priv, 1))
  344. return false;
  345. if (!poll_fw_ready(priv, 0))
  346. return false;
  347. return true;
  348. }
  349. static int eip197_load_firmwares(struct safexcel_crypto_priv *priv)
  350. {
  351. const char *fw_name[] = {"ifpp.bin", "ipue.bin"};
  352. const struct firmware *fw[FW_NB];
  353. char fw_path[37], *dir = NULL;
  354. int i, j, ret = 0, pe;
  355. int ipuesz, ifppsz, minifw = 0;
  356. if (priv->data->version == EIP197D_MRVL)
  357. dir = "eip197d";
  358. else if (priv->data->version == EIP197B_MRVL ||
  359. priv->data->version == EIP197_DEVBRD)
  360. dir = "eip197b";
  361. else if (priv->data->version == EIP197C_MXL)
  362. dir = "eip197c";
  363. else
  364. return -ENODEV;
  365. retry_fw:
  366. for (i = 0; i < FW_NB; i++) {
  367. snprintf(fw_path, 37, "inside-secure/%s/%s", dir, fw_name[i]);
  368. ret = firmware_request_nowarn(&fw[i], fw_path, priv->dev);
  369. if (ret) {
  370. if (minifw || priv->data->version != EIP197B_MRVL)
  371. goto release_fw;
  372. /* Fallback to the old firmware location for the
  373. * EIP197b.
  374. */
  375. ret = firmware_request_nowarn(&fw[i], fw_name[i],
  376. priv->dev);
  377. if (ret)
  378. goto release_fw;
  379. }
  380. }
  381. eip197_init_firmware(priv);
  382. ifppsz = eip197_write_firmware(priv, fw[FW_IFPP]);
  383. /* Enable access to IPUE program memories */
  384. for (pe = 0; pe < priv->config.pes; pe++)
  385. writel(EIP197_PE_ICE_RAM_CTRL_PUE_PROG_EN,
  386. EIP197_PE(priv) + EIP197_PE_ICE_RAM_CTRL(pe));
  387. ipuesz = eip197_write_firmware(priv, fw[FW_IPUE]);
  388. if (eip197_start_firmware(priv, ipuesz, ifppsz, minifw)) {
  389. dev_dbg(priv->dev, "Firmware loaded successfully\n");
  390. return 0;
  391. }
  392. ret = -ENODEV;
  393. release_fw:
  394. for (j = 0; j < i; j++)
  395. release_firmware(fw[j]);
  396. if (!minifw) {
  397. /* Retry with minifw path */
  398. dev_dbg(priv->dev, "Firmware set not (fully) present or init failed, falling back to BCLA mode\n");
  399. dir = "eip197_minifw";
  400. minifw = 1;
  401. goto retry_fw;
  402. }
  403. dev_err(priv->dev, "Firmware load failed.\n");
  404. return ret;
  405. }
  406. static int safexcel_hw_setup_cdesc_rings(struct safexcel_crypto_priv *priv)
  407. {
  408. u32 cd_size_rnd, val;
  409. int i, cd_fetch_cnt;
  410. cd_size_rnd = (priv->config.cd_size +
  411. (BIT(priv->hwconfig.hwdataw) - 1)) >>
  412. priv->hwconfig.hwdataw;
  413. /* determine number of CD's we can fetch into the CD FIFO as 1 block */
  414. if (priv->flags & SAFEXCEL_HW_EIP197) {
  415. /* EIP197: try to fetch enough in 1 go to keep all pipes busy */
  416. cd_fetch_cnt = (1 << priv->hwconfig.hwcfsize) / cd_size_rnd;
  417. cd_fetch_cnt = min_t(uint, cd_fetch_cnt,
  418. (priv->config.pes * EIP197_FETCH_DEPTH));
  419. } else {
  420. /* for the EIP97, just fetch all that fits minus 1 */
  421. cd_fetch_cnt = ((1 << priv->hwconfig.hwcfsize) /
  422. cd_size_rnd) - 1;
  423. }
  424. /*
  425. * Since we're using command desc's way larger than formally specified,
  426. * we need to check whether we can fit even 1 for low-end EIP196's!
  427. */
  428. if (!cd_fetch_cnt) {
  429. dev_err(priv->dev, "Unable to fit even 1 command desc!\n");
  430. return -ENODEV;
  431. }
  432. for (i = 0; i < priv->config.rings; i++) {
  433. /* ring base address */
  434. writel(lower_32_bits(priv->ring[i].cdr.base_dma),
  435. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_LO);
  436. writel(upper_32_bits(priv->ring[i].cdr.base_dma),
  437. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_HI);
  438. writel(EIP197_xDR_DESC_MODE_64BIT | EIP197_CDR_DESC_MODE_ADCP |
  439. (priv->config.cd_offset << 14) | priv->config.cd_size,
  440. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_DESC_SIZE);
  441. writel(((cd_fetch_cnt *
  442. (cd_size_rnd << priv->hwconfig.hwdataw)) << 16) |
  443. (cd_fetch_cnt * (priv->config.cd_offset / sizeof(u32))),
  444. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_CFG);
  445. /* Configure DMA tx control */
  446. val = EIP197_HIA_xDR_CFG_WR_CACHE(WR_CACHE_3BITS);
  447. val |= EIP197_HIA_xDR_CFG_RD_CACHE(RD_CACHE_3BITS);
  448. writel(val, EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_DMA_CFG);
  449. /* clear any pending interrupt */
  450. writel(GENMASK(5, 0),
  451. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_STAT);
  452. }
  453. return 0;
  454. }
  455. static int safexcel_hw_setup_rdesc_rings(struct safexcel_crypto_priv *priv)
  456. {
  457. u32 rd_size_rnd, val;
  458. int i, rd_fetch_cnt;
  459. /* determine number of RD's we can fetch into the FIFO as one block */
  460. rd_size_rnd = (EIP197_RD64_FETCH_SIZE +
  461. (BIT(priv->hwconfig.hwdataw) - 1)) >>
  462. priv->hwconfig.hwdataw;
  463. if (priv->flags & SAFEXCEL_HW_EIP197) {
  464. /* EIP197: try to fetch enough in 1 go to keep all pipes busy */
  465. rd_fetch_cnt = (1 << priv->hwconfig.hwrfsize) / rd_size_rnd;
  466. rd_fetch_cnt = min_t(uint, rd_fetch_cnt,
  467. (priv->config.pes * EIP197_FETCH_DEPTH));
  468. } else {
  469. /* for the EIP97, just fetch all that fits minus 1 */
  470. rd_fetch_cnt = ((1 << priv->hwconfig.hwrfsize) /
  471. rd_size_rnd) - 1;
  472. }
  473. for (i = 0; i < priv->config.rings; i++) {
  474. /* ring base address */
  475. writel(lower_32_bits(priv->ring[i].rdr.base_dma),
  476. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_LO);
  477. writel(upper_32_bits(priv->ring[i].rdr.base_dma),
  478. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_HI);
  479. writel(EIP197_xDR_DESC_MODE_64BIT | (priv->config.rd_offset << 14) |
  480. priv->config.rd_size,
  481. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_DESC_SIZE);
  482. writel(((rd_fetch_cnt *
  483. (rd_size_rnd << priv->hwconfig.hwdataw)) << 16) |
  484. (rd_fetch_cnt * (priv->config.rd_offset / sizeof(u32))),
  485. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_CFG);
  486. /* Configure DMA tx control */
  487. val = EIP197_HIA_xDR_CFG_WR_CACHE(WR_CACHE_3BITS);
  488. val |= EIP197_HIA_xDR_CFG_RD_CACHE(RD_CACHE_3BITS);
  489. val |= EIP197_HIA_xDR_WR_RES_BUF | EIP197_HIA_xDR_WR_CTRL_BUF;
  490. writel(val,
  491. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_DMA_CFG);
  492. /* clear any pending interrupt */
  493. writel(GENMASK(7, 0),
  494. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_STAT);
  495. /* enable ring interrupt */
  496. val = readl(EIP197_HIA_AIC_R(priv) + EIP197_HIA_AIC_R_ENABLE_CTRL(i));
  497. val |= EIP197_RDR_IRQ(i);
  498. writel(val, EIP197_HIA_AIC_R(priv) + EIP197_HIA_AIC_R_ENABLE_CTRL(i));
  499. }
  500. return 0;
  501. }
  502. static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
  503. {
  504. u32 val;
  505. int i, ret, pe, opbuflo, opbufhi;
  506. dev_dbg(priv->dev, "HW init: using %d pipe(s) and %d ring(s)\n",
  507. priv->config.pes, priv->config.rings);
  508. /*
  509. * For EIP197's only set maximum number of TX commands to 2^5 = 32
  510. * Skip for the EIP97 as it does not have this field.
  511. */
  512. if (priv->flags & SAFEXCEL_HW_EIP197) {
  513. val = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_MST_CTRL);
  514. val |= EIP197_MST_CTRL_TX_MAX_CMD(5);
  515. writel(val, EIP197_HIA_AIC(priv) + EIP197_HIA_MST_CTRL);
  516. }
  517. /* Configure wr/rd cache values */
  518. writel(EIP197_MST_CTRL_RD_CACHE(RD_CACHE_4BITS) |
  519. EIP197_MST_CTRL_WD_CACHE(WR_CACHE_4BITS),
  520. EIP197_HIA_GEN_CFG(priv) + EIP197_MST_CTRL);
  521. /* Interrupts reset */
  522. /* Disable all global interrupts */
  523. writel(0, EIP197_HIA_AIC_G(priv) + EIP197_HIA_AIC_G_ENABLE_CTRL);
  524. /* Clear any pending interrupt */
  525. writel(GENMASK(31, 0), EIP197_HIA_AIC_G(priv) + EIP197_HIA_AIC_G_ACK);
  526. /* Processing Engine configuration */
  527. for (pe = 0; pe < priv->config.pes; pe++) {
  528. /* Data Fetch Engine configuration */
  529. /* Reset all DFE threads */
  530. writel(EIP197_DxE_THR_CTRL_RESET_PE,
  531. EIP197_HIA_DFE_THR(priv) + EIP197_HIA_DFE_THR_CTRL(pe));
  532. if (priv->flags & EIP197_PE_ARB)
  533. /* Reset HIA input interface arbiter (if present) */
  534. writel(EIP197_HIA_RA_PE_CTRL_RESET,
  535. EIP197_HIA_AIC(priv) + EIP197_HIA_RA_PE_CTRL(pe));
  536. /* DMA transfer size to use */
  537. val = EIP197_HIA_DFE_CFG_DIS_DEBUG;
  538. val |= EIP197_HIA_DxE_CFG_MIN_DATA_SIZE(6) |
  539. EIP197_HIA_DxE_CFG_MAX_DATA_SIZE(9);
  540. val |= EIP197_HIA_DxE_CFG_MIN_CTRL_SIZE(6) |
  541. EIP197_HIA_DxE_CFG_MAX_CTRL_SIZE(7);
  542. val |= EIP197_HIA_DxE_CFG_DATA_CACHE_CTRL(RD_CACHE_3BITS);
  543. val |= EIP197_HIA_DxE_CFG_CTRL_CACHE_CTRL(RD_CACHE_3BITS);
  544. writel(val, EIP197_HIA_DFE(priv) + EIP197_HIA_DFE_CFG(pe));
  545. /* Leave the DFE threads reset state */
  546. writel(0, EIP197_HIA_DFE_THR(priv) + EIP197_HIA_DFE_THR_CTRL(pe));
  547. /* Configure the processing engine thresholds */
  548. writel(EIP197_PE_IN_xBUF_THRES_MIN(6) |
  549. EIP197_PE_IN_xBUF_THRES_MAX(9),
  550. EIP197_PE(priv) + EIP197_PE_IN_DBUF_THRES(pe));
  551. writel(EIP197_PE_IN_xBUF_THRES_MIN(6) |
  552. EIP197_PE_IN_xBUF_THRES_MAX(7),
  553. EIP197_PE(priv) + EIP197_PE_IN_TBUF_THRES(pe));
  554. if (priv->flags & SAFEXCEL_HW_EIP197)
  555. /* enable HIA input interface arbiter and rings */
  556. writel(EIP197_HIA_RA_PE_CTRL_EN |
  557. GENMASK(priv->config.rings - 1, 0),
  558. EIP197_HIA_AIC(priv) + EIP197_HIA_RA_PE_CTRL(pe));
  559. /* Data Store Engine configuration */
  560. /* Reset all DSE threads */
  561. writel(EIP197_DxE_THR_CTRL_RESET_PE,
  562. EIP197_HIA_DSE_THR(priv) + EIP197_HIA_DSE_THR_CTRL(pe));
  563. /* Wait for all DSE threads to complete */
  564. while ((readl(EIP197_HIA_DSE_THR(priv) + EIP197_HIA_DSE_THR_STAT(pe)) &
  565. GENMASK(15, 12)) != GENMASK(15, 12))
  566. ;
  567. /* DMA transfer size to use */
  568. if (priv->hwconfig.hwnumpes > 4) {
  569. opbuflo = 9;
  570. opbufhi = 10;
  571. } else {
  572. opbuflo = 7;
  573. opbufhi = 8;
  574. }
  575. val = EIP197_HIA_DSE_CFG_DIS_DEBUG;
  576. val |= EIP197_HIA_DxE_CFG_MIN_DATA_SIZE(opbuflo) |
  577. EIP197_HIA_DxE_CFG_MAX_DATA_SIZE(opbufhi);
  578. val |= EIP197_HIA_DxE_CFG_DATA_CACHE_CTRL(WR_CACHE_3BITS);
  579. val |= EIP197_HIA_DSE_CFG_ALWAYS_BUFFERABLE;
  580. /* FIXME: instability issues can occur for EIP97 but disabling
  581. * it impacts performance.
  582. */
  583. if (priv->flags & SAFEXCEL_HW_EIP197)
  584. val |= EIP197_HIA_DSE_CFG_EN_SINGLE_WR;
  585. writel(val, EIP197_HIA_DSE(priv) + EIP197_HIA_DSE_CFG(pe));
  586. /* Leave the DSE threads reset state */
  587. writel(0, EIP197_HIA_DSE_THR(priv) + EIP197_HIA_DSE_THR_CTRL(pe));
  588. /* Configure the processing engine thresholds */
  589. writel(EIP197_PE_OUT_DBUF_THRES_MIN(opbuflo) |
  590. EIP197_PE_OUT_DBUF_THRES_MAX(opbufhi),
  591. EIP197_PE(priv) + EIP197_PE_OUT_DBUF_THRES(pe));
  592. /* Processing Engine configuration */
  593. /* Token & context configuration */
  594. val = EIP197_PE_EIP96_TOKEN_CTRL_CTX_UPDATES |
  595. EIP197_PE_EIP96_TOKEN_CTRL_NO_TOKEN_WAIT |
  596. EIP197_PE_EIP96_TOKEN_CTRL_ENABLE_TIMEOUT;
  597. writel(val, EIP197_PE(priv) + EIP197_PE_EIP96_TOKEN_CTRL(pe));
  598. /* H/W capabilities selection: just enable everything */
  599. writel(EIP197_FUNCTION_ALL,
  600. EIP197_PE(priv) + EIP197_PE_EIP96_FUNCTION_EN(pe));
  601. writel(EIP197_FUNCTION_ALL,
  602. EIP197_PE(priv) + EIP197_PE_EIP96_FUNCTION2_EN(pe));
  603. }
  604. /* Command Descriptor Rings prepare */
  605. for (i = 0; i < priv->config.rings; i++) {
  606. /* Clear interrupts for this ring */
  607. writel(GENMASK(31, 0),
  608. EIP197_HIA_AIC_R(priv) + EIP197_HIA_AIC_R_ENABLE_CLR(i));
  609. /* Disable external triggering */
  610. writel(0, EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_CFG);
  611. /* Clear the pending prepared counter */
  612. writel(EIP197_xDR_PREP_CLR_COUNT,
  613. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_PREP_COUNT);
  614. /* Clear the pending processed counter */
  615. writel(EIP197_xDR_PROC_CLR_COUNT,
  616. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_PROC_COUNT);
  617. writel(0,
  618. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_PREP_PNTR);
  619. writel(0,
  620. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_PROC_PNTR);
  621. writel((EIP197_DEFAULT_RING_SIZE * priv->config.cd_offset),
  622. EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_RING_SIZE);
  623. }
  624. /* Result Descriptor Ring prepare */
  625. for (i = 0; i < priv->config.rings; i++) {
  626. /* Disable external triggering*/
  627. writel(0, EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_CFG);
  628. /* Clear the pending prepared counter */
  629. writel(EIP197_xDR_PREP_CLR_COUNT,
  630. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_PREP_COUNT);
  631. /* Clear the pending processed counter */
  632. writel(EIP197_xDR_PROC_CLR_COUNT,
  633. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_PROC_COUNT);
  634. writel(0,
  635. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_PREP_PNTR);
  636. writel(0,
  637. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_PROC_PNTR);
  638. /* Ring size */
  639. writel((EIP197_DEFAULT_RING_SIZE * priv->config.rd_offset),
  640. EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_RING_SIZE);
  641. }
  642. for (pe = 0; pe < priv->config.pes; pe++) {
  643. /* Enable command descriptor rings */
  644. writel(EIP197_DxE_THR_CTRL_EN | GENMASK(priv->config.rings - 1, 0),
  645. EIP197_HIA_DFE_THR(priv) + EIP197_HIA_DFE_THR_CTRL(pe));
  646. /* Enable result descriptor rings */
  647. writel(EIP197_DxE_THR_CTRL_EN | GENMASK(priv->config.rings - 1, 0),
  648. EIP197_HIA_DSE_THR(priv) + EIP197_HIA_DSE_THR_CTRL(pe));
  649. }
  650. /* Clear any HIA interrupt */
  651. writel(GENMASK(30, 20), EIP197_HIA_AIC_G(priv) + EIP197_HIA_AIC_G_ACK);
  652. if (priv->flags & EIP197_SIMPLE_TRC) {
  653. writel(EIP197_STRC_CONFIG_INIT |
  654. EIP197_STRC_CONFIG_LARGE_REC(EIP197_CS_TRC_REC_WC) |
  655. EIP197_STRC_CONFIG_SMALL_REC(EIP197_CS_TRC_REC_WC),
  656. priv->base + EIP197_STRC_CONFIG);
  657. writel(EIP197_PE_EIP96_TOKEN_CTRL2_CTX_DONE,
  658. EIP197_PE(priv) + EIP197_PE_EIP96_TOKEN_CTRL2(0));
  659. } else if (priv->flags & SAFEXCEL_HW_EIP197) {
  660. ret = eip197_trc_cache_init(priv);
  661. if (ret)
  662. return ret;
  663. }
  664. if (priv->flags & EIP197_ICE) {
  665. ret = eip197_load_firmwares(priv);
  666. if (ret)
  667. return ret;
  668. }
  669. return safexcel_hw_setup_cdesc_rings(priv) ?:
  670. safexcel_hw_setup_rdesc_rings(priv) ?:
  671. 0;
  672. }
  673. /* Called with ring's lock taken */
  674. static void safexcel_try_push_requests(struct safexcel_crypto_priv *priv,
  675. int ring)
  676. {
  677. int coal = min_t(int, priv->ring[ring].requests, EIP197_MAX_BATCH_SZ);
  678. if (!coal)
  679. return;
  680. /* Configure when we want an interrupt */
  681. writel(EIP197_HIA_RDR_THRESH_PKT_MODE |
  682. EIP197_HIA_RDR_THRESH_PROC_PKT(coal),
  683. EIP197_HIA_RDR(priv, ring) + EIP197_HIA_xDR_THRESH);
  684. }
  685. void safexcel_dequeue(struct safexcel_crypto_priv *priv, int ring)
  686. {
  687. struct crypto_async_request *req, *backlog;
  688. struct safexcel_context *ctx;
  689. int ret, nreq = 0, cdesc = 0, rdesc = 0, commands, results;
  690. /* If a request wasn't properly dequeued because of a lack of resources,
  691. * proceeded it first,
  692. */
  693. req = priv->ring[ring].req;
  694. backlog = priv->ring[ring].backlog;
  695. if (req)
  696. goto handle_req;
  697. while (true) {
  698. spin_lock_bh(&priv->ring[ring].queue_lock);
  699. backlog = crypto_get_backlog(&priv->ring[ring].queue);
  700. req = crypto_dequeue_request(&priv->ring[ring].queue);
  701. spin_unlock_bh(&priv->ring[ring].queue_lock);
  702. if (!req) {
  703. priv->ring[ring].req = NULL;
  704. priv->ring[ring].backlog = NULL;
  705. goto finalize;
  706. }
  707. handle_req:
  708. ctx = crypto_tfm_ctx(req->tfm);
  709. ret = ctx->send(req, ring, &commands, &results);
  710. if (ret)
  711. goto request_failed;
  712. if (backlog)
  713. crypto_request_complete(backlog, -EINPROGRESS);
  714. /* In case the send() helper did not issue any command to push
  715. * to the engine because the input data was cached, continue to
  716. * dequeue other requests as this is valid and not an error.
  717. */
  718. if (!commands && !results)
  719. continue;
  720. cdesc += commands;
  721. rdesc += results;
  722. nreq++;
  723. }
  724. request_failed:
  725. /* Not enough resources to handle all the requests. Bail out and save
  726. * the request and the backlog for the next dequeue call (per-ring).
  727. */
  728. priv->ring[ring].req = req;
  729. priv->ring[ring].backlog = backlog;
  730. finalize:
  731. if (!nreq)
  732. return;
  733. spin_lock_bh(&priv->ring[ring].lock);
  734. priv->ring[ring].requests += nreq;
  735. if (!priv->ring[ring].busy) {
  736. safexcel_try_push_requests(priv, ring);
  737. priv->ring[ring].busy = true;
  738. }
  739. spin_unlock_bh(&priv->ring[ring].lock);
  740. /* let the RDR know we have pending descriptors */
  741. writel((rdesc * priv->config.rd_offset),
  742. EIP197_HIA_RDR(priv, ring) + EIP197_HIA_xDR_PREP_COUNT);
  743. /* let the CDR know we have pending descriptors */
  744. writel((cdesc * priv->config.cd_offset),
  745. EIP197_HIA_CDR(priv, ring) + EIP197_HIA_xDR_PREP_COUNT);
  746. }
  747. inline int safexcel_rdesc_check_errors(struct safexcel_crypto_priv *priv,
  748. void *rdp)
  749. {
  750. struct safexcel_result_desc *rdesc = rdp;
  751. struct result_data_desc *result_data = rdp + priv->config.res_offset;
  752. if (likely((!rdesc->last_seg) || /* Rest only valid if last seg! */
  753. ((!rdesc->descriptor_overflow) &&
  754. (!rdesc->buffer_overflow) &&
  755. (!result_data->error_code))))
  756. return 0;
  757. if (rdesc->descriptor_overflow)
  758. dev_err(priv->dev, "Descriptor overflow detected");
  759. if (rdesc->buffer_overflow)
  760. dev_err(priv->dev, "Buffer overflow detected");
  761. if (result_data->error_code & 0x4066) {
  762. /* Fatal error (bits 1,2,5,6 & 14) */
  763. dev_err(priv->dev,
  764. "result descriptor error (%x)",
  765. result_data->error_code);
  766. return -EIO;
  767. } else if (result_data->error_code &
  768. (BIT(7) | BIT(4) | BIT(3) | BIT(0))) {
  769. /*
  770. * Give priority over authentication fails:
  771. * Blocksize, length & overflow errors,
  772. * something wrong with the input!
  773. */
  774. return -EINVAL;
  775. } else if (result_data->error_code & BIT(9)) {
  776. /* Authentication failed */
  777. return -EBADMSG;
  778. }
  779. /* All other non-fatal errors */
  780. return -EINVAL;
  781. }
  782. inline void safexcel_rdr_req_set(struct safexcel_crypto_priv *priv,
  783. int ring,
  784. struct safexcel_result_desc *rdesc,
  785. struct crypto_async_request *req)
  786. {
  787. int i = safexcel_ring_rdr_rdesc_index(priv, ring, rdesc);
  788. priv->ring[ring].rdr_req[i] = req;
  789. }
  790. inline struct crypto_async_request *
  791. safexcel_rdr_req_get(struct safexcel_crypto_priv *priv, int ring)
  792. {
  793. int i = safexcel_ring_first_rdr_index(priv, ring);
  794. return priv->ring[ring].rdr_req[i];
  795. }
  796. void safexcel_complete(struct safexcel_crypto_priv *priv, int ring)
  797. {
  798. struct safexcel_command_desc *cdesc;
  799. /* Acknowledge the command descriptors */
  800. do {
  801. cdesc = safexcel_ring_next_rptr(priv, &priv->ring[ring].cdr);
  802. if (IS_ERR(cdesc)) {
  803. dev_err(priv->dev,
  804. "Could not retrieve the command descriptor\n");
  805. return;
  806. }
  807. } while (!cdesc->last_seg);
  808. }
  809. int safexcel_invalidate_cache(struct crypto_async_request *async,
  810. struct safexcel_crypto_priv *priv,
  811. dma_addr_t ctxr_dma, int ring)
  812. {
  813. struct safexcel_command_desc *cdesc;
  814. struct safexcel_result_desc *rdesc;
  815. struct safexcel_token *dmmy;
  816. int ret = 0;
  817. /* Prepare command descriptor */
  818. cdesc = safexcel_add_cdesc(priv, ring, true, true, 0, 0, 0, ctxr_dma,
  819. &dmmy);
  820. if (IS_ERR(cdesc))
  821. return PTR_ERR(cdesc);
  822. cdesc->control_data.type = EIP197_TYPE_EXTENDED;
  823. cdesc->control_data.options = 0;
  824. cdesc->control_data.context_lo &= ~EIP197_CONTEXT_SIZE_MASK;
  825. cdesc->control_data.control0 = CONTEXT_CONTROL_INV_TR;
  826. /* Prepare result descriptor */
  827. rdesc = safexcel_add_rdesc(priv, ring, true, true, 0, 0);
  828. if (IS_ERR(rdesc)) {
  829. ret = PTR_ERR(rdesc);
  830. goto cdesc_rollback;
  831. }
  832. safexcel_rdr_req_set(priv, ring, rdesc, async);
  833. return ret;
  834. cdesc_rollback:
  835. safexcel_ring_rollback_wptr(priv, &priv->ring[ring].cdr);
  836. return ret;
  837. }
  838. static inline void safexcel_handle_result_descriptor(struct safexcel_crypto_priv *priv,
  839. int ring)
  840. {
  841. struct crypto_async_request *req;
  842. struct safexcel_context *ctx;
  843. int ret, i, nreq, ndesc, tot_descs, handled = 0;
  844. bool should_complete;
  845. handle_results:
  846. tot_descs = 0;
  847. nreq = readl(EIP197_HIA_RDR(priv, ring) + EIP197_HIA_xDR_PROC_COUNT);
  848. nreq >>= EIP197_xDR_PROC_xD_PKT_OFFSET;
  849. nreq &= EIP197_xDR_PROC_xD_PKT_MASK;
  850. if (!nreq)
  851. goto requests_left;
  852. for (i = 0; i < nreq; i++) {
  853. req = safexcel_rdr_req_get(priv, ring);
  854. ctx = crypto_tfm_ctx(req->tfm);
  855. ndesc = ctx->handle_result(priv, ring, req,
  856. &should_complete, &ret);
  857. if (ndesc < 0) {
  858. dev_err(priv->dev, "failed to handle result (%d)\n",
  859. ndesc);
  860. goto acknowledge;
  861. }
  862. if (should_complete) {
  863. local_bh_disable();
  864. crypto_request_complete(req, ret);
  865. local_bh_enable();
  866. }
  867. tot_descs += ndesc;
  868. handled++;
  869. }
  870. acknowledge:
  871. if (i)
  872. writel(EIP197_xDR_PROC_xD_PKT(i) |
  873. (tot_descs * priv->config.rd_offset),
  874. EIP197_HIA_RDR(priv, ring) + EIP197_HIA_xDR_PROC_COUNT);
  875. /* If the number of requests overflowed the counter, try to proceed more
  876. * requests.
  877. */
  878. if (nreq == EIP197_xDR_PROC_xD_PKT_MASK)
  879. goto handle_results;
  880. requests_left:
  881. spin_lock_bh(&priv->ring[ring].lock);
  882. priv->ring[ring].requests -= handled;
  883. safexcel_try_push_requests(priv, ring);
  884. if (!priv->ring[ring].requests)
  885. priv->ring[ring].busy = false;
  886. spin_unlock_bh(&priv->ring[ring].lock);
  887. }
  888. static void safexcel_dequeue_work(struct work_struct *work)
  889. {
  890. struct safexcel_work_data *data =
  891. container_of(work, struct safexcel_work_data, work);
  892. safexcel_dequeue(data->priv, data->ring);
  893. }
  894. struct safexcel_ring_irq_data {
  895. struct safexcel_crypto_priv *priv;
  896. int ring;
  897. };
  898. static irqreturn_t safexcel_irq_ring(int irq, void *data)
  899. {
  900. struct safexcel_ring_irq_data *irq_data = data;
  901. struct safexcel_crypto_priv *priv = irq_data->priv;
  902. int ring = irq_data->ring, rc = IRQ_NONE;
  903. u32 status, stat;
  904. status = readl(EIP197_HIA_AIC_R(priv) + EIP197_HIA_AIC_R_ENABLED_STAT(ring));
  905. if (!status)
  906. return rc;
  907. /* RDR interrupts */
  908. if (status & EIP197_RDR_IRQ(ring)) {
  909. stat = readl(EIP197_HIA_RDR(priv, ring) + EIP197_HIA_xDR_STAT);
  910. if (unlikely(stat & EIP197_xDR_ERR)) {
  911. /*
  912. * Fatal error, the RDR is unusable and must be
  913. * reinitialized. This should not happen under
  914. * normal circumstances.
  915. */
  916. dev_err(priv->dev, "RDR: fatal error.\n");
  917. } else if (likely(stat & EIP197_xDR_THRESH)) {
  918. rc = IRQ_WAKE_THREAD;
  919. }
  920. /* ACK the interrupts */
  921. writel(stat & 0xff,
  922. EIP197_HIA_RDR(priv, ring) + EIP197_HIA_xDR_STAT);
  923. }
  924. /* ACK the interrupts */
  925. writel(status, EIP197_HIA_AIC_R(priv) + EIP197_HIA_AIC_R_ACK(ring));
  926. return rc;
  927. }
  928. static irqreturn_t safexcel_irq_ring_thread(int irq, void *data)
  929. {
  930. struct safexcel_ring_irq_data *irq_data = data;
  931. struct safexcel_crypto_priv *priv = irq_data->priv;
  932. int ring = irq_data->ring;
  933. safexcel_handle_result_descriptor(priv, ring);
  934. queue_work(priv->ring[ring].workqueue,
  935. &priv->ring[ring].work_data.work);
  936. return IRQ_HANDLED;
  937. }
  938. static int safexcel_request_ring_irq(void *pdev, int irqid,
  939. int is_pci_dev,
  940. int ring_id,
  941. irq_handler_t handler,
  942. irq_handler_t threaded_handler,
  943. struct safexcel_ring_irq_data *ring_irq_priv)
  944. {
  945. int ret, irq, cpu;
  946. struct device *dev;
  947. if (IS_ENABLED(CONFIG_PCI) && is_pci_dev) {
  948. struct pci_dev *pci_pdev = pdev;
  949. dev = &pci_pdev->dev;
  950. irq = pci_irq_vector(pci_pdev, irqid);
  951. if (irq < 0) {
  952. dev_err(dev, "unable to get device MSI IRQ %d (err %d)\n",
  953. irqid, irq);
  954. return irq;
  955. }
  956. } else if (IS_ENABLED(CONFIG_OF)) {
  957. struct platform_device *plf_pdev = pdev;
  958. char irq_name[6] = {0}; /* "ringX\0" */
  959. snprintf(irq_name, 6, "ring%d", irqid);
  960. dev = &plf_pdev->dev;
  961. irq = platform_get_irq_byname(plf_pdev, irq_name);
  962. if (irq < 0)
  963. return irq;
  964. } else {
  965. return -ENXIO;
  966. }
  967. ret = devm_request_threaded_irq(dev, irq, handler,
  968. threaded_handler, IRQF_ONESHOT,
  969. dev_name(dev), ring_irq_priv);
  970. if (ret) {
  971. dev_err(dev, "unable to request IRQ %d\n", irq);
  972. return ret;
  973. }
  974. /* Set affinity */
  975. cpu = cpumask_local_spread(ring_id, NUMA_NO_NODE);
  976. irq_set_affinity_hint(irq, get_cpu_mask(cpu));
  977. return irq;
  978. }
  979. static struct safexcel_alg_template *safexcel_algs[] = {
  980. &safexcel_alg_ecb_des,
  981. &safexcel_alg_cbc_des,
  982. &safexcel_alg_ecb_des3_ede,
  983. &safexcel_alg_cbc_des3_ede,
  984. &safexcel_alg_ecb_aes,
  985. &safexcel_alg_cbc_aes,
  986. &safexcel_alg_ctr_aes,
  987. &safexcel_alg_md5,
  988. &safexcel_alg_sha1,
  989. &safexcel_alg_sha224,
  990. &safexcel_alg_sha256,
  991. &safexcel_alg_sha384,
  992. &safexcel_alg_sha512,
  993. &safexcel_alg_hmac_md5,
  994. &safexcel_alg_hmac_sha1,
  995. &safexcel_alg_hmac_sha224,
  996. &safexcel_alg_hmac_sha256,
  997. &safexcel_alg_hmac_sha384,
  998. &safexcel_alg_hmac_sha512,
  999. &safexcel_alg_authenc_hmac_sha1_cbc_aes,
  1000. &safexcel_alg_authenc_hmac_sha224_cbc_aes,
  1001. &safexcel_alg_authenc_hmac_sha256_cbc_aes,
  1002. &safexcel_alg_authenc_hmac_sha384_cbc_aes,
  1003. &safexcel_alg_authenc_hmac_sha512_cbc_aes,
  1004. &safexcel_alg_authenc_hmac_sha1_cbc_des3_ede,
  1005. &safexcel_alg_authenc_hmac_sha1_ctr_aes,
  1006. &safexcel_alg_authenc_hmac_sha224_ctr_aes,
  1007. &safexcel_alg_authenc_hmac_sha256_ctr_aes,
  1008. &safexcel_alg_authenc_hmac_sha384_ctr_aes,
  1009. &safexcel_alg_authenc_hmac_sha512_ctr_aes,
  1010. &safexcel_alg_xts_aes,
  1011. &safexcel_alg_gcm,
  1012. &safexcel_alg_ccm,
  1013. &safexcel_alg_cbcmac,
  1014. &safexcel_alg_xcbcmac,
  1015. &safexcel_alg_cmac,
  1016. &safexcel_alg_chacha20,
  1017. &safexcel_alg_chachapoly,
  1018. &safexcel_alg_chachapoly_esp,
  1019. &safexcel_alg_sm3,
  1020. &safexcel_alg_hmac_sm3,
  1021. &safexcel_alg_ecb_sm4,
  1022. &safexcel_alg_cbc_sm4,
  1023. &safexcel_alg_ctr_sm4,
  1024. &safexcel_alg_authenc_hmac_sha1_cbc_sm4,
  1025. &safexcel_alg_authenc_hmac_sm3_cbc_sm4,
  1026. &safexcel_alg_authenc_hmac_sha1_ctr_sm4,
  1027. &safexcel_alg_authenc_hmac_sm3_ctr_sm4,
  1028. &safexcel_alg_sha3_224,
  1029. &safexcel_alg_sha3_256,
  1030. &safexcel_alg_sha3_384,
  1031. &safexcel_alg_sha3_512,
  1032. &safexcel_alg_hmac_sha3_224,
  1033. &safexcel_alg_hmac_sha3_256,
  1034. &safexcel_alg_hmac_sha3_384,
  1035. &safexcel_alg_hmac_sha3_512,
  1036. &safexcel_alg_authenc_hmac_sha1_cbc_des,
  1037. &safexcel_alg_authenc_hmac_sha256_cbc_des3_ede,
  1038. &safexcel_alg_authenc_hmac_sha224_cbc_des3_ede,
  1039. &safexcel_alg_authenc_hmac_sha512_cbc_des3_ede,
  1040. &safexcel_alg_authenc_hmac_sha384_cbc_des3_ede,
  1041. &safexcel_alg_authenc_hmac_sha256_cbc_des,
  1042. &safexcel_alg_authenc_hmac_sha224_cbc_des,
  1043. &safexcel_alg_authenc_hmac_sha512_cbc_des,
  1044. &safexcel_alg_authenc_hmac_sha384_cbc_des,
  1045. &safexcel_alg_rfc4106_gcm,
  1046. &safexcel_alg_rfc4543_gcm,
  1047. &safexcel_alg_rfc4309_ccm,
  1048. };
  1049. static int safexcel_register_algorithms(struct safexcel_crypto_priv *priv)
  1050. {
  1051. int i, j, ret = 0;
  1052. for (i = 0; i < ARRAY_SIZE(safexcel_algs); i++) {
  1053. safexcel_algs[i]->priv = priv;
  1054. /* Do we have all required base algorithms available? */
  1055. if ((safexcel_algs[i]->algo_mask & priv->hwconfig.algo_flags) !=
  1056. safexcel_algs[i]->algo_mask)
  1057. /* No, so don't register this ciphersuite */
  1058. continue;
  1059. if (safexcel_algs[i]->type == SAFEXCEL_ALG_TYPE_SKCIPHER)
  1060. ret = crypto_register_skcipher(&safexcel_algs[i]->alg.skcipher);
  1061. else if (safexcel_algs[i]->type == SAFEXCEL_ALG_TYPE_AEAD)
  1062. ret = crypto_register_aead(&safexcel_algs[i]->alg.aead);
  1063. else
  1064. ret = crypto_register_ahash(&safexcel_algs[i]->alg.ahash);
  1065. if (ret)
  1066. goto fail;
  1067. }
  1068. return 0;
  1069. fail:
  1070. for (j = 0; j < i; j++) {
  1071. /* Do we have all required base algorithms available? */
  1072. if ((safexcel_algs[j]->algo_mask & priv->hwconfig.algo_flags) !=
  1073. safexcel_algs[j]->algo_mask)
  1074. /* No, so don't unregister this ciphersuite */
  1075. continue;
  1076. if (safexcel_algs[j]->type == SAFEXCEL_ALG_TYPE_SKCIPHER)
  1077. crypto_unregister_skcipher(&safexcel_algs[j]->alg.skcipher);
  1078. else if (safexcel_algs[j]->type == SAFEXCEL_ALG_TYPE_AEAD)
  1079. crypto_unregister_aead(&safexcel_algs[j]->alg.aead);
  1080. else
  1081. crypto_unregister_ahash(&safexcel_algs[j]->alg.ahash);
  1082. }
  1083. return ret;
  1084. }
  1085. static void safexcel_unregister_algorithms(struct safexcel_crypto_priv *priv)
  1086. {
  1087. int i;
  1088. for (i = 0; i < ARRAY_SIZE(safexcel_algs); i++) {
  1089. /* Do we have all required base algorithms available? */
  1090. if ((safexcel_algs[i]->algo_mask & priv->hwconfig.algo_flags) !=
  1091. safexcel_algs[i]->algo_mask)
  1092. /* No, so don't unregister this ciphersuite */
  1093. continue;
  1094. if (safexcel_algs[i]->type == SAFEXCEL_ALG_TYPE_SKCIPHER)
  1095. crypto_unregister_skcipher(&safexcel_algs[i]->alg.skcipher);
  1096. else if (safexcel_algs[i]->type == SAFEXCEL_ALG_TYPE_AEAD)
  1097. crypto_unregister_aead(&safexcel_algs[i]->alg.aead);
  1098. else
  1099. crypto_unregister_ahash(&safexcel_algs[i]->alg.ahash);
  1100. }
  1101. }
  1102. static void safexcel_configure(struct safexcel_crypto_priv *priv)
  1103. {
  1104. u32 mask = BIT(priv->hwconfig.hwdataw) - 1;
  1105. priv->config.pes = priv->hwconfig.hwnumpes;
  1106. priv->config.rings = min_t(u32, priv->hwconfig.hwnumrings, max_rings);
  1107. /* Cannot currently support more rings than we have ring AICs! */
  1108. priv->config.rings = min_t(u32, priv->config.rings,
  1109. priv->hwconfig.hwnumraic);
  1110. priv->config.cd_size = EIP197_CD64_FETCH_SIZE;
  1111. priv->config.cd_offset = (priv->config.cd_size + mask) & ~mask;
  1112. priv->config.cdsh_offset = (EIP197_MAX_TOKENS + mask) & ~mask;
  1113. /* res token is behind the descr, but ofs must be rounded to buswdth */
  1114. priv->config.res_offset = (EIP197_RD64_FETCH_SIZE + mask) & ~mask;
  1115. /* now the size of the descr is this 1st part plus the result struct */
  1116. priv->config.rd_size = priv->config.res_offset +
  1117. EIP197_RD64_RESULT_SIZE;
  1118. priv->config.rd_offset = (priv->config.rd_size + mask) & ~mask;
  1119. /* convert dwords to bytes */
  1120. priv->config.cd_offset *= sizeof(u32);
  1121. priv->config.cdsh_offset *= sizeof(u32);
  1122. priv->config.rd_offset *= sizeof(u32);
  1123. priv->config.res_offset *= sizeof(u32);
  1124. }
  1125. static void safexcel_init_register_offsets(struct safexcel_crypto_priv *priv)
  1126. {
  1127. struct safexcel_register_offsets *offsets = &priv->offsets;
  1128. if (priv->flags & SAFEXCEL_HW_EIP197) {
  1129. offsets->hia_aic = EIP197_HIA_AIC_BASE;
  1130. offsets->hia_aic_g = EIP197_HIA_AIC_G_BASE;
  1131. offsets->hia_aic_r = EIP197_HIA_AIC_R_BASE;
  1132. offsets->hia_aic_xdr = EIP197_HIA_AIC_xDR_BASE;
  1133. offsets->hia_dfe = EIP197_HIA_DFE_BASE;
  1134. offsets->hia_dfe_thr = EIP197_HIA_DFE_THR_BASE;
  1135. offsets->hia_dse = EIP197_HIA_DSE_BASE;
  1136. offsets->hia_dse_thr = EIP197_HIA_DSE_THR_BASE;
  1137. offsets->hia_gen_cfg = EIP197_HIA_GEN_CFG_BASE;
  1138. offsets->pe = EIP197_PE_BASE;
  1139. offsets->global = EIP197_GLOBAL_BASE;
  1140. } else {
  1141. offsets->hia_aic = EIP97_HIA_AIC_BASE;
  1142. offsets->hia_aic_g = EIP97_HIA_AIC_G_BASE;
  1143. offsets->hia_aic_r = EIP97_HIA_AIC_R_BASE;
  1144. offsets->hia_aic_xdr = EIP97_HIA_AIC_xDR_BASE;
  1145. offsets->hia_dfe = EIP97_HIA_DFE_BASE;
  1146. offsets->hia_dfe_thr = EIP97_HIA_DFE_THR_BASE;
  1147. offsets->hia_dse = EIP97_HIA_DSE_BASE;
  1148. offsets->hia_dse_thr = EIP97_HIA_DSE_THR_BASE;
  1149. offsets->hia_gen_cfg = EIP97_HIA_GEN_CFG_BASE;
  1150. offsets->pe = EIP97_PE_BASE;
  1151. offsets->global = EIP97_GLOBAL_BASE;
  1152. }
  1153. }
  1154. /*
  1155. * Generic part of probe routine, shared by platform and PCI driver
  1156. *
  1157. * Assumes IO resources have been mapped, private data mem has been allocated,
  1158. * clocks have been enabled, device pointer has been assigned etc.
  1159. *
  1160. */
  1161. static int safexcel_probe_generic(void *pdev,
  1162. struct safexcel_crypto_priv *priv,
  1163. int is_pci_dev)
  1164. {
  1165. struct device *dev = priv->dev;
  1166. u32 peid, version, mask, val, hiaopt, hwopt, peopt;
  1167. int i, ret, hwctg;
  1168. priv->context_pool = dmam_pool_create("safexcel-context", dev,
  1169. sizeof(struct safexcel_context_record),
  1170. 1, 0);
  1171. if (!priv->context_pool)
  1172. return -ENOMEM;
  1173. /*
  1174. * First try the EIP97 HIA version regs
  1175. * For the EIP197, this is guaranteed to NOT return any of the test
  1176. * values
  1177. */
  1178. version = readl(priv->base + EIP97_HIA_AIC_BASE + EIP197_HIA_VERSION);
  1179. mask = 0; /* do not swap */
  1180. if (EIP197_REG_LO16(version) == EIP197_HIA_VERSION_LE) {
  1181. priv->hwconfig.hiaver = EIP197_VERSION_MASK(version);
  1182. } else if (EIP197_REG_HI16(version) == EIP197_HIA_VERSION_BE) {
  1183. /* read back byte-swapped, so complement byte swap bits */
  1184. mask = EIP197_MST_CTRL_BYTE_SWAP_BITS;
  1185. priv->hwconfig.hiaver = EIP197_VERSION_SWAP(version);
  1186. } else {
  1187. /* So it wasn't an EIP97 ... maybe it's an EIP197? */
  1188. version = readl(priv->base + EIP197_HIA_AIC_BASE +
  1189. EIP197_HIA_VERSION);
  1190. if (EIP197_REG_LO16(version) == EIP197_HIA_VERSION_LE) {
  1191. priv->hwconfig.hiaver = EIP197_VERSION_MASK(version);
  1192. priv->flags |= SAFEXCEL_HW_EIP197;
  1193. } else if (EIP197_REG_HI16(version) ==
  1194. EIP197_HIA_VERSION_BE) {
  1195. /* read back byte-swapped, so complement swap bits */
  1196. mask = EIP197_MST_CTRL_BYTE_SWAP_BITS;
  1197. priv->hwconfig.hiaver = EIP197_VERSION_SWAP(version);
  1198. priv->flags |= SAFEXCEL_HW_EIP197;
  1199. } else {
  1200. return -ENODEV;
  1201. }
  1202. }
  1203. /* Now initialize the reg offsets based on the probing info so far */
  1204. safexcel_init_register_offsets(priv);
  1205. /*
  1206. * If the version was read byte-swapped, we need to flip the device
  1207. * swapping Keep in mind here, though, that what we write will also be
  1208. * byte-swapped ...
  1209. */
  1210. if (mask) {
  1211. val = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_MST_CTRL);
  1212. val = val ^ (mask >> 24); /* toggle byte swap bits */
  1213. writel(val, EIP197_HIA_AIC(priv) + EIP197_HIA_MST_CTRL);
  1214. }
  1215. /*
  1216. * We're not done probing yet! We may fall through to here if no HIA
  1217. * was found at all. So, with the endianness presumably correct now and
  1218. * the offsets setup, *really* probe for the EIP97/EIP197.
  1219. */
  1220. version = readl(EIP197_GLOBAL(priv) + EIP197_VERSION);
  1221. if (((priv->flags & SAFEXCEL_HW_EIP197) &&
  1222. (EIP197_REG_LO16(version) != EIP197_VERSION_LE) &&
  1223. (EIP197_REG_LO16(version) != EIP196_VERSION_LE)) ||
  1224. ((!(priv->flags & SAFEXCEL_HW_EIP197) &&
  1225. (EIP197_REG_LO16(version) != EIP97_VERSION_LE)))) {
  1226. /*
  1227. * We did not find the device that matched our initial probing
  1228. * (or our initial probing failed) Report appropriate error.
  1229. */
  1230. dev_err(priv->dev, "Probing for EIP97/EIP19x failed - no such device (read %08x)\n",
  1231. version);
  1232. return -ENODEV;
  1233. }
  1234. priv->hwconfig.hwver = EIP197_VERSION_MASK(version);
  1235. hwctg = version >> 28;
  1236. peid = version & 255;
  1237. /* Detect EIP206 processing pipe */
  1238. version = readl(EIP197_PE(priv) + + EIP197_PE_VERSION(0));
  1239. if (EIP197_REG_LO16(version) != EIP206_VERSION_LE) {
  1240. dev_err(priv->dev, "EIP%d: EIP206 not detected\n", peid);
  1241. return -ENODEV;
  1242. }
  1243. priv->hwconfig.ppver = EIP197_VERSION_MASK(version);
  1244. /* Detect EIP96 packet engine and version */
  1245. version = readl(EIP197_PE(priv) + EIP197_PE_EIP96_VERSION(0));
  1246. if (EIP197_REG_LO16(version) != EIP96_VERSION_LE) {
  1247. dev_err(dev, "EIP%d: EIP96 not detected.\n", peid);
  1248. return -ENODEV;
  1249. }
  1250. priv->hwconfig.pever = EIP197_VERSION_MASK(version);
  1251. hwopt = readl(EIP197_GLOBAL(priv) + EIP197_OPTIONS);
  1252. hiaopt = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_OPTIONS);
  1253. priv->hwconfig.icever = 0;
  1254. priv->hwconfig.ocever = 0;
  1255. priv->hwconfig.psever = 0;
  1256. if (priv->flags & SAFEXCEL_HW_EIP197) {
  1257. /* EIP197 */
  1258. peopt = readl(EIP197_PE(priv) + EIP197_PE_OPTIONS(0));
  1259. priv->hwconfig.hwdataw = (hiaopt >> EIP197_HWDATAW_OFFSET) &
  1260. EIP197_HWDATAW_MASK;
  1261. priv->hwconfig.hwcfsize = ((hiaopt >> EIP197_CFSIZE_OFFSET) &
  1262. EIP197_CFSIZE_MASK) +
  1263. EIP197_CFSIZE_ADJUST;
  1264. priv->hwconfig.hwrfsize = ((hiaopt >> EIP197_RFSIZE_OFFSET) &
  1265. EIP197_RFSIZE_MASK) +
  1266. EIP197_RFSIZE_ADJUST;
  1267. priv->hwconfig.hwnumpes = (hiaopt >> EIP197_N_PES_OFFSET) &
  1268. EIP197_N_PES_MASK;
  1269. priv->hwconfig.hwnumrings = (hiaopt >> EIP197_N_RINGS_OFFSET) &
  1270. EIP197_N_RINGS_MASK;
  1271. if (hiaopt & EIP197_HIA_OPT_HAS_PE_ARB)
  1272. priv->flags |= EIP197_PE_ARB;
  1273. if (EIP206_OPT_ICE_TYPE(peopt) == 1) {
  1274. priv->flags |= EIP197_ICE;
  1275. /* Detect ICE EIP207 class. engine and version */
  1276. version = readl(EIP197_PE(priv) +
  1277. EIP197_PE_ICE_VERSION(0));
  1278. if (EIP197_REG_LO16(version) != EIP207_VERSION_LE) {
  1279. dev_err(dev, "EIP%d: ICE EIP207 not detected.\n",
  1280. peid);
  1281. return -ENODEV;
  1282. }
  1283. priv->hwconfig.icever = EIP197_VERSION_MASK(version);
  1284. }
  1285. if (EIP206_OPT_OCE_TYPE(peopt) == 1) {
  1286. priv->flags |= EIP197_OCE;
  1287. /* Detect EIP96PP packet stream editor and version */
  1288. version = readl(EIP197_PE(priv) + EIP197_PE_PSE_VERSION(0));
  1289. if (EIP197_REG_LO16(version) != EIP96_VERSION_LE) {
  1290. dev_err(dev, "EIP%d: EIP96PP not detected.\n", peid);
  1291. return -ENODEV;
  1292. }
  1293. priv->hwconfig.psever = EIP197_VERSION_MASK(version);
  1294. /* Detect OCE EIP207 class. engine and version */
  1295. version = readl(EIP197_PE(priv) +
  1296. EIP197_PE_ICE_VERSION(0));
  1297. if (EIP197_REG_LO16(version) != EIP207_VERSION_LE) {
  1298. dev_err(dev, "EIP%d: OCE EIP207 not detected.\n",
  1299. peid);
  1300. return -ENODEV;
  1301. }
  1302. priv->hwconfig.ocever = EIP197_VERSION_MASK(version);
  1303. }
  1304. /* If not a full TRC, then assume simple TRC */
  1305. if (!(hwopt & EIP197_OPT_HAS_TRC))
  1306. priv->flags |= EIP197_SIMPLE_TRC;
  1307. /* EIP197 always has SOME form of TRC */
  1308. priv->flags |= EIP197_TRC_CACHE;
  1309. } else {
  1310. /* EIP97 */
  1311. priv->hwconfig.hwdataw = (hiaopt >> EIP197_HWDATAW_OFFSET) &
  1312. EIP97_HWDATAW_MASK;
  1313. priv->hwconfig.hwcfsize = (hiaopt >> EIP97_CFSIZE_OFFSET) &
  1314. EIP97_CFSIZE_MASK;
  1315. priv->hwconfig.hwrfsize = (hiaopt >> EIP97_RFSIZE_OFFSET) &
  1316. EIP97_RFSIZE_MASK;
  1317. priv->hwconfig.hwnumpes = 1; /* by definition */
  1318. priv->hwconfig.hwnumrings = (hiaopt >> EIP197_N_RINGS_OFFSET) &
  1319. EIP197_N_RINGS_MASK;
  1320. }
  1321. /* Scan for ring AIC's */
  1322. for (i = 0; i < EIP197_MAX_RING_AIC; i++) {
  1323. version = readl(EIP197_HIA_AIC_R(priv) +
  1324. EIP197_HIA_AIC_R_VERSION(i));
  1325. if (EIP197_REG_LO16(version) != EIP201_VERSION_LE)
  1326. break;
  1327. }
  1328. priv->hwconfig.hwnumraic = i;
  1329. /* Low-end EIP196 may not have any ring AIC's ... */
  1330. if (!priv->hwconfig.hwnumraic) {
  1331. dev_err(priv->dev, "No ring interrupt controller present!\n");
  1332. return -ENODEV;
  1333. }
  1334. /* Get supported algorithms from EIP96 transform engine */
  1335. priv->hwconfig.algo_flags = readl(EIP197_PE(priv) +
  1336. EIP197_PE_EIP96_OPTIONS(0));
  1337. /* Print single info line describing what we just detected */
  1338. dev_info(priv->dev, "EIP%d:%x(%d,%d,%d,%d)-HIA:%x(%d,%d,%d),PE:%x/%x(alg:%08x)/%x/%x/%x\n",
  1339. peid, priv->hwconfig.hwver, hwctg, priv->hwconfig.hwnumpes,
  1340. priv->hwconfig.hwnumrings, priv->hwconfig.hwnumraic,
  1341. priv->hwconfig.hiaver, priv->hwconfig.hwdataw,
  1342. priv->hwconfig.hwcfsize, priv->hwconfig.hwrfsize,
  1343. priv->hwconfig.ppver, priv->hwconfig.pever,
  1344. priv->hwconfig.algo_flags, priv->hwconfig.icever,
  1345. priv->hwconfig.ocever, priv->hwconfig.psever);
  1346. safexcel_configure(priv);
  1347. if (IS_ENABLED(CONFIG_PCI) && priv->data->version == EIP197_DEVBRD) {
  1348. /*
  1349. * Request MSI vectors for global + 1 per ring -
  1350. * or just 1 for older dev images
  1351. */
  1352. struct pci_dev *pci_pdev = pdev;
  1353. ret = pci_alloc_irq_vectors(pci_pdev,
  1354. priv->config.rings + 1,
  1355. priv->config.rings + 1,
  1356. PCI_IRQ_MSI | PCI_IRQ_MSIX);
  1357. if (ret < 0) {
  1358. dev_err(dev, "Failed to allocate PCI MSI interrupts\n");
  1359. return ret;
  1360. }
  1361. }
  1362. /* Register the ring IRQ handlers and configure the rings */
  1363. priv->ring = devm_kcalloc(dev, priv->config.rings,
  1364. sizeof(*priv->ring),
  1365. GFP_KERNEL);
  1366. if (!priv->ring)
  1367. return -ENOMEM;
  1368. for (i = 0; i < priv->config.rings; i++) {
  1369. char wq_name[9] = {0};
  1370. int irq;
  1371. struct safexcel_ring_irq_data *ring_irq;
  1372. ret = safexcel_init_ring_descriptors(priv,
  1373. &priv->ring[i].cdr,
  1374. &priv->ring[i].rdr);
  1375. if (ret) {
  1376. dev_err(dev, "Failed to initialize rings\n");
  1377. goto err_cleanup_rings;
  1378. }
  1379. priv->ring[i].rdr_req = devm_kcalloc(dev,
  1380. EIP197_DEFAULT_RING_SIZE,
  1381. sizeof(*priv->ring[i].rdr_req),
  1382. GFP_KERNEL);
  1383. if (!priv->ring[i].rdr_req) {
  1384. ret = -ENOMEM;
  1385. goto err_cleanup_rings;
  1386. }
  1387. ring_irq = devm_kzalloc(dev, sizeof(*ring_irq), GFP_KERNEL);
  1388. if (!ring_irq) {
  1389. ret = -ENOMEM;
  1390. goto err_cleanup_rings;
  1391. }
  1392. ring_irq->priv = priv;
  1393. ring_irq->ring = i;
  1394. irq = safexcel_request_ring_irq(pdev,
  1395. EIP197_IRQ_NUMBER(i, is_pci_dev),
  1396. is_pci_dev,
  1397. i,
  1398. safexcel_irq_ring,
  1399. safexcel_irq_ring_thread,
  1400. ring_irq);
  1401. if (irq < 0) {
  1402. dev_err(dev, "Failed to get IRQ ID for ring %d\n", i);
  1403. ret = irq;
  1404. goto err_cleanup_rings;
  1405. }
  1406. priv->ring[i].irq = irq;
  1407. priv->ring[i].work_data.priv = priv;
  1408. priv->ring[i].work_data.ring = i;
  1409. INIT_WORK(&priv->ring[i].work_data.work,
  1410. safexcel_dequeue_work);
  1411. snprintf(wq_name, 9, "wq_ring%d", i);
  1412. priv->ring[i].workqueue =
  1413. create_singlethread_workqueue(wq_name);
  1414. if (!priv->ring[i].workqueue) {
  1415. ret = -ENOMEM;
  1416. goto err_cleanup_rings;
  1417. }
  1418. priv->ring[i].requests = 0;
  1419. priv->ring[i].busy = false;
  1420. crypto_init_queue(&priv->ring[i].queue,
  1421. EIP197_DEFAULT_RING_SIZE);
  1422. spin_lock_init(&priv->ring[i].lock);
  1423. spin_lock_init(&priv->ring[i].queue_lock);
  1424. }
  1425. atomic_set(&priv->ring_used, 0);
  1426. ret = safexcel_hw_init(priv);
  1427. if (ret) {
  1428. dev_err(dev, "HW init failed (%d)\n", ret);
  1429. goto err_cleanup_rings;
  1430. }
  1431. ret = safexcel_register_algorithms(priv);
  1432. if (ret) {
  1433. dev_err(dev, "Failed to register algorithms (%d)\n", ret);
  1434. goto err_cleanup_rings;
  1435. }
  1436. return 0;
  1437. err_cleanup_rings:
  1438. for (i = 0; i < priv->config.rings; i++) {
  1439. if (priv->ring[i].irq)
  1440. irq_set_affinity_hint(priv->ring[i].irq, NULL);
  1441. if (priv->ring[i].workqueue)
  1442. destroy_workqueue(priv->ring[i].workqueue);
  1443. }
  1444. return ret;
  1445. }
  1446. static void safexcel_hw_reset_rings(struct safexcel_crypto_priv *priv)
  1447. {
  1448. int i;
  1449. for (i = 0; i < priv->config.rings; i++) {
  1450. /* clear any pending interrupt */
  1451. writel(GENMASK(5, 0), EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_STAT);
  1452. writel(GENMASK(7, 0), EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_STAT);
  1453. /* Reset the CDR base address */
  1454. writel(0, EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_LO);
  1455. writel(0, EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_HI);
  1456. /* Reset the RDR base address */
  1457. writel(0, EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_LO);
  1458. writel(0, EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_HI);
  1459. }
  1460. }
  1461. /* for Device Tree platform driver */
  1462. static int safexcel_probe(struct platform_device *pdev)
  1463. {
  1464. struct device *dev = &pdev->dev;
  1465. struct safexcel_crypto_priv *priv;
  1466. int ret;
  1467. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  1468. if (!priv)
  1469. return -ENOMEM;
  1470. priv->dev = dev;
  1471. priv->data = (struct safexcel_priv_data *)of_device_get_match_data(dev);
  1472. platform_set_drvdata(pdev, priv);
  1473. priv->base = devm_platform_ioremap_resource(pdev, 0);
  1474. if (IS_ERR(priv->base)) {
  1475. dev_err(dev, "failed to get resource\n");
  1476. return PTR_ERR(priv->base);
  1477. }
  1478. priv->clk = devm_clk_get(&pdev->dev, NULL);
  1479. ret = PTR_ERR_OR_ZERO(priv->clk);
  1480. /* The clock isn't mandatory */
  1481. if (ret != -ENOENT) {
  1482. if (ret)
  1483. return ret;
  1484. ret = clk_prepare_enable(priv->clk);
  1485. if (ret) {
  1486. dev_err(dev, "unable to enable clk (%d)\n", ret);
  1487. return ret;
  1488. }
  1489. }
  1490. priv->reg_clk = devm_clk_get(&pdev->dev, "reg");
  1491. ret = PTR_ERR_OR_ZERO(priv->reg_clk);
  1492. /* The clock isn't mandatory */
  1493. if (ret != -ENOENT) {
  1494. if (ret)
  1495. goto err_core_clk;
  1496. ret = clk_prepare_enable(priv->reg_clk);
  1497. if (ret) {
  1498. dev_err(dev, "unable to enable reg clk (%d)\n", ret);
  1499. goto err_core_clk;
  1500. }
  1501. }
  1502. ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
  1503. if (ret)
  1504. goto err_reg_clk;
  1505. /* Generic EIP97/EIP197 device probing */
  1506. ret = safexcel_probe_generic(pdev, priv, 0);
  1507. if (ret)
  1508. goto err_reg_clk;
  1509. return 0;
  1510. err_reg_clk:
  1511. clk_disable_unprepare(priv->reg_clk);
  1512. err_core_clk:
  1513. clk_disable_unprepare(priv->clk);
  1514. return ret;
  1515. }
  1516. static void safexcel_remove(struct platform_device *pdev)
  1517. {
  1518. struct safexcel_crypto_priv *priv = platform_get_drvdata(pdev);
  1519. int i;
  1520. safexcel_unregister_algorithms(priv);
  1521. safexcel_hw_reset_rings(priv);
  1522. clk_disable_unprepare(priv->reg_clk);
  1523. clk_disable_unprepare(priv->clk);
  1524. for (i = 0; i < priv->config.rings; i++) {
  1525. irq_set_affinity_hint(priv->ring[i].irq, NULL);
  1526. destroy_workqueue(priv->ring[i].workqueue);
  1527. }
  1528. }
  1529. static const struct safexcel_priv_data eip97ies_mrvl_data = {
  1530. .version = EIP97IES_MRVL,
  1531. };
  1532. static const struct safexcel_priv_data eip197b_mrvl_data = {
  1533. .version = EIP197B_MRVL,
  1534. };
  1535. static const struct safexcel_priv_data eip197d_mrvl_data = {
  1536. .version = EIP197D_MRVL,
  1537. };
  1538. static const struct safexcel_priv_data eip197_devbrd_data = {
  1539. .version = EIP197_DEVBRD,
  1540. };
  1541. static const struct safexcel_priv_data eip197c_mxl_data = {
  1542. .version = EIP197C_MXL,
  1543. .fw_little_endian = true,
  1544. };
  1545. static const struct of_device_id safexcel_of_match_table[] = {
  1546. {
  1547. .compatible = "inside-secure,safexcel-eip97ies",
  1548. .data = &eip97ies_mrvl_data,
  1549. },
  1550. {
  1551. .compatible = "inside-secure,safexcel-eip197b",
  1552. .data = &eip197b_mrvl_data,
  1553. },
  1554. {
  1555. .compatible = "inside-secure,safexcel-eip197d",
  1556. .data = &eip197d_mrvl_data,
  1557. },
  1558. {
  1559. .compatible = "inside-secure,safexcel-eip197c-mxl",
  1560. .data = &eip197c_mxl_data,
  1561. },
  1562. /* For backward compatibility and intended for generic use */
  1563. {
  1564. .compatible = "inside-secure,safexcel-eip97",
  1565. .data = &eip97ies_mrvl_data,
  1566. },
  1567. {
  1568. .compatible = "inside-secure,safexcel-eip197",
  1569. .data = &eip197b_mrvl_data,
  1570. },
  1571. {},
  1572. };
  1573. MODULE_DEVICE_TABLE(of, safexcel_of_match_table);
  1574. static struct platform_driver crypto_safexcel = {
  1575. .probe = safexcel_probe,
  1576. .remove = safexcel_remove,
  1577. .driver = {
  1578. .name = "crypto-safexcel",
  1579. .of_match_table = safexcel_of_match_table,
  1580. },
  1581. };
  1582. /* PCIE devices - i.e. Inside Secure development boards */
  1583. static int safexcel_pci_probe(struct pci_dev *pdev,
  1584. const struct pci_device_id *ent)
  1585. {
  1586. struct device *dev = &pdev->dev;
  1587. struct safexcel_crypto_priv *priv;
  1588. void __iomem *pciebase;
  1589. int rc;
  1590. u32 val;
  1591. dev_dbg(dev, "Probing PCIE device: vendor %04x, device %04x, subv %04x, subdev %04x, ctxt %lx\n",
  1592. ent->vendor, ent->device, ent->subvendor,
  1593. ent->subdevice, ent->driver_data);
  1594. priv = kzalloc_obj(*priv);
  1595. if (!priv)
  1596. return -ENOMEM;
  1597. priv->dev = dev;
  1598. priv->data = (struct safexcel_priv_data *)ent->driver_data;
  1599. pci_set_drvdata(pdev, priv);
  1600. /* enable the device */
  1601. rc = pcim_enable_device(pdev);
  1602. if (rc) {
  1603. dev_err(dev, "Failed to enable PCI device\n");
  1604. return rc;
  1605. }
  1606. /* take ownership of PCI BAR0 */
  1607. rc = pcim_iomap_regions(pdev, 1, "crypto_safexcel");
  1608. if (rc) {
  1609. dev_err(dev, "Failed to map IO region for BAR0\n");
  1610. return rc;
  1611. }
  1612. priv->base = pcim_iomap_table(pdev)[0];
  1613. if (priv->data->version == EIP197_DEVBRD) {
  1614. dev_dbg(dev, "Device identified as FPGA based development board - applying HW reset\n");
  1615. rc = pcim_iomap_regions(pdev, 4, "crypto_safexcel");
  1616. if (rc) {
  1617. dev_err(dev, "Failed to map IO region for BAR4\n");
  1618. return rc;
  1619. }
  1620. pciebase = pcim_iomap_table(pdev)[2];
  1621. val = readl(pciebase + EIP197_XLX_IRQ_BLOCK_ID_ADDR);
  1622. if ((val >> 16) == EIP197_XLX_IRQ_BLOCK_ID_VALUE) {
  1623. dev_dbg(dev, "Detected Xilinx PCIE IRQ block version %d, multiple MSI support enabled\n",
  1624. (val & 0xff));
  1625. /* Setup MSI identity map mapping */
  1626. writel(EIP197_XLX_USER_VECT_LUT0_IDENT,
  1627. pciebase + EIP197_XLX_USER_VECT_LUT0_ADDR);
  1628. writel(EIP197_XLX_USER_VECT_LUT1_IDENT,
  1629. pciebase + EIP197_XLX_USER_VECT_LUT1_ADDR);
  1630. writel(EIP197_XLX_USER_VECT_LUT2_IDENT,
  1631. pciebase + EIP197_XLX_USER_VECT_LUT2_ADDR);
  1632. writel(EIP197_XLX_USER_VECT_LUT3_IDENT,
  1633. pciebase + EIP197_XLX_USER_VECT_LUT3_ADDR);
  1634. /* Enable all device interrupts */
  1635. writel(GENMASK(31, 0),
  1636. pciebase + EIP197_XLX_USER_INT_ENB_MSK);
  1637. } else {
  1638. dev_err(dev, "Unrecognised IRQ block identifier %x\n",
  1639. val);
  1640. return -ENODEV;
  1641. }
  1642. /* HW reset FPGA dev board */
  1643. /* assert reset */
  1644. writel(1, priv->base + EIP197_XLX_GPIO_BASE);
  1645. wmb(); /* maintain strict ordering for accesses here */
  1646. /* deassert reset */
  1647. writel(0, priv->base + EIP197_XLX_GPIO_BASE);
  1648. wmb(); /* maintain strict ordering for accesses here */
  1649. }
  1650. /* enable bus mastering */
  1651. pci_set_master(pdev);
  1652. /* Generic EIP97/EIP197 device probing */
  1653. rc = safexcel_probe_generic(pdev, priv, 1);
  1654. return rc;
  1655. }
  1656. static void safexcel_pci_remove(struct pci_dev *pdev)
  1657. {
  1658. struct safexcel_crypto_priv *priv = pci_get_drvdata(pdev);
  1659. int i;
  1660. safexcel_unregister_algorithms(priv);
  1661. for (i = 0; i < priv->config.rings; i++)
  1662. destroy_workqueue(priv->ring[i].workqueue);
  1663. safexcel_hw_reset_rings(priv);
  1664. }
  1665. static const struct pci_device_id safexcel_pci_ids[] = {
  1666. {
  1667. PCI_DEVICE_SUB(PCI_VENDOR_ID_XILINX, 0x9038,
  1668. 0x16ae, 0xc522),
  1669. .driver_data = (kernel_ulong_t)&eip197_devbrd_data,
  1670. },
  1671. {},
  1672. };
  1673. MODULE_DEVICE_TABLE(pci, safexcel_pci_ids);
  1674. static struct pci_driver safexcel_pci_driver = {
  1675. .name = "crypto-safexcel",
  1676. .id_table = safexcel_pci_ids,
  1677. .probe = safexcel_pci_probe,
  1678. .remove = safexcel_pci_remove,
  1679. };
  1680. static int __init safexcel_init(void)
  1681. {
  1682. int ret;
  1683. /* Register PCI driver */
  1684. ret = pci_register_driver(&safexcel_pci_driver);
  1685. /* Register platform driver */
  1686. if (IS_ENABLED(CONFIG_OF) && !ret) {
  1687. ret = platform_driver_register(&crypto_safexcel);
  1688. if (ret)
  1689. pci_unregister_driver(&safexcel_pci_driver);
  1690. }
  1691. return ret;
  1692. }
  1693. static void __exit safexcel_exit(void)
  1694. {
  1695. /* Unregister platform driver */
  1696. if (IS_ENABLED(CONFIG_OF))
  1697. platform_driver_unregister(&crypto_safexcel);
  1698. /* Unregister PCI driver if successfully registered before */
  1699. pci_unregister_driver(&safexcel_pci_driver);
  1700. }
  1701. module_init(safexcel_init);
  1702. module_exit(safexcel_exit);
  1703. MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
  1704. MODULE_AUTHOR("Ofer Heifetz <oferh@marvell.com>");
  1705. MODULE_AUTHOR("Igal Liberman <igall@marvell.com>");
  1706. MODULE_DESCRIPTION("Support for SafeXcel cryptographic engines: EIP97 & EIP197");
  1707. MODULE_LICENSE("GPL v2");
  1708. MODULE_IMPORT_NS("CRYPTO_INTERNAL");
  1709. MODULE_FIRMWARE("ifpp.bin");
  1710. MODULE_FIRMWARE("ipue.bin");
  1711. MODULE_FIRMWARE("inside-secure/eip197b/ifpp.bin");
  1712. MODULE_FIRMWARE("inside-secure/eip197b/ipue.bin");
  1713. MODULE_FIRMWARE("inside-secure/eip197d/ifpp.bin");
  1714. MODULE_FIRMWARE("inside-secure/eip197d/ipue.bin");
  1715. MODULE_FIRMWARE("inside-secure/eip197_minifw/ifpp.bin");
  1716. MODULE_FIRMWARE("inside-secure/eip197_minifw/ipue.bin");