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