Commit | Line | Data |
---|---|---|
a2fbb9ea ET |
1 | /* bnx2x_init.h: Broadcom Everest network driver. |
2 | * | |
e8717a47 | 3 | * Copyright (c) 2007-2008 Broadcom Corporation |
a2fbb9ea ET |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation. | |
8 | * | |
24e3fcef EG |
9 | * Maintained by: Eilon Greenstein <eilong@broadcom.com> |
10 | * Written by: Eliezer Tamir | |
a2fbb9ea ET |
11 | */ |
12 | ||
13 | #ifndef BNX2X_INIT_H | |
14 | #define BNX2X_INIT_H | |
15 | ||
16 | #define COMMON 0x1 | |
17 | #define PORT0 0x2 | |
18 | #define PORT1 0x4 | |
19 | ||
20 | #define INIT_EMULATION 0x1 | |
21 | #define INIT_FPGA 0x2 | |
22 | #define INIT_ASIC 0x4 | |
23 | #define INIT_HARDWARE 0x7 | |
24 | ||
25 | #define STORM_INTMEM_SIZE (0x5800 / 4) | |
26 | #define TSTORM_INTMEM_ADDR 0x1a0000 | |
27 | #define CSTORM_INTMEM_ADDR 0x220000 | |
28 | #define XSTORM_INTMEM_ADDR 0x2a0000 | |
29 | #define USTORM_INTMEM_ADDR 0x320000 | |
30 | ||
31 | ||
32 | /* Init operation types and structures */ | |
33 | ||
34 | #define OP_RD 0x1 /* read single register */ | |
35 | #define OP_WR 0x2 /* write single register */ | |
36 | #define OP_IW 0x3 /* write single register using mailbox */ | |
37 | #define OP_SW 0x4 /* copy a string to the device */ | |
38 | #define OP_SI 0x5 /* copy a string using mailbox */ | |
39 | #define OP_ZR 0x6 /* clear memory */ | |
40 | #define OP_ZP 0x7 /* unzip then copy with DMAE */ | |
41 | #define OP_WB 0x8 /* copy a string using DMAE */ | |
42 | ||
43 | struct raw_op { | |
44 | u32 op :8; | |
45 | u32 offset :24; | |
46 | u32 raw_data; | |
47 | }; | |
48 | ||
49 | struct op_read { | |
50 | u32 op :8; | |
51 | u32 offset :24; | |
52 | u32 pad; | |
53 | }; | |
54 | ||
55 | struct op_write { | |
56 | u32 op :8; | |
57 | u32 offset :24; | |
58 | u32 val; | |
59 | }; | |
60 | ||
61 | struct op_string_write { | |
62 | u32 op :8; | |
63 | u32 offset :24; | |
64 | #ifdef __LITTLE_ENDIAN | |
65 | u16 data_off; | |
66 | u16 data_len; | |
67 | #else /* __BIG_ENDIAN */ | |
68 | u16 data_len; | |
69 | u16 data_off; | |
70 | #endif | |
71 | }; | |
72 | ||
73 | struct op_zero { | |
74 | u32 op :8; | |
75 | u32 offset :24; | |
76 | u32 len; | |
77 | }; | |
78 | ||
79 | union init_op { | |
80 | struct op_read read; | |
81 | struct op_write write; | |
82 | struct op_string_write str_wr; | |
83 | struct op_zero zero; | |
84 | struct raw_op raw; | |
85 | }; | |
86 | ||
87 | #include "bnx2x_init_values.h" | |
88 | ||
89 | static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val); | |
a2fbb9ea ET |
90 | static int bnx2x_gunzip(struct bnx2x *bp, u8 *zbuf, int len); |
91 | ||
92 | static void bnx2x_init_str_wr(struct bnx2x *bp, u32 addr, const u32 *data, | |
93 | u32 len) | |
94 | { | |
95 | int i; | |
96 | ||
97 | for (i = 0; i < len; i++) { | |
98 | REG_WR(bp, addr + i*4, data[i]); | |
99 | if (!(i % 10000)) { | |
100 | touch_softlockup_watchdog(); | |
101 | cpu_relax(); | |
102 | } | |
103 | } | |
104 | } | |
105 | ||
a2fbb9ea ET |
106 | static void bnx2x_init_ind_wr(struct bnx2x *bp, u32 addr, const u32 *data, |
107 | u16 len) | |
108 | { | |
109 | int i; | |
110 | ||
111 | for (i = 0; i < len; i++) { | |
112 | REG_WR_IND(bp, addr + i*4, data[i]); | |
113 | if (!(i % 10000)) { | |
114 | touch_softlockup_watchdog(); | |
115 | cpu_relax(); | |
116 | } | |
117 | } | |
118 | } | |
119 | ||
120 | static void bnx2x_init_wr_wb(struct bnx2x *bp, u32 addr, const u32 *data, | |
121 | u32 len, int gunzip) | |
122 | { | |
123 | int offset = 0; | |
124 | ||
125 | if (gunzip) { | |
126 | int rc; | |
127 | #ifdef __BIG_ENDIAN | |
128 | int i, size; | |
129 | u32 *temp; | |
130 | ||
131 | temp = kmalloc(len, GFP_KERNEL); | |
132 | size = (len / 4) + ((len % 4) ? 1 : 0); | |
133 | for (i = 0; i < size; i++) | |
134 | temp[i] = swab32(data[i]); | |
135 | data = temp; | |
136 | #endif | |
137 | rc = bnx2x_gunzip(bp, (u8 *)data, len); | |
138 | if (rc) { | |
139 | DP(NETIF_MSG_HW, "gunzip failed ! rc %d\n", rc); | |
140 | return; | |
141 | } | |
142 | len = bp->gunzip_outlen; | |
143 | #ifdef __BIG_ENDIAN | |
144 | kfree(temp); | |
145 | for (i = 0; i < len; i++) | |
146 | ((u32 *)bp->gunzip_buf)[i] = | |
147 | swab32(((u32 *)bp->gunzip_buf)[i]); | |
148 | #endif | |
149 | } else { | |
150 | if ((len * 4) > FW_BUF_SIZE) { | |
151 | BNX2X_ERR("LARGE DMAE OPERATION ! len 0x%x\n", len*4); | |
152 | return; | |
153 | } | |
154 | memcpy(bp->gunzip_buf, data, len * 4); | |
155 | } | |
156 | ||
157 | while (len > DMAE_LEN32_MAX) { | |
158 | bnx2x_write_dmae(bp, bp->gunzip_mapping + offset, | |
159 | addr + offset, DMAE_LEN32_MAX); | |
160 | offset += DMAE_LEN32_MAX * 4; | |
161 | len -= DMAE_LEN32_MAX; | |
162 | } | |
163 | bnx2x_write_dmae(bp, bp->gunzip_mapping + offset, addr + offset, len); | |
164 | } | |
165 | ||
166 | #define INIT_MEM_WB(reg, data, reg_off, len) \ | |
167 | bnx2x_init_wr_wb(bp, reg + reg_off*4, data, len, 0) | |
168 | ||
169 | #define INIT_GUNZIP_DMAE(reg, data, reg_off, len) \ | |
170 | bnx2x_init_wr_wb(bp, reg + reg_off*4, data, len, 1) | |
171 | ||
172 | static void bnx2x_init_fill(struct bnx2x *bp, u32 addr, int fill, u32 len) | |
173 | { | |
174 | int offset = 0; | |
175 | ||
176 | if ((len * 4) > FW_BUF_SIZE) { | |
177 | BNX2X_ERR("LARGE DMAE OPERATION ! len 0x%x\n", len * 4); | |
178 | return; | |
179 | } | |
180 | memset(bp->gunzip_buf, fill, len * 4); | |
181 | ||
182 | while (len > DMAE_LEN32_MAX) { | |
183 | bnx2x_write_dmae(bp, bp->gunzip_mapping + offset, | |
184 | addr + offset, DMAE_LEN32_MAX); | |
185 | offset += DMAE_LEN32_MAX * 4; | |
186 | len -= DMAE_LEN32_MAX; | |
187 | } | |
188 | bnx2x_write_dmae(bp, bp->gunzip_mapping + offset, addr + offset, len); | |
189 | } | |
190 | ||
191 | static void bnx2x_init_block(struct bnx2x *bp, u32 op_start, u32 op_end) | |
192 | { | |
193 | int i; | |
194 | union init_op *op; | |
195 | u32 op_type, addr, len; | |
196 | const u32 *data; | |
197 | ||
198 | for (i = op_start; i < op_end; i++) { | |
199 | ||
200 | op = (union init_op *)&(init_ops[i]); | |
201 | ||
202 | op_type = op->str_wr.op; | |
203 | addr = op->str_wr.offset; | |
204 | len = op->str_wr.data_len; | |
205 | data = init_data + op->str_wr.data_off; | |
206 | ||
207 | switch (op_type) { | |
208 | case OP_RD: | |
209 | REG_RD(bp, addr); | |
210 | break; | |
211 | case OP_WR: | |
212 | REG_WR(bp, addr, op->write.val); | |
213 | break; | |
214 | case OP_SW: | |
215 | bnx2x_init_str_wr(bp, addr, data, len); | |
216 | break; | |
217 | case OP_WB: | |
218 | bnx2x_init_wr_wb(bp, addr, data, len, 0); | |
219 | break; | |
220 | case OP_SI: | |
221 | bnx2x_init_ind_wr(bp, addr, data, len); | |
222 | break; | |
223 | case OP_ZR: | |
224 | bnx2x_init_fill(bp, addr, 0, op->zero.len); | |
225 | break; | |
226 | case OP_ZP: | |
227 | bnx2x_init_wr_wb(bp, addr, data, len, 1); | |
228 | break; | |
229 | default: | |
230 | BNX2X_ERR("BAD init operation!\n"); | |
231 | } | |
232 | } | |
233 | } | |
234 | ||
235 | ||
236 | /**************************************************************************** | |
237 | * PXP | |
238 | ****************************************************************************/ | |
239 | /* | |
240 | * This code configures the PCI read/write arbiter | |
241 | * which implements a wighted round robin | |
242 | * between the virtual queues in the chip. | |
243 | * | |
244 | * The values were derived for each PCI max payload and max request size. | |
245 | * since max payload and max request size are only known at run time, | |
246 | * this is done as a separate init stage. | |
247 | */ | |
248 | ||
249 | #define NUM_WR_Q 13 | |
250 | #define NUM_RD_Q 29 | |
251 | #define MAX_RD_ORD 3 | |
252 | #define MAX_WR_ORD 2 | |
253 | ||
254 | /* configuration for one arbiter queue */ | |
255 | struct arb_line { | |
256 | int l; | |
257 | int add; | |
258 | int ubound; | |
259 | }; | |
260 | ||
261 | /* derived configuration for each read queue for each max request size */ | |
262 | static const struct arb_line read_arb_data[NUM_RD_Q][MAX_RD_ORD + 1] = { | |
263 | {{8 , 64 , 25}, {16 , 64 , 25}, {32 , 64 , 25}, {64 , 64 , 41} }, | |
264 | {{4 , 8 , 4}, {4 , 8 , 4}, {4 , 8 , 4}, {4 , 8 , 4} }, | |
265 | {{4 , 3 , 3}, {4 , 3 , 3}, {4 , 3 , 3}, {4 , 3 , 3} }, | |
266 | {{8 , 3 , 6}, {16 , 3 , 11}, {16 , 3 , 11}, {16 , 3 , 11} }, | |
267 | {{8 , 64 , 25}, {16 , 64 , 25}, {32 , 64 , 25}, {64 , 64 , 41} }, | |
268 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {64 , 3 , 41} }, | |
269 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {64 , 3 , 41} }, | |
270 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {64 , 3 , 41} }, | |
271 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {64 , 3 , 41} }, | |
272 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
273 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
274 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
275 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
276 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
277 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
278 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
279 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
280 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
281 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
282 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
283 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
284 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
285 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
286 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
287 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
288 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
289 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
290 | {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} }, | |
291 | {{8 , 64 , 25}, {16 , 64 , 41}, {32 , 64 , 81}, {64 , 64 , 120} } | |
292 | }; | |
293 | ||
294 | /* derived configuration for each write queue for each max request size */ | |
295 | static const struct arb_line write_arb_data[NUM_WR_Q][MAX_WR_ORD + 1] = { | |
296 | {{4 , 6 , 3}, {4 , 6 , 3}, {4 , 6 , 3} }, | |
297 | {{4 , 2 , 3}, {4 , 2 , 3}, {4 , 2 , 3} }, | |
298 | {{8 , 2 , 6}, {16 , 2 , 11}, {16 , 2 , 11} }, | |
299 | {{8 , 2 , 6}, {16 , 2 , 11}, {32 , 2 , 21} }, | |
300 | {{8 , 2 , 6}, {16 , 2 , 11}, {32 , 2 , 21} }, | |
301 | {{8 , 2 , 6}, {16 , 2 , 11}, {32 , 2 , 21} }, | |
302 | {{8 , 64 , 25}, {16 , 64 , 25}, {32 , 64 , 25} }, | |
303 | {{8 , 2 , 6}, {16 , 2 , 11}, {16 , 2 , 11} }, | |
304 | {{8 , 2 , 6}, {16 , 2 , 11}, {16 , 2 , 11} }, | |
305 | {{8 , 9 , 6}, {16 , 9 , 11}, {32 , 9 , 21} }, | |
306 | {{8 , 47 , 19}, {16 , 47 , 19}, {32 , 47 , 21} }, | |
307 | {{8 , 9 , 6}, {16 , 9 , 11}, {16 , 9 , 11} }, | |
308 | {{8 , 64 , 25}, {16 , 64 , 41}, {32 , 64 , 81} } | |
309 | }; | |
310 | ||
311 | /* register adresses for read queues */ | |
312 | static const struct arb_line read_arb_addr[NUM_RD_Q-1] = { | |
313 | {PXP2_REG_RQ_BW_RD_L0, PXP2_REG_RQ_BW_RD_ADD0, | |
314 | PXP2_REG_RQ_BW_RD_UBOUND0}, | |
315 | {PXP2_REG_PSWRQ_BW_L1, PXP2_REG_PSWRQ_BW_ADD1, | |
316 | PXP2_REG_PSWRQ_BW_UB1}, | |
317 | {PXP2_REG_PSWRQ_BW_L2, PXP2_REG_PSWRQ_BW_ADD2, | |
318 | PXP2_REG_PSWRQ_BW_UB2}, | |
319 | {PXP2_REG_PSWRQ_BW_L3, PXP2_REG_PSWRQ_BW_ADD3, | |
320 | PXP2_REG_PSWRQ_BW_UB3}, | |
321 | {PXP2_REG_RQ_BW_RD_L4, PXP2_REG_RQ_BW_RD_ADD4, | |
322 | PXP2_REG_RQ_BW_RD_UBOUND4}, | |
323 | {PXP2_REG_RQ_BW_RD_L5, PXP2_REG_RQ_BW_RD_ADD5, | |
324 | PXP2_REG_RQ_BW_RD_UBOUND5}, | |
325 | {PXP2_REG_PSWRQ_BW_L6, PXP2_REG_PSWRQ_BW_ADD6, | |
326 | PXP2_REG_PSWRQ_BW_UB6}, | |
327 | {PXP2_REG_PSWRQ_BW_L7, PXP2_REG_PSWRQ_BW_ADD7, | |
328 | PXP2_REG_PSWRQ_BW_UB7}, | |
329 | {PXP2_REG_PSWRQ_BW_L8, PXP2_REG_PSWRQ_BW_ADD8, | |
330 | PXP2_REG_PSWRQ_BW_UB8}, | |
331 | {PXP2_REG_PSWRQ_BW_L9, PXP2_REG_PSWRQ_BW_ADD9, | |
332 | PXP2_REG_PSWRQ_BW_UB9}, | |
333 | {PXP2_REG_PSWRQ_BW_L10, PXP2_REG_PSWRQ_BW_ADD10, | |
334 | PXP2_REG_PSWRQ_BW_UB10}, | |
335 | {PXP2_REG_PSWRQ_BW_L11, PXP2_REG_PSWRQ_BW_ADD11, | |
336 | PXP2_REG_PSWRQ_BW_UB11}, | |
337 | {PXP2_REG_RQ_BW_RD_L12, PXP2_REG_RQ_BW_RD_ADD12, | |
338 | PXP2_REG_RQ_BW_RD_UBOUND12}, | |
339 | {PXP2_REG_RQ_BW_RD_L13, PXP2_REG_RQ_BW_RD_ADD13, | |
340 | PXP2_REG_RQ_BW_RD_UBOUND13}, | |
341 | {PXP2_REG_RQ_BW_RD_L14, PXP2_REG_RQ_BW_RD_ADD14, | |
342 | PXP2_REG_RQ_BW_RD_UBOUND14}, | |
343 | {PXP2_REG_RQ_BW_RD_L15, PXP2_REG_RQ_BW_RD_ADD15, | |
344 | PXP2_REG_RQ_BW_RD_UBOUND15}, | |
345 | {PXP2_REG_RQ_BW_RD_L16, PXP2_REG_RQ_BW_RD_ADD16, | |
346 | PXP2_REG_RQ_BW_RD_UBOUND16}, | |
347 | {PXP2_REG_RQ_BW_RD_L17, PXP2_REG_RQ_BW_RD_ADD17, | |
348 | PXP2_REG_RQ_BW_RD_UBOUND17}, | |
349 | {PXP2_REG_RQ_BW_RD_L18, PXP2_REG_RQ_BW_RD_ADD18, | |
350 | PXP2_REG_RQ_BW_RD_UBOUND18}, | |
351 | {PXP2_REG_RQ_BW_RD_L19, PXP2_REG_RQ_BW_RD_ADD19, | |
352 | PXP2_REG_RQ_BW_RD_UBOUND19}, | |
353 | {PXP2_REG_RQ_BW_RD_L20, PXP2_REG_RQ_BW_RD_ADD20, | |
354 | PXP2_REG_RQ_BW_RD_UBOUND20}, | |
355 | {PXP2_REG_RQ_BW_RD_L22, PXP2_REG_RQ_BW_RD_ADD22, | |
356 | PXP2_REG_RQ_BW_RD_UBOUND22}, | |
357 | {PXP2_REG_RQ_BW_RD_L23, PXP2_REG_RQ_BW_RD_ADD23, | |
358 | PXP2_REG_RQ_BW_RD_UBOUND23}, | |
359 | {PXP2_REG_RQ_BW_RD_L24, PXP2_REG_RQ_BW_RD_ADD24, | |
360 | PXP2_REG_RQ_BW_RD_UBOUND24}, | |
361 | {PXP2_REG_RQ_BW_RD_L25, PXP2_REG_RQ_BW_RD_ADD25, | |
362 | PXP2_REG_RQ_BW_RD_UBOUND25}, | |
363 | {PXP2_REG_RQ_BW_RD_L26, PXP2_REG_RQ_BW_RD_ADD26, | |
364 | PXP2_REG_RQ_BW_RD_UBOUND26}, | |
365 | {PXP2_REG_RQ_BW_RD_L27, PXP2_REG_RQ_BW_RD_ADD27, | |
366 | PXP2_REG_RQ_BW_RD_UBOUND27}, | |
367 | {PXP2_REG_PSWRQ_BW_L28, PXP2_REG_PSWRQ_BW_ADD28, | |
368 | PXP2_REG_PSWRQ_BW_UB28} | |
369 | }; | |
370 | ||
371 | /* register adresses for wrtie queues */ | |
372 | static const struct arb_line write_arb_addr[NUM_WR_Q-1] = { | |
373 | {PXP2_REG_PSWRQ_BW_L1, PXP2_REG_PSWRQ_BW_ADD1, | |
374 | PXP2_REG_PSWRQ_BW_UB1}, | |
375 | {PXP2_REG_PSWRQ_BW_L2, PXP2_REG_PSWRQ_BW_ADD2, | |
376 | PXP2_REG_PSWRQ_BW_UB2}, | |
377 | {PXP2_REG_PSWRQ_BW_L3, PXP2_REG_PSWRQ_BW_ADD3, | |
378 | PXP2_REG_PSWRQ_BW_UB3}, | |
379 | {PXP2_REG_PSWRQ_BW_L6, PXP2_REG_PSWRQ_BW_ADD6, | |
380 | PXP2_REG_PSWRQ_BW_UB6}, | |
381 | {PXP2_REG_PSWRQ_BW_L7, PXP2_REG_PSWRQ_BW_ADD7, | |
382 | PXP2_REG_PSWRQ_BW_UB7}, | |
383 | {PXP2_REG_PSWRQ_BW_L8, PXP2_REG_PSWRQ_BW_ADD8, | |
384 | PXP2_REG_PSWRQ_BW_UB8}, | |
385 | {PXP2_REG_PSWRQ_BW_L9, PXP2_REG_PSWRQ_BW_ADD9, | |
386 | PXP2_REG_PSWRQ_BW_UB9}, | |
387 | {PXP2_REG_PSWRQ_BW_L10, PXP2_REG_PSWRQ_BW_ADD10, | |
388 | PXP2_REG_PSWRQ_BW_UB10}, | |
389 | {PXP2_REG_PSWRQ_BW_L11, PXP2_REG_PSWRQ_BW_ADD11, | |
390 | PXP2_REG_PSWRQ_BW_UB11}, | |
391 | {PXP2_REG_PSWRQ_BW_L28, PXP2_REG_PSWRQ_BW_ADD28, | |
392 | PXP2_REG_PSWRQ_BW_UB28}, | |
393 | {PXP2_REG_RQ_BW_WR_L29, PXP2_REG_RQ_BW_WR_ADD29, | |
394 | PXP2_REG_RQ_BW_WR_UBOUND29}, | |
395 | {PXP2_REG_RQ_BW_WR_L30, PXP2_REG_RQ_BW_WR_ADD30, | |
396 | PXP2_REG_RQ_BW_WR_UBOUND30} | |
397 | }; | |
398 | ||
399 | static void bnx2x_init_pxp(struct bnx2x *bp) | |
400 | { | |
401 | int r_order, w_order; | |
402 | u32 val, i; | |
403 | ||
404 | pci_read_config_word(bp->pdev, | |
405 | bp->pcie_cap + PCI_EXP_DEVCTL, (u16 *)&val); | |
e8717a47 | 406 | DP(NETIF_MSG_HW, "read 0x%x from devctl\n", (u16)val); |
a2fbb9ea ET |
407 | w_order = ((val & PCI_EXP_DEVCTL_PAYLOAD) >> 5); |
408 | r_order = ((val & PCI_EXP_DEVCTL_READRQ) >> 12); | |
409 | ||
410 | if (r_order > MAX_RD_ORD) { | |
411 | DP(NETIF_MSG_HW, "read order of %d order adjusted to %d\n", | |
412 | r_order, MAX_RD_ORD); | |
413 | r_order = MAX_RD_ORD; | |
414 | } | |
415 | if (w_order > MAX_WR_ORD) { | |
416 | DP(NETIF_MSG_HW, "write order of %d order adjusted to %d\n", | |
417 | w_order, MAX_WR_ORD); | |
418 | w_order = MAX_WR_ORD; | |
419 | } | |
420 | DP(NETIF_MSG_HW, "read order %d write order %d\n", r_order, w_order); | |
421 | ||
422 | for (i = 0; i < NUM_RD_Q-1; i++) { | |
423 | REG_WR(bp, read_arb_addr[i].l, read_arb_data[i][r_order].l); | |
424 | REG_WR(bp, read_arb_addr[i].add, | |
425 | read_arb_data[i][r_order].add); | |
426 | REG_WR(bp, read_arb_addr[i].ubound, | |
427 | read_arb_data[i][r_order].ubound); | |
428 | } | |
429 | ||
430 | for (i = 0; i < NUM_WR_Q-1; i++) { | |
431 | if ((write_arb_addr[i].l == PXP2_REG_RQ_BW_WR_L29) || | |
432 | (write_arb_addr[i].l == PXP2_REG_RQ_BW_WR_L30)) { | |
433 | ||
434 | REG_WR(bp, write_arb_addr[i].l, | |
435 | write_arb_data[i][w_order].l); | |
436 | ||
437 | REG_WR(bp, write_arb_addr[i].add, | |
438 | write_arb_data[i][w_order].add); | |
439 | ||
440 | REG_WR(bp, write_arb_addr[i].ubound, | |
441 | write_arb_data[i][w_order].ubound); | |
442 | } else { | |
443 | ||
444 | val = REG_RD(bp, write_arb_addr[i].l); | |
445 | REG_WR(bp, write_arb_addr[i].l, | |
446 | val | (write_arb_data[i][w_order].l << 10)); | |
447 | ||
448 | val = REG_RD(bp, write_arb_addr[i].add); | |
449 | REG_WR(bp, write_arb_addr[i].add, | |
450 | val | (write_arb_data[i][w_order].add << 10)); | |
451 | ||
452 | val = REG_RD(bp, write_arb_addr[i].ubound); | |
453 | REG_WR(bp, write_arb_addr[i].ubound, | |
454 | val | (write_arb_data[i][w_order].ubound << 7)); | |
455 | } | |
456 | } | |
457 | ||
458 | val = write_arb_data[NUM_WR_Q-1][w_order].add; | |
459 | val += write_arb_data[NUM_WR_Q-1][w_order].ubound << 10; | |
460 | val += write_arb_data[NUM_WR_Q-1][w_order].l << 17; | |
461 | REG_WR(bp, PXP2_REG_PSWRQ_BW_RD, val); | |
462 | ||
463 | val = read_arb_data[NUM_RD_Q-1][r_order].add; | |
464 | val += read_arb_data[NUM_RD_Q-1][r_order].ubound << 10; | |
465 | val += read_arb_data[NUM_RD_Q-1][r_order].l << 17; | |
466 | REG_WR(bp, PXP2_REG_PSWRQ_BW_WR, val); | |
467 | ||
468 | REG_WR(bp, PXP2_REG_RQ_WR_MBS0, w_order); | |
e8717a47 | 469 | REG_WR(bp, PXP2_REG_RQ_WR_MBS1, w_order); |
a2fbb9ea | 470 | REG_WR(bp, PXP2_REG_RQ_RD_MBS0, r_order); |
e8717a47 | 471 | REG_WR(bp, PXP2_REG_RQ_RD_MBS1, r_order); |
a2fbb9ea | 472 | |
e8717a47 ET |
473 | if (r_order == MAX_RD_ORD) |
474 | REG_WR(bp, PXP2_REG_RQ_PDR_LIMIT, 0xe00); | |
475 | ||
476 | REG_WR(bp, PXP2_REG_WR_USDMDP_TH, (0x18 << w_order)); | |
a2fbb9ea ET |
477 | REG_WR(bp, PXP2_REG_WR_DMAE_TH, (128 << w_order)/16); |
478 | } | |
479 | ||
480 | ||
481 | /**************************************************************************** | |
482 | * CDU | |
483 | ****************************************************************************/ | |
484 | ||
485 | #define CDU_REGION_NUMBER_XCM_AG 2 | |
486 | #define CDU_REGION_NUMBER_UCM_AG 4 | |
487 | ||
488 | /** | |
489 | * String-to-compress [31:8] = CID (all 24 bits) | |
490 | * String-to-compress [7:4] = Region | |
491 | * String-to-compress [3:0] = Type | |
492 | */ | |
493 | #define CDU_VALID_DATA(_cid, _region, _type) \ | |
494 | (((_cid) << 8) | (((_region) & 0xf) << 4) | (((_type) & 0xf))) | |
495 | #define CDU_CRC8(_cid, _region, _type) \ | |
496 | calc_crc8(CDU_VALID_DATA(_cid, _region, _type), 0xff) | |
497 | #define CDU_RSRVD_VALUE_TYPE_A(_cid, _region, _type) \ | |
498 | (0x80 | (CDU_CRC8(_cid, _region, _type) & 0x7f)) | |
499 | #define CDU_RSRVD_VALUE_TYPE_B(_crc, _type) \ | |
500 | (0x80 | ((_type) & 0xf << 3) | (CDU_CRC8(_cid, _region, _type) & 0x7)) | |
501 | #define CDU_RSRVD_INVALIDATE_CONTEXT_VALUE(_val) ((_val) & ~0x80) | |
502 | ||
503 | /***************************************************************************** | |
504 | * Description: | |
505 | * Calculates crc 8 on a word value: polynomial 0-1-2-8 | |
506 | * Code was translated from Verilog. | |
507 | ****************************************************************************/ | |
508 | static u8 calc_crc8(u32 data, u8 crc) | |
509 | { | |
510 | u8 D[32]; | |
511 | u8 NewCRC[8]; | |
512 | u8 C[8]; | |
513 | u8 crc_res; | |
514 | u8 i; | |
515 | ||
516 | /* split the data into 31 bits */ | |
517 | for (i = 0; i < 32; i++) { | |
518 | D[i] = data & 1; | |
519 | data = data >> 1; | |
520 | } | |
521 | ||
522 | /* split the crc into 8 bits */ | |
523 | for (i = 0; i < 8; i++) { | |
524 | C[i] = crc & 1; | |
525 | crc = crc >> 1; | |
526 | } | |
527 | ||
528 | NewCRC[0] = D[31] ^ D[30] ^ D[28] ^ D[23] ^ D[21] ^ D[19] ^ D[18] ^ | |
529 | D[16] ^ D[14] ^ D[12] ^ D[8] ^ D[7] ^ D[6] ^ D[0] ^ C[4] ^ | |
530 | C[6] ^ C[7]; | |
531 | NewCRC[1] = D[30] ^ D[29] ^ D[28] ^ D[24] ^ D[23] ^ D[22] ^ D[21] ^ | |
532 | D[20] ^ D[18] ^ D[17] ^ D[16] ^ D[15] ^ D[14] ^ D[13] ^ | |
533 | D[12] ^ D[9] ^ D[6] ^ D[1] ^ D[0] ^ C[0] ^ C[4] ^ C[5] ^ C[6]; | |
534 | NewCRC[2] = D[29] ^ D[28] ^ D[25] ^ D[24] ^ D[22] ^ D[17] ^ D[15] ^ | |
535 | D[13] ^ D[12] ^ D[10] ^ D[8] ^ D[6] ^ D[2] ^ D[1] ^ D[0] ^ | |
536 | C[0] ^ C[1] ^ C[4] ^ C[5]; | |
537 | NewCRC[3] = D[30] ^ D[29] ^ D[26] ^ D[25] ^ D[23] ^ D[18] ^ D[16] ^ | |
538 | D[14] ^ D[13] ^ D[11] ^ D[9] ^ D[7] ^ D[3] ^ D[2] ^ D[1] ^ | |
539 | C[1] ^ C[2] ^ C[5] ^ C[6]; | |
540 | NewCRC[4] = D[31] ^ D[30] ^ D[27] ^ D[26] ^ D[24] ^ D[19] ^ D[17] ^ | |
541 | D[15] ^ D[14] ^ D[12] ^ D[10] ^ D[8] ^ D[4] ^ D[3] ^ D[2] ^ | |
542 | C[0] ^ C[2] ^ C[3] ^ C[6] ^ C[7]; | |
543 | NewCRC[5] = D[31] ^ D[28] ^ D[27] ^ D[25] ^ D[20] ^ D[18] ^ D[16] ^ | |
544 | D[15] ^ D[13] ^ D[11] ^ D[9] ^ D[5] ^ D[4] ^ D[3] ^ C[1] ^ | |
545 | C[3] ^ C[4] ^ C[7]; | |
546 | NewCRC[6] = D[29] ^ D[28] ^ D[26] ^ D[21] ^ D[19] ^ D[17] ^ D[16] ^ | |
547 | D[14] ^ D[12] ^ D[10] ^ D[6] ^ D[5] ^ D[4] ^ C[2] ^ C[4] ^ | |
548 | C[5]; | |
549 | NewCRC[7] = D[30] ^ D[29] ^ D[27] ^ D[22] ^ D[20] ^ D[18] ^ D[17] ^ | |
550 | D[15] ^ D[13] ^ D[11] ^ D[7] ^ D[6] ^ D[5] ^ C[3] ^ C[5] ^ | |
551 | C[6]; | |
552 | ||
553 | crc_res = 0; | |
554 | for (i = 0; i < 8; i++) | |
555 | crc_res |= (NewCRC[i] << i); | |
556 | ||
557 | return crc_res; | |
558 | } | |
559 | ||
560 | ||
561 | #endif /* BNX2X_INIT_H */ | |
562 |