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