src/dpdk/drivers/compress/isal/isal_compress_pmd.c
int
isal_comp_set_priv_xform_parameters(struct isal_priv_xform *priv_xform,
		const struct rte_comp_xform *xform)
{
	if (xform == NULL)
		return -EINVAL;

	/* Set compression private xform variables */
	if (xform->type == RTE_COMP_COMPRESS) {
		/* Set private xform type - COMPRESS/DECOMPRESS */
		priv_xform->type = RTE_COMP_COMPRESS;

		/* Set private xform algorithm */
		if (xform->compress.algo != RTE_COMP_ALGO_DEFLATE) {
			if (xform->compress.algo == RTE_COMP_ALGO_NULL) {
				ISAL_PMD_LOG(ERR, "By-pass not supported\n");
				return -ENOTSUP;
			}
			ISAL_PMD_LOG(ERR, "Algorithm not supported\n");
			return -ENOTSUP;
		}
		priv_xform->compress.algo = RTE_COMP_ALGO_DEFLATE;

		/* Set private xform window size, 32K supported */
		if (xform->compress.window_size == RTE_COMP_ISAL_WINDOW_SIZE)
			priv_xform->compress.window_size =
					RTE_COMP_ISAL_WINDOW_SIZE;
		else {
			ISAL_PMD_LOG(ERR, "Window size not supported\n");
			return -ENOTSUP;
		}

		/* Set private xform huffman type */
		switch (xform->compress.deflate.huffman) {
		case(RTE_COMP_HUFFMAN_DEFAULT):
			priv_xform->compress.deflate.huffman =
					RTE_COMP_HUFFMAN_DEFAULT;
			break;
		case(RTE_COMP_HUFFMAN_FIXED):
			priv_xform->compress.deflate.huffman =
					RTE_COMP_HUFFMAN_FIXED;
			break;
		case(RTE_COMP_HUFFMAN_DYNAMIC):
			priv_xform->compress.deflate.huffman =
					RTE_COMP_HUFFMAN_DYNAMIC;
			break;
		default:
			ISAL_PMD_LOG(ERR, "Huffman code not supported\n");
			return -ENOTSUP;
		}

		/* Set private xform checksum */
		switch (xform->compress.chksum) {
		/* Raw deflate by default */
		case(RTE_COMP_CHECKSUM_NONE):
			priv_xform->compress.chksum = IGZIP_DEFLATE;
			break;
		case(RTE_COMP_CHECKSUM_CRC32):
			priv_xform->compress.chksum = IGZIP_GZIP_NO_HDR;
			break;
		case(RTE_COMP_CHECKSUM_ADLER32):
			priv_xform->compress.chksum = IGZIP_ZLIB_NO_HDR;
			break;
		case(RTE_COMP_CHECKSUM_CRC32_ADLER32):
			ISAL_PMD_LOG(ERR, "Combined CRC and ADLER checksum not"
					" supported\n");
			return -ENOTSUP;
		default:
			ISAL_PMD_LOG(ERR, "Checksum type not supported\n");
			priv_xform->compress.chksum = IGZIP_DEFLATE;
			break;
		}

		/* Set private xform level.
		 * Checking compliance with compressdev API, -1 <= level => 9
		 */
		if (xform->compress.level < RTE_COMP_LEVEL_PMD_DEFAULT ||
				xform->compress.level > RTE_COMP_LEVEL_MAX) {
			ISAL_PMD_LOG(ERR, "Compression level out of range\n");
			return -EINVAL;
		}
		/* Check for Compressdev API level 0, No compression
		 * not supported in ISA-L
		 */
		else if (xform->compress.level == RTE_COMP_LEVEL_NONE) {
			ISAL_PMD_LOG(ERR, "No Compression not supported\n");
			return -ENOTSUP;
		}
		/* If using fixed huffman code, level must be 0 */
		else if (priv_xform->compress.deflate.huffman ==
				RTE_COMP_HUFFMAN_FIXED) {
			ISAL_PMD_LOG(DEBUG, "ISA-L level 0 used due to a"
					" fixed huffman code\n");
			priv_xform->compress.level = RTE_COMP_ISAL_LEVEL_ZERO;
			priv_xform->level_buffer_size =
					ISAL_DEF_LVL0_DEFAULT;
		} else {
			/* Mapping API levels to ISA-L levels 1,2 & 3 */
			switch (xform->compress.level) {
			case RTE_COMP_LEVEL_PMD_DEFAULT:
				/* Default is 1 if not using fixed huffman */
				priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_ONE;
				priv_xform->level_buffer_size =
						ISAL_DEF_LVL1_DEFAULT;
				break;
			case RTE_COMP_LEVEL_MIN:
				priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_ONE;
				priv_xform->level_buffer_size =
						ISAL_DEF_LVL1_DEFAULT;
				break;
			case RTE_COMP_ISAL_LEVEL_TWO:
				priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_TWO;
				priv_xform->level_buffer_size =
						ISAL_DEF_LVL2_DEFAULT;
				break;
			/* Level 3 or higher requested */
			default:
				/* Check for AVX512, to use ISA-L level 3 */
				if (rte_cpu_get_flag_enabled(
						RTE_CPUFLAG_AVX512F)) {
					priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_THREE;
					priv_xform->level_buffer_size =
						ISAL_DEF_LVL3_DEFAULT;
				}
				/* Check for AVX2, to use ISA-L level 3 */
				else if (rte_cpu_get_flag_enabled(
						RTE_CPUFLAG_AVX2)) {
					priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_THREE;
					priv_xform->level_buffer_size =
						ISAL_DEF_LVL3_DEFAULT;
				} else {
					ISAL_PMD_LOG(DEBUG, "Requested ISA-L level"
						" 3 or above; Level 3 optimized"
						" for AVX512 & AVX2 only."
						" level changed to 2.\n");
					priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_TWO;
					priv_xform->level_buffer_size =
						ISAL_DEF_LVL2_DEFAULT;
				}
			}
		}
	}

	/* Set decompression private xform variables */
	else if (xform->type == RTE_COMP_DECOMPRESS) {

		/* Set private xform type - COMPRESS/DECOMPRESS */
		priv_xform->type = RTE_COMP_DECOMPRESS;

		/* Set private xform algorithm */
		if (xform->decompress.algo != RTE_COMP_ALGO_DEFLATE) {
			if (xform->decompress.algo == RTE_COMP_ALGO_NULL) {
				ISAL_PMD_LOG(ERR, "By pass not supported\n");
				return -ENOTSUP;
			}
			ISAL_PMD_LOG(ERR, "Algorithm not supported\n");
			return -ENOTSUP;
		}
		priv_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE;

		/* Set private xform checksum */
		switch (xform->decompress.chksum) {
		/* Raw deflate by default */
		case(RTE_COMP_CHECKSUM_NONE):
			priv_xform->decompress.chksum = ISAL_DEFLATE;
			break;
		case(RTE_COMP_CHECKSUM_CRC32):
			priv_xform->decompress.chksum = ISAL_GZIP_NO_HDR;
			break;
		case(RTE_COMP_CHECKSUM_ADLER32):
			priv_xform->decompress.chksum = ISAL_ZLIB_NO_HDR;
			break;
		case(RTE_COMP_CHECKSUM_CRC32_ADLER32):
			ISAL_PMD_LOG(ERR, "Combined CRC and ADLER checksum not"
					" supported\n");
			return -ENOTSUP;
		default:
			ISAL_PMD_LOG(ERR, "Checksum type not supported\n");
			priv_xform->decompress.chksum = ISAL_DEFLATE;
			break;
		}

		/* Set private xform window size, 32K supported */
		if (xform->decompress.window_size == RTE_COMP_ISAL_WINDOW_SIZE)
			priv_xform->decompress.window_size =
					RTE_COMP_ISAL_WINDOW_SIZE;
		else {
			ISAL_PMD_LOG(ERR, "Window size not supported\n");
			return -ENOTSUP;
		}
	}
	return 0;
}
/* Verify and set private xform parameters */
Verify and set private xform parameters
Verify and set private xform parameters
int
isal_comp_set_priv_xform_parameters(struct isal_priv_xform *priv_xform,
		const struct rte_comp_xform *xform)
{
	if (xform == NULL)
		return -EINVAL;
	if (xform->type == RTE_COMP_COMPRESS) {
		priv_xform->type = RTE_COMP_COMPRESS;
		if (xform->compress.algo != RTE_COMP_ALGO_DEFLATE) {
			if (xform->compress.algo == RTE_COMP_ALGO_NULL) {
				ISAL_PMD_LOG(ERR, "By-pass not supported\n");
				return -ENOTSUP;
			}
			ISAL_PMD_LOG(ERR, "Algorithm not supported\n");
			return -ENOTSUP;
		}
		priv_xform->compress.algo = RTE_COMP_ALGO_DEFLATE;
		if (xform->compress.window_size == RTE_COMP_ISAL_WINDOW_SIZE)
			priv_xform->compress.window_size =
					RTE_COMP_ISAL_WINDOW_SIZE;
		else {
			ISAL_PMD_LOG(ERR, "Window size not supported\n");
			return -ENOTSUP;
		}
		switch (xform->compress.deflate.huffman) {
		case(RTE_COMP_HUFFMAN_DEFAULT):
			priv_xform->compress.deflate.huffman =
					RTE_COMP_HUFFMAN_DEFAULT;
			break;
		case(RTE_COMP_HUFFMAN_FIXED):
			priv_xform->compress.deflate.huffman =
					RTE_COMP_HUFFMAN_FIXED;
			break;
		case(RTE_COMP_HUFFMAN_DYNAMIC):
			priv_xform->compress.deflate.huffman =
					RTE_COMP_HUFFMAN_DYNAMIC;
			break;
		default:
			ISAL_PMD_LOG(ERR, "Huffman code not supported\n");
			return -ENOTSUP;
		}
		switch (xform->compress.chksum) {
		case(RTE_COMP_CHECKSUM_NONE):
			priv_xform->compress.chksum = IGZIP_DEFLATE;
			break;
		case(RTE_COMP_CHECKSUM_CRC32):
			priv_xform->compress.chksum = IGZIP_GZIP_NO_HDR;
			break;
		case(RTE_COMP_CHECKSUM_ADLER32):
			priv_xform->compress.chksum = IGZIP_ZLIB_NO_HDR;
			break;
		case(RTE_COMP_CHECKSUM_CRC32_ADLER32):
			ISAL_PMD_LOG(ERR, "Combined CRC and ADLER checksum not"
					" supported\n");
			return -ENOTSUP;
		default:
			ISAL_PMD_LOG(ERR, "Checksum type not supported\n");
			priv_xform->compress.chksum = IGZIP_DEFLATE;
			break;
		}
		if (xform->compress.level < RTE_COMP_LEVEL_PMD_DEFAULT ||
				xform->compress.level > RTE_COMP_LEVEL_MAX) {
			ISAL_PMD_LOG(ERR, "Compression level out of range\n");
			return -EINVAL;
		}
		else if (xform->compress.level == RTE_COMP_LEVEL_NONE) {
			ISAL_PMD_LOG(ERR, "No Compression not supported\n");
			return -ENOTSUP;
		}
		else if (priv_xform->compress.deflate.huffman ==
				RTE_COMP_HUFFMAN_FIXED) {
			ISAL_PMD_LOG(DEBUG, "ISA-L level 0 used due to a"
					" fixed huffman code\n");
			priv_xform->compress.level = RTE_COMP_ISAL_LEVEL_ZERO;
			priv_xform->level_buffer_size =
					ISAL_DEF_LVL0_DEFAULT;
		} else {
			switch (xform->compress.level) {
			case RTE_COMP_LEVEL_PMD_DEFAULT:
				priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_ONE;
				priv_xform->level_buffer_size =
						ISAL_DEF_LVL1_DEFAULT;
				break;
			case RTE_COMP_LEVEL_MIN:
				priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_ONE;
				priv_xform->level_buffer_size =
						ISAL_DEF_LVL1_DEFAULT;
				break;
			case RTE_COMP_ISAL_LEVEL_TWO:
				priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_TWO;
				priv_xform->level_buffer_size =
						ISAL_DEF_LVL2_DEFAULT;
				break;
			default:
				if (rte_cpu_get_flag_enabled(
						RTE_CPUFLAG_AVX512F)) {
					priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_THREE;
					priv_xform->level_buffer_size =
						ISAL_DEF_LVL3_DEFAULT;
				}
				else if (rte_cpu_get_flag_enabled(
						RTE_CPUFLAG_AVX2)) {
					priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_THREE;
					priv_xform->level_buffer_size =
						ISAL_DEF_LVL3_DEFAULT;
				} else {
					ISAL_PMD_LOG(DEBUG, "Requested ISA-L level"
						" 3 or above; Level 3 optimized"
						" for AVX512 & AVX2 only."
						" level changed to 2.\n");
					priv_xform->compress.level =
						RTE_COMP_ISAL_LEVEL_TWO;
					priv_xform->level_buffer_size =
						ISAL_DEF_LVL2_DEFAULT;
				}
			}
		}
	}
	else if (xform->type == RTE_COMP_DECOMPRESS) {
		priv_xform->type = RTE_COMP_DECOMPRESS;
		if (xform->decompress.algo != RTE_COMP_ALGO_DEFLATE) {
			if (xform->decompress.algo == RTE_COMP_ALGO_NULL) {
				ISAL_PMD_LOG(ERR, "By pass not supported\n");
				return -ENOTSUP;
			}
			ISAL_PMD_LOG(ERR, "Algorithm not supported\n");
			return -ENOTSUP;
		}
		priv_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE;
		switch (xform->decompress.chksum) {
		case(RTE_COMP_CHECKSUM_NONE):
			priv_xform->decompress.chksum = ISAL_DEFLATE;
			break;
		case(RTE_COMP_CHECKSUM_CRC32):
			priv_xform->decompress.chksum = ISAL_GZIP_NO_HDR;
			break;
		case(RTE_COMP_CHECKSUM_ADLER32):
			priv_xform->decompress.chksum = ISAL_ZLIB_NO_HDR;
			break;
		case(RTE_COMP_CHECKSUM_CRC32_ADLER32):
			ISAL_PMD_LOG(ERR, "Combined CRC and ADLER checksum not"
					" supported\n");
			return -ENOTSUP;
		default:
			ISAL_PMD_LOG(ERR, "Checksum type not supported\n");
			priv_xform->decompress.chksum = ISAL_DEFLATE;
			break;
		}
		if (xform->decompress.window_size == RTE_COMP_ISAL_WINDOW_SIZE)
			priv_xform->decompress.window_size =
					RTE_COMP_ISAL_WINDOW_SIZE;
		else {
			ISAL_PMD_LOG(ERR, "Window size not supported\n");
			return -ENOTSUP;
		}
	}
	return 0;
}
int isal_comp_set_priv_xform_parameters ( struct isal_priv_xform * priv_xform , const struct rte_comp_xform * xform ) { if ( xform == NULL ) return - EINVAL ; if ( xform -> type == RTE_COMP_COMPRESS ) { priv_xform -> type = RTE_COMP_COMPRESS ; if ( xform -> compress . algo != RTE_COMP_ALGO_DEFLATE ) { if ( xform -> compress . algo == RTE_COMP_ALGO_NULL ) { ISAL_PMD_LOG ( ERR , " \n " ) ; return - ENOTSUP ; } ISAL_PMD_LOG ( ERR , " \n " ) ; return - ENOTSUP ; } priv_xform -> compress . algo = RTE_COMP_ALGO_DEFLATE ; if ( xform -> compress . window_size == RTE_COMP_ISAL_WINDOW_SIZE ) priv_xform -> compress . window_size = RTE_COMP_ISAL_WINDOW_SIZE ; else { ISAL_PMD_LOG ( ERR , " \n " ) ; return - ENOTSUP ; } switch ( xform -> compress . deflate . huffman ) { case ( RTE_COMP_HUFFMAN_DEFAULT ) : priv_xform -> compress . deflate . huffman = RTE_COMP_HUFFMAN_DEFAULT ; break ; case ( RTE_COMP_HUFFMAN_FIXED ) : priv_xform -> compress . deflate . huffman = RTE_COMP_HUFFMAN_FIXED ; break ; case ( RTE_COMP_HUFFMAN_DYNAMIC ) : priv_xform -> compress . deflate . huffman = RTE_COMP_HUFFMAN_DYNAMIC ; break ; default : ISAL_PMD_LOG ( ERR , " \n " ) ; return - ENOTSUP ; } switch ( xform -> compress . chksum ) { case ( RTE_COMP_CHECKSUM_NONE ) : priv_xform -> compress . chksum = IGZIP_DEFLATE ; break ; case ( RTE_COMP_CHECKSUM_CRC32 ) : priv_xform -> compress . chksum = IGZIP_GZIP_NO_HDR ; break ; case ( RTE_COMP_CHECKSUM_ADLER32 ) : priv_xform -> compress . chksum = IGZIP_ZLIB_NO_HDR ; break ; case ( RTE_COMP_CHECKSUM_CRC32_ADLER32 ) : ISAL_PMD_LOG ( ERR , " " " \n " ) ; return - ENOTSUP ; default : ISAL_PMD_LOG ( ERR , " \n " ) ; priv_xform -> compress . chksum = IGZIP_DEFLATE ; break ; } if ( xform -> compress . level < RTE_COMP_LEVEL_PMD_DEFAULT || xform -> compress . level > RTE_COMP_LEVEL_MAX ) { ISAL_PMD_LOG ( ERR , " \n " ) ; return - EINVAL ; } else if ( xform -> compress . level == RTE_COMP_LEVEL_NONE ) { ISAL_PMD_LOG ( ERR , " \n " ) ; return - ENOTSUP ; } else if ( priv_xform -> compress . deflate . huffman == RTE_COMP_HUFFMAN_FIXED ) { ISAL_PMD_LOG ( DEBUG , " " " \n " ) ; priv_xform -> compress . level = RTE_COMP_ISAL_LEVEL_ZERO ; priv_xform -> level_buffer_size = ISAL_DEF_LVL0_DEFAULT ; } else { switch ( xform -> compress . level ) { case RTE_COMP_LEVEL_PMD_DEFAULT : priv_xform -> compress . level = RTE_COMP_ISAL_LEVEL_ONE ; priv_xform -> level_buffer_size = ISAL_DEF_LVL1_DEFAULT ; break ; case RTE_COMP_LEVEL_MIN : priv_xform -> compress . level = RTE_COMP_ISAL_LEVEL_ONE ; priv_xform -> level_buffer_size = ISAL_DEF_LVL1_DEFAULT ; break ; case RTE_COMP_ISAL_LEVEL_TWO : priv_xform -> compress . level = RTE_COMP_ISAL_LEVEL_TWO ; priv_xform -> level_buffer_size = ISAL_DEF_LVL2_DEFAULT ; break ; default : if ( rte_cpu_get_flag_enabled ( RTE_CPUFLAG_AVX512F ) ) { priv_xform -> compress . level = RTE_COMP_ISAL_LEVEL_THREE ; priv_xform -> level_buffer_size = ISAL_DEF_LVL3_DEFAULT ; } else if ( rte_cpu_get_flag_enabled ( RTE_CPUFLAG_AVX2 ) ) { priv_xform -> compress . level = RTE_COMP_ISAL_LEVEL_THREE ; priv_xform -> level_buffer_size = ISAL_DEF_LVL3_DEFAULT ; } else { ISAL_PMD_LOG ( DEBUG , " " " " " " " \n " ) ; priv_xform -> compress . level = RTE_COMP_ISAL_LEVEL_TWO ; priv_xform -> level_buffer_size = ISAL_DEF_LVL2_DEFAULT ; } } } } else if ( xform -> type == RTE_COMP_DECOMPRESS ) { priv_xform -> type = RTE_COMP_DECOMPRESS ; if ( xform -> decompress . algo != RTE_COMP_ALGO_DEFLATE ) { if ( xform -> decompress . algo == RTE_COMP_ALGO_NULL ) { ISAL_PMD_LOG ( ERR , " \n " ) ; return - ENOTSUP ; } ISAL_PMD_LOG ( ERR , " \n " ) ; return - ENOTSUP ; } priv_xform -> decompress . algo = RTE_COMP_ALGO_DEFLATE ; switch ( xform -> decompress . chksum ) { case ( RTE_COMP_CHECKSUM_NONE ) : priv_xform -> decompress . chksum = ISAL_DEFLATE ; break ; case ( RTE_COMP_CHECKSUM_CRC32 ) : priv_xform -> decompress . chksum = ISAL_GZIP_NO_HDR ; break ; case ( RTE_COMP_CHECKSUM_ADLER32 ) : priv_xform -> decompress . chksum = ISAL_ZLIB_NO_HDR ; break ; case ( RTE_COMP_CHECKSUM_CRC32_ADLER32 ) : ISAL_PMD_LOG ( ERR , " " " \n " ) ; return - ENOTSUP ; default : ISAL_PMD_LOG ( ERR , " \n " ) ; priv_xform -> decompress . chksum = ISAL_DEFLATE ; break ; } if ( xform -> decompress . window_size == RTE_COMP_ISAL_WINDOW_SIZE ) priv_xform -> decompress . window_size = RTE_COMP_ISAL_WINDOW_SIZE ; else { ISAL_PMD_LOG ( ERR , " \n " ) ; return - ENOTSUP ; } } return 0 ; }
Verify and set private xform parameters
Verify and set private xform parameters
/* Set compression private xform variables */ /* Set private xform type - COMPRESS/DECOMPRESS */ /* Set private xform algorithm */ /* Set private xform window size, 32K supported */ /* Set private xform huffman type */ /* Set private xform checksum */ /* Raw deflate by default */ /* Set private xform level.
		 * Checking compliance with compressdev API, -1 <= level => 9
		 */ /* Check for Compressdev API level 0, No compression
		 * not supported in ISA-L
		 */ /* If using fixed huffman code, level must be 0 */ /* Mapping API levels to ISA-L levels 1,2 & 3 */ /* Default is 1 if not using fixed huffman */ /* Level 3 or higher requested */ /* Check for AVX512, to use ISA-L level 3 */ /* Check for AVX2, to use ISA-L level 3 */ /* Set decompression private xform variables */ /* Set private xform type - COMPRESS/DECOMPRESS */ /* Set private xform algorithm */ /* Set private xform checksum */ /* Raw deflate by default */ /* Set private xform window size, 32K supported */