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