bnx2x_init_ops.h 27 KB

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