- supported.conf: Added sparse_keymap (eeepc_laptop depends on it)
[linux-flexiantxendom0-3.2.10.git] / drivers / net / sfc / sfc_resource / ci / efrm / iobufset.h
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 public API for iobufset resource.
7  *
8  * Copyright 2005-2007: Solarflare Communications Inc,
9  *                      9501 Jeronimo Road, Suite 250,
10  *                      Irvine, CA 92618, USA
11  *
12  * Developed and maintained by Solarflare Communications:
13  *                      <linux-xen-drivers@solarflare.com>
14  *                      <onload-dev@solarflare.com>
15  *
16  * Certain parts of the driver were implemented by
17  *          Alexandra Kossovsky <Alexandra.Kossovsky@oktetlabs.ru>
18  *          OKTET Labs Ltd, Russia,
19  *          http://oktetlabs.ru, <info@oktetlabs.ru>
20  *          by request of Solarflare Communications
21  *
22  *
23  * This program is free software; you can redistribute it and/or modify it
24  * under the terms of the GNU General Public License version 2 as published
25  * by the Free Software Foundation, incorporated herein by reference.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30  * GNU General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program; if not, write to the Free Software
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
35  ****************************************************************************
36  */
37
38 #ifndef __CI_EFRM_IOBUFSET_H__
39 #define __CI_EFRM_IOBUFSET_H__
40
41 #include <ci/efrm/vi_resource.h>
42
43 /*! Iobufset resource structture.
44  * Users should not access the structure fields directly, but use the API
45  * below.
46  * However, this structure should not be moved out of public headers,
47  * because part of API (ex. efrm_iobufset_dma_addr function) is inline and
48  * is used in the fast-path code.
49  */
50 struct iobufset_resource {
51         struct efrm_resource rs;
52         struct vi_resource *evq;
53         struct iobufset_resource *linked;
54         struct efhw_buffer_table_allocation buf_tbl_alloc;
55         unsigned int n_bufs;
56         unsigned int pages_per_contiguous_chunk;
57         unsigned chunk_order;
58         struct efhw_iopage bufs[1];
59         /*!< up to n_bufs can follow this, so this must be the last member */
60 };
61
62 #define iobufset_resource(rs1) \
63         container_of((rs1), struct iobufset_resource, rs)
64
65 /*!
66  * Allocate iobufset resource.
67  *
68  * \param vi        VI that "owns" these buffers. Grabs a reference
69  *                  on success.
70  * \param linked    Uses memory from an existing iobufset.  Grabs a
71  *                  reference on success.
72  * \param iobrs_out pointer to return the new filter resource
73  *
74  * \return          status code; if non-zero, frs_out is unchanged
75  */
76 extern int
77 efrm_iobufset_resource_alloc(int32_t n_pages,
78                              int32_t pages_per_contiguous_chunk,
79                              struct vi_resource *vi,
80                              struct iobufset_resource *linked,
81                              bool phys_addr_mode,
82                              struct iobufset_resource **iobrs_out);
83
84 extern void efrm_iobufset_resource_free(struct iobufset_resource *);
85 extern void efrm_iobufset_resource_release(struct iobufset_resource *);
86
87 static inline char *
88 efrm_iobufset_ptr(struct iobufset_resource *rs, unsigned offs)
89 {
90         EFRM_ASSERT(offs < (unsigned)(rs->n_bufs << PAGE_SHIFT));
91         return efhw_iopage_ptr(&rs->bufs[offs >> PAGE_SHIFT])
92             + (offs & (PAGE_SIZE - 1));
93 }
94
95 static inline char *efrm_iobufset_page_ptr(struct iobufset_resource *rs,
96                                        unsigned page_i)
97 {
98         EFRM_ASSERT(page_i < (unsigned)rs->n_bufs);
99         return efhw_iopage_ptr(&rs->bufs[page_i]);
100 }
101
102 static inline dma_addr_t
103 efrm_iobufset_dma_addr(struct iobufset_resource *rs, unsigned offs)
104 {
105         EFRM_ASSERT(offs < (unsigned)(rs->n_bufs << PAGE_SHIFT));
106         return efhw_iopage_dma_addr(&rs->bufs[offs >> PAGE_SHIFT])
107             + (offs & (PAGE_SIZE - 1));
108 }
109
110 #endif /* __CI_EFRM_IOBUFSET_H__ */