summaryrefslogtreecommitdiff
path: root/mac/pctt_region.h
blob: 8e7830cdcb15956711417269d10195f13d050770 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
 * This file is part of the UWB stack for linux.
 *
 * Copyright (c) 2021-2022 Qorvo US, Inc.
 *
 * This software is provided under the GNU General Public License, version 2
 * (GPLv2), as well as under a Qorvo commercial license.
 *
 * You may choose to use this software under the terms of the GPLv2 License,
 * version 2 ("GPLv2"), as published by the Free Software Foundation.
 * You should have received a copy of the GPLv2 along with this program.  If
 * not, see <http://www.gnu.org/licenses/>.
 *
 * This program is distributed under the GPLv2 in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GPLv2 for more
 * details.
 *
 * If you cannot meet the requirements of the GPLv2, you may not use this
 * software for any purpose without first obtaining a commercial license from
 * Qorvo. Please contact Qorvo to inquire about licensing terms.
 */

#ifndef PCTT_REGION_H
#define PCTT_REGION_H

#include <linux/kernel.h>
#include <net/mcps802154_schedule.h>
#include <net/vendor_cmd.h>
#include <linux/types.h>
#include <net/pctt_region_params.h>
#include <net/pctt_region_nl.h>

#include "pctt_session.h"

#define PCTT_SESSION_ID 0
#define PCTT_BOOLEAN_MAX 1
#define PCTT_FRAMES_MAX 2

#define PCTT_TIMESTAMP_SHIFT 9
/**
 * map_rad_q11_to_deg_q7() - Map a Fixed Point angle to a signed 16-bit integer
 * @ang_rad_q11: angle as Q11 fixed_point value in range [-PI, PI]
 *
 * Return: the angle mapped to deg q7
 */
static inline s16 map_rad_q11_to_deg_q7(int ang_rad_q11)
{
	/* 180 / (pi * (1 << 4)) => ~3,581. */
	return ang_rad_q11 * 3581 / 1000;
}

/**
 * struct pctt_test_per_rx_results - PER_RX result for report.
 */
struct pctt_test_per_rx_results {
	/**
	 * @attempts: No. of RX attempts.
	 */
	u32 attempts;
	/**
	 * @acq_detect: No. of times signal was detected.
	 */
	u32 acq_detect;
	/**
	 * @acq_reject: No. of times signal was rejected.
	 */
	u32 acq_reject;
	/**
	 * @rx_fail: No. of times RX did not go beyond ACQ stage.
	 */
	u32 rx_fail;
	/**
	 * @sync_cir_ready: No. of times sync CIR ready event was received.
	 */
	u32 sync_cir_ready;
	/**
	 * @sfd_fail: No. of time RX was stuck at either ACQ detect or sync CIR ready.
	 */
	u32 sfd_fail;
	/**
	 * @sfd_found: No. of times SFD was found.
	 */
	u32 sfd_found;
	/**
	 * @phr_dec_error: No. of times PHR decode failed.
	 */
	u32 phr_dec_error;
	/**
	 * @phr_bit_error: No. of times PHR bits in error.
	 */
	u32 phr_bit_error;
	/**
	 * @psdu_dec_error: No. of times payload decode failed.
	 */
	u32 psdu_dec_error;
	/**
	 * @psdu_bit_error: No. of times payload bits in error.
	 */
	u32 psdu_bit_error;
	/**
	 * @sts_found: No. of times STS detection was successful.
	 */
	u32 sts_found;
	/**
	 * @eof: No. of times end of frame event was triggered.
	 */
	u32 eof;
	/**
	 * @rssi: Received signal strength indication (RSSI).
	 */
	u8 rssi;
};

/**
 * struct pctt_test_rx_results - RX result for report.
 */
struct pctt_test_rx_results {
	/**
	 * @rx_done_ts_int: Integer part of timestamp 1/124.8Mhz ticks.
	 */
	u32 rx_done_ts_int;
	/**
	 * @rx_done_ts_frac: Fractional part of timestamp in 1/(128 * 499.2Mhz) ticks.
	 */
	u16 rx_done_ts_frac;
	/**
	 * @aoa_azimuth: AoA azimuth in degrees and it is a signed value in Q9.7 format.
	 */
	s16 aoa_azimuth;
	/**
	 * @aoa_elevation: AoA elevation in degrees and it is a signed value in Q9.7 format.
	 */
	s16 aoa_elevation;
	/**
	 * @phr: Received PHR (bits 0-12 as per IEEE spec).
	 */
	u16 phr;
	/**
	 * @psdu_data_len: Length of PSDU Data(N).
	 */
	u16 psdu_data_len;
	/**
	 * @toa_gap: ToA of main path minus ToA of first path in nanosecond.
	 */
	u8 toa_gap;
	/**
	 * @rssi: Received signal strength indication (RSSI).
	 */
	u8 rssi;
	/**
	 * @psdu_data: Received PSDU Data[0:N] bytes.
	 */
	u8 psdu_data[PCTT_PAYLOAD_MAX_LEN];
};

/**
 * struct pctt_test_ss_twr_results - SS_TWR result for report.
 */
struct pctt_test_ss_twr_results {
	/**
	 * @tx_timestamps_rctu: Timestamps of transmitted frame.
	 */
	u64 tx_timestamps_rctu;
	/**
	 * @rx_timestamps_rctu: Timestamps of received frame.
	 */
	u64 rx_timestamps_rctu;
	/**
	 * @measurement_rctu: Contains Tround time of Initiator or
	 * Treply time of Responder depending on DEVICE_ROLE option.
	 */
	u32 measurement_rctu;
	/**
	 * @pdoa_azimuth_deg_q7: Phase Difference of Arrival Azimuth in deg Q7
	 */
	s16 pdoa_azimuth_deg_q7;
	/**
	 * @aoa_azimuth_deg_q7: AoA Azimuth in deg Q7
	 */
	s16 aoa_azimuth_deg_q7;
	/**
	 * @pdoa_elevation_deg_q7: Phase Difference of Arrival Elevation in deg Q7
	 */
	s16 pdoa_elevation_deg_q7;
	/**
	 * @aoa_elevation_deg_q7: AoA Elevation in deg Q7
	 */
	s16 aoa_elevation_deg_q7;
	/**
	 * @rssi: Received signal strength indication (RSSI).
	 */
	u8 rssi;
};

/**
 * struct pctt_test_loopback_results - LOOPBACK result for report.
 */
struct pctt_test_loopback_results {
	/**
	 * @rssi: Received signal strength indication (RSSI).
	 */
	u8 rssi;
	/**
	 * @tx_ts_int: Integer part of TX timestamp in 1/124.8 us. resolution.
	 */
	u32 tx_ts_int;
	/**
	 * @tx_ts_frac: Fractional part of TX timestamp in 1/124.8/512 us. resolution.
	 */
	u16 tx_ts_frac;
	/**
	 * @rx_ts_int: Integer part of Rx timestamp in 1/124.8 us. resolution.
	 */
	u32 rx_ts_int;
	/**
	 * @rx_ts_frac: Fractional part of RX timestamp in 1/124.8/512 us. resolution.
	 */
	u16 rx_ts_frac;
};

/**
 * union pctt_tests_results - All commands notifications.
 */
union pctt_tests_results {
	/**
	 * @per_rx: Result of the PER_RX command.
	 */
	struct pctt_test_per_rx_results per_rx;
	/**
	 * @rx: Result of the RX command.
	 */
	struct pctt_test_rx_results rx;
	/**
	 * @ss_twr: Result of the SS_TWR command.
	 */
	struct pctt_test_ss_twr_results ss_twr;
	/**
	 * @loopback: Result of the LOOPBACK command.
	 */
	struct pctt_test_loopback_results loopback;
};

/**
 * union pctt_results - Main notification for all commands.
 */
struct pctt_results {
	/**
	 * @status: Result of the command done.
	 */
	enum pctt_status_ranging status;
	/**
	 * @tests: Result detail.
	 */
	union pctt_tests_results tests;
};

/**
 * struct pctt_slot - Information on an active slot.
 */
struct pctt_slot {
	/**
	 * @is_tx: Is transmit frame?
	 */
	bool is_tx;
	/**
	 * @is_rframe: Is ranging frame?
	 */
	bool is_rframe;
	/**
	 * @is_immediate: True when the frame is immediate.
	 */
	bool is_immediate;
	/**
	 * @timeout_dtu: see (mcps802154_rx_frame_config).timeout_dtu.
	 */
	int timeout_dtu;
};

struct pctt_local {
	/**
	 * @region: Region instance returned to MCPS.
	 */
	struct mcps802154_region region;
	/**
	 * @llhw: Low-level device pointer.
	 */
	struct mcps802154_llhw *llhw;
	/**
	 * @access: Access returned to MCPS.
	 */
	struct mcps802154_access access;
	/**
	 * @session: Unique session on the PCTT.
	 */
	struct pctt_session session;
	/**
	 * @frames: Access frames referenced from access.
	 */
	struct mcps802154_access_frame frames[PCTT_FRAMES_MAX];
	/**
	 * @sts_params: STS parameters for access frames.
	 */
	struct mcps802154_sts_params sts_params[PCTT_FRAMES_MAX];
	/**
	 * @slots: Descriptions of each active slots for the current session.
	 */
	struct pctt_slot slots[PCTT_FRAMES_MAX];
	/**
	 * @results: Test result used for notification at the end of test.
	 */
	struct pctt_results results;
	/**
	 * @frames_remaining_nb: Number of frame remaining to do for the current test.
	 */
	int frames_remaining_nb;
};

static inline struct pctt_local *
region_to_local(struct mcps802154_region *region)
{
	return container_of(region, struct pctt_local, region);
}

static inline struct pctt_local *
access_to_local(struct mcps802154_access *access)
{
	return container_of(access, struct pctt_local, access);
}

/**
 * pctt_report() - PCTT Report.
 * @local: pctt context.
 */
void pctt_report(struct pctt_local *local);

/**
 * pctt_session_notify_state_change() - Notify session state change to upper layers.
 * @local: context.
 */
void pctt_session_notify_state_change(struct pctt_local *local);

#endif /* PCTT_REGION_H */