From patchwork Fri Jan 10 03:17:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13933545 X-Patchwork-Delegate: kuba@kernel.org Received: from smtpbgbr1.qq.com (smtpbgbr1.qq.com [54.207.19.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F48413AD18 for ; Fri, 10 Jan 2025 02:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.207.19.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736477811; cv=none; b=md4sSgOq2glqy1XhEU6x2kE8twUzfpjsrwpqIi1IKOnzDTA5693Eh93bqSb1+8H9iM00Xvv6gVVUSBoK93ypXk5EYMSVJaAEfb3Xy0wqqvL18m50pNsBfuwfGTk118eTR3HV/D7IpdTRuHl5OyhW2gbCzpjRylVDwz2efY0AahM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736477811; c=relaxed/simple; bh=EdkB1nTJORPUmcnxasLVK9IKAPI6v3x4Ut7CLRIbjVQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UmYHPP+wyLMTj5SYuTNoHVS7VWRj/b5vpwRf50IXSrgnE0U4pwpAd9xqor1ACGLrFMg5ELP25Ofv/91ov0u5ePQtYhCJ16PEhk4INFXhpvmxHB1G/xZI99pAQMWHEMbFsCLXGE9I/hT2ExCfSuPTZYiwf7vLG60r18062xyGvBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=trustnetic.com; spf=pass smtp.mailfrom=trustnetic.com; arc=none smtp.client-ip=54.207.19.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=trustnetic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trustnetic.com X-QQ-mid: bizesmtpsz4t1736477797tjzs9g6 X-QQ-Originating-IP: B1C+wjHLm0Cadi4gbnR6tiHXQc8pPwcD0QvThWA55NY= Received: from wxdbg.localdomain.com ( [218.72.126.41]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 10 Jan 2025 10:56:36 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10969446398808863595 From: Jiawen Wu To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, linux@armlinux.org.uk, horms@kernel.org, jacob.e.keller@intel.com, netdev@vger.kernel.org, vadim.fedorenko@linux.dev Cc: mengyuanlou@net-swift.com, Jiawen Wu Subject: [PATCH net-next v3 3/4] net: wangxun: Implement do_aux_work of ptp_clock_info Date: Fri, 10 Jan 2025 11:17:15 +0800 Message-Id: <20250110031716.2120642-4-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20250110031716.2120642-1-jiawenwu@trustnetic.com> References: <20250110031716.2120642-1-jiawenwu@trustnetic.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:trustnetic.com:qybglogicsvrgz:qybglogicsvrgz8a-1 X-QQ-XMAILINFO: OYpbVsTx4C81cmDawgTVi1OPr0sIHAJTwcKCvMoT1Wz7gVFSiEsifsGh 3f9lLwgO0OBvwZbiceE4QuEVTa3iScUe7D1hx4lRmU1tMhjWGm1oe8Arv3fhhNHzBGaz9Np dAJt84sUerTt6Wmu3QwSfnmZO9lOjEPrxAHMSs6+ac7Wh+KxBfc7oBGJOkFEmEg96BquohP xMnfLTitlni4Qb4uI8E2GKKrO3qHnTjbbO28a3P7lrNF69g47TO3knf3O98re0UhvoxePTM 0Nx/06JoUUwzXvGaCzMGqLEETPvZhJOnNzURZ2F+yGnijwOUVaW244DzNB8QTA1M/nJVpKx NsoDGFm4yiVXNHqwUP5Ihaxnkntrr9OVJ8oLwutHhXP7C8LQJPCDo7gVy0kdfbWhWx4b8yv iky+uUmqGEHBER/Nyn6sibSJagmm4jYOf6SKO899rx3EaeCnH4pRGijvyDYzid/PqT2Y30e t9nhbW/VoFEJzxUhDfEwgnoJOCpQjclJyVlplJS6eJqCUQs5iDyvRXbdvTo1zvFMfLWFQ2P 3eh1GzLey9NC1FxDRxcUhCtz3z87ceDjW1gJJNyXjsvq9PyOM33JFrQos3fu8ZnHM9Y2+ck 9m40f/fQNcrW2/BanFFVn8oazBrbZ7Ma83+s/O7iYPvG+pmCzstX1f9X5dS5IbY2cR+7HYN kBQb9h9qH9vEcz+AS5yPD6tnn5mf1ViVkRkKeJFYcKZEjY8ruRIEaK/es5h8m8rbSJwMGDR kejHBEVhgC+X2h1QWeqHQJWyorZ7/EMkUo9rqTZoWCA8khRYHDTB5PPKP+attjXa29sjjAY 0MJciYeBmEboXBaSw0sHlbfb0XOUHO/hHDukTvmuwyxnjmM5BCsIlTg2GUYPD/Q754vmMc6 yiML8t3eu+VAFkjuoDr5dC2StDIYXYUua5b49i77UbuidX54dYN8MBuBx5s09JhOenoqE+M dFA7KDwh4k9pjkrWaqAt6RtIfiwJye0mmdC/kootpxfhRKUPAlGC9Y67lil1QNZEqbMwCxF u0eqgWxtHuEDlu5NHg X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= X-QQ-RECHKSPAM: 0 X-Patchwork-Delegate: kuba@kernel.org Implement watchdog task to detect SYSTIME overflow and error cases of Rx/Tx timestamp. Signed-off-by: Jiawen Wu --- drivers/net/ethernet/wangxun/libwx/wx_ptp.c | 113 ++++++++++++++++++ drivers/net/ethernet/wangxun/libwx/wx_type.h | 2 + drivers/net/ethernet/wangxun/ngbe/ngbe_mdio.c | 1 + .../net/ethernet/wangxun/txgbe/txgbe_phy.c | 1 + 4 files changed, 117 insertions(+) diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ptp.c b/drivers/net/ethernet/wangxun/libwx/wx_ptp.c index d97be12ef37c..e7dc9196ba54 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_ptp.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_ptp.c @@ -251,6 +251,116 @@ static void wx_ptp_tx_hwtstamp_work(struct work_struct *work) } } +/** + * wx_ptp_overflow_check - watchdog task to detect SYSTIME overflow + * @wx: pointer to wx struct + * + * this watchdog task periodically reads the timecounter + * in order to prevent missing when the system time registers wrap + * around. This needs to be run approximately twice a minute for the fastest + * overflowing hardware. We run it for all hardware since it shouldn't have a + * large impact. + */ +static void wx_ptp_overflow_check(struct wx *wx) +{ + bool timeout = time_is_before_jiffies(wx->last_overflow_check + + WX_OVERFLOW_PERIOD); + unsigned long flags; + + if (timeout) { + /* Update the timecounter */ + spin_lock_irqsave(&wx->tmreg_lock, flags); + timecounter_read(&wx->hw_tc); + spin_unlock_irqrestore(&wx->tmreg_lock, flags); + + wx->last_overflow_check = jiffies; + } +} + +/** + * wx_ptp_rx_hang - detect error case when Rx timestamp registers latched + * @wx: pointer to wx struct + * + * this watchdog task is scheduled to detect error case where hardware has + * dropped an Rx packet that was timestamped when the ring is full. The + * particular error is rare but leaves the device in a state unable to + * timestamp any future packets. + */ +static void wx_ptp_rx_hang(struct wx *wx) +{ + struct wx_ring *rx_ring; + unsigned long rx_event; + u32 tsyncrxctl; + int n; + + tsyncrxctl = rd32(wx, WX_PSR_1588_CTL); + + /* if we don't have a valid timestamp in the registers, just update the + * timeout counter and exit + */ + if (!(tsyncrxctl & WX_PSR_1588_CTL_VALID)) { + wx->last_rx_ptp_check = jiffies; + return; + } + + /* determine the most recent watchdog or rx_timestamp event */ + rx_event = wx->last_rx_ptp_check; + for (n = 0; n < wx->num_rx_queues; n++) { + rx_ring = wx->rx_ring[n]; + if (time_after(rx_ring->last_rx_timestamp, rx_event)) + rx_event = rx_ring->last_rx_timestamp; + } + + /* only need to read the high RXSTMP register to clear the lock */ + if (time_is_before_jiffies(rx_event + 5 * HZ)) { + rd32(wx, WX_PSR_1588_STMPH); + wx->last_rx_ptp_check = jiffies; + + wx->rx_hwtstamp_cleared++; + dev_warn(&wx->pdev->dev, "clearing RX Timestamp hang"); + } +} + +/** + * wx_ptp_tx_hang - detect error case where Tx timestamp never finishes + * @wx: private network wx structure + */ +static void wx_ptp_tx_hang(struct wx *wx) +{ + bool timeout = time_is_before_jiffies(wx->ptp_tx_start + + WX_PTP_TX_TIMEOUT); + + if (!wx->ptp_tx_skb) + return; + + if (!test_bit(WX_STATE_PTP_TX_IN_PROGRESS, wx->state)) + return; + + /* If we haven't received a timestamp within the timeout, it is + * reasonable to assume that it will never occur, so we can unlock the + * timestamp bit when this occurs. + */ + if (timeout) { + cancel_work_sync(&wx->ptp_tx_work); + wx_ptp_clear_tx_timestamp(wx); + wx->tx_hwtstamp_timeouts++; + dev_warn(&wx->pdev->dev, "clearing Tx timestamp hang\n"); + } +} + +static long wx_ptp_do_aux_work(struct ptp_clock_info *ptp) +{ + struct wx *wx = container_of(ptp, struct wx, ptp_caps); + + wx_ptp_overflow_check(wx); + if (unlikely(test_bit(WX_FLAG_RX_HWTSTAMP_IN_REGISTER, + wx->flags))) + wx_ptp_rx_hang(wx); + wx_ptp_tx_hang(wx); + + return HZ; +} + /** * wx_ptp_create_clock * @wx: the private board structure @@ -283,6 +393,7 @@ static long wx_ptp_create_clock(struct wx *wx) wx->ptp_caps.adjtime = wx_ptp_adjtime; wx->ptp_caps.gettimex64 = wx_ptp_gettimex64; wx->ptp_caps.settime64 = wx_ptp_settime64; + wx->ptp_caps.do_aux_work = wx_ptp_do_aux_work; if (wx->mac.type == wx_mac_em) wx->ptp_caps.max_adj = 500000000; else @@ -568,6 +679,8 @@ void wx_ptp_reset(struct wx *wx) timecounter_init(&wx->hw_tc, &wx->hw_cc, ktime_to_ns(ktime_get_real())); spin_unlock_irqrestore(&wx->tmreg_lock, flags); + + wx->last_overflow_check = jiffies; } EXPORT_SYMBOL(wx_ptp_reset); diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h index e70b397d1104..867d92547b61 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_type.h +++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h @@ -1174,6 +1174,8 @@ struct wx { u32 tx_hwtstamp_timeouts; u32 tx_hwtstamp_skipped; u32 rx_hwtstamp_cleared; + unsigned long last_overflow_check; + unsigned long last_rx_ptp_check; unsigned long ptp_tx_start; spinlock_t tmreg_lock; /* spinlock for ptp */ struct cyclecounter hw_cc; diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_mdio.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_mdio.c index c7944e62838a..ea1d7e9a91f3 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_mdio.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_mdio.c @@ -111,6 +111,7 @@ static void ngbe_mac_link_up(struct phylink_config *config, wr32(wx, WX_MAC_WDG_TIMEOUT, reg); wx->speed = speed; + wx->last_rx_ptp_check = jiffies; if (test_bit(WX_STATE_PTP_RUNNING, wx->state)) wx_ptp_reset_cyclecounter(wx); } diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c index 60e5f3288ad8..7e17d727c2ba 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c @@ -222,6 +222,7 @@ static void txgbe_mac_link_up(struct phylink_config *config, wr32(wx, WX_MAC_WDG_TIMEOUT, wdg); wx->speed = speed; + wx->last_rx_ptp_check = jiffies; if (test_bit(WX_STATE_PTP_RUNNING, wx->state)) wx_ptp_reset_cyclecounter(wx); }