diff mbox series

[net-next,2/2] net: stmmac: Add callbacks for DWC xpcs Energy Efficient Ethernet

Message ID 20210517094332.24976-3-michael.wei.hong.sit@intel.com (mailing list archive)
State Accepted
Commit e80fe71b3ffe1ec31c4a9be60170f897bbdf1b92
Delegated to: Netdev Maintainers
Headers show
Series Introducing support for DWC xpcs Energy Efficient Ethernet | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 2 maintainers not CCed: fugang.duan@nxp.com joabreu@synopsys.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 22 this patch: 22
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 44 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 22 this patch: 22
netdev/header_inline success Link

Commit Message

Sit, Michael Wei Hong May 17, 2021, 9:43 a.m. UTC
Link xpcs callback functions for MAC to configure the xpcs EEE feature.

The clk_eee frequency is used to calculate the MULT_FACT_100NS. This is
to adjust the clock tic closer to 100ns.

Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c    | 11 +++++++++++
 drivers/net/ethernet/stmicro/stmmac/hwif.h           |  2 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c |  6 ++++++
 include/linux/stmmac.h                               |  1 +
 4 files changed, 20 insertions(+)

Comments

Russell King (Oracle) May 17, 2021, 10:54 a.m. UTC | #1
On Mon, May 17, 2021 at 05:43:32PM +0800, Michael Sit Wei Hong wrote:
> Link xpcs callback functions for MAC to configure the xpcs EEE feature.
> 
> The clk_eee frequency is used to calculate the MULT_FACT_100NS. This is
> to adjust the clock tic closer to 100ns.
> 
> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>

What is the initial state of the EEE configuration before the first
call to stmmac_ethtool_op_set_eee()? Does it reflect the default EEE
settings?
Sit, Michael Wei Hong May 17, 2021, 11:37 a.m. UTC | #2
> -----Original Message-----
> From: Russell King <linux@armlinux.org.uk>
> Sent: Monday, 17 May, 2021 6:54 PM
> To: Sit, Michael Wei Hong <michael.wei.hong.sit@intel.com>
> Cc: Jose.Abreu@synopsys.com; andrew@lunn.ch;
> hkallweit1@gmail.com; kuba@kernel.org;
> netdev@vger.kernel.org; peppe.cavallaro@st.com;
> alexandre.torgue@foss.st.com; davem@davemloft.net;
> mcoquelin.stm32@gmail.com; Voon, Weifeng
> <weifeng.voon@intel.com>; Ong, Boon Leong
> <boon.leong.ong@intel.com>; Tan, Tee Min
> <tee.min.tan@intel.com>; vee.khee.wong@linux.intel.com;
> Wong, Vee Khee <vee.khee.wong@intel.com>; linux-stm32@st-
> md-mailman.stormreply.com; linux-arm-
> kernel@lists.infradead.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH net-next 2/2] net: stmmac: Add callbacks for
> DWC xpcs Energy Efficient Ethernet
> 
> On Mon, May 17, 2021 at 05:43:32PM +0800, Michael Sit Wei Hong
> wrote:
> > Link xpcs callback functions for MAC to configure the xpcs EEE
> feature.
> >
> > The clk_eee frequency is used to calculate the
> MULT_FACT_100NS. This
> > is to adjust the clock tic closer to 100ns.
> >
> > Signed-off-by: Michael Sit Wei Hong
> <michael.wei.hong.sit@intel.com>
> 
> What is the initial state of the EEE configuration before the first
> call to stmmac_ethtool_op_set_eee()? Does it reflect the default
> EEE settings?

The register values before the first call are the default reset values in
the registers. The reset values assumes the clk_eee_i time period is 10ns,
Hence, the reset value is set to 9.
According to the register description,
This value should be programmed such that the
clk_eee_i_time_period * (MULT_FACT_100NS + 1) should be
within 80 ns to 120 ns.

Since we are using a fixed 19.2MHz clk_eee, which is 52ns,
we are setting the value to 1.
> 
> --
> RMK's Patch system:
> https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at
> last!
Russell King (Oracle) May 18, 2021, 10:06 a.m. UTC | #3
On Mon, May 17, 2021 at 11:37:12AM +0000, Sit, Michael Wei Hong wrote:
> > From: Russell King <linux@armlinux.org.uk>
> > 
> > On Mon, May 17, 2021 at 05:43:32PM +0800, Michael Sit Wei Hong
> > wrote:
> > > Link xpcs callback functions for MAC to configure the xpcs EEE
> > feature.
> > >
> > > The clk_eee frequency is used to calculate the
> > MULT_FACT_100NS. This
> > > is to adjust the clock tic closer to 100ns.
> > >
> > > Signed-off-by: Michael Sit Wei Hong
> > <michael.wei.hong.sit@intel.com>
> > 
> > What is the initial state of the EEE configuration before the first
> > call to stmmac_ethtool_op_set_eee()? Does it reflect the default
> > EEE settings?
> 
> The register values before the first call are the default reset values in
> the registers. The reset values assumes the clk_eee_i time period is 10ns,
> Hence, the reset value is set to 9.
> According to the register description,
> This value should be programmed such that the
> clk_eee_i_time_period * (MULT_FACT_100NS + 1) should be
> within 80 ns to 120 ns.
> 
> Since we are using a fixed 19.2MHz clk_eee, which is 52ns,
> we are setting the value to 1.

Does that hardware default configuration match what is returned by
ethtool --show-eee ?
Sit, Michael Wei Hong May 19, 2021, 2:27 a.m. UTC | #4
> -----Original Message-----
> From: Russell King <linux@armlinux.org.uk>
> Sent: Tuesday, 18 May, 2021 6:06 PM
> To: Sit, Michael Wei Hong <michael.wei.hong.sit@intel.com>
> Cc: Jose.Abreu@synopsys.com; andrew@lunn.ch;
> hkallweit1@gmail.com; kuba@kernel.org;
> netdev@vger.kernel.org; peppe.cavallaro@st.com;
> alexandre.torgue@foss.st.com; davem@davemloft.net;
> mcoquelin.stm32@gmail.com; Voon, Weifeng
> <weifeng.voon@intel.com>; Ong, Boon Leong
> <boon.leong.ong@intel.com>; Tan, Tee Min
> <tee.min.tan@intel.com>; vee.khee.wong@linux.intel.com;
> Wong, Vee Khee <vee.khee.wong@intel.com>; linux-stm32@st-
> md-mailman.stormreply.com; linux-arm-
> kernel@lists.infradead.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH net-next 2/2] net: stmmac: Add callbacks for
> DWC xpcs Energy Efficient Ethernet
> 
> On Mon, May 17, 2021 at 11:37:12AM +0000, Sit, Michael Wei
> Hong wrote:
> > > From: Russell King <linux@armlinux.org.uk>
> > >
> > > On Mon, May 17, 2021 at 05:43:32PM +0800, Michael Sit Wei
> Hong
> > > wrote:
> > > > Link xpcs callback functions for MAC to configure the xpcs
> EEE
> > > feature.
> > > >
> > > > The clk_eee frequency is used to calculate the
> > > MULT_FACT_100NS. This
> > > > is to adjust the clock tic closer to 100ns.
> > > >
> > > > Signed-off-by: Michael Sit Wei Hong
> > > <michael.wei.hong.sit@intel.com>
> > >
> > > What is the initial state of the EEE configuration before the
> first
> > > call to stmmac_ethtool_op_set_eee()? Does it reflect the
> default EEE
> > > settings?
> >
> > The register values before the first call are the default reset
> values
> > in the registers. The reset values assumes the clk_eee_i time
> period
> > is 10ns, Hence, the reset value is set to 9.
> > According to the register description, This value should be
> programmed
> > such that the clk_eee_i_time_period * (MULT_FACT_100NS + 1)
> should be
> > within 80 ns to 120 ns.
> >
> > Since we are using a fixed 19.2MHz clk_eee, which is 52ns, we
> are
> > setting the value to 1.
> 
> Does that hardware default configuration match what is returned
> by ethtool --show-eee ?

May I know what is the hardware default configuration that is expected
to be returned by ethtool --show-eee?
The MULT_FACT_100NS value is an internal register setting not meant
to be exposed to userspace, and only relevant when EEE is enabled.
> 
> --
> RMK's Patch system:
> https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at
> last!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
index 80728a4c0e3f..e36a8cc59ad0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
@@ -429,6 +429,17 @@  static int intel_mgbe_common_data(struct pci_dev *pdev,
 	plat->force_sf_dma_mode = 0;
 	plat->tso_en = 1;
 
+	/* Multiplying factor to the clk_eee_i clock time
+	 * period to make it closer to 100 ns. This value
+	 * should be programmed such that the clk_eee_time_period *
+	 * (MULT_FACT_100NS + 1) should be within 80 ns to 120 ns
+	 * clk_eee frequency is 19.2Mhz
+	 * clk_eee_time_period is 52ns
+	 * 52ns * (1 + 1) = 104ns
+	 * MULT_FACT_100NS = 1
+	 */
+	plat->mult_fact_100ns = 1;
+
 	plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
 
 	for (i = 0; i < plat->rx_queues_to_use; i++) {
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 2cc91759b91f..c678d7b826a3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -624,6 +624,8 @@  struct stmmac_mmc_ops {
 	stmmac_do_callback(__priv, xpcs, link_up, __args)
 #define stmmac_xpcs_probe(__priv, __args...) \
 	stmmac_do_callback(__priv, xpcs, probe, __args)
+#define stmmac_xpcs_config_eee(__priv, __args...) \
+	stmmac_do_callback(__priv, xpcs, config_eee, __args)
 
 struct stmmac_regs_off {
 	u32 ptp_off;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index 61b11639ee0c..1f6d749fd9a3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -720,6 +720,12 @@  static int stmmac_ethtool_op_set_eee(struct net_device *dev,
 		netdev_warn(priv->dev,
 			    "Setting EEE tx-lpi is not supported\n");
 
+	ret = stmmac_xpcs_config_eee(priv, &priv->hw->xpcs_args,
+				     priv->plat->mult_fact_100ns,
+				     edata->eee_enabled);
+	if (ret)
+		return ret;
+
 	if (!edata->eee_enabled)
 		stmmac_disable_eee_mode(priv);
 
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 0db36360ef21..e14a12df381b 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -223,6 +223,7 @@  struct plat_stmmacenet_data {
 	struct clk *clk_ptp_ref;
 	unsigned int clk_ptp_rate;
 	unsigned int clk_ref_rate;
+	unsigned int mult_fact_100ns;
 	s32 ptp_max_adj;
 	struct reset_control *stmmac_rst;
 	struct stmmac_axi *axi;