bnx2x_init_ops.h 26 KB

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