Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5086893rwl; Tue, 28 Mar 2023 16:13:53 -0700 (PDT) X-Google-Smtp-Source: AKy350Yi1rr/1HO/MF/Vjv/ToVw4A01dkEBUy7qj1y3SAvaeFhM8dzePINsCyFJ71PMWYCweKIt+ X-Received: by 2002:a17:902:e74c:b0:1a1:b11d:6af5 with SMTP id p12-20020a170902e74c00b001a1b11d6af5mr21395020plf.52.1680045232910; Tue, 28 Mar 2023 16:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680045232; cv=none; d=google.com; s=arc-20160816; b=htPFrt3aKzACHuCaq+nWFvYVPIWSzAzhbfCv3PXPCzvXjxgPx6VxUznchMEcZ+P13y s1CG/Id21478QpOPzlLfnDmF6vTLaT6C9D011gOq79+QQdTTrw/NgSRGNC7CYFEPOupw COhI/mOhyqPMKM//TJ9ydkl8wVTvWrYzczed/o0RDgYdUkuTkLyogM4OJjVgC4/BpYUW mzKxPxjJLqSryyBGF4+GDQqZWP08g1/hKiuXtsdDw27qR0WcCZLsl9lt8kEsqYvvlVUx YWH1dYPITTP9+jsQi8FBRF9+7dpEldKWkt1w40tYf2FE2DUiFeKu5OCMhsieRUZcmbvz fULA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=30mVqDBt3qPVcDnNfWuY2qH9ovkW25QV8iQXSPqOSa4=; b=f8W9xoWUH2PbLadSz8TZx9FWWcs6gWYZ1hmRj1bS5/gn0P/iVSZqVxZ/sBkCqo80Qp PXvQyysJ5YSb9OKMjOG1p+BgbTfpfAt+Yy6gtPY9O9Wwa7IZAyL4mUN6FdozSP06Sd1m KSV8ph4bXceyghOS7k1yKxjpefSjwoSfr+aNln91+kJ3MyStqt0oJOC0VQmlVg4KF4HD 6KMl+CXs+uhSRynJUyN06vhUPSyKO56B6x0y/bJHo7md2hvOKVHkhfbuQCTMr7tPN4vo gXmw2ffIma7Cs1zPUocAb0gtFrp422JuKAqnL4rxnViMEh+3VmUjDNy6Qu1ZXliTe+p3 CnsA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f1-20020a655501000000b004fac433dbcdsi29438809pgr.134.2023.03.28.16.13.40; Tue, 28 Mar 2023 16:13:52 -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; 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 S229813AbjC1XIM (ORCPT + 99 others); Tue, 28 Mar 2023 19:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjC1XIL (ORCPT ); Tue, 28 Mar 2023 19:08:11 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D6D310F8; Tue, 28 Mar 2023 16:08:10 -0700 (PDT) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1phIQ9-000450-1v; Wed, 29 Mar 2023 01:08:05 +0200 Date: Wed, 29 Mar 2023 00:08:02 +0100 From: Daniel Golle To: Andrew Lunn Cc: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Sean Wang , Landen Chao , DENG Qingfang , Philipp Zabel , Sam Shih , Lorenzo Bianconi , John Crispin , Felix Fietkau Subject: Re: [RFC PATCH net-next v2 2/2] net: dsa: mt7530: introduce MMIO driver for MT7988 SoC Message-ID: References: <6f628e3a56ad8390b1f5a00b86b61c54d66d3106.1680041193.git.daniel@makrotopia.org> <8494e02c-6c04-46c9-af86-a414f27fcf23@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8494e02c-6c04-46c9-af86-a414f27fcf23@lunn.ch> X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On Wed, Mar 29, 2023 at 12:45:37AM +0200, Andrew Lunn wrote: > > @@ -146,11 +149,13 @@ core_write(struct mt7530_priv *priv, u32 reg, u32 val) > > { > > struct mii_bus *bus = priv->bus; > > > > - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); > > + if (bus) > > + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); > > > > core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val); > > > > - mutex_unlock(&bus->mdio_lock); > > + if (bus) > > + mutex_unlock(&bus->mdio_lock); > > } > > All this if (bus) is pretty ugly. > > First off, what is this mutex actually protecting? And why is the same > protection not required for MMIO? The mutex is protecting the MDIO bus. Each access to any register of the MT753x switch requires at least two operations on the MDIO bus. Hence if there is congruent access, e.g. due to PCS or PHY polling, this can mess up and interfere with another ongoing register access sequence. You may argue that we should just use regmap's locking API for that, as it is done also when creating the pcs-mtk-lynxi instance. However, some things like interrupt handling require more complex (as in: not covered by regmap_update_bits) pseudo-atomic operations, so the idea was to keep the locking just like it was before for MDIO-connected MT753x switches and provide a lock-less regmap replacing the former mt7530_mii_write() and mt7530_mii_read() functions. If we use MMIO we can directly access the 32-bit wide registers and hence do not require locking. > > If you have a convincing argument the mutex is not needed, please add > two helpers: > > mt7530_mutex_lock(struct mt7530_priv *priv) > mt7530_mutex_unlock(struct mt7530_priv *priv) > > and hide the if inside that. As part of the commit message, explain > why the mutex is not needed for MDIO. Ok, will do. > > Adding these helpers and changing all calls can be a preparation > patch. It is the sort of patch which should be obviously correct. Understood. > > > @@ -2588,6 +2664,8 @@ mt7531_mac_config(struct dsa_switch *ds, int port, unsigned int mode, > > case PHY_INTERFACE_MODE_NA: > > case PHY_INTERFACE_MODE_1000BASEX: > > case PHY_INTERFACE_MODE_2500BASEX: > > + case PHY_INTERFACE_MODE_USXGMII: > > + case PHY_INTERFACE_MODE_10GKR: > > /* handled in SGMII PCS driver */ > > return 0; > > default: > > @@ -2712,7 +2790,9 @@ static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, > > * variants. > > */ > > if (interface == PHY_INTERFACE_MODE_TRGMII || > > - (phy_interface_mode_is_8023z(interface))) { > > + interface == PHY_INTERFACE_MODE_USXGMII || > > + interface == PHY_INTERFACE_MODE_10GKR || > > + phy_interface_mode_is_8023z(interface)) { > > speed = SPEED_1000; > > duplex = DUPLEX_FULL; > > } > > This looks like something which should be in a separate patch. Ok, I will put it into a separate patch before adding support for MT7988 which is the only switch supporting those modes (and also requiring them). > > > +static int mt7988_setup(struct dsa_switch *ds) > > +{ > > + struct mt7530_priv *priv = ds->priv; > > + u32 unused_pm = 0; > > + int i; > > + > > + /* Reset the switch */ > > + reset_control_assert(priv->rstc); > > + udelay(20); > > + reset_control_deassert(priv->rstc); > > + udelay(20); > > + > > + /* Reset the switch PHYs */ > > + mt7530_write(priv, MT7530_SYS_CTRL, SYS_CTRL_PHY_RST); > > + > > + /* BPDU to CPU port */ > > + mt7530_rmw(priv, MT7531_CFC, MT7531_CPU_PMAP_MASK, > > + BIT(MT7988_CPU_PORT)); > > + mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK, > > + MT753X_BPDU_CPU_ONLY); > > + > > + /* Enable and reset MIB counters */ > > + mt7530_mib_reset(ds); > > + > > + for (i = 0; i < MT7530_NUM_PORTS; i++) { > > + /* Disable forwarding by default on all ports */ > > + mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, > > + PCR_MATRIX_CLR); > > + > > + mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); > > + > > + if (dsa_is_unused_port(ds, i)) > > + unused_pm |= BIT(i); > > + else if (dsa_is_cpu_port(ds, i)) > > + mt753x_cpu_port_enable(ds, i); > > + else > > + mt7530_port_disable(ds, i); > > + > > + /* Enable consistent egress tag */ > > + mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK, > > + PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); > > + } > > + > > + ds->configure_vlan_while_not_filtering = true; > > + > > + /* Flush the FDB table */ > > + return mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL); > > Is this really specific to the mt7988? While the setup function is somehow similar to mt7530_setup or mt7531_setup there are also differences. It would be possible to split this more, so more common parts can be shared, such as the loop over the ports which is the same as for MT7531. The way initial reset is carried out as well as setting up the CPU port is specific to MT7988. > > Andrew