From patchwork Wed Jun 2 17:31:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Keller, Jacob E" X-Patchwork-Id: 1486827 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FwGLD304Zz9sRK for ; Thu, 3 Jun 2021 03:32:03 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 491E483C01; Wed, 2 Jun 2021 17:32:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2SvyXtR-PMxg; Wed, 2 Jun 2021 17:32:01 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id 693C083D6E; Wed, 2 Jun 2021 17:32:01 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id F1D9C1BF990 for ; Wed, 2 Jun 2021 17:31:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id EC17340500 for ; Wed, 2 Jun 2021 17:31:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Eu9D8lxV3pqH for ; Wed, 2 Jun 2021 17:31:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by smtp4.osuosl.org (Postfix) with ESMTPS id 6B541404E8 for ; Wed, 2 Jun 2021 17:31:57 +0000 (UTC) IronPort-SDR: 4G6HrKBgNFBNTT73DqL9JHlANFlm8tYTiPSqjHTad61VxFYihbNNbFhax9HWpJbtT5Rx4Ndtr9 j7rY3e9FzXEA== X-IronPort-AV: E=McAfee;i="6200,9189,10003"; a="183527611" X-IronPort-AV: E=Sophos;i="5.83,242,1616482800"; d="scan'208";a="183527611" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2021 10:31:54 -0700 IronPort-SDR: 3JSLSKDcBIRpUJKDZLjwRBaShCEDmQwZIfspYvVWO8rTPNwaL/6pIIWmv7bD0AvsUfdEcXtX9c o3iNzZi7Ieag== X-IronPort-AV: E=Sophos;i="5.83,242,1616482800"; d="scan'208";a="617279495" Received: from jekeller-desk.amr.corp.intel.com ([10.166.241.4]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2021 10:31:54 -0700 From: Jacob Keller To: Anthony Nguyen Date: Wed, 2 Jun 2021 10:31:34 -0700 Message-Id: <20210602173134.4167891-1-jacob.e.keller@intel.com> X-Mailer: git-send-email 2.31.1.331.gb0c09ab8796f MIME-Version: 1.0 Subject: [Intel-wired-lan] [PATCH] squash! ice: enable receive hardware timestamping X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Intel Wired LAN Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" The ice_ptp_extend_32b_ts function is used to calculate the corrected 64bit timestamp from a 32bit timestamp and a cached copy of the PHC time. This function uses a local mask constant generated by GENMASK_ULL. This value is identical to U32_MAX. Some static analyzers (such as Klocwork) appear to incorrectly expand GENMASK_ULL(31, 0) into the wrong value. This causes the static analyzer to report that the "delta > (mask / 2)" calculation is redundant since delta can never be large enough to be greater than the mask divided by 2. We can fix this by removing the constant mask value and replacing it with U32_MAX. Once we've done this, it's clear that cached_phc_time & U32_MASK is the same as (u32)cached_phc_time, since casting down to a u32 will just discard the high bits. Make this explicit by using a new local variable, phc_time_lo. Signed-off-by: Jacob Keller --- drivers/net/ethernet/intel/ice/ice_ptp.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c index 4608a69acba2..71cd5474ec86 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -329,23 +329,25 @@ static void ice_ptp_update_cached_phctime(struct ice_pf *pf) */ static u64 ice_ptp_extend_32b_ts(u64 cached_phc_time, u32 in_tstamp) { - const u64 mask = GENMASK_ULL(31, 0); - u32 delta; + u32 delta, phc_time_lo; u64 ns; + /* Extract the lower 32 bits of the PHC time */ + phc_time_lo = (u32)cached_phc_time; + /* Calculate the delta between the lower 32bits of the cached PHC * time and the in_tstamp value */ - delta = (in_tstamp - (u32)(cached_phc_time & mask)); + delta = (in_tstamp - phc_time_lo); /* Do not assume that the in_tstamp is always more recent than the * cached PHC time. If the delta is large, it indicates that the * in_tstamp was taken in the past, and should be converted * forward. */ - if (delta > (mask / 2)) { + if (delta > (U32_MAX / 2)) { /* reverse the delta calculation here */ - delta = ((u32)(cached_phc_time & mask) - in_tstamp); + delta = (phc_time_lo - in_tstamp); ns = cached_phc_time - delta; } else { ns = cached_phc_time + delta;