2 * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #define TCPOPT_TIMESTAMP 8
37 #include <asm/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>
56 #include <net/neighbour.h>
57 #include <net/route.h>
58 #include <net/ip_fib.h>
63 u32 cm_packets_bounced
;
64 u32 cm_packets_dropped
;
65 u32 cm_packets_retrans
;
66 u32 cm_packets_created
;
67 u32 cm_packets_received
;
68 u32 cm_listens_created
;
69 u32 cm_listens_destroyed
;
71 atomic_t cm_loopbacks
;
72 atomic_t cm_nodes_created
;
73 atomic_t cm_nodes_destroyed
;
74 atomic_t cm_accel_dropped_pkts
;
75 atomic_t cm_resets_recvd
;
77 static inline int mini_cm_accelerated(struct nes_cm_core
*,
78 struct nes_cm_node
*);
79 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*,
80 struct nes_vnic
*, struct nes_cm_info
*);
81 static int mini_cm_del_listen(struct nes_cm_core
*, struct nes_cm_listener
*);
82 static struct nes_cm_node
*mini_cm_connect(struct nes_cm_core
*,
83 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 ietf_mpa_frame
*,
86 struct nes_cm_node
*);
87 static int mini_cm_reject(struct nes_cm_core
*, struct ietf_mpa_frame
*,
88 struct nes_cm_node
*);
89 static int mini_cm_recv_pkt(struct nes_cm_core
*, struct nes_vnic
*,
91 static int mini_cm_dealloc_core(struct nes_cm_core
*);
92 static int mini_cm_get(struct nes_cm_core
*);
93 static int mini_cm_set(struct nes_cm_core
*, u32
, u32
);
95 static struct sk_buff
*form_cm_frame(struct sk_buff
*, struct nes_cm_node
*,
96 void *, u32
, void *, u32
, u8
);
97 static struct sk_buff
*get_free_pkt(struct nes_cm_node
*cm_node
);
98 static int add_ref_cm_node(struct nes_cm_node
*);
99 static int rem_ref_cm_node(struct nes_cm_core
*, struct nes_cm_node
*);
101 static int nes_cm_disconn_true(struct nes_qp
*);
102 static int nes_cm_post_event(struct nes_cm_event
*event
);
103 static int nes_disconnect(struct nes_qp
*nesqp
, int abrupt
);
104 static void nes_disconnect_worker(struct work_struct
*work
);
106 static int send_mpa_request(struct nes_cm_node
*, struct sk_buff
*);
107 static int send_syn(struct nes_cm_node
*, u32
, struct sk_buff
*);
108 static int send_reset(struct nes_cm_node
*, struct sk_buff
*);
109 static int send_ack(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
);
110 static int send_fin(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
);
111 static void process_packet(struct nes_cm_node
*, struct sk_buff
*,
112 struct nes_cm_core
*);
114 static void active_open_err(struct nes_cm_node
*, struct sk_buff
*, int);
115 static void passive_open_err(struct nes_cm_node
*, struct sk_buff
*, int);
116 static void cleanup_retrans_entry(struct nes_cm_node
*);
117 static void handle_rcv_mpa(struct nes_cm_node
*, struct sk_buff
*,
118 enum nes_cm_event_type
);
119 static void free_retrans_entry(struct nes_cm_node
*cm_node
);
120 static int handle_tcp_options(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
121 struct sk_buff
*skb
, int optionsize
, int passive
);
123 /* CM event handler functions */
124 static void cm_event_connected(struct nes_cm_event
*);
125 static void cm_event_connect_error(struct nes_cm_event
*);
126 static void cm_event_reset(struct nes_cm_event
*);
127 static void cm_event_mpa_req(struct nes_cm_event
*);
129 static void print_core(struct nes_cm_core
*core
);
131 /* External CM API Interface */
132 /* instance of function pointers for client API */
133 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
134 static struct nes_cm_ops nes_cm_api
= {
143 mini_cm_dealloc_core
,
148 static struct nes_cm_core
*g_cm_core
;
150 atomic_t cm_connects
;
152 atomic_t cm_disconnects
;
154 atomic_t cm_connecteds
;
155 atomic_t cm_connect_reqs
;
162 static struct nes_cm_event
*create_event(struct nes_cm_node
*cm_node
,
163 enum nes_cm_event_type type
)
165 struct nes_cm_event
*event
;
170 /* allocate an empty event */
171 event
= kzalloc(sizeof(*event
), GFP_ATOMIC
);
177 event
->cm_node
= cm_node
;
178 event
->cm_info
.rem_addr
= cm_node
->rem_addr
;
179 event
->cm_info
.loc_addr
= cm_node
->loc_addr
;
180 event
->cm_info
.rem_port
= cm_node
->rem_port
;
181 event
->cm_info
.loc_port
= cm_node
->loc_port
;
182 event
->cm_info
.cm_id
= cm_node
->cm_id
;
184 nes_debug(NES_DBG_CM
, "cm_node=%p Created event=%p, type=%u, "
185 "dst_addr=%08x[%x], src_addr=%08x[%x]\n",
186 cm_node
, event
, type
, event
->cm_info
.loc_addr
,
187 event
->cm_info
.loc_port
, event
->cm_info
.rem_addr
,
188 event
->cm_info
.rem_port
);
190 nes_cm_post_event(event
);
198 static int send_mpa_request(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
202 nes_debug(NES_DBG_CM
, "skb set to NULL\n");
206 /* send an MPA Request frame */
207 form_cm_frame(skb
, cm_node
, NULL
, 0, &cm_node
->mpa_frame
,
208 cm_node
->mpa_frame_size
, SET_ACK
);
210 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
219 * recv_mpa - process a received TCP pkt, we are expecting an
222 static int parse_mpa(struct nes_cm_node
*cm_node
, u8
*buffer
, u32 len
)
224 struct ietf_mpa_frame
*mpa_frame
;
226 /* assume req frame is in tcp data payload */
227 if (len
< sizeof(struct ietf_mpa_frame
)) {
228 nes_debug(NES_DBG_CM
, "The received ietf buffer was too small (%x)\n", len
);
232 mpa_frame
= (struct ietf_mpa_frame
*)buffer
;
233 cm_node
->mpa_frame_size
= ntohs(mpa_frame
->priv_data_len
);
235 if (cm_node
->mpa_frame_size
+ sizeof(struct ietf_mpa_frame
) != len
) {
236 nes_debug(NES_DBG_CM
, "The received ietf buffer was not right"
237 " complete (%x + %x != %x)\n",
238 cm_node
->mpa_frame_size
, (u32
)sizeof(struct ietf_mpa_frame
), len
);
242 /* copy entire MPA frame to our cm_node's frame */
243 memcpy(cm_node
->mpa_frame_buf
, buffer
+ sizeof(struct ietf_mpa_frame
),
244 cm_node
->mpa_frame_size
);
251 * form_cm_frame - get a free packet and build empty frame Use
252 * node info to build.
254 static struct sk_buff
*form_cm_frame(struct sk_buff
*skb
,
255 struct nes_cm_node
*cm_node
, void *options
, u32 optionsize
,
256 void *data
, u32 datasize
, u8 flags
)
262 u16 packetsize
= sizeof(*iph
);
264 packetsize
+= sizeof(*tcph
);
265 packetsize
+= optionsize
+ datasize
;
267 memset(skb
->data
, 0x00, ETH_HLEN
+ sizeof(*iph
) + sizeof(*tcph
));
270 buf
= skb_put(skb
, packetsize
+ ETH_HLEN
);
272 ethh
= (struct ethhdr
*) buf
;
275 iph
= (struct iphdr
*)buf
;
277 tcph
= (struct tcphdr
*)buf
;
278 skb_reset_mac_header(skb
);
279 skb_set_network_header(skb
, ETH_HLEN
);
280 skb_set_transport_header(skb
, ETH_HLEN
+sizeof(*iph
));
281 buf
+= sizeof(*tcph
);
283 skb
->ip_summed
= CHECKSUM_PARTIAL
;
284 skb
->protocol
= htons(0x800);
286 skb
->mac_len
= ETH_HLEN
;
288 memcpy(ethh
->h_dest
, cm_node
->rem_mac
, ETH_ALEN
);
289 memcpy(ethh
->h_source
, cm_node
->loc_mac
, ETH_ALEN
);
290 ethh
->h_proto
= htons(0x0800);
292 iph
->version
= IPVERSION
;
293 iph
->ihl
= 5; /* 5 * 4Byte words, IP headr len */
295 iph
->tot_len
= htons(packetsize
);
296 iph
->id
= htons(++cm_node
->tcp_cntxt
.loc_id
);
298 iph
->frag_off
= htons(0x4000);
300 iph
->protocol
= 0x06; /* IPPROTO_TCP */
302 iph
->saddr
= htonl(cm_node
->loc_addr
);
303 iph
->daddr
= htonl(cm_node
->rem_addr
);
305 tcph
->source
= htons(cm_node
->loc_port
);
306 tcph
->dest
= htons(cm_node
->rem_port
);
307 tcph
->seq
= htonl(cm_node
->tcp_cntxt
.loc_seq_num
);
309 if (flags
& SET_ACK
) {
310 cm_node
->tcp_cntxt
.loc_ack_num
= cm_node
->tcp_cntxt
.rcv_nxt
;
311 tcph
->ack_seq
= htonl(cm_node
->tcp_cntxt
.loc_ack_num
);
316 if (flags
& SET_SYN
) {
317 cm_node
->tcp_cntxt
.loc_seq_num
++;
320 cm_node
->tcp_cntxt
.loc_seq_num
+= datasize
;
322 if (flags
& SET_FIN
) {
323 cm_node
->tcp_cntxt
.loc_seq_num
++;
330 tcph
->doff
= (u16
)((sizeof(*tcph
) + optionsize
+ 3) >> 2);
331 tcph
->window
= htons(cm_node
->tcp_cntxt
.rcv_wnd
);
334 memcpy(buf
, options
, optionsize
);
337 memcpy(buf
, data
, datasize
);
339 skb_shinfo(skb
)->nr_frags
= 0;
340 cm_packets_created
++;
347 * print_core - dump a cm core
349 static void print_core(struct nes_cm_core
*core
)
351 nes_debug(NES_DBG_CM
, "---------------------------------------------\n");
352 nes_debug(NES_DBG_CM
, "CM Core -- (core = %p )\n", core
);
355 nes_debug(NES_DBG_CM
, "---------------------------------------------\n");
357 nes_debug(NES_DBG_CM
, "State : %u \n", core
->state
);
359 nes_debug(NES_DBG_CM
, "Tx Free cnt : %u \n", skb_queue_len(&core
->tx_free_list
));
360 nes_debug(NES_DBG_CM
, "Listen Nodes : %u \n", atomic_read(&core
->listen_node_cnt
));
361 nes_debug(NES_DBG_CM
, "Active Nodes : %u \n", atomic_read(&core
->node_cnt
));
363 nes_debug(NES_DBG_CM
, "core : %p \n", core
);
365 nes_debug(NES_DBG_CM
, "-------------- end core ---------------\n");
371 * note - cm_node needs to be protected before calling this. Encase in:
372 * rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
374 int schedule_nes_timer(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
375 enum nes_timer_type type
, int send_retrans
,
376 int close_when_complete
)
379 struct nes_cm_core
*cm_core
= cm_node
->cm_core
;
380 struct nes_timer_entry
*new_send
;
386 new_send
= kzalloc(sizeof(*new_send
), GFP_ATOMIC
);
390 /* new_send->timetosend = currenttime */
391 new_send
->retrycount
= NES_DEFAULT_RETRYS
;
392 new_send
->retranscount
= NES_DEFAULT_RETRANS
;
394 new_send
->timetosend
= jiffies
;
395 new_send
->type
= type
;
396 new_send
->netdev
= cm_node
->netdev
;
397 new_send
->send_retrans
= send_retrans
;
398 new_send
->close_when_complete
= close_when_complete
;
400 if (type
== NES_TIMER_TYPE_CLOSE
) {
401 new_send
->timetosend
+= (HZ
/10);
402 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
403 list_add_tail(&new_send
->list
, &cm_node
->recv_list
);
404 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
407 if (type
== NES_TIMER_TYPE_SEND
) {
408 new_send
->seq_num
= ntohl(tcp_hdr(skb
)->seq
);
409 atomic_inc(&new_send
->skb
->users
);
410 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
411 cm_node
->send_entry
= new_send
;
412 add_ref_cm_node(cm_node
);
413 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
414 new_send
->timetosend
= jiffies
+ NES_RETRY_TIMEOUT
;
416 ret
= nes_nic_cm_xmit(new_send
->skb
, cm_node
->netdev
);
417 if (ret
!= NETDEV_TX_OK
) {
418 nes_debug(NES_DBG_CM
, "Error sending packet %p "
419 "(jiffies = %lu)\n", new_send
, jiffies
);
420 atomic_dec(&new_send
->skb
->users
);
421 new_send
->timetosend
= jiffies
;
425 cleanup_retrans_entry(cm_node
);
426 if (close_when_complete
)
427 rem_ref_cm_node(cm_core
, cm_node
);
433 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
435 if (!was_timer_set
) {
436 cm_core
->tcp_timer
.expires
= new_send
->timetosend
;
437 add_timer(&cm_core
->tcp_timer
);
447 static void nes_cm_timer_tick(unsigned long pass
)
449 unsigned long flags
, qplockflags
;
450 unsigned long nexttimeout
= jiffies
+ NES_LONG_TIME
;
451 struct iw_cm_id
*cm_id
;
452 struct nes_cm_node
*cm_node
;
453 struct nes_timer_entry
*send_entry
, *recv_entry
;
454 struct list_head
*list_core
, *list_core_temp
;
455 struct list_head
*list_node
, *list_node_temp
;
456 struct nes_cm_core
*cm_core
= g_cm_core
;
457 struct nes_qp
*nesqp
;
459 int ret
= NETDEV_TX_OK
;
460 enum nes_cm_node_state last_state
;
462 struct list_head timer_list
;
463 INIT_LIST_HEAD(&timer_list
);
464 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
466 list_for_each_safe(list_node
, list_core_temp
,
467 &cm_core
->connected_nodes
) {
468 cm_node
= container_of(list_node
, struct nes_cm_node
, list
);
469 if (!list_empty(&cm_node
->recv_list
) || (cm_node
->send_entry
)) {
470 add_ref_cm_node(cm_node
);
471 list_add(&cm_node
->timer_entry
, &timer_list
);
474 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
476 list_for_each_safe(list_node
, list_core_temp
, &timer_list
) {
477 cm_node
= container_of(list_node
, struct nes_cm_node
,
479 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
480 list_for_each_safe(list_core
, list_node_temp
,
481 &cm_node
->recv_list
) {
482 recv_entry
= container_of(list_core
,
483 struct nes_timer_entry
, list
);
486 if (time_after(recv_entry
->timetosend
, jiffies
)) {
487 if (nexttimeout
> recv_entry
->timetosend
||
489 nexttimeout
= recv_entry
->timetosend
;
494 list_del(&recv_entry
->list
);
495 cm_id
= cm_node
->cm_id
;
496 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
497 nesqp
= (struct nes_qp
*)recv_entry
->skb
;
498 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
500 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, "
501 "refcount = %d: HIT A "
502 "NES_TIMER_TYPE_CLOSE with something "
503 "to do!!!\n", nesqp
->hwqp
.qp_id
, cm_id
,
504 atomic_read(&nesqp
->refcount
));
505 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
506 nesqp
->last_aeq
= NES_AEQE_AEID_RESET_SENT
;
507 nesqp
->ibqp_state
= IB_QPS_ERR
;
508 spin_unlock_irqrestore(&nesqp
->lock
,
510 nes_cm_disconn(nesqp
);
512 spin_unlock_irqrestore(&nesqp
->lock
,
514 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, "
515 "refcount = %d: HIT A "
516 "NES_TIMER_TYPE_CLOSE with nothing "
517 "to do!!!\n", nesqp
->hwqp
.qp_id
, cm_id
,
518 atomic_read(&nesqp
->refcount
));
521 cm_id
->rem_ref(cm_id
);
524 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
526 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
528 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
530 send_entry
= cm_node
->send_entry
;
533 if (time_after(send_entry
->timetosend
, jiffies
)) {
534 if (cm_node
->state
!= NES_CM_STATE_TSA
) {
536 send_entry
->timetosend
) ||
539 send_entry
->timetosend
;
544 free_retrans_entry(cm_node
);
549 if ((cm_node
->state
== NES_CM_STATE_TSA
) ||
550 (cm_node
->state
== NES_CM_STATE_CLOSED
)) {
551 free_retrans_entry(cm_node
);
555 if (!send_entry
->retranscount
||
556 !send_entry
->retrycount
) {
557 cm_packets_dropped
++;
558 last_state
= cm_node
->state
;
559 cm_node
->state
= NES_CM_STATE_CLOSED
;
560 free_retrans_entry(cm_node
);
561 spin_unlock_irqrestore(
562 &cm_node
->retrans_list_lock
, flags
);
563 if (last_state
== NES_CM_STATE_SYN_RCVD
)
564 rem_ref_cm_node(cm_core
, cm_node
);
566 create_event(cm_node
,
567 NES_CM_EVENT_ABORTED
);
568 spin_lock_irqsave(&cm_node
->retrans_list_lock
,
572 atomic_inc(&send_entry
->skb
->users
);
573 cm_packets_retrans
++;
574 nes_debug(NES_DBG_CM
, "Retransmitting send_entry %p "
575 "for node %p, jiffies = %lu, time to send = "
576 "%lu, retranscount = %u, send_entry->seq_num = "
577 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
578 "0x%08X\n", send_entry
, cm_node
, jiffies
,
579 send_entry
->timetosend
,
580 send_entry
->retranscount
,
582 cm_node
->tcp_cntxt
.rem_ack_num
);
584 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
,
586 ret
= nes_nic_cm_xmit(send_entry
->skb
, cm_node
->netdev
);
587 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
588 if (ret
!= NETDEV_TX_OK
) {
589 nes_debug(NES_DBG_CM
, "rexmit failed for "
590 "node=%p\n", cm_node
);
591 cm_packets_bounced
++;
592 atomic_dec(&send_entry
->skb
->users
);
593 send_entry
->retrycount
--;
594 nexttimeout
= jiffies
+ NES_SHORT_TIME
;
600 nes_debug(NES_DBG_CM
, "Packet Sent: retrans count = "
601 "%u, retry count = %u.\n",
602 send_entry
->retranscount
,
603 send_entry
->retrycount
);
604 if (send_entry
->send_retrans
) {
605 send_entry
->retranscount
--;
606 send_entry
->timetosend
= jiffies
+
608 if (nexttimeout
> send_entry
->timetosend
||
610 nexttimeout
= send_entry
->timetosend
;
614 int close_when_complete
;
615 close_when_complete
=
616 send_entry
->close_when_complete
;
617 nes_debug(NES_DBG_CM
, "cm_node=%p state=%d\n",
618 cm_node
, cm_node
->state
);
619 free_retrans_entry(cm_node
);
620 if (close_when_complete
)
621 rem_ref_cm_node(cm_node
->cm_core
,
626 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
627 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
628 if (ret
!= NETDEV_TX_OK
) {
629 nes_debug(NES_DBG_CM
, "rexmit failed for cm_node=%p\n",
636 if (!timer_pending(&cm_core
->tcp_timer
)) {
637 cm_core
->tcp_timer
.expires
= nexttimeout
;
638 add_timer(&cm_core
->tcp_timer
);
647 static int send_syn(struct nes_cm_node
*cm_node
, u32 sendack
,
652 char optionsbuffer
[sizeof(struct option_mss
) +
653 sizeof(struct option_windowscale
) + sizeof(struct option_base
) +
654 TCP_OPTIONS_PADDING
];
657 /* Sending MSS option */
658 union all_known_options
*options
;
663 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
664 options
->as_mss
.optionnum
= OPTION_NUMBER_MSS
;
665 options
->as_mss
.length
= sizeof(struct option_mss
);
666 options
->as_mss
.mss
= htons(cm_node
->tcp_cntxt
.mss
);
667 optionssize
+= sizeof(struct option_mss
);
669 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
670 options
->as_windowscale
.optionnum
= OPTION_NUMBER_WINDOW_SCALE
;
671 options
->as_windowscale
.length
= sizeof(struct option_windowscale
);
672 options
->as_windowscale
.shiftcount
= cm_node
->tcp_cntxt
.rcv_wscale
;
673 optionssize
+= sizeof(struct option_windowscale
);
675 if (sendack
&& !(NES_DRV_OPT_SUPRESS_OPTION_BC
& nes_drv_opt
)) {
676 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
677 options
->as_base
.optionnum
= OPTION_NUMBER_WRITE0
;
678 options
->as_base
.length
= sizeof(struct option_base
);
679 optionssize
+= sizeof(struct option_base
);
680 /* we need the size to be a multiple of 4 */
681 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
684 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
689 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
690 options
->as_end
= OPTION_NUMBER_END
;
694 skb
= get_free_pkt(cm_node
);
696 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
703 form_cm_frame(skb
, cm_node
, optionsbuffer
, optionssize
, NULL
, 0, flags
);
704 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
713 static int send_reset(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
716 int flags
= SET_RST
| SET_ACK
;
719 skb
= get_free_pkt(cm_node
);
721 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
725 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, flags
);
726 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 1);
735 static int send_ack(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
740 skb
= get_free_pkt(cm_node
);
743 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
747 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
);
748 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 0);
757 static int send_fin(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
761 /* if we didn't get a frame get one */
763 skb
= get_free_pkt(cm_node
);
766 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
770 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
| SET_FIN
);
771 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
780 static struct sk_buff
*get_free_pkt(struct nes_cm_node
*cm_node
)
782 struct sk_buff
*skb
, *new_skb
;
784 /* check to see if we need to repopulate the free tx pkt queue */
785 if (skb_queue_len(&cm_node
->cm_core
->tx_free_list
) < NES_CM_FREE_PKT_LO_WATERMARK
) {
786 while (skb_queue_len(&cm_node
->cm_core
->tx_free_list
) <
787 cm_node
->cm_core
->free_tx_pkt_max
) {
788 /* replace the frame we took, we won't get it back */
789 new_skb
= dev_alloc_skb(cm_node
->cm_core
->mtu
);
791 /* add a replacement frame to the free tx list head */
792 skb_queue_head(&cm_node
->cm_core
->tx_free_list
, new_skb
);
796 skb
= skb_dequeue(&cm_node
->cm_core
->tx_free_list
);
803 * make_hashkey - generate hash key from node tuple
805 static inline int make_hashkey(u16 loc_port
, nes_addr_t loc_addr
, u16 rem_port
,
810 hashkey
= loc_addr
+ rem_addr
+ loc_port
+ rem_port
;
811 hashkey
= (hashkey
% NES_CM_HASHTABLE_SIZE
);
818 * find_node - find a cm node that matches the reference cm node
820 static struct nes_cm_node
*find_node(struct nes_cm_core
*cm_core
,
821 u16 rem_port
, nes_addr_t rem_addr
, u16 loc_port
, nes_addr_t loc_addr
)
825 struct list_head
*hte
;
826 struct nes_cm_node
*cm_node
;
828 /* make a hash index key for this packet */
829 hashkey
= make_hashkey(loc_port
, loc_addr
, rem_port
, rem_addr
);
831 /* get a handle on the hte */
832 hte
= &cm_core
->connected_nodes
;
834 nes_debug(NES_DBG_CM
, "Searching for an owner node: " NIPQUAD_FMT
":%x from core %p->%p\n",
835 HIPQUAD(loc_addr
), loc_port
, cm_core
, hte
);
837 /* walk list and find cm_node associated with this session ID */
838 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
839 list_for_each_entry(cm_node
, hte
, list
) {
840 /* compare quad, return node handle if a match */
841 nes_debug(NES_DBG_CM
, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
842 cm_node
->loc_addr
, cm_node
->loc_port
,
844 cm_node
->rem_addr
, cm_node
->rem_port
,
846 if ((cm_node
->loc_addr
== loc_addr
) && (cm_node
->loc_port
== loc_port
) &&
847 (cm_node
->rem_addr
== rem_addr
) && (cm_node
->rem_port
== rem_port
)) {
848 add_ref_cm_node(cm_node
);
849 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
853 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
861 * find_listener - find a cm node listening on this addr-port pair
863 static struct nes_cm_listener
*find_listener(struct nes_cm_core
*cm_core
,
864 nes_addr_t dst_addr
, u16 dst_port
, enum nes_cm_listener_state listener_state
)
867 struct nes_cm_listener
*listen_node
;
869 /* walk list and find cm_node associated with this session ID */
870 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
871 list_for_each_entry(listen_node
, &cm_core
->listen_list
.list
, list
) {
872 /* compare node pair, return node handle if a match */
873 if (((listen_node
->loc_addr
== dst_addr
) ||
874 listen_node
->loc_addr
== 0x00000000) &&
875 (listen_node
->loc_port
== dst_port
) &&
876 (listener_state
& listen_node
->listener_state
)) {
877 atomic_inc(&listen_node
->ref_count
);
878 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
882 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
884 nes_debug(NES_DBG_CM
, "Unable to find listener for " NIPQUAD_FMT
":%x\n",
885 HIPQUAD(dst_addr
), dst_port
);
893 * add_hte_node - add a cm node to the hash table
895 static int add_hte_node(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
899 struct list_head
*hte
;
901 if (!cm_node
|| !cm_core
)
904 nes_debug(NES_DBG_CM
, "Adding Node %p to Active Connection HT\n",
907 /* first, make an index into our hash table */
908 hashkey
= make_hashkey(cm_node
->loc_port
, cm_node
->loc_addr
,
909 cm_node
->rem_port
, cm_node
->rem_addr
);
910 cm_node
->hashkey
= hashkey
;
912 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
914 /* get a handle on the hash table element (list head for this slot) */
915 hte
= &cm_core
->connected_nodes
;
916 list_add_tail(&cm_node
->list
, hte
);
917 atomic_inc(&cm_core
->ht_node_cnt
);
919 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
926 * mini_cm_dec_refcnt_listen
928 static int mini_cm_dec_refcnt_listen(struct nes_cm_core
*cm_core
,
929 struct nes_cm_listener
*listener
, int free_hanging_nodes
)
933 struct list_head
*list_pos
= NULL
;
934 struct list_head
*list_temp
= NULL
;
935 struct nes_cm_node
*cm_node
= NULL
;
936 struct list_head reset_list
;
938 nes_debug(NES_DBG_CM
, "attempting listener= %p free_nodes= %d, "
939 "refcnt=%d\n", listener
, free_hanging_nodes
,
940 atomic_read(&listener
->ref_count
));
941 /* free non-accelerated child nodes for this listener */
942 INIT_LIST_HEAD(&reset_list
);
943 if (free_hanging_nodes
) {
944 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
945 list_for_each_safe(list_pos
, list_temp
,
946 &g_cm_core
->connected_nodes
) {
947 cm_node
= container_of(list_pos
, struct nes_cm_node
,
949 if ((cm_node
->listener
== listener
) &&
950 (!cm_node
->accelerated
)) {
951 add_ref_cm_node(cm_node
);
952 list_add(&cm_node
->reset_entry
, &reset_list
);
955 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
958 list_for_each_safe(list_pos
, list_temp
, &reset_list
) {
959 cm_node
= container_of(list_pos
, struct nes_cm_node
,
961 cleanup_retrans_entry(cm_node
);
962 send_reset(cm_node
, NULL
);
963 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
966 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
967 if (!atomic_dec_return(&listener
->ref_count
)) {
968 list_del(&listener
->list
);
970 /* decrement our listen node count */
971 atomic_dec(&cm_core
->listen_node_cnt
);
973 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
975 if (listener
->nesvnic
) {
976 nes_manage_apbvt(listener
->nesvnic
, listener
->loc_port
,
977 PCI_FUNC(listener
->nesvnic
->nesdev
->pcidev
->devfn
), NES_MANAGE_APBVT_DEL
);
980 nes_debug(NES_DBG_CM
, "destroying listener (%p)\n", listener
);
985 cm_listens_destroyed
++;
987 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
990 if (atomic_read(&listener
->pend_accepts_cnt
) > 0)
991 nes_debug(NES_DBG_CM
, "destroying listener (%p)"
992 " with non-zero pending accepts=%u\n",
993 listener
, atomic_read(&listener
->pend_accepts_cnt
));
1001 * mini_cm_del_listen
1003 static int mini_cm_del_listen(struct nes_cm_core
*cm_core
,
1004 struct nes_cm_listener
*listener
)
1006 listener
->listener_state
= NES_CM_LISTENER_PASSIVE_STATE
;
1007 listener
->cm_id
= NULL
; /* going to be destroyed pretty soon */
1008 return mini_cm_dec_refcnt_listen(cm_core
, listener
, 1);
1013 * mini_cm_accelerated
1015 static inline int mini_cm_accelerated(struct nes_cm_core
*cm_core
,
1016 struct nes_cm_node
*cm_node
)
1019 cm_node
->accelerated
= 1;
1021 if (cm_node
->accept_pend
) {
1022 BUG_ON(!cm_node
->listener
);
1023 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1024 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1027 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
1028 if (!was_timer_set
) {
1029 cm_core
->tcp_timer
.expires
= jiffies
+ NES_SHORT_TIME
;
1030 add_timer(&cm_core
->tcp_timer
);
1038 * nes_addr_resolve_neigh
1040 static int nes_addr_resolve_neigh(struct nes_vnic
*nesvnic
, u32 dst_ip
)
1044 struct neighbour
*neigh
;
1046 DECLARE_MAC_BUF(mac
);
1048 memset(&fl
, 0, sizeof fl
);
1049 fl
.nl_u
.ip4_u
.daddr
= htonl(dst_ip
);
1050 if (ip_route_output_key(&init_net
, &rt
, &fl
)) {
1051 printk("%s: ip_route_output_key failed for 0x%08X\n",
1056 neigh
= neigh_lookup(&arp_tbl
, &rt
->rt_gateway
, nesvnic
->netdev
);
1058 if (neigh
->nud_state
& NUD_VALID
) {
1059 nes_debug(NES_DBG_CM
, "Neighbor MAC address for 0x%08X"
1060 " is %s, Gateway is 0x%08X \n", dst_ip
,
1061 print_mac(mac
, neigh
->ha
), ntohl(rt
->rt_gateway
));
1062 nes_manage_arp_cache(nesvnic
->netdev
, neigh
->ha
,
1063 dst_ip
, NES_ARP_ADD
);
1064 rc
= nes_arp_table(nesvnic
->nesdev
, dst_ip
, NULL
,
1067 neigh_release(neigh
);
1070 if ((neigh
== NULL
) || (!(neigh
->nud_state
& NUD_VALID
)))
1071 neigh_event_send(rt
->u
.dst
.neighbour
, NULL
);
1079 * make_cm_node - create a new instance of a cm node
1081 static struct nes_cm_node
*make_cm_node(struct nes_cm_core
*cm_core
,
1082 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
,
1083 struct nes_cm_listener
*listener
)
1085 struct nes_cm_node
*cm_node
;
1088 struct nes_device
*nesdev
;
1089 struct nes_adapter
*nesadapter
;
1090 DECLARE_MAC_BUF(mac
);
1092 /* create an hte and cm_node for this instance */
1093 cm_node
= kzalloc(sizeof(*cm_node
), GFP_ATOMIC
);
1097 /* set our node specific transport info */
1098 cm_node
->loc_addr
= cm_info
->loc_addr
;
1099 cm_node
->rem_addr
= cm_info
->rem_addr
;
1100 cm_node
->loc_port
= cm_info
->loc_port
;
1101 cm_node
->rem_port
= cm_info
->rem_port
;
1102 cm_node
->send_write0
= send_first
;
1103 nes_debug(NES_DBG_CM
, "Make node addresses : loc = " NIPQUAD_FMT
1104 ":%x, rem = " NIPQUAD_FMT
":%x\n",
1105 HIPQUAD(cm_node
->loc_addr
), cm_node
->loc_port
,
1106 HIPQUAD(cm_node
->rem_addr
), cm_node
->rem_port
);
1107 cm_node
->listener
= listener
;
1108 cm_node
->netdev
= nesvnic
->netdev
;
1109 cm_node
->cm_id
= cm_info
->cm_id
;
1110 memcpy(cm_node
->loc_mac
, nesvnic
->netdev
->dev_addr
, ETH_ALEN
);
1112 nes_debug(NES_DBG_CM
, "listener=%p, cm_id=%p\n", cm_node
->listener
,
1115 spin_lock_init(&cm_node
->retrans_list_lock
);
1116 INIT_LIST_HEAD(&cm_node
->recv_list
);
1117 spin_lock_init(&cm_node
->recv_list_lock
);
1119 cm_node
->loopbackpartner
= NULL
;
1120 atomic_set(&cm_node
->ref_count
, 1);
1121 /* associate our parent CM core */
1122 cm_node
->cm_core
= cm_core
;
1123 cm_node
->tcp_cntxt
.loc_id
= NES_CM_DEF_LOCAL_ID
;
1124 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
1125 cm_node
->tcp_cntxt
.rcv_wnd
= NES_CM_DEFAULT_RCV_WND_SCALED
>>
1126 NES_CM_DEFAULT_RCV_WND_SCALE
;
1127 ts
= current_kernel_time();
1128 cm_node
->tcp_cntxt
.loc_seq_num
= htonl(ts
.tv_nsec
);
1129 cm_node
->tcp_cntxt
.mss
= nesvnic
->max_frame_size
- sizeof(struct iphdr
) -
1130 sizeof(struct tcphdr
) - ETH_HLEN
- VLAN_HLEN
;
1131 cm_node
->tcp_cntxt
.rcv_nxt
= 0;
1132 /* get a unique session ID , add thread_id to an upcounter to handle race */
1133 atomic_inc(&cm_core
->node_cnt
);
1134 cm_node
->conn_type
= cm_info
->conn_type
;
1135 cm_node
->apbvt_set
= 0;
1136 cm_node
->accept_pend
= 0;
1138 cm_node
->nesvnic
= nesvnic
;
1139 /* get some device handles, for arp lookup */
1140 nesdev
= nesvnic
->nesdev
;
1141 nesadapter
= nesdev
->nesadapter
;
1143 cm_node
->loopbackpartner
= NULL
;
1144 /* get the mac addr for the remote node */
1145 if (ipv4_is_loopback(htonl(cm_node
->rem_addr
)))
1146 arpindex
= nes_arp_table(nesdev
, ntohl(nesvnic
->local_ipaddr
), NULL
, NES_ARP_RESOLVE
);
1148 arpindex
= nes_arp_table(nesdev
, cm_node
->rem_addr
, NULL
, NES_ARP_RESOLVE
);
1150 arpindex
= nes_addr_resolve_neigh(nesvnic
, cm_info
->rem_addr
);
1157 /* copy the mac addr to node context */
1158 memcpy(cm_node
->rem_mac
, nesadapter
->arp_table
[arpindex
].mac_addr
, ETH_ALEN
);
1159 nes_debug(NES_DBG_CM
, "Remote mac addr from arp table: %s\n",
1160 print_mac(mac
, cm_node
->rem_mac
));
1162 add_hte_node(cm_core
, cm_node
);
1163 atomic_inc(&cm_nodes_created
);
1170 * add_ref_cm_node - destroy an instance of a cm node
1172 static int add_ref_cm_node(struct nes_cm_node
*cm_node
)
1174 atomic_inc(&cm_node
->ref_count
);
1180 * rem_ref_cm_node - destroy an instance of a cm node
1182 static int rem_ref_cm_node(struct nes_cm_core
*cm_core
,
1183 struct nes_cm_node
*cm_node
)
1185 unsigned long flags
, qplockflags
;
1186 struct nes_timer_entry
*recv_entry
;
1187 struct iw_cm_id
*cm_id
;
1188 struct list_head
*list_core
, *list_node_temp
;
1189 struct nes_qp
*nesqp
;
1194 spin_lock_irqsave(&cm_node
->cm_core
->ht_lock
, flags
);
1195 if (atomic_dec_return(&cm_node
->ref_count
)) {
1196 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1199 list_del(&cm_node
->list
);
1200 atomic_dec(&cm_core
->ht_node_cnt
);
1201 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1203 /* if the node is destroyed before connection was accelerated */
1204 if (!cm_node
->accelerated
&& cm_node
->accept_pend
) {
1205 BUG_ON(!cm_node
->listener
);
1206 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1207 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1209 BUG_ON(cm_node
->send_entry
);
1210 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
1211 list_for_each_safe(list_core
, list_node_temp
, &cm_node
->recv_list
) {
1212 recv_entry
= container_of(list_core
, struct nes_timer_entry
,
1214 list_del(&recv_entry
->list
);
1215 cm_id
= cm_node
->cm_id
;
1216 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
1217 nesqp
= (struct nes_qp
*)recv_entry
->skb
;
1218 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
1220 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p: HIT A "
1221 "NES_TIMER_TYPE_CLOSE with something to do!\n",
1222 nesqp
->hwqp
.qp_id
, cm_id
);
1223 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
1224 nesqp
->last_aeq
= NES_AEQE_AEID_RESET_SENT
;
1225 nesqp
->ibqp_state
= IB_QPS_ERR
;
1226 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
1227 nes_cm_disconn(nesqp
);
1229 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
1230 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p: HIT A "
1231 "NES_TIMER_TYPE_CLOSE with nothing to do!\n",
1232 nesqp
->hwqp
.qp_id
, cm_id
);
1234 cm_id
->rem_ref(cm_id
);
1237 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
1239 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
1241 if (cm_node
->listener
) {
1242 mini_cm_dec_refcnt_listen(cm_core
, cm_node
->listener
, 0);
1244 if (cm_node
->apbvt_set
&& cm_node
->nesvnic
) {
1245 nes_manage_apbvt(cm_node
->nesvnic
, cm_node
->loc_port
,
1247 cm_node
->nesvnic
->nesdev
->pcidev
->devfn
),
1248 NES_MANAGE_APBVT_DEL
);
1252 atomic_dec(&cm_core
->node_cnt
);
1253 atomic_inc(&cm_nodes_destroyed
);
1254 nesqp
= cm_node
->nesqp
;
1256 nesqp
->cm_node
= NULL
;
1257 nes_rem_ref(&nesqp
->ibqp
);
1258 cm_node
->nesqp
= NULL
;
1269 static int process_options(struct nes_cm_node
*cm_node
, u8
*optionsloc
,
1270 u32 optionsize
, u32 syn_packet
)
1274 union all_known_options
*all_options
;
1275 char got_mss_option
= 0;
1277 while (offset
< optionsize
) {
1278 all_options
= (union all_known_options
*)(optionsloc
+ offset
);
1279 switch (all_options
->as_base
.optionnum
) {
1280 case OPTION_NUMBER_END
:
1281 offset
= optionsize
;
1283 case OPTION_NUMBER_NONE
:
1286 case OPTION_NUMBER_MSS
:
1287 nes_debug(NES_DBG_CM
, "%s: MSS Length: %d Offset: %d "
1288 "Size: %d\n", __func__
,
1289 all_options
->as_mss
.length
, offset
, optionsize
);
1291 if (all_options
->as_mss
.length
!= 4) {
1294 tmp
= ntohs(all_options
->as_mss
.mss
);
1295 if (tmp
> 0 && tmp
<
1296 cm_node
->tcp_cntxt
.mss
)
1297 cm_node
->tcp_cntxt
.mss
= tmp
;
1300 case OPTION_NUMBER_WINDOW_SCALE
:
1301 cm_node
->tcp_cntxt
.snd_wscale
=
1302 all_options
->as_windowscale
.shiftcount
;
1304 case OPTION_NUMBER_WRITE0
:
1305 cm_node
->send_write0
= 1;
1308 nes_debug(NES_DBG_CM
, "TCP Option not understood: %x\n",
1309 all_options
->as_base
.optionnum
);
1312 offset
+= all_options
->as_base
.length
;
1314 if ((!got_mss_option
) && (syn_packet
))
1315 cm_node
->tcp_cntxt
.mss
= NES_CM_DEFAULT_MSS
;
1319 static void drop_packet(struct sk_buff
*skb
)
1321 atomic_inc(&cm_accel_dropped_pkts
);
1322 dev_kfree_skb_any(skb
);
1325 static void handle_fin_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1326 struct tcphdr
*tcph
)
1328 atomic_inc(&cm_resets_recvd
);
1329 nes_debug(NES_DBG_CM
, "Received FIN, cm_node = %p, state = %u. "
1330 "refcnt=%d\n", cm_node
, cm_node
->state
,
1331 atomic_read(&cm_node
->ref_count
));
1332 cm_node
->tcp_cntxt
.rcv_nxt
++;
1333 cleanup_retrans_entry(cm_node
);
1334 switch (cm_node
->state
) {
1335 case NES_CM_STATE_SYN_RCVD
:
1336 case NES_CM_STATE_SYN_SENT
:
1337 case NES_CM_STATE_ESTABLISHED
:
1338 case NES_CM_STATE_MPAREQ_SENT
:
1339 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
1340 send_fin(cm_node
, skb
);
1342 case NES_CM_STATE_FIN_WAIT1
:
1343 cm_node
->state
= NES_CM_STATE_CLOSING
;
1344 send_ack(cm_node
, skb
);
1346 case NES_CM_STATE_FIN_WAIT2
:
1347 cm_node
->state
= NES_CM_STATE_TIME_WAIT
;
1348 send_ack(cm_node
, skb
);
1349 cm_node
->state
= NES_CM_STATE_CLOSED
;
1351 case NES_CM_STATE_TSA
:
1353 nes_debug(NES_DBG_CM
, "Error Rcvd FIN for node-%p state = %d\n",
1354 cm_node
, cm_node
->state
);
1361 static void handle_rst_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1362 struct tcphdr
*tcph
)
1365 int reset
= 0; /* whether to send reset in case of err.. */
1367 atomic_inc(&cm_resets_recvd
);
1368 nes_debug(NES_DBG_CM
, "Received Reset, cm_node = %p, state = %u."
1369 " refcnt=%d\n", cm_node
, cm_node
->state
,
1370 atomic_read(&cm_node
->ref_count
));
1371 cleanup_retrans_entry(cm_node
);
1372 switch (cm_node
->state
) {
1373 case NES_CM_STATE_SYN_SENT
:
1374 case NES_CM_STATE_MPAREQ_SENT
:
1375 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1376 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1377 cm_node
->listener
, cm_node
->state
);
1378 active_open_err(cm_node
, skb
, reset
);
1380 case NES_CM_STATE_MPAREQ_RCVD
:
1381 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
1382 if (passive_state
== NES_SEND_RESET_EVENT
)
1383 create_event(cm_node
, NES_CM_EVENT_RESET
);
1384 cleanup_retrans_entry(cm_node
);
1385 cm_node
->state
= NES_CM_STATE_CLOSED
;
1386 dev_kfree_skb_any(skb
);
1388 case NES_CM_STATE_ESTABLISHED
:
1389 case NES_CM_STATE_SYN_RCVD
:
1390 case NES_CM_STATE_LISTENING
:
1391 nes_debug(NES_DBG_CM
, "Bad state %s[%u]\n", __func__
, __LINE__
);
1392 passive_open_err(cm_node
, skb
, reset
);
1394 case NES_CM_STATE_TSA
:
1395 active_open_err(cm_node
, skb
, reset
);
1397 case NES_CM_STATE_CLOSED
:
1398 cleanup_retrans_entry(cm_node
);
1407 static void handle_rcv_mpa(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1408 enum nes_cm_event_type type
)
1412 int datasize
= skb
->len
;
1413 u8
*dataloc
= skb
->data
;
1414 ret
= parse_mpa(cm_node
, dataloc
, datasize
);
1416 nes_debug(NES_DBG_CM
, "didn't like MPA Request\n");
1417 if (type
== NES_CM_EVENT_CONNECTED
) {
1418 nes_debug(NES_DBG_CM
, "%s[%u] create abort for "
1419 "cm_node=%p listener=%p state=%d\n", __func__
,
1420 __LINE__
, cm_node
, cm_node
->listener
,
1422 active_open_err(cm_node
, skb
, 1);
1424 passive_open_err(cm_node
, skb
, 1);
1427 cleanup_retrans_entry(cm_node
);
1428 dev_kfree_skb_any(skb
);
1429 if (type
== NES_CM_EVENT_CONNECTED
)
1430 cm_node
->state
= NES_CM_STATE_TSA
;
1432 atomic_set(&cm_node
->passive_state
,
1433 NES_PASSIVE_STATE_INDICATED
);
1434 create_event(cm_node
, type
);
1440 static void indicate_pkt_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
1442 switch (cm_node
->state
) {
1443 case NES_CM_STATE_SYN_SENT
:
1444 case NES_CM_STATE_MPAREQ_SENT
:
1445 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1446 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1447 cm_node
->listener
, cm_node
->state
);
1448 active_open_err(cm_node
, skb
, 1);
1450 case NES_CM_STATE_ESTABLISHED
:
1451 case NES_CM_STATE_SYN_RCVD
:
1452 passive_open_err(cm_node
, skb
, 1);
1454 case NES_CM_STATE_TSA
:
1460 static int check_syn(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1461 struct sk_buff
*skb
)
1465 err
= ((ntohl(tcph
->ack_seq
) == cm_node
->tcp_cntxt
.loc_seq_num
))? 0 : 1;
1467 active_open_err(cm_node
, skb
, 1);
1472 static int check_seq(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1473 struct sk_buff
*skb
)
1478 u32 loc_seq_num
= cm_node
->tcp_cntxt
.loc_seq_num
;
1479 u32 rcv_nxt
= cm_node
->tcp_cntxt
.rcv_nxt
;
1481 seq
= ntohl(tcph
->seq
);
1482 ack_seq
= ntohl(tcph
->ack_seq
);
1483 rcv_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
1484 if (ack_seq
!= loc_seq_num
)
1486 else if ((seq
+ rcv_wnd
) < rcv_nxt
)
1489 nes_debug(NES_DBG_CM
, "%s[%u] create abort for cm_node=%p "
1490 "listener=%p state=%d\n", __func__
, __LINE__
, cm_node
,
1491 cm_node
->listener
, cm_node
->state
);
1492 indicate_pkt_err(cm_node
, skb
);
1493 nes_debug(NES_DBG_CM
, "seq ERROR cm_node =%p seq=0x%08X "
1494 "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node
, seq
, rcv_nxt
,
1501 * handle_syn_pkt() is for Passive node. The syn packet is received when a node
1502 * is created with a listener or it may comein as rexmitted packet which in
1503 * that case will be just dropped.
1506 static void handle_syn_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1507 struct tcphdr
*tcph
)
1513 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1515 inc_sequence
= ntohl(tcph
->seq
);
1517 switch (cm_node
->state
) {
1518 case NES_CM_STATE_SYN_SENT
:
1519 case NES_CM_STATE_MPAREQ_SENT
:
1520 /* Rcvd syn on active open connection*/
1521 active_open_err(cm_node
, skb
, 1);
1523 case NES_CM_STATE_LISTENING
:
1525 cm_node
->accept_pend
= 1;
1526 atomic_inc(&cm_node
->listener
->pend_accepts_cnt
);
1527 if (atomic_read(&cm_node
->listener
->pend_accepts_cnt
) >
1528 cm_node
->listener
->backlog
) {
1529 nes_debug(NES_DBG_CM
, "drop syn due to backlog "
1532 passive_open_err(cm_node
, skb
, 0);
1535 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
,
1538 passive_open_err(cm_node
, skb
, 0);
1542 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
1543 BUG_ON(cm_node
->send_entry
);
1544 cm_node
->state
= NES_CM_STATE_SYN_RCVD
;
1545 send_syn(cm_node
, 1, skb
);
1547 case NES_CM_STATE_CLOSED
:
1548 cleanup_retrans_entry(cm_node
);
1549 send_reset(cm_node
, skb
);
1551 case NES_CM_STATE_TSA
:
1552 case NES_CM_STATE_ESTABLISHED
:
1553 case NES_CM_STATE_FIN_WAIT1
:
1554 case NES_CM_STATE_FIN_WAIT2
:
1555 case NES_CM_STATE_MPAREQ_RCVD
:
1556 case NES_CM_STATE_LAST_ACK
:
1557 case NES_CM_STATE_CLOSING
:
1558 case NES_CM_STATE_UNKNOWN
:
1565 static void handle_synack_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1566 struct tcphdr
*tcph
)
1573 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1575 inc_sequence
= ntohl(tcph
->seq
);
1576 switch (cm_node
->state
) {
1577 case NES_CM_STATE_SYN_SENT
:
1579 if (check_syn(cm_node
, tcph
, skb
))
1581 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
1583 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
, 0);
1585 nes_debug(NES_DBG_CM
, "cm_node=%p tcp_options failed\n",
1589 cleanup_retrans_entry(cm_node
);
1590 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ 1;
1591 send_mpa_request(cm_node
, skb
);
1592 cm_node
->state
= NES_CM_STATE_MPAREQ_SENT
;
1594 case NES_CM_STATE_MPAREQ_RCVD
:
1595 /* passive open, so should not be here */
1596 passive_open_err(cm_node
, skb
, 1);
1598 case NES_CM_STATE_LISTENING
:
1599 case NES_CM_STATE_CLOSED
:
1600 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
1601 cleanup_retrans_entry(cm_node
);
1602 send_reset(cm_node
, skb
);
1604 case NES_CM_STATE_ESTABLISHED
:
1605 case NES_CM_STATE_FIN_WAIT1
:
1606 case NES_CM_STATE_FIN_WAIT2
:
1607 case NES_CM_STATE_LAST_ACK
:
1608 case NES_CM_STATE_TSA
:
1609 case NES_CM_STATE_CLOSING
:
1610 case NES_CM_STATE_UNKNOWN
:
1611 case NES_CM_STATE_MPAREQ_SENT
:
1618 static void handle_ack_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1619 struct tcphdr
*tcph
)
1627 u32 temp_seq
= cm_node
->tcp_cntxt
.loc_seq_num
;
1629 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1630 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
1632 if (check_seq(cm_node
, tcph
, skb
))
1635 skb_pull(skb
, tcph
->doff
<< 2);
1636 inc_sequence
= ntohl(tcph
->seq
);
1637 rem_seq
= ntohl(tcph
->seq
);
1638 rem_seq_ack
= ntohl(tcph
->ack_seq
);
1639 datasize
= skb
->len
;
1641 switch (cm_node
->state
) {
1642 case NES_CM_STATE_SYN_RCVD
:
1644 ret
= handle_tcp_options(cm_node
, tcph
, skb
, optionsize
, 1);
1647 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
1648 cm_node
->tcp_cntxt
.loc_seq_num
= temp_seq
;
1649 if (cm_node
->tcp_cntxt
.rem_ack_num
!=
1650 cm_node
->tcp_cntxt
.loc_seq_num
) {
1651 nes_debug(NES_DBG_CM
, "rem_ack_num != loc_seq_num\n");
1652 cleanup_retrans_entry(cm_node
);
1653 send_reset(cm_node
, skb
);
1656 cm_node
->state
= NES_CM_STATE_ESTABLISHED
;
1658 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
1659 cm_node
->state
= NES_CM_STATE_MPAREQ_RCVD
;
1660 handle_rcv_mpa(cm_node
, skb
, NES_CM_EVENT_MPA_REQ
);
1661 } else { /* rcvd ACK only */
1662 dev_kfree_skb_any(skb
);
1663 cleanup_retrans_entry(cm_node
);
1666 case NES_CM_STATE_ESTABLISHED
:
1668 /* We expect mpa frame to be received only */
1670 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
1671 cm_node
->state
= NES_CM_STATE_MPAREQ_RCVD
;
1672 handle_rcv_mpa(cm_node
, skb
,
1673 NES_CM_EVENT_MPA_REQ
);
1677 case NES_CM_STATE_MPAREQ_SENT
:
1678 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
1680 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
1681 handle_rcv_mpa(cm_node
, skb
, NES_CM_EVENT_CONNECTED
);
1682 } else { /* Could be just an ack pkt.. */
1683 cleanup_retrans_entry(cm_node
);
1684 dev_kfree_skb_any(skb
);
1687 case NES_CM_STATE_LISTENING
:
1688 case NES_CM_STATE_CLOSED
:
1689 cleanup_retrans_entry(cm_node
);
1690 send_reset(cm_node
, skb
);
1692 case NES_CM_STATE_FIN_WAIT1
:
1693 case NES_CM_STATE_SYN_SENT
:
1694 case NES_CM_STATE_FIN_WAIT2
:
1695 case NES_CM_STATE_TSA
:
1696 case NES_CM_STATE_MPAREQ_RCVD
:
1697 case NES_CM_STATE_LAST_ACK
:
1698 case NES_CM_STATE_CLOSING
:
1699 case NES_CM_STATE_UNKNOWN
:
1708 static int handle_tcp_options(struct nes_cm_node
*cm_node
, struct tcphdr
*tcph
,
1709 struct sk_buff
*skb
, int optionsize
, int passive
)
1711 u8
*optionsloc
= (u8
*)&tcph
[1];
1713 if (process_options(cm_node
, optionsloc
, optionsize
,
1715 nes_debug(NES_DBG_CM
, "%s: Node %p, Sending RESET\n",
1718 passive_open_err(cm_node
, skb
, 1);
1720 active_open_err(cm_node
, skb
, 1);
1725 cm_node
->tcp_cntxt
.snd_wnd
= ntohs(tcph
->window
) <<
1726 cm_node
->tcp_cntxt
.snd_wscale
;
1728 if (cm_node
->tcp_cntxt
.snd_wnd
> cm_node
->tcp_cntxt
.max_snd_wnd
)
1729 cm_node
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.snd_wnd
;
1734 * active_open_err() will send reset() if flag set..
1735 * It will also send ABORT event.
1738 static void active_open_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1741 cleanup_retrans_entry(cm_node
);
1743 nes_debug(NES_DBG_CM
, "ERROR active err called for cm_node=%p, "
1744 "state=%d\n", cm_node
, cm_node
->state
);
1745 add_ref_cm_node(cm_node
);
1746 send_reset(cm_node
, skb
);
1748 dev_kfree_skb_any(skb
);
1750 cm_node
->state
= NES_CM_STATE_CLOSED
;
1751 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
1755 * passive_open_err() will either do a reset() or will free up the skb and
1756 * remove the cm_node.
1759 static void passive_open_err(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1762 cleanup_retrans_entry(cm_node
);
1763 cm_node
->state
= NES_CM_STATE_CLOSED
;
1765 nes_debug(NES_DBG_CM
, "passive_open_err sending RST for "
1766 "cm_node=%p state =%d\n", cm_node
, cm_node
->state
);
1767 send_reset(cm_node
, skb
);
1769 dev_kfree_skb_any(skb
);
1770 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1775 * free_retrans_entry() routines assumes that the retrans_list_lock has
1776 * been acquired before calling.
1778 static void free_retrans_entry(struct nes_cm_node
*cm_node
)
1780 struct nes_timer_entry
*send_entry
;
1781 send_entry
= cm_node
->send_entry
;
1783 cm_node
->send_entry
= NULL
;
1784 dev_kfree_skb_any(send_entry
->skb
);
1786 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
1790 static void cleanup_retrans_entry(struct nes_cm_node
*cm_node
)
1792 unsigned long flags
;
1794 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1795 free_retrans_entry(cm_node
);
1796 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1801 * Returns skb if to be freed, else it will return NULL if already used..
1803 static void process_packet(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1804 struct nes_cm_core
*cm_core
)
1806 enum nes_tcpip_pkt_type pkt_type
= NES_PKT_TYPE_UNKNOWN
;
1807 struct tcphdr
*tcph
= tcp_hdr(skb
);
1808 skb_pull(skb
, ip_hdr(skb
)->ihl
<< 2);
1810 nes_debug(NES_DBG_CM
, "process_packet: cm_node=%p state =%d syn=%d "
1811 "ack=%d rst=%d fin=%d\n", cm_node
, cm_node
->state
, tcph
->syn
,
1812 tcph
->ack
, tcph
->rst
, tcph
->fin
);
1815 pkt_type
= NES_PKT_TYPE_RST
;
1816 else if (tcph
->syn
) {
1817 pkt_type
= NES_PKT_TYPE_SYN
;
1819 pkt_type
= NES_PKT_TYPE_SYNACK
;
1820 } else if (tcph
->fin
)
1821 pkt_type
= NES_PKT_TYPE_FIN
;
1823 pkt_type
= NES_PKT_TYPE_ACK
;
1826 case NES_PKT_TYPE_SYN
:
1827 handle_syn_pkt(cm_node
, skb
, tcph
);
1829 case NES_PKT_TYPE_SYNACK
:
1830 handle_synack_pkt(cm_node
, skb
, tcph
);
1832 case NES_PKT_TYPE_ACK
:
1833 handle_ack_pkt(cm_node
, skb
, tcph
);
1835 case NES_PKT_TYPE_RST
:
1836 handle_rst_pkt(cm_node
, skb
, tcph
);
1838 case NES_PKT_TYPE_FIN
:
1839 handle_fin_pkt(cm_node
, skb
, tcph
);
1848 * mini_cm_listen - create a listen node with params
1850 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*cm_core
,
1851 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
)
1853 struct nes_cm_listener
*listener
;
1854 unsigned long flags
;
1856 nes_debug(NES_DBG_CM
, "Search for 0x%08x : 0x%04x\n",
1857 cm_info
->loc_addr
, cm_info
->loc_port
);
1859 /* cannot have multiple matching listeners */
1860 listener
= find_listener(cm_core
, htonl(cm_info
->loc_addr
),
1861 htons(cm_info
->loc_port
), NES_CM_LISTENER_EITHER_STATE
);
1862 if (listener
&& listener
->listener_state
== NES_CM_LISTENER_ACTIVE_STATE
) {
1863 /* find automatically incs ref count ??? */
1864 atomic_dec(&listener
->ref_count
);
1865 nes_debug(NES_DBG_CM
, "Not creating listener since it already exists\n");
1870 /* create a CM listen node (1/2 node to compare incoming traffic to) */
1871 listener
= kzalloc(sizeof(*listener
), GFP_ATOMIC
);
1873 nes_debug(NES_DBG_CM
, "Not creating listener memory allocation failed\n");
1877 listener
->loc_addr
= htonl(cm_info
->loc_addr
);
1878 listener
->loc_port
= htons(cm_info
->loc_port
);
1879 listener
->reused_node
= 0;
1881 atomic_set(&listener
->ref_count
, 1);
1884 /* find already inc'ed the ref count */
1886 listener
->reused_node
= 1;
1889 listener
->cm_id
= cm_info
->cm_id
;
1890 atomic_set(&listener
->pend_accepts_cnt
, 0);
1891 listener
->cm_core
= cm_core
;
1892 listener
->nesvnic
= nesvnic
;
1893 atomic_inc(&cm_core
->node_cnt
);
1895 listener
->conn_type
= cm_info
->conn_type
;
1896 listener
->backlog
= cm_info
->backlog
;
1897 listener
->listener_state
= NES_CM_LISTENER_ACTIVE_STATE
;
1899 if (!listener
->reused_node
) {
1900 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1901 list_add(&listener
->list
, &cm_core
->listen_list
.list
);
1902 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1903 atomic_inc(&cm_core
->listen_node_cnt
);
1906 nes_debug(NES_DBG_CM
, "Api - listen(): addr=0x%08X, port=0x%04x,"
1907 " listener = %p, backlog = %d, cm_id = %p.\n",
1908 cm_info
->loc_addr
, cm_info
->loc_port
,
1909 listener
, listener
->backlog
, listener
->cm_id
);
1916 * mini_cm_connect - make a connection node with params
1918 static struct nes_cm_node
*mini_cm_connect(struct nes_cm_core
*cm_core
,
1919 struct nes_vnic
*nesvnic
, u16 private_data_len
,
1920 void *private_data
, struct nes_cm_info
*cm_info
)
1923 struct nes_cm_node
*cm_node
;
1924 struct nes_cm_listener
*loopbackremotelistener
;
1925 struct nes_cm_node
*loopbackremotenode
;
1926 struct nes_cm_info loopback_cm_info
;
1927 u16 mpa_frame_size
= sizeof(struct ietf_mpa_frame
) + private_data_len
;
1928 struct ietf_mpa_frame
*mpa_frame
= NULL
;
1930 /* create a CM connection node */
1931 cm_node
= make_cm_node(cm_core
, nesvnic
, cm_info
, NULL
);
1934 mpa_frame
= &cm_node
->mpa_frame
;
1935 strcpy(mpa_frame
->key
, IEFT_MPA_KEY_REQ
);
1936 mpa_frame
->flags
= IETF_MPA_FLAGS_CRC
;
1937 mpa_frame
->rev
= IETF_MPA_VERSION
;
1938 mpa_frame
->priv_data_len
= htons(private_data_len
);
1940 /* set our node side to client (active) side */
1941 cm_node
->tcp_cntxt
.client
= 1;
1942 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
1944 if (cm_info
->loc_addr
== cm_info
->rem_addr
) {
1945 loopbackremotelistener
= find_listener(cm_core
,
1946 ntohl(nesvnic
->local_ipaddr
), cm_node
->rem_port
,
1947 NES_CM_LISTENER_ACTIVE_STATE
);
1948 if (loopbackremotelistener
== NULL
) {
1949 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
1951 atomic_inc(&cm_loopbacks
);
1952 loopback_cm_info
= *cm_info
;
1953 loopback_cm_info
.loc_port
= cm_info
->rem_port
;
1954 loopback_cm_info
.rem_port
= cm_info
->loc_port
;
1955 loopback_cm_info
.cm_id
= loopbackremotelistener
->cm_id
;
1956 loopbackremotenode
= make_cm_node(cm_core
, nesvnic
,
1957 &loopback_cm_info
, loopbackremotelistener
);
1958 loopbackremotenode
->loopbackpartner
= cm_node
;
1959 loopbackremotenode
->tcp_cntxt
.rcv_wscale
=
1960 NES_CM_DEFAULT_RCV_WND_SCALE
;
1961 cm_node
->loopbackpartner
= loopbackremotenode
;
1962 memcpy(loopbackremotenode
->mpa_frame_buf
, private_data
,
1964 loopbackremotenode
->mpa_frame_size
= private_data_len
;
1966 /* we are done handling this state. */
1967 /* set node to a TSA state */
1968 cm_node
->state
= NES_CM_STATE_TSA
;
1969 cm_node
->tcp_cntxt
.rcv_nxt
=
1970 loopbackremotenode
->tcp_cntxt
.loc_seq_num
;
1971 loopbackremotenode
->tcp_cntxt
.rcv_nxt
=
1972 cm_node
->tcp_cntxt
.loc_seq_num
;
1973 cm_node
->tcp_cntxt
.max_snd_wnd
=
1974 loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
1975 loopbackremotenode
->tcp_cntxt
.max_snd_wnd
=
1976 cm_node
->tcp_cntxt
.rcv_wnd
;
1977 cm_node
->tcp_cntxt
.snd_wnd
=
1978 loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
1979 loopbackremotenode
->tcp_cntxt
.snd_wnd
=
1980 cm_node
->tcp_cntxt
.rcv_wnd
;
1981 cm_node
->tcp_cntxt
.snd_wscale
=
1982 loopbackremotenode
->tcp_cntxt
.rcv_wscale
;
1983 loopbackremotenode
->tcp_cntxt
.snd_wscale
=
1984 cm_node
->tcp_cntxt
.rcv_wscale
;
1986 create_event(loopbackremotenode
, NES_CM_EVENT_MPA_REQ
);
1991 /* set our node side to client (active) side */
1992 cm_node
->tcp_cntxt
.client
= 1;
1993 /* init our MPA frame ptr */
1994 memcpy(mpa_frame
->priv_data
, private_data
, private_data_len
);
1996 cm_node
->mpa_frame_size
= mpa_frame_size
;
1998 /* send a syn and goto syn sent state */
1999 cm_node
->state
= NES_CM_STATE_SYN_SENT
;
2000 ret
= send_syn(cm_node
, 0, NULL
);
2003 /* error in sending the syn free up the cm_node struct */
2004 nes_debug(NES_DBG_CM
, "Api - connect() FAILED: dest "
2005 "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
2006 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
,
2008 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
2013 nes_debug(NES_DBG_CM
, "Api - connect(): dest addr=0x%08X,"
2014 "port=0x%04x, cm_node=%p, cm_id = %p.\n",
2015 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
,
2023 * mini_cm_accept - accept a connection
2024 * This function is never called
2026 static int mini_cm_accept(struct nes_cm_core
*cm_core
,
2027 struct ietf_mpa_frame
*mpa_frame
, struct nes_cm_node
*cm_node
)
2034 * mini_cm_reject - reject and teardown a connection
2036 static int mini_cm_reject(struct nes_cm_core
*cm_core
,
2037 struct ietf_mpa_frame
*mpa_frame
, struct nes_cm_node
*cm_node
)
2042 nes_debug(NES_DBG_CM
, "%s cm_node=%p type=%d state=%d\n",
2043 __func__
, cm_node
, cm_node
->tcp_cntxt
.client
, cm_node
->state
);
2045 if (cm_node
->tcp_cntxt
.client
)
2047 cleanup_retrans_entry(cm_node
);
2049 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
2050 cm_node
->state
= NES_CM_STATE_CLOSED
;
2051 if (passive_state
== NES_SEND_RESET_EVENT
)
2052 rem_ref_cm_node(cm_core
, cm_node
);
2054 ret
= send_reset(cm_node
, NULL
);
2062 static int mini_cm_close(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
2066 if (!cm_core
|| !cm_node
)
2069 switch (cm_node
->state
) {
2070 case NES_CM_STATE_SYN_RCVD
:
2071 case NES_CM_STATE_SYN_SENT
:
2072 case NES_CM_STATE_ONE_SIDE_ESTABLISHED
:
2073 case NES_CM_STATE_ESTABLISHED
:
2074 case NES_CM_STATE_ACCEPTING
:
2075 case NES_CM_STATE_MPAREQ_SENT
:
2076 case NES_CM_STATE_MPAREQ_RCVD
:
2077 cleanup_retrans_entry(cm_node
);
2078 send_reset(cm_node
, NULL
);
2080 case NES_CM_STATE_CLOSE_WAIT
:
2081 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
2082 send_fin(cm_node
, NULL
);
2084 case NES_CM_STATE_FIN_WAIT1
:
2085 case NES_CM_STATE_FIN_WAIT2
:
2086 case NES_CM_STATE_LAST_ACK
:
2087 case NES_CM_STATE_TIME_WAIT
:
2088 case NES_CM_STATE_CLOSING
:
2091 case NES_CM_STATE_LISTENING
:
2092 case NES_CM_STATE_UNKNOWN
:
2093 case NES_CM_STATE_INITED
:
2094 case NES_CM_STATE_CLOSED
:
2095 ret
= rem_ref_cm_node(cm_core
, cm_node
);
2097 case NES_CM_STATE_TSA
:
2098 if (cm_node
->send_entry
)
2099 printk(KERN_ERR
"ERROR Close got called from STATE_TSA "
2100 "send_entry=%p\n", cm_node
->send_entry
);
2101 ret
= rem_ref_cm_node(cm_core
, cm_node
);
2109 * recv_pkt - recv an ETHERNET packet, and process it through CM
2110 * node state machine
2112 static int mini_cm_recv_pkt(struct nes_cm_core
*cm_core
,
2113 struct nes_vnic
*nesvnic
, struct sk_buff
*skb
)
2115 struct nes_cm_node
*cm_node
= NULL
;
2116 struct nes_cm_listener
*listener
= NULL
;
2118 struct tcphdr
*tcph
;
2119 struct nes_cm_info nfo
;
2120 int skb_handled
= 1;
2124 if (skb
->len
< sizeof(struct iphdr
) + sizeof(struct tcphdr
)) {
2128 iph
= (struct iphdr
*)skb
->data
;
2129 tcph
= (struct tcphdr
*)(skb
->data
+ sizeof(struct iphdr
));
2131 nfo
.loc_addr
= ntohl(iph
->daddr
);
2132 nfo
.loc_port
= ntohs(tcph
->dest
);
2133 nfo
.rem_addr
= ntohl(iph
->saddr
);
2134 nfo
.rem_port
= ntohs(tcph
->source
);
2136 nes_debug(NES_DBG_CM
, "Received packet: dest=" NIPQUAD_FMT
2137 ":0x%04X src=" NIPQUAD_FMT
":0x%04X\n",
2138 NIPQUAD(iph
->daddr
), tcph
->dest
,
2139 NIPQUAD(iph
->saddr
), tcph
->source
);
2142 cm_node
= find_node(cm_core
,
2143 nfo
.rem_port
, nfo
.rem_addr
,
2144 nfo
.loc_port
, nfo
.loc_addr
);
2147 /* Only type of packet accepted are for */
2148 /* the PASSIVE open (syn only) */
2149 if ((!tcph
->syn
) || (tcph
->ack
)) {
2153 listener
= find_listener(cm_core
, nfo
.loc_addr
,
2155 NES_CM_LISTENER_ACTIVE_STATE
);
2159 nes_debug(NES_DBG_CM
, "Unable to find listener for the pkt\n");
2163 nfo
.cm_id
= listener
->cm_id
;
2164 nfo
.conn_type
= listener
->conn_type
;
2165 cm_node
= make_cm_node(cm_core
, nesvnic
, &nfo
,
2168 nes_debug(NES_DBG_CM
, "Unable to allocate "
2170 cm_packets_dropped
++;
2171 atomic_dec(&listener
->ref_count
);
2172 dev_kfree_skb_any(skb
);
2175 if (!tcph
->rst
&& !tcph
->fin
) {
2176 cm_node
->state
= NES_CM_STATE_LISTENING
;
2178 cm_packets_dropped
++;
2179 rem_ref_cm_node(cm_core
, cm_node
);
2180 dev_kfree_skb_any(skb
);
2183 add_ref_cm_node(cm_node
);
2184 } else if (cm_node
->state
== NES_CM_STATE_TSA
) {
2185 rem_ref_cm_node(cm_core
, cm_node
);
2186 atomic_inc(&cm_accel_dropped_pkts
);
2187 dev_kfree_skb_any(skb
);
2190 skb_reset_network_header(skb
);
2191 skb_set_transport_header(skb
, sizeof(*tcph
));
2192 skb
->len
= ntohs(iph
->tot_len
);
2193 process_packet(cm_node
, skb
, cm_core
);
2194 rem_ref_cm_node(cm_core
, cm_node
);
2201 * nes_cm_alloc_core - allocate a top level instance of a cm core
2203 static struct nes_cm_core
*nes_cm_alloc_core(void)
2207 struct nes_cm_core
*cm_core
;
2208 struct sk_buff
*skb
= NULL
;
2210 /* setup the CM core */
2211 /* alloc top level core control structure */
2212 cm_core
= kzalloc(sizeof(*cm_core
), GFP_KERNEL
);
2216 INIT_LIST_HEAD(&cm_core
->connected_nodes
);
2217 init_timer(&cm_core
->tcp_timer
);
2218 cm_core
->tcp_timer
.function
= nes_cm_timer_tick
;
2220 cm_core
->mtu
= NES_CM_DEFAULT_MTU
;
2221 cm_core
->state
= NES_CM_STATE_INITED
;
2222 cm_core
->free_tx_pkt_max
= NES_CM_DEFAULT_FREE_PKTS
;
2224 atomic_set(&cm_core
->events_posted
, 0);
2226 /* init the packet lists */
2227 skb_queue_head_init(&cm_core
->tx_free_list
);
2229 for (i
= 0; i
< NES_CM_DEFAULT_FRAME_CNT
; i
++) {
2230 skb
= dev_alloc_skb(cm_core
->mtu
);
2235 /* add 'raw' skb to free frame list */
2236 skb_queue_head(&cm_core
->tx_free_list
, skb
);
2239 cm_core
->api
= &nes_cm_api
;
2241 spin_lock_init(&cm_core
->ht_lock
);
2242 spin_lock_init(&cm_core
->listen_list_lock
);
2244 INIT_LIST_HEAD(&cm_core
->listen_list
.list
);
2246 nes_debug(NES_DBG_CM
, "Init CM Core completed -- cm_core=%p\n", cm_core
);
2248 nes_debug(NES_DBG_CM
, "Enable QUEUE EVENTS\n");
2249 cm_core
->event_wq
= create_singlethread_workqueue("nesewq");
2250 cm_core
->post_event
= nes_cm_post_event
;
2251 nes_debug(NES_DBG_CM
, "Enable QUEUE DISCONNECTS\n");
2252 cm_core
->disconn_wq
= create_singlethread_workqueue("nesdwq");
2254 print_core(cm_core
);
2260 * mini_cm_dealloc_core - deallocate a top level instance of a cm core
2262 static int mini_cm_dealloc_core(struct nes_cm_core
*cm_core
)
2264 nes_debug(NES_DBG_CM
, "De-Alloc CM Core (%p)\n", cm_core
);
2271 if (timer_pending(&cm_core
->tcp_timer
)) {
2272 del_timer(&cm_core
->tcp_timer
);
2275 destroy_workqueue(cm_core
->event_wq
);
2276 destroy_workqueue(cm_core
->disconn_wq
);
2277 nes_debug(NES_DBG_CM
, "\n");
2287 static int mini_cm_get(struct nes_cm_core
*cm_core
)
2289 return cm_core
->state
;
2296 static int mini_cm_set(struct nes_cm_core
*cm_core
, u32 type
, u32 value
)
2301 case NES_CM_SET_PKT_SIZE
:
2302 cm_core
->mtu
= value
;
2304 case NES_CM_SET_FREE_PKT_Q_SIZE
:
2305 cm_core
->free_tx_pkt_max
= value
;
2308 /* unknown set option */
2317 * nes_cm_init_tsa_conn setup HW; MPA frames must be
2318 * successfully exchanged when this is called
2320 static int nes_cm_init_tsa_conn(struct nes_qp
*nesqp
, struct nes_cm_node
*cm_node
)
2327 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4
|
2328 NES_QPCONTEXT_MISC_NO_NAGLE
| NES_QPCONTEXT_MISC_DO_NOT_FRAG
|
2329 NES_QPCONTEXT_MISC_DROS
);
2331 if (cm_node
->tcp_cntxt
.snd_wscale
|| cm_node
->tcp_cntxt
.rcv_wscale
)
2332 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE
);
2334 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT
);
2336 nesqp
->nesqp_context
->mss
|= cpu_to_le32(((u32
)cm_node
->tcp_cntxt
.mss
) << 16);
2338 nesqp
->nesqp_context
->tcp_state_flow_label
|= cpu_to_le32(
2339 (u32
)NES_QPCONTEXT_TCPSTATE_EST
<< NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT
);
2341 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2342 (cm_node
->tcp_cntxt
.snd_wscale
<< NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT
) &
2343 NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK
);
2345 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2346 (cm_node
->tcp_cntxt
.rcv_wscale
<< NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT
) &
2347 NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK
);
2349 nesqp
->nesqp_context
->keepalive
= cpu_to_le32(0x80);
2350 nesqp
->nesqp_context
->ts_recent
= 0;
2351 nesqp
->nesqp_context
->ts_age
= 0;
2352 nesqp
->nesqp_context
->snd_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2353 nesqp
->nesqp_context
->snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.snd_wnd
);
2354 nesqp
->nesqp_context
->rcv_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2355 nesqp
->nesqp_context
->rcv_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_wnd
<<
2356 cm_node
->tcp_cntxt
.rcv_wscale
);
2357 nesqp
->nesqp_context
->snd_max
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2358 nesqp
->nesqp_context
->snd_una
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2359 nesqp
->nesqp_context
->srtt
= 0;
2360 nesqp
->nesqp_context
->rttvar
= cpu_to_le32(0x6);
2361 nesqp
->nesqp_context
->ssthresh
= cpu_to_le32(0x3FFFC000);
2362 nesqp
->nesqp_context
->cwnd
= cpu_to_le32(2*cm_node
->tcp_cntxt
.mss
);
2363 nesqp
->nesqp_context
->snd_wl1
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2364 nesqp
->nesqp_context
->snd_wl2
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2365 nesqp
->nesqp_context
->max_snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.max_snd_wnd
);
2367 nes_debug(NES_DBG_CM
, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
2368 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
2369 nesqp
->hwqp
.qp_id
, le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
2370 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
2371 cm_node
->tcp_cntxt
.mss
, le32_to_cpu(nesqp
->nesqp_context
->pd_index_wscale
),
2372 le32_to_cpu(nesqp
->nesqp_context
->rcv_wnd
),
2373 le32_to_cpu(nesqp
->nesqp_context
->misc
));
2374 nes_debug(NES_DBG_CM
, " snd_wnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->snd_wnd
));
2375 nes_debug(NES_DBG_CM
, " snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->cwnd
));
2376 nes_debug(NES_DBG_CM
, " max_swnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->max_snd_wnd
));
2378 nes_debug(NES_DBG_CM
, "Change cm_node state to TSA\n");
2379 cm_node
->state
= NES_CM_STATE_TSA
;
2388 int nes_cm_disconn(struct nes_qp
*nesqp
)
2390 unsigned long flags
;
2392 spin_lock_irqsave(&nesqp
->lock
, flags
);
2393 if (nesqp
->disconn_pending
== 0) {
2394 nesqp
->disconn_pending
++;
2395 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2396 /* init our disconnect work element, to */
2397 INIT_WORK(&nesqp
->disconn_work
, nes_disconnect_worker
);
2399 queue_work(g_cm_core
->disconn_wq
, &nesqp
->disconn_work
);
2401 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2408 * nes_disconnect_worker
2410 static void nes_disconnect_worker(struct work_struct
*work
)
2412 struct nes_qp
*nesqp
= container_of(work
, struct nes_qp
, disconn_work
);
2414 nes_debug(NES_DBG_CM
, "processing AEQE id 0x%04X for QP%u.\n",
2415 nesqp
->last_aeq
, nesqp
->hwqp
.qp_id
);
2416 nes_cm_disconn_true(nesqp
);
2421 * nes_cm_disconn_true
2423 static int nes_cm_disconn_true(struct nes_qp
*nesqp
)
2425 unsigned long flags
;
2427 struct iw_cm_id
*cm_id
;
2428 struct iw_cm_event cm_event
;
2429 struct nes_vnic
*nesvnic
;
2431 u8 original_hw_tcp_state
;
2432 u8 original_ibqp_state
;
2433 u8 issued_disconnect_reset
= 0;
2436 nes_debug(NES_DBG_CM
, "disconnect_worker nesqp is NULL\n");
2440 spin_lock_irqsave(&nesqp
->lock
, flags
);
2441 cm_id
= nesqp
->cm_id
;
2442 /* make sure we havent already closed this connection */
2444 nes_debug(NES_DBG_CM
, "QP%u disconnect_worker cmid is NULL\n",
2446 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2450 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2451 nes_debug(NES_DBG_CM
, "Disconnecting QP%u\n", nesqp
->hwqp
.qp_id
);
2453 original_hw_tcp_state
= nesqp
->hw_tcp_state
;
2454 original_ibqp_state
= nesqp
->ibqp_state
;
2455 last_ae
= nesqp
->last_aeq
;
2458 nes_debug(NES_DBG_CM
, "set ibqp_state=%u\n", nesqp
->ibqp_state
);
2460 if ((nesqp
->cm_id
) && (cm_id
->event_handler
)) {
2461 if ((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSE_WAIT
) ||
2462 ((original_ibqp_state
== IB_QPS_RTS
) &&
2463 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2464 atomic_inc(&cm_disconnects
);
2465 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
2466 if (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
) {
2467 cm_event
.status
= IW_CM_EVENT_STATUS_RESET
;
2468 nes_debug(NES_DBG_CM
, "Generating a CM "
2469 "Disconnect Event (status reset) for "
2470 "QP%u, cm_id = %p. \n",
2471 nesqp
->hwqp
.qp_id
, cm_id
);
2473 cm_event
.status
= IW_CM_EVENT_STATUS_OK
;
2475 cm_event
.local_addr
= cm_id
->local_addr
;
2476 cm_event
.remote_addr
= cm_id
->remote_addr
;
2477 cm_event
.private_data
= NULL
;
2478 cm_event
.private_data_len
= 0;
2480 nes_debug(NES_DBG_CM
, "Generating a CM Disconnect Event"
2481 " for QP%u, SQ Head = %u, SQ Tail = %u. "
2482 "cm_id = %p, refcount = %u.\n",
2483 nesqp
->hwqp
.qp_id
, nesqp
->hwqp
.sq_head
,
2484 nesqp
->hwqp
.sq_tail
, cm_id
,
2485 atomic_read(&nesqp
->refcount
));
2487 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2488 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2490 nes_debug(NES_DBG_CM
, "OFA CM event_handler "
2491 "returned, ret=%d\n", ret
);
2492 spin_lock_irqsave(&nesqp
->lock
, flags
);
2495 nesqp
->disconn_pending
= 0;
2496 /* There might have been another AE while the lock was released */
2497 original_hw_tcp_state
= nesqp
->hw_tcp_state
;
2498 original_ibqp_state
= nesqp
->ibqp_state
;
2499 last_ae
= nesqp
->last_aeq
;
2501 if ((issued_disconnect_reset
== 0) && (nesqp
->cm_id
) &&
2502 ((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSED
) ||
2503 (original_hw_tcp_state
== NES_AEQE_TCP_STATE_TIME_WAIT
) ||
2504 (last_ae
== NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
) ||
2505 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2506 atomic_inc(&cm_closes
);
2507 nesqp
->cm_id
= NULL
;
2508 nesqp
->in_disconnect
= 0;
2509 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2510 nes_disconnect(nesqp
, 1);
2512 cm_id
->provider_data
= nesqp
;
2513 /* Send up the close complete event */
2514 cm_event
.event
= IW_CM_EVENT_CLOSE
;
2515 cm_event
.status
= IW_CM_EVENT_STATUS_OK
;
2516 cm_event
.provider_data
= cm_id
->provider_data
;
2517 cm_event
.local_addr
= cm_id
->local_addr
;
2518 cm_event
.remote_addr
= cm_id
->remote_addr
;
2519 cm_event
.private_data
= NULL
;
2520 cm_event
.private_data_len
= 0;
2522 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2524 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
2527 cm_id
->rem_ref(cm_id
);
2529 spin_lock_irqsave(&nesqp
->lock
, flags
);
2530 if (nesqp
->flush_issued
== 0) {
2531 nesqp
->flush_issued
= 1;
2532 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2533 flush_wqes(nesvnic
->nesdev
, nesqp
,
2534 NES_CQP_FLUSH_RQ
, 1);
2536 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2538 cm_id
= nesqp
->cm_id
;
2539 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2540 /* check to see if the inbound reset beat the outbound reset */
2541 if ((!cm_id
) && (last_ae
==NES_AEQE_AEID_RESET_SENT
)) {
2542 nes_debug(NES_DBG_CM
, "QP%u: Decing refcount "
2543 "due to inbound reset beating the "
2544 "outbound reset.\n", nesqp
->hwqp
.qp_id
);
2548 nesqp
->disconn_pending
= 0;
2549 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2559 static int nes_disconnect(struct nes_qp
*nesqp
, int abrupt
)
2562 struct nes_vnic
*nesvnic
;
2563 struct nes_device
*nesdev
;
2565 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2569 nesdev
= nesvnic
->nesdev
;
2571 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
2572 atomic_read(&nesvnic
->netdev
->refcnt
));
2574 if (nesqp
->active_conn
) {
2576 /* indicate this connection is NOT active */
2577 nesqp
->active_conn
= 0;
2579 /* Need to free the Last Streaming Mode Message */
2580 if (nesqp
->ietf_frame
) {
2581 pci_free_consistent(nesdev
->pcidev
,
2582 nesqp
->private_data_len
+sizeof(struct ietf_mpa_frame
),
2583 nesqp
->ietf_frame
, nesqp
->ietf_frame_pbase
);
2587 /* close the CM node down if it is still active */
2588 if (nesqp
->cm_node
) {
2589 nes_debug(NES_DBG_CM
, "Call close API\n");
2591 g_cm_core
->api
->close(g_cm_core
, nesqp
->cm_node
);
2601 int nes_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
2605 struct nes_qp
*nesqp
;
2606 struct nes_vnic
*nesvnic
;
2607 struct nes_device
*nesdev
;
2608 struct nes_cm_node
*cm_node
;
2609 struct nes_adapter
*adapter
;
2610 struct ib_qp_attr attr
;
2611 struct iw_cm_event cm_event
;
2612 struct nes_hw_qp_wqe
*wqe
;
2613 struct nes_v4_quad nes_quad
;
2618 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
2622 /* get all our handles */
2623 nesqp
= to_nesqp(ibqp
);
2624 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2625 nesdev
= nesvnic
->nesdev
;
2626 adapter
= nesdev
->nesadapter
;
2628 cm_node
= (struct nes_cm_node
*)cm_id
->provider_data
;
2629 nes_debug(NES_DBG_CM
, "nes_accept: cm_node= %p nesvnic=%p, netdev=%p,"
2630 "%s\n", cm_node
, nesvnic
, nesvnic
->netdev
,
2631 nesvnic
->netdev
->name
);
2633 /* associate the node with the QP */
2634 nesqp
->cm_node
= (void *)cm_node
;
2635 cm_node
->nesqp
= nesqp
;
2636 nes_add_ref(&nesqp
->ibqp
);
2638 nes_debug(NES_DBG_CM
, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
2639 nesqp
->hwqp
.qp_id
, cm_node
, jiffies
, cm_node
->listener
);
2640 atomic_inc(&cm_accepts
);
2642 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
2643 atomic_read(&nesvnic
->netdev
->refcnt
));
2645 /* allocate the ietf frame and space for private data */
2646 nesqp
->ietf_frame
= pci_alloc_consistent(nesdev
->pcidev
,
2647 sizeof(struct ietf_mpa_frame
) + conn_param
->private_data_len
,
2648 &nesqp
->ietf_frame_pbase
);
2650 if (!nesqp
->ietf_frame
) {
2651 nes_debug(NES_DBG_CM
, "Unable to allocate memory for private "
2657 /* setup the MPA frame */
2658 nesqp
->private_data_len
= conn_param
->private_data_len
;
2659 memcpy(nesqp
->ietf_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
);
2661 memcpy(nesqp
->ietf_frame
->priv_data
, conn_param
->private_data
,
2662 conn_param
->private_data_len
);
2664 nesqp
->ietf_frame
->priv_data_len
=
2665 cpu_to_be16(conn_param
->private_data_len
);
2666 nesqp
->ietf_frame
->rev
= mpa_version
;
2667 nesqp
->ietf_frame
->flags
= IETF_MPA_FLAGS_CRC
;
2669 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
2670 wqe
= &nesqp
->hwqp
.sq_vbase
[0];
2672 if (cm_id
->remote_addr
.sin_addr
.s_addr
!=
2673 cm_id
->local_addr
.sin_addr
.s_addr
) {
2674 u64temp
= (unsigned long)nesqp
;
2675 u64temp
|= NES_SW_CONTEXT_ALIGN
>>1;
2676 set_wqe_64bit_value(wqe
->wqe_words
,
2677 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
,
2679 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
2680 cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING
|
2681 NES_IWARP_SQ_WQE_WRPDU
);
2682 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] =
2683 cpu_to_le32(conn_param
->private_data_len
+
2684 sizeof(struct ietf_mpa_frame
));
2685 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
] =
2686 cpu_to_le32((u32
)nesqp
->ietf_frame_pbase
);
2687 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX
] =
2688 cpu_to_le32((u32
)((u64
)nesqp
->ietf_frame_pbase
>> 32));
2689 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] =
2690 cpu_to_le32(conn_param
->private_data_len
+
2691 sizeof(struct ietf_mpa_frame
));
2692 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 0;
2694 nesqp
->nesqp_context
->ird_ord_sizes
|=
2695 cpu_to_le32(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
2696 NES_QPCONTEXT_ORDIRD_WRPDU
);
2698 nesqp
->nesqp_context
->ird_ord_sizes
|=
2699 cpu_to_le32((NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
2700 NES_QPCONTEXT_ORDIRD_WRPDU
|
2701 NES_QPCONTEXT_ORDIRD_ALSMM
));
2703 nesqp
->skip_lsmm
= 1;
2706 /* Cache the cm_id in the qp */
2707 nesqp
->cm_id
= cm_id
;
2708 cm_node
->cm_id
= cm_id
;
2710 /* nesqp->cm_node = (void *)cm_id->provider_data; */
2711 cm_id
->provider_data
= nesqp
;
2712 nesqp
->active_conn
= 0;
2714 if (cm_node
->state
== NES_CM_STATE_TSA
)
2715 nes_debug(NES_DBG_CM
, "Already state = TSA for cm_node=%p\n",
2718 nes_cm_init_tsa_conn(nesqp
, cm_node
);
2720 nesqp
->nesqp_context
->tcpPorts
[0] =
2721 cpu_to_le16(ntohs(cm_id
->local_addr
.sin_port
));
2722 nesqp
->nesqp_context
->tcpPorts
[1] =
2723 cpu_to_le16(ntohs(cm_id
->remote_addr
.sin_port
));
2725 if (ipv4_is_loopback(cm_id
->remote_addr
.sin_addr
.s_addr
))
2726 nesqp
->nesqp_context
->ip0
=
2727 cpu_to_le32(ntohl(nesvnic
->local_ipaddr
));
2729 nesqp
->nesqp_context
->ip0
=
2730 cpu_to_le32(ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
));
2732 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
2733 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
2734 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
2736 nesqp
->nesqp_context
->arp_index_vlan
|=
2737 cpu_to_le32(nes_arp_table(nesdev
,
2738 le32_to_cpu(nesqp
->nesqp_context
->ip0
), NULL
,
2739 NES_ARP_RESOLVE
) << 16);
2741 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
2742 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
2744 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
2746 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32(
2747 ((u32
)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
));
2748 nesqp
->nesqp_context
->ird_ord_sizes
|=
2749 cpu_to_le32((u32
)conn_param
->ord
);
2751 memset(&nes_quad
, 0, sizeof(nes_quad
));
2752 nes_quad
.DstIpAdrIndex
=
2753 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
2754 if (ipv4_is_loopback(cm_id
->remote_addr
.sin_addr
.s_addr
))
2755 nes_quad
.SrcIpadr
= nesvnic
->local_ipaddr
;
2757 nes_quad
.SrcIpadr
= cm_id
->remote_addr
.sin_addr
.s_addr
;
2758 nes_quad
.TcpPorts
[0] = cm_id
->remote_addr
.sin_port
;
2759 nes_quad
.TcpPorts
[1] = cm_id
->local_addr
.sin_port
;
2761 /* Produce hash key */
2762 crc_value
= get_crc_value(&nes_quad
);
2763 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
2764 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, CRC = 0x%08X\n",
2765 nesqp
->hte_index
, nesqp
->hte_index
& adapter
->hte_index_mask
);
2767 nesqp
->hte_index
&= adapter
->hte_index_mask
;
2768 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
2770 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
2772 nes_debug(NES_DBG_CM
, "QP%u, Destination IP = 0x%08X:0x%04X, local = "
2773 "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
2774 "private data length=%zu.\n", nesqp
->hwqp
.qp_id
,
2775 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
2776 ntohs(cm_id
->remote_addr
.sin_port
),
2777 ntohl(cm_id
->local_addr
.sin_addr
.s_addr
),
2778 ntohs(cm_id
->local_addr
.sin_port
),
2779 le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
2780 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
2781 conn_param
->private_data_len
+
2782 sizeof(struct ietf_mpa_frame
));
2785 /* notify OF layer that accept event was successfull */
2786 cm_id
->add_ref(cm_id
);
2788 cm_event
.event
= IW_CM_EVENT_ESTABLISHED
;
2789 cm_event
.status
= IW_CM_EVENT_STATUS_ACCEPTED
;
2790 cm_event
.provider_data
= (void *)nesqp
;
2791 cm_event
.local_addr
= cm_id
->local_addr
;
2792 cm_event
.remote_addr
= cm_id
->remote_addr
;
2793 cm_event
.private_data
= NULL
;
2794 cm_event
.private_data_len
= 0;
2795 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2796 attr
.qp_state
= IB_QPS_RTS
;
2797 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
2798 if (cm_node
->loopbackpartner
) {
2799 cm_node
->loopbackpartner
->mpa_frame_size
=
2800 nesqp
->private_data_len
;
2801 /* copy entire MPA frame to our cm_node's frame */
2802 memcpy(cm_node
->loopbackpartner
->mpa_frame_buf
,
2803 nesqp
->ietf_frame
->priv_data
, nesqp
->private_data_len
);
2804 create_event(cm_node
->loopbackpartner
, NES_CM_EVENT_CONNECTED
);
2807 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
2808 "ret=%d\n", __func__
, __LINE__
, ret
);
2810 passive_state
= atomic_add_return(1, &cm_node
->passive_state
);
2811 if (passive_state
== NES_SEND_RESET_EVENT
)
2812 create_event(cm_node
, NES_CM_EVENT_RESET
);
2820 int nes_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
2822 struct nes_cm_node
*cm_node
;
2823 struct nes_cm_core
*cm_core
;
2825 atomic_inc(&cm_rejects
);
2826 cm_node
= (struct nes_cm_node
*) cm_id
->provider_data
;
2827 cm_core
= cm_node
->cm_core
;
2828 cm_node
->mpa_frame_size
= sizeof(struct ietf_mpa_frame
) + pdata_len
;
2830 strcpy(&cm_node
->mpa_frame
.key
[0], IEFT_MPA_KEY_REP
);
2831 memcpy(&cm_node
->mpa_frame
.priv_data
, pdata
, pdata_len
);
2833 cm_node
->mpa_frame
.priv_data_len
= cpu_to_be16(pdata_len
);
2834 cm_node
->mpa_frame
.rev
= mpa_version
;
2835 cm_node
->mpa_frame
.flags
= IETF_MPA_FLAGS_CRC
| IETF_MPA_FLAGS_REJECT
;
2837 cm_core
->api
->reject(cm_core
, &cm_node
->mpa_frame
, cm_node
);
2845 * setup and launch cm connect node
2847 int nes_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
2850 struct nes_qp
*nesqp
;
2851 struct nes_vnic
*nesvnic
;
2852 struct nes_device
*nesdev
;
2853 struct nes_cm_node
*cm_node
;
2854 struct nes_cm_info cm_info
;
2856 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
2859 nesqp
= to_nesqp(ibqp
);
2862 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2865 nesdev
= nesvnic
->nesdev
;
2869 nes_debug(NES_DBG_CM
, "QP%u, current IP = 0x%08X, Destination IP = "
2870 "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp
->hwqp
.qp_id
,
2871 ntohl(nesvnic
->local_ipaddr
),
2872 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
2873 ntohs(cm_id
->remote_addr
.sin_port
),
2874 ntohl(cm_id
->local_addr
.sin_addr
.s_addr
),
2875 ntohs(cm_id
->local_addr
.sin_port
));
2877 atomic_inc(&cm_connects
);
2878 nesqp
->active_conn
= 1;
2880 /* cache the cm_id in the qp */
2881 nesqp
->cm_id
= cm_id
;
2883 cm_id
->provider_data
= nesqp
;
2885 nesqp
->private_data_len
= conn_param
->private_data_len
;
2886 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32((u32
)conn_param
->ord
);
2887 nes_debug(NES_DBG_CM
, "requested ord = 0x%08X.\n", (u32
)conn_param
->ord
);
2888 nes_debug(NES_DBG_CM
, "mpa private data len =%u\n",
2889 conn_param
->private_data_len
);
2891 if (cm_id
->local_addr
.sin_addr
.s_addr
!=
2892 cm_id
->remote_addr
.sin_addr
.s_addr
)
2893 nes_manage_apbvt(nesvnic
, ntohs(cm_id
->local_addr
.sin_port
),
2894 PCI_FUNC(nesdev
->pcidev
->devfn
), NES_MANAGE_APBVT_ADD
);
2896 /* set up the connection params for the node */
2897 cm_info
.loc_addr
= htonl(cm_id
->local_addr
.sin_addr
.s_addr
);
2898 cm_info
.loc_port
= htons(cm_id
->local_addr
.sin_port
);
2899 cm_info
.rem_addr
= htonl(cm_id
->remote_addr
.sin_addr
.s_addr
);
2900 cm_info
.rem_port
= htons(cm_id
->remote_addr
.sin_port
);
2901 cm_info
.cm_id
= cm_id
;
2902 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
2904 cm_id
->add_ref(cm_id
);
2906 /* create a connect CM node connection */
2907 cm_node
= g_cm_core
->api
->connect(g_cm_core
, nesvnic
,
2908 conn_param
->private_data_len
, (void *)conn_param
->private_data
,
2911 if (cm_id
->local_addr
.sin_addr
.s_addr
!=
2912 cm_id
->remote_addr
.sin_addr
.s_addr
)
2913 nes_manage_apbvt(nesvnic
, ntohs(cm_id
->local_addr
.sin_port
),
2914 PCI_FUNC(nesdev
->pcidev
->devfn
),
2915 NES_MANAGE_APBVT_DEL
);
2917 cm_id
->rem_ref(cm_id
);
2921 cm_node
->apbvt_set
= 1;
2922 nesqp
->cm_node
= cm_node
;
2923 cm_node
->nesqp
= nesqp
;
2924 nes_add_ref(&nesqp
->ibqp
);
2933 int nes_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
2935 struct nes_vnic
*nesvnic
;
2936 struct nes_cm_listener
*cm_node
;
2937 struct nes_cm_info cm_info
;
2938 struct nes_adapter
*adapter
;
2942 nes_debug(NES_DBG_CM
, "cm_id = %p, local port = 0x%04X.\n",
2943 cm_id
, ntohs(cm_id
->local_addr
.sin_port
));
2945 nesvnic
= to_nesvnic(cm_id
->device
);
2948 adapter
= nesvnic
->nesdev
->nesadapter
;
2949 nes_debug(NES_DBG_CM
, "nesvnic=%p, netdev=%p, %s\n",
2950 nesvnic
, nesvnic
->netdev
, nesvnic
->netdev
->name
);
2952 nes_debug(NES_DBG_CM
, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
2953 nesvnic
->local_ipaddr
, cm_id
->local_addr
.sin_addr
.s_addr
);
2955 /* setup listen params in our api call struct */
2956 cm_info
.loc_addr
= nesvnic
->local_ipaddr
;
2957 cm_info
.loc_port
= cm_id
->local_addr
.sin_port
;
2958 cm_info
.backlog
= backlog
;
2959 cm_info
.cm_id
= cm_id
;
2961 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
2964 cm_node
= g_cm_core
->api
->listen(g_cm_core
, nesvnic
, &cm_info
);
2966 printk(KERN_ERR
"%s[%u] Error returned from listen API call\n",
2967 __func__
, __LINE__
);
2971 cm_id
->provider_data
= cm_node
;
2973 if (!cm_node
->reused_node
) {
2974 err
= nes_manage_apbvt(nesvnic
,
2975 ntohs(cm_id
->local_addr
.sin_port
),
2976 PCI_FUNC(nesvnic
->nesdev
->pcidev
->devfn
),
2977 NES_MANAGE_APBVT_ADD
);
2979 printk(KERN_ERR
"nes_manage_apbvt call returned %d.\n",
2981 g_cm_core
->api
->stop_listener(g_cm_core
, (void *)cm_node
);
2984 cm_listens_created
++;
2987 cm_id
->add_ref(cm_id
);
2988 cm_id
->provider_data
= (void *)cm_node
;
2996 * nes_destroy_listen
2998 int nes_destroy_listen(struct iw_cm_id
*cm_id
)
3000 if (cm_id
->provider_data
)
3001 g_cm_core
->api
->stop_listener(g_cm_core
, cm_id
->provider_data
);
3003 nes_debug(NES_DBG_CM
, "cm_id->provider_data was NULL\n");
3005 cm_id
->rem_ref(cm_id
);
3014 int nes_cm_recv(struct sk_buff
*skb
, struct net_device
*netdevice
)
3017 cm_packets_received
++;
3018 if ((g_cm_core
) && (g_cm_core
->api
)) {
3019 rc
= g_cm_core
->api
->recv_pkt(g_cm_core
, netdev_priv(netdevice
), skb
);
3021 nes_debug(NES_DBG_CM
, "Unable to process packet for CM,"
3022 " cm is not setup properly.\n");
3031 * Start and init a cm core module
3033 int nes_cm_start(void)
3035 nes_debug(NES_DBG_CM
, "\n");
3036 /* create the primary CM core, pass this handle to subsequent core inits */
3037 g_cm_core
= nes_cm_alloc_core();
3048 * stop and dealloc all cm core instances
3050 int nes_cm_stop(void)
3052 g_cm_core
->api
->destroy_cm_core(g_cm_core
);
3058 * cm_event_connected
3059 * handle a connected event, setup QPs and HW
3061 static void cm_event_connected(struct nes_cm_event
*event
)
3064 struct nes_qp
*nesqp
;
3065 struct nes_vnic
*nesvnic
;
3066 struct nes_device
*nesdev
;
3067 struct nes_cm_node
*cm_node
;
3068 struct nes_adapter
*nesadapter
;
3069 struct ib_qp_attr attr
;
3070 struct iw_cm_id
*cm_id
;
3071 struct iw_cm_event cm_event
;
3072 struct nes_hw_qp_wqe
*wqe
;
3073 struct nes_v4_quad nes_quad
;
3077 /* get all our handles */
3078 cm_node
= event
->cm_node
;
3079 cm_id
= cm_node
->cm_id
;
3080 nes_debug(NES_DBG_CM
, "cm_event_connected - %p - cm_id = %p\n", cm_node
, cm_id
);
3081 nesqp
= (struct nes_qp
*)cm_id
->provider_data
;
3082 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
3083 nesdev
= nesvnic
->nesdev
;
3084 nesadapter
= nesdev
->nesadapter
;
3086 if (nesqp
->destroyed
) {
3089 atomic_inc(&cm_connecteds
);
3090 nes_debug(NES_DBG_CM
, "QP%u attempting to connect to 0x%08X:0x%04X on"
3091 " local port 0x%04X. jiffies = %lu.\n",
3093 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
3094 ntohs(cm_id
->remote_addr
.sin_port
),
3095 ntohs(cm_id
->local_addr
.sin_port
),
3098 nes_cm_init_tsa_conn(nesqp
, cm_node
);
3100 /* set the QP tsa context */
3101 nesqp
->nesqp_context
->tcpPorts
[0] =
3102 cpu_to_le16(ntohs(cm_id
->local_addr
.sin_port
));
3103 nesqp
->nesqp_context
->tcpPorts
[1] =
3104 cpu_to_le16(ntohs(cm_id
->remote_addr
.sin_port
));
3105 if (ipv4_is_loopback(cm_id
->remote_addr
.sin_addr
.s_addr
))
3106 nesqp
->nesqp_context
->ip0
=
3107 cpu_to_le32(ntohl(nesvnic
->local_ipaddr
));
3109 nesqp
->nesqp_context
->ip0
=
3110 cpu_to_le32(ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
));
3112 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
3113 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
3114 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
3115 nesqp
->nesqp_context
->arp_index_vlan
|= cpu_to_le32(
3116 nes_arp_table(nesdev
,
3117 le32_to_cpu(nesqp
->nesqp_context
->ip0
),
3118 NULL
, NES_ARP_RESOLVE
) << 16);
3119 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
3120 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
3121 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
3122 nesqp
->nesqp_context
->ird_ord_sizes
|=
3123 cpu_to_le32((u32
)1 <<
3124 NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
);
3126 /* Adjust tail for not having a LSMM */
3127 nesqp
->hwqp
.sq_tail
= 1;
3129 #if defined(NES_SEND_FIRST_WRITE)
3130 if (cm_node
->send_write0
) {
3131 nes_debug(NES_DBG_CM
, "Sending first write.\n");
3132 wqe
= &nesqp
->hwqp
.sq_vbase
[0];
3133 u64temp
= (unsigned long)nesqp
;
3134 u64temp
|= NES_SW_CONTEXT_ALIGN
>>1;
3135 set_wqe_64bit_value(wqe
->wqe_words
,
3136 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
, u64temp
);
3137 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
3138 cpu_to_le32(NES_IWARP_SQ_OP_RDMAW
);
3139 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] = 0;
3140 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
] = 0;
3141 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX
] = 0;
3142 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] = 0;
3143 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 0;
3145 /* use the reserved spot on the WQ for the extra first WQE */
3146 nesqp
->nesqp_context
->ird_ord_sizes
&=
3147 cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
3148 NES_QPCONTEXT_ORDIRD_WRPDU
|
3149 NES_QPCONTEXT_ORDIRD_ALSMM
));
3150 nesqp
->skip_lsmm
= 1;
3151 nesqp
->hwqp
.sq_tail
= 0;
3152 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
,
3153 (1 << 24) | 0x00800000 | nesqp
->hwqp
.qp_id
);
3157 memset(&nes_quad
, 0, sizeof(nes_quad
));
3159 nes_quad
.DstIpAdrIndex
=
3160 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
3161 if (ipv4_is_loopback(cm_id
->remote_addr
.sin_addr
.s_addr
))
3162 nes_quad
.SrcIpadr
= nesvnic
->local_ipaddr
;
3164 nes_quad
.SrcIpadr
= cm_id
->remote_addr
.sin_addr
.s_addr
;
3165 nes_quad
.TcpPorts
[0] = cm_id
->remote_addr
.sin_port
;
3166 nes_quad
.TcpPorts
[1] = cm_id
->local_addr
.sin_port
;
3168 /* Produce hash key */
3169 crc_value
= get_crc_value(&nes_quad
);
3170 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
3171 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
3172 nesqp
->hte_index
, nesqp
->hte_index
& nesadapter
->hte_index_mask
);
3174 nesqp
->hte_index
&= nesadapter
->hte_index_mask
;
3175 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
3177 nesqp
->ietf_frame
= &cm_node
->mpa_frame
;
3178 nesqp
->private_data_len
= (u8
) cm_node
->mpa_frame_size
;
3179 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
3181 /* notify OF layer we successfully created the requested connection */
3182 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3183 cm_event
.status
= IW_CM_EVENT_STATUS_ACCEPTED
;
3184 cm_event
.provider_data
= cm_id
->provider_data
;
3185 cm_event
.local_addr
.sin_family
= AF_INET
;
3186 cm_event
.local_addr
.sin_port
= cm_id
->local_addr
.sin_port
;
3187 cm_event
.remote_addr
= cm_id
->remote_addr
;
3189 cm_event
.private_data
= (void *)event
->cm_node
->mpa_frame_buf
;
3190 cm_event
.private_data_len
= (u8
) event
->cm_node
->mpa_frame_size
;
3192 cm_event
.local_addr
.sin_addr
.s_addr
= event
->cm_info
.rem_addr
;
3193 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3194 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3197 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3198 "ret=%d\n", __func__
, __LINE__
, ret
);
3199 attr
.qp_state
= IB_QPS_RTS
;
3200 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
3202 nes_debug(NES_DBG_CM
, "Exiting connect thread for QP%u. jiffies = "
3203 "%lu\n", nesqp
->hwqp
.qp_id
, jiffies
);
3210 * cm_event_connect_error
3212 static void cm_event_connect_error(struct nes_cm_event
*event
)
3214 struct nes_qp
*nesqp
;
3215 struct iw_cm_id
*cm_id
;
3216 struct iw_cm_event cm_event
;
3217 /* struct nes_cm_info cm_info; */
3220 if (!event
->cm_node
)
3223 cm_id
= event
->cm_node
->cm_id
;
3228 nes_debug(NES_DBG_CM
, "cm_node=%p, cm_id=%p\n", event
->cm_node
, cm_id
);
3229 nesqp
= cm_id
->provider_data
;
3235 /* notify OF layer about this connection error event */
3236 /* cm_id->rem_ref(cm_id); */
3237 nesqp
->cm_id
= NULL
;
3238 cm_id
->provider_data
= NULL
;
3239 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
3240 cm_event
.status
= IW_CM_EVENT_STATUS_REJECTED
;
3241 cm_event
.provider_data
= cm_id
->provider_data
;
3242 cm_event
.local_addr
= cm_id
->local_addr
;
3243 cm_event
.remote_addr
= cm_id
->remote_addr
;
3244 cm_event
.private_data
= NULL
;
3245 cm_event
.private_data_len
= 0;
3247 nes_debug(NES_DBG_CM
, "call CM_EVENT REJECTED, local_addr=%08x, "
3248 "remove_addr=%08x\n", cm_event
.local_addr
.sin_addr
.s_addr
,
3249 cm_event
.remote_addr
.sin_addr
.s_addr
);
3251 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3252 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3254 printk(KERN_ERR
"%s[%u] OFA CM event_handler returned, "
3255 "ret=%d\n", __func__
, __LINE__
, ret
);
3256 cm_id
->rem_ref(cm_id
);
3258 rem_ref_cm_node(event
->cm_node
->cm_core
, event
->cm_node
);
3266 static void cm_event_reset(struct nes_cm_event
*event
)
3268 struct nes_qp
*nesqp
;
3269 struct iw_cm_id
*cm_id
;
3270 struct iw_cm_event cm_event
;
3271 /* struct nes_cm_info cm_info; */
3274 if (!event
->cm_node
)
3277 if (!event
->cm_node
->cm_id
)
3280 cm_id
= event
->cm_node
->cm_id
;
3282 nes_debug(NES_DBG_CM
, "%p - cm_id = %p\n", event
->cm_node
, cm_id
);
3283 nesqp
= cm_id
->provider_data
;
3285 nesqp
->cm_id
= NULL
;
3286 /* cm_id->provider_data = NULL; */
3287 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
3288 cm_event
.status
= IW_CM_EVENT_STATUS_RESET
;
3289 cm_event
.provider_data
= cm_id
->provider_data
;
3290 cm_event
.local_addr
= cm_id
->local_addr
;
3291 cm_event
.remote_addr
= cm_id
->remote_addr
;
3292 cm_event
.private_data
= NULL
;
3293 cm_event
.private_data_len
= 0;
3295 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3296 cm_id
->add_ref(cm_id
);
3297 atomic_inc(&cm_closes
);
3298 cm_event
.event
= IW_CM_EVENT_CLOSE
;
3299 cm_event
.status
= IW_CM_EVENT_STATUS_OK
;
3300 cm_event
.provider_data
= cm_id
->provider_data
;
3301 cm_event
.local_addr
= cm_id
->local_addr
;
3302 cm_event
.remote_addr
= cm_id
->remote_addr
;
3303 cm_event
.private_data
= NULL
;
3304 cm_event
.private_data_len
= 0;
3305 nes_debug(NES_DBG_CM
, "NODE %p Generating CLOSE\n", event
->cm_node
);
3306 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3308 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
3311 /* notify OF layer about this connection error event */
3312 cm_id
->rem_ref(cm_id
);
3321 static void cm_event_mpa_req(struct nes_cm_event
*event
)
3323 struct iw_cm_id
*cm_id
;
3324 struct iw_cm_event cm_event
;
3326 struct nes_cm_node
*cm_node
;
3328 cm_node
= event
->cm_node
;
3331 cm_id
= cm_node
->cm_id
;
3333 atomic_inc(&cm_connect_reqs
);
3334 nes_debug(NES_DBG_CM
, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3335 cm_node
, cm_id
, jiffies
);
3337 cm_event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
3338 cm_event
.status
= IW_CM_EVENT_STATUS_OK
;
3339 cm_event
.provider_data
= (void *)cm_node
;
3341 cm_event
.local_addr
.sin_family
= AF_INET
;
3342 cm_event
.local_addr
.sin_port
= htons(event
->cm_info
.loc_port
);
3343 cm_event
.local_addr
.sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3345 cm_event
.remote_addr
.sin_family
= AF_INET
;
3346 cm_event
.remote_addr
.sin_port
= htons(event
->cm_info
.rem_port
);
3347 cm_event
.remote_addr
.sin_addr
.s_addr
= htonl(event
->cm_info
.rem_addr
);
3349 cm_event
.private_data
= cm_node
->mpa_frame_buf
;
3350 cm_event
.private_data_len
= (u8
) cm_node
->mpa_frame_size
;
3352 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3354 printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
3355 __func__
, __LINE__
, ret
);
3361 static void nes_cm_event_handler(struct work_struct
*);
3365 * post an event to the cm event handler
3367 static int nes_cm_post_event(struct nes_cm_event
*event
)
3369 atomic_inc(&event
->cm_node
->cm_core
->events_posted
);
3370 add_ref_cm_node(event
->cm_node
);
3371 event
->cm_info
.cm_id
->add_ref(event
->cm_info
.cm_id
);
3372 INIT_WORK(&event
->event_work
, nes_cm_event_handler
);
3373 nes_debug(NES_DBG_CM
, "cm_node=%p queue_work, event=%p\n",
3374 event
->cm_node
, event
);
3376 queue_work(event
->cm_node
->cm_core
->event_wq
, &event
->event_work
);
3378 nes_debug(NES_DBG_CM
, "Exit\n");
3384 * nes_cm_event_handler
3385 * worker function to handle cm events
3386 * will free instance of nes_cm_event
3388 static void nes_cm_event_handler(struct work_struct
*work
)
3390 struct nes_cm_event
*event
= container_of(work
, struct nes_cm_event
,
3392 struct nes_cm_core
*cm_core
;
3394 if ((!event
) || (!event
->cm_node
) || (!event
->cm_node
->cm_core
))
3397 cm_core
= event
->cm_node
->cm_core
;
3398 nes_debug(NES_DBG_CM
, "event=%p, event->type=%u, events posted=%u\n",
3399 event
, event
->type
, atomic_read(&cm_core
->events_posted
));
3401 switch (event
->type
) {
3402 case NES_CM_EVENT_MPA_REQ
:
3403 cm_event_mpa_req(event
);
3404 nes_debug(NES_DBG_CM
, "cm_node=%p CM Event: MPA REQUEST\n",
3407 case NES_CM_EVENT_RESET
:
3408 nes_debug(NES_DBG_CM
, "cm_node = %p CM Event: RESET\n",
3410 cm_event_reset(event
);
3412 case NES_CM_EVENT_CONNECTED
:
3413 if ((!event
->cm_node
->cm_id
) ||
3414 (event
->cm_node
->state
!= NES_CM_STATE_TSA
))
3416 cm_event_connected(event
);
3417 nes_debug(NES_DBG_CM
, "CM Event: CONNECTED\n");
3419 case NES_CM_EVENT_ABORTED
:
3420 if ((!event
->cm_node
->cm_id
) ||
3421 (event
->cm_node
->state
== NES_CM_STATE_TSA
))
3423 cm_event_connect_error(event
);
3424 nes_debug(NES_DBG_CM
, "CM Event: ABORTED\n");
3426 case NES_CM_EVENT_DROPPED_PKT
:
3427 nes_debug(NES_DBG_CM
, "CM Event: DROPPED PKT\n");
3430 nes_debug(NES_DBG_CM
, "CM Event: UNKNOWN EVENT TYPE\n");
3434 atomic_dec(&cm_core
->events_posted
);
3435 event
->cm_info
.cm_id
->rem_ref(event
->cm_info
.cm_id
);
3436 rem_ref_cm_node(cm_core
, event
->cm_node
);