- patches.rt/0001-sched-count-of-queued-RT-tasks.patch: Delete.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / sfc_netback / ci / efhw / efhw_types.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 struct efhw_nic and some related types.
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_EFHW_EFAB_TYPES_H__
39 #define __CI_EFHW_EFAB_TYPES_H__
40
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>
45
46 /*--------------------------------------------------------------------
47  *
48  * hardware limits used in the types
49  *
50  *--------------------------------------------------------------------*/
51
52 #define EFHW_KEVENTQ_MAX    8
53
54 /*--------------------------------------------------------------------
55  *
56  * forward type declarations
57  *
58  *--------------------------------------------------------------------*/
59
60 struct efhw_nic;
61
62 /*--------------------------------------------------------------------
63  *
64  * Managed interface
65  *
66  *--------------------------------------------------------------------*/
67
68 struct efhw_buffer_table_allocation{
69         unsigned base;
70         unsigned order;
71 };
72
73 struct eventq_resource_hardware {
74         /*!iobuffer allocated for eventq - can be larger than eventq */
75         efhw_iopages_t iobuff;
76         unsigned iobuff_off;
77         struct efhw_buffer_table_allocation buf_tbl_alloc;
78         int capacity;           /*!< capacity of event queue */
79 };
80
81 /*--------------------------------------------------------------------
82  *
83  * event queues and event driven callbacks
84  *
85  *--------------------------------------------------------------------*/
86
87 struct efhw_keventq {
88         volatile int lock;
89         caddr_t evq_base;
90         int32_t evq_ptr;
91         uint32_t evq_mask;
92         unsigned instance;
93         struct eventq_resource_hardware hw;
94         struct efhw_ev_handler *ev_handlers;
95 };
96
97 /**********************************************************************
98  * Portable HW interface. ***************************************
99  **********************************************************************/
100
101 /*--------------------------------------------------------------------
102  *
103  * EtherFabric Functional units - configuration and control
104  *
105  *--------------------------------------------------------------------*/
106
107 struct efhw_func_ops {
108
109   /*-------------- Initialisation ------------ */
110
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);
114
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);
119
120   /*-------------- Interrupt support  ------------ */
121
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
126          **
127          **
128          ** opaque is an OS provided pointer for use by the OS callbacks
129          ** e.g in Windows used to indicate DPC scheduled
130          */
131         int (*interrupt) (struct efhw_nic *nic);
132
133         /*! Enable given interrupt mask for the given IRQ unit */
134         void (*interrupt_enable) (struct efhw_nic *nic, uint idx);
135
136         /*! Disable given interrupt mask for the given IRQ unit */
137         void (*interrupt_disable) (struct efhw_nic *nic, uint idx);
138
139         /*! Set interrupt moderation strategy for the given IRQ unit
140          ** val is in usec
141          */
142         void (*set_interrupt_moderation)(struct efhw_nic *nic,
143                                          uint idx, uint val);
144
145   /*-------------- Event support  ------------ */
146
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
150            be proivded
151          */
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);
156
157         /*! Disable the given event queue (and any associated timer) */
158         void (*event_queue_disable) (struct efhw_nic *nic, uint evq,
159                                      int timer_only);
160
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);
164
165         /*! Push a SW event on a given eventQ */
166         void (*sw_event) (struct efhw_nic *nic, int data, int evq);
167
168   /*-------------- Filter support  ------------ */
169
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
173          */
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);
178
179         /*! Attach a given filter to a DMAQ */
180         void (*ipfilter_attach) (struct efhw_nic *nic, int filter_idx,
181                                  int dmaq_idx);
182
183         /*! Detach a filter from its DMAQ */
184         void (*ipfilter_detach) (struct efhw_nic *nic, int filter_idx);
185
186         /*! Clear down a given filter */
187         void (*ipfilter_clear) (struct efhw_nic *nic, int filter_idx);
188
189   /*-------------- DMA support  ------------ */
190
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);
195
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);
200
201         /*! Disable a given TX DMAQ */
202         void (*dmaq_tx_q_disable) (struct efhw_nic *nic, uint dmaq);
203
204         /*! Disable a given RX DMAQ */
205         void (*dmaq_rx_q_disable) (struct efhw_nic *nic, uint dmaq);
206
207         /*! Flush a given TX DMA channel */
208         int (*flush_tx_dma_channel) (struct efhw_nic *nic, uint dmaq);
209
210         /*! Flush a given RX DMA channel */
211         int (*flush_rx_dma_channel) (struct efhw_nic *nic, uint dmaq);
212
213   /*-------------- Buffer table Support ------------ */
214
215         /*! Initialise a buffer table page */
216         void (*buffer_table_set) (struct efhw_nic *nic,
217                                   dma_addr_t dma_addr,
218                                   uint bufsz, uint region,
219                                   int own_id, int buffer_id);
220
221         /*! Initialise a block of buffer table pages */
222         void (*buffer_table_set_n) (struct efhw_nic *nic, int buffer_id,
223                                     dma_addr_t dma_addr,
224                                     uint bufsz, uint region,
225                                     int n_pages, int own_id);
226
227         /*! Clear a block of buffer table pages */
228         void (*buffer_table_clear) (struct efhw_nic *nic, int buffer_id,
229                                     int num);
230
231         /*! Commit a buffer table update  */
232         void (*buffer_table_commit) (struct efhw_nic *nic);
233
234 };
235
236
237 /*----------------------------------------------------------------------------
238  *
239  * NIC type
240  *
241  *---------------------------------------------------------------------------*/
242
243 struct efhw_device_type {
244         int  arch;            /* enum efhw_arch */
245         char variant;         /* 'A', 'B', ... */
246         int  revision;        /* 0, 1, ... */
247 };
248
249
250 /*----------------------------------------------------------------------------
251  *
252  * EtherFabric NIC instance - nic.c for HW independent functions
253  *
254  *---------------------------------------------------------------------------*/
255
256 /*! */
257 struct efhw_nic {
258         /*! zero base index in efrm_nic_table.nic array */
259         volatile int index;
260         int ifindex;            /*!< OS level nic index */
261 #ifdef HAS_NET_NAMESPACE
262         struct net *nd_net;
263 #endif
264
265         struct efhw_device_type devtype;
266
267         /*! Options that can be set by user. */
268         unsigned options;
269 # define NIC_OPT_EFTEST             0x1 /* owner is an eftest app */
270
271 # define NIC_OPT_DEFAULT            0
272
273         /*! Internal flags that indicate hardware properties at runtime. */
274         unsigned flags;
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
280
281         unsigned mtu;           /*!< MAC MTU (includes MAC hdr) */
282
283         /* hardware resources */
284
285         /*! I/O address of the start of the bar */
286         efhw_ioaddr_t bar_ioaddr;
287
288         /*! Bar number of control aperture. */
289         unsigned ctr_ap_bar;
290         /*! Length of control aperture in bytes. */
291         unsigned ctr_ap_bytes;
292
293         uint8_t mac_addr[ETH_ALEN];     /*!< mac address  */
294
295         /*! EtherFabric Functional Units -- functions */
296         const struct efhw_func_ops *efhw_func;
297
298         /* Value read from FPGA version register.  Zero for asic. */
299         unsigned fpga_version;
300
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
304          * holding this one.
305          */
306         spinlock_t *reg_lock;
307         spinlock_t the_reg_lock;
308
309         int buf_commit_outstanding;     /*!< outstanding buffer commits */
310
311         /*! interrupt callbacks (hard-irq) */
312         void (*irq_handler) (struct efhw_nic *, int unit);
313
314         /*! event queues per driver */
315         struct efhw_keventq evq[EFHW_KEVENTQ_MAX];
316
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 */
323
324         /* The new driverlink infrastructure. */
325         struct efx_dl_device *net_driver_dev;
326         struct efx_dlfilt_cb_s *dlfilter_cb;
327
328         /*! Bit masks of the sizes of event queues and dma queues supported
329          * by the nic. */
330         unsigned evq_sizes;
331         unsigned rxq_sizes;
332         unsigned txq_sizes;
333
334         /* Size of filter table (including odd and even banks). */
335         unsigned filter_tbl_size;
336 };
337
338
339 #define EFHW_KVA(nic)       ((nic)->bar_ioaddr)
340
341
342 #endif /* __CI_EFHW_EFHW_TYPES_H__ */