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