From: Vladimir Oltean <olteanv@gmail.com>
To: Arun Ramadoss <arun.ramadoss@microchip.com>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
woojung.huh@microchip.com, UNGLinuxDriver@microchip.com,
andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, linux@armlinux.org.uk,
Tristram.Ha@microchip.com, richardcochran@gmail.com
Subject: Re: [RFC Patch net-next v2 3/8] net: dsa: microchip: Initial hardware time stamping support
Date: Tue, 22 Nov 2022 01:13:14 +0200 [thread overview]
Message-ID: <20221121231314.kabhej6ae6bl3qtj@skbuf> (raw)
In-Reply-To: <20221121154150.9573-4-arun.ramadoss@microchip.com>
On Mon, Nov 21, 2022 at 09:11:45PM +0530, Arun Ramadoss wrote:
> +static int ksz_ptp_enable_mode(struct ksz_device *dev, bool enable)
> +{
> + u16 data = 0;
> +
> + /* Enable PTP mode */
> + if (enable)
> + data = PTP_ENABLE;
> +
> + return ksz_rmw16(dev, REG_PTP_MSG_CONF1, PTP_ENABLE, data);
> +}
> +
> +static int ksz_set_hwtstamp_config(struct ksz_device *dev, int port,
> + struct hwtstamp_config *config)
> +{
> + struct ksz_tagger_data *tagger_data = ksz_tagger_data(dev->ds);
> + struct ksz_port *prt = &dev->ports[port];
> + bool rx_on;
> +
> + /* reserved for future extensions */
> + if (config->flags)
> + return -EINVAL;
> +
> + switch (config->tx_type) {
> + case HWTSTAMP_TX_OFF:
> + case HWTSTAMP_TX_ONESTEP_P2P:
> + prt->hwts_tx_en = config->tx_type;
> + break;
> + case HWTSTAMP_TX_ON:
> + if (!is_lan937x(dev))
> + return -ERANGE;
> +
> + prt->hwts_tx_en = config->tx_type;
> + break;
> + default:
> + return -ERANGE;
> + }
> +
> + switch (config->rx_filter) {
> + case HWTSTAMP_FILTER_NONE:
> + rx_on = false;
> + break;
> + default:
> + rx_on = true;
> + break;
> + }
> +
> + if (rx_on != tagger_data->hwtstamp_get_state(dev->ds)) {
> + int ret;
> +
> + tagger_data->hwtstamp_set_state(dev->ds, false);
> +
> + ret = ksz_ptp_enable_mode(dev, rx_on);
> + if (ret)
> + return ret;
> +
> + if (rx_on)
> + tagger_data->hwtstamp_set_state(dev->ds, true);
> + }
What's your excuse which such a horrible code pattern? What will happen
so bad with the packet if it's flagged with a TX timestamp request in
KSZ_SKB_CB(skb) at the same time as REG_PTP_MSG_CONF1 is written to?
Also, doesn't dev->ports[port].hwts_tx_en serve as a guard against
flagging packets for TX timestamps when you shouldn't?
> +
> + return 0;
> +}
> diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
> index 37db5156f9a3..6a909a300c13 100644
> --- a/net/dsa/tag_ksz.c
> +++ b/net/dsa/tag_ksz.c
> @@ -4,6 +4,7 @@
> * Copyright (c) 2017 Microchip Technology
> */
>
> +#include <linux/dsa/ksz_common.h>
> #include <linux/etherdevice.h>
> #include <linux/list.h>
> #include <net/dsa.h>
> @@ -18,6 +19,62 @@
> #define KSZ_EGRESS_TAG_LEN 1
> #define KSZ_INGRESS_TAG_LEN 1
>
> +#define KSZ_HWTS_EN 0
> +
> +struct ksz_tagger_private {
> + struct ksz_tagger_data data; /* Must be first */
> + unsigned long state;
> +};
> +
> +static struct ksz_tagger_private *
> +ksz_tagger_private(struct dsa_switch *ds)
> +{
> + return ds->tagger_data;
> +}
> +
> +static bool ksz_hwtstamp_get_state(struct dsa_switch *ds)
> +{
> + struct ksz_tagger_private *priv = ksz_tagger_private(ds);
> +
> + return test_bit(KSZ_HWTS_EN, &priv->state);
> +}
> +
> +static void ksz_hwtstamp_set_state(struct dsa_switch *ds, bool on)
> +{
> + struct ksz_tagger_private *priv = ksz_tagger_private(ds);
> +
> + if (on)
> + set_bit(KSZ_HWTS_EN, &priv->state);
> + else
> + clear_bit(KSZ_HWTS_EN, &priv->state);
> +}
next prev parent reply other threads:[~2022-11-21 23:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 15:41 [RFC Patch net-next v2 0/8] net: dsa: microchip: add PTP support for KSZ9x and LAN937x Arun Ramadoss
2022-11-21 15:41 ` [RFC Patch net-next v2 1/8] net: ptp: add helper for one-step P2P clocks Arun Ramadoss
2022-11-22 14:34 ` Richard Cochran
2022-11-23 7:10 ` Arun.Ramadoss
2022-11-24 14:52 ` Richard Cochran
2022-11-21 15:41 ` [RFC Patch net-next v2 2/8] net: dsa: microchip: adding the posix clock support Arun Ramadoss
2022-11-21 21:33 ` Vladimir Oltean
2022-11-21 22:01 ` Vladimir Oltean
2022-11-21 15:41 ` [RFC Patch net-next v2 3/8] net: dsa: microchip: Initial hardware time stamping support Arun Ramadoss
2022-11-21 23:13 ` Vladimir Oltean [this message]
2022-11-23 13:57 ` Arun.Ramadoss
2022-11-24 10:22 ` Vladimir Oltean
2022-11-24 10:52 ` Arun.Ramadoss
2022-11-24 14:14 ` Vladimir Oltean
2022-11-25 7:06 ` Arun.Ramadoss
2022-11-25 21:40 ` Vladimir Oltean
2022-11-21 15:41 ` [RFC Patch net-next v2 4/8] net: dsa: microchip: Manipulating absolute time using ptp hw clock Arun Ramadoss
2022-11-21 15:41 ` [RFC Patch net-next v2 5/8] net: dsa: microchip: enable the ptp interrupt for timestamping Arun Ramadoss
2022-11-21 15:41 ` [RFC Patch net-next v2 6/8] net: dsa: microchip: Adding the ptp packet reception logic Arun Ramadoss
2022-11-21 15:41 ` [RFC Patch net-next v2 7/8] net: dsa: microchip: add the transmission tstamp logic Arun Ramadoss
2022-11-21 22:51 ` Vladimir Oltean
2022-11-23 8:49 ` Arun.Ramadoss
2022-11-21 15:41 ` [RFC Patch net-next v2 8/8] net: dsa: microchip: ptp: add periodic output signal Arun Ramadoss
2022-11-22 14:36 ` Richard Cochran
2022-11-22 14:38 ` Richard Cochran
2022-11-21 21:17 ` [RFC Patch net-next v2 0/8] net: dsa: microchip: add PTP support for KSZ9x and LAN937x Vladimir Oltean
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221121231314.kabhej6ae6bl3qtj@skbuf \
--to=olteanv@gmail.com \
--cc=Tristram.Ha@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=arun.ramadoss@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=vivien.didelot@gmail.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).