1 /*
2 * Copyright (c) 2014 Redpine Signals Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 */
17
18 #include <linux/firmware.h>
19 #include "rsi_usb.h"
20
21 /**
22 * rsi_usb_rx_thread() - This is a kernel thread to receive the packets from
23 * the USB device.
24 * @data: Pointer to the driver private structure.
25 *
26 * Return: 0.
27 */
rsi_usb_rx_thread(void * data)28 int rsi_usb_rx_thread(void *data)
29 {
30 struct rsi_common *common = data;
31 struct rsi_hw *adapter = common->priv;
32 struct rsi_91x_usbdev *dev = adapter->rsi_dev;
33 int status;
34 struct sk_buff *skb;
35
36 do {
37 rsi_wait_event(&dev->rx_thread.event, EVENT_WAIT_FOREVER);
38 rsi_reset_event(&dev->rx_thread.event);
39
40 while (true) {
41 if (atomic_read(&dev->rx_thread.thread_done))
42 goto out;
43
44 skb = skb_dequeue(&dev->rx_q);
45 if (!skb)
46 break;
47 status = rsi_read_pkt(common, skb->data, 0);
48 if (status) {
49 rsi_dbg(ERR_ZONE, "%s: Failed To read data",
50 __func__);
51 break;
52 }
53 dev_kfree_skb(skb);
54 }
55 } while (1);
56
57 out:
58 rsi_dbg(INFO_ZONE, "%s: Terminated thread\n", __func__);
59 skb_queue_purge(&dev->rx_q);
60 kthread_complete_and_exit(&dev->rx_thread.completion, 0);
61 }
62
63