ia64/linux-2.6.18-xen.hg

view drivers/xen/sfc_netback/ci/efrm/sysdep_linux.h @ 847:ad4d307bf9ce

net sfc: Update sfc and sfc_resource driver to latest release

...and update sfc_netfront, sfc_netback, sfc_netutil for any API changes

sfc_netback: Fix asymmetric use of SFC buffer table alloc and free
sfc_netback: Clean up if no SFC accel device found
sfc_netback: Gracefully handle case where page grant fails
sfc_netback: Disable net acceleration if the physical link goes down
sfc_netfront: Less verbose error messages, more verbose counters for
rx discard errors
sfc_netfront: Gracefully handle case where SFC netfront fails during
initialisation

Signed-off-by: Kieran Mansley <kmansley@solarflare.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 31 11:59:10 2009 +0100 (2009-03-31)
parents af0d925ba938
children
line source
1 /****************************************************************************
2 * Driver for Solarflare network controllers -
3 * resource management for Xen backend, OpenOnload, etc
4 * (including support for SFE4001 10GBT NIC)
5 *
6 * This file provides version-independent Linux kernel API for efrm library.
7 * Only kernels >=2.6.9 are supported.
8 *
9 * Copyright 2005-2007: Solarflare Communications Inc,
10 * 9501 Jeronimo Road, Suite 250,
11 * Irvine, CA 92618, USA
12 *
13 * Kfifo API is partially stolen from linux-2.6.22/include/linux/list.h
14 * Copyright (C) 2004 Stelian Pop <stelian@popies.net>
15 *
16 * Developed and maintained by Solarflare Communications:
17 * <linux-xen-drivers@solarflare.com>
18 * <onload-dev@solarflare.com>
19 *
20 * Certain parts of the driver were implemented by
21 * Alexandra Kossovsky <Alexandra.Kossovsky@oktetlabs.ru>
22 * OKTET Labs Ltd, Russia,
23 * http://oktetlabs.ru, <info@oktetlabs.ru>
24 * by request of Solarflare Communications
25 *
26 *
27 * This program is free software; you can redistribute it and/or modify it
28 * under the terms of the GNU General Public License version 2 as published
29 * by the Free Software Foundation, incorporated herein by reference.
30 *
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 *
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39 ****************************************************************************
40 */
42 #ifndef __CI_EFRM_SYSDEP_LINUX_H__
43 #define __CI_EFRM_SYSDEP_LINUX_H__
45 #include <linux/version.h>
46 #include <linux/list.h>
47 #include <linux/vmalloc.h>
48 #include <linux/errno.h>
49 #include <linux/string.h>
50 #include <linux/workqueue.h>
51 #include <linux/gfp.h>
52 #include <linux/slab.h>
53 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
54 #include <linux/hardirq.h>
55 #else
56 #include <asm/hardirq.h>
57 #endif
58 #include <linux/kernel.h>
59 #include <linux/if_ether.h>
60 #include <linux/completion.h>
61 #include <linux/in.h>
63 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
64 /* get roundup_pow_of_two(), which was in kernel.h in early kernel versions */
65 #include <linux/log2.h>
66 #endif
69 /********************************************************************
70 *
71 * Utility functions
72 *
73 ********************************************************************/
75 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
76 static inline unsigned long __attribute_const__ roundup_pow_of_two(unsigned long x)
77 {
78 return (1UL << fls(x - 1));
79 }
80 #endif
83 /********************************************************************
84 *
85 * List API
86 *
87 ********************************************************************/
88 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
89 static inline void
90 list_replace_init(struct list_head *old, struct list_head *new)
91 {
92 new->next = old->next;
93 new->next->prev = new;
94 new->prev = old->prev;
95 new->prev->next = new;
96 INIT_LIST_HEAD(old);
97 }
98 #endif
100 static inline struct list_head *list_pop(struct list_head *list)
101 {
102 struct list_head *link = list->next;
103 list_del(link);
104 return link;
105 }
107 static inline struct list_head *list_pop_tail(struct list_head *list)
108 {
109 struct list_head *link = list->prev;
110 list_del(link);
111 return link;
112 }
114 /********************************************************************
115 *
116 * Workqueue API
117 *
118 ********************************************************************/
120 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
121 #define NEED_OLD_WORK_API
123 /**
124 * The old and new work function prototypes just change
125 * the type of the pointer in the only argument, so it's
126 * safe to cast one function type to the other
127 */
128 typedef void (*efrm_old_work_func_t) (void *p);
130 #undef INIT_WORK
131 #define INIT_WORK(_work, _func) \
132 do { \
133 INIT_LIST_HEAD(&(_work)->entry); \
134 (_work)->pending = 0; \
135 PREPARE_WORK((_work), \
136 (efrm_old_work_func_t) (_func), \
137 (_work)); \
138 } while (0)
140 #endif
142 /********************************************************************
143 *
144 * Kfifo API
145 *
146 ********************************************************************/
148 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
150 #if !defined(RHEL_RELEASE_CODE) || (RHEL_RELEASE_CODE < 1029)
151 typedef unsigned gfp_t;
152 #endif
154 #define HAS_NO_KFIFO
156 struct kfifo {
157 unsigned char *buffer; /* the buffer holding the data */
158 unsigned int size; /* the size of the allocated buffer */
159 unsigned int in; /* data is added at offset (in % size) */
160 unsigned int out; /* data is extracted from off. (out % size) */
161 spinlock_t *lock; /* protects concurrent modifications */
162 };
164 extern struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size,
165 gfp_t gfp_mask, spinlock_t *lock);
166 extern struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask,
167 spinlock_t *lock);
168 extern void kfifo_free(struct kfifo *fifo);
169 extern unsigned int __kfifo_put(struct kfifo *fifo,
170 unsigned char *buffer, unsigned int len);
171 extern unsigned int __kfifo_get(struct kfifo *fifo,
172 unsigned char *buffer, unsigned int len);
174 /**
175 * kfifo_put - puts some data into the FIFO
176 * @fifo: the fifo to be used.
177 * @buffer: the data to be added.
178 * @len: the length of the data to be added.
179 *
180 * This function copies at most @len bytes from the @buffer into
181 * the FIFO depending on the free space, and returns the number of
182 * bytes copied.
183 */
184 static inline unsigned int
185 kfifo_put(struct kfifo *fifo, unsigned char *buffer, unsigned int len)
186 {
187 unsigned long flags;
188 unsigned int ret;
190 spin_lock_irqsave(fifo->lock, flags);
192 ret = __kfifo_put(fifo, buffer, len);
194 spin_unlock_irqrestore(fifo->lock, flags);
196 return ret;
197 }
199 /**
200 * kfifo_get - gets some data from the FIFO
201 * @fifo: the fifo to be used.
202 * @buffer: where the data must be copied.
203 * @len: the size of the destination buffer.
204 *
205 * This function copies at most @len bytes from the FIFO into the
206 * @buffer and returns the number of copied bytes.
207 */
208 static inline unsigned int
209 kfifo_get(struct kfifo *fifo, unsigned char *buffer, unsigned int len)
210 {
211 unsigned long flags;
212 unsigned int ret;
214 spin_lock_irqsave(fifo->lock, flags);
216 ret = __kfifo_get(fifo, buffer, len);
218 /*
219 * optimization: if the FIFO is empty, set the indices to 0
220 * so we don't wrap the next time
221 */
222 if (fifo->in == fifo->out)
223 fifo->in = fifo->out = 0;
225 spin_unlock_irqrestore(fifo->lock, flags);
227 return ret;
228 }
230 /**
231 * __kfifo_len - returns the number of bytes available in the FIFO, no locking version
232 * @fifo: the fifo to be used.
233 */
234 static inline unsigned int __kfifo_len(struct kfifo *fifo)
235 {
236 return fifo->in - fifo->out;
237 }
239 /**
240 * kfifo_len - returns the number of bytes available in the FIFO
241 * @fifo: the fifo to be used.
242 */
243 static inline unsigned int kfifo_len(struct kfifo *fifo)
244 {
245 unsigned long flags;
246 unsigned int ret;
248 spin_lock_irqsave(fifo->lock, flags);
250 ret = __kfifo_len(fifo);
252 spin_unlock_irqrestore(fifo->lock, flags);
254 return ret;
255 }
257 #else
258 #include <linux/kfifo.h>
259 #endif
261 static inline void kfifo_vfree(struct kfifo *fifo)
262 {
263 vfree(fifo->buffer);
264 kfree(fifo);
265 }
267 #endif /* __CI_EFRM_SYSDEP_LINUX_H__ */