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