xref: /linux/drivers/crypto/intel/qat/qat_common/adf_telemetry.h (revision 4b660dbd9ee2059850fd30e0df420ca7a38a1856)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2023 Intel Corporation. */
3 #ifndef ADF_TELEMETRY_H
4 #define ADF_TELEMETRY_H
5 
6 #include <linux/bits.h>
7 #include <linux/mutex.h>
8 #include <linux/types.h>
9 #include <linux/workqueue.h>
10 
11 #include "icp_qat_fw_init_admin.h"
12 
13 struct adf_accel_dev;
14 struct adf_tl_dbg_counter;
15 struct dentry;
16 
17 #define ADF_TL_SL_CNT_COUNT		\
18 	(sizeof(struct icp_qat_fw_init_admin_slice_cnt) / sizeof(__u8))
19 
20 #define TL_CAPABILITY_BIT		BIT(1)
21 /* Interval within device writes data to DMA region. Value in milliseconds. */
22 #define ADF_TL_DATA_WR_INTERVAL_MS	1000
23 /* Interval within timer interrupt should be handled. Value in milliseconds. */
24 #define ADF_TL_TIMER_INT_MS		(ADF_TL_DATA_WR_INTERVAL_MS / 2)
25 
26 #define ADF_TL_RP_REGS_DISABLED		(0xff)
27 
28 struct adf_tl_hw_data {
29 	size_t layout_sz;
30 	size_t slice_reg_sz;
31 	size_t rp_reg_sz;
32 	size_t msg_cnt_off;
33 	const struct adf_tl_dbg_counter *dev_counters;
34 	const struct adf_tl_dbg_counter *sl_util_counters;
35 	const struct adf_tl_dbg_counter *sl_exec_counters;
36 	const struct adf_tl_dbg_counter *rp_counters;
37 	u8 num_hbuff;
38 	u8 cpp_ns_per_cycle;
39 	u8 bw_units_to_bytes;
40 	u8 num_dev_counters;
41 	u8 num_rp_counters;
42 	u8 max_rp;
43 };
44 
45 struct adf_telemetry {
46 	struct adf_accel_dev *accel_dev;
47 	atomic_t state;
48 	u32 hbuffs;
49 	int hb_num;
50 	u32 msg_cnt;
51 	dma_addr_t regs_data_p; /* bus address for DMA mapping */
52 	void *regs_data; /* virtual address for DMA mapping */
53 	/**
54 	 * @regs_hist_buff: array of pointers to copies of the last @hbuffs
55 	 * values of @regs_data
56 	 */
57 	void **regs_hist_buff;
58 	struct dentry *dbg_dir;
59 	u8 *rp_num_indexes;
60 	/**
61 	 * @regs_hist_lock: protects from race conditions between write and read
62 	 * to the copies referenced by @regs_hist_buff
63 	 */
64 	struct mutex regs_hist_lock;
65 	/**
66 	 * @wr_lock: protects from concurrent writes to debugfs telemetry files
67 	 */
68 	struct mutex wr_lock;
69 	struct delayed_work work_ctx;
70 	struct icp_qat_fw_init_admin_slice_cnt slice_cnt;
71 };
72 
73 #ifdef CONFIG_DEBUG_FS
74 int adf_tl_init(struct adf_accel_dev *accel_dev);
75 int adf_tl_start(struct adf_accel_dev *accel_dev);
76 void adf_tl_stop(struct adf_accel_dev *accel_dev);
77 void adf_tl_shutdown(struct adf_accel_dev *accel_dev);
78 int adf_tl_run(struct adf_accel_dev *accel_dev, int state);
79 int adf_tl_halt(struct adf_accel_dev *accel_dev);
80 #else
81 static inline int adf_tl_init(struct adf_accel_dev *accel_dev)
82 {
83 	return 0;
84 }
85 
86 static inline int adf_tl_start(struct adf_accel_dev *accel_dev)
87 {
88 	return 0;
89 }
90 
91 static inline void adf_tl_stop(struct adf_accel_dev *accel_dev)
92 {
93 }
94 
95 static inline void adf_tl_shutdown(struct adf_accel_dev *accel_dev)
96 {
97 }
98 #endif /* CONFIG_DEBUG_FS */
99 #endif /* ADF_TELEMETRY_H */
100