summaryrefslogtreecommitdiff
path: root/drivers/staging/otus/wrap_usb.c
blob: 6b336ede8867eaf989986eb869cb5b83de8ed19b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * Copyright (c) 2007-2008 Atheros Communications Inc.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
/*                                                                      */
/*  Module Name : wrap_usb.c                                            */
/*                                                                      */
/*  Abstract                                                            */
/*     This module contains wrapper functions for USB management        */
/*                                                                      */
/*  NOTES                                                               */
/*     Platform dependent.                                              */
/*                                                                      */
/************************************************************************/

#include "oal_dt.h"
#include "usbdrv.h"

#include <linux/netlink.h>
#include <net/iw_handler.h>

extern void zfLnxInitUsbTxQ(zdev_t *dev);
extern void zfLnxInitUsbRxQ(zdev_t *dev);
extern u32_t zfLnxSubmitRegInUrb(zdev_t *dev);
u32_t zfLnxUsbOut(zdev_t *dev, u8_t *hdr, u16_t hdrlen, u8_t *snap,
		u16_t snapLen, u8_t *tail, u16_t tailLen, zbuf_t *buf,
		u16_t offset);
u32_t zfLnxUsbWriteReg(zdev_t *dev, u32_t *cmd, u16_t cmdLen);

void zfwUsbRegisterCallBack(zdev_t *dev, struct zfCbUsbFuncTbl *zfUsbFunc)
{
	struct usbdrv_private *macp = dev->ml_priv;

	macp->usbCbFunctions.zfcbUsbRecv = zfUsbFunc->zfcbUsbRecv;
	macp->usbCbFunctions.zfcbUsbRegIn = zfUsbFunc->zfcbUsbRegIn;
	macp->usbCbFunctions.zfcbUsbOutComplete = zfUsbFunc->zfcbUsbOutComplete;

	return;
}

u32_t zfwUsbGetFreeTxQSize(zdev_t *dev)
{
	struct usbdrv_private *macp = dev->ml_priv;
	u32_t		freeTxQSize;
	unsigned long irqFlag;
	/* zmw_declare_for_critical_section();	*/

	/* zmw_enter_critical_section(dev);	*/
	spin_lock_irqsave(&macp->cs_lock, irqFlag);

	freeTxQSize = ZM_MAX_TX_BUF_NUM - macp->TxBufCnt;

	/* zmw_leave_critical_section(dev);	*/
	spin_unlock_irqrestore(&macp->cs_lock, irqFlag);

	return freeTxQSize;
}

u32_t zfwUsbGetMaxTxQSize(zdev_t *dev)
{
	return ZM_MAX_TX_BUF_NUM;
}

u32_t zfwUsbEnableIntEpt(zdev_t *dev, u8_t endpt)
{
	/* Initialize USB TxQ */
	zfLnxInitUsbTxQ(dev);

	/* Initialize USB RxQ */
	zfLnxInitUsbRxQ(dev);

	/* Initialize USB Register In URB */
	/* zfwUsbSubmitRegIn(dev);	*/
	/* Initialize USB Register In URB */
	zfLnxSubmitRegInUrb(dev);

	return 0;
}

int zfwUsbEnableRxEpt(zdev_t *dev, u8_t endpt)
{
	return 0;
}

u32_t zfwUsbSubmitControl(zdev_t *dev, u8_t req, u16_t value, u16_t index,
			 void *data, u32_t size)
{
	int result = 0;
	u32_t ret = 0;
	struct usbdrv_private *macp = dev->ml_priv;
	u8_t *buf;

	if (size > 0) {
		buf = kmalloc(size, GFP_KERNEL);
		memcpy(buf, (u8_t *)data, size);
	} else
		buf = NULL;

#if 0
	printk(KERN_ERR "req = 0x%02x\n", req);
	printk(KERN_ERR "value = 0x%04x\n", value);
	printk(KERN_ERR "index = 0x%04x\n", index);
	printk(KERN_ERR "data = 0x%lx\n", (u32_t) data);
	printk(KERN_ERR "size = %ld\n", size);
#endif

	result = usb_control_msg(macp->udev, usb_sndctrlpipe(macp->udev, 0),
			req, USB_DIR_OUT | 0x40, value, index, buf, size, HZ);

	if (result < 0) {
		printk(KERN_ERR "zfwUsbSubmitControl() failed, result = 0x%x\n",
			result);
		ret = 1;
	}
	kfree(buf);

	return ret;
}

void zfwUsbCmd(zdev_t *dev, u8_t endpt, u32_t *cmd, u16_t cmdLen)
{
	struct usbdrv_private *macp = dev->ml_priv;
	u32_t ret;

	/* MPUsbCommand(dev, endpt, cmd, cmdLen);	*/
	ret = zfLnxUsbWriteReg(dev, cmd, cmdLen);

	/*
	 * if zfLnxUsbWriteReg() return error, free and allocate urb,
	 * resend again
	 */
	if (ret != 0) {
		usb_free_urb(macp->RegOutUrb);
		macp->RegOutUrb = usb_alloc_urb(0, GFP_ATOMIC);
		ret = zfLnxUsbWriteReg(dev, cmd, cmdLen);
	}
}

u32_t zfwUsbSend(zdev_t *dev, u8_t endpt, u8_t *hdr, u16_t hdrlen, u8_t *snap,
			u16_t snapLen,	u8_t *tail, u16_t tailLen,
			zbuf_t *buf, u16_t offset)
{
	u32_t status;

#ifdef ZM_CONFIG_BIG_ENDIAN
	u32_t ii = 0;
	u16_t *pc = NULL;

	pc = (u16_t *)hdr;
	for (ii = 0; ii < (hdrlen >> 1); ii++)
		pc[ii] = cpu_to_le16(pc[ii]);

	pc = (u16_t *)snap;
	for (ii = 0; ii < (snapLen >> 1); ii++)
		pc[ii] = cpu_to_le16(pc[ii]);

	pc = (u16_t *)tail;
	for (ii = 0; ii < (tailLen>>1); ii++)
		pc[ii] = cpu_to_le16(pc[ii]);
#endif

	status = zfLnxUsbOut(dev, hdr, hdrlen, snap, snapLen, tail, tailLen,
				buf, offset);
	if (status == 0)
		return 0;
	else
		return 1;
}

/* Leave an empty line below to remove warning message on some compiler */