File: qatzip.h

package info (click to toggle)
qatzip 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,912 kB
  • sloc: ansic: 20,086; makefile: 188; sh: 114
file content (3107 lines) | stat: -rwxr-xr-x 112,645 bytes parent folder | download
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
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
/***************************************************************************
 *
 *   BSD LICENSE
 *
 *   Copyright(c) 2007-2026 Intel Corporation. All rights reserved.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Intel Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ***************************************************************************/

/**
 *****************************************************************************
 * @file qatzip.h
 *
 * @defgroup qatZip Data Compression API
 *
 * @description
 *      These functions specify the API for data compression operations.
 *
 * @remarks
 *
 *
 *****************************************************************************/

#ifndef QATZIP_H
#define QATZIP_H

#ifdef __cplusplus
extern"C" {
#endif

#include <string.h>
#include <stdint.h>

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip Major Version Number
 * @description
 *      The QATzip API major version number. This number will be incremented
 *    when significant changes to the API have occurred.
 *    The combination of the major and minor number definitions represent
 *    the complete version number for this interface.
 *
 *****************************************************************************/
#define QATZIP_API_VERSION_NUM_MAJOR (2)

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip Minor Version Number
 * @description
 *      The QATzip API minor version number. This number will be incremented
 *    when minor changes to the API have occurred. The combination of the major
 *    and minor number definitions represent the complete version number for
 *    this interface.
 *****************************************************************************/
#define QATZIP_API_VERSION_NUM_MINOR (5)

/* Define a macro as an integer to test */
#define QATZIP_API_VERSION    (QATZIP_API_VERSION_NUM_MAJOR * 10000 +      \
                               QATZIP_API_VERSION_NUM_MINOR * 100)

/**
 *  These macros define how the project will be built
 *  QATZIP_LINK_DLL must be defined if linking the DLL
 *  QATZIP_BUILD_DLL must be defined when building a DLL
 *  No definition required if building the project as static library
 */
#if defined QATZIP_LINK_DLL
#define QATZIP_API __declspec(dllimport)
#elif defined QATZIP_BUILD_DLL
#define QATZIP_API __declspec(dllexport)
#else
#define QATZIP_API
#endif

/**
 *****************************************************************************
 *
 *  This API provides access to underlying compression functions in QAT
 *  hardware. The API supports an implementation that provides compression
 *  service in software if all of the required resources are not available
 *  to execute the compression service in hardware.
 *
 *  The API supports threaded applications.
 *  Applications can create threads and each of these threads can invoke the
 *  API defined herein.
 *
 *  For simplicity, initializations and setup function calls are not
 *  required to obtain compression services. If the initialization and setup
 *  functions are not called before compression or decompression requests, then
 *  they will be called with default arguments from within the compression or
 *  decompression functions. This results in several legal calling scenarios,
 *  described below.
 *
 *  Scenario 1 - All functions explicitly invoked by caller, with all arguments provided.
 *
 *  qzInit(&sess, sw_backup);
 *  qzSetupSession(&sess, &params);
 *  qzCompress(&sess, src, &src_len, dest, &dest_len, 1);
 *  qzDecompress(&sess, src, &src_len, dest, &dest_len);
 *  qzTeardownSession(&sess);
 *  qzClose(&sess);
 *
 *
 * Scenario 2 - Initialization function called, setup function not invoked by caller.
 *              This scenario can be used to specify the sw_backup argument to
 *              qzInit.
 *
 *  qzInit(&sess, sw_backup);
 *  qzCompress(&sess, src, &src_len, dest, &dest_len, 1);
 *      calls qzSetupSession(sess, NULL);
 *  qzTeardownSession(&sess);
 *  qzClose(&sess);
 *
 *
 * Scenario 3 - Calling application simply invokes the actual qzCompress functions.
 *
 *  qzCompress(&sess, src, &src_len, dest, &dest_len, 0);
 *      calls qzInit(sess, 1);
 *      calls qzSetupSession(sess, NULL);
 *  qzCompress(&sess, src, &src_len, dest, &dest_len, 1);
 *
 *  Notes: Invoking qzSetupSession with NULL for params sets up a session with
 *  default session attributed, detailed in the function description below.
 *
 *  If an application terminates without invoking tear down and close
 *  functions, process termination will invoke memory and hardware instance
 *  cleanup.
 *
 *  If a thread terminates without invoking tear down and close functions,
 *  memory and hardware are not cleaned up until the application exits.
 *
 *  Additions for QAT 2.0 and beyond platforms though Extending
 *  QzSessionParamsGen3_T, QzDataFormatGen3_T and Using qzSetupSessionGen3
 *  to setup session.
 *  1. Addition of LZ4 and LZ4s
 *  2. Addition of post processing functions for out of LZ4s
 *  3. Compression level up to 12 for LZ4 and LZ4s
 *  4. Support for gzip header with additional compression algorithms
 *
 *****************************************************************************/
/**
 *****************************************************************************
 * @ingroup qatZip
 *      Supported Huffman Headers
 *
 * @description
 *      This enumerated list identifies the Huffman header types
 *    supported by QATzip.
 *
 *****************************************************************************/
typedef enum QzHuffmanHdr_E {
    QZ_DYNAMIC_HDR = 0,
    /**< Full Dynamic Huffman Trees */
    QZ_STATIC_HDR
    /**< Static Huffman Trees */
} QzHuffmanHdr_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Supported memory types
 *
 * @description
 *      This enumerated list identifies memory types supported
 *    by QATzip.
 *
 *****************************************************************************/
typedef enum PinMem_E {
    COMMON_MEM = 0,
    /**< Allocate non-contiguous memory */
    PINNED_MEM
    /**< Allocate contiguous memory */
} PinMem_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Compress or decompress setting
 *
 * @description
 *      This enumerated list identifies the session directions
 *    supported by QATzip. A session can be compress, decompress
 *    or both.
 *
 *****************************************************************************/
typedef enum QzDirection_E {
    QZ_DIR_COMPRESS = 0,
    /**< Session will be used for compression */
    QZ_DIR_DECOMPRESS,
    /**< Session will be used for decompression */
    QZ_DIR_BOTH
    /**< Session will be used for both compression and decompression */
} QzDirection_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Streaming API input and output format
 *
 * @description
 *      This enumerated list identifies the data format supported by
 *    QATzip streaming API. A format can be raw deflate data block, deflate
 *    block wrapped by GZip header and footer, or deflate data block wrapped
 *    by GZip extension header and footer.
 *
 *****************************************************************************/
typedef enum QzDataFormat_E {
    QZ_DEFLATE_4B = 0,
    /**< Data is in raw deflate format with 4 byte header */
    QZ_DEFLATE_GZIP,
    /**< Data is in deflate wrapped by GZip header and footer */
    QZ_DEFLATE_GZIP_EXT,
    /**< Data is in deflate wrapped by GZip extended header and footer */
    QZ_DEFLATE_RAW,
    /**< Data is in raw deflate format */
    QZ_FMT_NUM
} QzDataFormat_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Supported polling mode
 *
 * @description
 *      Specifies whether the instance must be busy polling,
 *    or be periodical polling.
 *
 *****************************************************************************/
typedef enum QzPollingMode_E {
    QZ_PERIODICAL_POLLING = 0,
    /**< No busy polling */
    QZ_BUSY_POLLING,
    /**< busy polling */
} QzPollingMode_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Supported checksum type
 *
 * @description
 *      This enumerated list identifies the checksum type for input/output
 *    data. The format can be CRC32, Adler or none.
 *
 *****************************************************************************/
typedef enum QzCrcType_E {
    QZ_CRC32 = 0,
    /**< CRC32 checksum */
    QZ_ADLER,
    /**< Adler checksum */
    NONE
    /**< No checksum */
} QzCrcType_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Software Component type
 *
 * @description
 *      This enumerated list specifies the type of software that is being
 *    described.
 *
 *****************************************************************************/
typedef enum QzSoftwareComponentType_E {
    QZ_COMPONENT_FIRMWARE = 0,
    QZ_COMPONENT_KERNEL_DRIVER,
    QZ_COMPONENT_USER_DRIVER,
    QZ_COMPONENT_QATZIP_API,
    QZ_COMPONENT_SOFTWARE_PROVIDER
} QzSoftwareComponentType_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip Session Status definitions and function return codes
 *
 * @description
 *      This list identifies valid values for session status and function
 *    return codes.
 *
 *****************************************************************************/
#define QZ_OK                   (0)
/**< Success */
#define QZ_DUPLICATE            (1)
/**< Can not process function again. No failure */
#define QZ_FORCE_SW             (2)
/**< Using SW: Switch to software because of previous block */
#define QZ_PARAMS              (-1)
/**< Invalid parameter in function call */
#define QZ_FAIL                (-2)
/**< Unspecified error */
#define QZ_BUF_ERROR            (-3)
/**< Insufficient buffer error */
#define QZ_DATA_ERROR           (-4)
/**< Input data was corrupted */
#define QZ_TIMEOUT              (-5)
/**< Operation timed out */
#define QZ_INTEG                (-100)
/**< Integrity checked failed */
#define QZ_NO_HW                (11)
/**< Using SW: No QAT HW detected */
#define QZ_NO_MDRV              (12)
/**< Using SW: No memory driver detected */
#define QZ_NO_INST_ATTACH       (13)
/**< Using SW: Could not attach to an instance */
#define QZ_LOW_MEM              (14)
/**< Using SW: Not enough pinned memory */
#define QZ_LOW_DEST_MEM         (15)
/**< Using SW: Not enough pinned memory for dest buffer */
#define QZ_UNSUPPORTED_FMT      (16)
/**< Using SW: QAT device does not support data format */
#define QZ_NONE                 (100)
/**< Device uninitialized */
#define QZ_NOSW_NO_HW           (-101)
/**< Not using SW: No QAT HW detected */
#define QZ_NOSW_NO_MDRV         (-102)
/**< Not using SW: No memory driver detected */
#define QZ_NOSW_NO_INST_ATTACH  (-103)
/**< Not using SW: Could not attach to instance */
#define QZ_NOSW_LOW_MEM         (-104)
/**< Not using SW: not enough pinned memory */
#define QZ_NO_SW_AVAIL          (-105)
/**<Session may require software, but no software is available */
#define QZ_NOSW_UNSUPPORTED_FMT (-116)
/**< Not using SW: QAT device does not support data format */
#define QZ_POST_PROCESS_ERROR   (-117)
/**< Using post process: post process callback encountered an error */
#define QZ_METADATA_OVERFLOW    (-118)
/**< Insufficient memory allocated for metadata */
#define QZ_OUT_OF_RANGE         (-119)
/**< Metadata block_num specified is out of range */
#define QZ_NOT_SUPPORTED        (-200)
/**< Request not supported */

#define QZ_MAX_ALGORITHMS  ((int)255)
#define QZ_DEFLATE         ((unsigned char)8)
/**< used in gzip header to indicate deflate blocks */
/**< and in session params */
#define QZ_LZ4             ((unsigned char)'4')
#define QZ_LZ4_BLOCK       ((unsigned char)'B')
#define QZ_LZ4s            ((unsigned char)'s')
#define QZ_ZSTD            ((unsigned char)'Z')

#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifdef __linux__
#define QZ_MEMCPY(dest, src, dest_sz, src_sz) \
        memcpy((void *)(dest), (void *) (src), (size_t)MIN(dest_sz, src_sz))
#endif
#ifdef _WIN64
#define QZ_MEMCPY(dest, src, dest_sz, src_sz) \
        memcpy_s((void *)(dest), dest_sz, (void *) (src), MIN(dest_sz, src_sz))
#endif

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Post processing callback after LZ4s compression
 *
 * @description
 *        This function will be called in qzCompressCrc for post processing
 *      of lz4s payloads. Function implementation should be provided by user
 *      and comply with this prototype's rules. The input paramter 'dest'
 *      will contain the compressed lz4s format data.
 *
 *      The user callback function should be provided through the
 *      QzSessionParams_T. And set data format of compression to
 *      'QZ_LZ4S_FH', then post-processing will be trigger.
 *
 *      qzCallback's first parameter 'external' can be a customized
 *      compression context which can be setup before QAT qzSetupSession.
 *      It can be provided to QATZip though the 'qzCallback_external'
 *      variable in the QzSessionParams_T structure.
 *
 *      ExtStatus will be embedded into extended return codes when
 *      qzLZ4SCallbackFn return `QZ_POST_PROCESS_ERROR`. See extended return
 *      code section and *Ext API for details.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       external    User context provided through the
 *                              'qzCallback_external' pointer in the
 *                              QzSessionParams_T structure.
 * @param[in]       src         Point to source buffer
 * @param[in,out]   src_len     Length of source buffer. Modified to number
 *                              of bytes consumed
 * @param[in]       dest        Point to destination buffer
 * @param[in,out]   dest_len    Length of destination buffer. Modified
 *                              to length of compressed data when
 *                              function returns
 * @param[in,out]   ExtStatus   'qzCallback' customized error code.
 *
 * @retval QZ_OK                    Function executed successfully
 * @retval QZ_FAIL                  Function did not succeed
 * @retval QZ_PARAMS                params are invalid
 * @retval QZ_POST_PROCESS_ERROR    post processing error
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 * @see
 *      None
 *
 *****************************************************************************/
typedef int (*qzLZ4SCallbackFn)(void *external, const unsigned char *src,
                                unsigned int *src_len, unsigned char *dest,
                                unsigned int *dest_len, int *ExtStatus);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip Session Initialization parameters
 *
 * @description
 *      This structure contains data for initializing a session.
 *
 *****************************************************************************/
typedef struct QzSessionParams_S {
    QzHuffmanHdr_T huffman_hdr;
    /**< Dynamic or Static Huffman headers */
    QzDirection_T direction;
    /**< Compress or decompress */
    QzDataFormat_T data_fmt;
    /**< Deflate, deflate with GZip or deflate with GZip ext */
    unsigned int comp_lvl;
    /**< Compression level 1 to 9 */
    unsigned char comp_algorithm;
    /**< Compress/decompression algorithms */
    unsigned int max_forks;
    /**< Maximum forks permitted in the current thread */
    /**< 0 means no forking permitted */
    unsigned char sw_backup;
    /**< bit field defining SW configuration (see QZ_SW_* definitions) */
    unsigned int hw_buff_sz;
    /**< Default buffer size, must be a power of 2k */
    /**< 4K,8K,16K,32K,64K,128K */
    unsigned int strm_buff_sz;
    /**< Stream buffer size between [1K .. 2M - 5K] */
    /**< Default strm_buf_sz equals to hw_buff_sz */
    unsigned int input_sz_thrshold;
    /**< Default threshold of compression service's input size */
    /**< for sw failover, if the size of input request is less */
    /**< than the threshold, QATzip will route the request */
    /**< to software */
    unsigned int req_cnt_thrshold;
    /**< Set between 1 and NUM_BUFF, default NUM_BUFF */
    /**< NUM_BUFF is defined in qatzip_internal.h */
    unsigned int wait_cnt_thrshold;
    /**< When previous try failed, wait for specific number of calls */
    /**< before retrying to open device. Default threshold is 8 */
#ifdef ERR_INJECTION
    void *fbError;
    void *fbErrorCurr;
    /* Linked list for simulated errors from HW */
#endif
} QzSessionParams_T;

typedef struct QzSessionParamsCommon_S {
    QzDirection_T direction;
    /**< Compress or decompress */
    unsigned int comp_lvl;
    /**< Compression level 1 to 9 */
    unsigned char comp_algorithm;
    /**< Compress/decompression algorithms */
    unsigned int max_forks;
    /**< Maximum forks permitted in the current thread */
    /**< 0 means no forking permitted */
    unsigned char sw_backup;
    /**< bit field defining SW configuration (see QZ_SW_* definitions) */
    unsigned int hw_buff_sz;
    /**< Default buffer size, must be a power of 2k */
    /**< 4K,8K,16K,32K,64K,128K */
    unsigned int strm_buff_sz;
    /**< Stream buffer size between [1K .. 2M - 5K] */
    /**< Default strm_buf_sz equals to hw_buff_sz */
    unsigned int input_sz_thrshold;
    /**< Default threshold of compression service's input size */
    /**< for sw failover, if the size of input request is less */
    /**< than the threshold, QATzip will route the request */
    /**< to software */
    unsigned int req_cnt_thrshold;
    /**< Set between 1 and NUM_BUFF, default NUM_BUFF */
    /**< NUM_BUFF is defined in qatzip_internal.h */
    unsigned int wait_cnt_thrshold;
    /**< When previous try failed, wait for specific number of calls */
    /**< before retrying to open device. Default threshold is 8 */
    QzPollingMode_T polling_mode;
    /**< 0 means no busy polling, 1 means busy polling */
    unsigned int is_sensitive_mode;
    /**< 0 means disable sensitive mode, 1 means enable sensitive mode*/
#ifdef ERR_INJECTION
    void *fbError;
    void *fbErrorCurr;
    /* Linked list for simulated errors from HW */
#endif
} QzSessionParamsCommon_T;

typedef struct QzSessionParamsDeflate_S {
    QzSessionParamsCommon_T common_params;
    QzHuffmanHdr_T huffman_hdr;
    /**< Dynamic or Static Huffman headers */
    QzDataFormat_T data_fmt;
    /**< Deflate, deflate with GZip or deflate with GZip ext */
} QzSessionParamsDeflate_T;

typedef struct QzSessionParamsLZ4_S {
    QzSessionParamsCommon_T common_params;
} QzSessionParamsLZ4_T;

typedef struct QzSessionParamsLZ4S_S {
    QzSessionParamsCommon_T common_params;
    qzLZ4SCallbackFn qzCallback;
    /**< post processing callback for zstd compression*/
    void *qzCallback_external;
    /**< An opaque pointer provided by the user to be passed */
    /**< into qzCallback during post processing*/
    unsigned int lz4s_mini_match;
    /**< Set lz4s dictionary mini match, which would be 3 or 4 */
    /**< Default value is 3 */
} QzSessionParamsLZ4S_T;

typedef struct QzSessionParamsDeflateExt_S {
    QzSessionParamsDeflate_T deflate_params;
    /* stop decompression at end the stream, default is 0. */
    unsigned char stop_decompression_stream_end;
    /**< zlib format, default 0 if zlib format value will be 1*/
    unsigned char zlib_format;
} QzSessionParamsDeflateExt_T;

#define QZ_HUFF_HDR_DEFAULT          QZ_DYNAMIC_HDR
#define QZ_DIRECTION_DEFAULT         QZ_DIR_BOTH
#define QZ_DATA_FORMAT_DEFAULT       QZ_DEFLATE_GZIP_EXT
#define QZ_COMP_LEVEL_DEFAULT        1
#define QZ_COMP_ALGOL_DEFAULT        QZ_DEFLATE
#define QZ_POLL_SLEEP_DEFAULT        10
#define QZ_MAX_FORK_DEFAULT          3
#define QZ_SW_BACKUP_DEFAULT         1
#define QZ_HW_BUFF_SZ                (64*1024)
#define QZ_HW_BUFF_SZ_Gen3           (1*1024*1024)
#define QZ_HW_BUFF_MIN_SZ            (1*1024)
#define QZ_HW_BUFF_MAX_SZ            (512*1024)
#define QZ_HW_BUFF_MAX_SZ_Gen3       (2*1024*1024*1024U)
#define QZ_STRM_BUFF_SZ_DEFAULT      QZ_HW_BUFF_SZ
#define QZ_STRM_BUFF_MIN_SZ          (1*1024)
#define QZ_STRM_BUFF_MAX_SZ          (2*1024*1024 - 5*1024)
#define QZ_COMP_THRESHOLD_DEFAULT    1024
#define QZ_COMP_THRESHOLD_MINIMUM    128
#define QZ_REQ_THRESHOLD_MINIMUM     1
#define QZ_REQ_THRESHOLD_MAXIMUM     NUM_BUFF
#define QZ_REQ_THRESHOLD_DEFAULT     QZ_REQ_THRESHOLD_MAXIMUM
#define QZ_WAIT_CNT_THRESHOLD_DEFAULT 8
#define QZ_DEFLATE_COMP_LVL_MINIMUM      (1)
#define QZ_DEFLATE_COMP_LVL_MAXIMUM      (9)
#define QZ_DEFLATE_COMP_LVL_MAXIMUM_Gen3 (12)
#define QZ_LZS_COMP_LVL_MINIMUM          (1)
#define QZ_LZS_COMP_LVL_MAXIMUM          (12)
#define QZ_AUTO_SELECT_NUMA_NODE         (-1)

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip Session software configuration settings
 *
 * @description
 *      The following definitions can be used with the sw_backup variable in
 *      structs and functions to configure the session
 *
 *      QZ_ENABLE_SOFTWARE_BACKUP          Congifure session with software
 *                                         fallback
 *
 *      QZ_ENABLE_SOFTWARE_ONLY_EXECUTION  Configure session to only use
 *                                         software
 *****************************************************************************/
#define QZ_SW_BACKUP_BIT_POSITION   (0)
#define QZ_SW_FORCESW_BIT_POSITION  (1)

#define QZ_ENABLE_SOFTWARE_BACKUP(_BackupVariable) \
        (_BackupVariable |= (1 << QZ_SW_BACKUP_BIT_POSITION))
/**< SW backup/fallback enabled */
#define QZ_ENABLE_SOFTWARE_ONLY_EXECUTION(_BackupVariable) \
        (_BackupVariable |= (1 << QZ_SW_FORCESW_BIT_POSITION))
/**< Force SW to perform all compression/decompression operations */

#define QZ_DISABLE_SOFTWARE_BACKUP(_BackupVariable) \
        (_BackupVariable &= ~(1 << QZ_SW_BACKUP_BIT_POSITION))
/**< SW backup/fallback disabled */
#define QZ_DISABLE_SOFTWARE_ONLY_EXECUTION(_BackupVariable) \
        (_BackupVariable &= ~(1 << QZ_SW_FORCESW_BIT_POSITION))
/**< Disable SW only compression/decompression operations*/

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip Extended return information
 *
 * @description
 *      The following definitions can be used with the extended return
 *      values.
 *
 *      QZ_SW_EXECUTION indicates if a request for services was performed in
 *      software.
 *
 *      QZ_HW_TIMEOUT indicates if a request to hardware was timed out.
 *
 *      If set in the extended return value, QZ_POST_PROCESS_FAIL indicates
 *      post processing of the LZ4s compressed data has failed.
 *****************************************************************************/
#define QZ_SW_EXECUTION_BIT           (4)
#define QZ_SW_EXECUTION_MASK         (1 << QZ_SW_EXECUTION_BIT)
#define QZ_SW_EXECUTION(ret, ext_rc) \
     (!ret && (ext_rc & QZ_SW_EXECUTION_MASK))

#define QZ_TIMEOUT_BIT                (8)
#define QZ_TIMEOUT_MASK              (1 << QZ_TIMEOUT_BIT)
#define QZ_HW_TIMEOUT(ret, ext_rc)   \
     (!ret && (ext_rc & QZ_TIMEOUT_MASK))

#define QZ_POST_PROCESS_FAIL_BIT      (10)
#define QZ_POST_PROCESS_FAIL_MASK    (1 << QZ_POST_PROCESS_FAIL_BIT)
#define QZ_POST_PROCESS_FAIL(ret, ext_rc)   \
     (ret && (ext_rc & QZ_POST_PROCESS_FAIL_MASK))

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip Session opaque data storage
 *
 * @description
 *      This structure contains a pointer to a structure with
 *    session state.
 *
 *****************************************************************************/
typedef struct QzSession_S {
    signed long int hw_session_stat;
    /**< Filled in during initialization, session startup and decompression */
    int thd_sess_stat;
    /**< Note process compression and decompression thread state */
    void *internal;
    /**< Session data is opaque to outside world */
    unsigned long total_in;
    /**< Total processed input data length in this session */
    unsigned long total_out;
    /**< Total output data length in this session */
} QzSession_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip status structure
 *
 * @description
 *      This structure contains data relating to the status of QAT on the
 *    platform.
 *
 *****************************************************************************/
typedef struct QzStatus_S {
    unsigned short int qat_hw_count;
    /**< From PCI scan */
    unsigned char qat_service_init;
    /**< Check if the available services have been initialized */
    unsigned char qat_mem_drvr;
    /**< 1 if /dev/qat_mem exists */
    /**< 2 if /dev/qat_mem has been opened */
    /**< 0 otherwise */
    unsigned char qat_instance_attach;
    /**< Is this thread/g_process properly attached to an Instance? */
    unsigned long int memory_alloced;
    /**< Amount of memory allocated by this thread/process */
    unsigned char using_huge_pages;
    /**< Are memory slabs coming from huge pages? */
    signed long int hw_session_status;
    /**< One of QATzip Session Status */
    unsigned char algo_sw[QZ_MAX_ALGORITHMS];
    /**< Support software algorithms */
    unsigned char algo_hw[QZ_MAX_ALGORITHMS];
    /**< Count of hardware devices supporting algorithms */
} QzStatus_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip software version structure
 *
 * @description
 *      This structure contains data relating to the versions of a QATZip or a
 *    subcomponent of this library platform.
 *
 *****************************************************************************/
#define QZ_MAX_STRING_LENGTH 64
typedef struct QzSoftwareVersionInfo_S {
    QzSoftwareComponentType_T component_type;
    unsigned char component_name[QZ_MAX_STRING_LENGTH];
    unsigned int major_version;
    unsigned int minor_version;
    unsigned int patch_version;
    unsigned int build_number;
    unsigned char reserved[52];
} QzSoftwareVersionInfo_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip CRC64 configuration structure
 *
 * @description
 *      This structure contains data relating to configuration of the sessions
 *   CRC64 functionality.Session defaults to using ECMA-182 Normal on creation.
 *
 *****************************************************************************/
typedef struct QzCrc64Config_S {
    uint64_t polynomial;
    /**< Polynomial used for CRC64 calculation. Default 0x42F0E1EBA9EA3693 */
    uint64_t initial_value;
    /**< Defaults to 0x0000000000000000 */
    uint32_t reflect_in;
    /**< Reflect bit order before CRC calculation. Default 0 */
    uint32_t reflect_out;
    /**< Reflect bit order after CRC calculation.Default 0 */
    uint64_t xor_out;
    /**< Defaults to 0x0000000000000000 */
} QzCrc64Config_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip CRC32 configuration structure
 *
 * @description
 *      This structure contains data relating to configuration of the session's
 *   CRC32 functionality.
 *
 *****************************************************************************/
typedef struct QzCrc32Config_S {
    uint32_t polynomial;
    /**< Polynomial used for CRC32 calculation. */
    uint32_t initial_value;
    /**< Initial CRC32 value. */
    uint32_t reflect_in;
    /**< Reflect bit order before CRC calculation. */
    uint32_t reflect_out;
    /**< Reflect bit order after CRC calculation. */
    uint32_t xor_out;
    /**< XOR out value for CRC32 calculation. */
} QzCrc32Config_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip crc structure's valid_flags bitmap
 *
 * @description
 *      The following definitions can be used with the crc structure's
 *      valid_flags.
 *
 *      QZ_INPUT_CRC_VALID_MASK indicates if input crc feild is valid
 *      QZ_OUTPUT_CRC_VALID_MASK indicates if output crc feild is valid
 *      QZ_CRC32_VALID_MASK indicates if crc type is crc32 in union
 *      QZ_CRC64_VALID_MASK indicates if crc type is crc64 in union
 *
 *****************************************************************************/

#define QZ_INPUT_CRC_VALID_BIT             (4)
#define QZ_INPUT_CRC_VALID_MASK            (1 << QZ_INPUT_CRC_VALID_BIT)
#define QZ_OUTPUT_CRC_VALID_BIT            (8)
#define QZ_OUTPUT_CRC_VALID_MASK           (1 << QZ_OUTPUT_CRC_VALID_BIT)
#define QZ_CRC32_VALID_BIT                 (12)
#define QZ_CRC32_VALID_MASK                (1 << QZ_CRC32_VALID_BIT)
#define QZ_CRC64_VALID_BIT                 (16)
#define QZ_CRC64_VALID_MASK                (1 << QZ_CRC64_VALID_BIT)

#define QZ_CRC32_VALID(valid_flags) \
        ((valid_flags & QZ_CRC32_VALID_MASK) && !(valid_flags & QZ_CRC64_VALID_MASK))

#define QZ_CRC64_VALID(valid_flags) \
        ((valid_flags & QZ_CRC64_VALID_MASK) && !(valid_flags & QZ_CRC32_VALID_MASK))

#define QZ_INPUT_CRC_VALID(valid_flags) \
        (valid_flags & QZ_INPUT_CRC_VALID_MASK)

#define QZ_OUTPUT_CRC_VALID(valid_flags) \
        (valid_flags & QZ_OUTPUT_CRC_VALID_BIT)

/**
 *****************************************************************************
 * @ingroup qatZip
 *      crc structure in QzResult_T
 *
 * @description
 *      This structure include the crc input/output value data.
 *     And crc calculate status, whether input/output valid.
 *
 *****************************************************************************/
typedef struct QzCrcResult_S {
    int status;
    /**< indicate checksum compute's status */
    uint32_t valid_flags;
    /**< indicate whether input and output crc’s are valid */
    union {
        uint32_t *crc_32;
        uint64_t *crc_64;
    } in_crc;
    /**< indicate input crc value */
    union {
        uint32_t *crc_32;
        uint64_t *crc_64;
    } out_crc;
    /**< indicate output crc value */
} QzCrcResult_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QzResult structure for compress2/decompress2 API
 *
 * @description
 *      This structure contains status, custom callback params for async
 *     callback function, src_len for input buf length and dest_len for
 *     output buf length, and extend return code for post processing and
 *     CRC input/output result.
 *
 *****************************************************************************/
typedef struct QzResult_S {
    int status;
    /**< Status of the offload operation, output only */
    void *cb_tag;
    /**< Opaque to QATzip, Users could uses this pointer for tracking      */
    /**< customer side job structures, Most likely, the caller could track */
    /**< other variables including the pointers to the src and dest in     */
    /**< async mode, could set to NULL */
    unsigned int src_len;
    /**< Length of source buffer. Modified to number of bytes consumed */
    unsigned int dest_len;
    /**< Length of destination buffer. Modified to length of produced */
    /**< data when function returns */
    uint64_t ext_rc;
    /**< Extended return codes, output only */
    QzCrcResult_T *crc;
    /**< crc result include input/output, could be NULL */
    void *extension_result;
    /**< This pointer is for extensibility of QzResult, please don't use */
    /**< this pointer and always set this pointer as NULL */
} QzResult_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *
 * @description
 *      This callback function will be called in asynchronous compression and
 *      decompression API. Function implementation should be provided by user
 *      and comply with this prototype's rules.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in,out]  res      it's same as compress2/decompress2 API's last
 *                          parameters, include offloading result.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      None
 * @see
 *      None
 *
 *****************************************************************************/
typedef int (*qzAsyncCallbackFn)(QzResult_T *res);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip pointer to opaque metadata.
 *
 * @description
 *      The opaque pointer to metadata.
 *
 *****************************************************************************/
typedef void *QzMetadataBlob_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip log verbosity level
 *
 * @description
 *      This is an emum for qatzip log verbosity level
 *
 *****************************************************************************/
typedef enum QzLogLevel_E {
    LOG_NONE = 0,
    LOG_FATAL,
    LOG_ERROR,
    LOG_WARNING,
    LOG_INFO,
    LOG_DEBUG1,
    LOG_DEBUG2,
    LOG_DEBUG3
} QzLogLevel_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Set qatzip log verbosity level
 *
 * @description
 *      Set qatzip log verbosity level
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]   level   set log verbosity level
 * @retval              Old log verbosity level
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      None
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API QzLogLevel_T qzSetLogLevel(QzLogLevel_T level);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Initialize QAT hardware
 *
 * @description
 *      This function initializes the QAT hardware.
 *    This function is optional in the function calling sequence. If
 *    desired, this call can be made to avoid latency impact during the
 *    first call to qzDecompress or qzCompress, or to set the sw_backup
 *    parameter explicitly.
 *    The input parameter sw_backup specifies the behavior of the function
 *    and that of the functions called with the same session in the event
 *    there are insufficient resources to establish a QAT based compression
 *    or decompression session.
 *
 *    The required resources include access to the QAT hardware, contiguous
 *    pinned memory for mapping the hardware rings, and contiguous
 *    pinned memory for buffers.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      This function will:
 *        1) start the user space driver if necessary
 *        2) allocate all hardware instances available
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess           Session handle
 *                                 (pointer to opaque instance and
 *                                 session data.)
 * @param[in]       sw_backup      see QZ_SW_* definitions for expected behavior
 *
 * @retval QZ_OK                   Function executed successfully. A hardware
 *                                 or software instance has been allocated to
 *                                 the calling process/thread
 * @retval QZ_DUPLICATE            This process/thread already has a hardware
 *                                 instance
 * @retval QZ_PARAMS               *sess is NULL
 * @retval QZ_NOSW_NO_HW           No hardware and no software session being
 *                                 established
 * @retval QZ_NOSW_NO_MDRV         No memory driver. No software session
 *                                 established
 * @retval QZ_NOSW_NO_INST_ATTACH  No instance available
 *                                 No software session established
 * @retval QZ_NOSW_LOW_MEM         Not enough pinned memory available
 *                                 No software session established
 * @retval QZ_UNSUPPORTED_FMT           No support for requested algorithm;
 *                                      using software
 * @retval QZ_NOSW_UNSUPPORTED_FMT      No support for requested algorithm;
 *                                      No software session established
 * @retval QZ_NO_SW_AVAIL          No software is available. This will be
 *                                 returned when sw_backup is set but the
 *                                 session does not support software operations
 *                                 or software fallback is unavailable
 *                                 to the application.
 *
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzInit(QzSession_T *sess,  unsigned char sw_backup);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Initialize a QATzip session
 *
 * @description
 *      This function establishes a QAT session. This involves associating
 *    a hardware instance to the session, allocating buffers. If all of
 *    these activities can not be completed successfully, then this function
 *    will set up a software based session of param->sw_backup that is set to 1.
 *
 *    Before this function is called, the hardware must have been
 *    successfully started via qzInit.
 *
 *    If *sess includes an existing hardware or software session, then
 *    QZ_DUPLICATE will be returned without modifying the existing session.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess           Session handle
 *                                 (pointer to opaque instance and session data)
 * @param[in]       params         Parameters for session
 *
 *
 * @retval QZ_OK                   Function executed successfully. A hardware
 *                                 or software based compression session has been
 *                                 created
 * @retval QZ_DUPLICATE            *sess includes an existing hardware or
 *                                 software session
 * @retval QZ_PARAMS               *sess is NULL or member of params is invalid
 * @retval QZ_NOSW_NO_HW           No hardware and no sw session being
 *                                 established
 * @retval QZ_NOSW_NO_MDRV         No memory driver. No software session
 *                                 established
 * @retval QZ_NOSW_NO_INST_ATTACH  No instance available
 *                                 No software session established
 * @retval QZ_NO_LOW_MEM           Not enough pinned memory available
 *                                 No software session established
 * @retval QZ_UNSUPPORTED_FMT           No support for requested algorithm;
 *                                      using software
 * @retval QZ_NOSW_UNSUPPORTED_FMT      No support for requested algorithm;
 *                                      No software session established
 * @retval QZ_NO_SW_AVAIL          No software is available. This may returned
 *                                 when sw_backup is set to 1 but the session
 *                                 does not support software backup or software
 *                                 backup is unavailable to the application.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzSetupSession(QzSession_T *sess,  QzSessionParams_T *params);

QATZIP_API int qzSetupSessionDeflate(QzSession_T *sess,
                                     QzSessionParamsDeflate_T *params);

QATZIP_API int qzSetupSessionLZ4(QzSession_T *sess,
                                 QzSessionParamsLZ4_T *params);

QATZIP_API int qzSetupSessionLZ4S(QzSession_T *sess,
                                  QzSessionParamsLZ4S_T *params);

QATZIP_API int qzSetupSessionDeflateExt(QzSession_T *sess,
                                        QzSessionParamsDeflateExt_T *params);
/**
 *****************************************************************************
 * @ingroup qatZip
 *      Compress a buffer
 *
 * @description
 *      This function will compress a buffer if either a hardware based
 *    session or a software based session is available. If no session has
 *    been established - as indicated by the contents of *sess - then this
 *    function will attempt to set up a session using qzInit and qzSetupSession.
 *
 *    The resulting compressed block of data will be composed of one or more
 *    gzip blocks, as per RFC 1952.
 *
 *    This function will place completed compression blocks in the output
 *    buffer.
 *
 *    The caller must check the updated src_len. This value will be the
 *    number of consumed bytes on exit. The calling API may have to
 *    process the destination buffer and call again.
 *
 *    The parameter dest_len will be set to the number of bytes produced in
 *    the destination buffer. This value may be zero if no data was produced
 *    which may occur if the consumed data is retained internally. A
 *    possible reason for this may be small amounts of data in the src
 *    buffer.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess     Session handle
 *                           (pointer to opaque instance and session data)
 * @param[in]       src      Point to source buffer
 * @param[in,out]   src_len  Length of source buffer. Modified to number
 *                           of bytes consumed
 * @param[in]       dest     Point to destination buffer
 * @param[in,out]   dest_len Length of destination buffer. Modified
 *                           to length of compressed data when
 *                           function returns
 * @param[in]       last     1 for 'No more data to be compressed'
 *                           0 for 'More data to be compressed'
 * @param[in,out]   ext_rc   qzCompressExt only.
 *                           If not NULL, ext_rc point to a location where
 *                           extended return codes may be returned. See
 *                           extended return code section for details.
 *                           if NULL, no extended information will be
 *                           provided.
 *
 * @retval QZ_OK             Function executed successfully
 * @retval QZ_FAIL           Function did not succeed
 * @retval QZ_PARAMS         *sess is NULL or member of params is invalid
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzCompress(QzSession_T *sess, const unsigned char *src,
                          unsigned int *src_len, unsigned char *dest,
                          unsigned int *dest_len, unsigned int last);

QATZIP_API int qzCompressExt(QzSession_T *sess, const unsigned char *src,
                             unsigned int *src_len, unsigned char *dest,
                             unsigned int *dest_len, unsigned int last,
                             uint64_t *ext_rc);


/**
 *****************************************************************************
 * @ingroup qatZip
 *      Compress a buffer and return the CRC checksum
 *
 * @description
 *      This function will compress a buffer if either a hardware based
 *    session or a software based session is available. If no session has been
 *    established - as indicated by the contents of *sess - then this function
 *    will attempt to set up a session using qzInit and qzSetupSession.
 *
 *    The resulting compressed block of data will be composed of one or more
 *    gzip blocks, as per RFC 1952.
 *
 *    This function will place completed compression blocks in the output
 *    buffer and put CRC32 or CRC64 checksum for compressed input data in
 *    the user provided buffer *crc.
 *
 *    The caller must check the updated src_len. This value will be the
 *    number of consumed bytes on exit. The calling API may have to
 *    process the destination buffer and call again.
 *
 *    The parameter dest_len will be set to the number of bytes produced in
 *    the destination buffer. This value may be zero if no data was produced
 *    which may occur if the consumed data is retained internally. A
 *    possible reason for this may be small amounts of data in the src
 *    buffer.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess     Session handle
 *                           (pointer to opaque instance and session data)
 * @param[in]       src      Point to source buffer
 * @param[in,out]   src_len  Length of source buffer. Modified to number
 *                           of bytes consumed
 * @param[in]       dest     Point to destination buffer
 * @param[in,out]   dest_len Length of destination buffer. Modified
 *                           to length of compressed data when
 *                           function returns
 * @param[in]       last     1 for 'No more data to be compressed'
 *                           0 for 'More data to be compressed'
 * @param[in,out]   crc      Pointer to CRC32 or CRC64 checksum buffer
 * @param[in,out]   ext_rc   qzCompressCrcExt or qzCompressCrc64Ext only.
 *                           If not NULL, ext_rc point to a location where
 *                           extended return codes may be returned. See
 *                           extended return code section for details.
 *                           if NULL, no extended information will be
 *                           provided.
 *
 * @retval QZ_OK             Function executed successfully
 * @retval QZ_FAIL           Function did not succeed
 * @retval QZ_PARAMS         *sess is NULL or member of params is invalid
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzCompressCrc(QzSession_T *sess,
                             const unsigned char *src,
                             unsigned int *src_len,
                             unsigned char *dest,
                             unsigned int *dest_len,
                             unsigned int last,
                             unsigned long *crc);

QATZIP_API int qzCompressCrcExt(QzSession_T *sess,
                                const unsigned char *src,
                                unsigned int *src_len,
                                unsigned char *dest,
                                unsigned int *dest_len,
                                unsigned int last,
                                unsigned long *crc,
                                uint64_t *ext_rc);

QATZIP_API int qzCompressCrc64(QzSession_T *sess,
                               const unsigned char *src,
                               unsigned int *src_len,
                               unsigned char *dest,
                               unsigned int *dest_len,
                               unsigned int last,
                               uint64_t *crc);

QATZIP_API int qzCompressCrc64Ext(QzSession_T *sess,
                                  const unsigned char *src,
                                  unsigned int *src_len,
                                  unsigned char *dest,
                                  unsigned int *dest_len,
                                  unsigned int last,
                                  uint64_t *crc,
                                  uint64_t *ext_rc);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Compress a buffer and write metadata for each compressed block into
 *      the opaque metadata structure.
 *
 * @description
 *      This function will compress a buffer if either a hardware based
 *      session or a software based session is available. If no session has
 *      been established - as indicated by the contents of *sess - then this
 *      function will attempt to set up a session using qzInit and
 *      qzSetupSession.
 *
 *      This function will place completed compression blocks in the output
 *      buffer.
 *
 *      The caller must check the updated src_len. This value will be the
 *      number of consumed bytes on exit. The calling API may have to
 *      process the destination buffer and call again.
 *
 *      The parameter dest_len will be set to the number of bytes produced in
 *      the destination buffer. This value may be zero if no data was produced
 *      which may occur if the consumed data is retained internally. A
 *      possible reason for this may be small amounts of data in the src
 *      buffer.
 *
 *      The metadata for each compressed block will be written into the opaque
 *      metadata structure specified as function param metadata.
 *
 *      comp_thrshold specifies compression threshold of a block.
 *      If compressed size of the block is > comp_thrshold, the
 *      compression function shall copy the uncompressed data to the output
 *      buffer and set the size of the block in the metadata to the size of the
 *      uncompressed block. If the compressed size of the block is <=
 *      comp_thrshold, the compressed data will be copied to the output buffer
 *      and the compressed size will be set in the metadata.
 *
 *      hw_buff_sz_override specifies the data size to be used for the each
 *      compression operation. It overrides the hw_buff_sz parameter specified
 *      at session creation. If 0 is provided for this parameter, then the
 *      hw_buff_sz specified at session creation will be used. Memory for the
 *      opaque metadata structure should be allocated based on the hw_buff_sz
 *      or the hw_buff_sz_override that is used for the compression operation.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess                Session handle
 *                                      (pointer to opaque instance and
 *                                      session data)
 * @param[in]       src                 Point to source buffer.
 * @param[in,out]   src_len             Length of source buffer. Modified to
 *                                      number of bytes consumed.
 * @param[in]       dest                Point to destination buffer.
 * @param[in,out]   dest_len            Length of destination buffer. Modified
 *                                      to length of compressed data when
 *                                      function returns.
 * @param[in]       last                1 for 'No more data to be compressed'
 *                                      0 for 'More data to be compressed'
 * @param[in,out]   ext_rc              If not NULL, ext_rc point to a location
 *                                      where extended return codes may be
 *                                      returned. See extended return code
 *                                      section for details. if NULL, no
 *                                      extended information will be provided.
 * @param[in,out]   metadata            Pointer to opaque metadata.
 * @param[in]       hw_buff_sz_override Data size to be used for compression.
 * @param[in]       comp_thrshold       Compressed block threshold.
 *
 * @retval QZ_OK                        Function executed successfully
 * @retval QZ_FAIL                      Function did not succeed
 * @retval QZ_PARAMS                    *sess or metadata is NULL or Member of
 *                                      params is invalid, hw_buff_sz_override
 *                                      is invalid data size.
 * @retval QZ_METADATA_OVERFLOW         Unable to populate metadata due to
 *                                      insufficient memory allocated.
 * @retval QZ_NOT_SUPPORTED             Compression with metadata is not
 *                                      supported with given algorithm
 *                                      or format.
 * @retval QZ_NOSW_NO_HW                Function did not find an installed
 *                                      kernel driver or software provider.
 * @retval QZ_NOSW_NO_INST_ATTACH       No instance available.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzCompressWithMetadataExt(QzSession_T *sess,
        const unsigned char *src,
        unsigned int *src_len,
        unsigned char *dest,
        unsigned int *dest_len,
        unsigned int last,
        uint64_t *ext_rc,
        QzMetadataBlob_T metadata,
        uint32_t hw_buff_sz_override,
        uint32_t comp_thrshold);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Compress a buffer with asynchronous or synchronous model
 *
 * @description
 *      These functions has the same compression ability as "qzCompress",
 *      but with asynchronous or synchronous model.
 *
 *      If user provide the callback function(callback is not NULL), it would
 *      work as asynchronous model. Otherwise, it would work as synchronous
 *      model, just like "qzCompress".
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      No
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess       Session handle
 *                             (pointer to opaque instance and session data)
 * @param[in]       src        Pointer to source buffer.
 * @param[in]       dest       Pointer to destination buffer.
 * @param[in]       callback   User-defined callback Function to be called upon
 *                             completion of the compression operation. it could
 *                             be NULL, then it's an synchronous call, otherwise,
 *                             it's asynchronous call.
 * @param[in,out]   qzResults  Pointer to QzResult, It have to allocate by user.
 *
 * @retval QZ_OK               Request submit successfully.
 * @retval QZ_FAIL             Request submit failed.
 * @retval QZ_PARAMS           *sess is NULL or member of params is invalid.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      None
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzCompress2(QzSession_T *sess, const unsigned char *src,
                           unsigned char *dest, qzAsyncCallbackFn callback,
                           QzResult_T *qzResults);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Decompress a buffer
 *
 * @description
 *      This function will decompress a buffer if either a hardware based
 *    session or a software based session is available. If no session has been
 *    established - as indicated by the contents of *sess - then this function
 *    will attempt to set up a session using qzInit and qzSetupSession.
 *
 *    The input compressed block of data will be composed of one or more
 *    gzip blocks, as per RFC 1952.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]     sess      Session handle
 *                          (pointer to opaque instance and session data)
 * @param[in]     src       Point to source buffer
 * @param[in]     src_len   Length of source buffer. Modified to
 *                          length of processed compressed data
 *                          when function returns
 * @param[in]      dest     Point to destination buffer
 * @param[in,out]  dest_len Length of destination buffer. Modified
 *                          to length of decompressed data when
 *                          function returns
 * @param[in,out]   ext_rc  qzDecompressExt only.
 *                          If not NULL, ext_rc point to a location where
 *                          extended return codes may be returned. See
 *                          extended return code section for details.
 *                          if NULL, no extended information will be
 *                          provided.
 *
 * @retval QZ_OK            Function executed successfully
 * @retval QZ_FAIL          Function did not succeed
 * @retval QZ_PARAMS        *sess is NULL or member of params is invalid
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzDecompress(QzSession_T *sess, const unsigned char *src,
                            unsigned int *src_len, unsigned char *dest,
                            unsigned int *dest_len);

QATZIP_API int qzDecompressExt(QzSession_T *sess, const unsigned char *src,
                               unsigned int *src_len, unsigned char *dest,
                               unsigned int *dest_len, uint64_t *ext_rc);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Decompress a buffer and return the CRC checksum
 *
 * @description
 *      This function will decompress a buffer if either a hardware based
 *    session or a software based session is available. If no session has been
 *    established - as indicated by the contents of *sess - then this function
 *    will attempt to set up a session using qzInit and qzSetupSession.
 *
 *    This function will place completed decompression chunks in the output
 *    buffer and put the CRC32 or CRC64 checksum for compressed input data in
 *    the user provided buffer *crc.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]     sess      Session handle
 *                          (pointer to opaque instance and session data)
 * @param[in]     src       Point to source buffer
 * @param[in]     src_len   Length of source buffer. Modified to
 *                          length of processed compressed data
 *                          when function returns
 * @param[in]      dest     Point to destination buffer
 * @param[in,out]  dest_len Length of destination buffer. Modified
 *                          to length of decompressed data when
 *                          function returns
 * @param[in,out]  crc      Pointer to CRC32 or CRC64 checksum buffer
 * @param[in,out]  ext_rc   qzDecompressCrcExt or qzDecompressCrc64Ext only.
 *                          If not NULL, ext_rc point to a location where
 *                          extended return codes may be returned. See
 *                          extended return code section for details.
 *                          if NULL, no extended information will be
 *                          provided.
 *
 * @retval QZ_OK            Function executed successfully
 * @retval QZ_FAIL          Function did not succeed
 * @retval QZ_PARAMS        *sess is NULL or member of params is invalid
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzDecompressCrc(QzSession_T *sess,
                               const unsigned char *src,
                               unsigned int *src_len,
                               unsigned char *dest,
                               unsigned int *dest_len,
                               unsigned long *crc);

QATZIP_API int qzDecompressCrcExt(QzSession_T *sess,
                                  const unsigned char *src,
                                  unsigned int *src_len,
                                  unsigned char *dest,
                                  unsigned int *dest_len,
                                  unsigned long *crc,
                                  uint64_t *ext_rc);

QATZIP_API int qzDecompressCrc64(QzSession_T *sess,
                                 const unsigned char *src,
                                 unsigned int *src_len,
                                 unsigned char *dest,
                                 unsigned int *dest_len,
                                 uint64_t *crc);

QATZIP_API int qzDecompressCrc64Ext(QzSession_T *sess,
                                    const unsigned char *src,
                                    unsigned int *src_len,
                                    unsigned char *dest,
                                    unsigned int *dest_len,
                                    uint64_t *crc,
                                    uint64_t *ext_rc);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Decompress a buffer with metadata.
 *
 * @description
 *      This function will decompress a buffer if either a hardware based
 *      session or a software based session is available.
 *      If no session has been established - as indicated by the content
 *      of *sess - then this function will attempt to set up a session using
 *      qzInit and qzSetupSession.
 *
 *      The metadata function parameter specifies metadata of compressed file
 *      which can be used for regular or parallel decompression.
 *
 *      hw_buff_sz_override specifies the data size to be used for the each
 *      decompression operation. It overrides the hw_buff_sz parameter specified
 *      at session creation. If 0 is provided for this parameter, then the
 *      hw_buff_sz specified at session creation will be used. Memory for the
 *      opaque metadata structure should be allocated based on the hw_buff_sz
 *      or the hw_buff_sz_override that is used for the compression operation.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess                Session handle
 *                                      (pointer to opaque instance and session
 data)
 * @param[in]       src                 Point to source buffer
 * @param[in]       src_len             Length of source buffer. Modified to
 *                                      length of processed compressed data
 *                                      when function returns
 * @param[in]       dest                Point to destination buffer
 * @param[in,out]   dest_len            Length of destination buffer. Modified
 *                                      to length of decompressed data when
 *                                      function returns
 * @param[in,out]   ext_rc              If not NULL, ext_rc points to a location
 *                                      where extended return codes may be
 *                                      returned. See extended return code
 *                                      section for details.
 *                                      if NULL, no extended information will be
 *                                      provided.
 * @param[in]       metadata            Pointer to opaque metadata.
 * @param[in]       hw_buff_sz_override Expected size of decompressed block.
 *
 * @retval QZ_OK                        Function executed successfully.
 * @retval QZ_FAIL                      Function did not succeed.
 * @retval QZ_PARAMS                    *sess or metadata is NULL or Member of
 *                                      params is invalid, hw_buff_sz_override
 *                                      is invalid data size.
 * @retval QZ_METADATA_OVERFLOW         Unable to populate metadata due to
 *                                      insufficient memory allocated.
 * @retval QZ_NOT_SUPPORTED             Decompression with metadata is not
 *                                      supported with given algorithm
 *                                      or format.
 * @retval QZ_NOSW_NO_HW                Function did not find an installed
 *                                      kernel driver or software provider.
 * @retval QZ_NOSW_NO_INST_ATTACH       No instance available.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzDecompressWithMetadataExt(QzSession_T *sess,
        const unsigned char *src,
        unsigned int *src_len,
        unsigned char *dest,
        unsigned int *dest_len,
        uint64_t *ext_rc,
        QzMetadataBlob_T metadata,
        uint32_t hw_buff_sz_override);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Decompress a buffer with asynchronous or synchronous model
 *
 * @description
 *      These functions has the same decompression ability as "qzDecompress",
 *      but with asynchronous or synchronous model.
 *
 *      If user provide the callback function(callback is not NULL), it would
 *      work as asynchronous model. Otherwise, it would work as synchronous
 *      model, just like "qzDecompress".
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      No
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess       Session handle
 *                             (pointer to opaque instance and session data)
 * @param[in]       src        Pointer to source buffer containing compressed data.
 * @param[in]       dest       Pointer to destination buffer where decompressed
 *                             data will be stored.
 * @param[in]       callback   User-defined callback function to be called upon
 *                             completion of the decompression operation. it could
 *                             be NULL, then it's an synchronous call, otherwise,
 *                             it's asynchronous call.
 * @param[in,out]   qzResults  Pointer to QzResult, It have to allocate by user.
 *
 * @retval QZ_OK               Decompression request submitted successfully.
 * @retval QZ_FAIL             Decompression request submission failed.
 * @retval QZ_PARAMS           *sess is NULL or member of params is invalid.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      None
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzDecompress2(QzSession_T *sess, const unsigned char *src,
                             unsigned char *dest, qzAsyncCallbackFn callback,
                             QzResult_T *qzResults);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Uninitialize a QATzip session
 *
 * @description
 *      This function disconnects a session from a hardware instance and
 *    deallocates buffers. If no session has been initialized, then no
 *    action will take place.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess  Session handle
 *                        (pointer to opaque instance and session data)
 *
 * @retval QZ_OK          Function executed successfully
 * @retval QZ_FAIL        Function did not succeed
 * @retval QZ_PARAMS      *sess is NULL or member of params is invalid
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzTeardownSession(QzSession_T *sess);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Terminates a QATzip session
 *
 * @description
 *      This function closes the connection with QAT.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess  Session handle
 *                        (pointer to opaque instance and session data)
 *
 * @retval QZ_OK          Function executed successfully
 * @retval QZ_FAIL        Function did not succeed
 * @retval QZ_PARAMS      *sess is NULL or member of params is invalid
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzClose(QzSession_T *sess);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Get current QAT status
 *
 * @description
 *    This function retrieves the status of QAT in the platform.
 *    The status structure will be filled in as follows:
 *    qat_hw_count         Number of discovered QAT devices on PCU bus
 *    qat_service_init     1 if qzInit has been successfully run, 0 otherwise
 *    qat_mem_drvr         1 if the QAT memory driver is installed, 0 otherwise
 *    qat_instance_attach  1 if session has attached to a hardware instance,
 *                         0 otherwise
 *    memory_alloced       Amount of memory, in kilobytes, from kernel or huge
 *                         pages allocated  by this process/thread.
 *    using_huge_pages     1 if memory is being allocated from huge pages, 0 if
 *                         memory is being allocated from standard kernel memory
 *    hw_session_status    Hw session status: one of:
 *                                            QZ_OK
 *                                            QZ_FAIL
 *                                            QZ_NO_HW
 *                                            QZ_NO_MDRV
 *                                            QZ_NO_INST_ATTACH
 *                                            QZ_LOW_MEM
 *                                            QZ_NOSW_NO_HW
 *                                            QZ_NOSW_NO_MDRV
 *                                            QZ_NOSW_NO_INST_ATTACH
 *                                            QZ_NOSW_LOW_MEM
 *                                            QZ_NO_SW_AVAIL
 *
 * Applications should verify the elements of the status structure are
 * correct for the required operations. It should be noted that some
 * information will be available only after qzInit has been called, either
 * implicitly or explicitly.  The qat_service_init element of the status
 * structure will indicate if initialization has taken place.
 *
 * The hw_session_status will depend on the availability of hardware based
 * compression and software based compression. The following table indicates
 * what hw_session_status based on the availability of compression engines
 * and the sw_backup flag.
 *
 * | HW    | SW Engine | sw_backup | hw_session_stat   |
 * | avail | avail     | setting   |                   |
 * |-------|-----------|-----------|-------------------|
 * | N     | N         | 0         | QZ_NOSW_NO_HW     |
 * | N     | N         | 1         | QZ_NOSW_NO_HW     |
 * | N     | Y         | 0         | QZ_FAIL           |
 * | N     | Y         | 1         | QZ_NO_HW (1)      |
 * | Y     | N         | 0         | QZ_OK             |
 * | Y     | N         | 1         | QZ_NO_SW_AVAIL (2)|
 * | Y     | Y         | 0         | QZ_OK             |
 * | Y     | Y         | 1         | QZ_OK             |
 *
 * Note 1:
 *     If an application indicates software backup is required by setting
 *     sw_backup=1, and a software engine is available and if no hardware based
 *     compression engine is available then the hw_session_status will be set
 *     to QZ_NO_HW.  All compression and decompression will use the software
 *     engine.
 * Note 2:
 *     If an application indicates software backup is required by setting
 *     sw_backup=1, and if no software based compression engine is available
 *     then the hw_session_status will be set to QZ_NO_SW_AVAIL.  In this
 *     case, QAT based compression may be used however no software backup
 *     will available.
 *     If the application relies on software backup being avialable, then
 *     this return code can be treated as an error.
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess    Session handle
 *                          (pointer to opaque instance and session data)
 * @param[in]       status  Pointer to QATzip status structure
 * @retval QZ_OK            Function executed successfully. The hardware based
 *                          compression session has been created
 * @retval QZ_PARAMS        *status is NULL
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzGetStatus(QzSession_T *sess, QzStatus_T *status);

/**
 *****************************************************************************
 return end of stream.
 *****************************************************************************/
QATZIP_API int qzGetDeflateEndOfStream(QzSession_T *sess,
                                       unsigned char *endofstream);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Get the maximum compressed output length
 *
 * @description
 *      Get the maximum compressed output length.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]
 *         src_sz     Input data length in bytes
 *         sess       Session handle
 *                    (pointer to opaque instance and session data)
 *
 * @retval dest_sz    Max compressed data output length in bytes.
 *                    When src_sz is equal to 0, the return value is QZ_COMPRESSED_SZ_OF_EMPTY_FILE(34).
 *                    When integer overflow happens, the return value is 0
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
#define QZ_SKID_PAD_SZ 48
#define QZ_COMPRESSED_SZ_OF_EMPTY_FILE 34
QATZIP_API
unsigned int qzMaxCompressedLength(unsigned int src_sz, QzSession_T *sess);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Set default QzSessionParams_T value
 *
 * @description
 *      Set default QzSessionParams_T value.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]
 *              defaults   The pointer to value to be set as default
 *
 * @retval      QZ_OK      Success on setting default value
 * @retval      QZ_PARAM   Fail to set default value
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzSetDefaults(QzSessionParams_T *defaults);

QATZIP_API int qzSetDefaultsDeflate(QzSessionParamsDeflate_T *defaults);

QATZIP_API int qzSetDefaultsLZ4(QzSessionParamsLZ4_T *defaults);

QATZIP_API int qzSetDefaultsLZ4S(QzSessionParamsLZ4S_T *defaults);

QATZIP_API int qzSetDefaultsDeflateExt(QzSessionParamsDeflateExt_T *defaults);
/**
 *****************************************************************************
 * @ingroup qatZip
 *      Get default QzSessionParams_T value
 *
 * @description
 *      Get default QzSessionParams_T value.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]   defaults   The pointer to default value
 *
 * @retval      QZ_OK      Success on getting default value
 * @retval      QZ_PARAM   Fail to get default value
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzGetDefaults(QzSessionParams_T *defaults);

QATZIP_API int qzGetDefaultsDeflate(QzSessionParamsDeflate_T *defaults);

QATZIP_API int qzGetDefaultsLZ4(QzSessionParamsLZ4_T *defaults);

QATZIP_API int qzGetDefaultsLZ4S(QzSessionParamsLZ4S_T *defaults);

QATZIP_API int qzGetDefaultsDeflateExt(QzSessionParamsDeflateExt_T *defaults);
/**
 *****************************************************************************
 * @ingroup qatZip
 *      Allocate different types of memory
 *
 * @description
 *      Allocate different types of memory.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sz                  Memory size to be allocated
 * @param[in]       numa                NUMA node (0 or greater) from which to allocate memory
 *                                      QZ_AUTO_SELECT_NUMA_NODE (-1) to auto select optimal NUMA node
 * @param[in]       force_pinned        PINNED_MEM allocate contiguous memory
 *                                      COMMON_MEM allocate non-contiguous memory
 *
 * @retval          NULL                Fail to allocate memory
 * @retval          address             The address of allocated memory
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API void *qzMalloc(size_t sz, int numa, int force_pinned);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Allocate memory for metadata.
 *
 * @description
 *      Allocate memory for metadata. The function takes the size of entire
 *      input buffer and the data size at which individual block will be
 *      compressed. These parameters will be used to calculate and allocate
 *      required memory for metadata.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in, out]       metadata       Pointer to opaque metadata.
 * @param[in]            data_size      Size of uncompressed buffer.
 * @param[in]            hw_buff_sz     Data size at which individual block
 *                                      will be compressed.
 *
 * @retval QZ_OK                        Function executed successfully
 * @retval QZ_FAIL                      Function did not succeed
 * @retval QZ_PARAMS                    *metadata is NULL, or data_size is 0,
 *                                      or data_size is greater than 1GB, or
 *                                      incorrect hw_buff_sz.
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzAllocateMetadata(QzMetadataBlob_T *metadata,
                                  size_t data_size,
                                  uint32_t hw_buff_sz);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Free allocated memory
 *
 * @description
 *      Free allocated memory.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       m                   Memory address to be freed
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API void qzFree(void *m);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Free memory allocated for metadata.
 *
 * @description
 *      Free memory allocated for metadata.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       metadata    Pointer to opaque metadata.
 *
 * @retval QZ_OK                Function executed successfully.
 * @retval QZ_FAIL              Function did not succeed.
 * @retval QZ_PARAMS            metadata is NULL.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzFreeMetadata(QzMetadataBlob_T metadata);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Check whether the address is available
 *
 * @description
 *      Check whether the address is available.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]
 *              a       Address to be checked
 *
 * @retval      1       The address is available
 * @retval      0       The address is not available
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzMemFindAddr(unsigned char *a);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      QATzip Stream data storage
 *
 * @description
 *      This structure contains metadata needed for stream operation.
 *
 *****************************************************************************/
typedef struct QzStream_S {
    unsigned int in_sz;
    /**< Set by application, reset by QATzip to indicate consumed data */
    unsigned int out_sz;
    /**< Set by application, reset by QATzip to indicate processed data */
    unsigned char *in ;
    /**< Input data pointer set by application */
    unsigned char *out ;
    /**< Output data pointer set by application */
    unsigned int pending_in;
    /**< Unprocessed bytes held in QATzip */
    unsigned int pending_out;
    /**< Processed bytes held in QATzip */
    QzCrcType_T crc_type;
    /**< Checksum type in Adler, CRC32 or none */
    unsigned int crc_32;
    /**< Checksum value */
    unsigned long long reserved;
    /**< Reserved for future use */
    void *opaque;
    /**< Internal storage managed by QATzip */
} QzStream_T;

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Compress data in stream and return checksum
 *
 * @description
 *      This function will compress data in stream buffer if either a hardware
 *    based session or a software based session is available. If no session
 *    has been established - as indicated by the contents of *sess - then this
 *    function will attempt to set up a session using qzInit and qzSetupSession.
 *    The function will start to compress the data when receiving sufficient
 *    number of bytes - as defined by hw_buff_sz in QzSessionParams_T - or
 *    reaching the end of input data - as indicated by last parameter.
 *
 *    The resulting compressed block of data will be composed of one or more
 *    gzip blocks, per RFC 1952, or deflate blocks, per RFC 1951.
 *
 *    This function will place completed compression blocks in the *out
 *    of QzStream_T structure and put checksum for compressed input data
 *    in crc32 of QzStream_T structure.
 *
 *    The caller must check the updated in_sz of QzStream_T. This value will
 *    be the number of consumed bytes on exit. The calling API may have to
 *    process the destination buffer and call again.
 *
 *    The parameter out_sz in QzStream_T will be set to the number of bytes
 *    produced in the destination buffer. This value may be zero if no data
 *    was produced which may occur if the consumed data is retained internally.
 *    A possible reason for this may be small amounts of data in the src
 *    buffer.
 *
 *    The caller must check the updated pending_in of QzStream_T. This value
 *    will be the number of unprocessed bytes held in QATzip. The calling API
 *    may have to feed more input data or indicate reaching the end of input
 *    and call again.
 *
 *    The caller must check the updated pending_out of QzStream_T. This value
 *    will be the number of processed bytes held in QATzip. The calling API
 *    may have to process the destination buffer and call again.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess     Session handle
 *                           (pointer to opaque instance and session data)
 * @param[in,out]   strm     Stream handle
 * @param[in]       last     1 for 'No more data to be compressed'
 *                           0 for 'More data to be compressed'
 *                           (always set to 1 in the Microsoft(R)
 *                           Windows(TM) QATzip implementation)
 *
 * @retval QZ_OK             Function executed successfully
 * @retval QZ_FAIL           Function did not succeed
 * @retval QZ_PARAMS         *sess is NULL or member of params is invalid
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API
int qzCompressStream(QzSession_T *sess, QzStream_T *strm, unsigned int last);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Decompress data in stream and return checksum
 *
 * @description
 *      This function will decompress data in stream buffer if either a hardware
 *    based session or a software based session is available. If no session
 *    has been established - as indicated by the contents of *sess - then this
 *    function will attempt to set up a session using qzInit and qzSetupSession.
 *    The function will start to decompress the data when receiving sufficient
 *    number of bytes - as defined by hw_buff_sz in QzSessionParams_T - or
 *    reaching the end of input data - as indicated by last parameter.
 *
 *    The input compressed block of data will be composed of one or more
 *    gzip blocks, per RFC 1952, or deflate blocks, per RFC 1951.
 *
 *    This function will place completed decompression blocks in the *out
 *    of QzStream_T structure and put checksum for decompressed data in
 *    crc32 of QzStream_T structure.
 *
 *    The caller must check the updated in_sz of QzStream_T. This value will
 *    be the number of consumed bytes on exit. The calling API may have to
 *    process the destination buffer and call again.
 *
 *    The parameter out_sz in QzStream_T will be set to the number of bytes
 *    produced in the destination buffer. This value may be zero if no data
 *    was produced which may occur if the consumed data is retained internally.
 *    A possible reason for this may be small amounts of data in the src
 *    buffer.
 *
 *    The caller must check the updated pending_in of QzStream_T. This value
 *    will be the number of unprocessed bytes held in QATzip. The calling API
 *    may have to feed more input data or indicate reaching the end of input
 *    and call again.
 *
 *    The caller must check the updated pending_out of QzStream_T. This value
 *    will be the number of processed bytes held in QATzip. The calling API
 *    may have to process the destination buffer and call again.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess     Session handle
 *                           (pointer to opaque instance and session data)
 * @param[in,out]   strm     Stream handle
 * @param[in]       last     1 for 'No more data to be compressed'
 *                           0 for 'More data to be compressed'
 *
 * @retval QZ_OK             Function executed successfully
 * @retval QZ_FAIL           Function did not succeed
 * @retval QZ_PARAMS         *sess is NULL or member of params is invalid
 * @retval QZ_NEED_MORE      *last is set but end of block is absent
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API
int qzDecompressStream(QzSession_T *sess, QzStream_T *strm, unsigned int last);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Terminates a QATzip stream
 *
 * @description
 *      This function disconnects stream handle from session handle then reset
 *    stream flag and release stream memory.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess  Session handle
 *                        (pointer to opaque instance and session data)
 *
 * @retval QZ_OK          Function executed successfully
 * @retval QZ_FAIL        Function did not succeed
 * @retval QZ_PARAMS      *sess is NULL or member of params is invalid
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzEndStream(QzSession_T *sess, QzStream_T *strm);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Requests the release versions of the QATZip Library sub components.
 *
 * @description
 *      Populate an array of pre-allocated QzSoftwareVersionInfo_T structs
 *    with the names and versions of QATzip sub components.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      Yes
 * @threadSafe
 *      Yes
 *
 * @param[in, out]   api_info  pointer to a QzSoftwareVersionInfo_T
 *                             structure to populate.
 * @param[in, out]   num_elem  pointer to an unsigned int expressing
 *                             how many elements are in the array
 *                             provided in api_info
 *
 * @retval QZ_OK               Function executed successfully
 * @retval QZ_FAIL             Function did not succeed
 * @retval QZ_NO_SW_AVAIL      Function did not find a software provider for
 *                             fallback
 * @retval QZ_NO_HW            Function did not find an installed kernel driver
 * @retval QZ_NOSW_NO_HW       Functions did not find an installed kernel driver
                               or software provider
 * @retval QZ_PARAMS           *api_info or num_elem is NULL or not large
 *                             enough to store all QzSoftwareVersionInfo_T
 *                             structures
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API
int qzGetSoftwareComponentVersionList(QzSoftwareVersionInfo_T *api_info,
                                      unsigned int *num_elem);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Requests the number of Software components used by the QATZip library
 *
 * @description
 *      This function populates num_elem variable with the number of
 *      software components available to the library.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      Yes
 * @threadSafe
 *      Yes
 *
 * @param[in, out]   num_elem  pointer to an unsigned int to populate
 *                             how many software componets are associated
 *                             with QATZip
 *
 * @retval QZ_OK               Function executed successfully
 * @retval QZ_FAIL             Function did not succeed
 * @retval QZ_NO_SW_AVAIL      Function did not find a software provider for
 *                             fallback
 * @retval QZ_NO_HW            Function did not find an installed kernel driver
 * @retval QZ_NOSW_NO_HW       Functions did not find an installed kernel driver
                               or software provider
 * @retval QZ_PARAMS           *num_elem is NULL
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzGetSoftwareComponentCount(unsigned int *num_elem);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Requests the CRC64 configuration of the provided session
 *
 * @description
 *      This function populates crc64_config with the CRC64 configuration
 *      details of sess. This function has a dependency on invoking a setup
 *      session function first.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      Yes
 * @threadSafe
 *      Yes
 *
 * @param[in]       sess           Session handle
 *                                 (pointer to opaque instance and session data)
 * @param[out]      crc64_config   Configuration for CRC 64 generation.
 *
 * @retval QZ_OK               Function executed successfully
 * @retval QZ_FAIL             Session was not setup
 * @retval QZ_PARAMS           *sess or *crc64_config is NULL
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzGetSessionCrc64Config(QzSession_T *sess,
                                       QzCrc64Config_T *crc64_config);

/**
*****************************************************************************
* @ingroup qatZip
*      Requests the CRC32 configuration of the provided session
*
* @description
*      This function populates crc32_config with the CRC32 configuration
*      details of sess. This function has a dependency on invoking a setup
*      session function first.
*
* @context
*      This function shall not be called in an interrupt context.
* @assumptions
*      None
* @sideEffects
*      None
* @blocking
*      Yes
* @reentrant
*      Yes
* @threadSafe
*      Yes
*
* @param[in]       sess           Session handle
*                                 (pointer to opaque instance and session data)
* @param[out]      crc32_config   Configuration for CRC32 generation.
*
* @retval QZ_OK               Function executed successfully
* @retval QZ_FAIL             Session was not setup
* @retval QZ_PARAMS           *sess or *crc32_config is NULL
*
* @pre
*      None
* @post
*      None
* @note
*      Only a synchronous version of this function is provided.
*
* @see
*      None
*
*****************************************************************************/
QATZIP_API int qzGetSessionCrc32Config(QzSession_T *sess,
                                       QzCrc32Config_T *crc32_config);

/**
*****************************************************************************
* @ingroup qatZip
*      Sets the CRC64 configuration of the provided session with a
*      user defined set of parameters.
*
* @description
*      This function populates the CRC64 configuration details of sess
*      using the paramaters provided in crc64_config. This function has a
*      dependency on invoking a setup session function first.
*
* @context
*      This function shall not be called in an interrupt context.
* @assumptions
*      None
* @sideEffects
*      None
* @blocking
*      Yes
* @reentrant
*      Yes
* @threadSafe
*      Yes
*
* @param[in]       sess           Session handle
*                                 (pointer to opaque instance and session data)
* @param[in]       crc64_config   Configuration for CRC64 generation.
*
* @retval QZ_OK               Function executed successfully
* @retval QZ_FAIL             Session was not setup
* @retval QZ_PARAMS           *sess or *crc64_config is NULL or contains
*                             invalid paramters.
*
* @pre
*      None
* @post
*      None
* @note
*      Only a synchronous version of this function is provided.
*
* @see
*      None
*
*****************************************************************************/
QATZIP_API int qzSetSessionCrc64Config(QzSession_T *sess,
                                       QzCrc64Config_T *crc64_config);

/**
*****************************************************************************
* @ingroup qatZip
*      Sets the CRC32 configuration of the provided session with a
*      user defined set of parameters.
*
* @description
*      This function populates the CRC32 configuration details of sess
*      using the paramaters provided in crc32_config. This function has a
*      dependency on invoking a setup session function first.
*
* @context
*      This function shall not be called in an interrupt context.
* @assumptions
*      None
* @sideEffects
*      None
* @blocking
*      Yes
* @reentrant
*      Yes
* @threadSafe
*      Yes
*
* @param[in]       sess           Session handle
*                                 (pointer to opaque instance and session data)
* @param[in]       crc32_config   Configuration for CRC32 generation.
*
* @retval QZ_OK               Function executed successfully
* @retval QZ_FAIL             Session was not setup
* @retval QZ_PARAMS           *sess or *crc32_config is NULL or contains
*                             invalid parameters.
*
* @pre
*      None
* @post
*      None
* @note
*      Only a synchronous version of this function is provided.
*
* @see
*      None
*
*****************************************************************************/
QATZIP_API int qzSetSessionCrc32Config(QzSession_T *sess,
                                       QzCrc32Config_T *crc32_config);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Read metadata parameters.
 *
 * @description
 *      This function reads metadata information for the block specified by the
 *      function param block_num.
 *
 *      block_offset returns offset value in bytes from the previous compressed
 *      block of the compressed data.
 *
 *      block_size returns the block size in bytes of the compressed block.
 *      Some blocks may be uncompressed if size > threshold as specified during
 *      compression and the size returned will reflect the same.
 *
 *      block_flags returns the value 1 if the data is compressed and 0 if the
 *      data is not compressed.
 *
 *      block_hash returns the xxHash value of the plain text of the hw_buff_sz
 *      payload sent for compression operation.
 *
 *      If NULL is specified for any of the metadata parameters (block_offset,
 *      block_size, block_flags, block_hash) reading the parameter value
 *      will be ignored.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]            block_num      Block number of which metadata
 *                                      information should be read.
 * @param[in]            metadata       Pointer to opaque metadata.
 * @param[in, out]       block_offset   Pointer to the block offset value.
 * @param[in, out]       block_size     Pointer to the block size value.
 * @param[in, out]       block_flags    Pointer to the block flags value.
 * @param[in, out]       block_hash     Pointer to the block xxHash value.
 *
 * @retval QZ_OK                        Function executed successfully.
 * @retval QZ_FAIL                      Function did not succeed.
 * @retval QZ_PARAMS                    Metadata is NULL.
 * @retval QZ_OUT_OF_RANGE              block_num specified is out of range.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzMetadataBlockRead(uint32_t block_num,
                                   QzMetadataBlob_T metadata,
                                   uint32_t *block_offset,
                                   uint32_t *block_size,
                                   uint32_t *block_flags,
                                   uint32_t *block_hash);

/**
 *****************************************************************************
 * @ingroup qatZip
 *      Write metadata parameters.
 *
 * @description
 *      This function writes metadata information for the block specified by the
 *      function param block_num.
 *
 *      block_offset writes offset value in bytes from the previous compressed
 *      block of the compressed data.
 *
 *      block_size writes the block size in bytes of the compressed block.
 *
 *      block_flags causes the metadata to indicate the data is compressed if
 *      passed a value of 1 and indicates uncompressed if value
 *      passed is zero (0).
 *
 *      block_hash writes the xxHash value of the plain text of the hw_buff_sz
 *      payload sent for compression operation.
 *
 *      If NULL is specified for any of the metadata parameters (block_offset,
 *      block_size, block_flags, block_hash) writing the parameter value
 *      into metadata will be ignored.
 *
 * @context
 *      This function shall not be called in an interrupt context.
 * @assumptions
 *      None
 * @sideEffects
 *      None
 * @blocking
 *      Yes
 * @reentrant
 *      No
 * @threadSafe
 *      Yes
 *
 * @param[in]       block_num      Block number into which metadata information
 *                                 should be written.
 * @param[in, out]  metadata       Pointer to opaque metadata.
 * @param[in]       block_offset   Pointer to the block offset value.
 * @param[in]       block_size     Pointer to the block size value.
 * @param[in]       block_flags    Pointer to the block flags value.
 * @param[in]       block_hash     Pointer to the block xxHash value.
 *
 * @retval QZ_OK                   Function executed successfully.
 * @retval QZ_FAIL                 Function did not succeed.
 * @retval QZ_PARAMS               Metadata is NULL.
 * @retval QZ_OUT_OF_RANGE         block_num specified is out of range.
 *
 * @pre
 *      None
 * @post
 *      None
 * @note
 *      Only a synchronous version of this function is provided.
 *
 * @see
 *      None
 *
 *****************************************************************************/
QATZIP_API int qzMetadataBlockWrite(uint32_t block_num,
                                    QzMetadataBlob_T metadata,
                                    uint32_t *block_offset,
                                    uint32_t *block_size,
                                    uint32_t *block_flags,
                                    uint32_t *block_hash);

/**
*****************************************************************************
* @ingroup qatZip
*      Read CRC64 of a metadata block.
*
* @description
*      This function reads the input and output CRC64 for the block specified by
*      the function param block_num.
*
* @context
*      This function shall not be called in an interrupt context.
* @assumptions
*      None
* @sideEffects
*      None
* @blocking
*      Yes
* @reentrant
*      No
* @threadSafe
*      Yes
*
* @param[in]       block_num      Block number of which CRC64 should be read.
* @param[in]       metadata       Pointer to opaque metadata.
* @param[out]      input_crc      Pointer to the CRC64 calculation on input
*                                 buffer.
* @param[out]      output_crc     Pointer to the CRC64 calculation on output
*                                 buffer.
*
* @retval QZ_OK                   Function executed successfully.
* @retval QZ_FAIL                 Function did not succeed.
* @retval QZ_PARAMS               Metadata is NULL or checksum mismatch.
* @retval QZ_OUT_OF_RANGE         block_num specified is out of range.
*
* @pre
*      None
* @post
*      None
* @note
*      Only a synchronous version of this function is provided.
*
* @see
*      None
*
*****************************************************************************/
QATZIP_API int qzMetadataBlockGetCrc64(uint32_t block_num,
                                       QzMetadataBlob_T metadata,
                                       uint64_t *input_crc,
                                       uint64_t *output_crc);

/**
*****************************************************************************
* @ingroup qatZip
*      Read CRC32 of a metadata block.
*
* @description
*      This function reads the input and output CRC32 for the block specified by
*      the function param block_num.
*
* @context
*      This function shall not be called in an interrupt context.
* @assumptions
*      None
* @sideEffects
*      None
* @blocking
*      Yes
* @reentrant
*      No
* @threadSafe
*      Yes
*
* @param[in]       block_num      Block number of which CRC32 should be read.
* @param[in]       metadata       Pointer to opaque metadata.
* @param[out]      input_crc      Pointer to the CRC32 calculation on input
*                                 buffer.
* @param[out]      output_crc     Pointer to the CRC32 calculation on output
*                                 buffer.
*
* @retval QZ_OK                   Function executed successfully.
* @retval QZ_FAIL                 Function did not succeed.
* @retval QZ_PARAMS               Metadata is NULL or checksum mismatch.
* @retval QZ_OUT_OF_RANGE         block_num specified is out of range.
*
* @pre
*      None
* @post
*      None
* @note
*      Only a synchronous version of this function is provided.
*
* @see
*      None
*
*****************************************************************************/
QATZIP_API int qzMetadataBlockGetCrc32(uint32_t block_num,
                                       QzMetadataBlob_T metadata,
                                       uint32_t *input_crc,
                                       uint32_t *output_crc);

#ifdef __cplusplus
}
#endif

#endif