2 * Copyright (c) 2006 - 2009 Intel-NE, Inc. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
39 #define NES_MANAGE_APBVT_DEL 0
40 #define NES_MANAGE_APBVT_ADD 1
42 #define NES_MPA_REQUEST_ACCEPT 1
43 #define NES_MPA_REQUEST_REJECT 2
45 /* 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
52 IETF_MPA_FLAGS_MARKERS = 0x80, /* receive Markers */
53 IETF_MPA_FLAGS_CRC = 0x40, /* receive Markers */
54 IETF_MPA_FLAGS_REJECT = 0x20, /* Reject */
57 struct ietf_mpa_frame {
58 u8 key[IETF_MPA_KEY_SIZE];
65 #define ietf_mpa_req_resp_frame ietf_mpa_frame
69 __le32 DstIpAdrIndex; /* Only most significant 5 bits are valid */
71 __be16 TcpPorts[2]; /* src is low, dest is high */
78 NES_TIMER_NODE_CLEANUP,
82 #define NES_PASSIVE_STATE_INDICATED 0
83 #define NES_DO_NOT_SEND_RESET_EVENT 1
84 #define NES_SEND_RESET_EVENT 2
93 #define TCP_OPTIONS_PADDING 3
100 enum option_numbers {
104 OPTION_NUMBER_WINDOW_SCALE,
105 OPTION_NUMBER_SACK_PERM,
107 OPTION_NUMBER_WRITE0 = 0xbc
116 struct option_windowscale {
122 union all_known_options {
124 struct option_base as_base;
125 struct option_mss as_mss;
126 struct option_windowscale as_windowscale;
129 struct nes_timer_entry {
130 struct list_head list;
131 unsigned long timetosend; /* jiffies */
139 int close_when_complete;
140 struct net_device *netdev;
143 #define NES_DEFAULT_RETRYS 64
144 #define NES_DEFAULT_RETRANS 8
145 #ifdef CONFIG_INFINIBAND_NES_DEBUG
146 #define NES_RETRY_TIMEOUT (1000*HZ/1000)
148 #define NES_RETRY_TIMEOUT (3000*HZ/1000)
150 #define NES_SHORT_TIME (10)
151 #define NES_LONG_TIME (2000*HZ/1000)
153 #define NES_CM_HASHTABLE_SIZE 1024
154 #define NES_CM_TCP_TIMER_INTERVAL 3000
155 #define NES_CM_DEFAULT_MTU 1540
156 #define NES_CM_DEFAULT_FRAME_CNT 10
157 #define NES_CM_THREAD_STACK_SIZE 256
158 #define NES_CM_DEFAULT_RCV_WND 64240 // before we know that window scaling is allowed
159 #define NES_CM_DEFAULT_RCV_WND_SCALED 256960 // after we know that window scaling is allowed
160 #define NES_CM_DEFAULT_RCV_WND_SCALE 2
161 #define NES_CM_DEFAULT_FREE_PKTS 0x000A
162 #define NES_CM_FREE_PKT_LO_WATERMARK 2
164 #define NES_CM_DEFAULT_MSS 536
166 #define NES_CM_DEF_SEQ 0x159bf75f
167 #define NES_CM_DEF_LOCAL_ID 0x3b47
169 #define NES_CM_DEF_SEQ2 0x18ed5740
170 #define NES_CM_DEF_LOCAL_ID2 0xb807
171 #define MAX_CM_BUFFER 512
174 typedef u32 nes_addr_t;
176 #define nes_cm_tsa_context nes_qp_context
180 /* cm node transition states */
181 enum nes_cm_node_state {
182 NES_CM_STATE_UNKNOWN,
184 NES_CM_STATE_LISTENING,
185 NES_CM_STATE_SYN_RCVD,
186 NES_CM_STATE_SYN_SENT,
187 NES_CM_STATE_ONE_SIDE_ESTABLISHED,
188 NES_CM_STATE_ESTABLISHED,
189 NES_CM_STATE_ACCEPTING,
190 NES_CM_STATE_MPAREQ_SENT,
191 NES_CM_STATE_MPAREQ_RCVD,
192 NES_CM_STATE_MPAREJ_RCVD,
194 NES_CM_STATE_FIN_WAIT1,
195 NES_CM_STATE_FIN_WAIT2,
196 NES_CM_STATE_CLOSE_WAIT,
197 NES_CM_STATE_TIME_WAIT,
198 NES_CM_STATE_LAST_ACK,
199 NES_CM_STATE_CLOSING,
203 enum nes_tcpip_pkt_type {
204 NES_PKT_TYPE_UNKNOWN,
213 /* type of nes connection */
214 enum nes_cm_conn_type {
215 NES_CM_IWARP_CONN_TYPE,
218 /* CM context params */
219 struct nes_cm_tcp_context {
238 struct nes_cm_tsa_context tsa_cntxt;
239 struct timeval sent_ts;
243 enum nes_cm_listener_state {
244 NES_CM_LISTENER_PASSIVE_STATE=1,
245 NES_CM_LISTENER_ACTIVE_STATE=2,
246 NES_CM_LISTENER_EITHER_STATE=3
249 struct nes_cm_listener {
250 struct list_head list;
251 struct nes_cm_core *cm_core;
252 u8 loc_mac[ETH_ALEN];
255 struct iw_cm_id *cm_id;
256 enum nes_cm_conn_type conn_type;
258 struct nes_vnic *nesvnic;
259 atomic_t pend_accepts_cnt;
261 enum nes_cm_listener_state listener_state;
265 /* per connection node and node state information */
267 nes_addr_t loc_addr, rem_addr;
268 u16 loc_port, rem_port;
270 u8 loc_mac[ETH_ALEN];
271 u8 rem_mac[ETH_ALEN];
273 enum nes_cm_node_state state;
274 struct nes_cm_tcp_context tcp_cntxt;
275 struct nes_cm_core *cm_core;
276 struct sk_buff_head resend_list;
278 struct net_device *netdev;
280 struct nes_cm_node *loopbackpartner;
282 struct nes_timer_entry *send_entry;
284 spinlock_t retrans_list_lock;
285 struct nes_timer_entry *recv_entry;
289 struct ietf_mpa_frame mpa_frame;
290 u8 mpa_frame_buf[MAX_CM_BUFFER];
293 struct iw_cm_id *cm_id;
294 struct list_head list;
296 struct nes_cm_listener *listener;
297 enum nes_cm_conn_type conn_type;
298 struct nes_vnic *nesvnic;
301 struct list_head timer_entry;
302 struct list_head reset_entry;
303 struct nes_qp *nesqp;
304 atomic_t passive_state;
307 /* structure for client or CM to fill when making CM api calls. */
308 /* - only need to set relevant data, based on op. */
311 struct iw_cm_id *cm_id;
312 struct net_device *netdev;
320 enum nes_cm_conn_type conn_type;
325 enum nes_cm_event_type {
326 NES_CM_EVENT_UNKNOWN,
327 NES_CM_EVENT_ESTABLISHED,
328 NES_CM_EVENT_MPA_REQ,
329 NES_CM_EVENT_MPA_CONNECT,
330 NES_CM_EVENT_MPA_ACCEPT,
331 NES_CM_EVENT_MPA_REJECT,
332 NES_CM_EVENT_MPA_ESTABLISHED,
333 NES_CM_EVENT_CONNECTED,
336 NES_CM_EVENT_DROPPED_PKT,
337 NES_CM_EVENT_CLOSE_IMMED,
338 NES_CM_EVENT_CLOSE_HARD,
339 NES_CM_EVENT_CLOSE_CLEAN,
340 NES_CM_EVENT_ABORTED,
341 NES_CM_EVENT_SEND_FIRST
344 /* event to post to CM event handler */
345 struct nes_cm_event {
346 enum nes_cm_event_type type;
348 struct nes_cm_info cm_info;
349 struct work_struct event_work;
350 struct nes_cm_node *cm_node;
354 enum nes_cm_node_state state;
356 atomic_t listen_node_cnt;
357 struct nes_cm_node listen_list;
358 spinlock_t listen_list_lock;
363 atomic_t ht_node_cnt;
364 struct list_head connected_nodes;
365 /* struct list_head hashtable[NES_CM_HASHTABLE_SIZE]; */
368 struct timer_list tcp_timer;
370 struct nes_cm_ops *api;
372 int (*post_event)(struct nes_cm_event *event);
373 atomic_t events_posted;
374 struct workqueue_struct *event_wq;
375 struct workqueue_struct *disconn_wq;
378 u64 aborted_connects;
381 struct nes_cm_node *current_listen_node;
385 #define NES_CM_SET_PKT_SIZE (1 << 1)
386 #define NES_CM_SET_FREE_PKT_Q_SIZE (1 << 2)
388 /* CM ops/API for client interface */
390 int (*accelerated)(struct nes_cm_core *, struct nes_cm_node *);
391 struct nes_cm_listener * (*listen)(struct nes_cm_core *, struct nes_vnic *,
392 struct nes_cm_info *);
393 int (*stop_listener)(struct nes_cm_core *, struct nes_cm_listener *);
394 struct nes_cm_node * (*connect)(struct nes_cm_core *,
395 struct nes_vnic *, u16, void *,
396 struct nes_cm_info *);
397 int (*close)(struct nes_cm_core *, struct nes_cm_node *);
398 int (*accept)(struct nes_cm_core *, struct ietf_mpa_frame *,
399 struct nes_cm_node *);
400 int (*reject)(struct nes_cm_core *, struct ietf_mpa_frame *,
401 struct nes_cm_node *);
402 int (*recv_pkt)(struct nes_cm_core *, struct nes_vnic *,
404 int (*destroy_cm_core)(struct nes_cm_core *);
405 int (*get)(struct nes_cm_core *);
406 int (*set)(struct nes_cm_core *, u32, u32);
409 int schedule_nes_timer(struct nes_cm_node *, struct sk_buff *,
410 enum nes_timer_type, int, int);
412 int nes_cm_disconn(struct nes_qp *);
414 int nes_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
415 int nes_reject(struct iw_cm_id *, const void *, u8);
416 int nes_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
417 int nes_create_listen(struct iw_cm_id *, int);
418 int nes_destroy_listen(struct iw_cm_id *);
420 int nes_cm_recv(struct sk_buff *, struct net_device *);
421 int nes_cm_start(void);
422 int nes_cm_stop(void);
424 #endif /* NES_CM_H */