summaryrefslogtreecommitdiffstats
path: root/sys/contrib/octeon-sdk/cvmx-csr-db-support.c
blob: 6850c317c857f22a42ae8433f357bd004fe79b68 (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
/***********************license start***************
 * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
 * reserved.
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.

 *   * Neither the name of Cavium Networks nor the names of
 *     its contributors may be used to endorse or promote products
 *     derived from this software without specific prior written
 *     permission.

 * This Software, including technical data, may be subject to U.S. export  control
 * laws, including the U.S. Export Administration Act and its  associated
 * regulations, and may be subject to export or import  regulations in other
 * countries.

 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
 * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 ***********************license end**************************************/







/**
 * @file
 *
 * Utility functions for working with the CSR database
 *
 * <hr>$Revision: 49507 $<hr>
 */
#ifdef CVMX_BUILD_FOR_LINUX_KERNEL
#define PRINTF printk
#include <asm/octeon/cvmx.h>
#include <asm/octeon/cvmx-csr-db.h>
#else
#define PRINTF printf
#include "cvmx.h"
#include "cvmx-csr-db.h"
#endif

/**
 * Figure out which database to use for this chip. The passed
 * identifier can be a processor ID or a PCI ID.
 *
 * @param identifier processor ID or a PCI ID
 *
 * @return index into the csr db
 */
int cvmx_db_get_chipindex(int identifier)
{
    /* First try and see if the identifier is a Processor ID */
    switch (identifier & 0xffff00)
    {
        case 0x000d0600: /* CN50XX */
            return 8;
        case 0x000d0400: /* CN56XX */
            return 7;
        case 0x000d0300: /* CN58XX */
            return 5;
        case 0x000d0000: /* CN38XX */
            return 3;
        case 0x000d0100: /* CN31XX */
            return 1;
        case 0x000d0200: /* CN3010 */
            return 2;
        case 0x000d0700: /* CN52XX */
            return 10;
        case 0x000d9000: /* CN63XX */
            return 11;
    }

    /* Next try PCI device IDs */
    switch (identifier)
    {
        case 0x0003177d: /* CN38XX Pass 1 */
            return 0;
        case 0x0004177d: /* CN38XX Pass 2 */
            return 0;
        case 0x0005177d: /* CN38XX Pass 3 */
            return 3;
        case 0x1001177d: /* Thunder */
            return 3;
        case 0x0020177d: /* CN31XX Pass 1 */
            return 1;
        case 0x0030177d: /* CN30XX Pass 1 */
            return 2;
        case 0x0040177d: /* CN58XX Pass 2 */
            return 5;
        case 0x0050177d: /* CN56XX Pass 2 */
            return 7;
        case 0x0070177d: /* CN50XX Pass 1 */
            return 8;
        case 0x0080177d: /* CN52XX Pass 2 */
            return 10;
        case 0x0090177d: /* CN63XX Pass 1 */
            return 11;
    }

    /* Default to Pass 3 if we don't know */
    return 3;
}


#ifndef CVMX_BUILD_FOR_LINUX_KERNEL
/**
 * Get the CSR DB entry for the passed Octeon model and CSR name. The
 * model can either be specified as a processor id or PCI id.
 *
 * @param identifier Identifer to choose the CSR DB with
 * @param name       CSR name to lookup
 *
 * @return CSR DB entry or NULL on failure
 */
const CVMX_CSR_DB_ADDRESS_TYPE *cvmx_csr_db_get(int identifier, const char *name)
{
    int chip = cvmx_db_get_chipindex(identifier);
    int i=0;
    if (strncasecmp(name, "CVMX_", 5) == 0)
        name += 5;
    while (cvmx_csr_db_addresses[chip][i].name)
    {
        if (strcasecmp(name, cvmx_csr_db_addresses[chip][i].name) == 0)
            return &(cvmx_csr_db_addresses[chip][i]);
        i++;
    }
    return NULL;
}
#endif

static void __cvmx_csr_db_decode_csr(int chip, int index, uint64_t value)
{
    int field;
    int csr = cvmx_csr_db_addresses[chip][index].csroff;
    PRINTF("%s(0x%016llx) = 0x%016llx\n", cvmx_csr_db_addresses[chip][index].name, (unsigned long long)cvmx_csr_db_addresses[chip][index].address, (unsigned long long)value);
    for (field=cvmx_csr_db[chip][csr].fieldoff+cvmx_csr_db[chip][csr].numfields-1; field>=cvmx_csr_db[chip][csr].fieldoff; field--)
    {
        uint64_t v = (value >> cvmx_csr_db_fields[chip][field].startbit);
        if(cvmx_csr_db_fields[chip][field].sizebits < 64)
            v = v & ~((~0x0ull) << cvmx_csr_db_fields[chip][field].sizebits);
        if (cvmx_csr_db_fields[chip][field].sizebits == 1)
            PRINTF("  [   %2d] %-20s = %10llu (0x%llx)\n",
                cvmx_csr_db_fields[chip][field].startbit, cvmx_csr_db_fields[chip][field].name,
                (unsigned long long)v, (unsigned long long)v);
        else
            PRINTF("  [%2d:%2d] %-20s = %10llu (0x%llx)\n",
                cvmx_csr_db_fields[chip][field].startbit + cvmx_csr_db_fields[chip][field].sizebits - 1,
                cvmx_csr_db_fields[chip][field].startbit,
                cvmx_csr_db_fields[chip][field].name,
                (unsigned long long)v, (unsigned long long)v);
    }
}

/**
 * Decode a CSR value into named bitfields. The model can either
 * be specified as a processor id or PCI id.
 *
 * @param identifier Identifer to choose the CSR DB with
 * @param address    CSR address being decoded
 * @param value      Value to decode
 */
void cvmx_csr_db_decode(int identifier, uint64_t address, uint64_t value)
{
    int chip = cvmx_db_get_chipindex(identifier);
    int index=0;
    /* Strip off the upper 8 bits since they are normally mips addressing
        modes */
    address &= (1ull<<56)-1;
    while (cvmx_csr_db_addresses[chip][index].name)
    {
        if (cvmx_csr_db_addresses[chip][index].address == address)
            __cvmx_csr_db_decode_csr(chip, index, value);
        index++;
    }
}

/**
 * Decode a CSR value into named bitfields. The model can either
 * be specified as a processor id or PCI id.
 *
 * @param identifier Identifer to choose the CSR DB with
 * @param name       CSR name to decode
 * @param value      Value to decode
 */
void cvmx_csr_db_decode_by_name(int identifier, const char *name, uint64_t value)
{
    int chip = cvmx_db_get_chipindex(identifier);
    int index=0;
    while (cvmx_csr_db_addresses[chip][index].name)
    {
        if (strcasecmp(name, cvmx_csr_db_addresses[chip][index].name) == 0)
        {
            __cvmx_csr_db_decode_csr(chip, index, value);
            break;
        }
        index++;
    }
}


#ifndef CVMX_BUILD_FOR_LINUX_KERNEL
/**
 * Print a list of csrs begimning with a prefix. The
 * model can either be specified as a processor id or PCI id.
 *
 * @param identifier Identifer to choose the CSR DB with
 * @param prefix     Beginning prefix to look for
 */
void cvmx_csr_db_display_list(int identifier, const char *prefix)
{
    int i, len;
    int chip = cvmx_db_get_chipindex(identifier);
    if (prefix == NULL)
        prefix = "";
    if (strncasecmp(prefix, "CVMX_", 5) == 0)
        prefix += 5;
    len = strlen(prefix);

    i=0;
    while (cvmx_csr_db_addresses[chip][i].name)
    {
        if (strncasecmp(prefix, cvmx_csr_db_addresses[chip][i].name, len) == 0)
            PRINTF("%s\n", cvmx_csr_db_addresses[chip][i].name);
        i++;
    }
}
#endif
OpenPOWER on IntegriCloud