1 /******************************************************************************
2  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3  *
4  * This program is distributed in the hope that it will be useful, but WITHOUT
5  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
7  * more details.
8  *
9  * You should have received a copy of the GNU General Public License along with
10  * this program; if not, write to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
12  *
13  * The full GNU General Public License is included in this distribution in the
14  * file called LICENSE.
15  *
16  * Contact Information:
17  * wlanfae <wlanfae@realtek.com>
18 ******************************************************************************/
19 #ifndef __INC_QOS_TYPE_H
20 #define __INC_QOS_TYPE_H
21 
22 #define BIT0		    0x00000001
23 #define BIT1		    0x00000002
24 #define BIT2		    0x00000004
25 #define BIT3		    0x00000008
26 #define BIT4		    0x00000010
27 #define BIT5		    0x00000020
28 #define BIT6		    0x00000040
29 #define BIT7		    0x00000080
30 #define BIT8		    0x00000100
31 #define BIT9		    0x00000200
32 #define BIT10		   0x00000400
33 #define BIT11		   0x00000800
34 #define BIT12		   0x00001000
35 #define BIT13		   0x00002000
36 #define BIT14		   0x00004000
37 #define BIT15		   0x00008000
38 #define BIT16		   0x00010000
39 #define BIT17		   0x00020000
40 #define BIT18		   0x00040000
41 #define BIT19		   0x00080000
42 #define BIT20		   0x00100000
43 #define BIT21		   0x00200000
44 #define BIT22		   0x00400000
45 #define BIT23		   0x00800000
46 #define BIT24		   0x01000000
47 #define BIT25		   0x02000000
48 #define BIT26		   0x04000000
49 #define BIT27		   0x08000000
50 #define BIT28		   0x10000000
51 #define BIT29		   0x20000000
52 #define BIT30		   0x40000000
53 #define BIT31		   0x80000000
54 
55 union qos_tsinfo {
56 	u8		charData[3];
57 	struct {
58 		u8		ucTrafficType:1;
59 		u8		ucTSID:4;
60 		u8		ucDirection:2;
61 		u8		ucAccessPolicy:2;
62 		u8		ucAggregation:1;
63 		u8		ucPSB:1;
64 		u8		ucUP:3;
65 		u8		ucTSInfoAckPolicy:2;
66 		u8		ucSchedule:1;
67 		u8		ucReserved:7;
68 	} field;
69 };
70 
71 union tspec_body {
72 	u8		charData[55];
73 
74 	struct {
75 		union qos_tsinfo TSInfo;
76 		u16	NominalMSDUsize;
77 		u16	MaxMSDUsize;
78 		u32	MinServiceItv;
79 		u32	MaxServiceItv;
80 		u32	InactivityItv;
81 		u32	SuspenItv;
82 		u32	ServiceStartTime;
83 		u32	MinDataRate;
84 		u32	MeanDataRate;
85 		u32	PeakDataRate;
86 		u32	MaxBurstSize;
87 		u32	DelayBound;
88 		u32	MinPhyRate;
89 		u16	SurplusBandwidthAllowance;
90 		u16	MediumTime;
91 	} f;
92 };
93 
94 struct wmm_tspec {
95 	u8		ID;
96 	u8		Length;
97 	u8		OUI[3];
98 	u8		OUI_Type;
99 	u8		OUI_SubType;
100 	u8		Version;
101 	union tspec_body Body;
102 };
103 
104 struct octet_string {
105 	u8 *Octet;
106 	u16 Length;
107 };
108 
109 #define	MAX_WMMELE_LENGTH	64
110 
111 #define QOS_MODE u32
112 
113 #define QOS_DISABLE		0
114 #define QOS_WMM		1
115 #define QOS_WMMSA		2
116 #define QOS_EDCA		4
117 #define QOS_HCCA		8
118 #define QOS_WMM_UAPSD		16
119 
120 #define WMM_PARAM_ELE_BODY_LEN	18
121 
122 #define MAX_STA_TS_COUNT			16
123 #define MAX_AP_TS_COUNT			32
124 #define QOS_TSTREAM_KEY_SIZE		13
125 
126 #define WMM_ACTION_CATEGORY_CODE	17
127 #define WMM_PARAM_ELE_BODY_LEN	18
128 
129 #define MAX_TSPEC_TSID				15
130 #define SESSION_REJECT_TSID			0xfe
131 #define DEFAULT_TSID					0xff
132 
133 #define ADDTS_TIME_SLOT				100
134 
135 #define ACM_TIMEOUT				1000
136 #define SESSION_REJECT_TIMEOUT		60000
137 
138 enum ack_policy {
139 	eAckPlc0_ACK		= 0x00,
140 	eAckPlc1_NoACK		= 0x01,
141 };
142 
143 
144 #define SET_WMM_QOS_INFO_FIELD(_pStart, _val)	\
145 	WriteEF1Byte(_pStart, _val)
146 
147 #define GET_WMM_QOS_INFO_FIELD_PARAMETERSET_COUNT(_pStart) \
148 	LE_BITS_TO_1BYTE(_pStart, 0, 4)
149 #define SET_WMM_QOS_INFO_FIELD_PARAMETERSET_COUNT(_pStart, _val) \
150 	SET_BITS_TO_LE_1BYTE(_pStart, 0, 4, _val)
151 
152 #define GET_WMM_QOS_INFO_FIELD_AP_UAPSD(_pStart) \
153 	LE_BITS_TO_1BYTE(_pStart, 7, 1)
154 #define SET_WMM_QOS_INFO_FIELD_AP_UAPSD(_pStart, _val) \
155 	SET_BITS_TO_LE_1BYTE(_pStart, 7, 1, _val)
156 
157 #define GET_WMM_QOS_INFO_FIELD_STA_AC_VO_UAPSD(_pStart) \
158 	LE_BITS_TO_1BYTE(_pStart, 0, 1)
159 #define SET_WMM_QOS_INFO_FIELD_STA_AC_VO_UAPSD(_pStart, _val) \
160 	SET_BITS_TO_LE_1BYTE(_pStart, 0, 1, _val)
161 
162 #define GET_WMM_QOS_INFO_FIELD_STA_AC_VI_UAPSD(_pStart) \
163 	LE_BITS_TO_1BYTE(_pStart, 1, 1)
164 #define SET_WMM_QOS_INFO_FIELD_STA_AC_VI_UAPSD(_pStart, _val) \
165 	SET_BITS_TO_LE_1BYTE(_pStart, 1, 1, _val)
166 
167 #define GET_WMM_QOS_INFO_FIELD_STA_AC_BE_UAPSD(_pStart) \
168 	LE_BITS_TO_1BYTE(_pStart, 2, 1)
169 #define SET_WMM_QOS_INFO_FIELD_STA_AC_BE_UAPSD(_pStart, _val) \
170 	SET_BITS_TO_LE_1BYTE(_pStart, 2, 1, _val)
171 
172 #define GET_WMM_QOS_INFO_FIELD_STA_AC_BK_UAPSD(_pStart) \
173 	LE_BITS_TO_1BYTE(_pStart, 3, 1)
174 #define SET_WMM_QOS_INFO_FIELD_STA_AC_BK_UAPSD(_pStart, _val) \
175 	SET_BITS_TO_LE_1BYTE(_pStart, 3, 1, _val)
176 
177 #define GET_WMM_QOS_INFO_FIELD_STA_MAX_SP_LEN(_pStart) \
178 	LE_BITS_TO_1BYTE(_pStart, 5, 2)
179 #define SET_WMM_QOS_INFO_FIELD_STA_MAX_SP_LEN(_pStart, _val) \
180 	SET_BITS_TO_LE_1BYTE(_pStart, 5, 2, _val)
181 
182 enum qos_ie_source {
183 	QOSIE_SRC_ADDTSREQ,
184 	QOSIE_SRC_ADDTSRSP,
185 	QOSIE_SRC_REASOCREQ,
186 	QOSIE_SRC_REASOCRSP,
187 	QOSIE_SRC_DELTS,
188 };
189 
190 
191 #define AC_CODING u32
192 
193 #define AC0_BE	0
194 #define AC1_BK	1
195 #define AC2_VI	2
196 #define AC3_VO	3
197 #define AC_MAX	4
198 
199 
200 #define AC_PARAM_SIZE	4
201 
202 #define WMM_PARAM_ELEMENT_SIZE	(8+(4*AC_PARAM_SIZE))
203 
204 enum qos_ele_subtype {
205 	QOSELE_TYPE_INFO		= 0x00,
206 	QOSELE_TYPE_PARAM	= 0x01,
207 };
208 
209 
210 enum direction_value {
211 	DIR_UP			= 0,
212 	DIR_DOWN		= 1,
213 	DIR_DIRECT		= 2,
214 	DIR_BI_DIR		= 3,
215 };
216 
217 enum acm_method {
218 	eAcmWay0_SwAndHw		= 0,
219 	eAcmWay1_HW			= 1,
220 	eAcmWay2_SW			= 2,
221 };
222 
223 
224 struct acm {
225 	u64		UsedTime;
226 	u64		MediumTime;
227 	u8		HwAcmCtl;
228 };
229 
230 
231 
232 #define AC_UAPSD	u8
233 
234 #define	GET_VO_UAPSD(_apsd) ((_apsd) & BIT0)
235 #define	SET_VO_UAPSD(_apsd) ((_apsd) |= BIT0)
236 
237 #define	GET_VI_UAPSD(_apsd) ((_apsd) & BIT1)
238 #define	SET_VI_UAPSD(_apsd) ((_apsd) |= BIT1)
239 
240 #define	GET_BK_UAPSD(_apsd) ((_apsd) & BIT2)
241 #define	SET_BK_UAPSD(_apsd) ((_apsd) |= BIT2)
242 
243 #define	GET_BE_UAPSD(_apsd) ((_apsd) & BIT3)
244 #define	SET_BE_UAPSD(_apsd) ((_apsd) |= BIT3)
245 
246 union qos_tclas {
247 
248 	struct _TYPE_GENERAL {
249 		u8		Priority;
250 		u8		ClassifierType;
251 		u8		Mask;
252 	} TYPE_GENERAL;
253 
254 	struct _TYPE0_ETH {
255 		u8		Priority;
256 		u8		ClassifierType;
257 		u8		Mask;
258 		u8		SrcAddr[6];
259 		u8		DstAddr[6];
260 		u16		Type;
261 	} TYPE0_ETH;
262 
263 	struct _TYPE1_IPV4 {
264 		u8		Priority;
265 		u8		ClassifierType;
266 		u8		Mask;
267 		u8		Version;
268 		u8		SrcIP[4];
269 		u8		DstIP[4];
270 		u16		SrcPort;
271 		u16		DstPort;
272 		u8		DSCP;
273 		u8		Protocol;
274 		u8		Reserved;
275 	} TYPE1_IPV4;
276 
277 	struct _TYPE1_IPV6 {
278 		u8		Priority;
279 		u8		ClassifierType;
280 		u8		Mask;
281 		u8		Version;
282 		u8		SrcIP[16];
283 		u8		DstIP[16];
284 		u16		SrcPort;
285 		u16		DstPort;
286 		u8		FlowLabel[3];
287 	} TYPE1_IPV6;
288 
289 	struct _TYPE2_8021Q {
290 		u8		Priority;
291 		u8		ClassifierType;
292 		u8		Mask;
293 		u16		TagType;
294 	} TYPE2_8021Q;
295 };
296 
297 struct qos_tstream {
298 
299 	bool			bUsed;
300 	u16			MsduLifetime;
301 	bool			bEstablishing;
302 	u8			TimeSlotCount;
303 	u8			DialogToken;
304 	struct wmm_tspec TSpec;
305 	struct wmm_tspec OutStandingTSpec;
306 	u8			NominalPhyRate;
307 };
308 
309 struct sta_qos {
310 	u8 WMMIEBuf[MAX_WMMELE_LENGTH];
311 	u8 *WMMIE;
312 
313 	QOS_MODE QosCapability;
314 	QOS_MODE CurrentQosMode;
315 
316 	AC_UAPSD b4ac_Uapsd;
317 	AC_UAPSD Curr4acUapsd;
318 	u8 bInServicePeriod;
319 	u8 MaxSPLength;
320 	int NumBcnBeforeTrigger;
321 
322 	u8 *pWMMInfoEle;
323 	u8 WMMParamEle[WMM_PARAM_ELEMENT_SIZE];
324 
325 	struct acm acm[4];
326 	enum acm_method AcmMethod;
327 
328 	struct qos_tstream StaTsArray[MAX_STA_TS_COUNT];
329 	u8				DialogToken;
330 	struct wmm_tspec TSpec;
331 
332 	u8				QBssWirelessMode;
333 
334 	bool				bNoAck;
335 
336 	bool				bEnableRxImmBA;
337 
338 };
339 
340 #define QBSS_LOAD_SIZE				5
341 
342 struct bss_qos {
343 	QOS_MODE bdQoSMode;
344 	u8 bdWMMIEBuf[MAX_WMMELE_LENGTH];
345 	struct octet_string bdWMMIE;
346 
347 	enum qos_ele_subtype EleSubType;
348 
349 	u8 *pWMMInfoEle;
350 	u8 *pWMMParamEle;
351 
352 	u8 QBssLoad[QBSS_LOAD_SIZE];
353 	bool bQBssLoadValid;
354 };
355 
356 #define IsACValid(ac)		((ac >= 0 && ac <= 7) ? true : false)
357 
358 
359 union aci_aifsn {
360 	u8	charData;
361 
362 	struct {
363 		u8	AIFSN:4;
364 		u8	acm:1;
365 		u8	ACI:2;
366 		u8	Reserved:1;
367 	} f;
368 };
369 
370 union ecw {
371 	u8	charData;
372 	struct {
373 		u8	ECWmin:4;
374 		u8	ECWmax:4;
375 	} f;
376 };
377 
378 union ac_param {
379 	u32	longData;
380 	u8	charData[4];
381 
382 	struct {
383 		union aci_aifsn AciAifsn;
384 		union ecw Ecw;
385 		u16		TXOPLimit;
386 	} f;
387 };
388 
389 #endif
390