ia64/linux-2.6.18-xen.hg

view drivers/net/sfc/sfc_resource/ci/efhw/iopage_types.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 e4dd072db259
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 struct efhw_page and struct efhw_iopage for Linux
7 * kernel.
8 *
9 * Copyright 2005-2007: Solarflare Communications Inc,
10 * 9501 Jeronimo Road, Suite 250,
11 * Irvine, CA 92618, USA
12 *
13 * Developed and maintained by Solarflare Communications:
14 * <linux-xen-drivers@solarflare.com>
15 * <onload-dev@solarflare.com>
16 *
17 * Certain parts of the driver were implemented by
18 * Alexandra Kossovsky <Alexandra.Kossovsky@oktetlabs.ru>
19 * OKTET Labs Ltd, Russia,
20 * http://oktetlabs.ru, <info@oktetlabs.ru>
21 * by request of Solarflare Communications
22 *
23 *
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License version 2 as published
26 * by the Free Software Foundation, incorporated herein by reference.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 ****************************************************************************
37 */
39 #ifndef __CI_EFHW_IOPAGE_LINUX_H__
40 #define __CI_EFHW_IOPAGE_LINUX_H__
42 #include <linux/version.h>
43 #include <linux/gfp.h>
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
45 #include <linux/hardirq.h>
46 #else
47 #include <asm/hardirq.h>
48 #endif
49 #include <linux/errno.h>
50 #include <ci/efhw/debug.h>
52 /*--------------------------------------------------------------------
53 *
54 * struct efhw_page: A single page of memory. Directly mapped in the
55 * driver, and can be mapped to userlevel.
56 *
57 *--------------------------------------------------------------------*/
59 struct efhw_page {
60 unsigned long kva;
61 };
63 static inline int efhw_page_alloc(struct efhw_page *p)
64 {
65 p->kva = __get_free_page(in_interrupt()? GFP_ATOMIC : GFP_KERNEL);
66 return p->kva ? 0 : -ENOMEM;
67 }
69 static inline int efhw_page_alloc_zeroed(struct efhw_page *p)
70 {
71 p->kva = get_zeroed_page(in_interrupt()? GFP_ATOMIC : GFP_KERNEL);
72 return p->kva ? 0 : -ENOMEM;
73 }
75 static inline void efhw_page_free(struct efhw_page *p)
76 {
77 free_page(p->kva);
78 EFHW_DO_DEBUG(memset(p, 0, sizeof(*p)));
79 }
81 static inline char *efhw_page_ptr(struct efhw_page *p)
82 {
83 return (char *)p->kva;
84 }
86 static inline unsigned efhw_page_pfn(struct efhw_page *p)
87 {
88 return (unsigned)(__pa(p->kva) >> PAGE_SHIFT);
89 }
91 static inline void efhw_page_mark_invalid(struct efhw_page *p)
92 {
93 p->kva = 0;
94 }
96 static inline int efhw_page_is_valid(struct efhw_page *p)
97 {
98 return p->kva != 0;
99 }
101 static inline void efhw_page_init_from_va(struct efhw_page *p, void *va)
102 {
103 p->kva = (unsigned long)va;
104 }
106 /*--------------------------------------------------------------------
107 *
108 * struct efhw_iopage: A single page of memory. Directly mapped in the driver,
109 * and can be mapped to userlevel. Can also be accessed by the NIC.
110 *
111 *--------------------------------------------------------------------*/
113 struct efhw_iopage {
114 struct efhw_page p;
115 dma_addr_t dma_addr;
116 };
118 static inline dma_addr_t efhw_iopage_dma_addr(struct efhw_iopage *p)
119 {
120 return p->dma_addr;
121 }
123 #define efhw_iopage_ptr(iop) efhw_page_ptr(&(iop)->p)
124 #define efhw_iopage_pfn(iop) efhw_page_pfn(&(iop)->p)
125 #define efhw_iopage_mark_invalid(iop) efhw_page_mark_invalid(&(iop)->p)
126 #define efhw_iopage_is_valid(iop) efhw_page_is_valid(&(iop)->p)
128 /*--------------------------------------------------------------------
129 *
130 * struct efhw_iopages: A set of pages that are contiguous in physical
131 * memory. Directly mapped in the driver, and can be mapped to userlevel.
132 * Can also be accessed by the NIC.
133 *
134 * NB. The O/S may be unwilling to allocate many, or even any of these. So
135 * only use this type where the NIC really needs a physically contiguous
136 * buffer.
137 *
138 *--------------------------------------------------------------------*/
140 struct efhw_iopages {
141 caddr_t kva;
142 unsigned order;
143 dma_addr_t dma_addr;
144 };
146 static inline caddr_t efhw_iopages_ptr(struct efhw_iopages *p)
147 {
148 return p->kva;
149 }
151 static inline unsigned efhw_iopages_pfn(struct efhw_iopages *p)
152 {
153 return (unsigned)(__pa(p->kva) >> PAGE_SHIFT);
154 }
156 static inline dma_addr_t efhw_iopages_dma_addr(struct efhw_iopages *p)
157 {
158 return p->dma_addr;
159 }
161 static inline unsigned efhw_iopages_size(struct efhw_iopages *p)
162 {
163 return 1u << (p->order + PAGE_SHIFT);
164 }
166 /* struct efhw_iopage <-> struct efhw_iopages conversions for handling
167 * physically contiguous allocations in iobufsets for iSCSI. This allows
168 * the essential information about contiguous allocations from
169 * efhw_iopages_alloc() to be saved away in the struct efhw_iopage array in
170 * an iobufset. (Changing the iobufset resource to use a union type would
171 * involve a lot of code changes, and make the iobufset's metadata larger
172 * which could be bad as it's supposed to fit into a single page on some
173 * platforms.)
174 */
175 static inline void
176 efhw_iopage_init_from_iopages(struct efhw_iopage *iopage,
177 struct efhw_iopages *iopages, unsigned pageno)
178 {
179 iopage->p.kva = ((unsigned long)efhw_iopages_ptr(iopages))
180 + (pageno * PAGE_SIZE);
181 iopage->dma_addr = efhw_iopages_dma_addr(iopages) +
182 (pageno * PAGE_SIZE);
183 }
185 static inline void
186 efhw_iopages_init_from_iopage(struct efhw_iopages *iopages,
187 struct efhw_iopage *iopage, unsigned order)
188 {
189 iopages->kva = (caddr_t) efhw_iopage_ptr(iopage);
190 EFHW_ASSERT(iopages->kva);
191 iopages->order = order;
192 iopages->dma_addr = efhw_iopage_dma_addr(iopage);
193 }
195 #endif /* __CI_EFHW_IOPAGE_LINUX_H__ */