cxgbe: Implement tcp_info handler for connections handled by t4_tom.

The TCB is read using a memory window right now.  A better alternate to
get self-consistent, uncached information would be to use a GET_TCB
request but waiting for a reply from hw while holding non-sleepable
locks is quite inconvenient.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D14817
This commit is contained in:
np 2018-04-03 01:22:15 +00:00
parent c4e1d948c4
commit e7995099e0
4 changed files with 102 additions and 22 deletions

View File

@ -1160,6 +1160,7 @@ int vi_full_init(struct vi_info *);
int vi_full_uninit(struct vi_info *);
void vi_sysctls(struct vi_info *);
void vi_tick(void *);
int rw_via_memwin(struct adapter *, int, uint32_t, uint32_t *, int, int);
#ifdef DEV_NETMAP
/* t4_netmap.c */
@ -1252,4 +1253,19 @@ t4_wrq_tx(struct adapter *sc, struct wrqe *wr)
TXQ_UNLOCK(wrq);
}
static inline int
read_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
int len)
{
return (rw_via_memwin(sc, idx, addr, val, len, 0));
}
static inline int
write_via_memwin(struct adapter *sc, int idx, uint32_t addr,
const uint32_t *val, int len)
{
return (rw_via_memwin(sc, idx, addr, (void *)(uintptr_t)val, len, 1));
}
#endif

View File

@ -519,6 +519,12 @@ static inline u_int us_to_tcp_ticks(const struct adapter *adap, u_long us)
return (us * adap->params.vpd.cclk / 1000 >> adap->params.tp.tre);
}
static inline u_int tcp_ticks_to_us(const struct adapter *adap, u_int ticks)
{
return ((uint64_t)ticks << adap->params.tp.tre) /
core_ticks_per_usec(adap);
}
void t4_set_reg_field(struct adapter *adap, unsigned int addr, u32 mask, u32 val);
int t4_wr_mbox_meat_timeout(struct adapter *adap, int mbox, const void *cmd,

View File

@ -511,11 +511,6 @@ struct filter_entry {
static void setup_memwin(struct adapter *);
static void position_memwin(struct adapter *, int, uint32_t);
static int rw_via_memwin(struct adapter *, int, uint32_t, uint32_t *, int, int);
static inline int read_via_memwin(struct adapter *, int, uint32_t, uint32_t *,
int);
static inline int write_via_memwin(struct adapter *, int, uint32_t,
const uint32_t *, int);
static int validate_mem_range(struct adapter *, uint32_t, int);
static int fwmtype_to_hwmtype(int);
static int validate_mt_off_len(struct adapter *, int, uint32_t, int,
@ -2391,7 +2386,7 @@ position_memwin(struct adapter *sc, int idx, uint32_t addr)
t4_read_reg(sc, reg); /* flush */
}
static int
int
rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
int len, int rw)
{
@ -2439,22 +2434,6 @@ rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
return (0);
}
static inline int
read_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
int len)
{
return (rw_via_memwin(sc, idx, addr, val, len, 0));
}
static inline int
write_via_memwin(struct adapter *sc, int idx, uint32_t addr,
const uint32_t *val, int len)
{
return (rw_via_memwin(sc, idx, addr, (void *)(uintptr_t)val, len, 1));
}
static int
t4_range_cmp(const void *a, const void *b)
{

View File

@ -401,6 +401,84 @@ t4_ctloutput(struct toedev *tod, struct tcpcb *tp, int dir, int name)
}
}
static inline int
get_tcb_bit(u_char *tcb, int bit)
{
int ix, shift;
ix = 127 - (bit >> 3);
shift = bit & 0x7;
return ((tcb[ix] >> shift) & 1);
}
static inline uint64_t
get_tcb_bits(u_char *tcb, int hi, int lo)
{
uint64_t rc = 0;
while (hi >= lo) {
rc = (rc << 1) | get_tcb_bit(tcb, hi);
--hi;
}
return (rc);
}
/*
* Called by the kernel to allow the TOE driver to "refine" values filled up in
* the tcp_info for an offloaded connection.
*/
static void
t4_tcp_info(struct toedev *tod, struct tcpcb *tp, struct tcp_info *ti)
{
int i, j, k, rc;
struct adapter *sc = tod->tod_softc;
struct toepcb *toep = tp->t_toe;
uint32_t addr, v;
uint32_t buf[TCB_SIZE / sizeof(uint32_t)];
u_char *tcb, tmp;
INP_WLOCK_ASSERT(tp->t_inpcb);
MPASS(ti != NULL);
addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE) + toep->tid * TCB_SIZE;
rc = read_via_memwin(sc, 2, addr, &buf[0], TCB_SIZE);
if (rc != 0)
return;
tcb = (u_char *)&buf[0];
for (i = 0, j = TCB_SIZE - 16; i < j; i += 16, j -= 16) {
for (k = 0; k < 16; k++) {
tmp = tcb[i + k];
tcb[i + k] = tcb[j + k];
tcb[j + k] = tmp;
}
}
ti->tcpi_state = get_tcb_bits(tcb, 115, 112);
v = get_tcb_bits(tcb, 271, 256);
ti->tcpi_rtt = tcp_ticks_to_us(sc, v);
v = get_tcb_bits(tcb, 287, 272);
ti->tcpi_rttvar = tcp_ticks_to_us(sc, v);
ti->tcpi_snd_ssthresh = get_tcb_bits(tcb, 487, 460);
ti->tcpi_snd_cwnd = get_tcb_bits(tcb, 459, 432);
ti->tcpi_rcv_nxt = get_tcb_bits(tcb, 553, 522);
ti->tcpi_snd_nxt = get_tcb_bits(tcb, 319, 288) -
get_tcb_bits(tcb, 375, 348);
/* Receive window being advertised by us. */
ti->tcpi_rcv_space = get_tcb_bits(tcb, 581, 554);
/* Send window ceiling. */
v = get_tcb_bits(tcb, 159, 144) << get_tcb_bits(tcb, 131, 128);
ti->tcpi_snd_wnd = min(v, ti->tcpi_snd_cwnd);
}
/*
* The TOE driver will not receive any more CPLs for the tid associated with the
* toepcb; release the hold on the inpcb.
@ -1126,6 +1204,7 @@ t4_tom_activate(struct adapter *sc)
tod->tod_syncache_respond = t4_syncache_respond;
tod->tod_offload_socket = t4_offload_socket;
tod->tod_ctloutput = t4_ctloutput;
tod->tod_tcp_info = t4_tcp_info;
for_each_port(sc, i) {
for_each_vi(sc->port[i], v, vi) {