Index: sys/dev/cxgbe/adapter.h =================================================================== --- sys/dev/cxgbe/adapter.h +++ sys/dev/cxgbe/adapter.h @@ -1160,6 +1160,7 @@ 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 @@ 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 Index: sys/dev/cxgbe/common/common.h =================================================================== --- sys/dev/cxgbe/common/common.h +++ sys/dev/cxgbe/common/common.h @@ -519,6 +519,12 @@ 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, Index: sys/dev/cxgbe/t4_main.c =================================================================== --- sys/dev/cxgbe/t4_main.c +++ sys/dev/cxgbe/t4_main.c @@ -511,11 +511,6 @@ 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 @@ 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 @@ 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) { Index: sys/dev/cxgbe/tom/t4_tom.c =================================================================== --- sys/dev/cxgbe/tom/t4_tom.c +++ sys/dev/cxgbe/tom/t4_tom.c @@ -401,6 +401,84 @@ } } +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 @@ 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) {