0018-haswell-NRI-Add-REUT-I-O-test-library.patch 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. From f4dd460d609276de7cb7db91f145a404451a2301 Mon Sep 17 00:00:00 2001
  2. From: Angel Pons <th3fanbus@gmail.com>
  3. Date: Sun, 8 May 2022 00:11:29 +0200
  4. Subject: [PATCH 18/26] haswell NRI: Add REUT I/O test library
  5. Implement a library to run I/O tests using the REUT hardware.
  6. Change-Id: Id7b207cd0a3989ddd23c88c6b1f0cfa79d2c861f
  7. Signed-off-by: Angel Pons <th3fanbus@gmail.com>
  8. ---
  9. .../intel/haswell/native_raminit/Makefile.inc | 1 +
  10. .../haswell/native_raminit/raminit_native.h | 110 +++
  11. .../haswell/native_raminit/reg_structs.h | 121 +++
  12. .../intel/haswell/native_raminit/testing_io.c | 742 ++++++++++++++++++
  13. .../intel/haswell/registers/mchbar.h | 30 +
  14. 5 files changed, 1004 insertions(+)
  15. create mode 100644 src/northbridge/intel/haswell/native_raminit/testing_io.c
  16. diff --git a/src/northbridge/intel/haswell/native_raminit/Makefile.inc b/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  17. index 8d7d4e4db0..6e1b365602 100644
  18. --- a/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  19. +++ b/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  20. @@ -12,4 +12,5 @@ romstage-y += raminit_native.c
  21. romstage-y += reut.c
  22. romstage-y += setup_wdb.c
  23. romstage-y += spd_bitmunching.c
  24. +romstage-y += testing_io.c
  25. romstage-y += timings_refresh.c
  26. diff --git a/src/northbridge/intel/haswell/native_raminit/raminit_native.h b/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  27. index f29c2ec366..56df36ca8d 100644
  28. --- a/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  29. +++ b/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  30. @@ -58,6 +58,88 @@ enum {
  31. REUT_MODE_NOP = 3, /* Normal operation mode */
  32. };
  33. +/* REUT error counter control */
  34. +enum {
  35. + COUNT_ERRORS_PER_CHANNEL = 0,
  36. + COUNT_ERRORS_PER_LANE = 1,
  37. + COUNT_ERRORS_PER_BYTE_GROUP = 2,
  38. + COUNT_ERRORS_PER_CHUNK = 3,
  39. +};
  40. +
  41. +enum wdb_dq_pattern {
  42. + BASIC_VA = 0,
  43. + SEGMENT_WDB,
  44. + CADB,
  45. + TURN_AROUND,
  46. + LMN_VA,
  47. + TURN_AROUND_WR,
  48. + TURN_AROUND_ODT,
  49. + RD_RD_TA,
  50. + RD_RD_TA_ALL,
  51. +};
  52. +
  53. +enum reut_cmd_pat {
  54. + PAT_WR_RD,
  55. + PAT_WR,
  56. + PAT_RD,
  57. + PAT_RD_WR_TA,
  58. + PAT_WR_RD_TA,
  59. + PAT_ODT_TA,
  60. +};
  61. +
  62. +/* REUT subsequence types (B = Base, O = Offset) */
  63. +enum {
  64. + SUBSEQ_B_RD = 0 << 22,
  65. + SUBSEQ_B_WR = 1 << 22,
  66. + SUBSEQ_B_RD_WR = 2 << 22,
  67. + SUBSEQ_B_WR_RD = 3 << 22,
  68. + SUBSEQ_O_RD = 4 << 22,
  69. + SUBSEQ_O_WR = 5 << 22,
  70. +};
  71. +
  72. +/* REUT mux control */
  73. +enum {
  74. + REUT_MUX_LMN = 0,
  75. + REUT_MUX_BTBUFFER = 1,
  76. + REUT_MUX_LFSR = 2,
  77. +};
  78. +
  79. +/* Increment scale */
  80. +enum {
  81. + SCALE_LOGARITHM = 0,
  82. + SCALE_LINEAR = 1,
  83. +};
  84. +
  85. +enum test_stop {
  86. + NSOE = 0, /* Never stop on error */
  87. + NTHSOE = 1, /* Stop on the nth error (we use n = 1) */
  88. + ABGSOE = 2, /* Stop on all byte groups error */
  89. + ALSOE = 3, /* Stop on all lanes error */
  90. +};
  91. +
  92. +struct wdb_pat {
  93. + uint32_t start_ptr; /* Starting pointer in WDB */
  94. + uint32_t stop_ptr; /* Stopping pointer in WDB */
  95. + uint16_t inc_rate; /* How quickly the WDB walks through cachelines */
  96. + uint8_t dq_pattern; /* DQ pattern to use (see enum wdb_dq_pattern above) */
  97. +};
  98. +
  99. +struct reut_pole {
  100. + uint16_t start;
  101. + uint16_t stop;
  102. + uint16_t order;
  103. + uint32_t inc_rate;
  104. + uint16_t inc_val;
  105. + bool wrap_trigger;
  106. +};
  107. +
  108. +struct reut_box {
  109. + struct reut_pole rank;
  110. + struct reut_pole bank;
  111. + struct reut_pole row;
  112. + struct reut_pole col;
  113. +};
  114. +
  115. enum command_training_iteration {
  116. CT_ITERATION_CLOCK = 0,
  117. CT_ITERATION_CMD_NORTH,
  118. @@ -199,6 +281,10 @@ struct sysinfo {
  119. uint16_t mr1[NUM_CHANNELS][NUM_SLOTRANKS];
  120. uint16_t mr2[NUM_CHANNELS][NUM_SLOTRANKS];
  121. uint16_t mr3[NUM_CHANNELS][NUM_SLOTRANKS];
  122. +
  123. + uint8_t dq_pat;
  124. +
  125. + uint8_t dq_pat_lc;
  126. };
  127. static inline bool is_hsw_ult(void)
  128. @@ -342,6 +428,30 @@ void write_wdb_va_pat(
  129. void program_wdb_lfsr(const struct sysinfo *ctrl, bool cleanup);
  130. void setup_wdb(const struct sysinfo *ctrl);
  131. +void program_seq_addr(uint8_t channel, const struct reut_box *reut_addr, bool log_seq_addr);
  132. +void program_loop_count(const struct sysinfo *ctrl, uint8_t channel, uint8_t lc_exp);
  133. +
  134. +void setup_io_test(
  135. + struct sysinfo *ctrl,
  136. + uint8_t chanmask,
  137. + enum reut_cmd_pat cmd_pat,
  138. + uint16_t num_cl,
  139. + uint8_t lc,
  140. + const struct reut_box *reut_addr,
  141. + enum test_stop soe,
  142. + const struct wdb_pat *pat,
  143. + uint8_t en_cadb,
  144. + uint8_t subseq_wait);
  145. +
  146. +void setup_io_test_cadb(struct sysinfo *ctrl, uint8_t chanmask, uint8_t lc, enum test_stop soe);
  147. +void setup_io_test_basic_va(struct sysinfo *ctrl, uint8_t chm, uint8_t lc, enum test_stop soe);
  148. +void setup_io_test_mpr(struct sysinfo *ctrl, uint8_t chanmask, uint8_t lc, enum test_stop soe);
  149. +
  150. +uint8_t select_reut_ranks(struct sysinfo *ctrl, uint8_t channel, uint8_t rankmask);
  151. +
  152. +void run_mpr_io_test(bool clear_errors);
  153. +uint8_t run_io_test(struct sysinfo *ctrl, uint8_t chanmask, uint8_t dq_pat, bool clear_errors);
  154. +
  155. uint8_t get_rx_bias(const struct sysinfo *ctrl);
  156. uint8_t get_tCWL(uint32_t mem_clock_mhz);
  157. diff --git a/src/northbridge/intel/haswell/native_raminit/reg_structs.h b/src/northbridge/intel/haswell/native_raminit/reg_structs.h
  158. index 7aa8d8c8b2..b943259b91 100644
  159. --- a/src/northbridge/intel/haswell/native_raminit/reg_structs.h
  160. +++ b/src/northbridge/intel/haswell/native_raminit/reg_structs.h
  161. @@ -347,6 +347,54 @@ union reut_pat_cl_mux_lmn_reg {
  162. uint32_t raw;
  163. };
  164. +union reut_err_ctl_reg {
  165. + struct __packed {
  166. + uint32_t stop_on_nth_error : 6; // Bits 5:0
  167. + uint32_t : 6; // Bits 11:6
  168. + uint32_t stop_on_error_control : 2; // Bits 13:12
  169. + uint32_t : 2; // Bits 15:14
  170. + uint32_t selective_err_enable_chunk : 8; // Bits 23:16
  171. + uint32_t selective_err_enable_cacheline : 8; // Bits 31:24
  172. + };
  173. + uint32_t raw;
  174. +};
  175. +
  176. +union reut_pat_cadb_mux_ctrl_reg {
  177. + struct __packed {
  178. + uint32_t mux_0_ctrl : 2; // Bits 1:0
  179. + uint32_t : 2; // Bits 3:2
  180. + uint32_t mux_1_ctrl : 2; // Bits 5:4
  181. + uint32_t : 2; // Bits 7:6
  182. + uint32_t mux_2_ctrl : 2; // Bits 9:8
  183. + uint32_t : 6; // Bits 15:10
  184. + uint32_t sel_mux_0_ctrl : 2; // Bits 17:16
  185. + uint32_t : 2; // Bits 19:18
  186. + uint32_t sel_mux_1_ctrl : 2; // Bits 21:20
  187. + uint32_t : 2; // Bits 23:22
  188. + uint32_t sel_mux_2_ctrl : 2; // Bits 25:24
  189. + uint32_t : 6; // Bits 31:26
  190. + };
  191. + uint32_t raw;
  192. +};
  193. +
  194. +union reut_pat_wdb_cl_mux_cfg_reg {
  195. + struct __packed {
  196. + uint32_t mux_0_control : 2; // Bits 1:0
  197. + uint32_t : 1; // Bits 2:2
  198. + uint32_t mux_1_control : 2; // Bits 4:3
  199. + uint32_t : 1; // Bits 5:5
  200. + uint32_t mux_2_control : 2; // Bits 7:6
  201. + uint32_t : 6; // Bits 13:8
  202. + uint32_t ecc_replace_byte_ctl : 1; // Bits 14:14
  203. + uint32_t ecc_data_source_sel : 1; // Bits 15:15
  204. + uint32_t save_lfsr_seed_rate : 6; // Bits 21:16
  205. + uint32_t : 2; // Bits 23:22
  206. + uint32_t reload_lfsr_seed_rate : 3; // Bits 26:24
  207. + uint32_t : 5; // Bits 31:27
  208. + };
  209. + uint32_t raw;
  210. +};
  211. +
  212. union reut_pat_cadb_prog_reg {
  213. struct __packed {
  214. uint32_t addr : 16; // Bits 15:0
  215. @@ -366,6 +414,19 @@ union reut_pat_cadb_prog_reg {
  216. uint32_t raw32[2];
  217. };
  218. +union reut_pat_wdb_cl_ctrl_reg {
  219. + struct __packed {
  220. + uint32_t inc_rate : 5; // Bits 4:0
  221. + uint32_t inc_scale : 1; // Bits 5:5
  222. + uint32_t : 2; // Bits 7:6
  223. + uint32_t start_ptr : 6; // Bits 13:8
  224. + uint32_t : 2; // Bits 15:14
  225. + uint32_t end_ptr : 6; // Bits 21:16
  226. + uint32_t : 10; // Bits 31:22
  227. + };
  228. + uint32_t raw;
  229. +};
  230. +
  231. union reut_pat_cadb_mrs_reg {
  232. struct __packed {
  233. uint32_t delay_gap : 3; // Bits 2:0
  234. @@ -406,6 +467,66 @@ union reut_seq_cfg_reg {
  235. uint32_t raw32[2];
  236. };
  237. +union reut_seq_base_addr_reg {
  238. + struct __packed {
  239. + uint32_t : 3; // Bits 2:0
  240. + uint32_t col_addr : 8; // Bits 10:3
  241. + uint32_t : 13; // Bits 23:11
  242. + uint32_t row_addr : 16; // Bits 39:24
  243. + uint32_t : 8; // Bits 47:40
  244. + uint32_t bank_addr : 3; // Bits 50:48
  245. + uint32_t : 5; // Bits 55:51
  246. + uint32_t rank_addr : 3; // Bits 58:56
  247. + uint32_t : 5; // Bits 63:59
  248. + };
  249. + uint32_t raw32[2];
  250. + uint64_t raw;
  251. +};
  252. +
  253. +union reut_seq_misc_ctl_reg {
  254. + struct __packed {
  255. + uint32_t col_addr_order : 2; // Bits 1:0
  256. + uint32_t row_addr_order : 2; // Bits 3:2
  257. + uint32_t bank_addr_order : 2; // Bits 5:4
  258. + uint32_t rank_addr_order : 2; // Bits 7:6
  259. + uint32_t : 5; // Bits 12:8
  260. + uint32_t addr_invert_rate : 3; // Bits 15:13
  261. + uint32_t : 4; // Bits 19:16
  262. + uint32_t col_addr_invert_en : 1; // Bits 20:20
  263. + uint32_t row_addr_invert_en : 1; // Bits 21:21
  264. + uint32_t bank_addr_invert_en : 1; // Bits 22:22
  265. + uint32_t rank_addr_invert_en : 1; // Bits 23:23
  266. + uint32_t col_wrap_trigger_en : 1; // Bits 24:24
  267. + uint32_t row_wrap_trigger_en : 1; // Bits 25:25
  268. + uint32_t bank_wrap_trigger_en : 1; // Bits 26:26
  269. + uint32_t rank_wrap_trigger_en : 1; // Bits 27:27
  270. + uint32_t col_wrap_carry_en : 1; // Bits 28:28
  271. + uint32_t row_wrap_carry_en : 1; // Bits 29:29
  272. + uint32_t bank_wrap_carry_en : 1; // Bits 30:30
  273. + uint32_t rank_wrap_carry_en : 1; // Bits 31:31
  274. + };
  275. + uint32_t raw;
  276. +};
  277. +
  278. +union reut_seq_addr_inc_ctl_reg {
  279. + struct __packed {
  280. + uint32_t : 3; // Bits 2:0
  281. + uint32_t col_addr_increment : 8; // Bits 10:3
  282. + uint32_t : 1; // Bits 11:11
  283. + uint32_t col_addr_update : 8; // Bits 19:12
  284. + uint32_t row_addr_increment : 12; // Bits 31:20
  285. + uint32_t row_addr_update : 6; // Bits 37:32
  286. + uint32_t bank_addr_increment : 3; // Bits 40:38
  287. + uint32_t : 3; // Bits 43:41
  288. + uint32_t bank_addr_update : 8; // Bits 53:44
  289. + uint32_t rank_addr_increment : 3; // Bits 54:52
  290. + uint32_t : 1; // Bits 55:55
  291. + uint32_t rank_addr_update : 8; // Bits 63:56
  292. + };
  293. + uint64_t raw;
  294. + uint32_t raw32[2];
  295. +};
  296. +
  297. union reut_seq_ctl_reg {
  298. struct __packed {
  299. uint32_t start_test : 1; // Bits 0:0
  300. diff --git a/src/northbridge/intel/haswell/native_raminit/testing_io.c b/src/northbridge/intel/haswell/native_raminit/testing_io.c
  301. new file mode 100644
  302. index 0000000000..7716fc4285
  303. --- /dev/null
  304. +++ b/src/northbridge/intel/haswell/native_raminit/testing_io.c
  305. @@ -0,0 +1,742 @@
  306. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  307. +
  308. +#include <console/console.h>
  309. +#include <delay.h>
  310. +#include <lib.h>
  311. +#include <northbridge/intel/haswell/haswell.h>
  312. +#include <timer.h>
  313. +#include <types.h>
  314. +
  315. +#include "raminit_native.h"
  316. +
  317. +static void set_cadb_patterns(const uint8_t channel, const uint16_t seeds[NUM_CADB_MUX_SEEDS])
  318. +{
  319. + for (uint8_t i = 0; i < NUM_CADB_MUX_SEEDS; i++)
  320. + mchbar_write32(REUT_ch_PAT_CADB_MUX_x(channel, i), seeds[i]);
  321. +}
  322. +
  323. +static void setup_cadb(
  324. + struct sysinfo *ctrl,
  325. + const uint8_t channel,
  326. + const uint8_t vic_spread,
  327. + const uint8_t vic_bit)
  328. +{
  329. + const bool lmn_en = false;
  330. +
  331. + /*
  332. + * Currently, always start writing at CADB row 0.
  333. + * Could add a start point parameter in the future.
  334. + */
  335. + mchbar_write8(REUT_ch_PAT_CADB_WRITE_PTR(channel), 0);
  336. + const uint8_t num_cadb_rows = 8;
  337. + for (uint8_t row = 0; row < num_cadb_rows; row++) {
  338. + const uint8_t lfsr0 = (row >> 0) & 1;
  339. + const uint8_t lfsr1 = (row >> 1) & 1;
  340. + uint64_t reg64 = 0;
  341. + for (uint8_t bit = 0; bit < 22; bit++) {
  342. + uint8_t bremap;
  343. + if (bit >= 19) {
  344. + /* (bremap in 40 .. 42) => CADB data control */
  345. + bremap = bit + 21;
  346. + } else if (bit >= 16) {
  347. + /* (bremap in 24 .. 26) => CADB data bank */
  348. + bremap = bit + 8;
  349. + } else {
  350. + /* (bremap in 0 .. 15) => CADB data address */
  351. + bremap = bit;
  352. + }
  353. + const uint8_t fine = bit % vic_spread;
  354. + reg64 |= ((uint64_t)(fine == vic_bit ? lfsr0 : lfsr1)) << bremap;
  355. + }
  356. + /*
  357. + * Write row. CADB pointer is auto incremented after every write. This must be
  358. + * a single 64-bit write, otherwise the CADB pointer will auto-increment twice.
  359. + */
  360. + mchbar_write64(REUT_ch_PAT_CADB_PROG(channel), reg64);
  361. + }
  362. + const union reut_pat_cadb_mux_ctrl_reg cadb_mux_ctrl = {
  363. + .mux_0_ctrl = lmn_en ? REUT_MUX_LMN : REUT_MUX_LFSR,
  364. + .mux_1_ctrl = REUT_MUX_LFSR,
  365. + .mux_2_ctrl = REUT_MUX_LFSR,
  366. + };
  367. + mchbar_write32(REUT_ch_PAT_CADB_MUX_CTRL(channel), cadb_mux_ctrl.raw);
  368. + const union reut_pat_cl_mux_lmn_reg cadb_cl_mux_lmn = {
  369. + .en_sweep_freq = 1,
  370. + .l_counter = 1,
  371. + .m_counter = 1,
  372. + .n_counter = 6,
  373. + };
  374. + mchbar_write32(REUT_ch_PAT_CADB_CL_MUX_LMN(channel), cadb_cl_mux_lmn.raw);
  375. + const uint16_t cadb_mux_seeds[NUM_CADB_MUX_SEEDS] = { 0x0ea1, 0xbeef, 0xdead };
  376. + set_cadb_patterns(channel, cadb_mux_seeds);
  377. +}
  378. +
  379. +static uint32_t calc_rate(const uint32_t rate, const uint32_t lim, const uint8_t scale_bit)
  380. +{
  381. + return rate > lim ? log2_ceil(rate - 1) : BIT(scale_bit) | rate;
  382. +}
  383. +
  384. +void program_seq_addr(
  385. + const uint8_t channel,
  386. + const struct reut_box *reut_addr,
  387. + const bool log_seq_addr)
  388. +{
  389. + const int loglevel = log_seq_addr ? BIOS_ERR : BIOS_NEVER;
  390. + const uint32_t div = 8;
  391. + union reut_seq_base_addr_reg reut_seq_addr_start = {
  392. + .col_addr = reut_addr->col.start / div,
  393. + .row_addr = reut_addr->row.start,
  394. + .bank_addr = reut_addr->bank.start,
  395. + .rank_addr = reut_addr->rank.start,
  396. + };
  397. + mchbar_write64(REUT_ch_SEQ_ADDR_START(channel), reut_seq_addr_start.raw);
  398. + reut_seq_addr_start.raw = mchbar_read64(REUT_ch_SEQ_ADDR_START(channel));
  399. + printk(loglevel, "\tStart column: %u\n", reut_seq_addr_start.col_addr);
  400. + printk(loglevel, "\tStart row: %u\n", reut_seq_addr_start.row_addr);
  401. + printk(loglevel, "\tStart bank: %u\n", reut_seq_addr_start.bank_addr);
  402. + printk(loglevel, "\tStart rank: %u\n", reut_seq_addr_start.rank_addr);
  403. + printk(loglevel, "\n");
  404. +
  405. + union reut_seq_base_addr_reg reut_seq_addr_stop = {
  406. + .col_addr = reut_addr->col.stop / div,
  407. + .row_addr = reut_addr->row.stop,
  408. + .bank_addr = reut_addr->bank.stop,
  409. + .rank_addr = reut_addr->rank.stop,
  410. + };
  411. + mchbar_write64(REUT_ch_SEQ_ADDR_WRAP(channel), reut_seq_addr_stop.raw);
  412. + reut_seq_addr_stop.raw = mchbar_read64(REUT_ch_SEQ_ADDR_WRAP(channel));
  413. + printk(loglevel, "\tStop column: %u\n", reut_seq_addr_stop.col_addr);
  414. + printk(loglevel, "\tStop row: %u\n", reut_seq_addr_stop.row_addr);
  415. + printk(loglevel, "\tStop bank: %u\n", reut_seq_addr_stop.bank_addr);
  416. + printk(loglevel, "\tStop rank: %u\n", reut_seq_addr_stop.rank_addr);
  417. + printk(loglevel, "\n");
  418. +
  419. + union reut_seq_misc_ctl_reg reut_seq_misc_ctl = {
  420. + .col_wrap_trigger_en = reut_addr->col.wrap_trigger,
  421. + .row_wrap_trigger_en = reut_addr->row.wrap_trigger,
  422. + .bank_wrap_trigger_en = reut_addr->bank.wrap_trigger,
  423. + .rank_wrap_trigger_en = reut_addr->rank.wrap_trigger,
  424. + };
  425. + mchbar_write32(REUT_ch_SEQ_MISC_CTL(channel), reut_seq_misc_ctl.raw);
  426. + printk(loglevel, "\tWrap column: %u\n", reut_addr->col.wrap_trigger);
  427. + printk(loglevel, "\tWrap row: %u\n", reut_addr->row.wrap_trigger);
  428. + printk(loglevel, "\tWrap bank: %u\n", reut_addr->bank.wrap_trigger);
  429. + printk(loglevel, "\tWrap rank: %u\n", reut_addr->rank.wrap_trigger);
  430. + printk(loglevel, "\n");
  431. +
  432. + union reut_seq_addr_inc_ctl_reg reut_seq_addr_inc_ctl = {
  433. + .col_addr_update = calc_rate(reut_addr->col.inc_rate, 31, 7),
  434. + .row_addr_update = calc_rate(reut_addr->row.inc_rate, 15, 5),
  435. + .bank_addr_update = calc_rate(reut_addr->bank.inc_rate, 31, 7),
  436. + .rank_addr_update = calc_rate(reut_addr->rank.inc_rate, 31, 7),
  437. + .col_addr_increment = reut_addr->col.inc_val,
  438. + .row_addr_increment = reut_addr->row.inc_val,
  439. + .bank_addr_increment = reut_addr->bank.inc_val,
  440. + .rank_addr_increment = reut_addr->rank.inc_val,
  441. + };
  442. + printk(loglevel, "\tUpdRate column: %u\n", reut_addr->col.inc_rate);
  443. + printk(loglevel, "\tUpdRate row: %u\n", reut_addr->row.inc_rate);
  444. + printk(loglevel, "\tUpdRate bank: %u\n", reut_addr->bank.inc_rate);
  445. + printk(loglevel, "\tUpdRate rank: %u\n", reut_addr->rank.inc_rate);
  446. + printk(loglevel, "\n");
  447. + printk(loglevel, "\tUpdRateCR column: %u\n", reut_seq_addr_inc_ctl.col_addr_update);
  448. + printk(loglevel, "\tUpdRateCR row: %u\n", reut_seq_addr_inc_ctl.row_addr_update);
  449. + printk(loglevel, "\tUpdRateCR bank: %u\n", reut_seq_addr_inc_ctl.bank_addr_update);
  450. + printk(loglevel, "\tUpdRateCR rank: %u\n", reut_seq_addr_inc_ctl.rank_addr_update);
  451. + printk(loglevel, "\n");
  452. + printk(loglevel, "\tUpdInc column: %u\n", reut_seq_addr_inc_ctl.col_addr_increment);
  453. + printk(loglevel, "\tUpdInc row: %u\n", reut_seq_addr_inc_ctl.row_addr_increment);
  454. + printk(loglevel, "\tUpdInc bank: %u\n", reut_seq_addr_inc_ctl.bank_addr_increment);
  455. + printk(loglevel, "\tUpdInc rank: %u\n", reut_seq_addr_inc_ctl.rank_addr_increment);
  456. + printk(loglevel, "\n");
  457. + mchbar_write64(REUT_ch_SEQ_ADDR_INC_CTL(channel), reut_seq_addr_inc_ctl.raw);
  458. +}
  459. +
  460. +/*
  461. + * Early steppings take exponential (base 2) loopcount values,
  462. + * but later steppings take linear loopcount values elsewhere.
  463. + * Address the differences in register offset and format here.
  464. + */
  465. +void program_loop_count(const struct sysinfo *ctrl, const uint8_t channel, const uint8_t lc_exp)
  466. +{
  467. + if (ctrl->stepping >= STEPPING_C0) {
  468. + const uint32_t loopcount = lc_exp >= 32 ? 0 : BIT(lc_exp);
  469. + mchbar_write32(HSW_REUT_ch_SEQ_LOOP_COUNT(channel), loopcount);
  470. + } else {
  471. + const uint8_t loopcount = lc_exp >= 32 ? 0 : lc_exp + 1;
  472. + union reut_seq_cfg_reg reut_seq_cfg = {
  473. + .raw = mchbar_read64(REUT_ch_SEQ_CFG(channel)),
  474. + };
  475. + reut_seq_cfg.early_steppings_loop_count = loopcount;
  476. + mchbar_write64(REUT_ch_SEQ_CFG(channel), reut_seq_cfg.raw);
  477. + }
  478. +}
  479. +
  480. +static inline void write_subseq(const uint8_t channel, const uint8_t idx, const uint32_t ssq)
  481. +{
  482. + mchbar_write32(REUT_ch_SUBSEQ_x_CTL(channel, idx), ssq);
  483. +}
  484. +
  485. +static void program_subseq(
  486. + struct sysinfo *const ctrl,
  487. + const uint8_t channel,
  488. + const enum reut_cmd_pat cmd_pat,
  489. + const uint32_t ss_a,
  490. + const uint32_t ss_b)
  491. +{
  492. + switch (cmd_pat) {
  493. + case PAT_WR_RD_TA:
  494. + write_subseq(channel, 0, ss_a | SUBSEQ_B_WR);
  495. + for (uint8_t i = 1; i < 7; i++)
  496. + write_subseq(channel, i, ss_b | SUBSEQ_B_RD_WR);
  497. +
  498. + write_subseq(channel, 7, ss_a | SUBSEQ_B_RD);
  499. + break;
  500. + case PAT_RD_WR_TA:
  501. + write_subseq(channel, 0, ss_b | SUBSEQ_B_WR_RD);
  502. + break;
  503. + case PAT_ODT_TA:
  504. + write_subseq(channel, 0, ss_a | SUBSEQ_B_WR);
  505. + write_subseq(channel, 1, ss_b | SUBSEQ_B_RD_WR);
  506. + write_subseq(channel, 2, ss_a | SUBSEQ_B_RD);
  507. + write_subseq(channel, 3, ss_b | SUBSEQ_B_WR_RD);
  508. + break;
  509. + default:
  510. + write_subseq(channel, 0, ss_a | SUBSEQ_B_WR);
  511. + write_subseq(channel, 1, ss_a | SUBSEQ_B_RD);
  512. + break;
  513. + }
  514. +}
  515. +
  516. +void setup_io_test(
  517. + struct sysinfo *ctrl,
  518. + const uint8_t chanmask,
  519. + const enum reut_cmd_pat cmd_pat,
  520. + const uint16_t num_cl,
  521. + const uint8_t lc,
  522. + const struct reut_box *const reut_addr,
  523. + const enum test_stop soe,
  524. + const struct wdb_pat *const pat,
  525. + const uint8_t en_cadb,
  526. + const uint8_t subseq_wait)
  527. +{
  528. + if (!chanmask)
  529. + die("\n%s: invalid chanmask\n", __func__, chanmask);
  530. +
  531. + /*
  532. + * Prepare variables needed for both channels.
  533. + * Check for the cases where this MUST be 1: when
  534. + * we manually walk through subseq ODT and TA Wr.
  535. + */
  536. + uint8_t lc_exp = MAX(lc - log2_ceil(num_cl), 0);
  537. + if (cmd_pat == PAT_WR_RD_TA || cmd_pat == PAT_ODT_TA)
  538. + lc_exp = 0;
  539. +
  540. + uint8_t num_clcr;
  541. + if (num_cl > 127) {
  542. + /* Assume exponential number */
  543. + num_clcr = log2_ceil(num_cl);
  544. + } else {
  545. + /* Set number of cache lines as linear number */
  546. + num_clcr = num_cl | BIT(7);
  547. + }
  548. +
  549. + const uint16_t num_cl2 = 2 * num_cl;
  550. + uint8_t num_cl2cr;
  551. + if (num_cl2 > 127) {
  552. + /* Assume exponential number */
  553. + num_cl2cr = log2_ceil(num_cl2);
  554. + } else {
  555. + /* Set number of cache lines as linear number */
  556. + num_cl2cr = num_cl2 | BIT(7);
  557. + }
  558. +
  559. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  560. + if (!(chanmask & BIT(channel))) {
  561. + union reut_seq_cfg_reg reut_seq_cfg = {
  562. + .raw = mchbar_read64(REUT_ch_SEQ_CFG(channel)),
  563. + };
  564. + reut_seq_cfg.global_control = 0;
  565. + mchbar_write64(REUT_ch_SEQ_CFG(channel), reut_seq_cfg.raw);
  566. + continue;
  567. + }
  568. +
  569. + /*
  570. + * Program CADB
  571. + */
  572. + mchbar_write8(REUT_ch_MISC_PAT_CADB_CTRL(channel), !!en_cadb);
  573. + if (en_cadb)
  574. + setup_cadb(ctrl, channel, 7, 8);
  575. +
  576. + /*
  577. + * Program sequence
  578. + */
  579. + uint8_t subseq_start = 0;
  580. + uint8_t subseq_end = 0;
  581. + switch (cmd_pat) {
  582. + case PAT_WR_RD:
  583. + subseq_end = 1;
  584. + break;
  585. + case PAT_WR:
  586. + break;
  587. + case PAT_RD:
  588. + subseq_start = 1;
  589. + subseq_end = 1;
  590. + break;
  591. + case PAT_RD_WR_TA:
  592. + break;
  593. + case PAT_WR_RD_TA:
  594. + subseq_end = 7;
  595. + break;
  596. + case PAT_ODT_TA:
  597. + subseq_end = 3;
  598. + break;
  599. + default:
  600. + die("\n%s: Pattern type %u is invalid\n", __func__, cmd_pat);
  601. + }
  602. + const union reut_seq_cfg_reg reut_seq_cfg = {
  603. + .global_control = 1,
  604. + .initialization_mode = REUT_MODE_TEST,
  605. + .subsequence_start_pointer = subseq_start,
  606. + .subsequence_end_pointer = subseq_end,
  607. + .start_test_delay = 2,
  608. + };
  609. + mchbar_write64(REUT_ch_SEQ_CFG(channel), reut_seq_cfg.raw);
  610. + program_loop_count(ctrl, channel, lc_exp);
  611. + mchbar_write32(REUT_ch_SEQ_CTL(channel), (union reut_seq_ctl_reg) {
  612. + .clear_errors = 1,
  613. + }.raw);
  614. +
  615. + /*
  616. + * Program subsequences
  617. + */
  618. + uint32_t subseq_a = 0;
  619. +
  620. + /* Number of cachelines and scale */
  621. + subseq_a |= (num_clcr & 0x00ff) << 0;
  622. + subseq_a |= (subseq_wait & 0x3fff) << 8;
  623. +
  624. + /* Reset current base address to start */
  625. + subseq_a |= BIT(27);
  626. +
  627. + uint32_t subseq_b = 0;
  628. +
  629. + /* Number of cachelines and scale */
  630. + subseq_b |= (num_cl2cr & 0x00ff) << 0;
  631. + subseq_b |= (subseq_wait & 0x3fff) << 8;
  632. +
  633. + /* Reset current base address to start */
  634. + subseq_b |= BIT(27);
  635. +
  636. + program_subseq(ctrl, channel, cmd_pat, subseq_a, subseq_b);
  637. +
  638. + /* Program sequence address */
  639. + program_seq_addr(channel, reut_addr, false);
  640. +
  641. + /* Program WDB */
  642. + const bool is_linear = pat->inc_rate < 32;
  643. + mchbar_write32(REUT_ch_WDB_CL_CTRL(channel), (union reut_pat_wdb_cl_ctrl_reg) {
  644. + .start_ptr = pat->start_ptr,
  645. + .end_ptr = pat->stop_ptr,
  646. + .inc_rate = is_linear ? pat->inc_rate : log2_ceil(pat->inc_rate),
  647. + .inc_scale = is_linear,
  648. + }.raw);
  649. +
  650. + /* Enable LMN in LMN or CADB modes, used to create lots of supply noise */
  651. + const bool use_lmn = pat->dq_pattern == LMN_VA || pat->dq_pattern == CADB;
  652. + union reut_pat_wdb_cl_mux_cfg_reg pat_wdb_cl_mux_cfg = {
  653. + .mux_0_control = use_lmn ? REUT_MUX_LMN : REUT_MUX_LFSR,
  654. + .mux_1_control = REUT_MUX_LFSR,
  655. + .mux_2_control = REUT_MUX_LFSR,
  656. + .ecc_data_source_sel = 1,
  657. + };
  658. +
  659. + /* Program LFSR save/restore, too complex unless everything is power of 2 */
  660. + if (cmd_pat == PAT_ODT_TA || cmd_pat == PAT_WR_RD_TA) {
  661. + pat_wdb_cl_mux_cfg.reload_lfsr_seed_rate = log2_ceil(num_cl) + 1;
  662. + pat_wdb_cl_mux_cfg.save_lfsr_seed_rate = 1;
  663. + }
  664. + mchbar_write32(REUT_ch_PAT_WDB_CL_MUX_CFG(channel), pat_wdb_cl_mux_cfg.raw);
  665. +
  666. + /* Inversion mask is not used */
  667. + mchbar_write32(REUT_ch_PAT_WDB_INV(channel), 0);
  668. +
  669. + /* Program error checking */
  670. + const union reut_err_ctl_reg reut_err_ctl = {
  671. + .selective_err_enable_cacheline = 0xff,
  672. + .selective_err_enable_chunk = 0xff,
  673. + .stop_on_error_control = soe,
  674. + .stop_on_nth_error = 1,
  675. + };
  676. + mchbar_write32(REUT_ch_ERR_CONTROL(channel), reut_err_ctl.raw);
  677. + mchbar_write64(REUT_ch_ERR_DATA_MASK(channel), 0);
  678. + mchbar_write8(REUT_ch_ERR_ECC_MASK(channel), 0);
  679. + }
  680. +
  681. + /* Always do a ZQ short before the beginning of a test */
  682. + reut_issue_zq(ctrl, chanmask, ZQ_SHORT);
  683. +}
  684. +
  685. +void setup_io_test_cadb(
  686. + struct sysinfo *ctrl,
  687. + const uint8_t chanmask,
  688. + const uint8_t lc,
  689. + const enum test_stop soe)
  690. +{
  691. + const struct reut_box reut_addr = {
  692. + .rank = {
  693. + .start = 0,
  694. + .stop = 0,
  695. + .inc_rate = 32,
  696. + .inc_val = 1,
  697. + },
  698. + .bank = {
  699. + .start = 0,
  700. + .stop = 7,
  701. + .inc_rate = 3,
  702. + .inc_val = 1,
  703. + },
  704. + .row = {
  705. + .start = 0,
  706. + .stop = 2047,
  707. + .inc_rate = 3,
  708. + .inc_val = 73,
  709. + },
  710. + .col = {
  711. + .start = 0,
  712. + .stop = 1023,
  713. + .inc_rate = 0,
  714. + .inc_val = 53,
  715. + },
  716. + };
  717. + const struct wdb_pat pattern = {
  718. + .start_ptr = 0,
  719. + .stop_ptr = 9,
  720. + .inc_rate = 4,
  721. + .dq_pattern = CADB,
  722. + };
  723. + setup_io_test(
  724. + ctrl,
  725. + chanmask,
  726. + PAT_WR_RD,
  727. + 128,
  728. + lc,
  729. + &reut_addr,
  730. + soe,
  731. + &pattern,
  732. + 1,
  733. + 0);
  734. +
  735. + ctrl->dq_pat_lc = MAX(lc - 2 - 3, 0) + 1;
  736. + ctrl->dq_pat = CADB;
  737. +}
  738. +
  739. +void setup_io_test_basic_va(
  740. + struct sysinfo *ctrl,
  741. + const uint8_t chanmask,
  742. + const uint8_t lc,
  743. + const enum test_stop soe)
  744. +{
  745. + const uint32_t spread = 8;
  746. + const struct reut_box reut_addr = {
  747. + .rank = {
  748. + .start = 0,
  749. + .stop = 0,
  750. + .inc_rate = 32,
  751. + .inc_val = 1,
  752. + },
  753. + .col = {
  754. + .start = 0,
  755. + .stop = 1023,
  756. + .inc_rate = 0,
  757. + .inc_val = 1,
  758. + },
  759. + };
  760. + const struct wdb_pat pattern = {
  761. + .start_ptr = 0,
  762. + .stop_ptr = spread - 1,
  763. + .inc_rate = 4,
  764. + .dq_pattern = BASIC_VA,
  765. + };
  766. + setup_io_test(
  767. + ctrl,
  768. + chanmask,
  769. + PAT_WR_RD,
  770. + 128,
  771. + lc,
  772. + &reut_addr,
  773. + soe,
  774. + &pattern,
  775. + 0,
  776. + 0);
  777. +
  778. + ctrl->dq_pat_lc = MAX(lc - 8, 0) + 1;
  779. + ctrl->dq_pat = BASIC_VA;
  780. +}
  781. +
  782. +void setup_io_test_mpr(
  783. + struct sysinfo *ctrl,
  784. + const uint8_t chanmask,
  785. + const uint8_t lc,
  786. + const enum test_stop soe)
  787. +{
  788. + const struct reut_box reut_addr_ddr = {
  789. + .rank = {
  790. + .start = 0,
  791. + .stop = 0,
  792. + .inc_rate = 32,
  793. + .inc_val = 1,
  794. + },
  795. + .col = {
  796. + .start = 0,
  797. + .stop = 1023,
  798. + .inc_rate = 0,
  799. + .inc_val = 1,
  800. + },
  801. + };
  802. + const struct reut_box reut_addr_lpddr = {
  803. + .bank = {
  804. + .start = 4,
  805. + .stop = 4,
  806. + .inc_rate = 0,
  807. + .inc_val = 0,
  808. + },
  809. + };
  810. + const struct wdb_pat pattern = {
  811. + .start_ptr = 0,
  812. + .stop_ptr = 9,
  813. + .inc_rate = 4,
  814. + .dq_pattern = BASIC_VA,
  815. + };
  816. + setup_io_test(
  817. + ctrl,
  818. + chanmask,
  819. + PAT_RD,
  820. + 128,
  821. + lc,
  822. + ctrl->lpddr ? &reut_addr_lpddr : &reut_addr_ddr,
  823. + soe,
  824. + &pattern,
  825. + 0,
  826. + 0);
  827. +
  828. + ctrl->dq_pat_lc = 1;
  829. + ctrl->dq_pat = BASIC_VA;
  830. +}
  831. +
  832. +uint8_t select_reut_ranks(struct sysinfo *ctrl, const uint8_t channel, uint8_t rankmask)
  833. +{
  834. + rankmask &= ctrl->rankmap[channel];
  835. +
  836. + uint8_t rank_count = 0;
  837. + uint32_t rank_log_to_phys = 0;
  838. + for (uint8_t rank = 0; rank < NUM_SLOTRANKS; rank++) {
  839. + if (!rank_in_mask(rank, rankmask))
  840. + continue;
  841. +
  842. + rank_log_to_phys |= rank << (4 * rank_count);
  843. + rank_count++;
  844. + }
  845. + mchbar_write32(REUT_ch_RANK_LOG_TO_PHYS(channel), rank_log_to_phys);
  846. +
  847. + union reut_seq_cfg_reg reut_seq_cfg = {
  848. + .raw = mchbar_read64(REUT_ch_SEQ_CFG(channel)),
  849. + };
  850. + if (!rank_count) {
  851. + reut_seq_cfg.global_control = 0;
  852. + mchbar_write64(REUT_ch_SEQ_CFG(channel), reut_seq_cfg.raw);
  853. + return 0;
  854. + }
  855. + union reut_seq_base_addr_reg reut_seq_addr_stop = {
  856. + .raw = mchbar_read64(REUT_ch_SEQ_ADDR_WRAP(channel)),
  857. + };
  858. + reut_seq_addr_stop.rank_addr = rank_count - 1;
  859. + mchbar_write64(REUT_ch_SEQ_ADDR_WRAP(channel), reut_seq_addr_stop.raw);
  860. +
  861. + reut_seq_cfg.global_control = 1;
  862. + mchbar_write64(REUT_ch_SEQ_CFG(channel), reut_seq_cfg.raw);
  863. + return BIT(channel);
  864. +}
  865. +
  866. +void run_mpr_io_test(const bool clear_errors)
  867. +{
  868. + io_reset();
  869. + mchbar_write32(REUT_GLOBAL_CTL, (union reut_seq_ctl_reg) {
  870. + .start_test = 1,
  871. + .clear_errors = clear_errors,
  872. + }.raw);
  873. + tick_delay(2);
  874. + io_reset();
  875. + tick_delay(2);
  876. + mchbar_write32(REUT_GLOBAL_CTL, (union reut_seq_ctl_reg) {
  877. + .stop_test = 1,
  878. + }.raw);
  879. +}
  880. +
  881. +static uint8_t get_num_tests(const uint8_t dq_pat)
  882. +{
  883. + switch (dq_pat) {
  884. + case SEGMENT_WDB: return 4;
  885. + case CADB: return 7;
  886. + case TURN_AROUND_WR: return 8;
  887. + case TURN_AROUND_ODT: return 4;
  888. + case RD_RD_TA: return 2;
  889. + case RD_RD_TA_ALL: return 8;
  890. + default: return 1;
  891. + }
  892. +}
  893. +
  894. +uint8_t run_io_test(
  895. + struct sysinfo *const ctrl,
  896. + const uint8_t chanmask,
  897. + const uint8_t dq_pat,
  898. + const bool clear_errors)
  899. +{
  900. + /* SEGMENT_WDB only runs 4 tests */
  901. + const uint8_t segment_wdb_lc[4] = { 0, 0, 4, 2 };
  902. + const union reut_pat_wdb_cl_ctrl_reg pat_wdb_cl[4] = {
  903. + [0] = {
  904. + .start_ptr = 0,
  905. + .end_ptr = 9,
  906. + .inc_rate = 25,
  907. + .inc_scale = SCALE_LINEAR,
  908. + },
  909. + [1] = {
  910. + .start_ptr = 0,
  911. + .end_ptr = 9,
  912. + .inc_rate = 25,
  913. + .inc_scale = SCALE_LINEAR,
  914. + },
  915. + [2] = {
  916. + .start_ptr = 10,
  917. + .end_ptr = 63,
  918. + .inc_rate = 19,
  919. + .inc_scale = SCALE_LINEAR,
  920. + },
  921. + [3] = {
  922. + .start_ptr = 10,
  923. + .end_ptr = 63,
  924. + .inc_rate = 10,
  925. + .inc_scale = SCALE_LINEAR,
  926. + },
  927. + };
  928. + const bool is_turnaround = dq_pat == RD_RD_TA || dq_pat == RD_RD_TA_ALL;
  929. + const uint8_t num_tests = get_num_tests(dq_pat);
  930. + union tc_bank_rank_a_reg tc_bank_rank_a[NUM_CHANNELS] = { 0 };
  931. + if (is_turnaround) {
  932. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  933. + if (!(chanmask & BIT(channel)))
  934. + continue;
  935. +
  936. + tc_bank_rank_a[channel].raw = ctrl->tc_bankrank_a[channel].raw;
  937. + }
  938. + }
  939. + for (uint8_t t = 0; t < num_tests; t++) {
  940. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  941. + if (!(chanmask & BIT(channel)))
  942. + continue;
  943. +
  944. + if (dq_pat == SEGMENT_WDB) {
  945. + mchbar_write32(REUT_ch_WDB_CL_CTRL(channel), pat_wdb_cl[t].raw);
  946. + /*
  947. + * Skip programming LFSR save/restore. Too complex
  948. + * unless power of 2. Program desired loopcount.
  949. + */
  950. + const uint8_t pat_lc = ctrl->dq_pat_lc + segment_wdb_lc[t];
  951. + program_loop_count(ctrl, channel, pat_lc);
  952. + } else if (dq_pat == CADB) {
  953. + setup_cadb(ctrl, channel, num_tests, t);
  954. + } else if (dq_pat == TURN_AROUND_WR || dq_pat == TURN_AROUND_ODT) {
  955. + union reut_seq_cfg_reg reut_seq_cfg = {
  956. + .raw = mchbar_read64(REUT_ch_SEQ_CFG(channel)),
  957. + };
  958. + reut_seq_cfg.subsequence_start_pointer = t;
  959. + reut_seq_cfg.subsequence_end_pointer = t;
  960. + mchbar_write64(REUT_ch_SEQ_CFG(channel), reut_seq_cfg.raw);
  961. + union reut_seq_addr_inc_ctl_reg addr_inc_ctl = {
  962. + .raw = mchbar_read64(REUT_ch_SEQ_ADDR_INC_CTL(channel)),
  963. + };
  964. + uint8_t ta_inc_rate = 1;
  965. + if (dq_pat == TURN_AROUND_WR && (t == 0 || t == 7))
  966. + ta_inc_rate = 0;
  967. + else if (dq_pat == TURN_AROUND_ODT && (t == 0 || t == 2))
  968. + ta_inc_rate = 0;
  969. +
  970. + /* Program increment rate as linear value */
  971. + addr_inc_ctl.rank_addr_update = BIT(7) | ta_inc_rate;
  972. + addr_inc_ctl.col_addr_update = BIT(7) | ta_inc_rate;
  973. + mchbar_write64(REUT_ch_SEQ_ADDR_INC_CTL(channel),
  974. + addr_inc_ctl.raw);
  975. + } else if (dq_pat == RD_RD_TA) {
  976. + tc_bank_rank_a[channel].tRDRD_sr = (t == 0) ? 4 : 5;
  977. + mchbar_write32(TC_BANK_RANK_A_ch(channel),
  978. + tc_bank_rank_a[channel].raw);
  979. + } else if (dq_pat == RD_RD_TA_ALL) {
  980. + /*
  981. + * Program tRDRD for SR and DR. Run 8 tests, covering
  982. + * tRDRD_sr = 4, 5, 6, 7 and tRDRD_dr = min, +1, +2, +3
  983. + */
  984. + const uint32_t tRDRD_dr = ctrl->tc_bankrank_a[channel].tRDRD_dr;
  985. + tc_bank_rank_a[channel].tRDRD_sr = (t % 4) + 4;
  986. + tc_bank_rank_a[channel].tRDRD_dr = (t % 4) + tRDRD_dr;
  987. + mchbar_write32(TC_BANK_RANK_A_ch(channel),
  988. + tc_bank_rank_a[channel].raw);
  989. +
  990. + /* Program linear rank increment rate */
  991. + union reut_seq_addr_inc_ctl_reg addr_inc_ctl = {
  992. + .raw = mchbar_read64(REUT_ch_SEQ_ADDR_INC_CTL(channel)),
  993. + };
  994. + addr_inc_ctl.rank_addr_update = BIT(7) | (t / 4) ? 0 : 31;
  995. + mchbar_write64(REUT_ch_SEQ_ADDR_INC_CTL(channel),
  996. + addr_inc_ctl.raw);
  997. + }
  998. + }
  999. + bool test_soe = false;
  1000. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  1001. + if (!(chanmask & BIT(channel)))
  1002. + continue;
  1003. +
  1004. + const union reut_err_ctl_reg reut_err_ctl = {
  1005. + .raw = mchbar_read32(REUT_ch_ERR_CONTROL(channel)),
  1006. + };
  1007. + const uint8_t soe = reut_err_ctl.stop_on_error_control;
  1008. + if (soe != NSOE) {
  1009. + test_soe = true;
  1010. + break;
  1011. + }
  1012. + }
  1013. + io_reset();
  1014. + mchbar_write32(REUT_GLOBAL_CTL, (union reut_seq_ctl_reg) {
  1015. + .start_test = 1,
  1016. + .clear_errors = clear_errors && t == 0,
  1017. + }.raw);
  1018. + struct mono_time prev, curr;
  1019. + timer_monotonic_get(&prev);
  1020. + union reut_global_err_reg global_err;
  1021. + do {
  1022. + global_err.raw = mchbar_read32(REUT_GLOBAL_ERR);
  1023. + /** TODO: Clean up this mess **/
  1024. + timer_monotonic_get(&curr);
  1025. + if (mono_time_diff_microseconds(&prev, &curr) > 1000 * 1000) {
  1026. + mchbar_write32(REUT_GLOBAL_CTL, (union reut_seq_ctl_reg) {
  1027. + .stop_test = 1,
  1028. + }.raw);
  1029. + printk(BIOS_ERR, "REUT timed out, ch_done: %x\n",
  1030. + global_err.ch_test_done);
  1031. + break;
  1032. + }
  1033. + } while ((global_err.ch_test_done & chanmask) != chanmask);
  1034. + if (test_soe && global_err.ch_error & chanmask)
  1035. + break;
  1036. + }
  1037. + if (is_turnaround) {
  1038. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  1039. + if (!(chanmask & BIT(channel)))
  1040. + continue;
  1041. +
  1042. + mchbar_write32(TC_BANK_RANK_A_ch(channel),
  1043. + ctrl->tc_bankrank_a[channel].raw);
  1044. + }
  1045. + }
  1046. + return ((union reut_global_err_reg)mchbar_read32(REUT_GLOBAL_ERR)).ch_error;
  1047. +}
  1048. diff --git a/src/northbridge/intel/haswell/registers/mchbar.h b/src/northbridge/intel/haswell/registers/mchbar.h
  1049. index f8408e51a0..817a9f8bf8 100644
  1050. --- a/src/northbridge/intel/haswell/registers/mchbar.h
  1051. +++ b/src/northbridge/intel/haswell/registers/mchbar.h
  1052. @@ -94,20 +94,35 @@
  1053. #define TC_BANK_RANK_D_ch(ch) _MCMAIN_C(0x4014, ch)
  1054. #define SC_ROUNDT_LAT_ch(ch) _MCMAIN_C(0x4024, ch)
  1055. +#define REUT_ch_PAT_WDB_CL_MUX_CFG(ch) _MCMAIN_C(0x4040, ch)
  1056. +
  1057. #define REUT_ch_PAT_WDB_CL_MUX_WR_x(ch, x) _MCMAIN_C_X(0x4048, ch, x) /* x in 0 .. 2 */
  1058. #define REUT_ch_PAT_WDB_CL_MUX_RD_x(ch, x) _MCMAIN_C_X(0x4054, ch, x) /* x in 0 .. 2 */
  1059. #define REUT_ch_PAT_WDB_CL_MUX_LMN(ch) _MCMAIN_C(0x4078, ch)
  1060. +#define REUT_ch_PAT_WDB_INV(ch) _MCMAIN_C(0x4084, ch)
  1061. +
  1062. +#define REUT_ch_ERR_CONTROL(ch) _MCMAIN_C(0x4098, ch)
  1063. +#define REUT_ch_ERR_ECC_MASK(ch) _MCMAIN_C(0x409c, ch)
  1064. +
  1065. #define SC_WR_ADD_DELAY_ch(ch) _MCMAIN_C(0x40d0, ch)
  1066. +#define REUT_ch_ERR_DATA_MASK(ch) _MCMAIN_C(0x40d8, ch)
  1067. +
  1068. #define REUT_ch_MISC_CKE_CTRL(ch) _MCMAIN_C(0x4190, ch)
  1069. +#define REUT_ch_MISC_PAT_CADB_CTRL(ch) _MCMAIN_C(0x4198, ch)
  1070. #define REUT_ch_PAT_CADB_MRS(ch) _MCMAIN_C(0x419c, ch)
  1071. +#define REUT_ch_PAT_CADB_MUX_CTRL(ch) _MCMAIN_C(0x41a0, ch)
  1072. +#define REUT_ch_PAT_CADB_MUX_x(ch, x) _MCMAIN_C_X(0x41a4, ch, x) /* x in 0 .. 2 */
  1073. +#define REUT_ch_PAT_CADB_CL_MUX_LMN(ch) _MCMAIN_C(0x41b0, ch)
  1074. #define REUT_ch_PAT_CADB_WRITE_PTR(ch) _MCMAIN_C(0x41bc, ch)
  1075. #define REUT_ch_PAT_CADB_PROG(ch) _MCMAIN_C(0x41c0, ch)
  1076. +#define REUT_ch_WDB_CL_CTRL(ch) _MCMAIN_C(0x4200, ch)
  1077. +
  1078. #define TC_ZQCAL_ch(ch) _MCMAIN_C(0x4290, ch)
  1079. #define TC_RFP_ch(ch) _MCMAIN_C(0x4294, ch)
  1080. #define TC_RFTP_ch(ch) _MCMAIN_C(0x4298, ch)
  1081. @@ -119,12 +134,27 @@
  1082. #define QCLK_ch_LDAT_SDAT(ch) _MCMAIN_C(0x42d4, ch)
  1083. #define QCLK_ch_LDAT_DATA_IN_x(ch, x) _MCMAIN_C_X(0x42dc, ch, x) /* x in 0 .. 1 */
  1084. +#define REUT_GLOBAL_CTL 0x4800
  1085. #define REUT_GLOBAL_ERR 0x4804
  1086. +#define REUT_ch_SUBSEQ_x_CTL(ch, x) (0x4808 + 40 * (ch) + 4 * (x))
  1087. +
  1088. #define REUT_ch_SEQ_CFG(ch) (0x48a8 + 8 * (ch))
  1089. #define REUT_ch_SEQ_CTL(ch) (0x48b8 + 4 * (ch))
  1090. +#define REUT_ch_SEQ_ADDR_START(ch) (0x48d8 + 8 * (ch))
  1091. +
  1092. +#define REUT_ch_SEQ_ADDR_WRAP(ch) (0x48e8 + 8 * (ch))
  1093. +
  1094. +#define REUT_ch_SEQ_MISC_CTL(ch) (0x4908 + 4 * (ch))
  1095. +
  1096. +#define REUT_ch_SEQ_ADDR_INC_CTL(ch) (0x4910 + 8 * (ch))
  1097. +
  1098. +#define REUT_ch_RANK_LOG_TO_PHYS(ch) (0x4930 + 4 * (ch)) /* 4 bits per rank */
  1099. +
  1100. +#define HSW_REUT_ch_SEQ_LOOP_COUNT(ch) (0x4980 + 4 * (ch)) /* *** only on C0 *** */
  1101. +
  1102. /* MCMAIN broadcast */
  1103. #define MCSCHEDS_CBIT 0x4c20
  1104. --
  1105. 2.39.2