Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp614155pxh; Tue, 9 Nov 2021 16:12:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxu3Lvfv3w6I+OzJzZgrPrOpsJY1+apNTDCb2YIpWHICyEU51El2VWg0I/gNrI5DWSI04Du X-Received: by 2002:a92:cd86:: with SMTP id r6mr8235242ilb.149.1636503130766; Tue, 09 Nov 2021 16:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636503130; cv=none; d=google.com; s=arc-20160816; b=cesiFDJb3G2qIx+NaT/MY+xt/DRMAFBBRlLhkfB5EJ1AEcbTmSM2aPtWkPClFGAcOr AaIuoEAzIQ8l43b+QHcCu3CWPbH/w+M89o6nTeKZU3ci7E53gqHkkx/MXElIaomuyLFP T8lxsp42/uY5+oaBhZ22Z7SZ64RY2ksiVLxTZJVXVG8JfmeSbaWPVpi8iawsnnJ1dFDy zHvM2aWId+xVtfKjszButO0Yjq0eyx1q+alX3WlE4VSTdGDcBJ6rB4jMR2PRcgo2i8gG wwE9Ce7DcQl4L8oPeZb7QUk2AOtX1tDrx2Mvqm5fU/b4buJZa4pHhD/V5vBaPwGSAE59 4EQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=2L6rhPvItN9TtF9bTs6WdQ6t8LTnm64uAEz7E762uR4=; b=C9EyJq3EKNPZDcPG/ZspKigqkdrMnpw6TGbEIJFvkBpDhjDHTDUQThUcVgzfV74Yue a7jE62TVV9US/xWKyd5wqgJykZy5Uu7QNjsAoiHrRBwnaeGN334ZZfdRX7Zn4IT0k09h zl8spsd5eeei6wthsBnwWBxDRfIUzBhURr1nsZR8wusH3PzxjStgf8fS9Pnpo3klouvR Dg9bJ5VI2SufHOayRYWk599El1e9say6yPlPa5ImW8HD1+Ylrv30K4p3ZTVdAHBSZpTv +YumR9Q2nReHuDe3KlPILpAsNOntKM5mAGA6lufdzSJj6BLPYk0gjoadfSCz2pwKyW6G Cqug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f8GO3C4y; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g9si45319300ila.24.2021.11.09.16.11.58; Tue, 09 Nov 2021 16:12:10 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=f8GO3C4y; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241847AbhKISK1 (ORCPT + 97 others); Tue, 9 Nov 2021 13:10:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241785AbhKISKM (ORCPT ); Tue, 9 Nov 2021 13:10:12 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A028C06120B; Tue, 9 Nov 2021 10:07:26 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id o14so22378649plg.5; Tue, 09 Nov 2021 10:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=2L6rhPvItN9TtF9bTs6WdQ6t8LTnm64uAEz7E762uR4=; b=f8GO3C4yJFV0tcQCJKO62bvQvyPI/8stXnayu2hAB4hSAuvZZ3puhEUkdies7wCSeL O3VpG2DvCrAmVgT+/CwoBPymcOJyFd2kC+pRIF9jwR15SyQ2wZxlL0ucUcIqMDPY/gAy Zm44BNzWX75hLEdcDz9jGSFK8XBf1ZeX8SMuC+YO0hNsPp/ISmVIK4KwvnRlRCjL1KJq jnHzmRINu6w5t1n+xeBLXv7kMcD3PnzXExJCYfkyy16b0jSvRNL916JejXEcFuVnM09O 9cTqdES32DB7hC1XDB3lIOJWhuUAXt1c1uDbGg8tTDNji2r4lUJoJ1NBPqeNB6BFuDxb eQDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=2L6rhPvItN9TtF9bTs6WdQ6t8LTnm64uAEz7E762uR4=; b=LIUw+sHYoWCSYS6rU5tr2VoWyb4pQu+hMJvVE5gp1w5gORCpK/tHwow6lG6ohSScQb I+JGnxHOD8kgqf5Lz8SOwCWmFx8lzBRzCpMv/UNu3Q8846ZPD804ZXCl42K0RMl2f5YV AdzrE1QfBJXxcyYQ/4MVyW1K4ZoGcVN+mI3JEM/+aHm1az0z2sqVB6PhoxdjzY01XTTG F6+JPyuo1hPoTHytMY8A5SOs1YZmV8SQQA8aBIwkPMIRJm8wbnc/ij/OUTOLwvY5adFs cinv173QC/GvrrOUBfgFFnj6J27Zy+Pg2II8wKbDLgyitihcsYWWBRVanq+idcuFyt62 WC6g== X-Gm-Message-State: AOAM533cQrUyk6AAE18ZM4kV8pRrb/9fUx8kcqjHRPuObX7nhYYJtSmS nACXS27eg5i+y8bSDwJ/+lu++H13Dvo= X-Received: by 2002:a17:902:6902:b0:13f:c1cd:88f1 with SMTP id j2-20020a170902690200b0013fc1cd88f1mr8863981plk.36.1636481245760; Tue, 09 Nov 2021 10:07:25 -0800 (PST) Received: from [10.67.48.245] ([192.19.223.252]) by smtp.googlemail.com with ESMTPSA id j7sm3427169pjf.41.2021.11.09.10.07.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Nov 2021 10:07:25 -0800 (PST) Subject: Re: [PATCH v2 5/7] net: dsa: b53: Add logic for RX timestamping To: Martin Kaistra , Andrew Lunn , Vivien Didelot Cc: Richard Cochran , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , John Stultz , Thomas Gleixner , Stephen Boyd , Russell King , Marc Kleine-Budde , linux-kernel@vger.kernel.org, netdev@vger.kernel.org References: <20211109095013.27829-1-martin.kaistra@linutronix.de> <20211109095013.27829-6-martin.kaistra@linutronix.de> From: Florian Fainelli Message-ID: <9d9f3b13-051c-0c6d-e2cb-b64bbee2522f@gmail.com> Date: Tue, 9 Nov 2021 10:07:23 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211109095013.27829-6-martin.kaistra@linutronix.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/9/21 1:50 AM, Martin Kaistra wrote: > Packets received by the tagger with opcode=1 contain the 32-bit timestamp > according to the timebase register. This timestamp is saved in > BRCM_SKB_CB(skb)->meta_tstamp. b53_port_rxtstamp() takes this > and puts the full time information from the timecounter into > shwt->hwtstamp. > > Signed-off-by: Martin Kaistra > --- > drivers/net/dsa/b53/b53_common.c | 1 + > drivers/net/dsa/b53/b53_ptp.c | 28 +++++++++++++++++++++++++ > drivers/net/dsa/b53/b53_ptp.h | 10 +++++++++ > include/linux/dsa/b53.h | 30 +++++++++++++++++++++++++++ > net/dsa/tag_brcm.c | 35 ++++++++++++++++++++++++-------- > 5 files changed, 95 insertions(+), 9 deletions(-) > > diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c > index ed590efbd3bf..a9408f9cd414 100644 > --- a/drivers/net/dsa/b53/b53_common.c > +++ b/drivers/net/dsa/b53/b53_common.c > @@ -2300,6 +2300,7 @@ static const struct dsa_switch_ops b53_switch_ops = { > .port_max_mtu = b53_get_max_mtu, > .port_change_mtu = b53_change_mtu, > .get_ts_info = b53_get_ts_info, > + .port_rxtstamp = b53_port_rxtstamp, > }; > > struct b53_chip_data { > diff --git a/drivers/net/dsa/b53/b53_ptp.c b/drivers/net/dsa/b53/b53_ptp.c > index 8629c510b1a0..f8dd8d484d93 100644 > --- a/drivers/net/dsa/b53/b53_ptp.c > +++ b/drivers/net/dsa/b53/b53_ptp.c > @@ -6,6 +6,8 @@ > * Copyright (C) 2021 Linutronix GmbH > */ > > +#include > + > #include "b53_priv.h" > #include "b53_ptp.h" > > @@ -106,6 +108,32 @@ static long b53_hwtstamp_work(struct ptp_clock_info *ptp) > return B53_PTP_OVERFLOW_PERIOD; > } > > +bool b53_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb, > + unsigned int type) > +{ > + struct b53_device *dev = ds->priv; > + struct b53_port_hwtstamp *ps = &dev->ports[port].port_hwtstamp; > + struct skb_shared_hwtstamps *shwt; > + u64 ns; I had asked you to store b53_port_hwtstamp into dp->priv, any reason for not doing that? > + > + if (type != PTP_CLASS_V2_L2) > + return false; > + > + if (!test_bit(B53_HWTSTAMP_ENABLED, &ps->state)) > + return false; > + > + mutex_lock(&dev->ptp_mutex); > + ns = timecounter_cyc2time(&dev->tc, BRCM_SKB_CB(skb)->meta_tstamp); > + mutex_unlock(&dev->ptp_mutex); > + > + shwt = skb_hwtstamps(skb); > + memset(shwt, 0, sizeof(*shwt)); > + shwt->hwtstamp = ns_to_ktime(ns); > + > + return false; > +} > +EXPORT_SYMBOL(b53_port_rxtstamp); > + > int b53_ptp_init(struct b53_device *dev) > { > mutex_init(&dev->ptp_mutex); > diff --git a/drivers/net/dsa/b53/b53_ptp.h b/drivers/net/dsa/b53/b53_ptp.h > index 5cd2fd9621a2..3b3437870c55 100644 > --- a/drivers/net/dsa/b53/b53_ptp.h > +++ b/drivers/net/dsa/b53/b53_ptp.h > @@ -9,11 +9,15 @@ > > #include "b53_priv.h" > > +#define SKB_PTP_TYPE(__skb) (*(unsigned int *)((__skb)->cb)) > + > #ifdef CONFIG_B53_PTP > int b53_ptp_init(struct b53_device *dev); > void b53_ptp_exit(struct b53_device *dev); > int b53_get_ts_info(struct dsa_switch *ds, int port, > struct ethtool_ts_info *info); > +bool b53_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb, > + unsigned int type); > #else /* !CONFIG_B53_PTP */ > > static inline int b53_ptp_init(struct b53_device *dev) > @@ -31,5 +35,11 @@ static inline int b53_get_ts_info(struct dsa_switch *ds, int port, > return -EOPNOTSUPP; > } > > +static inline bool b53_port_rxtstamp(struct dsa_switch *ds, int port, > + struct sk_buff *skb, unsigned int type) > +{ > + return false; > +} > + > #endif > #endif > diff --git a/include/linux/dsa/b53.h b/include/linux/dsa/b53.h > index 85aa6d9dc53d..542e5e3040d6 100644 > --- a/include/linux/dsa/b53.h > +++ b/include/linux/dsa/b53.h > @@ -46,9 +46,32 @@ struct b53_io_ops { > struct phylink_link_state *state); > }; > > +/* state flags for b53_port_hwtstamp::state */ > +enum { > + B53_HWTSTAMP_ENABLED, > + B53_HWTSTAMP_TX_IN_PROGRESS, > +}; > + > +struct b53_port_hwtstamp { > + /* Port index */ > + int port_id; unsigned int; > + > + /* Timestamping state */ > + unsigned long state; > + > + /* Resources for transmit timestamping */ > + unsigned long tx_tstamp_start; > + struct sk_buff *tx_skb; > + > + /* Current timestamp configuration */ > + struct hwtstamp_config tstamp_config; > +}; > + > struct b53_port { > u16 vlan_ctl_mask; > struct ethtool_eee eee; > + /* Per-port timestamping resources */ > + struct b53_port_hwtstamp port_hwtstamp; > }; > > struct b53_vlan { > @@ -112,3 +135,10 @@ struct b53_device { > #define B53_PTP_OVERFLOW_PERIOD (HZ / 2) > struct delayed_work overflow_work; > }; > + > +struct brcm_skb_cb { > + struct sk_buff *clone; > + u32 meta_tstamp; > +}; > + > +#define BRCM_SKB_CB(skb) ((struct brcm_skb_cb *)(skb)->cb) > diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c > index 96dbb8ee2fee..d611c1073deb 100644 > --- a/net/dsa/tag_brcm.c > +++ b/net/dsa/tag_brcm.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > > #include "dsa_priv.h" > > @@ -31,7 +32,10 @@ > /* 6th byte in the tag */ > #define BRCM_LEG_PORT_ID (0xf) > > -/* Newer Broadcom tag (4 bytes) */ > +/* Newer Broadcom tag (4 bytes) > + * For egress, when opcode = 0001, additional 4 bytes are used for > + * the time stamp. > + */ > #define BRCM_TAG_LEN 4 > > /* Tag is constructed and desconstructed using byte by byte access > @@ -136,19 +140,29 @@ static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb, > */ > static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb, > struct net_device *dev, > - unsigned int offset) > + unsigned int offset, > + int *tag_len) unsigned int tag_len. -- Florian