1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 #ifndef __OSDEP_LINUX_SERVICE_H_
8 #define __OSDEP_LINUX_SERVICE_H_
9 
10 	#include <linux/spinlock.h>
11 	#include <linux/compiler.h>
12 	#include <linux/kernel.h>
13 	#include <linux/errno.h>
14 	#include <linux/init.h>
15 	#include <linux/slab.h>
16 	#include <linux/module.h>
17 	#include <linux/kref.h>
18 	/* include <linux/smp_lock.h> */
19 	#include <linux/netdevice.h>
20 	#include <linux/skbuff.h>
21 	#include <linux/uaccess.h>
22 	#include <asm/byteorder.h>
23 	#include <linux/atomic.h>
24 	#include <linux/io.h>
25 	#include <linux/semaphore.h>
26 	#include <linux/sem.h>
27 	#include <linux/sched.h>
28 	#include <linux/etherdevice.h>
29 	#include <linux/wireless.h>
30 	#include <net/iw_handler.h>
31 	#include <linux/if_arp.h>
32 	#include <linux/rtnetlink.h>
33 	#include <linux/delay.h>
34 	#include <linux/interrupt.h>	/*  for struct tasklet_struct */
35 	#include <linux/ip.h>
36 	#include <linux/kthread.h>
37 	#include <linux/list.h>
38 	#include <linux/vmalloc.h>
39 
40 /* 	#include <linux/ieee80211.h> */
41         #include <net/ieee80211_radiotap.h>
42 	#include <net/cfg80211.h>
43 
44 	typedef struct	semaphore _sema;
45 	typedef	spinlock_t	_lock;
46 	typedef struct mutex		_mutex;
47 	typedef struct timer_list _timer;
48 
49 	struct	__queue	{
50 		struct	list_head	queue;
51 		_lock	lock;
52 	};
53 
54 	typedef	struct sk_buff	_pkt;
55 	typedef unsigned char _buffer;
56 
57 	typedef	int	_OS_STATUS;
58 	/* typedef u32 _irqL; */
59 	typedef unsigned long _irqL;
60 	typedef	struct	net_device * _nic_hdl;
61 
62 	#define thread_exit() complete_and_exit(NULL, 0)
63 
64 	typedef void timer_hdl_return;
65 	typedef void* timer_hdl_context;
66 
67 	typedef struct work_struct _workitem;
68 
get_next(struct list_head * list)69 __inline static struct list_head *get_next(struct list_head	*list)
70 {
71 	return list->next;
72 }
73 
get_list_head(struct __queue * queue)74 __inline static struct list_head	*get_list_head(struct __queue	*queue)
75 {
76 	return (&(queue->queue));
77 }
78 
79 
80 #define LIST_CONTAINOR(ptr, type, member) \
81 	container_of(ptr, type, member)
82 
_set_timer(_timer * ptimer,u32 delay_time)83 __inline static void _set_timer(_timer *ptimer, u32 delay_time)
84 {
85 	mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
86 }
87 
_cancel_timer(_timer * ptimer,u8 * bcancelled)88 __inline static void _cancel_timer(_timer *ptimer, u8 *bcancelled)
89 {
90 	del_timer_sync(ptimer);
91 	*bcancelled =  true;/* true == 1; false == 0 */
92 }
93 
_init_workitem(_workitem * pwork,void * pfunc,void * cntx)94 __inline static void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
95 {
96 	INIT_WORK(pwork, pfunc);
97 }
98 
_set_workitem(_workitem * pwork)99 __inline static void _set_workitem(_workitem *pwork)
100 {
101 	schedule_work(pwork);
102 }
103 
_cancel_workitem_sync(_workitem * pwork)104 __inline static void _cancel_workitem_sync(_workitem *pwork)
105 {
106 	cancel_work_sync(pwork);
107 }
108 
rtw_netif_queue_stopped(struct net_device * pnetdev)109 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
110 {
111 	return (netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
112 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
113 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
114 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3)));
115 }
116 
rtw_netif_wake_queue(struct net_device * pnetdev)117 static inline void rtw_netif_wake_queue(struct net_device *pnetdev)
118 {
119 	netif_tx_wake_all_queues(pnetdev);
120 }
121 
rtw_netif_start_queue(struct net_device * pnetdev)122 static inline void rtw_netif_start_queue(struct net_device *pnetdev)
123 {
124 	netif_tx_start_all_queues(pnetdev);
125 }
126 
rtw_netif_stop_queue(struct net_device * pnetdev)127 static inline void rtw_netif_stop_queue(struct net_device *pnetdev)
128 {
129 	netif_tx_stop_all_queues(pnetdev);
130 }
131 
rtw_merge_string(char * dst,int dst_len,char * src1,char * src2)132 static inline void rtw_merge_string(char *dst, int dst_len, char *src1, char *src2)
133 {
134 	int	len = 0;
135 	len += snprintf(dst+len, dst_len - len, "%s", src1);
136 	len += snprintf(dst+len, dst_len - len, "%s", src2);
137 }
138 
139 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)), (sig), 1)
140 
141 #define rtw_netdev_priv(netdev) (((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
142 
143 #define NDEV_FMT "%s"
144 #define NDEV_ARG(ndev) ndev->name
145 #define ADPT_FMT "%s"
146 #define ADPT_ARG(adapter) adapter->pnetdev->name
147 #define FUNC_NDEV_FMT "%s(%s)"
148 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
149 #define FUNC_ADPT_FMT "%s(%s)"
150 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
151 
152 struct rtw_netdev_priv_indicator {
153 	void *priv;
154 	u32 sizeof_priv;
155 };
156 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv);
157 extern struct net_device * rtw_alloc_etherdev(int sizeof_priv);
158 
159 #endif
160