18c2ecf20Sopenharmony_ci/**
28c2ecf20Sopenharmony_ci * Copyright (c) 2014 Redpine Signals Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#ifndef __RSI_COMMON_H__
188c2ecf20Sopenharmony_ci#define __RSI_COMMON_H__
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <linux/kthread.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define EVENT_WAIT_FOREVER              0
238c2ecf20Sopenharmony_ci#define FIRMWARE_RSI9113                "rs9113_wlan_qspi.rps"
248c2ecf20Sopenharmony_ci#define QUEUE_NOT_FULL                  1
258c2ecf20Sopenharmony_ci#define QUEUE_FULL                      0
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic inline int rsi_init_event(struct rsi_event *pevent)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	atomic_set(&pevent->event_condition, 1);
308c2ecf20Sopenharmony_ci	init_waitqueue_head(&pevent->event_queue);
318c2ecf20Sopenharmony_ci	return 0;
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic inline int rsi_wait_event(struct rsi_event *event, u32 timeout)
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	int status = 0;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	if (!timeout)
398c2ecf20Sopenharmony_ci		status = wait_event_interruptible(event->event_queue,
408c2ecf20Sopenharmony_ci				(atomic_read(&event->event_condition) == 0));
418c2ecf20Sopenharmony_ci	else
428c2ecf20Sopenharmony_ci		status = wait_event_interruptible_timeout(event->event_queue,
438c2ecf20Sopenharmony_ci				(atomic_read(&event->event_condition) == 0),
448c2ecf20Sopenharmony_ci				timeout);
458c2ecf20Sopenharmony_ci	return status;
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic inline void rsi_set_event(struct rsi_event *event)
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci	atomic_set(&event->event_condition, 0);
518c2ecf20Sopenharmony_ci	wake_up_interruptible(&event->event_queue);
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic inline void rsi_reset_event(struct rsi_event *event)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	atomic_set(&event->event_condition, 1);
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic inline int rsi_create_kthread(struct rsi_common *common,
608c2ecf20Sopenharmony_ci				     struct rsi_thread *thread,
618c2ecf20Sopenharmony_ci				     void *func_ptr,
628c2ecf20Sopenharmony_ci				     u8 *name)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	init_completion(&thread->completion);
658c2ecf20Sopenharmony_ci	atomic_set(&thread->thread_done, 0);
668c2ecf20Sopenharmony_ci	thread->task = kthread_run(func_ptr, common, "%s", name);
678c2ecf20Sopenharmony_ci	if (IS_ERR(thread->task))
688c2ecf20Sopenharmony_ci		return (int)PTR_ERR(thread->task);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	return 0;
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic inline int rsi_kill_thread(struct rsi_thread *handle)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci	atomic_inc(&handle->thread_done);
768c2ecf20Sopenharmony_ci	rsi_set_event(&handle->event);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	return kthread_stop(handle->task);
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_civoid rsi_mac80211_detach(struct rsi_hw *hw);
828c2ecf20Sopenharmony_ciu16 rsi_get_connected_channel(struct ieee80211_vif *vif);
838c2ecf20Sopenharmony_cistruct rsi_hw *rsi_91x_init(u16 oper_mode);
848c2ecf20Sopenharmony_civoid rsi_91x_deinit(struct rsi_hw *adapter);
858c2ecf20Sopenharmony_ciint rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len);
868c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
878c2ecf20Sopenharmony_ciint rsi_config_wowlan(struct rsi_hw *adapter, struct cfg80211_wowlan *wowlan);
888c2ecf20Sopenharmony_ci#endif
898c2ecf20Sopenharmony_cistruct rsi_sta *rsi_find_sta(struct rsi_common *common, u8 *mac_addr);
908c2ecf20Sopenharmony_cistruct ieee80211_vif *rsi_get_vif(struct rsi_hw *adapter, u8 *mac);
918c2ecf20Sopenharmony_civoid rsi_roc_timeout(struct timer_list *t);
928c2ecf20Sopenharmony_ci#endif
93