From nobody Thu Sep 19 19:35:46 2024 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (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 50C2B74E11; Tue, 30 Apr 2024 22:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714514495; cv=none; b=kEMWbxzlmEKkk5uP3jALJBZt+gQUgdEW6bNKIQwOgCQCQsLCucL88B+rCi40Doex+az8s+hLNFub5MvBw3Qr8g0swmNi+rkr0tcIw8oGD8zAF8AAv/t9I3SfiwrGc2M19MH9lxXWBVPm1HsZPu080ILUsj4hPtIHfptPsHE0uLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714514495; c=relaxed/simple; bh=iEt4z79Rp/ekOOktnvu3zl7uib0Zfw+JTHZVZY8sIzc=; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=nrLp/sX76ERJqUJ0MBaAsqMQVIQNijW8czU9VrLOqjhjATDJjYL9FNezFTPLCjPtzoIjGgwofBrcUPQHtMFTWzGuOnT9bYcavF0UiRRoZFQLp79LlFGX7mO3EQwEWkZnEBWI+Bsy189yb9EoAGeqcRS9DVhMESKpW2fb3bofxU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.97.1) (envelope-from ) id 1s1vXQ-0000000019H-1CUZ; Tue, 30 Apr 2024 22:01:24 +0000 Date: Tue, 30 Apr 2024 23:01:17 +0100 From: Daniel Golle To: =?utf-8?B?QXLEsW7DpyDDnE5BTA==?= , Felix Fietkau , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Simon Horman , DENG Qingfang , Sean Wang , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Landen Chao , devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH net v2] net: dsa: mt7530: fix impossible MDIO address and issue warning Message-ID: <11f5f127d0350e72569c36f9060b6e642dfaddbb.1714514208.git.daniel@makrotopia.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The MDIO address of the MT7530 and MT7531 switch ICs can be configured using bootstrap pins. However, there are only 4 possible options for the switch itself: 7, 15, 23 and 31. As in MediaTek's SDK the address of the switch is wrongly stated in the device tree as 0 (while in reality it is 31), warn the user about such broken device tree and make a good guess what was actually intended. This is imporant also to not break compatibility with older device trees as with commit 868ff5f4944a ("net: dsa: mt7530-mdio: read PHY address of switch from device tree") the address in device tree will be taken into account. Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 sw= itch") Signed-off-by: Daniel Golle --- Changes since v1: - use FW_WARN as suggested. - fix build on net tree which doesn't have 'mdiodev' as member of the priv struct. Imho including this patch as fix makes sense to warn users about broken firmware, even if the change introducing the actual breakage is only present in net-next for now. drivers/net/dsa/mt7530-mdio.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c index fa3ee85a99c1..3c21c8d074c7 100644 --- a/drivers/net/dsa/mt7530-mdio.c +++ b/drivers/net/dsa/mt7530-mdio.c @@ -193,6 +193,19 @@ mt7530_probe(struct mdio_device *mdiodev) return PTR_ERR(priv->io_pwr); } =20 + /* Only MDIO bus address 7, 15, 23 and 31 are valid options */ + if (~(mdiodev->addr & 0x7) & 0x7) { + /* If the address in DT must be wrong, make a good guess about + * the most likely intention, and issue a warning. + */ + int correct_addr =3D ((((mdiodev->addr - 7) & ~0x7) % 0x20) + 7) & 0x1f; + + dev_warn(&mdiodev->dev, FW_WARN + "impossible switch MDIO address in device tree: %d, assuming %d\n", + mdiodev->addr, correct_addr); + mdiodev->addr =3D correct_addr; + } + regmap_config =3D devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config), GFP_KERNEL); if (!regmap_config) --=20 2.44.0