Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / sfc_netfront / ef_vi_falcon.h
1 /****************************************************************************
2  * Copyright 2002-2005: Level 5 Networks Inc.
3  * Copyright 2005-2008: Solarflare Communications Inc,
4  *                      9501 Jeronimo Road, Suite 250,
5  *                      Irvine, CA 92618, USA
6  *
7  * Maintained by Solarflare Communications
8  *  <linux-xen-drivers@solarflare.com>
9  *  <onload-dev@solarflare.com>
10  *
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License version 2 as published
13  * by the Free Software Foundation, incorporated herein by reference.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  ****************************************************************************
24  */
25
26 /*
27  * \author  slp
28  *  \brief  Falcon specific definitions
29  *   \date  2004/08
30  */
31
32 #ifndef __EF_VI_FALCON_H__
33 #define __EF_VI_FALCON_H__    
34
35 #define EFHW_4K         0x00001000u
36 #define EFHW_8K         0x00002000u
37
38 /* include the autogenerated register definitions */
39
40 #include "ef_vi_falcon_core.h"
41 #include "ef_vi_falcon_desc.h"
42 #include "ef_vi_falcon_event.h"
43
44
45 /*----------------------------------------------------------------------------
46  *
47  * Helpers to turn bit shifts into dword shifts and check that the bit fields 
48  * haven't overflown the dword etc. Aim is to preserve consistency with the 
49  * autogenerated headers - once stable we could hard code.
50  *
51  *---------------------------------------------------------------------------*/
52
53 /* mask constructors */
54 #define __FALCON_MASK(WIDTH,T)  ((((T)1) << (WIDTH)) - 1)
55 #define __EFVI_MASK32(WIDTH)  __FALCON_MASK((WIDTH),uint32_t)
56 #define __EFVI_MASK64(WIDTH)  __FALCON_MASK((WIDTH),uint64_t)
57
58 #define __EFVI_FALCON_MASKFIELD32(LBN, WIDTH)   ((uint32_t)  \
59                              (__EFVI_MASK32(WIDTH) << (LBN)))
60
61 /* constructors for fields which span the first and second dwords */
62 #define __LW(LBN) (32 - LBN)
63 #define LOW(v, LBN, WIDTH)   ((uint32_t)  \
64                                (((v) & __EFVI_MASK64(__LW((LBN)))) << (LBN)))
65 #define HIGH(v, LBN, WIDTH)  ((uint32_t)(((v) >> __LW((LBN))) & \
66                                        __EFVI_MASK64((WIDTH - __LW((LBN))))))
67 /* constructors for fields within the second dword */
68 #define __DW2(LBN)        ((LBN) - 32)
69
70 /* constructors for fields which span the second and third dwords */
71 #define __LW2(LBN) (64 - LBN)
72 #define LOW2(v, LBN, WIDTH) ((uint32_t) \
73                        (((v) & __EFVI_MASK64(__LW2((LBN)))) << ((LBN) - 32)))
74 #define HIGH2(v, LBN, WIDTH)  ((uint32_t) \
75              (((v) >> __LW2((LBN))) & __EFVI_MASK64((WIDTH - __LW2((LBN))))))
76
77 /* constructors for fields within the third dword */
78 #define __DW3(LBN)        ((LBN) - 64)
79
80                                 
81 /* constructors for fields which span the third and fourth dwords */
82 #define __LW3(LBN) (96 - LBN)
83 #define LOW3(v, LBN, WIDTH)   ((uint32_t)    \
84               (((v) & __EFVI_MASK64(__LW3((LBN)))) << ((LBN) - 64)))
85 #define HIGH3(v, LBN, WIDTH)  ((unit32_t)    \
86              (((v) >> __LW3((LBN))) & __EFVI_MASK64((WIDTH - __LW3((LBN))))))
87
88 /* constructors for fields within the fourth dword */
89 #define __DW4(LBN)        ((LBN) - 96)
90
91 /* checks that the autogenerated headers our consistent with our model */
92 #define WIDTHCHCK(a, b) ef_assert((a) == (b))
93 #define RANGECHCK(v, WIDTH) \
94                 ef_assert(((uint64_t)(v) & ~(__EFVI_MASK64((WIDTH)))) == 0)
95
96 /* fields within the first dword */
97 #define DWCHCK(LBN, WIDTH) ef_assert(((LBN) >= 0) &&(((LBN)+(WIDTH)) <= 32))
98
99 /* fields which span the first and second dwords */
100 #define LWCHK(LBN, WIDTH)  ef_assert(WIDTH >= __LW(LBN))
101
102 /*----------------------------------------------------------------------------
103  *
104  * Buffer virtual addresses (4K buffers) 
105  *
106  *---------------------------------------------------------------------------*/
107
108 /* Form a buffer virtual address from buffer ID and offset.  If the offset
109 ** is larger than the buffer size, then the buffer indexed will be
110 ** calculated appropriately.  It is the responsibility of the caller to
111 ** ensure that they have valid buffers programmed at that address.
112 */
113 #define EFVI_FALCON_VADDR_4K_S          (12)         
114 #define EFVI_FALCON_VADDR_M       0xfffff               /* post shift mask  */
115
116
117 #define EFVI_FALCON_BUFFER_4K_ADDR(id,off)      \
118   (((id) << EFVI_FALCON_VADDR_4K_S) + (off))
119
120 #define EFVI_FALCON_BUFFER_4K_PAGE(vaddr)                       \
121   (((vaddr) >> EFVI_FALCON_VADDR_4K_S) & EFVI_FALCON_VADDR_M)
122
123 #define EFVI_FALCON_BUFFER_4K_OFF(vaddr)                \
124   ((vaddr) & __EFVI_MASK32(EFVI_FALCON_VADDR_4K_S))
125
126
127 /*----------------------------------------------------------------------------
128  *
129  * Masks
130  *
131  *---------------------------------------------------------------------------*/
132
133 #define EFVI_FALCON_CLOCK_ASIC_HZ    (125000)
134 #define EFVI_FALCON_CLOCK_FPGA_HZ    (62500)
135 #define EFVI_FALCON_CLOCK_HZ         EFVI_FALCON_CLOCK_ASIC_HZ
136
137
138 /*----------------------------------------------------------------------------
139  *
140  * Timers
141  *
142  *---------------------------------------------------------------------------*/
143
144 /* Event-Queue Timer granularity - measured in us 
145    Given by: 4096 * 3 cycle * clock period */
146
147 #define EFVI_FALCON_EVQTIMER_PERIOD_US   ((4096 * 3 * 1000) / EFVI_FALCON_CLOCK_HZ)
148
149 /* mode bits */
150 #define EFVI_FALCON_TIMER_MODE_DIS     0     /* disabled */
151 #define EFVI_FALCON_TIMER_MODE_RUN     1     /* started counting right away */
152 #define EFVI_FALCON_TIMER_MODE_HOLD    2     /* trigger mode (user queues) */
153
154 #define EFVI_FALCON_EVQTIMER_HOLD     (EFVI_FALCON_TIMER_MODE_HOLD << TIMER_MODE_LBN)
155 #define EFVI_FALCON_EVQTIMER_RUN      (EFVI_FALCON_TIMER_MODE_RUN  << TIMER_MODE_LBN)
156 #define EFVI_FALCON_EVQTIMER_DISABLE  (EFVI_FALCON_TIMER_MODE_DIS  << TIMER_MODE_LBN) 
157
158
159 /* ---- ef_vi_event helpers --- */
160
161 #define EFVI_FALCON_EVENT_CODE(evp) \
162        ((evp)->u64 & EFVI_FALCON_EVENT_CODE_MASK)
163
164 #define EFVI_FALCON_EVENT_SW_DATA_MASK    0x0000ffff
165
166 #define __EFVI_FALCON_OPEN_MASK(WIDTH)  ((((uint64_t)1) << (WIDTH)) - 1)
167
168 #define EFVI_FALCON_EVENT_CODE_MASK \
169            (__EFVI_FALCON_OPEN_MASK(EV_CODE_WIDTH) << EV_CODE_LBN)
170
171
172 #endif  /* __EF_VI_FALCON_H__ */