ia64/linux-2.6.18-xen.hg

view drivers/net/sfc/sfc_resource/ci/efrm/private.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 private API of efrm library -- resource handling.
7 * This API is not designed for use outside of SFC resource driver.
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_EFRM_PRIVATE_H__
40 #define __CI_EFRM_PRIVATE_H__
42 #include <ci/efrm/resource.h>
43 #include <ci/efrm/driver_private.h>
44 #include <ci/efrm/sysdep.h>
45 #include <ci/efrm/debug.h>
47 /*--------------------------------------------------------------------
48 *
49 * create resource managers
50 *
51 *--------------------------------------------------------------------*/
53 /*! Create a resource manager for various types of resources
54 */
55 extern int
56 efrm_create_iobufset_resource_manager(struct efrm_resource_manager **out);
58 extern int
59 efrm_create_filter_resource_manager(struct efrm_resource_manager **out);
61 extern int
62 efrm_create_vi_resource_manager(struct efrm_resource_manager **out,
63 const struct vi_resource_dimensions *);
65 /*--------------------------------------------------------------------
66 *
67 * efrm_resource_handle_t handling
68 *
69 *--------------------------------------------------------------------*/
71 /*! Initialize an area of memory to be used as a resource */
72 static inline void efrm_resource_init(struct efrm_resource *rs,
73 int type, int instance)
74 {
75 EFRM_ASSERT(instance >= 0);
76 EFRM_ASSERT(type >= 0 && type < EFRM_RESOURCE_NUM);
77 atomic_set(&rs->rs_ref_count, 1);
78 rs->rs_handle.handle = (type << 28u) |
79 (((unsigned)jiffies & 0xfff) << 16) | instance;
80 }
82 /*--------------------------------------------------------------------
83 *
84 * Instance pool management
85 *
86 *--------------------------------------------------------------------*/
88 /*! Allocate instance pool. Use kfifo_vfree to destroy it. */
89 static inline int
90 efrm_kfifo_id_ctor(struct kfifo **ids_out,
91 unsigned int base, unsigned int limit, spinlock_t *lock)
92 {
93 unsigned int i;
94 struct kfifo *ids;
95 unsigned char *buffer;
96 #ifndef TCP_CHIMNEY_SUPPORT
97 unsigned int size = roundup_pow_of_two((limit - base) * sizeof(int));
98 #else
99 /* ### TODO - Linux kfifos really are a power of two, sysdep_ci2linux
100 does ci_fifo2's, which only actually hold 2^n - 1.
101 We need to double buffer size, not add one, because
102 ci_fifo2 can only be a power of two. */
103 unsigned int size = roundup_pow_of_two((limit - base) * 2 * sizeof(int));
104 #endif
106 EFRM_ASSERT(base <= limit);
107 buffer = vmalloc(size);
108 ids = kfifo_init(buffer, size, GFP_KERNEL, lock);
109 if (IS_ERR(ids))
110 return PTR_ERR(ids);
111 for (i = base; i < limit; i++)
112 EFRM_VERIFY_EQ(__kfifo_put(ids, (unsigned char *)&i,
113 sizeof(i)), sizeof(i));
115 *ids_out = ids;
116 return 0;
117 }
119 /*--------------------------------------------------------------------
120 *
121 * Various private functions
122 *
123 *--------------------------------------------------------------------*/
125 /*! Initialize the fields in the provided resource manager memory area
126 * \param rm The area of memory to be initialized
127 * \param dtor A method to destroy the resource manager
128 * \param name A Textual name for the resource manager
129 * \param type The type of resource managed
130 * \param initial_table_size Initial size of the ID table
131 * \param auto_destroy Destroy resource manager on driver onload iff true
132 *
133 * A default table size is provided if the value 0 is provided.
134 */
135 extern int
136 efrm_resource_manager_ctor(struct efrm_resource_manager *rm,
137 void (*dtor)(struct efrm_resource_manager *),
138 const char *name, unsigned type,
139 int initial_table_size);
141 extern void efrm_resource_manager_dtor(struct efrm_resource_manager *rm);
143 /*! Insert a resource into table in the resource manager.
144 *
145 * Caller should free the resource if this function returns non-zero.
146 */
147 extern int efrm_resource_manager_insert(struct efrm_resource *rs);
149 #endif /* __CI_EFRM_PRIVATE_H__ */