Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp191628lqp; Mon, 10 Jun 2024 00:18:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhj/uIWrC/1med/nmsI9o/qFyiy52yGFIcWb8BNyzzcy1lLMMphVTHHTifcgYMILYspUBc/MRCmurGfCM5MAA0SOKPQ1lOjHKWQe/2pg== X-Google-Smtp-Source: AGHT+IHohJ190UZl4LcrQdBA7sxgivwIk4wi95mxDdFedVok4efC0lFHOjlxbn7j2+xR3QJW5qD4 X-Received: by 2002:a05:6358:2829:b0:19f:1365:77b8 with SMTP id e5c5f4694b2df-19f1ff8efe4mr1106154955d.23.1718003923861; Mon, 10 Jun 2024 00:18:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718003923; cv=pass; d=google.com; s=arc-20160816; b=uojlqr2YxN4K1DQltDrHV+3lRFGTpcBCNyE9fyJ3Ndfj/LAfMxQZYI48l9gGH0XBdD o5Wev1g3qubdfIyCy6V4fpqIaT4zLKrPJetIm6QWwibVOZH++Z4PMoSbhkVuiexp503a XwBBnpZpm1J2Q13/fGTD+J7yxzjzUtYFMNbfhplwa1JhZBvAn+8rhIZgF6kbM42FV5Tg PkhMMsO9Hn/oSLF49Sp0l2HXXIYZ/EE1Az/BZNFIhTlPsiZ6qc0AgCoKBjhIwY/YSiUK QmzdETl1DjmH1DeZZA6GJrX05Z1iHhtbdc93dHLb1p54a8GkeljZGt8q3DKnDpJ/opAS 2Pvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hN/g428LiD5uWJnzYnUfLINd1g5a/rCwKHJfJu6r5Uo=; fh=PNVS6hneBIB5DuUKcqXTZxY2dQy/qm89zdYDxH+oLxc=; b=YC9z+lhnS7Hy2k/E4jI1hIgtxcgBhnThkYrSI99zwNrb9uCtaUVZNmkWMuIX0F+NkO zXYhhqdIyoPNStP/DW1jEBPI1p669ICFuTD9qNBDkra7YQaerIMI1qB/STuhfZBSDSnv FF1nI2NLYiAsgOGqPII8eRizW+9y7zysXPEqZuTTaXTMPRDUQYueiUNe8X6dTBK4YMgR NaUkyFm8Qp2TX/qGrRgVyiyEPvbrKIBwdNzRjC3Ar8ekMosyFnUIZzvzj0v19wAjJ6OO mxPMmmz01rzyuo53a8feRaV8FlQjVTHTvEUQaNRH1fzLJV8nWD5Ww0+6xm8MIVU9BaJa jcUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=rjLc5MBo; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-207759-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de261c9afasi3518360a12.342.2024.06.10.00.18.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 00:18:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207759-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=rjLc5MBo; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-207759-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F331A282E91 for ; Mon, 10 Jun 2024 07:18:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CCB84D8DD; Mon, 10 Jun 2024 07:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="rjLc5MBo" Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9BD84779E; Mon, 10 Jun 2024 07:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718003864; cv=none; b=WnBNLJ6XI+YO/chbU/skJcvx10jMRgSZf3nyutFjBsbCAwgiKjrdhRLYAr+sXNdzBcQybEsZwCrAe5rmINce0smDzxHdblHUFXC6nN1TqvfLAR9jzL0LrATSoXEKt6qXKF43AbG2UJw/NXMKZDkXJc2xRnMUTrbn1ZVIfQbeyyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718003864; c=relaxed/simple; bh=CzcWoMBzn29QzER+PxKqVEeUMc90IdZvWfmL2zf9o+A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ObhWajwEarD+QQbpAuJO9fvn+192gVZpWmI6wzV/kEcQ7xSBBRMn77YsQvMk51rpf6PQFB8iAA3d2IhkYIROEjzU6g+TPdvHdJE0/14u0Tmib5pVjCdALjRnceQK7yNNb0w4+irHP+pKzt/jYlXbkLVTAs9RN63kh3t/vGrXZrc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=rjLc5MBo; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 459DNPx4025556; Mon, 10 Jun 2024 09:16:52 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= hN/g428LiD5uWJnzYnUfLINd1g5a/rCwKHJfJu6r5Uo=; b=rjLc5MBopgRwRhgE bmK+AWzGyxAqn5/8Fz2svA7OPtGi/JUpDVQm/vCDw0wh2zDhzmOiCKp3wl1zZDVY noE2F5CDQwAI/u/ufC6jxdUiccFRKkwtsZXf0JRqKOFAXWWmZOTdULnH0zxzil/0 I5iYBCLXCsUccn7HwjJqwGSb7Y4SAuJyPOB2Sdkmv/Qi60yXFJPu2D/USZEye9GT 7VRoiqmuDumCwBTnq64lFg++/1i6ycoO3ewo4MAjDAvCpCRbAYNyNpM7OxYuZ3wR Qgc5ctnkVW4jQnuvnfkrXMktvYWL2Wg0VZR35igBtntsubdT3VP7Af3wqRRdBbhI +kaFqA== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3yme6d5cex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Jun 2024 09:16:52 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id B60714002D; Mon, 10 Jun 2024 09:16:28 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2DD0721075D; Mon, 10 Jun 2024 09:15:11 +0200 (CEST) Received: from localhost (10.48.86.164) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 10 Jun 2024 09:15:08 +0200 From: Christophe Roullier To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Maxime Coquelin , Alexandre Torgue , Richard Cochran , Jose Abreu , Liam Girdwood , Mark Brown , Christophe Roullier , Marek Vasut CC: , , , , Subject: [net-next,PATCH v6 2/8] net: stmmac: dwmac-stm32: Separate out external clock rate validation Date: Mon, 10 Jun 2024 09:14:53 +0200 Message-ID: <20240610071459.287500-3-christophe.roullier@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240610071459.287500-1-christophe.roullier@foss.st.com> References: <20240610071459.287500-1-christophe.roullier@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-10_02,2024-06-06_02,2024-05-17_01 From: Marek Vasut Pull the external clock frequency validation into a separate function, to avoid conflating it with external clock DT property decoding and clock mux register configuration. This should make the code easier to read and understand. This does change the code behavior slightly. The clock mux PMCR register setting now depends solely on the DT properties which configure the clock mux between external clock and internal RCC generated clock. The mux PMCR register settings no longer depend on the supplied clock frequency, that supplied clock frequency is now only validated, and if the clock frequency is invalid for a mode, it is rejected. Previously, the code would switch the PMCR register clock mux to internal RCC generated clock if external clock couldn't provide suitable frequency, without checking whether the RCC generated clock frequency is correct. Such behavior is risky at best, user should have configured their clock correctly in the first place, so this behavior is removed here. Signed-off-by: Marek Vasut Signed-off-by: Christophe Roullier --- .../net/ethernet/stmicro/stmmac/dwmac-stm32.c | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c index c92dfc4ecf570..2fd2620ebed69 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c @@ -157,25 +157,54 @@ static int stm32_dwmac_init(struct plat_stmmacenet_data *plat_dat, bool resume) return stm32_dwmac_clk_enable(dwmac, resume); } +static int stm32mp1_validate_ethck_rate(struct plat_stmmacenet_data *plat_dat) +{ + struct stm32_dwmac *dwmac = plat_dat->bsp_priv; + const u32 clk_rate = clk_get_rate(dwmac->clk_eth_ck); + + switch (plat_dat->mac_interface) { + case PHY_INTERFACE_MODE_MII: + case PHY_INTERFACE_MODE_GMII: + if (clk_rate == ETH_CK_F_25M) + return 0; + break; + case PHY_INTERFACE_MODE_RMII: + if (clk_rate == ETH_CK_F_25M || clk_rate == ETH_CK_F_50M) + return 0; + break; + case PHY_INTERFACE_MODE_RGMII: + case PHY_INTERFACE_MODE_RGMII_ID: + case PHY_INTERFACE_MODE_RGMII_RXID: + case PHY_INTERFACE_MODE_RGMII_TXID: + if (clk_rate == ETH_CK_F_25M || clk_rate == ETH_CK_F_125M) + return 0; + break; + default: + break; + } + + dev_err(dwmac->dev, "Mode %s does not match eth-ck frequency %d Hz", + phy_modes(plat_dat->mac_interface), clk_rate); + return -EINVAL; +} + static int stm32mp1_set_mode(struct plat_stmmacenet_data *plat_dat) { struct stm32_dwmac *dwmac = plat_dat->bsp_priv; - u32 reg = dwmac->mode_reg, clk_rate; - int val; + u32 reg = dwmac->mode_reg; + int val, ret; - clk_rate = clk_get_rate(dwmac->clk_eth_ck); dwmac->enable_eth_ck = false; switch (plat_dat->mac_interface) { case PHY_INTERFACE_MODE_MII: - if (clk_rate == ETH_CK_F_25M && dwmac->ext_phyclk) + if (dwmac->ext_phyclk) dwmac->enable_eth_ck = true; val = SYSCFG_PMCR_ETH_SEL_MII; pr_debug("SYSCFG init : PHY_INTERFACE_MODE_MII\n"); break; case PHY_INTERFACE_MODE_GMII: val = SYSCFG_PMCR_ETH_SEL_GMII; - if (clk_rate == ETH_CK_F_25M && - (dwmac->eth_clk_sel_reg || dwmac->ext_phyclk)) { + if (dwmac->eth_clk_sel_reg || dwmac->ext_phyclk) { dwmac->enable_eth_ck = true; val |= SYSCFG_PMCR_ETH_CLK_SEL; } @@ -183,8 +212,7 @@ static int stm32mp1_set_mode(struct plat_stmmacenet_data *plat_dat) break; case PHY_INTERFACE_MODE_RMII: val = SYSCFG_PMCR_ETH_SEL_RMII; - if ((clk_rate == ETH_CK_F_25M || clk_rate == ETH_CK_F_50M) && - (dwmac->eth_ref_clk_sel_reg || dwmac->ext_phyclk)) { + if (dwmac->eth_ref_clk_sel_reg || dwmac->ext_phyclk) { dwmac->enable_eth_ck = true; val |= SYSCFG_PMCR_ETH_REF_CLK_SEL; } @@ -195,8 +223,7 @@ static int stm32mp1_set_mode(struct plat_stmmacenet_data *plat_dat) case PHY_INTERFACE_MODE_RGMII_RXID: case PHY_INTERFACE_MODE_RGMII_TXID: val = SYSCFG_PMCR_ETH_SEL_RGMII; - if ((clk_rate == ETH_CK_F_25M || clk_rate == ETH_CK_F_125M) && - (dwmac->eth_clk_sel_reg || dwmac->ext_phyclk)) { + if (dwmac->eth_clk_sel_reg || dwmac->ext_phyclk) { dwmac->enable_eth_ck = true; val |= SYSCFG_PMCR_ETH_CLK_SEL; } @@ -209,6 +236,10 @@ static int stm32mp1_set_mode(struct plat_stmmacenet_data *plat_dat) return -EINVAL; } + ret = stm32mp1_validate_ethck_rate(plat_dat); + if (ret) + return ret; + /* Need to update PMCCLRR (clear register) */ regmap_write(dwmac->regmap, reg + SYSCFG_PMCCLRR_OFFSET, dwmac->ops->syscfg_eth_mask); -- 2.25.1