xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_tcp_ip.h (revision 9768746b)
1 /*
2  * Copyright (c) 2018-2019 Cavium, Inc.
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef __ECORE_TCP_IP_H
31 #define __ECORE_TCP_IP_H
32 
33 #define VLAN_VID_MASK	0x0fff /* VLAN Identifier */
34 #define ETH_P_8021Q	0x8100          /* 802.1Q VLAN Extended Header  */
35 #define ETH_P_8021AD	0x88A8          /* 802.1ad Service VLAN		*/
36 #define ETH_P_IPV6	0x86DD		/* IPv6 over bluebook		*/
37 #define ETH_P_IP	0x0800		/* Internet Protocol packet	*/
38 #define ETH_HLEN	14		/* Total octets in header.	 */
39 #define VLAN_HLEN       4               /* additional bytes required by VLAN */
40 #define MAX_VLAN_PRIO	7	/* Max vlan priority value in 801.1Q tag */
41 
42 #define MAX_DSCP		63 /* Max DSCP value in IP header */
43 #define IPPROTO_TCP	6
44 
45 #ifndef htonl
46 #define htonl(val) OSAL_CPU_TO_BE32(val)
47 #endif
48 
49 #ifndef ntohl
50 #define ntohl(val) OSAL_BE32_TO_CPU(val)
51 #endif
52 
53 #ifndef htons
54 #define htons(val) OSAL_CPU_TO_BE16(val)
55 #endif
56 
57 #ifndef ntohs
58 #define ntohs(val) OSAL_BE16_TO_CPU(val)
59 #endif
60 
61 struct ecore_ethhdr {
62 	unsigned char	h_dest[ETH_ALEN];	/* destination eth addr	*/
63 	unsigned char	h_source[ETH_ALEN];	/* source ether addr	*/
64 	u16		h_proto;		/* packet type ID field	*/
65 };
66 
67 struct ecore_iphdr {
68 	u8	ihl:4,
69 		version:4;
70 	u8	tos;
71 	u16	tot_len;
72 	u16	id;
73 	u16	frag_off;
74 	u8	ttl;
75 	u8	protocol;
76 	u16	check;
77 	u32	saddr;
78 	u32	daddr;
79 	/*The options start here. */
80 };
81 
82 struct ecore_vlan_ethhdr {
83 	unsigned char	h_dest[ETH_ALEN];
84 	unsigned char	h_source[ETH_ALEN];
85 	u16		h_vlan_proto;
86 	u16		h_vlan_TCI;
87 	u16		h_vlan_encapsulated_proto;
88 };
89 
90 struct ecore_in6_addr {
91 	union {
92 		u8		u6_addr8[16];
93 		u16		u6_addr16[8];
94 		u32		u6_addr32[4];
95 	} in6_u;
96 };
97 
98 struct ecore_ipv6hdr {
99 	u8			priority:4,
100 				version:4;
101 	u8			flow_lbl[3];
102 
103 	u16			payload_len;
104 	u8			nexthdr;
105 	u8			hop_limit;
106 
107 	struct	ecore_in6_addr	saddr;
108 	struct	ecore_in6_addr	daddr;
109 };
110 
111 struct ecore_tcphdr {
112 	u16	source;
113 	u16	dest;
114 	u32	seq;
115 	u32	ack_seq;
116 	u16	res1:4,
117 		doff:4,
118 		fin:1,
119 		syn:1,
120 		rst:1,
121 		psh:1,
122 		ack:1,
123 		urg:1,
124 		ece:1,
125 		cwr:1;
126 	u16	window;
127 	u16	check;
128 	u16	urg_ptr;
129 };
130 
131 enum {
132 	INET_ECN_NOT_ECT = 0,
133 	INET_ECN_ECT_1 = 1,
134 	INET_ECN_ECT_0 = 2,
135 	INET_ECN_CE = 3,
136 	INET_ECN_MASK = 3,
137 };
138 
139 #endif
140