-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathqatzip.h
executable file
·2568 lines (2483 loc) · 92.7 KB
/
qatzip.h
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
/***************************************************************************
*
* BSD LICENSE
*
* Copyright(c) 2007-2024 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 (3)
/* 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, ¶ms);
* 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)
/**< Insufficent 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_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 */
} QzSessionParamsLZ4S_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)
/**
*****************************************************************************
* @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 pointer to opaque metadata.
*
* @description
* The opaque pointer to metadata.
*
*****************************************************************************/
typedef void *QzMetadataBlob_T;
/**
*****************************************************************************
* @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);
/**
*****************************************************************************
* @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);