• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/drivers/staging/cxt1e1/
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/* forward reference */
72u_int32_t   pci_read_32 (u_int32_t *p);
73void        pci_write_32 (u_int32_t *p, u_int32_t v);
74
75
76/*
77 * system dependent callbacks
78 */
79
80/**********/
81/* malloc */
82/**********/
83
84static inline void *
85OS_kmalloc (size_t size)
86{
87    char       *ptr = kmalloc (size, GFP_KERNEL | GFP_DMA);
88
89    if (ptr)
90        memset (ptr, 0, size);
91    return ptr;
92}
93
94static inline void
95OS_kfree (void *x)
96{
97    kfree (x);
98}
99
100
101/****************/
102/* memory token */
103/****************/
104
105static inline void *
106OS_mem_token_alloc (size_t size)
107{
108    struct sk_buff *skb;
109
110    skb = dev_alloc_skb (size);
111    if (!skb)
112    {
113        //pr_warning("no mem in OS_mem_token_alloc !\n");
114        return 0;
115    }
116    return skb;
117}
118
119
120static inline void
121OS_mem_token_free (void *token)
122{
123    dev_kfree_skb_any (token);
124}
125
126
127static inline void
128OS_mem_token_free_irq (void *token)
129{
130    dev_kfree_skb_irq (token);
131}
132
133
134static inline void *
135OS_mem_token_data (void *token)
136{
137    return ((struct sk_buff *) token)->data;
138}
139
140
141static inline void *
142OS_mem_token_next (void *token)
143{
144    return 0;
145}
146
147
148static inline int
149OS_mem_token_len (void *token)
150{
151    return ((struct sk_buff *) token)->len;
152}
153
154
155static inline int
156OS_mem_token_tlen (void *token)
157{
158    return ((struct sk_buff *) token)->len;
159}
160
161
162/***************************************/
163/* virtual to physical addr conversion */
164/***************************************/
165
166static inline u_long
167OS_phystov (void *addr)
168{
169    return (u_long) __va (addr);
170}
171
172
173static inline u_long
174OS_vtophys (void *addr)
175{
176    return __pa (addr);
177}
178
179
180/**********/
181/* semops */
182/**********/
183
184void        OS_sem_init (void *, int);
185
186
187static inline void
188OS_sem_free (void *sem)
189{
190    /*
191     * NOOP - since semaphores structures predeclared w/in structures, no
192     * longer malloc'd
193     */
194}
195
196#define SD_SEM_TAKE(sem,desc)  down(sem)
197#define SD_SEM_GIVE(sem)       up(sem)
198#define SEM_AVAILABLE     1
199#define SEM_TAKEN         0
200
201
202/**********************/
203/* watchdog functions */
204/**********************/
205
206struct watchdog
207{
208    struct timer_list h;
209    struct work_struct work;
210    void       *softc;
211    void        (*func) (void *softc);
212    int         ticks;
213    int         init_tq;
214};
215
216
217static inline int
218OS_start_watchdog (struct watchdog * wd)
219{
220    wd->h.expires = jiffies + wd->ticks;
221    add_timer (&wd->h);
222    return 0;
223}
224
225
226static inline int
227OS_stop_watchdog (struct watchdog * wd)
228{
229    del_timer_sync (&wd->h);
230    return 0;
231}
232
233
234static inline int
235OS_free_watchdog (struct watchdog * wd)
236{
237    OS_stop_watchdog (wd);
238    OS_kfree (wd);
239    return 0;
240}
241
242
243/* sleep in microseconds */
244void        OS_uwait (int usec, char *description);
245void        OS_uwait_dummy (void);
246
247
248/* watchdog functions */
249int OS_init_watchdog(struct watchdog *wdp, void (*f) (void *), void *ci, int usec);
250
251
252#endif                          /*** _INC_SBECOM_INLNX_H_ ***/
253