]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/octeon-sdk/octeon-feature.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / octeon-sdk / octeon-feature.h
1 /***********************license start***************
2  * Copyright (c) 2003-2010  Cavium Networks (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 Networks 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  NETWORKS 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
57 extern "C" {
58 #endif
59
60 typedef enum
61 {
62     OCTEON_FEATURE_SAAD,        /**<  Octeon models in the CN5XXX family and higher support atomic add instructions to memory (saa/saad) */
63     OCTEON_FEATURE_ZIP,         /**<  Does this Octeon support the ZIP offload engine? */
64     OCTEON_FEATURE_CRYPTO,      /**<  Does this Octeon support crypto acceleration using COP2? */
65     OCTEON_FEATURE_DORM_CRYPTO, /**<  Can crypto be enabled by calling cvmx_crypto_dormant_enable()? */
66     OCTEON_FEATURE_PCIE,        /**<  Does this Octeon support PCI express? */
67     OCTEON_FEATURE_SRIO,        /**<  Does this Octeon support SRIOs */
68     OCTEON_FEATURE_KEY_MEMORY,  /**<  Some Octeon models support internal memory for storing cryptographic keys */
69     OCTEON_FEATURE_LED_CONTROLLER, /**<  Octeon has a LED controller for banks of external LEDs */
70     OCTEON_FEATURE_TRA,         /**<  Octeon has a trace buffer */
71     OCTEON_FEATURE_MGMT_PORT,   /**<  Octeon has a management port */
72     OCTEON_FEATURE_RAID,        /**<  Octeon has a raid unit */
73     OCTEON_FEATURE_USB,         /**<  Octeon has a builtin USB */
74     OCTEON_FEATURE_NO_WPTR,     /**<  Octeon IPD can run without using work queue entries */
75     OCTEON_FEATURE_DFA,         /**<  Octeon has DFA state machines */
76     OCTEON_FEATURE_MDIO_CLAUSE_45,     /**<  Octeon MDIO block supports clause 45 transactions for 10 Gig support */
77     OCTEON_FEATURE_NPEI,        /**<  CN52XX and CN56XX used a block named NPEI for PCIe access. Newer chips replaced this with SLI+DPI */
78 } octeon_feature_t;
79
80 /**
81  * Determine if the current Octeon supports a specific feature. These
82  * checks have been optimized to be fairly quick, but they should still
83  * be kept out of fast path code.
84  *
85  * @param feature Feature to check for. This should always be a constant so the
86  *                compiler can remove the switch statement through optimization.
87  *
88  * @return Non zero if the feature exists. Zero if the feature does not
89  *         exist.
90  */
91 static inline int octeon_has_feature(octeon_feature_t feature)
92 {
93     switch (feature)
94     {
95         case OCTEON_FEATURE_SAAD:
96             return !OCTEON_IS_MODEL(OCTEON_CN3XXX);
97
98         case OCTEON_FEATURE_ZIP:
99             if (OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN50XX) || OCTEON_IS_MODEL(OCTEON_CN52XX))
100                 return 0;
101             else
102                 return !cvmx_fuse_read(121);
103
104         case OCTEON_FEATURE_CRYPTO:
105             if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
106                 cvmx_mio_fus_dat2_t fus_2;
107                 fus_2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
108                 if (fus_2.s.nocrypto || fus_2.s.nomul) {
109                     return 0;
110                 } else if (!fus_2.s.dorm_crypto) {
111                     return 1;
112                 } else {
113                     cvmx_rnm_ctl_status_t st;
114                     st.u64 = cvmx_read_csr(CVMX_RNM_CTL_STATUS);
115                     return st.s.eer_val;
116                 }
117             } else {
118                 return !cvmx_fuse_read(90);
119             }
120
121         case OCTEON_FEATURE_DORM_CRYPTO:
122             if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
123                 cvmx_mio_fus_dat2_t fus_2;
124                 fus_2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
125                 return !fus_2.s.nocrypto && !fus_2.s.nomul && fus_2.s.dorm_crypto;
126             } else {
127                 return 0;
128             }
129
130         case OCTEON_FEATURE_PCIE:
131             return (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN6XXX));
132
133         case OCTEON_FEATURE_SRIO:
134             return (OCTEON_IS_MODEL(OCTEON_CN6XXX));
135
136         case OCTEON_FEATURE_KEY_MEMORY:
137             return OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN6XXX);
138
139         case OCTEON_FEATURE_LED_CONTROLLER:
140             return OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN56XX);
141
142         case OCTEON_FEATURE_TRA:
143             return !(OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN50XX));
144         case OCTEON_FEATURE_MGMT_PORT:
145             return OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN6XXX);
146
147         case OCTEON_FEATURE_RAID:
148             return OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN6XXX);
149
150         case OCTEON_FEATURE_USB:
151             return !(OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX));
152
153         case OCTEON_FEATURE_NO_WPTR:
154             return (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN6XXX)) &&
155                     !OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X) && !OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X);
156
157         case OCTEON_FEATURE_DFA:
158             if (!OCTEON_IS_MODEL(OCTEON_CN38XX) && !OCTEON_IS_MODEL(OCTEON_CN31XX) && !OCTEON_IS_MODEL(OCTEON_CN58XX))
159                 return 0;
160             else if (OCTEON_IS_MODEL(OCTEON_CN3020))
161                 return 0;
162             else
163                 return !cvmx_fuse_read(120);
164
165         case OCTEON_FEATURE_MDIO_CLAUSE_45:
166             return !(OCTEON_IS_MODEL(OCTEON_CN3XXX) || OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN50XX));
167
168         case OCTEON_FEATURE_NPEI:
169             return (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX));
170     }
171     return 0;
172 }
173
174 #ifdef  __cplusplus
175 }
176 #endif
177
178 #endif    /* __OCTEON_FEATURE_H__ */