1 /****************************************************************************
2 * Driver for Solarflare network controllers -
3 * resource management for Xen backend, OpenOnload, etc
4 * (including support for SFE4001 10GBT NIC)
6 * This file provides public API for iobufset resource.
8 * Copyright 2005-2007: Solarflare Communications Inc,
9 * 9501 Jeronimo Road, Suite 250,
10 * Irvine, CA 92618, USA
12 * Developed and maintained by Solarflare Communications:
13 * <linux-xen-drivers@solarflare.com>
14 * <onload-dev@solarflare.com>
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
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.
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.
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 ****************************************************************************
38 #ifndef __CI_EFRM_IOBUFSET_H__
39 #define __CI_EFRM_IOBUFSET_H__
41 #include <ci/efrm/vi_resource.h>
43 /*! Iobufset resource structture.
44 * Users should not access the structure fields directly, but use the API
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.
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;
56 unsigned int pages_per_contiguous_chunk;
58 struct efhw_iopage bufs[1];
59 /*!< up to n_bufs can follow this, so this must be the last member */
62 #define iobufset_resource(rs1) \
63 container_of((rs1), struct iobufset_resource, rs)
66 * Allocate iobufset resource.
68 * \param vi VI that "owns" these buffers. Grabs a reference
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
74 * \return status code; if non-zero, frs_out is unchanged
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,
82 struct iobufset_resource **iobrs_out);
84 extern void efrm_iobufset_resource_free(struct iobufset_resource *);
85 extern void efrm_iobufset_resource_release(struct iobufset_resource *);
88 efrm_iobufset_ptr(struct iobufset_resource *rs, unsigned offs)
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));
95 static inline char *efrm_iobufset_page_ptr(struct iobufset_resource *rs,
98 EFRM_ASSERT(page_i < (unsigned)rs->n_bufs);
99 return efhw_iopage_ptr(&rs->bufs[page_i]);
102 static inline dma_addr_t
103 efrm_iobufset_dma_addr(struct iobufset_resource *rs, unsigned offs)
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));
110 #endif /* __CI_EFRM_IOBUFSET_H__ */