xref: /wlan-dirver/qca-wifi-host-cmn/dp/wifi3.0/dp_rx_defrag.h (revision 1f55ed1a9f5050d8da228aa8dd3fff7c0242aa71)
1 /*
2  * Copyright (c) 2017-2018 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 #define UNI_DESC_OWNER_SW 0x1
43 #define UNI_DESC_BUF_TYPE_RX_MSDU_LINK 0x6
44 /**
45  * struct dp_rx_defrag_cipher: structure to indicate cipher header
46  * @ic_name: Name
47  * @ic_header: header length
48  * @ic_trailer: trail length
49  * @ic_miclen: MIC length
50  */
51 struct dp_rx_defrag_cipher {
52 	const char *ic_name;
53 	uint16_t ic_header;
54 	uint8_t ic_trailer;
55 	uint8_t ic_miclen;
56 };
57 
58 uint32_t dp_rx_frag_handle(struct dp_soc *soc, void *ring_desc,
59 		struct hal_rx_mpdu_desc_info *mpdu_desc_info,
60 		uint8_t *mac_id,
61 		uint32_t quota);
62 
63 /*
64  * dp_rx_frag_get_mac_hdr() - Return pointer to the mac hdr
65  * @rx_desc_info: Pointer to the pkt_tlvs in the
66  * nbuf (pkt_tlvs->mac_hdr->data)
67  *
68  * It is inefficient to peek into the packet for received
69  * frames but these APIs are required to get to some of
70  * 802.11 fields that hardware does not populate in the
71  * rx meta data.
72  *
73  * Returns: pointer to ieee80211_frame
74  */
75 static inline
76 struct ieee80211_frame *dp_rx_frag_get_mac_hdr(uint8_t *rx_desc_info)
77 {
78 	int rx_desc_len = hal_rx_get_desc_len();
79 	return (struct ieee80211_frame *)(rx_desc_info + rx_desc_len);
80 }
81 
82 /*
83  * dp_rx_frag_get_mpdu_seq_number() - Get mpdu sequence number
84  * @rx_desc_info: Pointer to the pkt_tlvs in the
85  * nbuf (pkt_tlvs->mac_hdr->data)
86  *
87  * Returns: uint16_t, rx sequence number
88  */
89 static inline
90 uint16_t dp_rx_frag_get_mpdu_seq_number(uint8_t *rx_desc_info)
91 {
92 	struct ieee80211_frame *mac_hdr;
93 	mac_hdr = dp_rx_frag_get_mac_hdr(rx_desc_info);
94 
95 	return qdf_le16_to_cpu(*(uint16_t *) mac_hdr->i_seq) >>
96 		IEEE80211_SEQ_SEQ_SHIFT;
97 }
98 
99 /*
100  * dp_rx_frag_get_mpdu_frag_number() - Get mpdu fragment number
101  * @rx_desc_info: Pointer to the pkt_tlvs in the
102  * nbuf (pkt_tlvs->mac_hdr->data)
103  *
104  * Returns: uint8_t, receive fragment number
105  */
106 static inline
107 uint8_t dp_rx_frag_get_mpdu_frag_number(uint8_t *rx_desc_info)
108 {
109 	struct ieee80211_frame *mac_hdr;
110 	mac_hdr = dp_rx_frag_get_mac_hdr(rx_desc_info);
111 
112 	return qdf_le16_to_cpu(*(uint16_t *) mac_hdr->i_seq) &
113 		IEEE80211_SEQ_FRAG_MASK;
114 }
115 
116 /*
117  * dp_rx_frag_get_more_frag_bit() - Get more fragment bit
118  * @rx_desc_info: Pointer to the pkt_tlvs in the
119  * nbuf (pkt_tlvs->mac_hdr->data)
120  *
121  * Returns: uint8_t, get more fragment bit
122  */
123 static inline
124 uint8_t dp_rx_frag_get_more_frag_bit(uint8_t *rx_desc_info)
125 {
126 	struct ieee80211_frame *mac_hdr;
127 	mac_hdr = dp_rx_frag_get_mac_hdr(rx_desc_info);
128 
129 	return (mac_hdr->i_fc[1] & IEEE80211_FC1_MORE_FRAG) >> 2;
130 }
131 
132 static inline
133 uint8_t dp_rx_get_pkt_dir(uint8_t *rx_desc_info)
134 {
135 	struct ieee80211_frame *mac_hdr;
136 	mac_hdr = dp_rx_frag_get_mac_hdr(rx_desc_info);
137 
138 	return mac_hdr->i_fc[1] & IEEE80211_FC1_DIR_MASK;
139 }
140 
141 void dp_rx_defrag_waitlist_flush(struct dp_soc *soc);
142 void dp_rx_reorder_flush_frag(struct dp_peer *peer,
143 			 unsigned int tid);
144 void dp_rx_defrag_waitlist_remove(struct dp_peer *peer, unsigned tid);
145 void dp_rx_defrag_cleanup(struct dp_peer *peer, unsigned tid);
146 
147 QDF_STATUS dp_rx_defrag_add_last_frag(struct dp_soc *soc,
148 				      struct dp_peer *peer, uint16_t tid,
149 		uint16_t rxseq, qdf_nbuf_t nbuf);
150 #endif /* _DP_RX_DEFRAG_H */
151