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/netdevice.h>
19 #include <linux/skbuff.h>
20 #include <linux/uaccess.h>
21 #include <asm/byteorder.h>
22 #include <linux/atomic.h>
23 #include <linux/io.h>
24 #include <linux/sem.h>
25 #include <linux/sched.h>
26 #include <linux/etherdevice.h>
27 #include <linux/wireless.h>
28 #include <net/iw_handler.h>
29 #include <linux/if_arp.h>
30 #include <linux/rtnetlink.h>
31 #include <linux/delay.h>
32 #include <linux/interrupt.h>	/*  for struct tasklet_struct */
33 #include <linux/ip.h>
34 #include <linux/kthread.h>
35 #include <linux/list.h>
36 #include <linux/vmalloc.h>
37 
38 #include <net/ieee80211_radiotap.h>
39 #include <net/cfg80211.h>
40 
41 struct	__queue	{
42 	struct	list_head	queue;
43 	spinlock_t	lock;
44 };
45 
get_next(struct list_head * list)46 static inline struct list_head *get_next(struct list_head	*list)
47 {
48 	return list->next;
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 + (delay_time * HZ / 1000)));
59 }
60 
_init_workitem(struct work_struct * pwork,void * pfunc,void * cntx)61 static inline void _init_workitem(struct work_struct *pwork, void *pfunc, void *cntx)
62 {
63 	INIT_WORK(pwork, pfunc);
64 }
65 
_set_workitem(struct work_struct * pwork)66 static inline void _set_workitem(struct work_struct *pwork)
67 {
68 	schedule_work(pwork);
69 }
70 
_cancel_workitem_sync(struct work_struct * pwork)71 static inline void _cancel_workitem_sync(struct work_struct *pwork)
72 {
73 	cancel_work_sync(pwork);
74 }
75 
rtw_netif_queue_stopped(struct net_device * pnetdev)76 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
77 {
78 	return (netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
79 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
80 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
81 		netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3)));
82 }
83 
rtw_netif_wake_queue(struct net_device * pnetdev)84 static inline void rtw_netif_wake_queue(struct net_device *pnetdev)
85 {
86 	netif_tx_wake_all_queues(pnetdev);
87 }
88 
rtw_netif_start_queue(struct net_device * pnetdev)89 static inline void rtw_netif_start_queue(struct net_device *pnetdev)
90 {
91 	netif_tx_start_all_queues(pnetdev);
92 }
93 
rtw_netif_stop_queue(struct net_device * pnetdev)94 static inline void rtw_netif_stop_queue(struct net_device *pnetdev)
95 {
96 	netif_tx_stop_all_queues(pnetdev);
97 }
98 
99 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)), (sig), 1)
100 
101 #define NDEV_ARG(ndev) ndev->name
102 #define ADPT_ARG(adapter) adapter->pnetdev->name
103 #define FUNC_NDEV_FMT "%s(%s)"
104 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
105 #define FUNC_ADPT_FMT "%s(%s)"
106 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
107 
108 struct rtw_netdev_priv_indicator {
109 	void *priv;
110 	u32 sizeof_priv;
111 };
112 
rtw_netdev_priv(struct net_device * netdev)113 static inline struct adapter *rtw_netdev_priv(struct net_device *netdev)
114 {
115 	return ((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv;
116 }
117 
118 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv);
119 extern struct net_device *rtw_alloc_etherdev(int sizeof_priv);
120 
121 #endif
122