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