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 * Functions for NPI initialization, configuration,
308c2ecf20Sopenharmony_ci * and monitoring.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci#include <asm/octeon/octeon.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-config.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-pip-defs.h>
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/**
418c2ecf20Sopenharmony_ci * Probe a NPI interface and determine the number of ports
428c2ecf20Sopenharmony_ci * connected to it. The NPI interface should still be down
438c2ecf20Sopenharmony_ci * after this call.
448c2ecf20Sopenharmony_ci *
458c2ecf20Sopenharmony_ci * @interface: Interface to probe
468c2ecf20Sopenharmony_ci *
478c2ecf20Sopenharmony_ci * Returns Number of ports on the interface. Zero to disable.
488c2ecf20Sopenharmony_ci */
498c2ecf20Sopenharmony_ciint __cvmx_helper_npi_probe(int interface)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci#if CVMX_PKO_QUEUES_PER_PORT_PCI > 0
528c2ecf20Sopenharmony_ci	if (OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX))
538c2ecf20Sopenharmony_ci		return 4;
548c2ecf20Sopenharmony_ci	else if (OCTEON_IS_MODEL(OCTEON_CN56XX)
558c2ecf20Sopenharmony_ci		 && !OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X))
568c2ecf20Sopenharmony_ci		/* The packet engines didn't exist before pass 2 */
578c2ecf20Sopenharmony_ci		return 4;
588c2ecf20Sopenharmony_ci	else if (OCTEON_IS_MODEL(OCTEON_CN52XX)
598c2ecf20Sopenharmony_ci		 && !OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X))
608c2ecf20Sopenharmony_ci		/* The packet engines didn't exist before pass 2 */
618c2ecf20Sopenharmony_ci		return 4;
628c2ecf20Sopenharmony_ci#endif
638c2ecf20Sopenharmony_ci	return 0;
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/**
678c2ecf20Sopenharmony_ci * Bringup and enable a NPI interface. After this call packet
688c2ecf20Sopenharmony_ci * I/O should be fully functional. This is called with IPD
698c2ecf20Sopenharmony_ci * enabled but PKO disabled.
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci * @interface: Interface to bring up
728c2ecf20Sopenharmony_ci *
738c2ecf20Sopenharmony_ci * Returns Zero on success, negative on failure
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_ciint __cvmx_helper_npi_enable(int interface)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	/*
788c2ecf20Sopenharmony_ci	 * On CN50XX, CN52XX, and CN56XX we need to disable length
798c2ecf20Sopenharmony_ci	 * checking so packet < 64 bytes and jumbo frames don't get
808c2ecf20Sopenharmony_ci	 * errors.
818c2ecf20Sopenharmony_ci	 */
828c2ecf20Sopenharmony_ci	if (!OCTEON_IS_MODEL(OCTEON_CN3XXX) &&
838c2ecf20Sopenharmony_ci	    !OCTEON_IS_MODEL(OCTEON_CN58XX)) {
848c2ecf20Sopenharmony_ci		int num_ports = cvmx_helper_ports_on_interface(interface);
858c2ecf20Sopenharmony_ci		int port;
868c2ecf20Sopenharmony_ci		for (port = 0; port < num_ports; port++) {
878c2ecf20Sopenharmony_ci			union cvmx_pip_prt_cfgx port_cfg;
888c2ecf20Sopenharmony_ci			int ipd_port =
898c2ecf20Sopenharmony_ci			    cvmx_helper_get_ipd_port(interface, port);
908c2ecf20Sopenharmony_ci			port_cfg.u64 =
918c2ecf20Sopenharmony_ci			    cvmx_read_csr(CVMX_PIP_PRT_CFGX(ipd_port));
928c2ecf20Sopenharmony_ci			port_cfg.s.maxerr_en = 0;
938c2ecf20Sopenharmony_ci			port_cfg.s.minerr_en = 0;
948c2ecf20Sopenharmony_ci			cvmx_write_csr(CVMX_PIP_PRT_CFGX(ipd_port),
958c2ecf20Sopenharmony_ci				       port_cfg.u64);
968c2ecf20Sopenharmony_ci		}
978c2ecf20Sopenharmony_ci	}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	/* Enables are controlled by the remote host, so nothing to do here */
1008c2ecf20Sopenharmony_ci	return 0;
1018c2ecf20Sopenharmony_ci}
102