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 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,
53 u16_t zfLnxGetFreeTxUrb(zdev_t *dev)
55 struct usbdrv_private *macp = dev->ml_priv;
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));
72 //printk(KERN_ERR "macp->TxUrbCnt: %d\n", macp->TxUrbCnt);
76 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
80 void zfLnxPutTxUrb(zdev_t *dev)
82 struct usbdrv_private *macp = dev->ml_priv;
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;
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;
109 unsigned long irqFlag;
111 spin_lock_irqsave(&macp->cs_lock, irqFlag);
113 TxBufCnt = macp->TxBufCnt;
115 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
119 UsbTxQ_t *zfLnxGetUsbTxBuffer(zdev_t *dev)
121 struct usbdrv_private *macp = dev->ml_priv;
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));
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);
150 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
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;
161 unsigned long irqFlag;
163 spin_lock_irqsave(&macp->cs_lock, irqFlag);
165 idx = ((macp->TxBufTail+1) & (ZM_MAX_TX_BUF_NUM - 1));
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;
182 TxQ->offset = offset;
184 macp->TxBufTail = ((macp->TxBufTail+1) & (ZM_MAX_TX_BUF_NUM - 1));
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);
195 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
199 zbuf_t *zfLnxGetUsbRxBuffer(zdev_t *dev)
201 struct usbdrv_private *macp = dev->ml_priv;
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));
219 printk("RxBufQ inconsistent: RxBufHead: %d, RxBufTail: %d\n",
220 macp->RxBufHead, macp->RxBufTail);
221 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
225 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
229 u32_t zfLnxPutUsbRxBuffer(zdev_t *dev, zbuf_t *buf)
231 struct usbdrv_private *macp = dev->ml_priv;
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;
248 printk("RxBufQ inconsistent: RxBufHead: %d, RxBufTail: %d\n",
249 macp->RxBufHead, macp->RxBufTail);
250 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
254 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
258 void zfLnxUsbDataOut_callback(urb_t *urb)
260 zdev_t* dev = urb->context;
263 /* Give the urb back */
266 /* Check whether there is any pending buffer needed */
268 if (zfLnxCheckTxBufferCnt(dev) != 0)
270 //TxData = zfwGetUsbTxBuffer(dev);
272 //if (TxData == NULL)
274 // printk("Get a NULL buffer from zfwGetUsbTxBuffer\n");
279 zfLnxUsbSubmitTxData(dev);
284 void zfLnxUsbDataIn_callback(urb_t *urb)
286 zdev_t* dev = urb->context;
287 struct usbdrv_private *macp = dev->ml_priv;
292 #if ZM_USB_STREAM_MODE == 1
293 static int remain_len = 0, check_pad = 0, check_len = 0;
299 zbuf_t *rxBufPool[8];
300 u16_t rxBufPoolIndex = 0;
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");
314 if (urb->status == -EPROTO){
315 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
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);
326 /* Enqueue skb buffer */
327 zfLnxPutUsbRxBuffer(dev, buf);
329 /* Submit a Rx urb */
330 zfLnxUsbIn(dev, urb, buf);
335 if (urb->actual_length == 0)
337 printk(KERN_ERR "Get an URB whose length is zero");
341 /* Dequeue skb buffer */
342 buf = zfLnxGetUsbRxBuffer(dev);
344 //zfwBufSetSize(dev, buf, urb->actual_length);
345 #ifdef NET_SKBUFF_DATA_USES_OFFSET
349 buf->tail = buf->data;
353 BUG_ON((buf->tail + urb->actual_length) > buf->end);
355 skb_put(buf, urb->actual_length);
357 #if ZM_USB_STREAM_MODE == 1
360 zbuf_t *remain_buf = macp->reamin_buf;
363 remain_len -= check_pad;
366 memcpy(&(remain_buf->data[check_len]), buf->data, remain_len);
367 check_len += remain_len;
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)
382 //printk("Get a packet, index: %d, pkt_len: 0x%04x\n", index, pkt_len);
385 for (ii = index; ii < pkt_len+4;)
387 printk("%02x ", (buf->data[ii] & 0xff));
389 if ((++ii % 16) == 0)
396 pad_len = 4 - (pkt_len & 0x3);
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;
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
419 new_buf->tail = new_buf->data;
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;
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;
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
452 new_buf->tail = new_buf->data;
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
464 rxBufPool[rxBufPoolIndex++] = new_buf;
469 printk(KERN_ERR "Can't find tag, pkt_len: 0x%04x, tag: 0x%04x\n", pkt_len, pkt_tag);
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);
488 dev_kfree_skb_any(buf);
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]);
506 /* pass data to upper layer */
507 macp->usbCbFunctions.zfcbUsbRecv(dev, buf);
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;
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");
536 if (urb->status == -EPROTO){
537 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
542 //printk(KERN_ERR "urb->status: 0x%08x\n", urb->status);
546 if (urb->actual_length == 0)
548 printk(KERN_ERR "Get an URB whose length is zero");
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)
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);
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);
584 u32_t zfLnxUsbSubmitTxData(zdev_t* dev)
589 u8_t *puTxBuf = NULL;
592 struct usbdrv_private *macp = dev->ml_priv;
593 #if ZM_USB_TX_STREAM_MODE == 1
598 UsbTxQ_t *TxQPool[ZM_MAX_TX_AGGREGATE_NUM];
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");
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;
624 //printk("usbTxAggCnt: %d\n", usbTxAggCnt);
627 #if ZM_USB_TX_STREAM_MODE == 1
628 for(ii = 0; ii < usbTxAggCnt; ii++)
631 /* Dequeue the packet from UsbTxBufQ */
632 TxData = zfLnxGetUsbTxBuffer(dev);
635 /* Give the urb back */
640 /* Point to the freeTxUrb buffer */
641 puTxBuf = macp->txUsbBuf[freeTxUrb];
643 #if ZM_USB_TX_STREAM_MODE == 1
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;
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);
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;
684 if (TxData->hdrlen != 0)
686 puTxBuf = macp->txUsbBuf[freeTxUrb];
687 for (i = 0; i < len; i++)
689 printk("%02x ", puTxBuf[i]);
697 /* For debug purpose */
698 if(TxData->hdr[9] & 0x40)
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);
718 #if ZM_USB_TX_STREAM_MODE == 1
719 // Add the Length and Tag
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))
735 TxQPool[ii] = TxData;
737 //DbgPrint("%d packet, offset: %d\n", ii+1, pUsbTxTransfer->offset);
740 //zfBufFree(dev, txData->buf);
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);
750 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
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);
758 macp->usbCbFunctions.zfcbUsbOutComplete(dev, TxData->buf, 1, TxData->hdr);
766 u32_t zfLnxUsbIn(zdev_t* dev, urb_t *urb, zbuf_t *buf)
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);
777 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
782 u32_t zfLnxUsbWriteReg(zdev_t* dev, u32_t* cmd, u16_t cmdLen)
784 struct usbdrv_private *macp = dev->ml_priv;
787 #ifdef ZM_CONFIG_BIG_ENDIAN
790 for(ii=0; ii<(cmdLen>>2); ii++)
791 cmd[ii] = cpu_to_le32(cmd[ii]);
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);
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)
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)
819 //printk("CWY - zfwPutUsbTxBuffer Error, free packet\n");
820 //dev_kfree_skb_any(buf);
821 macp->usbCbFunctions.zfcbUsbOutComplete(dev, buf, 0, hdr);
826 //printk("CWY - call zfwUsbSubmitTxData()\n");
827 ret = zfLnxUsbSubmitTxData(dev);
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);
844 macp->TxUrbCnt = ZM_MAX_TX_URB_NUM;
847 void zfLnxInitUsbRxQ(zdev_t* dev)
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);
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;
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)
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;
892 usb_fill_bulk_urb(urb, usb, usb_rcvbulkpipe(usb, epnum),
893 transfer_buffer, buffer_length, complete, context);
900 //printk("CWY - urb->hcpriv set by unknown reason, reset it\n");
905 ret = usb_submit_urb(urb, GFP_ATOMIC);
906 if ((epnum == 4) & (ret != 0))
908 //printk("CWY - ret = %x\n", 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,
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);
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);
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
943 unsigned char *old_tail;
945 struct nlmsghdr *nlh;
948 size = NLMSG_SPACE(len);
949 skb = alloc_skb(size, GFP_ATOMIC);
953 printk("dev_alloc_skb failure \n");
956 old_tail = skb->tail;
958 /*ÌîдÊý¾Ý±¨Ïà¹ØÐÅÏ¢*/
959 nlh = NLMSG_PUT(skb, 0, 0, WAI_K_MSG, size-sizeof(*nlh));
960 pos = NLMSG_DATA(nlh);
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);
972 nlmsg_failure: /*NLMSG_PUT ʧ°Ü£¬Ôò³·ÏúÌ×½Ó×Ö»º´æ*/
976 #undef COMMTYPE_GROUP
979 #endif //ZM_ENABLE_CENC
981 /* Simply return 0xffff if VAP function is not supported */
982 u16_t zfLnxGetVapId(zdev_t* dev)
986 for (i=0; i<ZM_VAP_PORT_NUMBER; i++)
988 if (vap[i].dev == dev)
996 u32_t zfwReadReg(zdev_t* dev, u32_t offset)
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)
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;
1026 if (test_and_set_bit(0, (void *)&smp_kevent_Lock))
1028 //schedule_work(&macp->kevent);
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);
1044 clear_bit(0, (void *)&smp_kevent_Lock);
1045 up(&macp->ioctl_sem);
1048 /************************************************************************/
1050 /* FUNCTION DESCRIPTION zfLnxCreateThread */
1051 /* Create a Thread */
1054 /* dev : device pointer */
1060 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
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);
1074 /************************************************************************/
1076 /* FUNCTION DESCRIPTION zfLnxSignalThread */
1077 /* Signal Thread with Flag */
1080 /* dev : device pointer */
1081 /* flag : signal thread flag */
1087 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1089 /************************************************************************/
1090 void zfLnxSignalThread(zdev_t *dev, int flag)
1092 struct usbdrv_private *macp = dev->ml_priv;
1096 printk("macp is NULL\n");
1100 if (0 && macp->kevent_ready != 1)
1102 printk("Kevent not ready\n");
1106 set_bit(flag, &macp->kevent_flags);
1108 if (!schedule_work(&macp->kevent))
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)