xref: /linux/drivers/staging/rtl8712/rtl871x_recv.h (revision a460513ed4b6994bfeb7bd86f72853140bc1ac12)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _RTL871X_RECV_H_
3 #define _RTL871X_RECV_H_
4 
5 #include "osdep_service.h"
6 #include "drv_types.h"
7 
8 #define NR_RECVFRAME 256
9 
10 #define RXFRAME_ALIGN	8
11 #define RXFRAME_ALIGN_SZ	(1 << RXFRAME_ALIGN)
12 
13 #define MAX_SUBFRAME_COUNT	64
14 
15 /* for Rx reordering buffer control */
16 struct recv_reorder_ctrl {
17 	struct _adapter	*padapter;
18 	u16 indicate_seq; /* =wstart_b, init_value=0xffff */
19 	u16 wend_b;
20 	u8 wsize_b;
21 	struct  __queue pending_recvframe_queue;
22 	struct timer_list reordering_ctrl_timer;
23 };
24 
25 struct	stainfo_rxcache	{
26 	u16	tid_rxseq[16];
27 };
28 
29 #define		PHY_RSSI_SLID_WIN_MAX			100
30 #define		PHY_LINKQUALITY_SLID_WIN_MAX		20
31 
32 
33 struct smooth_rssi_data {
34 	u32	elements[100];	/* array to store values */
35 	u32	index;		/* index to current array to store */
36 	u32	total_num;	/* num of valid elements */
37 	u32	total_val;	/* sum of valid elements */
38 };
39 
40 struct rx_pkt_attrib {
41 
42 	u8	amsdu;
43 	u8	order;
44 	u8	qos;
45 	u8	to_fr_ds;
46 	u8	frag_num;
47 	u16	seq_num;
48 	u8   pw_save;
49 	u8    mfrag;
50 	u8    mdata;
51 	u8	privacy; /* in frame_ctrl field */
52 	u8	bdecrypted;
53 	int	hdrlen;	 /* the WLAN Header Len */
54 	int	encrypt; /* 0 no encrypt. != 0 encrypt algorithm */
55 	int	iv_len;
56 	int	icv_len;
57 	int	priority;
58 	int	ack_policy;
59 	u8	crc_err;
60 	u8	dst[ETH_ALEN];
61 	u8	src[ETH_ALEN];
62 	u8	ta[ETH_ALEN];
63 	u8	ra[ETH_ALEN];
64 	u8	bssid[ETH_ALEN];
65 	u8	tcpchk_valid; /* 0: invalid, 1: valid */
66 	u8	ip_chkrpt; /* 0: incorrect, 1: correct */
67 	u8	tcp_chkrpt; /* 0: incorrect, 1: correct */
68 	u8	signal_qual;
69 	s8	rx_mimo_signal_qual[2];
70 	u8	mcs_rate;
71 	u8	htc;
72 	u8	signal_strength;
73 };
74 
75 /*
76  * accesser of recv_priv: recv_entry(dispatch / passive level);
77  * recv_thread(passive) ; returnpkt(dispatch)
78  * ; halt(passive) ;
79  *
80  * using enter_critical section to protect
81  */
82 struct recv_priv {
83 	spinlock_t lock;
84 	struct  __queue	free_recv_queue;
85 	struct  __queue	recv_pending_queue;
86 	u8 *pallocated_frame_buf;
87 	u8 *precv_frame_buf;
88 	uint free_recvframe_cnt;
89 	struct _adapter	*adapter;
90 	uint	rx_bytes;
91 	uint	rx_pkts;
92 	uint	rx_drop;
93 	uint  rx_icv_err;
94 	uint  rx_largepacket_crcerr;
95 	uint  rx_smallpacket_crcerr;
96 	uint  rx_middlepacket_crcerr;
97 	u8  rx_pending_cnt;
98 	uint	ff_hwaddr;
99 	struct tasklet_struct recv_tasklet;
100 	struct sk_buff_head free_recv_skb_queue;
101 	struct sk_buff_head rx_skb_queue;
102 	u8 *pallocated_recv_buf;
103 	u8 *precv_buf;    /* 4 alignment */
104 	struct  __queue	free_recv_buf_queue;
105 	u32	free_recv_buf_queue_cnt;
106 	/* For the phy information */
107 	s8 rssi;
108 	u8 signal;
109 	u8 noise;
110 	u8 fw_rssi;
111 	struct smooth_rssi_data signal_qual_data;
112 	struct smooth_rssi_data signal_strength_data;
113 };
114 
115 struct sta_recv_priv {
116 	spinlock_t lock;
117 	sint	option;
118 	struct  __queue defrag_q; /* keeping the fragment frame until defrag */
119 	struct	stainfo_rxcache rxcache;
120 	uint	sta_rx_bytes;
121 	uint	sta_rx_pkts;
122 	uint	sta_rx_fail;
123 };
124 
125 #include "rtl8712_recv.h"
126 
127 /* get a free recv_frame from pfree_recv_queue */
128 union recv_frame *r8712_alloc_recvframe(struct  __queue *pfree_recv_queue);
129 void r8712_free_recvframe(union recv_frame *precvframe,
130 			  struct  __queue *pfree_recv_queue);
131 void r8712_free_recvframe_queue(struct  __queue *pframequeue,
132 				 struct  __queue *pfree_recv_queue);
133 int r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe);
134 int recv_func(struct _adapter *padapter, void *pcontext);
135 
136 static inline u8 *get_rxmem(union recv_frame *precvframe)
137 {
138 	/* always return rx_head... */
139 	if (precvframe == NULL)
140 		return NULL;
141 	return precvframe->u.hdr.rx_head;
142 }
143 
144 static inline u8 *get_recvframe_data(union recv_frame *precvframe)
145 {
146 	/* always return rx_data */
147 	if (precvframe == NULL)
148 		return NULL;
149 	return precvframe->u.hdr.rx_data;
150 }
151 
152 static inline u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
153 {
154 	/* used for extract sz bytes from rx_data, update rx_data and return
155 	 * the updated rx_data to the caller
156 	 */
157 	if (precvframe == NULL)
158 		return NULL;
159 	precvframe->u.hdr.rx_data += sz;
160 	if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) {
161 		precvframe->u.hdr.rx_data -= sz;
162 		return NULL;
163 	}
164 	precvframe->u.hdr.len -= sz;
165 	return precvframe->u.hdr.rx_data;
166 }
167 
168 static inline u8 *recvframe_put(union recv_frame *precvframe, sint sz)
169 {
170 	/* used for append sz bytes from ptr to rx_tail, update rx_tail and
171 	 * return the updated rx_tail to the caller
172 	 * after putting, rx_tail must be still larger than rx_end.
173 	 */
174 	if (precvframe == NULL)
175 		return NULL;
176 	precvframe->u.hdr.rx_tail += sz;
177 	if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) {
178 		precvframe->u.hdr.rx_tail -= sz;
179 		return NULL;
180 	}
181 	precvframe->u.hdr.len += sz;
182 	return precvframe->u.hdr.rx_tail;
183 }
184 
185 static inline u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
186 {
187 	/* rmv data from rx_tail (by yitsen)
188 	 * used for extract sz bytes from rx_end, update rx_end and return the
189 	 * updated rx_end to the caller
190 	 * after pulling, rx_end must be still larger than rx_data.
191 	 */
192 	if (precvframe == NULL)
193 		return NULL;
194 	precvframe->u.hdr.rx_tail -= sz;
195 	if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) {
196 		precvframe->u.hdr.rx_tail += sz;
197 		return NULL;
198 	}
199 	precvframe->u.hdr.len -= sz;
200 	return precvframe->u.hdr.rx_tail;
201 }
202 
203 struct sta_info;
204 
205 void	_r8712_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
206 sint r8712_recvframe_chkmic(struct _adapter *adapter,
207 			    union recv_frame *precvframe);
208 union recv_frame *r8712_decryptor(struct _adapter *adapter,
209 				  union recv_frame *precv_frame);
210 union recv_frame *r8712_recvframe_chk_defrag(struct _adapter *adapter,
211 					     union recv_frame *precv_frame);
212 int r8712_validate_recv_frame(struct _adapter *adapter,
213 			      union recv_frame *precv_frame);
214 union recv_frame *r8712_portctrl(struct _adapter *adapter,
215 				 union recv_frame *precv_frame);
216 
217 #endif
218 
219