xref: /freebsd/sys/dev/qlnx/qlnxe/tcp_common.h (revision 36712a94975f5bd0d26c85377283b49a2369c82f)
1 /*
2  * Copyright (c) 2017-2018 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 
31 
32 #ifndef __TCP_COMMON__
33 #define __TCP_COMMON__
34 /********************/
35 /* TCP FW CONSTANTS */
36 /********************/
37 
38 #define TCP_INVALID_TIMEOUT_VAL -1
39 
40 
41 /*
42  * OOO opaque data received from LL2
43  */
44 struct ooo_opaque
45 {
46 	__le32 cid /* connection ID  */;
47 	u8 drop_isle /* isle number of the first isle to drop */;
48 	u8 drop_size /* number of isles to drop */;
49 	u8 ooo_opcode /* (use enum tcp_seg_placement_event) */;
50 	u8 ooo_isle /* OOO isle number to add the packet to */;
51 };
52 
53 
54 /*
55  * tcp connect mode enum
56  */
57 enum tcp_connect_mode
58 {
59 	TCP_CONNECT_ACTIVE,
60 	TCP_CONNECT_PASSIVE,
61 	MAX_TCP_CONNECT_MODE
62 };
63 
64 
65 /*
66  * tcp function init parameters
67  */
68 struct tcp_init_params
69 {
70 	__le32 two_msl_timer /* 2MSL (used for TIME_WAIT state) timeout value */;
71 	__le16 tx_sws_timer /* Transmission silly window syndrom timeout value */;
72 	u8 max_fin_rt /* Minimum Fin RT */;
73 	u8 reserved[9];
74 };
75 
76 
77 /*
78  * tcp IPv4/IPv6 enum
79  */
80 enum tcp_ip_version
81 {
82 	TCP_IPV4,
83 	TCP_IPV6,
84 	MAX_TCP_IP_VERSION
85 };
86 
87 
88 /*
89  * tcp offload parameters
90  */
91 struct tcp_offload_params
92 {
93 	__le16 local_mac_addr_lo;
94 	__le16 local_mac_addr_mid;
95 	__le16 local_mac_addr_hi;
96 	__le16 remote_mac_addr_lo;
97 	__le16 remote_mac_addr_mid;
98 	__le16 remote_mac_addr_hi;
99 	__le16 vlan_id;
100 	__le16 flags;
101 #define TCP_OFFLOAD_PARAMS_TS_EN_MASK            0x1 /* timestamp enable */
102 #define TCP_OFFLOAD_PARAMS_TS_EN_SHIFT           0
103 #define TCP_OFFLOAD_PARAMS_DA_EN_MASK            0x1 /* delayed ack enabled */
104 #define TCP_OFFLOAD_PARAMS_DA_EN_SHIFT           1
105 #define TCP_OFFLOAD_PARAMS_KA_EN_MASK            0x1 /* keep alive enabled */
106 #define TCP_OFFLOAD_PARAMS_KA_EN_SHIFT           2
107 #define TCP_OFFLOAD_PARAMS_ECN_SENDER_EN_MASK    0x1 /* ECN sender enabled */
108 #define TCP_OFFLOAD_PARAMS_ECN_SENDER_EN_SHIFT   3
109 #define TCP_OFFLOAD_PARAMS_ECN_RECEIVER_EN_MASK  0x1 /* ECN receiver enabled */
110 #define TCP_OFFLOAD_PARAMS_ECN_RECEIVER_EN_SHIFT 4
111 #define TCP_OFFLOAD_PARAMS_NAGLE_EN_MASK         0x1 /* nagle algorithm enabled */
112 #define TCP_OFFLOAD_PARAMS_NAGLE_EN_SHIFT        5
113 #define TCP_OFFLOAD_PARAMS_DA_CNT_EN_MASK        0x1 /* delayed ack counter enabled */
114 #define TCP_OFFLOAD_PARAMS_DA_CNT_EN_SHIFT       6
115 #define TCP_OFFLOAD_PARAMS_FIN_SENT_MASK         0x1 /* fin already sent to far end */
116 #define TCP_OFFLOAD_PARAMS_FIN_SENT_SHIFT        7
117 #define TCP_OFFLOAD_PARAMS_FIN_RECEIVED_MASK     0x1 /* fin received */
118 #define TCP_OFFLOAD_PARAMS_FIN_RECEIVED_SHIFT    8
119 #define TCP_OFFLOAD_PARAMS_RESERVED_MASK         0x7F
120 #define TCP_OFFLOAD_PARAMS_RESERVED_SHIFT        9
121 	u8 ip_version /*  (use enum tcp_ip_version) */;
122 	u8 reserved0[3];
123 	__le32 remote_ip[4];
124 	__le32 local_ip[4];
125 	__le32 flow_label;
126 	u8 ttl;
127 	u8 tos_or_tc;
128 	__le16 remote_port;
129 	__le16 local_port;
130 	__le16 mss /* the mss derived from remote mss and local mtu, ipVersion options and tags */;
131 	u8 rcv_wnd_scale;
132 	u8 connect_mode /* TCP connect mode: use enum tcp_connect_mode (use enum tcp_connect_mode) */;
133 	__le16 srtt /* in ms */;
134 	__le32 ss_thresh;
135 	__le32 rcv_wnd /* absolute receive window (not scaled) */;
136 	__le32 cwnd /* absolute congestion window */;
137 	u8 ka_max_probe_cnt;
138 	u8 dup_ack_theshold;
139 	__le16 reserved1;
140 	__le32 ka_timeout /* This member specifies, in ms, the timeout interval for inactivity before sending a keepalive probe */;
141 	__le32 ka_interval /* This member specifies, in ms, the timeout after which to retransmit a keepalive frame if no response is received to a keepalive probe  */;
142 	__le32 max_rt_time /* This member specifies, in ms, the maximum time that the offload target should spend retransmitting a segment */;
143 	__le32 initial_rcv_wnd /* Initial receive window */;
144 	__le32 rcv_next;
145 	__le32 snd_una;
146 	__le32 snd_next;
147 	__le32 snd_max;
148 	__le32 snd_wnd /* absolute send window (not scaled) */;
149 	__le32 snd_wl1 /* the segment sequence number used for the last window update */;
150 	__le32 ts_recent /* The timestamp value to send in the next ACK */;
151 	__le32 ts_recent_age /* The length of time, in ms, since the most recent timestamp was received */;
152 	__le32 total_rt /* The total time, in ms, that has been spent retransmitting the current TCP segment */;
153 	__le32 ka_timeout_delta /* The time remaining, in clock ticks, until the next keepalive timeout. A value of -1 indicates that the keepalive timer was not running when the connection was offloaded. */;
154 	__le32 rt_timeout_delta /* The time remaining, in clock ticks, until the next retransmit timeout. A value of -1 indicates that the  retransmit timer was not running when the connection was offloaded. */;
155 	u8 dup_ack_cnt /* The number of ACKs that have been accepted for the same sequence number */;
156 	u8 snd_wnd_probe_cnt /* The current send window probe round */;
157 	u8 ka_probe_cnt /* the number of keepalive probes that have been sent that have not received a response */;
158 	u8 rt_cnt /* The number of retransmits that have been sent */;
159 	__le16 rtt_var /* in ms */;
160 	__le16 fw_internal /* fw internal use - initialize value = 0 */;
161 	u8 snd_wnd_scale;
162 	u8 ack_frequency /* delayed ack counter threshold */;
163 	__le16 da_timeout_value /* delayed ack timeout value in ms */;
164 	__le32 reserved3;
165 };
166 
167 
168 /*
169  * tcp offload parameters
170  */
171 struct tcp_offload_params_opt2
172 {
173 	__le16 local_mac_addr_lo;
174 	__le16 local_mac_addr_mid;
175 	__le16 local_mac_addr_hi;
176 	__le16 remote_mac_addr_lo;
177 	__le16 remote_mac_addr_mid;
178 	__le16 remote_mac_addr_hi;
179 	__le16 vlan_id;
180 	__le16 flags;
181 #define TCP_OFFLOAD_PARAMS_OPT2_TS_EN_MASK      0x1 /* timestamp enable */
182 #define TCP_OFFLOAD_PARAMS_OPT2_TS_EN_SHIFT     0
183 #define TCP_OFFLOAD_PARAMS_OPT2_DA_EN_MASK      0x1 /* delayed ack enabled */
184 #define TCP_OFFLOAD_PARAMS_OPT2_DA_EN_SHIFT     1
185 #define TCP_OFFLOAD_PARAMS_OPT2_KA_EN_MASK      0x1 /* keep alive enabled */
186 #define TCP_OFFLOAD_PARAMS_OPT2_KA_EN_SHIFT     2
187 #define TCP_OFFLOAD_PARAMS_OPT2_ECN_EN_MASK     0x1 /* ECN enabled */
188 #define TCP_OFFLOAD_PARAMS_OPT2_ECN_EN_SHIFT    3
189 #define TCP_OFFLOAD_PARAMS_OPT2_RESERVED0_MASK  0xFFF
190 #define TCP_OFFLOAD_PARAMS_OPT2_RESERVED0_SHIFT 4
191 	u8 ip_version /*  (use enum tcp_ip_version) */;
192 	u8 reserved1[3];
193 	__le32 remote_ip[4];
194 	__le32 local_ip[4];
195 	__le32 flow_label;
196 	u8 ttl;
197 	u8 tos_or_tc;
198 	__le16 remote_port;
199 	__le16 local_port;
200 	__le16 mss /* the mss derived from remote mss and local mtu, ipVersion options and tags */;
201 	u8 rcv_wnd_scale;
202 	u8 connect_mode /* TCP connect mode: use enum tcp_connect_mode (use enum tcp_connect_mode) */;
203 	__le16 syn_ip_payload_length /* length of Tcp header in SYN packet - relevent for passive mode */;
204 	__le32 syn_phy_addr_lo /* physical address (low) of SYN buffer - relevent for passive mode */;
205 	__le32 syn_phy_addr_hi /* physical address (high) of SYN buffer - relevent for passive mode */;
206 	__le32 cwnd /* absolute congestion window */;
207 	u8 ka_max_probe_cnt;
208 	u8 reserved2[3];
209 	__le32 ka_timeout /* This member specifies, in ms, the timeout interval for inactivity before sending a keepalive probe */;
210 	__le32 ka_interval /* This member specifies, in ms, the timeout after which to retransmit a keepalive frame if no response is received to a keepalive probe  */;
211 	__le32 max_rt_time /* This member specifies, in ms, the maximum time that the offload target should spend retransmitting a segment */;
212 	__le32 reserved3[16];
213 };
214 
215 
216 /*
217  * tcp IPv4/IPv6 enum
218  */
219 enum tcp_seg_placement_event
220 {
221 	TCP_EVENT_ADD_PEN,
222 	TCP_EVENT_ADD_NEW_ISLE,
223 	TCP_EVENT_ADD_ISLE_RIGHT,
224 	TCP_EVENT_ADD_ISLE_LEFT,
225 	TCP_EVENT_JOIN,
226 	TCP_EVENT_DELETE_ISLES,
227 	TCP_EVENT_NOP,
228 	MAX_TCP_SEG_PLACEMENT_EVENT
229 };
230 
231 
232 /*
233  * tcp init parameters
234  */
235 struct tcp_update_params
236 {
237 	__le16 flags;
238 #define TCP_UPDATE_PARAMS_REMOTE_MAC_ADDR_CHANGED_MASK   0x1
239 #define TCP_UPDATE_PARAMS_REMOTE_MAC_ADDR_CHANGED_SHIFT  0
240 #define TCP_UPDATE_PARAMS_MSS_CHANGED_MASK               0x1
241 #define TCP_UPDATE_PARAMS_MSS_CHANGED_SHIFT              1
242 #define TCP_UPDATE_PARAMS_TTL_CHANGED_MASK               0x1
243 #define TCP_UPDATE_PARAMS_TTL_CHANGED_SHIFT              2
244 #define TCP_UPDATE_PARAMS_TOS_OR_TC_CHANGED_MASK         0x1
245 #define TCP_UPDATE_PARAMS_TOS_OR_TC_CHANGED_SHIFT        3
246 #define TCP_UPDATE_PARAMS_KA_TIMEOUT_CHANGED_MASK        0x1
247 #define TCP_UPDATE_PARAMS_KA_TIMEOUT_CHANGED_SHIFT       4
248 #define TCP_UPDATE_PARAMS_KA_INTERVAL_CHANGED_MASK       0x1
249 #define TCP_UPDATE_PARAMS_KA_INTERVAL_CHANGED_SHIFT      5
250 #define TCP_UPDATE_PARAMS_MAX_RT_TIME_CHANGED_MASK       0x1
251 #define TCP_UPDATE_PARAMS_MAX_RT_TIME_CHANGED_SHIFT      6
252 #define TCP_UPDATE_PARAMS_FLOW_LABEL_CHANGED_MASK        0x1
253 #define TCP_UPDATE_PARAMS_FLOW_LABEL_CHANGED_SHIFT       7
254 #define TCP_UPDATE_PARAMS_INITIAL_RCV_WND_CHANGED_MASK   0x1
255 #define TCP_UPDATE_PARAMS_INITIAL_RCV_WND_CHANGED_SHIFT  8
256 #define TCP_UPDATE_PARAMS_KA_MAX_PROBE_CNT_CHANGED_MASK  0x1
257 #define TCP_UPDATE_PARAMS_KA_MAX_PROBE_CNT_CHANGED_SHIFT 9
258 #define TCP_UPDATE_PARAMS_KA_EN_CHANGED_MASK             0x1
259 #define TCP_UPDATE_PARAMS_KA_EN_CHANGED_SHIFT            10
260 #define TCP_UPDATE_PARAMS_NAGLE_EN_CHANGED_MASK          0x1
261 #define TCP_UPDATE_PARAMS_NAGLE_EN_CHANGED_SHIFT         11
262 #define TCP_UPDATE_PARAMS_KA_EN_MASK                     0x1
263 #define TCP_UPDATE_PARAMS_KA_EN_SHIFT                    12
264 #define TCP_UPDATE_PARAMS_NAGLE_EN_MASK                  0x1
265 #define TCP_UPDATE_PARAMS_NAGLE_EN_SHIFT                 13
266 #define TCP_UPDATE_PARAMS_KA_RESTART_MASK                0x1
267 #define TCP_UPDATE_PARAMS_KA_RESTART_SHIFT               14
268 #define TCP_UPDATE_PARAMS_RETRANSMIT_RESTART_MASK        0x1
269 #define TCP_UPDATE_PARAMS_RETRANSMIT_RESTART_SHIFT       15
270 	__le16 remote_mac_addr_lo;
271 	__le16 remote_mac_addr_mid;
272 	__le16 remote_mac_addr_hi;
273 	__le16 mss;
274 	u8 ttl;
275 	u8 tos_or_tc;
276 	__le32 ka_timeout;
277 	__le32 ka_interval;
278 	__le32 max_rt_time;
279 	__le32 flow_label;
280 	__le32 initial_rcv_wnd;
281 	u8 ka_max_probe_cnt;
282 	u8 reserved1[7];
283 };
284 
285 
286 /*
287  * toe upload parameters
288  */
289 struct tcp_upload_params
290 {
291 	__le32 rcv_next;
292 	__le32 snd_una;
293 	__le32 snd_next;
294 	__le32 snd_max;
295 	__le32 snd_wnd /* absolute send window (not scaled) */;
296 	__le32 rcv_wnd /* absolute receive window (not scaled) */;
297 	__le32 snd_wl1 /* the segment sequence number used for the last window update */;
298 	__le32 cwnd /* absolute congestion window */;
299 	__le32 ss_thresh;
300 	__le16 srtt /* in ms */;
301 	__le16 rtt_var /* in ms */;
302 	__le32 ts_time /* The current value of the adjusted timestamp */;
303 	__le32 ts_recent /* The timestamp value to send in the next ACK */;
304 	__le32 ts_recent_age /* The length of time, in ms, since the most recent timestamp was received */;
305 	__le32 total_rt /* The total time, in ms, that has been spent retransmitting the current TCP segment */;
306 	__le32 ka_timeout_delta /* The time remaining, in clock ticks, until the next keepalive timeout. A value of -1 indicates that the keepalive timer was not running when the connection was offloaded. */;
307 	__le32 rt_timeout_delta /* The time remaining, in clock ticks, until the next retransmit timeout. A value of -1 indicates that the  retransmit timer was not running when the connection was offloaded. */;
308 	u8 dup_ack_cnt /* The number of ACKs that have been accepted for the same sequence number */;
309 	u8 snd_wnd_probe_cnt /* The current send window probe round */;
310 	u8 ka_probe_cnt /* the number of keepalive probes that have been sent that have not received a response */;
311 	u8 rt_cnt /* The number of retransmits that have been sent */;
312 	__le32 reserved;
313 };
314 
315 #endif /* __TCP_COMMON__ */
316