Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Aug 2018 04:23:51 +0000 (UTC)
From:      Navdeep Parhar <np@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r337996 - in head/sys: dev/cxgbe modules/cxgbe/if_cxgbe
Message-ID:  <201808180423.w7I4NpNY092604@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: np
Date: Sat Aug 18 04:23:51 2018
New Revision: 337996
URL: https://svnweb.freebsd.org/changeset/base/337996

Log:
  cxgbe(4): Replace T4_PKT_TIMESTAMP with something slightly less hackish.

Modified:
  head/sys/dev/cxgbe/adapter.h
  head/sys/dev/cxgbe/t4_main.c
  head/sys/dev/cxgbe/t4_sge.c
  head/sys/modules/cxgbe/if_cxgbe/Makefile

Modified: head/sys/dev/cxgbe/adapter.h
==============================================================================
--- head/sys/dev/cxgbe/adapter.h	Sat Aug 18 03:20:59 2018	(r337995)
+++ head/sys/dev/cxgbe/adapter.h	Sat Aug 18 04:23:51 2018	(r337996)
@@ -349,7 +349,7 @@ enum {
 	/* iq flags */
 	IQ_ALLOCATED	= (1 << 0),	/* firmware resources allocated */
 	IQ_HAS_FL	= (1 << 1),	/* iq associated with a freelist */
-					/* 1 << 2 Used to be IQ_INTR */
+	IQ_RX_TIMESTAMP	= (1 << 2),	/* provide the SGE rx timestamp */
 	IQ_LRO_ENABLED	= (1 << 3),	/* iq is an eth rxq with LRO enabled */
 	IQ_ADJ_CREDIT	= (1 << 4),	/* hw is off by 1 credit for this iq */
 

Modified: head/sys/dev/cxgbe/t4_main.c
==============================================================================
--- head/sys/dev/cxgbe/t4_main.c	Sat Aug 18 03:20:59 2018	(r337995)
+++ head/sys/dev/cxgbe/t4_main.c	Sat Aug 18 04:23:51 2018	(r337996)
@@ -1464,7 +1464,8 @@ cxgbe_probe(device_t dev)
 
 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
     IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
-    IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS)
+    IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS | \
+    IFCAP_HWRXTSTMP)
 #define T4_CAP_ENABLE (T4_CAP)
 
 static int
@@ -1813,6 +1814,18 @@ cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, cadd
 		if (mask & IFCAP_TXRTLMT)
 			ifp->if_capenable ^= IFCAP_TXRTLMT;
 #endif
+		if (mask & IFCAP_HWRXTSTMP) {
+			int i;
+			struct sge_rxq *rxq;
+
+			ifp->if_capenable ^= IFCAP_HWRXTSTMP;
+			for_each_rxq(vi, i, rxq) {
+				if (ifp->if_capenable & IFCAP_HWRXTSTMP)
+					rxq->iq.flags |= IQ_RX_TIMESTAMP;
+				else
+					rxq->iq.flags &= ~IQ_RX_TIMESTAMP;
+			}
+		}
 
 #ifdef VLAN_CAPABILITIES
 		VLAN_CAPABILITIES(ifp);

Modified: head/sys/dev/cxgbe/t4_sge.c
==============================================================================
--- head/sys/dev/cxgbe/t4_sge.c	Sat Aug 18 03:20:59 2018	(r337995)
+++ head/sys/dev/cxgbe/t4_sge.c	Sat Aug 18 04:23:51 2018	(r337996)
@@ -1564,6 +1564,17 @@ sort_before_lro(struct lro_ctrl *lro)
 	return (lro->lro_mbuf_max != 0);
 }
 
+static inline uint64_t
+last_flit_to_ns(struct adapter *sc, uint64_t lf)
+{
+	uint64_t n = be64toh(lf) & 0xfffffffffffffff;	/* 60b, not 64b. */
+
+	if (n > UINT64_MAX / 1000000)
+		return (n / sc->params.vpd.cclk * 1000000);
+	else
+		return (n * 1000000 / sc->params.vpd.cclk);
+}
+
 /*
  * Deals with interrupts on an iq+fl queue.
  */
@@ -1624,19 +1635,21 @@ service_iq_fl(struct sge_iq *iq, int budget)
 			if (__predict_false(m0 == NULL))
 				goto out;
 			refill = IDXDIFF(fl->hw_cidx, fl_hw_cidx, fl->sidx) > 2;
-#ifdef T4_PKT_TIMESTAMP
-			/*
-			 * 60 bit timestamp for the payload is
-			 * *(uint64_t *)m0->m_pktdat.  Note that it is
-			 * in the leading free-space in the mbuf.  The
-			 * kernel can clobber it during a pullup,
-			 * m_copymdata, etc.  You need to make sure that
-			 * the mbuf reaches you unmolested if you care
-			 * about the timestamp.
-			 */
-			*(uint64_t *)m0->m_pktdat =
-			    be64toh(ctrl->u.last_flit) & 0xfffffffffffffff;
+
+			if (iq->flags & IQ_RX_TIMESTAMP) {
+				/*
+				 * Fill up rcv_tstmp but do not set M_TSTMP.
+				 * rcv_tstmp is not in the format that the
+				 * kernel expects and we don't want to mislead
+				 * it.  For now this is only for custom code
+				 * that knows how to interpret cxgbe's stamp.
+				 */
+				m0->m_pkthdr.rcv_tstmp =
+				    last_flit_to_ns(sc, d->rsp.u.last_flit);
+#ifdef notyet
+				m0->m_flags |= M_TSTMP;
 #endif
+			}
 
 			/* fall through */
 
@@ -1814,10 +1827,7 @@ get_scatter_segment(struct adapter *sc, struct sge_fl 
 		if (m == NULL)
 			return (NULL);
 		fl->mbuf_allocated++;
-#ifdef T4_PKT_TIMESTAMP
-		/* Leave room for a timestamp */
-		m->m_data += 8;
-#endif
+
 		/* copy data to mbuf */
 		bcopy(payload, mtod(m, caddr_t), len);
 

Modified: head/sys/modules/cxgbe/if_cxgbe/Makefile
==============================================================================
--- head/sys/modules/cxgbe/if_cxgbe/Makefile	Sat Aug 18 03:20:59 2018	(r337995)
+++ head/sys/modules/cxgbe/if_cxgbe/Makefile	Sat Aug 18 04:23:51 2018	(r337996)
@@ -34,9 +34,6 @@ SRCS+=  cudbg_wtp.c
 SRCS+=  fastlz_api.c
 SRCS+=  fastlz.c
 
-# Provide the timestamp of a packet in its header mbuf.
-#CFLAGS+= -DT4_PKT_TIMESTAMP
-
 CFLAGS+= -I${CXGBE}
 
 .include <bsd.kmod.mk>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808180423.w7I4NpNY092604>