Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3424691pxf; Mon, 29 Mar 2021 01:41:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUqTTk4wmv6/PPFyhrq4XlykIk9Gah1vgYXPck/0lCNEAFNIXWzIkYgb0I54R8wOb/y7w3 X-Received: by 2002:a17:907:e88:: with SMTP id ho8mr28283677ejc.199.1617007284616; Mon, 29 Mar 2021 01:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617007284; cv=none; d=google.com; s=arc-20160816; b=zv3/AP78m9ER0kR6cXxXizEoWFyKLYgho+vikJRnI15xoZeNA6YIK2LgGi/FmazJE0 BLkTQynSuNkn/saGuNXHFG/KdxGYtT5F4U7tXiktq1uik6C492+NKDfUAK7lfUpbftxy hRj2OOeGRwRBerS9vlgfMIPHW3LXGWfikrR9kLNSnBZyQwNTzfINK+WWwgVb8ZIJUf4T AmUbuY5McwfIyN2GVdIf646il07DhX1FZCWtn1GJ9EnGAJEU/4jb/HuQSY2Iit3bwd7e MALCl0tkc6X4SmIERkEBMD9/Wn2d9v4CON1RmDfy3qI7yxz/xlg0kD3R1fKTLh4fZ4KO 4Fmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GVLcRKT6OKKzjaM5Ew/21zkTsAtPel0cGfAS+f74D7U=; b=qtmyG79J3WNJIkyNrvovjpNKc5VlDbwYubDL2qqsbAnyoBy1FlS/RxtfSKPMW7q4aP pTW+R5BcSKZOgeiD7RYcDr9eSsQTrl2Kjn8nddqzB2DwKQpvzr/7YKWaDH8lN7+noF2h rdgSz5xS+/d2w6YZ4BWOYk7ojWJm1sPLkc3foaGMYNWlX52wFGGol8YlcwBM9ajmrlKX dj49eLrEBeislZlXv16cVXMBVYUtuPVG5trRK4oITZ+gcFl7EmC5DYCT0ifC4k1lIkQl nh1+cA1wuOxK4kLRfwzQC/ea0H+lVcFqse5jDFiVMc7qgsOEUvEbBdpLpVW1BaO9q2jP nkwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zuJNMnk0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si12300131eji.719.2021.03.29.01.41.01; Mon, 29 Mar 2021 01:41:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zuJNMnk0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232481AbhC2IiX (ORCPT + 99 others); Mon, 29 Mar 2021 04:38:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:39492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234034AbhC2IWx (ORCPT ); Mon, 29 Mar 2021 04:22:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EDC9C61554; Mon, 29 Mar 2021 08:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006173; bh=EyJ19PmcJrJrQoziqBfQQkVFwOGfqLv3AECK8JWZtMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zuJNMnk0yanMzH7+O3ChIjAKPQAk0YFA1hq6Y+XwfWEvJ53PIjGNsaMpkjSLb4D4R AiRVl+vrXPWmgJRHPvpsnm88wre9Wr9bAP42IfBknkBY6Dq2cPoeUAAMde0cUs+CZU RRDwfjqlNWfpFj/KWl5613BdwXknbm5M1y9zfObo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andre Guedes , Vedang Patel , Jithu Joseph , Maciej Fijalkowski , Dvora Fuxbrumer , Tony Nguyen , Sasha Levin Subject: [PATCH 5.10 108/221] igc: Fix igc_ptp_rx_pktstamp() Date: Mon, 29 Mar 2021 09:57:19 +0200 Message-Id: <20210329075632.816219711@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andre Guedes [ Upstream commit fc9e5020971d57d7d0b3fef9e2ab2108fcb5588b ] The comment describing the timestamps layout in the packet buffer is wrong and the code is actually retrieving the timestamp in Timer 1 reference instead of Timer 0. This hasn't been a big issue so far because hardware is configured to report both timestamps using Timer 0 (see IGC_SRRCTL register configuration in igc_ptp_enable_rx_timestamp() helper). This patch fixes the comment and the code so we retrieve the timestamp in Timer 0 reference as expected. This patch also takes the opportunity to get rid of the hw.mac.type check since it is not required. Fixes: 81b055205e8ba ("igc: Add support for RX timestamping") Signed-off-by: Andre Guedes Signed-off-by: Vedang Patel Signed-off-by: Jithu Joseph Reviewed-by: Maciej Fijalkowski Tested-by: Dvora Fuxbrumer Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/igc/igc.h | 2 +- drivers/net/ethernet/intel/igc/igc_ptp.c | 72 +++++++++++++----------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/intel/igc/igc.h b/drivers/net/ethernet/intel/igc/igc.h index 35baae900c1f..6dca67d9c25d 100644 --- a/drivers/net/ethernet/intel/igc/igc.h +++ b/drivers/net/ethernet/intel/igc/igc.h @@ -545,7 +545,7 @@ void igc_ptp_init(struct igc_adapter *adapter); void igc_ptp_reset(struct igc_adapter *adapter); void igc_ptp_suspend(struct igc_adapter *adapter); void igc_ptp_stop(struct igc_adapter *adapter); -void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, void *va, +void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, __le32 *va, struct sk_buff *skb); int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr); int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr); diff --git a/drivers/net/ethernet/intel/igc/igc_ptp.c b/drivers/net/ethernet/intel/igc/igc_ptp.c index ac0b9c85da7c..545f4d0e67cf 100644 --- a/drivers/net/ethernet/intel/igc/igc_ptp.c +++ b/drivers/net/ethernet/intel/igc/igc_ptp.c @@ -152,46 +152,54 @@ static void igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter, } /** - * igc_ptp_rx_pktstamp - retrieve Rx per packet timestamp + * igc_ptp_rx_pktstamp - Retrieve timestamp from Rx packet buffer * @q_vector: Pointer to interrupt specific structure * @va: Pointer to address containing Rx buffer * @skb: Buffer containing timestamp and packet * - * This function is meant to retrieve the first timestamp from the - * first buffer of an incoming frame. The value is stored in little - * endian format starting on byte 0. There's a second timestamp - * starting on byte 8. - **/ -void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, void *va, + * This function retrieves the timestamp saved in the beginning of packet + * buffer. While two timestamps are available, one in timer0 reference and the + * other in timer1 reference, this function considers only the timestamp in + * timer0 reference. + */ +void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, __le32 *va, struct sk_buff *skb) { struct igc_adapter *adapter = q_vector->adapter; - __le64 *regval = (__le64 *)va; - int adjust = 0; - - /* The timestamp is recorded in little endian format. - * DWORD: | 0 | 1 | 2 | 3 - * Field: | Timer0 Low | Timer0 High | Timer1 Low | Timer1 High + u64 regval; + int adjust; + + /* Timestamps are saved in little endian at the beginning of the packet + * buffer following the layout: + * + * DWORD: | 0 | 1 | 2 | 3 | + * Field: | Timer1 SYSTIML | Timer1 SYSTIMH | Timer0 SYSTIML | Timer0 SYSTIMH | + * + * SYSTIML holds the nanoseconds part while SYSTIMH holds the seconds + * part of the timestamp. */ - igc_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), - le64_to_cpu(regval[0])); - - /* adjust timestamp for the RX latency based on link speed */ - if (adapter->hw.mac.type == igc_i225) { - switch (adapter->link_speed) { - case SPEED_10: - adjust = IGC_I225_RX_LATENCY_10; - break; - case SPEED_100: - adjust = IGC_I225_RX_LATENCY_100; - break; - case SPEED_1000: - adjust = IGC_I225_RX_LATENCY_1000; - break; - case SPEED_2500: - adjust = IGC_I225_RX_LATENCY_2500; - break; - } + regval = le32_to_cpu(va[2]); + regval |= (u64)le32_to_cpu(va[3]) << 32; + igc_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval); + + /* Adjust timestamp for the RX latency based on link speed */ + switch (adapter->link_speed) { + case SPEED_10: + adjust = IGC_I225_RX_LATENCY_10; + break; + case SPEED_100: + adjust = IGC_I225_RX_LATENCY_100; + break; + case SPEED_1000: + adjust = IGC_I225_RX_LATENCY_1000; + break; + case SPEED_2500: + adjust = IGC_I225_RX_LATENCY_2500; + break; + default: + adjust = 0; + netdev_warn_once(adapter->netdev, "Imprecise timestamp\n"); + break; } skb_hwtstamps(skb)->hwtstamp = ktime_sub_ns(skb_hwtstamps(skb)->hwtstamp, adjust); -- 2.30.1