2 ******************************************************************************
6 * Copyright (C) RESWIN 2015-2020
8 ******************************************************************************
11 #ifndef _ECRNX_FW_TRACE_H_
12 #define _ECRNX_FW_TRACE_H_
14 #include <linux/mutex.h>
15 #include <linux/wait.h>
16 #include <linux/workqueue.h>
18 #define FW_TRACE_READ_DUMP_max_SIZE 1824
20 * struct ecrnx_fw_trace_desc - Trace buffer info as provided by fw in ipc
22 * @pattern: Synchro pattern
23 * @start: Index of first entry in trace buffer
24 * @end: Index of last entry in trace buffer
25 * @size: Size, in 16bits words, od the trace buffer
26 * @offset: Offset, in bytest, to the start of the buffer from the address of
28 * @nb_compo: Number of filterable component (16LSB) synchro pattern (16 MSB)
29 * @offset_compo: Offset, in bytest, to the start of the component activation
30 * table from the address of this field.
32 struct ecrnx_fw_trace_ipc_desc {
33 volatile uint16_t pattern;
34 volatile uint32_t start;
35 volatile uint32_t end;
36 volatile uint32_t size;
37 volatile uint32_t offset;
38 volatile uint32_t nb_compo;
39 volatile uint32_t offset_compo;
43 * struct ecrnx_fw_trace_buf - Info for trace buffer in shared memory
45 * @lock: Address of the synchro word
46 * @data: Address of the trace buffer
47 * @size: Size, in 16bits words, of the trace buffer
48 * @start: Address on the current index (in 16 bits words) of the first trace
50 * @end: Address on the current index (in 16 bits words) of the last trace
51 * entry. If *end > size, it means that the trace buffer contains no traces.
52 * @reset_idx: Increased each time the trace buffer is reset
53 * (by calling _ecrnx_fw_trace_reset())
54 * @nb_compo: Size of the compo_table
55 * @compo_table: Table containing component filter status.
57 struct ecrnx_fw_trace_buf {
58 volatile uint16_t *lock;
61 volatile uint32_t *start;
62 volatile uint32_t *end;
64 unsigned int nb_compo;
65 uint32_t *compo_table;
69 * struct ecrnx_fw_trace_local_buf - Info for a local trace buffer
71 * @data: Address of the local buffer
72 * @data_end: Address after the end of the local buffer
73 * @size: Size, in 16bits words, oth the local buffer
74 * @read: Pointer to the next trace entry to read
75 * @write: Pointer to the next entry to write
76 * @nb_entries: Number of trace entries ready to be read
77 * @free_space: Free space, in 16bits words, in the buffer.
78 * @last_read: Address of the last entry read in the shared buffer
79 * @last_read_value: First word of the last trace entry read.
80 * @reset_idx: Reset index. If it doesn't match share buffer index then it
81 * means that share buffer has been resetted since last read.
83 struct ecrnx_fw_trace_local_buf {
92 uint16_t last_read_value;
94 uint16_t * show_reset;
99 * struct ecrnx_fw_trace - info to handle several reader of the shared buffer
101 * @buf: shared trace buffer.
102 * @mutex: mutex, used to prevent several reader updating shared buffer at the
104 * @queue: queue, used to delay reader.
105 * @work: work used to periodically check for new traces in shared buffer.
106 * @last_read_index: Last read index from shared buffer
107 * @closing: Indicate whether is driver is being removed, meaning that reader
108 * should no longer wait no new traces
110 struct ecrnx_fw_trace {
111 struct ecrnx_fw_trace_buf buf;
113 wait_queue_head_t queue;
114 struct delayed_work work;
119 int ecrnx_fw_trace_init(struct ecrnx_fw_trace *trace,
120 struct ecrnx_fw_trace_ipc_desc *ipc);
121 void ecrnx_fw_trace_deinit(struct ecrnx_fw_trace *trace);
123 int ecrnx_fw_trace_buf_init(struct ecrnx_fw_trace_buf *shared_buf,
124 struct ecrnx_fw_trace_ipc_desc *ipc);
126 int _ecrnx_fw_trace_reset(struct ecrnx_fw_trace *trace, bool lock);
127 void _ecrnx_fw_trace_dump(struct ecrnx_fw_trace_buf *trace);
129 int ecrnx_fw_trace_alloc_local(struct ecrnx_fw_trace_local_buf *local,
131 void ecrnx_fw_trace_free_local(struct ecrnx_fw_trace_local_buf *local);
134 size_t ecrnx_fw_trace_read(struct ecrnx_fw_trace *trace,
135 struct ecrnx_fw_trace_local_buf *local_buf,
136 bool dont_wait, char __user *user_buf, size_t size);
139 size_t ecrnx_fw_trace_level_read(struct ecrnx_fw_trace *trace,
140 char __user *user_buf, size_t len, loff_t *ppos);
141 size_t ecrnx_fw_trace_level_write(struct ecrnx_fw_trace *trace,
142 const char __user *user_buf, size_t len);
145 int ecrnx_fw_trace_config_filters(struct ecrnx_fw_trace_buf *trace_buf,
146 struct ecrnx_fw_trace_ipc_desc *ipc, char *ftl);
148 int ecrnx_fw_trace_save_filters(struct ecrnx_fw_trace *trace);
149 int ecrnx_fw_trace_restore_filters(struct ecrnx_fw_trace *trace);
152 * ecrnx_fw_trace_empty() - Check if shared buffer is empty
154 * @shared_buf: Pointer to shared buffer
156 static inline bool ecrnx_fw_trace_empty(struct ecrnx_fw_trace_buf *shared_buf)
158 return (*shared_buf->end >= shared_buf->size);
161 #endif /* _ECRNX_FW_TRACE_H_ */