Author: np
Date: Tue Apr  3 01:22:15 2018
New Revision: 331902
URL: https://svnweb.freebsd.org/changeset/base/331902

Log:
  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

Modified:
  head/sys/dev/cxgbe/adapter.h
  head/sys/dev/cxgbe/common/common.h
  head/sys/dev/cxgbe/t4_main.c
  head/sys/dev/cxgbe/tom/t4_tom.c

Modified: head/sys/dev/cxgbe/adapter.h
==============================================================================
--- head/sys/dev/cxgbe/adapter.h        Tue Apr  3 01:08:54 2018        
(r331901)
+++ head/sys/dev/cxgbe/adapter.h        Tue Apr  3 01:22:15 2018        
(r331902)
@@ -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

Modified: head/sys/dev/cxgbe/common/common.h
==============================================================================
--- head/sys/dev/cxgbe/common/common.h  Tue Apr  3 01:08:54 2018        
(r331901)
+++ head/sys/dev/cxgbe/common/common.h  Tue Apr  3 01:22:15 2018        
(r331902)
@@ -519,6 +519,12 @@ static inline u_int us_to_tcp_ticks(const struct adapt
        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,

Modified: head/sys/dev/cxgbe/t4_main.c
==============================================================================
--- head/sys/dev/cxgbe/t4_main.c        Tue Apr  3 01:08:54 2018        
(r331901)
+++ head/sys/dev/cxgbe/t4_main.c        Tue Apr  3 01:22:15 2018        
(r331902)
@@ -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 
        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)
 {
@@ -2437,22 +2432,6 @@ rw_via_memwin(struct adapter *sc, int idx, uint32_t ad
        }
 
        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

Modified: head/sys/dev/cxgbe/tom/t4_tom.c
==============================================================================
--- head/sys/dev/cxgbe/tom/t4_tom.c     Tue Apr  3 01:08:54 2018        
(r331901)
+++ head/sys/dev/cxgbe/tom/t4_tom.c     Tue Apr  3 01:22:15 2018        
(r331902)
@@ -401,7 +401,85 @@ t4_ctloutput(struct toedev *tod, struct tcpcb *tp, int
        }
 }
 
+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) {
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to