bnx2x_init.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /* bnx2x_init.h: Broadcom Everest network driver.
  2. * Structures and macroes needed during the initialization.
  3. *
  4. * Copyright (c) 2007-2013 Broadcom Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation.
  9. *
  10. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  11. * Written by: Eliezer Tamir
  12. * Modified by: Vladislav Zolotarov <vladz@broadcom.com>
  13. */
  14. #ifndef BNX2X_INIT_H
  15. #define BNX2X_INIT_H
  16. /* Init operation types and structures */
  17. enum {
  18. OP_RD = 0x1, /* read a single register */
  19. OP_WR, /* write a single register */
  20. OP_SW, /* copy a string to the device */
  21. OP_ZR, /* clear memory */
  22. OP_ZP, /* unzip then copy with DMAE */
  23. OP_WR_64, /* write 64 bit pattern */
  24. OP_WB, /* copy a string using DMAE */
  25. OP_WB_ZR, /* Clear a string using DMAE or indirect-wr */
  26. /* Skip the following ops if all of the init modes don't match */
  27. OP_IF_MODE_OR,
  28. /* Skip the following ops if any of the init modes don't match */
  29. OP_IF_MODE_AND,
  30. OP_MAX
  31. };
  32. enum {
  33. STAGE_START,
  34. STAGE_END,
  35. };
  36. /* Returns the index of start or end of a specific block stage in ops array*/
  37. #define BLOCK_OPS_IDX(block, stage, end) \
  38. (2*(((block)*NUM_OF_INIT_PHASES) + (stage)) + (end))
  39. /* structs for the various opcodes */
  40. struct raw_op {
  41. u32 op:8;
  42. u32 offset:24;
  43. u32 raw_data;
  44. };
  45. struct op_read {
  46. u32 op:8;
  47. u32 offset:24;
  48. u32 val;
  49. };
  50. struct op_write {
  51. u32 op:8;
  52. u32 offset:24;
  53. u32 val;
  54. };
  55. struct op_arr_write {
  56. u32 op:8;
  57. u32 offset:24;
  58. #ifdef __BIG_ENDIAN
  59. u16 data_len;
  60. u16 data_off;
  61. #else /* __LITTLE_ENDIAN */
  62. u16 data_off;
  63. u16 data_len;
  64. #endif
  65. };
  66. struct op_zero {
  67. u32 op:8;
  68. u32 offset:24;
  69. u32 len;
  70. };
  71. struct op_if_mode {
  72. u32 op:8;
  73. u32 cmd_offset:24;
  74. u32 mode_bit_map;
  75. };
  76. union init_op {
  77. struct op_read read;
  78. struct op_write write;
  79. struct op_arr_write arr_wr;
  80. struct op_zero zero;
  81. struct raw_op raw;
  82. struct op_if_mode if_mode;
  83. };
  84. /* Init Phases */
  85. enum {
  86. PHASE_COMMON,
  87. PHASE_PORT0,
  88. PHASE_PORT1,
  89. PHASE_PF0,
  90. PHASE_PF1,
  91. PHASE_PF2,
  92. PHASE_PF3,
  93. PHASE_PF4,
  94. PHASE_PF5,
  95. PHASE_PF6,
  96. PHASE_PF7,
  97. NUM_OF_INIT_PHASES
  98. };
  99. /* Init Modes */
  100. enum {
  101. MODE_ASIC = 0x00000001,
  102. MODE_FPGA = 0x00000002,
  103. MODE_EMUL = 0x00000004,
  104. MODE_E2 = 0x00000008,
  105. MODE_E3 = 0x00000010,
  106. MODE_PORT2 = 0x00000020,
  107. MODE_PORT4 = 0x00000040,
  108. MODE_SF = 0x00000080,
  109. MODE_MF = 0x00000100,
  110. MODE_MF_SD = 0x00000200,
  111. MODE_MF_SI = 0x00000400,
  112. MODE_MF_AFEX = 0x00000800,
  113. MODE_E3_A0 = 0x00001000,
  114. MODE_E3_B0 = 0x00002000,
  115. MODE_COS3 = 0x00004000,
  116. MODE_COS6 = 0x00008000,
  117. MODE_LITTLE_ENDIAN = 0x00010000,
  118. MODE_BIG_ENDIAN = 0x00020000,
  119. };
  120. /* Init Blocks */
  121. enum {
  122. BLOCK_ATC,
  123. BLOCK_BRB1,
  124. BLOCK_CCM,
  125. BLOCK_CDU,
  126. BLOCK_CFC,
  127. BLOCK_CSDM,
  128. BLOCK_CSEM,
  129. BLOCK_DBG,
  130. BLOCK_DMAE,
  131. BLOCK_DORQ,
  132. BLOCK_HC,
  133. BLOCK_IGU,
  134. BLOCK_MISC,
  135. BLOCK_NIG,
  136. BLOCK_PBF,
  137. BLOCK_PGLUE_B,
  138. BLOCK_PRS,
  139. BLOCK_PXP2,
  140. BLOCK_PXP,
  141. BLOCK_QM,
  142. BLOCK_SRC,
  143. BLOCK_TCM,
  144. BLOCK_TM,
  145. BLOCK_TSDM,
  146. BLOCK_TSEM,
  147. BLOCK_UCM,
  148. BLOCK_UPB,
  149. BLOCK_USDM,
  150. BLOCK_USEM,
  151. BLOCK_XCM,
  152. BLOCK_XPB,
  153. BLOCK_XSDM,
  154. BLOCK_XSEM,
  155. BLOCK_MISC_AEU,
  156. NUM_OF_INIT_BLOCKS
  157. };
  158. /* QM queue numbers */
  159. #define BNX2X_ETH_Q 0
  160. #define BNX2X_TOE_Q 3
  161. #define BNX2X_TOE_ACK_Q 6
  162. #define BNX2X_ISCSI_Q 9
  163. #define BNX2X_ISCSI_ACK_Q 11
  164. #define BNX2X_FCOE_Q 10
  165. /* Vnics per mode */
  166. #define BNX2X_PORT2_MODE_NUM_VNICS 4
  167. #define BNX2X_PORT4_MODE_NUM_VNICS 2
  168. /* COS offset for port1 in E3 B0 4port mode */
  169. #define BNX2X_E3B0_PORT1_COS_OFFSET 3
  170. /* QM Register addresses */
  171. #define BNX2X_Q_VOQ_REG_ADDR(pf_q_num)\
  172. (QM_REG_QVOQIDX_0 + 4 * (pf_q_num))
  173. #define BNX2X_VOQ_Q_REG_ADDR(cos, pf_q_num)\
  174. (QM_REG_VOQQMASK_0_LSB + 4 * ((cos) * 2 + ((pf_q_num) >> 5)))
  175. #define BNX2X_Q_CMDQ_REG_ADDR(pf_q_num)\
  176. (QM_REG_BYTECRDCMDQ_0 + 4 * ((pf_q_num) >> 4))
  177. /* extracts the QM queue number for the specified port and vnic */
  178. #define BNX2X_PF_Q_NUM(q_num, port, vnic)\
  179. ((((port) << 1) | (vnic)) * 16 + (q_num))
  180. /* Maps the specified queue to the specified COS */
  181. static inline void bnx2x_map_q_cos(struct bnx2x *bp, u32 q_num, u32 new_cos)
  182. {
  183. /* find current COS mapping */
  184. u32 curr_cos = REG_RD(bp, QM_REG_QVOQIDX_0 + q_num * 4);
  185. /* check if queue->COS mapping has changed */
  186. if (curr_cos != new_cos) {
  187. u32 num_vnics = BNX2X_PORT2_MODE_NUM_VNICS;
  188. u32 reg_addr, reg_bit_map, vnic;
  189. /* update parameters for 4port mode */
  190. if (INIT_MODE_FLAGS(bp) & MODE_PORT4) {
  191. num_vnics = BNX2X_PORT4_MODE_NUM_VNICS;
  192. if (BP_PORT(bp)) {
  193. curr_cos += BNX2X_E3B0_PORT1_COS_OFFSET;
  194. new_cos += BNX2X_E3B0_PORT1_COS_OFFSET;
  195. }
  196. }
  197. /* change queue mapping for each VNIC */
  198. for (vnic = 0; vnic < num_vnics; vnic++) {
  199. u32 pf_q_num =
  200. BNX2X_PF_Q_NUM(q_num, BP_PORT(bp), vnic);
  201. u32 q_bit_map = 1 << (pf_q_num & 0x1f);
  202. /* overwrite queue->VOQ mapping */
  203. REG_WR(bp, BNX2X_Q_VOQ_REG_ADDR(pf_q_num), new_cos);
  204. /* clear queue bit from current COS bit map */
  205. reg_addr = BNX2X_VOQ_Q_REG_ADDR(curr_cos, pf_q_num);
  206. reg_bit_map = REG_RD(bp, reg_addr);
  207. REG_WR(bp, reg_addr, reg_bit_map & (~q_bit_map));
  208. /* set queue bit in new COS bit map */
  209. reg_addr = BNX2X_VOQ_Q_REG_ADDR(new_cos, pf_q_num);
  210. reg_bit_map = REG_RD(bp, reg_addr);
  211. REG_WR(bp, reg_addr, reg_bit_map | q_bit_map);
  212. /* set/clear queue bit in command-queue bit map
  213. * (E2/E3A0 only, valid COS values are 0/1)
  214. */
  215. if (!(INIT_MODE_FLAGS(bp) & MODE_E3_B0)) {
  216. reg_addr = BNX2X_Q_CMDQ_REG_ADDR(pf_q_num);
  217. reg_bit_map = REG_RD(bp, reg_addr);
  218. q_bit_map = 1 << (2 * (pf_q_num & 0xf));
  219. reg_bit_map = new_cos ?
  220. (reg_bit_map | q_bit_map) :
  221. (reg_bit_map & (~q_bit_map));
  222. REG_WR(bp, reg_addr, reg_bit_map);
  223. }
  224. }
  225. }
  226. }
  227. /* Configures the QM according to the specified per-traffic-type COSes */
  228. static inline void bnx2x_dcb_config_qm(struct bnx2x *bp, enum cos_mode mode,
  229. struct priority_cos *traffic_cos)
  230. {
  231. bnx2x_map_q_cos(bp, BNX2X_FCOE_Q,
  232. traffic_cos[LLFC_TRAFFIC_TYPE_FCOE].cos);
  233. bnx2x_map_q_cos(bp, BNX2X_ISCSI_Q,
  234. traffic_cos[LLFC_TRAFFIC_TYPE_ISCSI].cos);
  235. bnx2x_map_q_cos(bp, BNX2X_ISCSI_ACK_Q,
  236. traffic_cos[LLFC_TRAFFIC_TYPE_ISCSI].cos);
  237. if (mode != STATIC_COS) {
  238. /* required only in backward compatible COS mode */
  239. bnx2x_map_q_cos(bp, BNX2X_ETH_Q,
  240. traffic_cos[LLFC_TRAFFIC_TYPE_NW].cos);
  241. bnx2x_map_q_cos(bp, BNX2X_TOE_Q,
  242. traffic_cos[LLFC_TRAFFIC_TYPE_NW].cos);
  243. bnx2x_map_q_cos(bp, BNX2X_TOE_ACK_Q,
  244. traffic_cos[LLFC_TRAFFIC_TYPE_NW].cos);
  245. }
  246. }
  247. /* congestion managment port init api description
  248. * the api works as follows:
  249. * the driver should pass the cmng_init_input struct, the port_init function
  250. * will prepare the required internal ram structure which will be passed back
  251. * to the driver (cmng_init) that will write it into the internal ram.
  252. *
  253. * IMPORTANT REMARKS:
  254. * 1. the cmng_init struct does not represent the contiguous internal ram
  255. * structure. the driver should use the XSTORM_CMNG_PERPORT_VARS_OFFSET
  256. * offset in order to write the port sub struct and the
  257. * PFID_FROM_PORT_AND_VNIC offset for writing the vnic sub struct (in other
  258. * words - don't use memcpy!).
  259. * 2. although the cmng_init struct is filled for the maximal vnic number
  260. * possible, the driver should only write the valid vnics into the internal
  261. * ram according to the appropriate port mode.
  262. */
  263. #define BITS_TO_BYTES(x) ((x)/8)
  264. /* CMNG constants, as derived from system spec calculations */
  265. /* default MIN rate in case VNIC min rate is configured to zero- 100Mbps */
  266. #define DEF_MIN_RATE 100
  267. /* resolution of the rate shaping timer - 400 usec */
  268. #define RS_PERIODIC_TIMEOUT_USEC 400
  269. /* number of bytes in single QM arbitration cycle -
  270. * coefficient for calculating the fairness timer
  271. */
  272. #define QM_ARB_BYTES 160000
  273. /* resolution of Min algorithm 1:100 */
  274. #define MIN_RES 100
  275. /* how many bytes above threshold for
  276. * the minimal credit of Min algorithm
  277. */
  278. #define MIN_ABOVE_THRESH 32768
  279. /* Fairness algorithm integration time coefficient -
  280. * for calculating the actual Tfair
  281. */
  282. #define T_FAIR_COEF ((MIN_ABOVE_THRESH + QM_ARB_BYTES) * 8 * MIN_RES)
  283. /* Memory of fairness algorithm - 2 cycles */
  284. #define FAIR_MEM 2
  285. #define SAFC_TIMEOUT_USEC 52
  286. #define SDM_TICKS 4
  287. static inline void bnx2x_init_max(const struct cmng_init_input *input_data,
  288. u32 r_param, struct cmng_init *ram_data)
  289. {
  290. u32 vnic;
  291. struct cmng_vnic *vdata = &ram_data->vnic;
  292. struct cmng_struct_per_port *pdata = &ram_data->port;
  293. /* rate shaping per-port variables
  294. * 100 micro seconds in SDM ticks = 25
  295. * since each tick is 4 microSeconds
  296. */
  297. pdata->rs_vars.rs_periodic_timeout =
  298. RS_PERIODIC_TIMEOUT_USEC / SDM_TICKS;
  299. /* this is the threshold below which no timer arming will occur.
  300. * 1.25 coefficient is for the threshold to be a little bigger
  301. * then the real time to compensate for timer in-accuracy
  302. */
  303. pdata->rs_vars.rs_threshold =
  304. (5 * RS_PERIODIC_TIMEOUT_USEC * r_param)/4;
  305. /* rate shaping per-vnic variables */
  306. for (vnic = 0; vnic < BNX2X_PORT2_MODE_NUM_VNICS; vnic++) {
  307. /* global vnic counter */
  308. vdata->vnic_max_rate[vnic].vn_counter.rate =
  309. input_data->vnic_max_rate[vnic];
  310. /* maximal Mbps for this vnic
  311. * the quota in each timer period - number of bytes
  312. * transmitted in this period
  313. */
  314. vdata->vnic_max_rate[vnic].vn_counter.quota =
  315. RS_PERIODIC_TIMEOUT_USEC *
  316. (u32)vdata->vnic_max_rate[vnic].vn_counter.rate / 8;
  317. }
  318. }
  319. static inline void bnx2x_init_min(const struct cmng_init_input *input_data,
  320. u32 r_param, struct cmng_init *ram_data)
  321. {
  322. u32 vnic, fair_periodic_timeout_usec, vnicWeightSum, tFair;
  323. struct cmng_vnic *vdata = &ram_data->vnic;
  324. struct cmng_struct_per_port *pdata = &ram_data->port;
  325. /* this is the resolution of the fairness timer */
  326. fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
  327. /* fairness per-port variables
  328. * for 10G it is 1000usec. for 1G it is 10000usec.
  329. */
  330. tFair = T_FAIR_COEF / input_data->port_rate;
  331. /* this is the threshold below which we won't arm the timer anymore */
  332. pdata->fair_vars.fair_threshold = QM_ARB_BYTES;
  333. /* we multiply by 1e3/8 to get bytes/msec. We don't want the credits
  334. * to pass a credit of the T_FAIR*FAIR_MEM (algorithm resolution)
  335. */
  336. pdata->fair_vars.upper_bound = r_param * tFair * FAIR_MEM;
  337. /* since each tick is 4 microSeconds */
  338. pdata->fair_vars.fairness_timeout =
  339. fair_periodic_timeout_usec / SDM_TICKS;
  340. /* calculate sum of weights */
  341. vnicWeightSum = 0;
  342. for (vnic = 0; vnic < BNX2X_PORT2_MODE_NUM_VNICS; vnic++)
  343. vnicWeightSum += input_data->vnic_min_rate[vnic];
  344. /* global vnic counter */
  345. if (vnicWeightSum > 0) {
  346. /* fairness per-vnic variables */
  347. for (vnic = 0; vnic < BNX2X_PORT2_MODE_NUM_VNICS; vnic++) {
  348. /* this is the credit for each period of the fairness
  349. * algorithm - number of bytes in T_FAIR (this vnic
  350. * share of the port rate)
  351. */
  352. vdata->vnic_min_rate[vnic].vn_credit_delta =
  353. (u32)input_data->vnic_min_rate[vnic] * 100 *
  354. (T_FAIR_COEF / (8 * 100 * vnicWeightSum));
  355. if (vdata->vnic_min_rate[vnic].vn_credit_delta <
  356. pdata->fair_vars.fair_threshold +
  357. MIN_ABOVE_THRESH) {
  358. vdata->vnic_min_rate[vnic].vn_credit_delta =
  359. pdata->fair_vars.fair_threshold +
  360. MIN_ABOVE_THRESH;
  361. }
  362. }
  363. }
  364. }
  365. static inline void bnx2x_init_fw_wrr(const struct cmng_init_input *input_data,
  366. u32 r_param, struct cmng_init *ram_data)
  367. {
  368. u32 vnic, cos;
  369. u32 cosWeightSum = 0;
  370. struct cmng_vnic *vdata = &ram_data->vnic;
  371. struct cmng_struct_per_port *pdata = &ram_data->port;
  372. for (cos = 0; cos < MAX_COS_NUMBER; cos++)
  373. cosWeightSum += input_data->cos_min_rate[cos];
  374. if (cosWeightSum > 0) {
  375. for (vnic = 0; vnic < BNX2X_PORT2_MODE_NUM_VNICS; vnic++) {
  376. /* Since cos and vnic shouldn't work together the rate
  377. * to divide between the coses is the port rate.
  378. */
  379. u32 *ccd = vdata->vnic_min_rate[vnic].cos_credit_delta;
  380. for (cos = 0; cos < MAX_COS_NUMBER; cos++) {
  381. /* this is the credit for each period of
  382. * the fairness algorithm - number of bytes
  383. * in T_FAIR (this cos share of the vnic rate)
  384. */
  385. ccd[cos] =
  386. (u32)input_data->cos_min_rate[cos] * 100 *
  387. (T_FAIR_COEF / (8 * 100 * cosWeightSum));
  388. if (ccd[cos] < pdata->fair_vars.fair_threshold
  389. + MIN_ABOVE_THRESH) {
  390. ccd[cos] =
  391. pdata->fair_vars.fair_threshold +
  392. MIN_ABOVE_THRESH;
  393. }
  394. }
  395. }
  396. }
  397. }
  398. static inline void bnx2x_init_safc(const struct cmng_init_input *input_data,
  399. struct cmng_init *ram_data)
  400. {
  401. /* in microSeconds */
  402. ram_data->port.safc_vars.safc_timeout_usec = SAFC_TIMEOUT_USEC;
  403. }
  404. /* Congestion management port init */
  405. static inline void bnx2x_init_cmng(const struct cmng_init_input *input_data,
  406. struct cmng_init *ram_data)
  407. {
  408. u32 r_param;
  409. memset(ram_data, 0, sizeof(struct cmng_init));
  410. ram_data->port.flags = input_data->flags;
  411. /* number of bytes transmitted in a rate of 10Gbps
  412. * in one usec = 1.25KB.
  413. */
  414. r_param = BITS_TO_BYTES(input_data->port_rate);
  415. bnx2x_init_max(input_data, r_param, ram_data);
  416. bnx2x_init_min(input_data, r_param, ram_data);
  417. bnx2x_init_fw_wrr(input_data, r_param, ram_data);
  418. bnx2x_init_safc(input_data, ram_data);
  419. }
  420. /* Returns the index of start or end of a specific block stage in ops array */
  421. #define BLOCK_OPS_IDX(block, stage, end) \
  422. (2*(((block)*NUM_OF_INIT_PHASES) + (stage)) + (end))
  423. #define INITOP_SET 0 /* set the HW directly */
  424. #define INITOP_CLEAR 1 /* clear the HW directly */
  425. #define INITOP_INIT 2 /* set the init-value array */
  426. /****************************************************************************
  427. * ILT management
  428. ****************************************************************************/
  429. struct ilt_line {
  430. dma_addr_t page_mapping;
  431. void *page;
  432. u32 size;
  433. };
  434. struct ilt_client_info {
  435. u32 page_size;
  436. u16 start;
  437. u16 end;
  438. u16 client_num;
  439. u16 flags;
  440. #define ILT_CLIENT_SKIP_INIT 0x1
  441. #define ILT_CLIENT_SKIP_MEM 0x2
  442. };
  443. struct bnx2x_ilt {
  444. u32 start_line;
  445. struct ilt_line *lines;
  446. struct ilt_client_info clients[4];
  447. #define ILT_CLIENT_CDU 0
  448. #define ILT_CLIENT_QM 1
  449. #define ILT_CLIENT_SRC 2
  450. #define ILT_CLIENT_TM 3
  451. };
  452. /****************************************************************************
  453. * SRC configuration
  454. ****************************************************************************/
  455. struct src_ent {
  456. u8 opaque[56];
  457. u64 next;
  458. };
  459. /****************************************************************************
  460. * Parity configuration
  461. ****************************************************************************/
  462. #define BLOCK_PRTY_INFO(block, en_mask, m1, m1h, m2, m3) \
  463. { \
  464. block##_REG_##block##_PRTY_MASK, \
  465. block##_REG_##block##_PRTY_STS_CLR, \
  466. en_mask, {m1, m1h, m2, m3}, #block \
  467. }
  468. #define BLOCK_PRTY_INFO_0(block, en_mask, m1, m1h, m2, m3) \
  469. { \
  470. block##_REG_##block##_PRTY_MASK_0, \
  471. block##_REG_##block##_PRTY_STS_CLR_0, \
  472. en_mask, {m1, m1h, m2, m3}, #block"_0" \
  473. }
  474. #define BLOCK_PRTY_INFO_1(block, en_mask, m1, m1h, m2, m3) \
  475. { \
  476. block##_REG_##block##_PRTY_MASK_1, \
  477. block##_REG_##block##_PRTY_STS_CLR_1, \
  478. en_mask, {m1, m1h, m2, m3}, #block"_1" \
  479. }
  480. static const struct {
  481. u32 mask_addr;
  482. u32 sts_clr_addr;
  483. u32 en_mask; /* Mask to enable parity attentions */
  484. struct {
  485. u32 e1; /* 57710 */
  486. u32 e1h; /* 57711 */
  487. u32 e2; /* 57712 */
  488. u32 e3; /* 578xx */
  489. } reg_mask; /* Register mask (all valid bits) */
  490. char name[8]; /* Block's longest name is 7 characters long
  491. * (name + suffix)
  492. */
  493. } bnx2x_blocks_parity_data[] = {
  494. /* bit 19 masked */
  495. /* REG_WR(bp, PXP_REG_PXP_PRTY_MASK, 0x80000); */
  496. /* bit 5,18,20-31 */
  497. /* REG_WR(bp, PXP2_REG_PXP2_PRTY_MASK_0, 0xfff40020); */
  498. /* bit 5 */
  499. /* REG_WR(bp, PXP2_REG_PXP2_PRTY_MASK_1, 0x20); */
  500. /* REG_WR(bp, HC_REG_HC_PRTY_MASK, 0x0); */
  501. /* REG_WR(bp, MISC_REG_MISC_PRTY_MASK, 0x0); */
  502. /* Block IGU, MISC, PXP and PXP2 parity errors as long as we don't
  503. * want to handle "system kill" flow at the moment.
  504. */
  505. BLOCK_PRTY_INFO(PXP, 0x7ffffff, 0x3ffffff, 0x3ffffff, 0x7ffffff,
  506. 0x7ffffff),
  507. BLOCK_PRTY_INFO_0(PXP2, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
  508. 0xffffffff),
  509. BLOCK_PRTY_INFO_1(PXP2, 0x1ffffff, 0x7f, 0x7f, 0x7ff, 0x1ffffff),
  510. BLOCK_PRTY_INFO(HC, 0x7, 0x7, 0x7, 0, 0),
  511. BLOCK_PRTY_INFO(NIG, 0xffffffff, 0x3fffffff, 0xffffffff, 0, 0),
  512. BLOCK_PRTY_INFO_0(NIG, 0xffffffff, 0, 0, 0xffffffff, 0xffffffff),
  513. BLOCK_PRTY_INFO_1(NIG, 0xffff, 0, 0, 0xff, 0xffff),
  514. BLOCK_PRTY_INFO(IGU, 0x7ff, 0, 0, 0x7ff, 0x7ff),
  515. BLOCK_PRTY_INFO(MISC, 0x1, 0x1, 0x1, 0x1, 0x1),
  516. BLOCK_PRTY_INFO(QM, 0, 0x1ff, 0xfff, 0xfff, 0xfff),
  517. BLOCK_PRTY_INFO(ATC, 0x1f, 0, 0, 0x1f, 0x1f),
  518. BLOCK_PRTY_INFO(PGLUE_B, 0x3, 0, 0, 0x3, 0x3),
  519. BLOCK_PRTY_INFO(DORQ, 0, 0x3, 0x3, 0x3, 0x3),
  520. {GRCBASE_UPB + PB_REG_PB_PRTY_MASK,
  521. GRCBASE_UPB + PB_REG_PB_PRTY_STS_CLR, 0xf,
  522. {0xf, 0xf, 0xf, 0xf}, "UPB"},
  523. {GRCBASE_XPB + PB_REG_PB_PRTY_MASK,
  524. GRCBASE_XPB + PB_REG_PB_PRTY_STS_CLR, 0,
  525. {0xf, 0xf, 0xf, 0xf}, "XPB"},
  526. BLOCK_PRTY_INFO(SRC, 0x4, 0x7, 0x7, 0x7, 0x7),
  527. BLOCK_PRTY_INFO(CDU, 0, 0x1f, 0x1f, 0x1f, 0x1f),
  528. BLOCK_PRTY_INFO(CFC, 0, 0xf, 0xf, 0xf, 0x3f),
  529. BLOCK_PRTY_INFO(DBG, 0, 0x1, 0x1, 0x1, 0x1),
  530. BLOCK_PRTY_INFO(DMAE, 0, 0xf, 0xf, 0xf, 0xf),
  531. BLOCK_PRTY_INFO(BRB1, 0, 0xf, 0xf, 0xf, 0xf),
  532. BLOCK_PRTY_INFO(PRS, (1<<6), 0xff, 0xff, 0xff, 0xff),
  533. BLOCK_PRTY_INFO(PBF, 0, 0, 0x3ffff, 0xfffff, 0xfffffff),
  534. BLOCK_PRTY_INFO(TM, 0, 0, 0x7f, 0x7f, 0x7f),
  535. BLOCK_PRTY_INFO(TSDM, 0x18, 0x7ff, 0x7ff, 0x7ff, 0x7ff),
  536. BLOCK_PRTY_INFO(CSDM, 0x8, 0x7ff, 0x7ff, 0x7ff, 0x7ff),
  537. BLOCK_PRTY_INFO(USDM, 0x38, 0x7ff, 0x7ff, 0x7ff, 0x7ff),
  538. BLOCK_PRTY_INFO(XSDM, 0x8, 0x7ff, 0x7ff, 0x7ff, 0x7ff),
  539. BLOCK_PRTY_INFO(TCM, 0, 0, 0x7ffffff, 0x7ffffff, 0x7ffffff),
  540. BLOCK_PRTY_INFO(CCM, 0, 0, 0x7ffffff, 0x7ffffff, 0x7ffffff),
  541. BLOCK_PRTY_INFO(UCM, 0, 0, 0x7ffffff, 0x7ffffff, 0x7ffffff),
  542. BLOCK_PRTY_INFO(XCM, 0, 0, 0x3fffffff, 0x3fffffff, 0x3fffffff),
  543. BLOCK_PRTY_INFO_0(TSEM, 0, 0xffffffff, 0xffffffff, 0xffffffff,
  544. 0xffffffff),
  545. BLOCK_PRTY_INFO_1(TSEM, 0, 0x3, 0x1f, 0x3f, 0x3f),
  546. BLOCK_PRTY_INFO_0(USEM, 0, 0xffffffff, 0xffffffff, 0xffffffff,
  547. 0xffffffff),
  548. BLOCK_PRTY_INFO_1(USEM, 0, 0x3, 0x1f, 0x1f, 0x1f),
  549. BLOCK_PRTY_INFO_0(CSEM, 0, 0xffffffff, 0xffffffff, 0xffffffff,
  550. 0xffffffff),
  551. BLOCK_PRTY_INFO_1(CSEM, 0, 0x3, 0x1f, 0x1f, 0x1f),
  552. BLOCK_PRTY_INFO_0(XSEM, 0, 0xffffffff, 0xffffffff, 0xffffffff,
  553. 0xffffffff),
  554. BLOCK_PRTY_INFO_1(XSEM, 0, 0x3, 0x1f, 0x3f, 0x3f),
  555. };
  556. /* [28] MCP Latched rom_parity
  557. * [29] MCP Latched ump_rx_parity
  558. * [30] MCP Latched ump_tx_parity
  559. * [31] MCP Latched scpad_parity
  560. */
  561. #define MISC_AEU_ENABLE_MCP_PRTY_BITS \
  562. (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
  563. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
  564. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
  565. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
  566. /* Below registers control the MCP parity attention output. When
  567. * MISC_AEU_ENABLE_MCP_PRTY_BITS are set - attentions are
  568. * enabled, when cleared - disabled.
  569. */
  570. static const u32 mcp_attn_ctl_regs[] = {
  571. MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0,
  572. MISC_REG_AEU_ENABLE4_NIG_0,
  573. MISC_REG_AEU_ENABLE4_PXP_0,
  574. MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0,
  575. MISC_REG_AEU_ENABLE4_NIG_1,
  576. MISC_REG_AEU_ENABLE4_PXP_1
  577. };
  578. static inline void bnx2x_set_mcp_parity(struct bnx2x *bp, u8 enable)
  579. {
  580. int i;
  581. u32 reg_val;
  582. for (i = 0; i < ARRAY_SIZE(mcp_attn_ctl_regs); i++) {
  583. reg_val = REG_RD(bp, mcp_attn_ctl_regs[i]);
  584. if (enable)
  585. reg_val |= MISC_AEU_ENABLE_MCP_PRTY_BITS;
  586. else
  587. reg_val &= ~MISC_AEU_ENABLE_MCP_PRTY_BITS;
  588. REG_WR(bp, mcp_attn_ctl_regs[i], reg_val);
  589. }
  590. }
  591. static inline u32 bnx2x_parity_reg_mask(struct bnx2x *bp, int idx)
  592. {
  593. if (CHIP_IS_E1(bp))
  594. return bnx2x_blocks_parity_data[idx].reg_mask.e1;
  595. else if (CHIP_IS_E1H(bp))
  596. return bnx2x_blocks_parity_data[idx].reg_mask.e1h;
  597. else if (CHIP_IS_E2(bp))
  598. return bnx2x_blocks_parity_data[idx].reg_mask.e2;
  599. else /* CHIP_IS_E3 */
  600. return bnx2x_blocks_parity_data[idx].reg_mask.e3;
  601. }
  602. static inline void bnx2x_disable_blocks_parity(struct bnx2x *bp)
  603. {
  604. int i;
  605. for (i = 0; i < ARRAY_SIZE(bnx2x_blocks_parity_data); i++) {
  606. u32 dis_mask = bnx2x_parity_reg_mask(bp, i);
  607. if (dis_mask) {
  608. REG_WR(bp, bnx2x_blocks_parity_data[i].mask_addr,
  609. dis_mask);
  610. DP(NETIF_MSG_HW, "Setting parity mask "
  611. "for %s to\t\t0x%x\n",
  612. bnx2x_blocks_parity_data[i].name, dis_mask);
  613. }
  614. }
  615. /* Disable MCP parity attentions */
  616. bnx2x_set_mcp_parity(bp, false);
  617. }
  618. /* Clear the parity error status registers. */
  619. static inline void bnx2x_clear_blocks_parity(struct bnx2x *bp)
  620. {
  621. int i;
  622. u32 reg_val, mcp_aeu_bits =
  623. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY |
  624. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY |
  625. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY |
  626. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY;
  627. /* Clear SEM_FAST parities */
  628. REG_WR(bp, XSEM_REG_FAST_MEMORY + SEM_FAST_REG_PARITY_RST, 0x1);
  629. REG_WR(bp, TSEM_REG_FAST_MEMORY + SEM_FAST_REG_PARITY_RST, 0x1);
  630. REG_WR(bp, USEM_REG_FAST_MEMORY + SEM_FAST_REG_PARITY_RST, 0x1);
  631. REG_WR(bp, CSEM_REG_FAST_MEMORY + SEM_FAST_REG_PARITY_RST, 0x1);
  632. for (i = 0; i < ARRAY_SIZE(bnx2x_blocks_parity_data); i++) {
  633. u32 reg_mask = bnx2x_parity_reg_mask(bp, i);
  634. if (reg_mask) {
  635. reg_val = REG_RD(bp, bnx2x_blocks_parity_data[i].
  636. sts_clr_addr);
  637. if (reg_val & reg_mask)
  638. DP(NETIF_MSG_HW,
  639. "Parity errors in %s: 0x%x\n",
  640. bnx2x_blocks_parity_data[i].name,
  641. reg_val & reg_mask);
  642. }
  643. }
  644. /* Check if there were parity attentions in MCP */
  645. reg_val = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_MCP);
  646. if (reg_val & mcp_aeu_bits)
  647. DP(NETIF_MSG_HW, "Parity error in MCP: 0x%x\n",
  648. reg_val & mcp_aeu_bits);
  649. /* Clear parity attentions in MCP:
  650. * [7] clears Latched rom_parity
  651. * [8] clears Latched ump_rx_parity
  652. * [9] clears Latched ump_tx_parity
  653. * [10] clears Latched scpad_parity (both ports)
  654. */
  655. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x780);
  656. }
  657. static inline void bnx2x_enable_blocks_parity(struct bnx2x *bp)
  658. {
  659. int i;
  660. for (i = 0; i < ARRAY_SIZE(bnx2x_blocks_parity_data); i++) {
  661. u32 reg_mask = bnx2x_parity_reg_mask(bp, i);
  662. if (reg_mask)
  663. REG_WR(bp, bnx2x_blocks_parity_data[i].mask_addr,
  664. bnx2x_blocks_parity_data[i].en_mask & reg_mask);
  665. }
  666. /* Enable MCP parity attentions */
  667. bnx2x_set_mcp_parity(bp, true);
  668. }
  669. #endif /* BNX2X_INIT_H */