xref: /OK3568_Linux_fs/kernel/arch/mips/include/asm/octeon/cvmx-pip.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /***********************license start***************
2*4882a593Smuzhiyun  * Author: Cavium Networks
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Contact: support@caviumnetworks.com
5*4882a593Smuzhiyun  * This file is part of the OCTEON SDK
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright (c) 2003-2008 Cavium Networks
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This file is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun  * it under the terms of the GNU General Public License, Version 2, as
11*4882a593Smuzhiyun  * published by the Free Software Foundation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This file is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15*4882a593Smuzhiyun  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16*4882a593Smuzhiyun  * NONINFRINGEMENT.  See the GNU General Public License for more
17*4882a593Smuzhiyun  * details.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
20*4882a593Smuzhiyun  * along with this file; if not, write to the Free Software
21*4882a593Smuzhiyun  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22*4882a593Smuzhiyun  * or visit http://www.gnu.org/licenses/.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * This file may also be available under a different license from Cavium.
25*4882a593Smuzhiyun  * Contact Cavium Networks for more information
26*4882a593Smuzhiyun  ***********************license end**************************************/
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun  * Interface to the hardware Packet Input Processing unit.
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  */
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #ifndef __CVMX_PIP_H__
34*4882a593Smuzhiyun #define __CVMX_PIP_H__
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #include <asm/octeon/cvmx-wqe.h>
37*4882a593Smuzhiyun #include <asm/octeon/cvmx-fpa.h>
38*4882a593Smuzhiyun #include <asm/octeon/cvmx-pip-defs.h>
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #define CVMX_PIP_NUM_INPUT_PORTS		48
41*4882a593Smuzhiyun #define CVMX_PIP_NUM_WATCHERS			4
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /*
44*4882a593Smuzhiyun  * Encodes the different error and exception codes
45*4882a593Smuzhiyun  */
46*4882a593Smuzhiyun typedef enum {
47*4882a593Smuzhiyun 	CVMX_PIP_L4_NO_ERR = 0ull,
48*4882a593Smuzhiyun 	/*
49*4882a593Smuzhiyun 	 * 1 = TCP (UDP) packet not long enough to cover TCP (UDP)
50*4882a593Smuzhiyun 	 * header
51*4882a593Smuzhiyun 	 */
52*4882a593Smuzhiyun 	CVMX_PIP_L4_MAL_ERR = 1ull,
53*4882a593Smuzhiyun 	/* 2  = TCP/UDP checksum failure */
54*4882a593Smuzhiyun 	CVMX_PIP_CHK_ERR = 2ull,
55*4882a593Smuzhiyun 	/*
56*4882a593Smuzhiyun 	 * 3 = TCP/UDP length check (TCP/UDP length does not match IP
57*4882a593Smuzhiyun 	 * length).
58*4882a593Smuzhiyun 	 */
59*4882a593Smuzhiyun 	CVMX_PIP_L4_LENGTH_ERR = 3ull,
60*4882a593Smuzhiyun 	/* 4  = illegal TCP/UDP port (either source or dest port is zero) */
61*4882a593Smuzhiyun 	CVMX_PIP_BAD_PRT_ERR = 4ull,
62*4882a593Smuzhiyun 	/* 8  = TCP flags = FIN only */
63*4882a593Smuzhiyun 	CVMX_PIP_TCP_FLG8_ERR = 8ull,
64*4882a593Smuzhiyun 	/* 9  = TCP flags = 0 */
65*4882a593Smuzhiyun 	CVMX_PIP_TCP_FLG9_ERR = 9ull,
66*4882a593Smuzhiyun 	/* 10 = TCP flags = FIN+RST+* */
67*4882a593Smuzhiyun 	CVMX_PIP_TCP_FLG10_ERR = 10ull,
68*4882a593Smuzhiyun 	/* 11 = TCP flags = SYN+URG+* */
69*4882a593Smuzhiyun 	CVMX_PIP_TCP_FLG11_ERR = 11ull,
70*4882a593Smuzhiyun 	/* 12 = TCP flags = SYN+RST+* */
71*4882a593Smuzhiyun 	CVMX_PIP_TCP_FLG12_ERR = 12ull,
72*4882a593Smuzhiyun 	/* 13 = TCP flags = SYN+FIN+* */
73*4882a593Smuzhiyun 	CVMX_PIP_TCP_FLG13_ERR = 13ull
74*4882a593Smuzhiyun } cvmx_pip_l4_err_t;
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun typedef enum {
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	CVMX_PIP_IP_NO_ERR = 0ull,
79*4882a593Smuzhiyun 	/* 1 = not IPv4 or IPv6 */
80*4882a593Smuzhiyun 	CVMX_PIP_NOT_IP = 1ull,
81*4882a593Smuzhiyun 	/* 2 = IPv4 header checksum violation */
82*4882a593Smuzhiyun 	CVMX_PIP_IPV4_HDR_CHK = 2ull,
83*4882a593Smuzhiyun 	/* 3 = malformed (packet not long enough to cover IP hdr) */
84*4882a593Smuzhiyun 	CVMX_PIP_IP_MAL_HDR = 3ull,
85*4882a593Smuzhiyun 	/* 4 = malformed (packet not long enough to cover len in IP hdr) */
86*4882a593Smuzhiyun 	CVMX_PIP_IP_MAL_PKT = 4ull,
87*4882a593Smuzhiyun 	/* 5 = TTL / hop count equal zero */
88*4882a593Smuzhiyun 	CVMX_PIP_TTL_HOP = 5ull,
89*4882a593Smuzhiyun 	/* 6 = IPv4 options / IPv6 early extension headers */
90*4882a593Smuzhiyun 	CVMX_PIP_OPTS = 6ull
91*4882a593Smuzhiyun } cvmx_pip_ip_exc_t;
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /**
94*4882a593Smuzhiyun  * NOTES
95*4882a593Smuzhiyun  *	 late collision (data received before collision)
96*4882a593Smuzhiyun  *	      late collisions cannot be detected by the receiver
97*4882a593Smuzhiyun  *	      they would appear as JAM bits which would appear as bad FCS
98*4882a593Smuzhiyun  *	      or carrier extend error which is CVMX_PIP_EXTEND_ERR
99*4882a593Smuzhiyun  */
100*4882a593Smuzhiyun typedef enum {
101*4882a593Smuzhiyun 	/* No error */
102*4882a593Smuzhiyun 	CVMX_PIP_RX_NO_ERR = 0ull,
103*4882a593Smuzhiyun 	/* RGM+SPI 1 = partially received packet (buffering/bandwidth
104*4882a593Smuzhiyun 	 * not adequate) */
105*4882a593Smuzhiyun 	CVMX_PIP_PARTIAL_ERR = 1ull,
106*4882a593Smuzhiyun 	/* RGM+SPI 2 = receive packet too large and truncated */
107*4882a593Smuzhiyun 	CVMX_PIP_JABBER_ERR = 2ull,
108*4882a593Smuzhiyun 	/*
109*4882a593Smuzhiyun 	 * RGM 3 = max frame error (pkt len > max frame len) (with FCS
110*4882a593Smuzhiyun 	 * error)
111*4882a593Smuzhiyun 	 */
112*4882a593Smuzhiyun 	CVMX_PIP_OVER_FCS_ERR = 3ull,
113*4882a593Smuzhiyun 	/* RGM+SPI 4 = max frame error (pkt len > max frame len) */
114*4882a593Smuzhiyun 	CVMX_PIP_OVER_ERR = 4ull,
115*4882a593Smuzhiyun 	/*
116*4882a593Smuzhiyun 	 * RGM 5 = nibble error (data not byte multiple - 100M and 10M
117*4882a593Smuzhiyun 	 * only)
118*4882a593Smuzhiyun 	 */
119*4882a593Smuzhiyun 	CVMX_PIP_ALIGN_ERR = 5ull,
120*4882a593Smuzhiyun 	/*
121*4882a593Smuzhiyun 	 * RGM 6 = min frame error (pkt len < min frame len) (with FCS
122*4882a593Smuzhiyun 	 * error)
123*4882a593Smuzhiyun 	 */
124*4882a593Smuzhiyun 	CVMX_PIP_UNDER_FCS_ERR = 6ull,
125*4882a593Smuzhiyun 	/* RGM	   7 = FCS error */
126*4882a593Smuzhiyun 	CVMX_PIP_GMX_FCS_ERR = 7ull,
127*4882a593Smuzhiyun 	/* RGM+SPI 8 = min frame error (pkt len < min frame len) */
128*4882a593Smuzhiyun 	CVMX_PIP_UNDER_ERR = 8ull,
129*4882a593Smuzhiyun 	/* RGM	   9 = Frame carrier extend error */
130*4882a593Smuzhiyun 	CVMX_PIP_EXTEND_ERR = 9ull,
131*4882a593Smuzhiyun 	/*
132*4882a593Smuzhiyun 	 * RGM 10 = length mismatch (len did not match len in L2
133*4882a593Smuzhiyun 	 * length/type)
134*4882a593Smuzhiyun 	 */
135*4882a593Smuzhiyun 	CVMX_PIP_LENGTH_ERR = 10ull,
136*4882a593Smuzhiyun 	/* RGM 11 = Frame error (some or all data bits marked err) */
137*4882a593Smuzhiyun 	CVMX_PIP_DAT_ERR = 11ull,
138*4882a593Smuzhiyun 	/*     SPI 11 = DIP4 error */
139*4882a593Smuzhiyun 	CVMX_PIP_DIP_ERR = 11ull,
140*4882a593Smuzhiyun 	/*
141*4882a593Smuzhiyun 	 * RGM 12 = packet was not large enough to pass the skipper -
142*4882a593Smuzhiyun 	 * no inspection could occur.
143*4882a593Smuzhiyun 	 */
144*4882a593Smuzhiyun 	CVMX_PIP_SKIP_ERR = 12ull,
145*4882a593Smuzhiyun 	/*
146*4882a593Smuzhiyun 	 * RGM 13 = studder error (data not repeated - 100M and 10M
147*4882a593Smuzhiyun 	 * only)
148*4882a593Smuzhiyun 	 */
149*4882a593Smuzhiyun 	CVMX_PIP_NIBBLE_ERR = 13ull,
150*4882a593Smuzhiyun 	/* RGM+SPI 16 = FCS error */
151*4882a593Smuzhiyun 	CVMX_PIP_PIP_FCS = 16L,
152*4882a593Smuzhiyun 	/*
153*4882a593Smuzhiyun 	 * RGM+SPI+PCI 17 = packet was not large enough to pass the
154*4882a593Smuzhiyun 	 * skipper - no inspection could occur.
155*4882a593Smuzhiyun 	 */
156*4882a593Smuzhiyun 	CVMX_PIP_PIP_SKIP_ERR = 17L,
157*4882a593Smuzhiyun 	/*
158*4882a593Smuzhiyun 	 * RGM+SPI+PCI 18 = malformed l2 (packet not long enough to
159*4882a593Smuzhiyun 	 * cover L2 hdr).
160*4882a593Smuzhiyun 	 */
161*4882a593Smuzhiyun 	CVMX_PIP_PIP_L2_MAL_HDR = 18L
162*4882a593Smuzhiyun 	/*
163*4882a593Smuzhiyun 	 * NOTES: xx = late collision (data received before collision)
164*4882a593Smuzhiyun 	 *	 late collisions cannot be detected by the receiver
165*4882a593Smuzhiyun 	 *	 they would appear as JAM bits which would appear as
166*4882a593Smuzhiyun 	 *	 bad FCS or carrier extend error which is
167*4882a593Smuzhiyun 	 *	 CVMX_PIP_EXTEND_ERR
168*4882a593Smuzhiyun 	 */
169*4882a593Smuzhiyun } cvmx_pip_rcv_err_t;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun /**
172*4882a593Smuzhiyun  * This defines the err_code field errors in the work Q entry
173*4882a593Smuzhiyun  */
174*4882a593Smuzhiyun typedef union {
175*4882a593Smuzhiyun 	cvmx_pip_l4_err_t l4_err;
176*4882a593Smuzhiyun 	cvmx_pip_ip_exc_t ip_exc;
177*4882a593Smuzhiyun 	cvmx_pip_rcv_err_t rcv_err;
178*4882a593Smuzhiyun } cvmx_pip_err_t;
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun /**
181*4882a593Smuzhiyun  * Status statistics for a port
182*4882a593Smuzhiyun  */
183*4882a593Smuzhiyun typedef struct {
184*4882a593Smuzhiyun 	/* Inbound octets marked to be dropped by the IPD */
185*4882a593Smuzhiyun 	uint32_t dropped_octets;
186*4882a593Smuzhiyun 	/* Inbound packets marked to be dropped by the IPD */
187*4882a593Smuzhiyun 	uint32_t dropped_packets;
188*4882a593Smuzhiyun 	/* RAW PCI Packets received by PIP per port */
189*4882a593Smuzhiyun 	uint32_t pci_raw_packets;
190*4882a593Smuzhiyun 	/* Number of octets processed by PIP */
191*4882a593Smuzhiyun 	uint32_t octets;
192*4882a593Smuzhiyun 	/* Number of packets processed by PIP */
193*4882a593Smuzhiyun 	uint32_t packets;
194*4882a593Smuzhiyun 	/*
195*4882a593Smuzhiyun 	 * Number of identified L2 multicast packets.	Does not
196*4882a593Smuzhiyun 	 * include broadcast packets.  Only includes packets whose
197*4882a593Smuzhiyun 	 * parse mode is SKIP_TO_L2
198*4882a593Smuzhiyun 	 */
199*4882a593Smuzhiyun 	uint32_t multicast_packets;
200*4882a593Smuzhiyun 	/*
201*4882a593Smuzhiyun 	 * Number of identified L2 broadcast packets.	Does not
202*4882a593Smuzhiyun 	 * include multicast packets.  Only includes packets whose
203*4882a593Smuzhiyun 	 * parse mode is SKIP_TO_L2
204*4882a593Smuzhiyun 	 */
205*4882a593Smuzhiyun 	uint32_t broadcast_packets;
206*4882a593Smuzhiyun 	/* Number of 64B packets */
207*4882a593Smuzhiyun 	uint32_t len_64_packets;
208*4882a593Smuzhiyun 	/* Number of 65-127B packets */
209*4882a593Smuzhiyun 	uint32_t len_65_127_packets;
210*4882a593Smuzhiyun 	/* Number of 128-255B packets */
211*4882a593Smuzhiyun 	uint32_t len_128_255_packets;
212*4882a593Smuzhiyun 	/* Number of 256-511B packets */
213*4882a593Smuzhiyun 	uint32_t len_256_511_packets;
214*4882a593Smuzhiyun 	/* Number of 512-1023B packets */
215*4882a593Smuzhiyun 	uint32_t len_512_1023_packets;
216*4882a593Smuzhiyun 	/* Number of 1024-1518B packets */
217*4882a593Smuzhiyun 	uint32_t len_1024_1518_packets;
218*4882a593Smuzhiyun 	/* Number of 1519-max packets */
219*4882a593Smuzhiyun 	uint32_t len_1519_max_packets;
220*4882a593Smuzhiyun 	/* Number of packets with FCS or Align opcode errors */
221*4882a593Smuzhiyun 	uint32_t fcs_align_err_packets;
222*4882a593Smuzhiyun 	/* Number of packets with length < min */
223*4882a593Smuzhiyun 	uint32_t runt_packets;
224*4882a593Smuzhiyun 	/* Number of packets with length < min and FCS error */
225*4882a593Smuzhiyun 	uint32_t runt_crc_packets;
226*4882a593Smuzhiyun 	/* Number of packets with length > max */
227*4882a593Smuzhiyun 	uint32_t oversize_packets;
228*4882a593Smuzhiyun 	/* Number of packets with length > max and FCS error */
229*4882a593Smuzhiyun 	uint32_t oversize_crc_packets;
230*4882a593Smuzhiyun 	/* Number of packets without GMX/SPX/PCI errors received by PIP */
231*4882a593Smuzhiyun 	uint32_t inb_packets;
232*4882a593Smuzhiyun 	/*
233*4882a593Smuzhiyun 	 * Total number of octets from all packets received by PIP,
234*4882a593Smuzhiyun 	 * including CRC
235*4882a593Smuzhiyun 	 */
236*4882a593Smuzhiyun 	uint64_t inb_octets;
237*4882a593Smuzhiyun 	/* Number of packets with GMX/SPX/PCI errors received by PIP */
238*4882a593Smuzhiyun 	uint16_t inb_errors;
239*4882a593Smuzhiyun } cvmx_pip_port_status_t;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun /**
242*4882a593Smuzhiyun  * Definition of the PIP custom header that can be prepended
243*4882a593Smuzhiyun  * to a packet by external hardware.
244*4882a593Smuzhiyun  */
245*4882a593Smuzhiyun typedef union {
246*4882a593Smuzhiyun 	uint64_t u64;
247*4882a593Smuzhiyun 	struct {
248*4882a593Smuzhiyun 		/*
249*4882a593Smuzhiyun 		 * Documented as R - Set if the Packet is RAWFULL. If
250*4882a593Smuzhiyun 		 * set, this header must be the full 8 bytes.
251*4882a593Smuzhiyun 		 */
252*4882a593Smuzhiyun 		uint64_t rawfull:1;
253*4882a593Smuzhiyun 		/* Must be zero */
254*4882a593Smuzhiyun 		uint64_t reserved0:5;
255*4882a593Smuzhiyun 		/* PIP parse mode for this packet */
256*4882a593Smuzhiyun 		uint64_t parse_mode:2;
257*4882a593Smuzhiyun 		/* Must be zero */
258*4882a593Smuzhiyun 		uint64_t reserved1:1;
259*4882a593Smuzhiyun 		/*
260*4882a593Smuzhiyun 		 * Skip amount, including this header, to the
261*4882a593Smuzhiyun 		 * beginning of the packet
262*4882a593Smuzhiyun 		 */
263*4882a593Smuzhiyun 		uint64_t skip_len:7;
264*4882a593Smuzhiyun 		/* Must be zero */
265*4882a593Smuzhiyun 		uint64_t reserved2:6;
266*4882a593Smuzhiyun 		/* POW input queue for this packet */
267*4882a593Smuzhiyun 		uint64_t qos:3;
268*4882a593Smuzhiyun 		/* POW input group for this packet */
269*4882a593Smuzhiyun 		uint64_t grp:4;
270*4882a593Smuzhiyun 		/*
271*4882a593Smuzhiyun 		 * Flag to store this packet in the work queue entry,
272*4882a593Smuzhiyun 		 * if possible
273*4882a593Smuzhiyun 		 */
274*4882a593Smuzhiyun 		uint64_t rs:1;
275*4882a593Smuzhiyun 		/* POW input tag type */
276*4882a593Smuzhiyun 		uint64_t tag_type:2;
277*4882a593Smuzhiyun 		/* POW input tag */
278*4882a593Smuzhiyun 		uint64_t tag:32;
279*4882a593Smuzhiyun 	} s;
280*4882a593Smuzhiyun } cvmx_pip_pkt_inst_hdr_t;
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun /* CSR typedefs have been moved to cvmx-csr-*.h */
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun /**
285*4882a593Smuzhiyun  * Configure an ethernet input port
286*4882a593Smuzhiyun  *
287*4882a593Smuzhiyun  * @port_num: Port number to configure
288*4882a593Smuzhiyun  * @port_cfg: Port hardware configuration
289*4882a593Smuzhiyun  * @port_tag_cfg:
290*4882a593Smuzhiyun  *		   Port POW tagging configuration
291*4882a593Smuzhiyun  */
cvmx_pip_config_port(uint64_t port_num,union cvmx_pip_prt_cfgx port_cfg,union cvmx_pip_prt_tagx port_tag_cfg)292*4882a593Smuzhiyun static inline void cvmx_pip_config_port(uint64_t port_num,
293*4882a593Smuzhiyun 					union cvmx_pip_prt_cfgx port_cfg,
294*4882a593Smuzhiyun 					union cvmx_pip_prt_tagx port_tag_cfg)
295*4882a593Smuzhiyun {
296*4882a593Smuzhiyun 	cvmx_write_csr(CVMX_PIP_PRT_CFGX(port_num), port_cfg.u64);
297*4882a593Smuzhiyun 	cvmx_write_csr(CVMX_PIP_PRT_TAGX(port_num), port_tag_cfg.u64);
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun #if 0
300*4882a593Smuzhiyun /**
301*4882a593Smuzhiyun  * @deprecated	    This function is a thin wrapper around the Pass1 version
302*4882a593Smuzhiyun  *		    of the CVMX_PIP_QOS_WATCHX CSR; Pass2 has added a field for
303*4882a593Smuzhiyun  *		    setting the group that is incompatible with this function,
304*4882a593Smuzhiyun  *		    the preferred upgrade path is to use the CSR directly.
305*4882a593Smuzhiyun  *
306*4882a593Smuzhiyun  * Configure the global QoS packet watchers. Each watcher is
307*4882a593Smuzhiyun  * capable of matching a field in a packet to determine the
308*4882a593Smuzhiyun  * QoS queue for scheduling.
309*4882a593Smuzhiyun  *
310*4882a593Smuzhiyun  * @watcher:	Watcher number to configure (0 - 3).
311*4882a593Smuzhiyun  * @match_type: Watcher match type
312*4882a593Smuzhiyun  * @match_value:
313*4882a593Smuzhiyun  *		     Value the watcher will match against
314*4882a593Smuzhiyun  * @qos:	QoS queue for packets matching this watcher
315*4882a593Smuzhiyun  */
316*4882a593Smuzhiyun static inline void cvmx_pip_config_watcher(uint64_t watcher,
317*4882a593Smuzhiyun 					   cvmx_pip_qos_watch_types match_type,
318*4882a593Smuzhiyun 					   uint64_t match_value, uint64_t qos)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun 	cvmx_pip_port_watcher_cfg_t watcher_config;
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun 	watcher_config.u64 = 0;
323*4882a593Smuzhiyun 	watcher_config.s.match_type = match_type;
324*4882a593Smuzhiyun 	watcher_config.s.match_value = match_value;
325*4882a593Smuzhiyun 	watcher_config.s.qos = qos;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	cvmx_write_csr(CVMX_PIP_QOS_WATCHX(watcher), watcher_config.u64);
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun #endif
330*4882a593Smuzhiyun /**
331*4882a593Smuzhiyun  * Configure the VLAN priority to QoS queue mapping.
332*4882a593Smuzhiyun  *
333*4882a593Smuzhiyun  * @vlan_priority:
334*4882a593Smuzhiyun  *		 VLAN priority (0-7)
335*4882a593Smuzhiyun  * @qos:    QoS queue for packets matching this watcher
336*4882a593Smuzhiyun  */
cvmx_pip_config_vlan_qos(uint64_t vlan_priority,uint64_t qos)337*4882a593Smuzhiyun static inline void cvmx_pip_config_vlan_qos(uint64_t vlan_priority,
338*4882a593Smuzhiyun 					    uint64_t qos)
339*4882a593Smuzhiyun {
340*4882a593Smuzhiyun 	union cvmx_pip_qos_vlanx pip_qos_vlanx;
341*4882a593Smuzhiyun 	pip_qos_vlanx.u64 = 0;
342*4882a593Smuzhiyun 	pip_qos_vlanx.s.qos = qos;
343*4882a593Smuzhiyun 	cvmx_write_csr(CVMX_PIP_QOS_VLANX(vlan_priority), pip_qos_vlanx.u64);
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun /**
347*4882a593Smuzhiyun  * Configure the Diffserv to QoS queue mapping.
348*4882a593Smuzhiyun  *
349*4882a593Smuzhiyun  * @diffserv: Diffserv field value (0-63)
350*4882a593Smuzhiyun  * @qos:      QoS queue for packets matching this watcher
351*4882a593Smuzhiyun  */
cvmx_pip_config_diffserv_qos(uint64_t diffserv,uint64_t qos)352*4882a593Smuzhiyun static inline void cvmx_pip_config_diffserv_qos(uint64_t diffserv, uint64_t qos)
353*4882a593Smuzhiyun {
354*4882a593Smuzhiyun 	union cvmx_pip_qos_diffx pip_qos_diffx;
355*4882a593Smuzhiyun 	pip_qos_diffx.u64 = 0;
356*4882a593Smuzhiyun 	pip_qos_diffx.s.qos = qos;
357*4882a593Smuzhiyun 	cvmx_write_csr(CVMX_PIP_QOS_DIFFX(diffserv), pip_qos_diffx.u64);
358*4882a593Smuzhiyun }
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun /**
361*4882a593Smuzhiyun  * Get the status counters for a port.
362*4882a593Smuzhiyun  *
363*4882a593Smuzhiyun  * @port_num: Port number to get statistics for.
364*4882a593Smuzhiyun  * @clear:    Set to 1 to clear the counters after they are read
365*4882a593Smuzhiyun  * @status:   Where to put the results.
366*4882a593Smuzhiyun  */
cvmx_pip_get_port_status(uint64_t port_num,uint64_t clear,cvmx_pip_port_status_t * status)367*4882a593Smuzhiyun static inline void cvmx_pip_get_port_status(uint64_t port_num, uint64_t clear,
368*4882a593Smuzhiyun 					    cvmx_pip_port_status_t *status)
369*4882a593Smuzhiyun {
370*4882a593Smuzhiyun 	union cvmx_pip_stat_ctl pip_stat_ctl;
371*4882a593Smuzhiyun 	union cvmx_pip_stat0_prtx stat0;
372*4882a593Smuzhiyun 	union cvmx_pip_stat1_prtx stat1;
373*4882a593Smuzhiyun 	union cvmx_pip_stat2_prtx stat2;
374*4882a593Smuzhiyun 	union cvmx_pip_stat3_prtx stat3;
375*4882a593Smuzhiyun 	union cvmx_pip_stat4_prtx stat4;
376*4882a593Smuzhiyun 	union cvmx_pip_stat5_prtx stat5;
377*4882a593Smuzhiyun 	union cvmx_pip_stat6_prtx stat6;
378*4882a593Smuzhiyun 	union cvmx_pip_stat7_prtx stat7;
379*4882a593Smuzhiyun 	union cvmx_pip_stat8_prtx stat8;
380*4882a593Smuzhiyun 	union cvmx_pip_stat9_prtx stat9;
381*4882a593Smuzhiyun 	union cvmx_pip_stat_inb_pktsx pip_stat_inb_pktsx;
382*4882a593Smuzhiyun 	union cvmx_pip_stat_inb_octsx pip_stat_inb_octsx;
383*4882a593Smuzhiyun 	union cvmx_pip_stat_inb_errsx pip_stat_inb_errsx;
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun 	pip_stat_ctl.u64 = 0;
386*4882a593Smuzhiyun 	pip_stat_ctl.s.rdclr = clear;
387*4882a593Smuzhiyun 	cvmx_write_csr(CVMX_PIP_STAT_CTL, pip_stat_ctl.u64);
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun 	stat0.u64 = cvmx_read_csr(CVMX_PIP_STAT0_PRTX(port_num));
390*4882a593Smuzhiyun 	stat1.u64 = cvmx_read_csr(CVMX_PIP_STAT1_PRTX(port_num));
391*4882a593Smuzhiyun 	stat2.u64 = cvmx_read_csr(CVMX_PIP_STAT2_PRTX(port_num));
392*4882a593Smuzhiyun 	stat3.u64 = cvmx_read_csr(CVMX_PIP_STAT3_PRTX(port_num));
393*4882a593Smuzhiyun 	stat4.u64 = cvmx_read_csr(CVMX_PIP_STAT4_PRTX(port_num));
394*4882a593Smuzhiyun 	stat5.u64 = cvmx_read_csr(CVMX_PIP_STAT5_PRTX(port_num));
395*4882a593Smuzhiyun 	stat6.u64 = cvmx_read_csr(CVMX_PIP_STAT6_PRTX(port_num));
396*4882a593Smuzhiyun 	stat7.u64 = cvmx_read_csr(CVMX_PIP_STAT7_PRTX(port_num));
397*4882a593Smuzhiyun 	stat8.u64 = cvmx_read_csr(CVMX_PIP_STAT8_PRTX(port_num));
398*4882a593Smuzhiyun 	stat9.u64 = cvmx_read_csr(CVMX_PIP_STAT9_PRTX(port_num));
399*4882a593Smuzhiyun 	pip_stat_inb_pktsx.u64 =
400*4882a593Smuzhiyun 	    cvmx_read_csr(CVMX_PIP_STAT_INB_PKTSX(port_num));
401*4882a593Smuzhiyun 	pip_stat_inb_octsx.u64 =
402*4882a593Smuzhiyun 	    cvmx_read_csr(CVMX_PIP_STAT_INB_OCTSX(port_num));
403*4882a593Smuzhiyun 	pip_stat_inb_errsx.u64 =
404*4882a593Smuzhiyun 	    cvmx_read_csr(CVMX_PIP_STAT_INB_ERRSX(port_num));
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun 	status->dropped_octets = stat0.s.drp_octs;
407*4882a593Smuzhiyun 	status->dropped_packets = stat0.s.drp_pkts;
408*4882a593Smuzhiyun 	status->octets = stat1.s.octs;
409*4882a593Smuzhiyun 	status->pci_raw_packets = stat2.s.raw;
410*4882a593Smuzhiyun 	status->packets = stat2.s.pkts;
411*4882a593Smuzhiyun 	status->multicast_packets = stat3.s.mcst;
412*4882a593Smuzhiyun 	status->broadcast_packets = stat3.s.bcst;
413*4882a593Smuzhiyun 	status->len_64_packets = stat4.s.h64;
414*4882a593Smuzhiyun 	status->len_65_127_packets = stat4.s.h65to127;
415*4882a593Smuzhiyun 	status->len_128_255_packets = stat5.s.h128to255;
416*4882a593Smuzhiyun 	status->len_256_511_packets = stat5.s.h256to511;
417*4882a593Smuzhiyun 	status->len_512_1023_packets = stat6.s.h512to1023;
418*4882a593Smuzhiyun 	status->len_1024_1518_packets = stat6.s.h1024to1518;
419*4882a593Smuzhiyun 	status->len_1519_max_packets = stat7.s.h1519;
420*4882a593Smuzhiyun 	status->fcs_align_err_packets = stat7.s.fcs;
421*4882a593Smuzhiyun 	status->runt_packets = stat8.s.undersz;
422*4882a593Smuzhiyun 	status->runt_crc_packets = stat8.s.frag;
423*4882a593Smuzhiyun 	status->oversize_packets = stat9.s.oversz;
424*4882a593Smuzhiyun 	status->oversize_crc_packets = stat9.s.jabber;
425*4882a593Smuzhiyun 	status->inb_packets = pip_stat_inb_pktsx.s.pkts;
426*4882a593Smuzhiyun 	status->inb_octets = pip_stat_inb_octsx.s.octs;
427*4882a593Smuzhiyun 	status->inb_errors = pip_stat_inb_errsx.s.errs;
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	if (cvmx_octeon_is_pass1()) {
430*4882a593Smuzhiyun 		/*
431*4882a593Smuzhiyun 		 * Kludge to fix Octeon Pass 1 errata - Drop counts
432*4882a593Smuzhiyun 		 * don't work.
433*4882a593Smuzhiyun 		 */
434*4882a593Smuzhiyun 		if (status->inb_packets > status->packets)
435*4882a593Smuzhiyun 			status->dropped_packets =
436*4882a593Smuzhiyun 			    status->inb_packets - status->packets;
437*4882a593Smuzhiyun 		else
438*4882a593Smuzhiyun 			status->dropped_packets = 0;
439*4882a593Smuzhiyun 		if (status->inb_octets - status->inb_packets * 4 >
440*4882a593Smuzhiyun 		    status->octets)
441*4882a593Smuzhiyun 			status->dropped_octets =
442*4882a593Smuzhiyun 			    status->inb_octets - status->inb_packets * 4 -
443*4882a593Smuzhiyun 			    status->octets;
444*4882a593Smuzhiyun 		else
445*4882a593Smuzhiyun 			status->dropped_octets = 0;
446*4882a593Smuzhiyun 	}
447*4882a593Smuzhiyun }
448*4882a593Smuzhiyun 
449*4882a593Smuzhiyun /**
450*4882a593Smuzhiyun  * Configure the hardware CRC engine
451*4882a593Smuzhiyun  *
452*4882a593Smuzhiyun  * @interface: Interface to configure (0 or 1)
453*4882a593Smuzhiyun  * @invert_result:
454*4882a593Smuzhiyun  *		   Invert the result of the CRC
455*4882a593Smuzhiyun  * @reflect:  Reflect
456*4882a593Smuzhiyun  * @initialization_vector:
457*4882a593Smuzhiyun  *		   CRC initialization vector
458*4882a593Smuzhiyun  */
cvmx_pip_config_crc(uint64_t interface,uint64_t invert_result,uint64_t reflect,uint32_t initialization_vector)459*4882a593Smuzhiyun static inline void cvmx_pip_config_crc(uint64_t interface,
460*4882a593Smuzhiyun 				       uint64_t invert_result, uint64_t reflect,
461*4882a593Smuzhiyun 				       uint32_t initialization_vector)
462*4882a593Smuzhiyun {
463*4882a593Smuzhiyun 	if (OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
464*4882a593Smuzhiyun 		union cvmx_pip_crc_ctlx config;
465*4882a593Smuzhiyun 		union cvmx_pip_crc_ivx pip_crc_ivx;
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun 		config.u64 = 0;
468*4882a593Smuzhiyun 		config.s.invres = invert_result;
469*4882a593Smuzhiyun 		config.s.reflect = reflect;
470*4882a593Smuzhiyun 		cvmx_write_csr(CVMX_PIP_CRC_CTLX(interface), config.u64);
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun 		pip_crc_ivx.u64 = 0;
473*4882a593Smuzhiyun 		pip_crc_ivx.s.iv = initialization_vector;
474*4882a593Smuzhiyun 		cvmx_write_csr(CVMX_PIP_CRC_IVX(interface), pip_crc_ivx.u64);
475*4882a593Smuzhiyun 	}
476*4882a593Smuzhiyun }
477*4882a593Smuzhiyun 
478*4882a593Smuzhiyun /**
479*4882a593Smuzhiyun  * Clear all bits in a tag mask. This should be called on
480*4882a593Smuzhiyun  * startup before any calls to cvmx_pip_tag_mask_set. Each bit
481*4882a593Smuzhiyun  * set in the final mask represent a byte used in the packet for
482*4882a593Smuzhiyun  * tag generation.
483*4882a593Smuzhiyun  *
484*4882a593Smuzhiyun  * @mask_index: Which tag mask to clear (0..3)
485*4882a593Smuzhiyun  */
cvmx_pip_tag_mask_clear(uint64_t mask_index)486*4882a593Smuzhiyun static inline void cvmx_pip_tag_mask_clear(uint64_t mask_index)
487*4882a593Smuzhiyun {
488*4882a593Smuzhiyun 	uint64_t index;
489*4882a593Smuzhiyun 	union cvmx_pip_tag_incx pip_tag_incx;
490*4882a593Smuzhiyun 	pip_tag_incx.u64 = 0;
491*4882a593Smuzhiyun 	pip_tag_incx.s.en = 0;
492*4882a593Smuzhiyun 	for (index = mask_index * 16; index < (mask_index + 1) * 16; index++)
493*4882a593Smuzhiyun 		cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun /**
497*4882a593Smuzhiyun  * Sets a range of bits in the tag mask. The tag mask is used
498*4882a593Smuzhiyun  * when the cvmx_pip_port_tag_cfg_t tag_mode is non zero.
499*4882a593Smuzhiyun  * There are four separate masks that can be configured.
500*4882a593Smuzhiyun  *
501*4882a593Smuzhiyun  * @mask_index: Which tag mask to modify (0..3)
502*4882a593Smuzhiyun  * @offset: Offset into the bitmask to set bits at. Use the GCC macro
503*4882a593Smuzhiyun  *	    offsetof() to determine the offsets into packet headers.
504*4882a593Smuzhiyun  *	    For example, offsetof(ethhdr, protocol) returns the offset
505*4882a593Smuzhiyun  *	    of the ethernet protocol field.  The bitmask selects which
506*4882a593Smuzhiyun  *	    bytes to include the tag, with bit offset X selecting
507*4882a593Smuzhiyun  *	    byte at offset X from the beginning of the packet data.
508*4882a593Smuzhiyun  * @len:    Number of bytes to include. Usually this is the sizeof()
509*4882a593Smuzhiyun  *	    the field.
510*4882a593Smuzhiyun  */
cvmx_pip_tag_mask_set(uint64_t mask_index,uint64_t offset,uint64_t len)511*4882a593Smuzhiyun static inline void cvmx_pip_tag_mask_set(uint64_t mask_index, uint64_t offset,
512*4882a593Smuzhiyun 					 uint64_t len)
513*4882a593Smuzhiyun {
514*4882a593Smuzhiyun 	while (len--) {
515*4882a593Smuzhiyun 		union cvmx_pip_tag_incx pip_tag_incx;
516*4882a593Smuzhiyun 		uint64_t index = mask_index * 16 + offset / 8;
517*4882a593Smuzhiyun 		pip_tag_incx.u64 = cvmx_read_csr(CVMX_PIP_TAG_INCX(index));
518*4882a593Smuzhiyun 		pip_tag_incx.s.en |= 0x80 >> (offset & 0x7);
519*4882a593Smuzhiyun 		cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
520*4882a593Smuzhiyun 		offset++;
521*4882a593Smuzhiyun 	}
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun #endif /*  __CVMX_PIP_H__ */
525