MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / Zydas / zdbuf.c
blob62b316a52f99212f2b57a09ceffa4848b57b2d3f
1 #ifndef __ZDBUF_C__
2 #define __ZDBUF_C__
4 #include "zd80211.h"
5 #include <linux/vmalloc.h>
8 #define MAX_SIGNAL_NUM 64
10 SignalQ_t mgtQ, txQ, awakeQ, psQ[MAX_RECORD];
11 SignalQ_t *pMgtQ = &mgtQ, *pTxQ, *pAwakeQ, *pPsQ[MAX_RECORD];
13 Signal_t *FreeSignalList;
14 Signal_t *SignalBuf[MAX_SIGNAL_NUM];
15 U32 freeSignalCount;
17 FrmDesc_t *FreeFdescList;
18 FrmDesc_t *FdescBuf[MAX_SIGNAL_NUM];
19 U32 freeFdescCount = MAX_SIGNAL_NUM;
21 U32 allocCnt = 0;
22 U32 freeCnt = 0;
24 void initSigQue(SignalQ_t *Q)
26 U32 flags;
28 flags = pdot11Obj->EnterCS();
29 Q->first = NULL;
30 Q->last = NULL;
31 Q->cnt = 0;
32 pdot11Obj->ExitCS(flags);
35 void releaseSignalBuf(void)
37 int i;
39 for (i=0; i<MAX_SIGNAL_NUM; i++)
40 vfree((void *)SignalBuf[i]);
42 /* Point the the FreeSignalList to NULL */
43 FreeSignalList = NULL;
46 void initSignalBuf(void)
48 int i;
49 U32 flags;
51 initSigQue(pMgtQ);
52 FreeSignalList = NULL;
53 freeSignalCount = MAX_SIGNAL_NUM;
55 for (i=0; i<MAX_SIGNAL_NUM; i++){
56 SignalBuf[i] = (Signal_t *)vmalloc(sizeof(Signal_t)); //can't use for DMA operation
58 if (!SignalBuf[i]){
59 FPRINT("80211: initSignalBuf failed");
60 //pdot11Obj->ExitCS(flags);
61 return;
63 flags = pdot11Obj->EnterCS();
64 SignalBuf[i]->pNext = FreeSignalList;
65 FreeSignalList = SignalBuf[i];
66 pdot11Obj->ExitCS(flags);
71 Signal_t *allocSignal(void)
73 U32 flags;
74 Signal_t *signal = NULL;
76 flags = pdot11Obj->EnterCS();
77 if (FreeSignalList != NULL){
78 signal = FreeSignalList;
79 FreeSignalList = FreeSignalList->pNext;
80 signal->pNext = NULL;
81 signal->buf = NULL;
82 signal->frmInfo.frmDesc = NULL;
83 freeSignalCount-- ;
86 pdot11Obj->ExitCS(flags);
87 return signal;
90 void freeSignal(Signal_t *signal)
92 U32 flags;
94 if (!signal){
95 FPRINT("Free NULL signal");
96 return;
99 flags = pdot11Obj->EnterCS();
100 signal->buf = NULL;
101 signal->vapId=0;
103 signal->frmInfo.frmDesc = NULL;
104 signal->pNext = FreeSignalList;
105 FreeSignalList = signal;
106 freeSignalCount++;
107 pdot11Obj->ExitCS(flags);
110 void re_initFdescBuf(void) {
111 int i;
112 for (i=0; i<MAX_SIGNAL_NUM; i++)
113 freeFdesc(FdescBuf[i]);
114 freeFdescCount = MAX_SIGNAL_NUM;
118 void initFdescBuf(void)
120 int i;
121 U32 flags;
122 //FrmDesc_t *pFrmDesc;
124 flags = pdot11Obj->EnterCS();
125 FreeFdescList = NULL;
127 for (i=0; i<MAX_SIGNAL_NUM; i++){
128 FdescBuf[i] = (FrmDesc_t *) kmalloc(sizeof (FrmDesc_t), GFP_ATOMIC); //may use for DMA operation
130 if (!FdescBuf[i]){
131 FPRINT("80211: initFdescBuf failed");
132 pdot11Obj->ExitCS(flags);
133 return;
136 FdescBuf[i]->pNext = FreeFdescList;
137 FreeFdescList = FdescBuf[i];
140 #if 0
141 FPRINT_V("FreeFdescList", FreeFdescList);
142 pFrmDesc = FreeFdescList;
143 for (i=0; i<MAX_SIGNAL_NUM; i++){
144 FPRINT_V("pFrmDesc", pFrmDesc);
145 FPRINT_V("pFrmDesc->pNext", pFrmDesc->pNext);
146 pFrmDesc = pFrmDesc->pNext;
148 #endif
150 pdot11Obj->ExitCS(flags);
154 void releaseFdescBuf(void)
156 int i;
158 for (i=0; i<MAX_SIGNAL_NUM; i++)
159 kfree((void *)FdescBuf[i]);
161 /* Point the the FreeFdescList to NULL */
162 FreeFdescList = NULL;
166 FrmDesc_t *allocFdesc(void)
168 U32 flags;
169 FrmDesc_t *pfrmDesc = NULL;
171 flags = pdot11Obj->EnterCS();
173 if (FreeFdescList != NULL){
174 pfrmDesc = FreeFdescList;
175 FreeFdescList = FreeFdescList->pNext;
176 //memset(pfrmDesc,0,sizeof(FrmDesc_t));
177 //memset(pfrmDesc->mpdu,0,sizeof(Frame_t)*MAX_FRAG_NUM);
178 pfrmDesc->pNext = NULL;
179 pfrmDesc->ConfigSet = 0;
180 //pfrmDesc->bDataFrm = 0;
181 pfrmDesc->pHash = NULL;
182 pfrmDesc->bValid = TRUE;
183 memset(pfrmDesc->CalMIC,0,sizeof(pfrmDesc->CalMIC));
184 freeFdescCount--;
185 allocCnt++;
187 if (FreeFdescList == NULL){
188 FPRINT("FreeFdescList == NULL");
189 FPRINT_V("freeFdescCount", (U32)freeFdescCount);
190 FPRINT_V("Cnt of MgtQ", pMgtQ->cnt);
194 pdot11Obj->ExitCS(flags);
195 //FPRINT_V("alloc pfrmDesc", (U32)pfrmDesc);
196 //FPRINT_V("FreeFdescList", (U32)FreeFdescList);
198 return pfrmDesc;
202 void freeFdesc(FrmDesc_t *pfrmDesc)
204 U32 flags;
205 FrmDesc_t *pOldFdesc;
207 if (!pfrmDesc){
208 FPRINT("Free NULL pfrmDesc");
209 return;
212 flags = pdot11Obj->EnterCS();
213 #if 0
214 if (!pfrmDesc->bValid){
215 FPRINT_V("pfrmDesc->bValid", pfrmDesc->bValid);
216 pdot11Obj->ExitCS(flags);
217 return;
219 #endif
221 //FPRINT_V("FreeFdescList", (U32)FreeFdescList);
222 pOldFdesc = FreeFdescList;
223 pfrmDesc->ConfigSet = 0;
224 //pfrmDesc->bDataFrm = 0;
225 pfrmDesc->pHash = NULL;
226 pfrmDesc->pNext = FreeFdescList;
227 FreeFdescList = pfrmDesc;
228 pfrmDesc->bValid = FALSE;
229 freeFdescCount++;
230 freeCnt++;
231 //FPRINT_V("free pfrmDesc", (U32)pfrmDesc);
233 #if 0
234 if (FreeFdescList == 0){
235 FPRINT("xxxxxxxxxx");
236 FPRINT_V("free pfrmDesc", (U32)pfrmDesc);
237 FPRINT_V("freeFdescCount", (U32)freeFdescCount);
240 if (pfrmDesc == pfrmDesc->pNext){
241 FPRINT("ooooooooooo");
242 FPRINT_V("pOldFdesc", (U32)pOldFdesc);
243 FPRINT_V("free pfrmDesc", (U32)pfrmDesc);
244 FPRINT_V("freeFdescCount", (U32)freeFdescCount);
246 #endif
247 pdot11Obj->ExitCS(flags);
251 Signal_t *sigDeque(SignalQ_t *Q)
253 U32 flags;
254 Signal_t *signal = NULL;
256 flags = pdot11Obj->EnterCS();
257 if (Q->first != NULL){
258 Q->cnt--;
259 signal = Q->first;
260 Q->first = (Q->first)->pNext;
261 if (Q->first == NULL)
262 Q->last = NULL;
264 pdot11Obj->ExitCS(flags);
265 return signal;
269 void sigEnque(SignalQ_t *Q, Signal_t *signal)
271 U32 flags;
273 flags = pdot11Obj->EnterCS();
274 signal->pNext = NULL;
275 if (Q->last == NULL){
276 Q->first = signal;
277 Q->last = signal;
279 else{
280 Q->last->pNext = signal;
281 Q->last = signal;
283 Q->cnt++;
285 if (Q == pMgtQ)
286 pdot11Obj->QueueFlag |= MGT_QUEUE_SET;
287 else if (Q == pTxQ)
288 pdot11Obj->QueueFlag |= TX_QUEUE_SET;
289 else if (Q == pAwakeQ)
290 pdot11Obj->QueueFlag |= AWAKE_QUEUE_SET;
292 pdot11Obj->ExitCS(flags);
296 void sigEnqueFirst(SignalQ_t *Q, Signal_t *signal)
298 int i_state;
300 FPRINT("sigEnqueFirst");
302 i_state = pdot11Obj->EnterCS();
303 signal->pNext = Q->first;
305 if (Q->last == NULL){
306 Q->last = signal;
309 Q->first = signal;
310 Q->cnt++;
312 pdot11Obj->ExitCS(i_state);
315 #endif