blob: f5835c29ef324783dc3e16a72f283d9d0239ff84 [file] [log] [blame]
Bob Beers50ee11f2010-03-04 08:40:46 -05001#ifndef _INC_SBECOM_INLNX_H_
2#define _INC_SBECOM_INLNX_H_
3
4/*-----------------------------------------------------------------------------
5 * sbecom_inline_linux.h - SBE common Linux inlined routines
6 *
7 * Copyright (C) 2007 One Stop Systems, Inc.
8 * Copyright (C) 2005 SBE, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * For further information, contact via email: support@onestopsystems.com
21 * One Stop Systems, Inc. Escondido, California U.S.A.
22 *-----------------------------------------------------------------------------
Bob Beers50ee11f2010-03-04 08:40:46 -050023 */
24
25
Bob Beers50ee11f2010-03-04 08:40:46 -050026#include <linux/types.h>
Bob Beers50ee11f2010-03-04 08:40:46 -050027#include <linux/module.h>
Bob Beers50ee11f2010-03-04 08:40:46 -050028#include <linux/kernel.h> /* resolves kmalloc references */
29#include <linux/skbuff.h> /* resolves skb references */
30#include <linux/netdevice.h> /* resolves dev_kree_skb_any */
31#include <asm/byteorder.h> /* resolves cpu_to_le32 */
32
Bob Beers50ee11f2010-03-04 08:40:46 -050033/* forward reference */
34u_int32_t pci_read_32 (u_int32_t *p);
35void pci_write_32 (u_int32_t *p, u_int32_t v);
36
Bob Beers50ee11f2010-03-04 08:40:46 -050037
38/*
39 * system dependent callbacks
40 */
41
Bob Beers50ee11f2010-03-04 08:40:46 -050042/****************/
43/* memory token */
44/****************/
45
46static inline void *
47OS_mem_token_alloc (size_t size)
48{
49 struct sk_buff *skb;
50
51 skb = dev_alloc_skb (size);
52 if (!skb)
53 {
Joe Perchese6e4d052010-05-03 11:02:44 -070054 //pr_warning("no mem in OS_mem_token_alloc !\n");
Sachin Kamatae919922013-09-27 09:36:29 +053055 return NULL;
Bob Beers50ee11f2010-03-04 08:40:46 -050056 }
57 return skb;
58}
59
60
61static inline void
62OS_mem_token_free (void *token)
63{
64 dev_kfree_skb_any (token);
65}
66
67
68static inline void
69OS_mem_token_free_irq (void *token)
70{
71 dev_kfree_skb_irq (token);
72}
73
74
75static inline void *
76OS_mem_token_data (void *token)
77{
78 return ((struct sk_buff *) token)->data;
79}
80
81
82static inline void *
83OS_mem_token_next (void *token)
84{
Sachin Kamatae919922013-09-27 09:36:29 +053085 return NULL;
Bob Beers50ee11f2010-03-04 08:40:46 -050086}
87
88
89static inline int
90OS_mem_token_len (void *token)
91{
92 return ((struct sk_buff *) token)->len;
93}
94
95
96static inline int
97OS_mem_token_tlen (void *token)
98{
99 return ((struct sk_buff *) token)->len;
100}
101
102
103/***************************************/
104/* virtual to physical addr conversion */
105/***************************************/
106
107static inline u_long
108OS_phystov (void *addr)
109{
110 return (u_long) __va (addr);
111}
112
113
114static inline u_long
115OS_vtophys (void *addr)
116{
117 return __pa (addr);
118}
119
120
121/**********/
122/* semops */
123/**********/
124
125void OS_sem_init (void *, int);
126
127
128static inline void
129OS_sem_free (void *sem)
130{
131 /*
132 * NOOP - since semaphores structures predeclared w/in structures, no
133 * longer malloc'd
134 */
135}
136
137#define SD_SEM_TAKE(sem,desc) down(sem)
138#define SD_SEM_GIVE(sem) up(sem)
139#define SEM_AVAILABLE 1
140#define SEM_TAKEN 0
141
142
143/**********************/
144/* watchdog functions */
145/**********************/
146
147struct watchdog
148{
149 struct timer_list h;
Bob Beers50ee11f2010-03-04 08:40:46 -0500150 struct work_struct work;
Bob Beers50ee11f2010-03-04 08:40:46 -0500151 void *softc;
152 void (*func) (void *softc);
153 int ticks;
154 int init_tq;
155};
156
157
158static inline int
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530159OS_start_watchdog (struct watchdog *wd)
Bob Beers50ee11f2010-03-04 08:40:46 -0500160{
161 wd->h.expires = jiffies + wd->ticks;
162 add_timer (&wd->h);
163 return 0;
164}
165
166
167static inline int
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530168OS_stop_watchdog (struct watchdog *wd)
Bob Beers50ee11f2010-03-04 08:40:46 -0500169{
170 del_timer_sync (&wd->h);
171 return 0;
172}
173
174
175static inline int
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530176OS_free_watchdog (struct watchdog *wd)
Bob Beers50ee11f2010-03-04 08:40:46 -0500177{
178 OS_stop_watchdog (wd);
Daeseok Youn693d9632014-04-18 09:31:35 +0900179 kfree(wd);
Bob Beers50ee11f2010-03-04 08:40:46 -0500180 return 0;
181}
182
183
184/* sleep in microseconds */
185void OS_uwait (int usec, char *description);
186void OS_uwait_dummy (void);
187
188
189/* watchdog functions */
190int OS_init_watchdog(struct watchdog *wdp, void (*f) (void *), void *ci, int usec);
191
192
193#endif /*** _INC_SBECOM_INLNX_H_ ***/