Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 1 | #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 Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 26 | #include <linux/types.h> |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 27 | #include <linux/module.h> |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 28 | #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 Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 33 | /* forward reference */ |
| 34 | u_int32_t pci_read_32 (u_int32_t *p); |
| 35 | void pci_write_32 (u_int32_t *p, u_int32_t v); |
| 36 | |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * system dependent callbacks |
| 40 | */ |
| 41 | |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 42 | /****************/ |
| 43 | /* memory token */ |
| 44 | /****************/ |
| 45 | |
| 46 | static inline void * |
| 47 | OS_mem_token_alloc (size_t size) |
| 48 | { |
| 49 | struct sk_buff *skb; |
| 50 | |
| 51 | skb = dev_alloc_skb (size); |
| 52 | if (!skb) |
| 53 | { |
Joe Perches | e6e4d05 | 2010-05-03 11:02:44 -0700 | [diff] [blame] | 54 | //pr_warning("no mem in OS_mem_token_alloc !\n"); |
Sachin Kamat | ae91992 | 2013-09-27 09:36:29 +0530 | [diff] [blame] | 55 | return NULL; |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 56 | } |
| 57 | return skb; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | static inline void |
| 62 | OS_mem_token_free (void *token) |
| 63 | { |
| 64 | dev_kfree_skb_any (token); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | static inline void |
| 69 | OS_mem_token_free_irq (void *token) |
| 70 | { |
| 71 | dev_kfree_skb_irq (token); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | static inline void * |
| 76 | OS_mem_token_data (void *token) |
| 77 | { |
| 78 | return ((struct sk_buff *) token)->data; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | static inline void * |
| 83 | OS_mem_token_next (void *token) |
| 84 | { |
Sachin Kamat | ae91992 | 2013-09-27 09:36:29 +0530 | [diff] [blame] | 85 | return NULL; |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
| 89 | static inline int |
| 90 | OS_mem_token_len (void *token) |
| 91 | { |
| 92 | return ((struct sk_buff *) token)->len; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | static inline int |
| 97 | OS_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 | |
| 107 | static inline u_long |
| 108 | OS_phystov (void *addr) |
| 109 | { |
| 110 | return (u_long) __va (addr); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | static inline u_long |
| 115 | OS_vtophys (void *addr) |
| 116 | { |
| 117 | return __pa (addr); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /**********/ |
| 122 | /* semops */ |
| 123 | /**********/ |
| 124 | |
| 125 | void OS_sem_init (void *, int); |
| 126 | |
| 127 | |
| 128 | static inline void |
| 129 | OS_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 | |
| 147 | struct watchdog |
| 148 | { |
| 149 | struct timer_list h; |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 150 | struct work_struct work; |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 151 | void *softc; |
| 152 | void (*func) (void *softc); |
| 153 | int ticks; |
| 154 | int init_tq; |
| 155 | }; |
| 156 | |
| 157 | |
| 158 | static inline int |
Dulshani Gunawardhana | ee1803c | 2013-05-22 23:29:26 +0530 | [diff] [blame] | 159 | OS_start_watchdog (struct watchdog *wd) |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 160 | { |
| 161 | wd->h.expires = jiffies + wd->ticks; |
| 162 | add_timer (&wd->h); |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | static inline int |
Dulshani Gunawardhana | ee1803c | 2013-05-22 23:29:26 +0530 | [diff] [blame] | 168 | OS_stop_watchdog (struct watchdog *wd) |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 169 | { |
| 170 | del_timer_sync (&wd->h); |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | static inline int |
Dulshani Gunawardhana | ee1803c | 2013-05-22 23:29:26 +0530 | [diff] [blame] | 176 | OS_free_watchdog (struct watchdog *wd) |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 177 | { |
| 178 | OS_stop_watchdog (wd); |
Daeseok Youn | 693d963 | 2014-04-18 09:31:35 +0900 | [diff] [blame] | 179 | kfree(wd); |
Bob Beers | 50ee11f | 2010-03-04 08:40:46 -0500 | [diff] [blame] | 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | /* sleep in microseconds */ |
| 185 | void OS_uwait (int usec, char *description); |
| 186 | void OS_uwait_dummy (void); |
| 187 | |
| 188 | |
| 189 | /* watchdog functions */ |
| 190 | int OS_init_watchdog(struct watchdog *wdp, void (*f) (void *), void *ci, int usec); |
| 191 | |
| 192 | |
| 193 | #endif /*** _INC_SBECOM_INLNX_H_ ***/ |