1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3 
4 #ifndef __OSDEP_SERVICE_H_
5 #define __OSDEP_SERVICE_H_
6 
7 #include <linux/sched/signal.h>
8 
9 #define _FAIL		0
10 #define _SUCCESS	1
11 #define RTW_RX_HANDLED 2
12 
13 #include <linux/spinlock.h>
14 #include <linux/compiler.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
20 #include <linux/kref.h>
21 #include <linux/netdevice.h>
22 #include <linux/skbuff.h>
23 #include <linux/circ_buf.h>
24 #include <linux/uaccess.h>
25 #include <asm/byteorder.h>
26 #include <asm/atomic.h>
27 #include <linux/io.h>
28 #include <linux/semaphore.h>
29 #include <linux/sem.h>
30 #include <linux/sched.h>
31 #include <linux/etherdevice.h>
32 #include <linux/wireless.h>
33 #include <net/iw_handler.h>
34 #include <linux/if_arp.h>
35 #include <linux/rtnetlink.h>
36 #include <linux/delay.h>
37 #include <linux/proc_fs.h>	/*  Necessary because we use the proc fs */
38 #include <linux/interrupt.h>	/*  for struct tasklet_struct */
39 #include <linux/ip.h>
40 #include <linux/kthread.h>
41 #include <linux/vmalloc.h>
42 
43 #include <linux/usb.h>
44 #include <linux/usb/ch9.h>
45 
46 struct	__queue	{
47 	struct	list_head	queue;
48 	spinlock_t lock;
49 };
50 
get_list_head(struct __queue * queue)51 static inline struct list_head *get_list_head(struct __queue *queue)
52 {
53 	return (&(queue->queue));
54 }
55 
_set_timer(struct timer_list * ptimer,u32 delay_time)56 static inline void _set_timer(struct timer_list *ptimer,u32 delay_time)
57 {
58 	mod_timer(ptimer, jiffies + msecs_to_jiffies(delay_time));
59 }
60 
rtw_netif_queue_stopped(struct net_device * pnetdev)61 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
62 {
63 	return  netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
64 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
65 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
66 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3));
67 }
68 
69 extern int RTW_STATUS_CODE(int error_code);
70 
71 void *rtw_malloc2d(int h, int w, int size);
72 
73 #define rtw_init_queue(q)					\
74 	do {							\
75 		INIT_LIST_HEAD(&((q)->queue));			\
76 		spin_lock_init(&((q)->lock));			\
77 	} while (0)
78 
_cancel_timer_ex(struct timer_list * ptimer)79 static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
80 {
81 	return del_timer_sync(ptimer);
82 }
83 
flush_signals_thread(void)84 static inline void flush_signals_thread(void)
85 {
86 	if (signal_pending (current))
87 		flush_signals(current);
88 }
89 
90 struct rtw_netdev_priv_indicator {
91 	void *priv;
92 	u32 sizeof_priv;
93 };
94 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
95 						    void *old_priv);
96 struct net_device *rtw_alloc_etherdev(int sizeof_priv);
97 
98 #define rtw_netdev_priv(netdev)					\
99 	(((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
100 void rtw_free_netdev(struct net_device *netdev);
101 
102 #define NDEV_FMT "%s"
103 #define NDEV_ARG(ndev) ndev->name
104 #define ADPT_FMT "%s"
105 #define ADPT_ARG(adapter) adapter->pnetdev->name
106 #define FUNC_NDEV_FMT "%s(%s)"
107 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
108 #define FUNC_ADPT_FMT "%s(%s)"
109 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
110 
111 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)),(sig), 1)
112 
113 /* Macros for handling unaligned memory accesses */
114 
115 #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
116 #define RTW_PUT_BE16(a, val)			\
117 	do {					\
118 		(a)[0] = ((u16) (val)) >> 8;	\
119 		(a)[1] = ((u16) (val)) & 0xff;	\
120 	} while (0)
121 
122 #define RTW_PUT_LE16(a, val)			\
123 	do {					\
124 		(a)[1] = ((u16) (val)) >> 8;	\
125 		(a)[0] = ((u16) (val)) & 0xff;	\
126 	} while (0)
127 
128 #define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
129 			 ((u32) (a)[2]))
130 
131 #define RTW_PUT_BE32(a, val)					\
132 	do {							\
133 		(a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff);	\
134 		(a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff);	\
135 		(a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff);	\
136 		(a)[3] = (u8) (((u32) (val)) & 0xff);		\
137 	} while (0)
138 
139 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len);
140 
141 struct rtw_cbuf {
142 	u32 write;
143 	u32 read;
144 	u32 size;
145 	void *bufs[];
146 };
147 
148 bool rtw_cbuf_empty(struct rtw_cbuf *cbuf);
149 void *rtw_cbuf_pop(struct rtw_cbuf *cbuf);
150 struct rtw_cbuf *rtw_cbuf_alloc(u32 size);
151 int wifirate2_ratetbl_inx(unsigned char rate);
152 
153 #endif
154