blob: 911846ae5c7d6425cc36fe234cdcf59e0e4b0990 [file] [log] [blame]
Glenn Streiff3c2d7742008-02-04 20:20:45 -08001/*
Chien Tungfa6c87d2009-12-09 15:21:56 -08002 * Copyright (c) 2006 - 2009 Intel Corporation. All rights reserved.
Glenn Streiff3c2d7742008-02-04 20:20:45 -08003 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 */
33
34#ifndef NES_CM_H
35#define NES_CM_H
36
37#define QUEUE_EVENTS
38
39#define NES_MANAGE_APBVT_DEL 0
40#define NES_MANAGE_APBVT_ADD 1
41
Faisal Latif9d5ab132009-03-06 15:15:01 -080042#define NES_MPA_REQUEST_ACCEPT 1
43#define NES_MPA_REQUEST_REJECT 2
44
Glenn Streiff3c2d7742008-02-04 20:20:45 -080045/* IETF MPA -- defines, enums, structs */
46#define IEFT_MPA_KEY_REQ "MPA ID Req Frame"
47#define IEFT_MPA_KEY_REP "MPA ID Rep Frame"
48#define IETF_MPA_KEY_SIZE 16
49#define IETF_MPA_VERSION 1
Faisal Latif9b84dbe2009-12-09 15:53:36 -080050#define IETF_MAX_PRIV_DATA_LEN 512
51#define IETF_MPA_FRAME_SIZE 20
Glenn Streiff3c2d7742008-02-04 20:20:45 -080052
53enum ietf_mpa_flags {
54 IETF_MPA_FLAGS_MARKERS = 0x80, /* receive Markers */
55 IETF_MPA_FLAGS_CRC = 0x40, /* receive Markers */
56 IETF_MPA_FLAGS_REJECT = 0x20, /* Reject */
57};
58
59struct ietf_mpa_frame {
60 u8 key[IETF_MPA_KEY_SIZE];
61 u8 flags;
62 u8 rev;
63 __be16 priv_data_len;
64 u8 priv_data[0];
65};
66
67#define ietf_mpa_req_resp_frame ietf_mpa_frame
68
69struct nes_v4_quad {
70 u32 rsvd0;
71 __le32 DstIpAdrIndex; /* Only most significant 5 bits are valid */
72 __be32 SrcIpadr;
73 __be16 TcpPorts[2]; /* src is low, dest is high */
74};
75
76struct nes_cm_node;
77enum nes_timer_type {
78 NES_TIMER_TYPE_SEND,
79 NES_TIMER_TYPE_RECV,
80 NES_TIMER_NODE_CLEANUP,
81 NES_TIMER_TYPE_CLOSE,
82};
83
Faisal Latif183ecfa2008-11-21 20:50:46 -060084#define NES_PASSIVE_STATE_INDICATED 0
85#define NES_DO_NOT_SEND_RESET_EVENT 1
86#define NES_SEND_RESET_EVENT 2
87
Glenn Streiff3c2d7742008-02-04 20:20:45 -080088#define MAX_NES_IFS 4
89
90#define SET_ACK 1
91#define SET_SYN 2
92#define SET_FIN 4
93#define SET_RST 8
94
Faisal Latif6492cdf2008-07-24 20:50:45 -070095#define TCP_OPTIONS_PADDING 3
96
Glenn Streiff3c2d7742008-02-04 20:20:45 -080097struct option_base {
98 u8 optionnum;
99 u8 length;
100};
101
102enum option_numbers {
103 OPTION_NUMBER_END,
104 OPTION_NUMBER_NONE,
105 OPTION_NUMBER_MSS,
106 OPTION_NUMBER_WINDOW_SCALE,
107 OPTION_NUMBER_SACK_PERM,
108 OPTION_NUMBER_SACK,
109 OPTION_NUMBER_WRITE0 = 0xbc
110};
111
112struct option_mss {
113 u8 optionnum;
114 u8 length;
115 __be16 mss;
116};
117
118struct option_windowscale {
119 u8 optionnum;
120 u8 length;
121 u8 shiftcount;
122};
123
124union all_known_options {
125 char as_end;
126 struct option_base as_base;
127 struct option_mss as_mss;
128 struct option_windowscale as_windowscale;
129};
130
131struct nes_timer_entry {
132 struct list_head list;
133 unsigned long timetosend; /* jiffies */
134 struct sk_buff *skb;
135 u32 type;
136 u32 retrycount;
137 u32 retranscount;
138 u32 context;
139 u32 seq_num;
140 u32 send_retrans;
141 int close_when_complete;
142 struct net_device *netdev;
143};
144
145#define NES_DEFAULT_RETRYS 64
146#define NES_DEFAULT_RETRANS 8
147#ifdef CONFIG_INFINIBAND_NES_DEBUG
148#define NES_RETRY_TIMEOUT (1000*HZ/1000)
149#else
150#define NES_RETRY_TIMEOUT (3000*HZ/1000)
151#endif
152#define NES_SHORT_TIME (10)
153#define NES_LONG_TIME (2000*HZ/1000)
Faisal Latif4e9c3902009-04-27 13:39:36 -0700154#define NES_MAX_TIMEOUT ((unsigned long) (12*HZ))
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800155
156#define NES_CM_HASHTABLE_SIZE 1024
157#define NES_CM_TCP_TIMER_INTERVAL 3000
158#define NES_CM_DEFAULT_MTU 1540
159#define NES_CM_DEFAULT_FRAME_CNT 10
160#define NES_CM_THREAD_STACK_SIZE 256
161#define NES_CM_DEFAULT_RCV_WND 64240 // before we know that window scaling is allowed
162#define NES_CM_DEFAULT_RCV_WND_SCALED 256960 // after we know that window scaling is allowed
163#define NES_CM_DEFAULT_RCV_WND_SCALE 2
164#define NES_CM_DEFAULT_FREE_PKTS 0x000A
165#define NES_CM_FREE_PKT_LO_WATERMARK 2
166
167#define NES_CM_DEFAULT_MSS 536
168
169#define NES_CM_DEF_SEQ 0x159bf75f
170#define NES_CM_DEF_LOCAL_ID 0x3b47
171
172#define NES_CM_DEF_SEQ2 0x18ed5740
173#define NES_CM_DEF_LOCAL_ID2 0xb807
Faisal Latif9b84dbe2009-12-09 15:53:36 -0800174#define MAX_CM_BUFFER (IETF_MPA_FRAME_SIZE + IETF_MAX_PRIV_DATA_LEN)
Faisal Latife1890622008-12-24 20:30:04 -0800175
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800176
177typedef u32 nes_addr_t;
178
179#define nes_cm_tsa_context nes_qp_context
180
181struct nes_qp;
182
183/* cm node transition states */
184enum nes_cm_node_state {
185 NES_CM_STATE_UNKNOWN,
186 NES_CM_STATE_INITED,
187 NES_CM_STATE_LISTENING,
188 NES_CM_STATE_SYN_RCVD,
189 NES_CM_STATE_SYN_SENT,
190 NES_CM_STATE_ONE_SIDE_ESTABLISHED,
191 NES_CM_STATE_ESTABLISHED,
192 NES_CM_STATE_ACCEPTING,
193 NES_CM_STATE_MPAREQ_SENT,
Faisal Latif6492cdf2008-07-24 20:50:45 -0700194 NES_CM_STATE_MPAREQ_RCVD,
Faisal Latif9d5ab132009-03-06 15:15:01 -0800195 NES_CM_STATE_MPAREJ_RCVD,
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800196 NES_CM_STATE_TSA,
197 NES_CM_STATE_FIN_WAIT1,
198 NES_CM_STATE_FIN_WAIT2,
199 NES_CM_STATE_CLOSE_WAIT,
200 NES_CM_STATE_TIME_WAIT,
201 NES_CM_STATE_LAST_ACK,
202 NES_CM_STATE_CLOSING,
203 NES_CM_STATE_CLOSED
204};
205
Faisal Latif6492cdf2008-07-24 20:50:45 -0700206enum nes_tcpip_pkt_type {
207 NES_PKT_TYPE_UNKNOWN,
208 NES_PKT_TYPE_SYN,
209 NES_PKT_TYPE_SYNACK,
210 NES_PKT_TYPE_ACK,
211 NES_PKT_TYPE_FIN,
212 NES_PKT_TYPE_RST
213};
214
215
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800216/* type of nes connection */
217enum nes_cm_conn_type {
218 NES_CM_IWARP_CONN_TYPE,
219};
220
221/* CM context params */
222struct nes_cm_tcp_context {
223 u8 client;
224
225 u32 loc_seq_num;
226 u32 loc_ack_num;
227 u32 rem_ack_num;
228 u32 rcv_nxt;
229
230 u32 loc_id;
231 u32 rem_id;
232
233 u32 snd_wnd;
234 u32 max_snd_wnd;
235
236 u32 rcv_wnd;
237 u32 mss;
238 u8 snd_wscale;
239 u8 rcv_wscale;
240
241 struct nes_cm_tsa_context tsa_cntxt;
242 struct timeval sent_ts;
243};
244
245
246enum nes_cm_listener_state {
247 NES_CM_LISTENER_PASSIVE_STATE=1,
248 NES_CM_LISTENER_ACTIVE_STATE=2,
249 NES_CM_LISTENER_EITHER_STATE=3
250};
251
252struct nes_cm_listener {
253 struct list_head list;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800254 struct nes_cm_core *cm_core;
255 u8 loc_mac[ETH_ALEN];
256 nes_addr_t loc_addr;
257 u16 loc_port;
258 struct iw_cm_id *cm_id;
259 enum nes_cm_conn_type conn_type;
260 atomic_t ref_count;
261 struct nes_vnic *nesvnic;
262 atomic_t pend_accepts_cnt;
263 int backlog;
264 enum nes_cm_listener_state listener_state;
265 u32 reused_node;
266};
267
268/* per connection node and node state information */
269struct nes_cm_node {
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800270 nes_addr_t loc_addr, rem_addr;
271 u16 loc_port, rem_port;
272
273 u8 loc_mac[ETH_ALEN];
274 u8 rem_mac[ETH_ALEN];
275
276 enum nes_cm_node_state state;
277 struct nes_cm_tcp_context tcp_cntxt;
278 struct nes_cm_core *cm_core;
279 struct sk_buff_head resend_list;
280 atomic_t ref_count;
281 struct net_device *netdev;
282
283 struct nes_cm_node *loopbackpartner;
Faisal Latif6492cdf2008-07-24 20:50:45 -0700284
285 struct nes_timer_entry *send_entry;
286
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800287 spinlock_t retrans_list_lock;
Faisal Latif9d5ab132009-03-06 15:15:01 -0800288 struct nes_timer_entry *recv_entry;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800289
290 int send_write0;
291 union {
292 struct ietf_mpa_frame mpa_frame;
Faisal Latif9d5ab132009-03-06 15:15:01 -0800293 u8 mpa_frame_buf[MAX_CM_BUFFER];
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800294 };
295 u16 mpa_frame_size;
296 struct iw_cm_id *cm_id;
297 struct list_head list;
298 int accelerated;
299 struct nes_cm_listener *listener;
300 enum nes_cm_conn_type conn_type;
301 struct nes_vnic *nesvnic;
302 int apbvt_set;
303 int accept_pend;
Faisal Latif879e5bd2008-11-21 20:50:41 -0600304 struct list_head timer_entry;
305 struct list_head reset_entry;
Faisal Latif6492cdf2008-07-24 20:50:45 -0700306 struct nes_qp *nesqp;
Faisal Latif183ecfa2008-11-21 20:50:46 -0600307 atomic_t passive_state;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800308};
309
310/* structure for client or CM to fill when making CM api calls. */
311/* - only need to set relevant data, based on op. */
312struct nes_cm_info {
313 union {
314 struct iw_cm_id *cm_id;
315 struct net_device *netdev;
316 };
317
318 u16 loc_port;
319 u16 rem_port;
320 nes_addr_t loc_addr;
321 nes_addr_t rem_addr;
322
323 enum nes_cm_conn_type conn_type;
324 int backlog;
325};
326
327/* CM event codes */
328enum nes_cm_event_type {
329 NES_CM_EVENT_UNKNOWN,
330 NES_CM_EVENT_ESTABLISHED,
331 NES_CM_EVENT_MPA_REQ,
332 NES_CM_EVENT_MPA_CONNECT,
333 NES_CM_EVENT_MPA_ACCEPT,
Faisal Latif9d5ab132009-03-06 15:15:01 -0800334 NES_CM_EVENT_MPA_REJECT,
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800335 NES_CM_EVENT_MPA_ESTABLISHED,
336 NES_CM_EVENT_CONNECTED,
337 NES_CM_EVENT_CLOSED,
338 NES_CM_EVENT_RESET,
339 NES_CM_EVENT_DROPPED_PKT,
340 NES_CM_EVENT_CLOSE_IMMED,
341 NES_CM_EVENT_CLOSE_HARD,
342 NES_CM_EVENT_CLOSE_CLEAN,
343 NES_CM_EVENT_ABORTED,
344 NES_CM_EVENT_SEND_FIRST
345};
346
347/* event to post to CM event handler */
348struct nes_cm_event {
349 enum nes_cm_event_type type;
350
351 struct nes_cm_info cm_info;
352 struct work_struct event_work;
353 struct nes_cm_node *cm_node;
354};
355
356struct nes_cm_core {
357 enum nes_cm_node_state state;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800358
359 atomic_t listen_node_cnt;
360 struct nes_cm_node listen_list;
361 spinlock_t listen_list_lock;
362
363 u32 mtu;
364 u32 free_tx_pkt_max;
365 u32 rx_pkt_posted;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800366 atomic_t ht_node_cnt;
367 struct list_head connected_nodes;
368 /* struct list_head hashtable[NES_CM_HASHTABLE_SIZE]; */
369 spinlock_t ht_lock;
370
371 struct timer_list tcp_timer;
372
373 struct nes_cm_ops *api;
374
375 int (*post_event)(struct nes_cm_event *event);
376 atomic_t events_posted;
377 struct workqueue_struct *event_wq;
378 struct workqueue_struct *disconn_wq;
379
380 atomic_t node_cnt;
381 u64 aborted_connects;
382 u32 options;
383
384 struct nes_cm_node *current_listen_node;
385};
386
387
388#define NES_CM_SET_PKT_SIZE (1 << 1)
389#define NES_CM_SET_FREE_PKT_Q_SIZE (1 << 2)
390
391/* CM ops/API for client interface */
392struct nes_cm_ops {
393 int (*accelerated)(struct nes_cm_core *, struct nes_cm_node *);
394 struct nes_cm_listener * (*listen)(struct nes_cm_core *, struct nes_vnic *,
395 struct nes_cm_info *);
396 int (*stop_listener)(struct nes_cm_core *, struct nes_cm_listener *);
397 struct nes_cm_node * (*connect)(struct nes_cm_core *,
Faisal Latif6492cdf2008-07-24 20:50:45 -0700398 struct nes_vnic *, u16, void *,
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800399 struct nes_cm_info *);
400 int (*close)(struct nes_cm_core *, struct nes_cm_node *);
401 int (*accept)(struct nes_cm_core *, struct ietf_mpa_frame *,
402 struct nes_cm_node *);
403 int (*reject)(struct nes_cm_core *, struct ietf_mpa_frame *,
404 struct nes_cm_node *);
Faisal Latif4a14f6a2008-11-21 20:50:49 -0600405 int (*recv_pkt)(struct nes_cm_core *, struct nes_vnic *,
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800406 struct sk_buff *);
407 int (*destroy_cm_core)(struct nes_cm_core *);
408 int (*get)(struct nes_cm_core *);
409 int (*set)(struct nes_cm_core *, u32, u32);
410};
411
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800412int schedule_nes_timer(struct nes_cm_node *, struct sk_buff *,
413 enum nes_timer_type, int, int);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800414
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800415int nes_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
416int nes_reject(struct iw_cm_id *, const void *, u8);
417int nes_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
418int nes_create_listen(struct iw_cm_id *, int);
419int nes_destroy_listen(struct iw_cm_id *);
420
421int nes_cm_recv(struct sk_buff *, struct net_device *);
422int nes_cm_start(void);
423int nes_cm_stop(void);
424
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800425#endif /* NES_CM_H */