public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
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,
	ceggers@arri.de, jacob.e.keller@intel.com
Subject: Re: [Patch net-next v6 02/13] net: dsa: microchip: ptp: Initial hardware time stamping support
Date: Tue, 3 Jan 2023 18:35:57 +0200	[thread overview]
Message-ID: <20230103163557.ggwdy3ung6bmtbwd@skbuf> (raw)
In-Reply-To: <20230102050459.31023-3-arun.ramadoss@microchip.com>

On Mon, Jan 02, 2023 at 10:34:48AM +0530, Arun Ramadoss wrote:
> From: Christian Eggers <ceggers@arri.de>
> 
> This patch adds the routine for get_ts_info, hwstamp_get, set. This enables
> the PTP support towards userspace applications such as linuxptp.
> 
> Signed-off-by: Christian Eggers <ceggers@arri.de>
> Co-developed-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---
> v1 -> v2
> - Declared the ksz_hwtstamp_get/set to NULL as macro if ptp is not
> enabled
> - Removed mutex lock in hwtstamp_set()
> 
> RFC v2 -> Patch v1
> - moved tagger set and get function to separate patch
> - Removed unnecessary comments
> ---
>  drivers/net/dsa/microchip/ksz_common.c |   3 +
>  drivers/net/dsa/microchip/ksz_common.h |   3 +
>  drivers/net/dsa/microchip/ksz_ptp.c    | 101 +++++++++++++++++++++++++
>  drivers/net/dsa/microchip/ksz_ptp.h    |  11 +++
>  4 files changed, 118 insertions(+)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index 3e2ebadeade9..1819f75eb007 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -2977,6 +2977,9 @@ static const struct dsa_switch_ops ksz_switch_ops = {
>  	.get_pause_stats	= ksz_get_pause_stats,
>  	.port_change_mtu	= ksz_change_mtu,
>  	.port_max_mtu		= ksz_max_mtu,
> +	.get_ts_info            = ksz_get_ts_info,
> +	.port_hwtstamp_get      = ksz_hwtstamp_get,
> +	.port_hwtstamp_set      = ksz_hwtstamp_set,

Most of ksz_switch_ops are aligned using tabs, you are introducing these
using spaces.

>  };
>  
>  struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
> diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
> index 23ed7fa72a3c..a5ce7ec30ba2 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -102,6 +102,9 @@ struct ksz_port {
>  	struct ksz_device *ksz_dev;
>  	struct ksz_irq pirq;
>  	u8 num;
> +#if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP)
> +	struct hwtstamp_config tstamp_config;
> +#endif
>  };
>  
>  struct ksz_device {
> diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c
> index fb1efb60ef71..280200b37012 100644
> --- a/drivers/net/dsa/microchip/ksz_ptp.c
> +++ b/drivers/net/dsa/microchip/ksz_ptp.c
> @@ -24,6 +24,107 @@
>  #define KSZ_PTP_INC_NS 40ULL  /* HW clock is incremented every 40 ns (by 40) */
>  #define KSZ_PTP_SUBNS_BITS 32
>  
> +/* The function is return back the capability of timestamping feature when
> + * requested through ethtool -T <interface> utility
> + */
> +int ksz_get_ts_info(struct dsa_switch *ds, int port, struct ethtool_ts_info *ts)
> +{
> +	struct ksz_device *dev	= ds->priv;

There is a tab here between *dev and = which is probably unintended.

> +	struct ksz_ptp_data *ptp_data;
> +
> +	ptp_data = &dev->ptp_data;
> +
> +	if (!ptp_data->clock)
> +		return -ENODEV;
> +
> +	ts->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
> +			      SOF_TIMESTAMPING_RX_HARDWARE |
> +			      SOF_TIMESTAMPING_RAW_HARDWARE;
> +
> +	ts->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ONESTEP_P2P);
> +
> +	ts->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
> +			 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
> +			 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
> +			 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
> +
> +	ts->phc_index = ptp_clock_index(ptp_data->clock);
> +
> +	return 0;
> +}
> +
> +int ksz_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	struct hwtstamp_config *config;
> +	struct ksz_port *prt;
> +
> +	prt = &dev->ports[port];
> +	config = &prt->tstamp_config;
> +
> +	return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ?
> +		-EFAULT : 0;
> +}
> +
> +static int ksz_set_hwtstamp_config(struct ksz_device *dev,
> +				   struct hwtstamp_config *config)
> +{
> +	if (config->flags)
> +		return -EINVAL;
> +
> +	switch (config->tx_type) {
> +	case HWTSTAMP_TX_OFF:
> +	case HWTSTAMP_TX_ONESTEP_P2P:
> +		break;
> +	default:
> +		return -ERANGE;
> +	}
> +
> +	switch (config->rx_filter) {
> +	case HWTSTAMP_FILTER_NONE:
> +		break;
> +	case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
> +	case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
> +		config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
> +		break;
> +	case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
> +	case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
> +		config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
> +		break;
> +	case HWTSTAMP_FILTER_PTP_V2_EVENT:
> +	case HWTSTAMP_FILTER_PTP_V2_SYNC:
> +		config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
> +		break;
> +	default:
> +		config->rx_filter = HWTSTAMP_FILTER_NONE;
> +		return -ERANGE;
> +	}
> +
> +	return 0;
> +}
> +
> +int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	struct hwtstamp_config config;
> +	struct ksz_port *prt;
> +	int ret;
> +
> +	prt = &dev->ports[port];
> +
> +	ret = copy_from_user(&config, ifr->ifr_data, sizeof(config));
> +	if (ret)
> +		return ret;
> +
> +	ret = ksz_set_hwtstamp_config(dev, &config);
> +	if (ret)
> +		return ret;
> +
> +	memcpy(&prt->tstamp_config, &config, sizeof(config));
> +
> +	return copy_to_user(ifr->ifr_data, &config, sizeof(config));
> +}
> +
>  static int _ksz_ptp_gettime(struct ksz_device *dev, struct timespec64 *ts)
>  {
>  	u32 nanoseconds;
> diff --git a/drivers/net/dsa/microchip/ksz_ptp.h b/drivers/net/dsa/microchip/ksz_ptp.h
> index 8930047da764..7bb3fde2dd14 100644
> --- a/drivers/net/dsa/microchip/ksz_ptp.h
> +++ b/drivers/net/dsa/microchip/ksz_ptp.h
> @@ -23,6 +23,11 @@ int ksz_ptp_clock_register(struct dsa_switch *ds);
>  
>  void ksz_ptp_clock_unregister(struct dsa_switch *ds);
>  
> +int ksz_get_ts_info(struct dsa_switch *ds, int port,
> +		    struct ethtool_ts_info *ts);
> +int ksz_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr);
> +int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr);
> +
>  #else
>  
>  struct ksz_ptp_data {
> @@ -37,6 +42,12 @@ static inline int ksz_ptp_clock_register(struct dsa_switch *ds)
>  
>  static inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { }
>  
> +#define ksz_get_ts_info NULL
> +
> +#define ksz_hwtstamp_get NULL
> +
> +#define ksz_hwtstamp_set NULL
> +
>  #endif	/* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */
>  
>  #endif
> -- 
> 2.36.1
> 

  reply	other threads:[~2023-01-03 16:36 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-02  5:04 [Patch net-next v6 00/13] net: dsa: microchip: add PTP support for KSZ9563/KSZ8563 and LAN937x Arun Ramadoss
2023-01-02  5:04 ` [Patch net-next v6 01/13] net: dsa: microchip: ptp: add the posix clock support Arun Ramadoss
2023-01-02  5:04 ` [Patch net-next v6 02/13] net: dsa: microchip: ptp: Initial hardware time stamping support Arun Ramadoss
2023-01-03 16:35   ` Vladimir Oltean [this message]
2023-01-02  5:04 ` [Patch net-next v6 03/13] net: dsa: microchip: ptp: add 4 bytes in tail tag when ptp enabled Arun Ramadoss
2023-01-02  5:04 ` [Patch net-next v6 04/13] net: dsa: microchip: ptp: manipulating absolute time using ptp hw clock Arun Ramadoss
2023-01-03 17:15   ` Vladimir Oltean
2023-01-02  5:04 ` [Patch net-next v6 05/13] net: dsa: microchip: ptp: enable interrupt for timestamping Arun Ramadoss
2023-01-02  5:04 ` [Patch net-next v6 06/13] net: ptp: add helper for one-step P2P clocks Arun Ramadoss
2023-01-02  5:04 ` [Patch net-next v6 07/13] net: dsa: microchip: ptp: add packet reception timestamping Arun Ramadoss
2023-01-02  5:04 ` [Patch net-next v6 08/13] net: dsa: microchip: ptp: add packet transmission timestamping Arun Ramadoss
2023-01-03 17:32   ` Vladimir Oltean
2023-01-02  5:04 ` [Patch net-next v6 09/13] net: dsa: microchip: ptp: move pdelay_rsp correction field to tail tag Arun Ramadoss
2023-01-03 17:40   ` Vladimir Oltean
2023-01-02  5:04 ` [Patch net-next v6 10/13] net: dsa: microchip: ptp: add periodic output signal Arun Ramadoss
2023-01-02  5:04 ` [Patch net-next v6 11/13] net: dsa: microchip: ptp: add support for perout programmable pins Arun Ramadoss
2023-01-02  5:04 ` [Patch net-next v6 12/13] net: dsa: microchip: ptp: lan937x: add 2 step timestamping Arun Ramadoss
2023-01-03 17:47   ` Vladimir Oltean
2023-01-02  5:04 ` [Patch net-next v6 13/13] net: dsa: microchip: ptp: lan937x: Enable periodic output in LED pins Arun Ramadoss

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=20230103163557.ggwdy3ung6bmtbwd@skbuf \
    --to=olteanv@gmail.com \
    --cc=Tristram.Ha@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=arun.ramadoss@microchip.com \
    --cc=ceggers@arri.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=jacob.e.keller@intel.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