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