144961713Sgirish /*
244961713Sgirish  * CDDL HEADER START
344961713Sgirish  *
444961713Sgirish  * The contents of this file are subject to the terms of the
544961713Sgirish  * Common Development and Distribution License (the "License").
644961713Sgirish  * You may not use this file except in compliance with the License.
744961713Sgirish  *
844961713Sgirish  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
944961713Sgirish  * or http://www.opensolaris.org/os/licensing.
1044961713Sgirish  * See the License for the specific language governing permissions
1144961713Sgirish  * and limitations under the License.
1244961713Sgirish  *
1344961713Sgirish  * When distributing Covered Code, include this CDDL HEADER in each
1444961713Sgirish  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1544961713Sgirish  * If applicable, add the following below this CDDL HEADER, with the
1644961713Sgirish  * fields enclosed by brackets "[]" replaced with your own identifying
1744961713Sgirish  * information: Portions Copyright [yyyy] [name of copyright owner]
1844961713Sgirish  *
1944961713Sgirish  * CDDL HEADER END
2044961713Sgirish  */
2144961713Sgirish /*
22*4df55fdeSJanie Lu  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2344961713Sgirish  * Use is subject to license terms.
2444961713Sgirish  */
2544961713Sgirish 
2644961713Sgirish #ifndef	_SYS_NXGE_NXGE_FLOW_H
2744961713Sgirish #define	_SYS_NXGE_NXGE_FLOW_H
2844961713Sgirish 
2944961713Sgirish #ifdef	__cplusplus
3044961713Sgirish extern "C" {
3144961713Sgirish #endif
3244961713Sgirish 
3344961713Sgirish #include <netinet/in.h>
3414ea4bb7Ssd #define	S6_addr32	_S6_un._S6_u32
3544961713Sgirish 
3644961713Sgirish typedef struct tcpip4_spec_s {
3744961713Sgirish 	in_addr_t  ip4src;
3844961713Sgirish 	in_addr_t  ip4dst;
3944961713Sgirish 	in_port_t  psrc;
4044961713Sgirish 	in_port_t  pdst;
41*4df55fdeSJanie Lu 	uint8_t	   tos;
4244961713Sgirish } tcpip4_spec_t;
4344961713Sgirish 
4444961713Sgirish typedef struct tcpip6_spec_s {
4544961713Sgirish 	struct in6_addr ip6src;
4644961713Sgirish 	struct in6_addr ip6dst;
4744961713Sgirish 	in_port_t  psrc;
4844961713Sgirish 	in_port_t  pdst;
49*4df55fdeSJanie Lu 	uint8_t	   tos;
5044961713Sgirish } tcpip6_spec_t;
5144961713Sgirish 
5244961713Sgirish typedef struct udpip4_spec_s {
5344961713Sgirish 	in_addr_t  ip4src;
5444961713Sgirish 	in_addr_t  ip4dst;
5544961713Sgirish 	in_port_t  psrc;
5644961713Sgirish 	in_port_t  pdst;
57*4df55fdeSJanie Lu 	uint8_t	   tos;
5844961713Sgirish } udpip4_spec_t;
5944961713Sgirish 
6044961713Sgirish typedef struct udpip6_spec_s {
6144961713Sgirish 	struct in6_addr ip6src;
6244961713Sgirish 	struct in6_addr ip6dst;
6344961713Sgirish 	in_port_t  psrc;
6444961713Sgirish 	in_port_t  pdst;
65*4df55fdeSJanie Lu 	uint8_t	   tos;
6644961713Sgirish } udpip6_spec_t;
6744961713Sgirish 
6844961713Sgirish typedef struct ahip4_spec_s {
6944961713Sgirish 	in_addr_t  ip4src;
7044961713Sgirish 	in_addr_t  ip4dst;
7144961713Sgirish 	uint32_t   spi;
72*4df55fdeSJanie Lu 	uint8_t	   tos;
7344961713Sgirish } ahip4_spec_t;
7444961713Sgirish 
7544961713Sgirish typedef struct ahip6_spec_s {
7644961713Sgirish 	struct in6_addr ip6src;
7744961713Sgirish 	struct in6_addr ip6dst;
7844961713Sgirish 	uint32_t   spi;
79*4df55fdeSJanie Lu 	uint8_t	   tos;
8044961713Sgirish } ahip6_spec_t;
8144961713Sgirish 
8244961713Sgirish typedef ahip4_spec_t espip4_spec_t;
8344961713Sgirish typedef ahip6_spec_t espip6_spec_t;
8444961713Sgirish 
8544961713Sgirish typedef struct rawip4_spec_s {
8644961713Sgirish 	struct in6_addr ip4src;
8744961713Sgirish 	struct in6_addr ip4dst;
8844961713Sgirish 	uint8_t    hdata[64];
8944961713Sgirish } rawip4_spec_t;
9044961713Sgirish 
9144961713Sgirish typedef struct rawip6_spec_s {
9244961713Sgirish 	struct in6_addr ip6src;
9344961713Sgirish 	struct in6_addr ip6dst;
9444961713Sgirish 	uint8_t    hdata[64];
9544961713Sgirish } rawip6_spec_t;
9644961713Sgirish 
9744961713Sgirish 
9844961713Sgirish typedef struct ether_spec_s {
9944961713Sgirish 	uint16_t   ether_type;
10044961713Sgirish 	uint8_t    frame_size;
10144961713Sgirish 	uint8_t    eframe[16];
10244961713Sgirish } ether_spec_t;
10344961713Sgirish 
10444961713Sgirish 
105*4df55fdeSJanie Lu #define	FSPEC_IP4	1
106*4df55fdeSJanie Lu #define	FSPEC_IP6	2
107*4df55fdeSJanie Lu 
10844961713Sgirish typedef struct ip_user_spec_s {
109*4df55fdeSJanie Lu 	uint32_t	ip4src;
110*4df55fdeSJanie Lu 	uint32_t	ip4dst;
111*4df55fdeSJanie Lu 	uint32_t	l4_4_bytes;
112*4df55fdeSJanie Lu 	uint8_t    	tos;
113*4df55fdeSJanie Lu 	uint8_t    	ip_ver;
114*4df55fdeSJanie Lu 	uint8_t    	proto;
11544961713Sgirish } ip_user_spec_t;
11644961713Sgirish 
117*4df55fdeSJanie Lu typedef struct ip6_frag_spec_s {
118*4df55fdeSJanie Lu 	struct in6_addr ip6src;
119*4df55fdeSJanie Lu 	struct in6_addr ip6dst;
120*4df55fdeSJanie Lu 	uint32_t	l4_4_bytes;
121*4df55fdeSJanie Lu 	uint8_t    	tos;
122*4df55fdeSJanie Lu 	uint8_t    	proto;	/* should be 44 */
123*4df55fdeSJanie Lu } ip6_frag_spec_t;
124*4df55fdeSJanie Lu 
125*4df55fdeSJanie Lu 
12644961713Sgirish typedef ether_spec_t arpip_spec_t;
12744961713Sgirish typedef ether_spec_t ether_user_spec_t;
12844961713Sgirish 
129*4df55fdeSJanie Lu struct flow_spec_s {
13044961713Sgirish 	uint32_t  flow_type;
13144961713Sgirish 	union {
13244961713Sgirish 		tcpip4_spec_t tcpip4spec;
13344961713Sgirish 		tcpip6_spec_t tcpip6spec;
13444961713Sgirish 		udpip4_spec_t udpip4spec;
13544961713Sgirish 		udpip6_spec_t udpip6spec;
13644961713Sgirish 		arpip_spec_t  arpipspec;
13744961713Sgirish 		ahip4_spec_t  ahip4spec;
13844961713Sgirish 		ahip6_spec_t  ahip6spec;
13944961713Sgirish 		espip4_spec_t espip4spec;
14044961713Sgirish 		espip6_spec_t espip6spec;
14144961713Sgirish 		rawip4_spec_t rawip4spec;
14244961713Sgirish 		rawip6_spec_t rawip6spec;
14344961713Sgirish 		ether_spec_t  etherspec;
14444961713Sgirish 		ip_user_spec_t  ip_usr_spec;
145*4df55fdeSJanie Lu 		ip6_frag_spec_t  ip6_frag_spec;
14644961713Sgirish 		uint8_t		hdata[64];
14744961713Sgirish 	} uh, um; /* entry, mask */
148*4df55fdeSJanie Lu } __attribute__((packed));
149*4df55fdeSJanie Lu 
150*4df55fdeSJanie Lu typedef struct flow_spec_s flow_spec_t;
15144961713Sgirish 
15244961713Sgirish #define	FSPEC_TCPIP4	0x1	/* TCP/IPv4 Flow */
15344961713Sgirish #define	FSPEC_TCPIP6	0x2	/* TCP/IPv6 */
15444961713Sgirish #define	FSPEC_UDPIP4	0x3	/* UDP/IPv4 */
15544961713Sgirish #define	FSPEC_UDPIP6	0x4	/* UDP/IPv6 */
15644961713Sgirish #define	FSPEC_ARPIP	0x5	/* ARP/IPv4 */
15744961713Sgirish #define	FSPEC_AHIP4	0x6	/* AH/IP4   */
15844961713Sgirish #define	FSPEC_AHIP6	0x7	/* AH/IP6   */
15944961713Sgirish #define	FSPEC_ESPIP4	0x8	/* ESP/IP4  */
16044961713Sgirish #define	FSPEC_ESPIP6	0x9	/* ESP/IP6  */
161*4df55fdeSJanie Lu #define	FSPEC_SCTPIP4	0xA	/* SCTP/IP4  */
162*4df55fdeSJanie Lu #define	FSPEC_SCTPIP6	0xB	/* SCTP/IP6  */
163*4df55fdeSJanie Lu #define	FSPEC_IP6FRAG	0xC	/* IPv6 Fragments */
164*4df55fdeSJanie Lu #define	FSPEC_RAW4	0xD	/* RAW/IP4  */
165*4df55fdeSJanie Lu #define	FSPEC_RAW6	0xE	/* RAW/IP6  */
166*4df55fdeSJanie Lu #define	FSPEC_ETHER	0xF	/* ETHER Programmable  */
167*4df55fdeSJanie Lu #define	FSPEC_IP_USR	0x10	/* IP Programmable  */
168*4df55fdeSJanie Lu #define	FSPEC_HDATA	0x11	/* Pkt Headers eth-da,sa,etype,ip,tcp(Bitmap) */
16944961713Sgirish 
17044961713Sgirish #define	TCAM_IPV6_ADDR(m32, ip6addr) {		\
17144961713Sgirish 		m32[0] = ip6addr.S6_addr32[0]; \
17244961713Sgirish 		m32[1] = ip6addr.S6_addr32[1]; \
17344961713Sgirish 		m32[2] = ip6addr.S6_addr32[2]; \
17444961713Sgirish 		m32[3] = ip6addr.S6_addr32[3]; \
17544961713Sgirish 	}
17644961713Sgirish 
177*4df55fdeSJanie Lu #define	FSPEC_IPV6_ADDR(ip6addr, m32) {		\
178*4df55fdeSJanie Lu 	ip6addr.S6_addr32[0] = m32[0];		\
179*4df55fdeSJanie Lu 	ip6addr.S6_addr32[1] = m32[1];		\
180*4df55fdeSJanie Lu 	ip6addr.S6_addr32[2] = m32[2];		\
181*4df55fdeSJanie Lu 	ip6addr.S6_addr32[3] = m32[3];		\
182*4df55fdeSJanie Lu }
183*4df55fdeSJanie Lu 
18444961713Sgirish #define	TCAM_IPV4_ADDR(m32, ip4addr) (m32 = ip4addr)
185*4df55fdeSJanie Lu #define	FSPEC_IPV4_ADDR(ip4addr, m32) (ip4addr = m32)
186*4df55fdeSJanie Lu 
18744961713Sgirish #define	TCAM_IP_PORTS(port32, dp, sp)	  (port32 = dp | (sp << 16))
188*4df55fdeSJanie Lu #define	FSPEC_IP_PORTS(dp, sp, port32) {	\
189*4df55fdeSJanie Lu 	dp = port32 & 0xff;			\
190*4df55fdeSJanie Lu 	sp = port32 >> 16;			\
191*4df55fdeSJanie Lu }
192*4df55fdeSJanie Lu 
19344961713Sgirish #define	TCAM_IP_CLASS(key, mask, class)	  {		\
19444961713Sgirish 		key = class; \
19544961713Sgirish 		mask = 0x1f; \
19644961713Sgirish 	}
19744961713Sgirish 
19844961713Sgirish #define	TCAM_IP_PROTO(key, mask, proto) {		\
19944961713Sgirish 		key = proto; \
20044961713Sgirish 		mask = 0xff; \
20144961713Sgirish 	}
20244961713Sgirish 
203*4df55fdeSJanie Lu struct flow_resource_s {
20444961713Sgirish 	uint64_t channel_cookie;
20544961713Sgirish 	uint64_t flow_cookie;
206*4df55fdeSJanie Lu 	uint64_t location;
20744961713Sgirish 	flow_spec_t flow_spec;
208*4df55fdeSJanie Lu } __attribute__((packed));
209*4df55fdeSJanie Lu 
210*4df55fdeSJanie Lu typedef struct flow_resource_s flow_resource_t;
211*4df55fdeSJanie Lu 
212*4df55fdeSJanie Lu /* ioctl data structure and cmd types for configuring rx classification */
213*4df55fdeSJanie Lu 
214*4df55fdeSJanie Lu #define	NXGE_RX_CLASS_GCHAN	0x01
215*4df55fdeSJanie Lu #define	NXGE_RX_CLASS_GRULE_CNT	0x02
216*4df55fdeSJanie Lu #define	NXGE_RX_CLASS_GRULE	0x03
217*4df55fdeSJanie Lu #define	NXGE_RX_CLASS_GRULE_ALL	0x04
218*4df55fdeSJanie Lu #define	NXGE_RX_CLASS_RULE_DEL	0x05
219*4df55fdeSJanie Lu #define	NXGE_RX_CLASS_RULE_INS	0x06
220*4df55fdeSJanie Lu 
221*4df55fdeSJanie Lu #define	NXGE_PKT_DISCARD	0xffffffffffffffffULL
222*4df55fdeSJanie Lu 
223*4df55fdeSJanie Lu struct rx_class_cfg_s {
224*4df55fdeSJanie Lu 	uint32_t cmd;
225*4df55fdeSJanie Lu 	uint32_t data; /* the rule DB size or the # rx rings */
226*4df55fdeSJanie Lu 	uint64_t rule_cnt;
227*4df55fdeSJanie Lu 	uint32_t rule_locs[256];
228*4df55fdeSJanie Lu 	flow_resource_t fs;
229*4df55fdeSJanie Lu } __attribute__((packed));
230*4df55fdeSJanie Lu 
231*4df55fdeSJanie Lu typedef struct rx_class_cfg_s rx_class_cfg_t;
232*4df55fdeSJanie Lu 
233*4df55fdeSJanie Lu /*
234*4df55fdeSJanie Lu  * ioctl data structure and cmd types for configuring rx hash
235*4df55fdeSJanie Lu  * for IP tunneled traffic and symmetric mode.
236*4df55fdeSJanie Lu  */
237*4df55fdeSJanie Lu 
238*4df55fdeSJanie Lu #define	NXGE_IPTUN_CFG_ADD_CLS	0x07
239*4df55fdeSJanie Lu #define	NXGE_IPTUN_CFG_SET_HASH	0x08
240*4df55fdeSJanie Lu #define	NXGE_IPTUN_CFG_DEL_CLS	0x09
241*4df55fdeSJanie Lu #define	NXGE_IPTUN_CFG_GET_CLS	0x0a
242*4df55fdeSJanie Lu #define	NXGE_CLS_CFG_SET_SYM	0x0b
243*4df55fdeSJanie Lu #define	NXGE_CLS_CFG_GET_SYM	0x0c
244*4df55fdeSJanie Lu 
245*4df55fdeSJanie Lu #define	IPTUN_PKT_IPV4		1
246*4df55fdeSJanie Lu #define	IPTUN_PKT_IPV6		2
247*4df55fdeSJanie Lu #define	IPTUN_PKT_GRE		3
248*4df55fdeSJanie Lu #define	IPTUN_PKT_GTP		4
249*4df55fdeSJanie Lu #define	OTHER_USR_PKT		5
250*4df55fdeSJanie Lu 
251*4df55fdeSJanie Lu #define	SEL_L4B_0_3		0x0001
252*4df55fdeSJanie Lu #define	SEL_L4B_4_7		0x0002
253*4df55fdeSJanie Lu #define	SEL_L4B_8_11		0x0004
254*4df55fdeSJanie Lu #define	SEL_L4B_12_15		0x0008
255*4df55fdeSJanie Lu #define	SEL_L4B_16_19		0x0010
256*4df55fdeSJanie Lu #define	SEL_L4B_20_23		0x0020
257*4df55fdeSJanie Lu #define	SEL_L4B_24_27		0x0040
258*4df55fdeSJanie Lu #define	SEL_L4B_28_31		0x0080
259*4df55fdeSJanie Lu #define	SEL_L4B_32_35		0x0100
260*4df55fdeSJanie Lu #define	SEL_L4B_36_39		0x0200
261*4df55fdeSJanie Lu 
262*4df55fdeSJanie Lu #define	HASH_IFPORT		0x0001
263*4df55fdeSJanie Lu #define	HASH_L2DA		0x0002
264*4df55fdeSJanie Lu #define	HASH_VLAN		0x0004
265*4df55fdeSJanie Lu #define	HASH_IPSA		0x0008
266*4df55fdeSJanie Lu #define	HASH_IPDA		0x0010
267*4df55fdeSJanie Lu #define	HASH_L3PROTO		0x0020
268*4df55fdeSJanie Lu 
269*4df55fdeSJanie Lu #define	CLS_TCPV4		0x08
270*4df55fdeSJanie Lu #define	CLS_UDPV4		0x09
271*4df55fdeSJanie Lu #define	CLS_AHESPV4		0x0A
272*4df55fdeSJanie Lu #define	CLS_SCTPV4		0x0B
273*4df55fdeSJanie Lu #define	CLS_TCPV6		0x0C
274*4df55fdeSJanie Lu #define	CLS_UDPV6		0x0D
275*4df55fdeSJanie Lu #define	CLS_AHESPV6		0x0E
276*4df55fdeSJanie Lu #define	CLS_SCTPV6		0x0F
277*4df55fdeSJanie Lu #define	CLS_IPV6FRAG		0x1F
278*4df55fdeSJanie Lu 
279*4df55fdeSJanie Lu struct _iptun_cfg {
280*4df55fdeSJanie Lu 	uint8_t		in_pkt_type;
281*4df55fdeSJanie Lu 	uint8_t		l4b0_val;
282*4df55fdeSJanie Lu 	uint8_t		l4b0_mask;
283*4df55fdeSJanie Lu 	uint8_t		l4b23_sel;
284*4df55fdeSJanie Lu 	uint16_t	l4b23_val;
285*4df55fdeSJanie Lu 	uint16_t	l4xor_sel;
286*4df55fdeSJanie Lu 	uint8_t		hash_flags;
287*4df55fdeSJanie Lu } __attribute__((packed));
288*4df55fdeSJanie Lu 
289*4df55fdeSJanie Lu typedef struct _iptun_cfg iptun_cfg_t;
290*4df55fdeSJanie Lu 
291*4df55fdeSJanie Lu struct _cfg_cmd {
292*4df55fdeSJanie Lu 	uint16_t cmd;
293*4df55fdeSJanie Lu 	uint8_t sym;
294*4df55fdeSJanie Lu 	uint8_t	class_id;
295*4df55fdeSJanie Lu 	iptun_cfg_t	iptun_cfg;
296*4df55fdeSJanie Lu } __attribute__((packed));
297*4df55fdeSJanie Lu 
298*4df55fdeSJanie Lu typedef struct _cfg_cmd cfg_cmd_t;
29944961713Sgirish 
30044961713Sgirish #ifdef	__cplusplus
30144961713Sgirish }
30244961713Sgirish #endif
30344961713Sgirish 
30444961713Sgirish #endif	/* _SYS_NXGE_NXGE_FLOW_H */
305