2008-02-05 04:20:45 +00:00
|
|
|
/*
|
2014-03-26 22:07:57 +00:00
|
|
|
* Copyright (c) 2006 - 2014 Intel Corporation. All rights reserved.
|
2008-02-05 04:20:45 +00:00
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#define TCPOPT_TIMESTAMP 8
|
|
|
|
|
2011-07-26 23:09:06 +00:00
|
|
|
#include <linux/atomic.h>
|
2008-02-05 04:20:45 +00:00
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/tcp.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/if_arp.h>
|
2008-03-21 00:55:30 +00:00
|
|
|
#include <linux/if_vlan.h>
|
2008-02-05 04:20:45 +00:00
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/random.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/threads.h>
|
2009-12-09 23:54:28 +00:00
|
|
|
#include <linux/highmem.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2008-10-03 19:21:19 +00:00
|
|
|
#include <net/arp.h>
|
2008-02-05 04:20:45 +00:00
|
|
|
#include <net/neighbour.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/ip_fib.h>
|
infiniband: i40iw, nes: don't use wall time for TCP sequence numbers
The nes infiniband driver uses current_kernel_time() to get a nanosecond
granunarity timestamp to initialize its tcp sequence counters. This is
one of only a few remaining users of that deprecated function, so we
should try to get rid of it.
Aside from using a deprecated API, there are several problems I see here:
- Using a CLOCK_REALTIME based time source makes it predictable in
case the time base is synchronized.
- Using a coarse timestamp means it only gets updated once per jiffie,
making it even more predictable in order to avoid having to access
the hardware clock source
- The upper 2 bits are always zero because the nanoseconds are at most
999999999.
For the Linux TCP implementation, we use secure_tcp_seq(), which appears
to be appropriate here as well, and solves all the above problems.
i40iw uses a variant of the same code, so I do that same thing there
for ipv4. Unlike nes, i40e also supports ipv6, which needs to call
secure_tcpv6_seq instead.
Acked-by: Shiraz Saleem <shiraz.saleem@intel.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
2018-07-09 08:34:43 +00:00
|
|
|
#include <net/secure_seq.h>
|
2009-04-27 20:38:31 +00:00
|
|
|
#include <net/tcp.h>
|
2014-03-26 22:07:57 +00:00
|
|
|
#include <linux/fcntl.h>
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
#include "nes.h"
|
|
|
|
|
|
|
|
u32 cm_packets_sent;
|
|
|
|
u32 cm_packets_bounced;
|
|
|
|
u32 cm_packets_dropped;
|
|
|
|
u32 cm_packets_retrans;
|
|
|
|
u32 cm_packets_created;
|
|
|
|
u32 cm_packets_received;
|
2010-02-12 19:55:03 +00:00
|
|
|
atomic_t cm_listens_created;
|
|
|
|
atomic_t cm_listens_destroyed;
|
2008-02-05 04:20:45 +00:00
|
|
|
u32 cm_backlog_drops;
|
|
|
|
atomic_t cm_loopbacks;
|
|
|
|
atomic_t cm_nodes_created;
|
|
|
|
atomic_t cm_nodes_destroyed;
|
|
|
|
atomic_t cm_accel_dropped_pkts;
|
|
|
|
atomic_t cm_resets_recvd;
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
|
|
|
|
static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
|
2008-02-05 04:20:45 +00:00
|
|
|
static int mini_cm_del_listen(struct nes_cm_core *, struct nes_cm_listener *);
|
2011-09-25 14:47:46 +00:00
|
|
|
static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *, struct nes_vnic *, u16, void *, struct nes_cm_info *);
|
2008-07-25 03:50:45 +00:00
|
|
|
static int mini_cm_close(struct nes_cm_core *, struct nes_cm_node *);
|
2011-09-25 14:47:46 +00:00
|
|
|
static int mini_cm_accept(struct nes_cm_core *, struct nes_cm_node *);
|
|
|
|
static int mini_cm_reject(struct nes_cm_core *, struct nes_cm_node *);
|
|
|
|
static int mini_cm_recv_pkt(struct nes_cm_core *, struct nes_vnic *, struct sk_buff *);
|
2008-04-17 04:01:09 +00:00
|
|
|
static int mini_cm_dealloc_core(struct nes_cm_core *);
|
|
|
|
static int mini_cm_get(struct nes_cm_core *);
|
|
|
|
static int mini_cm_set(struct nes_cm_core *, u32, u32);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
static void form_cm_frame(struct sk_buff *, struct nes_cm_node *, void *, u32, void *, u32, u8);
|
2008-07-25 03:50:45 +00:00
|
|
|
static int add_ref_cm_node(struct nes_cm_node *);
|
|
|
|
static int rem_ref_cm_node(struct nes_cm_core *, struct nes_cm_node *);
|
|
|
|
|
2008-04-17 04:01:09 +00:00
|
|
|
static int nes_cm_disconn_true(struct nes_qp *);
|
|
|
|
static int nes_cm_post_event(struct nes_cm_event *event);
|
|
|
|
static int nes_disconnect(struct nes_qp *nesqp, int abrupt);
|
|
|
|
static void nes_disconnect_worker(struct work_struct *work);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
static int send_mpa_request(struct nes_cm_node *, struct sk_buff *);
|
2009-03-06 23:15:01 +00:00
|
|
|
static int send_mpa_reject(struct nes_cm_node *);
|
2008-07-25 03:50:45 +00:00
|
|
|
static int send_syn(struct nes_cm_node *, u32, struct sk_buff *);
|
|
|
|
static int send_reset(struct nes_cm_node *, struct sk_buff *);
|
|
|
|
static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb);
|
2008-04-17 04:01:09 +00:00
|
|
|
static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
static void process_packet(struct nes_cm_node *, struct sk_buff *, struct nes_cm_core *);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
static void active_open_err(struct nes_cm_node *, struct sk_buff *, int);
|
|
|
|
static void passive_open_err(struct nes_cm_node *, struct sk_buff *, int);
|
|
|
|
static void cleanup_retrans_entry(struct nes_cm_node *);
|
2009-03-06 23:15:01 +00:00
|
|
|
static void handle_rcv_mpa(struct nes_cm_node *, struct sk_buff *);
|
2008-07-25 03:50:45 +00:00
|
|
|
static void free_retrans_entry(struct nes_cm_node *cm_node);
|
2011-09-25 14:47:46 +00:00
|
|
|
static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph, struct sk_buff *skb, int optionsize, int passive);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
/* CM event handler functions */
|
|
|
|
static void cm_event_connected(struct nes_cm_event *);
|
|
|
|
static void cm_event_connect_error(struct nes_cm_event *);
|
|
|
|
static void cm_event_reset(struct nes_cm_event *);
|
|
|
|
static void cm_event_mpa_req(struct nes_cm_event *);
|
2009-03-06 23:15:01 +00:00
|
|
|
static void cm_event_mpa_reject(struct nes_cm_event *);
|
|
|
|
static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
/* MPA build functions */
|
|
|
|
static int cm_build_mpa_frame(struct nes_cm_node *, u8 **, u16 *, u8 *, u8);
|
|
|
|
static void build_mpa_v2(struct nes_cm_node *, void *, u8);
|
|
|
|
static void build_mpa_v1(struct nes_cm_node *, void *, u8);
|
|
|
|
static void build_rdma0_msg(struct nes_cm_node *, struct nes_qp **);
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
static void print_core(struct nes_cm_core *core);
|
2014-03-11 19:17:25 +00:00
|
|
|
static void record_ird_ord(struct nes_cm_node *, u16, u16);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* External CM API Interface */
|
|
|
|
/* instance of function pointers for client API */
|
|
|
|
/* set address of this instance to cm_core->cm_ops at cm_core alloc */
|
2015-11-28 14:00:37 +00:00
|
|
|
static const struct nes_cm_ops nes_cm_api = {
|
2016-12-17 01:03:16 +00:00
|
|
|
.accelerated = mini_cm_accelerated,
|
|
|
|
.listen = mini_cm_listen,
|
|
|
|
.stop_listener = mini_cm_del_listen,
|
|
|
|
.connect = mini_cm_connect,
|
|
|
|
.close = mini_cm_close,
|
|
|
|
.accept = mini_cm_accept,
|
|
|
|
.reject = mini_cm_reject,
|
|
|
|
.recv_pkt = mini_cm_recv_pkt,
|
|
|
|
.destroy_cm_core = mini_cm_dealloc_core,
|
|
|
|
.get = mini_cm_get,
|
|
|
|
.set = mini_cm_set
|
2008-02-05 04:20:45 +00:00
|
|
|
};
|
|
|
|
|
2008-04-17 04:01:09 +00:00
|
|
|
static struct nes_cm_core *g_cm_core;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
atomic_t cm_connects;
|
|
|
|
atomic_t cm_accepts;
|
|
|
|
atomic_t cm_disconnects;
|
|
|
|
atomic_t cm_closes;
|
|
|
|
atomic_t cm_connecteds;
|
|
|
|
atomic_t cm_connect_reqs;
|
|
|
|
atomic_t cm_rejects;
|
|
|
|
|
2011-09-26 01:34:00 +00:00
|
|
|
int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
|
|
|
|
{
|
|
|
|
return add_ref_cm_node(cm_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nes_rem_ref_cm_node(struct nes_cm_node *cm_node)
|
|
|
|
{
|
|
|
|
return rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
/**
|
|
|
|
* create_event
|
|
|
|
*/
|
2011-09-25 14:47:46 +00:00
|
|
|
static struct nes_cm_event *create_event(struct nes_cm_node * cm_node,
|
|
|
|
enum nes_cm_event_type type)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct nes_cm_event *event;
|
|
|
|
|
|
|
|
if (!cm_node->cm_id)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* allocate an empty event */
|
|
|
|
event = kzalloc(sizeof(*event), GFP_ATOMIC);
|
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
event->type = type;
|
|
|
|
event->cm_node = cm_node;
|
|
|
|
event->cm_info.rem_addr = cm_node->rem_addr;
|
|
|
|
event->cm_info.loc_addr = cm_node->loc_addr;
|
|
|
|
event->cm_info.rem_port = cm_node->rem_port;
|
|
|
|
event->cm_info.loc_port = cm_node->loc_port;
|
|
|
|
event->cm_info.cm_id = cm_node->cm_id;
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "cm_node=%p Created event=%p, type=%u, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"dst_addr=%08x[%x], src_addr=%08x[%x]\n",
|
|
|
|
cm_node, event, type, event->cm_info.loc_addr,
|
|
|
|
event->cm_info.loc_port, event->cm_info.rem_addr,
|
|
|
|
event->cm_info.rem_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nes_cm_post_event(event);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send_mpa_request
|
|
|
|
*/
|
2008-07-25 03:50:45 +00:00
|
|
|
static int send_mpa_request(struct nes_cm_node *cm_node, struct sk_buff *skb)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2011-09-25 14:47:46 +00:00
|
|
|
u8 start_addr = 0;
|
|
|
|
u8 *start_ptr = &start_addr;
|
|
|
|
u8 **start_buff = &start_ptr;
|
|
|
|
u16 buff_len = 0;
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
if (!skb) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "skb set to NULL\n");
|
2008-02-05 04:20:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send an MPA Request frame */
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_build_mpa_frame(cm_node, start_buff, &buff_len, NULL, MPA_KEY_REQUEST);
|
|
|
|
form_cm_frame(skb, cm_node, NULL, 0, *start_buff, buff_len, SET_ACK);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
return schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int send_mpa_reject(struct nes_cm_node *cm_node)
|
|
|
|
{
|
2011-09-25 14:47:46 +00:00
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
u8 start_addr = 0;
|
|
|
|
u8 *start_ptr = &start_addr;
|
|
|
|
u8 **start_buff = &start_ptr;
|
|
|
|
u16 buff_len = 0;
|
2012-01-17 16:17:30 +00:00
|
|
|
struct ietf_mpa_v1 *mpa_frame;
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
skb = dev_alloc_skb(MAX_CM_BUFFER);
|
|
|
|
if (!skb) {
|
|
|
|
nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send an MPA reject frame */
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_build_mpa_frame(cm_node, start_buff, &buff_len, NULL, MPA_KEY_REPLY);
|
2012-01-17 16:17:30 +00:00
|
|
|
mpa_frame = (struct ietf_mpa_v1 *)*start_buff;
|
|
|
|
mpa_frame->flags |= IETF_MPA_FLAGS_REJECT;
|
2011-09-25 14:47:46 +00:00
|
|
|
form_cm_frame(skb, cm_node, NULL, 0, *start_buff, buff_len, SET_ACK | SET_FIN);
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
cm_node->state = NES_CM_STATE_FIN_WAIT1;
|
|
|
|
return schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* recv_mpa - process a received TCP pkt, we are expecting an
|
|
|
|
* IETF MPA frame
|
|
|
|
*/
|
2009-03-06 23:15:01 +00:00
|
|
|
static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 *type,
|
2011-09-25 14:47:46 +00:00
|
|
|
u32 len)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2011-09-25 14:47:46 +00:00
|
|
|
struct ietf_mpa_v1 *mpa_frame;
|
|
|
|
struct ietf_mpa_v2 *mpa_v2_frame;
|
|
|
|
struct ietf_rtr_msg *rtr_msg;
|
|
|
|
int mpa_hdr_len;
|
|
|
|
int priv_data_len;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
*type = NES_MPA_REQUEST_ACCEPT;
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
/* assume req frame is in tcp data payload */
|
2011-09-25 14:47:46 +00:00
|
|
|
if (len < sizeof(struct ietf_mpa_v1)) {
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "The received ietf buffer was too small (%x)\n", len);
|
2009-03-06 23:15:01 +00:00
|
|
|
return -EINVAL;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
/* points to the beginning of the frame, which could be MPA V1 or V2 */
|
|
|
|
mpa_frame = (struct ietf_mpa_v1 *)buffer;
|
|
|
|
mpa_hdr_len = sizeof(struct ietf_mpa_v1);
|
|
|
|
priv_data_len = ntohs(mpa_frame->priv_data_len);
|
|
|
|
|
2009-12-09 23:53:54 +00:00
|
|
|
/* make sure mpa private data len is less than 512 bytes */
|
2011-09-25 14:47:46 +00:00
|
|
|
if (priv_data_len > IETF_MAX_PRIV_DATA_LEN) {
|
2009-12-09 23:53:54 +00:00
|
|
|
nes_debug(NES_DBG_CM, "The received Length of Private"
|
2011-09-25 14:47:46 +00:00
|
|
|
" Data field exceeds 512 octets\n");
|
2009-12-09 23:53:54 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* make sure MPA receiver interoperate with the
|
|
|
|
* received MPA version and MPA key information
|
|
|
|
*
|
|
|
|
*/
|
2011-09-25 14:47:46 +00:00
|
|
|
if (mpa_frame->rev != IETF_MPA_V1 && mpa_frame->rev != IETF_MPA_V2) {
|
|
|
|
nes_debug(NES_DBG_CM, "The received mpa version"
|
|
|
|
" is not supported\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* backwards compatibility only
|
|
|
|
*/
|
|
|
|
if (mpa_frame->rev > cm_node->mpa_frame_rev) {
|
2009-12-09 23:53:54 +00:00
|
|
|
nes_debug(NES_DBG_CM, "The received mpa version"
|
2011-09-25 14:47:46 +00:00
|
|
|
" can not be interoperated\n");
|
2009-12-09 23:53:54 +00:00
|
|
|
return -EINVAL;
|
2011-09-25 14:47:46 +00:00
|
|
|
} else {
|
|
|
|
cm_node->mpa_frame_rev = mpa_frame->rev;
|
2009-12-09 23:53:54 +00:00
|
|
|
}
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2009-12-09 23:53:54 +00:00
|
|
|
if (cm_node->state != NES_CM_STATE_MPAREQ_SENT) {
|
|
|
|
if (memcmp(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE)) {
|
|
|
|
nes_debug(NES_DBG_CM, "Unexpected MPA Key received \n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (memcmp(mpa_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE)) {
|
|
|
|
nes_debug(NES_DBG_CM, "Unexpected MPA Key received \n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
if (priv_data_len + mpa_hdr_len != len) {
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "The received ietf buffer was not right"
|
2011-09-25 14:47:46 +00:00
|
|
|
" complete (%x + %x != %x)\n",
|
|
|
|
priv_data_len, mpa_hdr_len, len);
|
2009-03-06 23:15:01 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/* make sure it does not exceed the max size */
|
|
|
|
if (len > MAX_CM_BUFFER) {
|
|
|
|
nes_debug(NES_DBG_CM, "The received ietf buffer was too large"
|
2011-09-25 14:47:46 +00:00
|
|
|
" (%x + %x != %x)\n",
|
|
|
|
priv_data_len, mpa_hdr_len, len);
|
2009-03-06 23:15:01 +00:00
|
|
|
return -EINVAL;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->mpa_frame_size = priv_data_len;
|
|
|
|
|
|
|
|
switch (mpa_frame->rev) {
|
|
|
|
case IETF_MPA_V2: {
|
|
|
|
u16 ird_size;
|
|
|
|
u16 ord_size;
|
2012-02-26 01:45:37 +00:00
|
|
|
u16 rtr_ctrl_ird;
|
|
|
|
u16 rtr_ctrl_ord;
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
mpa_v2_frame = (struct ietf_mpa_v2 *)buffer;
|
|
|
|
mpa_hdr_len += IETF_RTR_MSG_SIZE;
|
|
|
|
cm_node->mpa_frame_size -= IETF_RTR_MSG_SIZE;
|
|
|
|
rtr_msg = &mpa_v2_frame->rtr_msg;
|
|
|
|
|
|
|
|
/* parse rtr message */
|
2012-02-26 01:45:37 +00:00
|
|
|
rtr_ctrl_ird = ntohs(rtr_msg->ctrl_ird);
|
|
|
|
rtr_ctrl_ord = ntohs(rtr_msg->ctrl_ord);
|
|
|
|
ird_size = rtr_ctrl_ird & IETF_NO_IRD_ORD;
|
|
|
|
ord_size = rtr_ctrl_ord & IETF_NO_IRD_ORD;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2012-02-26 01:45:37 +00:00
|
|
|
if (!(rtr_ctrl_ird & IETF_PEER_TO_PEER)) {
|
2011-09-25 14:47:46 +00:00
|
|
|
/* send reset */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-03-11 19:17:25 +00:00
|
|
|
if (ird_size == IETF_NO_IRD_ORD || ord_size == IETF_NO_IRD_ORD)
|
|
|
|
cm_node->mpav2_ird_ord = IETF_NO_IRD_ORD;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2014-03-11 19:17:25 +00:00
|
|
|
if (cm_node->mpav2_ird_ord != IETF_NO_IRD_ORD) {
|
2011-09-25 14:47:46 +00:00
|
|
|
/* responder */
|
2014-03-11 19:17:25 +00:00
|
|
|
if (cm_node->state != NES_CM_STATE_MPAREQ_SENT) {
|
|
|
|
/* we are still negotiating */
|
|
|
|
if (ord_size > NES_MAX_IRD) {
|
|
|
|
cm_node->ird_size = NES_MAX_IRD;
|
|
|
|
} else {
|
|
|
|
cm_node->ird_size = ord_size;
|
|
|
|
if (ord_size == 0 &&
|
|
|
|
(rtr_ctrl_ord & IETF_RDMA0_READ)) {
|
|
|
|
cm_node->ird_size = 1;
|
|
|
|
nes_debug(NES_DBG_CM,
|
|
|
|
"%s: Remote peer doesn't support RDMA0_READ (ord=%u)\n",
|
|
|
|
__func__, ord_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ird_size > NES_MAX_ORD)
|
|
|
|
cm_node->ord_size = NES_MAX_ORD;
|
|
|
|
else
|
|
|
|
cm_node->ord_size = ird_size;
|
|
|
|
} else { /* initiator */
|
|
|
|
if (ord_size > NES_MAX_IRD) {
|
|
|
|
nes_debug(NES_DBG_CM,
|
|
|
|
"%s: Unable to support the requested (ord =%u)\n",
|
|
|
|
__func__, ord_size);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
cm_node->ird_size = ord_size;
|
|
|
|
|
|
|
|
if (ird_size > NES_MAX_ORD) {
|
|
|
|
cm_node->ord_size = NES_MAX_ORD;
|
|
|
|
} else {
|
|
|
|
if (ird_size == 0 &&
|
|
|
|
(rtr_ctrl_ord & IETF_RDMA0_READ)) {
|
|
|
|
nes_debug(NES_DBG_CM,
|
|
|
|
"%s: Remote peer doesn't support RDMA0_READ (ird=%u)\n",
|
|
|
|
__func__, ird_size);
|
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
|
|
|
cm_node->ord_size = ird_size;
|
|
|
|
}
|
|
|
|
}
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-26 01:45:37 +00:00
|
|
|
if (rtr_ctrl_ord & IETF_RDMA0_READ) {
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->send_rdma0_op = SEND_RDMA_READ_ZERO;
|
2014-03-11 19:17:25 +00:00
|
|
|
|
2012-02-26 01:45:37 +00:00
|
|
|
} else if (rtr_ctrl_ord & IETF_RDMA0_WRITE) {
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->send_rdma0_op = SEND_RDMA_WRITE_ZERO;
|
|
|
|
} else { /* Not supported RDMA0 operation */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IETF_MPA_V1:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
/* copy entire MPA frame to our cm_node's frame */
|
2011-09-25 14:47:46 +00:00
|
|
|
memcpy(cm_node->mpa_frame_buf, buffer + mpa_hdr_len, cm_node->mpa_frame_size);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
if (mpa_frame->flags & IETF_MPA_FLAGS_REJECT)
|
|
|
|
*type = NES_MPA_REQUEST_REJECT;
|
2008-02-05 04:20:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* form_cm_frame - get a free packet and build empty frame Use
|
|
|
|
* node info to build.
|
|
|
|
*/
|
2008-11-22 02:51:01 +00:00
|
|
|
static void form_cm_frame(struct sk_buff *skb,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_cm_node *cm_node, void *options, u32 optionsize,
|
|
|
|
void *data, u32 datasize, u8 flags)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct tcphdr *tcph;
|
|
|
|
struct iphdr *iph;
|
|
|
|
struct ethhdr *ethh;
|
|
|
|
u8 *buf;
|
|
|
|
u16 packetsize = sizeof(*iph);
|
|
|
|
|
|
|
|
packetsize += sizeof(*tcph);
|
2011-09-25 14:47:46 +00:00
|
|
|
packetsize += optionsize + datasize;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
skb_trim(skb, 0);
|
2008-02-05 04:20:45 +00:00
|
|
|
memset(skb->data, 0x00, ETH_HLEN + sizeof(*iph) + sizeof(*tcph));
|
|
|
|
|
|
|
|
buf = skb_put(skb, packetsize + ETH_HLEN);
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
ethh = (struct ethhdr *)buf;
|
2008-02-05 04:20:45 +00:00
|
|
|
buf += ETH_HLEN;
|
|
|
|
|
|
|
|
iph = (struct iphdr *)buf;
|
|
|
|
buf += sizeof(*iph);
|
|
|
|
tcph = (struct tcphdr *)buf;
|
|
|
|
skb_reset_mac_header(skb);
|
|
|
|
skb_set_network_header(skb, ETH_HLEN);
|
2011-09-25 14:47:46 +00:00
|
|
|
skb_set_transport_header(skb, ETH_HLEN + sizeof(*iph));
|
2008-02-05 04:20:45 +00:00
|
|
|
buf += sizeof(*tcph);
|
|
|
|
|
|
|
|
skb->ip_summed = CHECKSUM_PARTIAL;
|
2012-09-20 20:55:33 +00:00
|
|
|
if (!(cm_node->netdev->features & NETIF_F_IP_CSUM))
|
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
2008-02-05 04:20:45 +00:00
|
|
|
skb->protocol = htons(0x800);
|
|
|
|
skb->data_len = 0;
|
|
|
|
skb->mac_len = ETH_HLEN;
|
|
|
|
|
|
|
|
memcpy(ethh->h_dest, cm_node->rem_mac, ETH_ALEN);
|
|
|
|
memcpy(ethh->h_source, cm_node->loc_mac, ETH_ALEN);
|
|
|
|
ethh->h_proto = htons(0x0800);
|
|
|
|
|
|
|
|
iph->version = IPVERSION;
|
2011-09-25 14:47:46 +00:00
|
|
|
iph->ihl = 5; /* 5 * 4Byte words, IP headr len */
|
2008-02-05 04:20:45 +00:00
|
|
|
iph->tos = 0;
|
|
|
|
iph->tot_len = htons(packetsize);
|
|
|
|
iph->id = htons(++cm_node->tcp_cntxt.loc_id);
|
|
|
|
|
|
|
|
iph->frag_off = htons(0x4000);
|
|
|
|
iph->ttl = 0x40;
|
2011-09-25 14:47:46 +00:00
|
|
|
iph->protocol = 0x06; /* IPPROTO_TCP */
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2016-02-26 15:18:02 +00:00
|
|
|
iph->saddr = htonl(cm_node->loc_addr);
|
|
|
|
iph->daddr = htonl(cm_node->rem_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2016-02-26 15:18:02 +00:00
|
|
|
tcph->source = htons(cm_node->loc_port);
|
|
|
|
tcph->dest = htons(cm_node->rem_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
tcph->seq = htonl(cm_node->tcp_cntxt.loc_seq_num);
|
|
|
|
|
|
|
|
if (flags & SET_ACK) {
|
|
|
|
cm_node->tcp_cntxt.loc_ack_num = cm_node->tcp_cntxt.rcv_nxt;
|
|
|
|
tcph->ack_seq = htonl(cm_node->tcp_cntxt.loc_ack_num);
|
|
|
|
tcph->ack = 1;
|
2011-09-25 14:47:46 +00:00
|
|
|
} else {
|
2008-02-05 04:20:45 +00:00
|
|
|
tcph->ack_seq = 0;
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (flags & SET_SYN) {
|
|
|
|
cm_node->tcp_cntxt.loc_seq_num++;
|
|
|
|
tcph->syn = 1;
|
2011-09-25 14:47:46 +00:00
|
|
|
} else {
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->tcp_cntxt.loc_seq_num += datasize;
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (flags & SET_FIN) {
|
|
|
|
cm_node->tcp_cntxt.loc_seq_num++;
|
2008-02-05 04:20:45 +00:00
|
|
|
tcph->fin = 1;
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (flags & SET_RST)
|
|
|
|
tcph->rst = 1;
|
|
|
|
|
|
|
|
tcph->doff = (u16)((sizeof(*tcph) + optionsize + 3) >> 2);
|
|
|
|
tcph->window = htons(cm_node->tcp_cntxt.rcv_wnd);
|
|
|
|
tcph->urg_ptr = 0;
|
|
|
|
if (optionsize)
|
|
|
|
memcpy(buf, options, optionsize);
|
|
|
|
buf += optionsize;
|
|
|
|
if (datasize)
|
|
|
|
memcpy(buf, data, datasize);
|
|
|
|
|
|
|
|
skb_shinfo(skb)->nr_frags = 0;
|
|
|
|
cm_packets_created++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* print_core - dump a cm core
|
|
|
|
*/
|
|
|
|
static void print_core(struct nes_cm_core *core)
|
|
|
|
{
|
|
|
|
nes_debug(NES_DBG_CM, "---------------------------------------------\n");
|
|
|
|
nes_debug(NES_DBG_CM, "CM Core -- (core = %p )\n", core);
|
|
|
|
if (!core)
|
|
|
|
return;
|
|
|
|
nes_debug(NES_DBG_CM, "---------------------------------------------\n");
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
nes_debug(NES_DBG_CM, "State : %u \n", core->state);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "Listen Nodes : %u \n", atomic_read(&core->listen_node_cnt));
|
|
|
|
nes_debug(NES_DBG_CM, "Active Nodes : %u \n", atomic_read(&core->node_cnt));
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "core : %p \n", core);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "-------------- end core ---------------\n");
|
|
|
|
}
|
|
|
|
|
2014-03-11 19:17:25 +00:00
|
|
|
static void record_ird_ord(struct nes_cm_node *cm_node,
|
|
|
|
u16 conn_ird, u16 conn_ord)
|
|
|
|
{
|
|
|
|
if (conn_ird > NES_MAX_IRD)
|
|
|
|
conn_ird = NES_MAX_IRD;
|
|
|
|
|
|
|
|
if (conn_ord > NES_MAX_ORD)
|
|
|
|
conn_ord = NES_MAX_ORD;
|
|
|
|
|
|
|
|
cm_node->ird_size = conn_ird;
|
|
|
|
cm_node->ord_size = conn_ord;
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
/**
|
|
|
|
* cm_build_mpa_frame - build a MPA V1 frame or MPA V2 frame
|
|
|
|
*/
|
|
|
|
static int cm_build_mpa_frame(struct nes_cm_node *cm_node, u8 **start_buff,
|
|
|
|
u16 *buff_len, u8 *pci_mem, u8 mpa_key)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
*start_buff = (pci_mem) ? pci_mem : &cm_node->mpa_frame_buf[0];
|
|
|
|
|
|
|
|
switch (cm_node->mpa_frame_rev) {
|
|
|
|
case IETF_MPA_V1:
|
|
|
|
*start_buff = (u8 *)*start_buff + sizeof(struct ietf_rtr_msg);
|
|
|
|
*buff_len = sizeof(struct ietf_mpa_v1) + cm_node->mpa_frame_size;
|
|
|
|
build_mpa_v1(cm_node, *start_buff, mpa_key);
|
|
|
|
break;
|
|
|
|
case IETF_MPA_V2:
|
|
|
|
*buff_len = sizeof(struct ietf_mpa_v2) + cm_node->mpa_frame_size;
|
|
|
|
build_mpa_v2(cm_node, *start_buff, mpa_key);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* build_mpa_v2 - build a MPA V2 frame
|
|
|
|
*/
|
|
|
|
static void build_mpa_v2(struct nes_cm_node *cm_node,
|
|
|
|
void *start_addr, u8 mpa_key)
|
|
|
|
{
|
|
|
|
struct ietf_mpa_v2 *mpa_frame = (struct ietf_mpa_v2 *)start_addr;
|
|
|
|
struct ietf_rtr_msg *rtr_msg = &mpa_frame->rtr_msg;
|
2012-02-26 01:45:37 +00:00
|
|
|
u16 ctrl_ird;
|
|
|
|
u16 ctrl_ord;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
|
|
|
/* initialize the upper 5 bytes of the frame */
|
|
|
|
build_mpa_v1(cm_node, start_addr, mpa_key);
|
|
|
|
mpa_frame->flags |= IETF_MPA_V2_FLAG; /* set a bit to indicate MPA V2 */
|
|
|
|
mpa_frame->priv_data_len += htons(IETF_RTR_MSG_SIZE);
|
|
|
|
|
|
|
|
/* initialize RTR msg */
|
2014-03-11 19:17:25 +00:00
|
|
|
if (cm_node->mpav2_ird_ord == IETF_NO_IRD_ORD) {
|
|
|
|
ctrl_ird = IETF_NO_IRD_ORD;
|
|
|
|
ctrl_ord = IETF_NO_IRD_ORD;
|
|
|
|
} else {
|
|
|
|
ctrl_ird = cm_node->ird_size & IETF_NO_IRD_ORD;
|
|
|
|
ctrl_ord = cm_node->ord_size & IETF_NO_IRD_ORD;
|
|
|
|
}
|
2012-02-26 01:45:37 +00:00
|
|
|
ctrl_ird |= IETF_PEER_TO_PEER;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
|
|
|
switch (mpa_key) {
|
|
|
|
case MPA_KEY_REQUEST:
|
2012-02-26 01:45:37 +00:00
|
|
|
ctrl_ord |= IETF_RDMA0_WRITE;
|
|
|
|
ctrl_ord |= IETF_RDMA0_READ;
|
2011-09-25 14:47:46 +00:00
|
|
|
break;
|
|
|
|
case MPA_KEY_REPLY:
|
|
|
|
switch (cm_node->send_rdma0_op) {
|
|
|
|
case SEND_RDMA_WRITE_ZERO:
|
2012-02-26 01:45:37 +00:00
|
|
|
ctrl_ord |= IETF_RDMA0_WRITE;
|
2011-09-25 14:47:46 +00:00
|
|
|
break;
|
|
|
|
case SEND_RDMA_READ_ZERO:
|
2012-02-26 01:45:37 +00:00
|
|
|
ctrl_ord |= IETF_RDMA0_READ;
|
2011-09-25 14:47:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-26 01:45:37 +00:00
|
|
|
rtr_msg->ctrl_ird = htons(ctrl_ird);
|
|
|
|
rtr_msg->ctrl_ord = htons(ctrl_ord);
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* build_mpa_v1 - build a MPA V1 frame
|
|
|
|
*/
|
|
|
|
static void build_mpa_v1(struct nes_cm_node *cm_node, void *start_addr, u8 mpa_key)
|
|
|
|
{
|
|
|
|
struct ietf_mpa_v1 *mpa_frame = (struct ietf_mpa_v1 *)start_addr;
|
|
|
|
|
|
|
|
switch (mpa_key) {
|
|
|
|
case MPA_KEY_REQUEST:
|
|
|
|
memcpy(mpa_frame->key, IEFT_MPA_KEY_REQ, IETF_MPA_KEY_SIZE);
|
|
|
|
break;
|
|
|
|
case MPA_KEY_REPLY:
|
|
|
|
memcpy(mpa_frame->key, IEFT_MPA_KEY_REP, IETF_MPA_KEY_SIZE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mpa_frame->flags = IETF_MPA_FLAGS_CRC;
|
|
|
|
mpa_frame->rev = cm_node->mpa_frame_rev;
|
|
|
|
mpa_frame->priv_data_len = htons(cm_node->mpa_frame_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void build_rdma0_msg(struct nes_cm_node *cm_node, struct nes_qp **nesqp_addr)
|
|
|
|
{
|
|
|
|
u64 u64temp;
|
|
|
|
struct nes_qp *nesqp = *nesqp_addr;
|
|
|
|
struct nes_hw_qp_wqe *wqe = &nesqp->hwqp.sq_vbase[0];
|
|
|
|
|
2014-03-11 19:20:17 +00:00
|
|
|
u64temp = (unsigned long)nesqp->nesuqp_addr;
|
2011-09-25 14:47:46 +00:00
|
|
|
u64temp |= NES_SW_CONTEXT_ALIGN >> 1;
|
|
|
|
set_wqe_64bit_value(wqe->wqe_words, NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX, u64temp);
|
|
|
|
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_LOW_IDX] = 0;
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_FRAG0_HIGH_IDX] = 0;
|
|
|
|
|
|
|
|
switch (cm_node->send_rdma0_op) {
|
|
|
|
case SEND_RDMA_WRITE_ZERO:
|
|
|
|
nes_debug(NES_DBG_CM, "Sending first write.\n");
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
|
|
|
|
cpu_to_le32(NES_IWARP_SQ_OP_RDMAW);
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] = 0;
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] = 0;
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEND_RDMA_READ_ZERO:
|
|
|
|
default:
|
2012-11-03 10:58:37 +00:00
|
|
|
if (cm_node->send_rdma0_op != SEND_RDMA_READ_ZERO)
|
|
|
|
WARN(1, "Unsupported RDMA0 len operation=%u\n",
|
|
|
|
cm_node->send_rdma0_op);
|
2011-09-25 14:47:46 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Sending first rdma operation.\n");
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
|
|
|
|
cpu_to_le32(NES_IWARP_SQ_OP_RDMAR);
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX] = 1;
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_TO_HIGH_IDX] = 0;
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX] = 0;
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_RDMA_STAG_IDX] = 1;
|
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nesqp->sq_kmapped) {
|
|
|
|
nesqp->sq_kmapped = 0;
|
|
|
|
kunmap(nesqp->page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*use the reserved spot on the WQ for the extra first WQE*/
|
|
|
|
nesqp->nesqp_context->ird_ord_sizes &= cpu_to_le32(~(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
|
|
|
|
NES_QPCONTEXT_ORDIRD_WRPDU |
|
|
|
|
NES_QPCONTEXT_ORDIRD_ALSMM));
|
|
|
|
nesqp->skip_lsmm = 1;
|
|
|
|
nesqp->hwqp.sq_tail = 0;
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* schedule_nes_timer
|
|
|
|
* note - cm_node needs to be protected before calling this. Encase in:
|
|
|
|
* rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
|
|
|
|
*/
|
|
|
|
int schedule_nes_timer(struct nes_cm_node *cm_node, struct sk_buff *skb,
|
2011-09-25 14:47:46 +00:00
|
|
|
enum nes_timer_type type, int send_retrans,
|
|
|
|
int close_when_complete)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2011-09-25 14:47:46 +00:00
|
|
|
unsigned long flags;
|
2008-07-25 03:50:45 +00:00
|
|
|
struct nes_cm_core *cm_core = cm_node->cm_core;
|
2008-02-05 04:20:45 +00:00
|
|
|
struct nes_timer_entry *new_send;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
new_send = kzalloc(sizeof(*new_send), GFP_ATOMIC);
|
|
|
|
if (!new_send)
|
2009-03-06 23:15:01 +00:00
|
|
|
return -ENOMEM;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* new_send->timetosend = currenttime */
|
|
|
|
new_send->retrycount = NES_DEFAULT_RETRYS;
|
|
|
|
new_send->retranscount = NES_DEFAULT_RETRANS;
|
|
|
|
new_send->skb = skb;
|
|
|
|
new_send->timetosend = jiffies;
|
|
|
|
new_send->type = type;
|
|
|
|
new_send->netdev = cm_node->netdev;
|
|
|
|
new_send->send_retrans = send_retrans;
|
|
|
|
new_send->close_when_complete = close_when_complete;
|
|
|
|
|
|
|
|
if (type == NES_TIMER_TYPE_CLOSE) {
|
2011-09-25 14:47:46 +00:00
|
|
|
new_send->timetosend += (HZ / 10);
|
2009-03-06 23:15:01 +00:00
|
|
|
if (cm_node->recv_entry) {
|
2009-04-08 21:22:20 +00:00
|
|
|
kfree(new_send);
|
2009-03-06 23:15:01 +00:00
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
cm_node->recv_entry = new_send;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type == NES_TIMER_TYPE_SEND) {
|
2008-04-17 04:01:07 +00:00
|
|
|
new_send->seq_num = ntohl(tcp_hdr(skb)->seq);
|
2017-06-30 10:07:58 +00:00
|
|
|
refcount_inc(&new_send->skb->users);
|
2008-07-25 03:50:45 +00:00
|
|
|
spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
|
|
|
|
cm_node->send_entry = new_send;
|
|
|
|
add_ref_cm_node(cm_node);
|
|
|
|
spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
|
|
|
|
new_send->timetosend = jiffies + NES_RETRY_TIMEOUT;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
ret = nes_nic_cm_xmit(new_send->skb, cm_node->netdev);
|
|
|
|
if (ret != NETDEV_TX_OK) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Error sending packet %p "
|
2011-09-25 14:47:46 +00:00
|
|
|
"(jiffies = %lu)\n", new_send, jiffies);
|
2008-02-05 04:20:45 +00:00
|
|
|
new_send->timetosend = jiffies;
|
2009-04-08 21:23:55 +00:00
|
|
|
ret = NETDEV_TX_OK;
|
2008-02-05 04:20:45 +00:00
|
|
|
} else {
|
|
|
|
cm_packets_sent++;
|
|
|
|
if (!send_retrans) {
|
2008-07-25 03:50:45 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (close_when_complete)
|
2008-07-25 03:50:45 +00:00
|
|
|
rem_ref_cm_node(cm_core, cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-06 19:56:31 +00:00
|
|
|
if (!timer_pending(&cm_core->tcp_timer))
|
|
|
|
mod_timer(&cm_core->tcp_timer, new_send->timetosend);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
static void nes_retrans_expired(struct nes_cm_node *cm_node)
|
|
|
|
{
|
2009-06-23 05:53:28 +00:00
|
|
|
struct iw_cm_id *cm_id = cm_node->cm_id;
|
2010-08-14 21:04:56 +00:00
|
|
|
enum nes_cm_node_state state = cm_node->state;
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2010-08-14 21:04:56 +00:00
|
|
|
switch (state) {
|
2009-03-06 23:15:01 +00:00
|
|
|
case NES_CM_STATE_SYN_RCVD:
|
|
|
|
case NES_CM_STATE_CLOSING:
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_LAST_ACK:
|
|
|
|
case NES_CM_STATE_FIN_WAIT1:
|
2009-06-23 05:53:28 +00:00
|
|
|
if (cm_node->cm_id)
|
|
|
|
cm_id->rem_ref(cm_id);
|
2009-03-06 23:15:01 +00:00
|
|
|
send_reset(cm_node, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
2009-12-09 23:54:03 +00:00
|
|
|
add_ref_cm_node(cm_node);
|
|
|
|
send_reset(cm_node, NULL);
|
2009-03-06 23:15:01 +00:00
|
|
|
create_event(cm_node, NES_CM_EVENT_ABORTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node)
|
|
|
|
{
|
|
|
|
struct nes_timer_entry *recv_entry = cm_node->recv_entry;
|
|
|
|
struct iw_cm_id *cm_id = cm_node->cm_id;
|
|
|
|
struct nes_qp *nesqp;
|
|
|
|
unsigned long qplockflags;
|
|
|
|
|
|
|
|
if (!recv_entry)
|
|
|
|
return;
|
|
|
|
nesqp = (struct nes_qp *)recv_entry->skb;
|
|
|
|
if (nesqp) {
|
|
|
|
spin_lock_irqsave(&nesqp->lock, qplockflags);
|
|
|
|
if (nesqp->cm_id) {
|
|
|
|
nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"refcount = %d: HIT A "
|
|
|
|
"NES_TIMER_TYPE_CLOSE with something "
|
|
|
|
"to do!!!\n", nesqp->hwqp.qp_id, cm_id,
|
|
|
|
atomic_read(&nesqp->refcount));
|
2009-03-06 23:15:01 +00:00
|
|
|
nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
|
|
|
|
nesqp->last_aeq = NES_AEQE_AEID_RESET_SENT;
|
|
|
|
nesqp->ibqp_state = IB_QPS_ERR;
|
|
|
|
spin_unlock_irqrestore(&nesqp->lock, qplockflags);
|
|
|
|
nes_cm_disconn(nesqp);
|
|
|
|
} else {
|
|
|
|
spin_unlock_irqrestore(&nesqp->lock, qplockflags);
|
|
|
|
nes_debug(NES_DBG_CM, "QP%u: cm_id = %p, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"refcount = %d: HIT A "
|
|
|
|
"NES_TIMER_TYPE_CLOSE with nothing "
|
|
|
|
"to do!!!\n", nesqp->hwqp.qp_id, cm_id,
|
|
|
|
atomic_read(&nesqp->refcount));
|
2009-03-06 23:15:01 +00:00
|
|
|
}
|
|
|
|
} else if (rem_node) {
|
|
|
|
/* TIME_WAIT state */
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
}
|
|
|
|
if (cm_node->cm_id)
|
|
|
|
cm_id->rem_ref(cm_id);
|
|
|
|
kfree(recv_entry);
|
|
|
|
cm_node->recv_entry = NULL;
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_timer_tick
|
|
|
|
*/
|
2017-10-05 00:45:27 +00:00
|
|
|
static void nes_cm_timer_tick(struct timer_list *unused)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2009-03-06 23:15:01 +00:00
|
|
|
unsigned long flags;
|
2008-02-05 04:20:45 +00:00
|
|
|
unsigned long nexttimeout = jiffies + NES_LONG_TIME;
|
|
|
|
struct nes_cm_node *cm_node;
|
|
|
|
struct nes_timer_entry *send_entry, *recv_entry;
|
2009-03-06 23:15:01 +00:00
|
|
|
struct list_head *list_core_temp;
|
|
|
|
struct list_head *list_node;
|
2008-02-05 04:20:45 +00:00
|
|
|
struct nes_cm_core *cm_core = g_cm_core;
|
|
|
|
u32 settimer = 0;
|
2009-04-27 20:39:36 +00:00
|
|
|
unsigned long timetosend;
|
2008-02-05 04:20:45 +00:00
|
|
|
int ret = NETDEV_TX_OK;
|
|
|
|
|
2008-11-22 02:50:41 +00:00
|
|
|
struct list_head timer_list;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2008-11-22 02:50:41 +00:00
|
|
|
INIT_LIST_HEAD(&timer_list);
|
2008-02-05 04:20:45 +00:00
|
|
|
spin_lock_irqsave(&cm_core->ht_lock, flags);
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
list_for_each_safe(list_node, list_core_temp,
|
2011-09-25 14:47:46 +00:00
|
|
|
&cm_core->connected_nodes) {
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node = container_of(list_node, struct nes_cm_node, list);
|
2009-03-06 23:15:01 +00:00
|
|
|
if ((cm_node->recv_entry) || (cm_node->send_entry)) {
|
2008-11-22 02:50:41 +00:00
|
|
|
add_ref_cm_node(cm_node);
|
|
|
|
list_add(&cm_node->timer_entry, &timer_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cm_core->ht_lock, flags);
|
|
|
|
|
|
|
|
list_for_each_safe(list_node, list_core_temp, &timer_list) {
|
|
|
|
cm_node = container_of(list_node, struct nes_cm_node,
|
2011-09-25 14:47:46 +00:00
|
|
|
timer_entry);
|
2009-03-06 23:15:01 +00:00
|
|
|
recv_entry = cm_node->recv_entry;
|
|
|
|
|
|
|
|
if (recv_entry) {
|
2008-07-25 03:50:45 +00:00
|
|
|
if (time_after(recv_entry->timetosend, jiffies)) {
|
|
|
|
if (nexttimeout > recv_entry->timetosend ||
|
2011-09-25 14:47:46 +00:00
|
|
|
!settimer) {
|
2008-02-05 04:20:45 +00:00
|
|
|
nexttimeout = recv_entry->timetosend;
|
|
|
|
settimer = 1;
|
|
|
|
}
|
2011-09-25 14:47:46 +00:00
|
|
|
} else {
|
2009-03-06 23:15:01 +00:00
|
|
|
handle_recv_entry(cm_node, 1);
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
|
2008-07-25 03:50:45 +00:00
|
|
|
do {
|
|
|
|
send_entry = cm_node->send_entry;
|
|
|
|
if (!send_entry)
|
2008-11-22 02:50:38 +00:00
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
if (time_after(send_entry->timetosend, jiffies)) {
|
|
|
|
if (cm_node->state != NES_CM_STATE_TSA) {
|
2008-07-25 03:50:45 +00:00
|
|
|
if ((nexttimeout >
|
2011-09-25 14:47:46 +00:00
|
|
|
send_entry->timetosend) ||
|
|
|
|
!settimer) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nexttimeout =
|
|
|
|
send_entry->timetosend;
|
2008-02-05 04:20:45 +00:00
|
|
|
settimer = 1;
|
|
|
|
}
|
|
|
|
} else {
|
2008-07-25 03:50:45 +00:00
|
|
|
free_retrans_entry(cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2009-03-06 23:15:01 +00:00
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
if ((cm_node->state == NES_CM_STATE_TSA) ||
|
2011-09-25 14:47:46 +00:00
|
|
|
(cm_node->state == NES_CM_STATE_CLOSED)) {
|
2008-07-25 03:50:45 +00:00
|
|
|
free_retrans_entry(cm_node);
|
2008-11-22 02:50:38 +00:00
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (!send_entry->retranscount ||
|
2011-09-25 14:47:46 +00:00
|
|
|
!send_entry->retrycount) {
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_packets_dropped++;
|
2008-07-25 03:50:45 +00:00
|
|
|
free_retrans_entry(cm_node);
|
2009-03-06 23:15:01 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
spin_unlock_irqrestore(
|
|
|
|
&cm_node->retrans_list_lock, flags);
|
2009-03-06 23:15:01 +00:00
|
|
|
nes_retrans_expired(cm_node);
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
2008-07-25 03:50:45 +00:00
|
|
|
spin_lock_irqsave(&cm_node->retrans_list_lock,
|
2011-09-25 14:47:46 +00:00
|
|
|
flags);
|
2008-11-22 02:50:38 +00:00
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2017-06-30 10:07:58 +00:00
|
|
|
refcount_inc(&send_entry->skb->users);
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_packets_retrans++;
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Retransmitting send_entry %p "
|
2011-09-25 14:47:46 +00:00
|
|
|
"for node %p, jiffies = %lu, time to send = "
|
|
|
|
"%lu, retranscount = %u, send_entry->seq_num = "
|
|
|
|
"0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
|
|
|
|
"0x%08X\n", send_entry, cm_node, jiffies,
|
|
|
|
send_entry->timetosend,
|
|
|
|
send_entry->retranscount,
|
|
|
|
send_entry->seq_num,
|
|
|
|
cm_node->tcp_cntxt.rem_ack_num);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cm_node->retrans_list_lock,
|
2011-09-25 14:47:46 +00:00
|
|
|
flags);
|
2008-02-05 04:20:45 +00:00
|
|
|
ret = nes_nic_cm_xmit(send_entry->skb, cm_node->netdev);
|
2008-07-25 03:50:45 +00:00
|
|
|
spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (ret != NETDEV_TX_OK) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "rexmit failed for "
|
2011-09-25 14:47:46 +00:00
|
|
|
"node=%p\n", cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_packets_bounced++;
|
|
|
|
send_entry->retrycount--;
|
|
|
|
nexttimeout = jiffies + NES_SHORT_TIME;
|
|
|
|
settimer = 1;
|
2008-11-22 02:50:38 +00:00
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
} else {
|
|
|
|
cm_packets_sent++;
|
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Packet Sent: retrans count = "
|
2011-09-25 14:47:46 +00:00
|
|
|
"%u, retry count = %u.\n",
|
|
|
|
send_entry->retranscount,
|
|
|
|
send_entry->retrycount);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (send_entry->send_retrans) {
|
|
|
|
send_entry->retranscount--;
|
2009-04-27 20:39:36 +00:00
|
|
|
timetosend = (NES_RETRY_TIMEOUT <<
|
2011-09-25 14:47:46 +00:00
|
|
|
(NES_DEFAULT_RETRANS - send_entry->retranscount));
|
2009-04-27 20:39:36 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
send_entry->timetosend = jiffies +
|
2011-09-25 14:47:46 +00:00
|
|
|
min(timetosend, NES_MAX_TIMEOUT);
|
2008-07-25 03:50:45 +00:00
|
|
|
if (nexttimeout > send_entry->timetosend ||
|
2011-09-25 14:47:46 +00:00
|
|
|
!settimer) {
|
2008-02-05 04:20:45 +00:00
|
|
|
nexttimeout = send_entry->timetosend;
|
|
|
|
settimer = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int close_when_complete;
|
2008-07-25 03:50:45 +00:00
|
|
|
close_when_complete =
|
|
|
|
send_entry->close_when_complete;
|
|
|
|
nes_debug(NES_DBG_CM, "cm_node=%p state=%d\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node, cm_node->state);
|
2008-07-25 03:50:45 +00:00
|
|
|
free_retrans_entry(cm_node);
|
|
|
|
if (close_when_complete)
|
|
|
|
rem_ref_cm_node(cm_node->cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
} while (0);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (settimer) {
|
2012-12-06 19:56:31 +00:00
|
|
|
if (!timer_pending(&cm_core->tcp_timer))
|
|
|
|
mod_timer(&cm_core->tcp_timer, nexttimeout);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send_syn
|
|
|
|
*/
|
2008-07-25 03:50:45 +00:00
|
|
|
static int send_syn(struct nes_cm_node *cm_node, u32 sendack,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct sk_buff *skb)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int flags = SET_SYN;
|
|
|
|
char optionsbuffer[sizeof(struct option_mss) +
|
2011-09-25 14:47:46 +00:00
|
|
|
sizeof(struct option_windowscale) + sizeof(struct option_base) +
|
|
|
|
TCP_OPTIONS_PADDING];
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
int optionssize = 0;
|
|
|
|
/* Sending MSS option */
|
|
|
|
union all_known_options *options;
|
|
|
|
|
|
|
|
if (!cm_node)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
options = (union all_known_options *)&optionsbuffer[optionssize];
|
|
|
|
options->as_mss.optionnum = OPTION_NUMBER_MSS;
|
|
|
|
options->as_mss.length = sizeof(struct option_mss);
|
|
|
|
options->as_mss.mss = htons(cm_node->tcp_cntxt.mss);
|
|
|
|
optionssize += sizeof(struct option_mss);
|
|
|
|
|
|
|
|
options = (union all_known_options *)&optionsbuffer[optionssize];
|
|
|
|
options->as_windowscale.optionnum = OPTION_NUMBER_WINDOW_SCALE;
|
|
|
|
options->as_windowscale.length = sizeof(struct option_windowscale);
|
|
|
|
options->as_windowscale.shiftcount = cm_node->tcp_cntxt.rcv_wscale;
|
|
|
|
optionssize += sizeof(struct option_windowscale);
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (sendack && !(NES_DRV_OPT_SUPRESS_OPTION_BC & nes_drv_opt)) {
|
2008-02-05 04:20:45 +00:00
|
|
|
options = (union all_known_options *)&optionsbuffer[optionssize];
|
|
|
|
options->as_base.optionnum = OPTION_NUMBER_WRITE0;
|
|
|
|
options->as_base.length = sizeof(struct option_base);
|
|
|
|
optionssize += sizeof(struct option_base);
|
|
|
|
/* we need the size to be a multiple of 4 */
|
|
|
|
options = (union all_known_options *)&optionsbuffer[optionssize];
|
|
|
|
options->as_end = 1;
|
|
|
|
optionssize += 1;
|
|
|
|
options = (union all_known_options *)&optionsbuffer[optionssize];
|
|
|
|
options->as_end = 1;
|
|
|
|
optionssize += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
options = (union all_known_options *)&optionsbuffer[optionssize];
|
|
|
|
options->as_end = OPTION_NUMBER_END;
|
|
|
|
optionssize += 1;
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (!skb)
|
2008-12-25 04:30:04 +00:00
|
|
|
skb = dev_alloc_skb(MAX_CM_BUFFER);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (!skb) {
|
|
|
|
nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendack)
|
|
|
|
flags |= SET_ACK;
|
|
|
|
|
|
|
|
form_cm_frame(skb, cm_node, optionsbuffer, optionssize, NULL, 0, flags);
|
|
|
|
ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send_reset
|
|
|
|
*/
|
2008-07-25 03:50:45 +00:00
|
|
|
static int send_reset(struct nes_cm_node *cm_node, struct sk_buff *skb)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int flags = SET_RST | SET_ACK;
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (!skb)
|
2008-12-25 04:30:04 +00:00
|
|
|
skb = dev_alloc_skb(MAX_CM_BUFFER);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (!skb) {
|
|
|
|
nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
|
2009-03-06 23:15:01 +00:00
|
|
|
return -ENOMEM;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, flags);
|
|
|
|
ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send_ack
|
|
|
|
*/
|
2008-07-25 03:50:45 +00:00
|
|
|
static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
if (!skb)
|
2008-12-25 04:30:04 +00:00
|
|
|
skb = dev_alloc_skb(MAX_CM_BUFFER);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (!skb) {
|
|
|
|
nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK);
|
|
|
|
ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send_fin
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* if we didn't get a frame get one */
|
|
|
|
if (!skb)
|
2008-12-25 04:30:04 +00:00
|
|
|
skb = dev_alloc_skb(MAX_CM_BUFFER);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (!skb) {
|
|
|
|
nes_debug(NES_DBG_CM, "Failed to get a Free pkt\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK | SET_FIN);
|
|
|
|
ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find_node - find a cm node that matches the reference cm node
|
|
|
|
*/
|
|
|
|
static struct nes_cm_node *find_node(struct nes_cm_core *cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
u16 rem_port, nes_addr_t rem_addr, u16 loc_port, nes_addr_t loc_addr)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct list_head *hte;
|
|
|
|
struct nes_cm_node *cm_node;
|
|
|
|
|
|
|
|
/* get a handle on the hte */
|
|
|
|
hte = &cm_core->connected_nodes;
|
|
|
|
|
|
|
|
/* walk list and find cm_node associated with this session ID */
|
|
|
|
spin_lock_irqsave(&cm_core->ht_lock, flags);
|
2008-04-17 04:09:26 +00:00
|
|
|
list_for_each_entry(cm_node, hte, list) {
|
2008-02-05 04:20:45 +00:00
|
|
|
/* compare quad, return node handle if a match */
|
|
|
|
nes_debug(NES_DBG_CM, "finding node %x:%x =? %x:%x ^ %x:%x =? %x:%x\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->loc_addr, cm_node->loc_port,
|
|
|
|
loc_addr, loc_port,
|
|
|
|
cm_node->rem_addr, cm_node->rem_port,
|
|
|
|
rem_addr, rem_port);
|
2016-02-26 15:18:02 +00:00
|
|
|
if ((cm_node->loc_addr == loc_addr) &&
|
|
|
|
(cm_node->loc_port == loc_port) &&
|
|
|
|
(cm_node->rem_addr == rem_addr) &&
|
|
|
|
(cm_node->rem_port == rem_port)) {
|
2008-02-05 04:20:45 +00:00
|
|
|
add_ref_cm_node(cm_node);
|
|
|
|
spin_unlock_irqrestore(&cm_core->ht_lock, flags);
|
|
|
|
return cm_node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cm_core->ht_lock, flags);
|
|
|
|
|
|
|
|
/* no owner node */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find_listener - find a cm node listening on this addr-port pair
|
|
|
|
*/
|
|
|
|
static struct nes_cm_listener *find_listener(struct nes_cm_core *cm_core,
|
2016-02-26 15:18:02 +00:00
|
|
|
nes_addr_t dst_addr, u16 dst_port,
|
|
|
|
enum nes_cm_listener_state listener_state)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct nes_cm_listener *listen_node;
|
2014-03-26 22:07:57 +00:00
|
|
|
nes_addr_t listen_addr;
|
|
|
|
u16 listen_port;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* walk list and find cm_node associated with this session ID */
|
|
|
|
spin_lock_irqsave(&cm_core->listen_list_lock, flags);
|
2008-04-17 04:09:26 +00:00
|
|
|
list_for_each_entry(listen_node, &cm_core->listen_list.list, list) {
|
2016-02-26 15:18:02 +00:00
|
|
|
listen_addr = listen_node->loc_addr;
|
|
|
|
listen_port = listen_node->loc_port;
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
/* compare node pair, return node handle if a match */
|
2014-03-26 22:07:57 +00:00
|
|
|
if (((listen_addr == dst_addr) ||
|
|
|
|
listen_addr == 0x00000000) &&
|
|
|
|
(listen_port == dst_port) &&
|
2011-09-25 14:47:46 +00:00
|
|
|
(listener_state & listen_node->listener_state)) {
|
2008-02-05 04:20:45 +00:00
|
|
|
atomic_inc(&listen_node->ref_count);
|
|
|
|
spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
|
|
|
|
return listen_node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
|
|
|
|
|
|
|
|
/* no listener */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add_hte_node - add a cm node to the hash table
|
|
|
|
*/
|
|
|
|
static int add_hte_node(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct list_head *hte;
|
|
|
|
|
|
|
|
if (!cm_node || !cm_core)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Adding Node %p to Active Connection HT\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&cm_core->ht_lock, flags);
|
|
|
|
|
|
|
|
/* get a handle on the hash table element (list head for this slot) */
|
|
|
|
hte = &cm_core->connected_nodes;
|
|
|
|
list_add_tail(&cm_node->list, hte);
|
|
|
|
atomic_inc(&cm_core->ht_node_cnt);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cm_core->ht_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_dec_refcnt_listen
|
|
|
|
*/
|
|
|
|
static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_cm_listener *listener, int free_hanging_nodes)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2009-03-06 23:15:01 +00:00
|
|
|
int ret = -EINVAL;
|
|
|
|
int err = 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
unsigned long flags;
|
2008-07-25 03:50:45 +00:00
|
|
|
struct list_head *list_pos = NULL;
|
|
|
|
struct list_head *list_temp = NULL;
|
|
|
|
struct nes_cm_node *cm_node = NULL;
|
2008-11-22 02:50:41 +00:00
|
|
|
struct list_head reset_list;
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "attempting listener= %p free_nodes= %d, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"refcnt=%d\n", listener, free_hanging_nodes,
|
|
|
|
atomic_read(&listener->ref_count));
|
2008-07-25 03:50:45 +00:00
|
|
|
/* free non-accelerated child nodes for this listener */
|
2008-11-22 02:50:41 +00:00
|
|
|
INIT_LIST_HEAD(&reset_list);
|
2008-07-25 03:50:45 +00:00
|
|
|
if (free_hanging_nodes) {
|
|
|
|
spin_lock_irqsave(&cm_core->ht_lock, flags);
|
|
|
|
list_for_each_safe(list_pos, list_temp,
|
2008-11-22 02:50:41 +00:00
|
|
|
&g_cm_core->connected_nodes) {
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node = container_of(list_pos, struct nes_cm_node,
|
2011-09-25 14:47:46 +00:00
|
|
|
list);
|
2008-07-25 03:50:45 +00:00
|
|
|
if ((cm_node->listener == listener) &&
|
2008-11-22 02:50:41 +00:00
|
|
|
(!cm_node->accelerated)) {
|
|
|
|
add_ref_cm_node(cm_node);
|
|
|
|
list_add(&cm_node->reset_entry, &reset_list);
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cm_core->ht_lock, flags);
|
|
|
|
}
|
2008-11-22 02:50:41 +00:00
|
|
|
|
|
|
|
list_for_each_safe(list_pos, list_temp, &reset_list) {
|
|
|
|
cm_node = container_of(list_pos, struct nes_cm_node,
|
2011-09-25 14:47:46 +00:00
|
|
|
reset_entry);
|
2009-03-06 23:15:01 +00:00
|
|
|
{
|
|
|
|
struct nes_cm_node *loopback = cm_node->loopbackpartner;
|
2009-12-09 23:54:08 +00:00
|
|
|
enum nes_cm_node_state old_state;
|
2009-03-06 23:15:01 +00:00
|
|
|
if (NES_CM_STATE_FIN_WAIT1 <= cm_node->state) {
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
} else {
|
|
|
|
if (!loopback) {
|
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
err = send_reset(cm_node, NULL);
|
|
|
|
if (err) {
|
|
|
|
cm_node->state =
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_CM_STATE_CLOSED;
|
2009-03-06 23:15:01 +00:00
|
|
|
WARN_ON(1);
|
|
|
|
} else {
|
2009-12-09 23:54:08 +00:00
|
|
|
old_state = cm_node->state;
|
|
|
|
cm_node->state = NES_CM_STATE_LISTENER_DESTROYED;
|
|
|
|
if (old_state != NES_CM_STATE_MPAREQ_RCVD)
|
|
|
|
rem_ref_cm_node(
|
|
|
|
cm_node->cm_core,
|
|
|
|
cm_node);
|
2009-03-06 23:15:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct nes_cm_event event;
|
|
|
|
|
|
|
|
event.cm_node = loopback;
|
|
|
|
event.cm_info.rem_addr =
|
|
|
|
loopback->rem_addr;
|
|
|
|
event.cm_info.loc_addr =
|
|
|
|
loopback->loc_addr;
|
|
|
|
event.cm_info.rem_port =
|
|
|
|
loopback->rem_port;
|
|
|
|
event.cm_info.loc_port =
|
|
|
|
loopback->loc_port;
|
|
|
|
event.cm_info.cm_id = loopback->cm_id;
|
2010-02-12 19:57:04 +00:00
|
|
|
add_ref_cm_node(loopback);
|
|
|
|
loopback->state = NES_CM_STATE_CLOSED;
|
2009-03-06 23:15:01 +00:00
|
|
|
cm_event_connect_error(&event);
|
2009-12-09 23:54:08 +00:00
|
|
|
cm_node->state = NES_CM_STATE_LISTENER_DESTROYED;
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
rem_ref_cm_node(cm_node->cm_core,
|
|
|
|
cm_node);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-22 02:50:41 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
spin_lock_irqsave(&cm_core->listen_list_lock, flags);
|
|
|
|
if (!atomic_dec_return(&listener->ref_count)) {
|
|
|
|
list_del(&listener->list);
|
|
|
|
|
|
|
|
/* decrement our listen node count */
|
|
|
|
atomic_dec(&cm_core->listen_node_cnt);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
|
|
|
|
|
2014-03-26 22:07:57 +00:00
|
|
|
if (listener->nesvnic) {
|
|
|
|
nes_manage_apbvt(listener->nesvnic,
|
2016-02-26 15:18:02 +00:00
|
|
|
listener->loc_port,
|
2014-03-26 22:07:57 +00:00
|
|
|
PCI_FUNC(listener->nesvnic->nesdev->pcidev->devfn),
|
|
|
|
NES_MANAGE_APBVT_DEL);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_NLMSG,
|
2016-02-26 15:18:02 +00:00
|
|
|
"Delete APBVT loc_port = %04X\n",
|
|
|
|
listener->loc_port);
|
2014-03-26 22:07:57 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "destroying listener (%p)\n", listener);
|
|
|
|
|
|
|
|
kfree(listener);
|
2008-02-21 14:27:32 +00:00
|
|
|
listener = NULL;
|
2008-02-05 04:20:45 +00:00
|
|
|
ret = 0;
|
2010-02-12 19:55:03 +00:00
|
|
|
atomic_inc(&cm_listens_destroyed);
|
2008-02-05 04:20:45 +00:00
|
|
|
} else {
|
|
|
|
spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
|
|
|
|
}
|
|
|
|
if (listener) {
|
|
|
|
if (atomic_read(&listener->pend_accepts_cnt) > 0)
|
|
|
|
nes_debug(NES_DBG_CM, "destroying listener (%p)"
|
2011-09-25 14:47:46 +00:00
|
|
|
" with non-zero pending accepts=%u\n",
|
|
|
|
listener, atomic_read(&listener->pend_accepts_cnt));
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_del_listen
|
|
|
|
*/
|
|
|
|
static int mini_cm_del_listen(struct nes_cm_core *cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_cm_listener *listener)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
listener->listener_state = NES_CM_LISTENER_PASSIVE_STATE;
|
|
|
|
listener->cm_id = NULL; /* going to be destroyed pretty soon */
|
|
|
|
return mini_cm_dec_refcnt_listen(cm_core, listener, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_accelerated
|
|
|
|
*/
|
|
|
|
static inline int mini_cm_accelerated(struct nes_cm_core *cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_cm_node *cm_node)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2017-12-17 18:21:38 +00:00
|
|
|
cm_node->accelerated = true;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (cm_node->accept_pend) {
|
|
|
|
BUG_ON(!cm_node->listener);
|
|
|
|
atomic_dec(&cm_node->listener->pend_accepts_cnt);
|
2009-03-06 23:15:01 +00:00
|
|
|
cm_node->accept_pend = 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
|
|
|
|
}
|
|
|
|
|
2012-12-06 19:56:31 +00:00
|
|
|
if (!timer_pending(&cm_core->tcp_timer))
|
|
|
|
mod_timer(&cm_core->tcp_timer, (jiffies + NES_SHORT_TIME));
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-10-03 19:21:19 +00:00
|
|
|
* nes_addr_resolve_neigh
|
2008-02-05 04:20:45 +00:00
|
|
|
*/
|
2009-12-09 23:54:33 +00:00
|
|
|
static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpindex)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct rtable *rt;
|
2008-10-03 19:21:19 +00:00
|
|
|
struct neighbour *neigh;
|
2009-12-09 23:54:33 +00:00
|
|
|
int rc = arpindex;
|
|
|
|
struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
|
2015-07-02 17:49:40 +00:00
|
|
|
__be32 dst_ipaddr = htonl(dst_ip);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2015-07-02 17:49:40 +00:00
|
|
|
rt = ip_route_output(&init_net, dst_ipaddr, nesvnic->local_ipaddr, 0, 0);
|
2011-03-02 22:31:35 +00:00
|
|
|
if (IS_ERR(rt)) {
|
2009-03-06 23:15:01 +00:00
|
|
|
printk(KERN_ERR "%s: ip_route_output_key failed for 0x%08X\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
__func__, dst_ip);
|
2008-10-03 19:21:19 +00:00
|
|
|
return rc;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 17:49:40 +00:00
|
|
|
neigh = dst_neigh_lookup(&rt->dst, &dst_ipaddr);
|
2012-01-24 13:16:03 +00:00
|
|
|
|
2011-12-02 16:52:27 +00:00
|
|
|
rcu_read_lock();
|
2008-10-03 19:21:19 +00:00
|
|
|
if (neigh) {
|
|
|
|
if (neigh->nud_state & NUD_VALID) {
|
|
|
|
nes_debug(NES_DBG_CM, "Neighbor MAC address for 0x%08X"
|
2008-10-27 22:59:26 +00:00
|
|
|
" is %pM, Gateway is 0x%08X \n", dst_ip,
|
|
|
|
neigh->ha, ntohl(rt->rt_gateway));
|
2009-12-09 23:54:33 +00:00
|
|
|
|
|
|
|
if (arpindex >= 0) {
|
2014-01-08 02:53:39 +00:00
|
|
|
if (ether_addr_equal(nesadapter->arp_table[arpindex].mac_addr, neigh->ha)) {
|
2009-12-09 23:54:33 +00:00
|
|
|
/* Mac address same as in nes_arp_table */
|
2012-01-24 13:16:03 +00:00
|
|
|
goto out;
|
2009-12-09 23:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nes_manage_arp_cache(nesvnic->netdev,
|
2011-09-25 14:47:46 +00:00
|
|
|
nesadapter->arp_table[arpindex].mac_addr,
|
|
|
|
dst_ip, NES_ARP_DELETE);
|
2009-12-09 23:54:33 +00:00
|
|
|
}
|
|
|
|
|
2008-10-03 19:21:19 +00:00
|
|
|
nes_manage_arp_cache(nesvnic->netdev, neigh->ha,
|
|
|
|
dst_ip, NES_ARP_ADD);
|
|
|
|
rc = nes_arp_table(nesvnic->nesdev, dst_ip, NULL,
|
|
|
|
NES_ARP_RESOLVE);
|
2011-12-02 16:52:27 +00:00
|
|
|
} else {
|
|
|
|
neigh_event_send(neigh, NULL);
|
2008-10-03 19:21:19 +00:00
|
|
|
}
|
2011-11-29 21:31:23 +00:00
|
|
|
}
|
2012-01-24 13:16:03 +00:00
|
|
|
out:
|
2011-12-02 16:52:27 +00:00
|
|
|
rcu_read_unlock();
|
2012-01-24 13:16:03 +00:00
|
|
|
|
|
|
|
if (neigh)
|
|
|
|
neigh_release(neigh);
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
ip_rt_put(rt);
|
2008-10-03 19:21:19 +00:00
|
|
|
return rc;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* make_cm_node - create a new instance of a cm node
|
|
|
|
*/
|
|
|
|
static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_vnic *nesvnic, struct nes_cm_info *cm_info,
|
|
|
|
struct nes_cm_listener *listener)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct nes_cm_node *cm_node;
|
2009-12-09 23:54:33 +00:00
|
|
|
int oldarpindex = 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
int arpindex = 0;
|
|
|
|
struct nes_device *nesdev;
|
|
|
|
struct nes_adapter *nesadapter;
|
|
|
|
|
|
|
|
/* create an hte and cm_node for this instance */
|
|
|
|
cm_node = kzalloc(sizeof(*cm_node), GFP_ATOMIC);
|
|
|
|
if (!cm_node)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* set our node specific transport info */
|
2015-04-21 20:28:25 +00:00
|
|
|
if (listener) {
|
|
|
|
cm_node->loc_addr = listener->loc_addr;
|
|
|
|
cm_node->loc_port = listener->loc_port;
|
|
|
|
} else {
|
|
|
|
cm_node->loc_addr = cm_info->loc_addr;
|
|
|
|
cm_node->loc_port = cm_info->loc_port;
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->rem_addr = cm_info->rem_addr;
|
|
|
|
cm_node->rem_port = cm_info->rem_port;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
|
|
|
cm_node->mpa_frame_rev = mpa_version;
|
|
|
|
cm_node->send_rdma0_op = SEND_RDMA_READ_ZERO;
|
2014-03-11 19:17:25 +00:00
|
|
|
cm_node->mpav2_ird_ord = 0;
|
|
|
|
cm_node->ird_size = 0;
|
|
|
|
cm_node->ord_size = 0;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2008-10-31 07:56:00 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Make node addresses : loc = %pI4:%x, rem = %pI4:%x\n",
|
|
|
|
&cm_node->loc_addr, cm_node->loc_port,
|
|
|
|
&cm_node->rem_addr, cm_node->rem_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->listener = listener;
|
2015-05-18 20:28:14 +00:00
|
|
|
if (listener)
|
|
|
|
cm_node->tos = listener->tos;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->netdev = nesvnic->netdev;
|
|
|
|
cm_node->cm_id = cm_info->cm_id;
|
|
|
|
memcpy(cm_node->loc_mac, nesvnic->netdev->dev_addr, ETH_ALEN);
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "listener=%p, cm_id=%p\n", cm_node->listener,
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->cm_id);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
spin_lock_init(&cm_node->retrans_list_lock);
|
|
|
|
|
|
|
|
cm_node->loopbackpartner = NULL;
|
|
|
|
atomic_set(&cm_node->ref_count, 1);
|
|
|
|
/* associate our parent CM core */
|
|
|
|
cm_node->cm_core = cm_core;
|
|
|
|
cm_node->tcp_cntxt.loc_id = NES_CM_DEF_LOCAL_ID;
|
|
|
|
cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
|
|
|
|
cm_node->tcp_cntxt.rcv_wnd = NES_CM_DEFAULT_RCV_WND_SCALED >>
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_CM_DEFAULT_RCV_WND_SCALE;
|
infiniband: i40iw, nes: don't use wall time for TCP sequence numbers
The nes infiniband driver uses current_kernel_time() to get a nanosecond
granunarity timestamp to initialize its tcp sequence counters. This is
one of only a few remaining users of that deprecated function, so we
should try to get rid of it.
Aside from using a deprecated API, there are several problems I see here:
- Using a CLOCK_REALTIME based time source makes it predictable in
case the time base is synchronized.
- Using a coarse timestamp means it only gets updated once per jiffie,
making it even more predictable in order to avoid having to access
the hardware clock source
- The upper 2 bits are always zero because the nanoseconds are at most
999999999.
For the Linux TCP implementation, we use secure_tcp_seq(), which appears
to be appropriate here as well, and solves all the above problems.
i40iw uses a variant of the same code, so I do that same thing there
for ipv4. Unlike nes, i40e also supports ipv6, which needs to call
secure_tcpv6_seq instead.
Acked-by: Shiraz Saleem <shiraz.saleem@intel.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
2018-07-09 08:34:43 +00:00
|
|
|
cm_node->tcp_cntxt.loc_seq_num = secure_tcp_seq(htonl(cm_node->loc_addr),
|
|
|
|
htonl(cm_node->rem_addr),
|
|
|
|
htons(cm_node->loc_port),
|
|
|
|
htons(cm_node->rem_port));
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->tcp_cntxt.mss = nesvnic->max_frame_size - sizeof(struct iphdr) -
|
2011-09-25 14:47:46 +00:00
|
|
|
sizeof(struct tcphdr) - ETH_HLEN - VLAN_HLEN;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->tcp_cntxt.rcv_nxt = 0;
|
|
|
|
/* get a unique session ID , add thread_id to an upcounter to handle race */
|
|
|
|
atomic_inc(&cm_core->node_cnt);
|
|
|
|
cm_node->conn_type = cm_info->conn_type;
|
|
|
|
cm_node->apbvt_set = 0;
|
|
|
|
cm_node->accept_pend = 0;
|
|
|
|
|
|
|
|
cm_node->nesvnic = nesvnic;
|
|
|
|
/* get some device handles, for arp lookup */
|
|
|
|
nesdev = nesvnic->nesdev;
|
|
|
|
nesadapter = nesdev->nesadapter;
|
|
|
|
|
|
|
|
cm_node->loopbackpartner = NULL;
|
2009-12-09 23:54:33 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
/* get the mac addr for the remote node */
|
2016-02-26 15:18:02 +00:00
|
|
|
oldarpindex = nes_arp_table(nesdev, cm_node->rem_addr,
|
|
|
|
NULL, NES_ARP_RESOLVE);
|
|
|
|
arpindex = nes_addr_resolve_neigh(nesvnic, cm_node->rem_addr,
|
|
|
|
oldarpindex);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (arpindex < 0) {
|
2009-12-09 23:54:33 +00:00
|
|
|
kfree(cm_node);
|
|
|
|
return NULL;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the mac addr to node context */
|
|
|
|
memcpy(cm_node->rem_mac, nesadapter->arp_table[arpindex].mac_addr, ETH_ALEN);
|
2008-10-27 22:59:26 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Remote mac addr from arp table: %pM\n",
|
|
|
|
cm_node->rem_mac);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
add_hte_node(cm_core, cm_node);
|
|
|
|
atomic_inc(&cm_nodes_created);
|
|
|
|
|
|
|
|
return cm_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add_ref_cm_node - destroy an instance of a cm node
|
|
|
|
*/
|
|
|
|
static int add_ref_cm_node(struct nes_cm_node *cm_node)
|
|
|
|
{
|
|
|
|
atomic_inc(&cm_node->ref_count);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rem_ref_cm_node - destroy an instance of a cm node
|
|
|
|
*/
|
|
|
|
static int rem_ref_cm_node(struct nes_cm_core *cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_cm_node *cm_node)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2009-03-06 23:15:01 +00:00
|
|
|
unsigned long flags;
|
2008-02-05 04:20:45 +00:00
|
|
|
struct nes_qp *nesqp;
|
|
|
|
|
|
|
|
if (!cm_node)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cm_node->cm_core->ht_lock, flags);
|
|
|
|
if (atomic_dec_return(&cm_node->ref_count)) {
|
|
|
|
spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
list_del(&cm_node->list);
|
|
|
|
atomic_dec(&cm_core->ht_node_cnt);
|
|
|
|
spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
|
|
|
|
|
|
|
|
/* if the node is destroyed before connection was accelerated */
|
|
|
|
if (!cm_node->accelerated && cm_node->accept_pend) {
|
|
|
|
BUG_ON(!cm_node->listener);
|
|
|
|
atomic_dec(&cm_node->listener->pend_accepts_cnt);
|
|
|
|
BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
|
|
|
|
}
|
2009-03-06 23:15:01 +00:00
|
|
|
WARN_ON(cm_node->send_entry);
|
|
|
|
if (cm_node->recv_entry)
|
|
|
|
handle_recv_entry(cm_node, 0);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (cm_node->listener) {
|
|
|
|
mini_cm_dec_refcnt_listen(cm_core, cm_node->listener, 0);
|
|
|
|
} else {
|
|
|
|
if (cm_node->apbvt_set && cm_node->nesvnic) {
|
2016-02-26 15:18:02 +00:00
|
|
|
nes_manage_apbvt(cm_node->nesvnic, cm_node->loc_port,
|
2014-03-26 22:07:57 +00:00
|
|
|
PCI_FUNC(cm_node->nesvnic->nesdev->pcidev->devfn),
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_MANAGE_APBVT_DEL);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2016-02-26 15:18:02 +00:00
|
|
|
nes_debug(NES_DBG_NLMSG, "Delete APBVT loc_port = %04X\n",
|
|
|
|
cm_node->loc_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
atomic_dec(&cm_core->node_cnt);
|
|
|
|
atomic_inc(&cm_nodes_destroyed);
|
2008-07-25 03:50:45 +00:00
|
|
|
nesqp = cm_node->nesqp;
|
|
|
|
if (nesqp) {
|
|
|
|
nesqp->cm_node = NULL;
|
|
|
|
nes_rem_ref(&nesqp->ibqp);
|
|
|
|
cm_node->nesqp = NULL;
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
kfree(cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* process_options
|
|
|
|
*/
|
2008-07-25 03:50:45 +00:00
|
|
|
static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
|
2011-09-25 14:47:46 +00:00
|
|
|
u32 optionsize, u32 syn_packet)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
u32 offset = 0;
|
|
|
|
union all_known_options *all_options;
|
|
|
|
char got_mss_option = 0;
|
|
|
|
|
|
|
|
while (offset < optionsize) {
|
|
|
|
all_options = (union all_known_options *)(optionsloc + offset);
|
|
|
|
switch (all_options->as_base.optionnum) {
|
2008-07-25 03:50:45 +00:00
|
|
|
case OPTION_NUMBER_END:
|
|
|
|
offset = optionsize;
|
|
|
|
break;
|
|
|
|
case OPTION_NUMBER_NONE:
|
|
|
|
offset += 1;
|
|
|
|
continue;
|
|
|
|
case OPTION_NUMBER_MSS:
|
|
|
|
nes_debug(NES_DBG_CM, "%s: MSS Length: %d Offset: %d "
|
2011-09-25 14:47:46 +00:00
|
|
|
"Size: %d\n", __func__,
|
|
|
|
all_options->as_mss.length, offset, optionsize);
|
2008-07-25 03:50:45 +00:00
|
|
|
got_mss_option = 1;
|
|
|
|
if (all_options->as_mss.length != 4) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
tmp = ntohs(all_options->as_mss.mss);
|
|
|
|
if (tmp > 0 && tmp <
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->tcp_cntxt.mss)
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->tcp_cntxt.mss = tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OPTION_NUMBER_WINDOW_SCALE:
|
|
|
|
cm_node->tcp_cntxt.snd_wscale =
|
|
|
|
all_options->as_windowscale.shiftcount;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nes_debug(NES_DBG_CM, "TCP Option not understood: %x\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
all_options->as_base.optionnum);
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
offset += all_options->as_base.length;
|
|
|
|
}
|
|
|
|
if ((!got_mss_option) && (syn_packet))
|
|
|
|
cm_node->tcp_cntxt.mss = NES_CM_DEFAULT_MSS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
static void drop_packet(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
atomic_inc(&cm_accel_dropped_pkts);
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
static void handle_fin_pkt(struct nes_cm_node *cm_node)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Received FIN, cm_node = %p, state = %u. "
|
2011-09-25 14:47:46 +00:00
|
|
|
"refcnt=%d\n", cm_node, cm_node->state,
|
|
|
|
atomic_read(&cm_node->ref_count));
|
2008-07-25 03:50:45 +00:00
|
|
|
switch (cm_node->state) {
|
|
|
|
case NES_CM_STATE_SYN_RCVD:
|
|
|
|
case NES_CM_STATE_SYN_SENT:
|
|
|
|
case NES_CM_STATE_ESTABLISHED:
|
2009-03-06 23:15:01 +00:00
|
|
|
case NES_CM_STATE_MPAREJ_RCVD:
|
2009-04-27 20:41:06 +00:00
|
|
|
cm_node->tcp_cntxt.rcv_nxt++;
|
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->state = NES_CM_STATE_LAST_ACK;
|
2009-03-06 23:15:01 +00:00
|
|
|
send_fin(cm_node, NULL);
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
2009-12-09 23:54:32 +00:00
|
|
|
case NES_CM_STATE_MPAREQ_SENT:
|
|
|
|
create_event(cm_node, NES_CM_EVENT_ABORTED);
|
|
|
|
cm_node->tcp_cntxt.rcv_nxt++;
|
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
add_ref_cm_node(cm_node);
|
|
|
|
send_reset(cm_node, NULL);
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_STATE_FIN_WAIT1:
|
2009-04-27 20:41:06 +00:00
|
|
|
cm_node->tcp_cntxt.rcv_nxt++;
|
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->state = NES_CM_STATE_CLOSING;
|
2009-03-06 23:15:01 +00:00
|
|
|
send_ack(cm_node, NULL);
|
2011-03-31 01:57:33 +00:00
|
|
|
/* Wait for ACK as this is simultaneous close..
|
2009-03-06 23:15:01 +00:00
|
|
|
* After we receive ACK, do not send anything..
|
|
|
|
* Just rm the node.. Done.. */
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
case NES_CM_STATE_FIN_WAIT2:
|
2009-04-27 20:41:06 +00:00
|
|
|
cm_node->tcp_cntxt.rcv_nxt++;
|
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->state = NES_CM_STATE_TIME_WAIT;
|
2009-03-06 23:15:01 +00:00
|
|
|
send_ack(cm_node, NULL);
|
|
|
|
schedule_nes_timer(cm_node, NULL, NES_TIMER_TYPE_CLOSE, 1, 0);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_TIME_WAIT:
|
2009-04-27 20:41:06 +00:00
|
|
|
cm_node->tcp_cntxt.rcv_nxt++;
|
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
2009-03-06 23:15:01 +00:00
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
case NES_CM_STATE_TSA:
|
|
|
|
default:
|
|
|
|
nes_debug(NES_DBG_CM, "Error Rcvd FIN for node-%p state = %d\n",
|
|
|
|
cm_node, cm_node->state);
|
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
|
|
|
|
struct tcphdr *tcph)
|
|
|
|
{
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
int reset = 0; /* whether to send reset in case of err.. */
|
|
|
|
atomic_inc(&cm_resets_recvd);
|
|
|
|
nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
|
|
|
|
" refcnt=%d\n", cm_node, cm_node->state,
|
|
|
|
atomic_read(&cm_node->ref_count));
|
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
switch (cm_node->state) {
|
|
|
|
case NES_CM_STATE_SYN_SENT:
|
|
|
|
case NES_CM_STATE_MPAREQ_SENT:
|
|
|
|
nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
|
|
|
|
"listener=%p state=%d\n", __func__, __LINE__, cm_node,
|
|
|
|
cm_node->listener, cm_node->state);
|
2011-09-25 14:47:46 +00:00
|
|
|
switch (cm_node->mpa_frame_rev) {
|
|
|
|
case IETF_MPA_V2:
|
|
|
|
cm_node->mpa_frame_rev = IETF_MPA_V1;
|
|
|
|
/* send a syn and goto syn sent state */
|
|
|
|
cm_node->state = NES_CM_STATE_SYN_SENT;
|
|
|
|
if (send_syn(cm_node, 0, NULL)) {
|
|
|
|
active_open_err(cm_node, skb, reset);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IETF_MPA_V1:
|
|
|
|
default:
|
|
|
|
active_open_err(cm_node, skb, reset);
|
|
|
|
break;
|
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
2008-11-22 02:50:46 +00:00
|
|
|
case NES_CM_STATE_MPAREQ_RCVD:
|
2010-09-15 16:32:39 +00:00
|
|
|
atomic_inc(&cm_node->passive_state);
|
2008-11-22 02:50:46 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_STATE_ESTABLISHED:
|
|
|
|
case NES_CM_STATE_SYN_RCVD:
|
|
|
|
case NES_CM_STATE_LISTENING:
|
|
|
|
nes_debug(NES_DBG_CM, "Bad state %s[%u]\n", __func__, __LINE__);
|
|
|
|
passive_open_err(cm_node, skb, reset);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_TSA:
|
2008-11-22 02:50:46 +00:00
|
|
|
active_open_err(cm_node, skb, reset);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_CLOSED:
|
|
|
|
drop_packet(skb);
|
|
|
|
break;
|
2010-08-14 21:04:56 +00:00
|
|
|
case NES_CM_STATE_FIN_WAIT2:
|
2009-06-23 05:53:28 +00:00
|
|
|
case NES_CM_STATE_FIN_WAIT1:
|
2009-04-27 20:41:06 +00:00
|
|
|
case NES_CM_STATE_LAST_ACK:
|
|
|
|
cm_node->cm_id->rem_ref(cm_node->cm_id);
|
2017-10-11 17:49:10 +00:00
|
|
|
/* fall through */
|
2009-03-06 23:15:01 +00:00
|
|
|
case NES_CM_STATE_TIME_WAIT:
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
drop_packet(skb);
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
default:
|
2008-11-22 02:50:46 +00:00
|
|
|
drop_packet(skb);
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
static void handle_rcv_mpa(struct nes_cm_node *cm_node, struct sk_buff *skb)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
2011-09-25 14:47:46 +00:00
|
|
|
int ret = 0;
|
2008-07-25 03:50:45 +00:00
|
|
|
int datasize = skb->len;
|
|
|
|
u8 *dataloc = skb->data;
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
enum nes_cm_event_type type = NES_CM_EVENT_UNKNOWN;
|
2011-09-25 14:47:46 +00:00
|
|
|
u32 res_type;
|
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
ret = parse_mpa(cm_node, dataloc, &res_type, datasize);
|
|
|
|
if (ret) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "didn't like MPA Request\n");
|
2009-03-06 23:15:01 +00:00
|
|
|
if (cm_node->state == NES_CM_STATE_MPAREQ_SENT) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "%s[%u] create abort for "
|
2011-09-25 14:47:46 +00:00
|
|
|
"cm_node=%p listener=%p state=%d\n", __func__,
|
|
|
|
__LINE__, cm_node, cm_node->listener,
|
|
|
|
cm_node->state);
|
2008-07-25 03:50:45 +00:00
|
|
|
active_open_err(cm_node, skb, 1);
|
|
|
|
} else {
|
|
|
|
passive_open_err(cm_node, skb, 1);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2009-03-06 23:15:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cm_node->state) {
|
|
|
|
case NES_CM_STATE_ESTABLISHED:
|
2011-09-25 14:47:46 +00:00
|
|
|
if (res_type == NES_MPA_REQUEST_REJECT)
|
2009-03-06 23:15:01 +00:00
|
|
|
/*BIG problem as we are receiving the MPA.. So should
|
2011-09-25 14:47:46 +00:00
|
|
|
* not be REJECT.. This is Passive Open.. We can
|
|
|
|
* only receive it Reject for Active Open...*/
|
2009-03-06 23:15:01 +00:00
|
|
|
WARN_ON(1);
|
|
|
|
cm_node->state = NES_CM_STATE_MPAREQ_RCVD;
|
|
|
|
type = NES_CM_EVENT_MPA_REQ;
|
|
|
|
atomic_set(&cm_node->passive_state,
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_PASSIVE_STATE_INDICATED);
|
2009-03-06 23:15:01 +00:00
|
|
|
break;
|
|
|
|
case NES_CM_STATE_MPAREQ_SENT:
|
2009-04-27 20:41:06 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
2009-03-06 23:15:01 +00:00
|
|
|
if (res_type == NES_MPA_REQUEST_REJECT) {
|
|
|
|
type = NES_CM_EVENT_MPA_REJECT;
|
|
|
|
cm_node->state = NES_CM_STATE_MPAREJ_RCVD;
|
|
|
|
} else {
|
|
|
|
type = NES_CM_EVENT_CONNECTED;
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->state = NES_CM_STATE_TSA;
|
2009-03-06 23:15:01 +00:00
|
|
|
}
|
2017-05-10 21:46:40 +00:00
|
|
|
send_ack(cm_node, NULL);
|
2009-03-06 23:15:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON(1);
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
2009-03-06 23:15:01 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
create_event(cm_node, type);
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void indicate_pkt_err(struct nes_cm_node *cm_node, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
switch (cm_node->state) {
|
|
|
|
case NES_CM_STATE_SYN_SENT:
|
|
|
|
case NES_CM_STATE_MPAREQ_SENT:
|
|
|
|
nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
|
2011-09-25 14:47:46 +00:00
|
|
|
"listener=%p state=%d\n", __func__, __LINE__, cm_node,
|
|
|
|
cm_node->listener, cm_node->state);
|
2008-07-25 03:50:45 +00:00
|
|
|
active_open_err(cm_node, skb, 1);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_ESTABLISHED:
|
|
|
|
case NES_CM_STATE_SYN_RCVD:
|
|
|
|
passive_open_err(cm_node, skb, 1);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_TSA:
|
|
|
|
default:
|
|
|
|
drop_packet(skb);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int check_syn(struct nes_cm_node *cm_node, struct tcphdr *tcph,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct sk_buff *skb)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
err = ((ntohl(tcph->ack_seq) == cm_node->tcp_cntxt.loc_seq_num)) ? 0 : 1;
|
2008-07-25 03:50:45 +00:00
|
|
|
if (err)
|
|
|
|
active_open_err(cm_node, skb, 1);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_seq(struct nes_cm_node *cm_node, struct tcphdr *tcph,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct sk_buff *skb)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
u32 seq;
|
|
|
|
u32 ack_seq;
|
|
|
|
u32 loc_seq_num = cm_node->tcp_cntxt.loc_seq_num;
|
|
|
|
u32 rcv_nxt = cm_node->tcp_cntxt.rcv_nxt;
|
|
|
|
u32 rcv_wnd;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
seq = ntohl(tcph->seq);
|
|
|
|
ack_seq = ntohl(tcph->ack_seq);
|
|
|
|
rcv_wnd = cm_node->tcp_cntxt.rcv_wnd;
|
|
|
|
if (ack_seq != loc_seq_num)
|
|
|
|
err = 1;
|
2011-09-25 14:47:46 +00:00
|
|
|
else if (!between(seq, rcv_nxt, (rcv_nxt + rcv_wnd)))
|
2008-07-25 03:50:45 +00:00
|
|
|
err = 1;
|
|
|
|
if (err) {
|
|
|
|
nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
|
2011-09-25 14:47:46 +00:00
|
|
|
"listener=%p state=%d\n", __func__, __LINE__, cm_node,
|
|
|
|
cm_node->listener, cm_node->state);
|
2008-07-25 03:50:45 +00:00
|
|
|
indicate_pkt_err(cm_node, skb);
|
|
|
|
nes_debug(NES_DBG_CM, "seq ERROR cm_node =%p seq=0x%08X "
|
2011-09-25 14:47:46 +00:00
|
|
|
"rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node, seq, rcv_nxt,
|
|
|
|
rcv_wnd);
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle_syn_pkt() is for Passive node. The syn packet is received when a node
|
|
|
|
* is created with a listener or it may comein as rexmitted packet which in
|
|
|
|
* that case will be just dropped.
|
|
|
|
*/
|
|
|
|
static void handle_syn_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct tcphdr *tcph)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u32 inc_sequence;
|
|
|
|
int optionsize;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
|
2008-11-22 02:50:52 +00:00
|
|
|
skb_trim(skb, 0);
|
2008-07-25 03:50:45 +00:00
|
|
|
inc_sequence = ntohl(tcph->seq);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
switch (cm_node->state) {
|
|
|
|
case NES_CM_STATE_SYN_SENT:
|
|
|
|
case NES_CM_STATE_MPAREQ_SENT:
|
|
|
|
/* Rcvd syn on active open connection*/
|
|
|
|
active_open_err(cm_node, skb, 1);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_LISTENING:
|
|
|
|
/* Passive OPEN */
|
|
|
|
if (atomic_read(&cm_node->listener->pend_accepts_cnt) >
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->listener->backlog) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "drop syn due to backlog "
|
2011-09-25 14:47:46 +00:00
|
|
|
"pressure \n");
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_backlog_drops++;
|
|
|
|
passive_open_err(cm_node, skb, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = handle_tcp_options(cm_node, tcph, skb, optionsize,
|
2011-09-25 14:47:46 +00:00
|
|
|
1);
|
2008-07-25 03:50:45 +00:00
|
|
|
if (ret) {
|
|
|
|
passive_open_err(cm_node, skb, 0);
|
|
|
|
/* drop pkt */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
|
|
|
|
BUG_ON(cm_node->send_entry);
|
2009-03-06 23:15:01 +00:00
|
|
|
cm_node->accept_pend = 1;
|
|
|
|
atomic_inc(&cm_node->listener->pend_accepts_cnt);
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->state = NES_CM_STATE_SYN_RCVD;
|
|
|
|
send_syn(cm_node, 1, skb);
|
|
|
|
break;
|
2008-11-22 02:50:52 +00:00
|
|
|
case NES_CM_STATE_CLOSED:
|
|
|
|
cleanup_retrans_entry(cm_node);
|
2009-12-09 23:54:18 +00:00
|
|
|
add_ref_cm_node(cm_node);
|
2008-11-22 02:50:52 +00:00
|
|
|
send_reset(cm_node, skb);
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_STATE_TSA:
|
|
|
|
case NES_CM_STATE_ESTABLISHED:
|
|
|
|
case NES_CM_STATE_FIN_WAIT1:
|
|
|
|
case NES_CM_STATE_FIN_WAIT2:
|
|
|
|
case NES_CM_STATE_MPAREQ_RCVD:
|
|
|
|
case NES_CM_STATE_LAST_ACK:
|
|
|
|
case NES_CM_STATE_CLOSING:
|
|
|
|
case NES_CM_STATE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
drop_packet(skb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_synack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct tcphdr *tcph)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u32 inc_sequence;
|
|
|
|
int optionsize;
|
|
|
|
|
|
|
|
optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
|
2008-11-22 02:50:52 +00:00
|
|
|
skb_trim(skb, 0);
|
2008-07-25 03:50:45 +00:00
|
|
|
inc_sequence = ntohl(tcph->seq);
|
|
|
|
switch (cm_node->state) {
|
|
|
|
case NES_CM_STATE_SYN_SENT:
|
2009-03-06 23:15:01 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
/* active open */
|
|
|
|
if (check_syn(cm_node, tcph, skb))
|
|
|
|
return;
|
|
|
|
cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
|
|
|
|
/* setup options */
|
|
|
|
ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 0);
|
|
|
|
if (ret) {
|
|
|
|
nes_debug(NES_DBG_CM, "cm_node=%p tcp_options failed\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
|
|
|
|
send_mpa_request(cm_node, skb);
|
|
|
|
cm_node->state = NES_CM_STATE_MPAREQ_SENT;
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_MPAREQ_RCVD:
|
|
|
|
/* passive open, so should not be here */
|
|
|
|
passive_open_err(cm_node, skb, 1);
|
|
|
|
break;
|
2008-11-22 02:50:52 +00:00
|
|
|
case NES_CM_STATE_LISTENING:
|
2009-12-09 23:54:18 +00:00
|
|
|
cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
|
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
send_reset(cm_node, skb);
|
|
|
|
break;
|
2008-11-22 02:50:52 +00:00
|
|
|
case NES_CM_STATE_CLOSED:
|
|
|
|
cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
|
|
|
|
cleanup_retrans_entry(cm_node);
|
2009-12-09 23:54:18 +00:00
|
|
|
add_ref_cm_node(cm_node);
|
2008-11-22 02:50:52 +00:00
|
|
|
send_reset(cm_node, skb);
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_STATE_ESTABLISHED:
|
|
|
|
case NES_CM_STATE_FIN_WAIT1:
|
|
|
|
case NES_CM_STATE_FIN_WAIT2:
|
|
|
|
case NES_CM_STATE_LAST_ACK:
|
|
|
|
case NES_CM_STATE_TSA:
|
|
|
|
case NES_CM_STATE_CLOSING:
|
|
|
|
case NES_CM_STATE_UNKNOWN:
|
|
|
|
case NES_CM_STATE_MPAREQ_SENT:
|
|
|
|
default:
|
|
|
|
drop_packet(skb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-04-27 20:41:06 +00:00
|
|
|
static int handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct tcphdr *tcph)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
|
|
|
int datasize = 0;
|
|
|
|
u32 inc_sequence;
|
2009-04-27 20:41:06 +00:00
|
|
|
int ret = 0;
|
2008-11-22 02:50:52 +00:00
|
|
|
int optionsize;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2008-11-22 02:50:52 +00:00
|
|
|
optionsize = (tcph->doff << 2) - sizeof(struct tcphdr);
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (check_seq(cm_node, tcph, skb))
|
2009-04-27 20:41:06 +00:00
|
|
|
return -EINVAL;
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
skb_pull(skb, tcph->doff << 2);
|
2008-02-05 04:20:45 +00:00
|
|
|
inc_sequence = ntohl(tcph->seq);
|
2008-07-25 03:50:45 +00:00
|
|
|
datasize = skb->len;
|
|
|
|
switch (cm_node->state) {
|
|
|
|
case NES_CM_STATE_SYN_RCVD:
|
|
|
|
/* Passive OPEN */
|
2009-04-27 20:41:06 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-11-22 02:50:52 +00:00
|
|
|
ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 1);
|
|
|
|
if (ret)
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
|
|
|
|
cm_node->state = NES_CM_STATE_ESTABLISHED;
|
|
|
|
if (datasize) {
|
|
|
|
cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
|
2009-03-06 23:15:01 +00:00
|
|
|
handle_rcv_mpa(cm_node, skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
} else { /* rcvd ACK only */
|
2008-07-25 03:50:45 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
case NES_CM_STATE_ESTABLISHED:
|
|
|
|
/* Passive OPEN */
|
2009-03-06 23:15:01 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
if (datasize) {
|
|
|
|
cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
|
2009-03-06 23:15:01 +00:00
|
|
|
handle_rcv_mpa(cm_node, skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
} else {
|
2008-07-25 03:50:45 +00:00
|
|
|
drop_packet(skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
case NES_CM_STATE_MPAREQ_SENT:
|
|
|
|
cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
|
|
|
|
if (datasize) {
|
|
|
|
cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
|
2009-03-06 23:15:01 +00:00
|
|
|
handle_rcv_mpa(cm_node, skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
} else { /* Could be just an ack pkt.. */
|
2008-07-25 03:50:45 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
2008-11-22 02:50:52 +00:00
|
|
|
case NES_CM_STATE_LISTENING:
|
2009-12-09 23:54:18 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
send_reset(cm_node, skb);
|
|
|
|
break;
|
2008-11-22 02:50:52 +00:00
|
|
|
case NES_CM_STATE_CLOSED:
|
|
|
|
cleanup_retrans_entry(cm_node);
|
2009-12-09 23:54:18 +00:00
|
|
|
add_ref_cm_node(cm_node);
|
2008-11-22 02:50:52 +00:00
|
|
|
send_reset(cm_node, skb);
|
|
|
|
break;
|
2009-03-06 23:15:01 +00:00
|
|
|
case NES_CM_STATE_LAST_ACK:
|
2009-04-27 20:41:06 +00:00
|
|
|
case NES_CM_STATE_CLOSING:
|
2009-03-06 23:15:01 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
cm_node->cm_id->rem_ref(cm_node->cm_id);
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
drop_packet(skb);
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_STATE_FIN_WAIT1:
|
2009-03-06 23:15:01 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
drop_packet(skb);
|
|
|
|
cm_node->state = NES_CM_STATE_FIN_WAIT2;
|
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_STATE_SYN_SENT:
|
|
|
|
case NES_CM_STATE_FIN_WAIT2:
|
|
|
|
case NES_CM_STATE_TSA:
|
|
|
|
case NES_CM_STATE_MPAREQ_RCVD:
|
|
|
|
case NES_CM_STATE_UNKNOWN:
|
|
|
|
default:
|
2009-04-27 20:41:06 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
drop_packet(skb);
|
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2009-04-27 20:41:06 +00:00
|
|
|
return ret;
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct sk_buff *skb, int optionsize, int passive)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
|
|
|
u8 *optionsloc = (u8 *)&tcph[1];
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
if (optionsize) {
|
2008-07-25 03:50:45 +00:00
|
|
|
if (process_options(cm_node, optionsloc, optionsize,
|
2011-09-25 14:47:46 +00:00
|
|
|
(u32)tcph->syn)) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "%s: Node %p, Sending RESET\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
__func__, cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
if (passive)
|
2008-11-22 02:50:52 +00:00
|
|
|
passive_open_err(cm_node, skb, 1);
|
2008-07-25 03:50:45 +00:00
|
|
|
else
|
2008-11-22 02:50:52 +00:00
|
|
|
active_open_err(cm_node, skb, 1);
|
2008-07-25 03:50:45 +00:00
|
|
|
return 1;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
cm_node->tcp_cntxt.snd_wnd = ntohs(tcph->window) <<
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->tcp_cntxt.snd_wscale;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (cm_node->tcp_cntxt.snd_wnd > cm_node->tcp_cntxt.max_snd_wnd)
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.snd_wnd;
|
2008-07-25 03:50:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
/*
|
|
|
|
* active_open_err() will send reset() if flag set..
|
|
|
|
* It will also send ABORT event.
|
|
|
|
*/
|
|
|
|
static void active_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
|
2011-09-25 14:47:46 +00:00
|
|
|
int reset)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
if (reset) {
|
|
|
|
nes_debug(NES_DBG_CM, "ERROR active err called for cm_node=%p, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"state=%d\n", cm_node, cm_node->state);
|
2008-07-25 03:50:45 +00:00
|
|
|
add_ref_cm_node(cm_node);
|
|
|
|
send_reset(cm_node, skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
} else {
|
2008-07-25 03:50:45 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
create_event(cm_node, NES_CM_EVENT_ABORTED);
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
/*
|
|
|
|
* passive_open_err() will either do a reset() or will free up the skb and
|
|
|
|
* remove the cm_node.
|
|
|
|
*/
|
|
|
|
static void passive_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
|
2011-09-25 14:47:46 +00:00
|
|
|
int reset)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
if (reset) {
|
|
|
|
nes_debug(NES_DBG_CM, "passive_open_err sending RST for "
|
2011-09-25 14:47:46 +00:00
|
|
|
"cm_node=%p state =%d\n", cm_node, cm_node->state);
|
2008-07-25 03:50:45 +00:00
|
|
|
send_reset(cm_node, skb);
|
|
|
|
} else {
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
/*
|
|
|
|
* free_retrans_entry() routines assumes that the retrans_list_lock has
|
|
|
|
* been acquired before calling.
|
|
|
|
*/
|
|
|
|
static void free_retrans_entry(struct nes_cm_node *cm_node)
|
|
|
|
{
|
|
|
|
struct nes_timer_entry *send_entry;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
send_entry = cm_node->send_entry;
|
|
|
|
if (send_entry) {
|
|
|
|
cm_node->send_entry = NULL;
|
|
|
|
dev_kfree_skb_any(send_entry->skb);
|
|
|
|
kfree(send_entry);
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
static void cleanup_retrans_entry(struct nes_cm_node *cm_node)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
|
|
|
|
free_retrans_entry(cm_node);
|
|
|
|
spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
/**
|
|
|
|
* process_packet
|
|
|
|
* Returns skb if to be freed, else it will return NULL if already used..
|
|
|
|
*/
|
|
|
|
static void process_packet(struct nes_cm_node *cm_node, struct sk_buff *skb,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_cm_core *cm_core)
|
2008-07-25 03:50:45 +00:00
|
|
|
{
|
2011-09-25 14:47:46 +00:00
|
|
|
enum nes_tcpip_pkt_type pkt_type = NES_PKT_TYPE_UNKNOWN;
|
2008-07-25 03:50:45 +00:00
|
|
|
struct tcphdr *tcph = tcp_hdr(skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
u32 fin_set = 0;
|
2009-04-27 20:41:06 +00:00
|
|
|
int ret = 0;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
skb_pull(skb, ip_hdr(skb)->ihl << 2);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "process_packet: cm_node=%p state =%d syn=%d "
|
2011-09-25 14:47:46 +00:00
|
|
|
"ack=%d rst=%d fin=%d\n", cm_node, cm_node->state, tcph->syn,
|
|
|
|
tcph->ack, tcph->rst, tcph->fin);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
if (tcph->rst) {
|
2008-07-25 03:50:45 +00:00
|
|
|
pkt_type = NES_PKT_TYPE_RST;
|
2011-09-25 14:47:46 +00:00
|
|
|
} else if (tcph->syn) {
|
2008-07-25 03:50:45 +00:00
|
|
|
pkt_type = NES_PKT_TYPE_SYN;
|
|
|
|
if (tcph->ack)
|
|
|
|
pkt_type = NES_PKT_TYPE_SYNACK;
|
2011-09-25 14:47:46 +00:00
|
|
|
} else if (tcph->ack) {
|
2008-07-25 03:50:45 +00:00
|
|
|
pkt_type = NES_PKT_TYPE_ACK;
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2009-03-06 23:15:01 +00:00
|
|
|
if (tcph->fin)
|
|
|
|
fin_set = 1;
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
switch (pkt_type) {
|
|
|
|
case NES_PKT_TYPE_SYN:
|
|
|
|
handle_syn_pkt(cm_node, skb, tcph);
|
|
|
|
break;
|
|
|
|
case NES_PKT_TYPE_SYNACK:
|
|
|
|
handle_synack_pkt(cm_node, skb, tcph);
|
|
|
|
break;
|
|
|
|
case NES_PKT_TYPE_ACK:
|
2009-04-27 20:41:06 +00:00
|
|
|
ret = handle_ack_pkt(cm_node, skb, tcph);
|
|
|
|
if (fin_set && !ret)
|
2009-03-06 23:15:01 +00:00
|
|
|
handle_fin_pkt(cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
case NES_PKT_TYPE_RST:
|
|
|
|
handle_rst_pkt(cm_node, skb, tcph);
|
|
|
|
break;
|
|
|
|
default:
|
2009-04-27 20:41:06 +00:00
|
|
|
if ((fin_set) && (!check_seq(cm_node, tcph, skb)))
|
2009-03-06 23:15:01 +00:00
|
|
|
handle_fin_pkt(cm_node);
|
2009-04-27 20:41:06 +00:00
|
|
|
drop_packet(skb);
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_listen - create a listen node with params
|
|
|
|
*/
|
|
|
|
static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *cm_core,
|
2014-03-26 22:07:57 +00:00
|
|
|
struct nes_vnic *nesvnic, struct nes_cm_info *cm_info)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct nes_cm_listener *listener;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "Search for 0x%08x : 0x%04x\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_info->loc_addr, cm_info->loc_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* cannot have multiple matching listeners */
|
2014-03-26 22:07:57 +00:00
|
|
|
listener = find_listener(cm_core, cm_info->loc_addr, cm_info->loc_port,
|
2016-02-26 15:18:02 +00:00
|
|
|
NES_CM_LISTENER_EITHER_STATE);
|
2014-03-26 22:07:57 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
if (listener && listener->listener_state == NES_CM_LISTENER_ACTIVE_STATE) {
|
|
|
|
/* find automatically incs ref count ??? */
|
|
|
|
atomic_dec(&listener->ref_count);
|
|
|
|
nes_debug(NES_DBG_CM, "Not creating listener since it already exists\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!listener) {
|
|
|
|
/* create a CM listen node (1/2 node to compare incoming traffic to) */
|
|
|
|
listener = kzalloc(sizeof(*listener), GFP_ATOMIC);
|
2016-11-03 14:44:19 +00:00
|
|
|
if (!listener)
|
2008-02-05 04:20:45 +00:00
|
|
|
return NULL;
|
|
|
|
|
2014-03-26 22:07:57 +00:00
|
|
|
listener->loc_addr = cm_info->loc_addr;
|
|
|
|
listener->loc_port = cm_info->loc_port;
|
2008-02-05 04:20:45 +00:00
|
|
|
listener->reused_node = 0;
|
|
|
|
|
|
|
|
atomic_set(&listener->ref_count, 1);
|
|
|
|
}
|
|
|
|
/* pasive case */
|
|
|
|
/* find already inc'ed the ref count */
|
|
|
|
else {
|
|
|
|
listener->reused_node = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener->cm_id = cm_info->cm_id;
|
|
|
|
atomic_set(&listener->pend_accepts_cnt, 0);
|
|
|
|
listener->cm_core = cm_core;
|
|
|
|
listener->nesvnic = nesvnic;
|
|
|
|
atomic_inc(&cm_core->node_cnt);
|
|
|
|
|
|
|
|
listener->conn_type = cm_info->conn_type;
|
|
|
|
listener->backlog = cm_info->backlog;
|
|
|
|
listener->listener_state = NES_CM_LISTENER_ACTIVE_STATE;
|
|
|
|
|
|
|
|
if (!listener->reused_node) {
|
|
|
|
spin_lock_irqsave(&cm_core->listen_list_lock, flags);
|
|
|
|
list_add(&listener->list, &cm_core->listen_list.list);
|
|
|
|
spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
|
|
|
|
atomic_inc(&cm_core->listen_node_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "Api - listen(): addr=0x%08X, port=0x%04x,"
|
2011-09-25 14:47:46 +00:00
|
|
|
" listener = %p, backlog = %d, cm_id = %p.\n",
|
|
|
|
cm_info->loc_addr, cm_info->loc_port,
|
|
|
|
listener, listener->backlog, listener->cm_id);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
return listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_connect - make a connection node with params
|
|
|
|
*/
|
2008-09-30 21:47:27 +00:00
|
|
|
static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_vnic *nesvnic, u16 private_data_len,
|
|
|
|
void *private_data, struct nes_cm_info *cm_info)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct nes_cm_node *cm_node;
|
|
|
|
struct nes_cm_listener *loopbackremotelistener;
|
|
|
|
struct nes_cm_node *loopbackremotenode;
|
|
|
|
struct nes_cm_info loopback_cm_info;
|
2011-09-25 14:47:46 +00:00
|
|
|
u8 *start_buff;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* create a CM connection node */
|
|
|
|
cm_node = make_cm_node(cm_core, nesvnic, cm_info, NULL);
|
|
|
|
if (!cm_node)
|
|
|
|
return NULL;
|
|
|
|
|
2008-04-29 20:46:54 +00:00
|
|
|
/* set our node side to client (active) side */
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->tcp_cntxt.client = 1;
|
|
|
|
cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
|
|
|
|
|
|
|
|
if (cm_info->loc_addr == cm_info->rem_addr) {
|
2008-07-25 03:50:45 +00:00
|
|
|
loopbackremotelistener = find_listener(cm_core,
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_node->loc_addr, cm_node->rem_port,
|
|
|
|
NES_CM_LISTENER_ACTIVE_STATE);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (loopbackremotelistener == NULL) {
|
|
|
|
create_event(cm_node, NES_CM_EVENT_ABORTED);
|
|
|
|
} else {
|
|
|
|
loopback_cm_info = *cm_info;
|
|
|
|
loopback_cm_info.loc_port = cm_info->rem_port;
|
|
|
|
loopback_cm_info.rem_port = cm_info->loc_port;
|
2016-02-26 15:18:02 +00:00
|
|
|
loopback_cm_info.loc_port =
|
|
|
|
cm_info->rem_port;
|
|
|
|
loopback_cm_info.rem_port =
|
|
|
|
cm_info->loc_port;
|
2008-02-05 04:20:45 +00:00
|
|
|
loopback_cm_info.cm_id = loopbackremotelistener->cm_id;
|
2008-07-25 03:50:45 +00:00
|
|
|
loopbackremotenode = make_cm_node(cm_core, nesvnic,
|
2011-09-25 14:47:46 +00:00
|
|
|
&loopback_cm_info, loopbackremotelistener);
|
2009-04-08 21:22:20 +00:00
|
|
|
if (!loopbackremotenode) {
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
atomic_inc(&cm_loopbacks);
|
2008-02-05 04:20:45 +00:00
|
|
|
loopbackremotenode->loopbackpartner = cm_node;
|
2008-07-25 03:50:45 +00:00
|
|
|
loopbackremotenode->tcp_cntxt.rcv_wscale =
|
|
|
|
NES_CM_DEFAULT_RCV_WND_SCALE;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->loopbackpartner = loopbackremotenode;
|
2008-07-25 03:50:45 +00:00
|
|
|
memcpy(loopbackremotenode->mpa_frame_buf, private_data,
|
2011-09-25 14:47:46 +00:00
|
|
|
private_data_len);
|
2008-07-25 03:50:45 +00:00
|
|
|
loopbackremotenode->mpa_frame_size = private_data_len;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
/* we are done handling this state. */
|
|
|
|
/* set node to a TSA state */
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->state = NES_CM_STATE_TSA;
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->tcp_cntxt.rcv_nxt =
|
|
|
|
loopbackremotenode->tcp_cntxt.loc_seq_num;
|
|
|
|
loopbackremotenode->tcp_cntxt.rcv_nxt =
|
|
|
|
cm_node->tcp_cntxt.loc_seq_num;
|
|
|
|
cm_node->tcp_cntxt.max_snd_wnd =
|
|
|
|
loopbackremotenode->tcp_cntxt.rcv_wnd;
|
|
|
|
loopbackremotenode->tcp_cntxt.max_snd_wnd =
|
|
|
|
cm_node->tcp_cntxt.rcv_wnd;
|
|
|
|
cm_node->tcp_cntxt.snd_wnd =
|
|
|
|
loopbackremotenode->tcp_cntxt.rcv_wnd;
|
|
|
|
loopbackremotenode->tcp_cntxt.snd_wnd =
|
|
|
|
cm_node->tcp_cntxt.rcv_wnd;
|
|
|
|
cm_node->tcp_cntxt.snd_wscale =
|
|
|
|
loopbackremotenode->tcp_cntxt.rcv_wscale;
|
|
|
|
loopbackremotenode->tcp_cntxt.snd_wscale =
|
|
|
|
cm_node->tcp_cntxt.rcv_wscale;
|
2009-03-06 23:15:01 +00:00
|
|
|
loopbackremotenode->state = NES_CM_STATE_MPAREQ_RCVD;
|
2008-02-05 04:20:45 +00:00
|
|
|
create_event(loopbackremotenode, NES_CM_EVENT_MPA_REQ);
|
|
|
|
}
|
|
|
|
return cm_node;
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
start_buff = &cm_node->mpa_frame_buf[0] + sizeof(struct ietf_mpa_v2);
|
|
|
|
cm_node->mpa_frame_size = private_data_len;
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
memcpy(start_buff, private_data, private_data_len);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* send a syn and goto syn sent state */
|
|
|
|
cm_node->state = NES_CM_STATE_SYN_SENT;
|
2008-07-25 03:50:45 +00:00
|
|
|
ret = send_syn(cm_node, 0, NULL);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
/* error in sending the syn free up the cm_node struct */
|
|
|
|
nes_debug(NES_DBG_CM, "Api - connect() FAILED: dest "
|
2011-09-25 14:47:46 +00:00
|
|
|
"addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
|
|
|
|
cm_node->rem_addr, cm_node->rem_port, cm_node,
|
|
|
|
cm_node->cm_id);
|
2008-07-25 03:50:45 +00:00
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
cm_node = NULL;
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
if (cm_node) {
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Api - connect(): dest addr=0x%08X,"
|
2011-09-25 14:47:46 +00:00
|
|
|
"port=0x%04x, cm_node=%p, cm_id = %p.\n",
|
|
|
|
cm_node->rem_addr, cm_node->rem_port, cm_node,
|
|
|
|
cm_node->cm_id);
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
return cm_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_accept - accept a connection
|
|
|
|
* This function is never called
|
|
|
|
*/
|
2011-09-25 14:47:46 +00:00
|
|
|
static int mini_cm_accept(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_reject - reject and teardown a connection
|
|
|
|
*/
|
2011-09-25 14:47:46 +00:00
|
|
|
static int mini_cm_reject(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2009-03-06 23:15:01 +00:00
|
|
|
int err = 0;
|
2008-11-22 02:50:46 +00:00
|
|
|
int passive_state;
|
2009-03-06 23:15:01 +00:00
|
|
|
struct nes_cm_event event;
|
|
|
|
struct iw_cm_id *cm_id = cm_node->cm_id;
|
|
|
|
struct nes_cm_node *loopback = cm_node->loopbackpartner;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "%s cm_node=%p type=%d state=%d\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
__func__, cm_node, cm_node->tcp_cntxt.client, cm_node->state);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (cm_node->tcp_cntxt.client)
|
|
|
|
return ret;
|
|
|
|
cleanup_retrans_entry(cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
if (!loopback) {
|
|
|
|
passive_state = atomic_add_return(1, &cm_node->passive_state);
|
|
|
|
if (passive_state == NES_SEND_RESET_EVENT) {
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
} else {
|
2009-12-09 23:54:08 +00:00
|
|
|
if (cm_node->state == NES_CM_STATE_LISTENER_DESTROYED) {
|
|
|
|
rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
} else {
|
|
|
|
ret = send_mpa_reject(cm_node);
|
|
|
|
if (ret) {
|
|
|
|
cm_node->state = NES_CM_STATE_CLOSED;
|
|
|
|
err = send_reset(cm_node, NULL);
|
|
|
|
if (err)
|
|
|
|
WARN_ON(1);
|
2011-09-25 14:47:46 +00:00
|
|
|
} else {
|
2009-12-09 23:54:08 +00:00
|
|
|
cm_id->add_ref(cm_id);
|
2011-09-25 14:47:46 +00:00
|
|
|
}
|
2009-12-09 23:54:08 +00:00
|
|
|
}
|
2009-03-06 23:15:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cm_node->cm_id = NULL;
|
2009-12-09 23:54:08 +00:00
|
|
|
if (cm_node->state == NES_CM_STATE_LISTENER_DESTROYED) {
|
|
|
|
rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
rem_ref_cm_node(cm_core, loopback);
|
|
|
|
} else {
|
|
|
|
event.cm_node = loopback;
|
|
|
|
event.cm_info.rem_addr = loopback->rem_addr;
|
|
|
|
event.cm_info.loc_addr = loopback->loc_addr;
|
|
|
|
event.cm_info.rem_port = loopback->rem_port;
|
|
|
|
event.cm_info.loc_port = loopback->loc_port;
|
|
|
|
event.cm_info.cm_id = loopback->cm_id;
|
|
|
|
cm_event_mpa_reject(&event);
|
|
|
|
rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
loopback->state = NES_CM_STATE_CLOSING;
|
2009-03-06 23:15:01 +00:00
|
|
|
|
2009-12-09 23:54:08 +00:00
|
|
|
cm_id = loopback->cm_id;
|
|
|
|
rem_ref_cm_node(cm_core, loopback);
|
|
|
|
cm_id->rem_ref(cm_id);
|
|
|
|
}
|
2009-03-06 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_close
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static int mini_cm_close(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!cm_core || !cm_node)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (cm_node->state) {
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_STATE_SYN_RCVD:
|
|
|
|
case NES_CM_STATE_SYN_SENT:
|
|
|
|
case NES_CM_STATE_ONE_SIDE_ESTABLISHED:
|
|
|
|
case NES_CM_STATE_ESTABLISHED:
|
|
|
|
case NES_CM_STATE_ACCEPTING:
|
|
|
|
case NES_CM_STATE_MPAREQ_SENT:
|
|
|
|
case NES_CM_STATE_MPAREQ_RCVD:
|
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
send_reset(cm_node, NULL);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_CLOSE_WAIT:
|
|
|
|
cm_node->state = NES_CM_STATE_LAST_ACK;
|
|
|
|
send_fin(cm_node, NULL);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_FIN_WAIT1:
|
|
|
|
case NES_CM_STATE_FIN_WAIT2:
|
|
|
|
case NES_CM_STATE_LAST_ACK:
|
|
|
|
case NES_CM_STATE_TIME_WAIT:
|
|
|
|
case NES_CM_STATE_CLOSING:
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_LISTENING:
|
2009-12-09 23:54:18 +00:00
|
|
|
cleanup_retrans_entry(cm_node);
|
|
|
|
send_reset(cm_node, NULL);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_MPAREJ_RCVD:
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_STATE_UNKNOWN:
|
|
|
|
case NES_CM_STATE_INITED:
|
|
|
|
case NES_CM_STATE_CLOSED:
|
2009-12-09 23:54:08 +00:00
|
|
|
case NES_CM_STATE_LISTENER_DESTROYED:
|
2008-07-25 03:50:45 +00:00
|
|
|
ret = rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
break;
|
|
|
|
case NES_CM_STATE_TSA:
|
|
|
|
if (cm_node->send_entry)
|
|
|
|
printk(KERN_ERR "ERROR Close got called from STATE_TSA "
|
2011-09-25 14:47:46 +00:00
|
|
|
"send_entry=%p\n", cm_node->send_entry);
|
2008-07-25 03:50:45 +00:00
|
|
|
ret = rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* recv_pkt - recv an ETHERNET packet, and process it through CM
|
|
|
|
* node state machine
|
|
|
|
*/
|
2008-11-22 02:50:49 +00:00
|
|
|
static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
|
2011-09-25 14:47:46 +00:00
|
|
|
struct nes_vnic *nesvnic, struct sk_buff *skb)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct nes_cm_node *cm_node = NULL;
|
|
|
|
struct nes_cm_listener *listener = NULL;
|
|
|
|
struct iphdr *iph;
|
|
|
|
struct tcphdr *tcph;
|
|
|
|
struct nes_cm_info nfo;
|
2008-11-22 02:50:49 +00:00
|
|
|
int skb_handled = 1;
|
2009-01-11 05:45:42 +00:00
|
|
|
__be32 tmp_daddr, tmp_saddr;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (!skb)
|
2008-11-22 02:50:49 +00:00
|
|
|
return 0;
|
2011-09-25 14:47:46 +00:00
|
|
|
if (skb->len < sizeof(struct iphdr) + sizeof(struct tcphdr))
|
2008-11-22 02:50:49 +00:00
|
|
|
return 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
iph = (struct iphdr *)skb->data;
|
|
|
|
tcph = (struct tcphdr *)(skb->data + sizeof(struct iphdr));
|
|
|
|
|
|
|
|
nfo.loc_addr = ntohl(iph->daddr);
|
|
|
|
nfo.loc_port = ntohs(tcph->dest);
|
|
|
|
nfo.rem_addr = ntohl(iph->saddr);
|
|
|
|
nfo.rem_port = ntohs(tcph->source);
|
|
|
|
|
2009-01-11 05:45:42 +00:00
|
|
|
tmp_daddr = cpu_to_be32(iph->daddr);
|
|
|
|
tmp_saddr = cpu_to_be32(iph->saddr);
|
|
|
|
|
2008-10-31 07:56:00 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Received packet: dest=%pI4:0x%04X src=%pI4:0x%04X\n",
|
2009-01-11 05:45:42 +00:00
|
|
|
&tmp_daddr, tcph->dest, &tmp_saddr, tcph->source);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
do {
|
|
|
|
cm_node = find_node(cm_core,
|
2016-02-26 15:18:02 +00:00
|
|
|
nfo.rem_port, nfo.rem_addr,
|
|
|
|
nfo.loc_port, nfo.loc_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (!cm_node) {
|
2008-07-25 03:50:45 +00:00
|
|
|
/* Only type of packet accepted are for */
|
|
|
|
/* the PASSIVE open (syn only) */
|
|
|
|
if ((!tcph->syn) || (tcph->ack)) {
|
2008-11-22 02:50:49 +00:00
|
|
|
skb_handled = 0;
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-02-26 15:18:02 +00:00
|
|
|
listener = find_listener(cm_core, nfo.loc_addr,
|
|
|
|
nfo.loc_port,
|
|
|
|
NES_CM_LISTENER_ACTIVE_STATE);
|
2008-11-22 02:50:49 +00:00
|
|
|
if (!listener) {
|
|
|
|
nfo.cm_id = NULL;
|
|
|
|
nfo.conn_type = 0;
|
|
|
|
nes_debug(NES_DBG_CM, "Unable to find listener for the pkt\n");
|
|
|
|
skb_handled = 0;
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-22 02:50:49 +00:00
|
|
|
nfo.cm_id = listener->cm_id;
|
|
|
|
nfo.conn_type = listener->conn_type;
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node = make_cm_node(cm_core, nesvnic, &nfo,
|
2011-09-25 14:47:46 +00:00
|
|
|
listener);
|
2008-07-25 03:50:45 +00:00
|
|
|
if (!cm_node) {
|
|
|
|
nes_debug(NES_DBG_CM, "Unable to allocate "
|
2011-09-25 14:47:46 +00:00
|
|
|
"node\n");
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_packets_dropped++;
|
2008-02-05 04:20:45 +00:00
|
|
|
atomic_dec(&listener->ref_count);
|
2008-07-25 03:50:45 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
if (!tcph->rst && !tcph->fin) {
|
|
|
|
cm_node->state = NES_CM_STATE_LISTENING;
|
|
|
|
} else {
|
|
|
|
cm_packets_dropped++;
|
|
|
|
rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
add_ref_cm_node(cm_node);
|
|
|
|
} else if (cm_node->state == NES_CM_STATE_TSA) {
|
2011-09-26 01:34:00 +00:00
|
|
|
if (cm_node->nesqp->pau_mode)
|
|
|
|
nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
|
|
|
|
else {
|
|
|
|
rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
atomic_inc(&cm_accel_dropped_pkts);
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
2008-11-22 02:50:49 +00:00
|
|
|
skb_reset_network_header(skb);
|
|
|
|
skb_set_transport_header(skb, sizeof(*tcph));
|
|
|
|
skb->len = ntohs(iph->tot_len);
|
2008-07-25 03:50:45 +00:00
|
|
|
process_packet(cm_node, skb, cm_core);
|
|
|
|
rem_ref_cm_node(cm_core, cm_node);
|
|
|
|
} while (0);
|
2008-11-22 02:50:49 +00:00
|
|
|
return skb_handled;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_alloc_core - allocate a top level instance of a cm core
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static struct nes_cm_core *nes_cm_alloc_core(void)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct nes_cm_core *cm_core;
|
|
|
|
|
|
|
|
/* setup the CM core */
|
|
|
|
/* alloc top level core control structure */
|
|
|
|
cm_core = kzalloc(sizeof(*cm_core), GFP_KERNEL);
|
|
|
|
if (!cm_core)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&cm_core->connected_nodes);
|
2017-10-05 00:45:27 +00:00
|
|
|
timer_setup(&cm_core->tcp_timer, nes_cm_timer_tick, 0);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_core->mtu = NES_CM_DEFAULT_MTU;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_core->state = NES_CM_STATE_INITED;
|
|
|
|
cm_core->free_tx_pkt_max = NES_CM_DEFAULT_FREE_PKTS;
|
|
|
|
|
|
|
|
atomic_set(&cm_core->events_posted, 0);
|
|
|
|
|
|
|
|
cm_core->api = &nes_cm_api;
|
|
|
|
|
|
|
|
spin_lock_init(&cm_core->ht_lock);
|
|
|
|
spin_lock_init(&cm_core->listen_list_lock);
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&cm_core->listen_list.list);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "Init CM Core completed -- cm_core=%p\n", cm_core);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "Enable QUEUE EVENTS\n");
|
2016-08-15 18:14:03 +00:00
|
|
|
cm_core->event_wq = alloc_ordered_workqueue("nesewq", 0);
|
2016-02-17 18:06:33 +00:00
|
|
|
if (!cm_core->event_wq)
|
|
|
|
goto out_free_cmcore;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_core->post_event = nes_cm_post_event;
|
|
|
|
nes_debug(NES_DBG_CM, "Enable QUEUE DISCONNECTS\n");
|
2016-08-15 18:14:03 +00:00
|
|
|
cm_core->disconn_wq = alloc_ordered_workqueue("nesdwq", 0);
|
2016-02-17 18:06:33 +00:00
|
|
|
if (!cm_core->disconn_wq)
|
|
|
|
goto out_free_wq;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
print_core(cm_core);
|
|
|
|
return cm_core;
|
2016-02-17 18:06:33 +00:00
|
|
|
|
|
|
|
out_free_wq:
|
|
|
|
destroy_workqueue(cm_core->event_wq);
|
|
|
|
out_free_cmcore:
|
|
|
|
kfree(cm_core);
|
|
|
|
return NULL;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_dealloc_core - deallocate a top level instance of a cm core
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static int mini_cm_dealloc_core(struct nes_cm_core *cm_core)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
nes_debug(NES_DBG_CM, "De-Alloc CM Core (%p)\n", cm_core);
|
|
|
|
|
|
|
|
if (!cm_core)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
barrier();
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
if (timer_pending(&cm_core->tcp_timer))
|
2008-02-05 04:20:45 +00:00
|
|
|
del_timer(&cm_core->tcp_timer);
|
|
|
|
|
|
|
|
destroy_workqueue(cm_core->event_wq);
|
|
|
|
destroy_workqueue(cm_core->disconn_wq);
|
|
|
|
nes_debug(NES_DBG_CM, "\n");
|
|
|
|
kfree(cm_core);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_get
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static int mini_cm_get(struct nes_cm_core *cm_core)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
return cm_core->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mini_cm_set
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static int mini_cm_set(struct nes_cm_core *cm_core, u32 type, u32 value)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
2009-03-06 23:15:01 +00:00
|
|
|
case NES_CM_SET_PKT_SIZE:
|
|
|
|
cm_core->mtu = value;
|
|
|
|
break;
|
|
|
|
case NES_CM_SET_FREE_PKT_Q_SIZE:
|
|
|
|
cm_core->free_tx_pkt_max = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* unknown set option */
|
|
|
|
ret = -EINVAL;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_init_tsa_conn setup HW; MPA frames must be
|
|
|
|
* successfully exchanged when this is called
|
|
|
|
*/
|
|
|
|
static int nes_cm_init_tsa_conn(struct nes_qp *nesqp, struct nes_cm_node *cm_node)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!nesqp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_IPV4 |
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_QPCONTEXT_MISC_NO_NAGLE | NES_QPCONTEXT_MISC_DO_NOT_FRAG |
|
|
|
|
NES_QPCONTEXT_MISC_DROS);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (cm_node->tcp_cntxt.snd_wscale || cm_node->tcp_cntxt.rcv_wscale)
|
|
|
|
nesqp->nesqp_context->misc |= cpu_to_le32(NES_QPCONTEXT_MISC_WSCALE);
|
|
|
|
|
|
|
|
nesqp->nesqp_context->misc2 |= cpu_to_le32(64 << NES_QPCONTEXT_MISC2_TTL_SHIFT);
|
|
|
|
|
2015-05-18 20:28:14 +00:00
|
|
|
nesqp->nesqp_context->misc2 |= cpu_to_le32(
|
|
|
|
cm_node->tos << NES_QPCONTEXT_MISC2_TOS_SHIFT);
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
nesqp->nesqp_context->mss |= cpu_to_le32(((u32)cm_node->tcp_cntxt.mss) << 16);
|
|
|
|
|
|
|
|
nesqp->nesqp_context->tcp_state_flow_label |= cpu_to_le32(
|
2011-09-25 14:47:46 +00:00
|
|
|
(u32)NES_QPCONTEXT_TCPSTATE_EST << NES_QPCONTEXT_TCPFLOW_TCP_STATE_SHIFT);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
|
2011-09-25 14:47:46 +00:00
|
|
|
(cm_node->tcp_cntxt.snd_wscale << NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT) &
|
|
|
|
NES_QPCONTEXT_PDWSCALE_SND_WSCALE_MASK);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->nesqp_context->pd_index_wscale |= cpu_to_le32(
|
2011-09-25 14:47:46 +00:00
|
|
|
(cm_node->tcp_cntxt.rcv_wscale << NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT) &
|
|
|
|
NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_MASK);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->nesqp_context->keepalive = cpu_to_le32(0x80);
|
|
|
|
nesqp->nesqp_context->ts_recent = 0;
|
|
|
|
nesqp->nesqp_context->ts_age = 0;
|
|
|
|
nesqp->nesqp_context->snd_nxt = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
|
|
|
|
nesqp->nesqp_context->snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.snd_wnd);
|
|
|
|
nesqp->nesqp_context->rcv_nxt = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
|
|
|
|
nesqp->nesqp_context->rcv_wnd = cpu_to_le32(cm_node->tcp_cntxt.rcv_wnd <<
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node->tcp_cntxt.rcv_wscale);
|
2008-02-05 04:20:45 +00:00
|
|
|
nesqp->nesqp_context->snd_max = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
|
|
|
|
nesqp->nesqp_context->snd_una = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
|
|
|
|
nesqp->nesqp_context->srtt = 0;
|
|
|
|
nesqp->nesqp_context->rttvar = cpu_to_le32(0x6);
|
|
|
|
nesqp->nesqp_context->ssthresh = cpu_to_le32(0x3FFFC000);
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->nesqp_context->cwnd = cpu_to_le32(2 * cm_node->tcp_cntxt.mss);
|
2008-02-05 04:20:45 +00:00
|
|
|
nesqp->nesqp_context->snd_wl1 = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
|
|
|
|
nesqp->nesqp_context->snd_wl2 = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
|
|
|
|
nesqp->nesqp_context->max_snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.max_snd_wnd);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "QP%u: rcv_nxt = 0x%08X, snd_nxt = 0x%08X,"
|
2011-09-25 14:47:46 +00:00
|
|
|
" Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
|
|
|
|
nesqp->hwqp.qp_id, le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
|
|
|
|
le32_to_cpu(nesqp->nesqp_context->snd_nxt),
|
|
|
|
cm_node->tcp_cntxt.mss, le32_to_cpu(nesqp->nesqp_context->pd_index_wscale),
|
|
|
|
le32_to_cpu(nesqp->nesqp_context->rcv_wnd),
|
|
|
|
le32_to_cpu(nesqp->nesqp_context->misc));
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, " snd_wnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->snd_wnd));
|
|
|
|
nes_debug(NES_DBG_CM, " snd_cwnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->cwnd));
|
|
|
|
nes_debug(NES_DBG_CM, " max_swnd = 0x%08X.\n", le32_to_cpu(nesqp->nesqp_context->max_snd_wnd));
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "Change cm_node state to TSA\n");
|
|
|
|
cm_node->state = NES_CM_STATE_TSA;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_disconn
|
|
|
|
*/
|
|
|
|
int nes_cm_disconn(struct nes_qp *nesqp)
|
|
|
|
{
|
2009-09-06 03:36:37 +00:00
|
|
|
struct disconn_work *work;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-09-06 03:36:37 +00:00
|
|
|
work = kzalloc(sizeof *work, GFP_ATOMIC);
|
|
|
|
if (!work)
|
2011-09-25 14:47:46 +00:00
|
|
|
return -ENOMEM; /* Timer will clean up */
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-09-06 03:36:37 +00:00
|
|
|
nes_add_ref(&nesqp->ibqp);
|
|
|
|
work->nesqp = nesqp;
|
|
|
|
INIT_WORK(&work->work, nes_disconnect_worker);
|
|
|
|
queue_work(g_cm_core->disconn_wq, &work->work);
|
2008-02-05 04:20:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_disconnect_worker
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static void nes_disconnect_worker(struct work_struct *work)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2009-09-06 03:36:37 +00:00
|
|
|
struct disconn_work *dwork = container_of(work, struct disconn_work, work);
|
|
|
|
struct nes_qp *nesqp = dwork->nesqp;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-09-06 03:36:37 +00:00
|
|
|
kfree(dwork);
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "processing AEQE id 0x%04X for QP%u.\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->last_aeq, nesqp->hwqp.qp_id);
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_cm_disconn_true(nesqp);
|
2009-09-06 03:36:36 +00:00
|
|
|
nes_rem_ref(&nesqp->ibqp);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_disconn_true
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static int nes_cm_disconn_true(struct nes_qp *nesqp)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int ret = 0;
|
|
|
|
struct iw_cm_id *cm_id;
|
|
|
|
struct iw_cm_event cm_event;
|
|
|
|
struct nes_vnic *nesvnic;
|
|
|
|
u16 last_ae;
|
|
|
|
u8 original_hw_tcp_state;
|
|
|
|
u8 original_ibqp_state;
|
2011-05-10 05:23:57 +00:00
|
|
|
int disconn_status = 0;
|
2009-09-06 03:36:39 +00:00
|
|
|
int issue_disconn = 0;
|
|
|
|
int issue_close = 0;
|
|
|
|
int issue_flush = 0;
|
|
|
|
u32 flush_q = NES_CQP_FLUSH_RQ;
|
|
|
|
struct ib_event ibevent;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (!nesqp) {
|
|
|
|
nes_debug(NES_DBG_CM, "disconnect_worker nesqp is NULL\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&nesqp->lock, flags);
|
|
|
|
cm_id = nesqp->cm_id;
|
|
|
|
/* make sure we havent already closed this connection */
|
|
|
|
if (!cm_id) {
|
|
|
|
nes_debug(NES_DBG_CM, "QP%u disconnect_worker cmid is NULL\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->hwqp.qp_id);
|
2008-02-05 04:20:45 +00:00
|
|
|
spin_unlock_irqrestore(&nesqp->lock, flags);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nesvnic = to_nesvnic(nesqp->ibqp.device);
|
|
|
|
nes_debug(NES_DBG_CM, "Disconnecting QP%u\n", nesqp->hwqp.qp_id);
|
|
|
|
|
|
|
|
original_hw_tcp_state = nesqp->hw_tcp_state;
|
2011-09-25 14:47:46 +00:00
|
|
|
original_ibqp_state = nesqp->ibqp_state;
|
2008-02-05 04:20:45 +00:00
|
|
|
last_ae = nesqp->last_aeq;
|
|
|
|
|
2009-09-06 03:36:39 +00:00
|
|
|
if (nesqp->term_flags) {
|
|
|
|
issue_disconn = 1;
|
|
|
|
issue_close = 1;
|
|
|
|
nesqp->cm_id = NULL;
|
2011-12-05 17:39:12 +00:00
|
|
|
del_timer(&nesqp->terminate_timer);
|
2009-09-06 03:36:39 +00:00
|
|
|
if (nesqp->flush_issued == 0) {
|
|
|
|
nesqp->flush_issued = 1;
|
|
|
|
issue_flush = 1;
|
|
|
|
}
|
|
|
|
} else if ((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
|
|
|
|
((original_ibqp_state == IB_QPS_RTS) &&
|
|
|
|
(last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
|
|
|
|
issue_disconn = 1;
|
|
|
|
if (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET)
|
2011-05-10 05:23:57 +00:00
|
|
|
disconn_status = -ECONNRESET;
|
2009-09-06 03:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
|
|
|
|
(original_hw_tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT) ||
|
|
|
|
(last_ae == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) ||
|
|
|
|
(last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
|
|
|
|
issue_close = 1;
|
|
|
|
nesqp->cm_id = NULL;
|
|
|
|
if (nesqp->flush_issued == 0) {
|
|
|
|
nesqp->flush_issued = 1;
|
|
|
|
issue_flush = 1;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-09-06 03:36:39 +00:00
|
|
|
spin_unlock_irqrestore(&nesqp->lock, flags);
|
|
|
|
|
|
|
|
if ((issue_flush) && (nesqp->destroyed == 0)) {
|
|
|
|
/* Flush the queue(s) */
|
|
|
|
if (nesqp->hw_iwarp_state >= NES_AEQE_IWARP_STATE_TERMINATE)
|
|
|
|
flush_q |= NES_CQP_FLUSH_SQ;
|
|
|
|
flush_wqes(nesvnic->nesdev, nesqp, flush_q, 1);
|
|
|
|
|
|
|
|
if (nesqp->term_flags) {
|
|
|
|
ibevent.device = nesqp->ibqp.device;
|
|
|
|
ibevent.event = nesqp->terminate_eventtype;
|
|
|
|
ibevent.element.qp = &nesqp->ibqp;
|
2012-05-11 19:29:32 +00:00
|
|
|
if (nesqp->ibqp.event_handler)
|
|
|
|
nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
|
2009-09-06 03:36:39 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-09-06 03:36:39 +00:00
|
|
|
if ((cm_id) && (cm_id->event_handler)) {
|
|
|
|
if (issue_disconn) {
|
2008-02-05 04:20:45 +00:00
|
|
|
atomic_inc(&cm_disconnects);
|
|
|
|
cm_event.event = IW_CM_EVENT_DISCONNECT;
|
2009-09-06 03:36:39 +00:00
|
|
|
cm_event.status = disconn_status;
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_event.local_addr = cm_id->m_local_addr;
|
|
|
|
cm_event.remote_addr = cm_id->m_remote_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.private_data = NULL;
|
|
|
|
cm_event.private_data_len = 0;
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Generating a CM Disconnect Event"
|
2011-09-25 14:47:46 +00:00
|
|
|
" for QP%u, SQ Head = %u, SQ Tail = %u. "
|
|
|
|
"cm_id = %p, refcount = %u.\n",
|
|
|
|
nesqp->hwqp.qp_id, nesqp->hwqp.sq_head,
|
|
|
|
nesqp->hwqp.sq_tail, cm_id,
|
|
|
|
atomic_read(&nesqp->refcount));
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
|
|
|
if (ret)
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "OFA CM event_handler "
|
2011-09-25 14:47:46 +00:00
|
|
|
"returned, ret=%d\n", ret);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2009-09-06 03:36:39 +00:00
|
|
|
if (issue_close) {
|
2008-02-05 04:20:45 +00:00
|
|
|
atomic_inc(&cm_closes);
|
|
|
|
nes_disconnect(nesqp, 1);
|
|
|
|
|
|
|
|
cm_id->provider_data = nesqp;
|
|
|
|
/* Send up the close complete event */
|
|
|
|
cm_event.event = IW_CM_EVENT_CLOSE;
|
2011-05-10 05:23:57 +00:00
|
|
|
cm_event.status = 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.provider_data = cm_id->provider_data;
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_event.local_addr = cm_id->m_local_addr;
|
|
|
|
cm_event.remote_addr = cm_id->m_remote_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.private_data = NULL;
|
|
|
|
cm_event.private_data_len = 0;
|
|
|
|
|
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
2011-09-25 14:47:46 +00:00
|
|
|
if (ret)
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
|
|
|
|
|
|
|
|
cm_id->rem_ref(cm_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_disconnect
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static int nes_disconnect(struct nes_qp *nesqp, int abrupt)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct nes_vnic *nesvnic;
|
|
|
|
struct nes_device *nesdev;
|
2009-03-12 21:34:59 +00:00
|
|
|
struct nes_ib_device *nesibdev;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesvnic = to_nesvnic(nesqp->ibqp.device);
|
|
|
|
if (!nesvnic)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nesdev = nesvnic->nesdev;
|
2009-03-12 21:34:59 +00:00
|
|
|
nesibdev = nesvnic->nesibdev;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
|
net: percpu net_device refcount
We tried very hard to remove all possible dev_hold()/dev_put() pairs in
network stack, using RCU conversions.
There is still an unavoidable device refcount change for every dst we
create/destroy, and this can slow down some workloads (routers or some
app servers, mmap af_packet)
We can switch to a percpu refcount implementation, now dynamic per_cpu
infrastructure is mature. On a 64 cpus machine, this consumes 256 bytes
per device.
On x86, dev_hold(dev) code :
before
lock incl 0x280(%ebx)
after:
movl 0x260(%ebx),%eax
incl fs:(%eax)
Stress bench :
(Sending 160.000.000 UDP frames,
IP route cache disabled, dual E5540 @2.53GHz,
32bit kernel, FIB_TRIE)
Before:
real 1m1.662s
user 0m14.373s
sys 12m55.960s
After:
real 0m51.179s
user 0m15.329s
sys 10m15.942s
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-10-11 10:22:12 +00:00
|
|
|
netdev_refcnt_read(nesvnic->netdev));
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (nesqp->active_conn) {
|
|
|
|
|
|
|
|
/* indicate this connection is NOT active */
|
|
|
|
nesqp->active_conn = 0;
|
|
|
|
} else {
|
|
|
|
/* Need to free the Last Streaming Mode Message */
|
|
|
|
if (nesqp->ietf_frame) {
|
2009-03-12 21:34:59 +00:00
|
|
|
if (nesqp->lsmm_mr)
|
|
|
|
nesibdev->ibdev.dereg_mr(nesqp->lsmm_mr);
|
2008-02-05 04:20:45 +00:00
|
|
|
pci_free_consistent(nesdev->pcidev,
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->private_data_len + nesqp->ietf_frame_size,
|
|
|
|
nesqp->ietf_frame, nesqp->ietf_frame_pbase);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close the CM node down if it is still active */
|
|
|
|
if (nesqp->cm_node) {
|
|
|
|
nes_debug(NES_DBG_CM, "Call close API\n");
|
|
|
|
|
|
|
|
g_cm_core->api->close(g_cm_core, nesqp->cm_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_accept
|
|
|
|
*/
|
|
|
|
int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
|
|
|
|
{
|
|
|
|
u64 u64temp;
|
|
|
|
struct ib_qp *ibqp;
|
|
|
|
struct nes_qp *nesqp;
|
|
|
|
struct nes_vnic *nesvnic;
|
|
|
|
struct nes_device *nesdev;
|
|
|
|
struct nes_cm_node *cm_node;
|
|
|
|
struct nes_adapter *adapter;
|
|
|
|
struct ib_qp_attr attr;
|
|
|
|
struct iw_cm_event cm_event;
|
|
|
|
struct nes_hw_qp_wqe *wqe;
|
|
|
|
struct nes_v4_quad nes_quad;
|
2008-02-21 14:31:22 +00:00
|
|
|
u32 crc_value;
|
2008-02-05 04:20:45 +00:00
|
|
|
int ret;
|
2008-11-22 02:50:46 +00:00
|
|
|
int passive_state;
|
2009-03-12 21:34:59 +00:00
|
|
|
struct ib_mr *ibmr = NULL;
|
|
|
|
struct nes_pd *nespd;
|
2009-04-08 21:21:02 +00:00
|
|
|
u64 tagged_offset;
|
2011-09-25 14:47:46 +00:00
|
|
|
u8 mpa_frame_offset = 0;
|
|
|
|
struct ietf_mpa_v2 *mpa_v2_frame;
|
|
|
|
u8 start_addr = 0;
|
|
|
|
u8 *start_ptr = &start_addr;
|
|
|
|
u8 **start_buff = &start_ptr;
|
|
|
|
u16 buff_len = 0;
|
2016-02-26 15:18:02 +00:00
|
|
|
struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
|
|
|
|
struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
|
2009-03-12 21:34:59 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
|
|
|
|
if (!ibqp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* get all our handles */
|
|
|
|
nesqp = to_nesqp(ibqp);
|
|
|
|
nesvnic = to_nesvnic(nesqp->ibqp.device);
|
|
|
|
nesdev = nesvnic->nesdev;
|
|
|
|
adapter = nesdev->nesadapter;
|
|
|
|
|
|
|
|
cm_node = (struct nes_cm_node *)cm_id->provider_data;
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "nes_accept: cm_node= %p nesvnic=%p, netdev=%p,"
|
|
|
|
"%s\n", cm_node, nesvnic, nesvnic->netdev,
|
|
|
|
nesvnic->netdev->name);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-12-09 23:54:08 +00:00
|
|
|
if (NES_CM_STATE_LISTENER_DESTROYED == cm_node->state) {
|
|
|
|
if (cm_node->loopbackpartner)
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node->loopbackpartner);
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-08-14 21:04:56 +00:00
|
|
|
passive_state = atomic_add_return(1, &cm_node->passive_state);
|
|
|
|
if (passive_state == NES_SEND_RESET_EVENT) {
|
|
|
|
rem_ref_cm_node(cm_node->cm_core, cm_node);
|
|
|
|
return -ECONNRESET;
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
/* associate the node with the QP */
|
|
|
|
nesqp->cm_node = (void *)cm_node;
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->nesqp = nesqp;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2014-03-11 19:17:25 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
|
|
|
|
nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
|
2008-02-05 04:20:45 +00:00
|
|
|
atomic_inc(&cm_accepts);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
|
net: percpu net_device refcount
We tried very hard to remove all possible dev_hold()/dev_put() pairs in
network stack, using RCU conversions.
There is still an unavoidable device refcount change for every dst we
create/destroy, and this can slow down some workloads (routers or some
app servers, mmap af_packet)
We can switch to a percpu refcount implementation, now dynamic per_cpu
infrastructure is mature. On a 64 cpus machine, this consumes 256 bytes
per device.
On x86, dev_hold(dev) code :
before
lock incl 0x280(%ebx)
after:
movl 0x260(%ebx),%eax
incl fs:(%eax)
Stress bench :
(Sending 160.000.000 UDP frames,
IP route cache disabled, dual E5540 @2.53GHz,
32bit kernel, FIB_TRIE)
Before:
real 1m1.662s
user 0m14.373s
sys 12m55.960s
After:
real 0m51.179s
user 0m15.329s
sys 10m15.942s
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-10-11 10:22:12 +00:00
|
|
|
netdev_refcnt_read(nesvnic->netdev));
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->ietf_frame_size = sizeof(struct ietf_mpa_v2);
|
2008-07-25 03:50:45 +00:00
|
|
|
/* allocate the ietf frame and space for private data */
|
|
|
|
nesqp->ietf_frame = pci_alloc_consistent(nesdev->pcidev,
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->ietf_frame_size + conn_param->private_data_len,
|
|
|
|
&nesqp->ietf_frame_pbase);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (!nesqp->ietf_frame) {
|
2011-09-25 14:47:46 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Unable to allocate memory for private data\n");
|
2008-07-25 03:50:45 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2011-09-25 14:47:46 +00:00
|
|
|
mpa_v2_frame = (struct ietf_mpa_v2 *)nesqp->ietf_frame;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
if (cm_node->mpa_frame_rev == IETF_MPA_V1)
|
|
|
|
mpa_frame_offset = 4;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2014-03-11 19:17:25 +00:00
|
|
|
if (cm_node->mpa_frame_rev == IETF_MPA_V1 ||
|
|
|
|
cm_node->mpav2_ird_ord == IETF_NO_IRD_ORD) {
|
|
|
|
record_ird_ord(cm_node, (u16)conn_param->ird, (u16)conn_param->ord);
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
memcpy(mpa_v2_frame->priv_data, conn_param->private_data,
|
|
|
|
conn_param->private_data_len);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_build_mpa_frame(cm_node, start_buff, &buff_len, nesqp->ietf_frame, MPA_KEY_REPLY);
|
|
|
|
nesqp->private_data_len = conn_param->private_data_len;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
/* setup our first outgoing iWarp send WQE (the IETF frame response) */
|
|
|
|
wqe = &nesqp->hwqp.sq_vbase[0];
|
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
if (raddr->sin_addr.s_addr != laddr->sin_addr.s_addr) {
|
2008-07-25 03:50:45 +00:00
|
|
|
u64temp = (unsigned long)nesqp;
|
2009-03-12 21:34:59 +00:00
|
|
|
nespd = nesqp->nespd;
|
2011-09-25 14:47:46 +00:00
|
|
|
tagged_offset = (u64)(unsigned long)*start_buff;
|
2015-12-23 18:12:50 +00:00
|
|
|
ibmr = nes_reg_phys_mr(&nespd->ibpd,
|
|
|
|
nesqp->ietf_frame_pbase + mpa_frame_offset,
|
|
|
|
buff_len, IB_ACCESS_LOCAL_WRITE,
|
|
|
|
&tagged_offset);
|
2016-01-12 09:27:43 +00:00
|
|
|
if (IS_ERR(ibmr)) {
|
2009-03-12 21:34:59 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Unable to register memory region"
|
2011-09-25 14:47:46 +00:00
|
|
|
"for lSMM for cm_node = %p \n",
|
|
|
|
cm_node);
|
2009-04-27 20:45:19 +00:00
|
|
|
pci_free_consistent(nesdev->pcidev,
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->private_data_len + nesqp->ietf_frame_size,
|
|
|
|
nesqp->ietf_frame, nesqp->ietf_frame_pbase);
|
2016-01-12 09:27:43 +00:00
|
|
|
return PTR_ERR(ibmr);
|
2009-03-12 21:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ibmr->pd = &nespd->ibpd;
|
|
|
|
ibmr->device = nespd->ibpd.device;
|
|
|
|
nesqp->lsmm_mr = ibmr;
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
u64temp |= NES_SW_CONTEXT_ALIGN >> 1;
|
2008-07-25 03:50:45 +00:00
|
|
|
set_wqe_64bit_value(wqe->wqe_words,
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_IWARP_SQ_WQE_COMP_CTX_LOW_IDX,
|
|
|
|
u64temp);
|
2008-07-25 03:50:45 +00:00
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_MISC_IDX] =
|
|
|
|
cpu_to_le32(NES_IWARP_SQ_WQE_STREAMING |
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_IWARP_SQ_WQE_WRPDU);
|
2008-07-25 03:50:45 +00:00
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX] =
|
2011-09-25 14:47:46 +00:00
|
|
|
cpu_to_le32(buff_len);
|
2009-03-12 21:34:59 +00:00
|
|
|
set_wqe_64bit_value(wqe->wqe_words,
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_IWARP_SQ_WQE_FRAG0_LOW_IDX,
|
|
|
|
(u64)(unsigned long)(*start_buff));
|
2008-07-25 03:50:45 +00:00
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_LENGTH0_IDX] =
|
2011-09-25 14:47:46 +00:00
|
|
|
cpu_to_le32(buff_len);
|
2009-03-12 21:34:59 +00:00
|
|
|
wqe->wqe_words[NES_IWARP_SQ_WQE_STAG0_IDX] = ibmr->lkey;
|
2009-12-09 23:54:28 +00:00
|
|
|
if (nesqp->sq_kmapped) {
|
|
|
|
nesqp->sq_kmapped = 0;
|
|
|
|
kunmap(nesqp->page);
|
|
|
|
}
|
2008-07-25 03:50:45 +00:00
|
|
|
|
|
|
|
nesqp->nesqp_context->ird_ord_sizes |=
|
|
|
|
cpu_to_le32(NES_QPCONTEXT_ORDIRD_LSMM_PRESENT |
|
2011-09-25 14:47:46 +00:00
|
|
|
NES_QPCONTEXT_ORDIRD_WRPDU);
|
2008-07-25 03:50:45 +00:00
|
|
|
} else {
|
|
|
|
nesqp->nesqp_context->ird_ord_sizes |=
|
2009-03-06 23:15:01 +00:00
|
|
|
cpu_to_le32(NES_QPCONTEXT_ORDIRD_WRPDU);
|
2008-07-25 03:50:45 +00:00
|
|
|
}
|
|
|
|
nesqp->skip_lsmm = 1;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* Cache the cm_id in the qp */
|
|
|
|
nesqp->cm_id = cm_id;
|
|
|
|
cm_node->cm_id = cm_id;
|
|
|
|
|
|
|
|
/* nesqp->cm_node = (void *)cm_id->provider_data; */
|
|
|
|
cm_id->provider_data = nesqp;
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->active_conn = 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if (cm_node->state == NES_CM_STATE_TSA)
|
|
|
|
nes_debug(NES_DBG_CM, "Already state = TSA for cm_node=%p\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_cm_init_tsa_conn(nesqp, cm_node);
|
|
|
|
|
2014-03-26 22:07:57 +00:00
|
|
|
nesqp->nesqp_context->tcpPorts[0] =
|
2016-02-26 15:18:02 +00:00
|
|
|
cpu_to_le16(cm_node->loc_port);
|
2014-03-26 22:07:57 +00:00
|
|
|
nesqp->nesqp_context->tcpPorts[1] =
|
2016-02-26 15:18:02 +00:00
|
|
|
cpu_to_le16(cm_node->rem_port);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2016-02-26 15:18:02 +00:00
|
|
|
nesqp->nesqp_context->ip0 = cpu_to_le32(cm_node->rem_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->nesqp_context->misc2 |= cpu_to_le32(
|
2011-09-25 14:47:46 +00:00
|
|
|
(u32)PCI_FUNC(nesdev->pcidev->devfn) <<
|
|
|
|
NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nesqp->nesqp_context->arp_index_vlan |=
|
|
|
|
cpu_to_le32(nes_arp_table(nesdev,
|
2011-09-25 14:47:46 +00:00
|
|
|
le32_to_cpu(nesqp->nesqp_context->ip0), NULL,
|
|
|
|
NES_ARP_RESOLVE) << 16);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
|
2008-07-25 03:50:45 +00:00
|
|
|
jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->nesqp_context->ird_index = cpu_to_le32(nesqp->hwqp.qp_id);
|
|
|
|
|
|
|
|
nesqp->nesqp_context->ird_ord_sizes |= cpu_to_le32(
|
2008-07-25 03:50:45 +00:00
|
|
|
((u32)1 << NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT));
|
|
|
|
nesqp->nesqp_context->ird_ord_sizes |=
|
2014-03-11 19:17:25 +00:00
|
|
|
cpu_to_le32((u32)cm_node->ord_size);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
memset(&nes_quad, 0, sizeof(nes_quad));
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_quad.DstIpAdrIndex =
|
|
|
|
cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
|
2016-02-26 15:18:02 +00:00
|
|
|
nes_quad.SrcIpadr = htonl(cm_node->rem_addr);
|
|
|
|
nes_quad.TcpPorts[0] = htons(cm_node->rem_port);
|
|
|
|
nes_quad.TcpPorts[1] = htons(cm_node->loc_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* Produce hash key */
|
2008-02-21 14:31:22 +00:00
|
|
|
crc_value = get_crc_value(&nes_quad);
|
|
|
|
nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, CRC = 0x%08X\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->hte_index, nesqp->hte_index & adapter->hte_index_mask);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->hte_index &= adapter->hte_index_mask;
|
|
|
|
nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
|
|
|
|
|
|
|
|
cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "QP%u, Destination IP = 0x%08X:0x%04X, local = "
|
2011-09-25 14:47:46 +00:00
|
|
|
"0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
|
|
|
|
"private data length=%u.\n", nesqp->hwqp.qp_id,
|
2013-07-04 10:40:44 +00:00
|
|
|
ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port),
|
|
|
|
ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port),
|
2011-09-25 14:47:46 +00:00
|
|
|
le32_to_cpu(nesqp->nesqp_context->rcv_nxt),
|
|
|
|
le32_to_cpu(nesqp->nesqp_context->snd_nxt),
|
|
|
|
buff_len);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-01-08 02:09:16 +00:00
|
|
|
/* notify OF layer that accept event was successful */
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_id->add_ref(cm_id);
|
2009-04-27 20:45:19 +00:00
|
|
|
nes_add_ref(&nesqp->ibqp);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
cm_event.event = IW_CM_EVENT_ESTABLISHED;
|
2011-05-10 05:23:57 +00:00
|
|
|
cm_event.status = 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.provider_data = (void *)nesqp;
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_event.local_addr = cm_id->m_local_addr;
|
|
|
|
cm_event.remote_addr = cm_id->m_remote_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.private_data = NULL;
|
|
|
|
cm_event.private_data_len = 0;
|
2014-03-11 19:17:25 +00:00
|
|
|
cm_event.ird = cm_node->ird_size;
|
|
|
|
cm_event.ord = cm_node->ord_size;
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
2008-11-22 02:50:46 +00:00
|
|
|
attr.qp_state = IB_QPS_RTS;
|
|
|
|
nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (cm_node->loopbackpartner) {
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->loopbackpartner->mpa_frame_size =
|
|
|
|
nesqp->private_data_len;
|
2008-02-05 04:20:45 +00:00
|
|
|
/* copy entire MPA frame to our cm_node's frame */
|
2008-07-25 03:50:45 +00:00
|
|
|
memcpy(cm_node->loopbackpartner->mpa_frame_buf,
|
2011-09-25 14:47:46 +00:00
|
|
|
conn_param->private_data, conn_param->private_data_len);
|
2008-02-05 04:20:45 +00:00
|
|
|
create_event(cm_node->loopbackpartner, NES_CM_EVENT_CONNECTED);
|
|
|
|
}
|
|
|
|
if (ret)
|
2008-07-25 03:50:45 +00:00
|
|
|
printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"ret=%d\n", __func__, __LINE__, ret);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_reject
|
|
|
|
*/
|
|
|
|
int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
|
|
|
|
{
|
|
|
|
struct nes_cm_node *cm_node;
|
2009-03-06 23:15:01 +00:00
|
|
|
struct nes_cm_node *loopback;
|
2008-02-05 04:20:45 +00:00
|
|
|
struct nes_cm_core *cm_core;
|
2011-09-25 14:47:46 +00:00
|
|
|
u8 *start_buff;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
atomic_inc(&cm_rejects);
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node = (struct nes_cm_node *)cm_id->provider_data;
|
2009-03-06 23:15:01 +00:00
|
|
|
loopback = cm_node->loopbackpartner;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_core = cm_node->cm_core;
|
2009-03-06 23:15:01 +00:00
|
|
|
cm_node->cm_id = cm_id;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
if (pdata_len + sizeof(struct ietf_mpa_v2) > MAX_CM_BUFFER)
|
2009-03-06 23:15:01 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (loopback) {
|
|
|
|
memcpy(&loopback->mpa_frame.priv_data, pdata, pdata_len);
|
|
|
|
loopback->mpa_frame.priv_data_len = pdata_len;
|
2011-09-25 14:47:46 +00:00
|
|
|
loopback->mpa_frame_size = pdata_len;
|
2009-03-06 23:15:01 +00:00
|
|
|
} else {
|
2011-09-25 14:47:46 +00:00
|
|
|
start_buff = &cm_node->mpa_frame_buf[0] + sizeof(struct ietf_mpa_v2);
|
|
|
|
cm_node->mpa_frame_size = pdata_len;
|
|
|
|
memcpy(start_buff, pdata, pdata_len);
|
2009-03-06 23:15:01 +00:00
|
|
|
}
|
2011-09-25 14:47:46 +00:00
|
|
|
return cm_core->api->reject(cm_core, cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_connect
|
|
|
|
* setup and launch cm connect node
|
|
|
|
*/
|
|
|
|
int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
|
|
|
|
{
|
|
|
|
struct ib_qp *ibqp;
|
|
|
|
struct nes_qp *nesqp;
|
|
|
|
struct nes_vnic *nesvnic;
|
|
|
|
struct nes_device *nesdev;
|
|
|
|
struct nes_cm_node *cm_node;
|
|
|
|
struct nes_cm_info cm_info;
|
2009-04-27 20:37:34 +00:00
|
|
|
int apbvt_set = 0;
|
2016-02-26 15:18:02 +00:00
|
|
|
struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
|
|
|
|
struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
if (cm_id->remote_addr.ss_family != AF_INET)
|
|
|
|
return -ENOSYS;
|
2008-02-05 04:20:45 +00:00
|
|
|
ibqp = nes_get_qp(cm_id->device, conn_param->qpn);
|
|
|
|
if (!ibqp)
|
|
|
|
return -EINVAL;
|
|
|
|
nesqp = to_nesqp(ibqp);
|
|
|
|
if (!nesqp)
|
|
|
|
return -EINVAL;
|
|
|
|
nesvnic = to_nesvnic(nesqp->ibqp.device);
|
|
|
|
if (!nesvnic)
|
|
|
|
return -EINVAL;
|
2011-09-25 14:47:46 +00:00
|
|
|
nesdev = nesvnic->nesdev;
|
2008-02-05 04:20:45 +00:00
|
|
|
if (!nesdev)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
if (!laddr->sin_port || !raddr->sin_port)
|
2009-12-09 23:54:08 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "QP%u, current IP = 0x%08X, Destination IP = "
|
2011-09-25 14:47:46 +00:00
|
|
|
"0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp->hwqp.qp_id,
|
2013-07-04 10:40:44 +00:00
|
|
|
ntohl(nesvnic->local_ipaddr), ntohl(raddr->sin_addr.s_addr),
|
|
|
|
ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
|
|
|
|
ntohs(laddr->sin_port));
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
atomic_inc(&cm_connects);
|
2008-02-05 04:20:45 +00:00
|
|
|
nesqp->active_conn = 1;
|
|
|
|
|
|
|
|
/* cache the cm_id in the qp */
|
|
|
|
nesqp->cm_id = cm_id;
|
|
|
|
cm_id->provider_data = nesqp;
|
|
|
|
nesqp->private_data_len = conn_param->private_data_len;
|
2012-05-11 15:46:16 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "requested ord = 0x%08X.\n", (u32)conn_param->ord);
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "mpa private data len =%u\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
conn_param->private_data_len);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2014-03-26 22:07:57 +00:00
|
|
|
/* set up the connection params for the node */
|
|
|
|
cm_info.loc_addr = ntohl(laddr->sin_addr.s_addr);
|
|
|
|
cm_info.loc_port = ntohs(laddr->sin_port);
|
|
|
|
cm_info.rem_addr = ntohl(raddr->sin_addr.s_addr);
|
|
|
|
cm_info.rem_port = ntohs(raddr->sin_port);
|
|
|
|
cm_info.cm_id = cm_id;
|
|
|
|
cm_info.conn_type = NES_CM_IWARP_CONN_TYPE;
|
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
if (laddr->sin_addr.s_addr != raddr->sin_addr.s_addr) {
|
2016-02-26 15:18:02 +00:00
|
|
|
nes_manage_apbvt(nesvnic, cm_info.loc_port,
|
|
|
|
PCI_FUNC(nesdev->pcidev->devfn),
|
|
|
|
NES_MANAGE_APBVT_ADD);
|
2009-04-27 20:37:34 +00:00
|
|
|
apbvt_set = 1;
|
|
|
|
}
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
cm_id->add_ref(cm_id);
|
|
|
|
|
|
|
|
/* create a connect CM node connection */
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node = g_cm_core->api->connect(g_cm_core, nesvnic,
|
2011-09-25 14:47:46 +00:00
|
|
|
conn_param->private_data_len, (void *)conn_param->private_data,
|
|
|
|
&cm_info);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (!cm_node) {
|
2009-04-27 20:37:34 +00:00
|
|
|
if (apbvt_set)
|
2016-02-26 15:18:02 +00:00
|
|
|
nes_manage_apbvt(nesvnic, cm_info.loc_port,
|
2011-09-25 14:47:46 +00:00
|
|
|
PCI_FUNC(nesdev->pcidev->devfn),
|
|
|
|
NES_MANAGE_APBVT_DEL);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2016-02-26 15:18:02 +00:00
|
|
|
nes_debug(NES_DBG_NLMSG, "Delete loc_port = %04X\n",
|
|
|
|
cm_info.loc_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_id->rem_ref(cm_id);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2014-03-11 19:17:25 +00:00
|
|
|
record_ird_ord(cm_node, (u16)conn_param->ird, (u16)conn_param->ord);
|
|
|
|
if (cm_node->send_rdma0_op == SEND_RDMA_READ_ZERO &&
|
|
|
|
cm_node->ord_size == 0)
|
|
|
|
cm_node->ord_size = 1;
|
|
|
|
|
2009-04-27 20:37:34 +00:00
|
|
|
cm_node->apbvt_set = apbvt_set;
|
2015-05-18 20:28:14 +00:00
|
|
|
cm_node->tos = cm_id->tos;
|
2008-02-05 04:20:45 +00:00
|
|
|
nesqp->cm_node = cm_node;
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_node->nesqp = nesqp;
|
2008-09-16 18:56:26 +00:00
|
|
|
nes_add_ref(&nesqp->ibqp);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_create_listen
|
|
|
|
*/
|
|
|
|
int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
|
|
|
|
{
|
|
|
|
struct nes_vnic *nesvnic;
|
|
|
|
struct nes_cm_listener *cm_node;
|
|
|
|
struct nes_cm_info cm_info;
|
|
|
|
int err;
|
2016-02-26 15:18:02 +00:00
|
|
|
struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "cm_id = %p, local port = 0x%04X.\n",
|
2013-07-04 10:40:44 +00:00
|
|
|
cm_id, ntohs(laddr->sin_port));
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2016-02-26 15:18:02 +00:00
|
|
|
if (cm_id->m_local_addr.ss_family != AF_INET)
|
2013-07-04 10:40:44 +00:00
|
|
|
return -ENOSYS;
|
2008-02-05 04:20:45 +00:00
|
|
|
nesvnic = to_nesvnic(cm_id->device);
|
|
|
|
if (!nesvnic)
|
|
|
|
return -EINVAL;
|
2010-08-04 21:25:40 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "nesvnic=%p, netdev=%p, %s\n",
|
|
|
|
nesvnic, nesvnic->netdev, nesvnic->netdev->name);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "nesvnic->local_ipaddr=0x%08x, sin_addr.s_addr=0x%08x\n",
|
2013-07-04 10:40:44 +00:00
|
|
|
nesvnic->local_ipaddr, laddr->sin_addr.s_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* setup listen params in our api call struct */
|
2014-03-26 22:07:57 +00:00
|
|
|
cm_info.loc_addr = ntohl(nesvnic->local_ipaddr);
|
|
|
|
cm_info.loc_port = ntohs(laddr->sin_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_info.backlog = backlog;
|
|
|
|
cm_info.cm_id = cm_id;
|
|
|
|
|
|
|
|
cm_info.conn_type = NES_CM_IWARP_CONN_TYPE;
|
|
|
|
|
|
|
|
cm_node = g_cm_core->api->listen(g_cm_core, nesvnic, &cm_info);
|
|
|
|
if (!cm_node) {
|
2008-07-25 03:50:45 +00:00
|
|
|
printk(KERN_ERR "%s[%u] Error returned from listen API call\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
__func__, __LINE__);
|
2008-02-05 04:20:45 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
cm_id->provider_data = cm_node;
|
2015-05-18 20:28:14 +00:00
|
|
|
cm_node->tos = cm_id->tos;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
if (!cm_node->reused_node) {
|
2016-02-26 15:18:02 +00:00
|
|
|
err = nes_manage_apbvt(nesvnic, cm_node->loc_port,
|
2011-09-25 14:47:46 +00:00
|
|
|
PCI_FUNC(nesvnic->nesdev->pcidev->devfn),
|
|
|
|
NES_MANAGE_APBVT_ADD);
|
2008-02-05 04:20:45 +00:00
|
|
|
if (err) {
|
2008-07-25 03:50:45 +00:00
|
|
|
printk(KERN_ERR "nes_manage_apbvt call returned %d.\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
err);
|
2008-02-05 04:20:45 +00:00
|
|
|
g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
|
|
|
|
return err;
|
|
|
|
}
|
2010-02-12 19:55:03 +00:00
|
|
|
atomic_inc(&cm_listens_created);
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cm_id->add_ref(cm_id);
|
|
|
|
cm_id->provider_data = (void *)cm_node;
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_destroy_listen
|
|
|
|
*/
|
|
|
|
int nes_destroy_listen(struct iw_cm_id *cm_id)
|
|
|
|
{
|
|
|
|
if (cm_id->provider_data)
|
|
|
|
g_cm_core->api->stop_listener(g_cm_core, cm_id->provider_data);
|
|
|
|
else
|
|
|
|
nes_debug(NES_DBG_CM, "cm_id->provider_data was NULL\n");
|
|
|
|
|
|
|
|
cm_id->rem_ref(cm_id);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_recv
|
|
|
|
*/
|
|
|
|
int nes_cm_recv(struct sk_buff *skb, struct net_device *netdevice)
|
|
|
|
{
|
2008-11-22 02:50:49 +00:00
|
|
|
int rc = 0;
|
2011-09-25 14:47:46 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_packets_received++;
|
2011-09-25 14:47:46 +00:00
|
|
|
if ((g_cm_core) && (g_cm_core->api))
|
2008-11-22 02:50:49 +00:00
|
|
|
rc = g_cm_core->api->recv_pkt(g_cm_core, netdev_priv(netdevice), skb);
|
2011-09-25 14:47:46 +00:00
|
|
|
else
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Unable to process packet for CM,"
|
2011-09-25 14:47:46 +00:00
|
|
|
" cm is not setup properly.\n");
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-11-22 02:50:49 +00:00
|
|
|
return rc;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_start
|
|
|
|
* Start and init a cm core module
|
|
|
|
*/
|
|
|
|
int nes_cm_start(void)
|
|
|
|
{
|
|
|
|
nes_debug(NES_DBG_CM, "\n");
|
|
|
|
/* create the primary CM core, pass this handle to subsequent core inits */
|
|
|
|
g_cm_core = nes_cm_alloc_core();
|
2011-09-25 14:47:46 +00:00
|
|
|
if (g_cm_core)
|
2008-02-05 04:20:45 +00:00
|
|
|
return 0;
|
2011-09-25 14:47:46 +00:00
|
|
|
else
|
2008-02-05 04:20:45 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_stop
|
|
|
|
* stop and dealloc all cm core instances
|
|
|
|
*/
|
|
|
|
int nes_cm_stop(void)
|
|
|
|
{
|
|
|
|
g_cm_core->api->destroy_cm_core(g_cm_core);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cm_event_connected
|
|
|
|
* handle a connected event, setup QPs and HW
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static void cm_event_connected(struct nes_cm_event *event)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct nes_qp *nesqp;
|
|
|
|
struct nes_vnic *nesvnic;
|
|
|
|
struct nes_device *nesdev;
|
|
|
|
struct nes_cm_node *cm_node;
|
|
|
|
struct nes_adapter *nesadapter;
|
|
|
|
struct ib_qp_attr attr;
|
|
|
|
struct iw_cm_id *cm_id;
|
|
|
|
struct iw_cm_event cm_event;
|
|
|
|
struct nes_v4_quad nes_quad;
|
2008-02-21 14:31:22 +00:00
|
|
|
u32 crc_value;
|
2008-02-05 04:20:45 +00:00
|
|
|
int ret;
|
2013-07-04 10:40:44 +00:00
|
|
|
struct sockaddr_in *laddr;
|
|
|
|
struct sockaddr_in *raddr;
|
|
|
|
struct sockaddr_in *cm_event_laddr;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* get all our handles */
|
|
|
|
cm_node = event->cm_node;
|
|
|
|
cm_id = cm_node->cm_id;
|
|
|
|
nes_debug(NES_DBG_CM, "cm_event_connected - %p - cm_id = %p\n", cm_node, cm_id);
|
|
|
|
nesqp = (struct nes_qp *)cm_id->provider_data;
|
|
|
|
nesvnic = to_nesvnic(nesqp->ibqp.device);
|
|
|
|
nesdev = nesvnic->nesdev;
|
|
|
|
nesadapter = nesdev->nesadapter;
|
2016-02-26 15:18:02 +00:00
|
|
|
laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
|
|
|
|
raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
|
2013-07-04 10:40:44 +00:00
|
|
|
cm_event_laddr = (struct sockaddr_in *)&cm_event.local_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
if (nesqp->destroyed)
|
2008-02-05 04:20:45 +00:00
|
|
|
return;
|
|
|
|
atomic_inc(&cm_connecteds);
|
|
|
|
nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
|
2011-09-25 14:47:46 +00:00
|
|
|
" local port 0x%04X. jiffies = %lu.\n",
|
2013-07-04 10:40:44 +00:00
|
|
|
nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
|
|
|
|
ntohs(raddr->sin_port), ntohs(laddr->sin_port), jiffies);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nes_cm_init_tsa_conn(nesqp, cm_node);
|
|
|
|
|
|
|
|
/* set the QP tsa context */
|
2014-03-26 22:07:57 +00:00
|
|
|
nesqp->nesqp_context->tcpPorts[0] =
|
2016-02-26 15:18:02 +00:00
|
|
|
cpu_to_le16(cm_node->loc_port);
|
2014-03-26 22:07:57 +00:00
|
|
|
nesqp->nesqp_context->tcpPorts[1] =
|
2016-02-26 15:18:02 +00:00
|
|
|
cpu_to_le16(cm_node->rem_port);
|
|
|
|
nesqp->nesqp_context->ip0 = cpu_to_le32(cm_node->rem_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->nesqp_context->misc2 |= cpu_to_le32(
|
2008-07-25 03:50:45 +00:00
|
|
|
(u32)PCI_FUNC(nesdev->pcidev->devfn) <<
|
|
|
|
NES_QPCONTEXT_MISC2_SRC_IP_SHIFT);
|
2008-02-05 04:20:45 +00:00
|
|
|
nesqp->nesqp_context->arp_index_vlan |= cpu_to_le32(
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_arp_table(nesdev,
|
|
|
|
le32_to_cpu(nesqp->nesqp_context->ip0),
|
2008-02-05 04:20:45 +00:00
|
|
|
NULL, NES_ARP_RESOLVE) << 16);
|
|
|
|
nesqp->nesqp_context->ts_val_delta = cpu_to_le32(
|
|
|
|
jiffies - nes_read_indexed(nesdev, NES_IDX_TCP_NOW));
|
|
|
|
nesqp->nesqp_context->ird_index = cpu_to_le32(nesqp->hwqp.qp_id);
|
|
|
|
nesqp->nesqp_context->ird_ord_sizes |=
|
2008-07-25 03:50:45 +00:00
|
|
|
cpu_to_le32((u32)1 <<
|
|
|
|
NES_QPCONTEXT_ORDIRD_IWARP_MODE_SHIFT);
|
2014-03-11 19:17:25 +00:00
|
|
|
nesqp->nesqp_context->ird_ord_sizes |=
|
|
|
|
cpu_to_le32((u32)cm_node->ord_size);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* Adjust tail for not having a LSMM */
|
2011-09-25 14:47:46 +00:00
|
|
|
/*nesqp->hwqp.sq_tail = 1;*/
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
build_rdma0_msg(cm_node, &nesqp);
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
nes_write32(nesdev->regs + NES_WQE_ALLOC,
|
|
|
|
(1 << 24) | 0x00800000 | nesqp->hwqp.qp_id);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
memset(&nes_quad, 0, sizeof(nes_quad));
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_quad.DstIpAdrIndex =
|
|
|
|
cpu_to_le32((u32)PCI_FUNC(nesdev->pcidev->devfn) << 24);
|
2016-02-26 15:18:02 +00:00
|
|
|
nes_quad.SrcIpadr = htonl(cm_node->rem_addr);
|
|
|
|
nes_quad.TcpPorts[0] = htons(cm_node->rem_port);
|
|
|
|
nes_quad.TcpPorts[1] = htons(cm_node->loc_port);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
/* Produce hash key */
|
2008-02-21 14:31:22 +00:00
|
|
|
crc_value = get_crc_value(&nes_quad);
|
|
|
|
nesqp->hte_index = cpu_to_be32(crc_value ^ 0xffffffff);
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "HTE Index = 0x%08X, After CRC = 0x%08X\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->hte_index, nesqp->hte_index & nesadapter->hte_index_mask);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->hte_index &= nesadapter->hte_index_mask;
|
|
|
|
nesqp->nesqp_context->hte_index = cpu_to_le32(nesqp->hte_index);
|
|
|
|
|
|
|
|
nesqp->ietf_frame = &cm_node->mpa_frame;
|
2011-09-25 14:47:46 +00:00
|
|
|
nesqp->private_data_len = (u8)cm_node->mpa_frame_size;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
|
|
|
|
|
|
|
|
/* notify OF layer we successfully created the requested connection */
|
|
|
|
cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
|
2011-05-10 05:23:57 +00:00
|
|
|
cm_event.status = 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.provider_data = cm_id->provider_data;
|
2013-07-04 10:40:44 +00:00
|
|
|
cm_event_laddr->sin_family = AF_INET;
|
|
|
|
cm_event_laddr->sin_port = laddr->sin_port;
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_event.remote_addr = cm_id->m_remote_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_event.private_data = (void *)event->cm_node->mpa_frame_buf;
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_event.private_data_len = (u8)event->cm_node->mpa_frame_size;
|
|
|
|
cm_event.ird = cm_node->ird_size;
|
|
|
|
cm_event.ord = cm_node->ord_size;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_event_laddr->sin_addr.s_addr = htonl(event->cm_info.loc_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
|
|
|
nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
|
|
|
|
|
|
|
|
if (ret)
|
2008-07-25 03:50:45 +00:00
|
|
|
printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"ret=%d\n", __func__, __LINE__, ret);
|
2008-07-25 03:50:45 +00:00
|
|
|
attr.qp_state = IB_QPS_RTS;
|
|
|
|
nes_modify_qp(&nesqp->ibqp, &attr, IB_QP_STATE, NULL);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "Exiting connect thread for QP%u. jiffies = "
|
2011-09-25 14:47:46 +00:00
|
|
|
"%lu\n", nesqp->hwqp.qp_id, jiffies);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cm_event_connect_error
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static void cm_event_connect_error(struct nes_cm_event *event)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct nes_qp *nesqp;
|
|
|
|
struct iw_cm_id *cm_id;
|
|
|
|
struct iw_cm_event cm_event;
|
|
|
|
/* struct nes_cm_info cm_info; */
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!event->cm_node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cm_id = event->cm_node->cm_id;
|
2011-09-25 14:47:46 +00:00
|
|
|
if (!cm_id)
|
2008-02-05 04:20:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "cm_node=%p, cm_id=%p\n", event->cm_node, cm_id);
|
|
|
|
nesqp = cm_id->provider_data;
|
|
|
|
|
2011-09-25 14:47:46 +00:00
|
|
|
if (!nesqp)
|
2008-02-05 04:20:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* notify OF layer about this connection error event */
|
|
|
|
/* cm_id->rem_ref(cm_id); */
|
|
|
|
nesqp->cm_id = NULL;
|
|
|
|
cm_id->provider_data = NULL;
|
|
|
|
cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
|
2009-12-09 23:54:08 +00:00
|
|
|
cm_event.status = -ECONNRESET;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.provider_data = cm_id->provider_data;
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_event.local_addr = cm_id->m_local_addr;
|
|
|
|
cm_event.remote_addr = cm_id->m_remote_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.private_data = NULL;
|
|
|
|
cm_event.private_data_len = 0;
|
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
#ifdef CONFIG_INFINIBAND_NES_DEBUG
|
|
|
|
{
|
|
|
|
struct sockaddr_in *cm_event_laddr = (struct sockaddr_in *)
|
|
|
|
&cm_event.local_addr;
|
|
|
|
struct sockaddr_in *cm_event_raddr = (struct sockaddr_in *)
|
|
|
|
&cm_event.remote_addr;
|
|
|
|
nes_debug(NES_DBG_CM, "call CM_EVENT REJECTED, local_addr=%08x, remote_addr=%08x\n",
|
|
|
|
cm_event_laddr->sin_addr.s_addr, cm_event_raddr->sin_addr.s_addr);
|
|
|
|
}
|
|
|
|
#endif
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
|
|
|
nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
|
|
|
|
if (ret)
|
2008-07-25 03:50:45 +00:00
|
|
|
printk(KERN_ERR "%s[%u] OFA CM event_handler returned, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"ret=%d\n", __func__, __LINE__, ret);
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_id->rem_ref(cm_id);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
rem_ref_cm_node(event->cm_node->cm_core, event->cm_node);
|
2008-02-05 04:20:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cm_event_reset
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static void cm_event_reset(struct nes_cm_event *event)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
struct nes_qp *nesqp;
|
|
|
|
struct iw_cm_id *cm_id;
|
|
|
|
struct iw_cm_event cm_event;
|
|
|
|
/* struct nes_cm_info cm_info; */
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!event->cm_node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!event->cm_node->cm_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cm_id = event->cm_node->cm_id;
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "%p - cm_id = %p\n", event->cm_node, cm_id);
|
|
|
|
nesqp = cm_id->provider_data;
|
2009-12-09 23:54:14 +00:00
|
|
|
if (!nesqp)
|
|
|
|
return;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
nesqp->cm_id = NULL;
|
|
|
|
/* cm_id->provider_data = NULL; */
|
|
|
|
cm_event.event = IW_CM_EVENT_DISCONNECT;
|
2011-05-10 05:23:57 +00:00
|
|
|
cm_event.status = -ECONNRESET;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.provider_data = cm_id->provider_data;
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_event.local_addr = cm_id->m_local_addr;
|
|
|
|
cm_event.remote_addr = cm_id->m_remote_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.private_data = NULL;
|
|
|
|
cm_event.private_data_len = 0;
|
|
|
|
|
2008-11-22 02:50:46 +00:00
|
|
|
cm_id->add_ref(cm_id);
|
2009-12-09 23:54:14 +00:00
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
2008-11-22 02:50:46 +00:00
|
|
|
atomic_inc(&cm_closes);
|
|
|
|
cm_event.event = IW_CM_EVENT_CLOSE;
|
2011-05-10 05:23:57 +00:00
|
|
|
cm_event.status = 0;
|
2008-11-22 02:50:46 +00:00
|
|
|
cm_event.provider_data = cm_id->provider_data;
|
2016-02-26 15:18:02 +00:00
|
|
|
cm_event.local_addr = cm_id->m_local_addr;
|
|
|
|
cm_event.remote_addr = cm_id->m_remote_addr;
|
2008-11-22 02:50:46 +00:00
|
|
|
cm_event.private_data = NULL;
|
|
|
|
cm_event.private_data_len = 0;
|
|
|
|
nes_debug(NES_DBG_CM, "NODE %p Generating CLOSE\n", event->cm_node);
|
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "OFA CM event_handler returned, ret=%d\n", ret);
|
|
|
|
|
|
|
|
|
|
|
|
/* notify OF layer about this connection error event */
|
|
|
|
cm_id->rem_ref(cm_id);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cm_event_mpa_req
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static void cm_event_mpa_req(struct nes_cm_event *event)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
2011-09-25 14:47:46 +00:00
|
|
|
struct iw_cm_id *cm_id;
|
2008-02-05 04:20:45 +00:00
|
|
|
struct iw_cm_event cm_event;
|
|
|
|
int ret;
|
|
|
|
struct nes_cm_node *cm_node;
|
2013-07-04 10:40:44 +00:00
|
|
|
struct sockaddr_in *cm_event_laddr = (struct sockaddr_in *)
|
|
|
|
&cm_event.local_addr;
|
|
|
|
struct sockaddr_in *cm_event_raddr = (struct sockaddr_in *)
|
|
|
|
&cm_event.remote_addr;
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
cm_node = event->cm_node;
|
|
|
|
if (!cm_node)
|
|
|
|
return;
|
|
|
|
cm_id = cm_node->cm_id;
|
|
|
|
|
|
|
|
atomic_inc(&cm_connect_reqs);
|
|
|
|
nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node, cm_id, jiffies);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
cm_event.event = IW_CM_EVENT_CONNECT_REQUEST;
|
2011-05-10 05:23:57 +00:00
|
|
|
cm_event.status = 0;
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_event.provider_data = (void *)cm_node;
|
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
cm_event_laddr->sin_family = AF_INET;
|
|
|
|
cm_event_laddr->sin_port = htons(event->cm_info.loc_port);
|
|
|
|
cm_event_laddr->sin_addr.s_addr = htonl(event->cm_info.loc_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
cm_event_raddr->sin_family = AF_INET;
|
|
|
|
cm_event_raddr->sin_port = htons(event->cm_info.rem_port);
|
|
|
|
cm_event_raddr->sin_addr.s_addr = htonl(event->cm_info.rem_addr);
|
2009-03-06 23:15:01 +00:00
|
|
|
cm_event.private_data = cm_node->mpa_frame_buf;
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_event.private_data_len = (u8)cm_node->mpa_frame_size;
|
2014-03-11 19:17:25 +00:00
|
|
|
if (cm_node->mpa_frame_rev == IETF_MPA_V1) {
|
|
|
|
cm_event.ird = NES_MAX_IRD;
|
|
|
|
cm_event.ord = NES_MAX_ORD;
|
|
|
|
} else {
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_event.ird = cm_node->ird_size;
|
|
|
|
cm_event.ord = cm_node->ord_size;
|
2014-03-11 19:17:25 +00:00
|
|
|
}
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "%s[%u] OFA CM event_handler returned, ret=%d\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
__func__, __LINE__, ret);
|
2009-03-06 23:15:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void cm_event_mpa_reject(struct nes_cm_event *event)
|
|
|
|
{
|
2011-09-25 14:47:46 +00:00
|
|
|
struct iw_cm_id *cm_id;
|
2009-03-06 23:15:01 +00:00
|
|
|
struct iw_cm_event cm_event;
|
|
|
|
struct nes_cm_node *cm_node;
|
|
|
|
int ret;
|
2013-07-04 10:40:44 +00:00
|
|
|
struct sockaddr_in *cm_event_laddr = (struct sockaddr_in *)
|
|
|
|
&cm_event.local_addr;
|
|
|
|
struct sockaddr_in *cm_event_raddr = (struct sockaddr_in *)
|
|
|
|
&cm_event.remote_addr;
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
cm_node = event->cm_node;
|
|
|
|
if (!cm_node)
|
|
|
|
return;
|
|
|
|
cm_id = cm_node->cm_id;
|
|
|
|
|
|
|
|
atomic_inc(&cm_connect_reqs);
|
|
|
|
nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_node, cm_id, jiffies);
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
|
|
|
|
cm_event.status = -ECONNREFUSED;
|
|
|
|
cm_event.provider_data = cm_id->provider_data;
|
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
cm_event_laddr->sin_family = AF_INET;
|
|
|
|
cm_event_laddr->sin_port = htons(event->cm_info.loc_port);
|
|
|
|
cm_event_laddr->sin_addr.s_addr = htonl(event->cm_info.loc_addr);
|
2009-03-06 23:15:01 +00:00
|
|
|
|
2013-07-04 10:40:44 +00:00
|
|
|
cm_event_raddr->sin_family = AF_INET;
|
|
|
|
cm_event_raddr->sin_port = htons(event->cm_info.rem_port);
|
|
|
|
cm_event_raddr->sin_addr.s_addr = htonl(event->cm_info.rem_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
2009-03-06 23:15:01 +00:00
|
|
|
cm_event.private_data = cm_node->mpa_frame_buf;
|
2011-09-25 14:47:46 +00:00
|
|
|
cm_event.private_data_len = (u8)cm_node->mpa_frame_size;
|
2009-03-06 23:15:01 +00:00
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "call CM_EVENT_MPA_REJECTED, local_addr=%08x, "
|
2011-09-25 14:47:46 +00:00
|
|
|
"remove_addr=%08x\n",
|
2013-07-04 10:40:44 +00:00
|
|
|
cm_event_laddr->sin_addr.s_addr,
|
|
|
|
cm_event_raddr->sin_addr.s_addr);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
ret = cm_id->event_handler(cm_id, &cm_event);
|
|
|
|
if (ret)
|
2009-03-06 23:15:01 +00:00
|
|
|
printk(KERN_ERR "%s[%u] OFA CM event_handler returned, ret=%d\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
__func__, __LINE__, ret);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void nes_cm_event_handler(struct work_struct *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_post_event
|
|
|
|
* post an event to the cm event handler
|
|
|
|
*/
|
2008-04-17 04:01:09 +00:00
|
|
|
static int nes_cm_post_event(struct nes_cm_event *event)
|
2008-02-05 04:20:45 +00:00
|
|
|
{
|
|
|
|
atomic_inc(&event->cm_node->cm_core->events_posted);
|
|
|
|
add_ref_cm_node(event->cm_node);
|
|
|
|
event->cm_info.cm_id->add_ref(event->cm_info.cm_id);
|
|
|
|
INIT_WORK(&event->event_work, nes_cm_event_handler);
|
2008-07-25 03:50:45 +00:00
|
|
|
nes_debug(NES_DBG_CM, "cm_node=%p queue_work, event=%p\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
event->cm_node, event);
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
queue_work(event->cm_node->cm_core->event_wq, &event->event_work);
|
|
|
|
|
|
|
|
nes_debug(NES_DBG_CM, "Exit\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nes_cm_event_handler
|
|
|
|
* worker function to handle cm events
|
|
|
|
* will free instance of nes_cm_event
|
|
|
|
*/
|
|
|
|
static void nes_cm_event_handler(struct work_struct *work)
|
|
|
|
{
|
2008-07-25 03:50:45 +00:00
|
|
|
struct nes_cm_event *event = container_of(work, struct nes_cm_event,
|
2011-09-25 14:47:46 +00:00
|
|
|
event_work);
|
2008-02-05 04:20:45 +00:00
|
|
|
struct nes_cm_core *cm_core;
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
if ((!event) || (!event->cm_node) || (!event->cm_node->cm_core))
|
2008-02-05 04:20:45 +00:00
|
|
|
return;
|
2008-07-25 03:50:45 +00:00
|
|
|
|
2008-02-05 04:20:45 +00:00
|
|
|
cm_core = event->cm_node->cm_core;
|
|
|
|
nes_debug(NES_DBG_CM, "event=%p, event->type=%u, events posted=%u\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
event, event->type, atomic_read(&cm_core->events_posted));
|
2008-02-05 04:20:45 +00:00
|
|
|
|
|
|
|
switch (event->type) {
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_EVENT_MPA_REQ:
|
|
|
|
cm_event_mpa_req(event);
|
|
|
|
nes_debug(NES_DBG_CM, "cm_node=%p CM Event: MPA REQUEST\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
event->cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
break;
|
|
|
|
case NES_CM_EVENT_RESET:
|
|
|
|
nes_debug(NES_DBG_CM, "cm_node = %p CM Event: RESET\n",
|
2011-09-25 14:47:46 +00:00
|
|
|
event->cm_node);
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_event_reset(event);
|
|
|
|
break;
|
|
|
|
case NES_CM_EVENT_CONNECTED:
|
|
|
|
if ((!event->cm_node->cm_id) ||
|
2011-09-25 14:47:46 +00:00
|
|
|
(event->cm_node->state != NES_CM_STATE_TSA))
|
2008-02-05 04:20:45 +00:00
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_event_connected(event);
|
|
|
|
nes_debug(NES_DBG_CM, "CM Event: CONNECTED\n");
|
|
|
|
break;
|
2009-03-06 23:15:01 +00:00
|
|
|
case NES_CM_EVENT_MPA_REJECT:
|
|
|
|
if ((!event->cm_node->cm_id) ||
|
2011-09-25 14:47:46 +00:00
|
|
|
(event->cm_node->state == NES_CM_STATE_TSA))
|
2009-03-06 23:15:01 +00:00
|
|
|
break;
|
|
|
|
cm_event_mpa_reject(event);
|
|
|
|
nes_debug(NES_DBG_CM, "CM Event: REJECT\n");
|
|
|
|
break;
|
|
|
|
|
2008-07-25 03:50:45 +00:00
|
|
|
case NES_CM_EVENT_ABORTED:
|
|
|
|
if ((!event->cm_node->cm_id) ||
|
2011-09-25 14:47:46 +00:00
|
|
|
(event->cm_node->state == NES_CM_STATE_TSA))
|
2008-02-05 04:20:45 +00:00
|
|
|
break;
|
2008-07-25 03:50:45 +00:00
|
|
|
cm_event_connect_error(event);
|
|
|
|
nes_debug(NES_DBG_CM, "CM Event: ABORTED\n");
|
|
|
|
break;
|
|
|
|
case NES_CM_EVENT_DROPPED_PKT:
|
|
|
|
nes_debug(NES_DBG_CM, "CM Event: DROPPED PKT\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nes_debug(NES_DBG_CM, "CM Event: UNKNOWN EVENT TYPE\n");
|
|
|
|
break;
|
2008-02-05 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
atomic_dec(&cm_core->events_posted);
|
|
|
|
event->cm_info.cm_id->rem_ref(event->cm_info.cm_id);
|
|
|
|
rem_ref_cm_node(cm_core, event->cm_node);
|
|
|
|
kfree(event);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|