Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 | // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2021 Intel Corporation. All rights rsvd. */ #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/device.h> #include <linux/iommu.h> #include <uapi/linux/idxd.h> #include <linux/highmem.h> #include <linux/sched/smt.h> #include <crypto/internal/acompress.h> #include "idxd.h" #include "iaa_crypto.h" #include "iaa_crypto_stats.h" #ifdef pr_fmt #undef pr_fmt #endif #define pr_fmt(fmt) "idxd: " IDXD_SUBDRIVER_NAME ": " fmt #define IAA_ALG_PRIORITY 300 /* number of iaa instances probed */ static unsigned int nr_iaa; static unsigned int nr_cpus; static unsigned int nr_nodes; static unsigned int nr_cpus_per_node; /* Number of physical cpus sharing each iaa instance */ static unsigned int cpus_per_iaa; static struct crypto_comp *deflate_generic_tfm; /* Per-cpu lookup table for balanced wqs */ static struct wq_table_entry __percpu *wq_table; static struct idxd_wq *wq_table_next_wq(int cpu) { struct wq_table_entry *entry = per_cpu_ptr(wq_table, cpu); if (++entry->cur_wq >= entry->n_wqs) entry->cur_wq = 0; if (!entry->wqs[entry->cur_wq]) return NULL; pr_debug("%s: returning wq at idx %d (iaa wq %d.%d) from cpu %d\n", __func__, entry->cur_wq, entry->wqs[entry->cur_wq]->idxd->id, entry->wqs[entry->cur_wq]->id, cpu); return entry->wqs[entry->cur_wq]; } static void wq_table_add(int cpu, struct idxd_wq *wq) { struct wq_table_entry *entry = per_cpu_ptr(wq_table, cpu); if (WARN_ON(entry->n_wqs == entry->max_wqs)) return; entry->wqs[entry->n_wqs++] = wq; pr_debug("%s: added iaa wq %d.%d to idx %d of cpu %d\n", __func__, entry->wqs[entry->n_wqs - 1]->idxd->id, entry->wqs[entry->n_wqs - 1]->id, entry->n_wqs - 1, cpu); } static void wq_table_free_entry(int cpu) { struct wq_table_entry *entry = per_cpu_ptr(wq_table, cpu); kfree(entry->wqs); memset(entry, 0, sizeof(*entry)); } static void wq_table_clear_entry(int cpu) { struct wq_table_entry *entry = per_cpu_ptr(wq_table, cpu); entry->n_wqs = 0; entry->cur_wq = 0; memset(entry->wqs, 0, entry->max_wqs * sizeof(struct idxd_wq *)); } LIST_HEAD(iaa_devices); DEFINE_MUTEX(iaa_devices_lock); /* If enabled, IAA hw crypto algos are registered, unavailable otherwise */ static bool iaa_crypto_enabled; static bool iaa_crypto_registered; /* Verify results of IAA compress or not */ static bool iaa_verify_compress = true; static ssize_t verify_compress_show(struct device_driver *driver, char *buf) { return sprintf(buf, "%d\n", iaa_verify_compress); } static ssize_t verify_compress_store(struct device_driver *driver, const char *buf, size_t count) { int ret = -EBUSY; mutex_lock(&iaa_devices_lock); if (iaa_crypto_enabled) goto out; ret = kstrtobool(buf, &iaa_verify_compress); if (ret) goto out; ret = count; out: mutex_unlock(&iaa_devices_lock); return ret; } static DRIVER_ATTR_RW(verify_compress); /* * The iaa crypto driver supports three 'sync' methods determining how * compressions and decompressions are performed: * * - sync: the compression or decompression completes before * returning. This is the mode used by the async crypto * interface when the sync mode is set to 'sync' and by * the sync crypto interface regardless of setting. * * - async: the compression or decompression is submitted and returns * immediately. Completion interrupts are not used so * the caller is responsible for polling the descriptor * for completion. This mode is applicable to only the * async crypto interface and is ignored for anything * else. * * - async_irq: the compression or decompression is submitted and * returns immediately. Completion interrupts are * enabled so the caller can wait for the completion and * yield to other threads. When the compression or * decompression completes, the completion is signaled * and the caller awakened. This mode is applicable to * only the async crypto interface and is ignored for * anything else. * * These modes can be set using the iaa_crypto sync_mode driver * attribute. */ /* Use async mode */ static bool async_mode; /* Use interrupts */ static bool use_irq; /** * set_iaa_sync_mode - Set IAA sync mode * @name: The name of the sync mode * * Make the IAA sync mode named @name the current sync mode used by * compression/decompression. */ static int set_iaa_sync_mode(const char *name) { int ret = 0; if (sysfs_streq(name, "sync")) { async_mode = false; use_irq = false; } else if (sysfs_streq(name, "async")) { async_mode = true; use_irq = false; } else if (sysfs_streq(name, "async_irq")) { async_mode = true; use_irq = true; } else { ret = -EINVAL; } return ret; } static ssize_t sync_mode_show(struct device_driver *driver, char *buf) { int ret = 0; if (!async_mode && !use_irq) ret = sprintf(buf, "%s\n", "sync"); else if (async_mode && !use_irq) ret = sprintf(buf, "%s\n", "async"); else if (async_mode && use_irq) ret = sprintf(buf, "%s\n", "async_irq"); return ret; } static ssize_t sync_mode_store(struct device_driver *driver, const char *buf, size_t count) { int ret = -EBUSY; mutex_lock(&iaa_devices_lock); if (iaa_crypto_enabled) goto out; ret = set_iaa_sync_mode(buf); if (ret == 0) ret = count; out: mutex_unlock(&iaa_devices_lock); return ret; } static DRIVER_ATTR_RW(sync_mode); static struct iaa_compression_mode *iaa_compression_modes[IAA_COMP_MODES_MAX]; static int find_empty_iaa_compression_mode(void) { int i = -EINVAL; for (i = 0; i < IAA_COMP_MODES_MAX; i++) { if (iaa_compression_modes[i]) continue; break; } return i; } static struct iaa_compression_mode *find_iaa_compression_mode(const char *name, int *idx) { struct iaa_compression_mode *mode; int i; for (i = 0; i < IAA_COMP_MODES_MAX; i++) { mode = iaa_compression_modes[i]; if (!mode) continue; if (!strcmp(mode->name, name)) { *idx = i; return iaa_compression_modes[i]; } } return NULL; } static void free_iaa_compression_mode(struct iaa_compression_mode *mode) { kfree(mode->name); kfree(mode->ll_table); kfree(mode->d_table); kfree(mode); } /* * IAA Compression modes are defined by an ll_table and a d_table. * These tables are typically generated and captured using statistics * collected from running actual compress/decompress workloads. * * A module or other kernel code can add and remove compression modes * with a given name using the exported @add_iaa_compression_mode() * and @remove_iaa_compression_mode functions. * * When a new compression mode is added, the tables are saved in a * global compression mode list. When IAA devices are added, a * per-IAA device dma mapping is created for each IAA device, for each * compression mode. These are the tables used to do the actual * compression/deccompression and are unmapped if/when the devices are * removed. Currently, compression modes must be added before any * device is added, and removed after all devices have been removed. */ /** * remove_iaa_compression_mode - Remove an IAA compression mode * @name: The name the compression mode will be known as * * Remove the IAA compression mode named @name. */ void remove_iaa_compression_mode(const char *name) { struct iaa_compression_mode *mode; int idx; mutex_lock(&iaa_devices_lock); if (!list_empty(&iaa_devices)) goto out; mode = find_iaa_compression_mode(name, &idx); if (mode) { free_iaa_compression_mode(mode); iaa_compression_modes[idx] = NULL; } out: mutex_unlock(&iaa_devices_lock); } EXPORT_SYMBOL_GPL(remove_iaa_compression_mode); /** * add_iaa_compression_mode - Add an IAA compression mode * @name: The name the compression mode will be known as * @ll_table: The ll table * @ll_table_size: The ll table size in bytes * @d_table: The d table * @d_table_size: The d table size in bytes * @init: Optional callback function to init the compression mode data * @free: Optional callback function to free the compression mode data * * Add a new IAA compression mode named @name. * * Returns 0 if successful, errcode otherwise. */ int add_iaa_compression_mode(const char *name, const u32 *ll_table, int ll_table_size, const u32 *d_table, int d_table_size, iaa_dev_comp_init_fn_t init, iaa_dev_comp_free_fn_t free) { struct iaa_compression_mode *mode; int idx, ret = -ENOMEM; mutex_lock(&iaa_devices_lock); if (!list_empty(&iaa_devices)) { ret = -EBUSY; goto out; } mode = kzalloc(sizeof(*mode), GFP_KERNEL); if (!mode) goto out; mode->name = kstrdup(name, GFP_KERNEL); if (!mode->name) goto free; if (ll_table) { mode->ll_table = kzalloc(ll_table_size, GFP_KERNEL); if (!mode->ll_table) goto free; memcpy(mode->ll_table, ll_table, ll_table_size); mode->ll_table_size = ll_table_size; } if (d_table) { mode->d_table = kzalloc(d_table_size, GFP_KERNEL); if (!mode->d_table) goto free; memcpy(mode->d_table, d_table, d_table_size); mode->d_table_size = d_table_size; } mode->init = init; mode->free = free; idx = find_empty_iaa_compression_mode(); if (idx < 0) goto free; pr_debug("IAA compression mode %s added at idx %d\n", mode->name, idx); iaa_compression_modes[idx] = mode; ret = 0; out: mutex_unlock(&iaa_devices_lock); return ret; free: free_iaa_compression_mode(mode); goto out; } EXPORT_SYMBOL_GPL(add_iaa_compression_mode); static struct iaa_device_compression_mode * get_iaa_device_compression_mode(struct iaa_device *iaa_device, int idx) { return iaa_device->compression_modes[idx]; } static void free_device_compression_mode(struct iaa_device *iaa_device, struct iaa_device_compression_mode *device_mode) { size_t size = sizeof(struct aecs_comp_table_record) + IAA_AECS_ALIGN; struct device *dev = &iaa_device->idxd->pdev->dev; kfree(device_mode->name); if (device_mode->aecs_comp_table) dma_free_coherent(dev, size, device_mode->aecs_comp_table, device_mode->aecs_comp_table_dma_addr); kfree(device_mode); } #define IDXD_OP_FLAG_AECS_RW_TGLS 0x400000 #define IAX_AECS_DEFAULT_FLAG (IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR | IDXD_OP_FLAG_CC) #define IAX_AECS_COMPRESS_FLAG (IAX_AECS_DEFAULT_FLAG | IDXD_OP_FLAG_RD_SRC2_AECS) #define IAX_AECS_DECOMPRESS_FLAG (IAX_AECS_DEFAULT_FLAG | IDXD_OP_FLAG_RD_SRC2_AECS) #define IAX_AECS_GEN_FLAG (IAX_AECS_DEFAULT_FLAG | \ IDXD_OP_FLAG_WR_SRC2_AECS_COMP | \ IDXD_OP_FLAG_AECS_RW_TGLS) static int check_completion(struct device *dev, struct iax_completion_record *comp, bool compress, bool only_once); static int init_device_compression_mode(struct iaa_device *iaa_device, struct iaa_compression_mode *mode, int idx, struct idxd_wq *wq) { size_t size = sizeof(struct aecs_comp_table_record) + IAA_AECS_ALIGN; struct device *dev = &iaa_device->idxd->pdev->dev; struct iaa_device_compression_mode *device_mode; int ret = -ENOMEM; device_mode = kzalloc(sizeof(*device_mode), GFP_KERNEL); if (!device_mode) return -ENOMEM; device_mode->name = kstrdup(mode->name, GFP_KERNEL); if (!device_mode->name) goto free; device_mode->aecs_comp_table = dma_alloc_coherent(dev, size, &device_mode->aecs_comp_table_dma_addr, GFP_KERNEL); if (!device_mode->aecs_comp_table) goto free; /* Add Huffman table to aecs */ memset(device_mode->aecs_comp_table, 0, sizeof(*device_mode->aecs_comp_table)); memcpy(device_mode->aecs_comp_table->ll_sym, mode->ll_table, mode->ll_table_size); memcpy(device_mode->aecs_comp_table->d_sym, mode->d_table, mode->d_table_size); if (mode->init) { ret = mode->init(device_mode); if (ret) goto free; } /* mode index should match iaa_compression_modes idx */ iaa_device->compression_modes[idx] = device_mode; pr_debug("IAA %s compression mode initialized for iaa device %d\n", mode->name, iaa_device->idxd->id); ret = 0; out: return ret; free: pr_debug("IAA %s compression mode initialization failed for iaa device %d\n", mode->name, iaa_device->idxd->id); free_device_compression_mode(iaa_device, device_mode); goto out; } static int init_device_compression_modes(struct iaa_device *iaa_device, struct idxd_wq *wq) { struct iaa_compression_mode *mode; int i, ret = 0; for (i = 0; i < IAA_COMP_MODES_MAX; i++) { mode = iaa_compression_modes[i]; if (!mode) continue; ret = init_device_compression_mode(iaa_device, mode, i, wq); if (ret) break; } return ret; } static void remove_device_compression_modes(struct iaa_device *iaa_device) { struct iaa_device_compression_mode *device_mode; int i; for (i = 0; i < IAA_COMP_MODES_MAX; i++) { device_mode = iaa_device->compression_modes[i]; if (!device_mode) continue; free_device_compression_mode(iaa_device, device_mode); iaa_device->compression_modes[i] = NULL; if (iaa_compression_modes[i]->free) iaa_compression_modes[i]->free(device_mode); } } static struct iaa_device *iaa_device_alloc(void) { struct iaa_device *iaa_device; iaa_device = kzalloc(sizeof(*iaa_device), GFP_KERNEL); if (!iaa_device) return NULL; INIT_LIST_HEAD(&iaa_device->wqs); return iaa_device; } static bool iaa_has_wq(struct iaa_device *iaa_device, struct idxd_wq *wq) { struct iaa_wq *iaa_wq; list_for_each_entry(iaa_wq, &iaa_device->wqs, list) { if (iaa_wq->wq == wq) return true; } return false; } static struct iaa_device *add_iaa_device(struct idxd_device *idxd) { struct iaa_device *iaa_device; iaa_device = iaa_device_alloc(); if (!iaa_device) return NULL; iaa_device->idxd = idxd; list_add_tail(&iaa_device->list, &iaa_devices); nr_iaa++; return iaa_device; } static int init_iaa_device(struct iaa_device *iaa_device, struct iaa_wq *iaa_wq) { int ret = 0; ret = init_device_compression_modes(iaa_device, iaa_wq->wq); if (ret) return ret; return ret; } static void del_iaa_device(struct iaa_device *iaa_device) { list_del(&iaa_device->list); nr_iaa--; } static int add_iaa_wq(struct iaa_device *iaa_device, struct idxd_wq *wq, struct iaa_wq **new_wq) { struct idxd_device *idxd = iaa_device->idxd; struct pci_dev *pdev = idxd->pdev; struct device *dev = &pdev->dev; struct iaa_wq *iaa_wq; iaa_wq = kzalloc(sizeof(*iaa_wq), GFP_KERNEL); if (!iaa_wq) return -ENOMEM; iaa_wq->wq = wq; iaa_wq->iaa_device = iaa_device; idxd_wq_set_private(wq, iaa_wq); list_add_tail(&iaa_wq->list, &iaa_device->wqs); iaa_device->n_wq++; if (new_wq) *new_wq = iaa_wq; dev_dbg(dev, "added wq %d to iaa device %d, n_wq %d\n", wq->id, iaa_device->idxd->id, iaa_device->n_wq); return 0; } static void del_iaa_wq(struct iaa_device *iaa_device, struct idxd_wq *wq) { struct idxd_device *idxd = iaa_device->idxd; struct pci_dev *pdev = idxd->pdev; struct device *dev = &pdev->dev; struct iaa_wq *iaa_wq; list_for_each_entry(iaa_wq, &iaa_device->wqs, list) { if (iaa_wq->wq == wq) { list_del(&iaa_wq->list); iaa_device->n_wq--; dev_dbg(dev, "removed wq %d from iaa_device %d, n_wq %d, nr_iaa %d\n", wq->id, iaa_device->idxd->id, iaa_device->n_wq, nr_iaa); if (iaa_device->n_wq == 0) del_iaa_device(iaa_device); break; } } } static void clear_wq_table(void) { int cpu; for (cpu = 0; cpu < nr_cpus; cpu++) wq_table_clear_entry(cpu); pr_debug("cleared wq table\n"); } static void free_iaa_device(struct iaa_device *iaa_device) { if (!iaa_device) return; remove_device_compression_modes(iaa_device); kfree(iaa_device); } static void __free_iaa_wq(struct iaa_wq *iaa_wq) { struct iaa_device *iaa_device; if (!iaa_wq) return; iaa_device = iaa_wq->iaa_device; if (iaa_device->n_wq == 0) free_iaa_device(iaa_wq->iaa_device); } static void free_iaa_wq(struct iaa_wq *iaa_wq) { struct idxd_wq *wq; __free_iaa_wq(iaa_wq); wq = iaa_wq->wq; kfree(iaa_wq); idxd_wq_set_private(wq, NULL); } static int iaa_wq_get(struct idxd_wq *wq) { struct idxd_device *idxd = wq->idxd; struct iaa_wq *iaa_wq; int ret = 0; spin_lock(&idxd->dev_lock); iaa_wq = idxd_wq_get_private(wq); if (iaa_wq && !iaa_wq->remove) { iaa_wq->ref++; idxd_wq_get(wq); } else { ret = -ENODEV; } spin_unlock(&idxd->dev_lock); return ret; } static int iaa_wq_put(struct idxd_wq *wq) { struct idxd_device *idxd = wq->idxd; struct iaa_wq *iaa_wq; bool free = false; int ret = 0; spin_lock(&idxd->dev_lock); iaa_wq = idxd_wq_get_private(wq); if (iaa_wq) { iaa_wq->ref--; if (iaa_wq->ref == 0 && iaa_wq->remove) { idxd_wq_set_private(wq, NULL); free = true; } idxd_wq_put(wq); } else { ret = -ENODEV; } spin_unlock(&idxd->dev_lock); if (free) { __free_iaa_wq(iaa_wq); kfree(iaa_wq); } return ret; } static void free_wq_table(void) { int cpu; for (cpu = 0; cpu < nr_cpus; cpu++) wq_table_free_entry(cpu); free_percpu(wq_table); pr_debug("freed wq table\n"); } static int alloc_wq_table(int max_wqs) { struct wq_table_entry *entry; int cpu; wq_table = alloc_percpu(struct wq_table_entry); if (!wq_table) return -ENOMEM; for (cpu = 0; cpu < nr_cpus; cpu++) { entry = per_cpu_ptr(wq_table, cpu); entry->wqs = kcalloc(max_wqs, sizeof(struct wq *), GFP_KERNEL); if (!entry->wqs) { free_wq_table(); return -ENOMEM; } entry->max_wqs = max_wqs; } pr_debug("initialized wq table\n"); return 0; } static int save_iaa_wq(struct idxd_wq *wq) { struct iaa_device *iaa_device, *found = NULL; struct idxd_device *idxd; struct pci_dev *pdev; struct device *dev; int ret = 0; list_for_each_entry(iaa_device, &iaa_devices, list) { if (iaa_device->idxd == wq->idxd) { idxd = iaa_device->idxd; pdev = idxd->pdev; dev = &pdev->dev; /* * Check to see that we don't already have this wq. * Shouldn't happen but we don't control probing. */ if (iaa_has_wq(iaa_device, wq)) { dev_dbg(dev, "same wq probed multiple times for iaa_device %p\n", iaa_device); goto out; } found = iaa_device; ret = add_iaa_wq(iaa_device, wq, NULL); if (ret) goto out; break; } } if (!found) { struct iaa_device *new_device; struct iaa_wq *new_wq; new_device = add_iaa_device(wq->idxd); if (!new_device) { ret = -ENOMEM; goto out; } ret = add_iaa_wq(new_device, wq, &new_wq); if (ret) { del_iaa_device(new_device); free_iaa_device(new_device); goto out; } ret = init_iaa_device(new_device, new_wq); if (ret) { del_iaa_wq(new_device, new_wq->wq); del_iaa_device(new_device); free_iaa_wq(new_wq); goto out; } } if (WARN_ON(nr_iaa == 0)) return -EINVAL; cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa; if (!cpus_per_iaa) cpus_per_iaa = 1; out: return 0; } static void remove_iaa_wq(struct idxd_wq *wq) { struct iaa_device *iaa_device; list_for_each_entry(iaa_device, &iaa_devices, list) { if (iaa_has_wq(iaa_device, wq)) { del_iaa_wq(iaa_device, wq); break; } } if (nr_iaa) { cpus_per_iaa = (nr_nodes * nr_cpus_per_node) / nr_iaa; if (!cpus_per_iaa) cpus_per_iaa = 1; } else cpus_per_iaa = 1; } static int wq_table_add_wqs(int iaa, int cpu) { struct iaa_device *iaa_device, *found_device = NULL; int ret = 0, cur_iaa = 0, n_wqs_added = 0; struct idxd_device *idxd; struct iaa_wq *iaa_wq; struct pci_dev *pdev; struct device *dev; list_for_each_entry(iaa_device, &iaa_devices, list) { idxd = iaa_device->idxd; pdev = idxd->pdev; dev = &pdev->dev; if (cur_iaa != iaa) { cur_iaa++; continue; } found_device = iaa_device; dev_dbg(dev, "getting wq from iaa_device %d, cur_iaa %d\n", found_device->idxd->id, cur_iaa); break; } if (!found_device) { found_device = list_first_entry_or_null(&iaa_devices, struct iaa_device, list); if (!found_device) { pr_debug("couldn't find any iaa devices with wqs!\n"); ret = -EINVAL; goto out; } cur_iaa = 0; idxd = found_device->idxd; pdev = idxd->pdev; dev = &pdev->dev; dev_dbg(dev, "getting wq from only iaa_device %d, cur_iaa %d\n", found_device->idxd->id, cur_iaa); } list_for_each_entry(iaa_wq, &found_device->wqs, list) { wq_table_add(cpu, iaa_wq->wq); pr_debug("rebalance: added wq for cpu=%d: iaa wq %d.%d\n", cpu, iaa_wq->wq->idxd->id, iaa_wq->wq->id); n_wqs_added++; } if (!n_wqs_added) { pr_debug("couldn't find any iaa wqs!\n"); ret = -EINVAL; goto out; } out: return ret; } /* * Rebalance the wq table so that given a cpu, it's easy to find the * closest IAA instance. The idea is to try to choose the most * appropriate IAA instance for a caller and spread available * workqueues around to clients. */ static void rebalance_wq_table(void) { const struct cpumask *node_cpus; int node, cpu, iaa = -1; if (nr_iaa == 0) return; pr_debug("rebalance: nr_nodes=%d, nr_cpus %d, nr_iaa %d, cpus_per_iaa %d\n", nr_nodes, nr_cpus, nr_iaa, cpus_per_iaa); clear_wq_table(); if (nr_iaa == 1) { for (cpu = 0; cpu < nr_cpus; cpu++) { if (WARN_ON(wq_table_add_wqs(0, cpu))) { pr_debug("could not add any wqs for iaa 0 to cpu %d!\n", cpu); return; } } return; } for_each_node_with_cpus(node) { node_cpus = cpumask_of_node(node); for (cpu = 0; cpu < nr_cpus_per_node; cpu++) { int node_cpu = cpumask_nth(cpu, node_cpus); if (WARN_ON(node_cpu >= nr_cpu_ids)) { pr_debug("node_cpu %d doesn't exist!\n", node_cpu); return; } if ((cpu % cpus_per_iaa) == 0) iaa++; if (WARN_ON(wq_table_add_wqs(iaa, node_cpu))) { pr_debug("could not add any wqs for iaa %d to cpu %d!\n", iaa, cpu); return; } } } } static inline int check_completion(struct device *dev, struct iax_completion_record *comp, bool compress, bool only_once) { char *op_str = compress ? "compress" : "decompress"; int ret = 0; while (!comp->status) { if (only_once) return -EAGAIN; cpu_relax(); } if (comp->status != IAX_COMP_SUCCESS) { if (comp->status == IAA_ERROR_WATCHDOG_EXPIRED) { ret = -ETIMEDOUT; dev_dbg(dev, "%s timed out, size=0x%x\n", op_str, comp->output_size); update_completion_timeout_errs(); goto out; } if (comp->status == IAA_ANALYTICS_ERROR && comp->error_code == IAA_ERROR_COMP_BUF_OVERFLOW && compress) { ret = -E2BIG; dev_dbg(dev, "compressed > uncompressed size," " not compressing, size=0x%x\n", comp->output_size); update_completion_comp_buf_overflow_errs(); goto out; } if (comp->status == IAA_ERROR_DECOMP_BUF_OVERFLOW) { ret = -EOVERFLOW; goto out; } ret = -EINVAL; dev_dbg(dev, "iaa %s status=0x%x, error=0x%x, size=0x%x\n", op_str, comp->status, comp->error_code, comp->output_size); print_hex_dump(KERN_INFO, "cmp-rec: ", DUMP_PREFIX_OFFSET, 8, 1, comp, 64, 0); update_completion_einval_errs(); goto out; } out: return ret; } static int deflate_generic_decompress(struct acomp_req *req) { void *src, *dst; int ret; src = kmap_local_page(sg_page(req->src)) + req->src->offset; dst = kmap_local_page(sg_page(req->dst)) + req->dst->offset; ret = crypto_comp_decompress(deflate_generic_tfm, src, req->slen, dst, &req->dlen); kunmap_local(src); kunmap_local(dst); update_total_sw_decomp_calls(); return ret; } static int iaa_remap_for_verify(struct device *dev, struct iaa_wq *iaa_wq, struct acomp_req *req, dma_addr_t *src_addr, dma_addr_t *dst_addr); static int iaa_compress_verify(struct crypto_tfm *tfm, struct acomp_req *req, struct idxd_wq *wq, dma_addr_t src_addr, unsigned int slen, dma_addr_t dst_addr, unsigned int *dlen, u32 compression_crc); static void iaa_desc_complete(struct idxd_desc *idxd_desc, enum idxd_complete_type comp_type, bool free_desc, void *__ctx, u32 *status) { struct iaa_device_compression_mode *active_compression_mode; struct iaa_compression_ctx *compression_ctx; struct crypto_ctx *ctx = __ctx; struct iaa_device *iaa_device; struct idxd_device *idxd; struct iaa_wq *iaa_wq; struct pci_dev *pdev; struct device *dev; int ret, err = 0; compression_ctx = crypto_tfm_ctx(ctx->tfm); iaa_wq = idxd_wq_get_private(idxd_desc->wq); iaa_device = iaa_wq->iaa_device; idxd = iaa_device->idxd; pdev = idxd->pdev; dev = &pdev->dev; active_compression_mode = get_iaa_device_compression_mode(iaa_device, compression_ctx->mode); dev_dbg(dev, "%s: compression mode %s," " ctx->src_addr %llx, ctx->dst_addr %llx\n", __func__, active_compression_mode->name, ctx->src_addr, ctx->dst_addr); ret = check_completion(dev, idxd_desc->iax_completion, ctx->compress, false); if (ret) { dev_dbg(dev, "%s: check_completion failed ret=%d\n", __func__, ret); if (!ctx->compress && idxd_desc->iax_completion->status == IAA_ANALYTICS_ERROR) { pr_warn("%s: falling back to deflate-generic decompress, " "analytics error code %x\n", __func__, idxd_desc->iax_completion->error_code); ret = deflate_generic_decompress(ctx->req); if (ret) { dev_dbg(dev, "%s: deflate-generic failed ret=%d\n", __func__, ret); err = -EIO; goto err; } } else { err = -EIO; goto err; } } else { ctx->req->dlen = idxd_desc->iax_completion->output_size; } /* Update stats */ if (ctx->compress) { update_total_comp_bytes_out(ctx->req->dlen); update_wq_comp_bytes(iaa_wq->wq, ctx->req->dlen); } else { update_total_decomp_bytes_in(ctx->req->dlen); update_wq_decomp_bytes(iaa_wq->wq, ctx->req->dlen); } if (ctx->compress && compression_ctx->verify_compress) { dma_addr_t src_addr, dst_addr; u32 compression_crc; compression_crc = idxd_desc->iax_completion->crc; ret = iaa_remap_for_verify(dev, iaa_wq, ctx->req, &src_addr, &dst_addr); if (ret) { dev_dbg(dev, "%s: compress verify remap failed ret=%d\n", __func__, ret); err = -EIO; goto out; } ret = iaa_compress_verify(ctx->tfm, ctx->req, iaa_wq->wq, src_addr, ctx->req->slen, dst_addr, &ctx->req->dlen, compression_crc); if (ret) { dev_dbg(dev, "%s: compress verify failed ret=%d\n", __func__, ret); err = -EIO; } dma_unmap_sg(dev, ctx->req->dst, sg_nents(ctx->req->dst), DMA_TO_DEVICE); dma_unmap_sg(dev, ctx->req->src, sg_nents(ctx->req->src), DMA_FROM_DEVICE); goto out; } err: dma_unmap_sg(dev, ctx->req->dst, sg_nents(ctx->req->dst), DMA_FROM_DEVICE); dma_unmap_sg(dev, ctx->req->src, sg_nents(ctx->req->src), DMA_TO_DEVICE); out: if (ret != 0) dev_dbg(dev, "asynchronous compress failed ret=%d\n", ret); if (ctx->req->base.complete) acomp_request_complete(ctx->req, err); if (free_desc) idxd_free_desc(idxd_desc->wq, idxd_desc); iaa_wq_put(idxd_desc->wq); } static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req, struct idxd_wq *wq, dma_addr_t src_addr, unsigned int slen, dma_addr_t dst_addr, unsigned int *dlen, u32 *compression_crc, bool disable_async) { struct iaa_device_compression_mode *active_compression_mode; struct iaa_compression_ctx *ctx = crypto_tfm_ctx(tfm); struct iaa_device *iaa_device; struct idxd_desc *idxd_desc; struct iax_hw_desc *desc; struct idxd_device *idxd; struct iaa_wq *iaa_wq; struct pci_dev *pdev; struct device *dev; int ret = 0; iaa_wq = idxd_wq_get_private(wq); iaa_device = iaa_wq->iaa_device; idxd = iaa_device->idxd; pdev = idxd->pdev; dev = &pdev->dev; active_compression_mode = get_iaa_device_compression_mode(iaa_device, ctx->mode); idxd_desc = idxd_alloc_desc(wq, IDXD_OP_BLOCK); if (IS_ERR(idxd_desc)) { dev_dbg(dev, "idxd descriptor allocation failed\n"); dev_dbg(dev, "iaa compress failed: ret=%ld\n", PTR_ERR(idxd_desc)); return PTR_ERR(idxd_desc); } desc = idxd_desc->iax_hw; desc->flags = IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR | IDXD_OP_FLAG_RD_SRC2_AECS | IDXD_OP_FLAG_CC; desc->opcode = IAX_OPCODE_COMPRESS; desc->compr_flags = IAA_COMP_FLAGS; desc->priv = 0; desc->src1_addr = (u64)src_addr; desc->src1_size = slen; desc->dst_addr = (u64)dst_addr; desc->max_dst_size = *dlen; desc->src2_addr = active_compression_mode->aecs_comp_table_dma_addr; desc->src2_size = sizeof(struct aecs_comp_table_record); desc->completion_addr = idxd_desc->compl_dma; if (ctx->use_irq && !disable_async) { desc->flags |= IDXD_OP_FLAG_RCI; idxd_desc->crypto.req = req; idxd_desc->crypto.tfm = tfm; idxd_desc->crypto.src_addr = src_addr; idxd_desc->crypto.dst_addr = dst_addr; idxd_desc->crypto.compress = true; dev_dbg(dev, "%s use_async_irq: compression mode %s," " src_addr %llx, dst_addr %llx\n", __func__, active_compression_mode->name, src_addr, dst_addr); } else if (ctx->async_mode && !disable_async) req->base.data = idxd_desc; dev_dbg(dev, "%s: compression mode %s," " desc->src1_addr %llx, desc->src1_size %d," " desc->dst_addr %llx, desc->max_dst_size %d," " desc->src2_addr %llx, desc->src2_size %d\n", __func__, active_compression_mode->name, desc->src1_addr, desc->src1_size, desc->dst_addr, desc->max_dst_size, desc->src2_addr, desc->src2_size); ret = idxd_submit_desc(wq, idxd_desc); if (ret) { dev_dbg(dev, "submit_desc failed ret=%d\n", ret); goto err; } /* Update stats */ update_total_comp_calls(); update_wq_comp_calls(wq); if (ctx->async_mode && !disable_async) { ret = -EINPROGRESS; dev_dbg(dev, "%s: returning -EINPROGRESS\n", __func__); goto out; } ret = check_completion(dev, idxd_desc->iax_completion, true, false); if (ret) { dev_dbg(dev, "check_completion failed ret=%d\n", ret); goto err; } *dlen = idxd_desc->iax_completion->output_size; /* Update stats */ update_total_comp_bytes_out(*dlen); update_wq_comp_bytes(wq, *dlen); *compression_crc = idxd_desc->iax_completion->crc; if (!ctx->async_mode || disable_async) idxd_free_desc(wq, idxd_desc); out: return ret; err: idxd_free_desc(wq, idxd_desc); dev_dbg(dev, "iaa compress failed: ret=%d\n", ret); goto out; } static int iaa_remap_for_verify(struct device *dev, struct iaa_wq *iaa_wq, struct acomp_req *req, dma_addr_t *src_addr, dma_addr_t *dst_addr) { int ret = 0; int nr_sgs; dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); nr_sgs = dma_map_sg(dev, req->src, sg_nents(req->src), DMA_FROM_DEVICE); if (nr_sgs <= 0 || nr_sgs > 1) { dev_dbg(dev, "verify: couldn't map src sg for iaa device %d," " wq %d: ret=%d\n", iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id, ret); ret = -EIO; goto out; } *src_addr = sg_dma_address(req->src); dev_dbg(dev, "verify: dma_map_sg, src_addr %llx, nr_sgs %d, req->src %p," " req->slen %d, sg_dma_len(sg) %d\n", *src_addr, nr_sgs, req->src, req->slen, sg_dma_len(req->src)); nr_sgs = dma_map_sg(dev, req->dst, sg_nents(req->dst), DMA_TO_DEVICE); if (nr_sgs <= 0 || nr_sgs > 1) { dev_dbg(dev, "verify: couldn't map dst sg for iaa device %d," " wq %d: ret=%d\n", iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id, ret); ret = -EIO; dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_FROM_DEVICE); goto out; } *dst_addr = sg_dma_address(req->dst); dev_dbg(dev, "verify: dma_map_sg, dst_addr %llx, nr_sgs %d, req->dst %p," " req->dlen %d, sg_dma_len(sg) %d\n", *dst_addr, nr_sgs, req->dst, req->dlen, sg_dma_len(req->dst)); out: return ret; } static int iaa_compress_verify(struct crypto_tfm *tfm, struct acomp_req *req, struct idxd_wq *wq, dma_addr_t src_addr, unsigned int slen, dma_addr_t dst_addr, unsigned int *dlen, u32 compression_crc) { struct iaa_device_compression_mode *active_compression_mode; struct iaa_compression_ctx *ctx = crypto_tfm_ctx(tfm); struct iaa_device *iaa_device; struct idxd_desc *idxd_desc; struct iax_hw_desc *desc; struct idxd_device *idxd; struct iaa_wq *iaa_wq; struct pci_dev *pdev; struct device *dev; int ret = 0; iaa_wq = idxd_wq_get_private(wq); iaa_device = iaa_wq->iaa_device; idxd = iaa_device->idxd; pdev = idxd->pdev; dev = &pdev->dev; active_compression_mode = get_iaa_device_compression_mode(iaa_device, ctx->mode); idxd_desc = idxd_alloc_desc(wq, IDXD_OP_BLOCK); if (IS_ERR(idxd_desc)) { dev_dbg(dev, "idxd descriptor allocation failed\n"); dev_dbg(dev, "iaa compress failed: ret=%ld\n", PTR_ERR(idxd_desc)); return PTR_ERR(idxd_desc); } desc = idxd_desc->iax_hw; /* Verify (optional) - decompress and check crc, suppress dest write */ desc->flags = IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR | IDXD_OP_FLAG_CC; desc->opcode = IAX_OPCODE_DECOMPRESS; desc->decompr_flags = IAA_DECOMP_FLAGS | IAA_DECOMP_SUPPRESS_OUTPUT; desc->priv = 0; desc->src1_addr = (u64)dst_addr; desc->src1_size = *dlen; desc->dst_addr = (u64)src_addr; desc->max_dst_size = slen; desc->completion_addr = idxd_desc->compl_dma; dev_dbg(dev, "(verify) compression mode %s," " desc->src1_addr %llx, desc->src1_size %d," " desc->dst_addr %llx, desc->max_dst_size %d," " desc->src2_addr %llx, desc->src2_size %d\n", active_compression_mode->name, desc->src1_addr, desc->src1_size, desc->dst_addr, desc->max_dst_size, desc->src2_addr, desc->src2_size); ret = idxd_submit_desc(wq, idxd_desc); if (ret) { dev_dbg(dev, "submit_desc (verify) failed ret=%d\n", ret); goto err; } ret = check_completion(dev, idxd_desc->iax_completion, false, false); if (ret) { dev_dbg(dev, "(verify) check_completion failed ret=%d\n", ret); goto err; } if (compression_crc != idxd_desc->iax_completion->crc) { ret = -EINVAL; dev_dbg(dev, "(verify) iaa comp/decomp crc mismatch:" " comp=0x%x, decomp=0x%x\n", compression_crc, idxd_desc->iax_completion->crc); print_hex_dump(KERN_INFO, "cmp-rec: ", DUMP_PREFIX_OFFSET, 8, 1, idxd_desc->iax_completion, 64, 0); goto err; } idxd_free_desc(wq, idxd_desc); out: return ret; err: idxd_free_desc(wq, idxd_desc); dev_dbg(dev, "iaa compress failed: ret=%d\n", ret); goto out; } static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, struct idxd_wq *wq, dma_addr_t src_addr, unsigned int slen, dma_addr_t dst_addr, unsigned int *dlen, bool disable_async) { struct iaa_device_compression_mode *active_compression_mode; struct iaa_compression_ctx *ctx = crypto_tfm_ctx(tfm); struct iaa_device *iaa_device; struct idxd_desc *idxd_desc; struct iax_hw_desc *desc; struct idxd_device *idxd; struct iaa_wq *iaa_wq; struct pci_dev *pdev; struct device *dev; int ret = 0; iaa_wq = idxd_wq_get_private(wq); iaa_device = iaa_wq->iaa_device; idxd = iaa_device->idxd; pdev = idxd->pdev; dev = &pdev->dev; active_compression_mode = get_iaa_device_compression_mode(iaa_device, ctx->mode); idxd_desc = idxd_alloc_desc(wq, IDXD_OP_BLOCK); if (IS_ERR(idxd_desc)) { dev_dbg(dev, "idxd descriptor allocation failed\n"); dev_dbg(dev, "iaa decompress failed: ret=%ld\n", PTR_ERR(idxd_desc)); return PTR_ERR(idxd_desc); } desc = idxd_desc->iax_hw; desc->flags = IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR | IDXD_OP_FLAG_CC; desc->opcode = IAX_OPCODE_DECOMPRESS; desc->max_dst_size = PAGE_SIZE; desc->decompr_flags = IAA_DECOMP_FLAGS; desc->priv = 0; desc->src1_addr = (u64)src_addr; desc->dst_addr = (u64)dst_addr; desc->max_dst_size = *dlen; desc->src1_size = slen; desc->completion_addr = idxd_desc->compl_dma; if (ctx->use_irq && !disable_async) { desc->flags |= IDXD_OP_FLAG_RCI; idxd_desc->crypto.req = req; idxd_desc->crypto.tfm = tfm; idxd_desc->crypto.src_addr = src_addr; idxd_desc->crypto.dst_addr = dst_addr; idxd_desc->crypto.compress = false; dev_dbg(dev, "%s: use_async_irq compression mode %s," " src_addr %llx, dst_addr %llx\n", __func__, active_compression_mode->name, src_addr, dst_addr); } else if (ctx->async_mode && !disable_async) req->base.data = idxd_desc; dev_dbg(dev, "%s: decompression mode %s," " desc->src1_addr %llx, desc->src1_size %d," " desc->dst_addr %llx, desc->max_dst_size %d," " desc->src2_addr %llx, desc->src2_size %d\n", __func__, active_compression_mode->name, desc->src1_addr, desc->src1_size, desc->dst_addr, desc->max_dst_size, desc->src2_addr, desc->src2_size); ret = idxd_submit_desc(wq, idxd_desc); if (ret) { dev_dbg(dev, "submit_desc failed ret=%d\n", ret); goto err; } /* Update stats */ update_total_decomp_calls(); update_wq_decomp_calls(wq); if (ctx->async_mode && !disable_async) { ret = -EINPROGRESS; dev_dbg(dev, "%s: returning -EINPROGRESS\n", __func__); goto out; } ret = check_completion(dev, idxd_desc->iax_completion, false, false); if (ret) { dev_dbg(dev, "%s: check_completion failed ret=%d\n", __func__, ret); if (idxd_desc->iax_completion->status == IAA_ANALYTICS_ERROR) { pr_warn("%s: falling back to deflate-generic decompress, " "analytics error code %x\n", __func__, idxd_desc->iax_completion->error_code); ret = deflate_generic_decompress(req); if (ret) { dev_dbg(dev, "%s: deflate-generic failed ret=%d\n", __func__, ret); goto err; } } else { goto err; } } else { req->dlen = idxd_desc->iax_completion->output_size; } *dlen = req->dlen; if (!ctx->async_mode || disable_async) idxd_free_desc(wq, idxd_desc); /* Update stats */ update_total_decomp_bytes_in(slen); update_wq_decomp_bytes(wq, slen); out: return ret; err: idxd_free_desc(wq, idxd_desc); dev_dbg(dev, "iaa decompress failed: ret=%d\n", ret); goto out; } static int iaa_comp_acompress(struct acomp_req *req) { struct iaa_compression_ctx *compression_ctx; struct crypto_tfm *tfm = req->base.tfm; dma_addr_t src_addr, dst_addr; bool disable_async = false; int nr_sgs, cpu, ret = 0; struct iaa_wq *iaa_wq; u32 compression_crc; struct idxd_wq *wq; struct device *dev; u64 start_time_ns; int order = -1; compression_ctx = crypto_tfm_ctx(tfm); if (!iaa_crypto_enabled) { pr_debug("iaa_crypto disabled, not compressing\n"); return -ENODEV; } if (!req->src || !req->slen) { pr_debug("invalid src, not compressing\n"); return -EINVAL; } cpu = get_cpu(); wq = wq_table_next_wq(cpu); put_cpu(); if (!wq) { pr_debug("no wq configured for cpu=%d\n", cpu); return -ENODEV; } ret = iaa_wq_get(wq); if (ret) { pr_debug("no wq available for cpu=%d\n", cpu); return -ENODEV; } iaa_wq = idxd_wq_get_private(wq); if (!req->dst) { gfp_t flags = req->flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC; /* incompressible data will always be < 2 * slen */ req->dlen = 2 * req->slen; order = order_base_2(round_up(req->dlen, PAGE_SIZE) / PAGE_SIZE); req->dst = sgl_alloc_order(req->dlen, order, false, flags, NULL); if (!req->dst) { ret = -ENOMEM; order = -1; goto out; } disable_async = true; } dev = &wq->idxd->pdev->dev; nr_sgs = dma_map_sg(dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); if (nr_sgs <= 0 || nr_sgs > 1) { dev_dbg(dev, "couldn't map src sg for iaa device %d," " wq %d: ret=%d\n", iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id, ret); ret = -EIO; goto out; } src_addr = sg_dma_address(req->src); dev_dbg(dev, "dma_map_sg, src_addr %llx, nr_sgs %d, req->src %p," " req->slen %d, sg_dma_len(sg) %d\n", src_addr, nr_sgs, req->src, req->slen, sg_dma_len(req->src)); nr_sgs = dma_map_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); if (nr_sgs <= 0 || nr_sgs > 1) { dev_dbg(dev, "couldn't map dst sg for iaa device %d," " wq %d: ret=%d\n", iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id, ret); ret = -EIO; goto err_map_dst; } dst_addr = sg_dma_address(req->dst); dev_dbg(dev, "dma_map_sg, dst_addr %llx, nr_sgs %d, req->dst %p," " req->dlen %d, sg_dma_len(sg) %d\n", dst_addr, nr_sgs, req->dst, req->dlen, sg_dma_len(req->dst)); start_time_ns = iaa_get_ts(); ret = iaa_compress(tfm, req, wq, src_addr, req->slen, dst_addr, &req->dlen, &compression_crc, disable_async); update_max_comp_delay_ns(start_time_ns); if (ret == -EINPROGRESS) return ret; if (!ret && compression_ctx->verify_compress) { ret = iaa_remap_for_verify(dev, iaa_wq, req, &src_addr, &dst_addr); if (ret) { dev_dbg(dev, "%s: compress verify remap failed ret=%d\n", __func__, ret); goto out; } ret = iaa_compress_verify(tfm, req, wq, src_addr, req->slen, dst_addr, &req->dlen, compression_crc); if (ret) dev_dbg(dev, "asynchronous compress verification failed ret=%d\n", ret); dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_TO_DEVICE); dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_FROM_DEVICE); goto out; } if (ret) dev_dbg(dev, "asynchronous compress failed ret=%d\n", ret); dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); err_map_dst: dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); out: iaa_wq_put(wq); if (order >= 0) sgl_free_order(req->dst, order); return ret; } static int iaa_comp_adecompress_alloc_dest(struct acomp_req *req) { gfp_t flags = req->flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC; struct crypto_tfm *tfm = req->base.tfm; dma_addr_t src_addr, dst_addr; int nr_sgs, cpu, ret = 0; struct iaa_wq *iaa_wq; struct device *dev; struct idxd_wq *wq; u64 start_time_ns; int order = -1; cpu = get_cpu(); wq = wq_table_next_wq(cpu); put_cpu(); if (!wq) { pr_debug("no wq configured for cpu=%d\n", cpu); return -ENODEV; } ret = iaa_wq_get(wq); if (ret) { pr_debug("no wq available for cpu=%d\n", cpu); return -ENODEV; } iaa_wq = idxd_wq_get_private(wq); dev = &wq->idxd->pdev->dev; nr_sgs = dma_map_sg(dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); if (nr_sgs <= 0 || nr_sgs > 1) { dev_dbg(dev, "couldn't map src sg for iaa device %d," " wq %d: ret=%d\n", iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id, ret); ret = -EIO; goto out; } src_addr = sg_dma_address(req->src); dev_dbg(dev, "dma_map_sg, src_addr %llx, nr_sgs %d, req->src %p," " req->slen %d, sg_dma_len(sg) %d\n", src_addr, nr_sgs, req->src, req->slen, sg_dma_len(req->src)); req->dlen = 4 * req->slen; /* start with ~avg comp rato */ alloc_dest: order = order_base_2(round_up(req->dlen, PAGE_SIZE) / PAGE_SIZE); req->dst = sgl_alloc_order(req->dlen, order, false, flags, NULL); if (!req->dst) { ret = -ENOMEM; order = -1; goto out; } nr_sgs = dma_map_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); if (nr_sgs <= 0 || nr_sgs > 1) { dev_dbg(dev, "couldn't map dst sg for iaa device %d," " wq %d: ret=%d\n", iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id, ret); ret = -EIO; goto err_map_dst; } dst_addr = sg_dma_address(req->dst); dev_dbg(dev, "dma_map_sg, dst_addr %llx, nr_sgs %d, req->dst %p," " req->dlen %d, sg_dma_len(sg) %d\n", dst_addr, nr_sgs, req->dst, req->dlen, sg_dma_len(req->dst)); start_time_ns = iaa_get_ts(); ret = iaa_decompress(tfm, req, wq, src_addr, req->slen, dst_addr, &req->dlen, true); update_max_decomp_delay_ns(start_time_ns); if (ret == -EOVERFLOW) { dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); req->dlen *= 2; if (req->dlen > CRYPTO_ACOMP_DST_MAX) goto err_map_dst; goto alloc_dest; } if (ret != 0) dev_dbg(dev, "asynchronous decompress failed ret=%d\n", ret); dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); err_map_dst: dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); out: iaa_wq_put(wq); if (order >= 0) sgl_free_order(req->dst, order); return ret; } static int iaa_comp_adecompress(struct acomp_req *req) { struct crypto_tfm *tfm = req->base.tfm; dma_addr_t src_addr, dst_addr; int nr_sgs, cpu, ret = 0; struct iaa_wq *iaa_wq; struct device *dev; u64 start_time_ns; struct idxd_wq *wq; if (!iaa_crypto_enabled) { pr_debug("iaa_crypto disabled, not decompressing\n"); return -ENODEV; } if (!req->src || !req->slen) { pr_debug("invalid src, not decompressing\n"); return -EINVAL; } if (!req->dst) return iaa_comp_adecompress_alloc_dest(req); cpu = get_cpu(); wq = wq_table_next_wq(cpu); put_cpu(); if (!wq) { pr_debug("no wq configured for cpu=%d\n", cpu); return -ENODEV; } ret = iaa_wq_get(wq); if (ret) { pr_debug("no wq available for cpu=%d\n", cpu); return -ENODEV; } iaa_wq = idxd_wq_get_private(wq); dev = &wq->idxd->pdev->dev; nr_sgs = dma_map_sg(dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); if (nr_sgs <= 0 || nr_sgs > 1) { dev_dbg(dev, "couldn't map src sg for iaa device %d," " wq %d: ret=%d\n", iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id, ret); ret = -EIO; goto out; } src_addr = sg_dma_address(req->src); dev_dbg(dev, "dma_map_sg, src_addr %llx, nr_sgs %d, req->src %p," " req->slen %d, sg_dma_len(sg) %d\n", src_addr, nr_sgs, req->src, req->slen, sg_dma_len(req->src)); nr_sgs = dma_map_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); if (nr_sgs <= 0 || nr_sgs > 1) { dev_dbg(dev, "couldn't map dst sg for iaa device %d," " wq %d: ret=%d\n", iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id, ret); ret = -EIO; goto err_map_dst; } dst_addr = sg_dma_address(req->dst); dev_dbg(dev, "dma_map_sg, dst_addr %llx, nr_sgs %d, req->dst %p," " req->dlen %d, sg_dma_len(sg) %d\n", dst_addr, nr_sgs, req->dst, req->dlen, sg_dma_len(req->dst)); start_time_ns = iaa_get_ts(); ret = iaa_decompress(tfm, req, wq, src_addr, req->slen, dst_addr, &req->dlen, false); update_max_decomp_delay_ns(start_time_ns); if (ret == -EINPROGRESS) return ret; if (ret != 0) dev_dbg(dev, "asynchronous decompress failed ret=%d\n", ret); dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); err_map_dst: dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); out: iaa_wq_put(wq); return ret; } static void compression_ctx_init(struct iaa_compression_ctx *ctx) { ctx->verify_compress = iaa_verify_compress; ctx->async_mode = async_mode; ctx->use_irq = use_irq; } static int iaa_comp_init_fixed(struct crypto_acomp *acomp_tfm) { struct crypto_tfm *tfm = crypto_acomp_tfm(acomp_tfm); struct iaa_compression_ctx *ctx = crypto_tfm_ctx(tfm); compression_ctx_init(ctx); ctx->mode = IAA_MODE_FIXED; return 0; } static void dst_free(struct scatterlist *sgl) { /* * Called for req->dst = NULL cases but we free elsewhere * using sgl_free_order(). */ } static struct acomp_alg iaa_acomp_fixed_deflate = { .init = iaa_comp_init_fixed, .compress = iaa_comp_acompress, .decompress = iaa_comp_adecompress, .dst_free = dst_free, .base = { .cra_name = "deflate", .cra_driver_name = "deflate-iaa", .cra_flags = CRYPTO_ALG_ASYNC, .cra_ctxsize = sizeof(struct iaa_compression_ctx), .cra_module = THIS_MODULE, .cra_priority = IAA_ALG_PRIORITY, } }; static int iaa_register_compression_device(void) { int ret; ret = crypto_register_acomp(&iaa_acomp_fixed_deflate); if (ret) { pr_err("deflate algorithm acomp fixed registration failed (%d)\n", ret); goto out; } iaa_crypto_registered = true; out: return ret; } static int iaa_unregister_compression_device(void) { if (iaa_crypto_registered) crypto_unregister_acomp(&iaa_acomp_fixed_deflate); return 0; } static int iaa_crypto_probe(struct idxd_dev *idxd_dev) { struct idxd_wq *wq = idxd_dev_to_wq(idxd_dev); struct idxd_device *idxd = wq->idxd; struct idxd_driver_data *data = idxd->data; struct device *dev = &idxd_dev->conf_dev; bool first_wq = false; int ret = 0; if (idxd->state != IDXD_DEV_ENABLED) return -ENXIO; if (data->type != IDXD_TYPE_IAX) return -ENODEV; mutex_lock(&wq->wq_lock); if (idxd_wq_get_private(wq)) { mutex_unlock(&wq->wq_lock); return -EBUSY; } if (!idxd_wq_driver_name_match(wq, dev)) { dev_dbg(dev, "wq %d.%d driver_name match failed: wq driver_name %s, dev driver name %s\n", idxd->id, wq->id, wq->driver_name, dev->driver->name); idxd->cmd_status = IDXD_SCMD_WQ_NO_DRV_NAME; ret = -ENODEV; goto err; } wq->type = IDXD_WQT_KERNEL; ret = idxd_drv_enable_wq(wq); if (ret < 0) { dev_dbg(dev, "enable wq %d.%d failed: %d\n", idxd->id, wq->id, ret); ret = -ENXIO; goto err; } mutex_lock(&iaa_devices_lock); if (list_empty(&iaa_devices)) { ret = alloc_wq_table(wq->idxd->max_wqs); if (ret) goto err_alloc; first_wq = true; } ret = save_iaa_wq(wq); if (ret) goto err_save; rebalance_wq_table(); if (first_wq) { iaa_crypto_enabled = true; ret = iaa_register_compression_device(); if (ret != 0) { iaa_crypto_enabled = false; dev_dbg(dev, "IAA compression device registration failed\n"); goto err_register; } try_module_get(THIS_MODULE); pr_info("iaa_crypto now ENABLED\n"); } mutex_unlock(&iaa_devices_lock); out: mutex_unlock(&wq->wq_lock); return ret; err_register: remove_iaa_wq(wq); free_iaa_wq(idxd_wq_get_private(wq)); err_save: if (first_wq) free_wq_table(); err_alloc: mutex_unlock(&iaa_devices_lock); idxd_drv_disable_wq(wq); err: wq->type = IDXD_WQT_NONE; goto out; } static void iaa_crypto_remove(struct idxd_dev *idxd_dev) { struct idxd_wq *wq = idxd_dev_to_wq(idxd_dev); struct idxd_device *idxd = wq->idxd; struct iaa_wq *iaa_wq; bool free = false; idxd_wq_quiesce(wq); mutex_lock(&wq->wq_lock); mutex_lock(&iaa_devices_lock); remove_iaa_wq(wq); spin_lock(&idxd->dev_lock); iaa_wq = idxd_wq_get_private(wq); if (!iaa_wq) { spin_unlock(&idxd->dev_lock); pr_err("%s: no iaa_wq available to remove\n", __func__); goto out; } if (iaa_wq->ref) { iaa_wq->remove = true; } else { wq = iaa_wq->wq; idxd_wq_set_private(wq, NULL); free = true; } spin_unlock(&idxd->dev_lock); if (free) { __free_iaa_wq(iaa_wq); kfree(iaa_wq); } idxd_drv_disable_wq(wq); rebalance_wq_table(); if (nr_iaa == 0) { iaa_crypto_enabled = false; free_wq_table(); module_put(THIS_MODULE); pr_info("iaa_crypto now DISABLED\n"); } out: mutex_unlock(&iaa_devices_lock); mutex_unlock(&wq->wq_lock); } static enum idxd_dev_type dev_types[] = { IDXD_DEV_WQ, IDXD_DEV_NONE, }; static struct idxd_device_driver iaa_crypto_driver = { .probe = iaa_crypto_probe, .remove = iaa_crypto_remove, .name = IDXD_SUBDRIVER_NAME, .type = dev_types, .desc_complete = iaa_desc_complete, }; static int __init iaa_crypto_init_module(void) { int ret = 0; int node; nr_cpus = num_online_cpus(); for_each_node_with_cpus(node) nr_nodes++; if (!nr_nodes) { pr_err("IAA couldn't find any nodes with cpus\n"); return -ENODEV; } nr_cpus_per_node = nr_cpus / nr_nodes; if (crypto_has_comp("deflate-generic", 0, 0)) deflate_generic_tfm = crypto_alloc_comp("deflate-generic", 0, 0); if (IS_ERR_OR_NULL(deflate_generic_tfm)) { pr_err("IAA could not alloc %s tfm: errcode = %ld\n", "deflate-generic", PTR_ERR(deflate_generic_tfm)); return -ENOMEM; } ret = iaa_aecs_init_fixed(); if (ret < 0) { pr_debug("IAA fixed compression mode init failed\n"); goto err_aecs_init; } ret = idxd_driver_register(&iaa_crypto_driver); if (ret) { pr_debug("IAA wq sub-driver registration failed\n"); goto err_driver_reg; } ret = driver_create_file(&iaa_crypto_driver.drv, &driver_attr_verify_compress); if (ret) { pr_debug("IAA verify_compress attr creation failed\n"); goto err_verify_attr_create; } ret = driver_create_file(&iaa_crypto_driver.drv, &driver_attr_sync_mode); if (ret) { pr_debug("IAA sync mode attr creation failed\n"); goto err_sync_attr_create; } if (iaa_crypto_debugfs_init()) pr_warn("debugfs init failed, stats not available\n"); pr_debug("initialized\n"); out: return ret; err_sync_attr_create: driver_remove_file(&iaa_crypto_driver.drv, &driver_attr_verify_compress); err_verify_attr_create: idxd_driver_unregister(&iaa_crypto_driver); err_driver_reg: iaa_aecs_cleanup_fixed(); err_aecs_init: crypto_free_comp(deflate_generic_tfm); goto out; } static void __exit iaa_crypto_cleanup_module(void) { if (iaa_unregister_compression_device()) pr_debug("IAA compression device unregister failed\n"); iaa_crypto_debugfs_cleanup(); driver_remove_file(&iaa_crypto_driver.drv, &driver_attr_sync_mode); driver_remove_file(&iaa_crypto_driver.drv, &driver_attr_verify_compress); idxd_driver_unregister(&iaa_crypto_driver); iaa_aecs_cleanup_fixed(); crypto_free_comp(deflate_generic_tfm); pr_debug("cleaned up\n"); } MODULE_IMPORT_NS(IDXD); MODULE_LICENSE("GPL"); MODULE_ALIAS_IDXD_DEVICE(0); MODULE_AUTHOR("Intel Corporation"); MODULE_DESCRIPTION("IAA Compression Accelerator Crypto Driver"); module_init(iaa_crypto_init_module); module_exit(iaa_crypto_cleanup_module); |