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>
31 #include <net/iw_handler.h>
34 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
35 #define URB_ZERO_PACKET USB_ZERO_PACKET
38 extern void zfiRecv80211(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* addInfo
);
39 extern void zfCoreRecv(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* addInfo
);
40 extern void zfIdlChkRsp(zdev_t
* dev
, u32_t
* rsp
, u16_t rspLen
);
41 extern void zfIdlRsp(zdev_t
* dev
, u32_t
*rsp
, u16_t rspLen
);
45 //extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
46 extern struct zsVapStruct vap
[ZM_VAP_PORT_NUMBER
];
48 u32_t
zfLnxUsbSubmitTxData(zdev_t
* dev
);
49 u32_t
zfLnxUsbIn(zdev_t
* dev
, urb_t
*urb
, zbuf_t
*buf
);
50 u32_t
zfLnxSubmitRegInUrb(zdev_t
*dev
);
51 u32_t
zfLnxUsbSubmitBulkUrb(urb_t
*urb
, struct usb_device
*usb
, u16_t epnum
, u16_t direction
,
52 void *transfer_buffer
, int buffer_length
, usb_complete_t complete
, void *context
);
53 u32_t
zfLnxUsbSubmitIntUrb(urb_t
*urb
, struct usb_device
*usb
, u16_t epnum
, u16_t direction
,
54 void *transfer_buffer
, int buffer_length
, usb_complete_t complete
, void *context
,
57 u16_t
zfLnxGetFreeTxUrb(zdev_t
*dev
)
59 struct usbdrv_private
*macp
= dev
->ml_priv
;
61 unsigned long irqFlag
;
63 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
65 //idx = ((macp->TxUrbTail + 1) & (ZM_MAX_TX_URB_NUM - 1));
67 //if (idx != macp->TxUrbHead)
68 if (macp
->TxUrbCnt
!= 0)
70 idx
= macp
->TxUrbTail
;
71 macp
->TxUrbTail
= ((macp
->TxUrbTail
+ 1) & (ZM_MAX_TX_URB_NUM
- 1));
76 //printk(KERN_ERR "macp->TxUrbCnt: %d\n", macp->TxUrbCnt);
80 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
84 void zfLnxPutTxUrb(zdev_t
*dev
)
86 struct usbdrv_private
*macp
= dev
->ml_priv
;
88 unsigned long irqFlag
;
90 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
92 idx
= ((macp
->TxUrbHead
+ 1) & (ZM_MAX_TX_URB_NUM
- 1));
94 //if (idx != macp->TxUrbTail)
95 if (macp
->TxUrbCnt
< ZM_MAX_TX_URB_NUM
)
97 macp
->TxUrbHead
= idx
;
102 printk("UsbTxUrbQ inconsistent: TxUrbHead: %d, TxUrbTail: %d\n",
103 macp
->TxUrbHead
, macp
->TxUrbTail
);
106 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
109 u16_t
zfLnxCheckTxBufferCnt(zdev_t
*dev
)
111 struct usbdrv_private
*macp
= dev
->ml_priv
;
113 unsigned long irqFlag
;
115 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
117 TxBufCnt
= macp
->TxBufCnt
;
119 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
123 UsbTxQ_t
*zfLnxGetUsbTxBuffer(zdev_t
*dev
)
125 struct usbdrv_private
*macp
= dev
->ml_priv
;
128 unsigned long irqFlag
;
130 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
132 idx
= ((macp
->TxBufHead
+1) & (ZM_MAX_TX_BUF_NUM
- 1));
134 //if (idx != macp->TxBufTail)
135 if (macp
->TxBufCnt
> 0)
137 //printk("CWY - zfwGetUsbTxBuffer ,macp->TxBufCnt = %d\n", macp->TxBufCnt);
138 TxQ
= (UsbTxQ_t
*)&(macp
->UsbTxBufQ
[macp
->TxBufHead
]);
139 macp
->TxBufHead
= ((macp
->TxBufHead
+1) & (ZM_MAX_TX_BUF_NUM
- 1));
144 if (macp
->TxBufHead
!= macp
->TxBufTail
)
146 printk(KERN_ERR
"zfwGetUsbTxBuf UsbTxBufQ inconsistent: TxBufHead: %d, TxBufTail: %d\n",
147 macp
->TxBufHead
, macp
->TxBufTail
);
150 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
154 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
158 u16_t
zfLnxPutUsbTxBuffer(zdev_t
*dev
, u8_t
*hdr
, u16_t hdrlen
,
159 u8_t
*snap
, u16_t snapLen
, u8_t
*tail
, u16_t tailLen
,
160 zbuf_t
*buf
, u16_t offset
)
162 struct usbdrv_private
*macp
= dev
->ml_priv
;
165 unsigned long irqFlag
;
167 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
169 idx
= ((macp
->TxBufTail
+1) & (ZM_MAX_TX_BUF_NUM
- 1));
172 //zm_assert(macp->TxBufCnt >= 0); // deleted because of always true
174 //if (idx != macp->TxBufHead)
175 if (macp
->TxBufCnt
< ZM_MAX_TX_BUF_NUM
)
177 //printk("CWY - zfwPutUsbTxBuffer ,macp->TxBufCnt = %d\n", macp->TxBufCnt);
178 TxQ
= (UsbTxQ_t
*)&(macp
->UsbTxBufQ
[macp
->TxBufTail
]);
179 memcpy(TxQ
->hdr
, hdr
, hdrlen
);
180 TxQ
->hdrlen
= hdrlen
;
181 memcpy(TxQ
->snap
, snap
, snapLen
);
182 TxQ
->snapLen
= snapLen
;
183 memcpy(TxQ
->tail
, tail
, tailLen
);
184 TxQ
->tailLen
= tailLen
;
186 TxQ
->offset
= offset
;
188 macp
->TxBufTail
= ((macp
->TxBufTail
+1) & (ZM_MAX_TX_BUF_NUM
- 1));
193 printk(KERN_ERR
"zfLnxPutUsbTxBuffer UsbTxBufQ inconsistent: TxBufHead: %d, TxBufTail: %d, TxBufCnt: %d\n",
194 macp
->TxBufHead
, macp
->TxBufTail
, macp
->TxBufCnt
);
195 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
199 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
203 zbuf_t
*zfLnxGetUsbRxBuffer(zdev_t
*dev
)
205 struct usbdrv_private
*macp
= dev
->ml_priv
;
208 unsigned long irqFlag
;
210 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
212 //idx = ((macp->RxBufHead+1) & (ZM_MAX_RX_URB_NUM - 1));
214 //if (idx != macp->RxBufTail)
215 if (macp
->RxBufCnt
!= 0)
217 buf
= macp
->UsbRxBufQ
[macp
->RxBufHead
];
218 macp
->RxBufHead
= ((macp
->RxBufHead
+1) & (ZM_MAX_RX_URB_NUM
- 1));
223 printk("RxBufQ inconsistent: RxBufHead: %d, RxBufTail: %d\n",
224 macp
->RxBufHead
, macp
->RxBufTail
);
225 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
229 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
233 u32_t
zfLnxPutUsbRxBuffer(zdev_t
*dev
, zbuf_t
*buf
)
235 struct usbdrv_private
*macp
= dev
->ml_priv
;
237 unsigned long irqFlag
;
239 spin_lock_irqsave(&macp
->cs_lock
, irqFlag
);
241 idx
= ((macp
->RxBufTail
+1) & (ZM_MAX_RX_URB_NUM
- 1));
243 //if (idx != macp->RxBufHead)
244 if (macp
->RxBufCnt
!= ZM_MAX_RX_URB_NUM
)
246 macp
->UsbRxBufQ
[macp
->RxBufTail
] = buf
;
247 macp
->RxBufTail
= idx
;
252 printk("RxBufQ inconsistent: RxBufHead: %d, RxBufTail: %d\n",
253 macp
->RxBufHead
, macp
->RxBufTail
);
254 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
258 spin_unlock_irqrestore(&macp
->cs_lock
, irqFlag
);
262 void zfLnxUsbDataOut_callback(urb_t
*urb
)
264 zdev_t
* dev
= urb
->context
;
267 /* Give the urb back */
270 /* Check whether there is any pending buffer needed */
272 if (zfLnxCheckTxBufferCnt(dev
) != 0)
274 //TxData = zfwGetUsbTxBuffer(dev);
276 //if (TxData == NULL)
278 // printk("Get a NULL buffer from zfwGetUsbTxBuffer\n");
283 zfLnxUsbSubmitTxData(dev
);
288 void zfLnxUsbDataIn_callback(urb_t
*urb
)
290 zdev_t
* dev
= urb
->context
;
291 struct usbdrv_private
*macp
= dev
->ml_priv
;
296 #if ZM_USB_STREAM_MODE == 1
297 static int remain_len
= 0, check_pad
= 0, check_len
= 0;
303 zbuf_t
*rxBufPool
[8];
304 u16_t rxBufPoolIndex
= 0;
307 /* Check status for URB */
308 if (urb
->status
!= 0){
309 printk("zfLnxUsbDataIn_callback() : status=0x%x\n", urb
->status
);
310 if ((urb
->status
!= -ENOENT
) && (urb
->status
!= -ECONNRESET
)
311 && (urb
->status
!= -ESHUTDOWN
))
313 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
314 if (urb
->status
== USB_ST_INTERNALERROR
)
317 if (urb
->status
== -EPIPE
){
318 //printk(KERN_ERR "nonzero read bulk status received: -EPIPE");
322 if (urb
->status
== -EPROTO
){
323 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
329 //printk(KERN_ERR "urb->status: 0x%08x\n", urb->status);
331 /* Dequeue skb buffer */
332 buf
= zfLnxGetUsbRxBuffer(dev
);
333 dev_kfree_skb_any(buf
);
335 /* Enqueue skb buffer */
336 zfLnxPutUsbRxBuffer(dev
, buf
);
338 /* Submit a Rx urb */
339 zfLnxUsbIn(dev
, urb
, buf
);
344 if (urb
->actual_length
== 0)
346 printk(KERN_ERR
"Get an URB whose length is zero");
350 /* Dequeue skb buffer */
351 buf
= zfLnxGetUsbRxBuffer(dev
);
353 //zfwBufSetSize(dev, buf, urb->actual_length);
354 #ifdef NET_SKBUFF_DATA_USES_OFFSET
358 buf
->tail
= buf
->data
;
362 if ((buf
->tail
+ urb
->actual_length
) > buf
->end
)
365 skb_put(buf
, urb
->actual_length
);
367 #if ZM_USB_STREAM_MODE == 1
370 zbuf_t
*remain_buf
= macp
->reamin_buf
;
373 remain_len
-= check_pad
;
376 memcpy(&(remain_buf
->data
[check_len
]), buf
->data
, remain_len
);
377 check_len
+= remain_len
;
380 rxBufPool
[rxBufPoolIndex
++] = remain_buf
;
383 while(index
< urb
->actual_length
)
385 pkt_len
= buf
->data
[index
] + (buf
->data
[index
+1] << 8);
386 pkt_tag
= buf
->data
[index
+2] + (buf
->data
[index
+3] << 8);
388 if (pkt_tag
== 0x4e00)
392 //printk("Get a packet, index: %d, pkt_len: 0x%04x\n", index, pkt_len);
395 for (ii
= index
; ii
< pkt_len
+4;)
397 printk("%02x ", (buf
->data
[ii
] & 0xff));
399 if ((++ii
% 16) == 0)
406 pad_len
= 4 - (pkt_len
& 0x3);
412 index
= index
+ 4 + pkt_len
+ pad_len
;
414 if (index
> ZM_MAX_RX_BUFFER_SIZE
)
416 remain_len
= index
- ZM_MAX_RX_BUFFER_SIZE
; // - pad_len;
417 check_len
= ZM_MAX_RX_BUFFER_SIZE
- chk_idx
- 4;
420 /* Allocate a skb buffer */
421 //new_buf = zfwBufAllocate(dev, ZM_MAX_RX_BUFFER_SIZE);
422 new_buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
424 /* Set skb buffer length */
425 #ifdef NET_SKBUFF_DATA_USES_OFFSET
429 new_buf
->tail
= new_buf
->data
;
433 skb_put(new_buf
, pkt_len
);
435 /* Copy the buffer */
436 memcpy(new_buf
->data
, &(buf
->data
[chk_idx
+4]), check_len
);
438 /* Record the buffer pointer */
439 macp
->reamin_buf
= new_buf
;
443 #ifdef ZM_DONT_COPY_RX_BUFFER
444 if (rxBufPoolIndex
== 0)
446 new_buf
= skb_clone(buf
, GFP_ATOMIC
);
448 new_buf
->data
= &(buf
->data
[chk_idx
+4]);
449 new_buf
->len
= pkt_len
;
454 /* Allocate a skb buffer */
455 new_buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
457 /* Set skb buffer length */
458 #ifdef NET_SKBUFF_DATA_USES_OFFSET
462 new_buf
->tail
= new_buf
->data
;
466 skb_put(new_buf
, pkt_len
);
468 /* Copy the buffer */
469 memcpy(new_buf
->data
, &(buf
->data
[chk_idx
+4]), pkt_len
);
471 #ifdef ZM_DONT_COPY_RX_BUFFER
474 rxBufPool
[rxBufPoolIndex
++] = new_buf
;
479 printk(KERN_ERR
"Can't find tag, pkt_len: 0x%04x, tag: 0x%04x\n", pkt_len
, pkt_tag
);
482 dev_kfree_skb_any(buf
);
484 /* Allocate a skb buffer */
485 new_buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
487 /* Enqueue skb buffer */
488 zfLnxPutUsbRxBuffer(dev
, new_buf
);
490 /* Submit a Rx urb */
491 zfLnxUsbIn(dev
, urb
, new_buf
);
498 dev_kfree_skb_any(buf
);
501 /* Allocate a skb buffer */
502 new_buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
504 /* Enqueue skb buffer */
505 zfLnxPutUsbRxBuffer(dev
, new_buf
);
507 /* Submit a Rx urb */
508 zfLnxUsbIn(dev
, urb
, new_buf
);
510 #if ZM_USB_STREAM_MODE == 1
511 for(ii
= 0; ii
< rxBufPoolIndex
; ii
++)
513 macp
->usbCbFunctions
.zfcbUsbRecv(dev
, rxBufPool
[ii
]);
516 /* pass data to upper layer */
517 macp
->usbCbFunctions
.zfcbUsbRecv(dev
, buf
);
521 void zfLnxUsbRegOut_callback(urb_t
*urb
)
523 //dev_t* dev = urb->context;
525 //printk(KERN_ERR "zfwUsbRegOut_callback\n");
528 void zfLnxUsbRegIn_callback(urb_t
*urb
)
530 zdev_t
* dev
= urb
->context
;
533 struct usbdrv_private
*macp
= dev
->ml_priv
;
535 /* Check status for URB */
536 if (urb
->status
!= 0){
537 printk("zfLnxUsbRegIn_callback() : status=0x%x\n", urb
->status
);
538 if ((urb
->status
!= -ENOENT
) && (urb
->status
!= -ECONNRESET
)
539 && (urb
->status
!= -ESHUTDOWN
))
541 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
542 if (urb
->status
== USB_ST_INTERNALERROR
)
545 if (urb
->status
== -EPIPE
){
546 //printk(KERN_ERR "nonzero read bulk status received: -EPIPE");
550 if (urb
->status
== -EPROTO
){
551 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
557 //printk(KERN_ERR "urb->status: 0x%08x\n", urb->status);
561 if (urb
->actual_length
== 0)
563 printk(KERN_ERR
"Get an URB whose length is zero");
567 /* Copy data into respone buffer */
568 memcpy(rsp
, macp
->regUsbReadBuf
, urb
->actual_length
);
570 /* Notify to upper layer */
571 //zfIdlChkRsp(dev, rsp, (u16_t)urb->actual_length);
572 //zfiUsbRegIn(dev, rsp, (u16_t)urb->actual_length);
573 macp
->usbCbFunctions
.zfcbUsbRegIn(dev
, rsp
, (u16_t
)urb
->actual_length
);
575 /* Issue another USB IN URB */
576 zfLnxSubmitRegInUrb(dev
);
579 u32_t
zfLnxSubmitRegInUrb(zdev_t
*dev
)
582 struct usbdrv_private
*macp
= dev
->ml_priv
;
584 /* Submit a rx urb */
585 //ret = zfLnxUsbSubmitBulkUrb(macp->RegInUrb, macp->udev,
586 // USB_REG_IN_PIPE, USB_DIR_IN, macp->regUsbReadBuf,
587 // ZM_USB_REG_MAX_BUF_SIZE, zfLnxUsbRegIn_callback, dev);
590 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
592 ret
= zfLnxUsbSubmitIntUrb(macp
->RegInUrb
, macp
->udev
,
593 USB_REG_IN_PIPE
, USB_DIR_IN
, macp
->regUsbReadBuf
,
594 ZM_USB_REG_MAX_BUF_SIZE
, zfLnxUsbRegIn_callback
, dev
, 1);
599 u32_t
zfLnxUsbSubmitTxData(zdev_t
* dev
)
604 u8_t
*puTxBuf
= NULL
;
607 struct usbdrv_private
*macp
= dev
->ml_priv
;
608 #if ZM_USB_TX_STREAM_MODE == 1
613 UsbTxQ_t
*TxQPool
[ZM_MAX_TX_AGGREGATE_NUM
];
616 /* First check whether there is a free URB */
617 freeTxUrb
= zfLnxGetFreeTxUrb(dev
);
619 /* If there is no any free Tx Urb */
620 if (freeTxUrb
== 0xffff)
622 //printk(KERN_ERR "Can't get free Tx Urb\n");
623 //printk("CWY - Can't get free Tx Urb\n");
627 #if ZM_USB_TX_STREAM_MODE == 1
628 usbTxAggCnt
= zfLnxCheckTxBufferCnt(dev
);
630 if (usbTxAggCnt
>= ZM_MAX_TX_AGGREGATE_NUM
)
632 usbTxAggCnt
= ZM_MAX_TX_AGGREGATE_NUM
;
639 //printk("usbTxAggCnt: %d\n", usbTxAggCnt);
642 #if ZM_USB_TX_STREAM_MODE == 1
643 for(ii
= 0; ii
< usbTxAggCnt
; ii
++)
646 /* Dequeue the packet from UsbTxBufQ */
647 TxData
= zfLnxGetUsbTxBuffer(dev
);
650 /* Give the urb back */
655 /* Point to the freeTxUrb buffer */
656 puTxBuf
= macp
->txUsbBuf
[freeTxUrb
];
658 #if ZM_USB_TX_STREAM_MODE == 1
660 pUsbTxHdr
= (u16_t
*)puTxBuf
;
662 /* Add the packet length and tag information */
663 *pUsbTxHdr
++ = TxData
->hdrlen
+ TxData
->snapLen
+
664 (TxData
->buf
->len
- TxData
->offset
) + TxData
->tailLen
;
666 *pUsbTxHdr
++ = 0x697e;
669 #endif // #ifdef ZM_USB_TX_STREAM_MODE
671 /* Copy WLAN header and packet buffer into USB buffer */
672 for(i
= 0; i
< TxData
->hdrlen
; i
++)
674 *puTxBuf
++ = TxData
->hdr
[i
];
677 /* Copy SNAP header */
678 for(i
= 0; i
< TxData
->snapLen
; i
++)
680 *puTxBuf
++ = TxData
->snap
[i
];
683 /* Copy packet buffer */
684 for(i
= 0; i
< TxData
->buf
->len
- TxData
->offset
; i
++)
686 //*puTxBuf++ = zmw_rx_buf_readb(dev, TxData->buf, i);
687 *puTxBuf
++ = *(u8_t
*)((u8_t
*)TxData
->buf
->data
+i
+TxData
->offset
);
691 for(i
= 0; i
< TxData
->tailLen
; i
++)
693 *puTxBuf
++ = TxData
->tail
[i
];
696 len
= TxData
->hdrlen
+TxData
->snapLen
+TxData
->buf
->len
+TxData
->tailLen
-TxData
->offset
;
699 if (TxData
->hdrlen
!= 0)
701 puTxBuf
= macp
->txUsbBuf
[freeTxUrb
];
702 for (i
= 0; i
< len
; i
++)
704 printk("%02x ", puTxBuf
[i
]);
712 /* For debug purpose */
713 if(TxData
->hdr
[9] & 0x40)
716 u16_t ctrlLen
= TxData
->hdr
[0] + (TxData
->hdr
[1] << 8);
718 if (ctrlLen
!= len
+ 4)
720 /* Dump control setting */
721 for(i
= 0; i
< 8; i
++)
723 printk(KERN_ERR
"0x%02x ", TxData
->hdr
[i
]);
725 printk(KERN_ERR
"\n");
727 printk(KERN_ERR
"ctrLen: %d, hdrLen: %d, snapLen: %d\n", ctrlLen
, TxData
->hdrlen
, TxData
->snapLen
);
728 printk(KERN_ERR
"bufLen: %d, tailLen: %d, len: %d\n", TxData
->buf
->len
, TxData
->tailLen
, len
);
733 #if ZM_USB_TX_STREAM_MODE == 1
734 // Add the Length and Tag
737 //printk("%d packet, length: %d\n", ii+1, len);
739 if (ii
< (ZM_MAX_TX_AGGREGATE_NUM
-1))
741 /* Pad the buffer to firmware descriptor boundary */
742 offset
+= (((len
-1) / 4) + 1) * 4;
745 if (ii
== (ZM_MAX_TX_AGGREGATE_NUM
-1))
750 TxQPool
[ii
] = TxData
;
752 //DbgPrint("%d packet, offset: %d\n", ii+1, pUsbTxTransfer->offset);
755 //zfBufFree(dev, txData->buf);
758 //printk("CWY - call zfwUsbSubmitBulkUrb(), len = 0x%d\n", len);
759 /* Submit a tx urb */
760 ret
= zfLnxUsbSubmitBulkUrb(macp
->WlanTxDataUrb
[freeTxUrb
], macp
->udev
,
761 USB_WLAN_TX_PIPE
, USB_DIR_OUT
, macp
->txUsbBuf
[freeTxUrb
],
762 len
, zfLnxUsbDataOut_callback
, dev
);
765 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
768 //dev_kfree_skb_any(TxData->buf);
769 #if ZM_USB_TX_STREAM_MODE == 1
770 for(ii
= 0; ii
< usbTxAggCnt
; ii
++)
771 macp
->usbCbFunctions
.zfcbUsbOutComplete(dev
, TxQPool
[ii
]->buf
, 1, TxQPool
[ii
]->hdr
);
773 macp
->usbCbFunctions
.zfcbUsbOutComplete(dev
, TxData
->buf
, 1, TxData
->hdr
);
781 u32_t
zfLnxUsbIn(zdev_t
* dev
, urb_t
*urb
, zbuf_t
*buf
)
784 struct usbdrv_private
*macp
= dev
->ml_priv
;
786 /* Submit a rx urb */
787 ret
= zfLnxUsbSubmitBulkUrb(urb
, macp
->udev
, USB_WLAN_RX_PIPE
,
788 USB_DIR_IN
, buf
->data
, ZM_MAX_RX_BUFFER_SIZE
,
789 zfLnxUsbDataIn_callback
, dev
);
792 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
797 u32_t
zfLnxUsbWriteReg(zdev_t
* dev
, u32_t
* cmd
, u16_t cmdLen
)
799 struct usbdrv_private
*macp
= dev
->ml_priv
;
802 #ifdef ZM_CONFIG_BIG_ENDIAN
805 for(ii
=0; ii
<(cmdLen
>>2); ii
++)
806 cmd
[ii
] = cpu_to_le32(cmd
[ii
]);
809 memcpy(macp
->regUsbWriteBuf
, cmd
, cmdLen
);
811 /* Issue an USB Out transfer */
812 /* Submit a tx urb */
813 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
814 ret
= zfLnxUsbSubmitBulkUrb(macp
->RegOutUrb
, macp
->udev
,
815 USB_REG_OUT_PIPE
, USB_DIR_OUT
, macp
->regUsbWriteBuf
,
816 cmdLen
, zfLnxUsbRegOut_callback
, dev
);
818 ret
= zfLnxUsbSubmitIntUrb(macp
->RegOutUrb
, macp
->udev
,
819 USB_REG_OUT_PIPE
, USB_DIR_OUT
, macp
->regUsbWriteBuf
,
820 cmdLen
, zfLnxUsbRegOut_callback
, dev
, 1);
827 u32_t
zfLnxUsbOut(zdev_t
* dev
, u8_t
*hdr
, u16_t hdrlen
, u8_t
*snap
, u16_t snapLen
,
828 u8_t
*tail
, u16_t tailLen
, zbuf_t
*buf
, u16_t offset
)
831 struct usbdrv_private
*macp
= dev
->ml_priv
;
833 /* Check length of tail buffer */
834 //zm_assert((tailLen <= 16));
836 /* Enqueue the packet into UsbTxBufQ */
837 if (zfLnxPutUsbTxBuffer(dev
, hdr
, hdrlen
, snap
, snapLen
, tail
, tailLen
, buf
, offset
) == 0xffff)
840 //printk("CWY - zfwPutUsbTxBuffer Error, free packet\n");
841 //dev_kfree_skb_any(buf);
842 macp
->usbCbFunctions
.zfcbUsbOutComplete(dev
, buf
, 0, hdr
);
847 //printk("CWY - call zfwUsbSubmitTxData()\n");
848 ret
= zfLnxUsbSubmitTxData(dev
);
852 void zfLnxInitUsbTxQ(zdev_t
* dev
)
854 struct usbdrv_private
*macp
= dev
->ml_priv
;
856 printk(KERN_ERR
"zfwInitUsbTxQ\n");
858 /* Zero memory for UsbTxBufQ */
859 memset(macp
->UsbTxBufQ
, 0, sizeof(UsbTxQ_t
) * ZM_MAX_TX_URB_NUM
);
865 macp
->TxUrbCnt
= ZM_MAX_TX_URB_NUM
;
868 void zfLnxInitUsbRxQ(zdev_t
* dev
)
872 struct usbdrv_private
*macp
= dev
->ml_priv
;
874 /* Zero memory for UsbRxBufQ */
875 memset(macp
->UsbRxBufQ
, 0, sizeof(zbuf_t
*) * ZM_MAX_RX_URB_NUM
);
879 for (i
= 0; i
< ZM_MAX_RX_URB_NUM
; i
++)
881 //buf = zfwBufAllocate(dev, ZM_MAX_RX_BUFFER_SIZE);
882 buf
= dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE
);
883 macp
->UsbRxBufQ
[i
] = buf
;
886 //macp->RxBufTail = ZM_MAX_RX_URB_NUM - 1;
889 /* Submit all Rx urbs */
890 for (i
= 0; i
< ZM_MAX_RX_URB_NUM
; i
++)
892 zfLnxPutUsbRxBuffer(dev
, macp
->UsbRxBufQ
[i
]);
893 zfLnxUsbIn(dev
, macp
->WlanRxDataUrb
[i
], macp
->UsbRxBufQ
[i
]);
899 u32_t
zfLnxUsbSubmitBulkUrb(urb_t
*urb
, struct usb_device
*usb
, u16_t epnum
, u16_t direction
,
900 void *transfer_buffer
, int buffer_length
, usb_complete_t complete
, void *context
)
904 if(direction
== USB_DIR_OUT
)
906 usb_fill_bulk_urb(urb
, usb
, usb_sndbulkpipe(usb
, epnum
),
907 transfer_buffer
, buffer_length
, complete
, context
);
909 urb
->transfer_flags
|= URB_ZERO_PACKET
;
913 usb_fill_bulk_urb(urb
, usb
, usb_rcvbulkpipe(usb
, epnum
),
914 transfer_buffer
, buffer_length
, complete
, context
);
917 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
918 urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
925 //printk("CWY - urb->hcpriv set by unknown reason, reset it\n");
930 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
931 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
933 ret
= usb_submit_urb(urb
);
935 if ((epnum
== 4) & (ret
!= 0))
937 //printk("CWY - ret = %x\n", ret);
942 u32_t
zfLnxUsbSubmitIntUrb(urb_t
*urb
, struct usb_device
*usb
, u16_t epnum
, u16_t direction
,
943 void *transfer_buffer
, int buffer_length
, usb_complete_t complete
, void *context
,
948 if(direction
== USB_DIR_OUT
)
950 usb_fill_int_urb(urb
, usb
, usb_sndbulkpipe(usb
, epnum
),
951 transfer_buffer
, buffer_length
, complete
, context
, interval
);
955 usb_fill_int_urb(urb
, usb
, usb_rcvbulkpipe(usb
, epnum
),
956 transfer_buffer
, buffer_length
, complete
, context
, interval
);
959 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
960 urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
963 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
964 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
966 ret
= usb_submit_urb(urb
);
972 #ifdef ZM_ENABLE_CENC
973 int zfLnxCencSendMsg(struct sock
*netlink_sk
, u_int8_t
*msg
, int len
)
975 #define COMMTYPE_GROUP 8
976 #define WAI_K_MSG 0x11
980 unsigned char *old_tail
;
982 struct nlmsghdr
*nlh
;
985 size
= NLMSG_SPACE(len
);
986 skb
= alloc_skb(size
, GFP_ATOMIC
);
990 printk("dev_alloc_skb failure \n");
993 old_tail
= skb
->tail
;
995 /*ÌîдÊý¾Ý±¨Ïà¹ØÐÅÏ¢*/
996 nlh
= NLMSG_PUT(skb
, 0, 0, WAI_K_MSG
, size
-sizeof(*nlh
));
997 pos
= NLMSG_DATA(nlh
);
1000 /*´«Êäµ½Óû§¿Õ¼äµÄÊý¾Ý*/
1001 memcpy(pos
, msg
, len
);
1002 /*¼ÆËã¾¹ý×Ö½Ú¶ÔÆäºóµÄÊý¾Ýʵ¼Ê³¤¶È*/
1003 nlh
->nlmsg_len
= skb
->tail
- old_tail
;
1004 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
1005 NETLINK_CB(skb
).dst_groups
= COMMTYPE_GROUP
;
1007 NETLINK_CB(skb
).dst_group
= COMMTYPE_GROUP
;
1009 netlink_broadcast(netlink_sk
, skb
, 0, COMMTYPE_GROUP
, GFP_ATOMIC
);
1013 nlmsg_failure
: /*NLMSG_PUT ʧ°Ü£¬Ôò³·ÏúÌ×½Ó×Ö»º´æ*/
1018 #undef COMMTYPE_GROUP
1021 #endif //ZM_ENABLE_CENC
1023 /* Simply return 0xffff if VAP function is not supported */
1024 u16_t
zfLnxGetVapId(zdev_t
* dev
)
1028 for (i
=0; i
<ZM_VAP_PORT_NUMBER
; i
++)
1030 if (vap
[i
].dev
== dev
)
1038 u32_t
zfwReadReg(zdev_t
* dev
, u32_t offset
)
1044 #define work_struct tq_struct
1046 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
1047 #define schedule_work(a) queue_task(a, &tq_scheduler)
1049 #define schedule_work(a) schedule_task(a)
1052 #define flush_scheduled_work flush_scheduled_tasks
1053 #define INIT_WORK(_wq, _routine, _data) INIT_TQUEUE(_wq, _routine, _data)
1054 #define PREPARE_WORK(_wq, _routine, _data) PREPARE_TQUEUE(_wq, _routine, _data)
1057 #define KEVENT_WATCHDOG 0x00000001
1059 u32_t smp_kevent_Lock
= 0;
1061 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,20))
1062 void kevent(struct work_struct
*work
)
1064 void kevent(void *data
)
1067 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,20))
1068 struct usbdrv_private
*macp
=
1069 container_of(work
, struct usbdrv_private
, kevent
);
1070 zdev_t
*dev
= macp
->device
;
1072 zdev_t
*dev
= (zdev_t
*) data
;
1073 struct usbdrv_private
*macp
= dev
->ml_priv
;
1081 if (test_and_set_bit(0, (void *)&smp_kevent_Lock
))
1083 //schedule_work(&macp->kevent);
1087 down(&macp
->ioctl_sem
);
1089 if (test_and_clear_bit(KEVENT_WATCHDOG
, &macp
->kevent_flags
))
1091 extern u16_t
zfHpStartRecv(zdev_t
*dev
);
1092 //zfiHwWatchDogReinit(dev);
1093 printk(("\n ************ Hw watchDog occur!! ************** \n"));
1094 zfiWlanSuspend(dev
);
1095 zfiWlanResume(dev
,0);
1099 clear_bit(0, (void *)&smp_kevent_Lock
);
1100 up(&macp
->ioctl_sem
);
1103 /************************************************************************/
1105 /* FUNCTION DESCRIPTION zfLnxCreateThread */
1106 /* Create a Thread */
1109 /* dev : device pointer */
1115 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1117 /************************************************************************/
1118 u8_t
zfLnxCreateThread(zdev_t
*dev
)
1120 struct usbdrv_private
*macp
= dev
->ml_priv
;
1122 /* Create Mutex and keventd */
1123 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20))
1124 INIT_WORK(&macp
->kevent
, kevent
, dev
);
1126 INIT_WORK(&macp
->kevent
, kevent
);
1128 init_MUTEX(&macp
->ioctl_sem
);
1133 /************************************************************************/
1135 /* FUNCTION DESCRIPTION zfLnxSignalThread */
1136 /* Signal Thread with Flag */
1139 /* dev : device pointer */
1140 /* flag : signal thread flag */
1146 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1148 /************************************************************************/
1149 void zfLnxSignalThread(zdev_t
*dev
, int flag
)
1151 struct usbdrv_private
*macp
= dev
->ml_priv
;
1155 printk("macp is NULL\n");
1159 if (0 && macp
->kevent_ready
!= 1)
1161 printk("Kevent not ready\n");
1165 set_bit(flag
, &macp
->kevent_flags
);
1167 if (!schedule_work(&macp
->kevent
))
1170 //printk(KERN_ERR "schedule_task failed, flag = %x\n", flag);
1174 /* Notify wrapper todo redownload firmware and reinit procedure when */
1175 /* hardware watchdog occur : zfiHwWatchDogReinit() */
1176 void zfLnxWatchDogNotify(zdev_t
* dev
)
1178 zfLnxSignalThread(dev
, KEVENT_WATCHDOG
);
1181 /* Query Durantion of Active Scan */
1182 void zfwGetActiveScanDur(zdev_t
* dev
, u8_t
* Dur
)
1184 *Dur
= 30; // default 30 ms
1187 void zfwGetShowZeroLengthSSID(zdev_t
* dev
, u8_t
* Dur
)