octeon-feature.h revision 242342
1/***********************license start***************
2 * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *
13 *   * Redistributions in binary form must reproduce the above
14 *     copyright notice, this list of conditions and the following
15 *     disclaimer in the documentation and/or other materials provided
16 *     with the distribution.
17
18 *   * Neither the name of Cavium Inc. nor the names of
19 *     its contributors may be used to endorse or promote products
20 *     derived from this software without specific prior written
21 *     permission.
22
23 * This Software, including technical data, may be subject to U.S. export  control
24 * laws, including the U.S. Export Administration Act and its  associated
25 * regulations, and may be subject to export or import  regulations in other
26 * countries.
27
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39
40
41
42
43
44
45/**
46 * @file
47 *
48 * File defining checks for different Octeon features.
49 *
50 * <hr>$Revision: 30468 $<hr>
51 */
52
53#ifndef __OCTEON_FEATURE_H__
54#define __OCTEON_FEATURE_H__
55
56#ifdef	__cplusplus
57extern "C" {
58#endif
59
60/*
61 * Errors
62 */
63typedef enum
64{
65   OCTEON_FEATURE_SUCCESS                = 0,
66   OCTEON_FEATURE_MAP_OVERFLOW           = -1,
67} octeon_feature_result_t;
68
69/*
70 * Octeon models are declared after the macros in octeon-model.h with the
71 * suffix _FEATURE. The individual features are declared with the
72 * _FEATURE_ infix.
73 */
74typedef enum
75{
76    /*
77     * Checks on the critical path are moved to the top (8 positions)
78     * so that the compiler generates one less insn than for the rest
79     * of the checks.
80     */
81    OCTEON_FEATURE_PKND,        /**<  CN68XX uses port kinds for packet interface */
82    OCTEON_FEATURE_CN68XX_WQE,  /**<  CN68XX has different fields in word0 - word2 */
83
84    /*
85     * Features
86     */
87    OCTEON_FEATURE_SAAD,        /**<  Octeon models in the CN5XXX family and higher support atomic add instructions to memory (saa/saad) */
88    OCTEON_FEATURE_ZIP,         /**<  Does this Octeon support the ZIP offload engine? */
89    OCTEON_FEATURE_CRYPTO,      /**<  Does this Octeon support crypto acceleration using COP2? */
90    OCTEON_FEATURE_DORM_CRYPTO, /**<  Can crypto be enabled by calling cvmx_crypto_dormant_enable()? */
91    OCTEON_FEATURE_PCIE,        /**<  Does this Octeon support PCI express? */
92    OCTEON_FEATURE_SRIO,        /**<  Does this Octeon support SRIO */
93    OCTEON_FEATURE_ILK,         /**<  Does this Octeon support Interlaken */
94    OCTEON_FEATURE_KEY_MEMORY,  /**<  Some Octeon models support internal memory for storing cryptographic keys */
95    OCTEON_FEATURE_LED_CONTROLLER, /**<  Octeon has a LED controller for banks of external LEDs */
96    OCTEON_FEATURE_TRA,         /**<  Octeon has a trace buffer */
97    OCTEON_FEATURE_MGMT_PORT,   /**<  Octeon has a management port */
98    OCTEON_FEATURE_RAID,        /**<  Octeon has a raid unit */
99    OCTEON_FEATURE_USB,         /**<  Octeon has a builtin USB */
100    OCTEON_FEATURE_NO_WPTR,     /**<  Octeon IPD can run without using work queue entries */
101    OCTEON_FEATURE_DFA,         /**<  Octeon has DFA state machines */
102    OCTEON_FEATURE_MDIO_CLAUSE_45,     /**<  Octeon MDIO block supports clause 45 transactions for 10 Gig support */
103    OCTEON_FEATURE_NPEI,        /**<  CN52XX and CN56XX used a block named NPEI for PCIe access. Newer chips replaced this with SLI+DPI */
104    OCTEON_FEATURE_HFA,         /**<  Octeon has DFA/HFA */
105    OCTEON_FEATURE_DFM,         /**<  Octeon has DFM */
106    OCTEON_FEATURE_CIU2,        /**<  Octeon has CIU2 */
107    OCTEON_FEATURE_DICI_MODE,   /**<  Octeon has DMA Instruction Completion Interrupt mode */
108    OCTEON_FEATURE_BIT_EXTRACTOR,    /**<  Octeon has Bit Select Extractor schedulor */
109    OCTEON_FEATURE_NAND,        /**<  Octeon has NAND */
110    OCTEON_FEATURE_MMC,         /**<  Octeon has built-in MMC support */
111    OCTEON_MAX_FEATURE
112} octeon_feature_t;
113
114/**
115 * Determine if the current Octeon supports a specific feature. These
116 * checks have been optimized to be fairly quick, but they should still
117 * be kept out of fast path code.
118 *
119 * @param feature Feature to check for. This should always be a constant so the
120 *                compiler can remove the switch statement through optimization.
121 *
122 * @return Non zero if the feature exists. Zero if the feature does not
123 *         exist.
124 *
125 * Note: This was octeon_has_feature before the feature map and is
126 * called only after model-checking is set up in octeon_feature_init().
127 */
128static inline int old_octeon_has_feature(octeon_feature_t feature)
129{
130    switch (feature)
131    {
132        case OCTEON_FEATURE_SAAD:
133            return !OCTEON_IS_MODEL(OCTEON_CN3XXX);
134
135        case OCTEON_FEATURE_ZIP:
136            if (OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN50XX) || OCTEON_IS_MODEL(OCTEON_CN52XX))
137                return 0;
138            else
139                return !cvmx_fuse_read(121);
140
141        case OCTEON_FEATURE_CRYPTO:
142	    if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_MODEL(OCTEON_CNF7XXX)) {
143                cvmx_mio_fus_dat2_t fus_2;
144                fus_2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
145                if (fus_2.s.nocrypto || fus_2.s.nomul) {
146                    return 0;
147                } else if (!fus_2.s.dorm_crypto) {
148                    return 1;
149                } else {
150                    cvmx_rnm_ctl_status_t st;
151                    st.u64 = cvmx_read_csr(CVMX_RNM_CTL_STATUS);
152                    return st.s.eer_val;
153                }
154            } else {
155                return !cvmx_fuse_read(90);
156            }
157
158        case OCTEON_FEATURE_DORM_CRYPTO:
159            if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_MODEL(OCTEON_CNF7XXX)) {
160                cvmx_mio_fus_dat2_t fus_2;
161                fus_2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
162                return !fus_2.s.nocrypto && !fus_2.s.nomul && fus_2.s.dorm_crypto;
163            } else {
164                return 0;
165            }
166
167        case OCTEON_FEATURE_PCIE:
168            return (OCTEON_IS_MODEL(OCTEON_CN56XX)
169                    || OCTEON_IS_MODEL(OCTEON_CN52XX)
170                    || OCTEON_IS_MODEL(OCTEON_CN6XXX)
171                    || OCTEON_IS_MODEL(OCTEON_CNF7XXX));
172
173	case OCTEON_FEATURE_SRIO:
174	    return (OCTEON_IS_MODEL(OCTEON_CN63XX) || OCTEON_IS_MODEL(OCTEON_CN66XX));
175
176	case OCTEON_FEATURE_ILK:
177	    return (OCTEON_IS_MODEL(OCTEON_CN68XX));
178
179        case OCTEON_FEATURE_KEY_MEMORY:
180            return (OCTEON_IS_MODEL(OCTEON_CN38XX)
181                    || OCTEON_IS_MODEL(OCTEON_CN58XX)
182                    || OCTEON_IS_MODEL(OCTEON_CN56XX)
183                    || OCTEON_IS_MODEL(OCTEON_CN6XXX)
184                    || OCTEON_IS_MODEL(OCTEON_CNF7XXX));
185
186        case OCTEON_FEATURE_LED_CONTROLLER:
187            return OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN56XX);
188
189        case OCTEON_FEATURE_TRA:
190            return !(OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN50XX));
191        case OCTEON_FEATURE_MGMT_PORT:
192            return (OCTEON_IS_MODEL(OCTEON_CN56XX)
193                    || OCTEON_IS_MODEL(OCTEON_CN52XX)
194                    || OCTEON_IS_MODEL(OCTEON_CN6XXX));
195
196        case OCTEON_FEATURE_RAID:
197            return OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN6XXX);
198
199        case OCTEON_FEATURE_USB:
200            return !(OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX));
201
202        case OCTEON_FEATURE_NO_WPTR:
203            return ((OCTEON_IS_MODEL(OCTEON_CN56XX)
204                     || OCTEON_IS_MODEL(OCTEON_CN52XX)
205                     || OCTEON_IS_MODEL(OCTEON_CN6XXX)
206                     || OCTEON_IS_MODEL(OCTEON_CNF7XXX))
207                    && !OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X)
208                    && !OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X));
209
210        case OCTEON_FEATURE_DFA:
211            if (!OCTEON_IS_MODEL(OCTEON_CN38XX) && !OCTEON_IS_MODEL(OCTEON_CN31XX) && !OCTEON_IS_MODEL(OCTEON_CN58XX))
212                return 0;
213            else if (OCTEON_IS_MODEL(OCTEON_CN3020))
214                return 0;
215            else
216                return !cvmx_fuse_read(120);
217
218        case OCTEON_FEATURE_HFA:
219            if (!OCTEON_IS_MODEL(OCTEON_CN6XXX))
220                return 0;
221            else
222                return !cvmx_fuse_read(90);
223
224        case OCTEON_FEATURE_DFM:
225            if (!(OCTEON_IS_MODEL(OCTEON_CN63XX) || OCTEON_IS_MODEL(OCTEON_CN66XX)))
226                return 0;
227            else
228                return !cvmx_fuse_read(90);
229
230        case OCTEON_FEATURE_MDIO_CLAUSE_45:
231            return !(OCTEON_IS_MODEL(OCTEON_CN3XXX) || OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN50XX));
232
233        case OCTEON_FEATURE_NPEI:
234            return (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX));
235
236        case OCTEON_FEATURE_PKND:
237            return (OCTEON_IS_MODEL(OCTEON_CN68XX));
238
239        case OCTEON_FEATURE_CN68XX_WQE:
240            return (OCTEON_IS_MODEL(OCTEON_CN68XX));
241
242        case OCTEON_FEATURE_CIU2:
243            return (OCTEON_IS_MODEL(OCTEON_CN68XX));
244
245        case OCTEON_FEATURE_NAND:
246            return (OCTEON_IS_MODEL(OCTEON_CN52XX)
247                    || OCTEON_IS_MODEL(OCTEON_CN63XX)
248                    || OCTEON_IS_MODEL(OCTEON_CN66XX)
249                    || OCTEON_IS_MODEL(OCTEON_CN68XX));
250
251        case OCTEON_FEATURE_DICI_MODE:
252            return (OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X)
253                    || OCTEON_IS_MODEL(OCTEON_CN61XX)
254                    || OCTEON_IS_MODEL(OCTEON_CNF71XX));
255
256        case OCTEON_FEATURE_BIT_EXTRACTOR:
257            return (OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X)
258                    || OCTEON_IS_MODEL(OCTEON_CN61XX)
259                    || OCTEON_IS_MODEL(OCTEON_CNF71XX));
260
261        case OCTEON_FEATURE_MMC:
262            return (OCTEON_IS_MODEL(OCTEON_CN61XX)
263		    || OCTEON_IS_MODEL(OCTEON_CNF71XX));
264        default:
265	    break;
266    }
267    return 0;
268}
269
270/*
271 * bit map for octeon features
272 */
273#define FEATURE_MAP_SIZE	128
274extern uint8_t octeon_feature_map[FEATURE_MAP_SIZE];
275
276/*
277 * Answer ``Is the bit for feature set in the bitmap?''
278 * @param feature
279 * @return 1 when the feature is present and 0 otherwise, -1 in case of error.
280 */
281#if defined(__U_BOOT__) || defined(CVMX_BUILD_FOR_LINUX_HOST) || defined(CVMX_BUILD_FOR_TOOLCHAIN)
282#define octeon_has_feature old_octeon_has_feature
283#else
284#if defined(USE_RUNTIME_MODEL_CHECKS) || (defined(__FreeBSD__) && defined(_KERNEL))
285static inline int octeon_has_feature(octeon_feature_t feature)
286{
287	int byte, bit;
288	byte = feature >> 3;
289	bit = feature & 0x7;
290
291	if (byte >= FEATURE_MAP_SIZE)
292        {
293#ifdef CVMX_BUILD_FOR_LINUX_KERNEL
294            printk("ERROR: octeon_feature_map: Invalid Octeon Feature 0x%x\n", feature);
295#else
296            printf("ERROR: octeon_feature_map: Invalid Octeon Feature 0x%x\n", feature);
297#endif
298            return -1;
299        }
300
301	return (octeon_feature_map[byte] & ((1 << bit))) ? 1 : 0;
302}
303#else
304#define octeon_has_feature old_octeon_has_feature
305#endif
306#endif
307
308/*
309 * initialize octeon_feature_map[]
310 */
311extern void octeon_feature_init(void);
312
313#ifdef	__cplusplus
314}
315#endif
316
317#endif    /* __OCTEON_FEATURE_H__ */
318