bnx2x_init.h 25 KB

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