Message ID | 20230620113855.733526-4-linux@rasmusvillemoes.dk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3600757vqr; Tue, 20 Jun 2023 04:45:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6WNBOcRiSy5mISBBjOc2OP1lupf6Prvy7CKDQu2FKjYdO3kLLcH98pCmgbhrW07RasIFv5 X-Received: by 2002:a17:90a:e516:b0:259:b504:583e with SMTP id t22-20020a17090ae51600b00259b504583emr11239641pjy.27.1687261500256; Tue, 20 Jun 2023 04:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687261500; cv=none; d=google.com; s=arc-20160816; b=wTkGKKkrgNCFtAn3DdVprQhI4Vio1Ln2tA7HZG+MFP14X3SqQKldxIReRRhmuDwjIU dTW5aGisexBlt/69j0Y1zdj/CSsr03CViLQcylMOQVWUQYGEjCW/gsrfekeLDNqLpoXE 4NMR1RgVhApM4ngPYjI25th9GwKoSLlwvrRxEsXihuSMXofIqBor65g8nXoWCy5L09ec GA8+6gArqZHsdiqoxc7IDFz5SFe1z2Cb9I+Gl1IhwHNHu9sn7i8uXP3XYOafqPl73jTU biIyBTQuXda79OYl9EVaRq44Igtjfez8fhqbd9AnF4aCX0jFzA/8cpgLpG0I6Lr0gvEq riag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rc0VF9QAKItzIoQIN+TGeSbpZSwD884ZJlY6XLWEwnQ=; b=0Tzo7ygZjf1p7J0nOIPUeH/KybfGn6c2Q+5CNILO0n3w75IIIF13eHfK6RfFX9WBQX VfKXlyPb6hhA3vcK4s8qG9w/dNe1aimj0Ow4do141PHFI/BaIHO4wHruMYAQx+9RLwaF KSmsEKRJ3I61cCaSiDvu3zySxnlXUNdJWmve18WoXuWSzE6jK5GGkhKvSWfh786hOcdL IUNz27c4DDJwr6L7dSuTyycxneV+btqDqEKEEvZCbHEbB3vT5Q6S9FIXmNGbXUmklWUH cgTIMXkb8K9o1e1srCUEECrDg0lTX8hcDy5987Q+z6DJwmg5f8ANxx+END7HNKApSyBx yhRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b="OSo/IOjp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r20-20020a17090b051400b002597c3244c5si1685231pjz.80.2023.06.20.04.44.45; Tue, 20 Jun 2023 04:45:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b="OSo/IOjp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232543AbjFTLlK (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Tue, 20 Jun 2023 07:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbjFTLlD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 20 Jun 2023 07:41:03 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE4DE71 for <linux-kernel@vger.kernel.org>; Tue, 20 Jun 2023 04:41:01 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f4b2bc1565so5979835e87.2 for <linux-kernel@vger.kernel.org>; Tue, 20 Jun 2023 04:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1687261259; x=1689853259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rc0VF9QAKItzIoQIN+TGeSbpZSwD884ZJlY6XLWEwnQ=; b=OSo/IOjpcTOvWjExcqsUbvuVyXnARS++fI0WVy3bVnpKwZGoSPB4IrOxk/VnscG8BF FfeSlGKun5ERhfnpb5CLB13pbyP1lWPKhVHkcU8hsfjhGbLJJtwZAFIiMr/anJHqRSP1 +eIcUHFwHvqjxUsQOzyIPT2Qmnbt5eDVXiQBE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687261259; x=1689853259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rc0VF9QAKItzIoQIN+TGeSbpZSwD884ZJlY6XLWEwnQ=; b=dRAGp31KW0QsnNOcvgb/iGkxWhFynsVxRhWtrrvLdq/FdqBUnwIxVV8TNaDnCr7wOm wW+K6mOtUTXAvzJ5PwhWLGHQw52F0plp3+GdViPxjJGoc3ufyp8uFqL98yc5WM/6ztlr pISE/gm/x1AZ55EYDns04q1k4XqN9X175IETpQ89f4Qzvr1U1IN5thTh8HnyEQ9np15F IxLGoudOnCYkxAQXgNcP13H5IOd1oqMOgFsLdSCSnbFYxvua5bhWDvCbxbimTJ/cMUwA dsjdTjrvoMgn7zcLTgCnWa2oQduXSg+XqjqJRq46aSnjPAwLugtcPwKoZL32I1Z67IU6 J69A== X-Gm-Message-State: AC+VfDyzCt4yvO/LTyBFIN6oX3s+T3GNRe/egGUmmPQHrW1TiX8/OWW2 CKNI6oqdY2Iy5Y0dj2RwFtiKEg== X-Received: by 2002:ac2:5b12:0:b0:4f3:dd96:bf55 with SMTP id v18-20020ac25b12000000b004f3dd96bf55mr7093121lfn.11.1687261258951; Tue, 20 Jun 2023 04:40:58 -0700 (PDT) Received: from localhost.localdomain ([87.54.42.112]) by smtp.gmail.com with ESMTPSA id d12-20020ac2544c000000b004f84162e08bsm329879lfn.185.2023.06.20.04.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:40:58 -0700 (PDT) From: Rasmus Villemoes <linux@rasmusvillemoes.dk> To: Woojung Huh <woojung.huh@microchip.com>, UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>, Florian Fainelli <f.fainelli@gmail.com>, Vladimir Oltean <olteanv@gmail.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/3] net: dsa: microchip: fix writes to phy registers >= 0x10 Date: Tue, 20 Jun 2023 13:38:54 +0200 Message-Id: <20230620113855.733526-4-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230620113855.733526-1-linux@rasmusvillemoes.dk> References: <20230620113855.733526-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769221900251385467?= X-GMAIL-MSGID: =?utf-8?q?1769221914973879864?= |
Series |
net: dsa: microchip: fix writes to phy registers >= 0x10
|
|
Commit Message
Rasmus Villemoes
June 20, 2023, 11:38 a.m. UTC
According to the errata sheets for ksz9477 and ksz9567, writes to the
PHY registers 0x10-0x1f (i.e. those located at addresses 0xN120 to
0xN13f) must be done as a 32 bit write to the 4-byte aligned address
containing the register, hence requires a RMW in order not to change
the adjacent PHY register.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
drivers/net/dsa/microchip/ksz9477.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
Comments
On Tue, Jun 20, 2023 at 01:38:54PM +0200, Rasmus Villemoes wrote: > According to the errata sheets for ksz9477 and ksz9567, writes to the > PHY registers 0x10-0x1f (i.e. those located at addresses 0xN120 to > 0xN13f) must be done as a 32 bit write to the 4-byte aligned address > containing the register, hence requires a RMW in order not to change > the adjacent PHY register. > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Reviewed-by: Simon Horman <simon.horman@corigine.com>
On Tue, Jun 20, 2023 at 01:38:54PM +0200, Rasmus Villemoes wrote: > According to the errata sheets for ksz9477 and ksz9567, writes to the > PHY registers 0x10-0x1f (i.e. those located at addresses 0xN120 to > 0xN13f) must be done as a 32 bit write to the 4-byte aligned address > containing the register, hence requires a RMW in order not to change > the adjacent PHY register. ASIC engineers do see to come up with novel ways to break things. I assume you have not seen real problems with this, which is why it is not for net and a Fixes: tag? Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew
On 20/06/2023 21.28, Andrew Lunn wrote: > On Tue, Jun 20, 2023 at 01:38:54PM +0200, Rasmus Villemoes wrote: >> According to the errata sheets for ksz9477 and ksz9567, writes to the >> PHY registers 0x10-0x1f (i.e. those located at addresses 0xN120 to >> 0xN13f) must be done as a 32 bit write to the 4-byte aligned address >> containing the register, hence requires a RMW in order not to change >> the adjacent PHY register. > > ASIC engineers do see to come up with novel ways to break things. > > I assume you have not seen real problems with this, which is why it is > not for net and a Fixes: tag? Well, not real problems yet, no. The back story is that I want/need to implement support for "single LED mode" on the ksz9567, because our board has two separate simple LEDs for link/activity, and not some multi-color LED that can indicate speed/link/activity. So that means writing a 1 to bit 4 of MMD reg 2/0, but due to an errata, _also_ writing a 1 to bit 9 of phy register 0x1e, and when one wants to do that, this errata applies. Rasmus
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index fc5157a10af5..83b7f2d5c1ea 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -329,11 +329,27 @@ int ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data) int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) { + u32 mask, val32; + /* No real PHY after this. */ if (!dev->info->internal_phy[addr]) return 0; - return ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val); + if (reg < 0x10) + return ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val); + + /* Errata: When using SPI, I2C, or in-band register access, + * writes to certain PHY registers should be performed as + * 32-bit writes instead of 16-bit writes. + */ + val32 = val; + mask = 0xffff; + if ((reg & 1) == 0) { + val32 <<= 16; + mask <<= 16; + } + reg &= ~1; + return ksz_prmw32(dev, addr, 0x100 + (reg << 1), mask, val32); } void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member)