1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019 HiSilicon Limited. */
3 #ifndef __HISI_HPRE_H
4 #define __HISI_HPRE_H
5 
6 #include <linux/list.h>
7 #include "../qm.h"
8 
9 #define HPRE_SQE_SIZE			sizeof(struct hpre_sqe)
10 #define HPRE_PF_DEF_Q_NUM		64
11 #define HPRE_PF_DEF_Q_BASE		0
12 
13 enum {
14 	HPRE_CLUSTER0,
15 	HPRE_CLUSTER1,
16 	HPRE_CLUSTER2,
17 	HPRE_CLUSTER3,
18 	HPRE_CLUSTERS_NUM,
19 };
20 
21 enum hpre_ctrl_dbgfs_file {
22 	HPRE_CURRENT_QM,
23 	HPRE_CLEAR_ENABLE,
24 	HPRE_CLUSTER_CTRL,
25 	HPRE_DEBUG_FILE_NUM,
26 };
27 
28 enum hpre_dfx_dbgfs_file {
29 	HPRE_SEND_CNT,
30 	HPRE_RECV_CNT,
31 	HPRE_SEND_FAIL_CNT,
32 	HPRE_SEND_BUSY_CNT,
33 	HPRE_OVER_THRHLD_CNT,
34 	HPRE_OVERTIME_THRHLD,
35 	HPRE_INVALID_REQ_CNT,
36 	HPRE_DFX_FILE_NUM
37 };
38 
39 #define HPRE_DEBUGFS_FILE_NUM    (HPRE_DEBUG_FILE_NUM + HPRE_CLUSTERS_NUM - 1)
40 
41 struct hpre_debugfs_file {
42 	int index;
43 	enum hpre_ctrl_dbgfs_file type;
44 	spinlock_t lock;
45 	struct hpre_debug *debug;
46 };
47 
48 struct hpre_dfx {
49 	atomic64_t value;
50 	enum hpre_dfx_dbgfs_file type;
51 };
52 
53 /*
54  * One HPRE controller has one PF and multiple VFs, some global configurations
55  * which PF has need this structure.
56  * Just relevant for PF.
57  */
58 struct hpre_debug {
59 	struct dentry *debug_root;
60 	struct hpre_dfx dfx[HPRE_DFX_FILE_NUM];
61 	struct hpre_debugfs_file files[HPRE_DEBUGFS_FILE_NUM];
62 };
63 
64 struct hpre {
65 	struct hisi_qm qm;
66 	struct hpre_debug debug;
67 	unsigned long status;
68 };
69 
70 enum hpre_alg_type {
71 	HPRE_ALG_NC_NCRT = 0x0,
72 	HPRE_ALG_NC_CRT = 0x1,
73 	HPRE_ALG_KG_STD = 0x2,
74 	HPRE_ALG_KG_CRT = 0x3,
75 	HPRE_ALG_DH_G2 = 0x4,
76 	HPRE_ALG_DH = 0x5,
77 };
78 
79 struct hpre_sqe {
80 	__le32 dw0;
81 	__u8 task_len1;
82 	__u8 task_len2;
83 	__u8 mrttest_num;
84 	__u8 resv1;
85 	__le64 key;
86 	__le64 in;
87 	__le64 out;
88 	__le16 tag;
89 	__le16 resv2;
90 #define _HPRE_SQE_ALIGN_EXT	7
91 	__le32 rsvd1[_HPRE_SQE_ALIGN_EXT];
92 };
93 
94 struct hisi_qp *hpre_create_qp(void);
95 int hpre_algs_register(void);
96 void hpre_algs_unregister(void);
97 
98 #endif
99