summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/memory/lib/phy/adr.H
blob: 62884f8bdcdeed0559056b91f47ed0ee46773dbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/phy/adr.H $     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2017                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file adr.H
/// @brief Subroutines for the PHY ADR registers
///
// *HWP HWP Owner: Stephen Glancy <sglancy@us.ibm.com>
// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 3
// *HWP Consumed by: FSP:HB

#ifndef _MSS_ADR_H_
#define _MSS_ADR_H_

#include <fapi2.H>
#include <p9_mc_scom_addresses.H>
#include <p9_mc_scom_addresses_fld.H>

#include <lib/shared/mss_const.H>
#include <generic/memory/lib/utils/scom.H>
#include <lib/utils/mss_pair.H>

namespace mss
{

// I have a dream that the PHY code can be shared among controllers. So, I drive the
// engine from a set of traits. This might be folly. Allow me to dream. BRS

///
/// @class adrTraits
/// @brief a collection of traits associated with the PHY ADR interface
/// @tparam T fapi2::TargetType representing the PHY
///
template< fapi2::TargetType T >
class adrTraits;

///
/// @class adrTraits
/// @brief a collection of traits associated with the Centaur PHY ADR interface
///
template<>
class adrTraits<fapi2::TARGET_TYPE_MBA>
{
};

///
/// @class adrTraits
/// @brief a collection of traits associated with the Nimbus PHY ADR
///
template<>
class adrTraits<fapi2::TARGET_TYPE_MCA>
{
    public:

        enum
        {
            // Each register has two fields. One for the even lane and one for the odd lane.
            ADR_DELAY_EVEN = MCA_DDRPHY_ADR_DELAY0_P0_ADR0_01,
            ADR_DELAY_ODD = MCA_DDRPHY_ADR_DELAY0_P0_ADR0_01_DELAY1,
            ADR_DELAY_LEN = MCA_DDRPHY_ADR_DELAY0_P0_ADR0_01_DELAY1_LEN,

            ADR_IO_FET_SLICE_EN_MAP0_ADR0 = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0,
            ADR_IO_FET_SLICE_EN_MAP1_ADR0 = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR0,
            ADR_IO_FET_SLICE_EN_MAP0_ADR1 = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1,
            ADR_IO_FET_SLICE_EN_MAP1_ADR1 = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR1,
            ADR_IO_FET_SLICE_EN_MAP0_ADR2 = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2,
            ADR_IO_FET_SLICE_EN_MAP1_ADR2 = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR2,
            ADR_IO_FET_SLICE_EN_MAP0_ADR3 = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3,
            ADR_IO_FET_SLICE_EN_MAP1_ADR3 = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR3,
            ADR_IO_FET_SLICE_EN_LANE0_POS = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0_01_SEL0,
            ADR_IO_FET_SLICE_EN_LANE1_POS = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0_01_SEL1,
            ADR_IO_FET_SLICE_EN_LANE2_POS = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0_01_SEL2,
            ADR_IO_FET_SLICE_EN_LANE3_POS = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0_01_SEL3,
            ADR_IO_FET_SLICE_EN_LANE4_POS = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0_01_SEL4,
            ADR_IO_FET_SLICE_EN_LANE5_POS = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0_01_SEL5,
            ADR_IO_FET_SLICE_EN_LANE6_POS = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0_01_SEL6,
            ADR_IO_FET_SLICE_EN_LANE7_POS = MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0_01_SEL7,
            NUM_CLK_LANES = 4,
            NUM_CMD_ADDR_LANES = 23,
            NUM_CNTL_LANES = 10,
            NUM_CSCID_LANES = 7,
        };

        //IO FET slice driver registers, broken up by attribute groupings:
        //  1) CLK
        //  2) ADR
        //  3) CNTL
        //  4) CS/CID
        // The vector contains a pair < register, bit position >
        static constexpr mss::pair<uint64_t, uint64_t> IO_TX_FET_SLICE_CLK_REG[NUM_CLK_LANES]  =
        {
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE3_POS }, //CLK00 P
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE2_POS }, //CLK00 N
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE7_POS }, //CLK01 P
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE6_POS }, //CLK01 N
        };
        static constexpr mss::pair<uint64_t, uint64_t> IO_TX_FET_SLICE_CMD_ADDR_REG[NUM_CMD_ADDR_LANES]  =
        {
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE0_POS }, //ADDR0
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE5_POS }, //ADDR1
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE2_POS }, //ADDR2
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE4_POS }, //ADDR3
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE6_POS }, //ADDR4
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE3_POS }, //ADDR5
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE1_POS }, //ADDR6
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE7_POS }, //ADDR7
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE2_POS }, //ADDR8
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE0_POS }, //ADDR9
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE5_POS }, //ADDR10
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3, ADR_IO_FET_SLICE_EN_LANE1_POS }, //ADDR11
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE3_POS }, //ADDR12
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE0_POS }, //ADDR13
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE1_POS }, //ADDR14/WEN
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE3_POS }, //ADDR15/CAS
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE1_POS }, //ADDR16/RAS
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE4_POS }, //ADDR17/RAS
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE7_POS }, //BA0
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE4_POS }, //BA1
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3, ADR_IO_FET_SLICE_EN_LANE2_POS }, //BG0
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3, ADR_IO_FET_SLICE_EN_LANE5_POS }, //BG1
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3, ADR_IO_FET_SLICE_EN_LANE0_POS }, //ACT_N

        };
        static constexpr mss::pair<uint64_t, uint64_t> IO_TX_FET_SLICE_CNTL_REG[NUM_CNTL_LANES] =
        {
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3, ADR_IO_FET_SLICE_EN_LANE3_POS }, //CKE0
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE2_POS }, //CKE1
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3, ADR_IO_FET_SLICE_EN_LANE6_POS }, //CKE2
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3, ADR_IO_FET_SLICE_EN_LANE4_POS }, //CKE3
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE2_POS }, //ODT0
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE6_POS }, //ODT1
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE1_POS }, //ODT2
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE2_POS }, //ODT3
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE3_POS }, //PARITY
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR3, ADR_IO_FET_SLICE_EN_LANE7_POS }, //RESET_N
        };
        static constexpr mss::pair<uint64_t, uint64_t> IO_TX_FET_SLICE_CSCID_REG[NUM_CSCID_LANES] =
        {
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE0_POS }, //CS0
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE1_POS }, //CS1
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR2, ADR_IO_FET_SLICE_EN_LANE0_POS }, //CS2
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE1_POS }, //CS3
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR0, ADR_IO_FET_SLICE_EN_LANE3_POS }, //CID0
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP0_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE5_POS }, //CID1
            { MCA_DDRPHY_ADR_IO_FET_SLICE_EN_MAP1_P0_ADR1, ADR_IO_FET_SLICE_EN_LANE0_POS }, //CID2
        };
};

///
/// @brief A structure to represent an adr operation
///
struct adr_data
{
    // The register
    uint64_t iv_reg;

    // One function gets the even lanes attribute, the other gets the odd lanes
    fapi2::ReturnCode (*iv_even_func)(const fapi2::Target<fapi2::TARGET_TYPE_MCA>&, uint8_t&);
    fapi2::ReturnCode (*iv_odd_func)(const fapi2::Target<fapi2::TARGET_TYPE_MCA>&, uint8_t&);
};

namespace adr
{

///
/// @brief Reset the ADR Delay Lines
/// @param[in] i_target the fapi2 target of the MCA
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
/// @note reads VPD and resets the delay lines. This is very controller specific, so we have
/// a one function for each controller (er ... but just one now)
///
fapi2::ReturnCode reset_delay( const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target );

//TODO RTC:161327 Change API to use or to have a function parameter version for ADR IO IMP

///
/// @brief sets up the clock driver impedances
/// @tparam T the type of the target in question
/// @param[in] i_target the port in question
/// @return fapi2::ReturnCode, FAPI2_RC_SUCCESS iff no error
///
template< fapi2::TargetType T >
fapi2::ReturnCode reset_imp_clk( const fapi2::Target<T>& i_target );

///
/// @brief Reads the clock output impedance register
/// @tparam I Clock lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_target the fapi2 target of the port
/// @param[out] o_data the value of both of the register
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline fapi2::ReturnCode read_imp_clk( const fapi2::Target<T>& i_target,
                                       fapi2::buffer<uint64_t>& o_data )
{
    static_assert( I < TT::NUM_CLK_LANES, "lane instance out of range");

    //one register per CLK
    FAPI_TRY( mss::getScom(i_target, TT::IO_TX_FET_SLICE_CLK_REG[I].first, o_data) );
    FAPI_INF("%s imp_clk lane<%d>: 0x%016lx", mss::c_str(i_target), I, o_data);

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Writes the clock output impedance register
/// @tparam I Clock lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_target the fapi2 target of the port
/// @param[in] i_data the value of both of the the register
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline fapi2::ReturnCode write_imp_clk( const fapi2::Target<T>& i_target,
                                        const fapi2::buffer<uint64_t>& i_data )
{
    static_assert( I < TT::NUM_CLK_LANES, "lane instance out of range");

    //one register per CLK
    FAPI_INF("%s imp_clk lane<%d>: 0x%016lx", mss::c_str(i_target), I, i_data);
    FAPI_TRY( mss::putScom(i_target, TT::IO_TX_FET_SLICE_CLK_REG[I].first, i_data) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief sets up the command/address driver impedances
/// @tparam T the type of the target in question
/// @param[in] i_target the port in question
/// @return fapi2::ReturnCode, FAPI2_RC_SUCCESS iff no error
///
template< fapi2::TargetType T >
fapi2::ReturnCode reset_imp_cmd_addr( const fapi2::Target<T>& i_target );

///
/// @brief Reads the command/address output impedance register
/// @tparam I Command/Address lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_target the fapi2 target of the port
/// @param[out] o_data the value of both of the register
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline fapi2::ReturnCode read_imp_cmd_addr( const fapi2::Target<T>& i_target,
        fapi2::buffer<uint64_t>& o_data )
{
    static_assert( I < TT::NUM_CMD_ADDR_LANES, "lane instance out of range");

    //one register per CMD/ADDR lane
    FAPI_TRY( mss::getScom(i_target, TT::IO_TX_FET_SLICE_CMD_ADDR_REG[I].first, o_data) );
    FAPI_INF("%s imp_cmd_addr lane<%d>: 0x%016lx", mss::c_str(i_target), I, o_data);

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Writes the command/address output impedance register
/// @tparam I Command/Address lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_target the fapi2 target of the port
/// @param[in] i_data the value of both of the the register
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline fapi2::ReturnCode write_imp_cmd_addr( const fapi2::Target<T>& i_target,
        const fapi2::buffer<uint64_t>& i_data )
{
    static_assert( I < TT::NUM_CMD_ADDR_LANES, "lane instance out of range");

    //one register per CMD/ADDR lane
    FAPI_INF("%s imp_cmd_addr lane<%d>: 0x%016lx", mss::c_str(i_target), I, i_data);
    FAPI_TRY( mss::putScom(i_target, TT::IO_TX_FET_SLICE_CMD_ADDR_REG[I].first, i_data) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief sets up the control driver impedances
/// @tparam T the type of the target in question
/// @param[in] i_target the port in question
/// @return fapi2::ReturnCode, FAPI2_RC_SUCCESS iff no error
///
template< fapi2::TargetType T >
fapi2::ReturnCode reset_imp_cntl( const fapi2::Target<T>& i_target );

///
/// @brief Reads the control output impedance register
/// @tparam I Control lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_target the fapi2 target of the port
/// @param[out] o_data the value of both of the register
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline fapi2::ReturnCode read_imp_cntl( const fapi2::Target<T>& i_target,
                                        fapi2::buffer<uint64_t>& o_data )
{
    static_assert( I < TT::NUM_CNTL_LANES, "lane instance out of range");

    //one register per CNTL
    FAPI_TRY( mss::getScom(i_target, TT::IO_TX_FET_SLICE_CNTL_REG[I].first, o_data) );
    FAPI_INF("%s imp_cntl lane<%d>: 0x%016lx", mss::c_str(i_target), I, o_data);

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Writes the control output impedance register
/// @tparam I Control lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_target the fapi2 target of the port
/// @param[in] i_data the value of both of the the register
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline fapi2::ReturnCode write_imp_cntl( const fapi2::Target<T>& i_target,
        const fapi2::buffer<uint64_t>& i_data )
{
    static_assert( I < TT::NUM_CNTL_LANES, "lane instance out of range");

    //one register per CNTL
    FAPI_INF("%s imp_cntl lane<%d>: 0x%016lx", mss::c_str(i_target), I, i_data);
    FAPI_TRY( mss::putScom(i_target, TT::IO_TX_FET_SLICE_CNTL_REG[I].first, i_data) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief sets up the chip select/chip id driver impedances
/// @tparam T the type of the target in question
/// @param[in] i_target the port in question
/// @return fapi2::ReturnCode, FAPI2_RC_SUCCESS iff no error
///
template< fapi2::TargetType T >
fapi2::ReturnCode reset_imp_cscid( const fapi2::Target<T>& i_target );

///
/// @brief Reads the chip select/chip id output impedance register
/// @tparam I Chip Select/Chip ID lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_target the fapi2 target of the port
/// @param[out] o_data the value of both of the register
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline fapi2::ReturnCode read_imp_cscid( const fapi2::Target<T>& i_target,
        fapi2::buffer<uint64_t>& o_data )
{
    static_assert( I < TT::NUM_CSCID_LANES, "lane instance out of range");

    //one register per CS/CID
    FAPI_TRY( mss::getScom(i_target, TT::IO_TX_FET_SLICE_CSCID_REG[I].first, o_data) );
    FAPI_INF("%s imp_cscid lane<%d>: 0x%016lx", mss::c_str(i_target), I, o_data);

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Writes the chip select/chip id output impedance register
/// @tparam I Chip Select/Chip ID lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_target the fapi2 target of the port
/// @param[in] i_data the value of both of the the register
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline fapi2::ReturnCode write_imp_cscid( const fapi2::Target<T>& i_target,
        const fapi2::buffer<uint64_t>& i_data )
{
    static_assert( I < TT::NUM_CSCID_LANES, "lane instance out of range");

    //one register per CS/CID
    FAPI_INF("%s imp_cscid lane<%d>: 0x%016lx", mss::c_str(i_target), I, i_data);
    FAPI_TRY( mss::putScom(i_target, TT::IO_TX_FET_SLICE_CSCID_REG[I].first, i_data) );

fapi_try_exit:
    return fapi2::current_err;
}

//////////////////////////////////////////
// ADR impedance field access functions //
//////////////////////////////////////////
///
/// @brief Writes the chip select's/chip id's output impedance field
/// @tparam I Chip Select/Chip ID lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in,out] io_data register data to modify
/// @param[in] i_field - field data to change
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline void set_imp_cscid( fapi2::buffer<uint64_t>& io_data,
                           const bool i_field )
{
    static_assert( I < TT::NUM_CSCID_LANES, "lane instance out of range");

    // modifies the data
    io_data.writeBit<TT::IO_TX_FET_SLICE_CSCID_REG[I].second>(i_field);
}

///
/// @brief Reads the chip select's/chip id's output impedance field
/// @tparam I Chip Select/Chip ID lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_data the field data
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline const bool get_imp_cscid( const fapi2::buffer<uint64_t>& i_data )
{
    static_assert( I < TT::NUM_CSCID_LANES, "lane instance out of range");

    // sends the output data
    return i_data.getBit<TT::IO_TX_FET_SLICE_CSCID_REG[I].second>();
}

///
/// @brief Writes the clocks's output impedance field
/// @tparam I Clock lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in,out] io_data register data to modify
/// @param[in] i_field - field data to change
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline void set_imp_clk( fapi2::buffer<uint64_t>& io_data,
                         const bool i_field )
{
    static_assert( I < TT::NUM_CLK_LANES, "lane instance out of range");

    // modifies the data
    io_data.writeBit<TT::IO_TX_FET_SLICE_CLK_REG[I].second>(i_field);
}

///
/// @brief Reads the clock's output impedance field
/// @tparam I Clock lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_data the field data
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline const bool get_imp_clk( const fapi2::buffer<uint64_t>& i_data )
{
    static_assert( I < TT::NUM_CLK_LANES, "lane instance out of range");

    // sends the output data
    return i_data.getBit<TT::IO_TX_FET_SLICE_CLK_REG[I].second>();
}

///
/// @brief Writes the command/address's output impedance field
/// @tparam I Command/Address lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in,out] io_data register data to modify
/// @param[in] i_field - field data to change
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline void set_imp_cmd_addr( fapi2::buffer<uint64_t>& io_data,
                              const bool i_field )
{
    static_assert( I < TT::NUM_CMD_ADDR_LANES, "lane instance out of range");

    // modifies the data
    io_data.writeBit<TT::IO_TX_FET_SLICE_CMD_ADDR_REG[I].second>(i_field);
}

///
/// @brief Reads the command/addresses's output impedance field
/// @tparam I Command/Address lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_data the field data
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline const bool get_imp_cmd_addr( const fapi2::buffer<uint64_t>& i_data )
{
    static_assert( I < TT::NUM_CMD_ADDR_LANES, "lane instance out of range");

    // sends the output data
    return i_data.getBit<TT::IO_TX_FET_SLICE_CMD_ADDR_REG[I].second>();
}

///
/// @brief Writes the control signal's output impedance field
/// @tparam I Control lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in,out] io_data register data to modify
/// @param[in] i_field - field data to change
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline void set_imp_cntl( fapi2::buffer<uint64_t>& io_data,
                          const bool i_field )
{
    static_assert( I < TT::NUM_CNTL_LANES, "lane instance out of range");

    // modifies the data
    io_data.writeBit<TT::IO_TX_FET_SLICE_CNTL_REG[I].second>(i_field);
}

///
/// @brief Reads the control signal's output impedance field
/// @tparam I Control lane instance
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to adrTraits<T>
/// @param[in] i_data the field data
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
template< uint64_t I, fapi2::TargetType T, typename TT = adrTraits<T> >
inline const bool get_imp_cntl( const fapi2::buffer<uint64_t>& i_data )
{
    static_assert( I < TT::NUM_CNTL_LANES, "lane instance out of range");

    // sends the output data
    return i_data.getBit<TT::IO_TX_FET_SLICE_CNTL_REG[I].second>();
}

} // close namespace adr

} // close namespace mss

#endif
OpenPOWER on IntegriCloud