bnx2x_init_ops.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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-2009 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. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val);
  17. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len);
  18. static void bnx2x_init_str_wr(struct bnx2x *bp, u32 addr, const u32 *data,
  19. u32 len)
  20. {
  21. int i;
  22. for (i = 0; i < len; i++) {
  23. REG_WR(bp, addr + i*4, data[i]);
  24. if (!(i % 10000)) {
  25. touch_softlockup_watchdog();
  26. cpu_relax();
  27. }
  28. }
  29. }
  30. static void bnx2x_init_ind_wr(struct bnx2x *bp, u32 addr, const u32 *data,
  31. u16 len)
  32. {
  33. int i;
  34. for (i = 0; i < len; i++) {
  35. REG_WR_IND(bp, addr + i*4, data[i]);
  36. if (!(i % 10000)) {
  37. touch_softlockup_watchdog();
  38. cpu_relax();
  39. }
  40. }
  41. }
  42. static void bnx2x_write_big_buf(struct bnx2x *bp, u32 addr, u32 len)
  43. {
  44. int offset = 0;
  45. if (bp->dmae_ready) {
  46. while (len > DMAE_LEN32_WR_MAX) {
  47. bnx2x_write_dmae(bp, bp->gunzip_mapping + offset,
  48. addr + offset, DMAE_LEN32_WR_MAX);
  49. offset += DMAE_LEN32_WR_MAX * 4;
  50. len -= DMAE_LEN32_WR_MAX;
  51. }
  52. bnx2x_write_dmae(bp, bp->gunzip_mapping + offset,
  53. addr + offset, len);
  54. } else
  55. bnx2x_init_str_wr(bp, addr, bp->gunzip_buf, len);
  56. }
  57. static void bnx2x_init_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  58. {
  59. u32 buf_len = (((len * 4) > FW_BUF_SIZE) ? FW_BUF_SIZE : (len * 4));
  60. u32 buf_len32 = buf_len / 4;
  61. int i;
  62. memset(bp->gunzip_buf, fill, buf_len);
  63. for (i = 0; i < len; i += buf_len32) {
  64. u32 cur_len = min(buf_len32, len - i);
  65. bnx2x_write_big_buf(bp, addr + i * 4, cur_len);
  66. }
  67. }
  68. static void bnx2x_init_wr_64(struct bnx2x *bp, u32 addr, const u32 *data,
  69. u32 len64)
  70. {
  71. u32 buf_len32 = FW_BUF_SIZE / 4;
  72. u32 len = len64 * 2;
  73. u64 data64 = 0;
  74. int i;
  75. /* 64 bit value is in a blob: first low DWORD, then high DWORD */
  76. data64 = HILO_U64((*(data + 1)), (*data));
  77. len64 = min((u32)(FW_BUF_SIZE/8), len64);
  78. for (i = 0; i < len64; i++) {
  79. u64 *pdata = ((u64 *)(bp->gunzip_buf)) + i;
  80. *pdata = data64;
  81. }
  82. for (i = 0; i < len; i += buf_len32) {
  83. u32 cur_len = min(buf_len32, len - i);
  84. bnx2x_write_big_buf(bp, addr + i * 4, cur_len);
  85. }
  86. }
  87. /*********************************************************
  88. There are different blobs for each PRAM section.
  89. In addition, each blob write operation is divided into a few operations
  90. in order to decrease the amount of phys. contiguous buffer needed.
  91. Thus, when we select a blob the address may be with some offset
  92. from the beginning of PRAM section.
  93. The same holds for the INT_TABLE sections.
  94. **********************************************************/
  95. #define IF_IS_INT_TABLE_ADDR(base, addr) \
  96. if (((base) <= (addr)) && ((base) + 0x400 >= (addr)))
  97. #define IF_IS_PRAM_ADDR(base, addr) \
  98. if (((base) <= (addr)) && ((base) + 0x40000 >= (addr)))
  99. static const u8 *bnx2x_sel_blob(struct bnx2x *bp, u32 addr, const u8 *data)
  100. {
  101. IF_IS_INT_TABLE_ADDR(TSEM_REG_INT_TABLE, addr)
  102. data = bp->tsem_int_table_data;
  103. else IF_IS_INT_TABLE_ADDR(CSEM_REG_INT_TABLE, addr)
  104. data = bp->csem_int_table_data;
  105. else IF_IS_INT_TABLE_ADDR(USEM_REG_INT_TABLE, addr)
  106. data = bp->usem_int_table_data;
  107. else IF_IS_INT_TABLE_ADDR(XSEM_REG_INT_TABLE, addr)
  108. data = bp->xsem_int_table_data;
  109. else IF_IS_PRAM_ADDR(TSEM_REG_PRAM, addr)
  110. data = bp->tsem_pram_data;
  111. else IF_IS_PRAM_ADDR(CSEM_REG_PRAM, addr)
  112. data = bp->csem_pram_data;
  113. else IF_IS_PRAM_ADDR(USEM_REG_PRAM, addr)
  114. data = bp->usem_pram_data;
  115. else IF_IS_PRAM_ADDR(XSEM_REG_PRAM, addr)
  116. data = bp->xsem_pram_data;
  117. return data;
  118. }
  119. static void bnx2x_write_big_buf_wb(struct bnx2x *bp, u32 addr, u32 len)
  120. {
  121. int offset = 0;
  122. if (bp->dmae_ready) {
  123. while (len > DMAE_LEN32_WR_MAX) {
  124. bnx2x_write_dmae(bp, bp->gunzip_mapping + offset,
  125. addr + offset, DMAE_LEN32_WR_MAX);
  126. offset += DMAE_LEN32_WR_MAX * 4;
  127. len -= DMAE_LEN32_WR_MAX;
  128. }
  129. bnx2x_write_dmae(bp, bp->gunzip_mapping + offset,
  130. addr + offset, len);
  131. } else
  132. bnx2x_init_ind_wr(bp, addr, bp->gunzip_buf, len);
  133. }
  134. static void bnx2x_init_wr_wb(struct bnx2x *bp, u32 addr, const u32 *data,
  135. u32 len)
  136. {
  137. /* This is needed for NO_ZIP mode, currently supported
  138. in little endian mode only */
  139. data = (const u32*)bnx2x_sel_blob(bp, addr, (const u8*)data);
  140. if ((len * 4) > FW_BUF_SIZE) {
  141. BNX2X_ERR("LARGE DMAE OPERATION ! "
  142. "addr 0x%x len 0x%x\n", addr, len*4);
  143. return;
  144. }
  145. memcpy(bp->gunzip_buf, data, len * 4);
  146. bnx2x_write_big_buf_wb(bp, addr, len);
  147. }
  148. static void bnx2x_init_wr_zp(struct bnx2x *bp, u32 addr,
  149. u32 len, u32 blob_off)
  150. {
  151. int rc, i;
  152. const u8 *data = NULL;
  153. data = bnx2x_sel_blob(bp, addr, data) + 4*blob_off;
  154. if (data == NULL) {
  155. panic("Blob not found for addr 0x%x\n", addr);
  156. return;
  157. }
  158. rc = bnx2x_gunzip(bp, data, len);
  159. if (rc) {
  160. BNX2X_ERR("gunzip failed ! addr 0x%x rc %d\n", addr, rc);
  161. BNX2X_ERR("blob_offset=0x%x\n", blob_off);
  162. return;
  163. }
  164. /* gunzip_outlen is in dwords */
  165. len = bp->gunzip_outlen;
  166. for (i = 0; i < len; i++)
  167. ((u32 *)bp->gunzip_buf)[i] =
  168. cpu_to_le32(((u32 *)bp->gunzip_buf)[i]);
  169. bnx2x_write_big_buf_wb(bp, addr, len);
  170. }
  171. static void bnx2x_init_block(struct bnx2x *bp, u32 block, u32 stage)
  172. {
  173. int hw_wr, i;
  174. u16 op_start =
  175. bp->init_ops_offsets[BLOCK_OPS_IDX(block,stage,STAGE_START)];
  176. u16 op_end =
  177. bp->init_ops_offsets[BLOCK_OPS_IDX(block,stage,STAGE_END)];
  178. union init_op *op;
  179. u32 op_type, addr, len;
  180. const u32 *data, *data_base;
  181. /* If empty block */
  182. if (op_start == op_end)
  183. return;
  184. if (CHIP_REV_IS_FPGA(bp))
  185. hw_wr = OP_WR_FPGA;
  186. else if (CHIP_REV_IS_EMUL(bp))
  187. hw_wr = OP_WR_EMUL;
  188. else
  189. hw_wr = OP_WR_ASIC;
  190. data_base = bp->init_data;
  191. for (i = op_start; i < op_end; i++) {
  192. op = (union init_op *)&(bp->init_ops[i]);
  193. op_type = op->str_wr.op;
  194. addr = op->str_wr.offset;
  195. len = op->str_wr.data_len;
  196. data = data_base + op->str_wr.data_off;
  197. /* HW/EMUL specific */
  198. if (unlikely((op_type > OP_WB) && (op_type == hw_wr)))
  199. op_type = OP_WR;
  200. switch (op_type) {
  201. case OP_RD:
  202. REG_RD(bp, addr);
  203. break;
  204. case OP_WR:
  205. REG_WR(bp, addr, op->write.val);
  206. break;
  207. case OP_SW:
  208. bnx2x_init_str_wr(bp, addr, data, len);
  209. break;
  210. case OP_WB:
  211. bnx2x_init_wr_wb(bp, addr, data, len);
  212. break;
  213. case OP_SI:
  214. bnx2x_init_ind_wr(bp, addr, data, len);
  215. break;
  216. case OP_ZR:
  217. bnx2x_init_fill(bp, addr, 0, op->zero.len);
  218. break;
  219. case OP_ZP:
  220. bnx2x_init_wr_zp(bp, addr, len,
  221. op->str_wr.data_off);
  222. break;
  223. case OP_WR_64:
  224. bnx2x_init_wr_64(bp, addr, data, len);
  225. break;
  226. default:
  227. /* happens whenever an op is of a diff HW */
  228. #if 0
  229. DP(NETIF_MSG_HW, "skipping init operation "
  230. "index %d[%d:%d]: type %d addr 0x%x "
  231. "len %d(0x%x)\n",
  232. i, op_start, op_end, op_type, addr, len, len);
  233. #endif
  234. break;
  235. }
  236. }
  237. }
  238. /* PXP */
  239. static void bnx2x_init_pxp(struct bnx2x *bp)
  240. {
  241. u16 devctl;
  242. int r_order, w_order;
  243. u32 val, i;
  244. pci_read_config_word(bp->pdev,
  245. bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
  246. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  247. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  248. if (bp->mrrs == -1)
  249. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  250. else {
  251. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  252. r_order = bp->mrrs;
  253. }
  254. if (r_order > MAX_RD_ORD) {
  255. DP(NETIF_MSG_HW, "read order of %d order adjusted to %d\n",
  256. r_order, MAX_RD_ORD);
  257. r_order = MAX_RD_ORD;
  258. }
  259. if (w_order > MAX_WR_ORD) {
  260. DP(NETIF_MSG_HW, "write order of %d order adjusted to %d\n",
  261. w_order, MAX_WR_ORD);
  262. w_order = MAX_WR_ORD;
  263. }
  264. if (CHIP_REV_IS_FPGA(bp)) {
  265. DP(NETIF_MSG_HW, "write order adjusted to 1 for FPGA\n");
  266. w_order = 0;
  267. }
  268. DP(NETIF_MSG_HW, "read order %d write order %d\n", r_order, w_order);
  269. for (i = 0; i < NUM_RD_Q-1; i++) {
  270. REG_WR(bp, read_arb_addr[i].l, read_arb_data[i][r_order].l);
  271. REG_WR(bp, read_arb_addr[i].add,
  272. read_arb_data[i][r_order].add);
  273. REG_WR(bp, read_arb_addr[i].ubound,
  274. read_arb_data[i][r_order].ubound);
  275. }
  276. for (i = 0; i < NUM_WR_Q-1; i++) {
  277. if ((write_arb_addr[i].l == PXP2_REG_RQ_BW_WR_L29) ||
  278. (write_arb_addr[i].l == PXP2_REG_RQ_BW_WR_L30)) {
  279. REG_WR(bp, write_arb_addr[i].l,
  280. write_arb_data[i][w_order].l);
  281. REG_WR(bp, write_arb_addr[i].add,
  282. write_arb_data[i][w_order].add);
  283. REG_WR(bp, write_arb_addr[i].ubound,
  284. write_arb_data[i][w_order].ubound);
  285. } else {
  286. val = REG_RD(bp, write_arb_addr[i].l);
  287. REG_WR(bp, write_arb_addr[i].l,
  288. val | (write_arb_data[i][w_order].l << 10));
  289. val = REG_RD(bp, write_arb_addr[i].add);
  290. REG_WR(bp, write_arb_addr[i].add,
  291. val | (write_arb_data[i][w_order].add << 10));
  292. val = REG_RD(bp, write_arb_addr[i].ubound);
  293. REG_WR(bp, write_arb_addr[i].ubound,
  294. val | (write_arb_data[i][w_order].ubound << 7));
  295. }
  296. }
  297. val = write_arb_data[NUM_WR_Q-1][w_order].add;
  298. val += write_arb_data[NUM_WR_Q-1][w_order].ubound << 10;
  299. val += write_arb_data[NUM_WR_Q-1][w_order].l << 17;
  300. REG_WR(bp, PXP2_REG_PSWRQ_BW_RD, val);
  301. val = read_arb_data[NUM_RD_Q-1][r_order].add;
  302. val += read_arb_data[NUM_RD_Q-1][r_order].ubound << 10;
  303. val += read_arb_data[NUM_RD_Q-1][r_order].l << 17;
  304. REG_WR(bp, PXP2_REG_PSWRQ_BW_WR, val);
  305. REG_WR(bp, PXP2_REG_RQ_WR_MBS0, w_order);
  306. REG_WR(bp, PXP2_REG_RQ_WR_MBS1, w_order);
  307. REG_WR(bp, PXP2_REG_RQ_RD_MBS0, r_order);
  308. REG_WR(bp, PXP2_REG_RQ_RD_MBS1, r_order);
  309. if (r_order == MAX_RD_ORD)
  310. REG_WR(bp, PXP2_REG_RQ_PDR_LIMIT, 0xe00);
  311. REG_WR(bp, PXP2_REG_WR_USDMDP_TH, (0x18 << w_order));
  312. if (CHIP_IS_E1H(bp)) {
  313. val = ((w_order == 0) ? 2 : 3);
  314. REG_WR(bp, PXP2_REG_WR_HC_MPS, val);
  315. REG_WR(bp, PXP2_REG_WR_USDM_MPS, val);
  316. REG_WR(bp, PXP2_REG_WR_CSDM_MPS, val);
  317. REG_WR(bp, PXP2_REG_WR_TSDM_MPS, val);
  318. REG_WR(bp, PXP2_REG_WR_XSDM_MPS, val);
  319. REG_WR(bp, PXP2_REG_WR_QM_MPS, val);
  320. REG_WR(bp, PXP2_REG_WR_TM_MPS, val);
  321. REG_WR(bp, PXP2_REG_WR_SRC_MPS, val);
  322. REG_WR(bp, PXP2_REG_WR_DBG_MPS, val);
  323. REG_WR(bp, PXP2_REG_WR_DMAE_MPS, 2); /* DMAE is special */
  324. REG_WR(bp, PXP2_REG_WR_CDU_MPS, val);
  325. }
  326. }
  327. /*****************************************************************************
  328. * Description:
  329. * Calculates crc 8 on a word value: polynomial 0-1-2-8
  330. * Code was translated from Verilog.
  331. ****************************************************************************/
  332. static u8 calc_crc8(u32 data, u8 crc)
  333. {
  334. u8 D[32];
  335. u8 NewCRC[8];
  336. u8 C[8];
  337. u8 crc_res;
  338. u8 i;
  339. /* split the data into 31 bits */
  340. for (i = 0; i < 32; i++) {
  341. D[i] = data & 1;
  342. data = data >> 1;
  343. }
  344. /* split the crc into 8 bits */
  345. for (i = 0; i < 8; i++) {
  346. C[i] = crc & 1;
  347. crc = crc >> 1;
  348. }
  349. NewCRC[0] = D[31] ^ D[30] ^ D[28] ^ D[23] ^ D[21] ^ D[19] ^ D[18] ^
  350. D[16] ^ D[14] ^ D[12] ^ D[8] ^ D[7] ^ D[6] ^ D[0] ^ C[4] ^
  351. C[6] ^ C[7];
  352. NewCRC[1] = D[30] ^ D[29] ^ D[28] ^ D[24] ^ D[23] ^ D[22] ^ D[21] ^
  353. D[20] ^ D[18] ^ D[17] ^ D[16] ^ D[15] ^ D[14] ^ D[13] ^
  354. D[12] ^ D[9] ^ D[6] ^ D[1] ^ D[0] ^ C[0] ^ C[4] ^ C[5] ^ C[6];
  355. NewCRC[2] = D[29] ^ D[28] ^ D[25] ^ D[24] ^ D[22] ^ D[17] ^ D[15] ^
  356. D[13] ^ D[12] ^ D[10] ^ D[8] ^ D[6] ^ D[2] ^ D[1] ^ D[0] ^
  357. C[0] ^ C[1] ^ C[4] ^ C[5];
  358. NewCRC[3] = D[30] ^ D[29] ^ D[26] ^ D[25] ^ D[23] ^ D[18] ^ D[16] ^
  359. D[14] ^ D[13] ^ D[11] ^ D[9] ^ D[7] ^ D[3] ^ D[2] ^ D[1] ^
  360. C[1] ^ C[2] ^ C[5] ^ C[6];
  361. NewCRC[4] = D[31] ^ D[30] ^ D[27] ^ D[26] ^ D[24] ^ D[19] ^ D[17] ^
  362. D[15] ^ D[14] ^ D[12] ^ D[10] ^ D[8] ^ D[4] ^ D[3] ^ D[2] ^
  363. C[0] ^ C[2] ^ C[3] ^ C[6] ^ C[7];
  364. NewCRC[5] = D[31] ^ D[28] ^ D[27] ^ D[25] ^ D[20] ^ D[18] ^ D[16] ^
  365. D[15] ^ D[13] ^ D[11] ^ D[9] ^ D[5] ^ D[4] ^ D[3] ^ C[1] ^
  366. C[3] ^ C[4] ^ C[7];
  367. NewCRC[6] = D[29] ^ D[28] ^ D[26] ^ D[21] ^ D[19] ^ D[17] ^ D[16] ^
  368. D[14] ^ D[12] ^ D[10] ^ D[6] ^ D[5] ^ D[4] ^ C[2] ^ C[4] ^
  369. C[5];
  370. NewCRC[7] = D[30] ^ D[29] ^ D[27] ^ D[22] ^ D[20] ^ D[18] ^ D[17] ^
  371. D[15] ^ D[13] ^ D[11] ^ D[7] ^ D[6] ^ D[5] ^ C[3] ^ C[5] ^
  372. C[6];
  373. crc_res = 0;
  374. for (i = 0; i < 8; i++)
  375. crc_res |= (NewCRC[i] << i);
  376. return crc_res;
  377. }
  378. #endif /* BNX2X_INIT_OPS_H */