[go: nahoru, domu]

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