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 * Interface to the hardware Packet Input Processing unit.
3062306a36Sopenharmony_ci *
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#ifndef __CVMX_PIP_H__
3462306a36Sopenharmony_ci#define __CVMX_PIP_H__
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#include <asm/octeon/cvmx-wqe.h>
3762306a36Sopenharmony_ci#include <asm/octeon/cvmx-fpa.h>
3862306a36Sopenharmony_ci#include <asm/octeon/cvmx-pip-defs.h>
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define CVMX_PIP_NUM_INPUT_PORTS		48
4162306a36Sopenharmony_ci#define CVMX_PIP_NUM_WATCHERS			4
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/*
4462306a36Sopenharmony_ci * Encodes the different error and exception codes
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_citypedef enum {
4762306a36Sopenharmony_ci	CVMX_PIP_L4_NO_ERR = 0ull,
4862306a36Sopenharmony_ci	/*
4962306a36Sopenharmony_ci	 * 1 = TCP (UDP) packet not long enough to cover TCP (UDP)
5062306a36Sopenharmony_ci	 * header
5162306a36Sopenharmony_ci	 */
5262306a36Sopenharmony_ci	CVMX_PIP_L4_MAL_ERR = 1ull,
5362306a36Sopenharmony_ci	/* 2  = TCP/UDP checksum failure */
5462306a36Sopenharmony_ci	CVMX_PIP_CHK_ERR = 2ull,
5562306a36Sopenharmony_ci	/*
5662306a36Sopenharmony_ci	 * 3 = TCP/UDP length check (TCP/UDP length does not match IP
5762306a36Sopenharmony_ci	 * length).
5862306a36Sopenharmony_ci	 */
5962306a36Sopenharmony_ci	CVMX_PIP_L4_LENGTH_ERR = 3ull,
6062306a36Sopenharmony_ci	/* 4  = illegal TCP/UDP port (either source or dest port is zero) */
6162306a36Sopenharmony_ci	CVMX_PIP_BAD_PRT_ERR = 4ull,
6262306a36Sopenharmony_ci	/* 8  = TCP flags = FIN only */
6362306a36Sopenharmony_ci	CVMX_PIP_TCP_FLG8_ERR = 8ull,
6462306a36Sopenharmony_ci	/* 9  = TCP flags = 0 */
6562306a36Sopenharmony_ci	CVMX_PIP_TCP_FLG9_ERR = 9ull,
6662306a36Sopenharmony_ci	/* 10 = TCP flags = FIN+RST+* */
6762306a36Sopenharmony_ci	CVMX_PIP_TCP_FLG10_ERR = 10ull,
6862306a36Sopenharmony_ci	/* 11 = TCP flags = SYN+URG+* */
6962306a36Sopenharmony_ci	CVMX_PIP_TCP_FLG11_ERR = 11ull,
7062306a36Sopenharmony_ci	/* 12 = TCP flags = SYN+RST+* */
7162306a36Sopenharmony_ci	CVMX_PIP_TCP_FLG12_ERR = 12ull,
7262306a36Sopenharmony_ci	/* 13 = TCP flags = SYN+FIN+* */
7362306a36Sopenharmony_ci	CVMX_PIP_TCP_FLG13_ERR = 13ull
7462306a36Sopenharmony_ci} cvmx_pip_l4_err_t;
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_citypedef enum {
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci	CVMX_PIP_IP_NO_ERR = 0ull,
7962306a36Sopenharmony_ci	/* 1 = not IPv4 or IPv6 */
8062306a36Sopenharmony_ci	CVMX_PIP_NOT_IP = 1ull,
8162306a36Sopenharmony_ci	/* 2 = IPv4 header checksum violation */
8262306a36Sopenharmony_ci	CVMX_PIP_IPV4_HDR_CHK = 2ull,
8362306a36Sopenharmony_ci	/* 3 = malformed (packet not long enough to cover IP hdr) */
8462306a36Sopenharmony_ci	CVMX_PIP_IP_MAL_HDR = 3ull,
8562306a36Sopenharmony_ci	/* 4 = malformed (packet not long enough to cover len in IP hdr) */
8662306a36Sopenharmony_ci	CVMX_PIP_IP_MAL_PKT = 4ull,
8762306a36Sopenharmony_ci	/* 5 = TTL / hop count equal zero */
8862306a36Sopenharmony_ci	CVMX_PIP_TTL_HOP = 5ull,
8962306a36Sopenharmony_ci	/* 6 = IPv4 options / IPv6 early extension headers */
9062306a36Sopenharmony_ci	CVMX_PIP_OPTS = 6ull
9162306a36Sopenharmony_ci} cvmx_pip_ip_exc_t;
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/**
9462306a36Sopenharmony_ci * NOTES
9562306a36Sopenharmony_ci *	 late collision (data received before collision)
9662306a36Sopenharmony_ci *	      late collisions cannot be detected by the receiver
9762306a36Sopenharmony_ci *	      they would appear as JAM bits which would appear as bad FCS
9862306a36Sopenharmony_ci *	      or carrier extend error which is CVMX_PIP_EXTEND_ERR
9962306a36Sopenharmony_ci */
10062306a36Sopenharmony_citypedef enum {
10162306a36Sopenharmony_ci	/* No error */
10262306a36Sopenharmony_ci	CVMX_PIP_RX_NO_ERR = 0ull,
10362306a36Sopenharmony_ci	/* RGM+SPI 1 = partially received packet (buffering/bandwidth
10462306a36Sopenharmony_ci	 * not adequate) */
10562306a36Sopenharmony_ci	CVMX_PIP_PARTIAL_ERR = 1ull,
10662306a36Sopenharmony_ci	/* RGM+SPI 2 = receive packet too large and truncated */
10762306a36Sopenharmony_ci	CVMX_PIP_JABBER_ERR = 2ull,
10862306a36Sopenharmony_ci	/*
10962306a36Sopenharmony_ci	 * RGM 3 = max frame error (pkt len > max frame len) (with FCS
11062306a36Sopenharmony_ci	 * error)
11162306a36Sopenharmony_ci	 */
11262306a36Sopenharmony_ci	CVMX_PIP_OVER_FCS_ERR = 3ull,
11362306a36Sopenharmony_ci	/* RGM+SPI 4 = max frame error (pkt len > max frame len) */
11462306a36Sopenharmony_ci	CVMX_PIP_OVER_ERR = 4ull,
11562306a36Sopenharmony_ci	/*
11662306a36Sopenharmony_ci	 * RGM 5 = nibble error (data not byte multiple - 100M and 10M
11762306a36Sopenharmony_ci	 * only)
11862306a36Sopenharmony_ci	 */
11962306a36Sopenharmony_ci	CVMX_PIP_ALIGN_ERR = 5ull,
12062306a36Sopenharmony_ci	/*
12162306a36Sopenharmony_ci	 * RGM 6 = min frame error (pkt len < min frame len) (with FCS
12262306a36Sopenharmony_ci	 * error)
12362306a36Sopenharmony_ci	 */
12462306a36Sopenharmony_ci	CVMX_PIP_UNDER_FCS_ERR = 6ull,
12562306a36Sopenharmony_ci	/* RGM	   7 = FCS error */
12662306a36Sopenharmony_ci	CVMX_PIP_GMX_FCS_ERR = 7ull,
12762306a36Sopenharmony_ci	/* RGM+SPI 8 = min frame error (pkt len < min frame len) */
12862306a36Sopenharmony_ci	CVMX_PIP_UNDER_ERR = 8ull,
12962306a36Sopenharmony_ci	/* RGM	   9 = Frame carrier extend error */
13062306a36Sopenharmony_ci	CVMX_PIP_EXTEND_ERR = 9ull,
13162306a36Sopenharmony_ci	/*
13262306a36Sopenharmony_ci	 * RGM 10 = length mismatch (len did not match len in L2
13362306a36Sopenharmony_ci	 * length/type)
13462306a36Sopenharmony_ci	 */
13562306a36Sopenharmony_ci	CVMX_PIP_LENGTH_ERR = 10ull,
13662306a36Sopenharmony_ci	/* RGM 11 = Frame error (some or all data bits marked err) */
13762306a36Sopenharmony_ci	CVMX_PIP_DAT_ERR = 11ull,
13862306a36Sopenharmony_ci	/*     SPI 11 = DIP4 error */
13962306a36Sopenharmony_ci	CVMX_PIP_DIP_ERR = 11ull,
14062306a36Sopenharmony_ci	/*
14162306a36Sopenharmony_ci	 * RGM 12 = packet was not large enough to pass the skipper -
14262306a36Sopenharmony_ci	 * no inspection could occur.
14362306a36Sopenharmony_ci	 */
14462306a36Sopenharmony_ci	CVMX_PIP_SKIP_ERR = 12ull,
14562306a36Sopenharmony_ci	/*
14662306a36Sopenharmony_ci	 * RGM 13 = studder error (data not repeated - 100M and 10M
14762306a36Sopenharmony_ci	 * only)
14862306a36Sopenharmony_ci	 */
14962306a36Sopenharmony_ci	CVMX_PIP_NIBBLE_ERR = 13ull,
15062306a36Sopenharmony_ci	/* RGM+SPI 16 = FCS error */
15162306a36Sopenharmony_ci	CVMX_PIP_PIP_FCS = 16L,
15262306a36Sopenharmony_ci	/*
15362306a36Sopenharmony_ci	 * RGM+SPI+PCI 17 = packet was not large enough to pass the
15462306a36Sopenharmony_ci	 * skipper - no inspection could occur.
15562306a36Sopenharmony_ci	 */
15662306a36Sopenharmony_ci	CVMX_PIP_PIP_SKIP_ERR = 17L,
15762306a36Sopenharmony_ci	/*
15862306a36Sopenharmony_ci	 * RGM+SPI+PCI 18 = malformed l2 (packet not long enough to
15962306a36Sopenharmony_ci	 * cover L2 hdr).
16062306a36Sopenharmony_ci	 */
16162306a36Sopenharmony_ci	CVMX_PIP_PIP_L2_MAL_HDR = 18L
16262306a36Sopenharmony_ci	/*
16362306a36Sopenharmony_ci	 * NOTES: xx = late collision (data received before collision)
16462306a36Sopenharmony_ci	 *	 late collisions cannot be detected by the receiver
16562306a36Sopenharmony_ci	 *	 they would appear as JAM bits which would appear as
16662306a36Sopenharmony_ci	 *	 bad FCS or carrier extend error which is
16762306a36Sopenharmony_ci	 *	 CVMX_PIP_EXTEND_ERR
16862306a36Sopenharmony_ci	 */
16962306a36Sopenharmony_ci} cvmx_pip_rcv_err_t;
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci/**
17262306a36Sopenharmony_ci * This defines the err_code field errors in the work Q entry
17362306a36Sopenharmony_ci */
17462306a36Sopenharmony_citypedef union {
17562306a36Sopenharmony_ci	cvmx_pip_l4_err_t l4_err;
17662306a36Sopenharmony_ci	cvmx_pip_ip_exc_t ip_exc;
17762306a36Sopenharmony_ci	cvmx_pip_rcv_err_t rcv_err;
17862306a36Sopenharmony_ci} cvmx_pip_err_t;
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci/**
18162306a36Sopenharmony_ci * Status statistics for a port
18262306a36Sopenharmony_ci */
18362306a36Sopenharmony_citypedef struct {
18462306a36Sopenharmony_ci	/* Inbound octets marked to be dropped by the IPD */
18562306a36Sopenharmony_ci	uint32_t dropped_octets;
18662306a36Sopenharmony_ci	/* Inbound packets marked to be dropped by the IPD */
18762306a36Sopenharmony_ci	uint32_t dropped_packets;
18862306a36Sopenharmony_ci	/* RAW PCI Packets received by PIP per port */
18962306a36Sopenharmony_ci	uint32_t pci_raw_packets;
19062306a36Sopenharmony_ci	/* Number of octets processed by PIP */
19162306a36Sopenharmony_ci	uint32_t octets;
19262306a36Sopenharmony_ci	/* Number of packets processed by PIP */
19362306a36Sopenharmony_ci	uint32_t packets;
19462306a36Sopenharmony_ci	/*
19562306a36Sopenharmony_ci	 * Number of identified L2 multicast packets.	Does not
19662306a36Sopenharmony_ci	 * include broadcast packets.  Only includes packets whose
19762306a36Sopenharmony_ci	 * parse mode is SKIP_TO_L2
19862306a36Sopenharmony_ci	 */
19962306a36Sopenharmony_ci	uint32_t multicast_packets;
20062306a36Sopenharmony_ci	/*
20162306a36Sopenharmony_ci	 * Number of identified L2 broadcast packets.	Does not
20262306a36Sopenharmony_ci	 * include multicast packets.  Only includes packets whose
20362306a36Sopenharmony_ci	 * parse mode is SKIP_TO_L2
20462306a36Sopenharmony_ci	 */
20562306a36Sopenharmony_ci	uint32_t broadcast_packets;
20662306a36Sopenharmony_ci	/* Number of 64B packets */
20762306a36Sopenharmony_ci	uint32_t len_64_packets;
20862306a36Sopenharmony_ci	/* Number of 65-127B packets */
20962306a36Sopenharmony_ci	uint32_t len_65_127_packets;
21062306a36Sopenharmony_ci	/* Number of 128-255B packets */
21162306a36Sopenharmony_ci	uint32_t len_128_255_packets;
21262306a36Sopenharmony_ci	/* Number of 256-511B packets */
21362306a36Sopenharmony_ci	uint32_t len_256_511_packets;
21462306a36Sopenharmony_ci	/* Number of 512-1023B packets */
21562306a36Sopenharmony_ci	uint32_t len_512_1023_packets;
21662306a36Sopenharmony_ci	/* Number of 1024-1518B packets */
21762306a36Sopenharmony_ci	uint32_t len_1024_1518_packets;
21862306a36Sopenharmony_ci	/* Number of 1519-max packets */
21962306a36Sopenharmony_ci	uint32_t len_1519_max_packets;
22062306a36Sopenharmony_ci	/* Number of packets with FCS or Align opcode errors */
22162306a36Sopenharmony_ci	uint32_t fcs_align_err_packets;
22262306a36Sopenharmony_ci	/* Number of packets with length < min */
22362306a36Sopenharmony_ci	uint32_t runt_packets;
22462306a36Sopenharmony_ci	/* Number of packets with length < min and FCS error */
22562306a36Sopenharmony_ci	uint32_t runt_crc_packets;
22662306a36Sopenharmony_ci	/* Number of packets with length > max */
22762306a36Sopenharmony_ci	uint32_t oversize_packets;
22862306a36Sopenharmony_ci	/* Number of packets with length > max and FCS error */
22962306a36Sopenharmony_ci	uint32_t oversize_crc_packets;
23062306a36Sopenharmony_ci	/* Number of packets without GMX/SPX/PCI errors received by PIP */
23162306a36Sopenharmony_ci	uint32_t inb_packets;
23262306a36Sopenharmony_ci	/*
23362306a36Sopenharmony_ci	 * Total number of octets from all packets received by PIP,
23462306a36Sopenharmony_ci	 * including CRC
23562306a36Sopenharmony_ci	 */
23662306a36Sopenharmony_ci	uint64_t inb_octets;
23762306a36Sopenharmony_ci	/* Number of packets with GMX/SPX/PCI errors received by PIP */
23862306a36Sopenharmony_ci	uint16_t inb_errors;
23962306a36Sopenharmony_ci} cvmx_pip_port_status_t;
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci/**
24262306a36Sopenharmony_ci * Definition of the PIP custom header that can be prepended
24362306a36Sopenharmony_ci * to a packet by external hardware.
24462306a36Sopenharmony_ci */
24562306a36Sopenharmony_citypedef union {
24662306a36Sopenharmony_ci	uint64_t u64;
24762306a36Sopenharmony_ci	struct {
24862306a36Sopenharmony_ci		/*
24962306a36Sopenharmony_ci		 * Documented as R - Set if the Packet is RAWFULL. If
25062306a36Sopenharmony_ci		 * set, this header must be the full 8 bytes.
25162306a36Sopenharmony_ci		 */
25262306a36Sopenharmony_ci		uint64_t rawfull:1;
25362306a36Sopenharmony_ci		/* Must be zero */
25462306a36Sopenharmony_ci		uint64_t reserved0:5;
25562306a36Sopenharmony_ci		/* PIP parse mode for this packet */
25662306a36Sopenharmony_ci		uint64_t parse_mode:2;
25762306a36Sopenharmony_ci		/* Must be zero */
25862306a36Sopenharmony_ci		uint64_t reserved1:1;
25962306a36Sopenharmony_ci		/*
26062306a36Sopenharmony_ci		 * Skip amount, including this header, to the
26162306a36Sopenharmony_ci		 * beginning of the packet
26262306a36Sopenharmony_ci		 */
26362306a36Sopenharmony_ci		uint64_t skip_len:7;
26462306a36Sopenharmony_ci		/* Must be zero */
26562306a36Sopenharmony_ci		uint64_t reserved2:6;
26662306a36Sopenharmony_ci		/* POW input queue for this packet */
26762306a36Sopenharmony_ci		uint64_t qos:3;
26862306a36Sopenharmony_ci		/* POW input group for this packet */
26962306a36Sopenharmony_ci		uint64_t grp:4;
27062306a36Sopenharmony_ci		/*
27162306a36Sopenharmony_ci		 * Flag to store this packet in the work queue entry,
27262306a36Sopenharmony_ci		 * if possible
27362306a36Sopenharmony_ci		 */
27462306a36Sopenharmony_ci		uint64_t rs:1;
27562306a36Sopenharmony_ci		/* POW input tag type */
27662306a36Sopenharmony_ci		uint64_t tag_type:2;
27762306a36Sopenharmony_ci		/* POW input tag */
27862306a36Sopenharmony_ci		uint64_t tag:32;
27962306a36Sopenharmony_ci	} s;
28062306a36Sopenharmony_ci} cvmx_pip_pkt_inst_hdr_t;
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci/* CSR typedefs have been moved to cvmx-csr-*.h */
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci/**
28562306a36Sopenharmony_ci * Configure an ethernet input port
28662306a36Sopenharmony_ci *
28762306a36Sopenharmony_ci * @port_num: Port number to configure
28862306a36Sopenharmony_ci * @port_cfg: Port hardware configuration
28962306a36Sopenharmony_ci * @port_tag_cfg:
29062306a36Sopenharmony_ci *		   Port POW tagging configuration
29162306a36Sopenharmony_ci */
29262306a36Sopenharmony_cistatic inline void cvmx_pip_config_port(uint64_t port_num,
29362306a36Sopenharmony_ci					union cvmx_pip_prt_cfgx port_cfg,
29462306a36Sopenharmony_ci					union cvmx_pip_prt_tagx port_tag_cfg)
29562306a36Sopenharmony_ci{
29662306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_PRT_CFGX(port_num), port_cfg.u64);
29762306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_PRT_TAGX(port_num), port_tag_cfg.u64);
29862306a36Sopenharmony_ci}
29962306a36Sopenharmony_ci#if 0
30062306a36Sopenharmony_ci/**
30162306a36Sopenharmony_ci * @deprecated	    This function is a thin wrapper around the Pass1 version
30262306a36Sopenharmony_ci *		    of the CVMX_PIP_QOS_WATCHX CSR; Pass2 has added a field for
30362306a36Sopenharmony_ci *		    setting the group that is incompatible with this function,
30462306a36Sopenharmony_ci *		    the preferred upgrade path is to use the CSR directly.
30562306a36Sopenharmony_ci *
30662306a36Sopenharmony_ci * Configure the global QoS packet watchers. Each watcher is
30762306a36Sopenharmony_ci * capable of matching a field in a packet to determine the
30862306a36Sopenharmony_ci * QoS queue for scheduling.
30962306a36Sopenharmony_ci *
31062306a36Sopenharmony_ci * @watcher:	Watcher number to configure (0 - 3).
31162306a36Sopenharmony_ci * @match_type: Watcher match type
31262306a36Sopenharmony_ci * @match_value:
31362306a36Sopenharmony_ci *		     Value the watcher will match against
31462306a36Sopenharmony_ci * @qos:	QoS queue for packets matching this watcher
31562306a36Sopenharmony_ci */
31662306a36Sopenharmony_cistatic inline void cvmx_pip_config_watcher(uint64_t watcher,
31762306a36Sopenharmony_ci					   cvmx_pip_qos_watch_types match_type,
31862306a36Sopenharmony_ci					   uint64_t match_value, uint64_t qos)
31962306a36Sopenharmony_ci{
32062306a36Sopenharmony_ci	cvmx_pip_port_watcher_cfg_t watcher_config;
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ci	watcher_config.u64 = 0;
32362306a36Sopenharmony_ci	watcher_config.s.match_type = match_type;
32462306a36Sopenharmony_ci	watcher_config.s.match_value = match_value;
32562306a36Sopenharmony_ci	watcher_config.s.qos = qos;
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_QOS_WATCHX(watcher), watcher_config.u64);
32862306a36Sopenharmony_ci}
32962306a36Sopenharmony_ci#endif
33062306a36Sopenharmony_ci/**
33162306a36Sopenharmony_ci * Configure the VLAN priority to QoS queue mapping.
33262306a36Sopenharmony_ci *
33362306a36Sopenharmony_ci * @vlan_priority:
33462306a36Sopenharmony_ci *		 VLAN priority (0-7)
33562306a36Sopenharmony_ci * @qos:    QoS queue for packets matching this watcher
33662306a36Sopenharmony_ci */
33762306a36Sopenharmony_cistatic inline void cvmx_pip_config_vlan_qos(uint64_t vlan_priority,
33862306a36Sopenharmony_ci					    uint64_t qos)
33962306a36Sopenharmony_ci{
34062306a36Sopenharmony_ci	union cvmx_pip_qos_vlanx pip_qos_vlanx;
34162306a36Sopenharmony_ci	pip_qos_vlanx.u64 = 0;
34262306a36Sopenharmony_ci	pip_qos_vlanx.s.qos = qos;
34362306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_QOS_VLANX(vlan_priority), pip_qos_vlanx.u64);
34462306a36Sopenharmony_ci}
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ci/**
34762306a36Sopenharmony_ci * Configure the Diffserv to QoS queue mapping.
34862306a36Sopenharmony_ci *
34962306a36Sopenharmony_ci * @diffserv: Diffserv field value (0-63)
35062306a36Sopenharmony_ci * @qos:      QoS queue for packets matching this watcher
35162306a36Sopenharmony_ci */
35262306a36Sopenharmony_cistatic inline void cvmx_pip_config_diffserv_qos(uint64_t diffserv, uint64_t qos)
35362306a36Sopenharmony_ci{
35462306a36Sopenharmony_ci	union cvmx_pip_qos_diffx pip_qos_diffx;
35562306a36Sopenharmony_ci	pip_qos_diffx.u64 = 0;
35662306a36Sopenharmony_ci	pip_qos_diffx.s.qos = qos;
35762306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_QOS_DIFFX(diffserv), pip_qos_diffx.u64);
35862306a36Sopenharmony_ci}
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci/**
36162306a36Sopenharmony_ci * Get the status counters for a port.
36262306a36Sopenharmony_ci *
36362306a36Sopenharmony_ci * @port_num: Port number to get statistics for.
36462306a36Sopenharmony_ci * @clear:    Set to 1 to clear the counters after they are read
36562306a36Sopenharmony_ci * @status:   Where to put the results.
36662306a36Sopenharmony_ci */
36762306a36Sopenharmony_cistatic inline void cvmx_pip_get_port_status(uint64_t port_num, uint64_t clear,
36862306a36Sopenharmony_ci					    cvmx_pip_port_status_t *status)
36962306a36Sopenharmony_ci{
37062306a36Sopenharmony_ci	union cvmx_pip_stat_ctl pip_stat_ctl;
37162306a36Sopenharmony_ci	union cvmx_pip_stat0_prtx stat0;
37262306a36Sopenharmony_ci	union cvmx_pip_stat1_prtx stat1;
37362306a36Sopenharmony_ci	union cvmx_pip_stat2_prtx stat2;
37462306a36Sopenharmony_ci	union cvmx_pip_stat3_prtx stat3;
37562306a36Sopenharmony_ci	union cvmx_pip_stat4_prtx stat4;
37662306a36Sopenharmony_ci	union cvmx_pip_stat5_prtx stat5;
37762306a36Sopenharmony_ci	union cvmx_pip_stat6_prtx stat6;
37862306a36Sopenharmony_ci	union cvmx_pip_stat7_prtx stat7;
37962306a36Sopenharmony_ci	union cvmx_pip_stat8_prtx stat8;
38062306a36Sopenharmony_ci	union cvmx_pip_stat9_prtx stat9;
38162306a36Sopenharmony_ci	union cvmx_pip_stat_inb_pktsx pip_stat_inb_pktsx;
38262306a36Sopenharmony_ci	union cvmx_pip_stat_inb_octsx pip_stat_inb_octsx;
38362306a36Sopenharmony_ci	union cvmx_pip_stat_inb_errsx pip_stat_inb_errsx;
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci	pip_stat_ctl.u64 = 0;
38662306a36Sopenharmony_ci	pip_stat_ctl.s.rdclr = clear;
38762306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PIP_STAT_CTL, pip_stat_ctl.u64);
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_ci	stat0.u64 = cvmx_read_csr(CVMX_PIP_STAT0_PRTX(port_num));
39062306a36Sopenharmony_ci	stat1.u64 = cvmx_read_csr(CVMX_PIP_STAT1_PRTX(port_num));
39162306a36Sopenharmony_ci	stat2.u64 = cvmx_read_csr(CVMX_PIP_STAT2_PRTX(port_num));
39262306a36Sopenharmony_ci	stat3.u64 = cvmx_read_csr(CVMX_PIP_STAT3_PRTX(port_num));
39362306a36Sopenharmony_ci	stat4.u64 = cvmx_read_csr(CVMX_PIP_STAT4_PRTX(port_num));
39462306a36Sopenharmony_ci	stat5.u64 = cvmx_read_csr(CVMX_PIP_STAT5_PRTX(port_num));
39562306a36Sopenharmony_ci	stat6.u64 = cvmx_read_csr(CVMX_PIP_STAT6_PRTX(port_num));
39662306a36Sopenharmony_ci	stat7.u64 = cvmx_read_csr(CVMX_PIP_STAT7_PRTX(port_num));
39762306a36Sopenharmony_ci	stat8.u64 = cvmx_read_csr(CVMX_PIP_STAT8_PRTX(port_num));
39862306a36Sopenharmony_ci	stat9.u64 = cvmx_read_csr(CVMX_PIP_STAT9_PRTX(port_num));
39962306a36Sopenharmony_ci	pip_stat_inb_pktsx.u64 =
40062306a36Sopenharmony_ci	    cvmx_read_csr(CVMX_PIP_STAT_INB_PKTSX(port_num));
40162306a36Sopenharmony_ci	pip_stat_inb_octsx.u64 =
40262306a36Sopenharmony_ci	    cvmx_read_csr(CVMX_PIP_STAT_INB_OCTSX(port_num));
40362306a36Sopenharmony_ci	pip_stat_inb_errsx.u64 =
40462306a36Sopenharmony_ci	    cvmx_read_csr(CVMX_PIP_STAT_INB_ERRSX(port_num));
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci	status->dropped_octets = stat0.s.drp_octs;
40762306a36Sopenharmony_ci	status->dropped_packets = stat0.s.drp_pkts;
40862306a36Sopenharmony_ci	status->octets = stat1.s.octs;
40962306a36Sopenharmony_ci	status->pci_raw_packets = stat2.s.raw;
41062306a36Sopenharmony_ci	status->packets = stat2.s.pkts;
41162306a36Sopenharmony_ci	status->multicast_packets = stat3.s.mcst;
41262306a36Sopenharmony_ci	status->broadcast_packets = stat3.s.bcst;
41362306a36Sopenharmony_ci	status->len_64_packets = stat4.s.h64;
41462306a36Sopenharmony_ci	status->len_65_127_packets = stat4.s.h65to127;
41562306a36Sopenharmony_ci	status->len_128_255_packets = stat5.s.h128to255;
41662306a36Sopenharmony_ci	status->len_256_511_packets = stat5.s.h256to511;
41762306a36Sopenharmony_ci	status->len_512_1023_packets = stat6.s.h512to1023;
41862306a36Sopenharmony_ci	status->len_1024_1518_packets = stat6.s.h1024to1518;
41962306a36Sopenharmony_ci	status->len_1519_max_packets = stat7.s.h1519;
42062306a36Sopenharmony_ci	status->fcs_align_err_packets = stat7.s.fcs;
42162306a36Sopenharmony_ci	status->runt_packets = stat8.s.undersz;
42262306a36Sopenharmony_ci	status->runt_crc_packets = stat8.s.frag;
42362306a36Sopenharmony_ci	status->oversize_packets = stat9.s.oversz;
42462306a36Sopenharmony_ci	status->oversize_crc_packets = stat9.s.jabber;
42562306a36Sopenharmony_ci	status->inb_packets = pip_stat_inb_pktsx.s.pkts;
42662306a36Sopenharmony_ci	status->inb_octets = pip_stat_inb_octsx.s.octs;
42762306a36Sopenharmony_ci	status->inb_errors = pip_stat_inb_errsx.s.errs;
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_ci	if (cvmx_octeon_is_pass1()) {
43062306a36Sopenharmony_ci		/*
43162306a36Sopenharmony_ci		 * Kludge to fix Octeon Pass 1 errata - Drop counts
43262306a36Sopenharmony_ci		 * don't work.
43362306a36Sopenharmony_ci		 */
43462306a36Sopenharmony_ci		if (status->inb_packets > status->packets)
43562306a36Sopenharmony_ci			status->dropped_packets =
43662306a36Sopenharmony_ci			    status->inb_packets - status->packets;
43762306a36Sopenharmony_ci		else
43862306a36Sopenharmony_ci			status->dropped_packets = 0;
43962306a36Sopenharmony_ci		if (status->inb_octets - status->inb_packets * 4 >
44062306a36Sopenharmony_ci		    status->octets)
44162306a36Sopenharmony_ci			status->dropped_octets =
44262306a36Sopenharmony_ci			    status->inb_octets - status->inb_packets * 4 -
44362306a36Sopenharmony_ci			    status->octets;
44462306a36Sopenharmony_ci		else
44562306a36Sopenharmony_ci			status->dropped_octets = 0;
44662306a36Sopenharmony_ci	}
44762306a36Sopenharmony_ci}
44862306a36Sopenharmony_ci
44962306a36Sopenharmony_ci/**
45062306a36Sopenharmony_ci * Configure the hardware CRC engine
45162306a36Sopenharmony_ci *
45262306a36Sopenharmony_ci * @interface: Interface to configure (0 or 1)
45362306a36Sopenharmony_ci * @invert_result:
45462306a36Sopenharmony_ci *		   Invert the result of the CRC
45562306a36Sopenharmony_ci * @reflect:  Reflect
45662306a36Sopenharmony_ci * @initialization_vector:
45762306a36Sopenharmony_ci *		   CRC initialization vector
45862306a36Sopenharmony_ci */
45962306a36Sopenharmony_cistatic inline void cvmx_pip_config_crc(uint64_t interface,
46062306a36Sopenharmony_ci				       uint64_t invert_result, uint64_t reflect,
46162306a36Sopenharmony_ci				       uint32_t initialization_vector)
46262306a36Sopenharmony_ci{
46362306a36Sopenharmony_ci	if (OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
46462306a36Sopenharmony_ci		union cvmx_pip_crc_ctlx config;
46562306a36Sopenharmony_ci		union cvmx_pip_crc_ivx pip_crc_ivx;
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_ci		config.u64 = 0;
46862306a36Sopenharmony_ci		config.s.invres = invert_result;
46962306a36Sopenharmony_ci		config.s.reflect = reflect;
47062306a36Sopenharmony_ci		cvmx_write_csr(CVMX_PIP_CRC_CTLX(interface), config.u64);
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_ci		pip_crc_ivx.u64 = 0;
47362306a36Sopenharmony_ci		pip_crc_ivx.s.iv = initialization_vector;
47462306a36Sopenharmony_ci		cvmx_write_csr(CVMX_PIP_CRC_IVX(interface), pip_crc_ivx.u64);
47562306a36Sopenharmony_ci	}
47662306a36Sopenharmony_ci}
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci/**
47962306a36Sopenharmony_ci * Clear all bits in a tag mask. This should be called on
48062306a36Sopenharmony_ci * startup before any calls to cvmx_pip_tag_mask_set. Each bit
48162306a36Sopenharmony_ci * set in the final mask represent a byte used in the packet for
48262306a36Sopenharmony_ci * tag generation.
48362306a36Sopenharmony_ci *
48462306a36Sopenharmony_ci * @mask_index: Which tag mask to clear (0..3)
48562306a36Sopenharmony_ci */
48662306a36Sopenharmony_cistatic inline void cvmx_pip_tag_mask_clear(uint64_t mask_index)
48762306a36Sopenharmony_ci{
48862306a36Sopenharmony_ci	uint64_t index;
48962306a36Sopenharmony_ci	union cvmx_pip_tag_incx pip_tag_incx;
49062306a36Sopenharmony_ci	pip_tag_incx.u64 = 0;
49162306a36Sopenharmony_ci	pip_tag_incx.s.en = 0;
49262306a36Sopenharmony_ci	for (index = mask_index * 16; index < (mask_index + 1) * 16; index++)
49362306a36Sopenharmony_ci		cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
49462306a36Sopenharmony_ci}
49562306a36Sopenharmony_ci
49662306a36Sopenharmony_ci/**
49762306a36Sopenharmony_ci * Sets a range of bits in the tag mask. The tag mask is used
49862306a36Sopenharmony_ci * when the cvmx_pip_port_tag_cfg_t tag_mode is non zero.
49962306a36Sopenharmony_ci * There are four separate masks that can be configured.
50062306a36Sopenharmony_ci *
50162306a36Sopenharmony_ci * @mask_index: Which tag mask to modify (0..3)
50262306a36Sopenharmony_ci * @offset: Offset into the bitmask to set bits at. Use the GCC macro
50362306a36Sopenharmony_ci *	    offsetof() to determine the offsets into packet headers.
50462306a36Sopenharmony_ci *	    For example, offsetof(ethhdr, protocol) returns the offset
50562306a36Sopenharmony_ci *	    of the ethernet protocol field.  The bitmask selects which
50662306a36Sopenharmony_ci *	    bytes to include the tag, with bit offset X selecting
50762306a36Sopenharmony_ci *	    byte at offset X from the beginning of the packet data.
50862306a36Sopenharmony_ci * @len:    Number of bytes to include. Usually this is the sizeof()
50962306a36Sopenharmony_ci *	    the field.
51062306a36Sopenharmony_ci */
51162306a36Sopenharmony_cistatic inline void cvmx_pip_tag_mask_set(uint64_t mask_index, uint64_t offset,
51262306a36Sopenharmony_ci					 uint64_t len)
51362306a36Sopenharmony_ci{
51462306a36Sopenharmony_ci	while (len--) {
51562306a36Sopenharmony_ci		union cvmx_pip_tag_incx pip_tag_incx;
51662306a36Sopenharmony_ci		uint64_t index = mask_index * 16 + offset / 8;
51762306a36Sopenharmony_ci		pip_tag_incx.u64 = cvmx_read_csr(CVMX_PIP_TAG_INCX(index));
51862306a36Sopenharmony_ci		pip_tag_incx.s.en |= 0x80 >> (offset & 0x7);
51962306a36Sopenharmony_ci		cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
52062306a36Sopenharmony_ci		offset++;
52162306a36Sopenharmony_ci	}
52262306a36Sopenharmony_ci}
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_ci#endif /*  __CVMX_PIP_H__ */
525