Skip to contentSkip to conversation

ENETC: support hardware timestamping

PATCH Superseded Y.b. Lu 3 participants 11 messages May 16, 2019 – May 20, 2019

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Y.b. Lu

author maintainer
#0 lore raw

cover ENETC: support hardware timestamping

This patch-set is to support hardware timestamping for ENETC and also to add 1588 timer device tree node for ls1028a.

Because ENETC RX BD ring dynamic allocation hasn't been supported and it's too expensive to use extended RX BDs if timestamping isn't used, we have to use a Kconfig option to enable/disable timestamping for now. This Kconfig option will be removed once RX BD ring dynamic allocation is implemented.

Yangbo Lu (3):
enetc: add hardware timestamping support
enetc: add get_ts_info interface for ethtool
arm64: dts: fsl: ls1028a: add ENETC 1588 timer node

 .../arm64/boot/dts/freescale/fsl-ls1028a.dtsi |   5 +
 drivers/net/ethernet/freescale/enetc/Kconfig  |  11 ++
 drivers/net/ethernet/freescale/enetc/enetc.c  | 156 +++++++++++++++++-
 drivers/net/ethernet/freescale/enetc/enetc.h  |  14 +-
 .../ethernet/freescale/enetc/enetc_ethtool.c  |  31 ++++
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  13 ++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |   1 +
 .../net/ethernet/freescale/enetc/enetc_ptp.c  |   5 +
 .../net/ethernet/freescale/enetc/enetc_vf.c   |   1 +
 9 files changed, 231 insertions(+), 6 deletions(-)
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 1/3 enetc: add hardware timestamping support

This patch is to add hardware timestamping support for ENETC. On Rx, timestamping is enabled for all frames. On Tx, we only instruct the hardware to timestamp the frames marked accordingly by the stack.

Because the RX BD ring dynamic allocation hasn't been supported and it's too expensive to use extended RX BDs if timestamping isn't used, we have to use a Kconfig option to enable/disable timestamping for now. This Kconfig option will be removed once RX BD ring dynamic allocation is implemented.

---
 drivers/net/ethernet/freescale/enetc/Kconfig  |  11 ++
 drivers/net/ethernet/freescale/enetc/enetc.c  | 156 +++++++++++++++++-
 drivers/net/ethernet/freescale/enetc/enetc.h  |  11 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  13 ++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |   1 +
 .../net/ethernet/freescale/enetc/enetc_vf.c   |   1 +
 6 files changed, 187 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/enetc/Kconfig +11 -0
index 8429f5c1d810..fc6f30d2ef91 100644
@@ -29,3 +29,14 @@ config FSL_ENETC_PTP_CLOCK
 	  packets using the SO_TIMESTAMPING API.
 
 	  If compiled as module (M), the module name is fsl-enetc-ptp.
+
+config FSL_ENETC_HW_TIMESTAMPING
+	bool "ENETC hardware timestamping support"
+	depends on FSL_ENETC || FSL_ENETC_VF
+	help
+	  Enable hardware timestamping support on the Ethernet packets
+	  using the SO_TIMESTAMPING API. Because the RX BD ring dynamic
+	  allocation hasn't been supported and it's too expensive to use
+	  extended RX BDs if timestamping isn't used, the option was used
+	  to control hardware timestamping/extended RX BDs to be enabled
+	  or not.
drivers/net/ethernet/freescale/enetc/enetc.c +151 -5

229 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc.h +10 -1
index b274135c5103..8c63ea253ab2 100644
@@ -21,7 +21,9 @@ struct enetc_tx_swbd {
 	struct sk_buff *skb;
 	dma_addr_t dma;
 	u16 len;
-	u16 is_dma_page;
+	u8 is_dma_page:1;
+	u8 check_wb:1;
+	u8 do_tstamp:1;
 };
 
 #define ENETC_RX_MAXFRM_SIZE	ENETC_MAC_MAXFRM_SIZE
@@ -167,6 +169,11 @@ struct enetc_cls_rule {
 
 #define ENETC_MAX_BDR_INT	2 /* fixed to max # of available cpus */
 
+enum enetc_hw_features {
+	ENETC_F_RX_TSTAMP	= BIT(0),
+	ENETC_F_TX_TSTAMP	= BIT(1),
+};
+
 struct enetc_ndev_priv {
 	struct net_device *ndev;
 	struct device *dev; /* dma-mapping device */
@@ -178,6 +185,7 @@ struct enetc_ndev_priv {
 	u16 rx_bd_count, tx_bd_count;
 
 	u16 msg_enable;
+	int hw_features;
 
 	struct enetc_bdr *tx_ring[16];
 	struct enetc_bdr *rx_ring[16];
@@ -216,6 +224,7 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev);
 struct net_device_stats *enetc_get_stats(struct net_device *ndev);
 int enetc_set_features(struct net_device *ndev,
 		       netdev_features_t features);
+int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd);
 /* ethtool */
 void enetc_set_ethtool_ops(struct net_device *ndev);
 
drivers/net/ethernet/freescale/enetc/enetc_hw.h +13 -0
index df8eb8882d92..6559cef4b07d 100644
@@ -361,6 +361,12 @@ union enetc_tx_bd {
 		u8 e_flags;
 		u8 flags;
 	} ext; /* Tx BD extension */
+	struct {
+		__le32 tstamp;
+		u8 reserved[10];
+		u8 status;
+		u8 flags;
+	} wb; /* writeback descriptor */
 };
 
 #define ENETC_TXBD_FLAGS_L4CS	BIT(0)
@@ -399,6 +405,9 @@ union enetc_rx_bd {
 	struct {
 		__le64 addr;
 		u8 reserved[8];
+#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
+		u8 reserved1[16];
+#endif
 	} w;
 	struct {
 		__le16 inet_csum;
@@ -413,6 +422,10 @@ union enetc_rx_bd {
 			};
 			__le32 lstatus;
 		};
+#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
+		__le32 tstamp;
+		u8 reserved[12];
+#endif
 	} r;
 };
 
drivers/net/ethernet/freescale/enetc/enetc_pf.c +1 -0
index 15876a6e7598..17e9017cf897 100644
@@ -702,6 +702,7 @@ static const struct net_device_ops enetc_ndev_ops = {
 	.ndo_set_vf_vlan	= enetc_pf_set_vf_vlan,
 	.ndo_set_vf_spoofchk	= enetc_pf_set_vf_spoofchk,
 	.ndo_set_features	= enetc_pf_set_features,
+	.ndo_do_ioctl		= enetc_ioctl,
 };
 
 static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
drivers/net/ethernet/freescale/enetc/enetc_vf.c +1 -0
index 64bebee9f52a..af93cb1af513 100644
@@ -111,6 +111,7 @@ static const struct net_device_ops enetc_ndev_ops = {
 	.ndo_get_stats		= enetc_get_stats,
 	.ndo_set_mac_address	= enetc_vf_set_mac_addr,
 	.ndo_set_features	= enetc_vf_set_features,
+	.ndo_do_ioctl		= enetc_ioctl,
 };
 
 static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
Signature · 1 line
2.17.1
author maintainer
#9 lore raw

PATCH 2/3 enetc: add get_ts_info interface for ethtool

In reply to Y.b. Lu

This patch is to add get_ts_info interface for ethtool to support getting timestamping capability.

---
 drivers/net/ethernet/freescale/enetc/enetc.h  |  3 ++
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 31 +++++++++++++++++++
 .../net/ethernet/freescale/enetc/enetc_ptp.c  |  5 +++
 3 files changed, 39 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc.h +3 -0
index 8c63ea253ab2..eb7cc76dc0c0 100644
@@ -208,6 +208,9 @@ struct enetc_msg_cmd_set_primary_mac {
 
 #define ENETC_CBDR_TIMEOUT	1000 /* usecs */
 
+/* PTP driver exports */
+extern int enetc_phc_index;
+
 /* SI common */
 int enetc_pci_probe(struct pci_dev *pdev, const char *name, int sizeof_priv);
 void enetc_pci_remove(struct pci_dev *pdev);
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +31 -0
index 1ecad9ffabae..e2e5a0ca8c47 100644
@@ -555,6 +555,35 @@ static void enetc_get_ringparam(struct net_device *ndev,
 	}
 }
 
+static int enetc_get_ts_info(struct net_device *ndev,
+			     struct ethtool_ts_info *info)
+{
+	int *phc_idx;
+
+	phc_idx = symbol_get(enetc_phc_index);
+	if (phc_idx) {
+		info->phc_index = *phc_idx;
+		symbol_put(enetc_phc_index);
+	} else {
+		info->phc_index = -1;
+	}
+
+#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
+	info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
+				SOF_TIMESTAMPING_RX_HARDWARE |
+				SOF_TIMESTAMPING_RAW_HARDWARE;
+
+	info->tx_types = (1 << HWTSTAMP_TX_OFF) |
+			 (1 << HWTSTAMP_TX_ON);
+	info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
+			   (1 << HWTSTAMP_FILTER_ALL);
+#else
+	info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
+				SOF_TIMESTAMPING_SOFTWARE;
+#endif
+	return 0;
+}
+
 static const struct ethtool_ops enetc_pf_ethtool_ops = {
 	.get_regs_len = enetc_get_reglen,
 	.get_regs = enetc_get_regs,
@@ -570,6 +599,7 @@ static const struct ethtool_ops enetc_pf_ethtool_ops = {
 	.get_ringparam = enetc_get_ringparam,
 	.get_link_ksettings = phy_ethtool_get_link_ksettings,
 	.set_link_ksettings = phy_ethtool_set_link_ksettings,
+	.get_ts_info = enetc_get_ts_info,
 };
 
 static const struct ethtool_ops enetc_vf_ethtool_ops = {
@@ -584,6 +614,7 @@ static const struct ethtool_ops enetc_vf_ethtool_ops = {
 	.get_rxfh = enetc_get_rxfh,
 	.set_rxfh = enetc_set_rxfh,
 	.get_ringparam = enetc_get_ringparam,
+	.get_ts_info = enetc_get_ts_info,
 };
 
 void enetc_set_ethtool_ops(struct net_device *ndev)
drivers/net/ethernet/freescale/enetc/enetc_ptp.c +5 -0
index 8c1497e7d9c5..2fd2586e42bf 100644
@@ -7,6 +7,9 @@
 
 #include "enetc.h"
 
+int enetc_phc_index = -1;
+EXPORT_SYMBOL(enetc_phc_index);
+
 static struct ptp_clock_info enetc_ptp_caps = {
 	.owner		= THIS_MODULE,
 	.name		= "ENETC PTP clock",
@@ -96,6 +99,7 @@ static int enetc_ptp_probe(struct pci_dev *pdev,
 	if (err)
 		goto err_no_clock;
 
+	enetc_phc_index = ptp_qoriq->phc_index;
 	pci_set_drvdata(pdev, ptp_qoriq);
 
 	return 0;
@@ -119,6 +123,7 @@ static void enetc_ptp_remove(struct pci_dev *pdev)
 {
 	struct ptp_qoriq *ptp_qoriq = pci_get_drvdata(pdev);
 
+	enetc_phc_index = -1;
 	ptp_qoriq_free(ptp_qoriq);
 	kfree(ptp_qoriq);
 
Signature · 1 line
2.17.1
author maintainer
#10 lore raw

PATCH 3/3 arm64: dts: fsl: ls1028a: add ENETC 1588 timer node

In reply to Y.b. Lu

Add ENETC 1588 timer node which is ENETC PF 4 (Physiscal Function 4).

---
 arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi +5 -0
index 2896bbcfa3bb..d732a63754fb 100644
@@ -369,6 +369,11 @@
 				compatible = "fsl,enetc";
 				reg = <0x000100 0 0 0 0>;
 			};
+			ethernet@0,4 { /* PTP clock */
+				reg = <0x000400 0 0 0 0>;
+				clocks = <&clockgen 4 0>;
+				little-endian;
+			};
 		};
 	};
 };
Signature · 1 line
2.17.1
maintainer
#2 lore raw

RE: [PATCH 1/3] enetc: add hardware timestamping support

In reply to Y.b. Lu
Quoted 2 lines

-----Original Message-----
From: Y.b. Lu

[...]

Quoted 2 lines

Subject: [PATCH 1/3] enetc: add hardware timestamping support

[...]

Hi Yangbo,

These enetc patches targeting net-next will have to be rebased on the latest enetc net.git commits, otherwise there will be some merge conflicts for enetc.c and enetc_ethtool.c.
Thanks,
Claudiu

see
22fb43f36006 "enetc: Add missing link state info for ethtool" f4a0be84d73e "enetc: Fix NULL dma address unmap for Tx BD extensions"

#4 lore raw

Re: [PATCH 1/3] enetc: add hardware timestamping support

In reply to Y.b. Lu

drivers/net/ethernet/freescale/enetc/Kconfig config FSL_ENETC_PTP_CLOCK · line 39

Quoted 7 lines · Y.b. Lu
drivers/net/ethernet/freescale/enetc/Kconfig +7 -0
+config FSL_ENETC_HW_TIMESTAMPING
+	bool "ENETC hardware timestamping support"
+	depends on FSL_ENETC || FSL_ENETC_VF
+	help
+	  Enable hardware timestamping support on the Ethernet packets
+	  using the SO_TIMESTAMPING API. Because the RX BD ring dynamic
+	  allocation hasn't been supported and it's too expensive to use

s/it's/it is/

drivers/net/ethernet/freescale/enetc/Kconfig config FSL_ENETC_PTP_CLOCK · line 42

Quoted 3 lines
drivers/net/ethernet/freescale/enetc/Kconfig +3 -0
+	  extended RX BDs if timestamping isn't used, the option was used
+	  to control hardware timestamping/extended RX BDs to be enabled
+	  or not.

..., this option enables extended RX BDs in order to support hardware timestamping.

drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci) · line 339

Quoted 10 lines

static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int napi_budget) {

drivers/net/ethernet/freescale/enetc/enetc.c +4 -0
 	struct net_device *ndev = tx_ring->ndev;
+	struct enetc_ndev_priv *priv = netdev_priv(ndev);
 	int tx_frm_cnt = 0, tx_byte_cnt = 0;
 	struct enetc_tx_swbd *tx_swbd;
+	union enetc_tx_bd *txbd;
+	bool do_tstamp;
 	int i, bds_to_clean;
+	u64 tstamp = 0;

Please keep in reverse Christmas tree order as much as possible:

	union enetc_tx_bd *txbd;
	int i, bds_to_clean;
	bool do_tstamp;
	u64 tstamp = 0;
Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc.c +5 -0
 	i = tx_ring->next_to_clean;
 	tx_swbd = &tx_ring->tx_swbd[i];
 	bds_to_clean = enetc_bd_ready_count(tx_ring, i);
 
+	do_tstamp = false;
+
 	while (bds_to_clean && tx_frm_cnt < ENETC_DEFAULT_TX_WORK) {
 		bool is_eof = !!tx_swbd->skb;
 
+		if (unlikely(tx_swbd->check_wb)) {
+			txbd = ENETC_TXBD(*tx_ring, i);
+

drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci) · line 362

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.c +10 -0
+			if (!(txbd->flags & ENETC_TXBD_FLAGS_W))
+				goto no_wb;
+
+			if (tx_swbd->do_tstamp) {
+				enetc_get_tx_tstamp(&priv->si->hw, txbd,
+						    &tstamp);
+				do_tstamp = true;
+			}
+		}
+no_wb:

This goto seems strange and unnecessary. How about this instead?

			if (txbd->flags & ENETC_TXBD_FLAGS_W &&
			    tx_swbd->do_tstamp) {
				enetc_get_tx_tstamp(&priv->si->hw, txbd, &tstamp);
				do_tstamp = true;
			}
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.c +4 -0
 		enetc_unmap_tx_buff(tx_ring, tx_swbd);
 		if (is_eof) {
+			if (unlikely(do_tstamp)) {
+				enetc_tstamp_tx(tx_swbd->skb, tstamp);
+				do_tstamp = false;
+			}
 			napi_consume_skb(tx_swbd->skb, napi_budget);
 			tx_swbd->skb = NULL;
 		}

drivers/net/ethernet/freescale/enetc/enetc.c struct enetc_cls_rule { · line 172

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1 -0
@@ -167,6 +169,11 @@ struct enetc_cls_rule {
 
 #define ENETC_MAX_BDR_INT	2 /* fixed to max # of available cpus */
 
+enum enetc_hw_features {

This is a poor choice of name. It sounds like it describes HW capabilities, but you use it to track whether a feature is requested at run time.

drivers/net/ethernet/freescale/enetc/enetc.h struct enetc_ndev_priv { · line 188

Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc.h +5 -0
+	ENETC_F_RX_TSTAMP	= BIT(0),
+	ENETC_F_TX_TSTAMP	= BIT(1),
+};
+
 struct enetc_ndev_priv {
 	struct net_device *ndev;
 	struct device *dev; /* dma-mapping device */
@@ -178,6 +185,7 @@ struct enetc_ndev_priv {
 	u16 rx_bd_count, tx_bd_count;
 
 	u16 msg_enable;
+	int hw_features;

This is also poorly named. How about "tstamp_request" instead?

drivers/net/ethernet/freescale/enetc/enetc.h struct enetc_ndev_priv { · line 191

Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc.h +0 -0
 	struct enetc_bdr *tx_ring[16];
 	struct enetc_bdr *rx_ring[16];

Thanks,
Richard

maintainer
#5 lore raw

RE: [PATCH 1/3] enetc: add hardware timestamping support

Quoted 13 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Thursday, May 16, 2019 5:33 PM
To: Y.b. Lu <[email protected]>
Cc: [email protected]; David Miller <[email protected]>; Claudiu Manoil <[email protected]>; Shawn Guo <[email protected]>; Rob Herring <[email protected]>; [email protected]; linux-arm- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] enetc: add hardware timestamping support

On Thu, May 16, 2019 at 09:59:08AM +0000, Y.b. Lu wrote:

[...]

Quoted 13 lines

drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci) · line 339

Quoted 11 lines

static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int napi_budget) {

drivers/net/ethernet/freescale/enetc/enetc.c +4 -0
 	struct net_device *ndev = tx_ring->ndev;
+	struct enetc_ndev_priv *priv = netdev_priv(ndev);
 	int tx_frm_cnt = 0, tx_byte_cnt = 0;
 	struct enetc_tx_swbd *tx_swbd;
+	union enetc_tx_bd *txbd;
+	bool do_tstamp;
 	int i, bds_to_clean;
+	u64 tstamp = 0;

Please keep in reverse Christmas tree order as much as possible:

For the xmass tree part, Yangbo, better move the priv and txbd declarations inside the scope of the if() {} block where they are actually used, i.e.:

		if (unlikely(tx_swbd->check_wb)) {
			struct enetc_ndev_priv *priv = netdev_priv(ndev);
			union enetc_tx_bd *txbd;
			[...]
		}
Quoted 31 lines
	union enetc_tx_bd *txbd;
	int i, bds_to_clean;
	bool do_tstamp;
	u64 tstamp = 0;
Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc.c +5 -0
 	i = tx_ring->next_to_clean;
 	tx_swbd = &tx_ring->tx_swbd[i];
 	bds_to_clean = enetc_bd_ready_count(tx_ring, i);
 
+	do_tstamp = false;
+
 	while (bds_to_clean && tx_frm_cnt < ENETC_DEFAULT_TX_WORK) {
 		bool is_eof = !!tx_swbd->skb;
 
+		if (unlikely(tx_swbd->check_wb)) {
+			txbd = ENETC_TXBD(*tx_ring, i);
+

drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci) · line 362

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.c +10 -0
+			if (!(txbd->flags & ENETC_TXBD_FLAGS_W))
+				goto no_wb;
+
+			if (tx_swbd->do_tstamp) {
+				enetc_get_tx_tstamp(&priv->si->hw, txbd,
+						    &tstamp);
+				do_tstamp = true;
+			}
+		}
+no_wb:

This goto seems strange and unnecessary. How about this instead?

Quoted 6 lines
			if (txbd->flags & ENETC_TXBD_FLAGS_W &&
			    tx_swbd->do_tstamp) {
				enetc_get_tx_tstamp(&priv->si->hw, txbd, &tstamp);
				do_tstamp = true;
			}

Absolutely, somehow I missed this. I guess the intention was to be able to support multiple if() blocks for the writeback case (W flag set) but the code is much better off without the goto.

Quoted 29 lines
Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.c +4 -0
 		enetc_unmap_tx_buff(tx_ring, tx_swbd);
 		if (is_eof) {
+			if (unlikely(do_tstamp)) {
+				enetc_tstamp_tx(tx_swbd->skb, tstamp);
+				do_tstamp = false;
+			}
 			napi_consume_skb(tx_swbd->skb, napi_budget);
 			tx_swbd->skb = NULL;
 		}

drivers/net/ethernet/freescale/enetc/enetc.c struct enetc_cls_rule { · line 172

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1 -0
@@ -167,6 +169,11 @@ struct enetc_cls_rule {
 
 #define ENETC_MAX_BDR_INT	2 /* fixed to max # of available cpus */
 
+enum enetc_hw_features {

This is a poor choice of name. It sounds like it describes HW capabilities, but you use it to track whether a feature is requested at run time.

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.h +4 -0
+	ENETC_F_RX_TSTAMP	= BIT(0),
+	ENETC_F_TX_TSTAMP	= BIT(1),
+};
+
 struct enetc_ndev_priv {
 	struct net_device *ndev;
 	struct device *dev; /* dma-mapping device */
@@ -178,6 +185,7 @@ struct enetc_ndev_priv {
 	u16 rx_bd_count, tx_bd_count;
 
Quoted 5 lines

drivers/net/ethernet/freescale/enetc/enetc.h struct enetc_ndev_priv { · line 188

Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc.h +1 -0
 	u16 msg_enable;
+	int hw_features;

This is also poorly named. How about "tstamp_request" instead?

This ndev_priv variable was intended to gather flags for all the active h/w related features, i.e. keeping count of what h/w offloads are enabled for the current device (at least for those that don't have already a netdev_features_t flag). I wouldn't waste an int for 2 timestamp flags, I'd rather have a more generic name. Maybe active_offloads then?

Anyway, the name can be changed later too, when other offloads will be added.

Thanks,
Claudiu

author maintainer
#3 lore raw

RE: [PATCH 1/3] enetc: add hardware timestamping support

In reply to Claudiu Manoil
Quoted 25 lines

-----Original Message-----
From: Claudiu Manoil
Sent: Thursday, May 16, 2019 9:31 PM
To: Y.b. Lu <[email protected]>; [email protected]; Richard Cochran <[email protected]>; David Miller <[email protected]>; Shawn Guo <[email protected]>; Rob Herring <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH 1/3] enetc: add hardware timestamping support

Quoted 2 lines

-----Original Message-----
From: Y.b. Lu

[...]

Quoted 2 lines

Subject: [PATCH 1/3] enetc: add hardware timestamping support

[...]

Hi Yangbo,

These enetc patches targeting net-next will have to be rebased on the latest enetc net.git commits, otherwise there will be some merge conflicts for enetc.c and enetc_ethtool.c.
Thanks,
Claudiu

Quoted 3 lines

see
22fb43f36006 "enetc: Add missing link state info for ethtool" f4a0be84d73e "enetc: Fix NULL dma address unmap for Tx BD extensions"

[Y.b. Lu] Thanks Claudiu. I should have noticed that. Let me send v2 after net-next is open.

author maintainer
#7 lore raw

RE: [EXT] Re: [PATCH 1/3] enetc: add hardware timestamping support

In reply to Richard Cochran

Hi,

Quoted 21 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Thursday, May 16, 2019 10:33 PM
To: Y.b. Lu <[email protected]>
Cc: [email protected]; David Miller <[email protected]>; Claudiu Manoil <[email protected]>; Shawn Guo <[email protected]>; Rob Herring <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [PATCH 1/3] enetc: add hardware timestamping support

drivers/net/ethernet/freescale/enetc/Kconfig config FSL_ENETC_PTP_CLOCK · line 39

Quoted 7 lines · Y.b. Lu
drivers/net/ethernet/freescale/enetc/Kconfig +7 -0
+config FSL_ENETC_HW_TIMESTAMPING
+     bool "ENETC hardware timestamping support"
+     depends on FSL_ENETC || FSL_ENETC_VF
+     help
+       Enable hardware timestamping support on the Ethernet packets
+       using the SO_TIMESTAMPING API. Because the RX BD ring dynamic
+       allocation hasn't been supported and it's too expensive to use
Quoted 1 line

s/it's/it is/

[Y.b. Lu] Will modify it. BTW, may I know what's the purpose of dropping single quote character? For searching, script checking, or something else? If require to not use single quote character, I will also modify some other places in Kconfig messages.

Quoted 7 lines

drivers/net/ethernet/freescale/enetc/Kconfig config FSL_ENETC_PTP_CLOCK · line 42

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/Kconfig +3 -0
+       extended RX BDs if timestamping isn't used, the option was used
+       to control hardware timestamping/extended RX BDs to be enabled
+       or not.

..., this option enables extended RX BDs in order to support hardware timestamping.

[Y.b. Lu] Will rephrase it.

Quoted 91 lines

drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci) · line 339

Quoted 11 lines

static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int

napi_budget)  {
      struct net_device *ndev = tx_ring->ndev;
drivers/net/ethernet/freescale/enetc/enetc.c +4 -0
+     struct enetc_ndev_priv *priv = netdev_priv(ndev);
      int tx_frm_cnt = 0, tx_byte_cnt = 0;
      struct enetc_tx_swbd *tx_swbd;
+     union enetc_tx_bd *txbd;
+     bool do_tstamp;
      int i, bds_to_clean;
+     u64 tstamp = 0;

Please keep in reverse Christmas tree order as much as possible:

        union enetc_tx_bd *txbd;
        int i, bds_to_clean;
        bool do_tstamp;
        u64 tstamp = 0;
Quoted 12 lines
      i = tx_ring->next_to_clean;
      tx_swbd = &tx_ring->tx_swbd[i];
      bds_to_clean = enetc_bd_ready_count(tx_ring, i);
drivers/net/ethernet/freescale/enetc/enetc.c +5 -0
+     do_tstamp = false;
+
      while (bds_to_clean && tx_frm_cnt < ENETC_DEFAULT_TX_WORK) {
              bool is_eof = !!tx_swbd->skb;
 
+             if (unlikely(tx_swbd->check_wb)) {
+                     txbd = ENETC_TXBD(*tx_ring, i);
+

drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci) · line 362

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.c +10 -0
+                     if (!(txbd->flags & ENETC_TXBD_FLAGS_W))
+                             goto no_wb;
+
+                     if (tx_swbd->do_tstamp) {
+                             enetc_get_tx_tstamp(&priv->si->hw, txbd,
+                                                 &tstamp);
+                             do_tstamp = true;
+                     }
+             }
+no_wb:

This goto seems strange and unnecessary. How about this instead?

                        if (txbd->flags & ENETC_TXBD_FLAGS_W &&
                            tx_swbd->do_tstamp) {
                                enetc_get_tx_tstamp(&priv->si->hw, txbd,
&tstamp);
                                do_tstamp = true;
                        }
Quoted 10 lines
              enetc_unmap_tx_buff(tx_ring, tx_swbd);
              if (is_eof) {
drivers/net/ethernet/freescale/enetc/enetc.c +4 -0
+                     if (unlikely(do_tstamp)) {
+                             enetc_tstamp_tx(tx_swbd->skb, tstamp);
+                             do_tstamp = false;
+                     }
                      napi_consume_skb(tx_swbd->skb, napi_budget);
                      tx_swbd->skb = NULL;
              }

drivers/net/ethernet/freescale/enetc/enetc.c struct enetc_cls_rule { · line 172

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1 -0
@@ -167,6 +169,11 @@ struct enetc_cls_rule {
 
 #define ENETC_MAX_BDR_INT    2 /* fixed to max # of available cpus */
 
+enum enetc_hw_features {

This is a poor choice of name. It sounds like it describes HW capabilities, but you use it to track whether a feature is requested at run time.

drivers/net/ethernet/freescale/enetc/enetc.h struct enetc_cls_rule {

Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc.h +4 -0
+     ENETC_F_RX_TSTAMP       = BIT(0),
+     ENETC_F_TX_TSTAMP       = BIT(1),
+};
+
 struct enetc_ndev_priv {
      struct net_device *ndev;
      struct device *dev; /* dma-mapping device */ @@ -178,6 +185,7

@@

Quoted 5 lines
struct enetc_ndev_priv {
      u16 rx_bd_count, tx_bd_count;

      u16 msg_enable;

+ int hw_features;

This is also poorly named. How about "tstamp_request" instead?

Quoted 3 lines
      struct enetc_bdr *tx_ring[16];
      struct enetc_bdr *rx_ring[16];

Thanks,
Richard

author maintainer
#6 lore raw

RE: [PATCH 1/3] enetc: add hardware timestamping support

In reply to Claudiu Manoil

Hi,

Quoted 40 lines

-----Original Message-----
From: Claudiu Manoil
Sent: Thursday, May 16, 2019 11:31 PM
To: Richard Cochran <[email protected]>; Y.b. Lu <[email protected]>
Cc: [email protected]; David Miller <[email protected]>; Shawn Guo <[email protected]>; Rob Herring <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH 1/3] enetc: add hardware timestamping support

Quoted 6 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Thursday, May 16, 2019 5:33 PM
To: Y.b. Lu <[email protected]>
Cc: [email protected]; David Miller <[email protected]>; Claudiu Manoil <[email protected]>; Shawn Guo <[email protected]>;

Rob

Quoted 6 lines

Herring <[email protected]>; [email protected]; linux-arm- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] enetc: add hardware timestamping support

On Thu, May 16, 2019 at 09:59:08AM +0000, Y.b. Lu wrote:

[...]

Quoted 13 lines

drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci) · line 339

Quoted 11 lines

static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int
napi_budget) {

drivers/net/ethernet/freescale/enetc/enetc.c +4 -0
 	struct net_device *ndev = tx_ring->ndev;
+	struct enetc_ndev_priv *priv = netdev_priv(ndev);
 	int tx_frm_cnt = 0, tx_byte_cnt = 0;
 	struct enetc_tx_swbd *tx_swbd;
+	union enetc_tx_bd *txbd;
+	bool do_tstamp;
 	int i, bds_to_clean;
+	u64 tstamp = 0;

Please keep in reverse Christmas tree order as much as possible:

Quoted 9 lines

For the xmass tree part, Yangbo, better move the priv and txbd declarations inside the scope of the if() {} block where they are actually used, i.e.:

		if (unlikely(tx_swbd->check_wb)) {
			struct enetc_ndev_priv *priv = netdev_priv(ndev);
			union enetc_tx_bd *txbd;
			[...]
		}

[Y.b. Lu] Will do that.

Quoted 38 lines
Quoted 31 lines
	union enetc_tx_bd *txbd;
	int i, bds_to_clean;
	bool do_tstamp;
	u64 tstamp = 0;
Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc.c +5 -0
 	i = tx_ring->next_to_clean;
 	tx_swbd = &tx_ring->tx_swbd[i];
 	bds_to_clean = enetc_bd_ready_count(tx_ring, i);
 
+	do_tstamp = false;
+
 	while (bds_to_clean && tx_frm_cnt < ENETC_DEFAULT_TX_WORK) {
 		bool is_eof = !!tx_swbd->skb;
 
+		if (unlikely(tx_swbd->check_wb)) {
+			txbd = ENETC_TXBD(*tx_ring, i);
+

drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci) · line 362

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.c +10 -0
+			if (!(txbd->flags & ENETC_TXBD_FLAGS_W))
+				goto no_wb;
+
+			if (tx_swbd->do_tstamp) {
+				enetc_get_tx_tstamp(&priv->si->hw, txbd,
+						    &tstamp);
+				do_tstamp = true;
+			}
+		}
+no_wb:

This goto seems strange and unnecessary. How about this instead?

Quoted 6 lines
			if (txbd->flags & ENETC_TXBD_FLAGS_W &&
			    tx_swbd->do_tstamp) {
				enetc_get_tx_tstamp(&priv->si->hw, txbd, &tstamp);
				do_tstamp = true;
			}
Quoted 4 lines

Absolutely, somehow I missed this. I guess the intention was to be able to support multiple
if() blocks for the writeback case (W flag set) but the code is much better off without the goto.

[Y.b. Lu] Will use this to support current single tstamp writeback case.

Quoted 44 lines
Quoted 30 lines
Quoted 11 lines
drivers/net/ethernet/freescale/enetc/enetc.c +4 -0
 		enetc_unmap_tx_buff(tx_ring, tx_swbd);
 		if (is_eof) {
+			if (unlikely(do_tstamp)) {
+				enetc_tstamp_tx(tx_swbd->skb, tstamp);
+				do_tstamp = false;
+			}
 			napi_consume_skb(tx_swbd->skb, napi_budget);
 			tx_swbd->skb = NULL;
 		}

drivers/net/ethernet/freescale/enetc/enetc.c struct enetc_cls_rule { · line 172

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1 -0
@@ -167,6 +169,11 @@ struct enetc_cls_rule {
 
 #define ENETC_MAX_BDR_INT	2 /* fixed to max # of available cpus */
 
+enum enetc_hw_features {

This is a poor choice of name. It sounds like it describes HW capabilities, but you use it to track whether a feature is requested at run time.

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc.h +4 -0
+	ENETC_F_RX_TSTAMP	= BIT(0),
+	ENETC_F_TX_TSTAMP	= BIT(1),
+};
+
 struct enetc_ndev_priv {
 	struct net_device *ndev;
 	struct device *dev; /* dma-mapping device */ @@ -178,6 +185,7 @@

struct enetc_ndev_priv {
u16 rx_bd_count, tx_bd_count;

Quoted 5 lines

drivers/net/ethernet/freescale/enetc/enetc.h struct enetc_ndev_priv { · line 188

Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc.h +1 -0
 	u16 msg_enable;
+	int hw_features;

This is also poorly named. How about "tstamp_request" instead?

This ndev_priv variable was intended to gather flags for all the active h/w related features, i.e. keeping count of what h/w offloads are enabled for the current device (at least for those that don't have already a netdev_features_t flag).
I wouldn't waste an int for 2 timestamp flags, I'd rather have a more generic name.
Maybe active_offloads then?

Quoted 2 lines

Anyway, the name can be changed later too, when other offloads will be added.

[Y.b. Lu] How about using active_offloads, and add TODO comments in enum enetc_active_offloads?

Quoted 3 lines

Thanks,
Claudiu

#8 lore raw

Re: [EXT] Re: [PATCH 1/3] enetc: add hardware timestamping support

In reply to Y.b. Lu
Quoted 11 lines · Y.b. Lu
Quoted 9 lines

drivers/net/ethernet/freescale/enetc/Kconfig config FSL_ENETC_PTP_CLOCK · line 39

Quoted 7 lines
drivers/net/ethernet/freescale/enetc/Kconfig +7 -0
+config FSL_ENETC_HW_TIMESTAMPING
+     bool "ENETC hardware timestamping support"
+     depends on FSL_ENETC || FSL_ENETC_VF
+     help
+       Enable hardware timestamping support on the Ethernet packets
+       using the SO_TIMESTAMPING API. Because the RX BD ring dynamic
+       allocation hasn't been supported and it's too expensive to use

s/it's/it is/

[Y.b. Lu] Will modify it. BTW, may I know what's the purpose of dropping single quote character? For searching, script checking, or something else?

Simply because "it's" is informal speech, but the Kconfig help is formal technical documentation. (Or at least it should be!)

Thanks,
Richard