1 /*
2  * Copyright 2014-2017 Cavium, Inc.
3  * The contents of this file are subject to the terms of the Common Development
4  * and Distribution License, v.1,  (the "License").
5  *
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the License at available
9  * at http://opensource.org/licenses/CDDL-1.0
10  *
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 #ifndef _TCP_CTX_H
16 #define _TCP_CTX_H
17 
18 #include "bcmtype.h"
19 #include "l2_defs.h"
20 
21 /////////////////////////////////////////////////////////////////////
22 // TCP TX section
23 /////////////////////////////////////////////////////////////////////
24 
25 #if defined(LITTLE_ENDIAN)
26     typedef struct {
27         u32_t  tcp_tsch_snd_next;        // TSCH copy of snd_next, used for window calculations
28         u32_t  tcp_snd_max;              // TCP snd_max
29         u8_t   tcp_tsch_xnum;            // last slot number that was scheduled by TSCH
30         u8_t   tcp_cons_retx_num;        // last retransmit flush index that COM has received completion for
31         u8_t   tcp_tsch_cmd;             // Index of next ccell to be scheduled by TSCH
32         u8_t   tcp_cp_cmd;               // Command Queue producer
33         u8_t   tcp_tsch_cons_retx_num;   // last retransmit flush index that was sent by TSCH
34         u8_t   tcp_prod_retx_num;        // Retransmit flush is initiated by incrementing this member
35         u16_t  tcp_pgid;                 // L2 context cid that belong to this connection
36         u8_t   cam_pending;              // number of free entries in the CAM that are reserved for offloading the connection
37         u8_t   tcp_tcp_hlen;             // size of TCP header in 32 bit  words
38         u8_t   tcp_iphdr_nbytes;         // size of IP header in bytes
39         u8_t   l2_slot_size;             // N/A for iSCSI
40         u32_t  tcp_max_adv_win;          // Maximum advertised window to the remote peer
41         u8_t   tcp_modes;
42         u8_t   tcp_dack;
43         u8_t   tcp_tos;
44         u8_t   tcp_ttl;
45         union {
46             u32_t  tcp_ip_dst;           // destination IP address
47             u32_t  tcp_ipv6_dst[4];      // destination IP v6 address
48         }u1;
49         union {
50             u32_t  tcp_ip_src;	         // source IP address
51             u32_t  tcp_ipv6_src[4];      // source IP v6 address
52         }u2;
53         u16_t  tcp_dst_port;             // TCP destination port number
54         u16_t  tcp_src_port;             // TCP source port number
55     } tcp_tx_ctx_l_t;
56     typedef tcp_tx_ctx_l_t  tcp_tx_ctx_t;
57 #elif defined(BIG_ENDIAN)
58     typedef struct {
59         u32_t  tcp_tsch_snd_next;        // TSCH copy of snd_next, used for window calculations
60         u32_t  tcp_snd_max;              // TCP snd_max
61         u8_t   tcp_cp_cmd;               // Command Queue producer
62         u8_t   tcp_tsch_cmd;             // Index of next ccell to be scheduled by TSCH
63         u8_t   tcp_cons_retx_num;        // last retransmit flush index that COM has received completion for
64         u8_t   tcp_tsch_xnum;            // last slot number that was scheduled by TSCH
65         u16_t  tcp_pgid;                 // L2 context cid that belong to this connection
66         u8_t   tcp_prod_retx_num;        // Retransmit flush is initiated by incrementing this member
67         u8_t   tcp_tsch_cons_retx_num;   // last retransmit flush index that was sent by TSCH
68         u8_t   l2_slot_size;             // N/A for iSCSI
69         u8_t   tcp_iphdr_nbytes;         // size of IP header in bytes
70         u8_t   tcp_tcp_hlen;             // size of TCP header in 32 bit  words
71         u8_t   cam_pending;              // number of free entries in the CAM that are reserved for offloading the connection
72         u32_t  tcp_max_adv_win;          // Maximum advertised window to the remote peer
73         u8_t   tcp_ttl;
74         u8_t   tcp_tos;
75         u8_t   tcp_dack;
76         u8_t   tcp_modes;
77             #define L4CTX_TCP_MODES_RST_INDICATED_PENDING       (1<<0)
78             #define L4CTX_TCP_MODES_DISC_BD                     (1<<1)
79             #define L4CTX_TCP_MODES_UPLOAD_INITED               (1<<2)
80             #define L4CTX_TCP_MODES_RMT_DISC                    (1<<3)
81             #define L4CTX_TCP_MODES_PG_INVALIDATED              (1<<4)
82             #define L4CTX_TCP_MODES_ABORT_PENDING               (1<<5)
83             #define L4CTX_TCP_MODES_DISC_PENDING                (1<<6)
84             #define L4CTX_TCP_MODES_STOP_TX                     (1<<7)
85         union {
86             u32_t  tcp_ip_dst;           // destination IP address
87             u32_t  tcp_ipv6_dst[4];      // destination IP v6 address
88         };
89         union {
90             u32_t  tcp_ip_src;	         // source IP address
91             u32_t  tcp_ipv6_src[4];      // source IP v6 address
92         };
93         u16_t  tcp_src_port;             // TCP source port number
94         u16_t  tcp_dst_port;             // TCP destination port number
95     } tcp_tx_ctx_b_t;
96 
97     typedef tcp_tx_ctx_b_t  tcp_tx_ctx_t;
98 #endif
99 /////////////////////////////////////////////////////////////////////
100 // TCP CMN section
101 /////////////////////////////////////////////////////////////////////
102 
103 // Congestion avoidance and slow start require that two variables be maintained
104 // for each connection: a congestion window, cwnd, and a slow start threshold
105 // size, ssthresh. Initialization for a given connection sets cwnd to one segment
106 // and ssthresh to 65535 (or 0xFFFF)bytes. (but MS passed down 0xFFFFFFFF as
107 // initial value)
108 #define INITIAL_SSTHRESH_VAL    0xFFFFFFFF
109 #define MAX_SSTHRESH_VAL        0x7FFFFFFF
110 
111 typedef struct {
112     u8_t    ctx_type;                   // 0x0     context type enum
113         #define CTX_TYPE_ISCSI                           (5<<4)
114     u8_t    size;                       // 0x1     context size in bytes
115     u8_t    bd_pre_read;                // 0x2
116     u8_t    gen_bd_cid;                 // 0x3
117     u8_t    gen_bd_max;                 // 0x4
118     u8_t    oubits;                     // 0x5
119     u16_t   sq_prod;                    // 0x6     SQ producer, updated by host via mailbox. wraps at size: bits 0 - (k-1): queue element index within page, bits k - 15: page index in page table
120     u8_t    tcp_flags;                  // 0x8
121     u8_t    tcp_state;                  // 0x9     TCP state machine
122     union idx16_union_t rq_prod;        // 0xa     RQ producer, updated by driver, wraps at rq_size
123     u32_t   tcp_timer1;                 // 0xc     retransmit timer
124     u16_t   tcp_timer2;                 // 0x10
125     u16_t   tcp_timer3;                 //
126     u16_t   tcp_timer4;                 // 0x14
127     u16_t   tcp_timer5;                 //
128     u32_t   tcp_slot_size;              // 0x18
129         #define L4CTX_TCP_SLOT_SIZE_SLOT_SIZE               (0xffffffL<<0)
130         #define L4CTX_TCP_SLOT_SIZE_CMD_MAX                 (0x7fL<<24)
131         #define L4CTX_TCP_SLOT_SIZE_STOP                    (1UL<<31)
132     u32_t   tcp_snd_cwin;               // 0x1c
133     u32_t   tcp_snd_win;                // 0x20
134     u8_t    tcp_num_dupack;             // 0x24    number of consecutive duplicate ACK received
135     u8_t    tcp_tx_protocol_flags;      // 0x25    ack/rst/syn/fin indication
136     u8_t    tcp_comp_cons_retx_num;     //         Last retransmit flush index that was completed by TXP
137     u8_t    tcp_num_retx;               //
138     u32_t   tcp_fl;                     //         TCP flow label for IPV6
139     u32_t   tcp_ssthresh;               // 0x2c    TCP slow start threshold
140     u32_t   tcp_rcv_next;               // 0x30    TCP receive next sequence number
141     u32_t   tcp_rcv_win_seq;            //         unused in iSCSI
142     u32_t   tcp_snd_una;                //
143     u32_t   tcp_snd_next;               //
144     u32_t   tcp_sm_rtt;                 // 0x40
145     u32_t   tcp_sm_delta;               //
146     u32_t   tcp_max_snd_win;            //
147     u8_t    tcp_txp_cmd;                // 0x4c    index of the ccell that the TXP is currently transmitting
148     u8_t    tcp_upload_reason;          //
149 	u8_t   	tcp_rcv_seg_scale;        	// 		   TCP segment scale that is advertised by Xinan
150     u8_t    tcp_ulp_ooo_flags;
151 #define TCP_ULP_OOO_DETECTED		(0x01)
152 	u32_t  	last_ack_sent;        	//         TCP ack sequence of the previous packet transmitted
153     u32_t   tcp_offload_seq;            //         initial TCP seq number of the Xinan sid (i.e. bseq + offload_seq = tcp_seq)
154     u32_t   tcp_tstamp;                 //
155     u16_t   tcp_mss;                    //         mss of the connection
156     u8_t    ka_probe_cnt;
157     u8_t    ka_max_probe_cnt;
158     u8_t    force_ack_pending;
159     u8_t    krnlq_id;                   //         indicate which krnlq that kcqe should be written to.
160     u16_t   ka_timeout_tick;
161     u16_t   ka_interval_tick;
162     u8_t    unused2;
163     u8_t    challenge_ack_state;         //         refer to tcpm-tcpsecure-09 requirement
164         #define CHALLENGE_ACK_NOT_SENT          0            // Challenge Ack not sent
165         #define CHALLENGE_ACK_SENT_KA_DISABLED  1            // Challenge ACK is sent while KA was disabled
166         #define CHALLENGE_ACK_SENT_KA_ENABLED   2            // Challenge ACK is sent while KA was enabled
167 } tcp_cmn_ctx_b_t;
168 
169 typedef struct {
170     u8_t    gen_bd_cid;                 // 0x0
171     u8_t    bd_pre_read;                // 0x1
172     u8_t    size;                       // 0x2
173     u8_t    ctx_type;                   // 0x3     context type enum
174     u16_t   sq_prod;                    // 0x4     SQ producer, updated by host via mailbox. wraps at size: bits 0 - (k-1): queue element index within page, bits k - 15: page index in page table
175     u8_t    oubits;                     // 0x6      ???
176     u8_t    gen_bd_max;                 // 0x7
177     u16_t   rq_prod;                    // 0x8     RQ producer, updated by driver, wraps at rq_size
178     u8_t    tcp_state;                  // 0xa     TCP state machine
179     u8_t    tcp_flags;                  // 0xb
180     u32_t   tcp_timer1;                 // 0xc     retransmit timer
181     u16_t   tcp_timer3;                 //
182     u16_t   tcp_timer2;                 // 0x10
183     u16_t   tcp_timer5;                 //
184     u16_t   tcp_timer4;                 // 0x14
185     u32_t   tcp_slot_size;              // 0x18
186     u32_t   tcp_snd_cwin;               // 0x1c
187     u32_t   tcp_snd_win;                // 0x20
188     u8_t    tcp_num_retx;               //
189     u8_t    tcp_comp_cons_retx_num;     //         Last retransmit flush index that was completed by TXP
190     u8_t    tcp_tx_protocol_flags;      // 0x25    ack/rst/syn/fin indication
191     u8_t    tcp_num_dupack;             // 0x24    number of consecutive duplicate ACK received
192     u32_t   tcp_fl;                     // 0x28    TCP flow label for IPV6
193     u32_t   tcp_ssthresh;               // 0x2c    TCP slow start threshold
194     u32_t   tcp_rcv_next;               // 0x30    TCP receive next sequence number
195     u32_t   tcp_rcv_win_seq;            //         unused in iSCSI
196     u32_t   tcp_snd_una;                //
197     u32_t   tcp_snd_next;               //
198     u32_t   tcp_sm_rtt;                 // 0x40
199     u32_t   tcp_sm_delta;               //
200     u32_t   tcp_max_snd_win;            //
201     u8_t    tcp_ulp_ooo_flags;
202     u8_t   	tcp_rcv_seg_scale;        	//          TCP segment scale that is advertised by Xinan
203     u8_t    tcp_upload_reason;          //
204     u8_t    tcp_txp_cmd;                // 0x4c    index of the ccell that the TXP is currently transmitting
205 	u32_t  	last_ack_sent;        	// TCP ack sequence of the previous packet transmitted
206     u32_t   tcp_offload_seq;            // initial TCP seq number of the Xinan side (i.e. bseq + offload_seq = tcp_seq)
207     u32_t   tcp_tstamp;                 //
208     u8_t    ka_max_probe_cnt;
209     u8_t    ka_probe_cnt;
210     u16_t   tcp_mss;                    // mss of the connection
211     u16_t   ka_timeout_tick;
212     u8_t    krnlq_id;                   // indicate which krnlq that kcqe should be written to.
213     u8_t    force_ack_pending;
214     u8_t    challenge_ack_state;        // refer to tcpm-tcpsecure-09 requirement
215     u8_t    unused2;
216     u16_t   ka_interval_tick;
217 } tcp_cmn_ctx_l_t;
218 
219 #if defined(LITTLE_ENDIAN)
220     typedef tcp_cmn_ctx_l_t  tcp_cmn_ctx_t;
221 #elif defined(BIG_ENDIAN)
222     typedef tcp_cmn_ctx_b_t  tcp_cmn_ctx_t;
223 #endif
224 /////////////////////////////////////////////////////////////////////
225 // TCP RX section
226 /////////////////////////////////////////////////////////////////////
227 typedef struct {
228     u8_t    state;                      // iooo state
229     u8_t    spill_mode:1;
230     u8_t    mode:7;
231 } iooo_tcp_b_t;
232 
233 typedef struct {
234     u8_t    mode:7;
235     u8_t    spill_mode:1;
236     u8_t    state;                      // iooo state
237 } iooo_tcp_l_t;
238 
239 typedef struct {
240     u32_t   tcp_snd_wl1;            //
241     u32_t   tcp_snd_wl2;            //
242     u8_t   	tcp_snd_seg_scale;    	// TCP segment scale that is advertised by the remote peer
243 #if (ISCSI_OOO_SUPPORT)
244     iooo_tcp_b_t iooo_tcp;              // iSCSI OOO tcp manager structure
245     u8_t    reserved0;
246 #else
247     u8_t    reserved0[3];
248 #endif
249 } tcp_rx_ctx_b_t;
250 
251 typedef struct {
252     u32_t  tcp_snd_wl1;             //
253     u32_t  tcp_snd_wl2;             //
254 #if (ISCSI_OOO_SUPPORT)
255     iooo_tcp_l_t iooo_tcp;              // iSCSI OOO tcp manager structure
256     u8_t    reserved0;
257 #else
258     u8_t    reserved0[3];
259 #endif
260     u8_t   	tcp_snd_seg_scale;      // TCP segment scale that is advertised by the remote peer
261 } tcp_rx_ctx_l_t;
262 
263 #if defined(LITTLE_ENDIAN)
264     typedef tcp_rx_ctx_l_t  tcp_rx_ctx_t;
265 #elif defined(BIG_ENDIAN)
266     typedef tcp_rx_ctx_b_t  tcp_rx_ctx_t;
267 #endif
268 
269 #endif /* _TCP_CTX_H */
270 
271