1 /******************************************************************************
3 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #ifndef __OSDEP_LINUX_SERVICE_H_
16 #define __OSDEP_LINUX_SERVICE_H_
18 #include <linux/spinlock.h>
19 #include <linux/compiler.h>
20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/kref.h>
26 /* include <linux/smp_lock.h> */
27 #include <linux/netdevice.h>
28 #include <linux/skbuff.h>
29 #include <linux/uaccess.h>
30 #include <asm/byteorder.h>
31 #include <linux/atomic.h>
33 #include <linux/semaphore.h>
34 #include <linux/sem.h>
35 #include <linux/sched.h>
36 #include <linux/etherdevice.h>
37 #include <linux/wireless.h>
38 #include <net/iw_handler.h>
39 #include <linux/if_arp.h>
40 #include <linux/rtnetlink.h>
41 #include <linux/delay.h>
42 #include <linux/interrupt.h> /* for struct tasklet_struct */
44 #include <linux/kthread.h>
45 #include <linux/list.h>
46 #include <linux/vmalloc.h>
48 /* #include <linux/ieee80211.h> */
49 #include <net/ieee80211_radiotap.h>
50 #include <net/cfg80211.h>
52 typedef struct semaphore _sema;
53 typedef spinlock_t _lock;
54 typedef struct mutex _mutex;
55 typedef struct timer_list _timer;
58 struct list_head queue;
62 typedef struct sk_buff _pkt;
63 typedef unsigned char _buffer;
65 typedef int _OS_STATUS;
66 /* typedef u32 _irqL; */
67 typedef unsigned long _irqL;
68 typedef struct net_device * _nic_hdl;
70 #define thread_exit() complete_and_exit(NULL, 0)
72 typedef void timer_hdl_return;
73 typedef void* timer_hdl_context;
75 typedef struct work_struct _workitem;
77 __inline static struct list_head *get_next(struct list_head *list)
82 __inline static struct list_head *get_list_head(struct __queue *queue)
84 return (&(queue->queue));
88 #define LIST_CONTAINOR(ptr, type, member) \
89 ((type *)((char *)(ptr)-(__kernel_size_t)(&((type *)0)->member)))
91 #define RTW_TIMER_HDL_ARGS void *FunctionContext
93 __inline static void _init_timer(_timer *ptimer, _nic_hdl nic_hdl, void *pfunc, void* cntx)
95 /* setup_timer(ptimer, pfunc, (u32)cntx); */
96 ptimer->function = pfunc;
97 ptimer->data = (unsigned long)cntx;
101 __inline static void _set_timer(_timer *ptimer, u32 delay_time)
103 mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
106 __inline static void _cancel_timer(_timer *ptimer, u8 *bcancelled)
108 del_timer_sync(ptimer);
109 *bcancelled = true;/* true == 1; false == 0 */
113 __inline static void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
115 INIT_WORK(pwork, pfunc);
118 __inline static void _set_workitem(_workitem *pwork)
120 schedule_work(pwork);
123 __inline static void _cancel_workitem_sync(_workitem *pwork)
125 cancel_work_sync(pwork);
128 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
130 return (netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
131 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
132 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
133 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3)));
136 static inline void rtw_netif_wake_queue(struct net_device *pnetdev)
138 netif_tx_wake_all_queues(pnetdev);
141 static inline void rtw_netif_start_queue(struct net_device *pnetdev)
143 netif_tx_start_all_queues(pnetdev);
146 static inline void rtw_netif_stop_queue(struct net_device *pnetdev)
148 netif_tx_stop_all_queues(pnetdev);
151 static inline void rtw_merge_string(char *dst, int dst_len, char *src1, char *src2)
154 len += snprintf(dst+len, dst_len - len, "%s", src1);
155 len += snprintf(dst+len, dst_len - len, "%s", src2);
158 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)), (sig), 1)
160 #define rtw_netdev_priv(netdev) (((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
162 #define NDEV_FMT "%s"
163 #define NDEV_ARG(ndev) ndev->name
164 #define ADPT_FMT "%s"
165 #define ADPT_ARG(adapter) adapter->pnetdev->name
166 #define FUNC_NDEV_FMT "%s(%s)"
167 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
168 #define FUNC_ADPT_FMT "%s(%s)"
169 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
171 struct rtw_netdev_priv_indicator {
175 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv);
176 extern struct net_device * rtw_alloc_etherdev(int sizeof_priv);