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 NIC table.
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_NIC_TABLE_H__
39 #define __CI_EFRM_NIC_TABLE_H__
41 #include <ci/efhw/efhw_types.h>
42 #include <ci/efrm/sysdep.h>
44 /*--------------------------------------------------------------------
46 * struct efrm_nic_table - top level driver object keeping all NICs -
47 * implemented in driver_object.c
49 *--------------------------------------------------------------------*/
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 */
64 /* Resource driver structures used by other drivers as well */
65 extern struct efrm_nic_table efrm_nic_table;
67 static inline void efrm_nic_table_hold(void)
69 atomic_inc(&efrm_nic_table.ref_count);
72 static inline void efrm_nic_table_rele(void)
74 atomic_dec(&efrm_nic_table.ref_count);
77 static inline int efrm_nic_table_held(void)
79 return (atomic_read(&efrm_nic_table.ref_count) != 0);
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); \
89 if (((_nic) = efrm_nic_table.nic[_nic_i]))
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); \
95 if (((_nic) = efrm_nic_table.nic[_i]) && \
96 efrm_nic_set_read((_set), (_i)))
98 #endif /* __CI_EFRM_NIC_TABLE_H__ */