summaryrefslogtreecommitdiff
path: root/cesar/mac/pbproc/inc/context.h
blob: c83cd6ce061772f8a5934f4f14425a95350f8e1c (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
#ifndef mac_pbproc_inc_context_h
#define mac_pbproc_inc_context_h
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    mac/pbproc/inc/context.h
 * \brief   PB Processing context.
 * \ingroup mac_pbproc
 */
#include "mac/pbproc/pbproc.h"
#include "mac/ca/ca.h"
#include "hal/phy/phy.h"
#include "hal/arch/arch.h"

#include "lib/slist.h"

#include "mac/pbproc/inc/fsm.h"
#include "mac/pbproc/inc/prep_mpdu.h"
#include "mac/pbproc/inc/trace.h"
#include "mac/pbproc/inc/sacki_enc.h"

#include "mac/common/timings.h"

/** General anticipation for whole PBProc. */
#define PBPROC_ANTICIP_TCK MAC_US_TO_TCK (80)

/** Anticipation for TX once MPDU is ready to be sent. */
#define PBPROC_TX_ANTICIP_TCK MAC_US_TO_TCK (22 + 5)

/** If the total number of PB exceed this threshold, request an interrupt
 * before the end of frame reception to compute SACKD. */
#define PBPROC_SACKD_ANTICIP_PB_THRESHOLD 30

/** Number of PB before frame end for first step of SACKD computation (there
 * can be only one PB in the last symbol, and at most three PB in the symbol
 * before. */
#define PBPROC_SACKD_ANTICIP_PB_NB 4

/** Maximum number of channel data retrieved after a frame reception. */
#define PBPROC_CHANDATA_NB 11

/** Delay to keep detection valid for HP 1.0 and 1.1. */
#define PBPROC_HP_DETECT_DELAY_TCK MAC_MS_TO_TCK (2000)

/** SACK data. */
struct pbproc_sackd_t
{
    /** Whether it is valid. */
    bool valid;
    /** Corresponding TEI. */
    u8 tei;
    /** Corresponding LID. */
    u8 lid;
    /** Corresponding broadcast flag. */
    bool bcast;
    /** Corresponding CFP. */
    bool cfp;
    /** Corresponding burst count. */
    u8 burst_cnt;
    /** Corresponding last MPDU count. */
    u8 last_mpdu_cnt;
    /** Whether at least one CRC is bad. */
    bool any_pb_crc_error;
    /** Prepared SACKT. */
    u8 sackt[4];
    /** Prepared SACKI. */
    pbproc_sacki_enc_t sacki_enc;
};
typedef struct pbproc_sackd_t pbproc_sackd_t;

/** Information on the received MPDU. */
struct pbproc_recv_mpdu_t
{
    /** RX parameters. */
    pbproc_rx_params_t rx_params;
    /** Block allocated to commit MPDU information. */
    pbproc_rx_desc_t *rx_desc;
    /** First PB descriptor. */
    pb_t *pb_head;
    /** Last PB descriptor. */
    pb_t *pb_tail;
    /** Number of PB. */
    uint pb_nb;
    /** First channel data descriptor. */
    pb_t *chandata_head;
    /** Number of channel data blocks. */
    uint chandata_nb;
    /** MPDU count (part of a burst). */
    uint mpdu_cnt;
    /** Acknowledgement TX date. */
    u32 ack_date;
    /** Drop received PB. */
    bool drop;
    /** SACK data. */
    pbproc_sackd_t sackd;
};
typedef struct pbproc_recv_mpdu_t pbproc_recv_mpdu_t;

/** To be committed MPDU. */
struct pbproc_commit_t
{
    /** First pending MPDU. */
    pbproc_rx_desc_t *rx_head;
    /** Last pending MPDU. */
    pbproc_rx_desc_t *rx_tail;
    /** First pending beacon. */
    pb_beacon_t *rx_beacon_head;
    /** Last pending beacon. */
    pb_beacon_t *rx_beacon_tail;
    /** First PB to be released. */
    pb_t *release_head;
    /** Last PB to be released. */
    pb_t *release_tail;
};
typedef struct pbproc_commit_t pbproc_commit_t;

/** Particular frames detection. */
struct pbproc_detect_t
{
    /** Date at which beacon detection should be reset. */
    u32 beacon_detect_expiration_date;
    /** Whether beacon detection date is valid. */
    bool beacon_detected;
    /** Last HP 1.0 detection date. */
    u32 hp10_detect_date;
    /** Whether HP 1.0 detection date is valid. */
    bool hp10_detected;
    /** Last HP 1.1 detection date. */
    u32 hp11_detect_date;
    /** Whether HP 1.1 detection date is valid. */
    bool hp11_detected;
};
typedef struct pbproc_detect_t pbproc_detect_t;

/** SPOC pending update information. */
struct pbproc_spoc_update_t
{
    /** Update steps:
     *  - program coefficients and create preamble (PHY_PREPARE_TYPE_PREAMBLE).
     *  - create PRS (PHY_PREPARE_TYPE_PRS).
     * Set to PHY_PREPARE_TYPE_NB if no update pending. */
    phy_prepare_type_t step;
    /** Whether frequency error is synchronised. */
    bool sync;
    /** SPOC coefficients, to be released once updated. */
    phy_spoc_coeff_t *coeff;
};
typedef struct pbproc_spoc_update_t pbproc_spoc_update_t;

/** Index the times array. */
#define PBPROC_TIMES_ARRAY_INDEX(hybrid, coexistence_mode) \
    ((coexistence_mode) == MAC_COEXISTENCE_HYBRID_DELIMITERS_MODE \
     ? 2 : (hybrid))

/** Precomputed times. */
struct pbproc_times_t
{
    /** Preamble + frame controls in ticks. */
    uint pre_fcs_tck;
    /** SACK in ticks. */
    uint sack_tck;
    /** RTS + RCG in ticks. */
    uint rts_rcg_tck;
    /** RTS + RCG + CTS + CMG in ticks. */
    uint rts_rcg_cts_cmg_tck;
    /** Maximum frame length in ticks. */
    uint max_fl_tck;
};
typedef struct pbproc_times_t pbproc_times_t;

/** PB Processing statistics. */
struct pbproc_stat_t
{
    /** No CTS response. */
    uint rts_fail;
    /** Lost contention in PRP. */
    uint prp_lost;
    /** Lost contention in CW. */
    uint cw_lost;
    /** AIFS. */
    uint aifs;
    /** RX: out of an allocation or too near AIFS. */
    uint rx_out_of_alloc;
    /** RX: no enough PB in pool. */
    uint rx_pool_shortage;
    /** RX: handle FC. */
    uint rx_handle_fc;
    /** RX: beacon. */
    uint rx_beacon;
    /** RX: data (SOF, RSOF). */
    uint rx_data;
    /** RX: data with ack. */
    uint rx_data_wack;
    /** RX: data without ack. */
    uint rx_data_woack;
    /** RX: data burst interrupted. */
    uint rx_data_burst_stop;
    /** RX: bad data MPDU. */
    uint rx_data_error;
    /** RX: empty frame. */
    uint rx_data_empty;
    /** RX: bad symbol nb. */
    uint rx_data_bad_symb_nb;
    /** RX: sound. */
    uint rx_sound;
    /** RX: sound complete flag sent. */
    uint rx_sound_complete;
    /** RX: sound dropped (no channel data requested or no more PB). */
    uint rx_sound_drop;
    /** RX: RTS for us. */
    uint rx_rts;
    /** RX: not for us. */
    uint rx_nfu;
    /** RX: unknown FC. */
    uint rx_fc_unknown;
    /** RX: FC CRC error. */
    uint rx_crc_error;
    /** TX: invalid (nothing to send). */
    uint tx_invalid;
    /** TX: late. */
    uint tx_late;
    /** TX: data (or beacon). */
    uint tx_data;
    /** TX: data canceled due to lost access. */
    uint tx_data_cancel;
    /** TX: MPDU with non zero mpdu_cnt. */
    uint tx_data_burst;
    /** TX: interrupted burst. */
    uint tx_data_burst_interrupted;
    /** TX: data with ack. */
    uint tx_data_wack;
    /** TX: data without ack. */
    uint tx_data_woack;
    /** TX: beacon. */
    uint tx_data_beacon;
    /** TX: data with ack, ack received. */
    uint tx_data_wack_ack;
    /** TX: data with ack, no ack received. */
    uint tx_data_wack_noack;
    /** TX: sound. */
    uint tx_sound;
    /** TX: sound, ack received. */
    uint tx_sound_ack;
    /** TX: sound, no ack received (FIXME: this includes lost access). */
    uint tx_sound_noack;
};
typedef struct pbproc_stat_t pbproc_stat_t;

/** The mighty PB Processing context. */
struct pbproc_t
{
    /** The PB Processing FSM. */
    pbproc_fsm_t fsm;
    /** Global configuration. */
    mac_config_t *config;
    /** MAC STA & MFS store. */
    mac_store_t *store;
    /** Phy context. */
    phy_t *phy;
    /** Channel access context. */
    ca_t *ca;
#if CONFIG_TRACE
    /** PBProc trace. */
    trace_buffer_t trace;
#endif /* !CONFIG_TRACE */
    /** User data passed to any callback. */
    void *user_data;
    /** MPDU RX callback. */
    pbproc_rx_cb_t rx_cb;
    /** Beacon RX callback. */
    pbproc_rx_beacon_cb_t rx_beacon_cb;
    /** Received MPDU. */
    pbproc_recv_mpdu_t recv_mpdu;
    /** Committed MPDU. */
    pbproc_commit_t commit;
    /** Obtained access. */
    ca_access_param_t access;
    /** Whether the PB Processing is activated. */
    bool activated;
    /** PBDMA status. */
    phy_pbdma_status_t pbdma_status;
    /** Prepared MPDU. */
    pbproc_prep_mpdu_t prep_mpdu;
    /** Current allocation characteristics. */
    ca_alloc_param_t alloc;
    /** Particular frames detection. */
    pbproc_detect_t detect;
    /** Pending SPOC update. */
    pbproc_spoc_update_t spoc_update;
    /** Precomputed times, indexed with "is hybrid?" + "is hybrid delimiter
     * mode". */
    pbproc_times_t times_array[3];
    /** Precomputed times for this allocation. */
    pbproc_times_t times;
    /** Symbol length in ticks, depends of the guard length. */
    uint symbol_tck[PHY_GIL_NB];
    /** Statistics. */
    pbproc_stat_t stats;
    /** RX PB pool head. */
    pb_t *rx_pool_head;
    /** RX PB pool tail. */
    pb_t *rx_pool_tail;
    /** RX PB pool size. */
    uint rx_pool_size;
    /** Channel data configurations. */
    phy_chandata_conf_t chandata_conf[PBPROC_CHANDATA_NB];
    /** Number of channel data blocks to retrieve after reception. */
    uint chandata_nb;
    /** Whether channel data should be collected for data MPDU. */
    bool chandata_data;
};
/* Forward declaration in mac/pbproc/pbproc.h. */

#endif /* mac_pbproc_inc_context_h */