• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2006 - 2014 Intel Corporation.  All rights reserved.
3  *
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 
42 #define NES_MPA_REQUEST_ACCEPT  1
43 #define NES_MPA_REQUEST_REJECT  2
44 
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
50 #define IETF_MAX_PRIV_DATA_LEN 512
51 #define IETF_MPA_FRAME_SIZE    20
52 #define IETF_RTR_MSG_SIZE      4
53 #define IETF_MPA_V2_FLAG       0x10
54 
55 /* IETF RTR MSG Fields               */
56 #define IETF_PEER_TO_PEER       0x8000
57 #define IETF_FLPDU_ZERO_LEN     0x4000
58 #define IETF_RDMA0_WRITE        0x8000
59 #define IETF_RDMA0_READ         0x4000
60 #define IETF_NO_IRD_ORD         0x3FFF
61 #define NES_MAX_IRD		 0x40
62 #define NES_MAX_ORD		 0x7F
63 
64 enum ietf_mpa_flags {
65 	IETF_MPA_FLAGS_MARKERS = 0x80,	/* receive Markers */
66 	IETF_MPA_FLAGS_CRC     = 0x40,	/* receive Markers */
67 	IETF_MPA_FLAGS_REJECT  = 0x20,	/* Reject */
68 };
69 
70 struct ietf_mpa_v1 {
71 	u8 key[IETF_MPA_KEY_SIZE];
72 	u8 flags;
73 	u8 rev;
74 	__be16 priv_data_len;
75 	u8 priv_data[0];
76 };
77 
78 #define ietf_mpa_req_resp_frame ietf_mpa_frame
79 
80 struct ietf_rtr_msg {
81 	__be16 ctrl_ird;
82 	__be16 ctrl_ord;
83 };
84 
85 struct ietf_mpa_v2 {
86 	u8 key[IETF_MPA_KEY_SIZE];
87 	u8 flags;
88 	u8 rev;
89 	 __be16 priv_data_len;
90 	struct ietf_rtr_msg rtr_msg;
91 	u8 priv_data[0];
92 };
93 
94 struct nes_v4_quad {
95 	u32 rsvd0;
96 	__le32 DstIpAdrIndex;	/* Only most significant 5 bits are valid */
97 	__be32 SrcIpadr;
98 	__be16 TcpPorts[2];		/* src is low, dest is high */
99 };
100 
101 struct nes_cm_node;
102 enum nes_timer_type {
103 	NES_TIMER_TYPE_SEND,
104 	NES_TIMER_TYPE_RECV,
105 	NES_TIMER_NODE_CLEANUP,
106 	NES_TIMER_TYPE_CLOSE,
107 };
108 
109 #define NES_PASSIVE_STATE_INDICATED	0
110 #define NES_DO_NOT_SEND_RESET_EVENT	1
111 #define NES_SEND_RESET_EVENT		2
112 
113 #define MAX_NES_IFS 4
114 
115 #define SET_ACK 1
116 #define SET_SYN 2
117 #define SET_FIN 4
118 #define SET_RST 8
119 
120 #define TCP_OPTIONS_PADDING	3
121 
122 struct option_base {
123 	u8 optionnum;
124 	u8 length;
125 };
126 
127 enum option_numbers {
128 	OPTION_NUMBER_END,
129 	OPTION_NUMBER_NONE,
130 	OPTION_NUMBER_MSS,
131 	OPTION_NUMBER_WINDOW_SCALE,
132 	OPTION_NUMBER_SACK_PERM,
133 	OPTION_NUMBER_SACK,
134 	OPTION_NUMBER_WRITE0 = 0xbc
135 };
136 
137 struct option_mss {
138 	u8 optionnum;
139 	u8 length;
140 	__be16 mss;
141 };
142 
143 struct option_windowscale {
144 	u8 optionnum;
145 	u8 length;
146 	u8 shiftcount;
147 };
148 
149 union all_known_options {
150 	char as_end;
151 	struct option_base as_base;
152 	struct option_mss as_mss;
153 	struct option_windowscale as_windowscale;
154 };
155 
156 struct nes_timer_entry {
157 	struct list_head list;
158 	unsigned long timetosend;	/* jiffies */
159 	struct sk_buff *skb;
160 	u32 type;
161 	u32 retrycount;
162 	u32 retranscount;
163 	u32 context;
164 	u32 seq_num;
165 	u32 send_retrans;
166 	int close_when_complete;
167 	struct net_device *netdev;
168 };
169 
170 #define NES_DEFAULT_RETRYS  64
171 #define NES_DEFAULT_RETRANS 8
172 #ifdef CONFIG_INFINIBAND_NES_DEBUG
173 #define NES_RETRY_TIMEOUT   (1000*HZ/1000)
174 #else
175 #define NES_RETRY_TIMEOUT   (3000*HZ/1000)
176 #endif
177 #define NES_SHORT_TIME      (10)
178 #define NES_LONG_TIME       (2000*HZ/1000)
179 #define NES_MAX_TIMEOUT     ((unsigned long) (12*HZ))
180 
181 #define NES_CM_HASHTABLE_SIZE         1024
182 #define NES_CM_TCP_TIMER_INTERVAL     3000
183 #define NES_CM_DEFAULT_MTU            1540
184 #define NES_CM_DEFAULT_FRAME_CNT      10
185 #define NES_CM_THREAD_STACK_SIZE      256
186 #define NES_CM_DEFAULT_RCV_WND        64240	// before we know that window scaling is allowed
187 #define NES_CM_DEFAULT_RCV_WND_SCALED 256960  // after we know that window scaling is allowed
188 #define NES_CM_DEFAULT_RCV_WND_SCALE  2
189 #define NES_CM_DEFAULT_FREE_PKTS      0x000A
190 #define NES_CM_FREE_PKT_LO_WATERMARK  2
191 
192 #define NES_CM_DEFAULT_MSS   536
193 
194 #define NES_CM_DEF_SEQ       0x159bf75f
195 #define NES_CM_DEF_LOCAL_ID  0x3b47
196 
197 #define NES_CM_DEF_SEQ2      0x18ed5740
198 #define NES_CM_DEF_LOCAL_ID2 0xb807
199 #define	MAX_CM_BUFFER	(IETF_MPA_FRAME_SIZE + IETF_RTR_MSG_SIZE + IETF_MAX_PRIV_DATA_LEN)
200 
201 typedef u32 nes_addr_t;
202 
203 #define nes_cm_tsa_context nes_qp_context
204 
205 struct nes_qp;
206 
207 /* cm node transition states */
208 enum nes_cm_node_state {
209 	NES_CM_STATE_UNKNOWN,
210 	NES_CM_STATE_INITED,
211 	NES_CM_STATE_LISTENING,
212 	NES_CM_STATE_SYN_RCVD,
213 	NES_CM_STATE_SYN_SENT,
214 	NES_CM_STATE_ONE_SIDE_ESTABLISHED,
215 	NES_CM_STATE_ESTABLISHED,
216 	NES_CM_STATE_ACCEPTING,
217 	NES_CM_STATE_MPAREQ_SENT,
218 	NES_CM_STATE_MPAREQ_RCVD,
219 	NES_CM_STATE_MPAREJ_RCVD,
220 	NES_CM_STATE_TSA,
221 	NES_CM_STATE_FIN_WAIT1,
222 	NES_CM_STATE_FIN_WAIT2,
223 	NES_CM_STATE_CLOSE_WAIT,
224 	NES_CM_STATE_TIME_WAIT,
225 	NES_CM_STATE_LAST_ACK,
226 	NES_CM_STATE_CLOSING,
227 	NES_CM_STATE_LISTENER_DESTROYED,
228 	NES_CM_STATE_CLOSED
229 };
230 
231 enum mpa_frame_version {
232 	IETF_MPA_V1 = 1,
233 	IETF_MPA_V2 = 2
234 };
235 
236 enum mpa_frame_key {
237 	MPA_KEY_REQUEST,
238 	MPA_KEY_REPLY
239 };
240 
241 enum send_rdma0 {
242 	SEND_RDMA_READ_ZERO = 1,
243 	SEND_RDMA_WRITE_ZERO = 2
244 };
245 
246 enum nes_tcpip_pkt_type {
247 	NES_PKT_TYPE_UNKNOWN,
248 	NES_PKT_TYPE_SYN,
249 	NES_PKT_TYPE_SYNACK,
250 	NES_PKT_TYPE_ACK,
251 	NES_PKT_TYPE_FIN,
252 	NES_PKT_TYPE_RST
253 };
254 
255 
256 /* type of nes connection */
257 enum nes_cm_conn_type {
258 	NES_CM_IWARP_CONN_TYPE,
259 };
260 
261 /* CM context params */
262 struct nes_cm_tcp_context {
263 	u8  client;
264 
265 	u32 loc_seq_num;
266 	u32 loc_ack_num;
267 	u32 rem_ack_num;
268 	u32 rcv_nxt;
269 
270 	u32 loc_id;
271 	u32 rem_id;
272 
273 	u32 snd_wnd;
274 	u32 max_snd_wnd;
275 
276 	u32 rcv_wnd;
277 	u32 mss;
278 	u8  snd_wscale;
279 	u8  rcv_wscale;
280 
281 	struct nes_cm_tsa_context tsa_cntxt;
282 	struct timeval            sent_ts;
283 };
284 
285 
286 enum nes_cm_listener_state {
287 	NES_CM_LISTENER_PASSIVE_STATE = 1,
288 	NES_CM_LISTENER_ACTIVE_STATE = 2,
289 	NES_CM_LISTENER_EITHER_STATE = 3
290 };
291 
292 struct nes_cm_listener {
293 	struct list_head           list;
294 	struct nes_cm_core         *cm_core;
295 	u8                         loc_mac[ETH_ALEN];
296 	nes_addr_t                 loc_addr, mapped_loc_addr;
297 	u16                        loc_port, mapped_loc_port;
298 	struct iw_cm_id            *cm_id;
299 	enum nes_cm_conn_type      conn_type;
300 	atomic_t                   ref_count;
301 	struct nes_vnic            *nesvnic;
302 	atomic_t                   pend_accepts_cnt;
303 	int                        backlog;
304 	enum nes_cm_listener_state listener_state;
305 	u32                        reused_node;
306 	u8			   tos;
307 };
308 
309 /* per connection node and node state information */
310 struct nes_cm_node {
311 	nes_addr_t                loc_addr, rem_addr;
312 	nes_addr_t                mapped_loc_addr, mapped_rem_addr;
313 	u16                       loc_port, rem_port;
314 	u16                       mapped_loc_port, mapped_rem_port;
315 
316 	u8                        loc_mac[ETH_ALEN];
317 	u8                        rem_mac[ETH_ALEN];
318 
319 	enum nes_cm_node_state    state;
320 	struct nes_cm_tcp_context tcp_cntxt;
321 	struct nes_cm_core        *cm_core;
322 	struct sk_buff_head       resend_list;
323 	atomic_t                  ref_count;
324 	struct net_device         *netdev;
325 
326 	struct nes_cm_node        *loopbackpartner;
327 
328 	struct nes_timer_entry	  *send_entry;
329 	struct nes_timer_entry    *recv_entry;
330 	spinlock_t                retrans_list_lock;
331 	enum send_rdma0           send_rdma0_op;
332 
333 	union {
334 		struct ietf_mpa_v1 mpa_frame;
335 		struct ietf_mpa_v2 mpa_v2_frame;
336 		u8                 mpa_frame_buf[MAX_CM_BUFFER];
337 	};
338 	enum mpa_frame_version    mpa_frame_rev;
339 	u16			  ird_size;
340 	u16                       ord_size;
341 	u16			  mpav2_ird_ord;
342 
343 	u16                       mpa_frame_size;
344 	struct iw_cm_id           *cm_id;
345 	struct list_head          list;
346 	int                       accelerated;
347 	struct nes_cm_listener    *listener;
348 	enum nes_cm_conn_type     conn_type;
349 	struct nes_vnic           *nesvnic;
350 	int                       apbvt_set;
351 	int                       accept_pend;
352 	struct list_head	timer_entry;
353 	struct list_head	reset_entry;
354 	struct nes_qp		*nesqp;
355 	atomic_t 		passive_state;
356 	u8			tos;
357 };
358 
359 /* structure for client or CM to fill when making CM api calls. */
360 /*	- only need to set relevant data, based on op. */
361 struct nes_cm_info {
362 	union {
363 		struct iw_cm_id   *cm_id;
364 		struct net_device *netdev;
365 	};
366 
367 	u16 loc_port;
368 	u16 rem_port;
369 	nes_addr_t loc_addr;
370 	nes_addr_t rem_addr;
371 	u16 mapped_loc_port;
372 	u16 mapped_rem_port;
373 	nes_addr_t mapped_loc_addr;
374 	nes_addr_t mapped_rem_addr;
375 
376 	enum nes_cm_conn_type  conn_type;
377 	int backlog;
378 };
379 
380 /* CM event codes */
381 enum  nes_cm_event_type {
382 	NES_CM_EVENT_UNKNOWN,
383 	NES_CM_EVENT_ESTABLISHED,
384 	NES_CM_EVENT_MPA_REQ,
385 	NES_CM_EVENT_MPA_CONNECT,
386 	NES_CM_EVENT_MPA_ACCEPT,
387 	NES_CM_EVENT_MPA_REJECT,
388 	NES_CM_EVENT_MPA_ESTABLISHED,
389 	NES_CM_EVENT_CONNECTED,
390 	NES_CM_EVENT_CLOSED,
391 	NES_CM_EVENT_RESET,
392 	NES_CM_EVENT_DROPPED_PKT,
393 	NES_CM_EVENT_CLOSE_IMMED,
394 	NES_CM_EVENT_CLOSE_HARD,
395 	NES_CM_EVENT_CLOSE_CLEAN,
396 	NES_CM_EVENT_ABORTED,
397 	NES_CM_EVENT_SEND_FIRST
398 };
399 
400 /* event to post to CM event handler */
401 struct nes_cm_event {
402 	enum nes_cm_event_type type;
403 
404 	struct nes_cm_info cm_info;
405 	struct work_struct event_work;
406 	struct nes_cm_node *cm_node;
407 };
408 
409 struct nes_cm_core {
410 	enum nes_cm_node_state  state;
411 
412 	atomic_t                listen_node_cnt;
413 	struct nes_cm_node      listen_list;
414 	spinlock_t              listen_list_lock;
415 
416 	u32                     mtu;
417 	u32                     free_tx_pkt_max;
418 	u32                     rx_pkt_posted;
419 	atomic_t                ht_node_cnt;
420 	struct list_head        connected_nodes;
421 	/* struct list_head hashtable[NES_CM_HASHTABLE_SIZE]; */
422 	spinlock_t              ht_lock;
423 
424 	struct timer_list       tcp_timer;
425 
426 	struct nes_cm_ops       *api;
427 
428 	int (*post_event)(struct nes_cm_event *event);
429 	atomic_t                events_posted;
430 	struct workqueue_struct *event_wq;
431 	struct workqueue_struct *disconn_wq;
432 
433 	atomic_t                node_cnt;
434 	u64                     aborted_connects;
435 	u32                     options;
436 
437 	struct nes_cm_node      *current_listen_node;
438 };
439 
440 
441 #define NES_CM_SET_PKT_SIZE        (1 << 1)
442 #define NES_CM_SET_FREE_PKT_Q_SIZE (1 << 2)
443 
444 /* CM ops/API for client interface */
445 struct nes_cm_ops {
446 	int (*accelerated)(struct nes_cm_core *, struct nes_cm_node *);
447 	struct nes_cm_listener * (*listen)(struct nes_cm_core *, struct nes_vnic *,
448 			struct nes_cm_info *);
449 	int (*stop_listener)(struct nes_cm_core *, struct nes_cm_listener *);
450 	struct nes_cm_node * (*connect)(struct nes_cm_core *,
451 			struct nes_vnic *, u16, void *,
452 			struct nes_cm_info *);
453 	int (*close)(struct nes_cm_core *, struct nes_cm_node *);
454 	int (*accept)(struct nes_cm_core *, struct nes_cm_node *);
455 	int (*reject)(struct nes_cm_core *, struct nes_cm_node *);
456 	int (*recv_pkt)(struct nes_cm_core *, struct nes_vnic *,
457 			struct sk_buff *);
458 	int (*destroy_cm_core)(struct nes_cm_core *);
459 	int (*get)(struct nes_cm_core *);
460 	int (*set)(struct nes_cm_core *, u32, u32);
461 };
462 
463 int schedule_nes_timer(struct nes_cm_node *, struct sk_buff *,
464 		enum nes_timer_type, int, int);
465 
466 int nes_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
467 int nes_reject(struct iw_cm_id *, const void *, u8);
468 int nes_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
469 int nes_create_listen(struct iw_cm_id *, int);
470 int nes_destroy_listen(struct iw_cm_id *);
471 
472 int nes_cm_recv(struct sk_buff *, struct net_device *);
473 int nes_cm_start(void);
474 int nes_cm_stop(void);
475 int nes_add_ref_cm_node(struct nes_cm_node *cm_node);
476 int nes_rem_ref_cm_node(struct nes_cm_node *cm_node);
477 
478 #endif			/* NES_CM_H */
479