xref: /linux/drivers/crypto/intel/qat/qat_common/adf_heartbeat.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright(c) 2023 Intel Corporation */
3 
4 #ifndef ADF_HEARTBEAT_H_
5 #define ADF_HEARTBEAT_H_
6 
7 #include <linux/types.h>
8 
9 struct adf_accel_dev;
10 struct dentry;
11 
12 #define ADF_CFG_HB_TIMER_MIN_MS 200
13 #define ADF_CFG_HB_TIMER_DEFAULT_MS 500
14 #define ADF_CFG_HB_COUNT_THRESHOLD 3
15 
16 #define ADF_CFG_HB_RESET_MS 5000
17 
18 enum adf_device_heartbeat_status {
19 	HB_DEV_UNRESPONSIVE = 0,
20 	HB_DEV_ALIVE,
21 	HB_DEV_UNSUPPORTED,
22 };
23 
24 /* Heartbeat counter pair */
25 struct hb_cnt_pair {
26 	__u16 resp_heartbeat_cnt;
27 	__u16 req_heartbeat_cnt;
28 };
29 
30 struct adf_heartbeat {
31 	unsigned int hb_sent_counter;
32 	unsigned int hb_failed_counter;
33 	unsigned int hb_timer;
34 	u64 last_hb_check_time;
35 	u64 last_hb_reset_time;
36 	bool ctrs_cnt_checked;
37 	struct hb_dma_addr {
38 		dma_addr_t phy_addr;
39 		void *virt_addr;
40 	} dma;
41 	struct {
42 		struct dentry *base_dir;
43 		struct dentry *status;
44 		struct dentry *cfg;
45 		struct dentry *sent;
46 		struct dentry *failed;
47 #ifdef CONFIG_CRYPTO_DEV_QAT_ERROR_INJECTION
48 		struct dentry *inject_error;
49 #endif
50 	} dbgfs;
51 };
52 
53 #ifdef CONFIG_DEBUG_FS
54 int adf_heartbeat_init(struct adf_accel_dev *accel_dev);
55 int adf_heartbeat_start(struct adf_accel_dev *accel_dev);
56 void adf_heartbeat_shutdown(struct adf_accel_dev *accel_dev);
57 
58 int adf_heartbeat_ms_to_ticks(struct adf_accel_dev *accel_dev, unsigned int time_ms,
59 			      uint32_t *value);
60 int adf_heartbeat_save_cfg_param(struct adf_accel_dev *accel_dev,
61 				 unsigned int timer_ms);
62 void adf_heartbeat_status(struct adf_accel_dev *accel_dev,
63 			  enum adf_device_heartbeat_status *hb_status);
64 void adf_heartbeat_check_ctrs(struct adf_accel_dev *accel_dev);
65 
66 #ifdef CONFIG_CRYPTO_DEV_QAT_ERROR_INJECTION
67 int adf_heartbeat_inject_error(struct adf_accel_dev *accel_dev);
68 #else
adf_heartbeat_inject_error(struct adf_accel_dev * accel_dev)69 static inline int adf_heartbeat_inject_error(struct adf_accel_dev *accel_dev)
70 {
71 	return -EPERM;
72 }
73 #endif
74 
75 #else
adf_heartbeat_init(struct adf_accel_dev * accel_dev)76 static inline int adf_heartbeat_init(struct adf_accel_dev *accel_dev)
77 {
78 	return 0;
79 }
80 
adf_heartbeat_start(struct adf_accel_dev * accel_dev)81 static inline int adf_heartbeat_start(struct adf_accel_dev *accel_dev)
82 {
83 	return 0;
84 }
85 
adf_heartbeat_shutdown(struct adf_accel_dev * accel_dev)86 static inline void adf_heartbeat_shutdown(struct adf_accel_dev *accel_dev)
87 {
88 }
89 
adf_heartbeat_save_cfg_param(struct adf_accel_dev * accel_dev,unsigned int timer_ms)90 static inline int adf_heartbeat_save_cfg_param(struct adf_accel_dev *accel_dev,
91 					       unsigned int timer_ms)
92 {
93 	return 0;
94 }
95 
adf_heartbeat_check_ctrs(struct adf_accel_dev * accel_dev)96 static inline void adf_heartbeat_check_ctrs(struct adf_accel_dev *accel_dev)
97 {
98 }
99 #endif
100 #endif /* ADF_HEARTBEAT_H_ */
101