Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
/*
* Store these as signed since there are comparisons with
* signed numbers.
*/
uint32_t bit_chk;
uint32_t sticky_bit_chk;
int32_t left_edge[RW_MGR_MEM_DQ_PER_READ_DQS];
int32_t right_edge[RW_MGR_MEM_DQ_PER_READ_DQS];
int32_t final_dq[RW_MGR_MEM_DQ_PER_READ_DQS];
int32_t mid;
int32_t orig_mid_min, mid_min;
int32_t new_dqs, start_dqs, start_dqs_en, shift_dq, final_dqs,
final_dqs_en;
int32_t dq_margin, dqs_margin;
uint32_t stop;
uint32_t temp_dq_in_delay1, temp_dq_in_delay2;
uint32_t addr;
debug("%s:%d: %u %u", __func__, __LINE__, read_group, test_bgn);
addr = sdr_get_addr((u32 *)SCC_MGR_DQS_IN_DELAY);
start_dqs = readl(SOCFPGA_SDR_ADDRESS + addr + (read_group << 2));
if (IO_SHIFT_DQS_EN_WHEN_SHIFT_DQS)
start_dqs_en = readl(SOCFPGA_SDR_ADDRESS + addr + ((read_group << 2)
- IO_DQS_EN_DELAY_OFFSET));
/* set the left and right edge of each bit to an illegal value */
/* use (IO_IO_IN_DELAY_MAX + 1) as an illegal value */
sticky_bit_chk = 0;
for (i = 0; i < RW_MGR_MEM_DQ_PER_READ_DQS; i++) {
left_edge[i] = IO_IO_IN_DELAY_MAX + 1;
right_edge[i] = IO_IO_IN_DELAY_MAX + 1;
}
addr = (u32)&sdr_scc_mgr->update;
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
/* Search for the left edge of the window for each bit */
for (d = 0; d <= IO_IO_IN_DELAY_MAX; d++) {
scc_mgr_apply_group_dq_in_delay(write_group, test_bgn, d);
writel(0, SOCFPGA_SDR_ADDRESS + addr);
/*
* Stop searching when the read test doesn't pass AND when
* we've seen a passing read on every bit.
*/
if (use_read_test) {
stop = !rw_mgr_mem_calibrate_read_test(rank_bgn,
read_group, NUM_READ_PB_TESTS, PASS_ONE_BIT,
&bit_chk, 0, 0);
} else {
rw_mgr_mem_calibrate_write_test(rank_bgn, write_group,
0, PASS_ONE_BIT,
&bit_chk, 0);
bit_chk = bit_chk >> (RW_MGR_MEM_DQ_PER_READ_DQS *
(read_group - (write_group *
RW_MGR_MEM_IF_READ_DQS_WIDTH /
RW_MGR_MEM_IF_WRITE_DQS_WIDTH)));
stop = (bit_chk == 0);
}
sticky_bit_chk = sticky_bit_chk | bit_chk;
stop = stop && (sticky_bit_chk == param->read_correct_mask);
debug_cond(DLEVEL == 2, "%s:%d vfifo_center(left): dtap=%u => %u == %u \
&& %u", __func__, __LINE__, d,
sticky_bit_chk,
param->read_correct_mask, stop);
if (stop == 1) {
break;
} else {
for (i = 0; i < RW_MGR_MEM_DQ_PER_READ_DQS; i++) {
if (bit_chk & 1) {
/* Remember a passing test as the
left_edge */
left_edge[i] = d;
} else {
/* If a left edge has not been seen yet,
then a future passing test will mark
this edge as the right edge */
if (left_edge[i] ==
IO_IO_IN_DELAY_MAX + 1) {
right_edge[i] = -(d + 1);
}
}
bit_chk = bit_chk >> 1;
}
}
}
/* Reset DQ delay chains to 0 */
scc_mgr_apply_group_dq_in_delay(write_group, test_bgn, 0);
sticky_bit_chk = 0;
for (i = RW_MGR_MEM_DQ_PER_READ_DQS - 1;; i--) {
debug_cond(DLEVEL == 2, "%s:%d vfifo_center: left_edge[%u]: \
%d right_edge[%u]: %d\n", __func__, __LINE__,
i, left_edge[i], i, right_edge[i]);
/*
* Check for cases where we haven't found the left edge,
* which makes our assignment of the the right edge invalid.
* Reset it to the illegal value.
*/
if ((left_edge[i] == IO_IO_IN_DELAY_MAX + 1) && (
right_edge[i] != IO_IO_IN_DELAY_MAX + 1)) {
right_edge[i] = IO_IO_IN_DELAY_MAX + 1;
debug_cond(DLEVEL == 2, "%s:%d vfifo_center: reset \
right_edge[%u]: %d\n", __func__, __LINE__,
i, right_edge[i]);
}
/*
* Reset sticky bit (except for bits where we have seen
* both the left and right edge).
*/
sticky_bit_chk = sticky_bit_chk << 1;
if ((left_edge[i] != IO_IO_IN_DELAY_MAX + 1) &&
(right_edge[i] != IO_IO_IN_DELAY_MAX + 1)) {
sticky_bit_chk = sticky_bit_chk | 1;
}
if (i == 0)
break;
}
addr = (u32)&sdr_scc_mgr->update;
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
/* Search for the right edge of the window for each bit */
for (d = 0; d <= IO_DQS_IN_DELAY_MAX - start_dqs; d++) {
scc_mgr_set_dqs_bus_in_delay(read_group, d + start_dqs);
if (IO_SHIFT_DQS_EN_WHEN_SHIFT_DQS) {
uint32_t delay = d + start_dqs_en;
if (delay > IO_DQS_EN_DELAY_MAX)
delay = IO_DQS_EN_DELAY_MAX;
scc_mgr_set_dqs_en_delay(read_group, delay);
}
scc_mgr_load_dqs(read_group);
writel(0, SOCFPGA_SDR_ADDRESS + addr);
/*
* Stop searching when the read test doesn't pass AND when
* we've seen a passing read on every bit.
*/
if (use_read_test) {
stop = !rw_mgr_mem_calibrate_read_test(rank_bgn,
read_group, NUM_READ_PB_TESTS, PASS_ONE_BIT,
&bit_chk, 0, 0);
} else {
rw_mgr_mem_calibrate_write_test(rank_bgn, write_group,
0, PASS_ONE_BIT,
&bit_chk, 0);
bit_chk = bit_chk >> (RW_MGR_MEM_DQ_PER_READ_DQS *
(read_group - (write_group *
RW_MGR_MEM_IF_READ_DQS_WIDTH /
RW_MGR_MEM_IF_WRITE_DQS_WIDTH)));
stop = (bit_chk == 0);
}
sticky_bit_chk = sticky_bit_chk | bit_chk;
stop = stop && (sticky_bit_chk == param->read_correct_mask);
debug_cond(DLEVEL == 2, "%s:%d vfifo_center(right): dtap=%u => %u == \
%u && %u", __func__, __LINE__, d,
sticky_bit_chk, param->read_correct_mask, stop);
if (stop == 1) {
break;
} else {
for (i = 0; i < RW_MGR_MEM_DQ_PER_READ_DQS; i++) {
if (bit_chk & 1) {
/* Remember a passing test as
the right_edge */
right_edge[i] = d;
} else {
if (d != 0) {
/* If a right edge has not been
seen yet, then a future passing
test will mark this edge as the
left edge */
if (right_edge[i] ==
IO_IO_IN_DELAY_MAX + 1) {
left_edge[i] = -(d + 1);
}
} else {
/* d = 0 failed, but it passed
when testing the left edge,
so it must be marginal,
set it to -1 */
if (right_edge[i] ==
IO_IO_IN_DELAY_MAX + 1 &&
left_edge[i] !=
IO_IO_IN_DELAY_MAX
+ 1) {
right_edge[i] = -1;
}
/* If a right edge has not been
seen yet, then a future passing
test will mark this edge as the
left edge */
else if (right_edge[i] ==
IO_IO_IN_DELAY_MAX +
1) {
left_edge[i] = -(d + 1);
}
}
}
debug_cond(DLEVEL == 2, "%s:%d vfifo_center[r,\
d=%u]: ", __func__, __LINE__, d);
debug_cond(DLEVEL == 2, "bit_chk_test=%d left_edge[%u]: %d ",
(int)(bit_chk & 1), i, left_edge[i]);
debug_cond(DLEVEL == 2, "right_edge[%u]: %d\n", i,
right_edge[i]);
bit_chk = bit_chk >> 1;
}
}
}
/* Check that all bits have a window */
addr = (u32)&sdr_scc_mgr->update;
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
for (i = 0; i < RW_MGR_MEM_DQ_PER_READ_DQS; i++) {
debug_cond(DLEVEL == 2, "%s:%d vfifo_center: left_edge[%u]: \
%d right_edge[%u]: %d", __func__, __LINE__,
i, left_edge[i], i, right_edge[i]);
if ((left_edge[i] == IO_IO_IN_DELAY_MAX + 1) || (right_edge[i]
== IO_IO_IN_DELAY_MAX + 1)) {
/*
* Restore delay chain settings before letting the loop
* in rw_mgr_mem_calibrate_vfifo to retry different
* dqs/ck relationships.
*/
scc_mgr_set_dqs_bus_in_delay(read_group, start_dqs);
if (IO_SHIFT_DQS_EN_WHEN_SHIFT_DQS) {
scc_mgr_set_dqs_en_delay(read_group,
start_dqs_en);
}
scc_mgr_load_dqs(read_group);
writel(0, SOCFPGA_SDR_ADDRESS + addr);
debug_cond(DLEVEL == 1, "%s:%d vfifo_center: failed to \
find edge [%u]: %d %d", __func__, __LINE__,
i, left_edge[i], right_edge[i]);
if (use_read_test) {
set_failing_group_stage(read_group *
RW_MGR_MEM_DQ_PER_READ_DQS + i,
CAL_STAGE_VFIFO,
CAL_SUBSTAGE_VFIFO_CENTER);
} else {
set_failing_group_stage(read_group *
RW_MGR_MEM_DQ_PER_READ_DQS + i,
CAL_STAGE_VFIFO_AFTER_WRITES,
CAL_SUBSTAGE_VFIFO_CENTER);
}
return 0;
}
}
/* Find middle of window for each DQ bit */
mid_min = left_edge[0] - right_edge[0];
min_index = 0;
for (i = 1; i < RW_MGR_MEM_DQ_PER_READ_DQS; i++) {
mid = left_edge[i] - right_edge[i];
if (mid < mid_min) {
mid_min = mid;
min_index = i;
}
}
/*
* -mid_min/2 represents the amount that we need to move DQS.
* If mid_min is odd and positive we'll need to add one to
* make sure the rounding in further calculations is correct
* (always bias to the right), so just add 1 for all positive values.
*/
if (mid_min > 0)
mid_min++;
mid_min = mid_min / 2;
debug_cond(DLEVEL == 1, "%s:%d vfifo_center: mid_min=%d (index=%u)\n",
__func__, __LINE__, mid_min, min_index);
/* Determine the amount we can change DQS (which is -mid_min) */
orig_mid_min = mid_min;
new_dqs = start_dqs - mid_min;
if (new_dqs > IO_DQS_IN_DELAY_MAX)
new_dqs = IO_DQS_IN_DELAY_MAX;
else if (new_dqs < 0)
new_dqs = 0;
mid_min = start_dqs - new_dqs;
debug_cond(DLEVEL == 1, "vfifo_center: new mid_min=%d new_dqs=%d\n",
mid_min, new_dqs);
if (IO_SHIFT_DQS_EN_WHEN_SHIFT_DQS) {
if (start_dqs_en - mid_min > IO_DQS_EN_DELAY_MAX)
mid_min += start_dqs_en - mid_min - IO_DQS_EN_DELAY_MAX;
else if (start_dqs_en - mid_min < 0)
mid_min += start_dqs_en - mid_min;
}
new_dqs = start_dqs - mid_min;
debug_cond(DLEVEL == 1, "vfifo_center: start_dqs=%d start_dqs_en=%d \
new_dqs=%d mid_min=%d\n", start_dqs,
IO_SHIFT_DQS_EN_WHEN_SHIFT_DQS ? start_dqs_en : -1,
new_dqs, mid_min);
/* Initialize data for export structures */
dqs_margin = IO_IO_IN_DELAY_MAX + 1;
dq_margin = IO_IO_IN_DELAY_MAX + 1;
addr = sdr_get_addr((u32 *)SCC_MGR_IO_IN_DELAY);
/* add delay to bring centre of all DQ windows to the same "level" */
for (i = 0, p = test_bgn; i < RW_MGR_MEM_DQ_PER_READ_DQS; i++, p++) {
/* Use values before divide by 2 to reduce round off error */
shift_dq = (left_edge[i] - right_edge[i] -
(left_edge[min_index] - right_edge[min_index]))/2 +
(orig_mid_min - mid_min);
debug_cond(DLEVEL == 2, "vfifo_center: before: \
shift_dq[%u]=%d\n", i, shift_dq);
temp_dq_in_delay1 = readl(SOCFPGA_SDR_ADDRESS + addr + (p << 2));
temp_dq_in_delay2 = readl(SOCFPGA_SDR_ADDRESS + addr + (i << 2));
if (shift_dq + (int32_t)temp_dq_in_delay1 >
(int32_t)IO_IO_IN_DELAY_MAX) {
shift_dq = (int32_t)IO_IO_IN_DELAY_MAX - temp_dq_in_delay2;
} else if (shift_dq + (int32_t)temp_dq_in_delay1 < 0) {
shift_dq = -(int32_t)temp_dq_in_delay1;
}
debug_cond(DLEVEL == 2, "vfifo_center: after: \
shift_dq[%u]=%d\n", i, shift_dq);
final_dq[i] = temp_dq_in_delay1 + shift_dq;
scc_mgr_set_dq_in_delay(write_group, p, final_dq[i]);
scc_mgr_load_dq(p);
debug_cond(DLEVEL == 2, "vfifo_center: margin[%u]=[%d,%d]\n", i,
left_edge[i] - shift_dq + (-mid_min),
right_edge[i] + shift_dq - (-mid_min));
/* To determine values for export structures */
if (left_edge[i] - shift_dq + (-mid_min) < dq_margin)
dq_margin = left_edge[i] - shift_dq + (-mid_min);
if (right_edge[i] + shift_dq - (-mid_min) < dqs_margin)
dqs_margin = right_edge[i] + shift_dq - (-mid_min);
}
final_dqs = new_dqs;
if (IO_SHIFT_DQS_EN_WHEN_SHIFT_DQS)
final_dqs_en = start_dqs_en - mid_min;
/* Move DQS-en */
if (IO_SHIFT_DQS_EN_WHEN_SHIFT_DQS) {
scc_mgr_set_dqs_en_delay(read_group, final_dqs_en);
scc_mgr_load_dqs(read_group);
}
/* Move DQS */
scc_mgr_set_dqs_bus_in_delay(read_group, final_dqs);
scc_mgr_load_dqs(read_group);
debug_cond(DLEVEL == 2, "%s:%d vfifo_center: dq_margin=%d \
dqs_margin=%d", __func__, __LINE__,
dq_margin, dqs_margin);
/*
* Do not remove this line as it makes sure all of our decisions
* have been applied. Apply the update bit.
*/
addr = (u32)&sdr_scc_mgr->update;
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
writel(0, SOCFPGA_SDR_ADDRESS + addr);
return (dq_margin >= 0) && (dqs_margin >= 0);
}
/*
* calibrate the read valid prediction FIFO.
*
* - read valid prediction will consist of finding a good DQS enable phase,
* DQS enable delay, DQS input phase, and DQS input delay.
* - we also do a per-bit deskew on the DQ lines.
*/
static uint32_t rw_mgr_mem_calibrate_vfifo(uint32_t read_group,
uint32_t test_bgn)
{
uint32_t p, d, rank_bgn, sr;
uint32_t dtaps_per_ptap;
uint32_t tmp_delay;
uint32_t bit_chk;
uint32_t grp_calibrated;
uint32_t write_group, write_test_bgn;
uint32_t failed_substage;
debug("%s:%d: %u %u\n", __func__, __LINE__, read_group, test_bgn);
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
/* update info for sims */
reg_file_set_stage(CAL_STAGE_VFIFO);
write_group = read_group;
write_test_bgn = test_bgn;
/* USER Determine number of delay taps for each phase tap */
dtaps_per_ptap = 0;
tmp_delay = 0;
while (tmp_delay < IO_DELAY_PER_OPA_TAP) {
dtaps_per_ptap++;
tmp_delay += IO_DELAY_PER_DQS_EN_DCHAIN_TAP;
}
dtaps_per_ptap--;
tmp_delay = 0;
/* update info for sims */
reg_file_set_group(read_group);
grp_calibrated = 0;
reg_file_set_sub_stage(CAL_SUBSTAGE_GUARANTEED_READ);
failed_substage = CAL_SUBSTAGE_GUARANTEED_READ;
for (d = 0; d <= dtaps_per_ptap && grp_calibrated == 0; d += 2) {
/*
* In RLDRAMX we may be messing the delay of pins in
* the same write group but outside of the current read
* the group, but that's ok because we haven't
* calibrated output side yet.
*/
if (d > 0) {
scc_mgr_apply_group_all_out_delay_add_all_ranks
(write_group, write_test_bgn, d);
}
for (p = 0; p <= IO_DQDQS_OUT_PHASE_MAX && grp_calibrated == 0;
p++) {
/* set a particular dqdqs phase */
scc_mgr_set_dqdqs_output_phase_all_ranks(read_group, p);
debug_cond(DLEVEL == 1, "%s:%d calibrate_vfifo: g=%u \
p=%u d=%u\n", __func__, __LINE__,
read_group, p, d);
/*
* Load up the patterns used by read calibration
* using current DQDQS phase.
*/
rw_mgr_mem_calibrate_read_load_patterns(0, 1);
if (!(gbl->phy_debug_mode_flags &
PHY_DEBUG_DISABLE_GUARANTEED_READ)) {
if (!rw_mgr_mem_calibrate_read_test_patterns_all_ranks
(read_group, 1, &bit_chk)) {
debug_cond(DLEVEL == 1, "%s:%d Guaranteed read test failed:",
__func__, __LINE__);
debug_cond(DLEVEL == 1, " g=%u p=%u d=%u\n",
read_group, p, d);
break;
}
}
/* case:56390 */
grp_calibrated = 1;
if (rw_mgr_mem_calibrate_vfifo_find_dqs_en_phase_sweep_dq_in_delay
(write_group, read_group, test_bgn)) {
/*
* USER Read per-bit deskew can be done on a
* per shadow register basis.
*/
for (rank_bgn = 0, sr = 0;
rank_bgn < RW_MGR_MEM_NUMBER_OF_RANKS;
rank_bgn += NUM_RANKS_PER_SHADOW_REG,
++sr) {
/*
* Determine if this set of ranks
* should be skipped entirely.
*/
if (!param->skip_shadow_regs[sr]) {
/*
* If doing read after write
* calibration, do not update
* FOM, now - do it then.
*/
if (!rw_mgr_mem_calibrate_vfifo_center
(rank_bgn, write_group,
read_group, test_bgn, 1, 0)) {
grp_calibrated = 0;
failed_substage =
CAL_SUBSTAGE_VFIFO_CENTER;
}
}
}
} else {
grp_calibrated = 0;
failed_substage = CAL_SUBSTAGE_DQS_EN_PHASE;
}
}
}
if (grp_calibrated == 0) {
set_failing_group_stage(write_group, CAL_STAGE_VFIFO,
failed_substage);
return 0;
}
/*
* Reset the delay chains back to zero if they have moved > 1
* (check for > 1 because loop will increase d even when pass in
* first case).
*/
if (d > 2)
scc_mgr_zero_group(write_group, write_test_bgn, 1);
return 1;
}
/* VFIFO Calibration -- Read Deskew Calibration after write deskew */
static uint32_t rw_mgr_mem_calibrate_vfifo_end(uint32_t read_group,
uint32_t test_bgn)
{
uint32_t rank_bgn, sr;
uint32_t grp_calibrated;
uint32_t write_group;
debug("%s:%d %u %u", __func__, __LINE__, read_group, test_bgn);
/* update info for sims */
reg_file_set_stage(CAL_STAGE_VFIFO_AFTER_WRITES);
reg_file_set_sub_stage(CAL_SUBSTAGE_VFIFO_CENTER);
write_group = read_group;
/* update info for sims */
reg_file_set_group(read_group);
grp_calibrated = 1;
/* Read per-bit deskew can be done on a per shadow register basis */
for (rank_bgn = 0, sr = 0; rank_bgn < RW_MGR_MEM_NUMBER_OF_RANKS;
rank_bgn += NUM_RANKS_PER_SHADOW_REG, ++sr) {
/* Determine if this set of ranks should be skipped entirely */
if (!param->skip_shadow_regs[sr]) {
/* This is the last calibration round, update FOM here */
if (!rw_mgr_mem_calibrate_vfifo_center(rank_bgn,
write_group,
read_group,
test_bgn, 0,
1)) {
grp_calibrated = 0;
}
}
}
if (grp_calibrated == 0) {
set_failing_group_stage(write_group,
CAL_STAGE_VFIFO_AFTER_WRITES,
CAL_SUBSTAGE_VFIFO_CENTER);
return 0;
}
return 1;
}
/* Calibrate LFIFO to find smallest read latency */
static uint32_t rw_mgr_mem_calibrate_lfifo(void)
{
uint32_t found_one;
uint32_t bit_chk;
uint32_t addr;
debug("%s:%d\n", __func__, __LINE__);
/* update info for sims */
reg_file_set_stage(CAL_STAGE_LFIFO);
reg_file_set_sub_stage(CAL_SUBSTAGE_READ_LATENCY);
/* Load up the patterns used by read calibration for all ranks */
rw_mgr_mem_calibrate_read_load_patterns(0, 1);
found_one = 0;
addr = sdr_get_addr(&phy_mgr_cfg->phy_rlat);
do {
writel(gbl->curr_read_lat, SOCFPGA_SDR_ADDRESS + addr);
debug_cond(DLEVEL == 2, "%s:%d lfifo: read_lat=%u",
__func__, __LINE__, gbl->curr_read_lat);
if (!rw_mgr_mem_calibrate_read_test_all_ranks(0,
NUM_READ_TESTS,
PASS_ALL_BITS,
&bit_chk, 1)) {
break;
}
found_one = 1;
/* reduce read latency and see if things are working */
/* correctly */
gbl->curr_read_lat--;
} while (gbl->curr_read_lat > 0);
/* reset the fifos to get pointers to known state */
addr = sdr_get_addr(&phy_mgr_cmd->fifo_reset);
writel(0, SOCFPGA_SDR_ADDRESS + addr);
if (found_one) {
/* add a fudge factor to the read latency that was determined */
gbl->curr_read_lat += 2;
addr = sdr_get_addr(&phy_mgr_cfg->phy_rlat);
writel(gbl->curr_read_lat, SOCFPGA_SDR_ADDRESS + addr);
debug_cond(DLEVEL == 2, "%s:%d lfifo: success: using \
read_lat=%u\n", __func__, __LINE__,
gbl->curr_read_lat);
return 1;
} else {
set_failing_group_stage(0xff, CAL_STAGE_LFIFO,
CAL_SUBSTAGE_READ_LATENCY);
debug_cond(DLEVEL == 2, "%s:%d lfifo: failed at initial \
read_lat=%u\n", __func__, __LINE__,
gbl->curr_read_lat);
return 0;
}
}
/*
* issue write test command.
* two variants are provided. one that just tests a write pattern and
* another that tests datamask functionality.
*/
static void rw_mgr_mem_calibrate_write_test_issue(uint32_t group,
uint32_t test_dm)
{
uint32_t mcc_instruction;
uint32_t quick_write_mode = (((STATIC_CALIB_STEPS) & CALIB_SKIP_WRITES) &&
ENABLE_SUPER_QUICK_CALIBRATION);
uint32_t rw_wl_nop_cycles;
uint32_t addr;
/*
* Set counter and jump addresses for the right
* number of NOP cycles.
* The number of supported NOP cycles can range from -1 to infinity
* Three different cases are handled:
*
* 1. For a number of NOP cycles greater than 0, the RW Mgr looping
* mechanism will be used to insert the right number of NOPs
*
* 2. For a number of NOP cycles equals to 0, the micro-instruction
* issuing the write command will jump straight to the
* micro-instruction that turns on DQS (for DDRx), or outputs write
* data (for RLD), skipping
* the NOP micro-instruction all together
*
* 3. A number of NOP cycles equal to -1 indicates that DQS must be
* turned on in the same micro-instruction that issues the write
* command. Then we need
* to directly jump to the micro-instruction that sends out the data
*
* NOTE: Implementing this mechanism uses 2 RW Mgr jump-counters
* (2 and 3). One jump-counter (0) is used to perform multiple
* write-read operations.
* one counter left to issue this command in "multiple-group" mode
*/
rw_wl_nop_cycles = gbl->rw_wl_nop_cycles;
if (rw_wl_nop_cycles == -1) {
/*
* CNTR 2 - We want to execute the special write operation that
* turns on DQS right away and then skip directly to the
* instruction that sends out the data. We set the counter to a
* large number so that the jump is always taken.
*/
addr = (u32)&sdr_rw_load_mgr_regs->load_cntr2;
writel(0xFF, SOCFPGA_SDR_ADDRESS + addr);
/* CNTR 3 - Not used */
if (test_dm) {
mcc_instruction = RW_MGR_LFSR_WR_RD_DM_BANK_0_WL_1;
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add2;
writel(RW_MGR_LFSR_WR_RD_DM_BANK_0_DATA,
SOCFPGA_SDR_ADDRESS + addr);
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add3;
writel(RW_MGR_LFSR_WR_RD_DM_BANK_0_NOP,
SOCFPGA_SDR_ADDRESS + addr);
} else {
mcc_instruction = RW_MGR_LFSR_WR_RD_BANK_0_WL_1;
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add2;
writel(RW_MGR_LFSR_WR_RD_BANK_0_DATA, SOCFPGA_SDR_ADDRESS + addr);
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add3;
writel(RW_MGR_LFSR_WR_RD_BANK_0_NOP, SOCFPGA_SDR_ADDRESS + addr);
}
} else if (rw_wl_nop_cycles == 0) {
/*
* CNTR 2 - We want to skip the NOP operation and go straight
* to the DQS enable instruction. We set the counter to a large
* number so that the jump is always taken.
*/
addr = (u32)&sdr_rw_load_mgr_regs->load_cntr2;
writel(0xFF, SOCFPGA_SDR_ADDRESS + addr);
/* CNTR 3 - Not used */
if (test_dm) {
mcc_instruction = RW_MGR_LFSR_WR_RD_DM_BANK_0;
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add2;
writel(RW_MGR_LFSR_WR_RD_DM_BANK_0_DQS,
SOCFPGA_SDR_ADDRESS + addr);
} else {
mcc_instruction = RW_MGR_LFSR_WR_RD_BANK_0;
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add2;
writel(RW_MGR_LFSR_WR_RD_BANK_0_DQS, SOCFPGA_SDR_ADDRESS + addr);
}
} else {
/*
* CNTR 2 - In this case we want to execute the next instruction
* and NOT take the jump. So we set the counter to 0. The jump
* address doesn't count.
*/
addr = (u32)&sdr_rw_load_mgr_regs->load_cntr2;
writel(0x0, SOCFPGA_SDR_ADDRESS + addr);
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add2;
writel(0x0, SOCFPGA_SDR_ADDRESS + addr);
/*
* CNTR 3 - Set the nop counter to the number of cycles we
* need to loop for, minus 1.
*/
addr = (u32)&sdr_rw_load_mgr_regs->load_cntr3;
writel(rw_wl_nop_cycles - 1, SOCFPGA_SDR_ADDRESS + addr);
if (test_dm) {
mcc_instruction = RW_MGR_LFSR_WR_RD_DM_BANK_0;
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add3;
writel(RW_MGR_LFSR_WR_RD_DM_BANK_0_NOP, SOCFPGA_SDR_ADDRESS + addr);
} else {
mcc_instruction = RW_MGR_LFSR_WR_RD_BANK_0;
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add3;
writel(RW_MGR_LFSR_WR_RD_BANK_0_NOP, SOCFPGA_SDR_ADDRESS + addr);
}
}
addr = sdr_get_addr((u32 *)RW_MGR_RESET_READ_DATAPATH);
writel(0, SOCFPGA_SDR_ADDRESS + addr);
addr = (u32)&sdr_rw_load_mgr_regs->load_cntr0;
if (quick_write_mode)
writel(0x08, SOCFPGA_SDR_ADDRESS + addr);
else
writel(0x40, SOCFPGA_SDR_ADDRESS + addr);
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add0;
writel(mcc_instruction, SOCFPGA_SDR_ADDRESS + addr);
/*
* CNTR 1 - This is used to ensure enough time elapses
* for read data to come back.
*/
addr = (u32)&sdr_rw_load_mgr_regs->load_cntr1;
writel(0x30, SOCFPGA_SDR_ADDRESS + addr);
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add1;
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
if (test_dm) {
writel(RW_MGR_LFSR_WR_RD_DM_BANK_0_WAIT, SOCFPGA_SDR_ADDRESS + addr);
} else {
writel(RW_MGR_LFSR_WR_RD_BANK_0_WAIT, SOCFPGA_SDR_ADDRESS + addr);
}
addr = sdr_get_addr((u32 *)RW_MGR_RUN_SINGLE_GROUP);
writel(mcc_instruction, SOCFPGA_SDR_ADDRESS + addr + (group << 2));
}
/* Test writes, can check for a single bit pass or multiple bit pass */
static uint32_t rw_mgr_mem_calibrate_write_test(uint32_t rank_bgn,
uint32_t write_group, uint32_t use_dm, uint32_t all_correct,
uint32_t *bit_chk, uint32_t all_ranks)
{
uint32_t addr;
uint32_t r;
uint32_t correct_mask_vg;
uint32_t tmp_bit_chk;
uint32_t vg;
uint32_t rank_end = all_ranks ? RW_MGR_MEM_NUMBER_OF_RANKS :
(rank_bgn + NUM_RANKS_PER_SHADOW_REG);
uint32_t addr_rw_mgr;
uint32_t base_rw_mgr;
*bit_chk = param->write_correct_mask;
correct_mask_vg = param->write_correct_mask_vg;
for (r = rank_bgn; r < rank_end; r++) {
if (param->skip_ranks[r]) {
/* request to skip the rank */
continue;
}
/* set rank */
set_rank_and_odt_mask(r, RW_MGR_ODT_MODE_READ_WRITE);
tmp_bit_chk = 0;
addr = sdr_get_addr(&phy_mgr_cmd->fifo_reset);
addr_rw_mgr = SDR_PHYGRP_RWMGRGRP_ADDRESS;
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
for (vg = RW_MGR_MEM_VIRTUAL_GROUPS_PER_WRITE_DQS-1; ; vg--) {
/* reset the fifos to get pointers to known state */
writel(0, SOCFPGA_SDR_ADDRESS + addr);
tmp_bit_chk = tmp_bit_chk <<
(RW_MGR_MEM_DQ_PER_WRITE_DQS /
RW_MGR_MEM_VIRTUAL_GROUPS_PER_WRITE_DQS);
rw_mgr_mem_calibrate_write_test_issue(write_group *
RW_MGR_MEM_VIRTUAL_GROUPS_PER_WRITE_DQS+vg,
use_dm);
base_rw_mgr = readl(SOCFPGA_SDR_ADDRESS + addr_rw_mgr);
tmp_bit_chk = tmp_bit_chk | (correct_mask_vg & ~(base_rw_mgr));
if (vg == 0)
break;
}
*bit_chk &= tmp_bit_chk;
}
if (all_correct) {
set_rank_and_odt_mask(0, RW_MGR_ODT_MODE_OFF);
debug_cond(DLEVEL == 2, "write_test(%u,%u,ALL) : %u == \
%u => %lu", write_group, use_dm,
*bit_chk, param->write_correct_mask,
(long unsigned int)(*bit_chk ==
param->write_correct_mask));
return *bit_chk == param->write_correct_mask;
} else {
set_rank_and_odt_mask(0, RW_MGR_ODT_MODE_OFF);
debug_cond(DLEVEL == 2, "write_test(%u,%u,ONE) : %u != ",
write_group, use_dm, *bit_chk);
debug_cond(DLEVEL == 2, "%lu" " => %lu", (long unsigned int)0,
(long unsigned int)(*bit_chk != 0));
return *bit_chk != 0x00;
}
}
/*
* center all windows. do per-bit-deskew to possibly increase size of
* certain windows.
*/
static uint32_t rw_mgr_mem_calibrate_writes_center(uint32_t rank_bgn,
uint32_t write_group, uint32_t test_bgn)
{
uint32_t i, p, min_index;
int32_t d;
/*
* Store these as signed since there are comparisons with
* signed numbers.
*/
uint32_t bit_chk;
uint32_t sticky_bit_chk;
int32_t left_edge[RW_MGR_MEM_DQ_PER_WRITE_DQS];
int32_t right_edge[RW_MGR_MEM_DQ_PER_WRITE_DQS];
int32_t mid;
int32_t mid_min, orig_mid_min;
int32_t new_dqs, start_dqs, shift_dq;
int32_t dq_margin, dqs_margin, dm_margin;
uint32_t stop;
uint32_t temp_dq_out1_delay;
uint32_t addr;
debug("%s:%d %u %u", __func__, __LINE__, write_group, test_bgn);
dm_margin = 0;
addr = sdr_get_addr((u32 *)SCC_MGR_IO_OUT1_DELAY);
start_dqs = readl(SOCFPGA_SDR_ADDRESS + addr +
(RW_MGR_MEM_DQ_PER_WRITE_DQS << 2));
/* per-bit deskew */
/*
* set the left and right edge of each bit to an illegal value
* use (IO_IO_OUT1_DELAY_MAX + 1) as an illegal value.
*/
sticky_bit_chk = 0;
for (i = 0; i < RW_MGR_MEM_DQ_PER_WRITE_DQS; i++) {
left_edge[i] = IO_IO_OUT1_DELAY_MAX + 1;
right_edge[i] = IO_IO_OUT1_DELAY_MAX + 1;
}
/* Search for the left edge of the window for each bit */
addr = (u32)&sdr_scc_mgr->update;
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
for (d = 0; d <= IO_IO_OUT1_DELAY_MAX; d++) {
scc_mgr_apply_group_dq_out1_delay(write_group, test_bgn, d);
writel(0, SOCFPGA_SDR_ADDRESS + addr);
/*
* Stop searching when the read test doesn't pass AND when
* we've seen a passing read on every bit.
*/
stop = !rw_mgr_mem_calibrate_write_test(rank_bgn, write_group,
0, PASS_ONE_BIT, &bit_chk, 0);
sticky_bit_chk = sticky_bit_chk | bit_chk;
stop = stop && (sticky_bit_chk == param->write_correct_mask);
debug_cond(DLEVEL == 2, "write_center(left): dtap=%d => %u \
== %u && %u [bit_chk= %u ]\n",
d, sticky_bit_chk, param->write_correct_mask,
stop, bit_chk);
if (stop == 1) {
break;
} else {
for (i = 0; i < RW_MGR_MEM_DQ_PER_WRITE_DQS; i++) {
if (bit_chk & 1) {
/*
* Remember a passing test as the
* left_edge.
*/
left_edge[i] = d;
} else {
/*
* If a left edge has not been seen
* yet, then a future passing test will
* mark this edge as the right edge.
*/
if (left_edge[i] ==
IO_IO_OUT1_DELAY_MAX + 1) {
right_edge[i] = -(d + 1);
}
}
debug_cond(DLEVEL == 2, "write_center[l,d=%d):", d);
debug_cond(DLEVEL == 2, "bit_chk_test=%d left_edge[%u]: %d",
(int)(bit_chk & 1), i, left_edge[i]);
debug_cond(DLEVEL == 2, "right_edge[%u]: %d\n", i,
right_edge[i]);
bit_chk = bit_chk >> 1;
}
}
}
/* Reset DQ delay chains to 0 */
scc_mgr_apply_group_dq_out1_delay(write_group, test_bgn, 0);
sticky_bit_chk = 0;
for (i = RW_MGR_MEM_DQ_PER_WRITE_DQS - 1;; i--) {
debug_cond(DLEVEL == 2, "%s:%d write_center: left_edge[%u]: \
%d right_edge[%u]: %d\n", __func__, __LINE__,
i, left_edge[i], i, right_edge[i]);
/*
* Check for cases where we haven't found the left edge,
* which makes our assignment of the the right edge invalid.
* Reset it to the illegal value.
*/
if ((left_edge[i] == IO_IO_OUT1_DELAY_MAX + 1) &&
(right_edge[i] != IO_IO_OUT1_DELAY_MAX + 1)) {
right_edge[i] = IO_IO_OUT1_DELAY_MAX + 1;
debug_cond(DLEVEL == 2, "%s:%d write_center: reset \
right_edge[%u]: %d\n", __func__, __LINE__,
i, right_edge[i]);
}
/*
* Reset sticky bit (except for bits where we have
* seen the left edge).
*/
sticky_bit_chk = sticky_bit_chk << 1;
if ((left_edge[i] != IO_IO_OUT1_DELAY_MAX + 1))
sticky_bit_chk = sticky_bit_chk | 1;
if (i == 0)
break;
}
/* Search for the right edge of the window for each bit */
addr = (u32)&sdr_scc_mgr->update;
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
for (d = 0; d <= IO_IO_OUT1_DELAY_MAX - start_dqs; d++) {
scc_mgr_apply_group_dqs_io_and_oct_out1(write_group,
d + start_dqs);
writel(0, SOCFPGA_SDR_ADDRESS + addr);
/*
* Stop searching when the read test doesn't pass AND when
* we've seen a passing read on every bit.
*/
stop = !rw_mgr_mem_calibrate_write_test(rank_bgn, write_group,
0, PASS_ONE_BIT, &bit_chk, 0);
sticky_bit_chk = sticky_bit_chk | bit_chk;
stop = stop && (sticky_bit_chk == param->write_correct_mask);
debug_cond(DLEVEL == 2, "write_center (right): dtap=%u => %u == \
%u && %u\n", d, sticky_bit_chk,
param->write_correct_mask, stop);
if (stop == 1) {
if (d == 0) {
for (i = 0; i < RW_MGR_MEM_DQ_PER_WRITE_DQS;
i++) {
/* d = 0 failed, but it passed when
testing the left edge, so it must be
marginal, set it to -1 */
if (right_edge[i] ==
IO_IO_OUT1_DELAY_MAX + 1 &&
left_edge[i] !=
IO_IO_OUT1_DELAY_MAX + 1) {
right_edge[i] = -1;
}
}
}
break;
} else {
for (i = 0; i < RW_MGR_MEM_DQ_PER_WRITE_DQS; i++) {