2 * Copyright (c) 2006 - 2009 Intel-NE, 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 void form_cm_frame(struct sk_buff *, struct nes_cm_node *,
96 void *, u32, void *, u32, u8);
97 static int add_ref_cm_node(struct nes_cm_node *);
98 static int rem_ref_cm_node(struct nes_cm_core *, struct nes_cm_node *);
100 static int nes_cm_disconn_true(struct nes_qp *);
101 static int nes_cm_post_event(struct nes_cm_event *event);
102 static int nes_disconnect(struct nes_qp *nesqp, int abrupt);
103 static void nes_disconnect_worker(struct work_struct *work);
105 static int send_mpa_request(struct nes_cm_node *, struct sk_buff *);
106 static int send_syn(struct nes_cm_node *, u32, struct sk_buff *);
107 static int send_reset(struct nes_cm_node *, struct sk_buff *);
108 static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb);
109 static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb);
110 static void process_packet(struct nes_cm_node *, struct sk_buff *,
111 struct nes_cm_core *);
113 static void active_open_err(struct nes_cm_node *, struct sk_buff *, int);
114 static void passive_open_err(struct nes_cm_node *, struct sk_buff *, int);
115 static void cleanup_retrans_entry(struct nes_cm_node *);
116 static void handle_rcv_mpa(struct nes_cm_node *, struct sk_buff *,
117 enum nes_cm_event_type);
118 static void free_retrans_entry(struct nes_cm_node *cm_node);
119 static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
120 struct sk_buff *skb, int optionsize, int passive);
122 /* CM event handler functions */
123 static void cm_event_connected(struct nes_cm_event *);
124 static void cm_event_connect_error(struct nes_cm_event *);
125 static void cm_event_reset(struct nes_cm_event *);
126 static void cm_event_mpa_req(struct nes_cm_event *);
128 static void print_core(struct nes_cm_core *core);
130 /* External CM API Interface */
131 /* instance of function pointers for client API */
132 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
133 static struct nes_cm_ops nes_cm_api = {
142 mini_cm_dealloc_core,
147 static struct nes_cm_core *g_cm_core;
149 atomic_t cm_connects;
151 atomic_t cm_disconnects;
153 atomic_t cm_connecteds;
154 atomic_t cm_connect_reqs;
161 static struct nes_cm_event *create_event(struct nes_cm_node *cm_node,
162 enum nes_cm_event_type type)
164 struct nes_cm_event *event;
169 /* allocate an empty event */
170 event = kzalloc(sizeof(*event), GFP_ATOMIC);
176 event->cm_node = cm_node;
177 event->cm_info.rem_addr = cm_node->rem_addr;
178 event->cm_info.loc_addr = cm_node->loc_addr;
179 event->cm_info.rem_port = cm_node->rem_port;
180 event->cm_info.loc_port = cm_node->loc_port;
181 event->cm_info.cm_id = cm_node->cm_id;
183 nes_debug(NES_DBG_CM, "cm_node=%p Created event=%p, type=%u, "
184 "dst_addr=%08x[%x], src_addr=%08x[%x]\n",
185 cm_node, event, type, event->cm_info.loc_addr,
186 event->cm_info.loc_port, event->cm_info.rem_addr,
187 event->cm_info.rem_port);
189 nes_cm_post_event(event);
197 static int send_mpa_request(struct nes_cm_node *cm_node, struct sk_buff *skb)
201 nes_debug(NES_DBG_CM, "skb set to NULL\n");
205 /* send an MPA Request frame */
206 form_cm_frame(skb, cm_node, NULL, 0, &cm_node->mpa_frame,
207 cm_node->mpa_frame_size, SET_ACK);
209 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
218 * recv_mpa - process a received TCP pkt, we are expecting an
221 static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 len)
223 struct ietf_mpa_frame *mpa_frame;
225 /* assume req frame is in tcp data payload */
226 if (len < sizeof(struct ietf_mpa_frame)) {
227 nes_debug(NES_DBG_CM, "The received ietf buffer was too small (%x)\n", len);
231 mpa_frame = (struct ietf_mpa_frame *)buffer;
232 cm_node->mpa_frame_size = ntohs(mpa_frame->priv_data_len);
234 if (cm_node->mpa_frame_size + sizeof(struct ietf_mpa_frame) != len) {
235 nes_debug(NES_DBG_CM, "The received ietf buffer was not right"
236 " complete (%x + %x != %x)\n",
237 cm_node->mpa_frame_size, (u32)sizeof(struct ietf_mpa_frame), len);
241 /* copy entire MPA frame to our cm_node's frame */
242 memcpy(cm_node->mpa_frame_buf, buffer + sizeof(struct ietf_mpa_frame),
243 cm_node->mpa_frame_size);
250 * form_cm_frame - get a free packet and build empty frame Use
251 * node info to build.
253 static void form_cm_frame(struct sk_buff *skb,
254 struct nes_cm_node *cm_node, void *options, u32 optionsize,
255 void *data, u32 datasize, u8 flags)
261 u16 packetsize = sizeof(*iph);
263 packetsize += sizeof(*tcph);
264 packetsize += optionsize + datasize;
266 memset(skb->data, 0x00, ETH_HLEN + sizeof(*iph) + sizeof(*tcph));
269 buf = skb_put(skb, packetsize + ETH_HLEN);
271 ethh = (struct ethhdr *) buf;
274 iph = (struct iphdr *)buf;
276 tcph = (struct tcphdr *)buf;
277 skb_reset_mac_header(skb);
278 skb_set_network_header(skb, ETH_HLEN);
279 skb_set_transport_header(skb, ETH_HLEN+sizeof(*iph));
280 buf += sizeof(*tcph);
282 skb->ip_summed = CHECKSUM_PARTIAL;
283 skb->protocol = htons(0x800);
285 skb->mac_len = ETH_HLEN;
287 memcpy(ethh->h_dest, cm_node->rem_mac, ETH_ALEN);
288 memcpy(ethh->h_source, cm_node->loc_mac, ETH_ALEN);
289 ethh->h_proto = htons(0x0800);
291 iph->version = IPVERSION;
292 iph->ihl = 5; /* 5 * 4Byte words, IP headr len */
294 iph->tot_len = htons(packetsize);
295 iph->id = htons(++cm_node->tcp_cntxt.loc_id);
297 iph->frag_off = htons(0x4000);
299 iph->protocol = 0x06; /* IPPROTO_TCP */
301 iph->saddr = htonl(cm_node->loc_addr);
302 iph->daddr = htonl(cm_node->rem_addr);
304 tcph->source = htons(cm_node->loc_port);
305 tcph->dest = htons(cm_node->rem_port);
306 tcph->seq = htonl(cm_node->tcp_cntxt.loc_seq_num);
308 if (flags & SET_ACK) {
309 cm_node->tcp_cntxt.loc_ack_num = cm_node->tcp_cntxt.rcv_nxt;
310 tcph->ack_seq = htonl(cm_node->tcp_cntxt.loc_ack_num);
315 if (flags & SET_SYN) {
316 cm_node->tcp_cntxt.loc_seq_num++;
319 cm_node->tcp_cntxt.loc_seq_num += datasize;
321 if (flags & SET_FIN) {
322 cm_node->tcp_cntxt.loc_seq_num++;
329 tcph->doff = (u16)((sizeof(*tcph) + optionsize + 3) >> 2);
330 tcph->window = htons(cm_node->tcp_cntxt.rcv_wnd);
333 memcpy(buf, options, optionsize);
336 memcpy(buf, data, datasize);
338 skb_shinfo(skb)->nr_frags = 0;
339 cm_packets_created++;
345 * print_core - dump a cm core
347 static void print_core(struct nes_cm_core *core)
349 nes_debug(NES_DBG_CM, "---------------------------------------------\n");
350 nes_debug(NES_DBG_CM, "CM Core -- (core = %p )\n", core);
353 nes_debug(NES_DBG_CM, "---------------------------------------------\n");
355 nes_debug(NES_DBG_CM, "State : %u \n", core->state);
357 nes_debug(NES_DBG_CM, "Listen Nodes : %u \n", atomic_read(&core->listen_node_cnt));
358 nes_debug(NES_DBG_CM, "Active Nodes : %u \n", atomic_read(&core->node_cnt));
360 nes_debug(NES_DBG_CM, "core : %p \n", core);
362 nes_debug(NES_DBG_CM, "-------------- end core ---------------\n");
368 * note - cm_node needs to be protected before calling this. Encase in:
369 * rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
371 int schedule_nes_timer(struct nes_cm_node *cm_node, struct sk_buff *skb,
372 enum nes_timer_type type, int send_retrans,
373 int close_when_complete)
376 struct nes_cm_core *cm_core = cm_node->cm_core;
377 struct nes_timer_entry *new_send;
381 new_send = kzalloc(sizeof(*new_send), GFP_ATOMIC);
385 /* new_send->timetosend = currenttime */
386 new_send->retrycount = NES_DEFAULT_RETRYS;
387 new_send->retranscount = NES_DEFAULT_RETRANS;
389 new_send->timetosend = jiffies;
390 new_send->type = type;
391 new_send->netdev = cm_node->netdev;
392 new_send->send_retrans = send_retrans;
393 new_send->close_when_complete = close_when_complete;
395 if (type == NES_TIMER_TYPE_CLOSE) {
396 new_send->timetosend += (HZ/10);
397 spin_lock_irqsave(&cm_node->recv_list_lock, flags);
398 list_add_tail(&new_send->list, &cm_node->recv_list);
399 spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
402 if (type == NES_TIMER_TYPE_SEND) {
403 new_send->seq_num = ntohl(tcp_hdr(skb)->seq);
404 atomic_inc(&new_send->skb->users);
405 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
406 cm_node->send_entry = new_send;
407 add_ref_cm_node(cm_node);
408 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
409 new_send->timetosend = jiffies + NES_RETRY_TIMEOUT;
411 ret = nes_nic_cm_xmit(new_send->skb, cm_node->netdev);
412 if (ret != NETDEV_TX_OK) {
413 nes_debug(NES_DBG_CM, "Error sending packet %p "
414 "(jiffies = %lu)\n", new_send, jiffies);
415 atomic_dec(&new_send->skb->users);
416 new_send->timetosend = jiffies;
420 cleanup_retrans_entry(cm_node);
421 if (close_when_complete)
422 rem_ref_cm_node(cm_core, cm_node);
428 was_timer_set = timer_pending(&cm_core->tcp_timer);
430 if (!was_timer_set) {
431 cm_core->tcp_timer.expires = new_send->timetosend;
432 add_timer(&cm_core->tcp_timer);
442 static void nes_cm_timer_tick(unsigned long pass)
444 unsigned long flags, qplockflags;
445 unsigned long nexttimeout = jiffies + NES_LONG_TIME;
446 struct iw_cm_id *cm_id;
447 struct nes_cm_node *cm_node;
448 struct nes_timer_entry *send_entry, *recv_entry;
449 struct list_head *list_core, *list_core_temp;
450 struct list_head *list_node, *list_node_temp;
451 struct nes_cm_core *cm_core = g_cm_core;
452 struct nes_qp *nesqp;
454 int ret = NETDEV_TX_OK;
455 enum nes_cm_node_state last_state;
457 struct list_head timer_list;
458 INIT_LIST_HEAD(&timer_list);
459 spin_lock_irqsave(&cm_core->ht_lock, flags);
461 list_for_each_safe(list_node, list_core_temp,
462 &cm_core->connected_nodes) {
463 cm_node = container_of(list_node, struct nes_cm_node, list);
464 if (!list_empty(&cm_node->recv_list) || (cm_node->send_entry)) {
465 add_ref_cm_node(cm_node);
466 list_add(&cm_node->timer_entry, &timer_list);
469 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
471 list_for_each_safe(list_node, list_core_temp, &timer_list) {
472 cm_node = container_of(list_node, struct nes_cm_node,
474 spin_lock_irqsave(&cm_node->recv_list_lock, flags);
475 list_for_each_safe(list_core, list_node_temp,
476 &cm_node->recv_list) {
477 recv_entry = container_of(list_core,
478 struct nes_timer_entry, list);
481 if (time_after(recv_entry->timetosend, jiffies)) {
482 if (nexttimeout > recv_entry->timetosend ||
484 nexttimeout = recv_entry->timetosend;
489 list_del(&recv_entry->list);
490 cm_id = cm_node->cm_id;
491 spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
492 nesqp = (struct nes_qp *)recv_entry->skb;
493 spin_lock_irqsave(&nesqp->lock, qplockflags);
495 nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, "
496 "refcount = %d: HIT A "
497 "NES_TIMER_TYPE_CLOSE with something "
498 "to do!!!\n", nesqp->hwqp.qp_id, cm_id,
499 atomic_read(&nesqp->refcount));
500 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
501 nesqp->last_aeq = NES_AEQE_AEID_RESET_SENT;
502 nesqp->ibqp_state = IB_QPS_ERR;
503 spin_unlock_irqrestore(&nesqp->lock,
505 nes_cm_disconn(nesqp);
507 spin_unlock_irqrestore(&nesqp->lock,
509 nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, "
510 "refcount = %d: HIT A "
511 "NES_TIMER_TYPE_CLOSE with nothing "
512 "to do!!!\n", nesqp->hwqp.qp_id, cm_id,
513 atomic_read(&nesqp->refcount));
516 cm_id->rem_ref(cm_id);
519 spin_lock_irqsave(&cm_node->recv_list_lock, flags);
521 spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
523 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
525 send_entry = cm_node->send_entry;
528 if (time_after(send_entry->timetosend, jiffies)) {
529 if (cm_node->state != NES_CM_STATE_TSA) {
531 send_entry->timetosend) ||
534 send_entry->timetosend;
539 free_retrans_entry(cm_node);
544 if ((cm_node->state == NES_CM_STATE_TSA) ||
545 (cm_node->state == NES_CM_STATE_CLOSED)) {
546 free_retrans_entry(cm_node);
550 if (!send_entry->retranscount ||
551 !send_entry->retrycount) {
552 cm_packets_dropped++;
553 last_state = cm_node->state;
554 cm_node->state = NES_CM_STATE_CLOSED;
555 free_retrans_entry(cm_node);
556 spin_unlock_irqrestore(
557 &cm_node->retrans_list_lock, flags);
558 if (last_state == NES_CM_STATE_SYN_RCVD)
559 rem_ref_cm_node(cm_core, cm_node);
561 create_event(cm_node,
562 NES_CM_EVENT_ABORTED);
563 spin_lock_irqsave(&cm_node->retrans_list_lock,
567 atomic_inc(&send_entry->skb->users);
568 cm_packets_retrans++;
569 nes_debug(NES_DBG_CM, "Retransmitting send_entry %p "
570 "for node %p, jiffies = %lu, time to send = "
571 "%lu, retranscount = %u, send_entry->seq_num = "
572 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
573 "0x%08X\n", send_entry, cm_node, jiffies,
574 send_entry->timetosend,
575 send_entry->retranscount,
577 cm_node->tcp_cntxt.rem_ack_num);
579 spin_unlock_irqrestore(&cm_node->retrans_list_lock,
581 ret = nes_nic_cm_xmit(send_entry->skb, cm_node->netdev);
582 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
583 if (ret != NETDEV_TX_OK) {
584 nes_debug(NES_DBG_CM, "rexmit failed for "
585 "node=%p\n", cm_node);
586 cm_packets_bounced++;
587 atomic_dec(&send_entry->skb->users);
588 send_entry->retrycount--;
589 nexttimeout = jiffies + NES_SHORT_TIME;
595 nes_debug(NES_DBG_CM, "Packet Sent: retrans count = "
596 "%u, retry count = %u.\n",
597 send_entry->retranscount,
598 send_entry->retrycount);
599 if (send_entry->send_retrans) {
600 send_entry->retranscount--;
601 send_entry->timetosend = jiffies +
603 if (nexttimeout > send_entry->timetosend ||
605 nexttimeout = send_entry->timetosend;
609 int close_when_complete;
610 close_when_complete =
611 send_entry->close_when_complete;
612 nes_debug(NES_DBG_CM, "cm_node=%p state=%d\n",
613 cm_node, cm_node->state);
614 free_retrans_entry(cm_node);
615 if (close_when_complete)
616 rem_ref_cm_node(cm_node->cm_core,
621 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
622 rem_ref_cm_node(cm_node->cm_core, cm_node);
623 if (ret != NETDEV_TX_OK) {
624 nes_debug(NES_DBG_CM, "rexmit failed for cm_node=%p\n",
631 if (!timer_pending(&cm_core->tcp_timer)) {
632 cm_core->tcp_timer.expires = nexttimeout;
633 add_timer(&cm_core->tcp_timer);
642 static int send_syn(struct nes_cm_node *cm_node, u32 sendack,
647 char optionsbuffer[sizeof(struct option_mss) +
648 sizeof(struct option_windowscale) + sizeof(struct option_base) +
649 TCP_OPTIONS_PADDING];
652 /* Sending MSS option */
653 union all_known_options *options;
658 options = (union all_known_options *)&optionsbuffer[optionssize];
659 options->as_mss.optionnum = OPTION_NUMBER_MSS;
660 options->as_mss.length = sizeof(struct option_mss);
661 options->as_mss.mss = htons(cm_node->tcp_cntxt.mss);
662 optionssize += sizeof(struct option_mss);
664 options = (union all_known_options *)&optionsbuffer[optionssize];
665 options->as_windowscale.optionnum = OPTION_NUMBER_WINDOW_SCALE;
666 options->as_windowscale.length = sizeof(struct option_windowscale);
667 options->as_windowscale.shiftcount = cm_node->tcp_cntxt.rcv_wscale;
668 optionssize += sizeof(struct option_windowscale);
670 if (sendack && !(NES_DRV_OPT_SUPRESS_OPTION_BC & nes_drv_opt)) {
671 options = (union all_known_options *)&optionsbuffer[optionssize];
672 options->as_base.optionnum = OPTION_NUMBER_WRITE0;
673 options->as_base.length = sizeof(struct option_base);
674 optionssize += sizeof(struct option_base);
675 /* we need the size to be a multiple of 4 */
676 options = (union all_known_options *)&optionsbuffer[optionssize];
679 options = (union all_known_options *)&optionsbuffer[optionssize];
684 options = (union all_known_options *)&optionsbuffer[optionssize];
685 options->as_end = OPTION_NUMBER_END;
689 skb = dev_alloc_skb(MAX_CM_BUFFER);
691 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
698 form_cm_frame(skb, cm_node, optionsbuffer, optionssize, NULL, 0, flags);
699 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
708 static int send_reset(struct nes_cm_node *cm_node, struct sk_buff *skb)
711 int flags = SET_RST | SET_ACK;
714 skb = dev_alloc_skb(MAX_CM_BUFFER);
716 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
720 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, flags);
721 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 1);
730 static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb)
735 skb = dev_alloc_skb(MAX_CM_BUFFER);
738 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
742 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK);
743 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 0);
752 static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb)
756 /* if we didn't get a frame get one */
758 skb = dev_alloc_skb(MAX_CM_BUFFER);
761 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
765 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK | SET_FIN);
766 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
773 * find_node - find a cm node that matches the reference cm node
775 static struct nes_cm_node *find_node(struct nes_cm_core *cm_core,
776 u16 rem_port, nes_addr_t rem_addr, u16 loc_port, nes_addr_t loc_addr)
779 struct list_head *hte;
780 struct nes_cm_node *cm_node;
781 __be32 tmp_addr = cpu_to_be32(loc_addr);
783 /* get a handle on the hte */
784 hte = &cm_core->connected_nodes;
786 nes_debug(NES_DBG_CM, "Searching for an owner node: %pI4:%x from core %p->%p\n",
787 &tmp_addr, loc_port, cm_core, hte);
789 /* walk list and find cm_node associated with this session ID */
790 spin_lock_irqsave(&cm_core->ht_lock, flags);
791 list_for_each_entry(cm_node, hte, list) {
792 /* compare quad, return node handle if a match */
793 nes_debug(NES_DBG_CM, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
794 cm_node->loc_addr, cm_node->loc_port,
796 cm_node->rem_addr, cm_node->rem_port,
798 if ((cm_node->loc_addr == loc_addr) && (cm_node->loc_port == loc_port) &&
799 (cm_node->rem_addr == rem_addr) && (cm_node->rem_port == rem_port)) {
800 add_ref_cm_node(cm_node);
801 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
805 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
813 * find_listener - find a cm node listening on this addr-port pair
815 static struct nes_cm_listener *find_listener(struct nes_cm_core *cm_core,
816 nes_addr_t dst_addr, u16 dst_port, enum nes_cm_listener_state listener_state)
819 struct nes_cm_listener *listen_node;
820 __be32 tmp_addr = cpu_to_be32(dst_addr);
822 /* walk list and find cm_node associated with this session ID */
823 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
824 list_for_each_entry(listen_node, &cm_core->listen_list.list, list) {
825 /* compare node pair, return node handle if a match */
826 if (((listen_node->loc_addr == dst_addr) ||
827 listen_node->loc_addr == 0x00000000) &&
828 (listen_node->loc_port == dst_port) &&
829 (listener_state & listen_node->listener_state)) {
830 atomic_inc(&listen_node->ref_count);
831 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
835 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
837 nes_debug(NES_DBG_CM, "Unable to find listener for %pI4:%x\n",
838 &tmp_addr, dst_port);
846 * add_hte_node - add a cm node to the hash table
848 static int add_hte_node(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
851 struct list_head *hte;
853 if (!cm_node || !cm_core)
856 nes_debug(NES_DBG_CM, "Adding Node %p to Active Connection HT\n",
859 spin_lock_irqsave(&cm_core->ht_lock, flags);
861 /* get a handle on the hash table element (list head for this slot) */
862 hte = &cm_core->connected_nodes;
863 list_add_tail(&cm_node->list, hte);
864 atomic_inc(&cm_core->ht_node_cnt);
866 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
873 * mini_cm_dec_refcnt_listen
875 static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
876 struct nes_cm_listener *listener, int free_hanging_nodes)
880 struct list_head *list_pos = NULL;
881 struct list_head *list_temp = NULL;
882 struct nes_cm_node *cm_node = NULL;
883 struct list_head reset_list;
885 nes_debug(NES_DBG_CM, "attempting listener= %p free_nodes= %d, "
886 "refcnt=%d\n", listener, free_hanging_nodes,
887 atomic_read(&listener->ref_count));
888 /* free non-accelerated child nodes for this listener */
889 INIT_LIST_HEAD(&reset_list);
890 if (free_hanging_nodes) {
891 spin_lock_irqsave(&cm_core->ht_lock, flags);
892 list_for_each_safe(list_pos, list_temp,
893 &g_cm_core->connected_nodes) {
894 cm_node = container_of(list_pos, struct nes_cm_node,
896 if ((cm_node->listener == listener) &&
897 (!cm_node->accelerated)) {
898 add_ref_cm_node(cm_node);
899 list_add(&cm_node->reset_entry, &reset_list);
902 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
905 list_for_each_safe(list_pos, list_temp, &reset_list) {
906 cm_node = container_of(list_pos, struct nes_cm_node,
908 cleanup_retrans_entry(cm_node);
909 send_reset(cm_node, NULL);
910 rem_ref_cm_node(cm_node->cm_core, cm_node);
913 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
914 if (!atomic_dec_return(&listener->ref_count)) {
915 list_del(&listener->list);
917 /* decrement our listen node count */
918 atomic_dec(&cm_core->listen_node_cnt);
920 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
922 if (listener->nesvnic) {
923 nes_manage_apbvt(listener->nesvnic, listener->loc_port,
924 PCI_FUNC(listener->nesvnic->nesdev->pcidev->devfn), NES_MANAGE_APBVT_DEL);
927 nes_debug(NES_DBG_CM, "destroying listener (%p)\n", listener);
932 cm_listens_destroyed++;
934 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
937 if (atomic_read(&listener->pend_accepts_cnt) > 0)
938 nes_debug(NES_DBG_CM, "destroying listener (%p)"
939 " with non-zero pending accepts=%u\n",
940 listener, atomic_read(&listener->pend_accepts_cnt));
950 static int mini_cm_del_listen(struct nes_cm_core *cm_core,
951 struct nes_cm_listener *listener)
953 listener->listener_state = NES_CM_LISTENER_PASSIVE_STATE;
954 listener->cm_id = NULL; /* going to be destroyed pretty soon */
955 return mini_cm_dec_refcnt_listen(cm_core, listener, 1);
960 * mini_cm_accelerated
962 static inline int mini_cm_accelerated(struct nes_cm_core *cm_core,
963 struct nes_cm_node *cm_node)
966 cm_node->accelerated = 1;
968 if (cm_node->accept_pend) {
969 BUG_ON(!cm_node->listener);
970 atomic_dec(&cm_node->listener->pend_accepts_cnt);
971 BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
974 was_timer_set = timer_pending(&cm_core->tcp_timer);
975 if (!was_timer_set) {
976 cm_core->tcp_timer.expires = jiffies + NES_SHORT_TIME;
977 add_timer(&cm_core->tcp_timer);
985 * nes_addr_resolve_neigh
987 static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip)
991 struct neighbour *neigh;
994 memset(&fl, 0, sizeof fl);
995 fl.nl_u.ip4_u.daddr = htonl(dst_ip);
996 if (ip_route_output_key(&init_net, &rt, &fl)) {
997 printk("%s: ip_route_output_key failed for 0x%08X\n",
1002 neigh = neigh_lookup(&arp_tbl, &rt->rt_gateway, nesvnic->netdev);
1004 if (neigh->nud_state & NUD_VALID) {
1005 nes_debug(NES_DBG_CM, "Neighbor MAC address for 0x%08X"
1006 " is %pM, Gateway is 0x%08X \n", dst_ip,
1007 neigh->ha, ntohl(rt->rt_gateway));
1008 nes_manage_arp_cache(nesvnic->netdev, neigh->ha,
1009 dst_ip, NES_ARP_ADD);
1010 rc = nes_arp_table(nesvnic->nesdev, dst_ip, NULL,
1013 neigh_release(neigh);
1016 if ((neigh == NULL) || (!(neigh->nud_state & NUD_VALID)))
1017 neigh_event_send(rt->u.dst.neighbour, NULL);
1025 * make_cm_node - create a new instance of a cm node
1027 static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
1028 struct nes_vnic *nesvnic, struct nes_cm_info *cm_info,
1029 struct nes_cm_listener *listener)
1031 struct nes_cm_node *cm_node;
1034 struct nes_device *nesdev;
1035 struct nes_adapter *nesadapter;
1037 /* create an hte and cm_node for this instance */
1038 cm_node = kzalloc(sizeof(*cm_node), GFP_ATOMIC);
1042 /* set our node specific transport info */
1043 cm_node->loc_addr = cm_info->loc_addr;
1044 cm_node->rem_addr = cm_info->rem_addr;
1045 cm_node->loc_port = cm_info->loc_port;
1046 cm_node->rem_port = cm_info->rem_port;
1047 cm_node->send_write0 = send_first;
1048 nes_debug(NES_DBG_CM, "Make node addresses : loc = %pI4:%x, rem = %pI4:%x\n",
1049 &cm_node->loc_addr, cm_node->loc_port,
1050 &cm_node->rem_addr, cm_node->rem_port);
1051 cm_node->listener = listener;
1052 cm_node->netdev = nesvnic->netdev;
1053 cm_node->cm_id = cm_info->cm_id;
1054 memcpy(cm_node->loc_mac, nesvnic->netdev->dev_addr, ETH_ALEN);
1056 nes_debug(NES_DBG_CM, "listener=%p, cm_id=%p\n", cm_node->listener,
1059 spin_lock_init(&cm_node->retrans_list_lock);
1060 INIT_LIST_HEAD(&cm_node->recv_list);
1061 spin_lock_init(&cm_node->recv_list_lock);
1063 cm_node->loopbackpartner = NULL;
1064 atomic_set(&cm_node->ref_count, 1);
1065 /* associate our parent CM core */
1066 cm_node->cm_core = cm_core;
1067 cm_node->tcp_cntxt.loc_id = NES_CM_DEF_LOCAL_ID;
1068 cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
1069 cm_node->tcp_cntxt.rcv_wnd = NES_CM_DEFAULT_RCV_WND_SCALED >>
1070 NES_CM_DEFAULT_RCV_WND_SCALE;
1071 ts = current_kernel_time();
1072 cm_node->tcp_cntxt.loc_seq_num = htonl(ts.tv_nsec);
1073 cm_node->tcp_cntxt.mss = nesvnic->max_frame_size - sizeof(struct iphdr) -
1074 sizeof(struct tcphdr) - ETH_HLEN - VLAN_HLEN;
1075 cm_node->tcp_cntxt.rcv_nxt = 0;
1076 /* get a unique session ID , add thread_id to an upcounter to handle race */
1077 atomic_inc(&cm_core->node_cnt);
1078 cm_node->conn_type = cm_info->conn_type;
1079 cm_node->apbvt_set = 0;
1080 cm_node->accept_pend = 0;
1082 cm_node->nesvnic = nesvnic;
1083 /* get some device handles, for arp lookup */
1084 nesdev = nesvnic->nesdev;
1085 nesadapter = nesdev->nesadapter;
1087 cm_node->loopbackpartner = NULL;
1088 /* get the mac addr for the remote node */
1089 if (ipv4_is_loopback(htonl(cm_node->rem_addr)))
1090 arpindex = nes_arp_table(nesdev, ntohl(nesvnic->local_ipaddr), NULL, NES_ARP_RESOLVE);
1092 arpindex = nes_arp_table(nesdev, cm_node->rem_addr, NULL, NES_ARP_RESOLVE);
1094 arpindex = nes_addr_resolve_neigh(nesvnic, cm_info->rem_addr);
1101 /* copy the mac addr to node context */
1102 memcpy(cm_node->rem_mac, nesadapter->arp_table[arpindex].mac_addr, ETH_ALEN);
1103 nes_debug(NES_DBG_CM, "Remote mac addr from arp table: %pM\n",
1106 add_hte_node(cm_core, cm_node);
1107 atomic_inc(&cm_nodes_created);
1114 * add_ref_cm_node - destroy an instance of a cm node
1116 static int add_ref_cm_node(struct nes_cm_node *cm_node)
1118 atomic_inc(&cm_node->ref_count);
1124 * rem_ref_cm_node - destroy an instance of a cm node
1126 static int rem_ref_cm_node(struct nes_cm_core *cm_core,
1127 struct nes_cm_node *cm_node)
1129 unsigned long flags, qplockflags;
1130 struct nes_timer_entry *recv_entry;
1131 struct iw_cm_id *cm_id;
1132 struct list_head *list_core, *list_node_temp;
1133 struct nes_qp *nesqp;
1138 spin_lock_irqsave(&cm_node->cm_core->ht_lock, flags);
1139 if (atomic_dec_return(&cm_node->ref_count)) {
1140 spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
1143 list_del(&cm_node->list);
1144 atomic_dec(&cm_core->ht_node_cnt);
1145 spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
1147 /* if the node is destroyed before connection was accelerated */
1148 if (!cm_node->accelerated && cm_node->accept_pend) {
1149 BUG_ON(!cm_node->listener);
1150 atomic_dec(&cm_node->listener->pend_accepts_cnt);
1151 BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
1153 BUG_ON(cm_node->send_entry);
1154 spin_lock_irqsave(&cm_node->recv_list_lock, flags);
1155 list_for_each_safe(list_core, list_node_temp, &cm_node->recv_list) {
1156 recv_entry = container_of(list_core, struct nes_timer_entry,
1158 list_del(&recv_entry->list);
1159 cm_id = cm_node->cm_id;
1160 spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
1161 nesqp = (struct nes_qp *)recv_entry->skb;
1162 spin_lock_irqsave(&nesqp->lock, qplockflags);
1164 nes_debug(NES_DBG_CM, "QP%u: cm_id = %p: HIT A "
1165 "NES_TIMER_TYPE_CLOSE with something to do!\n",
1166 nesqp->hwqp.qp_id, cm_id);
1167 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
1168 nesqp->last_aeq = NES_AEQE_AEID_RESET_SENT;
1169 nesqp->ibqp_state = IB_QPS_ERR;
1170 spin_unlock_irqrestore(&nesqp->lock, qplockflags);
1171 nes_cm_disconn(nesqp);
1173 spin_unlock_irqrestore(&nesqp->lock, qplockflags);
1174 nes_debug(NES_DBG_CM, "QP%u: cm_id = %p: HIT A "
1175 "NES_TIMER_TYPE_CLOSE with nothing to do!\n",
1176 nesqp->hwqp.qp_id, cm_id);
1178 cm_id->rem_ref(cm_id);
1181 spin_lock_irqsave(&cm_node->recv_list_lock, flags);
1183 spin_unlock_irqrestore(&cm_node->recv_list_lock, flags);
1185 if (cm_node->listener) {
1186 mini_cm_dec_refcnt_listen(cm_core, cm_node->listener, 0);
1188 if (cm_node->apbvt_set && cm_node->nesvnic) {
1189 nes_manage_apbvt(cm_node->nesvnic, cm_node->loc_port,
1191 cm_node->nesvnic->nesdev->pcidev->devfn),
1192 NES_MANAGE_APBVT_DEL);
1196 atomic_dec(&cm_core->node_cnt);
1197 atomic_inc(&cm_nodes_destroyed);
1198 nesqp = cm_node->nesqp;
1200 nesqp->cm_node = NULL;
1201 nes_rem_ref(&nesqp->ibqp);
1202 cm_node->nesqp = NULL;
1213 static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
1214 u32 optionsize, u32 syn_packet)
1218 union all_known_options *all_options;
1219 char got_mss_option = 0;
1221 while (offset < optionsize) {
1222 all_options = (union all_known_options *)(optionsloc + offset);
1223 switch (all_options->as_base.optionnum) {
1224 case OPTION_NUMBER_END:
1225 offset = optionsize;
1227 case OPTION_NUMBER_NONE:
1230 case OPTION_NUMBER_MSS:
1231 nes_debug(NES_DBG_CM, "%s: MSS Length: %d Offset: %d "
1232 "Size: %d\n", __func__,
1233 all_options->as_mss.length, offset, optionsize);
1235 if (all_options->as_mss.length != 4) {
1238 tmp = ntohs(all_options->as_mss.mss);
1239 if (tmp > 0 && tmp <
1240 cm_node->tcp_cntxt.mss)
1241 cm_node->tcp_cntxt.mss = tmp;
1244 case OPTION_NUMBER_WINDOW_SCALE:
1245 cm_node->tcp_cntxt.snd_wscale =
1246 all_options->as_windowscale.shiftcount;
1248 case OPTION_NUMBER_WRITE0:
1249 cm_node->send_write0 = 1;
1252 nes_debug(NES_DBG_CM, "TCP Option not understood: %x\n",
1253 all_options->as_base.optionnum);
1256 offset += all_options->as_base.length;
1258 if ((!got_mss_option) && (syn_packet))
1259 cm_node->tcp_cntxt.mss = NES_CM_DEFAULT_MSS;
1263 static void drop_packet(struct sk_buff *skb)
1265 atomic_inc(&cm_accel_dropped_pkts);
1266 dev_kfree_skb_any(skb);
1269 static void handle_fin_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1270 struct tcphdr *tcph)
1272 nes_debug(NES_DBG_CM, "Received FIN, cm_node = %p, state = %u. "
1273 "refcnt=%d\n", cm_node, cm_node->state,
1274 atomic_read(&cm_node->ref_count));
1275 cm_node->tcp_cntxt.rcv_nxt++;
1276 cleanup_retrans_entry(cm_node);
1277 switch (cm_node->state) {
1278 case NES_CM_STATE_SYN_RCVD:
1279 case NES_CM_STATE_SYN_SENT:
1280 case NES_CM_STATE_ESTABLISHED:
1281 case NES_CM_STATE_MPAREQ_SENT:
1282 cm_node->state = NES_CM_STATE_LAST_ACK;
1283 send_fin(cm_node, skb);
1285 case NES_CM_STATE_FIN_WAIT1:
1286 cm_node->state = NES_CM_STATE_CLOSING;
1287 send_ack(cm_node, skb);
1289 case NES_CM_STATE_FIN_WAIT2:
1290 cm_node->state = NES_CM_STATE_TIME_WAIT;
1291 send_ack(cm_node, skb);
1292 cm_node->state = NES_CM_STATE_CLOSED;
1294 case NES_CM_STATE_TSA:
1296 nes_debug(NES_DBG_CM, "Error Rcvd FIN for node-%p state = %d\n",
1297 cm_node, cm_node->state);
1304 static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1305 struct tcphdr *tcph)
1308 int reset = 0; /* whether to send reset in case of err.. */
1310 atomic_inc(&cm_resets_recvd);
1311 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
1312 " refcnt=%d\n", cm_node, cm_node->state,
1313 atomic_read(&cm_node->ref_count));
1314 cleanup_retrans_entry(cm_node);
1315 switch (cm_node->state) {
1316 case NES_CM_STATE_SYN_SENT:
1317 case NES_CM_STATE_MPAREQ_SENT:
1318 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1319 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1320 cm_node->listener, cm_node->state);
1321 active_open_err(cm_node, skb, reset);
1323 case NES_CM_STATE_MPAREQ_RCVD:
1324 passive_state = atomic_add_return(1, &cm_node->passive_state);
1325 if (passive_state == NES_SEND_RESET_EVENT)
1326 create_event(cm_node, NES_CM_EVENT_RESET);
1327 cleanup_retrans_entry(cm_node);
1328 cm_node->state = NES_CM_STATE_CLOSED;
1329 dev_kfree_skb_any(skb);
1331 case NES_CM_STATE_ESTABLISHED:
1332 case NES_CM_STATE_SYN_RCVD:
1333 case NES_CM_STATE_LISTENING:
1334 nes_debug(NES_DBG_CM, "Bad state %s[%u]\n", __func__, __LINE__);
1335 passive_open_err(cm_node, skb, reset);
1337 case NES_CM_STATE_TSA:
1338 active_open_err(cm_node, skb, reset);
1340 case NES_CM_STATE_CLOSED:
1341 cleanup_retrans_entry(cm_node);
1350 static void handle_rcv_mpa(struct nes_cm_node *cm_node, struct sk_buff *skb,
1351 enum nes_cm_event_type type)
1355 int datasize = skb->len;
1356 u8 *dataloc = skb->data;
1357 ret = parse_mpa(cm_node, dataloc, datasize);
1359 nes_debug(NES_DBG_CM, "didn't like MPA Request\n");
1360 if (type == NES_CM_EVENT_CONNECTED) {
1361 nes_debug(NES_DBG_CM, "%s[%u] create abort for "
1362 "cm_node=%p listener=%p state=%d\n", __func__,
1363 __LINE__, cm_node, cm_node->listener,
1365 active_open_err(cm_node, skb, 1);
1367 passive_open_err(cm_node, skb, 1);
1370 cleanup_retrans_entry(cm_node);
1371 dev_kfree_skb_any(skb);
1372 if (type == NES_CM_EVENT_CONNECTED)
1373 cm_node->state = NES_CM_STATE_TSA;
1375 atomic_set(&cm_node->passive_state,
1376 NES_PASSIVE_STATE_INDICATED);
1377 create_event(cm_node, type);
1383 static void indicate_pkt_err(struct nes_cm_node *cm_node, struct sk_buff *skb)
1385 switch (cm_node->state) {
1386 case NES_CM_STATE_SYN_SENT:
1387 case NES_CM_STATE_MPAREQ_SENT:
1388 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1389 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1390 cm_node->listener, cm_node->state);
1391 active_open_err(cm_node, skb, 1);
1393 case NES_CM_STATE_ESTABLISHED:
1394 case NES_CM_STATE_SYN_RCVD:
1395 passive_open_err(cm_node, skb, 1);
1397 case NES_CM_STATE_TSA:
1403 static int check_syn(struct nes_cm_node *cm_node, struct tcphdr *tcph,
1404 struct sk_buff *skb)
1408 err = ((ntohl(tcph->ack_seq) == cm_node->tcp_cntxt.loc_seq_num))? 0 : 1;
1410 active_open_err(cm_node, skb, 1);
1415 static int check_seq(struct nes_cm_node *cm_node, struct tcphdr *tcph,
1416 struct sk_buff *skb)
1421 u32 loc_seq_num = cm_node->tcp_cntxt.loc_seq_num;
1422 u32 rcv_nxt = cm_node->tcp_cntxt.rcv_nxt;
1424 seq = ntohl(tcph->seq);
1425 ack_seq = ntohl(tcph->ack_seq);
1426 rcv_wnd = cm_node->tcp_cntxt.rcv_wnd;
1427 if (ack_seq != loc_seq_num)
1429 else if ((seq + rcv_wnd) < rcv_nxt)
1432 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1433 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1434 cm_node->listener, cm_node->state);
1435 indicate_pkt_err(cm_node, skb);
1436 nes_debug(NES_DBG_CM, "seq ERROR cm_node =%p seq=0x%08X "
1437 "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node, seq, rcv_nxt,
1444 * handle_syn_pkt() is for Passive node. The syn packet is received when a node
1445 * is created with a listener or it may comein as rexmitted packet which in
1446 * that case will be just dropped.
1449 static void handle_syn_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1450 struct tcphdr *tcph)
1456 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
1458 inc_sequence = ntohl(tcph->seq);
1460 switch (cm_node->state) {
1461 case NES_CM_STATE_SYN_SENT:
1462 case NES_CM_STATE_MPAREQ_SENT:
1463 /* Rcvd syn on active open connection*/
1464 active_open_err(cm_node, skb, 1);
1466 case NES_CM_STATE_LISTENING:
1468 cm_node->accept_pend = 1;
1469 atomic_inc(&cm_node->listener->pend_accepts_cnt);
1470 if (atomic_read(&cm_node->listener->pend_accepts_cnt) >
1471 cm_node->listener->backlog) {
1472 nes_debug(NES_DBG_CM, "drop syn due to backlog "
1475 passive_open_err(cm_node, skb, 0);
1478 ret = handle_tcp_options(cm_node, tcph, skb, optionsize,
1481 passive_open_err(cm_node, skb, 0);
1485 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
1486 BUG_ON(cm_node->send_entry);
1487 cm_node->state = NES_CM_STATE_SYN_RCVD;
1488 send_syn(cm_node, 1, skb);
1490 case NES_CM_STATE_CLOSED:
1491 cleanup_retrans_entry(cm_node);
1492 send_reset(cm_node, skb);
1494 case NES_CM_STATE_TSA:
1495 case NES_CM_STATE_ESTABLISHED:
1496 case NES_CM_STATE_FIN_WAIT1:
1497 case NES_CM_STATE_FIN_WAIT2:
1498 case NES_CM_STATE_MPAREQ_RCVD:
1499 case NES_CM_STATE_LAST_ACK:
1500 case NES_CM_STATE_CLOSING:
1501 case NES_CM_STATE_UNKNOWN:
1508 static void handle_synack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1509 struct tcphdr *tcph)
1516 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
1518 inc_sequence = ntohl(tcph->seq);
1519 switch (cm_node->state) {
1520 case NES_CM_STATE_SYN_SENT:
1522 if (check_syn(cm_node, tcph, skb))
1524 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
1526 ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 0);
1528 nes_debug(NES_DBG_CM, "cm_node=%p tcp_options failed\n",
1532 cleanup_retrans_entry(cm_node);
1533 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
1534 send_mpa_request(cm_node, skb);
1535 cm_node->state = NES_CM_STATE_MPAREQ_SENT;
1537 case NES_CM_STATE_MPAREQ_RCVD:
1538 /* passive open, so should not be here */
1539 passive_open_err(cm_node, skb, 1);
1541 case NES_CM_STATE_LISTENING:
1542 case NES_CM_STATE_CLOSED:
1543 cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
1544 cleanup_retrans_entry(cm_node);
1545 send_reset(cm_node, skb);
1547 case NES_CM_STATE_ESTABLISHED:
1548 case NES_CM_STATE_FIN_WAIT1:
1549 case NES_CM_STATE_FIN_WAIT2:
1550 case NES_CM_STATE_LAST_ACK:
1551 case NES_CM_STATE_TSA:
1552 case NES_CM_STATE_CLOSING:
1553 case NES_CM_STATE_UNKNOWN:
1554 case NES_CM_STATE_MPAREQ_SENT:
1561 static void handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1562 struct tcphdr *tcph)
1570 u32 temp_seq = cm_node->tcp_cntxt.loc_seq_num;
1572 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
1573 cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
1575 if (check_seq(cm_node, tcph, skb))
1578 skb_pull(skb, tcph->doff << 2);
1579 inc_sequence = ntohl(tcph->seq);
1580 rem_seq = ntohl(tcph->seq);
1581 rem_seq_ack = ntohl(tcph->ack_seq);
1582 datasize = skb->len;
1584 switch (cm_node->state) {
1585 case NES_CM_STATE_SYN_RCVD:
1587 ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 1);
1590 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
1591 cm_node->tcp_cntxt.loc_seq_num = temp_seq;
1592 if (cm_node->tcp_cntxt.rem_ack_num !=
1593 cm_node->tcp_cntxt.loc_seq_num) {
1594 nes_debug(NES_DBG_CM, "rem_ack_num != loc_seq_num\n");
1595 cleanup_retrans_entry(cm_node);
1596 send_reset(cm_node, skb);
1599 cm_node->state = NES_CM_STATE_ESTABLISHED;
1601 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
1602 cm_node->state = NES_CM_STATE_MPAREQ_RCVD;
1603 handle_rcv_mpa(cm_node, skb, NES_CM_EVENT_MPA_REQ);
1604 } else { /* rcvd ACK only */
1605 dev_kfree_skb_any(skb);
1606 cleanup_retrans_entry(cm_node);
1609 case NES_CM_STATE_ESTABLISHED:
1611 /* We expect mpa frame to be received only */
1613 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
1614 cm_node->state = NES_CM_STATE_MPAREQ_RCVD;
1615 handle_rcv_mpa(cm_node, skb,
1616 NES_CM_EVENT_MPA_REQ);
1620 case NES_CM_STATE_MPAREQ_SENT:
1621 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
1623 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
1624 handle_rcv_mpa(cm_node, skb, NES_CM_EVENT_CONNECTED);
1625 } else { /* Could be just an ack pkt.. */
1626 cleanup_retrans_entry(cm_node);
1627 dev_kfree_skb_any(skb);
1630 case NES_CM_STATE_LISTENING:
1631 case NES_CM_STATE_CLOSED:
1632 cleanup_retrans_entry(cm_node);
1633 send_reset(cm_node, skb);
1635 case NES_CM_STATE_FIN_WAIT1:
1636 case NES_CM_STATE_SYN_SENT:
1637 case NES_CM_STATE_FIN_WAIT2:
1638 case NES_CM_STATE_TSA:
1639 case NES_CM_STATE_MPAREQ_RCVD:
1640 case NES_CM_STATE_LAST_ACK:
1641 case NES_CM_STATE_CLOSING:
1642 case NES_CM_STATE_UNKNOWN:
1651 static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
1652 struct sk_buff *skb, int optionsize, int passive)
1654 u8 *optionsloc = (u8 *)&tcph[1];
1656 if (process_options(cm_node, optionsloc, optionsize,
1658 nes_debug(NES_DBG_CM, "%s: Node %p, Sending RESET\n",
1661 passive_open_err(cm_node, skb, 1);
1663 active_open_err(cm_node, skb, 1);
1668 cm_node->tcp_cntxt.snd_wnd = ntohs(tcph->window) <<
1669 cm_node->tcp_cntxt.snd_wscale;
1671 if (cm_node->tcp_cntxt.snd_wnd > cm_node->tcp_cntxt.max_snd_wnd)
1672 cm_node->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.snd_wnd;
1677 * active_open_err() will send reset() if flag set..
1678 * It will also send ABORT event.
1681 static void active_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
1684 cleanup_retrans_entry(cm_node);
1686 nes_debug(NES_DBG_CM, "ERROR active err called for cm_node=%p, "
1687 "state=%d\n", cm_node, cm_node->state);
1688 add_ref_cm_node(cm_node);
1689 send_reset(cm_node, skb);
1691 dev_kfree_skb_any(skb);
1693 cm_node->state = NES_CM_STATE_CLOSED;
1694 create_event(cm_node, NES_CM_EVENT_ABORTED);
1698 * passive_open_err() will either do a reset() or will free up the skb and
1699 * remove the cm_node.
1702 static void passive_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
1705 cleanup_retrans_entry(cm_node);
1706 cm_node->state = NES_CM_STATE_CLOSED;
1708 nes_debug(NES_DBG_CM, "passive_open_err sending RST for "
1709 "cm_node=%p state =%d\n", cm_node, cm_node->state);
1710 send_reset(cm_node, skb);
1712 dev_kfree_skb_any(skb);
1713 rem_ref_cm_node(cm_node->cm_core, cm_node);
1718 * free_retrans_entry() routines assumes that the retrans_list_lock has
1719 * been acquired before calling.
1721 static void free_retrans_entry(struct nes_cm_node *cm_node)
1723 struct nes_timer_entry *send_entry;
1724 send_entry = cm_node->send_entry;
1726 cm_node->send_entry = NULL;
1727 dev_kfree_skb_any(send_entry->skb);
1729 rem_ref_cm_node(cm_node->cm_core, cm_node);
1733 static void cleanup_retrans_entry(struct nes_cm_node *cm_node)
1735 unsigned long flags;
1737 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
1738 free_retrans_entry(cm_node);
1739 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
1744 * Returns skb if to be freed, else it will return NULL if already used..
1746 static void process_packet(struct nes_cm_node *cm_node, struct sk_buff *skb,
1747 struct nes_cm_core *cm_core)
1749 enum nes_tcpip_pkt_type pkt_type = NES_PKT_TYPE_UNKNOWN;
1750 struct tcphdr *tcph = tcp_hdr(skb);
1751 skb_pull(skb, ip_hdr(skb)->ihl << 2);
1753 nes_debug(NES_DBG_CM, "process_packet: cm_node=%p state =%d syn=%d "
1754 "ack=%d rst=%d fin=%d\n", cm_node, cm_node->state, tcph->syn,
1755 tcph->ack, tcph->rst, tcph->fin);
1758 pkt_type = NES_PKT_TYPE_RST;
1759 else if (tcph->syn) {
1760 pkt_type = NES_PKT_TYPE_SYN;
1762 pkt_type = NES_PKT_TYPE_SYNACK;
1763 } else if (tcph->fin)
1764 pkt_type = NES_PKT_TYPE_FIN;
1766 pkt_type = NES_PKT_TYPE_ACK;
1769 case NES_PKT_TYPE_SYN:
1770 handle_syn_pkt(cm_node, skb, tcph);
1772 case NES_PKT_TYPE_SYNACK:
1773 handle_synack_pkt(cm_node, skb, tcph);
1775 case NES_PKT_TYPE_ACK:
1776 handle_ack_pkt(cm_node, skb, tcph);
1778 case NES_PKT_TYPE_RST:
1779 handle_rst_pkt(cm_node, skb, tcph);
1781 case NES_PKT_TYPE_FIN:
1782 handle_fin_pkt(cm_node, skb, tcph);
1791 * mini_cm_listen - create a listen node with params
1793 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *cm_core,
1794 struct nes_vnic *nesvnic, struct nes_cm_info *cm_info)
1796 struct nes_cm_listener *listener;
1797 unsigned long flags;
1799 nes_debug(NES_DBG_CM, "Search for 0x%08x : 0x%04x\n",
1800 cm_info->loc_addr, cm_info->loc_port);
1802 /* cannot have multiple matching listeners */
1803 listener = find_listener(cm_core, htonl(cm_info->loc_addr),
1804 htons(cm_info->loc_port), NES_CM_LISTENER_EITHER_STATE);
1805 if (listener && listener->listener_state == NES_CM_LISTENER_ACTIVE_STATE) {
1806 /* find automatically incs ref count ??? */
1807 atomic_dec(&listener->ref_count);
1808 nes_debug(NES_DBG_CM, "Not creating listener since it already exists\n");
1813 /* create a CM listen node (1/2 node to compare incoming traffic to) */
1814 listener = kzalloc(sizeof(*listener), GFP_ATOMIC);
1816 nes_debug(NES_DBG_CM, "Not creating listener memory allocation failed\n");
1820 listener->loc_addr = htonl(cm_info->loc_addr);
1821 listener->loc_port = htons(cm_info->loc_port);
1822 listener->reused_node = 0;
1824 atomic_set(&listener->ref_count, 1);
1827 /* find already inc'ed the ref count */
1829 listener->reused_node = 1;
1832 listener->cm_id = cm_info->cm_id;
1833 atomic_set(&listener->pend_accepts_cnt, 0);
1834 listener->cm_core = cm_core;
1835 listener->nesvnic = nesvnic;
1836 atomic_inc(&cm_core->node_cnt);
1838 listener->conn_type = cm_info->conn_type;
1839 listener->backlog = cm_info->backlog;
1840 listener->listener_state = NES_CM_LISTENER_ACTIVE_STATE;
1842 if (!listener->reused_node) {
1843 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
1844 list_add(&listener->list, &cm_core->listen_list.list);
1845 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
1846 atomic_inc(&cm_core->listen_node_cnt);
1849 nes_debug(NES_DBG_CM, "Api - listen(): addr=0x%08X, port=0x%04x,"
1850 " listener = %p, backlog = %d, cm_id = %p.\n",
1851 cm_info->loc_addr, cm_info->loc_port,
1852 listener, listener->backlog, listener->cm_id);
1859 * mini_cm_connect - make a connection node with params
1861 static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
1862 struct nes_vnic *nesvnic, u16 private_data_len,
1863 void *private_data, struct nes_cm_info *cm_info)
1866 struct nes_cm_node *cm_node;
1867 struct nes_cm_listener *loopbackremotelistener;
1868 struct nes_cm_node *loopbackremotenode;
1869 struct nes_cm_info loopback_cm_info;
1870 u16 mpa_frame_size = sizeof(struct ietf_mpa_frame) + private_data_len;
1871 struct ietf_mpa_frame *mpa_frame = NULL;
1873 /* create a CM connection node */
1874 cm_node = make_cm_node(cm_core, nesvnic, cm_info, NULL);
1877 mpa_frame = &cm_node->mpa_frame;
1878 strcpy(mpa_frame->key, IEFT_MPA_KEY_REQ);
1879 mpa_frame->flags = IETF_MPA_FLAGS_CRC;
1880 mpa_frame->rev = IETF_MPA_VERSION;
1881 mpa_frame->priv_data_len = htons(private_data_len);
1883 /* set our node side to client (active) side */
1884 cm_node->tcp_cntxt.client = 1;
1885 cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
1887 if (cm_info->loc_addr == cm_info->rem_addr) {
1888 loopbackremotelistener = find_listener(cm_core,
1889 ntohl(nesvnic->local_ipaddr), cm_node->rem_port,
1890 NES_CM_LISTENER_ACTIVE_STATE);
1891 if (loopbackremotelistener == NULL) {
1892 create_event(cm_node, NES_CM_EVENT_ABORTED);
1894 atomic_inc(&cm_loopbacks);
1895 loopback_cm_info = *cm_info;
1896 loopback_cm_info.loc_port = cm_info->rem_port;
1897 loopback_cm_info.rem_port = cm_info->loc_port;
1898 loopback_cm_info.cm_id = loopbackremotelistener->cm_id;
1899 loopbackremotenode = make_cm_node(cm_core, nesvnic,
1900 &loopback_cm_info, loopbackremotelistener);
1901 loopbackremotenode->loopbackpartner = cm_node;
1902 loopbackremotenode->tcp_cntxt.rcv_wscale =
1903 NES_CM_DEFAULT_RCV_WND_SCALE;
1904 cm_node->loopbackpartner = loopbackremotenode;
1905 memcpy(loopbackremotenode->mpa_frame_buf, private_data,
1907 loopbackremotenode->mpa_frame_size = private_data_len;
1909 /* we are done handling this state. */
1910 /* set node to a TSA state */
1911 cm_node->state = NES_CM_STATE_TSA;
1912 cm_node->tcp_cntxt.rcv_nxt =
1913 loopbackremotenode->tcp_cntxt.loc_seq_num;
1914 loopbackremotenode->tcp_cntxt.rcv_nxt =
1915 cm_node->tcp_cntxt.loc_seq_num;
1916 cm_node->tcp_cntxt.max_snd_wnd =
1917 loopbackremotenode->tcp_cntxt.rcv_wnd;
1918 loopbackremotenode->tcp_cntxt.max_snd_wnd =
1919 cm_node->tcp_cntxt.rcv_wnd;
1920 cm_node->tcp_cntxt.snd_wnd =
1921 loopbackremotenode->tcp_cntxt.rcv_wnd;
1922 loopbackremotenode->tcp_cntxt.snd_wnd =
1923 cm_node->tcp_cntxt.rcv_wnd;
1924 cm_node->tcp_cntxt.snd_wscale =
1925 loopbackremotenode->tcp_cntxt.rcv_wscale;
1926 loopbackremotenode->tcp_cntxt.snd_wscale =
1927 cm_node->tcp_cntxt.rcv_wscale;
1929 create_event(loopbackremotenode, NES_CM_EVENT_MPA_REQ);
1934 /* set our node side to client (active) side */
1935 cm_node->tcp_cntxt.client = 1;
1936 /* init our MPA frame ptr */
1937 memcpy(mpa_frame->priv_data, private_data, private_data_len);
1939 cm_node->mpa_frame_size = mpa_frame_size;
1941 /* send a syn and goto syn sent state */
1942 cm_node->state = NES_CM_STATE_SYN_SENT;
1943 ret = send_syn(cm_node, 0, NULL);
1946 /* error in sending the syn free up the cm_node struct */
1947 nes_debug(NES_DBG_CM, "Api - connect() FAILED: dest "
1948 "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
1949 cm_node->rem_addr, cm_node->rem_port, cm_node,
1951 rem_ref_cm_node(cm_node->cm_core, cm_node);
1956 nes_debug(NES_DBG_CM, "Api - connect(): dest addr=0x%08X,"
1957 "port=0x%04x, cm_node=%p, cm_id = %p.\n",
1958 cm_node->rem_addr, cm_node->rem_port, cm_node,
1966 * mini_cm_accept - accept a connection
1967 * This function is never called
1969 static int mini_cm_accept(struct nes_cm_core *cm_core,
1970 struct ietf_mpa_frame *mpa_frame, struct nes_cm_node *cm_node)
1977 * mini_cm_reject - reject and teardown a connection
1979 static int mini_cm_reject(struct nes_cm_core *cm_core,
1980 struct ietf_mpa_frame *mpa_frame, struct nes_cm_node *cm_node)
1985 nes_debug(NES_DBG_CM, "%s cm_node=%p type=%d state=%d\n",
1986 __func__, cm_node, cm_node->tcp_cntxt.client, cm_node->state);
1988 if (cm_node->tcp_cntxt.client)
1990 cleanup_retrans_entry(cm_node);
1992 passive_state = atomic_add_return(1, &cm_node->passive_state);
1993 cm_node->state = NES_CM_STATE_CLOSED;
1994 if (passive_state == NES_SEND_RESET_EVENT)
1995 rem_ref_cm_node(cm_core, cm_node);
1997 ret = send_reset(cm_node, NULL);
2005 static int mini_cm_close(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
2009 if (!cm_core || !cm_node)
2012 switch (cm_node->state) {
2013 case NES_CM_STATE_SYN_RCVD:
2014 case NES_CM_STATE_SYN_SENT:
2015 case NES_CM_STATE_ONE_SIDE_ESTABLISHED:
2016 case NES_CM_STATE_ESTABLISHED:
2017 case NES_CM_STATE_ACCEPTING:
2018 case NES_CM_STATE_MPAREQ_SENT:
2019 case NES_CM_STATE_MPAREQ_RCVD:
2020 cleanup_retrans_entry(cm_node);
2021 send_reset(cm_node, NULL);
2023 case NES_CM_STATE_CLOSE_WAIT:
2024 cm_node->state = NES_CM_STATE_LAST_ACK;
2025 send_fin(cm_node, NULL);
2027 case NES_CM_STATE_FIN_WAIT1:
2028 case NES_CM_STATE_FIN_WAIT2:
2029 case NES_CM_STATE_LAST_ACK:
2030 case NES_CM_STATE_TIME_WAIT:
2031 case NES_CM_STATE_CLOSING:
2034 case NES_CM_STATE_LISTENING:
2035 case NES_CM_STATE_UNKNOWN:
2036 case NES_CM_STATE_INITED:
2037 case NES_CM_STATE_CLOSED:
2038 ret = rem_ref_cm_node(cm_core, cm_node);
2040 case NES_CM_STATE_TSA:
2041 if (cm_node->send_entry)
2042 printk(KERN_ERR "ERROR Close got called from STATE_TSA "
2043 "send_entry=%p\n", cm_node->send_entry);
2044 ret = rem_ref_cm_node(cm_core, cm_node);
2052 * recv_pkt - recv an ETHERNET packet, and process it through CM
2053 * node state machine
2055 static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
2056 struct nes_vnic *nesvnic, struct sk_buff *skb)
2058 struct nes_cm_node *cm_node = NULL;
2059 struct nes_cm_listener *listener = NULL;
2061 struct tcphdr *tcph;
2062 struct nes_cm_info nfo;
2063 int skb_handled = 1;
2064 __be32 tmp_daddr, tmp_saddr;
2068 if (skb->len < sizeof(struct iphdr) + sizeof(struct tcphdr)) {
2072 iph = (struct iphdr *)skb->data;
2073 tcph = (struct tcphdr *)(skb->data + sizeof(struct iphdr));
2075 nfo.loc_addr = ntohl(iph->daddr);
2076 nfo.loc_port = ntohs(tcph->dest);
2077 nfo.rem_addr = ntohl(iph->saddr);
2078 nfo.rem_port = ntohs(tcph->source);
2080 tmp_daddr = cpu_to_be32(iph->daddr);
2081 tmp_saddr = cpu_to_be32(iph->saddr);
2083 nes_debug(NES_DBG_CM, "Received packet: dest=%pI4:0x%04X src=%pI4:0x%04X\n",
2084 &tmp_daddr, tcph->dest, &tmp_saddr, tcph->source);
2087 cm_node = find_node(cm_core,
2088 nfo.rem_port, nfo.rem_addr,
2089 nfo.loc_port, nfo.loc_addr);
2092 /* Only type of packet accepted are for */
2093 /* the PASSIVE open (syn only) */
2094 if ((!tcph->syn) || (tcph->ack)) {
2098 listener = find_listener(cm_core, nfo.loc_addr,
2100 NES_CM_LISTENER_ACTIVE_STATE);
2104 nes_debug(NES_DBG_CM, "Unable to find listener for the pkt\n");
2108 nfo.cm_id = listener->cm_id;
2109 nfo.conn_type = listener->conn_type;
2110 cm_node = make_cm_node(cm_core, nesvnic, &nfo,
2113 nes_debug(NES_DBG_CM, "Unable to allocate "
2115 cm_packets_dropped++;
2116 atomic_dec(&listener->ref_count);
2117 dev_kfree_skb_any(skb);
2120 if (!tcph->rst && !tcph->fin) {
2121 cm_node->state = NES_CM_STATE_LISTENING;
2123 cm_packets_dropped++;
2124 rem_ref_cm_node(cm_core, cm_node);
2125 dev_kfree_skb_any(skb);
2128 add_ref_cm_node(cm_node);
2129 } else if (cm_node->state == NES_CM_STATE_TSA) {
2130 rem_ref_cm_node(cm_core, cm_node);
2131 atomic_inc(&cm_accel_dropped_pkts);
2132 dev_kfree_skb_any(skb);
2135 skb_reset_network_header(skb);
2136 skb_set_transport_header(skb, sizeof(*tcph));
2137 skb->len = ntohs(iph->tot_len);
2138 process_packet(cm_node, skb, cm_core);
2139 rem_ref_cm_node(cm_core, cm_node);
2146 * nes_cm_alloc_core - allocate a top level instance of a cm core
2148 static struct nes_cm_core *nes_cm_alloc_core(void)
2150 struct nes_cm_core *cm_core;
2152 /* setup the CM core */
2153 /* alloc top level core control structure */
2154 cm_core = kzalloc(sizeof(*cm_core), GFP_KERNEL);
2158 INIT_LIST_HEAD(&cm_core->connected_nodes);
2159 init_timer(&cm_core->tcp_timer);
2160 cm_core->tcp_timer.function = nes_cm_timer_tick;
2162 cm_core->mtu = NES_CM_DEFAULT_MTU;
2163 cm_core->state = NES_CM_STATE_INITED;
2164 cm_core->free_tx_pkt_max = NES_CM_DEFAULT_FREE_PKTS;
2166 atomic_set(&cm_core->events_posted, 0);
2168 cm_core->api = &nes_cm_api;
2170 spin_lock_init(&cm_core->ht_lock);
2171 spin_lock_init(&cm_core->listen_list_lock);
2173 INIT_LIST_HEAD(&cm_core->listen_list.list);
2175 nes_debug(NES_DBG_CM, "Init CM Core completed -- cm_core=%p\n", cm_core);
2177 nes_debug(NES_DBG_CM, "Enable QUEUE EVENTS\n");
2178 cm_core->event_wq = create_singlethread_workqueue("nesewq");
2179 cm_core->post_event = nes_cm_post_event;
2180 nes_debug(NES_DBG_CM, "Enable QUEUE DISCONNECTS\n");
2181 cm_core->disconn_wq = create_singlethread_workqueue("nesdwq");
2183 print_core(cm_core);
2189 * mini_cm_dealloc_core - deallocate a top level instance of a cm core
2191 static int mini_cm_dealloc_core(struct nes_cm_core *cm_core)
2193 nes_debug(NES_DBG_CM, "De-Alloc CM Core (%p)\n", cm_core);
2200 if (timer_pending(&cm_core->tcp_timer)) {
2201 del_timer(&cm_core->tcp_timer);
2204 destroy_workqueue(cm_core->event_wq);
2205 destroy_workqueue(cm_core->disconn_wq);
2206 nes_debug(NES_DBG_CM, "\n");
2216 static int mini_cm_get(struct nes_cm_core *cm_core)
2218 return cm_core->state;
2225 static int mini_cm_set(struct nes_cm_core *cm_core, u32 type, u32 value)
2230 case NES_CM_SET_PKT_SIZE:
2231 cm_core->mtu = value;
2233 case NES_CM_SET_FREE_PKT_Q_SIZE:
2234 cm_core->free_tx_pkt_max = value;
2237 /* unknown set option */
2246 * nes_cm_init_tsa_conn setup HW; MPA frames must be
2247 * successfully exchanged when this is called
2249 static int nes_cm_init_tsa_conn(struct nes_qp *nesqp, struct nes_cm_node *cm_node)
2256 nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4 |
2257 NES_QPCONTEXT_MISC_NO_NAGLE | NES_QPCONTEXT_MISC_DO_NOT_FRAG |
2258 NES_QPCONTEXT_MISC_DROS);
2260 if (cm_node->tcp_cntxt.snd_wscale || cm_node->tcp_cntxt.rcv_wscale)
2261 nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE);
2263 nesqp->nesqp_context->misc2 |= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT);
2265 nesqp->nesqp_context->mss |= cpu_to_le32(((u32)cm_node->tcp_cntxt.mss) << 16);
2267 nesqp->nesqp_context->tcp_state_flow_label |= cpu_to_le32(
2268 (u32)NES_QPCONTEXT_TCPSTATE_EST << NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT);
2270 nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
2271 (cm_node->tcp_cntxt.snd_wscale << NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT) &
2272 NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK);
2274 nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
2275 (cm_node->tcp_cntxt.rcv_wscale << NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT) &
2276 NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK);
2278 nesqp->nesqp_context->keepalive = cpu_to_le32(0x80);
2279 nesqp->nesqp_context->ts_recent = 0;
2280 nesqp->nesqp_context->ts_age = 0;
2281 nesqp->nesqp_context->snd_nxt = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2282 nesqp->nesqp_context->snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.snd_wnd);
2283 nesqp->nesqp_context->rcv_nxt = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
2284 nesqp->nesqp_context->rcv_wnd = cpu_to_le32(cm_node->tcp_cntxt.rcv_wnd <<
2285 cm_node->tcp_cntxt.rcv_wscale);
2286 nesqp->nesqp_context->snd_max = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2287 nesqp->nesqp_context->snd_una = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2288 nesqp->nesqp_context->srtt = 0;
2289 nesqp->nesqp_context->rttvar = cpu_to_le32(0x6);
2290 nesqp->nesqp_context->ssthresh = cpu_to_le32(0x3FFFC000);
2291 nesqp->nesqp_context->cwnd = cpu_to_le32(2*cm_node->tcp_cntxt.mss);
2292 nesqp->nesqp_context->snd_wl1 = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
2293 nesqp->nesqp_context->snd_wl2 = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2294 nesqp->nesqp_context->max_snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.max_snd_wnd);
2296 nes_debug(NES_DBG_CM, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
2297 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
2298 nesqp->hwqp.qp_id, le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
2299 le32_to_cpu(nesqp->nesqp_context->snd_nxt),
2300 cm_node->tcp_cntxt.mss, le32_to_cpu(nesqp->nesqp_context->pd_index_wscale),
2301 le32_to_cpu(nesqp->nesqp_context->rcv_wnd),
2302 le32_to_cpu(nesqp->nesqp_context->misc));
2303 nes_debug(NES_DBG_CM, " snd_wnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->snd_wnd));
2304 nes_debug(NES_DBG_CM, " snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->cwnd));
2305 nes_debug(NES_DBG_CM, " max_swnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->max_snd_wnd));
2307 nes_debug(NES_DBG_CM, "Change cm_node state to TSA\n");
2308 cm_node->state = NES_CM_STATE_TSA;
2317 int nes_cm_disconn(struct nes_qp *nesqp)
2319 unsigned long flags;
2321 spin_lock_irqsave(&nesqp->lock, flags);
2322 if (nesqp->disconn_pending == 0) {
2323 nesqp->disconn_pending++;
2324 spin_unlock_irqrestore(&nesqp->lock, flags);
2325 /* init our disconnect work element, to */
2326 INIT_WORK(&nesqp->disconn_work, nes_disconnect_worker);
2328 queue_work(g_cm_core->disconn_wq, &nesqp->disconn_work);
2330 spin_unlock_irqrestore(&nesqp->lock, flags);
2337 * nes_disconnect_worker
2339 static void nes_disconnect_worker(struct work_struct *work)
2341 struct nes_qp *nesqp = container_of(work, struct nes_qp, disconn_work);
2343 nes_debug(NES_DBG_CM, "processing AEQE id 0x%04X for QP%u.\n",
2344 nesqp->last_aeq, nesqp->hwqp.qp_id);
2345 nes_cm_disconn_true(nesqp);
2350 * nes_cm_disconn_true
2352 static int nes_cm_disconn_true(struct nes_qp *nesqp)
2354 unsigned long flags;
2356 struct iw_cm_id *cm_id;
2357 struct iw_cm_event cm_event;
2358 struct nes_vnic *nesvnic;
2360 u8 original_hw_tcp_state;
2361 u8 original_ibqp_state;
2362 u8 issued_disconnect_reset = 0;
2365 nes_debug(NES_DBG_CM, "disconnect_worker nesqp is NULL\n");
2369 spin_lock_irqsave(&nesqp->lock, flags);
2370 cm_id = nesqp->cm_id;
2371 /* make sure we havent already closed this connection */
2373 nes_debug(NES_DBG_CM, "QP%u disconnect_worker cmid is NULL\n",
2375 spin_unlock_irqrestore(&nesqp->lock, flags);
2379 nesvnic = to_nesvnic(nesqp->ibqp.device);
2380 nes_debug(NES_DBG_CM, "Disconnecting QP%u\n", nesqp->hwqp.qp_id);
2382 original_hw_tcp_state = nesqp->hw_tcp_state;
2383 original_ibqp_state = nesqp->ibqp_state;
2384 last_ae = nesqp->last_aeq;
2387 nes_debug(NES_DBG_CM, "set ibqp_state=%u\n", nesqp->ibqp_state);
2389 if ((nesqp->cm_id) && (cm_id->event_handler)) {
2390 if ((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2391 ((original_ibqp_state == IB_QPS_RTS) &&
2392 (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2393 atomic_inc(&cm_disconnects);
2394 cm_event.event = IW_CM_EVENT_DISCONNECT;
2395 if (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET) {
2396 cm_event.status = IW_CM_EVENT_STATUS_RESET;
2397 nes_debug(NES_DBG_CM, "Generating a CM "
2398 "Disconnect Event (status reset) for "
2399 "QP%u, cm_id = %p. \n",
2400 nesqp->hwqp.qp_id, cm_id);
2402 cm_event.status = IW_CM_EVENT_STATUS_OK;
2404 cm_event.local_addr = cm_id->local_addr;
2405 cm_event.remote_addr = cm_id->remote_addr;
2406 cm_event.private_data = NULL;
2407 cm_event.private_data_len = 0;
2409 nes_debug(NES_DBG_CM, "Generating a CM Disconnect Event"
2410 " for QP%u, SQ Head = %u, SQ Tail = %u. "
2411 "cm_id = %p, refcount = %u.\n",
2412 nesqp->hwqp.qp_id, nesqp->hwqp.sq_head,
2413 nesqp->hwqp.sq_tail, cm_id,
2414 atomic_read(&nesqp->refcount));
2416 spin_unlock_irqrestore(&nesqp->lock, flags);
2417 ret = cm_id->event_handler(cm_id, &cm_event);
2419 nes_debug(NES_DBG_CM, "OFA CM event_handler "
2420 "returned, ret=%d\n", ret);
2421 spin_lock_irqsave(&nesqp->lock, flags);
2424 nesqp->disconn_pending = 0;
2425 /* There might have been another AE while the lock was released */
2426 original_hw_tcp_state = nesqp->hw_tcp_state;
2427 original_ibqp_state = nesqp->ibqp_state;
2428 last_ae = nesqp->last_aeq;
2430 if ((issued_disconnect_reset == 0) && (nesqp->cm_id) &&
2431 ((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
2432 (original_hw_tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT) ||
2433 (last_ae == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) ||
2434 (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2435 atomic_inc(&cm_closes);
2436 nesqp->cm_id = NULL;
2437 nesqp->in_disconnect = 0;
2438 spin_unlock_irqrestore(&nesqp->lock, flags);
2439 nes_disconnect(nesqp, 1);
2441 cm_id->provider_data = nesqp;
2442 /* Send up the close complete event */
2443 cm_event.event = IW_CM_EVENT_CLOSE;
2444 cm_event.status = IW_CM_EVENT_STATUS_OK;
2445 cm_event.provider_data = cm_id->provider_data;
2446 cm_event.local_addr = cm_id->local_addr;
2447 cm_event.remote_addr = cm_id->remote_addr;
2448 cm_event.private_data = NULL;
2449 cm_event.private_data_len = 0;
2451 ret = cm_id->event_handler(cm_id, &cm_event);
2453 nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
2456 cm_id->rem_ref(cm_id);
2458 spin_lock_irqsave(&nesqp->lock, flags);
2459 if (nesqp->flush_issued == 0) {
2460 nesqp->flush_issued = 1;
2461 spin_unlock_irqrestore(&nesqp->lock, flags);
2462 flush_wqes(nesvnic->nesdev, nesqp,
2463 NES_CQP_FLUSH_RQ, 1);
2465 spin_unlock_irqrestore(&nesqp->lock, flags);
2467 cm_id = nesqp->cm_id;
2468 spin_unlock_irqrestore(&nesqp->lock, flags);
2469 /* check to see if the inbound reset beat the outbound reset */
2470 if ((!cm_id) && (last_ae==NES_AEQE_AEID_RESET_SENT)) {
2471 nes_debug(NES_DBG_CM, "QP%u: Decing refcount "
2472 "due to inbound reset beating the "
2473 "outbound reset.\n", nesqp->hwqp.qp_id);
2477 nesqp->disconn_pending = 0;
2478 spin_unlock_irqrestore(&nesqp->lock, flags);
2488 static int nes_disconnect(struct nes_qp *nesqp, int abrupt)
2491 struct nes_vnic *nesvnic;
2492 struct nes_device *nesdev;
2494 nesvnic = to_nesvnic(nesqp->ibqp.device);
2498 nesdev = nesvnic->nesdev;
2500 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
2501 atomic_read(&nesvnic->netdev->refcnt));
2503 if (nesqp->active_conn) {
2505 /* indicate this connection is NOT active */
2506 nesqp->active_conn = 0;
2508 /* Need to free the Last Streaming Mode Message */
2509 if (nesqp->ietf_frame) {
2510 pci_free_consistent(nesdev->pcidev,
2511 nesqp->private_data_len+sizeof(struct ietf_mpa_frame),
2512 nesqp->ietf_frame, nesqp->ietf_frame_pbase);
2516 /* close the CM node down if it is still active */
2517 if (nesqp->cm_node) {
2518 nes_debug(NES_DBG_CM, "Call close API\n");
2520 g_cm_core->api->close(g_cm_core, nesqp->cm_node);
2530 int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2534 struct nes_qp *nesqp;
2535 struct nes_vnic *nesvnic;
2536 struct nes_device *nesdev;
2537 struct nes_cm_node *cm_node;
2538 struct nes_adapter *adapter;
2539 struct ib_qp_attr attr;
2540 struct iw_cm_event cm_event;
2541 struct nes_hw_qp_wqe *wqe;
2542 struct nes_v4_quad nes_quad;
2547 ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
2551 /* get all our handles */
2552 nesqp = to_nesqp(ibqp);
2553 nesvnic = to_nesvnic(nesqp->ibqp.device);
2554 nesdev = nesvnic->nesdev;
2555 adapter = nesdev->nesadapter;
2557 cm_node = (struct nes_cm_node *)cm_id->provider_data;
2558 nes_debug(NES_DBG_CM, "nes_accept: cm_node= %p nesvnic=%p, netdev=%p,"
2559 "%s\n", cm_node, nesvnic, nesvnic->netdev,
2560 nesvnic->netdev->name);
2562 /* associate the node with the QP */
2563 nesqp->cm_node = (void *)cm_node;
2564 cm_node->nesqp = nesqp;
2565 nes_add_ref(&nesqp->ibqp);
2567 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
2568 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
2569 atomic_inc(&cm_accepts);
2571 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
2572 atomic_read(&nesvnic->netdev->refcnt));
2574 /* allocate the ietf frame and space for private data */
2575 nesqp->ietf_frame = pci_alloc_consistent(nesdev->pcidev,
2576 sizeof(struct ietf_mpa_frame) + conn_param->private_data_len,
2577 &nesqp->ietf_frame_pbase);
2579 if (!nesqp->ietf_frame) {
2580 nes_debug(NES_DBG_CM, "Unable to allocate memory for private "
2586 /* setup the MPA frame */
2587 nesqp->private_data_len = conn_param->private_data_len;
2588 memcpy(nesqp->ietf_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
2590 memcpy(nesqp->ietf_frame->priv_data, conn_param->private_data,
2591 conn_param->private_data_len);
2593 nesqp->ietf_frame->priv_data_len =
2594 cpu_to_be16(conn_param->private_data_len);
2595 nesqp->ietf_frame->rev = mpa_version;
2596 nesqp->ietf_frame->flags = IETF_MPA_FLAGS_CRC;
2598 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
2599 wqe = &nesqp->hwqp.sq_vbase[0];
2601 if (cm_id->remote_addr.sin_addr.s_addr !=
2602 cm_id->local_addr.sin_addr.s_addr) {
2603 u64temp = (unsigned long)nesqp;
2604 u64temp |= NES_SW_CONTEXT_ALIGN>>1;
2605 set_wqe_64bit_value(wqe->wqe_words,
2606 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX,
2608 wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
2609 cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING |
2610 NES_IWARP_SQ_WQE_WRPDU);
2611 wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] =
2612 cpu_to_le32(conn_param->private_data_len +
2613 sizeof(struct ietf_mpa_frame));
2614 wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX] =
2615 cpu_to_le32((u32)nesqp->ietf_frame_pbase);
2616 wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX] =
2617 cpu_to_le32((u32)((u64)nesqp->ietf_frame_pbase >> 32));
2618 wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] =
2619 cpu_to_le32(conn_param->private_data_len +
2620 sizeof(struct ietf_mpa_frame));
2621 wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 0;
2623 nesqp->nesqp_context->ird_ord_sizes |=
2624 cpu_to_le32(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
2625 NES_QPCONTEXT_ORDIRD_WRPDU);
2627 nesqp->nesqp_context->ird_ord_sizes |=
2628 cpu_to_le32((NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
2629 NES_QPCONTEXT_ORDIRD_WRPDU |
2630 NES_QPCONTEXT_ORDIRD_ALSMM));
2632 nesqp->skip_lsmm = 1;
2635 /* Cache the cm_id in the qp */
2636 nesqp->cm_id = cm_id;
2637 cm_node->cm_id = cm_id;
2639 /* nesqp->cm_node = (void *)cm_id->provider_data; */
2640 cm_id->provider_data = nesqp;
2641 nesqp->active_conn = 0;
2643 if (cm_node->state == NES_CM_STATE_TSA)
2644 nes_debug(NES_DBG_CM, "Already state = TSA for cm_node=%p\n",
2647 nes_cm_init_tsa_conn(nesqp, cm_node);
2649 nesqp->nesqp_context->tcpPorts[0] =
2650 cpu_to_le16(ntohs(cm_id->local_addr.sin_port));
2651 nesqp->nesqp_context->tcpPorts[1] =
2652 cpu_to_le16(ntohs(cm_id->remote_addr.sin_port));
2654 if (ipv4_is_loopback(cm_id->remote_addr.sin_addr.s_addr))
2655 nesqp->nesqp_context->ip0 =
2656 cpu_to_le32(ntohl(nesvnic->local_ipaddr));
2658 nesqp->nesqp_context->ip0 =
2659 cpu_to_le32(ntohl(cm_id->remote_addr.sin_addr.s_addr));
2661 nesqp->nesqp_context->misc2 |= cpu_to_le32(
2662 (u32)PCI_FUNC(nesdev->pcidev->devfn) <<
2663 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
2665 nesqp->nesqp_context->arp_index_vlan |=
2666 cpu_to_le32(nes_arp_table(nesdev,
2667 le32_to_cpu(nesqp->nesqp_context->ip0), NULL,
2668 NES_ARP_RESOLVE) << 16);
2670 nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
2671 jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
2673 nesqp->nesqp_context->ird_index = cpu_to_le32(nesqp->hwqp.qp_id);
2675 nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32(
2676 ((u32)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT));
2677 nesqp->nesqp_context->ird_ord_sizes |=
2678 cpu_to_le32((u32)conn_param->ord);
2680 memset(&nes_quad, 0, sizeof(nes_quad));
2681 nes_quad.DstIpAdrIndex =
2682 cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
2683 if (ipv4_is_loopback(cm_id->remote_addr.sin_addr.s_addr))
2684 nes_quad.SrcIpadr = nesvnic->local_ipaddr;
2686 nes_quad.SrcIpadr = cm_id->remote_addr.sin_addr.s_addr;
2687 nes_quad.TcpPorts[0] = cm_id->remote_addr.sin_port;
2688 nes_quad.TcpPorts[1] = cm_id->local_addr.sin_port;
2690 /* Produce hash key */
2691 crc_value = get_crc_value(&nes_quad);
2692 nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
2693 nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, CRC = 0x%08X\n",
2694 nesqp->hte_index, nesqp->hte_index & adapter->hte_index_mask);
2696 nesqp->hte_index &= adapter->hte_index_mask;
2697 nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
2699 cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
2701 nes_debug(NES_DBG_CM, "QP%u, Destination IP = 0x%08X:0x%04X, local = "
2702 "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
2703 "private data length=%zu.\n", nesqp->hwqp.qp_id,
2704 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2705 ntohs(cm_id->remote_addr.sin_port),
2706 ntohl(cm_id->local_addr.sin_addr.s_addr),
2707 ntohs(cm_id->local_addr.sin_port),
2708 le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
2709 le32_to_cpu(nesqp->nesqp_context->snd_nxt),
2710 conn_param->private_data_len +
2711 sizeof(struct ietf_mpa_frame));
2714 /* notify OF layer that accept event was successful */
2715 cm_id->add_ref(cm_id);
2717 cm_event.event = IW_CM_EVENT_ESTABLISHED;
2718 cm_event.status = IW_CM_EVENT_STATUS_ACCEPTED;
2719 cm_event.provider_data = (void *)nesqp;
2720 cm_event.local_addr = cm_id->local_addr;
2721 cm_event.remote_addr = cm_id->remote_addr;
2722 cm_event.private_data = NULL;
2723 cm_event.private_data_len = 0;
2724 ret = cm_id->event_handler(cm_id, &cm_event);
2725 attr.qp_state = IB_QPS_RTS;
2726 nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
2727 if (cm_node->loopbackpartner) {
2728 cm_node->loopbackpartner->mpa_frame_size =
2729 nesqp->private_data_len;
2730 /* copy entire MPA frame to our cm_node's frame */
2731 memcpy(cm_node->loopbackpartner->mpa_frame_buf,
2732 nesqp->ietf_frame->priv_data, nesqp->private_data_len);
2733 create_event(cm_node->loopbackpartner, NES_CM_EVENT_CONNECTED);
2736 printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
2737 "ret=%d\n", __func__, __LINE__, ret);
2739 passive_state = atomic_add_return(1, &cm_node->passive_state);
2740 if (passive_state == NES_SEND_RESET_EVENT)
2741 create_event(cm_node, NES_CM_EVENT_RESET);
2749 int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2751 struct nes_cm_node *cm_node;
2752 struct nes_cm_core *cm_core;
2754 atomic_inc(&cm_rejects);
2755 cm_node = (struct nes_cm_node *) cm_id->provider_data;
2756 cm_core = cm_node->cm_core;
2757 cm_node->mpa_frame_size = sizeof(struct ietf_mpa_frame) + pdata_len;
2759 strcpy(&cm_node->mpa_frame.key[0], IEFT_MPA_KEY_REP);
2760 memcpy(&cm_node->mpa_frame.priv_data, pdata, pdata_len);
2762 cm_node->mpa_frame.priv_data_len = cpu_to_be16(pdata_len);
2763 cm_node->mpa_frame.rev = mpa_version;
2764 cm_node->mpa_frame.flags = IETF_MPA_FLAGS_CRC | IETF_MPA_FLAGS_REJECT;
2766 cm_core->api->reject(cm_core, &cm_node->mpa_frame, cm_node);
2774 * setup and launch cm connect node
2776 int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2779 struct nes_qp *nesqp;
2780 struct nes_vnic *nesvnic;
2781 struct nes_device *nesdev;
2782 struct nes_cm_node *cm_node;
2783 struct nes_cm_info cm_info;
2785 ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
2788 nesqp = to_nesqp(ibqp);
2791 nesvnic = to_nesvnic(nesqp->ibqp.device);
2794 nesdev = nesvnic->nesdev;
2798 nes_debug(NES_DBG_CM, "QP%u, current IP = 0x%08X, Destination IP = "
2799 "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp->hwqp.qp_id,
2800 ntohl(nesvnic->local_ipaddr),
2801 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2802 ntohs(cm_id->remote_addr.sin_port),
2803 ntohl(cm_id->local_addr.sin_addr.s_addr),
2804 ntohs(cm_id->local_addr.sin_port));
2806 atomic_inc(&cm_connects);
2807 nesqp->active_conn = 1;
2809 /* cache the cm_id in the qp */
2810 nesqp->cm_id = cm_id;
2812 cm_id->provider_data = nesqp;
2814 nesqp->private_data_len = conn_param->private_data_len;
2815 nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32((u32)conn_param->ord);
2816 nes_debug(NES_DBG_CM, "requested ord = 0x%08X.\n", (u32)conn_param->ord);
2817 nes_debug(NES_DBG_CM, "mpa private data len =%u\n",
2818 conn_param->private_data_len);
2820 if (cm_id->local_addr.sin_addr.s_addr !=
2821 cm_id->remote_addr.sin_addr.s_addr)
2822 nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
2823 PCI_FUNC(nesdev->pcidev->devfn), NES_MANAGE_APBVT_ADD);
2825 /* set up the connection params for the node */
2826 cm_info.loc_addr = htonl(cm_id->local_addr.sin_addr.s_addr);
2827 cm_info.loc_port = htons(cm_id->local_addr.sin_port);
2828 cm_info.rem_addr = htonl(cm_id->remote_addr.sin_addr.s_addr);
2829 cm_info.rem_port = htons(cm_id->remote_addr.sin_port);
2830 cm_info.cm_id = cm_id;
2831 cm_info.conn_type = NES_CM_IWARP_CONN_TYPE;
2833 cm_id->add_ref(cm_id);
2835 /* create a connect CM node connection */
2836 cm_node = g_cm_core->api->connect(g_cm_core, nesvnic,
2837 conn_param->private_data_len, (void *)conn_param->private_data,
2840 if (cm_id->local_addr.sin_addr.s_addr !=
2841 cm_id->remote_addr.sin_addr.s_addr)
2842 nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
2843 PCI_FUNC(nesdev->pcidev->devfn),
2844 NES_MANAGE_APBVT_DEL);
2846 cm_id->rem_ref(cm_id);
2850 cm_node->apbvt_set = 1;
2851 nesqp->cm_node = cm_node;
2852 cm_node->nesqp = nesqp;
2853 nes_add_ref(&nesqp->ibqp);
2862 int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
2864 struct nes_vnic *nesvnic;
2865 struct nes_cm_listener *cm_node;
2866 struct nes_cm_info cm_info;
2867 struct nes_adapter *adapter;
2871 nes_debug(NES_DBG_CM, "cm_id = %p, local port = 0x%04X.\n",
2872 cm_id, ntohs(cm_id->local_addr.sin_port));
2874 nesvnic = to_nesvnic(cm_id->device);
2877 adapter = nesvnic->nesdev->nesadapter;
2878 nes_debug(NES_DBG_CM, "nesvnic=%p, netdev=%p, %s\n",
2879 nesvnic, nesvnic->netdev, nesvnic->netdev->name);
2881 nes_debug(NES_DBG_CM, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
2882 nesvnic->local_ipaddr, cm_id->local_addr.sin_addr.s_addr);
2884 /* setup listen params in our api call struct */
2885 cm_info.loc_addr = nesvnic->local_ipaddr;
2886 cm_info.loc_port = cm_id->local_addr.sin_port;
2887 cm_info.backlog = backlog;
2888 cm_info.cm_id = cm_id;
2890 cm_info.conn_type = NES_CM_IWARP_CONN_TYPE;
2893 cm_node = g_cm_core->api->listen(g_cm_core, nesvnic, &cm_info);
2895 printk(KERN_ERR "%s[%u] Error returned from listen API call\n",
2896 __func__, __LINE__);
2900 cm_id->provider_data = cm_node;
2902 if (!cm_node->reused_node) {
2903 err = nes_manage_apbvt(nesvnic,
2904 ntohs(cm_id->local_addr.sin_port),
2905 PCI_FUNC(nesvnic->nesdev->pcidev->devfn),
2906 NES_MANAGE_APBVT_ADD);
2908 printk(KERN_ERR "nes_manage_apbvt call returned %d.\n",
2910 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
2913 cm_listens_created++;
2916 cm_id->add_ref(cm_id);
2917 cm_id->provider_data = (void *)cm_node;
2925 * nes_destroy_listen
2927 int nes_destroy_listen(struct iw_cm_id *cm_id)
2929 if (cm_id->provider_data)
2930 g_cm_core->api->stop_listener(g_cm_core, cm_id->provider_data);
2932 nes_debug(NES_DBG_CM, "cm_id->provider_data was NULL\n");
2934 cm_id->rem_ref(cm_id);
2943 int nes_cm_recv(struct sk_buff *skb, struct net_device *netdevice)
2946 cm_packets_received++;
2947 if ((g_cm_core) && (g_cm_core->api)) {
2948 rc = g_cm_core->api->recv_pkt(g_cm_core, netdev_priv(netdevice), skb);
2950 nes_debug(NES_DBG_CM, "Unable to process packet for CM,"
2951 " cm is not setup properly.\n");
2960 * Start and init a cm core module
2962 int nes_cm_start(void)
2964 nes_debug(NES_DBG_CM, "\n");
2965 /* create the primary CM core, pass this handle to subsequent core inits */
2966 g_cm_core = nes_cm_alloc_core();
2977 * stop and dealloc all cm core instances
2979 int nes_cm_stop(void)
2981 g_cm_core->api->destroy_cm_core(g_cm_core);
2987 * cm_event_connected
2988 * handle a connected event, setup QPs and HW
2990 static void cm_event_connected(struct nes_cm_event *event)
2993 struct nes_qp *nesqp;
2994 struct nes_vnic *nesvnic;
2995 struct nes_device *nesdev;
2996 struct nes_cm_node *cm_node;
2997 struct nes_adapter *nesadapter;
2998 struct ib_qp_attr attr;
2999 struct iw_cm_id *cm_id;
3000 struct iw_cm_event cm_event;
3001 struct nes_hw_qp_wqe *wqe;
3002 struct nes_v4_quad nes_quad;
3006 /* get all our handles */
3007 cm_node = event->cm_node;
3008 cm_id = cm_node->cm_id;
3009 nes_debug(NES_DBG_CM, "cm_event_connected - %p - cm_id = %p\n", cm_node, cm_id);
3010 nesqp = (struct nes_qp *)cm_id->provider_data;
3011 nesvnic = to_nesvnic(nesqp->ibqp.device);
3012 nesdev = nesvnic->nesdev;
3013 nesadapter = nesdev->nesadapter;
3015 if (nesqp->destroyed) {
3018 atomic_inc(&cm_connecteds);
3019 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
3020 " local port 0x%04X. jiffies = %lu.\n",
3022 ntohl(cm_id->remote_addr.sin_addr.s_addr),
3023 ntohs(cm_id->remote_addr.sin_port),
3024 ntohs(cm_id->local_addr.sin_port),
3027 nes_cm_init_tsa_conn(nesqp, cm_node);
3029 /* set the QP tsa context */
3030 nesqp->nesqp_context->tcpPorts[0] =
3031 cpu_to_le16(ntohs(cm_id->local_addr.sin_port));
3032 nesqp->nesqp_context->tcpPorts[1] =
3033 cpu_to_le16(ntohs(cm_id->remote_addr.sin_port));
3034 if (ipv4_is_loopback(cm_id->remote_addr.sin_addr.s_addr))
3035 nesqp->nesqp_context->ip0 =
3036 cpu_to_le32(ntohl(nesvnic->local_ipaddr));
3038 nesqp->nesqp_context->ip0 =
3039 cpu_to_le32(ntohl(cm_id->remote_addr.sin_addr.s_addr));
3041 nesqp->nesqp_context->misc2 |= cpu_to_le32(
3042 (u32)PCI_FUNC(nesdev->pcidev->devfn) <<
3043 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
3044 nesqp->nesqp_context->arp_index_vlan |= cpu_to_le32(
3045 nes_arp_table(nesdev,
3046 le32_to_cpu(nesqp->nesqp_context->ip0),
3047 NULL, NES_ARP_RESOLVE) << 16);
3048 nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
3049 jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
3050 nesqp->nesqp_context->ird_index = cpu_to_le32(nesqp->hwqp.qp_id);
3051 nesqp->nesqp_context->ird_ord_sizes |=
3052 cpu_to_le32((u32)1 <<
3053 NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT);
3055 /* Adjust tail for not having a LSMM */
3056 nesqp->hwqp.sq_tail = 1;
3058 #if defined(NES_SEND_FIRST_WRITE)
3059 if (cm_node->send_write0) {
3060 nes_debug(NES_DBG_CM, "Sending first write.\n");
3061 wqe = &nesqp->hwqp.sq_vbase[0];
3062 u64temp = (unsigned long)nesqp;
3063 u64temp |= NES_SW_CONTEXT_ALIGN>>1;
3064 set_wqe_64bit_value(wqe->wqe_words,
3065 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX, u64temp);
3066 wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
3067 cpu_to_le32(NES_IWARP_SQ_OP_RDMAW);
3068 wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] = 0;
3069 wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX] = 0;
3070 wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX] = 0;
3071 wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] = 0;
3072 wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 0;
3074 /* use the reserved spot on the WQ for the extra first WQE */
3075 nesqp->nesqp_context->ird_ord_sizes &=
3076 cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
3077 NES_QPCONTEXT_ORDIRD_WRPDU |
3078 NES_QPCONTEXT_ORDIRD_ALSMM));
3079 nesqp->skip_lsmm = 1;
3080 nesqp->hwqp.sq_tail = 0;
3081 nes_write32(nesdev->regs + NES_WQE_ALLOC,
3082 (1 << 24) | 0x00800000 | nesqp->hwqp.qp_id);
3086 memset(&nes_quad, 0, sizeof(nes_quad));
3088 nes_quad.DstIpAdrIndex =
3089 cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
3090 if (ipv4_is_loopback(cm_id->remote_addr.sin_addr.s_addr))
3091 nes_quad.SrcIpadr = nesvnic->local_ipaddr;
3093 nes_quad.SrcIpadr = cm_id->remote_addr.sin_addr.s_addr;
3094 nes_quad.TcpPorts[0] = cm_id->remote_addr.sin_port;
3095 nes_quad.TcpPorts[1] = cm_id->local_addr.sin_port;
3097 /* Produce hash key */
3098 crc_value = get_crc_value(&nes_quad);
3099 nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
3100 nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
3101 nesqp->hte_index, nesqp->hte_index & nesadapter->hte_index_mask);
3103 nesqp->hte_index &= nesadapter->hte_index_mask;
3104 nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
3106 nesqp->ietf_frame = &cm_node->mpa_frame;
3107 nesqp->private_data_len = (u8) cm_node->mpa_frame_size;
3108 cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
3110 /* notify OF layer we successfully created the requested connection */
3111 cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
3112 cm_event.status = IW_CM_EVENT_STATUS_ACCEPTED;
3113 cm_event.provider_data = cm_id->provider_data;
3114 cm_event.local_addr.sin_family = AF_INET;
3115 cm_event.local_addr.sin_port = cm_id->local_addr.sin_port;
3116 cm_event.remote_addr = cm_id->remote_addr;
3118 cm_event.private_data = (void *)event->cm_node->mpa_frame_buf;
3119 cm_event.private_data_len = (u8) event->cm_node->mpa_frame_size;
3121 cm_event.local_addr.sin_addr.s_addr = event->cm_info.rem_addr;
3122 ret = cm_id->event_handler(cm_id, &cm_event);
3123 nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
3126 printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
3127 "ret=%d\n", __func__, __LINE__, ret);
3128 attr.qp_state = IB_QPS_RTS;
3129 nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
3131 nes_debug(NES_DBG_CM, "Exiting connect thread for QP%u. jiffies = "
3132 "%lu\n", nesqp->hwqp.qp_id, jiffies);
3139 * cm_event_connect_error
3141 static void cm_event_connect_error(struct nes_cm_event *event)
3143 struct nes_qp *nesqp;
3144 struct iw_cm_id *cm_id;
3145 struct iw_cm_event cm_event;
3146 /* struct nes_cm_info cm_info; */
3149 if (!event->cm_node)
3152 cm_id = event->cm_node->cm_id;
3157 nes_debug(NES_DBG_CM, "cm_node=%p, cm_id=%p\n", event->cm_node, cm_id);
3158 nesqp = cm_id->provider_data;
3164 /* notify OF layer about this connection error event */
3165 /* cm_id->rem_ref(cm_id); */
3166 nesqp->cm_id = NULL;
3167 cm_id->provider_data = NULL;
3168 cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
3169 cm_event.status = IW_CM_EVENT_STATUS_REJECTED;
3170 cm_event.provider_data = cm_id->provider_data;
3171 cm_event.local_addr = cm_id->local_addr;
3172 cm_event.remote_addr = cm_id->remote_addr;
3173 cm_event.private_data = NULL;
3174 cm_event.private_data_len = 0;
3176 nes_debug(NES_DBG_CM, "call CM_EVENT REJECTED, local_addr=%08x, "
3177 "remove_addr=%08x\n", cm_event.local_addr.sin_addr.s_addr,
3178 cm_event.remote_addr.sin_addr.s_addr);
3180 ret = cm_id->event_handler(cm_id, &cm_event);
3181 nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
3183 printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
3184 "ret=%d\n", __func__, __LINE__, ret);
3185 cm_id->rem_ref(cm_id);
3187 rem_ref_cm_node(event->cm_node->cm_core, event->cm_node);
3195 static void cm_event_reset(struct nes_cm_event *event)
3197 struct nes_qp *nesqp;
3198 struct iw_cm_id *cm_id;
3199 struct iw_cm_event cm_event;
3200 /* struct nes_cm_info cm_info; */
3203 if (!event->cm_node)
3206 if (!event->cm_node->cm_id)
3209 cm_id = event->cm_node->cm_id;
3211 nes_debug(NES_DBG_CM, "%p - cm_id = %p\n", event->cm_node, cm_id);
3212 nesqp = cm_id->provider_data;
3214 nesqp->cm_id = NULL;
3215 /* cm_id->provider_data = NULL; */
3216 cm_event.event = IW_CM_EVENT_DISCONNECT;
3217 cm_event.status = IW_CM_EVENT_STATUS_RESET;
3218 cm_event.provider_data = cm_id->provider_data;
3219 cm_event.local_addr = cm_id->local_addr;
3220 cm_event.remote_addr = cm_id->remote_addr;
3221 cm_event.private_data = NULL;
3222 cm_event.private_data_len = 0;
3224 ret = cm_id->event_handler(cm_id, &cm_event);
3225 cm_id->add_ref(cm_id);
3226 atomic_inc(&cm_closes);
3227 cm_event.event = IW_CM_EVENT_CLOSE;
3228 cm_event.status = IW_CM_EVENT_STATUS_OK;
3229 cm_event.provider_data = cm_id->provider_data;
3230 cm_event.local_addr = cm_id->local_addr;
3231 cm_event.remote_addr = cm_id->remote_addr;
3232 cm_event.private_data = NULL;
3233 cm_event.private_data_len = 0;
3234 nes_debug(NES_DBG_CM, "NODE %p Generating CLOSE\n", event->cm_node);
3235 ret = cm_id->event_handler(cm_id, &cm_event);
3237 nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
3240 /* notify OF layer about this connection error event */
3241 cm_id->rem_ref(cm_id);
3250 static void cm_event_mpa_req(struct nes_cm_event *event)
3252 struct iw_cm_id *cm_id;
3253 struct iw_cm_event cm_event;
3255 struct nes_cm_node *cm_node;
3257 cm_node = event->cm_node;
3260 cm_id = cm_node->cm_id;
3262 atomic_inc(&cm_connect_reqs);
3263 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3264 cm_node, cm_id, jiffies);
3266 cm_event.event = IW_CM_EVENT_CONNECT_REQUEST;
3267 cm_event.status = IW_CM_EVENT_STATUS_OK;
3268 cm_event.provider_data = (void *)cm_node;
3270 cm_event.local_addr.sin_family = AF_INET;
3271 cm_event.local_addr.sin_port = htons(event->cm_info.loc_port);
3272 cm_event.local_addr.sin_addr.s_addr = htonl(event->cm_info.loc_addr);
3274 cm_event.remote_addr.sin_family = AF_INET;
3275 cm_event.remote_addr.sin_port = htons(event->cm_info.rem_port);
3276 cm_event.remote_addr.sin_addr.s_addr = htonl(event->cm_info.rem_addr);
3278 cm_event.private_data = cm_node->mpa_frame_buf;
3279 cm_event.private_data_len = (u8) cm_node->mpa_frame_size;
3281 ret = cm_id->event_handler(cm_id, &cm_event);
3283 printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
3284 __func__, __LINE__, ret);
3290 static void nes_cm_event_handler(struct work_struct *);
3294 * post an event to the cm event handler
3296 static int nes_cm_post_event(struct nes_cm_event *event)
3298 atomic_inc(&event->cm_node->cm_core->events_posted);
3299 add_ref_cm_node(event->cm_node);
3300 event->cm_info.cm_id->add_ref(event->cm_info.cm_id);
3301 INIT_WORK(&event->event_work, nes_cm_event_handler);
3302 nes_debug(NES_DBG_CM, "cm_node=%p queue_work, event=%p\n",
3303 event->cm_node, event);
3305 queue_work(event->cm_node->cm_core->event_wq, &event->event_work);
3307 nes_debug(NES_DBG_CM, "Exit\n");
3313 * nes_cm_event_handler
3314 * worker function to handle cm events
3315 * will free instance of nes_cm_event
3317 static void nes_cm_event_handler(struct work_struct *work)
3319 struct nes_cm_event *event = container_of(work, struct nes_cm_event,
3321 struct nes_cm_core *cm_core;
3323 if ((!event) || (!event->cm_node) || (!event->cm_node->cm_core))
3326 cm_core = event->cm_node->cm_core;
3327 nes_debug(NES_DBG_CM, "event=%p, event->type=%u, events posted=%u\n",
3328 event, event->type, atomic_read(&cm_core->events_posted));
3330 switch (event->type) {
3331 case NES_CM_EVENT_MPA_REQ:
3332 cm_event_mpa_req(event);
3333 nes_debug(NES_DBG_CM, "cm_node=%p CM Event: MPA REQUEST\n",
3336 case NES_CM_EVENT_RESET:
3337 nes_debug(NES_DBG_CM, "cm_node = %p CM Event: RESET\n",
3339 cm_event_reset(event);
3341 case NES_CM_EVENT_CONNECTED:
3342 if ((!event->cm_node->cm_id) ||
3343 (event->cm_node->state != NES_CM_STATE_TSA))
3345 cm_event_connected(event);
3346 nes_debug(NES_DBG_CM, "CM Event: CONNECTED\n");
3348 case NES_CM_EVENT_ABORTED:
3349 if ((!event->cm_node->cm_id) ||
3350 (event->cm_node->state == NES_CM_STATE_TSA))
3352 cm_event_connect_error(event);
3353 nes_debug(NES_DBG_CM, "CM Event: ABORTED\n");
3355 case NES_CM_EVENT_DROPPED_PKT:
3356 nes_debug(NES_DBG_CM, "CM Event: DROPPED PKT\n");
3359 nes_debug(NES_DBG_CM, "CM Event: UNKNOWN EVENT TYPE\n");
3363 atomic_dec(&cm_core->events_posted);
3364 event->cm_info.cm_id->rem_ref(event->cm_info.cm_id);
3365 rem_ref_cm_node(cm_core, event->cm_node);