2 * Copyright (c) 2006 - 2014 Intel Corporation. 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
35 #define TCPOPT_TIMESTAMP 8
37 #include <linux/atomic.h>
38 #include <linux/skbuff.h>
40 #include <linux/tcp.h>
41 #include <linux/init.h>
42 #include <linux/if_arp.h>
43 #include <linux/if_vlan.h>
44 #include <linux/notifier.h>
45 #include <linux/net.h>
46 #include <linux/types.h>
47 #include <linux/timer.h>
48 #include <linux/time.h>
49 #include <linux/delay.h>
50 #include <linux/etherdevice.h>
51 #include <linux/netdevice.h>
52 #include <linux/random.h>
53 #include <linux/list.h>
54 #include <linux/threads.h>
55 #include <linux/highmem.h>
56 #include <linux/slab.h>
58 #include <net/neighbour.h>
59 #include <net/route.h>
60 #include <net/ip_fib.h>
62 #include <linux/fcntl.h>
67 u32 cm_packets_bounced
;
68 u32 cm_packets_dropped
;
69 u32 cm_packets_retrans
;
70 u32 cm_packets_created
;
71 u32 cm_packets_received
;
72 atomic_t cm_listens_created
;
73 atomic_t cm_listens_destroyed
;
75 atomic_t cm_loopbacks
;
76 atomic_t cm_nodes_created
;
77 atomic_t cm_nodes_destroyed
;
78 atomic_t cm_accel_dropped_pkts
;
79 atomic_t cm_resets_recvd
;
81 static inline int mini_cm_accelerated(struct nes_cm_core
*, struct nes_cm_node
*);
82 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*, struct nes_vnic
*, struct nes_cm_info
*);
83 static int mini_cm_del_listen(struct nes_cm_core
*, struct nes_cm_listener
*);
84 static struct nes_cm_node
*mini_cm_connect(struct nes_cm_core
*, struct nes_vnic
*, u16
, void *, struct nes_cm_info
*);
85 static int mini_cm_close(struct nes_cm_core
*, struct nes_cm_node
*);
86 static int mini_cm_accept(struct nes_cm_core
*, struct nes_cm_node
*);
87 static int mini_cm_reject(struct nes_cm_core
*, struct nes_cm_node
*);
88 static int mini_cm_recv_pkt(struct nes_cm_core
*, struct nes_vnic
*, struct sk_buff
*);
89 static int mini_cm_dealloc_core(struct nes_cm_core
*);
90 static int mini_cm_get(struct nes_cm_core
*);
91 static int mini_cm_set(struct nes_cm_core
*, u32
, u32
);
93 static void form_cm_frame(struct sk_buff
*, struct nes_cm_node
*, void *, u32
, void *, u32
, u8
);
94 static int add_ref_cm_node(struct nes_cm_node
*);
95 static int rem_ref_cm_node(struct nes_cm_core
*, struct nes_cm_node
*);
97 static int nes_cm_disconn_true(struct nes_qp
*);
98 static int nes_cm_post_event(struct nes_cm_event
*event
);
99 static int nes_disconnect(struct nes_qp
*nesqp
, int abrupt
);
100 static void nes_disconnect_worker(struct work_struct
*work
);
102 static int send_mpa_request(struct nes_cm_node
*, struct sk_buff
*);
103 static int send_mpa_reject(struct nes_cm_node
*);
104 static int send_syn(struct nes_cm_node
*, u32
, struct sk_buff
*);
105 static int send_reset(struct nes_cm_node
*, struct sk_buff
*);
106 static int send_ack(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
);
107 static int send_fin(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
);
108 static void process_packet(struct nes_cm_node
*, struct sk_buff
*, struct nes_cm_core
*);
110 static void active_open_err(struct nes_cm_node
*, struct sk_buff
*, int);
111 static void passive_open_err(struct nes_cm_node
*, struct sk_buff
*, int);
112 static void cleanup_retrans_entry(struct nes_cm_node
*);
113 static void handle_rcv_mpa(struct nes_cm_node
*, struct sk_buff
*);
114 static void free_retrans_entry(struct nes_cm_node
*cm_node
);
115 static int handle_tcp_options(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
, struct sk_buff
*skb
, int optionsize
, int passive
);
117 /* CM event handler functions */
118 static void cm_event_connected(struct nes_cm_event
*);
119 static void cm_event_connect_error(struct nes_cm_event
*);
120 static void cm_event_reset(struct nes_cm_event
*);
121 static void cm_event_mpa_req(struct nes_cm_event
*);
122 static void cm_event_mpa_reject(struct nes_cm_event
*);
123 static void handle_recv_entry(struct nes_cm_node
*cm_node
, u32 rem_node
);
125 /* MPA build functions */
126 static int cm_build_mpa_frame(struct nes_cm_node
*, u8
**, u16
*, u8
*, u8
);
127 static void build_mpa_v2(struct nes_cm_node
*, void *, u8
);
128 static void build_mpa_v1(struct nes_cm_node
*, void *, u8
);
129 static void build_rdma0_msg(struct nes_cm_node
*, struct nes_qp
**);
131 static void print_core(struct nes_cm_core
*core
);
132 static void record_ird_ord(struct nes_cm_node
*, u16
, u16
);
134 /* External CM API Interface */
135 /* instance of function pointers for client API */
136 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
137 static const struct nes_cm_ops nes_cm_api
= {
146 mini_cm_dealloc_core
,
151 static struct nes_cm_core
*g_cm_core
;
153 atomic_t cm_connects
;
155 atomic_t cm_disconnects
;
157 atomic_t cm_connecteds
;
158 atomic_t cm_connect_reqs
;
161 int nes_add_ref_cm_node(struct nes_cm_node
*cm_node
)
163 return add_ref_cm_node(cm_node
);
166 int nes_rem_ref_cm_node(struct nes_cm_node
*cm_node
)
168 return rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
173 static struct nes_cm_event
*create_event(struct nes_cm_node
* cm_node
,
174 enum nes_cm_event_type type
)
176 struct nes_cm_event
*event
;
181 /* allocate an empty event */
182 event
= kzalloc(sizeof(*event
), GFP_ATOMIC
);
188 event
->cm_node
= cm_node
;
189 event
->cm_info
.rem_addr
= cm_node
->rem_addr
;
190 event
->cm_info
.loc_addr
= cm_node
->loc_addr
;
191 event
->cm_info
.rem_port
= cm_node
->rem_port
;
192 event
->cm_info
.loc_port
= cm_node
->loc_port
;
193 event
->cm_info
.cm_id
= cm_node
->cm_id
;
195 nes_debug(NES_DBG_CM
, "cm_node=%p Created event=%p, type=%u, "
196 "dst_addr=%08x[%x], src_addr=%08x[%x]\n",
197 cm_node
, event
, type
, event
->cm_info
.loc_addr
,
198 event
->cm_info
.loc_port
, event
->cm_info
.rem_addr
,
199 event
->cm_info
.rem_port
);
201 nes_cm_post_event(event
);
209 static int send_mpa_request(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
212 u8
*start_ptr
= &start_addr
;
213 u8
**start_buff
= &start_ptr
;
217 nes_debug(NES_DBG_CM
, "skb set to NULL\n");
221 /* send an MPA Request frame */
222 cm_build_mpa_frame(cm_node
, start_buff
, &buff_len
, NULL
, MPA_KEY_REQUEST
);
223 form_cm_frame(skb
, cm_node
, NULL
, 0, *start_buff
, buff_len
, SET_ACK
);
225 return schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
230 static int send_mpa_reject(struct nes_cm_node
*cm_node
)
232 struct sk_buff
*skb
= NULL
;
234 u8
*start_ptr
= &start_addr
;
235 u8
**start_buff
= &start_ptr
;
237 struct ietf_mpa_v1
*mpa_frame
;
239 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
241 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
245 /* send an MPA reject frame */
246 cm_build_mpa_frame(cm_node
, start_buff
, &buff_len
, NULL
, MPA_KEY_REPLY
);
247 mpa_frame
= (struct ietf_mpa_v1
*)*start_buff
;
248 mpa_frame
->flags
|= IETF_MPA_FLAGS_REJECT
;
249 form_cm_frame(skb
, cm_node
, NULL
, 0, *start_buff
, buff_len
, SET_ACK
| SET_FIN
);
251 cm_node
->state
= NES_CM_STATE_FIN_WAIT1
;
252 return schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
257 * recv_mpa - process a received TCP pkt, we are expecting an
260 static int parse_mpa(struct nes_cm_node
*cm_node
, u8
*buffer
, u32
*type
,
263 struct ietf_mpa_v1
*mpa_frame
;
264 struct ietf_mpa_v2
*mpa_v2_frame
;
265 struct ietf_rtr_msg
*rtr_msg
;
269 *type
= NES_MPA_REQUEST_ACCEPT
;
271 /* assume req frame is in tcp data payload */
272 if (len
< sizeof(struct ietf_mpa_v1
)) {
273 nes_debug(NES_DBG_CM
, "The received ietf buffer was too small (%x)\n", len
);
277 /* points to the beginning of the frame, which could be MPA V1 or V2 */
278 mpa_frame
= (struct ietf_mpa_v1
*)buffer
;
279 mpa_hdr_len
= sizeof(struct ietf_mpa_v1
);
280 priv_data_len
= ntohs(mpa_frame
->priv_data_len
);
282 /* make sure mpa private data len is less than 512 bytes */
283 if (priv_data_len
> IETF_MAX_PRIV_DATA_LEN
) {
284 nes_debug(NES_DBG_CM
, "The received Length of Private"
285 " Data field exceeds 512 octets\n");
289 * make sure MPA receiver interoperate with the
290 * received MPA version and MPA key information
293 if (mpa_frame
->rev
!= IETF_MPA_V1
&& mpa_frame
->rev
!= IETF_MPA_V2
) {
294 nes_debug(NES_DBG_CM
, "The received mpa version"
295 " is not supported\n");
299 * backwards compatibility only
301 if (mpa_frame
->rev
> cm_node
->mpa_frame_rev
) {
302 nes_debug(NES_DBG_CM
, "The received mpa version"
303 " can not be interoperated\n");
306 cm_node
->mpa_frame_rev
= mpa_frame
->rev
;
309 if (cm_node
->state
!= NES_CM_STATE_MPAREQ_SENT
) {
310 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
)) {
311 nes_debug(NES_DBG_CM
, "Unexpected MPA Key received \n");
315 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
)) {
316 nes_debug(NES_DBG_CM
, "Unexpected MPA Key received \n");
321 if (priv_data_len
+ mpa_hdr_len
!= len
) {
322 nes_debug(NES_DBG_CM
, "The received ietf buffer was not right"
323 " complete (%x + %x != %x)\n",
324 priv_data_len
, mpa_hdr_len
, len
);
327 /* make sure it does not exceed the max size */
328 if (len
> MAX_CM_BUFFER
) {
329 nes_debug(NES_DBG_CM
, "The received ietf buffer was too large"
330 " (%x + %x != %x)\n",
331 priv_data_len
, mpa_hdr_len
, len
);
335 cm_node
->mpa_frame_size
= priv_data_len
;
337 switch (mpa_frame
->rev
) {
344 mpa_v2_frame
= (struct ietf_mpa_v2
*)buffer
;
345 mpa_hdr_len
+= IETF_RTR_MSG_SIZE
;
346 cm_node
->mpa_frame_size
-= IETF_RTR_MSG_SIZE
;
347 rtr_msg
= &mpa_v2_frame
->rtr_msg
;
349 /* parse rtr message */
350 rtr_ctrl_ird
= ntohs(rtr_msg
->ctrl_ird
);
351 rtr_ctrl_ord
= ntohs(rtr_msg
->ctrl_ord
);
352 ird_size
= rtr_ctrl_ird
& IETF_NO_IRD_ORD
;
353 ord_size
= rtr_ctrl_ord
& IETF_NO_IRD_ORD
;
355 if (!(rtr_ctrl_ird
& IETF_PEER_TO_PEER
)) {
359 if (ird_size
== IETF_NO_IRD_ORD
|| ord_size
== IETF_NO_IRD_ORD
)
360 cm_node
->mpav2_ird_ord
= IETF_NO_IRD_ORD
;
362 if (cm_node
->mpav2_ird_ord
!= IETF_NO_IRD_ORD
) {
364 if (cm_node
->state
!= NES_CM_STATE_MPAREQ_SENT
) {
365 /* we are still negotiating */
366 if (ord_size
> NES_MAX_IRD
) {
367 cm_node
->ird_size
= NES_MAX_IRD
;
369 cm_node
->ird_size
= ord_size
;
371 (rtr_ctrl_ord
& IETF_RDMA0_READ
)) {
372 cm_node
->ird_size
= 1;
373 nes_debug(NES_DBG_CM
,
374 "%s: Remote peer doesn't support RDMA0_READ (ord=%u)\n",
378 if (ird_size
> NES_MAX_ORD
)
379 cm_node
->ord_size
= NES_MAX_ORD
;
381 cm_node
->ord_size
= ird_size
;
382 } else { /* initiator */
383 if (ord_size
> NES_MAX_IRD
) {
384 nes_debug(NES_DBG_CM
,
385 "%s: Unable to support the requested (ord =%u)\n",
389 cm_node
->ird_size
= ord_size
;
391 if (ird_size
> NES_MAX_ORD
) {
392 cm_node
->ord_size
= NES_MAX_ORD
;
395 (rtr_ctrl_ord
& IETF_RDMA0_READ
)) {
396 nes_debug(NES_DBG_CM
,
397 "%s: Remote peer doesn't support RDMA0_READ (ird=%u)\n",
401 cm_node
->ord_size
= ird_size
;
407 if (rtr_ctrl_ord
& IETF_RDMA0_READ
) {
408 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
410 } else if (rtr_ctrl_ord
& IETF_RDMA0_WRITE
) {
411 cm_node
->send_rdma0_op
= SEND_RDMA_WRITE_ZERO
;
412 } else { /* Not supported RDMA0 operation */
422 /* copy entire MPA frame to our cm_node's frame */
423 memcpy(cm_node
->mpa_frame_buf
, buffer
+ mpa_hdr_len
, cm_node
->mpa_frame_size
);
425 if (mpa_frame
->flags
& IETF_MPA_FLAGS_REJECT
)
426 *type
= NES_MPA_REQUEST_REJECT
;
432 * form_cm_frame - get a free packet and build empty frame Use
433 * node info to build.
435 static void form_cm_frame(struct sk_buff
*skb
,
436 struct nes_cm_node
*cm_node
, void *options
, u32 optionsize
,
437 void *data
, u32 datasize
, u8 flags
)
443 u16 packetsize
= sizeof(*iph
);
445 packetsize
+= sizeof(*tcph
);
446 packetsize
+= optionsize
+ datasize
;
449 memset(skb
->data
, 0x00, ETH_HLEN
+ sizeof(*iph
) + sizeof(*tcph
));
451 buf
= skb_put(skb
, packetsize
+ ETH_HLEN
);
453 ethh
= (struct ethhdr
*)buf
;
456 iph
= (struct iphdr
*)buf
;
458 tcph
= (struct tcphdr
*)buf
;
459 skb_reset_mac_header(skb
);
460 skb_set_network_header(skb
, ETH_HLEN
);
461 skb_set_transport_header(skb
, ETH_HLEN
+ sizeof(*iph
));
462 buf
+= sizeof(*tcph
);
464 skb
->ip_summed
= CHECKSUM_PARTIAL
;
465 if (!(cm_node
->netdev
->features
& NETIF_F_IP_CSUM
))
466 skb
->ip_summed
= CHECKSUM_NONE
;
467 skb
->protocol
= htons(0x800);
469 skb
->mac_len
= ETH_HLEN
;
471 memcpy(ethh
->h_dest
, cm_node
->rem_mac
, ETH_ALEN
);
472 memcpy(ethh
->h_source
, cm_node
->loc_mac
, ETH_ALEN
);
473 ethh
->h_proto
= htons(0x0800);
475 iph
->version
= IPVERSION
;
476 iph
->ihl
= 5; /* 5 * 4Byte words, IP headr len */
478 iph
->tot_len
= htons(packetsize
);
479 iph
->id
= htons(++cm_node
->tcp_cntxt
.loc_id
);
481 iph
->frag_off
= htons(0x4000);
483 iph
->protocol
= 0x06; /* IPPROTO_TCP */
485 iph
->saddr
= htonl(cm_node
->loc_addr
);
486 iph
->daddr
= htonl(cm_node
->rem_addr
);
488 tcph
->source
= htons(cm_node
->loc_port
);
489 tcph
->dest
= htons(cm_node
->rem_port
);
490 tcph
->seq
= htonl(cm_node
->tcp_cntxt
.loc_seq_num
);
492 if (flags
& SET_ACK
) {
493 cm_node
->tcp_cntxt
.loc_ack_num
= cm_node
->tcp_cntxt
.rcv_nxt
;
494 tcph
->ack_seq
= htonl(cm_node
->tcp_cntxt
.loc_ack_num
);
500 if (flags
& SET_SYN
) {
501 cm_node
->tcp_cntxt
.loc_seq_num
++;
504 cm_node
->tcp_cntxt
.loc_seq_num
+= datasize
;
507 if (flags
& SET_FIN
) {
508 cm_node
->tcp_cntxt
.loc_seq_num
++;
515 tcph
->doff
= (u16
)((sizeof(*tcph
) + optionsize
+ 3) >> 2);
516 tcph
->window
= htons(cm_node
->tcp_cntxt
.rcv_wnd
);
519 memcpy(buf
, options
, optionsize
);
522 memcpy(buf
, data
, datasize
);
524 skb_shinfo(skb
)->nr_frags
= 0;
525 cm_packets_created
++;
529 * print_core - dump a cm core
531 static void print_core(struct nes_cm_core
*core
)
533 nes_debug(NES_DBG_CM
, "---------------------------------------------\n");
534 nes_debug(NES_DBG_CM
, "CM Core -- (core = %p )\n", core
);
537 nes_debug(NES_DBG_CM
, "---------------------------------------------\n");
539 nes_debug(NES_DBG_CM
, "State : %u \n", core
->state
);
541 nes_debug(NES_DBG_CM
, "Listen Nodes : %u \n", atomic_read(&core
->listen_node_cnt
));
542 nes_debug(NES_DBG_CM
, "Active Nodes : %u \n", atomic_read(&core
->node_cnt
));
544 nes_debug(NES_DBG_CM
, "core : %p \n", core
);
546 nes_debug(NES_DBG_CM
, "-------------- end core ---------------\n");
549 static void record_ird_ord(struct nes_cm_node
*cm_node
,
550 u16 conn_ird
, u16 conn_ord
)
552 if (conn_ird
> NES_MAX_IRD
)
553 conn_ird
= NES_MAX_IRD
;
555 if (conn_ord
> NES_MAX_ORD
)
556 conn_ord
= NES_MAX_ORD
;
558 cm_node
->ird_size
= conn_ird
;
559 cm_node
->ord_size
= conn_ord
;
563 * cm_build_mpa_frame - build a MPA V1 frame or MPA V2 frame
565 static int cm_build_mpa_frame(struct nes_cm_node
*cm_node
, u8
**start_buff
,
566 u16
*buff_len
, u8
*pci_mem
, u8 mpa_key
)
570 *start_buff
= (pci_mem
) ? pci_mem
: &cm_node
->mpa_frame_buf
[0];
572 switch (cm_node
->mpa_frame_rev
) {
574 *start_buff
= (u8
*)*start_buff
+ sizeof(struct ietf_rtr_msg
);
575 *buff_len
= sizeof(struct ietf_mpa_v1
) + cm_node
->mpa_frame_size
;
576 build_mpa_v1(cm_node
, *start_buff
, mpa_key
);
579 *buff_len
= sizeof(struct ietf_mpa_v2
) + cm_node
->mpa_frame_size
;
580 build_mpa_v2(cm_node
, *start_buff
, mpa_key
);
589 * build_mpa_v2 - build a MPA V2 frame
591 static void build_mpa_v2(struct nes_cm_node
*cm_node
,
592 void *start_addr
, u8 mpa_key
)
594 struct ietf_mpa_v2
*mpa_frame
= (struct ietf_mpa_v2
*)start_addr
;
595 struct ietf_rtr_msg
*rtr_msg
= &mpa_frame
->rtr_msg
;
599 /* initialize the upper 5 bytes of the frame */
600 build_mpa_v1(cm_node
, start_addr
, mpa_key
);
601 mpa_frame
->flags
|= IETF_MPA_V2_FLAG
; /* set a bit to indicate MPA V2 */
602 mpa_frame
->priv_data_len
+= htons(IETF_RTR_MSG_SIZE
);
604 /* initialize RTR msg */
605 if (cm_node
->mpav2_ird_ord
== IETF_NO_IRD_ORD
) {
606 ctrl_ird
= IETF_NO_IRD_ORD
;
607 ctrl_ord
= IETF_NO_IRD_ORD
;
609 ctrl_ird
= cm_node
->ird_size
& IETF_NO_IRD_ORD
;
610 ctrl_ord
= cm_node
->ord_size
& IETF_NO_IRD_ORD
;
612 ctrl_ird
|= IETF_PEER_TO_PEER
;
613 ctrl_ird
|= IETF_FLPDU_ZERO_LEN
;
616 case MPA_KEY_REQUEST
:
617 ctrl_ord
|= IETF_RDMA0_WRITE
;
618 ctrl_ord
|= IETF_RDMA0_READ
;
621 switch (cm_node
->send_rdma0_op
) {
622 case SEND_RDMA_WRITE_ZERO
:
623 ctrl_ord
|= IETF_RDMA0_WRITE
;
625 case SEND_RDMA_READ_ZERO
:
626 ctrl_ord
|= IETF_RDMA0_READ
;
630 rtr_msg
->ctrl_ird
= htons(ctrl_ird
);
631 rtr_msg
->ctrl_ord
= htons(ctrl_ord
);
635 * build_mpa_v1 - build a MPA V1 frame
637 static void build_mpa_v1(struct nes_cm_node
*cm_node
, void *start_addr
, u8 mpa_key
)
639 struct ietf_mpa_v1
*mpa_frame
= (struct ietf_mpa_v1
*)start_addr
;
642 case MPA_KEY_REQUEST
:
643 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
);
646 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
);
649 mpa_frame
->flags
= IETF_MPA_FLAGS_CRC
;
650 mpa_frame
->rev
= cm_node
->mpa_frame_rev
;
651 mpa_frame
->priv_data_len
= htons(cm_node
->mpa_frame_size
);
654 static void build_rdma0_msg(struct nes_cm_node
*cm_node
, struct nes_qp
**nesqp_addr
)
657 struct nes_qp
*nesqp
= *nesqp_addr
;
658 struct nes_hw_qp_wqe
*wqe
= &nesqp
->hwqp
.sq_vbase
[0];
660 u64temp
= (unsigned long)nesqp
->nesuqp_addr
;
661 u64temp
|= NES_SW_CONTEXT_ALIGN
>> 1;
662 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
, u64temp
);
664 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
] = 0;
665 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX
] = 0;
667 switch (cm_node
->send_rdma0_op
) {
668 case SEND_RDMA_WRITE_ZERO
:
669 nes_debug(NES_DBG_CM
, "Sending first write.\n");
670 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
671 cpu_to_le32(NES_IWARP_SQ_OP_RDMAW
);
672 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] = 0;
673 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] = 0;
674 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 0;
677 case SEND_RDMA_READ_ZERO
:
679 if (cm_node
->send_rdma0_op
!= SEND_RDMA_READ_ZERO
)
680 WARN(1, "Unsupported RDMA0 len operation=%u\n",
681 cm_node
->send_rdma0_op
);
682 nes_debug(NES_DBG_CM
, "Sending first rdma operation.\n");
683 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
684 cpu_to_le32(NES_IWARP_SQ_OP_RDMAR
);
685 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX
] = 1;
686 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_TO_HIGH_IDX
] = 0;
687 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX
] = 0;
688 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_STAG_IDX
] = 1;
689 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 1;
693 if (nesqp
->sq_kmapped
) {
694 nesqp
->sq_kmapped
= 0;
698 /*use the reserved spot on the WQ for the extra first WQE*/
699 nesqp
->nesqp_context
->ird_ord_sizes
&= cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
700 NES_QPCONTEXT_ORDIRD_WRPDU
|
701 NES_QPCONTEXT_ORDIRD_ALSMM
));
702 nesqp
->skip_lsmm
= 1;
703 nesqp
->hwqp
.sq_tail
= 0;
708 * note - cm_node needs to be protected before calling this. Encase in:
709 * rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
711 int schedule_nes_timer(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
712 enum nes_timer_type type
, int send_retrans
,
713 int close_when_complete
)
716 struct nes_cm_core
*cm_core
= cm_node
->cm_core
;
717 struct nes_timer_entry
*new_send
;
720 new_send
= kzalloc(sizeof(*new_send
), GFP_ATOMIC
);
724 /* new_send->timetosend = currenttime */
725 new_send
->retrycount
= NES_DEFAULT_RETRYS
;
726 new_send
->retranscount
= NES_DEFAULT_RETRANS
;
728 new_send
->timetosend
= jiffies
;
729 new_send
->type
= type
;
730 new_send
->netdev
= cm_node
->netdev
;
731 new_send
->send_retrans
= send_retrans
;
732 new_send
->close_when_complete
= close_when_complete
;
734 if (type
== NES_TIMER_TYPE_CLOSE
) {
735 new_send
->timetosend
+= (HZ
/ 10);
736 if (cm_node
->recv_entry
) {
741 cm_node
->recv_entry
= new_send
;
744 if (type
== NES_TIMER_TYPE_SEND
) {
745 new_send
->seq_num
= ntohl(tcp_hdr(skb
)->seq
);
746 atomic_inc(&new_send
->skb
->users
);
747 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
748 cm_node
->send_entry
= new_send
;
749 add_ref_cm_node(cm_node
);
750 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
751 new_send
->timetosend
= jiffies
+ NES_RETRY_TIMEOUT
;
753 ret
= nes_nic_cm_xmit(new_send
->skb
, cm_node
->netdev
);
754 if (ret
!= NETDEV_TX_OK
) {
755 nes_debug(NES_DBG_CM
, "Error sending packet %p "
756 "(jiffies = %lu)\n", new_send
, jiffies
);
757 new_send
->timetosend
= jiffies
;
762 cleanup_retrans_entry(cm_node
);
763 if (close_when_complete
)
764 rem_ref_cm_node(cm_core
, cm_node
);
770 if (!timer_pending(&cm_core
->tcp_timer
))
771 mod_timer(&cm_core
->tcp_timer
, new_send
->timetosend
);
776 static void nes_retrans_expired(struct nes_cm_node
*cm_node
)
778 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
779 enum nes_cm_node_state state
= cm_node
->state
;
780 cm_node
->state
= NES_CM_STATE_CLOSED
;
783 case NES_CM_STATE_SYN_RCVD
:
784 case NES_CM_STATE_CLOSING
:
785 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
787 case NES_CM_STATE_LAST_ACK
:
788 case NES_CM_STATE_FIN_WAIT1
:
790 cm_id
->rem_ref(cm_id
);
791 send_reset(cm_node
, NULL
);
794 add_ref_cm_node(cm_node
);
795 send_reset(cm_node
, NULL
);
796 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
800 static void handle_recv_entry(struct nes_cm_node
*cm_node
, u32 rem_node
)
802 struct nes_timer_entry
*recv_entry
= cm_node
->recv_entry
;
803 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
804 struct nes_qp
*nesqp
;
805 unsigned long qplockflags
;
809 nesqp
= (struct nes_qp
*)recv_entry
->skb
;
811 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
813 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, "
814 "refcount = %d: HIT A "
815 "NES_TIMER_TYPE_CLOSE with something "
816 "to do!!!\n", nesqp
->hwqp
.qp_id
, cm_id
,
817 atomic_read(&nesqp
->refcount
));
818 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
819 nesqp
->last_aeq
= NES_AEQE_AEID_RESET_SENT
;
820 nesqp
->ibqp_state
= IB_QPS_ERR
;
821 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
822 nes_cm_disconn(nesqp
);
824 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
825 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, "
826 "refcount = %d: HIT A "
827 "NES_TIMER_TYPE_CLOSE with nothing "
828 "to do!!!\n", nesqp
->hwqp
.qp_id
, cm_id
,
829 atomic_read(&nesqp
->refcount
));
831 } else if (rem_node
) {
832 /* TIME_WAIT state */
833 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
836 cm_id
->rem_ref(cm_id
);
838 cm_node
->recv_entry
= NULL
;
844 static void nes_cm_timer_tick(unsigned long pass
)
847 unsigned long nexttimeout
= jiffies
+ NES_LONG_TIME
;
848 struct nes_cm_node
*cm_node
;
849 struct nes_timer_entry
*send_entry
, *recv_entry
;
850 struct list_head
*list_core_temp
;
851 struct list_head
*list_node
;
852 struct nes_cm_core
*cm_core
= g_cm_core
;
854 unsigned long timetosend
;
855 int ret
= NETDEV_TX_OK
;
857 struct list_head timer_list
;
859 INIT_LIST_HEAD(&timer_list
);
860 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
862 list_for_each_safe(list_node
, list_core_temp
,
863 &cm_core
->connected_nodes
) {
864 cm_node
= container_of(list_node
, struct nes_cm_node
, list
);
865 if ((cm_node
->recv_entry
) || (cm_node
->send_entry
)) {
866 add_ref_cm_node(cm_node
);
867 list_add(&cm_node
->timer_entry
, &timer_list
);
870 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
872 list_for_each_safe(list_node
, list_core_temp
, &timer_list
) {
873 cm_node
= container_of(list_node
, struct nes_cm_node
,
875 recv_entry
= cm_node
->recv_entry
;
878 if (time_after(recv_entry
->timetosend
, jiffies
)) {
879 if (nexttimeout
> recv_entry
->timetosend
||
881 nexttimeout
= recv_entry
->timetosend
;
885 handle_recv_entry(cm_node
, 1);
889 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
891 send_entry
= cm_node
->send_entry
;
894 if (time_after(send_entry
->timetosend
, jiffies
)) {
895 if (cm_node
->state
!= NES_CM_STATE_TSA
) {
897 send_entry
->timetosend
) ||
900 send_entry
->timetosend
;
904 free_retrans_entry(cm_node
);
909 if ((cm_node
->state
== NES_CM_STATE_TSA
) ||
910 (cm_node
->state
== NES_CM_STATE_CLOSED
)) {
911 free_retrans_entry(cm_node
);
915 if (!send_entry
->retranscount
||
916 !send_entry
->retrycount
) {
917 cm_packets_dropped
++;
918 free_retrans_entry(cm_node
);
920 spin_unlock_irqrestore(
921 &cm_node
->retrans_list_lock
, flags
);
922 nes_retrans_expired(cm_node
);
923 cm_node
->state
= NES_CM_STATE_CLOSED
;
924 spin_lock_irqsave(&cm_node
->retrans_list_lock
,
928 atomic_inc(&send_entry
->skb
->users
);
929 cm_packets_retrans
++;
930 nes_debug(NES_DBG_CM
, "Retransmitting send_entry %p "
931 "for node %p, jiffies = %lu, time to send = "
932 "%lu, retranscount = %u, send_entry->seq_num = "
933 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
934 "0x%08X\n", send_entry
, cm_node
, jiffies
,
935 send_entry
->timetosend
,
936 send_entry
->retranscount
,
938 cm_node
->tcp_cntxt
.rem_ack_num
);
940 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
,
942 ret
= nes_nic_cm_xmit(send_entry
->skb
, cm_node
->netdev
);
943 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
944 if (ret
!= NETDEV_TX_OK
) {
945 nes_debug(NES_DBG_CM
, "rexmit failed for "
946 "node=%p\n", cm_node
);
947 cm_packets_bounced
++;
948 send_entry
->retrycount
--;
949 nexttimeout
= jiffies
+ NES_SHORT_TIME
;
955 nes_debug(NES_DBG_CM
, "Packet Sent: retrans count = "
956 "%u, retry count = %u.\n",
957 send_entry
->retranscount
,
958 send_entry
->retrycount
);
959 if (send_entry
->send_retrans
) {
960 send_entry
->retranscount
--;
961 timetosend
= (NES_RETRY_TIMEOUT
<<
962 (NES_DEFAULT_RETRANS
- send_entry
->retranscount
));
964 send_entry
->timetosend
= jiffies
+
965 min(timetosend
, NES_MAX_TIMEOUT
);
966 if (nexttimeout
> send_entry
->timetosend
||
968 nexttimeout
= send_entry
->timetosend
;
972 int close_when_complete
;
973 close_when_complete
=
974 send_entry
->close_when_complete
;
975 nes_debug(NES_DBG_CM
, "cm_node=%p state=%d\n",
976 cm_node
, cm_node
->state
);
977 free_retrans_entry(cm_node
);
978 if (close_when_complete
)
979 rem_ref_cm_node(cm_node
->cm_core
,
984 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
985 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
989 if (!timer_pending(&cm_core
->tcp_timer
))
990 mod_timer(&cm_core
->tcp_timer
, nexttimeout
);
998 static int send_syn(struct nes_cm_node
*cm_node
, u32 sendack
,
1002 int flags
= SET_SYN
;
1003 char optionsbuffer
[sizeof(struct option_mss
) +
1004 sizeof(struct option_windowscale
) + sizeof(struct option_base
) +
1005 TCP_OPTIONS_PADDING
];
1007 int optionssize
= 0;
1008 /* Sending MSS option */
1009 union all_known_options
*options
;
1014 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1015 options
->as_mss
.optionnum
= OPTION_NUMBER_MSS
;
1016 options
->as_mss
.length
= sizeof(struct option_mss
);
1017 options
->as_mss
.mss
= htons(cm_node
->tcp_cntxt
.mss
);
1018 optionssize
+= sizeof(struct option_mss
);
1020 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1021 options
->as_windowscale
.optionnum
= OPTION_NUMBER_WINDOW_SCALE
;
1022 options
->as_windowscale
.length
= sizeof(struct option_windowscale
);
1023 options
->as_windowscale
.shiftcount
= cm_node
->tcp_cntxt
.rcv_wscale
;
1024 optionssize
+= sizeof(struct option_windowscale
);
1026 if (sendack
&& !(NES_DRV_OPT_SUPRESS_OPTION_BC
& nes_drv_opt
)) {
1027 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1028 options
->as_base
.optionnum
= OPTION_NUMBER_WRITE0
;
1029 options
->as_base
.length
= sizeof(struct option_base
);
1030 optionssize
+= sizeof(struct option_base
);
1031 /* we need the size to be a multiple of 4 */
1032 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1033 options
->as_end
= 1;
1035 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1036 options
->as_end
= 1;
1040 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1041 options
->as_end
= OPTION_NUMBER_END
;
1045 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1047 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1054 form_cm_frame(skb
, cm_node
, optionsbuffer
, optionssize
, NULL
, 0, flags
);
1055 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
1064 static int send_reset(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1067 int flags
= SET_RST
| SET_ACK
;
1070 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1072 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1076 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, flags
);
1077 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 1);
1086 static int send_ack(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1091 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1094 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1098 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
);
1099 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 0);
1108 static int send_fin(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1112 /* if we didn't get a frame get one */
1114 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1117 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1121 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
| SET_FIN
);
1122 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
1129 * find_node - find a cm node that matches the reference cm node
1131 static struct nes_cm_node
*find_node(struct nes_cm_core
*cm_core
,
1132 u16 rem_port
, nes_addr_t rem_addr
, u16 loc_port
, nes_addr_t loc_addr
)
1134 unsigned long flags
;
1135 struct list_head
*hte
;
1136 struct nes_cm_node
*cm_node
;
1138 /* get a handle on the hte */
1139 hte
= &cm_core
->connected_nodes
;
1141 /* walk list and find cm_node associated with this session ID */
1142 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1143 list_for_each_entry(cm_node
, hte
, list
) {
1144 /* compare quad, return node handle if a match */
1145 nes_debug(NES_DBG_CM
, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
1146 cm_node
->loc_addr
, cm_node
->loc_port
,
1148 cm_node
->rem_addr
, cm_node
->rem_port
,
1149 rem_addr
, rem_port
);
1150 if ((cm_node
->loc_addr
== loc_addr
) &&
1151 (cm_node
->loc_port
== loc_port
) &&
1152 (cm_node
->rem_addr
== rem_addr
) &&
1153 (cm_node
->rem_port
== rem_port
)) {
1154 add_ref_cm_node(cm_node
);
1155 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1159 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1167 * find_listener - find a cm node listening on this addr-port pair
1169 static struct nes_cm_listener
*find_listener(struct nes_cm_core
*cm_core
,
1170 nes_addr_t dst_addr
, u16 dst_port
,
1171 enum nes_cm_listener_state listener_state
)
1173 unsigned long flags
;
1174 struct nes_cm_listener
*listen_node
;
1175 nes_addr_t listen_addr
;
1178 /* walk list and find cm_node associated with this session ID */
1179 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1180 list_for_each_entry(listen_node
, &cm_core
->listen_list
.list
, list
) {
1181 listen_addr
= listen_node
->loc_addr
;
1182 listen_port
= listen_node
->loc_port
;
1184 /* compare node pair, return node handle if a match */
1185 if (((listen_addr
== dst_addr
) ||
1186 listen_addr
== 0x00000000) &&
1187 (listen_port
== dst_port
) &&
1188 (listener_state
& listen_node
->listener_state
)) {
1189 atomic_inc(&listen_node
->ref_count
);
1190 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1194 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1201 * add_hte_node - add a cm node to the hash table
1203 static int add_hte_node(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
1205 unsigned long flags
;
1206 struct list_head
*hte
;
1208 if (!cm_node
|| !cm_core
)
1211 nes_debug(NES_DBG_CM
, "Adding Node %p to Active Connection HT\n",
1214 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1216 /* get a handle on the hash table element (list head for this slot) */
1217 hte
= &cm_core
->connected_nodes
;
1218 list_add_tail(&cm_node
->list
, hte
);
1219 atomic_inc(&cm_core
->ht_node_cnt
);
1221 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1228 * mini_cm_dec_refcnt_listen
1230 static int mini_cm_dec_refcnt_listen(struct nes_cm_core
*cm_core
,
1231 struct nes_cm_listener
*listener
, int free_hanging_nodes
)
1235 unsigned long flags
;
1236 struct list_head
*list_pos
= NULL
;
1237 struct list_head
*list_temp
= NULL
;
1238 struct nes_cm_node
*cm_node
= NULL
;
1239 struct list_head reset_list
;
1241 nes_debug(NES_DBG_CM
, "attempting listener= %p free_nodes= %d, "
1242 "refcnt=%d\n", listener
, free_hanging_nodes
,
1243 atomic_read(&listener
->ref_count
));
1244 /* free non-accelerated child nodes for this listener */
1245 INIT_LIST_HEAD(&reset_list
);
1246 if (free_hanging_nodes
) {
1247 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1248 list_for_each_safe(list_pos
, list_temp
,
1249 &g_cm_core
->connected_nodes
) {
1250 cm_node
= container_of(list_pos
, struct nes_cm_node
,
1252 if ((cm_node
->listener
== listener
) &&
1253 (!cm_node
->accelerated
)) {
1254 add_ref_cm_node(cm_node
);
1255 list_add(&cm_node
->reset_entry
, &reset_list
);
1258 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1261 list_for_each_safe(list_pos
, list_temp
, &reset_list
) {
1262 cm_node
= container_of(list_pos
, struct nes_cm_node
,
1265 struct nes_cm_node
*loopback
= cm_node
->loopbackpartner
;
1266 enum nes_cm_node_state old_state
;
1267 if (NES_CM_STATE_FIN_WAIT1
<= cm_node
->state
) {
1268 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1271 cleanup_retrans_entry(cm_node
);
1272 err
= send_reset(cm_node
, NULL
);
1275 NES_CM_STATE_CLOSED
;
1278 old_state
= cm_node
->state
;
1279 cm_node
->state
= NES_CM_STATE_LISTENER_DESTROYED
;
1280 if (old_state
!= NES_CM_STATE_MPAREQ_RCVD
)
1286 struct nes_cm_event event
;
1288 event
.cm_node
= loopback
;
1289 event
.cm_info
.rem_addr
=
1291 event
.cm_info
.loc_addr
=
1293 event
.cm_info
.rem_port
=
1295 event
.cm_info
.loc_port
=
1297 event
.cm_info
.cm_id
= loopback
->cm_id
;
1298 add_ref_cm_node(loopback
);
1299 loopback
->state
= NES_CM_STATE_CLOSED
;
1300 cm_event_connect_error(&event
);
1301 cm_node
->state
= NES_CM_STATE_LISTENER_DESTROYED
;
1303 rem_ref_cm_node(cm_node
->cm_core
,
1311 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1312 if (!atomic_dec_return(&listener
->ref_count
)) {
1313 list_del(&listener
->list
);
1315 /* decrement our listen node count */
1316 atomic_dec(&cm_core
->listen_node_cnt
);
1318 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1320 if (listener
->nesvnic
) {
1321 nes_manage_apbvt(listener
->nesvnic
,
1323 PCI_FUNC(listener
->nesvnic
->nesdev
->pcidev
->devfn
),
1324 NES_MANAGE_APBVT_DEL
);
1326 nes_debug(NES_DBG_NLMSG
,
1327 "Delete APBVT loc_port = %04X\n",
1328 listener
->loc_port
);
1331 nes_debug(NES_DBG_CM
, "destroying listener (%p)\n", listener
);
1336 atomic_inc(&cm_listens_destroyed
);
1338 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1341 if (atomic_read(&listener
->pend_accepts_cnt
) > 0)
1342 nes_debug(NES_DBG_CM
, "destroying listener (%p)"
1343 " with non-zero pending accepts=%u\n",
1344 listener
, atomic_read(&listener
->pend_accepts_cnt
));
1352 * mini_cm_del_listen
1354 static int mini_cm_del_listen(struct nes_cm_core
*cm_core
,
1355 struct nes_cm_listener
*listener
)
1357 listener
->listener_state
= NES_CM_LISTENER_PASSIVE_STATE
;
1358 listener
->cm_id
= NULL
; /* going to be destroyed pretty soon */
1359 return mini_cm_dec_refcnt_listen(cm_core
, listener
, 1);
1364 * mini_cm_accelerated
1366 static inline int mini_cm_accelerated(struct nes_cm_core
*cm_core
,
1367 struct nes_cm_node
*cm_node
)
1369 cm_node
->accelerated
= 1;
1371 if (cm_node
->accept_pend
) {
1372 BUG_ON(!cm_node
->listener
);
1373 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1374 cm_node
->accept_pend
= 0;
1375 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1378 if (!timer_pending(&cm_core
->tcp_timer
))
1379 mod_timer(&cm_core
->tcp_timer
, (jiffies
+ NES_SHORT_TIME
));
1386 * nes_addr_resolve_neigh
1388 static int nes_addr_resolve_neigh(struct nes_vnic
*nesvnic
, u32 dst_ip
, int arpindex
)
1391 struct neighbour
*neigh
;
1393 struct net_device
*netdev
;
1394 struct nes_adapter
*nesadapter
= nesvnic
->nesdev
->nesadapter
;
1395 __be32 dst_ipaddr
= htonl(dst_ip
);
1397 rt
= ip_route_output(&init_net
, dst_ipaddr
, nesvnic
->local_ipaddr
, 0, 0);
1399 printk(KERN_ERR
"%s: ip_route_output_key failed for 0x%08X\n",
1404 if (netif_is_bond_slave(nesvnic
->netdev
))
1405 netdev
= netdev_master_upper_dev_get(nesvnic
->netdev
);
1407 netdev
= nesvnic
->netdev
;
1409 neigh
= dst_neigh_lookup(&rt
->dst
, &dst_ipaddr
);
1413 if (neigh
->nud_state
& NUD_VALID
) {
1414 nes_debug(NES_DBG_CM
, "Neighbor MAC address for 0x%08X"
1415 " is %pM, Gateway is 0x%08X \n", dst_ip
,
1416 neigh
->ha
, ntohl(rt
->rt_gateway
));
1418 if (arpindex
>= 0) {
1419 if (ether_addr_equal(nesadapter
->arp_table
[arpindex
].mac_addr
, neigh
->ha
)) {
1420 /* Mac address same as in nes_arp_table */
1424 nes_manage_arp_cache(nesvnic
->netdev
,
1425 nesadapter
->arp_table
[arpindex
].mac_addr
,
1426 dst_ip
, NES_ARP_DELETE
);
1429 nes_manage_arp_cache(nesvnic
->netdev
, neigh
->ha
,
1430 dst_ip
, NES_ARP_ADD
);
1431 rc
= nes_arp_table(nesvnic
->nesdev
, dst_ip
, NULL
,
1434 neigh_event_send(neigh
, NULL
);
1441 neigh_release(neigh
);
1448 * make_cm_node - create a new instance of a cm node
1450 static struct nes_cm_node
*make_cm_node(struct nes_cm_core
*cm_core
,
1451 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
,
1452 struct nes_cm_listener
*listener
)
1454 struct nes_cm_node
*cm_node
;
1456 int oldarpindex
= 0;
1458 struct nes_device
*nesdev
;
1459 struct nes_adapter
*nesadapter
;
1461 /* create an hte and cm_node for this instance */
1462 cm_node
= kzalloc(sizeof(*cm_node
), GFP_ATOMIC
);
1466 /* set our node specific transport info */
1468 cm_node
->loc_addr
= listener
->loc_addr
;
1469 cm_node
->loc_port
= listener
->loc_port
;
1471 cm_node
->loc_addr
= cm_info
->loc_addr
;
1472 cm_node
->loc_port
= cm_info
->loc_port
;
1474 cm_node
->rem_addr
= cm_info
->rem_addr
;
1475 cm_node
->rem_port
= cm_info
->rem_port
;
1477 cm_node
->mpa_frame_rev
= mpa_version
;
1478 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
1479 cm_node
->mpav2_ird_ord
= 0;
1480 cm_node
->ird_size
= 0;
1481 cm_node
->ord_size
= 0;
1483 nes_debug(NES_DBG_CM
, "Make node addresses : loc = %pI4:%x, rem = %pI4:%x\n",
1484 &cm_node
->loc_addr
, cm_node
->loc_port
,
1485 &cm_node
->rem_addr
, cm_node
->rem_port
);
1486 cm_node
->listener
= listener
;
1488 cm_node
->tos
= listener
->tos
;
1489 cm_node
->netdev
= nesvnic
->netdev
;
1490 cm_node
->cm_id
= cm_info
->cm_id
;
1491 memcpy(cm_node
->loc_mac
, nesvnic
->netdev
->dev_addr
, ETH_ALEN
);
1493 nes_debug(NES_DBG_CM
, "listener=%p, cm_id=%p\n", cm_node
->listener
,
1496 spin_lock_init(&cm_node
->retrans_list_lock
);
1498 cm_node
->loopbackpartner
= NULL
;
1499 atomic_set(&cm_node
->ref_count
, 1);
1500 /* associate our parent CM core */
1501 cm_node
->cm_core
= cm_core
;
1502 cm_node
->tcp_cntxt
.loc_id
= NES_CM_DEF_LOCAL_ID
;
1503 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
1504 cm_node
->tcp_cntxt
.rcv_wnd
= NES_CM_DEFAULT_RCV_WND_SCALED
>>
1505 NES_CM_DEFAULT_RCV_WND_SCALE
;
1506 ts
= current_kernel_time();
1507 cm_node
->tcp_cntxt
.loc_seq_num
= htonl(ts
.tv_nsec
);
1508 cm_node
->tcp_cntxt
.mss
= nesvnic
->max_frame_size
- sizeof(struct iphdr
) -
1509 sizeof(struct tcphdr
) - ETH_HLEN
- VLAN_HLEN
;
1510 cm_node
->tcp_cntxt
.rcv_nxt
= 0;
1511 /* get a unique session ID , add thread_id to an upcounter to handle race */
1512 atomic_inc(&cm_core
->node_cnt
);
1513 cm_node
->conn_type
= cm_info
->conn_type
;
1514 cm_node
->apbvt_set
= 0;
1515 cm_node
->accept_pend
= 0;
1517 cm_node
->nesvnic
= nesvnic
;
1518 /* get some device handles, for arp lookup */
1519 nesdev
= nesvnic
->nesdev
;
1520 nesadapter
= nesdev
->nesadapter
;
1522 cm_node
->loopbackpartner
= NULL
;
1524 /* get the mac addr for the remote node */
1525 oldarpindex
= nes_arp_table(nesdev
, cm_node
->rem_addr
,
1526 NULL
, NES_ARP_RESOLVE
);
1527 arpindex
= nes_addr_resolve_neigh(nesvnic
, cm_node
->rem_addr
,
1534 /* copy the mac addr to node context */
1535 memcpy(cm_node
->rem_mac
, nesadapter
->arp_table
[arpindex
].mac_addr
, ETH_ALEN
);
1536 nes_debug(NES_DBG_CM
, "Remote mac addr from arp table: %pM\n",
1539 add_hte_node(cm_core
, cm_node
);
1540 atomic_inc(&cm_nodes_created
);
1547 * add_ref_cm_node - destroy an instance of a cm node
1549 static int add_ref_cm_node(struct nes_cm_node
*cm_node
)
1551 atomic_inc(&cm_node
->ref_count
);
1557 * rem_ref_cm_node - destroy an instance of a cm node
1559 static int rem_ref_cm_node(struct nes_cm_core
*cm_core
,
1560 struct nes_cm_node
*cm_node
)
1562 unsigned long flags
;
1563 struct nes_qp
*nesqp
;
1568 spin_lock_irqsave(&cm_node
->cm_core
->ht_lock
, flags
);
1569 if (atomic_dec_return(&cm_node
->ref_count
)) {
1570 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1573 list_del(&cm_node
->list
);
1574 atomic_dec(&cm_core
->ht_node_cnt
);
1575 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1577 /* if the node is destroyed before connection was accelerated */
1578 if (!cm_node
->accelerated
&& cm_node
->accept_pend
) {
1579 BUG_ON(!cm_node
->listener
);
1580 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1581 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1583 WARN_ON(cm_node
->send_entry
);
1584 if (cm_node
->recv_entry
)
1585 handle_recv_entry(cm_node
, 0);
1586 if (cm_node
->listener
) {
1587 mini_cm_dec_refcnt_listen(cm_core
, cm_node
->listener
, 0);
1589 if (cm_node
->apbvt_set
&& cm_node
->nesvnic
) {
1590 nes_manage_apbvt(cm_node
->nesvnic
, cm_node
->loc_port
,
1591 PCI_FUNC(cm_node
->nesvnic
->nesdev
->pcidev
->devfn
),
1592 NES_MANAGE_APBVT_DEL
);
1594 nes_debug(NES_DBG_NLMSG
, "Delete APBVT loc_port = %04X\n",
1598 atomic_dec(&cm_core
->node_cnt
);
1599 atomic_inc(&cm_nodes_destroyed
);
1600 nesqp
= cm_node
->nesqp
;
1602 nesqp
->cm_node
= NULL
;
1603 nes_rem_ref(&nesqp
->ibqp
);
1604 cm_node
->nesqp
= NULL
;
1614 static int process_options(struct nes_cm_node
*cm_node
, u8
*optionsloc
,
1615 u32 optionsize
, u32 syn_packet
)
1619 union all_known_options
*all_options
;
1620 char got_mss_option
= 0;
1622 while (offset
< optionsize
) {
1623 all_options
= (union all_known_options
*)(optionsloc
+ offset
);
1624 switch (all_options
->as_base
.optionnum
) {
1625 case OPTION_NUMBER_END
:
1626 offset
= optionsize
;
1628 case OPTION_NUMBER_NONE
:
1631 case OPTION_NUMBER_MSS
:
1632 nes_debug(NES_DBG_CM
, "%s: MSS Length: %d Offset: %d "
1633 "Size: %d\n", __func__
,
1634 all_options
->as_mss
.length
, offset
, optionsize
);
1636 if (all_options
->as_mss
.length
!= 4) {
1639 tmp
= ntohs(all_options
->as_mss
.mss
);
1640 if (tmp
> 0 && tmp
<
1641 cm_node
->tcp_cntxt
.mss
)
1642 cm_node
->tcp_cntxt
.mss
= tmp
;
1645 case OPTION_NUMBER_WINDOW_SCALE
:
1646 cm_node
->tcp_cntxt
.snd_wscale
=
1647 all_options
->as_windowscale
.shiftcount
;
1650 nes_debug(NES_DBG_CM
, "TCP Option not understood: %x\n",
1651 all_options
->as_base
.optionnum
);
1654 offset
+= all_options
->as_base
.length
;
1656 if ((!got_mss_option
) && (syn_packet
))
1657 cm_node
->tcp_cntxt
.mss
= NES_CM_DEFAULT_MSS
;
1661 static void drop_packet(struct sk_buff
*skb
)
1663 atomic_inc(&cm_accel_dropped_pkts
);
1664 dev_kfree_skb_any(skb
);
1667 static void handle_fin_pkt(struct nes_cm_node
*cm_node
)
1669 nes_debug(NES_DBG_CM
, "Received FIN, cm_node = %p, state = %u. "
1670 "refcnt=%d\n", cm_node
, cm_node
->state
,
1671 atomic_read(&cm_node
->ref_count
));
1672 switch (cm_node
->state
) {
1673 case NES_CM_STATE_SYN_RCVD
:
1674 case NES_CM_STATE_SYN_SENT
:
1675 case NES_CM_STATE_ESTABLISHED
:
1676 case NES_CM_STATE_MPAREJ_RCVD
:
1677 cm_node
->tcp_cntxt
.rcv_nxt
++;
1678 cleanup_retrans_entry(cm_node
);
1679 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
1680 send_fin(cm_node
, NULL
);
1682 case NES_CM_STATE_MPAREQ_SENT
:
1683 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
1684 cm_node
->tcp_cntxt
.rcv_nxt
++;
1685 cleanup_retrans_entry(cm_node
);
1686 cm_node
->state
= NES_CM_STATE_CLOSED
;
1687 add_ref_cm_node(cm_node
);
1688 send_reset(cm_node
, NULL
);
1690 case NES_CM_STATE_FIN_WAIT1
:
1691 cm_node
->tcp_cntxt
.rcv_nxt
++;
1692 cleanup_retrans_entry(cm_node
);
1693 cm_node
->state
= NES_CM_STATE_CLOSING
;
1694 send_ack(cm_node
, NULL
);
1695 /* Wait for ACK as this is simultaneous close..
1696 * After we receive ACK, do not send anything..
1697 * Just rm the node.. Done.. */
1699 case NES_CM_STATE_FIN_WAIT2
:
1700 cm_node
->tcp_cntxt
.rcv_nxt
++;
1701 cleanup_retrans_entry(cm_node
);
1702 cm_node
->state
= NES_CM_STATE_TIME_WAIT
;
1703 send_ack(cm_node
, NULL
);
1704 schedule_nes_timer(cm_node
, NULL
, NES_TIMER_TYPE_CLOSE
, 1, 0);
1706 case NES_CM_STATE_TIME_WAIT
:
1707 cm_node
->tcp_cntxt
.rcv_nxt
++;
1708 cleanup_retrans_entry(cm_node
);
1709 cm_node
->state
= NES_CM_STATE_CLOSED
;
1710 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1712 case NES_CM_STATE_TSA
:
1714 nes_debug(NES_DBG_CM
, "Error Rcvd FIN for node-%p state = %d\n",
1715 cm_node
, cm_node
->state
);
1721 static void handle_rst_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1722 struct tcphdr
*tcph
)
1725 int reset
= 0; /* whether to send reset in case of err.. */
1726 atomic_inc(&cm_resets_recvd
);
1727 nes_debug(NES_DBG_CM
, "Received Reset, cm_node = %p, state = %u."
1728 " refcnt=%d\n", cm_node
, cm_node
->state
,
1729 atomic_read(&cm_node
->ref_count
));
1730 cleanup_retrans_entry(cm_node
);
1731 switch (cm_node
->state
) {
1732 case NES_CM_STATE_SYN_SENT
:
1733 case NES_CM_STATE_MPAREQ_SENT
:
1734 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1735 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1736 cm_node
->listener
, cm_node
->state
);
1737 switch (cm_node
->mpa_frame_rev
) {
1739 cm_node
->mpa_frame_rev
= IETF_MPA_V1
;
1740 /* send a syn and goto syn sent state */
1741 cm_node
->state
= NES_CM_STATE_SYN_SENT
;
1742 if (send_syn(cm_node
, 0, NULL
)) {
1743 active_open_err(cm_node
, skb
, reset
);
1748 active_open_err(cm_node
, skb
, reset
);
1752 case NES_CM_STATE_MPAREQ_RCVD
:
1753 atomic_inc(&cm_node
->passive_state
);
1754 dev_kfree_skb_any(skb
);
1756 case NES_CM_STATE_ESTABLISHED
:
1757 case NES_CM_STATE_SYN_RCVD
:
1758 case NES_CM_STATE_LISTENING
:
1759 nes_debug(NES_DBG_CM
, "Bad state %s[%u]\n", __func__
, __LINE__
);
1760 passive_open_err(cm_node
, skb
, reset
);
1762 case NES_CM_STATE_TSA
:
1763 active_open_err(cm_node
, skb
, reset
);
1765 case NES_CM_STATE_CLOSED
:
1768 case NES_CM_STATE_FIN_WAIT2
:
1769 case NES_CM_STATE_FIN_WAIT1
:
1770 case NES_CM_STATE_LAST_ACK
:
1771 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
1772 case NES_CM_STATE_TIME_WAIT
:
1773 cm_node
->state
= NES_CM_STATE_CLOSED
;
1774 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1784 static void handle_rcv_mpa(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1787 int datasize
= skb
->len
;
1788 u8
*dataloc
= skb
->data
;
1790 enum nes_cm_event_type type
= NES_CM_EVENT_UNKNOWN
;
1793 ret
= parse_mpa(cm_node
, dataloc
, &res_type
, datasize
);
1795 nes_debug(NES_DBG_CM
, "didn't like MPA Request\n");
1796 if (cm_node
->state
== NES_CM_STATE_MPAREQ_SENT
) {
1797 nes_debug(NES_DBG_CM
, "%s[%u] create abort for "
1798 "cm_node=%p listener=%p state=%d\n", __func__
,
1799 __LINE__
, cm_node
, cm_node
->listener
,
1801 active_open_err(cm_node
, skb
, 1);
1803 passive_open_err(cm_node
, skb
, 1);
1808 switch (cm_node
->state
) {
1809 case NES_CM_STATE_ESTABLISHED
:
1810 if (res_type
== NES_MPA_REQUEST_REJECT
)
1811 /*BIG problem as we are receiving the MPA.. So should
1812 * not be REJECT.. This is Passive Open.. We can
1813 * only receive it Reject for Active Open...*/
1815 cm_node
->state
= NES_CM_STATE_MPAREQ_RCVD
;
1816 type
= NES_CM_EVENT_MPA_REQ
;
1817 atomic_set(&cm_node
->passive_state
,
1818 NES_PASSIVE_STATE_INDICATED
);
1820 case NES_CM_STATE_MPAREQ_SENT
:
1821 cleanup_retrans_entry(cm_node
);
1822 if (res_type
== NES_MPA_REQUEST_REJECT
) {
1823 type
= NES_CM_EVENT_MPA_REJECT
;
1824 cm_node
->state
= NES_CM_STATE_MPAREJ_RCVD
;
1826 type
= NES_CM_EVENT_CONNECTED
;
1827 cm_node
->state
= NES_CM_STATE_TSA
;
1835 dev_kfree_skb_any(skb
);
1836 create_event(cm_node
, type
);
1839 static void indicate_pkt_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1841 switch (cm_node
->state
) {
1842 case NES_CM_STATE_SYN_SENT
:
1843 case NES_CM_STATE_MPAREQ_SENT
:
1844 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1845 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1846 cm_node
->listener
, cm_node
->state
);
1847 active_open_err(cm_node
, skb
, 1);
1849 case NES_CM_STATE_ESTABLISHED
:
1850 case NES_CM_STATE_SYN_RCVD
:
1851 passive_open_err(cm_node
, skb
, 1);
1853 case NES_CM_STATE_TSA
:
1859 static int check_syn(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1860 struct sk_buff
*skb
)
1864 err
= ((ntohl(tcph
->ack_seq
) == cm_node
->tcp_cntxt
.loc_seq_num
)) ? 0 : 1;
1866 active_open_err(cm_node
, skb
, 1);
1871 static int check_seq(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1872 struct sk_buff
*skb
)
1877 u32 loc_seq_num
= cm_node
->tcp_cntxt
.loc_seq_num
;
1878 u32 rcv_nxt
= cm_node
->tcp_cntxt
.rcv_nxt
;
1881 seq
= ntohl(tcph
->seq
);
1882 ack_seq
= ntohl(tcph
->ack_seq
);
1883 rcv_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
1884 if (ack_seq
!= loc_seq_num
)
1886 else if (!between(seq
, rcv_nxt
, (rcv_nxt
+ rcv_wnd
)))
1889 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1890 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1891 cm_node
->listener
, cm_node
->state
);
1892 indicate_pkt_err(cm_node
, skb
);
1893 nes_debug(NES_DBG_CM
, "seq ERROR cm_node =%p seq=0x%08X "
1894 "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node
, seq
, rcv_nxt
,
1901 * handle_syn_pkt() is for Passive node. The syn packet is received when a node
1902 * is created with a listener or it may comein as rexmitted packet which in
1903 * that case will be just dropped.
1905 static void handle_syn_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1906 struct tcphdr
*tcph
)
1912 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1914 inc_sequence
= ntohl(tcph
->seq
);
1916 switch (cm_node
->state
) {
1917 case NES_CM_STATE_SYN_SENT
:
1918 case NES_CM_STATE_MPAREQ_SENT
:
1919 /* Rcvd syn on active open connection*/
1920 active_open_err(cm_node
, skb
, 1);
1922 case NES_CM_STATE_LISTENING
:
1924 if (atomic_read(&cm_node
->listener
->pend_accepts_cnt
) >
1925 cm_node
->listener
->backlog
) {
1926 nes_debug(NES_DBG_CM
, "drop syn due to backlog "
1929 passive_open_err(cm_node
, skb
, 0);
1932 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
,
1935 passive_open_err(cm_node
, skb
, 0);
1939 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
1940 BUG_ON(cm_node
->send_entry
);
1941 cm_node
->accept_pend
= 1;
1942 atomic_inc(&cm_node
->listener
->pend_accepts_cnt
);
1944 cm_node
->state
= NES_CM_STATE_SYN_RCVD
;
1945 send_syn(cm_node
, 1, skb
);
1947 case NES_CM_STATE_CLOSED
:
1948 cleanup_retrans_entry(cm_node
);
1949 add_ref_cm_node(cm_node
);
1950 send_reset(cm_node
, skb
);
1952 case NES_CM_STATE_TSA
:
1953 case NES_CM_STATE_ESTABLISHED
:
1954 case NES_CM_STATE_FIN_WAIT1
:
1955 case NES_CM_STATE_FIN_WAIT2
:
1956 case NES_CM_STATE_MPAREQ_RCVD
:
1957 case NES_CM_STATE_LAST_ACK
:
1958 case NES_CM_STATE_CLOSING
:
1959 case NES_CM_STATE_UNKNOWN
:
1966 static void handle_synack_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1967 struct tcphdr
*tcph
)
1973 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1975 inc_sequence
= ntohl(tcph
->seq
);
1976 switch (cm_node
->state
) {
1977 case NES_CM_STATE_SYN_SENT
:
1978 cleanup_retrans_entry(cm_node
);
1980 if (check_syn(cm_node
, tcph
, skb
))
1982 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
1984 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
, 0);
1986 nes_debug(NES_DBG_CM
, "cm_node=%p tcp_options failed\n",
1990 cleanup_retrans_entry(cm_node
);
1991 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
1992 send_mpa_request(cm_node
, skb
);
1993 cm_node
->state
= NES_CM_STATE_MPAREQ_SENT
;
1995 case NES_CM_STATE_MPAREQ_RCVD
:
1996 /* passive open, so should not be here */
1997 passive_open_err(cm_node
, skb
, 1);
1999 case NES_CM_STATE_LISTENING
:
2000 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2001 cleanup_retrans_entry(cm_node
);
2002 cm_node
->state
= NES_CM_STATE_CLOSED
;
2003 send_reset(cm_node
, skb
);
2005 case NES_CM_STATE_CLOSED
:
2006 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2007 cleanup_retrans_entry(cm_node
);
2008 add_ref_cm_node(cm_node
);
2009 send_reset(cm_node
, skb
);
2011 case NES_CM_STATE_ESTABLISHED
:
2012 case NES_CM_STATE_FIN_WAIT1
:
2013 case NES_CM_STATE_FIN_WAIT2
:
2014 case NES_CM_STATE_LAST_ACK
:
2015 case NES_CM_STATE_TSA
:
2016 case NES_CM_STATE_CLOSING
:
2017 case NES_CM_STATE_UNKNOWN
:
2018 case NES_CM_STATE_MPAREQ_SENT
:
2025 static int handle_ack_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2026 struct tcphdr
*tcph
)
2033 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2035 if (check_seq(cm_node
, tcph
, skb
))
2038 skb_pull(skb
, tcph
->doff
<< 2);
2039 inc_sequence
= ntohl(tcph
->seq
);
2040 datasize
= skb
->len
;
2041 switch (cm_node
->state
) {
2042 case NES_CM_STATE_SYN_RCVD
:
2044 cleanup_retrans_entry(cm_node
);
2045 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
, 1);
2048 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2049 cm_node
->state
= NES_CM_STATE_ESTABLISHED
;
2051 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2052 handle_rcv_mpa(cm_node
, skb
);
2053 } else { /* rcvd ACK only */
2054 dev_kfree_skb_any(skb
);
2057 case NES_CM_STATE_ESTABLISHED
:
2059 cleanup_retrans_entry(cm_node
);
2061 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2062 handle_rcv_mpa(cm_node
, skb
);
2067 case NES_CM_STATE_MPAREQ_SENT
:
2068 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2070 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2071 handle_rcv_mpa(cm_node
, skb
);
2072 } else { /* Could be just an ack pkt.. */
2073 dev_kfree_skb_any(skb
);
2076 case NES_CM_STATE_LISTENING
:
2077 cleanup_retrans_entry(cm_node
);
2078 cm_node
->state
= NES_CM_STATE_CLOSED
;
2079 send_reset(cm_node
, skb
);
2081 case NES_CM_STATE_CLOSED
:
2082 cleanup_retrans_entry(cm_node
);
2083 add_ref_cm_node(cm_node
);
2084 send_reset(cm_node
, skb
);
2086 case NES_CM_STATE_LAST_ACK
:
2087 case NES_CM_STATE_CLOSING
:
2088 cleanup_retrans_entry(cm_node
);
2089 cm_node
->state
= NES_CM_STATE_CLOSED
;
2090 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2091 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2094 case NES_CM_STATE_FIN_WAIT1
:
2095 cleanup_retrans_entry(cm_node
);
2097 cm_node
->state
= NES_CM_STATE_FIN_WAIT2
;
2099 case NES_CM_STATE_SYN_SENT
:
2100 case NES_CM_STATE_FIN_WAIT2
:
2101 case NES_CM_STATE_TSA
:
2102 case NES_CM_STATE_MPAREQ_RCVD
:
2103 case NES_CM_STATE_UNKNOWN
:
2105 cleanup_retrans_entry(cm_node
);
2114 static int handle_tcp_options(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
2115 struct sk_buff
*skb
, int optionsize
, int passive
)
2117 u8
*optionsloc
= (u8
*)&tcph
[1];
2120 if (process_options(cm_node
, optionsloc
, optionsize
,
2122 nes_debug(NES_DBG_CM
, "%s: Node %p, Sending RESET\n",
2125 passive_open_err(cm_node
, skb
, 1);
2127 active_open_err(cm_node
, skb
, 1);
2132 cm_node
->tcp_cntxt
.snd_wnd
= ntohs(tcph
->window
) <<
2133 cm_node
->tcp_cntxt
.snd_wscale
;
2135 if (cm_node
->tcp_cntxt
.snd_wnd
> cm_node
->tcp_cntxt
.max_snd_wnd
)
2136 cm_node
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.snd_wnd
;
2141 * active_open_err() will send reset() if flag set..
2142 * It will also send ABORT event.
2144 static void active_open_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2147 cleanup_retrans_entry(cm_node
);
2149 nes_debug(NES_DBG_CM
, "ERROR active err called for cm_node=%p, "
2150 "state=%d\n", cm_node
, cm_node
->state
);
2151 add_ref_cm_node(cm_node
);
2152 send_reset(cm_node
, skb
);
2154 dev_kfree_skb_any(skb
);
2157 cm_node
->state
= NES_CM_STATE_CLOSED
;
2158 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
2162 * passive_open_err() will either do a reset() or will free up the skb and
2163 * remove the cm_node.
2165 static void passive_open_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2168 cleanup_retrans_entry(cm_node
);
2169 cm_node
->state
= NES_CM_STATE_CLOSED
;
2171 nes_debug(NES_DBG_CM
, "passive_open_err sending RST for "
2172 "cm_node=%p state =%d\n", cm_node
, cm_node
->state
);
2173 send_reset(cm_node
, skb
);
2175 dev_kfree_skb_any(skb
);
2176 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2181 * free_retrans_entry() routines assumes that the retrans_list_lock has
2182 * been acquired before calling.
2184 static void free_retrans_entry(struct nes_cm_node
*cm_node
)
2186 struct nes_timer_entry
*send_entry
;
2188 send_entry
= cm_node
->send_entry
;
2190 cm_node
->send_entry
= NULL
;
2191 dev_kfree_skb_any(send_entry
->skb
);
2193 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2197 static void cleanup_retrans_entry(struct nes_cm_node
*cm_node
)
2199 unsigned long flags
;
2201 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
2202 free_retrans_entry(cm_node
);
2203 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
2208 * Returns skb if to be freed, else it will return NULL if already used..
2210 static void process_packet(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2211 struct nes_cm_core
*cm_core
)
2213 enum nes_tcpip_pkt_type pkt_type
= NES_PKT_TYPE_UNKNOWN
;
2214 struct tcphdr
*tcph
= tcp_hdr(skb
);
2218 skb_pull(skb
, ip_hdr(skb
)->ihl
<< 2);
2220 nes_debug(NES_DBG_CM
, "process_packet: cm_node=%p state =%d syn=%d "
2221 "ack=%d rst=%d fin=%d\n", cm_node
, cm_node
->state
, tcph
->syn
,
2222 tcph
->ack
, tcph
->rst
, tcph
->fin
);
2225 pkt_type
= NES_PKT_TYPE_RST
;
2226 } else if (tcph
->syn
) {
2227 pkt_type
= NES_PKT_TYPE_SYN
;
2229 pkt_type
= NES_PKT_TYPE_SYNACK
;
2230 } else if (tcph
->ack
) {
2231 pkt_type
= NES_PKT_TYPE_ACK
;
2237 case NES_PKT_TYPE_SYN
:
2238 handle_syn_pkt(cm_node
, skb
, tcph
);
2240 case NES_PKT_TYPE_SYNACK
:
2241 handle_synack_pkt(cm_node
, skb
, tcph
);
2243 case NES_PKT_TYPE_ACK
:
2244 ret
= handle_ack_pkt(cm_node
, skb
, tcph
);
2245 if (fin_set
&& !ret
)
2246 handle_fin_pkt(cm_node
);
2248 case NES_PKT_TYPE_RST
:
2249 handle_rst_pkt(cm_node
, skb
, tcph
);
2252 if ((fin_set
) && (!check_seq(cm_node
, tcph
, skb
)))
2253 handle_fin_pkt(cm_node
);
2260 * mini_cm_listen - create a listen node with params
2262 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*cm_core
,
2263 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
)
2265 struct nes_cm_listener
*listener
;
2266 unsigned long flags
;
2268 nes_debug(NES_DBG_CM
, "Search for 0x%08x : 0x%04x\n",
2269 cm_info
->loc_addr
, cm_info
->loc_port
);
2271 /* cannot have multiple matching listeners */
2272 listener
= find_listener(cm_core
, cm_info
->loc_addr
, cm_info
->loc_port
,
2273 NES_CM_LISTENER_EITHER_STATE
);
2275 if (listener
&& listener
->listener_state
== NES_CM_LISTENER_ACTIVE_STATE
) {
2276 /* find automatically incs ref count ??? */
2277 atomic_dec(&listener
->ref_count
);
2278 nes_debug(NES_DBG_CM
, "Not creating listener since it already exists\n");
2283 /* create a CM listen node (1/2 node to compare incoming traffic to) */
2284 listener
= kzalloc(sizeof(*listener
), GFP_ATOMIC
);
2286 nes_debug(NES_DBG_CM
, "Not creating listener memory allocation failed\n");
2290 listener
->loc_addr
= cm_info
->loc_addr
;
2291 listener
->loc_port
= cm_info
->loc_port
;
2292 listener
->reused_node
= 0;
2294 atomic_set(&listener
->ref_count
, 1);
2297 /* find already inc'ed the ref count */
2299 listener
->reused_node
= 1;
2302 listener
->cm_id
= cm_info
->cm_id
;
2303 atomic_set(&listener
->pend_accepts_cnt
, 0);
2304 listener
->cm_core
= cm_core
;
2305 listener
->nesvnic
= nesvnic
;
2306 atomic_inc(&cm_core
->node_cnt
);
2308 listener
->conn_type
= cm_info
->conn_type
;
2309 listener
->backlog
= cm_info
->backlog
;
2310 listener
->listener_state
= NES_CM_LISTENER_ACTIVE_STATE
;
2312 if (!listener
->reused_node
) {
2313 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
2314 list_add(&listener
->list
, &cm_core
->listen_list
.list
);
2315 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
2316 atomic_inc(&cm_core
->listen_node_cnt
);
2319 nes_debug(NES_DBG_CM
, "Api - listen(): addr=0x%08X, port=0x%04x,"
2320 " listener = %p, backlog = %d, cm_id = %p.\n",
2321 cm_info
->loc_addr
, cm_info
->loc_port
,
2322 listener
, listener
->backlog
, listener
->cm_id
);
2329 * mini_cm_connect - make a connection node with params
2331 static struct nes_cm_node
*mini_cm_connect(struct nes_cm_core
*cm_core
,
2332 struct nes_vnic
*nesvnic
, u16 private_data_len
,
2333 void *private_data
, struct nes_cm_info
*cm_info
)
2336 struct nes_cm_node
*cm_node
;
2337 struct nes_cm_listener
*loopbackremotelistener
;
2338 struct nes_cm_node
*loopbackremotenode
;
2339 struct nes_cm_info loopback_cm_info
;
2342 /* create a CM connection node */
2343 cm_node
= make_cm_node(cm_core
, nesvnic
, cm_info
, NULL
);
2347 /* set our node side to client (active) side */
2348 cm_node
->tcp_cntxt
.client
= 1;
2349 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
2351 if (cm_info
->loc_addr
== cm_info
->rem_addr
) {
2352 loopbackremotelistener
= find_listener(cm_core
,
2353 cm_node
->loc_addr
, cm_node
->rem_port
,
2354 NES_CM_LISTENER_ACTIVE_STATE
);
2355 if (loopbackremotelistener
== NULL
) {
2356 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
2358 loopback_cm_info
= *cm_info
;
2359 loopback_cm_info
.loc_port
= cm_info
->rem_port
;
2360 loopback_cm_info
.rem_port
= cm_info
->loc_port
;
2361 loopback_cm_info
.loc_port
=
2363 loopback_cm_info
.rem_port
=
2365 loopback_cm_info
.cm_id
= loopbackremotelistener
->cm_id
;
2366 loopbackremotenode
= make_cm_node(cm_core
, nesvnic
,
2367 &loopback_cm_info
, loopbackremotelistener
);
2368 if (!loopbackremotenode
) {
2369 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2372 atomic_inc(&cm_loopbacks
);
2373 loopbackremotenode
->loopbackpartner
= cm_node
;
2374 loopbackremotenode
->tcp_cntxt
.rcv_wscale
=
2375 NES_CM_DEFAULT_RCV_WND_SCALE
;
2376 cm_node
->loopbackpartner
= loopbackremotenode
;
2377 memcpy(loopbackremotenode
->mpa_frame_buf
, private_data
,
2379 loopbackremotenode
->mpa_frame_size
= private_data_len
;
2381 /* we are done handling this state. */
2382 /* set node to a TSA state */
2383 cm_node
->state
= NES_CM_STATE_TSA
;
2384 cm_node
->tcp_cntxt
.rcv_nxt
=
2385 loopbackremotenode
->tcp_cntxt
.loc_seq_num
;
2386 loopbackremotenode
->tcp_cntxt
.rcv_nxt
=
2387 cm_node
->tcp_cntxt
.loc_seq_num
;
2388 cm_node
->tcp_cntxt
.max_snd_wnd
=
2389 loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
2390 loopbackremotenode
->tcp_cntxt
.max_snd_wnd
=
2391 cm_node
->tcp_cntxt
.rcv_wnd
;
2392 cm_node
->tcp_cntxt
.snd_wnd
=
2393 loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
2394 loopbackremotenode
->tcp_cntxt
.snd_wnd
=
2395 cm_node
->tcp_cntxt
.rcv_wnd
;
2396 cm_node
->tcp_cntxt
.snd_wscale
=
2397 loopbackremotenode
->tcp_cntxt
.rcv_wscale
;
2398 loopbackremotenode
->tcp_cntxt
.snd_wscale
=
2399 cm_node
->tcp_cntxt
.rcv_wscale
;
2400 loopbackremotenode
->state
= NES_CM_STATE_MPAREQ_RCVD
;
2401 create_event(loopbackremotenode
, NES_CM_EVENT_MPA_REQ
);
2406 start_buff
= &cm_node
->mpa_frame_buf
[0] + sizeof(struct ietf_mpa_v2
);
2407 cm_node
->mpa_frame_size
= private_data_len
;
2409 memcpy(start_buff
, private_data
, private_data_len
);
2411 /* send a syn and goto syn sent state */
2412 cm_node
->state
= NES_CM_STATE_SYN_SENT
;
2413 ret
= send_syn(cm_node
, 0, NULL
);
2416 /* error in sending the syn free up the cm_node struct */
2417 nes_debug(NES_DBG_CM
, "Api - connect() FAILED: dest "
2418 "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
2419 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
,
2421 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2426 nes_debug(NES_DBG_CM
, "Api - connect(): dest addr=0x%08X,"
2427 "port=0x%04x, cm_node=%p, cm_id = %p.\n",
2428 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
,
2437 * mini_cm_accept - accept a connection
2438 * This function is never called
2440 static int mini_cm_accept(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2447 * mini_cm_reject - reject and teardown a connection
2449 static int mini_cm_reject(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2454 struct nes_cm_event event
;
2455 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
2456 struct nes_cm_node
*loopback
= cm_node
->loopbackpartner
;
2458 nes_debug(NES_DBG_CM
, "%s cm_node=%p type=%d state=%d\n",
2459 __func__
, cm_node
, cm_node
->tcp_cntxt
.client
, cm_node
->state
);
2461 if (cm_node
->tcp_cntxt
.client
)
2463 cleanup_retrans_entry(cm_node
);
2466 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
2467 if (passive_state
== NES_SEND_RESET_EVENT
) {
2468 cm_node
->state
= NES_CM_STATE_CLOSED
;
2469 rem_ref_cm_node(cm_core
, cm_node
);
2471 if (cm_node
->state
== NES_CM_STATE_LISTENER_DESTROYED
) {
2472 rem_ref_cm_node(cm_core
, cm_node
);
2474 ret
= send_mpa_reject(cm_node
);
2476 cm_node
->state
= NES_CM_STATE_CLOSED
;
2477 err
= send_reset(cm_node
, NULL
);
2481 cm_id
->add_ref(cm_id
);
2486 cm_node
->cm_id
= NULL
;
2487 if (cm_node
->state
== NES_CM_STATE_LISTENER_DESTROYED
) {
2488 rem_ref_cm_node(cm_core
, cm_node
);
2489 rem_ref_cm_node(cm_core
, loopback
);
2491 event
.cm_node
= loopback
;
2492 event
.cm_info
.rem_addr
= loopback
->rem_addr
;
2493 event
.cm_info
.loc_addr
= loopback
->loc_addr
;
2494 event
.cm_info
.rem_port
= loopback
->rem_port
;
2495 event
.cm_info
.loc_port
= loopback
->loc_port
;
2496 event
.cm_info
.cm_id
= loopback
->cm_id
;
2497 cm_event_mpa_reject(&event
);
2498 rem_ref_cm_node(cm_core
, cm_node
);
2499 loopback
->state
= NES_CM_STATE_CLOSING
;
2501 cm_id
= loopback
->cm_id
;
2502 rem_ref_cm_node(cm_core
, loopback
);
2503 cm_id
->rem_ref(cm_id
);
2514 static int mini_cm_close(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2518 if (!cm_core
|| !cm_node
)
2521 switch (cm_node
->state
) {
2522 case NES_CM_STATE_SYN_RCVD
:
2523 case NES_CM_STATE_SYN_SENT
:
2524 case NES_CM_STATE_ONE_SIDE_ESTABLISHED
:
2525 case NES_CM_STATE_ESTABLISHED
:
2526 case NES_CM_STATE_ACCEPTING
:
2527 case NES_CM_STATE_MPAREQ_SENT
:
2528 case NES_CM_STATE_MPAREQ_RCVD
:
2529 cleanup_retrans_entry(cm_node
);
2530 send_reset(cm_node
, NULL
);
2532 case NES_CM_STATE_CLOSE_WAIT
:
2533 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
2534 send_fin(cm_node
, NULL
);
2536 case NES_CM_STATE_FIN_WAIT1
:
2537 case NES_CM_STATE_FIN_WAIT2
:
2538 case NES_CM_STATE_LAST_ACK
:
2539 case NES_CM_STATE_TIME_WAIT
:
2540 case NES_CM_STATE_CLOSING
:
2543 case NES_CM_STATE_LISTENING
:
2544 cleanup_retrans_entry(cm_node
);
2545 send_reset(cm_node
, NULL
);
2547 case NES_CM_STATE_MPAREJ_RCVD
:
2548 case NES_CM_STATE_UNKNOWN
:
2549 case NES_CM_STATE_INITED
:
2550 case NES_CM_STATE_CLOSED
:
2551 case NES_CM_STATE_LISTENER_DESTROYED
:
2552 ret
= rem_ref_cm_node(cm_core
, cm_node
);
2554 case NES_CM_STATE_TSA
:
2555 if (cm_node
->send_entry
)
2556 printk(KERN_ERR
"ERROR Close got called from STATE_TSA "
2557 "send_entry=%p\n", cm_node
->send_entry
);
2558 ret
= rem_ref_cm_node(cm_core
, cm_node
);
2566 * recv_pkt - recv an ETHERNET packet, and process it through CM
2567 * node state machine
2569 static int mini_cm_recv_pkt(struct nes_cm_core
*cm_core
,
2570 struct nes_vnic
*nesvnic
, struct sk_buff
*skb
)
2572 struct nes_cm_node
*cm_node
= NULL
;
2573 struct nes_cm_listener
*listener
= NULL
;
2575 struct tcphdr
*tcph
;
2576 struct nes_cm_info nfo
;
2577 int skb_handled
= 1;
2578 __be32 tmp_daddr
, tmp_saddr
;
2582 if (skb
->len
< sizeof(struct iphdr
) + sizeof(struct tcphdr
))
2585 iph
= (struct iphdr
*)skb
->data
;
2586 tcph
= (struct tcphdr
*)(skb
->data
+ sizeof(struct iphdr
));
2588 nfo
.loc_addr
= ntohl(iph
->daddr
);
2589 nfo
.loc_port
= ntohs(tcph
->dest
);
2590 nfo
.rem_addr
= ntohl(iph
->saddr
);
2591 nfo
.rem_port
= ntohs(tcph
->source
);
2593 tmp_daddr
= cpu_to_be32(iph
->daddr
);
2594 tmp_saddr
= cpu_to_be32(iph
->saddr
);
2596 nes_debug(NES_DBG_CM
, "Received packet: dest=%pI4:0x%04X src=%pI4:0x%04X\n",
2597 &tmp_daddr
, tcph
->dest
, &tmp_saddr
, tcph
->source
);
2600 cm_node
= find_node(cm_core
,
2601 nfo
.rem_port
, nfo
.rem_addr
,
2602 nfo
.loc_port
, nfo
.loc_addr
);
2605 /* Only type of packet accepted are for */
2606 /* the PASSIVE open (syn only) */
2607 if ((!tcph
->syn
) || (tcph
->ack
)) {
2611 listener
= find_listener(cm_core
, nfo
.loc_addr
,
2613 NES_CM_LISTENER_ACTIVE_STATE
);
2617 nes_debug(NES_DBG_CM
, "Unable to find listener for the pkt\n");
2621 nfo
.cm_id
= listener
->cm_id
;
2622 nfo
.conn_type
= listener
->conn_type
;
2623 cm_node
= make_cm_node(cm_core
, nesvnic
, &nfo
,
2626 nes_debug(NES_DBG_CM
, "Unable to allocate "
2628 cm_packets_dropped
++;
2629 atomic_dec(&listener
->ref_count
);
2630 dev_kfree_skb_any(skb
);
2633 if (!tcph
->rst
&& !tcph
->fin
) {
2634 cm_node
->state
= NES_CM_STATE_LISTENING
;
2636 cm_packets_dropped
++;
2637 rem_ref_cm_node(cm_core
, cm_node
);
2638 dev_kfree_skb_any(skb
);
2641 add_ref_cm_node(cm_node
);
2642 } else if (cm_node
->state
== NES_CM_STATE_TSA
) {
2643 if (cm_node
->nesqp
->pau_mode
)
2644 nes_queue_mgt_skbs(skb
, nesvnic
, cm_node
->nesqp
);
2646 rem_ref_cm_node(cm_core
, cm_node
);
2647 atomic_inc(&cm_accel_dropped_pkts
);
2648 dev_kfree_skb_any(skb
);
2652 skb_reset_network_header(skb
);
2653 skb_set_transport_header(skb
, sizeof(*tcph
));
2654 skb
->len
= ntohs(iph
->tot_len
);
2655 process_packet(cm_node
, skb
, cm_core
);
2656 rem_ref_cm_node(cm_core
, cm_node
);
2663 * nes_cm_alloc_core - allocate a top level instance of a cm core
2665 static struct nes_cm_core
*nes_cm_alloc_core(void)
2667 struct nes_cm_core
*cm_core
;
2669 /* setup the CM core */
2670 /* alloc top level core control structure */
2671 cm_core
= kzalloc(sizeof(*cm_core
), GFP_KERNEL
);
2675 INIT_LIST_HEAD(&cm_core
->connected_nodes
);
2676 init_timer(&cm_core
->tcp_timer
);
2677 cm_core
->tcp_timer
.function
= nes_cm_timer_tick
;
2679 cm_core
->mtu
= NES_CM_DEFAULT_MTU
;
2680 cm_core
->state
= NES_CM_STATE_INITED
;
2681 cm_core
->free_tx_pkt_max
= NES_CM_DEFAULT_FREE_PKTS
;
2683 atomic_set(&cm_core
->events_posted
, 0);
2685 cm_core
->api
= &nes_cm_api
;
2687 spin_lock_init(&cm_core
->ht_lock
);
2688 spin_lock_init(&cm_core
->listen_list_lock
);
2690 INIT_LIST_HEAD(&cm_core
->listen_list
.list
);
2692 nes_debug(NES_DBG_CM
, "Init CM Core completed -- cm_core=%p\n", cm_core
);
2694 nes_debug(NES_DBG_CM
, "Enable QUEUE EVENTS\n");
2695 cm_core
->event_wq
= create_singlethread_workqueue("nesewq");
2696 if (!cm_core
->event_wq
)
2697 goto out_free_cmcore
;
2698 cm_core
->post_event
= nes_cm_post_event
;
2699 nes_debug(NES_DBG_CM
, "Enable QUEUE DISCONNECTS\n");
2700 cm_core
->disconn_wq
= create_singlethread_workqueue("nesdwq");
2701 if (!cm_core
->disconn_wq
)
2704 print_core(cm_core
);
2708 destroy_workqueue(cm_core
->event_wq
);
2716 * mini_cm_dealloc_core - deallocate a top level instance of a cm core
2718 static int mini_cm_dealloc_core(struct nes_cm_core
*cm_core
)
2720 nes_debug(NES_DBG_CM
, "De-Alloc CM Core (%p)\n", cm_core
);
2727 if (timer_pending(&cm_core
->tcp_timer
))
2728 del_timer(&cm_core
->tcp_timer
);
2730 destroy_workqueue(cm_core
->event_wq
);
2731 destroy_workqueue(cm_core
->disconn_wq
);
2732 nes_debug(NES_DBG_CM
, "\n");
2742 static int mini_cm_get(struct nes_cm_core
*cm_core
)
2744 return cm_core
->state
;
2751 static int mini_cm_set(struct nes_cm_core
*cm_core
, u32 type
, u32 value
)
2756 case NES_CM_SET_PKT_SIZE
:
2757 cm_core
->mtu
= value
;
2759 case NES_CM_SET_FREE_PKT_Q_SIZE
:
2760 cm_core
->free_tx_pkt_max
= value
;
2763 /* unknown set option */
2772 * nes_cm_init_tsa_conn setup HW; MPA frames must be
2773 * successfully exchanged when this is called
2775 static int nes_cm_init_tsa_conn(struct nes_qp
*nesqp
, struct nes_cm_node
*cm_node
)
2782 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4
|
2783 NES_QPCONTEXT_MISC_NO_NAGLE
| NES_QPCONTEXT_MISC_DO_NOT_FRAG
|
2784 NES_QPCONTEXT_MISC_DROS
);
2786 if (cm_node
->tcp_cntxt
.snd_wscale
|| cm_node
->tcp_cntxt
.rcv_wscale
)
2787 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE
);
2789 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT
);
2791 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
2792 cm_node
->tos
<< NES_QPCONTEXT_MISC2_TOS_SHIFT
);
2794 nesqp
->nesqp_context
->mss
|= cpu_to_le32(((u32
)cm_node
->tcp_cntxt
.mss
) << 16);
2796 nesqp
->nesqp_context
->tcp_state_flow_label
|= cpu_to_le32(
2797 (u32
)NES_QPCONTEXT_TCPSTATE_EST
<< NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT
);
2799 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2800 (cm_node
->tcp_cntxt
.snd_wscale
<< NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT
) &
2801 NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK
);
2803 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2804 (cm_node
->tcp_cntxt
.rcv_wscale
<< NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT
) &
2805 NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK
);
2807 nesqp
->nesqp_context
->keepalive
= cpu_to_le32(0x80);
2808 nesqp
->nesqp_context
->ts_recent
= 0;
2809 nesqp
->nesqp_context
->ts_age
= 0;
2810 nesqp
->nesqp_context
->snd_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2811 nesqp
->nesqp_context
->snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.snd_wnd
);
2812 nesqp
->nesqp_context
->rcv_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2813 nesqp
->nesqp_context
->rcv_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_wnd
<<
2814 cm_node
->tcp_cntxt
.rcv_wscale
);
2815 nesqp
->nesqp_context
->snd_max
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2816 nesqp
->nesqp_context
->snd_una
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2817 nesqp
->nesqp_context
->srtt
= 0;
2818 nesqp
->nesqp_context
->rttvar
= cpu_to_le32(0x6);
2819 nesqp
->nesqp_context
->ssthresh
= cpu_to_le32(0x3FFFC000);
2820 nesqp
->nesqp_context
->cwnd
= cpu_to_le32(2 * cm_node
->tcp_cntxt
.mss
);
2821 nesqp
->nesqp_context
->snd_wl1
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2822 nesqp
->nesqp_context
->snd_wl2
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2823 nesqp
->nesqp_context
->max_snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.max_snd_wnd
);
2825 nes_debug(NES_DBG_CM
, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
2826 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
2827 nesqp
->hwqp
.qp_id
, le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
2828 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
2829 cm_node
->tcp_cntxt
.mss
, le32_to_cpu(nesqp
->nesqp_context
->pd_index_wscale
),
2830 le32_to_cpu(nesqp
->nesqp_context
->rcv_wnd
),
2831 le32_to_cpu(nesqp
->nesqp_context
->misc
));
2832 nes_debug(NES_DBG_CM
, " snd_wnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->snd_wnd
));
2833 nes_debug(NES_DBG_CM
, " snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->cwnd
));
2834 nes_debug(NES_DBG_CM
, " max_swnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->max_snd_wnd
));
2836 nes_debug(NES_DBG_CM
, "Change cm_node state to TSA\n");
2837 cm_node
->state
= NES_CM_STATE_TSA
;
2846 int nes_cm_disconn(struct nes_qp
*nesqp
)
2848 struct disconn_work
*work
;
2850 work
= kzalloc(sizeof *work
, GFP_ATOMIC
);
2852 return -ENOMEM
; /* Timer will clean up */
2854 nes_add_ref(&nesqp
->ibqp
);
2855 work
->nesqp
= nesqp
;
2856 INIT_WORK(&work
->work
, nes_disconnect_worker
);
2857 queue_work(g_cm_core
->disconn_wq
, &work
->work
);
2863 * nes_disconnect_worker
2865 static void nes_disconnect_worker(struct work_struct
*work
)
2867 struct disconn_work
*dwork
= container_of(work
, struct disconn_work
, work
);
2868 struct nes_qp
*nesqp
= dwork
->nesqp
;
2871 nes_debug(NES_DBG_CM
, "processing AEQE id 0x%04X for QP%u.\n",
2872 nesqp
->last_aeq
, nesqp
->hwqp
.qp_id
);
2873 nes_cm_disconn_true(nesqp
);
2874 nes_rem_ref(&nesqp
->ibqp
);
2879 * nes_cm_disconn_true
2881 static int nes_cm_disconn_true(struct nes_qp
*nesqp
)
2883 unsigned long flags
;
2885 struct iw_cm_id
*cm_id
;
2886 struct iw_cm_event cm_event
;
2887 struct nes_vnic
*nesvnic
;
2889 u8 original_hw_tcp_state
;
2890 u8 original_ibqp_state
;
2891 int disconn_status
= 0;
2892 int issue_disconn
= 0;
2893 int issue_close
= 0;
2894 int issue_flush
= 0;
2895 u32 flush_q
= NES_CQP_FLUSH_RQ
;
2896 struct ib_event ibevent
;
2899 nes_debug(NES_DBG_CM
, "disconnect_worker nesqp is NULL\n");
2903 spin_lock_irqsave(&nesqp
->lock
, flags
);
2904 cm_id
= nesqp
->cm_id
;
2905 /* make sure we havent already closed this connection */
2907 nes_debug(NES_DBG_CM
, "QP%u disconnect_worker cmid is NULL\n",
2909 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2913 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2914 nes_debug(NES_DBG_CM
, "Disconnecting QP%u\n", nesqp
->hwqp
.qp_id
);
2916 original_hw_tcp_state
= nesqp
->hw_tcp_state
;
2917 original_ibqp_state
= nesqp
->ibqp_state
;
2918 last_ae
= nesqp
->last_aeq
;
2920 if (nesqp
->term_flags
) {
2923 nesqp
->cm_id
= NULL
;
2924 del_timer(&nesqp
->terminate_timer
);
2925 if (nesqp
->flush_issued
== 0) {
2926 nesqp
->flush_issued
= 1;
2929 } else if ((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSE_WAIT
) ||
2930 ((original_ibqp_state
== IB_QPS_RTS
) &&
2931 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2933 if (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
)
2934 disconn_status
= -ECONNRESET
;
2937 if (((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSED
) ||
2938 (original_hw_tcp_state
== NES_AEQE_TCP_STATE_TIME_WAIT
) ||
2939 (last_ae
== NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
) ||
2940 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2942 nesqp
->cm_id
= NULL
;
2943 if (nesqp
->flush_issued
== 0) {
2944 nesqp
->flush_issued
= 1;
2949 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2951 if ((issue_flush
) && (nesqp
->destroyed
== 0)) {
2952 /* Flush the queue(s) */
2953 if (nesqp
->hw_iwarp_state
>= NES_AEQE_IWARP_STATE_TERMINATE
)
2954 flush_q
|= NES_CQP_FLUSH_SQ
;
2955 flush_wqes(nesvnic
->nesdev
, nesqp
, flush_q
, 1);
2957 if (nesqp
->term_flags
) {
2958 ibevent
.device
= nesqp
->ibqp
.device
;
2959 ibevent
.event
= nesqp
->terminate_eventtype
;
2960 ibevent
.element
.qp
= &nesqp
->ibqp
;
2961 if (nesqp
->ibqp
.event_handler
)
2962 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2966 if ((cm_id
) && (cm_id
->event_handler
)) {
2967 if (issue_disconn
) {
2968 atomic_inc(&cm_disconnects
);
2969 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
2970 cm_event
.status
= disconn_status
;
2971 cm_event
.local_addr
= cm_id
->m_local_addr
;
2972 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
2973 cm_event
.private_data
= NULL
;
2974 cm_event
.private_data_len
= 0;
2976 nes_debug(NES_DBG_CM
, "Generating a CM Disconnect Event"
2977 " for QP%u, SQ Head = %u, SQ Tail = %u. "
2978 "cm_id = %p, refcount = %u.\n",
2979 nesqp
->hwqp
.qp_id
, nesqp
->hwqp
.sq_head
,
2980 nesqp
->hwqp
.sq_tail
, cm_id
,
2981 atomic_read(&nesqp
->refcount
));
2983 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2985 nes_debug(NES_DBG_CM
, "OFA CM event_handler "
2986 "returned, ret=%d\n", ret
);
2990 atomic_inc(&cm_closes
);
2991 nes_disconnect(nesqp
, 1);
2993 cm_id
->provider_data
= nesqp
;
2994 /* Send up the close complete event */
2995 cm_event
.event
= IW_CM_EVENT_CLOSE
;
2996 cm_event
.status
= 0;
2997 cm_event
.provider_data
= cm_id
->provider_data
;
2998 cm_event
.local_addr
= cm_id
->m_local_addr
;
2999 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3000 cm_event
.private_data
= NULL
;
3001 cm_event
.private_data_len
= 0;
3003 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3005 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3007 cm_id
->rem_ref(cm_id
);
3018 static int nes_disconnect(struct nes_qp
*nesqp
, int abrupt
)
3021 struct nes_vnic
*nesvnic
;
3022 struct nes_device
*nesdev
;
3023 struct nes_ib_device
*nesibdev
;
3025 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3029 nesdev
= nesvnic
->nesdev
;
3030 nesibdev
= nesvnic
->nesibdev
;
3032 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
3033 netdev_refcnt_read(nesvnic
->netdev
));
3035 if (nesqp
->active_conn
) {
3037 /* indicate this connection is NOT active */
3038 nesqp
->active_conn
= 0;
3040 /* Need to free the Last Streaming Mode Message */
3041 if (nesqp
->ietf_frame
) {
3043 nesibdev
->ibdev
.dereg_mr(nesqp
->lsmm_mr
);
3044 pci_free_consistent(nesdev
->pcidev
,
3045 nesqp
->private_data_len
+ nesqp
->ietf_frame_size
,
3046 nesqp
->ietf_frame
, nesqp
->ietf_frame_pbase
);
3050 /* close the CM node down if it is still active */
3051 if (nesqp
->cm_node
) {
3052 nes_debug(NES_DBG_CM
, "Call close API\n");
3054 g_cm_core
->api
->close(g_cm_core
, nesqp
->cm_node
);
3064 int nes_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3068 struct nes_qp
*nesqp
;
3069 struct nes_vnic
*nesvnic
;
3070 struct nes_device
*nesdev
;
3071 struct nes_cm_node
*cm_node
;
3072 struct nes_adapter
*adapter
;
3073 struct ib_qp_attr attr
;
3074 struct iw_cm_event cm_event
;
3075 struct nes_hw_qp_wqe
*wqe
;
3076 struct nes_v4_quad nes_quad
;
3080 struct nes_ib_device
*nesibdev
;
3081 struct ib_mr
*ibmr
= NULL
;
3082 struct nes_pd
*nespd
;
3084 u8 mpa_frame_offset
= 0;
3085 struct ietf_mpa_v2
*mpa_v2_frame
;
3087 u8
*start_ptr
= &start_addr
;
3088 u8
**start_buff
= &start_ptr
;
3090 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3091 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3093 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
3097 /* get all our handles */
3098 nesqp
= to_nesqp(ibqp
);
3099 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3100 nesdev
= nesvnic
->nesdev
;
3101 adapter
= nesdev
->nesadapter
;
3103 cm_node
= (struct nes_cm_node
*)cm_id
->provider_data
;
3104 nes_debug(NES_DBG_CM
, "nes_accept: cm_node= %p nesvnic=%p, netdev=%p,"
3105 "%s\n", cm_node
, nesvnic
, nesvnic
->netdev
,
3106 nesvnic
->netdev
->name
);
3108 if (NES_CM_STATE_LISTENER_DESTROYED
== cm_node
->state
) {
3109 if (cm_node
->loopbackpartner
)
3110 rem_ref_cm_node(cm_node
->cm_core
, cm_node
->loopbackpartner
);
3111 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
3115 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
3116 if (passive_state
== NES_SEND_RESET_EVENT
) {
3117 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
3120 /* associate the node with the QP */
3121 nesqp
->cm_node
= (void *)cm_node
;
3122 cm_node
->nesqp
= nesqp
;
3125 nes_debug(NES_DBG_CM
, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
3126 nesqp
->hwqp
.qp_id
, cm_node
, jiffies
, cm_node
->listener
);
3127 atomic_inc(&cm_accepts
);
3129 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
3130 netdev_refcnt_read(nesvnic
->netdev
));
3132 nesqp
->ietf_frame_size
= sizeof(struct ietf_mpa_v2
);
3133 /* allocate the ietf frame and space for private data */
3134 nesqp
->ietf_frame
= pci_alloc_consistent(nesdev
->pcidev
,
3135 nesqp
->ietf_frame_size
+ conn_param
->private_data_len
,
3136 &nesqp
->ietf_frame_pbase
);
3138 if (!nesqp
->ietf_frame
) {
3139 nes_debug(NES_DBG_CM
, "Unable to allocate memory for private data\n");
3142 mpa_v2_frame
= (struct ietf_mpa_v2
*)nesqp
->ietf_frame
;
3144 if (cm_node
->mpa_frame_rev
== IETF_MPA_V1
)
3145 mpa_frame_offset
= 4;
3147 if (cm_node
->mpa_frame_rev
== IETF_MPA_V1
||
3148 cm_node
->mpav2_ird_ord
== IETF_NO_IRD_ORD
) {
3149 record_ird_ord(cm_node
, (u16
)conn_param
->ird
, (u16
)conn_param
->ord
);
3152 memcpy(mpa_v2_frame
->priv_data
, conn_param
->private_data
,
3153 conn_param
->private_data_len
);
3155 cm_build_mpa_frame(cm_node
, start_buff
, &buff_len
, nesqp
->ietf_frame
, MPA_KEY_REPLY
);
3156 nesqp
->private_data_len
= conn_param
->private_data_len
;
3158 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
3159 wqe
= &nesqp
->hwqp
.sq_vbase
[0];
3161 if (raddr
->sin_addr
.s_addr
!= laddr
->sin_addr
.s_addr
) {
3162 u64temp
= (unsigned long)nesqp
;
3163 nesibdev
= nesvnic
->nesibdev
;
3164 nespd
= nesqp
->nespd
;
3165 tagged_offset
= (u64
)(unsigned long)*start_buff
;
3166 ibmr
= nes_reg_phys_mr(&nespd
->ibpd
,
3167 nesqp
->ietf_frame_pbase
+ mpa_frame_offset
,
3168 buff_len
, IB_ACCESS_LOCAL_WRITE
,
3171 nes_debug(NES_DBG_CM
, "Unable to register memory region"
3172 "for lSMM for cm_node = %p \n",
3174 pci_free_consistent(nesdev
->pcidev
,
3175 nesqp
->private_data_len
+ nesqp
->ietf_frame_size
,
3176 nesqp
->ietf_frame
, nesqp
->ietf_frame_pbase
);
3177 return PTR_ERR(ibmr
);
3180 ibmr
->pd
= &nespd
->ibpd
;
3181 ibmr
->device
= nespd
->ibpd
.device
;
3182 nesqp
->lsmm_mr
= ibmr
;
3184 u64temp
|= NES_SW_CONTEXT_ALIGN
>> 1;
3185 set_wqe_64bit_value(wqe
->wqe_words
,
3186 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
,
3188 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
3189 cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING
|
3190 NES_IWARP_SQ_WQE_WRPDU
);
3191 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] =
3192 cpu_to_le32(buff_len
);
3193 set_wqe_64bit_value(wqe
->wqe_words
,
3194 NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
,
3195 (u64
)(unsigned long)(*start_buff
));
3196 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] =
3197 cpu_to_le32(buff_len
);
3198 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = ibmr
->lkey
;
3199 if (nesqp
->sq_kmapped
) {
3200 nesqp
->sq_kmapped
= 0;
3201 kunmap(nesqp
->page
);
3204 nesqp
->nesqp_context
->ird_ord_sizes
|=
3205 cpu_to_le32(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
3206 NES_QPCONTEXT_ORDIRD_WRPDU
);
3208 nesqp
->nesqp_context
->ird_ord_sizes
|=
3209 cpu_to_le32(NES_QPCONTEXT_ORDIRD_WRPDU
);
3211 nesqp
->skip_lsmm
= 1;
3213 /* Cache the cm_id in the qp */
3214 nesqp
->cm_id
= cm_id
;
3215 cm_node
->cm_id
= cm_id
;
3217 /* nesqp->cm_node = (void *)cm_id->provider_data; */
3218 cm_id
->provider_data
= nesqp
;
3219 nesqp
->active_conn
= 0;
3221 if (cm_node
->state
== NES_CM_STATE_TSA
)
3222 nes_debug(NES_DBG_CM
, "Already state = TSA for cm_node=%p\n",
3225 nes_cm_init_tsa_conn(nesqp
, cm_node
);
3227 nesqp
->nesqp_context
->tcpPorts
[0] =
3228 cpu_to_le16(cm_node
->loc_port
);
3229 nesqp
->nesqp_context
->tcpPorts
[1] =
3230 cpu_to_le16(cm_node
->rem_port
);
3232 nesqp
->nesqp_context
->ip0
= cpu_to_le32(cm_node
->rem_addr
);
3234 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
3235 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
3236 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
3238 nesqp
->nesqp_context
->arp_index_vlan
|=
3239 cpu_to_le32(nes_arp_table(nesdev
,
3240 le32_to_cpu(nesqp
->nesqp_context
->ip0
), NULL
,
3241 NES_ARP_RESOLVE
) << 16);
3243 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
3244 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
3246 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
3248 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32(
3249 ((u32
)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
));
3250 nesqp
->nesqp_context
->ird_ord_sizes
|=
3251 cpu_to_le32((u32
)cm_node
->ord_size
);
3253 memset(&nes_quad
, 0, sizeof(nes_quad
));
3254 nes_quad
.DstIpAdrIndex
=
3255 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
3256 nes_quad
.SrcIpadr
= htonl(cm_node
->rem_addr
);
3257 nes_quad
.TcpPorts
[0] = htons(cm_node
->rem_port
);
3258 nes_quad
.TcpPorts
[1] = htons(cm_node
->loc_port
);
3260 /* Produce hash key */
3261 crc_value
= get_crc_value(&nes_quad
);
3262 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
3263 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, CRC = 0x%08X\n",
3264 nesqp
->hte_index
, nesqp
->hte_index
& adapter
->hte_index_mask
);
3266 nesqp
->hte_index
&= adapter
->hte_index_mask
;
3267 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
3269 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
3271 nes_debug(NES_DBG_CM
, "QP%u, Destination IP = 0x%08X:0x%04X, local = "
3272 "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
3273 "private data length=%u.\n", nesqp
->hwqp
.qp_id
,
3274 ntohl(raddr
->sin_addr
.s_addr
), ntohs(raddr
->sin_port
),
3275 ntohl(laddr
->sin_addr
.s_addr
), ntohs(laddr
->sin_port
),
3276 le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
3277 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
3280 /* notify OF layer that accept event was successful */
3281 cm_id
->add_ref(cm_id
);
3282 nes_add_ref(&nesqp
->ibqp
);
3284 cm_event
.event
= IW_CM_EVENT_ESTABLISHED
;
3285 cm_event
.status
= 0;
3286 cm_event
.provider_data
= (void *)nesqp
;
3287 cm_event
.local_addr
= cm_id
->m_local_addr
;
3288 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3289 cm_event
.private_data
= NULL
;
3290 cm_event
.private_data_len
= 0;
3291 cm_event
.ird
= cm_node
->ird_size
;
3292 cm_event
.ord
= cm_node
->ord_size
;
3294 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3295 attr
.qp_state
= IB_QPS_RTS
;
3296 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3297 if (cm_node
->loopbackpartner
) {
3298 cm_node
->loopbackpartner
->mpa_frame_size
=
3299 nesqp
->private_data_len
;
3300 /* copy entire MPA frame to our cm_node's frame */
3301 memcpy(cm_node
->loopbackpartner
->mpa_frame_buf
,
3302 conn_param
->private_data
, conn_param
->private_data_len
);
3303 create_event(cm_node
->loopbackpartner
, NES_CM_EVENT_CONNECTED
);
3306 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3307 "ret=%d\n", __func__
, __LINE__
, ret
);
3316 int nes_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
3318 struct nes_cm_node
*cm_node
;
3319 struct nes_cm_node
*loopback
;
3320 struct nes_cm_core
*cm_core
;
3323 atomic_inc(&cm_rejects
);
3324 cm_node
= (struct nes_cm_node
*)cm_id
->provider_data
;
3325 loopback
= cm_node
->loopbackpartner
;
3326 cm_core
= cm_node
->cm_core
;
3327 cm_node
->cm_id
= cm_id
;
3329 if (pdata_len
+ sizeof(struct ietf_mpa_v2
) > MAX_CM_BUFFER
)
3333 memcpy(&loopback
->mpa_frame
.priv_data
, pdata
, pdata_len
);
3334 loopback
->mpa_frame
.priv_data_len
= pdata_len
;
3335 loopback
->mpa_frame_size
= pdata_len
;
3337 start_buff
= &cm_node
->mpa_frame_buf
[0] + sizeof(struct ietf_mpa_v2
);
3338 cm_node
->mpa_frame_size
= pdata_len
;
3339 memcpy(start_buff
, pdata
, pdata_len
);
3341 return cm_core
->api
->reject(cm_core
, cm_node
);
3347 * setup and launch cm connect node
3349 int nes_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3352 struct nes_qp
*nesqp
;
3353 struct nes_vnic
*nesvnic
;
3354 struct nes_device
*nesdev
;
3355 struct nes_cm_node
*cm_node
;
3356 struct nes_cm_info cm_info
;
3358 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3359 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3361 if (cm_id
->remote_addr
.ss_family
!= AF_INET
)
3363 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
3366 nesqp
= to_nesqp(ibqp
);
3369 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3372 nesdev
= nesvnic
->nesdev
;
3376 if (!laddr
->sin_port
|| !raddr
->sin_port
)
3379 nes_debug(NES_DBG_CM
, "QP%u, current IP = 0x%08X, Destination IP = "
3380 "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp
->hwqp
.qp_id
,
3381 ntohl(nesvnic
->local_ipaddr
), ntohl(raddr
->sin_addr
.s_addr
),
3382 ntohs(raddr
->sin_port
), ntohl(laddr
->sin_addr
.s_addr
),
3383 ntohs(laddr
->sin_port
));
3385 atomic_inc(&cm_connects
);
3386 nesqp
->active_conn
= 1;
3388 /* cache the cm_id in the qp */
3389 nesqp
->cm_id
= cm_id
;
3390 cm_id
->provider_data
= nesqp
;
3391 nesqp
->private_data_len
= conn_param
->private_data_len
;
3393 nes_debug(NES_DBG_CM
, "requested ord = 0x%08X.\n", (u32
)conn_param
->ord
);
3394 nes_debug(NES_DBG_CM
, "mpa private data len =%u\n",
3395 conn_param
->private_data_len
);
3397 /* set up the connection params for the node */
3398 cm_info
.loc_addr
= ntohl(laddr
->sin_addr
.s_addr
);
3399 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3400 cm_info
.rem_addr
= ntohl(raddr
->sin_addr
.s_addr
);
3401 cm_info
.rem_port
= ntohs(raddr
->sin_port
);
3402 cm_info
.cm_id
= cm_id
;
3403 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
3405 if (laddr
->sin_addr
.s_addr
!= raddr
->sin_addr
.s_addr
) {
3406 nes_manage_apbvt(nesvnic
, cm_info
.loc_port
,
3407 PCI_FUNC(nesdev
->pcidev
->devfn
),
3408 NES_MANAGE_APBVT_ADD
);
3412 cm_id
->add_ref(cm_id
);
3414 /* create a connect CM node connection */
3415 cm_node
= g_cm_core
->api
->connect(g_cm_core
, nesvnic
,
3416 conn_param
->private_data_len
, (void *)conn_param
->private_data
,
3420 nes_manage_apbvt(nesvnic
, cm_info
.loc_port
,
3421 PCI_FUNC(nesdev
->pcidev
->devfn
),
3422 NES_MANAGE_APBVT_DEL
);
3424 nes_debug(NES_DBG_NLMSG
, "Delete loc_port = %04X\n",
3426 cm_id
->rem_ref(cm_id
);
3430 record_ird_ord(cm_node
, (u16
)conn_param
->ird
, (u16
)conn_param
->ord
);
3431 if (cm_node
->send_rdma0_op
== SEND_RDMA_READ_ZERO
&&
3432 cm_node
->ord_size
== 0)
3433 cm_node
->ord_size
= 1;
3435 cm_node
->apbvt_set
= apbvt_set
;
3436 cm_node
->tos
= cm_id
->tos
;
3437 nesqp
->cm_node
= cm_node
;
3438 cm_node
->nesqp
= nesqp
;
3439 nes_add_ref(&nesqp
->ibqp
);
3448 int nes_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
3450 struct nes_vnic
*nesvnic
;
3451 struct nes_cm_listener
*cm_node
;
3452 struct nes_cm_info cm_info
;
3454 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3456 nes_debug(NES_DBG_CM
, "cm_id = %p, local port = 0x%04X.\n",
3457 cm_id
, ntohs(laddr
->sin_port
));
3459 if (cm_id
->m_local_addr
.ss_family
!= AF_INET
)
3461 nesvnic
= to_nesvnic(cm_id
->device
);
3465 nes_debug(NES_DBG_CM
, "nesvnic=%p, netdev=%p, %s\n",
3466 nesvnic
, nesvnic
->netdev
, nesvnic
->netdev
->name
);
3468 nes_debug(NES_DBG_CM
, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
3469 nesvnic
->local_ipaddr
, laddr
->sin_addr
.s_addr
);
3471 /* setup listen params in our api call struct */
3472 cm_info
.loc_addr
= ntohl(nesvnic
->local_ipaddr
);
3473 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3474 cm_info
.backlog
= backlog
;
3475 cm_info
.cm_id
= cm_id
;
3477 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
3479 cm_node
= g_cm_core
->api
->listen(g_cm_core
, nesvnic
, &cm_info
);
3481 printk(KERN_ERR
"%s[%u] Error returned from listen API call\n",
3482 __func__
, __LINE__
);
3486 cm_id
->provider_data
= cm_node
;
3487 cm_node
->tos
= cm_id
->tos
;
3489 if (!cm_node
->reused_node
) {
3490 err
= nes_manage_apbvt(nesvnic
, cm_node
->loc_port
,
3491 PCI_FUNC(nesvnic
->nesdev
->pcidev
->devfn
),
3492 NES_MANAGE_APBVT_ADD
);
3494 printk(KERN_ERR
"nes_manage_apbvt call returned %d.\n",
3496 g_cm_core
->api
->stop_listener(g_cm_core
, (void *)cm_node
);
3499 atomic_inc(&cm_listens_created
);
3502 cm_id
->add_ref(cm_id
);
3503 cm_id
->provider_data
= (void *)cm_node
;
3511 * nes_destroy_listen
3513 int nes_destroy_listen(struct iw_cm_id
*cm_id
)
3515 if (cm_id
->provider_data
)
3516 g_cm_core
->api
->stop_listener(g_cm_core
, cm_id
->provider_data
);
3518 nes_debug(NES_DBG_CM
, "cm_id->provider_data was NULL\n");
3520 cm_id
->rem_ref(cm_id
);
3529 int nes_cm_recv(struct sk_buff
*skb
, struct net_device
*netdevice
)
3533 cm_packets_received
++;
3534 if ((g_cm_core
) && (g_cm_core
->api
))
3535 rc
= g_cm_core
->api
->recv_pkt(g_cm_core
, netdev_priv(netdevice
), skb
);
3537 nes_debug(NES_DBG_CM
, "Unable to process packet for CM,"
3538 " cm is not setup properly.\n");
3546 * Start and init a cm core module
3548 int nes_cm_start(void)
3550 nes_debug(NES_DBG_CM
, "\n");
3551 /* create the primary CM core, pass this handle to subsequent core inits */
3552 g_cm_core
= nes_cm_alloc_core();
3562 * stop and dealloc all cm core instances
3564 int nes_cm_stop(void)
3566 g_cm_core
->api
->destroy_cm_core(g_cm_core
);
3572 * cm_event_connected
3573 * handle a connected event, setup QPs and HW
3575 static void cm_event_connected(struct nes_cm_event
*event
)
3577 struct nes_qp
*nesqp
;
3578 struct nes_vnic
*nesvnic
;
3579 struct nes_device
*nesdev
;
3580 struct nes_cm_node
*cm_node
;
3581 struct nes_adapter
*nesadapter
;
3582 struct ib_qp_attr attr
;
3583 struct iw_cm_id
*cm_id
;
3584 struct iw_cm_event cm_event
;
3585 struct nes_v4_quad nes_quad
;
3588 struct sockaddr_in
*laddr
;
3589 struct sockaddr_in
*raddr
;
3590 struct sockaddr_in
*cm_event_laddr
;
3592 /* get all our handles */
3593 cm_node
= event
->cm_node
;
3594 cm_id
= cm_node
->cm_id
;
3595 nes_debug(NES_DBG_CM
, "cm_event_connected - %p - cm_id = %p\n", cm_node
, cm_id
);
3596 nesqp
= (struct nes_qp
*)cm_id
->provider_data
;
3597 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3598 nesdev
= nesvnic
->nesdev
;
3599 nesadapter
= nesdev
->nesadapter
;
3600 laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3601 raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3602 cm_event_laddr
= (struct sockaddr_in
*)&cm_event
.local_addr
;
3604 if (nesqp
->destroyed
)
3606 atomic_inc(&cm_connecteds
);
3607 nes_debug(NES_DBG_CM
, "QP%u attempting to connect to 0x%08X:0x%04X on"
3608 " local port 0x%04X. jiffies = %lu.\n",
3609 nesqp
->hwqp
.qp_id
, ntohl(raddr
->sin_addr
.s_addr
),
3610 ntohs(raddr
->sin_port
), ntohs(laddr
->sin_port
), jiffies
);
3612 nes_cm_init_tsa_conn(nesqp
, cm_node
);
3614 /* set the QP tsa context */
3615 nesqp
->nesqp_context
->tcpPorts
[0] =
3616 cpu_to_le16(cm_node
->loc_port
);
3617 nesqp
->nesqp_context
->tcpPorts
[1] =
3618 cpu_to_le16(cm_node
->rem_port
);
3619 nesqp
->nesqp_context
->ip0
= cpu_to_le32(cm_node
->rem_addr
);
3621 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
3622 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
3623 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
3624 nesqp
->nesqp_context
->arp_index_vlan
|= cpu_to_le32(
3625 nes_arp_table(nesdev
,
3626 le32_to_cpu(nesqp
->nesqp_context
->ip0
),
3627 NULL
, NES_ARP_RESOLVE
) << 16);
3628 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
3629 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
3630 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
3631 nesqp
->nesqp_context
->ird_ord_sizes
|=
3632 cpu_to_le32((u32
)1 <<
3633 NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
);
3634 nesqp
->nesqp_context
->ird_ord_sizes
|=
3635 cpu_to_le32((u32
)cm_node
->ord_size
);
3637 /* Adjust tail for not having a LSMM */
3638 /*nesqp->hwqp.sq_tail = 1;*/
3640 build_rdma0_msg(cm_node
, &nesqp
);
3642 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
,
3643 (1 << 24) | 0x00800000 | nesqp
->hwqp
.qp_id
);
3645 memset(&nes_quad
, 0, sizeof(nes_quad
));
3647 nes_quad
.DstIpAdrIndex
=
3648 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
3649 nes_quad
.SrcIpadr
= htonl(cm_node
->rem_addr
);
3650 nes_quad
.TcpPorts
[0] = htons(cm_node
->rem_port
);
3651 nes_quad
.TcpPorts
[1] = htons(cm_node
->loc_port
);
3653 /* Produce hash key */
3654 crc_value
= get_crc_value(&nes_quad
);
3655 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
3656 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
3657 nesqp
->hte_index
, nesqp
->hte_index
& nesadapter
->hte_index_mask
);
3659 nesqp
->hte_index
&= nesadapter
->hte_index_mask
;
3660 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
3662 nesqp
->ietf_frame
= &cm_node
->mpa_frame
;
3663 nesqp
->private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3664 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
3666 /* notify OF layer we successfully created the requested connection */
3667 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3668 cm_event
.status
= 0;
3669 cm_event
.provider_data
= cm_id
->provider_data
;
3670 cm_event_laddr
->sin_family
= AF_INET
;
3671 cm_event_laddr
->sin_port
= laddr
->sin_port
;
3672 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3674 cm_event
.private_data
= (void *)event
->cm_node
->mpa_frame_buf
;
3675 cm_event
.private_data_len
= (u8
)event
->cm_node
->mpa_frame_size
;
3676 cm_event
.ird
= cm_node
->ird_size
;
3677 cm_event
.ord
= cm_node
->ord_size
;
3679 cm_event_laddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3680 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3681 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3684 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3685 "ret=%d\n", __func__
, __LINE__
, ret
);
3686 attr
.qp_state
= IB_QPS_RTS
;
3687 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3689 nes_debug(NES_DBG_CM
, "Exiting connect thread for QP%u. jiffies = "
3690 "%lu\n", nesqp
->hwqp
.qp_id
, jiffies
);
3697 * cm_event_connect_error
3699 static void cm_event_connect_error(struct nes_cm_event
*event
)
3701 struct nes_qp
*nesqp
;
3702 struct iw_cm_id
*cm_id
;
3703 struct iw_cm_event cm_event
;
3704 /* struct nes_cm_info cm_info; */
3707 if (!event
->cm_node
)
3710 cm_id
= event
->cm_node
->cm_id
;
3714 nes_debug(NES_DBG_CM
, "cm_node=%p, cm_id=%p\n", event
->cm_node
, cm_id
);
3715 nesqp
= cm_id
->provider_data
;
3720 /* notify OF layer about this connection error event */
3721 /* cm_id->rem_ref(cm_id); */
3722 nesqp
->cm_id
= NULL
;
3723 cm_id
->provider_data
= NULL
;
3724 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3725 cm_event
.status
= -ECONNRESET
;
3726 cm_event
.provider_data
= cm_id
->provider_data
;
3727 cm_event
.local_addr
= cm_id
->m_local_addr
;
3728 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3729 cm_event
.private_data
= NULL
;
3730 cm_event
.private_data_len
= 0;
3732 #ifdef CONFIG_INFINIBAND_NES_DEBUG
3734 struct sockaddr_in
*cm_event_laddr
= (struct sockaddr_in
*)
3735 &cm_event
.local_addr
;
3736 struct sockaddr_in
*cm_event_raddr
= (struct sockaddr_in
*)
3737 &cm_event
.remote_addr
;
3738 nes_debug(NES_DBG_CM
, "call CM_EVENT REJECTED, local_addr=%08x, remote_addr=%08x\n",
3739 cm_event_laddr
->sin_addr
.s_addr
, cm_event_raddr
->sin_addr
.s_addr
);
3743 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3744 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3746 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3747 "ret=%d\n", __func__
, __LINE__
, ret
);
3748 cm_id
->rem_ref(cm_id
);
3750 rem_ref_cm_node(event
->cm_node
->cm_core
, event
->cm_node
);
3758 static void cm_event_reset(struct nes_cm_event
*event
)
3760 struct nes_qp
*nesqp
;
3761 struct iw_cm_id
*cm_id
;
3762 struct iw_cm_event cm_event
;
3763 /* struct nes_cm_info cm_info; */
3766 if (!event
->cm_node
)
3769 if (!event
->cm_node
->cm_id
)
3772 cm_id
= event
->cm_node
->cm_id
;
3774 nes_debug(NES_DBG_CM
, "%p - cm_id = %p\n", event
->cm_node
, cm_id
);
3775 nesqp
= cm_id
->provider_data
;
3779 nesqp
->cm_id
= NULL
;
3780 /* cm_id->provider_data = NULL; */
3781 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
3782 cm_event
.status
= -ECONNRESET
;
3783 cm_event
.provider_data
= cm_id
->provider_data
;
3784 cm_event
.local_addr
= cm_id
->m_local_addr
;
3785 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3786 cm_event
.private_data
= NULL
;
3787 cm_event
.private_data_len
= 0;
3789 cm_id
->add_ref(cm_id
);
3790 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3791 atomic_inc(&cm_closes
);
3792 cm_event
.event
= IW_CM_EVENT_CLOSE
;
3793 cm_event
.status
= 0;
3794 cm_event
.provider_data
= cm_id
->provider_data
;
3795 cm_event
.local_addr
= cm_id
->m_local_addr
;
3796 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3797 cm_event
.private_data
= NULL
;
3798 cm_event
.private_data_len
= 0;
3799 nes_debug(NES_DBG_CM
, "NODE %p Generating CLOSE\n", event
->cm_node
);
3800 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3802 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3805 /* notify OF layer about this connection error event */
3806 cm_id
->rem_ref(cm_id
);
3815 static void cm_event_mpa_req(struct nes_cm_event
*event
)
3817 struct iw_cm_id
*cm_id
;
3818 struct iw_cm_event cm_event
;
3820 struct nes_cm_node
*cm_node
;
3821 struct sockaddr_in
*cm_event_laddr
= (struct sockaddr_in
*)
3822 &cm_event
.local_addr
;
3823 struct sockaddr_in
*cm_event_raddr
= (struct sockaddr_in
*)
3824 &cm_event
.remote_addr
;
3826 cm_node
= event
->cm_node
;
3829 cm_id
= cm_node
->cm_id
;
3831 atomic_inc(&cm_connect_reqs
);
3832 nes_debug(NES_DBG_CM
, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3833 cm_node
, cm_id
, jiffies
);
3835 cm_event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
3836 cm_event
.status
= 0;
3837 cm_event
.provider_data
= (void *)cm_node
;
3839 cm_event_laddr
->sin_family
= AF_INET
;
3840 cm_event_laddr
->sin_port
= htons(event
->cm_info
.loc_port
);
3841 cm_event_laddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3843 cm_event_raddr
->sin_family
= AF_INET
;
3844 cm_event_raddr
->sin_port
= htons(event
->cm_info
.rem_port
);
3845 cm_event_raddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.rem_addr
);
3846 cm_event
.private_data
= cm_node
->mpa_frame_buf
;
3847 cm_event
.private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3848 if (cm_node
->mpa_frame_rev
== IETF_MPA_V1
) {
3849 cm_event
.ird
= NES_MAX_IRD
;
3850 cm_event
.ord
= NES_MAX_ORD
;
3852 cm_event
.ird
= cm_node
->ird_size
;
3853 cm_event
.ord
= cm_node
->ord_size
;
3856 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3858 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, ret=%d\n",
3859 __func__
, __LINE__
, ret
);
3864 static void cm_event_mpa_reject(struct nes_cm_event
*event
)
3866 struct iw_cm_id
*cm_id
;
3867 struct iw_cm_event cm_event
;
3868 struct nes_cm_node
*cm_node
;
3870 struct sockaddr_in
*cm_event_laddr
= (struct sockaddr_in
*)
3871 &cm_event
.local_addr
;
3872 struct sockaddr_in
*cm_event_raddr
= (struct sockaddr_in
*)
3873 &cm_event
.remote_addr
;
3875 cm_node
= event
->cm_node
;
3878 cm_id
= cm_node
->cm_id
;
3880 atomic_inc(&cm_connect_reqs
);
3881 nes_debug(NES_DBG_CM
, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3882 cm_node
, cm_id
, jiffies
);
3884 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3885 cm_event
.status
= -ECONNREFUSED
;
3886 cm_event
.provider_data
= cm_id
->provider_data
;
3888 cm_event_laddr
->sin_family
= AF_INET
;
3889 cm_event_laddr
->sin_port
= htons(event
->cm_info
.loc_port
);
3890 cm_event_laddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3892 cm_event_raddr
->sin_family
= AF_INET
;
3893 cm_event_raddr
->sin_port
= htons(event
->cm_info
.rem_port
);
3894 cm_event_raddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.rem_addr
);
3896 cm_event
.private_data
= cm_node
->mpa_frame_buf
;
3897 cm_event
.private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3899 nes_debug(NES_DBG_CM
, "call CM_EVENT_MPA_REJECTED, local_addr=%08x, "
3900 "remove_addr=%08x\n",
3901 cm_event_laddr
->sin_addr
.s_addr
,
3902 cm_event_raddr
->sin_addr
.s_addr
);
3904 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3906 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, ret=%d\n",
3907 __func__
, __LINE__
, ret
);
3913 static void nes_cm_event_handler(struct work_struct
*);
3917 * post an event to the cm event handler
3919 static int nes_cm_post_event(struct nes_cm_event
*event
)
3921 atomic_inc(&event
->cm_node
->cm_core
->events_posted
);
3922 add_ref_cm_node(event
->cm_node
);
3923 event
->cm_info
.cm_id
->add_ref(event
->cm_info
.cm_id
);
3924 INIT_WORK(&event
->event_work
, nes_cm_event_handler
);
3925 nes_debug(NES_DBG_CM
, "cm_node=%p queue_work, event=%p\n",
3926 event
->cm_node
, event
);
3928 queue_work(event
->cm_node
->cm_core
->event_wq
, &event
->event_work
);
3930 nes_debug(NES_DBG_CM
, "Exit\n");
3936 * nes_cm_event_handler
3937 * worker function to handle cm events
3938 * will free instance of nes_cm_event
3940 static void nes_cm_event_handler(struct work_struct
*work
)
3942 struct nes_cm_event
*event
= container_of(work
, struct nes_cm_event
,
3944 struct nes_cm_core
*cm_core
;
3946 if ((!event
) || (!event
->cm_node
) || (!event
->cm_node
->cm_core
))
3949 cm_core
= event
->cm_node
->cm_core
;
3950 nes_debug(NES_DBG_CM
, "event=%p, event->type=%u, events posted=%u\n",
3951 event
, event
->type
, atomic_read(&cm_core
->events_posted
));
3953 switch (event
->type
) {
3954 case NES_CM_EVENT_MPA_REQ
:
3955 cm_event_mpa_req(event
);
3956 nes_debug(NES_DBG_CM
, "cm_node=%p CM Event: MPA REQUEST\n",
3959 case NES_CM_EVENT_RESET
:
3960 nes_debug(NES_DBG_CM
, "cm_node = %p CM Event: RESET\n",
3962 cm_event_reset(event
);
3964 case NES_CM_EVENT_CONNECTED
:
3965 if ((!event
->cm_node
->cm_id
) ||
3966 (event
->cm_node
->state
!= NES_CM_STATE_TSA
))
3968 cm_event_connected(event
);
3969 nes_debug(NES_DBG_CM
, "CM Event: CONNECTED\n");
3971 case NES_CM_EVENT_MPA_REJECT
:
3972 if ((!event
->cm_node
->cm_id
) ||
3973 (event
->cm_node
->state
== NES_CM_STATE_TSA
))
3975 cm_event_mpa_reject(event
);
3976 nes_debug(NES_DBG_CM
, "CM Event: REJECT\n");
3979 case NES_CM_EVENT_ABORTED
:
3980 if ((!event
->cm_node
->cm_id
) ||
3981 (event
->cm_node
->state
== NES_CM_STATE_TSA
))
3983 cm_event_connect_error(event
);
3984 nes_debug(NES_DBG_CM
, "CM Event: ABORTED\n");
3986 case NES_CM_EVENT_DROPPED_PKT
:
3987 nes_debug(NES_DBG_CM
, "CM Event: DROPPED PKT\n");
3990 nes_debug(NES_DBG_CM
, "CM Event: UNKNOWN EVENT TYPE\n");
3994 atomic_dec(&cm_core
->events_posted
);
3995 event
->cm_info
.cm_id
->rem_ref(event
->cm_info
.cm_id
);
3996 rem_ref_cm_node(cm_core
, event
->cm_node
);