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