Skip to content

Commit 85e2a2c

Browse files
committed
Merge branch 'net-stmmac-increase-clk_ptp_ref-rate'
Andrew Halaney says: ==================== net: stmmac: Increase clk_ptp_ref rate This series aims to increase the clk_ptp_ref rate to get the best possible PTP timestamping resolution possible. Some modified disclosure about my development/testing process from the RFC/RFT v1 follows. Disclosure: I don't know much about PTP beyond what you can google in an afternoon, don't have access to documentation about the stmmac IP, and have only tested that (based on code comments and git commit history) the programming of the subsecond register (and the clock rate) makes more sense with these changes. Qualcomm has tested a similar change offlist, verifying PTP more formally as I understand it. The last version was an RFC/RFT, but I didn't get a lot of confirmation that doing patch 3 in that series (essentially setting clk_ptp_ref to whatever its max value is) for the whole stmmac ecosystem was a safe idea. So I am erring on the side of caution and doing this for the Qualcomm platform only. See v1 for an approach that would apply to all stmmac platform drivers with clk_ptp_ref. v1: https://lore.kernel.org/netdev/20230711205732.364954-1-ahalaney@redhat.com/ ==================== Link: https://lore.kernel.org/r/20230725211853.895832-2-ahalaney@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 5908a4c + db845b9 commit 85e2a2c

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ static void intel_speed_mode_2500(struct net_device *ndev, void *intel_data)
257257
/* Program PTP Clock Frequency for different variant of
258258
* Intel mGBE that has slightly different GPO mapping
259259
*/
260-
static void intel_mgbe_ptp_clk_freq_config(void *npriv)
260+
static void intel_mgbe_ptp_clk_freq_config(struct stmmac_priv *priv)
261261
{
262-
struct stmmac_priv *priv = (struct stmmac_priv *)npriv;
263262
struct intel_priv_data *intel_priv;
264263
u32 gpio_value;
265264

drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,23 @@ static void ethqos_clks_disable(void *data)
694694
ethqos_clks_config(data, false);
695695
}
696696

697+
static void ethqos_ptp_clk_freq_config(struct stmmac_priv *priv)
698+
{
699+
struct plat_stmmacenet_data *plat_dat = priv->plat;
700+
int err;
701+
702+
if (!plat_dat->clk_ptp_ref)
703+
return;
704+
705+
/* Max the PTP ref clock out to get the best resolution possible */
706+
err = clk_set_rate(plat_dat->clk_ptp_ref, ULONG_MAX);
707+
if (err)
708+
netdev_err(priv->dev, "Failed to max out clk_ptp_ref: %d\n", err);
709+
plat_dat->clk_ptp_rate = clk_get_rate(plat_dat->clk_ptp_ref);
710+
711+
netdev_dbg(priv->dev, "PTP rate %d\n", plat_dat->clk_ptp_rate);
712+
}
713+
697714
static int qcom_ethqos_probe(struct platform_device *pdev)
698715
{
699716
struct device_node *np = pdev->dev.of_node;
@@ -779,6 +796,7 @@ static int qcom_ethqos_probe(struct platform_device *pdev)
779796
plat_dat->bsp_priv = ethqos;
780797
plat_dat->fix_mac_speed = ethqos_fix_mac_speed;
781798
plat_dat->dump_debug_regs = rgmii_dump;
799+
plat_dat->ptp_clk_freq_config = ethqos_ptp_clk_freq_config;
782800
plat_dat->has_gmac4 = 1;
783801
if (ethqos->has_emac_ge_3)
784802
plat_dat->dwmac4_addrs = &data->dwmac4_addrs;

include/linux/stmmac.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
| DMA_AXI_BLEN_32 | DMA_AXI_BLEN_64 \
7777
| DMA_AXI_BLEN_128 | DMA_AXI_BLEN_256)
7878

79+
struct stmmac_priv;
80+
7981
/* Platfrom data for platform device structure's platform_data field */
8082

8183
struct stmmac_mdio_bus_data {
@@ -258,7 +260,7 @@ struct plat_stmmacenet_data {
258260
int (*serdes_powerup)(struct net_device *ndev, void *priv);
259261
void (*serdes_powerdown)(struct net_device *ndev, void *priv);
260262
void (*speed_mode_2500)(struct net_device *ndev, void *priv);
261-
void (*ptp_clk_freq_config)(void *priv);
263+
void (*ptp_clk_freq_config)(struct stmmac_priv *priv);
262264
int (*init)(struct platform_device *pdev, void *priv);
263265
void (*exit)(struct platform_device *pdev, void *priv);
264266
struct mac_device_info *(*setup)(void *priv);

0 commit comments

Comments
 (0)