1*4882a593Smuzhiyun /**
2*4882a593Smuzhiyun * Copyright (c) 2014 Redpine Signals Inc.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission to use, copy, modify, and/or distribute this software for any
5*4882a593Smuzhiyun * purpose with or without fee is hereby granted, provided that the above
6*4882a593Smuzhiyun * copyright notice and this permission notice appear in all copies.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*4882a593Smuzhiyun * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*4882a593Smuzhiyun * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*4882a593Smuzhiyun * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*4882a593Smuzhiyun * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*4882a593Smuzhiyun * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*4882a593Smuzhiyun * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*4882a593Smuzhiyun */
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #ifndef __RSI_COMMON_H__
18*4882a593Smuzhiyun #define __RSI_COMMON_H__
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include <linux/kthread.h>
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #define EVENT_WAIT_FOREVER 0
23*4882a593Smuzhiyun #define FIRMWARE_RSI9113 "rs9113_wlan_qspi.rps"
24*4882a593Smuzhiyun #define QUEUE_NOT_FULL 1
25*4882a593Smuzhiyun #define QUEUE_FULL 0
26*4882a593Smuzhiyun
rsi_init_event(struct rsi_event * pevent)27*4882a593Smuzhiyun static inline int rsi_init_event(struct rsi_event *pevent)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun atomic_set(&pevent->event_condition, 1);
30*4882a593Smuzhiyun init_waitqueue_head(&pevent->event_queue);
31*4882a593Smuzhiyun return 0;
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun
rsi_wait_event(struct rsi_event * event,u32 timeout)34*4882a593Smuzhiyun static inline int rsi_wait_event(struct rsi_event *event, u32 timeout)
35*4882a593Smuzhiyun {
36*4882a593Smuzhiyun int status = 0;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun if (!timeout)
39*4882a593Smuzhiyun status = wait_event_interruptible(event->event_queue,
40*4882a593Smuzhiyun (atomic_read(&event->event_condition) == 0));
41*4882a593Smuzhiyun else
42*4882a593Smuzhiyun status = wait_event_interruptible_timeout(event->event_queue,
43*4882a593Smuzhiyun (atomic_read(&event->event_condition) == 0),
44*4882a593Smuzhiyun timeout);
45*4882a593Smuzhiyun return status;
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
rsi_set_event(struct rsi_event * event)48*4882a593Smuzhiyun static inline void rsi_set_event(struct rsi_event *event)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun atomic_set(&event->event_condition, 0);
51*4882a593Smuzhiyun wake_up_interruptible(&event->event_queue);
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
rsi_reset_event(struct rsi_event * event)54*4882a593Smuzhiyun static inline void rsi_reset_event(struct rsi_event *event)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun atomic_set(&event->event_condition, 1);
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
rsi_create_kthread(struct rsi_common * common,struct rsi_thread * thread,void * func_ptr,u8 * name)59*4882a593Smuzhiyun static inline int rsi_create_kthread(struct rsi_common *common,
60*4882a593Smuzhiyun struct rsi_thread *thread,
61*4882a593Smuzhiyun void *func_ptr,
62*4882a593Smuzhiyun u8 *name)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun init_completion(&thread->completion);
65*4882a593Smuzhiyun atomic_set(&thread->thread_done, 0);
66*4882a593Smuzhiyun thread->task = kthread_run(func_ptr, common, "%s", name);
67*4882a593Smuzhiyun if (IS_ERR(thread->task))
68*4882a593Smuzhiyun return (int)PTR_ERR(thread->task);
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun return 0;
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun
rsi_kill_thread(struct rsi_thread * handle)73*4882a593Smuzhiyun static inline int rsi_kill_thread(struct rsi_thread *handle)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun atomic_inc(&handle->thread_done);
76*4882a593Smuzhiyun rsi_set_event(&handle->event);
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun return kthread_stop(handle->task);
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun void rsi_mac80211_detach(struct rsi_hw *hw);
82*4882a593Smuzhiyun u16 rsi_get_connected_channel(struct ieee80211_vif *vif);
83*4882a593Smuzhiyun struct rsi_hw *rsi_91x_init(u16 oper_mode);
84*4882a593Smuzhiyun void rsi_91x_deinit(struct rsi_hw *adapter);
85*4882a593Smuzhiyun int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len);
86*4882a593Smuzhiyun #ifdef CONFIG_PM
87*4882a593Smuzhiyun int rsi_config_wowlan(struct rsi_hw *adapter, struct cfg80211_wowlan *wowlan);
88*4882a593Smuzhiyun #endif
89*4882a593Smuzhiyun struct rsi_sta *rsi_find_sta(struct rsi_common *common, u8 *mac_addr);
90*4882a593Smuzhiyun struct ieee80211_vif *rsi_get_vif(struct rsi_hw *adapter, u8 *mac);
91*4882a593Smuzhiyun void rsi_roc_timeout(struct timer_list *t);
92*4882a593Smuzhiyun #endif
93