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