2 * Copyright (c) 2006 - 2011 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>
66 u32 cm_packets_bounced
;
67 u32 cm_packets_dropped
;
68 u32 cm_packets_retrans
;
69 u32 cm_packets_created
;
70 u32 cm_packets_received
;
71 atomic_t cm_listens_created
;
72 atomic_t cm_listens_destroyed
;
74 atomic_t cm_loopbacks
;
75 atomic_t cm_nodes_created
;
76 atomic_t cm_nodes_destroyed
;
77 atomic_t cm_accel_dropped_pkts
;
78 atomic_t cm_resets_recvd
;
80 static inline int mini_cm_accelerated(struct nes_cm_core
*, struct nes_cm_node
*);
81 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*, struct nes_vnic
*, struct nes_cm_info
*);
82 static int mini_cm_del_listen(struct nes_cm_core
*, struct nes_cm_listener
*);
83 static struct nes_cm_node
*mini_cm_connect(struct nes_cm_core
*, struct nes_vnic
*, u16
, void *, struct nes_cm_info
*);
84 static int mini_cm_close(struct nes_cm_core
*, struct nes_cm_node
*);
85 static int mini_cm_accept(struct nes_cm_core
*, struct nes_cm_node
*);
86 static int mini_cm_reject(struct nes_cm_core
*, struct nes_cm_node
*);
87 static int mini_cm_recv_pkt(struct nes_cm_core
*, struct nes_vnic
*, struct sk_buff
*);
88 static int mini_cm_dealloc_core(struct nes_cm_core
*);
89 static int mini_cm_get(struct nes_cm_core
*);
90 static int mini_cm_set(struct nes_cm_core
*, u32
, u32
);
92 static void form_cm_frame(struct sk_buff
*, struct nes_cm_node
*, void *, u32
, void *, u32
, u8
);
93 static int add_ref_cm_node(struct nes_cm_node
*);
94 static int rem_ref_cm_node(struct nes_cm_core
*, struct nes_cm_node
*);
96 static int nes_cm_disconn_true(struct nes_qp
*);
97 static int nes_cm_post_event(struct nes_cm_event
*event
);
98 static int nes_disconnect(struct nes_qp
*nesqp
, int abrupt
);
99 static void nes_disconnect_worker(struct work_struct
*work
);
101 static int send_mpa_request(struct nes_cm_node
*, struct sk_buff
*);
102 static int send_mpa_reject(struct nes_cm_node
*);
103 static int send_syn(struct nes_cm_node
*, u32
, struct sk_buff
*);
104 static int send_reset(struct nes_cm_node
*, struct sk_buff
*);
105 static int send_ack(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
);
106 static int send_fin(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
);
107 static void process_packet(struct nes_cm_node
*, struct sk_buff
*, struct nes_cm_core
*);
109 static void active_open_err(struct nes_cm_node
*, struct sk_buff
*, int);
110 static void passive_open_err(struct nes_cm_node
*, struct sk_buff
*, int);
111 static void cleanup_retrans_entry(struct nes_cm_node
*);
112 static void handle_rcv_mpa(struct nes_cm_node
*, struct sk_buff
*);
113 static void free_retrans_entry(struct nes_cm_node
*cm_node
);
114 static int handle_tcp_options(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
, struct sk_buff
*skb
, int optionsize
, int passive
);
116 /* CM event handler functions */
117 static void cm_event_connected(struct nes_cm_event
*);
118 static void cm_event_connect_error(struct nes_cm_event
*);
119 static void cm_event_reset(struct nes_cm_event
*);
120 static void cm_event_mpa_req(struct nes_cm_event
*);
121 static void cm_event_mpa_reject(struct nes_cm_event
*);
122 static void handle_recv_entry(struct nes_cm_node
*cm_node
, u32 rem_node
);
124 /* MPA build functions */
125 static int cm_build_mpa_frame(struct nes_cm_node
*, u8
**, u16
*, u8
*, u8
);
126 static void build_mpa_v2(struct nes_cm_node
*, void *, u8
);
127 static void build_mpa_v1(struct nes_cm_node
*, void *, u8
);
128 static void build_rdma0_msg(struct nes_cm_node
*, struct nes_qp
**);
130 static void print_core(struct nes_cm_core
*core
);
132 /* External CM API Interface */
133 /* instance of function pointers for client API */
134 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
135 static struct nes_cm_ops nes_cm_api
= {
144 mini_cm_dealloc_core
,
149 static struct nes_cm_core
*g_cm_core
;
151 atomic_t cm_connects
;
153 atomic_t cm_disconnects
;
155 atomic_t cm_connecteds
;
156 atomic_t cm_connect_reqs
;
159 int nes_add_ref_cm_node(struct nes_cm_node
*cm_node
)
161 return add_ref_cm_node(cm_node
);
164 int nes_rem_ref_cm_node(struct nes_cm_node
*cm_node
)
166 return rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
172 static struct nes_cm_event
*create_event(struct nes_cm_node
* cm_node
,
173 enum nes_cm_event_type type
)
175 struct nes_cm_event
*event
;
180 /* allocate an empty event */
181 event
= kzalloc(sizeof(*event
), GFP_ATOMIC
);
187 event
->cm_node
= cm_node
;
188 event
->cm_info
.rem_addr
= cm_node
->rem_addr
;
189 event
->cm_info
.loc_addr
= cm_node
->loc_addr
;
190 event
->cm_info
.rem_port
= cm_node
->rem_port
;
191 event
->cm_info
.loc_port
= cm_node
->loc_port
;
192 event
->cm_info
.cm_id
= cm_node
->cm_id
;
194 nes_debug(NES_DBG_CM
, "cm_node=%p Created event=%p, type=%u, "
195 "dst_addr=%08x[%x], src_addr=%08x[%x]\n",
196 cm_node
, event
, type
, event
->cm_info
.loc_addr
,
197 event
->cm_info
.loc_port
, event
->cm_info
.rem_addr
,
198 event
->cm_info
.rem_port
);
200 nes_cm_post_event(event
);
208 static int send_mpa_request(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
211 u8
*start_ptr
= &start_addr
;
212 u8
**start_buff
= &start_ptr
;
216 nes_debug(NES_DBG_CM
, "skb set to NULL\n");
220 /* send an MPA Request frame */
221 cm_build_mpa_frame(cm_node
, start_buff
, &buff_len
, NULL
, MPA_KEY_REQUEST
);
222 form_cm_frame(skb
, cm_node
, NULL
, 0, *start_buff
, buff_len
, SET_ACK
);
224 return schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
229 static int send_mpa_reject(struct nes_cm_node
*cm_node
)
231 struct sk_buff
*skb
= NULL
;
233 u8
*start_ptr
= &start_addr
;
234 u8
**start_buff
= &start_ptr
;
236 struct ietf_mpa_v1
*mpa_frame
;
238 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
240 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
244 /* send an MPA reject frame */
245 cm_build_mpa_frame(cm_node
, start_buff
, &buff_len
, NULL
, MPA_KEY_REPLY
);
246 mpa_frame
= (struct ietf_mpa_v1
*)*start_buff
;
247 mpa_frame
->flags
|= IETF_MPA_FLAGS_REJECT
;
248 form_cm_frame(skb
, cm_node
, NULL
, 0, *start_buff
, buff_len
, SET_ACK
| SET_FIN
);
250 cm_node
->state
= NES_CM_STATE_FIN_WAIT1
;
251 return schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
256 * recv_mpa - process a received TCP pkt, we are expecting an
259 static int parse_mpa(struct nes_cm_node
*cm_node
, u8
*buffer
, u32
*type
,
262 struct ietf_mpa_v1
*mpa_frame
;
263 struct ietf_mpa_v2
*mpa_v2_frame
;
264 struct ietf_rtr_msg
*rtr_msg
;
268 *type
= NES_MPA_REQUEST_ACCEPT
;
270 /* assume req frame is in tcp data payload */
271 if (len
< sizeof(struct ietf_mpa_v1
)) {
272 nes_debug(NES_DBG_CM
, "The received ietf buffer was too small (%x)\n", len
);
276 /* points to the beginning of the frame, which could be MPA V1 or V2 */
277 mpa_frame
= (struct ietf_mpa_v1
*)buffer
;
278 mpa_hdr_len
= sizeof(struct ietf_mpa_v1
);
279 priv_data_len
= ntohs(mpa_frame
->priv_data_len
);
281 /* make sure mpa private data len is less than 512 bytes */
282 if (priv_data_len
> IETF_MAX_PRIV_DATA_LEN
) {
283 nes_debug(NES_DBG_CM
, "The received Length of Private"
284 " Data field exceeds 512 octets\n");
288 * make sure MPA receiver interoperate with the
289 * received MPA version and MPA key information
292 if (mpa_frame
->rev
!= IETF_MPA_V1
&& mpa_frame
->rev
!= IETF_MPA_V2
) {
293 nes_debug(NES_DBG_CM
, "The received mpa version"
294 " is not supported\n");
298 * backwards compatibility only
300 if (mpa_frame
->rev
> cm_node
->mpa_frame_rev
) {
301 nes_debug(NES_DBG_CM
, "The received mpa version"
302 " can not be interoperated\n");
305 cm_node
->mpa_frame_rev
= mpa_frame
->rev
;
308 if (cm_node
->state
!= NES_CM_STATE_MPAREQ_SENT
) {
309 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
)) {
310 nes_debug(NES_DBG_CM
, "Unexpected MPA Key received \n");
314 if (memcmp(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
)) {
315 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
)) {
360 if (cm_node
->state
!= NES_CM_STATE_MPAREQ_SENT
) {
362 if (cm_node
->ord_size
> ird_size
)
363 cm_node
->ord_size
= ird_size
;
366 if (cm_node
->ord_size
> ird_size
)
367 cm_node
->ord_size
= ird_size
;
369 if (cm_node
->ird_size
< ord_size
) {
370 /* no resources available */
371 /* send terminate message */
376 if (rtr_ctrl_ord
& IETF_RDMA0_READ
) {
377 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
378 } else if (rtr_ctrl_ord
& IETF_RDMA0_WRITE
) {
379 cm_node
->send_rdma0_op
= SEND_RDMA_WRITE_ZERO
;
380 } else { /* Not supported RDMA0 operation */
390 /* copy entire MPA frame to our cm_node's frame */
391 memcpy(cm_node
->mpa_frame_buf
, buffer
+ mpa_hdr_len
, cm_node
->mpa_frame_size
);
393 if (mpa_frame
->flags
& IETF_MPA_FLAGS_REJECT
)
394 *type
= NES_MPA_REQUEST_REJECT
;
400 * form_cm_frame - get a free packet and build empty frame Use
401 * node info to build.
403 static void form_cm_frame(struct sk_buff
*skb
,
404 struct nes_cm_node
*cm_node
, void *options
, u32 optionsize
,
405 void *data
, u32 datasize
, u8 flags
)
411 u16 packetsize
= sizeof(*iph
);
413 packetsize
+= sizeof(*tcph
);
414 packetsize
+= optionsize
+ datasize
;
417 memset(skb
->data
, 0x00, ETH_HLEN
+ sizeof(*iph
) + sizeof(*tcph
));
419 buf
= skb_put(skb
, packetsize
+ ETH_HLEN
);
421 ethh
= (struct ethhdr
*)buf
;
424 iph
= (struct iphdr
*)buf
;
426 tcph
= (struct tcphdr
*)buf
;
427 skb_reset_mac_header(skb
);
428 skb_set_network_header(skb
, ETH_HLEN
);
429 skb_set_transport_header(skb
, ETH_HLEN
+ sizeof(*iph
));
430 buf
+= sizeof(*tcph
);
432 skb
->ip_summed
= CHECKSUM_PARTIAL
;
433 skb
->protocol
= htons(0x800);
435 skb
->mac_len
= ETH_HLEN
;
437 memcpy(ethh
->h_dest
, cm_node
->rem_mac
, ETH_ALEN
);
438 memcpy(ethh
->h_source
, cm_node
->loc_mac
, ETH_ALEN
);
439 ethh
->h_proto
= htons(0x0800);
441 iph
->version
= IPVERSION
;
442 iph
->ihl
= 5; /* 5 * 4Byte words, IP headr len */
444 iph
->tot_len
= htons(packetsize
);
445 iph
->id
= htons(++cm_node
->tcp_cntxt
.loc_id
);
447 iph
->frag_off
= htons(0x4000);
449 iph
->protocol
= 0x06; /* IPPROTO_TCP */
451 iph
->saddr
= htonl(cm_node
->loc_addr
);
452 iph
->daddr
= htonl(cm_node
->rem_addr
);
454 tcph
->source
= htons(cm_node
->loc_port
);
455 tcph
->dest
= htons(cm_node
->rem_port
);
456 tcph
->seq
= htonl(cm_node
->tcp_cntxt
.loc_seq_num
);
458 if (flags
& SET_ACK
) {
459 cm_node
->tcp_cntxt
.loc_ack_num
= cm_node
->tcp_cntxt
.rcv_nxt
;
460 tcph
->ack_seq
= htonl(cm_node
->tcp_cntxt
.loc_ack_num
);
466 if (flags
& SET_SYN
) {
467 cm_node
->tcp_cntxt
.loc_seq_num
++;
470 cm_node
->tcp_cntxt
.loc_seq_num
+= datasize
;
473 if (flags
& SET_FIN
) {
474 cm_node
->tcp_cntxt
.loc_seq_num
++;
481 tcph
->doff
= (u16
)((sizeof(*tcph
) + optionsize
+ 3) >> 2);
482 tcph
->window
= htons(cm_node
->tcp_cntxt
.rcv_wnd
);
485 memcpy(buf
, options
, optionsize
);
488 memcpy(buf
, data
, datasize
);
490 skb_shinfo(skb
)->nr_frags
= 0;
491 cm_packets_created
++;
495 * print_core - dump a cm core
497 static void print_core(struct nes_cm_core
*core
)
499 nes_debug(NES_DBG_CM
, "---------------------------------------------\n");
500 nes_debug(NES_DBG_CM
, "CM Core -- (core = %p )\n", core
);
503 nes_debug(NES_DBG_CM
, "---------------------------------------------\n");
505 nes_debug(NES_DBG_CM
, "State : %u \n", core
->state
);
507 nes_debug(NES_DBG_CM
, "Listen Nodes : %u \n", atomic_read(&core
->listen_node_cnt
));
508 nes_debug(NES_DBG_CM
, "Active Nodes : %u \n", atomic_read(&core
->node_cnt
));
510 nes_debug(NES_DBG_CM
, "core : %p \n", core
);
512 nes_debug(NES_DBG_CM
, "-------------- end core ---------------\n");
516 * cm_build_mpa_frame - build a MPA V1 frame or MPA V2 frame
518 static int cm_build_mpa_frame(struct nes_cm_node
*cm_node
, u8
**start_buff
,
519 u16
*buff_len
, u8
*pci_mem
, u8 mpa_key
)
523 *start_buff
= (pci_mem
) ? pci_mem
: &cm_node
->mpa_frame_buf
[0];
525 switch (cm_node
->mpa_frame_rev
) {
527 *start_buff
= (u8
*)*start_buff
+ sizeof(struct ietf_rtr_msg
);
528 *buff_len
= sizeof(struct ietf_mpa_v1
) + cm_node
->mpa_frame_size
;
529 build_mpa_v1(cm_node
, *start_buff
, mpa_key
);
532 *buff_len
= sizeof(struct ietf_mpa_v2
) + cm_node
->mpa_frame_size
;
533 build_mpa_v2(cm_node
, *start_buff
, mpa_key
);
542 * build_mpa_v2 - build a MPA V2 frame
544 static void build_mpa_v2(struct nes_cm_node
*cm_node
,
545 void *start_addr
, u8 mpa_key
)
547 struct ietf_mpa_v2
*mpa_frame
= (struct ietf_mpa_v2
*)start_addr
;
548 struct ietf_rtr_msg
*rtr_msg
= &mpa_frame
->rtr_msg
;
552 /* initialize the upper 5 bytes of the frame */
553 build_mpa_v1(cm_node
, start_addr
, mpa_key
);
554 mpa_frame
->flags
|= IETF_MPA_V2_FLAG
; /* set a bit to indicate MPA V2 */
555 mpa_frame
->priv_data_len
+= htons(IETF_RTR_MSG_SIZE
);
557 /* initialize RTR msg */
558 ctrl_ird
= (cm_node
->ird_size
> IETF_NO_IRD_ORD
) ?
559 IETF_NO_IRD_ORD
: cm_node
->ird_size
;
560 ctrl_ord
= (cm_node
->ord_size
> IETF_NO_IRD_ORD
) ?
561 IETF_NO_IRD_ORD
: cm_node
->ord_size
;
563 ctrl_ird
|= IETF_PEER_TO_PEER
;
564 ctrl_ird
|= IETF_FLPDU_ZERO_LEN
;
567 case MPA_KEY_REQUEST
:
568 ctrl_ord
|= IETF_RDMA0_WRITE
;
569 ctrl_ord
|= IETF_RDMA0_READ
;
572 switch (cm_node
->send_rdma0_op
) {
573 case SEND_RDMA_WRITE_ZERO
:
574 ctrl_ord
|= IETF_RDMA0_WRITE
;
576 case SEND_RDMA_READ_ZERO
:
577 ctrl_ord
|= IETF_RDMA0_READ
;
581 rtr_msg
->ctrl_ird
= htons(ctrl_ird
);
582 rtr_msg
->ctrl_ord
= htons(ctrl_ord
);
586 * build_mpa_v1 - build a MPA V1 frame
588 static void build_mpa_v1(struct nes_cm_node
*cm_node
, void *start_addr
, u8 mpa_key
)
590 struct ietf_mpa_v1
*mpa_frame
= (struct ietf_mpa_v1
*)start_addr
;
593 case MPA_KEY_REQUEST
:
594 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REQ
, IETF_MPA_KEY_SIZE
);
597 memcpy(mpa_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
);
600 mpa_frame
->flags
= IETF_MPA_FLAGS_CRC
;
601 mpa_frame
->rev
= cm_node
->mpa_frame_rev
;
602 mpa_frame
->priv_data_len
= htons(cm_node
->mpa_frame_size
);
605 static void build_rdma0_msg(struct nes_cm_node
*cm_node
, struct nes_qp
**nesqp_addr
)
608 struct nes_qp
*nesqp
= *nesqp_addr
;
609 struct nes_hw_qp_wqe
*wqe
= &nesqp
->hwqp
.sq_vbase
[0];
611 u64temp
= (unsigned long)nesqp
;
612 u64temp
|= NES_SW_CONTEXT_ALIGN
>> 1;
613 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
, u64temp
);
615 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
] = 0;
616 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX
] = 0;
618 switch (cm_node
->send_rdma0_op
) {
619 case SEND_RDMA_WRITE_ZERO
:
620 nes_debug(NES_DBG_CM
, "Sending first write.\n");
621 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
622 cpu_to_le32(NES_IWARP_SQ_OP_RDMAW
);
623 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] = 0;
624 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] = 0;
625 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 0;
628 case SEND_RDMA_READ_ZERO
:
630 if (cm_node
->send_rdma0_op
!= SEND_RDMA_READ_ZERO
) {
631 printk(KERN_ERR
"%s[%u]: Unsupported RDMA0 len operation=%u\n",
632 __func__
, __LINE__
, cm_node
->send_rdma0_op
);
635 nes_debug(NES_DBG_CM
, "Sending first rdma operation.\n");
636 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
637 cpu_to_le32(NES_IWARP_SQ_OP_RDMAR
);
638 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX
] = 1;
639 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_TO_HIGH_IDX
] = 0;
640 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX
] = 0;
641 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_STAG_IDX
] = 1;
642 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 1;
646 if (nesqp
->sq_kmapped
) {
647 nesqp
->sq_kmapped
= 0;
651 /*use the reserved spot on the WQ for the extra first WQE*/
652 nesqp
->nesqp_context
->ird_ord_sizes
&= cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
653 NES_QPCONTEXT_ORDIRD_WRPDU
|
654 NES_QPCONTEXT_ORDIRD_ALSMM
));
655 nesqp
->skip_lsmm
= 1;
656 nesqp
->hwqp
.sq_tail
= 0;
661 * note - cm_node needs to be protected before calling this. Encase in:
662 * rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
664 int schedule_nes_timer(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
665 enum nes_timer_type type
, int send_retrans
,
666 int close_when_complete
)
669 struct nes_cm_core
*cm_core
= cm_node
->cm_core
;
670 struct nes_timer_entry
*new_send
;
674 new_send
= kzalloc(sizeof(*new_send
), GFP_ATOMIC
);
678 /* new_send->timetosend = currenttime */
679 new_send
->retrycount
= NES_DEFAULT_RETRYS
;
680 new_send
->retranscount
= NES_DEFAULT_RETRANS
;
682 new_send
->timetosend
= jiffies
;
683 new_send
->type
= type
;
684 new_send
->netdev
= cm_node
->netdev
;
685 new_send
->send_retrans
= send_retrans
;
686 new_send
->close_when_complete
= close_when_complete
;
688 if (type
== NES_TIMER_TYPE_CLOSE
) {
689 new_send
->timetosend
+= (HZ
/ 10);
690 if (cm_node
->recv_entry
) {
695 cm_node
->recv_entry
= new_send
;
698 if (type
== NES_TIMER_TYPE_SEND
) {
699 new_send
->seq_num
= ntohl(tcp_hdr(skb
)->seq
);
700 atomic_inc(&new_send
->skb
->users
);
701 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
702 cm_node
->send_entry
= new_send
;
703 add_ref_cm_node(cm_node
);
704 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
705 new_send
->timetosend
= jiffies
+ NES_RETRY_TIMEOUT
;
707 ret
= nes_nic_cm_xmit(new_send
->skb
, cm_node
->netdev
);
708 if (ret
!= NETDEV_TX_OK
) {
709 nes_debug(NES_DBG_CM
, "Error sending packet %p "
710 "(jiffies = %lu)\n", new_send
, jiffies
);
711 new_send
->timetosend
= jiffies
;
716 cleanup_retrans_entry(cm_node
);
717 if (close_when_complete
)
718 rem_ref_cm_node(cm_core
, cm_node
);
724 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
726 if (!was_timer_set
) {
727 cm_core
->tcp_timer
.expires
= new_send
->timetosend
;
728 add_timer(&cm_core
->tcp_timer
);
734 static void nes_retrans_expired(struct nes_cm_node
*cm_node
)
736 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
737 enum nes_cm_node_state state
= cm_node
->state
;
738 cm_node
->state
= NES_CM_STATE_CLOSED
;
741 case NES_CM_STATE_SYN_RCVD
:
742 case NES_CM_STATE_CLOSING
:
743 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
745 case NES_CM_STATE_LAST_ACK
:
746 case NES_CM_STATE_FIN_WAIT1
:
748 cm_id
->rem_ref(cm_id
);
749 send_reset(cm_node
, NULL
);
752 add_ref_cm_node(cm_node
);
753 send_reset(cm_node
, NULL
);
754 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
758 static void handle_recv_entry(struct nes_cm_node
*cm_node
, u32 rem_node
)
760 struct nes_timer_entry
*recv_entry
= cm_node
->recv_entry
;
761 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
762 struct nes_qp
*nesqp
;
763 unsigned long qplockflags
;
767 nesqp
= (struct nes_qp
*)recv_entry
->skb
;
769 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
771 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, "
772 "refcount = %d: HIT A "
773 "NES_TIMER_TYPE_CLOSE with something "
774 "to do!!!\n", nesqp
->hwqp
.qp_id
, cm_id
,
775 atomic_read(&nesqp
->refcount
));
776 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
777 nesqp
->last_aeq
= NES_AEQE_AEID_RESET_SENT
;
778 nesqp
->ibqp_state
= IB_QPS_ERR
;
779 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
780 nes_cm_disconn(nesqp
);
782 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
783 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, "
784 "refcount = %d: HIT A "
785 "NES_TIMER_TYPE_CLOSE with nothing "
786 "to do!!!\n", nesqp
->hwqp
.qp_id
, cm_id
,
787 atomic_read(&nesqp
->refcount
));
789 } else if (rem_node
) {
790 /* TIME_WAIT state */
791 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
794 cm_id
->rem_ref(cm_id
);
796 cm_node
->recv_entry
= NULL
;
802 static void nes_cm_timer_tick(unsigned long pass
)
805 unsigned long nexttimeout
= jiffies
+ NES_LONG_TIME
;
806 struct nes_cm_node
*cm_node
;
807 struct nes_timer_entry
*send_entry
, *recv_entry
;
808 struct list_head
*list_core_temp
;
809 struct list_head
*list_node
;
810 struct nes_cm_core
*cm_core
= g_cm_core
;
812 unsigned long timetosend
;
813 int ret
= NETDEV_TX_OK
;
815 struct list_head timer_list
;
817 INIT_LIST_HEAD(&timer_list
);
818 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
820 list_for_each_safe(list_node
, list_core_temp
,
821 &cm_core
->connected_nodes
) {
822 cm_node
= container_of(list_node
, struct nes_cm_node
, list
);
823 if ((cm_node
->recv_entry
) || (cm_node
->send_entry
)) {
824 add_ref_cm_node(cm_node
);
825 list_add(&cm_node
->timer_entry
, &timer_list
);
828 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
830 list_for_each_safe(list_node
, list_core_temp
, &timer_list
) {
831 cm_node
= container_of(list_node
, struct nes_cm_node
,
833 recv_entry
= cm_node
->recv_entry
;
836 if (time_after(recv_entry
->timetosend
, jiffies
)) {
837 if (nexttimeout
> recv_entry
->timetosend
||
839 nexttimeout
= recv_entry
->timetosend
;
843 handle_recv_entry(cm_node
, 1);
847 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
849 send_entry
= cm_node
->send_entry
;
852 if (time_after(send_entry
->timetosend
, jiffies
)) {
853 if (cm_node
->state
!= NES_CM_STATE_TSA
) {
855 send_entry
->timetosend
) ||
858 send_entry
->timetosend
;
862 free_retrans_entry(cm_node
);
867 if ((cm_node
->state
== NES_CM_STATE_TSA
) ||
868 (cm_node
->state
== NES_CM_STATE_CLOSED
)) {
869 free_retrans_entry(cm_node
);
873 if (!send_entry
->retranscount
||
874 !send_entry
->retrycount
) {
875 cm_packets_dropped
++;
876 free_retrans_entry(cm_node
);
878 spin_unlock_irqrestore(
879 &cm_node
->retrans_list_lock
, flags
);
880 nes_retrans_expired(cm_node
);
881 cm_node
->state
= NES_CM_STATE_CLOSED
;
882 spin_lock_irqsave(&cm_node
->retrans_list_lock
,
886 atomic_inc(&send_entry
->skb
->users
);
887 cm_packets_retrans
++;
888 nes_debug(NES_DBG_CM
, "Retransmitting send_entry %p "
889 "for node %p, jiffies = %lu, time to send = "
890 "%lu, retranscount = %u, send_entry->seq_num = "
891 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
892 "0x%08X\n", send_entry
, cm_node
, jiffies
,
893 send_entry
->timetosend
,
894 send_entry
->retranscount
,
896 cm_node
->tcp_cntxt
.rem_ack_num
);
898 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
,
900 ret
= nes_nic_cm_xmit(send_entry
->skb
, cm_node
->netdev
);
901 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
902 if (ret
!= NETDEV_TX_OK
) {
903 nes_debug(NES_DBG_CM
, "rexmit failed for "
904 "node=%p\n", cm_node
);
905 cm_packets_bounced
++;
906 send_entry
->retrycount
--;
907 nexttimeout
= jiffies
+ NES_SHORT_TIME
;
913 nes_debug(NES_DBG_CM
, "Packet Sent: retrans count = "
914 "%u, retry count = %u.\n",
915 send_entry
->retranscount
,
916 send_entry
->retrycount
);
917 if (send_entry
->send_retrans
) {
918 send_entry
->retranscount
--;
919 timetosend
= (NES_RETRY_TIMEOUT
<<
920 (NES_DEFAULT_RETRANS
- send_entry
->retranscount
));
922 send_entry
->timetosend
= jiffies
+
923 min(timetosend
, NES_MAX_TIMEOUT
);
924 if (nexttimeout
> send_entry
->timetosend
||
926 nexttimeout
= send_entry
->timetosend
;
930 int close_when_complete
;
931 close_when_complete
=
932 send_entry
->close_when_complete
;
933 nes_debug(NES_DBG_CM
, "cm_node=%p state=%d\n",
934 cm_node
, cm_node
->state
);
935 free_retrans_entry(cm_node
);
936 if (close_when_complete
)
937 rem_ref_cm_node(cm_node
->cm_core
,
942 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
943 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
947 if (!timer_pending(&cm_core
->tcp_timer
)) {
948 cm_core
->tcp_timer
.expires
= nexttimeout
;
949 add_timer(&cm_core
->tcp_timer
);
958 static int send_syn(struct nes_cm_node
*cm_node
, u32 sendack
,
963 char optionsbuffer
[sizeof(struct option_mss
) +
964 sizeof(struct option_windowscale
) + sizeof(struct option_base
) +
965 TCP_OPTIONS_PADDING
];
968 /* Sending MSS option */
969 union all_known_options
*options
;
974 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
975 options
->as_mss
.optionnum
= OPTION_NUMBER_MSS
;
976 options
->as_mss
.length
= sizeof(struct option_mss
);
977 options
->as_mss
.mss
= htons(cm_node
->tcp_cntxt
.mss
);
978 optionssize
+= sizeof(struct option_mss
);
980 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
981 options
->as_windowscale
.optionnum
= OPTION_NUMBER_WINDOW_SCALE
;
982 options
->as_windowscale
.length
= sizeof(struct option_windowscale
);
983 options
->as_windowscale
.shiftcount
= cm_node
->tcp_cntxt
.rcv_wscale
;
984 optionssize
+= sizeof(struct option_windowscale
);
986 if (sendack
&& !(NES_DRV_OPT_SUPRESS_OPTION_BC
& nes_drv_opt
)) {
987 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
988 options
->as_base
.optionnum
= OPTION_NUMBER_WRITE0
;
989 options
->as_base
.length
= sizeof(struct option_base
);
990 optionssize
+= sizeof(struct option_base
);
991 /* we need the size to be a multiple of 4 */
992 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
995 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1000 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
1001 options
->as_end
= OPTION_NUMBER_END
;
1005 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1007 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1014 form_cm_frame(skb
, cm_node
, optionsbuffer
, optionssize
, NULL
, 0, flags
);
1015 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
1024 static int send_reset(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1027 int flags
= SET_RST
| SET_ACK
;
1030 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1032 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1036 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, flags
);
1037 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 1);
1046 static int send_ack(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1051 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1054 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1058 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
);
1059 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 0);
1068 static int send_fin(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1072 /* if we didn't get a frame get one */
1074 skb
= dev_alloc_skb(MAX_CM_BUFFER
);
1077 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1081 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
| SET_FIN
);
1082 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
1089 * find_node - find a cm node that matches the reference cm node
1091 static struct nes_cm_node
*find_node(struct nes_cm_core
*cm_core
,
1092 u16 rem_port
, nes_addr_t rem_addr
, u16 loc_port
, nes_addr_t loc_addr
)
1094 unsigned long flags
;
1095 struct list_head
*hte
;
1096 struct nes_cm_node
*cm_node
;
1098 /* get a handle on the hte */
1099 hte
= &cm_core
->connected_nodes
;
1101 /* walk list and find cm_node associated with this session ID */
1102 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1103 list_for_each_entry(cm_node
, hte
, list
) {
1104 /* compare quad, return node handle if a match */
1105 nes_debug(NES_DBG_CM
, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
1106 cm_node
->loc_addr
, cm_node
->loc_port
,
1108 cm_node
->rem_addr
, cm_node
->rem_port
,
1109 rem_addr
, rem_port
);
1110 if ((cm_node
->loc_addr
== loc_addr
) && (cm_node
->loc_port
== loc_port
) &&
1111 (cm_node
->rem_addr
== rem_addr
) && (cm_node
->rem_port
== rem_port
)) {
1112 add_ref_cm_node(cm_node
);
1113 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1117 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1125 * find_listener - find a cm node listening on this addr-port pair
1127 static struct nes_cm_listener
*find_listener(struct nes_cm_core
*cm_core
,
1128 nes_addr_t dst_addr
, u16 dst_port
, enum nes_cm_listener_state listener_state
)
1130 unsigned long flags
;
1131 struct nes_cm_listener
*listen_node
;
1133 /* walk list and find cm_node associated with this session ID */
1134 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1135 list_for_each_entry(listen_node
, &cm_core
->listen_list
.list
, list
) {
1136 /* compare node pair, return node handle if a match */
1137 if (((listen_node
->loc_addr
== dst_addr
) ||
1138 listen_node
->loc_addr
== 0x00000000) &&
1139 (listen_node
->loc_port
== dst_port
) &&
1140 (listener_state
& listen_node
->listener_state
)) {
1141 atomic_inc(&listen_node
->ref_count
);
1142 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1146 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1154 * add_hte_node - add a cm node to the hash table
1156 static int add_hte_node(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
1158 unsigned long flags
;
1159 struct list_head
*hte
;
1161 if (!cm_node
|| !cm_core
)
1164 nes_debug(NES_DBG_CM
, "Adding Node %p to Active Connection HT\n",
1167 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1169 /* get a handle on the hash table element (list head for this slot) */
1170 hte
= &cm_core
->connected_nodes
;
1171 list_add_tail(&cm_node
->list
, hte
);
1172 atomic_inc(&cm_core
->ht_node_cnt
);
1174 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1181 * mini_cm_dec_refcnt_listen
1183 static int mini_cm_dec_refcnt_listen(struct nes_cm_core
*cm_core
,
1184 struct nes_cm_listener
*listener
, int free_hanging_nodes
)
1188 unsigned long flags
;
1189 struct list_head
*list_pos
= NULL
;
1190 struct list_head
*list_temp
= NULL
;
1191 struct nes_cm_node
*cm_node
= NULL
;
1192 struct list_head reset_list
;
1194 nes_debug(NES_DBG_CM
, "attempting listener= %p free_nodes= %d, "
1195 "refcnt=%d\n", listener
, free_hanging_nodes
,
1196 atomic_read(&listener
->ref_count
));
1197 /* free non-accelerated child nodes for this listener */
1198 INIT_LIST_HEAD(&reset_list
);
1199 if (free_hanging_nodes
) {
1200 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
1201 list_for_each_safe(list_pos
, list_temp
,
1202 &g_cm_core
->connected_nodes
) {
1203 cm_node
= container_of(list_pos
, struct nes_cm_node
,
1205 if ((cm_node
->listener
== listener
) &&
1206 (!cm_node
->accelerated
)) {
1207 add_ref_cm_node(cm_node
);
1208 list_add(&cm_node
->reset_entry
, &reset_list
);
1211 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
1214 list_for_each_safe(list_pos
, list_temp
, &reset_list
) {
1215 cm_node
= container_of(list_pos
, struct nes_cm_node
,
1218 struct nes_cm_node
*loopback
= cm_node
->loopbackpartner
;
1219 enum nes_cm_node_state old_state
;
1220 if (NES_CM_STATE_FIN_WAIT1
<= cm_node
->state
) {
1221 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1224 cleanup_retrans_entry(cm_node
);
1225 err
= send_reset(cm_node
, NULL
);
1228 NES_CM_STATE_CLOSED
;
1231 old_state
= cm_node
->state
;
1232 cm_node
->state
= NES_CM_STATE_LISTENER_DESTROYED
;
1233 if (old_state
!= NES_CM_STATE_MPAREQ_RCVD
)
1239 struct nes_cm_event event
;
1241 event
.cm_node
= loopback
;
1242 event
.cm_info
.rem_addr
=
1244 event
.cm_info
.loc_addr
=
1246 event
.cm_info
.rem_port
=
1248 event
.cm_info
.loc_port
=
1250 event
.cm_info
.cm_id
= loopback
->cm_id
;
1251 add_ref_cm_node(loopback
);
1252 loopback
->state
= NES_CM_STATE_CLOSED
;
1253 cm_event_connect_error(&event
);
1254 cm_node
->state
= NES_CM_STATE_LISTENER_DESTROYED
;
1256 rem_ref_cm_node(cm_node
->cm_core
,
1264 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1265 if (!atomic_dec_return(&listener
->ref_count
)) {
1266 list_del(&listener
->list
);
1268 /* decrement our listen node count */
1269 atomic_dec(&cm_core
->listen_node_cnt
);
1271 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1273 if (listener
->nesvnic
)
1274 nes_manage_apbvt(listener
->nesvnic
, listener
->loc_port
,
1275 PCI_FUNC(listener
->nesvnic
->nesdev
->pcidev
->devfn
), NES_MANAGE_APBVT_DEL
);
1277 nes_debug(NES_DBG_CM
, "destroying listener (%p)\n", listener
);
1282 atomic_inc(&cm_listens_destroyed
);
1284 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1287 if (atomic_read(&listener
->pend_accepts_cnt
) > 0)
1288 nes_debug(NES_DBG_CM
, "destroying listener (%p)"
1289 " with non-zero pending accepts=%u\n",
1290 listener
, atomic_read(&listener
->pend_accepts_cnt
));
1298 * mini_cm_del_listen
1300 static int mini_cm_del_listen(struct nes_cm_core
*cm_core
,
1301 struct nes_cm_listener
*listener
)
1303 listener
->listener_state
= NES_CM_LISTENER_PASSIVE_STATE
;
1304 listener
->cm_id
= NULL
; /* going to be destroyed pretty soon */
1305 return mini_cm_dec_refcnt_listen(cm_core
, listener
, 1);
1310 * mini_cm_accelerated
1312 static inline int mini_cm_accelerated(struct nes_cm_core
*cm_core
,
1313 struct nes_cm_node
*cm_node
)
1317 cm_node
->accelerated
= 1;
1319 if (cm_node
->accept_pend
) {
1320 BUG_ON(!cm_node
->listener
);
1321 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1322 cm_node
->accept_pend
= 0;
1323 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1326 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
1327 if (!was_timer_set
) {
1328 cm_core
->tcp_timer
.expires
= jiffies
+ NES_SHORT_TIME
;
1329 add_timer(&cm_core
->tcp_timer
);
1337 * nes_addr_resolve_neigh
1339 static int nes_addr_resolve_neigh(struct nes_vnic
*nesvnic
, u32 dst_ip
, int arpindex
)
1342 struct neighbour
*neigh
;
1344 struct net_device
*netdev
;
1345 struct nes_adapter
*nesadapter
= nesvnic
->nesdev
->nesadapter
;
1347 rt
= ip_route_output(&init_net
, htonl(dst_ip
), 0, 0, 0);
1349 printk(KERN_ERR
"%s: ip_route_output_key failed for 0x%08X\n",
1354 if (netif_is_bond_slave(nesvnic
->netdev
))
1355 netdev
= nesvnic
->netdev
->master
;
1357 netdev
= nesvnic
->netdev
;
1359 neigh
= dst_neigh_lookup(&rt
->dst
, &dst_ip
);
1363 if (neigh
->nud_state
& NUD_VALID
) {
1364 nes_debug(NES_DBG_CM
, "Neighbor MAC address for 0x%08X"
1365 " is %pM, Gateway is 0x%08X \n", dst_ip
,
1366 neigh
->ha
, ntohl(rt
->rt_gateway
));
1368 if (arpindex
>= 0) {
1369 if (!memcmp(nesadapter
->arp_table
[arpindex
].mac_addr
,
1370 neigh
->ha
, ETH_ALEN
)) {
1371 /* Mac address same as in nes_arp_table */
1375 nes_manage_arp_cache(nesvnic
->netdev
,
1376 nesadapter
->arp_table
[arpindex
].mac_addr
,
1377 dst_ip
, NES_ARP_DELETE
);
1380 nes_manage_arp_cache(nesvnic
->netdev
, neigh
->ha
,
1381 dst_ip
, NES_ARP_ADD
);
1382 rc
= nes_arp_table(nesvnic
->nesdev
, dst_ip
, NULL
,
1385 neigh_event_send(neigh
, NULL
);
1392 neigh_release(neigh
);
1399 * make_cm_node - create a new instance of a cm node
1401 static struct nes_cm_node
*make_cm_node(struct nes_cm_core
*cm_core
,
1402 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
,
1403 struct nes_cm_listener
*listener
)
1405 struct nes_cm_node
*cm_node
;
1407 int oldarpindex
= 0;
1409 struct nes_device
*nesdev
;
1410 struct nes_adapter
*nesadapter
;
1412 /* create an hte and cm_node for this instance */
1413 cm_node
= kzalloc(sizeof(*cm_node
), GFP_ATOMIC
);
1417 /* set our node specific transport info */
1418 cm_node
->loc_addr
= cm_info
->loc_addr
;
1419 cm_node
->rem_addr
= cm_info
->rem_addr
;
1420 cm_node
->loc_port
= cm_info
->loc_port
;
1421 cm_node
->rem_port
= cm_info
->rem_port
;
1423 cm_node
->mpa_frame_rev
= mpa_version
;
1424 cm_node
->send_rdma0_op
= SEND_RDMA_READ_ZERO
;
1425 cm_node
->ird_size
= IETF_NO_IRD_ORD
;
1426 cm_node
->ord_size
= IETF_NO_IRD_ORD
;
1428 nes_debug(NES_DBG_CM
, "Make node addresses : loc = %pI4:%x, rem = %pI4:%x\n",
1429 &cm_node
->loc_addr
, cm_node
->loc_port
,
1430 &cm_node
->rem_addr
, cm_node
->rem_port
);
1431 cm_node
->listener
= listener
;
1432 cm_node
->netdev
= nesvnic
->netdev
;
1433 cm_node
->cm_id
= cm_info
->cm_id
;
1434 memcpy(cm_node
->loc_mac
, nesvnic
->netdev
->dev_addr
, ETH_ALEN
);
1436 nes_debug(NES_DBG_CM
, "listener=%p, cm_id=%p\n", cm_node
->listener
,
1439 spin_lock_init(&cm_node
->retrans_list_lock
);
1441 cm_node
->loopbackpartner
= NULL
;
1442 atomic_set(&cm_node
->ref_count
, 1);
1443 /* associate our parent CM core */
1444 cm_node
->cm_core
= cm_core
;
1445 cm_node
->tcp_cntxt
.loc_id
= NES_CM_DEF_LOCAL_ID
;
1446 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
1447 cm_node
->tcp_cntxt
.rcv_wnd
= NES_CM_DEFAULT_RCV_WND_SCALED
>>
1448 NES_CM_DEFAULT_RCV_WND_SCALE
;
1449 ts
= current_kernel_time();
1450 cm_node
->tcp_cntxt
.loc_seq_num
= htonl(ts
.tv_nsec
);
1451 cm_node
->tcp_cntxt
.mss
= nesvnic
->max_frame_size
- sizeof(struct iphdr
) -
1452 sizeof(struct tcphdr
) - ETH_HLEN
- VLAN_HLEN
;
1453 cm_node
->tcp_cntxt
.rcv_nxt
= 0;
1454 /* get a unique session ID , add thread_id to an upcounter to handle race */
1455 atomic_inc(&cm_core
->node_cnt
);
1456 cm_node
->conn_type
= cm_info
->conn_type
;
1457 cm_node
->apbvt_set
= 0;
1458 cm_node
->accept_pend
= 0;
1460 cm_node
->nesvnic
= nesvnic
;
1461 /* get some device handles, for arp lookup */
1462 nesdev
= nesvnic
->nesdev
;
1463 nesadapter
= nesdev
->nesadapter
;
1465 cm_node
->loopbackpartner
= NULL
;
1467 /* get the mac addr for the remote node */
1468 if (ipv4_is_loopback(htonl(cm_node
->rem_addr
))) {
1469 arpindex
= nes_arp_table(nesdev
, ntohl(nesvnic
->local_ipaddr
), NULL
, NES_ARP_RESOLVE
);
1471 oldarpindex
= nes_arp_table(nesdev
, cm_node
->rem_addr
, NULL
, NES_ARP_RESOLVE
);
1472 arpindex
= nes_addr_resolve_neigh(nesvnic
, cm_info
->rem_addr
, oldarpindex
);
1479 /* copy the mac addr to node context */
1480 memcpy(cm_node
->rem_mac
, nesadapter
->arp_table
[arpindex
].mac_addr
, ETH_ALEN
);
1481 nes_debug(NES_DBG_CM
, "Remote mac addr from arp table: %pM\n",
1484 add_hte_node(cm_core
, cm_node
);
1485 atomic_inc(&cm_nodes_created
);
1492 * add_ref_cm_node - destroy an instance of a cm node
1494 static int add_ref_cm_node(struct nes_cm_node
*cm_node
)
1496 atomic_inc(&cm_node
->ref_count
);
1502 * rem_ref_cm_node - destroy an instance of a cm node
1504 static int rem_ref_cm_node(struct nes_cm_core
*cm_core
,
1505 struct nes_cm_node
*cm_node
)
1507 unsigned long flags
;
1508 struct nes_qp
*nesqp
;
1513 spin_lock_irqsave(&cm_node
->cm_core
->ht_lock
, flags
);
1514 if (atomic_dec_return(&cm_node
->ref_count
)) {
1515 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1518 list_del(&cm_node
->list
);
1519 atomic_dec(&cm_core
->ht_node_cnt
);
1520 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1522 /* if the node is destroyed before connection was accelerated */
1523 if (!cm_node
->accelerated
&& cm_node
->accept_pend
) {
1524 BUG_ON(!cm_node
->listener
);
1525 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1526 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1528 WARN_ON(cm_node
->send_entry
);
1529 if (cm_node
->recv_entry
)
1530 handle_recv_entry(cm_node
, 0);
1531 if (cm_node
->listener
) {
1532 mini_cm_dec_refcnt_listen(cm_core
, cm_node
->listener
, 0);
1534 if (cm_node
->apbvt_set
&& cm_node
->nesvnic
) {
1535 nes_manage_apbvt(cm_node
->nesvnic
, cm_node
->loc_port
,
1537 cm_node
->nesvnic
->nesdev
->pcidev
->devfn
),
1538 NES_MANAGE_APBVT_DEL
);
1542 atomic_dec(&cm_core
->node_cnt
);
1543 atomic_inc(&cm_nodes_destroyed
);
1544 nesqp
= cm_node
->nesqp
;
1546 nesqp
->cm_node
= NULL
;
1547 nes_rem_ref(&nesqp
->ibqp
);
1548 cm_node
->nesqp
= NULL
;
1558 static int process_options(struct nes_cm_node
*cm_node
, u8
*optionsloc
,
1559 u32 optionsize
, u32 syn_packet
)
1563 union all_known_options
*all_options
;
1564 char got_mss_option
= 0;
1566 while (offset
< optionsize
) {
1567 all_options
= (union all_known_options
*)(optionsloc
+ offset
);
1568 switch (all_options
->as_base
.optionnum
) {
1569 case OPTION_NUMBER_END
:
1570 offset
= optionsize
;
1572 case OPTION_NUMBER_NONE
:
1575 case OPTION_NUMBER_MSS
:
1576 nes_debug(NES_DBG_CM
, "%s: MSS Length: %d Offset: %d "
1577 "Size: %d\n", __func__
,
1578 all_options
->as_mss
.length
, offset
, optionsize
);
1580 if (all_options
->as_mss
.length
!= 4) {
1583 tmp
= ntohs(all_options
->as_mss
.mss
);
1584 if (tmp
> 0 && tmp
<
1585 cm_node
->tcp_cntxt
.mss
)
1586 cm_node
->tcp_cntxt
.mss
= tmp
;
1589 case OPTION_NUMBER_WINDOW_SCALE
:
1590 cm_node
->tcp_cntxt
.snd_wscale
=
1591 all_options
->as_windowscale
.shiftcount
;
1594 nes_debug(NES_DBG_CM
, "TCP Option not understood: %x\n",
1595 all_options
->as_base
.optionnum
);
1598 offset
+= all_options
->as_base
.length
;
1600 if ((!got_mss_option
) && (syn_packet
))
1601 cm_node
->tcp_cntxt
.mss
= NES_CM_DEFAULT_MSS
;
1605 static void drop_packet(struct sk_buff
*skb
)
1607 atomic_inc(&cm_accel_dropped_pkts
);
1608 dev_kfree_skb_any(skb
);
1611 static void handle_fin_pkt(struct nes_cm_node
*cm_node
)
1613 nes_debug(NES_DBG_CM
, "Received FIN, cm_node = %p, state = %u. "
1614 "refcnt=%d\n", cm_node
, cm_node
->state
,
1615 atomic_read(&cm_node
->ref_count
));
1616 switch (cm_node
->state
) {
1617 case NES_CM_STATE_SYN_RCVD
:
1618 case NES_CM_STATE_SYN_SENT
:
1619 case NES_CM_STATE_ESTABLISHED
:
1620 case NES_CM_STATE_MPAREJ_RCVD
:
1621 cm_node
->tcp_cntxt
.rcv_nxt
++;
1622 cleanup_retrans_entry(cm_node
);
1623 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
1624 send_fin(cm_node
, NULL
);
1626 case NES_CM_STATE_MPAREQ_SENT
:
1627 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
1628 cm_node
->tcp_cntxt
.rcv_nxt
++;
1629 cleanup_retrans_entry(cm_node
);
1630 cm_node
->state
= NES_CM_STATE_CLOSED
;
1631 add_ref_cm_node(cm_node
);
1632 send_reset(cm_node
, NULL
);
1634 case NES_CM_STATE_FIN_WAIT1
:
1635 cm_node
->tcp_cntxt
.rcv_nxt
++;
1636 cleanup_retrans_entry(cm_node
);
1637 cm_node
->state
= NES_CM_STATE_CLOSING
;
1638 send_ack(cm_node
, NULL
);
1639 /* Wait for ACK as this is simultaneous close..
1640 * After we receive ACK, do not send anything..
1641 * Just rm the node.. Done.. */
1643 case NES_CM_STATE_FIN_WAIT2
:
1644 cm_node
->tcp_cntxt
.rcv_nxt
++;
1645 cleanup_retrans_entry(cm_node
);
1646 cm_node
->state
= NES_CM_STATE_TIME_WAIT
;
1647 send_ack(cm_node
, NULL
);
1648 schedule_nes_timer(cm_node
, NULL
, NES_TIMER_TYPE_CLOSE
, 1, 0);
1650 case NES_CM_STATE_TIME_WAIT
:
1651 cm_node
->tcp_cntxt
.rcv_nxt
++;
1652 cleanup_retrans_entry(cm_node
);
1653 cm_node
->state
= NES_CM_STATE_CLOSED
;
1654 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1656 case NES_CM_STATE_TSA
:
1658 nes_debug(NES_DBG_CM
, "Error Rcvd FIN for node-%p state = %d\n",
1659 cm_node
, cm_node
->state
);
1665 static void handle_rst_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1666 struct tcphdr
*tcph
)
1669 int reset
= 0; /* whether to send reset in case of err.. */
1670 atomic_inc(&cm_resets_recvd
);
1671 nes_debug(NES_DBG_CM
, "Received Reset, cm_node = %p, state = %u."
1672 " refcnt=%d\n", cm_node
, cm_node
->state
,
1673 atomic_read(&cm_node
->ref_count
));
1674 cleanup_retrans_entry(cm_node
);
1675 switch (cm_node
->state
) {
1676 case NES_CM_STATE_SYN_SENT
:
1677 case NES_CM_STATE_MPAREQ_SENT
:
1678 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1679 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1680 cm_node
->listener
, cm_node
->state
);
1681 switch (cm_node
->mpa_frame_rev
) {
1683 cm_node
->mpa_frame_rev
= IETF_MPA_V1
;
1684 /* send a syn and goto syn sent state */
1685 cm_node
->state
= NES_CM_STATE_SYN_SENT
;
1686 if (send_syn(cm_node
, 0, NULL
)) {
1687 active_open_err(cm_node
, skb
, reset
);
1692 active_open_err(cm_node
, skb
, reset
);
1696 case NES_CM_STATE_MPAREQ_RCVD
:
1697 atomic_inc(&cm_node
->passive_state
);
1698 dev_kfree_skb_any(skb
);
1700 case NES_CM_STATE_ESTABLISHED
:
1701 case NES_CM_STATE_SYN_RCVD
:
1702 case NES_CM_STATE_LISTENING
:
1703 nes_debug(NES_DBG_CM
, "Bad state %s[%u]\n", __func__
, __LINE__
);
1704 passive_open_err(cm_node
, skb
, reset
);
1706 case NES_CM_STATE_TSA
:
1707 active_open_err(cm_node
, skb
, reset
);
1709 case NES_CM_STATE_CLOSED
:
1712 case NES_CM_STATE_FIN_WAIT2
:
1713 case NES_CM_STATE_FIN_WAIT1
:
1714 case NES_CM_STATE_LAST_ACK
:
1715 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
1716 case NES_CM_STATE_TIME_WAIT
:
1717 cm_node
->state
= NES_CM_STATE_CLOSED
;
1718 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1728 static void handle_rcv_mpa(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1731 int datasize
= skb
->len
;
1732 u8
*dataloc
= skb
->data
;
1734 enum nes_cm_event_type type
= NES_CM_EVENT_UNKNOWN
;
1737 ret
= parse_mpa(cm_node
, dataloc
, &res_type
, datasize
);
1739 nes_debug(NES_DBG_CM
, "didn't like MPA Request\n");
1740 if (cm_node
->state
== NES_CM_STATE_MPAREQ_SENT
) {
1741 nes_debug(NES_DBG_CM
, "%s[%u] create abort for "
1742 "cm_node=%p listener=%p state=%d\n", __func__
,
1743 __LINE__
, cm_node
, cm_node
->listener
,
1745 active_open_err(cm_node
, skb
, 1);
1747 passive_open_err(cm_node
, skb
, 1);
1752 switch (cm_node
->state
) {
1753 case NES_CM_STATE_ESTABLISHED
:
1754 if (res_type
== NES_MPA_REQUEST_REJECT
)
1755 /*BIG problem as we are receiving the MPA.. So should
1756 * not be REJECT.. This is Passive Open.. We can
1757 * only receive it Reject for Active Open...*/
1759 cm_node
->state
= NES_CM_STATE_MPAREQ_RCVD
;
1760 type
= NES_CM_EVENT_MPA_REQ
;
1761 atomic_set(&cm_node
->passive_state
,
1762 NES_PASSIVE_STATE_INDICATED
);
1764 case NES_CM_STATE_MPAREQ_SENT
:
1765 cleanup_retrans_entry(cm_node
);
1766 if (res_type
== NES_MPA_REQUEST_REJECT
) {
1767 type
= NES_CM_EVENT_MPA_REJECT
;
1768 cm_node
->state
= NES_CM_STATE_MPAREJ_RCVD
;
1770 type
= NES_CM_EVENT_CONNECTED
;
1771 cm_node
->state
= NES_CM_STATE_TSA
;
1779 dev_kfree_skb_any(skb
);
1780 create_event(cm_node
, type
);
1783 static void indicate_pkt_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1785 switch (cm_node
->state
) {
1786 case NES_CM_STATE_SYN_SENT
:
1787 case NES_CM_STATE_MPAREQ_SENT
:
1788 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1789 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1790 cm_node
->listener
, cm_node
->state
);
1791 active_open_err(cm_node
, skb
, 1);
1793 case NES_CM_STATE_ESTABLISHED
:
1794 case NES_CM_STATE_SYN_RCVD
:
1795 passive_open_err(cm_node
, skb
, 1);
1797 case NES_CM_STATE_TSA
:
1803 static int check_syn(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1804 struct sk_buff
*skb
)
1808 err
= ((ntohl(tcph
->ack_seq
) == cm_node
->tcp_cntxt
.loc_seq_num
)) ? 0 : 1;
1810 active_open_err(cm_node
, skb
, 1);
1815 static int check_seq(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1816 struct sk_buff
*skb
)
1821 u32 loc_seq_num
= cm_node
->tcp_cntxt
.loc_seq_num
;
1822 u32 rcv_nxt
= cm_node
->tcp_cntxt
.rcv_nxt
;
1825 seq
= ntohl(tcph
->seq
);
1826 ack_seq
= ntohl(tcph
->ack_seq
);
1827 rcv_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
1828 if (ack_seq
!= loc_seq_num
)
1830 else if (!between(seq
, rcv_nxt
, (rcv_nxt
+ rcv_wnd
)))
1833 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1834 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1835 cm_node
->listener
, cm_node
->state
);
1836 indicate_pkt_err(cm_node
, skb
);
1837 nes_debug(NES_DBG_CM
, "seq ERROR cm_node =%p seq=0x%08X "
1838 "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node
, seq
, rcv_nxt
,
1845 * handle_syn_pkt() is for Passive node. The syn packet is received when a node
1846 * is created with a listener or it may comein as rexmitted packet which in
1847 * that case will be just dropped.
1849 static void handle_syn_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1850 struct tcphdr
*tcph
)
1856 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1858 inc_sequence
= ntohl(tcph
->seq
);
1860 switch (cm_node
->state
) {
1861 case NES_CM_STATE_SYN_SENT
:
1862 case NES_CM_STATE_MPAREQ_SENT
:
1863 /* Rcvd syn on active open connection*/
1864 active_open_err(cm_node
, skb
, 1);
1866 case NES_CM_STATE_LISTENING
:
1868 if (atomic_read(&cm_node
->listener
->pend_accepts_cnt
) >
1869 cm_node
->listener
->backlog
) {
1870 nes_debug(NES_DBG_CM
, "drop syn due to backlog "
1873 passive_open_err(cm_node
, skb
, 0);
1876 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
,
1879 passive_open_err(cm_node
, skb
, 0);
1883 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
1884 BUG_ON(cm_node
->send_entry
);
1885 cm_node
->accept_pend
= 1;
1886 atomic_inc(&cm_node
->listener
->pend_accepts_cnt
);
1888 cm_node
->state
= NES_CM_STATE_SYN_RCVD
;
1889 send_syn(cm_node
, 1, skb
);
1891 case NES_CM_STATE_CLOSED
:
1892 cleanup_retrans_entry(cm_node
);
1893 add_ref_cm_node(cm_node
);
1894 send_reset(cm_node
, skb
);
1896 case NES_CM_STATE_TSA
:
1897 case NES_CM_STATE_ESTABLISHED
:
1898 case NES_CM_STATE_FIN_WAIT1
:
1899 case NES_CM_STATE_FIN_WAIT2
:
1900 case NES_CM_STATE_MPAREQ_RCVD
:
1901 case NES_CM_STATE_LAST_ACK
:
1902 case NES_CM_STATE_CLOSING
:
1903 case NES_CM_STATE_UNKNOWN
:
1910 static void handle_synack_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1911 struct tcphdr
*tcph
)
1917 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1919 inc_sequence
= ntohl(tcph
->seq
);
1920 switch (cm_node
->state
) {
1921 case NES_CM_STATE_SYN_SENT
:
1922 cleanup_retrans_entry(cm_node
);
1924 if (check_syn(cm_node
, tcph
, skb
))
1926 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
1928 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
, 0);
1930 nes_debug(NES_DBG_CM
, "cm_node=%p tcp_options failed\n",
1934 cleanup_retrans_entry(cm_node
);
1935 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
1936 send_mpa_request(cm_node
, skb
);
1937 cm_node
->state
= NES_CM_STATE_MPAREQ_SENT
;
1939 case NES_CM_STATE_MPAREQ_RCVD
:
1940 /* passive open, so should not be here */
1941 passive_open_err(cm_node
, skb
, 1);
1943 case NES_CM_STATE_LISTENING
:
1944 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
1945 cleanup_retrans_entry(cm_node
);
1946 cm_node
->state
= NES_CM_STATE_CLOSED
;
1947 send_reset(cm_node
, skb
);
1949 case NES_CM_STATE_CLOSED
:
1950 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
1951 cleanup_retrans_entry(cm_node
);
1952 add_ref_cm_node(cm_node
);
1953 send_reset(cm_node
, skb
);
1955 case NES_CM_STATE_ESTABLISHED
:
1956 case NES_CM_STATE_FIN_WAIT1
:
1957 case NES_CM_STATE_FIN_WAIT2
:
1958 case NES_CM_STATE_LAST_ACK
:
1959 case NES_CM_STATE_TSA
:
1960 case NES_CM_STATE_CLOSING
:
1961 case NES_CM_STATE_UNKNOWN
:
1962 case NES_CM_STATE_MPAREQ_SENT
:
1969 static int handle_ack_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1970 struct tcphdr
*tcph
)
1977 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1979 if (check_seq(cm_node
, tcph
, skb
))
1982 skb_pull(skb
, tcph
->doff
<< 2);
1983 inc_sequence
= ntohl(tcph
->seq
);
1984 datasize
= skb
->len
;
1985 switch (cm_node
->state
) {
1986 case NES_CM_STATE_SYN_RCVD
:
1988 cleanup_retrans_entry(cm_node
);
1989 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
, 1);
1992 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
1993 cm_node
->state
= NES_CM_STATE_ESTABLISHED
;
1995 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
1996 handle_rcv_mpa(cm_node
, skb
);
1997 } else { /* rcvd ACK only */
1998 dev_kfree_skb_any(skb
);
2001 case NES_CM_STATE_ESTABLISHED
:
2003 cleanup_retrans_entry(cm_node
);
2005 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2006 handle_rcv_mpa(cm_node
, skb
);
2011 case NES_CM_STATE_MPAREQ_SENT
:
2012 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
2014 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
2015 handle_rcv_mpa(cm_node
, skb
);
2016 } else { /* Could be just an ack pkt.. */
2017 dev_kfree_skb_any(skb
);
2020 case NES_CM_STATE_LISTENING
:
2021 cleanup_retrans_entry(cm_node
);
2022 cm_node
->state
= NES_CM_STATE_CLOSED
;
2023 send_reset(cm_node
, skb
);
2025 case NES_CM_STATE_CLOSED
:
2026 cleanup_retrans_entry(cm_node
);
2027 add_ref_cm_node(cm_node
);
2028 send_reset(cm_node
, skb
);
2030 case NES_CM_STATE_LAST_ACK
:
2031 case NES_CM_STATE_CLOSING
:
2032 cleanup_retrans_entry(cm_node
);
2033 cm_node
->state
= NES_CM_STATE_CLOSED
;
2034 cm_node
->cm_id
->rem_ref(cm_node
->cm_id
);
2035 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2038 case NES_CM_STATE_FIN_WAIT1
:
2039 cleanup_retrans_entry(cm_node
);
2041 cm_node
->state
= NES_CM_STATE_FIN_WAIT2
;
2043 case NES_CM_STATE_SYN_SENT
:
2044 case NES_CM_STATE_FIN_WAIT2
:
2045 case NES_CM_STATE_TSA
:
2046 case NES_CM_STATE_MPAREQ_RCVD
:
2047 case NES_CM_STATE_UNKNOWN
:
2049 cleanup_retrans_entry(cm_node
);
2058 static int handle_tcp_options(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
2059 struct sk_buff
*skb
, int optionsize
, int passive
)
2061 u8
*optionsloc
= (u8
*)&tcph
[1];
2064 if (process_options(cm_node
, optionsloc
, optionsize
,
2066 nes_debug(NES_DBG_CM
, "%s: Node %p, Sending RESET\n",
2069 passive_open_err(cm_node
, skb
, 1);
2071 active_open_err(cm_node
, skb
, 1);
2076 cm_node
->tcp_cntxt
.snd_wnd
= ntohs(tcph
->window
) <<
2077 cm_node
->tcp_cntxt
.snd_wscale
;
2079 if (cm_node
->tcp_cntxt
.snd_wnd
> cm_node
->tcp_cntxt
.max_snd_wnd
)
2080 cm_node
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.snd_wnd
;
2085 * active_open_err() will send reset() if flag set..
2086 * It will also send ABORT event.
2088 static void active_open_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2091 cleanup_retrans_entry(cm_node
);
2093 nes_debug(NES_DBG_CM
, "ERROR active err called for cm_node=%p, "
2094 "state=%d\n", cm_node
, cm_node
->state
);
2095 add_ref_cm_node(cm_node
);
2096 send_reset(cm_node
, skb
);
2098 dev_kfree_skb_any(skb
);
2101 cm_node
->state
= NES_CM_STATE_CLOSED
;
2102 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
2106 * passive_open_err() will either do a reset() or will free up the skb and
2107 * remove the cm_node.
2109 static void passive_open_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2112 cleanup_retrans_entry(cm_node
);
2113 cm_node
->state
= NES_CM_STATE_CLOSED
;
2115 nes_debug(NES_DBG_CM
, "passive_open_err sending RST for "
2116 "cm_node=%p state =%d\n", cm_node
, cm_node
->state
);
2117 send_reset(cm_node
, skb
);
2119 dev_kfree_skb_any(skb
);
2120 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2125 * free_retrans_entry() routines assumes that the retrans_list_lock has
2126 * been acquired before calling.
2128 static void free_retrans_entry(struct nes_cm_node
*cm_node
)
2130 struct nes_timer_entry
*send_entry
;
2132 send_entry
= cm_node
->send_entry
;
2134 cm_node
->send_entry
= NULL
;
2135 dev_kfree_skb_any(send_entry
->skb
);
2137 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2141 static void cleanup_retrans_entry(struct nes_cm_node
*cm_node
)
2143 unsigned long flags
;
2145 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
2146 free_retrans_entry(cm_node
);
2147 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
2152 * Returns skb if to be freed, else it will return NULL if already used..
2154 static void process_packet(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
2155 struct nes_cm_core
*cm_core
)
2157 enum nes_tcpip_pkt_type pkt_type
= NES_PKT_TYPE_UNKNOWN
;
2158 struct tcphdr
*tcph
= tcp_hdr(skb
);
2162 skb_pull(skb
, ip_hdr(skb
)->ihl
<< 2);
2164 nes_debug(NES_DBG_CM
, "process_packet: cm_node=%p state =%d syn=%d "
2165 "ack=%d rst=%d fin=%d\n", cm_node
, cm_node
->state
, tcph
->syn
,
2166 tcph
->ack
, tcph
->rst
, tcph
->fin
);
2169 pkt_type
= NES_PKT_TYPE_RST
;
2170 } else if (tcph
->syn
) {
2171 pkt_type
= NES_PKT_TYPE_SYN
;
2173 pkt_type
= NES_PKT_TYPE_SYNACK
;
2174 } else if (tcph
->ack
) {
2175 pkt_type
= NES_PKT_TYPE_ACK
;
2181 case NES_PKT_TYPE_SYN
:
2182 handle_syn_pkt(cm_node
, skb
, tcph
);
2184 case NES_PKT_TYPE_SYNACK
:
2185 handle_synack_pkt(cm_node
, skb
, tcph
);
2187 case NES_PKT_TYPE_ACK
:
2188 ret
= handle_ack_pkt(cm_node
, skb
, tcph
);
2189 if (fin_set
&& !ret
)
2190 handle_fin_pkt(cm_node
);
2192 case NES_PKT_TYPE_RST
:
2193 handle_rst_pkt(cm_node
, skb
, tcph
);
2196 if ((fin_set
) && (!check_seq(cm_node
, tcph
, skb
)))
2197 handle_fin_pkt(cm_node
);
2204 * mini_cm_listen - create a listen node with params
2206 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*cm_core
,
2207 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
)
2209 struct nes_cm_listener
*listener
;
2210 unsigned long flags
;
2212 nes_debug(NES_DBG_CM
, "Search for 0x%08x : 0x%04x\n",
2213 cm_info
->loc_addr
, cm_info
->loc_port
);
2215 /* cannot have multiple matching listeners */
2216 listener
= find_listener(cm_core
, htonl(cm_info
->loc_addr
),
2217 htons(cm_info
->loc_port
), NES_CM_LISTENER_EITHER_STATE
);
2218 if (listener
&& listener
->listener_state
== NES_CM_LISTENER_ACTIVE_STATE
) {
2219 /* find automatically incs ref count ??? */
2220 atomic_dec(&listener
->ref_count
);
2221 nes_debug(NES_DBG_CM
, "Not creating listener since it already exists\n");
2226 /* create a CM listen node (1/2 node to compare incoming traffic to) */
2227 listener
= kzalloc(sizeof(*listener
), GFP_ATOMIC
);
2229 nes_debug(NES_DBG_CM
, "Not creating listener memory allocation failed\n");
2233 listener
->loc_addr
= htonl(cm_info
->loc_addr
);
2234 listener
->loc_port
= htons(cm_info
->loc_port
);
2235 listener
->reused_node
= 0;
2237 atomic_set(&listener
->ref_count
, 1);
2240 /* find already inc'ed the ref count */
2242 listener
->reused_node
= 1;
2245 listener
->cm_id
= cm_info
->cm_id
;
2246 atomic_set(&listener
->pend_accepts_cnt
, 0);
2247 listener
->cm_core
= cm_core
;
2248 listener
->nesvnic
= nesvnic
;
2249 atomic_inc(&cm_core
->node_cnt
);
2251 listener
->conn_type
= cm_info
->conn_type
;
2252 listener
->backlog
= cm_info
->backlog
;
2253 listener
->listener_state
= NES_CM_LISTENER_ACTIVE_STATE
;
2255 if (!listener
->reused_node
) {
2256 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
2257 list_add(&listener
->list
, &cm_core
->listen_list
.list
);
2258 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
2259 atomic_inc(&cm_core
->listen_node_cnt
);
2262 nes_debug(NES_DBG_CM
, "Api - listen(): addr=0x%08X, port=0x%04x,"
2263 " listener = %p, backlog = %d, cm_id = %p.\n",
2264 cm_info
->loc_addr
, cm_info
->loc_port
,
2265 listener
, listener
->backlog
, listener
->cm_id
);
2272 * mini_cm_connect - make a connection node with params
2274 static struct nes_cm_node
*mini_cm_connect(struct nes_cm_core
*cm_core
,
2275 struct nes_vnic
*nesvnic
, u16 private_data_len
,
2276 void *private_data
, struct nes_cm_info
*cm_info
)
2279 struct nes_cm_node
*cm_node
;
2280 struct nes_cm_listener
*loopbackremotelistener
;
2281 struct nes_cm_node
*loopbackremotenode
;
2282 struct nes_cm_info loopback_cm_info
;
2285 /* create a CM connection node */
2286 cm_node
= make_cm_node(cm_core
, nesvnic
, cm_info
, NULL
);
2290 /* set our node side to client (active) side */
2291 cm_node
->tcp_cntxt
.client
= 1;
2292 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
2294 if (cm_info
->loc_addr
== cm_info
->rem_addr
) {
2295 loopbackremotelistener
= find_listener(cm_core
,
2296 ntohl(nesvnic
->local_ipaddr
), cm_node
->rem_port
,
2297 NES_CM_LISTENER_ACTIVE_STATE
);
2298 if (loopbackremotelistener
== NULL
) {
2299 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
2301 loopback_cm_info
= *cm_info
;
2302 loopback_cm_info
.loc_port
= cm_info
->rem_port
;
2303 loopback_cm_info
.rem_port
= cm_info
->loc_port
;
2304 loopback_cm_info
.cm_id
= loopbackremotelistener
->cm_id
;
2305 loopbackremotenode
= make_cm_node(cm_core
, nesvnic
,
2306 &loopback_cm_info
, loopbackremotelistener
);
2307 if (!loopbackremotenode
) {
2308 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2311 atomic_inc(&cm_loopbacks
);
2312 loopbackremotenode
->loopbackpartner
= cm_node
;
2313 loopbackremotenode
->tcp_cntxt
.rcv_wscale
=
2314 NES_CM_DEFAULT_RCV_WND_SCALE
;
2315 cm_node
->loopbackpartner
= loopbackremotenode
;
2316 memcpy(loopbackremotenode
->mpa_frame_buf
, private_data
,
2318 loopbackremotenode
->mpa_frame_size
= private_data_len
;
2320 /* we are done handling this state. */
2321 /* set node to a TSA state */
2322 cm_node
->state
= NES_CM_STATE_TSA
;
2323 cm_node
->tcp_cntxt
.rcv_nxt
=
2324 loopbackremotenode
->tcp_cntxt
.loc_seq_num
;
2325 loopbackremotenode
->tcp_cntxt
.rcv_nxt
=
2326 cm_node
->tcp_cntxt
.loc_seq_num
;
2327 cm_node
->tcp_cntxt
.max_snd_wnd
=
2328 loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
2329 loopbackremotenode
->tcp_cntxt
.max_snd_wnd
=
2330 cm_node
->tcp_cntxt
.rcv_wnd
;
2331 cm_node
->tcp_cntxt
.snd_wnd
=
2332 loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
2333 loopbackremotenode
->tcp_cntxt
.snd_wnd
=
2334 cm_node
->tcp_cntxt
.rcv_wnd
;
2335 cm_node
->tcp_cntxt
.snd_wscale
=
2336 loopbackremotenode
->tcp_cntxt
.rcv_wscale
;
2337 loopbackremotenode
->tcp_cntxt
.snd_wscale
=
2338 cm_node
->tcp_cntxt
.rcv_wscale
;
2339 loopbackremotenode
->state
= NES_CM_STATE_MPAREQ_RCVD
;
2340 create_event(loopbackremotenode
, NES_CM_EVENT_MPA_REQ
);
2345 start_buff
= &cm_node
->mpa_frame_buf
[0] + sizeof(struct ietf_mpa_v2
);
2346 cm_node
->mpa_frame_size
= private_data_len
;
2348 memcpy(start_buff
, private_data
, private_data_len
);
2350 /* send a syn and goto syn sent state */
2351 cm_node
->state
= NES_CM_STATE_SYN_SENT
;
2352 ret
= send_syn(cm_node
, 0, NULL
);
2355 /* error in sending the syn free up the cm_node struct */
2356 nes_debug(NES_DBG_CM
, "Api - connect() FAILED: dest "
2357 "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
2358 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
,
2360 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2365 nes_debug(NES_DBG_CM
, "Api - connect(): dest addr=0x%08X,"
2366 "port=0x%04x, cm_node=%p, cm_id = %p.\n",
2367 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
,
2376 * mini_cm_accept - accept a connection
2377 * This function is never called
2379 static int mini_cm_accept(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2386 * mini_cm_reject - reject and teardown a connection
2388 static int mini_cm_reject(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2393 struct nes_cm_event event
;
2394 struct iw_cm_id
*cm_id
= cm_node
->cm_id
;
2395 struct nes_cm_node
*loopback
= cm_node
->loopbackpartner
;
2397 nes_debug(NES_DBG_CM
, "%s cm_node=%p type=%d state=%d\n",
2398 __func__
, cm_node
, cm_node
->tcp_cntxt
.client
, cm_node
->state
);
2400 if (cm_node
->tcp_cntxt
.client
)
2402 cleanup_retrans_entry(cm_node
);
2405 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
2406 if (passive_state
== NES_SEND_RESET_EVENT
) {
2407 cm_node
->state
= NES_CM_STATE_CLOSED
;
2408 rem_ref_cm_node(cm_core
, cm_node
);
2410 if (cm_node
->state
== NES_CM_STATE_LISTENER_DESTROYED
) {
2411 rem_ref_cm_node(cm_core
, cm_node
);
2413 ret
= send_mpa_reject(cm_node
);
2415 cm_node
->state
= NES_CM_STATE_CLOSED
;
2416 err
= send_reset(cm_node
, NULL
);
2420 cm_id
->add_ref(cm_id
);
2425 cm_node
->cm_id
= NULL
;
2426 if (cm_node
->state
== NES_CM_STATE_LISTENER_DESTROYED
) {
2427 rem_ref_cm_node(cm_core
, cm_node
);
2428 rem_ref_cm_node(cm_core
, loopback
);
2430 event
.cm_node
= loopback
;
2431 event
.cm_info
.rem_addr
= loopback
->rem_addr
;
2432 event
.cm_info
.loc_addr
= loopback
->loc_addr
;
2433 event
.cm_info
.rem_port
= loopback
->rem_port
;
2434 event
.cm_info
.loc_port
= loopback
->loc_port
;
2435 event
.cm_info
.cm_id
= loopback
->cm_id
;
2436 cm_event_mpa_reject(&event
);
2437 rem_ref_cm_node(cm_core
, cm_node
);
2438 loopback
->state
= NES_CM_STATE_CLOSING
;
2440 cm_id
= loopback
->cm_id
;
2441 rem_ref_cm_node(cm_core
, loopback
);
2442 cm_id
->rem_ref(cm_id
);
2453 static int mini_cm_close(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2457 if (!cm_core
|| !cm_node
)
2460 switch (cm_node
->state
) {
2461 case NES_CM_STATE_SYN_RCVD
:
2462 case NES_CM_STATE_SYN_SENT
:
2463 case NES_CM_STATE_ONE_SIDE_ESTABLISHED
:
2464 case NES_CM_STATE_ESTABLISHED
:
2465 case NES_CM_STATE_ACCEPTING
:
2466 case NES_CM_STATE_MPAREQ_SENT
:
2467 case NES_CM_STATE_MPAREQ_RCVD
:
2468 cleanup_retrans_entry(cm_node
);
2469 send_reset(cm_node
, NULL
);
2471 case NES_CM_STATE_CLOSE_WAIT
:
2472 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
2473 send_fin(cm_node
, NULL
);
2475 case NES_CM_STATE_FIN_WAIT1
:
2476 case NES_CM_STATE_FIN_WAIT2
:
2477 case NES_CM_STATE_LAST_ACK
:
2478 case NES_CM_STATE_TIME_WAIT
:
2479 case NES_CM_STATE_CLOSING
:
2482 case NES_CM_STATE_LISTENING
:
2483 cleanup_retrans_entry(cm_node
);
2484 send_reset(cm_node
, NULL
);
2486 case NES_CM_STATE_MPAREJ_RCVD
:
2487 case NES_CM_STATE_UNKNOWN
:
2488 case NES_CM_STATE_INITED
:
2489 case NES_CM_STATE_CLOSED
:
2490 case NES_CM_STATE_LISTENER_DESTROYED
:
2491 ret
= rem_ref_cm_node(cm_core
, cm_node
);
2493 case NES_CM_STATE_TSA
:
2494 if (cm_node
->send_entry
)
2495 printk(KERN_ERR
"ERROR Close got called from STATE_TSA "
2496 "send_entry=%p\n", cm_node
->send_entry
);
2497 ret
= rem_ref_cm_node(cm_core
, cm_node
);
2505 * recv_pkt - recv an ETHERNET packet, and process it through CM
2506 * node state machine
2508 static int mini_cm_recv_pkt(struct nes_cm_core
*cm_core
,
2509 struct nes_vnic
*nesvnic
, struct sk_buff
*skb
)
2511 struct nes_cm_node
*cm_node
= NULL
;
2512 struct nes_cm_listener
*listener
= NULL
;
2514 struct tcphdr
*tcph
;
2515 struct nes_cm_info nfo
;
2516 int skb_handled
= 1;
2517 __be32 tmp_daddr
, tmp_saddr
;
2521 if (skb
->len
< sizeof(struct iphdr
) + sizeof(struct tcphdr
))
2524 iph
= (struct iphdr
*)skb
->data
;
2525 tcph
= (struct tcphdr
*)(skb
->data
+ sizeof(struct iphdr
));
2527 nfo
.loc_addr
= ntohl(iph
->daddr
);
2528 nfo
.loc_port
= ntohs(tcph
->dest
);
2529 nfo
.rem_addr
= ntohl(iph
->saddr
);
2530 nfo
.rem_port
= ntohs(tcph
->source
);
2532 tmp_daddr
= cpu_to_be32(iph
->daddr
);
2533 tmp_saddr
= cpu_to_be32(iph
->saddr
);
2535 nes_debug(NES_DBG_CM
, "Received packet: dest=%pI4:0x%04X src=%pI4:0x%04X\n",
2536 &tmp_daddr
, tcph
->dest
, &tmp_saddr
, tcph
->source
);
2539 cm_node
= find_node(cm_core
,
2540 nfo
.rem_port
, nfo
.rem_addr
,
2541 nfo
.loc_port
, nfo
.loc_addr
);
2544 /* Only type of packet accepted are for */
2545 /* the PASSIVE open (syn only) */
2546 if ((!tcph
->syn
) || (tcph
->ack
)) {
2550 listener
= find_listener(cm_core
, nfo
.loc_addr
,
2552 NES_CM_LISTENER_ACTIVE_STATE
);
2556 nes_debug(NES_DBG_CM
, "Unable to find listener for the pkt\n");
2560 nfo
.cm_id
= listener
->cm_id
;
2561 nfo
.conn_type
= listener
->conn_type
;
2562 cm_node
= make_cm_node(cm_core
, nesvnic
, &nfo
,
2565 nes_debug(NES_DBG_CM
, "Unable to allocate "
2567 cm_packets_dropped
++;
2568 atomic_dec(&listener
->ref_count
);
2569 dev_kfree_skb_any(skb
);
2572 if (!tcph
->rst
&& !tcph
->fin
) {
2573 cm_node
->state
= NES_CM_STATE_LISTENING
;
2575 cm_packets_dropped
++;
2576 rem_ref_cm_node(cm_core
, cm_node
);
2577 dev_kfree_skb_any(skb
);
2580 add_ref_cm_node(cm_node
);
2581 } else if (cm_node
->state
== NES_CM_STATE_TSA
) {
2582 if (cm_node
->nesqp
->pau_mode
)
2583 nes_queue_mgt_skbs(skb
, nesvnic
, cm_node
->nesqp
);
2585 rem_ref_cm_node(cm_core
, cm_node
);
2586 atomic_inc(&cm_accel_dropped_pkts
);
2587 dev_kfree_skb_any(skb
);
2591 skb_reset_network_header(skb
);
2592 skb_set_transport_header(skb
, sizeof(*tcph
));
2593 skb
->len
= ntohs(iph
->tot_len
);
2594 process_packet(cm_node
, skb
, cm_core
);
2595 rem_ref_cm_node(cm_core
, cm_node
);
2602 * nes_cm_alloc_core - allocate a top level instance of a cm core
2604 static struct nes_cm_core
*nes_cm_alloc_core(void)
2606 struct nes_cm_core
*cm_core
;
2608 /* setup the CM core */
2609 /* alloc top level core control structure */
2610 cm_core
= kzalloc(sizeof(*cm_core
), GFP_KERNEL
);
2614 INIT_LIST_HEAD(&cm_core
->connected_nodes
);
2615 init_timer(&cm_core
->tcp_timer
);
2616 cm_core
->tcp_timer
.function
= nes_cm_timer_tick
;
2618 cm_core
->mtu
= NES_CM_DEFAULT_MTU
;
2619 cm_core
->state
= NES_CM_STATE_INITED
;
2620 cm_core
->free_tx_pkt_max
= NES_CM_DEFAULT_FREE_PKTS
;
2622 atomic_set(&cm_core
->events_posted
, 0);
2624 cm_core
->api
= &nes_cm_api
;
2626 spin_lock_init(&cm_core
->ht_lock
);
2627 spin_lock_init(&cm_core
->listen_list_lock
);
2629 INIT_LIST_HEAD(&cm_core
->listen_list
.list
);
2631 nes_debug(NES_DBG_CM
, "Init CM Core completed -- cm_core=%p\n", cm_core
);
2633 nes_debug(NES_DBG_CM
, "Enable QUEUE EVENTS\n");
2634 cm_core
->event_wq
= create_singlethread_workqueue("nesewq");
2635 cm_core
->post_event
= nes_cm_post_event
;
2636 nes_debug(NES_DBG_CM
, "Enable QUEUE DISCONNECTS\n");
2637 cm_core
->disconn_wq
= create_singlethread_workqueue("nesdwq");
2639 print_core(cm_core
);
2645 * mini_cm_dealloc_core - deallocate a top level instance of a cm core
2647 static int mini_cm_dealloc_core(struct nes_cm_core
*cm_core
)
2649 nes_debug(NES_DBG_CM
, "De-Alloc CM Core (%p)\n", cm_core
);
2656 if (timer_pending(&cm_core
->tcp_timer
))
2657 del_timer(&cm_core
->tcp_timer
);
2659 destroy_workqueue(cm_core
->event_wq
);
2660 destroy_workqueue(cm_core
->disconn_wq
);
2661 nes_debug(NES_DBG_CM
, "\n");
2671 static int mini_cm_get(struct nes_cm_core
*cm_core
)
2673 return cm_core
->state
;
2680 static int mini_cm_set(struct nes_cm_core
*cm_core
, u32 type
, u32 value
)
2685 case NES_CM_SET_PKT_SIZE
:
2686 cm_core
->mtu
= value
;
2688 case NES_CM_SET_FREE_PKT_Q_SIZE
:
2689 cm_core
->free_tx_pkt_max
= value
;
2692 /* unknown set option */
2701 * nes_cm_init_tsa_conn setup HW; MPA frames must be
2702 * successfully exchanged when this is called
2704 static int nes_cm_init_tsa_conn(struct nes_qp
*nesqp
, struct nes_cm_node
*cm_node
)
2711 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4
|
2712 NES_QPCONTEXT_MISC_NO_NAGLE
| NES_QPCONTEXT_MISC_DO_NOT_FRAG
|
2713 NES_QPCONTEXT_MISC_DROS
);
2715 if (cm_node
->tcp_cntxt
.snd_wscale
|| cm_node
->tcp_cntxt
.rcv_wscale
)
2716 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE
);
2718 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT
);
2720 nesqp
->nesqp_context
->mss
|= cpu_to_le32(((u32
)cm_node
->tcp_cntxt
.mss
) << 16);
2722 nesqp
->nesqp_context
->tcp_state_flow_label
|= cpu_to_le32(
2723 (u32
)NES_QPCONTEXT_TCPSTATE_EST
<< NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT
);
2725 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2726 (cm_node
->tcp_cntxt
.snd_wscale
<< NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT
) &
2727 NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK
);
2729 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2730 (cm_node
->tcp_cntxt
.rcv_wscale
<< NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT
) &
2731 NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK
);
2733 nesqp
->nesqp_context
->keepalive
= cpu_to_le32(0x80);
2734 nesqp
->nesqp_context
->ts_recent
= 0;
2735 nesqp
->nesqp_context
->ts_age
= 0;
2736 nesqp
->nesqp_context
->snd_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2737 nesqp
->nesqp_context
->snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.snd_wnd
);
2738 nesqp
->nesqp_context
->rcv_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2739 nesqp
->nesqp_context
->rcv_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_wnd
<<
2740 cm_node
->tcp_cntxt
.rcv_wscale
);
2741 nesqp
->nesqp_context
->snd_max
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2742 nesqp
->nesqp_context
->snd_una
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2743 nesqp
->nesqp_context
->srtt
= 0;
2744 nesqp
->nesqp_context
->rttvar
= cpu_to_le32(0x6);
2745 nesqp
->nesqp_context
->ssthresh
= cpu_to_le32(0x3FFFC000);
2746 nesqp
->nesqp_context
->cwnd
= cpu_to_le32(2 * cm_node
->tcp_cntxt
.mss
);
2747 nesqp
->nesqp_context
->snd_wl1
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2748 nesqp
->nesqp_context
->snd_wl2
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2749 nesqp
->nesqp_context
->max_snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.max_snd_wnd
);
2751 nes_debug(NES_DBG_CM
, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
2752 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
2753 nesqp
->hwqp
.qp_id
, le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
2754 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
2755 cm_node
->tcp_cntxt
.mss
, le32_to_cpu(nesqp
->nesqp_context
->pd_index_wscale
),
2756 le32_to_cpu(nesqp
->nesqp_context
->rcv_wnd
),
2757 le32_to_cpu(nesqp
->nesqp_context
->misc
));
2758 nes_debug(NES_DBG_CM
, " snd_wnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->snd_wnd
));
2759 nes_debug(NES_DBG_CM
, " snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->cwnd
));
2760 nes_debug(NES_DBG_CM
, " max_swnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->max_snd_wnd
));
2762 nes_debug(NES_DBG_CM
, "Change cm_node state to TSA\n");
2763 cm_node
->state
= NES_CM_STATE_TSA
;
2772 int nes_cm_disconn(struct nes_qp
*nesqp
)
2774 struct disconn_work
*work
;
2776 work
= kzalloc(sizeof *work
, GFP_ATOMIC
);
2778 return -ENOMEM
; /* Timer will clean up */
2780 nes_add_ref(&nesqp
->ibqp
);
2781 work
->nesqp
= nesqp
;
2782 INIT_WORK(&work
->work
, nes_disconnect_worker
);
2783 queue_work(g_cm_core
->disconn_wq
, &work
->work
);
2789 * nes_disconnect_worker
2791 static void nes_disconnect_worker(struct work_struct
*work
)
2793 struct disconn_work
*dwork
= container_of(work
, struct disconn_work
, work
);
2794 struct nes_qp
*nesqp
= dwork
->nesqp
;
2797 nes_debug(NES_DBG_CM
, "processing AEQE id 0x%04X for QP%u.\n",
2798 nesqp
->last_aeq
, nesqp
->hwqp
.qp_id
);
2799 nes_cm_disconn_true(nesqp
);
2800 nes_rem_ref(&nesqp
->ibqp
);
2805 * nes_cm_disconn_true
2807 static int nes_cm_disconn_true(struct nes_qp
*nesqp
)
2809 unsigned long flags
;
2811 struct iw_cm_id
*cm_id
;
2812 struct iw_cm_event cm_event
;
2813 struct nes_vnic
*nesvnic
;
2815 u8 original_hw_tcp_state
;
2816 u8 original_ibqp_state
;
2817 int disconn_status
= 0;
2818 int issue_disconn
= 0;
2819 int issue_close
= 0;
2820 int issue_flush
= 0;
2821 u32 flush_q
= NES_CQP_FLUSH_RQ
;
2822 struct ib_event ibevent
;
2825 nes_debug(NES_DBG_CM
, "disconnect_worker nesqp is NULL\n");
2829 spin_lock_irqsave(&nesqp
->lock
, flags
);
2830 cm_id
= nesqp
->cm_id
;
2831 /* make sure we havent already closed this connection */
2833 nes_debug(NES_DBG_CM
, "QP%u disconnect_worker cmid is NULL\n",
2835 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2839 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2840 nes_debug(NES_DBG_CM
, "Disconnecting QP%u\n", nesqp
->hwqp
.qp_id
);
2842 original_hw_tcp_state
= nesqp
->hw_tcp_state
;
2843 original_ibqp_state
= nesqp
->ibqp_state
;
2844 last_ae
= nesqp
->last_aeq
;
2846 if (nesqp
->term_flags
) {
2849 nesqp
->cm_id
= NULL
;
2850 del_timer(&nesqp
->terminate_timer
);
2851 if (nesqp
->flush_issued
== 0) {
2852 nesqp
->flush_issued
= 1;
2855 } else if ((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSE_WAIT
) ||
2856 ((original_ibqp_state
== IB_QPS_RTS
) &&
2857 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2859 if (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
)
2860 disconn_status
= -ECONNRESET
;
2863 if (((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSED
) ||
2864 (original_hw_tcp_state
== NES_AEQE_TCP_STATE_TIME_WAIT
) ||
2865 (last_ae
== NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
) ||
2866 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2868 nesqp
->cm_id
= NULL
;
2869 if (nesqp
->flush_issued
== 0) {
2870 nesqp
->flush_issued
= 1;
2875 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2877 if ((issue_flush
) && (nesqp
->destroyed
== 0)) {
2878 /* Flush the queue(s) */
2879 if (nesqp
->hw_iwarp_state
>= NES_AEQE_IWARP_STATE_TERMINATE
)
2880 flush_q
|= NES_CQP_FLUSH_SQ
;
2881 flush_wqes(nesvnic
->nesdev
, nesqp
, flush_q
, 1);
2883 if (nesqp
->term_flags
) {
2884 ibevent
.device
= nesqp
->ibqp
.device
;
2885 ibevent
.event
= nesqp
->terminate_eventtype
;
2886 ibevent
.element
.qp
= &nesqp
->ibqp
;
2887 if (nesqp
->ibqp
.event_handler
)
2888 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2892 if ((cm_id
) && (cm_id
->event_handler
)) {
2893 if (issue_disconn
) {
2894 atomic_inc(&cm_disconnects
);
2895 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
2896 cm_event
.status
= disconn_status
;
2897 cm_event
.local_addr
= cm_id
->local_addr
;
2898 cm_event
.remote_addr
= cm_id
->remote_addr
;
2899 cm_event
.private_data
= NULL
;
2900 cm_event
.private_data_len
= 0;
2902 nes_debug(NES_DBG_CM
, "Generating a CM Disconnect Event"
2903 " for QP%u, SQ Head = %u, SQ Tail = %u. "
2904 "cm_id = %p, refcount = %u.\n",
2905 nesqp
->hwqp
.qp_id
, nesqp
->hwqp
.sq_head
,
2906 nesqp
->hwqp
.sq_tail
, cm_id
,
2907 atomic_read(&nesqp
->refcount
));
2909 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2911 nes_debug(NES_DBG_CM
, "OFA CM event_handler "
2912 "returned, ret=%d\n", ret
);
2916 atomic_inc(&cm_closes
);
2917 nes_disconnect(nesqp
, 1);
2919 cm_id
->provider_data
= nesqp
;
2920 /* Send up the close complete event */
2921 cm_event
.event
= IW_CM_EVENT_CLOSE
;
2922 cm_event
.status
= 0;
2923 cm_event
.provider_data
= cm_id
->provider_data
;
2924 cm_event
.local_addr
= cm_id
->local_addr
;
2925 cm_event
.remote_addr
= cm_id
->remote_addr
;
2926 cm_event
.private_data
= NULL
;
2927 cm_event
.private_data_len
= 0;
2929 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2931 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
2933 cm_id
->rem_ref(cm_id
);
2944 static int nes_disconnect(struct nes_qp
*nesqp
, int abrupt
)
2947 struct nes_vnic
*nesvnic
;
2948 struct nes_device
*nesdev
;
2949 struct nes_ib_device
*nesibdev
;
2951 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2955 nesdev
= nesvnic
->nesdev
;
2956 nesibdev
= nesvnic
->nesibdev
;
2958 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
2959 netdev_refcnt_read(nesvnic
->netdev
));
2961 if (nesqp
->active_conn
) {
2963 /* indicate this connection is NOT active */
2964 nesqp
->active_conn
= 0;
2966 /* Need to free the Last Streaming Mode Message */
2967 if (nesqp
->ietf_frame
) {
2969 nesibdev
->ibdev
.dereg_mr(nesqp
->lsmm_mr
);
2970 pci_free_consistent(nesdev
->pcidev
,
2971 nesqp
->private_data_len
+ nesqp
->ietf_frame_size
,
2972 nesqp
->ietf_frame
, nesqp
->ietf_frame_pbase
);
2976 /* close the CM node down if it is still active */
2977 if (nesqp
->cm_node
) {
2978 nes_debug(NES_DBG_CM
, "Call close API\n");
2980 g_cm_core
->api
->close(g_cm_core
, nesqp
->cm_node
);
2990 int nes_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
2994 struct nes_qp
*nesqp
;
2995 struct nes_vnic
*nesvnic
;
2996 struct nes_device
*nesdev
;
2997 struct nes_cm_node
*cm_node
;
2998 struct nes_adapter
*adapter
;
2999 struct ib_qp_attr attr
;
3000 struct iw_cm_event cm_event
;
3001 struct nes_hw_qp_wqe
*wqe
;
3002 struct nes_v4_quad nes_quad
;
3006 struct nes_ib_device
*nesibdev
;
3007 struct ib_mr
*ibmr
= NULL
;
3008 struct ib_phys_buf ibphysbuf
;
3009 struct nes_pd
*nespd
;
3011 u8 mpa_frame_offset
= 0;
3012 struct ietf_mpa_v2
*mpa_v2_frame
;
3014 u8
*start_ptr
= &start_addr
;
3015 u8
**start_buff
= &start_ptr
;
3018 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
3022 /* get all our handles */
3023 nesqp
= to_nesqp(ibqp
);
3024 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3025 nesdev
= nesvnic
->nesdev
;
3026 adapter
= nesdev
->nesadapter
;
3028 cm_node
= (struct nes_cm_node
*)cm_id
->provider_data
;
3029 nes_debug(NES_DBG_CM
, "nes_accept: cm_node= %p nesvnic=%p, netdev=%p,"
3030 "%s\n", cm_node
, nesvnic
, nesvnic
->netdev
,
3031 nesvnic
->netdev
->name
);
3033 if (NES_CM_STATE_LISTENER_DESTROYED
== cm_node
->state
) {
3034 if (cm_node
->loopbackpartner
)
3035 rem_ref_cm_node(cm_node
->cm_core
, cm_node
->loopbackpartner
);
3036 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
3040 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
3041 if (passive_state
== NES_SEND_RESET_EVENT
) {
3042 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
3046 /* associate the node with the QP */
3047 nesqp
->cm_node
= (void *)cm_node
;
3048 cm_node
->nesqp
= nesqp
;
3050 nes_debug(NES_DBG_CM
, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
3051 nesqp
->hwqp
.qp_id
, cm_node
, jiffies
, cm_node
->listener
);
3052 atomic_inc(&cm_accepts
);
3054 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
3055 netdev_refcnt_read(nesvnic
->netdev
));
3057 nesqp
->ietf_frame_size
= sizeof(struct ietf_mpa_v2
);
3058 /* allocate the ietf frame and space for private data */
3059 nesqp
->ietf_frame
= pci_alloc_consistent(nesdev
->pcidev
,
3060 nesqp
->ietf_frame_size
+ conn_param
->private_data_len
,
3061 &nesqp
->ietf_frame_pbase
);
3063 if (!nesqp
->ietf_frame
) {
3064 nes_debug(NES_DBG_CM
, "Unable to allocate memory for private data\n");
3067 mpa_v2_frame
= (struct ietf_mpa_v2
*)nesqp
->ietf_frame
;
3069 if (cm_node
->mpa_frame_rev
== IETF_MPA_V1
)
3070 mpa_frame_offset
= 4;
3072 memcpy(mpa_v2_frame
->priv_data
, conn_param
->private_data
,
3073 conn_param
->private_data_len
);
3075 cm_build_mpa_frame(cm_node
, start_buff
, &buff_len
, nesqp
->ietf_frame
, MPA_KEY_REPLY
);
3076 nesqp
->private_data_len
= conn_param
->private_data_len
;
3078 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
3079 wqe
= &nesqp
->hwqp
.sq_vbase
[0];
3081 if (cm_id
->remote_addr
.sin_addr
.s_addr
!=
3082 cm_id
->local_addr
.sin_addr
.s_addr
) {
3083 u64temp
= (unsigned long)nesqp
;
3084 nesibdev
= nesvnic
->nesibdev
;
3085 nespd
= nesqp
->nespd
;
3086 ibphysbuf
.addr
= nesqp
->ietf_frame_pbase
+ mpa_frame_offset
;
3087 ibphysbuf
.size
= buff_len
;
3088 tagged_offset
= (u64
)(unsigned long)*start_buff
;
3089 ibmr
= nesibdev
->ibdev
.reg_phys_mr((struct ib_pd
*)nespd
,
3091 IB_ACCESS_LOCAL_WRITE
,
3094 nes_debug(NES_DBG_CM
, "Unable to register memory region"
3095 "for lSMM for cm_node = %p \n",
3097 pci_free_consistent(nesdev
->pcidev
,
3098 nesqp
->private_data_len
+ nesqp
->ietf_frame_size
,
3099 nesqp
->ietf_frame
, nesqp
->ietf_frame_pbase
);
3103 ibmr
->pd
= &nespd
->ibpd
;
3104 ibmr
->device
= nespd
->ibpd
.device
;
3105 nesqp
->lsmm_mr
= ibmr
;
3107 u64temp
|= NES_SW_CONTEXT_ALIGN
>> 1;
3108 set_wqe_64bit_value(wqe
->wqe_words
,
3109 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
,
3111 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
3112 cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING
|
3113 NES_IWARP_SQ_WQE_WRPDU
);
3114 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] =
3115 cpu_to_le32(buff_len
);
3116 set_wqe_64bit_value(wqe
->wqe_words
,
3117 NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
,
3118 (u64
)(unsigned long)(*start_buff
));
3119 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] =
3120 cpu_to_le32(buff_len
);
3121 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = ibmr
->lkey
;
3122 if (nesqp
->sq_kmapped
) {
3123 nesqp
->sq_kmapped
= 0;
3124 kunmap(nesqp
->page
);
3127 nesqp
->nesqp_context
->ird_ord_sizes
|=
3128 cpu_to_le32(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
3129 NES_QPCONTEXT_ORDIRD_WRPDU
);
3131 nesqp
->nesqp_context
->ird_ord_sizes
|=
3132 cpu_to_le32(NES_QPCONTEXT_ORDIRD_WRPDU
);
3134 nesqp
->skip_lsmm
= 1;
3137 /* Cache the cm_id in the qp */
3138 nesqp
->cm_id
= cm_id
;
3139 cm_node
->cm_id
= cm_id
;
3141 /* nesqp->cm_node = (void *)cm_id->provider_data; */
3142 cm_id
->provider_data
= nesqp
;
3143 nesqp
->active_conn
= 0;
3145 if (cm_node
->state
== NES_CM_STATE_TSA
)
3146 nes_debug(NES_DBG_CM
, "Already state = TSA for cm_node=%p\n",
3149 nes_cm_init_tsa_conn(nesqp
, cm_node
);
3151 nesqp
->nesqp_context
->tcpPorts
[0] =
3152 cpu_to_le16(ntohs(cm_id
->local_addr
.sin_port
));
3153 nesqp
->nesqp_context
->tcpPorts
[1] =
3154 cpu_to_le16(ntohs(cm_id
->remote_addr
.sin_port
));
3156 if (ipv4_is_loopback(cm_id
->remote_addr
.sin_addr
.s_addr
))
3157 nesqp
->nesqp_context
->ip0
=
3158 cpu_to_le32(ntohl(nesvnic
->local_ipaddr
));
3160 nesqp
->nesqp_context
->ip0
=
3161 cpu_to_le32(ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
));
3163 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
3164 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
3165 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
3167 nesqp
->nesqp_context
->arp_index_vlan
|=
3168 cpu_to_le32(nes_arp_table(nesdev
,
3169 le32_to_cpu(nesqp
->nesqp_context
->ip0
), NULL
,
3170 NES_ARP_RESOLVE
) << 16);
3172 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
3173 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
3175 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
3177 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32(
3178 ((u32
)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
));
3179 nesqp
->nesqp_context
->ird_ord_sizes
|=
3180 cpu_to_le32((u32
)conn_param
->ord
);
3182 memset(&nes_quad
, 0, sizeof(nes_quad
));
3183 nes_quad
.DstIpAdrIndex
=
3184 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
3185 if (ipv4_is_loopback(cm_id
->remote_addr
.sin_addr
.s_addr
))
3186 nes_quad
.SrcIpadr
= nesvnic
->local_ipaddr
;
3188 nes_quad
.SrcIpadr
= cm_id
->remote_addr
.sin_addr
.s_addr
;
3189 nes_quad
.TcpPorts
[0] = cm_id
->remote_addr
.sin_port
;
3190 nes_quad
.TcpPorts
[1] = cm_id
->local_addr
.sin_port
;
3192 /* Produce hash key */
3193 crc_value
= get_crc_value(&nes_quad
);
3194 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
3195 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, CRC = 0x%08X\n",
3196 nesqp
->hte_index
, nesqp
->hte_index
& adapter
->hte_index_mask
);
3198 nesqp
->hte_index
&= adapter
->hte_index_mask
;
3199 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
3201 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
3203 nes_debug(NES_DBG_CM
, "QP%u, Destination IP = 0x%08X:0x%04X, local = "
3204 "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
3205 "private data length=%u.\n", nesqp
->hwqp
.qp_id
,
3206 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
3207 ntohs(cm_id
->remote_addr
.sin_port
),
3208 ntohl(cm_id
->local_addr
.sin_addr
.s_addr
),
3209 ntohs(cm_id
->local_addr
.sin_port
),
3210 le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
3211 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
3214 /* notify OF layer that accept event was successful */
3215 cm_id
->add_ref(cm_id
);
3216 nes_add_ref(&nesqp
->ibqp
);
3218 cm_event
.event
= IW_CM_EVENT_ESTABLISHED
;
3219 cm_event
.status
= 0;
3220 cm_event
.provider_data
= (void *)nesqp
;
3221 cm_event
.local_addr
= cm_id
->local_addr
;
3222 cm_event
.remote_addr
= cm_id
->remote_addr
;
3223 cm_event
.private_data
= NULL
;
3224 cm_event
.private_data_len
= 0;
3225 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3226 attr
.qp_state
= IB_QPS_RTS
;
3227 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3228 if (cm_node
->loopbackpartner
) {
3229 cm_node
->loopbackpartner
->mpa_frame_size
=
3230 nesqp
->private_data_len
;
3231 /* copy entire MPA frame to our cm_node's frame */
3232 memcpy(cm_node
->loopbackpartner
->mpa_frame_buf
,
3233 conn_param
->private_data
, conn_param
->private_data_len
);
3234 create_event(cm_node
->loopbackpartner
, NES_CM_EVENT_CONNECTED
);
3237 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3238 "ret=%d\n", __func__
, __LINE__
, ret
);
3247 int nes_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
3249 struct nes_cm_node
*cm_node
;
3250 struct nes_cm_node
*loopback
;
3251 struct nes_cm_core
*cm_core
;
3254 atomic_inc(&cm_rejects
);
3255 cm_node
= (struct nes_cm_node
*)cm_id
->provider_data
;
3256 loopback
= cm_node
->loopbackpartner
;
3257 cm_core
= cm_node
->cm_core
;
3258 cm_node
->cm_id
= cm_id
;
3260 if (pdata_len
+ sizeof(struct ietf_mpa_v2
) > MAX_CM_BUFFER
)
3264 memcpy(&loopback
->mpa_frame
.priv_data
, pdata
, pdata_len
);
3265 loopback
->mpa_frame
.priv_data_len
= pdata_len
;
3266 loopback
->mpa_frame_size
= pdata_len
;
3268 start_buff
= &cm_node
->mpa_frame_buf
[0] + sizeof(struct ietf_mpa_v2
);
3269 cm_node
->mpa_frame_size
= pdata_len
;
3270 memcpy(start_buff
, pdata
, pdata_len
);
3272 return cm_core
->api
->reject(cm_core
, cm_node
);
3278 * setup and launch cm connect node
3280 int nes_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
3283 struct nes_qp
*nesqp
;
3284 struct nes_vnic
*nesvnic
;
3285 struct nes_device
*nesdev
;
3286 struct nes_cm_node
*cm_node
;
3287 struct nes_cm_info cm_info
;
3290 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
3293 nesqp
= to_nesqp(ibqp
);
3296 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3299 nesdev
= nesvnic
->nesdev
;
3303 if (!(cm_id
->local_addr
.sin_port
) || !(cm_id
->remote_addr
.sin_port
))
3306 nes_debug(NES_DBG_CM
, "QP%u, current IP = 0x%08X, Destination IP = "
3307 "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp
->hwqp
.qp_id
,
3308 ntohl(nesvnic
->local_ipaddr
),
3309 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
3310 ntohs(cm_id
->remote_addr
.sin_port
),
3311 ntohl(cm_id
->local_addr
.sin_addr
.s_addr
),
3312 ntohs(cm_id
->local_addr
.sin_port
));
3314 atomic_inc(&cm_connects
);
3315 nesqp
->active_conn
= 1;
3317 /* cache the cm_id in the qp */
3318 nesqp
->cm_id
= cm_id
;
3320 cm_id
->provider_data
= nesqp
;
3322 nesqp
->private_data_len
= conn_param
->private_data_len
;
3323 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32((u32
)conn_param
->ord
);
3324 /* space for rdma0 read msg */
3325 if (conn_param
->ord
== 0)
3326 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32(1);
3328 nes_debug(NES_DBG_CM
, "requested ord = 0x%08X.\n", (u32
)conn_param
->ord
);
3329 nes_debug(NES_DBG_CM
, "mpa private data len =%u\n",
3330 conn_param
->private_data_len
);
3332 if (cm_id
->local_addr
.sin_addr
.s_addr
!=
3333 cm_id
->remote_addr
.sin_addr
.s_addr
) {
3334 nes_manage_apbvt(nesvnic
, ntohs(cm_id
->local_addr
.sin_port
),
3335 PCI_FUNC(nesdev
->pcidev
->devfn
), NES_MANAGE_APBVT_ADD
);
3339 /* set up the connection params for the node */
3340 cm_info
.loc_addr
= htonl(cm_id
->local_addr
.sin_addr
.s_addr
);
3341 cm_info
.loc_port
= htons(cm_id
->local_addr
.sin_port
);
3342 cm_info
.rem_addr
= htonl(cm_id
->remote_addr
.sin_addr
.s_addr
);
3343 cm_info
.rem_port
= htons(cm_id
->remote_addr
.sin_port
);
3344 cm_info
.cm_id
= cm_id
;
3345 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
3347 cm_id
->add_ref(cm_id
);
3349 /* create a connect CM node connection */
3350 cm_node
= g_cm_core
->api
->connect(g_cm_core
, nesvnic
,
3351 conn_param
->private_data_len
, (void *)conn_param
->private_data
,
3355 nes_manage_apbvt(nesvnic
, ntohs(cm_id
->local_addr
.sin_port
),
3356 PCI_FUNC(nesdev
->pcidev
->devfn
),
3357 NES_MANAGE_APBVT_DEL
);
3359 cm_id
->rem_ref(cm_id
);
3363 cm_node
->apbvt_set
= apbvt_set
;
3364 nesqp
->cm_node
= cm_node
;
3365 cm_node
->nesqp
= nesqp
;
3366 nes_add_ref(&nesqp
->ibqp
);
3375 int nes_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
3377 struct nes_vnic
*nesvnic
;
3378 struct nes_cm_listener
*cm_node
;
3379 struct nes_cm_info cm_info
;
3382 nes_debug(NES_DBG_CM
, "cm_id = %p, local port = 0x%04X.\n",
3383 cm_id
, ntohs(cm_id
->local_addr
.sin_port
));
3385 nesvnic
= to_nesvnic(cm_id
->device
);
3389 nes_debug(NES_DBG_CM
, "nesvnic=%p, netdev=%p, %s\n",
3390 nesvnic
, nesvnic
->netdev
, nesvnic
->netdev
->name
);
3392 nes_debug(NES_DBG_CM
, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
3393 nesvnic
->local_ipaddr
, cm_id
->local_addr
.sin_addr
.s_addr
);
3395 /* setup listen params in our api call struct */
3396 cm_info
.loc_addr
= nesvnic
->local_ipaddr
;
3397 cm_info
.loc_port
= cm_id
->local_addr
.sin_port
;
3398 cm_info
.backlog
= backlog
;
3399 cm_info
.cm_id
= cm_id
;
3401 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
3404 cm_node
= g_cm_core
->api
->listen(g_cm_core
, nesvnic
, &cm_info
);
3406 printk(KERN_ERR
"%s[%u] Error returned from listen API call\n",
3407 __func__
, __LINE__
);
3411 cm_id
->provider_data
= cm_node
;
3413 if (!cm_node
->reused_node
) {
3414 err
= nes_manage_apbvt(nesvnic
,
3415 ntohs(cm_id
->local_addr
.sin_port
),
3416 PCI_FUNC(nesvnic
->nesdev
->pcidev
->devfn
),
3417 NES_MANAGE_APBVT_ADD
);
3419 printk(KERN_ERR
"nes_manage_apbvt call returned %d.\n",
3421 g_cm_core
->api
->stop_listener(g_cm_core
, (void *)cm_node
);
3424 atomic_inc(&cm_listens_created
);
3427 cm_id
->add_ref(cm_id
);
3428 cm_id
->provider_data
= (void *)cm_node
;
3436 * nes_destroy_listen
3438 int nes_destroy_listen(struct iw_cm_id
*cm_id
)
3440 if (cm_id
->provider_data
)
3441 g_cm_core
->api
->stop_listener(g_cm_core
, cm_id
->provider_data
);
3443 nes_debug(NES_DBG_CM
, "cm_id->provider_data was NULL\n");
3445 cm_id
->rem_ref(cm_id
);
3454 int nes_cm_recv(struct sk_buff
*skb
, struct net_device
*netdevice
)
3458 cm_packets_received
++;
3459 if ((g_cm_core
) && (g_cm_core
->api
))
3460 rc
= g_cm_core
->api
->recv_pkt(g_cm_core
, netdev_priv(netdevice
), skb
);
3462 nes_debug(NES_DBG_CM
, "Unable to process packet for CM,"
3463 " cm is not setup properly.\n");
3471 * Start and init a cm core module
3473 int nes_cm_start(void)
3475 nes_debug(NES_DBG_CM
, "\n");
3476 /* create the primary CM core, pass this handle to subsequent core inits */
3477 g_cm_core
= nes_cm_alloc_core();
3487 * stop and dealloc all cm core instances
3489 int nes_cm_stop(void)
3491 g_cm_core
->api
->destroy_cm_core(g_cm_core
);
3497 * cm_event_connected
3498 * handle a connected event, setup QPs and HW
3500 static void cm_event_connected(struct nes_cm_event
*event
)
3502 struct nes_qp
*nesqp
;
3503 struct nes_vnic
*nesvnic
;
3504 struct nes_device
*nesdev
;
3505 struct nes_cm_node
*cm_node
;
3506 struct nes_adapter
*nesadapter
;
3507 struct ib_qp_attr attr
;
3508 struct iw_cm_id
*cm_id
;
3509 struct iw_cm_event cm_event
;
3510 struct nes_v4_quad nes_quad
;
3514 /* get all our handles */
3515 cm_node
= event
->cm_node
;
3516 cm_id
= cm_node
->cm_id
;
3517 nes_debug(NES_DBG_CM
, "cm_event_connected - %p - cm_id = %p\n", cm_node
, cm_id
);
3518 nesqp
= (struct nes_qp
*)cm_id
->provider_data
;
3519 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3520 nesdev
= nesvnic
->nesdev
;
3521 nesadapter
= nesdev
->nesadapter
;
3523 if (nesqp
->destroyed
)
3525 atomic_inc(&cm_connecteds
);
3526 nes_debug(NES_DBG_CM
, "QP%u attempting to connect to 0x%08X:0x%04X on"
3527 " local port 0x%04X. jiffies = %lu.\n",
3529 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
3530 ntohs(cm_id
->remote_addr
.sin_port
),
3531 ntohs(cm_id
->local_addr
.sin_port
),
3534 nes_cm_init_tsa_conn(nesqp
, cm_node
);
3536 /* set the QP tsa context */
3537 nesqp
->nesqp_context
->tcpPorts
[0] =
3538 cpu_to_le16(ntohs(cm_id
->local_addr
.sin_port
));
3539 nesqp
->nesqp_context
->tcpPorts
[1] =
3540 cpu_to_le16(ntohs(cm_id
->remote_addr
.sin_port
));
3541 if (ipv4_is_loopback(cm_id
->remote_addr
.sin_addr
.s_addr
))
3542 nesqp
->nesqp_context
->ip0
=
3543 cpu_to_le32(ntohl(nesvnic
->local_ipaddr
));
3545 nesqp
->nesqp_context
->ip0
=
3546 cpu_to_le32(ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
));
3548 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
3549 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
3550 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
3551 nesqp
->nesqp_context
->arp_index_vlan
|= cpu_to_le32(
3552 nes_arp_table(nesdev
,
3553 le32_to_cpu(nesqp
->nesqp_context
->ip0
),
3554 NULL
, NES_ARP_RESOLVE
) << 16);
3555 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
3556 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
3557 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
3558 nesqp
->nesqp_context
->ird_ord_sizes
|=
3559 cpu_to_le32((u32
)1 <<
3560 NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
);
3562 /* Adjust tail for not having a LSMM */
3563 /*nesqp->hwqp.sq_tail = 1;*/
3565 build_rdma0_msg(cm_node
, &nesqp
);
3567 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
,
3568 (1 << 24) | 0x00800000 | nesqp
->hwqp
.qp_id
);
3570 memset(&nes_quad
, 0, sizeof(nes_quad
));
3572 nes_quad
.DstIpAdrIndex
=
3573 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
3574 if (ipv4_is_loopback(cm_id
->remote_addr
.sin_addr
.s_addr
))
3575 nes_quad
.SrcIpadr
= nesvnic
->local_ipaddr
;
3577 nes_quad
.SrcIpadr
= cm_id
->remote_addr
.sin_addr
.s_addr
;
3578 nes_quad
.TcpPorts
[0] = cm_id
->remote_addr
.sin_port
;
3579 nes_quad
.TcpPorts
[1] = cm_id
->local_addr
.sin_port
;
3581 /* Produce hash key */
3582 crc_value
= get_crc_value(&nes_quad
);
3583 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
3584 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
3585 nesqp
->hte_index
, nesqp
->hte_index
& nesadapter
->hte_index_mask
);
3587 nesqp
->hte_index
&= nesadapter
->hte_index_mask
;
3588 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
3590 nesqp
->ietf_frame
= &cm_node
->mpa_frame
;
3591 nesqp
->private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3592 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
3594 /* notify OF layer we successfully created the requested connection */
3595 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3596 cm_event
.status
= 0;
3597 cm_event
.provider_data
= cm_id
->provider_data
;
3598 cm_event
.local_addr
.sin_family
= AF_INET
;
3599 cm_event
.local_addr
.sin_port
= cm_id
->local_addr
.sin_port
;
3600 cm_event
.remote_addr
= cm_id
->remote_addr
;
3602 cm_event
.private_data
= (void *)event
->cm_node
->mpa_frame_buf
;
3603 cm_event
.private_data_len
= (u8
)event
->cm_node
->mpa_frame_size
;
3604 cm_event
.ird
= cm_node
->ird_size
;
3605 cm_event
.ord
= cm_node
->ord_size
;
3607 cm_event
.local_addr
.sin_addr
.s_addr
= event
->cm_info
.rem_addr
;
3608 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3609 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3612 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3613 "ret=%d\n", __func__
, __LINE__
, ret
);
3614 attr
.qp_state
= IB_QPS_RTS
;
3615 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3617 nes_debug(NES_DBG_CM
, "Exiting connect thread for QP%u. jiffies = "
3618 "%lu\n", nesqp
->hwqp
.qp_id
, jiffies
);
3625 * cm_event_connect_error
3627 static void cm_event_connect_error(struct nes_cm_event
*event
)
3629 struct nes_qp
*nesqp
;
3630 struct iw_cm_id
*cm_id
;
3631 struct iw_cm_event cm_event
;
3632 /* struct nes_cm_info cm_info; */
3635 if (!event
->cm_node
)
3638 cm_id
= event
->cm_node
->cm_id
;
3642 nes_debug(NES_DBG_CM
, "cm_node=%p, cm_id=%p\n", event
->cm_node
, cm_id
);
3643 nesqp
= cm_id
->provider_data
;
3648 /* notify OF layer about this connection error event */
3649 /* cm_id->rem_ref(cm_id); */
3650 nesqp
->cm_id
= NULL
;
3651 cm_id
->provider_data
= NULL
;
3652 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3653 cm_event
.status
= -ECONNRESET
;
3654 cm_event
.provider_data
= cm_id
->provider_data
;
3655 cm_event
.local_addr
= cm_id
->local_addr
;
3656 cm_event
.remote_addr
= cm_id
->remote_addr
;
3657 cm_event
.private_data
= NULL
;
3658 cm_event
.private_data_len
= 0;
3660 nes_debug(NES_DBG_CM
, "call CM_EVENT REJECTED, local_addr=%08x, "
3661 "remove_addr=%08x\n", cm_event
.local_addr
.sin_addr
.s_addr
,
3662 cm_event
.remote_addr
.sin_addr
.s_addr
);
3664 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3665 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3667 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3668 "ret=%d\n", __func__
, __LINE__
, ret
);
3669 cm_id
->rem_ref(cm_id
);
3671 rem_ref_cm_node(event
->cm_node
->cm_core
, event
->cm_node
);
3679 static void cm_event_reset(struct nes_cm_event
*event
)
3681 struct nes_qp
*nesqp
;
3682 struct iw_cm_id
*cm_id
;
3683 struct iw_cm_event cm_event
;
3684 /* struct nes_cm_info cm_info; */
3687 if (!event
->cm_node
)
3690 if (!event
->cm_node
->cm_id
)
3693 cm_id
= event
->cm_node
->cm_id
;
3695 nes_debug(NES_DBG_CM
, "%p - cm_id = %p\n", event
->cm_node
, cm_id
);
3696 nesqp
= cm_id
->provider_data
;
3700 nesqp
->cm_id
= NULL
;
3701 /* cm_id->provider_data = NULL; */
3702 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
3703 cm_event
.status
= -ECONNRESET
;
3704 cm_event
.provider_data
= cm_id
->provider_data
;
3705 cm_event
.local_addr
= cm_id
->local_addr
;
3706 cm_event
.remote_addr
= cm_id
->remote_addr
;
3707 cm_event
.private_data
= NULL
;
3708 cm_event
.private_data_len
= 0;
3710 cm_id
->add_ref(cm_id
);
3711 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3712 atomic_inc(&cm_closes
);
3713 cm_event
.event
= IW_CM_EVENT_CLOSE
;
3714 cm_event
.status
= 0;
3715 cm_event
.provider_data
= cm_id
->provider_data
;
3716 cm_event
.local_addr
= cm_id
->local_addr
;
3717 cm_event
.remote_addr
= cm_id
->remote_addr
;
3718 cm_event
.private_data
= NULL
;
3719 cm_event
.private_data_len
= 0;
3720 nes_debug(NES_DBG_CM
, "NODE %p Generating CLOSE\n", event
->cm_node
);
3721 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3723 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3726 /* notify OF layer about this connection error event */
3727 cm_id
->rem_ref(cm_id
);
3736 static void cm_event_mpa_req(struct nes_cm_event
*event
)
3738 struct iw_cm_id
*cm_id
;
3739 struct iw_cm_event cm_event
;
3741 struct nes_cm_node
*cm_node
;
3743 cm_node
= event
->cm_node
;
3746 cm_id
= cm_node
->cm_id
;
3748 atomic_inc(&cm_connect_reqs
);
3749 nes_debug(NES_DBG_CM
, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3750 cm_node
, cm_id
, jiffies
);
3752 cm_event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
3753 cm_event
.status
= 0;
3754 cm_event
.provider_data
= (void *)cm_node
;
3756 cm_event
.local_addr
.sin_family
= AF_INET
;
3757 cm_event
.local_addr
.sin_port
= htons(event
->cm_info
.loc_port
);
3758 cm_event
.local_addr
.sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3760 cm_event
.remote_addr
.sin_family
= AF_INET
;
3761 cm_event
.remote_addr
.sin_port
= htons(event
->cm_info
.rem_port
);
3762 cm_event
.remote_addr
.sin_addr
.s_addr
= htonl(event
->cm_info
.rem_addr
);
3763 cm_event
.private_data
= cm_node
->mpa_frame_buf
;
3764 cm_event
.private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3765 cm_event
.ird
= cm_node
->ird_size
;
3766 cm_event
.ord
= cm_node
->ord_size
;
3768 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3770 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, ret=%d\n",
3771 __func__
, __LINE__
, ret
);
3776 static void cm_event_mpa_reject(struct nes_cm_event
*event
)
3778 struct iw_cm_id
*cm_id
;
3779 struct iw_cm_event cm_event
;
3780 struct nes_cm_node
*cm_node
;
3783 cm_node
= event
->cm_node
;
3786 cm_id
= cm_node
->cm_id
;
3788 atomic_inc(&cm_connect_reqs
);
3789 nes_debug(NES_DBG_CM
, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3790 cm_node
, cm_id
, jiffies
);
3792 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3793 cm_event
.status
= -ECONNREFUSED
;
3794 cm_event
.provider_data
= cm_id
->provider_data
;
3796 cm_event
.local_addr
.sin_family
= AF_INET
;
3797 cm_event
.local_addr
.sin_port
= htons(event
->cm_info
.loc_port
);
3798 cm_event
.local_addr
.sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3800 cm_event
.remote_addr
.sin_family
= AF_INET
;
3801 cm_event
.remote_addr
.sin_port
= htons(event
->cm_info
.rem_port
);
3802 cm_event
.remote_addr
.sin_addr
.s_addr
= htonl(event
->cm_info
.rem_addr
);
3804 cm_event
.private_data
= cm_node
->mpa_frame_buf
;
3805 cm_event
.private_data_len
= (u8
)cm_node
->mpa_frame_size
;
3807 nes_debug(NES_DBG_CM
, "call CM_EVENT_MPA_REJECTED, local_addr=%08x, "
3808 "remove_addr=%08x\n",
3809 cm_event
.local_addr
.sin_addr
.s_addr
,
3810 cm_event
.remote_addr
.sin_addr
.s_addr
);
3812 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3814 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, ret=%d\n",
3815 __func__
, __LINE__
, ret
);
3821 static void nes_cm_event_handler(struct work_struct
*);
3825 * post an event to the cm event handler
3827 static int nes_cm_post_event(struct nes_cm_event
*event
)
3829 atomic_inc(&event
->cm_node
->cm_core
->events_posted
);
3830 add_ref_cm_node(event
->cm_node
);
3831 event
->cm_info
.cm_id
->add_ref(event
->cm_info
.cm_id
);
3832 INIT_WORK(&event
->event_work
, nes_cm_event_handler
);
3833 nes_debug(NES_DBG_CM
, "cm_node=%p queue_work, event=%p\n",
3834 event
->cm_node
, event
);
3836 queue_work(event
->cm_node
->cm_core
->event_wq
, &event
->event_work
);
3838 nes_debug(NES_DBG_CM
, "Exit\n");
3844 * nes_cm_event_handler
3845 * worker function to handle cm events
3846 * will free instance of nes_cm_event
3848 static void nes_cm_event_handler(struct work_struct
*work
)
3850 struct nes_cm_event
*event
= container_of(work
, struct nes_cm_event
,
3852 struct nes_cm_core
*cm_core
;
3854 if ((!event
) || (!event
->cm_node
) || (!event
->cm_node
->cm_core
))
3857 cm_core
= event
->cm_node
->cm_core
;
3858 nes_debug(NES_DBG_CM
, "event=%p, event->type=%u, events posted=%u\n",
3859 event
, event
->type
, atomic_read(&cm_core
->events_posted
));
3861 switch (event
->type
) {
3862 case NES_CM_EVENT_MPA_REQ
:
3863 cm_event_mpa_req(event
);
3864 nes_debug(NES_DBG_CM
, "cm_node=%p CM Event: MPA REQUEST\n",
3867 case NES_CM_EVENT_RESET
:
3868 nes_debug(NES_DBG_CM
, "cm_node = %p CM Event: RESET\n",
3870 cm_event_reset(event
);
3872 case NES_CM_EVENT_CONNECTED
:
3873 if ((!event
->cm_node
->cm_id
) ||
3874 (event
->cm_node
->state
!= NES_CM_STATE_TSA
))
3876 cm_event_connected(event
);
3877 nes_debug(NES_DBG_CM
, "CM Event: CONNECTED\n");
3879 case NES_CM_EVENT_MPA_REJECT
:
3880 if ((!event
->cm_node
->cm_id
) ||
3881 (event
->cm_node
->state
== NES_CM_STATE_TSA
))
3883 cm_event_mpa_reject(event
);
3884 nes_debug(NES_DBG_CM
, "CM Event: REJECT\n");
3887 case NES_CM_EVENT_ABORTED
:
3888 if ((!event
->cm_node
->cm_id
) ||
3889 (event
->cm_node
->state
== NES_CM_STATE_TSA
))
3891 cm_event_connect_error(event
);
3892 nes_debug(NES_DBG_CM
, "CM Event: ABORTED\n");
3894 case NES_CM_EVENT_DROPPED_PKT
:
3895 nes_debug(NES_DBG_CM
, "CM Event: DROPPED PKT\n");
3898 nes_debug(NES_DBG_CM
, "CM Event: UNKNOWN EVENT TYPE\n");
3902 atomic_dec(&cm_core
->events_posted
);
3903 event
->cm_info
.cm_id
->rem_ref(event
->cm_info
.cm_id
);
3904 rem_ref_cm_node(cm_core
, event
->cm_node
);