Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1858688rwp; Thu, 13 Jul 2023 18:35:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlHXz28B6tXxDIUoap4OCWO3qZbcXSW6MJkid6l9tnIzJCCWYbnLa9bU9nS/FIgIKAzjiALH X-Received: by 2002:a17:906:77d5:b0:993:fe9d:eac4 with SMTP id m21-20020a17090677d500b00993fe9deac4mr3220118ejn.7.1689298538071; Thu, 13 Jul 2023 18:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689298538; cv=none; d=google.com; s=arc-20160816; b=JisRR/opn3GfrefeLKdsGsJB6XP2VmKutcIkOfTbYjS+rknleI1sW51RB2aFMUf+fp Hj//mNl4x6DZCnUjqpoIuNo4dATPegp0m3DMmDNzOmbdrUH6Am3pnuFSXRXPA6o4jLCh bIosCzn5aWFPmKsZ6XcWOJ2QCOYyU+WVaFrisM08sswOt7Dg/zTwXUN9iXGjwR5BULgP KQQNkqssmMfTvsBB0bkA/F1/vXEfw0ZewXOe0nLcN1Ye8wkyg07ZdJ1VGkRW1z4mNcnl hp+iHriZ5L1ol3pViTM9JI/iduKQOUlA9IyGURjYg6Bq5uI/456KCQS00VzflkyLPAwA yKMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=1Hpddngr14z7RJu/7vP9aCno1Rz3/amOHBE0Y3d1ARY=; fh=vLCrU9fg5eBSB6QXrYy5g7RALdI0ofdV9wOsW2ziyHk=; b=U9n/CzKoI6dI5PVm4UCbgYU49i9KIq7z6n0uK0Ya7OYqCZuHsyHcqIqVycLugYyIMj 702fAh1ABkhgi2Bl8RjlLjN1oVfyOnCNLZMh4QEjEcog4YrtawHGa9ivD/+1yNyyT/+A F+3yvd2SpIZf7Bal9vY0+RRhjk1UjCf10q6DAozREmvkRiQTow38lrHK9w++IAzXN7ua +VYrsARXjLwTAij9o5gMq5B2nw9WRpqfRu6xzItCXjdZfZ/zimZl0x85eK2pkaZF6Flx +U4EKDW39v24bV5xVIQ9HlLUw2cc1KfsLYyB4arLxqSEPnazY8GD6nM7DL1iCeVfssYl dWPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="wPR/h9pU"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a1709067e0b00b00992f81122e9si7719803ejr.340.2023.07.13.18.35.14; Thu, 13 Jul 2023 18:35:38 -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=@microchip.com header.s=mchp header.b="wPR/h9pU"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234071AbjGNApo (ORCPT + 99 others); Thu, 13 Jul 2023 20:45:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231292AbjGNApn (ORCPT ); Thu, 13 Jul 2023 20:45:43 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DDC026B6; Thu, 13 Jul 2023 17:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1689295542; x=1720831542; h=from:to:cc:subject:date:message-id:mime-version; bh=BZyAeb29yLT1h4dm/ASvrLm3jTIvvdsnRAwPfvo9k6Y=; b=wPR/h9pUAbRgrOesG4OAObdrWH0pS56u5+xTUOrtC0OPyVZiVRaJMF6+ 8L1ut+JxP/JsF5LpnhNPE5WBonSRP272b+c20/1IovniN9kKGLeX45Xt2 9BIgv8Vf8V0PedJTnjx/Zaw7/UuuBLk1KVM1kmlB/OAucDaSiK9qz18VD b3J+q3grW7jLsnQmB2HXd1lfByD5HyrQ/rmvtgl65R5dNPCkSd+Eaa0Jn I4rAhNYw/HLCX4L4dalLs6glBVnqXC88sAXn4vIq2Mx0IrjlVAAzw71Ax UWNVlmHKzLgMvcztH4+gyHhRz8kyayR1+fuhmnfeIilaq3Tle9S5YXUk+ Q==; X-IronPort-AV: E=Sophos;i="6.01,204,1684825200"; d="scan'208";a="224602311" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Jul 2023 17:45:40 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 13 Jul 2023 17:45:39 -0700 Received: from hat-linux.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Thu, 13 Jul 2023 17:45:39 -0700 From: To: Michael Grzeschik , Oleksij Rempel , Woojung Huh , "Andrew Lunn" , Florian Fainelli , "Vladimir Oltean" , CC: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , , , Tristram Ha Subject: [PATCH v2 net] net: dsa: microchip: correct KSZ8795 static MAC table access Date: Thu, 13 Jul 2023 17:46:22 -0700 Message-ID: <1689295582-2726-1-git-send-email-Tristram.Ha@microchip.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, 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: X-Mailing-List: linux-kernel@vger.kernel.org From: Tristram Ha The KSZ8795 driver code was modified to use on KSZ8863/73, which has different register definitions. Some of the new KSZ8795 register information are wrong compared to previous code. KSZ8795 also behaves differently in that the STATIC_MAC_TABLE_USE_FID and STATIC_MAC_TABLE_FID bits are off by 1 when doing MAC table reading than writing. To compensate that a special code was added to shift the register value by 1 before applying those bits. This is wrong when the code is running on KSZ8863, so this special code is only executed when KSZ8795 is detected. Fixes: 4b20a07e103f ("net: dsa: microchip: ksz8795: add support for ksz88xx chips") Signed-off-by: Tristram Ha Reviewed-by: Horatiu Vultur --- v2 - Send to more maintainers. Add review from Horatiu Vultur v1 - Use correct commit for fixes drivers/net/dsa/microchip/ksz8795.c | 8 +++++++- drivers/net/dsa/microchip/ksz_common.c | 8 ++++---- drivers/net/dsa/microchip/ksz_common.h | 7 +++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 84d502589f8e..91aba470fb2f 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -506,7 +506,13 @@ static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr, (data_hi & masks[STATIC_MAC_TABLE_FWD_PORTS]) >> shifts[STATIC_MAC_FWD_PORTS]; alu->is_override = (data_hi & masks[STATIC_MAC_TABLE_OVERRIDE]) ? 1 : 0; - data_hi >>= 1; + + /* KSZ8795 family switches have STATIC_MAC_TABLE_USE_FID and + * STATIC_MAC_TABLE_FID definitions off by 1 when doing read on the + * static MAC table compared to doing write. + */ + if (ksz_is_ksz87xx(dev)) + data_hi >>= 1; alu->is_static = true; alu->is_use_fid = (data_hi & masks[STATIC_MAC_TABLE_USE_FID]) ? 1 : 0; alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID]) >> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 813b91a816bb..b18cd170ec06 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -331,13 +331,13 @@ static const u32 ksz8795_masks[] = { [STATIC_MAC_TABLE_VALID] = BIT(21), [STATIC_MAC_TABLE_USE_FID] = BIT(23), [STATIC_MAC_TABLE_FID] = GENMASK(30, 24), - [STATIC_MAC_TABLE_OVERRIDE] = BIT(26), - [STATIC_MAC_TABLE_FWD_PORTS] = GENMASK(24, 20), + [STATIC_MAC_TABLE_OVERRIDE] = BIT(22), + [STATIC_MAC_TABLE_FWD_PORTS] = GENMASK(20, 16), [DYNAMIC_MAC_TABLE_ENTRIES_H] = GENMASK(6, 0), - [DYNAMIC_MAC_TABLE_MAC_EMPTY] = BIT(8), + [DYNAMIC_MAC_TABLE_MAC_EMPTY] = BIT(7), [DYNAMIC_MAC_TABLE_NOT_READY] = BIT(7), [DYNAMIC_MAC_TABLE_ENTRIES] = GENMASK(31, 29), - [DYNAMIC_MAC_TABLE_FID] = GENMASK(26, 20), + [DYNAMIC_MAC_TABLE_FID] = GENMASK(22, 16), [DYNAMIC_MAC_TABLE_SRC_PORT] = GENMASK(26, 24), [DYNAMIC_MAC_TABLE_TIMESTAMP] = GENMASK(28, 27), [P_MII_TX_FLOW_CTRL] = BIT(5), diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 28444e5924f9..a4de58847dea 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -601,6 +601,13 @@ static inline void ksz_regmap_unlock(void *__mtx) mutex_unlock(mtx); } +static inline bool ksz_is_ksz87xx(struct ksz_device *dev) +{ + return dev->chip_id == KSZ8795_CHIP_ID || + dev->chip_id == KSZ8794_CHIP_ID || + dev->chip_id == KSZ8765_CHIP_ID; +} + static inline bool ksz_is_ksz88x3(struct ksz_device *dev) { return dev->chip_id == KSZ8830_CHIP_ID; -- 2.17.1