Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp117574lqm; Tue, 30 Apr 2024 15:01:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWlyF+H72VF/v80nCADEVToa09yCE1U1N1PameHqznWd+EZNUVNyTOxEUvX5LsWmO5UAgIPx/uZoaxojt+MK6jupU2tBLDLPFBJ1R1zxQ== X-Google-Smtp-Source: AGHT+IGSWoFZbIEkOo5zRWNFe5G4fC3vq8wY0amqwLkbAygg8PjyJlYwiCvCTcTzuvlSSz5+pcEm X-Received: by 2002:a05:6808:b30:b0:3c7:4d4e:f4d with SMTP id t16-20020a0568080b3000b003c74d4e0f4dmr906845oij.39.1714514507018; Tue, 30 Apr 2024 15:01:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714514506; cv=pass; d=google.com; s=arc-20160816; b=y8XXiPCIixcJGPZf+3ZxZmT1rwGzT6p8jhGDdNQQsg+CJbE4vUUvS2e6er9dcfH5tV jXUk9+o+GPhNinJfubPy242LgzuWsy5mxpYRHYWjDBZeucCe/otwOibZFMjMj8/XEstF FML8IA19gnvrE1Cf6Vzo27UpNNCtgniR+CQq5DqWJMvS0MzIQfJ969GlfSJxFDtsbHH2 uIY2d/c67aqhH1pEd53KuqPUhMmNy5fdMHglG0WavQPe2FE2mo8mm1jrmmpHEmP9q/ur K3HU7vgzNB0Roqxm68M2Onjxs0LzjCoYG4Nqjf3PKEa1rSKVXRKF5WUVuhiWOYYpjA7p VNRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:to:from:date; bh=hfTluUzeXpnCDaDDivqMUVtI+jRQWx9LpRIOCGhPIXs=; fh=2h6buv3QeggfTXC5lfCHqMWhKWObehUOmiFylQLwr0A=; b=IvVtIUOlhL/wCRqog3sPeVTOpY+nusKHcfXCcSHa9/eeQcVoxmb+iSHnACl+YAK597 Fmj94v07o1/pmhJUX6+Ygud1PfOby0v+l5ZUIFM8SJONOC8ngQAyzCLR85GclYAxJM7r yjSUuQSmawbuaxbMYhNH3PWS8Es3dzxjfkJNxjnWj7sF2kRrtM1RhyV8h0EzhgjI1fH/ 2eaGS37SPbuk8oRNnADufi7MIFFjqxK7qfeWw4P+T+hAnP1UJ8w4hmYuw0WjUNFPnWhL VAX9HRHJEpZm1mnx0o45yYkKHr2ONiHvtYW/3REmRp7TBwgcItFgpsigJWl7Mt7RWShr ZrBQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-164765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164765-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id if14-20020a0562141c4e00b006a0d1f42532si5085161qvb.558.2024.04.30.15.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 15:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-164765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164765-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 91C501C229CE for ; Tue, 30 Apr 2024 22:01:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 452221BF6CE; Tue, 30 Apr 2024 22:01:36 +0000 (UTC) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 switch") 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); } + /* 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 = ((((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 = correct_addr; + } + regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config), GFP_KERNEL); if (!regmap_config) -- 2.44.0