bnx2x_init.h 22 KB

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