bnx2x_init.h 26 KB

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