staging: fsl-dpaa2/eth: Add support for hardware timestamping
PATCH v2 1/3 staging: fsl-dpaa2/eth: Add support for hardware timestamping
From: Ioana Radulescu <[email protected]>
Hardware timestamping is supported both on Rx and Tx paths. On Rx, timestamping is enabled for all frames. On Tx, we only instruct the hardware to timestamp the frames marked accordingly by the stack.
---
Changes for v2:
- Addressed sparse issues.
- Used tx_tstamp/rx_tstamp instead of ts_tx_en/ts_rx_en.
- Used DPAA2_PTP_CLK_PERIOD_NS instead.
--- drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c | 111 +++++++++++++++++++++++- drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h | 48 ++++++++++- 2 files changed, 153 insertions(+), 6 deletions(-)
drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c +107 -4
@@ -38,8 +38,11 @@#include <linux/msi.h> #include <linux/kthread.h> #include <linux/iommu.h> - +#include <linux/net_tstamp.h> #include <linux/fsl/mc.h> + +#include <net/sock.h> +#include "dpaa2-eth.h" /* CREATE_TRACE_POINTS only needs to be defined once. Other dpa files
@@ -275,6 +278,18 @@ static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv,prefetch (skb->data); +/* Get the timestamp value */ +if (priv->rx_tstamp) { +struct skb_shared_hwtstamps *shhwtstamps =skb_hwtstamps (skb); +__le64 *ts =dpaa2_get_ts (vaddr, false); +u64 ns; + +memset (shhwtstamps,0 ,sizeof (*shhwtstamps)); + + ns =DPAA2_PTP_CLK_PERIOD_NS *le64_to_cpup (ts); + shhwtstamps->hwtstamp =ns_to_ktime (ns); + } +/* Check if we need to validate the L4 csum */ if (likely (dpaa2_fd_get_frc (fd) &DPAA2_FD_FRC_FASV )) { status =le32_to_cpu (fas->status);
@@ -334,6 +349,28 @@ static int consume_frames(struct dpaa2_eth_channel *ch)return cleaned; } +/* Configure the egress frame annotation for timestamp update */ +static void enable_tx_tstamp (struct dpaa2_fd *fd,void *buf_start) +{ +struct dpaa2_faead *faead; +u32 ctrl, frc; + +/* Mark the egress frame annotation area as valid */ + frc =dpaa2_fd_get_frc (fd); +dpaa2_fd_set_frc (fd, frc |DPAA2_FD_FRC_FAEADV ); + +/* Set hardware annotation size */ + ctrl =dpaa2_fd_get_ctrl (fd); +dpaa2_fd_set_ctrl (fd, ctrl |DPAA2_FD_CTRL_ASAL ); + +/* enable UPD (update prepanded data) bit in FAEAD field of +* hardware frame annotation area +*/ + ctrl =DPAA2_FAEAD_A2V |DPAA2_FAEAD_UPDV |DPAA2_FAEAD_UPD ; + faead =dpaa2_get_faead (buf_start, true); + faead->ctrl =cpu_to_le32 (ctrl); +} +/* Create a frame descriptor based on a fragmented skb */ static int build_sg_fd(struct dpaa2_eth_priv *priv, struct sk_buff *skb,
@@ -420,6 +457,9 @@ static int build_sg_fd(struct dpaa2_eth_priv *priv,dpaa2_fd_set_len (fd, skb->len);dpaa2_fd_set_ctrl (fd,DPAA2_FD_CTRL_PTA |DPAA2_FD_CTRL_PTV1 ); +if (priv->tx_tstamp &&skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ) +enable_tx_tstamp (fd, sgt_buf); +return 0 ; dma_map_single_failed:
@@ -470,6 +510,9 @@ static int build_single_fd(struct dpaa2_eth_priv *priv,dpaa2_fd_set_format (fd, dpaa2_fd_single);dpaa2_fd_set_ctrl (fd,DPAA2_FD_CTRL_PTA |DPAA2_FD_CTRL_PTV1 ); +if (priv->tx_tstamp &&skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ) +enable_tx_tstamp (fd, buffer_start); +return 0 ; }
@@ -520,6 +563,19 @@ static void free_tx_fd(const struct dpaa2_eth_priv *priv,return ; } +/* Get the timestamp value */ +if (priv->tx_tstamp &&skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ) { +struct skb_shared_hwtstamps shhwtstamps; +__le64 *ts =dpaa2_get_ts (skbh, true); +u64 ns; + +memset (&shhwtstamps,0 ,sizeof (shhwtstamps)); + + ns =DPAA2_PTP_CLK_PERIOD_NS *le64_to_cpup (ts); + shhwtstamps.hwtstamp =ns_to_ktime (ns); +skb_tstamp_tx (skb, &shhwtstamps); + } +/* Free SGT buffer allocated on tx */ if (fd_format != dpaa2_fd_single)skb_free_frag (skbh);
@@ -552,6 +608,10 @@ static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, struct net_device *net_dev) goto err_alloc_headroom; } percpu_extras->tx_reallocs++; + +if (skb->sk) +skb_set_owner_w (ns, skb->sk); +dev_kfree_skb (skb); skb = ns; }
@@ -1365,6 +1425,45 @@ static int dpaa2_eth_set_features(struct net_device *net_dev,return 0 ; } +static int dpaa2_eth_ts_ioctl (struct net_device *dev,struct ifreq *rq,int cmd) +{ +struct dpaa2_eth_priv *priv =netdev_priv (dev); +struct hwtstamp_config config; + +if (copy_from_user (&config, rq->ifr_data,sizeof (config))) +return -EFAULT ; + +switch (config.tx_type) { +case HWTSTAMP_TX_OFF : + priv->tx_tstamp = false; +break ; +case HWTSTAMP_TX_ON : + priv->tx_tstamp = true; +break ; +default : +return -ERANGE ; + } + +if (config.rx_filter ==HWTSTAMP_FILTER_NONE ) { + priv->rx_tstamp = false; + }else { + priv->rx_tstamp = true; +/* TS is set for all frame types, not only those requested */ + config.rx_filter =HWTSTAMP_FILTER_ALL ; + } + +return copy_to_user (rq->ifr_data, &config,sizeof (config)) ? + -EFAULT :0 ; +} + +static int dpaa2_eth_ioctl (struct net_device *dev,struct ifreq *rq,int cmd) +{ +if (cmd ==SIOCSHWTSTAMP ) +return dpaa2_eth_ts_ioctl (dev, rq, cmd); + +return -EINVAL ; +} +static const struct net_device_ops dpaa2_eth_ops = { .ndo_open = dpaa2_eth_open, .ndo_start_xmit = dpaa2_eth_tx,
@@ -1375,6 +1474,7 @@ static int dpaa2_eth_set_features(struct net_device *net_dev, .ndo_change_mtu = dpaa2_eth_change_mtu, .ndo_set_rx_mode = dpaa2_eth_set_rx_mode, .ndo_set_features = dpaa2_eth_set_features, + .ndo_do_ioctl = dpaa2_eth_ioctl, };static void cdan_cb (struct dpaa2_io_notification_ctx *ctx)
@@ -1770,7 +1870,9 @@ static int set_buffer_layout(struct dpaa2_eth_priv *priv)/* tx buffer */ buf_layout.private_data_size =DPAA2_ETH_SWA_SIZE ; - buf_layout.options =DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE ; + buf_layout.pass_timestamp = true; + buf_layout.options =DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE | +DPNI_BUF_LAYOUT_OPT_TIMESTAMP ; err =dpni_set_buffer_layout (priv->mc_io,0 , priv->mc_token,DPNI_QUEUE_TX , &buf_layout);if (err) {
@@ -1779,7 +1881,7 @@ static int set_buffer_layout(struct dpaa2_eth_priv *priv) }/* tx-confirm buffer */ - buf_layout.options =0 ; + buf_layout.options =DPNI_BUF_LAYOUT_OPT_TIMESTAMP ; err =dpni_set_buffer_layout (priv->mc_io,0 , priv->mc_token,DPNI_QUEUE_TX_CONFIRM , &buf_layout);if (err) {
@@ -1810,7 +1912,8 @@ static int set_buffer_layout(struct dpaa2_eth_priv *priv) buf_layout.options =DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |DPNI_BUF_LAYOUT_OPT_DATA_ALIGN | -DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM ; +DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM | +DPNI_BUF_LAYOUT_OPT_TIMESTAMP ; err =dpni_set_buffer_layout (priv->mc_io,0 , priv->mc_token,DPNI_QUEUE_RX , &buf_layout);if (err) {
drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h +46 -2
88 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 2/3 staging: fsl-dpaa2/eth: add the get_ts_info interface for ethtool
Since hardware timestmaping has been supported in driver, this patch is to add the get_ts_info interface for ethtool to show timestamping capability.
---
Changes for v2:
- Added this patch.
--- drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h | 1 + drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-)
drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h +1 -0
@@ -390,6 +390,7 @@ struct dpaa2_eth_priv {extern const struct ethtool_ops dpaa2_ethtool_ops;extern const char dpaa2_eth_drv_version[]; +extern int dpaa2_phc_index;static inline int dpaa2_eth_cmp_dpni_ver (struct dpaa2_eth_priv *priv,u16 ver_major,u16 ver_minor)
drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c +23 -0
@@ -30,6 +30,8 @@* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <linux/net_tstamp.h> +#include "dpni.h" /* DPNI_LINK_OPT_* */ #include "dpaa2-eth.h"
@@ -274,6 +276,26 @@ static int dpaa2_eth_get_rxnfc(struct net_device *net_dev,return 0 ; } +int dpaa2_phc_index =-1 ; +EXPORT_SYMBOL (dpaa2_phc_index); + +static int dpaa2_eth_get_ts_info (struct net_device *dev, +struct ethtool_ts_info *info) +{ + info->so_timestamping =SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->phc_index = dpaa2_phc_index; + + info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | + (1 <<HWTSTAMP_TX_ON ); + + info->rx_filters = (1 <<HWTSTAMP_FILTER_NONE ) | + (1 <<HWTSTAMP_FILTER_ALL ); +return 0 ; +} +const struct ethtool_ops dpaa2_ethtool_ops = { .get_drvinfo = dpaa2_eth_get_drvinfo, .get_link = ethtool_op_get_link,
@@ -283,4 +305,5 @@ static int dpaa2_eth_get_rxnfc(struct net_device *net_dev, .get_ethtool_stats = dpaa2_eth_get_ethtool_stats, .get_strings = dpaa2_eth_get_strings, .get_rxnfc = dpaa2_eth_get_rxnfc, + .get_ts_info = dpaa2_eth_get_ts_info, };
Signature · 1 line
1.7.1
PATCH v2 3/3 staging: fsl-dpaa2/rtc: support phc_index of ethtool_ts_info
In reply to Yangbo LuThis patch is to support phc_index of ethtool_ts_info. Also make the rtc drvier depend on FSL_DPAA2_ETH because this driver is only useful when PTP programs are getting hardware time stamps on the PTP Ethernet packets using the SO_TIMESTAMPING API.
---
Changes for v2:
- Added this patch.
--- drivers/staging/fsl-dpaa2/Kconfig | 2 +- drivers/staging/fsl-dpaa2/rtc/rtc.c | 6 ++---- drivers/staging/fsl-dpaa2/rtc/rtc.h | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 drivers/staging/fsl-dpaa2/rtc/rtc.h
drivers/staging/fsl-dpaa2/Kconfig +1 -1
@@ -27,7 +27,7 @@ config FSL_DPAA2_ETHSW config FSL_DPAA2_PTP_CLOCK tristate "Freescale DPAA2 PTP Clock" - depends on FSL_DPAA2 + depends on FSL_DPAA2_ETH select PTP_1588_CLOCK help This driver adds support for using the DPAA2 1588 timer module
drivers/staging/fsl-dpaa2/rtc/rtc.c +2 -4
@@ -9,14 +9,12 @@#include <linux/ptp_clock_kernel.h> #include <linux/fsl/mc.h> -#include "dprtc.h" -#include "dprtc-cmd.h" +#include "rtc.h" struct ptp_dpaa2_priv {struct fsl_mc_device *rtc_mc_dev;struct ptp_clock *clock;struct ptp_clock_info caps; -int phc_index;u32 freq_comp; };
@@ -173,7 +171,7 @@ static int rtc_probe(struct fsl_mc_device *mc_dev) goto err_close; } - ptp_dpaa2->phc_index =ptp_clock_index (ptp_dpaa2->clock); + dpaa2_phc_index =ptp_clock_index (ptp_dpaa2->clock);dev_set_drvdata (dev, ptp_dpaa2);
drivers/staging/fsl-dpaa2/rtc/rtc.h new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 NXP +*/ + +#ifndef __RTC_H +#define __RTC_H + +#include "dprtc.h" +#include "dprtc-cmd.h" + +extern int dpaa2_phc_index; + +#endif
Signature · 1 line
1.7.1
Greg Kroah-Hartman
maintainerQuoted 7 lines · Yangbo Lu
From: Ioana Radulescu <[email protected]>
Hardware timestamping is supported both on Rx and Tx paths. On Rx, timestamping is enabled for all frames. On Tx, we only instruct the hardware to timestamp the frames marked accordingly by the stack.
Quoted 7 lines
Signed-off-by Ioana Radulescu <[email protected]>Signed-off-by Yangbo Lu <[email protected]>---
Changes for v2:
- Addressed sparse issues.
- Used tx_tstamp/rx_tstamp instead of ts_tx_en/ts_rx_en.
- UsedDPAA2_PTP_CLK_PERIOD_NSinstead.
Why are you adding new features to this driver instead of working on getting it out of the staging directory? What is remaining left to do to get it moved out?
thanks,
greg k-h
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel