From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=12.32.117.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796129165; b=WOSlnMgsyF+hTe82mOMO1ytIWXivFOlXmGjf1eIJMuAdhydZrfGXzGwJwUQ0NMJT+Vmc qFzKMmmm2t35Gqhta8oTSb6dtoGDoQSrsGXo76TIOVLrBhNlajkaqJA1U/tp3Q770akDc IkixzV0eWFpR8+h412Waq/bDmEsuj1DEaU8g1+T7+ZdnuHbdSPa2T0rEvdbmGV3vTWFHV lPU+NEznoOX7dfFeDwMnSQY3NoQf+6XA6nIrEZWqqHvgPD/mf+jQyOUNM+l3DlPhdYPX2 agHm0xk+NuG8BIV9k442MicIaV5OgOV6X1QuBvaunElZ1iW7mogysYtNgwS0k/lV95A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129165; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=7uO5RpOziAPx3vd8tij9etAs9JmnZLFFQ5WK2I43uYo=; b=BFEYm7azeOHqVdHA/raI2z+09/MLWBBPLlmhiJxF3w3R2zRxhswJVwIS61o7Oz58H+Sh OGxsJhjLVediTLiog356bLJWMNQxZjbeEH30wmfCfCZJQkh2I6kWGzIoIwyeoFLHNCqW8 SBQmCqZHvd2KGUtiBjK7cfiAe6SoMDNUg5SomNnetwIPeUkmyJSayzhA9LEsyPesM43Le Tqd/dZcez8smKb1trymlelUZlEZlGX872qthdrCAv/eZxSp503wwks3Vc/AqKrFDTpqin +nAo+ka7Y/ZMAM8NaKrWD0p7k4YGC86G2imLgvysrShcYveiqGhfeHTGk+XctDICa/A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chelsio.com; spf=pass smtp.mailfrom=chelsio.com; arc=none smtp.remote-ip=12.32.117.8 Received: from stargate.chelsio.com (unknown [12.32.117.8]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC5F3606A693 for ; Tue, 1 Dec 2026 12:45:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CC5F3606A693 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chelsio.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chelsio.com Received: from mehrangarh-blr-asicdesigners-com.asicdesigners.com (mehrangarh.blr.asicdesigners.com [10.193.185.169]) by stargate.chelsio.com (8.14.7/8.14.7) with ESMTP id 6B1Ci7oU026690; Tue, 1 Dec 2026 04:45:13 -0800 From: Potnuri Bharat Teja To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, bharat@chelsio.com, harshitha.vr@chelsio.com Subject: [PATCH net-next v6 06/12] cxgb4: update PTP register access for T7 Date: Tue, 1 Dec 2026 17:15:50 -0500 Message-Id: <20261201221556.251018-7-bharat@chelsio.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20261201221556.251018-1-bharat@chelsio.com> References: <20261201221556.251018-1-bharat@chelsio.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The MAC_PORT_TX_TS_VAL_LO/HI registers moved within the port register block on T7, and the PTP clock sum is now read from the chip global MAC_PTP_SUM_LO/HI instead of a per port register. Select the right registers by chip version. The clock sum is read with t4_read_reg64(); the Tx timestamp is read as two 32-bit registers, as T7 MAC_PORT_TX_TS_VAL_LO is not 8-byte aligned. PTP port register accesses and the port ID of the PTP firmware commands (Rx redirect, Rx timestamping mode and Tx type) now use the logical port number (pi->lport), as does the channel of the Rx redirect command. On transmit, ptp_classify_raw() replaces the open coded IPv4/UDP test. Only untagged IPv4/UDP event messages are timestamped, as those are the only ones whose looped back copy cxgb4_ptp_is_ptp_rx() recognises. A PTP packet is sent on the PTP Tx queue and timestamped only if it fits in an immediate work request (is_eth_imm()); the timestamp is read back through adap->ptp_tx_skb, which the SGL path would orphan and leave DMA mapped. The PTP Tx slot is claimed only after the queue credit and DMA mapping checks, so a failed transmit no longer leaves adap->ptp_tx_skb set and blocks later PTP packets. On receive, cxgb4_ptp_is_ptp_rx() checks the IPv4 header length and the packet length before reading the looped back packet, and t4_systim_to_hwstamp() checks that a received PTP event packet holds a MAC header and finds the PTP header of an IEEE 802.3 (ETH_P_1588) packet right after it. Signed-off-by: Potnuri Bharat Teja --- .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 6 +- .../net/ethernet/chelsio/cxgb4/cxgb4_ptp.c | 65 ++++++++++++------- drivers/net/ethernet/chelsio/cxgb4/sge.c | 32 +++++++-- drivers/net/ethernet/chelsio/cxgb4/t4_regs.h | 1 + 4 files changed, 71 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c index 11e0479db7b4..db018947d021 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c @@ -3071,10 +3071,10 @@ static int cxgb_hwtstamp_set(struct net_device *dev, break; case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: - cxgb4_ptprx_timestamping(pi, pi->port_id, PTP_TS_L4); + cxgb4_ptprx_timestamping(pi, pi->lport, PTP_TS_L4); break; case HWTSTAMP_FILTER_PTP_V2_EVENT: - cxgb4_ptprx_timestamping(pi, pi->port_id, PTP_TS_L2_L4); + cxgb4_ptprx_timestamping(pi, pi->lport, PTP_TS_L2_L4); break; case HWTSTAMP_FILTER_ALL: case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: @@ -3089,7 +3089,7 @@ static int cxgb_hwtstamp_set(struct net_device *dev, if (config->tx_type == HWTSTAMP_TX_OFF && config->rx_filter == HWTSTAMP_FILTER_NONE) { - if (cxgb4_ptp_txtype(adapter, pi->port_id) >= 0) + if (cxgb4_ptp_txtype(adapter, pi->lport) >= 0) pi->ptp_enable = false; } diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c index cbd06d9b95d4..abc817525f0c 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c @@ -54,17 +54,15 @@ * cxgb4_ptp_is_ptp_tx - determine whether TX packet is PTP or not * @skb: skb of outgoing ptp request * + * Return: true if @skb is an untagged IPv4/UDP PTP event message, the only + * kind whose looped back copy cxgb4_ptp_is_ptp_rx() recognises. */ bool cxgb4_ptp_is_ptp_tx(struct sk_buff *skb) { - struct udphdr *uh; + unsigned int ptp_class = ptp_classify_raw(skb); - uh = udp_hdr(skb); - return skb->len >= PTP_MIN_LENGTH && - skb->len <= PTP_IN_TRANSMIT_PACKET_MAXNUM && - likely(skb->protocol == htons(ETH_P_IP)) && - ip_hdr(skb)->protocol == IPPROTO_UDP && - uh->dest == htons(PTP_EVENT_PORT); + return (ptp_class & (PTP_CLASS_PMASK | PTP_CLASS_VLAN)) == + PTP_CLASS_IPV4; } bool is_ptp_enabled(struct sk_buff *skb, struct net_device *dev) @@ -83,11 +81,24 @@ bool is_ptp_enabled(struct sk_buff *skb, struct net_device *dev) */ bool cxgb4_ptp_is_ptp_rx(struct sk_buff *skb) { - struct udphdr *uh = (struct udphdr *)(skb->data + ETH_HLEN + - IPV4_HLEN(skb->data)); - - return uh->dest == htons(PTP_EVENT_PORT) && - uh->source == htons(PTP_EVENT_PORT); + struct ethhdr *eth = (struct ethhdr *)skb->data; + struct udphdr *uh; + struct iphdr *iph; + unsigned int ihl; + + if (skb_headlen(skb) < ETH_HLEN + sizeof(*iph) || + eth->h_proto != htons(ETH_P_IP)) + return false; + + iph = (struct iphdr *)(skb->data + ETH_HLEN); + ihl = iph->ihl * 4; + if (ihl < sizeof(*iph) || iph->protocol != IPPROTO_UDP || + skb_headlen(skb) < ETH_HLEN + ihl + sizeof(*uh)) + return false; + + uh = (struct udphdr *)(skb->data + ETH_HLEN + ihl); + return uh->dest == htons(PTP_EVENT_PORT) && + uh->source == htons(PTP_EVENT_PORT); } /** @@ -99,16 +110,23 @@ bool cxgb4_ptp_is_ptp_rx(struct sk_buff *skb) void cxgb4_ptp_read_hwstamp(struct adapter *adapter, struct port_info *pi) { struct skb_shared_hwtstamps *skb_ts = NULL; + u32 lo_reg, hi_reg; u64 tx_ts; skb_ts = skb_hwtstamps(adapter->ptp_tx_skb); - tx_ts = t4_read_reg(adapter, - T5_PORT_REG(pi->port_id, MAC_PORT_TX_TS_VAL_LO)); + if (CHELSIO_CHIP_VERSION(adapter->params.chip) >= CHELSIO_T7) { + lo_reg = T7_PORT_REG(pi->lport, T7_MAC_PORT_TX_TS_VAL_LO); + hi_reg = T7_PORT_REG(pi->lport, T7_MAC_PORT_TX_TS_VAL_HI); + } else { + lo_reg = T5_PORT_REG(pi->lport, MAC_PORT_TX_TS_VAL_LO); + hi_reg = T5_PORT_REG(pi->lport, MAC_PORT_TX_TS_VAL_HI); + } + + /* T7 TX_TS_VAL_LO is not 8-byte aligned, use two 32-bit reads */ + tx_ts = t4_read_reg(adapter, lo_reg); + tx_ts |= (u64)t4_read_reg(adapter, hi_reg) << 32; - tx_ts |= (u64)t4_read_reg(adapter, - T5_PORT_REG(pi->port_id, - MAC_PORT_TX_TS_VAL_HI)) << 32; skb_ts->hwtstamp = ns_to_ktime(tx_ts); skb_tstamp_tx(adapter->ptp_tx_skb, skb_ts); dev_kfree_skb_any(adapter->ptp_tx_skb); @@ -179,11 +197,11 @@ int cxgb4_ptp_redirect_rx_packet(struct adapter *adapter, struct port_info *pi) c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PTP_CMD) | FW_CMD_REQUEST_F | FW_CMD_WRITE_F | - FW_PTP_CMD_PORTID_V(pi->port_id)); + FW_PTP_CMD_PORTID_V(pi->lport)); c.retval_len16 = cpu_to_be32(FW_CMD_LEN16_V(sizeof(c) / 16)); c.u.init.sc = FW_PTP_SC_RDRX_TYPE; - c.u.init.txchan = pi->tx_chan; + c.u.init.txchan = pi->lport; c.u.init.absid = cpu_to_be16(receive_q->rspq.abs_id); err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); @@ -319,9 +337,10 @@ static int cxgb4_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) ptp_clock_info); u64 ns; - ns = t4_read_reg(adapter, T5_PORT_REG(0, MAC_PORT_PTP_SUM_LO_A)); - ns |= (u64)t4_read_reg(adapter, - T5_PORT_REG(0, MAC_PORT_PTP_SUM_HI_A)) << 32; + if (CHELSIO_CHIP_VERSION(adapter->params.chip) >= CHELSIO_T7) + ns = t4_read_reg64(adapter, MAC_PTP_SUM_LO_A); + else + ns = t4_read_reg64(adapter, T5_PORT_REG(0, MAC_PORT_PTP_SUM_LO_A)); /* convert to timespec*/ *ts = ns_to_timespec64(ns); @@ -432,7 +451,7 @@ void cxgb4_ptp_init(struct adapter *adapter) spin_lock_init(&adapter->ptp_lock); adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info, - &adapter->pdev->dev); + adapter->pdev_dev); if (IS_ERR_OR_NULL(adapter->ptp_clock)) { adapter->ptp_clock = NULL; dev_err(adapter->pdev_dev, diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c index 71d936810696..b33ded33a9f2 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c @@ -1529,13 +1529,18 @@ static netdev_tx_t cxgb4_eth_xmit(struct sk_buff *skb, struct net_device *dev) #endif /* CHELSIO_TLS_DEVICE */ qidx = skb_get_queue_mapping(skb); + chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip); + + /* A PTP packet is timestamped only if it fits in an immediate work + * request: the timestamp is read back through adap->ptp_tx_skb, which + * the SGL path would orphan and keep mapped. + */ + if (ptp_enabled && (skb_is_gso(skb) || !is_eth_imm(skb, chip_ver))) + ptp_enabled = false; + if (ptp_enabled) { - if (!(adap->ptp_tx_skb)) { - skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; - adap->ptp_tx_skb = skb_get(skb); - } else { + if (adap->ptp_tx_skb) goto out_free; - } q = &adap->sge.ptptxq; } else { q = &adap->sge.ethtxq[qidx + pi->first_qset]; @@ -1550,7 +1555,6 @@ static netdev_tx_t cxgb4_eth_xmit(struct sk_buff *skb, struct net_device *dev) goto out_free; #endif /* CONFIG_CHELSIO_T4_FCOE */ - chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip); flits = calc_tx_flits(skb, chip_ver); ndesc = flits_to_desc(flits); credits = txq_avail(&q->q) - ndesc; @@ -1581,6 +1585,12 @@ static netdev_tx_t cxgb4_eth_xmit(struct sk_buff *skb, struct net_device *dev) goto out_free; } + /* Claim the PTP Tx slot only once nothing can fail any more */ + if (ptp_enabled) { + skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; + adap->ptp_tx_skb = skb_get(skb); + } + wr_mid = FW_WR_LEN16_V(DIV_ROUND_UP(flits, 2)); if (unlikely(credits < ETHTXQ_STOP_THRES)) { /* After we're done injecting the Work Request for this @@ -3509,7 +3519,15 @@ static noinline int t4_systim_to_hwstamp(struct adapter *adapter, data = skb->data + sizeof(*cpl); skb_pull(skb, 2 * sizeof(u64) + sizeof(struct cpl_rx_mps_pkt)); - offset = ETH_HLEN + IPV4_HLEN(skb->data) + UDP_HLEN; + + if (skb->len < ETH_HLEN) + return RX_PTP_PKT_ERR; + + /* IEEE 802.3 PTP carries the PTP message right after the MAC header */ + if (((struct ethhdr *)skb->data)->h_proto == htons(ETH_P_1588)) + offset = ETH_HLEN; + else + offset = ETH_HLEN + IPV4_HLEN(skb->data) + UDP_HLEN; if (skb->len < offset + OFF_PTP_SEQUENCE_ID + sizeof(short)) return RX_PTP_PKT_ERR; diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h b/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h index 4957045b6afe..83fde22afe17 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h +++ b/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h @@ -4574,6 +4574,7 @@ #define MAC_PORT_EPIO_OP_A 0x8d0 #define MAC_PORT_CFG2_A 0x818 +#define MAC_PTP_SUM_LO_A 0x38108 #define MAC_PORT_PTP_SUM_LO_A 0x990 #define MAC_PORT_PTP_SUM_HI_A 0x994 -- 2.39.1