Skip to content

Commit d6228b7

Browse files
temapdavem330
authored andcommitted
net: stmmac: implement the SIOCGHWTSTAMP ioctl
This patch adds support for the SIOCGHWTSTAMP ioctl which enables user processes to read the current hwtstamp_config settings non-destructively. Signed-off-by: Artem Panfilov <panfilov.artyom@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bbc318f commit d6228b7

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/pci.h>
2929
#include "common.h"
3030
#include <linux/ptp_clock_kernel.h>
31+
#include <linux/net_tstamp.h>
3132
#include <linux/reset.h>
3233

3334
struct stmmac_resources {
@@ -174,6 +175,7 @@ struct stmmac_priv {
174175
unsigned int mode;
175176
unsigned int chain_mode;
176177
int extend_desc;
178+
struct hwtstamp_config tstamp_config;
177179
struct ptp_clock *ptp_clock;
178180
struct ptp_clock_info ptp_clock_ops;
179181
unsigned int default_addend;

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p,
534534
}
535535

536536
/**
537-
* stmmac_hwtstamp_ioctl - control hardware timestamping.
537+
* stmmac_hwtstamp_set - control hardware timestamping.
538538
* @dev: device pointer.
539539
* @ifr: An IOCTL specific structure, that can contain a pointer to
540540
* a proprietary structure used to pass information to the driver.
@@ -544,7 +544,7 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p,
544544
* Return Value:
545545
* 0 on success and an appropriate -ve integer on failure.
546546
*/
547-
static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
547+
static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
548548
{
549549
struct stmmac_priv *priv = netdev_priv(dev);
550550
struct hwtstamp_config config;
@@ -573,7 +573,7 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
573573
}
574574

575575
if (copy_from_user(&config, ifr->ifr_data,
576-
sizeof(struct hwtstamp_config)))
576+
sizeof(config)))
577577
return -EFAULT;
578578

579579
netdev_dbg(priv->dev, "%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
@@ -765,8 +765,31 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
765765
(u32)now.tv_sec, now.tv_nsec);
766766
}
767767

768+
memcpy(&priv->tstamp_config, &config, sizeof(config));
769+
768770
return copy_to_user(ifr->ifr_data, &config,
769-
sizeof(struct hwtstamp_config)) ? -EFAULT : 0;
771+
sizeof(config)) ? -EFAULT : 0;
772+
}
773+
774+
/**
775+
* stmmac_hwtstamp_get - read hardware timestamping.
776+
* @dev: device pointer.
777+
* @ifr: An IOCTL specific structure, that can contain a pointer to
778+
* a proprietary structure used to pass information to the driver.
779+
* Description:
780+
* This function obtain the current hardware timestamping settings
781+
as requested.
782+
*/
783+
static int stmmac_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
784+
{
785+
struct stmmac_priv *priv = netdev_priv(dev);
786+
struct hwtstamp_config *config = &priv->tstamp_config;
787+
788+
if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
789+
return -EOPNOTSUPP;
790+
791+
return copy_to_user(ifr->ifr_data, config,
792+
sizeof(*config)) ? -EFAULT : 0;
770793
}
771794

772795
/**
@@ -3767,7 +3790,10 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37673790
ret = phy_mii_ioctl(dev->phydev, rq, cmd);
37683791
break;
37693792
case SIOCSHWTSTAMP:
3770-
ret = stmmac_hwtstamp_ioctl(dev, rq);
3793+
ret = stmmac_hwtstamp_set(dev, rq);
3794+
break;
3795+
case SIOCGHWTSTAMP:
3796+
ret = stmmac_hwtstamp_get(dev, rq);
37713797
break;
37723798
default:
37733799
break;

0 commit comments

Comments
 (0)