Loading...
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
13struct adf_accel_dev;
14struct adf_tl_dbg_counter;
15struct 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
28struct 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 u8 max_sl_cnt;
44};
45
46struct adf_telemetry {
47 struct adf_accel_dev *accel_dev;
48 atomic_t state;
49 u32 hbuffs;
50 int hb_num;
51 u32 msg_cnt;
52 dma_addr_t regs_data_p; /* bus address for DMA mapping */
53 void *regs_data; /* virtual address for DMA mapping */
54 /**
55 * @regs_hist_buff: array of pointers to copies of the last @hbuffs
56 * values of @regs_data
57 */
58 void **regs_hist_buff;
59 struct dentry *dbg_dir;
60 u8 *rp_num_indexes;
61 /**
62 * @regs_hist_lock: protects from race conditions between write and read
63 * to the copies referenced by @regs_hist_buff
64 */
65 struct mutex regs_hist_lock;
66 /**
67 * @wr_lock: protects from concurrent writes to debugfs telemetry files
68 */
69 struct mutex wr_lock;
70 struct delayed_work work_ctx;
71 struct icp_qat_fw_init_admin_slice_cnt slice_cnt;
72};
73
74#ifdef CONFIG_DEBUG_FS
75int adf_tl_init(struct adf_accel_dev *accel_dev);
76int adf_tl_start(struct adf_accel_dev *accel_dev);
77void adf_tl_stop(struct adf_accel_dev *accel_dev);
78void adf_tl_shutdown(struct adf_accel_dev *accel_dev);
79int adf_tl_run(struct adf_accel_dev *accel_dev, int state);
80int adf_tl_halt(struct adf_accel_dev *accel_dev);
81#else
82static inline int adf_tl_init(struct adf_accel_dev *accel_dev)
83{
84 return 0;
85}
86
87static inline int adf_tl_start(struct adf_accel_dev *accel_dev)
88{
89 return 0;
90}
91
92static inline void adf_tl_stop(struct adf_accel_dev *accel_dev)
93{
94}
95
96static inline void adf_tl_shutdown(struct adf_accel_dev *accel_dev)
97{
98}
99#endif /* CONFIG_DEBUG_FS */
100#endif /* ADF_TELEMETRY_H */