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 * Interface to the hardware Packet Input Processing unit.
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#ifndef __CVMX_PIP_H__
348c2ecf20Sopenharmony_ci#define __CVMX_PIP_H__
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-wqe.h>
378c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-fpa.h>
388c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-pip-defs.h>
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define CVMX_PIP_NUM_INPUT_PORTS		48
418c2ecf20Sopenharmony_ci#define CVMX_PIP_NUM_WATCHERS			4
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/*
448c2ecf20Sopenharmony_ci * Encodes the different error and exception codes
458c2ecf20Sopenharmony_ci */
468c2ecf20Sopenharmony_citypedef enum {
478c2ecf20Sopenharmony_ci	CVMX_PIP_L4_NO_ERR = 0ull,
488c2ecf20Sopenharmony_ci	/*
498c2ecf20Sopenharmony_ci	 * 1 = TCP (UDP) packet not long enough to cover TCP (UDP)
508c2ecf20Sopenharmony_ci	 * header
518c2ecf20Sopenharmony_ci	 */
528c2ecf20Sopenharmony_ci	CVMX_PIP_L4_MAL_ERR = 1ull,
538c2ecf20Sopenharmony_ci	/* 2  = TCP/UDP checksum failure */
548c2ecf20Sopenharmony_ci	CVMX_PIP_CHK_ERR = 2ull,
558c2ecf20Sopenharmony_ci	/*
568c2ecf20Sopenharmony_ci	 * 3 = TCP/UDP length check (TCP/UDP length does not match IP
578c2ecf20Sopenharmony_ci	 * length).
588c2ecf20Sopenharmony_ci	 */
598c2ecf20Sopenharmony_ci	CVMX_PIP_L4_LENGTH_ERR = 3ull,
608c2ecf20Sopenharmony_ci	/* 4  = illegal TCP/UDP port (either source or dest port is zero) */
618c2ecf20Sopenharmony_ci	CVMX_PIP_BAD_PRT_ERR = 4ull,
628c2ecf20Sopenharmony_ci	/* 8  = TCP flags = FIN only */
638c2ecf20Sopenharmony_ci	CVMX_PIP_TCP_FLG8_ERR = 8ull,
648c2ecf20Sopenharmony_ci	/* 9  = TCP flags = 0 */
658c2ecf20Sopenharmony_ci	CVMX_PIP_TCP_FLG9_ERR = 9ull,
668c2ecf20Sopenharmony_ci	/* 10 = TCP flags = FIN+RST+* */
678c2ecf20Sopenharmony_ci	CVMX_PIP_TCP_FLG10_ERR = 10ull,
688c2ecf20Sopenharmony_ci	/* 11 = TCP flags = SYN+URG+* */
698c2ecf20Sopenharmony_ci	CVMX_PIP_TCP_FLG11_ERR = 11ull,
708c2ecf20Sopenharmony_ci	/* 12 = TCP flags = SYN+RST+* */
718c2ecf20Sopenharmony_ci	CVMX_PIP_TCP_FLG12_ERR = 12ull,
728c2ecf20Sopenharmony_ci	/* 13 = TCP flags = SYN+FIN+* */
738c2ecf20Sopenharmony_ci	CVMX_PIP_TCP_FLG13_ERR = 13ull
748c2ecf20Sopenharmony_ci} cvmx_pip_l4_err_t;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_citypedef enum {
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	CVMX_PIP_IP_NO_ERR = 0ull,
798c2ecf20Sopenharmony_ci	/* 1 = not IPv4 or IPv6 */
808c2ecf20Sopenharmony_ci	CVMX_PIP_NOT_IP = 1ull,
818c2ecf20Sopenharmony_ci	/* 2 = IPv4 header checksum violation */
828c2ecf20Sopenharmony_ci	CVMX_PIP_IPV4_HDR_CHK = 2ull,
838c2ecf20Sopenharmony_ci	/* 3 = malformed (packet not long enough to cover IP hdr) */
848c2ecf20Sopenharmony_ci	CVMX_PIP_IP_MAL_HDR = 3ull,
858c2ecf20Sopenharmony_ci	/* 4 = malformed (packet not long enough to cover len in IP hdr) */
868c2ecf20Sopenharmony_ci	CVMX_PIP_IP_MAL_PKT = 4ull,
878c2ecf20Sopenharmony_ci	/* 5 = TTL / hop count equal zero */
888c2ecf20Sopenharmony_ci	CVMX_PIP_TTL_HOP = 5ull,
898c2ecf20Sopenharmony_ci	/* 6 = IPv4 options / IPv6 early extension headers */
908c2ecf20Sopenharmony_ci	CVMX_PIP_OPTS = 6ull
918c2ecf20Sopenharmony_ci} cvmx_pip_ip_exc_t;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/**
948c2ecf20Sopenharmony_ci * NOTES
958c2ecf20Sopenharmony_ci *	 late collision (data received before collision)
968c2ecf20Sopenharmony_ci *	      late collisions cannot be detected by the receiver
978c2ecf20Sopenharmony_ci *	      they would appear as JAM bits which would appear as bad FCS
988c2ecf20Sopenharmony_ci *	      or carrier extend error which is CVMX_PIP_EXTEND_ERR
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_citypedef enum {
1018c2ecf20Sopenharmony_ci	/* No error */
1028c2ecf20Sopenharmony_ci	CVMX_PIP_RX_NO_ERR = 0ull,
1038c2ecf20Sopenharmony_ci	/* RGM+SPI 1 = partially received packet (buffering/bandwidth
1048c2ecf20Sopenharmony_ci	 * not adequate) */
1058c2ecf20Sopenharmony_ci	CVMX_PIP_PARTIAL_ERR = 1ull,
1068c2ecf20Sopenharmony_ci	/* RGM+SPI 2 = receive packet too large and truncated */
1078c2ecf20Sopenharmony_ci	CVMX_PIP_JABBER_ERR = 2ull,
1088c2ecf20Sopenharmony_ci	/*
1098c2ecf20Sopenharmony_ci	 * RGM 3 = max frame error (pkt len > max frame len) (with FCS
1108c2ecf20Sopenharmony_ci	 * error)
1118c2ecf20Sopenharmony_ci	 */
1128c2ecf20Sopenharmony_ci	CVMX_PIP_OVER_FCS_ERR = 3ull,
1138c2ecf20Sopenharmony_ci	/* RGM+SPI 4 = max frame error (pkt len > max frame len) */
1148c2ecf20Sopenharmony_ci	CVMX_PIP_OVER_ERR = 4ull,
1158c2ecf20Sopenharmony_ci	/*
1168c2ecf20Sopenharmony_ci	 * RGM 5 = nibble error (data not byte multiple - 100M and 10M
1178c2ecf20Sopenharmony_ci	 * only)
1188c2ecf20Sopenharmony_ci	 */
1198c2ecf20Sopenharmony_ci	CVMX_PIP_ALIGN_ERR = 5ull,
1208c2ecf20Sopenharmony_ci	/*
1218c2ecf20Sopenharmony_ci	 * RGM 6 = min frame error (pkt len < min frame len) (with FCS
1228c2ecf20Sopenharmony_ci	 * error)
1238c2ecf20Sopenharmony_ci	 */
1248c2ecf20Sopenharmony_ci	CVMX_PIP_UNDER_FCS_ERR = 6ull,
1258c2ecf20Sopenharmony_ci	/* RGM	   7 = FCS error */
1268c2ecf20Sopenharmony_ci	CVMX_PIP_GMX_FCS_ERR = 7ull,
1278c2ecf20Sopenharmony_ci	/* RGM+SPI 8 = min frame error (pkt len < min frame len) */
1288c2ecf20Sopenharmony_ci	CVMX_PIP_UNDER_ERR = 8ull,
1298c2ecf20Sopenharmony_ci	/* RGM	   9 = Frame carrier extend error */
1308c2ecf20Sopenharmony_ci	CVMX_PIP_EXTEND_ERR = 9ull,
1318c2ecf20Sopenharmony_ci	/*
1328c2ecf20Sopenharmony_ci	 * RGM 10 = length mismatch (len did not match len in L2
1338c2ecf20Sopenharmony_ci	 * length/type)
1348c2ecf20Sopenharmony_ci	 */
1358c2ecf20Sopenharmony_ci	CVMX_PIP_LENGTH_ERR = 10ull,
1368c2ecf20Sopenharmony_ci	/* RGM 11 = Frame error (some or all data bits marked err) */
1378c2ecf20Sopenharmony_ci	CVMX_PIP_DAT_ERR = 11ull,
1388c2ecf20Sopenharmony_ci	/*     SPI 11 = DIP4 error */
1398c2ecf20Sopenharmony_ci	CVMX_PIP_DIP_ERR = 11ull,
1408c2ecf20Sopenharmony_ci	/*
1418c2ecf20Sopenharmony_ci	 * RGM 12 = packet was not large enough to pass the skipper -
1428c2ecf20Sopenharmony_ci	 * no inspection could occur.
1438c2ecf20Sopenharmony_ci	 */
1448c2ecf20Sopenharmony_ci	CVMX_PIP_SKIP_ERR = 12ull,
1458c2ecf20Sopenharmony_ci	/*
1468c2ecf20Sopenharmony_ci	 * RGM 13 = studder error (data not repeated - 100M and 10M
1478c2ecf20Sopenharmony_ci	 * only)
1488c2ecf20Sopenharmony_ci	 */
1498c2ecf20Sopenharmony_ci	CVMX_PIP_NIBBLE_ERR = 13ull,
1508c2ecf20Sopenharmony_ci	/* RGM+SPI 16 = FCS error */
1518c2ecf20Sopenharmony_ci	CVMX_PIP_PIP_FCS = 16L,
1528c2ecf20Sopenharmony_ci	/*
1538c2ecf20Sopenharmony_ci	 * RGM+SPI+PCI 17 = packet was not large enough to pass the
1548c2ecf20Sopenharmony_ci	 * skipper - no inspection could occur.
1558c2ecf20Sopenharmony_ci	 */
1568c2ecf20Sopenharmony_ci	CVMX_PIP_PIP_SKIP_ERR = 17L,
1578c2ecf20Sopenharmony_ci	/*
1588c2ecf20Sopenharmony_ci	 * RGM+SPI+PCI 18 = malformed l2 (packet not long enough to
1598c2ecf20Sopenharmony_ci	 * cover L2 hdr).
1608c2ecf20Sopenharmony_ci	 */
1618c2ecf20Sopenharmony_ci	CVMX_PIP_PIP_L2_MAL_HDR = 18L
1628c2ecf20Sopenharmony_ci	/*
1638c2ecf20Sopenharmony_ci	 * NOTES: xx = late collision (data received before collision)
1648c2ecf20Sopenharmony_ci	 *	 late collisions cannot be detected by the receiver
1658c2ecf20Sopenharmony_ci	 *	 they would appear as JAM bits which would appear as
1668c2ecf20Sopenharmony_ci	 *	 bad FCS or carrier extend error which is
1678c2ecf20Sopenharmony_ci	 *	 CVMX_PIP_EXTEND_ERR
1688c2ecf20Sopenharmony_ci	 */
1698c2ecf20Sopenharmony_ci} cvmx_pip_rcv_err_t;
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/**
1728c2ecf20Sopenharmony_ci * This defines the err_code field errors in the work Q entry
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_citypedef union {
1758c2ecf20Sopenharmony_ci	cvmx_pip_l4_err_t l4_err;
1768c2ecf20Sopenharmony_ci	cvmx_pip_ip_exc_t ip_exc;
1778c2ecf20Sopenharmony_ci	cvmx_pip_rcv_err_t rcv_err;
1788c2ecf20Sopenharmony_ci} cvmx_pip_err_t;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci/**
1818c2ecf20Sopenharmony_ci * Status statistics for a port
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_citypedef struct {
1848c2ecf20Sopenharmony_ci	/* Inbound octets marked to be dropped by the IPD */
1858c2ecf20Sopenharmony_ci	uint32_t dropped_octets;
1868c2ecf20Sopenharmony_ci	/* Inbound packets marked to be dropped by the IPD */
1878c2ecf20Sopenharmony_ci	uint32_t dropped_packets;
1888c2ecf20Sopenharmony_ci	/* RAW PCI Packets received by PIP per port */
1898c2ecf20Sopenharmony_ci	uint32_t pci_raw_packets;
1908c2ecf20Sopenharmony_ci	/* Number of octets processed by PIP */
1918c2ecf20Sopenharmony_ci	uint32_t octets;
1928c2ecf20Sopenharmony_ci	/* Number of packets processed by PIP */
1938c2ecf20Sopenharmony_ci	uint32_t packets;
1948c2ecf20Sopenharmony_ci	/*
1958c2ecf20Sopenharmony_ci	 * Number of identified L2 multicast packets.	Does not
1968c2ecf20Sopenharmony_ci	 * include broadcast packets.  Only includes packets whose
1978c2ecf20Sopenharmony_ci	 * parse mode is SKIP_TO_L2
1988c2ecf20Sopenharmony_ci	 */
1998c2ecf20Sopenharmony_ci	uint32_t multicast_packets;
2008c2ecf20Sopenharmony_ci	/*
2018c2ecf20Sopenharmony_ci	 * Number of identified L2 broadcast packets.	Does not
2028c2ecf20Sopenharmony_ci	 * include multicast packets.  Only includes packets whose
2038c2ecf20Sopenharmony_ci	 * parse mode is SKIP_TO_L2
2048c2ecf20Sopenharmony_ci	 */
2058c2ecf20Sopenharmony_ci	uint32_t broadcast_packets;
2068c2ecf20Sopenharmony_ci	/* Number of 64B packets */
2078c2ecf20Sopenharmony_ci	uint32_t len_64_packets;
2088c2ecf20Sopenharmony_ci	/* Number of 65-127B packets */
2098c2ecf20Sopenharmony_ci	uint32_t len_65_127_packets;
2108c2ecf20Sopenharmony_ci	/* Number of 128-255B packets */
2118c2ecf20Sopenharmony_ci	uint32_t len_128_255_packets;
2128c2ecf20Sopenharmony_ci	/* Number of 256-511B packets */
2138c2ecf20Sopenharmony_ci	uint32_t len_256_511_packets;
2148c2ecf20Sopenharmony_ci	/* Number of 512-1023B packets */
2158c2ecf20Sopenharmony_ci	uint32_t len_512_1023_packets;
2168c2ecf20Sopenharmony_ci	/* Number of 1024-1518B packets */
2178c2ecf20Sopenharmony_ci	uint32_t len_1024_1518_packets;
2188c2ecf20Sopenharmony_ci	/* Number of 1519-max packets */
2198c2ecf20Sopenharmony_ci	uint32_t len_1519_max_packets;
2208c2ecf20Sopenharmony_ci	/* Number of packets with FCS or Align opcode errors */
2218c2ecf20Sopenharmony_ci	uint32_t fcs_align_err_packets;
2228c2ecf20Sopenharmony_ci	/* Number of packets with length < min */
2238c2ecf20Sopenharmony_ci	uint32_t runt_packets;
2248c2ecf20Sopenharmony_ci	/* Number of packets with length < min and FCS error */
2258c2ecf20Sopenharmony_ci	uint32_t runt_crc_packets;
2268c2ecf20Sopenharmony_ci	/* Number of packets with length > max */
2278c2ecf20Sopenharmony_ci	uint32_t oversize_packets;
2288c2ecf20Sopenharmony_ci	/* Number of packets with length > max and FCS error */
2298c2ecf20Sopenharmony_ci	uint32_t oversize_crc_packets;
2308c2ecf20Sopenharmony_ci	/* Number of packets without GMX/SPX/PCI errors received by PIP */
2318c2ecf20Sopenharmony_ci	uint32_t inb_packets;
2328c2ecf20Sopenharmony_ci	/*
2338c2ecf20Sopenharmony_ci	 * Total number of octets from all packets received by PIP,
2348c2ecf20Sopenharmony_ci	 * including CRC
2358c2ecf20Sopenharmony_ci	 */
2368c2ecf20Sopenharmony_ci	uint64_t inb_octets;
2378c2ecf20Sopenharmony_ci	/* Number of packets with GMX/SPX/PCI errors received by PIP */
2388c2ecf20Sopenharmony_ci	uint16_t inb_errors;
2398c2ecf20Sopenharmony_ci} cvmx_pip_port_status_t;
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci/**
2428c2ecf20Sopenharmony_ci * Definition of the PIP custom header that can be prepended
2438c2ecf20Sopenharmony_ci * to a packet by external hardware.
2448c2ecf20Sopenharmony_ci */
2458c2ecf20Sopenharmony_citypedef union {
2468c2ecf20Sopenharmony_ci	uint64_t u64;
2478c2ecf20Sopenharmony_ci	struct {
2488c2ecf20Sopenharmony_ci		/*
2498c2ecf20Sopenharmony_ci		 * Documented as R - Set if the Packet is RAWFULL. If
2508c2ecf20Sopenharmony_ci		 * set, this header must be the full 8 bytes.
2518c2ecf20Sopenharmony_ci		 */
2528c2ecf20Sopenharmony_ci		uint64_t rawfull:1;
2538c2ecf20Sopenharmony_ci		/* Must be zero */
2548c2ecf20Sopenharmony_ci		uint64_t reserved0:5;
2558c2ecf20Sopenharmony_ci		/* PIP parse mode for this packet */
2568c2ecf20Sopenharmony_ci		uint64_t parse_mode:2;
2578c2ecf20Sopenharmony_ci		/* Must be zero */
2588c2ecf20Sopenharmony_ci		uint64_t reserved1:1;
2598c2ecf20Sopenharmony_ci		/*
2608c2ecf20Sopenharmony_ci		 * Skip amount, including this header, to the
2618c2ecf20Sopenharmony_ci		 * beginning of the packet
2628c2ecf20Sopenharmony_ci		 */
2638c2ecf20Sopenharmony_ci		uint64_t skip_len:7;
2648c2ecf20Sopenharmony_ci		/* Must be zero */
2658c2ecf20Sopenharmony_ci		uint64_t reserved2:6;
2668c2ecf20Sopenharmony_ci		/* POW input queue for this packet */
2678c2ecf20Sopenharmony_ci		uint64_t qos:3;
2688c2ecf20Sopenharmony_ci		/* POW input group for this packet */
2698c2ecf20Sopenharmony_ci		uint64_t grp:4;
2708c2ecf20Sopenharmony_ci		/*
2718c2ecf20Sopenharmony_ci		 * Flag to store this packet in the work queue entry,
2728c2ecf20Sopenharmony_ci		 * if possible
2738c2ecf20Sopenharmony_ci		 */
2748c2ecf20Sopenharmony_ci		uint64_t rs:1;
2758c2ecf20Sopenharmony_ci		/* POW input tag type */
2768c2ecf20Sopenharmony_ci		uint64_t tag_type:2;
2778c2ecf20Sopenharmony_ci		/* POW input tag */
2788c2ecf20Sopenharmony_ci		uint64_t tag:32;
2798c2ecf20Sopenharmony_ci	} s;
2808c2ecf20Sopenharmony_ci} cvmx_pip_pkt_inst_hdr_t;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci/* CSR typedefs have been moved to cvmx-csr-*.h */
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci/**
2858c2ecf20Sopenharmony_ci * Configure an ethernet input port
2868c2ecf20Sopenharmony_ci *
2878c2ecf20Sopenharmony_ci * @port_num: Port number to configure
2888c2ecf20Sopenharmony_ci * @port_cfg: Port hardware configuration
2898c2ecf20Sopenharmony_ci * @port_tag_cfg:
2908c2ecf20Sopenharmony_ci *		   Port POW tagging configuration
2918c2ecf20Sopenharmony_ci */
2928c2ecf20Sopenharmony_cistatic inline void cvmx_pip_config_port(uint64_t port_num,
2938c2ecf20Sopenharmony_ci					union cvmx_pip_prt_cfgx port_cfg,
2948c2ecf20Sopenharmony_ci					union cvmx_pip_prt_tagx port_tag_cfg)
2958c2ecf20Sopenharmony_ci{
2968c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_PRT_CFGX(port_num), port_cfg.u64);
2978c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_PRT_TAGX(port_num), port_tag_cfg.u64);
2988c2ecf20Sopenharmony_ci}
2998c2ecf20Sopenharmony_ci#if 0
3008c2ecf20Sopenharmony_ci/**
3018c2ecf20Sopenharmony_ci * @deprecated	    This function is a thin wrapper around the Pass1 version
3028c2ecf20Sopenharmony_ci *		    of the CVMX_PIP_QOS_WATCHX CSR; Pass2 has added a field for
3038c2ecf20Sopenharmony_ci *		    setting the group that is incompatible with this function,
3048c2ecf20Sopenharmony_ci *		    the preferred upgrade path is to use the CSR directly.
3058c2ecf20Sopenharmony_ci *
3068c2ecf20Sopenharmony_ci * Configure the global QoS packet watchers. Each watcher is
3078c2ecf20Sopenharmony_ci * capable of matching a field in a packet to determine the
3088c2ecf20Sopenharmony_ci * QoS queue for scheduling.
3098c2ecf20Sopenharmony_ci *
3108c2ecf20Sopenharmony_ci * @watcher:	Watcher number to configure (0 - 3).
3118c2ecf20Sopenharmony_ci * @match_type: Watcher match type
3128c2ecf20Sopenharmony_ci * @match_value:
3138c2ecf20Sopenharmony_ci *		     Value the watcher will match against
3148c2ecf20Sopenharmony_ci * @qos:	QoS queue for packets matching this watcher
3158c2ecf20Sopenharmony_ci */
3168c2ecf20Sopenharmony_cistatic inline void cvmx_pip_config_watcher(uint64_t watcher,
3178c2ecf20Sopenharmony_ci					   cvmx_pip_qos_watch_types match_type,
3188c2ecf20Sopenharmony_ci					   uint64_t match_value, uint64_t qos)
3198c2ecf20Sopenharmony_ci{
3208c2ecf20Sopenharmony_ci	cvmx_pip_port_watcher_cfg_t watcher_config;
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	watcher_config.u64 = 0;
3238c2ecf20Sopenharmony_ci	watcher_config.s.match_type = match_type;
3248c2ecf20Sopenharmony_ci	watcher_config.s.match_value = match_value;
3258c2ecf20Sopenharmony_ci	watcher_config.s.qos = qos;
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_QOS_WATCHX(watcher), watcher_config.u64);
3288c2ecf20Sopenharmony_ci}
3298c2ecf20Sopenharmony_ci#endif
3308c2ecf20Sopenharmony_ci/**
3318c2ecf20Sopenharmony_ci * Configure the VLAN priority to QoS queue mapping.
3328c2ecf20Sopenharmony_ci *
3338c2ecf20Sopenharmony_ci * @vlan_priority:
3348c2ecf20Sopenharmony_ci *		 VLAN priority (0-7)
3358c2ecf20Sopenharmony_ci * @qos:    QoS queue for packets matching this watcher
3368c2ecf20Sopenharmony_ci */
3378c2ecf20Sopenharmony_cistatic inline void cvmx_pip_config_vlan_qos(uint64_t vlan_priority,
3388c2ecf20Sopenharmony_ci					    uint64_t qos)
3398c2ecf20Sopenharmony_ci{
3408c2ecf20Sopenharmony_ci	union cvmx_pip_qos_vlanx pip_qos_vlanx;
3418c2ecf20Sopenharmony_ci	pip_qos_vlanx.u64 = 0;
3428c2ecf20Sopenharmony_ci	pip_qos_vlanx.s.qos = qos;
3438c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_QOS_VLANX(vlan_priority), pip_qos_vlanx.u64);
3448c2ecf20Sopenharmony_ci}
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci/**
3478c2ecf20Sopenharmony_ci * Configure the Diffserv to QoS queue mapping.
3488c2ecf20Sopenharmony_ci *
3498c2ecf20Sopenharmony_ci * @diffserv: Diffserv field value (0-63)
3508c2ecf20Sopenharmony_ci * @qos:      QoS queue for packets matching this watcher
3518c2ecf20Sopenharmony_ci */
3528c2ecf20Sopenharmony_cistatic inline void cvmx_pip_config_diffserv_qos(uint64_t diffserv, uint64_t qos)
3538c2ecf20Sopenharmony_ci{
3548c2ecf20Sopenharmony_ci	union cvmx_pip_qos_diffx pip_qos_diffx;
3558c2ecf20Sopenharmony_ci	pip_qos_diffx.u64 = 0;
3568c2ecf20Sopenharmony_ci	pip_qos_diffx.s.qos = qos;
3578c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_QOS_DIFFX(diffserv), pip_qos_diffx.u64);
3588c2ecf20Sopenharmony_ci}
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci/**
3618c2ecf20Sopenharmony_ci * Get the status counters for a port.
3628c2ecf20Sopenharmony_ci *
3638c2ecf20Sopenharmony_ci * @port_num: Port number to get statistics for.
3648c2ecf20Sopenharmony_ci * @clear:    Set to 1 to clear the counters after they are read
3658c2ecf20Sopenharmony_ci * @status:   Where to put the results.
3668c2ecf20Sopenharmony_ci */
3678c2ecf20Sopenharmony_cistatic inline void cvmx_pip_get_port_status(uint64_t port_num, uint64_t clear,
3688c2ecf20Sopenharmony_ci					    cvmx_pip_port_status_t *status)
3698c2ecf20Sopenharmony_ci{
3708c2ecf20Sopenharmony_ci	union cvmx_pip_stat_ctl pip_stat_ctl;
3718c2ecf20Sopenharmony_ci	union cvmx_pip_stat0_prtx stat0;
3728c2ecf20Sopenharmony_ci	union cvmx_pip_stat1_prtx stat1;
3738c2ecf20Sopenharmony_ci	union cvmx_pip_stat2_prtx stat2;
3748c2ecf20Sopenharmony_ci	union cvmx_pip_stat3_prtx stat3;
3758c2ecf20Sopenharmony_ci	union cvmx_pip_stat4_prtx stat4;
3768c2ecf20Sopenharmony_ci	union cvmx_pip_stat5_prtx stat5;
3778c2ecf20Sopenharmony_ci	union cvmx_pip_stat6_prtx stat6;
3788c2ecf20Sopenharmony_ci	union cvmx_pip_stat7_prtx stat7;
3798c2ecf20Sopenharmony_ci	union cvmx_pip_stat8_prtx stat8;
3808c2ecf20Sopenharmony_ci	union cvmx_pip_stat9_prtx stat9;
3818c2ecf20Sopenharmony_ci	union cvmx_pip_stat_inb_pktsx pip_stat_inb_pktsx;
3828c2ecf20Sopenharmony_ci	union cvmx_pip_stat_inb_octsx pip_stat_inb_octsx;
3838c2ecf20Sopenharmony_ci	union cvmx_pip_stat_inb_errsx pip_stat_inb_errsx;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	pip_stat_ctl.u64 = 0;
3868c2ecf20Sopenharmony_ci	pip_stat_ctl.s.rdclr = clear;
3878c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_STAT_CTL, pip_stat_ctl.u64);
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	stat0.u64 = cvmx_read_csr(CVMX_PIP_STAT0_PRTX(port_num));
3908c2ecf20Sopenharmony_ci	stat1.u64 = cvmx_read_csr(CVMX_PIP_STAT1_PRTX(port_num));
3918c2ecf20Sopenharmony_ci	stat2.u64 = cvmx_read_csr(CVMX_PIP_STAT2_PRTX(port_num));
3928c2ecf20Sopenharmony_ci	stat3.u64 = cvmx_read_csr(CVMX_PIP_STAT3_PRTX(port_num));
3938c2ecf20Sopenharmony_ci	stat4.u64 = cvmx_read_csr(CVMX_PIP_STAT4_PRTX(port_num));
3948c2ecf20Sopenharmony_ci	stat5.u64 = cvmx_read_csr(CVMX_PIP_STAT5_PRTX(port_num));
3958c2ecf20Sopenharmony_ci	stat6.u64 = cvmx_read_csr(CVMX_PIP_STAT6_PRTX(port_num));
3968c2ecf20Sopenharmony_ci	stat7.u64 = cvmx_read_csr(CVMX_PIP_STAT7_PRTX(port_num));
3978c2ecf20Sopenharmony_ci	stat8.u64 = cvmx_read_csr(CVMX_PIP_STAT8_PRTX(port_num));
3988c2ecf20Sopenharmony_ci	stat9.u64 = cvmx_read_csr(CVMX_PIP_STAT9_PRTX(port_num));
3998c2ecf20Sopenharmony_ci	pip_stat_inb_pktsx.u64 =
4008c2ecf20Sopenharmony_ci	    cvmx_read_csr(CVMX_PIP_STAT_INB_PKTSX(port_num));
4018c2ecf20Sopenharmony_ci	pip_stat_inb_octsx.u64 =
4028c2ecf20Sopenharmony_ci	    cvmx_read_csr(CVMX_PIP_STAT_INB_OCTSX(port_num));
4038c2ecf20Sopenharmony_ci	pip_stat_inb_errsx.u64 =
4048c2ecf20Sopenharmony_ci	    cvmx_read_csr(CVMX_PIP_STAT_INB_ERRSX(port_num));
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	status->dropped_octets = stat0.s.drp_octs;
4078c2ecf20Sopenharmony_ci	status->dropped_packets = stat0.s.drp_pkts;
4088c2ecf20Sopenharmony_ci	status->octets = stat1.s.octs;
4098c2ecf20Sopenharmony_ci	status->pci_raw_packets = stat2.s.raw;
4108c2ecf20Sopenharmony_ci	status->packets = stat2.s.pkts;
4118c2ecf20Sopenharmony_ci	status->multicast_packets = stat3.s.mcst;
4128c2ecf20Sopenharmony_ci	status->broadcast_packets = stat3.s.bcst;
4138c2ecf20Sopenharmony_ci	status->len_64_packets = stat4.s.h64;
4148c2ecf20Sopenharmony_ci	status->len_65_127_packets = stat4.s.h65to127;
4158c2ecf20Sopenharmony_ci	status->len_128_255_packets = stat5.s.h128to255;
4168c2ecf20Sopenharmony_ci	status->len_256_511_packets = stat5.s.h256to511;
4178c2ecf20Sopenharmony_ci	status->len_512_1023_packets = stat6.s.h512to1023;
4188c2ecf20Sopenharmony_ci	status->len_1024_1518_packets = stat6.s.h1024to1518;
4198c2ecf20Sopenharmony_ci	status->len_1519_max_packets = stat7.s.h1519;
4208c2ecf20Sopenharmony_ci	status->fcs_align_err_packets = stat7.s.fcs;
4218c2ecf20Sopenharmony_ci	status->runt_packets = stat8.s.undersz;
4228c2ecf20Sopenharmony_ci	status->runt_crc_packets = stat8.s.frag;
4238c2ecf20Sopenharmony_ci	status->oversize_packets = stat9.s.oversz;
4248c2ecf20Sopenharmony_ci	status->oversize_crc_packets = stat9.s.jabber;
4258c2ecf20Sopenharmony_ci	status->inb_packets = pip_stat_inb_pktsx.s.pkts;
4268c2ecf20Sopenharmony_ci	status->inb_octets = pip_stat_inb_octsx.s.octs;
4278c2ecf20Sopenharmony_ci	status->inb_errors = pip_stat_inb_errsx.s.errs;
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	if (cvmx_octeon_is_pass1()) {
4308c2ecf20Sopenharmony_ci		/*
4318c2ecf20Sopenharmony_ci		 * Kludge to fix Octeon Pass 1 errata - Drop counts
4328c2ecf20Sopenharmony_ci		 * don't work.
4338c2ecf20Sopenharmony_ci		 */
4348c2ecf20Sopenharmony_ci		if (status->inb_packets > status->packets)
4358c2ecf20Sopenharmony_ci			status->dropped_packets =
4368c2ecf20Sopenharmony_ci			    status->inb_packets - status->packets;
4378c2ecf20Sopenharmony_ci		else
4388c2ecf20Sopenharmony_ci			status->dropped_packets = 0;
4398c2ecf20Sopenharmony_ci		if (status->inb_octets - status->inb_packets * 4 >
4408c2ecf20Sopenharmony_ci		    status->octets)
4418c2ecf20Sopenharmony_ci			status->dropped_octets =
4428c2ecf20Sopenharmony_ci			    status->inb_octets - status->inb_packets * 4 -
4438c2ecf20Sopenharmony_ci			    status->octets;
4448c2ecf20Sopenharmony_ci		else
4458c2ecf20Sopenharmony_ci			status->dropped_octets = 0;
4468c2ecf20Sopenharmony_ci	}
4478c2ecf20Sopenharmony_ci}
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci/**
4508c2ecf20Sopenharmony_ci * Configure the hardware CRC engine
4518c2ecf20Sopenharmony_ci *
4528c2ecf20Sopenharmony_ci * @interface: Interface to configure (0 or 1)
4538c2ecf20Sopenharmony_ci * @invert_result:
4548c2ecf20Sopenharmony_ci *		   Invert the result of the CRC
4558c2ecf20Sopenharmony_ci * @reflect:  Reflect
4568c2ecf20Sopenharmony_ci * @initialization_vector:
4578c2ecf20Sopenharmony_ci *		   CRC initialization vector
4588c2ecf20Sopenharmony_ci */
4598c2ecf20Sopenharmony_cistatic inline void cvmx_pip_config_crc(uint64_t interface,
4608c2ecf20Sopenharmony_ci				       uint64_t invert_result, uint64_t reflect,
4618c2ecf20Sopenharmony_ci				       uint32_t initialization_vector)
4628c2ecf20Sopenharmony_ci{
4638c2ecf20Sopenharmony_ci	if (OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
4648c2ecf20Sopenharmony_ci		union cvmx_pip_crc_ctlx config;
4658c2ecf20Sopenharmony_ci		union cvmx_pip_crc_ivx pip_crc_ivx;
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci		config.u64 = 0;
4688c2ecf20Sopenharmony_ci		config.s.invres = invert_result;
4698c2ecf20Sopenharmony_ci		config.s.reflect = reflect;
4708c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_PIP_CRC_CTLX(interface), config.u64);
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci		pip_crc_ivx.u64 = 0;
4738c2ecf20Sopenharmony_ci		pip_crc_ivx.s.iv = initialization_vector;
4748c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_PIP_CRC_IVX(interface), pip_crc_ivx.u64);
4758c2ecf20Sopenharmony_ci	}
4768c2ecf20Sopenharmony_ci}
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci/**
4798c2ecf20Sopenharmony_ci * Clear all bits in a tag mask. This should be called on
4808c2ecf20Sopenharmony_ci * startup before any calls to cvmx_pip_tag_mask_set. Each bit
4818c2ecf20Sopenharmony_ci * set in the final mask represent a byte used in the packet for
4828c2ecf20Sopenharmony_ci * tag generation.
4838c2ecf20Sopenharmony_ci *
4848c2ecf20Sopenharmony_ci * @mask_index: Which tag mask to clear (0..3)
4858c2ecf20Sopenharmony_ci */
4868c2ecf20Sopenharmony_cistatic inline void cvmx_pip_tag_mask_clear(uint64_t mask_index)
4878c2ecf20Sopenharmony_ci{
4888c2ecf20Sopenharmony_ci	uint64_t index;
4898c2ecf20Sopenharmony_ci	union cvmx_pip_tag_incx pip_tag_incx;
4908c2ecf20Sopenharmony_ci	pip_tag_incx.u64 = 0;
4918c2ecf20Sopenharmony_ci	pip_tag_incx.s.en = 0;
4928c2ecf20Sopenharmony_ci	for (index = mask_index * 16; index < (mask_index + 1) * 16; index++)
4938c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
4948c2ecf20Sopenharmony_ci}
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci/**
4978c2ecf20Sopenharmony_ci * Sets a range of bits in the tag mask. The tag mask is used
4988c2ecf20Sopenharmony_ci * when the cvmx_pip_port_tag_cfg_t tag_mode is non zero.
4998c2ecf20Sopenharmony_ci * There are four separate masks that can be configured.
5008c2ecf20Sopenharmony_ci *
5018c2ecf20Sopenharmony_ci * @mask_index: Which tag mask to modify (0..3)
5028c2ecf20Sopenharmony_ci * @offset: Offset into the bitmask to set bits at. Use the GCC macro
5038c2ecf20Sopenharmony_ci *	    offsetof() to determine the offsets into packet headers.
5048c2ecf20Sopenharmony_ci *	    For example, offsetof(ethhdr, protocol) returns the offset
5058c2ecf20Sopenharmony_ci *	    of the ethernet protocol field.  The bitmask selects which
5068c2ecf20Sopenharmony_ci *	    bytes to include the tag, with bit offset X selecting
5078c2ecf20Sopenharmony_ci *	    byte at offset X from the beginning of the packet data.
5088c2ecf20Sopenharmony_ci * @len:    Number of bytes to include. Usually this is the sizeof()
5098c2ecf20Sopenharmony_ci *	    the field.
5108c2ecf20Sopenharmony_ci */
5118c2ecf20Sopenharmony_cistatic inline void cvmx_pip_tag_mask_set(uint64_t mask_index, uint64_t offset,
5128c2ecf20Sopenharmony_ci					 uint64_t len)
5138c2ecf20Sopenharmony_ci{
5148c2ecf20Sopenharmony_ci	while (len--) {
5158c2ecf20Sopenharmony_ci		union cvmx_pip_tag_incx pip_tag_incx;
5168c2ecf20Sopenharmony_ci		uint64_t index = mask_index * 16 + offset / 8;
5178c2ecf20Sopenharmony_ci		pip_tag_incx.u64 = cvmx_read_csr(CVMX_PIP_TAG_INCX(index));
5188c2ecf20Sopenharmony_ci		pip_tag_incx.s.en |= 0x80 >> (offset & 0x7);
5198c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
5208c2ecf20Sopenharmony_ci		offset++;
5218c2ecf20Sopenharmony_ci	}
5228c2ecf20Sopenharmony_ci}
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci#endif /*  __CVMX_PIP_H__ */
525