Loading...
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
9struct adf_accel_dev;
10struct 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
18enum adf_device_heartbeat_status {
19 HB_DEV_UNRESPONSIVE = 0,
20 HB_DEV_ALIVE,
21 HB_DEV_UNSUPPORTED,
22};
23
24/* Heartbeat counter pair */
25struct hb_cnt_pair {
26 __u16 resp_heartbeat_cnt;
27 __u16 req_heartbeat_cnt;
28};
29
30struct 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
54int adf_heartbeat_init(struct adf_accel_dev *accel_dev);
55int adf_heartbeat_start(struct adf_accel_dev *accel_dev);
56void adf_heartbeat_shutdown(struct adf_accel_dev *accel_dev);
57
58int adf_heartbeat_ms_to_ticks(struct adf_accel_dev *accel_dev, unsigned int time_ms,
59 uint32_t *value);
60int adf_heartbeat_save_cfg_param(struct adf_accel_dev *accel_dev,
61 unsigned int timer_ms);
62void adf_heartbeat_status(struct adf_accel_dev *accel_dev,
63 enum adf_device_heartbeat_status *hb_status);
64void adf_heartbeat_check_ctrs(struct adf_accel_dev *accel_dev);
65
66#ifdef CONFIG_CRYPTO_DEV_QAT_ERROR_INJECTION
67int adf_heartbeat_inject_error(struct adf_accel_dev *accel_dev);
68#else
69static inline int adf_heartbeat_inject_error(struct adf_accel_dev *accel_dev)
70{
71 return -EPERM;
72}
73#endif
74
75#else
76static inline int adf_heartbeat_init(struct adf_accel_dev *accel_dev)
77{
78 return 0;
79}
80
81static inline int adf_heartbeat_start(struct adf_accel_dev *accel_dev)
82{
83 return 0;
84}
85
86static inline void adf_heartbeat_shutdown(struct adf_accel_dev *accel_dev)
87{
88}
89
90static inline int adf_heartbeat_save_cfg_param(struct adf_accel_dev *accel_dev,
91 unsigned int timer_ms)
92{
93 return 0;
94}
95
96static inline void adf_heartbeat_check_ctrs(struct adf_accel_dev *accel_dev)
97{
98}
99#endif
100#endif /* ADF_HEARTBEAT_H_ */