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 
28 #ifndef __RTMP_USB_H__
29 #define __RTMP_USB_H__
30 
31 #include "../rtusb_io.h"
32 
33 #ifdef LINUX
34 #include <linux/usb.h>
35 #endif /* LINUX */
36 
37 extern u8 EpToQueue[6];
38 
39 #define RXBULKAGGRE_ZISE			12
40 #define MAX_TXBULK_LIMIT		(LOCAL_TXBUF_SIZE*(BULKAGGRE_ZISE-1))
41 #define MAX_TXBULK_SIZE		(LOCAL_TXBUF_SIZE*BULKAGGRE_ZISE)
42 #define MAX_RXBULK_SIZE		(LOCAL_TXBUF_SIZE*RXBULKAGGRE_ZISE)
43 #define MAX_MLME_HANDLER_MEMORY 20
44 
45 /* Flags for Bulkflags control for bulk out data */
46 #define	fRTUSB_BULK_OUT_DATA_NULL				0x00000001
47 #define	fRTUSB_BULK_OUT_RTS					0x00000002
48 #define	fRTUSB_BULK_OUT_MLME					0x00000004
49 
50 #define	fRTUSB_BULK_OUT_PSPOLL				0x00000010
51 #define	fRTUSB_BULK_OUT_DATA_FRAG				0x00000020
52 #define	fRTUSB_BULK_OUT_DATA_FRAG_2			0x00000040
53 #define	fRTUSB_BULK_OUT_DATA_FRAG_3			0x00000080
54 #define	fRTUSB_BULK_OUT_DATA_FRAG_4			0x00000100
55 
56 #define	fRTUSB_BULK_OUT_DATA_NORMAL			0x00010000
57 #define	fRTUSB_BULK_OUT_DATA_NORMAL_2			0x00020000
58 #define	fRTUSB_BULK_OUT_DATA_NORMAL_3			0x00040000
59 #define	fRTUSB_BULK_OUT_DATA_NORMAL_4			0x00080000
60 
61 /* TODO:move to ./ate/include/iface/ate_usb.h */
62 
63 #define FREE_HTTX_RING(_pCookie, _pipeId, _txContext)			\
64 {									\
65 	if ((_txContext)->ENextBulkOutPosition == \
66 	(_txContext)->CurWritePosition) {\
67 		(_txContext)->bRingEmpty = TRUE;			\
68 	}								\
69 	/*NdisInterlockedDecrement(&(_p)->TxCount); */\
70 }
71 
72 /******************************************************************************
73 
74 	USB Bulk operation related definitions
75 
76 ******************************************************************************/
77 
78 #ifdef LINUX
79 #define BULKAGGRE_ZISE			100
80 #define RT28XX_PUT_DEVICE			usb_put_dev
81 #define RTUSB_ALLOC_URB(iso)		usb_alloc_urb(iso, GFP_ATOMIC)
82 #define RTUSB_SUBMIT_URB(pUrb)		usb_submit_urb(pUrb, \
83 								GFP_ATOMIC)
84 #define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, \
85 							BufSize, \
86 							pDma_addr)	\
87 							usb_alloc_coherent(\
88 							pUsb_Dev, \
89 							BufSize, \
90 							GFP_ATOMIC, \
91 							pDma_addr)
92 #define RTUSB_URB_FREE_BUFFER(pUsb_Dev, \
93 							BufSize, \
94 							pTransferBuf, \
95 							Dma_addr)	\
96 							usb_free_coherent( \
97 							pUsb_Dev, \
98 							BufSize, \
99 							pTransferBuf, \
100 							Dma_addr)
101 
102 #define RTUSB_FREE_URB(pUrb)	usb_free_urb(pUrb)
103 
104 /* unlink urb */
105 #define RTUSB_UNLINK_URB(pUrb)		usb_kill_urb(pUrb)
106 
107 extern void dump_urb(struct urb *purb);
108 
109 #define InterlockedIncrement		atomic_inc
110 #define NdisInterlockedIncrement	atomic_inc
111 #define InterlockedDecrement		atomic_dec
112 #define NdisInterlockedDecrement	atomic_dec
113 #define InterlockedExchange		atomic_set
114 
115 #endif /* LINUX */
116 
117 #define NT_SUCCESS(status)		(((status) >= 0) ? (TRUE) : (FALSE))
118 
119 #define USBD_TRANSFER_DIRECTION_OUT		0
120 #define USBD_TRANSFER_DIRECTION_IN		0
121 #define USBD_SHORT_TRANSFER_OK			0
122 #define PURB			struct urb *
123 
124 #define PIRP		void *
125 #define NDIS_OID	u32
126 #ifndef USB_ST_NOERROR
127 #define USB_ST_NOERROR     0
128 #endif
129 
130 /* vendor-specific control operations */
131 #define CONTROL_TIMEOUT_JIFFIES ((100 * OS_HZ) / 1000)
132 #define UNLINK_TIMEOUT_MS		3
133 
134 void RTUSBBulkOutDataPacketComplete(struct urb *purb, struct pt_regs *pt_regs);
135 void RTUSBBulkOutMLMEPacketComplete(struct urb *pUrb, struct pt_regs *pt_regs);
136 void RTUSBBulkOutNullFrameComplete(struct urb *pUrb, struct pt_regs *pt_regs);
137 void RTUSBBulkOutRTSFrameComplete(struct urb *pUrb, struct pt_regs *pt_regs);
138 void RTUSBBulkOutPsPollComplete(struct urb *pUrb, struct pt_regs *pt_regs);
139 void RTUSBBulkRxComplete(struct urb *pUrb, struct pt_regs *pt_regs);
140 
141 #ifdef KTHREAD_SUPPORT
142 #define RTUSBMlmeUp(pAd) \
143 	do {								    \
144 		struct rt_rtmp_os_task *_pTask = &((pAd)->mlmeTask);\
145 		if (_pTask->kthread_task) {\
146 			_pTask->kthread_running = TRUE; \
147 		wake_up(&_pTask->kthread_q); \
148 		} \
149 	} while (0)
150 #else
151 #define RTUSBMlmeUp(pAd)	        \
152 	do {								    \
153 		struct rt_rtmp_os_task *_pTask = &((pAd)->mlmeTask);\
154 		CHECK_PID_LEGALITY(_pTask->taskPID)		    \
155 		{ \
156 			RTMP_SEM_EVENT_UP(&(_pTask->taskSema)); \
157 		} \
158 	} while (0)
159 #endif
160 
161 #ifdef KTHREAD_SUPPORT
162 #define RTUSBCMDUp(pAd) \
163 	do {	\
164 		struct rt_rtmp_os_task *_pTask = &((pAd)->cmdQTask);	\
165 		{ \
166 			_pTask->kthread_running = TRUE; \
167 		wake_up(&_pTask->kthread_q); \
168 		} \
169 	} while (0)
170 
171 #else
172 #define RTUSBCMDUp(pAd)	                \
173 	do {							    \
174 		struct rt_rtmp_os_task *_pTask = &((pAd)->cmdQTask);	\
175 		CHECK_PID_LEGALITY(_pTask->taskPID)	    \
176 		{\
177 			RTMP_SEM_EVENT_UP(&(_pTask->taskSema)); \
178 		} \
179 	} while (0)
180 #endif
181 
182 #define DEVICE_VENDOR_REQUEST_OUT       0x40
183 #define DEVICE_VENDOR_REQUEST_IN        0xc0
184 /*#define INTERFACE_VENDOR_REQUEST_OUT    0x41*/
185 /*#define INTERFACE_VENDOR_REQUEST_IN     0xc1*/
186 
187 #define BULKOUT_MGMT_RESET_FLAG		0x80
188 
189 #define RTUSB_SET_BULK_FLAG(_M, _F)	((_M)->BulkFlags |= (_F))
190 #define RTUSB_CLEAR_BULK_FLAG(_M, _F)	((_M)->BulkFlags &= ~(_F))
191 #define RTUSB_TEST_BULK_FLAG(_M, _F)	(((_M)->BulkFlags & (_F)) != 0)
192 
193 #define RTMP_IRQ_REQUEST(net_dev)		do {} while (0)
194 #define RTMP_IRQ_RELEASE(net_dev)		do {} while (0)
195 
196 #endif /* __RTMP_USB_H__ */
197