1 /****************************************************************************
2 * Solarflare driver for Xen network acceleration
4 * Copyright 2006-2008: Solarflare Communications Inc,
5 * 9501 Jeronimo Road, Suite 250,
6 * Irvine, CA 92618, USA
8 * Maintained by Solarflare Communications <linux-xen-drivers@solarflare.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation, incorporated herein by reference.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ****************************************************************************
25 #ifndef NETFRONT_ACCEL_BUFS_H
26 #define NETFRONT_ACCEL_BUFS_H
28 #include <linux/skbuff.h>
29 #include <linux/spinlock.h>
30 #include <xen/xenbus.h>
32 #include "accel_msg_iface.h"
35 /*! Buffer descriptor structure */
36 typedef struct netfront_accel_pkt_desc {
40 /* This is the socket buffer currently married to this buffer */
43 } netfront_accel_pkt_desc;
46 #define NETFRONT_ACCEL_DEFAULT_BUF_PAGES (384)
47 #define NETFRONT_ACCEL_BUF_PAGES_PER_BLOCK_SHIFT (4)
48 #define NETFRONT_ACCEL_BUF_PAGES_PER_BLOCK \
49 (1 << (NETFRONT_ACCEL_BUF_PAGES_PER_BLOCK_SHIFT))
50 #define NETFRONT_ACCEL_BUFS_PER_PAGE_SHIFT (1)
51 #define NETFRONT_ACCEL_BUFS_PER_PAGE \
52 (1 << (NETFRONT_ACCEL_BUFS_PER_PAGE_SHIFT))
53 #define NETFRONT_ACCEL_BUFS_PER_BLOCK_SHIFT \
54 (NETFRONT_ACCEL_BUF_PAGES_PER_BLOCK_SHIFT + \
55 NETFRONT_ACCEL_BUFS_PER_PAGE_SHIFT)
56 #define NETFRONT_ACCEL_BUFS_PER_BLOCK \
57 (1 << NETFRONT_ACCEL_BUFS_PER_BLOCK_SHIFT)
58 #define NETFRONT_ACCEL_BUF_NUM_BLOCKS(max_pages) \
59 (((max_pages)+NETFRONT_ACCEL_BUF_PAGES_PER_BLOCK-1) / \
60 NETFRONT_ACCEL_BUF_PAGES_PER_BLOCK)
62 /*! Buffer management structure. */
63 struct netfront_accel_bufinfo {
64 /* number added to this manager */
66 /* number currently used from this manager */
71 int internally_locked;
75 * array of pointers (length NETFRONT_ACCEL_BUF_NUM_BLOCKS) to
78 struct netfront_accel_pkt_desc **desc_blocks;
82 struct netfront_accel_bufpages {
83 /* length of lists of pages/grants */
85 /* list of pages allocated for network buffers */
87 /* list of grants for the above pages */
88 grant_ref_t *grant_list;
90 /* number of page requests that have been made */
95 /*! Allocate memory for the buffer manager, set up locks etc.
96 * Optionally takes a lock to use, if not supplied it makes its own.
98 * \return pointer to netfront_accel_bufinfo structure that represents the
101 extern struct netfront_accel_bufinfo *
102 netfront_accel_init_bufs(spinlock_t *lock);
104 /*! Allocate memory for the buffers
107 netfront_accel_alloc_buffer_mem(struct netfront_accel_bufpages *bufpages,
108 struct netfront_accel_bufinfo *rx_res,
109 struct netfront_accel_bufinfo *tx_res,
112 netfront_accel_free_buffer_mem(struct netfront_accel_bufpages *bufpages,
113 struct netfront_accel_bufinfo *rx_res,
114 struct netfront_accel_bufinfo *tx_res);
116 /*! Release memory for the buffer manager, buffers, etc.
118 * \param manager pointer to netfront_accel_bufinfo structure that
119 * represents the buffer manager
121 extern void netfront_accel_fini_bufs(struct netfront_accel_bufinfo *manager);
123 /*! Release a buffer.
125 * \param manager The buffer manager which owns the buffer.
126 * \param id The buffer identifier.
128 extern int netfront_accel_buf_put(struct netfront_accel_bufinfo *manager,
131 /*! Get the packet descriptor associated with a buffer id.
133 * \param manager The buffer manager which owns the buffer.
134 * \param id The buffer identifier.
136 * The returned value is the packet descriptor for this buffer.
138 extern netfront_accel_pkt_desc *
139 netfront_accel_buf_find(struct netfront_accel_bufinfo *manager, u16 id);
142 /*! Fill out a message request for some buffers to be mapped by the
145 * \param manager The buffer manager
146 * \param msg Pointer to an ef_msg to complete.
147 * \return 0 on success
150 netfront_accel_buf_map_request(struct xenbus_device *dev,
151 struct netfront_accel_bufpages *bufpages,
152 struct net_accel_msg *msg,
153 int pages, int offset);
155 /*! Process a response to a buffer request.
157 * Deal with a received message from the back end in response to our
158 * request for buffers
160 * \param manager The buffer manager
161 * \param msg The received message from the back end describing new
163 * \return 0 on success
166 netfront_accel_add_bufs(struct netfront_accel_bufpages *bufpages,
167 struct netfront_accel_bufinfo *manager,
168 struct net_accel_msg *msg);
171 /*! Allocate a buffer from the buffer manager
173 * \param manager The buffer manager data structure
174 * \param id On exit, the id of the buffer allocated
175 * \return Pointer to buffer descriptor.
177 struct netfront_accel_pkt_desc *
178 netfront_accel_buf_get(struct netfront_accel_bufinfo *manager);
180 #endif /* NETFRONT_ACCEL_BUFS_H */