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