Skip to contentSkip to conversation

Enable SGMII and 2500BASEX interface mode switching for Intel platforms

PATCH Superseded Choong Yong Liang 4 participants 17 messages Feb 4, 2025 – Feb 6, 2025

Subsystems (11)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover Enable SGMII and 2500BASEX interface mode switching for Intel platforms

During the interface mode change, the 'phylink_major_config' function will be triggered in phylink. The modification of the following functions will support the switching between SGMII and 2500BASE-X interface modes for the Intel platform:

- xpcs_switch_interface_mode: Re-initiates clause 37 auto-negotiation for the SGMII interface mode to perform auto-negotiation.
- mac_finish: Configures the SerDes according to the interface mode.

With the above changes, the code will work as follows during the interface mode change. The PCS will reconfigure according to the pcs_neg_mode and the selected interface mode. Then, the MAC driver will perform SerDes configuration in 'mac_finish' based on the selected interface mode. During the SerDes configuration, the selected interface mode will identify TSN lane registers from FIA and then send IPC commands to the Power Management Controller (PMC) through the PMC driver/API. The PMC will act as a proxy to program the PLL registers.

Change log:
v1 -> v2:
- Add static to pmc_lpm_modes declaration
- Add cur_link_an_mode to the kernel doc
- Combine 2 commits i.e. "stmmac: intel: Separate driver_data of ADL-N from TGL" and "net: stmmac: Add 1G/2.5G auto-negotiation support for ADL-N" into 1 commit.

v2 -> v3:
- Create pmc_ipc.c file for intel_pmc_ipc() function and allocate the file in arch/x86/platform/intel/ directory.
- Update phylink's AN mode during phy interface change and not exposing phylink's AN mode into phylib.

v3 -> v4:
- Introduce allow_switch_interface flag to have all ethtool link modes that are supported and advertised will be published.
- Introduce mac_get_pcs_neg_mode function that selects the PCS negotiation mode according to the interface mode.
- Remove pcs-xpcs.c changes and handle pcs during mac_select_pcs function
- Configure SerDes base on the interface on mac_finish function.

v4 -> v5:
- remove 'allow_switch_interface' related patches.
- remove 'mac_select_pcs' related patches.
- add a soft reset according to XPCS datasheet for re-initiate Clause 37 auto-negotiation when switching to SGMII interface mode.

v5 -> v6:
- Remove 'mac_get_pcs_neg_mode' related patches.
The pcs_neg_mode is properly handled by the
'net: add negotiation of in-band capabilities' patch series:
https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
- Using act_link_an_mode to determine PHY, as cfg_link_an_mode was not updated for the 2500BASE-X interface mode, caused a failure to link up.
- Clean up and standardize the interface mode switch for xpcs.

v1: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
v2: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
v3: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
v4: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
v5: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/

Choong Yong Liang (6):
net: phylink: use act_link_an_mode to determine PHY
net: pcs: xpcs: re-initiate clause 37 Auto-negotiation
stmmac: intel: configure SerDes according to the interface mode
net: stmmac: configure SerDes on mac_finish
stmmac: intel: interface switching support for EHL platform
stmmac: intel: interface switching support for ADL-N platform

David E. Box (1):
arch: x86: add IPC mailbox accessor function and add SoC register
access

 MAINTAINERS                                   |   2 +
 arch/x86/Kconfig                              |   9 +
 arch/x86/platform/intel/Makefile              |   1 +
 arch/x86/platform/intel/pmc_ipc.c             |  75 ++++++++
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |   2 +
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 173 +++++++++++++++++-
 .../net/ethernet/stmicro/stmmac/dwmac-intel.h |  81 ++++++++
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  13 ++
 drivers/net/pcs/pcs-xpcs-wx.c                 |   4 +-
 drivers/net/pcs/pcs-xpcs.c                    |  60 +++++-
 drivers/net/phy/phylink.c                     |  10 +-
 .../linux/platform_data/x86/intel_pmc_ipc.h   |  34 ++++
 include/linux/stmmac.h                        |   3 +
 13 files changed, 450 insertions(+), 17 deletions(-)
 create mode 100644 arch/x86/platform/intel/pmc_ipc.c
 create mode 100644 include/linux/platform_data/x86/intel_pmc_ipc.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 1/7 net: phylink: use act_link_an_mode to determine PHY

When the interface mode is SGMII and act_link_an_mode is MLO_AN_INBAND, switching to the 2500BASE-X interface mode will trigger phylink_major_config, and act_link_an_mode will be updated to MLO_AN_PHY in phylink_pcs_neg_mode when the PCS does not support in-band mode. The MAC and PCS will configure according to the interface mode and act_link_an_mode.

However, when the interface goes link down and then link up again, the MAC will attempt to attach the PHY. The interface mode remains as 2500BASE-X, but cfg_link_an_mode still holds MLO_AN_INBAND. This causes a failure to attach the PHY.

This patch uses act_link_an_mode to determine if there is a PHY to attach.

---
 drivers/net/phy/phylink.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/phy/phylink.c +6 -4
index 214b62fba991..b0f9725e0494 100644
@@ -1903,6 +1903,7 @@ int phylink_set_fixed_link(struct phylink *pl,
 
 	pl->cfg_link_an_mode = MLO_AN_FIXED;
 	pl->req_link_an_mode = pl->cfg_link_an_mode;
+	pl->act_link_an_mode = pl->cfg_link_an_mode;
 
 	return 0;
 }
@@ -2002,6 +2003,7 @@ struct phylink *phylink_create(struct phylink_config *config,
 	}
 
 	pl->req_link_an_mode = pl->cfg_link_an_mode;
+	pl->act_link_an_mode = pl->cfg_link_an_mode;
 
 	ret = phylink_register_sfp(pl, fwnode);
 	if (ret < 0) {
@@ -2044,8 +2046,8 @@ EXPORT_SYMBOL_GPL(phylink_destroy);
  */
 bool phylink_expects_phy(struct phylink *pl)
 {
-	if (pl->cfg_link_an_mode == MLO_AN_FIXED ||
-	    (pl->cfg_link_an_mode == MLO_AN_INBAND &&
+	if (pl->act_link_an_mode == MLO_AN_FIXED ||
+	    (pl->act_link_an_mode == MLO_AN_INBAND &&
 	     phy_interface_mode_is_8023z(pl->link_config.interface)))
 		return false;
 	return true;
@@ -2280,8 +2282,8 @@ static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy,
 {
 	u32 flags = 0;
 
-	if (WARN_ON(pl->cfg_link_an_mode == MLO_AN_FIXED ||
-		    (pl->cfg_link_an_mode == MLO_AN_INBAND &&
+	if (WARN_ON(pl->act_link_an_mode == MLO_AN_FIXED ||
+		    (pl->act_link_an_mode == MLO_AN_INBAND &&
 		     phy_interface_mode_is_8023z(interface) && !pl->sfp_bus)))
 		return -EINVAL;
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH net-next v6 1/7] net: phylink: use act_link_an_mode to determine PHY

Quoted 6 lines · Choong Yong Liang

When the interface mode is SGMII and act_link_an_mode is MLO_AN_INBAND, switching to the 2500BASE-X interface mode will trigger phylink_major_config, and act_link_an_mode will be updated to MLO_AN_PHY in phylink_pcs_neg_mode when the PCS does not support in-band mode. The MAC and PCS will configure according to the interface mode and act_link_an_mode.

act_link_an_mode must only ever be updated by phylink_major_config() since it defines state for the currently configured mode, and must stay in sync with how the hardware has been programmed at all times.

Quoted 2 lines

However, when the interface goes link down and then link up again, the MAC will attempt to attach the PHY.

Why is the MAC trying to disconnect and reconnect the PHY on link changes? Do you really mean "link down" and "link up" as in "connection with the link partner" or do you mean administratively taking the interface down and up (which is a completely different thing.)

Quoted 3 lines

The interface mode remains as 2500BASE-X,
but cfg_link_an_mode still holds MLO_AN_INBAND. This causes a failure to attach the PHY.

Hmm.

pl->link_interface is the configured setting from firmware etc and doesn't change.

pl->cfg_link_an_mode is the configured mode from firmware etc which was passed to phylink_create(), and again doesn't change.

So there should be no difference unless something weird is going on, which as you're talking about stmmac, could be the case.

More information needed, but as this patch currently stands, I deem it to be incorrect, sorry.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#3 lore raw

Re: [PATCH net-next v6 1/7] net: phylink: use act_link_an_mode to determine PHY

Quoted 12 lines · Russell King (Oracle)
Quoted 6 lines · Choong Yong Liang

When the interface mode is SGMII and act_link_an_mode is MLO_AN_INBAND, switching to the 2500BASE-X interface mode will trigger phylink_major_config, and act_link_an_mode will be updated to MLO_AN_PHY in phylink_pcs_neg_mode when the PCS does not support in-band mode. The MAC and PCS will configure according to the interface mode and act_link_an_mode.

act_link_an_mode must only ever be updated by phylink_major_config() since it defines state for the currently configured mode, and must stay in sync with how the hardware has been programmed at all times.

Quoted 8 lines
Quoted 2 lines

However, when the interface goes link down and then link up again, the MAC will attempt to attach the PHY.

Why is the MAC trying to disconnect and reconnect the PHY on link changes? Do you really mean "link down" and "link up" as in "connection with the link partner" or do you mean administratively taking the interface down and up (which is a completely different thing.)

The "link down" and "link up" I mention in this part refer to using the command:
ifconfig <interface> down/up

Quoted 6 lines
Quoted 3 lines

The interface mode remains as 2500BASE-X,
but cfg_link_an_mode still holds MLO_AN_INBAND. This causes a failure to attach the PHY.

Hmm.

Quoted 9 lines

pl->link_interface is the configured setting from firmware etc and doesn't change.

pl->cfg_link_an_mode is the configured mode from firmware etc which was passed to phylink_create(), and again doesn't change.

So there should be no difference unless something weird is going on, which as you're talking about stmmac, could be the case.

Thank you for pointing that out.

I think I was confused between pl->link_interface and pl->link_config.interface. The function phylink_attach_phy() uses pl->link_interface, whereas phylink_expects_phy() uses pl->link_config.interface.

When the interface switches from SGMII to 2500BASE-X,
pl->link_config.interface is updated by phylink_major_config().
So, when the STMMAC link goes down and comes up again,
it is blocked by phylink_expects_phy().
At this point, pl->cfg_link_an_mode is MLO_AN_INBAND and pl->link_config.interface is 2500BASE-X.

Since phylink_expects_phy() is trying to achieve the same checking condition as phylink_attach_phy(), it should use pl->link_interface for the check as well.

Does that make sense to you?

Quoted 3 lines

More information needed, but as this patch currently stands, I deem it to be incorrect, sorry.

#4 lore raw

PATCH v6 2/7 net: pcs: xpcs: re-initiate clause 37 Auto-negotiation

In reply to Choong Yong Liang

The xpcs_switch_interface_mode function was introduced to handle interface switching.

According to the XPCS datasheet, a soft reset is required to initiate Clause 37 auto-negotiation when the XPCS switches interface modes.

When the interface mode is set to 2500BASE-X, Clause 37 auto-negotiation is turned off.

Subsequently, when the interface mode switches from 2500BASE-X to SGMII, re-initiating Clause 37 auto-negotiation is required for the SGMII interface mode to function properly.

---
 drivers/net/pcs/pcs-xpcs-wx.c |  4 +--
 drivers/net/pcs/pcs-xpcs.c    | 60 ++++++++++++++++++++++++++++++++---
 2 files changed, 57 insertions(+), 7 deletions(-)
drivers/net/pcs/pcs-xpcs-wx.c +1 -3
index fc52f7aa5f59..f73ab04d09f0 100644
@@ -172,11 +172,9 @@ int txgbe_xpcs_switch_mode(struct dw_xpcs *xpcs, phy_interface_t interface)
 		return 0;
 	}
 
-	if (xpcs->interface == interface && !txgbe_xpcs_mode_quirk(xpcs))
+	if (!txgbe_xpcs_mode_quirk(xpcs))
 		return 0;
 
-	xpcs->interface = interface;
-
 	ret = txgbe_pcs_poll_power_up(xpcs);
 	if (ret < 0)
 		return ret;
drivers/net/pcs/pcs-xpcs.c +56 -4

73 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

PATCH v6 3/7 arch: x86: add IPC mailbox accessor function and add SoC register access

In reply to Choong Yong Liang

From: "David E. Box" <[email protected]>

- Exports intel_pmc_ipc() for host access to the PMC IPC mailbox
- Add support to use IPC command allows host to access SoC registers through PMC firmware that are otherwise inaccessible to the host due to security policies.

---
 MAINTAINERS                                   |  2 +
 arch/x86/Kconfig                              |  9 +++
 arch/x86/platform/intel/Makefile              |  1 +
 arch/x86/platform/intel/pmc_ipc.c             | 75 +++++++++++++++++++
 .../linux/platform_data/x86/intel_pmc_ipc.h   | 34 +++++++++
 5 files changed, 121 insertions(+)
 create mode 100644 arch/x86/platform/intel/pmc_ipc.c
 create mode 100644 include/linux/platform_data/x86/intel_pmc_ipc.h
MAINTAINERS +2 -0
index d1086e53a317..7a0681f83449 100644
@@ -11862,8 +11862,10 @@ M:	Rajneesh Bhardwaj <[email protected]>
 M:	David E Box <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	arch/x86/platform/intel/pmc_ipc.c
 F:	Documentation/ABI/testing/sysfs-platform-intel-pmc
 F:	drivers/platform/x86/intel/pmc/
+F:	linux/platform_data/x86/intel_pmc_ipc.h
 
 INTEL PMIC GPIO DRIVERS
 M:	Andy Shevchenko <[email protected]>
arch/x86/Kconfig +9 -0
index 87198d957e2f..631c1f10776c 100644
@@ -688,6 +688,15 @@ config X86_AMD_PLATFORM_DEVICE
 	  I2C and UART depend on COMMON_CLK to set clock. GPIO driver is
 	  implemented under PINCTRL subsystem.
 
+config INTEL_PMC_IPC
+	tristate "Intel Core SoC Power Management Controller IPC mailbox"
+	depends on ACPI
+	help
+	  This option enables sideband register access support for Intel SoC
+	  power management controller IPC mailbox.
+
+	  If you don't require the option or are in doubt, say N.
+
 config IOSF_MBI
 	tristate "Intel SoC IOSF Sideband support for SoC platforms"
 	depends on PCI
arch/x86/platform/intel/Makefile +1 -0
index dbee3b00f9d0..2f1805556d0c 100644
@@ -1,2 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_IOSF_MBI)			+= iosf_mbi.o
+obj-$(CONFIG_INTEL_PMC_IPC)		+= pmc_ipc.o
arch/x86/platform/intel/pmc_ipc.c new file +75 -0

75 lines not on this page · raw message

include/linux/platform_data/x86/intel_pmc_ipc.h new file +34 -0
new file mode 100644
index 000000000000..d47b89f873fc
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Intel Core SoC Power Management Controller Header File
+ *
+ * Copyright (c) 2023, Intel Corporation.
+ * All Rights Reserved.
+ *
+ * Authors: Choong Yong Liang <[email protected]>
+ *          David E. Box <[email protected]>
+ */
+#ifndef INTEL_PMC_IPC_H
+#define INTEL_PMC_IPC_H
+
+#define IPC_SOC_REGISTER_ACCESS			0xAA
+#define IPC_SOC_SUB_CMD_READ			0x00
+#define IPC_SOC_SUB_CMD_WRITE			0x01
+
+struct pmc_ipc_cmd {
+	u32 cmd;
+	u32 sub_cmd;
+	u32 size;
+	u32 wbuf[4];
+};
+
+/**
+ * intel_pmc_ipc() - PMC IPC Mailbox accessor
+ * @ipc_cmd:  struct pmc_ipc_cmd prepared with input to send
+ * @rbuf:     Allocated u32[4] array for returned IPC data
+ *
+ * Return: 0 on success. Non-zero on mailbox error
+ */
+int intel_pmc_ipc(struct pmc_ipc_cmd *ipc_cmd, u32 *rbuf);
+
+#endif /* INTEL_PMC_IPC_H */
Signature · 1 line
2.34.1
#6 lore raw

PATCH v6 4/7 stmmac: intel: configure SerDes according to the interface mode

In reply to Choong Yong Liang

Intel platform will configure the SerDes through PMC api based on the provided interface mode.

This patch adds several new functions below:-
- intel_tsn_lane_is_available(): This new function reads FIA lane ownership registers and common lane registers through IPC commands to know which lane the mGbE port is assigned to.
- intel_config_serdes(): To configure the SerDes based on the assigned lane and latest interface mode, it sends IPC command to the PMC through PMC driver/API. The PMC acts as a proxy for R/W on behalf of the driver.
- intel_set_reg_access(): Set the register access to the available TSN interface.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |   2 +
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 107 +++++++++++++++++-
 .../net/ethernet/stmicro/stmmac/dwmac-intel.h |  75 ++++++++++++
 include/linux/stmmac.h                        |   3 +
 4 files changed, 185 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/Kconfig +2 -0
index 4cc85a36a1ab..25154b915b02 100644
@@ -307,6 +307,8 @@ config DWMAC_INTEL
 	default X86
 	depends on X86 && STMMAC_ETH && PCI
 	depends on COMMON_CLK
+	depends on ACPI
+	select INTEL_PMC_IPC
 	help
 	  This selects the Intel platform specific bus support for the
 	  stmmac driver. This driver is used for Intel Quark/EHL/TGL.
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +105 -2

149 lines not on this page · raw message

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.h +75 -0

79 lines not on this page · raw message

include/linux/stmmac.h +3 -0
index c9878a612e53..dcfa5f423d1c 100644
@@ -236,6 +236,9 @@ struct plat_stmmacenet_data {
 	int (*serdes_powerup)(struct net_device *ndev, void *priv);
 	void (*serdes_powerdown)(struct net_device *ndev, void *priv);
 	void (*speed_mode_2500)(struct net_device *ndev, void *priv);
+	int (*config_serdes)(struct net_device *ndev,
+			     void *priv,
+			     phy_interface_t interface);
 	void (*ptp_clk_freq_config)(struct stmmac_priv *priv);
 	int (*init)(struct platform_device *pdev, void *priv);
 	void (*exit)(struct platform_device *pdev, void *priv);
Signature · 1 line
2.34.1
maintainer
#7 lore raw

Re: [PATCH net-next v6 4/7] stmmac: intel: configure SerDes according to the interface mode

Quoted 1 line · Choong Yong Liang

Intel platform will configure the SerDes through PMC api based on the

API

Quoted 67 lines

provided interface mode.

This patch adds several new functions below:-
- intel_tsn_lane_is_available(): This new function reads FIA lane ownership registers and common lane registers through IPC commands to know which lane the mGbE port is assigned to.
- intel_config_serdes(): To configure the SerDes based on the assigned lane and latest interface mode, it sends IPC command to the PMC through PMC driver/API. The PMC acts as a proxy for R/W on behalf of the driver.
- intel_set_reg_access(): Set the register access to the available TSN interface.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |   2 +
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 107 +++++++++++++++++-
 .../net/ethernet/stmicro/stmmac/dwmac-intel.h |  75 ++++++++++++
 include/linux/stmmac.h                        |   3 +
 4 files changed, 185 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/Kconfig +2 -0
index 4cc85a36a1ab..25154b915b02 100644
@@ -307,6 +307,8 @@ config DWMAC_INTEL
 	default X86
 	depends on X86 && STMMAC_ETH && PCI
 	depends on COMMON_CLK
+	depends on ACPI
+	select INTEL_PMC_IPC
 	help
 	  This selects the Intel platform specific bus support for the
 	  stmmac driver. This driver is used for Intel Quark/EHL/TGL.
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +5 -1
index 48acba5eb178..347dd75bcdcd 100644
@@ -5,6 +5,7 @@
 #include <linux/clk-provider.h>
 #include <linux/pci.h>
 #include <linux/dmi.h>
+#include <linux/platform_data/x86/intel_pmc_ipc.h>
 #include "dwmac-intel.h"
 #include "dwmac4.h"
 #include "stmmac.h"
@@ -14,6 +15,9 @@ struct intel_priv_data {
 	int mdio_adhoc_addr;	/* mdio address for serdes & etc */
 	unsigned long crossts_adj;
 	bool is_pse;
+	const int *tsn_lane_registers;
+	int max_tsn_lane_registers;
+	int pid_modphy;
 };
 
 /* This struct is used to associate PCI Function of MAC controller on a board,
@@ -93,7 +97,7 @@ static int intel_serdes_powerup(struct net_device *ndev, void *priv_data)
 	data &= ~SERDES_RATE_MASK;
 	data &= ~SERDES_PCLK_MASK;
 
-	if (priv->plat->max_speed == 2500)
+	if (priv->plat->phy_interface == PHY_INTERFACE_MODE_2500BASEX)
 		data |= SERDES_RATE_PCIE_GEN2 << SERDES_RATE_PCIE_SHIFT |
 			SERDES_PCLK_37p5MHZ << SERDES_PCLK_SHIFT;
 	else
@@ -415,6 +419,103 @@ static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv,
 	}
 }

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv, · line 430

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +9 -0
 
+static bool intel_tsn_lane_is_available(struct net_device *ndev,
+					struct intel_priv_data *intel_priv)
+{
+	struct stmmac_priv *priv = netdev_priv(ndev);
+	struct pmc_ipc_cmd tmp = {0};
+	u32 rbuf[4] = {0};
+	int ret, i, j;
+
+	if (priv->plat->serdes_powerup) {

The logic could be reversed + return immediately to reduce the indentation of the block below.

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv, · line 434

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +4 -0
+		tmp.cmd = IPC_SOC_REGISTER_ACCESS;
+		tmp.sub_cmd = IPC_SOC_SUB_CMD_READ;
+
+		for (i = 0; i < 5; i++) {

Name the magic 5 with a define?

Quoted 16 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +16 -0
+			tmp.wbuf[0] = R_PCH_FIA_15_PCR_LOS1_REG_BASE + i;
+
+			ret = intel_pmc_ipc(&tmp, rbuf);
+			if (ret < 0) {
+				netdev_info(priv->dev,
+					    "Failed to read from PMC.\n");
+				return false;
+			}
+
+			for (j = 0; j <= intel_priv->max_tsn_lane_registers; j++)
+				if ((rbuf[0] >>
+				    (4 * (intel_priv->tsn_lane_registers[j] % 8)) &
+				     B_PCH_FIA_PCR_L0O) == 0xB)
+					return true;
+		}
+	}

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv, · line 460

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +10 -0
+	return false;
+}
+
+static int intel_set_reg_access(const struct pmc_serdes_regs *regs, int max_regs)
+{
+	int ret = 0, i;
+
+	for (i = 0; i < max_regs; i++) {
+		struct pmc_ipc_cmd tmp = {0};
+		u32 buf[4] = {0};

If you just want to have them initialized, it's enough to use {}, no dummy 0 is necessary.

Quoted 35 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +35 -0
+
+		tmp.cmd = IPC_SOC_REGISTER_ACCESS;
+		tmp.sub_cmd = IPC_SOC_SUB_CMD_WRITE;
+		tmp.wbuf[0] = (u32)regs[i].index;
+		tmp.wbuf[1] = regs[i].val;
+
+		ret = intel_pmc_ipc(&tmp, buf);
+		if (ret < 0)
+			return ret;
+	}
+
+	return ret;
+}
+
+static int intel_config_serdes(struct net_device *ndev,
+			       void *intel_data,
+			       phy_interface_t interface)
+{
+	struct intel_priv_data *intel_priv = intel_data;
+	struct stmmac_priv *priv = netdev_priv(ndev);
+	int ret = 0;
+
+	if (!intel_tsn_lane_is_available(ndev, intel_priv)) {
+		netdev_info(priv->dev,
+			    "No TSN lane available to set the registers.\n");
+		goto pmc_read_error;
+	}
+
+	if (intel_priv->pid_modphy == PID_MODPHY1) {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX) {
+			ret = intel_set_reg_access(pid_modphy1_2p5g_regs,
+						   ARRAY_SIZE(pid_modphy1_2p5g_regs));
+		} else {
+			ret = intel_set_reg_access(pid_modphy1_1g_regs,
+						   ARRAY_SIZE(pid_modphy1_1g_regs));

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv, · line 505

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +10 -0
+		}
+	} else {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX) {
+			ret = intel_set_reg_access(pid_modphy3_2p5g_regs,
+						   ARRAY_SIZE(pid_modphy3_2p5g_regs));
+		} else {
+			ret = intel_set_reg_access(pid_modphy3_1g_regs,
+						   ARRAY_SIZE(pid_modphy3_1g_regs));
+		}
+	}

This looks somewhat ugly. Perhaps it would be better if you make the call on main level of the function and use local variables to hold the regs array and its number of elements until then.

It would be even better if you could just store the pointer and # of elements into some platform info structure so that it wouldn't need to be calculated on the fly here (but I don't know this driver well enough to know if that's viable/easy to do).

Quoted 111 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +15 -1
+	priv->plat->phy_interface = interface;
+
+	if (ret < 0)
+		goto pmc_read_error;
+
+pmc_read_error:
+	intel_serdes_powerdown(ndev, intel_priv);
+	intel_serdes_powerup(ndev, intel_priv);
+
+	return ret;
+}
+
 static void common_default_data(struct plat_stmmacenet_data *plat)
 {
 	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
@@ -650,7 +751,7 @@ static int ehl_sgmii_data(struct pci_dev *pdev,
 	plat->speed_mode_2500 = intel_speed_mode_2500;
 	plat->serdes_powerup = intel_serdes_powerup;
 	plat->serdes_powerdown = intel_serdes_powerdown;
-
+	plat->config_serdes = intel_config_serdes;
 	plat->clk_ptp_rate = 204800000;
 
 	return ehl_common_data(pdev, plat);
@@ -709,6 +810,7 @@ static int ehl_pse0_sgmii1g_data(struct pci_dev *pdev,
 	plat->speed_mode_2500 = intel_speed_mode_2500;
 	plat->serdes_powerup = intel_serdes_powerup;
 	plat->serdes_powerdown = intel_serdes_powerdown;
+	plat->config_serdes = intel_config_serdes;
 	return ehl_pse0_common_data(pdev, plat);
 }
 
@@ -750,6 +852,7 @@ static int ehl_pse1_sgmii1g_data(struct pci_dev *pdev,
 	plat->speed_mode_2500 = intel_speed_mode_2500;
 	plat->serdes_powerup = intel_serdes_powerup;
 	plat->serdes_powerdown = intel_serdes_powerdown;
+	plat->config_serdes = intel_config_serdes;
 	return ehl_pse1_common_data(pdev, plat);
 }
 
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.h +63 -0
index 0a37987478c1..79c35ba969ea 100644
@@ -50,4 +50,79 @@
 #define PCH_PTP_CLK_FREQ_19_2MHZ	(GMAC_GPO0)
 #define PCH_PTP_CLK_FREQ_200MHZ		(0)
 
+#define	PID_MODPHY1 0xAA
+#define	PID_MODPHY3 0xA8
+
+#if IS_ENABLED(CONFIG_INTEL_PMC_IPC)
+struct pmc_serdes_regs {
+	u8 index;
+	u32 val;
+};
+
+/* Modphy Register index */
+#define R_PCH_FIA_15_PCR_LOS1_REG_BASE			8
+#define R_PCH_FIA_15_PCR_LOS2_REG_BASE			9
+#define R_PCH_FIA_15_PCR_LOS3_REG_BASE			10
+#define R_PCH_FIA_15_PCR_LOS4_REG_BASE			11
+#define R_PCH_FIA_15_PCR_LOS5_REG_BASE			12
+#define B_PCH_FIA_PCR_L0O				GENMASK(3, 0)
+#define PID_MODPHY1_B_MODPHY_PCR_LCPLL_DWORD0		13
+#define PID_MODPHY1_N_MODPHY_PCR_LCPLL_DWORD2		14
+#define PID_MODPHY1_N_MODPHY_PCR_LCPLL_DWORD7		15
+#define PID_MODPHY1_N_MODPHY_PCR_LPPLL_DWORD10		16
+#define PID_MODPHY1_N_MODPHY_PCR_CMN_ANA_DWORD30	17
+#define PID_MODPHY3_B_MODPHY_PCR_LCPLL_DWORD0		18
+#define PID_MODPHY3_N_MODPHY_PCR_LCPLL_DWORD2		19
+#define PID_MODPHY3_N_MODPHY_PCR_LCPLL_DWORD7		20
+#define PID_MODPHY3_N_MODPHY_PCR_LPPLL_DWORD10		21
+#define PID_MODPHY3_N_MODPHY_PCR_CMN_ANA_DWORD30	22
+
+#define B_MODPHY_PCR_LCPLL_DWORD0_1G		0x46AAAA41
+#define N_MODPHY_PCR_LCPLL_DWORD2_1G		0x00000139
+#define N_MODPHY_PCR_LCPLL_DWORD7_1G		0x002A0003
+#define N_MODPHY_PCR_LPPLL_DWORD10_1G		0x00170008
+#define N_MODPHY_PCR_CMN_ANA_DWORD30_1G		0x0000D4AC
+#define B_MODPHY_PCR_LCPLL_DWORD0_2P5G		0x58555551
+#define N_MODPHY_PCR_LCPLL_DWORD2_2P5G		0x0000012D
+#define N_MODPHY_PCR_LCPLL_DWORD7_2P5G		0x001F0003
+#define N_MODPHY_PCR_LPPLL_DWORD10_2P5G		0x00170008
+#define N_MODPHY_PCR_CMN_ANA_DWORD30_2P5G	0x8200ACAC
+
+static const struct pmc_serdes_regs pid_modphy3_1g_regs[] = {
+	{ PID_MODPHY3_B_MODPHY_PCR_LCPLL_DWORD0,	B_MODPHY_PCR_LCPLL_DWORD0_1G },
+	{ PID_MODPHY3_N_MODPHY_PCR_LCPLL_DWORD2,	N_MODPHY_PCR_LCPLL_DWORD2_1G },
+	{ PID_MODPHY3_N_MODPHY_PCR_LCPLL_DWORD7,	N_MODPHY_PCR_LCPLL_DWORD7_1G },
+	{ PID_MODPHY3_N_MODPHY_PCR_LPPLL_DWORD10,	N_MODPHY_PCR_LPPLL_DWORD10_1G },
+	{ PID_MODPHY3_N_MODPHY_PCR_CMN_ANA_DWORD30,	N_MODPHY_PCR_CMN_ANA_DWORD30_1G },
+	{}
+};
+
+static const struct pmc_serdes_regs pid_modphy3_2p5g_regs[] = {
+	{ PID_MODPHY3_B_MODPHY_PCR_LCPLL_DWORD0,	B_MODPHY_PCR_LCPLL_DWORD0_2P5G },
+	{ PID_MODPHY3_N_MODPHY_PCR_LCPLL_DWORD2,	N_MODPHY_PCR_LCPLL_DWORD2_2P5G },
+	{ PID_MODPHY3_N_MODPHY_PCR_LCPLL_DWORD7,	N_MODPHY_PCR_LCPLL_DWORD7_2P5G },
+	{ PID_MODPHY3_N_MODPHY_PCR_LPPLL_DWORD10,	N_MODPHY_PCR_LPPLL_DWORD10_2P5G },
+	{ PID_MODPHY3_N_MODPHY_PCR_CMN_ANA_DWORD30,	N_MODPHY_PCR_CMN_ANA_DWORD30_2P5G },
+	{}
+};
+
+static const struct pmc_serdes_regs pid_modphy1_1g_regs[] = {
+	{ PID_MODPHY1_B_MODPHY_PCR_LCPLL_DWORD0,	B_MODPHY_PCR_LCPLL_DWORD0_1G },
+	{ PID_MODPHY1_N_MODPHY_PCR_LCPLL_DWORD2,	N_MODPHY_PCR_LCPLL_DWORD2_1G },
+	{ PID_MODPHY1_N_MODPHY_PCR_LCPLL_DWORD7,	N_MODPHY_PCR_LCPLL_DWORD7_1G },
+	{ PID_MODPHY1_N_MODPHY_PCR_LPPLL_DWORD10,	N_MODPHY_PCR_LPPLL_DWORD10_1G },
+	{ PID_MODPHY1_N_MODPHY_PCR_CMN_ANA_DWORD30,	N_MODPHY_PCR_CMN_ANA_DWORD30_1G },
+	{}

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.h line 125

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.h +10 -0
+};
+
+static const struct pmc_serdes_regs pid_modphy1_2p5g_regs[] = {
+	{ PID_MODPHY1_B_MODPHY_PCR_LCPLL_DWORD0,	B_MODPHY_PCR_LCPLL_DWORD0_2P5G },
+	{ PID_MODPHY1_N_MODPHY_PCR_LCPLL_DWORD2,	N_MODPHY_PCR_LCPLL_DWORD2_2P5G },
+	{ PID_MODPHY1_N_MODPHY_PCR_LCPLL_DWORD7,	N_MODPHY_PCR_LCPLL_DWORD7_2P5G },
+	{ PID_MODPHY1_N_MODPHY_PCR_LPPLL_DWORD10,	N_MODPHY_PCR_LPPLL_DWORD10_2P5G },
+	{ PID_MODPHY1_N_MODPHY_PCR_CMN_ANA_DWORD30,	N_MODPHY_PCR_CMN_ANA_DWORD30_2P5G },
+	{}
+};

Why are these arrays in a header and not in the C file that uses them???

Quoted 18 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.h +2 -0
+#endif /* CONFIG_INTEL_PMC_IPC */
+
 #endif /* __DWMAC_INTEL_H__ */
include/linux/stmmac.h +3 -0
index c9878a612e53..dcfa5f423d1c 100644
@@ -236,6 +236,9 @@ struct plat_stmmacenet_data {
 	int (*serdes_powerup)(struct net_device *ndev, void *priv);
 	void (*serdes_powerdown)(struct net_device *ndev, void *priv);
 	void (*speed_mode_2500)(struct net_device *ndev, void *priv);
+	int (*config_serdes)(struct net_device *ndev,
+			     void *priv,
+			     phy_interface_t interface);
 	void (*ptp_clk_freq_config)(struct stmmac_priv *priv);
 	int (*init)(struct platform_device *pdev, void *priv);
 	void (*exit)(struct platform_device *pdev, void *priv);
Signature · 1 line
 i.
#8 lore raw

Re: [PATCH net-next v6 4/7] stmmac: intel: configure SerDes according to the interface mode

Quoted 12 lines · Ilpo Järvinen

On Tue, 4 Feb 2025, Choong Yong Liang wrote:

The logic could be reversed + return immediately to reduce the indentation of the block below.

If you just want to have them initialized, it's enough to use {}, no dummy 0 is necessary.

This looks somewhat ugly. Perhaps it would be better if you make the call on main level of the function and use local variables to hold the regs array and its number of elements until then.

Quoted 7 lines

It would be even better if you could just store the pointer and # of elements into some platform info structure so that it wouldn't need to be calculated on the fly here (but I don't know this driver well enough to know if that's viable/easy to do).

Why are these arrays in a header and not in the C file that uses them???

Hi Ilpo,

Thank you for your detailed review and comments on the patch.

I'll reverse the logic in intel_tsn_lane_is_available, define the magic number, initialize arrays with {}, refactor intel_config_serdes, and move the arrays to the C file.

#9 lore raw

Re: [PATCH net-next v6 4/7] stmmac: intel: configure SerDes according to the interface mode

In reply to Choong Yong Liang

include/linux/stmmac.h struct plat_stmmacenet_data { · line 241

Quoted 3 lines · Choong Yong Liang
include/linux/stmmac.h +3 -0
+	int (*config_serdes)(struct net_device *ndev,
+			     void *priv,
+			     phy_interface_t interface);

Since you call this from phylink's mac_finish() method, I would much rather the call down into platform code was also called the same so we don't end up with a proliferation of methods called from that function. As such, please also arrange for it to pass the AN mode as well.

Thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#10 lore raw

Re: [PATCH net-next v6 4/7] stmmac: intel: configure SerDes according to the interface mode

Quoted 11 lines · Russell King (Oracle)

include/linux/stmmac.h struct plat_stmmacenet_data { · line 241

Quoted 3 lines · Choong Yong Liang
include/linux/stmmac.h +3 -0
+	int (*config_serdes)(struct net_device *ndev,
+			     void *priv,
+			     phy_interface_t interface);

Since you call this from phylink's mac_finish() method, I would much rather the call down into platform code was also called the same so we don't end up with a proliferation of methods called from that function. As such, please also arrange for it to pass the AN mode as well.

Quoted 2 lines

Thanks.

Hi Russell,

Thank you for your feedback on the patch. Based on your suggestion, I have updated the code to align with the mac_finish() method and included the AN mode as well. The updated function signature is as follows:

int (*mac_finish)(struct net_device *ndev,
void *priv,
unsigned int mode,
phy_interface_t interface);

Could you please confirm if this meets your expectations, or if there are any further adjustments needed?

#11 lore raw

Re: [PATCH net-next v6 4/7] stmmac: intel: configure SerDes according to the interface mode

Quoted 11 lines · Choong Yong Liang

Thank you for your feedback on the patch. Based on your suggestion, I have updated the code to align with the mac_finish() method and included the AN mode as well. The updated function signature is as follows:

int (*mac_finish)(struct net_device *ndev,
void *priv,
unsigned int mode,
phy_interface_t interface);

Could you please confirm if this meets your expectations, or if there are any further adjustments needed?

That's fine, thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
reviewer
#12 lore raw

Re: [PATCH net-next v6 4/7] stmmac: intel: configure SerDes according to the interface mode

In reply to Choong Yong Liang
Quoted 14 lines · Choong Yong Liang

Intel platform will configure the SerDes through PMC api based on the provided interface mode.

This patch adds several new functions below:-
- intel_tsn_lane_is_available(): This new function reads FIA lane ownership registers and common lane registers through IPC commands to know which lane the mGbE port is assigned to.
- intel_config_serdes(): To configure the SerDes based on the assigned lane and latest interface mode, it sends IPC command to the PMC through PMC driver/API. The PMC acts as a proxy for R/W on behalf of the driver.
- intel_set_reg_access(): Set the register access to the available TSN interface.

...

Quoted 26 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +26 -0
+static int intel_config_serdes(struct net_device *ndev,
+			       void *intel_data,
+			       phy_interface_t interface)
+{
+	struct intel_priv_data *intel_priv = intel_data;
+	struct stmmac_priv *priv = netdev_priv(ndev);
+	int ret = 0;
+
+	if (!intel_tsn_lane_is_available(ndev, intel_priv)) {
+		netdev_info(priv->dev,
+			    "No TSN lane available to set the registers.\n");
+		goto pmc_read_error;
+	}
+
+	if (intel_priv->pid_modphy == PID_MODPHY1) {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX) {
+			ret = intel_set_reg_access(pid_modphy1_2p5g_regs,
+						   ARRAY_SIZE(pid_modphy1_2p5g_regs));
+		} else {
+			ret = intel_set_reg_access(pid_modphy1_1g_regs,
+						   ARRAY_SIZE(pid_modphy1_1g_regs));
+		}
+	} else {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX) {
+			ret = intel_set_reg_access(pid_modphy3_2p5g_regs,
+						   ARRAY_SIZE(pid_modphy3_2p5g_regs));

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv, · line 510

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +10 -0
+		} else {
+			ret = intel_set_reg_access(pid_modphy3_1g_regs,
+						   ARRAY_SIZE(pid_modphy3_1g_regs));
+		}
+	}
+
+	priv->plat->phy_interface = interface;
+
+	if (ret < 0)
+		goto pmc_read_error;

Perhaps this is an artifact of earlier refactoring, but the condition above seems to be without meaning as in either case the code goes directly to pmc_read_error.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +8 -0
+
+pmc_read_error:
+	intel_serdes_powerdown(ndev, intel_priv);
+	intel_serdes_powerup(ndev, intel_priv);
+
+	return ret;
+}
+
 static void common_default_data(struct plat_stmmacenet_data *plat)
 {
 	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */

...

#13 lore raw

Re: [PATCH net-next v6 4/7] stmmac: intel: configure SerDes according to the interface mode

Quoted 41 lines · Simon Horman
Quoted 26 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +26 -0
+static int intel_config_serdes(struct net_device *ndev,
+			       void *intel_data,
+			       phy_interface_t interface)
+{
+	struct intel_priv_data *intel_priv = intel_data;
+	struct stmmac_priv *priv = netdev_priv(ndev);
+	int ret = 0;
+
+	if (!intel_tsn_lane_is_available(ndev, intel_priv)) {
+		netdev_info(priv->dev,
+			    "No TSN lane available to set the registers.\n");
+		goto pmc_read_error;
+	}
+
+	if (intel_priv->pid_modphy == PID_MODPHY1) {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX) {
+			ret = intel_set_reg_access(pid_modphy1_2p5g_regs,
+						   ARRAY_SIZE(pid_modphy1_2p5g_regs));
+		} else {
+			ret = intel_set_reg_access(pid_modphy1_1g_regs,
+						   ARRAY_SIZE(pid_modphy1_1g_regs));
+		}
+	} else {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX) {
+			ret = intel_set_reg_access(pid_modphy3_2p5g_regs,
+						   ARRAY_SIZE(pid_modphy3_2p5g_regs));

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c static void intel_mgbe_pse_crossts_adj(struct intel_priv_data *intel_priv, · line 510

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +10 -0
+		} else {
+			ret = intel_set_reg_access(pid_modphy3_1g_regs,
+						   ARRAY_SIZE(pid_modphy3_1g_regs));
+		}
+	}
+
+	priv->plat->phy_interface = interface;
+
+	if (ret < 0)
+		goto pmc_read_error;

Perhaps this is an artifact of earlier refactoring, but the condition above seems to be without meaning as in either case the code goes directly to pmc_read_error.

Quoted 14 lines
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +8 -0
+
+pmc_read_error:
+	intel_serdes_powerdown(ndev, intel_priv);
+	intel_serdes_powerup(ndev, intel_priv);
+
+	return ret;
+}
+
  static void common_default_data(struct plat_stmmacenet_data *plat)
  {
  	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */

...

Hi Simon,

You are right.
I will perform the cleanup on the code and submit the next version.

Thank you for your feedback.

#14 lore raw

PATCH v6 5/7 net: stmmac: configure SerDes on mac_finish

In reply to Choong Yong Liang

SerDes will configure according to the provided interface mode after finish a major reconfiguration of the interface mode.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +13 -0
index d04543e5697b..56efc475e51c 100644
@@ -1124,6 +1124,18 @@ static int stmmac_mac_enable_tx_lpi(struct phylink_config *config, u32 timer,
 	return 0;
 }
 
+static int stmmac_mac_finish(struct phylink_config *config, unsigned int mode,
+			     phy_interface_t interface)
+{
+	struct net_device *ndev = to_net_dev(config->dev);
+	struct stmmac_priv *priv = netdev_priv(ndev);
+
+	if (priv->plat->config_serdes)
+		priv->plat->config_serdes(ndev, priv->plat->bsp_priv, interface);
+
+	return 0;
+}
+
 static const struct phylink_mac_ops stmmac_phylink_mac_ops = {
 	.mac_get_caps = stmmac_mac_get_caps,
 	.mac_select_pcs = stmmac_mac_select_pcs,
@@ -1132,6 +1144,7 @@ static const struct phylink_mac_ops stmmac_phylink_mac_ops = {
 	.mac_link_up = stmmac_mac_link_up,
 	.mac_disable_tx_lpi = stmmac_mac_disable_tx_lpi,
 	.mac_enable_tx_lpi = stmmac_mac_enable_tx_lpi,
+	.mac_finish = stmmac_mac_finish,
 };
 
 /**
Signature · 1 line
2.34.1
#15 lore raw

PATCH v6 6/7 stmmac: intel: interface switching support for EHL platform

In reply to Choong Yong Liang

The intel_config_serdes function was provided to handle interface mode changes for the ADL-N platform.

The Modphy register lane was provided to configure the serdes when changing interface modes.

---
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 19 ++++++++++++++++---
 .../net/ethernet/stmicro/stmmac/dwmac-intel.h |  4 ++++
 2 files changed, 20 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +16 -3
index 347dd75bcdcd..de561a00f902 100644
@@ -725,6 +725,8 @@ static int intel_mgbe_common_data(struct pci_dev *pdev,
 static int ehl_common_data(struct pci_dev *pdev,
 			   struct plat_stmmacenet_data *plat)
 {
+	struct intel_priv_data *intel_priv = plat->bsp_priv;
+
 	plat->rx_queues_to_use = 8;
 	plat->tx_queues_to_use = 8;
 	plat->flags |= STMMAC_FLAG_USE_PHY_WOL;
@@ -740,19 +742,24 @@ static int ehl_common_data(struct pci_dev *pdev,
 	plat->safety_feat_cfg->prtyen = 0;
 	plat->safety_feat_cfg->tmouten = 0;
 
+	intel_priv->tsn_lane_registers = ehl_tsn_lane_registers;
+	intel_priv->max_tsn_lane_registers = ARRAY_SIZE(ehl_tsn_lane_registers);
+
 	return intel_mgbe_common_data(pdev, plat);
 }
 
 static int ehl_sgmii_data(struct pci_dev *pdev,
 			  struct plat_stmmacenet_data *plat)
 {
+	struct intel_priv_data *intel_priv = plat->bsp_priv;
+
 	plat->bus_id = 1;
 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
-	plat->speed_mode_2500 = intel_speed_mode_2500;
 	plat->serdes_powerup = intel_serdes_powerup;
 	plat->serdes_powerdown = intel_serdes_powerdown;
 	plat->config_serdes = intel_config_serdes;
 	plat->clk_ptp_rate = 204800000;
+	intel_priv->pid_modphy = PID_MODPHY3;
 
 	return ehl_common_data(pdev, plat);
 }
@@ -806,11 +813,14 @@ static struct stmmac_pci_info ehl_pse0_rgmii1g_info = {
 static int ehl_pse0_sgmii1g_data(struct pci_dev *pdev,
 				 struct plat_stmmacenet_data *plat)
 {
+	struct intel_priv_data *intel_priv = plat->bsp_priv;
+
 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
-	plat->speed_mode_2500 = intel_speed_mode_2500;
 	plat->serdes_powerup = intel_serdes_powerup;
 	plat->serdes_powerdown = intel_serdes_powerdown;
 	plat->config_serdes = intel_config_serdes;
+	intel_priv->pid_modphy = PID_MODPHY1;
+
 	return ehl_pse0_common_data(pdev, plat);
 }
 
@@ -848,11 +858,14 @@ static struct stmmac_pci_info ehl_pse1_rgmii1g_info = {
 static int ehl_pse1_sgmii1g_data(struct pci_dev *pdev,
 				 struct plat_stmmacenet_data *plat)
 {
+	struct intel_priv_data *intel_priv = plat->bsp_priv;
+
 	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
-	plat->speed_mode_2500 = intel_speed_mode_2500;
 	plat->serdes_powerup = intel_serdes_powerup;
 	plat->serdes_powerdown = intel_serdes_powerdown;
 	plat->config_serdes = intel_config_serdes;
+	intel_priv->pid_modphy = PID_MODPHY1;
+
 	return ehl_pse1_common_data(pdev, plat);
 }
 
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.h +4 -0
index 79c35ba969ea..093eed977ab0 100644
@@ -123,6 +123,10 @@ static const struct pmc_serdes_regs pid_modphy1_2p5g_regs[] = {
 	{ PID_MODPHY1_N_MODPHY_PCR_CMN_ANA_DWORD30,	N_MODPHY_PCR_CMN_ANA_DWORD30_2P5G },
 	{}
 };
+
+static const int ehl_tsn_lane_registers[] = {7, 8, 9, 10, 11};
+#else
+static const int ehl_tsn_lane_registers[] = {};
 #endif /* CONFIG_INTEL_PMC_IPC */
 
 #endif /* __DWMAC_INTEL_H__ */
Signature · 1 line
2.34.1
#16 lore raw

PATCH v6 7/7 stmmac: intel: interface switching support for ADL-N platform

In reply to Choong Yong Liang

The intel_config_serdes function was provided to handle interface mode changes for the ADL-N platform.

The Modphy register lane was provided to configure the serdes when changing interface modes.

---
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 47 ++++++++++++++++++-
 .../net/ethernet/stmicro/stmmac/dwmac-intel.h |  2 +
 2 files changed, 48 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +46 -1
index de561a00f902..b5180cf303e2 100644
@@ -951,6 +951,51 @@ static int adls_sgmii_phy1_data(struct pci_dev *pdev,
 static struct stmmac_pci_info adls_sgmii1g_phy1_info = {
 	.setup = adls_sgmii_phy1_data,
 };
+
+static int adln_common_data(struct pci_dev *pdev,
+			    struct plat_stmmacenet_data *plat)
+{
+	struct intel_priv_data *intel_priv = plat->bsp_priv;
+
+	plat->rx_queues_to_use = 6;
+	plat->tx_queues_to_use = 4;
+	plat->clk_ptp_rate = 204800000;
+
+	plat->safety_feat_cfg->tsoee = 1;
+	plat->safety_feat_cfg->mrxpee = 0;
+	plat->safety_feat_cfg->mestee = 1;
+	plat->safety_feat_cfg->mrxee = 1;
+	plat->safety_feat_cfg->mtxee = 1;
+	plat->safety_feat_cfg->epsi = 0;
+	plat->safety_feat_cfg->edpp = 0;
+	plat->safety_feat_cfg->prtyen = 0;
+	plat->safety_feat_cfg->tmouten = 0;
+
+	intel_priv->tsn_lane_registers = adln_tsn_lane_registers;
+	intel_priv->max_tsn_lane_registers = ARRAY_SIZE(adln_tsn_lane_registers);
+
+	return intel_mgbe_common_data(pdev, plat);
+}
+
+static int adln_sgmii_phy0_data(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat)
+{
+	struct intel_priv_data *intel_priv = plat->bsp_priv;
+
+	plat->bus_id = 1;
+	plat->phy_interface = PHY_INTERFACE_MODE_SGMII;
+	plat->serdes_powerup = intel_serdes_powerup;
+	plat->serdes_powerdown = intel_serdes_powerdown;
+	plat->config_serdes = intel_config_serdes;
+	intel_priv->pid_modphy = PID_MODPHY1;
+
+	return adln_common_data(pdev, plat);
+}
+
+static struct stmmac_pci_info adln_sgmii1g_phy0_info = {
+	.setup = adln_sgmii_phy0_data,
+};
+
 static const struct stmmac_pci_func_data galileo_stmmac_func_data[] = {
 	{
 		.func = 6,
@@ -1333,7 +1378,7 @@ static const struct pci_device_id intel_eth_pci_id_table[] = {
 	{ PCI_DEVICE_DATA(INTEL, TGLH_SGMII1G_1, &tgl_sgmii1g_phy1_info) },
 	{ PCI_DEVICE_DATA(INTEL, ADLS_SGMII1G_0, &adls_sgmii1g_phy0_info) },
 	{ PCI_DEVICE_DATA(INTEL, ADLS_SGMII1G_1, &adls_sgmii1g_phy1_info) },
-	{ PCI_DEVICE_DATA(INTEL, ADLN_SGMII1G, &tgl_sgmii1g_phy0_info) },
+	{ PCI_DEVICE_DATA(INTEL, ADLN_SGMII1G, &adln_sgmii1g_phy0_info) },
 	{ PCI_DEVICE_DATA(INTEL, RPLP_SGMII1G, &tgl_sgmii1g_phy0_info) },
 	{}
 };
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.h +2 -0
index 093eed977ab0..2c6b50958988 100644
@@ -124,8 +124,10 @@ static const struct pmc_serdes_regs pid_modphy1_2p5g_regs[] = {
 	{}
 };
 
+static const int adln_tsn_lane_registers[] = {6};
 static const int ehl_tsn_lane_registers[] = {7, 8, 9, 10, 11};
 #else
+static const int adln_tsn_lane_registers[] = {};
 static const int ehl_tsn_lane_registers[] = {};
 #endif /* CONFIG_INTEL_PMC_IPC */
 
Signature · 1 line
2.34.1