xref: /wlan-driver/qcacld-3.0/core/dp/ol/inc/ol_htt_rx_api.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2011-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * @file ol_htt_rx_api.h
22  * @brief Specify the rx HTT API functions called by the host data SW.
23  * @details
24  *  This file declares the HTT API functions that are specifically
25  *  related to receive processing.
26  *  In particular, this file specifies methods of the abstract HTT rx
27  *  descriptor, and functions to iterate though a series of rx descriptors
28  *  and rx MSDU buffers.
29  */
30 #ifndef _OL_HTT_RX_API__H_
31 #define _OL_HTT_RX_API__H_
32 
33 #include <osdep.h>              /* uint16_t, etc. */
34 #include <qdf_nbuf.h>           /* qdf_nbuf_t */
35 #include <qdf_types.h>          /* bool */
36 
37 #include <htt.h>                /* HTT_RX_IND_MPDU_STATUS */
38 #include <ol_htt_api.h>         /* htt_pdev_handle */
39 
40 #include <cds_ieee80211_common.h>
41 #include <ol_vowext_dbg_defs.h>
42 
43 /*================ constants and types used in the rx API ===================*/
44 
45 #define HTT_RSSI_INVALID 0x7fff
46 
47 #ifndef EXTERNAL_USE_ONLY
48 
49 #define IEEE80211_LSIG_LEN  3
50 #define IEEE80211_HTSIG_LEN 6
51 #define IEEE80211_SB_LEN    2
52 
53 /**
54  * struct ieee80211_rx_status - RX status
55  * @rs_numchains: Number of chains
56  * @rs_flags: Flags
57  * @rs_rssi: RSSI (noise floor adjusted)
58  * @rs_abs_rssi: Absolute RSSI
59  * @rs_datarate: Data rate received
60  * @rs_rateieee: ieee rate
61  * @rs_ratephy: Phy rate
62  * @rs_rssictl: RSSI (noise floor adjusted)
63  * @rs_rssiextn: RSSI (noise floor adjusted)
64  * @rs_isvalidrssi: rs_rssi is valid or not
65  * @rs_phymode: Phy mode
66  * @rs_freq: Received frequency
67  * @rs_tstamp: Received timestamp
68  * @rs_full_chan: Detail channel structure of recv frame.
69  *                It could be NULL if not available
70  * @rs_isaggr: Is Aggreggated?
71  * @rs_isapsd: Is APSD?
72  * @rs_noisefloor: Noise floor
73  * @rs_channel: Channel
74  * @rs_rpttstamp: txbf report time stamp
75  * @rs_cryptodecapcount: Crypto bytes decapped/demic'ed
76  * @rs_padspace: No. of padding bytes present after header
77  *               in wbuf
78  * @rs_qosdecapcount: QoS/HTC bytes decapped
79  * @rs_lsig: lsig
80  * @rs_htsig: HT sig
81  * @rs_servicebytes: Received service bytes
82  */
83 struct ieee80211_rx_status {
84 	int rs_numchains;
85 	int rs_flags;
86 	int rs_rssi;
87 	int rs_abs_rssi;
88 	int rs_datarate;
89 	int rs_rateieee;
90 	int rs_ratephy;
91 
92 	uint8_t rs_rssictl[IEEE80211_MAX_ANTENNA];
93 	uint8_t rs_rssiextn[IEEE80211_MAX_ANTENNA];
94 	uint8_t rs_isvalidrssi;
95 
96 	enum ieee80211_phymode rs_phymode;
97 	int rs_freq;
98 
99 	union {
100 		uint8_t data[8];
101 		uint64_t tsf;
102 	} rs_tstamp;
103 
104 	struct ieee80211_channel *rs_full_chan;
105 
106 	uint8_t rs_isaggr;
107 	uint8_t rs_isapsd;
108 	int16_t rs_noisefloor;
109 	uint16_t rs_channel;
110 #ifdef ATH_SUPPORT_TxBF
111 	uint32_t rs_rpttstamp;
112 #endif
113 
114 	/*
115 	 * The following counts are meant to assist in stats calculation.
116 	 *  These variables are incremented only in specific situations, and
117 	 *  should not be relied upon for any purpose other than the original
118 	 *  stats related purpose they have been introduced for.
119 	 */
120 
121 	uint16_t rs_cryptodecapcount;
122 	uint8_t rs_padspace;
123 	uint8_t rs_qosdecapcount;
124 
125 	/* End of stats calculation related counts. */
126 
127 	uint8_t rs_lsig[IEEE80211_LSIG_LEN];
128 	uint8_t rs_htsig[IEEE80211_HTSIG_LEN];
129 	uint8_t rs_servicebytes[IEEE80211_SB_LEN];
130 
131 };
132 #endif /* EXTERNAL_USE_ONLY */
133 
134 /**
135  * struct ocb_rx_stats_hdr_t - RX stats header
136  * @version:		The version must be 1.
137  * @length:		The length of this structure
138  * @channel_freq:	The center frequency for the packet
139  * @rssi_cmb:		combined RSSI from all chains
140  * @rssi[4]:		rssi for chains 0 through 3 (for 20 MHz bandwidth)
141  * @tsf32:		timestamp in TSF units
142  * @timestamp_microsec:	timestamp in microseconds
143  * @datarate:		MCS index
144  * @timestamp_submicrosec: submicrosecond portion of the timestamp
145  * @ext_tid:		Extended TID
146  * @reserved:		Ensure the size of the structure is a multiple of 4.
147  *			Must be 0.
148  *
149  * When receiving an OCB packet, the RX stats is sent to the user application
150  * so that the user application can do processing based on the RX stats.
151  * This structure will be preceded by an ethernet header with
152  * the proto field set to 0x8152. This struct includes various RX
153  * parameters including RSSI, data rate, and center frequency.
154  */
155 PREPACK struct ocb_rx_stats_hdr_t {
156 	uint16_t version;
157 	uint16_t length;
158 	uint16_t channel_freq;
159 	int16_t rssi_cmb;
160 	int16_t rssi[4];
161 	uint32_t tsf32;
162 	uint32_t timestamp_microsec;
163 	uint8_t datarate;
164 	uint8_t timestamp_submicrosec;
165 	uint8_t ext_tid;
166 	uint8_t reserved;
167 };
168 
169 /*================ rx indication message field access methods ===============*/
170 
171 /**
172  * @brief Check if a rx indication message has a rx reorder flush command.
173  * @details
174  *  Space is reserved in each rx indication message for a rx reorder flush
175  *  command, to release specified MPDUs from the rx reorder holding array
176  *  before processing the new MPDUs referenced by the rx indication message.
177  *  This rx reorder flush command contains a flag to show whether the command
178  *  is valid within a given rx indication message.
179  *  This function checks the validity flag from the rx indication
180  *  flush command IE within the rx indication message.
181  *
182  * @param pdev - the HTT instance the rx data was received on
183  * @param rx_ind_msg - the netbuf containing the rx indication message
184  * @return
185  *      1 - the message's rx flush command is valid and should be processed
186  *          before processing new rx MPDUs,
187  *      -OR-
188  *      0 - the message's rx flush command is invalid and should be ignored
189  */
190 int htt_rx_ind_flush(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg);
191 
192 /**
193  * @brief Return the sequence number starting the range of MPDUs to flush.
194  * @details
195  *  Read the fields of the rx indication message that identify the start
196  *  and end of the range of MPDUs to flush from the rx reorder holding array
197  *  and send on to subsequent stages of rx processing.
198  *  These sequence numbers are the 6 LSBs of the 12-bit 802.11 sequence
199  *  number.  These sequence numbers are masked with the block ack window size,
200  *  rounded up to a power of two (minus one, to create a bitmask) to obtain
201  *  the corresponding index into the rx reorder holding array.
202  *  The series of MPDUs to flush includes the one specified by the start
203  *  sequence number.
204  *  The series of MPDUs to flush excludes the one specified by the end
205  *  sequence number; the MPDUs up to but not including the end sequence number
206  *  are to be flushed.
207  *  These start and end seq num fields are only valid if the "flush valid"
208  *  flag is set.
209  *
210  * @param pdev - the HTT instance the rx data was received on
211  * @param rx_ind_msg - the netbuf containing the rx indication message
212  * @param seq_num_start - (call-by-reference output) sequence number
213  *      for the start of the range of MPDUs to flush
214  * @param seq_num_end - (call-by-reference output) sequence number
215  *      for the end of the range of MPDUs to flush
216  */
217 void
218 htt_rx_ind_flush_seq_num_range(htt_pdev_handle pdev,
219 			       qdf_nbuf_t rx_ind_msg,
220 			       unsigned *seq_num_start, unsigned *seq_num_end);
221 
222 /**
223  * @brief Check if a rx indication message has a rx reorder release command.
224  * @details
225  *  Space is reserved in each rx indication message for a rx reorder release
226  *  command, to release specified MPDUs from the rx reorder holding array
227  *  after processing the new MPDUs referenced by the rx indication message.
228  *  This rx reorder release command contains a flag to show whether the command
229  *  is valid within a given rx indication message.
230  *  This function checks the validity flag from the rx indication
231  *  release command IE within the rx indication message.
232  *
233  * @param pdev - the HTT instance the rx data was received on
234  * @param rx_ind_msg - the netbuf containing the rx indication message
235  * @return
236  *      1 - the message's rx release command is valid and should be processed
237  *          after processing new rx MPDUs,
238  *      -OR-
239  *      0 - the message's rx release command is invalid and should be ignored
240  */
241 int htt_rx_ind_release(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg);
242 
243 /**
244  * @brief Return the sequence number starting the range of MPDUs to release.
245  * @details
246  *  Read the fields of the rx indication message that identify the start
247  *  and end of the range of MPDUs to release from the rx reorder holding
248  *  array and send on to subsequent stages of rx processing.
249  *  These sequence numbers are the 6 LSBs of the 12-bit 802.11 sequence
250  *  number.  These sequence numbers are masked with the block ack window size,
251  *  rounded up to a power of two (minus one, to create a bitmask) to obtain
252  *  the corresponding index into the rx reorder holding array.
253  *  The series of MPDUs to release includes the one specified by the start
254  *  sequence number.
255  *  The series of MPDUs to release excludes the one specified by the end
256  *  sequence number; the MPDUs up to but not including the end sequence number
257  *  are to be released.
258  *  These start and end seq num fields are only valid if the "release valid"
259  *  flag is set.
260  *
261  * @param pdev - the HTT instance the rx data was received on
262  * @param rx_ind_msg - the netbuf containing the rx indication message
263  * @param seq_num_start - (call-by-reference output) sequence number
264  *        for the start of the range of MPDUs to release
265  * @param seq_num_end - (call-by-reference output) sequence number
266  *        for the end of the range of MPDUs to release
267  */
268 void
269 htt_rx_ind_release_seq_num_range(htt_pdev_handle pdev,
270 				 qdf_nbuf_t rx_ind_msg,
271 				 unsigned int *seq_num_start,
272 				 unsigned int *seq_num_end);
273 
274 /*
275  * For now, the host HTT -> host data rx status enum
276  * exactly matches the target HTT -> host HTT rx status enum;
277  * no translation is required.
278  * However, the host data SW should only use the htt_rx_status,
279  * so that in the future a translation from target HTT rx status
280  * to host HTT rx status can be added, if the need ever arises.
281  */
282 enum htt_rx_status {
283 	htt_rx_status_unknown = HTT_RX_IND_MPDU_STATUS_UNKNOWN,
284 	htt_rx_status_ok = HTT_RX_IND_MPDU_STATUS_OK,
285 	htt_rx_status_err_fcs = HTT_RX_IND_MPDU_STATUS_ERR_FCS,
286 	htt_rx_status_err_dup = HTT_RX_IND_MPDU_STATUS_ERR_DUP,
287 	htt_rx_status_err_replay = HTT_RX_IND_MPDU_STATUS_ERR_REPLAY,
288 	htt_rx_status_err_inv_peer = HTT_RX_IND_MPDU_STATUS_ERR_INV_PEER,
289 	htt_rx_status_ctrl_mgmt_null = HTT_RX_IND_MPDU_STATUS_MGMT_CTRL,
290 	htt_rx_status_tkip_mic_err = HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR,
291 
292 	htt_rx_status_err_misc = HTT_RX_IND_MPDU_STATUS_ERR_MISC
293 };
294 
295 /**
296  * @brief Check the status MPDU range referenced by a rx indication message.
297  * @details
298  *  Check the status of a range of MPDUs referenced by a rx indication message.
299  *  This status determines whether the MPDUs should be processed or discarded.
300  *  If the status is OK, then the MPDUs within the range should be processed
301  *  as usual.
302  *  Otherwise (FCS error, duplicate error, replay error, unknown sender error,
303  *  etc.) the MPDUs within the range should be discarded.
304  *
305  * @param pdev - the HTT instance the rx data was received on
306  * @param rx_ind_msg - the netbuf containing the rx indication message
307  * @param mpdu_range_num - which MPDU range within the rx ind msg to check,
308  *        starting from 0
309  * @param status - (call-by-reference output) MPDU status
310  * @param mpdu_count - (call-by-reference output) count of MPDUs comprising
311  *        the specified MPDU range
312  */
313 void
314 htt_rx_ind_mpdu_range_info(htt_pdev_handle pdev,
315 			   qdf_nbuf_t rx_ind_msg,
316 			   int mpdu_range_num,
317 			   enum htt_rx_status *status, int *mpdu_count);
318 
319 /**
320  * @brief Return the RSSI provided in a rx indication message.
321  * @details
322  *  Return the RSSI from an rx indication message, converted to dBm units.
323  *
324  * @param pdev - the HTT instance the rx data was received on
325  * @param rx_ind_msg - the netbuf containing the rx indication message
326  * @return RSSI in dBm, or HTT_INVALID_RSSI
327  */
328 int16_t
329 htt_rx_ind_rssi_dbm(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg);
330 
331 int16_t
332 htt_rx_ind_rssi_dbm_chain(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg,
333 			  int8_t chain);
334 
335 void
336 htt_rx_ind_legacy_rate(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg,
337 		       uint8_t *legacy_rate, uint8_t *legacy_rate_sel);
338 
339 
340 void
341 htt_rx_ind_timestamp(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg,
342 		     uint32_t *timestamp_microsec,
343 		     uint8_t *timestamp_submicrosec);
344 
345 uint32_t
346 htt_rx_ind_tsf32(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg);
347 
348 uint8_t
349 htt_rx_ind_ext_tid(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg);
350 
351 
352 /*==================== rx MPDU descriptor access methods ====================*/
353 
354 /**
355  * @brief Check if the retry bit is set in Rx-descriptor
356  * @details
357  * This function returns the retry bit of the 802.11 header for the
358  *  provided rx MPDU descriptor.
359  *
360  * @param pdev - the handle of the physical device the rx data was received on
361  * @param msdu_desc - the abstract descriptor for the MSDU in question
362  * @return boolean -- true if retry is set, false otherwise
363  */
364 extern
365 bool (*htt_rx_mpdu_desc_retry)(
366 		htt_pdev_handle pdev, void *mpdu_desc);
367 
368 /**
369  * @brief Return a rx MPDU's sequence number.
370  * @details
371  *  This function returns the LSBs of the 802.11 sequence number for the
372  *  provided rx MPDU descriptor.
373  *  Depending on the system, 6-12 LSBs from the 802.11 sequence number are
374  *  returned.  (Typically, either the 8 or 12 LSBs are returned.)
375  *  This sequence number is masked with the block ack window size,
376  *  rounded up to a power of two (minus one, to create a bitmask) to obtain
377  *  the corresponding index into the rx reorder holding array.
378  *
379  * @param pdev - the HTT instance the rx data was received on
380  * @param mpdu_desc - the abstract descriptor for the MPDU in question
381  * @return the LSBs of the sequence number for the MPDU
382  */
383 extern uint16_t
384 (*htt_rx_mpdu_desc_seq_num)(htt_pdev_handle pdev, void *mpdu_desc,
385 			    bool update_seq_num);
386 
387 /**
388  * @brief Return a rx MPDU's rx reorder array index, based on sequence number.
389  * @details
390  *  This function returns a sequence-number based index into the rx
391  *  reorder array for the specified MPDU.
392  *  In some systems, this rx reorder array is simply the LSBs of the
393  *  sequence number, or possibly even the full sequence number.
394  *  To support such systems, the returned index has to be masked with
395  *  the power-of-two array size before using the value to index the
396  *  rx reorder array.
397  *  In other systems, this rx reorder array index is
398  *      (sequence number) % (block ack window size)
399  *
400  * @param pdev - the HTT instance the rx data was received on
401  * @param mpdu_desc - the abstract descriptor for the MPDU in question
402  * @return the rx reorder array index the MPDU goes into
403  */
404 /* use sequence number (or LSBs thereof) as rx reorder array index */
405 #define htt_rx_mpdu_desc_reorder_idx htt_rx_mpdu_desc_seq_num
406 
407 union htt_rx_pn_t {
408 	/* WEP: 24-bit PN */
409 	uint32_t pn24;
410 
411 	/* TKIP or CCMP: 48-bit PN */
412 	uint64_t pn48;
413 
414 	/* WAPI: 128-bit PN */
415 	uint64_t pn128[2];
416 };
417 
418 /**
419  * @brief Find the packet number (PN) for a MPDU.
420  * @details
421  *  This function only applies when the rx PN check is configured to be
422  *  performed in the host rather than the target, and on peers using a
423  *  security type for which a PN check applies.
424  *  The pn_len_bits argument is used to determine which element of the
425  *  htt_rx_pn_t union to deposit the PN value read from the MPDU descriptor
426  *  into.
427  *  A 24-bit PN is deposited into pn->pn24.
428  *  A 48-bit PN is deposited into pn->pn48.
429  *  A 128-bit PN is deposited in little-endian order into pn->pn128.
430  *  Specifically, bits 63:0 of the PN are copied into pn->pn128[0], while
431  *  bits 127:64 of the PN are copied into pn->pn128[1].
432  *
433  * @param pdev - the HTT instance the rx data was received on
434  * @param mpdu_desc - the abstract descriptor for the MPDU in question
435  * @param pn - the location to copy the packet number into
436  * @param pn_len_bits - the PN size, in bits
437  */
438 extern void (*htt_rx_mpdu_desc_pn)(htt_pdev_handle pdev,
439 				   void *mpdu_desc,
440 				   union htt_rx_pn_t *pn, int pn_len_bits);
441 
442 /**
443  * @brief This function Returns the TID value from the Rx descriptor
444  *                             for Low Latency driver
445  * @details
446  *  This function returns the TID set in the 802.11 QoS Control for the MPDU
447  *  in the packet header, by looking at the mpdu_start of the Rx descriptor.
448  *  Rx descriptor gets a copy of the TID from the MAC.
449  * @pdev:  Handle (pointer) to HTT pdev.
450  * @param mpdu_desc - the abstract descriptor for the MPDU in question
451  * @return:        Actual TID set in the packet header.
452  */
453 extern
454 uint8_t (*htt_rx_mpdu_desc_tid)(
455 			htt_pdev_handle pdev, void *mpdu_desc);
456 
457 /**
458  * @brief Return the TSF timestamp indicating when a MPDU was received.
459  * @details
460  *  This function provides the timestamp indicating when the PPDU that
461  *  the specified MPDU belongs to was received.
462  *
463  * @param pdev - the HTT instance the rx data was received on
464  * @param mpdu_desc - the abstract descriptor for the MPDU in question
465  * @return 32 LSBs of TSF time at which the MPDU's PPDU was received
466  */
467 uint32_t htt_rx_mpdu_desc_tsf32(htt_pdev_handle pdev, void *mpdu_desc);
468 
469 /**
470  * @brief Return the 802.11 header of the MPDU
471  * @details
472  *  This function provides a pointer to the start of the 802.11 header
473  *  of the Rx MPDU
474  *
475  * @param pdev - the HTT instance the rx data was received on
476  * @param mpdu_desc - the abstract descriptor for the MPDU in question
477  * @return pointer to 802.11 header of the received MPDU
478  */
479 char *htt_rx_mpdu_wifi_hdr_retrieve(htt_pdev_handle pdev, void *mpdu_desc);
480 
481 /**
482  * @brief Return the RSSI provided in a rx descriptor.
483  * @details
484  *  Return the RSSI from a rx descriptor, converted to dBm units.
485  *
486  * @param pdev - the HTT instance the rx data was received on
487  * @param mpdu_desc - the abstract descriptor for the MPDU in question
488  * @return RSSI in dBm, or HTT_INVALID_RSSI
489  */
490 int16_t htt_rx_mpdu_desc_rssi_dbm(htt_pdev_handle pdev, void *mpdu_desc);
491 
492 /*==================== rx MSDU descriptor access methods ====================*/
493 
494 /**
495  * @brief Check if a MSDU completes a MPDU.
496  * @details
497  *  When A-MSDU aggregation is used, a single MPDU will consist of
498  *  multiple MSDUs.  This function checks a MSDU's rx descriptor to
499  *  see whether the MSDU is the final MSDU within a MPDU.
500  *
501  * @param pdev - the handle of the physical device the rx data was received on
502  * @param msdu_desc - the abstract descriptor for the MSDU in question
503  * @return
504  *      0 - there are subsequent MSDUs within the A-MSDU / MPDU
505  *      -OR-
506  *      1 - this is the last MSDU within its MPDU
507  */
508 extern bool (*htt_rx_msdu_desc_completes_mpdu)(htt_pdev_handle pdev,
509 					       void *msdu_desc);
510 
511 /**
512  * @brief Check if a MSDU is first msdu of MPDU.
513  * @details
514  *  When A-MSDU aggregation is used, a single MPDU will consist of
515  *  multiple MSDUs.  This function checks a MSDU's rx descriptor to
516  *  see whether the MSDU is the first MSDU within a MPDU.
517  *
518  * @param pdev - the handle of the physical device the rx data was received on
519  * @param msdu_desc - the abstract descriptor for the MSDU in question
520  * @return
521  *      0 - this is interior MSDU in the A-MSDU / MPDU
522  *      -OR-
523  *      1 - this is the first MSDU within its MPDU
524  */
525 extern bool (*htt_rx_msdu_first_msdu_flag)(htt_pdev_handle pdev,
526 					   void *msdu_desc);
527 
528 /**
529  * @brief Retrieve encrypt bit from a mpdu desc.
530  * @details
531  *  Fw will pass all the frame  to the host whether encrypted or not, and will
532  *  indicate the encrypt flag in the desc, this function is to get the info
533  *  and used to make a judge whether should make pn check, because
534  *  non-encrypted frames always get the same pn number 0.
535  *
536  * @param pdev - the HTT instance the rx data was received on
537  * @param mpdu_desc - the abstract descriptor for the MPDU in question
538  * @return 0 - the frame was not encrypted
539  *         1 - the frame was encrypted
540  */
541 extern bool (*htt_rx_mpdu_is_encrypted)(htt_pdev_handle pdev, void *mpdu_desc);
542 
543 /**
544  * @brief Indicate whether a rx desc has a WLAN unicast vs. mcast/bcast flag.
545  * @details
546  *  A flag indicating whether a MPDU was delivered over WLAN as unicast or
547  *  multicast/broadcast may be only valid once per MPDU (LL), or within each
548  *  rx descriptor for the MSDUs within the MPDU (HL).  (In practice, it is
549  *  unlikely that A-MSDU aggregation will be used in HL, so typically HL will
550  *  only have one MSDU per MPDU anyway.)
551  *  This function indicates whether the specified rx descriptor contains
552  *  a WLAN ucast vs. mcast/bcast flag.
553  *
554  * @param pdev - the HTT instance the rx data was received on
555  * @param msdu_desc - the abstract descriptor for the MSDU in question
556  * @return
557  *      0 - The rx descriptor does not contain a WLAN ucast vs. mcast flag.
558  *      -OR-
559  *      1 - The rx descriptor has a valid WLAN ucast vs. mcast flag.
560  */
561 extern int (*htt_rx_msdu_has_wlan_mcast_flag)(htt_pdev_handle pdev,
562 					      void *msdu_desc);
563 
564 /**
565  * @brief Indicate whether a MSDU was received as unicast or mcast/bcast
566  * @details
567  *  Indicate whether the MPDU that the specified MSDU belonged to was
568  *  delivered over the WLAN as unicast, or as multicast/broadcast.
569  *  This query can only be performed on rx descriptors for which
570  *  htt_rx_msdu_has_wlan_mcast_flag is true.
571  *
572  * @param pdev - the HTT instance the rx data was received on
573  * @param msdu_desc - the abstract descriptor for the MSDU in question
574  * @return
575  *      0 - The MSDU was delivered over the WLAN as unicast.
576  *      -OR-
577  *      1 - The MSDU was delivered over the WLAN as broadcast or multicast.
578  */
579 extern bool (*htt_rx_msdu_is_wlan_mcast)(htt_pdev_handle pdev, void *msdu_desc);
580 
581 /**
582  * @brief Indicate whether a MSDU was received as a fragmented frame
583  * @details
584  *  This query can only be performed on LL system.
585  *
586  * @param pdev - the HTT instance the rx data was received on
587  * @param msdu_desc - the abstract descriptor for the MSDU in question
588  * @return
589  *      0 - The MSDU was a non-fragmented frame.
590  *      -OR-
591  *      1 - The MSDU was fragmented frame.
592  */
593 extern int (*htt_rx_msdu_is_frag)(htt_pdev_handle pdev, void *msdu_desc);
594 
595 /**
596  * @brief Indicate if a MSDU should be delivered to the OS shim or discarded.
597  * @details
598  *  Indicate whether a MSDU should be discarded or delivered to the OS shim.
599  *
600  * @param pdev - the HTT instance the rx data was received on
601  * @param msdu_desc - the abstract descriptor for the MSDU in question
602  * @return
603  *      0 - The MSDU should be delivered to the OS
604  *      -OR-
605  *      non-zero - The MSDU should not be delivered to the OS.
606  *          If the "forward" flag is set, it should be forwarded to tx.
607  *          Else, it should be discarded.
608  */
609 int htt_rx_msdu_discard(htt_pdev_handle pdev, void *msdu_desc);
610 
611 /**
612  * @brief Indicate whether a MSDU should be forwarded to tx.
613  * @details
614  *  Indicate whether a MSDU should be forwarded to tx, e.g. for intra-BSS
615  *  STA-to-STA forwarding in an AP, or for multicast echo in an AP.
616  *
617  * @param pdev - the HTT instance the rx data was received on
618  * @param msdu_desc - the abstract descriptor for the MSDU in question
619  * @return
620  *      0 - The MSDU should not be forwarded
621  *      -OR-
622  *      non-zero - The MSDU should be forwarded.
623  *          If the "discard" flag is set, then the original MSDU can be
624  *          directly forwarded into the tx path.
625  *          Else, a copy (clone?) of the rx MSDU needs to be created to
626  *          send to the tx path.
627  */
628 int htt_rx_msdu_forward(htt_pdev_handle pdev, void *msdu_desc);
629 
630 /**
631  * @brief Indicate whether a MSDU's contents need to be inspected.
632  * @details
633  *  Indicate whether the host data SW needs to examine the contents of the
634  *  received MSDU, and based on the packet type infer what special handling
635  *  to provide for the MSDU.
636  *
637  * @param pdev - the HTT instance the rx data was received on
638  * @param msdu_desc - the abstract descriptor for the MSDU in question
639  * @return
640  *      0 - No inspection + special handling is required.
641  *      -OR-
642  *      non-zero - Inspect the MSDU contents to infer what special handling
643  *          to apply to the MSDU.
644  */
645 int htt_rx_msdu_inspect(htt_pdev_handle pdev, void *msdu_desc);
646 
647 /**
648  * @brief Provide all action specifications for a rx MSDU
649  * @details
650  *  Provide all action specifications together.  This provides the same
651  *  information in a single function call as would be provided by calling
652  *  the functions htt_rx_msdu_discard, htt_rx_msdu_forward, and
653  *  htt_rx_msdu_inspect.
654  *
655  * @param pdev - the HTT instance the rx data was received on
656  * @param msdu_desc - the abstract descriptor for the MSDU in question
657  * @param[out] discard - 1: discard the MSDU, 0: deliver the MSDU to the OS
658  * @param[out] forward - 1: forward the rx MSDU to tx, 0: no rx->tx forward
659  * @param[out] inspect - 1: process according to MSDU contents, 0: no inspect
660  */
661 void
662 htt_rx_msdu_actions(htt_pdev_handle pdev,
663 		    void *msdu_desc, int *discard, int *forward, int *inspect);
664 
665 /**
666  * @brief Get the key id sent in IV of the frame
667  * @details
668  *  Provide the key index octet which is taken from IV.
669  *  This is valid only for the first MSDU.
670  *
671  * @param pdev - the HTT instance the rx data was received on
672  * @param msdu_desc - the abstract descriptor for the MSDU in question
673  * @key_id - Key id octet
674  * @return indication of whether key id access is successful
675  *   true - Success
676  *   false - if this is not first msdu
677  */
678 extern bool
679 (*htt_rx_msdu_desc_key_id)(htt_pdev_handle pdev,
680 			   void *mpdu_desc, uint8_t *key_id);
681 
682 extern bool
683 (*htt_rx_msdu_chan_info_present)(
684 	htt_pdev_handle pdev,
685 	void *mpdu_desc);
686 
687 extern bool
688 (*htt_rx_msdu_center_freq)(
689 	htt_pdev_handle pdev,
690 	struct ol_txrx_peer_t *peer,
691 	void *mpdu_desc,
692 	uint16_t *primary_chan_center_freq_mhz,
693 	uint16_t *contig_chan1_center_freq_mhz,
694 	uint16_t *contig_chan2_center_freq_mhz,
695 	uint8_t *phy_mode);
696 
697 /*====================== rx MSDU + descriptor delivery ======================*/
698 
699 /**
700  * @brief Return a linked-list of network buffer holding the next rx A-MSDU.
701  * @details
702  *  In some systems, the rx MSDUs are uploaded along with the rx
703  *  indication message, while in other systems the rx MSDUs are uploaded
704  *  out of band, via MAC DMA.
705  *  This function provides an abstract way to obtain a linked-list of the
706  *  next MSDUs, regardless of whether the MSDU was delivered in-band with
707  *  the rx indication message, or out of band through MAC DMA.
708  *  In a LL system, this function returns a linked list of the one or more
709  *  MSDUs that together comprise an A-MSDU.
710  *  In a HL system, this function returns a degenerate linked list consisting
711  *  of a single MSDU (head_msdu == tail_msdu).
712  *  This function also makes sure each MSDU's rx descriptor can be found
713  *  through the MSDU's network buffer.
714  *  In most systems, this is trivial - a single network buffer stores both
715  *  the MSDU rx descriptor and the MSDU payload.
716  *  In systems where the rx descriptor is in a separate buffer from the
717  *  network buffer holding the MSDU payload, a pointer to the rx descriptor
718  *  has to be stored in the network buffer.
719  *  After this function call, the descriptor for a given MSDU can be
720  *  obtained via the htt_rx_msdu_desc_retrieve function.
721  *
722  * @param pdev - the HTT instance the rx data was received on
723  * @param rx_ind_msg - the netbuf containing the rx indication message
724  * @param head_msdu - call-by-reference network buffer handle, which gets set
725  *      in this function to point to the head MSDU of the A-MSDU
726  * @param tail_msdu - call-by-reference network buffer handle, which gets set
727  *      in this function to point to the tail MSDU of the A-MSDU, or the
728  *      same MSDU that the head_msdu points to if only a single MSDU is
729  *      delivered at a time.
730  * @return indication of whether any MSDUs in the AMSDU use chaining:
731  * 0 - no buffer chaining
732  * 1 - buffers are chained
733  */
734 extern int
735 (*htt_rx_amsdu_pop)(htt_pdev_handle pdev,
736 		    qdf_nbuf_t rx_ind_msg,
737 		    qdf_nbuf_t *head_msdu, qdf_nbuf_t *tail_msdu,
738 		    uint32_t *msdu_count);
739 
740 extern int
741 (*htt_rx_frag_pop)(htt_pdev_handle pdev,
742 		   qdf_nbuf_t rx_ind_msg,
743 		   qdf_nbuf_t *head_msdu, qdf_nbuf_t *tail_msdu,
744 		   uint32_t *msdu_count);
745 
746 /**
747  * @brief Return the maximum number of available msdus currently
748  *
749  * @param pdev - the HTT instance the rx data was received on
750  */
751 extern int
752 (*htt_rx_offload_msdu_cnt)(
753     htt_pdev_handle pdev);
754 
755 /**
756  * @brief Return a linked list of buffers holding one MSDU
757  *  In some systems the buffers are delivered along with offload delivery
758  *  indication message itself, while in other systems the buffers are uploaded
759  *  out of band, via MAC DMA.
760  * @details
761  *  This function provides an abstract way to obtain a linked-list of the
762  *  buffers corresponding to an msdu, regardless of whether the MSDU was
763  *  delivered in-band with the rx indication message, or out of band through
764  *  MAC DMA.
765  *  In a LL system, this function returns a linked list of one or more
766  *  buffers corresponding to an MSDU
767  *  In a HL system , TODO
768  *
769  * @param pdev - the HTT instance the rx data was received on
770  * @param offload_deliver_msg - the nebuf containing the offload deliver message
771  * @param head_msdu - call-by-reference network buffer handle, which gets set in
772  *      this function to the head buffer of this MSDU
773  * @param tail_msdu - call-by-reference network buffer handle, which gets set in
774  *      this function to the tail buffer of this MSDU
775  */
776 extern int
777 (*htt_rx_offload_msdu_pop)(htt_pdev_handle pdev,
778 			   qdf_nbuf_t offload_deliver_msg,
779 			   int *vdev_id,
780 			   int *peer_id,
781 			   int *tid,
782 			   uint8_t *fw_desc,
783 			   qdf_nbuf_t *head_buf, qdf_nbuf_t *tail_buf);
784 
785 /**
786  * @brief Return the rx descriptor for the next rx MPDU.
787  * @details
788  *  The rx MSDU descriptors may be uploaded as part of the rx indication
789  *  message, or delivered separately out of band.
790  *  This function provides an abstract way to obtain the next MPDU descriptor,
791  *  regardless of whether the MPDU descriptors are delivered in-band with
792  *  the rx indication message, or out of band.
793  *  This is used to iterate through the series of MPDU descriptors referenced
794  *  by a rx indication message.
795  *  The htt_rx_amsdu_pop function should be called before this function
796  *  (or at least before using the returned rx descriptor handle), so that
797  *  the cache location for the rx descriptor will be flushed before the
798  *  rx descriptor gets used.
799  *
800  * @param pdev - the HTT instance the rx data was received on
801  * @param rx_ind_msg - the netbuf containing the rx indication message
802  * @return next abstract rx descriptor from the series of MPDUs referenced
803  *      by an rx ind msg
804  */
805 extern void *
806 (*htt_rx_mpdu_desc_list_next)(htt_pdev_handle pdev, qdf_nbuf_t rx_ind_msg);
807 
808 /**
809  * @brief Retrieve a previously-stored rx descriptor from a MSDU buffer.
810  * @details
811  *  The data SW will call the htt_rx_msdu_desc_link macro/function to
812  *  link a MSDU's rx descriptor with the buffer holding the MSDU payload.
813  *  This function retrieves the rx MSDU descriptor.
814  *
815  * @param pdev - the HTT instance the rx data was received on
816  * @param msdu - the buffer containing the MSDU payload
817  * @return the corresponding abstract rx MSDU descriptor
818  */
819 extern void *
820 (*htt_rx_msdu_desc_retrieve)(htt_pdev_handle pdev, qdf_nbuf_t msdu);
821 
822 /**
823  * @brief Free both an rx MSDU descriptor and the associated MSDU buffer.
824  * @details
825  *  Usually the WLAN driver does not free rx MSDU buffers, but needs to
826  *  do so when an invalid frame (e.g. FCS error) was deposited into the
827  *  queue of rx buffers.
828  *  This function frees both the rx descriptor and the rx frame.
829  *  On some systems, the rx descriptor and rx frame are stored in the
830  *  same buffer, and thus one free suffices for both objects.
831  *  On other systems, the rx descriptor and rx frame are stored
832  *  separately, so distinct frees are internally needed.
833  *  However, in either case, the rx descriptor has been associated with
834  *  the MSDU buffer, and can be retrieved by htt_rx_msdu_desc_retrieve.
835  *  Hence, it is only necessary to provide the MSDU buffer; the HTT SW
836  *  internally finds the corresponding MSDU rx descriptor.
837  *
838  * @param htt_pdev - the HTT instance the rx data was received on
839  * @param rx_msdu_desc - rx descriptor for the MSDU being freed
840  * @param msdu - rx frame buffer for the MSDU being freed
841  */
842 void htt_rx_desc_frame_free(htt_pdev_handle htt_pdev, qdf_nbuf_t msdu);
843 
844 /**
845  * @brief Look up and free the rx descriptor for a MSDU.
846  * @details
847  *  When the driver delivers rx frames to the OS, it first needs
848  *  to free the associated rx descriptors.
849  *  In some systems the rx descriptors are allocated in the same
850  *  buffer as the rx frames, so this operation is a no-op.
851  *  In other systems, the rx descriptors are stored separately
852  *  from the rx frames, so the rx descriptor has to be freed.
853  *  The descriptor is located from the MSDU buffer with the
854  *  htt_rx_desc_frame_free macro/function.
855  *
856  * @param htt_pdev - the HTT instance the rx data was received on
857  * @param msdu - rx frame buffer for the rx MSDU descriptor being freed
858  */
859 void htt_rx_msdu_desc_free(htt_pdev_handle htt_pdev, qdf_nbuf_t msdu);
860 
861 /**
862  * @brief Add new MSDU buffers for the target to fill.
863  * @details
864  *  In some systems, the underlying upload mechanism (HIF) allocates new rx
865  *  buffers itself.  In other systems, the underlying upload mechanism
866  *  (MAC DMA) needs to be provided with new rx buffers.
867  *  This function is used as an abstract method to indicate to the underlying
868  *  data upload mechanism when it is an appropriate time to allocate new rx
869  *  buffers.
870  *  If the allocation is automatically handled, a la HIF, then this function
871  *  call is ignored.
872  *  If the allocation has to be done explicitly, a la MAC DMA, then this
873  *  function provides the context and timing for such replenishment
874  *  allocations.
875  *
876  * @param pdev - the HTT instance the rx data will be received on
877  */
878 void htt_rx_msdu_buff_replenish(htt_pdev_handle pdev);
879 
880 /**
881  * @brief Add new MSDU buffers for the target to fill.
882  * @details
883  *  This is full_reorder_offload version of the replenish function.
884  *  In full_reorder, FW sends HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND
885  *  msg to host. It includes the number of MSDUs. Thgis will be fed
886  *  into htt_rx_msdu_buff_in_order_replenish function.
887  *  The reason for creating yet another function is to avoid checks
888  *  in real-time.
889  *
890  * @param pdev - the HTT instance the rx data will be received on
891  * @num        - number of buffers to replenish
892  *
893  * Return: number of buffers actually replenished
894  */
895 #ifndef CONFIG_HL_SUPPORT
896 int htt_rx_msdu_buff_in_order_replenish(htt_pdev_handle pdev, uint32_t num);
897 #else
898 static inline
htt_rx_msdu_buff_in_order_replenish(htt_pdev_handle pdev,uint32_t num)899 int htt_rx_msdu_buff_in_order_replenish(htt_pdev_handle pdev, uint32_t num)
900 {
901 	return 0;
902 }
903 #endif
904 
905 /**
906  * @brief Links list of MSDUs into an single MPDU. Updates RX stats
907  * @details
908  *  When HW MSDU splitting is turned on each MSDU in an AMSDU MPDU occupies
909  *  a separate wbuf for delivery to the network stack. For delivery to the
910  *  monitor mode interface they need to be restitched into an MPDU. This
911  *  function does this. Also updates the RX status if the MPDU starts
912  *  a new PPDU
913  *
914  * @param pdev - the HTT instance the rx data was received on
915  * @param head_msdu - network buffer handle, which points to the first MSDU
916  *      in the list. This is a NULL terminated list
917  * @param rx_status - pointer to the status associated with this MPDU.
918  *      Updated only if there is a new PPDU and new status associated with it
919  * @param clone_not_reqd - If set the MPDU linking destroys the passed in
920  *      list, else operates on a cloned nbuf
921  * @return network buffer handle to the MPDU
922  */
923 #if defined(FEATURE_MONITOR_MODE_SUPPORT)
924 #if !defined(QCA6290_HEADERS_DEF) && !defined(QCA6390_HEADERS_DEF) && \
925     !defined(QCA6490_HEADERS_DEF) && !defined(QCA6750_HEADERS_DEF)
926 qdf_nbuf_t
927 htt_rx_restitch_mpdu_from_msdus(htt_pdev_handle pdev,
928 				qdf_nbuf_t head_msdu,
929 				struct ieee80211_rx_status *rx_status,
930 				unsigned clone_not_reqd);
931 #else
932 static inline qdf_nbuf_t
htt_rx_restitch_mpdu_from_msdus(htt_pdev_handle pdev,qdf_nbuf_t head_msdu,struct ieee80211_rx_status * rx_status,unsigned clone_not_reqd)933 htt_rx_restitch_mpdu_from_msdus(htt_pdev_handle pdev,
934 				qdf_nbuf_t head_msdu,
935 				struct ieee80211_rx_status *rx_status,
936 				unsigned clone_not_reqd)
937 {
938 	return NULL;
939 }
940 #endif
941 #endif
942 /**
943  * @brief Return the sequence number of MPDUs to flush.
944  * @param pdev - the HTT instance the rx data was received on
945  * @param rx_frag_ind_msg - the netbuf containing the rx fragment indication
946  *      message
947  * @param seq_num_start - (call-by-reference output) sequence number
948  *      for the start of the range of MPDUs to flush
949  * @param seq_num_end - (call-by-reference output) sequence number
950  *      for the end of the range of MPDUs to flush
951  */
952 void
953 htt_rx_frag_ind_flush_seq_num_range(htt_pdev_handle pdev,
954 				    qdf_nbuf_t rx_frag_ind_msg,
955 				    uint16_t *seq_num_start, uint16_t *seq_num_end);
956 
957 #ifdef CONFIG_HL_SUPPORT
958 /**
959  * htt_rx_msdu_rx_desc_size_hl() - Return the HL rx desc size
960  * @pdev: the HTT instance the rx data was received on.
961  * @msdu_desc: the hl rx desc pointer
962  *
963  * Return: HL rx desc size
964  */
965 uint16_t htt_rx_msdu_rx_desc_size_hl(htt_pdev_handle pdev, void *msdu_desc);
966 #else
967 static inline
htt_rx_msdu_rx_desc_size_hl(htt_pdev_handle pdev,void * msdu_desc)968 uint16_t htt_rx_msdu_rx_desc_size_hl(htt_pdev_handle pdev, void *msdu_desc)
969 {
970 	return 0;
971 }
972 #endif
973 
974 /**
975  * @brief populates vowext stats by processing RX desc.
976  * @param msdu - network buffer handle
977  * @param vowstats - handle to vow ext stats.
978  */
979 void htt_rx_get_vowext_stats(qdf_nbuf_t msdu, struct vow_extstats *vowstats);
980 
981 /**
982  * @brief parses the offload message passed by the target.
983  * @param pdev - pdev handle
984  * @param paddr - physical address of the rx buffer
985  * @param vdev_id - reference to vdev id to be filled
986  * @param peer_id - reference to the peer id to be filled
987  * @param tid - reference to the tid to be filled
988  * @param fw_desc - reference to the fw descriptor to be filled
989  * @param peer_id - reference to the peer id to be filled
990  * @param head_buf - reference to the head buffer
991  * @param tail_buf - reference to the tail buffer
992  */
993 int
994 htt_rx_offload_paddr_msdu_pop_ll(htt_pdev_handle pdev,
995 				 uint32_t *msg_word,
996 				 int msdu_iter,
997 				 int *vdev_id,
998 				 int *peer_id,
999 				 int *tid,
1000 				 uint8_t *fw_desc,
1001 				 qdf_nbuf_t *head_buf, qdf_nbuf_t *tail_buf);
1002 
1003 uint32_t htt_rx_amsdu_rx_in_order_get_pktlog(qdf_nbuf_t rx_ind_msg);
1004 
1005 /**
1006  * htt_rx_update_smmu_map() - set smmu map/unmap for rx buffers
1007  * @pdev: htt pdev handle
1008  * @map: value to set smmu map/unmap for rx buffers
1009  *
1010  * Return: QDF_STATUS
1011  */
1012 QDF_STATUS htt_rx_update_smmu_map(struct htt_pdev_t *pdev, bool map);
1013 
1014 /** htt_tx_enable_ppdu_end
1015  * @enable_ppdu_end - set it to 1 if WLAN_FEATURE_TSF_PLUS is defined,
1016  *                    else do nothing
1017  */
1018 #ifdef WLAN_FEATURE_TSF_PLUS
1019 void htt_rx_enable_ppdu_end(int *enable_ppdu_end);
1020 #else
1021 static inline
htt_rx_enable_ppdu_end(int * enable_ppdu_end)1022 void htt_rx_enable_ppdu_end(int *enable_ppdu_end)
1023 {
1024 }
1025 #endif
1026 
1027 #endif /* _OL_HTT_RX_API__H_ */
1028