Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[pandora-kernel.git] / drivers / staging / cxt1e1 / sbecom_inline_linux.h
1 /*
2  * $Id: sbecom_inline_linux.h,v 1.2 2007/08/15 22:51:35 rickd PMCC4_3_1B $
3  */
4
5 #ifndef _INC_SBECOM_INLNX_H_
6 #define _INC_SBECOM_INLNX_H_
7
8 /*-----------------------------------------------------------------------------
9  * sbecom_inline_linux.h - SBE common Linux inlined routines
10  *
11  * Copyright (C) 2007  One Stop Systems, Inc.
12  * Copyright (C) 2005  SBE, Inc.
13  *
14  *   This program is free software; you can redistribute it and/or modify
15  *   it under the terms of the GNU General Public License as published by
16  *   the Free Software Foundation; either version 2 of the License, or
17  *   (at your option) any later version.
18  *
19  *   This program is distributed in the hope that it will be useful,
20  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   GNU General Public License for more details.
23  *
24  * For further information, contact via email: support@onestopsystems.com
25  * One Stop Systems, Inc.  Escondido, California  U.S.A.
26  *-----------------------------------------------------------------------------
27  * RCS info:
28  * RCS revision: $Revision: 1.2 $
29  * Last changed on $Date: 2007/08/15 22:51:35 $
30  * Changed by $Author: rickd $
31  *-----------------------------------------------------------------------------
32  * $Log: sbecom_inline_linux.h,v $
33  * Revision 1.2  2007/08/15 22:51:35  rickd
34  * Remove duplicate version.h entry.
35  *
36  * Revision 1.1  2007/08/15 22:50:29  rickd
37  * Update linux/config for 2.6.18 and later.
38  *
39  * Revision 1.0  2005/09/28 00:10:09  rickd
40  * Initial revision
41  *
42  *-----------------------------------------------------------------------------
43  */
44
45
46 #if defined (__FreeBSD__) || defined (__NetBSD__)
47 #include <sys/types.h>
48 #else
49 #include <linux/types.h>
50 #include <linux/version.h>
51 #if defined(CONFIG_SMP) && ! defined(__SMP__)
52 #define __SMP__
53 #endif
54 #if defined(CONFIG_MODVERSIONS) && defined(MODULE) && ! defined(MODVERSIONS)
55 #define MODVERSIONS
56 #endif
57
58 #ifdef MODULE
59 #ifdef MODVERSIONS
60 #include <config/modversions.h>
61 #endif
62 #include <linux/module.h>
63 #endif
64 #endif
65
66 #include <linux/kernel.h>       /* resolves kmalloc references */
67 #include <linux/skbuff.h>       /* resolves skb references */
68 #include <linux/netdevice.h>    /* resolves dev_kree_skb_any */
69 #include <asm/byteorder.h>      /* resolves cpu_to_le32 */
70
71 #if 0
72
73 /*** PORT POINT WARNING
74  ***
75  *** Under Linux 2.6 it has been found that compiler is re-ordering
76  *** in-lined pci_write_32() functions to the detrement of correct
77  *** hardware setup.  Therefore, inlining of PCI accesses has been
78  *** de-implemented, and subroutine calls have been implemented.
79  ***/
80
81 static inline u_int32_t
82 pci_read_32 (u_int32_t *p)
83 {
84 #ifdef FLOW_DEBUG
85     u_int32_t   v;
86
87     FLUSH_PCI_READ ();
88     v = le32_to_cpu (*p);
89     if (cxt1e1_log_level >= LOG_DEBUG)
90         pr_info("pci_read : %x = %x\n", (u_int32_t) p, v);
91     return v;
92 #else
93                 FLUSH_PCI_READ ();      /* */
94     return le32_to_cpu (*p);
95 #endif
96 }
97
98 static inline void
99 pci_write_32 (u_int32_t *p, u_int32_t v)
100 {
101 #ifdef FLOW_DEBUG
102     if (cxt1e1_log_level >= LOG_DEBUG)
103         pr_info("pci_write: %x = %x\n", (u_int32_t) p, v);
104 #endif
105     *p = cpu_to_le32 (v);
106     FLUSH_PCI_WRITE ();             /* This routine is called from routines
107                                      * which do multiple register writes
108                                      * which themselves need flushing between
109                                      * writes in order to guarantee write
110                                      * ordering.  It is less code-cumbersome
111                                      * to flush here-in then to investigate
112                                      * and code the many other register
113                                      * writing routines. */
114 }
115 #else
116 /* forward reference */
117 u_int32_t   pci_read_32 (u_int32_t *p);
118 void        pci_write_32 (u_int32_t *p, u_int32_t v);
119
120 #endif
121
122
123 /*
124  * system dependent callbacks
125  */
126
127 /**********/
128 /* malloc */
129 /**********/
130
131 static inline void *
132 OS_kmalloc (size_t size)
133 {
134     char       *ptr = kmalloc (size, GFP_KERNEL | GFP_DMA);
135
136     if (ptr)
137         memset (ptr, 0, size);
138     return ptr;
139 }
140
141 static inline void
142 OS_kfree (void *x)
143 {
144     kfree (x);
145 }
146
147
148 /****************/
149 /* memory token */
150 /****************/
151
152 static inline void *
153 OS_mem_token_alloc (size_t size)
154 {
155     struct sk_buff *skb;
156
157     skb = dev_alloc_skb (size);
158     if (!skb)
159     {
160         //pr_warning("no mem in OS_mem_token_alloc !\n");
161         return 0;
162     }
163     return skb;
164 }
165
166
167 static inline void
168 OS_mem_token_free (void *token)
169 {
170     dev_kfree_skb_any (token);
171 }
172
173
174 static inline void
175 OS_mem_token_free_irq (void *token)
176 {
177     dev_kfree_skb_irq (token);
178 }
179
180
181 static inline void *
182 OS_mem_token_data (void *token)
183 {
184     return ((struct sk_buff *) token)->data;
185 }
186
187
188 static inline void *
189 OS_mem_token_next (void *token)
190 {
191     return 0;
192 }
193
194
195 static inline int
196 OS_mem_token_len (void *token)
197 {
198     return ((struct sk_buff *) token)->len;
199 }
200
201
202 static inline int
203 OS_mem_token_tlen (void *token)
204 {
205     return ((struct sk_buff *) token)->len;
206 }
207
208
209 /***************************************/
210 /* virtual to physical addr conversion */
211 /***************************************/
212
213 static inline u_long
214 OS_phystov (void *addr)
215 {
216     return (u_long) __va (addr);
217 }
218
219
220 static inline u_long
221 OS_vtophys (void *addr)
222 {
223     return __pa (addr);
224 }
225
226
227 /**********/
228 /* semops */
229 /**********/
230
231 void        OS_sem_init (void *, int);
232
233
234 static inline void
235 OS_sem_free (void *sem)
236 {
237     /*
238      * NOOP - since semaphores structures predeclared w/in structures, no
239      * longer malloc'd
240      */
241 }
242
243 #define SD_SEM_TAKE(sem,desc)  down(sem)
244 #define SD_SEM_GIVE(sem)       up(sem)
245 #define SEM_AVAILABLE     1
246 #define SEM_TAKEN         0
247
248
249 /**********************/
250 /* watchdog functions */
251 /**********************/
252
253 struct watchdog
254 {
255     struct timer_list h;
256     struct work_struct work;
257     void       *softc;
258     void        (*func) (void *softc);
259     int         ticks;
260     int         init_tq;
261 };
262
263
264 static inline int
265 OS_start_watchdog (struct watchdog * wd)
266 {
267     wd->h.expires = jiffies + wd->ticks;
268     add_timer (&wd->h);
269     return 0;
270 }
271
272
273 static inline int
274 OS_stop_watchdog (struct watchdog * wd)
275 {
276     del_timer_sync (&wd->h);
277     return 0;
278 }
279
280
281 static inline int
282 OS_free_watchdog (struct watchdog * wd)
283 {
284     OS_stop_watchdog (wd);
285     OS_kfree (wd);
286     return 0;
287 }
288
289
290 /* sleep in microseconds */
291 void        OS_uwait (int usec, char *description);
292 void        OS_uwait_dummy (void);
293
294
295 /* watchdog functions */
296 int OS_init_watchdog(struct watchdog *wdp, void (*f) (void *), void *ci, int usec);
297
298
299 #endif                          /*** _INC_SBECOM_INLNX_H_ ***/