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 enum adf_device_heartbeat_status {
17 	HB_DEV_UNRESPONSIVE = 0,
18 	HB_DEV_ALIVE,
19 	HB_DEV_UNSUPPORTED,
20 };
21 
22 struct adf_heartbeat {
23 	unsigned int hb_sent_counter;
24 	unsigned int hb_failed_counter;
25 	unsigned int hb_timer;
26 	u64 last_hb_check_time;
27 	bool ctrs_cnt_checked;
28 	struct hb_dma_addr {
29 		dma_addr_t phy_addr;
30 		void *virt_addr;
31 	} dma;
32 	struct {
33 		struct dentry *base_dir;
34 		struct dentry *status;
35 		struct dentry *cfg;
36 		struct dentry *sent;
37 		struct dentry *failed;
38 	} dbgfs;
39 };
40 
41 #ifdef CONFIG_DEBUG_FS
42 int adf_heartbeat_init(struct adf_accel_dev *accel_dev);
43 int adf_heartbeat_start(struct adf_accel_dev *accel_dev);
44 void adf_heartbeat_shutdown(struct adf_accel_dev *accel_dev);
45 
46 int adf_heartbeat_ms_to_ticks(struct adf_accel_dev *accel_dev, unsigned int time_ms,
47 			      uint32_t *value);
48 int adf_heartbeat_save_cfg_param(struct adf_accel_dev *accel_dev,
49 				 unsigned int timer_ms);
50 void adf_heartbeat_status(struct adf_accel_dev *accel_dev,
51 			  enum adf_device_heartbeat_status *hb_status);
52 void adf_heartbeat_check_ctrs(struct adf_accel_dev *accel_dev);
53 
54 #else
55 static inline int adf_heartbeat_init(struct adf_accel_dev *accel_dev)
56 {
57 	return 0;
58 }
59 
60 static inline int adf_heartbeat_start(struct adf_accel_dev *accel_dev)
61 {
62 	return 0;
63 }
64 
65 static inline void adf_heartbeat_shutdown(struct adf_accel_dev *accel_dev)
66 {
67 }
68 
69 static inline int adf_heartbeat_save_cfg_param(struct adf_accel_dev *accel_dev,
70 					       unsigned int timer_ms)
71 {
72 	return 0;
73 }
74 
75 static inline void adf_heartbeat_check_ctrs(struct adf_accel_dev *accel_dev)
76 {
77 }
78 #endif
79 #endif /* ADF_HEARTBEAT_H_ */
80