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 */
18 /* This module contains wrapper functions. */
21 /* Platform dependent. */
24 /* Please include your header files here */
28 #include <linux/netlink.h>
29 #include <net/iw_handler.h>
31 extern void zfiRecv80211(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* addInfo
);
32 extern void zfCoreRecv(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* addInfo
);
33 extern void zfIdlChkRsp(zdev_t
* dev
, u32_t
* rsp
, u16_t rspLen
);
34 extern void zfIdlRsp(zdev_t
* dev
, u32_t
*rsp
, u16_t rspLen
);
38 //extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
39 extern struct zsVapStruct vap
[ZM_VAP_PORT_NUMBER
];
41 u32_t
zfLnxUsbSubmitTxData(zdev_t
* dev
);
42 u32_t
zfLnxUsbIn(zdev_t
* dev
, urb_t
*urb
, zbuf_t
*buf
);
43 u32_t
zfLnxSubmitRegInUrb(zdev_t
*dev
);
44 u32_t
zfLnxUsbSubmitBulkUrb(urb_t
*urb
, struct usb_device
*usb
, u16_t epnum
, u16_t direction
,
45 void *transfer_buffer
, int buffer_length
, usb_complete_t complete
, void *context
);
46 u32_t
zfLnxUsbSubmitIntUrb(urb_t
*urb
, struct usb_device
*usb
, u16_t epnum
, u16_t direction
,
47 void *transfer_buffer
, int buffer_length
, usb_complete_t complete
, void *context
,
50 u16_t
zfLnxGetFreeTxUrb(zdev_t
*dev
)
52 struct usbdrv_private
*macp
= dev
->ml_priv
;
54 unsigned long irqFlag
;
56 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
58 //idx = ((macp->TxUrbTail + 1) & (ZM_MAX_TX_URB_NUM - 1));
60 //if (idx != macp->TxUrbHead)
61 if (macp
->TxUrbCnt
!= 0)
63 idx
= macp
->TxUrbTail
;
64 macp
->TxUrbTail
= ((macp
->TxUrbTail
+ 1) & (ZM_MAX_TX_URB_NUM
- 1));
69 //printk(KERN_ERR "macp->TxUrbCnt: %d\n", macp->TxUrbCnt);
73 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
77 void zfLnxPutTxUrb(zdev_t
*dev
)
79 struct usbdrv_private
*macp
= dev
->ml_priv
;
81 unsigned long irqFlag
;
83 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
85 idx
= ((macp
->TxUrbHead
+ 1) & (ZM_MAX_TX_URB_NUM
- 1));
87 //if (idx != macp->TxUrbTail)
88 if (macp
->TxUrbCnt
< ZM_MAX_TX_URB_NUM
)
90 macp
->TxUrbHead
= idx
;
95 printk("UsbTxUrbQ inconsistent: TxUrbHead: %d, TxUrbTail: %d\n",
96 macp
->TxUrbHead
, macp
->TxUrbTail
);
99 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
102 u16_t
zfLnxCheckTxBufferCnt(zdev_t
*dev
)
104 struct usbdrv_private
*macp
= dev
->ml_priv
;
106 unsigned long irqFlag
;
108 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
110 TxBufCnt
= macp
->TxBufCnt
;
112 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
116 UsbTxQ_t
*zfLnxGetUsbTxBuffer(zdev_t
*dev
)
118 struct usbdrv_private
*macp
= dev
->ml_priv
;
121 unsigned long irqFlag
;
123 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
125 idx
= ((macp
->TxBufHead
+1) & (ZM_MAX_TX_BUF_NUM
- 1));
127 //if (idx != macp->TxBufTail)
128 if (macp
->TxBufCnt
> 0)
130 //printk("CWY - zfwGetUsbTxBuffer ,macp->TxBufCnt = %d\n", macp->TxBufCnt);
131 TxQ
= (UsbTxQ_t
*)&(macp
->UsbTxBufQ
[macp
->TxBufHead
]);
132 macp
->TxBufHead
= ((macp
->TxBufHead
+1) & (ZM_MAX_TX_BUF_NUM
- 1));
137 if (macp
->TxBufHead
!= macp
->TxBufTail
)
139 printk(KERN_ERR
"zfwGetUsbTxBuf UsbTxBufQ inconsistent: TxBufHead: %d, TxBufTail: %d\n",
140 macp
->TxBufHead
, macp
->TxBufTail
);
143 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
147 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
151 u16_t
zfLnxPutUsbTxBuffer(zdev_t
*dev
, u8_t
*hdr
, u16_t hdrlen
,
152 u8_t
*snap
, u16_t snapLen
, u8_t
*tail
, u16_t tailLen
,
153 zbuf_t
*buf
, u16_t offset
)
155 struct usbdrv_private
*macp
= dev
->ml_priv
;
158 unsigned long irqFlag
;
160 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
162 idx
= ((macp
->TxBufTail
+1) & (ZM_MAX_TX_BUF_NUM
- 1));
165 //zm_assert(macp->TxBufCnt >= 0); // deleted because of always true
167 //if (idx != macp->TxBufHead)
168 if (macp
->TxBufCnt
< ZM_MAX_TX_BUF_NUM
)
170 //printk("CWY - zfwPutUsbTxBuffer ,macp->TxBufCnt = %d\n", macp->TxBufCnt);
171 TxQ
= (UsbTxQ_t
*)&(macp
->UsbTxBufQ
[macp
->TxBufTail
]);
172 memcpy(TxQ
->hdr
, hdr
, hdrlen
);
173 TxQ
->hdrlen
= hdrlen
;
174 memcpy(TxQ
->snap
, snap
, snapLen
);
175 TxQ
->snapLen
= snapLen
;
176 memcpy(TxQ
->tail
, tail
, tailLen
);
177 TxQ
->tailLen
= tailLen
;
179 TxQ
->offset
= offset
;
181 macp
->TxBufTail
= ((macp
->TxBufTail
+1) & (ZM_MAX_TX_BUF_NUM
- 1));
186 printk(KERN_ERR
"zfLnxPutUsbTxBuffer UsbTxBufQ inconsistent: TxBufHead: %d, TxBufTail: %d, TxBufCnt: %d\n",
187 macp
->TxBufHead
, macp
->TxBufTail
, macp
->TxBufCnt
);
188 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
192 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
196 zbuf_t
*zfLnxGetUsbRxBuffer(zdev_t
*dev
)
198 struct usbdrv_private
*macp
= dev
->ml_priv
;
201 unsigned long irqFlag
;
203 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
205 //idx = ((macp->RxBufHead+1) & (ZM_MAX_RX_URB_NUM - 1));
207 //if (idx != macp->RxBufTail)
208 if (macp
->RxBufCnt
!= 0)
210 buf
= macp
->UsbRxBufQ
[macp
->RxBufHead
];
211 macp
->RxBufHead
= ((macp
->RxBufHead
+1) & (ZM_MAX_RX_URB_NUM
- 1));
216 printk("RxBufQ inconsistent: RxBufHead: %d, RxBufTail: %d\n",
217 macp
->RxBufHead
, macp
->RxBufTail
);
218 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
222 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
226 u32_t
zfLnxPutUsbRxBuffer(zdev_t
*dev
, zbuf_t
*buf
)
228 struct usbdrv_private
*macp
= dev
->ml_priv
;
230 unsigned long irqFlag
;
232 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
234 idx
= ((macp
->RxBufTail
+1) & (ZM_MAX_RX_URB_NUM
- 1));
236 //if (idx != macp->RxBufHead)
237 if (macp
->RxBufCnt
!= ZM_MAX_RX_URB_NUM
)
239 macp
->UsbRxBufQ
[macp
->RxBufTail
] = buf
;
240 macp
->RxBufTail
= idx
;
245 printk("RxBufQ inconsistent: RxBufHead: %d, RxBufTail: %d\n",
246 macp
->RxBufHead
, macp
->RxBufTail
);
247 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
251 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
255 void zfLnxUsbDataOut_callback(urb_t
*urb
)
257 zdev_t
* dev
= urb
->context
;
260 /* Give the urb back */
263 /* Check whether there is any pending buffer needed */
265 if (zfLnxCheckTxBufferCnt(dev
) != 0)
267 //TxData = zfwGetUsbTxBuffer(dev);
269 //if (TxData == NULL)
271 // printk("Get a NULL buffer from zfwGetUsbTxBuffer\n");
276 zfLnxUsbSubmitTxData(dev
);
281 void zfLnxUsbDataIn_callback(urb_t
*urb
)
283 zdev_t
* dev
= urb
->context
;
284 struct usbdrv_private
*macp
= dev
->ml_priv
;
289 #if ZM_USB_STREAM_MODE == 1
290 static int remain_len
= 0, check_pad
= 0, check_len
= 0;
296 zbuf_t
*rxBufPool
[8];
297 u16_t rxBufPoolIndex
= 0;
300 /* Check status for URB */
301 if (urb
->status
!= 0){
302 printk("zfLnxUsbDataIn_callback() : status=0x%x\n", urb
->status
);
303 if ((urb
->status
!= -ENOENT
) && (urb
->status
!= -ECONNRESET
)
304 && (urb
->status
!= -ESHUTDOWN
))
306 if (urb
->status
== -EPIPE
){
307 //printk(KERN_ERR "nonzero read bulk status received: -EPIPE");
311 if (urb
->status
== -EPROTO
){
312 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
317 //printk(KERN_ERR "urb->status: 0x%08x\n", urb->status);
319 /* Dequeue skb buffer */
320 buf
= zfLnxGetUsbRxBuffer(dev
);
321 dev_kfree_skb_any(buf
);
323 /* Enqueue skb buffer */
324 zfLnxPutUsbRxBuffer(dev
, buf
);
326 /* Submit a Rx urb */
327 zfLnxUsbIn(dev
, urb
, buf
);
332 if (urb
->actual_length
== 0)
334 printk(KERN_ERR
"Get an URB whose length is zero");
338 /* Dequeue skb buffer */
339 buf
= zfLnxGetUsbRxBuffer(dev
);
341 //zfwBufSetSize(dev, buf, urb->actual_length);
342 #ifdef NET_SKBUFF_DATA_USES_OFFSET
346 buf
->tail
= buf
->data
;
350 BUG_ON((buf
->tail
+ urb
->actual_length
) > buf
->end
);
352 skb_put(buf
, urb
->actual_length
);
354 #if ZM_USB_STREAM_MODE == 1
357 zbuf_t
*remain_buf
= macp
->reamin_buf
;
360 remain_len
-= check_pad
;
363 memcpy(&(remain_buf
->data
[check_len
]), buf
->data
, remain_len
);
364 check_len
+= remain_len
;
367 rxBufPool
[rxBufPoolIndex
++] = remain_buf
;
370 while(index
< urb
->actual_length
)
372 pkt_len
= buf
->data
[index
] + (buf
->data
[index
+1] << 8);
373 pkt_tag
= buf
->data
[index
+2] + (buf
->data
[index
+3] << 8);
375 if (pkt_tag
== 0x4e00)
379 //printk("Get a packet, index: %d, pkt_len: 0x%04x\n", index, pkt_len);
382 for (ii
= index
; ii
< pkt_len
+4;)
384 printk("%02x ", (buf
->data
[ii
] & 0xff));
386 if ((++ii
% 16) == 0)
393 pad_len
= 4 - (pkt_len
& 0x3);
399 index
= index
+ 4 + pkt_len
+ pad_len
;
401 if (index
> ZM_MAX_RX_BUFFER_SIZE
)
403 remain_len
= index
- ZM_MAX_RX_BUFFER_SIZE
; // - pad_len;
404 check_len
= ZM_MAX_RX_BUFFER_SIZE
- chk_idx
- 4;
407 /* Allocate a skb buffer */
408 //new_buf = zfwBufAllocate(dev, ZM_MAX_RX_BUFFER_SIZE);
409 new_buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
411 /* Set skb buffer length */
412 #ifdef NET_SKBUFF_DATA_USES_OFFSET
416 new_buf
->tail
= new_buf
->data
;
420 skb_put(new_buf
, pkt_len
);
422 /* Copy the buffer */
423 memcpy(new_buf
->data
, &(buf
->data
[chk_idx
+4]), check_len
);
425 /* Record the buffer pointer */
426 macp
->reamin_buf
= new_buf
;
430 #ifdef ZM_DONT_COPY_RX_BUFFER
431 if (rxBufPoolIndex
== 0)
433 new_buf
= skb_clone(buf
, GFP_ATOMIC
);
435 new_buf
->data
= &(buf
->data
[chk_idx
+4]);
436 new_buf
->len
= pkt_len
;
441 /* Allocate a skb buffer */
442 new_buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
444 /* Set skb buffer length */
445 #ifdef NET_SKBUFF_DATA_USES_OFFSET
449 new_buf
->tail
= new_buf
->data
;
453 skb_put(new_buf
, pkt_len
);
455 /* Copy the buffer */
456 memcpy(new_buf
->data
, &(buf
->data
[chk_idx
+4]), pkt_len
);
458 #ifdef ZM_DONT_COPY_RX_BUFFER
461 rxBufPool
[rxBufPoolIndex
++] = new_buf
;
466 printk(KERN_ERR
"Can't find tag, pkt_len: 0x%04x, tag: 0x%04x\n", pkt_len
, pkt_tag
);
469 dev_kfree_skb_any(buf
);
471 /* Allocate a skb buffer */
472 new_buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
474 /* Enqueue skb buffer */
475 zfLnxPutUsbRxBuffer(dev
, new_buf
);
477 /* Submit a Rx urb */
478 zfLnxUsbIn(dev
, urb
, new_buf
);
485 dev_kfree_skb_any(buf
);
488 /* Allocate a skb buffer */
489 new_buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
491 /* Enqueue skb buffer */
492 zfLnxPutUsbRxBuffer(dev
, new_buf
);
494 /* Submit a Rx urb */
495 zfLnxUsbIn(dev
, urb
, new_buf
);
497 #if ZM_USB_STREAM_MODE == 1
498 for(ii
= 0; ii
< rxBufPoolIndex
; ii
++)
500 macp
->usbCbFunctions
.zfcbUsbRecv(dev
, rxBufPool
[ii
]);
503 /* pass data to upper layer */
504 macp
->usbCbFunctions
.zfcbUsbRecv(dev
, buf
);
508 void zfLnxUsbRegOut_callback(urb_t
*urb
)
510 //dev_t* dev = urb->context;
512 //printk(KERN_ERR "zfwUsbRegOut_callback\n");
515 void zfLnxUsbRegIn_callback(urb_t
*urb
)
517 zdev_t
* dev
= urb
->context
;
520 struct usbdrv_private
*macp
= dev
->ml_priv
;
522 /* Check status for URB */
523 if (urb
->status
!= 0){
524 printk("zfLnxUsbRegIn_callback() : status=0x%x\n", urb
->status
);
525 if ((urb
->status
!= -ENOENT
) && (urb
->status
!= -ECONNRESET
)
526 && (urb
->status
!= -ESHUTDOWN
))
528 if (urb
->status
== -EPIPE
){
529 //printk(KERN_ERR "nonzero read bulk status received: -EPIPE");
533 if (urb
->status
== -EPROTO
){
534 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
539 //printk(KERN_ERR "urb->status: 0x%08x\n", urb->status);
543 if (urb
->actual_length
== 0)
545 printk(KERN_ERR
"Get an URB whose length is zero");
549 /* Copy data into respone buffer */
550 memcpy(rsp
, macp
->regUsbReadBuf
, urb
->actual_length
);
552 /* Notify to upper layer */
553 //zfIdlChkRsp(dev, rsp, (u16_t)urb->actual_length);
554 //zfiUsbRegIn(dev, rsp, (u16_t)urb->actual_length);
555 macp
->usbCbFunctions
.zfcbUsbRegIn(dev
, rsp
, (u16_t
)urb
->actual_length
);
557 /* Issue another USB IN URB */
558 zfLnxSubmitRegInUrb(dev
);
561 u32_t
zfLnxSubmitRegInUrb(zdev_t
*dev
)
564 struct usbdrv_private
*macp
= dev
->ml_priv
;
566 /* Submit a rx urb */
567 //ret = zfLnxUsbSubmitBulkUrb(macp->RegInUrb, macp->udev,
568 // USB_REG_IN_PIPE, USB_DIR_IN, macp->regUsbReadBuf,
569 // ZM_USB_REG_MAX_BUF_SIZE, zfLnxUsbRegIn_callback, dev);
572 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
574 ret
= zfLnxUsbSubmitIntUrb(macp
->RegInUrb
, macp
->udev
,
575 USB_REG_IN_PIPE
, USB_DIR_IN
, macp
->regUsbReadBuf
,
576 ZM_USB_REG_MAX_BUF_SIZE
, zfLnxUsbRegIn_callback
, dev
, 1);
581 u32_t
zfLnxUsbSubmitTxData(zdev_t
* dev
)
586 u8_t
*puTxBuf
= NULL
;
589 struct usbdrv_private
*macp
= dev
->ml_priv
;
590 #if ZM_USB_TX_STREAM_MODE == 1
595 UsbTxQ_t
*TxQPool
[ZM_MAX_TX_AGGREGATE_NUM
];
598 /* First check whether there is a free URB */
599 freeTxUrb
= zfLnxGetFreeTxUrb(dev
);
601 /* If there is no any free Tx Urb */
602 if (freeTxUrb
== 0xffff)
604 //printk(KERN_ERR "Can't get free Tx Urb\n");
605 //printk("CWY - Can't get free Tx Urb\n");
609 #if ZM_USB_TX_STREAM_MODE == 1
610 usbTxAggCnt
= zfLnxCheckTxBufferCnt(dev
);
612 if (usbTxAggCnt
>= ZM_MAX_TX_AGGREGATE_NUM
)
614 usbTxAggCnt
= ZM_MAX_TX_AGGREGATE_NUM
;
621 //printk("usbTxAggCnt: %d\n", usbTxAggCnt);
624 #if ZM_USB_TX_STREAM_MODE == 1
625 for(ii
= 0; ii
< usbTxAggCnt
; ii
++)
628 /* Dequeue the packet from UsbTxBufQ */
629 TxData
= zfLnxGetUsbTxBuffer(dev
);
632 /* Give the urb back */
637 /* Point to the freeTxUrb buffer */
638 puTxBuf
= macp
->txUsbBuf
[freeTxUrb
];
640 #if ZM_USB_TX_STREAM_MODE == 1
642 pUsbTxHdr
= (u16_t
*)puTxBuf
;
644 /* Add the packet length and tag information */
645 *pUsbTxHdr
++ = TxData
->hdrlen
+ TxData
->snapLen
+
646 (TxData
->buf
->len
- TxData
->offset
) + TxData
->tailLen
;
648 *pUsbTxHdr
++ = 0x697e;
651 #endif // #ifdef ZM_USB_TX_STREAM_MODE
653 /* Copy WLAN header and packet buffer into USB buffer */
654 for(i
= 0; i
< TxData
->hdrlen
; i
++)
656 *puTxBuf
++ = TxData
->hdr
[i
];
659 /* Copy SNAP header */
660 for(i
= 0; i
< TxData
->snapLen
; i
++)
662 *puTxBuf
++ = TxData
->snap
[i
];
665 /* Copy packet buffer */
666 for(i
= 0; i
< TxData
->buf
->len
- TxData
->offset
; i
++)
668 //*puTxBuf++ = zmw_rx_buf_readb(dev, TxData->buf, i);
669 *puTxBuf
++ = *(u8_t
*)((u8_t
*)TxData
->buf
->data
+i
+TxData
->offset
);
673 for(i
= 0; i
< TxData
->tailLen
; i
++)
675 *puTxBuf
++ = TxData
->tail
[i
];
678 len
= TxData
->hdrlen
+TxData
->snapLen
+TxData
->buf
->len
+TxData
->tailLen
-TxData
->offset
;
681 if (TxData
->hdrlen
!= 0)
683 puTxBuf
= macp
->txUsbBuf
[freeTxUrb
];
684 for (i
= 0; i
< len
; i
++)
686 printk("%02x ", puTxBuf
[i
]);
694 /* For debug purpose */
695 if(TxData
->hdr
[9] & 0x40)
698 u16_t ctrlLen
= TxData
->hdr
[0] + (TxData
->hdr
[1] << 8);
700 if (ctrlLen
!= len
+ 4)
702 /* Dump control setting */
703 for(i
= 0; i
< 8; i
++)
705 printk(KERN_ERR
"0x%02x ", TxData
->hdr
[i
]);
707 printk(KERN_ERR
"\n");
709 printk(KERN_ERR
"ctrLen: %d, hdrLen: %d, snapLen: %d\n", ctrlLen
, TxData
->hdrlen
, TxData
->snapLen
);
710 printk(KERN_ERR
"bufLen: %d, tailLen: %d, len: %d\n", TxData
->buf
->len
, TxData
->tailLen
, len
);
715 #if ZM_USB_TX_STREAM_MODE == 1
716 // Add the Length and Tag
719 //printk("%d packet, length: %d\n", ii+1, len);
721 if (ii
< (ZM_MAX_TX_AGGREGATE_NUM
-1))
723 /* Pad the buffer to firmware descriptor boundary */
724 offset
+= (((len
-1) / 4) + 1) * 4;
727 if (ii
== (ZM_MAX_TX_AGGREGATE_NUM
-1))
732 TxQPool
[ii
] = TxData
;
734 //DbgPrint("%d packet, offset: %d\n", ii+1, pUsbTxTransfer->offset);
737 //zfBufFree(dev, txData->buf);
740 //printk("CWY - call zfwUsbSubmitBulkUrb(), len = 0x%d\n", len);
741 /* Submit a tx urb */
742 ret
= zfLnxUsbSubmitBulkUrb(macp
->WlanTxDataUrb
[freeTxUrb
], macp
->udev
,
743 USB_WLAN_TX_PIPE
, USB_DIR_OUT
, macp
->txUsbBuf
[freeTxUrb
],
744 len
, zfLnxUsbDataOut_callback
, dev
);
747 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
750 //dev_kfree_skb_any(TxData->buf);
751 #if ZM_USB_TX_STREAM_MODE == 1
752 for(ii
= 0; ii
< usbTxAggCnt
; ii
++)
753 macp
->usbCbFunctions
.zfcbUsbOutComplete(dev
, TxQPool
[ii
]->buf
, 1, TxQPool
[ii
]->hdr
);
755 macp
->usbCbFunctions
.zfcbUsbOutComplete(dev
, TxData
->buf
, 1, TxData
->hdr
);
763 u32_t
zfLnxUsbIn(zdev_t
* dev
, urb_t
*urb
, zbuf_t
*buf
)
766 struct usbdrv_private
*macp
= dev
->ml_priv
;
768 /* Submit a rx urb */
769 ret
= zfLnxUsbSubmitBulkUrb(urb
, macp
->udev
, USB_WLAN_RX_PIPE
,
770 USB_DIR_IN
, buf
->data
, ZM_MAX_RX_BUFFER_SIZE
,
771 zfLnxUsbDataIn_callback
, dev
);
774 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
779 u32_t
zfLnxUsbWriteReg(zdev_t
* dev
, u32_t
* cmd
, u16_t cmdLen
)
781 struct usbdrv_private
*macp
= dev
->ml_priv
;
784 #ifdef ZM_CONFIG_BIG_ENDIAN
787 for(ii
=0; ii
<(cmdLen
>>2); ii
++)
788 cmd
[ii
] = cpu_to_le32(cmd
[ii
]);
791 memcpy(macp
->regUsbWriteBuf
, cmd
, cmdLen
);
793 /* Issue an USB Out transfer */
794 /* Submit a tx urb */
795 ret
= zfLnxUsbSubmitIntUrb(macp
->RegOutUrb
, macp
->udev
,
796 USB_REG_OUT_PIPE
, USB_DIR_OUT
, macp
->regUsbWriteBuf
,
797 cmdLen
, zfLnxUsbRegOut_callback
, dev
, 1);
803 u32_t
zfLnxUsbOut(zdev_t
* dev
, u8_t
*hdr
, u16_t hdrlen
, u8_t
*snap
, u16_t snapLen
,
804 u8_t
*tail
, u16_t tailLen
, zbuf_t
*buf
, u16_t offset
)
807 struct usbdrv_private
*macp
= dev
->ml_priv
;
809 /* Check length of tail buffer */
810 //zm_assert((tailLen <= 16));
812 /* Enqueue the packet into UsbTxBufQ */
813 if (zfLnxPutUsbTxBuffer(dev
, hdr
, hdrlen
, snap
, snapLen
, tail
, tailLen
, buf
, offset
) == 0xffff)
816 //printk("CWY - zfwPutUsbTxBuffer Error, free packet\n");
817 //dev_kfree_skb_any(buf);
818 macp
->usbCbFunctions
.zfcbUsbOutComplete(dev
, buf
, 0, hdr
);
823 //printk("CWY - call zfwUsbSubmitTxData()\n");
824 ret
= zfLnxUsbSubmitTxData(dev
);
828 void zfLnxInitUsbTxQ(zdev_t
* dev
)
830 struct usbdrv_private
*macp
= dev
->ml_priv
;
832 printk(KERN_ERR
"zfwInitUsbTxQ\n");
834 /* Zero memory for UsbTxBufQ */
835 memset(macp
->UsbTxBufQ
, 0, sizeof(UsbTxQ_t
) * ZM_MAX_TX_URB_NUM
);
841 macp
->TxUrbCnt
= ZM_MAX_TX_URB_NUM
;
844 void zfLnxInitUsbRxQ(zdev_t
* dev
)
848 struct usbdrv_private
*macp
= dev
->ml_priv
;
850 /* Zero memory for UsbRxBufQ */
851 memset(macp
->UsbRxBufQ
, 0, sizeof(zbuf_t
*) * ZM_MAX_RX_URB_NUM
);
855 for (i
= 0; i
< ZM_MAX_RX_URB_NUM
; i
++)
857 //buf = zfwBufAllocate(dev, ZM_MAX_RX_BUFFER_SIZE);
858 buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
859 macp
->UsbRxBufQ
[i
] = buf
;
862 //macp->RxBufTail = ZM_MAX_RX_URB_NUM - 1;
865 /* Submit all Rx urbs */
866 for (i
= 0; i
< ZM_MAX_RX_URB_NUM
; i
++)
868 zfLnxPutUsbRxBuffer(dev
, macp
->UsbRxBufQ
[i
]);
869 zfLnxUsbIn(dev
, macp
->WlanRxDataUrb
[i
], macp
->UsbRxBufQ
[i
]);
875 u32_t
zfLnxUsbSubmitBulkUrb(urb_t
*urb
, struct usb_device
*usb
, u16_t epnum
, u16_t direction
,
876 void *transfer_buffer
, int buffer_length
, usb_complete_t complete
, void *context
)
880 if(direction
== USB_DIR_OUT
)
882 usb_fill_bulk_urb(urb
, usb
, usb_sndbulkpipe(usb
, epnum
),
883 transfer_buffer
, buffer_length
, complete
, context
);
885 urb
->transfer_flags
|= URB_ZERO_PACKET
;
889 usb_fill_bulk_urb(urb
, usb
, usb_rcvbulkpipe(usb
, epnum
),
890 transfer_buffer
, buffer_length
, complete
, context
);
897 //printk("CWY - urb->hcpriv set by unknown reason, reset it\n");
902 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
903 if ((epnum
== 4) & (ret
!= 0))
905 //printk("CWY - ret = %x\n", ret);
910 u32_t
zfLnxUsbSubmitIntUrb(urb_t
*urb
, struct usb_device
*usb
, u16_t epnum
, u16_t direction
,
911 void *transfer_buffer
, int buffer_length
, usb_complete_t complete
, void *context
,
916 if(direction
== USB_DIR_OUT
)
918 usb_fill_int_urb(urb
, usb
, usb_sndbulkpipe(usb
, epnum
),
919 transfer_buffer
, buffer_length
, complete
, context
, interval
);
923 usb_fill_int_urb(urb
, usb
, usb_rcvbulkpipe(usb
, epnum
),
924 transfer_buffer
, buffer_length
, complete
, context
, interval
);
927 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
932 #ifdef ZM_ENABLE_CENC
933 int zfLnxCencSendMsg(struct sock
*netlink_sk
, u_int8_t
*msg
, int len
)
935 #define COMMTYPE_GROUP 8
936 #define WAI_K_MSG 0x11
940 unsigned char *old_tail
;
942 struct nlmsghdr
*nlh
;
945 size
= NLMSG_SPACE(len
);
946 skb
= alloc_skb(size
, GFP_ATOMIC
);
950 printk("dev_alloc_skb failure \n");
953 old_tail
= skb
->tail
;
955 /*ÌîдÊý¾Ý±¨Ïà¹ØÐÅÏ¢*/
956 nlh
= NLMSG_PUT(skb
, 0, 0, WAI_K_MSG
, size
-sizeof(*nlh
));
957 pos
= NLMSG_DATA(nlh
);
960 /*´«Êäµ½Óû§¿Õ¼äµÄÊý¾Ý*/
961 memcpy(pos
, msg
, len
);
962 /*¼ÆËã¾¹ý×Ö½Ú¶ÔÆäºóµÄÊý¾Ýʵ¼Ê³¤¶È*/
963 nlh
->nlmsg_len
= skb
->tail
- old_tail
;
964 NETLINK_CB(skb
).dst_group
= COMMTYPE_GROUP
;
965 netlink_broadcast(netlink_sk
, skb
, 0, COMMTYPE_GROUP
, GFP_ATOMIC
);
969 nlmsg_failure
: /*NLMSG_PUT ʧ°Ü£¬Ôò³·ÏúÌ×½Ó×Ö»º´æ*/
973 #undef COMMTYPE_GROUP
976 #endif //ZM_ENABLE_CENC
978 /* Simply return 0xffff if VAP function is not supported */
979 u16_t
zfLnxGetVapId(zdev_t
* dev
)
983 for (i
=0; i
<ZM_VAP_PORT_NUMBER
; i
++)
985 if (vap
[i
].dev
== dev
)
993 u32_t
zfwReadReg(zdev_t
* dev
, u32_t offset
)
999 #define work_struct tq_struct
1001 #define schedule_work(a) schedule_task(a)
1003 #define flush_scheduled_work flush_scheduled_tasks
1004 #define INIT_WORK(_wq, _routine, _data) INIT_TQUEUE(_wq, _routine, _data)
1005 #define PREPARE_WORK(_wq, _routine, _data) PREPARE_TQUEUE(_wq, _routine, _data)
1008 #define KEVENT_WATCHDOG 0x00000001
1010 u32_t smp_kevent_Lock
= 0;
1012 void kevent(struct work_struct
*work
)
1014 struct usbdrv_private
*macp
=
1015 container_of(work
, struct usbdrv_private
, kevent
);
1016 zdev_t
*dev
= macp
->device
;
1018 if (test_and_set_bit(0, (void *)&smp_kevent_Lock
))
1020 //schedule_work(&macp->kevent);
1024 down(&macp
->ioctl_sem
);
1026 if (test_and_clear_bit(KEVENT_WATCHDOG
, &macp
->kevent_flags
))
1028 extern u16_t
zfHpStartRecv(zdev_t
*dev
);
1029 //zfiHwWatchDogReinit(dev);
1030 printk(("\n ************ Hw watchDog occur!! ************** \n"));
1031 zfiWlanSuspend(dev
);
1032 zfiWlanResume(dev
,0);
1036 clear_bit(0, (void *)&smp_kevent_Lock
);
1037 up(&macp
->ioctl_sem
);
1040 /************************************************************************/
1042 /* FUNCTION DESCRIPTION zfLnxCreateThread */
1043 /* Create a Thread */
1046 /* dev : device pointer */
1052 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1054 /************************************************************************/
1055 u8_t
zfLnxCreateThread(zdev_t
*dev
)
1057 struct usbdrv_private
*macp
= dev
->ml_priv
;
1059 /* Create Mutex and keventd */
1060 INIT_WORK(&macp
->kevent
, kevent
);
1061 init_MUTEX(&macp
->ioctl_sem
);
1066 /************************************************************************/
1068 /* FUNCTION DESCRIPTION zfLnxSignalThread */
1069 /* Signal Thread with Flag */
1072 /* dev : device pointer */
1073 /* flag : signal thread flag */
1079 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1081 /************************************************************************/
1082 void zfLnxSignalThread(zdev_t
*dev
, int flag
)
1084 struct usbdrv_private
*macp
= dev
->ml_priv
;
1088 printk("macp is NULL\n");
1092 if (0 && macp
->kevent_ready
!= 1)
1094 printk("Kevent not ready\n");
1098 set_bit(flag
, &macp
->kevent_flags
);
1100 if (!schedule_work(&macp
->kevent
))
1103 //printk(KERN_ERR "schedule_task failed, flag = %x\n", flag);
1107 /* Notify wrapper todo redownload firmware and reinit procedure when */
1108 /* hardware watchdog occur : zfiHwWatchDogReinit() */
1109 void zfLnxWatchDogNotify(zdev_t
* dev
)
1111 zfLnxSignalThread(dev
, KEVENT_WATCHDOG
);
1114 /* Query Durantion of Active Scan */
1115 void zfwGetActiveScanDur(zdev_t
* dev
, u8_t
* Dur
)
1117 *Dur
= 30; // default 30 ms
1120 void zfwGetShowZeroLengthSSID(zdev_t
* dev
, u8_t
* Dur
)