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 if ((buf->tail + urb->actual_length) > buf->end)
356 skb_put(buf, urb->actual_length);
358 #if ZM_USB_STREAM_MODE == 1
361 zbuf_t *remain_buf = macp->reamin_buf;
364 remain_len -= check_pad;
367 memcpy(&(remain_buf->data[check_len]), buf->data, remain_len);
368 check_len += remain_len;
371 rxBufPool[rxBufPoolIndex++] = remain_buf;
374 while(index < urb->actual_length)
376 pkt_len = buf->data[index] + (buf->data[index+1] << 8);
377 pkt_tag = buf->data[index+2] + (buf->data[index+3] << 8);
379 if (pkt_tag == 0x4e00)
383 //printk("Get a packet, index: %d, pkt_len: 0x%04x\n", index, pkt_len);
386 for (ii = index; ii < pkt_len+4;)
388 printk("%02x ", (buf->data[ii] & 0xff));
390 if ((++ii % 16) == 0)
397 pad_len = 4 - (pkt_len & 0x3);
403 index = index + 4 + pkt_len + pad_len;
405 if (index > ZM_MAX_RX_BUFFER_SIZE)
407 remain_len = index - ZM_MAX_RX_BUFFER_SIZE; // - pad_len;
408 check_len = ZM_MAX_RX_BUFFER_SIZE - chk_idx - 4;
411 /* Allocate a skb buffer */
412 //new_buf = zfwBufAllocate(dev, ZM_MAX_RX_BUFFER_SIZE);
413 new_buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
415 /* Set skb buffer length */
416 #ifdef NET_SKBUFF_DATA_USES_OFFSET
420 new_buf->tail = new_buf->data;
424 skb_put(new_buf, pkt_len);
426 /* Copy the buffer */
427 memcpy(new_buf->data, &(buf->data[chk_idx+4]), check_len);
429 /* Record the buffer pointer */
430 macp->reamin_buf = new_buf;
434 #ifdef ZM_DONT_COPY_RX_BUFFER
435 if (rxBufPoolIndex == 0)
437 new_buf = skb_clone(buf, GFP_ATOMIC);
439 new_buf->data = &(buf->data[chk_idx+4]);
440 new_buf->len = pkt_len;
445 /* Allocate a skb buffer */
446 new_buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
448 /* Set skb buffer length */
449 #ifdef NET_SKBUFF_DATA_USES_OFFSET
453 new_buf->tail = new_buf->data;
457 skb_put(new_buf, pkt_len);
459 /* Copy the buffer */
460 memcpy(new_buf->data, &(buf->data[chk_idx+4]), pkt_len);
462 #ifdef ZM_DONT_COPY_RX_BUFFER
465 rxBufPool[rxBufPoolIndex++] = new_buf;
470 printk(KERN_ERR "Can't find tag, pkt_len: 0x%04x, tag: 0x%04x\n", pkt_len, pkt_tag);
473 dev_kfree_skb_any(buf);
475 /* Allocate a skb buffer */
476 new_buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
478 /* Enqueue skb buffer */
479 zfLnxPutUsbRxBuffer(dev, new_buf);
481 /* Submit a Rx urb */
482 zfLnxUsbIn(dev, urb, new_buf);
489 dev_kfree_skb_any(buf);
492 /* Allocate a skb buffer */
493 new_buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
495 /* Enqueue skb buffer */
496 zfLnxPutUsbRxBuffer(dev, new_buf);
498 /* Submit a Rx urb */
499 zfLnxUsbIn(dev, urb, new_buf);
501 #if ZM_USB_STREAM_MODE == 1
502 for(ii = 0; ii < rxBufPoolIndex; ii++)
504 macp->usbCbFunctions.zfcbUsbRecv(dev, rxBufPool[ii]);
507 /* pass data to upper layer */
508 macp->usbCbFunctions.zfcbUsbRecv(dev, buf);
512 void zfLnxUsbRegOut_callback(urb_t *urb)
514 //dev_t* dev = urb->context;
516 //printk(KERN_ERR "zfwUsbRegOut_callback\n");
519 void zfLnxUsbRegIn_callback(urb_t *urb)
521 zdev_t* dev = urb->context;
524 struct usbdrv_private *macp = dev->ml_priv;
526 /* Check status for URB */
527 if (urb->status != 0){
528 printk("zfLnxUsbRegIn_callback() : status=0x%x\n", urb->status);
529 if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)
530 && (urb->status != -ESHUTDOWN))
532 if (urb->status == -EPIPE){
533 //printk(KERN_ERR "nonzero read bulk status received: -EPIPE");
537 if (urb->status == -EPROTO){
538 //printk(KERN_ERR "nonzero read bulk status received: -EPROTO");
543 //printk(KERN_ERR "urb->status: 0x%08x\n", urb->status);
547 if (urb->actual_length == 0)
549 printk(KERN_ERR "Get an URB whose length is zero");
553 /* Copy data into respone buffer */
554 memcpy(rsp, macp->regUsbReadBuf, urb->actual_length);
556 /* Notify to upper layer */
557 //zfIdlChkRsp(dev, rsp, (u16_t)urb->actual_length);
558 //zfiUsbRegIn(dev, rsp, (u16_t)urb->actual_length);
559 macp->usbCbFunctions.zfcbUsbRegIn(dev, rsp, (u16_t)urb->actual_length);
561 /* Issue another USB IN URB */
562 zfLnxSubmitRegInUrb(dev);
565 u32_t zfLnxSubmitRegInUrb(zdev_t *dev)
568 struct usbdrv_private *macp = dev->ml_priv;
570 /* Submit a rx urb */
571 //ret = zfLnxUsbSubmitBulkUrb(macp->RegInUrb, macp->udev,
572 // USB_REG_IN_PIPE, USB_DIR_IN, macp->regUsbReadBuf,
573 // ZM_USB_REG_MAX_BUF_SIZE, zfLnxUsbRegIn_callback, dev);
576 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
578 ret = zfLnxUsbSubmitIntUrb(macp->RegInUrb, macp->udev,
579 USB_REG_IN_PIPE, USB_DIR_IN, macp->regUsbReadBuf,
580 ZM_USB_REG_MAX_BUF_SIZE, zfLnxUsbRegIn_callback, dev, 1);
585 u32_t zfLnxUsbSubmitTxData(zdev_t* dev)
590 u8_t *puTxBuf = NULL;
593 struct usbdrv_private *macp = dev->ml_priv;
594 #if ZM_USB_TX_STREAM_MODE == 1
599 UsbTxQ_t *TxQPool[ZM_MAX_TX_AGGREGATE_NUM];
602 /* First check whether there is a free URB */
603 freeTxUrb = zfLnxGetFreeTxUrb(dev);
605 /* If there is no any free Tx Urb */
606 if (freeTxUrb == 0xffff)
608 //printk(KERN_ERR "Can't get free Tx Urb\n");
609 //printk("CWY - Can't get free Tx Urb\n");
613 #if ZM_USB_TX_STREAM_MODE == 1
614 usbTxAggCnt = zfLnxCheckTxBufferCnt(dev);
616 if (usbTxAggCnt >= ZM_MAX_TX_AGGREGATE_NUM)
618 usbTxAggCnt = ZM_MAX_TX_AGGREGATE_NUM;
625 //printk("usbTxAggCnt: %d\n", usbTxAggCnt);
628 #if ZM_USB_TX_STREAM_MODE == 1
629 for(ii = 0; ii < usbTxAggCnt; ii++)
632 /* Dequeue the packet from UsbTxBufQ */
633 TxData = zfLnxGetUsbTxBuffer(dev);
636 /* Give the urb back */
641 /* Point to the freeTxUrb buffer */
642 puTxBuf = macp->txUsbBuf[freeTxUrb];
644 #if ZM_USB_TX_STREAM_MODE == 1
646 pUsbTxHdr = (u16_t *)puTxBuf;
648 /* Add the packet length and tag information */
649 *pUsbTxHdr++ = TxData->hdrlen + TxData->snapLen +
650 (TxData->buf->len - TxData->offset) + TxData->tailLen;
652 *pUsbTxHdr++ = 0x697e;
655 #endif // #ifdef ZM_USB_TX_STREAM_MODE
657 /* Copy WLAN header and packet buffer into USB buffer */
658 for(i = 0; i < TxData->hdrlen; i++)
660 *puTxBuf++ = TxData->hdr[i];
663 /* Copy SNAP header */
664 for(i = 0; i < TxData->snapLen; i++)
666 *puTxBuf++ = TxData->snap[i];
669 /* Copy packet buffer */
670 for(i = 0; i < TxData->buf->len - TxData->offset; i++)
672 //*puTxBuf++ = zmw_rx_buf_readb(dev, TxData->buf, i);
673 *puTxBuf++ = *(u8_t*)((u8_t*)TxData->buf->data+i+TxData->offset);
677 for(i = 0; i < TxData->tailLen; i++)
679 *puTxBuf++ = TxData->tail[i];
682 len = TxData->hdrlen+TxData->snapLen+TxData->buf->len+TxData->tailLen-TxData->offset;
685 if (TxData->hdrlen != 0)
687 puTxBuf = macp->txUsbBuf[freeTxUrb];
688 for (i = 0; i < len; i++)
690 printk("%02x ", puTxBuf[i]);
698 /* For debug purpose */
699 if(TxData->hdr[9] & 0x40)
702 u16_t ctrlLen = TxData->hdr[0] + (TxData->hdr[1] << 8);
704 if (ctrlLen != len + 4)
706 /* Dump control setting */
707 for(i = 0; i < 8; i++)
709 printk(KERN_ERR "0x%02x ", TxData->hdr[i]);
711 printk(KERN_ERR "\n");
713 printk(KERN_ERR "ctrLen: %d, hdrLen: %d, snapLen: %d\n", ctrlLen, TxData->hdrlen, TxData->snapLen);
714 printk(KERN_ERR "bufLen: %d, tailLen: %d, len: %d\n", TxData->buf->len, TxData->tailLen, len);
719 #if ZM_USB_TX_STREAM_MODE == 1
720 // Add the Length and Tag
723 //printk("%d packet, length: %d\n", ii+1, len);
725 if (ii < (ZM_MAX_TX_AGGREGATE_NUM-1))
727 /* Pad the buffer to firmware descriptor boundary */
728 offset += (((len-1) / 4) + 1) * 4;
731 if (ii == (ZM_MAX_TX_AGGREGATE_NUM-1))
736 TxQPool[ii] = TxData;
738 //DbgPrint("%d packet, offset: %d\n", ii+1, pUsbTxTransfer->offset);
741 //zfBufFree(dev, txData->buf);
744 //printk("CWY - call zfwUsbSubmitBulkUrb(), len = 0x%d\n", len);
745 /* Submit a tx urb */
746 ret = zfLnxUsbSubmitBulkUrb(macp->WlanTxDataUrb[freeTxUrb], macp->udev,
747 USB_WLAN_TX_PIPE, USB_DIR_OUT, macp->txUsbBuf[freeTxUrb],
748 len, zfLnxUsbDataOut_callback, dev);
751 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
754 //dev_kfree_skb_any(TxData->buf);
755 #if ZM_USB_TX_STREAM_MODE == 1
756 for(ii = 0; ii < usbTxAggCnt; ii++)
757 macp->usbCbFunctions.zfcbUsbOutComplete(dev, TxQPool[ii]->buf, 1, TxQPool[ii]->hdr);
759 macp->usbCbFunctions.zfcbUsbOutComplete(dev, TxData->buf, 1, TxData->hdr);
767 u32_t zfLnxUsbIn(zdev_t* dev, urb_t *urb, zbuf_t *buf)
770 struct usbdrv_private *macp = dev->ml_priv;
772 /* Submit a rx urb */
773 ret = zfLnxUsbSubmitBulkUrb(urb, macp->udev, USB_WLAN_RX_PIPE,
774 USB_DIR_IN, buf->data, ZM_MAX_RX_BUFFER_SIZE,
775 zfLnxUsbDataIn_callback, dev);
778 // printk("zfwUsbSubmitBulkUrb fail, status: 0x%08x\n", (int)ret);
783 u32_t zfLnxUsbWriteReg(zdev_t* dev, u32_t* cmd, u16_t cmdLen)
785 struct usbdrv_private *macp = dev->ml_priv;
788 #ifdef ZM_CONFIG_BIG_ENDIAN
791 for(ii=0; ii<(cmdLen>>2); ii++)
792 cmd[ii] = cpu_to_le32(cmd[ii]);
795 memcpy(macp->regUsbWriteBuf, cmd, cmdLen);
797 /* Issue an USB Out transfer */
798 /* Submit a tx urb */
799 ret = zfLnxUsbSubmitIntUrb(macp->RegOutUrb, macp->udev,
800 USB_REG_OUT_PIPE, USB_DIR_OUT, macp->regUsbWriteBuf,
801 cmdLen, zfLnxUsbRegOut_callback, dev, 1);
807 u32_t zfLnxUsbOut(zdev_t* dev, u8_t *hdr, u16_t hdrlen, u8_t *snap, u16_t snapLen,
808 u8_t *tail, u16_t tailLen, zbuf_t *buf, u16_t offset)
811 struct usbdrv_private *macp = dev->ml_priv;
813 /* Check length of tail buffer */
814 //zm_assert((tailLen <= 16));
816 /* Enqueue the packet into UsbTxBufQ */
817 if (zfLnxPutUsbTxBuffer(dev, hdr, hdrlen, snap, snapLen, tail, tailLen, buf, offset) == 0xffff)
820 //printk("CWY - zfwPutUsbTxBuffer Error, free packet\n");
821 //dev_kfree_skb_any(buf);
822 macp->usbCbFunctions.zfcbUsbOutComplete(dev, buf, 0, hdr);
827 //printk("CWY - call zfwUsbSubmitTxData()\n");
828 ret = zfLnxUsbSubmitTxData(dev);
832 void zfLnxInitUsbTxQ(zdev_t* dev)
834 struct usbdrv_private *macp = dev->ml_priv;
836 printk(KERN_ERR "zfwInitUsbTxQ\n");
838 /* Zero memory for UsbTxBufQ */
839 memset(macp->UsbTxBufQ, 0, sizeof(UsbTxQ_t) * ZM_MAX_TX_URB_NUM);
845 macp->TxUrbCnt = ZM_MAX_TX_URB_NUM;
848 void zfLnxInitUsbRxQ(zdev_t* dev)
852 struct usbdrv_private *macp = dev->ml_priv;
854 /* Zero memory for UsbRxBufQ */
855 memset(macp->UsbRxBufQ, 0, sizeof(zbuf_t *) * ZM_MAX_RX_URB_NUM);
859 for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
861 //buf = zfwBufAllocate(dev, ZM_MAX_RX_BUFFER_SIZE);
862 buf = dev_alloc_skb(ZM_MAX_RX_BUFFER_SIZE);
863 macp->UsbRxBufQ[i] = buf;
866 //macp->RxBufTail = ZM_MAX_RX_URB_NUM - 1;
869 /* Submit all Rx urbs */
870 for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
872 zfLnxPutUsbRxBuffer(dev, macp->UsbRxBufQ[i]);
873 zfLnxUsbIn(dev, macp->WlanRxDataUrb[i], macp->UsbRxBufQ[i]);
879 u32_t zfLnxUsbSubmitBulkUrb(urb_t *urb, struct usb_device *usb, u16_t epnum, u16_t direction,
880 void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context)
884 if(direction == USB_DIR_OUT)
886 usb_fill_bulk_urb(urb, usb, usb_sndbulkpipe(usb, epnum),
887 transfer_buffer, buffer_length, complete, context);
889 urb->transfer_flags |= URB_ZERO_PACKET;
893 usb_fill_bulk_urb(urb, usb, usb_rcvbulkpipe(usb, epnum),
894 transfer_buffer, buffer_length, complete, context);
901 //printk("CWY - urb->hcpriv set by unknown reason, reset it\n");
906 ret = usb_submit_urb(urb, GFP_ATOMIC);
907 if ((epnum == 4) & (ret != 0))
909 //printk("CWY - ret = %x\n", ret);
914 u32_t zfLnxUsbSubmitIntUrb(urb_t *urb, struct usb_device *usb, u16_t epnum, u16_t direction,
915 void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context,
920 if(direction == USB_DIR_OUT)
922 usb_fill_int_urb(urb, usb, usb_sndbulkpipe(usb, epnum),
923 transfer_buffer, buffer_length, complete, context, interval);
927 usb_fill_int_urb(urb, usb, usb_rcvbulkpipe(usb, epnum),
928 transfer_buffer, buffer_length, complete, context, interval);
931 ret = usb_submit_urb(urb, GFP_ATOMIC);
936 #ifdef ZM_ENABLE_CENC
937 int zfLnxCencSendMsg(struct sock *netlink_sk, u_int8_t *msg, int len)
939 #define COMMTYPE_GROUP 8
940 #define WAI_K_MSG 0x11
944 unsigned char *old_tail;
946 struct nlmsghdr *nlh;
949 size = NLMSG_SPACE(len);
950 skb = alloc_skb(size, GFP_ATOMIC);
954 printk("dev_alloc_skb failure \n");
957 old_tail = skb->tail;
959 /*ÌîдÊý¾Ý±¨Ïà¹ØÐÅÏ¢*/
960 nlh = NLMSG_PUT(skb, 0, 0, WAI_K_MSG, size-sizeof(*nlh));
961 pos = NLMSG_DATA(nlh);
964 /*´«Êäµ½Óû§¿Õ¼äµÄÊý¾Ý*/
965 memcpy(pos, msg, len);
966 /*¼ÆËã¾¹ý×Ö½Ú¶ÔÆäºóµÄÊý¾Ýʵ¼Ê³¤¶È*/
967 nlh->nlmsg_len = skb->tail - old_tail;
968 NETLINK_CB(skb).dst_group = COMMTYPE_GROUP;
969 netlink_broadcast(netlink_sk, skb, 0, COMMTYPE_GROUP, GFP_ATOMIC);
973 nlmsg_failure: /*NLMSG_PUT ʧ°Ü£¬Ôò³·ÏúÌ×½Ó×Ö»º´æ*/
978 #undef COMMTYPE_GROUP
981 #endif //ZM_ENABLE_CENC
983 /* Simply return 0xffff if VAP function is not supported */
984 u16_t zfLnxGetVapId(zdev_t* dev)
988 for (i=0; i<ZM_VAP_PORT_NUMBER; i++)
990 if (vap[i].dev == dev)
998 u32_t zfwReadReg(zdev_t* dev, u32_t offset)
1004 #define work_struct tq_struct
1006 #define schedule_work(a) schedule_task(a)
1008 #define flush_scheduled_work flush_scheduled_tasks
1009 #define INIT_WORK(_wq, _routine, _data) INIT_TQUEUE(_wq, _routine, _data)
1010 #define PREPARE_WORK(_wq, _routine, _data) PREPARE_TQUEUE(_wq, _routine, _data)
1013 #define KEVENT_WATCHDOG 0x00000001
1015 u32_t smp_kevent_Lock = 0;
1017 void kevent(struct work_struct *work)
1019 struct usbdrv_private *macp =
1020 container_of(work, struct usbdrv_private, kevent);
1021 zdev_t *dev = macp->device;
1028 if (test_and_set_bit(0, (void *)&smp_kevent_Lock))
1030 //schedule_work(&macp->kevent);
1034 down(&macp->ioctl_sem);
1036 if (test_and_clear_bit(KEVENT_WATCHDOG, &macp->kevent_flags))
1038 extern u16_t zfHpStartRecv(zdev_t *dev);
1039 //zfiHwWatchDogReinit(dev);
1040 printk(("\n ************ Hw watchDog occur!! ************** \n"));
1041 zfiWlanSuspend(dev);
1042 zfiWlanResume(dev,0);
1046 clear_bit(0, (void *)&smp_kevent_Lock);
1047 up(&macp->ioctl_sem);
1050 /************************************************************************/
1052 /* FUNCTION DESCRIPTION zfLnxCreateThread */
1053 /* Create a Thread */
1056 /* dev : device pointer */
1062 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1064 /************************************************************************/
1065 u8_t zfLnxCreateThread(zdev_t *dev)
1067 struct usbdrv_private *macp = dev->ml_priv;
1069 /* Create Mutex and keventd */
1070 INIT_WORK(&macp->kevent, kevent);
1071 init_MUTEX(&macp->ioctl_sem);
1076 /************************************************************************/
1078 /* FUNCTION DESCRIPTION zfLnxSignalThread */
1079 /* Signal Thread with Flag */
1082 /* dev : device pointer */
1083 /* flag : signal thread flag */
1089 /* Yuan-Gu Wei Atheros Communications, INC. 2007.3 */
1091 /************************************************************************/
1092 void zfLnxSignalThread(zdev_t *dev, int flag)
1094 struct usbdrv_private *macp = dev->ml_priv;
1098 printk("macp is NULL\n");
1102 if (0 && macp->kevent_ready != 1)
1104 printk("Kevent not ready\n");
1108 set_bit(flag, &macp->kevent_flags);
1110 if (!schedule_work(&macp->kevent))
1113 //printk(KERN_ERR "schedule_task failed, flag = %x\n", flag);
1117 /* Notify wrapper todo redownload firmware and reinit procedure when */
1118 /* hardware watchdog occur : zfiHwWatchDogReinit() */
1119 void zfLnxWatchDogNotify(zdev_t* dev)
1121 zfLnxSignalThread(dev, KEVENT_WATCHDOG);
1124 /* Query Durantion of Active Scan */
1125 void zfwGetActiveScanDur(zdev_t* dev, u8_t* Dur)
1127 *Dur = 30; // default 30 ms
1130 void zfwGetShowZeroLengthSSID(zdev_t* dev, u8_t* Dur)