RDMA/nes: Fix Xansation test crash on cm_node ref_count
[deliverable/linux.git] / drivers / infiniband / hw / nes / nes_cm.c
CommitLineData
3c2d774c 1/*
fa6c87d5 2 * Copyright (c) 2006 - 2009 Intel Corporation. All rights reserved.
3c2d774c
GS
3 *
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:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
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.
22 *
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
30 * SOFTWARE.
31 *
32 */
33
34
35#define TCPOPT_TIMESTAMP 8
36
37#include <asm/atomic.h>
38#include <linux/skbuff.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
41#include <linux/init.h>
42#include <linux/if_arp.h>
f2b2b59b 43#include <linux/if_vlan.h>
3c2d774c
GS
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>
7191a0a1 55#include <net/arp.h>
3c2d774c
GS
56#include <net/neighbour.h>
57#include <net/route.h>
58#include <net/ip_fib.h>
c11470f9 59#include <net/tcp.h>
3c2d774c
GS
60
61#include "nes.h"
62
63u32 cm_packets_sent;
64u32 cm_packets_bounced;
65u32 cm_packets_dropped;
66u32 cm_packets_retrans;
67u32 cm_packets_created;
68u32 cm_packets_received;
69u32 cm_listens_created;
70u32 cm_listens_destroyed;
71u32 cm_backlog_drops;
72atomic_t cm_loopbacks;
73atomic_t cm_nodes_created;
74atomic_t cm_nodes_destroyed;
75atomic_t cm_accel_dropped_pkts;
76atomic_t cm_resets_recvd;
77
6492cdf3
FL
78static inline int mini_cm_accelerated(struct nes_cm_core *,
79 struct nes_cm_node *);
3c2d774c 80static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *,
6492cdf3 81 struct nes_vnic *, struct nes_cm_info *);
3c2d774c 82static int mini_cm_del_listen(struct nes_cm_core *, struct nes_cm_listener *);
1a855fbf 83static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *,
6492cdf3
FL
84 struct nes_vnic *, u16, void *, struct nes_cm_info *);
85static int mini_cm_close(struct nes_cm_core *, struct nes_cm_node *);
1a855fbf 86static int mini_cm_accept(struct nes_cm_core *, struct ietf_mpa_frame *,
6492cdf3 87 struct nes_cm_node *);
1a855fbf 88static int mini_cm_reject(struct nes_cm_core *, struct ietf_mpa_frame *,
6492cdf3 89 struct nes_cm_node *);
4a14f6a7 90static int mini_cm_recv_pkt(struct nes_cm_core *, struct nes_vnic *,
6492cdf3 91 struct sk_buff *);
1a855fbf
RD
92static int mini_cm_dealloc_core(struct nes_cm_core *);
93static int mini_cm_get(struct nes_cm_core *);
94static int mini_cm_set(struct nes_cm_core *, u32, u32);
6492cdf3 95
6098d107 96static void form_cm_frame(struct sk_buff *, struct nes_cm_node *,
6492cdf3 97 void *, u32, void *, u32, u8);
6492cdf3
FL
98static int add_ref_cm_node(struct nes_cm_node *);
99static int rem_ref_cm_node(struct nes_cm_core *, struct nes_cm_node *);
100
1a855fbf
RD
101static int nes_cm_disconn_true(struct nes_qp *);
102static int nes_cm_post_event(struct nes_cm_event *event);
103static int nes_disconnect(struct nes_qp *nesqp, int abrupt);
104static void nes_disconnect_worker(struct work_struct *work);
6492cdf3
FL
105
106static int send_mpa_request(struct nes_cm_node *, struct sk_buff *);
9d5ab133 107static int send_mpa_reject(struct nes_cm_node *);
6492cdf3
FL
108static int send_syn(struct nes_cm_node *, u32, struct sk_buff *);
109static int send_reset(struct nes_cm_node *, struct sk_buff *);
110static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb);
1a855fbf 111static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb);
6492cdf3
FL
112static void process_packet(struct nes_cm_node *, struct sk_buff *,
113 struct nes_cm_core *);
114
115static void active_open_err(struct nes_cm_node *, struct sk_buff *, int);
116static void passive_open_err(struct nes_cm_node *, struct sk_buff *, int);
117static void cleanup_retrans_entry(struct nes_cm_node *);
9d5ab133 118static void handle_rcv_mpa(struct nes_cm_node *, struct sk_buff *);
6492cdf3
FL
119static void free_retrans_entry(struct nes_cm_node *cm_node);
120static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
121 struct sk_buff *skb, int optionsize, int passive);
122
123/* CM event handler functions */
124static void cm_event_connected(struct nes_cm_event *);
125static void cm_event_connect_error(struct nes_cm_event *);
126static void cm_event_reset(struct nes_cm_event *);
127static void cm_event_mpa_req(struct nes_cm_event *);
9d5ab133
FL
128static void cm_event_mpa_reject(struct nes_cm_event *);
129static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node);
6492cdf3
FL
130
131static void print_core(struct nes_cm_core *core);
3c2d774c
GS
132
133/* External CM API Interface */
134/* instance of function pointers for client API */
135/* set address of this instance to cm_core->cm_ops at cm_core alloc */
136static struct nes_cm_ops nes_cm_api = {
137 mini_cm_accelerated,
138 mini_cm_listen,
139 mini_cm_del_listen,
140 mini_cm_connect,
141 mini_cm_close,
142 mini_cm_accept,
143 mini_cm_reject,
144 mini_cm_recv_pkt,
145 mini_cm_dealloc_core,
146 mini_cm_get,
147 mini_cm_set
148};
149
1a855fbf 150static struct nes_cm_core *g_cm_core;
3c2d774c
GS
151
152atomic_t cm_connects;
153atomic_t cm_accepts;
154atomic_t cm_disconnects;
155atomic_t cm_closes;
156atomic_t cm_connecteds;
157atomic_t cm_connect_reqs;
158atomic_t cm_rejects;
159
160
161/**
162 * create_event
163 */
164static struct nes_cm_event *create_event(struct nes_cm_node *cm_node,
165 enum nes_cm_event_type type)
166{
167 struct nes_cm_event *event;
168
169 if (!cm_node->cm_id)
170 return NULL;
171
172 /* allocate an empty event */
173 event = kzalloc(sizeof(*event), GFP_ATOMIC);
174
175 if (!event)
176 return NULL;
177
178 event->type = type;
179 event->cm_node = cm_node;
180 event->cm_info.rem_addr = cm_node->rem_addr;
181 event->cm_info.loc_addr = cm_node->loc_addr;
182 event->cm_info.rem_port = cm_node->rem_port;
183 event->cm_info.loc_port = cm_node->loc_port;
184 event->cm_info.cm_id = cm_node->cm_id;
185
6492cdf3
FL
186 nes_debug(NES_DBG_CM, "cm_node=%p Created event=%p, type=%u, "
187 "dst_addr=%08x[%x], src_addr=%08x[%x]\n",
188 cm_node, event, type, event->cm_info.loc_addr,
189 event->cm_info.loc_port, event->cm_info.rem_addr,
190 event->cm_info.rem_port);
3c2d774c
GS
191
192 nes_cm_post_event(event);
193 return event;
194}
195
196
197/**
198 * send_mpa_request
199 */
6492cdf3 200static int send_mpa_request(struct nes_cm_node *cm_node, struct sk_buff *skb)
3c2d774c 201{
3c2d774c 202 if (!skb) {
6492cdf3 203 nes_debug(NES_DBG_CM, "skb set to NULL\n");
3c2d774c
GS
204 return -1;
205 }
206
207 /* send an MPA Request frame */
208 form_cm_frame(skb, cm_node, NULL, 0, &cm_node->mpa_frame,
209 cm_node->mpa_frame_size, SET_ACK);
210
9d5ab133
FL
211 return schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
212}
3c2d774c 213
9d5ab133
FL
214
215
216static int send_mpa_reject(struct nes_cm_node *cm_node)
217{
218 struct sk_buff *skb = NULL;
219
220 skb = dev_alloc_skb(MAX_CM_BUFFER);
221 if (!skb) {
222 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
223 return -ENOMEM;
224 }
225
226 /* send an MPA reject frame */
227 form_cm_frame(skb, cm_node, NULL, 0, &cm_node->mpa_frame,
228 cm_node->mpa_frame_size, SET_ACK | SET_FIN);
229
230 cm_node->state = NES_CM_STATE_FIN_WAIT1;
231 return schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
3c2d774c
GS
232}
233
234
235/**
236 * recv_mpa - process a received TCP pkt, we are expecting an
237 * IETF MPA frame
238 */
9d5ab133
FL
239static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 *type,
240 u32 len)
3c2d774c
GS
241{
242 struct ietf_mpa_frame *mpa_frame;
243
9d5ab133
FL
244 *type = NES_MPA_REQUEST_ACCEPT;
245
3c2d774c
GS
246 /* assume req frame is in tcp data payload */
247 if (len < sizeof(struct ietf_mpa_frame)) {
248 nes_debug(NES_DBG_CM, "The received ietf buffer was too small (%x)\n", len);
9d5ab133 249 return -EINVAL;
3c2d774c
GS
250 }
251
252 mpa_frame = (struct ietf_mpa_frame *)buffer;
253 cm_node->mpa_frame_size = ntohs(mpa_frame->priv_data_len);
1cf078c9
FL
254 /* make sure mpa private data len is less than 512 bytes */
255 if (cm_node->mpa_frame_size > IETF_MAX_PRIV_DATA_LEN) {
256 nes_debug(NES_DBG_CM, "The received Length of Private"
257 " Data field exceeds 512 octets\n");
258 return -EINVAL;
259 }
260 /*
261 * make sure MPA receiver interoperate with the
262 * received MPA version and MPA key information
263 *
264 */
265 if (mpa_frame->rev != mpa_version) {
266 nes_debug(NES_DBG_CM, "The received mpa version"
267 " can not be interoperated\n");
268 return -EINVAL;
269 }
270 if (cm_node->state != NES_CM_STATE_MPAREQ_SENT) {
271 if (memcmp(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE)) {
272 nes_debug(NES_DBG_CM, "Unexpected MPA Key received \n");
273 return -EINVAL;
274 }
275 } else {
276 if (memcmp(mpa_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE)) {
277 nes_debug(NES_DBG_CM, "Unexpected MPA Key received \n");
278 return -EINVAL;
279 }
280 }
3c2d774c
GS
281
282 if (cm_node->mpa_frame_size + sizeof(struct ietf_mpa_frame) != len) {
283 nes_debug(NES_DBG_CM, "The received ietf buffer was not right"
284 " complete (%x + %x != %x)\n",
9d5ab133
FL
285 cm_node->mpa_frame_size,
286 (u32)sizeof(struct ietf_mpa_frame), len);
287 return -EINVAL;
288 }
289 /* make sure it does not exceed the max size */
290 if (len > MAX_CM_BUFFER) {
291 nes_debug(NES_DBG_CM, "The received ietf buffer was too large"
292 " (%x + %x != %x)\n",
293 cm_node->mpa_frame_size,
294 (u32)sizeof(struct ietf_mpa_frame), len);
295 return -EINVAL;
3c2d774c
GS
296 }
297
298 /* copy entire MPA frame to our cm_node's frame */
299 memcpy(cm_node->mpa_frame_buf, buffer + sizeof(struct ietf_mpa_frame),
300 cm_node->mpa_frame_size);
301
9d5ab133
FL
302 if (mpa_frame->flags & IETF_MPA_FLAGS_REJECT)
303 *type = NES_MPA_REQUEST_REJECT;
3c2d774c
GS
304 return 0;
305}
306
307
3c2d774c
GS
308/**
309 * form_cm_frame - get a free packet and build empty frame Use
310 * node info to build.
311 */
6098d107 312static void form_cm_frame(struct sk_buff *skb,
6492cdf3
FL
313 struct nes_cm_node *cm_node, void *options, u32 optionsize,
314 void *data, u32 datasize, u8 flags)
3c2d774c
GS
315{
316 struct tcphdr *tcph;
317 struct iphdr *iph;
318 struct ethhdr *ethh;
319 u8 *buf;
320 u16 packetsize = sizeof(*iph);
321
322 packetsize += sizeof(*tcph);
323 packetsize += optionsize + datasize;
324
325 memset(skb->data, 0x00, ETH_HLEN + sizeof(*iph) + sizeof(*tcph));
326
327 skb->len = 0;
328 buf = skb_put(skb, packetsize + ETH_HLEN);
329
330 ethh = (struct ethhdr *) buf;
331 buf += ETH_HLEN;
332
333 iph = (struct iphdr *)buf;
334 buf += sizeof(*iph);
335 tcph = (struct tcphdr *)buf;
336 skb_reset_mac_header(skb);
337 skb_set_network_header(skb, ETH_HLEN);
338 skb_set_transport_header(skb, ETH_HLEN+sizeof(*iph));
339 buf += sizeof(*tcph);
340
341 skb->ip_summed = CHECKSUM_PARTIAL;
342 skb->protocol = htons(0x800);
343 skb->data_len = 0;
344 skb->mac_len = ETH_HLEN;
345
346 memcpy(ethh->h_dest, cm_node->rem_mac, ETH_ALEN);
347 memcpy(ethh->h_source, cm_node->loc_mac, ETH_ALEN);
348 ethh->h_proto = htons(0x0800);
349
350 iph->version = IPVERSION;
351 iph->ihl = 5; /* 5 * 4Byte words, IP headr len */
352 iph->tos = 0;
353 iph->tot_len = htons(packetsize);
354 iph->id = htons(++cm_node->tcp_cntxt.loc_id);
355
356 iph->frag_off = htons(0x4000);
357 iph->ttl = 0x40;
358 iph->protocol = 0x06; /* IPPROTO_TCP */
359
360 iph->saddr = htonl(cm_node->loc_addr);
361 iph->daddr = htonl(cm_node->rem_addr);
362
363 tcph->source = htons(cm_node->loc_port);
364 tcph->dest = htons(cm_node->rem_port);
365 tcph->seq = htonl(cm_node->tcp_cntxt.loc_seq_num);
366
367 if (flags & SET_ACK) {
368 cm_node->tcp_cntxt.loc_ack_num = cm_node->tcp_cntxt.rcv_nxt;
369 tcph->ack_seq = htonl(cm_node->tcp_cntxt.loc_ack_num);
370 tcph->ack = 1;
371 } else
372 tcph->ack_seq = 0;
373
374 if (flags & SET_SYN) {
375 cm_node->tcp_cntxt.loc_seq_num++;
376 tcph->syn = 1;
377 } else
6492cdf3 378 cm_node->tcp_cntxt.loc_seq_num += datasize;
3c2d774c 379
6492cdf3
FL
380 if (flags & SET_FIN) {
381 cm_node->tcp_cntxt.loc_seq_num++;
3c2d774c 382 tcph->fin = 1;
6492cdf3 383 }
3c2d774c
GS
384
385 if (flags & SET_RST)
386 tcph->rst = 1;
387
388 tcph->doff = (u16)((sizeof(*tcph) + optionsize + 3) >> 2);
389 tcph->window = htons(cm_node->tcp_cntxt.rcv_wnd);
390 tcph->urg_ptr = 0;
391 if (optionsize)
392 memcpy(buf, options, optionsize);
393 buf += optionsize;
394 if (datasize)
395 memcpy(buf, data, datasize);
396
397 skb_shinfo(skb)->nr_frags = 0;
398 cm_packets_created++;
399
3c2d774c
GS
400}
401
402
403/**
404 * print_core - dump a cm core
405 */
406static void print_core(struct nes_cm_core *core)
407{
408 nes_debug(NES_DBG_CM, "---------------------------------------------\n");
409 nes_debug(NES_DBG_CM, "CM Core -- (core = %p )\n", core);
410 if (!core)
411 return;
412 nes_debug(NES_DBG_CM, "---------------------------------------------\n");
3c2d774c
GS
413
414 nes_debug(NES_DBG_CM, "State : %u \n", core->state);
415
3c2d774c
GS
416 nes_debug(NES_DBG_CM, "Listen Nodes : %u \n", atomic_read(&core->listen_node_cnt));
417 nes_debug(NES_DBG_CM, "Active Nodes : %u \n", atomic_read(&core->node_cnt));
418
419 nes_debug(NES_DBG_CM, "core : %p \n", core);
420
421 nes_debug(NES_DBG_CM, "-------------- end core ---------------\n");
422}
423
424
425/**
426 * schedule_nes_timer
427 * note - cm_node needs to be protected before calling this. Encase in:
428 * rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
429 */
430int schedule_nes_timer(struct nes_cm_node *cm_node, struct sk_buff *skb,
431 enum nes_timer_type type, int send_retrans,
432 int close_when_complete)
433{
434 unsigned long flags;
6492cdf3 435 struct nes_cm_core *cm_core = cm_node->cm_core;
3c2d774c
GS
436 struct nes_timer_entry *new_send;
437 int ret = 0;
438 u32 was_timer_set;
439
440 new_send = kzalloc(sizeof(*new_send), GFP_ATOMIC);
441 if (!new_send)
9d5ab133 442 return -ENOMEM;
3c2d774c
GS
443
444 /* new_send->timetosend = currenttime */
445 new_send->retrycount = NES_DEFAULT_RETRYS;
446 new_send->retranscount = NES_DEFAULT_RETRANS;
447 new_send->skb = skb;
448 new_send->timetosend = jiffies;
449 new_send->type = type;
450 new_send->netdev = cm_node->netdev;
451 new_send->send_retrans = send_retrans;
452 new_send->close_when_complete = close_when_complete;
453
454 if (type == NES_TIMER_TYPE_CLOSE) {
6492cdf3 455 new_send->timetosend += (HZ/10);
9d5ab133 456 if (cm_node->recv_entry) {
79fc3d74 457 kfree(new_send);
9d5ab133
FL
458 WARN_ON(1);
459 return -EINVAL;
460 }
461 cm_node->recv_entry = new_send;
3c2d774c
GS
462 }
463
464 if (type == NES_TIMER_TYPE_SEND) {
b30db1c1 465 new_send->seq_num = ntohl(tcp_hdr(skb)->seq);
3c2d774c 466 atomic_inc(&new_send->skb->users);
6492cdf3
FL
467 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
468 cm_node->send_entry = new_send;
469 add_ref_cm_node(cm_node);
470 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
471 new_send->timetosend = jiffies + NES_RETRY_TIMEOUT;
3c2d774c
GS
472
473 ret = nes_nic_cm_xmit(new_send->skb, cm_node->netdev);
474 if (ret != NETDEV_TX_OK) {
6492cdf3
FL
475 nes_debug(NES_DBG_CM, "Error sending packet %p "
476 "(jiffies = %lu)\n", new_send, jiffies);
3c2d774c 477 new_send->timetosend = jiffies;
5962c2c8 478 ret = NETDEV_TX_OK;
3c2d774c
GS
479 } else {
480 cm_packets_sent++;
481 if (!send_retrans) {
6492cdf3 482 cleanup_retrans_entry(cm_node);
3c2d774c 483 if (close_when_complete)
6492cdf3 484 rem_ref_cm_node(cm_core, cm_node);
3c2d774c
GS
485 return ret;
486 }
3c2d774c 487 }
3c2d774c 488 }
3c2d774c
GS
489
490 was_timer_set = timer_pending(&cm_core->tcp_timer);
491
492 if (!was_timer_set) {
493 cm_core->tcp_timer.expires = new_send->timetosend;
494 add_timer(&cm_core->tcp_timer);
495 }
496
497 return ret;
498}
499
9d5ab133
FL
500static void nes_retrans_expired(struct nes_cm_node *cm_node)
501{
68237a0f 502 struct iw_cm_id *cm_id = cm_node->cm_id;
9d5ab133
FL
503 switch (cm_node->state) {
504 case NES_CM_STATE_SYN_RCVD:
505 case NES_CM_STATE_CLOSING:
506 rem_ref_cm_node(cm_node->cm_core, cm_node);
507 break;
508 case NES_CM_STATE_LAST_ACK:
509 case NES_CM_STATE_FIN_WAIT1:
68237a0f
FL
510 if (cm_node->cm_id)
511 cm_id->rem_ref(cm_id);
512 cm_node->state = NES_CM_STATE_CLOSED;
9d5ab133
FL
513 send_reset(cm_node, NULL);
514 break;
515 default:
69524e1a
FL
516 add_ref_cm_node(cm_node);
517 send_reset(cm_node, NULL);
9d5ab133
FL
518 create_event(cm_node, NES_CM_EVENT_ABORTED);
519 }
520}
521
522static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node)
523{
524 struct nes_timer_entry *recv_entry = cm_node->recv_entry;
525 struct iw_cm_id *cm_id = cm_node->cm_id;
526 struct nes_qp *nesqp;
527 unsigned long qplockflags;
528
529 if (!recv_entry)
530 return;
531 nesqp = (struct nes_qp *)recv_entry->skb;
532 if (nesqp) {
533 spin_lock_irqsave(&nesqp->lock, qplockflags);
534 if (nesqp->cm_id) {
535 nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, "
536 "refcount = %d: HIT A "
537 "NES_TIMER_TYPE_CLOSE with something "
538 "to do!!!\n", nesqp->hwqp.qp_id, cm_id,
539 atomic_read(&nesqp->refcount));
540 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
541 nesqp->last_aeq = NES_AEQE_AEID_RESET_SENT;
542 nesqp->ibqp_state = IB_QPS_ERR;
543 spin_unlock_irqrestore(&nesqp->lock, qplockflags);
544 nes_cm_disconn(nesqp);
545 } else {
546 spin_unlock_irqrestore(&nesqp->lock, qplockflags);
547 nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, "
548 "refcount = %d: HIT A "
549 "NES_TIMER_TYPE_CLOSE with nothing "
550 "to do!!!\n", nesqp->hwqp.qp_id, cm_id,
551 atomic_read(&nesqp->refcount));
552 }
553 } else if (rem_node) {
554 /* TIME_WAIT state */
555 rem_ref_cm_node(cm_node->cm_core, cm_node);
556 }
557 if (cm_node->cm_id)
558 cm_id->rem_ref(cm_id);
559 kfree(recv_entry);
560 cm_node->recv_entry = NULL;
561}
3c2d774c
GS
562
563/**
564 * nes_cm_timer_tick
565 */
1a855fbf 566static void nes_cm_timer_tick(unsigned long pass)
3c2d774c 567{
9d5ab133 568 unsigned long flags;
3c2d774c 569 unsigned long nexttimeout = jiffies + NES_LONG_TIME;
3c2d774c
GS
570 struct nes_cm_node *cm_node;
571 struct nes_timer_entry *send_entry, *recv_entry;
9d5ab133
FL
572 struct list_head *list_core_temp;
573 struct list_head *list_node;
3c2d774c 574 struct nes_cm_core *cm_core = g_cm_core;
3c2d774c 575 u32 settimer = 0;
4e9c3900 576 unsigned long timetosend;
3c2d774c 577 int ret = NETDEV_TX_OK;
3c2d774c 578
879e5bd5
FL
579 struct list_head timer_list;
580 INIT_LIST_HEAD(&timer_list);
3c2d774c
GS
581 spin_lock_irqsave(&cm_core->ht_lock, flags);
582
6492cdf3 583 list_for_each_safe(list_node, list_core_temp,
879e5bd5 584 &cm_core->connected_nodes) {
3c2d774c 585 cm_node = container_of(list_node, struct nes_cm_node, list);
9d5ab133 586 if ((cm_node->recv_entry) || (cm_node->send_entry)) {
879e5bd5
FL
587 add_ref_cm_node(cm_node);
588 list_add(&cm_node->timer_entry, &timer_list);
589 }
590 }
591 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
592
593 list_for_each_safe(list_node, list_core_temp, &timer_list) {
594 cm_node = container_of(list_node, struct nes_cm_node,
595 timer_entry);
9d5ab133
FL
596 recv_entry = cm_node->recv_entry;
597
598 if (recv_entry) {
6492cdf3
FL
599 if (time_after(recv_entry->timetosend, jiffies)) {
600 if (nexttimeout > recv_entry->timetosend ||
9d5ab133 601 !settimer) {
3c2d774c
GS
602 nexttimeout = recv_entry->timetosend;
603 settimer = 1;
604 }
9d5ab133
FL
605 } else
606 handle_recv_entry(cm_node, 1);
3c2d774c 607 }
3c2d774c
GS
608
609 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
6492cdf3
FL
610 do {
611 send_entry = cm_node->send_entry;
612 if (!send_entry)
c5d321e5 613 break;
3c2d774c
GS
614 if (time_after(send_entry->timetosend, jiffies)) {
615 if (cm_node->state != NES_CM_STATE_TSA) {
6492cdf3
FL
616 if ((nexttimeout >
617 send_entry->timetosend) ||
618 !settimer) {
619 nexttimeout =
620 send_entry->timetosend;
3c2d774c
GS
621 settimer = 1;
622 }
3c2d774c 623 } else {
6492cdf3 624 free_retrans_entry(cm_node);
3c2d774c 625 }
9d5ab133 626 break;
3c2d774c 627 }
6492cdf3
FL
628
629 if ((cm_node->state == NES_CM_STATE_TSA) ||
630 (cm_node->state == NES_CM_STATE_CLOSED)) {
631 free_retrans_entry(cm_node);
c5d321e5 632 break;
3c2d774c
GS
633 }
634
6492cdf3
FL
635 if (!send_entry->retranscount ||
636 !send_entry->retrycount) {
3c2d774c 637 cm_packets_dropped++;
6492cdf3 638 free_retrans_entry(cm_node);
9d5ab133 639
6492cdf3
FL
640 spin_unlock_irqrestore(
641 &cm_node->retrans_list_lock, flags);
9d5ab133
FL
642 nes_retrans_expired(cm_node);
643 cm_node->state = NES_CM_STATE_CLOSED;
6492cdf3
FL
644 spin_lock_irqsave(&cm_node->retrans_list_lock,
645 flags);
c5d321e5 646 break;
3c2d774c 647 }
3c2d774c
GS
648 atomic_inc(&send_entry->skb->users);
649 cm_packets_retrans++;
6492cdf3
FL
650 nes_debug(NES_DBG_CM, "Retransmitting send_entry %p "
651 "for node %p, jiffies = %lu, time to send = "
652 "%lu, retranscount = %u, send_entry->seq_num = "
653 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
654 "0x%08X\n", send_entry, cm_node, jiffies,
655 send_entry->timetosend,
656 send_entry->retranscount,
657 send_entry->seq_num,
658 cm_node->tcp_cntxt.rem_ack_num);
659
660 spin_unlock_irqrestore(&cm_node->retrans_list_lock,
661 flags);
3c2d774c 662 ret = nes_nic_cm_xmit(send_entry->skb, cm_node->netdev);
6492cdf3 663 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
3c2d774c 664 if (ret != NETDEV_TX_OK) {
6492cdf3
FL
665 nes_debug(NES_DBG_CM, "rexmit failed for "
666 "node=%p\n", cm_node);
3c2d774c 667 cm_packets_bounced++;
3c2d774c
GS
668 send_entry->retrycount--;
669 nexttimeout = jiffies + NES_SHORT_TIME;
670 settimer = 1;
c5d321e5 671 break;
3c2d774c
GS
672 } else {
673 cm_packets_sent++;
674 }
6492cdf3
FL
675 nes_debug(NES_DBG_CM, "Packet Sent: retrans count = "
676 "%u, retry count = %u.\n",
677 send_entry->retranscount,
678 send_entry->retrycount);
3c2d774c
GS
679 if (send_entry->send_retrans) {
680 send_entry->retranscount--;
4e9c3900
FL
681 timetosend = (NES_RETRY_TIMEOUT <<
682 (NES_DEFAULT_RETRANS - send_entry->retranscount));
683
6492cdf3 684 send_entry->timetosend = jiffies +
4e9c3900 685 min(timetosend, NES_MAX_TIMEOUT);
6492cdf3
FL
686 if (nexttimeout > send_entry->timetosend ||
687 !settimer) {
3c2d774c
GS
688 nexttimeout = send_entry->timetosend;
689 settimer = 1;
690 }
3c2d774c
GS
691 } else {
692 int close_when_complete;
6492cdf3
FL
693 close_when_complete =
694 send_entry->close_when_complete;
695 nes_debug(NES_DBG_CM, "cm_node=%p state=%d\n",
696 cm_node, cm_node->state);
697 free_retrans_entry(cm_node);
698 if (close_when_complete)
699 rem_ref_cm_node(cm_node->cm_core,
700 cm_node);
3c2d774c 701 }
6492cdf3 702 } while (0);
3c2d774c 703
6492cdf3
FL
704 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
705 rem_ref_cm_node(cm_node->cm_core, cm_node);
3c2d774c 706 }
3c2d774c
GS
707
708 if (settimer) {
709 if (!timer_pending(&cm_core->tcp_timer)) {
710 cm_core->tcp_timer.expires = nexttimeout;
711 add_timer(&cm_core->tcp_timer);
712 }
713 }
714}
715
716
717/**
718 * send_syn
719 */
6492cdf3
FL
720static int send_syn(struct nes_cm_node *cm_node, u32 sendack,
721 struct sk_buff *skb)
3c2d774c
GS
722{
723 int ret;
724 int flags = SET_SYN;
3c2d774c 725 char optionsbuffer[sizeof(struct option_mss) +
6492cdf3
FL
726 sizeof(struct option_windowscale) + sizeof(struct option_base) +
727 TCP_OPTIONS_PADDING];
3c2d774c
GS
728
729 int optionssize = 0;
730 /* Sending MSS option */
731 union all_known_options *options;
732
733 if (!cm_node)
734 return -EINVAL;
735
736 options = (union all_known_options *)&optionsbuffer[optionssize];
737 options->as_mss.optionnum = OPTION_NUMBER_MSS;
738 options->as_mss.length = sizeof(struct option_mss);
739 options->as_mss.mss = htons(cm_node->tcp_cntxt.mss);
740 optionssize += sizeof(struct option_mss);
741
742 options = (union all_known_options *)&optionsbuffer[optionssize];
743 options->as_windowscale.optionnum = OPTION_NUMBER_WINDOW_SCALE;
744 options->as_windowscale.length = sizeof(struct option_windowscale);
745 options->as_windowscale.shiftcount = cm_node->tcp_cntxt.rcv_wscale;
746 optionssize += sizeof(struct option_windowscale);
747
6492cdf3 748 if (sendack && !(NES_DRV_OPT_SUPRESS_OPTION_BC & nes_drv_opt)) {
3c2d774c
GS
749 options = (union all_known_options *)&optionsbuffer[optionssize];
750 options->as_base.optionnum = OPTION_NUMBER_WRITE0;
751 options->as_base.length = sizeof(struct option_base);
752 optionssize += sizeof(struct option_base);
753 /* we need the size to be a multiple of 4 */
754 options = (union all_known_options *)&optionsbuffer[optionssize];
755 options->as_end = 1;
756 optionssize += 1;
757 options = (union all_known_options *)&optionsbuffer[optionssize];
758 options->as_end = 1;
759 optionssize += 1;
760 }
761
762 options = (union all_known_options *)&optionsbuffer[optionssize];
763 options->as_end = OPTION_NUMBER_END;
764 optionssize += 1;
765
6492cdf3 766 if (!skb)
e189062a 767 skb = dev_alloc_skb(MAX_CM_BUFFER);
3c2d774c
GS
768 if (!skb) {
769 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
770 return -1;
771 }
772
773 if (sendack)
774 flags |= SET_ACK;
775
776 form_cm_frame(skb, cm_node, optionsbuffer, optionssize, NULL, 0, flags);
777 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
778
779 return ret;
780}
781
782
783/**
784 * send_reset
785 */
6492cdf3 786static int send_reset(struct nes_cm_node *cm_node, struct sk_buff *skb)
3c2d774c
GS
787{
788 int ret;
3c2d774c
GS
789 int flags = SET_RST | SET_ACK;
790
6492cdf3 791 if (!skb)
e189062a 792 skb = dev_alloc_skb(MAX_CM_BUFFER);
3c2d774c
GS
793 if (!skb) {
794 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
9d5ab133 795 return -ENOMEM;
3c2d774c
GS
796 }
797
3c2d774c
GS
798 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, flags);
799 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 1);
800
801 return ret;
802}
803
804
805/**
806 * send_ack
807 */
6492cdf3 808static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb)
3c2d774c
GS
809{
810 int ret;
6492cdf3
FL
811
812 if (!skb)
e189062a 813 skb = dev_alloc_skb(MAX_CM_BUFFER);
3c2d774c
GS
814
815 if (!skb) {
816 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
817 return -1;
818 }
819
820 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK);
821 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 0);
822
823 return ret;
824}
825
826
827/**
828 * send_fin
829 */
1a855fbf 830static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb)
3c2d774c
GS
831{
832 int ret;
833
834 /* if we didn't get a frame get one */
835 if (!skb)
e189062a 836 skb = dev_alloc_skb(MAX_CM_BUFFER);
3c2d774c
GS
837
838 if (!skb) {
839 nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
840 return -1;
841 }
842
843 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK | SET_FIN);
844 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
845
846 return ret;
847}
848
849
3c2d774c
GS
850/**
851 * find_node - find a cm node that matches the reference cm node
852 */
853static struct nes_cm_node *find_node(struct nes_cm_core *cm_core,
854 u16 rem_port, nes_addr_t rem_addr, u16 loc_port, nes_addr_t loc_addr)
855{
856 unsigned long flags;
3c2d774c
GS
857 struct list_head *hte;
858 struct nes_cm_node *cm_node;
859
3c2d774c
GS
860 /* get a handle on the hte */
861 hte = &cm_core->connected_nodes;
862
3c2d774c
GS
863 /* walk list and find cm_node associated with this session ID */
864 spin_lock_irqsave(&cm_core->ht_lock, flags);
4e96a774 865 list_for_each_entry(cm_node, hte, list) {
3c2d774c
GS
866 /* compare quad, return node handle if a match */
867 nes_debug(NES_DBG_CM, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
868 cm_node->loc_addr, cm_node->loc_port,
869 loc_addr, loc_port,
870 cm_node->rem_addr, cm_node->rem_port,
871 rem_addr, rem_port);
872 if ((cm_node->loc_addr == loc_addr) && (cm_node->loc_port == loc_port) &&
873 (cm_node->rem_addr == rem_addr) && (cm_node->rem_port == rem_port)) {
874 add_ref_cm_node(cm_node);
875 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
876 return cm_node;
877 }
878 }
879 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
880
881 /* no owner node */
882 return NULL;
883}
884
885
886/**
887 * find_listener - find a cm node listening on this addr-port pair
888 */
889static struct nes_cm_listener *find_listener(struct nes_cm_core *cm_core,
890 nes_addr_t dst_addr, u16 dst_port, enum nes_cm_listener_state listener_state)
891{
892 unsigned long flags;
3c2d774c
GS
893 struct nes_cm_listener *listen_node;
894
895 /* walk list and find cm_node associated with this session ID */
896 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
4e96a774 897 list_for_each_entry(listen_node, &cm_core->listen_list.list, list) {
3c2d774c
GS
898 /* compare node pair, return node handle if a match */
899 if (((listen_node->loc_addr == dst_addr) ||
900 listen_node->loc_addr == 0x00000000) &&
901 (listen_node->loc_port == dst_port) &&
902 (listener_state & listen_node->listener_state)) {
903 atomic_inc(&listen_node->ref_count);
904 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
905 return listen_node;
906 }
907 }
908 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
909
3c2d774c
GS
910 /* no listener */
911 return NULL;
912}
913
914
915/**
916 * add_hte_node - add a cm node to the hash table
917 */
918static int add_hte_node(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
919{
920 unsigned long flags;
3c2d774c
GS
921 struct list_head *hte;
922
923 if (!cm_node || !cm_core)
924 return -EINVAL;
925
6492cdf3
FL
926 nes_debug(NES_DBG_CM, "Adding Node %p to Active Connection HT\n",
927 cm_node);
3c2d774c 928
3c2d774c
GS
929 spin_lock_irqsave(&cm_core->ht_lock, flags);
930
931 /* get a handle on the hash table element (list head for this slot) */
932 hte = &cm_core->connected_nodes;
933 list_add_tail(&cm_node->list, hte);
934 atomic_inc(&cm_core->ht_node_cnt);
935
936 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
937
938 return 0;
939}
940
941
942/**
943 * mini_cm_dec_refcnt_listen
944 */
945static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
6492cdf3 946 struct nes_cm_listener *listener, int free_hanging_nodes)
3c2d774c 947{
9d5ab133
FL
948 int ret = -EINVAL;
949 int err = 0;
3c2d774c 950 unsigned long flags;
6492cdf3
FL
951 struct list_head *list_pos = NULL;
952 struct list_head *list_temp = NULL;
953 struct nes_cm_node *cm_node = NULL;
879e5bd5 954 struct list_head reset_list;
6492cdf3
FL
955
956 nes_debug(NES_DBG_CM, "attempting listener= %p free_nodes= %d, "
957 "refcnt=%d\n", listener, free_hanging_nodes,
958 atomic_read(&listener->ref_count));
959 /* free non-accelerated child nodes for this listener */
879e5bd5 960 INIT_LIST_HEAD(&reset_list);
6492cdf3
FL
961 if (free_hanging_nodes) {
962 spin_lock_irqsave(&cm_core->ht_lock, flags);
963 list_for_each_safe(list_pos, list_temp,
879e5bd5 964 &g_cm_core->connected_nodes) {
6492cdf3
FL
965 cm_node = container_of(list_pos, struct nes_cm_node,
966 list);
967 if ((cm_node->listener == listener) &&
879e5bd5
FL
968 (!cm_node->accelerated)) {
969 add_ref_cm_node(cm_node);
970 list_add(&cm_node->reset_entry, &reset_list);
6492cdf3
FL
971 }
972 }
973 spin_unlock_irqrestore(&cm_core->ht_lock, flags);
974 }
879e5bd5
FL
975
976 list_for_each_safe(list_pos, list_temp, &reset_list) {
977 cm_node = container_of(list_pos, struct nes_cm_node,
9d5ab133
FL
978 reset_entry);
979 {
980 struct nes_cm_node *loopback = cm_node->loopbackpartner;
c5a7d489 981 enum nes_cm_node_state old_state;
9d5ab133
FL
982 if (NES_CM_STATE_FIN_WAIT1 <= cm_node->state) {
983 rem_ref_cm_node(cm_node->cm_core, cm_node);
984 } else {
985 if (!loopback) {
986 cleanup_retrans_entry(cm_node);
987 err = send_reset(cm_node, NULL);
988 if (err) {
989 cm_node->state =
990 NES_CM_STATE_CLOSED;
991 WARN_ON(1);
992 } else {
c5a7d489
FL
993 old_state = cm_node->state;
994 cm_node->state = NES_CM_STATE_LISTENER_DESTROYED;
995 if (old_state != NES_CM_STATE_MPAREQ_RCVD)
996 rem_ref_cm_node(
997 cm_node->cm_core,
998 cm_node);
9d5ab133
FL
999 }
1000 } else {
1001 struct nes_cm_event event;
1002
1003 event.cm_node = loopback;
1004 event.cm_info.rem_addr =
1005 loopback->rem_addr;
1006 event.cm_info.loc_addr =
1007 loopback->loc_addr;
1008 event.cm_info.rem_port =
1009 loopback->rem_port;
1010 event.cm_info.loc_port =
1011 loopback->loc_port;
1012 event.cm_info.cm_id = loopback->cm_id;
1013 cm_event_connect_error(&event);
c5a7d489 1014 cm_node->state = NES_CM_STATE_LISTENER_DESTROYED;
9d5ab133
FL
1015 loopback->state = NES_CM_STATE_CLOSED;
1016
9d5ab133
FL
1017 rem_ref_cm_node(cm_node->cm_core,
1018 cm_node);
1019
1020 }
1021 }
1022 }
879e5bd5
FL
1023 }
1024
3c2d774c
GS
1025 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
1026 if (!atomic_dec_return(&listener->ref_count)) {
1027 list_del(&listener->list);
1028
1029 /* decrement our listen node count */
1030 atomic_dec(&cm_core->listen_node_cnt);
1031
1032 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
1033
1034 if (listener->nesvnic) {
1035 nes_manage_apbvt(listener->nesvnic, listener->loc_port,
1036 PCI_FUNC(listener->nesvnic->nesdev->pcidev->devfn), NES_MANAGE_APBVT_DEL);
1037 }
1038
1039 nes_debug(NES_DBG_CM, "destroying listener (%p)\n", listener);
1040
1041 kfree(listener);
a2e9c384 1042 listener = NULL;
3c2d774c
GS
1043 ret = 0;
1044 cm_listens_destroyed++;
1045 } else {
1046 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
1047 }
1048 if (listener) {
1049 if (atomic_read(&listener->pend_accepts_cnt) > 0)
1050 nes_debug(NES_DBG_CM, "destroying listener (%p)"
1051 " with non-zero pending accepts=%u\n",
1052 listener, atomic_read(&listener->pend_accepts_cnt));
1053 }
1054
1055 return ret;
1056}
1057
1058
1059/**
1060 * mini_cm_del_listen
1061 */
1062static int mini_cm_del_listen(struct nes_cm_core *cm_core,
1063 struct nes_cm_listener *listener)
1064{
1065 listener->listener_state = NES_CM_LISTENER_PASSIVE_STATE;
1066 listener->cm_id = NULL; /* going to be destroyed pretty soon */
1067 return mini_cm_dec_refcnt_listen(cm_core, listener, 1);
1068}
1069
1070
1071/**
1072 * mini_cm_accelerated
1073 */
1074static inline int mini_cm_accelerated(struct nes_cm_core *cm_core,
1075 struct nes_cm_node *cm_node)
1076{
1077 u32 was_timer_set;
1078 cm_node->accelerated = 1;
1079
1080 if (cm_node->accept_pend) {
1081 BUG_ON(!cm_node->listener);
1082 atomic_dec(&cm_node->listener->pend_accepts_cnt);
9d5ab133 1083 cm_node->accept_pend = 0;
3c2d774c
GS
1084 BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
1085 }
1086
1087 was_timer_set = timer_pending(&cm_core->tcp_timer);
1088 if (!was_timer_set) {
1089 cm_core->tcp_timer.expires = jiffies + NES_SHORT_TIME;
1090 add_timer(&cm_core->tcp_timer);
1091 }
1092
1093 return 0;
1094}
1095
1096
1097/**
7191a0a1 1098 * nes_addr_resolve_neigh
3c2d774c 1099 */
7191a0a1 1100static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip)
3c2d774c
GS
1101{
1102 struct rtable *rt;
1103 struct flowi fl;
7191a0a1
BS
1104 struct neighbour *neigh;
1105 int rc = -1;
3c2d774c
GS
1106
1107 memset(&fl, 0, sizeof fl);
1108 fl.nl_u.ip4_u.daddr = htonl(dst_ip);
1109 if (ip_route_output_key(&init_net, &rt, &fl)) {
9d5ab133 1110 printk(KERN_ERR "%s: ip_route_output_key failed for 0x%08X\n",
33718363 1111 __func__, dst_ip);
7191a0a1 1112 return rc;
3c2d774c
GS
1113 }
1114
7191a0a1
BS
1115 neigh = neigh_lookup(&arp_tbl, &rt->rt_gateway, nesvnic->netdev);
1116 if (neigh) {
1117 if (neigh->nud_state & NUD_VALID) {
1118 nes_debug(NES_DBG_CM, "Neighbor MAC address for 0x%08X"
e174961c
JB
1119 " is %pM, Gateway is 0x%08X \n", dst_ip,
1120 neigh->ha, ntohl(rt->rt_gateway));
7191a0a1
BS
1121 nes_manage_arp_cache(nesvnic->netdev, neigh->ha,
1122 dst_ip, NES_ARP_ADD);
1123 rc = nes_arp_table(nesvnic->nesdev, dst_ip, NULL,
1124 NES_ARP_RESOLVE);
1125 }
1126 neigh_release(neigh);
1127 }
1128
1129 if ((neigh == NULL) || (!(neigh->nud_state & NUD_VALID)))
1130 neigh_event_send(rt->u.dst.neighbour, NULL);
1131
3c2d774c 1132 ip_rt_put(rt);
7191a0a1 1133 return rc;
3c2d774c
GS
1134}
1135
1136
1137/**
1138 * make_cm_node - create a new instance of a cm node
1139 */
1140static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
1141 struct nes_vnic *nesvnic, struct nes_cm_info *cm_info,
1142 struct nes_cm_listener *listener)
1143{
1144 struct nes_cm_node *cm_node;
1145 struct timespec ts;
1146 int arpindex = 0;
1147 struct nes_device *nesdev;
1148 struct nes_adapter *nesadapter;
1149
1150 /* create an hte and cm_node for this instance */
1151 cm_node = kzalloc(sizeof(*cm_node), GFP_ATOMIC);
1152 if (!cm_node)
1153 return NULL;
1154
1155 /* set our node specific transport info */
1156 cm_node->loc_addr = cm_info->loc_addr;
1157 cm_node->rem_addr = cm_info->rem_addr;
1158 cm_node->loc_port = cm_info->loc_port;
1159 cm_node->rem_port = cm_info->rem_port;
1160 cm_node->send_write0 = send_first;
63779436
HH
1161 nes_debug(NES_DBG_CM, "Make node addresses : loc = %pI4:%x, rem = %pI4:%x\n",
1162 &cm_node->loc_addr, cm_node->loc_port,
1163 &cm_node->rem_addr, cm_node->rem_port);
3c2d774c
GS
1164 cm_node->listener = listener;
1165 cm_node->netdev = nesvnic->netdev;
1166 cm_node->cm_id = cm_info->cm_id;
1167 memcpy(cm_node->loc_mac, nesvnic->netdev->dev_addr, ETH_ALEN);
1168
6492cdf3
FL
1169 nes_debug(NES_DBG_CM, "listener=%p, cm_id=%p\n", cm_node->listener,
1170 cm_node->cm_id);
3c2d774c 1171
3c2d774c 1172 spin_lock_init(&cm_node->retrans_list_lock);
3c2d774c
GS
1173
1174 cm_node->loopbackpartner = NULL;
1175 atomic_set(&cm_node->ref_count, 1);
1176 /* associate our parent CM core */
1177 cm_node->cm_core = cm_core;
1178 cm_node->tcp_cntxt.loc_id = NES_CM_DEF_LOCAL_ID;
1179 cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
1180 cm_node->tcp_cntxt.rcv_wnd = NES_CM_DEFAULT_RCV_WND_SCALED >>
1181 NES_CM_DEFAULT_RCV_WND_SCALE;
1182 ts = current_kernel_time();
1183 cm_node->tcp_cntxt.loc_seq_num = htonl(ts.tv_nsec);
1184 cm_node->tcp_cntxt.mss = nesvnic->max_frame_size - sizeof(struct iphdr) -
f2b2b59b 1185 sizeof(struct tcphdr) - ETH_HLEN - VLAN_HLEN;
3c2d774c
GS
1186 cm_node->tcp_cntxt.rcv_nxt = 0;
1187 /* get a unique session ID , add thread_id to an upcounter to handle race */
1188 atomic_inc(&cm_core->node_cnt);
3c2d774c
GS
1189 cm_node->conn_type = cm_info->conn_type;
1190 cm_node->apbvt_set = 0;
1191 cm_node->accept_pend = 0;
1192
1193 cm_node->nesvnic = nesvnic;
1194 /* get some device handles, for arp lookup */
1195 nesdev = nesvnic->nesdev;
1196 nesadapter = nesdev->nesadapter;
1197
1198 cm_node->loopbackpartner = NULL;
1199 /* get the mac addr for the remote node */
1ee86555
CT
1200 if (ipv4_is_loopback(htonl(cm_node->rem_addr)))
1201 arpindex = nes_arp_table(nesdev, ntohl(nesvnic->local_ipaddr), NULL, NES_ARP_RESOLVE);
1202 else
1203 arpindex = nes_arp_table(nesdev, cm_node->rem_addr, NULL, NES_ARP_RESOLVE);
3c2d774c 1204 if (arpindex < 0) {
7191a0a1
BS
1205 arpindex = nes_addr_resolve_neigh(nesvnic, cm_info->rem_addr);
1206 if (arpindex < 0) {
1207 kfree(cm_node);
1208 return NULL;
1209 }
3c2d774c
GS
1210 }
1211
1212 /* copy the mac addr to node context */
1213 memcpy(cm_node->rem_mac, nesadapter->arp_table[arpindex].mac_addr, ETH_ALEN);
e174961c
JB
1214 nes_debug(NES_DBG_CM, "Remote mac addr from arp table: %pM\n",
1215 cm_node->rem_mac);
3c2d774c
GS
1216
1217 add_hte_node(cm_core, cm_node);
1218 atomic_inc(&cm_nodes_created);
1219
1220 return cm_node;
1221}
1222
1223
1224/**
1225 * add_ref_cm_node - destroy an instance of a cm node
1226 */
1227static int add_ref_cm_node(struct nes_cm_node *cm_node)
1228{
1229 atomic_inc(&cm_node->ref_count);
1230 return 0;
1231}
1232
1233
1234/**
1235 * rem_ref_cm_node - destroy an instance of a cm node
1236 */
1237static int rem_ref_cm_node(struct nes_cm_core *cm_core,
6492cdf3 1238 struct nes_cm_node *cm_node)
3c2d774c 1239{
9d5ab133 1240 unsigned long flags;
3c2d774c
GS
1241 struct nes_qp *nesqp;
1242
1243 if (!cm_node)
1244 return -EINVAL;
1245
1246 spin_lock_irqsave(&cm_node->cm_core->ht_lock, flags);
1247 if (atomic_dec_return(&cm_node->ref_count)) {
1248 spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
1249 return 0;
1250 }
1251 list_del(&cm_node->list);
1252 atomic_dec(&cm_core->ht_node_cnt);
1253 spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
1254
1255 /* if the node is destroyed before connection was accelerated */
1256 if (!cm_node->accelerated && cm_node->accept_pend) {
1257 BUG_ON(!cm_node->listener);
1258 atomic_dec(&cm_node->listener->pend_accepts_cnt);
1259 BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
1260 }
9d5ab133
FL
1261 WARN_ON(cm_node->send_entry);
1262 if (cm_node->recv_entry)
1263 handle_recv_entry(cm_node, 0);
3c2d774c
GS
1264 if (cm_node->listener) {
1265 mini_cm_dec_refcnt_listen(cm_core, cm_node->listener, 0);
1266 } else {
1267 if (cm_node->apbvt_set && cm_node->nesvnic) {
1268 nes_manage_apbvt(cm_node->nesvnic, cm_node->loc_port,
6492cdf3
FL
1269 PCI_FUNC(
1270 cm_node->nesvnic->nesdev->pcidev->devfn),
1271 NES_MANAGE_APBVT_DEL);
3c2d774c
GS
1272 }
1273 }
1274
3c2d774c
GS
1275 atomic_dec(&cm_core->node_cnt);
1276 atomic_inc(&cm_nodes_destroyed);
6492cdf3
FL
1277 nesqp = cm_node->nesqp;
1278 if (nesqp) {
1279 nesqp->cm_node = NULL;
1280 nes_rem_ref(&nesqp->ibqp);
1281 cm_node->nesqp = NULL;
1282 }
3c2d774c 1283
6492cdf3 1284 kfree(cm_node);
3c2d774c
GS
1285 return 0;
1286}
1287
3c2d774c
GS
1288/**
1289 * process_options
1290 */
6492cdf3
FL
1291static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
1292 u32 optionsize, u32 syn_packet)
3c2d774c
GS
1293{
1294 u32 tmp;
1295 u32 offset = 0;
1296 union all_known_options *all_options;
1297 char got_mss_option = 0;
1298
1299 while (offset < optionsize) {
1300 all_options = (union all_known_options *)(optionsloc + offset);
1301 switch (all_options->as_base.optionnum) {
6492cdf3
FL
1302 case OPTION_NUMBER_END:
1303 offset = optionsize;
1304 break;
1305 case OPTION_NUMBER_NONE:
1306 offset += 1;
1307 continue;
1308 case OPTION_NUMBER_MSS:
1309 nes_debug(NES_DBG_CM, "%s: MSS Length: %d Offset: %d "
1310 "Size: %d\n", __func__,
1311 all_options->as_mss.length, offset, optionsize);
1312 got_mss_option = 1;
1313 if (all_options->as_mss.length != 4) {
1314 return 1;
1315 } else {
1316 tmp = ntohs(all_options->as_mss.mss);
1317 if (tmp > 0 && tmp <
1318 cm_node->tcp_cntxt.mss)
1319 cm_node->tcp_cntxt.mss = tmp;
1320 }
1321 break;
1322 case OPTION_NUMBER_WINDOW_SCALE:
1323 cm_node->tcp_cntxt.snd_wscale =
1324 all_options->as_windowscale.shiftcount;
1325 break;
1326 case OPTION_NUMBER_WRITE0:
1327 cm_node->send_write0 = 1;
1328 break;
1329 default:
1330 nes_debug(NES_DBG_CM, "TCP Option not understood: %x\n",
1331 all_options->as_base.optionnum);
1332 break;
3c2d774c
GS
1333 }
1334 offset += all_options->as_base.length;
1335 }
1336 if ((!got_mss_option) && (syn_packet))
1337 cm_node->tcp_cntxt.mss = NES_CM_DEFAULT_MSS;
1338 return 0;
1339}
1340
6492cdf3
FL
1341static void drop_packet(struct sk_buff *skb)
1342{
1343 atomic_inc(&cm_accel_dropped_pkts);
1344 dev_kfree_skb_any(skb);
1345}
3c2d774c 1346
9d5ab133 1347static void handle_fin_pkt(struct nes_cm_node *cm_node)
3c2d774c 1348{
6492cdf3
FL
1349 nes_debug(NES_DBG_CM, "Received FIN, cm_node = %p, state = %u. "
1350 "refcnt=%d\n", cm_node, cm_node->state,
1351 atomic_read(&cm_node->ref_count));
6492cdf3
FL
1352 switch (cm_node->state) {
1353 case NES_CM_STATE_SYN_RCVD:
1354 case NES_CM_STATE_SYN_SENT:
1355 case NES_CM_STATE_ESTABLISHED:
1356 case NES_CM_STATE_MPAREQ_SENT:
9d5ab133 1357 case NES_CM_STATE_MPAREJ_RCVD:
109d67e4
FL
1358 cm_node->tcp_cntxt.rcv_nxt++;
1359 cleanup_retrans_entry(cm_node);
6492cdf3 1360 cm_node->state = NES_CM_STATE_LAST_ACK;
9d5ab133 1361 send_fin(cm_node, NULL);
6492cdf3
FL
1362 break;
1363 case NES_CM_STATE_FIN_WAIT1:
109d67e4
FL
1364 cm_node->tcp_cntxt.rcv_nxt++;
1365 cleanup_retrans_entry(cm_node);
6492cdf3 1366 cm_node->state = NES_CM_STATE_CLOSING;
9d5ab133
FL
1367 send_ack(cm_node, NULL);
1368 /* Wait for ACK as this is simultanous close..
1369 * After we receive ACK, do not send anything..
1370 * Just rm the node.. Done.. */
6492cdf3
FL
1371 break;
1372 case NES_CM_STATE_FIN_WAIT2:
109d67e4
FL
1373 cm_node->tcp_cntxt.rcv_nxt++;
1374 cleanup_retrans_entry(cm_node);
6492cdf3 1375 cm_node->state = NES_CM_STATE_TIME_WAIT;
9d5ab133
FL
1376 send_ack(cm_node, NULL);
1377 schedule_nes_timer(cm_node, NULL, NES_TIMER_TYPE_CLOSE, 1, 0);
1378 break;
1379 case NES_CM_STATE_TIME_WAIT:
109d67e4
FL
1380 cm_node->tcp_cntxt.rcv_nxt++;
1381 cleanup_retrans_entry(cm_node);
6492cdf3 1382 cm_node->state = NES_CM_STATE_CLOSED;
9d5ab133 1383 rem_ref_cm_node(cm_node->cm_core, cm_node);
6492cdf3
FL
1384 break;
1385 case NES_CM_STATE_TSA:
1386 default:
1387 nes_debug(NES_DBG_CM, "Error Rcvd FIN for node-%p state = %d\n",
1388 cm_node, cm_node->state);
6492cdf3 1389 break;
3c2d774c 1390 }
6492cdf3 1391}
3c2d774c 1392
3c2d774c 1393
6492cdf3
FL
1394static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1395 struct tcphdr *tcph)
1396{
3c2d774c 1397
6492cdf3 1398 int reset = 0; /* whether to send reset in case of err.. */
183ecfa3 1399 int passive_state;
6492cdf3
FL
1400 atomic_inc(&cm_resets_recvd);
1401 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
1402 " refcnt=%d\n", cm_node, cm_node->state,
1403 atomic_read(&cm_node->ref_count));
1404 cleanup_retrans_entry(cm_node);
1405 switch (cm_node->state) {
1406 case NES_CM_STATE_SYN_SENT:
1407 case NES_CM_STATE_MPAREQ_SENT:
1408 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1409 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1410 cm_node->listener, cm_node->state);
1411 active_open_err(cm_node, skb, reset);
1412 break;
183ecfa3
FL
1413 case NES_CM_STATE_MPAREQ_RCVD:
1414 passive_state = atomic_add_return(1, &cm_node->passive_state);
1415 if (passive_state == NES_SEND_RESET_EVENT)
1416 create_event(cm_node, NES_CM_EVENT_RESET);
183ecfa3
FL
1417 cm_node->state = NES_CM_STATE_CLOSED;
1418 dev_kfree_skb_any(skb);
1419 break;
6492cdf3
FL
1420 case NES_CM_STATE_ESTABLISHED:
1421 case NES_CM_STATE_SYN_RCVD:
1422 case NES_CM_STATE_LISTENING:
1423 nes_debug(NES_DBG_CM, "Bad state %s[%u]\n", __func__, __LINE__);
1424 passive_open_err(cm_node, skb, reset);
1425 break;
1426 case NES_CM_STATE_TSA:
183ecfa3
FL
1427 active_open_err(cm_node, skb, reset);
1428 break;
1429 case NES_CM_STATE_CLOSED:
183ecfa3
FL
1430 drop_packet(skb);
1431 break;
68237a0f 1432 case NES_CM_STATE_FIN_WAIT1:
109d67e4
FL
1433 case NES_CM_STATE_LAST_ACK:
1434 cm_node->cm_id->rem_ref(cm_node->cm_id);
9d5ab133 1435 case NES_CM_STATE_TIME_WAIT:
9d5ab133
FL
1436 cm_node->state = NES_CM_STATE_CLOSED;
1437 rem_ref_cm_node(cm_node->cm_core, cm_node);
1438 drop_packet(skb);
1439 break;
6492cdf3 1440 default:
183ecfa3 1441 drop_packet(skb);
6492cdf3
FL
1442 break;
1443 }
1444}
3c2d774c 1445
9d5ab133
FL
1446
1447static void handle_rcv_mpa(struct nes_cm_node *cm_node, struct sk_buff *skb)
6492cdf3
FL
1448{
1449
9d5ab133 1450 int ret = 0;
6492cdf3
FL
1451 int datasize = skb->len;
1452 u8 *dataloc = skb->data;
9d5ab133
FL
1453
1454 enum nes_cm_event_type type = NES_CM_EVENT_UNKNOWN;
1455 u32 res_type;
1456 ret = parse_mpa(cm_node, dataloc, &res_type, datasize);
1457 if (ret) {
6492cdf3 1458 nes_debug(NES_DBG_CM, "didn't like MPA Request\n");
9d5ab133 1459 if (cm_node->state == NES_CM_STATE_MPAREQ_SENT) {
6492cdf3
FL
1460 nes_debug(NES_DBG_CM, "%s[%u] create abort for "
1461 "cm_node=%p listener=%p state=%d\n", __func__,
1462 __LINE__, cm_node, cm_node->listener,
1463 cm_node->state);
1464 active_open_err(cm_node, skb, 1);
1465 } else {
1466 passive_open_err(cm_node, skb, 1);
3c2d774c 1467 }
9d5ab133
FL
1468 return;
1469 }
1470
1471 switch (cm_node->state) {
1472 case NES_CM_STATE_ESTABLISHED:
1473 if (res_type == NES_MPA_REQUEST_REJECT) {
1474 /*BIG problem as we are receiving the MPA.. So should
1475 * not be REJECT.. This is Passive Open.. We can
1476 * only receive it Reject for Active Open...*/
1477 WARN_ON(1);
1478 }
1479 cm_node->state = NES_CM_STATE_MPAREQ_RCVD;
1480 type = NES_CM_EVENT_MPA_REQ;
1481 atomic_set(&cm_node->passive_state,
1482 NES_PASSIVE_STATE_INDICATED);
1483 break;
1484 case NES_CM_STATE_MPAREQ_SENT:
109d67e4 1485 cleanup_retrans_entry(cm_node);
9d5ab133
FL
1486 if (res_type == NES_MPA_REQUEST_REJECT) {
1487 type = NES_CM_EVENT_MPA_REJECT;
1488 cm_node->state = NES_CM_STATE_MPAREJ_RCVD;
1489 } else {
1490 type = NES_CM_EVENT_CONNECTED;
6492cdf3 1491 cm_node->state = NES_CM_STATE_TSA;
9d5ab133 1492 }
6492cdf3 1493
9d5ab133
FL
1494 break;
1495 default:
1496 WARN_ON(1);
1497 break;
6492cdf3 1498 }
9d5ab133
FL
1499 dev_kfree_skb_any(skb);
1500 create_event(cm_node, type);
6492cdf3
FL
1501}
1502
1503static void indicate_pkt_err(struct nes_cm_node *cm_node, struct sk_buff *skb)
1504{
1505 switch (cm_node->state) {
1506 case NES_CM_STATE_SYN_SENT:
1507 case NES_CM_STATE_MPAREQ_SENT:
1508 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1509 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1510 cm_node->listener, cm_node->state);
1511 active_open_err(cm_node, skb, 1);
1512 break;
1513 case NES_CM_STATE_ESTABLISHED:
1514 case NES_CM_STATE_SYN_RCVD:
1515 passive_open_err(cm_node, skb, 1);
1516 break;
1517 case NES_CM_STATE_TSA:
1518 default:
1519 drop_packet(skb);
3c2d774c 1520 }
6492cdf3
FL
1521}
1522
1523static int check_syn(struct nes_cm_node *cm_node, struct tcphdr *tcph,
1524 struct sk_buff *skb)
1525{
1526 int err;
1527
1528 err = ((ntohl(tcph->ack_seq) == cm_node->tcp_cntxt.loc_seq_num))? 0 : 1;
1529 if (err)
1530 active_open_err(cm_node, skb, 1);
1531
1532 return err;
1533}
1534
1535static int check_seq(struct nes_cm_node *cm_node, struct tcphdr *tcph,
1536 struct sk_buff *skb)
1537{
1538 int err = 0;
1539 u32 seq;
1540 u32 ack_seq;
1541 u32 loc_seq_num = cm_node->tcp_cntxt.loc_seq_num;
1542 u32 rcv_nxt = cm_node->tcp_cntxt.rcv_nxt;
1543 u32 rcv_wnd;
1544 seq = ntohl(tcph->seq);
1545 ack_seq = ntohl(tcph->ack_seq);
1546 rcv_wnd = cm_node->tcp_cntxt.rcv_wnd;
1547 if (ack_seq != loc_seq_num)
1548 err = 1;
c11470f9 1549 else if (!between(seq, rcv_nxt, (rcv_nxt+rcv_wnd)))
6492cdf3
FL
1550 err = 1;
1551 if (err) {
1552 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1553 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1554 cm_node->listener, cm_node->state);
1555 indicate_pkt_err(cm_node, skb);
1556 nes_debug(NES_DBG_CM, "seq ERROR cm_node =%p seq=0x%08X "
1557 "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node, seq, rcv_nxt,
1558 rcv_wnd);
1559 }
1560 return err;
1561}
1562
1563/*
1564 * handle_syn_pkt() is for Passive node. The syn packet is received when a node
1565 * is created with a listener or it may comein as rexmitted packet which in
1566 * that case will be just dropped.
1567 */
1568
1569static void handle_syn_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1570 struct tcphdr *tcph)
1571{
1572 int ret;
1573 u32 inc_sequence;
1574 int optionsize;
3c2d774c
GS
1575
1576 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
abb77256 1577 skb_trim(skb, 0);
6492cdf3 1578 inc_sequence = ntohl(tcph->seq);
3c2d774c 1579
6492cdf3
FL
1580 switch (cm_node->state) {
1581 case NES_CM_STATE_SYN_SENT:
1582 case NES_CM_STATE_MPAREQ_SENT:
1583 /* Rcvd syn on active open connection*/
1584 active_open_err(cm_node, skb, 1);
1585 break;
1586 case NES_CM_STATE_LISTENING:
1587 /* Passive OPEN */
6492cdf3
FL
1588 if (atomic_read(&cm_node->listener->pend_accepts_cnt) >
1589 cm_node->listener->backlog) {
1590 nes_debug(NES_DBG_CM, "drop syn due to backlog "
1591 "pressure \n");
1592 cm_backlog_drops++;
1593 passive_open_err(cm_node, skb, 0);
1594 break;
1595 }
1596 ret = handle_tcp_options(cm_node, tcph, skb, optionsize,
1597 1);
1598 if (ret) {
1599 passive_open_err(cm_node, skb, 0);
1600 /* drop pkt */
1601 break;
1602 }
1603 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
1604 BUG_ON(cm_node->send_entry);
9d5ab133
FL
1605 cm_node->accept_pend = 1;
1606 atomic_inc(&cm_node->listener->pend_accepts_cnt);
1607
6492cdf3
FL
1608 cm_node->state = NES_CM_STATE_SYN_RCVD;
1609 send_syn(cm_node, 1, skb);
1610 break;
abb77256
FL
1611 case NES_CM_STATE_CLOSED:
1612 cleanup_retrans_entry(cm_node);
886f98a3 1613 add_ref_cm_node(cm_node);
abb77256
FL
1614 send_reset(cm_node, skb);
1615 break;
6492cdf3
FL
1616 case NES_CM_STATE_TSA:
1617 case NES_CM_STATE_ESTABLISHED:
1618 case NES_CM_STATE_FIN_WAIT1:
1619 case NES_CM_STATE_FIN_WAIT2:
1620 case NES_CM_STATE_MPAREQ_RCVD:
1621 case NES_CM_STATE_LAST_ACK:
1622 case NES_CM_STATE_CLOSING:
1623 case NES_CM_STATE_UNKNOWN:
6492cdf3
FL
1624 default:
1625 drop_packet(skb);
1626 break;
1627 }
1628}
1629
1630static void handle_synack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1631 struct tcphdr *tcph)
1632{
1633
1634 int ret;
1635 u32 inc_sequence;
1636 int optionsize;
1637
1638 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
abb77256 1639 skb_trim(skb, 0);
6492cdf3
FL
1640 inc_sequence = ntohl(tcph->seq);
1641 switch (cm_node->state) {
1642 case NES_CM_STATE_SYN_SENT:
9d5ab133 1643 cleanup_retrans_entry(cm_node);
6492cdf3
FL
1644 /* active open */
1645 if (check_syn(cm_node, tcph, skb))
1646 return;
1647 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
1648 /* setup options */
1649 ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 0);
1650 if (ret) {
1651 nes_debug(NES_DBG_CM, "cm_node=%p tcp_options failed\n",
1652 cm_node);
1653 break;
1654 }
1655 cleanup_retrans_entry(cm_node);
1656 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
1657 send_mpa_request(cm_node, skb);
1658 cm_node->state = NES_CM_STATE_MPAREQ_SENT;
1659 break;
1660 case NES_CM_STATE_MPAREQ_RCVD:
1661 /* passive open, so should not be here */
1662 passive_open_err(cm_node, skb, 1);
1663 break;
abb77256 1664 case NES_CM_STATE_LISTENING:
886f98a3
FL
1665 cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
1666 cleanup_retrans_entry(cm_node);
1667 cm_node->state = NES_CM_STATE_CLOSED;
1668 send_reset(cm_node, skb);
1669 break;
abb77256
FL
1670 case NES_CM_STATE_CLOSED:
1671 cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
1672 cleanup_retrans_entry(cm_node);
886f98a3 1673 add_ref_cm_node(cm_node);
abb77256
FL
1674 send_reset(cm_node, skb);
1675 break;
6492cdf3
FL
1676 case NES_CM_STATE_ESTABLISHED:
1677 case NES_CM_STATE_FIN_WAIT1:
1678 case NES_CM_STATE_FIN_WAIT2:
1679 case NES_CM_STATE_LAST_ACK:
1680 case NES_CM_STATE_TSA:
1681 case NES_CM_STATE_CLOSING:
1682 case NES_CM_STATE_UNKNOWN:
6492cdf3
FL
1683 case NES_CM_STATE_MPAREQ_SENT:
1684 default:
1685 drop_packet(skb);
1686 break;
1687 }
1688}
3c2d774c 1689
109d67e4 1690static int handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
6492cdf3
FL
1691 struct tcphdr *tcph)
1692{
1693 int datasize = 0;
1694 u32 inc_sequence;
1695 u32 rem_seq_ack;
1696 u32 rem_seq;
109d67e4 1697 int ret = 0;
abb77256 1698 int optionsize;
abb77256 1699 optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
abb77256 1700
6492cdf3 1701 if (check_seq(cm_node, tcph, skb))
109d67e4 1702 return -EINVAL;
6492cdf3
FL
1703
1704 skb_pull(skb, tcph->doff << 2);
3c2d774c 1705 inc_sequence = ntohl(tcph->seq);
6492cdf3
FL
1706 rem_seq = ntohl(tcph->seq);
1707 rem_seq_ack = ntohl(tcph->ack_seq);
1708 datasize = skb->len;
6492cdf3
FL
1709 switch (cm_node->state) {
1710 case NES_CM_STATE_SYN_RCVD:
1711 /* Passive OPEN */
109d67e4 1712 cleanup_retrans_entry(cm_node);
abb77256
FL
1713 ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 1);
1714 if (ret)
1715 break;
6492cdf3
FL
1716 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
1717 cm_node->state = NES_CM_STATE_ESTABLISHED;
1718 if (datasize) {
1719 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
9d5ab133 1720 handle_rcv_mpa(cm_node, skb);
109d67e4 1721 } else /* rcvd ACK only */
6492cdf3 1722 dev_kfree_skb_any(skb);
6492cdf3
FL
1723 break;
1724 case NES_CM_STATE_ESTABLISHED:
1725 /* Passive OPEN */
9d5ab133 1726 cleanup_retrans_entry(cm_node);
6492cdf3
FL
1727 if (datasize) {
1728 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
9d5ab133 1729 handle_rcv_mpa(cm_node, skb);
6492cdf3
FL
1730 } else
1731 drop_packet(skb);
1732 break;
1733 case NES_CM_STATE_MPAREQ_SENT:
1734 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
1735 if (datasize) {
1736 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
9d5ab133 1737 handle_rcv_mpa(cm_node, skb);
109d67e4 1738 } else /* Could be just an ack pkt.. */
6492cdf3 1739 dev_kfree_skb_any(skb);
6492cdf3 1740 break;
abb77256 1741 case NES_CM_STATE_LISTENING:
886f98a3
FL
1742 cleanup_retrans_entry(cm_node);
1743 cm_node->state = NES_CM_STATE_CLOSED;
1744 send_reset(cm_node, skb);
1745 break;
abb77256
FL
1746 case NES_CM_STATE_CLOSED:
1747 cleanup_retrans_entry(cm_node);
886f98a3 1748 add_ref_cm_node(cm_node);
abb77256
FL
1749 send_reset(cm_node, skb);
1750 break;
9d5ab133 1751 case NES_CM_STATE_LAST_ACK:
109d67e4 1752 case NES_CM_STATE_CLOSING:
9d5ab133
FL
1753 cleanup_retrans_entry(cm_node);
1754 cm_node->state = NES_CM_STATE_CLOSED;
1755 cm_node->cm_id->rem_ref(cm_node->cm_id);
9d5ab133
FL
1756 rem_ref_cm_node(cm_node->cm_core, cm_node);
1757 drop_packet(skb);
1758 break;
6492cdf3 1759 case NES_CM_STATE_FIN_WAIT1:
9d5ab133
FL
1760 cleanup_retrans_entry(cm_node);
1761 drop_packet(skb);
1762 cm_node->state = NES_CM_STATE_FIN_WAIT2;
1763 break;
6492cdf3
FL
1764 case NES_CM_STATE_SYN_SENT:
1765 case NES_CM_STATE_FIN_WAIT2:
1766 case NES_CM_STATE_TSA:
6492cdf3 1767 case NES_CM_STATE_MPAREQ_RCVD:
6492cdf3
FL
1768 case NES_CM_STATE_UNKNOWN:
1769 default:
109d67e4 1770 cleanup_retrans_entry(cm_node);
6492cdf3
FL
1771 drop_packet(skb);
1772 break;
3c2d774c 1773 }
109d67e4 1774 return ret;
6492cdf3 1775}
3c2d774c 1776
3c2d774c
GS
1777
1778
6492cdf3
FL
1779static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
1780 struct sk_buff *skb, int optionsize, int passive)
1781{
1782 u8 *optionsloc = (u8 *)&tcph[1];
3c2d774c 1783 if (optionsize) {
6492cdf3
FL
1784 if (process_options(cm_node, optionsloc, optionsize,
1785 (u32)tcph->syn)) {
1786 nes_debug(NES_DBG_CM, "%s: Node %p, Sending RESET\n",
1787 __func__, cm_node);
1788 if (passive)
abb77256 1789 passive_open_err(cm_node, skb, 1);
6492cdf3 1790 else
abb77256 1791 active_open_err(cm_node, skb, 1);
6492cdf3 1792 return 1;
3c2d774c 1793 }
6492cdf3 1794 }
3c2d774c
GS
1795
1796 cm_node->tcp_cntxt.snd_wnd = ntohs(tcph->window) <<
1797 cm_node->tcp_cntxt.snd_wscale;
1798
6492cdf3 1799 if (cm_node->tcp_cntxt.snd_wnd > cm_node->tcp_cntxt.max_snd_wnd)
3c2d774c 1800 cm_node->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.snd_wnd;
6492cdf3
FL
1801 return 0;
1802}
3c2d774c 1803
6492cdf3
FL
1804/*
1805 * active_open_err() will send reset() if flag set..
1806 * It will also send ABORT event.
1807 */
3c2d774c 1808
6492cdf3
FL
1809static void active_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
1810 int reset)
1811{
1812 cleanup_retrans_entry(cm_node);
1813 if (reset) {
1814 nes_debug(NES_DBG_CM, "ERROR active err called for cm_node=%p, "
1815 "state=%d\n", cm_node, cm_node->state);
1816 add_ref_cm_node(cm_node);
1817 send_reset(cm_node, skb);
1818 } else
1819 dev_kfree_skb_any(skb);
3c2d774c 1820
6492cdf3
FL
1821 cm_node->state = NES_CM_STATE_CLOSED;
1822 create_event(cm_node, NES_CM_EVENT_ABORTED);
1823}
3c2d774c 1824
6492cdf3
FL
1825/*
1826 * passive_open_err() will either do a reset() or will free up the skb and
1827 * remove the cm_node.
1828 */
3c2d774c 1829
6492cdf3
FL
1830static void passive_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
1831 int reset)
1832{
1833 cleanup_retrans_entry(cm_node);
1834 cm_node->state = NES_CM_STATE_CLOSED;
1835 if (reset) {
1836 nes_debug(NES_DBG_CM, "passive_open_err sending RST for "
1837 "cm_node=%p state =%d\n", cm_node, cm_node->state);
1838 send_reset(cm_node, skb);
1839 } else {
1840 dev_kfree_skb_any(skb);
1841 rem_ref_cm_node(cm_node->cm_core, cm_node);
3c2d774c 1842 }
6492cdf3 1843}
3c2d774c 1844
6492cdf3
FL
1845/*
1846 * free_retrans_entry() routines assumes that the retrans_list_lock has
1847 * been acquired before calling.
1848 */
1849static void free_retrans_entry(struct nes_cm_node *cm_node)
1850{
1851 struct nes_timer_entry *send_entry;
1852 send_entry = cm_node->send_entry;
1853 if (send_entry) {
1854 cm_node->send_entry = NULL;
1855 dev_kfree_skb_any(send_entry->skb);
1856 kfree(send_entry);
1857 rem_ref_cm_node(cm_node->cm_core, cm_node);
3c2d774c 1858 }
6492cdf3 1859}
3c2d774c 1860
6492cdf3
FL
1861static void cleanup_retrans_entry(struct nes_cm_node *cm_node)
1862{
1863 unsigned long flags;
3c2d774c 1864
6492cdf3
FL
1865 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
1866 free_retrans_entry(cm_node);
1867 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
3c2d774c
GS
1868}
1869
6492cdf3
FL
1870/**
1871 * process_packet
1872 * Returns skb if to be freed, else it will return NULL if already used..
1873 */
1874static void process_packet(struct nes_cm_node *cm_node, struct sk_buff *skb,
1875 struct nes_cm_core *cm_core)
1876{
1877 enum nes_tcpip_pkt_type pkt_type = NES_PKT_TYPE_UNKNOWN;
1878 struct tcphdr *tcph = tcp_hdr(skb);
9d5ab133 1879 u32 fin_set = 0;
109d67e4 1880 int ret = 0;
6492cdf3
FL
1881 skb_pull(skb, ip_hdr(skb)->ihl << 2);
1882
1883 nes_debug(NES_DBG_CM, "process_packet: cm_node=%p state =%d syn=%d "
1884 "ack=%d rst=%d fin=%d\n", cm_node, cm_node->state, tcph->syn,
1885 tcph->ack, tcph->rst, tcph->fin);
1886
1887 if (tcph->rst)
1888 pkt_type = NES_PKT_TYPE_RST;
1889 else if (tcph->syn) {
1890 pkt_type = NES_PKT_TYPE_SYN;
1891 if (tcph->ack)
1892 pkt_type = NES_PKT_TYPE_SYNACK;
9d5ab133 1893 } else if (tcph->ack)
6492cdf3 1894 pkt_type = NES_PKT_TYPE_ACK;
9d5ab133
FL
1895 if (tcph->fin)
1896 fin_set = 1;
6492cdf3
FL
1897
1898 switch (pkt_type) {
1899 case NES_PKT_TYPE_SYN:
1900 handle_syn_pkt(cm_node, skb, tcph);
1901 break;
1902 case NES_PKT_TYPE_SYNACK:
1903 handle_synack_pkt(cm_node, skb, tcph);
1904 break;
1905 case NES_PKT_TYPE_ACK:
109d67e4
FL
1906 ret = handle_ack_pkt(cm_node, skb, tcph);
1907 if (fin_set && !ret)
9d5ab133 1908 handle_fin_pkt(cm_node);
6492cdf3
FL
1909 break;
1910 case NES_PKT_TYPE_RST:
1911 handle_rst_pkt(cm_node, skb, tcph);
1912 break;
6492cdf3 1913 default:
109d67e4 1914 if ((fin_set) && (!check_seq(cm_node, tcph, skb)))
9d5ab133 1915 handle_fin_pkt(cm_node);
109d67e4 1916 drop_packet(skb);
6492cdf3
FL
1917 break;
1918 }
1919}
3c2d774c
GS
1920
1921/**
1922 * mini_cm_listen - create a listen node with params
1923 */
1924static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *cm_core,
6492cdf3 1925 struct nes_vnic *nesvnic, struct nes_cm_info *cm_info)
3c2d774c
GS
1926{
1927 struct nes_cm_listener *listener;
1928 unsigned long flags;
1929
1930 nes_debug(NES_DBG_CM, "Search for 0x%08x : 0x%04x\n",
1931 cm_info->loc_addr, cm_info->loc_port);
1932
1933 /* cannot have multiple matching listeners */
1934 listener = find_listener(cm_core, htonl(cm_info->loc_addr),
1935 htons(cm_info->loc_port), NES_CM_LISTENER_EITHER_STATE);
1936 if (listener && listener->listener_state == NES_CM_LISTENER_ACTIVE_STATE) {
1937 /* find automatically incs ref count ??? */
1938 atomic_dec(&listener->ref_count);
1939 nes_debug(NES_DBG_CM, "Not creating listener since it already exists\n");
1940 return NULL;
1941 }
1942
1943 if (!listener) {
1944 /* create a CM listen node (1/2 node to compare incoming traffic to) */
1945 listener = kzalloc(sizeof(*listener), GFP_ATOMIC);
1946 if (!listener) {
1947 nes_debug(NES_DBG_CM, "Not creating listener memory allocation failed\n");
1948 return NULL;
1949 }
1950
3c2d774c
GS
1951 listener->loc_addr = htonl(cm_info->loc_addr);
1952 listener->loc_port = htons(cm_info->loc_port);
1953 listener->reused_node = 0;
1954
1955 atomic_set(&listener->ref_count, 1);
1956 }
1957 /* pasive case */
1958 /* find already inc'ed the ref count */
1959 else {
1960 listener->reused_node = 1;
1961 }
1962
1963 listener->cm_id = cm_info->cm_id;
1964 atomic_set(&listener->pend_accepts_cnt, 0);
1965 listener->cm_core = cm_core;
1966 listener->nesvnic = nesvnic;
1967 atomic_inc(&cm_core->node_cnt);
3c2d774c 1968
3c2d774c
GS
1969 listener->conn_type = cm_info->conn_type;
1970 listener->backlog = cm_info->backlog;
1971 listener->listener_state = NES_CM_LISTENER_ACTIVE_STATE;
1972
1973 if (!listener->reused_node) {
1974 spin_lock_irqsave(&cm_core->listen_list_lock, flags);
1975 list_add(&listener->list, &cm_core->listen_list.list);
1976 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
1977 atomic_inc(&cm_core->listen_node_cnt);
1978 }
1979
1980 nes_debug(NES_DBG_CM, "Api - listen(): addr=0x%08X, port=0x%04x,"
1981 " listener = %p, backlog = %d, cm_id = %p.\n",
1982 cm_info->loc_addr, cm_info->loc_port,
1983 listener, listener->backlog, listener->cm_id);
1984
1985 return listener;
1986}
1987
1988
1989/**
1990 * mini_cm_connect - make a connection node with params
1991 */
54c86a8c 1992static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
6492cdf3
FL
1993 struct nes_vnic *nesvnic, u16 private_data_len,
1994 void *private_data, struct nes_cm_info *cm_info)
3c2d774c
GS
1995{
1996 int ret = 0;
1997 struct nes_cm_node *cm_node;
1998 struct nes_cm_listener *loopbackremotelistener;
1999 struct nes_cm_node *loopbackremotenode;
2000 struct nes_cm_info loopback_cm_info;
6492cdf3
FL
2001 u16 mpa_frame_size = sizeof(struct ietf_mpa_frame) + private_data_len;
2002 struct ietf_mpa_frame *mpa_frame = NULL;
3c2d774c
GS
2003
2004 /* create a CM connection node */
2005 cm_node = make_cm_node(cm_core, nesvnic, cm_info, NULL);
2006 if (!cm_node)
2007 return NULL;
6492cdf3 2008 mpa_frame = &cm_node->mpa_frame;
1cf078c9 2009 memcpy(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE);
6492cdf3
FL
2010 mpa_frame->flags = IETF_MPA_FLAGS_CRC;
2011 mpa_frame->rev = IETF_MPA_VERSION;
2012 mpa_frame->priv_data_len = htons(private_data_len);
3c2d774c 2013
7495ab68 2014 /* set our node side to client (active) side */
3c2d774c
GS
2015 cm_node->tcp_cntxt.client = 1;
2016 cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
2017
2018 if (cm_info->loc_addr == cm_info->rem_addr) {
6492cdf3
FL
2019 loopbackremotelistener = find_listener(cm_core,
2020 ntohl(nesvnic->local_ipaddr), cm_node->rem_port,
2021 NES_CM_LISTENER_ACTIVE_STATE);
3c2d774c
GS
2022 if (loopbackremotelistener == NULL) {
2023 create_event(cm_node, NES_CM_EVENT_ABORTED);
2024 } else {
3c2d774c
GS
2025 loopback_cm_info = *cm_info;
2026 loopback_cm_info.loc_port = cm_info->rem_port;
2027 loopback_cm_info.rem_port = cm_info->loc_port;
2028 loopback_cm_info.cm_id = loopbackremotelistener->cm_id;
6492cdf3
FL
2029 loopbackremotenode = make_cm_node(cm_core, nesvnic,
2030 &loopback_cm_info, loopbackremotelistener);
79fc3d74
FL
2031 if (!loopbackremotenode) {
2032 rem_ref_cm_node(cm_node->cm_core, cm_node);
2033 return NULL;
2034 }
2035 atomic_inc(&cm_loopbacks);
3c2d774c 2036 loopbackremotenode->loopbackpartner = cm_node;
6492cdf3
FL
2037 loopbackremotenode->tcp_cntxt.rcv_wscale =
2038 NES_CM_DEFAULT_RCV_WND_SCALE;
3c2d774c 2039 cm_node->loopbackpartner = loopbackremotenode;
6492cdf3
FL
2040 memcpy(loopbackremotenode->mpa_frame_buf, private_data,
2041 private_data_len);
2042 loopbackremotenode->mpa_frame_size = private_data_len;
3c2d774c 2043
6492cdf3
FL
2044 /* we are done handling this state. */
2045 /* set node to a TSA state */
3c2d774c 2046 cm_node->state = NES_CM_STATE_TSA;
6492cdf3
FL
2047 cm_node->tcp_cntxt.rcv_nxt =
2048 loopbackremotenode->tcp_cntxt.loc_seq_num;
2049 loopbackremotenode->tcp_cntxt.rcv_nxt =
2050 cm_node->tcp_cntxt.loc_seq_num;
2051 cm_node->tcp_cntxt.max_snd_wnd =
2052 loopbackremotenode->tcp_cntxt.rcv_wnd;
2053 loopbackremotenode->tcp_cntxt.max_snd_wnd =
2054 cm_node->tcp_cntxt.rcv_wnd;
2055 cm_node->tcp_cntxt.snd_wnd =
2056 loopbackremotenode->tcp_cntxt.rcv_wnd;
2057 loopbackremotenode->tcp_cntxt.snd_wnd =
2058 cm_node->tcp_cntxt.rcv_wnd;
2059 cm_node->tcp_cntxt.snd_wscale =
2060 loopbackremotenode->tcp_cntxt.rcv_wscale;
2061 loopbackremotenode->tcp_cntxt.snd_wscale =
2062 cm_node->tcp_cntxt.rcv_wscale;
9d5ab133 2063 loopbackremotenode->state = NES_CM_STATE_MPAREQ_RCVD;
3c2d774c
GS
2064 create_event(loopbackremotenode, NES_CM_EVENT_MPA_REQ);
2065 }
2066 return cm_node;
2067 }
2068
2069 /* set our node side to client (active) side */
2070 cm_node->tcp_cntxt.client = 1;
2071 /* init our MPA frame ptr */
6492cdf3
FL
2072 memcpy(mpa_frame->priv_data, private_data, private_data_len);
2073
3c2d774c
GS
2074 cm_node->mpa_frame_size = mpa_frame_size;
2075
2076 /* send a syn and goto syn sent state */
2077 cm_node->state = NES_CM_STATE_SYN_SENT;
6492cdf3
FL
2078 ret = send_syn(cm_node, 0, NULL);
2079
2080 if (ret) {
2081 /* error in sending the syn free up the cm_node struct */
2082 nes_debug(NES_DBG_CM, "Api - connect() FAILED: dest "
2083 "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
2084 cm_node->rem_addr, cm_node->rem_port, cm_node,
2085 cm_node->cm_id);
2086 rem_ref_cm_node(cm_node->cm_core, cm_node);
2087 cm_node = NULL;
2088 }
3c2d774c 2089
6492cdf3
FL
2090 if (cm_node)
2091 nes_debug(NES_DBG_CM, "Api - connect(): dest addr=0x%08X,"
2092 "port=0x%04x, cm_node=%p, cm_id = %p.\n",
2093 cm_node->rem_addr, cm_node->rem_port, cm_node,
2094 cm_node->cm_id);
3c2d774c
GS
2095
2096 return cm_node;
2097}
2098
2099
2100/**
2101 * mini_cm_accept - accept a connection
2102 * This function is never called
2103 */
6492cdf3
FL
2104static int mini_cm_accept(struct nes_cm_core *cm_core,
2105 struct ietf_mpa_frame *mpa_frame, struct nes_cm_node *cm_node)
3c2d774c
GS
2106{
2107 return 0;
2108}
2109
2110
2111/**
2112 * mini_cm_reject - reject and teardown a connection
2113 */
1a855fbf 2114static int mini_cm_reject(struct nes_cm_core *cm_core,
6492cdf3 2115 struct ietf_mpa_frame *mpa_frame, struct nes_cm_node *cm_node)
3c2d774c
GS
2116{
2117 int ret = 0;
9d5ab133 2118 int err = 0;
183ecfa3 2119 int passive_state;
9d5ab133
FL
2120 struct nes_cm_event event;
2121 struct iw_cm_id *cm_id = cm_node->cm_id;
2122 struct nes_cm_node *loopback = cm_node->loopbackpartner;
3c2d774c 2123
6492cdf3
FL
2124 nes_debug(NES_DBG_CM, "%s cm_node=%p type=%d state=%d\n",
2125 __func__, cm_node, cm_node->tcp_cntxt.client, cm_node->state);
3c2d774c 2126
6492cdf3
FL
2127 if (cm_node->tcp_cntxt.client)
2128 return ret;
2129 cleanup_retrans_entry(cm_node);
3c2d774c 2130
9d5ab133
FL
2131 if (!loopback) {
2132 passive_state = atomic_add_return(1, &cm_node->passive_state);
2133 if (passive_state == NES_SEND_RESET_EVENT) {
2134 cm_node->state = NES_CM_STATE_CLOSED;
2135 rem_ref_cm_node(cm_core, cm_node);
2136 } else {
c5a7d489
FL
2137 if (cm_node->state == NES_CM_STATE_LISTENER_DESTROYED) {
2138 rem_ref_cm_node(cm_core, cm_node);
2139 } else {
2140 ret = send_mpa_reject(cm_node);
2141 if (ret) {
2142 cm_node->state = NES_CM_STATE_CLOSED;
2143 err = send_reset(cm_node, NULL);
2144 if (err)
2145 WARN_ON(1);
2146 } else
2147 cm_id->add_ref(cm_id);
2148 }
9d5ab133
FL
2149 }
2150 } else {
2151 cm_node->cm_id = NULL;
c5a7d489
FL
2152 if (cm_node->state == NES_CM_STATE_LISTENER_DESTROYED) {
2153 rem_ref_cm_node(cm_core, cm_node);
2154 rem_ref_cm_node(cm_core, loopback);
2155 } else {
2156 event.cm_node = loopback;
2157 event.cm_info.rem_addr = loopback->rem_addr;
2158 event.cm_info.loc_addr = loopback->loc_addr;
2159 event.cm_info.rem_port = loopback->rem_port;
2160 event.cm_info.loc_port = loopback->loc_port;
2161 event.cm_info.cm_id = loopback->cm_id;
2162 cm_event_mpa_reject(&event);
2163 rem_ref_cm_node(cm_core, cm_node);
2164 loopback->state = NES_CM_STATE_CLOSING;
9d5ab133 2165
c5a7d489
FL
2166 cm_id = loopback->cm_id;
2167 rem_ref_cm_node(cm_core, loopback);
2168 cm_id->rem_ref(cm_id);
2169 }
9d5ab133
FL
2170 }
2171
3c2d774c
GS
2172 return ret;
2173}
2174
2175
2176/**
2177 * mini_cm_close
2178 */
1a855fbf 2179static int mini_cm_close(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
3c2d774c
GS
2180{
2181 int ret = 0;
2182
2183 if (!cm_core || !cm_node)
2184 return -EINVAL;
2185
2186 switch (cm_node->state) {
6492cdf3
FL
2187 case NES_CM_STATE_SYN_RCVD:
2188 case NES_CM_STATE_SYN_SENT:
2189 case NES_CM_STATE_ONE_SIDE_ESTABLISHED:
2190 case NES_CM_STATE_ESTABLISHED:
2191 case NES_CM_STATE_ACCEPTING:
2192 case NES_CM_STATE_MPAREQ_SENT:
2193 case NES_CM_STATE_MPAREQ_RCVD:
2194 cleanup_retrans_entry(cm_node);
2195 send_reset(cm_node, NULL);
2196 break;
2197 case NES_CM_STATE_CLOSE_WAIT:
2198 cm_node->state = NES_CM_STATE_LAST_ACK;
2199 send_fin(cm_node, NULL);
2200 break;
2201 case NES_CM_STATE_FIN_WAIT1:
2202 case NES_CM_STATE_FIN_WAIT2:
2203 case NES_CM_STATE_LAST_ACK:
2204 case NES_CM_STATE_TIME_WAIT:
2205 case NES_CM_STATE_CLOSING:
2206 ret = -1;
2207 break;
2208 case NES_CM_STATE_LISTENING:
886f98a3
FL
2209 cleanup_retrans_entry(cm_node);
2210 send_reset(cm_node, NULL);
2211 break;
2212 case NES_CM_STATE_MPAREJ_RCVD:
6492cdf3
FL
2213 case NES_CM_STATE_UNKNOWN:
2214 case NES_CM_STATE_INITED:
2215 case NES_CM_STATE_CLOSED:
c5a7d489 2216 case NES_CM_STATE_LISTENER_DESTROYED:
6492cdf3
FL
2217 ret = rem_ref_cm_node(cm_core, cm_node);
2218 break;
2219 case NES_CM_STATE_TSA:
2220 if (cm_node->send_entry)
2221 printk(KERN_ERR "ERROR Close got called from STATE_TSA "
2222 "send_entry=%p\n", cm_node->send_entry);
2223 ret = rem_ref_cm_node(cm_core, cm_node);
2224 break;
3c2d774c 2225 }
3c2d774c
GS
2226 return ret;
2227}
2228
2229
2230/**
2231 * recv_pkt - recv an ETHERNET packet, and process it through CM
2232 * node state machine
2233 */
4a14f6a7 2234static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
6492cdf3 2235 struct nes_vnic *nesvnic, struct sk_buff *skb)
3c2d774c
GS
2236{
2237 struct nes_cm_node *cm_node = NULL;
2238 struct nes_cm_listener *listener = NULL;
2239 struct iphdr *iph;
2240 struct tcphdr *tcph;
2241 struct nes_cm_info nfo;
4a14f6a7 2242 int skb_handled = 1;
03080e5c 2243 __be32 tmp_daddr, tmp_saddr;
3c2d774c 2244
6492cdf3 2245 if (!skb)
4a14f6a7 2246 return 0;
6492cdf3 2247 if (skb->len < sizeof(struct iphdr) + sizeof(struct tcphdr)) {
4a14f6a7 2248 return 0;
3c2d774c
GS
2249 }
2250
2251 iph = (struct iphdr *)skb->data;
2252 tcph = (struct tcphdr *)(skb->data + sizeof(struct iphdr));
3c2d774c
GS
2253
2254 nfo.loc_addr = ntohl(iph->daddr);
2255 nfo.loc_port = ntohs(tcph->dest);
2256 nfo.rem_addr = ntohl(iph->saddr);
2257 nfo.rem_port = ntohs(tcph->source);
2258
03080e5c
HH
2259 tmp_daddr = cpu_to_be32(iph->daddr);
2260 tmp_saddr = cpu_to_be32(iph->saddr);
2261
63779436 2262 nes_debug(NES_DBG_CM, "Received packet: dest=%pI4:0x%04X src=%pI4:0x%04X\n",
03080e5c 2263 &tmp_daddr, tcph->dest, &tmp_saddr, tcph->source);
3c2d774c 2264
6492cdf3
FL
2265 do {
2266 cm_node = find_node(cm_core,
3c2d774c
GS
2267 nfo.rem_port, nfo.rem_addr,
2268 nfo.loc_port, nfo.loc_addr);
2269
3c2d774c 2270 if (!cm_node) {
6492cdf3
FL
2271 /* Only type of packet accepted are for */
2272 /* the PASSIVE open (syn only) */
2273 if ((!tcph->syn) || (tcph->ack)) {
4a14f6a7 2274 skb_handled = 0;
6492cdf3
FL
2275 break;
2276 }
2277 listener = find_listener(cm_core, nfo.loc_addr,
2278 nfo.loc_port,
2279 NES_CM_LISTENER_ACTIVE_STATE);
4a14f6a7
FL
2280 if (!listener) {
2281 nfo.cm_id = NULL;
2282 nfo.conn_type = 0;
2283 nes_debug(NES_DBG_CM, "Unable to find listener for the pkt\n");
2284 skb_handled = 0;
6492cdf3
FL
2285 break;
2286 }
4a14f6a7
FL
2287 nfo.cm_id = listener->cm_id;
2288 nfo.conn_type = listener->conn_type;
6492cdf3
FL
2289 cm_node = make_cm_node(cm_core, nesvnic, &nfo,
2290 listener);
2291 if (!cm_node) {
2292 nes_debug(NES_DBG_CM, "Unable to allocate "
2293 "node\n");
2294 cm_packets_dropped++;
3c2d774c 2295 atomic_dec(&listener->ref_count);
6492cdf3
FL
2296 dev_kfree_skb_any(skb);
2297 break;
3c2d774c 2298 }
6492cdf3
FL
2299 if (!tcph->rst && !tcph->fin) {
2300 cm_node->state = NES_CM_STATE_LISTENING;
2301 } else {
2302 cm_packets_dropped++;
2303 rem_ref_cm_node(cm_core, cm_node);
2304 dev_kfree_skb_any(skb);
2305 break;
3c2d774c 2306 }
6492cdf3
FL
2307 add_ref_cm_node(cm_node);
2308 } else if (cm_node->state == NES_CM_STATE_TSA) {
3c2d774c 2309 rem_ref_cm_node(cm_core, cm_node);
6492cdf3
FL
2310 atomic_inc(&cm_accel_dropped_pkts);
2311 dev_kfree_skb_any(skb);
2312 break;
3c2d774c 2313 }
4a14f6a7
FL
2314 skb_reset_network_header(skb);
2315 skb_set_transport_header(skb, sizeof(*tcph));
2316 skb->len = ntohs(iph->tot_len);
6492cdf3
FL
2317 process_packet(cm_node, skb, cm_core);
2318 rem_ref_cm_node(cm_core, cm_node);
2319 } while (0);
4a14f6a7 2320 return skb_handled;
3c2d774c
GS
2321}
2322
2323
2324/**
2325 * nes_cm_alloc_core - allocate a top level instance of a cm core
2326 */
1a855fbf 2327static struct nes_cm_core *nes_cm_alloc_core(void)
3c2d774c 2328{
3c2d774c 2329 struct nes_cm_core *cm_core;
3c2d774c
GS
2330
2331 /* setup the CM core */
2332 /* alloc top level core control structure */
2333 cm_core = kzalloc(sizeof(*cm_core), GFP_KERNEL);
2334 if (!cm_core)
2335 return NULL;
2336
2337 INIT_LIST_HEAD(&cm_core->connected_nodes);
2338 init_timer(&cm_core->tcp_timer);
2339 cm_core->tcp_timer.function = nes_cm_timer_tick;
2340
2341 cm_core->mtu = NES_CM_DEFAULT_MTU;
2342 cm_core->state = NES_CM_STATE_INITED;
2343 cm_core->free_tx_pkt_max = NES_CM_DEFAULT_FREE_PKTS;
2344
3c2d774c
GS
2345 atomic_set(&cm_core->events_posted, 0);
2346
3c2d774c
GS
2347 cm_core->api = &nes_cm_api;
2348
2349 spin_lock_init(&cm_core->ht_lock);
2350 spin_lock_init(&cm_core->listen_list_lock);
2351
2352 INIT_LIST_HEAD(&cm_core->listen_list.list);
2353
2354 nes_debug(NES_DBG_CM, "Init CM Core completed -- cm_core=%p\n", cm_core);
2355
2356 nes_debug(NES_DBG_CM, "Enable QUEUE EVENTS\n");
2357 cm_core->event_wq = create_singlethread_workqueue("nesewq");
2358 cm_core->post_event = nes_cm_post_event;
2359 nes_debug(NES_DBG_CM, "Enable QUEUE DISCONNECTS\n");
2360 cm_core->disconn_wq = create_singlethread_workqueue("nesdwq");
2361
2362 print_core(cm_core);
2363 return cm_core;
2364}
2365
2366
2367/**
2368 * mini_cm_dealloc_core - deallocate a top level instance of a cm core
2369 */
1a855fbf 2370static int mini_cm_dealloc_core(struct nes_cm_core *cm_core)
3c2d774c
GS
2371{
2372 nes_debug(NES_DBG_CM, "De-Alloc CM Core (%p)\n", cm_core);
2373
2374 if (!cm_core)
2375 return -EINVAL;
2376
2377 barrier();
2378
2379 if (timer_pending(&cm_core->tcp_timer)) {
2380 del_timer(&cm_core->tcp_timer);
2381 }
2382
2383 destroy_workqueue(cm_core->event_wq);
2384 destroy_workqueue(cm_core->disconn_wq);
2385 nes_debug(NES_DBG_CM, "\n");
2386 kfree(cm_core);
2387
2388 return 0;
2389}
2390
2391
2392/**
2393 * mini_cm_get
2394 */
1a855fbf 2395static int mini_cm_get(struct nes_cm_core *cm_core)
3c2d774c
GS
2396{
2397 return cm_core->state;
2398}
2399
2400
2401/**
2402 * mini_cm_set
2403 */
1a855fbf 2404static int mini_cm_set(struct nes_cm_core *cm_core, u32 type, u32 value)
3c2d774c
GS
2405{
2406 int ret = 0;
2407
2408 switch (type) {
9d5ab133
FL
2409 case NES_CM_SET_PKT_SIZE:
2410 cm_core->mtu = value;
2411 break;
2412 case NES_CM_SET_FREE_PKT_Q_SIZE:
2413 cm_core->free_tx_pkt_max = value;
2414 break;
2415 default:
2416 /* unknown set option */
2417 ret = -EINVAL;
3c2d774c
GS
2418 }
2419
2420 return ret;
2421}
2422
2423
2424/**
2425 * nes_cm_init_tsa_conn setup HW; MPA frames must be
2426 * successfully exchanged when this is called
2427 */
2428static int nes_cm_init_tsa_conn(struct nes_qp *nesqp, struct nes_cm_node *cm_node)
2429{
2430 int ret = 0;
2431
2432 if (!nesqp)
2433 return -EINVAL;
2434
2435 nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4 |
2436 NES_QPCONTEXT_MISC_NO_NAGLE | NES_QPCONTEXT_MISC_DO_NOT_FRAG |
2437 NES_QPCONTEXT_MISC_DROS);
2438
2439 if (cm_node->tcp_cntxt.snd_wscale || cm_node->tcp_cntxt.rcv_wscale)
2440 nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE);
2441
2442 nesqp->nesqp_context->misc2 |= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT);
2443
2444 nesqp->nesqp_context->mss |= cpu_to_le32(((u32)cm_node->tcp_cntxt.mss) << 16);
2445
2446 nesqp->nesqp_context->tcp_state_flow_label |= cpu_to_le32(
2447 (u32)NES_QPCONTEXT_TCPSTATE_EST << NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT);
2448
2449 nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
2450 (cm_node->tcp_cntxt.snd_wscale << NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT) &
2451 NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK);
2452
2453 nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
2454 (cm_node->tcp_cntxt.rcv_wscale << NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT) &
2455 NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK);
2456
2457 nesqp->nesqp_context->keepalive = cpu_to_le32(0x80);
2458 nesqp->nesqp_context->ts_recent = 0;
2459 nesqp->nesqp_context->ts_age = 0;
2460 nesqp->nesqp_context->snd_nxt = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2461 nesqp->nesqp_context->snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.snd_wnd);
2462 nesqp->nesqp_context->rcv_nxt = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
2463 nesqp->nesqp_context->rcv_wnd = cpu_to_le32(cm_node->tcp_cntxt.rcv_wnd <<
2464 cm_node->tcp_cntxt.rcv_wscale);
2465 nesqp->nesqp_context->snd_max = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2466 nesqp->nesqp_context->snd_una = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2467 nesqp->nesqp_context->srtt = 0;
2468 nesqp->nesqp_context->rttvar = cpu_to_le32(0x6);
2469 nesqp->nesqp_context->ssthresh = cpu_to_le32(0x3FFFC000);
2470 nesqp->nesqp_context->cwnd = cpu_to_le32(2*cm_node->tcp_cntxt.mss);
2471 nesqp->nesqp_context->snd_wl1 = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
2472 nesqp->nesqp_context->snd_wl2 = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2473 nesqp->nesqp_context->max_snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.max_snd_wnd);
2474
2475 nes_debug(NES_DBG_CM, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
2476 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
2477 nesqp->hwqp.qp_id, le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
2478 le32_to_cpu(nesqp->nesqp_context->snd_nxt),
2479 cm_node->tcp_cntxt.mss, le32_to_cpu(nesqp->nesqp_context->pd_index_wscale),
2480 le32_to_cpu(nesqp->nesqp_context->rcv_wnd),
2481 le32_to_cpu(nesqp->nesqp_context->misc));
2482 nes_debug(NES_DBG_CM, " snd_wnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->snd_wnd));
2483 nes_debug(NES_DBG_CM, " snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->cwnd));
2484 nes_debug(NES_DBG_CM, " max_swnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->max_snd_wnd));
2485
2486 nes_debug(NES_DBG_CM, "Change cm_node state to TSA\n");
2487 cm_node->state = NES_CM_STATE_TSA;
2488
2489 return ret;
2490}
2491
2492
2493/**
2494 * nes_cm_disconn
2495 */
2496int nes_cm_disconn(struct nes_qp *nesqp)
2497{
873fcdd4 2498 struct disconn_work *work;
3c2d774c 2499
873fcdd4
DW
2500 work = kzalloc(sizeof *work, GFP_ATOMIC);
2501 if (!work)
2502 return -ENOMEM; /* Timer will clean up */
3c2d774c 2503
873fcdd4
DW
2504 nes_add_ref(&nesqp->ibqp);
2505 work->nesqp = nesqp;
2506 INIT_WORK(&work->work, nes_disconnect_worker);
2507 queue_work(g_cm_core->disconn_wq, &work->work);
3c2d774c
GS
2508 return 0;
2509}
2510
2511
2512/**
2513 * nes_disconnect_worker
2514 */
1a855fbf 2515static void nes_disconnect_worker(struct work_struct *work)
3c2d774c 2516{
873fcdd4
DW
2517 struct disconn_work *dwork = container_of(work, struct disconn_work, work);
2518 struct nes_qp *nesqp = dwork->nesqp;
3c2d774c 2519
873fcdd4 2520 kfree(dwork);
3c2d774c
GS
2521 nes_debug(NES_DBG_CM, "processing AEQE id 0x%04X for QP%u.\n",
2522 nesqp->last_aeq, nesqp->hwqp.qp_id);
2523 nes_cm_disconn_true(nesqp);
c4c3f279 2524 nes_rem_ref(&nesqp->ibqp);
3c2d774c
GS
2525}
2526
2527
2528/**
2529 * nes_cm_disconn_true
2530 */
1a855fbf 2531static int nes_cm_disconn_true(struct nes_qp *nesqp)
3c2d774c
GS
2532{
2533 unsigned long flags;
2534 int ret = 0;
2535 struct iw_cm_id *cm_id;
2536 struct iw_cm_event cm_event;
2537 struct nes_vnic *nesvnic;
2538 u16 last_ae;
2539 u8 original_hw_tcp_state;
2540 u8 original_ibqp_state;
b29a4fc4
DW
2541 enum iw_cm_event_type disconn_status = IW_CM_EVENT_STATUS_OK;
2542 int issue_disconn = 0;
2543 int issue_close = 0;
2544 int issue_flush = 0;
2545 u32 flush_q = NES_CQP_FLUSH_RQ;
2546 struct ib_event ibevent;
3c2d774c
GS
2547
2548 if (!nesqp) {
2549 nes_debug(NES_DBG_CM, "disconnect_worker nesqp is NULL\n");
2550 return -1;
2551 }
2552
2553 spin_lock_irqsave(&nesqp->lock, flags);
2554 cm_id = nesqp->cm_id;
2555 /* make sure we havent already closed this connection */
2556 if (!cm_id) {
2557 nes_debug(NES_DBG_CM, "QP%u disconnect_worker cmid is NULL\n",
2558 nesqp->hwqp.qp_id);
2559 spin_unlock_irqrestore(&nesqp->lock, flags);
3c2d774c
GS
2560 return -1;
2561 }
2562
2563 nesvnic = to_nesvnic(nesqp->ibqp.device);
2564 nes_debug(NES_DBG_CM, "Disconnecting QP%u\n", nesqp->hwqp.qp_id);
2565
2566 original_hw_tcp_state = nesqp->hw_tcp_state;
2567 original_ibqp_state = nesqp->ibqp_state;
2568 last_ae = nesqp->last_aeq;
2569
b29a4fc4
DW
2570 if (nesqp->term_flags) {
2571 issue_disconn = 1;
2572 issue_close = 1;
2573 nesqp->cm_id = NULL;
2574 if (nesqp->flush_issued == 0) {
2575 nesqp->flush_issued = 1;
2576 issue_flush = 1;
2577 }
2578 } else if ((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2579 ((original_ibqp_state == IB_QPS_RTS) &&
2580 (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2581 issue_disconn = 1;
2582 if (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET)
2583 disconn_status = IW_CM_EVENT_STATUS_RESET;
2584 }
2585
2586 if (((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
2587 (original_hw_tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT) ||
2588 (last_ae == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) ||
2589 (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2590 issue_close = 1;
2591 nesqp->cm_id = NULL;
2592 if (nesqp->flush_issued == 0) {
2593 nesqp->flush_issued = 1;
2594 issue_flush = 1;
2595 }
2596 }
3c2d774c 2597
b29a4fc4
DW
2598 spin_unlock_irqrestore(&nesqp->lock, flags);
2599
2600 if ((issue_flush) && (nesqp->destroyed == 0)) {
2601 /* Flush the queue(s) */
2602 if (nesqp->hw_iwarp_state >= NES_AEQE_IWARP_STATE_TERMINATE)
2603 flush_q |= NES_CQP_FLUSH_SQ;
2604 flush_wqes(nesvnic->nesdev, nesqp, flush_q, 1);
2605
2606 if (nesqp->term_flags) {
2607 ibevent.device = nesqp->ibqp.device;
2608 ibevent.event = nesqp->terminate_eventtype;
2609 ibevent.element.qp = &nesqp->ibqp;
2610 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2611 }
2612 }
3c2d774c 2613
b29a4fc4
DW
2614 if ((cm_id) && (cm_id->event_handler)) {
2615 if (issue_disconn) {
3c2d774c
GS
2616 atomic_inc(&cm_disconnects);
2617 cm_event.event = IW_CM_EVENT_DISCONNECT;
b29a4fc4 2618 cm_event.status = disconn_status;
3c2d774c
GS
2619 cm_event.local_addr = cm_id->local_addr;
2620 cm_event.remote_addr = cm_id->remote_addr;
2621 cm_event.private_data = NULL;
2622 cm_event.private_data_len = 0;
2623
6492cdf3
FL
2624 nes_debug(NES_DBG_CM, "Generating a CM Disconnect Event"
2625 " for QP%u, SQ Head = %u, SQ Tail = %u. "
2626 "cm_id = %p, refcount = %u.\n",
2627 nesqp->hwqp.qp_id, nesqp->hwqp.sq_head,
2628 nesqp->hwqp.sq_tail, cm_id,
2629 atomic_read(&nesqp->refcount));
3c2d774c 2630
3c2d774c
GS
2631 ret = cm_id->event_handler(cm_id, &cm_event);
2632 if (ret)
6492cdf3
FL
2633 nes_debug(NES_DBG_CM, "OFA CM event_handler "
2634 "returned, ret=%d\n", ret);
3c2d774c
GS
2635 }
2636
b29a4fc4 2637 if (issue_close) {
3c2d774c 2638 atomic_inc(&cm_closes);
3c2d774c
GS
2639 nes_disconnect(nesqp, 1);
2640
2641 cm_id->provider_data = nesqp;
2642 /* Send up the close complete event */
2643 cm_event.event = IW_CM_EVENT_CLOSE;
2644 cm_event.status = IW_CM_EVENT_STATUS_OK;
2645 cm_event.provider_data = cm_id->provider_data;
2646 cm_event.local_addr = cm_id->local_addr;
2647 cm_event.remote_addr = cm_id->remote_addr;
2648 cm_event.private_data = NULL;
2649 cm_event.private_data_len = 0;
2650
2651 ret = cm_id->event_handler(cm_id, &cm_event);
2652 if (ret) {
2653 nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
2654 }
2655
2656 cm_id->rem_ref(cm_id);
3c2d774c 2657 }
3c2d774c 2658 }
3c2d774c
GS
2659
2660 return 0;
2661}
2662
2663
2664/**
2665 * nes_disconnect
2666 */
1a855fbf 2667static int nes_disconnect(struct nes_qp *nesqp, int abrupt)
3c2d774c
GS
2668{
2669 int ret = 0;
2670 struct nes_vnic *nesvnic;
2671 struct nes_device *nesdev;
c12e56ef 2672 struct nes_ib_device *nesibdev;
3c2d774c
GS
2673
2674 nesvnic = to_nesvnic(nesqp->ibqp.device);
2675 if (!nesvnic)
2676 return -EINVAL;
2677
2678 nesdev = nesvnic->nesdev;
c12e56ef 2679 nesibdev = nesvnic->nesibdev;
3c2d774c
GS
2680
2681 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
2682 atomic_read(&nesvnic->netdev->refcnt));
2683
2684 if (nesqp->active_conn) {
2685
2686 /* indicate this connection is NOT active */
2687 nesqp->active_conn = 0;
2688 } else {
2689 /* Need to free the Last Streaming Mode Message */
2690 if (nesqp->ietf_frame) {
c12e56ef
FL
2691 if (nesqp->lsmm_mr)
2692 nesibdev->ibdev.dereg_mr(nesqp->lsmm_mr);
3c2d774c
GS
2693 pci_free_consistent(nesdev->pcidev,
2694 nesqp->private_data_len+sizeof(struct ietf_mpa_frame),
2695 nesqp->ietf_frame, nesqp->ietf_frame_pbase);
2696 }
2697 }
2698
2699 /* close the CM node down if it is still active */
2700 if (nesqp->cm_node) {
2701 nes_debug(NES_DBG_CM, "Call close API\n");
2702
2703 g_cm_core->api->close(g_cm_core, nesqp->cm_node);
3c2d774c
GS
2704 }
2705
2706 return ret;
2707}
2708
2709
2710/**
2711 * nes_accept
2712 */
2713int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2714{
2715 u64 u64temp;
2716 struct ib_qp *ibqp;
2717 struct nes_qp *nesqp;
2718 struct nes_vnic *nesvnic;
2719 struct nes_device *nesdev;
2720 struct nes_cm_node *cm_node;
2721 struct nes_adapter *adapter;
2722 struct ib_qp_attr attr;
2723 struct iw_cm_event cm_event;
2724 struct nes_hw_qp_wqe *wqe;
2725 struct nes_v4_quad nes_quad;
30da7cff 2726 u32 crc_value;
3c2d774c 2727 int ret;
183ecfa3 2728 int passive_state;
c12e56ef
FL
2729 struct nes_ib_device *nesibdev;
2730 struct ib_mr *ibmr = NULL;
2731 struct ib_phys_buf ibphysbuf;
2732 struct nes_pd *nespd;
7a5efb62 2733 u64 tagged_offset;
c12e56ef 2734
3c2d774c
GS
2735 ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
2736 if (!ibqp)
2737 return -EINVAL;
2738
2739 /* get all our handles */
2740 nesqp = to_nesqp(ibqp);
2741 nesvnic = to_nesvnic(nesqp->ibqp.device);
2742 nesdev = nesvnic->nesdev;
2743 adapter = nesdev->nesadapter;
2744
3c2d774c 2745 cm_node = (struct nes_cm_node *)cm_id->provider_data;
6492cdf3
FL
2746 nes_debug(NES_DBG_CM, "nes_accept: cm_node= %p nesvnic=%p, netdev=%p,"
2747 "%s\n", cm_node, nesvnic, nesvnic->netdev,
2748 nesvnic->netdev->name);
3c2d774c 2749
c5a7d489
FL
2750 if (NES_CM_STATE_LISTENER_DESTROYED == cm_node->state) {
2751 if (cm_node->loopbackpartner)
2752 rem_ref_cm_node(cm_node->cm_core, cm_node->loopbackpartner);
2753 rem_ref_cm_node(cm_node->cm_core, cm_node);
2754 return -EINVAL;
2755 }
2756
3c2d774c
GS
2757 /* associate the node with the QP */
2758 nesqp->cm_node = (void *)cm_node;
6492cdf3 2759 cm_node->nesqp = nesqp;
3c2d774c 2760
6492cdf3
FL
2761 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
2762 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
3c2d774c
GS
2763 atomic_inc(&cm_accepts);
2764
2765 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
2766 atomic_read(&nesvnic->netdev->refcnt));
2767
6492cdf3
FL
2768 /* allocate the ietf frame and space for private data */
2769 nesqp->ietf_frame = pci_alloc_consistent(nesdev->pcidev,
2770 sizeof(struct ietf_mpa_frame) + conn_param->private_data_len,
2771 &nesqp->ietf_frame_pbase);
3c2d774c 2772
6492cdf3
FL
2773 if (!nesqp->ietf_frame) {
2774 nes_debug(NES_DBG_CM, "Unable to allocate memory for private "
2775 "data\n");
2776 return -ENOMEM;
2777 }
3c2d774c 2778
3c2d774c 2779
6492cdf3
FL
2780 /* setup the MPA frame */
2781 nesqp->private_data_len = conn_param->private_data_len;
2782 memcpy(nesqp->ietf_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
3c2d774c 2783
6492cdf3
FL
2784 memcpy(nesqp->ietf_frame->priv_data, conn_param->private_data,
2785 conn_param->private_data_len);
3c2d774c 2786
6492cdf3
FL
2787 nesqp->ietf_frame->priv_data_len =
2788 cpu_to_be16(conn_param->private_data_len);
2789 nesqp->ietf_frame->rev = mpa_version;
2790 nesqp->ietf_frame->flags = IETF_MPA_FLAGS_CRC;
3c2d774c 2791
6492cdf3
FL
2792 /* setup our first outgoing iWarp send WQE (the IETF frame response) */
2793 wqe = &nesqp->hwqp.sq_vbase[0];
2794
2795 if (cm_id->remote_addr.sin_addr.s_addr !=
2796 cm_id->local_addr.sin_addr.s_addr) {
2797 u64temp = (unsigned long)nesqp;
c12e56ef
FL
2798 nesibdev = nesvnic->nesibdev;
2799 nespd = nesqp->nespd;
2800 ibphysbuf.addr = nesqp->ietf_frame_pbase;
2801 ibphysbuf.size = conn_param->private_data_len +
2802 sizeof(struct ietf_mpa_frame);
7a5efb62 2803 tagged_offset = (u64)(unsigned long)nesqp->ietf_frame;
c12e56ef
FL
2804 ibmr = nesibdev->ibdev.reg_phys_mr((struct ib_pd *)nespd,
2805 &ibphysbuf, 1,
2806 IB_ACCESS_LOCAL_WRITE,
7a5efb62 2807 &tagged_offset);
c12e56ef
FL
2808 if (!ibmr) {
2809 nes_debug(NES_DBG_CM, "Unable to register memory region"
2810 "for lSMM for cm_node = %p \n",
2811 cm_node);
9256b251
FL
2812 pci_free_consistent(nesdev->pcidev,
2813 nesqp->private_data_len+sizeof(struct ietf_mpa_frame),
2814 nesqp->ietf_frame, nesqp->ietf_frame_pbase);
c12e56ef
FL
2815 return -ENOMEM;
2816 }
2817
2818 ibmr->pd = &nespd->ibpd;
2819 ibmr->device = nespd->ibpd.device;
2820 nesqp->lsmm_mr = ibmr;
2821
6492cdf3
FL
2822 u64temp |= NES_SW_CONTEXT_ALIGN>>1;
2823 set_wqe_64bit_value(wqe->wqe_words,
2824 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX,
2825 u64temp);
2826 wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
2827 cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING |
2828 NES_IWARP_SQ_WQE_WRPDU);
2829 wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] =
2830 cpu_to_le32(conn_param->private_data_len +
2831 sizeof(struct ietf_mpa_frame));
c12e56ef
FL
2832 set_wqe_64bit_value(wqe->wqe_words,
2833 NES_IWARP_SQ_WQE_FRAG0_LOW_IDX,
7a5efb62 2834 (u64)(unsigned long)nesqp->ietf_frame);
6492cdf3
FL
2835 wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] =
2836 cpu_to_le32(conn_param->private_data_len +
2837 sizeof(struct ietf_mpa_frame));
c12e56ef 2838 wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = ibmr->lkey;
6492cdf3
FL
2839
2840 nesqp->nesqp_context->ird_ord_sizes |=
2841 cpu_to_le32(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
2842 NES_QPCONTEXT_ORDIRD_WRPDU);
2843 } else {
2844 nesqp->nesqp_context->ird_ord_sizes |=
9d5ab133 2845 cpu_to_le32(NES_QPCONTEXT_ORDIRD_WRPDU);
6492cdf3
FL
2846 }
2847 nesqp->skip_lsmm = 1;
3c2d774c
GS
2848
2849
2850 /* Cache the cm_id in the qp */
2851 nesqp->cm_id = cm_id;
2852 cm_node->cm_id = cm_id;
2853
2854 /* nesqp->cm_node = (void *)cm_id->provider_data; */
2855 cm_id->provider_data = nesqp;
2856 nesqp->active_conn = 0;
2857
6492cdf3
FL
2858 if (cm_node->state == NES_CM_STATE_TSA)
2859 nes_debug(NES_DBG_CM, "Already state = TSA for cm_node=%p\n",
2860 cm_node);
2861
3c2d774c
GS
2862 nes_cm_init_tsa_conn(nesqp, cm_node);
2863
6492cdf3
FL
2864 nesqp->nesqp_context->tcpPorts[0] =
2865 cpu_to_le16(ntohs(cm_id->local_addr.sin_port));
2866 nesqp->nesqp_context->tcpPorts[1] =
2867 cpu_to_le16(ntohs(cm_id->remote_addr.sin_port));
2868
2869 if (ipv4_is_loopback(cm_id->remote_addr.sin_addr.s_addr))
2870 nesqp->nesqp_context->ip0 =
2871 cpu_to_le32(ntohl(nesvnic->local_ipaddr));
2872 else
2873 nesqp->nesqp_context->ip0 =
2874 cpu_to_le32(ntohl(cm_id->remote_addr.sin_addr.s_addr));
3c2d774c
GS
2875
2876 nesqp->nesqp_context->misc2 |= cpu_to_le32(
6492cdf3
FL
2877 (u32)PCI_FUNC(nesdev->pcidev->devfn) <<
2878 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
3c2d774c 2879
6492cdf3
FL
2880 nesqp->nesqp_context->arp_index_vlan |=
2881 cpu_to_le32(nes_arp_table(nesdev,
2882 le32_to_cpu(nesqp->nesqp_context->ip0), NULL,
3c2d774c
GS
2883 NES_ARP_RESOLVE) << 16);
2884
2885 nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
6492cdf3 2886 jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
3c2d774c
GS
2887
2888 nesqp->nesqp_context->ird_index = cpu_to_le32(nesqp->hwqp.qp_id);
2889
2890 nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32(
6492cdf3
FL
2891 ((u32)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT));
2892 nesqp->nesqp_context->ird_ord_sizes |=
2893 cpu_to_le32((u32)conn_param->ord);
3c2d774c
GS
2894
2895 memset(&nes_quad, 0, sizeof(nes_quad));
6492cdf3
FL
2896 nes_quad.DstIpAdrIndex =
2897 cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
2898 if (ipv4_is_loopback(cm_id->remote_addr.sin_addr.s_addr))
2899 nes_quad.SrcIpadr = nesvnic->local_ipaddr;
2900 else
2901 nes_quad.SrcIpadr = cm_id->remote_addr.sin_addr.s_addr;
2902 nes_quad.TcpPorts[0] = cm_id->remote_addr.sin_port;
2903 nes_quad.TcpPorts[1] = cm_id->local_addr.sin_port;
3c2d774c
GS
2904
2905 /* Produce hash key */
30da7cff
FL
2906 crc_value = get_crc_value(&nes_quad);
2907 nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
3c2d774c 2908 nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, CRC = 0x%08X\n",
6492cdf3 2909 nesqp->hte_index, nesqp->hte_index & adapter->hte_index_mask);
3c2d774c
GS
2910
2911 nesqp->hte_index &= adapter->hte_index_mask;
2912 nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
2913
2914 cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
2915
6492cdf3
FL
2916 nes_debug(NES_DBG_CM, "QP%u, Destination IP = 0x%08X:0x%04X, local = "
2917 "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
2918 "private data length=%zu.\n", nesqp->hwqp.qp_id,
3c2d774c
GS
2919 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2920 ntohs(cm_id->remote_addr.sin_port),
2921 ntohl(cm_id->local_addr.sin_addr.s_addr),
2922 ntohs(cm_id->local_addr.sin_port),
2923 le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
2924 le32_to_cpu(nesqp->nesqp_context->snd_nxt),
6492cdf3
FL
2925 conn_param->private_data_len +
2926 sizeof(struct ietf_mpa_frame));
3c2d774c 2927
3c2d774c 2928
73ac36ea 2929 /* notify OF layer that accept event was successful */
3c2d774c 2930 cm_id->add_ref(cm_id);
9256b251 2931 nes_add_ref(&nesqp->ibqp);
3c2d774c
GS
2932
2933 cm_event.event = IW_CM_EVENT_ESTABLISHED;
2934 cm_event.status = IW_CM_EVENT_STATUS_ACCEPTED;
2935 cm_event.provider_data = (void *)nesqp;
2936 cm_event.local_addr = cm_id->local_addr;
2937 cm_event.remote_addr = cm_id->remote_addr;
2938 cm_event.private_data = NULL;
2939 cm_event.private_data_len = 0;
2940 ret = cm_id->event_handler(cm_id, &cm_event);
183ecfa3
FL
2941 attr.qp_state = IB_QPS_RTS;
2942 nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
3c2d774c 2943 if (cm_node->loopbackpartner) {
6492cdf3
FL
2944 cm_node->loopbackpartner->mpa_frame_size =
2945 nesqp->private_data_len;
3c2d774c 2946 /* copy entire MPA frame to our cm_node's frame */
6492cdf3
FL
2947 memcpy(cm_node->loopbackpartner->mpa_frame_buf,
2948 nesqp->ietf_frame->priv_data, nesqp->private_data_len);
3c2d774c
GS
2949 create_event(cm_node->loopbackpartner, NES_CM_EVENT_CONNECTED);
2950 }
2951 if (ret)
6492cdf3
FL
2952 printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
2953 "ret=%d\n", __func__, __LINE__, ret);
3c2d774c 2954
183ecfa3
FL
2955 passive_state = atomic_add_return(1, &cm_node->passive_state);
2956 if (passive_state == NES_SEND_RESET_EVENT)
2957 create_event(cm_node, NES_CM_EVENT_RESET);
3c2d774c
GS
2958 return 0;
2959}
2960
2961
2962/**
2963 * nes_reject
2964 */
2965int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2966{
2967 struct nes_cm_node *cm_node;
9d5ab133
FL
2968 struct nes_cm_node *loopback;
2969
3c2d774c
GS
2970 struct nes_cm_core *cm_core;
2971
2972 atomic_inc(&cm_rejects);
2973 cm_node = (struct nes_cm_node *) cm_id->provider_data;
9d5ab133 2974 loopback = cm_node->loopbackpartner;
3c2d774c 2975 cm_core = cm_node->cm_core;
9d5ab133 2976 cm_node->cm_id = cm_id;
3c2d774c
GS
2977 cm_node->mpa_frame_size = sizeof(struct ietf_mpa_frame) + pdata_len;
2978
9d5ab133
FL
2979 if (cm_node->mpa_frame_size > MAX_CM_BUFFER)
2980 return -EINVAL;
2981
1cf078c9 2982 memcpy(&cm_node->mpa_frame.key[0], IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
9d5ab133
FL
2983 if (loopback) {
2984 memcpy(&loopback->mpa_frame.priv_data, pdata, pdata_len);
2985 loopback->mpa_frame.priv_data_len = pdata_len;
2986 loopback->mpa_frame_size = sizeof(struct ietf_mpa_frame) +
2987 pdata_len;
2988 } else {
2989 memcpy(&cm_node->mpa_frame.priv_data, pdata, pdata_len);
2990 cm_node->mpa_frame.priv_data_len = cpu_to_be16(pdata_len);
2991 }
3c2d774c 2992
3c2d774c
GS
2993 cm_node->mpa_frame.rev = mpa_version;
2994 cm_node->mpa_frame.flags = IETF_MPA_FLAGS_CRC | IETF_MPA_FLAGS_REJECT;
2995
9d5ab133 2996 return cm_core->api->reject(cm_core, &cm_node->mpa_frame, cm_node);
3c2d774c
GS
2997}
2998
2999
3000/**
3001 * nes_connect
3002 * setup and launch cm connect node
3003 */
3004int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3005{
3006 struct ib_qp *ibqp;
3007 struct nes_qp *nesqp;
3008 struct nes_vnic *nesvnic;
3009 struct nes_device *nesdev;
3010 struct nes_cm_node *cm_node;
3011 struct nes_cm_info cm_info;
53094c38 3012 int apbvt_set = 0;
3c2d774c
GS
3013
3014 ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
3015 if (!ibqp)
3016 return -EINVAL;
3017 nesqp = to_nesqp(ibqp);
3018 if (!nesqp)
3019 return -EINVAL;
3020 nesvnic = to_nesvnic(nesqp->ibqp.device);
3021 if (!nesvnic)
3022 return -EINVAL;
3023 nesdev = nesvnic->nesdev;
3024 if (!nesdev)
3025 return -EINVAL;
3026
c5a7d489
FL
3027 if (!(cm_id->local_addr.sin_port) || !(cm_id->remote_addr.sin_port))
3028 return -EINVAL;
3029
6492cdf3
FL
3030 nes_debug(NES_DBG_CM, "QP%u, current IP = 0x%08X, Destination IP = "
3031 "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp->hwqp.qp_id,
3032 ntohl(nesvnic->local_ipaddr),
3033 ntohl(cm_id->remote_addr.sin_addr.s_addr),
3034 ntohs(cm_id->remote_addr.sin_port),
3035 ntohl(cm_id->local_addr.sin_addr.s_addr),
3036 ntohs(cm_id->local_addr.sin_port));
3c2d774c 3037
6492cdf3 3038 atomic_inc(&cm_connects);
3c2d774c
GS
3039 nesqp->active_conn = 1;
3040
3c2d774c
GS
3041 /* cache the cm_id in the qp */
3042 nesqp->cm_id = cm_id;
3043
3044 cm_id->provider_data = nesqp;
3045
3c2d774c
GS
3046 nesqp->private_data_len = conn_param->private_data_len;
3047 nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32((u32)conn_param->ord);
3048 nes_debug(NES_DBG_CM, "requested ord = 0x%08X.\n", (u32)conn_param->ord);
6492cdf3
FL
3049 nes_debug(NES_DBG_CM, "mpa private data len =%u\n",
3050 conn_param->private_data_len);
3c2d774c 3051
6492cdf3 3052 if (cm_id->local_addr.sin_addr.s_addr !=
53094c38 3053 cm_id->remote_addr.sin_addr.s_addr) {
3c2d774c 3054 nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
6492cdf3 3055 PCI_FUNC(nesdev->pcidev->devfn), NES_MANAGE_APBVT_ADD);
53094c38
FL
3056 apbvt_set = 1;
3057 }
3c2d774c
GS
3058
3059 /* set up the connection params for the node */
6492cdf3
FL
3060 cm_info.loc_addr = htonl(cm_id->local_addr.sin_addr.s_addr);
3061 cm_info.loc_port = htons(cm_id->local_addr.sin_port);
3062 cm_info.rem_addr = htonl(cm_id->remote_addr.sin_addr.s_addr);
3063 cm_info.rem_port = htons(cm_id->remote_addr.sin_port);
3c2d774c
GS
3064 cm_info.cm_id = cm_id;
3065 cm_info.conn_type = NES_CM_IWARP_CONN_TYPE;
3066
3067 cm_id->add_ref(cm_id);
3c2d774c
GS
3068
3069 /* create a connect CM node connection */
6492cdf3
FL
3070 cm_node = g_cm_core->api->connect(g_cm_core, nesvnic,
3071 conn_param->private_data_len, (void *)conn_param->private_data,
3072 &cm_info);
3c2d774c 3073 if (!cm_node) {
53094c38 3074 if (apbvt_set)
3c2d774c 3075 nes_manage_apbvt(nesvnic, ntohs(cm_id->local_addr.sin_port),
6492cdf3
FL
3076 PCI_FUNC(nesdev->pcidev->devfn),
3077 NES_MANAGE_APBVT_DEL);
3078
3c2d774c
GS
3079 cm_id->rem_ref(cm_id);
3080 return -ENOMEM;
3081 }
3082
53094c38 3083 cm_node->apbvt_set = apbvt_set;
3c2d774c 3084 nesqp->cm_node = cm_node;
6492cdf3 3085 cm_node->nesqp = nesqp;
d7ffd507 3086 nes_add_ref(&nesqp->ibqp);
3c2d774c
GS
3087
3088 return 0;
3089}
3090
3091
3092/**
3093 * nes_create_listen
3094 */
3095int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
3096{
3097 struct nes_vnic *nesvnic;
3098 struct nes_cm_listener *cm_node;
3099 struct nes_cm_info cm_info;
3100 struct nes_adapter *adapter;
3101 int err;
3102
3103
3104 nes_debug(NES_DBG_CM, "cm_id = %p, local port = 0x%04X.\n",
3105 cm_id, ntohs(cm_id->local_addr.sin_port));
3106
3107 nesvnic = to_nesvnic(cm_id->device);
3108 if (!nesvnic)
3109 return -EINVAL;
3110 adapter = nesvnic->nesdev->nesadapter;
3111 nes_debug(NES_DBG_CM, "nesvnic=%p, netdev=%p, %s\n",
3112 nesvnic, nesvnic->netdev, nesvnic->netdev->name);
3113
3114 nes_debug(NES_DBG_CM, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
3115 nesvnic->local_ipaddr, cm_id->local_addr.sin_addr.s_addr);
3116
3117 /* setup listen params in our api call struct */
3118 cm_info.loc_addr = nesvnic->local_ipaddr;
3119 cm_info.loc_port = cm_id->local_addr.sin_port;
3120 cm_info.backlog = backlog;
3121 cm_info.cm_id = cm_id;
3122
3123 cm_info.conn_type = NES_CM_IWARP_CONN_TYPE;
3124
3125
3126 cm_node = g_cm_core->api->listen(g_cm_core, nesvnic, &cm_info);
3127 if (!cm_node) {
6492cdf3 3128 printk(KERN_ERR "%s[%u] Error returned from listen API call\n",
33718363 3129 __func__, __LINE__);
3c2d774c
GS
3130 return -ENOMEM;
3131 }
3132
3133 cm_id->provider_data = cm_node;
3134
3135 if (!cm_node->reused_node) {
6492cdf3
FL
3136 err = nes_manage_apbvt(nesvnic,
3137 ntohs(cm_id->local_addr.sin_port),
3138 PCI_FUNC(nesvnic->nesdev->pcidev->devfn),
3139 NES_MANAGE_APBVT_ADD);
3c2d774c 3140 if (err) {
6492cdf3
FL
3141 printk(KERN_ERR "nes_manage_apbvt call returned %d.\n",
3142 err);
3c2d774c
GS
3143 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
3144 return err;
3145 }
3146 cm_listens_created++;
3147 }
3148
3149 cm_id->add_ref(cm_id);
3150 cm_id->provider_data = (void *)cm_node;
3151
3152
3153 return 0;
3154}
3155
3156
3157/**
3158 * nes_destroy_listen
3159 */
3160int nes_destroy_listen(struct iw_cm_id *cm_id)
3161{
3162 if (cm_id->provider_data)
3163 g_cm_core->api->stop_listener(g_cm_core, cm_id->provider_data);
3164 else
3165 nes_debug(NES_DBG_CM, "cm_id->provider_data was NULL\n");
3166
3167 cm_id->rem_ref(cm_id);
3168
3169 return 0;
3170}
3171
3172
3173/**
3174 * nes_cm_recv
3175 */
3176int nes_cm_recv(struct sk_buff *skb, struct net_device *netdevice)
3177{
4a14f6a7 3178 int rc = 0;
3c2d774c
GS
3179 cm_packets_received++;
3180 if ((g_cm_core) && (g_cm_core->api)) {
4a14f6a7 3181 rc = g_cm_core->api->recv_pkt(g_cm_core, netdev_priv(netdevice), skb);
3c2d774c
GS
3182 } else {
3183 nes_debug(NES_DBG_CM, "Unable to process packet for CM,"
3184 " cm is not setup properly.\n");
3185 }
3186
4a14f6a7 3187 return rc;
3c2d774c
GS
3188}
3189
3190
3191/**
3192 * nes_cm_start
3193 * Start and init a cm core module
3194 */
3195int nes_cm_start(void)
3196{
3197 nes_debug(NES_DBG_CM, "\n");
3198 /* create the primary CM core, pass this handle to subsequent core inits */
3199 g_cm_core = nes_cm_alloc_core();
3200 if (g_cm_core) {
3201 return 0;
3202 } else {
3203 return -ENOMEM;
3204 }
3205}
3206
3207
3208/**
3209 * nes_cm_stop
3210 * stop and dealloc all cm core instances
3211 */
3212int nes_cm_stop(void)
3213{
3214 g_cm_core->api->destroy_cm_core(g_cm_core);
3215 return 0;
3216}
3217
3218
3219/**
3220 * cm_event_connected
3221 * handle a connected event, setup QPs and HW
3222 */
1a855fbf 3223static void cm_event_connected(struct nes_cm_event *event)
3c2d774c
GS
3224{
3225 u64 u64temp;
3226 struct nes_qp *nesqp;
3227 struct nes_vnic *nesvnic;
3228 struct nes_device *nesdev;
3229 struct nes_cm_node *cm_node;
3230 struct nes_adapter *nesadapter;
3231 struct ib_qp_attr attr;
3232 struct iw_cm_id *cm_id;
3233 struct iw_cm_event cm_event;
3234 struct nes_hw_qp_wqe *wqe;
3235 struct nes_v4_quad nes_quad;
30da7cff 3236 u32 crc_value;
3c2d774c
GS
3237 int ret;
3238
3239 /* get all our handles */
3240 cm_node = event->cm_node;
3241 cm_id = cm_node->cm_id;
3242 nes_debug(NES_DBG_CM, "cm_event_connected - %p - cm_id = %p\n", cm_node, cm_id);
3243 nesqp = (struct nes_qp *)cm_id->provider_data;
3244 nesvnic = to_nesvnic(nesqp->ibqp.device);
3245 nesdev = nesvnic->nesdev;
3246 nesadapter = nesdev->nesadapter;
3247
3248 if (nesqp->destroyed) {
3249 return;
3250 }
3251 atomic_inc(&cm_connecteds);
3252 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
3253 " local port 0x%04X. jiffies = %lu.\n",
3254 nesqp->hwqp.qp_id,
3255 ntohl(cm_id->remote_addr.sin_addr.s_addr),
3256 ntohs(cm_id->remote_addr.sin_port),
3257 ntohs(cm_id->local_addr.sin_port),
3258 jiffies);
3259
3260 nes_cm_init_tsa_conn(nesqp, cm_node);
3261
3262 /* set the QP tsa context */
6492cdf3
FL
3263 nesqp->nesqp_context->tcpPorts[0] =
3264 cpu_to_le16(ntohs(cm_id->local_addr.sin_port));
3265 nesqp->nesqp_context->tcpPorts[1] =
3266 cpu_to_le16(ntohs(cm_id->remote_addr.sin_port));
3267 if (ipv4_is_loopback(cm_id->remote_addr.sin_addr.s_addr))
3268 nesqp->nesqp_context->ip0 =
3269 cpu_to_le32(ntohl(nesvnic->local_ipaddr));
3270 else
3271 nesqp->nesqp_context->ip0 =
3272 cpu_to_le32(ntohl(cm_id->remote_addr.sin_addr.s_addr));
3c2d774c
GS
3273
3274 nesqp->nesqp_context->misc2 |= cpu_to_le32(
6492cdf3
FL
3275 (u32)PCI_FUNC(nesdev->pcidev->devfn) <<
3276 NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
3c2d774c 3277 nesqp->nesqp_context->arp_index_vlan |= cpu_to_le32(
6492cdf3
FL
3278 nes_arp_table(nesdev,
3279 le32_to_cpu(nesqp->nesqp_context->ip0),
3c2d774c
GS
3280 NULL, NES_ARP_RESOLVE) << 16);
3281 nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
3282 jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
3283 nesqp->nesqp_context->ird_index = cpu_to_le32(nesqp->hwqp.qp_id);
3284 nesqp->nesqp_context->ird_ord_sizes |=
6492cdf3
FL
3285 cpu_to_le32((u32)1 <<
3286 NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT);
3c2d774c
GS
3287
3288 /* Adjust tail for not having a LSMM */
3289 nesqp->hwqp.sq_tail = 1;
3290
3291#if defined(NES_SEND_FIRST_WRITE)
6492cdf3
FL
3292 if (cm_node->send_write0) {
3293 nes_debug(NES_DBG_CM, "Sending first write.\n");
3294 wqe = &nesqp->hwqp.sq_vbase[0];
3295 u64temp = (unsigned long)nesqp;
3296 u64temp |= NES_SW_CONTEXT_ALIGN>>1;
3297 set_wqe_64bit_value(wqe->wqe_words,
3298 NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX, u64temp);
3299 wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
3300 cpu_to_le32(NES_IWARP_SQ_OP_RDMAW);
3301 wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] = 0;
3302 wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX] = 0;
3303 wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX] = 0;
3304 wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] = 0;
3305 wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 0;
3306
3307 /* use the reserved spot on the WQ for the extra first WQE */
3308 nesqp->nesqp_context->ird_ord_sizes &=
3309 cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
3310 NES_QPCONTEXT_ORDIRD_WRPDU |
3311 NES_QPCONTEXT_ORDIRD_ALSMM));
3312 nesqp->skip_lsmm = 1;
3313 nesqp->hwqp.sq_tail = 0;
3314 nes_write32(nesdev->regs + NES_WQE_ALLOC,
3315 (1 << 24) | 0x00800000 | nesqp->hwqp.qp_id);
3316 }
3c2d774c
GS
3317#endif
3318
3319 memset(&nes_quad, 0, sizeof(nes_quad));
3320
6492cdf3
FL
3321 nes_quad.DstIpAdrIndex =
3322 cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
3323 if (ipv4_is_loopback(cm_id->remote_addr.sin_addr.s_addr))
3324 nes_quad.SrcIpadr = nesvnic->local_ipaddr;
3325 else
3326 nes_quad.SrcIpadr = cm_id->remote_addr.sin_addr.s_addr;
3c2d774c
GS
3327 nes_quad.TcpPorts[0] = cm_id->remote_addr.sin_port;
3328 nes_quad.TcpPorts[1] = cm_id->local_addr.sin_port;
3329
3330 /* Produce hash key */
30da7cff
FL
3331 crc_value = get_crc_value(&nes_quad);
3332 nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
3c2d774c
GS
3333 nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
3334 nesqp->hte_index, nesqp->hte_index & nesadapter->hte_index_mask);
3335
3336 nesqp->hte_index &= nesadapter->hte_index_mask;
3337 nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
3338
3339 nesqp->ietf_frame = &cm_node->mpa_frame;
3340 nesqp->private_data_len = (u8) cm_node->mpa_frame_size;
3341 cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
3342
3c2d774c
GS
3343 /* notify OF layer we successfully created the requested connection */
3344 cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
3345 cm_event.status = IW_CM_EVENT_STATUS_ACCEPTED;
3346 cm_event.provider_data = cm_id->provider_data;
3347 cm_event.local_addr.sin_family = AF_INET;
3348 cm_event.local_addr.sin_port = cm_id->local_addr.sin_port;
3349 cm_event.remote_addr = cm_id->remote_addr;
3350
6492cdf3
FL
3351 cm_event.private_data = (void *)event->cm_node->mpa_frame_buf;
3352 cm_event.private_data_len = (u8) event->cm_node->mpa_frame_size;
3c2d774c
GS
3353
3354 cm_event.local_addr.sin_addr.s_addr = event->cm_info.rem_addr;
3355 ret = cm_id->event_handler(cm_id, &cm_event);
3356 nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
3357
3358 if (ret)
6492cdf3
FL
3359 printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
3360 "ret=%d\n", __func__, __LINE__, ret);
3361 attr.qp_state = IB_QPS_RTS;
3362 nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
3c2d774c 3363
6492cdf3
FL
3364 nes_debug(NES_DBG_CM, "Exiting connect thread for QP%u. jiffies = "
3365 "%lu\n", nesqp->hwqp.qp_id, jiffies);
3c2d774c
GS
3366
3367 return;
3368}
3369
3370
3371/**
3372 * cm_event_connect_error
3373 */
1a855fbf 3374static void cm_event_connect_error(struct nes_cm_event *event)
3c2d774c
GS
3375{
3376 struct nes_qp *nesqp;
3377 struct iw_cm_id *cm_id;
3378 struct iw_cm_event cm_event;
3379 /* struct nes_cm_info cm_info; */
3380 int ret;
3381
3382 if (!event->cm_node)
3383 return;
3384
3385 cm_id = event->cm_node->cm_id;
3386 if (!cm_id) {
3387 return;
3388 }
3389
3390 nes_debug(NES_DBG_CM, "cm_node=%p, cm_id=%p\n", event->cm_node, cm_id);
3391 nesqp = cm_id->provider_data;
3392
3393 if (!nesqp) {
3394 return;
3395 }
3396
3397 /* notify OF layer about this connection error event */
3398 /* cm_id->rem_ref(cm_id); */
3399 nesqp->cm_id = NULL;
3400 cm_id->provider_data = NULL;
3401 cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
c5a7d489 3402 cm_event.status = -ECONNRESET;
3c2d774c
GS
3403 cm_event.provider_data = cm_id->provider_data;
3404 cm_event.local_addr = cm_id->local_addr;
3405 cm_event.remote_addr = cm_id->remote_addr;
3406 cm_event.private_data = NULL;
3407 cm_event.private_data_len = 0;
3408
6492cdf3
FL
3409 nes_debug(NES_DBG_CM, "call CM_EVENT REJECTED, local_addr=%08x, "
3410 "remove_addr=%08x\n", cm_event.local_addr.sin_addr.s_addr,
3411 cm_event.remote_addr.sin_addr.s_addr);
3c2d774c
GS
3412
3413 ret = cm_id->event_handler(cm_id, &cm_event);
3414 nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
3415 if (ret)
6492cdf3
FL
3416 printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
3417 "ret=%d\n", __func__, __LINE__, ret);
6492cdf3 3418 cm_id->rem_ref(cm_id);
3c2d774c 3419
6492cdf3 3420 rem_ref_cm_node(event->cm_node->cm_core, event->cm_node);
3c2d774c
GS
3421 return;
3422}
3423
3424
3425/**
3426 * cm_event_reset
3427 */
1a855fbf 3428static void cm_event_reset(struct nes_cm_event *event)
3c2d774c
GS
3429{
3430 struct nes_qp *nesqp;
3431 struct iw_cm_id *cm_id;
3432 struct iw_cm_event cm_event;
3433 /* struct nes_cm_info cm_info; */
3434 int ret;
3435
3436 if (!event->cm_node)
3437 return;
3438
3439 if (!event->cm_node->cm_id)
3440 return;
3441
3442 cm_id = event->cm_node->cm_id;
3443
3444 nes_debug(NES_DBG_CM, "%p - cm_id = %p\n", event->cm_node, cm_id);
3445 nesqp = cm_id->provider_data;
f9f3f1e0
FL
3446 if (!nesqp)
3447 return;
3c2d774c
GS
3448
3449 nesqp->cm_id = NULL;
3450 /* cm_id->provider_data = NULL; */
3451 cm_event.event = IW_CM_EVENT_DISCONNECT;
3452 cm_event.status = IW_CM_EVENT_STATUS_RESET;
3453 cm_event.provider_data = cm_id->provider_data;
3454 cm_event.local_addr = cm_id->local_addr;
3455 cm_event.remote_addr = cm_id->remote_addr;
3456 cm_event.private_data = NULL;
3457 cm_event.private_data_len = 0;
3458
183ecfa3 3459 cm_id->add_ref(cm_id);
f9f3f1e0 3460 ret = cm_id->event_handler(cm_id, &cm_event);
183ecfa3
FL
3461 atomic_inc(&cm_closes);
3462 cm_event.event = IW_CM_EVENT_CLOSE;
3463 cm_event.status = IW_CM_EVENT_STATUS_OK;
3464 cm_event.provider_data = cm_id->provider_data;
3465 cm_event.local_addr = cm_id->local_addr;
3466 cm_event.remote_addr = cm_id->remote_addr;
3467 cm_event.private_data = NULL;
3468 cm_event.private_data_len = 0;
3469 nes_debug(NES_DBG_CM, "NODE %p Generating CLOSE\n", event->cm_node);
3470 ret = cm_id->event_handler(cm_id, &cm_event);
3471
3c2d774c
GS
3472 nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
3473
3474
3475 /* notify OF layer about this connection error event */
3476 cm_id->rem_ref(cm_id);
3477
3478 return;
3479}
3480
3481
3482/**
3483 * cm_event_mpa_req
3484 */
1a855fbf 3485static void cm_event_mpa_req(struct nes_cm_event *event)
3c2d774c
GS
3486{
3487 struct iw_cm_id *cm_id;
3488 struct iw_cm_event cm_event;
3489 int ret;
3490 struct nes_cm_node *cm_node;
3491
3492 cm_node = event->cm_node;
3493 if (!cm_node)
3494 return;
3495 cm_id = cm_node->cm_id;
3496
3497 atomic_inc(&cm_connect_reqs);
3498 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3499 cm_node, cm_id, jiffies);
3500
3501 cm_event.event = IW_CM_EVENT_CONNECT_REQUEST;
3502 cm_event.status = IW_CM_EVENT_STATUS_OK;
3503 cm_event.provider_data = (void *)cm_node;
3504
3505 cm_event.local_addr.sin_family = AF_INET;
3506 cm_event.local_addr.sin_port = htons(event->cm_info.loc_port);
3507 cm_event.local_addr.sin_addr.s_addr = htonl(event->cm_info.loc_addr);
3508
9d5ab133
FL
3509 cm_event.remote_addr.sin_family = AF_INET;
3510 cm_event.remote_addr.sin_port = htons(event->cm_info.rem_port);
3511 cm_event.remote_addr.sin_addr.s_addr = htonl(event->cm_info.rem_addr);
3512 cm_event.private_data = cm_node->mpa_frame_buf;
3513 cm_event.private_data_len = (u8) cm_node->mpa_frame_size;
3514
3515 ret = cm_id->event_handler(cm_id, &cm_event);
3516 if (ret)
3517 printk(KERN_ERR "%s[%u] OFA CM event_handler returned, ret=%d\n",
3518 __func__, __LINE__, ret);
3519 return;
3520}
3521
3522
3523static void cm_event_mpa_reject(struct nes_cm_event *event)
3524{
3525 struct iw_cm_id *cm_id;
3526 struct iw_cm_event cm_event;
3527 struct nes_cm_node *cm_node;
3528 int ret;
3529
3530 cm_node = event->cm_node;
3531 if (!cm_node)
3532 return;
3533 cm_id = cm_node->cm_id;
3534
3535 atomic_inc(&cm_connect_reqs);
3536 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3537 cm_node, cm_id, jiffies);
3538
3539 cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
3540 cm_event.status = -ECONNREFUSED;
3541 cm_event.provider_data = cm_id->provider_data;
3542
3543 cm_event.local_addr.sin_family = AF_INET;
3544 cm_event.local_addr.sin_port = htons(event->cm_info.loc_port);
3545 cm_event.local_addr.sin_addr.s_addr = htonl(event->cm_info.loc_addr);
3546
3c2d774c
GS
3547 cm_event.remote_addr.sin_family = AF_INET;
3548 cm_event.remote_addr.sin_port = htons(event->cm_info.rem_port);
3549 cm_event.remote_addr.sin_addr.s_addr = htonl(event->cm_info.rem_addr);
3550
9d5ab133
FL
3551 cm_event.private_data = cm_node->mpa_frame_buf;
3552 cm_event.private_data_len = (u8) cm_node->mpa_frame_size;
3553
3554 nes_debug(NES_DBG_CM, "call CM_EVENT_MPA_REJECTED, local_addr=%08x, "
3555 "remove_addr=%08x\n",
3556 cm_event.local_addr.sin_addr.s_addr,
3557 cm_event.remote_addr.sin_addr.s_addr);
3c2d774c
GS
3558
3559 ret = cm_id->event_handler(cm_id, &cm_event);
3560 if (ret)
9d5ab133 3561 printk(KERN_ERR "%s[%u] OFA CM event_handler returned, ret=%d\n",
33718363 3562 __func__, __LINE__, ret);
3c2d774c
GS
3563
3564 return;
3565}
3566
3567
3568static void nes_cm_event_handler(struct work_struct *);
3569
3570/**
3571 * nes_cm_post_event
3572 * post an event to the cm event handler
3573 */
1a855fbf 3574static int nes_cm_post_event(struct nes_cm_event *event)
3c2d774c
GS
3575{
3576 atomic_inc(&event->cm_node->cm_core->events_posted);
3577 add_ref_cm_node(event->cm_node);
3578 event->cm_info.cm_id->add_ref(event->cm_info.cm_id);
3579 INIT_WORK(&event->event_work, nes_cm_event_handler);
6492cdf3
FL
3580 nes_debug(NES_DBG_CM, "cm_node=%p queue_work, event=%p\n",
3581 event->cm_node, event);
3c2d774c
GS
3582
3583 queue_work(event->cm_node->cm_core->event_wq, &event->event_work);
3584
3585 nes_debug(NES_DBG_CM, "Exit\n");
3586 return 0;
3587}
3588
3589
3590/**
3591 * nes_cm_event_handler
3592 * worker function to handle cm events
3593 * will free instance of nes_cm_event
3594 */
3595static void nes_cm_event_handler(struct work_struct *work)
3596{
6492cdf3
FL
3597 struct nes_cm_event *event = container_of(work, struct nes_cm_event,
3598 event_work);
3c2d774c
GS
3599 struct nes_cm_core *cm_core;
3600
6492cdf3 3601 if ((!event) || (!event->cm_node) || (!event->cm_node->cm_core))
3c2d774c 3602 return;
6492cdf3 3603
3c2d774c
GS
3604 cm_core = event->cm_node->cm_core;
3605 nes_debug(NES_DBG_CM, "event=%p, event->type=%u, events posted=%u\n",
6492cdf3 3606 event, event->type, atomic_read(&cm_core->events_posted));
3c2d774c
GS
3607
3608 switch (event->type) {
6492cdf3
FL
3609 case NES_CM_EVENT_MPA_REQ:
3610 cm_event_mpa_req(event);
3611 nes_debug(NES_DBG_CM, "cm_node=%p CM Event: MPA REQUEST\n",
3612 event->cm_node);
3613 break;
3614 case NES_CM_EVENT_RESET:
3615 nes_debug(NES_DBG_CM, "cm_node = %p CM Event: RESET\n",
3616 event->cm_node);
3617 cm_event_reset(event);
3618 break;
3619 case NES_CM_EVENT_CONNECTED:
3620 if ((!event->cm_node->cm_id) ||
3621 (event->cm_node->state != NES_CM_STATE_TSA))
3c2d774c 3622 break;
6492cdf3
FL
3623 cm_event_connected(event);
3624 nes_debug(NES_DBG_CM, "CM Event: CONNECTED\n");
3625 break;
9d5ab133
FL
3626 case NES_CM_EVENT_MPA_REJECT:
3627 if ((!event->cm_node->cm_id) ||
3628 (event->cm_node->state == NES_CM_STATE_TSA))
3629 break;
3630 cm_event_mpa_reject(event);
3631 nes_debug(NES_DBG_CM, "CM Event: REJECT\n");
3632 break;
3633
6492cdf3
FL
3634 case NES_CM_EVENT_ABORTED:
3635 if ((!event->cm_node->cm_id) ||
3636 (event->cm_node->state == NES_CM_STATE_TSA))
3c2d774c 3637 break;
6492cdf3
FL
3638 cm_event_connect_error(event);
3639 nes_debug(NES_DBG_CM, "CM Event: ABORTED\n");
3640 break;
3641 case NES_CM_EVENT_DROPPED_PKT:
3642 nes_debug(NES_DBG_CM, "CM Event: DROPPED PKT\n");
3643 break;
3644 default:
3645 nes_debug(NES_DBG_CM, "CM Event: UNKNOWN EVENT TYPE\n");
3646 break;
3c2d774c
GS
3647 }
3648
3649 atomic_dec(&cm_core->events_posted);
3650 event->cm_info.cm_id->rem_ref(event->cm_info.cm_id);
3651 rem_ref_cm_node(cm_core, event->cm_node);
3652 kfree(event);
3653
3654 return;
3655}
This page took 0.372006 seconds and 5 git commands to generate.