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