From 37fea17dc1a4f61630c5b6799fca2aee9501557e Mon Sep 17 00:00:00 2001 From: np Date: Sat, 18 Aug 2018 04:23:51 +0000 Subject: [PATCH] cxgbe(4): Replace T4_PKT_TIMESTAMP with something slightly less hackish. --- sys/dev/cxgbe/adapter.h | 2 +- sys/dev/cxgbe/t4_main.c | 15 ++++++++++- sys/dev/cxgbe/t4_sge.c | 42 ++++++++++++++++++----------- sys/modules/cxgbe/if_cxgbe/Makefile | 3 --- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/sys/dev/cxgbe/adapter.h b/sys/dev/cxgbe/adapter.h index c03fdf8d1396..6aa13356cc43 100644 --- a/sys/dev/cxgbe/adapter.h +++ b/sys/dev/cxgbe/adapter.h @@ -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 */ diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c index 6c97ba87a61b..2d41bff5dfdd 100644 --- a/sys/dev/cxgbe/t4_main.c +++ b/sys/dev/cxgbe/t4_main.c @@ -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, caddr_t data) 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); diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c index 1b47c26879c5..0e2f8d45feb9 100644 --- a/sys/dev/cxgbe/t4_sge.c +++ b/sys/dev/cxgbe/t4_sge.c @@ -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 *fl, int fr_offset, 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); diff --git a/sys/modules/cxgbe/if_cxgbe/Makefile b/sys/modules/cxgbe/if_cxgbe/Makefile index 3f06c535b29c..d35287bab5cf 100644 --- a/sys/modules/cxgbe/if_cxgbe/Makefile +++ b/sys/modules/cxgbe/if_cxgbe/Makefile @@ -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