1*a4b16dadSTom Zanussi // SPDX-License-Identifier: GPL-2.0-only
2*a4b16dadSTom Zanussi /* Copyright(c) 2022 Intel Corporation */
3*a4b16dadSTom Zanussi #include "adf_accel_devices.h"
4*a4b16dadSTom Zanussi #include "adf_gen2_dc.h"
5*a4b16dadSTom Zanussi #include "icp_qat_fw_comp.h"
6*a4b16dadSTom Zanussi 
qat_comp_build_deflate_ctx(void * ctx)7*a4b16dadSTom Zanussi static void qat_comp_build_deflate_ctx(void *ctx)
8*a4b16dadSTom Zanussi {
9*a4b16dadSTom Zanussi 	struct icp_qat_fw_comp_req *req_tmpl = (struct icp_qat_fw_comp_req *)ctx;
10*a4b16dadSTom Zanussi 	struct icp_qat_fw_comn_req_hdr *header = &req_tmpl->comn_hdr;
11*a4b16dadSTom Zanussi 	struct icp_qat_fw_comp_req_hdr_cd_pars *cd_pars = &req_tmpl->cd_pars;
12*a4b16dadSTom Zanussi 	struct icp_qat_fw_comp_req_params *req_pars = &req_tmpl->comp_pars;
13*a4b16dadSTom Zanussi 	struct icp_qat_fw_comp_cd_hdr *comp_cd_ctrl = &req_tmpl->comp_cd_ctrl;
14*a4b16dadSTom Zanussi 
15*a4b16dadSTom Zanussi 	memset(req_tmpl, 0, sizeof(*req_tmpl));
16*a4b16dadSTom Zanussi 	header->hdr_flags =
17*a4b16dadSTom Zanussi 		ICP_QAT_FW_COMN_HDR_FLAGS_BUILD(ICP_QAT_FW_COMN_REQ_FLAG_SET);
18*a4b16dadSTom Zanussi 	header->service_type = ICP_QAT_FW_COMN_REQ_CPM_FW_COMP;
19*a4b16dadSTom Zanussi 	header->service_cmd_id = ICP_QAT_FW_COMP_CMD_STATIC;
20*a4b16dadSTom Zanussi 	header->comn_req_flags =
21*a4b16dadSTom Zanussi 		ICP_QAT_FW_COMN_FLAGS_BUILD(QAT_COMN_CD_FLD_TYPE_16BYTE_DATA,
22*a4b16dadSTom Zanussi 					    QAT_COMN_PTR_TYPE_SGL);
23*a4b16dadSTom Zanussi 	header->serv_specif_flags =
24*a4b16dadSTom Zanussi 		ICP_QAT_FW_COMP_FLAGS_BUILD(ICP_QAT_FW_COMP_STATELESS_SESSION,
25*a4b16dadSTom Zanussi 					    ICP_QAT_FW_COMP_NOT_AUTO_SELECT_BEST,
26*a4b16dadSTom Zanussi 					    ICP_QAT_FW_COMP_NOT_ENH_AUTO_SELECT_BEST,
27*a4b16dadSTom Zanussi 					    ICP_QAT_FW_COMP_NOT_DISABLE_TYPE0_ENH_AUTO_SELECT_BEST,
28*a4b16dadSTom Zanussi 					    ICP_QAT_FW_COMP_ENABLE_SECURE_RAM_USED_AS_INTMD_BUF);
29*a4b16dadSTom Zanussi 	cd_pars->u.sl.comp_slice_cfg_word[0] =
30*a4b16dadSTom Zanussi 		ICP_QAT_HW_COMPRESSION_CONFIG_BUILD(ICP_QAT_HW_COMPRESSION_DIR_COMPRESS,
31*a4b16dadSTom Zanussi 						    ICP_QAT_HW_COMPRESSION_DELAYED_MATCH_DISABLED,
32*a4b16dadSTom Zanussi 						    ICP_QAT_HW_COMPRESSION_ALGO_DEFLATE,
33*a4b16dadSTom Zanussi 						    ICP_QAT_HW_COMPRESSION_DEPTH_1,
34*a4b16dadSTom Zanussi 						    ICP_QAT_HW_COMPRESSION_FILE_TYPE_0);
35*a4b16dadSTom Zanussi 	req_pars->crc.legacy.initial_adler = COMP_CPR_INITIAL_ADLER;
36*a4b16dadSTom Zanussi 	req_pars->crc.legacy.initial_crc32 = COMP_CPR_INITIAL_CRC;
37*a4b16dadSTom Zanussi 	req_pars->req_par_flags =
38*a4b16dadSTom Zanussi 		ICP_QAT_FW_COMP_REQ_PARAM_FLAGS_BUILD(ICP_QAT_FW_COMP_SOP,
39*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_EOP,
40*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_BFINAL,
41*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_CNV,
42*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_CNV_RECOVERY,
43*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_NO_CNV_DFX,
44*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_CRC_MODE_LEGACY,
45*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_NO_XXHASH_ACC,
46*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_CNV_ERROR_NONE,
47*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_NO_APPEND_CRC,
48*a4b16dadSTom Zanussi 						      ICP_QAT_FW_COMP_NO_DROP_DATA);
49*a4b16dadSTom Zanussi 	ICP_QAT_FW_COMN_NEXT_ID_SET(comp_cd_ctrl, ICP_QAT_FW_SLICE_DRAM_WR);
50*a4b16dadSTom Zanussi 	ICP_QAT_FW_COMN_CURR_ID_SET(comp_cd_ctrl, ICP_QAT_FW_SLICE_COMP);
51*a4b16dadSTom Zanussi 
52*a4b16dadSTom Zanussi 	/* Fill second half of the template for decompression */
53*a4b16dadSTom Zanussi 	memcpy(req_tmpl + 1, req_tmpl, sizeof(*req_tmpl));
54*a4b16dadSTom Zanussi 	req_tmpl++;
55*a4b16dadSTom Zanussi 	header = &req_tmpl->comn_hdr;
56*a4b16dadSTom Zanussi 	header->service_cmd_id = ICP_QAT_FW_COMP_CMD_DECOMPRESS;
57*a4b16dadSTom Zanussi 	cd_pars = &req_tmpl->cd_pars;
58*a4b16dadSTom Zanussi 	cd_pars->u.sl.comp_slice_cfg_word[0] =
59*a4b16dadSTom Zanussi 		ICP_QAT_HW_COMPRESSION_CONFIG_BUILD(ICP_QAT_HW_COMPRESSION_DIR_DECOMPRESS,
60*a4b16dadSTom Zanussi 						    ICP_QAT_HW_COMPRESSION_DELAYED_MATCH_DISABLED,
61*a4b16dadSTom Zanussi 						    ICP_QAT_HW_COMPRESSION_ALGO_DEFLATE,
62*a4b16dadSTom Zanussi 						    ICP_QAT_HW_COMPRESSION_DEPTH_1,
63*a4b16dadSTom Zanussi 						    ICP_QAT_HW_COMPRESSION_FILE_TYPE_0);
64*a4b16dadSTom Zanussi }
65*a4b16dadSTom Zanussi 
adf_gen2_init_dc_ops(struct adf_dc_ops * dc_ops)66*a4b16dadSTom Zanussi void adf_gen2_init_dc_ops(struct adf_dc_ops *dc_ops)
67*a4b16dadSTom Zanussi {
68*a4b16dadSTom Zanussi 	dc_ops->build_deflate_ctx = qat_comp_build_deflate_ctx;
69*a4b16dadSTom Zanussi }
70*a4b16dadSTom Zanussi EXPORT_SYMBOL_GPL(adf_gen2_init_dc_ops);
71