xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/marvell/mwifiex/usb.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * NXP Wireless LAN device driver: USB specific handling
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright 2011-2020 NXP
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * This software file (the "File") is distributed by NXP
7*4882a593Smuzhiyun  * under the terms of the GNU General Public License Version 2, June 1991
8*4882a593Smuzhiyun  * (the "License").  You may use, redistribute and/or modify this File in
9*4882a593Smuzhiyun  * accordance with the terms and conditions of the License, a copy of which
10*4882a593Smuzhiyun  * is available by writing to the Free Software Foundation, Inc.,
11*4882a593Smuzhiyun  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12*4882a593Smuzhiyun  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15*4882a593Smuzhiyun  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16*4882a593Smuzhiyun  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
17*4882a593Smuzhiyun  * this warranty disclaimer.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include "main.h"
21*4882a593Smuzhiyun #include "usb.h"
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #define USB_VERSION	"1.0"
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun static struct mwifiex_if_ops usb_ops;
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun static const struct usb_device_id mwifiex_usb_table[] = {
28*4882a593Smuzhiyun 	/* 8766 */
29*4882a593Smuzhiyun 	{USB_DEVICE(USB8XXX_VID, USB8766_PID_1)},
30*4882a593Smuzhiyun 	{USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8766_PID_2,
31*4882a593Smuzhiyun 				       USB_CLASS_VENDOR_SPEC,
32*4882a593Smuzhiyun 				       USB_SUBCLASS_VENDOR_SPEC, 0xff)},
33*4882a593Smuzhiyun 	/* 8797 */
34*4882a593Smuzhiyun 	{USB_DEVICE(USB8XXX_VID, USB8797_PID_1)},
35*4882a593Smuzhiyun 	{USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8797_PID_2,
36*4882a593Smuzhiyun 				       USB_CLASS_VENDOR_SPEC,
37*4882a593Smuzhiyun 				       USB_SUBCLASS_VENDOR_SPEC, 0xff)},
38*4882a593Smuzhiyun 	/* 8801 */
39*4882a593Smuzhiyun 	{USB_DEVICE(USB8XXX_VID, USB8801_PID_1)},
40*4882a593Smuzhiyun 	{USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8801_PID_2,
41*4882a593Smuzhiyun 				       USB_CLASS_VENDOR_SPEC,
42*4882a593Smuzhiyun 				       USB_SUBCLASS_VENDOR_SPEC, 0xff)},
43*4882a593Smuzhiyun 	/* 8997 */
44*4882a593Smuzhiyun 	{USB_DEVICE(USB8XXX_VID, USB8997_PID_1)},
45*4882a593Smuzhiyun 	{USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8997_PID_2,
46*4882a593Smuzhiyun 				       USB_CLASS_VENDOR_SPEC,
47*4882a593Smuzhiyun 				       USB_SUBCLASS_VENDOR_SPEC, 0xff)},
48*4882a593Smuzhiyun 	{ }	/* Terminating entry */
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun MODULE_DEVICE_TABLE(usb, mwifiex_usb_table);
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun static int mwifiex_usb_submit_rx_urb(struct urb_context *ctx, int size);
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /* This function handles received packet. Necessary action is taken based on
56*4882a593Smuzhiyun  * cmd/event/data.
57*4882a593Smuzhiyun  */
mwifiex_usb_recv(struct mwifiex_adapter * adapter,struct sk_buff * skb,u8 ep)58*4882a593Smuzhiyun static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
59*4882a593Smuzhiyun 			    struct sk_buff *skb, u8 ep)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun 	u32 recv_type;
62*4882a593Smuzhiyun 	__le32 tmp;
63*4882a593Smuzhiyun 	int ret;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	if (adapter->hs_activated)
66*4882a593Smuzhiyun 		mwifiex_process_hs_config(adapter);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun 	if (skb->len < INTF_HEADER_LEN) {
69*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
70*4882a593Smuzhiyun 			    "%s: invalid skb->len\n", __func__);
71*4882a593Smuzhiyun 		return -1;
72*4882a593Smuzhiyun 	}
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	switch (ep) {
75*4882a593Smuzhiyun 	case MWIFIEX_USB_EP_CMD_EVENT:
76*4882a593Smuzhiyun 		mwifiex_dbg(adapter, EVENT,
77*4882a593Smuzhiyun 			    "%s: EP_CMD_EVENT\n", __func__);
78*4882a593Smuzhiyun 		skb_copy_from_linear_data(skb, &tmp, INTF_HEADER_LEN);
79*4882a593Smuzhiyun 		recv_type = le32_to_cpu(tmp);
80*4882a593Smuzhiyun 		skb_pull(skb, INTF_HEADER_LEN);
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 		switch (recv_type) {
83*4882a593Smuzhiyun 		case MWIFIEX_USB_TYPE_CMD:
84*4882a593Smuzhiyun 			if (skb->len > MWIFIEX_SIZE_OF_CMD_BUFFER) {
85*4882a593Smuzhiyun 				mwifiex_dbg(adapter, ERROR,
86*4882a593Smuzhiyun 					    "CMD: skb->len too large\n");
87*4882a593Smuzhiyun 				ret = -1;
88*4882a593Smuzhiyun 				goto exit_restore_skb;
89*4882a593Smuzhiyun 			} else if (!adapter->curr_cmd) {
90*4882a593Smuzhiyun 				mwifiex_dbg(adapter, WARN, "CMD: no curr_cmd\n");
91*4882a593Smuzhiyun 				if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
92*4882a593Smuzhiyun 					mwifiex_process_sleep_confirm_resp(
93*4882a593Smuzhiyun 							adapter, skb->data,
94*4882a593Smuzhiyun 							skb->len);
95*4882a593Smuzhiyun 					ret = 0;
96*4882a593Smuzhiyun 					goto exit_restore_skb;
97*4882a593Smuzhiyun 				}
98*4882a593Smuzhiyun 				ret = -1;
99*4882a593Smuzhiyun 				goto exit_restore_skb;
100*4882a593Smuzhiyun 			}
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 			adapter->curr_cmd->resp_skb = skb;
103*4882a593Smuzhiyun 			adapter->cmd_resp_received = true;
104*4882a593Smuzhiyun 			break;
105*4882a593Smuzhiyun 		case MWIFIEX_USB_TYPE_EVENT:
106*4882a593Smuzhiyun 			if (skb->len < sizeof(u32)) {
107*4882a593Smuzhiyun 				mwifiex_dbg(adapter, ERROR,
108*4882a593Smuzhiyun 					    "EVENT: skb->len too small\n");
109*4882a593Smuzhiyun 				ret = -1;
110*4882a593Smuzhiyun 				goto exit_restore_skb;
111*4882a593Smuzhiyun 			}
112*4882a593Smuzhiyun 			skb_copy_from_linear_data(skb, &tmp, sizeof(u32));
113*4882a593Smuzhiyun 			adapter->event_cause = le32_to_cpu(tmp);
114*4882a593Smuzhiyun 			mwifiex_dbg(adapter, EVENT,
115*4882a593Smuzhiyun 				    "event_cause %#x\n", adapter->event_cause);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun 			if (skb->len > MAX_EVENT_SIZE) {
118*4882a593Smuzhiyun 				mwifiex_dbg(adapter, ERROR,
119*4882a593Smuzhiyun 					    "EVENT: event body too large\n");
120*4882a593Smuzhiyun 				ret = -1;
121*4882a593Smuzhiyun 				goto exit_restore_skb;
122*4882a593Smuzhiyun 			}
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 			memcpy(adapter->event_body, skb->data +
125*4882a593Smuzhiyun 			       MWIFIEX_EVENT_HEADER_LEN, skb->len);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 			adapter->event_received = true;
128*4882a593Smuzhiyun 			adapter->event_skb = skb;
129*4882a593Smuzhiyun 			break;
130*4882a593Smuzhiyun 		default:
131*4882a593Smuzhiyun 			mwifiex_dbg(adapter, ERROR,
132*4882a593Smuzhiyun 				    "unknown recv_type %#x\n", recv_type);
133*4882a593Smuzhiyun 			ret = -1;
134*4882a593Smuzhiyun 			goto exit_restore_skb;
135*4882a593Smuzhiyun 		}
136*4882a593Smuzhiyun 		break;
137*4882a593Smuzhiyun 	case MWIFIEX_USB_EP_DATA:
138*4882a593Smuzhiyun 		mwifiex_dbg(adapter, DATA, "%s: EP_DATA\n", __func__);
139*4882a593Smuzhiyun 		if (skb->len > MWIFIEX_RX_DATA_BUF_SIZE) {
140*4882a593Smuzhiyun 			mwifiex_dbg(adapter, ERROR,
141*4882a593Smuzhiyun 				    "DATA: skb->len too large\n");
142*4882a593Smuzhiyun 			return -1;
143*4882a593Smuzhiyun 		}
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 		skb_queue_tail(&adapter->rx_data_q, skb);
146*4882a593Smuzhiyun 		adapter->data_received = true;
147*4882a593Smuzhiyun 		atomic_inc(&adapter->rx_pending);
148*4882a593Smuzhiyun 		break;
149*4882a593Smuzhiyun 	default:
150*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
151*4882a593Smuzhiyun 			    "%s: unknown endport %#x\n", __func__, ep);
152*4882a593Smuzhiyun 		return -1;
153*4882a593Smuzhiyun 	}
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	return -EINPROGRESS;
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun exit_restore_skb:
158*4882a593Smuzhiyun 	/* The buffer will be reused for further cmds/events */
159*4882a593Smuzhiyun 	skb_push(skb, INTF_HEADER_LEN);
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	return ret;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun 
mwifiex_usb_rx_complete(struct urb * urb)164*4882a593Smuzhiyun static void mwifiex_usb_rx_complete(struct urb *urb)
165*4882a593Smuzhiyun {
166*4882a593Smuzhiyun 	struct urb_context *context = (struct urb_context *)urb->context;
167*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter = context->adapter;
168*4882a593Smuzhiyun 	struct sk_buff *skb = context->skb;
169*4882a593Smuzhiyun 	struct usb_card_rec *card;
170*4882a593Smuzhiyun 	int recv_length = urb->actual_length;
171*4882a593Smuzhiyun 	int size, status;
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	if (!adapter || !adapter->card) {
174*4882a593Smuzhiyun 		pr_err("mwifiex adapter or card structure is not valid\n");
175*4882a593Smuzhiyun 		return;
176*4882a593Smuzhiyun 	}
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	card = (struct usb_card_rec *)adapter->card;
179*4882a593Smuzhiyun 	if (card->rx_cmd_ep == context->ep)
180*4882a593Smuzhiyun 		atomic_dec(&card->rx_cmd_urb_pending);
181*4882a593Smuzhiyun 	else
182*4882a593Smuzhiyun 		atomic_dec(&card->rx_data_urb_pending);
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun 	if (recv_length) {
185*4882a593Smuzhiyun 		if (urb->status ||
186*4882a593Smuzhiyun 		    test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags)) {
187*4882a593Smuzhiyun 			mwifiex_dbg(adapter, ERROR,
188*4882a593Smuzhiyun 				    "URB status is failed: %d\n", urb->status);
189*4882a593Smuzhiyun 			/* Do not free skb in case of command ep */
190*4882a593Smuzhiyun 			if (card->rx_cmd_ep != context->ep)
191*4882a593Smuzhiyun 				dev_kfree_skb_any(skb);
192*4882a593Smuzhiyun 			goto setup_for_next;
193*4882a593Smuzhiyun 		}
194*4882a593Smuzhiyun 		if (skb->len > recv_length)
195*4882a593Smuzhiyun 			skb_trim(skb, recv_length);
196*4882a593Smuzhiyun 		else
197*4882a593Smuzhiyun 			skb_put(skb, recv_length - skb->len);
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 		status = mwifiex_usb_recv(adapter, skb, context->ep);
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun 		mwifiex_dbg(adapter, INFO,
202*4882a593Smuzhiyun 			    "info: recv_length=%d, status=%d\n",
203*4882a593Smuzhiyun 			    recv_length, status);
204*4882a593Smuzhiyun 		if (status == -EINPROGRESS) {
205*4882a593Smuzhiyun 			mwifiex_queue_main_work(adapter);
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 			/* urb for data_ep is re-submitted now;
208*4882a593Smuzhiyun 			 * urb for cmd_ep will be re-submitted in callback
209*4882a593Smuzhiyun 			 * mwifiex_usb_recv_complete
210*4882a593Smuzhiyun 			 */
211*4882a593Smuzhiyun 			if (card->rx_cmd_ep == context->ep)
212*4882a593Smuzhiyun 				return;
213*4882a593Smuzhiyun 		} else {
214*4882a593Smuzhiyun 			if (status == -1)
215*4882a593Smuzhiyun 				mwifiex_dbg(adapter, ERROR,
216*4882a593Smuzhiyun 					    "received data processing failed!\n");
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun 			/* Do not free skb in case of command ep */
219*4882a593Smuzhiyun 			if (card->rx_cmd_ep != context->ep)
220*4882a593Smuzhiyun 				dev_kfree_skb_any(skb);
221*4882a593Smuzhiyun 		}
222*4882a593Smuzhiyun 	} else if (urb->status) {
223*4882a593Smuzhiyun 		if (!test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
224*4882a593Smuzhiyun 			mwifiex_dbg(adapter, FATAL,
225*4882a593Smuzhiyun 				    "Card is removed: %d\n", urb->status);
226*4882a593Smuzhiyun 			set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
227*4882a593Smuzhiyun 		}
228*4882a593Smuzhiyun 		dev_kfree_skb_any(skb);
229*4882a593Smuzhiyun 		return;
230*4882a593Smuzhiyun 	} else {
231*4882a593Smuzhiyun 		/* Do not free skb in case of command ep */
232*4882a593Smuzhiyun 		if (card->rx_cmd_ep != context->ep)
233*4882a593Smuzhiyun 			dev_kfree_skb_any(skb);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 		/* fall through setup_for_next */
236*4882a593Smuzhiyun 	}
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun setup_for_next:
239*4882a593Smuzhiyun 	if (card->rx_cmd_ep == context->ep)
240*4882a593Smuzhiyun 		size = MWIFIEX_RX_CMD_BUF_SIZE;
241*4882a593Smuzhiyun 	else
242*4882a593Smuzhiyun 		size = MWIFIEX_RX_DATA_BUF_SIZE;
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun 	if (card->rx_cmd_ep == context->ep) {
245*4882a593Smuzhiyun 		mwifiex_usb_submit_rx_urb(context, size);
246*4882a593Smuzhiyun 	} else {
247*4882a593Smuzhiyun 		if (atomic_read(&adapter->rx_pending) <= HIGH_RX_PENDING) {
248*4882a593Smuzhiyun 			mwifiex_usb_submit_rx_urb(context, size);
249*4882a593Smuzhiyun 		} else {
250*4882a593Smuzhiyun 			context->skb = NULL;
251*4882a593Smuzhiyun 		}
252*4882a593Smuzhiyun 	}
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 	return;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun 
mwifiex_usb_tx_complete(struct urb * urb)257*4882a593Smuzhiyun static void mwifiex_usb_tx_complete(struct urb *urb)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun 	struct urb_context *context = (struct urb_context *)(urb->context);
260*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter = context->adapter;
261*4882a593Smuzhiyun 	struct usb_card_rec *card = adapter->card;
262*4882a593Smuzhiyun 	struct usb_tx_data_port *port;
263*4882a593Smuzhiyun 	int i;
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 	mwifiex_dbg(adapter, INFO,
266*4882a593Smuzhiyun 		    "%s: status: %d\n", __func__, urb->status);
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 	if (context->ep == card->tx_cmd_ep) {
269*4882a593Smuzhiyun 		mwifiex_dbg(adapter, CMD,
270*4882a593Smuzhiyun 			    "%s: CMD\n", __func__);
271*4882a593Smuzhiyun 		atomic_dec(&card->tx_cmd_urb_pending);
272*4882a593Smuzhiyun 		adapter->cmd_sent = false;
273*4882a593Smuzhiyun 	} else {
274*4882a593Smuzhiyun 		mwifiex_dbg(adapter, DATA,
275*4882a593Smuzhiyun 			    "%s: DATA\n", __func__);
276*4882a593Smuzhiyun 		mwifiex_write_data_complete(adapter, context->skb, 0,
277*4882a593Smuzhiyun 					    urb->status ? -1 : 0);
278*4882a593Smuzhiyun 		for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
279*4882a593Smuzhiyun 			port = &card->port[i];
280*4882a593Smuzhiyun 			if (context->ep == port->tx_data_ep) {
281*4882a593Smuzhiyun 				atomic_dec(&port->tx_data_urb_pending);
282*4882a593Smuzhiyun 				port->block_status = false;
283*4882a593Smuzhiyun 				break;
284*4882a593Smuzhiyun 			}
285*4882a593Smuzhiyun 		}
286*4882a593Smuzhiyun 		adapter->data_sent = false;
287*4882a593Smuzhiyun 	}
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun 	if (card->mc_resync_flag)
290*4882a593Smuzhiyun 		mwifiex_multi_chan_resync(adapter);
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 	mwifiex_queue_main_work(adapter);
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun 	return;
295*4882a593Smuzhiyun }
296*4882a593Smuzhiyun 
mwifiex_usb_submit_rx_urb(struct urb_context * ctx,int size)297*4882a593Smuzhiyun static int mwifiex_usb_submit_rx_urb(struct urb_context *ctx, int size)
298*4882a593Smuzhiyun {
299*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter = ctx->adapter;
300*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun 	if (test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
303*4882a593Smuzhiyun 		if (card->rx_cmd_ep == ctx->ep) {
304*4882a593Smuzhiyun 			mwifiex_dbg(adapter, INFO, "%s: free rx_cmd skb\n",
305*4882a593Smuzhiyun 				    __func__);
306*4882a593Smuzhiyun 			dev_kfree_skb_any(ctx->skb);
307*4882a593Smuzhiyun 			ctx->skb = NULL;
308*4882a593Smuzhiyun 		}
309*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
310*4882a593Smuzhiyun 			    "%s: card removed/suspended, EP %d rx_cmd URB submit skipped\n",
311*4882a593Smuzhiyun 			    __func__, ctx->ep);
312*4882a593Smuzhiyun 		return -1;
313*4882a593Smuzhiyun 	}
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	if (card->rx_cmd_ep != ctx->ep) {
316*4882a593Smuzhiyun 		ctx->skb = dev_alloc_skb(size);
317*4882a593Smuzhiyun 		if (!ctx->skb) {
318*4882a593Smuzhiyun 			mwifiex_dbg(adapter, ERROR,
319*4882a593Smuzhiyun 				    "%s: dev_alloc_skb failed\n", __func__);
320*4882a593Smuzhiyun 			return -ENOMEM;
321*4882a593Smuzhiyun 		}
322*4882a593Smuzhiyun 	}
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun 	if (card->rx_cmd_ep == ctx->ep &&
325*4882a593Smuzhiyun 	    card->rx_cmd_ep_type == USB_ENDPOINT_XFER_INT)
326*4882a593Smuzhiyun 		usb_fill_int_urb(ctx->urb, card->udev,
327*4882a593Smuzhiyun 				 usb_rcvintpipe(card->udev, ctx->ep),
328*4882a593Smuzhiyun 				 ctx->skb->data, size, mwifiex_usb_rx_complete,
329*4882a593Smuzhiyun 				 (void *)ctx, card->rx_cmd_interval);
330*4882a593Smuzhiyun 	else
331*4882a593Smuzhiyun 		usb_fill_bulk_urb(ctx->urb, card->udev,
332*4882a593Smuzhiyun 				  usb_rcvbulkpipe(card->udev, ctx->ep),
333*4882a593Smuzhiyun 				  ctx->skb->data, size, mwifiex_usb_rx_complete,
334*4882a593Smuzhiyun 				  (void *)ctx);
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	if (card->rx_cmd_ep == ctx->ep)
337*4882a593Smuzhiyun 		atomic_inc(&card->rx_cmd_urb_pending);
338*4882a593Smuzhiyun 	else
339*4882a593Smuzhiyun 		atomic_inc(&card->rx_data_urb_pending);
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun 	if (usb_submit_urb(ctx->urb, GFP_ATOMIC)) {
342*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR, "usb_submit_urb failed\n");
343*4882a593Smuzhiyun 		dev_kfree_skb_any(ctx->skb);
344*4882a593Smuzhiyun 		ctx->skb = NULL;
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun 		if (card->rx_cmd_ep == ctx->ep)
347*4882a593Smuzhiyun 			atomic_dec(&card->rx_cmd_urb_pending);
348*4882a593Smuzhiyun 		else
349*4882a593Smuzhiyun 			atomic_dec(&card->rx_data_urb_pending);
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 		return -1;
352*4882a593Smuzhiyun 	}
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun 	return 0;
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun 
mwifiex_usb_free(struct usb_card_rec * card)357*4882a593Smuzhiyun static void mwifiex_usb_free(struct usb_card_rec *card)
358*4882a593Smuzhiyun {
359*4882a593Smuzhiyun 	struct usb_tx_data_port *port;
360*4882a593Smuzhiyun 	int i, j;
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun 	if (atomic_read(&card->rx_cmd_urb_pending) && card->rx_cmd.urb)
363*4882a593Smuzhiyun 		usb_kill_urb(card->rx_cmd.urb);
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun 	usb_free_urb(card->rx_cmd.urb);
366*4882a593Smuzhiyun 	card->rx_cmd.urb = NULL;
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun 	if (atomic_read(&card->rx_data_urb_pending))
369*4882a593Smuzhiyun 		for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
370*4882a593Smuzhiyun 			if (card->rx_data_list[i].urb)
371*4882a593Smuzhiyun 				usb_kill_urb(card->rx_data_list[i].urb);
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun 	for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
374*4882a593Smuzhiyun 		usb_free_urb(card->rx_data_list[i].urb);
375*4882a593Smuzhiyun 		card->rx_data_list[i].urb = NULL;
376*4882a593Smuzhiyun 	}
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun 	for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
379*4882a593Smuzhiyun 		port = &card->port[i];
380*4882a593Smuzhiyun 		for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
381*4882a593Smuzhiyun 			usb_kill_urb(port->tx_data_list[j].urb);
382*4882a593Smuzhiyun 			usb_free_urb(port->tx_data_list[j].urb);
383*4882a593Smuzhiyun 			port->tx_data_list[j].urb = NULL;
384*4882a593Smuzhiyun 		}
385*4882a593Smuzhiyun 	}
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun 	usb_free_urb(card->tx_cmd.urb);
388*4882a593Smuzhiyun 	card->tx_cmd.urb = NULL;
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	return;
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun /* This function probes an mwifiex device and registers it. It allocates
394*4882a593Smuzhiyun  * the card structure, initiates the device registration and initialization
395*4882a593Smuzhiyun  * procedure by adding a logical interface.
396*4882a593Smuzhiyun  */
mwifiex_usb_probe(struct usb_interface * intf,const struct usb_device_id * id)397*4882a593Smuzhiyun static int mwifiex_usb_probe(struct usb_interface *intf,
398*4882a593Smuzhiyun 			     const struct usb_device_id *id)
399*4882a593Smuzhiyun {
400*4882a593Smuzhiyun 	struct usb_device *udev = interface_to_usbdev(intf);
401*4882a593Smuzhiyun 	struct usb_host_interface *iface_desc = intf->cur_altsetting;
402*4882a593Smuzhiyun 	struct usb_endpoint_descriptor *epd;
403*4882a593Smuzhiyun 	int ret, i;
404*4882a593Smuzhiyun 	struct usb_card_rec *card;
405*4882a593Smuzhiyun 	u16 id_vendor, id_product, bcd_device;
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun 	card = devm_kzalloc(&intf->dev, sizeof(*card), GFP_KERNEL);
408*4882a593Smuzhiyun 	if (!card)
409*4882a593Smuzhiyun 		return -ENOMEM;
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun 	init_completion(&card->fw_done);
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun 	id_vendor = le16_to_cpu(udev->descriptor.idVendor);
414*4882a593Smuzhiyun 	id_product = le16_to_cpu(udev->descriptor.idProduct);
415*4882a593Smuzhiyun 	bcd_device = le16_to_cpu(udev->descriptor.bcdDevice);
416*4882a593Smuzhiyun 	pr_debug("info: VID/PID = %X/%X, Boot2 version = %X\n",
417*4882a593Smuzhiyun 		 id_vendor, id_product, bcd_device);
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun 	/* PID_1 is used for firmware downloading only */
420*4882a593Smuzhiyun 	switch (id_product) {
421*4882a593Smuzhiyun 	case USB8766_PID_1:
422*4882a593Smuzhiyun 	case USB8797_PID_1:
423*4882a593Smuzhiyun 	case USB8801_PID_1:
424*4882a593Smuzhiyun 	case USB8997_PID_1:
425*4882a593Smuzhiyun 		card->usb_boot_state = USB8XXX_FW_DNLD;
426*4882a593Smuzhiyun 		break;
427*4882a593Smuzhiyun 	case USB8766_PID_2:
428*4882a593Smuzhiyun 	case USB8797_PID_2:
429*4882a593Smuzhiyun 	case USB8801_PID_2:
430*4882a593Smuzhiyun 	case USB8997_PID_2:
431*4882a593Smuzhiyun 		card->usb_boot_state = USB8XXX_FW_READY;
432*4882a593Smuzhiyun 		break;
433*4882a593Smuzhiyun 	default:
434*4882a593Smuzhiyun 		pr_warn("unknown id_product %#x\n", id_product);
435*4882a593Smuzhiyun 		card->usb_boot_state = USB8XXX_FW_DNLD;
436*4882a593Smuzhiyun 		break;
437*4882a593Smuzhiyun 	}
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun 	card->udev = udev;
440*4882a593Smuzhiyun 	card->intf = intf;
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun 	pr_debug("info: bcdUSB=%#x Device Class=%#x SubClass=%#x Protocol=%#x\n",
443*4882a593Smuzhiyun 		 le16_to_cpu(udev->descriptor.bcdUSB),
444*4882a593Smuzhiyun 		 udev->descriptor.bDeviceClass,
445*4882a593Smuzhiyun 		 udev->descriptor.bDeviceSubClass,
446*4882a593Smuzhiyun 		 udev->descriptor.bDeviceProtocol);
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
449*4882a593Smuzhiyun 		epd = &iface_desc->endpoint[i].desc;
450*4882a593Smuzhiyun 		if (usb_endpoint_dir_in(epd) &&
451*4882a593Smuzhiyun 		    usb_endpoint_num(epd) == MWIFIEX_USB_EP_CMD_EVENT &&
452*4882a593Smuzhiyun 		    (usb_endpoint_xfer_bulk(epd) ||
453*4882a593Smuzhiyun 		     usb_endpoint_xfer_int(epd))) {
454*4882a593Smuzhiyun 			card->rx_cmd_ep_type = usb_endpoint_type(epd);
455*4882a593Smuzhiyun 			card->rx_cmd_interval = epd->bInterval;
456*4882a593Smuzhiyun 			pr_debug("info: Rx CMD/EVT:: max pkt size: %d, addr: %d, ep_type: %d\n",
457*4882a593Smuzhiyun 				 le16_to_cpu(epd->wMaxPacketSize),
458*4882a593Smuzhiyun 				 epd->bEndpointAddress, card->rx_cmd_ep_type);
459*4882a593Smuzhiyun 			card->rx_cmd_ep = usb_endpoint_num(epd);
460*4882a593Smuzhiyun 			atomic_set(&card->rx_cmd_urb_pending, 0);
461*4882a593Smuzhiyun 		}
462*4882a593Smuzhiyun 		if (usb_endpoint_dir_in(epd) &&
463*4882a593Smuzhiyun 		    usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA &&
464*4882a593Smuzhiyun 		    usb_endpoint_xfer_bulk(epd)) {
465*4882a593Smuzhiyun 			pr_debug("info: bulk IN: max pkt size: %d, addr: %d\n",
466*4882a593Smuzhiyun 				 le16_to_cpu(epd->wMaxPacketSize),
467*4882a593Smuzhiyun 				 epd->bEndpointAddress);
468*4882a593Smuzhiyun 			card->rx_data_ep = usb_endpoint_num(epd);
469*4882a593Smuzhiyun 			atomic_set(&card->rx_data_urb_pending, 0);
470*4882a593Smuzhiyun 		}
471*4882a593Smuzhiyun 		if (usb_endpoint_dir_out(epd) &&
472*4882a593Smuzhiyun 		    usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA &&
473*4882a593Smuzhiyun 		    usb_endpoint_xfer_bulk(epd)) {
474*4882a593Smuzhiyun 			pr_debug("info: bulk OUT: max pkt size: %d, addr: %d\n",
475*4882a593Smuzhiyun 				 le16_to_cpu(epd->wMaxPacketSize),
476*4882a593Smuzhiyun 				 epd->bEndpointAddress);
477*4882a593Smuzhiyun 			card->port[0].tx_data_ep = usb_endpoint_num(epd);
478*4882a593Smuzhiyun 			atomic_set(&card->port[0].tx_data_urb_pending, 0);
479*4882a593Smuzhiyun 		}
480*4882a593Smuzhiyun 		if (usb_endpoint_dir_out(epd) &&
481*4882a593Smuzhiyun 		    usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA_CH2 &&
482*4882a593Smuzhiyun 		    usb_endpoint_xfer_bulk(epd)) {
483*4882a593Smuzhiyun 			pr_debug("info: bulk OUT chan2:\t"
484*4882a593Smuzhiyun 				 "max pkt size: %d, addr: %d\n",
485*4882a593Smuzhiyun 				 le16_to_cpu(epd->wMaxPacketSize),
486*4882a593Smuzhiyun 				 epd->bEndpointAddress);
487*4882a593Smuzhiyun 			card->port[1].tx_data_ep = usb_endpoint_num(epd);
488*4882a593Smuzhiyun 			atomic_set(&card->port[1].tx_data_urb_pending, 0);
489*4882a593Smuzhiyun 		}
490*4882a593Smuzhiyun 		if (usb_endpoint_dir_out(epd) &&
491*4882a593Smuzhiyun 		    usb_endpoint_num(epd) == MWIFIEX_USB_EP_CMD_EVENT &&
492*4882a593Smuzhiyun 		    (usb_endpoint_xfer_bulk(epd) ||
493*4882a593Smuzhiyun 		     usb_endpoint_xfer_int(epd))) {
494*4882a593Smuzhiyun 			card->tx_cmd_ep_type = usb_endpoint_type(epd);
495*4882a593Smuzhiyun 			card->tx_cmd_interval = epd->bInterval;
496*4882a593Smuzhiyun 			pr_debug("info: bulk OUT: max pkt size: %d, addr: %d\n",
497*4882a593Smuzhiyun 				 le16_to_cpu(epd->wMaxPacketSize),
498*4882a593Smuzhiyun 				 epd->bEndpointAddress);
499*4882a593Smuzhiyun 			pr_debug("info: Tx CMD:: max pkt size: %d, addr: %d, ep_type: %d\n",
500*4882a593Smuzhiyun 				 le16_to_cpu(epd->wMaxPacketSize),
501*4882a593Smuzhiyun 				 epd->bEndpointAddress, card->tx_cmd_ep_type);
502*4882a593Smuzhiyun 			card->tx_cmd_ep = usb_endpoint_num(epd);
503*4882a593Smuzhiyun 			atomic_set(&card->tx_cmd_urb_pending, 0);
504*4882a593Smuzhiyun 			card->bulk_out_maxpktsize =
505*4882a593Smuzhiyun 					le16_to_cpu(epd->wMaxPacketSize);
506*4882a593Smuzhiyun 		}
507*4882a593Smuzhiyun 	}
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun 	switch (card->usb_boot_state) {
510*4882a593Smuzhiyun 	case USB8XXX_FW_DNLD:
511*4882a593Smuzhiyun 		/* Reject broken descriptors. */
512*4882a593Smuzhiyun 		if (!card->rx_cmd_ep || !card->tx_cmd_ep)
513*4882a593Smuzhiyun 			return -ENODEV;
514*4882a593Smuzhiyun 		if (card->bulk_out_maxpktsize == 0)
515*4882a593Smuzhiyun 			return -ENODEV;
516*4882a593Smuzhiyun 		break;
517*4882a593Smuzhiyun 	case USB8XXX_FW_READY:
518*4882a593Smuzhiyun 		/* Assume the driver can handle missing endpoints for now. */
519*4882a593Smuzhiyun 		break;
520*4882a593Smuzhiyun 	default:
521*4882a593Smuzhiyun 		WARN_ON(1);
522*4882a593Smuzhiyun 		return -ENODEV;
523*4882a593Smuzhiyun 	}
524*4882a593Smuzhiyun 
525*4882a593Smuzhiyun 	usb_set_intfdata(intf, card);
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun 	ret = mwifiex_add_card(card, &card->fw_done, &usb_ops,
528*4882a593Smuzhiyun 			       MWIFIEX_USB, &card->udev->dev);
529*4882a593Smuzhiyun 	if (ret) {
530*4882a593Smuzhiyun 		pr_err("%s: mwifiex_add_card failed: %d\n", __func__, ret);
531*4882a593Smuzhiyun 		usb_reset_device(udev);
532*4882a593Smuzhiyun 		return ret;
533*4882a593Smuzhiyun 	}
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun 	usb_get_dev(udev);
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun 	return 0;
538*4882a593Smuzhiyun }
539*4882a593Smuzhiyun 
540*4882a593Smuzhiyun /* Kernel needs to suspend all functions separately. Therefore all
541*4882a593Smuzhiyun  * registered functions must have drivers with suspend and resume
542*4882a593Smuzhiyun  * methods. Failing that the kernel simply removes the whole card.
543*4882a593Smuzhiyun  *
544*4882a593Smuzhiyun  * If already not suspended, this function allocates and sends a
545*4882a593Smuzhiyun  * 'host sleep activate' request to the firmware and turns off the traffic.
546*4882a593Smuzhiyun  */
mwifiex_usb_suspend(struct usb_interface * intf,pm_message_t message)547*4882a593Smuzhiyun static int mwifiex_usb_suspend(struct usb_interface *intf, pm_message_t message)
548*4882a593Smuzhiyun {
549*4882a593Smuzhiyun 	struct usb_card_rec *card = usb_get_intfdata(intf);
550*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter;
551*4882a593Smuzhiyun 	struct usb_tx_data_port *port;
552*4882a593Smuzhiyun 	int i, j;
553*4882a593Smuzhiyun 
554*4882a593Smuzhiyun 	/* Might still be loading firmware */
555*4882a593Smuzhiyun 	wait_for_completion(&card->fw_done);
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	adapter = card->adapter;
558*4882a593Smuzhiyun 	if (!adapter) {
559*4882a593Smuzhiyun 		dev_err(&intf->dev, "card is not valid\n");
560*4882a593Smuzhiyun 		return 0;
561*4882a593Smuzhiyun 	}
562*4882a593Smuzhiyun 
563*4882a593Smuzhiyun 	if (unlikely(test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)))
564*4882a593Smuzhiyun 		mwifiex_dbg(adapter, WARN,
565*4882a593Smuzhiyun 			    "Device already suspended\n");
566*4882a593Smuzhiyun 
567*4882a593Smuzhiyun 	/* Enable the Host Sleep */
568*4882a593Smuzhiyun 	if (!mwifiex_enable_hs(adapter)) {
569*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
570*4882a593Smuzhiyun 			    "cmd: failed to suspend\n");
571*4882a593Smuzhiyun 		clear_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
572*4882a593Smuzhiyun 		return -EFAULT;
573*4882a593Smuzhiyun 	}
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun 
576*4882a593Smuzhiyun 	/* 'MWIFIEX_IS_SUSPENDED' bit indicates device is suspended.
577*4882a593Smuzhiyun 	 * It must be set here before the usb_kill_urb() calls. Reason
578*4882a593Smuzhiyun 	 * is in the complete handlers, urb->status(= -ENOENT) and
579*4882a593Smuzhiyun 	 * this flag is used in combination to distinguish between a
580*4882a593Smuzhiyun 	 * 'suspended' state and a 'disconnect' one.
581*4882a593Smuzhiyun 	 */
582*4882a593Smuzhiyun 	set_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
583*4882a593Smuzhiyun 	clear_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun 	if (atomic_read(&card->rx_cmd_urb_pending) && card->rx_cmd.urb)
586*4882a593Smuzhiyun 		usb_kill_urb(card->rx_cmd.urb);
587*4882a593Smuzhiyun 
588*4882a593Smuzhiyun 	if (atomic_read(&card->rx_data_urb_pending))
589*4882a593Smuzhiyun 		for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
590*4882a593Smuzhiyun 			if (card->rx_data_list[i].urb)
591*4882a593Smuzhiyun 				usb_kill_urb(card->rx_data_list[i].urb);
592*4882a593Smuzhiyun 
593*4882a593Smuzhiyun 	for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
594*4882a593Smuzhiyun 		port = &card->port[i];
595*4882a593Smuzhiyun 		for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
596*4882a593Smuzhiyun 			if (port->tx_data_list[j].urb)
597*4882a593Smuzhiyun 				usb_kill_urb(port->tx_data_list[j].urb);
598*4882a593Smuzhiyun 		}
599*4882a593Smuzhiyun 	}
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun 	if (card->tx_cmd.urb)
602*4882a593Smuzhiyun 		usb_kill_urb(card->tx_cmd.urb);
603*4882a593Smuzhiyun 
604*4882a593Smuzhiyun 	return 0;
605*4882a593Smuzhiyun }
606*4882a593Smuzhiyun 
607*4882a593Smuzhiyun /* Kernel needs to suspend all functions separately. Therefore all
608*4882a593Smuzhiyun  * registered functions must have drivers with suspend and resume
609*4882a593Smuzhiyun  * methods. Failing that the kernel simply removes the whole card.
610*4882a593Smuzhiyun  *
611*4882a593Smuzhiyun  * If already not resumed, this function turns on the traffic and
612*4882a593Smuzhiyun  * sends a 'host sleep cancel' request to the firmware.
613*4882a593Smuzhiyun  */
mwifiex_usb_resume(struct usb_interface * intf)614*4882a593Smuzhiyun static int mwifiex_usb_resume(struct usb_interface *intf)
615*4882a593Smuzhiyun {
616*4882a593Smuzhiyun 	struct usb_card_rec *card = usb_get_intfdata(intf);
617*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter;
618*4882a593Smuzhiyun 	int i;
619*4882a593Smuzhiyun 
620*4882a593Smuzhiyun 	if (!card->adapter) {
621*4882a593Smuzhiyun 		dev_err(&intf->dev, "%s: card->adapter is NULL\n",
622*4882a593Smuzhiyun 			__func__);
623*4882a593Smuzhiyun 		return 0;
624*4882a593Smuzhiyun 	}
625*4882a593Smuzhiyun 	adapter = card->adapter;
626*4882a593Smuzhiyun 
627*4882a593Smuzhiyun 	if (unlikely(!test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags))) {
628*4882a593Smuzhiyun 		mwifiex_dbg(adapter, WARN,
629*4882a593Smuzhiyun 			    "Device already resumed\n");
630*4882a593Smuzhiyun 		return 0;
631*4882a593Smuzhiyun 	}
632*4882a593Smuzhiyun 
633*4882a593Smuzhiyun 	/* Indicate device resumed. The netdev queue will be resumed only
634*4882a593Smuzhiyun 	 * after the urbs have been re-submitted
635*4882a593Smuzhiyun 	 */
636*4882a593Smuzhiyun 	clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
637*4882a593Smuzhiyun 
638*4882a593Smuzhiyun 	if (!atomic_read(&card->rx_data_urb_pending))
639*4882a593Smuzhiyun 		for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
640*4882a593Smuzhiyun 			mwifiex_usb_submit_rx_urb(&card->rx_data_list[i],
641*4882a593Smuzhiyun 						  MWIFIEX_RX_DATA_BUF_SIZE);
642*4882a593Smuzhiyun 
643*4882a593Smuzhiyun 	if (!atomic_read(&card->rx_cmd_urb_pending)) {
644*4882a593Smuzhiyun 		card->rx_cmd.skb = dev_alloc_skb(MWIFIEX_RX_CMD_BUF_SIZE);
645*4882a593Smuzhiyun 		if (card->rx_cmd.skb)
646*4882a593Smuzhiyun 			mwifiex_usb_submit_rx_urb(&card->rx_cmd,
647*4882a593Smuzhiyun 						  MWIFIEX_RX_CMD_BUF_SIZE);
648*4882a593Smuzhiyun 	}
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun 	/* Disable Host Sleep */
651*4882a593Smuzhiyun 	if (adapter->hs_activated)
652*4882a593Smuzhiyun 		mwifiex_cancel_hs(mwifiex_get_priv(adapter,
653*4882a593Smuzhiyun 						   MWIFIEX_BSS_ROLE_ANY),
654*4882a593Smuzhiyun 				  MWIFIEX_ASYNC_CMD);
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun 	return 0;
657*4882a593Smuzhiyun }
658*4882a593Smuzhiyun 
mwifiex_usb_disconnect(struct usb_interface * intf)659*4882a593Smuzhiyun static void mwifiex_usb_disconnect(struct usb_interface *intf)
660*4882a593Smuzhiyun {
661*4882a593Smuzhiyun 	struct usb_card_rec *card = usb_get_intfdata(intf);
662*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter;
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun 	wait_for_completion(&card->fw_done);
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun 	adapter = card->adapter;
667*4882a593Smuzhiyun 	if (!adapter || !adapter->priv_num)
668*4882a593Smuzhiyun 		return;
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun 	if (card->udev->state != USB_STATE_NOTATTACHED && !adapter->mfg_mode) {
671*4882a593Smuzhiyun 		mwifiex_deauthenticate_all(adapter);
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun 		mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
674*4882a593Smuzhiyun 							  MWIFIEX_BSS_ROLE_ANY),
675*4882a593Smuzhiyun 					 MWIFIEX_FUNC_SHUTDOWN);
676*4882a593Smuzhiyun 	}
677*4882a593Smuzhiyun 
678*4882a593Smuzhiyun 	mwifiex_dbg(adapter, FATAL,
679*4882a593Smuzhiyun 		    "%s: removing card\n", __func__);
680*4882a593Smuzhiyun 	mwifiex_remove_card(adapter);
681*4882a593Smuzhiyun 
682*4882a593Smuzhiyun 	usb_put_dev(interface_to_usbdev(intf));
683*4882a593Smuzhiyun }
684*4882a593Smuzhiyun 
mwifiex_usb_coredump(struct device * dev)685*4882a593Smuzhiyun static void mwifiex_usb_coredump(struct device *dev)
686*4882a593Smuzhiyun {
687*4882a593Smuzhiyun 	struct usb_interface *intf = to_usb_interface(dev);
688*4882a593Smuzhiyun 	struct usb_card_rec *card = usb_get_intfdata(intf);
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun 	mwifiex_fw_dump_event(mwifiex_get_priv(card->adapter,
691*4882a593Smuzhiyun 					       MWIFIEX_BSS_ROLE_ANY));
692*4882a593Smuzhiyun }
693*4882a593Smuzhiyun 
694*4882a593Smuzhiyun static struct usb_driver mwifiex_usb_driver = {
695*4882a593Smuzhiyun 	.name = "mwifiex_usb",
696*4882a593Smuzhiyun 	.probe = mwifiex_usb_probe,
697*4882a593Smuzhiyun 	.disconnect = mwifiex_usb_disconnect,
698*4882a593Smuzhiyun 	.id_table = mwifiex_usb_table,
699*4882a593Smuzhiyun 	.suspend = mwifiex_usb_suspend,
700*4882a593Smuzhiyun 	.resume = mwifiex_usb_resume,
701*4882a593Smuzhiyun 	.soft_unbind = 1,
702*4882a593Smuzhiyun 	.drvwrap.driver = {
703*4882a593Smuzhiyun 		.coredump = mwifiex_usb_coredump,
704*4882a593Smuzhiyun 	},
705*4882a593Smuzhiyun };
706*4882a593Smuzhiyun 
mwifiex_write_data_sync(struct mwifiex_adapter * adapter,u8 * pbuf,u32 * len,u8 ep,u32 timeout)707*4882a593Smuzhiyun static int mwifiex_write_data_sync(struct mwifiex_adapter *adapter, u8 *pbuf,
708*4882a593Smuzhiyun 				   u32 *len, u8 ep, u32 timeout)
709*4882a593Smuzhiyun {
710*4882a593Smuzhiyun 	struct usb_card_rec *card = adapter->card;
711*4882a593Smuzhiyun 	int actual_length, ret;
712*4882a593Smuzhiyun 
713*4882a593Smuzhiyun 	if (!(*len % card->bulk_out_maxpktsize))
714*4882a593Smuzhiyun 		(*len)++;
715*4882a593Smuzhiyun 
716*4882a593Smuzhiyun 	/* Send the data block */
717*4882a593Smuzhiyun 	ret = usb_bulk_msg(card->udev, usb_sndbulkpipe(card->udev, ep), pbuf,
718*4882a593Smuzhiyun 			   *len, &actual_length, timeout);
719*4882a593Smuzhiyun 	if (ret) {
720*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
721*4882a593Smuzhiyun 			    "usb_bulk_msg for tx failed: %d\n", ret);
722*4882a593Smuzhiyun 		return ret;
723*4882a593Smuzhiyun 	}
724*4882a593Smuzhiyun 
725*4882a593Smuzhiyun 	*len = actual_length;
726*4882a593Smuzhiyun 
727*4882a593Smuzhiyun 	return ret;
728*4882a593Smuzhiyun }
729*4882a593Smuzhiyun 
mwifiex_read_data_sync(struct mwifiex_adapter * adapter,u8 * pbuf,u32 * len,u8 ep,u32 timeout)730*4882a593Smuzhiyun static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *pbuf,
731*4882a593Smuzhiyun 				  u32 *len, u8 ep, u32 timeout)
732*4882a593Smuzhiyun {
733*4882a593Smuzhiyun 	struct usb_card_rec *card = adapter->card;
734*4882a593Smuzhiyun 	int actual_length, ret;
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun 	/* Receive the data response */
737*4882a593Smuzhiyun 	ret = usb_bulk_msg(card->udev, usb_rcvbulkpipe(card->udev, ep), pbuf,
738*4882a593Smuzhiyun 			   *len, &actual_length, timeout);
739*4882a593Smuzhiyun 	if (ret) {
740*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
741*4882a593Smuzhiyun 			    "usb_bulk_msg for rx failed: %d\n", ret);
742*4882a593Smuzhiyun 		return ret;
743*4882a593Smuzhiyun 	}
744*4882a593Smuzhiyun 
745*4882a593Smuzhiyun 	*len = actual_length;
746*4882a593Smuzhiyun 
747*4882a593Smuzhiyun 	return ret;
748*4882a593Smuzhiyun }
749*4882a593Smuzhiyun 
mwifiex_usb_port_resync(struct mwifiex_adapter * adapter)750*4882a593Smuzhiyun static void mwifiex_usb_port_resync(struct mwifiex_adapter *adapter)
751*4882a593Smuzhiyun {
752*4882a593Smuzhiyun 	struct usb_card_rec *card = adapter->card;
753*4882a593Smuzhiyun 	u8 active_port = MWIFIEX_USB_EP_DATA;
754*4882a593Smuzhiyun 	struct mwifiex_private *priv = NULL;
755*4882a593Smuzhiyun 	int i;
756*4882a593Smuzhiyun 
757*4882a593Smuzhiyun 	if (adapter->usb_mc_status) {
758*4882a593Smuzhiyun 		for (i = 0; i < adapter->priv_num; i++) {
759*4882a593Smuzhiyun 			priv = adapter->priv[i];
760*4882a593Smuzhiyun 			if (!priv)
761*4882a593Smuzhiyun 				continue;
762*4882a593Smuzhiyun 			if ((priv->bss_role == MWIFIEX_BSS_ROLE_UAP &&
763*4882a593Smuzhiyun 			     !priv->bss_started) ||
764*4882a593Smuzhiyun 			    (priv->bss_role == MWIFIEX_BSS_ROLE_STA &&
765*4882a593Smuzhiyun 			     !priv->media_connected))
766*4882a593Smuzhiyun 				priv->usb_port = MWIFIEX_USB_EP_DATA;
767*4882a593Smuzhiyun 		}
768*4882a593Smuzhiyun 		for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++)
769*4882a593Smuzhiyun 			card->port[i].block_status = false;
770*4882a593Smuzhiyun 	} else {
771*4882a593Smuzhiyun 		for (i = 0; i < adapter->priv_num; i++) {
772*4882a593Smuzhiyun 			priv = adapter->priv[i];
773*4882a593Smuzhiyun 			if (!priv)
774*4882a593Smuzhiyun 				continue;
775*4882a593Smuzhiyun 			if ((priv->bss_role == MWIFIEX_BSS_ROLE_UAP &&
776*4882a593Smuzhiyun 			     priv->bss_started) ||
777*4882a593Smuzhiyun 			    (priv->bss_role == MWIFIEX_BSS_ROLE_STA &&
778*4882a593Smuzhiyun 			     priv->media_connected)) {
779*4882a593Smuzhiyun 				active_port = priv->usb_port;
780*4882a593Smuzhiyun 				break;
781*4882a593Smuzhiyun 			}
782*4882a593Smuzhiyun 		}
783*4882a593Smuzhiyun 		for (i = 0; i < adapter->priv_num; i++) {
784*4882a593Smuzhiyun 			priv = adapter->priv[i];
785*4882a593Smuzhiyun 			if (priv)
786*4882a593Smuzhiyun 				priv->usb_port = active_port;
787*4882a593Smuzhiyun 		}
788*4882a593Smuzhiyun 		for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
789*4882a593Smuzhiyun 			if (active_port == card->port[i].tx_data_ep)
790*4882a593Smuzhiyun 				card->port[i].block_status = false;
791*4882a593Smuzhiyun 			else
792*4882a593Smuzhiyun 				card->port[i].block_status = true;
793*4882a593Smuzhiyun 		}
794*4882a593Smuzhiyun 	}
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun 
mwifiex_usb_is_port_ready(struct mwifiex_private * priv)797*4882a593Smuzhiyun static bool mwifiex_usb_is_port_ready(struct mwifiex_private *priv)
798*4882a593Smuzhiyun {
799*4882a593Smuzhiyun 	struct usb_card_rec *card = priv->adapter->card;
800*4882a593Smuzhiyun 	int idx;
801*4882a593Smuzhiyun 
802*4882a593Smuzhiyun 	for (idx = 0; idx < MWIFIEX_TX_DATA_PORT; idx++) {
803*4882a593Smuzhiyun 		if (priv->usb_port == card->port[idx].tx_data_ep)
804*4882a593Smuzhiyun 			return !card->port[idx].block_status;
805*4882a593Smuzhiyun 	}
806*4882a593Smuzhiyun 
807*4882a593Smuzhiyun 	return false;
808*4882a593Smuzhiyun }
809*4882a593Smuzhiyun 
mwifiex_usb_data_sent(struct mwifiex_adapter * adapter)810*4882a593Smuzhiyun static inline u8 mwifiex_usb_data_sent(struct mwifiex_adapter *adapter)
811*4882a593Smuzhiyun {
812*4882a593Smuzhiyun 	struct usb_card_rec *card = adapter->card;
813*4882a593Smuzhiyun 	int i;
814*4882a593Smuzhiyun 
815*4882a593Smuzhiyun 	for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++)
816*4882a593Smuzhiyun 		if (!card->port[i].block_status)
817*4882a593Smuzhiyun 			return false;
818*4882a593Smuzhiyun 
819*4882a593Smuzhiyun 	return true;
820*4882a593Smuzhiyun }
821*4882a593Smuzhiyun 
mwifiex_usb_construct_send_urb(struct mwifiex_adapter * adapter,struct usb_tx_data_port * port,u8 ep,struct urb_context * context,struct sk_buff * skb_send)822*4882a593Smuzhiyun static int mwifiex_usb_construct_send_urb(struct mwifiex_adapter *adapter,
823*4882a593Smuzhiyun 					  struct usb_tx_data_port *port, u8 ep,
824*4882a593Smuzhiyun 					  struct urb_context *context,
825*4882a593Smuzhiyun 					  struct sk_buff *skb_send)
826*4882a593Smuzhiyun {
827*4882a593Smuzhiyun 	struct usb_card_rec *card = adapter->card;
828*4882a593Smuzhiyun 	int ret = -EINPROGRESS;
829*4882a593Smuzhiyun 	struct urb *tx_urb;
830*4882a593Smuzhiyun 
831*4882a593Smuzhiyun 	context->adapter = adapter;
832*4882a593Smuzhiyun 	context->ep = ep;
833*4882a593Smuzhiyun 	context->skb = skb_send;
834*4882a593Smuzhiyun 	tx_urb = context->urb;
835*4882a593Smuzhiyun 
836*4882a593Smuzhiyun 	if (ep == card->tx_cmd_ep &&
837*4882a593Smuzhiyun 	    card->tx_cmd_ep_type == USB_ENDPOINT_XFER_INT)
838*4882a593Smuzhiyun 		usb_fill_int_urb(tx_urb, card->udev,
839*4882a593Smuzhiyun 				 usb_sndintpipe(card->udev, ep), skb_send->data,
840*4882a593Smuzhiyun 				 skb_send->len, mwifiex_usb_tx_complete,
841*4882a593Smuzhiyun 				 (void *)context, card->tx_cmd_interval);
842*4882a593Smuzhiyun 	else
843*4882a593Smuzhiyun 		usb_fill_bulk_urb(tx_urb, card->udev,
844*4882a593Smuzhiyun 				  usb_sndbulkpipe(card->udev, ep),
845*4882a593Smuzhiyun 				  skb_send->data, skb_send->len,
846*4882a593Smuzhiyun 				  mwifiex_usb_tx_complete, (void *)context);
847*4882a593Smuzhiyun 
848*4882a593Smuzhiyun 	tx_urb->transfer_flags |= URB_ZERO_PACKET;
849*4882a593Smuzhiyun 
850*4882a593Smuzhiyun 	if (ep == card->tx_cmd_ep)
851*4882a593Smuzhiyun 		atomic_inc(&card->tx_cmd_urb_pending);
852*4882a593Smuzhiyun 	else
853*4882a593Smuzhiyun 		atomic_inc(&port->tx_data_urb_pending);
854*4882a593Smuzhiyun 
855*4882a593Smuzhiyun 	if (ep != card->tx_cmd_ep &&
856*4882a593Smuzhiyun 	    atomic_read(&port->tx_data_urb_pending) ==
857*4882a593Smuzhiyun 					MWIFIEX_TX_DATA_URB) {
858*4882a593Smuzhiyun 		port->block_status = true;
859*4882a593Smuzhiyun 		adapter->data_sent = mwifiex_usb_data_sent(adapter);
860*4882a593Smuzhiyun 		ret = -ENOSR;
861*4882a593Smuzhiyun 	}
862*4882a593Smuzhiyun 
863*4882a593Smuzhiyun 	if (usb_submit_urb(tx_urb, GFP_ATOMIC)) {
864*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
865*4882a593Smuzhiyun 			    "%s: usb_submit_urb failed\n", __func__);
866*4882a593Smuzhiyun 		if (ep == card->tx_cmd_ep) {
867*4882a593Smuzhiyun 			atomic_dec(&card->tx_cmd_urb_pending);
868*4882a593Smuzhiyun 		} else {
869*4882a593Smuzhiyun 			atomic_dec(&port->tx_data_urb_pending);
870*4882a593Smuzhiyun 			port->block_status = false;
871*4882a593Smuzhiyun 			adapter->data_sent = false;
872*4882a593Smuzhiyun 			if (port->tx_data_ix)
873*4882a593Smuzhiyun 				port->tx_data_ix--;
874*4882a593Smuzhiyun 			else
875*4882a593Smuzhiyun 				port->tx_data_ix = MWIFIEX_TX_DATA_URB;
876*4882a593Smuzhiyun 		}
877*4882a593Smuzhiyun 		ret = -1;
878*4882a593Smuzhiyun 	}
879*4882a593Smuzhiyun 
880*4882a593Smuzhiyun 	return ret;
881*4882a593Smuzhiyun }
882*4882a593Smuzhiyun 
mwifiex_usb_prepare_tx_aggr_skb(struct mwifiex_adapter * adapter,struct usb_tx_data_port * port,struct sk_buff ** skb_send)883*4882a593Smuzhiyun static int mwifiex_usb_prepare_tx_aggr_skb(struct mwifiex_adapter *adapter,
884*4882a593Smuzhiyun 					   struct usb_tx_data_port *port,
885*4882a593Smuzhiyun 					   struct sk_buff **skb_send)
886*4882a593Smuzhiyun {
887*4882a593Smuzhiyun 	struct sk_buff *skb_aggr, *skb_tmp;
888*4882a593Smuzhiyun 	u8 *payload, pad;
889*4882a593Smuzhiyun 	u16 align = adapter->bus_aggr.tx_aggr_align;
890*4882a593Smuzhiyun 	struct mwifiex_txinfo *tx_info = NULL;
891*4882a593Smuzhiyun 	bool is_txinfo_set = false;
892*4882a593Smuzhiyun 
893*4882a593Smuzhiyun 	/* Packets in aggr_list will be send in either skb_aggr or
894*4882a593Smuzhiyun 	 * write complete, delete the tx_aggr timer
895*4882a593Smuzhiyun 	 */
896*4882a593Smuzhiyun 	if (port->tx_aggr.timer_cnxt.is_hold_timer_set) {
897*4882a593Smuzhiyun 		del_timer(&port->tx_aggr.timer_cnxt.hold_timer);
898*4882a593Smuzhiyun 		port->tx_aggr.timer_cnxt.is_hold_timer_set = false;
899*4882a593Smuzhiyun 		port->tx_aggr.timer_cnxt.hold_tmo_msecs = 0;
900*4882a593Smuzhiyun 	}
901*4882a593Smuzhiyun 
902*4882a593Smuzhiyun 	skb_aggr = mwifiex_alloc_dma_align_buf(port->tx_aggr.aggr_len,
903*4882a593Smuzhiyun 					       GFP_ATOMIC);
904*4882a593Smuzhiyun 	if (!skb_aggr) {
905*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
906*4882a593Smuzhiyun 			    "%s: alloc skb_aggr failed\n", __func__);
907*4882a593Smuzhiyun 
908*4882a593Smuzhiyun 		while ((skb_tmp = skb_dequeue(&port->tx_aggr.aggr_list)))
909*4882a593Smuzhiyun 			mwifiex_write_data_complete(adapter, skb_tmp, 0, -1);
910*4882a593Smuzhiyun 
911*4882a593Smuzhiyun 		port->tx_aggr.aggr_num = 0;
912*4882a593Smuzhiyun 		port->tx_aggr.aggr_len = 0;
913*4882a593Smuzhiyun 		return -EBUSY;
914*4882a593Smuzhiyun 	}
915*4882a593Smuzhiyun 
916*4882a593Smuzhiyun 	tx_info = MWIFIEX_SKB_TXCB(skb_aggr);
917*4882a593Smuzhiyun 	memset(tx_info, 0, sizeof(*tx_info));
918*4882a593Smuzhiyun 
919*4882a593Smuzhiyun 	while ((skb_tmp = skb_dequeue(&port->tx_aggr.aggr_list))) {
920*4882a593Smuzhiyun 		/* padding for aligning next packet header*/
921*4882a593Smuzhiyun 		pad = (align - (skb_tmp->len & (align - 1))) % align;
922*4882a593Smuzhiyun 		payload = skb_put(skb_aggr, skb_tmp->len + pad);
923*4882a593Smuzhiyun 		memcpy(payload, skb_tmp->data, skb_tmp->len);
924*4882a593Smuzhiyun 		if (skb_queue_empty(&port->tx_aggr.aggr_list)) {
925*4882a593Smuzhiyun 			/* do not padding for last packet*/
926*4882a593Smuzhiyun 			*(u16 *)payload = cpu_to_le16(skb_tmp->len);
927*4882a593Smuzhiyun 			*(u16 *)&payload[2] =
928*4882a593Smuzhiyun 				cpu_to_le16(MWIFIEX_TYPE_AGGR_DATA_V2 | 0x80);
929*4882a593Smuzhiyun 			skb_trim(skb_aggr, skb_aggr->len - pad);
930*4882a593Smuzhiyun 		} else {
931*4882a593Smuzhiyun 			/* add aggregation interface header */
932*4882a593Smuzhiyun 			*(u16 *)payload = cpu_to_le16(skb_tmp->len + pad);
933*4882a593Smuzhiyun 			*(u16 *)&payload[2] =
934*4882a593Smuzhiyun 				cpu_to_le16(MWIFIEX_TYPE_AGGR_DATA_V2);
935*4882a593Smuzhiyun 		}
936*4882a593Smuzhiyun 
937*4882a593Smuzhiyun 		if (!is_txinfo_set) {
938*4882a593Smuzhiyun 			tx_info->bss_num = MWIFIEX_SKB_TXCB(skb_tmp)->bss_num;
939*4882a593Smuzhiyun 			tx_info->bss_type = MWIFIEX_SKB_TXCB(skb_tmp)->bss_type;
940*4882a593Smuzhiyun 			is_txinfo_set = true;
941*4882a593Smuzhiyun 		}
942*4882a593Smuzhiyun 
943*4882a593Smuzhiyun 		port->tx_aggr.aggr_num--;
944*4882a593Smuzhiyun 		port->tx_aggr.aggr_len -= (skb_tmp->len + pad);
945*4882a593Smuzhiyun 		mwifiex_write_data_complete(adapter, skb_tmp, 0, 0);
946*4882a593Smuzhiyun 	}
947*4882a593Smuzhiyun 
948*4882a593Smuzhiyun 	tx_info->pkt_len = skb_aggr->len -
949*4882a593Smuzhiyun 			(sizeof(struct txpd) + adapter->intf_hdr_len);
950*4882a593Smuzhiyun 	tx_info->flags |= MWIFIEX_BUF_FLAG_AGGR_PKT;
951*4882a593Smuzhiyun 
952*4882a593Smuzhiyun 	port->tx_aggr.aggr_num = 0;
953*4882a593Smuzhiyun 	port->tx_aggr.aggr_len = 0;
954*4882a593Smuzhiyun 	*skb_send = skb_aggr;
955*4882a593Smuzhiyun 
956*4882a593Smuzhiyun 	return 0;
957*4882a593Smuzhiyun }
958*4882a593Smuzhiyun 
959*4882a593Smuzhiyun /* This function prepare data packet to be send under usb tx aggregation
960*4882a593Smuzhiyun  * protocol, check current usb aggregation status, link packet to aggrgation
961*4882a593Smuzhiyun  * list if possible, work flow as below:
962*4882a593Smuzhiyun  * (1) if only 1 packet available, add usb tx aggregation header and send.
963*4882a593Smuzhiyun  * (2) if packet is able to aggregated, link it to current aggregation list.
964*4882a593Smuzhiyun  * (3) if packet is not able to aggregated, aggregate and send exist packets
965*4882a593Smuzhiyun  *     in aggrgation list. Then, link packet in the list if there is more
966*4882a593Smuzhiyun  *     packet in transmit queue, otherwise try to transmit single packet.
967*4882a593Smuzhiyun  */
mwifiex_usb_aggr_tx_data(struct mwifiex_adapter * adapter,u8 ep,struct sk_buff * skb,struct mwifiex_tx_param * tx_param,struct usb_tx_data_port * port)968*4882a593Smuzhiyun static int mwifiex_usb_aggr_tx_data(struct mwifiex_adapter *adapter, u8 ep,
969*4882a593Smuzhiyun 				    struct sk_buff *skb,
970*4882a593Smuzhiyun 				    struct mwifiex_tx_param *tx_param,
971*4882a593Smuzhiyun 				    struct usb_tx_data_port *port)
972*4882a593Smuzhiyun {
973*4882a593Smuzhiyun 	u8 *payload, pad;
974*4882a593Smuzhiyun 	u16 align = adapter->bus_aggr.tx_aggr_align;
975*4882a593Smuzhiyun 	struct sk_buff *skb_send = NULL;
976*4882a593Smuzhiyun 	struct urb_context *context = NULL;
977*4882a593Smuzhiyun 	struct txpd *local_tx_pd =
978*4882a593Smuzhiyun 		(struct txpd *)((u8 *)skb->data + adapter->intf_hdr_len);
979*4882a593Smuzhiyun 	u8 f_send_aggr_buf = 0;
980*4882a593Smuzhiyun 	u8 f_send_cur_buf = 0;
981*4882a593Smuzhiyun 	u8 f_precopy_cur_buf = 0;
982*4882a593Smuzhiyun 	u8 f_postcopy_cur_buf = 0;
983*4882a593Smuzhiyun 	u32 timeout;
984*4882a593Smuzhiyun 	int ret;
985*4882a593Smuzhiyun 
986*4882a593Smuzhiyun 	/* padding to ensure each packet alginment */
987*4882a593Smuzhiyun 	pad = (align - (skb->len & (align - 1))) % align;
988*4882a593Smuzhiyun 
989*4882a593Smuzhiyun 	if (tx_param && tx_param->next_pkt_len) {
990*4882a593Smuzhiyun 		/* next packet available in tx queue*/
991*4882a593Smuzhiyun 		if (port->tx_aggr.aggr_len + skb->len + pad >
992*4882a593Smuzhiyun 		    adapter->bus_aggr.tx_aggr_max_size) {
993*4882a593Smuzhiyun 			f_send_aggr_buf = 1;
994*4882a593Smuzhiyun 			f_postcopy_cur_buf = 1;
995*4882a593Smuzhiyun 		} else {
996*4882a593Smuzhiyun 			/* current packet could be aggregated*/
997*4882a593Smuzhiyun 			f_precopy_cur_buf = 1;
998*4882a593Smuzhiyun 
999*4882a593Smuzhiyun 			if (port->tx_aggr.aggr_len + skb->len + pad +
1000*4882a593Smuzhiyun 			    tx_param->next_pkt_len >
1001*4882a593Smuzhiyun 			    adapter->bus_aggr.tx_aggr_max_size ||
1002*4882a593Smuzhiyun 			    port->tx_aggr.aggr_num + 2 >
1003*4882a593Smuzhiyun 			    adapter->bus_aggr.tx_aggr_max_num) {
1004*4882a593Smuzhiyun 			    /* next packet could not be aggregated
1005*4882a593Smuzhiyun 			     * send current aggregation buffer
1006*4882a593Smuzhiyun 			     */
1007*4882a593Smuzhiyun 				f_send_aggr_buf = 1;
1008*4882a593Smuzhiyun 			}
1009*4882a593Smuzhiyun 		}
1010*4882a593Smuzhiyun 	} else {
1011*4882a593Smuzhiyun 		/* last packet in tx queue */
1012*4882a593Smuzhiyun 		if (port->tx_aggr.aggr_num > 0) {
1013*4882a593Smuzhiyun 			/* pending packets in aggregation buffer*/
1014*4882a593Smuzhiyun 			if (port->tx_aggr.aggr_len + skb->len + pad >
1015*4882a593Smuzhiyun 			    adapter->bus_aggr.tx_aggr_max_size) {
1016*4882a593Smuzhiyun 				/* current packet not be able to aggregated,
1017*4882a593Smuzhiyun 				 * send aggr buffer first, then send packet.
1018*4882a593Smuzhiyun 				 */
1019*4882a593Smuzhiyun 				f_send_cur_buf = 1;
1020*4882a593Smuzhiyun 			} else {
1021*4882a593Smuzhiyun 				/* last packet, Aggregation and send */
1022*4882a593Smuzhiyun 				f_precopy_cur_buf = 1;
1023*4882a593Smuzhiyun 			}
1024*4882a593Smuzhiyun 
1025*4882a593Smuzhiyun 			f_send_aggr_buf = 1;
1026*4882a593Smuzhiyun 		} else {
1027*4882a593Smuzhiyun 			/* no pending packets in aggregation buffer,
1028*4882a593Smuzhiyun 			 * send current packet immediately
1029*4882a593Smuzhiyun 			 */
1030*4882a593Smuzhiyun 			 f_send_cur_buf = 1;
1031*4882a593Smuzhiyun 		}
1032*4882a593Smuzhiyun 	}
1033*4882a593Smuzhiyun 
1034*4882a593Smuzhiyun 	if (local_tx_pd->flags & MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET) {
1035*4882a593Smuzhiyun 		/* Send NULL packet immediately*/
1036*4882a593Smuzhiyun 		if (f_precopy_cur_buf) {
1037*4882a593Smuzhiyun 			if (skb_queue_empty(&port->tx_aggr.aggr_list)) {
1038*4882a593Smuzhiyun 				f_precopy_cur_buf = 0;
1039*4882a593Smuzhiyun 				f_send_aggr_buf = 0;
1040*4882a593Smuzhiyun 				f_send_cur_buf = 1;
1041*4882a593Smuzhiyun 			} else {
1042*4882a593Smuzhiyun 				f_send_aggr_buf = 1;
1043*4882a593Smuzhiyun 			}
1044*4882a593Smuzhiyun 		} else if (f_postcopy_cur_buf) {
1045*4882a593Smuzhiyun 			f_send_cur_buf = 1;
1046*4882a593Smuzhiyun 			f_postcopy_cur_buf = 0;
1047*4882a593Smuzhiyun 		}
1048*4882a593Smuzhiyun 	}
1049*4882a593Smuzhiyun 
1050*4882a593Smuzhiyun 	if (f_precopy_cur_buf) {
1051*4882a593Smuzhiyun 		skb_queue_tail(&port->tx_aggr.aggr_list, skb);
1052*4882a593Smuzhiyun 		port->tx_aggr.aggr_len += (skb->len + pad);
1053*4882a593Smuzhiyun 		port->tx_aggr.aggr_num++;
1054*4882a593Smuzhiyun 		if (f_send_aggr_buf)
1055*4882a593Smuzhiyun 			goto send_aggr_buf;
1056*4882a593Smuzhiyun 
1057*4882a593Smuzhiyun 		/* packet will not been send immediately,
1058*4882a593Smuzhiyun 		 * set a timer to make sure it will be sent under
1059*4882a593Smuzhiyun 		 * strict time limit. Dynamically fit the timeout
1060*4882a593Smuzhiyun 		 * value, according to packets number in aggr_list
1061*4882a593Smuzhiyun 		 */
1062*4882a593Smuzhiyun 		if (!port->tx_aggr.timer_cnxt.is_hold_timer_set) {
1063*4882a593Smuzhiyun 			port->tx_aggr.timer_cnxt.hold_tmo_msecs =
1064*4882a593Smuzhiyun 					MWIFIEX_USB_TX_AGGR_TMO_MIN;
1065*4882a593Smuzhiyun 			timeout =
1066*4882a593Smuzhiyun 				port->tx_aggr.timer_cnxt.hold_tmo_msecs;
1067*4882a593Smuzhiyun 			mod_timer(&port->tx_aggr.timer_cnxt.hold_timer,
1068*4882a593Smuzhiyun 				  jiffies + msecs_to_jiffies(timeout));
1069*4882a593Smuzhiyun 			port->tx_aggr.timer_cnxt.is_hold_timer_set = true;
1070*4882a593Smuzhiyun 		} else {
1071*4882a593Smuzhiyun 			if (port->tx_aggr.timer_cnxt.hold_tmo_msecs <
1072*4882a593Smuzhiyun 			    MWIFIEX_USB_TX_AGGR_TMO_MAX) {
1073*4882a593Smuzhiyun 				/* Dyanmic fit timeout */
1074*4882a593Smuzhiyun 				timeout =
1075*4882a593Smuzhiyun 				++port->tx_aggr.timer_cnxt.hold_tmo_msecs;
1076*4882a593Smuzhiyun 				mod_timer(&port->tx_aggr.timer_cnxt.hold_timer,
1077*4882a593Smuzhiyun 					  jiffies + msecs_to_jiffies(timeout));
1078*4882a593Smuzhiyun 			}
1079*4882a593Smuzhiyun 		}
1080*4882a593Smuzhiyun 	}
1081*4882a593Smuzhiyun 
1082*4882a593Smuzhiyun send_aggr_buf:
1083*4882a593Smuzhiyun 	if (f_send_aggr_buf) {
1084*4882a593Smuzhiyun 		ret = mwifiex_usb_prepare_tx_aggr_skb(adapter, port, &skb_send);
1085*4882a593Smuzhiyun 		if (!ret) {
1086*4882a593Smuzhiyun 			context = &port->tx_data_list[port->tx_data_ix++];
1087*4882a593Smuzhiyun 			ret = mwifiex_usb_construct_send_urb(adapter, port, ep,
1088*4882a593Smuzhiyun 							     context, skb_send);
1089*4882a593Smuzhiyun 			if (ret == -1)
1090*4882a593Smuzhiyun 				mwifiex_write_data_complete(adapter, skb_send,
1091*4882a593Smuzhiyun 							    0, -1);
1092*4882a593Smuzhiyun 		}
1093*4882a593Smuzhiyun 	}
1094*4882a593Smuzhiyun 
1095*4882a593Smuzhiyun 	if (f_send_cur_buf) {
1096*4882a593Smuzhiyun 		if (f_send_aggr_buf) {
1097*4882a593Smuzhiyun 			if (atomic_read(&port->tx_data_urb_pending) >=
1098*4882a593Smuzhiyun 			    MWIFIEX_TX_DATA_URB) {
1099*4882a593Smuzhiyun 				port->block_status = true;
1100*4882a593Smuzhiyun 				adapter->data_sent =
1101*4882a593Smuzhiyun 					mwifiex_usb_data_sent(adapter);
1102*4882a593Smuzhiyun 				/* no available urb, postcopy packet*/
1103*4882a593Smuzhiyun 				f_postcopy_cur_buf = 1;
1104*4882a593Smuzhiyun 				goto postcopy_cur_buf;
1105*4882a593Smuzhiyun 			}
1106*4882a593Smuzhiyun 
1107*4882a593Smuzhiyun 			if (port->tx_data_ix >= MWIFIEX_TX_DATA_URB)
1108*4882a593Smuzhiyun 				port->tx_data_ix = 0;
1109*4882a593Smuzhiyun 		}
1110*4882a593Smuzhiyun 
1111*4882a593Smuzhiyun 		payload = skb->data;
1112*4882a593Smuzhiyun 		*(u16 *)&payload[2] =
1113*4882a593Smuzhiyun 			cpu_to_le16(MWIFIEX_TYPE_AGGR_DATA_V2 | 0x80);
1114*4882a593Smuzhiyun 		*(u16 *)payload = cpu_to_le16(skb->len);
1115*4882a593Smuzhiyun 		skb_send = skb;
1116*4882a593Smuzhiyun 		context = &port->tx_data_list[port->tx_data_ix++];
1117*4882a593Smuzhiyun 		return mwifiex_usb_construct_send_urb(adapter, port, ep,
1118*4882a593Smuzhiyun 						      context, skb_send);
1119*4882a593Smuzhiyun 	}
1120*4882a593Smuzhiyun 
1121*4882a593Smuzhiyun postcopy_cur_buf:
1122*4882a593Smuzhiyun 	if (f_postcopy_cur_buf) {
1123*4882a593Smuzhiyun 		skb_queue_tail(&port->tx_aggr.aggr_list, skb);
1124*4882a593Smuzhiyun 		port->tx_aggr.aggr_len += (skb->len + pad);
1125*4882a593Smuzhiyun 		port->tx_aggr.aggr_num++;
1126*4882a593Smuzhiyun 		/* New aggregation begin, start timer */
1127*4882a593Smuzhiyun 		if (!port->tx_aggr.timer_cnxt.is_hold_timer_set) {
1128*4882a593Smuzhiyun 			port->tx_aggr.timer_cnxt.hold_tmo_msecs =
1129*4882a593Smuzhiyun 					MWIFIEX_USB_TX_AGGR_TMO_MIN;
1130*4882a593Smuzhiyun 			timeout = port->tx_aggr.timer_cnxt.hold_tmo_msecs;
1131*4882a593Smuzhiyun 			mod_timer(&port->tx_aggr.timer_cnxt.hold_timer,
1132*4882a593Smuzhiyun 				  jiffies + msecs_to_jiffies(timeout));
1133*4882a593Smuzhiyun 			port->tx_aggr.timer_cnxt.is_hold_timer_set = true;
1134*4882a593Smuzhiyun 		}
1135*4882a593Smuzhiyun 	}
1136*4882a593Smuzhiyun 
1137*4882a593Smuzhiyun 	return -EINPROGRESS;
1138*4882a593Smuzhiyun }
1139*4882a593Smuzhiyun 
mwifiex_usb_tx_aggr_tmo(struct timer_list * t)1140*4882a593Smuzhiyun static void mwifiex_usb_tx_aggr_tmo(struct timer_list *t)
1141*4882a593Smuzhiyun {
1142*4882a593Smuzhiyun 	struct urb_context *urb_cnxt = NULL;
1143*4882a593Smuzhiyun 	struct sk_buff *skb_send = NULL;
1144*4882a593Smuzhiyun 	struct tx_aggr_tmr_cnxt *timer_context =
1145*4882a593Smuzhiyun 		from_timer(timer_context, t, hold_timer);
1146*4882a593Smuzhiyun 	struct mwifiex_adapter *adapter = timer_context->adapter;
1147*4882a593Smuzhiyun 	struct usb_tx_data_port *port = timer_context->port;
1148*4882a593Smuzhiyun 	int err = 0;
1149*4882a593Smuzhiyun 
1150*4882a593Smuzhiyun 	spin_lock_bh(&port->tx_aggr_lock);
1151*4882a593Smuzhiyun 	err = mwifiex_usb_prepare_tx_aggr_skb(adapter, port, &skb_send);
1152*4882a593Smuzhiyun 	if (err) {
1153*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
1154*4882a593Smuzhiyun 			    "prepare tx aggr skb failed, err=%d\n", err);
1155*4882a593Smuzhiyun 		goto unlock;
1156*4882a593Smuzhiyun 	}
1157*4882a593Smuzhiyun 
1158*4882a593Smuzhiyun 	if (atomic_read(&port->tx_data_urb_pending) >=
1159*4882a593Smuzhiyun 	    MWIFIEX_TX_DATA_URB) {
1160*4882a593Smuzhiyun 		port->block_status = true;
1161*4882a593Smuzhiyun 		adapter->data_sent =
1162*4882a593Smuzhiyun 			mwifiex_usb_data_sent(adapter);
1163*4882a593Smuzhiyun 		err = -1;
1164*4882a593Smuzhiyun 		goto done;
1165*4882a593Smuzhiyun 	}
1166*4882a593Smuzhiyun 
1167*4882a593Smuzhiyun 	if (port->tx_data_ix >= MWIFIEX_TX_DATA_URB)
1168*4882a593Smuzhiyun 		port->tx_data_ix = 0;
1169*4882a593Smuzhiyun 
1170*4882a593Smuzhiyun 	urb_cnxt = &port->tx_data_list[port->tx_data_ix++];
1171*4882a593Smuzhiyun 	err = mwifiex_usb_construct_send_urb(adapter, port, port->tx_data_ep,
1172*4882a593Smuzhiyun 					     urb_cnxt, skb_send);
1173*4882a593Smuzhiyun done:
1174*4882a593Smuzhiyun 	if (err == -1)
1175*4882a593Smuzhiyun 		mwifiex_write_data_complete(adapter, skb_send, 0, -1);
1176*4882a593Smuzhiyun unlock:
1177*4882a593Smuzhiyun 	spin_unlock_bh(&port->tx_aggr_lock);
1178*4882a593Smuzhiyun }
1179*4882a593Smuzhiyun 
1180*4882a593Smuzhiyun /* This function write a command/data packet to card. */
mwifiex_usb_host_to_card(struct mwifiex_adapter * adapter,u8 ep,struct sk_buff * skb,struct mwifiex_tx_param * tx_param)1181*4882a593Smuzhiyun static int mwifiex_usb_host_to_card(struct mwifiex_adapter *adapter, u8 ep,
1182*4882a593Smuzhiyun 				    struct sk_buff *skb,
1183*4882a593Smuzhiyun 				    struct mwifiex_tx_param *tx_param)
1184*4882a593Smuzhiyun {
1185*4882a593Smuzhiyun 	struct usb_card_rec *card = adapter->card;
1186*4882a593Smuzhiyun 	struct urb_context *context = NULL;
1187*4882a593Smuzhiyun 	struct usb_tx_data_port *port = NULL;
1188*4882a593Smuzhiyun 	int idx, ret;
1189*4882a593Smuzhiyun 
1190*4882a593Smuzhiyun 	if (test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
1191*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
1192*4882a593Smuzhiyun 			    "%s: not allowed while suspended\n", __func__);
1193*4882a593Smuzhiyun 		return -1;
1194*4882a593Smuzhiyun 	}
1195*4882a593Smuzhiyun 
1196*4882a593Smuzhiyun 	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags)) {
1197*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR, "%s: device removed\n", __func__);
1198*4882a593Smuzhiyun 		return -1;
1199*4882a593Smuzhiyun 	}
1200*4882a593Smuzhiyun 
1201*4882a593Smuzhiyun 	mwifiex_dbg(adapter, INFO, "%s: ep=%d\n", __func__, ep);
1202*4882a593Smuzhiyun 
1203*4882a593Smuzhiyun 	if (ep == card->tx_cmd_ep) {
1204*4882a593Smuzhiyun 		context = &card->tx_cmd;
1205*4882a593Smuzhiyun 	} else {
1206*4882a593Smuzhiyun 		/* get the data port structure for endpoint */
1207*4882a593Smuzhiyun 		for (idx = 0; idx < MWIFIEX_TX_DATA_PORT; idx++) {
1208*4882a593Smuzhiyun 			if (ep == card->port[idx].tx_data_ep) {
1209*4882a593Smuzhiyun 				port = &card->port[idx];
1210*4882a593Smuzhiyun 				if (atomic_read(&port->tx_data_urb_pending)
1211*4882a593Smuzhiyun 				    >= MWIFIEX_TX_DATA_URB) {
1212*4882a593Smuzhiyun 					port->block_status = true;
1213*4882a593Smuzhiyun 					adapter->data_sent =
1214*4882a593Smuzhiyun 						mwifiex_usb_data_sent(adapter);
1215*4882a593Smuzhiyun 					return -EBUSY;
1216*4882a593Smuzhiyun 				}
1217*4882a593Smuzhiyun 				if (port->tx_data_ix >= MWIFIEX_TX_DATA_URB)
1218*4882a593Smuzhiyun 					port->tx_data_ix = 0;
1219*4882a593Smuzhiyun 				break;
1220*4882a593Smuzhiyun 			}
1221*4882a593Smuzhiyun 		}
1222*4882a593Smuzhiyun 
1223*4882a593Smuzhiyun 		if (!port) {
1224*4882a593Smuzhiyun 			mwifiex_dbg(adapter, ERROR, "Wrong usb tx data port\n");
1225*4882a593Smuzhiyun 			return -1;
1226*4882a593Smuzhiyun 		}
1227*4882a593Smuzhiyun 
1228*4882a593Smuzhiyun 		if (adapter->bus_aggr.enable) {
1229*4882a593Smuzhiyun 			spin_lock_bh(&port->tx_aggr_lock);
1230*4882a593Smuzhiyun 			ret =  mwifiex_usb_aggr_tx_data(adapter, ep, skb,
1231*4882a593Smuzhiyun 							tx_param, port);
1232*4882a593Smuzhiyun 			spin_unlock_bh(&port->tx_aggr_lock);
1233*4882a593Smuzhiyun 			return ret;
1234*4882a593Smuzhiyun 		}
1235*4882a593Smuzhiyun 
1236*4882a593Smuzhiyun 		context = &port->tx_data_list[port->tx_data_ix++];
1237*4882a593Smuzhiyun 	}
1238*4882a593Smuzhiyun 
1239*4882a593Smuzhiyun 	return mwifiex_usb_construct_send_urb(adapter, port, ep, context, skb);
1240*4882a593Smuzhiyun }
1241*4882a593Smuzhiyun 
mwifiex_usb_tx_init(struct mwifiex_adapter * adapter)1242*4882a593Smuzhiyun static int mwifiex_usb_tx_init(struct mwifiex_adapter *adapter)
1243*4882a593Smuzhiyun {
1244*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
1245*4882a593Smuzhiyun 	struct usb_tx_data_port *port;
1246*4882a593Smuzhiyun 	int i, j;
1247*4882a593Smuzhiyun 
1248*4882a593Smuzhiyun 	card->tx_cmd.adapter = adapter;
1249*4882a593Smuzhiyun 	card->tx_cmd.ep = card->tx_cmd_ep;
1250*4882a593Smuzhiyun 
1251*4882a593Smuzhiyun 	card->tx_cmd.urb = usb_alloc_urb(0, GFP_KERNEL);
1252*4882a593Smuzhiyun 	if (!card->tx_cmd.urb)
1253*4882a593Smuzhiyun 		return -ENOMEM;
1254*4882a593Smuzhiyun 
1255*4882a593Smuzhiyun 	for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
1256*4882a593Smuzhiyun 		port = &card->port[i];
1257*4882a593Smuzhiyun 		if (!port->tx_data_ep)
1258*4882a593Smuzhiyun 			continue;
1259*4882a593Smuzhiyun 		port->tx_data_ix = 0;
1260*4882a593Smuzhiyun 		skb_queue_head_init(&port->tx_aggr.aggr_list);
1261*4882a593Smuzhiyun 		if (port->tx_data_ep == MWIFIEX_USB_EP_DATA)
1262*4882a593Smuzhiyun 			port->block_status = false;
1263*4882a593Smuzhiyun 		else
1264*4882a593Smuzhiyun 			port->block_status = true;
1265*4882a593Smuzhiyun 		for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
1266*4882a593Smuzhiyun 			port->tx_data_list[j].adapter = adapter;
1267*4882a593Smuzhiyun 			port->tx_data_list[j].ep = port->tx_data_ep;
1268*4882a593Smuzhiyun 			port->tx_data_list[j].urb =
1269*4882a593Smuzhiyun 					usb_alloc_urb(0, GFP_KERNEL);
1270*4882a593Smuzhiyun 			if (!port->tx_data_list[j].urb)
1271*4882a593Smuzhiyun 				return -ENOMEM;
1272*4882a593Smuzhiyun 		}
1273*4882a593Smuzhiyun 
1274*4882a593Smuzhiyun 		port->tx_aggr.timer_cnxt.adapter = adapter;
1275*4882a593Smuzhiyun 		port->tx_aggr.timer_cnxt.port = port;
1276*4882a593Smuzhiyun 		port->tx_aggr.timer_cnxt.is_hold_timer_set = false;
1277*4882a593Smuzhiyun 		port->tx_aggr.timer_cnxt.hold_tmo_msecs = 0;
1278*4882a593Smuzhiyun 		timer_setup(&port->tx_aggr.timer_cnxt.hold_timer,
1279*4882a593Smuzhiyun 			    mwifiex_usb_tx_aggr_tmo, 0);
1280*4882a593Smuzhiyun 	}
1281*4882a593Smuzhiyun 
1282*4882a593Smuzhiyun 	return 0;
1283*4882a593Smuzhiyun }
1284*4882a593Smuzhiyun 
mwifiex_usb_rx_init(struct mwifiex_adapter * adapter)1285*4882a593Smuzhiyun static int mwifiex_usb_rx_init(struct mwifiex_adapter *adapter)
1286*4882a593Smuzhiyun {
1287*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
1288*4882a593Smuzhiyun 	int i;
1289*4882a593Smuzhiyun 
1290*4882a593Smuzhiyun 	card->rx_cmd.adapter = adapter;
1291*4882a593Smuzhiyun 	card->rx_cmd.ep = card->rx_cmd_ep;
1292*4882a593Smuzhiyun 
1293*4882a593Smuzhiyun 	card->rx_cmd.urb = usb_alloc_urb(0, GFP_KERNEL);
1294*4882a593Smuzhiyun 	if (!card->rx_cmd.urb)
1295*4882a593Smuzhiyun 		return -ENOMEM;
1296*4882a593Smuzhiyun 
1297*4882a593Smuzhiyun 	card->rx_cmd.skb = dev_alloc_skb(MWIFIEX_RX_CMD_BUF_SIZE);
1298*4882a593Smuzhiyun 	if (!card->rx_cmd.skb)
1299*4882a593Smuzhiyun 		return -ENOMEM;
1300*4882a593Smuzhiyun 
1301*4882a593Smuzhiyun 	if (mwifiex_usb_submit_rx_urb(&card->rx_cmd, MWIFIEX_RX_CMD_BUF_SIZE))
1302*4882a593Smuzhiyun 		return -1;
1303*4882a593Smuzhiyun 
1304*4882a593Smuzhiyun 	for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
1305*4882a593Smuzhiyun 		card->rx_data_list[i].adapter = adapter;
1306*4882a593Smuzhiyun 		card->rx_data_list[i].ep = card->rx_data_ep;
1307*4882a593Smuzhiyun 
1308*4882a593Smuzhiyun 		card->rx_data_list[i].urb = usb_alloc_urb(0, GFP_KERNEL);
1309*4882a593Smuzhiyun 		if (!card->rx_data_list[i].urb)
1310*4882a593Smuzhiyun 			return -1;
1311*4882a593Smuzhiyun 		if (mwifiex_usb_submit_rx_urb(&card->rx_data_list[i],
1312*4882a593Smuzhiyun 					      MWIFIEX_RX_DATA_BUF_SIZE))
1313*4882a593Smuzhiyun 			return -1;
1314*4882a593Smuzhiyun 	}
1315*4882a593Smuzhiyun 
1316*4882a593Smuzhiyun 	return 0;
1317*4882a593Smuzhiyun }
1318*4882a593Smuzhiyun 
1319*4882a593Smuzhiyun /* This function register usb device and initialize parameter. */
mwifiex_register_dev(struct mwifiex_adapter * adapter)1320*4882a593Smuzhiyun static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
1321*4882a593Smuzhiyun {
1322*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
1323*4882a593Smuzhiyun 
1324*4882a593Smuzhiyun 	card->adapter = adapter;
1325*4882a593Smuzhiyun 
1326*4882a593Smuzhiyun 	switch (le16_to_cpu(card->udev->descriptor.idProduct)) {
1327*4882a593Smuzhiyun 	case USB8997_PID_1:
1328*4882a593Smuzhiyun 	case USB8997_PID_2:
1329*4882a593Smuzhiyun 		adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
1330*4882a593Smuzhiyun 		strcpy(adapter->fw_name, USB8997_DEFAULT_FW_NAME);
1331*4882a593Smuzhiyun 		adapter->ext_scan = true;
1332*4882a593Smuzhiyun 		break;
1333*4882a593Smuzhiyun 	case USB8766_PID_1:
1334*4882a593Smuzhiyun 	case USB8766_PID_2:
1335*4882a593Smuzhiyun 		adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
1336*4882a593Smuzhiyun 		strcpy(adapter->fw_name, USB8766_DEFAULT_FW_NAME);
1337*4882a593Smuzhiyun 		adapter->ext_scan = true;
1338*4882a593Smuzhiyun 		break;
1339*4882a593Smuzhiyun 	case USB8801_PID_1:
1340*4882a593Smuzhiyun 	case USB8801_PID_2:
1341*4882a593Smuzhiyun 		adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
1342*4882a593Smuzhiyun 		strcpy(adapter->fw_name, USB8801_DEFAULT_FW_NAME);
1343*4882a593Smuzhiyun 		adapter->ext_scan = false;
1344*4882a593Smuzhiyun 		break;
1345*4882a593Smuzhiyun 	case USB8797_PID_1:
1346*4882a593Smuzhiyun 	case USB8797_PID_2:
1347*4882a593Smuzhiyun 	default:
1348*4882a593Smuzhiyun 		adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
1349*4882a593Smuzhiyun 		strcpy(adapter->fw_name, USB8797_DEFAULT_FW_NAME);
1350*4882a593Smuzhiyun 		break;
1351*4882a593Smuzhiyun 	}
1352*4882a593Smuzhiyun 
1353*4882a593Smuzhiyun 	adapter->usb_mc_status = false;
1354*4882a593Smuzhiyun 	adapter->usb_mc_setup = false;
1355*4882a593Smuzhiyun 
1356*4882a593Smuzhiyun 	return 0;
1357*4882a593Smuzhiyun }
1358*4882a593Smuzhiyun 
mwifiex_usb_cleanup_tx_aggr(struct mwifiex_adapter * adapter)1359*4882a593Smuzhiyun static void mwifiex_usb_cleanup_tx_aggr(struct mwifiex_adapter *adapter)
1360*4882a593Smuzhiyun {
1361*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
1362*4882a593Smuzhiyun 	struct usb_tx_data_port *port;
1363*4882a593Smuzhiyun 	struct sk_buff *skb_tmp;
1364*4882a593Smuzhiyun 	int idx;
1365*4882a593Smuzhiyun 
1366*4882a593Smuzhiyun 	for (idx = 0; idx < MWIFIEX_TX_DATA_PORT; idx++) {
1367*4882a593Smuzhiyun 		port = &card->port[idx];
1368*4882a593Smuzhiyun 		if (adapter->bus_aggr.enable)
1369*4882a593Smuzhiyun 			while ((skb_tmp =
1370*4882a593Smuzhiyun 				skb_dequeue(&port->tx_aggr.aggr_list)))
1371*4882a593Smuzhiyun 				mwifiex_write_data_complete(adapter, skb_tmp,
1372*4882a593Smuzhiyun 							    0, -1);
1373*4882a593Smuzhiyun 		if (port->tx_aggr.timer_cnxt.hold_timer.function)
1374*4882a593Smuzhiyun 			del_timer_sync(&port->tx_aggr.timer_cnxt.hold_timer);
1375*4882a593Smuzhiyun 		port->tx_aggr.timer_cnxt.is_hold_timer_set = false;
1376*4882a593Smuzhiyun 		port->tx_aggr.timer_cnxt.hold_tmo_msecs = 0;
1377*4882a593Smuzhiyun 	}
1378*4882a593Smuzhiyun }
1379*4882a593Smuzhiyun 
mwifiex_unregister_dev(struct mwifiex_adapter * adapter)1380*4882a593Smuzhiyun static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
1381*4882a593Smuzhiyun {
1382*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
1383*4882a593Smuzhiyun 
1384*4882a593Smuzhiyun 	mwifiex_usb_free(card);
1385*4882a593Smuzhiyun 
1386*4882a593Smuzhiyun 	mwifiex_usb_cleanup_tx_aggr(adapter);
1387*4882a593Smuzhiyun 
1388*4882a593Smuzhiyun 	card->adapter = NULL;
1389*4882a593Smuzhiyun }
1390*4882a593Smuzhiyun 
mwifiex_prog_fw_w_helper(struct mwifiex_adapter * adapter,struct mwifiex_fw_image * fw)1391*4882a593Smuzhiyun static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1392*4882a593Smuzhiyun 				    struct mwifiex_fw_image *fw)
1393*4882a593Smuzhiyun {
1394*4882a593Smuzhiyun 	int ret = 0;
1395*4882a593Smuzhiyun 	u8 *firmware = fw->fw_buf, *recv_buff;
1396*4882a593Smuzhiyun 	u32 retries = USB8XXX_FW_MAX_RETRY + 1;
1397*4882a593Smuzhiyun 	u32 dlen;
1398*4882a593Smuzhiyun 	u32 fw_seqnum = 0, tlen = 0, dnld_cmd = 0;
1399*4882a593Smuzhiyun 	struct fw_data *fwdata;
1400*4882a593Smuzhiyun 	struct fw_sync_header sync_fw;
1401*4882a593Smuzhiyun 	u8 check_winner = 1;
1402*4882a593Smuzhiyun 
1403*4882a593Smuzhiyun 	if (!firmware) {
1404*4882a593Smuzhiyun 		mwifiex_dbg(adapter, ERROR,
1405*4882a593Smuzhiyun 			    "No firmware image found! Terminating download\n");
1406*4882a593Smuzhiyun 		ret = -1;
1407*4882a593Smuzhiyun 		goto fw_exit;
1408*4882a593Smuzhiyun 	}
1409*4882a593Smuzhiyun 
1410*4882a593Smuzhiyun 	/* Allocate memory for transmit */
1411*4882a593Smuzhiyun 	fwdata = kzalloc(FW_DNLD_TX_BUF_SIZE, GFP_KERNEL);
1412*4882a593Smuzhiyun 	if (!fwdata) {
1413*4882a593Smuzhiyun 		ret = -ENOMEM;
1414*4882a593Smuzhiyun 		goto fw_exit;
1415*4882a593Smuzhiyun 	}
1416*4882a593Smuzhiyun 
1417*4882a593Smuzhiyun 	/* Allocate memory for receive */
1418*4882a593Smuzhiyun 	recv_buff = kzalloc(FW_DNLD_RX_BUF_SIZE, GFP_KERNEL);
1419*4882a593Smuzhiyun 	if (!recv_buff) {
1420*4882a593Smuzhiyun 		ret = -ENOMEM;
1421*4882a593Smuzhiyun 		goto cleanup;
1422*4882a593Smuzhiyun 	}
1423*4882a593Smuzhiyun 
1424*4882a593Smuzhiyun 	do {
1425*4882a593Smuzhiyun 		/* Send pseudo data to check winner status first */
1426*4882a593Smuzhiyun 		if (check_winner) {
1427*4882a593Smuzhiyun 			memset(&fwdata->fw_hdr, 0, sizeof(struct fw_header));
1428*4882a593Smuzhiyun 			dlen = 0;
1429*4882a593Smuzhiyun 		} else {
1430*4882a593Smuzhiyun 			/* copy the header of the fw_data to get the length */
1431*4882a593Smuzhiyun 			memcpy(&fwdata->fw_hdr, &firmware[tlen],
1432*4882a593Smuzhiyun 			       sizeof(struct fw_header));
1433*4882a593Smuzhiyun 
1434*4882a593Smuzhiyun 			dlen = le32_to_cpu(fwdata->fw_hdr.data_len);
1435*4882a593Smuzhiyun 			dnld_cmd = le32_to_cpu(fwdata->fw_hdr.dnld_cmd);
1436*4882a593Smuzhiyun 			tlen += sizeof(struct fw_header);
1437*4882a593Smuzhiyun 
1438*4882a593Smuzhiyun 			/* Command 7 doesn't have data length field */
1439*4882a593Smuzhiyun 			if (dnld_cmd == FW_CMD_7)
1440*4882a593Smuzhiyun 				dlen = 0;
1441*4882a593Smuzhiyun 
1442*4882a593Smuzhiyun 			memcpy(fwdata->data, &firmware[tlen], dlen);
1443*4882a593Smuzhiyun 
1444*4882a593Smuzhiyun 			fwdata->seq_num = cpu_to_le32(fw_seqnum);
1445*4882a593Smuzhiyun 			tlen += dlen;
1446*4882a593Smuzhiyun 		}
1447*4882a593Smuzhiyun 
1448*4882a593Smuzhiyun 		/* If the send/receive fails or CRC occurs then retry */
1449*4882a593Smuzhiyun 		while (--retries) {
1450*4882a593Smuzhiyun 			u8 *buf = (u8 *)fwdata;
1451*4882a593Smuzhiyun 			u32 len = FW_DATA_XMIT_SIZE;
1452*4882a593Smuzhiyun 
1453*4882a593Smuzhiyun 			/* send the firmware block */
1454*4882a593Smuzhiyun 			ret = mwifiex_write_data_sync(adapter, buf, &len,
1455*4882a593Smuzhiyun 						MWIFIEX_USB_EP_CMD_EVENT,
1456*4882a593Smuzhiyun 						MWIFIEX_USB_TIMEOUT);
1457*4882a593Smuzhiyun 			if (ret) {
1458*4882a593Smuzhiyun 				mwifiex_dbg(adapter, ERROR,
1459*4882a593Smuzhiyun 					    "write_data_sync: failed: %d\n",
1460*4882a593Smuzhiyun 					    ret);
1461*4882a593Smuzhiyun 				continue;
1462*4882a593Smuzhiyun 			}
1463*4882a593Smuzhiyun 
1464*4882a593Smuzhiyun 			buf = recv_buff;
1465*4882a593Smuzhiyun 			len = FW_DNLD_RX_BUF_SIZE;
1466*4882a593Smuzhiyun 
1467*4882a593Smuzhiyun 			/* Receive the firmware block response */
1468*4882a593Smuzhiyun 			ret = mwifiex_read_data_sync(adapter, buf, &len,
1469*4882a593Smuzhiyun 						MWIFIEX_USB_EP_CMD_EVENT,
1470*4882a593Smuzhiyun 						MWIFIEX_USB_TIMEOUT);
1471*4882a593Smuzhiyun 			if (ret) {
1472*4882a593Smuzhiyun 				mwifiex_dbg(adapter, ERROR,
1473*4882a593Smuzhiyun 					    "read_data_sync: failed: %d\n",
1474*4882a593Smuzhiyun 					    ret);
1475*4882a593Smuzhiyun 				continue;
1476*4882a593Smuzhiyun 			}
1477*4882a593Smuzhiyun 
1478*4882a593Smuzhiyun 			memcpy(&sync_fw, recv_buff,
1479*4882a593Smuzhiyun 			       sizeof(struct fw_sync_header));
1480*4882a593Smuzhiyun 
1481*4882a593Smuzhiyun 			/* check 1st firmware block resp for highest bit set */
1482*4882a593Smuzhiyun 			if (check_winner) {
1483*4882a593Smuzhiyun 				if (le32_to_cpu(sync_fw.cmd) & 0x80000000) {
1484*4882a593Smuzhiyun 					mwifiex_dbg(adapter, WARN,
1485*4882a593Smuzhiyun 						    "USB is not the winner %#x\n",
1486*4882a593Smuzhiyun 						    sync_fw.cmd);
1487*4882a593Smuzhiyun 
1488*4882a593Smuzhiyun 					/* returning success */
1489*4882a593Smuzhiyun 					ret = 0;
1490*4882a593Smuzhiyun 					goto cleanup;
1491*4882a593Smuzhiyun 				}
1492*4882a593Smuzhiyun 
1493*4882a593Smuzhiyun 				mwifiex_dbg(adapter, MSG,
1494*4882a593Smuzhiyun 					    "start to download FW...\n");
1495*4882a593Smuzhiyun 
1496*4882a593Smuzhiyun 				check_winner = 0;
1497*4882a593Smuzhiyun 				break;
1498*4882a593Smuzhiyun 			}
1499*4882a593Smuzhiyun 
1500*4882a593Smuzhiyun 			/* check the firmware block response for CRC errors */
1501*4882a593Smuzhiyun 			if (sync_fw.cmd) {
1502*4882a593Smuzhiyun 				mwifiex_dbg(adapter, ERROR,
1503*4882a593Smuzhiyun 					    "FW received block with CRC %#x\n",
1504*4882a593Smuzhiyun 					    sync_fw.cmd);
1505*4882a593Smuzhiyun 				ret = -1;
1506*4882a593Smuzhiyun 				continue;
1507*4882a593Smuzhiyun 			}
1508*4882a593Smuzhiyun 
1509*4882a593Smuzhiyun 			retries = USB8XXX_FW_MAX_RETRY + 1;
1510*4882a593Smuzhiyun 			break;
1511*4882a593Smuzhiyun 		}
1512*4882a593Smuzhiyun 		fw_seqnum++;
1513*4882a593Smuzhiyun 	} while ((dnld_cmd != FW_HAS_LAST_BLOCK) && retries);
1514*4882a593Smuzhiyun 
1515*4882a593Smuzhiyun cleanup:
1516*4882a593Smuzhiyun 	mwifiex_dbg(adapter, MSG,
1517*4882a593Smuzhiyun 		    "info: FW download over, size %d bytes\n", tlen);
1518*4882a593Smuzhiyun 
1519*4882a593Smuzhiyun 	kfree(recv_buff);
1520*4882a593Smuzhiyun 	kfree(fwdata);
1521*4882a593Smuzhiyun 
1522*4882a593Smuzhiyun 	if (retries)
1523*4882a593Smuzhiyun 		ret = 0;
1524*4882a593Smuzhiyun fw_exit:
1525*4882a593Smuzhiyun 	return ret;
1526*4882a593Smuzhiyun }
1527*4882a593Smuzhiyun 
mwifiex_usb_dnld_fw(struct mwifiex_adapter * adapter,struct mwifiex_fw_image * fw)1528*4882a593Smuzhiyun static int mwifiex_usb_dnld_fw(struct mwifiex_adapter *adapter,
1529*4882a593Smuzhiyun 			struct mwifiex_fw_image *fw)
1530*4882a593Smuzhiyun {
1531*4882a593Smuzhiyun 	int ret;
1532*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
1533*4882a593Smuzhiyun 
1534*4882a593Smuzhiyun 	if (card->usb_boot_state == USB8XXX_FW_DNLD) {
1535*4882a593Smuzhiyun 		ret = mwifiex_prog_fw_w_helper(adapter, fw);
1536*4882a593Smuzhiyun 		if (ret)
1537*4882a593Smuzhiyun 			return -1;
1538*4882a593Smuzhiyun 
1539*4882a593Smuzhiyun 		/* Boot state changes after successful firmware download */
1540*4882a593Smuzhiyun 		if (card->usb_boot_state == USB8XXX_FW_DNLD)
1541*4882a593Smuzhiyun 			return -1;
1542*4882a593Smuzhiyun 	}
1543*4882a593Smuzhiyun 
1544*4882a593Smuzhiyun 	ret = mwifiex_usb_rx_init(adapter);
1545*4882a593Smuzhiyun 	if (!ret)
1546*4882a593Smuzhiyun 		ret = mwifiex_usb_tx_init(adapter);
1547*4882a593Smuzhiyun 
1548*4882a593Smuzhiyun 	return ret;
1549*4882a593Smuzhiyun }
1550*4882a593Smuzhiyun 
mwifiex_submit_rx_urb(struct mwifiex_adapter * adapter,u8 ep)1551*4882a593Smuzhiyun static void mwifiex_submit_rx_urb(struct mwifiex_adapter *adapter, u8 ep)
1552*4882a593Smuzhiyun {
1553*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
1554*4882a593Smuzhiyun 
1555*4882a593Smuzhiyun 	skb_push(card->rx_cmd.skb, INTF_HEADER_LEN);
1556*4882a593Smuzhiyun 	if ((ep == card->rx_cmd_ep) &&
1557*4882a593Smuzhiyun 	    (!atomic_read(&card->rx_cmd_urb_pending)))
1558*4882a593Smuzhiyun 		mwifiex_usb_submit_rx_urb(&card->rx_cmd,
1559*4882a593Smuzhiyun 					  MWIFIEX_RX_CMD_BUF_SIZE);
1560*4882a593Smuzhiyun 
1561*4882a593Smuzhiyun 	return;
1562*4882a593Smuzhiyun }
1563*4882a593Smuzhiyun 
mwifiex_usb_cmd_event_complete(struct mwifiex_adapter * adapter,struct sk_buff * skb)1564*4882a593Smuzhiyun static int mwifiex_usb_cmd_event_complete(struct mwifiex_adapter *adapter,
1565*4882a593Smuzhiyun 				       struct sk_buff *skb)
1566*4882a593Smuzhiyun {
1567*4882a593Smuzhiyun 	mwifiex_submit_rx_urb(adapter, MWIFIEX_USB_EP_CMD_EVENT);
1568*4882a593Smuzhiyun 
1569*4882a593Smuzhiyun 	return 0;
1570*4882a593Smuzhiyun }
1571*4882a593Smuzhiyun 
1572*4882a593Smuzhiyun /* This function wakes up the card. */
mwifiex_pm_wakeup_card(struct mwifiex_adapter * adapter)1573*4882a593Smuzhiyun static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
1574*4882a593Smuzhiyun {
1575*4882a593Smuzhiyun 	/* Simulation of HS_AWAKE event */
1576*4882a593Smuzhiyun 	adapter->pm_wakeup_fw_try = false;
1577*4882a593Smuzhiyun 	del_timer(&adapter->wakeup_timer);
1578*4882a593Smuzhiyun 	adapter->pm_wakeup_card_req = false;
1579*4882a593Smuzhiyun 	adapter->ps_state = PS_STATE_AWAKE;
1580*4882a593Smuzhiyun 
1581*4882a593Smuzhiyun 	return 0;
1582*4882a593Smuzhiyun }
1583*4882a593Smuzhiyun 
mwifiex_usb_submit_rem_rx_urbs(struct mwifiex_adapter * adapter)1584*4882a593Smuzhiyun static void mwifiex_usb_submit_rem_rx_urbs(struct mwifiex_adapter *adapter)
1585*4882a593Smuzhiyun {
1586*4882a593Smuzhiyun 	struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
1587*4882a593Smuzhiyun 	int i;
1588*4882a593Smuzhiyun 	struct urb_context *ctx;
1589*4882a593Smuzhiyun 
1590*4882a593Smuzhiyun 	for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
1591*4882a593Smuzhiyun 		if (card->rx_data_list[i].skb)
1592*4882a593Smuzhiyun 			continue;
1593*4882a593Smuzhiyun 		ctx = &card->rx_data_list[i];
1594*4882a593Smuzhiyun 		mwifiex_usb_submit_rx_urb(ctx, MWIFIEX_RX_DATA_BUF_SIZE);
1595*4882a593Smuzhiyun 	}
1596*4882a593Smuzhiyun }
1597*4882a593Smuzhiyun 
1598*4882a593Smuzhiyun /* This function is called after the card has woken up. */
1599*4882a593Smuzhiyun static inline int
mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter * adapter)1600*4882a593Smuzhiyun mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
1601*4882a593Smuzhiyun {
1602*4882a593Smuzhiyun 	return 0;
1603*4882a593Smuzhiyun }
1604*4882a593Smuzhiyun 
1605*4882a593Smuzhiyun static struct mwifiex_if_ops usb_ops = {
1606*4882a593Smuzhiyun 	.register_dev =		mwifiex_register_dev,
1607*4882a593Smuzhiyun 	.unregister_dev =	mwifiex_unregister_dev,
1608*4882a593Smuzhiyun 	.wakeup =		mwifiex_pm_wakeup_card,
1609*4882a593Smuzhiyun 	.wakeup_complete =	mwifiex_pm_wakeup_card_complete,
1610*4882a593Smuzhiyun 
1611*4882a593Smuzhiyun 	/* USB specific */
1612*4882a593Smuzhiyun 	.dnld_fw =		mwifiex_usb_dnld_fw,
1613*4882a593Smuzhiyun 	.cmdrsp_complete =	mwifiex_usb_cmd_event_complete,
1614*4882a593Smuzhiyun 	.event_complete =	mwifiex_usb_cmd_event_complete,
1615*4882a593Smuzhiyun 	.host_to_card =		mwifiex_usb_host_to_card,
1616*4882a593Smuzhiyun 	.submit_rem_rx_urbs =	mwifiex_usb_submit_rem_rx_urbs,
1617*4882a593Smuzhiyun 	.multi_port_resync =	mwifiex_usb_port_resync,
1618*4882a593Smuzhiyun 	.is_port_ready =	mwifiex_usb_is_port_ready,
1619*4882a593Smuzhiyun };
1620*4882a593Smuzhiyun 
1621*4882a593Smuzhiyun module_usb_driver(mwifiex_usb_driver);
1622*4882a593Smuzhiyun 
1623*4882a593Smuzhiyun MODULE_AUTHOR("Marvell International Ltd.");
1624*4882a593Smuzhiyun MODULE_DESCRIPTION("Marvell WiFi-Ex USB Driver version" USB_VERSION);
1625*4882a593Smuzhiyun MODULE_VERSION(USB_VERSION);
1626*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
1627*4882a593Smuzhiyun MODULE_FIRMWARE(USB8766_DEFAULT_FW_NAME);
1628*4882a593Smuzhiyun MODULE_FIRMWARE(USB8797_DEFAULT_FW_NAME);
1629*4882a593Smuzhiyun MODULE_FIRMWARE(USB8801_DEFAULT_FW_NAME);
1630*4882a593Smuzhiyun MODULE_FIRMWARE(USB8997_DEFAULT_FW_NAME);
1631