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.
17 /* Module Name : wrap_usb.c */
20 /* This module contains wrapper functions for USB management */
23 /* Platform dependent. */
25 /************************************************************************/
30 #include <linux/netlink.h>
31 #include <linux/slab.h>
32 #include <net/iw_handler.h>
34 extern void zfLnxInitUsbTxQ(zdev_t *dev);
35 extern void zfLnxInitUsbRxQ(zdev_t *dev);
36 extern u32_t zfLnxSubmitRegInUrb(zdev_t *dev);
37 u32_t zfLnxUsbOut(zdev_t *dev, u8_t *hdr, u16_t hdrlen, u8_t *snap,
38 u16_t snapLen, u8_t *tail, u16_t tailLen, zbuf_t *buf,
40 u32_t zfLnxUsbWriteReg(zdev_t *dev, u32_t *cmd, u16_t cmdLen);
42 void zfwUsbRegisterCallBack(zdev_t *dev, struct zfCbUsbFuncTbl *zfUsbFunc)
44 struct usbdrv_private *macp = dev->ml_priv;
46 macp->usbCbFunctions.zfcbUsbRecv = zfUsbFunc->zfcbUsbRecv;
47 macp->usbCbFunctions.zfcbUsbRegIn = zfUsbFunc->zfcbUsbRegIn;
48 macp->usbCbFunctions.zfcbUsbOutComplete = zfUsbFunc->zfcbUsbOutComplete;
53 u32_t zfwUsbGetFreeTxQSize(zdev_t *dev)
55 struct usbdrv_private *macp = dev->ml_priv;
57 unsigned long irqFlag;
58 /* zmw_declare_for_critical_section(); */
60 /* zmw_enter_critical_section(dev); */
61 spin_lock_irqsave(&macp->cs_lock, irqFlag);
63 freeTxQSize = ZM_MAX_TX_BUF_NUM - macp->TxBufCnt;
65 /* zmw_leave_critical_section(dev); */
66 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
71 u32_t zfwUsbGetMaxTxQSize(zdev_t *dev)
73 return ZM_MAX_TX_BUF_NUM;
76 u32_t zfwUsbEnableIntEpt(zdev_t *dev, u8_t endpt)
78 /* Initialize USB TxQ */
81 /* Initialize USB RxQ */
84 /* Initialize USB Register In URB */
85 /* zfwUsbSubmitRegIn(dev); */
86 /* Initialize USB Register In URB */
87 zfLnxSubmitRegInUrb(dev);
92 int zfwUsbEnableRxEpt(zdev_t *dev, u8_t endpt)
97 u32_t zfwUsbSubmitControl(zdev_t *dev, u8_t req, u16_t value, u16_t index,
98 void *data, u32_t size)
102 struct usbdrv_private *macp = dev->ml_priv;
106 buf = kmalloc(size, GFP_KERNEL);
107 memcpy(buf, (u8_t *)data, size);
112 printk(KERN_ERR "req = 0x%02x\n", req);
113 printk(KERN_ERR "value = 0x%04x\n", value);
114 printk(KERN_ERR "index = 0x%04x\n", index);
115 printk(KERN_ERR "data = 0x%lx\n", (u32_t) data);
116 printk(KERN_ERR "size = %ld\n", size);
119 result = usb_control_msg(macp->udev, usb_sndctrlpipe(macp->udev, 0),
120 req, USB_DIR_OUT | 0x40, value, index, buf, size, HZ);
123 printk(KERN_ERR "zfwUsbSubmitControl() failed, result = 0x%x\n",
132 void zfwUsbCmd(zdev_t *dev, u8_t endpt, u32_t *cmd, u16_t cmdLen)
134 struct usbdrv_private *macp = dev->ml_priv;
137 /* MPUsbCommand(dev, endpt, cmd, cmdLen); */
138 ret = zfLnxUsbWriteReg(dev, cmd, cmdLen);
141 * if zfLnxUsbWriteReg() return error, free and allocate urb,
145 usb_free_urb(macp->RegOutUrb);
146 macp->RegOutUrb = usb_alloc_urb(0, GFP_ATOMIC);
147 ret = zfLnxUsbWriteReg(dev, cmd, cmdLen);
151 u32_t zfwUsbSend(zdev_t *dev, u8_t endpt, u8_t *hdr, u16_t hdrlen, u8_t *snap,
152 u16_t snapLen, u8_t *tail, u16_t tailLen,
153 zbuf_t *buf, u16_t offset)
157 #ifdef ZM_CONFIG_BIG_ENDIAN
162 for (ii = 0; ii < (hdrlen >> 1); ii++)
163 pc[ii] = cpu_to_le16(pc[ii]);
166 for (ii = 0; ii < (snapLen >> 1); ii++)
167 pc[ii] = cpu_to_le16(pc[ii]);
170 for (ii = 0; ii < (tailLen>>1); ii++)
171 pc[ii] = cpu_to_le16(pc[ii]);
174 status = zfLnxUsbOut(dev, hdr, hdrlen, snap, snapLen, tail, tailLen,
182 /* Leave an empty line below to remove warning message on some compiler */