From patchwork Sun Mar 6 08:56:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 12770596 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF55EC433F5 for ; Sun, 6 Mar 2022 08:57:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232996AbiCFI63 (ORCPT ); Sun, 6 Mar 2022 03:58:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbiCFI62 (ORCPT ); Sun, 6 Mar 2022 03:58:28 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CA4E1276F for ; Sun, 6 Mar 2022 00:57:37 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id y2so11372526edc.2 for ; Sun, 06 Mar 2022 00:57:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=engleder-embedded-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4tpRDlVpoM3YR6pw/CRsfFETA4WrdcR4DFtWFWhIyko=; b=qf82AtZNyc5+PaP+vKwFH2u0eaA1DB7aenGFLEoGm+Qfdch859M+3BLLpv92S3/Of5 1TVh/fbkvPVh1NSOaYG/7PYYk+MHMA6lhe0b/YkkK6v4lDYh4JYXRUB89FFYlm6ds5rz tEowu6XPEby9FpSTter5InYNlEOPf64WaUrV7/W74OCRr6M4eMWkGtuncMsqEcR6coUt 69msjkK4z/UOWWOGBJxCHQr52dVn2mXF19lquUxYNyE2qJyu56t0hToqyfAcPnFcj8VB FsN2WZpYHw8NgXx4CbJIEnxcze3S9hwH+mcWCsg1rfBNqc229m8+vH3A5lBP0N/uR6zF 5Eaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4tpRDlVpoM3YR6pw/CRsfFETA4WrdcR4DFtWFWhIyko=; b=tCEaJlh6N23qMrEwz49/HAAbUCPRUeTf73nv4Yp6K4V2unMF+SK0/Ie36GkuTO1Wnv V0yeuxkGz0ccfZdZM21z/GPym+cliE6GXrUn8gMNLWu3IRTYarRFA89spwKZdKsDLxHq HeYLM/zeurBzcT6LlVjLcRXAllsLNDbkufqOlHcL/Q4RGK0+WXwU2WKqfUZnPGkfV/iT /rJDDSeCAMk2xoff6MfDo+ZvL2/gd/EYisci16nD+LmdGw4d4Eq0+mC+JcQDf1uQJe26 QCTN8EUFEd6QfEGCZIKrSNsGtDyW0u5FDoCiFndBBysV9U+0il640H1rKVqlCUxCwqpH Z5Nw== X-Gm-Message-State: AOAM533liNz9o4fv4WH0bgraef9h0gNclmzbp8BHWpfSXK0iG5yLFkqk ZGuEbyeBcnIOuYeAyV0pRYDOIA== X-Google-Smtp-Source: ABdhPJyVFpGCc30KTKxZXHEIKBTFpmHvD+qieWtZO6ZknZHSlAjFSGtgHwfN+M8Qb/vKLlJEi+oNpg== X-Received: by 2002:aa7:d403:0:b0:40f:739c:cbae with SMTP id z3-20020aa7d403000000b0040f739ccbaemr5978606edq.267.1646557055916; Sun, 06 Mar 2022 00:57:35 -0800 (PST) Received: from hornet.engleder.at ([2001:871:23a:8366:6e3b:e5ff:fe2c:34c1]) by smtp.gmail.com with ESMTPSA id z24-20020a170906815800b006dab4bd985dsm2663423ejw.107.2022.03.06.00.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 00:57:35 -0800 (PST) From: Gerhard Engleder To: richardcochran@gmail.com, yangbo.lu@nxp.com, davem@davemloft.net, kuba@kernel.org Cc: mlichvar@redhat.com, vinicius.gomes@intel.com, netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next 1/6] bpf: Access hwtstamp field of hwtstamps directly Date: Sun, 6 Mar 2022 09:56:53 +0100 Message-Id: <20220306085658.1943-2-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220306085658.1943-1-gerhard@engleder-embedded.com> References: <20220306085658.1943-1-gerhard@engleder-embedded.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC skb_shared_hwtstamps contains only the field hwtstamp. That property is hard-coded and checked during build in BPF. bpf_target_off() gets the whole structure as argument (hwtstamps) instead of the actually accessed field hwtstamp. Access hwtstamp field directly and allow future extensions of skb_shared_hwtstamps. Signed-off-by: Gerhard Engleder --- net/core/filter.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 88767f7da150..09e202b60060 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -9364,13 +9364,12 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, break; case offsetof(struct __sk_buff, hwtstamp): BUILD_BUG_ON(sizeof_field(struct skb_shared_hwtstamps, hwtstamp) != 8); - BUILD_BUG_ON(offsetof(struct skb_shared_hwtstamps, hwtstamp) != 0); insn = bpf_convert_shinfo_access(si, insn); *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg, bpf_target_off(struct skb_shared_info, - hwtstamps, 8, + hwtstamps.hwtstamp, 8, target_size)); break; } From patchwork Sun Mar 6 08:56:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 12770600 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B527C4332F for ; Sun, 6 Mar 2022 08:57:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232978AbiCFI6f (ORCPT ); Sun, 6 Mar 2022 03:58:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233002AbiCFI6c (ORCPT ); Sun, 6 Mar 2022 03:58:32 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 941DA1A394 for ; Sun, 6 Mar 2022 00:57:39 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id q17so16017270edd.4 for ; Sun, 06 Mar 2022 00:57:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=engleder-embedded-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k6CeGpm/lwo9g059L+ipT3MX8Qu35+AyMwdPGKmU+fQ=; b=hOXJDS7wcoaKCIXCo6nqbQ7xulyTuhYSlxmTYEQyhdiIjnRA9Knt93J1F49QiyhEZT oApXKTO2dec3oe6WxsbRgLEm11cxQbt+IaZ5yT9+t+RlHWivibt+d6UkWdqLy2RWbAV9 IAhOve8i+x1JXflXTXfq7Gf5g9e47/7Em7zYZJ/qGyDg3ixfImbhrK0MO4Lvue+28Oh0 MCHZfxDi1+o9NHG+bbI9X/MTqxD2DjLw5yrvJXyrVuhL+PpIvmWGySwK7xLrZ1GtvEgw Df4niHEO7r8d0+LU+A+YUPXxjzBfhjfkVgZ3wbGhHmCfOgD8RLRullr2pW1+x1UyUAJf v5GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k6CeGpm/lwo9g059L+ipT3MX8Qu35+AyMwdPGKmU+fQ=; b=sEBdfPlNPnpycnSaHz4CDevHDPqj3njnqdcL8ROAsxkv2IWNmZYaPtkOPmEaPXoogo xgovjEtUo3deEtplAw6ZkAA3ydKoVevGdZdo307XrX5CG4/nvwrTDq1Yx6ThhOqNZLAu 3TjKg7CvjY5776r8wQLKoz6oqp+ysOfDk2GzGuVauaGiQsWAQz7dkpHvfXI3I8G6hmzh lgSVKMJFbqVZFgd6yavuJRSZ6Tbatj9Sr05xZehAgCDmEiyClQBq1vTt6jgPxePxo618 ajZYcCkZQ58oyljeiWQcQNQgBBICElLCjE/f9lF5ZLH1pYDBcctPvpgCGFKBrDUxUee2 rqrQ== X-Gm-Message-State: AOAM533fSdnYwcGS+BgkA3yrf8LhLhObbEnLUKLLoeViXiQ9LQx8On8i uaQAJetpN5wiqhYP3O5Polq0gNV7QCTXzR/z X-Google-Smtp-Source: ABdhPJyyqhGGVtsfvrYZSSPLT1wC0pZVqDSL0GwmADyV/sBa2UBmHLwTJXYOXpbXV/pkaXeVoNwGzg== X-Received: by 2002:a05:6402:5209:b0:412:7cd8:a8fc with SMTP id s9-20020a056402520900b004127cd8a8fcmr5964671edd.51.1646557058088; Sun, 06 Mar 2022 00:57:38 -0800 (PST) Received: from hornet.engleder.at ([2001:871:23a:8366:6e3b:e5ff:fe2c:34c1]) by smtp.gmail.com with ESMTPSA id z24-20020a170906815800b006dab4bd985dsm2663423ejw.107.2022.03.06.00.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 00:57:37 -0800 (PST) From: Gerhard Engleder To: richardcochran@gmail.com, yangbo.lu@nxp.com, davem@davemloft.net, kuba@kernel.org Cc: mlichvar@redhat.com, vinicius.gomes@intel.com, netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next 2/6] ptp: Initialize skb_shared_hwtstamps Date: Sun, 6 Mar 2022 09:56:54 +0100 Message-Id: <20220306085658.1943-3-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220306085658.1943-1-gerhard@engleder-embedded.com> References: <20220306085658.1943-1-gerhard@engleder-embedded.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC There are only a few locations, which do not initialize the whole skb_shared_hwtstamps structure and write the only field of the structure. This is ok as long as skb_shared_hwtstamps is not extended with additional fields. Always initialize the whole skb_shared_hwtstamps structure to prepare for future extensions of this structure. Signed-off-by: Gerhard Engleder --- drivers/net/ethernet/cavium/liquidio/lio_main.c | 1 + drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 1 + drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c | 1 + drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c | 1 + drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c | 1 + drivers/net/ethernet/sfc/tx_common.c | 1 + drivers/ptp/ptp_ines.c | 1 + 7 files changed, 7 insertions(+) diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c index ba28aa444e5a..8c7868007bdf 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c @@ -2212,6 +2212,7 @@ static void handle_timestamp(struct octeon_device *oct, netif_info(lio, tx_done, lio->netdev, "Got resulting SKBTX_HW_TSTAMP skb=%p ns=%016llu\n", skb, (unsigned long long)ns); + memset(&ts, 0, sizeof(ts)); ts.hwtstamp = ns_to_ktime(ns + lio->ptp_adjust); skb_tstamp_tx(skb, &ts); } diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c index 568f211d91cc..ebac2d46a3bf 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c @@ -1340,6 +1340,7 @@ static void handle_timestamp(struct octeon_device *oct, u32 status, void *buf) netif_info(lio, tx_done, lio->netdev, "Got resulting SKBTX_HW_TSTAMP skb=%p ns=%016llu\n", skb, (unsigned long long)ns); + memset(&ts, 0, sizeof(ts)); ts.hwtstamp = ns_to_ktime(ns + lio->ptp_adjust); skb_tstamp_tx(skb, &ts); } diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c index 5bf117d2179f..67241dbe575c 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c @@ -109,6 +109,7 @@ void cxgb4_ptp_read_hwstamp(struct adapter *adapter, struct port_info *pi) tx_ts |= (u64)t4_read_reg(adapter, T5_PORT_REG(pi->port_id, MAC_PORT_TX_TS_VAL_HI)) << 32; + memset(skb_ts, 0, sizeof(*skb_ts)); 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); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c index a40b1583f114..4e378d856529 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c @@ -103,6 +103,7 @@ void hclge_ptp_clean_tx_hwts(struct hclge_dev *hdev) hdev->ptp->tx_cleaned++; ns += (((u64)hi) << 32 | lo) * NSEC_PER_SEC; + memset(&hwts, 0, sizeof(hwts)); hwts.hwtstamp = ns_to_ktime(ns); skb_tstamp_tx(skb, &hwts); dev_kfree_skb_any(skb); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c index 35422e64d89f..887a09887f03 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c @@ -445,6 +445,7 @@ static void mlxsw_sp1_packet_timestamp(struct mlxsw_sp *mlxsw_sp, nsec = timecounter_cyc2time(&mlxsw_sp->clock->tc, timestamp); spin_unlock_bh(&mlxsw_sp->clock->lock); + memset(&hwtstamps, 0, sizeof(hwtstamps)); hwtstamps.hwtstamp = ns_to_ktime(nsec); mlxsw_sp1_ptp_packet_finish(mlxsw_sp, skb, key.local_port, key.ingress, &hwtstamps); diff --git a/drivers/net/ethernet/sfc/tx_common.c b/drivers/net/ethernet/sfc/tx_common.c index d530cde2b864..f7b6228a6be0 100644 --- a/drivers/net/ethernet/sfc/tx_common.c +++ b/drivers/net/ethernet/sfc/tx_common.c @@ -170,6 +170,7 @@ void efx_dequeue_buffer(struct efx_tx_queue *tx_queue, tx_queue->completed_timestamp_minor)) { struct skb_shared_hwtstamps hwtstamp; + memset(&hwtstamp, 0, sizeof(hwtstamp)); hwtstamp.hwtstamp = efx_ptp_nic_to_kernel_time(tx_queue); skb_tstamp_tx(skb, &hwtstamp); diff --git a/drivers/ptp/ptp_ines.c b/drivers/ptp/ptp_ines.c index 61f47fb9d997..6413e44267cc 100644 --- a/drivers/ptp/ptp_ines.c +++ b/drivers/ptp/ptp_ines.c @@ -659,6 +659,7 @@ static void ines_txtstamp_work(struct work_struct *work) kfree_skb(skb); return; } + memset(&ssh, 0, sizeof(ssh)); ssh.hwtstamp = ns_to_ktime(ns); skb_complete_tx_timestamp(skb, &ssh); } From patchwork Sun Mar 6 08:56:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 12770598 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A36FC43217 for ; Sun, 6 Mar 2022 08:57:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233055AbiCFI6h (ORCPT ); Sun, 6 Mar 2022 03:58:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233058AbiCFI6e (ORCPT ); Sun, 6 Mar 2022 03:58:34 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E18E1EECA for ; Sun, 6 Mar 2022 00:57:41 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id dr20so25959892ejc.6 for ; Sun, 06 Mar 2022 00:57:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=engleder-embedded-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GfSSb7+i0bqUTwc6AvkcGUVXMXbSZgE8tY3iI0Vn6+g=; b=5Hls2rNMYZWcLT6eOhIgaXZ5BLGZPhTevMdqAl+kS4EUjlLI63sv5JniGokNdLHJGu 1cxVIqieQRiOWgPcSRPam6JQRank6lrE0SUmQAVhxxPadiQlX7uohrxm+eF06w+r4cw2 YzomAsKS4iO2TJKTDNMoQA/JboH3YJG022XSWhCIKEL9ZwUHcyxj6c1Edn8/N+YiQc90 bUzLaWzRg2d4VC29SGBc5OI9X/HWkAwhiu7HpNnKOM3BP9pVvt1DpKyyVnGfLKgonrZc Yc/wlt2Jae5239SqGEOP2Y65bnRurOoaD5uUbEIw1HmQRhmFSqWRwIJmeThnbjov6+fh KcgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GfSSb7+i0bqUTwc6AvkcGUVXMXbSZgE8tY3iI0Vn6+g=; b=wmAmxKKgNL+yy72kzRf3mCaCJoYZWbYTCXMKqbY+JJVLw6qFNyMbIp3nn99C3jI0T8 Ywv/dKlFOHysk32MzQxHLcPGZB5PxaBrbzzNWxdbOtMTzTmr30PVunKAIKhuzMdK1nfz xEUKFqIR4o4bnt0TOZg0qLSa7bnVdKqZ/eZHFctGJP9XXD2ra6ZuEwQsLSCuG4tRYxb+ JEYm6xzoPjc084PHEkLyDfJrtIec8tVkrmZUOYtG1fxBA+tcMUQwudtHiU/Jn2dQ62TC T7721k8GWNM/C4WRgnlnxbb1jFOeNmS8hqTHrZpBziD4xjsKId75yD6s19388+67en7J s9lQ== X-Gm-Message-State: AOAM533+XLotv63iO0VlVBpIlbUlft9Xxc0sCrXo/swJnLBubFuZEPzS 9U6C+n2L5dmstJtgDba8OgCqwWD/hSm/PJi4 X-Google-Smtp-Source: ABdhPJxHU0G0abWFZ6vnrH+UGN1QQ4hBY0QNNmCp7v6GE9ORU9Q0DcQCVMjNQgvONVUqVjkqo8WEfg== X-Received: by 2002:a17:906:7852:b0:5bb:1bdb:e95f with SMTP id p18-20020a170906785200b005bb1bdbe95fmr5289735ejm.435.1646557059769; Sun, 06 Mar 2022 00:57:39 -0800 (PST) Received: from hornet.engleder.at ([2001:871:23a:8366:6e3b:e5ff:fe2c:34c1]) by smtp.gmail.com with ESMTPSA id z24-20020a170906815800b006dab4bd985dsm2663423ejw.107.2022.03.06.00.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 00:57:39 -0800 (PST) From: Gerhard Engleder To: richardcochran@gmail.com, yangbo.lu@nxp.com, davem@davemloft.net, kuba@kernel.org Cc: mlichvar@redhat.com, vinicius.gomes@intel.com, netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next 3/6] ptp: Add free running time support Date: Sun, 6 Mar 2022 09:56:55 +0100 Message-Id: <20220306085658.1943-4-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220306085658.1943-1-gerhard@engleder-embedded.com> References: <20220306085658.1943-1-gerhard@engleder-embedded.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC ptp vclocks require a clock with free running time for the timecounter. Currently only a physical clock forced to free running is supported. If vclocks are used, then the physical clock cannot be synchronized anymore. The synchronized time is not available in hardware in this case. As a result, timed transmission with ETF/TAPRIO hardware support is not possible anymore. If hardware would support a free running time additionally to the physical clock, then the physical clock does not need to be forced to free running. Thus, the physical clocks can still be synchronized while vclocks are in use. The physical clock could be used to synchronize the time domain of the TSN network and trigger ETF/TAPRIO. In parallel vclocks can be used to synchronize other time domains. Allow read and cross time stamp of additional free running time for physical clocks. Let vclocks use free running time if available. Signed-off-by: Gerhard Engleder --- drivers/ptp/ptp_vclock.c | 20 +++++++++++++++----- include/linux/ptp_clock_kernel.h | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index cb179a3ea508..3715d75ee8bd 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -68,7 +68,10 @@ static int ptp_vclock_gettimex(struct ptp_clock_info *ptp, int err; u64 ns; - err = pptp->info->gettimex64(pptp->info, &pts, sts); + if (pptp->info->getfreeruntimex64) + err = pptp->info->getfreeruntimex64(pptp->info, &pts, sts); + else + err = pptp->info->gettimex64(pptp->info, &pts, sts); if (err) return err; @@ -104,7 +107,10 @@ static int ptp_vclock_getcrosststamp(struct ptp_clock_info *ptp, int err; u64 ns; - err = pptp->info->getcrosststamp(pptp->info, xtstamp); + if (pptp->info->getfreeruncrosststamp) + err = pptp->info->getfreeruncrosststamp(pptp->info, xtstamp); + else + err = pptp->info->getcrosststamp(pptp->info, xtstamp); if (err) return err; @@ -143,7 +149,9 @@ static u64 ptp_vclock_read(const struct cyclecounter *cc) struct ptp_clock *ptp = vclock->pclock; struct timespec64 ts = {}; - if (ptp->info->gettimex64) + if (ptp->info->getfreeruntimex64) + ptp->info->getfreeruntimex64(ptp->info, &ts, NULL); + else if (ptp->info->gettimex64) ptp->info->gettimex64(ptp->info, &ts, NULL); else ptp->info->gettime64(ptp->info, &ts); @@ -168,11 +176,13 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock) vclock->pclock = pclock; vclock->info = ptp_vclock_info; - if (pclock->info->gettimex64) + if (pclock->info->getfreeruntimex64 || pclock->info->gettimex64) vclock->info.gettimex64 = ptp_vclock_gettimex; else vclock->info.gettime64 = ptp_vclock_gettime; - if (pclock->info->getcrosststamp) + if ((pclock->info->getfreeruntimex64 && + pclock->info->getfreeruncrosststamp) || + pclock->info->getcrosststamp) vclock->info.getcrosststamp = ptp_vclock_getcrosststamp; vclock->cc = ptp_vclock_cc; diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index 554454cb8693..b291517fc7c8 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -108,6 +108,28 @@ struct ptp_system_timestamp { * @settime64: Set the current time on the hardware clock. * parameter ts: Time value to set. * + * @getfreeruntimex64: Reads the current free running time from the hardware + * clock and optionally also the system clock. This + * operation requires hardware support for an additional + * free running time including support for hardware time + * stamps based on that free running time. + * The free running time must be completely independet from + * the actual time of the PTP clock. It must be monotonic + * and its frequency must be constant. + * parameter ts: Holds the PHC free running timestamp. + * parameter sts: If not NULL, it holds a pair of + * timestamps from the system clock. The first reading is + * made right before reading the lowest bits of the PHC + * free running timestamp and the second reading + * immediately follows that. + * + * @getfreeruncrosststamp: Reads the current time from the free running + * hardware clock and system clock simultaneously. + * parameter cts: Contains timestamp (device,system) + * pair, where device time is the free running time + * also used for @getfreeruntimex64 and system time is + * realtime and monotonic. + * * @enable: Request driver to enable or disable an ancillary feature. * parameter request: Desired resource to enable or disable. * parameter on: Caller passes one to enable or zero to disable. @@ -155,6 +177,11 @@ struct ptp_clock_info { int (*getcrosststamp)(struct ptp_clock_info *ptp, struct system_device_crosststamp *cts); int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts); + int (*getfreeruntimex64)(struct ptp_clock_info *ptp, + struct timespec64 *ts, + struct ptp_system_timestamp *sts); + int (*getfreeruncrosststamp)(struct ptp_clock_info *ptp, + struct system_device_crosststamp *cts); int (*enable)(struct ptp_clock_info *ptp, struct ptp_clock_request *request, int on); int (*verify)(struct ptp_clock_info *ptp, unsigned int pin, From patchwork Sun Mar 6 08:56:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 12770597 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A6CCC433FE for ; Sun, 6 Mar 2022 08:57:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbiCFI6g (ORCPT ); Sun, 6 Mar 2022 03:58:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233059AbiCFI6e (ORCPT ); Sun, 6 Mar 2022 03:58:34 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7872E1B786 for ; Sun, 6 Mar 2022 00:57:43 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id r13so26025698ejd.5 for ; Sun, 06 Mar 2022 00:57:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=engleder-embedded-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XDNNHD8OAOxJFkw4wjhl3Pxdt/6dwSNvkD57lHXJ1ng=; b=KhFhyRIKIUUoX6dTRdFFHJEK5ybgR5fqm8Lz2lvycRtwVaUSVKNNrzBuLv4mulYgPE nEo2gjXw9NsIytgKHPiq00X5oJHCScoC5lCsD9oUYbsrPMY8nohMzkl4UiC+b9mFjr7a cFbDBWk+HVBQjpFYVwwTPfQaNXFAe57Vd88DOjwivogTrR64ijvHB62hXRII0/CWBpv8 j1dTAcgOaTHzDCkF6RpBjAczcbftXWBZpi1t++xvG0qdYTbUIBgBaYs/xAQsn8AQ9rHS ENIUrMRAjIkSSHPs7yZePVYrN+hipyQeMOAQQJgcmpGUtry7qPwmy6kR+py8yvijglC+ VX4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XDNNHD8OAOxJFkw4wjhl3Pxdt/6dwSNvkD57lHXJ1ng=; b=8NBQGg8vdDHf5nkfz5yn6Zae+sNPAPtvfDX6Y9pYpTx1KlN2ig8Xs71fkG3B9J+mNz vkH3B2U9qlfFX6ENOacZSN+XHW7R5NzPuFvnyH+psI6RRpir2d1X2PVYWDg0p0hTEq0m hA963W14ti541YTRHmLe3I0w0GjyepM0a35sZot/y1nuuh97ENaVHAbTmmOnqFpJ7nzd RBkNOLyaJq0QvSM6g7uVbqrsjnS92JE3fCtJz9Az7sAYq4dvwb7Bk0cwhHhoxK3LeYg/ mNcqhr+2cDBRPTq/De4mjr1F6/nuB9XHfmviEOVCJTP5aEQBetKbqAgPYZjxgvm41JQ+ 9EeQ== X-Gm-Message-State: AOAM533aJMYK2D0J7hK1cHAQgGKQOW8pa1qv3+5gZ7q53hBI0tuYREF/ KW6K5S0doNaQ2duUHeoUoT6M1Q== X-Google-Smtp-Source: ABdhPJx9sYX70Ke88/sL/uyL40sPYF3Zs/87PGrwrCpSBMgL/l3QEnNFmWvdwau9fs+4+a76WXi5KQ== X-Received: by 2002:a17:906:c113:b0:6d7:7b53:9cb with SMTP id do19-20020a170906c11300b006d77b5309cbmr5399988ejc.197.1646557061982; Sun, 06 Mar 2022 00:57:41 -0800 (PST) Received: from hornet.engleder.at ([2001:871:23a:8366:6e3b:e5ff:fe2c:34c1]) by smtp.gmail.com with ESMTPSA id z24-20020a170906815800b006dab4bd985dsm2663423ejw.107.2022.03.06.00.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 00:57:41 -0800 (PST) From: Gerhard Engleder To: richardcochran@gmail.com, yangbo.lu@nxp.com, davem@davemloft.net, kuba@kernel.org Cc: mlichvar@redhat.com, vinicius.gomes@intel.com, netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next 4/6] ptp: Support time stamps based on free running time Date: Sun, 6 Mar 2022 09:56:56 +0100 Message-Id: <20220306085658.1943-5-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220306085658.1943-1-gerhard@engleder-embedded.com> References: <20220306085658.1943-1-gerhard@engleder-embedded.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Physical clocks are used for hardware time stamping. Also ptp vclocks support hardware time stamps. If a physical clock additionally supports a free running time and this time is used as base for ptp vclocks, then also hardware time stamps based on that free running time are required. Add hardware time stamp of additional free running time to skb_shared_hwtstamps and use it if physical clock supports an additional free running time. Signed-off-by: Gerhard Engleder --- drivers/ptp/ptp_vclock.c | 5 ++++- include/linux/skbuff.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index 3715d75ee8bd..84f798a11bca 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -268,7 +268,10 @@ ktime_t ptp_convert_timestamp(const struct skb_shared_hwtstamps *hwtstamps, vclock = info_to_vclock(ptp->info); - ns = ktime_to_ns(hwtstamps->hwtstamp); + if (vclock->pclock->info->getfreeruntimex64) + ns = ktime_to_ns(hwtstamps->hwfreeruntstamp); + else + ns = ktime_to_ns(hwtstamps->hwtstamp); spin_lock_irqsave(&vclock->lock, flags); ns = timecounter_cyc2time(&vclock->tc, ns); diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 2be263184d1e..2ec8d944a557 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -521,6 +521,8 @@ static inline bool skb_frag_must_loop(struct page *p) * struct skb_shared_hwtstamps - hardware time stamps * @hwtstamp: hardware time stamp transformed into duration * since arbitrary point in time + * @hwfreeruntstamp: hardware time stamp based on free running time + * transformed into duration since arbitrary point in time * * Software time stamps generated by ktime_get_real() are stored in * skb->tstamp. @@ -533,6 +535,7 @@ static inline bool skb_frag_must_loop(struct page *p) */ struct skb_shared_hwtstamps { ktime_t hwtstamp; + ktime_t hwfreeruntstamp; }; /* Definitions for tx_flags in struct skb_shared_info */ From patchwork Sun Mar 6 08:56:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 12770601 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B23ADC433EF for ; Sun, 6 Mar 2022 08:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231313AbiCFI6t (ORCPT ); Sun, 6 Mar 2022 03:58:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233019AbiCFI6g (ORCPT ); Sun, 6 Mar 2022 03:58:36 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E73F255AF for ; Sun, 6 Mar 2022 00:57:44 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id d10so25963584eje.10 for ; Sun, 06 Mar 2022 00:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=engleder-embedded-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nFl8voH13+B60rPVfRGg/sN/NnRz7ZCp7lxbB/q82DQ=; b=LqvzdCz+yDLiWJrQQBeQSBzyY40E+6veWVgX37z/icL5/bs4qknlHY+Z3jqVZsETbC UFn81NdQ8EVWQPa7fAl5+PuyVN0qn6DEnX1E3oEW5cGM2fsC8iejsAoBnioSm0c7VlBi 94RL0YFoupN9CpRjj/MhlhufxyQ/KRnf1UB8HXlRB0IR3wLwRLogcy9JEvVEwo7TUd1Y mWoIN6vPwqC6fJyj7u4CQRTrqEeXpnFujQRp9mELkJmaEPDJKm4/BqRivRMATDpusGzG isHVqfCDhle3+SBV6aOT9Wvt7clyH33b/j5CKt4ItP1GpIJmijYLVzm9z1mahec/qc9y mhTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nFl8voH13+B60rPVfRGg/sN/NnRz7ZCp7lxbB/q82DQ=; b=KFVQcBaYnT9bzkZQFJwZaJUHoybmFvewt3KcI+MWN3J7gfsHrHKZbwypNA6s9azfsb 8YBer1cBlc11QQGMXVNzBv1vzSnL4ZVU7Z0GDTOnNeblkPU+Byb48XQBxMC8PsqcnUWy CWhePujHAbB57b5O3p4CBm32PrrwcAIcNWyvWjGaejIrOm6OUjrhhLcxLmnMG6xQzVGm IK1HiGSvD2p09eEZu58EQgjUT2O0EXtSdautJs7pfoKwNtPEFnyTFlt4OOiT9ixnSolw HExkHSejkQmuL8/sJ1PT+SmhpCcaAJ1mKdLTztY1PLjC4lwU5g/L1rA0PTKvDb5yT7Ge gwAA== X-Gm-Message-State: AOAM530JDE24BXktzNHZplNkxBpyoSYO67yD+hGb1kJnC7pW/KZ9VlGr bO+UcVnwMjSL52Tc+R+5JrmgBQ== X-Google-Smtp-Source: ABdhPJzx7dnRgdVDMN0lCVQWsBOWbg2LkvbYDrmyeKUHEGn7xgRFXE0YjJ2wdfz+eZNUWWNj4lBrSg== X-Received: by 2002:a17:907:7283:b0:6da:9504:1dbf with SMTP id dt3-20020a170907728300b006da95041dbfmr4996134ejc.84.1646557063448; Sun, 06 Mar 2022 00:57:43 -0800 (PST) Received: from hornet.engleder.at ([2001:871:23a:8366:6e3b:e5ff:fe2c:34c1]) by smtp.gmail.com with ESMTPSA id z24-20020a170906815800b006dab4bd985dsm2663423ejw.107.2022.03.06.00.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 00:57:43 -0800 (PST) From: Gerhard Engleder To: richardcochran@gmail.com, yangbo.lu@nxp.com, davem@davemloft.net, kuba@kernel.org Cc: mlichvar@redhat.com, vinicius.gomes@intel.com, netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next 5/6] ptp: Allow vclocks without free running physical clock Date: Sun, 6 Mar 2022 09:56:57 +0100 Message-Id: <20220306085658.1943-6-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220306085658.1943-1-gerhard@engleder-embedded.com> References: <20220306085658.1943-1-gerhard@engleder-embedded.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC If a physical clock supports an additional free running time, then there is no need to force the physical clock itself to free running. Guarantee free running physical clock only if additional free running time is not supported. Signed-off-by: Gerhard Engleder --- drivers/ptp/ptp_clock.c | 8 ++++---- drivers/ptp/ptp_private.h | 9 +++++++++ drivers/ptp/ptp_sysfs.c | 11 ++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index b6f2cfd15dd2..b9944053e2b8 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -77,8 +77,8 @@ static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tp { struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); - if (ptp_vclock_in_use(ptp)) { - pr_err("ptp: virtual clock in use\n"); + if (ptp_vclock_free_run(ptp)) { + pr_err("ptp: virtual clock requires free run\n"); return -EBUSY; } @@ -103,8 +103,8 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx) struct ptp_clock_info *ops; int err = -EOPNOTSUPP; - if (ptp_vclock_in_use(ptp)) { - pr_err("ptp: virtual clock in use\n"); + if (ptp_vclock_free_run(ptp)) { + pr_err("ptp: virtual clock requires free run\n"); return -EBUSY; } diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index dba6be477067..595eb741d391 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -96,6 +96,15 @@ static inline bool ptp_vclock_in_use(struct ptp_clock *ptp) return in_use; } +/* Check if free run for virtual clock is required */ +static inline bool ptp_vclock_free_run(struct ptp_clock *ptp) +{ + if (ptp->info->getfreeruntimex64) + return false; + else + return ptp_vclock_in_use(ptp); +} + extern struct class *ptp_class; /* diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c index 9233bfedeb17..485dcfd4a8c3 100644 --- a/drivers/ptp/ptp_sysfs.c +++ b/drivers/ptp/ptp_sysfs.c @@ -230,11 +230,12 @@ static ssize_t n_vclocks_store(struct device *dev, for (i = 1; i <= ptp->n_vclocks - num; i++) *(ptp->vclock_index + ptp->n_vclocks - i) = -1; } - - if (num == 0) - dev_info(dev, "only physical clock in use now\n"); - else - dev_info(dev, "guarantee physical clock free running\n"); + if (!ptp->info->getfreeruntimex64) { + if (num == 0) + dev_info(dev, "only physical clock in use now\n"); + else + dev_info(dev, "guarantee physical clock free running\n"); + } ptp->n_vclocks = num; mutex_unlock(&ptp->n_vclocks_mux); From patchwork Sun Mar 6 08:56:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 12770602 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8D88C433F5 for ; Sun, 6 Mar 2022 08:58:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229829AbiCFI6u (ORCPT ); Sun, 6 Mar 2022 03:58:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233059AbiCFI6i (ORCPT ); Sun, 6 Mar 2022 03:58:38 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 921FA220E0 for ; Sun, 6 Mar 2022 00:57:46 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id y2so11372808edc.2 for ; Sun, 06 Mar 2022 00:57:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=engleder-embedded-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hxr58LzZb0xxkkoq+RaydR2euslE0TC19IlcbYrBZQY=; b=Pfh75midBf1EUr2TAsvYTlIJ+DYEdwl8BN5UPbCWSQOth9ajWfpD+86OfZndGAXcvz eAgCXhImV9xhOc2N0vW/6hGC93N7UmRi7o9k3yP4Xxi1Q0hMT2eQMBdmp3GN8HHuiEB6 GWRrqDRLKe+G8IDuSRZrWQeRzUUgD7DAQuWrW4TZq7WJMiKzbuzwD6WqpL4MnP/02vsX 0BTJrvGjL7XG5Bh+omAYgSnfEqPFMyTzzVQx0ts0koHsfYY90LCvSarM6mu/E2pjYxji btKejEQWgyixY/uB6CyiRSxnyd/IahpLWf3bFLAZbYnmS2PSqaJJSC2qwAC1oYq6lviV Zdxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hxr58LzZb0xxkkoq+RaydR2euslE0TC19IlcbYrBZQY=; b=VDHnlUvCEfl/rPCmSCNFBs/cpEMx9XxtbI57bpOpCToYvyk/m+PYPh8Wz23qEDPEqF N9hdn8B1vA7OVLjynXQhkHbEhEntF8Q6l/LJQr0tv0MqY4j03ncS5yLsfmspID38xGNc qZ8NJ7vIT+D8dK7jSruIetUNUqD7AldFzgD+O1c6/B79368+F2fCjD60FEE3PlJrjET2 XsP2ZDGDKmav0t1N3C0pKEUwE1IuHfaLFPWYLEeqJ0T8GdkJ11n+nxveio5Jn3psf5HH lODoGlmlQq+9dI4TdAqaFdhBjrgoQMoTAyt5uzsGYAKYaL2lU6tH2ictsbFdBUv3GbsJ t4rQ== X-Gm-Message-State: AOAM5339sNfzYAeVFxijiIgklC6fV0I3rJa0JJY9iQmOOl2DIsdMchFD gq+JswvBFZdX/zUsSrlSiKW1wA== X-Google-Smtp-Source: ABdhPJx4y9mO5/uw/w0zmTscsH8XTeYed+K5MptAi/ri9hbPRqKK+5Ei0ve0lsp6Vwl9KLvaDSBzWA== X-Received: by 2002:a05:6402:8d5:b0:416:1b20:5090 with SMTP id d21-20020a05640208d500b004161b205090mr5728555edz.393.1646557065183; Sun, 06 Mar 2022 00:57:45 -0800 (PST) Received: from hornet.engleder.at ([2001:871:23a:8366:6e3b:e5ff:fe2c:34c1]) by smtp.gmail.com with ESMTPSA id z24-20020a170906815800b006dab4bd985dsm2663423ejw.107.2022.03.06.00.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 00:57:44 -0800 (PST) From: Gerhard Engleder To: richardcochran@gmail.com, yangbo.lu@nxp.com, davem@davemloft.net, kuba@kernel.org Cc: mlichvar@redhat.com, vinicius.gomes@intel.com, netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next 6/6] tsnep: Add free running time support Date: Sun, 6 Mar 2022 09:56:58 +0100 Message-Id: <20220306085658.1943-7-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220306085658.1943-1-gerhard@engleder-embedded.com> References: <20220306085658.1943-1-gerhard@engleder-embedded.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The TSN endpoint Ethernet MAC supports a free running counter additionally to its clock. This free running counter can be read and hardware time stamps are supported. As the name implies, this counter cannot be set and its frequency cannot be adjusted. Add free running time support based on free running counter to physical clock. This also requires hardware time stamps based on that free running time. Signed-off-by: Gerhard Engleder --- drivers/net/ethernet/engleder/tsnep_hw.h | 9 +++++-- drivers/net/ethernet/engleder/tsnep_main.c | 6 +++++ drivers/net/ethernet/engleder/tsnep_ptp.c | 28 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/engleder/tsnep_hw.h b/drivers/net/ethernet/engleder/tsnep_hw.h index 71cc8577d640..916ceac3ada2 100644 --- a/drivers/net/ethernet/engleder/tsnep_hw.h +++ b/drivers/net/ethernet/engleder/tsnep_hw.h @@ -43,6 +43,10 @@ #define ECM_RESET_CHANNEL 0x00000100 #define ECM_RESET_TXRX 0x00010000 +/* counter */ +#define ECM_COUNTER_LOW 0x0028 +#define ECM_COUNTER_HIGH 0x002C + /* control and status */ #define ECM_STATUS 0x0080 #define ECM_LINK_MODE_OFF 0x01000000 @@ -190,7 +194,8 @@ struct tsnep_tx_desc { /* tsnep TX descriptor writeback */ struct tsnep_tx_desc_wb { __le32 properties; - __le32 reserved1[3]; + __le32 reserved1; + __le64 counter; __le64 timestamp; __le32 dma_delay; __le32 reserved2; @@ -221,7 +226,7 @@ struct tsnep_rx_desc_wb { /* tsnep RX inline meta */ struct tsnep_rx_inline { - __le64 reserved; + __le64 counter; __le64 timestamp; }; diff --git a/drivers/net/ethernet/engleder/tsnep_main.c b/drivers/net/ethernet/engleder/tsnep_main.c index 904f3304727e..4aa3d04da2e4 100644 --- a/drivers/net/ethernet/engleder/tsnep_main.c +++ b/drivers/net/ethernet/engleder/tsnep_main.c @@ -472,9 +472,12 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) struct skb_shared_hwtstamps hwtstamps; u64 timestamp = __le64_to_cpu(entry->desc_wb->timestamp); + u64 counter = + __le64_to_cpu(entry->desc_wb->counter); memset(&hwtstamps, 0, sizeof(hwtstamps)); hwtstamps.hwtstamp = ns_to_ktime(timestamp); + hwtstamps.hwfreeruntstamp = ns_to_ktime(counter); skb_tstamp_tx(entry->skb, &hwtstamps); } @@ -706,9 +709,12 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi, (struct tsnep_rx_inline *)skb->data; u64 timestamp = __le64_to_cpu(rx_inline->timestamp); + u64 counter = + __le64_to_cpu(rx_inline->counter); memset(hwtstamps, 0, sizeof(*hwtstamps)); hwtstamps->hwtstamp = ns_to_ktime(timestamp); + hwtstamps->hwfreeruntstamp = ns_to_ktime(counter); } skb_pull(skb, TSNEP_RX_INLINE_METADATA_SIZE); skb->protocol = eth_type_trans(skb, diff --git a/drivers/net/ethernet/engleder/tsnep_ptp.c b/drivers/net/ethernet/engleder/tsnep_ptp.c index eaad453d487e..5f0b807fd86c 100644 --- a/drivers/net/ethernet/engleder/tsnep_ptp.c +++ b/drivers/net/ethernet/engleder/tsnep_ptp.c @@ -175,6 +175,33 @@ static int tsnep_ptp_settime64(struct ptp_clock_info *ptp, return 0; } +static int tsnep_ptp_getfreeruntimex64(struct ptp_clock_info *ptp, + struct timespec64 *ts, + struct ptp_system_timestamp *sts) +{ + struct tsnep_adapter *adapter = container_of(ptp, struct tsnep_adapter, + ptp_clock_info); + u32 high_before; + u32 low; + u32 high; + u64 counter; + + /* read high dword twice to detect overrun */ + high = ioread32(adapter->addr + ECM_COUNTER_HIGH); + do { + ptp_read_system_prets(sts); + low = ioread32(adapter->addr + ECM_COUNTER_LOW); + ptp_read_system_postts(sts); + high_before = high; + high = ioread32(adapter->addr + ECM_COUNTER_HIGH); + } while (high != high_before); + counter = (((u64)high) << 32) | ((u64)low); + + *ts = ns_to_timespec64(counter); + + return 0; +} + int tsnep_ptp_init(struct tsnep_adapter *adapter) { int retval = 0; @@ -192,6 +219,7 @@ int tsnep_ptp_init(struct tsnep_adapter *adapter) adapter->ptp_clock_info.adjtime = tsnep_ptp_adjtime; adapter->ptp_clock_info.gettimex64 = tsnep_ptp_gettimex64; adapter->ptp_clock_info.settime64 = tsnep_ptp_settime64; + adapter->ptp_clock_info.getfreeruntimex64 = tsnep_ptp_getfreeruntimex64; spin_lock_init(&adapter->ptp_lock);