- patches.rt/0001-sched-count-of-queued-RT-tasks.patch: Delete.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / sfc_netback / ci / efrm / nic_table.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 NIC table.
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_NIC_TABLE_H__
39 #define __CI_EFRM_NIC_TABLE_H__
40
41 #include <ci/efhw/efhw_types.h>
42 #include <ci/efrm/sysdep.h>
43
44 /*--------------------------------------------------------------------
45  *
46  * struct efrm_nic_table - top level driver object keeping all NICs -
47  * implemented in driver_object.c
48  *
49  *--------------------------------------------------------------------*/
50
51 /*! Comment? */
52 struct efrm_nic_table {
53         /*! nics attached to this driver */
54         struct efhw_nic *nic[EFHW_MAX_NR_DEVS];
55         /*! pointer to an arbitrary struct efhw_nic if one exists;
56          * for code which does not care which NIC it wants but
57          * still needs one. Note you cannot assume nic[0] exists. */
58         struct efhw_nic *a_nic;
59         uint32_t nic_count;     /*!< number of nics attached to this driver */
60         spinlock_t lock;        /*!< lock for table modifications */
61         atomic_t ref_count;     /*!< refcount for users of nic table */
62 };
63
64 /* Resource driver structures used by other drivers as well */
65 extern struct efrm_nic_table efrm_nic_table;
66
67 static inline void efrm_nic_table_hold(void)
68 {
69         atomic_inc(&efrm_nic_table.ref_count);
70 }
71
72 static inline void efrm_nic_table_rele(void)
73 {
74         atomic_dec(&efrm_nic_table.ref_count);
75 }
76
77 static inline int efrm_nic_table_held(void)
78 {
79         return (atomic_read(&efrm_nic_table.ref_count) != 0);
80 }
81
82 /* Run code block _x multiple times with variable nic set to each
83  * registered NIC in turn.
84  * DO NOT "break" out of this loop early. */
85 #define EFRM_FOR_EACH_NIC(_nic_i, _nic)                                 \
86         for ((_nic_i) = (efrm_nic_table_hold(), 0);                     \
87              (_nic_i) < EFHW_MAX_NR_DEVS || (efrm_nic_table_rele(), 0); \
88              (_nic_i)++)                                                \
89                 if (((_nic) = efrm_nic_table.nic[_nic_i]))
90
91 #define EFRM_FOR_EACH_NIC_IN_SET(_set, _i, _nic)                        \
92         for ((_i) = (efrm_nic_table_hold(), 0);                         \
93              (_i) < EFHW_MAX_NR_DEVS || (efrm_nic_table_rele(), 0);     \
94              ++(_i))                                                    \
95                 if (((_nic) = efrm_nic_table.nic[_i]) &&                \
96                     efrm_nic_set_read((_set), (_i)))
97
98 #endif /* __CI_EFRM_NIC_TABLE_H__ */