2023-07-31 05:25:51

by Vishvambar Panth S

[permalink] [raw]
Subject: [PATCH net-next] net: lan743x: skip timestamping for non-PTP packets

Currently all the RX packets are timestamped and the timestamp is appended
to the RX packet for processing, this reduces RX throughput. This can be
optimized by timestamping packets only when the PTP messages are received.
The RX PTP Configuration register [PTP_RX_TS_CFG] specifies what are the
PTP message types to be timestamped. The PTP_RX_TS_CFG_MSG_EN_ configures
Sync, Delay_Req, Pdelay_Req, Pdelay_Resp Message types to be timestamped.
The RX_CFG_B_TS_ALL_RX_ bit enables storing the timestamp for all RX
frames, now this is cleared as only PTP packets will be timestamped. The
RX_CFG_B_TS_DESCR_EN_ enables storing the timestamp in an extension
descriptor. When PTP messages are received the timestamp will be stored
in an extension descriptor of the RX packet.

Test setup: x86 PC with LAN7430 ---> x86 PC with i210 as partner

Before:

Connecting to host 192.168.10.3, port 5201
Reverse mode, remote host 192.168.10.3 is sending
[ 5] local 192.168.10.10 port 54072 connected to 192.168.10.3 port 5201
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 97.7 MBytes 819 Mbits/sec
[ 5] 1.00-2.00 sec 97.6 MBytes 819 Mbits/sec
[ 5] 2.00-3.00 sec 97.7 MBytes 819 Mbits/sec
[ 5] 3.00-4.00 sec 97.7 MBytes 819 Mbits/sec
[ 5] 4.00-5.00 sec 97.7 MBytes 820 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.05 sec 490 MBytes 814 Mbits/sec 0 sender
[ 5] 0.00-5.00 sec 488 MBytes 819 Mbits/sec receiver

iperf Done.

After:

Connecting to host 192.168.10.3, port 5201
Reverse mode, remote host 192.168.10.3 is sending
[ 5] local 192.168.10.10 port 42438 connected to 192.168.10.3 port 5201
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 112 MBytes 941 Mbits/sec
[ 5] 1.00-2.00 sec 112 MBytes 941 Mbits/sec
[ 5] 2.00-3.00 sec 112 MBytes 941 Mbits/sec
[ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec
[ 5] 4.00-5.00 sec 112 MBytes 941 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.04 sec 563 MBytes 936 Mbits/sec 0 sender
[ 5] 0.00-5.00 sec 561 MBytes 941 Mbits/sec receiver

iperf Done.

Signed-off-by: Vishvambar Panth S <[email protected]>
---
drivers/net/ethernet/microchip/lan743x_ethtool.c | 4 +++-
drivers/net/ethernet/microchip/lan743x_main.c | 2 +-
drivers/net/ethernet/microchip/lan743x_main.h | 5 ++++-
drivers/net/ethernet/microchip/lan743x_ptp.c | 11 +++++++++++
4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/microchip/lan743x_ethtool.c b/drivers/net/ethernet/microchip/lan743x_ethtool.c
index 2db5949b4c7e..01cb2e4cce82 100644
--- a/drivers/net/ethernet/microchip/lan743x_ethtool.c
+++ b/drivers/net/ethernet/microchip/lan743x_ethtool.c
@@ -1047,7 +1047,9 @@ static int lan743x_ethtool_get_ts_info(struct net_device *netdev,
BIT(HWTSTAMP_TX_ON) |
BIT(HWTSTAMP_TX_ONESTEP_SYNC);
ts_info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
- BIT(HWTSTAMP_FILTER_ALL);
+ BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
+ BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
+ BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ);
return 0;
}

diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index a36f6369f132..154f714f5b92 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -2938,7 +2938,7 @@ static int lan743x_rx_open(struct lan743x_rx *rx)
data |= RX_CFG_B_RX_PAD_2_;
data &= ~RX_CFG_B_RX_RING_LEN_MASK_;
data |= ((rx->ring_size) & RX_CFG_B_RX_RING_LEN_MASK_);
- data |= RX_CFG_B_TS_ALL_RX_;
+ data |= RX_CFG_B_TS_DESCR_EN_;
if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0))
data |= RX_CFG_B_RDMABL_512_;

diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index 52609fc13ad9..e1b01a899002 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -522,6 +522,9 @@
(((u32)(rx_latency)) & 0x0000FFFF)
#define PTP_CAP_INFO (0x0A60)
#define PTP_CAP_INFO_TX_TS_CNT_GET_(reg_val) (((reg_val) & 0x00000070) >> 4)
+#define PTP_RX_TS_CFG (0x0A68)
+/* Config for Sync, Delay_Req, Pdelay_Req, Pdelay_Resp Message types */
+#define PTP_RX_TS_CFG_MSG_EN_ (0x000F)

#define PTP_TX_MOD (0x0AA4)
#define PTP_TX_MOD_TX_PTP_SYNC_TS_INSERT_ (0x10000000)
@@ -656,7 +659,7 @@
#define RX_CFG_A_RX_HP_WB_EN_ BIT(5)

#define RX_CFG_B(channel) (0xC44 + ((channel) << 6))
-#define RX_CFG_B_TS_ALL_RX_ BIT(29)
+#define RX_CFG_B_TS_DESCR_EN_ BIT(28)
#define RX_CFG_B_RX_PAD_MASK_ (0x03000000)
#define RX_CFG_B_RX_PAD_0_ (0x00000000)
#define RX_CFG_B_RX_PAD_2_ (0x02000000)
diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
index 39e1066ecd5f..74204f5bf8b0 100644
--- a/drivers/net/ethernet/microchip/lan743x_ptp.c
+++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
@@ -1636,9 +1636,14 @@ static bool lan743x_ptp_is_enabled(struct lan743x_adapter *adapter)
static void lan743x_ptp_enable(struct lan743x_adapter *adapter)
{
struct lan743x_ptp *ptp = &adapter->ptp;
+ u32 data;

mutex_lock(&ptp->command_lock);

+ data = lan743x_csr_read(adapter, PTP_RX_TS_CFG);
+ data |= PTP_RX_TS_CFG_MSG_EN_;
+ lan743x_csr_write(adapter, PTP_RX_TS_CFG, data);
+
if (lan743x_ptp_is_enabled(adapter)) {
netif_warn(adapter, drv, adapter->netdev,
"PTP already enabled\n");
@@ -1652,6 +1657,7 @@ static void lan743x_ptp_enable(struct lan743x_adapter *adapter)
static void lan743x_ptp_disable(struct lan743x_adapter *adapter)
{
struct lan743x_ptp *ptp = &adapter->ptp;
+ u32 data;

mutex_lock(&ptp->command_lock);
if (!lan743x_ptp_is_enabled(adapter)) {
@@ -1659,6 +1665,11 @@ static void lan743x_ptp_disable(struct lan743x_adapter *adapter)
"PTP already disabled\n");
goto done;
}
+
+ data = lan743x_csr_read(adapter, PTP_RX_TS_CFG);
+ data &= ~PTP_RX_TS_CFG_MSG_EN_;
+ lan743x_csr_write(adapter, PTP_RX_TS_CFG, data);
+
lan743x_csr_write(adapter, PTP_CMD_CTL, PTP_CMD_CTL_PTP_DISABLE_);
lan743x_ptp_wait_till_cmd_done(adapter, PTP_CMD_CTL_PTP_ENABLE_);
done:
--
2.25.1



2023-07-31 14:11:16

by Vadim Fedorenko

[permalink] [raw]
Subject: Re: [PATCH net-next] net: lan743x: skip timestamping for non-PTP packets

On 31/07/2023 13:54, Vishvambar Panth S wrote:
> Currently all the RX packets are timestamped and the timestamp is appended
> to the RX packet for processing, this reduces RX throughput. This can be
> optimized by timestamping packets only when the PTP messages are received.
> The RX PTP Configuration register [PTP_RX_TS_CFG] specifies what are the
> PTP message types to be timestamped. The PTP_RX_TS_CFG_MSG_EN_ configures
> Sync, Delay_Req, Pdelay_Req, Pdelay_Resp Message types to be timestamped.
> The RX_CFG_B_TS_ALL_RX_ bit enables storing the timestamp for all RX
> frames, now this is cleared as only PTP packets will be timestamped. The
> RX_CFG_B_TS_DESCR_EN_ enables storing the timestamp in an extension
> descriptor. When PTP messages are received the timestamp will be stored
> in an extension descriptor of the RX packet.

Even though the performance benefit is clear, the PTP subsystem provides
options to select whether PTP filters must be applied or all packets
must be stamped. I think it's better to implement both options as the
hardware supports them, there are use cases where timestamps are needed
for all packets. Linuxptp can be easily configured for both variants,
the hardware/driver documentation can state that there will be
performance degradation for all RX packets timestamps mode.


2023-07-31 15:10:43

by Richard Cochran

[permalink] [raw]
Subject: Re: [PATCH net-next] net: lan743x: skip timestamping for non-PTP packets

On Mon, Jul 31, 2023 at 06:24:18PM +0530, Vishvambar Panth S wrote:
> Currently all the RX packets are timestamped and the timestamp is appended
> to the RX packet for processing, this reduces RX throughput. This can be
> optimized by timestamping packets only when the PTP messages are received.

No, you should not do this unconditionally.

Instead, you need to dial the correct setting based on the
hwtstamp_config in lan743x_ptp_ioctl().

Thanks,
Richard

2023-08-03 05:06:49

by Vishvambar Panth S

[permalink] [raw]
Subject: RE: [PATCH net-next] net: lan743x: skip timestamping for non-PTP packets

Hi Vadim,

Thanks for your review comments.
We will work on configuring timestamp based on hwtstamp_config. We will update in the next patch submission.

Thanks,
Vishvambar Panth S

-----Original Message-----
From: Vadim Fedorenko <[email protected]>
Sent: Monday, July 31, 2023 7:16 PM
To: VishvambarPanth S - I69108 <[email protected]>; [email protected]; [email protected]
Cc: Bryan Whitehead - C21958 <[email protected]>; UNGLinuxDriver <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] net: lan743x: skip timestamping for non-PTP packets

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

On 31/07/2023 13:54, Vishvambar Panth S wrote:
> Currently all the RX packets are timestamped and the timestamp is
> appended to the RX packet for processing, this reduces RX throughput.
> This can be optimized by timestamping packets only when the PTP messages are received.
> The RX PTP Configuration register [PTP_RX_TS_CFG] specifies what are
> the PTP message types to be timestamped. The PTP_RX_TS_CFG_MSG_EN_
> configures Sync, Delay_Req, Pdelay_Req, Pdelay_Resp Message types to be timestamped.
> The RX_CFG_B_TS_ALL_RX_ bit enables storing the timestamp for all RX
> frames, now this is cleared as only PTP packets will be timestamped.
> The RX_CFG_B_TS_DESCR_EN_ enables storing the timestamp in an
> extension descriptor. When PTP messages are received the timestamp
> will be stored in an extension descriptor of the RX packet.

Even though the performance benefit is clear, the PTP subsystem provides options to select whether PTP filters must be applied or all packets must be stamped. I think it's better to implement both options as the hardware supports them, there are use cases where timestamps are needed for all packets. Linuxptp can be easily configured for both variants, the hardware/driver documentation can state that there will be performance degradation for all RX packets timestamps mode.

2023-08-03 06:00:58

by Vishvambar Panth S

[permalink] [raw]
Subject: RE: [PATCH net-next] net: lan743x: skip timestamping for non-PTP packets

Hi Richard,

Thanks for your review comments.
We will work on configuring timestamp based on hwtstamp_config. We will update in the next patch submission.

Thanks,
Vishvambar Panth S

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Monday, July 31, 2023 7:21 PM
To: VishvambarPanth S - I69108 <[email protected]>
Cc: [email protected]; [email protected]; Bryan Whitehead - C21958 <[email protected]>; UNGLinuxDriver <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] net: lan743x: skip timestamping for non-PTP packets

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

On Mon, Jul 31, 2023 at 06:24:18PM +0530, Vishvambar Panth S wrote:
> Currently all the RX packets are timestamped and the timestamp is
> appended to the RX packet for processing, this reduces RX throughput.
> This can be optimized by timestamping packets only when the PTP messages are received.

No, you should not do this unconditionally.

Instead, you need to dial the correct setting based on the hwtstamp_config in lan743x_ptp_ioctl().

Thanks,
Richard