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
= {
138 .accelerated
= mini_cm_accelerated
,
139 .listen
= mini_cm_listen
,
140 .stop_listener
= mini_cm_del_listen
,
141 .connect
= mini_cm_connect
,
142 .close
= mini_cm_close
,
143 .accept
= mini_cm_accept
,
144 .reject
= mini_cm_reject
,
145 .recv_pkt
= mini_cm_recv_pkt
,
146 .destroy_cm_core
= 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
;
615 case MPA_KEY_REQUEST
:
616 ctrl_ord
|= IETF_RDMA0_WRITE
;
617 ctrl_ord
|= IETF_RDMA0_READ
;
620 switch (cm_node
->send_rdma0_op
) {
621 case SEND_RDMA_WRITE_ZERO
:
622 ctrl_ord
|= IETF_RDMA0_WRITE
;
624 case SEND_RDMA_READ_ZERO
:
625 ctrl_ord
|= IETF_RDMA0_READ
;
629 rtr_msg
->ctrl_ird
= htons(ctrl_ird
);
630 rtr_msg
->ctrl_ord
= htons(ctrl_ord
);
634 * build_mpa_v1 - build a MPA V1 frame
636 static void build_mpa_v1(struct nes_cm_node
*cm_node
, void *start_addr
, u8 mpa_key
)
638 struct ietf_mpa_v1
*mpa_frame
= (struct ietf_mpa_v1
*)start_addr
;
641 case MPA_KEY_REQUEST
:
642 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
);
645 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
);
648 mpa_frame
->flags
= IETF_MPA_FLAGS_CRC
;
649 mpa_frame
->rev
= cm_node
->mpa_frame_rev
;
650 mpa_frame
->priv_data_len
= htons(cm_node
->mpa_frame_size
);
653 static void build_rdma0_msg(struct nes_cm_node
*cm_node
, struct nes_qp
**nesqp_addr
)
656 struct nes_qp
*nesqp
= *nesqp_addr
;
657 struct nes_hw_qp_wqe
*wqe
= &nesqp
->hwqp
.sq_vbase
[0];
659 u64temp
= (unsigned long)nesqp
->nesuqp_addr
;
660 u64temp
|= NES_SW_CONTEXT_ALIGN
>> 1;
661 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
, u64temp
);
663 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
] = 0;
664 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX
] = 0;
666 switch (cm_node
->send_rdma0_op
) {
667 case SEND_RDMA_WRITE_ZERO
:
668 nes_debug(NES_DBG_CM
, "Sending first write.\n");
669 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
670 cpu_to_le32(NES_IWARP_SQ_OP_RDMAW
);
671 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] = 0;
672 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] = 0;
673 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 0;
676 case SEND_RDMA_READ_ZERO
:
678 if (cm_node
->send_rdma0_op
!= SEND_RDMA_READ_ZERO
)
679 WARN(1, "Unsupported RDMA0 len operation=%u\n",
680 cm_node
->send_rdma0_op
);
681 nes_debug(NES_DBG_CM
, "Sending first rdma operation.\n");
682 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
683 cpu_to_le32(NES_IWARP_SQ_OP_RDMAR
);
684 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX
] = 1;
685 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_TO_HIGH_IDX
] = 0;
686 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX
] = 0;
687 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_STAG_IDX
] = 1;
688 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 1;
692 if (nesqp
->sq_kmapped
) {
693 nesqp
->sq_kmapped
= 0;
697 /*use the reserved spot on the WQ for the extra first WQE*/
698 nesqp
->nesqp_context
->ird_ord_sizes
&= cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
699 NES_QPCONTEXT_ORDIRD_WRPDU
|
700 NES_QPCONTEXT_ORDIRD_ALSMM
));
701 nesqp
->skip_lsmm
= 1;
702 nesqp
->hwqp
.sq_tail
= 0;
707 * note - cm_node needs to be protected before calling this. Encase in:
708 * rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
710 int schedule_nes_timer(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
711 enum nes_timer_type type
, int send_retrans
,
712 int close_when_complete
)
715 struct nes_cm_core
*cm_core
= cm_node
->cm_core
;
716 struct nes_timer_entry
*new_send
;
719 new_send
= kzalloc(sizeof(*new_send
), GFP_ATOMIC
);
723 /* new_send->timetosend = currenttime */
724 new_send
->retrycount
= NES_DEFAULT_RETRYS
;
725 new_send
->retranscount
= NES_DEFAULT_RETRANS
;
727 new_send
->timetosend
= jiffies
;
728 new_send
->type
= type
;
729 new_send
->netdev
= cm_node
->netdev
;
730 new_send
->send_retrans
= send_retrans
;
731 new_send
->close_when_complete
= close_when_complete
;
733 if (type
== NES_TIMER_TYPE_CLOSE
) {
734 new_send
->timetosend
+= (HZ
/ 10);
735 if (cm_node
->recv_entry
) {
740 cm_node
->recv_entry
= new_send
;
743 if (type
== NES_TIMER_TYPE_SEND
) {
744 new_send
->seq_num
= ntohl(tcp_hdr(skb
)->seq
);
745 refcount_inc(&new_send
->skb
->users
);
746 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
747 cm_node
->send_entry
= new_send
;
748 add_ref_cm_node(cm_node
);
749 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
750 new_send
->timetosend
= jiffies
+ NES_RETRY_TIMEOUT
;
752 ret
= nes_nic_cm_xmit(new_send
->skb
, cm_node
->netdev
);
753 if (ret
!= NETDEV_TX_OK
) {
754 nes_debug(NES_DBG_CM
, "Error sending packet %p "
755 "(jiffies = %lu)\n", new_send
, jiffies
);
756 new_send
->timetosend
= jiffies
;
761 cleanup_retrans_entry(cm_node
);
762 if (close_when_complete
)
763 rem_ref_cm_node(cm_core
, cm_node
);
769 if (!timer_pending(&cm_core
->tcp_timer
))
770 mod_timer(&cm_core
->tcp_timer
, new_send
->timetosend
);
775 static void nes_retrans_expired(struct nes_cm_node
*cm_node
)
777 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
778 enum nes_cm_node_state state
= cm_node
->state
;
779 cm_node
->state
= NES_CM_STATE_CLOSED
;
782 case NES_CM_STATE_SYN_RCVD
:
783 case NES_CM_STATE_CLOSING
:
784 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
786 case NES_CM_STATE_LAST_ACK
:
787 case NES_CM_STATE_FIN_WAIT1
:
789 cm_id
->rem_ref(cm_id
);
790 send_reset(cm_node
, NULL
);
793 add_ref_cm_node(cm_node
);
794 send_reset(cm_node
, NULL
);
795 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
799 static void handle_recv_entry(struct nes_cm_node
*cm_node
, u32 rem_node
)
801 struct nes_timer_entry
*recv_entry
= cm_node
->recv_entry
;
802 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
803 struct nes_qp
*nesqp
;
804 unsigned long qplockflags
;
808 nesqp
= (struct nes_qp
*)recv_entry
->skb
;
810 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
812 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, "
813 "refcount = %d: HIT A "
814 "NES_TIMER_TYPE_CLOSE with something "
815 "to do!!!\n", nesqp
->hwqp
.qp_id
, cm_id
,
816 atomic_read(&nesqp
->refcount
));
817 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
818 nesqp
->last_aeq
= NES_AEQE_AEID_RESET_SENT
;
819 nesqp
->ibqp_state
= IB_QPS_ERR
;
820 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
821 nes_cm_disconn(nesqp
);
823 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
824 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, "
825 "refcount = %d: HIT A "
826 "NES_TIMER_TYPE_CLOSE with nothing "
827 "to do!!!\n", nesqp
->hwqp
.qp_id
, cm_id
,
828 atomic_read(&nesqp
->refcount
));
830 } else if (rem_node
) {
831 /* TIME_WAIT state */
832 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
835 cm_id
->rem_ref(cm_id
);
837 cm_node
->recv_entry
= NULL
;
843 static void nes_cm_timer_tick(struct timer_list
*unused
)
846 unsigned long nexttimeout
= jiffies
+ NES_LONG_TIME
;
847 struct nes_cm_node
*cm_node
;
848 struct nes_timer_entry
*send_entry
, *recv_entry
;
849 struct list_head
*list_core_temp
;
850 struct list_head
*list_node
;
851 struct nes_cm_core
*cm_core
= g_cm_core
;
853 unsigned long timetosend
;
854 int ret
= NETDEV_TX_OK
;
856 struct list_head timer_list
;
858 INIT_LIST_HEAD(&timer_list
);
859 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
861 list_for_each_safe(list_node
, list_core_temp
,
862 &cm_core
->connected_nodes
) {
863 cm_node
= container_of(list_node
, struct nes_cm_node
, list
);
864 if ((cm_node
->recv_entry
) || (cm_node
->send_entry
)) {
865 add_ref_cm_node(cm_node
);
866 list_add(&cm_node
->timer_entry
, &timer_list
);
869 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
871 list_for_each_safe(list_node
, list_core_temp
, &timer_list
) {
872 cm_node
= container_of(list_node
, struct nes_cm_node
,
874 recv_entry
= cm_node
->recv_entry
;
877 if (time_after(recv_entry
->timetosend
, jiffies
)) {
878 if (nexttimeout
> recv_entry
->timetosend
||
880 nexttimeout
= recv_entry
->timetosend
;
884 handle_recv_entry(cm_node
, 1);
888 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
890 send_entry
= cm_node
->send_entry
;
893 if (time_after(send_entry
->timetosend
, jiffies
)) {
894 if (cm_node
->state
!= NES_CM_STATE_TSA
) {
896 send_entry
->timetosend
) ||
899 send_entry
->timetosend
;
903 free_retrans_entry(cm_node
);
908 if ((cm_node
->state
== NES_CM_STATE_TSA
) ||
909 (cm_node
->state
== NES_CM_STATE_CLOSED
)) {
910 free_retrans_entry(cm_node
);
914 if (!send_entry
->retranscount
||
915 !send_entry
->retrycount
) {
916 cm_packets_dropped
++;
917 free_retrans_entry(cm_node
);
919 spin_unlock_irqrestore(
920 &cm_node
->retrans_list_lock
, flags
);
921 nes_retrans_expired(cm_node
);
922 cm_node
->state
= NES_CM_STATE_CLOSED
;
923 spin_lock_irqsave(&cm_node
->retrans_list_lock
,
927 refcount_inc(&send_entry
->skb
->users
);
928 cm_packets_retrans
++;
929 nes_debug(NES_DBG_CM
, "Retransmitting send_entry %p "
930 "for node %p, jiffies = %lu, time to send = "
931 "%lu, retranscount = %u, send_entry->seq_num = "
932 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
933 "0x%08X\n", send_entry
, cm_node
, jiffies
,
934 send_entry
->timetosend
,
935 send_entry
->retranscount
,
937 cm_node
->tcp_cntxt
.rem_ack_num
);
939 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
,
941 ret
= nes_nic_cm_xmit(send_entry
->skb
, cm_node
->netdev
);
942 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
943 if (ret
!= NETDEV_TX_OK
) {
944 nes_debug(NES_DBG_CM
, "rexmit failed for "
945 "node=%p\n", cm_node
);
946 cm_packets_bounced
++;
947 send_entry
->retrycount
--;
948 nexttimeout
= jiffies
+ NES_SHORT_TIME
;
954 nes_debug(NES_DBG_CM
, "Packet Sent: retrans count = "
955 "%u, retry count = %u.\n",
956 send_entry
->retranscount
,
957 send_entry
->retrycount
);
958 if (send_entry
->send_retrans
) {
959 send_entry
->retranscount
--;
960 timetosend
= (NES_RETRY_TIMEOUT
<<
961 (NES_DEFAULT_RETRANS
- send_entry
->retranscount
));
963 send_entry
->timetosend
= jiffies
+
964 min(timetosend
, NES_MAX_TIMEOUT
);
965 if (nexttimeout
> send_entry
->timetosend
||
967 nexttimeout
= send_entry
->timetosend
;
971 int close_when_complete
;
972 close_when_complete
=
973 send_entry
->close_when_complete
;
974 nes_debug(NES_DBG_CM
, "cm_node=%p state=%d\n",
975 cm_node
, cm_node
->state
);
976 free_retrans_entry(cm_node
);
977 if (close_when_complete
)
978 rem_ref_cm_node(cm_node
->cm_core
,
983 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
984 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
988 if (!timer_pending(&cm_core
->tcp_timer
))
989 mod_timer(&cm_core
->tcp_timer
, nexttimeout
);
997 static int send_syn(struct nes_cm_node
*cm_node
, u32 sendack
,
1001 int flags
= SET_SYN
;
1002 char optionsbuffer
[sizeof(struct option_mss
) +
1003 sizeof(struct option_windowscale
) + sizeof(struct option_base
) +
1004 TCP_OPTIONS_PADDING
];
1006 int optionssize
= 0;
1007 /* Sending MSS option */
1008 union all_known_options
*options
;
1013 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1014 options
->as_mss
.optionnum
= OPTION_NUMBER_MSS
;
1015 options
->as_mss
.length
= sizeof(struct option_mss
);
1016 options
->as_mss
.mss
= htons(cm_node
->tcp_cntxt
.mss
);
1017 optionssize
+= sizeof(struct option_mss
);
1019 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1020 options
->as_windowscale
.optionnum
= OPTION_NUMBER_WINDOW_SCALE
;
1021 options
->as_windowscale
.length
= sizeof(struct option_windowscale
);
1022 options
->as_windowscale
.shiftcount
= cm_node
->tcp_cntxt
.rcv_wscale
;
1023 optionssize
+= sizeof(struct option_windowscale
);
1025 if (sendack
&& !(NES_DRV_OPT_SUPRESS_OPTION_BC
& nes_drv_opt
)) {
1026 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1027 options
->as_base
.optionnum
= OPTION_NUMBER_WRITE0
;
1028 options
->as_base
.length
= sizeof(struct option_base
);
1029 optionssize
+= sizeof(struct option_base
);
1030 /* we need the size to be a multiple of 4 */
1031 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1032 options
->as_end
= 1;
1034 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1035 options
->as_end
= 1;
1039 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1040 options
->as_end
= OPTION_NUMBER_END
;
1044 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1046 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1053 form_cm_frame(skb
, cm_node
, optionsbuffer
, optionssize
, NULL
, 0, flags
);
1054 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
1063 static int send_reset(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1066 int flags
= SET_RST
| SET_ACK
;
1069 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1071 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1075 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, flags
);
1076 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 1);
1085 static int send_ack(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1090 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1093 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1097 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
);
1098 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 0);
1107 static int send_fin(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1111 /* if we didn't get a frame get one */
1113 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1116 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1120 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
| SET_FIN
);
1121 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
1128 * find_node - find a cm node that matches the reference cm node
1130 static struct nes_cm_node
*find_node(struct nes_cm_core
*cm_core
,
1131 u16 rem_port
, nes_addr_t rem_addr
, u16 loc_port
, nes_addr_t loc_addr
)
1133 unsigned long flags
;
1134 struct list_head
*hte
;
1135 struct nes_cm_node
*cm_node
;
1137 /* get a handle on the hte */
1138 hte
= &cm_core
->connected_nodes
;
1140 /* walk list and find cm_node associated with this session ID */
1141 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1142 list_for_each_entry(cm_node
, hte
, list
) {
1143 /* compare quad, return node handle if a match */
1144 nes_debug(NES_DBG_CM
, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
1145 cm_node
->loc_addr
, cm_node
->loc_port
,
1147 cm_node
->rem_addr
, cm_node
->rem_port
,
1148 rem_addr
, rem_port
);
1149 if ((cm_node
->loc_addr
== loc_addr
) &&
1150 (cm_node
->loc_port
== loc_port
) &&
1151 (cm_node
->rem_addr
== rem_addr
) &&
1152 (cm_node
->rem_port
== rem_port
)) {
1153 add_ref_cm_node(cm_node
);
1154 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1158 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1166 * find_listener - find a cm node listening on this addr-port pair
1168 static struct nes_cm_listener
*find_listener(struct nes_cm_core
*cm_core
,
1169 nes_addr_t dst_addr
, u16 dst_port
,
1170 enum nes_cm_listener_state listener_state
)
1172 unsigned long flags
;
1173 struct nes_cm_listener
*listen_node
;
1174 nes_addr_t listen_addr
;
1177 /* walk list and find cm_node associated with this session ID */
1178 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1179 list_for_each_entry(listen_node
, &cm_core
->listen_list
.list
, list
) {
1180 listen_addr
= listen_node
->loc_addr
;
1181 listen_port
= listen_node
->loc_port
;
1183 /* compare node pair, return node handle if a match */
1184 if (((listen_addr
== dst_addr
) ||
1185 listen_addr
== 0x00000000) &&
1186 (listen_port
== dst_port
) &&
1187 (listener_state
& listen_node
->listener_state
)) {
1188 atomic_inc(&listen_node
->ref_count
);
1189 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1193 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1200 * add_hte_node - add a cm node to the hash table
1202 static int add_hte_node(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
1204 unsigned long flags
;
1205 struct list_head
*hte
;
1207 if (!cm_node
|| !cm_core
)
1210 nes_debug(NES_DBG_CM
, "Adding Node %p to Active Connection HT\n",
1213 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1215 /* get a handle on the hash table element (list head for this slot) */
1216 hte
= &cm_core
->connected_nodes
;
1217 list_add_tail(&cm_node
->list
, hte
);
1218 atomic_inc(&cm_core
->ht_node_cnt
);
1220 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1227 * mini_cm_dec_refcnt_listen
1229 static int mini_cm_dec_refcnt_listen(struct nes_cm_core
*cm_core
,
1230 struct nes_cm_listener
*listener
, int free_hanging_nodes
)
1234 unsigned long flags
;
1235 struct list_head
*list_pos
= NULL
;
1236 struct list_head
*list_temp
= NULL
;
1237 struct nes_cm_node
*cm_node
= NULL
;
1238 struct list_head reset_list
;
1240 nes_debug(NES_DBG_CM
, "attempting listener= %p free_nodes= %d, "
1241 "refcnt=%d\n", listener
, free_hanging_nodes
,
1242 atomic_read(&listener
->ref_count
));
1243 /* free non-accelerated child nodes for this listener */
1244 INIT_LIST_HEAD(&reset_list
);
1245 if (free_hanging_nodes
) {
1246 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1247 list_for_each_safe(list_pos
, list_temp
,
1248 &g_cm_core
->connected_nodes
) {
1249 cm_node
= container_of(list_pos
, struct nes_cm_node
,
1251 if ((cm_node
->listener
== listener
) &&
1252 (!cm_node
->accelerated
)) {
1253 add_ref_cm_node(cm_node
);
1254 list_add(&cm_node
->reset_entry
, &reset_list
);
1257 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1260 list_for_each_safe(list_pos
, list_temp
, &reset_list
) {
1261 cm_node
= container_of(list_pos
, struct nes_cm_node
,
1264 struct nes_cm_node
*loopback
= cm_node
->loopbackpartner
;
1265 enum nes_cm_node_state old_state
;
1266 if (NES_CM_STATE_FIN_WAIT1
<= cm_node
->state
) {
1267 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1270 cleanup_retrans_entry(cm_node
);
1271 err
= send_reset(cm_node
, NULL
);
1274 NES_CM_STATE_CLOSED
;
1277 old_state
= cm_node
->state
;
1278 cm_node
->state
= NES_CM_STATE_LISTENER_DESTROYED
;
1279 if (old_state
!= NES_CM_STATE_MPAREQ_RCVD
)
1285 struct nes_cm_event event
;
1287 event
.cm_node
= loopback
;
1288 event
.cm_info
.rem_addr
=
1290 event
.cm_info
.loc_addr
=
1292 event
.cm_info
.rem_port
=
1294 event
.cm_info
.loc_port
=
1296 event
.cm_info
.cm_id
= loopback
->cm_id
;
1297 add_ref_cm_node(loopback
);
1298 loopback
->state
= NES_CM_STATE_CLOSED
;
1299 cm_event_connect_error(&event
);
1300 cm_node
->state
= NES_CM_STATE_LISTENER_DESTROYED
;
1302 rem_ref_cm_node(cm_node
->cm_core
,
1310 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1311 if (!atomic_dec_return(&listener
->ref_count
)) {
1312 list_del(&listener
->list
);
1314 /* decrement our listen node count */
1315 atomic_dec(&cm_core
->listen_node_cnt
);
1317 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1319 if (listener
->nesvnic
) {
1320 nes_manage_apbvt(listener
->nesvnic
,
1322 PCI_FUNC(listener
->nesvnic
->nesdev
->pcidev
->devfn
),
1323 NES_MANAGE_APBVT_DEL
);
1325 nes_debug(NES_DBG_NLMSG
,
1326 "Delete APBVT loc_port = %04X\n",
1327 listener
->loc_port
);
1330 nes_debug(NES_DBG_CM
, "destroying listener (%p)\n", listener
);
1335 atomic_inc(&cm_listens_destroyed
);
1337 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1340 if (atomic_read(&listener
->pend_accepts_cnt
) > 0)
1341 nes_debug(NES_DBG_CM
, "destroying listener (%p)"
1342 " with non-zero pending accepts=%u\n",
1343 listener
, atomic_read(&listener
->pend_accepts_cnt
));
1351 * mini_cm_del_listen
1353 static int mini_cm_del_listen(struct nes_cm_core
*cm_core
,
1354 struct nes_cm_listener
*listener
)
1356 listener
->listener_state
= NES_CM_LISTENER_PASSIVE_STATE
;
1357 listener
->cm_id
= NULL
; /* going to be destroyed pretty soon */
1358 return mini_cm_dec_refcnt_listen(cm_core
, listener
, 1);
1363 * mini_cm_accelerated
1365 static inline int mini_cm_accelerated(struct nes_cm_core
*cm_core
,
1366 struct nes_cm_node
*cm_node
)
1368 cm_node
->accelerated
= true;
1370 if (cm_node
->accept_pend
) {
1371 BUG_ON(!cm_node
->listener
);
1372 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1373 cm_node
->accept_pend
= 0;
1374 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1377 if (!timer_pending(&cm_core
->tcp_timer
))
1378 mod_timer(&cm_core
->tcp_timer
, (jiffies
+ NES_SHORT_TIME
));
1385 * nes_addr_resolve_neigh
1387 static int nes_addr_resolve_neigh(struct nes_vnic
*nesvnic
, u32 dst_ip
, int arpindex
)
1390 struct neighbour
*neigh
;
1392 struct nes_adapter
*nesadapter
= nesvnic
->nesdev
->nesadapter
;
1393 __be32 dst_ipaddr
= htonl(dst_ip
);
1395 rt
= ip_route_output(&init_net
, dst_ipaddr
, nesvnic
->local_ipaddr
, 0, 0);
1397 printk(KERN_ERR
"%s: ip_route_output_key failed for 0x%08X\n",
1402 neigh
= dst_neigh_lookup(&rt
->dst
, &dst_ipaddr
);
1406 if (neigh
->nud_state
& NUD_VALID
) {
1407 nes_debug(NES_DBG_CM
, "Neighbor MAC address for 0x%08X"
1408 " is %pM, Gateway is 0x%08X \n", dst_ip
,
1409 neigh
->ha
, ntohl(rt
->rt_gateway
));
1411 if (arpindex
>= 0) {
1412 if (ether_addr_equal(nesadapter
->arp_table
[arpindex
].mac_addr
, neigh
->ha
)) {
1413 /* Mac address same as in nes_arp_table */
1417 nes_manage_arp_cache(nesvnic
->netdev
,
1418 nesadapter
->arp_table
[arpindex
].mac_addr
,
1419 dst_ip
, NES_ARP_DELETE
);
1422 nes_manage_arp_cache(nesvnic
->netdev
, neigh
->ha
,
1423 dst_ip
, NES_ARP_ADD
);
1424 rc
= nes_arp_table(nesvnic
->nesdev
, dst_ip
, NULL
,
1427 neigh_event_send(neigh
, NULL
);
1434 neigh_release(neigh
);
1441 * make_cm_node - create a new instance of a cm node
1443 static struct nes_cm_node
*make_cm_node(struct nes_cm_core
*cm_core
,
1444 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
,
1445 struct nes_cm_listener
*listener
)
1447 struct nes_cm_node
*cm_node
;
1449 int oldarpindex
= 0;
1451 struct nes_device
*nesdev
;
1452 struct nes_adapter
*nesadapter
;
1454 /* create an hte and cm_node for this instance */
1455 cm_node
= kzalloc(sizeof(*cm_node
), GFP_ATOMIC
);
1459 /* set our node specific transport info */
1461 cm_node
->loc_addr
= listener
->loc_addr
;
1462 cm_node
->loc_port
= listener
->loc_port
;
1464 cm_node
->loc_addr
= cm_info
->loc_addr
;
1465 cm_node
->loc_port
= cm_info
->loc_port
;
1467 cm_node
->rem_addr
= cm_info
->rem_addr
;
1468 cm_node
->rem_port
= cm_info
->rem_port
;
1470 cm_node
->mpa_frame_rev
= mpa_version
;
1471 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
1472 cm_node
->mpav2_ird_ord
= 0;
1473 cm_node
->ird_size
= 0;
1474 cm_node
->ord_size
= 0;
1476 nes_debug(NES_DBG_CM
, "Make node addresses : loc = %pI4:%x, rem = %pI4:%x\n",
1477 &cm_node
->loc_addr
, cm_node
->loc_port
,
1478 &cm_node
->rem_addr
, cm_node
->rem_port
);
1479 cm_node
->listener
= listener
;
1481 cm_node
->tos
= listener
->tos
;
1482 cm_node
->netdev
= nesvnic
->netdev
;
1483 cm_node
->cm_id
= cm_info
->cm_id
;
1484 memcpy(cm_node
->loc_mac
, nesvnic
->netdev
->dev_addr
, ETH_ALEN
);
1486 nes_debug(NES_DBG_CM
, "listener=%p, cm_id=%p\n", cm_node
->listener
,
1489 spin_lock_init(&cm_node
->retrans_list_lock
);
1491 cm_node
->loopbackpartner
= NULL
;
1492 atomic_set(&cm_node
->ref_count
, 1);
1493 /* associate our parent CM core */
1494 cm_node
->cm_core
= cm_core
;
1495 cm_node
->tcp_cntxt
.loc_id
= NES_CM_DEF_LOCAL_ID
;
1496 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
1497 cm_node
->tcp_cntxt
.rcv_wnd
= NES_CM_DEFAULT_RCV_WND_SCALED
>>
1498 NES_CM_DEFAULT_RCV_WND_SCALE
;
1499 ts
= current_kernel_time();
1500 cm_node
->tcp_cntxt
.loc_seq_num
= htonl(ts
.tv_nsec
);
1501 cm_node
->tcp_cntxt
.mss
= nesvnic
->max_frame_size
- sizeof(struct iphdr
) -
1502 sizeof(struct tcphdr
) - ETH_HLEN
- VLAN_HLEN
;
1503 cm_node
->tcp_cntxt
.rcv_nxt
= 0;
1504 /* get a unique session ID , add thread_id to an upcounter to handle race */
1505 atomic_inc(&cm_core
->node_cnt
);
1506 cm_node
->conn_type
= cm_info
->conn_type
;
1507 cm_node
->apbvt_set
= 0;
1508 cm_node
->accept_pend
= 0;
1510 cm_node
->nesvnic
= nesvnic
;
1511 /* get some device handles, for arp lookup */
1512 nesdev
= nesvnic
->nesdev
;
1513 nesadapter
= nesdev
->nesadapter
;
1515 cm_node
->loopbackpartner
= NULL
;
1517 /* get the mac addr for the remote node */
1518 oldarpindex
= nes_arp_table(nesdev
, cm_node
->rem_addr
,
1519 NULL
, NES_ARP_RESOLVE
);
1520 arpindex
= nes_addr_resolve_neigh(nesvnic
, cm_node
->rem_addr
,
1527 /* copy the mac addr to node context */
1528 memcpy(cm_node
->rem_mac
, nesadapter
->arp_table
[arpindex
].mac_addr
, ETH_ALEN
);
1529 nes_debug(NES_DBG_CM
, "Remote mac addr from arp table: %pM\n",
1532 add_hte_node(cm_core
, cm_node
);
1533 atomic_inc(&cm_nodes_created
);
1540 * add_ref_cm_node - destroy an instance of a cm node
1542 static int add_ref_cm_node(struct nes_cm_node
*cm_node
)
1544 atomic_inc(&cm_node
->ref_count
);
1550 * rem_ref_cm_node - destroy an instance of a cm node
1552 static int rem_ref_cm_node(struct nes_cm_core
*cm_core
,
1553 struct nes_cm_node
*cm_node
)
1555 unsigned long flags
;
1556 struct nes_qp
*nesqp
;
1561 spin_lock_irqsave(&cm_node
->cm_core
->ht_lock
, flags
);
1562 if (atomic_dec_return(&cm_node
->ref_count
)) {
1563 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1566 list_del(&cm_node
->list
);
1567 atomic_dec(&cm_core
->ht_node_cnt
);
1568 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1570 /* if the node is destroyed before connection was accelerated */
1571 if (!cm_node
->accelerated
&& cm_node
->accept_pend
) {
1572 BUG_ON(!cm_node
->listener
);
1573 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1574 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1576 WARN_ON(cm_node
->send_entry
);
1577 if (cm_node
->recv_entry
)
1578 handle_recv_entry(cm_node
, 0);
1579 if (cm_node
->listener
) {
1580 mini_cm_dec_refcnt_listen(cm_core
, cm_node
->listener
, 0);
1582 if (cm_node
->apbvt_set
&& cm_node
->nesvnic
) {
1583 nes_manage_apbvt(cm_node
->nesvnic
, cm_node
->loc_port
,
1584 PCI_FUNC(cm_node
->nesvnic
->nesdev
->pcidev
->devfn
),
1585 NES_MANAGE_APBVT_DEL
);
1587 nes_debug(NES_DBG_NLMSG
, "Delete APBVT loc_port = %04X\n",
1591 atomic_dec(&cm_core
->node_cnt
);
1592 atomic_inc(&cm_nodes_destroyed
);
1593 nesqp
= cm_node
->nesqp
;
1595 nesqp
->cm_node
= NULL
;
1596 nes_rem_ref(&nesqp
->ibqp
);
1597 cm_node
->nesqp
= NULL
;
1607 static int process_options(struct nes_cm_node
*cm_node
, u8
*optionsloc
,
1608 u32 optionsize
, u32 syn_packet
)
1612 union all_known_options
*all_options
;
1613 char got_mss_option
= 0;
1615 while (offset
< optionsize
) {
1616 all_options
= (union all_known_options
*)(optionsloc
+ offset
);
1617 switch (all_options
->as_base
.optionnum
) {
1618 case OPTION_NUMBER_END
:
1619 offset
= optionsize
;
1621 case OPTION_NUMBER_NONE
:
1624 case OPTION_NUMBER_MSS
:
1625 nes_debug(NES_DBG_CM
, "%s: MSS Length: %d Offset: %d "
1626 "Size: %d\n", __func__
,
1627 all_options
->as_mss
.length
, offset
, optionsize
);
1629 if (all_options
->as_mss
.length
!= 4) {
1632 tmp
= ntohs(all_options
->as_mss
.mss
);
1633 if (tmp
> 0 && tmp
<
1634 cm_node
->tcp_cntxt
.mss
)
1635 cm_node
->tcp_cntxt
.mss
= tmp
;
1638 case OPTION_NUMBER_WINDOW_SCALE
:
1639 cm_node
->tcp_cntxt
.snd_wscale
=
1640 all_options
->as_windowscale
.shiftcount
;
1643 nes_debug(NES_DBG_CM
, "TCP Option not understood: %x\n",
1644 all_options
->as_base
.optionnum
);
1647 offset
+= all_options
->as_base
.length
;
1649 if ((!got_mss_option
) && (syn_packet
))
1650 cm_node
->tcp_cntxt
.mss
= NES_CM_DEFAULT_MSS
;
1654 static void drop_packet(struct sk_buff
*skb
)
1656 atomic_inc(&cm_accel_dropped_pkts
);
1657 dev_kfree_skb_any(skb
);
1660 static void handle_fin_pkt(struct nes_cm_node
*cm_node
)
1662 nes_debug(NES_DBG_CM
, "Received FIN, cm_node = %p, state = %u. "
1663 "refcnt=%d\n", cm_node
, cm_node
->state
,
1664 atomic_read(&cm_node
->ref_count
));
1665 switch (cm_node
->state
) {
1666 case NES_CM_STATE_SYN_RCVD
:
1667 case NES_CM_STATE_SYN_SENT
:
1668 case NES_CM_STATE_ESTABLISHED
:
1669 case NES_CM_STATE_MPAREJ_RCVD
:
1670 cm_node
->tcp_cntxt
.rcv_nxt
++;
1671 cleanup_retrans_entry(cm_node
);
1672 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
1673 send_fin(cm_node
, NULL
);
1675 case NES_CM_STATE_MPAREQ_SENT
:
1676 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
1677 cm_node
->tcp_cntxt
.rcv_nxt
++;
1678 cleanup_retrans_entry(cm_node
);
1679 cm_node
->state
= NES_CM_STATE_CLOSED
;
1680 add_ref_cm_node(cm_node
);
1681 send_reset(cm_node
, NULL
);
1683 case NES_CM_STATE_FIN_WAIT1
:
1684 cm_node
->tcp_cntxt
.rcv_nxt
++;
1685 cleanup_retrans_entry(cm_node
);
1686 cm_node
->state
= NES_CM_STATE_CLOSING
;
1687 send_ack(cm_node
, NULL
);
1688 /* Wait for ACK as this is simultaneous close..
1689 * After we receive ACK, do not send anything..
1690 * Just rm the node.. Done.. */
1692 case NES_CM_STATE_FIN_WAIT2
:
1693 cm_node
->tcp_cntxt
.rcv_nxt
++;
1694 cleanup_retrans_entry(cm_node
);
1695 cm_node
->state
= NES_CM_STATE_TIME_WAIT
;
1696 send_ack(cm_node
, NULL
);
1697 schedule_nes_timer(cm_node
, NULL
, NES_TIMER_TYPE_CLOSE
, 1, 0);
1699 case NES_CM_STATE_TIME_WAIT
:
1700 cm_node
->tcp_cntxt
.rcv_nxt
++;
1701 cleanup_retrans_entry(cm_node
);
1702 cm_node
->state
= NES_CM_STATE_CLOSED
;
1703 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1705 case NES_CM_STATE_TSA
:
1707 nes_debug(NES_DBG_CM
, "Error Rcvd FIN for node-%p state = %d\n",
1708 cm_node
, cm_node
->state
);
1714 static void handle_rst_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1715 struct tcphdr
*tcph
)
1718 int reset
= 0; /* whether to send reset in case of err.. */
1719 atomic_inc(&cm_resets_recvd
);
1720 nes_debug(NES_DBG_CM
, "Received Reset, cm_node = %p, state = %u."
1721 " refcnt=%d\n", cm_node
, cm_node
->state
,
1722 atomic_read(&cm_node
->ref_count
));
1723 cleanup_retrans_entry(cm_node
);
1724 switch (cm_node
->state
) {
1725 case NES_CM_STATE_SYN_SENT
:
1726 case NES_CM_STATE_MPAREQ_SENT
:
1727 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1728 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1729 cm_node
->listener
, cm_node
->state
);
1730 switch (cm_node
->mpa_frame_rev
) {
1732 cm_node
->mpa_frame_rev
= IETF_MPA_V1
;
1733 /* send a syn and goto syn sent state */
1734 cm_node
->state
= NES_CM_STATE_SYN_SENT
;
1735 if (send_syn(cm_node
, 0, NULL
)) {
1736 active_open_err(cm_node
, skb
, reset
);
1741 active_open_err(cm_node
, skb
, reset
);
1745 case NES_CM_STATE_MPAREQ_RCVD
:
1746 atomic_inc(&cm_node
->passive_state
);
1747 dev_kfree_skb_any(skb
);
1749 case NES_CM_STATE_ESTABLISHED
:
1750 case NES_CM_STATE_SYN_RCVD
:
1751 case NES_CM_STATE_LISTENING
:
1752 nes_debug(NES_DBG_CM
, "Bad state %s[%u]\n", __func__
, __LINE__
);
1753 passive_open_err(cm_node
, skb
, reset
);
1755 case NES_CM_STATE_TSA
:
1756 active_open_err(cm_node
, skb
, reset
);
1758 case NES_CM_STATE_CLOSED
:
1761 case NES_CM_STATE_FIN_WAIT2
:
1762 case NES_CM_STATE_FIN_WAIT1
:
1763 case NES_CM_STATE_LAST_ACK
:
1764 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
1766 case NES_CM_STATE_TIME_WAIT
:
1767 cm_node
->state
= NES_CM_STATE_CLOSED
;
1768 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1778 static void handle_rcv_mpa(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1781 int datasize
= skb
->len
;
1782 u8
*dataloc
= skb
->data
;
1784 enum nes_cm_event_type type
= NES_CM_EVENT_UNKNOWN
;
1787 ret
= parse_mpa(cm_node
, dataloc
, &res_type
, datasize
);
1789 nes_debug(NES_DBG_CM
, "didn't like MPA Request\n");
1790 if (cm_node
->state
== NES_CM_STATE_MPAREQ_SENT
) {
1791 nes_debug(NES_DBG_CM
, "%s[%u] create abort for "
1792 "cm_node=%p listener=%p state=%d\n", __func__
,
1793 __LINE__
, cm_node
, cm_node
->listener
,
1795 active_open_err(cm_node
, skb
, 1);
1797 passive_open_err(cm_node
, skb
, 1);
1802 switch (cm_node
->state
) {
1803 case NES_CM_STATE_ESTABLISHED
:
1804 if (res_type
== NES_MPA_REQUEST_REJECT
)
1805 /*BIG problem as we are receiving the MPA.. So should
1806 * not be REJECT.. This is Passive Open.. We can
1807 * only receive it Reject for Active Open...*/
1809 cm_node
->state
= NES_CM_STATE_MPAREQ_RCVD
;
1810 type
= NES_CM_EVENT_MPA_REQ
;
1811 atomic_set(&cm_node
->passive_state
,
1812 NES_PASSIVE_STATE_INDICATED
);
1814 case NES_CM_STATE_MPAREQ_SENT
:
1815 cleanup_retrans_entry(cm_node
);
1816 if (res_type
== NES_MPA_REQUEST_REJECT
) {
1817 type
= NES_CM_EVENT_MPA_REJECT
;
1818 cm_node
->state
= NES_CM_STATE_MPAREJ_RCVD
;
1820 type
= NES_CM_EVENT_CONNECTED
;
1821 cm_node
->state
= NES_CM_STATE_TSA
;
1823 send_ack(cm_node
, NULL
);
1829 dev_kfree_skb_any(skb
);
1830 create_event(cm_node
, type
);
1833 static void indicate_pkt_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1835 switch (cm_node
->state
) {
1836 case NES_CM_STATE_SYN_SENT
:
1837 case NES_CM_STATE_MPAREQ_SENT
:
1838 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1839 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1840 cm_node
->listener
, cm_node
->state
);
1841 active_open_err(cm_node
, skb
, 1);
1843 case NES_CM_STATE_ESTABLISHED
:
1844 case NES_CM_STATE_SYN_RCVD
:
1845 passive_open_err(cm_node
, skb
, 1);
1847 case NES_CM_STATE_TSA
:
1853 static int check_syn(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1854 struct sk_buff
*skb
)
1858 err
= ((ntohl(tcph
->ack_seq
) == cm_node
->tcp_cntxt
.loc_seq_num
)) ? 0 : 1;
1860 active_open_err(cm_node
, skb
, 1);
1865 static int check_seq(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1866 struct sk_buff
*skb
)
1871 u32 loc_seq_num
= cm_node
->tcp_cntxt
.loc_seq_num
;
1872 u32 rcv_nxt
= cm_node
->tcp_cntxt
.rcv_nxt
;
1875 seq
= ntohl(tcph
->seq
);
1876 ack_seq
= ntohl(tcph
->ack_seq
);
1877 rcv_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
1878 if (ack_seq
!= loc_seq_num
)
1880 else if (!between(seq
, rcv_nxt
, (rcv_nxt
+ rcv_wnd
)))
1883 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1884 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1885 cm_node
->listener
, cm_node
->state
);
1886 indicate_pkt_err(cm_node
, skb
);
1887 nes_debug(NES_DBG_CM
, "seq ERROR cm_node =%p seq=0x%08X "
1888 "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node
, seq
, rcv_nxt
,
1895 * handle_syn_pkt() is for Passive node. The syn packet is received when a node
1896 * is created with a listener or it may comein as rexmitted packet which in
1897 * that case will be just dropped.
1899 static void handle_syn_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1900 struct tcphdr
*tcph
)
1906 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1908 inc_sequence
= ntohl(tcph
->seq
);
1910 switch (cm_node
->state
) {
1911 case NES_CM_STATE_SYN_SENT
:
1912 case NES_CM_STATE_MPAREQ_SENT
:
1913 /* Rcvd syn on active open connection*/
1914 active_open_err(cm_node
, skb
, 1);
1916 case NES_CM_STATE_LISTENING
:
1918 if (atomic_read(&cm_node
->listener
->pend_accepts_cnt
) >
1919 cm_node
->listener
->backlog
) {
1920 nes_debug(NES_DBG_CM
, "drop syn due to backlog "
1923 passive_open_err(cm_node
, skb
, 0);
1926 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
,
1929 passive_open_err(cm_node
, skb
, 0);
1933 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
1934 BUG_ON(cm_node
->send_entry
);
1935 cm_node
->accept_pend
= 1;
1936 atomic_inc(&cm_node
->listener
->pend_accepts_cnt
);
1938 cm_node
->state
= NES_CM_STATE_SYN_RCVD
;
1939 send_syn(cm_node
, 1, skb
);
1941 case NES_CM_STATE_CLOSED
:
1942 cleanup_retrans_entry(cm_node
);
1943 add_ref_cm_node(cm_node
);
1944 send_reset(cm_node
, skb
);
1946 case NES_CM_STATE_TSA
:
1947 case NES_CM_STATE_ESTABLISHED
:
1948 case NES_CM_STATE_FIN_WAIT1
:
1949 case NES_CM_STATE_FIN_WAIT2
:
1950 case NES_CM_STATE_MPAREQ_RCVD
:
1951 case NES_CM_STATE_LAST_ACK
:
1952 case NES_CM_STATE_CLOSING
:
1953 case NES_CM_STATE_UNKNOWN
:
1960 static void handle_synack_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1961 struct tcphdr
*tcph
)
1967 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1969 inc_sequence
= ntohl(tcph
->seq
);
1970 switch (cm_node
->state
) {
1971 case NES_CM_STATE_SYN_SENT
:
1972 cleanup_retrans_entry(cm_node
);
1974 if (check_syn(cm_node
, tcph
, skb
))
1976 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
1978 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
, 0);
1980 nes_debug(NES_DBG_CM
, "cm_node=%p tcp_options failed\n",
1984 cleanup_retrans_entry(cm_node
);
1985 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
1986 send_mpa_request(cm_node
, skb
);
1987 cm_node
->state
= NES_CM_STATE_MPAREQ_SENT
;
1989 case NES_CM_STATE_MPAREQ_RCVD
:
1990 /* passive open, so should not be here */
1991 passive_open_err(cm_node
, skb
, 1);
1993 case NES_CM_STATE_LISTENING
:
1994 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
1995 cleanup_retrans_entry(cm_node
);
1996 cm_node
->state
= NES_CM_STATE_CLOSED
;
1997 send_reset(cm_node
, skb
);
1999 case NES_CM_STATE_CLOSED
:
2000 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
2001 cleanup_retrans_entry(cm_node
);
2002 add_ref_cm_node(cm_node
);
2003 send_reset(cm_node
, skb
);
2005 case NES_CM_STATE_ESTABLISHED
:
2006 case NES_CM_STATE_FIN_WAIT1
:
2007 case NES_CM_STATE_FIN_WAIT2
:
2008 case NES_CM_STATE_LAST_ACK
:
2009 case NES_CM_STATE_TSA
:
2010 case NES_CM_STATE_CLOSING
:
2011 case NES_CM_STATE_UNKNOWN
:
2012 case NES_CM_STATE_MPAREQ_SENT
:
2019 static int handle_ack_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2020 struct tcphdr
*tcph
)
2027 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
2029 if (check_seq(cm_node
, tcph
, skb
))
2032 skb_pull(skb
, tcph
->doff
<< 2);
2033 inc_sequence
= ntohl(tcph
->seq
);
2034 datasize
= skb
->len
;
2035 switch (cm_node
->state
) {
2036 case NES_CM_STATE_SYN_RCVD
:
2038 cleanup_retrans_entry(cm_node
);
2039 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
, 1);
2042 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2043 cm_node
->state
= NES_CM_STATE_ESTABLISHED
;
2045 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2046 handle_rcv_mpa(cm_node
, skb
);
2047 } else { /* rcvd ACK only */
2048 dev_kfree_skb_any(skb
);
2051 case NES_CM_STATE_ESTABLISHED
:
2053 cleanup_retrans_entry(cm_node
);
2055 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2056 handle_rcv_mpa(cm_node
, skb
);
2061 case NES_CM_STATE_MPAREQ_SENT
:
2062 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2064 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2065 handle_rcv_mpa(cm_node
, skb
);
2066 } else { /* Could be just an ack pkt.. */
2067 dev_kfree_skb_any(skb
);
2070 case NES_CM_STATE_LISTENING
:
2071 cleanup_retrans_entry(cm_node
);
2072 cm_node
->state
= NES_CM_STATE_CLOSED
;
2073 send_reset(cm_node
, skb
);
2075 case NES_CM_STATE_CLOSED
:
2076 cleanup_retrans_entry(cm_node
);
2077 add_ref_cm_node(cm_node
);
2078 send_reset(cm_node
, skb
);
2080 case NES_CM_STATE_LAST_ACK
:
2081 case NES_CM_STATE_CLOSING
:
2082 cleanup_retrans_entry(cm_node
);
2083 cm_node
->state
= NES_CM_STATE_CLOSED
;
2084 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2085 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2088 case NES_CM_STATE_FIN_WAIT1
:
2089 cleanup_retrans_entry(cm_node
);
2091 cm_node
->state
= NES_CM_STATE_FIN_WAIT2
;
2093 case NES_CM_STATE_SYN_SENT
:
2094 case NES_CM_STATE_FIN_WAIT2
:
2095 case NES_CM_STATE_TSA
:
2096 case NES_CM_STATE_MPAREQ_RCVD
:
2097 case NES_CM_STATE_UNKNOWN
:
2099 cleanup_retrans_entry(cm_node
);
2108 static int handle_tcp_options(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
2109 struct sk_buff
*skb
, int optionsize
, int passive
)
2111 u8
*optionsloc
= (u8
*)&tcph
[1];
2114 if (process_options(cm_node
, optionsloc
, optionsize
,
2116 nes_debug(NES_DBG_CM
, "%s: Node %p, Sending RESET\n",
2119 passive_open_err(cm_node
, skb
, 1);
2121 active_open_err(cm_node
, skb
, 1);
2126 cm_node
->tcp_cntxt
.snd_wnd
= ntohs(tcph
->window
) <<
2127 cm_node
->tcp_cntxt
.snd_wscale
;
2129 if (cm_node
->tcp_cntxt
.snd_wnd
> cm_node
->tcp_cntxt
.max_snd_wnd
)
2130 cm_node
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.snd_wnd
;
2135 * active_open_err() will send reset() if flag set..
2136 * It will also send ABORT event.
2138 static void active_open_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2141 cleanup_retrans_entry(cm_node
);
2143 nes_debug(NES_DBG_CM
, "ERROR active err called for cm_node=%p, "
2144 "state=%d\n", cm_node
, cm_node
->state
);
2145 add_ref_cm_node(cm_node
);
2146 send_reset(cm_node
, skb
);
2148 dev_kfree_skb_any(skb
);
2151 cm_node
->state
= NES_CM_STATE_CLOSED
;
2152 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
2156 * passive_open_err() will either do a reset() or will free up the skb and
2157 * remove the cm_node.
2159 static void passive_open_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2162 cleanup_retrans_entry(cm_node
);
2163 cm_node
->state
= NES_CM_STATE_CLOSED
;
2165 nes_debug(NES_DBG_CM
, "passive_open_err sending RST for "
2166 "cm_node=%p state =%d\n", cm_node
, cm_node
->state
);
2167 send_reset(cm_node
, skb
);
2169 dev_kfree_skb_any(skb
);
2170 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2175 * free_retrans_entry() routines assumes that the retrans_list_lock has
2176 * been acquired before calling.
2178 static void free_retrans_entry(struct nes_cm_node
*cm_node
)
2180 struct nes_timer_entry
*send_entry
;
2182 send_entry
= cm_node
->send_entry
;
2184 cm_node
->send_entry
= NULL
;
2185 dev_kfree_skb_any(send_entry
->skb
);
2187 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2191 static void cleanup_retrans_entry(struct nes_cm_node
*cm_node
)
2193 unsigned long flags
;
2195 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
2196 free_retrans_entry(cm_node
);
2197 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
2202 * Returns skb if to be freed, else it will return NULL if already used..
2204 static void process_packet(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2205 struct nes_cm_core
*cm_core
)
2207 enum nes_tcpip_pkt_type pkt_type
= NES_PKT_TYPE_UNKNOWN
;
2208 struct tcphdr
*tcph
= tcp_hdr(skb
);
2212 skb_pull(skb
, ip_hdr(skb
)->ihl
<< 2);
2214 nes_debug(NES_DBG_CM
, "process_packet: cm_node=%p state =%d syn=%d "
2215 "ack=%d rst=%d fin=%d\n", cm_node
, cm_node
->state
, tcph
->syn
,
2216 tcph
->ack
, tcph
->rst
, tcph
->fin
);
2219 pkt_type
= NES_PKT_TYPE_RST
;
2220 } else if (tcph
->syn
) {
2221 pkt_type
= NES_PKT_TYPE_SYN
;
2223 pkt_type
= NES_PKT_TYPE_SYNACK
;
2224 } else if (tcph
->ack
) {
2225 pkt_type
= NES_PKT_TYPE_ACK
;
2231 case NES_PKT_TYPE_SYN
:
2232 handle_syn_pkt(cm_node
, skb
, tcph
);
2234 case NES_PKT_TYPE_SYNACK
:
2235 handle_synack_pkt(cm_node
, skb
, tcph
);
2237 case NES_PKT_TYPE_ACK
:
2238 ret
= handle_ack_pkt(cm_node
, skb
, tcph
);
2239 if (fin_set
&& !ret
)
2240 handle_fin_pkt(cm_node
);
2242 case NES_PKT_TYPE_RST
:
2243 handle_rst_pkt(cm_node
, skb
, tcph
);
2246 if ((fin_set
) && (!check_seq(cm_node
, tcph
, skb
)))
2247 handle_fin_pkt(cm_node
);
2254 * mini_cm_listen - create a listen node with params
2256 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*cm_core
,
2257 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
)
2259 struct nes_cm_listener
*listener
;
2260 unsigned long flags
;
2262 nes_debug(NES_DBG_CM
, "Search for 0x%08x : 0x%04x\n",
2263 cm_info
->loc_addr
, cm_info
->loc_port
);
2265 /* cannot have multiple matching listeners */
2266 listener
= find_listener(cm_core
, cm_info
->loc_addr
, cm_info
->loc_port
,
2267 NES_CM_LISTENER_EITHER_STATE
);
2269 if (listener
&& listener
->listener_state
== NES_CM_LISTENER_ACTIVE_STATE
) {
2270 /* find automatically incs ref count ??? */
2271 atomic_dec(&listener
->ref_count
);
2272 nes_debug(NES_DBG_CM
, "Not creating listener since it already exists\n");
2277 /* create a CM listen node (1/2 node to compare incoming traffic to) */
2278 listener
= kzalloc(sizeof(*listener
), GFP_ATOMIC
);
2282 listener
->loc_addr
= cm_info
->loc_addr
;
2283 listener
->loc_port
= cm_info
->loc_port
;
2284 listener
->reused_node
= 0;
2286 atomic_set(&listener
->ref_count
, 1);
2289 /* find already inc'ed the ref count */
2291 listener
->reused_node
= 1;
2294 listener
->cm_id
= cm_info
->cm_id
;
2295 atomic_set(&listener
->pend_accepts_cnt
, 0);
2296 listener
->cm_core
= cm_core
;
2297 listener
->nesvnic
= nesvnic
;
2298 atomic_inc(&cm_core
->node_cnt
);
2300 listener
->conn_type
= cm_info
->conn_type
;
2301 listener
->backlog
= cm_info
->backlog
;
2302 listener
->listener_state
= NES_CM_LISTENER_ACTIVE_STATE
;
2304 if (!listener
->reused_node
) {
2305 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
2306 list_add(&listener
->list
, &cm_core
->listen_list
.list
);
2307 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
2308 atomic_inc(&cm_core
->listen_node_cnt
);
2311 nes_debug(NES_DBG_CM
, "Api - listen(): addr=0x%08X, port=0x%04x,"
2312 " listener = %p, backlog = %d, cm_id = %p.\n",
2313 cm_info
->loc_addr
, cm_info
->loc_port
,
2314 listener
, listener
->backlog
, listener
->cm_id
);
2321 * mini_cm_connect - make a connection node with params
2323 static struct nes_cm_node
*mini_cm_connect(struct nes_cm_core
*cm_core
,
2324 struct nes_vnic
*nesvnic
, u16 private_data_len
,
2325 void *private_data
, struct nes_cm_info
*cm_info
)
2328 struct nes_cm_node
*cm_node
;
2329 struct nes_cm_listener
*loopbackremotelistener
;
2330 struct nes_cm_node
*loopbackremotenode
;
2331 struct nes_cm_info loopback_cm_info
;
2334 /* create a CM connection node */
2335 cm_node
= make_cm_node(cm_core
, nesvnic
, cm_info
, NULL
);
2339 /* set our node side to client (active) side */
2340 cm_node
->tcp_cntxt
.client
= 1;
2341 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
2343 if (cm_info
->loc_addr
== cm_info
->rem_addr
) {
2344 loopbackremotelistener
= find_listener(cm_core
,
2345 cm_node
->loc_addr
, cm_node
->rem_port
,
2346 NES_CM_LISTENER_ACTIVE_STATE
);
2347 if (loopbackremotelistener
== NULL
) {
2348 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
2350 loopback_cm_info
= *cm_info
;
2351 loopback_cm_info
.loc_port
= cm_info
->rem_port
;
2352 loopback_cm_info
.rem_port
= cm_info
->loc_port
;
2353 loopback_cm_info
.loc_port
=
2355 loopback_cm_info
.rem_port
=
2357 loopback_cm_info
.cm_id
= loopbackremotelistener
->cm_id
;
2358 loopbackremotenode
= make_cm_node(cm_core
, nesvnic
,
2359 &loopback_cm_info
, loopbackremotelistener
);
2360 if (!loopbackremotenode
) {
2361 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2364 atomic_inc(&cm_loopbacks
);
2365 loopbackremotenode
->loopbackpartner
= cm_node
;
2366 loopbackremotenode
->tcp_cntxt
.rcv_wscale
=
2367 NES_CM_DEFAULT_RCV_WND_SCALE
;
2368 cm_node
->loopbackpartner
= loopbackremotenode
;
2369 memcpy(loopbackremotenode
->mpa_frame_buf
, private_data
,
2371 loopbackremotenode
->mpa_frame_size
= private_data_len
;
2373 /* we are done handling this state. */
2374 /* set node to a TSA state */
2375 cm_node
->state
= NES_CM_STATE_TSA
;
2376 cm_node
->tcp_cntxt
.rcv_nxt
=
2377 loopbackremotenode
->tcp_cntxt
.loc_seq_num
;
2378 loopbackremotenode
->tcp_cntxt
.rcv_nxt
=
2379 cm_node
->tcp_cntxt
.loc_seq_num
;
2380 cm_node
->tcp_cntxt
.max_snd_wnd
=
2381 loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
2382 loopbackremotenode
->tcp_cntxt
.max_snd_wnd
=
2383 cm_node
->tcp_cntxt
.rcv_wnd
;
2384 cm_node
->tcp_cntxt
.snd_wnd
=
2385 loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
2386 loopbackremotenode
->tcp_cntxt
.snd_wnd
=
2387 cm_node
->tcp_cntxt
.rcv_wnd
;
2388 cm_node
->tcp_cntxt
.snd_wscale
=
2389 loopbackremotenode
->tcp_cntxt
.rcv_wscale
;
2390 loopbackremotenode
->tcp_cntxt
.snd_wscale
=
2391 cm_node
->tcp_cntxt
.rcv_wscale
;
2392 loopbackremotenode
->state
= NES_CM_STATE_MPAREQ_RCVD
;
2393 create_event(loopbackremotenode
, NES_CM_EVENT_MPA_REQ
);
2398 start_buff
= &cm_node
->mpa_frame_buf
[0] + sizeof(struct ietf_mpa_v2
);
2399 cm_node
->mpa_frame_size
= private_data_len
;
2401 memcpy(start_buff
, private_data
, private_data_len
);
2403 /* send a syn and goto syn sent state */
2404 cm_node
->state
= NES_CM_STATE_SYN_SENT
;
2405 ret
= send_syn(cm_node
, 0, NULL
);
2408 /* error in sending the syn free up the cm_node struct */
2409 nes_debug(NES_DBG_CM
, "Api - connect() FAILED: dest "
2410 "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
2411 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
,
2413 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2418 nes_debug(NES_DBG_CM
, "Api - connect(): dest addr=0x%08X,"
2419 "port=0x%04x, cm_node=%p, cm_id = %p.\n",
2420 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
,
2429 * mini_cm_accept - accept a connection
2430 * This function is never called
2432 static int mini_cm_accept(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2439 * mini_cm_reject - reject and teardown a connection
2441 static int mini_cm_reject(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2446 struct nes_cm_event event
;
2447 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
2448 struct nes_cm_node
*loopback
= cm_node
->loopbackpartner
;
2450 nes_debug(NES_DBG_CM
, "%s cm_node=%p type=%d state=%d\n",
2451 __func__
, cm_node
, cm_node
->tcp_cntxt
.client
, cm_node
->state
);
2453 if (cm_node
->tcp_cntxt
.client
)
2455 cleanup_retrans_entry(cm_node
);
2458 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
2459 if (passive_state
== NES_SEND_RESET_EVENT
) {
2460 cm_node
->state
= NES_CM_STATE_CLOSED
;
2461 rem_ref_cm_node(cm_core
, cm_node
);
2463 if (cm_node
->state
== NES_CM_STATE_LISTENER_DESTROYED
) {
2464 rem_ref_cm_node(cm_core
, cm_node
);
2466 ret
= send_mpa_reject(cm_node
);
2468 cm_node
->state
= NES_CM_STATE_CLOSED
;
2469 err
= send_reset(cm_node
, NULL
);
2473 cm_id
->add_ref(cm_id
);
2478 cm_node
->cm_id
= NULL
;
2479 if (cm_node
->state
== NES_CM_STATE_LISTENER_DESTROYED
) {
2480 rem_ref_cm_node(cm_core
, cm_node
);
2481 rem_ref_cm_node(cm_core
, loopback
);
2483 event
.cm_node
= loopback
;
2484 event
.cm_info
.rem_addr
= loopback
->rem_addr
;
2485 event
.cm_info
.loc_addr
= loopback
->loc_addr
;
2486 event
.cm_info
.rem_port
= loopback
->rem_port
;
2487 event
.cm_info
.loc_port
= loopback
->loc_port
;
2488 event
.cm_info
.cm_id
= loopback
->cm_id
;
2489 cm_event_mpa_reject(&event
);
2490 rem_ref_cm_node(cm_core
, cm_node
);
2491 loopback
->state
= NES_CM_STATE_CLOSING
;
2493 cm_id
= loopback
->cm_id
;
2494 rem_ref_cm_node(cm_core
, loopback
);
2495 cm_id
->rem_ref(cm_id
);
2506 static int mini_cm_close(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2510 if (!cm_core
|| !cm_node
)
2513 switch (cm_node
->state
) {
2514 case NES_CM_STATE_SYN_RCVD
:
2515 case NES_CM_STATE_SYN_SENT
:
2516 case NES_CM_STATE_ONE_SIDE_ESTABLISHED
:
2517 case NES_CM_STATE_ESTABLISHED
:
2518 case NES_CM_STATE_ACCEPTING
:
2519 case NES_CM_STATE_MPAREQ_SENT
:
2520 case NES_CM_STATE_MPAREQ_RCVD
:
2521 cleanup_retrans_entry(cm_node
);
2522 send_reset(cm_node
, NULL
);
2524 case NES_CM_STATE_CLOSE_WAIT
:
2525 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
2526 send_fin(cm_node
, NULL
);
2528 case NES_CM_STATE_FIN_WAIT1
:
2529 case NES_CM_STATE_FIN_WAIT2
:
2530 case NES_CM_STATE_LAST_ACK
:
2531 case NES_CM_STATE_TIME_WAIT
:
2532 case NES_CM_STATE_CLOSING
:
2535 case NES_CM_STATE_LISTENING
:
2536 cleanup_retrans_entry(cm_node
);
2537 send_reset(cm_node
, NULL
);
2539 case NES_CM_STATE_MPAREJ_RCVD
:
2540 case NES_CM_STATE_UNKNOWN
:
2541 case NES_CM_STATE_INITED
:
2542 case NES_CM_STATE_CLOSED
:
2543 case NES_CM_STATE_LISTENER_DESTROYED
:
2544 ret
= rem_ref_cm_node(cm_core
, cm_node
);
2546 case NES_CM_STATE_TSA
:
2547 if (cm_node
->send_entry
)
2548 printk(KERN_ERR
"ERROR Close got called from STATE_TSA "
2549 "send_entry=%p\n", cm_node
->send_entry
);
2550 ret
= rem_ref_cm_node(cm_core
, cm_node
);
2558 * recv_pkt - recv an ETHERNET packet, and process it through CM
2559 * node state machine
2561 static int mini_cm_recv_pkt(struct nes_cm_core
*cm_core
,
2562 struct nes_vnic
*nesvnic
, struct sk_buff
*skb
)
2564 struct nes_cm_node
*cm_node
= NULL
;
2565 struct nes_cm_listener
*listener
= NULL
;
2567 struct tcphdr
*tcph
;
2568 struct nes_cm_info nfo
;
2569 int skb_handled
= 1;
2570 __be32 tmp_daddr
, tmp_saddr
;
2574 if (skb
->len
< sizeof(struct iphdr
) + sizeof(struct tcphdr
))
2577 iph
= (struct iphdr
*)skb
->data
;
2578 tcph
= (struct tcphdr
*)(skb
->data
+ sizeof(struct iphdr
));
2580 nfo
.loc_addr
= ntohl(iph
->daddr
);
2581 nfo
.loc_port
= ntohs(tcph
->dest
);
2582 nfo
.rem_addr
= ntohl(iph
->saddr
);
2583 nfo
.rem_port
= ntohs(tcph
->source
);
2585 tmp_daddr
= cpu_to_be32(iph
->daddr
);
2586 tmp_saddr
= cpu_to_be32(iph
->saddr
);
2588 nes_debug(NES_DBG_CM
, "Received packet: dest=%pI4:0x%04X src=%pI4:0x%04X\n",
2589 &tmp_daddr
, tcph
->dest
, &tmp_saddr
, tcph
->source
);
2592 cm_node
= find_node(cm_core
,
2593 nfo
.rem_port
, nfo
.rem_addr
,
2594 nfo
.loc_port
, nfo
.loc_addr
);
2597 /* Only type of packet accepted are for */
2598 /* the PASSIVE open (syn only) */
2599 if ((!tcph
->syn
) || (tcph
->ack
)) {
2603 listener
= find_listener(cm_core
, nfo
.loc_addr
,
2605 NES_CM_LISTENER_ACTIVE_STATE
);
2609 nes_debug(NES_DBG_CM
, "Unable to find listener for the pkt\n");
2613 nfo
.cm_id
= listener
->cm_id
;
2614 nfo
.conn_type
= listener
->conn_type
;
2615 cm_node
= make_cm_node(cm_core
, nesvnic
, &nfo
,
2618 nes_debug(NES_DBG_CM
, "Unable to allocate "
2620 cm_packets_dropped
++;
2621 atomic_dec(&listener
->ref_count
);
2622 dev_kfree_skb_any(skb
);
2625 if (!tcph
->rst
&& !tcph
->fin
) {
2626 cm_node
->state
= NES_CM_STATE_LISTENING
;
2628 cm_packets_dropped
++;
2629 rem_ref_cm_node(cm_core
, cm_node
);
2630 dev_kfree_skb_any(skb
);
2633 add_ref_cm_node(cm_node
);
2634 } else if (cm_node
->state
== NES_CM_STATE_TSA
) {
2635 if (cm_node
->nesqp
->pau_mode
)
2636 nes_queue_mgt_skbs(skb
, nesvnic
, cm_node
->nesqp
);
2638 rem_ref_cm_node(cm_core
, cm_node
);
2639 atomic_inc(&cm_accel_dropped_pkts
);
2640 dev_kfree_skb_any(skb
);
2644 skb_reset_network_header(skb
);
2645 skb_set_transport_header(skb
, sizeof(*tcph
));
2646 skb
->len
= ntohs(iph
->tot_len
);
2647 process_packet(cm_node
, skb
, cm_core
);
2648 rem_ref_cm_node(cm_core
, cm_node
);
2655 * nes_cm_alloc_core - allocate a top level instance of a cm core
2657 static struct nes_cm_core
*nes_cm_alloc_core(void)
2659 struct nes_cm_core
*cm_core
;
2661 /* setup the CM core */
2662 /* alloc top level core control structure */
2663 cm_core
= kzalloc(sizeof(*cm_core
), GFP_KERNEL
);
2667 INIT_LIST_HEAD(&cm_core
->connected_nodes
);
2668 timer_setup(&cm_core
->tcp_timer
, nes_cm_timer_tick
, 0);
2670 cm_core
->mtu
= NES_CM_DEFAULT_MTU
;
2671 cm_core
->state
= NES_CM_STATE_INITED
;
2672 cm_core
->free_tx_pkt_max
= NES_CM_DEFAULT_FREE_PKTS
;
2674 atomic_set(&cm_core
->events_posted
, 0);
2676 cm_core
->api
= &nes_cm_api
;
2678 spin_lock_init(&cm_core
->ht_lock
);
2679 spin_lock_init(&cm_core
->listen_list_lock
);
2681 INIT_LIST_HEAD(&cm_core
->listen_list
.list
);
2683 nes_debug(NES_DBG_CM
, "Init CM Core completed -- cm_core=%p\n", cm_core
);
2685 nes_debug(NES_DBG_CM
, "Enable QUEUE EVENTS\n");
2686 cm_core
->event_wq
= alloc_ordered_workqueue("nesewq", 0);
2687 if (!cm_core
->event_wq
)
2688 goto out_free_cmcore
;
2689 cm_core
->post_event
= nes_cm_post_event
;
2690 nes_debug(NES_DBG_CM
, "Enable QUEUE DISCONNECTS\n");
2691 cm_core
->disconn_wq
= alloc_ordered_workqueue("nesdwq", 0);
2692 if (!cm_core
->disconn_wq
)
2695 print_core(cm_core
);
2699 destroy_workqueue(cm_core
->event_wq
);
2707 * mini_cm_dealloc_core - deallocate a top level instance of a cm core
2709 static int mini_cm_dealloc_core(struct nes_cm_core
*cm_core
)
2711 nes_debug(NES_DBG_CM
, "De-Alloc CM Core (%p)\n", cm_core
);
2718 if (timer_pending(&cm_core
->tcp_timer
))
2719 del_timer(&cm_core
->tcp_timer
);
2721 destroy_workqueue(cm_core
->event_wq
);
2722 destroy_workqueue(cm_core
->disconn_wq
);
2723 nes_debug(NES_DBG_CM
, "\n");
2733 static int mini_cm_get(struct nes_cm_core
*cm_core
)
2735 return cm_core
->state
;
2742 static int mini_cm_set(struct nes_cm_core
*cm_core
, u32 type
, u32 value
)
2747 case NES_CM_SET_PKT_SIZE
:
2748 cm_core
->mtu
= value
;
2750 case NES_CM_SET_FREE_PKT_Q_SIZE
:
2751 cm_core
->free_tx_pkt_max
= value
;
2754 /* unknown set option */
2763 * nes_cm_init_tsa_conn setup HW; MPA frames must be
2764 * successfully exchanged when this is called
2766 static int nes_cm_init_tsa_conn(struct nes_qp
*nesqp
, struct nes_cm_node
*cm_node
)
2773 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4
|
2774 NES_QPCONTEXT_MISC_NO_NAGLE
| NES_QPCONTEXT_MISC_DO_NOT_FRAG
|
2775 NES_QPCONTEXT_MISC_DROS
);
2777 if (cm_node
->tcp_cntxt
.snd_wscale
|| cm_node
->tcp_cntxt
.rcv_wscale
)
2778 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE
);
2780 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT
);
2782 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
2783 cm_node
->tos
<< NES_QPCONTEXT_MISC2_TOS_SHIFT
);
2785 nesqp
->nesqp_context
->mss
|= cpu_to_le32(((u32
)cm_node
->tcp_cntxt
.mss
) << 16);
2787 nesqp
->nesqp_context
->tcp_state_flow_label
|= cpu_to_le32(
2788 (u32
)NES_QPCONTEXT_TCPSTATE_EST
<< NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT
);
2790 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2791 (cm_node
->tcp_cntxt
.snd_wscale
<< NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT
) &
2792 NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK
);
2794 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2795 (cm_node
->tcp_cntxt
.rcv_wscale
<< NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT
) &
2796 NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK
);
2798 nesqp
->nesqp_context
->keepalive
= cpu_to_le32(0x80);
2799 nesqp
->nesqp_context
->ts_recent
= 0;
2800 nesqp
->nesqp_context
->ts_age
= 0;
2801 nesqp
->nesqp_context
->snd_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2802 nesqp
->nesqp_context
->snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.snd_wnd
);
2803 nesqp
->nesqp_context
->rcv_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2804 nesqp
->nesqp_context
->rcv_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_wnd
<<
2805 cm_node
->tcp_cntxt
.rcv_wscale
);
2806 nesqp
->nesqp_context
->snd_max
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2807 nesqp
->nesqp_context
->snd_una
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2808 nesqp
->nesqp_context
->srtt
= 0;
2809 nesqp
->nesqp_context
->rttvar
= cpu_to_le32(0x6);
2810 nesqp
->nesqp_context
->ssthresh
= cpu_to_le32(0x3FFFC000);
2811 nesqp
->nesqp_context
->cwnd
= cpu_to_le32(2 * cm_node
->tcp_cntxt
.mss
);
2812 nesqp
->nesqp_context
->snd_wl1
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2813 nesqp
->nesqp_context
->snd_wl2
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2814 nesqp
->nesqp_context
->max_snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.max_snd_wnd
);
2816 nes_debug(NES_DBG_CM
, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
2817 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
2818 nesqp
->hwqp
.qp_id
, le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
2819 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
2820 cm_node
->tcp_cntxt
.mss
, le32_to_cpu(nesqp
->nesqp_context
->pd_index_wscale
),
2821 le32_to_cpu(nesqp
->nesqp_context
->rcv_wnd
),
2822 le32_to_cpu(nesqp
->nesqp_context
->misc
));
2823 nes_debug(NES_DBG_CM
, " snd_wnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->snd_wnd
));
2824 nes_debug(NES_DBG_CM
, " snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->cwnd
));
2825 nes_debug(NES_DBG_CM
, " max_swnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->max_snd_wnd
));
2827 nes_debug(NES_DBG_CM
, "Change cm_node state to TSA\n");
2828 cm_node
->state
= NES_CM_STATE_TSA
;
2837 int nes_cm_disconn(struct nes_qp
*nesqp
)
2839 struct disconn_work
*work
;
2841 work
= kzalloc(sizeof *work
, GFP_ATOMIC
);
2843 return -ENOMEM
; /* Timer will clean up */
2845 nes_add_ref(&nesqp
->ibqp
);
2846 work
->nesqp
= nesqp
;
2847 INIT_WORK(&work
->work
, nes_disconnect_worker
);
2848 queue_work(g_cm_core
->disconn_wq
, &work
->work
);
2854 * nes_disconnect_worker
2856 static void nes_disconnect_worker(struct work_struct
*work
)
2858 struct disconn_work
*dwork
= container_of(work
, struct disconn_work
, work
);
2859 struct nes_qp
*nesqp
= dwork
->nesqp
;
2862 nes_debug(NES_DBG_CM
, "processing AEQE id 0x%04X for QP%u.\n",
2863 nesqp
->last_aeq
, nesqp
->hwqp
.qp_id
);
2864 nes_cm_disconn_true(nesqp
);
2865 nes_rem_ref(&nesqp
->ibqp
);
2870 * nes_cm_disconn_true
2872 static int nes_cm_disconn_true(struct nes_qp
*nesqp
)
2874 unsigned long flags
;
2876 struct iw_cm_id
*cm_id
;
2877 struct iw_cm_event cm_event
;
2878 struct nes_vnic
*nesvnic
;
2880 u8 original_hw_tcp_state
;
2881 u8 original_ibqp_state
;
2882 int disconn_status
= 0;
2883 int issue_disconn
= 0;
2884 int issue_close
= 0;
2885 int issue_flush
= 0;
2886 u32 flush_q
= NES_CQP_FLUSH_RQ
;
2887 struct ib_event ibevent
;
2890 nes_debug(NES_DBG_CM
, "disconnect_worker nesqp is NULL\n");
2894 spin_lock_irqsave(&nesqp
->lock
, flags
);
2895 cm_id
= nesqp
->cm_id
;
2896 /* make sure we havent already closed this connection */
2898 nes_debug(NES_DBG_CM
, "QP%u disconnect_worker cmid is NULL\n",
2900 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2904 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2905 nes_debug(NES_DBG_CM
, "Disconnecting QP%u\n", nesqp
->hwqp
.qp_id
);
2907 original_hw_tcp_state
= nesqp
->hw_tcp_state
;
2908 original_ibqp_state
= nesqp
->ibqp_state
;
2909 last_ae
= nesqp
->last_aeq
;
2911 if (nesqp
->term_flags
) {
2914 nesqp
->cm_id
= NULL
;
2915 del_timer(&nesqp
->terminate_timer
);
2916 if (nesqp
->flush_issued
== 0) {
2917 nesqp
->flush_issued
= 1;
2920 } else if ((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSE_WAIT
) ||
2921 ((original_ibqp_state
== IB_QPS_RTS
) &&
2922 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2924 if (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
)
2925 disconn_status
= -ECONNRESET
;
2928 if (((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSED
) ||
2929 (original_hw_tcp_state
== NES_AEQE_TCP_STATE_TIME_WAIT
) ||
2930 (last_ae
== NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
) ||
2931 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2933 nesqp
->cm_id
= NULL
;
2934 if (nesqp
->flush_issued
== 0) {
2935 nesqp
->flush_issued
= 1;
2940 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2942 if ((issue_flush
) && (nesqp
->destroyed
== 0)) {
2943 /* Flush the queue(s) */
2944 if (nesqp
->hw_iwarp_state
>= NES_AEQE_IWARP_STATE_TERMINATE
)
2945 flush_q
|= NES_CQP_FLUSH_SQ
;
2946 flush_wqes(nesvnic
->nesdev
, nesqp
, flush_q
, 1);
2948 if (nesqp
->term_flags
) {
2949 ibevent
.device
= nesqp
->ibqp
.device
;
2950 ibevent
.event
= nesqp
->terminate_eventtype
;
2951 ibevent
.element
.qp
= &nesqp
->ibqp
;
2952 if (nesqp
->ibqp
.event_handler
)
2953 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2957 if ((cm_id
) && (cm_id
->event_handler
)) {
2958 if (issue_disconn
) {
2959 atomic_inc(&cm_disconnects
);
2960 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
2961 cm_event
.status
= disconn_status
;
2962 cm_event
.local_addr
= cm_id
->m_local_addr
;
2963 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
2964 cm_event
.private_data
= NULL
;
2965 cm_event
.private_data_len
= 0;
2967 nes_debug(NES_DBG_CM
, "Generating a CM Disconnect Event"
2968 " for QP%u, SQ Head = %u, SQ Tail = %u. "
2969 "cm_id = %p, refcount = %u.\n",
2970 nesqp
->hwqp
.qp_id
, nesqp
->hwqp
.sq_head
,
2971 nesqp
->hwqp
.sq_tail
, cm_id
,
2972 atomic_read(&nesqp
->refcount
));
2974 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2976 nes_debug(NES_DBG_CM
, "OFA CM event_handler "
2977 "returned, ret=%d\n", ret
);
2981 atomic_inc(&cm_closes
);
2982 nes_disconnect(nesqp
, 1);
2984 cm_id
->provider_data
= nesqp
;
2985 /* Send up the close complete event */
2986 cm_event
.event
= IW_CM_EVENT_CLOSE
;
2987 cm_event
.status
= 0;
2988 cm_event
.provider_data
= cm_id
->provider_data
;
2989 cm_event
.local_addr
= cm_id
->m_local_addr
;
2990 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
2991 cm_event
.private_data
= NULL
;
2992 cm_event
.private_data_len
= 0;
2994 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2996 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
2998 cm_id
->rem_ref(cm_id
);
3009 static int nes_disconnect(struct nes_qp
*nesqp
, int abrupt
)
3012 struct nes_vnic
*nesvnic
;
3013 struct nes_device
*nesdev
;
3014 struct nes_ib_device
*nesibdev
;
3016 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3020 nesdev
= nesvnic
->nesdev
;
3021 nesibdev
= nesvnic
->nesibdev
;
3023 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
3024 netdev_refcnt_read(nesvnic
->netdev
));
3026 if (nesqp
->active_conn
) {
3028 /* indicate this connection is NOT active */
3029 nesqp
->active_conn
= 0;
3031 /* Need to free the Last Streaming Mode Message */
3032 if (nesqp
->ietf_frame
) {
3034 nesibdev
->ibdev
.dereg_mr(nesqp
->lsmm_mr
);
3035 pci_free_consistent(nesdev
->pcidev
,
3036 nesqp
->private_data_len
+ nesqp
->ietf_frame_size
,
3037 nesqp
->ietf_frame
, nesqp
->ietf_frame_pbase
);
3041 /* close the CM node down if it is still active */
3042 if (nesqp
->cm_node
) {
3043 nes_debug(NES_DBG_CM
, "Call close API\n");
3045 g_cm_core
->api
->close(g_cm_core
, nesqp
->cm_node
);
3055 int nes_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3059 struct nes_qp
*nesqp
;
3060 struct nes_vnic
*nesvnic
;
3061 struct nes_device
*nesdev
;
3062 struct nes_cm_node
*cm_node
;
3063 struct nes_adapter
*adapter
;
3064 struct ib_qp_attr attr
;
3065 struct iw_cm_event cm_event
;
3066 struct nes_hw_qp_wqe
*wqe
;
3067 struct nes_v4_quad nes_quad
;
3071 struct ib_mr
*ibmr
= NULL
;
3072 struct nes_pd
*nespd
;
3074 u8 mpa_frame_offset
= 0;
3075 struct ietf_mpa_v2
*mpa_v2_frame
;
3077 u8
*start_ptr
= &start_addr
;
3078 u8
**start_buff
= &start_ptr
;
3080 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3081 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3083 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
3087 /* get all our handles */
3088 nesqp
= to_nesqp(ibqp
);
3089 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3090 nesdev
= nesvnic
->nesdev
;
3091 adapter
= nesdev
->nesadapter
;
3093 cm_node
= (struct nes_cm_node
*)cm_id
->provider_data
;
3094 nes_debug(NES_DBG_CM
, "nes_accept: cm_node= %p nesvnic=%p, netdev=%p,"
3095 "%s\n", cm_node
, nesvnic
, nesvnic
->netdev
,
3096 nesvnic
->netdev
->name
);
3098 if (NES_CM_STATE_LISTENER_DESTROYED
== cm_node
->state
) {
3099 if (cm_node
->loopbackpartner
)
3100 rem_ref_cm_node(cm_node
->cm_core
, cm_node
->loopbackpartner
);
3101 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
3105 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
3106 if (passive_state
== NES_SEND_RESET_EVENT
) {
3107 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
3110 /* associate the node with the QP */
3111 nesqp
->cm_node
= (void *)cm_node
;
3112 cm_node
->nesqp
= nesqp
;
3115 nes_debug(NES_DBG_CM
, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
3116 nesqp
->hwqp
.qp_id
, cm_node
, jiffies
, cm_node
->listener
);
3117 atomic_inc(&cm_accepts
);
3119 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
3120 netdev_refcnt_read(nesvnic
->netdev
));
3122 nesqp
->ietf_frame_size
= sizeof(struct ietf_mpa_v2
);
3123 /* allocate the ietf frame and space for private data */
3124 nesqp
->ietf_frame
= pci_alloc_consistent(nesdev
->pcidev
,
3125 nesqp
->ietf_frame_size
+ conn_param
->private_data_len
,
3126 &nesqp
->ietf_frame_pbase
);
3128 if (!nesqp
->ietf_frame
) {
3129 nes_debug(NES_DBG_CM
, "Unable to allocate memory for private data\n");
3132 mpa_v2_frame
= (struct ietf_mpa_v2
*)nesqp
->ietf_frame
;
3134 if (cm_node
->mpa_frame_rev
== IETF_MPA_V1
)
3135 mpa_frame_offset
= 4;
3137 if (cm_node
->mpa_frame_rev
== IETF_MPA_V1
||
3138 cm_node
->mpav2_ird_ord
== IETF_NO_IRD_ORD
) {
3139 record_ird_ord(cm_node
, (u16
)conn_param
->ird
, (u16
)conn_param
->ord
);
3142 memcpy(mpa_v2_frame
->priv_data
, conn_param
->private_data
,
3143 conn_param
->private_data_len
);
3145 cm_build_mpa_frame(cm_node
, start_buff
, &buff_len
, nesqp
->ietf_frame
, MPA_KEY_REPLY
);
3146 nesqp
->private_data_len
= conn_param
->private_data_len
;
3148 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
3149 wqe
= &nesqp
->hwqp
.sq_vbase
[0];
3151 if (raddr
->sin_addr
.s_addr
!= laddr
->sin_addr
.s_addr
) {
3152 u64temp
= (unsigned long)nesqp
;
3153 nespd
= nesqp
->nespd
;
3154 tagged_offset
= (u64
)(unsigned long)*start_buff
;
3155 ibmr
= nes_reg_phys_mr(&nespd
->ibpd
,
3156 nesqp
->ietf_frame_pbase
+ mpa_frame_offset
,
3157 buff_len
, IB_ACCESS_LOCAL_WRITE
,
3160 nes_debug(NES_DBG_CM
, "Unable to register memory region"
3161 "for lSMM for cm_node = %p \n",
3163 pci_free_consistent(nesdev
->pcidev
,
3164 nesqp
->private_data_len
+ nesqp
->ietf_frame_size
,
3165 nesqp
->ietf_frame
, nesqp
->ietf_frame_pbase
);
3166 return PTR_ERR(ibmr
);
3169 ibmr
->pd
= &nespd
->ibpd
;
3170 ibmr
->device
= nespd
->ibpd
.device
;
3171 nesqp
->lsmm_mr
= ibmr
;
3173 u64temp
|= NES_SW_CONTEXT_ALIGN
>> 1;
3174 set_wqe_64bit_value(wqe
->wqe_words
,
3175 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
,
3177 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
3178 cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING
|
3179 NES_IWARP_SQ_WQE_WRPDU
);
3180 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] =
3181 cpu_to_le32(buff_len
);
3182 set_wqe_64bit_value(wqe
->wqe_words
,
3183 NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
,
3184 (u64
)(unsigned long)(*start_buff
));
3185 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] =
3186 cpu_to_le32(buff_len
);
3187 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = ibmr
->lkey
;
3188 if (nesqp
->sq_kmapped
) {
3189 nesqp
->sq_kmapped
= 0;
3190 kunmap(nesqp
->page
);
3193 nesqp
->nesqp_context
->ird_ord_sizes
|=
3194 cpu_to_le32(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
3195 NES_QPCONTEXT_ORDIRD_WRPDU
);
3197 nesqp
->nesqp_context
->ird_ord_sizes
|=
3198 cpu_to_le32(NES_QPCONTEXT_ORDIRD_WRPDU
);
3200 nesqp
->skip_lsmm
= 1;
3202 /* Cache the cm_id in the qp */
3203 nesqp
->cm_id
= cm_id
;
3204 cm_node
->cm_id
= cm_id
;
3206 /* nesqp->cm_node = (void *)cm_id->provider_data; */
3207 cm_id
->provider_data
= nesqp
;
3208 nesqp
->active_conn
= 0;
3210 if (cm_node
->state
== NES_CM_STATE_TSA
)
3211 nes_debug(NES_DBG_CM
, "Already state = TSA for cm_node=%p\n",
3214 nes_cm_init_tsa_conn(nesqp
, cm_node
);
3216 nesqp
->nesqp_context
->tcpPorts
[0] =
3217 cpu_to_le16(cm_node
->loc_port
);
3218 nesqp
->nesqp_context
->tcpPorts
[1] =
3219 cpu_to_le16(cm_node
->rem_port
);
3221 nesqp
->nesqp_context
->ip0
= cpu_to_le32(cm_node
->rem_addr
);
3223 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
3224 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
3225 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
3227 nesqp
->nesqp_context
->arp_index_vlan
|=
3228 cpu_to_le32(nes_arp_table(nesdev
,
3229 le32_to_cpu(nesqp
->nesqp_context
->ip0
), NULL
,
3230 NES_ARP_RESOLVE
) << 16);
3232 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
3233 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
3235 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
3237 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32(
3238 ((u32
)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
));
3239 nesqp
->nesqp_context
->ird_ord_sizes
|=
3240 cpu_to_le32((u32
)cm_node
->ord_size
);
3242 memset(&nes_quad
, 0, sizeof(nes_quad
));
3243 nes_quad
.DstIpAdrIndex
=
3244 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
3245 nes_quad
.SrcIpadr
= htonl(cm_node
->rem_addr
);
3246 nes_quad
.TcpPorts
[0] = htons(cm_node
->rem_port
);
3247 nes_quad
.TcpPorts
[1] = htons(cm_node
->loc_port
);
3249 /* Produce hash key */
3250 crc_value
= get_crc_value(&nes_quad
);
3251 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
3252 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, CRC = 0x%08X\n",
3253 nesqp
->hte_index
, nesqp
->hte_index
& adapter
->hte_index_mask
);
3255 nesqp
->hte_index
&= adapter
->hte_index_mask
;
3256 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
3258 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
3260 nes_debug(NES_DBG_CM
, "QP%u, Destination IP = 0x%08X:0x%04X, local = "
3261 "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
3262 "private data length=%u.\n", nesqp
->hwqp
.qp_id
,
3263 ntohl(raddr
->sin_addr
.s_addr
), ntohs(raddr
->sin_port
),
3264 ntohl(laddr
->sin_addr
.s_addr
), ntohs(laddr
->sin_port
),
3265 le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
3266 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
3269 /* notify OF layer that accept event was successful */
3270 cm_id
->add_ref(cm_id
);
3271 nes_add_ref(&nesqp
->ibqp
);
3273 cm_event
.event
= IW_CM_EVENT_ESTABLISHED
;
3274 cm_event
.status
= 0;
3275 cm_event
.provider_data
= (void *)nesqp
;
3276 cm_event
.local_addr
= cm_id
->m_local_addr
;
3277 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3278 cm_event
.private_data
= NULL
;
3279 cm_event
.private_data_len
= 0;
3280 cm_event
.ird
= cm_node
->ird_size
;
3281 cm_event
.ord
= cm_node
->ord_size
;
3283 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3284 attr
.qp_state
= IB_QPS_RTS
;
3285 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3286 if (cm_node
->loopbackpartner
) {
3287 cm_node
->loopbackpartner
->mpa_frame_size
=
3288 nesqp
->private_data_len
;
3289 /* copy entire MPA frame to our cm_node's frame */
3290 memcpy(cm_node
->loopbackpartner
->mpa_frame_buf
,
3291 conn_param
->private_data
, conn_param
->private_data_len
);
3292 create_event(cm_node
->loopbackpartner
, NES_CM_EVENT_CONNECTED
);
3295 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3296 "ret=%d\n", __func__
, __LINE__
, ret
);
3305 int nes_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
3307 struct nes_cm_node
*cm_node
;
3308 struct nes_cm_node
*loopback
;
3309 struct nes_cm_core
*cm_core
;
3312 atomic_inc(&cm_rejects
);
3313 cm_node
= (struct nes_cm_node
*)cm_id
->provider_data
;
3314 loopback
= cm_node
->loopbackpartner
;
3315 cm_core
= cm_node
->cm_core
;
3316 cm_node
->cm_id
= cm_id
;
3318 if (pdata_len
+ sizeof(struct ietf_mpa_v2
) > MAX_CM_BUFFER
)
3322 memcpy(&loopback
->mpa_frame
.priv_data
, pdata
, pdata_len
);
3323 loopback
->mpa_frame
.priv_data_len
= pdata_len
;
3324 loopback
->mpa_frame_size
= pdata_len
;
3326 start_buff
= &cm_node
->mpa_frame_buf
[0] + sizeof(struct ietf_mpa_v2
);
3327 cm_node
->mpa_frame_size
= pdata_len
;
3328 memcpy(start_buff
, pdata
, pdata_len
);
3330 return cm_core
->api
->reject(cm_core
, cm_node
);
3336 * setup and launch cm connect node
3338 int nes_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3341 struct nes_qp
*nesqp
;
3342 struct nes_vnic
*nesvnic
;
3343 struct nes_device
*nesdev
;
3344 struct nes_cm_node
*cm_node
;
3345 struct nes_cm_info cm_info
;
3347 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3348 struct sockaddr_in
*raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3350 if (cm_id
->remote_addr
.ss_family
!= AF_INET
)
3352 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
3355 nesqp
= to_nesqp(ibqp
);
3358 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3361 nesdev
= nesvnic
->nesdev
;
3365 if (!laddr
->sin_port
|| !raddr
->sin_port
)
3368 nes_debug(NES_DBG_CM
, "QP%u, current IP = 0x%08X, Destination IP = "
3369 "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp
->hwqp
.qp_id
,
3370 ntohl(nesvnic
->local_ipaddr
), ntohl(raddr
->sin_addr
.s_addr
),
3371 ntohs(raddr
->sin_port
), ntohl(laddr
->sin_addr
.s_addr
),
3372 ntohs(laddr
->sin_port
));
3374 atomic_inc(&cm_connects
);
3375 nesqp
->active_conn
= 1;
3377 /* cache the cm_id in the qp */
3378 nesqp
->cm_id
= cm_id
;
3379 cm_id
->provider_data
= nesqp
;
3380 nesqp
->private_data_len
= conn_param
->private_data_len
;
3382 nes_debug(NES_DBG_CM
, "requested ord = 0x%08X.\n", (u32
)conn_param
->ord
);
3383 nes_debug(NES_DBG_CM
, "mpa private data len =%u\n",
3384 conn_param
->private_data_len
);
3386 /* set up the connection params for the node */
3387 cm_info
.loc_addr
= ntohl(laddr
->sin_addr
.s_addr
);
3388 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3389 cm_info
.rem_addr
= ntohl(raddr
->sin_addr
.s_addr
);
3390 cm_info
.rem_port
= ntohs(raddr
->sin_port
);
3391 cm_info
.cm_id
= cm_id
;
3392 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
3394 if (laddr
->sin_addr
.s_addr
!= raddr
->sin_addr
.s_addr
) {
3395 nes_manage_apbvt(nesvnic
, cm_info
.loc_port
,
3396 PCI_FUNC(nesdev
->pcidev
->devfn
),
3397 NES_MANAGE_APBVT_ADD
);
3401 cm_id
->add_ref(cm_id
);
3403 /* create a connect CM node connection */
3404 cm_node
= g_cm_core
->api
->connect(g_cm_core
, nesvnic
,
3405 conn_param
->private_data_len
, (void *)conn_param
->private_data
,
3409 nes_manage_apbvt(nesvnic
, cm_info
.loc_port
,
3410 PCI_FUNC(nesdev
->pcidev
->devfn
),
3411 NES_MANAGE_APBVT_DEL
);
3413 nes_debug(NES_DBG_NLMSG
, "Delete loc_port = %04X\n",
3415 cm_id
->rem_ref(cm_id
);
3419 record_ird_ord(cm_node
, (u16
)conn_param
->ird
, (u16
)conn_param
->ord
);
3420 if (cm_node
->send_rdma0_op
== SEND_RDMA_READ_ZERO
&&
3421 cm_node
->ord_size
== 0)
3422 cm_node
->ord_size
= 1;
3424 cm_node
->apbvt_set
= apbvt_set
;
3425 cm_node
->tos
= cm_id
->tos
;
3426 nesqp
->cm_node
= cm_node
;
3427 cm_node
->nesqp
= nesqp
;
3428 nes_add_ref(&nesqp
->ibqp
);
3437 int nes_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
3439 struct nes_vnic
*nesvnic
;
3440 struct nes_cm_listener
*cm_node
;
3441 struct nes_cm_info cm_info
;
3443 struct sockaddr_in
*laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3445 nes_debug(NES_DBG_CM
, "cm_id = %p, local port = 0x%04X.\n",
3446 cm_id
, ntohs(laddr
->sin_port
));
3448 if (cm_id
->m_local_addr
.ss_family
!= AF_INET
)
3450 nesvnic
= to_nesvnic(cm_id
->device
);
3454 nes_debug(NES_DBG_CM
, "nesvnic=%p, netdev=%p, %s\n",
3455 nesvnic
, nesvnic
->netdev
, nesvnic
->netdev
->name
);
3457 nes_debug(NES_DBG_CM
, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
3458 nesvnic
->local_ipaddr
, laddr
->sin_addr
.s_addr
);
3460 /* setup listen params in our api call struct */
3461 cm_info
.loc_addr
= ntohl(nesvnic
->local_ipaddr
);
3462 cm_info
.loc_port
= ntohs(laddr
->sin_port
);
3463 cm_info
.backlog
= backlog
;
3464 cm_info
.cm_id
= cm_id
;
3466 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
3468 cm_node
= g_cm_core
->api
->listen(g_cm_core
, nesvnic
, &cm_info
);
3470 printk(KERN_ERR
"%s[%u] Error returned from listen API call\n",
3471 __func__
, __LINE__
);
3475 cm_id
->provider_data
= cm_node
;
3476 cm_node
->tos
= cm_id
->tos
;
3478 if (!cm_node
->reused_node
) {
3479 err
= nes_manage_apbvt(nesvnic
, cm_node
->loc_port
,
3480 PCI_FUNC(nesvnic
->nesdev
->pcidev
->devfn
),
3481 NES_MANAGE_APBVT_ADD
);
3483 printk(KERN_ERR
"nes_manage_apbvt call returned %d.\n",
3485 g_cm_core
->api
->stop_listener(g_cm_core
, (void *)cm_node
);
3488 atomic_inc(&cm_listens_created
);
3491 cm_id
->add_ref(cm_id
);
3492 cm_id
->provider_data
= (void *)cm_node
;
3500 * nes_destroy_listen
3502 int nes_destroy_listen(struct iw_cm_id
*cm_id
)
3504 if (cm_id
->provider_data
)
3505 g_cm_core
->api
->stop_listener(g_cm_core
, cm_id
->provider_data
);
3507 nes_debug(NES_DBG_CM
, "cm_id->provider_data was NULL\n");
3509 cm_id
->rem_ref(cm_id
);
3518 int nes_cm_recv(struct sk_buff
*skb
, struct net_device
*netdevice
)
3522 cm_packets_received
++;
3523 if ((g_cm_core
) && (g_cm_core
->api
))
3524 rc
= g_cm_core
->api
->recv_pkt(g_cm_core
, netdev_priv(netdevice
), skb
);
3526 nes_debug(NES_DBG_CM
, "Unable to process packet for CM,"
3527 " cm is not setup properly.\n");
3535 * Start and init a cm core module
3537 int nes_cm_start(void)
3539 nes_debug(NES_DBG_CM
, "\n");
3540 /* create the primary CM core, pass this handle to subsequent core inits */
3541 g_cm_core
= nes_cm_alloc_core();
3551 * stop and dealloc all cm core instances
3553 int nes_cm_stop(void)
3555 g_cm_core
->api
->destroy_cm_core(g_cm_core
);
3561 * cm_event_connected
3562 * handle a connected event, setup QPs and HW
3564 static void cm_event_connected(struct nes_cm_event
*event
)
3566 struct nes_qp
*nesqp
;
3567 struct nes_vnic
*nesvnic
;
3568 struct nes_device
*nesdev
;
3569 struct nes_cm_node
*cm_node
;
3570 struct nes_adapter
*nesadapter
;
3571 struct ib_qp_attr attr
;
3572 struct iw_cm_id
*cm_id
;
3573 struct iw_cm_event cm_event
;
3574 struct nes_v4_quad nes_quad
;
3577 struct sockaddr_in
*laddr
;
3578 struct sockaddr_in
*raddr
;
3579 struct sockaddr_in
*cm_event_laddr
;
3581 /* get all our handles */
3582 cm_node
= event
->cm_node
;
3583 cm_id
= cm_node
->cm_id
;
3584 nes_debug(NES_DBG_CM
, "cm_event_connected - %p - cm_id = %p\n", cm_node
, cm_id
);
3585 nesqp
= (struct nes_qp
*)cm_id
->provider_data
;
3586 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3587 nesdev
= nesvnic
->nesdev
;
3588 nesadapter
= nesdev
->nesadapter
;
3589 laddr
= (struct sockaddr_in
*)&cm_id
->m_local_addr
;
3590 raddr
= (struct sockaddr_in
*)&cm_id
->m_remote_addr
;
3591 cm_event_laddr
= (struct sockaddr_in
*)&cm_event
.local_addr
;
3593 if (nesqp
->destroyed
)
3595 atomic_inc(&cm_connecteds
);
3596 nes_debug(NES_DBG_CM
, "QP%u attempting to connect to 0x%08X:0x%04X on"
3597 " local port 0x%04X. jiffies = %lu.\n",
3598 nesqp
->hwqp
.qp_id
, ntohl(raddr
->sin_addr
.s_addr
),
3599 ntohs(raddr
->sin_port
), ntohs(laddr
->sin_port
), jiffies
);
3601 nes_cm_init_tsa_conn(nesqp
, cm_node
);
3603 /* set the QP tsa context */
3604 nesqp
->nesqp_context
->tcpPorts
[0] =
3605 cpu_to_le16(cm_node
->loc_port
);
3606 nesqp
->nesqp_context
->tcpPorts
[1] =
3607 cpu_to_le16(cm_node
->rem_port
);
3608 nesqp
->nesqp_context
->ip0
= cpu_to_le32(cm_node
->rem_addr
);
3610 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
3611 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
3612 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
3613 nesqp
->nesqp_context
->arp_index_vlan
|= cpu_to_le32(
3614 nes_arp_table(nesdev
,
3615 le32_to_cpu(nesqp
->nesqp_context
->ip0
),
3616 NULL
, NES_ARP_RESOLVE
) << 16);
3617 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
3618 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
3619 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
3620 nesqp
->nesqp_context
->ird_ord_sizes
|=
3621 cpu_to_le32((u32
)1 <<
3622 NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
);
3623 nesqp
->nesqp_context
->ird_ord_sizes
|=
3624 cpu_to_le32((u32
)cm_node
->ord_size
);
3626 /* Adjust tail for not having a LSMM */
3627 /*nesqp->hwqp.sq_tail = 1;*/
3629 build_rdma0_msg(cm_node
, &nesqp
);
3631 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
,
3632 (1 << 24) | 0x00800000 | nesqp
->hwqp
.qp_id
);
3634 memset(&nes_quad
, 0, sizeof(nes_quad
));
3636 nes_quad
.DstIpAdrIndex
=
3637 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
3638 nes_quad
.SrcIpadr
= htonl(cm_node
->rem_addr
);
3639 nes_quad
.TcpPorts
[0] = htons(cm_node
->rem_port
);
3640 nes_quad
.TcpPorts
[1] = htons(cm_node
->loc_port
);
3642 /* Produce hash key */
3643 crc_value
= get_crc_value(&nes_quad
);
3644 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
3645 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
3646 nesqp
->hte_index
, nesqp
->hte_index
& nesadapter
->hte_index_mask
);
3648 nesqp
->hte_index
&= nesadapter
->hte_index_mask
;
3649 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
3651 nesqp
->ietf_frame
= &cm_node
->mpa_frame
;
3652 nesqp
->private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3653 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
3655 /* notify OF layer we successfully created the requested connection */
3656 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3657 cm_event
.status
= 0;
3658 cm_event
.provider_data
= cm_id
->provider_data
;
3659 cm_event_laddr
->sin_family
= AF_INET
;
3660 cm_event_laddr
->sin_port
= laddr
->sin_port
;
3661 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3663 cm_event
.private_data
= (void *)event
->cm_node
->mpa_frame_buf
;
3664 cm_event
.private_data_len
= (u8
)event
->cm_node
->mpa_frame_size
;
3665 cm_event
.ird
= cm_node
->ird_size
;
3666 cm_event
.ord
= cm_node
->ord_size
;
3668 cm_event_laddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3669 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3670 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3673 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3674 "ret=%d\n", __func__
, __LINE__
, ret
);
3675 attr
.qp_state
= IB_QPS_RTS
;
3676 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3678 nes_debug(NES_DBG_CM
, "Exiting connect thread for QP%u. jiffies = "
3679 "%lu\n", nesqp
->hwqp
.qp_id
, jiffies
);
3686 * cm_event_connect_error
3688 static void cm_event_connect_error(struct nes_cm_event
*event
)
3690 struct nes_qp
*nesqp
;
3691 struct iw_cm_id
*cm_id
;
3692 struct iw_cm_event cm_event
;
3693 /* struct nes_cm_info cm_info; */
3696 if (!event
->cm_node
)
3699 cm_id
= event
->cm_node
->cm_id
;
3703 nes_debug(NES_DBG_CM
, "cm_node=%p, cm_id=%p\n", event
->cm_node
, cm_id
);
3704 nesqp
= cm_id
->provider_data
;
3709 /* notify OF layer about this connection error event */
3710 /* cm_id->rem_ref(cm_id); */
3711 nesqp
->cm_id
= NULL
;
3712 cm_id
->provider_data
= NULL
;
3713 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3714 cm_event
.status
= -ECONNRESET
;
3715 cm_event
.provider_data
= cm_id
->provider_data
;
3716 cm_event
.local_addr
= cm_id
->m_local_addr
;
3717 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3718 cm_event
.private_data
= NULL
;
3719 cm_event
.private_data_len
= 0;
3721 #ifdef CONFIG_INFINIBAND_NES_DEBUG
3723 struct sockaddr_in
*cm_event_laddr
= (struct sockaddr_in
*)
3724 &cm_event
.local_addr
;
3725 struct sockaddr_in
*cm_event_raddr
= (struct sockaddr_in
*)
3726 &cm_event
.remote_addr
;
3727 nes_debug(NES_DBG_CM
, "call CM_EVENT REJECTED, local_addr=%08x, remote_addr=%08x\n",
3728 cm_event_laddr
->sin_addr
.s_addr
, cm_event_raddr
->sin_addr
.s_addr
);
3732 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3733 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3735 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3736 "ret=%d\n", __func__
, __LINE__
, ret
);
3737 cm_id
->rem_ref(cm_id
);
3739 rem_ref_cm_node(event
->cm_node
->cm_core
, event
->cm_node
);
3747 static void cm_event_reset(struct nes_cm_event
*event
)
3749 struct nes_qp
*nesqp
;
3750 struct iw_cm_id
*cm_id
;
3751 struct iw_cm_event cm_event
;
3752 /* struct nes_cm_info cm_info; */
3755 if (!event
->cm_node
)
3758 if (!event
->cm_node
->cm_id
)
3761 cm_id
= event
->cm_node
->cm_id
;
3763 nes_debug(NES_DBG_CM
, "%p - cm_id = %p\n", event
->cm_node
, cm_id
);
3764 nesqp
= cm_id
->provider_data
;
3768 nesqp
->cm_id
= NULL
;
3769 /* cm_id->provider_data = NULL; */
3770 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
3771 cm_event
.status
= -ECONNRESET
;
3772 cm_event
.provider_data
= cm_id
->provider_data
;
3773 cm_event
.local_addr
= cm_id
->m_local_addr
;
3774 cm_event
.remote_addr
= cm_id
->m_remote_addr
;
3775 cm_event
.private_data
= NULL
;
3776 cm_event
.private_data_len
= 0;
3778 cm_id
->add_ref(cm_id
);
3779 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3780 atomic_inc(&cm_closes
);
3781 cm_event
.event
= IW_CM_EVENT_CLOSE
;
3782 cm_event
.status
= 0;
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;
3788 nes_debug(NES_DBG_CM
, "NODE %p Generating CLOSE\n", event
->cm_node
);
3789 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3791 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3794 /* notify OF layer about this connection error event */
3795 cm_id
->rem_ref(cm_id
);
3804 static void cm_event_mpa_req(struct nes_cm_event
*event
)
3806 struct iw_cm_id
*cm_id
;
3807 struct iw_cm_event cm_event
;
3809 struct nes_cm_node
*cm_node
;
3810 struct sockaddr_in
*cm_event_laddr
= (struct sockaddr_in
*)
3811 &cm_event
.local_addr
;
3812 struct sockaddr_in
*cm_event_raddr
= (struct sockaddr_in
*)
3813 &cm_event
.remote_addr
;
3815 cm_node
= event
->cm_node
;
3818 cm_id
= cm_node
->cm_id
;
3820 atomic_inc(&cm_connect_reqs
);
3821 nes_debug(NES_DBG_CM
, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3822 cm_node
, cm_id
, jiffies
);
3824 cm_event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
3825 cm_event
.status
= 0;
3826 cm_event
.provider_data
= (void *)cm_node
;
3828 cm_event_laddr
->sin_family
= AF_INET
;
3829 cm_event_laddr
->sin_port
= htons(event
->cm_info
.loc_port
);
3830 cm_event_laddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3832 cm_event_raddr
->sin_family
= AF_INET
;
3833 cm_event_raddr
->sin_port
= htons(event
->cm_info
.rem_port
);
3834 cm_event_raddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.rem_addr
);
3835 cm_event
.private_data
= cm_node
->mpa_frame_buf
;
3836 cm_event
.private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3837 if (cm_node
->mpa_frame_rev
== IETF_MPA_V1
) {
3838 cm_event
.ird
= NES_MAX_IRD
;
3839 cm_event
.ord
= NES_MAX_ORD
;
3841 cm_event
.ird
= cm_node
->ird_size
;
3842 cm_event
.ord
= cm_node
->ord_size
;
3845 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3847 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, ret=%d\n",
3848 __func__
, __LINE__
, ret
);
3853 static void cm_event_mpa_reject(struct nes_cm_event
*event
)
3855 struct iw_cm_id
*cm_id
;
3856 struct iw_cm_event cm_event
;
3857 struct nes_cm_node
*cm_node
;
3859 struct sockaddr_in
*cm_event_laddr
= (struct sockaddr_in
*)
3860 &cm_event
.local_addr
;
3861 struct sockaddr_in
*cm_event_raddr
= (struct sockaddr_in
*)
3862 &cm_event
.remote_addr
;
3864 cm_node
= event
->cm_node
;
3867 cm_id
= cm_node
->cm_id
;
3869 atomic_inc(&cm_connect_reqs
);
3870 nes_debug(NES_DBG_CM
, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3871 cm_node
, cm_id
, jiffies
);
3873 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3874 cm_event
.status
= -ECONNREFUSED
;
3875 cm_event
.provider_data
= cm_id
->provider_data
;
3877 cm_event_laddr
->sin_family
= AF_INET
;
3878 cm_event_laddr
->sin_port
= htons(event
->cm_info
.loc_port
);
3879 cm_event_laddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3881 cm_event_raddr
->sin_family
= AF_INET
;
3882 cm_event_raddr
->sin_port
= htons(event
->cm_info
.rem_port
);
3883 cm_event_raddr
->sin_addr
.s_addr
= htonl(event
->cm_info
.rem_addr
);
3885 cm_event
.private_data
= cm_node
->mpa_frame_buf
;
3886 cm_event
.private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3888 nes_debug(NES_DBG_CM
, "call CM_EVENT_MPA_REJECTED, local_addr=%08x, "
3889 "remove_addr=%08x\n",
3890 cm_event_laddr
->sin_addr
.s_addr
,
3891 cm_event_raddr
->sin_addr
.s_addr
);
3893 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3895 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, ret=%d\n",
3896 __func__
, __LINE__
, ret
);
3902 static void nes_cm_event_handler(struct work_struct
*);
3906 * post an event to the cm event handler
3908 static int nes_cm_post_event(struct nes_cm_event
*event
)
3910 atomic_inc(&event
->cm_node
->cm_core
->events_posted
);
3911 add_ref_cm_node(event
->cm_node
);
3912 event
->cm_info
.cm_id
->add_ref(event
->cm_info
.cm_id
);
3913 INIT_WORK(&event
->event_work
, nes_cm_event_handler
);
3914 nes_debug(NES_DBG_CM
, "cm_node=%p queue_work, event=%p\n",
3915 event
->cm_node
, event
);
3917 queue_work(event
->cm_node
->cm_core
->event_wq
, &event
->event_work
);
3919 nes_debug(NES_DBG_CM
, "Exit\n");
3925 * nes_cm_event_handler
3926 * worker function to handle cm events
3927 * will free instance of nes_cm_event
3929 static void nes_cm_event_handler(struct work_struct
*work
)
3931 struct nes_cm_event
*event
= container_of(work
, struct nes_cm_event
,
3933 struct nes_cm_core
*cm_core
;
3935 if ((!event
) || (!event
->cm_node
) || (!event
->cm_node
->cm_core
))
3938 cm_core
= event
->cm_node
->cm_core
;
3939 nes_debug(NES_DBG_CM
, "event=%p, event->type=%u, events posted=%u\n",
3940 event
, event
->type
, atomic_read(&cm_core
->events_posted
));
3942 switch (event
->type
) {
3943 case NES_CM_EVENT_MPA_REQ
:
3944 cm_event_mpa_req(event
);
3945 nes_debug(NES_DBG_CM
, "cm_node=%p CM Event: MPA REQUEST\n",
3948 case NES_CM_EVENT_RESET
:
3949 nes_debug(NES_DBG_CM
, "cm_node = %p CM Event: RESET\n",
3951 cm_event_reset(event
);
3953 case NES_CM_EVENT_CONNECTED
:
3954 if ((!event
->cm_node
->cm_id
) ||
3955 (event
->cm_node
->state
!= NES_CM_STATE_TSA
))
3957 cm_event_connected(event
);
3958 nes_debug(NES_DBG_CM
, "CM Event: CONNECTED\n");
3960 case NES_CM_EVENT_MPA_REJECT
:
3961 if ((!event
->cm_node
->cm_id
) ||
3962 (event
->cm_node
->state
== NES_CM_STATE_TSA
))
3964 cm_event_mpa_reject(event
);
3965 nes_debug(NES_DBG_CM
, "CM Event: REJECT\n");
3968 case NES_CM_EVENT_ABORTED
:
3969 if ((!event
->cm_node
->cm_id
) ||
3970 (event
->cm_node
->state
== NES_CM_STATE_TSA
))
3972 cm_event_connect_error(event
);
3973 nes_debug(NES_DBG_CM
, "CM Event: ABORTED\n");
3975 case NES_CM_EVENT_DROPPED_PKT
:
3976 nes_debug(NES_DBG_CM
, "CM Event: DROPPED PKT\n");
3979 nes_debug(NES_DBG_CM
, "CM Event: UNKNOWN EVENT TYPE\n");
3983 atomic_dec(&cm_core
->events_posted
);
3984 event
->cm_info
.cm_id
->rem_ref(event
->cm_info
.cm_id
);
3985 rem_ref_cm_node(cm_core
, event
->cm_node
);