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