Ali Bahar | cf3e688 | 2011-09-04 03:14:04 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. |
| 4 | * |
| 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. |
| 8 | * |
| 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 |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * Modifications for inclusion into the Linux staging tree are |
| 19 | * Copyright(c) 2010 Larry Finger. All rights reserved. |
| 20 | * |
| 21 | * Contact information: |
| 22 | * WLAN FAE <wlanfae@realtek.com> |
| 23 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 24 | * |
| 25 | ******************************************************************************/ |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 26 | #ifndef __OSDEP_SERVICE_H_ |
| 27 | #define __OSDEP_SERVICE_H_ |
| 28 | |
| 29 | #define _SUCCESS 1 |
| 30 | #define _FAIL 0 |
| 31 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 32 | #include <linux/spinlock.h> |
Ali Bahar | 359140a | 2011-09-04 03:14:11 +0800 | [diff] [blame] | 33 | |
| 34 | #include <linux/interrupt.h> |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 35 | #include <linux/semaphore.h> |
Ali Bahar | 359140a | 2011-09-04 03:14:11 +0800 | [diff] [blame] | 36 | #include <linux/sched.h> |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 37 | #include <linux/sem.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/etherdevice.h> |
| 40 | #include <net/iw_handler.h> |
Ali Bahar | 359140a | 2011-09-04 03:14:11 +0800 | [diff] [blame] | 41 | #include <linux/proc_fs.h> /* Necessary because we use the proc fs */ |
| 42 | |
| 43 | #include "basic_types.h" |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 44 | |
| 45 | struct __queue { |
| 46 | struct list_head queue; |
| 47 | spinlock_t lock; |
| 48 | }; |
| 49 | |
| 50 | #define _pkt struct sk_buff |
| 51 | #define _buffer unsigned char |
| 52 | #define thread_exit() complete_and_exit(NULL, 0) |
| 53 | #define _workitem struct work_struct |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 54 | |
| 55 | #define _init_queue(pqueue) \ |
| 56 | do { \ |
| 57 | _init_listhead(&((pqueue)->queue)); \ |
| 58 | spin_lock_init(&((pqueue)->lock)); \ |
| 59 | } while (0) |
| 60 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 61 | static inline struct list_head *get_next(struct list_head *list) |
| 62 | { |
| 63 | return list->next; |
| 64 | } |
| 65 | |
| 66 | static inline struct list_head *get_list_head(struct __queue *queue) |
| 67 | { |
| 68 | return &(queue->queue); |
| 69 | } |
| 70 | |
| 71 | #define LIST_CONTAINOR(ptr, type, member) \ |
| 72 | ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member))) |
| 73 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 74 | static inline void list_delete(struct list_head *plist) |
| 75 | { |
| 76 | list_del_init(plist); |
| 77 | } |
| 78 | |
| 79 | static inline void _init_timer(struct timer_list *ptimer, |
| 80 | struct net_device *padapter, |
| 81 | void *pfunc, void *cntx) |
| 82 | { |
| 83 | ptimer->function = pfunc; |
| 84 | ptimer->data = (addr_t)cntx; |
| 85 | init_timer(ptimer); |
| 86 | } |
| 87 | |
| 88 | static inline void _set_timer(struct timer_list *ptimer, u32 delay_time) |
| 89 | { |
| 90 | mod_timer(ptimer, (jiffies+(delay_time*HZ/1000))); |
| 91 | } |
| 92 | |
| 93 | static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled) |
| 94 | { |
| 95 | del_timer(ptimer); |
| 96 | *bcancelled = true; /*true ==1; false==0*/ |
| 97 | } |
| 98 | |
| 99 | static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx) |
| 100 | { |
| 101 | INIT_WORK(pwork, pfunc); |
| 102 | } |
| 103 | |
| 104 | static inline void _set_workitem(_workitem *pwork) |
| 105 | { |
| 106 | schedule_work(pwork); |
| 107 | } |
| 108 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 109 | #ifndef BIT |
| 110 | #define BIT(x) (1 << (x)) |
| 111 | #endif |
| 112 | |
| 113 | /* |
| 114 | For the following list_xxx operations, |
| 115 | caller must guarantee the atomic context. |
| 116 | Otherwise, there will be racing condition. |
| 117 | */ |
| 118 | static inline u32 is_list_empty(struct list_head *phead) |
| 119 | { |
| 120 | if (list_empty(phead)) |
| 121 | return true; |
| 122 | else |
| 123 | return false; |
| 124 | } |
| 125 | |
Javier M. Mellid | 0593758 | 2011-04-02 03:01:49 +0200 | [diff] [blame] | 126 | static inline void list_insert_tail(struct list_head *plist, |
| 127 | struct list_head *phead) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 128 | { |
| 129 | list_add_tail(plist, phead); |
| 130 | } |
| 131 | |
| 132 | static inline u32 _down_sema(struct semaphore *sema) |
| 133 | { |
| 134 | if (down_interruptible(sema)) |
| 135 | return _FAIL; |
| 136 | else |
| 137 | return _SUCCESS; |
| 138 | } |
| 139 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 140 | static inline void _init_listhead(struct list_head *list) |
| 141 | { |
| 142 | INIT_LIST_HEAD(list); |
| 143 | } |
| 144 | |
| 145 | static inline u32 _queue_empty(struct __queue *pqueue) |
| 146 | { |
| 147 | return is_list_empty(&(pqueue->queue)); |
| 148 | } |
| 149 | |
Aybuke Ozdemir | 9ab3726 | 2014-03-18 01:39:25 +0200 | [diff] [blame] | 150 | static inline u32 end_of_queue_search(struct list_head *head, |
| 151 | struct list_head *plist) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 152 | { |
| 153 | if (head == plist) |
| 154 | return true; |
| 155 | else |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | static inline void sleep_schedulable(int ms) |
| 160 | { |
| 161 | u32 delta; |
| 162 | |
| 163 | delta = (ms * HZ) / 1000;/*(ms)*/ |
| 164 | if (delta == 0) |
| 165 | delta = 1;/* 1 ms */ |
| 166 | set_current_state(TASK_INTERRUPTIBLE); |
| 167 | if (schedule_timeout(delta) != 0) |
Andreea-Cristina Bernat | 774448d | 2014-03-12 23:00:04 +0200 | [diff] [blame] | 168 | return; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 171 | static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer) |
| 172 | { |
| 173 | return del_timer(ptimer); |
| 174 | } |
| 175 | |
| 176 | static inline void thread_enter(void *context) |
| 177 | { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 178 | allow_signal(SIGTERM); |
| 179 | } |
| 180 | |
| 181 | static inline void flush_signals_thread(void) |
| 182 | { |
| 183 | if (signal_pending(current)) |
| 184 | flush_signals(current); |
| 185 | } |
| 186 | |
| 187 | static inline u32 _RND8(u32 sz) |
| 188 | { |
Larry Finger | 4c510e9 | 2010-11-07 12:22:18 -0600 | [diff] [blame] | 189 | return ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static inline u32 _RND128(u32 sz) |
| 193 | { |
Larry Finger | 4c510e9 | 2010-11-07 12:22:18 -0600 | [diff] [blame] | 194 | return ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static inline u32 _RND256(u32 sz) |
| 198 | { |
Larry Finger | 4c510e9 | 2010-11-07 12:22:18 -0600 | [diff] [blame] | 199 | return ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static inline u32 _RND512(u32 sz) |
| 203 | { |
Larry Finger | 4c510e9 | 2010-11-07 12:22:18 -0600 | [diff] [blame] | 204 | return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 205 | } |
| 206 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 207 | #endif |
| 208 | |