• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/staging/rt2860/chip/
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify  *
11 * it under the terms of the GNU General Public License as published by  *
12 * the Free Software Foundation; either version 2 of the License, or     *
13 * (at your option) any later version.                                   *
14 *                                                                       *
15 * This program is distributed in the hope that it will be useful,       *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18 * GNU General Public License for more details.                          *
19 *                                                                       *
20 * You should have received a copy of the GNU General Public License     *
21 * along with this program; if not, write to the                         *
22 * Free Software Foundation, Inc.,                                       *
23 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24 *                                                                       *
25 *************************************************************************
26
27    Module Name:
28		mac_usb.h
29
30    Abstract:
31
32    Revision History:
33    Who          When          What
34    ---------    ----------    ----------------------------------------------
35 */
36
37#ifndef __MAC_USB_H__
38#define __MAC_USB_H__
39
40#include "../rtmp_type.h"
41#include "rtmp_mac.h"
42#include "rtmp_phy.h"
43#include "../rtmp_iface.h"
44#include "../rtmp_dot11.h"
45
46#define USB_CYC_CFG				0x02a4
47
48#define BEACON_RING_SIZE		2
49#define MGMTPIPEIDX			0	/* EP6 is highest priority */
50
51#define RTMP_PKT_TAIL_PADDING	11	/* 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding) */
52
53#define fRTMP_ADAPTER_NEED_STOP_TX		\
54		(fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS |	\
55		 fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \
56		 fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
57
58/* */
59/* RXINFO appends at the end of each rx packet. */
60/* */
61#define RXINFO_SIZE				4
62#define RT2870_RXDMALEN_FIELD_SIZE	4
63
64typedef struct PACKED rt_rxinfo {
65	u32 BA:1;
66	u32 DATA:1;
67	u32 NULLDATA:1;
68	u32 FRAG:1;
69	u32 U2M:1;		/* 1: this RX frame is unicast to me */
70	u32 Mcast:1;		/* 1: this is a multicast frame */
71	u32 Bcast:1;		/* 1: this is a broadcast frame */
72	u32 MyBss:1;		/* 1: this frame belongs to the same BSSID */
73	u32 Crc:1;		/* 1: CRC error */
74	u32 CipherErr:2;	/* 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid */
75	u32 AMSDU:1;		/* rx with 802.3 header, not 802.11 header. */
76	u32 HTC:1;
77	u32 RSSI:1;
78	u32 L2PAD:1;
79	u32 AMPDU:1;		/* To be moved */
80	u32 Decrypted:1;
81	u32 PlcpRssil:1;
82	u32 CipherAlg:1;
83	u32 LastAMSDU:1;
84	u32 PlcpSignal:12;
85} RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
86
87/* */
88/* TXINFO */
89/* */
90#define TXINFO_SIZE				4
91
92struct rt_txinfo {
93	/* Word 0 */
94	u32 USBDMATxPktLen:16;	/*used ONLY in USB bulk Aggregation,  Total byte counts of all sub-frame. */
95	u32 rsv:8;
96	u32 WIV:1;		/* Wireless Info Valid. 1 if Driver already fill WI,  o if DMA needs to copy WI to correctposition */
97	u32 QSEL:2;		/* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */
98	u32 SwUseLastRound:1;	/* Software use. */
99	u32 rsv2:2;		/* Software use. */
100	u32 USBDMANextVLD:1;	/*used ONLY in USB bulk Aggregation, NextValid */
101	u32 USBDMATxburst:1;	/*used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint */
102};
103
104/* */
105/* Management ring buffer format */
106/* */
107struct rt_mgmt {
108	BOOLEAN Valid;
109	u8 *pBuffer;
110	unsigned long Length;
111};
112
113/*////////////////////////////////////////////////////////////////////////// */
114/* The struct rt_tx_buffer structure forms the transmitted USB packet to the device */
115/*////////////////////////////////////////////////////////////////////////// */
116struct rt_tx_buffer {
117	union {
118		u8 WirelessPacket[TX_BUFFER_NORMSIZE];
119		struct rt_header_802_11 NullFrame;
120		struct rt_pspoll_frame PsPollPacket;
121		struct rt_rts_frame RTSFrame;
122	} field;
123	u8 Aggregation[4];	/*Buffer for save Aggregation size. */
124};
125
126struct rt_httx_buffer {
127	union {
128		u8 WirelessPacket[MAX_TXBULK_SIZE];
129		struct rt_header_802_11 NullFrame;
130		struct rt_pspoll_frame PsPollPacket;
131		struct rt_rts_frame RTSFrame;
132	} field;
133	u8 Aggregation[4];	/*Buffer for save Aggregation size. */
134};
135
136/* used to track driver-generated write irps */
137struct rt_tx_context {
138	void *pAd;		/*Initialized in MiniportInitialize */
139	PURB pUrb;		/*Initialized in MiniportInitialize */
140	PIRP pIrp;		/*used to cancel pending bulk out. */
141	/*Initialized in MiniportInitialize */
142	struct rt_tx_buffer *TransferBuffer;	/*Initialized in MiniportInitialize */
143	unsigned long BulkOutSize;
144	u8 BulkOutPipeId;
145	u8 SelfIdx;
146	BOOLEAN InUse;
147	BOOLEAN bWaitingBulkOut;	/* at least one packet is in this TxContext, ready for making IRP anytime. */
148	BOOLEAN bFullForBulkOut;	/* all tx buffer are full , so waiting for tx bulkout. */
149	BOOLEAN IRPPending;
150	BOOLEAN LastOne;
151	BOOLEAN bAggregatible;
152	u8 Header_802_3[LENGTH_802_3];
153	u8 Rsv[2];
154	unsigned long DataOffset;
155	u32 TxRate;
156	dma_addr_t data_dma;	/* urb dma on linux */
157
158};
159
160/* used to track driver-generated write irps */
161struct rt_ht_tx_context {
162	void *pAd;		/*Initialized in MiniportInitialize */
163	PURB pUrb;		/*Initialized in MiniportInitialize */
164	PIRP pIrp;		/*used to cancel pending bulk out. */
165	/*Initialized in MiniportInitialize */
166	struct rt_httx_buffer *TransferBuffer;	/*Initialized in MiniportInitialize */
167	unsigned long BulkOutSize;	/* Indicate the total bulk-out size in bytes in one bulk-transmission */
168	u8 BulkOutPipeId;
169	BOOLEAN IRPPending;
170	BOOLEAN LastOne;
171	BOOLEAN bCurWriting;
172	BOOLEAN bRingEmpty;
173	BOOLEAN bCopySavePad;
174	u8 SavedPad[8];
175	u8 Header_802_3[LENGTH_802_3];
176	unsigned long CurWritePosition;	/* Indicate the buffer offset which packet will be inserted start from. */
177	unsigned long CurWriteRealPos;	/* Indicate the buffer offset which packet now are writing to. */
178	unsigned long NextBulkOutPosition;	/* Indicate the buffer start offset of a bulk-transmission */
179	unsigned long ENextBulkOutPosition;	/* Indicate the buffer end offset of a bulk-transmission */
180	u32 TxRate;
181	dma_addr_t data_dma;	/* urb dma on linux */
182};
183
184/* */
185/* Structure to keep track of receive packets and buffers to indicate */
186/* receive data to the protocol. */
187/* */
188struct rt_rx_context {
189	u8 *TransferBuffer;
190	void *pAd;
191	PIRP pIrp;		/*used to cancel pending bulk in. */
192	PURB pUrb;
193	/*These 2 Boolean shouldn't both be 1 at the same time. */
194	unsigned long BulkInOffset;	/* number of packets waiting for reordering . */
195/*      BOOLEAN                         ReorderInUse;   // At least one packet in this buffer are in reordering buffer and wait for receive indication */
196	BOOLEAN bRxHandling;	/* Notify this packet is being process now. */
197	BOOLEAN InUse;		/* USB Hardware Occupied. Wait for USB HW to put packet. */
198	BOOLEAN Readable;	/* Receive Complete back. OK for driver to indicate receiving packet. */
199	BOOLEAN IRPPending;	/* TODO: To be removed */
200	atomic_t IrpLock;
201	spinlock_t RxContextLock;
202	dma_addr_t data_dma;	/* urb dma on linux */
203};
204
205/******************************************************************************
206
207	USB Frimware Related MACRO
208
209******************************************************************************/
210/* 8051 firmware image for usb - use last-half base address = 0x3000 */
211#define FIRMWARE_IMAGE_BASE			0x3000
212#define MAX_FIRMWARE_IMAGE_SIZE		0x1000	/* 4kbyte */
213
214#define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen)		\
215	RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
216
217/******************************************************************************
218
219	USB TX Related MACRO
220
221******************************************************************************/
222#define RTMP_START_DEQUEUE(pAd, QueIdx, irqFlags)				\
223			do {													\
224				RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags);		\
225				if (pAd->DeQueueRunning[QueIdx]) {						\
226					RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
227					DBGPRINT(RT_DEBUG_OFF, ("DeQueueRunning[%d]= TRUE!\n", QueIdx));		\
228					continue;											\
229				} else {												\
230					pAd->DeQueueRunning[QueIdx] = TRUE;					\
231					RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
232				}														\
233			} while (0)
234
235#define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags)						\
236			do {													\
237				RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags);		\
238				pAd->DeQueueRunning[QueIdx] = FALSE;					\
239				RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);	\
240			} while (0)
241
242#define	RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
243		(RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
244
245#define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx)			\
246		do {} while (0)
247
248#define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType)		\
249		((_TxFrameType == TX_RALINK_FRAME) && \
250		(RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
251
252#define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)	\
253		RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
254
255#define HAL_WriteTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)	\
256		RtmpUSB_WriteSingleTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
257
258#define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
259		RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
260
261#define HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber)	\
262		RtmpUSB_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber)
263
264#define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)	\
265		RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
266
267#define HAL_LastTxIdx(pAd, QueIdx, TxIdx) \
268				/*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx) */
269
270#define HAL_KickOutTx(pAd, pTxBlk, QueIdx)	\
271			RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
272
273#define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)	\
274			RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
275
276#define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen)	\
277			RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
278
279#define GET_TXRING_FREENO(_pAd, _QueIdx)	(_QueIdx)	/*(_pAd->TxRing[_QueIdx].TxSwFreeIdx) */
280#define GET_MGMTRING_FREENO(_pAd)			(_pAd->MgmtRing.TxSwFreeIdx)
281
282/* ----------------- RX Related MACRO ----------------- */
283
284/*
285  *	Device Hardware Interface Related MACRO
286  */
287#define RTMP_IRQ_INIT(pAd)				do {} while (0)
288#define RTMP_IRQ_ENABLE(pAd)			do {} while (0)
289
290/*
291  *	MLME Related MACRO
292  */
293#define RTMP_MLME_HANDLER(pAd)			RTUSBMlmeUp(pAd)
294
295#define RTMP_MLME_PRE_SANITY_CHECK(pAd)								\
296	{	if ((pAd->CommonCfg.bHardwareRadio == TRUE) &&					\
297			(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&		\
298			(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) {	\
299			RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
300
301#define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd)	\
302	{	RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0);	\
303		RTUSBMlmeUp(pAd); }
304
305#define RTMP_MLME_RESET_STATE_MACHINE(pAd)	\
306	{	MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL);	\
307		RTUSBMlmeUp(pAd); }
308
309#define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry)		\
310	{	RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(struct rt_mac_table_entry));	\
311		RTUSBMlmeUp(_pAd);									\
312	}
313
314/*
315  *	Power Save Related MACRO
316  */
317#define RTMP_PS_POLL_ENQUEUE(pAd)						\
318	{	RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL);	\
319		RTUSBKickBulkOut(pAd); }
320
321#define RTMP_STA_FORCE_WAKEUP(_pAd, bFromTx) \
322	RT28xxUsbStaAsicForceWakeup(_pAd, bFromTx);
323
324#define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
325    RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
326
327#define RTMP_SET_PSM_BIT(_pAd, _val) \
328	{\
329		if ((_pAd)->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP) \
330			MlmeSetPsmBit(_pAd, _val);\
331		else { \
332			u16 _psm_val; \
333			_psm_val = _val; \
334			RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_SET_PSM_BIT, &(_psm_val), sizeof(u16)); \
335		} \
336	}
337
338#define RTMP_MLME_RADIO_ON(pAd) \
339    RT28xxUsbMlmeRadioOn(pAd);
340
341#define RTMP_MLME_RADIO_OFF(pAd) \
342    RT28xxUsbMlmeRadioOFF(pAd);
343
344#endif /*__MAC_USB_H__ // */
345