Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp339705pxh; Tue, 9 Nov 2021 11:33:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4JdmTPzfS47ymw95Hk+9rP3iBWhuF1mta94d/3Y7YjgsN3ADrWI6g76JZZNLN3m66Q8nj X-Received: by 2002:a6b:fa1a:: with SMTP id p26mr6837857ioh.68.1636486404828; Tue, 09 Nov 2021 11:33:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636486404; cv=none; d=google.com; s=arc-20160816; b=aGSY1iIoPbjY7mpswLiPyYvRkiWe40Il5sOULM34Ldxwt9dN0pLyEG78c3LIQ4LK8/ /+WwxvlYXasaP47fCGukg/WhEZ6CrBztlSPjSPaexAawQ4qxecFU42hZhIODRuLlTHmx fNN63BPbiT8+OjX1+wfrBZ+mSvbsyH5/YQqIbb2nE73/y+05nao4Bld6H9cKGBxw7aPH Jf7TLHzTsXSI4VJm5RPTnOTTBCCEeHyOU8cqP4w2Tw/OzWcRTnyntPQsAxXSBHQB2NOr i3tc8+CeLqkFW1puyOOB1dpuZjx+0mTmqi46AGyKmFJK7yK1pUPzCxaTIx7ZPHjSKITJ WQ8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=2tHBO2b/mRYqYaDxmJViJfyYebaSLivzcR+D3MQPfYI=; b=JKFLSMMuEHOr5zq7aneyLnfacFGXzLbK1pHumegnb92ba2kP9w7SOVO44f0iVjsdtd AU3iRcWOiQFSEDKMmzHFrTr/SZl5qJQSDnbHir9k0G035BHeCeGxUsr12VDE0ZNDPEmU azmFeM2Uk/UQM8t7zGLhzjm6Ae7/6UQ0CJHAYX6jrj2wh/OSq3KPSp6y7XC97VEC0l7w urg/UTqAjq/I67Q+NfjRg5zmCzRTvbTV7K27Di8J9kJNkTU7dTA+imrB8hKV8sRHBZ4+ 3JDjgYKjKfH9loKlbKdlLvdNqJq4HX+Om2/drI6Ql1VedNgoP3O4HxNFbYFGuUbRwn// vikg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pIO4YMV7; dkim=neutral (no key) header.i=@linutronix.de; 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=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si28728090iow.100.2021.11.09.11.33.07; Tue, 09 Nov 2021 11:33:24 -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=@linutronix.de header.s=2020 header.b=pIO4YMV7; dkim=neutral (no key) header.i=@linutronix.de; 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=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245160AbhKIJyP (ORCPT + 99 others); Tue, 9 Nov 2021 04:54:15 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35044 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244998AbhKIJx5 (ORCPT ); Tue, 9 Nov 2021 04:53:57 -0500 From: Martin Kaistra DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1636451471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2tHBO2b/mRYqYaDxmJViJfyYebaSLivzcR+D3MQPfYI=; b=pIO4YMV7vjsKIUiMyfskBgshhCRgjBXAVW5BQsGFdKBssH/g6xEuRFeNOwSajPv/Y9lnR6 Jk6e2lEpK6hzPEZmnoujPZgvnbHHchLRmSnbzeXbupwFhvkTDiEbNfd5x2N7FRDSn/meQT f7plRlTymJstIxhoxLbUAgX06GFtBgpkGgwxGNn2ICjyDKpMalqklKzrGGCIADtSRbD/Pk 9gSDWSTXgpQhGdDmLq5RTSlaud0wA3hfBucB7dCHxwpkgZwbEPFbS2SgbPc0PZc4SYKhrz sQ0n45cIWsMjqNbQzVFf5NCRSsHYkAUgjUPc1CLb/WeO2ppEjHYJgQx+CSlAaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1636451471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2tHBO2b/mRYqYaDxmJViJfyYebaSLivzcR+D3MQPfYI=; b=ghE+auZmb+06eJQ90iZy85RhAs34/Y0gR0NjNZ+1KDjFS5bX28Lir+LjJ/OgrFa7iHvoF/ AfvfeKWw8x0icfDQ== To: Florian Fainelli , Andrew Lunn , Vivien Didelot Cc: martin.kaistra@linutronix.de, Richard Cochran , Kurt Kanzenbach , 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 Subject: [PATCH v2 7/7] net: dsa: b53: Expose PTP timestamping ioctls to userspace Date: Tue, 9 Nov 2021 10:50:09 +0100 Message-Id: <20211109095013.27829-8-martin.kaistra@linutronix.de> In-Reply-To: <20211109095013.27829-1-martin.kaistra@linutronix.de> References: <20211109095013.27829-1-martin.kaistra@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow userspace to use the PTP support. Currently only L2 is supported. Signed-off-by: Martin Kaistra Reviewed-by: Kurt Kanzenbach --- drivers/net/dsa/b53/b53_common.c | 2 + drivers/net/dsa/b53/b53_ptp.c | 90 +++++++++++++++++++++++++++++++- drivers/net/dsa/b53/b53_ptp.h | 14 +++++ 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index 56a9de89b38b..3e7e5f83cc84 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -2302,6 +2302,8 @@ static const struct dsa_switch_ops b53_switch_ops = { .get_ts_info = b53_get_ts_info, .port_rxtstamp = b53_port_rxtstamp, .port_txtstamp = b53_port_txtstamp, + .port_hwtstamp_set = b53_port_hwtstamp_set, + .port_hwtstamp_get = b53_port_hwtstamp_get, }; struct b53_chip_data { diff --git a/drivers/net/dsa/b53/b53_ptp.c b/drivers/net/dsa/b53/b53_ptp.c index 5567135ba8b9..f611ac219fb5 100644 --- a/drivers/net/dsa/b53/b53_ptp.c +++ b/drivers/net/dsa/b53/b53_ptp.c @@ -260,13 +260,99 @@ int b53_get_ts_info(struct dsa_switch *ds, int port, info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE | SOF_TIMESTAMPING_RAW_HARDWARE; - info->tx_types = BIT(HWTSTAMP_TX_OFF); - info->rx_filters = BIT(HWTSTAMP_FILTER_NONE); + info->tx_types = BIT(HWTSTAMP_TX_ON); + info->rx_filters = BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT); return 0; } EXPORT_SYMBOL(b53_get_ts_info); +static int b53_set_hwtstamp_config(struct b53_device *dev, int port, + struct hwtstamp_config *config) +{ + struct b53_port_hwtstamp *ps = &dev->ports[port].port_hwtstamp; + bool tstamp_enable = false; + + clear_bit_unlock(B53_HWTSTAMP_ENABLED, &ps->state); + + /* Reserved for future extensions */ + if (config->flags) + return -EINVAL; + + switch (config->tx_type) { + case HWTSTAMP_TX_ON: + tstamp_enable = true; + break; + case HWTSTAMP_TX_OFF: + tstamp_enable = false; + break; + default: + return -ERANGE; + } + + switch (config->rx_filter) { + case HWTSTAMP_FILTER_NONE: + tstamp_enable = false; + break; + case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: + case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: + case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: + config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; + break; + default: + return -ERANGE; + } + + if (ps->tx_skb) { + dev_kfree_skb_any(ps->tx_skb); + ps->tx_skb = NULL; + } + clear_bit(B53_HWTSTAMP_TX_IN_PROGRESS, &ps->state); + + if (tstamp_enable) + set_bit(B53_HWTSTAMP_ENABLED, &ps->state); + + return 0; +} + +int b53_port_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr) +{ + struct b53_device *dev = ds->priv; + struct b53_port_hwtstamp *ps; + struct hwtstamp_config config; + int err; + + ps = &dev->ports[port].port_hwtstamp; + + if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) + return -EFAULT; + + err = b53_set_hwtstamp_config(dev, port, &config); + if (err) + return err; + + /* Save the chosen configuration to be returned later */ + memcpy(&ps->tstamp_config, &config, sizeof(config)); + + return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : + 0; +} +EXPORT_SYMBOL(b53_port_hwtstamp_set); + +int b53_port_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr) +{ + struct b53_device *dev = ds->priv; + struct b53_port_hwtstamp *ps; + struct hwtstamp_config *config; + + ps = &dev->ports[port].port_hwtstamp; + config = &ps->tstamp_config; + + return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? -EFAULT : + 0; +} +EXPORT_SYMBOL(b53_port_hwtstamp_get); + void b53_ptp_exit(struct b53_device *dev) { if (dev->ptp_clock) diff --git a/drivers/net/dsa/b53/b53_ptp.h b/drivers/net/dsa/b53/b53_ptp.h index f888f0a2022a..3a341f752e31 100644 --- a/drivers/net/dsa/b53/b53_ptp.h +++ b/drivers/net/dsa/b53/b53_ptp.h @@ -17,6 +17,8 @@ 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); +int b53_port_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr); +int b53_port_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr); bool b53_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb, unsigned int type); void b53_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb); @@ -38,6 +40,18 @@ static inline int b53_get_ts_info(struct dsa_switch *ds, int port, return -EOPNOTSUPP; } +static inline int b53_port_hwtstamp_set(struct dsa_switch *ds, int port, + struct ifreq *ifr) +{ + return -EOPNOTSUPP; +} + +static inline int b53_port_hwtstamp_get(struct dsa_switch *ds, int port, + struct ifreq *ifr) +{ + return -EOPNOTSUPP; +} + static inline bool b53_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb, unsigned int type) { -- 2.20.1