xref: /openbmc/linux/drivers/net/wireless/ath/ath6kl/usb.c (revision 171fe768)
1 /*
2  * Copyright (c) 2007-2011 Atheros Communications Inc.
3  * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <linux/module.h>
19 #include <linux/usb.h>
20 
21 #include "debug.h"
22 #include "core.h"
23 
24 /* constants */
25 #define TX_URB_COUNT            32
26 #define RX_URB_COUNT            32
27 #define ATH6KL_USB_RX_BUFFER_SIZE  1700
28 
29 /* tx/rx pipes for usb */
30 enum ATH6KL_USB_PIPE_ID {
31 	ATH6KL_USB_PIPE_TX_CTRL = 0,
32 	ATH6KL_USB_PIPE_TX_DATA_LP,
33 	ATH6KL_USB_PIPE_TX_DATA_MP,
34 	ATH6KL_USB_PIPE_TX_DATA_HP,
35 	ATH6KL_USB_PIPE_RX_CTRL,
36 	ATH6KL_USB_PIPE_RX_DATA,
37 	ATH6KL_USB_PIPE_RX_DATA2,
38 	ATH6KL_USB_PIPE_RX_INT,
39 	ATH6KL_USB_PIPE_MAX
40 };
41 
42 #define ATH6KL_USB_PIPE_INVALID ATH6KL_USB_PIPE_MAX
43 
44 struct ath6kl_usb_pipe {
45 	struct list_head urb_list_head;
46 	struct usb_anchor urb_submitted;
47 	u32 urb_alloc;
48 	u32 urb_cnt;
49 	u32 urb_cnt_thresh;
50 	unsigned int usb_pipe_handle;
51 	u32 flags;
52 	u8 ep_address;
53 	u8 logical_pipe_num;
54 	struct ath6kl_usb *ar_usb;
55 	u16 max_packet_size;
56 	struct work_struct io_complete_work;
57 	struct sk_buff_head io_comp_queue;
58 	struct usb_endpoint_descriptor *ep_desc;
59 };
60 
61 #define ATH6KL_USB_PIPE_FLAG_TX    (1 << 0)
62 
63 /* usb device object */
64 struct ath6kl_usb {
65 	/* protects pipe->urb_list_head and  pipe->urb_cnt */
66 	spinlock_t cs_lock;
67 
68 	struct usb_device *udev;
69 	struct usb_interface *interface;
70 	struct ath6kl_usb_pipe pipes[ATH6KL_USB_PIPE_MAX];
71 	u8 *diag_cmd_buffer;
72 	u8 *diag_resp_buffer;
73 	struct ath6kl *ar;
74 };
75 
76 /* usb urb object */
77 struct ath6kl_urb_context {
78 	struct list_head link;
79 	struct ath6kl_usb_pipe *pipe;
80 	struct sk_buff *skb;
81 	struct ath6kl *ar;
82 };
83 
84 /* USB endpoint definitions */
85 #define ATH6KL_USB_EP_ADDR_APP_CTRL_IN          0x81
86 #define ATH6KL_USB_EP_ADDR_APP_DATA_IN          0x82
87 #define ATH6KL_USB_EP_ADDR_APP_DATA2_IN         0x83
88 #define ATH6KL_USB_EP_ADDR_APP_INT_IN           0x84
89 
90 #define ATH6KL_USB_EP_ADDR_APP_CTRL_OUT         0x01
91 #define ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT      0x02
92 #define ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT      0x03
93 #define ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT      0x04
94 
95 /* diagnostic command defnitions */
96 #define ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD        1
97 #define ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP       2
98 #define ATH6KL_USB_CONTROL_REQ_DIAG_CMD            3
99 #define ATH6KL_USB_CONTROL_REQ_DIAG_RESP           4
100 
101 #define ATH6KL_USB_CTRL_DIAG_CC_READ               0
102 #define ATH6KL_USB_CTRL_DIAG_CC_WRITE              1
103 
104 struct ath6kl_usb_ctrl_diag_cmd_write {
105 	__le32 cmd;
106 	__le32 address;
107 	__le32 value;
108 	__le32 _pad[1];
109 } __packed;
110 
111 struct ath6kl_usb_ctrl_diag_cmd_read {
112 	__le32 cmd;
113 	__le32 address;
114 } __packed;
115 
116 struct ath6kl_usb_ctrl_diag_resp_read {
117 	__le32 value;
118 } __packed;
119 
120 /* function declarations */
121 static void ath6kl_usb_recv_complete(struct urb *urb);
122 
123 #define ATH6KL_USB_IS_BULK_EP(attr) (((attr) & 3) == 0x02)
124 #define ATH6KL_USB_IS_INT_EP(attr)  (((attr) & 3) == 0x03)
125 #define ATH6KL_USB_IS_ISOC_EP(attr)  (((attr) & 3) == 0x01)
126 #define ATH6KL_USB_IS_DIR_IN(addr)  ((addr) & 0x80)
127 
128 /* pipe/urb operations */
129 static struct ath6kl_urb_context *
130 ath6kl_usb_alloc_urb_from_pipe(struct ath6kl_usb_pipe *pipe)
131 {
132 	struct ath6kl_urb_context *urb_context = NULL;
133 	unsigned long flags;
134 
135 	spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
136 	if (!list_empty(&pipe->urb_list_head)) {
137 		urb_context =
138 		    list_first_entry(&pipe->urb_list_head,
139 				     struct ath6kl_urb_context, link);
140 		list_del(&urb_context->link);
141 		pipe->urb_cnt--;
142 	}
143 	spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags);
144 
145 	return urb_context;
146 }
147 
148 static void ath6kl_usb_free_urb_to_pipe(struct ath6kl_usb_pipe *pipe,
149 					struct ath6kl_urb_context *urb_context)
150 {
151 	unsigned long flags;
152 
153 	spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
154 	pipe->urb_cnt++;
155 
156 	list_add(&urb_context->link, &pipe->urb_list_head);
157 	spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags);
158 }
159 
160 static void ath6kl_usb_cleanup_recv_urb(struct ath6kl_urb_context *urb_context)
161 {
162 	if (urb_context->skb != NULL) {
163 		dev_kfree_skb(urb_context->skb);
164 		urb_context->skb = NULL;
165 	}
166 
167 	ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
168 }
169 
170 static inline struct ath6kl_usb *ath6kl_usb_priv(struct ath6kl *ar)
171 {
172 	return ar->hif_priv;
173 }
174 
175 /* pipe resource allocation/cleanup */
176 static int ath6kl_usb_alloc_pipe_resources(struct ath6kl_usb_pipe *pipe,
177 					   int urb_cnt)
178 {
179 	struct ath6kl_urb_context *urb_context;
180 	int status = 0, i;
181 
182 	INIT_LIST_HEAD(&pipe->urb_list_head);
183 	init_usb_anchor(&pipe->urb_submitted);
184 
185 	for (i = 0; i < urb_cnt; i++) {
186 		urb_context = kzalloc(sizeof(struct ath6kl_urb_context),
187 				      GFP_KERNEL);
188 		if (urb_context == NULL) {
189 			status = -ENOMEM;
190 			goto fail_alloc_pipe_resources;
191 		}
192 
193 		urb_context->pipe = pipe;
194 
195 		/*
196 		 * we are only allocate the urb contexts here, the actual URB
197 		 * is allocated from the kernel as needed to do a transaction
198 		 */
199 		pipe->urb_alloc++;
200 		ath6kl_usb_free_urb_to_pipe(pipe, urb_context);
201 	}
202 
203 	ath6kl_dbg(ATH6KL_DBG_USB,
204 		   "ath6kl usb: alloc resources lpipe:%d hpipe:0x%X urbs:%d\n",
205 		   pipe->logical_pipe_num, pipe->usb_pipe_handle,
206 		   pipe->urb_alloc);
207 
208 fail_alloc_pipe_resources:
209 	return status;
210 }
211 
212 static void ath6kl_usb_free_pipe_resources(struct ath6kl_usb_pipe *pipe)
213 {
214 	struct ath6kl_urb_context *urb_context;
215 
216 	if (pipe->ar_usb == NULL) {
217 		/* nothing allocated for this pipe */
218 		return;
219 	}
220 
221 	ath6kl_dbg(ATH6KL_DBG_USB,
222 		   "ath6kl usb: free resources lpipe:%d"
223 		   "hpipe:0x%X urbs:%d avail:%d\n",
224 		   pipe->logical_pipe_num, pipe->usb_pipe_handle,
225 		   pipe->urb_alloc, pipe->urb_cnt);
226 
227 	if (pipe->urb_alloc != pipe->urb_cnt) {
228 		ath6kl_dbg(ATH6KL_DBG_USB,
229 			   "ath6kl usb: urb leak! lpipe:%d"
230 			   "hpipe:0x%X urbs:%d avail:%d\n",
231 			   pipe->logical_pipe_num, pipe->usb_pipe_handle,
232 			   pipe->urb_alloc, pipe->urb_cnt);
233 	}
234 
235 	while (true) {
236 		urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
237 		if (urb_context == NULL)
238 			break;
239 		kfree(urb_context);
240 	}
241 
242 }
243 
244 static void ath6kl_usb_cleanup_pipe_resources(struct ath6kl_usb *ar_usb)
245 {
246 	int i;
247 
248 	for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++)
249 		ath6kl_usb_free_pipe_resources(&ar_usb->pipes[i]);
250 
251 }
252 
253 static u8 ath6kl_usb_get_logical_pipe_num(struct ath6kl_usb *ar_usb,
254 					  u8 ep_address, int *urb_count)
255 {
256 	u8 pipe_num = ATH6KL_USB_PIPE_INVALID;
257 
258 	switch (ep_address) {
259 	case ATH6KL_USB_EP_ADDR_APP_CTRL_IN:
260 		pipe_num = ATH6KL_USB_PIPE_RX_CTRL;
261 		*urb_count = RX_URB_COUNT;
262 		break;
263 	case ATH6KL_USB_EP_ADDR_APP_DATA_IN:
264 		pipe_num = ATH6KL_USB_PIPE_RX_DATA;
265 		*urb_count = RX_URB_COUNT;
266 		break;
267 	case ATH6KL_USB_EP_ADDR_APP_INT_IN:
268 		pipe_num = ATH6KL_USB_PIPE_RX_INT;
269 		*urb_count = RX_URB_COUNT;
270 		break;
271 	case ATH6KL_USB_EP_ADDR_APP_DATA2_IN:
272 		pipe_num = ATH6KL_USB_PIPE_RX_DATA2;
273 		*urb_count = RX_URB_COUNT;
274 		break;
275 	case ATH6KL_USB_EP_ADDR_APP_CTRL_OUT:
276 		pipe_num = ATH6KL_USB_PIPE_TX_CTRL;
277 		*urb_count = TX_URB_COUNT;
278 		break;
279 	case ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT:
280 		pipe_num = ATH6KL_USB_PIPE_TX_DATA_LP;
281 		*urb_count = TX_URB_COUNT;
282 		break;
283 	case ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT:
284 		pipe_num = ATH6KL_USB_PIPE_TX_DATA_MP;
285 		*urb_count = TX_URB_COUNT;
286 		break;
287 	case ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT:
288 		pipe_num = ATH6KL_USB_PIPE_TX_DATA_HP;
289 		*urb_count = TX_URB_COUNT;
290 		break;
291 	default:
292 		/* note: there may be endpoints not currently used */
293 		break;
294 	}
295 
296 	return pipe_num;
297 }
298 
299 static int ath6kl_usb_setup_pipe_resources(struct ath6kl_usb *ar_usb)
300 {
301 	struct usb_interface *interface = ar_usb->interface;
302 	struct usb_host_interface *iface_desc = interface->cur_altsetting;
303 	struct usb_endpoint_descriptor *endpoint;
304 	struct ath6kl_usb_pipe *pipe;
305 	int i, urbcount, status = 0;
306 	u8 pipe_num;
307 
308 	ath6kl_dbg(ATH6KL_DBG_USB, "setting up USB Pipes using interface\n");
309 
310 	/* walk decriptors and setup pipes */
311 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
312 		endpoint = &iface_desc->endpoint[i].desc;
313 
314 		if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) {
315 			ath6kl_dbg(ATH6KL_DBG_USB,
316 				   "%s Bulk Ep:0x%2.2X maxpktsz:%d\n",
317 				   ATH6KL_USB_IS_DIR_IN
318 				   (endpoint->bEndpointAddress) ?
319 				   "RX" : "TX", endpoint->bEndpointAddress,
320 				   le16_to_cpu(endpoint->wMaxPacketSize));
321 		} else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) {
322 			ath6kl_dbg(ATH6KL_DBG_USB,
323 				   "%s Int Ep:0x%2.2X maxpktsz:%d interval:%d\n",
324 				   ATH6KL_USB_IS_DIR_IN
325 				   (endpoint->bEndpointAddress) ?
326 				   "RX" : "TX", endpoint->bEndpointAddress,
327 				   le16_to_cpu(endpoint->wMaxPacketSize),
328 				   endpoint->bInterval);
329 		} else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) {
330 			/* TODO for ISO */
331 			ath6kl_dbg(ATH6KL_DBG_USB,
332 				   "%s ISOC Ep:0x%2.2X maxpktsz:%d interval:%d\n",
333 				   ATH6KL_USB_IS_DIR_IN
334 				   (endpoint->bEndpointAddress) ?
335 				   "RX" : "TX", endpoint->bEndpointAddress,
336 				   le16_to_cpu(endpoint->wMaxPacketSize),
337 				   endpoint->bInterval);
338 		}
339 		urbcount = 0;
340 
341 		pipe_num =
342 		    ath6kl_usb_get_logical_pipe_num(ar_usb,
343 						    endpoint->bEndpointAddress,
344 						    &urbcount);
345 		if (pipe_num == ATH6KL_USB_PIPE_INVALID)
346 			continue;
347 
348 		pipe = &ar_usb->pipes[pipe_num];
349 		if (pipe->ar_usb != NULL) {
350 			/* hmmm..pipe was already setup */
351 			continue;
352 		}
353 
354 		pipe->ar_usb = ar_usb;
355 		pipe->logical_pipe_num = pipe_num;
356 		pipe->ep_address = endpoint->bEndpointAddress;
357 		pipe->max_packet_size = le16_to_cpu(endpoint->wMaxPacketSize);
358 
359 		if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) {
360 			if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
361 				pipe->usb_pipe_handle =
362 				    usb_rcvbulkpipe(ar_usb->udev,
363 						    pipe->ep_address);
364 			} else {
365 				pipe->usb_pipe_handle =
366 				    usb_sndbulkpipe(ar_usb->udev,
367 						    pipe->ep_address);
368 			}
369 		} else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) {
370 			if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
371 				pipe->usb_pipe_handle =
372 				    usb_rcvintpipe(ar_usb->udev,
373 						   pipe->ep_address);
374 			} else {
375 				pipe->usb_pipe_handle =
376 				    usb_sndintpipe(ar_usb->udev,
377 						   pipe->ep_address);
378 			}
379 		} else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) {
380 			/* TODO for ISO */
381 			if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
382 				pipe->usb_pipe_handle =
383 				    usb_rcvisocpipe(ar_usb->udev,
384 						    pipe->ep_address);
385 			} else {
386 				pipe->usb_pipe_handle =
387 				    usb_sndisocpipe(ar_usb->udev,
388 						    pipe->ep_address);
389 			}
390 		}
391 
392 		pipe->ep_desc = endpoint;
393 
394 		if (!ATH6KL_USB_IS_DIR_IN(pipe->ep_address))
395 			pipe->flags |= ATH6KL_USB_PIPE_FLAG_TX;
396 
397 		status = ath6kl_usb_alloc_pipe_resources(pipe, urbcount);
398 		if (status != 0)
399 			break;
400 	}
401 
402 	return status;
403 }
404 
405 /* pipe operations */
406 static void ath6kl_usb_post_recv_transfers(struct ath6kl_usb_pipe *recv_pipe,
407 					   int buffer_length)
408 {
409 	struct ath6kl_urb_context *urb_context;
410 	struct urb *urb;
411 	int usb_status;
412 
413 	while (true) {
414 		urb_context = ath6kl_usb_alloc_urb_from_pipe(recv_pipe);
415 		if (urb_context == NULL)
416 			break;
417 
418 		urb_context->skb = dev_alloc_skb(buffer_length);
419 		if (urb_context->skb == NULL)
420 			goto err_cleanup_urb;
421 
422 		urb = usb_alloc_urb(0, GFP_ATOMIC);
423 		if (urb == NULL)
424 			goto err_cleanup_urb;
425 
426 		usb_fill_bulk_urb(urb,
427 				  recv_pipe->ar_usb->udev,
428 				  recv_pipe->usb_pipe_handle,
429 				  urb_context->skb->data,
430 				  buffer_length,
431 				  ath6kl_usb_recv_complete, urb_context);
432 
433 		ath6kl_dbg(ATH6KL_DBG_USB_BULK,
434 			   "ath6kl usb: bulk recv submit:%d, 0x%X (ep:0x%2.2X), %d bytes buf:0x%p\n",
435 			   recv_pipe->logical_pipe_num,
436 			   recv_pipe->usb_pipe_handle, recv_pipe->ep_address,
437 			   buffer_length, urb_context->skb);
438 
439 		usb_anchor_urb(urb, &recv_pipe->urb_submitted);
440 		usb_status = usb_submit_urb(urb, GFP_ATOMIC);
441 
442 		if (usb_status) {
443 			ath6kl_dbg(ATH6KL_DBG_USB_BULK,
444 				   "ath6kl usb : usb bulk recv failed %d\n",
445 				   usb_status);
446 			usb_unanchor_urb(urb);
447 			usb_free_urb(urb);
448 			goto err_cleanup_urb;
449 		}
450 		usb_free_urb(urb);
451 	}
452 	return;
453 
454 err_cleanup_urb:
455 	ath6kl_usb_cleanup_recv_urb(urb_context);
456 	return;
457 }
458 
459 static void ath6kl_usb_flush_all(struct ath6kl_usb *ar_usb)
460 {
461 	int i;
462 
463 	for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
464 		if (ar_usb->pipes[i].ar_usb != NULL)
465 			usb_kill_anchored_urbs(&ar_usb->pipes[i].urb_submitted);
466 	}
467 
468 	/*
469 	 * Flushing any pending I/O may schedule work this call will block
470 	 * until all scheduled work runs to completion.
471 	 */
472 	flush_scheduled_work();
473 }
474 
475 static void ath6kl_usb_start_recv_pipes(struct ath6kl_usb *ar_usb)
476 {
477 	/*
478 	 * note: control pipe is no longer used
479 	 * ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_cnt_thresh =
480 	 *      ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_alloc/2;
481 	 * ath6kl_usb_post_recv_transfers(&ar_usb->
482 	 *		pipes[ATH6KL_USB_PIPE_RX_CTRL],
483 	 *		ATH6KL_USB_RX_BUFFER_SIZE);
484 	 */
485 
486 	ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA].urb_cnt_thresh =
487 	    ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA].urb_alloc / 2;
488 	ath6kl_usb_post_recv_transfers(&ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA],
489 				       ATH6KL_USB_RX_BUFFER_SIZE);
490 }
491 
492 /* hif usb rx/tx completion functions */
493 static void ath6kl_usb_recv_complete(struct urb *urb)
494 {
495 	struct ath6kl_urb_context *urb_context = urb->context;
496 	struct ath6kl_usb_pipe *pipe = urb_context->pipe;
497 	struct sk_buff *skb = NULL;
498 	int status = 0;
499 
500 	ath6kl_dbg(ATH6KL_DBG_USB_BULK,
501 		   "%s: recv pipe: %d, stat:%d, len:%d urb:0x%p\n", __func__,
502 		   pipe->logical_pipe_num, urb->status, urb->actual_length,
503 		   urb);
504 
505 	if (urb->status != 0) {
506 		status = -EIO;
507 		switch (urb->status) {
508 		case -ECONNRESET:
509 		case -ENOENT:
510 		case -ESHUTDOWN:
511 			/*
512 			 * no need to spew these errors when device
513 			 * removed or urb killed due to driver shutdown
514 			 */
515 			status = -ECANCELED;
516 			break;
517 		default:
518 			ath6kl_dbg(ATH6KL_DBG_USB_BULK,
519 				   "%s recv pipe: %d (ep:0x%2.2X), failed:%d\n",
520 				   __func__, pipe->logical_pipe_num,
521 				   pipe->ep_address, urb->status);
522 			break;
523 		}
524 		goto cleanup_recv_urb;
525 	}
526 
527 	if (urb->actual_length == 0)
528 		goto cleanup_recv_urb;
529 
530 	skb = urb_context->skb;
531 
532 	/* we are going to pass it up */
533 	urb_context->skb = NULL;
534 	skb_put(skb, urb->actual_length);
535 
536 	/* note: queue implements a lock */
537 	skb_queue_tail(&pipe->io_comp_queue, skb);
538 	schedule_work(&pipe->io_complete_work);
539 
540 cleanup_recv_urb:
541 	ath6kl_usb_cleanup_recv_urb(urb_context);
542 
543 	if (status == 0 &&
544 	    pipe->urb_cnt >= pipe->urb_cnt_thresh) {
545 		/* our free urbs are piling up, post more transfers */
546 		ath6kl_usb_post_recv_transfers(pipe, ATH6KL_USB_RX_BUFFER_SIZE);
547 	}
548 }
549 
550 static void ath6kl_usb_usb_transmit_complete(struct urb *urb)
551 {
552 	struct ath6kl_urb_context *urb_context = urb->context;
553 	struct ath6kl_usb_pipe *pipe = urb_context->pipe;
554 	struct sk_buff *skb;
555 
556 	ath6kl_dbg(ATH6KL_DBG_USB_BULK,
557 		   "%s: pipe: %d, stat:%d, len:%d\n",
558 		   __func__, pipe->logical_pipe_num, urb->status,
559 		   urb->actual_length);
560 
561 	if (urb->status != 0) {
562 		ath6kl_dbg(ATH6KL_DBG_USB_BULK,
563 			   "%s:  pipe: %d, failed:%d\n",
564 			   __func__, pipe->logical_pipe_num, urb->status);
565 	}
566 
567 	skb = urb_context->skb;
568 	urb_context->skb = NULL;
569 	ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
570 
571 	/* note: queue implements a lock */
572 	skb_queue_tail(&pipe->io_comp_queue, skb);
573 	schedule_work(&pipe->io_complete_work);
574 }
575 
576 static void ath6kl_usb_io_comp_work(struct work_struct *work)
577 {
578 	struct ath6kl_usb_pipe *pipe = container_of(work,
579 						    struct ath6kl_usb_pipe,
580 						    io_complete_work);
581 	struct ath6kl_usb *ar_usb;
582 	struct sk_buff *skb;
583 
584 	ar_usb = pipe->ar_usb;
585 
586 	while ((skb = skb_dequeue(&pipe->io_comp_queue))) {
587 		if (pipe->flags & ATH6KL_USB_PIPE_FLAG_TX) {
588 			ath6kl_dbg(ATH6KL_DBG_USB_BULK,
589 				   "ath6kl usb xmit callback buf:0x%p\n", skb);
590 			ath6kl_core_tx_complete(ar_usb->ar, skb);
591 		} else {
592 			ath6kl_dbg(ATH6KL_DBG_USB_BULK,
593 				   "ath6kl usb recv callback buf:0x%p\n", skb);
594 			ath6kl_core_rx_complete(ar_usb->ar, skb,
595 						pipe->logical_pipe_num);
596 		}
597 	}
598 }
599 
600 #define ATH6KL_USB_MAX_DIAG_CMD (sizeof(struct ath6kl_usb_ctrl_diag_cmd_write))
601 #define ATH6KL_USB_MAX_DIAG_RESP (sizeof(struct ath6kl_usb_ctrl_diag_resp_read))
602 
603 static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb)
604 {
605 	ath6kl_usb_flush_all(ar_usb);
606 
607 	ath6kl_usb_cleanup_pipe_resources(ar_usb);
608 
609 	usb_set_intfdata(ar_usb->interface, NULL);
610 
611 	kfree(ar_usb->diag_cmd_buffer);
612 	kfree(ar_usb->diag_resp_buffer);
613 
614 	kfree(ar_usb);
615 }
616 
617 static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface)
618 {
619 	struct usb_device *dev = interface_to_usbdev(interface);
620 	struct ath6kl_usb *ar_usb;
621 	struct ath6kl_usb_pipe *pipe;
622 	int status = 0;
623 	int i;
624 
625 	ar_usb = kzalloc(sizeof(struct ath6kl_usb), GFP_KERNEL);
626 	if (ar_usb == NULL)
627 		goto fail_ath6kl_usb_create;
628 
629 	usb_set_intfdata(interface, ar_usb);
630 	spin_lock_init(&(ar_usb->cs_lock));
631 	ar_usb->udev = dev;
632 	ar_usb->interface = interface;
633 
634 	for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
635 		pipe = &ar_usb->pipes[i];
636 		INIT_WORK(&pipe->io_complete_work,
637 			  ath6kl_usb_io_comp_work);
638 		skb_queue_head_init(&pipe->io_comp_queue);
639 	}
640 
641 	ar_usb->diag_cmd_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_CMD, GFP_KERNEL);
642 	if (ar_usb->diag_cmd_buffer == NULL) {
643 		status = -ENOMEM;
644 		goto fail_ath6kl_usb_create;
645 	}
646 
647 	ar_usb->diag_resp_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_RESP,
648 					   GFP_KERNEL);
649 	if (ar_usb->diag_resp_buffer == NULL) {
650 		status = -ENOMEM;
651 		goto fail_ath6kl_usb_create;
652 	}
653 
654 	status = ath6kl_usb_setup_pipe_resources(ar_usb);
655 
656 fail_ath6kl_usb_create:
657 	if (status != 0) {
658 		ath6kl_usb_destroy(ar_usb);
659 		ar_usb = NULL;
660 	}
661 	return ar_usb;
662 }
663 
664 static void ath6kl_usb_device_detached(struct usb_interface *interface)
665 {
666 	struct ath6kl_usb *ar_usb;
667 
668 	ar_usb = usb_get_intfdata(interface);
669 	if (ar_usb == NULL)
670 		return;
671 
672 	ath6kl_stop_txrx(ar_usb->ar);
673 
674 	/* Delay to wait for the target to reboot */
675 	mdelay(20);
676 	ath6kl_core_cleanup(ar_usb->ar);
677 	ath6kl_usb_destroy(ar_usb);
678 }
679 
680 /* exported hif usb APIs for htc pipe */
681 static void hif_start(struct ath6kl *ar)
682 {
683 	struct ath6kl_usb *device = ath6kl_usb_priv(ar);
684 	int i;
685 
686 	ath6kl_usb_start_recv_pipes(device);
687 
688 	/* set the TX resource avail threshold for each TX pipe */
689 	for (i = ATH6KL_USB_PIPE_TX_CTRL;
690 	     i <= ATH6KL_USB_PIPE_TX_DATA_HP; i++) {
691 		device->pipes[i].urb_cnt_thresh =
692 		    device->pipes[i].urb_alloc / 2;
693 	}
694 }
695 
696 static int ath6kl_usb_send(struct ath6kl *ar, u8 PipeID,
697 			   struct sk_buff *hdr_skb, struct sk_buff *skb)
698 {
699 	struct ath6kl_usb *device = ath6kl_usb_priv(ar);
700 	struct ath6kl_usb_pipe *pipe = &device->pipes[PipeID];
701 	struct ath6kl_urb_context *urb_context;
702 	int usb_status, status = 0;
703 	struct urb *urb;
704 	u8 *data;
705 	u32 len;
706 
707 	ath6kl_dbg(ATH6KL_DBG_USB_BULK, "+%s pipe : %d, buf:0x%p\n",
708 		   __func__, PipeID, skb);
709 
710 	urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
711 
712 	if (urb_context == NULL) {
713 		/*
714 		 * TODO: it is possible to run out of urbs if
715 		 * 2 endpoints map to the same pipe ID
716 		 */
717 		ath6kl_dbg(ATH6KL_DBG_USB_BULK,
718 			   "%s pipe:%d no urbs left. URB Cnt : %d\n",
719 			   __func__, PipeID, pipe->urb_cnt);
720 		status = -ENOMEM;
721 		goto fail_hif_send;
722 	}
723 
724 	urb_context->skb = skb;
725 
726 	data = skb->data;
727 	len = skb->len;
728 
729 	urb = usb_alloc_urb(0, GFP_ATOMIC);
730 	if (urb == NULL) {
731 		status = -ENOMEM;
732 		ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
733 					    urb_context);
734 		goto fail_hif_send;
735 	}
736 
737 	usb_fill_bulk_urb(urb,
738 			  device->udev,
739 			  pipe->usb_pipe_handle,
740 			  data,
741 			  len,
742 			  ath6kl_usb_usb_transmit_complete, urb_context);
743 
744 	if ((len % pipe->max_packet_size) == 0) {
745 		/* hit a max packet boundary on this pipe */
746 		urb->transfer_flags |= URB_ZERO_PACKET;
747 	}
748 
749 	ath6kl_dbg(ATH6KL_DBG_USB_BULK,
750 		   "athusb bulk send submit:%d, 0x%X (ep:0x%2.2X), %d bytes\n",
751 		   pipe->logical_pipe_num, pipe->usb_pipe_handle,
752 		   pipe->ep_address, len);
753 
754 	usb_anchor_urb(urb, &pipe->urb_submitted);
755 	usb_status = usb_submit_urb(urb, GFP_ATOMIC);
756 
757 	if (usb_status) {
758 		ath6kl_dbg(ATH6KL_DBG_USB_BULK,
759 			   "ath6kl usb : usb bulk transmit failed %d\n",
760 			   usb_status);
761 		usb_unanchor_urb(urb);
762 		ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
763 					    urb_context);
764 		status = -EINVAL;
765 	}
766 	usb_free_urb(urb);
767 
768 fail_hif_send:
769 	return status;
770 }
771 
772 static void hif_stop(struct ath6kl *ar)
773 {
774 	struct ath6kl_usb *device = ath6kl_usb_priv(ar);
775 
776 	ath6kl_usb_flush_all(device);
777 }
778 
779 static void ath6kl_usb_get_default_pipe(struct ath6kl *ar,
780 					u8 *ul_pipe, u8 *dl_pipe)
781 {
782 	*ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
783 	*dl_pipe = ATH6KL_USB_PIPE_RX_CTRL;
784 }
785 
786 static int ath6kl_usb_map_service_pipe(struct ath6kl *ar, u16 svc_id,
787 				       u8 *ul_pipe, u8 *dl_pipe)
788 {
789 	int status = 0;
790 
791 	switch (svc_id) {
792 	case HTC_CTRL_RSVD_SVC:
793 	case WMI_CONTROL_SVC:
794 		*ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
795 		/* due to large control packets, shift to data pipe */
796 		*dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
797 		break;
798 	case WMI_DATA_BE_SVC:
799 	case WMI_DATA_BK_SVC:
800 		*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
801 		/*
802 		* Disable rxdata2 directly, it will be enabled
803 		* if FW enable rxdata2
804 		*/
805 		*dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
806 		break;
807 	case WMI_DATA_VI_SVC:
808 
809 		if (ar->hw.flags & ATH6KL_HW_MAP_LP_ENDPOINT)
810 			*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
811 		else
812 			*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
813 		/*
814 		* Disable rxdata2 directly, it will be enabled
815 		* if FW enable rxdata2
816 		*/
817 		*dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
818 		break;
819 	case WMI_DATA_VO_SVC:
820 
821 		if (ar->hw.flags & ATH6KL_HW_MAP_LP_ENDPOINT)
822 			*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
823 		else
824 			*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
825 		/*
826 		* Disable rxdata2 directly, it will be enabled
827 		* if FW enable rxdata2
828 		*/
829 		*dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
830 		break;
831 	default:
832 		status = -EPERM;
833 		break;
834 	}
835 
836 	return status;
837 }
838 
839 static u16 ath6kl_usb_get_free_queue_number(struct ath6kl *ar, u8 pipe_id)
840 {
841 	struct ath6kl_usb *device = ath6kl_usb_priv(ar);
842 
843 	return device->pipes[pipe_id].urb_cnt;
844 }
845 
846 static void hif_detach_htc(struct ath6kl *ar)
847 {
848 	struct ath6kl_usb *device = ath6kl_usb_priv(ar);
849 
850 	ath6kl_usb_flush_all(device);
851 }
852 
853 static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb,
854 				   u8 req, u16 value, u16 index, void *data,
855 				   u32 size)
856 {
857 	u8 *buf = NULL;
858 	int ret;
859 
860 	if (size > 0) {
861 		buf = kmalloc(size, GFP_KERNEL);
862 		if (buf == NULL)
863 			return -ENOMEM;
864 
865 		memcpy(buf, data, size);
866 	}
867 
868 	/* note: if successful returns number of bytes transfered */
869 	ret = usb_control_msg(ar_usb->udev,
870 			      usb_sndctrlpipe(ar_usb->udev, 0),
871 			      req,
872 			      USB_DIR_OUT | USB_TYPE_VENDOR |
873 			      USB_RECIP_DEVICE, value, index, buf,
874 			      size, 1000);
875 
876 	if (ret < 0) {
877 		ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
878 			   __func__, ret);
879 	}
880 
881 	kfree(buf);
882 
883 	return 0;
884 }
885 
886 static int ath6kl_usb_submit_ctrl_in(struct ath6kl_usb *ar_usb,
887 				  u8 req, u16 value, u16 index, void *data,
888 				  u32 size)
889 {
890 	u8 *buf = NULL;
891 	int ret;
892 
893 	if (size > 0) {
894 		buf = kmalloc(size, GFP_KERNEL);
895 		if (buf == NULL)
896 			return -ENOMEM;
897 	}
898 
899 	/* note: if successful returns number of bytes transfered */
900 	ret = usb_control_msg(ar_usb->udev,
901 				 usb_rcvctrlpipe(ar_usb->udev, 0),
902 				 req,
903 				 USB_DIR_IN | USB_TYPE_VENDOR |
904 				 USB_RECIP_DEVICE, value, index, buf,
905 				 size, 2 * HZ);
906 
907 	if (ret < 0) {
908 		ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
909 			   __func__, ret);
910 	}
911 
912 	memcpy((u8 *) data, buf, size);
913 
914 	kfree(buf);
915 
916 	return 0;
917 }
918 
919 static int ath6kl_usb_ctrl_msg_exchange(struct ath6kl_usb *ar_usb,
920 				     u8 req_val, u8 *req_buf, u32 req_len,
921 				     u8 resp_val, u8 *resp_buf, u32 *resp_len)
922 {
923 	int ret;
924 
925 	/* send command */
926 	ret = ath6kl_usb_submit_ctrl_out(ar_usb, req_val, 0, 0,
927 					 req_buf, req_len);
928 
929 	if (ret != 0)
930 		return ret;
931 
932 	if (resp_buf == NULL) {
933 		/* no expected response */
934 		return ret;
935 	}
936 
937 	/* get response */
938 	ret = ath6kl_usb_submit_ctrl_in(ar_usb, resp_val, 0, 0,
939 					resp_buf, *resp_len);
940 
941 	return ret;
942 }
943 
944 static int ath6kl_usb_diag_read32(struct ath6kl *ar, u32 address, u32 *data)
945 {
946 	struct ath6kl_usb *ar_usb = ar->hif_priv;
947 	struct ath6kl_usb_ctrl_diag_resp_read *resp;
948 	struct ath6kl_usb_ctrl_diag_cmd_read *cmd;
949 	u32 resp_len;
950 	int ret;
951 
952 	cmd = (struct ath6kl_usb_ctrl_diag_cmd_read *) ar_usb->diag_cmd_buffer;
953 
954 	memset(cmd, 0, sizeof(*cmd));
955 	cmd->cmd = ATH6KL_USB_CTRL_DIAG_CC_READ;
956 	cmd->address = cpu_to_le32(address);
957 	resp_len = sizeof(*resp);
958 
959 	ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
960 				ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
961 				(u8 *) cmd,
962 				sizeof(struct ath6kl_usb_ctrl_diag_cmd_write),
963 				ATH6KL_USB_CONTROL_REQ_DIAG_RESP,
964 				ar_usb->diag_resp_buffer, &resp_len);
965 
966 	if (ret)
967 		return ret;
968 
969 	resp = (struct ath6kl_usb_ctrl_diag_resp_read *)
970 		ar_usb->diag_resp_buffer;
971 
972 	*data = le32_to_cpu(resp->value);
973 
974 	return ret;
975 }
976 
977 static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data)
978 {
979 	struct ath6kl_usb *ar_usb = ar->hif_priv;
980 	struct ath6kl_usb_ctrl_diag_cmd_write *cmd;
981 
982 	cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer;
983 
984 	memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write));
985 	cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE);
986 	cmd->address = cpu_to_le32(address);
987 	cmd->value = data;
988 
989 	return ath6kl_usb_ctrl_msg_exchange(ar_usb,
990 					    ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
991 					    (u8 *) cmd,
992 					    sizeof(*cmd),
993 					    0, NULL, NULL);
994 
995 }
996 
997 static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
998 {
999 	struct ath6kl_usb *ar_usb = ar->hif_priv;
1000 	int ret;
1001 
1002 	/* get response */
1003 	ret = ath6kl_usb_submit_ctrl_in(ar_usb,
1004 					ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP,
1005 					0, 0, buf, len);
1006 	if (ret != 0) {
1007 		ath6kl_err("Unable to read the bmi data from the device: %d\n",
1008 			   ret);
1009 		return ret;
1010 	}
1011 
1012 	return 0;
1013 }
1014 
1015 static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
1016 {
1017 	struct ath6kl_usb *ar_usb = ar->hif_priv;
1018 	int ret;
1019 
1020 	/* send command */
1021 	ret = ath6kl_usb_submit_ctrl_out(ar_usb,
1022 					 ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD,
1023 					 0, 0, buf, len);
1024 	if (ret != 0) {
1025 		ath6kl_err("unable to send the bmi data to the device: %d\n",
1026 			   ret);
1027 		return ret;
1028 	}
1029 
1030 	return 0;
1031 }
1032 
1033 static int ath6kl_usb_power_on(struct ath6kl *ar)
1034 {
1035 	hif_start(ar);
1036 	return 0;
1037 }
1038 
1039 static int ath6kl_usb_power_off(struct ath6kl *ar)
1040 {
1041 	hif_detach_htc(ar);
1042 	return 0;
1043 }
1044 
1045 static void ath6kl_usb_stop(struct ath6kl *ar)
1046 {
1047 	hif_stop(ar);
1048 }
1049 
1050 static void ath6kl_usb_cleanup_scatter(struct ath6kl *ar)
1051 {
1052 	/*
1053 	 * USB doesn't support it. Just return.
1054 	 */
1055 	return;
1056 }
1057 
1058 static const struct ath6kl_hif_ops ath6kl_usb_ops = {
1059 	.diag_read32 = ath6kl_usb_diag_read32,
1060 	.diag_write32 = ath6kl_usb_diag_write32,
1061 	.bmi_read = ath6kl_usb_bmi_read,
1062 	.bmi_write = ath6kl_usb_bmi_write,
1063 	.power_on = ath6kl_usb_power_on,
1064 	.power_off = ath6kl_usb_power_off,
1065 	.stop = ath6kl_usb_stop,
1066 	.pipe_send = ath6kl_usb_send,
1067 	.pipe_get_default = ath6kl_usb_get_default_pipe,
1068 	.pipe_map_service = ath6kl_usb_map_service_pipe,
1069 	.pipe_get_free_queue_number = ath6kl_usb_get_free_queue_number,
1070 	.cleanup_scatter = ath6kl_usb_cleanup_scatter,
1071 };
1072 
1073 /* ath6kl usb driver registered functions */
1074 static int ath6kl_usb_probe(struct usb_interface *interface,
1075 			    const struct usb_device_id *id)
1076 {
1077 	struct usb_device *dev = interface_to_usbdev(interface);
1078 	struct ath6kl *ar;
1079 	struct ath6kl_usb *ar_usb = NULL;
1080 	int vendor_id, product_id;
1081 	int ret = 0;
1082 
1083 	usb_get_dev(dev);
1084 
1085 	vendor_id = le16_to_cpu(dev->descriptor.idVendor);
1086 	product_id = le16_to_cpu(dev->descriptor.idProduct);
1087 
1088 	ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id);
1089 	ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id);
1090 
1091 	if (interface->cur_altsetting)
1092 		ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n",
1093 			   interface->cur_altsetting->desc.bInterfaceNumber);
1094 
1095 
1096 	if (dev->speed == USB_SPEED_HIGH)
1097 		ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n");
1098 	else
1099 		ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n");
1100 
1101 	ar_usb = ath6kl_usb_create(interface);
1102 
1103 	if (ar_usb == NULL) {
1104 		ret = -ENOMEM;
1105 		goto err_usb_put;
1106 	}
1107 
1108 	ar = ath6kl_core_create(&ar_usb->udev->dev);
1109 	if (ar == NULL) {
1110 		ath6kl_err("Failed to alloc ath6kl core\n");
1111 		ret = -ENOMEM;
1112 		goto err_usb_destroy;
1113 	}
1114 
1115 	ar->hif_priv = ar_usb;
1116 	ar->hif_type = ATH6KL_HIF_TYPE_USB;
1117 	ar->hif_ops = &ath6kl_usb_ops;
1118 	ar->mbox_info.block_size = 16;
1119 	ar->bmi.max_data_size = 252;
1120 
1121 	ar_usb->ar = ar;
1122 
1123 	ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE);
1124 	if (ret) {
1125 		ath6kl_err("Failed to init ath6kl core: %d\n", ret);
1126 		goto err_core_free;
1127 	}
1128 
1129 	return ret;
1130 
1131 err_core_free:
1132 	ath6kl_core_destroy(ar);
1133 err_usb_destroy:
1134 	ath6kl_usb_destroy(ar_usb);
1135 err_usb_put:
1136 	usb_put_dev(dev);
1137 
1138 	return ret;
1139 }
1140 
1141 static void ath6kl_usb_remove(struct usb_interface *interface)
1142 {
1143 	usb_put_dev(interface_to_usbdev(interface));
1144 	ath6kl_usb_device_detached(interface);
1145 }
1146 
1147 #ifdef CONFIG_PM
1148 
1149 static int ath6kl_usb_suspend(struct usb_interface *interface,
1150 			      pm_message_t message)
1151 {
1152 	struct ath6kl_usb *device;
1153 	device = usb_get_intfdata(interface);
1154 
1155 	ath6kl_usb_flush_all(device);
1156 	return 0;
1157 }
1158 
1159 static int ath6kl_usb_resume(struct usb_interface *interface)
1160 {
1161 	struct ath6kl_usb *device;
1162 	device = usb_get_intfdata(interface);
1163 
1164 	ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA],
1165 				       ATH6KL_USB_RX_BUFFER_SIZE);
1166 	ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA2],
1167 				       ATH6KL_USB_RX_BUFFER_SIZE);
1168 
1169 	return 0;
1170 }
1171 
1172 static int ath6kl_usb_reset_resume(struct usb_interface *intf)
1173 {
1174 	if (usb_get_intfdata(intf))
1175 		ath6kl_usb_remove(intf);
1176 	return 0;
1177 }
1178 
1179 #else
1180 
1181 #define ath6kl_usb_suspend NULL
1182 #define ath6kl_usb_resume NULL
1183 #define ath6kl_usb_reset_resume NULL
1184 
1185 #endif
1186 
1187 /* table of devices that work with this driver */
1188 static struct usb_device_id ath6kl_usb_ids[] = {
1189 	{USB_DEVICE(0x0cf3, 0x9374)},
1190 	{ /* Terminating entry */ },
1191 };
1192 
1193 MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
1194 
1195 static struct usb_driver ath6kl_usb_driver = {
1196 	.name = "ath6kl_usb",
1197 	.probe = ath6kl_usb_probe,
1198 	.suspend = ath6kl_usb_suspend,
1199 	.resume = ath6kl_usb_resume,
1200 	.reset_resume = ath6kl_usb_reset_resume,
1201 	.disconnect = ath6kl_usb_remove,
1202 	.id_table = ath6kl_usb_ids,
1203 	.supports_autosuspend = true,
1204 	.disable_hub_initiated_lpm = 1,
1205 };
1206 
1207 static int ath6kl_usb_init(void)
1208 {
1209 	int ret;
1210 
1211 	ret = usb_register(&ath6kl_usb_driver);
1212 	if (ret) {
1213 		ath6kl_err("usb registration failed: %d\n", ret);
1214 		return ret;
1215 	}
1216 
1217 	return 0;
1218 }
1219 
1220 static void ath6kl_usb_exit(void)
1221 {
1222 	usb_deregister(&ath6kl_usb_driver);
1223 }
1224 
1225 module_init(ath6kl_usb_init);
1226 module_exit(ath6kl_usb_exit);
1227 
1228 MODULE_AUTHOR("Atheros Communications, Inc.");
1229 MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices");
1230 MODULE_LICENSE("Dual BSD/GPL");
1231 MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE);
1232 MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE);
1233 MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE);
1234 MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE);
1235 MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE);
1236 MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE);
1237 MODULE_FIRMWARE(AR6004_HW_1_2_FIRMWARE_FILE);
1238 MODULE_FIRMWARE(AR6004_HW_1_2_BOARD_DATA_FILE);
1239 MODULE_FIRMWARE(AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE);
1240 MODULE_FIRMWARE(AR6004_HW_1_3_FW_DIR "/" AR6004_HW_1_3_FIRMWARE_FILE);
1241 MODULE_FIRMWARE(AR6004_HW_1_3_BOARD_DATA_FILE);
1242 MODULE_FIRMWARE(AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE);
1243