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 /* 14 * type used in qm sqc DW6. 15 * 0 - Algorithm which has been supported in V2, like RSA, DH and so on; 16 * 1 - ECC algorithm in V3. 17 */ 18 #define HPRE_V2_ALG_TYPE 0 19 #define HPRE_V3_ECC_ALG_TYPE 1 20 21 enum { 22 HPRE_CLUSTER0, 23 HPRE_CLUSTER1, 24 HPRE_CLUSTER2, 25 HPRE_CLUSTER3 26 }; 27 28 enum hpre_ctrl_dbgfs_file { 29 HPRE_CURRENT_QM, 30 HPRE_CLEAR_ENABLE, 31 HPRE_CLUSTER_CTRL, 32 HPRE_DEBUG_FILE_NUM, 33 }; 34 35 enum hpre_dfx_dbgfs_file { 36 HPRE_SEND_CNT, 37 HPRE_RECV_CNT, 38 HPRE_SEND_FAIL_CNT, 39 HPRE_SEND_BUSY_CNT, 40 HPRE_OVER_THRHLD_CNT, 41 HPRE_OVERTIME_THRHLD, 42 HPRE_INVALID_REQ_CNT, 43 HPRE_DFX_FILE_NUM 44 }; 45 46 #define HPRE_CLUSTERS_NUM_V2 (HPRE_CLUSTER3 + 1) 47 #define HPRE_CLUSTERS_NUM_V3 1 48 #define HPRE_CLUSTERS_NUM_MAX HPRE_CLUSTERS_NUM_V2 49 #define HPRE_DEBUGFS_FILE_NUM (HPRE_DEBUG_FILE_NUM + HPRE_CLUSTERS_NUM_MAX - 1) 50 51 struct hpre_debugfs_file { 52 int index; 53 enum hpre_ctrl_dbgfs_file type; 54 spinlock_t lock; 55 struct hpre_debug *debug; 56 }; 57 58 struct hpre_dfx { 59 atomic64_t value; 60 enum hpre_dfx_dbgfs_file type; 61 }; 62 63 /* 64 * One HPRE controller has one PF and multiple VFs, some global configurations 65 * which PF has need this structure. 66 * Just relevant for PF. 67 */ 68 struct hpre_debug { 69 struct hpre_dfx dfx[HPRE_DFX_FILE_NUM]; 70 struct hpre_debugfs_file files[HPRE_DEBUGFS_FILE_NUM]; 71 }; 72 73 struct hpre { 74 struct hisi_qm qm; 75 struct hpre_debug debug; 76 unsigned long status; 77 }; 78 79 enum hpre_alg_type { 80 HPRE_ALG_NC_NCRT = 0x0, 81 HPRE_ALG_NC_CRT = 0x1, 82 HPRE_ALG_KG_STD = 0x2, 83 HPRE_ALG_KG_CRT = 0x3, 84 HPRE_ALG_DH_G2 = 0x4, 85 HPRE_ALG_DH = 0x5, 86 HPRE_ALG_ECC_MUL = 0xD, 87 /* shared by x25519 and x448, but x448 is not supported now */ 88 HPRE_ALG_CURVE25519_MUL = 0x10, 89 }; 90 91 struct hpre_sqe { 92 __le32 dw0; 93 __u8 task_len1; 94 __u8 task_len2; 95 __u8 mrttest_num; 96 __u8 resv1; 97 __le64 key; 98 __le64 in; 99 __le64 out; 100 __le16 tag; 101 __le16 resv2; 102 #define _HPRE_SQE_ALIGN_EXT 7 103 __le32 rsvd1[_HPRE_SQE_ALIGN_EXT]; 104 }; 105 106 struct hisi_qp *hpre_create_qp(u8 type); 107 int hpre_algs_register(struct hisi_qm *qm); 108 void hpre_algs_unregister(struct hisi_qm *qm); 109 110 #endif 111