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 struct efhw_nic and some related types.
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_EFHW_EFAB_TYPES_H__
39 #define __CI_EFHW_EFAB_TYPES_H__
41 #include <ci/efhw/efhw_config.h>
42 #include <ci/efhw/hardware_sysdep.h>
43 #include <ci/efhw/iopage_types.h>
44 #include <ci/efhw/sysdep.h>
46 /*--------------------------------------------------------------------
48 * hardware limits used in the types
50 *--------------------------------------------------------------------*/
52 #define EFHW_KEVENTQ_MAX 8
54 /*--------------------------------------------------------------------
56 * forward type declarations
58 *--------------------------------------------------------------------*/
62 /*--------------------------------------------------------------------
66 *--------------------------------------------------------------------*/
68 struct efhw_buffer_table_allocation{
73 struct eventq_resource_hardware {
74 /*!iobuffer allocated for eventq - can be larger than eventq */
75 efhw_iopages_t iobuff;
77 struct efhw_buffer_table_allocation buf_tbl_alloc;
78 int capacity; /*!< capacity of event queue */
81 /*--------------------------------------------------------------------
83 * event queues and event driven callbacks
85 *--------------------------------------------------------------------*/
93 struct eventq_resource_hardware hw;
94 struct efhw_ev_handler *ev_handlers;
97 /**********************************************************************
98 * Portable HW interface. ***************************************
99 **********************************************************************/
101 /*--------------------------------------------------------------------
103 * EtherFabric Functional units - configuration and control
105 *--------------------------------------------------------------------*/
107 struct efhw_func_ops {
109 /*-------------- Initialisation ------------ */
111 /*! close down all hardware functional units - leaves NIC in a safe
112 state for driver unload */
113 void (*close_hardware) (struct efhw_nic *nic);
115 /*! initialise all hardware functional units */
116 int (*init_hardware) (struct efhw_nic *nic,
117 struct efhw_ev_handler *,
118 const uint8_t *mac_addr);
120 /*-------------- Interrupt support ------------ */
122 /*! Main interrupt routine
123 ** This function returns,
124 ** - zero, if the IRQ was not generated by EF1
125 ** - non-zero, if EF1 was the source of the IRQ
128 ** opaque is an OS provided pointer for use by the OS callbacks
129 ** e.g in Windows used to indicate DPC scheduled
131 int (*interrupt) (struct efhw_nic *nic);
133 /*! Enable given interrupt mask for the given IRQ unit */
134 void (*interrupt_enable) (struct efhw_nic *nic, uint idx);
136 /*! Disable given interrupt mask for the given IRQ unit */
137 void (*interrupt_disable) (struct efhw_nic *nic, uint idx);
139 /*! Set interrupt moderation strategy for the given IRQ unit
142 void (*set_interrupt_moderation)(struct efhw_nic *nic,
145 /*-------------- Event support ------------ */
147 /*! Enable the given event queue
148 depending on the underlying implementation (EF1 or Falcon) then
149 either a q_base_addr in host memory, or a buffer base id should
152 void (*event_queue_enable) (struct efhw_nic *nic,
153 uint evq, /* evnt queue index */
154 uint evq_size, /* units of #entries */
155 dma_addr_t q_base_addr, uint buf_base_id);
157 /*! Disable the given event queue (and any associated timer) */
158 void (*event_queue_disable) (struct efhw_nic *nic, uint evq,
161 /*! request wakeup from the NIC on a given event Q */
162 void (*wakeup_request) (struct efhw_nic *nic, dma_addr_t q_base_addr,
163 int next_i, int evq);
165 /*! Push a SW event on a given eventQ */
166 void (*sw_event) (struct efhw_nic *nic, int data, int evq);
168 /*-------------- Filter support ------------ */
170 /*! Setup a given filter - The software can request a filter_i,
171 * but some EtherFabric implementations will override with
172 * a more suitable index
174 int (*ipfilter_set) (struct efhw_nic *nic, int type,
175 int *filter_i, int dmaq,
176 unsigned saddr_be32, unsigned sport_be16,
177 unsigned daddr_be32, unsigned dport_be16);
179 /*! Attach a given filter to a DMAQ */
180 void (*ipfilter_attach) (struct efhw_nic *nic, int filter_idx,
183 /*! Detach a filter from its DMAQ */
184 void (*ipfilter_detach) (struct efhw_nic *nic, int filter_idx);
186 /*! Clear down a given filter */
187 void (*ipfilter_clear) (struct efhw_nic *nic, int filter_idx);
189 /*-------------- DMA support ------------ */
191 /*! Initialise NIC state for a given TX DMAQ */
192 void (*dmaq_tx_q_init) (struct efhw_nic *nic,
193 uint dmaq, uint evq, uint owner, uint tag,
194 uint dmaq_size, uint buf_idx, uint flags);
196 /*! Initialise NIC state for a given RX DMAQ */
197 void (*dmaq_rx_q_init) (struct efhw_nic *nic,
198 uint dmaq, uint evq, uint owner, uint tag,
199 uint dmaq_size, uint buf_idx, uint flags);
201 /*! Disable a given TX DMAQ */
202 void (*dmaq_tx_q_disable) (struct efhw_nic *nic, uint dmaq);
204 /*! Disable a given RX DMAQ */
205 void (*dmaq_rx_q_disable) (struct efhw_nic *nic, uint dmaq);
207 /*! Flush a given TX DMA channel */
208 int (*flush_tx_dma_channel) (struct efhw_nic *nic, uint dmaq);
210 /*! Flush a given RX DMA channel */
211 int (*flush_rx_dma_channel) (struct efhw_nic *nic, uint dmaq);
213 /*-------------- Buffer table Support ------------ */
215 /*! Initialise a buffer table page */
216 void (*buffer_table_set) (struct efhw_nic *nic,
218 uint bufsz, uint region,
219 int own_id, int buffer_id);
221 /*! Initialise a block of buffer table pages */
222 void (*buffer_table_set_n) (struct efhw_nic *nic, int buffer_id,
224 uint bufsz, uint region,
225 int n_pages, int own_id);
227 /*! Clear a block of buffer table pages */
228 void (*buffer_table_clear) (struct efhw_nic *nic, int buffer_id,
231 /*! Commit a buffer table update */
232 void (*buffer_table_commit) (struct efhw_nic *nic);
237 /*----------------------------------------------------------------------------
241 *---------------------------------------------------------------------------*/
243 struct efhw_device_type {
244 int arch; /* enum efhw_arch */
245 char variant; /* 'A', 'B', ... */
246 int revision; /* 0, 1, ... */
250 /*----------------------------------------------------------------------------
252 * EtherFabric NIC instance - nic.c for HW independent functions
254 *---------------------------------------------------------------------------*/
258 /*! zero base index in efrm_nic_table.nic array */
260 int ifindex; /*!< OS level nic index */
261 #ifdef HAS_NET_NAMESPACE
265 struct efhw_device_type devtype;
267 /*! Options that can be set by user. */
269 # define NIC_OPT_EFTEST 0x1 /* owner is an eftest app */
271 # define NIC_OPT_DEFAULT 0
273 /*! Internal flags that indicate hardware properties at runtime. */
275 # define NIC_FLAG_NO_INTERRUPT 0x01 /* to be set at init time only */
276 # define NIC_FLAG_TRY_MSI 0x02
277 # define NIC_FLAG_MSI 0x04
278 # define NIC_FLAG_OS_IRQ_EN 0x08
279 # define NIC_FLAG_10G 0x10
281 unsigned mtu; /*!< MAC MTU (includes MAC hdr) */
283 /* hardware resources */
285 /*! I/O address of the start of the bar */
286 efhw_ioaddr_t bar_ioaddr;
288 /*! Bar number of control aperture. */
290 /*! Length of control aperture in bytes. */
291 unsigned ctr_ap_bytes;
293 uint8_t mac_addr[ETH_ALEN]; /*!< mac address */
295 /*! EtherFabric Functional Units -- functions */
296 const struct efhw_func_ops *efhw_func;
298 /* Value read from FPGA version register. Zero for asic. */
299 unsigned fpga_version;
301 /*! This lock protects a number of misc NIC resources. It should
302 * only be used for things that can be at the bottom of the lock
303 * order. ie. You mustn't attempt to grab any other lock while
306 spinlock_t *reg_lock;
307 spinlock_t the_reg_lock;
309 int buf_commit_outstanding; /*!< outstanding buffer commits */
311 /*! interrupt callbacks (hard-irq) */
312 void (*irq_handler) (struct efhw_nic *, int unit);
314 /*! event queues per driver */
315 struct efhw_keventq evq[EFHW_KEVENTQ_MAX];
317 /* for marking when we are not using an IRQ unit
318 - 0 is a valid offset to an IRQ unit on EF1! */
319 #define EFHW_IRQ_UNIT_UNUSED 0xffff
320 /*! interrupt unit in use */
321 unsigned int irq_unit[EFHW_KEVENTQ_MAX];
322 efhw_iopage_t irq_iobuff; /*!< Falcon SYSERR interrupt */
324 /* The new driverlink infrastructure. */
325 struct efx_dl_device *net_driver_dev;
326 struct efx_dlfilt_cb_s *dlfilter_cb;
328 /*! Bit masks of the sizes of event queues and dma queues supported
334 /* Size of filter table (including odd and even banks). */
335 unsigned filter_tbl_size;
339 #define EFHW_KVA(nic) ((nic)->bar_ioaddr)
342 #endif /* __CI_EFHW_EFHW_TYPES_H__ */