]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/cxt1e1/sbecom_inline_linux.h
Staging: cxt1e1: fix cxt1e1 module names
[net-next-2.6.git] / drivers / staging / cxt1e1 / sbecom_inline_linux.h
CommitLineData
50ee11fe
BB
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 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
52#include <linux/config.h>
53#endif
54#if defined(CONFIG_SMP) && ! defined(__SMP__)
55#define __SMP__
56#endif
57#if defined(CONFIG_MODVERSIONS) && defined(MODULE) && ! defined(MODVERSIONS)
58#define MODVERSIONS
59#endif
60
61#ifdef MODULE
62#ifdef MODVERSIONS
63#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
64#include <linux/modversions.h>
65#else
66#include <config/modversions.h>
67#endif
68#endif
69#include <linux/module.h>
70#endif
71#endif
72
73#include <linux/kernel.h> /* resolves kmalloc references */
74#include <linux/skbuff.h> /* resolves skb references */
75#include <linux/netdevice.h> /* resolves dev_kree_skb_any */
76#include <asm/byteorder.h> /* resolves cpu_to_le32 */
77
78#if 0
79
80/*** PORT POINT WARNING
81 ***
82 *** Under Linux 2.6 it has been found that compiler is re-ordering
83 *** in-lined pci_write_32() functions to the detrement of correct
84 *** hardware setup. Therefore, inlining of PCI accesses has been
85 *** de-implemented, and subroutine calls have been implemented.
86 ***/
87
88static inline u_int32_t
89pci_read_32 (u_int32_t *p)
90{
91#ifdef FLOW_DEBUG
92 u_int32_t v;
93
94 FLUSH_PCI_READ ();
95 v = le32_to_cpu (*p);
96 if (log_level >= LOG_DEBUG)
97 printk ("pci_read : %x = %x\n", (u_int32_t) p, v);
98 return v;
99#else
100 FLUSH_PCI_READ (); /* */
101 return le32_to_cpu (*p);
102#endif
103}
104
105static inline void
106pci_write_32 (u_int32_t *p, u_int32_t v)
107{
108#ifdef FLOW_DEBUG
109 if (log_level >= LOG_DEBUG)
110 printk ("pci_write: %x = %x\n", (u_int32_t) p, v);
111#endif
112 *p = cpu_to_le32 (v);
113 FLUSH_PCI_WRITE (); /* This routine is called from routines
114 * which do multiple register writes
115 * which themselves need flushing between
116 * writes in order to guarantee write
117 * ordering. It is less code-cumbersome
118 * to flush here-in then to investigate
119 * and code the many other register
120 * writing routines. */
121}
122#else
123/* forward reference */
124u_int32_t pci_read_32 (u_int32_t *p);
125void pci_write_32 (u_int32_t *p, u_int32_t v);
126
127#endif
128
129
130/*
131 * system dependent callbacks
132 */
133
134/**********/
135/* malloc */
136/**********/
137
138static inline void *
139OS_kmalloc (size_t size)
140{
141 char *ptr = kmalloc (size, GFP_KERNEL | GFP_DMA);
142
143 if (ptr)
144 memset (ptr, 0, size);
145 return ptr;
146}
147
148static inline void
149OS_kfree (void *x)
150{
151 kfree (x);
152}
153
154
155/****************/
156/* memory token */
157/****************/
158
159static inline void *
160OS_mem_token_alloc (size_t size)
161{
162 struct sk_buff *skb;
163
164 skb = dev_alloc_skb (size);
165 if (!skb)
166 {
e6e4d05d 167 //pr_warning("no mem in OS_mem_token_alloc !\n");
50ee11fe
BB
168 return 0;
169 }
170 return skb;
171}
172
173
174static inline void
175OS_mem_token_free (void *token)
176{
177 dev_kfree_skb_any (token);
178}
179
180
181static inline void
182OS_mem_token_free_irq (void *token)
183{
184 dev_kfree_skb_irq (token);
185}
186
187
188static inline void *
189OS_mem_token_data (void *token)
190{
191 return ((struct sk_buff *) token)->data;
192}
193
194
195static inline void *
196OS_mem_token_next (void *token)
197{
198 return 0;
199}
200
201
202static inline int
203OS_mem_token_len (void *token)
204{
205 return ((struct sk_buff *) token)->len;
206}
207
208
209static inline int
210OS_mem_token_tlen (void *token)
211{
212 return ((struct sk_buff *) token)->len;
213}
214
215
216/***************************************/
217/* virtual to physical addr conversion */
218/***************************************/
219
220static inline u_long
221OS_phystov (void *addr)
222{
223 return (u_long) __va (addr);
224}
225
226
227static inline u_long
228OS_vtophys (void *addr)
229{
230 return __pa (addr);
231}
232
233
234/**********/
235/* semops */
236/**********/
237
238void OS_sem_init (void *, int);
239
240
241static inline void
242OS_sem_free (void *sem)
243{
244 /*
245 * NOOP - since semaphores structures predeclared w/in structures, no
246 * longer malloc'd
247 */
248}
249
250#define SD_SEM_TAKE(sem,desc) down(sem)
251#define SD_SEM_GIVE(sem) up(sem)
252#define SEM_AVAILABLE 1
253#define SEM_TAKEN 0
254
255
256/**********************/
257/* watchdog functions */
258/**********************/
259
260struct watchdog
261{
262 struct timer_list h;
263#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
264 struct tq_struct tq;
265#else
266 struct work_struct work;
267#endif
268 void *softc;
269 void (*func) (void *softc);
270 int ticks;
271 int init_tq;
272};
273
274
275static inline int
276OS_start_watchdog (struct watchdog * wd)
277{
278 wd->h.expires = jiffies + wd->ticks;
279 add_timer (&wd->h);
280 return 0;
281}
282
283
284static inline int
285OS_stop_watchdog (struct watchdog * wd)
286{
287 del_timer_sync (&wd->h);
288 return 0;
289}
290
291
292static inline int
293OS_free_watchdog (struct watchdog * wd)
294{
295 OS_stop_watchdog (wd);
296 OS_kfree (wd);
297 return 0;
298}
299
300
301/* sleep in microseconds */
302void OS_uwait (int usec, char *description);
303void OS_uwait_dummy (void);
304
305
306/* watchdog functions */
307int OS_init_watchdog(struct watchdog *wdp, void (*f) (void *), void *ci, int usec);
308
309
310#endif /*** _INC_SBECOM_INLNX_H_ ***/