linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x
@ 2025-07-15 11:02 Luo Jie
  2025-07-15 11:02 ` [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support Luo Jie
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Luo Jie @ 2025-07-15 11:02 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-arm-msm, linux-kernel, Luo Jie

The implementation of the PHY counter is identical for both QCA808x and
QCA807x series devices. This includes counters for both good and bad CRC
frames in the RX and TX directions, which are active when CRC checking
is enabled.

This patch series introduces PHY counter functions into a shared library,
enabling counter support for the QCA808x and QCA807x families through this
common infrastructure. Additionally, enable CRC checking and configure
automatic clearing of counters after reading within config_init() to ensure
accurate counter recording.

Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
---
Changes in v3:
- Resolved the compilation error on the ARCH_i386 platform as reported by
  the kernel test robot.
- Link to v2: https://lore.kernel.org/r/20250714-qcom_phy_counter-v2-0-94dde9d9769f@quicinc.com

Changes in v2:
- Update to use the standardized PHY statistics framework.
- Enabled automatic clearing of counters following each read operation,
  ensuring support for 64-bit statistics.
- Link to v1: https://lore.kernel.org/r/20250709-qcom_phy_counter-v1-0-93a54a029c46@quicinc.com

---
Luo Jie (3):
      net: phy: qcom: Add PHY counter support
      net: phy: qcom: qca808x: Support PHY counter
      net: phy: qcom: qca807x: Support PHY counter

 drivers/net/phy/qcom/qca807x.c      | 25 +++++++++++++
 drivers/net/phy/qcom/qca808x.c      | 23 ++++++++++++
 drivers/net/phy/qcom/qcom-phy-lib.c | 75 +++++++++++++++++++++++++++++++++++++
 drivers/net/phy/qcom/qcom.h         | 23 ++++++++++++
 4 files changed, 146 insertions(+)
---
base-commit: 06baf9bfa6ca8db7d5f32e12e27d1dc1b7cb3a8a
change-id: 20250709-qcom_phy_counter-49fe93241fdd

Best regards,
-- 
Luo Jie <quic_luoj@quicinc.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support
  2025-07-15 11:02 [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x Luo Jie
@ 2025-07-15 11:02 ` Luo Jie
  2025-07-15 16:11   ` Andrew Lunn
  2025-07-17 13:38   ` Andrew Lunn
  2025-07-15 11:02 ` [PATCH net-next v3 2/3] net: phy: qcom: qca808x: Support PHY counter Luo Jie
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Luo Jie @ 2025-07-15 11:02 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-arm-msm, linux-kernel, Luo Jie

Add PHY counter functionality to the shared library. The implementation
is identical for the current QCA807X and QCA808X PHYs.

The PHY counter can be configured to perform CRC checking for both received
and transmitted packets. Additionally, the packet counter can be set to
automatically clear after it is read.

The PHY counter includes 32-bit packet counters for both RX (received) and
TX (transmitted) packets, as well as 16-bit counters for recording CRC
error packets for both RX and TX.

Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
---
 drivers/net/phy/qcom/qcom-phy-lib.c | 75 +++++++++++++++++++++++++++++++++++++
 drivers/net/phy/qcom/qcom.h         | 23 ++++++++++++
 2 files changed, 98 insertions(+)

diff --git a/drivers/net/phy/qcom/qcom-phy-lib.c b/drivers/net/phy/qcom/qcom-phy-lib.c
index af7d0d8e81be..965c2bb99a9b 100644
--- a/drivers/net/phy/qcom/qcom-phy-lib.c
+++ b/drivers/net/phy/qcom/qcom-phy-lib.c
@@ -699,3 +699,78 @@ int qca808x_led_reg_blink_set(struct phy_device *phydev, u16 reg,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(qca808x_led_reg_blink_set);
+
+/* Enable CRC checking for both received and transmitted frames to ensure
+ * accurate counter recording. The hardware supports a 32-bit counter,
+ * configure the counter to clear after it is read to facilitate the
+ * implementation of a 64-bit software counter
+ */
+int qcom_phy_counter_config(struct phy_device *phydev)
+{
+	return phy_set_bits_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_CTRL,
+				QCA808X_MMD7_CNT_CTRL_CRC_CHECK_EN |
+				QCA808X_MMD7_CNT_CTRL_READ_CLEAR_EN);
+}
+EXPORT_SYMBOL_GPL(qcom_phy_counter_config);
+
+int qcom_phy_update_stats(struct phy_device *phydev,
+			  struct qcom_phy_hw_stats *hw_stats)
+{
+	int ret;
+	u32 cnt;
+
+	/* PHY 32-bit counter for RX packets. */
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_15_0);
+	if (ret < 0)
+		return ret;
+
+	cnt = ret;
+
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_31_16);
+	if (ret < 0)
+		return ret;
+
+	cnt |= ret << 16;
+	hw_stats->rx_pkts += cnt;
+
+	/* PHY 16-bit counter for RX CRC error packets. */
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_ERR_PKT);
+	if (ret < 0)
+		return ret;
+
+	hw_stats->rx_err_pkts += ret;
+
+	/* PHY 32-bit counter for TX packets. */
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_TX_PKT_15_0);
+	if (ret < 0)
+		return ret;
+
+	cnt = ret;
+
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_TX_PKT_31_16);
+	if (ret < 0)
+		return ret;
+
+	cnt |= ret << 16;
+	hw_stats->tx_pkts += cnt;
+
+	/* PHY 16-bit counter for TX CRC error packets. */
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_TX_ERR_PKT);
+	if (ret < 0)
+		return ret;
+
+	hw_stats->tx_err_pkts += ret;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(qcom_phy_update_stats);
+
+void qcom_phy_get_stats(struct ethtool_phy_stats *stats,
+			struct qcom_phy_hw_stats hw_stats)
+{
+	stats->tx_packets = hw_stats.tx_pkts;
+	stats->tx_errors = hw_stats.tx_err_pkts;
+	stats->rx_packets = hw_stats.rx_pkts;
+	stats->rx_errors = hw_stats.rx_err_pkts;
+}
+EXPORT_SYMBOL_GPL(qcom_phy_get_stats);
diff --git a/drivers/net/phy/qcom/qcom.h b/drivers/net/phy/qcom/qcom.h
index 7f7151c8baca..5071e7149a11 100644
--- a/drivers/net/phy/qcom/qcom.h
+++ b/drivers/net/phy/qcom/qcom.h
@@ -195,6 +195,17 @@
 #define AT803X_MIN_DOWNSHIFT			2
 #define AT803X_MAX_DOWNSHIFT			9
 
+#define QCA808X_MMD7_CNT_CTRL			0x8029
+#define QCA808X_MMD7_CNT_CTRL_READ_CLEAR_EN	BIT(1)
+#define QCA808X_MMD7_CNT_CTRL_CRC_CHECK_EN	BIT(0)
+
+#define QCA808X_MMD7_CNT_RX_PKT_31_16		0x802a
+#define QCA808X_MMD7_CNT_RX_PKT_15_0		0x802b
+#define QCA808X_MMD7_CNT_RX_ERR_PKT		0x802c
+#define QCA808X_MMD7_CNT_TX_PKT_31_16		0x802d
+#define QCA808X_MMD7_CNT_TX_PKT_15_0		0x802e
+#define QCA808X_MMD7_CNT_TX_ERR_PKT		0x802f
+
 enum stat_access_type {
 	PHY,
 	MMD
@@ -212,6 +223,13 @@ struct at803x_ss_mask {
 	u8 speed_shift;
 };
 
+struct qcom_phy_hw_stats {
+	u64 rx_pkts;
+	u64 rx_err_pkts;
+	u64 tx_pkts;
+	u64 tx_err_pkts;
+};
+
 int at803x_debug_reg_read(struct phy_device *phydev, u16 reg);
 int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
 			  u16 clear, u16 set);
@@ -246,3 +264,8 @@ int qca808x_led_reg_brightness_set(struct phy_device *phydev,
 int qca808x_led_reg_blink_set(struct phy_device *phydev, u16 reg,
 			      unsigned long *delay_on,
 			      unsigned long *delay_off);
+int qcom_phy_counter_config(struct phy_device *phydev);
+int qcom_phy_update_stats(struct phy_device *phydev,
+			  struct qcom_phy_hw_stats *hw_stats);
+void qcom_phy_get_stats(struct ethtool_phy_stats *stats,
+			struct qcom_phy_hw_stats hw_stats);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next v3 2/3] net: phy: qcom: qca808x: Support PHY counter
  2025-07-15 11:02 [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x Luo Jie
  2025-07-15 11:02 ` [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support Luo Jie
@ 2025-07-15 11:02 ` Luo Jie
  2025-07-15 11:02 ` [PATCH net-next v3 3/3] net: phy: qcom: qca807x: " Luo Jie
  2025-07-18  2:00 ` [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x patchwork-bot+netdevbpf
  3 siblings, 0 replies; 11+ messages in thread
From: Luo Jie @ 2025-07-15 11:02 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-arm-msm, linux-kernel, Luo Jie

Enable CRC checking for received and transmitted frames, and configure
counters to clear after being read within config_init() for accurate
counter recording. Additionally, add PHY counter operations and integrate
shared functions.

Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
---
 drivers/net/phy/qcom/qca808x.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/net/phy/qcom/qca808x.c b/drivers/net/phy/qcom/qca808x.c
index 6de16c0eaa08..8eb51b1a006c 100644
--- a/drivers/net/phy/qcom/qca808x.c
+++ b/drivers/net/phy/qcom/qca808x.c
@@ -93,6 +93,7 @@ MODULE_LICENSE("GPL");
 
 struct qca808x_priv {
 	int led_polarity_mode;
+	struct qcom_phy_hw_stats hw_stats;
 };
 
 static int qca808x_phy_fast_retrain_config(struct phy_device *phydev)
@@ -243,6 +244,10 @@ static int qca808x_config_init(struct phy_device *phydev)
 
 	qca808x_fill_possible_interfaces(phydev);
 
+	ret = qcom_phy_counter_config(phydev);
+	if (ret)
+		return ret;
+
 	/* Configure adc threshold as 100mv for the link 10M */
 	return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD,
 				     QCA808X_ADC_THRESHOLD_MASK,
@@ -622,6 +627,22 @@ static int qca808x_led_polarity_set(struct phy_device *phydev, int index,
 			      active_low ? 0 : QCA808X_LED_ACTIVE_HIGH);
 }
 
+static int qca808x_update_stats(struct phy_device *phydev)
+{
+	struct qca808x_priv *priv = phydev->priv;
+
+	return qcom_phy_update_stats(phydev, &priv->hw_stats);
+}
+
+static void qca808x_get_phy_stats(struct phy_device *phydev,
+				  struct ethtool_eth_phy_stats *eth_stats,
+				  struct ethtool_phy_stats *stats)
+{
+	struct qca808x_priv *priv = phydev->priv;
+
+	qcom_phy_get_stats(stats, priv->hw_stats);
+}
+
 static struct phy_driver qca808x_driver[] = {
 {
 	/* Qualcomm QCA8081 */
@@ -651,6 +672,8 @@ static struct phy_driver qca808x_driver[] = {
 	.led_hw_control_set	= qca808x_led_hw_control_set,
 	.led_hw_control_get	= qca808x_led_hw_control_get,
 	.led_polarity_set	= qca808x_led_polarity_set,
+	.update_stats		= qca808x_update_stats,
+	.get_phy_stats		= qca808x_get_phy_stats,
 }, };
 
 module_phy_driver(qca808x_driver);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next v3 3/3] net: phy: qcom: qca807x: Support PHY counter
  2025-07-15 11:02 [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x Luo Jie
  2025-07-15 11:02 ` [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support Luo Jie
  2025-07-15 11:02 ` [PATCH net-next v3 2/3] net: phy: qcom: qca808x: Support PHY counter Luo Jie
@ 2025-07-15 11:02 ` Luo Jie
  2025-07-18  2:00 ` [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x patchwork-bot+netdevbpf
  3 siblings, 0 replies; 11+ messages in thread
From: Luo Jie @ 2025-07-15 11:02 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-arm-msm, linux-kernel, Luo Jie

Within the QCA807X PHY operation's config_init() function, enable CRC
checking for received and transmitted frames and configure counter to
clear after being read to support counter recording. Additionally, add
support for PHY counter operations.

Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
---
 drivers/net/phy/qcom/qca807x.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/net/phy/qcom/qca807x.c b/drivers/net/phy/qcom/qca807x.c
index 6d10ef7e9a8a..291f052ea53c 100644
--- a/drivers/net/phy/qcom/qca807x.c
+++ b/drivers/net/phy/qcom/qca807x.c
@@ -124,6 +124,7 @@ struct qca807x_priv {
 	bool dac_full_amplitude;
 	bool dac_full_bias_current;
 	bool dac_disable_bias_current_tweak;
+	struct qcom_phy_hw_stats hw_stats;
 };
 
 static int qca807x_cable_test_start(struct phy_device *phydev)
@@ -768,6 +769,10 @@ static int qca807x_config_init(struct phy_device *phydev)
 			return ret;
 	}
 
+	ret = qcom_phy_counter_config(phydev);
+	if (ret)
+		return ret;
+
 	control_dac = phy_read_mmd(phydev, MDIO_MMD_AN,
 				   QCA807X_MMD7_1000BASE_T_POWER_SAVE_PER_CABLE_LENGTH);
 	control_dac &= ~QCA807X_CONTROL_DAC_MASK;
@@ -782,6 +787,22 @@ static int qca807x_config_init(struct phy_device *phydev)
 			     control_dac);
 }
 
+static int qca807x_update_stats(struct phy_device *phydev)
+{
+	struct qca807x_priv *priv = phydev->priv;
+
+	return qcom_phy_update_stats(phydev, &priv->hw_stats);
+}
+
+static void qca807x_get_phy_stats(struct phy_device *phydev,
+				  struct ethtool_eth_phy_stats *eth_stats,
+				  struct ethtool_phy_stats *stats)
+{
+	struct qca807x_priv *priv = phydev->priv;
+
+	qcom_phy_get_stats(stats, priv->hw_stats);
+}
+
 static struct phy_driver qca807x_drivers[] = {
 	{
 		PHY_ID_MATCH_EXACT(PHY_ID_QCA8072),
@@ -800,6 +821,8 @@ static struct phy_driver qca807x_drivers[] = {
 		.suspend	= genphy_suspend,
 		.cable_test_start	= qca807x_cable_test_start,
 		.cable_test_get_status	= qca808x_cable_test_get_status,
+		.update_stats		= qca807x_update_stats,
+		.get_phy_stats		= qca807x_get_phy_stats,
 	},
 	{
 		PHY_ID_MATCH_EXACT(PHY_ID_QCA8075),
@@ -823,6 +846,8 @@ static struct phy_driver qca807x_drivers[] = {
 		.led_hw_is_supported = qca807x_led_hw_is_supported,
 		.led_hw_control_set = qca807x_led_hw_control_set,
 		.led_hw_control_get = qca807x_led_hw_control_get,
+		.update_stats		= qca807x_update_stats,
+		.get_phy_stats		= qca807x_get_phy_stats,
 	},
 };
 module_phy_driver(qca807x_drivers);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support
  2025-07-15 11:02 ` [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support Luo Jie
@ 2025-07-15 16:11   ` Andrew Lunn
  2025-07-16 10:15     ` Luo Jie
  2025-07-17 13:38   ` Andrew Lunn
  1 sibling, 1 reply; 11+ messages in thread
From: Andrew Lunn @ 2025-07-15 16:11 UTC (permalink / raw)
  To: Luo Jie
  Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-arm-msm, linux-kernel

> +int qcom_phy_update_stats(struct phy_device *phydev,
> +			  struct qcom_phy_hw_stats *hw_stats)
> +{
> +	int ret;
> +	u32 cnt;
> +
> +	/* PHY 32-bit counter for RX packets. */
> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_15_0);
> +	if (ret < 0)
> +		return ret;
> +
> +	cnt = ret;
> +
> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_31_16);
> +	if (ret < 0)
> +		return ret;

Does reading QCA808X_MMD7_CNT_RX_PKT_15_0 cause
QCA808X_MMD7_CNT_RX_PKT_31_16 to latch?

Sometimes you need to read the high part, the low part, and then
reread the high part to ensure it has not incremented. But this is
only needed if the hardware does not latch.

	Andrew

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support
  2025-07-15 16:11   ` Andrew Lunn
@ 2025-07-16 10:15     ` Luo Jie
  2025-07-17 13:23       ` Paolo Abeni
  0 siblings, 1 reply; 11+ messages in thread
From: Luo Jie @ 2025-07-16 10:15 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-arm-msm, linux-kernel



On 7/16/2025 12:11 AM, Andrew Lunn wrote:
>> +int qcom_phy_update_stats(struct phy_device *phydev,
>> +			  struct qcom_phy_hw_stats *hw_stats)
>> +{
>> +	int ret;
>> +	u32 cnt;
>> +
>> +	/* PHY 32-bit counter for RX packets. */
>> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_15_0);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	cnt = ret;
>> +
>> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_31_16);
>> +	if (ret < 0)
>> +		return ret;
> 
> Does reading QCA808X_MMD7_CNT_RX_PKT_15_0 cause
> QCA808X_MMD7_CNT_RX_PKT_31_16 to latch?

Checked with the hardware design team: The high 16-bit counter register
does not latch when reading the low 16 bits.

> 
> Sometimes you need to read the high part, the low part, and then
> reread the high part to ensure it has not incremented. But this is
> only needed if the hardware does not latch.
> 
> 	Andrew

Since the counter is configured to clear after reading, the clear action
takes priority over latching the count. This means that when reading the
low 16 bits, the high 16-bit counter value cannot increment, any new
packet events occurring during the read will be recorded after the
16-bit counter is cleared.

Therefore, the current sequence for reading the counter is correct and
will not result in missed increments.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support
  2025-07-16 10:15     ` Luo Jie
@ 2025-07-17 13:23       ` Paolo Abeni
  2025-07-17 13:46         ` Andrew Lunn
  0 siblings, 1 reply; 11+ messages in thread
From: Paolo Abeni @ 2025-07-17 13:23 UTC (permalink / raw)
  To: Luo Jie, Andrew Lunn
  Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, netdev, linux-arm-msm, linux-kernel

On 7/16/25 12:15 PM, Luo Jie wrote:
> On 7/16/2025 12:11 AM, Andrew Lunn wrote:
>>> +int qcom_phy_update_stats(struct phy_device *phydev,
>>> +			  struct qcom_phy_hw_stats *hw_stats)
>>> +{
>>> +	int ret;
>>> +	u32 cnt;
>>> +
>>> +	/* PHY 32-bit counter for RX packets. */
>>> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_15_0);
>>> +	if (ret < 0)
>>> +		return ret;
>>> +
>>> +	cnt = ret;
>>> +
>>> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_31_16);
>>> +	if (ret < 0)
>>> +		return ret;
>>
>> Does reading QCA808X_MMD7_CNT_RX_PKT_15_0 cause
>> QCA808X_MMD7_CNT_RX_PKT_31_16 to latch?
> 
> Checked with the hardware design team: The high 16-bit counter register
> does not latch when reading the low 16 bits.
> 
>>
>> Sometimes you need to read the high part, the low part, and then
>> reread the high part to ensure it has not incremented. But this is
>> only needed if the hardware does not latch.
>>
>> 	Andrew
> 
> Since the counter is configured to clear after reading, the clear action
> takes priority over latching the count. This means that when reading the
> low 16 bits, the high 16-bit counter value cannot increment, any new
> packet events occurring during the read will be recorded after the
> 16-bit counter is cleared.

Out of sheer ignorance and language bias on my side, based on the above
I would have assumed that the registers do latch ;)

> Therefore, the current sequence for reading the counter is correct and
> will not result in missed increments.

Andrew, looks good?

/P


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support
  2025-07-15 11:02 ` [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support Luo Jie
  2025-07-15 16:11   ` Andrew Lunn
@ 2025-07-17 13:38   ` Andrew Lunn
  1 sibling, 0 replies; 11+ messages in thread
From: Andrew Lunn @ 2025-07-17 13:38 UTC (permalink / raw)
  To: Luo Jie
  Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-arm-msm, linux-kernel

On Tue, Jul 15, 2025 at 07:02:26PM +0800, Luo Jie wrote:
> Add PHY counter functionality to the shared library. The implementation
> is identical for the current QCA807X and QCA808X PHYs.
> 
> The PHY counter can be configured to perform CRC checking for both received
> and transmitted packets. Additionally, the packet counter can be set to
> automatically clear after it is read.
> 
> The PHY counter includes 32-bit packet counters for both RX (received) and
> TX (transmitted) packets, as well as 16-bit counters for recording CRC
> error packets for both RX and TX.
> 
> Signed-off-by: Luo Jie <quic_luoj@quicinc.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support
  2025-07-17 13:23       ` Paolo Abeni
@ 2025-07-17 13:46         ` Andrew Lunn
  2025-07-18 14:02           ` Luo Jie
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Lunn @ 2025-07-17 13:46 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Luo Jie, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, netdev, linux-arm-msm, linux-kernel

On Thu, Jul 17, 2025 at 03:23:16PM +0200, Paolo Abeni wrote:
> On 7/16/25 12:15 PM, Luo Jie wrote:
> > On 7/16/2025 12:11 AM, Andrew Lunn wrote:
> >>> +int qcom_phy_update_stats(struct phy_device *phydev,
> >>> +			  struct qcom_phy_hw_stats *hw_stats)
> >>> +{
> >>> +	int ret;
> >>> +	u32 cnt;
> >>> +
> >>> +	/* PHY 32-bit counter for RX packets. */
> >>> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_15_0);
> >>> +	if (ret < 0)
> >>> +		return ret;
> >>> +
> >>> +	cnt = ret;
> >>> +
> >>> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_31_16);
> >>> +	if (ret < 0)
> >>> +		return ret;
> >>
> >> Does reading QCA808X_MMD7_CNT_RX_PKT_15_0 cause
> >> QCA808X_MMD7_CNT_RX_PKT_31_16 to latch?
> > 
> > Checked with the hardware design team: The high 16-bit counter register
> > does not latch when reading the low 16 bits.
> > 
> >>
> >> Sometimes you need to read the high part, the low part, and then
> >> reread the high part to ensure it has not incremented. But this is
> >> only needed if the hardware does not latch.
> >>
> >> 	Andrew
> > 
> > Since the counter is configured to clear after reading, the clear action
> > takes priority over latching the count. This means that when reading the
> > low 16 bits, the high 16-bit counter value cannot increment, any new
> > packet events occurring during the read will be recorded after the
> > 16-bit counter is cleared.
> 
> Out of sheer ignorance and language bias on my side, based on the above
> I would have assumed that the registers do latch ;)

I interpret it differently. The register is set to clear on read. So
you read and clear the least significant word. Even if that word
starts incriminating, you have 65535 increments before it will
overflow into the next word. So you can read the most significant word
before such an overflow happens. It does not latch, you just have a
time window when it is safe.

What i actually find odd is that clear on read works on words, not the
full counter. I assume that is documented in the datasheet, and
tested, because i've never seen hardware do that before.

	Andrew

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x
  2025-07-15 11:02 [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x Luo Jie
                   ` (2 preceding siblings ...)
  2025-07-15 11:02 ` [PATCH net-next v3 3/3] net: phy: qcom: qca807x: " Luo Jie
@ 2025-07-18  2:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-07-18  2:00 UTC (permalink / raw)
  To: Luo Jie
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev,
	linux-arm-msm, linux-kernel

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 15 Jul 2025 19:02:25 +0800 you wrote:
> The implementation of the PHY counter is identical for both QCA808x and
> QCA807x series devices. This includes counters for both good and bad CRC
> frames in the RX and TX directions, which are active when CRC checking
> is enabled.
> 
> This patch series introduces PHY counter functions into a shared library,
> enabling counter support for the QCA808x and QCA807x families through this
> common infrastructure. Additionally, enable CRC checking and configure
> automatic clearing of counters after reading within config_init() to ensure
> accurate counter recording.
> 
> [...]

Here is the summary with links:
  - [net-next,v3,1/3] net: phy: qcom: Add PHY counter support
    https://git.kernel.org/netdev/net-next/c/22bf4bd8ec4f
  - [net-next,v3,2/3] net: phy: qcom: qca808x: Support PHY counter
    https://git.kernel.org/netdev/net-next/c/3370e33a1c23
  - [net-next,v3,3/3] net: phy: qcom: qca807x: Support PHY counter
    https://git.kernel.org/netdev/net-next/c/d98f43b84a1e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support
  2025-07-17 13:46         ` Andrew Lunn
@ 2025-07-18 14:02           ` Luo Jie
  0 siblings, 0 replies; 11+ messages in thread
From: Luo Jie @ 2025-07-18 14:02 UTC (permalink / raw)
  To: Andrew Lunn, Paolo Abeni
  Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, netdev, linux-arm-msm, linux-kernel



On 7/17/2025 9:46 PM, Andrew Lunn wrote:
> On Thu, Jul 17, 2025 at 03:23:16PM +0200, Paolo Abeni wrote:
>> On 7/16/25 12:15 PM, Luo Jie wrote:
>>> On 7/16/2025 12:11 AM, Andrew Lunn wrote:
>>>>> +int qcom_phy_update_stats(struct phy_device *phydev,
>>>>> +			  struct qcom_phy_hw_stats *hw_stats)
>>>>> +{
>>>>> +	int ret;
>>>>> +	u32 cnt;
>>>>> +
>>>>> +	/* PHY 32-bit counter for RX packets. */
>>>>> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_15_0);
>>>>> +	if (ret < 0)
>>>>> +		return ret;
>>>>> +
>>>>> +	cnt = ret;
>>>>> +
>>>>> +	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_CNT_RX_PKT_31_16);
>>>>> +	if (ret < 0)
>>>>> +		return ret;
>>>>
>>>> Does reading QCA808X_MMD7_CNT_RX_PKT_15_0 cause
>>>> QCA808X_MMD7_CNT_RX_PKT_31_16 to latch?
>>>
>>> Checked with the hardware design team: The high 16-bit counter register
>>> does not latch when reading the low 16 bits.
>>>
>>>>
>>>> Sometimes you need to read the high part, the low part, and then
>>>> reread the high part to ensure it has not incremented. But this is
>>>> only needed if the hardware does not latch.
>>>>
>>>> 	Andrew
>>>
>>> Since the counter is configured to clear after reading, the clear action
>>> takes priority over latching the count. This means that when reading the
>>> low 16 bits, the high 16-bit counter value cannot increment, any new
>>> packet events occurring during the read will be recorded after the
>>> 16-bit counter is cleared.
>>
>> Out of sheer ignorance and language bias on my side, based on the above
>> I would have assumed that the registers do latch ;)
> 
> I interpret it differently. The register is set to clear on read. So
> you read and clear the least significant word. Even if that word
> starts incriminating, you have 65535 increments before it will
> overflow into the next word. So you can read the most significant word
> before such an overflow happens. It does not latch, you just have a
> time window when it is safe.
> 
> What i actually find odd is that clear on read works on words, not the
> full counter. I assume that is documented in the datasheet, and
> tested, because i've never seen hardware do that before.
> 
> 	Andrew

Thank you for the review. The PHY counter functionality is also used in
the downstream code, and this patch series has been validated
accordingly. However, please note that the PHY counter is intended as a
debug feature and may not be documented in the datasheet. I will share
this feedback with the hardware team in the hope that we can include
documentation for this feature in the datasheet for future chips.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-07-18 14:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15 11:02 [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x Luo Jie
2025-07-15 11:02 ` [PATCH net-next v3 1/3] net: phy: qcom: Add PHY counter support Luo Jie
2025-07-15 16:11   ` Andrew Lunn
2025-07-16 10:15     ` Luo Jie
2025-07-17 13:23       ` Paolo Abeni
2025-07-17 13:46         ` Andrew Lunn
2025-07-18 14:02           ` Luo Jie
2025-07-17 13:38   ` Andrew Lunn
2025-07-15 11:02 ` [PATCH net-next v3 2/3] net: phy: qcom: qca808x: Support PHY counter Luo Jie
2025-07-15 11:02 ` [PATCH net-next v3 3/3] net: phy: qcom: qca807x: " Luo Jie
2025-07-18  2:00 ` [PATCH net-next v3 0/3] Add shared PHY counter support for QCA807x and QCA808x patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).