162306a36Sopenharmony_ci/***********************license start***************
262306a36Sopenharmony_ci * Author: Cavium Networks
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Contact: support@caviumnetworks.com
562306a36Sopenharmony_ci * This file is part of the OCTEON SDK
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
1062306a36Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
1162306a36Sopenharmony_ci * published by the Free Software Foundation.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
1462306a36Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
1562306a36Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
1662306a36Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more
1762306a36Sopenharmony_ci * details.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License
2062306a36Sopenharmony_ci * along with this file; if not, write to the Free Software
2162306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2262306a36Sopenharmony_ci * or visit http://www.gnu.org/licenses/.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * This file may also be available under a different license from Cavium.
2562306a36Sopenharmony_ci * Contact Cavium Networks for more information
2662306a36Sopenharmony_ci ***********************license end**************************************/
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * File defining checks for different Octeon features.
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#ifndef __OCTEON_FEATURE_H__
3362306a36Sopenharmony_ci#define __OCTEON_FEATURE_H__
3462306a36Sopenharmony_ci#include <asm/octeon/cvmx-mio-defs.h>
3562306a36Sopenharmony_ci#include <asm/octeon/cvmx-rnm-defs.h>
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cienum octeon_feature {
3862306a36Sopenharmony_ci	/* CN68XX uses port kinds for packet interface */
3962306a36Sopenharmony_ci	OCTEON_FEATURE_PKND,
4062306a36Sopenharmony_ci	/* CN68XX has different fields in word0 - word2 */
4162306a36Sopenharmony_ci	OCTEON_FEATURE_CN68XX_WQE,
4262306a36Sopenharmony_ci	/*
4362306a36Sopenharmony_ci	 * Octeon models in the CN5XXX family and higher support
4462306a36Sopenharmony_ci	 * atomic add instructions to memory (saa/saad).
4562306a36Sopenharmony_ci	 */
4662306a36Sopenharmony_ci	OCTEON_FEATURE_SAAD,
4762306a36Sopenharmony_ci	/* Does this Octeon support the ZIP offload engine? */
4862306a36Sopenharmony_ci	OCTEON_FEATURE_ZIP,
4962306a36Sopenharmony_ci	OCTEON_FEATURE_DORM_CRYPTO,
5062306a36Sopenharmony_ci	/* Does this Octeon support PCI express? */
5162306a36Sopenharmony_ci	OCTEON_FEATURE_PCIE,
5262306a36Sopenharmony_ci	/* Does this Octeon support SRIOs */
5362306a36Sopenharmony_ci	OCTEON_FEATURE_SRIO,
5462306a36Sopenharmony_ci	/*  Does this Octeon support Interlaken */
5562306a36Sopenharmony_ci	OCTEON_FEATURE_ILK,
5662306a36Sopenharmony_ci	/* Some Octeon models support internal memory for storing
5762306a36Sopenharmony_ci	 * cryptographic keys */
5862306a36Sopenharmony_ci	OCTEON_FEATURE_KEY_MEMORY,
5962306a36Sopenharmony_ci	/* Octeon has a LED controller for banks of external LEDs */
6062306a36Sopenharmony_ci	OCTEON_FEATURE_LED_CONTROLLER,
6162306a36Sopenharmony_ci	/* Octeon has a trace buffer */
6262306a36Sopenharmony_ci	OCTEON_FEATURE_TRA,
6362306a36Sopenharmony_ci	/* Octeon has a management port */
6462306a36Sopenharmony_ci	OCTEON_FEATURE_MGMT_PORT,
6562306a36Sopenharmony_ci	/* Octeon has a raid unit */
6662306a36Sopenharmony_ci	OCTEON_FEATURE_RAID,
6762306a36Sopenharmony_ci	/* Octeon has a builtin USB */
6862306a36Sopenharmony_ci	OCTEON_FEATURE_USB,
6962306a36Sopenharmony_ci	/* Octeon IPD can run without using work queue entries */
7062306a36Sopenharmony_ci	OCTEON_FEATURE_NO_WPTR,
7162306a36Sopenharmony_ci	/* Octeon has DFA state machines */
7262306a36Sopenharmony_ci	OCTEON_FEATURE_DFA,
7362306a36Sopenharmony_ci	/* Octeon MDIO block supports clause 45 transactions for 10
7462306a36Sopenharmony_ci	 * Gig support */
7562306a36Sopenharmony_ci	OCTEON_FEATURE_MDIO_CLAUSE_45,
7662306a36Sopenharmony_ci	/*
7762306a36Sopenharmony_ci	 *  CN52XX and CN56XX used a block named NPEI for PCIe
7862306a36Sopenharmony_ci	 *  access. Newer chips replaced this with SLI+DPI.
7962306a36Sopenharmony_ci	 */
8062306a36Sopenharmony_ci	OCTEON_FEATURE_NPEI,
8162306a36Sopenharmony_ci	OCTEON_FEATURE_HFA,
8262306a36Sopenharmony_ci	OCTEON_FEATURE_DFM,
8362306a36Sopenharmony_ci	OCTEON_FEATURE_CIU2,
8462306a36Sopenharmony_ci	OCTEON_FEATURE_CIU3,
8562306a36Sopenharmony_ci	/* Octeon has FPA first seen on 78XX */
8662306a36Sopenharmony_ci	OCTEON_FEATURE_FPA3,
8762306a36Sopenharmony_ci	OCTEON_FEATURE_FAU,
8862306a36Sopenharmony_ci	OCTEON_MAX_FEATURE
8962306a36Sopenharmony_ci};
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_cienum octeon_feature_bits {
9262306a36Sopenharmony_ci	OCTEON_HAS_CRYPTO = 0x0001,	/* Crypto acceleration using COP2 */
9362306a36Sopenharmony_ci};
9462306a36Sopenharmony_ciextern enum octeon_feature_bits __octeon_feature_bits;
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/**
9762306a36Sopenharmony_ci * octeon_has_crypto() - Check if this OCTEON has crypto acceleration support.
9862306a36Sopenharmony_ci *
9962306a36Sopenharmony_ci * Returns: Non-zero if the feature exists. Zero if the feature does not exist.
10062306a36Sopenharmony_ci */
10162306a36Sopenharmony_cistatic inline int octeon_has_crypto(void)
10262306a36Sopenharmony_ci{
10362306a36Sopenharmony_ci	return __octeon_feature_bits & OCTEON_HAS_CRYPTO;
10462306a36Sopenharmony_ci}
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/**
10762306a36Sopenharmony_ci * Determine if the current Octeon supports a specific feature. These
10862306a36Sopenharmony_ci * checks have been optimized to be fairly quick, but they should still
10962306a36Sopenharmony_ci * be kept out of fast path code.
11062306a36Sopenharmony_ci *
11162306a36Sopenharmony_ci * @feature: Feature to check for. This should always be a constant so the
11262306a36Sopenharmony_ci *		  compiler can remove the switch statement through optimization.
11362306a36Sopenharmony_ci *
11462306a36Sopenharmony_ci * Returns Non zero if the feature exists. Zero if the feature does not
11562306a36Sopenharmony_ci *	   exist.
11662306a36Sopenharmony_ci */
11762306a36Sopenharmony_cistatic inline bool octeon_has_feature(enum octeon_feature feature)
11862306a36Sopenharmony_ci{
11962306a36Sopenharmony_ci	switch (feature) {
12062306a36Sopenharmony_ci	case OCTEON_FEATURE_SAAD:
12162306a36Sopenharmony_ci		return !OCTEON_IS_MODEL(OCTEON_CN3XXX);
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci	case OCTEON_FEATURE_DORM_CRYPTO:
12462306a36Sopenharmony_ci		if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
12562306a36Sopenharmony_ci			union cvmx_mio_fus_dat2 fus_2;
12662306a36Sopenharmony_ci			fus_2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
12762306a36Sopenharmony_ci			return !fus_2.s.nocrypto && !fus_2.s.nomul && fus_2.s.dorm_crypto;
12862306a36Sopenharmony_ci		} else {
12962306a36Sopenharmony_ci			return false;
13062306a36Sopenharmony_ci		}
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci	case OCTEON_FEATURE_PCIE:
13362306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN56XX)
13462306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX)
13562306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX)
13662306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN7XXX);
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	case OCTEON_FEATURE_SRIO:
13962306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN63XX)
14062306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN66XX);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci	case OCTEON_FEATURE_ILK:
14362306a36Sopenharmony_ci		return (OCTEON_IS_MODEL(OCTEON_CN68XX));
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci	case OCTEON_FEATURE_KEY_MEMORY:
14662306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN38XX)
14762306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN58XX)
14862306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN56XX)
14962306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX);
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci	case OCTEON_FEATURE_LED_CONTROLLER:
15262306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN38XX)
15362306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN58XX)
15462306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN56XX);
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci	case OCTEON_FEATURE_TRA:
15762306a36Sopenharmony_ci		return !(OCTEON_IS_MODEL(OCTEON_CN30XX)
15862306a36Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN50XX));
15962306a36Sopenharmony_ci	case OCTEON_FEATURE_MGMT_PORT:
16062306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN56XX)
16162306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX)
16262306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX);
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci	case OCTEON_FEATURE_RAID:
16562306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN56XX)
16662306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX)
16762306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX);
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci	case OCTEON_FEATURE_USB:
17062306a36Sopenharmony_ci		return !(OCTEON_IS_MODEL(OCTEON_CN38XX)
17162306a36Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN58XX));
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci	case OCTEON_FEATURE_NO_WPTR:
17462306a36Sopenharmony_ci		return (OCTEON_IS_MODEL(OCTEON_CN56XX)
17562306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX)
17662306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX))
17762306a36Sopenharmony_ci			  && !OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X)
17862306a36Sopenharmony_ci			  && !OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X);
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci	case OCTEON_FEATURE_MDIO_CLAUSE_45:
18162306a36Sopenharmony_ci		return !(OCTEON_IS_MODEL(OCTEON_CN3XXX)
18262306a36Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN58XX)
18362306a36Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN50XX));
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci	case OCTEON_FEATURE_NPEI:
18662306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN56XX)
18762306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX);
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci	case OCTEON_FEATURE_PKND:
19062306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN68XX);
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci	case OCTEON_FEATURE_CN68XX_WQE:
19362306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN68XX);
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci	case OCTEON_FEATURE_CIU2:
19662306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN68XX);
19762306a36Sopenharmony_ci	case OCTEON_FEATURE_CIU3:
19862306a36Sopenharmony_ci	case OCTEON_FEATURE_FPA3:
19962306a36Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN78XX)
20062306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CNF75XX)
20162306a36Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN73XX);
20262306a36Sopenharmony_ci	case OCTEON_FEATURE_FAU:
20362306a36Sopenharmony_ci		return !(OCTEON_IS_MODEL(OCTEON_CN78XX)
20462306a36Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CNF75XX)
20562306a36Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN73XX));
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci	default:
20862306a36Sopenharmony_ci		break;
20962306a36Sopenharmony_ci	}
21062306a36Sopenharmony_ci	return false;
21162306a36Sopenharmony_ci}
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci#endif /* __OCTEON_FEATURE_H__ */
214