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