xref: /wlan-dirver/qca-wifi-host-cmn/dp/wifi3.0/dp_rx_defrag.h (revision b12e92eccda8e53ac75145bf0572673454a209a5)
1 /*
2  * Copyright (c) 2017 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _DP_RX_DEFRAG_H
20 #define _DP_RX_DEFRAG_H
21 
22 #include "hal_rx.h"
23 
24 #ifdef CONFIG_MCL
25 #include <cds_ieee80211_common.h>
26 #else
27 #include <linux/ieee80211.h>
28 #endif
29 
30 #define DEFRAG_IEEE80211_ADDR_LEN	6
31 #define DEFRAG_IEEE80211_KEY_LEN	8
32 #define DEFRAG_IEEE80211_FCS_LEN	4
33 
34 #define DP_RX_DEFRAG_IEEE80211_ADDR_COPY(dst, src) \
35 	qdf_mem_copy(dst, src, IEEE80211_ADDR_LEN)
36 
37 #define DP_RX_DEFRAG_IEEE80211_QOS_HAS_SEQ(wh) \
38 	(((wh) & \
39 	(IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \
40 	(IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
41 
42 /**
43  * struct dp_rx_defrag_cipher: structure to indicate cipher header
44  * @ic_name: Name
45  * @ic_header: header length
46  * @ic_trailer: trail length
47  * @ic_miclen: MIC length
48  */
49 struct dp_rx_defrag_cipher {
50 	const char *ic_name;
51 	uint16_t ic_header;
52 	uint8_t ic_trailer;
53 	uint8_t ic_miclen;
54 };
55 
56 uint32_t dp_rx_frag_handle(struct dp_soc *soc, void *ring_desc,
57 		struct hal_rx_mpdu_desc_info *mpdu_desc_info,
58 		union dp_rx_desc_list_elem_t **head,
59 		union dp_rx_desc_list_elem_t **tail,
60 		uint32_t quota);
61 
62 /*
63  * dp_rx_frag_get_mac_hdr() - Return pointer to the mac hdr
64  * @rx_desc_info: Pointer to the pkt_tlvs in the
65  * nbuf (pkt_tlvs->mac_hdr->data)
66  *
67  * It is inefficient to peek into the packet for received
68  * frames but these APIs are required to get to some of
69  * 802.11 fields that hardware does not populate in the
70  * rx meta data.
71  *
72  * Returns: pointer to ieee80211_frame
73  */
74 static inline
75 struct ieee80211_frame *dp_rx_frag_get_mac_hdr(uint8_t *rx_desc_info)
76 {
77 	int rx_desc_len = hal_rx_get_desc_len();
78 	return (struct ieee80211_frame *)(rx_desc_info + rx_desc_len);
79 }
80 
81 /*
82  * dp_rx_frag_get_mpdu_seq_number() - Get mpdu sequence number
83  * @rx_desc_info: Pointer to the pkt_tlvs in the
84  * nbuf (pkt_tlvs->mac_hdr->data)
85  *
86  * Returns: uint16_t, rx sequence number
87  */
88 static inline
89 uint16_t dp_rx_frag_get_mpdu_seq_number(uint8_t *rx_desc_info)
90 {
91 	struct ieee80211_frame *mac_hdr;
92 	mac_hdr = dp_rx_frag_get_mac_hdr(rx_desc_info);
93 
94 	return qdf_le16_to_cpu(*(uint16_t *) mac_hdr->i_seq) >>
95 		IEEE80211_SEQ_SEQ_SHIFT;
96 }
97 
98 /*
99  * dp_rx_frag_get_mpdu_frag_number() - Get mpdu fragment number
100  * @rx_desc_info: Pointer to the pkt_tlvs in the
101  * nbuf (pkt_tlvs->mac_hdr->data)
102  *
103  * Returns: uint8_t, receive fragment number
104  */
105 static inline
106 uint8_t dp_rx_frag_get_mpdu_frag_number(uint8_t *rx_desc_info)
107 {
108 	struct ieee80211_frame *mac_hdr;
109 	mac_hdr = dp_rx_frag_get_mac_hdr(rx_desc_info);
110 
111 	return qdf_le16_to_cpu(*(uint16_t *) mac_hdr->i_seq) &
112 		IEEE80211_SEQ_FRAG_MASK;
113 }
114 
115 /*
116  * dp_rx_frag_get_more_frag_bit() - Get more fragment bit
117  * @rx_desc_info: Pointer to the pkt_tlvs in the
118  * nbuf (pkt_tlvs->mac_hdr->data)
119  *
120  * Returns: uint8_t, get more fragment bit
121  */
122 static inline
123 uint8_t dp_rx_frag_get_more_frag_bit(uint8_t *rx_desc_info)
124 {
125 	struct ieee80211_frame *mac_hdr;
126 	mac_hdr = dp_rx_frag_get_mac_hdr(rx_desc_info);
127 
128 	return mac_hdr->i_fc[1] & IEEE80211_FC1_MORE_FRAG;
129 }
130 
131 #endif /* _DP_RX_DEFRAG_H */
132