ASoC: Remove duplicate ADC/DAC widgets from wm_hubs.c
[linux/fpc-iii.git] / drivers / staging / otus / wwrap.c
blob4db8f6e75ad8340f671485f6dafdf390f373b0a9
1 /*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 /* Module Name : wwrap.c */
17 /* Abstract */
18 /* This module contains wrapper functions. */
19 /* */
20 /* NOTES */
21 /* Platform dependent. */
22 /* */
24 /* Please include your header files here */
25 #include "oal_dt.h"
26 #include "usbdrv.h"
28 #include <linux/netlink.h>
30 #if WIRELESS_EXT > 12
31 #include <net/iw_handler.h>
32 #endif
34 extern void zfiRecv80211(zdev_t* dev, zbuf_t* buf, struct zsAdditionInfo* addInfo);
35 extern void zfCoreRecv(zdev_t* dev, zbuf_t* buf, struct zsAdditionInfo* addInfo);
36 extern void zfIdlChkRsp(zdev_t* dev, u32_t* rsp, u16_t rspLen);
37 extern void zfIdlRsp(zdev_t* dev, u32_t *rsp, u16_t rspLen);
41 //extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
42 extern struct zsVapStruct vap[ZM_VAP_PORT_NUMBER];
44 u32_t zfLnxUsbSubmitTxData(zdev_t* dev);
45 u32_t zfLnxUsbIn(zdev_t* dev, urb_t *urb, zbuf_t *buf);
46 u32_t zfLnxSubmitRegInUrb(zdev_t *dev);
47 u32_t zfLnxUsbSubmitBulkUrb(urb_t *urb, struct usb_device *usb, u16_t epnum, u16_t direction,
48 void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context);
49 u32_t zfLnxUsbSubmitIntUrb(urb_t *urb, struct usb_device *usb, u16_t epnum, u16_t direction,
50 void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context,
51 u32_t interval);
53 u16_t zfLnxGetFreeTxUrb(zdev_t *dev)
55 struct usbdrv_private *macp = dev->ml_priv;
56 u16_t idx;
57 unsigned long irqFlag;
59 spin_lock_irqsave(&macp->cs_lock, irqFlag);
61 //idx = ((macp->TxUrbTail + 1) & (ZM_MAX_TX_URB_NUM - 1));
63 //if (idx != macp->TxUrbHead)
64 if (macp->TxUrbCnt != 0)
66 idx = macp->TxUrbTail;
67 macp->TxUrbTail = ((macp->TxUrbTail + 1) & (ZM_MAX_TX_URB_NUM - 1));
68 macp->TxUrbCnt--;
70 else
72 //printk(KERN_ERR "macp->TxUrbCnt: %d\n", macp->TxUrbCnt);
73 idx = 0xffff;
76 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
77 return idx;
80 void zfLnxPutTxUrb(zdev_t *dev)
82 struct usbdrv_private *macp = dev->ml_priv;
83 u16_t idx;
84 unsigned long irqFlag;
86 spin_lock_irqsave(&macp->cs_lock, irqFlag);
88 idx = ((macp->TxUrbHead + 1) & (ZM_MAX_TX_URB_NUM - 1));
90 //if (idx != macp->TxUrbTail)
91 if (macp->TxUrbCnt < ZM_MAX_TX_URB_NUM)
93 macp->TxUrbHead = idx;
94 macp->TxUrbCnt++;
96 else
98 printk("UsbTxUrbQ inconsistent: TxUrbHead: %d, TxUrbTail: %d\n",
99 macp->TxUrbHead, macp->TxUrbTail);
102 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
105 u16_t zfLnxCheckTxBufferCnt(zdev_t *dev)
107 struct usbdrv_private *macp = dev->ml_priv;
108 u16_t TxBufCnt;
109 unsigned long irqFlag;
111 spin_lock_irqsave(&macp->cs_lock, irqFlag);
113 TxBufCnt = macp->TxBufCnt;
115 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
116 return TxBufCnt;
119 UsbTxQ_t *zfLnxGetUsbTxBuffer(zdev_t *dev)
121 struct usbdrv_private *macp = dev->ml_priv;
122 u16_t idx;
123 UsbTxQ_t *TxQ;
124 unsigned long irqFlag;
126 spin_lock_irqsave(&macp->cs_lock, irqFlag);
128 idx = ((macp->TxBufHead+1) & (ZM_MAX_TX_BUF_NUM - 1));
130 //if (idx != macp->TxBufTail)
131 if (macp->TxBufCnt > 0)
133 //printk("CWY - zfwGetUsbTxBuffer ,macp->TxBufCnt = %d\n", macp->TxBufCnt);
134 TxQ = (UsbTxQ_t *)&(macp->UsbTxBufQ[macp->TxBufHead]);
135 macp->TxBufHead = ((macp->TxBufHead+1) & (ZM_MAX_TX_BUF_NUM - 1));
136 macp->TxBufCnt--;
138 else
140 if (macp->TxBufHead != macp->TxBufTail)
142 printk(KERN_ERR "zfwGetUsbTxBuf UsbTxBufQ inconsistent: TxBufHead: %d, TxBufTail: %d\n",
143 macp->TxBufHead, macp->TxBufTail);
146 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
147 return NULL;
150 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
151 return TxQ;
154 u16_t zfLnxPutUsbTxBuffer(zdev_t *dev, u8_t *hdr, u16_t hdrlen,
155 u8_t *snap, u16_t snapLen, u8_t *tail, u16_t tailLen,
156 zbuf_t *buf, u16_t offset)
158 struct usbdrv_private *macp = dev->ml_priv;
159 u16_t idx;
160 UsbTxQ_t *TxQ;
161 unsigned long irqFlag;
163 spin_lock_irqsave(&macp->cs_lock, irqFlag);
165 idx = ((macp->TxBufTail+1) & (ZM_MAX_TX_BUF_NUM - 1));
167 /* For Tx debug */
168 //zm_assert(macp->TxBufCnt >= 0); // deleted because of always true
170 //if (idx != macp->TxBufHead)
171 if (macp->TxBufCnt < ZM_MAX_TX_BUF_NUM)
173 //printk("CWY - zfwPutUsbTxBuffer ,macp->TxBufCnt = %d\n", macp->TxBufCnt);
174 TxQ = (UsbTxQ_t *)&(macp->UsbTxBufQ[macp->TxBufTail]);
175 memcpy(TxQ->hdr, hdr, hdrlen);
176 TxQ->hdrlen = hdrlen;
177 memcpy(TxQ->snap, snap, snapLen);
178 TxQ->snapLen = snapLen;
179 memcpy(TxQ->tail, tail, tailLen);
180 TxQ->tailLen = tailLen;
181 TxQ->buf = buf;
182 TxQ->offset = offset;
184 macp->TxBufTail = ((macp->TxBufTail+1) & (ZM_MAX_TX_BUF_NUM - 1));
185 macp->TxBufCnt++;
187 else
189 printk(KERN_ERR "zfLnxPutUsbTxBuffer UsbTxBufQ inconsistent: TxBufHead: %d, TxBufTail: %d, TxBufCnt: %d\n",
190 macp->TxBufHead, macp->TxBufTail, macp->TxBufCnt);
191 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
192 return 0xffff;
195 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
196 return 0;
199 zbuf_t *zfLnxGetUsbRxBuffer(zdev_t *dev)
201 struct usbdrv_private *macp = dev->ml_priv;
202 //u16_t idx;
203 zbuf_t *buf;
204 unsigned long irqFlag;
206 spin_lock_irqsave(&macp->cs_lock, irqFlag);
208 //idx = ((macp->RxBufHead+1) & (ZM_MAX_RX_URB_NUM - 1));
210 //if (idx != macp->RxBufTail)
211 if (macp->RxBufCnt != 0)
213 buf = macp->UsbRxBufQ[macp->RxBufHead];
214 macp->RxBufHead = ((macp->RxBufHead+1) & (ZM_MAX_RX_URB_NUM - 1));
215 macp->RxBufCnt--;
217 else
219 printk("RxBufQ inconsistent: RxBufHead: %d, RxBufTail: %d\n",
220 macp->RxBufHead, macp->RxBufTail);
221 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
222 return NULL;
225 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
226 return buf;
229 u32_t zfLnxPutUsbRxBuffer(zdev_t *dev, zbuf_t *buf)
231 struct usbdrv_private *macp = dev->ml_priv;
232 u16_t idx;
233 unsigned long irqFlag;
235 spin_lock_irqsave(&macp->cs_lock, irqFlag);
237 idx = ((macp->RxBufTail+1) & (ZM_MAX_RX_URB_NUM - 1));
239 //if (idx != macp->RxBufHead)
240 if (macp->RxBufCnt != ZM_MAX_RX_URB_NUM)
242 macp->UsbRxBufQ[macp->RxBufTail] = buf;
243 macp->RxBufTail = idx;
244 macp->RxBufCnt++;
246 else
248 printk("RxBufQ inconsistent: RxBufHead: %d, RxBufTail: %d\n",
249 macp->RxBufHead, macp->RxBufTail);
250 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
251 return 0xffff;
254 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
255 return 0;
258 void zfLnxUsbDataOut_callback(urb_t *urb)
260 zdev_t* dev = urb->context;
261 //UsbTxQ_t *TxData;
263 /* Give the urb back */
264 zfLnxPutTxUrb(dev);
266 /* Check whether there is any pending buffer needed */
267 /* to be sent */
268 if (zfLnxCheckTxBufferCnt(dev) != 0)
270 //TxData = zfwGetUsbTxBuffer(dev);
272 //if (TxData == NULL)
274 // printk("Get a NULL buffer from zfwGetUsbTxBuffer\n");
275 // return;
277 //else
279 zfLnxUsbSubmitTxData(dev);
284 void zfLnxUsbDataIn_callback(urb_t *urb)
286 zdev_t* dev = urb->context;
287 struct usbdrv_private *macp = dev->ml_priv;
288 zbuf_t *buf;
289 zbuf_t *new_buf;
290 int status;
292 #if ZM_USB_STREAM_MODE == 1
293 static int remain_len = 0, check_pad = 0, check_len = 0;
294 int index = 0;
295 int chk_idx;
296 u16_t pkt_len;
297 u16_t pkt_tag;
298 u16_t ii;
299 zbuf_t *rxBufPool[8];
300 u16_t rxBufPoolIndex = 0;
301 #endif
303 /* Check status for URB */
304 if (urb->status != 0){
305 printk("zfLnxUsbDataIn_callback() : status=0x%x\n", urb->status);
306 if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)
307 && (urb->status != -ESHUTDOWN))
309 if (urb->status == -EPIPE){
310 //printk(KERN_ERR "nonzero read bulk status received: -EPIPE");
311 status = -1;
314 if (urb->status == -EPROTO){
315 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
316 status = -1;
320 //printk(KERN_ERR "urb->status: 0x%08x\n", urb->status);
322 /* Dequeue skb buffer */
323 buf = zfLnxGetUsbRxBuffer(dev);
324 dev_kfree_skb_any(buf);
325 #if 0
326 /* Enqueue skb buffer */
327 zfLnxPutUsbRxBuffer(dev, buf);
329 /* Submit a Rx urb */
330 zfLnxUsbIn(dev, urb, buf);
331 #endif
332 return;
335 if (urb->actual_length == 0)
337 printk(KERN_ERR "Get an URB whose length is zero");
338 status = -1;
341 /* Dequeue skb buffer */
342 buf = zfLnxGetUsbRxBuffer(dev);
344 //zfwBufSetSize(dev, buf, urb->actual_length);
345 #ifdef NET_SKBUFF_DATA_USES_OFFSET
346 buf->tail = 0;
347 buf->len = 0;
348 #else
349 buf->tail = buf->data;
350 buf->len = 0;
351 #endif
353 BUG_ON((buf->tail + urb->actual_length) > buf->end);
355 skb_put(buf, urb->actual_length);
357 #if ZM_USB_STREAM_MODE == 1
358 if (remain_len != 0)
360 zbuf_t *remain_buf = macp->reamin_buf;
362 index = remain_len;
363 remain_len -= check_pad;
365 /* Copy data */
366 memcpy(&(remain_buf->data[check_len]), buf->data, remain_len);
367 check_len += remain_len;
368 remain_len = 0;
370 rxBufPool[rxBufPoolIndex++] = remain_buf;
373 while(index < urb->actual_length)
375 pkt_len = buf->data[index] + (buf->data[index+1] << 8);
376 pkt_tag = buf->data[index+2] + (buf->data[index+3] << 8);
378 if (pkt_tag == 0x4e00)
380 int pad_len;
382 //printk("Get a packet, index: %d, pkt_len: 0x%04x\n", index, pkt_len);
383 #if 0
384 /* Dump data */
385 for (ii = index; ii < pkt_len+4;)
387 printk("%02x ", (buf->data[ii] & 0xff));
389 if ((++ii % 16) == 0)
390 printk("\n");
393 printk("\n");
394 #endif
396 pad_len = 4 - (pkt_len & 0x3);
398 if(pad_len == 4)
399 pad_len = 0;
401 chk_idx = index;
402 index = index + 4 + pkt_len + pad_len;
404 if (index > ZM_MAX_RX_BUFFER_SIZE)
406 remain_len = index - ZM_MAX_RX_BUFFER_SIZE; // - pad_len;
407 check_len = ZM_MAX_RX_BUFFER_SIZE - chk_idx - 4;
408 check_pad = pad_len;
410 /* Allocate a skb buffer */
411 //new_buf = zfwBufAllocate(dev, ZM_MAX_RX_BUFFER_SIZE);
412 new_buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
414 /* Set skb buffer length */
415 #ifdef NET_SKBUFF_DATA_USES_OFFSET
416 new_buf->tail = 0;
417 new_buf->len = 0;
418 #else
419 new_buf->tail = new_buf->data;
420 new_buf->len = 0;
421 #endif
423 skb_put(new_buf, pkt_len);
425 /* Copy the buffer */
426 memcpy(new_buf->data, &(buf->data[chk_idx+4]), check_len);
428 /* Record the buffer pointer */
429 macp->reamin_buf = new_buf;
431 else
433 #ifdef ZM_DONT_COPY_RX_BUFFER
434 if (rxBufPoolIndex == 0)
436 new_buf = skb_clone(buf, GFP_ATOMIC);
438 new_buf->data = &(buf->data[chk_idx+4]);
439 new_buf->len = pkt_len;
441 else
443 #endif
444 /* Allocate a skb buffer */
445 new_buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
447 /* Set skb buffer length */
448 #ifdef NET_SKBUFF_DATA_USES_OFFSET
449 new_buf->tail = 0;
450 new_buf->len = 0;
451 #else
452 new_buf->tail = new_buf->data;
453 new_buf->len = 0;
454 #endif
456 skb_put(new_buf, pkt_len);
458 /* Copy the buffer */
459 memcpy(new_buf->data, &(buf->data[chk_idx+4]), pkt_len);
461 #ifdef ZM_DONT_COPY_RX_BUFFER
463 #endif
464 rxBufPool[rxBufPoolIndex++] = new_buf;
467 else
469 printk(KERN_ERR "Can't find tag, pkt_len: 0x%04x, tag: 0x%04x\n", pkt_len, pkt_tag);
471 /* Free buffer */
472 dev_kfree_skb_any(buf);
474 /* Allocate a skb buffer */
475 new_buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
477 /* Enqueue skb buffer */
478 zfLnxPutUsbRxBuffer(dev, new_buf);
480 /* Submit a Rx urb */
481 zfLnxUsbIn(dev, urb, new_buf);
483 return;
487 /* Free buffer */
488 dev_kfree_skb_any(buf);
489 #endif
491 /* Allocate a skb buffer */
492 new_buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
494 /* Enqueue skb buffer */
495 zfLnxPutUsbRxBuffer(dev, new_buf);
497 /* Submit a Rx urb */
498 zfLnxUsbIn(dev, urb, new_buf);
500 #if ZM_USB_STREAM_MODE == 1
501 for(ii = 0; ii < rxBufPoolIndex; ii++)
503 macp->usbCbFunctions.zfcbUsbRecv(dev, rxBufPool[ii]);
505 #else
506 /* pass data to upper layer */
507 macp->usbCbFunctions.zfcbUsbRecv(dev, buf);
508 #endif
511 void zfLnxUsbRegOut_callback(urb_t *urb)
513 //dev_t* dev = urb->context;
515 //printk(KERN_ERR "zfwUsbRegOut_callback\n");
518 void zfLnxUsbRegIn_callback(urb_t *urb)
520 zdev_t* dev = urb->context;
521 u32_t rsp[64/4];
522 int status;
523 struct usbdrv_private *macp = dev->ml_priv;
525 /* Check status for URB */
526 if (urb->status != 0){
527 printk("zfLnxUsbRegIn_callback() : status=0x%x\n", urb->status);
528 if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)
529 && (urb->status != -ESHUTDOWN))
531 if (urb->status == -EPIPE){
532 //printk(KERN_ERR "nonzero read bulk status received: -EPIPE");
533 status = -1;
536 if (urb->status == -EPROTO){
537 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
538 status = -1;
542 //printk(KERN_ERR "urb->status: 0x%08x\n", urb->status);
543 return;
546 if (urb->actual_length == 0)
548 printk(KERN_ERR "Get an URB whose length is zero");
549 status = -1;
552 /* Copy data into respone buffer */
553 memcpy(rsp, macp->regUsbReadBuf, urb->actual_length);
555 /* Notify to upper layer */
556 //zfIdlChkRsp(dev, rsp, (u16_t)urb->actual_length);
557 //zfiUsbRegIn(dev, rsp, (u16_t)urb->actual_length);
558 macp->usbCbFunctions.zfcbUsbRegIn(dev, rsp, (u16_t)urb->actual_length);
560 /* Issue another USB IN URB */
561 zfLnxSubmitRegInUrb(dev);
564 u32_t zfLnxSubmitRegInUrb(zdev_t *dev)
566 u32_t ret;
567 struct usbdrv_private *macp = dev->ml_priv;
569 /* Submit a rx urb */
570 //ret = zfLnxUsbSubmitBulkUrb(macp->RegInUrb, macp->udev,
571 // USB_REG_IN_PIPE, USB_DIR_IN, macp->regUsbReadBuf,
572 // ZM_USB_REG_MAX_BUF_SIZE, zfLnxUsbRegIn_callback, dev);
573 //CWYang(-)
574 //if (ret != 0)
575 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
577 ret = zfLnxUsbSubmitIntUrb(macp->RegInUrb, macp->udev,
578 USB_REG_IN_PIPE, USB_DIR_IN, macp->regUsbReadBuf,
579 ZM_USB_REG_MAX_BUF_SIZE, zfLnxUsbRegIn_callback, dev, 1);
581 return ret;
584 u32_t zfLnxUsbSubmitTxData(zdev_t* dev)
586 u32_t i;
587 u32_t ret;
588 u16_t freeTxUrb;
589 u8_t *puTxBuf = NULL;
590 UsbTxQ_t *TxData;
591 int len = 0;
592 struct usbdrv_private *macp = dev->ml_priv;
593 #if ZM_USB_TX_STREAM_MODE == 1
594 u8_t ii;
595 u16_t offset = 0;
596 u16_t usbTxAggCnt;
597 u16_t *pUsbTxHdr;
598 UsbTxQ_t *TxQPool[ZM_MAX_TX_AGGREGATE_NUM];
599 #endif
601 /* First check whether there is a free URB */
602 freeTxUrb = zfLnxGetFreeTxUrb(dev);
604 /* If there is no any free Tx Urb */
605 if (freeTxUrb == 0xffff)
607 //printk(KERN_ERR "Can't get free Tx Urb\n");
608 //printk("CWY - Can't get free Tx Urb\n");
609 return 0xffff;
612 #if ZM_USB_TX_STREAM_MODE == 1
613 usbTxAggCnt = zfLnxCheckTxBufferCnt(dev);
615 if (usbTxAggCnt >= ZM_MAX_TX_AGGREGATE_NUM)
617 usbTxAggCnt = ZM_MAX_TX_AGGREGATE_NUM;
619 else
621 usbTxAggCnt = 1;
624 //printk("usbTxAggCnt: %d\n", usbTxAggCnt);
625 #endif
627 #if ZM_USB_TX_STREAM_MODE == 1
628 for(ii = 0; ii < usbTxAggCnt; ii++)
630 #endif
631 /* Dequeue the packet from UsbTxBufQ */
632 TxData = zfLnxGetUsbTxBuffer(dev);
633 if (TxData == NULL)
635 /* Give the urb back */
636 zfLnxPutTxUrb(dev);
637 return 0xffff;
640 /* Point to the freeTxUrb buffer */
641 puTxBuf = macp->txUsbBuf[freeTxUrb];
643 #if ZM_USB_TX_STREAM_MODE == 1
644 puTxBuf += offset;
645 pUsbTxHdr = (u16_t *)puTxBuf;
647 /* Add the packet length and tag information */
648 *pUsbTxHdr++ = TxData->hdrlen + TxData->snapLen +
649 (TxData->buf->len - TxData->offset) + TxData->tailLen;
651 *pUsbTxHdr++ = 0x697e;
653 puTxBuf += 4;
654 #endif // #ifdef ZM_USB_TX_STREAM_MODE
656 /* Copy WLAN header and packet buffer into USB buffer */
657 for(i = 0; i < TxData->hdrlen; i++)
659 *puTxBuf++ = TxData->hdr[i];
662 /* Copy SNAP header */
663 for(i = 0; i < TxData->snapLen; i++)
665 *puTxBuf++ = TxData->snap[i];
668 /* Copy packet buffer */
669 for(i = 0; i < TxData->buf->len - TxData->offset; i++)
671 //*puTxBuf++ = zmw_rx_buf_readb(dev, TxData->buf, i);
672 *puTxBuf++ = *(u8_t*)((u8_t*)TxData->buf->data+i+TxData->offset);
675 /* Copy tail */
676 for(i = 0; i < TxData->tailLen; i++)
678 *puTxBuf++ = TxData->tail[i];
681 len = TxData->hdrlen+TxData->snapLen+TxData->buf->len+TxData->tailLen-TxData->offset;
683 #if 0
684 if (TxData->hdrlen != 0)
686 puTxBuf = macp->txUsbBuf[freeTxUrb];
687 for (i = 0; i < len; i++)
689 printk("%02x ", puTxBuf[i]);
690 if (i % 16 == 15)
691 printk("\n");
693 printk("\n");
695 #endif
696 #if 0
697 /* For debug purpose */
698 if(TxData->hdr[9] & 0x40)
700 int i;
701 u16_t ctrlLen = TxData->hdr[0] + (TxData->hdr[1] << 8);
703 if (ctrlLen != len + 4)
705 /* Dump control setting */
706 for(i = 0; i < 8; i++)
708 printk(KERN_ERR "0x%02x ", TxData->hdr[i]);
710 printk(KERN_ERR "\n");
712 printk(KERN_ERR "ctrLen: %d, hdrLen: %d, snapLen: %d\n", ctrlLen, TxData->hdrlen, TxData->snapLen);
713 printk(KERN_ERR "bufLen: %d, tailLen: %d, len: %d\n", TxData->buf->len, TxData->tailLen, len);
716 #endif
718 #if ZM_USB_TX_STREAM_MODE == 1
719 // Add the Length and Tag
720 len += 4;
722 //printk("%d packet, length: %d\n", ii+1, len);
724 if (ii < (ZM_MAX_TX_AGGREGATE_NUM-1))
726 /* Pad the buffer to firmware descriptor boundary */
727 offset += (((len-1) / 4) + 1) * 4;
730 if (ii == (ZM_MAX_TX_AGGREGATE_NUM-1))
732 len += offset;
735 TxQPool[ii] = TxData;
737 //DbgPrint("%d packet, offset: %d\n", ii+1, pUsbTxTransfer->offset);
739 /* free packet */
740 //zfBufFree(dev, txData->buf);
742 #endif
743 //printk("CWY - call zfwUsbSubmitBulkUrb(), len = 0x%d\n", len);
744 /* Submit a tx urb */
745 ret = zfLnxUsbSubmitBulkUrb(macp->WlanTxDataUrb[freeTxUrb], macp->udev,
746 USB_WLAN_TX_PIPE, USB_DIR_OUT, macp->txUsbBuf[freeTxUrb],
747 len, zfLnxUsbDataOut_callback, dev);
748 //CWYang(-)
749 //if (ret != 0)
750 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
752 /* free packet */
753 //dev_kfree_skb_any(TxData->buf);
754 #if ZM_USB_TX_STREAM_MODE == 1
755 for(ii = 0; ii < usbTxAggCnt; ii++)
756 macp->usbCbFunctions.zfcbUsbOutComplete(dev, TxQPool[ii]->buf, 1, TxQPool[ii]->hdr);
757 #else
758 macp->usbCbFunctions.zfcbUsbOutComplete(dev, TxData->buf, 1, TxData->hdr);
759 #endif
761 return ret;
766 u32_t zfLnxUsbIn(zdev_t* dev, urb_t *urb, zbuf_t *buf)
768 u32_t ret;
769 struct usbdrv_private *macp = dev->ml_priv;
771 /* Submit a rx urb */
772 ret = zfLnxUsbSubmitBulkUrb(urb, macp->udev, USB_WLAN_RX_PIPE,
773 USB_DIR_IN, buf->data, ZM_MAX_RX_BUFFER_SIZE,
774 zfLnxUsbDataIn_callback, dev);
775 //CWYang(-)
776 //if (ret != 0)
777 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
779 return ret;
782 u32_t zfLnxUsbWriteReg(zdev_t* dev, u32_t* cmd, u16_t cmdLen)
784 struct usbdrv_private *macp = dev->ml_priv;
785 u32_t ret;
787 #ifdef ZM_CONFIG_BIG_ENDIAN
788 int ii = 0;
790 for(ii=0; ii<(cmdLen>>2); ii++)
791 cmd[ii] = cpu_to_le32(cmd[ii]);
792 #endif
794 memcpy(macp->regUsbWriteBuf, cmd, cmdLen);
796 /* Issue an USB Out transfer */
797 /* Submit a tx urb */
798 ret = zfLnxUsbSubmitIntUrb(macp->RegOutUrb, macp->udev,
799 USB_REG_OUT_PIPE, USB_DIR_OUT, macp->regUsbWriteBuf,
800 cmdLen, zfLnxUsbRegOut_callback, dev, 1);
802 return ret;
806 u32_t zfLnxUsbOut(zdev_t* dev, u8_t *hdr, u16_t hdrlen, u8_t *snap, u16_t snapLen,
807 u8_t *tail, u16_t tailLen, zbuf_t *buf, u16_t offset)
809 u32_t ret;
810 struct usbdrv_private *macp = dev->ml_priv;
812 /* Check length of tail buffer */
813 //zm_assert((tailLen <= 16));
815 /* Enqueue the packet into UsbTxBufQ */
816 if (zfLnxPutUsbTxBuffer(dev, hdr, hdrlen, snap, snapLen, tail, tailLen, buf, offset) == 0xffff)
818 /* free packet */
819 //printk("CWY - zfwPutUsbTxBuffer Error, free packet\n");
820 //dev_kfree_skb_any(buf);
821 macp->usbCbFunctions.zfcbUsbOutComplete(dev, buf, 0, hdr);
822 return 0xffff;
825 //return 0;
826 //printk("CWY - call zfwUsbSubmitTxData()\n");
827 ret = zfLnxUsbSubmitTxData(dev);
828 return ret;
831 void zfLnxInitUsbTxQ(zdev_t* dev)
833 struct usbdrv_private *macp = dev->ml_priv;
835 printk(KERN_ERR "zfwInitUsbTxQ\n");
837 /* Zero memory for UsbTxBufQ */
838 memset(macp->UsbTxBufQ, 0, sizeof(UsbTxQ_t) * ZM_MAX_TX_URB_NUM);
840 macp->TxBufHead = 0;
841 macp->TxBufTail = 0;
842 macp->TxUrbHead = 0;
843 macp->TxUrbTail = 0;
844 macp->TxUrbCnt = ZM_MAX_TX_URB_NUM;
847 void zfLnxInitUsbRxQ(zdev_t* dev)
849 u16_t i;
850 zbuf_t *buf;
851 struct usbdrv_private *macp = dev->ml_priv;
853 /* Zero memory for UsbRxBufQ */
854 memset(macp->UsbRxBufQ, 0, sizeof(zbuf_t *) * ZM_MAX_RX_URB_NUM);
856 macp->RxBufHead = 0;
858 for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
860 //buf = zfwBufAllocate(dev, ZM_MAX_RX_BUFFER_SIZE);
861 buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
862 macp->UsbRxBufQ[i] = buf;
865 //macp->RxBufTail = ZM_MAX_RX_URB_NUM - 1;
866 macp->RxBufTail = 0;
868 /* Submit all Rx urbs */
869 for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
871 zfLnxPutUsbRxBuffer(dev, macp->UsbRxBufQ[i]);
872 zfLnxUsbIn(dev, macp->WlanRxDataUrb[i], macp->UsbRxBufQ[i]);
878 u32_t zfLnxUsbSubmitBulkUrb(urb_t *urb, struct usb_device *usb, u16_t epnum, u16_t direction,
879 void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context)
881 u32_t ret;
883 if(direction == USB_DIR_OUT)
885 usb_fill_bulk_urb(urb, usb, usb_sndbulkpipe(usb, epnum),
886 transfer_buffer, buffer_length, complete, context);
888 urb->transfer_flags |= URB_ZERO_PACKET;
890 else
892 usb_fill_bulk_urb(urb, usb, usb_rcvbulkpipe(usb, epnum),
893 transfer_buffer, buffer_length, complete, context);
896 if (epnum == 4)
898 if (urb->hcpriv)
900 //printk("CWY - urb->hcpriv set by unknown reason, reset it\n");
901 //urb->hcpriv = 0;
905 ret = usb_submit_urb(urb, GFP_ATOMIC);
906 if ((epnum == 4) & (ret != 0))
908 //printk("CWY - ret = %x\n", ret);
910 return ret;
913 u32_t zfLnxUsbSubmitIntUrb(urb_t *urb, struct usb_device *usb, u16_t epnum, u16_t direction,
914 void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context,
915 u32_t interval)
917 u32_t ret;
919 if(direction == USB_DIR_OUT)
921 usb_fill_int_urb(urb, usb, usb_sndbulkpipe(usb, epnum),
922 transfer_buffer, buffer_length, complete, context, interval);
924 else
926 usb_fill_int_urb(urb, usb, usb_rcvbulkpipe(usb, epnum),
927 transfer_buffer, buffer_length, complete, context, interval);
930 ret = usb_submit_urb(urb, GFP_ATOMIC);
932 return ret;
935 #ifdef ZM_ENABLE_CENC
936 int zfLnxCencSendMsg(struct sock *netlink_sk, u_int8_t *msg, int len)
938 #define COMMTYPE_GROUP 8
939 #define WAI_K_MSG 0x11
941 int ret = -1;
942 int size;
943 unsigned char *old_tail;
944 struct sk_buff *skb;
945 struct nlmsghdr *nlh;
946 char *pos = NULL;
948 size = NLMSG_SPACE(len);
949 skb = alloc_skb(size, GFP_ATOMIC);
951 if(skb == NULL)
953 printk("dev_alloc_skb failure \n");
954 goto out;
956 old_tail = skb->tail;
958 /*ÌîдÊý¾Ý±¨Ïà¹ØÐÅÏ¢*/
959 nlh = NLMSG_PUT(skb, 0, 0, WAI_K_MSG, size-sizeof(*nlh));
960 pos = NLMSG_DATA(nlh);
961 memset(pos, 0, len);
963 /*´«Êäµ½Óû§¿Õ¼äµÄÊý¾Ý*/
964 memcpy(pos, msg, len);
965 /*¼ÆËã¾­¹ý×Ö½Ú¶ÔÆäºóµÄÊý¾Ýʵ¼Ê³¤¶È*/
966 nlh->nlmsg_len = skb->tail - old_tail;
967 NETLINK_CB(skb).dst_group = COMMTYPE_GROUP;
968 netlink_broadcast(netlink_sk, skb, 0, COMMTYPE_GROUP, GFP_ATOMIC);
969 ret = 0;
970 out:
971 return ret;
972 nlmsg_failure: /*NLMSG_PUT ʧ°Ü£¬Ôò³·ÏúÌ×½Ó×Ö»º´æ*/
973 kfree_skb(skb);
974 goto out;
976 #undef COMMTYPE_GROUP
977 #undef WAI_K_MSG
979 #endif //ZM_ENABLE_CENC
981 /* Simply return 0xffff if VAP function is not supported */
982 u16_t zfLnxGetVapId(zdev_t* dev)
984 u16_t i;
986 for (i=0; i<ZM_VAP_PORT_NUMBER; i++)
988 if (vap[i].dev == dev)
990 return i;
993 return 0xffff;
996 u32_t zfwReadReg(zdev_t* dev, u32_t offset)
998 return 0;
1001 #ifndef INIT_WORK
1002 #define work_struct tq_struct
1004 #define schedule_work(a) schedule_task(a)
1006 #define flush_scheduled_work flush_scheduled_tasks
1007 #define INIT_WORK(_wq, _routine, _data) INIT_TQUEUE(_wq, _routine, _data)
1008 #define PREPARE_WORK(_wq, _routine, _data) PREPARE_TQUEUE(_wq, _routine, _data)
1009 #endif
1011 #define KEVENT_WATCHDOG 0x00000001
1013 u32_t smp_kevent_Lock = 0;
1015 void kevent(struct work_struct *work)
1017 struct usbdrv_private *macp =
1018 container_of(work, struct usbdrv_private, kevent);
1019 zdev_t *dev = macp->device;
1021 if (macp == NULL)
1023 return;
1026 if (test_and_set_bit(0, (void *)&smp_kevent_Lock))
1028 //schedule_work(&macp->kevent);
1029 return;
1032 down(&macp->ioctl_sem);
1034 if (test_and_clear_bit(KEVENT_WATCHDOG, &macp->kevent_flags))
1036 extern u16_t zfHpStartRecv(zdev_t *dev);
1037 //zfiHwWatchDogReinit(dev);
1038 printk(("\n ************ Hw watchDog occur!! ************** \n"));
1039 zfiWlanSuspend(dev);
1040 zfiWlanResume(dev,0);
1041 zfHpStartRecv(dev);
1044 clear_bit(0, (void *)&smp_kevent_Lock);
1045 up(&macp->ioctl_sem);
1048 /************************************************************************/
1049 /* */
1050 /* FUNCTION DESCRIPTION zfLnxCreateThread */
1051 /* Create a Thread */
1052 /* */
1053 /* INPUTS */
1054 /* dev : device pointer */
1055 /* */
1056 /* OUTPUTS */
1057 /* always 0 */
1058 /* */
1059 /* AUTHOR */
1060 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1061 /* */
1062 /************************************************************************/
1063 u8_t zfLnxCreateThread(zdev_t *dev)
1065 struct usbdrv_private *macp = dev->ml_priv;
1067 /* Create Mutex and keventd */
1068 INIT_WORK(&macp->kevent, kevent);
1069 init_MUTEX(&macp->ioctl_sem);
1071 return 0;
1074 /************************************************************************/
1075 /* */
1076 /* FUNCTION DESCRIPTION zfLnxSignalThread */
1077 /* Signal Thread with Flag */
1078 /* */
1079 /* INPUTS */
1080 /* dev : device pointer */
1081 /* flag : signal thread flag */
1082 /* */
1083 /* OUTPUTS */
1084 /* none */
1085 /* */
1086 /* AUTHOR */
1087 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1088 /* */
1089 /************************************************************************/
1090 void zfLnxSignalThread(zdev_t *dev, int flag)
1092 struct usbdrv_private *macp = dev->ml_priv;
1094 if (macp == NULL)
1096 printk("macp is NULL\n");
1097 return;
1100 if (0 && macp->kevent_ready != 1)
1102 printk("Kevent not ready\n");
1103 return;
1106 set_bit(flag, &macp->kevent_flags);
1108 if (!schedule_work(&macp->kevent))
1110 //Fails is Normal
1111 //printk(KERN_ERR "schedule_task failed, flag = %x\n", flag);
1115 /* Notify wrapper todo redownload firmware and reinit procedure when */
1116 /* hardware watchdog occur : zfiHwWatchDogReinit() */
1117 void zfLnxWatchDogNotify(zdev_t* dev)
1119 zfLnxSignalThread(dev, KEVENT_WATCHDOG);
1122 /* Query Durantion of Active Scan */
1123 void zfwGetActiveScanDur(zdev_t* dev, u8_t* Dur)
1125 *Dur = 30; // default 30 ms
1128 void zfwGetShowZeroLengthSSID(zdev_t* dev, u8_t* Dur)
1130 *Dur = 0;