18c2ecf20Sopenharmony_ci/***********************license start***************
28c2ecf20Sopenharmony_ci * Author: Cavium Networks
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Contact: support@caviumnetworks.com
58c2ecf20Sopenharmony_ci * This file is part of the OCTEON SDK
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
168c2ecf20Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more
178c2ecf20Sopenharmony_ci * details.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
208c2ecf20Sopenharmony_ci * along with this file; if not, write to the Free Software
218c2ecf20Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
228c2ecf20Sopenharmony_ci * or visit http://www.gnu.org/licenses/.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * This file may also be available under a different license from Cavium.
258c2ecf20Sopenharmony_ci * Contact Cavium Networks for more information
268c2ecf20Sopenharmony_ci ***********************license end**************************************/
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/*
298c2ecf20Sopenharmony_ci * File defining checks for different Octeon features.
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#ifndef __OCTEON_FEATURE_H__
338c2ecf20Sopenharmony_ci#define __OCTEON_FEATURE_H__
348c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-mio-defs.h>
358c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-rnm-defs.h>
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cienum octeon_feature {
388c2ecf20Sopenharmony_ci	/* CN68XX uses port kinds for packet interface */
398c2ecf20Sopenharmony_ci	OCTEON_FEATURE_PKND,
408c2ecf20Sopenharmony_ci	/* CN68XX has different fields in word0 - word2 */
418c2ecf20Sopenharmony_ci	OCTEON_FEATURE_CN68XX_WQE,
428c2ecf20Sopenharmony_ci	/*
438c2ecf20Sopenharmony_ci	 * Octeon models in the CN5XXX family and higher support
448c2ecf20Sopenharmony_ci	 * atomic add instructions to memory (saa/saad).
458c2ecf20Sopenharmony_ci	 */
468c2ecf20Sopenharmony_ci	OCTEON_FEATURE_SAAD,
478c2ecf20Sopenharmony_ci	/* Does this Octeon support the ZIP offload engine? */
488c2ecf20Sopenharmony_ci	OCTEON_FEATURE_ZIP,
498c2ecf20Sopenharmony_ci	OCTEON_FEATURE_DORM_CRYPTO,
508c2ecf20Sopenharmony_ci	/* Does this Octeon support PCI express? */
518c2ecf20Sopenharmony_ci	OCTEON_FEATURE_PCIE,
528c2ecf20Sopenharmony_ci	/* Does this Octeon support SRIOs */
538c2ecf20Sopenharmony_ci	OCTEON_FEATURE_SRIO,
548c2ecf20Sopenharmony_ci	/*  Does this Octeon support Interlaken */
558c2ecf20Sopenharmony_ci	OCTEON_FEATURE_ILK,
568c2ecf20Sopenharmony_ci	/* Some Octeon models support internal memory for storing
578c2ecf20Sopenharmony_ci	 * cryptographic keys */
588c2ecf20Sopenharmony_ci	OCTEON_FEATURE_KEY_MEMORY,
598c2ecf20Sopenharmony_ci	/* Octeon has a LED controller for banks of external LEDs */
608c2ecf20Sopenharmony_ci	OCTEON_FEATURE_LED_CONTROLLER,
618c2ecf20Sopenharmony_ci	/* Octeon has a trace buffer */
628c2ecf20Sopenharmony_ci	OCTEON_FEATURE_TRA,
638c2ecf20Sopenharmony_ci	/* Octeon has a management port */
648c2ecf20Sopenharmony_ci	OCTEON_FEATURE_MGMT_PORT,
658c2ecf20Sopenharmony_ci	/* Octeon has a raid unit */
668c2ecf20Sopenharmony_ci	OCTEON_FEATURE_RAID,
678c2ecf20Sopenharmony_ci	/* Octeon has a builtin USB */
688c2ecf20Sopenharmony_ci	OCTEON_FEATURE_USB,
698c2ecf20Sopenharmony_ci	/* Octeon IPD can run without using work queue entries */
708c2ecf20Sopenharmony_ci	OCTEON_FEATURE_NO_WPTR,
718c2ecf20Sopenharmony_ci	/* Octeon has DFA state machines */
728c2ecf20Sopenharmony_ci	OCTEON_FEATURE_DFA,
738c2ecf20Sopenharmony_ci	/* Octeon MDIO block supports clause 45 transactions for 10
748c2ecf20Sopenharmony_ci	 * Gig support */
758c2ecf20Sopenharmony_ci	OCTEON_FEATURE_MDIO_CLAUSE_45,
768c2ecf20Sopenharmony_ci	/*
778c2ecf20Sopenharmony_ci	 *  CN52XX and CN56XX used a block named NPEI for PCIe
788c2ecf20Sopenharmony_ci	 *  access. Newer chips replaced this with SLI+DPI.
798c2ecf20Sopenharmony_ci	 */
808c2ecf20Sopenharmony_ci	OCTEON_FEATURE_NPEI,
818c2ecf20Sopenharmony_ci	OCTEON_FEATURE_HFA,
828c2ecf20Sopenharmony_ci	OCTEON_FEATURE_DFM,
838c2ecf20Sopenharmony_ci	OCTEON_FEATURE_CIU2,
848c2ecf20Sopenharmony_ci	OCTEON_FEATURE_CIU3,
858c2ecf20Sopenharmony_ci	/* Octeon has FPA first seen on 78XX */
868c2ecf20Sopenharmony_ci	OCTEON_FEATURE_FPA3,
878c2ecf20Sopenharmony_ci	OCTEON_FEATURE_FAU,
888c2ecf20Sopenharmony_ci	OCTEON_MAX_FEATURE
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cienum octeon_feature_bits {
928c2ecf20Sopenharmony_ci	OCTEON_HAS_CRYPTO = 0x0001,	/* Crypto acceleration using COP2 */
938c2ecf20Sopenharmony_ci};
948c2ecf20Sopenharmony_ciextern enum octeon_feature_bits __octeon_feature_bits;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/**
978c2ecf20Sopenharmony_ci * octeon_has_crypto() - Check if this OCTEON has crypto acceleration support.
988c2ecf20Sopenharmony_ci *
998c2ecf20Sopenharmony_ci * Returns: Non-zero if the feature exists. Zero if the feature does not exist.
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_cistatic inline int octeon_has_crypto(void)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	return __octeon_feature_bits & OCTEON_HAS_CRYPTO;
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/**
1078c2ecf20Sopenharmony_ci * Determine if the current Octeon supports a specific feature. These
1088c2ecf20Sopenharmony_ci * checks have been optimized to be fairly quick, but they should still
1098c2ecf20Sopenharmony_ci * be kept out of fast path code.
1108c2ecf20Sopenharmony_ci *
1118c2ecf20Sopenharmony_ci * @feature: Feature to check for. This should always be a constant so the
1128c2ecf20Sopenharmony_ci *		  compiler can remove the switch statement through optimization.
1138c2ecf20Sopenharmony_ci *
1148c2ecf20Sopenharmony_ci * Returns Non zero if the feature exists. Zero if the feature does not
1158c2ecf20Sopenharmony_ci *	   exist.
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_cistatic inline bool octeon_has_feature(enum octeon_feature feature)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	switch (feature) {
1208c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_SAAD:
1218c2ecf20Sopenharmony_ci		return !OCTEON_IS_MODEL(OCTEON_CN3XXX);
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_DORM_CRYPTO:
1248c2ecf20Sopenharmony_ci		if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
1258c2ecf20Sopenharmony_ci			union cvmx_mio_fus_dat2 fus_2;
1268c2ecf20Sopenharmony_ci			fus_2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
1278c2ecf20Sopenharmony_ci			return !fus_2.s.nocrypto && !fus_2.s.nomul && fus_2.s.dorm_crypto;
1288c2ecf20Sopenharmony_ci		} else {
1298c2ecf20Sopenharmony_ci			return false;
1308c2ecf20Sopenharmony_ci		}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_PCIE:
1338c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN56XX)
1348c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX)
1358c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX)
1368c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN7XXX);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_SRIO:
1398c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN63XX)
1408c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN66XX);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_ILK:
1438c2ecf20Sopenharmony_ci		return (OCTEON_IS_MODEL(OCTEON_CN68XX));
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_KEY_MEMORY:
1468c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN38XX)
1478c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN58XX)
1488c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN56XX)
1498c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX);
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_LED_CONTROLLER:
1528c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN38XX)
1538c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN58XX)
1548c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN56XX);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_TRA:
1578c2ecf20Sopenharmony_ci		return !(OCTEON_IS_MODEL(OCTEON_CN30XX)
1588c2ecf20Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN50XX));
1598c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_MGMT_PORT:
1608c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN56XX)
1618c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX)
1628c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_RAID:
1658c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN56XX)
1668c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX)
1678c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_USB:
1708c2ecf20Sopenharmony_ci		return !(OCTEON_IS_MODEL(OCTEON_CN38XX)
1718c2ecf20Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN58XX));
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_NO_WPTR:
1748c2ecf20Sopenharmony_ci		return (OCTEON_IS_MODEL(OCTEON_CN56XX)
1758c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX)
1768c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN6XXX))
1778c2ecf20Sopenharmony_ci			  && !OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X)
1788c2ecf20Sopenharmony_ci			  && !OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X);
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_MDIO_CLAUSE_45:
1818c2ecf20Sopenharmony_ci		return !(OCTEON_IS_MODEL(OCTEON_CN3XXX)
1828c2ecf20Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN58XX)
1838c2ecf20Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN50XX));
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_NPEI:
1868c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN56XX)
1878c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN52XX);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_PKND:
1908c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN68XX);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_CN68XX_WQE:
1938c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN68XX);
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_CIU2:
1968c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN68XX);
1978c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_CIU3:
1988c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_FPA3:
1998c2ecf20Sopenharmony_ci		return OCTEON_IS_MODEL(OCTEON_CN78XX)
2008c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CNF75XX)
2018c2ecf20Sopenharmony_ci			|| OCTEON_IS_MODEL(OCTEON_CN73XX);
2028c2ecf20Sopenharmony_ci	case OCTEON_FEATURE_FAU:
2038c2ecf20Sopenharmony_ci		return !(OCTEON_IS_MODEL(OCTEON_CN78XX)
2048c2ecf20Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CNF75XX)
2058c2ecf20Sopenharmony_ci			 || OCTEON_IS_MODEL(OCTEON_CN73XX));
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	default:
2088c2ecf20Sopenharmony_ci		break;
2098c2ecf20Sopenharmony_ci	}
2108c2ecf20Sopenharmony_ci	return false;
2118c2ecf20Sopenharmony_ci}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci#endif /* __OCTEON_FEATURE_H__ */
214