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