lan743x: lan743x: Add PTP support
Subsystems (3)
Bryan Whitehead
maintainerPATCH 1/1 lan743x: lan743x: Add PTP support
PTP support includes:
Ingress, and egress timestamping.
One step timestamping available.
PTP clock support.
Periodic output support.
--- drivers/net/ethernet/microchip/Makefile | 2 +- drivers/net/ethernet/microchip/lan743x_ethtool.c | 27 + drivers/net/ethernet/microchip/lan743x_main.c | 78 +- drivers/net/ethernet/microchip/lan743x_main.h | 101 +- drivers/net/ethernet/microchip/lan743x_ptp.c | 1164 ++++++++++++++++++++++ drivers/net/ethernet/microchip/lan743x_ptp.h | 76 ++ 6 files changed, 1443 insertions(+), 5 deletions(-) create mode 100644 drivers/net/ethernet/microchip/lan743x_ptp.c create mode 100644 drivers/net/ethernet/microchip/lan743x_ptp.h
drivers/net/ethernet/microchip/Makefile +1 -1
@@ -6,4 +6,4 @@ obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_ENCX24J600) += encx24j600.o encx24j600-regmap.o obj-$(CONFIG_LAN743X) += lan743x.o -lan743x-objs := lan743x_main.o lan743x_ethtool.o +lan743x-objs := lan743x_main.o lan743x_ethtool.o lan743x_ptp.o
drivers/net/ethernet/microchip/lan743x_ethtool.c +27 -0
@@ -4,6 +4,7 @@#include <linux/netdevice.h> #include "lan743x_main.h" #include "lan743x_ethtool.h" +#include <linux/net_tstamp.h> #include <linux/pci.h> #include <linux/phy.h>
@@ -542,6 +543,31 @@ static int lan743x_ethtool_set_rxfh(struct net_device *netdev,return 0 ; } +static int lan743x_ethtool_get_ts_info (struct net_device *netdev, +struct ethtool_ts_info *ts_info) +{ +struct lan743x_adapter *adapter =netdev_priv (netdev); + + ts_info->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_RX_SOFTWARE | +SOF_TIMESTAMPING_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + +if (adapter->ptp.ptp_clock) + ts_info->phc_index =ptp_clock_index (adapter->ptp.ptp_clock); +else + ts_info->phc_index =-1 ; + + ts_info->tx_types =BIT (HWTSTAMP_TX_OFF ) | +BIT (HWTSTAMP_TX_ON ) | +BIT (HWTSTAMP_TX_ONESTEP_SYNC ); + ts_info->rx_filters =BIT (HWTSTAMP_FILTER_NONE ) | +BIT (HWTSTAMP_FILTER_ALL ); +return 0 ; +} +static int lan743x_ethtool_get_eee (struct net_device *netdev,struct ethtool_eee *eee) {
@@ -685,6 +711,7 @@ const struct ethtool_ops lan743x_ethtool_ops = { .get_rxfh_indir_size = lan743x_ethtool_get_rxfh_indir_size, .get_rxfh = lan743x_ethtool_get_rxfh, .set_rxfh = lan743x_ethtool_set_rxfh, + .get_ts_info = lan743x_ethtool_get_ts_info, .get_eee = lan743x_ethtool_get_eee, .set_eee = lan743x_ethtool_set_eee, .get_link_ksettings = phy_ethtool_get_link_ksettings,
drivers/net/ethernet/microchip/lan743x_main.c +75 -3
193 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_main.h +100 -1
163 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_ptp.c new file +1164 -0
1,164 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_ptp.h new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
2.7.4
drivers/net/ethernet/microchip/lan743x_ptp.c line 275
Quoted 13 lines · Bryan Whitehead
drivers/net/ethernet/microchip/lan743x_ptp.c new file +13
-0+static int lan743x_ptpci_adjfine (struct ptp_clock_info *ptpci,long scaled_ppm) +{ +struct lan743x_ptp *ptp = + container_of(ptpci, struct lan743x_ptp, ptp_clock_info); +struct lan743x_adapter *adapter = + container_of(ptp, struct lan743x_adapter, ptp); +u32 lan743x_rate_adj =0 ; +bool positive = true; +u64 u64_delta =0 ; + +if ((scaled_ppm < (-LAN743X_PTP_MAX_FINE_ADJ_IN_SCALED_PPM )) || + scaled_ppm >LAN743X_PTP_MAX_FINE_ADJ_IN_SCALED_PPM ) { +return -EINVAL ;
Maybe ERANGE is better here.
Quoted 12 lines
drivers/net/ethernet/microchip/lan743x_ptp.c new file +12
-0+ } +if (scaled_ppm >0 ) { + u64_delta = (u64 )scaled_ppm; + positive = true; + }else { + u64_delta = (u64)(-scaled_ppm); + positive = false; + } + u64_delta = (u64_delta <<19 ); + lan743x_rate_adj =div_u64 (u64_delta,1000000 ); + +if (positive)
drivers/net/ethernet/microchip/lan743x_ptp.c line 297
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_ptp.c new file +10
-0+ lan743x_rate_adj |=PTP_CLOCK_RATE_ADJ_DIR_ ; + +lan743x_csr_write (adapter,PTP_CLOCK_RATE_ADJ , + lan743x_rate_adj); + +return 0 ; +} + +static int lan743x_ptpci_adjfreq (struct ptp_clock_info *ptpci,s32 delta_ppb) +{
Since you have adjfine, you can delete adjfreq. The core PTP code does this in ptp_clock.c:
if (ops->adjfine) err = ops->adjfine(ops, tx->freq); else err = ops->adjfreq(ops, ppb);
Thanks,
Richard
From: Bryan Whitehead <[email protected]>
Date: Thu, 9 Aug 2018 15:36:10 -0400
Quoted 7 lines
PTP support includes:
Ingress, and egress timestamping.
One step timestamping available.
PTP clock support.
Periodic output support.Signed-off-by Bryan Whitehead <[email protected]>
Applied to net-next, thank you.