Commit 3a36ff34 authored by Chenghai Huang's avatar Chenghai Huang Committed by JiangShui
Browse files

crypto: hisilicon/zip - add zip comp high perf mode configuration

driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8IVG6


CVE: NA

----------------------------------------------------------------------

To meet specific application scenarios, the function of switching between
the high performance mode and the high compression mode is added.

Use the perf_mode=0/1 configuration to set the compression high perf mode,
0(default, high compression mode), 1(high performance mode). These two
modes only apply to the compression direction and are compatible with
software algorithm in both directions.

Signed-off-by: default avatarChenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: default avatarJiangShui Yang <yangjiangshui@h-partners.com>
parent dca84f43
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
@@ -106,6 +106,14 @@
#define HZIP_CLOCK_GATED_EN		(HZIP_CORE_GATED_EN | \
					 HZIP_CORE_GATED_OOO_EN)

/* zip comp high performance */
#define HZIP_HIGH_PERF_OFFSET		0x301208

enum {
	HZIP_HIGH_COMP_RATE,
	HZIP_HIGH_COMP_PERF,
};

static const char hisi_zip_name[] = "hisi_zip";
static struct dentry *hzip_debugfs_root;

@@ -366,6 +374,37 @@ static int hzip_diff_regs_show(struct seq_file *s, void *unused)
	return 0;
}
DEFINE_SHOW_ATTRIBUTE(hzip_diff_regs);

static int perf_mode_set(const char *val, const struct kernel_param *kp)
{
	int ret;
	u32 n;

	if (!val)
		return -EINVAL;

	ret = kstrtou32(val, 10, &n);
	if (ret != 0 || (n != HZIP_HIGH_COMP_PERF &&
			 n != HZIP_HIGH_COMP_RATE))
		return -EINVAL;

	return param_set_int(val, kp);
}

static const struct kernel_param_ops zip_com_perf_ops = {
	.set = perf_mode_set,
	.get = param_get_int,
};

/*
 * perf_mode = 0 means enable high compression rate mode,
 * perf_mode = 1 means enable high compression performance mode.
 * These two modes only apply to the compression direction.
 */
static u32 perf_mode = HZIP_HIGH_COMP_RATE;
module_param_cb(perf_mode, &zip_com_perf_ops, &perf_mode, 0444);
MODULE_PARM_DESC(perf_mode, "ZIP high perf mode 0(default), 1(enable)");

static const struct kernel_param_ops zip_uacce_mode_ops = {
	.set = uacce_mode_set,
	.get = param_get_int,
@@ -431,6 +470,28 @@ bool hisi_zip_alg_support(struct hisi_qm *qm, u32 alg)
	return false;
}

static int hisi_zip_set_high_perf(struct hisi_qm *qm)
{
	u32 val;
	int ret;

	val = readl_relaxed(qm->io_base + HZIP_HIGH_PERF_OFFSET);
	if (perf_mode == HZIP_HIGH_COMP_PERF)
		val |= HZIP_HIGH_COMP_PERF;
	else
		val &= ~HZIP_HIGH_COMP_PERF;

	/* Set perf mode */
	writel(val, qm->io_base + HZIP_HIGH_PERF_OFFSET);
	ret = readl_relaxed_poll_timeout(qm->io_base + HZIP_HIGH_PERF_OFFSET,
					 val, val == perf_mode, HZIP_DELAY_1_US,
					 HZIP_POLL_TIMEOUT_US);
	if (ret)
		pci_err(qm->pdev, "failed to set perf mode\n");

	return ret;
}

static void hisi_zip_open_sva_prefetch(struct hisi_qm *qm)
{
	u32 val;
@@ -1113,6 +1174,10 @@ static int hisi_zip_pf_probe_init(struct hisi_zip *hisi_zip)
	if (ret)
		return ret;

	ret = hisi_zip_set_high_perf(qm);
	if (ret)
		return ret;

	hisi_zip_open_sva_prefetch(qm);
	hisi_qm_dev_err_init(qm);
	hisi_zip_debug_regs_clear(qm);