nx-842-powernv.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * Driver for IBM PowerNV 842 compression accelerator
  3. *
  4. * Copyright (C) 2015 Dan Streetman, IBM Corp
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include "nx-842.h"
  18. #include <linux/timer.h>
  19. #include <asm/prom.h>
  20. #include <asm/icswx.h>
  21. MODULE_LICENSE("GPL");
  22. MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
  23. MODULE_DESCRIPTION("842 H/W Compression driver for IBM PowerNV processors");
  24. MODULE_ALIAS_CRYPTO("842");
  25. MODULE_ALIAS_CRYPTO("842-nx");
  26. #define WORKMEM_ALIGN (CRB_ALIGN)
  27. #define CSB_WAIT_MAX (5000) /* ms */
  28. struct nx842_workmem {
  29. /* Below fields must be properly aligned */
  30. struct coprocessor_request_block crb; /* CRB_ALIGN align */
  31. struct data_descriptor_entry ddl_in[DDL_LEN_MAX]; /* DDE_ALIGN align */
  32. struct data_descriptor_entry ddl_out[DDL_LEN_MAX]; /* DDE_ALIGN align */
  33. /* Above fields must be properly aligned */
  34. ktime_t start;
  35. char padding[WORKMEM_ALIGN]; /* unused, to allow alignment */
  36. } __packed __aligned(WORKMEM_ALIGN);
  37. struct nx842_coproc {
  38. unsigned int chip_id;
  39. unsigned int ct;
  40. unsigned int ci;
  41. struct list_head list;
  42. };
  43. /* no cpu hotplug on powernv, so this list never changes after init */
  44. static LIST_HEAD(nx842_coprocs);
  45. static unsigned int nx842_ct;
  46. /**
  47. * setup_indirect_dde - Setup an indirect DDE
  48. *
  49. * The DDE is setup with the the DDE count, byte count, and address of
  50. * first direct DDE in the list.
  51. */
  52. static void setup_indirect_dde(struct data_descriptor_entry *dde,
  53. struct data_descriptor_entry *ddl,
  54. unsigned int dde_count, unsigned int byte_count)
  55. {
  56. dde->flags = 0;
  57. dde->count = dde_count;
  58. dde->index = 0;
  59. dde->length = cpu_to_be32(byte_count);
  60. dde->address = cpu_to_be64(nx842_get_pa(ddl));
  61. }
  62. /**
  63. * setup_direct_dde - Setup single DDE from buffer
  64. *
  65. * The DDE is setup with the buffer and length. The buffer must be properly
  66. * aligned. The used length is returned.
  67. * Returns:
  68. * N Successfully set up DDE with N bytes
  69. */
  70. static unsigned int setup_direct_dde(struct data_descriptor_entry *dde,
  71. unsigned long pa, unsigned int len)
  72. {
  73. unsigned int l = min_t(unsigned int, len, LEN_ON_PAGE(pa));
  74. dde->flags = 0;
  75. dde->count = 0;
  76. dde->index = 0;
  77. dde->length = cpu_to_be32(l);
  78. dde->address = cpu_to_be64(pa);
  79. return l;
  80. }
  81. /**
  82. * setup_ddl - Setup DDL from buffer
  83. *
  84. * Returns:
  85. * 0 Successfully set up DDL
  86. */
  87. static int setup_ddl(struct data_descriptor_entry *dde,
  88. struct data_descriptor_entry *ddl,
  89. unsigned char *buf, unsigned int len,
  90. bool in)
  91. {
  92. unsigned long pa = nx842_get_pa(buf);
  93. int i, ret, total_len = len;
  94. if (!IS_ALIGNED(pa, DDE_BUFFER_ALIGN)) {
  95. pr_debug("%s buffer pa 0x%lx not 0x%x-byte aligned\n",
  96. in ? "input" : "output", pa, DDE_BUFFER_ALIGN);
  97. return -EINVAL;
  98. }
  99. /* only need to check last mult; since buffer must be
  100. * DDE_BUFFER_ALIGN aligned, and that is a multiple of
  101. * DDE_BUFFER_SIZE_MULT, and pre-last page DDE buffers
  102. * are guaranteed a multiple of DDE_BUFFER_SIZE_MULT.
  103. */
  104. if (len % DDE_BUFFER_LAST_MULT) {
  105. pr_debug("%s buffer len 0x%x not a multiple of 0x%x\n",
  106. in ? "input" : "output", len, DDE_BUFFER_LAST_MULT);
  107. if (in)
  108. return -EINVAL;
  109. len = round_down(len, DDE_BUFFER_LAST_MULT);
  110. }
  111. /* use a single direct DDE */
  112. if (len <= LEN_ON_PAGE(pa)) {
  113. ret = setup_direct_dde(dde, pa, len);
  114. WARN_ON(ret < len);
  115. return 0;
  116. }
  117. /* use the DDL */
  118. for (i = 0; i < DDL_LEN_MAX && len > 0; i++) {
  119. ret = setup_direct_dde(&ddl[i], pa, len);
  120. buf += ret;
  121. len -= ret;
  122. pa = nx842_get_pa(buf);
  123. }
  124. if (len > 0) {
  125. pr_debug("0x%x total %s bytes 0x%x too many for DDL.\n",
  126. total_len, in ? "input" : "output", len);
  127. if (in)
  128. return -EMSGSIZE;
  129. total_len -= len;
  130. }
  131. setup_indirect_dde(dde, ddl, i, total_len);
  132. return 0;
  133. }
  134. #define CSB_ERR(csb, msg, ...) \
  135. pr_err("ERROR: " msg " : %02x %02x %02x %02x %08x\n", \
  136. ##__VA_ARGS__, (csb)->flags, \
  137. (csb)->cs, (csb)->cc, (csb)->ce, \
  138. be32_to_cpu((csb)->count))
  139. #define CSB_ERR_ADDR(csb, msg, ...) \
  140. CSB_ERR(csb, msg " at %lx", ##__VA_ARGS__, \
  141. (unsigned long)be64_to_cpu((csb)->address))
  142. /**
  143. * wait_for_csb
  144. */
  145. static int wait_for_csb(struct nx842_workmem *wmem,
  146. struct coprocessor_status_block *csb)
  147. {
  148. ktime_t start = wmem->start, now = ktime_get();
  149. ktime_t timeout = ktime_add_ms(start, CSB_WAIT_MAX);
  150. while (!(ACCESS_ONCE(csb->flags) & CSB_V)) {
  151. cpu_relax();
  152. now = ktime_get();
  153. if (ktime_after(now, timeout))
  154. break;
  155. }
  156. /* hw has updated csb and output buffer */
  157. barrier();
  158. /* check CSB flags */
  159. if (!(csb->flags & CSB_V)) {
  160. CSB_ERR(csb, "CSB still not valid after %ld us, giving up",
  161. (long)ktime_us_delta(now, start));
  162. return -ETIMEDOUT;
  163. }
  164. if (csb->flags & CSB_F) {
  165. CSB_ERR(csb, "Invalid CSB format");
  166. return -EPROTO;
  167. }
  168. if (csb->flags & CSB_CH) {
  169. CSB_ERR(csb, "Invalid CSB chaining state");
  170. return -EPROTO;
  171. }
  172. /* verify CSB completion sequence is 0 */
  173. if (csb->cs) {
  174. CSB_ERR(csb, "Invalid CSB completion sequence");
  175. return -EPROTO;
  176. }
  177. /* check CSB Completion Code */
  178. switch (csb->cc) {
  179. /* no error */
  180. case CSB_CC_SUCCESS:
  181. break;
  182. case CSB_CC_TPBC_GT_SPBC:
  183. /* not an error, but the compressed data is
  184. * larger than the uncompressed data :(
  185. */
  186. break;
  187. /* input data errors */
  188. case CSB_CC_OPERAND_OVERLAP:
  189. /* input and output buffers overlap */
  190. CSB_ERR(csb, "Operand Overlap error");
  191. return -EINVAL;
  192. case CSB_CC_INVALID_OPERAND:
  193. CSB_ERR(csb, "Invalid operand");
  194. return -EINVAL;
  195. case CSB_CC_NOSPC:
  196. /* output buffer too small */
  197. return -ENOSPC;
  198. case CSB_CC_ABORT:
  199. CSB_ERR(csb, "Function aborted");
  200. return -EINTR;
  201. case CSB_CC_CRC_MISMATCH:
  202. CSB_ERR(csb, "CRC mismatch");
  203. return -EINVAL;
  204. case CSB_CC_TEMPL_INVALID:
  205. CSB_ERR(csb, "Compressed data template invalid");
  206. return -EINVAL;
  207. case CSB_CC_TEMPL_OVERFLOW:
  208. CSB_ERR(csb, "Compressed data template shows data past end");
  209. return -EINVAL;
  210. /* these should not happen */
  211. case CSB_CC_INVALID_ALIGN:
  212. /* setup_ddl should have detected this */
  213. CSB_ERR_ADDR(csb, "Invalid alignment");
  214. return -EINVAL;
  215. case CSB_CC_DATA_LENGTH:
  216. /* setup_ddl should have detected this */
  217. CSB_ERR(csb, "Invalid data length");
  218. return -EINVAL;
  219. case CSB_CC_WR_TRANSLATION:
  220. case CSB_CC_TRANSLATION:
  221. case CSB_CC_TRANSLATION_DUP1:
  222. case CSB_CC_TRANSLATION_DUP2:
  223. case CSB_CC_TRANSLATION_DUP3:
  224. case CSB_CC_TRANSLATION_DUP4:
  225. case CSB_CC_TRANSLATION_DUP5:
  226. case CSB_CC_TRANSLATION_DUP6:
  227. /* should not happen, we use physical addrs */
  228. CSB_ERR_ADDR(csb, "Translation error");
  229. return -EPROTO;
  230. case CSB_CC_WR_PROTECTION:
  231. case CSB_CC_PROTECTION:
  232. case CSB_CC_PROTECTION_DUP1:
  233. case CSB_CC_PROTECTION_DUP2:
  234. case CSB_CC_PROTECTION_DUP3:
  235. case CSB_CC_PROTECTION_DUP4:
  236. case CSB_CC_PROTECTION_DUP5:
  237. case CSB_CC_PROTECTION_DUP6:
  238. /* should not happen, we use physical addrs */
  239. CSB_ERR_ADDR(csb, "Protection error");
  240. return -EPROTO;
  241. case CSB_CC_PRIVILEGE:
  242. /* shouldn't happen, we're in HYP mode */
  243. CSB_ERR(csb, "Insufficient Privilege error");
  244. return -EPROTO;
  245. case CSB_CC_EXCESSIVE_DDE:
  246. /* shouldn't happen, setup_ddl doesn't use many dde's */
  247. CSB_ERR(csb, "Too many DDEs in DDL");
  248. return -EINVAL;
  249. case CSB_CC_TRANSPORT:
  250. /* shouldn't happen, we setup CRB correctly */
  251. CSB_ERR(csb, "Invalid CRB");
  252. return -EINVAL;
  253. case CSB_CC_SEGMENTED_DDL:
  254. /* shouldn't happen, setup_ddl creates DDL right */
  255. CSB_ERR(csb, "Segmented DDL error");
  256. return -EINVAL;
  257. case CSB_CC_DDE_OVERFLOW:
  258. /* shouldn't happen, setup_ddl creates DDL right */
  259. CSB_ERR(csb, "DDE overflow error");
  260. return -EINVAL;
  261. case CSB_CC_SESSION:
  262. /* should not happen with ICSWX */
  263. CSB_ERR(csb, "Session violation error");
  264. return -EPROTO;
  265. case CSB_CC_CHAIN:
  266. /* should not happen, we don't use chained CRBs */
  267. CSB_ERR(csb, "Chained CRB error");
  268. return -EPROTO;
  269. case CSB_CC_SEQUENCE:
  270. /* should not happen, we don't use chained CRBs */
  271. CSB_ERR(csb, "CRB seqeunce number error");
  272. return -EPROTO;
  273. case CSB_CC_UNKNOWN_CODE:
  274. CSB_ERR(csb, "Unknown subfunction code");
  275. return -EPROTO;
  276. /* hardware errors */
  277. case CSB_CC_RD_EXTERNAL:
  278. case CSB_CC_RD_EXTERNAL_DUP1:
  279. case CSB_CC_RD_EXTERNAL_DUP2:
  280. case CSB_CC_RD_EXTERNAL_DUP3:
  281. CSB_ERR_ADDR(csb, "Read error outside coprocessor");
  282. return -EPROTO;
  283. case CSB_CC_WR_EXTERNAL:
  284. CSB_ERR_ADDR(csb, "Write error outside coprocessor");
  285. return -EPROTO;
  286. case CSB_CC_INTERNAL:
  287. CSB_ERR(csb, "Internal error in coprocessor");
  288. return -EPROTO;
  289. case CSB_CC_PROVISION:
  290. CSB_ERR(csb, "Storage provision error");
  291. return -EPROTO;
  292. case CSB_CC_HW:
  293. CSB_ERR(csb, "Correctable hardware error");
  294. return -EPROTO;
  295. default:
  296. CSB_ERR(csb, "Invalid CC %d", csb->cc);
  297. return -EPROTO;
  298. }
  299. /* check Completion Extension state */
  300. if (csb->ce & CSB_CE_TERMINATION) {
  301. CSB_ERR(csb, "CSB request was terminated");
  302. return -EPROTO;
  303. }
  304. if (csb->ce & CSB_CE_INCOMPLETE) {
  305. CSB_ERR(csb, "CSB request not complete");
  306. return -EPROTO;
  307. }
  308. if (!(csb->ce & CSB_CE_TPBC)) {
  309. CSB_ERR(csb, "TPBC not provided, unknown target length");
  310. return -EPROTO;
  311. }
  312. /* successful completion */
  313. pr_debug_ratelimited("Processed %u bytes in %lu us\n",
  314. be32_to_cpu(csb->count),
  315. (unsigned long)ktime_us_delta(now, start));
  316. return 0;
  317. }
  318. /**
  319. * nx842_powernv_function - compress/decompress data using the 842 algorithm
  320. *
  321. * (De)compression provided by the NX842 coprocessor on IBM PowerNV systems.
  322. * This compresses or decompresses the provided input buffer into the provided
  323. * output buffer.
  324. *
  325. * Upon return from this function @outlen contains the length of the
  326. * output data. If there is an error then @outlen will be 0 and an
  327. * error will be specified by the return code from this function.
  328. *
  329. * The @workmem buffer should only be used by one function call at a time.
  330. *
  331. * @in: input buffer pointer
  332. * @inlen: input buffer size
  333. * @out: output buffer pointer
  334. * @outlenp: output buffer size pointer
  335. * @workmem: working memory buffer pointer, size determined by
  336. * nx842_powernv_driver.workmem_size
  337. * @fc: function code, see CCW Function Codes in nx-842.h
  338. *
  339. * Returns:
  340. * 0 Success, output of length @outlenp stored in the buffer at @out
  341. * -ENODEV Hardware unavailable
  342. * -ENOSPC Output buffer is to small
  343. * -EMSGSIZE Input buffer too large
  344. * -EINVAL buffer constraints do not fix nx842_constraints
  345. * -EPROTO hardware error during operation
  346. * -ETIMEDOUT hardware did not complete operation in reasonable time
  347. * -EINTR operation was aborted
  348. */
  349. static int nx842_powernv_function(const unsigned char *in, unsigned int inlen,
  350. unsigned char *out, unsigned int *outlenp,
  351. void *workmem, int fc)
  352. {
  353. struct coprocessor_request_block *crb;
  354. struct coprocessor_status_block *csb;
  355. struct nx842_workmem *wmem;
  356. int ret;
  357. u64 csb_addr;
  358. u32 ccw;
  359. unsigned int outlen = *outlenp;
  360. wmem = PTR_ALIGN(workmem, WORKMEM_ALIGN);
  361. *outlenp = 0;
  362. /* shoudn't happen, we don't load without a coproc */
  363. if (!nx842_ct) {
  364. pr_err_ratelimited("coprocessor CT is 0");
  365. return -ENODEV;
  366. }
  367. crb = &wmem->crb;
  368. csb = &crb->csb;
  369. /* Clear any previous values */
  370. memset(crb, 0, sizeof(*crb));
  371. /* set up DDLs */
  372. ret = setup_ddl(&crb->source, wmem->ddl_in,
  373. (unsigned char *)in, inlen, true);
  374. if (ret)
  375. return ret;
  376. ret = setup_ddl(&crb->target, wmem->ddl_out,
  377. out, outlen, false);
  378. if (ret)
  379. return ret;
  380. /* set up CCW */
  381. ccw = 0;
  382. ccw = SET_FIELD(ccw, CCW_CT, nx842_ct);
  383. ccw = SET_FIELD(ccw, CCW_CI_842, 0); /* use 0 for hw auto-selection */
  384. ccw = SET_FIELD(ccw, CCW_FC_842, fc);
  385. /* set up CRB's CSB addr */
  386. csb_addr = nx842_get_pa(csb) & CRB_CSB_ADDRESS;
  387. csb_addr |= CRB_CSB_AT; /* Addrs are phys */
  388. crb->csb_addr = cpu_to_be64(csb_addr);
  389. wmem->start = ktime_get();
  390. /* do ICSWX */
  391. ret = icswx(cpu_to_be32(ccw), crb);
  392. pr_debug_ratelimited("icswx CR %x ccw %x crb->ccw %x\n", ret,
  393. (unsigned int)ccw,
  394. (unsigned int)be32_to_cpu(crb->ccw));
  395. switch (ret) {
  396. case ICSWX_INITIATED:
  397. ret = wait_for_csb(wmem, csb);
  398. break;
  399. case ICSWX_BUSY:
  400. pr_debug_ratelimited("842 Coprocessor busy\n");
  401. ret = -EBUSY;
  402. break;
  403. case ICSWX_REJECTED:
  404. pr_err_ratelimited("ICSWX rejected\n");
  405. ret = -EPROTO;
  406. break;
  407. default:
  408. pr_err_ratelimited("Invalid ICSWX return code %x\n", ret);
  409. ret = -EPROTO;
  410. break;
  411. }
  412. if (!ret)
  413. *outlenp = be32_to_cpu(csb->count);
  414. return ret;
  415. }
  416. /**
  417. * nx842_powernv_compress - Compress data using the 842 algorithm
  418. *
  419. * Compression provided by the NX842 coprocessor on IBM PowerNV systems.
  420. * The input buffer is compressed and the result is stored in the
  421. * provided output buffer.
  422. *
  423. * Upon return from this function @outlen contains the length of the
  424. * compressed data. If there is an error then @outlen will be 0 and an
  425. * error will be specified by the return code from this function.
  426. *
  427. * @in: input buffer pointer
  428. * @inlen: input buffer size
  429. * @out: output buffer pointer
  430. * @outlenp: output buffer size pointer
  431. * @workmem: working memory buffer pointer, size determined by
  432. * nx842_powernv_driver.workmem_size
  433. *
  434. * Returns: see @nx842_powernv_function()
  435. */
  436. static int nx842_powernv_compress(const unsigned char *in, unsigned int inlen,
  437. unsigned char *out, unsigned int *outlenp,
  438. void *wmem)
  439. {
  440. return nx842_powernv_function(in, inlen, out, outlenp,
  441. wmem, CCW_FC_842_COMP_NOCRC);
  442. }
  443. /**
  444. * nx842_powernv_decompress - Decompress data using the 842 algorithm
  445. *
  446. * Decompression provided by the NX842 coprocessor on IBM PowerNV systems.
  447. * The input buffer is decompressed and the result is stored in the
  448. * provided output buffer.
  449. *
  450. * Upon return from this function @outlen contains the length of the
  451. * decompressed data. If there is an error then @outlen will be 0 and an
  452. * error will be specified by the return code from this function.
  453. *
  454. * @in: input buffer pointer
  455. * @inlen: input buffer size
  456. * @out: output buffer pointer
  457. * @outlenp: output buffer size pointer
  458. * @workmem: working memory buffer pointer, size determined by
  459. * nx842_powernv_driver.workmem_size
  460. *
  461. * Returns: see @nx842_powernv_function()
  462. */
  463. static int nx842_powernv_decompress(const unsigned char *in, unsigned int inlen,
  464. unsigned char *out, unsigned int *outlenp,
  465. void *wmem)
  466. {
  467. return nx842_powernv_function(in, inlen, out, outlenp,
  468. wmem, CCW_FC_842_DECOMP_NOCRC);
  469. }
  470. static int __init nx842_powernv_probe(struct device_node *dn)
  471. {
  472. struct nx842_coproc *coproc;
  473. struct property *ct_prop, *ci_prop;
  474. unsigned int ct, ci;
  475. int chip_id;
  476. chip_id = of_get_ibm_chip_id(dn);
  477. if (chip_id < 0) {
  478. pr_err("ibm,chip-id missing\n");
  479. return -EINVAL;
  480. }
  481. ct_prop = of_find_property(dn, "ibm,842-coprocessor-type", NULL);
  482. if (!ct_prop) {
  483. pr_err("ibm,842-coprocessor-type missing\n");
  484. return -EINVAL;
  485. }
  486. ct = be32_to_cpu(*(unsigned int *)ct_prop->value);
  487. ci_prop = of_find_property(dn, "ibm,842-coprocessor-instance", NULL);
  488. if (!ci_prop) {
  489. pr_err("ibm,842-coprocessor-instance missing\n");
  490. return -EINVAL;
  491. }
  492. ci = be32_to_cpu(*(unsigned int *)ci_prop->value);
  493. coproc = kmalloc(sizeof(*coproc), GFP_KERNEL);
  494. if (!coproc)
  495. return -ENOMEM;
  496. coproc->chip_id = chip_id;
  497. coproc->ct = ct;
  498. coproc->ci = ci;
  499. INIT_LIST_HEAD(&coproc->list);
  500. list_add(&coproc->list, &nx842_coprocs);
  501. pr_info("coprocessor found on chip %d, CT %d CI %d\n", chip_id, ct, ci);
  502. if (!nx842_ct)
  503. nx842_ct = ct;
  504. else if (nx842_ct != ct)
  505. pr_err("NX842 chip %d, CT %d != first found CT %d\n",
  506. chip_id, ct, nx842_ct);
  507. return 0;
  508. }
  509. static struct nx842_constraints nx842_powernv_constraints = {
  510. .alignment = DDE_BUFFER_ALIGN,
  511. .multiple = DDE_BUFFER_LAST_MULT,
  512. .minimum = DDE_BUFFER_LAST_MULT,
  513. .maximum = (DDL_LEN_MAX - 1) * PAGE_SIZE,
  514. };
  515. static struct nx842_driver nx842_powernv_driver = {
  516. .name = KBUILD_MODNAME,
  517. .owner = THIS_MODULE,
  518. .workmem_size = sizeof(struct nx842_workmem),
  519. .constraints = &nx842_powernv_constraints,
  520. .compress = nx842_powernv_compress,
  521. .decompress = nx842_powernv_decompress,
  522. };
  523. static int nx842_powernv_crypto_init(struct crypto_tfm *tfm)
  524. {
  525. return nx842_crypto_init(tfm, &nx842_powernv_driver);
  526. }
  527. static struct crypto_alg nx842_powernv_alg = {
  528. .cra_name = "842",
  529. .cra_driver_name = "842-nx",
  530. .cra_priority = 300,
  531. .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
  532. .cra_ctxsize = sizeof(struct nx842_crypto_ctx),
  533. .cra_module = THIS_MODULE,
  534. .cra_init = nx842_powernv_crypto_init,
  535. .cra_exit = nx842_crypto_exit,
  536. .cra_u = { .compress = {
  537. .coa_compress = nx842_crypto_compress,
  538. .coa_decompress = nx842_crypto_decompress } }
  539. };
  540. static __init int nx842_powernv_init(void)
  541. {
  542. struct device_node *dn;
  543. int ret;
  544. /* verify workmem size/align restrictions */
  545. BUILD_BUG_ON(WORKMEM_ALIGN % CRB_ALIGN);
  546. BUILD_BUG_ON(CRB_ALIGN % DDE_ALIGN);
  547. BUILD_BUG_ON(CRB_SIZE % DDE_ALIGN);
  548. /* verify buffer size/align restrictions */
  549. BUILD_BUG_ON(PAGE_SIZE % DDE_BUFFER_ALIGN);
  550. BUILD_BUG_ON(DDE_BUFFER_ALIGN % DDE_BUFFER_SIZE_MULT);
  551. BUILD_BUG_ON(DDE_BUFFER_SIZE_MULT % DDE_BUFFER_LAST_MULT);
  552. for_each_compatible_node(dn, NULL, "ibm,power-nx")
  553. nx842_powernv_probe(dn);
  554. if (!nx842_ct)
  555. return -ENODEV;
  556. ret = crypto_register_alg(&nx842_powernv_alg);
  557. if (ret) {
  558. struct nx842_coproc *coproc, *n;
  559. list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) {
  560. list_del(&coproc->list);
  561. kfree(coproc);
  562. }
  563. return ret;
  564. }
  565. return 0;
  566. }
  567. module_init(nx842_powernv_init);
  568. static void __exit nx842_powernv_exit(void)
  569. {
  570. struct nx842_coproc *coproc, *n;
  571. crypto_unregister_alg(&nx842_powernv_alg);
  572. list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) {
  573. list_del(&coproc->list);
  574. kfree(coproc);
  575. }
  576. }
  577. module_exit(nx842_powernv_exit);