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