2012-06-19 07:34:13 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2012 Chelsio Communications, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
* Written by: Navdeep Parhar <np@FreeBSD.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "opt_inet.h"
|
2013-01-15 18:38:51 +00:00
|
|
|
#include "opt_inet6.h"
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
#ifdef TCP_OFFLOAD
|
|
|
|
#include <sys/param.h>
|
2013-10-29 11:17:49 +00:00
|
|
|
#include <sys/systm.h>
|
2012-06-19 07:34:13 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/ktr.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_vlan_var.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#define TCPSTATES
|
|
|
|
#include <netinet/tcp_fsm.h>
|
2016-01-27 05:15:53 +00:00
|
|
|
#include <netinet/tcp_var.h>
|
2012-06-19 07:34:13 +00:00
|
|
|
#include <netinet/toecore.h>
|
|
|
|
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/t4_msg.h"
|
|
|
|
#include "common/t4_regs.h"
|
2013-07-04 17:55:52 +00:00
|
|
|
#include "common/t4_regs_values.h"
|
2012-06-19 07:34:13 +00:00
|
|
|
#include "tom/t4_tom_l2t.h"
|
|
|
|
#include "tom/t4_tom.h"
|
|
|
|
|
|
|
|
/* atid services */
|
|
|
|
static int alloc_atid(struct adapter *, void *);
|
|
|
|
static void *lookup_atid(struct adapter *, int);
|
|
|
|
static void free_atid(struct adapter *, int);
|
|
|
|
|
|
|
|
static int
|
|
|
|
alloc_atid(struct adapter *sc, void *ctx)
|
|
|
|
{
|
|
|
|
struct tid_info *t = &sc->tids;
|
|
|
|
int atid = -1;
|
|
|
|
|
|
|
|
mtx_lock(&t->atid_lock);
|
|
|
|
if (t->afree) {
|
|
|
|
union aopen_entry *p = t->afree;
|
|
|
|
|
|
|
|
atid = p - t->atid_tab;
|
|
|
|
t->afree = p->next;
|
|
|
|
p->data = ctx;
|
|
|
|
t->atids_in_use++;
|
|
|
|
}
|
|
|
|
mtx_unlock(&t->atid_lock);
|
|
|
|
return (atid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
lookup_atid(struct adapter *sc, int atid)
|
|
|
|
{
|
|
|
|
struct tid_info *t = &sc->tids;
|
|
|
|
|
|
|
|
return (t->atid_tab[atid].data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_atid(struct adapter *sc, int atid)
|
|
|
|
{
|
|
|
|
struct tid_info *t = &sc->tids;
|
|
|
|
union aopen_entry *p = &t->atid_tab[atid];
|
|
|
|
|
|
|
|
mtx_lock(&t->atid_lock);
|
|
|
|
p->next = t->afree;
|
|
|
|
t->afree = p;
|
|
|
|
t->atids_in_use--;
|
|
|
|
mtx_unlock(&t->atid_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-01-07 00:08:55 +00:00
|
|
|
* Active open succeeded.
|
2012-06-19 07:34:13 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
do_act_establish(struct sge_iq *iq, const struct rss_header *rss,
|
|
|
|
struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct adapter *sc = iq->adapter;
|
|
|
|
const struct cpl_act_establish *cpl = (const void *)(rss + 1);
|
2014-10-07 21:26:22 +00:00
|
|
|
u_int tid = GET_TID(cpl);
|
|
|
|
u_int atid = G_TID_TID(ntohl(cpl->tos_atid));
|
2012-06-19 07:34:13 +00:00
|
|
|
struct toepcb *toep = lookup_atid(sc, atid);
|
|
|
|
struct inpcb *inp = toep->inp;
|
|
|
|
|
|
|
|
KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
|
|
|
|
KASSERT(toep->tid == atid, ("%s: toep tid/atid mismatch", __func__));
|
|
|
|
|
|
|
|
CTR3(KTR_CXGBE, "%s: atid %u, tid %u", __func__, atid, tid);
|
|
|
|
free_atid(sc, atid);
|
|
|
|
|
2017-01-11 23:48:17 +00:00
|
|
|
CURVNET_SET(toep->vnet);
|
2012-06-19 07:34:13 +00:00
|
|
|
INP_WLOCK(inp);
|
|
|
|
toep->tid = tid;
|
2017-01-07 20:26:19 +00:00
|
|
|
insert_tid(sc, tid, toep, inp->inp_vflag & INP_IPV6 ? 2 : 1);
|
2012-06-19 07:34:13 +00:00
|
|
|
if (inp->inp_flags & INP_DROPPED) {
|
|
|
|
|
|
|
|
/* socket closed by the kernel before hw told us it connected */
|
|
|
|
|
|
|
|
send_flowc_wr(toep, NULL);
|
|
|
|
send_reset(sc, toep, be32toh(cpl->snd_isn));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
make_established(toep, cpl->snd_isn, cpl->rcv_isn, cpl->tcp_opt);
|
|
|
|
done:
|
|
|
|
INP_WUNLOCK(inp);
|
2017-01-11 23:48:17 +00:00
|
|
|
CURVNET_RESTORE();
|
2012-06-19 07:34:13 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert an ACT_OPEN_RPL status to an errno.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
act_open_rpl_status_to_errno(int status)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case CPL_ERR_CONN_RESET:
|
|
|
|
return (ECONNREFUSED);
|
|
|
|
case CPL_ERR_ARP_MISS:
|
|
|
|
return (EHOSTUNREACH);
|
|
|
|
case CPL_ERR_CONN_TIMEDOUT:
|
|
|
|
return (ETIMEDOUT);
|
|
|
|
case CPL_ERR_TCAM_FULL:
|
2012-08-21 18:09:33 +00:00
|
|
|
return (EAGAIN);
|
2012-06-19 07:34:13 +00:00
|
|
|
case CPL_ERR_CONN_EXIST:
|
|
|
|
log(LOG_ERR, "ACTIVE_OPEN_RPL: 4-tuple in use\n");
|
2012-08-21 18:09:33 +00:00
|
|
|
return (EAGAIN);
|
2012-06-19 07:34:13 +00:00
|
|
|
default:
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 21:26:22 +00:00
|
|
|
void
|
|
|
|
act_open_failure_cleanup(struct adapter *sc, u_int atid, u_int status)
|
|
|
|
{
|
|
|
|
struct toepcb *toep = lookup_atid(sc, atid);
|
|
|
|
struct inpcb *inp = toep->inp;
|
|
|
|
struct toedev *tod = &toep->td->tod;
|
|
|
|
|
|
|
|
free_atid(sc, atid);
|
|
|
|
toep->tid = -1;
|
|
|
|
|
2017-01-11 23:48:17 +00:00
|
|
|
CURVNET_SET(toep->vnet);
|
2014-10-07 21:26:22 +00:00
|
|
|
if (status != EAGAIN)
|
2015-08-03 12:13:54 +00:00
|
|
|
INP_INFO_RLOCK(&V_tcbinfo);
|
2014-10-07 21:26:22 +00:00
|
|
|
INP_WLOCK(inp);
|
|
|
|
toe_connect_failed(tod, inp, status);
|
|
|
|
final_cpl_received(toep); /* unlocks inp */
|
|
|
|
if (status != EAGAIN)
|
2015-08-03 12:13:54 +00:00
|
|
|
INP_INFO_RUNLOCK(&V_tcbinfo);
|
2017-01-11 23:48:17 +00:00
|
|
|
CURVNET_RESTORE();
|
2014-10-07 21:26:22 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 00:08:55 +00:00
|
|
|
/*
|
|
|
|
* Active open failed.
|
|
|
|
*/
|
2012-06-19 07:34:13 +00:00
|
|
|
static int
|
|
|
|
do_act_open_rpl(struct sge_iq *iq, const struct rss_header *rss,
|
|
|
|
struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct adapter *sc = iq->adapter;
|
|
|
|
const struct cpl_act_open_rpl *cpl = (const void *)(rss + 1);
|
2014-10-07 21:26:22 +00:00
|
|
|
u_int atid = G_TID_TID(G_AOPEN_ATID(be32toh(cpl->atid_status)));
|
|
|
|
u_int status = G_AOPEN_STATUS(be32toh(cpl->atid_status));
|
2012-06-19 07:34:13 +00:00
|
|
|
struct toepcb *toep = lookup_atid(sc, atid);
|
2012-08-21 18:09:33 +00:00
|
|
|
int rc;
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
|
|
|
|
KASSERT(toep->tid == atid, ("%s: toep tid/atid mismatch", __func__));
|
|
|
|
|
|
|
|
CTR3(KTR_CXGBE, "%s: atid %u, status %u ", __func__, atid, status);
|
|
|
|
|
|
|
|
/* Ignore negative advice */
|
2013-01-26 03:01:51 +00:00
|
|
|
if (negative_advice(status))
|
2012-06-19 07:34:13 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (status && act_open_has_tid(status))
|
|
|
|
release_tid(sc, GET_TID(cpl), toep->ctrlq);
|
|
|
|
|
2012-08-21 18:09:33 +00:00
|
|
|
rc = act_open_rpl_status_to_errno(status);
|
2014-10-07 21:26:22 +00:00
|
|
|
act_open_failure_cleanup(sc, atid, rc);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Options2 for active open.
|
|
|
|
*/
|
|
|
|
static uint32_t
|
2013-01-15 18:38:51 +00:00
|
|
|
calc_opt2a(struct socket *so, struct toepcb *toep)
|
2012-06-19 07:34:13 +00:00
|
|
|
{
|
|
|
|
struct tcpcb *tp = so_sototcpcb(so);
|
2015-12-03 00:02:01 +00:00
|
|
|
struct port_info *pi = toep->vi->pi;
|
2012-06-19 07:34:13 +00:00
|
|
|
struct adapter *sc = pi->adapter;
|
2013-04-11 21:36:01 +00:00
|
|
|
uint32_t opt2;
|
|
|
|
|
|
|
|
opt2 = V_TX_QUEUE(sc->params.tp.tx_modq[pi->tx_chan]) |
|
|
|
|
F_RSS_QUEUE_VALID | V_RSS_QUEUE(toep->ofld_rxq->iq.abs_id);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
if (tp->t_flags & TF_SACK_PERMIT)
|
|
|
|
opt2 |= F_SACK_EN;
|
|
|
|
|
|
|
|
if (tp->t_flags & TF_REQ_TSTMP)
|
|
|
|
opt2 |= F_TSTAMPS_EN;
|
|
|
|
|
|
|
|
if (tp->t_flags & TF_REQ_SCALE)
|
|
|
|
opt2 |= F_WND_SCALE_EN;
|
|
|
|
|
|
|
|
if (V_tcp_do_ecn)
|
|
|
|
opt2 |= F_CCTRL_ECN;
|
|
|
|
|
2013-04-11 21:36:01 +00:00
|
|
|
/* RX_COALESCE is always a valid value (M_RX_COALESCE). */
|
2013-03-30 02:26:20 +00:00
|
|
|
if (is_t4(sc))
|
2013-04-11 21:36:01 +00:00
|
|
|
opt2 |= F_RX_COALESCE_VALID;
|
2013-07-04 18:41:21 +00:00
|
|
|
else {
|
2013-04-11 21:36:01 +00:00
|
|
|
opt2 |= F_T5_OPT_2_VALID;
|
2016-02-19 00:29:16 +00:00
|
|
|
opt2 |= F_T5_ISS;
|
2013-07-04 18:41:21 +00:00
|
|
|
}
|
2013-07-04 21:19:01 +00:00
|
|
|
if (sc->tt.rx_coalesce)
|
|
|
|
opt2 |= V_RX_COALESCE(M_RX_COALESCE);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
2012-08-17 00:49:29 +00:00
|
|
|
#ifdef USE_DDP_RX_FLOW_CONTROL
|
|
|
|
if (toep->ulp_mode == ULP_MODE_TCPDDP)
|
|
|
|
opt2 |= F_RX_FC_VALID | F_RX_FC_DDP;
|
|
|
|
#endif
|
|
|
|
|
2012-06-19 07:34:13 +00:00
|
|
|
return (htobe32(opt2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-05 01:29:24 +00:00
|
|
|
t4_init_connect_cpl_handlers(void)
|
2012-06-19 07:34:13 +00:00
|
|
|
{
|
|
|
|
|
2016-07-05 01:29:24 +00:00
|
|
|
t4_register_cpl_handler(CPL_ACT_ESTABLISH, do_act_establish);
|
|
|
|
t4_register_cpl_handler(CPL_ACT_OPEN_RPL, do_act_open_rpl);
|
2012-06-19 07:34:13 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 18:38:51 +00:00
|
|
|
#define DONT_OFFLOAD_ACTIVE_OPEN(x) do { \
|
|
|
|
reason = __LINE__; \
|
|
|
|
rc = (x); \
|
|
|
|
goto failed; \
|
|
|
|
} while (0)
|
|
|
|
|
2013-03-30 02:26:20 +00:00
|
|
|
static inline int
|
|
|
|
act_open_cpl_size(struct adapter *sc, int isipv6)
|
|
|
|
{
|
2016-09-17 23:08:49 +00:00
|
|
|
int idx;
|
|
|
|
static const int sz_table[3][2] = {
|
|
|
|
{
|
|
|
|
sizeof (struct cpl_act_open_req),
|
|
|
|
sizeof (struct cpl_act_open_req6)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sizeof (struct cpl_t5_act_open_req),
|
|
|
|
sizeof (struct cpl_t5_act_open_req6)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sizeof (struct cpl_t6_act_open_req),
|
|
|
|
sizeof (struct cpl_t6_act_open_req6)
|
|
|
|
},
|
2013-03-30 02:26:20 +00:00
|
|
|
};
|
|
|
|
|
2016-09-17 23:08:49 +00:00
|
|
|
MPASS(chip_id(sc) >= CHELSIO_T4);
|
|
|
|
idx = min(chip_id(sc) - CHELSIO_T4, 2);
|
|
|
|
|
|
|
|
return (sz_table[idx][!!isipv6]);
|
2013-03-30 02:26:20 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 07:34:13 +00:00
|
|
|
/*
|
|
|
|
* active open (soconnect).
|
|
|
|
*
|
|
|
|
* State of affairs on entry:
|
|
|
|
* soisconnecting (so_state |= SS_ISCONNECTING)
|
|
|
|
* tcbinfo not locked (This has changed - used to be WLOCKed)
|
|
|
|
* inp WLOCKed
|
|
|
|
* tp->t_state = TCPS_SYN_SENT
|
|
|
|
* rtalloc1, RT_UNLOCK on rt.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
t4_connect(struct toedev *tod, struct socket *so, struct rtentry *rt,
|
|
|
|
struct sockaddr *nam)
|
|
|
|
{
|
|
|
|
struct adapter *sc = tod->tod_softc;
|
2013-01-15 18:38:51 +00:00
|
|
|
struct tom_data *td = tod_td(tod);
|
2012-06-19 07:34:13 +00:00
|
|
|
struct toepcb *toep = NULL;
|
|
|
|
struct wrqe *wr = NULL;
|
|
|
|
struct ifnet *rt_ifp = rt->rt_ifp;
|
2015-12-03 00:02:01 +00:00
|
|
|
struct vi_info *vi;
|
2013-01-15 18:38:51 +00:00
|
|
|
int mtu_idx, rscale, qid_atid, rc, isipv6;
|
2012-06-19 07:34:13 +00:00
|
|
|
struct inpcb *inp = sotoinpcb(so);
|
|
|
|
struct tcpcb *tp = intotcpcb(inp);
|
2013-01-15 18:38:51 +00:00
|
|
|
int reason;
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
INP_WLOCK_ASSERT(inp);
|
2013-01-15 18:38:51 +00:00
|
|
|
KASSERT(nam->sa_family == AF_INET || nam->sa_family == AF_INET6,
|
|
|
|
("%s: dest addr %p has family %u", __func__, nam, nam->sa_family));
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
if (rt_ifp->if_type == IFT_ETHER)
|
2015-12-03 00:02:01 +00:00
|
|
|
vi = rt_ifp->if_softc;
|
2012-06-19 07:34:13 +00:00
|
|
|
else if (rt_ifp->if_type == IFT_L2VLAN) {
|
|
|
|
struct ifnet *ifp = VLAN_COOKIE(rt_ifp);
|
|
|
|
|
2015-12-03 00:02:01 +00:00
|
|
|
vi = ifp->if_softc;
|
2012-06-19 07:34:13 +00:00
|
|
|
} else if (rt_ifp->if_type == IFT_IEEE8023ADLAG)
|
2013-01-15 18:38:51 +00:00
|
|
|
DONT_OFFLOAD_ACTIVE_OPEN(ENOSYS); /* XXX: implement lagg+TOE */
|
2012-06-19 07:34:13 +00:00
|
|
|
else
|
2013-01-15 18:38:51 +00:00
|
|
|
DONT_OFFLOAD_ACTIVE_OPEN(ENOTSUP);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
2016-09-05 19:37:47 +00:00
|
|
|
toep = alloc_toepcb(vi, -1, -1, M_NOWAIT | M_ZERO);
|
2012-06-19 07:34:13 +00:00
|
|
|
if (toep == NULL)
|
2013-01-15 18:38:51 +00:00
|
|
|
DONT_OFFLOAD_ACTIVE_OPEN(ENOMEM);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
2013-01-15 18:38:51 +00:00
|
|
|
toep->tid = alloc_atid(sc, toep);
|
|
|
|
if (toep->tid < 0)
|
|
|
|
DONT_OFFLOAD_ACTIVE_OPEN(ENOMEM);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
2015-12-03 00:02:01 +00:00
|
|
|
toep->l2te = t4_l2t_get(vi->pi, rt_ifp,
|
2012-06-19 07:34:13 +00:00
|
|
|
rt->rt_flags & RTF_GATEWAY ? rt->rt_gateway : nam);
|
2013-01-15 18:38:51 +00:00
|
|
|
if (toep->l2te == NULL)
|
|
|
|
DONT_OFFLOAD_ACTIVE_OPEN(ENOMEM);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
2013-01-15 18:38:51 +00:00
|
|
|
isipv6 = nam->sa_family == AF_INET6;
|
2013-03-30 02:26:20 +00:00
|
|
|
wr = alloc_wrqe(act_open_cpl_size(sc, isipv6), toep->ctrlq);
|
2012-06-19 07:34:13 +00:00
|
|
|
if (wr == NULL)
|
2013-01-15 18:38:51 +00:00
|
|
|
DONT_OFFLOAD_ACTIVE_OPEN(ENOMEM);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
2017-01-11 23:48:17 +00:00
|
|
|
toep->vnet = so->so_vnet;
|
2012-08-17 00:49:29 +00:00
|
|
|
if (sc->tt.ddp && (so->so_options & SO_NO_DDP) == 0)
|
|
|
|
set_tcpddp_ulp_mode(toep);
|
|
|
|
else
|
|
|
|
toep->ulp_mode = ULP_MODE_NONE;
|
2012-06-19 07:34:13 +00:00
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
|
|
|
/* opt0 rcv_bufsiz initially, assumes its normal meaning later */
|
|
|
|
toep->rx_credits = min(select_rcv_wnd(so) >> 10, M_RCV_BUFSIZ);
|
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The kernel sets request_r_scale based on sb_max whereas we need to
|
|
|
|
* take hardware's MAX_RCV_WND into account too. This is normally a
|
|
|
|
* no-op as MAX_RCV_WND is much larger than the default sb_max.
|
|
|
|
*/
|
|
|
|
if (tp->t_flags & TF_REQ_SCALE)
|
|
|
|
rscale = tp->request_r_scale = select_rcv_wscale();
|
|
|
|
else
|
|
|
|
rscale = 0;
|
|
|
|
mtu_idx = find_best_mtu_idx(sc, &inp->inp_inc, 0);
|
2013-01-15 18:38:51 +00:00
|
|
|
qid_atid = (toep->ofld_rxq->iq.abs_id << 14) | toep->tid;
|
|
|
|
|
|
|
|
if (isipv6) {
|
|
|
|
struct cpl_act_open_req6 *cpl = wrtod(wr);
|
2016-09-17 23:08:49 +00:00
|
|
|
struct cpl_t5_act_open_req6 *cpl5 = (void *)cpl;
|
|
|
|
struct cpl_t6_act_open_req6 *cpl6 = (void *)cpl;
|
2013-01-15 18:38:51 +00:00
|
|
|
|
2016-09-17 23:08:49 +00:00
|
|
|
if ((inp->inp_vflag & INP_IPV6) == 0)
|
2013-01-15 18:38:51 +00:00
|
|
|
DONT_OFFLOAD_ACTIVE_OPEN(ENOTSUP);
|
|
|
|
|
|
|
|
toep->ce = hold_lip(td, &inp->in6p_laddr);
|
|
|
|
if (toep->ce == NULL)
|
|
|
|
DONT_OFFLOAD_ACTIVE_OPEN(ENOENT);
|
|
|
|
|
2016-09-17 23:08:49 +00:00
|
|
|
switch (chip_id(sc)) {
|
|
|
|
case CHELSIO_T4:
|
2013-07-04 17:55:52 +00:00
|
|
|
INIT_TP_WR(cpl, 0);
|
2015-12-03 00:02:01 +00:00
|
|
|
cpl->params = select_ntuple(vi, toep->l2te);
|
2016-09-17 23:08:49 +00:00
|
|
|
break;
|
|
|
|
case CHELSIO_T5:
|
|
|
|
INIT_TP_WR(cpl5, 0);
|
|
|
|
cpl5->iss = htobe32(tp->iss);
|
|
|
|
cpl5->params = select_ntuple(vi, toep->l2te);
|
|
|
|
break;
|
|
|
|
case CHELSIO_T6:
|
|
|
|
default:
|
|
|
|
INIT_TP_WR(cpl6, 0);
|
|
|
|
cpl6->iss = htobe32(tp->iss);
|
|
|
|
cpl6->params = select_ntuple(vi, toep->l2te);
|
|
|
|
break;
|
2013-07-04 17:55:52 +00:00
|
|
|
}
|
2013-01-15 18:38:51 +00:00
|
|
|
OPCODE_TID(cpl) = htobe32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
|
|
|
|
qid_atid));
|
|
|
|
cpl->local_port = inp->inp_lport;
|
|
|
|
cpl->local_ip_hi = *(uint64_t *)&inp->in6p_laddr.s6_addr[0];
|
|
|
|
cpl->local_ip_lo = *(uint64_t *)&inp->in6p_laddr.s6_addr[8];
|
|
|
|
cpl->peer_port = inp->inp_fport;
|
|
|
|
cpl->peer_ip_hi = *(uint64_t *)&inp->in6p_faddr.s6_addr[0];
|
|
|
|
cpl->peer_ip_lo = *(uint64_t *)&inp->in6p_faddr.s6_addr[8];
|
2015-12-03 00:02:01 +00:00
|
|
|
cpl->opt0 = calc_opt0(so, vi, toep->l2te, mtu_idx, rscale,
|
2013-01-15 18:38:51 +00:00
|
|
|
toep->rx_credits, toep->ulp_mode);
|
|
|
|
cpl->opt2 = calc_opt2a(so, toep);
|
2013-07-04 17:55:52 +00:00
|
|
|
} else {
|
|
|
|
struct cpl_act_open_req *cpl = wrtod(wr);
|
2016-09-17 23:08:49 +00:00
|
|
|
struct cpl_t5_act_open_req *cpl5 = (void *)cpl;
|
|
|
|
struct cpl_t6_act_open_req *cpl6 = (void *)cpl;
|
2013-07-04 17:55:52 +00:00
|
|
|
|
2016-09-17 23:08:49 +00:00
|
|
|
switch (chip_id(sc)) {
|
|
|
|
case CHELSIO_T4:
|
2013-07-04 17:55:52 +00:00
|
|
|
INIT_TP_WR(cpl, 0);
|
2015-12-03 00:02:01 +00:00
|
|
|
cpl->params = select_ntuple(vi, toep->l2te);
|
2016-09-17 23:08:49 +00:00
|
|
|
break;
|
|
|
|
case CHELSIO_T5:
|
|
|
|
INIT_TP_WR(cpl5, 0);
|
|
|
|
cpl5->iss = htobe32(tp->iss);
|
|
|
|
cpl5->params = select_ntuple(vi, toep->l2te);
|
|
|
|
break;
|
|
|
|
case CHELSIO_T6:
|
|
|
|
default:
|
|
|
|
INIT_TP_WR(cpl6, 0);
|
|
|
|
cpl6->iss = htobe32(tp->iss);
|
|
|
|
cpl6->params = select_ntuple(vi, toep->l2te);
|
|
|
|
break;
|
2013-03-30 02:26:20 +00:00
|
|
|
}
|
2013-01-15 18:38:51 +00:00
|
|
|
OPCODE_TID(cpl) = htobe32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
|
|
|
|
qid_atid));
|
|
|
|
inp_4tuple_get(inp, &cpl->local_ip, &cpl->local_port,
|
|
|
|
&cpl->peer_ip, &cpl->peer_port);
|
2015-12-03 00:02:01 +00:00
|
|
|
cpl->opt0 = calc_opt0(so, vi, toep->l2te, mtu_idx, rscale,
|
2013-01-15 18:38:51 +00:00
|
|
|
toep->rx_credits, toep->ulp_mode);
|
|
|
|
cpl->opt2 = calc_opt2a(so, toep);
|
|
|
|
}
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
CTR5(KTR_CXGBE, "%s: atid %u (%s), toep %p, inp %p", __func__,
|
|
|
|
toep->tid, tcpstates[tp->t_state], toep, inp);
|
|
|
|
|
2013-01-15 18:38:51 +00:00
|
|
|
offload_socket(so, toep);
|
|
|
|
rc = t4_l2t_send(sc, wr, toep->l2te);
|
2012-06-19 07:34:13 +00:00
|
|
|
if (rc == 0) {
|
2012-08-21 18:30:16 +00:00
|
|
|
toep->flags |= TPF_CPL_PENDING;
|
2012-06-19 07:34:13 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_offload_socket(so);
|
2013-01-15 18:38:51 +00:00
|
|
|
reason = __LINE__;
|
2012-06-19 07:34:13 +00:00
|
|
|
failed:
|
2013-01-15 18:38:51 +00:00
|
|
|
CTR3(KTR_CXGBE, "%s: not offloading (%d), rc %d", __func__, reason, rc);
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
if (wr)
|
|
|
|
free_wrqe(wr);
|
2013-01-15 18:38:51 +00:00
|
|
|
|
|
|
|
if (toep) {
|
|
|
|
if (toep->tid >= 0)
|
|
|
|
free_atid(sc, toep->tid);
|
|
|
|
if (toep->l2te)
|
|
|
|
t4_l2t_release(toep->l2te);
|
|
|
|
if (toep->ce)
|
|
|
|
release_lip(td, toep->ce);
|
2012-06-19 07:34:13 +00:00
|
|
|
free_toepcb(toep);
|
2013-01-15 18:38:51 +00:00
|
|
|
}
|
2012-06-19 07:34:13 +00:00
|
|
|
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
#endif
|