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
*, struct nes_cm_node
*);
78 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*,
79 struct nes_vnic
*, struct nes_cm_info
*);
80 static int add_ref_cm_node(struct nes_cm_node
*);
81 static int rem_ref_cm_node(struct nes_cm_core
*, struct nes_cm_node
*);
82 static int mini_cm_del_listen(struct nes_cm_core
*, struct nes_cm_listener
*);
85 /* External CM API Interface */
86 /* instance of function pointers for client API */
87 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
88 static struct nes_cm_ops nes_cm_api
= {
102 struct nes_cm_core
*g_cm_core
;
104 atomic_t cm_connects
;
106 atomic_t cm_disconnects
;
108 atomic_t cm_connecteds
;
109 atomic_t cm_connect_reqs
;
116 static struct nes_cm_event
*create_event(struct nes_cm_node
*cm_node
,
117 enum nes_cm_event_type type
)
119 struct nes_cm_event
*event
;
124 /* allocate an empty event */
125 event
= kzalloc(sizeof(*event
), GFP_ATOMIC
);
131 event
->cm_node
= cm_node
;
132 event
->cm_info
.rem_addr
= cm_node
->rem_addr
;
133 event
->cm_info
.loc_addr
= cm_node
->loc_addr
;
134 event
->cm_info
.rem_port
= cm_node
->rem_port
;
135 event
->cm_info
.loc_port
= cm_node
->loc_port
;
136 event
->cm_info
.cm_id
= cm_node
->cm_id
;
138 nes_debug(NES_DBG_CM
, "Created event=%p, type=%u, dst_addr=%08x[%x],"
139 " src_addr=%08x[%x]\n",
141 event
->cm_info
.loc_addr
, event
->cm_info
.loc_port
,
142 event
->cm_info
.rem_addr
, event
->cm_info
.rem_port
);
144 nes_cm_post_event(event
);
152 int send_mpa_request(struct nes_cm_node
*cm_node
)
157 skb
= get_free_pkt(cm_node
);
159 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
163 /* send an MPA Request frame */
164 form_cm_frame(skb
, cm_node
, NULL
, 0, &cm_node
->mpa_frame
,
165 cm_node
->mpa_frame_size
, SET_ACK
);
167 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
177 * recv_mpa - process a received TCP pkt, we are expecting an
180 static int parse_mpa(struct nes_cm_node
*cm_node
, u8
*buffer
, u32 len
)
182 struct ietf_mpa_frame
*mpa_frame
;
184 /* assume req frame is in tcp data payload */
185 if (len
< sizeof(struct ietf_mpa_frame
)) {
186 nes_debug(NES_DBG_CM
, "The received ietf buffer was too small (%x)\n", len
);
190 mpa_frame
= (struct ietf_mpa_frame
*)buffer
;
191 cm_node
->mpa_frame_size
= ntohs(mpa_frame
->priv_data_len
);
193 if (cm_node
->mpa_frame_size
+ sizeof(struct ietf_mpa_frame
) != len
) {
194 nes_debug(NES_DBG_CM
, "The received ietf buffer was not right"
195 " complete (%x + %x != %x)\n",
196 cm_node
->mpa_frame_size
, (u32
)sizeof(struct ietf_mpa_frame
), len
);
200 /* copy entire MPA frame to our cm_node's frame */
201 memcpy(cm_node
->mpa_frame_buf
, buffer
+ sizeof(struct ietf_mpa_frame
),
202 cm_node
->mpa_frame_size
);
209 * handle_exception_pkt - process an exception packet.
210 * We have been in a TSA state, and we have now received SW
211 * TCP/IP traffic should be a FIN request or IP pkt with options
213 static int handle_exception_pkt(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
216 struct tcphdr
*tcph
= tcp_hdr(skb
);
218 /* first check to see if this a FIN pkt */
220 /* we need to ACK the FIN request */
223 /* check which side we are (client/server) and set next state accordingly */
224 if (cm_node
->tcp_cntxt
.client
)
225 cm_node
->state
= NES_CM_STATE_CLOSING
;
227 /* we are the server side */
228 cm_node
->state
= NES_CM_STATE_CLOSE_WAIT
;
229 /* since this is a self contained CM we don't wait for */
230 /* an APP to close us, just send final FIN immediately */
231 ret
= send_fin(cm_node
, NULL
);
232 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
243 * form_cm_frame - get a free packet and build empty frame Use
244 * node info to build.
246 struct sk_buff
*form_cm_frame(struct sk_buff
*skb
, struct nes_cm_node
*cm_node
,
247 void *options
, u32 optionsize
, void *data
, u32 datasize
, u8 flags
)
253 u16 packetsize
= sizeof(*iph
);
255 packetsize
+= sizeof(*tcph
);
256 packetsize
+= optionsize
+ datasize
;
258 memset(skb
->data
, 0x00, ETH_HLEN
+ sizeof(*iph
) + sizeof(*tcph
));
261 buf
= skb_put(skb
, packetsize
+ ETH_HLEN
);
263 ethh
= (struct ethhdr
*) buf
;
266 iph
= (struct iphdr
*)buf
;
268 tcph
= (struct tcphdr
*)buf
;
269 skb_reset_mac_header(skb
);
270 skb_set_network_header(skb
, ETH_HLEN
);
271 skb_set_transport_header(skb
, ETH_HLEN
+sizeof(*iph
));
272 buf
+= sizeof(*tcph
);
274 skb
->ip_summed
= CHECKSUM_PARTIAL
;
275 skb
->protocol
= htons(0x800);
277 skb
->mac_len
= ETH_HLEN
;
279 memcpy(ethh
->h_dest
, cm_node
->rem_mac
, ETH_ALEN
);
280 memcpy(ethh
->h_source
, cm_node
->loc_mac
, ETH_ALEN
);
281 ethh
->h_proto
= htons(0x0800);
283 iph
->version
= IPVERSION
;
284 iph
->ihl
= 5; /* 5 * 4Byte words, IP headr len */
286 iph
->tot_len
= htons(packetsize
);
287 iph
->id
= htons(++cm_node
->tcp_cntxt
.loc_id
);
289 iph
->frag_off
= htons(0x4000);
291 iph
->protocol
= 0x06; /* IPPROTO_TCP */
293 iph
->saddr
= htonl(cm_node
->loc_addr
);
294 iph
->daddr
= htonl(cm_node
->rem_addr
);
296 tcph
->source
= htons(cm_node
->loc_port
);
297 tcph
->dest
= htons(cm_node
->rem_port
);
298 tcph
->seq
= htonl(cm_node
->tcp_cntxt
.loc_seq_num
);
300 if (flags
& SET_ACK
) {
301 cm_node
->tcp_cntxt
.loc_ack_num
= cm_node
->tcp_cntxt
.rcv_nxt
;
302 tcph
->ack_seq
= htonl(cm_node
->tcp_cntxt
.loc_ack_num
);
307 if (flags
& SET_SYN
) {
308 cm_node
->tcp_cntxt
.loc_seq_num
++;
311 cm_node
->tcp_cntxt
.loc_seq_num
+= datasize
; /* data (no headers) */
319 tcph
->doff
= (u16
)((sizeof(*tcph
) + optionsize
+ 3) >> 2);
320 tcph
->window
= htons(cm_node
->tcp_cntxt
.rcv_wnd
);
323 memcpy(buf
, options
, optionsize
);
326 memcpy(buf
, data
, datasize
);
328 skb_shinfo(skb
)->nr_frags
= 0;
329 cm_packets_created
++;
336 * print_core - dump a cm core
338 static void print_core(struct nes_cm_core
*core
)
340 nes_debug(NES_DBG_CM
, "---------------------------------------------\n");
341 nes_debug(NES_DBG_CM
, "CM Core -- (core = %p )\n", core
);
344 nes_debug(NES_DBG_CM
, "---------------------------------------------\n");
345 nes_debug(NES_DBG_CM
, "Session ID : %u \n", atomic_read(&core
->session_id
));
347 nes_debug(NES_DBG_CM
, "State : %u \n", core
->state
);
349 nes_debug(NES_DBG_CM
, "Tx Free cnt : %u \n", skb_queue_len(&core
->tx_free_list
));
350 nes_debug(NES_DBG_CM
, "Listen Nodes : %u \n", atomic_read(&core
->listen_node_cnt
));
351 nes_debug(NES_DBG_CM
, "Active Nodes : %u \n", atomic_read(&core
->node_cnt
));
353 nes_debug(NES_DBG_CM
, "core : %p \n", core
);
355 nes_debug(NES_DBG_CM
, "-------------- end core ---------------\n");
361 * note - cm_node needs to be protected before calling this. Encase in:
362 * rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
364 int schedule_nes_timer(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
365 enum nes_timer_type type
, int send_retrans
,
366 int close_when_complete
)
369 struct nes_cm_core
*cm_core
;
370 struct nes_timer_entry
*new_send
;
376 new_send
= kzalloc(sizeof(*new_send
), GFP_ATOMIC
);
380 /* new_send->timetosend = currenttime */
381 new_send
->retrycount
= NES_DEFAULT_RETRYS
;
382 new_send
->retranscount
= NES_DEFAULT_RETRANS
;
384 new_send
->timetosend
= jiffies
;
385 new_send
->type
= type
;
386 new_send
->netdev
= cm_node
->netdev
;
387 new_send
->send_retrans
= send_retrans
;
388 new_send
->close_when_complete
= close_when_complete
;
390 if (type
== NES_TIMER_TYPE_CLOSE
) {
391 new_send
->timetosend
+= (HZ
/2); /* TODO: decide on the correct value here */
392 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
393 list_add_tail(&new_send
->list
, &cm_node
->recv_list
);
394 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
397 if (type
== NES_TIMER_TYPE_SEND
) {
398 new_send
->seq_num
= htonl(tcp_hdr(skb
)->seq
);
399 atomic_inc(&new_send
->skb
->users
);
401 ret
= nes_nic_cm_xmit(new_send
->skb
, cm_node
->netdev
);
402 if (ret
!= NETDEV_TX_OK
) {
403 nes_debug(NES_DBG_CM
, "Error sending packet %p (jiffies = %lu)\n",
405 atomic_dec(&new_send
->skb
->users
);
406 new_send
->timetosend
= jiffies
;
410 if (close_when_complete
)
411 rem_ref_cm_node(cm_node
->cm_core
, cm_node
);
412 dev_kfree_skb_any(new_send
->skb
);
416 new_send
->timetosend
= jiffies
+ NES_RETRY_TIMEOUT
;
418 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
419 list_add_tail(&new_send
->list
, &cm_node
->retrans_list
);
420 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
422 if (type
== NES_TIMER_TYPE_RECV
) {
423 new_send
->seq_num
= htonl(tcp_hdr(skb
)->seq
);
424 new_send
->timetosend
= jiffies
;
425 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
426 list_add_tail(&new_send
->list
, &cm_node
->recv_list
);
427 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
429 cm_core
= cm_node
->cm_core
;
431 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
433 if (!was_timer_set
) {
434 cm_core
->tcp_timer
.expires
= new_send
->timetosend
;
435 add_timer(&cm_core
->tcp_timer
);
445 void nes_cm_timer_tick(unsigned long pass
)
447 unsigned long flags
, qplockflags
;
448 unsigned long nexttimeout
= jiffies
+ NES_LONG_TIME
;
449 struct iw_cm_id
*cm_id
;
450 struct nes_cm_node
*cm_node
;
451 struct nes_timer_entry
*send_entry
, *recv_entry
;
452 struct list_head
*list_core
, *list_core_temp
;
453 struct list_head
*list_node
, *list_node_temp
;
454 struct nes_cm_core
*cm_core
= g_cm_core
;
455 struct nes_qp
*nesqp
;
458 int ret
= NETDEV_TX_OK
;
461 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
463 list_for_each_safe(list_node
, list_core_temp
, &cm_core
->connected_nodes
) {
464 cm_node
= container_of(list_node
, struct nes_cm_node
, list
);
465 add_ref_cm_node(cm_node
);
466 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
467 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
468 list_for_each_safe(list_core
, list_node_temp
, &cm_node
->recv_list
) {
469 recv_entry
= container_of(list_core
, struct nes_timer_entry
, list
);
470 if ((time_after(recv_entry
->timetosend
, jiffies
)) &&
471 (recv_entry
->type
== NES_TIMER_TYPE_CLOSE
)) {
472 if (nexttimeout
> recv_entry
->timetosend
|| !settimer
) {
473 nexttimeout
= recv_entry
->timetosend
;
478 list_del(&recv_entry
->list
);
479 cm_id
= cm_node
->cm_id
;
480 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
481 if (recv_entry
->type
== NES_TIMER_TYPE_CLOSE
) {
482 nesqp
= (struct nes_qp
*)recv_entry
->skb
;
483 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
485 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, refcount = %d: "
486 "****** HIT A NES_TIMER_TYPE_CLOSE"
487 " with something to do!!! ******\n",
488 nesqp
->hwqp
.qp_id
, cm_id
,
489 atomic_read(&nesqp
->refcount
));
490 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
491 nesqp
->last_aeq
= NES_AEQE_AEID_RESET_SENT
;
492 nesqp
->ibqp_state
= IB_QPS_ERR
;
493 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
494 nes_cm_disconn(nesqp
);
496 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
497 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p, refcount = %d:"
498 " ****** HIT A NES_TIMER_TYPE_CLOSE"
499 " with nothing to do!!! ******\n",
500 nesqp
->hwqp
.qp_id
, cm_id
,
501 atomic_read(&nesqp
->refcount
));
502 nes_rem_ref(&nesqp
->ibqp
);
505 cm_id
->rem_ref(cm_id
);
508 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
510 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
512 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
514 list_for_each_safe(list_core
, list_node_temp
, &cm_node
->retrans_list
) {
518 send_entry
= container_of(list_core
, struct nes_timer_entry
, list
);
519 if (time_after(send_entry
->timetosend
, jiffies
)) {
520 if (cm_node
->state
!= NES_CM_STATE_TSA
) {
521 if ((nexttimeout
> send_entry
->timetosend
) || !settimer
) {
522 nexttimeout
= send_entry
->timetosend
;
528 list_del(&send_entry
->list
);
529 skb
= send_entry
->skb
;
530 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
531 dev_kfree_skb_any(skb
);
533 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
537 if (send_entry
->type
== NES_TIMER_NODE_CLEANUP
) {
538 list_del(&send_entry
->list
);
539 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
541 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
544 if ((send_entry
->seq_num
< cm_node
->tcp_cntxt
.rem_ack_num
) ||
545 (cm_node
->state
== NES_CM_STATE_TSA
) ||
546 (cm_node
->state
== NES_CM_STATE_CLOSED
)) {
547 skb
= send_entry
->skb
;
548 list_del(&send_entry
->list
);
549 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
551 dev_kfree_skb_any(skb
);
552 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
556 if (!send_entry
->retranscount
|| !send_entry
->retrycount
) {
557 cm_packets_dropped
++;
558 skb
= send_entry
->skb
;
559 list_del(&send_entry
->list
);
560 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
561 dev_kfree_skb_any(skb
);
563 if (cm_node
->state
== NES_CM_STATE_SYN_RCVD
) {
564 /* this node never even generated an indication up to the cm */
565 rem_ref_cm_node(cm_core
, cm_node
);
567 cm_node
->state
= NES_CM_STATE_CLOSED
;
568 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
570 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
573 /* this seems like the correct place, but leave send entry unprotected */
574 // spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
575 atomic_inc(&send_entry
->skb
->users
);
576 cm_packets_retrans
++;
577 nes_debug(NES_DBG_CM
, "Retransmitting send_entry %p for node %p,"
578 " jiffies = %lu, time to send = %lu, retranscount = %u, "
579 "send_entry->seq_num = 0x%08X, cm_node->tcp_cntxt.rem_ack_num = 0x%08X\n",
580 send_entry
, cm_node
, jiffies
, send_entry
->timetosend
, send_entry
->retranscount
,
581 send_entry
->seq_num
, cm_node
->tcp_cntxt
.rem_ack_num
);
583 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
584 ret
= nes_nic_cm_xmit(send_entry
->skb
, cm_node
->netdev
);
585 if (ret
!= NETDEV_TX_OK
) {
586 cm_packets_bounced
++;
587 atomic_dec(&send_entry
->skb
->users
);
588 send_entry
->retrycount
--;
589 nexttimeout
= jiffies
+ NES_SHORT_TIME
;
592 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
597 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
598 list_del(&send_entry
->list
);
599 nes_debug(NES_DBG_CM
, "Packet Sent: retrans count = %u, retry count = %u.\n",
600 send_entry
->retranscount
, send_entry
->retrycount
);
601 if (send_entry
->send_retrans
) {
602 send_entry
->retranscount
--;
603 send_entry
->timetosend
= jiffies
+ NES_RETRY_TIMEOUT
;
604 if (nexttimeout
> send_entry
->timetosend
|| !settimer
) {
605 nexttimeout
= send_entry
->timetosend
;
608 list_add(&send_entry
->list
, &cm_node
->retrans_list
);
611 int close_when_complete
;
612 skb
= send_entry
->skb
;
613 close_when_complete
= send_entry
->close_when_complete
;
614 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
615 if (close_when_complete
) {
616 BUG_ON(atomic_read(&cm_node
->ref_count
) == 1);
617 rem_ref_cm_node(cm_core
, cm_node
);
619 dev_kfree_skb_any(skb
);
621 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
625 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
627 rem_ref_cm_node(cm_core
, cm_node
);
629 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
630 if (ret
!= NETDEV_TX_OK
)
633 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
636 if (!timer_pending(&cm_core
->tcp_timer
)) {
637 cm_core
->tcp_timer
.expires
= nexttimeout
;
638 add_timer(&cm_core
->tcp_timer
);
647 int send_syn(struct nes_cm_node
*cm_node
, u32 sendack
)
652 char optionsbuffer
[sizeof(struct option_mss
) +
653 sizeof(struct option_windowscale
) +
654 sizeof(struct option_base
) + 1];
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
)
677 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
678 options
->as_base
.optionnum
= OPTION_NUMBER_WRITE0
;
679 options
->as_base
.length
= sizeof(struct option_base
);
680 optionssize
+= sizeof(struct option_base
);
681 /* we need the size to be a multiple of 4 */
682 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
685 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
690 options
= (union all_known_options
*)&optionsbuffer
[optionssize
];
691 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 int send_reset(struct nes_cm_node
*cm_node
)
716 struct sk_buff
*skb
= get_free_pkt(cm_node
);
717 int flags
= SET_RST
| SET_ACK
;
720 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
724 add_ref_cm_node(cm_node
);
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 int send_ack(struct nes_cm_node
*cm_node
)
738 struct sk_buff
*skb
= get_free_pkt(cm_node
);
741 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
745 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
);
746 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 0, 0);
755 int send_fin(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
)
759 /* if we didn't get a frame get one */
761 skb
= get_free_pkt(cm_node
);
764 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
768 form_cm_frame(skb
, cm_node
, NULL
, 0, NULL
, 0, SET_ACK
| SET_FIN
);
769 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
778 struct sk_buff
*get_free_pkt(struct nes_cm_node
*cm_node
)
780 struct sk_buff
*skb
, *new_skb
;
782 /* check to see if we need to repopulate the free tx pkt queue */
783 if (skb_queue_len(&cm_node
->cm_core
->tx_free_list
) < NES_CM_FREE_PKT_LO_WATERMARK
) {
784 while (skb_queue_len(&cm_node
->cm_core
->tx_free_list
) <
785 cm_node
->cm_core
->free_tx_pkt_max
) {
786 /* replace the frame we took, we won't get it back */
787 new_skb
= dev_alloc_skb(cm_node
->cm_core
->mtu
);
789 /* add a replacement frame to the free tx list head */
790 skb_queue_head(&cm_node
->cm_core
->tx_free_list
, new_skb
);
794 skb
= skb_dequeue(&cm_node
->cm_core
->tx_free_list
);
801 * make_hashkey - generate hash key from node tuple
803 static inline int make_hashkey(u16 loc_port
, nes_addr_t loc_addr
, u16 rem_port
,
808 hashkey
= loc_addr
+ rem_addr
+ loc_port
+ rem_port
;
809 hashkey
= (hashkey
% NES_CM_HASHTABLE_SIZE
);
816 * find_node - find a cm node that matches the reference cm node
818 static struct nes_cm_node
*find_node(struct nes_cm_core
*cm_core
,
819 u16 rem_port
, nes_addr_t rem_addr
, u16 loc_port
, nes_addr_t loc_addr
)
823 struct list_head
*list_pos
;
824 struct list_head
*hte
;
825 struct nes_cm_node
*cm_node
;
827 /* make a hash index key for this packet */
828 hashkey
= make_hashkey(loc_port
, loc_addr
, rem_port
, rem_addr
);
830 /* get a handle on the hte */
831 hte
= &cm_core
->connected_nodes
;
833 nes_debug(NES_DBG_CM
, "Searching for an owner node:%x:%x from core %p->%p\n",
834 loc_addr
, loc_port
, cm_core
, hte
);
836 /* walk list and find cm_node associated with this session ID */
837 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
838 list_for_each(list_pos
, hte
) {
839 cm_node
= container_of(list_pos
, struct nes_cm_node
, 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 list_head
*listen_list
;
868 struct nes_cm_listener
*listen_node
;
870 /* walk list and find cm_node associated with this session ID */
871 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
872 list_for_each(listen_list
, &cm_core
->listen_list
.list
) {
873 listen_node
= container_of(listen_list
, struct nes_cm_listener
, list
);
874 /* compare node pair, return node handle if a match */
875 if (((listen_node
->loc_addr
== dst_addr
) ||
876 listen_node
->loc_addr
== 0x00000000) &&
877 (listen_node
->loc_port
== dst_port
) &&
878 (listener_state
& listen_node
->listener_state
)) {
879 atomic_inc(&listen_node
->ref_count
);
880 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
884 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
886 nes_debug(NES_DBG_CM
, "Unable to find listener- %x:%x\n",
895 * add_hte_node - add a cm node to the hash table
897 static int add_hte_node(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
901 struct list_head
*hte
;
903 if (!cm_node
|| !cm_core
)
906 nes_debug(NES_DBG_CM
, "Adding Node to Active Connection HT\n");
908 /* first, make an index into our hash table */
909 hashkey
= make_hashkey(cm_node
->loc_port
, cm_node
->loc_addr
,
910 cm_node
->rem_port
, cm_node
->rem_addr
);
911 cm_node
->hashkey
= hashkey
;
913 spin_lock_irqsave(&cm_core
->ht_lock
, flags
);
915 /* get a handle on the hash table element (list head for this slot) */
916 hte
= &cm_core
->connected_nodes
;
917 list_add_tail(&cm_node
->list
, hte
);
918 atomic_inc(&cm_core
->ht_node_cnt
);
920 spin_unlock_irqrestore(&cm_core
->ht_lock
, flags
);
927 * mini_cm_dec_refcnt_listen
929 static int mini_cm_dec_refcnt_listen(struct nes_cm_core
*cm_core
,
930 struct nes_cm_listener
*listener
, int free_hanging_nodes
)
934 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
935 if (!atomic_dec_return(&listener
->ref_count
)) {
936 list_del(&listener
->list
);
938 /* decrement our listen node count */
939 atomic_dec(&cm_core
->listen_node_cnt
);
941 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
943 if (listener
->nesvnic
) {
944 nes_manage_apbvt(listener
->nesvnic
, listener
->loc_port
,
945 PCI_FUNC(listener
->nesvnic
->nesdev
->pcidev
->devfn
), NES_MANAGE_APBVT_DEL
);
948 nes_debug(NES_DBG_CM
, "destroying listener (%p)\n", listener
);
953 cm_listens_destroyed
++;
955 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
958 if (atomic_read(&listener
->pend_accepts_cnt
) > 0)
959 nes_debug(NES_DBG_CM
, "destroying listener (%p)"
960 " with non-zero pending accepts=%u\n",
961 listener
, atomic_read(&listener
->pend_accepts_cnt
));
971 static int mini_cm_del_listen(struct nes_cm_core
*cm_core
,
972 struct nes_cm_listener
*listener
)
974 listener
->listener_state
= NES_CM_LISTENER_PASSIVE_STATE
;
975 listener
->cm_id
= NULL
; /* going to be destroyed pretty soon */
976 return mini_cm_dec_refcnt_listen(cm_core
, listener
, 1);
981 * mini_cm_accelerated
983 static inline int mini_cm_accelerated(struct nes_cm_core
*cm_core
,
984 struct nes_cm_node
*cm_node
)
987 cm_node
->accelerated
= 1;
989 if (cm_node
->accept_pend
) {
990 BUG_ON(!cm_node
->listener
);
991 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
992 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
995 was_timer_set
= timer_pending(&cm_core
->tcp_timer
);
996 if (!was_timer_set
) {
997 cm_core
->tcp_timer
.expires
= jiffies
+ NES_SHORT_TIME
;
998 add_timer(&cm_core
->tcp_timer
);
1008 static void nes_addr_send_arp(u32 dst_ip
)
1013 memset(&fl
, 0, sizeof fl
);
1014 fl
.nl_u
.ip4_u
.daddr
= htonl(dst_ip
);
1015 if (ip_route_output_key(&init_net
, &rt
, &fl
)) {
1016 printk("%s: ip_route_output_key failed for 0x%08X\n",
1017 __FUNCTION__
, dst_ip
);
1021 neigh_event_send(rt
->u
.dst
.neighbour
, NULL
);
1027 * make_cm_node - create a new instance of a cm node
1029 static struct nes_cm_node
*make_cm_node(struct nes_cm_core
*cm_core
,
1030 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
,
1031 struct nes_cm_listener
*listener
)
1033 struct nes_cm_node
*cm_node
;
1036 struct nes_device
*nesdev
;
1037 struct nes_adapter
*nesadapter
;
1039 /* create an hte and cm_node for this instance */
1040 cm_node
= kzalloc(sizeof(*cm_node
), GFP_ATOMIC
);
1044 /* set our node specific transport info */
1045 cm_node
->loc_addr
= cm_info
->loc_addr
;
1046 cm_node
->rem_addr
= cm_info
->rem_addr
;
1047 cm_node
->loc_port
= cm_info
->loc_port
;
1048 cm_node
->rem_port
= cm_info
->rem_port
;
1049 cm_node
->send_write0
= send_first
;
1050 nes_debug(NES_DBG_CM
, "Make node addresses : loc = %x:%x, rem = %x:%x\n",
1051 cm_node
->loc_addr
, cm_node
->loc_port
, cm_node
->rem_addr
, cm_node
->rem_port
);
1052 cm_node
->listener
= listener
;
1053 cm_node
->netdev
= nesvnic
->netdev
;
1054 cm_node
->cm_id
= cm_info
->cm_id
;
1055 memcpy(cm_node
->loc_mac
, nesvnic
->netdev
->dev_addr
, ETH_ALEN
);
1057 nes_debug(NES_DBG_CM
, "listener=%p, cm_id=%p\n",
1058 cm_node
->listener
, cm_node
->cm_id
);
1060 INIT_LIST_HEAD(&cm_node
->retrans_list
);
1061 spin_lock_init(&cm_node
->retrans_list_lock
);
1062 INIT_LIST_HEAD(&cm_node
->recv_list
);
1063 spin_lock_init(&cm_node
->recv_list_lock
);
1065 cm_node
->loopbackpartner
= NULL
;
1066 atomic_set(&cm_node
->ref_count
, 1);
1067 /* associate our parent CM core */
1068 cm_node
->cm_core
= cm_core
;
1069 cm_node
->tcp_cntxt
.loc_id
= NES_CM_DEF_LOCAL_ID
;
1070 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
1071 cm_node
->tcp_cntxt
.rcv_wnd
= NES_CM_DEFAULT_RCV_WND_SCALED
>>
1072 NES_CM_DEFAULT_RCV_WND_SCALE
;
1073 ts
= current_kernel_time();
1074 cm_node
->tcp_cntxt
.loc_seq_num
= htonl(ts
.tv_nsec
);
1075 cm_node
->tcp_cntxt
.mss
= nesvnic
->max_frame_size
- sizeof(struct iphdr
) -
1076 sizeof(struct tcphdr
) - ETH_HLEN
- VLAN_HLEN
;
1077 cm_node
->tcp_cntxt
.rcv_nxt
= 0;
1078 /* get a unique session ID , add thread_id to an upcounter to handle race */
1079 atomic_inc(&cm_core
->node_cnt
);
1080 atomic_inc(&cm_core
->session_id
);
1081 cm_node
->session_id
= (u32
)(atomic_read(&cm_core
->session_id
) + current
->tgid
);
1082 cm_node
->conn_type
= cm_info
->conn_type
;
1083 cm_node
->apbvt_set
= 0;
1084 cm_node
->accept_pend
= 0;
1086 cm_node
->nesvnic
= nesvnic
;
1087 /* get some device handles, for arp lookup */
1088 nesdev
= nesvnic
->nesdev
;
1089 nesadapter
= nesdev
->nesadapter
;
1091 cm_node
->loopbackpartner
= NULL
;
1092 /* get the mac addr for the remote node */
1093 arpindex
= nes_arp_table(nesdev
, cm_node
->rem_addr
, NULL
, NES_ARP_RESOLVE
);
1096 nes_addr_send_arp(cm_info
->rem_addr
);
1100 /* copy the mac addr to node context */
1101 memcpy(cm_node
->rem_mac
, nesadapter
->arp_table
[arpindex
].mac_addr
, ETH_ALEN
);
1102 nes_debug(NES_DBG_CM
, "Remote mac addr from arp table:%02x,"
1103 " %02x, %02x, %02x, %02x, %02x\n",
1104 cm_node
->rem_mac
[0], cm_node
->rem_mac
[1],
1105 cm_node
->rem_mac
[2], cm_node
->rem_mac
[3],
1106 cm_node
->rem_mac
[4], cm_node
->rem_mac
[5]);
1108 add_hte_node(cm_core
, cm_node
);
1109 atomic_inc(&cm_nodes_created
);
1116 * add_ref_cm_node - destroy an instance of a cm node
1118 static int add_ref_cm_node(struct nes_cm_node
*cm_node
)
1120 atomic_inc(&cm_node
->ref_count
);
1126 * rem_ref_cm_node - destroy an instance of a cm node
1128 static int rem_ref_cm_node(struct nes_cm_core
*cm_core
,
1129 struct nes_cm_node
*cm_node
)
1131 unsigned long flags
, qplockflags
;
1132 struct nes_timer_entry
*send_entry
;
1133 struct nes_timer_entry
*recv_entry
;
1134 struct iw_cm_id
*cm_id
;
1135 struct list_head
*list_core
, *list_node_temp
;
1136 struct nes_qp
*nesqp
;
1141 spin_lock_irqsave(&cm_node
->cm_core
->ht_lock
, flags
);
1142 if (atomic_dec_return(&cm_node
->ref_count
)) {
1143 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1146 list_del(&cm_node
->list
);
1147 atomic_dec(&cm_core
->ht_node_cnt
);
1148 spin_unlock_irqrestore(&cm_node
->cm_core
->ht_lock
, flags
);
1150 /* if the node is destroyed before connection was accelerated */
1151 if (!cm_node
->accelerated
&& cm_node
->accept_pend
) {
1152 BUG_ON(!cm_node
->listener
);
1153 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1154 BUG_ON(atomic_read(&cm_node
->listener
->pend_accepts_cnt
) < 0);
1157 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1158 list_for_each_safe(list_core
, list_node_temp
, &cm_node
->retrans_list
) {
1159 send_entry
= container_of(list_core
, struct nes_timer_entry
, list
);
1160 list_del(&send_entry
->list
);
1161 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1162 dev_kfree_skb_any(send_entry
->skb
);
1164 spin_lock_irqsave(&cm_node
->retrans_list_lock
, flags
);
1167 spin_unlock_irqrestore(&cm_node
->retrans_list_lock
, flags
);
1169 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
1170 list_for_each_safe(list_core
, list_node_temp
, &cm_node
->recv_list
) {
1171 recv_entry
= container_of(list_core
, struct nes_timer_entry
, list
);
1172 list_del(&recv_entry
->list
);
1173 cm_id
= cm_node
->cm_id
;
1174 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
1175 if (recv_entry
->type
== NES_TIMER_TYPE_CLOSE
) {
1176 nesqp
= (struct nes_qp
*)recv_entry
->skb
;
1177 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
1179 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p: ****** HIT A NES_TIMER_TYPE_CLOSE"
1180 " with something to do!!! ******\n",
1181 nesqp
->hwqp
.qp_id
, cm_id
);
1182 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
1183 nesqp
->last_aeq
= NES_AEQE_AEID_RESET_SENT
;
1184 nesqp
->ibqp_state
= IB_QPS_ERR
;
1185 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
1186 nes_cm_disconn(nesqp
);
1188 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
1189 nes_debug(NES_DBG_CM
, "QP%u: cm_id = %p: ****** HIT A NES_TIMER_TYPE_CLOSE"
1190 " with nothing to do!!! ******\n",
1191 nesqp
->hwqp
.qp_id
, cm_id
);
1192 nes_rem_ref(&nesqp
->ibqp
);
1194 cm_id
->rem_ref(cm_id
);
1195 } else if (recv_entry
->type
== NES_TIMER_TYPE_RECV
) {
1196 dev_kfree_skb_any(recv_entry
->skb
);
1199 spin_lock_irqsave(&cm_node
->recv_list_lock
, flags
);
1201 spin_unlock_irqrestore(&cm_node
->recv_list_lock
, flags
);
1203 if (cm_node
->listener
) {
1204 mini_cm_dec_refcnt_listen(cm_core
, cm_node
->listener
, 0);
1206 if (cm_node
->apbvt_set
&& cm_node
->nesvnic
) {
1207 nes_manage_apbvt(cm_node
->nesvnic
, cm_node
->loc_port
,
1208 PCI_FUNC(cm_node
->nesvnic
->nesdev
->pcidev
->devfn
),
1209 NES_MANAGE_APBVT_DEL
);
1214 atomic_dec(&cm_core
->node_cnt
);
1215 atomic_inc(&cm_nodes_destroyed
);
1224 static int process_options(struct nes_cm_node
*cm_node
, u8
*optionsloc
, u32 optionsize
, u32 syn_packet
)
1228 union all_known_options
*all_options
;
1229 char got_mss_option
= 0;
1231 while (offset
< optionsize
) {
1232 all_options
= (union all_known_options
*)(optionsloc
+ offset
);
1233 switch (all_options
->as_base
.optionnum
) {
1234 case OPTION_NUMBER_END
:
1235 offset
= optionsize
;
1237 case OPTION_NUMBER_NONE
:
1240 case OPTION_NUMBER_MSS
:
1241 nes_debug(NES_DBG_CM
, "%s: MSS Length: %d Offset: %d Size: %d\n",
1243 all_options
->as_mss
.length
, offset
, optionsize
);
1245 if (all_options
->as_mss
.length
!= 4) {
1248 tmp
= ntohs(all_options
->as_mss
.mss
);
1249 if (tmp
> 0 && tmp
< cm_node
->tcp_cntxt
.mss
)
1250 cm_node
->tcp_cntxt
.mss
= tmp
;
1253 case OPTION_NUMBER_WINDOW_SCALE
:
1254 cm_node
->tcp_cntxt
.snd_wscale
= all_options
->as_windowscale
.shiftcount
;
1256 case OPTION_NUMBER_WRITE0
:
1257 cm_node
->send_write0
= 1;
1260 nes_debug(NES_DBG_CM
, "TCP Option not understood: %x\n",
1261 all_options
->as_base
.optionnum
);
1264 offset
+= all_options
->as_base
.length
;
1266 if ((!got_mss_option
) && (syn_packet
))
1267 cm_node
->tcp_cntxt
.mss
= NES_CM_DEFAULT_MSS
;
1275 int process_packet(struct nes_cm_node
*cm_node
, struct sk_buff
*skb
,
1276 struct nes_cm_core
*cm_core
)
1281 struct tcphdr
*tcph
= tcp_hdr(skb
);
1283 if (cm_node
->state
== NES_CM_STATE_SYN_SENT
&& tcph
->syn
) {
1284 inc_sequence
= ntohl(tcph
->seq
);
1285 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
;
1288 if ((!tcph
) || (cm_node
->state
== NES_CM_STATE_TSA
)) {
1290 atomic_inc(&cm_accel_dropped_pkts
);
1295 atomic_inc(&cm_resets_recvd
);
1296 nes_debug(NES_DBG_CM
, "Received Reset, cm_node = %p, state = %u. refcnt=%d\n",
1297 cm_node
, cm_node
->state
, atomic_read(&cm_node
->ref_count
));
1298 switch (cm_node
->state
) {
1299 case NES_CM_STATE_LISTENING
:
1300 rem_ref_cm_node(cm_core
, cm_node
);
1302 case NES_CM_STATE_TSA
:
1303 case NES_CM_STATE_CLOSED
:
1305 case NES_CM_STATE_SYN_RCVD
:
1306 nes_debug(NES_DBG_CM
, "Received a reset for local 0x%08X:%04X,"
1307 " remote 0x%08X:%04X, node state = %u\n",
1308 cm_node
->loc_addr
, cm_node
->loc_port
,
1309 cm_node
->rem_addr
, cm_node
->rem_port
,
1311 rem_ref_cm_node(cm_core
, cm_node
);
1313 case NES_CM_STATE_ONE_SIDE_ESTABLISHED
:
1314 case NES_CM_STATE_ESTABLISHED
:
1315 case NES_CM_STATE_MPAREQ_SENT
:
1317 nes_debug(NES_DBG_CM
, "Received a reset for local 0x%08X:%04X,"
1318 " remote 0x%08X:%04X, node state = %u refcnt=%d\n",
1319 cm_node
->loc_addr
, cm_node
->loc_port
,
1320 cm_node
->rem_addr
, cm_node
->rem_port
,
1321 cm_node
->state
, atomic_read(&cm_node
->ref_count
));
1323 cm_node
->state
= NES_CM_STATE_CLOSED
;
1325 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
1332 optionsize
= (tcph
->doff
<< 2) - sizeof(struct tcphdr
);
1334 skb_pull(skb
, ip_hdr(skb
)->ihl
<< 2);
1335 skb_pull(skb
, tcph
->doff
<< 2);
1337 datasize
= skb
->len
;
1338 inc_sequence
= ntohl(tcph
->seq
);
1339 nes_debug(NES_DBG_CM
, "datasize = %u, sequence = 0x%08X, ack_seq = 0x%08X,"
1340 " rcv_nxt = 0x%08X Flags: %s %s.\n",
1341 datasize
, inc_sequence
, ntohl(tcph
->ack_seq
),
1342 cm_node
->tcp_cntxt
.rcv_nxt
, (tcph
->syn
? "SYN":""),
1343 (tcph
->ack
? "ACK":""));
1345 if (!tcph
->syn
&& (inc_sequence
!= cm_node
->tcp_cntxt
.rcv_nxt
)
1347 nes_debug(NES_DBG_CM
, "dropping packet, datasize = %u, sequence = 0x%08X,"
1348 " ack_seq = 0x%08X, rcv_nxt = 0x%08X Flags: %s.\n",
1349 datasize
, inc_sequence
, ntohl(tcph
->ack_seq
),
1350 cm_node
->tcp_cntxt
.rcv_nxt
, (tcph
->ack
? "ACK":""));
1351 if (cm_node
->state
== NES_CM_STATE_LISTENING
) {
1352 rem_ref_cm_node(cm_core
, cm_node
);
1357 cm_node
->tcp_cntxt
.rcv_nxt
= inc_sequence
+ datasize
;
1361 u8
*optionsloc
= (u8
*)&tcph
[1];
1362 if (process_options(cm_node
, optionsloc
, optionsize
, (u32
)tcph
->syn
)) {
1363 nes_debug(NES_DBG_CM
, "%s: Node %p, Sending RESET\n", __FUNCTION__
, cm_node
);
1364 send_reset(cm_node
);
1365 if (cm_node
->state
!= NES_CM_STATE_SYN_SENT
)
1366 rem_ref_cm_node(cm_core
, cm_node
);
1369 } else if (tcph
->syn
)
1370 cm_node
->tcp_cntxt
.mss
= NES_CM_DEFAULT_MSS
;
1372 cm_node
->tcp_cntxt
.snd_wnd
= ntohs(tcph
->window
) <<
1373 cm_node
->tcp_cntxt
.snd_wscale
;
1375 if (cm_node
->tcp_cntxt
.snd_wnd
> cm_node
->tcp_cntxt
.max_snd_wnd
) {
1376 cm_node
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.snd_wnd
;
1380 cm_node
->tcp_cntxt
.rem_ack_num
= ntohl(tcph
->ack_seq
);
1381 switch (cm_node
->state
) {
1382 case NES_CM_STATE_SYN_RCVD
:
1383 case NES_CM_STATE_SYN_SENT
:
1384 /* read and stash current sequence number */
1385 if (cm_node
->tcp_cntxt
.rem_ack_num
!= cm_node
->tcp_cntxt
.loc_seq_num
) {
1386 nes_debug(NES_DBG_CM
, "ERROR - cm_node->tcp_cntxt.rem_ack_num !="
1387 " cm_node->tcp_cntxt.loc_seq_num\n");
1388 send_reset(cm_node
);
1391 if (cm_node
->state
== NES_CM_STATE_SYN_SENT
)
1392 cm_node
->state
= NES_CM_STATE_ONE_SIDE_ESTABLISHED
;
1394 cm_node
->state
= NES_CM_STATE_ESTABLISHED
;
1397 case NES_CM_STATE_LAST_ACK
:
1398 cm_node
->state
= NES_CM_STATE_CLOSED
;
1400 case NES_CM_STATE_FIN_WAIT1
:
1401 cm_node
->state
= NES_CM_STATE_FIN_WAIT2
;
1403 case NES_CM_STATE_CLOSING
:
1404 cm_node
->state
= NES_CM_STATE_TIME_WAIT
;
1405 /* need to schedule this to happen in 2MSL timeouts */
1406 cm_node
->state
= NES_CM_STATE_CLOSED
;
1408 case NES_CM_STATE_ONE_SIDE_ESTABLISHED
:
1409 case NES_CM_STATE_ESTABLISHED
:
1410 case NES_CM_STATE_MPAREQ_SENT
:
1411 case NES_CM_STATE_CLOSE_WAIT
:
1412 case NES_CM_STATE_TIME_WAIT
:
1413 case NES_CM_STATE_CLOSED
:
1415 case NES_CM_STATE_LISTENING
:
1416 nes_debug(NES_DBG_CM
, "Received an ACK on a listening port (SYN %d)\n", tcph
->syn
);
1417 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
1418 send_reset(cm_node
);
1419 /* send_reset bumps refcount, this should have been a new node */
1420 rem_ref_cm_node(cm_core
, cm_node
);
1423 case NES_CM_STATE_TSA
:
1424 nes_debug(NES_DBG_CM
, "Received a packet with the ack bit set while in TSA state\n");
1426 case NES_CM_STATE_UNKNOWN
:
1427 case NES_CM_STATE_INITED
:
1428 case NES_CM_STATE_ACCEPTING
:
1429 case NES_CM_STATE_FIN_WAIT2
:
1431 nes_debug(NES_DBG_CM
, "Received ack from unknown state: %x\n",
1433 send_reset(cm_node
);
1439 if (cm_node
->state
== NES_CM_STATE_LISTENING
) {
1440 /* do not exceed backlog */
1441 atomic_inc(&cm_node
->listener
->pend_accepts_cnt
);
1442 if (atomic_read(&cm_node
->listener
->pend_accepts_cnt
) >
1443 cm_node
->listener
->backlog
) {
1444 nes_debug(NES_DBG_CM
, "drop syn due to backlog pressure \n");
1446 atomic_dec(&cm_node
->listener
->pend_accepts_cnt
);
1447 rem_ref_cm_node(cm_core
, cm_node
);
1450 cm_node
->accept_pend
= 1;
1454 cm_node
->tcp_cntxt
.rcv_nxt
++;
1456 if (cm_node
->state
== NES_CM_STATE_LISTENING
) {
1457 cm_node
->state
= NES_CM_STATE_SYN_RCVD
;
1458 send_syn(cm_node
, 1);
1460 if (cm_node
->state
== NES_CM_STATE_ONE_SIDE_ESTABLISHED
) {
1461 cm_node
->state
= NES_CM_STATE_ESTABLISHED
;
1462 /* send final handshake ACK */
1463 ret
= send_ack(cm_node
);
1467 cm_node
->state
= NES_CM_STATE_MPAREQ_SENT
;
1468 ret
= send_mpa_request(cm_node
);
1475 cm_node
->tcp_cntxt
.rcv_nxt
++;
1476 switch (cm_node
->state
) {
1477 case NES_CM_STATE_SYN_RCVD
:
1478 case NES_CM_STATE_SYN_SENT
:
1479 case NES_CM_STATE_ONE_SIDE_ESTABLISHED
:
1480 case NES_CM_STATE_ESTABLISHED
:
1481 case NES_CM_STATE_ACCEPTING
:
1482 case NES_CM_STATE_MPAREQ_SENT
:
1483 cm_node
->state
= NES_CM_STATE_CLOSE_WAIT
;
1484 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
1485 ret
= send_fin(cm_node
, NULL
);
1487 case NES_CM_STATE_FIN_WAIT1
:
1488 cm_node
->state
= NES_CM_STATE_CLOSING
;
1489 ret
= send_ack(cm_node
);
1491 case NES_CM_STATE_FIN_WAIT2
:
1492 cm_node
->state
= NES_CM_STATE_TIME_WAIT
;
1493 cm_node
->tcp_cntxt
.loc_seq_num
++;
1494 ret
= send_ack(cm_node
);
1495 /* need to schedule this to happen in 2MSL timeouts */
1496 cm_node
->state
= NES_CM_STATE_CLOSED
;
1498 case NES_CM_STATE_CLOSE_WAIT
:
1499 case NES_CM_STATE_LAST_ACK
:
1500 case NES_CM_STATE_CLOSING
:
1501 case NES_CM_STATE_TSA
:
1503 nes_debug(NES_DBG_CM
, "Received a fin while in %x state\n",
1511 u8
*dataloc
= skb
->data
;
1512 /* figure out what state we are in and handle transition to next state */
1513 switch (cm_node
->state
) {
1514 case NES_CM_STATE_LISTENING
:
1515 case NES_CM_STATE_SYN_RCVD
:
1516 case NES_CM_STATE_SYN_SENT
:
1517 case NES_CM_STATE_FIN_WAIT1
:
1518 case NES_CM_STATE_FIN_WAIT2
:
1519 case NES_CM_STATE_CLOSE_WAIT
:
1520 case NES_CM_STATE_LAST_ACK
:
1521 case NES_CM_STATE_CLOSING
:
1523 case NES_CM_STATE_MPAREQ_SENT
:
1524 /* recv the mpa res frame, ret=frame len (incl priv data) */
1525 ret
= parse_mpa(cm_node
, dataloc
, datasize
);
1528 /* set the req frame payload len in skb */
1529 /* we are done handling this state, set node to a TSA state */
1530 cm_node
->state
= NES_CM_STATE_TSA
;
1532 create_event(cm_node
, NES_CM_EVENT_CONNECTED
);
1535 case NES_CM_STATE_ESTABLISHED
:
1536 /* we are expecting an MPA req frame */
1537 ret
= parse_mpa(cm_node
, dataloc
, datasize
);
1541 cm_node
->state
= NES_CM_STATE_TSA
;
1543 /* we got a valid MPA request, create an event */
1544 create_event(cm_node
, NES_CM_EVENT_MPA_REQ
);
1546 case NES_CM_STATE_TSA
:
1547 handle_exception_pkt(cm_node
, skb
);
1549 case NES_CM_STATE_UNKNOWN
:
1550 case NES_CM_STATE_INITED
:
1561 * mini_cm_listen - create a listen node with params
1563 static struct nes_cm_listener
*mini_cm_listen(struct nes_cm_core
*cm_core
,
1564 struct nes_vnic
*nesvnic
, struct nes_cm_info
*cm_info
)
1566 struct nes_cm_listener
*listener
;
1567 unsigned long flags
;
1569 nes_debug(NES_DBG_CM
, "Search for 0x%08x : 0x%04x\n",
1570 cm_info
->loc_addr
, cm_info
->loc_port
);
1572 /* cannot have multiple matching listeners */
1573 listener
= find_listener(cm_core
, htonl(cm_info
->loc_addr
),
1574 htons(cm_info
->loc_port
), NES_CM_LISTENER_EITHER_STATE
);
1575 if (listener
&& listener
->listener_state
== NES_CM_LISTENER_ACTIVE_STATE
) {
1576 /* find automatically incs ref count ??? */
1577 atomic_dec(&listener
->ref_count
);
1578 nes_debug(NES_DBG_CM
, "Not creating listener since it already exists\n");
1583 /* create a CM listen node (1/2 node to compare incoming traffic to) */
1584 listener
= kzalloc(sizeof(*listener
), GFP_ATOMIC
);
1586 nes_debug(NES_DBG_CM
, "Not creating listener memory allocation failed\n");
1590 memset(listener
, 0, sizeof(struct nes_cm_listener
));
1591 listener
->loc_addr
= htonl(cm_info
->loc_addr
);
1592 listener
->loc_port
= htons(cm_info
->loc_port
);
1593 listener
->reused_node
= 0;
1595 atomic_set(&listener
->ref_count
, 1);
1598 /* find already inc'ed the ref count */
1600 listener
->reused_node
= 1;
1603 listener
->cm_id
= cm_info
->cm_id
;
1604 atomic_set(&listener
->pend_accepts_cnt
, 0);
1605 listener
->cm_core
= cm_core
;
1606 listener
->nesvnic
= nesvnic
;
1607 atomic_inc(&cm_core
->node_cnt
);
1608 atomic_inc(&cm_core
->session_id
);
1610 listener
->session_id
= (u32
)(atomic_read(&cm_core
->session_id
) + current
->tgid
);
1611 listener
->conn_type
= cm_info
->conn_type
;
1612 listener
->backlog
= cm_info
->backlog
;
1613 listener
->listener_state
= NES_CM_LISTENER_ACTIVE_STATE
;
1615 if (!listener
->reused_node
) {
1616 spin_lock_irqsave(&cm_core
->listen_list_lock
, flags
);
1617 list_add(&listener
->list
, &cm_core
->listen_list
.list
);
1618 spin_unlock_irqrestore(&cm_core
->listen_list_lock
, flags
);
1619 atomic_inc(&cm_core
->listen_node_cnt
);
1622 nes_debug(NES_DBG_CM
, "Api - listen(): addr=0x%08X, port=0x%04x,"
1623 " listener = %p, backlog = %d, cm_id = %p.\n",
1624 cm_info
->loc_addr
, cm_info
->loc_port
,
1625 listener
, listener
->backlog
, listener
->cm_id
);
1632 * mini_cm_connect - make a connection node with params
1634 struct nes_cm_node
*mini_cm_connect(struct nes_cm_core
*cm_core
,
1635 struct nes_vnic
*nesvnic
, struct ietf_mpa_frame
*mpa_frame
,
1636 struct nes_cm_info
*cm_info
)
1639 struct nes_cm_node
*cm_node
;
1640 struct nes_cm_listener
*loopbackremotelistener
;
1641 struct nes_cm_node
*loopbackremotenode
;
1642 struct nes_cm_info loopback_cm_info
;
1644 u16 mpa_frame_size
= sizeof(struct ietf_mpa_frame
) +
1645 ntohs(mpa_frame
->priv_data_len
);
1647 cm_info
->loc_addr
= htonl(cm_info
->loc_addr
);
1648 cm_info
->rem_addr
= htonl(cm_info
->rem_addr
);
1649 cm_info
->loc_port
= htons(cm_info
->loc_port
);
1650 cm_info
->rem_port
= htons(cm_info
->rem_port
);
1652 /* create a CM connection node */
1653 cm_node
= make_cm_node(cm_core
, nesvnic
, cm_info
, NULL
);
1657 // set our node side to client (active) side
1658 cm_node
->tcp_cntxt
.client
= 1;
1659 cm_node
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
1661 if (cm_info
->loc_addr
== cm_info
->rem_addr
) {
1662 loopbackremotelistener
= find_listener(cm_core
, cm_node
->rem_addr
,
1663 cm_node
->rem_port
, NES_CM_LISTENER_ACTIVE_STATE
);
1664 if (loopbackremotelistener
== NULL
) {
1665 create_event(cm_node
, NES_CM_EVENT_ABORTED
);
1667 atomic_inc(&cm_loopbacks
);
1668 loopback_cm_info
= *cm_info
;
1669 loopback_cm_info
.loc_port
= cm_info
->rem_port
;
1670 loopback_cm_info
.rem_port
= cm_info
->loc_port
;
1671 loopback_cm_info
.cm_id
= loopbackremotelistener
->cm_id
;
1672 loopbackremotenode
= make_cm_node(cm_core
, nesvnic
, &loopback_cm_info
,
1673 loopbackremotelistener
);
1674 loopbackremotenode
->loopbackpartner
= cm_node
;
1675 loopbackremotenode
->tcp_cntxt
.rcv_wscale
= NES_CM_DEFAULT_RCV_WND_SCALE
;
1676 cm_node
->loopbackpartner
= loopbackremotenode
;
1677 memcpy(loopbackremotenode
->mpa_frame_buf
, &mpa_frame
->priv_data
,
1679 loopbackremotenode
->mpa_frame_size
= mpa_frame_size
-
1680 sizeof(struct ietf_mpa_frame
);
1682 // we are done handling this state, set node to a TSA state
1683 cm_node
->state
= NES_CM_STATE_TSA
;
1684 cm_node
->tcp_cntxt
.rcv_nxt
= loopbackremotenode
->tcp_cntxt
.loc_seq_num
;
1685 loopbackremotenode
->tcp_cntxt
.rcv_nxt
= cm_node
->tcp_cntxt
.loc_seq_num
;
1686 cm_node
->tcp_cntxt
.max_snd_wnd
= loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
1687 loopbackremotenode
->tcp_cntxt
.max_snd_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
1688 cm_node
->tcp_cntxt
.snd_wnd
= loopbackremotenode
->tcp_cntxt
.rcv_wnd
;
1689 loopbackremotenode
->tcp_cntxt
.snd_wnd
= cm_node
->tcp_cntxt
.rcv_wnd
;
1690 cm_node
->tcp_cntxt
.snd_wscale
= loopbackremotenode
->tcp_cntxt
.rcv_wscale
;
1691 loopbackremotenode
->tcp_cntxt
.snd_wscale
= cm_node
->tcp_cntxt
.rcv_wscale
;
1693 create_event(loopbackremotenode
, NES_CM_EVENT_MPA_REQ
);
1698 /* set our node side to client (active) side */
1699 cm_node
->tcp_cntxt
.client
= 1;
1700 /* init our MPA frame ptr */
1701 memcpy(&cm_node
->mpa_frame
, mpa_frame
, mpa_frame_size
);
1702 cm_node
->mpa_frame_size
= mpa_frame_size
;
1704 /* send a syn and goto syn sent state */
1705 cm_node
->state
= NES_CM_STATE_SYN_SENT
;
1706 ret
= send_syn(cm_node
, 0);
1708 nes_debug(NES_DBG_CM
, "Api - connect(): dest addr=0x%08X, port=0x%04x,"
1709 " cm_node=%p, cm_id = %p.\n",
1710 cm_node
->rem_addr
, cm_node
->rem_port
, cm_node
, cm_node
->cm_id
);
1717 * mini_cm_accept - accept a connection
1718 * This function is never called
1720 int mini_cm_accept(struct nes_cm_core
*cm_core
, struct ietf_mpa_frame
*mpa_frame
,
1721 struct nes_cm_node
*cm_node
)
1728 * mini_cm_reject - reject and teardown a connection
1730 int mini_cm_reject(struct nes_cm_core
*cm_core
,
1731 struct ietf_mpa_frame
*mpa_frame
,
1732 struct nes_cm_node
*cm_node
)
1735 struct sk_buff
*skb
;
1736 u16 mpa_frame_size
= sizeof(struct ietf_mpa_frame
) +
1737 ntohs(mpa_frame
->priv_data_len
);
1739 skb
= get_free_pkt(cm_node
);
1741 nes_debug(NES_DBG_CM
, "Failed to get a Free pkt\n");
1745 /* send an MPA Request frame */
1746 form_cm_frame(skb
, cm_node
, NULL
, 0, mpa_frame
, mpa_frame_size
, SET_ACK
| SET_FIN
);
1747 ret
= schedule_nes_timer(cm_node
, skb
, NES_TIMER_TYPE_SEND
, 1, 0);
1749 cm_node
->state
= NES_CM_STATE_CLOSED
;
1750 ret
= send_fin(cm_node
, NULL
);
1753 printk(KERN_INFO PFX
"failed to send MPA Reply (reject)\n");
1764 int mini_cm_close(struct nes_cm_core
*cm_core
, struct nes_cm_node
*cm_node
)
1768 if (!cm_core
|| !cm_node
)
1771 switch (cm_node
->state
) {
1772 /* if passed in node is null, create a reference key node for node search */
1773 /* check if we found an owner node for this pkt */
1774 case NES_CM_STATE_SYN_RCVD
:
1775 case NES_CM_STATE_SYN_SENT
:
1776 case NES_CM_STATE_ONE_SIDE_ESTABLISHED
:
1777 case NES_CM_STATE_ESTABLISHED
:
1778 case NES_CM_STATE_ACCEPTING
:
1779 case NES_CM_STATE_MPAREQ_SENT
:
1780 cm_node
->state
= NES_CM_STATE_FIN_WAIT1
;
1781 send_fin(cm_node
, NULL
);
1783 case NES_CM_STATE_CLOSE_WAIT
:
1784 cm_node
->state
= NES_CM_STATE_LAST_ACK
;
1785 send_fin(cm_node
, NULL
);
1787 case NES_CM_STATE_FIN_WAIT1
:
1788 case NES_CM_STATE_FIN_WAIT2
:
1789 case NES_CM_STATE_LAST_ACK
:
1790 case NES_CM_STATE_TIME_WAIT
:
1791 case NES_CM_STATE_CLOSING
:
1794 case NES_CM_STATE_LISTENING
:
1795 case NES_CM_STATE_UNKNOWN
:
1796 case NES_CM_STATE_INITED
:
1797 case NES_CM_STATE_CLOSED
:
1798 case NES_CM_STATE_TSA
:
1799 ret
= rem_ref_cm_node(cm_core
, cm_node
);
1802 cm_node
->cm_id
= NULL
;
1808 * recv_pkt - recv an ETHERNET packet, and process it through CM
1809 * node state machine
1811 int mini_cm_recv_pkt(struct nes_cm_core
*cm_core
, struct nes_vnic
*nesvnic
,
1812 struct sk_buff
*skb
)
1814 struct nes_cm_node
*cm_node
= NULL
;
1815 struct nes_cm_listener
*listener
= NULL
;
1817 struct tcphdr
*tcph
;
1818 struct nes_cm_info nfo
;
1821 if (!skb
|| skb
->len
< sizeof(struct iphdr
) + sizeof(struct tcphdr
)) {
1826 iph
= (struct iphdr
*)skb
->data
;
1827 tcph
= (struct tcphdr
*)(skb
->data
+ sizeof(struct iphdr
));
1828 skb_reset_network_header(skb
);
1829 skb_set_transport_header(skb
, sizeof(*tcph
));
1830 skb
->len
= ntohs(iph
->tot_len
);
1832 nfo
.loc_addr
= ntohl(iph
->daddr
);
1833 nfo
.loc_port
= ntohs(tcph
->dest
);
1834 nfo
.rem_addr
= ntohl(iph
->saddr
);
1835 nfo
.rem_port
= ntohs(tcph
->source
);
1837 nes_debug(NES_DBG_CM
, "Received packet: dest=0x%08X:0x%04X src=0x%08X:0x%04X\n",
1838 iph
->daddr
, tcph
->dest
, iph
->saddr
, tcph
->source
);
1840 /* note: this call is going to increment cm_node ref count */
1841 cm_node
= find_node(cm_core
,
1842 nfo
.rem_port
, nfo
.rem_addr
,
1843 nfo
.loc_port
, nfo
.loc_addr
);
1846 listener
= find_listener(cm_core
, nfo
.loc_addr
, nfo
.loc_port
,
1847 NES_CM_LISTENER_ACTIVE_STATE
);
1849 nfo
.cm_id
= listener
->cm_id
;
1850 nfo
.conn_type
= listener
->conn_type
;
1856 cm_node
= make_cm_node(cm_core
, nesvnic
, &nfo
, listener
);
1858 nes_debug(NES_DBG_CM
, "Unable to allocate node\n");
1860 nes_debug(NES_DBG_CM
, "unable to allocate node and decrementing listener refcount\n");
1861 atomic_dec(&listener
->ref_count
);
1867 nes_debug(NES_DBG_CM
, "Packet found for unknown port %x refcnt=%d\n",
1868 nfo
.loc_port
, atomic_read(&cm_node
->ref_count
));
1870 nes_debug(NES_DBG_CM
, "Packet found for unknown port=%d"
1871 " rem_port=%d refcnt=%d\n",
1872 nfo
.loc_port
, nfo
.rem_port
, atomic_read(&cm_node
->ref_count
));
1874 cm_node
->tcp_cntxt
.rcv_nxt
= ntohl(tcph
->seq
);
1875 cm_node
->tcp_cntxt
.loc_seq_num
= ntohl(tcph
->ack_seq
);
1876 send_reset(cm_node
);
1878 rem_ref_cm_node(cm_core
, cm_node
);
1882 add_ref_cm_node(cm_node
);
1883 cm_node
->state
= NES_CM_STATE_LISTENING
;
1886 nes_debug(NES_DBG_CM
, "Processing Packet for node %p, data = (%p):\n",
1887 cm_node
, skb
->data
);
1888 process_packet(cm_node
, skb
, cm_core
);
1890 rem_ref_cm_node(cm_core
, cm_node
);
1893 dev_kfree_skb_any(skb
);
1899 * nes_cm_alloc_core - allocate a top level instance of a cm core
1901 struct nes_cm_core
*nes_cm_alloc_core(void)
1905 struct nes_cm_core
*cm_core
;
1906 struct sk_buff
*skb
= NULL
;
1908 /* setup the CM core */
1909 /* alloc top level core control structure */
1910 cm_core
= kzalloc(sizeof(*cm_core
), GFP_KERNEL
);
1914 INIT_LIST_HEAD(&cm_core
->connected_nodes
);
1915 init_timer(&cm_core
->tcp_timer
);
1916 cm_core
->tcp_timer
.function
= nes_cm_timer_tick
;
1918 cm_core
->mtu
= NES_CM_DEFAULT_MTU
;
1919 cm_core
->state
= NES_CM_STATE_INITED
;
1920 cm_core
->free_tx_pkt_max
= NES_CM_DEFAULT_FREE_PKTS
;
1922 atomic_set(&cm_core
->session_id
, 0);
1923 atomic_set(&cm_core
->events_posted
, 0);
1925 /* init the packet lists */
1926 skb_queue_head_init(&cm_core
->tx_free_list
);
1928 for (i
= 0; i
< NES_CM_DEFAULT_FRAME_CNT
; i
++) {
1929 skb
= dev_alloc_skb(cm_core
->mtu
);
1934 /* add 'raw' skb to free frame list */
1935 skb_queue_head(&cm_core
->tx_free_list
, skb
);
1938 cm_core
->api
= &nes_cm_api
;
1940 spin_lock_init(&cm_core
->ht_lock
);
1941 spin_lock_init(&cm_core
->listen_list_lock
);
1943 INIT_LIST_HEAD(&cm_core
->listen_list
.list
);
1945 nes_debug(NES_DBG_CM
, "Init CM Core completed -- cm_core=%p\n", cm_core
);
1947 nes_debug(NES_DBG_CM
, "Enable QUEUE EVENTS\n");
1948 cm_core
->event_wq
= create_singlethread_workqueue("nesewq");
1949 cm_core
->post_event
= nes_cm_post_event
;
1950 nes_debug(NES_DBG_CM
, "Enable QUEUE DISCONNECTS\n");
1951 cm_core
->disconn_wq
= create_singlethread_workqueue("nesdwq");
1953 print_core(cm_core
);
1959 * mini_cm_dealloc_core - deallocate a top level instance of a cm core
1961 int mini_cm_dealloc_core(struct nes_cm_core
*cm_core
)
1963 nes_debug(NES_DBG_CM
, "De-Alloc CM Core (%p)\n", cm_core
);
1970 if (timer_pending(&cm_core
->tcp_timer
)) {
1971 del_timer(&cm_core
->tcp_timer
);
1974 destroy_workqueue(cm_core
->event_wq
);
1975 destroy_workqueue(cm_core
->disconn_wq
);
1976 nes_debug(NES_DBG_CM
, "\n");
1986 int mini_cm_get(struct nes_cm_core
*cm_core
)
1988 return cm_core
->state
;
1995 int mini_cm_set(struct nes_cm_core
*cm_core
, u32 type
, u32 value
)
2000 case NES_CM_SET_PKT_SIZE
:
2001 cm_core
->mtu
= value
;
2003 case NES_CM_SET_FREE_PKT_Q_SIZE
:
2004 cm_core
->free_tx_pkt_max
= value
;
2007 /* unknown set option */
2016 * nes_cm_init_tsa_conn setup HW; MPA frames must be
2017 * successfully exchanged when this is called
2019 static int nes_cm_init_tsa_conn(struct nes_qp
*nesqp
, struct nes_cm_node
*cm_node
)
2026 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4
|
2027 NES_QPCONTEXT_MISC_NO_NAGLE
| NES_QPCONTEXT_MISC_DO_NOT_FRAG
|
2028 NES_QPCONTEXT_MISC_DROS
);
2030 if (cm_node
->tcp_cntxt
.snd_wscale
|| cm_node
->tcp_cntxt
.rcv_wscale
)
2031 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE
);
2033 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT
);
2035 nesqp
->nesqp_context
->mss
|= cpu_to_le32(((u32
)cm_node
->tcp_cntxt
.mss
) << 16);
2037 nesqp
->nesqp_context
->tcp_state_flow_label
|= cpu_to_le32(
2038 (u32
)NES_QPCONTEXT_TCPSTATE_EST
<< NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT
);
2040 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2041 (cm_node
->tcp_cntxt
.snd_wscale
<< NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT
) &
2042 NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK
);
2044 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32(
2045 (cm_node
->tcp_cntxt
.rcv_wscale
<< NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT
) &
2046 NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK
);
2048 nesqp
->nesqp_context
->keepalive
= cpu_to_le32(0x80);
2049 nesqp
->nesqp_context
->ts_recent
= 0;
2050 nesqp
->nesqp_context
->ts_age
= 0;
2051 nesqp
->nesqp_context
->snd_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2052 nesqp
->nesqp_context
->snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.snd_wnd
);
2053 nesqp
->nesqp_context
->rcv_nxt
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2054 nesqp
->nesqp_context
->rcv_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_wnd
<<
2055 cm_node
->tcp_cntxt
.rcv_wscale
);
2056 nesqp
->nesqp_context
->snd_max
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2057 nesqp
->nesqp_context
->snd_una
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2058 nesqp
->nesqp_context
->srtt
= 0;
2059 nesqp
->nesqp_context
->rttvar
= cpu_to_le32(0x6);
2060 nesqp
->nesqp_context
->ssthresh
= cpu_to_le32(0x3FFFC000);
2061 nesqp
->nesqp_context
->cwnd
= cpu_to_le32(2*cm_node
->tcp_cntxt
.mss
);
2062 nesqp
->nesqp_context
->snd_wl1
= cpu_to_le32(cm_node
->tcp_cntxt
.rcv_nxt
);
2063 nesqp
->nesqp_context
->snd_wl2
= cpu_to_le32(cm_node
->tcp_cntxt
.loc_seq_num
);
2064 nesqp
->nesqp_context
->max_snd_wnd
= cpu_to_le32(cm_node
->tcp_cntxt
.max_snd_wnd
);
2066 nes_debug(NES_DBG_CM
, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
2067 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
2068 nesqp
->hwqp
.qp_id
, le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
2069 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
2070 cm_node
->tcp_cntxt
.mss
, le32_to_cpu(nesqp
->nesqp_context
->pd_index_wscale
),
2071 le32_to_cpu(nesqp
->nesqp_context
->rcv_wnd
),
2072 le32_to_cpu(nesqp
->nesqp_context
->misc
));
2073 nes_debug(NES_DBG_CM
, " snd_wnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->snd_wnd
));
2074 nes_debug(NES_DBG_CM
, " snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->cwnd
));
2075 nes_debug(NES_DBG_CM
, " max_swnd = 0x%08X.\n", le32_to_cpu(nesqp
->nesqp_context
->max_snd_wnd
));
2077 nes_debug(NES_DBG_CM
, "Change cm_node state to TSA\n");
2078 cm_node
->state
= NES_CM_STATE_TSA
;
2087 int nes_cm_disconn(struct nes_qp
*nesqp
)
2089 unsigned long flags
;
2091 spin_lock_irqsave(&nesqp
->lock
, flags
);
2092 if (nesqp
->disconn_pending
== 0) {
2093 nesqp
->disconn_pending
++;
2094 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2095 /* nes_add_ref(&nesqp->ibqp); */
2096 /* init our disconnect work element, to */
2097 INIT_WORK(&nesqp
->disconn_work
, nes_disconnect_worker
);
2099 queue_work(g_cm_core
->disconn_wq
, &nesqp
->disconn_work
);
2101 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2102 nes_rem_ref(&nesqp
->ibqp
);
2110 * nes_disconnect_worker
2112 void nes_disconnect_worker(struct work_struct
*work
)
2114 struct nes_qp
*nesqp
= container_of(work
, struct nes_qp
, disconn_work
);
2116 nes_debug(NES_DBG_CM
, "processing AEQE id 0x%04X for QP%u.\n",
2117 nesqp
->last_aeq
, nesqp
->hwqp
.qp_id
);
2118 nes_cm_disconn_true(nesqp
);
2123 * nes_cm_disconn_true
2125 int nes_cm_disconn_true(struct nes_qp
*nesqp
)
2127 unsigned long flags
;
2129 struct iw_cm_id
*cm_id
;
2130 struct iw_cm_event cm_event
;
2131 struct nes_vnic
*nesvnic
;
2133 u8 original_hw_tcp_state
;
2134 u8 original_ibqp_state
;
2135 u8 issued_disconnect_reset
= 0;
2138 nes_debug(NES_DBG_CM
, "disconnect_worker nesqp is NULL\n");
2142 spin_lock_irqsave(&nesqp
->lock
, flags
);
2143 cm_id
= nesqp
->cm_id
;
2144 /* make sure we havent already closed this connection */
2146 nes_debug(NES_DBG_CM
, "QP%u disconnect_worker cmid is NULL\n",
2148 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2149 nes_rem_ref(&nesqp
->ibqp
);
2153 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2154 nes_debug(NES_DBG_CM
, "Disconnecting QP%u\n", nesqp
->hwqp
.qp_id
);
2156 original_hw_tcp_state
= nesqp
->hw_tcp_state
;
2157 original_ibqp_state
= nesqp
->ibqp_state
;
2158 last_ae
= nesqp
->last_aeq
;
2161 nes_debug(NES_DBG_CM
, "set ibqp_state=%u\n", nesqp
->ibqp_state
);
2163 if ((nesqp
->cm_id
) && (cm_id
->event_handler
)) {
2164 if ((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSE_WAIT
) ||
2165 ((original_ibqp_state
== IB_QPS_RTS
) &&
2166 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2167 atomic_inc(&cm_disconnects
);
2168 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
2169 if (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
) {
2170 issued_disconnect_reset
= 1;
2171 cm_event
.status
= IW_CM_EVENT_STATUS_RESET
;
2172 nes_debug(NES_DBG_CM
, "Generating a CM Disconnect Event (status reset) for "
2173 " QP%u, cm_id = %p. \n",
2174 nesqp
->hwqp
.qp_id
, cm_id
);
2176 cm_event
.status
= IW_CM_EVENT_STATUS_OK
;
2179 cm_event
.local_addr
= cm_id
->local_addr
;
2180 cm_event
.remote_addr
= cm_id
->remote_addr
;
2181 cm_event
.private_data
= NULL
;
2182 cm_event
.private_data_len
= 0;
2184 nes_debug(NES_DBG_CM
, "Generating a CM Disconnect Event for "
2185 " QP%u, SQ Head = %u, SQ Tail = %u. cm_id = %p, refcount = %u.\n",
2187 nesqp
->hwqp
.sq_head
, nesqp
->hwqp
.sq_tail
, cm_id
,
2188 atomic_read(&nesqp
->refcount
));
2190 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2191 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2193 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
2194 spin_lock_irqsave(&nesqp
->lock
, flags
);
2197 nesqp
->disconn_pending
= 0;
2198 /* There might have been another AE while the lock was released */
2199 original_hw_tcp_state
= nesqp
->hw_tcp_state
;
2200 original_ibqp_state
= nesqp
->ibqp_state
;
2201 last_ae
= nesqp
->last_aeq
;
2203 if ((issued_disconnect_reset
== 0) && (nesqp
->cm_id
) &&
2204 ((original_hw_tcp_state
== NES_AEQE_TCP_STATE_CLOSED
) ||
2205 (original_hw_tcp_state
== NES_AEQE_TCP_STATE_TIME_WAIT
) ||
2206 (last_ae
== NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
) ||
2207 (last_ae
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2208 atomic_inc(&cm_closes
);
2209 nesqp
->cm_id
= NULL
;
2210 nesqp
->in_disconnect
= 0;
2211 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2212 nes_disconnect(nesqp
, 1);
2214 cm_id
->provider_data
= nesqp
;
2215 /* Send up the close complete event */
2216 cm_event
.event
= IW_CM_EVENT_CLOSE
;
2217 cm_event
.status
= IW_CM_EVENT_STATUS_OK
;
2218 cm_event
.provider_data
= cm_id
->provider_data
;
2219 cm_event
.local_addr
= cm_id
->local_addr
;
2220 cm_event
.remote_addr
= cm_id
->remote_addr
;
2221 cm_event
.private_data
= NULL
;
2222 cm_event
.private_data_len
= 0;
2224 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2226 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
2229 cm_id
->rem_ref(cm_id
);
2231 spin_lock_irqsave(&nesqp
->lock
, flags
);
2232 if (nesqp
->flush_issued
== 0) {
2233 nesqp
->flush_issued
= 1;
2234 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2235 flush_wqes(nesvnic
->nesdev
, nesqp
, NES_CQP_FLUSH_RQ
, 1);
2237 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2240 /* This reference is from either ModifyQP or the AE processing,
2241 there is still a race here with modifyqp */
2242 nes_rem_ref(&nesqp
->ibqp
);
2245 cm_id
= nesqp
->cm_id
;
2246 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2247 /* check to see if the inbound reset beat the outbound reset */
2248 if ((!cm_id
) && (last_ae
==NES_AEQE_AEID_RESET_SENT
)) {
2249 nes_debug(NES_DBG_CM
, "QP%u: Decing refcount due to inbound reset"
2250 " beating the outbound reset.\n",
2252 nes_rem_ref(&nesqp
->ibqp
);
2256 nesqp
->disconn_pending
= 0;
2257 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2259 nes_rem_ref(&nesqp
->ibqp
);
2268 int nes_disconnect(struct nes_qp
*nesqp
, int abrupt
)
2271 struct nes_vnic
*nesvnic
;
2272 struct nes_device
*nesdev
;
2274 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2278 nesdev
= nesvnic
->nesdev
;
2280 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
2281 atomic_read(&nesvnic
->netdev
->refcnt
));
2283 if (nesqp
->active_conn
) {
2285 /* indicate this connection is NOT active */
2286 nesqp
->active_conn
= 0;
2288 /* Need to free the Last Streaming Mode Message */
2289 if (nesqp
->ietf_frame
) {
2290 pci_free_consistent(nesdev
->pcidev
,
2291 nesqp
->private_data_len
+sizeof(struct ietf_mpa_frame
),
2292 nesqp
->ietf_frame
, nesqp
->ietf_frame_pbase
);
2296 /* close the CM node down if it is still active */
2297 if (nesqp
->cm_node
) {
2298 nes_debug(NES_DBG_CM
, "Call close API\n");
2300 g_cm_core
->api
->close(g_cm_core
, nesqp
->cm_node
);
2301 nesqp
->cm_node
= NULL
;
2311 int nes_accept(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
2315 struct nes_qp
*nesqp
;
2316 struct nes_vnic
*nesvnic
;
2317 struct nes_device
*nesdev
;
2318 struct nes_cm_node
*cm_node
;
2319 struct nes_adapter
*adapter
;
2320 struct ib_qp_attr attr
;
2321 struct iw_cm_event cm_event
;
2322 struct nes_hw_qp_wqe
*wqe
;
2323 struct nes_v4_quad nes_quad
;
2327 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
2331 /* get all our handles */
2332 nesqp
= to_nesqp(ibqp
);
2333 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2334 nesdev
= nesvnic
->nesdev
;
2335 adapter
= nesdev
->nesadapter
;
2337 nes_debug(NES_DBG_CM
, "nesvnic=%p, netdev=%p, %s\n",
2338 nesvnic
, nesvnic
->netdev
, nesvnic
->netdev
->name
);
2340 /* since this is from a listen, we were able to put node handle into cm_id */
2341 cm_node
= (struct nes_cm_node
*)cm_id
->provider_data
;
2343 /* associate the node with the QP */
2344 nesqp
->cm_node
= (void *)cm_node
;
2346 nes_debug(NES_DBG_CM
, "QP%u, cm_node=%p, jiffies = %lu\n",
2347 nesqp
->hwqp
.qp_id
, cm_node
, jiffies
);
2348 atomic_inc(&cm_accepts
);
2350 nes_debug(NES_DBG_CM
, "netdev refcnt = %u.\n",
2351 atomic_read(&nesvnic
->netdev
->refcnt
));
2353 /* allocate the ietf frame and space for private data */
2354 nesqp
->ietf_frame
= pci_alloc_consistent(nesdev
->pcidev
,
2355 sizeof(struct ietf_mpa_frame
) + conn_param
->private_data_len
,
2356 &nesqp
->ietf_frame_pbase
);
2358 if (!nesqp
->ietf_frame
) {
2359 nes_debug(NES_DBG_CM
, "Unable to allocate memory for private data\n");
2364 /* setup the MPA frame */
2365 nesqp
->private_data_len
= conn_param
->private_data_len
;
2366 memcpy(nesqp
->ietf_frame
->key
, IEFT_MPA_KEY_REP
, IETF_MPA_KEY_SIZE
);
2368 memcpy(nesqp
->ietf_frame
->priv_data
, conn_param
->private_data
,
2369 conn_param
->private_data_len
);
2371 nesqp
->ietf_frame
->priv_data_len
= cpu_to_be16(conn_param
->private_data_len
);
2372 nesqp
->ietf_frame
->rev
= mpa_version
;
2373 nesqp
->ietf_frame
->flags
= IETF_MPA_FLAGS_CRC
;
2375 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
2376 wqe
= &nesqp
->hwqp
.sq_vbase
[0];
2378 if (cm_id
->remote_addr
.sin_addr
.s_addr
!= cm_id
->local_addr
.sin_addr
.s_addr
) {
2379 u64temp
= (unsigned long)nesqp
;
2380 u64temp
|= NES_SW_CONTEXT_ALIGN
>>1;
2381 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
,
2383 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] =
2384 cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING
| NES_IWARP_SQ_WQE_WRPDU
);
2385 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] =
2386 cpu_to_le32(conn_param
->private_data_len
+ sizeof(struct ietf_mpa_frame
));
2387 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
] =
2388 cpu_to_le32((u32
)nesqp
->ietf_frame_pbase
);
2389 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX
] =
2390 cpu_to_le32((u32
)((u64
)nesqp
->ietf_frame_pbase
>> 32));
2391 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] =
2392 cpu_to_le32(conn_param
->private_data_len
+ sizeof(struct ietf_mpa_frame
));
2393 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 0;
2395 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32(
2396 NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
| NES_QPCONTEXT_ORDIRD_WRPDU
);
2398 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32((NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
2399 NES_QPCONTEXT_ORDIRD_WRPDU
| NES_QPCONTEXT_ORDIRD_ALSMM
));
2401 nesqp
->skip_lsmm
= 1;
2404 /* Cache the cm_id in the qp */
2405 nesqp
->cm_id
= cm_id
;
2406 cm_node
->cm_id
= cm_id
;
2408 /* nesqp->cm_node = (void *)cm_id->provider_data; */
2409 cm_id
->provider_data
= nesqp
;
2410 nesqp
->active_conn
= 0;
2412 nes_cm_init_tsa_conn(nesqp
, cm_node
);
2414 nesqp
->nesqp_context
->tcpPorts
[0] = cpu_to_le16(ntohs(cm_id
->local_addr
.sin_port
));
2415 nesqp
->nesqp_context
->tcpPorts
[1] = cpu_to_le16(ntohs(cm_id
->remote_addr
.sin_port
));
2416 nesqp
->nesqp_context
->ip0
= cpu_to_le32(ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
));
2418 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
2419 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
2421 nesqp
->nesqp_context
->arp_index_vlan
|= cpu_to_le32(
2422 nes_arp_table(nesdev
, le32_to_cpu(nesqp
->nesqp_context
->ip0
), NULL
,
2423 NES_ARP_RESOLVE
) << 16);
2425 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
2426 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
2428 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
2430 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32(
2431 ((u32
)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
));
2432 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32((u32
)conn_param
->ord
);
2434 memset(&nes_quad
, 0, sizeof(nes_quad
));
2435 nes_quad
.DstIpAdrIndex
= cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
2436 nes_quad
.SrcIpadr
= cm_id
->remote_addr
.sin_addr
.s_addr
;
2437 nes_quad
.TcpPorts
[0] = cm_id
->remote_addr
.sin_port
;
2438 nes_quad
.TcpPorts
[1] = cm_id
->local_addr
.sin_port
;
2440 /* Produce hash key */
2441 crc_value
= get_crc_value(&nes_quad
);
2442 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
2443 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, CRC = 0x%08X\n",
2444 nesqp
->hte_index
, nesqp
->hte_index
& adapter
->hte_index_mask
);
2446 nesqp
->hte_index
&= adapter
->hte_index_mask
;
2447 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
2449 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
2451 nes_debug(NES_DBG_CM
, "QP%u, Destination IP = 0x%08X:0x%04X, local = 0x%08X:0x%04X,"
2452 " rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + private data length=%zu.\n",
2454 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
2455 ntohs(cm_id
->remote_addr
.sin_port
),
2456 ntohl(cm_id
->local_addr
.sin_addr
.s_addr
),
2457 ntohs(cm_id
->local_addr
.sin_port
),
2458 le32_to_cpu(nesqp
->nesqp_context
->rcv_nxt
),
2459 le32_to_cpu(nesqp
->nesqp_context
->snd_nxt
),
2460 conn_param
->private_data_len
+sizeof(struct ietf_mpa_frame
));
2462 attr
.qp_state
= IB_QPS_RTS
;
2463 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
2465 /* notify OF layer that accept event was successfull */
2466 cm_id
->add_ref(cm_id
);
2468 cm_event
.event
= IW_CM_EVENT_ESTABLISHED
;
2469 cm_event
.status
= IW_CM_EVENT_STATUS_ACCEPTED
;
2470 cm_event
.provider_data
= (void *)nesqp
;
2471 cm_event
.local_addr
= cm_id
->local_addr
;
2472 cm_event
.remote_addr
= cm_id
->remote_addr
;
2473 cm_event
.private_data
= NULL
;
2474 cm_event
.private_data_len
= 0;
2475 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2476 if (cm_node
->loopbackpartner
) {
2477 cm_node
->loopbackpartner
->mpa_frame_size
= nesqp
->private_data_len
;
2478 /* copy entire MPA frame to our cm_node's frame */
2479 memcpy(cm_node
->loopbackpartner
->mpa_frame_buf
, nesqp
->ietf_frame
->priv_data
,
2480 nesqp
->private_data_len
);
2481 create_event(cm_node
->loopbackpartner
, NES_CM_EVENT_CONNECTED
);
2484 printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
2485 __FUNCTION__
, __LINE__
, ret
);
2494 int nes_reject(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
)
2496 struct nes_cm_node
*cm_node
;
2497 struct nes_cm_core
*cm_core
;
2499 atomic_inc(&cm_rejects
);
2500 cm_node
= (struct nes_cm_node
*) cm_id
->provider_data
;
2501 cm_core
= cm_node
->cm_core
;
2502 cm_node
->mpa_frame_size
= sizeof(struct ietf_mpa_frame
) + pdata_len
;
2504 strcpy(&cm_node
->mpa_frame
.key
[0], IEFT_MPA_KEY_REP
);
2505 memcpy(&cm_node
->mpa_frame
.priv_data
, pdata
, pdata_len
);
2507 cm_node
->mpa_frame
.priv_data_len
= cpu_to_be16(pdata_len
);
2508 cm_node
->mpa_frame
.rev
= mpa_version
;
2509 cm_node
->mpa_frame
.flags
= IETF_MPA_FLAGS_CRC
| IETF_MPA_FLAGS_REJECT
;
2511 cm_core
->api
->reject(cm_core
, &cm_node
->mpa_frame
, cm_node
);
2519 * setup and launch cm connect node
2521 int nes_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
)
2524 struct nes_qp
*nesqp
;
2525 struct nes_vnic
*nesvnic
;
2526 struct nes_device
*nesdev
;
2527 struct nes_cm_node
*cm_node
;
2528 struct nes_cm_info cm_info
;
2530 ibqp
= nes_get_qp(cm_id
->device
, conn_param
->qpn
);
2533 nesqp
= to_nesqp(ibqp
);
2536 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2539 nesdev
= nesvnic
->nesdev
;
2543 atomic_inc(&cm_connects
);
2545 nesqp
->ietf_frame
= kzalloc(sizeof(struct ietf_mpa_frame
) +
2546 conn_param
->private_data_len
, GFP_KERNEL
);
2547 if (!nesqp
->ietf_frame
)
2550 /* set qp as having an active connection */
2551 nesqp
->active_conn
= 1;
2553 nes_debug(NES_DBG_CM
, "QP%u, Destination IP = 0x%08X:0x%04X, local = 0x%08X:0x%04X.\n",
2555 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
2556 ntohs(cm_id
->remote_addr
.sin_port
),
2557 ntohl(cm_id
->local_addr
.sin_addr
.s_addr
),
2558 ntohs(cm_id
->local_addr
.sin_port
));
2560 /* cache the cm_id in the qp */
2561 nesqp
->cm_id
= cm_id
;
2563 cm_id
->provider_data
= nesqp
;
2565 /* copy the private data */
2566 if (conn_param
->private_data_len
) {
2567 memcpy(nesqp
->ietf_frame
->priv_data
, conn_param
->private_data
,
2568 conn_param
->private_data_len
);
2571 nesqp
->private_data_len
= conn_param
->private_data_len
;
2572 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32((u32
)conn_param
->ord
);
2573 nes_debug(NES_DBG_CM
, "requested ord = 0x%08X.\n", (u32
)conn_param
->ord
);
2574 nes_debug(NES_DBG_CM
, "mpa private data len =%u\n", conn_param
->private_data_len
);
2576 strcpy(&nesqp
->ietf_frame
->key
[0], IEFT_MPA_KEY_REQ
);
2577 nesqp
->ietf_frame
->flags
= IETF_MPA_FLAGS_CRC
;
2578 nesqp
->ietf_frame
->rev
= IETF_MPA_VERSION
;
2579 nesqp
->ietf_frame
->priv_data_len
= htons(conn_param
->private_data_len
);
2581 if (cm_id
->local_addr
.sin_addr
.s_addr
!= cm_id
->remote_addr
.sin_addr
.s_addr
)
2582 nes_manage_apbvt(nesvnic
, ntohs(cm_id
->local_addr
.sin_port
),
2583 PCI_FUNC(nesdev
->pcidev
->devfn
), NES_MANAGE_APBVT_ADD
);
2585 /* set up the connection params for the node */
2586 cm_info
.loc_addr
= (cm_id
->local_addr
.sin_addr
.s_addr
);
2587 cm_info
.loc_port
= (cm_id
->local_addr
.sin_port
);
2588 cm_info
.rem_addr
= (cm_id
->remote_addr
.sin_addr
.s_addr
);
2589 cm_info
.rem_port
= (cm_id
->remote_addr
.sin_port
);
2590 cm_info
.cm_id
= cm_id
;
2591 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
2593 cm_id
->add_ref(cm_id
);
2594 nes_add_ref(&nesqp
->ibqp
);
2596 /* create a connect CM node connection */
2597 cm_node
= g_cm_core
->api
->connect(g_cm_core
, nesvnic
, nesqp
->ietf_frame
, &cm_info
);
2599 if (cm_id
->local_addr
.sin_addr
.s_addr
!= cm_id
->remote_addr
.sin_addr
.s_addr
)
2600 nes_manage_apbvt(nesvnic
, ntohs(cm_id
->local_addr
.sin_port
),
2601 PCI_FUNC(nesdev
->pcidev
->devfn
), NES_MANAGE_APBVT_DEL
);
2602 nes_rem_ref(&nesqp
->ibqp
);
2603 kfree(nesqp
->ietf_frame
);
2604 nesqp
->ietf_frame
= NULL
;
2605 cm_id
->rem_ref(cm_id
);
2609 cm_node
->apbvt_set
= 1;
2610 nesqp
->cm_node
= cm_node
;
2619 int nes_create_listen(struct iw_cm_id
*cm_id
, int backlog
)
2621 struct nes_vnic
*nesvnic
;
2622 struct nes_cm_listener
*cm_node
;
2623 struct nes_cm_info cm_info
;
2624 struct nes_adapter
*adapter
;
2628 nes_debug(NES_DBG_CM
, "cm_id = %p, local port = 0x%04X.\n",
2629 cm_id
, ntohs(cm_id
->local_addr
.sin_port
));
2631 nesvnic
= to_nesvnic(cm_id
->device
);
2634 adapter
= nesvnic
->nesdev
->nesadapter
;
2635 nes_debug(NES_DBG_CM
, "nesvnic=%p, netdev=%p, %s\n",
2636 nesvnic
, nesvnic
->netdev
, nesvnic
->netdev
->name
);
2638 nes_debug(NES_DBG_CM
, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
2639 nesvnic
->local_ipaddr
, cm_id
->local_addr
.sin_addr
.s_addr
);
2641 /* setup listen params in our api call struct */
2642 cm_info
.loc_addr
= nesvnic
->local_ipaddr
;
2643 cm_info
.loc_port
= cm_id
->local_addr
.sin_port
;
2644 cm_info
.backlog
= backlog
;
2645 cm_info
.cm_id
= cm_id
;
2647 cm_info
.conn_type
= NES_CM_IWARP_CONN_TYPE
;
2650 cm_node
= g_cm_core
->api
->listen(g_cm_core
, nesvnic
, &cm_info
);
2652 printk("%s[%u] Error returned from listen API call\n",
2653 __FUNCTION__
, __LINE__
);
2657 cm_id
->provider_data
= cm_node
;
2659 if (!cm_node
->reused_node
) {
2660 err
= nes_manage_apbvt(nesvnic
, ntohs(cm_id
->local_addr
.sin_port
),
2661 PCI_FUNC(nesvnic
->nesdev
->pcidev
->devfn
), NES_MANAGE_APBVT_ADD
);
2663 printk("nes_manage_apbvt call returned %d.\n", err
);
2664 g_cm_core
->api
->stop_listener(g_cm_core
, (void *)cm_node
);
2667 cm_listens_created
++;
2670 cm_id
->add_ref(cm_id
);
2671 cm_id
->provider_data
= (void *)cm_node
;
2679 * nes_destroy_listen
2681 int nes_destroy_listen(struct iw_cm_id
*cm_id
)
2683 if (cm_id
->provider_data
)
2684 g_cm_core
->api
->stop_listener(g_cm_core
, cm_id
->provider_data
);
2686 nes_debug(NES_DBG_CM
, "cm_id->provider_data was NULL\n");
2688 cm_id
->rem_ref(cm_id
);
2697 int nes_cm_recv(struct sk_buff
*skb
, struct net_device
*netdevice
)
2699 cm_packets_received
++;
2700 if ((g_cm_core
) && (g_cm_core
->api
)) {
2701 g_cm_core
->api
->recv_pkt(g_cm_core
, netdev_priv(netdevice
), skb
);
2703 nes_debug(NES_DBG_CM
, "Unable to process packet for CM,"
2704 " cm is not setup properly.\n");
2713 * Start and init a cm core module
2715 int nes_cm_start(void)
2717 nes_debug(NES_DBG_CM
, "\n");
2718 /* create the primary CM core, pass this handle to subsequent core inits */
2719 g_cm_core
= nes_cm_alloc_core();
2730 * stop and dealloc all cm core instances
2732 int nes_cm_stop(void)
2734 g_cm_core
->api
->destroy_cm_core(g_cm_core
);
2740 * cm_event_connected
2741 * handle a connected event, setup QPs and HW
2743 void cm_event_connected(struct nes_cm_event
*event
)
2746 struct nes_qp
*nesqp
;
2747 struct nes_vnic
*nesvnic
;
2748 struct nes_device
*nesdev
;
2749 struct nes_cm_node
*cm_node
;
2750 struct nes_adapter
*nesadapter
;
2751 struct ib_qp_attr attr
;
2752 struct iw_cm_id
*cm_id
;
2753 struct iw_cm_event cm_event
;
2754 struct nes_hw_qp_wqe
*wqe
;
2755 struct nes_v4_quad nes_quad
;
2759 /* get all our handles */
2760 cm_node
= event
->cm_node
;
2761 cm_id
= cm_node
->cm_id
;
2762 nes_debug(NES_DBG_CM
, "cm_event_connected - %p - cm_id = %p\n", cm_node
, cm_id
);
2763 nesqp
= (struct nes_qp
*)cm_id
->provider_data
;
2764 nesvnic
= to_nesvnic(nesqp
->ibqp
.device
);
2765 nesdev
= nesvnic
->nesdev
;
2766 nesadapter
= nesdev
->nesadapter
;
2768 if (nesqp
->destroyed
) {
2771 atomic_inc(&cm_connecteds
);
2772 nes_debug(NES_DBG_CM
, "QP%u attempting to connect to 0x%08X:0x%04X on"
2773 " local port 0x%04X. jiffies = %lu.\n",
2775 ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
),
2776 ntohs(cm_id
->remote_addr
.sin_port
),
2777 ntohs(cm_id
->local_addr
.sin_port
),
2780 nes_cm_init_tsa_conn(nesqp
, cm_node
);
2782 /* set the QP tsa context */
2783 nesqp
->nesqp_context
->tcpPorts
[0] = cpu_to_le16(ntohs(cm_id
->local_addr
.sin_port
));
2784 nesqp
->nesqp_context
->tcpPorts
[1] = cpu_to_le16(ntohs(cm_id
->remote_addr
.sin_port
));
2785 nesqp
->nesqp_context
->ip0
= cpu_to_le32(ntohl(cm_id
->remote_addr
.sin_addr
.s_addr
));
2787 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
2788 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << NES_QPCONTEXT_MISC2_SRC_IP_SHIFT
);
2789 nesqp
->nesqp_context
->arp_index_vlan
|= cpu_to_le32(
2790 nes_arp_table(nesdev
, le32_to_cpu(nesqp
->nesqp_context
->ip0
),
2791 NULL
, NES_ARP_RESOLVE
) << 16);
2792 nesqp
->nesqp_context
->ts_val_delta
= cpu_to_le32(
2793 jiffies
- nes_read_indexed(nesdev
, NES_IDX_TCP_NOW
));
2794 nesqp
->nesqp_context
->ird_index
= cpu_to_le32(nesqp
->hwqp
.qp_id
);
2795 nesqp
->nesqp_context
->ird_ord_sizes
|=
2796 cpu_to_le32((u32
)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT
);
2798 /* Adjust tail for not having a LSMM */
2799 nesqp
->hwqp
.sq_tail
= 1;
2801 #if defined(NES_SEND_FIRST_WRITE)
2802 if (cm_node
->send_write0
) {
2803 nes_debug(NES_DBG_CM
, "Sending first write.\n");
2804 wqe
= &nesqp
->hwqp
.sq_vbase
[0];
2805 u64temp
= (unsigned long)nesqp
;
2806 u64temp
|= NES_SW_CONTEXT_ALIGN
>>1;
2807 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX
,
2809 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] = cpu_to_le32(NES_IWARP_SQ_OP_RDMAW
);
2810 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
] = 0;
2811 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
] = 0;
2812 wqe
->wqe_words
[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX
] = 0;
2813 wqe
->wqe_words
[NES_IWARP_SQ_WQE_LENGTH0_IDX
] = 0;
2814 wqe
->wqe_words
[NES_IWARP_SQ_WQE_STAG0_IDX
] = 0;
2816 /* use the reserved spot on the WQ for the extra first WQE */
2817 nesqp
->nesqp_context
->ird_ord_sizes
&= cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT
|
2818 NES_QPCONTEXT_ORDIRD_WRPDU
| NES_QPCONTEXT_ORDIRD_ALSMM
));
2819 nesqp
->skip_lsmm
= 1;
2820 nesqp
->hwqp
.sq_tail
= 0;
2821 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
,
2822 (1 << 24) | 0x00800000 | nesqp
->hwqp
.qp_id
);
2826 memset(&nes_quad
, 0, sizeof(nes_quad
));
2828 nes_quad
.DstIpAdrIndex
= cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
2829 nes_quad
.SrcIpadr
= cm_id
->remote_addr
.sin_addr
.s_addr
;
2830 nes_quad
.TcpPorts
[0] = cm_id
->remote_addr
.sin_port
;
2831 nes_quad
.TcpPorts
[1] = cm_id
->local_addr
.sin_port
;
2833 /* Produce hash key */
2834 crc_value
= get_crc_value(&nes_quad
);
2835 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
2836 nes_debug(NES_DBG_CM
, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
2837 nesqp
->hte_index
, nesqp
->hte_index
& nesadapter
->hte_index_mask
);
2839 nesqp
->hte_index
&= nesadapter
->hte_index_mask
;
2840 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
2842 nesqp
->ietf_frame
= &cm_node
->mpa_frame
;
2843 nesqp
->private_data_len
= (u8
) cm_node
->mpa_frame_size
;
2844 cm_node
->cm_core
->api
->accelerated(cm_node
->cm_core
, cm_node
);
2846 /* modify QP state to rts */
2847 attr
.qp_state
= IB_QPS_RTS
;
2848 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
2850 /* notify OF layer we successfully created the requested connection */
2851 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
2852 cm_event
.status
= IW_CM_EVENT_STATUS_ACCEPTED
;
2853 cm_event
.provider_data
= cm_id
->provider_data
;
2854 cm_event
.local_addr
.sin_family
= AF_INET
;
2855 cm_event
.local_addr
.sin_port
= cm_id
->local_addr
.sin_port
;
2856 cm_event
.remote_addr
= cm_id
->remote_addr
;
2858 cm_event
.private_data
= (void *)event
->cm_node
->mpa_frame_buf
;
2859 cm_event
.private_data_len
= (u8
) event
->cm_node
->mpa_frame_size
;
2861 cm_event
.local_addr
.sin_addr
.s_addr
= event
->cm_info
.rem_addr
;
2862 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2863 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
2866 printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
2867 __FUNCTION__
, __LINE__
, ret
);
2868 nes_debug(NES_DBG_CM
, "Exiting connect thread for QP%u. jiffies = %lu\n",
2869 nesqp
->hwqp
.qp_id
, jiffies
);
2871 nes_rem_ref(&nesqp
->ibqp
);
2878 * cm_event_connect_error
2880 void cm_event_connect_error(struct nes_cm_event
*event
)
2882 struct nes_qp
*nesqp
;
2883 struct iw_cm_id
*cm_id
;
2884 struct iw_cm_event cm_event
;
2885 /* struct nes_cm_info cm_info; */
2888 if (!event
->cm_node
)
2891 cm_id
= event
->cm_node
->cm_id
;
2896 nes_debug(NES_DBG_CM
, "cm_node=%p, cm_id=%p\n", event
->cm_node
, cm_id
);
2897 nesqp
= cm_id
->provider_data
;
2903 /* notify OF layer about this connection error event */
2904 /* cm_id->rem_ref(cm_id); */
2905 nesqp
->cm_id
= NULL
;
2906 cm_id
->provider_data
= NULL
;
2907 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
2908 cm_event
.status
= IW_CM_EVENT_STATUS_REJECTED
;
2909 cm_event
.provider_data
= cm_id
->provider_data
;
2910 cm_event
.local_addr
= cm_id
->local_addr
;
2911 cm_event
.remote_addr
= cm_id
->remote_addr
;
2912 cm_event
.private_data
= NULL
;
2913 cm_event
.private_data_len
= 0;
2915 nes_debug(NES_DBG_CM
, "call CM_EVENT REJECTED, local_addr=%08x, remove_addr=%08x\n",
2916 cm_event
.local_addr
.sin_addr
.s_addr
, cm_event
.remote_addr
.sin_addr
.s_addr
);
2918 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2919 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
2921 printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
2922 __FUNCTION__
, __LINE__
, ret
);
2923 nes_rem_ref(&nesqp
->ibqp
);
2924 cm_id
->rem_ref(cm_id
);
2933 void cm_event_reset(struct nes_cm_event
*event
)
2935 struct nes_qp
*nesqp
;
2936 struct iw_cm_id
*cm_id
;
2937 struct iw_cm_event cm_event
;
2938 /* struct nes_cm_info cm_info; */
2941 if (!event
->cm_node
)
2944 if (!event
->cm_node
->cm_id
)
2947 cm_id
= event
->cm_node
->cm_id
;
2949 nes_debug(NES_DBG_CM
, "%p - cm_id = %p\n", event
->cm_node
, cm_id
);
2950 nesqp
= cm_id
->provider_data
;
2952 nesqp
->cm_id
= NULL
;
2953 /* cm_id->provider_data = NULL; */
2954 cm_event
.event
= IW_CM_EVENT_DISCONNECT
;
2955 cm_event
.status
= IW_CM_EVENT_STATUS_RESET
;
2956 cm_event
.provider_data
= cm_id
->provider_data
;
2957 cm_event
.local_addr
= cm_id
->local_addr
;
2958 cm_event
.remote_addr
= cm_id
->remote_addr
;
2959 cm_event
.private_data
= NULL
;
2960 cm_event
.private_data_len
= 0;
2962 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
2963 nes_debug(NES_DBG_CM
, "OFA CM event_handler returned, ret=%d\n", ret
);
2966 /* notify OF layer about this connection error event */
2967 cm_id
->rem_ref(cm_id
);
2976 void cm_event_mpa_req(struct nes_cm_event
*event
)
2978 struct iw_cm_id
*cm_id
;
2979 struct iw_cm_event cm_event
;
2981 struct nes_cm_node
*cm_node
;
2983 cm_node
= event
->cm_node
;
2986 cm_id
= cm_node
->cm_id
;
2988 atomic_inc(&cm_connect_reqs
);
2989 nes_debug(NES_DBG_CM
, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
2990 cm_node
, cm_id
, jiffies
);
2992 cm_event
.event
= IW_CM_EVENT_CONNECT_REQUEST
;
2993 cm_event
.status
= IW_CM_EVENT_STATUS_OK
;
2994 cm_event
.provider_data
= (void *)cm_node
;
2996 cm_event
.local_addr
.sin_family
= AF_INET
;
2997 cm_event
.local_addr
.sin_port
= htons(event
->cm_info
.loc_port
);
2998 cm_event
.local_addr
.sin_addr
.s_addr
= htonl(event
->cm_info
.loc_addr
);
3000 cm_event
.remote_addr
.sin_family
= AF_INET
;
3001 cm_event
.remote_addr
.sin_port
= htons(event
->cm_info
.rem_port
);
3002 cm_event
.remote_addr
.sin_addr
.s_addr
= htonl(event
->cm_info
.rem_addr
);
3004 cm_event
.private_data
= cm_node
->mpa_frame_buf
;
3005 cm_event
.private_data_len
= (u8
) cm_node
->mpa_frame_size
;
3007 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
3009 printk("%s[%u] OFA CM event_handler returned, ret=%d\n",
3010 __FUNCTION__
, __LINE__
, ret
);
3016 static void nes_cm_event_handler(struct work_struct
*);
3020 * post an event to the cm event handler
3022 int nes_cm_post_event(struct nes_cm_event
*event
)
3024 atomic_inc(&event
->cm_node
->cm_core
->events_posted
);
3025 add_ref_cm_node(event
->cm_node
);
3026 event
->cm_info
.cm_id
->add_ref(event
->cm_info
.cm_id
);
3027 INIT_WORK(&event
->event_work
, nes_cm_event_handler
);
3028 nes_debug(NES_DBG_CM
, "queue_work, event=%p\n", event
);
3030 queue_work(event
->cm_node
->cm_core
->event_wq
, &event
->event_work
);
3032 nes_debug(NES_DBG_CM
, "Exit\n");
3038 * nes_cm_event_handler
3039 * worker function to handle cm events
3040 * will free instance of nes_cm_event
3042 static void nes_cm_event_handler(struct work_struct
*work
)
3044 struct nes_cm_event
*event
= container_of(work
, struct nes_cm_event
, event_work
);
3045 struct nes_cm_core
*cm_core
;
3047 if ((!event
) || (!event
->cm_node
) || (!event
->cm_node
->cm_core
)) {
3050 cm_core
= event
->cm_node
->cm_core
;
3051 nes_debug(NES_DBG_CM
, "event=%p, event->type=%u, events posted=%u\n",
3052 event
, event
->type
, atomic_read(&cm_core
->events_posted
));
3054 switch (event
->type
) {
3055 case NES_CM_EVENT_MPA_REQ
:
3056 cm_event_mpa_req(event
);
3057 nes_debug(NES_DBG_CM
, "CM Event: MPA REQUEST\n");
3059 case NES_CM_EVENT_RESET
:
3060 nes_debug(NES_DBG_CM
, "CM Event: RESET\n");
3061 cm_event_reset(event
);
3063 case NES_CM_EVENT_CONNECTED
:
3064 if ((!event
->cm_node
->cm_id
) ||
3065 (event
->cm_node
->state
!= NES_CM_STATE_TSA
)) {
3068 cm_event_connected(event
);
3069 nes_debug(NES_DBG_CM
, "CM Event: CONNECTED\n");
3071 case NES_CM_EVENT_ABORTED
:
3072 if ((!event
->cm_node
->cm_id
) || (event
->cm_node
->state
== NES_CM_STATE_TSA
)) {
3075 cm_event_connect_error(event
);
3076 nes_debug(NES_DBG_CM
, "CM Event: ABORTED\n");
3078 case NES_CM_EVENT_DROPPED_PKT
:
3079 nes_debug(NES_DBG_CM
, "CM Event: DROPPED PKT\n");
3082 nes_debug(NES_DBG_CM
, "CM Event: UNKNOWN EVENT TYPE\n");
3086 atomic_dec(&cm_core
->events_posted
);
3087 event
->cm_info
.cm_id
->rem_ref(event
->cm_info
.cm_id
);
3088 rem_ref_cm_node(cm_core
, event
->cm_node
);