]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/net/bnx2x/bnx2x_init_ops.h
e65de784182c72e9e1395086b08b569ee5823328
[net-next-2.6.git] / drivers / net / bnx2x / bnx2x_init_ops.h
1 /* bnx2x_init_ops.h: Broadcom Everest network driver.
2  *               Static functions needed during the initialization.
3  *               This file is "included" in bnx2x_main.c.
4  *
5  * Copyright (c) 2007-2010 Broadcom Corporation
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation.
10  *
11  * Maintained by: Eilon Greenstein <eilong@broadcom.com>
12  * Written by: Vladislav Zolotarov <vladz@broadcom.com>
13  */
14
15 #ifndef BNX2X_INIT_OPS_H
16 #define BNX2X_INIT_OPS_H
17
18 static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len);
19
20
21 static void bnx2x_init_str_wr(struct bnx2x *bp, u32 addr, const u32 *data,
22                               u32 len)
23 {
24         u32 i;
25
26         for (i = 0; i < len; i++)
27                 REG_WR(bp, addr + i*4, data[i]);
28 }
29
30 static void bnx2x_init_ind_wr(struct bnx2x *bp, u32 addr, const u32 *data,
31                               u32 len)
32 {
33         u32 i;
34
35         for (i = 0; i < len; i++)
36                 REG_WR_IND(bp, addr + i*4, data[i]);
37 }
38
39 static void bnx2x_write_big_buf(struct bnx2x *bp, u32 addr, u32 len)
40 {
41         if (bp->dmae_ready)
42                 bnx2x_write_dmae_phys_len(bp, GUNZIP_PHYS(bp), addr, len);
43         else
44                 bnx2x_init_str_wr(bp, addr, GUNZIP_BUF(bp), len);
45 }
46
47 static void bnx2x_init_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
48 {
49         u32 buf_len = (((len*4) > FW_BUF_SIZE) ? FW_BUF_SIZE : (len*4));
50         u32 buf_len32 = buf_len/4;
51         u32 i;
52
53         memset(GUNZIP_BUF(bp), (u8)fill, buf_len);
54
55         for (i = 0; i < len; i += buf_len32) {
56                 u32 cur_len = min(buf_len32, len - i);
57
58                 bnx2x_write_big_buf(bp, addr + i*4, cur_len);
59         }
60 }
61
62 static void bnx2x_init_wr_64(struct bnx2x *bp, u32 addr, const u32 *data,
63                              u32 len64)
64 {
65         u32 buf_len32 = FW_BUF_SIZE/4;
66         u32 len = len64*2;
67         u64 data64 = 0;
68         u32 i;
69
70         /* 64 bit value is in a blob: first low DWORD, then high DWORD */
71         data64 = HILO_U64((*(data + 1)), (*data));
72
73         len64 = min((u32)(FW_BUF_SIZE/8), len64);
74         for (i = 0; i < len64; i++) {
75                 u64 *pdata = ((u64 *)(GUNZIP_BUF(bp))) + i;
76
77                 *pdata = data64;
78         }
79
80         for (i = 0; i < len; i += buf_len32) {
81                 u32 cur_len = min(buf_len32, len - i);
82
83                 bnx2x_write_big_buf(bp, addr + i*4, cur_len);
84         }
85 }
86
87 /*********************************************************
88    There are different blobs for each PRAM section.
89    In addition, each blob write operation is divided into a few operations
90    in order to decrease the amount of phys. contiguous buffer needed.
91    Thus, when we select a blob the address may be with some offset
92    from the beginning of PRAM section.
93    The same holds for the INT_TABLE sections.
94 **********************************************************/
95 #define IF_IS_INT_TABLE_ADDR(base, addr) \
96                         if (((base) <= (addr)) && ((base) + 0x400 >= (addr)))
97
98 #define IF_IS_PRAM_ADDR(base, addr) \
99                         if (((base) <= (addr)) && ((base) + 0x40000 >= (addr)))
100
101 static const u8 *bnx2x_sel_blob(struct bnx2x *bp, u32 addr, const u8 *data)
102 {
103         IF_IS_INT_TABLE_ADDR(TSEM_REG_INT_TABLE, addr)
104                 data = INIT_TSEM_INT_TABLE_DATA(bp);
105         else
106                 IF_IS_INT_TABLE_ADDR(CSEM_REG_INT_TABLE, addr)
107                         data = INIT_CSEM_INT_TABLE_DATA(bp);
108         else
109                 IF_IS_INT_TABLE_ADDR(USEM_REG_INT_TABLE, addr)
110                         data = INIT_USEM_INT_TABLE_DATA(bp);
111         else
112                 IF_IS_INT_TABLE_ADDR(XSEM_REG_INT_TABLE, addr)
113                         data = INIT_XSEM_INT_TABLE_DATA(bp);
114         else
115                 IF_IS_PRAM_ADDR(TSEM_REG_PRAM, addr)
116                         data = INIT_TSEM_PRAM_DATA(bp);
117         else
118                 IF_IS_PRAM_ADDR(CSEM_REG_PRAM, addr)
119                         data = INIT_CSEM_PRAM_DATA(bp);
120         else
121                 IF_IS_PRAM_ADDR(USEM_REG_PRAM, addr)
122                         data = INIT_USEM_PRAM_DATA(bp);
123         else
124                 IF_IS_PRAM_ADDR(XSEM_REG_PRAM, addr)
125                         data = INIT_XSEM_PRAM_DATA(bp);
126
127         return data;
128 }
129
130 static void bnx2x_write_big_buf_wb(struct bnx2x *bp, u32 addr, u32 len)
131 {
132         if (bp->dmae_ready)
133                 bnx2x_write_dmae_phys_len(bp, GUNZIP_PHYS(bp), addr, len);
134         else
135                 bnx2x_init_ind_wr(bp, addr, GUNZIP_BUF(bp), len);
136 }
137
138 static void bnx2x_init_wr_wb(struct bnx2x *bp, u32 addr, const u32 *data,
139                              u32 len)
140 {
141         const u32 *old_data = data;
142
143         data = (const u32 *)bnx2x_sel_blob(bp, addr, (const u8 *)data);
144
145         if (bp->dmae_ready) {
146                 if (old_data != data)
147                         VIRT_WR_DMAE_LEN(bp, data, addr, len, 1);
148                 else
149                         VIRT_WR_DMAE_LEN(bp, data, addr, len, 0);
150         } else
151                 bnx2x_init_ind_wr(bp, addr, data, len);
152 }
153
154 static void bnx2x_wr_64(struct bnx2x *bp, u32 reg, u32 val_lo, u32 val_hi)
155 {
156         u32 wb_write[2];
157
158         wb_write[0] = val_lo;
159         wb_write[1] = val_hi;
160         REG_WR_DMAE_LEN(bp, reg, wb_write, 2);
161 }
162
163 static void bnx2x_init_wr_zp(struct bnx2x *bp, u32 addr, u32 len, u32 blob_off)
164 {
165         const u8 *data = NULL;
166         int rc;
167         u32 i;
168
169         data = bnx2x_sel_blob(bp, addr, data) + blob_off*4;
170
171         rc = bnx2x_gunzip(bp, data, len);
172         if (rc)
173                 return;
174
175         /* gunzip_outlen is in dwords */
176         len = GUNZIP_OUTLEN(bp);
177         for (i = 0; i < len; i++)
178                 ((u32 *)GUNZIP_BUF(bp))[i] =
179                                 cpu_to_le32(((u32 *)GUNZIP_BUF(bp))[i]);
180
181         bnx2x_write_big_buf_wb(bp, addr, len);
182 }
183
184 static void bnx2x_init_block(struct bnx2x *bp, u32 block, u32 stage)
185 {
186         u16 op_start =
187                 INIT_OPS_OFFSETS(bp)[BLOCK_OPS_IDX(block, stage, STAGE_START)];
188         u16 op_end =
189                 INIT_OPS_OFFSETS(bp)[BLOCK_OPS_IDX(block, stage, STAGE_END)];
190         union init_op *op;
191         int hw_wr;
192         u32 i, op_type, addr, len;
193         const u32 *data, *data_base;
194
195         /* If empty block */
196         if (op_start == op_end)
197                 return;
198
199         if (CHIP_REV_IS_FPGA(bp))
200                 hw_wr = OP_WR_FPGA;
201         else if (CHIP_REV_IS_EMUL(bp))
202                 hw_wr = OP_WR_EMUL;
203         else
204                 hw_wr = OP_WR_ASIC;
205
206         data_base = INIT_DATA(bp);
207
208         for (i = op_start; i < op_end; i++) {
209
210                 op = (union init_op *)&(INIT_OPS(bp)[i]);
211
212                 op_type = op->str_wr.op;
213                 addr = op->str_wr.offset;
214                 len = op->str_wr.data_len;
215                 data = data_base + op->str_wr.data_off;
216
217                 /* HW/EMUL specific */
218                 if ((op_type > OP_WB) && (op_type == hw_wr))
219                         op_type = OP_WR;
220
221                 switch (op_type) {
222                 case OP_RD:
223                         REG_RD(bp, addr);
224                         break;
225                 case OP_WR:
226                         REG_WR(bp, addr, op->write.val);
227                         break;
228                 case OP_SW:
229                         bnx2x_init_str_wr(bp, addr, data, len);
230                         break;
231                 case OP_WB:
232                         bnx2x_init_wr_wb(bp, addr, data, len);
233                         break;
234                 case OP_SI:
235                         bnx2x_init_ind_wr(bp, addr, data, len);
236                         break;
237                 case OP_ZR:
238                         bnx2x_init_fill(bp, addr, 0, op->zero.len);
239                         break;
240                 case OP_ZP:
241                         bnx2x_init_wr_zp(bp, addr, len,
242                                          op->str_wr.data_off);
243                         break;
244                 case OP_WR_64:
245                         bnx2x_init_wr_64(bp, addr, data, len);
246                         break;
247                 default:
248                         /* happens whenever an op is of a diff HW */
249                         break;
250                 }
251         }
252 }
253
254
255 /****************************************************************************
256 * PXP Arbiter
257 ****************************************************************************/
258 /*
259  * This code configures the PCI read/write arbiter
260  * which implements a weighted round robin
261  * between the virtual queues in the chip.
262  *
263  * The values were derived for each PCI max payload and max request size.
264  * since max payload and max request size are only known at run time,
265  * this is done as a separate init stage.
266  */
267
268 #define NUM_WR_Q                        13
269 #define NUM_RD_Q                        29
270 #define MAX_RD_ORD                      3
271 #define MAX_WR_ORD                      2
272
273 /* configuration for one arbiter queue */
274 struct arb_line {
275         int l;
276         int add;
277         int ubound;
278 };
279
280 /* derived configuration for each read queue for each max request size */
281 static const struct arb_line read_arb_data[NUM_RD_Q][MAX_RD_ORD + 1] = {
282 /* 1 */ { {8, 64, 25}, {16, 64, 25}, {32, 64, 25}, {64, 64, 41} },
283         { {4, 8,  4},  {4,  8,  4},  {4,  8,  4},  {4,  8,  4}  },
284         { {4, 3,  3},  {4,  3,  3},  {4,  3,  3},  {4,  3,  3}  },
285         { {8, 3,  6},  {16, 3,  11}, {16, 3,  11}, {16, 3,  11} },
286         { {8, 64, 25}, {16, 64, 25}, {32, 64, 25}, {64, 64, 41} },
287         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {64, 3,  41} },
288         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {64, 3,  41} },
289         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {64, 3,  41} },
290         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {64, 3,  41} },
291 /* 10 */{ {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
292         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
293         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
294         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
295         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
296         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
297         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
298         { {8, 64, 6},  {16, 64, 11}, {32, 64, 21}, {32, 64, 21} },
299         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
300         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
301 /* 20 */{ {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
302         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
303         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
304         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
305         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
306         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
307         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
308         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
309         { {8, 3,  6},  {16, 3,  11}, {32, 3,  21}, {32, 3,  21} },
310         { {8, 64, 25}, {16, 64, 41}, {32, 64, 81}, {64, 64, 120} }
311 };
312
313 /* derived configuration for each write queue for each max request size */
314 static const struct arb_line write_arb_data[NUM_WR_Q][MAX_WR_ORD + 1] = {
315 /* 1 */ { {4, 6,  3},  {4,  6,  3},  {4,  6,  3} },
316         { {4, 2,  3},  {4,  2,  3},  {4,  2,  3} },
317         { {8, 2,  6},  {16, 2,  11}, {16, 2,  11} },
318         { {8, 2,  6},  {16, 2,  11}, {32, 2,  21} },
319         { {8, 2,  6},  {16, 2,  11}, {32, 2,  21} },
320         { {8, 2,  6},  {16, 2,  11}, {32, 2,  21} },
321         { {8, 64, 25}, {16, 64, 25}, {32, 64, 25} },
322         { {8, 2,  6},  {16, 2,  11}, {16, 2,  11} },
323         { {8, 2,  6},  {16, 2,  11}, {16, 2,  11} },
324 /* 10 */{ {8, 9,  6},  {16, 9,  11}, {32, 9,  21} },
325         { {8, 47, 19}, {16, 47, 19}, {32, 47, 21} },
326         { {8, 9,  6},  {16, 9,  11}, {16, 9,  11} },
327         { {8, 64, 25}, {16, 64, 41}, {32, 64, 81} }
328 };
329
330 /* register addresses for read queues */
331 static const struct arb_line read_arb_addr[NUM_RD_Q-1] = {
332 /* 1 */ {PXP2_REG_RQ_BW_RD_L0, PXP2_REG_RQ_BW_RD_ADD0,
333                 PXP2_REG_RQ_BW_RD_UBOUND0},
334         {PXP2_REG_PSWRQ_BW_L1, PXP2_REG_PSWRQ_BW_ADD1,
335                 PXP2_REG_PSWRQ_BW_UB1},
336         {PXP2_REG_PSWRQ_BW_L2, PXP2_REG_PSWRQ_BW_ADD2,
337                 PXP2_REG_PSWRQ_BW_UB2},
338         {PXP2_REG_PSWRQ_BW_L3, PXP2_REG_PSWRQ_BW_ADD3,
339                 PXP2_REG_PSWRQ_BW_UB3},
340         {PXP2_REG_RQ_BW_RD_L4, PXP2_REG_RQ_BW_RD_ADD4,
341                 PXP2_REG_RQ_BW_RD_UBOUND4},
342         {PXP2_REG_RQ_BW_RD_L5, PXP2_REG_RQ_BW_RD_ADD5,
343                 PXP2_REG_RQ_BW_RD_UBOUND5},
344         {PXP2_REG_PSWRQ_BW_L6, PXP2_REG_PSWRQ_BW_ADD6,
345                 PXP2_REG_PSWRQ_BW_UB6},
346         {PXP2_REG_PSWRQ_BW_L7, PXP2_REG_PSWRQ_BW_ADD7,
347                 PXP2_REG_PSWRQ_BW_UB7},
348         {PXP2_REG_PSWRQ_BW_L8, PXP2_REG_PSWRQ_BW_ADD8,
349                 PXP2_REG_PSWRQ_BW_UB8},
350 /* 10 */{PXP2_REG_PSWRQ_BW_L9, PXP2_REG_PSWRQ_BW_ADD9,
351                 PXP2_REG_PSWRQ_BW_UB9},
352         {PXP2_REG_PSWRQ_BW_L10, PXP2_REG_PSWRQ_BW_ADD10,
353                 PXP2_REG_PSWRQ_BW_UB10},
354         {PXP2_REG_PSWRQ_BW_L11, PXP2_REG_PSWRQ_BW_ADD11,
355                 PXP2_REG_PSWRQ_BW_UB11},
356         {PXP2_REG_RQ_BW_RD_L12, PXP2_REG_RQ_BW_RD_ADD12,
357                 PXP2_REG_RQ_BW_RD_UBOUND12},
358         {PXP2_REG_RQ_BW_RD_L13, PXP2_REG_RQ_BW_RD_ADD13,
359                 PXP2_REG_RQ_BW_RD_UBOUND13},
360         {PXP2_REG_RQ_BW_RD_L14, PXP2_REG_RQ_BW_RD_ADD14,
361                 PXP2_REG_RQ_BW_RD_UBOUND14},
362         {PXP2_REG_RQ_BW_RD_L15, PXP2_REG_RQ_BW_RD_ADD15,
363                 PXP2_REG_RQ_BW_RD_UBOUND15},
364         {PXP2_REG_RQ_BW_RD_L16, PXP2_REG_RQ_BW_RD_ADD16,
365                 PXP2_REG_RQ_BW_RD_UBOUND16},
366         {PXP2_REG_RQ_BW_RD_L17, PXP2_REG_RQ_BW_RD_ADD17,
367                 PXP2_REG_RQ_BW_RD_UBOUND17},
368         {PXP2_REG_RQ_BW_RD_L18, PXP2_REG_RQ_BW_RD_ADD18,
369                 PXP2_REG_RQ_BW_RD_UBOUND18},
370 /* 20 */{PXP2_REG_RQ_BW_RD_L19, PXP2_REG_RQ_BW_RD_ADD19,
371                 PXP2_REG_RQ_BW_RD_UBOUND19},
372         {PXP2_REG_RQ_BW_RD_L20, PXP2_REG_RQ_BW_RD_ADD20,
373                 PXP2_REG_RQ_BW_RD_UBOUND20},
374         {PXP2_REG_RQ_BW_RD_L22, PXP2_REG_RQ_BW_RD_ADD22,
375                 PXP2_REG_RQ_BW_RD_UBOUND22},
376         {PXP2_REG_RQ_BW_RD_L23, PXP2_REG_RQ_BW_RD_ADD23,
377                 PXP2_REG_RQ_BW_RD_UBOUND23},
378         {PXP2_REG_RQ_BW_RD_L24, PXP2_REG_RQ_BW_RD_ADD24,
379                 PXP2_REG_RQ_BW_RD_UBOUND24},
380         {PXP2_REG_RQ_BW_RD_L25, PXP2_REG_RQ_BW_RD_ADD25,
381                 PXP2_REG_RQ_BW_RD_UBOUND25},
382         {PXP2_REG_RQ_BW_RD_L26, PXP2_REG_RQ_BW_RD_ADD26,
383                 PXP2_REG_RQ_BW_RD_UBOUND26},
384         {PXP2_REG_RQ_BW_RD_L27, PXP2_REG_RQ_BW_RD_ADD27,
385                 PXP2_REG_RQ_BW_RD_UBOUND27},
386         {PXP2_REG_PSWRQ_BW_L28, PXP2_REG_PSWRQ_BW_ADD28,
387                 PXP2_REG_PSWRQ_BW_UB28}
388 };
389
390 /* register addresses for write queues */
391 static const struct arb_line write_arb_addr[NUM_WR_Q-1] = {
392 /* 1 */ {PXP2_REG_PSWRQ_BW_L1, PXP2_REG_PSWRQ_BW_ADD1,
393                 PXP2_REG_PSWRQ_BW_UB1},
394         {PXP2_REG_PSWRQ_BW_L2, PXP2_REG_PSWRQ_BW_ADD2,
395                 PXP2_REG_PSWRQ_BW_UB2},
396         {PXP2_REG_PSWRQ_BW_L3, PXP2_REG_PSWRQ_BW_ADD3,
397                 PXP2_REG_PSWRQ_BW_UB3},
398         {PXP2_REG_PSWRQ_BW_L6, PXP2_REG_PSWRQ_BW_ADD6,
399                 PXP2_REG_PSWRQ_BW_UB6},
400         {PXP2_REG_PSWRQ_BW_L7, PXP2_REG_PSWRQ_BW_ADD7,
401                 PXP2_REG_PSWRQ_BW_UB7},
402         {PXP2_REG_PSWRQ_BW_L8, PXP2_REG_PSWRQ_BW_ADD8,
403                 PXP2_REG_PSWRQ_BW_UB8},
404         {PXP2_REG_PSWRQ_BW_L9, PXP2_REG_PSWRQ_BW_ADD9,
405                 PXP2_REG_PSWRQ_BW_UB9},
406         {PXP2_REG_PSWRQ_BW_L10, PXP2_REG_PSWRQ_BW_ADD10,
407                 PXP2_REG_PSWRQ_BW_UB10},
408         {PXP2_REG_PSWRQ_BW_L11, PXP2_REG_PSWRQ_BW_ADD11,
409                 PXP2_REG_PSWRQ_BW_UB11},
410 /* 10 */{PXP2_REG_PSWRQ_BW_L28, PXP2_REG_PSWRQ_BW_ADD28,
411                 PXP2_REG_PSWRQ_BW_UB28},
412         {PXP2_REG_RQ_BW_WR_L29, PXP2_REG_RQ_BW_WR_ADD29,
413                 PXP2_REG_RQ_BW_WR_UBOUND29},
414         {PXP2_REG_RQ_BW_WR_L30, PXP2_REG_RQ_BW_WR_ADD30,
415                 PXP2_REG_RQ_BW_WR_UBOUND30}
416 };
417
418 static void bnx2x_init_pxp_arb(struct bnx2x *bp, int r_order, int w_order)
419 {
420         u32 val, i;
421
422         if (r_order > MAX_RD_ORD) {
423                 DP(NETIF_MSG_HW, "read order of %d  order adjusted to %d\n",
424                    r_order, MAX_RD_ORD);
425                 r_order = MAX_RD_ORD;
426         }
427         if (w_order > MAX_WR_ORD) {
428                 DP(NETIF_MSG_HW, "write order of %d  order adjusted to %d\n",
429                    w_order, MAX_WR_ORD);
430                 w_order = MAX_WR_ORD;
431         }
432         if (CHIP_REV_IS_FPGA(bp)) {
433                 DP(NETIF_MSG_HW, "write order adjusted to 1 for FPGA\n");
434                 w_order = 0;
435         }
436         DP(NETIF_MSG_HW, "read order %d  write order %d\n", r_order, w_order);
437
438         for (i = 0; i < NUM_RD_Q-1; i++) {
439                 REG_WR(bp, read_arb_addr[i].l, read_arb_data[i][r_order].l);
440                 REG_WR(bp, read_arb_addr[i].add,
441                        read_arb_data[i][r_order].add);
442                 REG_WR(bp, read_arb_addr[i].ubound,
443                        read_arb_data[i][r_order].ubound);
444         }
445
446         for (i = 0; i < NUM_WR_Q-1; i++) {
447                 if ((write_arb_addr[i].l == PXP2_REG_RQ_BW_WR_L29) ||
448                     (write_arb_addr[i].l == PXP2_REG_RQ_BW_WR_L30)) {
449
450                         REG_WR(bp, write_arb_addr[i].l,
451                                write_arb_data[i][w_order].l);
452
453                         REG_WR(bp, write_arb_addr[i].add,
454                                write_arb_data[i][w_order].add);
455
456                         REG_WR(bp, write_arb_addr[i].ubound,
457                                write_arb_data[i][w_order].ubound);
458                 } else {
459
460                         val = REG_RD(bp, write_arb_addr[i].l);
461                         REG_WR(bp, write_arb_addr[i].l,
462                                val | (write_arb_data[i][w_order].l << 10));
463
464                         val = REG_RD(bp, write_arb_addr[i].add);
465                         REG_WR(bp, write_arb_addr[i].add,
466                                val | (write_arb_data[i][w_order].add << 10));
467
468                         val = REG_RD(bp, write_arb_addr[i].ubound);
469                         REG_WR(bp, write_arb_addr[i].ubound,
470                                val | (write_arb_data[i][w_order].ubound << 7));
471                 }
472         }
473
474         val =  write_arb_data[NUM_WR_Q-1][w_order].add;
475         val += write_arb_data[NUM_WR_Q-1][w_order].ubound << 10;
476         val += write_arb_data[NUM_WR_Q-1][w_order].l << 17;
477         REG_WR(bp, PXP2_REG_PSWRQ_BW_RD, val);
478
479         val =  read_arb_data[NUM_RD_Q-1][r_order].add;
480         val += read_arb_data[NUM_RD_Q-1][r_order].ubound << 10;
481         val += read_arb_data[NUM_RD_Q-1][r_order].l << 17;
482         REG_WR(bp, PXP2_REG_PSWRQ_BW_WR, val);
483
484         REG_WR(bp, PXP2_REG_RQ_WR_MBS0, w_order);
485         REG_WR(bp, PXP2_REG_RQ_WR_MBS1, w_order);
486         REG_WR(bp, PXP2_REG_RQ_RD_MBS0, r_order);
487         REG_WR(bp, PXP2_REG_RQ_RD_MBS1, r_order);
488
489         if ((CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) && (r_order == MAX_RD_ORD))
490                 REG_WR(bp, PXP2_REG_RQ_PDR_LIMIT, 0xe00);
491
492         if (CHIP_IS_E2(bp))
493                 REG_WR(bp, PXP2_REG_WR_USDMDP_TH, (0x8 << w_order));
494         else
495                 REG_WR(bp, PXP2_REG_WR_USDMDP_TH, (0x18 << w_order));
496
497         if (CHIP_IS_E1H(bp) || CHIP_IS_E2(bp)) {
498                 /*    MPS      w_order     optimal TH      presently TH
499                  *    128         0             0               2
500                  *    256         1             1               3
501                  *    >=512       2             2               3
502                  */
503                 /* DMAE is special */
504                 if (CHIP_IS_E2(bp)) {
505                         /* E2 can use optimal TH */
506                         val = w_order;
507                         REG_WR(bp, PXP2_REG_WR_DMAE_MPS, val);
508                 } else {
509                         val = ((w_order == 0) ? 2 : 3);
510                         REG_WR(bp, PXP2_REG_WR_DMAE_MPS, 2);
511                 }
512
513                 REG_WR(bp, PXP2_REG_WR_HC_MPS, val);
514                 REG_WR(bp, PXP2_REG_WR_USDM_MPS, val);
515                 REG_WR(bp, PXP2_REG_WR_CSDM_MPS, val);
516                 REG_WR(bp, PXP2_REG_WR_TSDM_MPS, val);
517                 REG_WR(bp, PXP2_REG_WR_XSDM_MPS, val);
518                 REG_WR(bp, PXP2_REG_WR_QM_MPS, val);
519                 REG_WR(bp, PXP2_REG_WR_TM_MPS, val);
520                 REG_WR(bp, PXP2_REG_WR_SRC_MPS, val);
521                 REG_WR(bp, PXP2_REG_WR_DBG_MPS, val);
522                 REG_WR(bp, PXP2_REG_WR_CDU_MPS, val);
523         }
524
525         /* Validate number of tags suppoted by device */
526 #define PCIE_REG_PCIER_TL_HDR_FC_ST             0x2980
527         val = REG_RD(bp, PCIE_REG_PCIER_TL_HDR_FC_ST);
528         val &= 0xFF;
529         if (val <= 0x20)
530                 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x20);
531 }
532
533 /****************************************************************************
534 * ILT management
535 ****************************************************************************/
536 /*
537  * This codes hides the low level HW interaction for ILT management and
538  * configuration. The API consists of a shadow ILT table which is set by the
539  * driver and a set of routines to use it to configure the HW.
540  *
541  */
542
543 /* ILT HW init operations */
544
545 /* ILT memory management operations */
546 #define ILT_MEMOP_ALLOC         0
547 #define ILT_MEMOP_FREE          1
548
549 /* the phys address is shifted right 12 bits and has an added
550  * 1=valid bit added to the 53rd bit
551  * then since this is a wide register(TM)
552  * we split it into two 32 bit writes
553  */
554 #define ILT_ADDR1(x)            ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
555 #define ILT_ADDR2(x)            ((u32)((1 << 20) | ((u64)x >> 44)))
556 #define ILT_RANGE(f, l)         (((l) << 10) | f)
557
558 static int bnx2x_ilt_line_mem_op(struct bnx2x *bp, struct ilt_line *line,
559                                  u32 size, u8 memop)
560 {
561         if (memop == ILT_MEMOP_FREE) {
562                 BNX2X_ILT_FREE(line->page, line->page_mapping, line->size);
563                 return 0;
564         }
565         BNX2X_ILT_ZALLOC(line->page, &line->page_mapping, size);
566         if (!line->page)
567                 return -1;
568         line->size = size;
569         return 0;
570 }
571
572
573 static int bnx2x_ilt_client_mem_op(struct bnx2x *bp, int cli_num, u8 memop)
574 {
575         int i, rc;
576         struct bnx2x_ilt *ilt = BP_ILT(bp);
577         struct ilt_client_info *ilt_cli = &ilt->clients[cli_num];
578
579         if (!ilt || !ilt->lines)
580                 return -1;
581
582         if (ilt_cli->flags & (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM))
583                 return 0;
584
585         for (rc = 0, i = ilt_cli->start; i <= ilt_cli->end && !rc; i++) {
586                 rc = bnx2x_ilt_line_mem_op(bp, &ilt->lines[i],
587                                            ilt_cli->page_size, memop);
588         }
589         return rc;
590 }
591
592 int bnx2x_ilt_mem_op(struct bnx2x *bp, u8 memop)
593 {
594         int rc = bnx2x_ilt_client_mem_op(bp, ILT_CLIENT_CDU, memop);
595         if (!rc)
596                 rc = bnx2x_ilt_client_mem_op(bp, ILT_CLIENT_QM, memop);
597         if (!rc)
598                 rc = bnx2x_ilt_client_mem_op(bp, ILT_CLIENT_SRC, memop);
599         if (!rc)
600                 rc = bnx2x_ilt_client_mem_op(bp, ILT_CLIENT_TM, memop);
601
602         return rc;
603 }
604
605 static void bnx2x_ilt_line_wr(struct bnx2x *bp, int abs_idx,
606                               dma_addr_t page_mapping)
607 {
608         u32 reg;
609
610         if (CHIP_IS_E1(bp))
611                 reg = PXP2_REG_RQ_ONCHIP_AT + abs_idx*8;
612         else
613                 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + abs_idx*8;
614
615         bnx2x_wr_64(bp, reg, ILT_ADDR1(page_mapping), ILT_ADDR2(page_mapping));
616 }
617
618 static void bnx2x_ilt_line_init_op(struct bnx2x *bp, struct bnx2x_ilt *ilt,
619                                    int idx, u8 initop)
620 {
621         dma_addr_t      null_mapping;
622         int abs_idx = ilt->start_line + idx;
623
624
625         switch (initop) {
626         case INITOP_INIT:
627                 /* set in the init-value array */
628         case INITOP_SET:
629                 bnx2x_ilt_line_wr(bp, abs_idx, ilt->lines[idx].page_mapping);
630                 break;
631         case INITOP_CLEAR:
632                 null_mapping = 0;
633                 bnx2x_ilt_line_wr(bp, abs_idx, null_mapping);
634                 break;
635         }
636 }
637
638 void bnx2x_ilt_boundry_init_op(struct bnx2x *bp,
639                                       struct ilt_client_info *ilt_cli,
640                                       u32 ilt_start, u8 initop)
641 {
642         u32 start_reg = 0;
643         u32 end_reg = 0;
644
645         /* The boundary is either SET or INIT,
646            CLEAR => SET and for now SET ~~ INIT */
647
648         /* find the appropriate regs */
649         if (CHIP_IS_E1(bp)) {
650                 switch (ilt_cli->client_num) {
651                 case ILT_CLIENT_CDU:
652                         start_reg = PXP2_REG_PSWRQ_CDU0_L2P;
653                         break;
654                 case ILT_CLIENT_QM:
655                         start_reg = PXP2_REG_PSWRQ_QM0_L2P;
656                         break;
657                 case ILT_CLIENT_SRC:
658                         start_reg = PXP2_REG_PSWRQ_SRC0_L2P;
659                         break;
660                 case ILT_CLIENT_TM:
661                         start_reg = PXP2_REG_PSWRQ_TM0_L2P;
662                         break;
663                 }
664                 REG_WR(bp, start_reg + BP_FUNC(bp)*4,
665                        ILT_RANGE((ilt_start + ilt_cli->start),
666                                  (ilt_start + ilt_cli->end)));
667         } else {
668                 switch (ilt_cli->client_num) {
669                 case ILT_CLIENT_CDU:
670                         start_reg = PXP2_REG_RQ_CDU_FIRST_ILT;
671                         end_reg = PXP2_REG_RQ_CDU_LAST_ILT;
672                         break;
673                 case ILT_CLIENT_QM:
674                         start_reg = PXP2_REG_RQ_QM_FIRST_ILT;
675                         end_reg = PXP2_REG_RQ_QM_LAST_ILT;
676                         break;
677                 case ILT_CLIENT_SRC:
678                         start_reg = PXP2_REG_RQ_SRC_FIRST_ILT;
679                         end_reg = PXP2_REG_RQ_SRC_LAST_ILT;
680                         break;
681                 case ILT_CLIENT_TM:
682                         start_reg = PXP2_REG_RQ_TM_FIRST_ILT;
683                         end_reg = PXP2_REG_RQ_TM_LAST_ILT;
684                         break;
685                 }
686                 REG_WR(bp, start_reg, (ilt_start + ilt_cli->start));
687                 REG_WR(bp, end_reg, (ilt_start + ilt_cli->end));
688         }
689 }
690
691 void bnx2x_ilt_client_init_op_ilt(struct bnx2x *bp, struct bnx2x_ilt *ilt,
692                                   struct ilt_client_info *ilt_cli, u8 initop)
693 {
694         int i;
695
696         if (ilt_cli->flags & ILT_CLIENT_SKIP_INIT)
697                 return;
698
699         for (i = ilt_cli->start; i <= ilt_cli->end; i++)
700                 bnx2x_ilt_line_init_op(bp, ilt, i, initop);
701
702         /* init/clear the ILT boundries */
703         bnx2x_ilt_boundry_init_op(bp, ilt_cli, ilt->start_line, initop);
704 }
705
706 void bnx2x_ilt_client_init_op(struct bnx2x *bp,
707                               struct ilt_client_info *ilt_cli, u8 initop)
708 {
709         struct bnx2x_ilt *ilt = BP_ILT(bp);
710
711         bnx2x_ilt_client_init_op_ilt(bp, ilt, ilt_cli, initop);
712 }
713
714 static void bnx2x_ilt_client_id_init_op(struct bnx2x *bp,
715                                         int cli_num, u8 initop)
716 {
717         struct bnx2x_ilt *ilt = BP_ILT(bp);
718         struct ilt_client_info *ilt_cli = &ilt->clients[cli_num];
719
720         bnx2x_ilt_client_init_op(bp, ilt_cli, initop);
721 }
722
723 void bnx2x_ilt_init_op(struct bnx2x *bp, u8 initop)
724 {
725         bnx2x_ilt_client_id_init_op(bp, ILT_CLIENT_CDU, initop);
726         bnx2x_ilt_client_id_init_op(bp, ILT_CLIENT_QM, initop);
727         bnx2x_ilt_client_id_init_op(bp, ILT_CLIENT_SRC, initop);
728         bnx2x_ilt_client_id_init_op(bp, ILT_CLIENT_TM, initop);
729 }
730
731 static void bnx2x_ilt_init_client_psz(struct bnx2x *bp, int cli_num,
732                                             u32 psz_reg, u8 initop)
733 {
734         struct bnx2x_ilt *ilt = BP_ILT(bp);
735         struct ilt_client_info *ilt_cli = &ilt->clients[cli_num];
736
737         if (ilt_cli->flags & ILT_CLIENT_SKIP_INIT)
738                 return;
739
740         switch (initop) {
741         case INITOP_INIT:
742                 /* set in the init-value array */
743         case INITOP_SET:
744                 REG_WR(bp, psz_reg, ILOG2(ilt_cli->page_size >> 12));
745                 break;
746         case INITOP_CLEAR:
747                 break;
748         }
749 }
750
751 /*
752  * called during init common stage, ilt clients should be initialized
753  * prioir to calling this function
754  */
755 void bnx2x_ilt_init_page_size(struct bnx2x *bp, u8 initop)
756 {
757         bnx2x_ilt_init_client_psz(bp, ILT_CLIENT_CDU,
758                                   PXP2_REG_RQ_CDU_P_SIZE, initop);
759         bnx2x_ilt_init_client_psz(bp, ILT_CLIENT_QM,
760                                   PXP2_REG_RQ_QM_P_SIZE, initop);
761         bnx2x_ilt_init_client_psz(bp, ILT_CLIENT_SRC,
762                                   PXP2_REG_RQ_SRC_P_SIZE, initop);
763         bnx2x_ilt_init_client_psz(bp, ILT_CLIENT_TM,
764                                   PXP2_REG_RQ_TM_P_SIZE, initop);
765 }
766
767 /****************************************************************************
768 * QM initializations
769 ****************************************************************************/
770 #define QM_QUEUES_PER_FUNC      16 /* E1 has 32, but only 16 are used */
771 #define QM_INIT_MIN_CID_COUNT   31
772 #define QM_INIT(cid_cnt)        (cid_cnt > QM_INIT_MIN_CID_COUNT)
773
774 /* called during init port stage */
775 void bnx2x_qm_init_cid_count(struct bnx2x *bp, int qm_cid_count,
776                              u8 initop)
777 {
778         int port = BP_PORT(bp);
779
780         if (QM_INIT(qm_cid_count)) {
781                 switch (initop) {
782                 case INITOP_INIT:
783                         /* set in the init-value array */
784                 case INITOP_SET:
785                         REG_WR(bp, QM_REG_CONNNUM_0 + port*4,
786                                qm_cid_count/16 - 1);
787                         break;
788                 case INITOP_CLEAR:
789                         break;
790                 }
791         }
792 }
793
794 static void bnx2x_qm_set_ptr_table(struct bnx2x *bp, int qm_cid_count)
795 {
796         int i;
797         u32 wb_data[2];
798
799         wb_data[0] = wb_data[1] = 0;
800
801         for (i = 0; i < 4 * QM_QUEUES_PER_FUNC; i++) {
802                 REG_WR(bp, QM_REG_BASEADDR + i*4,
803                        qm_cid_count * 4 * (i % QM_QUEUES_PER_FUNC));
804                 bnx2x_init_ind_wr(bp, QM_REG_PTRTBL + i*8,
805                                   wb_data, 2);
806
807                 if (CHIP_IS_E1H(bp)) {
808                         REG_WR(bp, QM_REG_BASEADDR_EXT_A + i*4,
809                                qm_cid_count * 4 * (i % QM_QUEUES_PER_FUNC));
810                         bnx2x_init_ind_wr(bp, QM_REG_PTRTBL_EXT_A + i*8,
811                                           wb_data, 2);
812                 }
813         }
814 }
815
816 /* called during init common stage */
817 void bnx2x_qm_init_ptr_table(struct bnx2x *bp, int qm_cid_count,
818                              u8 initop)
819 {
820         if (!QM_INIT(qm_cid_count))
821                 return;
822
823         switch (initop) {
824         case INITOP_INIT:
825                 /* set in the init-value array */
826         case INITOP_SET:
827                 bnx2x_qm_set_ptr_table(bp, qm_cid_count);
828                 break;
829         case INITOP_CLEAR:
830                 break;
831         }
832 }
833
834 /****************************************************************************
835 * SRC initializations
836 ****************************************************************************/
837
838 /* called during init func stage */
839 void bnx2x_src_init_t2(struct bnx2x *bp, struct src_ent *t2,
840                        dma_addr_t t2_mapping, int src_cid_count)
841 {
842         int i;
843         int port = BP_PORT(bp);
844
845         /* Initialize T2 */
846         for (i = 0; i < src_cid_count-1; i++)
847                 t2[i].next = (u64)(t2_mapping + (i+1)*sizeof(struct src_ent));
848
849         /* tell the searcher where the T2 table is */
850         REG_WR(bp, SRC_REG_COUNTFREE0 + port*4, src_cid_count);
851
852         bnx2x_wr_64(bp, SRC_REG_FIRSTFREE0 + port*16,
853                     U64_LO(t2_mapping), U64_HI(t2_mapping));
854
855         bnx2x_wr_64(bp, SRC_REG_LASTFREE0 + port*16,
856                     U64_LO((u64)t2_mapping +
857                            (src_cid_count-1) * sizeof(struct src_ent)),
858                     U64_HI((u64)t2_mapping +
859                            (src_cid_count-1) * sizeof(struct src_ent)));
860 }
861
862 #endif /* BNX2X_INIT_OPS_H */