net:wireless:Support eswin usb wifi ECR6600U
[platform/kernel/linux-starfive.git] / drivers / net / wireless / eswin / ecrnx_fw_trace.h
1 /**
2  ******************************************************************************
3  *
4  * ecrnx_fw_trace.h
5  *
6  * Copyright (C) RESWIN 2015-2020
7  *
8  ******************************************************************************
9  */
10
11 #ifndef _ECRNX_FW_TRACE_H_
12 #define _ECRNX_FW_TRACE_H_
13
14 #include <linux/mutex.h>
15 #include <linux/wait.h>
16 #include <linux/workqueue.h>
17
18 #define    FW_TRACE_READ_DUMP_max_SIZE 1824
19 /**
20  * struct ecrnx_fw_trace_desc - Trace buffer info as provided by fw in ipc
21  *
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
27  * this field.
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.
31  */
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;
40 };
41
42 /**
43  * struct ecrnx_fw_trace_buf - Info for trace buffer in shared memory
44  *
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
49  * entry.
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.
56  */
57 struct ecrnx_fw_trace_buf {
58     volatile uint16_t *lock;
59     uint16_t *data;
60     uint32_t size;
61     volatile uint32_t *start;
62     volatile uint32_t *end;
63     int reset_idx;
64     unsigned int nb_compo;
65     uint32_t *compo_table;
66 };
67
68 /**
69  * struct ecrnx_fw_trace_local_buf - Info for a local trace buffer
70  *
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.
82  */
83 struct ecrnx_fw_trace_local_buf {
84     uint16_t *data;
85     uint16_t *data_end;
86     uint32_t size;
87     uint16_t *read;
88     uint16_t *write;
89     uint16_t nb_entries;
90     uint32_t free_space;
91     uint16_t *last_read;
92     uint16_t last_read_value;
93     int reset_idx;
94     uint16_t * show_reset;
95 };
96
97
98 /**
99  * struct ecrnx_fw_trace - info to handle several reader of the shared buffer
100  *
101  * @buf: shared trace buffer.
102  * @mutex: mutex, used to prevent several reader updating shared buffer at the
103  * same time.
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
109  */
110 struct ecrnx_fw_trace {
111     struct ecrnx_fw_trace_buf buf;
112     struct mutex mutex;
113     wait_queue_head_t queue;
114     struct delayed_work work;
115     int last_read_index;
116     bool closing;
117 };
118
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);
122
123 int ecrnx_fw_trace_buf_init(struct ecrnx_fw_trace_buf *shared_buf,
124                            struct ecrnx_fw_trace_ipc_desc *ipc);
125
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);
128
129 int ecrnx_fw_trace_alloc_local(struct ecrnx_fw_trace_local_buf *local,
130                               int size);
131 void ecrnx_fw_trace_free_local(struct ecrnx_fw_trace_local_buf *local);
132
133
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);
137
138
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);
143
144
145 int ecrnx_fw_trace_config_filters(struct ecrnx_fw_trace_buf *trace_buf,
146                                  struct ecrnx_fw_trace_ipc_desc *ipc, char *ftl);
147
148 int ecrnx_fw_trace_save_filters(struct ecrnx_fw_trace *trace);
149 int ecrnx_fw_trace_restore_filters(struct ecrnx_fw_trace *trace);
150
151 /**
152  * ecrnx_fw_trace_empty() - Check if shared buffer is empty
153  *
154  * @shared_buf: Pointer to shared buffer
155  */
156 static inline bool ecrnx_fw_trace_empty(struct ecrnx_fw_trace_buf *shared_buf)
157 {
158     return (*shared_buf->end >= shared_buf->size);
159 }
160
161 #endif /* _ECRNX_FW_TRACE_H_ */