Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / drivers / infiniband / qib7322.h
1 #ifndef _QIB7322_H
2 #define _QIB7322_H
3
4 /*
5  * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  */
22
23 FILE_LICENCE ( GPL2_OR_LATER );
24
25 /**
26  * @file
27  *
28  * QLogic QIB7322 Infiniband HCA
29  *
30  */
31
32 #define BITOPS_LITTLE_ENDIAN
33 #include <ipxe/bitops.h>
34 #include "qib_7322_regs.h"
35
36 /** A QIB7322 GPIO register */
37 struct QIB_7322_GPIO_pb {
38         pseudo_bit_t GPIO[16];
39         pseudo_bit_t Reserved[48];
40 };
41 struct QIB_7322_GPIO {
42         PSEUDO_BIT_STRUCT ( struct QIB_7322_GPIO_pb );
43 };
44
45 /** A QIB7322 general scalar register */
46 struct QIB_7322_scalar_pb {
47         pseudo_bit_t Value[64];
48 };
49 struct QIB_7322_scalar {
50         PSEUDO_BIT_STRUCT ( struct QIB_7322_scalar_pb );
51 };
52
53 /** QIB7322 feature mask */
54 struct QIB_7322_feature_mask_pb {
55         pseudo_bit_t Port0_Link_Speed_Supported[3];
56         pseudo_bit_t Port1_Link_Speed_Supported[3];
57         pseudo_bit_t _unused_0[58];
58 };
59 struct QIB_7322_feature_mask {
60         PSEUDO_BIT_STRUCT ( struct QIB_7322_feature_mask_pb );
61 };
62
63 /** QIB7322 send per-buffer control word */
64 struct QIB_7322_SendPbc_pb {
65         pseudo_bit_t LengthP1_toibc[11];
66         pseudo_bit_t Reserved1[4];
67         pseudo_bit_t LengthP1_trigger[11];
68         pseudo_bit_t Reserved2[3];
69         pseudo_bit_t TestEbp[1];
70         pseudo_bit_t Test[1];
71         pseudo_bit_t Intr[1];
72         pseudo_bit_t StaticRateControlCnt[14];
73         pseudo_bit_t Reserved3[12];
74         pseudo_bit_t Port[1];
75         pseudo_bit_t VLane[3];
76         pseudo_bit_t Reserved4[1];
77         pseudo_bit_t VL15[1];
78 };
79 struct QIB_7322_SendPbc {
80         PSEUDO_BIT_STRUCT ( struct QIB_7322_SendPbc_pb );
81 };
82
83 /** QIB7322 send buffer availability */
84 struct QIB_7322_SendBufAvail_pb {
85         pseudo_bit_t InUseCheck[162][2];
86         pseudo_bit_t Reserved[60];
87 };
88 struct QIB_7322_SendBufAvail {
89         PSEUDO_BIT_STRUCT ( struct QIB_7322_SendBufAvail_pb );
90 };
91
92 /** DMA alignment for send buffer availability */
93 #define QIB7322_SENDBUFAVAIL_ALIGN 64
94
95 /** QIB7322 port-specific receive control */
96 struct QIB_7322_RcvCtrl_P_pb {
97         pseudo_bit_t ContextEnable[18];
98         pseudo_bit_t _unused_1[21];
99         pseudo_bit_t RcvIBPortEnable[1];
100         pseudo_bit_t RcvQPMapEnable[1];
101         pseudo_bit_t RcvPartitionKeyDisable[1];
102         pseudo_bit_t RcvResetCredit[1];
103         pseudo_bit_t _unused_2[21];
104 };
105 struct QIB_7322_RcvCtrl_P {
106         PSEUDO_BIT_STRUCT ( struct QIB_7322_RcvCtrl_P_pb );
107 };
108
109 /** A QIB7322 eager receive descriptor */
110 struct QIB_7322_RcvEgr_pb {
111         pseudo_bit_t Addr[37];
112         pseudo_bit_t BufSize[3];
113         pseudo_bit_t Reserved[24];
114 };
115 struct QIB_7322_RcvEgr {
116         PSEUDO_BIT_STRUCT ( struct QIB_7322_RcvEgr_pb );
117 };
118
119 /** QIB7322 receive header flags */
120 struct QIB_7322_RcvHdrFlags_pb {
121         pseudo_bit_t PktLen[11];
122         pseudo_bit_t RcvType[3];
123         pseudo_bit_t SoftB[1];
124         pseudo_bit_t SoftA[1];
125         pseudo_bit_t EgrIndex[12];
126         pseudo_bit_t Reserved1[3];
127         pseudo_bit_t UseEgrBfr[1];
128         pseudo_bit_t RcvSeq[4];
129         pseudo_bit_t HdrqOffset[11];
130         pseudo_bit_t Reserved2[8];
131         pseudo_bit_t IBErr[1];
132         pseudo_bit_t MKErr[1];
133         pseudo_bit_t TIDErr[1];
134         pseudo_bit_t KHdrErr[1];
135         pseudo_bit_t MTUErr[1];
136         pseudo_bit_t LenErr[1];
137         pseudo_bit_t ParityErr[1];
138         pseudo_bit_t VCRCErr[1];
139         pseudo_bit_t ICRCErr[1];
140 };
141 struct QIB_7322_RcvHdrFlags {
142         PSEUDO_BIT_STRUCT ( struct QIB_7322_RcvHdrFlags_pb );
143 };
144
145 /** QIB7322 DDS tuning parameters */
146 struct QIB_7322_IBSD_DDS_MAP_TABLE_pb {
147         pseudo_bit_t Pre[3];
148         pseudo_bit_t PreXtra[2];
149         pseudo_bit_t Post[4];
150         pseudo_bit_t Main[5];
151         pseudo_bit_t Amp[4];
152         pseudo_bit_t _unused_0[46];
153 };
154 struct QIB_7322_IBSD_DDS_MAP_TABLE {
155         PSEUDO_BIT_STRUCT ( struct QIB_7322_IBSD_DDS_MAP_TABLE_pb );
156 };
157
158 /** QIB7322 memory BAR size */
159 #define QIB7322_BAR0_SIZE 0x400000
160
161 /** QIB7322 base port number */
162 #define QIB7322_PORT_BASE 1
163
164 /** QIB7322 maximum number of ports */
165 #define QIB7322_MAX_PORTS 2
166
167 /** QIB7322 maximum width */
168 #define QIB7322_MAX_WIDTH 4
169
170 /** QIB7322 board identifiers */
171 enum qib7322_board_id {
172         QIB7322_BOARD_QLE7342_EMULATION = 0,
173         QIB7322_BOARD_QLE7340 = 1,
174         QIB7322_BOARD_QLE7342 = 2,
175         QIB7322_BOARD_QMI7342 = 3,
176         QIB7322_BOARD_QMH7342_UNSUPPORTED = 4,
177         QIB7322_BOARD_QME7342 = 5,
178         QIB7322_BOARD_QMH7342 = 6,
179         QIB7322_BOARD_QLE7342_TEST = 15,
180 };
181
182 /** QIB7322 I2C SCL line GPIO number */
183 #define QIB7322_GPIO_SCL 0
184
185 /** QIB7322 I2C SDA line GPIO number */
186 #define QIB7322_GPIO_SDA 1
187
188 /** GUID offset within EEPROM */
189 #define QIB7322_EEPROM_GUID_OFFSET 3
190
191 /** GUID size within EEPROM */
192 #define QIB7322_EEPROM_GUID_SIZE 8
193
194 /** Board serial number offset within EEPROM */
195 #define QIB7322_EEPROM_SERIAL_OFFSET 12
196
197 /** Board serial number size within EEPROM */
198 #define QIB7322_EEPROM_SERIAL_SIZE 12
199
200 /** QIB7322 small send buffer size */
201 #define QIB7322_SMALL_SEND_BUF_SIZE 4096
202
203 /** QIB7322 small send buffer starting index */
204 #define QIB7322_SMALL_SEND_BUF_START 0
205
206 /** QIB7322 small send buffer count */
207 #define QIB7322_SMALL_SEND_BUF_COUNT 128
208
209 /** QIB7322 large send buffer size */
210 #define QIB7322_LARGE_SEND_BUF_SIZE 8192
211
212 /** QIB7322 large send buffer starting index */
213 #define QIB7322_LARGE_SEND_BUF_START 128
214
215 /** QIB7322 large send buffer count */
216 #define QIB7322_LARGE_SEND_BUF_COUNT 32
217
218 /** QIB7322 VL15 port 0 send buffer starting index */
219 #define QIB7322_VL15_PORT0_SEND_BUF_START 160
220
221 /** QIB7322 VL15 port 0 send buffer count */
222 #define QIB7322_VL15_PORT0_SEND_BUF_COUNT 1
223
224 /** QIB7322 VL15 port 0 send buffer size */
225 #define QIB7322_VL15_PORT0_SEND_BUF_SIZE 8192
226
227 /** QIB7322 VL15 port 0 send buffer starting index */
228 #define QIB7322_VL15_PORT1_SEND_BUF_START 161
229
230 /** QIB7322 VL15 port 0 send buffer count */
231 #define QIB7322_VL15_PORT1_SEND_BUF_COUNT 1
232
233 /** QIB7322 VL15 port 0 send buffer size */
234 #define QIB7322_VL15_PORT1_SEND_BUF_SIZE 8192
235
236 /** Number of small send buffers used
237  *
238  * This is a policy decision.  Must be less than or equal to the total
239  * number of small send buffers supported by the hardware
240  * (QIB7322_SMALL_SEND_BUF_COUNT).
241  */
242 #define QIB7322_SMALL_SEND_BUF_USED 32
243
244 /** Number of contexts (including kernel context)
245  *
246  * This is a policy decision.  Must be 6, 10 or 18.
247  */
248 #define QIB7322_NUM_CONTEXTS 6
249
250 /** ContextCfg values for different numbers of contexts */
251 enum qib7322_contextcfg {
252         QIB7322_CONTEXTCFG_6CTX = 0,
253         QIB7322_CONTEXTCFG_10CTX = 1,
254         QIB7322_CONTEXTCFG_18CTX = 2,
255 };
256
257 /** ContextCfg values for different numbers of contexts */
258 #define QIB7322_EAGER_ARRAY_SIZE_6CTX_KERNEL 1024
259 #define QIB7322_EAGER_ARRAY_SIZE_6CTX_USER 4096
260 #define QIB7322_EAGER_ARRAY_SIZE_10CTX_KERNEL 1024
261 #define QIB7322_EAGER_ARRAY_SIZE_10CTX_USER 2048
262 #define QIB7322_EAGER_ARRAY_SIZE_18CTX_KERNEL 1024
263 #define QIB7322_EAGER_ARRAY_SIZE_18CTX_USER 1024
264
265 /** Eager buffer required alignment */
266 #define QIB7322_EAGER_BUFFER_ALIGN 2048
267
268 /** Eager buffer size encodings */
269 enum qib7322_eager_buffer_size {
270         QIB7322_EAGER_BUFFER_NONE = 0,
271         QIB7322_EAGER_BUFFER_2K = 1,
272         QIB7322_EAGER_BUFFER_4K = 2,
273         QIB7322_EAGER_BUFFER_8K = 3,
274         QIB7322_EAGER_BUFFER_16K = 4,
275         QIB7322_EAGER_BUFFER_32K = 5,
276         QIB7322_EAGER_BUFFER_64K = 6,
277 };
278
279 /** Number of RX headers per context
280  *
281  * This is a policy decision.
282  */
283 #define QIB7322_RECV_HEADER_COUNT 8
284
285 /** Maximum size of each RX header
286  *
287  * This is a policy decision.  Must be divisible by 4.
288  */
289 #define QIB7322_RECV_HEADER_SIZE 96
290
291 /** Total size of an RX header ring */
292 #define QIB7322_RECV_HEADERS_SIZE \
293         ( QIB7322_RECV_HEADER_SIZE * QIB7322_RECV_HEADER_COUNT )
294
295 /** RX header alignment */
296 #define QIB7322_RECV_HEADERS_ALIGN 64
297
298 /** RX payload size
299  *
300  * This is a policy decision.  Must be a valid eager buffer size.
301  */
302 #define QIB7322_RECV_PAYLOAD_SIZE 2048
303
304 /** Maximum number of credits per port
305  *
306  * 64kB of internal RX buffer space, in units of 64 bytes, split
307  * between two ports.
308  */
309 #define QIB7322_MAX_CREDITS ( ( 65536 / 64 ) / QIB7322_MAX_PORTS )
310
311 /** Number of credits to advertise for VL15
312  *
313  * This is a policy decision.  Using 9 credits allows for 9*64=576
314  * bytes, which is enough for two MADs.
315  */
316 #define QIB7322_MAX_CREDITS_VL15 9
317
318 /** Number of credits to advertise for VL0
319  *
320  * This is a policy decision.
321  */
322 #define QIB7322_MAX_CREDITS_VL0 \
323         ( QIB7322_MAX_CREDITS - QIB7322_MAX_CREDITS_VL15 )
324
325 /** QPN used for Infinipath Packets
326  *
327  * This is a policy decision.  Must have bit 0 clear.  Must not be a
328  * QPN that we will use.
329  */
330 #define QIB7322_QP_IDETH 0xdead0
331
332 /** Maximum time for wait for AHB, in us */
333 #define QIB7322_AHB_MAX_WAIT_US 500
334
335 /** QIB7322 AHB locations */
336 #define QIB7322_AHB_LOC_ADDRESS( _location ) ( (_location) & 0xffff )
337 #define QIB7322_AHB_LOC_TARGET( _location ) ( (_location) >> 16 )
338 #define QIB7322_AHB_CHAN_0 0
339 #define QIB7322_AHB_CHAN_1 1
340 #define QIB7322_AHB_PLL 2
341 #define QIB7322_AHB_CHAN_2 3
342 #define QIB7322_AHB_CHAN_3 4
343 #define QIB7322_AHB_SUBSYS 5
344 #define QIB7322_AHB_CHAN( _channel ) ( (_channel) + ( (_channel) >> 1 ) )
345 #define QIB7322_AHB_TARGET_0 2
346 #define QIB7322_AHB_TARGET_1 3
347 #define QIB7322_AHB_TARGET( _port ) ( (_port) + 2 )
348 #define QIB7322_AHB_LOCATION( _port, _channel, _register )      \
349         ( ( QIB7322_AHB_TARGET(_port) << 16 ) |                 \
350           ( QIB7322_AHB_CHAN(_channel) << 7 ) |                 \
351           ( (_register) << 1 ) )
352
353 /** QIB7322 link states */
354 enum qib7322_link_state {
355         QIB7322_LINK_STATE_DOWN = 0,
356         QIB7322_LINK_STATE_INIT = 1,
357         QIB7322_LINK_STATE_ARM = 2,
358         QIB7322_LINK_STATE_ACTIVE = 3,
359         QIB7322_LINK_STATE_ACT_DEFER = 4,
360 };
361
362 /** Maximum time to wait for link state changes, in us */
363 #define QIB7322_LINK_STATE_MAX_WAIT_US 20
364
365 #endif /* _QIB7322_H */