bnx2x_init.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /* bnx2x_init.h: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2008 Broadcom Corporation
  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. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. */
  12. #ifndef BNX2X_INIT_H
  13. #define BNX2X_INIT_H
  14. #define COMMON 0x1
  15. #define PORT0 0x2
  16. #define PORT1 0x4
  17. #define INIT_EMULATION 0x1
  18. #define INIT_FPGA 0x2
  19. #define INIT_ASIC 0x4
  20. #define INIT_HARDWARE 0x7
  21. #define STORM_INTMEM_SIZE_E1 (0x5800 / 4)
  22. #define STORM_INTMEM_SIZE_E1H (0x10000 / 4)
  23. #define TSTORM_INTMEM_ADDR 0x1a0000
  24. #define CSTORM_INTMEM_ADDR 0x220000
  25. #define XSTORM_INTMEM_ADDR 0x2a0000
  26. #define USTORM_INTMEM_ADDR 0x320000
  27. /* Init operation types and structures */
  28. /* Common for both E1 and E1H */
  29. #define OP_RD 0x1 /* read single register */
  30. #define OP_WR 0x2 /* write single register */
  31. #define OP_IW 0x3 /* write single register using mailbox */
  32. #define OP_SW 0x4 /* copy a string to the device */
  33. #define OP_SI 0x5 /* copy a string using mailbox */
  34. #define OP_ZR 0x6 /* clear memory */
  35. #define OP_ZP 0x7 /* unzip then copy with DMAE */
  36. #define OP_WR_64 0x8 /* write 64 bit pattern */
  37. #define OP_WB 0x9 /* copy a string using DMAE */
  38. /* Operation specific for E1 */
  39. #define OP_RD_E1 0xa /* read single register */
  40. #define OP_WR_E1 0xb /* write single register */
  41. #define OP_IW_E1 0xc /* write single register using mailbox */
  42. #define OP_SW_E1 0xd /* copy a string to the device */
  43. #define OP_SI_E1 0xe /* copy a string using mailbox */
  44. #define OP_ZR_E1 0xf /* clear memory */
  45. #define OP_ZP_E1 0x10 /* unzip then copy with DMAE */
  46. #define OP_WR_64_E1 0x11 /* write 64 bit pattern on E1 */
  47. #define OP_WB_E1 0x12 /* copy a string using DMAE */
  48. /* Operation specific for E1H */
  49. #define OP_RD_E1H 0x13 /* read single register */
  50. #define OP_WR_E1H 0x14 /* write single register */
  51. #define OP_IW_E1H 0x15 /* write single register using mailbox */
  52. #define OP_SW_E1H 0x16 /* copy a string to the device */
  53. #define OP_SI_E1H 0x17 /* copy a string using mailbox */
  54. #define OP_ZR_E1H 0x18 /* clear memory */
  55. #define OP_ZP_E1H 0x19 /* unzip then copy with DMAE */
  56. #define OP_WR_64_E1H 0x1a /* write 64 bit pattern on E1H */
  57. #define OP_WB_E1H 0x1b /* copy a string using DMAE */
  58. /* FPGA and EMUL specific operations */
  59. #define OP_WR_EMUL_E1H 0x1c /* write single register on E1H Emul */
  60. #define OP_WR_EMUL 0x1d /* write single register on Emulation */
  61. #define OP_WR_FPGA 0x1e /* write single register on FPGA */
  62. #define OP_WR_ASIC 0x1f /* write single register on ASIC */
  63. struct raw_op {
  64. u32 op:8;
  65. u32 offset:24;
  66. u32 raw_data;
  67. };
  68. struct op_read {
  69. u32 op:8;
  70. u32 offset:24;
  71. u32 pad;
  72. };
  73. struct op_write {
  74. u32 op:8;
  75. u32 offset:24;
  76. u32 val;
  77. };
  78. struct op_string_write {
  79. u32 op:8;
  80. u32 offset:24;
  81. #ifdef __LITTLE_ENDIAN
  82. u16 data_off;
  83. u16 data_len;
  84. #else /* __BIG_ENDIAN */
  85. u16 data_len;
  86. u16 data_off;
  87. #endif
  88. };
  89. struct op_zero {
  90. u32 op:8;
  91. u32 offset:24;
  92. u32 len;
  93. };
  94. union init_op {
  95. struct op_read read;
  96. struct op_write write;
  97. struct op_string_write str_wr;
  98. struct op_zero zero;
  99. struct raw_op raw;
  100. };
  101. #include "bnx2x_init_values.h"
  102. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val);
  103. static int bnx2x_gunzip(struct bnx2x *bp, u8 *zbuf, int len);
  104. static void bnx2x_init_str_wr(struct bnx2x *bp, u32 addr, const u32 *data,
  105. u32 len)
  106. {
  107. int i;
  108. for (i = 0; i < len; i++) {
  109. REG_WR(bp, addr + i*4, data[i]);
  110. if (!(i % 10000)) {
  111. touch_softlockup_watchdog();
  112. cpu_relax();
  113. }
  114. }
  115. }
  116. static void bnx2x_init_ind_wr(struct bnx2x *bp, u32 addr, const u32 *data,
  117. u16 len)
  118. {
  119. int i;
  120. for (i = 0; i < len; i++) {
  121. REG_WR_IND(bp, addr + i*4, data[i]);
  122. if (!(i % 10000)) {
  123. touch_softlockup_watchdog();
  124. cpu_relax();
  125. }
  126. }
  127. }
  128. static void bnx2x_write_big_buf(struct bnx2x *bp, u32 addr, u32 len)
  129. {
  130. #ifdef USE_DMAE
  131. int offset = 0;
  132. if (bp->dmae_ready) {
  133. while (len > DMAE_LEN32_WR_MAX) {
  134. bnx2x_write_dmae(bp, bp->gunzip_mapping + offset,
  135. addr + offset, DMAE_LEN32_WR_MAX);
  136. offset += DMAE_LEN32_WR_MAX * 4;
  137. len -= DMAE_LEN32_WR_MAX;
  138. }
  139. bnx2x_write_dmae(bp, bp->gunzip_mapping + offset,
  140. addr + offset, len);
  141. } else
  142. bnx2x_init_str_wr(bp, addr, bp->gunzip_buf, len);
  143. #else
  144. bnx2x_init_str_wr(bp, addr, bp->gunzip_buf, len);
  145. #endif
  146. }
  147. static void bnx2x_init_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  148. {
  149. if ((len * 4) > FW_BUF_SIZE) {
  150. BNX2X_ERR("LARGE DMAE OPERATION ! addr 0x%x len 0x%x\n",
  151. addr, len*4);
  152. return;
  153. }
  154. memset(bp->gunzip_buf, fill, len * 4);
  155. bnx2x_write_big_buf(bp, addr, len);
  156. }
  157. static void bnx2x_init_wr_64(struct bnx2x *bp, u32 addr, const u32 *data,
  158. u32 len64)
  159. {
  160. u32 buf_len32 = FW_BUF_SIZE/4;
  161. u32 len = len64*2;
  162. u64 data64 = 0;
  163. int i;
  164. /* 64 bit value is in a blob: first low DWORD, then high DWORD */
  165. data64 = HILO_U64((*(data + 1)), (*data));
  166. len64 = min((u32)(FW_BUF_SIZE/8), len64);
  167. for (i = 0; i < len64; i++) {
  168. u64 *pdata = ((u64 *)(bp->gunzip_buf)) + i;
  169. *pdata = data64;
  170. }
  171. for (i = 0; i < len; i += buf_len32) {
  172. u32 cur_len = min(buf_len32, len - i);
  173. bnx2x_write_big_buf(bp, addr + i * 4, cur_len);
  174. }
  175. }
  176. /*********************************************************
  177. There are different blobs for each PRAM section.
  178. In addition, each blob write operation is divided into a few operations
  179. in order to decrease the amount of phys. contiguous buffer needed.
  180. Thus, when we select a blob the address may be with some offset
  181. from the beginning of PRAM section.
  182. The same holds for the INT_TABLE sections.
  183. **********************************************************/
  184. #define IF_IS_INT_TABLE_ADDR(base, addr) \
  185. if (((base) <= (addr)) && ((base) + 0x400 >= (addr)))
  186. #define IF_IS_PRAM_ADDR(base, addr) \
  187. if (((base) <= (addr)) && ((base) + 0x40000 >= (addr)))
  188. static const u32 *bnx2x_sel_blob(u32 addr, const u32 *data, int is_e1)
  189. {
  190. IF_IS_INT_TABLE_ADDR(TSEM_REG_INT_TABLE, addr)
  191. data = is_e1 ? tsem_int_table_data_e1 :
  192. tsem_int_table_data_e1h;
  193. else
  194. IF_IS_INT_TABLE_ADDR(CSEM_REG_INT_TABLE, addr)
  195. data = is_e1 ? csem_int_table_data_e1 :
  196. csem_int_table_data_e1h;
  197. else
  198. IF_IS_INT_TABLE_ADDR(USEM_REG_INT_TABLE, addr)
  199. data = is_e1 ? usem_int_table_data_e1 :
  200. usem_int_table_data_e1h;
  201. else
  202. IF_IS_INT_TABLE_ADDR(XSEM_REG_INT_TABLE, addr)
  203. data = is_e1 ? xsem_int_table_data_e1 :
  204. xsem_int_table_data_e1h;
  205. else
  206. IF_IS_PRAM_ADDR(TSEM_REG_PRAM, addr)
  207. data = is_e1 ? tsem_pram_data_e1 : tsem_pram_data_e1h;
  208. else
  209. IF_IS_PRAM_ADDR(CSEM_REG_PRAM, addr)
  210. data = is_e1 ? csem_pram_data_e1 : csem_pram_data_e1h;
  211. else
  212. IF_IS_PRAM_ADDR(USEM_REG_PRAM, addr)
  213. data = is_e1 ? usem_pram_data_e1 : usem_pram_data_e1h;
  214. else
  215. IF_IS_PRAM_ADDR(XSEM_REG_PRAM, addr)
  216. data = is_e1 ? xsem_pram_data_e1 : xsem_pram_data_e1h;
  217. return data;
  218. }
  219. static void bnx2x_init_wr_wb(struct bnx2x *bp, u32 addr, const u32 *data,
  220. u32 len, int gunzip, int is_e1, u32 blob_off)
  221. {
  222. int offset = 0;
  223. data = bnx2x_sel_blob(addr, data, is_e1) + blob_off;
  224. if (gunzip) {
  225. int rc;
  226. #ifdef __BIG_ENDIAN
  227. int i, size;
  228. u32 *temp;
  229. temp = kmalloc(len, GFP_KERNEL);
  230. size = (len / 4) + ((len % 4) ? 1 : 0);
  231. for (i = 0; i < size; i++)
  232. temp[i] = swab32(data[i]);
  233. data = temp;
  234. #endif
  235. rc = bnx2x_gunzip(bp, (u8 *)data, len);
  236. if (rc) {
  237. BNX2X_ERR("gunzip failed ! rc %d\n", rc);
  238. return;
  239. }
  240. len = bp->gunzip_outlen;
  241. #ifdef __BIG_ENDIAN
  242. kfree(temp);
  243. for (i = 0; i < len; i++)
  244. ((u32 *)bp->gunzip_buf)[i] =
  245. swab32(((u32 *)bp->gunzip_buf)[i]);
  246. #endif
  247. } else {
  248. if ((len * 4) > FW_BUF_SIZE) {
  249. BNX2X_ERR("LARGE DMAE OPERATION ! "
  250. "addr 0x%x len 0x%x\n", addr, len*4);
  251. return;
  252. }
  253. memcpy(bp->gunzip_buf, data, len * 4);
  254. }
  255. if (bp->dmae_ready) {
  256. while (len > DMAE_LEN32_WR_MAX) {
  257. bnx2x_write_dmae(bp, bp->gunzip_mapping + offset,
  258. addr + offset, DMAE_LEN32_WR_MAX);
  259. offset += DMAE_LEN32_WR_MAX * 4;
  260. len -= DMAE_LEN32_WR_MAX;
  261. }
  262. bnx2x_write_dmae(bp, bp->gunzip_mapping + offset,
  263. addr + offset, len);
  264. } else
  265. bnx2x_init_ind_wr(bp, addr, bp->gunzip_buf, len);
  266. }
  267. static void bnx2x_init_block(struct bnx2x *bp, u32 op_start, u32 op_end)
  268. {
  269. int is_e1 = CHIP_IS_E1(bp);
  270. int is_e1h = CHIP_IS_E1H(bp);
  271. int is_emul_e1h = (CHIP_REV_IS_EMUL(bp) && is_e1h);
  272. int hw_wr, i;
  273. union init_op *op;
  274. u32 op_type, addr, len;
  275. const u32 *data, *data_base;
  276. if (CHIP_REV_IS_FPGA(bp))
  277. hw_wr = OP_WR_FPGA;
  278. else if (CHIP_REV_IS_EMUL(bp))
  279. hw_wr = OP_WR_EMUL;
  280. else
  281. hw_wr = OP_WR_ASIC;
  282. if (is_e1)
  283. data_base = init_data_e1;
  284. else /* CHIP_IS_E1H(bp) */
  285. data_base = init_data_e1h;
  286. for (i = op_start; i < op_end; i++) {
  287. op = (union init_op *)&(init_ops[i]);
  288. op_type = op->str_wr.op;
  289. addr = op->str_wr.offset;
  290. len = op->str_wr.data_len;
  291. data = data_base + op->str_wr.data_off;
  292. /* careful! it must be in order */
  293. if (unlikely(op_type > OP_WB)) {
  294. /* If E1 only */
  295. if (op_type <= OP_WB_E1) {
  296. if (is_e1)
  297. op_type -= (OP_RD_E1 - OP_RD);
  298. /* If E1H only */
  299. } else if (op_type <= OP_WB_E1H) {
  300. if (is_e1h)
  301. op_type -= (OP_RD_E1H - OP_RD);
  302. }
  303. /* HW/EMUL specific */
  304. if (op_type == hw_wr)
  305. op_type = OP_WR;
  306. /* EMUL on E1H is special */
  307. if ((op_type == OP_WR_EMUL_E1H) && is_emul_e1h)
  308. op_type = OP_WR;
  309. }
  310. switch (op_type) {
  311. case OP_RD:
  312. REG_RD(bp, addr);
  313. break;
  314. case OP_WR:
  315. REG_WR(bp, addr, op->write.val);
  316. break;
  317. case OP_SW:
  318. bnx2x_init_str_wr(bp, addr, data, len);
  319. break;
  320. case OP_WB:
  321. bnx2x_init_wr_wb(bp, addr, data, len, 0, is_e1, 0);
  322. break;
  323. case OP_SI:
  324. bnx2x_init_ind_wr(bp, addr, data, len);
  325. break;
  326. case OP_ZR:
  327. bnx2x_init_fill(bp, addr, 0, op->zero.len);
  328. break;
  329. case OP_ZP:
  330. bnx2x_init_wr_wb(bp, addr, data, len, 1, is_e1,
  331. op->str_wr.data_off);
  332. break;
  333. case OP_WR_64:
  334. bnx2x_init_wr_64(bp, addr, data, len);
  335. break;
  336. default:
  337. /* happens whenever an op is of a diff HW */
  338. #if 0
  339. DP(NETIF_MSG_HW, "skipping init operation "
  340. "index %d[%d:%d]: type %d addr 0x%x "
  341. "len %d(0x%x)\n",
  342. i, op_start, op_end, op_type, addr, len, len);
  343. #endif
  344. break;
  345. }
  346. }
  347. }
  348. /****************************************************************************
  349. * PXP
  350. ****************************************************************************/
  351. /*
  352. * This code configures the PCI read/write arbiter
  353. * which implements a weighted round robin
  354. * between the virtual queues in the chip.
  355. *
  356. * The values were derived for each PCI max payload and max request size.
  357. * since max payload and max request size are only known at run time,
  358. * this is done as a separate init stage.
  359. */
  360. #define NUM_WR_Q 13
  361. #define NUM_RD_Q 29
  362. #define MAX_RD_ORD 3
  363. #define MAX_WR_ORD 2
  364. /* configuration for one arbiter queue */
  365. struct arb_line {
  366. int l;
  367. int add;
  368. int ubound;
  369. };
  370. /* derived configuration for each read queue for each max request size */
  371. static const struct arb_line read_arb_data[NUM_RD_Q][MAX_RD_ORD + 1] = {
  372. {{8 , 64 , 25}, {16 , 64 , 25}, {32 , 64 , 25}, {64 , 64 , 41} },
  373. {{4 , 8 , 4}, {4 , 8 , 4}, {4 , 8 , 4}, {4 , 8 , 4} },
  374. {{4 , 3 , 3}, {4 , 3 , 3}, {4 , 3 , 3}, {4 , 3 , 3} },
  375. {{8 , 3 , 6}, {16 , 3 , 11}, {16 , 3 , 11}, {16 , 3 , 11} },
  376. {{8 , 64 , 25}, {16 , 64 , 25}, {32 , 64 , 25}, {64 , 64 , 41} },
  377. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {64 , 3 , 41} },
  378. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {64 , 3 , 41} },
  379. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {64 , 3 , 41} },
  380. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {64 , 3 , 41} },
  381. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  382. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  383. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  384. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  385. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  386. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  387. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  388. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  389. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  390. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  391. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  392. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  393. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  394. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  395. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  396. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  397. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  398. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  399. {{8 , 3 , 6}, {16 , 3 , 11}, {32 , 3 , 21}, {32 , 3 , 21} },
  400. {{8 , 64 , 25}, {16 , 64 , 41}, {32 , 64 , 81}, {64 , 64 , 120} }
  401. };
  402. /* derived configuration for each write queue for each max request size */
  403. static const struct arb_line write_arb_data[NUM_WR_Q][MAX_WR_ORD + 1] = {
  404. {{4 , 6 , 3}, {4 , 6 , 3}, {4 , 6 , 3} },
  405. {{4 , 2 , 3}, {4 , 2 , 3}, {4 , 2 , 3} },
  406. {{8 , 2 , 6}, {16 , 2 , 11}, {16 , 2 , 11} },
  407. {{8 , 2 , 6}, {16 , 2 , 11}, {32 , 2 , 21} },
  408. {{8 , 2 , 6}, {16 , 2 , 11}, {32 , 2 , 21} },
  409. {{8 , 2 , 6}, {16 , 2 , 11}, {32 , 2 , 21} },
  410. {{8 , 64 , 25}, {16 , 64 , 25}, {32 , 64 , 25} },
  411. {{8 , 2 , 6}, {16 , 2 , 11}, {16 , 2 , 11} },
  412. {{8 , 2 , 6}, {16 , 2 , 11}, {16 , 2 , 11} },
  413. {{8 , 9 , 6}, {16 , 9 , 11}, {32 , 9 , 21} },
  414. {{8 , 47 , 19}, {16 , 47 , 19}, {32 , 47 , 21} },
  415. {{8 , 9 , 6}, {16 , 9 , 11}, {16 , 9 , 11} },
  416. {{8 , 64 , 25}, {16 , 64 , 41}, {32 , 64 , 81} }
  417. };
  418. /* register addresses for read queues */
  419. static const struct arb_line read_arb_addr[NUM_RD_Q-1] = {
  420. {PXP2_REG_RQ_BW_RD_L0, PXP2_REG_RQ_BW_RD_ADD0,
  421. PXP2_REG_RQ_BW_RD_UBOUND0},
  422. {PXP2_REG_PSWRQ_BW_L1, PXP2_REG_PSWRQ_BW_ADD1,
  423. PXP2_REG_PSWRQ_BW_UB1},
  424. {PXP2_REG_PSWRQ_BW_L2, PXP2_REG_PSWRQ_BW_ADD2,
  425. PXP2_REG_PSWRQ_BW_UB2},
  426. {PXP2_REG_PSWRQ_BW_L3, PXP2_REG_PSWRQ_BW_ADD3,
  427. PXP2_REG_PSWRQ_BW_UB3},
  428. {PXP2_REG_RQ_BW_RD_L4, PXP2_REG_RQ_BW_RD_ADD4,
  429. PXP2_REG_RQ_BW_RD_UBOUND4},
  430. {PXP2_REG_RQ_BW_RD_L5, PXP2_REG_RQ_BW_RD_ADD5,
  431. PXP2_REG_RQ_BW_RD_UBOUND5},
  432. {PXP2_REG_PSWRQ_BW_L6, PXP2_REG_PSWRQ_BW_ADD6,
  433. PXP2_REG_PSWRQ_BW_UB6},
  434. {PXP2_REG_PSWRQ_BW_L7, PXP2_REG_PSWRQ_BW_ADD7,
  435. PXP2_REG_PSWRQ_BW_UB7},
  436. {PXP2_REG_PSWRQ_BW_L8, PXP2_REG_PSWRQ_BW_ADD8,
  437. PXP2_REG_PSWRQ_BW_UB8},
  438. {PXP2_REG_PSWRQ_BW_L9, PXP2_REG_PSWRQ_BW_ADD9,
  439. PXP2_REG_PSWRQ_BW_UB9},
  440. {PXP2_REG_PSWRQ_BW_L10, PXP2_REG_PSWRQ_BW_ADD10,
  441. PXP2_REG_PSWRQ_BW_UB10},
  442. {PXP2_REG_PSWRQ_BW_L11, PXP2_REG_PSWRQ_BW_ADD11,
  443. PXP2_REG_PSWRQ_BW_UB11},
  444. {PXP2_REG_RQ_BW_RD_L12, PXP2_REG_RQ_BW_RD_ADD12,
  445. PXP2_REG_RQ_BW_RD_UBOUND12},
  446. {PXP2_REG_RQ_BW_RD_L13, PXP2_REG_RQ_BW_RD_ADD13,
  447. PXP2_REG_RQ_BW_RD_UBOUND13},
  448. {PXP2_REG_RQ_BW_RD_L14, PXP2_REG_RQ_BW_RD_ADD14,
  449. PXP2_REG_RQ_BW_RD_UBOUND14},
  450. {PXP2_REG_RQ_BW_RD_L15, PXP2_REG_RQ_BW_RD_ADD15,
  451. PXP2_REG_RQ_BW_RD_UBOUND15},
  452. {PXP2_REG_RQ_BW_RD_L16, PXP2_REG_RQ_BW_RD_ADD16,
  453. PXP2_REG_RQ_BW_RD_UBOUND16},
  454. {PXP2_REG_RQ_BW_RD_L17, PXP2_REG_RQ_BW_RD_ADD17,
  455. PXP2_REG_RQ_BW_RD_UBOUND17},
  456. {PXP2_REG_RQ_BW_RD_L18, PXP2_REG_RQ_BW_RD_ADD18,
  457. PXP2_REG_RQ_BW_RD_UBOUND18},
  458. {PXP2_REG_RQ_BW_RD_L19, PXP2_REG_RQ_BW_RD_ADD19,
  459. PXP2_REG_RQ_BW_RD_UBOUND19},
  460. {PXP2_REG_RQ_BW_RD_L20, PXP2_REG_RQ_BW_RD_ADD20,
  461. PXP2_REG_RQ_BW_RD_UBOUND20},
  462. {PXP2_REG_RQ_BW_RD_L22, PXP2_REG_RQ_BW_RD_ADD22,
  463. PXP2_REG_RQ_BW_RD_UBOUND22},
  464. {PXP2_REG_RQ_BW_RD_L23, PXP2_REG_RQ_BW_RD_ADD23,
  465. PXP2_REG_RQ_BW_RD_UBOUND23},
  466. {PXP2_REG_RQ_BW_RD_L24, PXP2_REG_RQ_BW_RD_ADD24,
  467. PXP2_REG_RQ_BW_RD_UBOUND24},
  468. {PXP2_REG_RQ_BW_RD_L25, PXP2_REG_RQ_BW_RD_ADD25,
  469. PXP2_REG_RQ_BW_RD_UBOUND25},
  470. {PXP2_REG_RQ_BW_RD_L26, PXP2_REG_RQ_BW_RD_ADD26,
  471. PXP2_REG_RQ_BW_RD_UBOUND26},
  472. {PXP2_REG_RQ_BW_RD_L27, PXP2_REG_RQ_BW_RD_ADD27,
  473. PXP2_REG_RQ_BW_RD_UBOUND27},
  474. {PXP2_REG_PSWRQ_BW_L28, PXP2_REG_PSWRQ_BW_ADD28,
  475. PXP2_REG_PSWRQ_BW_UB28}
  476. };
  477. /* register addresses for write queues */
  478. static const struct arb_line write_arb_addr[NUM_WR_Q-1] = {
  479. {PXP2_REG_PSWRQ_BW_L1, PXP2_REG_PSWRQ_BW_ADD1,
  480. PXP2_REG_PSWRQ_BW_UB1},
  481. {PXP2_REG_PSWRQ_BW_L2, PXP2_REG_PSWRQ_BW_ADD2,
  482. PXP2_REG_PSWRQ_BW_UB2},
  483. {PXP2_REG_PSWRQ_BW_L3, PXP2_REG_PSWRQ_BW_ADD3,
  484. PXP2_REG_PSWRQ_BW_UB3},
  485. {PXP2_REG_PSWRQ_BW_L6, PXP2_REG_PSWRQ_BW_ADD6,
  486. PXP2_REG_PSWRQ_BW_UB6},
  487. {PXP2_REG_PSWRQ_BW_L7, PXP2_REG_PSWRQ_BW_ADD7,
  488. PXP2_REG_PSWRQ_BW_UB7},
  489. {PXP2_REG_PSWRQ_BW_L8, PXP2_REG_PSWRQ_BW_ADD8,
  490. PXP2_REG_PSWRQ_BW_UB8},
  491. {PXP2_REG_PSWRQ_BW_L9, PXP2_REG_PSWRQ_BW_ADD9,
  492. PXP2_REG_PSWRQ_BW_UB9},
  493. {PXP2_REG_PSWRQ_BW_L10, PXP2_REG_PSWRQ_BW_ADD10,
  494. PXP2_REG_PSWRQ_BW_UB10},
  495. {PXP2_REG_PSWRQ_BW_L11, PXP2_REG_PSWRQ_BW_ADD11,
  496. PXP2_REG_PSWRQ_BW_UB11},
  497. {PXP2_REG_PSWRQ_BW_L28, PXP2_REG_PSWRQ_BW_ADD28,
  498. PXP2_REG_PSWRQ_BW_UB28},
  499. {PXP2_REG_RQ_BW_WR_L29, PXP2_REG_RQ_BW_WR_ADD29,
  500. PXP2_REG_RQ_BW_WR_UBOUND29},
  501. {PXP2_REG_RQ_BW_WR_L30, PXP2_REG_RQ_BW_WR_ADD30,
  502. PXP2_REG_RQ_BW_WR_UBOUND30}
  503. };
  504. static void bnx2x_init_pxp(struct bnx2x *bp)
  505. {
  506. u16 devctl;
  507. int r_order, w_order;
  508. u32 val, i;
  509. pci_read_config_word(bp->pdev,
  510. bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
  511. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  512. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  513. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  514. if (r_order > MAX_RD_ORD) {
  515. DP(NETIF_MSG_HW, "read order of %d order adjusted to %d\n",
  516. r_order, MAX_RD_ORD);
  517. r_order = MAX_RD_ORD;
  518. }
  519. if (w_order > MAX_WR_ORD) {
  520. DP(NETIF_MSG_HW, "write order of %d order adjusted to %d\n",
  521. w_order, MAX_WR_ORD);
  522. w_order = MAX_WR_ORD;
  523. }
  524. if (CHIP_REV_IS_FPGA(bp)) {
  525. DP(NETIF_MSG_HW, "write order adjusted to 1 for FPGA\n");
  526. w_order = 0;
  527. }
  528. DP(NETIF_MSG_HW, "read order %d write order %d\n", r_order, w_order);
  529. for (i = 0; i < NUM_RD_Q-1; i++) {
  530. REG_WR(bp, read_arb_addr[i].l, read_arb_data[i][r_order].l);
  531. REG_WR(bp, read_arb_addr[i].add,
  532. read_arb_data[i][r_order].add);
  533. REG_WR(bp, read_arb_addr[i].ubound,
  534. read_arb_data[i][r_order].ubound);
  535. }
  536. for (i = 0; i < NUM_WR_Q-1; i++) {
  537. if ((write_arb_addr[i].l == PXP2_REG_RQ_BW_WR_L29) ||
  538. (write_arb_addr[i].l == PXP2_REG_RQ_BW_WR_L30)) {
  539. REG_WR(bp, write_arb_addr[i].l,
  540. write_arb_data[i][w_order].l);
  541. REG_WR(bp, write_arb_addr[i].add,
  542. write_arb_data[i][w_order].add);
  543. REG_WR(bp, write_arb_addr[i].ubound,
  544. write_arb_data[i][w_order].ubound);
  545. } else {
  546. val = REG_RD(bp, write_arb_addr[i].l);
  547. REG_WR(bp, write_arb_addr[i].l,
  548. val | (write_arb_data[i][w_order].l << 10));
  549. val = REG_RD(bp, write_arb_addr[i].add);
  550. REG_WR(bp, write_arb_addr[i].add,
  551. val | (write_arb_data[i][w_order].add << 10));
  552. val = REG_RD(bp, write_arb_addr[i].ubound);
  553. REG_WR(bp, write_arb_addr[i].ubound,
  554. val | (write_arb_data[i][w_order].ubound << 7));
  555. }
  556. }
  557. val = write_arb_data[NUM_WR_Q-1][w_order].add;
  558. val += write_arb_data[NUM_WR_Q-1][w_order].ubound << 10;
  559. val += write_arb_data[NUM_WR_Q-1][w_order].l << 17;
  560. REG_WR(bp, PXP2_REG_PSWRQ_BW_RD, val);
  561. val = read_arb_data[NUM_RD_Q-1][r_order].add;
  562. val += read_arb_data[NUM_RD_Q-1][r_order].ubound << 10;
  563. val += read_arb_data[NUM_RD_Q-1][r_order].l << 17;
  564. REG_WR(bp, PXP2_REG_PSWRQ_BW_WR, val);
  565. REG_WR(bp, PXP2_REG_RQ_WR_MBS0, w_order);
  566. REG_WR(bp, PXP2_REG_RQ_WR_MBS1, w_order);
  567. REG_WR(bp, PXP2_REG_RQ_RD_MBS0, r_order);
  568. REG_WR(bp, PXP2_REG_RQ_RD_MBS1, r_order);
  569. if (r_order == MAX_RD_ORD)
  570. REG_WR(bp, PXP2_REG_RQ_PDR_LIMIT, 0xe00);
  571. REG_WR(bp, PXP2_REG_WR_USDMDP_TH, (0x18 << w_order));
  572. if (CHIP_IS_E1H(bp)) {
  573. REG_WR(bp, PXP2_REG_WR_HC_MPS, w_order+1);
  574. REG_WR(bp, PXP2_REG_WR_USDM_MPS, w_order+1);
  575. REG_WR(bp, PXP2_REG_WR_CSDM_MPS, w_order+1);
  576. REG_WR(bp, PXP2_REG_WR_TSDM_MPS, w_order+1);
  577. REG_WR(bp, PXP2_REG_WR_XSDM_MPS, w_order+1);
  578. REG_WR(bp, PXP2_REG_WR_QM_MPS, w_order+1);
  579. REG_WR(bp, PXP2_REG_WR_TM_MPS, w_order+1);
  580. REG_WR(bp, PXP2_REG_WR_SRC_MPS, w_order+1);
  581. REG_WR(bp, PXP2_REG_WR_DBG_MPS, w_order+1);
  582. REG_WR(bp, PXP2_REG_WR_DMAE_MPS, 2); /* DMAE is special */
  583. REG_WR(bp, PXP2_REG_WR_CDU_MPS, w_order+1);
  584. }
  585. }
  586. /****************************************************************************
  587. * CDU
  588. ****************************************************************************/
  589. #define CDU_REGION_NUMBER_XCM_AG 2
  590. #define CDU_REGION_NUMBER_UCM_AG 4
  591. /**
  592. * String-to-compress [31:8] = CID (all 24 bits)
  593. * String-to-compress [7:4] = Region
  594. * String-to-compress [3:0] = Type
  595. */
  596. #define CDU_VALID_DATA(_cid, _region, _type) \
  597. (((_cid) << 8) | (((_region) & 0xf) << 4) | (((_type) & 0xf)))
  598. #define CDU_CRC8(_cid, _region, _type) \
  599. calc_crc8(CDU_VALID_DATA(_cid, _region, _type), 0xff)
  600. #define CDU_RSRVD_VALUE_TYPE_A(_cid, _region, _type) \
  601. (0x80 | (CDU_CRC8(_cid, _region, _type) & 0x7f))
  602. #define CDU_RSRVD_VALUE_TYPE_B(_crc, _type) \
  603. (0x80 | ((_type) & 0xf << 3) | (CDU_CRC8(_cid, _region, _type) & 0x7))
  604. #define CDU_RSRVD_INVALIDATE_CONTEXT_VALUE(_val) ((_val) & ~0x80)
  605. /*****************************************************************************
  606. * Description:
  607. * Calculates crc 8 on a word value: polynomial 0-1-2-8
  608. * Code was translated from Verilog.
  609. ****************************************************************************/
  610. static u8 calc_crc8(u32 data, u8 crc)
  611. {
  612. u8 D[32];
  613. u8 NewCRC[8];
  614. u8 C[8];
  615. u8 crc_res;
  616. u8 i;
  617. /* split the data into 31 bits */
  618. for (i = 0; i < 32; i++) {
  619. D[i] = data & 1;
  620. data = data >> 1;
  621. }
  622. /* split the crc into 8 bits */
  623. for (i = 0; i < 8; i++) {
  624. C[i] = crc & 1;
  625. crc = crc >> 1;
  626. }
  627. NewCRC[0] = D[31] ^ D[30] ^ D[28] ^ D[23] ^ D[21] ^ D[19] ^ D[18] ^
  628. D[16] ^ D[14] ^ D[12] ^ D[8] ^ D[7] ^ D[6] ^ D[0] ^ C[4] ^
  629. C[6] ^ C[7];
  630. NewCRC[1] = D[30] ^ D[29] ^ D[28] ^ D[24] ^ D[23] ^ D[22] ^ D[21] ^
  631. D[20] ^ D[18] ^ D[17] ^ D[16] ^ D[15] ^ D[14] ^ D[13] ^
  632. D[12] ^ D[9] ^ D[6] ^ D[1] ^ D[0] ^ C[0] ^ C[4] ^ C[5] ^ C[6];
  633. NewCRC[2] = D[29] ^ D[28] ^ D[25] ^ D[24] ^ D[22] ^ D[17] ^ D[15] ^
  634. D[13] ^ D[12] ^ D[10] ^ D[8] ^ D[6] ^ D[2] ^ D[1] ^ D[0] ^
  635. C[0] ^ C[1] ^ C[4] ^ C[5];
  636. NewCRC[3] = D[30] ^ D[29] ^ D[26] ^ D[25] ^ D[23] ^ D[18] ^ D[16] ^
  637. D[14] ^ D[13] ^ D[11] ^ D[9] ^ D[7] ^ D[3] ^ D[2] ^ D[1] ^
  638. C[1] ^ C[2] ^ C[5] ^ C[6];
  639. NewCRC[4] = D[31] ^ D[30] ^ D[27] ^ D[26] ^ D[24] ^ D[19] ^ D[17] ^
  640. D[15] ^ D[14] ^ D[12] ^ D[10] ^ D[8] ^ D[4] ^ D[3] ^ D[2] ^
  641. C[0] ^ C[2] ^ C[3] ^ C[6] ^ C[7];
  642. NewCRC[5] = D[31] ^ D[28] ^ D[27] ^ D[25] ^ D[20] ^ D[18] ^ D[16] ^
  643. D[15] ^ D[13] ^ D[11] ^ D[9] ^ D[5] ^ D[4] ^ D[3] ^ C[1] ^
  644. C[3] ^ C[4] ^ C[7];
  645. NewCRC[6] = D[29] ^ D[28] ^ D[26] ^ D[21] ^ D[19] ^ D[17] ^ D[16] ^
  646. D[14] ^ D[12] ^ D[10] ^ D[6] ^ D[5] ^ D[4] ^ C[2] ^ C[4] ^
  647. C[5];
  648. NewCRC[7] = D[30] ^ D[29] ^ D[27] ^ D[22] ^ D[20] ^ D[18] ^ D[17] ^
  649. D[15] ^ D[13] ^ D[11] ^ D[7] ^ D[6] ^ D[5] ^ C[3] ^ C[5] ^
  650. C[6];
  651. crc_res = 0;
  652. for (i = 0; i < 8; i++)
  653. crc_res |= (NewCRC[i] << i);
  654. return crc_res;
  655. }
  656. /* registers addresses are not in order
  657. so these arrays help simplify the code */
  658. static const int cm_start[E1H_FUNC_MAX][9] = {
  659. {MISC_FUNC0_START, TCM_FUNC0_START, UCM_FUNC0_START, CCM_FUNC0_START,
  660. XCM_FUNC0_START, TSEM_FUNC0_START, USEM_FUNC0_START, CSEM_FUNC0_START,
  661. XSEM_FUNC0_START},
  662. {MISC_FUNC1_START, TCM_FUNC1_START, UCM_FUNC1_START, CCM_FUNC1_START,
  663. XCM_FUNC1_START, TSEM_FUNC1_START, USEM_FUNC1_START, CSEM_FUNC1_START,
  664. XSEM_FUNC1_START},
  665. {MISC_FUNC2_START, TCM_FUNC2_START, UCM_FUNC2_START, CCM_FUNC2_START,
  666. XCM_FUNC2_START, TSEM_FUNC2_START, USEM_FUNC2_START, CSEM_FUNC2_START,
  667. XSEM_FUNC2_START},
  668. {MISC_FUNC3_START, TCM_FUNC3_START, UCM_FUNC3_START, CCM_FUNC3_START,
  669. XCM_FUNC3_START, TSEM_FUNC3_START, USEM_FUNC3_START, CSEM_FUNC3_START,
  670. XSEM_FUNC3_START},
  671. {MISC_FUNC4_START, TCM_FUNC4_START, UCM_FUNC4_START, CCM_FUNC4_START,
  672. XCM_FUNC4_START, TSEM_FUNC4_START, USEM_FUNC4_START, CSEM_FUNC4_START,
  673. XSEM_FUNC4_START},
  674. {MISC_FUNC5_START, TCM_FUNC5_START, UCM_FUNC5_START, CCM_FUNC5_START,
  675. XCM_FUNC5_START, TSEM_FUNC5_START, USEM_FUNC5_START, CSEM_FUNC5_START,
  676. XSEM_FUNC5_START},
  677. {MISC_FUNC6_START, TCM_FUNC6_START, UCM_FUNC6_START, CCM_FUNC6_START,
  678. XCM_FUNC6_START, TSEM_FUNC6_START, USEM_FUNC6_START, CSEM_FUNC6_START,
  679. XSEM_FUNC6_START},
  680. {MISC_FUNC7_START, TCM_FUNC7_START, UCM_FUNC7_START, CCM_FUNC7_START,
  681. XCM_FUNC7_START, TSEM_FUNC7_START, USEM_FUNC7_START, CSEM_FUNC7_START,
  682. XSEM_FUNC7_START}
  683. };
  684. static const int cm_end[E1H_FUNC_MAX][9] = {
  685. {MISC_FUNC0_END, TCM_FUNC0_END, UCM_FUNC0_END, CCM_FUNC0_END,
  686. XCM_FUNC0_END, TSEM_FUNC0_END, USEM_FUNC0_END, CSEM_FUNC0_END,
  687. XSEM_FUNC0_END},
  688. {MISC_FUNC1_END, TCM_FUNC1_END, UCM_FUNC1_END, CCM_FUNC1_END,
  689. XCM_FUNC1_END, TSEM_FUNC1_END, USEM_FUNC1_END, CSEM_FUNC1_END,
  690. XSEM_FUNC1_END},
  691. {MISC_FUNC2_END, TCM_FUNC2_END, UCM_FUNC2_END, CCM_FUNC2_END,
  692. XCM_FUNC2_END, TSEM_FUNC2_END, USEM_FUNC2_END, CSEM_FUNC2_END,
  693. XSEM_FUNC2_END},
  694. {MISC_FUNC3_END, TCM_FUNC3_END, UCM_FUNC3_END, CCM_FUNC3_END,
  695. XCM_FUNC3_END, TSEM_FUNC3_END, USEM_FUNC3_END, CSEM_FUNC3_END,
  696. XSEM_FUNC3_END},
  697. {MISC_FUNC4_END, TCM_FUNC4_END, UCM_FUNC4_END, CCM_FUNC4_END,
  698. XCM_FUNC4_END, TSEM_FUNC4_END, USEM_FUNC4_END, CSEM_FUNC4_END,
  699. XSEM_FUNC4_END},
  700. {MISC_FUNC5_END, TCM_FUNC5_END, UCM_FUNC5_END, CCM_FUNC5_END,
  701. XCM_FUNC5_END, TSEM_FUNC5_END, USEM_FUNC5_END, CSEM_FUNC5_END,
  702. XSEM_FUNC5_END},
  703. {MISC_FUNC6_END, TCM_FUNC6_END, UCM_FUNC6_END, CCM_FUNC6_END,
  704. XCM_FUNC6_END, TSEM_FUNC6_END, USEM_FUNC6_END, CSEM_FUNC6_END,
  705. XSEM_FUNC6_END},
  706. {MISC_FUNC7_END, TCM_FUNC7_END, UCM_FUNC7_END, CCM_FUNC7_END,
  707. XCM_FUNC7_END, TSEM_FUNC7_END, USEM_FUNC7_END, CSEM_FUNC7_END,
  708. XSEM_FUNC7_END},
  709. };
  710. static const int hc_limits[E1H_FUNC_MAX][2] = {
  711. {HC_FUNC0_START, HC_FUNC0_END},
  712. {HC_FUNC1_START, HC_FUNC1_END},
  713. {HC_FUNC2_START, HC_FUNC2_END},
  714. {HC_FUNC3_START, HC_FUNC3_END},
  715. {HC_FUNC4_START, HC_FUNC4_END},
  716. {HC_FUNC5_START, HC_FUNC5_END},
  717. {HC_FUNC6_START, HC_FUNC6_END},
  718. {HC_FUNC7_START, HC_FUNC7_END}
  719. };
  720. #endif /* BNX2X_INIT_H */